Nektar++
Loading...
Searching...
No Matches
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
53
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 " + std::to_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 for (j = 0; j < BndExp[i]->GetExpSize(); ++j, ++cnt)
106 {
107 int elmtNum = BoundarytoElmtID[cnt];
108 int facetNum = BoundarytoTraceID[cnt];
109 int oppositeNum = 0;
110
111 // Get boundary and element expansions.
112 LocalRegions::ExpansionSharedPtr bndElmt = BndExp[i]->GetExp(j);
113 LocalRegions::ExpansionSharedPtr elmt = exp->GetExp(elmtNum);
114
115 // Determine which face is opposite to the surface
116 switch (elmt->DetShapeType())
117 {
119 {
120 oppositeNum = (facetNum + 2) % 4;
121 }
122 break;
123
125 {
126 switch (facetNum)
127 {
128 case 1:
129 oppositeNum = 3;
130 break;
131 case 3:
132 oppositeNum = 1;
133 break;
134 default:
135 ASSERTL0(false, "Surface must be on a triangular "
136 "face of the prism.");
137 }
138 }
139 break;
140
142 {
143 switch (facetNum)
144 {
145 case 0:
146 oppositeNum = 5;
147 break;
148 case 1:
149 oppositeNum = 3;
150 break;
151 case 2:
152 oppositeNum = 4;
153 break;
154 case 3:
155 oppositeNum = 1;
156 break;
157 case 4:
158 oppositeNum = 2;
159 break;
160 case 5:
161 oppositeNum = 0;
162 break;
163 default:
164 ASSERTL0(false, "Face out of bound.");
165 }
166 }
167 break;
168
169 default:
170 ASSERTL0(false, "Element not supported");
171 }
172
173 int nq = elmt->GetTotPoints();
174 int nqBnd = bndElmt->GetTotPoints();
175
177 x[0] = Array<OneD, NekDouble>(nq);
178 x[1] = Array<OneD, NekDouble>(nq);
179 x[2] = Array<OneD, NekDouble>(nq);
180 elmt->GetCoords(x[0], x[1], x[2]);
181
182 Array<OneD, NekDouble> face1(nqBnd), face2(nqBnd);
184 BndExp[i]->UpdatePhys() + BndExp[i]->GetPhys_Offset(j);
185
186 // Zero existing value.
187 Vmath::Zero(nqBnd, dist, 1);
188
189 // Calculate distance between two faces of the element
190 for (k = 0; k < expdim; ++k)
191 {
192 switch (expdim)
193 {
194 case 2:
195 {
196 elmt->GetTracePhysVals(facetNum, bndElmt, x[k], face1);
197 elmt->GetTracePhysVals(oppositeNum, bndElmt, x[k],
198 face2);
199 // Consider edge orientation
200 if (elmt->GetTraceOrient(facetNum) !=
201 elmt->GetTraceOrient(oppositeNum))
202 {
203 Vmath::Reverse(nqBnd, face2, 1, face2, 1);
204 }
205 }
206 break;
207 case 3:
208 {
209 // Use orientation from the surface for both faces
210 StdRegions::Orientation orientation =
211 elmt->GetTraceOrient(facetNum);
212 elmt->GetTracePhysVals(facetNum, bndElmt, x[k], face1,
213 orientation);
214 elmt->GetTracePhysVals(oppositeNum, bndElmt, x[k],
215 face2, orientation);
216 }
217 break;
218 default:
219 ASSERTL0(false, "Expansion not supported");
220 }
221 Vmath::Vsub(nqBnd, face1, 1, face2, 1, face1, 1);
222 Vmath::Vvtvp(nqBnd, face1, 1, face1, 1, dist, 1, dist, 1);
223 }
224 Vmath::Vsqrt(nqBnd, dist, 1, dist, 1);
225 }
226
227 BndExp[i]->FwdTransLocalElmt(BndExp[i]->GetPhys(),
228 BndExp[i]->UpdateCoeffs());
229 }
230}
231} // namespace Nektar::FieldUtils
#define ASSERTL0(condition, msg)
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.
std::shared_ptr< Field > FieldSharedPtr
Definition Field.hpp:1026
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
STL namespace.