Nektar++
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
 
- Public Member Functions inherited from Nektar::SpatialDomains::Geometry
 Geometry ()
 Default constructor. More...
 
 Geometry (int coordim)
 Constructor when supplied a coordinate dimension. More...
 
virtual ~Geometry ()
 Default destructor. More...
 
int GetCoordim () const
 Return the coordinate dimension of this object (i.e. the dimension of the space in which this object is embedded). More...
 
void SetCoordim (int coordim)
 Sets the coordinate dimension of this object (i.e. the dimension of the space in which this object is embedded). More...
 
GeomFactorsSharedPtr GetGeomFactors ()
 Get the geometric factors for this object, generating them if required. More...
 
GeomFactorsSharedPtr GetRefGeomFactors (const Array< OneD, const LibUtilities::BasisSharedPtr > &tbasis)
 
GeomFactorsSharedPtr GetMetricInfo ()
 Get the geometric factors for this object. More...
 
LibUtilities::ShapeType GetShapeType (void)
 Get the geometric shape type of this object. More...
 
int GetGlobalID (void) const
 Get the ID of this object. More...
 
void SetGlobalID (int globalid)
 Set the ID of this object. More...
 
int GetVid (int i) const
 Get the ID of vertex i of this object. More...
 
int GetEid (int i) const
 Get the ID of edge i of this object. More...
 
int GetFid (int i) const
 Get the ID of face i of this object. More...
 
int GetTid (int i) const
 Get the ID of trace i of this object. More...
 
PointGeomSharedPtr GetVertex (int i) const
 Returns vertex i of this object. More...
 
Geometry1DSharedPtr GetEdge (int i) const
 Returns edge i of this object. More...
 
Geometry2DSharedPtr GetFace (int i) const
 Returns face i of this object. More...
 
StdRegions::Orientation GetEorient (const int i) const
 Returns the orientation of edge i with respect to the ordering of edges in the standard element. More...
 
StdRegions::Orientation GetForient (const int i) const
 Returns the orientation of face i with respect to the ordering of faces in the standard element. More...
 
int GetNumVerts () const
 Get the number of vertices of this object. More...
 
int GetNumEdges () const
 Get the number of edges of this object. More...
 
int GetNumFaces () const
 Get the number of faces of this object. More...
 
int GetShapeDim () const
 Get the object's shape dimension. More...
 
StdRegions::StdExpansionSharedPtr GetXmap () const
 Return the mapping object Geometry::m_xmap that represents the coordinate transformation from standard element to physical element. More...
 
const Array< OneD, const NekDouble > & GetCoeffs (const int i) const
 Return the coefficients of the transformation Geometry::m_xmap in coordinate direction i. More...
 
void FillGeom ()
 Populate the coordinate mapping Geometry::m_coeffs information from any children geometry elements. More...
 
std::array< NekDouble, 6 > GetBoundingBox ()
 Generates the bounding box for the element. More...
 
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)\). More...
 
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)\). More...
 
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)\). More...
 
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. More...
 
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. More...
 
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. More...
 
bool MinMaxCheck (const Array< OneD, const NekDouble > &gloCoord)
 Check if given global coord is within the BoundingBox of the element. More...
 
bool ClampLocCoords (Array< OneD, NekDouble > &locCoord, NekDouble tol=std::numeric_limits< NekDouble >::epsilon())
 Clamp local coords to be within standard regions [-1, 1]^dim. More...
 
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. More...
 
int GetVertexFaceMap (int i, int j) const
 Returns the standard element face IDs that are connected to a given vertex. More...
 
int GetEdgeFaceMap (int i, int j) const
 Returns the standard element edge IDs that are connected to a given face. More...
 
int GetEdgeNormalToFaceVert (int i, int j) const
 Returns the standard lement edge IDs that are normal to a given face vertex. More...
 
int GetDir (const int i, const int j=0) const
 Returns the element coordinate direction corresponding to a given face coordinate direction. More...
 
void Reset (CurveMap &curvedEdges, CurveMap &curvedFaces)
 Reset this geometry object: unset the current state, zero Geometry::m_coeffs and remove allocated GeomFactors. More...
 
void Setup ()
 

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. More...
 
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)
 
void v_FillGeom () override
 Put all quadrature information into face/edge structure and backward transform. More...
 
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. More...
 
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. More...
 
int v_GetNumVerts () const override
 Get the number of vertices of this object. More...
 
int v_GetNumEdges () const override
 Get the number of edges of this object. More...
 
int v_GetNumFaces () const override
 Get the number of faces of this object. More...
 
PointGeomSharedPtr v_GetVertex (int i) const override
 
Geometry1DSharedPtr v_GetEdge (int i) const override
 Returns edge i of this object. More...
 
Geometry2DSharedPtr v_GetFace (int i) const override
 Returns face i of this object. More...
 
StdRegions::Orientation v_GetEorient (const int i) const override
 Returns the orientation of edge i with respect to the ordering of edges in the standard element. More...
 
StdRegions::Orientation v_GetForient (const int i) const override
 Returns the orientation of face i with respect to the ordering of faces in the standard element. More...
 
- Protected Member Functions inherited from Nektar::SpatialDomains::Geometry
void GenGeomFactors ()
 Handles generation of geometry factors. More...
 
virtual PointGeomSharedPtr v_GetVertex (int i) const =0
 
virtual Geometry1DSharedPtr v_GetEdge (int i) const
 Returns edge i of this object. More...
 
virtual Geometry2DSharedPtr v_GetFace (int i) const
 Returns face i of this object. More...
 
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. More...
 
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. More...
 
virtual int v_GetNumVerts () const
 Get the number of vertices of this object. More...
 
virtual int v_GetNumEdges () const
 Get the number of edges of this object. More...
 
virtual int v_GetNumFaces () const
 Get the number of faces of this object. More...
 
virtual int v_GetShapeDim () const
 Get the object's shape dimension. More...
 
virtual StdRegions::StdExpansionSharedPtr v_GetXmap () const
 Return the mapping object Geometry::m_xmap that represents the coordinate transformation from standard element to physical element. More...
 
virtual void v_FillGeom ()
 Populate the coordinate mapping Geometry::m_coeffs information from any children geometry elements. More...
 
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)\). More...
 
virtual int v_AllLeftCheck (const Array< OneD, const NekDouble > &gloCoord)
 
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. More...
 
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 geometry object. More...
 
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. More...
 
virtual int v_GetVertexFaceMap (int i, int j) const
 Returns the standard element face IDs that are connected to a given vertex. More...
 
virtual int v_GetEdgeFaceMap (int i, int j) const
 Returns the standard element edge IDs that are connected to a given face. More...
 
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. More...
 
virtual int v_GetDir (const int faceidx, const int facedir) const
 Returns the element coordinate direction corresponding to a given face coordinate direction. More...
 
virtual void v_Reset (CurveMap &curvedEdges, CurveMap &curvedFaces)
 Reset this geometry object: unset the current state, zero Geometry::m_coeffs and remove allocated GeomFactors. More...
 
virtual void v_Setup ()
 
virtual void v_GenGeomFactors ()=0
 
void SetUpCoeffs (const int nCoeffs)
 Initialise the Geometry::m_coeffs array. More...
 
virtual void v_CalculateInverseIsoParam ()
 

Protected Attributes

PointGeomVector m_verts
 
SegGeomVector m_edges
 
Geometry2DVector m_faces
 
std::vector< StdRegions::Orientationm_eorient
 
std::vector< StdRegions::Orientationm_forient
 
int m_eid
 
bool m_ownverts
 
- Protected Attributes inherited from Nektar::SpatialDomains::Geometry
int m_coordim
 Coordinate dimension of this geometry object. More...
 
GeomFactorsSharedPtr m_geomFactors
 Geometric factors. More...
 
GeomState m_geomFactorsState
 State of the geometric factors. More...
 
StdRegions::StdExpansionSharedPtr m_xmap
 \(\chi\) mapping containing isoparametric transformation. More...
 
GeomState m_state
 Enumeration to dictate whether coefficients are filled. More...
 
bool m_setupState
 Wether or not the setup routines have been run. More...
 
GeomType m_geomType
 Type of geometry. More...
 
LibUtilities::ShapeType m_shapeType
 Type of shape. More...
 
int m_globalID
 Global ID. More...
 
Array< OneD, Array< OneD, NekDouble > > m_coeffs
 Array containing expansion coefficients of m_xmap. More...
 
Array< OneD, NekDoublem_boundingBox
 Array containing bounding box. More...
 
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. More...
 
- Static Protected Attributes inherited from Nektar::SpatialDomains::Geometry
static GeomFactorsVector m_regGeomFactorsManager
 

Detailed Description

3D geometry information

Definition at line 64 of file Geometry3D.h.

Constructor & Destructor Documentation

◆ Geometry3D() [1/2]

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

Definition at line 49 of file Geometry3D.cpp.

50{
51}

◆ Geometry3D() [2/2]

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

Definition at line 53 of file Geometry3D.cpp.

53 : Geometry(coordim)
54{
56 "Coordinate dimension should be at least 3 for a 3D geometry.");
57}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
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 ( )
override

Definition at line 59 of file Geometry3D.cpp.

60{
61}

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 70 of file Geometry3D.cpp.

72{
73 // maximum iterations for convergence
74 const int MaxIterations = 51;
75 // |x-xp|^2 < EPSILON error tolerance
76 const NekDouble Tol = 1.e-8;
77 // |r,s| > LcoordDIV stop the search
78 const NekDouble LcoordDiv = 15.0;
79
80 Array<OneD, const NekDouble> Jac =
81 m_geomFactors->GetJac(m_xmap->GetPointsKeys());
82
83 NekDouble ScaledTol =
84 Vmath::Vsum(Jac.size(), Jac, 1) / ((NekDouble)Jac.size());
85 ScaledTol *= Tol * Tol;
86
87 NekDouble xmap, ymap, zmap, res;
88 int cnt = 0;
89 Array<OneD, NekDouble> var(8, 1.);
90 Array<OneD, NekDouble> deriv(9);
91 Array<OneD, NekDouble> tmp(3);
92 while (cnt++ < MaxIterations)
93 {
94 var[1] = Lcoords[0];
95 var[2] = Lcoords[1];
96 var[3] = Lcoords[2];
97 var[4] = Lcoords[0] * Lcoords[1];
98 var[5] = Lcoords[1] * Lcoords[2];
99 var[6] = Lcoords[0] * Lcoords[2];
100 var[7] = var[4] * Lcoords[2];
101 // calculate the global point corresponding to Lcoords
102 xmap =
103 Vmath::Dot(m_isoParameter[0].size(), var, 1, m_isoParameter[0], 1);
104 ymap =
105 Vmath::Dot(m_isoParameter[0].size(), var, 1, m_isoParameter[1], 1);
106 zmap =
107 Vmath::Dot(m_isoParameter[0].size(), var, 1, m_isoParameter[2], 1);
108
109 tmp[0] = coords[0] - xmap;
110 tmp[1] = coords[1] - ymap;
111 tmp[2] = coords[2] - zmap;
112
113 res = tmp[0] * tmp[0] + tmp[1] * tmp[1] + tmp[2] * tmp[2];
114 if (res < ScaledTol)
115 {
116 break;
117 }
118
119 // Interpolate derivative metric at Lcoords (ddx1, ddx2, ddx3)
120 deriv[0] = m_isoParameter[0][1] + m_isoParameter[0][4] * Lcoords[1];
121 deriv[1] = m_isoParameter[0][2] + m_isoParameter[0][4] * Lcoords[0];
122 deriv[2] = m_isoParameter[0][3];
123 deriv[3] = m_isoParameter[1][1] + m_isoParameter[1][4] * Lcoords[1];
124 deriv[4] = m_isoParameter[1][2] + m_isoParameter[1][4] * Lcoords[0];
125 deriv[5] = m_isoParameter[1][3];
126 deriv[6] = m_isoParameter[2][1] + m_isoParameter[2][4] * Lcoords[1];
127 deriv[7] = m_isoParameter[2][2] + m_isoParameter[2][4] * Lcoords[0];
128 deriv[8] = m_isoParameter[2][3];
129 if (m_isoParameter[0].size() >= 6)
130 {
131 deriv[1] += m_isoParameter[0][5] * Lcoords[2];
132 deriv[2] += m_isoParameter[0][5] * Lcoords[1];
133 deriv[4] += m_isoParameter[1][5] * Lcoords[2];
134 deriv[5] += m_isoParameter[1][5] * Lcoords[1];
135 deriv[7] += m_isoParameter[2][5] * Lcoords[2];
136 deriv[8] += m_isoParameter[2][5] * Lcoords[1];
137 }
138 if (m_isoParameter[0].size() >= 8)
139 {
140 deriv[0] += m_isoParameter[0][6] * Lcoords[2] +
141 m_isoParameter[0][7] * var[5];
142 deriv[1] += m_isoParameter[0][7] * var[6];
143 deriv[2] += m_isoParameter[0][6] * Lcoords[0] +
144 m_isoParameter[0][7] * var[4];
145 deriv[3] += m_isoParameter[1][6] * Lcoords[2] +
146 m_isoParameter[1][7] * var[5];
147 deriv[4] += m_isoParameter[1][7] * var[6];
148 deriv[5] += m_isoParameter[1][6] * Lcoords[0] +
149 m_isoParameter[1][7] * var[4];
150 deriv[6] += m_isoParameter[2][6] * Lcoords[2] +
151 m_isoParameter[2][7] * var[5];
152 deriv[7] += m_isoParameter[2][7] * var[6];
153 deriv[8] += m_isoParameter[2][6] * Lcoords[0] +
154 m_isoParameter[2][7] * var[4];
155 }
156 DNekMatSharedPtr mat =
158 Vmath::Vcopy(9, deriv, 1, mat->GetPtr(), 1);
159 mat->Invert();
160 Lcoords[0] += Vmath::Dot(3, mat->GetPtr(), 1, tmp, 1);
161 Lcoords[1] += Vmath::Dot(3, mat->GetPtr() + 3, 1, tmp, 1);
162 Lcoords[2] += Vmath::Dot(3, mat->GetPtr() + 6, 1, tmp, 1);
163
164 if (!(std::isfinite(Lcoords[0]) && std::isfinite(Lcoords[1]) &&
165 std::isfinite(Lcoords[2])) ||
166 fabs(Lcoords[0]) > LcoordDiv || fabs(Lcoords[1]) > LcoordDiv ||
167 fabs(Lcoords[2]) > LcoordDiv)
168 {
169 std::ostringstream ss;
170 ss << "Iteration has diverged in NewtonIterationForLocCoord in "
171 "element "
172 << GetGlobalID();
173 WARNINGL1(false, ss.str());
174 return;
175 }
176 }
177
178 if (cnt >= MaxIterations)
179 {
180 std::ostringstream ss;
181
182 ss << "Reached MaxIterations (" << MaxIterations
183 << ") in Newton iteration ";
184
185 WARNINGL1(cnt < MaxIterations, ss.str());
186 }
187}
#define WARNINGL1(condition, msg)
Definition: ErrorUtil.hpp:243
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:324
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
Definition: NekTypeDefs.hpp:75
double NekDouble
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 196 of file Geometry3D.cpp.

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

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 189 of file Geometry3D.cpp.

191{
192 // todo: check only plane surfaces
193 return 0;
194}

◆ v_CalculateInverseIsoParam()

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

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 570 of file Geometry3D.cpp.

571{
572 DNekMatSharedPtr mat =
574 for (int i = 0; i < 3; ++i)
575 {
576 for (int j = 0; j < 3; ++j)
577 {
578
579 mat->SetValue(i, j, m_isoParameter[i][j + 1]);
580 }
581 }
582 mat->Invert();
583 m_invIsoParam = Array<OneD, Array<OneD, NekDouble>>(3);
584 for (int i = 0; i < 3; ++i)
585 {
586 m_invIsoParam[i] = Array<OneD, NekDouble>(3);
587 for (int j = 0; j < 3; ++j)
588 {
589 m_invIsoParam[i][j] = mat->GetValue(i, j);
590 }
591 }
592}
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_FillGeom()

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

Put all quadrature information into face/edge structure and backward transform.

Note verts, edges, and faces are listed according to anticlockwise convention but points in _coeffs have to be in array format from left to right.

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 447 of file Geometry3D.cpp.

448{
449 if (m_state == ePtsFilled)
450 {
451 return;
452 }
453
454 int i, j, k;
455
456 for (i = 0; i < m_forient.size(); i++)
457 {
458 m_faces[i]->FillGeom();
459
460 int nFaceCoeffs = m_faces[i]->GetXmap()->GetNcoeffs();
461
462 Array<OneD, unsigned int> mapArray(nFaceCoeffs);
463 Array<OneD, int> signArray(nFaceCoeffs);
464
465 if (m_forient[i] < 9)
466 {
467 m_xmap->GetTraceToElementMap(
468 i, mapArray, signArray, m_forient[i],
469 m_faces[i]->GetXmap()->GetTraceNcoeffs(0),
470 m_faces[i]->GetXmap()->GetTraceNcoeffs(1));
471 }
472 else
473 {
474 m_xmap->GetTraceToElementMap(
475 i, mapArray, signArray, m_forient[i],
476 m_faces[i]->GetXmap()->GetTraceNcoeffs(1),
477 m_faces[i]->GetXmap()->GetTraceNcoeffs(0));
478 }
479
480 for (j = 0; j < m_coordim; j++)
481 {
482 const Array<OneD, const NekDouble> &coeffs =
483 m_faces[i]->GetCoeffs(j);
484
485 for (k = 0; k < nFaceCoeffs; k++)
486 {
487 NekDouble v = signArray[k] * coeffs[k];
488 m_coeffs[j][mapArray[k]] = v;
489 }
490 }
491 }
492
494}
std::vector< StdRegions::Orientation > m_forient
Definition: Geometry3D.h:81
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
StdRegions::StdExpansionSharedPtr GetXmap() const
Return the mapping object Geometry::m_xmap that represents the coordinate transformation from standar...
Definition: Geometry.h:433
@ ePtsFilled
Geometric information has been generated.

References Nektar::SpatialDomains::ePtsFilled, Nektar::SpatialDomains::Geometry::GetXmap(), Nektar::SpatialDomains::Geometry::m_coeffs, Nektar::SpatialDomains::Geometry::m_coordim, m_faces, m_forient, Nektar::SpatialDomains::Geometry::m_state, and Nektar::SpatialDomains::Geometry::m_xmap.

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

◆ 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 500 of file Geometry3D.cpp.

502{
503 ASSERTL1(m_state == ePtsFilled, "Geometry is not in physical space");
504
505 Array<OneD, NekDouble> tmp(m_xmap->GetTotPoints());
506 m_xmap->BwdTrans(m_coeffs[i], tmp);
507
508 return m_xmap->PhysEvaluate(Lcoord, tmp);
509}
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242

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

◆ v_GetEdge()

Geometry1DSharedPtr Nektar::SpatialDomains::Geometry3D::v_GetEdge ( int  i) const
overrideprotectedvirtual

Returns edge i of this object.

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 540 of file Geometry3D.cpp.

541{
542 ASSERTL2(i >= 0 && i <= m_edges.size() - 1,
543 "Edge ID must be between 0 and " +
544 boost::lexical_cast<string>(m_edges.size() - 1));
545 return m_edges[i];
546}
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed to...
Definition: ErrorUtil.hpp:265

References ASSERTL2, and m_edges.

◆ v_GetEorient()

StdRegions::Orientation Nektar::SpatialDomains::Geometry3D::v_GetEorient ( const int  i) const
inlineoverrideprotectedvirtual

Returns the orientation of edge i with respect to the ordering of edges in the standard element.

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 554 of file Geometry3D.cpp.

555{
556 ASSERTL2(i >= 0 && i <= m_edges.size() - 1,
557 "Edge ID must be between 0 and " +
558 boost::lexical_cast<string>(m_edges.size() - 1));
559 return m_eorient[i];
560}
std::vector< StdRegions::Orientation > m_eorient
Definition: Geometry3D.h:80

References ASSERTL2, m_edges, and m_eorient.

◆ v_GetFace()

Geometry2DSharedPtr Nektar::SpatialDomains::Geometry3D::v_GetFace ( int  i) const
overrideprotectedvirtual

Returns face i of this object.

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 548 of file Geometry3D.cpp.

549{
550 ASSERTL2((i >= 0) && (i <= 5), "Edge id must be between 0 and 4");
551 return m_faces[i];
552}

References ASSERTL2, and m_faces.

◆ v_GetForient()

StdRegions::Orientation Nektar::SpatialDomains::Geometry3D::v_GetForient ( const int  i) const
overrideprotectedvirtual

Returns the orientation of face i with respect to the ordering of faces in the standard element.

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 562 of file Geometry3D.cpp.

563{
564 ASSERTL2(i >= 0 && i <= m_faces.size() - 1,
565 "Face ID must be between 0 and " +
566 boost::lexical_cast<string>(m_faces.size() - 1));
567 return m_forient[i];
568}

References ASSERTL2, m_faces, and m_forient.

◆ 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 369 of file Geometry3D.cpp.

371{
372 NekDouble dist = std::numeric_limits<double>::max();
373 Array<OneD, NekDouble> tmpcoords(3);
374 tmpcoords[0] = coords[0];
375 tmpcoords[1] = coords[1];
376 tmpcoords[2] = coords[2];
377 if (GetMetricInfo()->GetGtype() == eRegular)
378 {
379 tmpcoords[0] -= m_isoParameter[0][0];
380 tmpcoords[1] -= m_isoParameter[1][0];
381 tmpcoords[2] -= m_isoParameter[2][0];
382 Lcoords[0] = m_invIsoParam[0][0] * tmpcoords[0] +
383 m_invIsoParam[0][1] * tmpcoords[1] +
384 m_invIsoParam[0][2] * tmpcoords[2];
385 Lcoords[1] = m_invIsoParam[1][0] * tmpcoords[0] +
386 m_invIsoParam[1][1] * tmpcoords[1] +
387 m_invIsoParam[1][2] * tmpcoords[2];
388 Lcoords[2] = m_invIsoParam[2][0] * tmpcoords[0] +
389 m_invIsoParam[2][1] * tmpcoords[1] +
390 m_invIsoParam[2][2] * tmpcoords[2];
391 }
392 else if (m_straightEdge)
393 {
394 ClampLocCoords(Lcoords, 0.);
395 NewtonIterationForLocCoord(tmpcoords, Lcoords);
396 }
397 else
398 {
399 v_FillGeom();
400 // Determine nearest point of coords to values in m_xmap
401 int npts = m_xmap->GetTotPoints();
402 Array<OneD, NekDouble> ptsx(npts), ptsy(npts), ptsz(npts);
403 Array<OneD, NekDouble> tmp1(npts), tmp2(npts);
404
405 m_xmap->BwdTrans(m_coeffs[0], ptsx);
406 m_xmap->BwdTrans(m_coeffs[1], ptsy);
407 m_xmap->BwdTrans(m_coeffs[2], ptsz);
408
409 const Array<OneD, const NekDouble> za = m_xmap->GetPoints(0);
410 const Array<OneD, const NekDouble> zb = m_xmap->GetPoints(1);
411 const Array<OneD, const NekDouble> zc = m_xmap->GetPoints(2);
412
413 // guess the first local coords based on nearest point
414 Vmath::Sadd(npts, -coords[0], ptsx, 1, tmp1, 1);
415 Vmath::Vmul(npts, tmp1, 1, tmp1, 1, tmp1, 1);
416 Vmath::Sadd(npts, -coords[1], ptsy, 1, tmp2, 1);
417 Vmath::Vvtvp(npts, tmp2, 1, tmp2, 1, tmp1, 1, tmp1, 1);
418 Vmath::Sadd(npts, -coords[2], ptsz, 1, tmp2, 1);
419 Vmath::Vvtvp(npts, tmp2, 1, tmp2, 1, tmp1, 1, tmp1, 1);
420
421 int min_i = Vmath::Imin(npts, tmp1, 1);
422
423 // Get Local coordinates
424 int qa = za.size(), qb = zb.size();
425
426 Array<OneD, NekDouble> eta(3, 0.);
427 eta[2] = zc[min_i / (qa * qb)];
428 min_i = min_i % (qa * qb);
429 eta[1] = zb[min_i / qa];
430 eta[0] = za[min_i % qa];
431 m_xmap->LocCollapsedToLocCoord(eta, Lcoords);
432
433 // Perform newton iteration to find local coordinates
434 NewtonIterationForLocCoord(coords, ptsx, ptsy, ptsz, Lcoords, dist);
435 }
436 return dist;
437}
void v_FillGeom() override
Put all quadrature information into face/edge structure and backward transform.
Definition: Geometry3D.cpp:447
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)
Definition: Geometry3D.cpp:196
GeomFactorsSharedPtr GetMetricInfo()
Get the geometric factors for this object.
Definition: Geometry.h:308
@ 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(), v_FillGeom(), Vmath::Vmul(), and Vmath::Vvtvp().

◆ v_GetNumEdges()

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

Get the number of edges of this object.

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 525 of file Geometry3D.cpp.

526{
527 return m_edges.size();
528}

References m_edges.

◆ v_GetNumFaces()

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

Get the number of faces of this object.

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 530 of file Geometry3D.cpp.

531{
532 return m_faces.size();
533}

References m_faces.

◆ v_GetNumVerts()

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

Get the number of vertices of this object.

Reimplemented from Nektar::SpatialDomains::Geometry.

Definition at line 520 of file Geometry3D.cpp.

521{
522 return m_verts.size();
523}

References m_verts.

◆ 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 515 of file Geometry3D.cpp.

516{
517 return 3;
518}

◆ v_GetVertex()

PointGeomSharedPtr Nektar::SpatialDomains::Geometry3D::v_GetVertex ( int  i) const
overrideprotectedvirtual

Implements Nektar::SpatialDomains::Geometry.

Definition at line 535 of file Geometry3D.cpp.

536{
537 return m_verts[i];
538}

References m_verts.

Member Data Documentation

◆ kDim

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

Definition at line 74 of file Geometry3D.h.

◆ m_edges

SegGeomVector Nektar::SpatialDomains::Geometry3D::m_edges
protected

◆ m_eid

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

Definition at line 82 of file Geometry3D.h.

◆ m_eorient

std::vector<StdRegions::Orientation> Nektar::SpatialDomains::Geometry3D::m_eorient
protected

◆ m_faces

Geometry2DVector Nektar::SpatialDomains::Geometry3D::m_faces
protected

◆ m_forient

std::vector<StdRegions::Orientation> Nektar::SpatialDomains::Geometry3D::m_forient
protected

◆ m_ownverts

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

Definition at line 83 of file Geometry3D.h.

◆ m_verts

PointGeomVector Nektar::SpatialDomains::Geometry3D::m_verts
protected