Nektar++
ProcessDisplacement.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ProcessDisplacement.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: Deforms a mesh given input field defining displacement.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <iostream>
36#include <string>
37using namespace std;
38
39#include "ProcessDisplacement.h"
40
43#include <LocalRegions/SegExp.h>
44#include <LocalRegions/TriExp.h>
48
49namespace Nektar::FieldUtils
50{
52{
53 TriFaceIDs(int a, int b, int c) : a(a), b(b), c(c)
54 {
55 }
56 int a;
57 int b;
58 int c;
59};
60
62{
63 std::size_t operator()(TriFaceIDs const &p) const
64 {
65 std::vector<int> ids(3);
66
67 ids[0] = p.a;
68 ids[1] = p.b;
69 ids[2] = p.c;
70
71 std::sort(ids.begin(), ids.end());
72 return hash_combine(ids[0], ids[1], ids[2]);
73 }
74};
75
76bool operator==(TriFaceIDs const &p1, TriFaceIDs const &p2)
77{
78 std::vector<int> ids1(3), ids2(3);
79
80 ids1[0] = p1.a;
81 ids1[1] = p1.b;
82 ids1[2] = p1.c;
83 ids2[0] = p2.a;
84 ids2[1] = p2.b;
85 ids2[2] = p2.c;
86
87 std::sort(ids1.begin(), ids1.end());
88 std::sort(ids2.begin(), ids2.end());
89
90 return ids1[0] == ids2[0] && ids1[1] == ids2[1] && ids1[2] == ids2[2];
91}
92
93typedef std::unordered_map<TriFaceIDs, int, TriFaceHash> TriFaceMap;
94
98 "Deform a mesh given an input field defining displacement");
99
102{
103 m_config["to"] =
104 ConfigOption(false, "", "Name of file containing high order boundary");
105
106 m_config["usevertexids"] = ConfigOption(
107 true, "0", "Use vertex IDs instead of face IDs for matching");
108}
109
111{
112}
113
114void ProcessDisplacement::v_Process(po::variables_map &vm)
115{
117 ASSERTL0(!boost::iequals(m_config["bnd"].as<string>(), "All"),
118 "ProcessDisplacement needs bnd parameter with a single id.");
119
120 string toFile = m_config["to"].as<string>();
121
122 if (toFile == "")
123 {
124 cout << "ProcessDisplacement: you must provide a file" << endl;
125 return;
126 }
127
128 bool useVertexIds = m_config["usevertexids"].as<bool>();
129
130 vector<string> files;
131 files.push_back(toFile);
136
137 // Try to find boundary condition expansion.
138 int bndCondId = m_config["bnd"].as<int>();
139
140 // FIXME: We should be storing boundary condition IDs
141 // somewhere...
142 if (bndGraph->GetMeshDimension() == 1)
143 {
144 m_f->m_exp.push_back(m_f->AppendExpList(0, "v"));
145 m_f->m_variables.push_back("v");
146
148 m_f->m_exp[0]->GetBndCondExpansions()[bndCondId];
150 m_f->m_exp[1]->GetBndCondExpansions()[bndCondId];
151
152 map<int, int> bndCondIds;
153 for (int i = 0; i < bndCondExpU->GetExpSize(); ++i)
154 {
155 bndCondIds[bndCondExpU->GetExp(i)->GetGeom()->GetGlobalID()] = i;
156 }
157
158 const SpatialDomains::SegGeomMap &tmp = bndGraph->GetAllSegGeoms();
159
160 for (auto &sIt : tmp)
161 {
162 auto mIt = bndCondIds.find(sIt.first);
163
164 if (mIt == bndCondIds.end())
165 {
166 cout << "Warning: couldn't find element " << sIt.first << endl;
167 continue;
168 }
169
170 int e = mIt->second;
171
173 std::dynamic_pointer_cast<SpatialDomains::SegGeom>(
174 bndCondExpU->GetExp(e)->GetGeom());
175
176 SpatialDomains::SegGeomSharedPtr to = sIt.second;
177
178 // Create temporary SegExp
181 bndCondExpU->GetExp(e)->GetBasis(0)->GetBasisKey(), to);
182
183 const int offset = bndCondExpU->GetPhys_Offset(e);
184 const int nq = toSeg->GetTotPoints();
185
186 Array<OneD, NekDouble> xL(nq), xC(nq), yL(nq), yC(nq), tmp;
187
188 bndCondExpU->GetExp(e)->GetCoords(xC, yC);
189 toSeg->GetCoords(xL, yL);
190
191 Vmath::Vsub(nq, xL, 1, xC, 1,
192 tmp = bndCondExpU->UpdatePhys() + offset, 1);
193 Vmath::Vsub(nq, yL, 1, yC, 1,
194 tmp = bndCondExpV->UpdatePhys() + offset, 1);
195 }
196
197 // bndconstrained?
198 bndCondExpU->FwdTransBndConstrained(bndCondExpU->GetPhys(),
199 bndCondExpU->UpdateCoeffs());
200 bndCondExpV->FwdTransBndConstrained(bndCondExpV->GetPhys(),
201 bndCondExpV->UpdateCoeffs());
202 }
203 else if (bndGraph->GetMeshDimension() == 2)
204 {
205 m_f->m_exp.push_back(m_f->AppendExpList(0, "v"));
206 m_f->m_exp.push_back(m_f->AppendExpList(0, "w"));
207 m_f->m_variables.push_back("v");
208 m_f->m_variables.push_back("w");
209
211 m_f->m_exp[0]->GetBndCondExpansions()[bndCondId];
213 m_f->m_exp[1]->GetBndCondExpansions()[bndCondId];
215 m_f->m_exp[2]->GetBndCondExpansions()[bndCondId];
216
217 map<int, int> bndCondIds;
218 for (int i = 0; i < bndCondExpU->GetExpSize(); ++i)
219 {
220 bndCondIds[bndCondExpU->GetExp(i)->GetGeom()->GetGlobalID()] = i;
221 }
222
223 TriFaceMap vertexFaceMap;
224
225 if (useVertexIds)
226 {
227 for (int i = 0; i < bndCondExpU->GetExpSize(); ++i)
228 {
230 std::dynamic_pointer_cast<SpatialDomains::TriGeom>(
231 bndCondExpU->GetExp(i)->GetGeom());
232
233 TriFaceIDs t(from->GetVid(0), from->GetVid(1), from->GetVid(2));
234 vertexFaceMap[t] = i;
235 }
236 }
237
238 const SpatialDomains::TriGeomMap &tmp = bndGraph->GetAllTriGeoms();
239
240 for (auto &sIt : tmp)
241 {
242 int e;
243
244 if (useVertexIds)
245 {
246 TriFaceIDs t(sIt.second->GetVid(0), sIt.second->GetVid(1),
247 sIt.second->GetVid(2));
248
249 auto tIt = vertexFaceMap.find(t);
250 e = tIt == vertexFaceMap.end() ? -1 : tIt->second;
251 }
252 else
253 {
254 auto mIt = bndCondIds.find(sIt.first);
255 e = mIt == bndCondIds.end() ? -1 : mIt->second;
256 }
257
258 if (e == -1)
259 {
260 cout << "Warning: couldn't find element " << sIt.first << endl;
261 continue;
262 }
263
265 std::dynamic_pointer_cast<SpatialDomains::TriGeom>(
266 bndCondExpU->GetExp(e)->GetGeom());
267
268 SpatialDomains::TriGeomSharedPtr to = sIt.second;
269
270 // Create temporary SegExp
273 bndCondExpU->GetExp(e)->GetBasis(0)->GetBasisKey(),
274 bndCondExpV->GetExp(e)->GetBasis(1)->GetBasisKey(), to);
275
276 const int offset = bndCondExpU->GetPhys_Offset(e);
277 const int nq = toSeg->GetTotPoints();
278
279 Array<OneD, NekDouble> xL(nq), xC(nq), yL(nq), yC(nq), tmp;
280 Array<OneD, NekDouble> zL(nq), zC(nq);
281
282 bndCondExpU->GetExp(e)->GetCoords(xC, yC, zC);
283 toSeg->GetCoords(xL, yL, zL);
284
285 Vmath::Vsub(nq, xL, 1, xC, 1,
286 tmp = bndCondExpU->UpdatePhys() + offset, 1);
287 Vmath::Vsub(nq, yL, 1, yC, 1,
288 tmp = bndCondExpV->UpdatePhys() + offset, 1);
289 Vmath::Vsub(nq, zL, 1, zC, 1,
290 tmp = bndCondExpW->UpdatePhys() + offset, 1);
291 }
292
293 // bndconstrained?
294 bndCondExpU->FwdTransBndConstrained(bndCondExpU->GetPhys(),
295 bndCondExpU->UpdateCoeffs());
296 bndCondExpV->FwdTransBndConstrained(bndCondExpV->GetPhys(),
297 bndCondExpV->UpdateCoeffs());
298 bndCondExpW->FwdTransBndConstrained(bndCondExpW->GetPhys(),
299 bndCondExpW->UpdateCoeffs());
300 }
301}
302} // 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
void v_Process(po::variables_map &vm) override
Write mesh to output file.
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
Definition: MeshGraph.cpp:115
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:990
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
bool operator==(TriFaceIDs const &p1, TriFaceIDs const &p2)
std::unordered_map< TriFaceIDs, int, TriFaceHash > TriFaceMap
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< SegExp > SegExpSharedPtr
Definition: SegExp.h:248
std::shared_ptr< TriExp > TriExpSharedPtr
Definition: TriExp.h:250
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::map< int, TriGeomSharedPtr > TriGeomMap
Definition: TriGeom.h:57
std::map< int, SegGeomSharedPtr > SegGeomMap
Definition: SegGeom.h:49
std::shared_ptr< SegGeom > SegGeomSharedPtr
Definition: Geometry2D.h:59
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
std::shared_ptr< TriGeom > TriGeomSharedPtr
Definition: TriGeom.h:56
void hash_combine(std::size_t &seed)
Definition: HashUtils.hpp:44
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
Represents a command-line configuration option.
Definition: Module.h:129
std::size_t operator()(TriFaceIDs const &p) const