Nektar++
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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Computes scalar gradient field.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <string>
37 using namespace std;
38 
39 #include "ProcessScalGrad.h"
40 
42 #include <MultiRegions/ExpList.h>
43 
44 namespace Nektar
45 {
46 namespace FieldUtils
47 {
48 
49 ModuleKey ProcessScalGrad::className =
51  ModuleKey(eProcessModule, "scalargrad"),
52  ProcessScalGrad::create,
53  "Computes scalar gradient field.");
54 
55 ProcessScalGrad::ProcessScalGrad(FieldSharedPtr f) : ProcessBoundaryExtract(f)
56 {
57 }
58 
60 {
61 }
62 
63 void ProcessScalGrad::Process(po::variables_map &vm)
64 {
66 
67  int i, j, k;
68 
69  int spacedim = m_f->m_graph->GetSpaceDimension();
70  if ((m_f->m_numHomogeneousDir) == 1 || (m_f->m_numHomogeneousDir) == 2)
71  {
72  spacedim = 3;
73  }
74 
75  int nfields = m_f->m_variables.size();
76 
77  string var;
78  for (i = 0; i < nfields; i++)
79  {
80  var = m_f->m_variables[i];
81  stringstream filename;
82  filename << var << "_scalar_gradient";
83  filename >> var;
84  m_f->m_variables[i] = var;
85  }
86  if (m_f->m_exp[0]->GetNumElmts() == 0)
87  {
88  return;
89  }
90 
91  if (spacedim == 1)
92  {
93  ASSERTL0(false, "Error: scalar gradient for a 1D problem cannot "
94  "be computed");
95  }
96 
97  int ngrad = spacedim;
98  int n, cnt, elmtid, nq, offset, boundary, nfq;
99  int npoints = m_f->m_exp[0]->GetNpoints();
100  Array<OneD, NekDouble> scalar;
101  Array<OneD, Array<OneD, NekDouble> > grad(ngrad), fgrad(ngrad),
102  outfield(nfields);
103 
106  Array<OneD, int> BoundarytoElmtID, BoundarytoTraceID;
108 
109  m_f->m_exp[0]->GetBoundaryToElmtMap(BoundarytoElmtID, BoundarytoTraceID);
110 
111  for (i = 0; i < nfields; i++)
112  {
113  BndExp[i] = m_f->m_exp[i]->GetBndCondExpansions();
114  outfield[i] = Array<OneD, NekDouble>(npoints);
115  }
116 
117  // loop over the types of boundary conditions
118  for (cnt = n = 0; n < BndExp[0].size(); ++n)
119  {
120  bool doneBnd = false;
121  // identify if boundary has been defined
122  for (int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
123  {
124  if (n == m_f->m_bndRegionsToWrite[b])
125  {
126  doneBnd = true;
127  for (i = 0; i < BndExp[0][n]->GetExpSize(); ++i, cnt++)
128  {
129  // find element and face of this expansion.
130  elmtid = BoundarytoElmtID[cnt];
131  elmt = m_f->m_exp[0]->GetExp(elmtid);
132  nq = elmt->GetTotPoints();
133  offset = m_f->m_exp[0]->GetPhys_Offset(elmtid);
134 
135  // Initialise local arrays for the velocity gradients, and
136  // stress components
137  // size of total number of quadrature points for each
138  // element (hence local).
139  for (j = 0; j < ngrad; ++j)
140  {
141  grad[j] = Array<OneD, NekDouble>(nq);
142  }
143 
144  if (spacedim == 2)
145  {
146  // Not implemented in 2D.
147  }
148  else
149  {
150  for (j = 0; j < nfields; j++)
151  {
152  outfield[j] = BndExp[j][n]->UpdateCoeffs() +
153  BndExp[j][n]->GetCoeff_Offset(i);
154  }
155 
156  // Get face 2D expansion from element expansion
157  bc = std::dynamic_pointer_cast<
159  BndExp[0][n]->GetExp(i));
160  nfq = bc->GetTotPoints();
161 
162  // identify boundary of element looking at.
163  boundary = BoundarytoTraceID[cnt];
164 
165  const LocalRegions::Expansion * lep = dynamic_cast<const LocalRegions::Expansion*>( &( *bc ) );
166 
167  // Get face normals
168  const SpatialDomains::GeomFactorsSharedPtr m_metricinfo = lep->GetMetricInfo();
169 
170  const Array<OneD, const Array<OneD, NekDouble> > normals = elmt->GetTraceNormal(boundary);
171 
172  // initialise arrays
173  for (j = 0; j < ngrad; ++j)
174  {
175  fgrad[j] = Array<OneD, NekDouble>(nfq);
176  }
177  Array<OneD, NekDouble> gradnorm(nfq);
178 
179  for (k = 0; k < nfields; k++)
180  {
181  Vmath::Zero(nfq, gradnorm, 1);
182 
183  scalar = m_f->m_exp[k]->GetPhys() + offset;
184  elmt->PhysDeriv(scalar, grad[0], grad[1], grad[2]);
185 
186  for (j = 0; j < ngrad; ++j)
187  {
188  elmt->GetTracePhysVals(boundary, bc, grad[j],
189  fgrad[j]);
190  }
191 
192  // surface curved
193  if (m_metricinfo->GetGtype() ==
195  {
196  for (j = 0; j < ngrad; j++)
197  {
198  Vmath::Vvtvp(nfq, normals[j], 1, fgrad[j],
199  1, gradnorm, 1, gradnorm, 1);
200  }
201  }
202  else
203  {
204  for (j = 0; j < ngrad; j++)
205  {
206  Vmath::Svtvp(nfq, normals[j][0], fgrad[j],
207  1, gradnorm, 1, gradnorm, 1);
208  }
209  }
210  bc->FwdTrans(gradnorm, outfield[k]);
211  }
212  }
213  }
214  }
215  }
216  if (doneBnd == false)
217  {
218  cnt += BndExp[0][n]->GetExpSize();
219  }
220  }
221 
222  for (j = 0; j < nfields; ++j)
223  {
224  for (int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
225  {
226  m_f->m_exp[j]->UpdateBndCondExpansion(m_f->m_bndRegionsToWrite[b]) =
227  BndExp[j][m_f->m_bndRegionsToWrite[b]];
228  }
229  }
230 }
231 }
232 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
FieldSharedPtr m_f
Field object.
Definition: Module.h:230
This processing module sets up for the boundary field to be extracted.
virtual void Process(po::variables_map &vm)
virtual void Process(po::variables_map &vm)
Write mesh to output file.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
const SpatialDomains::GeomFactorsSharedPtr & GetMetricInfo() const
Definition: Expansion.cpp:251
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
Definition: StdExpansion.h:134
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:989
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:290
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:68
std::shared_ptr< GeomFactors > GeomFactorsSharedPtr
Pointer to a GeomFactors object.
Definition: GeomFactors.h:62
@ eDeformed
Geometry is curved or has non-constant factors.
std::shared_ptr< StdExpansion2D > StdExpansion2DSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
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:565
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:513
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:436