48namespace SpatialDomains
58 "Coordinate dimension should be at least 3 for a 3D geometry.");
76 const int MaxIterations = 51;
87 ScaledTol *= Tol * Tol;
94 while (cnt++ < MaxIterations)
99 var[4] = Lcoords[0] * Lcoords[1];
100 var[5] = Lcoords[1] * Lcoords[2];
101 var[6] = Lcoords[0] * Lcoords[2];
102 var[7] = var[4] * Lcoords[2];
111 tmp[0] = coords[0] - xmap;
112 tmp[1] = coords[1] - ymap;
113 tmp[2] = coords[2] - zmap;
115 res = tmp[0] * tmp[0] + tmp[1] * tmp[1] + tmp[2] * tmp[2];
162 Lcoords[0] +=
Vmath::Dot(3, mat->GetPtr(), 1, tmp, 1);
163 Lcoords[1] +=
Vmath::Dot(3, mat->GetPtr() + 3, 1, tmp, 1);
164 Lcoords[2] +=
Vmath::Dot(3, mat->GetPtr() + 6, 1, tmp, 1);
166 if (!(std::isfinite(Lcoords[0]) && std::isfinite(Lcoords[1]) &&
167 std::isfinite(Lcoords[2])) ||
168 fabs(Lcoords[0]) > LcoordDiv || fabs(Lcoords[1]) > LcoordDiv ||
169 fabs(Lcoords[2]) > LcoordDiv)
171 std::ostringstream ss;
172 ss <<
"Iteration has diverged in NewtonIterationForLocCoord in "
180 if (cnt >= MaxIterations)
182 std::ostringstream ss;
184 ss <<
"Reached MaxIterations (" << MaxIterations
185 <<
") in Newton iteration ";
187 WARNINGL1(cnt < MaxIterations, ss.str());
193 boost::ignore_unused(gloCoord);
221 NekDouble derx_1, derx_2, derx_3, dery_1, dery_2, dery_3, derz_1, derz_2,
225 NekDouble init0 = Lcoords[0], init1 = Lcoords[1], init2 = Lcoords[2];
238 m_xmap->PhysDeriv(ptsx, DxD1, DxD2, DxD3);
239 m_xmap->PhysDeriv(ptsy, DyD1, DyD2, DyD3);
240 m_xmap->PhysDeriv(ptsz, DzD1, DzD2, DzD3);
248 while (cnt++ < MaxIterations)
251 m_xmap->LocCoordToLocCollapsed(Lcoords, eta);
252 I[0] =
m_xmap->GetBasis(0)->GetI(eta);
253 I[1] =
m_xmap->GetBasis(1)->GetI(eta + 1);
254 I[2] =
m_xmap->GetBasis(2)->GetI(eta + 2);
257 xmap =
m_xmap->PhysEvaluate(I, ptsx);
258 ymap =
m_xmap->PhysEvaluate(I, ptsy);
259 zmap =
m_xmap->PhysEvaluate(I, ptsz);
261 F1 = coords[0] - xmap;
262 F2 = coords[1] - ymap;
263 F3 = coords[2] - zmap;
265 if (F1 * F1 + F2 * F2 + F3 * F3 < ScaledTol)
267 resid =
sqrt(F1 * F1 + F2 * F2 + F3 * F3);
272 derx_1 =
m_xmap->PhysEvaluate(I, DxD1);
273 derx_2 =
m_xmap->PhysEvaluate(I, DxD2);
274 derx_3 =
m_xmap->PhysEvaluate(I, DxD3);
275 dery_1 =
m_xmap->PhysEvaluate(I, DyD1);
276 dery_2 =
m_xmap->PhysEvaluate(I, DyD2);
277 dery_3 =
m_xmap->PhysEvaluate(I, DyD3);
278 derz_1 =
m_xmap->PhysEvaluate(I, DzD1);
279 derz_2 =
m_xmap->PhysEvaluate(I, DzD2);
280 derz_3 =
m_xmap->PhysEvaluate(I, DzD3);
282 jac = derx_1 * (dery_2 * derz_3 - dery_3 * derz_2) -
283 derx_2 * (dery_1 * derz_3 - dery_3 * derz_1) +
284 derx_3 * (dery_1 * derz_2 - dery_2 * derz_1);
290 ((dery_2 * derz_3 - dery_3 * derz_2) * (coords[0] - xmap) -
291 (derx_2 * derz_3 - derx_3 * derz_2) * (coords[1] - ymap) +
292 (derx_2 * dery_3 - derx_3 * dery_2) * (coords[2] - zmap)) /
297 ((dery_1 * derz_3 - dery_3 * derz_1) * (coords[0] - xmap) -
298 (derx_1 * derz_3 - derx_3 * derz_1) * (coords[1] - ymap) +
299 (derx_1 * dery_3 - derx_3 * dery_1) * (coords[2] - zmap)) /
304 ((dery_1 * derz_2 - dery_2 * derz_1) * (coords[0] - xmap) -
305 (derx_1 * derz_2 - derx_2 * derz_1) * (coords[1] - ymap) +
306 (derx_1 * dery_2 - derx_2 * dery_1) * (coords[2] - zmap)) /
309 if (!(std::isfinite(Lcoords[0]) && std::isfinite(Lcoords[1]) &&
310 std::isfinite(Lcoords[2])))
313 std::ostringstream ss;
314 ss <<
"nan or inf found in NewtonIterationForLocCoord in element "
319 if (fabs(Lcoords[0]) > LcoordDiv || fabs(Lcoords[1]) > LcoordDiv ||
320 fabs(Lcoords[2]) > LcoordDiv)
326 m_xmap->LocCoordToLocCollapsed(Lcoords, eta);
329 I[0] =
m_xmap->GetBasis(0)->GetI(eta);
330 I[1] =
m_xmap->GetBasis(1)->GetI(eta + 1);
331 I[2] =
m_xmap->GetBasis(2)->GetI(eta + 2);
333 xmap =
m_xmap->PhysEvaluate(I, ptsx);
334 ymap =
m_xmap->PhysEvaluate(I, ptsy);
335 zmap =
m_xmap->PhysEvaluate(I, ptsz);
336 F1 = coords[0] - xmap;
337 F2 = coords[1] - ymap;
338 F3 = coords[2] - zmap;
339 dist =
sqrt(F1 * F1 + F2 * F2 + F3 * F3);
346 if (cnt >= MaxIterations)
349 m_xmap->LocCoordToLocCollapsed(Lcoords, collCoords);
352 if ((collCoords[0] >= -1.0 && collCoords[0] <= 1.0) &&
353 (collCoords[1] >= -1.0 && collCoords[1] <= 1.0) &&
354 (collCoords[2] >= -1.0 && collCoords[2] <= 1.0))
356 std::ostringstream ss;
358 ss <<
"Reached MaxIterations (" << MaxIterations
359 <<
") in Newton iteration ";
360 ss <<
"Init value (" << setprecision(4) << init0 <<
"," << init1
361 <<
"," << init2 <<
") ";
362 ss <<
"Fin value (" << Lcoords[0] <<
"," << Lcoords[1] <<
","
363 << Lcoords[2] <<
") ";
364 ss <<
"Resid = " << resid <<
" Tolerance = " <<
sqrt(ScaledTol);
366 WARNINGL1(cnt < MaxIterations, ss.str());
374 NekDouble dist = std::numeric_limits<double>::max();
376 tmpcoords[0] = coords[0];
377 tmpcoords[1] = coords[1];
378 tmpcoords[2] = coords[2];
403 int npts =
m_xmap->GetTotPoints();
426 int qa = za.size(), qb = zb.size();
429 eta[2] = zc[min_i / (qa * qb)];
430 min_i = min_i % (qa * qb);
431 eta[1] = zb[min_i / qa];
432 eta[0] = za[min_i % qa];
433 m_xmap->LocCollapsedToLocCoord(eta, Lcoords);
462 int nFaceCoeffs =
m_faces[i]->GetXmap()->GetNcoeffs();
469 m_xmap->GetTraceToElementMap(
476 m_xmap->GetTraceToElementMap(
487 for (k = 0; k < nFaceCoeffs; k++)
510 return m_xmap->PhysEvaluate(Lcoord, tmp);
545 "Edge ID must be between 0 and " +
546 boost::lexical_cast<string>(
m_edges.size() - 1));
552 ASSERTL2((i >= 0) && (i <= 5),
"Edge id must be between 0 and 4");
559 "Edge ID must be between 0 and " +
560 boost::lexical_cast<string>(
m_edges.size() - 1));
567 "Face ID must be between 0 and " +
568 boost::lexical_cast<string>(
m_faces.size() - 1));
576 for (
int i = 0; i < 3; ++i)
578 for (
int j = 0; j < 3; ++j)
586 for (
int i = 0; i < 3; ++i)
589 for (
int j = 0; j < 3; ++j)
#define WARNINGL1(condition, msg)
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed to...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
virtual Geometry2DSharedPtr v_GetFace(int i) const override
Returns face i of this object.
virtual int v_GetNumFaces() const override
Get the number of faces of this object.
virtual 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 ge...
virtual int v_AllLeftCheck(const Array< OneD, const NekDouble > &gloCoord) override
virtual int v_GetNumEdges() const override
Get the number of edges of this object.
std::vector< StdRegions::Orientation > m_forient
virtual void v_CalculateInverseIsoParam() override
virtual void v_FillGeom() override
Put all quadrature information into face/edge structure and backward transform.
virtual 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.
virtual PointGeomSharedPtr v_GetVertex(int i) const override
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 Geometry1DSharedPtr v_GetEdge(int i) const override
Returns edge i of this object.
virtual 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.
virtual int v_GetShapeDim() const override
Get the object's shape dimension.
virtual 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.
std::vector< StdRegions::Orientation > m_eorient
virtual int v_GetNumVerts() const override
Get the number of vertices of this object.
Base class for shape geometry information.
GeomState m_state
Enumeration to dictate whether coefficients are filled.
Array< OneD, Array< OneD, NekDouble > > m_isoParameter
Array< OneD, Array< OneD, NekDouble > > m_invIsoParam
bool ClampLocCoords(Array< OneD, NekDouble > &locCoord, NekDouble tol=std::numeric_limits< NekDouble >::epsilon())
Clamp local coords to be within standard regions [-1, 1]^dim.
int GetGlobalID(void) const
Get the ID of this object.
Array< OneD, Array< OneD, NekDouble > > m_coeffs
Array containing expansion coefficients of m_xmap.
GeomFactorsSharedPtr GetMetricInfo()
Get the geometric factors for this object.
StdRegions::StdExpansionSharedPtr m_xmap
mapping containing isoparametric transformation.
StdRegions::StdExpansionSharedPtr GetXmap() const
Return the mapping object Geometry::m_xmap that represents the coordinate transformation from standar...
GeomFactorsSharedPtr m_geomFactors
Geometric factors.
int m_coordim
Coordinate dimension of this geometry object.
static const unsigned int kNewtonIterations
@ eRegular
Geometry is straight-sided with constant geometric factors.
std::shared_ptr< PointGeom > PointGeomSharedPtr
std::shared_ptr< Geometry2D > Geometry2DSharedPtr
@ ePtsFilled
Geometric information has been generated.
std::shared_ptr< Geometry1D > Geometry1DSharedPtr
The above copyright notice and this permission notice shall be included.
std::shared_ptr< DNekMat > DNekMatSharedPtr
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.
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
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
T Dot(int n, const T *w, const T *x)
dot (vector times vector): z = w*x
int Imin(int n, const T *x, const int incx)
Return the index of the minimum element in x.
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add scalar y = alpha + x.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
scalarT< T > sqrt(scalarT< T > in)