Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Nektar::SpatialDomains::GeometryLocator Class Reference

Inverts the mapping \(\chi:\xi\mapsto x\) for one geometry. More...

#include <GeometryLocator.h>

Inheritance diagram for Nektar::SpatialDomains::GeometryLocator:
[legend]

Public Member Functions

 GeometryLocator (Geometry *geom)
 
virtual ~GeometryLocator ()=default
 
void Build ()
 Populate the cache. Called by Create() once the concrete type exists, since it dispatches virtually.
 
Geometry * GetGeometry () const
 
std::array< NekDouble, 6 > GetBoundingBox ()
 Generates the bounding box for the element.
 
void ClearBoundingBox ()
 
bool ContainsPoint (const Array< OneD, const NekDouble > &gloCoord, NekDouble tol=0.0)
 Determine whether the element contains a Cartesian coordinate.
 
bool ContainsPoint (const Array< OneD, const NekDouble > &gloCoord, Array< OneD, NekDouble > &locCoord, NekDouble tol)
 Determine whether the element contains a Cartesian coordinate.
 
bool ContainsPoint (const Array< OneD, const NekDouble > &gloCoord, Array< OneD, NekDouble > &locCoord, NekDouble tol, NekDouble &dist)
 
NekDouble GetLocCoords (const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
 Determine the local collapsed coordinates corresponding to a given Cartesian coordinate.
 
NekDouble FindDistance (const Array< OneD, const NekDouble > &xs, Array< OneD, NekDouble > &xi)
 
int PreliminaryCheck (const Array< OneD, const NekDouble > &gloCoord, NekDouble &edgeDist)
 A fast and robust check if a given global coord is outside of a deformed element. For regular elements, this check is unnecessary.
 
bool MinMaxCheck (const Array< OneD, const NekDouble > &gloCoord)
 Check if given global coord is within the BoundingBox of the element.
 

Static Public Member Functions

static std::unique_ptr< GeometryLocator > Create (Geometry *geom)
 Build the locator appropriate to geom's dimension, with its cache already populated.
 
static bool ClampLocCoords (Array< OneD, NekDouble > &locCoord, int dim, NekDouble tol=std::numeric_limits< NekDouble >::epsilon())
 Clamp local coordinates into the reference element \([-1-tol,1+tol]^{dim}\), returning whether anything was clamped. Depends only on the reference element, so it needs no locator.
 

Protected Member Functions

virtual NekDouble v_GetLocCoords (const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
 
virtual NekDouble v_FindDistance (const Array< OneD, const NekDouble > &xs, Array< OneD, NekDouble > &xi)
 
virtual int v_AllLeftCheck (const Array< OneD, const NekDouble > &gloCoord, NekDouble &edgeDist)
 
virtual void v_CalculateInverseIsoParam ()
 
virtual void v_PreSolveStraightEdge ()
 

Protected Attributes

Geometry * m_geom
 The geometry being searched. Not owned.
 
IsoParam m_iso
 The shape's isoparametric coefficients. The straight-edged 2D solve rewrites them into a factored form, so the locator keeps its own copy rather than sharing the geometry's.
 
int m_straightEdge = 0
 Non-zero if every \(\chi\) basis is linear. Bits 1 and 2 are used by the 2D straight-edged solve to record which axes were swapped.
 
std::array< std::array< NekDouble, kMaxGeomDim >, kMaxGeomDim > m_invIsoParam {}
 Inverse of the linear part of m_iso, for regular elements.
 
bool m_newtonConverged = false
 Whether the Newton iteration of the last GetLocCoords call converged, i.e. whether its local coordinates map to the point. Set only by elements located by Newton iteration; read by ContainsPoint.
 
bool m_hasBoundingBox = false
 Element bounding box as (xmin, ymin, zmin, xmax, ymax, zmax).
 
std::array< NekDouble, 6 > m_boundingBox {}
 
bool m_edgeNormalBuilt = false
 2D only: inward edge normals used to reject points outside straight-sided elements. A curved edge gets no normal, so m_hasEdgeNormal records which entries are usable.
 
std::array< bool, kMaxGeomVerts > m_hasEdgeNormal {}
 
std::array< std::array< NekDouble, 2 >, kMaxGeomVerts > m_edgeNormal {}
 

Detailed Description

Inverts the mapping \(\chi:\xi\mapsto x\) for one geometry.

Point location – deciding whether an element contains a Cartesian coordinate, recovering the local coordinate that maps to it, or measuring the distance to it – is an algorithm applied to a geometry, not a property of one. For anything but an affine element it is a nonlinear solve, and it needs a cache of derived quantities to be quick. Neither the algorithm nor the cache belongs on Geometry, so both live here and are owned by whoever does the searching.

Build one with GeometryLocator::Create() and keep it for as long as the geometry is unchanged; it must not outlive the geometry it refers to. A locator is invalidated by anything that moves or re-curves the geometry, which is to say by any of the Geometry Reset entry points.

The concrete algorithms differ by the dimension of the shape rather than by the shape itself, which is why the subclasses are per-dimension.

Definition at line 102 of file GeometryLocator.h.

Constructor & Destructor Documentation

◆ GeometryLocator()

Nektar::SpatialDomains::GeometryLocator::GeometryLocator ( Geometry *  geom)
explicit

Definition at line 50 of file GeometryLocator.cpp.

50 : m_geom(geom)
51{
52 ASSERTL0(m_geom != nullptr, "A locator needs a geometry to search.");
53}
#define ASSERTL0(condition, msg)
Geometry * m_geom
The geometry being searched. Not owned.

References ASSERTL0, and m_geom.

◆ ~GeometryLocator()

virtual Nektar::SpatialDomains::GeometryLocator::~GeometryLocator ( )
virtualdefault

Member Function Documentation

◆ Build()

void Nektar::SpatialDomains::GeometryLocator::Build ( )

Populate the cache. Called by Create() once the concrete type exists, since it dispatches virtually.

Populate the cache of quantities derived from the geometry.

Separate from the constructor because it dispatches virtually: the inverse-coefficient and straight-edged forms differ by dimension.

Definition at line 61 of file GeometryLocator.cpp.

62{
64
65 // Classifying the geometry is exactly the test of whether the nonlinear
66 // isoparametric coefficients vanish, so this yields both at once.
68 {
70 }
71 else if (m_straightEdge)
72 {
74 }
75}
GeomType CalcGeomType()
Classify whether this shape is regular or deformed.
Definition Geometry.cpp:151
bool HasLinearXmap()
True if every basis is linear.
Definition Geometry.cpp:109
IsoParam m_iso
The shape's isoparametric coefficients. The straight-edged 2D solve rewrites them into a factored for...
int m_straightEdge
Non-zero if every basis is linear. Bits 1 and 2 are used by the 2D straight-edged solve to record wh...
@ eRegular
Geometry is straight-sided with constant geometric factors.

References Nektar::SpatialDomains::Geometry::CalcGeomType(), Nektar::SpatialDomains::eRegular, Nektar::SpatialDomains::Geometry::HasLinearXmap(), m_geom, m_iso, m_straightEdge, v_CalculateInverseIsoParam(), and v_PreSolveStraightEdge().

◆ ClampLocCoords()

bool Nektar::SpatialDomains::GeometryLocator::ClampLocCoords ( Array< OneD, NekDouble > &  locCoord,
int  dim,
NekDouble  tol = std::numeric_limits<NekDouble>::epsilon() 
)
static

Clamp local coordinates into the reference element \([-1-tol,1+tol]^{dim}\), returning whether anything was clamped. Depends only on the reference element, so it needs no locator.

Clamp local coords to be within standard regions [-1, 1]^dim.

Parameters
LcoordsCorresponding local coordinates

Definition at line 303 of file GeometryLocator.cpp.

305{
306 // Validation checks
307 ASSERTL1(locCoord.size() >= dim, "Expects local coordinates to be same or "
308 "larger than shape dimension.");
309
310 // If out of range clamp locCoord to be within [-1,1]^dim
311 // since any larger value will be very oscillatory if
312 // called by 'returnNearestElmt' option in
313 // ExpList::GetExpIndex
314 bool clamp = false;
315 for (int i = 0; i < dim; ++i)
316 {
317 if (!std::isfinite(locCoord[i]))
318 {
319 locCoord[i] = 0.;
320 clamp = true;
321 }
322 else if (locCoord[i] < -(1. + tol))
323 {
324 locCoord[i] = -(1. + tol);
325 clamp = true;
326 }
327 else if (locCoord[i] > (1. + tol))
328 {
329 locCoord[i] = 1. + tol;
330 clamp = true;
331 }
332 }
333 return clamp;
334}
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....

References ASSERTL1.

Referenced by ContainsPoint(), Nektar::SpatialDomains::GeometryLocator2D::NewtonIterationForLocCoord(), Nektar::SpatialDomains::GeometryLocator3D::NewtonIterationForLocCoord(), Nektar::FieldUtils::ProcessWallNormalData::NewtonIterForLocCoordOnBndElmt(), Nektar::SpatialDomains::GeometryLocator1D::v_FindDistance(), Nektar::SpatialDomains::GeometryLocator2D::v_FindDistance(), Nektar::SpatialDomains::GeometryLocator2D::v_GetLocCoords(), and Nektar::SpatialDomains::GeometryLocator3D::v_GetLocCoords().

◆ ClearBoundingBox()

void Nektar::SpatialDomains::GeometryLocator::ClearBoundingBox ( )

Definition at line 235 of file GeometryLocator.cpp.

236{
237 m_hasBoundingBox = false;
238}
bool m_hasBoundingBox
Element bounding box as (xmin, ymin, zmin, xmax, ymax, zmax).

References m_hasBoundingBox.

◆ ContainsPoint() [1/3]

bool Nektar::SpatialDomains::GeometryLocator::ContainsPoint ( const Array< OneD, const NekDouble > &  gloCoord,
Array< OneD, NekDouble > &  locCoord,
NekDouble  tol 
)

Determine whether the element contains a Cartesian coordinate.

See also
GeometryLocator::ContainsPoint

Definition at line 119 of file GeometryLocator.cpp.

122{
123 NekDouble dist;
124 return ContainsPoint(gloCoord, locCoord, tol, dist);
125}
bool ContainsPoint(const Array< OneD, const NekDouble > &gloCoord, NekDouble tol=0.0)
Determine whether the element contains a Cartesian coordinate.

References ContainsPoint().

◆ ContainsPoint() [2/3]

bool Nektar::SpatialDomains::GeometryLocator::ContainsPoint ( const Array< OneD, const NekDouble > &  gloCoord,
Array< OneD, NekDouble > &  locCoord,
NekDouble  tol,
NekDouble &  dist 
)

dist is assigned value for curved elements

Definition at line 342 of file GeometryLocator.cpp.

345{
346 NekDouble edgeDist;
347 int inside = PreliminaryCheck(gloCoord, edgeDist);
348 if (inside == -1)
349 {
350 dist = edgeDist;
351 if (edgeDist < std::numeric_limits<double>::max())
352 {
353 // Just outside a straight edge: not inside, but the element is
354 // a candidate nearest element. A point on a straight domain
355 // boundary is only on it to round-off, and no other element can
356 // contain it. Return the clamped local coordinates and the
357 // distance, so that GetExpIndex can still pick this element
358 // when no element contains the point.
359 NekDouble locDist = GetLocCoords(gloCoord, locCoord);
360 Array<OneD, NekDouble> eta(m_geom->GetShapeDim(), 0.);
361 m_geom->GetXmap()->LocCoordToLocCollapsed(locCoord, eta);
362 ClampLocCoords(eta, m_geom->GetShapeDim(), 0.);
363 m_geom->GetXmap()->LocCollapsedToLocCoord(eta, locCoord);
364 // Only curved elements measure a distance in GetLocCoords
365 if (locDist < std::numeric_limits<double>::max())
366 {
367 dist = std::max(dist, locDist);
368 }
369 }
370 return false;
371 }
372 dist = GetLocCoords(gloCoord, locCoord);
373 if (inside == 1)
374 {
375 dist = 0.;
376 return true;
377 }
378 else
379 {
380 Array<OneD, NekDouble> eta(m_geom->GetShapeDim(), 0.);
381 m_geom->GetXmap()->LocCoordToLocCollapsed(locCoord, eta);
382 if (ClampLocCoords(eta, m_geom->GetShapeDim(), tol))
383 {
384 // Return the clamped point, at which dist was measured: the
385 // caller may take it as the nearest point. Unclamped, a point
386 // just beyond a collapsed edge or vertex can have collapsed
387 // coordinates of any size, and the expansion is evaluated there.
388 m_geom->GetXmap()->LocCollapsedToLocCoord(eta, locCoord);
389 // A straight-sided 3D element's Newton iteration reports no
390 // distance to the element, only whether it converged, so it
391 // offers no nearest point. A straight-sided pyramid with a
392 // non-parallelogram base (m_nCoeff = 0) takes the full-map
393 // Newton iteration instead, which does measure the distance.
394 if (m_geom->CalcGeomType() == eRegular ||
395 (m_geom->GetShapeDim() == 3 && m_straightEdge &&
396 m_iso.m_nCoeff > 0))
397 {
398 dist = std::numeric_limits<double>::max();
399 }
400 return false;
401 }
402 // Elements located by Newton iteration: 2D curved, and 3D
403 if (m_geom->GetCoordim() == m_geom->GetShapeDim() &&
405 (m_geom->GetShapeDim() == 3 ||
406 (m_geom->GetShapeDim() == 2 && !m_straightEdge)))
407 {
408 // The point is within tol of the element, so it is inside if the
409 // local coordinates map to it. dist cannot tell: a converged
410 // point just outside keeps the distance from the clamped point,
411 // and one that did not converge keeps its residual (both used
412 // by GetExpIndex to rank the nearest element).
413 return m_newtonConverged;
414 }
415 return m_geom->GetCoordim() != 3 ||
418 dist <= tol;
419 }
420}
LibUtilities::ShapeType GetShapeType(void)
The shape this object is, as a LibUtilities::ShapeType.
Definition Geometry.h:460
int GetShapeDim() const
Dimension of the shape itself, which may be less than GetCoordim().
Definition Geometry.h:557
int GetCoordim() const
Dimension of the space this object is embedded in.
Definition Geometry.h:447
StdRegions::StdExpansion * GetXmap() const
The expansion holding the mapping from the standard element to this one. Shared between geometries a...
Definition Geometry.h:571
int PreliminaryCheck(const Array< OneD, const NekDouble > &gloCoord, NekDouble &edgeDist)
A fast and robust check if a given global coord is outside of a deformed element. For regular element...
NekDouble GetLocCoords(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
Determine the local collapsed coordinates corresponding to a given Cartesian coordinate.
static bool ClampLocCoords(Array< OneD, NekDouble > &locCoord, int dim, NekDouble tol=std::numeric_limits< NekDouble >::epsilon())
Clamp local coordinates into the reference element , returning whether anything was clamped....
bool m_newtonConverged
Whether the Newton iteration of the last GetLocCoords call converged, i.e. whether its local coordina...
void LocCoordToLocCollapsed(const Array< OneD, const NekDouble > &xi, Array< OneD, NekDouble > &eta)
Convert local cartesian coordinate xi into local collapsed coordinates eta.
void LocCollapsedToLocCoord(const Array< OneD, const NekDouble > &eta, Array< OneD, NekDouble > &xi)
Convert local collapsed coordinates eta into local cartesian coordinate xi.
@ eDeformed
Geometry is curved or has non-constant factors.
int m_nCoeff
Coefficients per coordinate direction. Only the leading m_nCoeff entries of each row are meaningful,...

References Nektar::SpatialDomains::Geometry::CalcGeomType(), ClampLocCoords(), Nektar::SpatialDomains::eDeformed, Nektar::LibUtilities::eQuadrilateral, Nektar::SpatialDomains::eRegular, Nektar::LibUtilities::eTriangle, Nektar::SpatialDomains::Geometry::GetCoordim(), GetLocCoords(), Nektar::SpatialDomains::Geometry::GetShapeDim(), Nektar::SpatialDomains::Geometry::GetShapeType(), Nektar::SpatialDomains::Geometry::GetXmap(), Nektar::StdRegions::StdExpansion::LocCollapsedToLocCoord(), Nektar::StdRegions::StdExpansion::LocCoordToLocCollapsed(), m_geom, m_iso, Nektar::SpatialDomains::IsoParam::m_nCoeff, m_newtonConverged, m_straightEdge, and PreliminaryCheck().

◆ ContainsPoint() [3/3]

bool Nektar::SpatialDomains::GeometryLocator::ContainsPoint ( const Array< OneD, const NekDouble > &  gloCoord,
NekDouble  tol = 0.0 
)

Determine whether the element contains a Cartesian coordinate.

See also
GeometryLocator::ContainsPoint

Definition at line 108 of file GeometryLocator.cpp.

110{
111 Array<OneD, NekDouble> locCoord(m_geom->GetCoordim(), 0.0);
112 NekDouble dist;
113 return ContainsPoint(gloCoord, locCoord, tol, dist);
114}

References ContainsPoint(), Nektar::SpatialDomains::Geometry::GetCoordim(), and m_geom.

Referenced by ContainsPoint(), and ContainsPoint().

◆ Create()

GeometryLocatorUniquePtr Nektar::SpatialDomains::GeometryLocator::Create ( Geometry *  geom)
static

Build the locator appropriate to geom's dimension, with its cache already populated.

Definition at line 77 of file GeometryLocator.cpp.

78{
79 ASSERTL0(geom != nullptr, "A locator needs a geometry to search.");
80
82 switch (geom->GetShapeDim())
83 {
84 case 1:
85 loc = std::make_unique<GeometryLocator1D>(geom);
86 break;
87 case 2:
88 loc = std::make_unique<GeometryLocator2D>(geom);
89 break;
90 case 3:
91 loc = std::make_unique<GeometryLocator3D>(geom);
92 break;
93 default:
95 "No inverse mapping for this shape dimension.");
96 return loc;
97 }
98
99 loc->Build();
100 return loc;
101}
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
std::unique_ptr< GeometryLocator > GeometryLocatorUniquePtr

References ASSERTL0, Nektar::ErrorUtil::efatal, Nektar::SpatialDomains::Geometry::GetShapeDim(), and NEKERROR.

Referenced by Geometry_ContainsPoint(), Nektar::LocalRegions::Expansion::GetLocator(), Nektar::SpatialDomains::MeshGraph::GeomRTree::InsertGeom(), and Nektar::PyrInverseMapTests::WorstRoundTrip().

◆ FindDistance()

NekDouble Nektar::SpatialDomains::GeometryLocator::FindDistance ( const Array< OneD, const NekDouble > &  xs,
Array< OneD, NekDouble > &  xi 
)

Definition at line 145 of file GeometryLocator.cpp.

147{
148 return v_FindDistance(xs, xi);
149}
virtual NekDouble v_FindDistance(const Array< OneD, const NekDouble > &xs, Array< OneD, NekDouble > &xi)

References v_FindDistance().

◆ GetBoundingBox()

std::array< NekDouble, 6 > Nektar::SpatialDomains::GeometryLocator::GetBoundingBox ( )

Generates the bounding box for the element.

For regular elements, the vertices are sufficient to define the extent of the bounding box. For non-regular elements, the extremes of the quadrature point coordinates are used. A 10% margin is added around this computed region to account for convex hull elements where the true extent of the element may extend slightly beyond the quadrature points.

Definition at line 160 of file GeometryLocator.cpp.

161{
162
164 {
165 return {{m_boundingBox[0], m_boundingBox[1], m_boundingBox[2],
167 }
168 // NekDouble minx, miny, minz, maxx, maxy, maxz;
169 Array<OneD, NekDouble> min(3), max(3);
170
171 // Always get vertexes min/max
172 PointGeom *p = m_geom->GetVertex(0);
173 Array<OneD, NekDouble> x(3, 0.0);
174 p->GetCoords(x[0], x[1], x[2]);
175 for (int j = 0; j < 3; ++j)
176 {
177 min[j] = x[j];
178 max[j] = x[j];
179 }
180 for (int i = 1; i < m_geom->GetNumVerts(); ++i)
181 {
182 p = m_geom->GetVertex(i);
183 p->GetCoords(x[0], x[1], x[2]);
184 for (int j = 0; j < 3; ++j)
185 {
186 min[j] = (x[j] < min[j] ? x[j] : min[j]);
187 max[j] = (x[j] > max[j] ? x[j] : max[j]);
188 }
189 }
190 // If element is deformed loop over quadrature points
192 if (m_geom->CalcGeomType() != eRegular)
193 {
194 marginFactor = 0.1;
195 const int nq = m_geom->GetXmap()->GetTotPoints();
196 Array<OneD, Array<OneD, NekDouble>> xvec(3);
197 for (int j = 0; j < 3; ++j)
198 {
199 xvec[j] = Array<OneD, NekDouble>(nq, 0.0);
200 }
201 for (int j = 0; j < m_geom->GetCoordim(); ++j)
202 {
203 m_geom->GetXmap()->BwdTrans(m_geom->GetCoeffs(j), xvec[j]);
204 }
205 for (int j = 0; j < 3; ++j)
206 {
207 for (int i = 0; i < nq; ++i)
208 {
209 min[j] = (xvec[j][i] < min[j] ? xvec[j][i] : min[j]);
210 max[j] = (xvec[j][i] > max[j] ? xvec[j][i] : max[j]);
211 }
212 }
213 }
214 // Add margin to bounding box, in order to
215 // return the nearest element
216 for (int j = 0; j < 3; ++j)
217 {
218 NekDouble margin =
219 marginFactor * (max[j] - min[j]) + NekConstants::kFindDistanceMin;
220 min[j] -= margin;
221 max[j] += margin;
222 }
223
224 // save bounding box
225 m_hasBoundingBox = true;
226 for (int j = 0; j < 3; ++j)
227 {
228 m_boundingBox[j] = min[j];
229 m_boundingBox[j + 3] = max[j];
230 }
231 // Return bounding box
232 return {{min[0], min[1], min[2], max[0], max[1], max[2]}};
233}
PointGeom * GetVertex(int i) const
Get vertex i of this object.
Definition Geometry.h:495
int GetNumVerts() const
Get the number of vertices of this object.
Definition Geometry.h:520
const Array< OneD, const NekDouble > & GetCoeffs(const int i)
The coefficients of in coordinate direction i, filling them first if that has not happened yet.
Definition Geometry.h:576
std::array< NekDouble, 6 > m_boundingBox
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
void BwdTrans(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray)
This function performs the Backward transformation from coefficient space to physical space.
static const NekDouble kGeomFactorsTol
static const NekDouble kFindDistanceMin
std::vector< double > p(NPUPPER)
scalarT< T > max(scalarT< T > lhs, scalarT< T > rhs)
Definition scalar.hpp:304
scalarT< T > min(scalarT< T > lhs, scalarT< T > rhs)
Definition scalar.hpp:299

References Nektar::StdRegions::StdExpansion::BwdTrans(), Nektar::SpatialDomains::Geometry::CalcGeomType(), Nektar::SpatialDomains::eRegular, Nektar::SpatialDomains::Geometry::GetCoeffs(), Nektar::SpatialDomains::Geometry::GetCoordim(), Nektar::SpatialDomains::Geometry::GetNumVerts(), Nektar::StdRegions::StdExpansion::GetTotPoints(), Nektar::SpatialDomains::Geometry::GetVertex(), Nektar::SpatialDomains::Geometry::GetXmap(), Nektar::NekConstants::kFindDistanceMin, Nektar::NekConstants::kGeomFactorsTol, m_boundingBox, m_geom, m_hasBoundingBox, tinysimd::max(), and tinysimd::min().

Referenced by MinMaxCheck().

◆ GetGeometry()

Geometry * Nektar::SpatialDomains::GeometryLocator::GetGeometry ( ) const
inline

Definition at line 117 of file GeometryLocator.h.

118 {
119 return m_geom;
120 }

References m_geom.

◆ GetLocCoords()

NekDouble Nektar::SpatialDomains::GeometryLocator::GetLocCoords ( const Array< OneD, const NekDouble > &  coords,
Array< OneD, NekDouble > &  Lcoords 
)

Determine the local collapsed coordinates corresponding to a given Cartesian coordinate.

For curvilinear and non-affine elements this is a nonlinear optimisation problem solved by Newton iteration, so it can be expensive.

Parameters
coordsInput Cartesian global coordinates
LcoordsCorresponding local coordinates
Returns
Distance between the obtained coordinates and the provided ones.

Definition at line 139 of file GeometryLocator.cpp.

141{
142 return v_GetLocCoords(coords, Lcoords);
143}
virtual NekDouble v_GetLocCoords(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)

References v_GetLocCoords().

Referenced by ContainsPoint(), Nektar::SpatialDomains::GeometryLocator1D::v_FindDistance(), Nektar::SpatialDomains::GeometryLocator2D::v_FindDistance(), Nektar::LocalRegions::HexExp::v_PhysEvalFirstDeriv(), Nektar::LocalRegions::PrismExp::v_PhysEvalFirstDeriv(), Nektar::LocalRegions::PyrExp::v_PhysEvalFirstDeriv(), Nektar::LocalRegions::QuadExp::v_PhysEvalFirstDeriv(), Nektar::LocalRegions::SegExp::v_PhysEvalFirstDeriv(), Nektar::LocalRegions::TetExp::v_PhysEvalFirstDeriv(), Nektar::LocalRegions::TriExp::v_PhysEvalFirstDeriv(), Nektar::LocalRegions::SegExp::v_PhysEvalFirstSecondDeriv(), and Nektar::LocalRegions::Expansion::v_PhysEvaluate().

◆ MinMaxCheck()

bool Nektar::SpatialDomains::GeometryLocator::MinMaxCheck ( const Array< OneD, const NekDouble > &  gloCoord)

Check if given global coord is within the BoundingBox of the element.

Parameters
coordsInput Cartesian global coordinates
Returns
True if within distance or False otherwise.

Definition at line 280 of file GeometryLocator.cpp.

281{
282 // Validation checks
283 ASSERTL1(gloCoord.size() >= m_geom->GetCoordim(),
284 "Expects number of global coordinates supplied to be greater than "
285 "or equal to the mesh dimension.");
286
287 std::array<NekDouble, 6> minMax = GetBoundingBox();
288 for (int i = 0; i < m_geom->GetCoordim(); ++i)
289 {
290 if ((gloCoord[i] < minMax[i]) || (gloCoord[i] > minMax[i + 3]))
291 {
292 return false;
293 }
294 }
295 return true;
296}
std::array< NekDouble, 6 > GetBoundingBox()
Generates the bounding box for the element.

References ASSERTL1, GetBoundingBox(), Nektar::SpatialDomains::Geometry::GetCoordim(), and m_geom.

Referenced by PreliminaryCheck().

◆ PreliminaryCheck()

int Nektar::SpatialDomains::GeometryLocator::PreliminaryCheck ( const Array< OneD, const NekDouble > &  gloCoord,
NekDouble &  edgeDist 
)

A fast and robust check if a given global coord is outside of a deformed element. For regular elements, this check is unnecessary.

Parameters
coordsInput Cartesian global coordinates
edgeDistFor a point just outside straight edges of the element (see v_AllLeftCheck), its distance from them. Otherwise the largest double.
Returns
1 is inside of the element. 0 maybe inside -1 outside of the element

Definition at line 253 of file GeometryLocator.cpp.

255{
256 edgeDist = std::numeric_limits<double>::max();
257 // bounding box check
258 if (!MinMaxCheck(gloCoord))
259 {
260 return -1;
261 }
262
263 // regular element check
264 if (m_geom->CalcGeomType() == eRegular)
265 {
266 return 0;
267 }
268
269 // All left check for straight edges/plane surfaces
270 return v_AllLeftCheck(gloCoord, edgeDist);
271}
bool MinMaxCheck(const Array< OneD, const NekDouble > &gloCoord)
Check if given global coord is within the BoundingBox of the element.
virtual int v_AllLeftCheck(const Array< OneD, const NekDouble > &gloCoord, NekDouble &edgeDist)

References Nektar::SpatialDomains::Geometry::CalcGeomType(), Nektar::SpatialDomains::eRegular, m_geom, MinMaxCheck(), and v_AllLeftCheck().

Referenced by ContainsPoint().

◆ v_AllLeftCheck()

int Nektar::SpatialDomains::GeometryLocator::v_AllLeftCheck ( const Array< OneD, const NekDouble > &  gloCoord,
NekDouble &  edgeDist 
)
protectedvirtual

Reimplemented in Nektar::SpatialDomains::GeometryLocator2D.

Definition at line 443 of file GeometryLocator.cpp.

446{
447 return 0;
448}

Referenced by PreliminaryCheck().

◆ v_CalculateInverseIsoParam()

void Nektar::SpatialDomains::GeometryLocator::v_CalculateInverseIsoParam ( )
protectedvirtual

Nothing to do by default. Build() drives this for every shape, but only the 2D and 3D inverse maps are expressed through an inverted coefficient matrix; a segment inverts \(\chi\) in closed form straight from its quadrature points.

See also
Geometry1D::v_GetLocCoords

Nothing to do by default. Build() drives this for every shape, but only the 2D and 3D inverse maps are expressed through an inverted coefficient matrix; a segment inverts \(\chi\) in closed form straight from its quadrature points.

See also
Geometry1D::v_GetLocCoords

Reimplemented in Nektar::SpatialDomains::GeometryLocator2D, and Nektar::SpatialDomains::GeometryLocator3D.

Definition at line 460 of file GeometryLocator.cpp.

461{
462}

Referenced by Build().

◆ v_FindDistance()

NekDouble Nektar::SpatialDomains::GeometryLocator::v_FindDistance ( const Array< OneD, const NekDouble > &  xs,
Array< OneD, NekDouble > &  xi 
)
protectedvirtual

Reimplemented in Nektar::SpatialDomains::GeometryLocator1D, and Nektar::SpatialDomains::GeometryLocator2D.

Definition at line 434 of file GeometryLocator.cpp.

437{
439 "This function has not been defined for this geometry");
440 return false;
441}

References Nektar::ErrorUtil::efatal, and NEKERROR.

Referenced by FindDistance().

◆ v_GetLocCoords()

NekDouble Nektar::SpatialDomains::GeometryLocator::v_GetLocCoords ( const Array< OneD, const NekDouble > &  coords,
Array< OneD, NekDouble > &  Lcoords 
)
protectedvirtual

Reimplemented in Nektar::SpatialDomains::GeometryLocator1D, Nektar::SpatialDomains::GeometryLocator2D, and Nektar::SpatialDomains::GeometryLocator3D.

Definition at line 425 of file GeometryLocator.cpp.

428{
430 "This function is only valid for expansion type geometries");
431 return 0.0;
432}

References Nektar::ErrorUtil::efatal, and NEKERROR.

Referenced by GetLocCoords().

◆ v_PreSolveStraightEdge()

void Nektar::SpatialDomains::GeometryLocator::v_PreSolveStraightEdge ( )
protectedvirtual

Only the quadrilateral has a straight-edged solve to prepare for.

Only the quadrilateral has a straight-edged solve to prepare for.

Reimplemented in Nektar::SpatialDomains::GeometryLocator2D.

Definition at line 469 of file GeometryLocator.cpp.

470{
471}

Referenced by Build().

Member Data Documentation

◆ m_boundingBox

std::array<NekDouble, 6> Nektar::SpatialDomains::GeometryLocator::m_boundingBox {}
protected

Definition at line 177 of file GeometryLocator.h.

177{};

Referenced by GetBoundingBox().

◆ m_edgeNormal

std::array<std::array<NekDouble, 2>, kMaxGeomVerts> Nektar::SpatialDomains::GeometryLocator::m_edgeNormal {}
protected

Definition at line 184 of file GeometryLocator.h.

184{};

Referenced by Nektar::SpatialDomains::GeometryLocator2D::v_AllLeftCheck().

◆ m_edgeNormalBuilt

bool Nektar::SpatialDomains::GeometryLocator::m_edgeNormalBuilt = false
protected

2D only: inward edge normals used to reject points outside straight-sided elements. A curved edge gets no normal, so m_hasEdgeNormal records which entries are usable.

Definition at line 182 of file GeometryLocator.h.

Referenced by Nektar::SpatialDomains::GeometryLocator2D::v_AllLeftCheck().

◆ m_geom

Geometry* Nektar::SpatialDomains::GeometryLocator::m_geom
protected

◆ m_hasBoundingBox

bool Nektar::SpatialDomains::GeometryLocator::m_hasBoundingBox = false
protected

Element bounding box as (xmin, ymin, zmin, xmax, ymax, zmax).

Definition at line 176 of file GeometryLocator.h.

Referenced by ClearBoundingBox(), and GetBoundingBox().

◆ m_hasEdgeNormal

std::array<bool, kMaxGeomVerts> Nektar::SpatialDomains::GeometryLocator::m_hasEdgeNormal {}
protected

Definition at line 183 of file GeometryLocator.h.

183{};

Referenced by Nektar::SpatialDomains::GeometryLocator2D::v_AllLeftCheck().

◆ m_invIsoParam

std::array<std::array<NekDouble, kMaxGeomDim>, kMaxGeomDim> Nektar::SpatialDomains::GeometryLocator::m_invIsoParam {}
protected

◆ m_iso

IsoParam Nektar::SpatialDomains::GeometryLocator::m_iso
protected

◆ m_newtonConverged

bool Nektar::SpatialDomains::GeometryLocator::m_newtonConverged = false
protected

Whether the Newton iteration of the last GetLocCoords call converged, i.e. whether its local coordinates map to the point. Set only by elements located by Newton iteration; read by ContainsPoint.

Definition at line 173 of file GeometryLocator.h.

Referenced by ContainsPoint(), Nektar::SpatialDomains::GeometryLocator3D::NewtonIterationForLocCoord(), Nektar::SpatialDomains::GeometryLocator2D::NewtonIterationForLocCoord(), and Nektar::SpatialDomains::GeometryLocator3D::NewtonIterationForLocCoord().

◆ m_straightEdge

int Nektar::SpatialDomains::GeometryLocator::m_straightEdge = 0
protected