Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProcessScalGrad.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessScalGrad.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Computes scalar gradient field.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include "ProcessScalGrad.h"
41 
44 #include <MultiRegions/ExpList.h>
45 
46 namespace Nektar
47 {
48 namespace Utilities
49 {
50 
51 ModuleKey ProcessScalGrad::className =
53  ModuleKey(eProcessModule, "scalargrad"),
54  ProcessScalGrad::create, "Computes scalar gradient field.");
55 
56 ProcessScalGrad::ProcessScalGrad(FieldSharedPtr f) : ProcessModule(f)
57 {
58  m_config["bnd"] = ConfigOption(false,"All","Boundary to be extracted");
59  f->m_writeBndFld = true;
60  f->m_declareExpansionAsContField = true;
61  m_f->m_fldToBnd = false;
62 }
63 
65 {
66 }
67 
68 void ProcessScalGrad::Process(po::variables_map &vm)
69 {
70  if (m_f->m_verbose)
71  {
72  if(m_f->m_comm->TreatAsRankZero())
73  {
74  cout << "ProcessScalGrad: Calculating scalar gradient..." << endl;
75  }
76  }
77 
78  int i, j, k;
79 
80  // Set up Field options to output boundary fld
81  string bvalues = m_config["bnd"].as<string>();
82 
83  if(bvalues.compare("All") == 0)
84  {
86  BndExp = m_f->m_exp[0]->GetBndCondExpansions();
87 
88  for(i = 0; i < BndExp.num_elements(); ++i)
89  {
90  m_f->m_bndRegionsToWrite.push_back(i);
91  }
92  }
93  else
94  {
96  m_f->m_bndRegionsToWrite),"Failed to interpret range string");
97  }
98 
99  int spacedim = m_f->m_graph->GetSpaceDimension();
100  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
101  (m_f->m_fielddef[0]->m_numHomogeneousDir) == 2)
102  {
103  spacedim = 3;
104  }
105 
106  int nfields = m_f->m_fielddef[0]->m_fields.size();
107  //ASSERTL0(nfields == 1,"Implicit assumption that input is in ADR format of (u)");
108 
109  if (spacedim == 1)
110  {
111  ASSERTL0(false, "Error: scalar gradient for a 1D problem cannot "
112  "be computed");
113  }
114 
115 
116  int ngrad = spacedim;
117  int n, cnt, elmtid, nq, offset, boundary, nfq;
118  int npoints = m_f->m_exp[0]->GetNpoints();
119  string var;
120  Array<OneD, NekDouble> scalar;
121  Array<OneD, Array<OneD, NekDouble> > grad(ngrad), fgrad(ngrad), outfield(nfields);
122 
125  Array<OneD, int> BoundarytoElmtID, BoundarytoTraceID;
127 
128  m_f->m_exp[0]->GetBoundaryToElmtMap(BoundarytoElmtID, BoundarytoTraceID);
129 
130  for (i = 0; i < nfields; i++)
131  {
132  var = m_f->m_fielddef[0]->m_fields[i];
133  stringstream filename;
134  filename << var << "_scalar_gradient";
135  filename >> var;
136  m_f->m_fielddef[0]->m_fields[i] = var;
137 
138  BndExp[i] = m_f->m_exp[i]->GetBndCondExpansions();
139  outfield[i] = Array<OneD, NekDouble>(npoints);
140  }
141 
142  // loop over the types of boundary conditions
143  for(cnt = n = 0; n < BndExp[0].num_elements(); ++n)
144  {
145  bool doneBnd = false;
146  // identify if boundary has been defined
147  for(int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
148  {
149  if(n == m_f->m_bndRegionsToWrite[b])
150  {
151  doneBnd = true;
152  for(i = 0; i < BndExp[0][n]->GetExpSize(); ++i, cnt++)
153  {
154  // find element and face of this expansion.
155  elmtid = BoundarytoElmtID[cnt];
156  elmt = m_f->m_exp[0]->GetExp(elmtid);
157  nq = elmt->GetTotPoints();
158  offset = m_f->m_exp[0]->GetPhys_Offset(elmtid);
159 
160  // Initialise local arrays for the velocity gradients, and stress components
161  // size of total number of quadrature points for each element (hence local).
162  for(j = 0; j < ngrad; ++j)
163  {
164  grad[j] = Array<OneD, NekDouble>(nq);
165  }
166 
167  if(spacedim == 2)
168  {
169  //Not implemented in 2D.
170  }
171  else
172  {
173  for(j = 0; j < nfields; j++)
174  {
175  outfield[j] = BndExp[j][n]->UpdateCoeffs() + BndExp[j][n]->GetCoeff_Offset(i);
176  }
177 
178  // Get face 2D expansion from element expansion
179  bc = boost::dynamic_pointer_cast<StdRegions::StdExpansion2D> (BndExp[0][n]->GetExp(i));
180  nfq = bc->GetTotPoints();
181 
182  //identify boundary of element looking at.
183  boundary = BoundarytoTraceID[cnt];
184 
185  //Get face normals
186  const SpatialDomains::GeomFactorsSharedPtr m_metricinfo = bc->GetMetricInfo();
187 
189  = elmt->GetFaceNormal(boundary);
190 
191  // initialise arrays
192  for(j = 0; j < ngrad; ++j)
193  {
194  fgrad[j] = Array<OneD, NekDouble>(nfq);
195  }
196  Array<OneD, NekDouble> gradnorm(nfq);
197 
198  for(k = 0; k < nfields; k++)
199  {
200  Vmath::Zero(nfq, gradnorm, 1);
201 
202  scalar = m_f->m_exp[k]->GetPhys() + offset;
203  elmt->PhysDeriv(scalar, grad[0],grad[1],grad[2]);
204 
205  for(j = 0; j < ngrad; ++j)
206  {
207  elmt->GetFacePhysVals(boundary,bc,grad[j],fgrad[j]);
208  }
209 
210  //surface curved
211  if (m_metricinfo->GetGtype() == SpatialDomains::eDeformed)
212  {
213  for (j=0; j<ngrad; j++)
214  {
215  Vmath::Vvtvp(nfq, normals[j], 1, fgrad[j], 1, gradnorm, 1, gradnorm, 1);
216  }
217  }
218  else
219  {
220  for (j=0; j<ngrad; j++)
221  {
222  Vmath::Svtvp(nfq, normals[j][0], fgrad[j], 1, gradnorm, 1, gradnorm, 1);
223  }
224  }
225  bc->FwdTrans(gradnorm, outfield[k]);
226  }
227 
228  }
229  }
230  }
231  }
232  if(doneBnd == false)
233  {
234  cnt += BndExp[0][n]->GetExpSize();
235  }
236  }
237 
238  for(j = 0; j < nfields; ++j)
239  {
240  for(int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
241  {
242  m_f->m_exp[j]->UpdateBndCondExpansion(m_f->m_bndRegionsToWrite[b]) = BndExp[j][m_f->m_bndRegionsToWrite[b]];
243  }
244  }
245 }
246 
247 }
248 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
pair< ModuleType, string > ModuleKey
static bool GenerateOrderedVector(const char *const str, std::vector< unsigned int > &vec)
Definition: ParseUtils.hpp:97
virtual void Process()=0
map< string, ConfigOption > m_config
List of configuration values.
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector plus vector): z = alpha*x + y
Definition: Vmath.cpp:471
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.cpp:428
STL namespace.
FieldSharedPtr m_f
Field object.
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
Definition: StdExpansion.h:141
boost::shared_ptr< StdExpansion2D > StdExpansion2DSharedPtr
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:698
Represents a command-line configuration option.
boost::shared_ptr< GeomFactors > GeomFactorsSharedPtr
Pointer to a GeomFactors object.
Definition: GeomFactors.h:62
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:359
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
Geometry is curved or has non-constant factors.
ModuleFactory & GetModuleFactory()
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215