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