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

3D geometry information More...

#include <Geometry3D.h>

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

Public Member Functions

 Geometry3D ()
 
 Geometry3D (const int coordim)
 
 ~Geometry3D () override=default
 
- Public Member Functions inherited from Nektar::SpatialDomains::Geometry
 Geometry ()
 Default constructor.
 
 Geometry (int coordim)
 Constructor when supplied a coordinate dimension.
 
virtual ~Geometry ()=default
 
int GetCoordim () const
 Return the coordinate dimension of this object (i.e. the dimension of the space in which this object is embedded).
 
void SetCoordim (int coordim)
 Sets the coordinate dimension of this object (i.e. the dimension of the space in which this object is embedded).
 
GeomFactorsSharedPtr GetGeomFactors ()
 Get the geometric factors for this object, generating them if required.
 
GeomFactorsSharedPtr GetRefGeomFactors (const Array< OneD, const LibUtilities::BasisSharedPtr > &tbasis)
 
GeomFactorsSharedPtr GetMetricInfo ()
 Get the geometric factors for this object.
 
LibUtilities::ShapeType GetShapeType (void)
 Get the geometric shape type of this object.
 
int GetGlobalID (void) const
 Get the ID of this object.
 
void SetGlobalID (int globalid)
 Set the ID of this object.
 
int GetVid (int i) const
 Returns global id of vertex i of this object.
 
int GetEid (int i) const
 Get the ID of edge i of this object.
 
int GetFid (int i) const
 Get the ID of face i of this object.
 
int GetTid (int i) const
 Get the ID of trace i of this object.
 
PointGeomGetVertex (int i) const
 Returns vertex i of this object.
 
Geometry1DGetEdge (int i) const
 Returns edge i of this object.
 
Geometry2DGetFace (int i) const
 Returns face i of this object.
 
StdRegions::Orientation GetEorient (const int i) const
 Returns the orientation of edge i with respect to the ordering of edges in the standard element.
 
StdRegions::Orientation GetForient (const int i) const
 Returns the orientation of face i with respect to the ordering of faces in the standard element.
 
int GetNumVerts () const
 Get the number of vertices of this object.
 
int GetNumEdges () const
 Get the number of edges of this object.
 
int GetNumFaces () const
 Get the number of faces of this object.
 
int GetShapeDim () const
 Get the object's shape dimension.
 
StdRegions::StdExpansionSharedPtr GetXmap () const
 Return the mapping object Geometry::m_xmap that represents the coordinate transformation from standard element to physical element.
 
const Array< OneD, const NekDouble > & GetCoeffs (const int i) const
 Return the coefficients of the transformation Geometry::m_xmap in coordinate direction i.
 
void FillGeom ()
 Populate the coordinate mapping Geometry::m_coeffs information from any children geometry elements.
 
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 an element contains a particular Cartesian coordinate \((x,y,z)\).
 
bool ContainsPoint (const Array< OneD, const NekDouble > &gloCoord, Array< OneD, NekDouble > &locCoord, NekDouble tol)
 Determine whether an element contains a particular Cartesian coordinate \((x,y,z)\).
 
bool ContainsPoint (const Array< OneD, const NekDouble > &gloCoord, Array< OneD, NekDouble > &locCoord, NekDouble tol, NekDouble &dist)
 Determine whether an element contains a particular Cartesian coordinate \(\vec{x} = (x,y,z)\).
 
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 geometry object.
 
NekDouble GetCoord (const int i, const Array< OneD, const NekDouble > &Lcoord)
 Given local collapsed coordinate Lcoord, return the value of physical coordinate in direction i.
 
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 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.
 
bool ClampLocCoords (Array< OneD, NekDouble > &locCoord, NekDouble tol=std::numeric_limits< NekDouble >::epsilon())
 Clamp local coords to be within standard regions [-1, 1]^dim.
 
NekDouble FindDistance (const Array< OneD, const NekDouble > &xs, Array< OneD, NekDouble > &xi)
 
int GetVertexEdgeMap (int i, int j) const
 Returns the standard element edge IDs that are connected to a given vertex.
 
int GetVertexFaceMap (int i, int j) const
 Returns the standard element face IDs that are connected to a given vertex.
 
int GetEdgeFaceMap (int i, int j) const
 Returns the standard element edge IDs that are connected to a given face.
 
int GetEdgeNormalToFaceVert (int i, int j) const
 Returns the standard lement edge IDs that are normal to a given face vertex.
 
int GetDir (const int i, const int j=0) const
 Returns the element coordinate direction corresponding to a given face coordinate direction.
 
void Reset (CurveMap &curvedEdges, CurveMap &curvedFaces)
 Reset this geometry object: unset the current state, zero Geometry::m_coeffs and remove allocated GeomFactors.
 
void ResetNonRecursive (CurveMap &curvedEdges, CurveMap &curvedFaces)
 Reset this geometry object non-recursively: unset the current state, zero Geometry::m_coeffs and remove allocated GeomFactors.
 
void Setup ()
 
void GenGeomFactors ()
 Handles generation of geometry factors.
 

Static Public Attributes

static const int kDim = 3
 

Protected Member Functions

NekDouble v_GetLocCoords (const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords) override
 Determine the local collapsed coordinates that correspond to a given Cartesian coordinate for this geometry object.
 
void NewtonIterationForLocCoord (const Array< OneD, const NekDouble > &coords, const Array< OneD, const NekDouble > &ptsx, const Array< OneD, const NekDouble > &ptsy, const Array< OneD, const NekDouble > &ptsz, Array< OneD, NekDouble > &Lcoords, NekDouble &dist)
 
void NewtonIterationForLocCoord (const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
 
NekDouble v_GetCoord (const int i, const Array< OneD, const NekDouble > &Lcoord) override
 Given local collapsed coordinate Lcoord return the value of physical coordinate in direction i.
 
void v_CalculateInverseIsoParam () override
 
int v_AllLeftCheck (const Array< OneD, const NekDouble > &gloCoord) override
 
int v_GetShapeDim () const override
 Get the object's shape dimension.
 
- Protected Member Functions inherited from Nektar::SpatialDomains::Geometry
virtual int v_GetVid (int i) const
 Get the ID of vertex i of this object.
 
virtual PointGeomv_GetVertex (int i) const
 Returns vertex i of this object.
 
virtual Geometry1Dv_GetEdge (int i) const
 Returns edge i of this object.
 
virtual Geometry2Dv_GetFace (int i) const
 Returns face i of this object.
 
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.
 
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.
 
virtual int v_GetNumVerts () const
 Get the number of vertices of this object.
 
virtual int v_GetNumEdges () const
 Get the number of edges of this object.
 
virtual int v_GetNumFaces () const
 Get the number of faces of this object.
 
virtual StdRegions::StdExpansionSharedPtr v_GetXmap () const
 Return the mapping object Geometry::m_xmap that represents the coordinate transformation from standard element to physical element.
 
virtual void v_FillGeom ()
 Populate the coordinate mapping Geometry::m_coeffs information from any children geometry elements.
 
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 \(\vec{x} = (x,y,z)\).
 
virtual NekDouble v_FindDistance (const Array< OneD, const NekDouble > &xs, Array< OneD, NekDouble > &xi)
 
virtual int v_GetVertexEdgeMap (int i, int j) const
 Returns the standard element edge IDs that are connected to a given vertex.
 
virtual int v_GetVertexFaceMap (int i, int j) const
 Returns the standard element face IDs that are connected to a given vertex.
 
virtual int v_GetEdgeFaceMap (int i, int j) const
 Returns the standard element edge IDs that are connected to a given face.
 
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.
 
virtual int v_GetDir (const int faceidx, const int facedir) const
 Returns the element coordinate direction corresponding to a given face coordinate direction.
 
virtual void v_Reset (CurveMap &curvedEdges, CurveMap &curvedFaces)
 Reset this geometry object: unset the current state, zero Geometry::m_coeffs and remove allocated GeomFactors.
 
virtual void v_Setup ()
 
virtual void v_GenGeomFactors ()=0
 
void SetUpCoeffs (const int nCoeffs)
 Initialise the Geometry::m_coeffs array.
 

Protected Attributes

int m_eid
 
bool m_ownverts
 
- Protected Attributes inherited from Nektar::SpatialDomains::Geometry
int m_coordim
 Coordinate dimension of this geometry object.
 
GeomFactorsSharedPtr m_geomFactors
 Geometric factors.
 
GeomState m_geomFactorsState
 State of the geometric factors.
 
StdRegions::StdExpansionSharedPtr m_xmap
 \(\chi\) mapping containing isoparametric transformation.
 
GeomState m_state
 Enumeration to dictate whether coefficients are filled.
 
bool m_setupState
 Wether or not the setup routines have been run.
 
GeomType m_geomType
 Type of geometry.
 
LibUtilities::ShapeType m_shapeType
 Type of shape.
 
int m_globalID
 Global ID.
 
Array< OneD, Array< OneD, NekDouble > > m_coeffs
 Array containing expansion coefficients of m_xmap.
 
Array< OneD, NekDoublem_boundingBox
 Array containing bounding box.
 
Array< OneD, Array< OneD, NekDouble > > m_isoParameter
 
Array< OneD, Array< OneD, NekDouble > > m_invIsoParam
 
int m_straightEdge
 

Additional Inherited Members

- Static Protected Member Functions inherited from Nektar::SpatialDomains::Geometry
static GeomFactorsSharedPtr ValidateRegGeomFactor (GeomFactorsSharedPtr geomFactor)
 Check to see if a geometric factor has already been created that contains the same regular information.
 
- Static Protected Attributes inherited from Nektar::SpatialDomains::Geometry
static GeomFactorsVector m_regGeomFactorsManager
 

Detailed Description

3D geometry information

Definition at line 49 of file Geometry3D.h.

Constructor & Destructor Documentation

◆ Geometry3D() [1/2]

Nektar::SpatialDomains::Geometry3D::Geometry3D ( )

Definition at line 47 of file Geometry3D.cpp.

48{
49}

◆ Geometry3D() [2/2]

Nektar::SpatialDomains::Geometry3D::Geometry3D ( const int  coordim)

Definition at line 51 of file Geometry3D.cpp.

51 : Geometry(coordim)
52{
54 "Coordinate dimension should be at least 3 for a 3D geometry.");
55}
#define ASSERTL0(condition, msg)
Geometry()
Default constructor.
Definition Geometry.cpp:50
int m_coordim
Coordinate dimension of this geometry object.
Definition Geometry.h:183

References ASSERTL0, and Nektar::SpatialDomains::Geometry::m_coordim.

◆ ~Geometry3D()

Nektar::SpatialDomains::Geometry3D::~Geometry3D ( )
overridedefault

Member Function Documentation

◆ NewtonIterationForLocCoord() [1/2]

void Nektar::SpatialDomains::Geometry3D::NewtonIterationForLocCoord ( const Array< OneD, const NekDouble > &  coords,
Array< OneD, NekDouble > &  Lcoords 
)
protected

Definition at line 64 of file Geometry3D.cpp.

66{
67 // maximum iterations for convergence
68 const int MaxIterations = 51;
69 // |x-xp|^2 < EPSILON error tolerance
70 const NekDouble Tol = 1.e-8;
71 // |r,s| > LcoordDIV stop the search
72 const NekDouble LcoordDiv = 15.0;
73
74 Array<OneD, const NekDouble> Jac =
75 m_geomFactors->GetJac(m_xmap->GetPointsKeys());
76
77 NekDouble ScaledTol =
78 Vmath::Vsum(Jac.size(), Jac, 1) / ((NekDouble)Jac.size());
79 ScaledTol *= Tol * Tol;
80
81 NekDouble xmap, ymap, zmap, res;
82 int cnt = 0;
83 Array<OneD, NekDouble> var(8, 1.);
84 Array<OneD, NekDouble> deriv(9);
85 Array<OneD, NekDouble> tmp(3);
86 while (cnt++ < MaxIterations)
87 {
88 var[1] = Lcoords[0];
89 var[2] = Lcoords[1];
90 var[3] = Lcoords[2];
91 var[4] = Lcoords[0] * Lcoords[1];
92 var[5] = Lcoords[1] * Lcoords[2];
93 var[6] = Lcoords[0] * Lcoords[2];
94 var[7] = var[4] * Lcoords[2];
95 // calculate the global point corresponding to Lcoords
96 xmap =
97 Vmath::Dot(m_isoParameter[0].size(), var, 1, m_isoParameter[0], 1);
98 ymap =
99 Vmath::Dot(m_isoParameter[0].size(), var, 1, m_isoParameter[1], 1);
100 zmap =
101 Vmath::Dot(m_isoParameter[0].size(), var, 1, m_isoParameter[2], 1);
102
103 tmp[0] = coords[0] - xmap;
104 tmp[1] = coords[1] - ymap;
105 tmp[2] = coords[2] - zmap;
106
107 res = tmp[0] * tmp[0] + tmp[1] * tmp[1] + tmp[2] * tmp[2];
108 if (res < ScaledTol)
109 {
110 break;
111 }
112
113 // Interpolate derivative metric at Lcoords (ddx1, ddx2, ddx3)
114 deriv[0] = m_isoParameter[0][1] + m_isoParameter[0][4] * Lcoords[1];
115 deriv[1] = m_isoParameter[0][2] + m_isoParameter[0][4] * Lcoords[0];
116 deriv[2] = m_isoParameter[0][3];
117 deriv[3] = m_isoParameter[1][1] + m_isoParameter[1][4] * Lcoords[1];
118 deriv[4] = m_isoParameter[1][2] + m_isoParameter[1][4] * Lcoords[0];
119 deriv[5] = m_isoParameter[1][3];
120 deriv[6] = m_isoParameter[2][1] + m_isoParameter[2][4] * Lcoords[1];
121 deriv[7] = m_isoParameter[2][2] + m_isoParameter[2][4] * Lcoords[0];
122 deriv[8] = m_isoParameter[2][3];
123 if (m_isoParameter[0].size() >= 6)
124 {
125 deriv[1] += m_isoParameter[0][5] * Lcoords[2];
126 deriv[2] += m_isoParameter[0][5] * Lcoords[1];
127 deriv[4] += m_isoParameter[1][5] * Lcoords[2];
128 deriv[5] += m_isoParameter[1][5] * Lcoords[1];
129 deriv[7] += m_isoParameter[2][5] * Lcoords[2];
130 deriv[8] += m_isoParameter[2][5] * Lcoords[1];
131 }
132 if (m_isoParameter[0].size() >= 8)
133 {
134 deriv[0] += m_isoParameter[0][6] * Lcoords[2] +
135 m_isoParameter[0][7] * var[5];
136 deriv[1] += m_isoParameter[0][7] * var[6];
137 deriv[2] += m_isoParameter[0][6] * Lcoords[0] +
138 m_isoParameter[0][7] * var[4];
139 deriv[3] += m_isoParameter[1][6] * Lcoords[2] +
140 m_isoParameter[1][7] * var[5];
141 deriv[4] += m_isoParameter[1][7] * var[6];
142 deriv[5] += m_isoParameter[1][6] * Lcoords[0] +
143 m_isoParameter[1][7] * var[4];
144 deriv[6] += m_isoParameter[2][6] * Lcoords[2] +
145 m_isoParameter[2][7] * var[5];
146 deriv[7] += m_isoParameter[2][7] * var[6];
147 deriv[8] += m_isoParameter[2][6] * Lcoords[0] +
148 m_isoParameter[2][7] * var[4];
149 }
150 DNekMatSharedPtr mat =
152 Vmath::Vcopy(9, deriv, 1, mat->GetPtr(), 1);
153 mat->Invert();
154 Lcoords[0] += Vmath::Dot(3, mat->GetPtr(), 1, tmp, 1);
155 Lcoords[1] += Vmath::Dot(3, mat->GetPtr() + 3, 1, tmp, 1);
156 Lcoords[2] += Vmath::Dot(3, mat->GetPtr() + 6, 1, tmp, 1);
157
158 if (!(std::isfinite(Lcoords[0]) && std::isfinite(Lcoords[1]) &&
159 std::isfinite(Lcoords[2])) ||
160 fabs(Lcoords[0]) > LcoordDiv || fabs(Lcoords[1]) > LcoordDiv ||
161 fabs(Lcoords[2]) > LcoordDiv)
162 {
163 std::ostringstream ss;
164 ss << "Iteration has diverged in NewtonIterationForLocCoord in "
165 "element "
166 << GetGlobalID();
167 WARNINGL1(false, ss.str());
168 return;
169 }
170 }
171
172 if (cnt >= MaxIterations)
173 {
174 std::ostringstream ss;
175
176 ss << "Reached MaxIterations (" << MaxIterations
177 << ") in Newton iteration ";
178
179 WARNINGL1(cnt < MaxIterations, ss.str());
180 }
181}
#define WARNINGL1(condition, msg)
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Array< OneD, Array< OneD, NekDouble > > m_isoParameter
Definition Geometry.h:204
int GetGlobalID(void) const
Get the ID of this object.
Definition Geometry.h:322
StdRegions::StdExpansionSharedPtr m_xmap
mapping containing isoparametric transformation.
Definition Geometry.h:189
GeomFactorsSharedPtr m_geomFactors
Geometric factors.
Definition Geometry.h:185
std::shared_ptr< DNekMat > DNekMatSharedPtr
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
Definition Vmath.hpp:608
T Dot(int n, const T *w, const T *x)
dot product
Definition Vmath.hpp:761
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:825

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Vmath::Dot(), Nektar::eFULL, Nektar::SpatialDomains::Geometry::GetGlobalID(), Nektar::SpatialDomains::Geometry::m_geomFactors, Nektar::SpatialDomains::Geometry::m_isoParameter, Nektar::SpatialDomains::Geometry::m_xmap, Vmath::Vcopy(), Vmath::Vsum(), and WARNINGL1.

◆ NewtonIterationForLocCoord() [2/2]

void Nektar::SpatialDomains::Geometry3D::NewtonIterationForLocCoord ( const Array< OneD, const NekDouble > &  coords,
const Array< OneD, const NekDouble > &  ptsx,
const Array< OneD, const NekDouble > &  ptsy,
const Array< OneD, const NekDouble > &  ptsz,
Array< OneD, NekDouble > &  Lcoords,
NekDouble dist 
)
protected

Definition at line 190 of file Geometry3D.cpp.

196{
197 // maximum iterations for convergence
198 const int MaxIterations = NekConstants::kNewtonIterations;
199 // |x-xp|^2 < EPSILON error tolerance
200 const NekDouble Tol = 1.e-8;
201 // |r,s| > LcoordDIV stop the search
202 const NekDouble LcoordDiv = 15.0;
203
204 Array<OneD, const NekDouble> Jac =
205 m_geomFactors->GetJac(m_xmap->GetPointsKeys());
206
207 NekDouble ScaledTol =
208 Vmath::Vsum(Jac.size(), Jac, 1) / ((NekDouble)Jac.size());
209 ScaledTol *= Tol;
210
211 NekDouble xmap, ymap, zmap, F1, F2, F3;
212
213 NekDouble derx_1, derx_2, derx_3, dery_1, dery_2, dery_3, derz_1, derz_2,
214 derz_3, jac;
215
216 // save intiial guess for later reference if required.
217 NekDouble init0 = Lcoords[0], init1 = Lcoords[1], init2 = Lcoords[2];
218
219 Array<OneD, NekDouble> DxD1(ptsx.size());
220 Array<OneD, NekDouble> DxD2(ptsx.size());
221 Array<OneD, NekDouble> DxD3(ptsx.size());
222 Array<OneD, NekDouble> DyD1(ptsx.size());
223 Array<OneD, NekDouble> DyD2(ptsx.size());
224 Array<OneD, NekDouble> DyD3(ptsx.size());
225 Array<OneD, NekDouble> DzD1(ptsx.size());
226 Array<OneD, NekDouble> DzD2(ptsx.size());
227 Array<OneD, NekDouble> DzD3(ptsx.size());
228
229 // Ideally this will be stored in m_geomfactors
230 m_xmap->PhysDeriv(ptsx, DxD1, DxD2, DxD3);
231 m_xmap->PhysDeriv(ptsy, DyD1, DyD2, DyD3);
232 m_xmap->PhysDeriv(ptsz, DzD1, DzD2, DzD3);
233
234 int cnt = 0;
235 Array<OneD, DNekMatSharedPtr> I(3);
236 Array<OneD, NekDouble> eta(3);
237
238 F1 = F2 = F3 = 2000; // Starting value of Function
239 NekDouble resid = sqrt(F1 * F1 + F2 * F2 + F3 * F3);
240 while (cnt++ < MaxIterations)
241 {
242 // evaluate lagrange interpolant at Lcoords
243 m_xmap->LocCoordToLocCollapsed(Lcoords, eta);
244 I[0] = m_xmap->GetBasis(0)->GetI(eta);
245 I[1] = m_xmap->GetBasis(1)->GetI(eta + 1);
246 I[2] = m_xmap->GetBasis(2)->GetI(eta + 2);
247
248 // calculate the global point `corresponding to Lcoords
249 xmap = m_xmap->PhysEvaluate(I, ptsx);
250 ymap = m_xmap->PhysEvaluate(I, ptsy);
251 zmap = m_xmap->PhysEvaluate(I, ptsz);
252
253 F1 = coords[0] - xmap;
254 F2 = coords[1] - ymap;
255 F3 = coords[2] - zmap;
256
257 if (F1 * F1 + F2 * F2 + F3 * F3 < ScaledTol)
258 {
259 resid = sqrt(F1 * F1 + F2 * F2 + F3 * F3);
260 break;
261 }
262
263 // Interpolate derivative metric at Lcoords
264 derx_1 = m_xmap->PhysEvaluate(I, DxD1);
265 derx_2 = m_xmap->PhysEvaluate(I, DxD2);
266 derx_3 = m_xmap->PhysEvaluate(I, DxD3);
267 dery_1 = m_xmap->PhysEvaluate(I, DyD1);
268 dery_2 = m_xmap->PhysEvaluate(I, DyD2);
269 dery_3 = m_xmap->PhysEvaluate(I, DyD3);
270 derz_1 = m_xmap->PhysEvaluate(I, DzD1);
271 derz_2 = m_xmap->PhysEvaluate(I, DzD2);
272 derz_3 = m_xmap->PhysEvaluate(I, DzD3);
273
274 jac = derx_1 * (dery_2 * derz_3 - dery_3 * derz_2) -
275 derx_2 * (dery_1 * derz_3 - dery_3 * derz_1) +
276 derx_3 * (dery_1 * derz_2 - dery_2 * derz_1);
277
278 // use analytical inverse of derivitives which are also similar to
279 // those of metric factors.
280 Lcoords[0] =
281 Lcoords[0] +
282 ((dery_2 * derz_3 - dery_3 * derz_2) * (coords[0] - xmap) -
283 (derx_2 * derz_3 - derx_3 * derz_2) * (coords[1] - ymap) +
284 (derx_2 * dery_3 - derx_3 * dery_2) * (coords[2] - zmap)) /
285 jac;
286
287 Lcoords[1] =
288 Lcoords[1] -
289 ((dery_1 * derz_3 - dery_3 * derz_1) * (coords[0] - xmap) -
290 (derx_1 * derz_3 - derx_3 * derz_1) * (coords[1] - ymap) +
291 (derx_1 * dery_3 - derx_3 * dery_1) * (coords[2] - zmap)) /
292 jac;
293
294 Lcoords[2] =
295 Lcoords[2] +
296 ((dery_1 * derz_2 - dery_2 * derz_1) * (coords[0] - xmap) -
297 (derx_1 * derz_2 - derx_2 * derz_1) * (coords[1] - ymap) +
298 (derx_1 * dery_2 - derx_2 * dery_1) * (coords[2] - zmap)) /
299 jac;
300
301 if (!(std::isfinite(Lcoords[0]) && std::isfinite(Lcoords[1]) &&
302 std::isfinite(Lcoords[2])))
303 {
304 dist = 1e16;
305 std::ostringstream ss;
306 ss << "nan or inf found in NewtonIterationForLocCoord in element "
307 << GetGlobalID();
308 WARNINGL1(false, ss.str());
309 return;
310 }
311 if (fabs(Lcoords[0]) > LcoordDiv || fabs(Lcoords[1]) > LcoordDiv ||
312 fabs(Lcoords[2]) > LcoordDiv)
313 {
314 break; // lcoords have diverged so stop iteration
315 }
316 }
317
318 m_xmap->LocCoordToLocCollapsed(Lcoords, eta);
319 if (ClampLocCoords(eta, 0.))
320 {
321 I[0] = m_xmap->GetBasis(0)->GetI(eta);
322 I[1] = m_xmap->GetBasis(1)->GetI(eta + 1);
323 I[2] = m_xmap->GetBasis(2)->GetI(eta + 2);
324 // calculate the global point corresponding to Lcoords
325 xmap = m_xmap->PhysEvaluate(I, ptsx);
326 ymap = m_xmap->PhysEvaluate(I, ptsy);
327 zmap = m_xmap->PhysEvaluate(I, ptsz);
328 F1 = coords[0] - xmap;
329 F2 = coords[1] - ymap;
330 F3 = coords[2] - zmap;
331 dist = sqrt(F1 * F1 + F2 * F2 + F3 * F3);
332 }
333 else
334 {
335 dist = 0.;
336 }
337
338 if (cnt >= MaxIterations)
339 {
340 Array<OneD, NekDouble> collCoords(3);
341 m_xmap->LocCoordToLocCollapsed(Lcoords, collCoords);
342
343 // if coordinate is inside element dump error!
344 if ((collCoords[0] >= -1.0 && collCoords[0] <= 1.0) &&
345 (collCoords[1] >= -1.0 && collCoords[1] <= 1.0) &&
346 (collCoords[2] >= -1.0 && collCoords[2] <= 1.0))
347 {
348 std::ostringstream ss;
349
350 ss << "Reached MaxIterations (" << MaxIterations
351 << ") in Newton iteration ";
352 ss << "Init value (" << std::setprecision(4) << init0 << ","
353 << init1 << "," << init2 << ") ";
354 ss << "Fin value (" << Lcoords[0] << "," << Lcoords[1] << ","
355 << Lcoords[2] << ") ";
356 ss << "Resid = " << resid
357 << " Tolerance = " << std::sqrt(ScaledTol);
358
359 WARNINGL1(cnt < MaxIterations, ss.str());
360 }
361 }
362}
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:536
static const unsigned int kNewtonIterations
scalarT< T > sqrt(scalarT< T > in)
Definition scalar.hpp:290

References Nektar::SpatialDomains::Geometry::ClampLocCoords(), Nektar::SpatialDomains::Geometry::GetGlobalID(), Nektar::NekConstants::kNewtonIterations, Nektar::SpatialDomains::Geometry::m_geomFactors, Nektar::SpatialDomains::Geometry::m_xmap, tinysimd::sqrt(), Vmath::Vsum(), and WARNINGL1.

Referenced by v_GetLocCoords().

◆ v_AllLeftCheck()

int Nektar::SpatialDomains::Geometry3D::v_AllLeftCheck ( const Array< OneD, const NekDouble > &  gloCoord)
overrideprotectedvirtual

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 183 of file Geometry3D.cpp.

185{
186 // todo: check only plane surfaces
187 return 0;
188}

◆ v_CalculateInverseIsoParam()

void Nektar::SpatialDomains::Geometry3D::v_CalculateInverseIsoParam ( )
overrideprotectedvirtual

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 458 of file Geometry3D.cpp.

459{
460 DNekMatSharedPtr mat =
462 for (int i = 0; i < 3; ++i)
463 {
464 for (int j = 0; j < 3; ++j)
465 {
466
467 mat->SetValue(i, j, m_isoParameter[i][j + 1]);
468 }
469 }
470 mat->Invert();
471 m_invIsoParam = Array<OneD, Array<OneD, NekDouble>>(3);
472 for (int i = 0; i < 3; ++i)
473 {
474 m_invIsoParam[i] = Array<OneD, NekDouble>(3);
475 for (int j = 0; j < 3; ++j)
476 {
477 m_invIsoParam[i][j] = mat->GetValue(i, j);
478 }
479 }
480}
Array< OneD, Array< OneD, NekDouble > > m_invIsoParam
Definition Geometry.h:205

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::eFULL, Nektar::SpatialDomains::Geometry::m_invIsoParam, and Nektar::SpatialDomains::Geometry::m_isoParameter.

Referenced by Nektar::SpatialDomains::HexGeom::v_GenGeomFactors(), Nektar::SpatialDomains::PrismGeom::v_GenGeomFactors(), Nektar::SpatialDomains::PyrGeom::v_GenGeomFactors(), and Nektar::SpatialDomains::TetGeom::v_GenGeomFactors().

◆ v_GetCoord()

NekDouble Nektar::SpatialDomains::Geometry3D::v_GetCoord ( const int  i,
const Array< OneD, const NekDouble > &  Lcoord 
)
overrideprotectedvirtual

Given local collapsed coordinate Lcoord return the value of physical coordinate in direction i.

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 438 of file Geometry3D.cpp.

440{
441 ASSERTL1(m_state == ePtsFilled, "Geometry is not in physical space");
442
443 Array<OneD, NekDouble> tmp(m_xmap->GetTotPoints());
444 m_xmap->BwdTrans(m_coeffs[i], tmp);
445
446 return m_xmap->PhysEvaluate(Lcoord, tmp);
447}
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
GeomState m_state
Enumeration to dictate whether coefficients are filled.
Definition Geometry.h:191
Array< OneD, Array< OneD, NekDouble > > m_coeffs
Array containing expansion coefficients of m_xmap.
Definition Geometry.h:201
@ ePtsFilled
Geometric information has been generated.

References ASSERTL1, Nektar::SpatialDomains::ePtsFilled, Nektar::SpatialDomains::Geometry::m_coeffs, Nektar::SpatialDomains::Geometry::m_state, and Nektar::SpatialDomains::Geometry::m_xmap.

◆ v_GetLocCoords()

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

Determine the local collapsed coordinates that correspond to a given Cartesian coordinate for this geometry object.

For curvilinear and non-affine elements (i.e. where the Jacobian varies as a function of the standard element coordinates), this is a non-linear optimisation problem that requires the use of a Newton iteration. Note therefore that this can be an expensive operation.

Note that, clearly, the provided Cartesian coordinate lie outside the element. The function therefore returns the minimum distance from some position in the element to . Lcoords will also be constrained to fit within the range \([-1,1]^d\) where \( d \) is the dimension of the element.

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

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 364 of file Geometry3D.cpp.

366{
367 NekDouble dist = std::numeric_limits<double>::max();
368 Array<OneD, NekDouble> tmpcoords(3);
369 tmpcoords[0] = coords[0];
370 tmpcoords[1] = coords[1];
371 tmpcoords[2] = coords[2];
372 if (GetMetricInfo()->GetGtype() == eRegular)
373 {
374 tmpcoords[0] -= m_isoParameter[0][0];
375 tmpcoords[1] -= m_isoParameter[1][0];
376 tmpcoords[2] -= m_isoParameter[2][0];
377 Lcoords[0] = m_invIsoParam[0][0] * tmpcoords[0] +
378 m_invIsoParam[0][1] * tmpcoords[1] +
379 m_invIsoParam[0][2] * tmpcoords[2];
380 Lcoords[1] = m_invIsoParam[1][0] * tmpcoords[0] +
381 m_invIsoParam[1][1] * tmpcoords[1] +
382 m_invIsoParam[1][2] * tmpcoords[2];
383 Lcoords[2] = m_invIsoParam[2][0] * tmpcoords[0] +
384 m_invIsoParam[2][1] * tmpcoords[1] +
385 m_invIsoParam[2][2] * tmpcoords[2];
386 }
387 else if (m_straightEdge)
388 {
389 ClampLocCoords(Lcoords, 0.);
390 NewtonIterationForLocCoord(tmpcoords, Lcoords);
391 }
392 else
393 {
394 v_FillGeom();
395 // Determine nearest point of coords to values in m_xmap
396 int npts = m_xmap->GetTotPoints();
397 Array<OneD, NekDouble> ptsx(npts), ptsy(npts), ptsz(npts);
398 Array<OneD, NekDouble> tmp1(npts), tmp2(npts);
399
400 m_xmap->BwdTrans(m_coeffs[0], ptsx);
401 m_xmap->BwdTrans(m_coeffs[1], ptsy);
402 m_xmap->BwdTrans(m_coeffs[2], ptsz);
403
404 const Array<OneD, const NekDouble> za = m_xmap->GetPoints(0);
405 const Array<OneD, const NekDouble> zb = m_xmap->GetPoints(1);
406 const Array<OneD, const NekDouble> zc = m_xmap->GetPoints(2);
407
408 // guess the first local coords based on nearest point
409 Vmath::Sadd(npts, -coords[0], ptsx, 1, tmp1, 1);
410 Vmath::Vmul(npts, tmp1, 1, tmp1, 1, tmp1, 1);
411 Vmath::Sadd(npts, -coords[1], ptsy, 1, tmp2, 1);
412 Vmath::Vvtvp(npts, tmp2, 1, tmp2, 1, tmp1, 1, tmp1, 1);
413 Vmath::Sadd(npts, -coords[2], ptsz, 1, tmp2, 1);
414 Vmath::Vvtvp(npts, tmp2, 1, tmp2, 1, tmp1, 1, tmp1, 1);
415
416 int min_i = Vmath::Imin(npts, tmp1, 1);
417
418 // Get Local coordinates
419 int qa = za.size(), qb = zb.size();
420
421 Array<OneD, NekDouble> eta(3, 0.);
422 eta[2] = zc[min_i / (qa * qb)];
423 min_i = min_i % (qa * qb);
424 eta[1] = zb[min_i / qa];
425 eta[0] = za[min_i % qa];
426 m_xmap->LocCollapsedToLocCoord(eta, Lcoords);
427
428 // Perform newton iteration to find local coordinates
429 NewtonIterationForLocCoord(coords, ptsx, ptsy, ptsz, Lcoords, dist);
430 }
431 return dist;
432}
void NewtonIterationForLocCoord(const Array< OneD, const NekDouble > &coords, const Array< OneD, const NekDouble > &ptsx, const Array< OneD, const NekDouble > &ptsy, const Array< OneD, const NekDouble > &ptsz, Array< OneD, NekDouble > &Lcoords, NekDouble &dist)
virtual void v_FillGeom()
Populate the coordinate mapping Geometry::m_coeffs information from any children geometry elements.
Definition Geometry.cpp:363
GeomFactorsSharedPtr GetMetricInfo()
Get the geometric factors for this object.
Definition Geometry.h:306
@ eRegular
Geometry is straight-sided with constant geometric factors.
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition Vmath.hpp:72
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition Vmath.hpp:366
int Imin(int n, const T *x, const int incx)
Return the index of the minimum element in x.
Definition Vmath.hpp:704
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
Definition Vmath.hpp:194

References Nektar::SpatialDomains::Geometry::ClampLocCoords(), Nektar::SpatialDomains::eRegular, Nektar::SpatialDomains::Geometry::GetMetricInfo(), Vmath::Imin(), Nektar::SpatialDomains::Geometry::m_coeffs, Nektar::SpatialDomains::Geometry::m_invIsoParam, Nektar::SpatialDomains::Geometry::m_isoParameter, Nektar::SpatialDomains::Geometry::m_straightEdge, Nektar::SpatialDomains::Geometry::m_xmap, NewtonIterationForLocCoord(), Vmath::Sadd(), Nektar::SpatialDomains::Geometry::v_FillGeom(), Vmath::Vmul(), and Vmath::Vvtvp().

◆ v_GetShapeDim()

int Nektar::SpatialDomains::Geometry3D::v_GetShapeDim ( ) const
overrideprotectedvirtual

Get the object's shape dimension.

For example, a segment is one dimensional and quadrilateral is two dimensional.

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 453 of file Geometry3D.cpp.

454{
455 return 3;
456}

Member Data Documentation

◆ kDim

const int Nektar::SpatialDomains::Geometry3D::kDim = 3
static

Definition at line 59 of file Geometry3D.h.

◆ m_eid

int Nektar::SpatialDomains::Geometry3D::m_eid
protected

Definition at line 62 of file Geometry3D.h.

◆ m_ownverts

bool Nektar::SpatialDomains::Geometry3D::m_ownverts
protected

Definition at line 63 of file Geometry3D.h.