Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 <iostream>
37 #include <string>
38 using namespace std;
39 
40 #include "ProcessScalGrad.h"
41 
44 #include <MultiRegions/ExpList.h>
45 
46 namespace Nektar
47 {
48 namespace FieldUtils
49 {
50 
51 ModuleKey ProcessScalGrad::className =
53  ModuleKey(eProcessModule, "scalargrad"),
54  ProcessScalGrad::create,
55  "Computes scalar gradient field.");
56 
57 ProcessScalGrad::ProcessScalGrad(FieldSharedPtr f) : ProcessModule(f)
58 {
59  m_config["bnd"] = ConfigOption(false, "All", "Boundary to be extracted");
60  f->m_writeBndFld = true;
61  f->m_declareExpansionAsContField = true;
62  m_f->m_fldToBnd = false;
63 }
64 
66 {
67 }
68 
69 void ProcessScalGrad::Process(po::variables_map &vm)
70 {
71  if (m_f->m_verbose)
72  {
73  if (m_f->m_comm->TreatAsRankZero())
74  {
75  cout << "ProcessScalGrad: Calculating scalar gradient..." << endl;
76  }
77  }
78 
79  int i, j, k;
80 
81  // Set up Field options to output boundary fld
82  string bvalues = m_config["bnd"].as<string>();
83 
84  if (bvalues.compare("All") == 0)
85  {
87  m_f->m_exp[0]->GetBndCondExpansions();
88 
89  for (i = 0; i < BndExp.num_elements(); ++i)
90  {
91  m_f->m_bndRegionsToWrite.push_back(i);
92  }
93  }
94  else
95  {
97  m_f->m_bndRegionsToWrite),
98  "Failed to interpret range string");
99  }
100 
101  int spacedim = m_f->m_graph->GetSpaceDimension();
102  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
103  (m_f->m_fielddef[0]->m_numHomogeneousDir) == 2)
104  {
105  spacedim = 3;
106  }
107 
108  int nfields = m_f->m_fielddef[0]->m_fields.size();
109  // ASSERTL0(nfields == 1,"Implicit assumption that input is in ADR format of
110  // (u)");
111 
112  if (spacedim == 1)
113  {
114  ASSERTL0(false, "Error: scalar gradient for a 1D problem cannot "
115  "be computed");
116  }
117 
118  int ngrad = spacedim;
119  int n, cnt, elmtid, nq, offset, boundary, nfq;
120  int npoints = m_f->m_exp[0]->GetNpoints();
121  string var;
122  Array<OneD, NekDouble> scalar;
123  Array<OneD, Array<OneD, NekDouble> > grad(ngrad), fgrad(ngrad),
124  outfield(nfields);
125 
128  Array<OneD, int> BoundarytoElmtID, BoundarytoTraceID;
130 
131  m_f->m_exp[0]->GetBoundaryToElmtMap(BoundarytoElmtID, BoundarytoTraceID);
132 
133  for (i = 0; i < nfields; i++)
134  {
135  var = m_f->m_fielddef[0]->m_fields[i];
136  stringstream filename;
137  filename << var << "_scalar_gradient";
138  filename >> var;
139  m_f->m_fielddef[0]->m_fields[i] = var;
140 
141  BndExp[i] = m_f->m_exp[i]->GetBndCondExpansions();
142  outfield[i] = Array<OneD, NekDouble>(npoints);
143  }
144 
145  // loop over the types of boundary conditions
146  for (cnt = n = 0; n < BndExp[0].num_elements(); ++n)
147  {
148  bool doneBnd = false;
149  // identify if boundary has been defined
150  for (int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
151  {
152  if (n == m_f->m_bndRegionsToWrite[b])
153  {
154  doneBnd = true;
155  for (i = 0; i < BndExp[0][n]->GetExpSize(); ++i, cnt++)
156  {
157  // find element and face of this expansion.
158  elmtid = BoundarytoElmtID[cnt];
159  elmt = m_f->m_exp[0]->GetExp(elmtid);
160  nq = elmt->GetTotPoints();
161  offset = m_f->m_exp[0]->GetPhys_Offset(elmtid);
162 
163  // Initialise local arrays for the velocity gradients, and
164  // stress components
165  // size of total number of quadrature points for each
166  // element (hence local).
167  for (j = 0; j < ngrad; ++j)
168  {
169  grad[j] = Array<OneD, NekDouble>(nq);
170  }
171 
172  if (spacedim == 2)
173  {
174  // Not implemented in 2D.
175  }
176  else
177  {
178  for (j = 0; j < nfields; j++)
179  {
180  outfield[j] = BndExp[j][n]->UpdateCoeffs() +
181  BndExp[j][n]->GetCoeff_Offset(i);
182  }
183 
184  // Get face 2D expansion from element expansion
185  bc = boost::dynamic_pointer_cast<
187  BndExp[0][n]->GetExp(i));
188  nfq = bc->GetTotPoints();
189 
190  // identify boundary of element looking at.
191  boundary = BoundarytoTraceID[cnt];
192 
193  // Get face normals
195  m_metricinfo = bc->GetMetricInfo();
196 
198  normals = elmt->GetFaceNormal(boundary);
199 
200  // initialise arrays
201  for (j = 0; j < ngrad; ++j)
202  {
203  fgrad[j] = Array<OneD, NekDouble>(nfq);
204  }
205  Array<OneD, NekDouble> gradnorm(nfq);
206 
207  for (k = 0; k < nfields; k++)
208  {
209  Vmath::Zero(nfq, gradnorm, 1);
210 
211  scalar = m_f->m_exp[k]->GetPhys() + offset;
212  elmt->PhysDeriv(scalar, grad[0], grad[1], grad[2]);
213 
214  for (j = 0; j < ngrad; ++j)
215  {
216  elmt->GetFacePhysVals(boundary, bc, grad[j],
217  fgrad[j]);
218  }
219 
220  // surface curved
221  if (m_metricinfo->GetGtype() ==
223  {
224  for (j = 0; j < ngrad; j++)
225  {
226  Vmath::Vvtvp(nfq, normals[j], 1, fgrad[j],
227  1, gradnorm, 1, gradnorm, 1);
228  }
229  }
230  else
231  {
232  for (j = 0; j < ngrad; j++)
233  {
234  Vmath::Svtvp(nfq, normals[j][0], fgrad[j],
235  1, gradnorm, 1, gradnorm, 1);
236  }
237  }
238  bc->FwdTrans(gradnorm, outfield[k]);
239  }
240  }
241  }
242  }
243  }
244  if (doneBnd == false)
245  {
246  cnt += BndExp[0][n]->GetExpSize();
247  }
248  }
249 
250  for (j = 0; j < nfields; ++j)
251  {
252  for (int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
253  {
254  m_f->m_exp[j]->UpdateBndCondExpansion(m_f->m_bndRegionsToWrite[b]) =
255  BndExp[j][m_f->m_bndRegionsToWrite[b]];
256  }
257  }
258 }
259 }
260 }
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
static bool GenerateOrderedVector(const char *const str, std::vector< unsigned int > &vec)
Definition: ParseUtils.hpp:97
Represents a command-line configuration option.
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:485
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:442
STL namespace.
pair< ModuleType, string > ModuleKey
virtual void Process(po::variables_map &vm)
Write mesh to output file.
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:740
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:373
Abstract base class for processing modules.
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
Geometry is curved or has non-constant factors.
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215