Nektar++
Loading...
Searching...
No Matches
Geometry.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: Geometry.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: This file contains the base class implementation for the
32// Geometry class.
33//
34//
35////////////////////////////////////////////////////////////////////////////////
36
40
42{
43
44/**
45 * @brief Default constructor.
46 */
48 : m_coordim(0), m_state(eNotFilled), m_setupState(false),
49 m_shapeType(LibUtilities::eNoShapeType), m_globalID(-1), m_straightEdge(0)
50{
51}
52
53/**
54 * @brief Constructor when supplied a coordinate dimension.
55 */
56Geometry::Geometry(const int coordim)
57 : m_coordim(coordim), m_state(eNotFilled), m_setupState(false),
58 m_shapeType(LibUtilities::eNoShapeType), m_globalID(-1), m_straightEdge(0)
59{
60}
61
62bool SortByGlobalId(const Geometry *&lhs, const Geometry *&rhs)
63{
64 return lhs->GetGlobalID() < rhs->GetGlobalID();
65}
66
67bool GlobalIdEquality(const Geometry *&lhs, const Geometry *&rhs)
68{
69 return lhs->GetGlobalID() == rhs->GetGlobalID();
70}
71
72/**
73 * @brief Get the ID of vertex @p i of this object.
74 */
75int Geometry::v_GetVid(int i) const
76{
77 return GetVertex(i)->GetGlobalID();
78}
79
80/**
81 * @brief Get the ID of edge @p i of this object.
82 */
83int Geometry::GetEid(int i) const
84{
85 return GetEdge(i)->GetGlobalID();
86}
87
88/**
89 * @brief Get the ID of face @p i of this object.
90 */
91int Geometry::GetFid(int i) const
92{
93 return GetFace(i)->GetGlobalID();
94}
95
96/**
97 * @copydoc Geometry::GetVertex()
98 */
99PointGeom *Geometry::v_GetVertex([[maybe_unused]] const int i) const
100{
102 "This function is only valid for shape type geometries");
103 return nullptr;
104}
105
106/**
107 * @copydoc Geometry::GetEdge()
108 */
109Geometry1D *Geometry::v_GetEdge([[maybe_unused]] const int i) const
110{
112 "This function is only valid for shape type geometries");
113 return nullptr;
114}
115
116/**
117 * @copydoc Geometry::GetFace()
118 */
119Geometry2D *Geometry::v_GetFace([[maybe_unused]] const int i) const
120{
122 "This function is only valid for shape type geometries");
123 return nullptr;
124}
125
126/**
127 * @copydoc Geometry::GetNumVerts()
128 */
130{
132 "This function is only valid for shape type geometries");
133 return 0;
134}
135
136/**
137 * @copydoc Geometry::GetEorient()
138 */
140 [[maybe_unused]] const int i) const
141{
143 "This function is not valid for this geometry.");
145}
146
147/**
148 * @copydoc Geometry::GetForient()
149 */
151 [[maybe_unused]] const int i) const
152{
154 "This function is not valid for this geometry.");
155 return StdRegions::eFwd;
156}
157
158/**
159 * @copydoc Geometry::GetNumEdges()
160 */
162{
163 return 0;
164}
165
166/**
167 * @copydoc Geometry::GetNumFaces()
168 */
170{
171 return 0;
172}
173
174/**
175 * @copydoc Geometry::GetShapeDim()
176 */
178{
180 "This function is only valid for shape type geometries");
181 return 0;
182}
183
184/**
185 * Calculates the GeomType (deformed, regular etc).
186 */
188{
190 "This function is only valid for shape type geometries");
191 return eNoGeomType;
192}
193
194/**
195 * @copydoc Geometry::GenGeomFactors()
196 */
198 [[maybe_unused]] LibUtilities::PointsKeyVector &keyTgt)
199{
201 "This function is only valid for shape type geometries");
202 return GeomFactorsUniquePtr();
203}
204
206 [[maybe_unused]] const Array<OneD, const NekDouble> &gloCoord)
207{
208 return 0;
209}
210
212{
214 "This function is only valid for shape type geometries");
215}
216
217/**
218 * @copydoc Geometry::GetXmap()
219 */
224
225/**
226 * @copydoc Geometry::ContainsPoint(
227 * const Array<OneD, const NekDouble> &, Array<OneD, NekDouble> &,
228 * NekDouble, NekDouble&)
229 * dist is assigned value for curved elements
230 */
232 Array<OneD, NekDouble> &locCoord, NekDouble tol,
233 NekDouble &dist)
234{
235 int inside = PreliminaryCheck(gloCoord);
236 if (inside == -1)
237 {
238 dist = std::numeric_limits<double>::max();
239 return false;
240 }
241 dist = GetLocCoords(gloCoord, locCoord);
242 if (inside == 1)
243 {
244 dist = 0.;
245 return true;
246 }
247 else
248 {
250 m_xmap->LocCoordToLocCollapsed(locCoord, eta);
251 if (ClampLocCoords(eta, tol))
252 {
253 if (CalcGeomType() == eRegular)
254 {
255 dist = std::numeric_limits<double>::max();
256 }
257 return false;
258 }
259 return 3 != m_coordim ||
262 dist <= tol;
263 }
264}
265
267 [[maybe_unused]] const Array<OneD, const NekDouble> &xs,
268 [[maybe_unused]] Array<OneD, NekDouble> &xi)
269{
271 "This function has not been defined for this geometry");
272 return false;
273}
274
275/**
276 * @copydoc Geometry::GetVertexEdgeMap()
277 */
278int Geometry::v_GetVertexEdgeMap([[maybe_unused]] const int i,
279 [[maybe_unused]] const int j) const
280{
282 "This function has not been defined for this geometry");
283 return 0;
284}
285
286/**
287 * @copydoc Geometry::GetVertexFaceMap()
288 */
289int Geometry::v_GetVertexFaceMap([[maybe_unused]] const int i,
290 [[maybe_unused]] const int j) const
291{
293 "This function has not been defined for this geometry");
294 return 0;
295}
296
297/**
298 * @copydoc Geometry::GetEdgeFaceMap()
299 */
300int Geometry::v_GetEdgeFaceMap([[maybe_unused]] const int i,
301 [[maybe_unused]] const int j) const
302{
304 "This function has not been defined for this geometry");
305 return 0;
306}
307
308/**
309 * @copydoc Geometry::GetEdgeNormalToFaceVert()
310 */
311int Geometry::v_GetEdgeNormalToFaceVert([[maybe_unused]] const int i,
312 [[maybe_unused]] const int j) const
313{
315 "This function has not been defined for this geometry");
316 return 0;
317}
318
319/**
320 * @copydoc Geometry::GetDir()
321 */
322int Geometry::v_GetDir([[maybe_unused]] const int i,
323 [[maybe_unused]] const int j) const
324{
326 "This function has not been defined for this geometry");
327 return 0;
328}
329
330/**
331 * @copydoc Geometry::GetCoord()
332 */
334 [[maybe_unused]] const int i,
335 [[maybe_unused]] const Array<OneD, const NekDouble> &Lcoord)
336{
338 "This function is only valid for expansion type geometries");
339 return 0.0;
340}
341
342/**
343 * @copydoc Geometry::GetLocCoords()
344 */
346 [[maybe_unused]] const Array<OneD, const NekDouble> &coords,
347 [[maybe_unused]] Array<OneD, NekDouble> &Lcoords)
348{
350 "This function is only valid for expansion type geometries");
351 return 0.0;
352}
353
354/**
355 * @copydoc Geometry::FillGeom()
356 */
358{
360 "This function is only valid for expansion type geometries");
361}
362
363/**
364 * @copydoc Geometry::Reset()
365 */
366void Geometry::v_Reset([[maybe_unused]] CurveMap &curvedEdges,
367 [[maybe_unused]] CurveMap &curvedFaces)
368{
369 // Reset state
371}
372
374{
376 "This function is only valid for expansion type geometries");
377}
378
379/**
380 * @brief Generates the bounding box for the element.
381 *
382 * For regular elements, the vertices are sufficient to define the extent of
383 * the bounding box. For non-regular elements, the extremes of the quadrature
384 * point coordinates are used. A 10% margin is added around this computed
385 * region to account for convex hull elements where the true extent of the
386 * element may extend slightly beyond the quadrature points.
387 */
388std::array<NekDouble, 6> Geometry::GetBoundingBox()
389{
390 if (m_boundingBox.size() == 6)
391 {
392 return {{m_boundingBox[0], m_boundingBox[1], m_boundingBox[2],
394 }
395 // NekDouble minx, miny, minz, maxx, maxy, maxz;
397
398 // Always get vertexes min/max
399 PointGeom *p = GetVertex(0);
400 Array<OneD, NekDouble> x(3, 0.0);
401 p->GetCoords(x[0], x[1], x[2]);
402 for (int j = 0; j < 3; ++j)
403 {
404 min[j] = x[j];
405 max[j] = x[j];
406 }
407 for (int i = 1; i < GetNumVerts(); ++i)
408 {
409 p = GetVertex(i);
410 p->GetCoords(x[0], x[1], x[2]);
411 for (int j = 0; j < 3; ++j)
412 {
413 min[j] = (x[j] < min[j] ? x[j] : min[j]);
414 max[j] = (x[j] > max[j] ? x[j] : max[j]);
415 }
416 }
417 // If element is deformed loop over quadrature points
419 if (CalcGeomType() != eRegular)
420 {
421 marginFactor = 0.1;
422 const int nq = GetXmap()->GetTotPoints();
424 for (int j = 0; j < 3; ++j)
425 {
426 xvec[j] = Array<OneD, NekDouble>(nq, 0.0);
427 }
428 for (int j = 0; j < GetCoordim(); ++j)
429 {
430 GetXmap()->BwdTrans(m_coeffs[j], xvec[j]);
431 }
432 for (int j = 0; j < 3; ++j)
433 {
434 for (int i = 0; i < nq; ++i)
435 {
436 min[j] = (xvec[j][i] < min[j] ? xvec[j][i] : min[j]);
437 max[j] = (xvec[j][i] > max[j] ? xvec[j][i] : max[j]);
438 }
439 }
440 }
441 // Add margin to bounding box, in order to
442 // return the nearest element
443 for (int j = 0; j < 3; ++j)
444 {
445 NekDouble margin =
446 marginFactor * (max[j] - min[j]) + NekConstants::kFindDistanceMin;
447 min[j] -= margin;
448 max[j] += margin;
449 }
450
451 // save bounding box
453 for (int j = 0; j < 3; ++j)
454 {
455 m_boundingBox[j] = min[j];
456 m_boundingBox[j + 3] = max[j];
457 }
458 // Return bounding box
459 return {{min[0], min[1], min[2], max[0], max[1], max[2]}};
460}
461
463{
464 m_boundingBox = {};
465}
466
467/**
468 * @brief A fast and robust check if a given global coord is outside of a
469 * deformed element. For regular elements, this check is unnecessary.
470 *
471 * @param coords Input Cartesian global coordinates
472 *
473 * @return 1 is inside of the element.
474 * 0 maybe inside
475 * -1 outside of the element
476 */
478{
479 // bounding box check
480 if (!MinMaxCheck(gloCoord))
481 {
482 return -1;
483 }
484
485 // regular element check
486 if (CalcGeomType() == eRegular)
487 {
488 return 0;
489 }
490
491 // All left check for straight edges/plane surfaces
492 return v_AllLeftCheck(gloCoord);
493}
494
495/**
496 * @brief Check if given global coord is within the BoundingBox of the element.
497 *
498 * @param coords Input Cartesian global coordinates
499 *
500 * @return True if within distance or False otherwise.
501 */
503{
504 // Validation checks
505 ASSERTL1(gloCoord.size() >= m_coordim,
506 "Expects number of global coordinates supplied to be greater than "
507 "or equal to the mesh dimension.");
508
509 std::array<NekDouble, 6> minMax = GetBoundingBox();
510 for (int i = 0; i < m_coordim; ++i)
511 {
512 if ((gloCoord[i] < minMax[i]) || (gloCoord[i] > minMax[i + 3]))
513 {
514 return false;
515 }
516 }
517 return true;
518}
519
520/**
521 * @brief Clamp local coords to be within standard regions [-1, 1]^dim.
522 *
523 * @param Lcoords Corresponding local coordinates
524 */
526{
527 // Validation checks
528 ASSERTL1(locCoord.size() >= GetShapeDim(),
529 "Expects local coordinates to be same or "
530 "larger than shape dimension.");
531
532 // If out of range clamp locCoord to be within [-1,1]^dim
533 // since any larger value will be very oscillatory if
534 // called by 'returnNearestElmt' option in
535 // ExpList::GetExpIndex
536 bool clamp = false;
537 for (int i = 0; i < GetShapeDim(); ++i)
538 {
539 if (!std::isfinite(locCoord[i]))
540 {
541 locCoord[i] = 0.;
542 clamp = true;
543 }
544 else if (locCoord[i] < -(1. + tol))
545 {
546 locCoord[i] = -(1. + tol);
547 clamp = true;
548 }
549 else if (locCoord[i] > (1. + tol))
550 {
551 locCoord[i] = 1. + tol;
552 clamp = true;
553 }
554 }
555 return clamp;
556}
557
558} // namespace Nektar::SpatialDomains
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
1D geometry information
Definition Geometry1D.h:49
2D geometry information
Definition Geometry2D.h:50
Base class for shape geometry information.
Definition Geometry.h:84
virtual int v_GetNumEdges() const
Get the number of edges of this object.
Definition Geometry.cpp:161
virtual StdRegions::Orientation v_GetForient(const int i) const
Returns the orientation of face i with respect to the ordering of faces in the standard element.
Definition Geometry.cpp:150
virtual NekDouble v_GetCoord(const int i, const Array< OneD, const NekDouble > &Lcoord)
Given local collapsed coordinate Lcoord, return the value of physical coordinate in direction i.
Definition Geometry.cpp:333
Array< OneD, NekDouble > m_boundingBox
Array containing bounding box.
Definition Geometry.h:198
GeomState m_state
Enumeration to dictate whether coefficients are filled.
Definition Geometry.h:188
virtual void v_CalculateInverseIsoParam()
Definition Geometry.cpp:211
virtual int v_AllLeftCheck(const Array< OneD, const NekDouble > &gloCoord)
Definition Geometry.cpp:205
NekDouble GetLocCoords(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
Determine the local collapsed coordinates that correspond to a given Cartesian coordinate for this ge...
Definition Geometry.h:549
int PreliminaryCheck(const Array< OneD, const NekDouble > &gloCoord)
A fast and robust check if a given global coord is outside of a deformed element. For regular element...
Definition Geometry.cpp:477
virtual int v_GetEdgeNormalToFaceVert(const int i, const int j) const
Returns the standard lement edge IDs that are normal to a given face vertex.
Definition Geometry.cpp:311
int GetShapeDim() const
Get the object's shape dimension.
Definition Geometry.h:422
virtual void v_FillGeom()
Populate the coordinate mapping Geometry::m_coeffs information from any children geometry elements.
Definition Geometry.cpp:357
Geometry()
Default constructor.
Definition Geometry.cpp:47
virtual NekDouble v_GetLocCoords(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
Determine the local collapsed coordinates that correspond to a given Cartesian coordinate for this ge...
Definition Geometry.cpp:345
virtual int v_GetNumFaces() const
Get the number of faces of this object.
Definition Geometry.cpp:169
virtual StdRegions::StdExpansionSharedPtr v_GetXmap() const
Return the mapping object Geometry::m_xmap that represents the coordinate transformation from standar...
Definition Geometry.cpp:220
virtual void v_Reset(CurveMap &curvedEdges, CurveMap &curvedFaces)
Reset this geometry object: unset the current state, zero Geometry::m_coeffs and remove allocated Geo...
Definition Geometry.cpp:366
bool ClampLocCoords(Array< OneD, NekDouble > &locCoord, NekDouble tol=std::numeric_limits< NekDouble >::epsilon())
Clamp local coords to be within standard regions [-1, 1]^dim.
Definition Geometry.cpp:525
int GetGlobalID(void) const
Get the ID of this object.
Definition Geometry.h:314
PointGeom * GetVertex(int i) const
Returns vertex i of this object.
Definition Geometry.h:353
int GetCoordim() const
Return the coordinate dimension of this object (i.e. the dimension of the space in which this object ...
Definition Geometry.h:277
int GetFid(int i) const
Get the ID of face i of this object.
Definition Geometry.cpp:91
std::vector< Array< OneD, NekDouble > > m_coeffs
Array containing expansion coefficients of m_xmap.
Definition Geometry.h:196
virtual int v_GetEdgeFaceMap(int i, int j) const
Returns the standard element edge IDs that are connected to a given face.
Definition Geometry.cpp:300
LibUtilities::ShapeType m_shapeType
Type of shape.
Definition Geometry.h:192
StdRegions::StdExpansionSharedPtr m_xmap
mapping containing isoparametric transformation.
Definition Geometry.h:186
virtual StdRegions::Orientation v_GetEorient(const int i) const
Returns the orientation of edge i with respect to the ordering of edges in the standard element.
Definition Geometry.cpp:139
StdRegions::StdExpansionSharedPtr GetXmap() const
Return the mapping object Geometry::m_xmap that represents the coordinate transformation from standar...
Definition Geometry.h:440
virtual PointGeom * v_GetVertex(const int i) const
Returns vertex i of this object.
Definition Geometry.cpp:99
std::array< NekDouble, 6 > GetBoundingBox()
Generates the bounding box for the element.
Definition Geometry.cpp:388
int GetNumVerts() const
Get the number of vertices of this object.
Definition Geometry.h:395
Geometry1D * GetEdge(int i) const
Returns edge i of this object.
Definition Geometry.h:361
Geometry2D * GetFace(int i) const
Returns face i of this object.
Definition Geometry.h:369
bool MinMaxCheck(const Array< OneD, const NekDouble > &gloCoord)
Check if given global coord is within the BoundingBox of the element.
Definition Geometry.cpp:502
virtual GeomType v_CalcGeomType()
Definition Geometry.cpp:187
virtual int v_GetVertexEdgeMap(int i, int j) const
Returns the standard element edge IDs that are connected to a given vertex.
Definition Geometry.cpp:278
virtual Geometry1D * v_GetEdge(const int i) const
Returns edge i of this object.
Definition Geometry.cpp:109
virtual NekDouble v_FindDistance(const Array< OneD, const NekDouble > &xs, Array< OneD, NekDouble > &xi)
Definition Geometry.cpp:266
virtual int v_GetNumVerts() const
Get the number of vertices of this object.
Definition Geometry.cpp:129
int m_coordim
Coordinate dimension of this geometry object.
Definition Geometry.h:184
virtual int v_GetDir(const int faceidx, const int facedir) const
Returns the element coordinate direction corresponding to a given face coordinate direction.
Definition Geometry.cpp:322
virtual Geometry2D * v_GetFace(const int i) const
Returns face i of this object.
Definition Geometry.cpp:119
virtual int v_GetVid(int i) const
Get the ID of vertex i of this object.
Definition Geometry.cpp:75
virtual int v_GetShapeDim() const
Get the object's shape dimension.
Definition Geometry.cpp:177
virtual int v_GetVertexFaceMap(int i, int j) const
Returns the standard element face IDs that are connected to a given vertex.
Definition Geometry.cpp:289
virtual bool v_ContainsPoint(const Array< OneD, const NekDouble > &gloCoord, Array< OneD, NekDouble > &locCoord, NekDouble tol, NekDouble &dist)
Determine whether an element contains a particular Cartesian coordinate .
Definition Geometry.cpp:231
int GetEid(int i) const
Get the ID of edge i of this object.
Definition Geometry.cpp:83
virtual GeomFactorsUniquePtr v_GenGeomFactors(LibUtilities::PointsKeyVector &keyTgt)
Used by Expansion to generate associated GeomFactors.
Definition Geometry.cpp:197
std::vector< PointsKey > PointsKeyVector
Definition Points.h:313
static const NekDouble kGeomFactorsTol
static const NekDouble kFindDistanceMin
bool GlobalIdEquality(const Geometry *&lhs, const Geometry *&rhs)
Definition Geometry.cpp:67
bool SortByGlobalId(const Geometry *&lhs, const Geometry *&rhs)
Less than operator to sort Geometry objects by global id when sorting STL containers.
Definition Geometry.cpp:62
unique_ptr_objpool< GeomFactors > GeomFactorsUniquePtr
Definition Geometry.h:62
std::map< int, CurveUniquePtr > CurveMap
Definition Geometry.h:71
GeomType
Indicates the type of element geometry.
@ eRegular
Geometry is straight-sided with constant geometric factors.
@ eNoGeomType
No type defined.
@ eNotFilled
Geometric information has not been generated.
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
scalarT< T > max(scalarT< T > lhs, scalarT< T > rhs)
Definition scalar.hpp:305
scalarT< T > min(scalarT< T > lhs, scalarT< T > rhs)
Definition scalar.hpp:300