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"), ProcessScalGrad::create,
52  "Computes scalar gradient field.");
53 
54 ProcessScalGrad::ProcessScalGrad(FieldSharedPtr f) : ProcessBoundaryExtract(f)
55 {
56 }
57 
59 {
60 }
61 
62 void ProcessScalGrad::v_Process(po::variables_map &vm)
63 {
65 
66  int i, j, k;
67 
68  int spacedim = m_f->m_graph->GetSpaceDimension();
69  if ((m_f->m_numHomogeneousDir) == 1 || (m_f->m_numHomogeneousDir) == 2)
70  {
71  spacedim = 3;
72  }
73 
74  int nfields = m_f->m_variables.size();
75 
76  string var;
77  for (i = 0; i < nfields; i++)
78  {
79  var = m_f->m_variables[i];
80  stringstream filename;
81  filename << var << "_scalar_gradient";
82  filename >> var;
83  m_f->m_variables[i] = var;
84  }
85  if (m_f->m_exp[0]->GetNumElmts() == 0)
86  {
87  return;
88  }
89 
90  if (spacedim == 1)
91  {
92  ASSERTL0(false, "Error: scalar gradient for a 1D problem cannot "
93  "be computed");
94  }
95 
96  int ngrad = spacedim;
97  int n, cnt, elmtid, nq, offset, boundary, nfq;
98  int npoints = m_f->m_exp[0]->GetNpoints();
100  Array<OneD, Array<OneD, NekDouble>> grad(ngrad), fgrad(ngrad),
101  outfield(nfields);
102 
105  Array<OneD, int> BoundarytoElmtID, BoundarytoTraceID;
107 
108  m_f->m_exp[0]->GetBoundaryToElmtMap(BoundarytoElmtID, BoundarytoTraceID);
109 
110  for (i = 0; i < nfields; i++)
111  {
112  BndExp[i] = m_f->m_exp[i]->GetBndCondExpansions();
113  outfield[i] = Array<OneD, NekDouble>(npoints);
114  }
115 
116  // loop over the types of boundary conditions
117  for (cnt = n = 0; n < BndExp[0].size(); ++n)
118  {
119  bool doneBnd = false;
120  // identify if boundary has been defined
121  for (int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
122  {
123  if (n == m_f->m_bndRegionsToWrite[b])
124  {
125  doneBnd = true;
126  for (i = 0; i < BndExp[0][n]->GetExpSize(); ++i, cnt++)
127  {
128  // find element and face of this expansion.
129  elmtid = BoundarytoElmtID[cnt];
130  elmt = m_f->m_exp[0]->GetExp(elmtid);
131  nq = elmt->GetTotPoints();
132  offset = m_f->m_exp[0]->GetPhys_Offset(elmtid);
133 
134  // Initialise local arrays for the velocity
135  // gradients, and stress components size of total
136  // number of quadrature points for each element
137  // (hence local).
138  for (j = 0; j < ngrad; ++j)
139  {
140  grad[j] = Array<OneD, NekDouble>(nq);
141  }
142 
143  if (spacedim == 2)
144  {
145  // Not implemented in 2D.
146  }
147  else
148  {
149  for (j = 0; j < nfields; j++)
150  {
151  outfield[j] = BndExp[j][n]->UpdateCoeffs() +
152  BndExp[j][n]->GetCoeff_Offset(i);
153  }
154 
155  // Get face 2D expansion from element expansion
156  bc = std::dynamic_pointer_cast<
158  BndExp[0][n]->GetExp(i));
159  nfq = bc->GetTotPoints();
160 
161  // identify boundary of element looking at.
162  boundary = BoundarytoTraceID[cnt];
163 
164  const LocalRegions::Expansion *lep =
165  dynamic_cast<const LocalRegions::Expansion *>(
166  &(*bc));
167 
168  // Get face normals
170  m_metricinfo = lep->GetMetricInfo();
171 
173  normals = elmt->GetTraceNormal(boundary);
174 
175  // initialise arrays
176  for (j = 0; j < ngrad; ++j)
177  {
178  fgrad[j] = Array<OneD, NekDouble>(nfq);
179  }
180  Array<OneD, NekDouble> gradnorm(nfq);
181 
182  for (k = 0; k < nfields; k++)
183  {
184  Vmath::Zero(nfq, gradnorm, 1);
185 
186  scalar = m_f->m_exp[k]->GetPhys() + offset;
187  elmt->PhysDeriv(scalar, grad[0], grad[1], grad[2]);
188 
189  for (j = 0; j < ngrad; ++j)
190  {
191  elmt->GetTracePhysVals(boundary, bc, grad[j],
192  fgrad[j]);
193  }
194 
195  // surface curved
196  if (m_metricinfo->GetGtype() ==
198  {
199  for (j = 0; j < ngrad; j++)
200  {
201  Vmath::Vvtvp(nfq, normals[j], 1, fgrad[j],
202  1, gradnorm, 1, gradnorm, 1);
203  }
204  }
205  else
206  {
207  for (j = 0; j < ngrad; j++)
208  {
209  Vmath::Svtvp(nfq, normals[j][0], fgrad[j],
210  1, gradnorm, 1, gradnorm, 1);
211  }
212  }
213  bc->FwdTrans(gradnorm, outfield[k]);
214  }
215  }
216  }
217  }
218  }
219  if (doneBnd == false)
220  {
221  cnt += BndExp[0][n]->GetExpSize();
222  }
223  }
224 
225  for (j = 0; j < nfields; ++j)
226  {
227  for (int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
228  {
229  m_f->m_exp[j]->UpdateBndCondExpansion(m_f->m_bndRegionsToWrite[b]) =
230  BndExp[j][m_f->m_bndRegionsToWrite[b]];
231  }
232  }
233 }
234 } // namespace FieldUtils
235 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
This processing module sets up for the boundary field to be extracted.
virtual void v_Process(po::variables_map &vm) override
virtual void v_Process(po::variables_map &vm) override
Write mesh to output file.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
const SpatialDomains::GeomFactorsSharedPtr & GetMetricInfo() const
Definition: Expansion.cpp:250
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
Definition: StdExpansion.h:140
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:991
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
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:2
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:622
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:574
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:492