Nektar++
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 
42 namespace Nektar
43 {
44 namespace SpatialDomains
45 {
46 
48  int coordDim)
49  : m_type(type), m_id(indx), m_domain(domain), m_coordDim(coordDim)
50 {
51  // Fill elements from domain
52  for (auto &comp : domain)
53  {
54  for (auto &geom : comp.second->m_geomVec)
55  {
56  m_elements.emplace_back(geom);
57  }
58  }
59 
60  // The seenVerts/Edges/Faces keeps track of geometry so duplicates aren't
61  // emplaced in to the storage vector
62  std::unordered_set<int> seenVerts, seenEdges, seenFaces;
63 
64  // Fill verts/edges/faces vector storage that are to be moved each timestep
65  for (auto &comp : m_domain)
66  {
67  for (auto &geom : comp.second->m_geomVec)
68  {
69  for (int i = 0; i < geom->GetNumVerts(); ++i)
70  {
71  PointGeomSharedPtr vert = geom->GetVertex(i);
72 
73  if (seenVerts.find(vert->GetGlobalID()) != seenVerts.end())
74  {
75  continue;
76  }
77 
78  seenVerts.insert(vert->GetGlobalID());
79  m_verts.emplace_back(vert);
80  }
81 
82  for (int i = 0; i < geom->GetNumEdges(); ++i)
83  {
84  SegGeomSharedPtr edge =
85  std::static_pointer_cast<SegGeom>(geom->GetEdge(i));
86 
87  if (seenEdges.find(edge->GetGlobalID()) != seenEdges.end())
88  {
89  continue;
90  }
91 
92  seenEdges.insert(edge->GetGlobalID());
93 
94  CurveSharedPtr curve = edge->GetCurve();
95  if (!curve)
96  {
97  continue;
98  }
99 
100  m_curves.emplace_back(curve);
101  }
102 
103  for (int i = 0; i < geom->GetNumFaces(); ++i)
104  {
105  Geometry2DSharedPtr face =
106  std::static_pointer_cast<Geometry2D>(geom->GetFace(i));
107 
108  if (seenFaces.find(face->GetGlobalID()) != seenFaces.end())
109  {
110  continue;
111  }
112 
113  seenFaces.insert(face->GetGlobalID());
114 
115  CurveSharedPtr curve = face->GetCurve();
116  if (!curve)
117  {
118  continue;
119  }
120 
121  m_curves.emplace_back(curve);
122  }
123  }
124  }
125 
126  // Copy points so we know original positions.
127  for (auto &pt : m_verts)
128  {
129  m_origVerts.emplace_back(*pt);
130  }
131 
132  for (auto &curve : m_curves)
133  {
134  for (auto &pt : curve->m_points)
135  {
136  m_origVerts.emplace_back(*pt);
137  }
138  }
139 }
140 
141 ZoneRotate::ZoneRotate(int id, const CompositeMap &domain, const int coordDim,
142  const NekPoint<NekDouble> &origin, const DNekVec &axis,
143  const LibUtilities::EquationSharedPtr &angularVelEqn)
144  : ZoneBase(MovementType::eRotate, id, domain, coordDim), m_origin(origin),
145  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 
280 {
281  boost::ignore_unused(time);
282  return false;
283 }
284 
286 {
287  int cnt = 0;
288  for (auto &vert : m_verts)
289  {
290  auto pnt = m_origVerts[cnt++];
291 
292  Array<OneD, NekDouble> coords(3, 0.0);
293  vert->GetCoords(coords);
294 
295  Array<OneD, NekDouble> newLoc(3, 0.0);
296  newLoc[0] =
297  m_xDeform->Evaluate(coords[0], coords[1], coords[2], time) + pnt(0);
298  newLoc[1] =
299  m_yDeform->Evaluate(coords[0], coords[1], coords[2], time) + pnt(1);
300  newLoc[2] =
301  m_zDeform->Evaluate(coords[0], coords[1], coords[2], time) + pnt(2);
302 
303  vert->UpdatePosition(newLoc[0], newLoc[1], newLoc[2]);
304  }
305 
307 
308  return true;
309 }
310 
311 } // namespace SpatialDomains
312 } // namespace Nektar
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:129
std::shared_ptr< Curve > CurveSharedPtr
Definition: Curve.hpp:60
MovementType
Enum of zone movement type.
Definition: Zones.h:49
std::shared_ptr< SegGeom > SegGeomSharedPtr
Definition: Geometry2D.h:62
std::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:59
std::shared_ptr< Geometry2D > Geometry2DSharedPtr
Definition: Geometry.h:65
std::map< int, CompositeSharedPtr > CompositeMap
Definition: MeshGraph.h:138
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
Zone base: Contains the shared functions and variables.
Definition: Zones.h:63
std::vector< PointGeomSharedPtr > m_verts
Vector of all points in the zone.
Definition: Zones.h:130
int m_coordDim
Coordinate dimension.
Definition: Zones.h:128
void ClearBoundingBoxes()
Clears all bounding boxes associated with the zones elements.
Definition: Zones.cpp:158
std::vector< PointGeom > m_origVerts
Vector of all points in the zone at initialisation.
Definition: Zones.h:134
std::vector< CurveSharedPtr > m_curves
Vector of all curves in the zone.
Definition: Zones.h:132
CompositeMap m_domain
Zone domain.
Definition: Zones.h:122
ZoneBase(MovementType type, int indx, CompositeMap domain, int coordDim)
Constructor.
Definition: Zones.cpp:47
std::vector< GeometrySharedPtr > m_elements
Vector of highest dimension zone elements.
Definition: Zones.h:124
virtual bool v_Move(NekDouble time) final
Virtual function for movement of the zone at.
Definition: Zones.cpp:279
LibUtilities::EquationSharedPtr m_zDeform
Equation specifying prescribed motion in z-direction.
Definition: Zones.h:291
LibUtilities::EquationSharedPtr m_yDeform
Equation specifying prescribed motion in y-direction.
Definition: Zones.h:289
virtual bool v_Move(NekDouble time) final
Virtual function for movement of the zone at.
Definition: Zones.cpp:285
LibUtilities::EquationSharedPtr m_xDeform
Equation specifying prescribed motion in x-direction.
Definition: Zones.h:287
DNekVec m_axis
Axis rotation is performed around.
Definition: Zones.h:169
NekDouble GetAngularVel(NekDouble &time) const
Return the angular velocity of the zone at.
Definition: Zones.cpp:180
ZoneRotate(int id, const CompositeMap &domain, const int coordDim, const NekPoint< NekDouble > &origin, const DNekVec &axis, const LibUtilities::EquationSharedPtr &angularVelEqn)
Definition: Zones.cpp:141
DNekMat m_W
W matrix Rodrigues' rotation formula, cross product of axis.
Definition: Zones.h:173
NekPoint< NekDouble > m_origin
Origin point rotation is performed around.
Definition: Zones.h:167
LibUtilities::EquationSharedPtr m_angularVelEqn
Equation defining angular velocity as a function of time.
Definition: Zones.h:171
virtual bool v_Move(NekDouble time) final
Virtual function for movement of the zone at.
Definition: Zones.cpp:186
DNekMat m_W2
W^2 matrix Rodrigues' rotation formula, cross product of axis squared.
Definition: Zones.h:175
virtual bool v_Move(NekDouble time) final
Virtual function for movement of the zone at.
Definition: Zones.cpp:234
std::vector< NekDouble > m_velocity
Definition: Zones.h:209