Nektar++
Movement/Zones.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: Zones.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// License for the specific language governing rights and limitations under
14// Permission is hereby granted, free of charge, to any person obtaining a
15// copy of this software and associated documentation files (the "Software"),
16// to deal in the Software without restriction, including without limitation
17// the rights to use, copy, modify, merge, publish, distribute, sublicense,
18// and/or sell copies of the Software, and to permit persons to whom the
19// Software is furnished to do so, subject to the following conditions:
20//
21// The above copyright notice and this permission notice shall be included
22// in all copies or substantial portions of the Software.
23//
24// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30// DEALINGS IN THE SOFTWARE.
31//
32// Description: Zones used in the non-conformal interfaces
33// and ALE implementations
34//
35////////////////////////////////////////////////////////////////////////////////
36
40#include <tinyxml.h>
41
43{
44
45ZoneBase::ZoneBase(MovementType type, int indx, int domainID,
46 CompositeMap domain, int coordDim)
47 : m_type(type), m_id(indx), m_domainID(domainID), m_domain(domain),
48 m_coordDim(coordDim)
49{
50 // Fill elements from domain
51 for (auto &comp : domain)
52 {
53 for (auto &geom : comp.second->m_geomVec)
54 {
55 m_elements.emplace_back(geom);
56 }
57 }
58
59 // The seenVerts/Edges/Faces keeps track of geometry so duplicates aren't
60 // emplaced in to the storage vector
61 std::unordered_set<int> seenVerts, seenEdges, seenFaces;
62
63 // Fill verts/edges/faces vector storage that are to be moved each timestep
64 for (auto &comp : m_domain)
65 {
66 for (auto &geom : comp.second->m_geomVec)
67 {
68 for (int i = 0; i < geom->GetNumVerts(); ++i)
69 {
70 PointGeomSharedPtr vert = geom->GetVertex(i);
71
72 if (seenVerts.find(vert->GetGlobalID()) != seenVerts.end())
73 {
74 continue;
75 }
76
77 seenVerts.insert(vert->GetGlobalID());
78 m_verts.emplace_back(vert);
79 }
80
81 for (int i = 0; i < geom->GetNumEdges(); ++i)
82 {
83 SegGeomSharedPtr edge =
84 std::static_pointer_cast<SegGeom>(geom->GetEdge(i));
85
86 if (seenEdges.find(edge->GetGlobalID()) != seenEdges.end())
87 {
88 continue;
89 }
90
91 seenEdges.insert(edge->GetGlobalID());
92
93 CurveSharedPtr curve = edge->GetCurve();
94 if (!curve)
95 {
96 continue;
97 }
98
99 m_curves.emplace_back(curve);
100 }
101
102 for (int i = 0; i < geom->GetNumFaces(); ++i)
103 {
105 std::static_pointer_cast<Geometry2D>(geom->GetFace(i));
106
107 if (seenFaces.find(face->GetGlobalID()) != seenFaces.end())
108 {
109 continue;
110 }
111
112 seenFaces.insert(face->GetGlobalID());
113
114 CurveSharedPtr curve = face->GetCurve();
115 if (!curve)
116 {
117 continue;
118 }
119
120 m_curves.emplace_back(curve);
121 }
122 }
123 }
124
125 // Copy points so we know original positions.
126 for (auto &pt : m_verts)
127 {
128 m_origVerts.emplace_back(*pt);
129 }
130
131 for (auto &curve : m_curves)
132 {
133 for (auto &pt : curve->m_points)
134 {
135 m_origVerts.emplace_back(*pt);
136 }
137 }
138}
139
140ZoneRotate::ZoneRotate(int id, int domainID, const CompositeMap &domain,
141 const int coordDim, const NekPoint<NekDouble> &origin,
142 const DNekVec &axis,
143 const LibUtilities::EquationSharedPtr &angularVelEqn)
144 : ZoneBase(MovementType::eRotate, id, domainID, domain, coordDim),
145 m_origin(origin), m_axis(axis), m_angularVelEqn(angularVelEqn)
146{
147 // Construct rotation matrix
148 m_W(0, 1) = -m_axis[2];
149 m_W(0, 2) = m_axis[1];
150 m_W(1, 0) = m_axis[2];
151 m_W(1, 2) = -m_axis[0];
152 m_W(2, 0) = -m_axis[1];
153 m_W(2, 1) = m_axis[0];
154
155 m_W2 = m_W * m_W;
156}
157
159{
160 // Clear bboxes (these will be regenerated next time GetBoundingBox is
161 // called)
162 for (auto &el : m_elements)
163 {
164 el->ClearBoundingBox();
165
166 int nfaces = el->GetNumFaces();
167 for (int i = 0; i < nfaces; ++i)
168 {
169 el->GetFace(i)->ClearBoundingBox();
170 }
171
172 int nedges = el->GetNumEdges();
173 for (int i = 0; i < nedges; ++i)
174 {
175 el->GetEdge(i)->ClearBoundingBox();
176 }
177 }
178}
179
181{
182 return m_angularVelEqn->Evaluate(0, 0, 0, time);
183}
184
185// Calculate new location of points using Rodrigues formula
187{
188 // Currently only valid for constant angular velocity
189 NekDouble angle = GetAngularVel(time) * time;
190
191 // Identity matrix
192 DNekMat rot(3, 3, 0.0);
193 rot(0, 0) = 1.0;
194 rot(1, 1) = 1.0;
195 rot(2, 2) = 1.0;
196
197 // Rodrigues' rotation formula in matrix form
198 rot = rot + sin(angle) * m_W + (1 - cos(angle)) * m_W2;
199
200 int cnt = 0;
201 for (auto &vert : m_verts)
202 {
204 DNekVec pntVec = {pnt[0], pnt[1], pnt[2]};
205
206 DNekVec newLoc = rot * pntVec;
207
208 vert->UpdatePosition(newLoc(0) + m_origin[0], newLoc(1) + m_origin[1],
209 newLoc(2) + m_origin[2]);
210 cnt++;
211 }
212
213 for (auto &curve : m_curves)
214 {
215 for (auto &vert : curve->m_points)
216 {
218 DNekVec pntVec = {pnt[0], pnt[1], pnt[2]};
219
220 DNekVec newLoc = rot * pntVec;
221
222 vert->UpdatePosition(newLoc(0) + m_origin[0],
223 newLoc(1) + m_origin[1],
224 newLoc(2) + m_origin[2]);
225 cnt++;
226 }
227 }
228
230
231 return true;
232}
233
235{
236 Array<OneD, NekDouble> dist(3, 0.0);
237 for (int i = 0; i < m_coordDim; ++i)
238 {
239 dist[i] = m_velocity[i] * timeStep;
240 }
241
242 int cnt = 0;
243 for (auto &vert : m_verts)
244 {
245 Array<OneD, NekDouble> newLoc(3, 0.0);
246 auto pnt = m_origVerts[cnt];
247
248 for (int i = 0; i < m_coordDim; ++i)
249 {
250 newLoc[i] = pnt(i) + dist[i];
251 }
252
253 vert->UpdatePosition(newLoc[0], newLoc[1], newLoc[2]);
254 cnt++;
255 }
256
257 for (auto &curve : m_curves)
258 {
259 for (auto &vert : curve->m_points)
260 {
261 Array<OneD, NekDouble> newLoc(3, 0.0);
262 auto pnt = m_origVerts[cnt];
263
264 for (int i = 0; i < m_coordDim; ++i)
265 {
266 newLoc[i] = pnt(i) + dist[i];
267 }
268
269 vert->UpdatePosition(newLoc[0], newLoc[1], newLoc[2]);
270 cnt++;
271 }
272 }
273
275
276 return true;
277}
278
279bool ZoneFixed::v_Move([[maybe_unused]] NekDouble time)
280{
281 return false;
282}
283
285{
286 int cnt = 0;
287 for (auto &vert : m_verts)
288 {
289 auto pnt = m_origVerts[cnt++];
290
291 Array<OneD, NekDouble> coords(3, 0.0);
292 vert->GetCoords(coords);
293
294 Array<OneD, NekDouble> newLoc(3, 0.0);
295 newLoc[0] =
296 m_xDeform->Evaluate(coords[0], coords[1], coords[2], time) + pnt(0);
297 newLoc[1] =
298 m_yDeform->Evaluate(coords[0], coords[1], coords[2], time) + pnt(1);
299 newLoc[2] =
300 m_zDeform->Evaluate(coords[0], coords[1], coords[2], time) + pnt(2);
301
302 vert->UpdatePosition(newLoc[0], newLoc[1], newLoc[2]);
303 }
304
306
307 return true;
308}
309
310} // namespace Nektar::SpatialDomains
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:125
const NekPoint< NekDouble > origin
std::shared_ptr< Curve > CurveSharedPtr
Definition: Curve.hpp:58
MovementType
Enum of zone movement type.
Definition: Zones.h:47
std::shared_ptr< SegGeom > SegGeomSharedPtr
Definition: Geometry2D.h:59
std::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:57
std::shared_ptr< Geometry2D > Geometry2DSharedPtr
Definition: Geometry.h:62
std::map< int, CompositeSharedPtr > CompositeMap
Definition: MeshGraph.h:136
double NekDouble
Zone base: Contains the shared functions and variables.
Definition: Zones.h:62
ZoneBase(MovementType type, int indx, int domainID, CompositeMap domain, int coordDim)
Constructor.
std::vector< PointGeomSharedPtr > m_verts
Vector of all points in the zone.
Definition: Zones.h:131
int m_coordDim
Coordinate dimension.
Definition: Zones.h:129
void ClearBoundingBoxes()
Clears all bounding boxes associated with the zones elements.
std::vector< PointGeom > m_origVerts
Vector of all points in the zone at initialisation.
Definition: Zones.h:135
std::vector< CurveSharedPtr > m_curves
Vector of all curves in the zone.
Definition: Zones.h:133
CompositeMap m_domain
Zone domain.
Definition: Zones.h:123
std::vector< GeometrySharedPtr > m_elements
Vector of highest dimension zone elements.
Definition: Zones.h:125
bool v_Move(NekDouble time) final
Virtual function for movement of the zone at.
LibUtilities::EquationSharedPtr m_zDeform
Equation specifying prescribed motion in z-direction.
Definition: Zones.h:338
LibUtilities::EquationSharedPtr m_yDeform
Equation specifying prescribed motion in y-direction.
Definition: Zones.h:336
bool v_Move(NekDouble time) final
Virtual function for movement of the zone at.
LibUtilities::EquationSharedPtr m_xDeform
Equation specifying prescribed motion in x-direction.
Definition: Zones.h:334
DNekVec m_axis
Axis rotation is performed around.
Definition: Zones.h:194
NekDouble GetAngularVel(NekDouble &time) const
Return the angular velocity of the zone at.
DNekMat m_W
W matrix Rodrigues' rotation formula, cross product of axis.
Definition: Zones.h:198
NekPoint< NekDouble > m_origin
Origin point rotation is performed around.
Definition: Zones.h:192
LibUtilities::EquationSharedPtr m_angularVelEqn
Equation defining angular velocity as a function of time.
Definition: Zones.h:196
bool v_Move(NekDouble time) final
Virtual function for movement of the zone at.
DNekMat m_W2
W^2 matrix Rodrigues' rotation formula, cross product of axis squared.
Definition: Zones.h:200
ZoneRotate(int id, int domainID, const CompositeMap &domain, const int coordDim, const NekPoint< NekDouble > &origin, const DNekVec &axis, const LibUtilities::EquationSharedPtr &angularVelEqn)
bool v_Move(NekDouble time) final
Virtual function for movement of the zone at.
std::vector< NekDouble > m_velocity
Definition: Zones.h:236