Nektar++
ProcessSurfDistance.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessSurfDistance.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 height of elements connected to a surface.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <string>
37 using namespace std;
38 
39 #include "ProcessSurfDistance.h"
40 
41 namespace Nektar
42 {
43 namespace FieldUtils
44 {
45 
46 ModuleKey ProcessSurfDistance::className =
48  ModuleKey(eProcessModule, "surfdistance"), ProcessSurfDistance::create,
49  "Computes height of element connected to a surface.");
50 
51 ProcessSurfDistance::ProcessSurfDistance(FieldSharedPtr f)
53 {
54 }
55 
57 {
58 }
59 
60 void ProcessSurfDistance::v_Process(po::variables_map &vm)
61 {
63  ASSERTL0(!boost::iequals(m_config["bnd"].as<string>(), "All"),
64  "ProcessSurfDistance needs bnd parameter with a single id.");
65 
66  int i, j, k, cnt;
67  int surf = m_config["bnd"].as<int>();
68  int expdim = m_f->m_graph->GetMeshDimension();
69 
70  ASSERTL0(surf >= 0, "Invalid surface " + boost::lexical_cast<string>(surf));
71 
72  int nfields = m_f->m_variables.size();
73  m_f->m_variables.push_back("dist");
74 
75  if (m_f->m_exp[0]->GetNumElmts() == 0)
76  {
77  return;
78  }
79 
80  int NumHomogeneousDir = m_f->m_numHomogeneousDir;
82  if (nfields)
83  {
84  m_f->m_exp.resize(nfields + 1);
85  exp = m_f->AppendExpList(NumHomogeneousDir);
86 
87  m_f->m_exp[nfields] = exp;
88  }
89  else
90  {
91  exp = m_f->m_exp[0];
92  }
93 
94  // Grab boundary expansions.
96  exp->GetBndCondExpansions();
97 
98  // Get map that takes us from boundary element to element.
99  Array<OneD, int> BoundarytoElmtID, BoundarytoTraceID;
100  exp->GetBoundaryToElmtMap(BoundarytoElmtID, BoundarytoTraceID);
101 
102  ASSERTL0(!(m_f->m_numHomogeneousDir),
103  "Homogeneous expansions not supported");
104 
105  for (i = cnt = 0; i < BndExp.size(); ++i)
106  {
107  if (i != surf)
108  {
109  cnt += BndExp[i]->GetExpSize();
110  continue;
111  }
112 
113  for (j = 0; j < BndExp[i]->GetExpSize(); ++j, ++cnt)
114  {
115  int elmtNum = BoundarytoElmtID[cnt];
116  int facetNum = BoundarytoTraceID[cnt];
117  int oppositeNum = 0;
118 
119  // Get boundary and element expansions.
120  LocalRegions::ExpansionSharedPtr bndElmt = BndExp[i]->GetExp(j);
121  LocalRegions::ExpansionSharedPtr elmt = exp->GetExp(elmtNum);
122 
123  // Determine which face is opposite to the surface
124  switch (elmt->DetShapeType())
125  {
127  {
128  oppositeNum = (facetNum + 2) % 4;
129  }
130  break;
131 
133  {
134  switch (facetNum)
135  {
136  case 1:
137  oppositeNum = 3;
138  break;
139  case 3:
140  oppositeNum = 1;
141  break;
142  default:
143  ASSERTL0(false, "Surface must be on a triangular "
144  "face of the prism.");
145  }
146  }
147  break;
148 
150  {
151  switch (facetNum)
152  {
153  case 0:
154  oppositeNum = 5;
155  break;
156  case 1:
157  oppositeNum = 3;
158  break;
159  case 2:
160  oppositeNum = 4;
161  break;
162  case 3:
163  oppositeNum = 1;
164  break;
165  case 4:
166  oppositeNum = 2;
167  break;
168  case 5:
169  oppositeNum = 0;
170  break;
171  default:
172  ASSERTL0(false, "Face out of bound.");
173  }
174  }
175  break;
176 
177  default:
178  ASSERTL0(false, "Element not supported");
179  }
180 
181  int nq = elmt->GetTotPoints();
182  int nqBnd = bndElmt->GetTotPoints();
183 
185  x[0] = Array<OneD, NekDouble>(nq);
186  x[1] = Array<OneD, NekDouble>(nq);
187  x[2] = Array<OneD, NekDouble>(nq);
188  elmt->GetCoords(x[0], x[1], x[2]);
189 
190  Array<OneD, NekDouble> face1(nqBnd), face2(nqBnd);
192  BndExp[i]->UpdatePhys() + BndExp[i]->GetPhys_Offset(j);
193 
194  // Zero existing value.
195  Vmath::Zero(nqBnd, dist, 1);
196 
197  // Calculate distance between two faces of the element
198  for (k = 0; k < expdim; ++k)
199  {
200  switch (expdim)
201  {
202  case 2:
203  {
204  elmt->GetTracePhysVals(facetNum, bndElmt, x[k], face1);
205  elmt->GetTracePhysVals(oppositeNum, bndElmt, x[k],
206  face2);
207  // Consider edge orientation
208  if (elmt->GetTraceOrient(facetNum) !=
209  elmt->GetTraceOrient(oppositeNum))
210  {
211  Vmath::Reverse(nqBnd, face2, 1, face2, 1);
212  }
213  }
214  break;
215  case 3:
216  {
217  // Use orientation from the surface for both faces
218  StdRegions::Orientation orientation =
219  elmt->GetTraceOrient(facetNum);
220  elmt->GetTracePhysVals(facetNum, bndElmt, x[k], face1,
221  orientation);
222  elmt->GetTracePhysVals(oppositeNum, bndElmt, x[k],
223  face2, orientation);
224  }
225  break;
226  default:
227  ASSERTL0(false, "Expansion not supported");
228  }
229  Vmath::Vsub(nqBnd, face1, 1, face2, 1, face1, 1);
230  Vmath::Vvtvp(nqBnd, face1, 1, face1, 1, dist, 1, dist, 1);
231  }
232  Vmath::Vsqrt(nqBnd, dist, 1, dist, 1);
233  }
234 
235  BndExp[i]->FwdTransLocalElmt(BndExp[i]->GetPhys(),
236  BndExp[i]->UpdateCoeffs());
237  }
238 }
239 } // namespace FieldUtils
240 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:263
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
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< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
Definition: Vmath.cpp:534
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
void Reverse(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1286
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.cpp:419