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