47 namespace SpatialDomains
50 Geometry2D::Geometry2D()
58 "Coordinate dimension should be at least 2 for a 2D geometry");
73 const int MaxIterations = 51;
87 NekDouble derx_1, derx_2, dery_1, dery_2, jac;
90 NekDouble init0 = Lcoords[0], init1 = Lcoords[1];
98 m_xmap->PhysDeriv(ptsx, DxD1, DxD2);
99 m_xmap->PhysDeriv(ptsy, DyD1, DyD2);
107 while (cnt++ < MaxIterations)
110 m_xmap->LocCoordToLocCollapsed(Lcoords, eta);
111 I[0] =
m_xmap->GetBasis(0)->GetI(eta);
112 I[1] =
m_xmap->GetBasis(1)->GetI(eta + 1);
115 xmap =
m_xmap->PhysEvaluate(I, ptsx);
116 ymap =
m_xmap->PhysEvaluate(I, ptsy);
118 F1 = coords[0] - xmap;
119 F2 = coords[1] - ymap;
121 if (F1 * F1 + F2 * F2 < ScaledTol)
123 resid =
sqrt(F1 * F1 + F2 * F2);
128 derx_1 =
m_xmap->PhysEvaluate(I, DxD1);
129 derx_2 =
m_xmap->PhysEvaluate(I, DxD2);
130 dery_1 =
m_xmap->PhysEvaluate(I, DyD1);
131 dery_2 =
m_xmap->PhysEvaluate(I, DyD2);
133 jac = dery_2 * derx_1 - dery_1 * derx_2;
139 (dery_2 * (coords[0] - xmap) - derx_2 * (coords[1] - ymap)) / jac;
143 (-dery_1 * (coords[0] - xmap) + derx_1 * (coords[1] - ymap)) / jac;
145 if( !(std::isfinite(Lcoords[0]) && std::isfinite(Lcoords[1])) )
148 std::ostringstream ss;
149 ss <<
"nan or inf found in NewtonIterationForLocCoord in element "
154 if (fabs(Lcoords[0]) > LcoordDiv || fabs(Lcoords[1]) > LcoordDiv)
160 m_xmap->LocCoordToLocCollapsed(Lcoords, eta);
163 I[0] =
m_xmap->GetBasis(0)->GetI(eta);
164 I[1] =
m_xmap->GetBasis(1)->GetI(eta + 1);
166 xmap =
m_xmap->PhysEvaluate(I, ptsx);
167 ymap =
m_xmap->PhysEvaluate(I, ptsy);
168 F1 = coords[0] - xmap;
169 F2 = coords[1] - ymap;
170 dist =
sqrt(F1 * F1 + F2 * F2);
177 if (cnt >= MaxIterations)
180 m_xmap->LocCoordToLocCollapsed(Lcoords, collCoords);
183 if ((collCoords[0] >= -1.0 && collCoords[0] <= 1.0) &&
184 (collCoords[1] >= -1.0 && collCoords[1] <= 1.0))
186 std::ostringstream ss;
188 ss <<
"Reached MaxIterations (" << MaxIterations
189 <<
") in Newton iteration ";
190 ss <<
"Init value (" << setprecision(4) << init0 <<
"," << init1
193 ss <<
"Fin value (" << Lcoords[0] <<
"," << Lcoords[1] <<
","
195 ss <<
"Resid = " << resid <<
" Tolerance = " <<
sqrt(ScaledTol);
197 WARNINGL1(cnt < MaxIterations, ss.str());
220 ASSERTL0(
false,
"unrecognized 2D element type");
236 orth1.
Mult(norm, e10);
237 orth2.
Mult(norm, e20);
241 Lcoords[0] = er0.
dot(orth2) / e10.
dot(orth2);
242 Lcoords[0] = 2. * Lcoords[0] - 1.;
243 Lcoords[1] = er0.
dot(orth1) / e20.
dot(orth1);
244 Lcoords[1] = 2. * Lcoords[1] - 1.;
248 m_xmap->LocCoordToLocCollapsed(Lcoords, eta);
252 m_xmap->LocCollapsedToLocCoord(eta, xi);
253 xi[0] = (xi[0] + 1.) * 0.5;
254 xi[1] = (xi[1] + 1.) * 0.5;
257 NekDouble tmp = xi[0]*e10[i] + xi[1]*e20[i] - er0[i];
267 int npts =
m_xmap->GetTotPoints();
272 int idx = 0, idy = 1;
280 double tmp = std::fabs(norm[0]);
281 if(tmp < fabs(norm[1]))
286 if(tmp < fabs(norm[2]))
290 idx = (tmpi + 1) % 3;
291 idy = (tmpi + 2) % 3;
294 tmpcoords[0] = coords[idx];
295 tmpcoords[1] = coords[idy];
304 Vmath::Sadd(npts, -tmpcoords[0], ptsx, 1, tmpx, 1);
305 Vmath::Sadd(npts, -tmpcoords[1], ptsy, 1, tmpy, 1);
312 eta[0] = za[min_i % za.size()];
313 eta[1] = zb[min_i / za.size()];
314 m_xmap->LocCollapsedToLocCoord(eta, Lcoords);
#define WARNINGL1(condition, msg)
#define ASSERTL0(condition, msg)
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed to...
void NewtonIterationForLocCoord(const Array< OneD, const NekDouble > &coords, const Array< OneD, const NekDouble > &ptsx, const Array< OneD, const NekDouble > &ptsy, Array< OneD, NekDouble > &Lcoords, NekDouble &dist)
virtual Geometry1DSharedPtr v_GetEdge(int i) const
Returns edge i of this object.
std::vector< StdRegions::Orientation > m_eorient
virtual int v_GetShapeDim() const
Get the object's shape dimension.
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 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 NekDouble v_GetLocCoords(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
Determine the local collapsed coordinates that correspond to a given Cartesian coordinate for this ge...
virtual PointGeomSharedPtr v_GetVertex(int i) const
Base class for shape geometry information.
bool ClampLocCoords(Array< OneD, NekDouble > &locCoord, NekDouble tol)
Clamp local coords to be within standard regions [-1, 1]^dim.
virtual void v_FillGeom()
Populate the coordinate mapping Geometry::m_coeffs information from any children geometry elements.
int GetGlobalID(void) const
Get the ID of this object.
LibUtilities::ShapeType m_shapeType
Type of shape.
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.
GeomFactorsSharedPtr m_geomFactors
Geometric factors.
int m_coordim
Coordinate dimension of this geometry object.
void Sub(PointGeom &a, PointGeom &b)
void Mult(PointGeom &a, PointGeom &b)
_this = a x b
NekDouble dot(PointGeom &a)
retun the dot product between this and input a
std::shared_ptr< Curve > CurveSharedPtr
@ eRegular
Geometry is straight-sided with constant geometric factors.
std::shared_ptr< PointGeom > PointGeomSharedPtr
std::shared_ptr< Geometry1D > Geometry1DSharedPtr
The above copyright notice and this permission notice shall be included.
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)
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 vector y = alpha - x.
scalarT< T > sqrt(scalarT< T > in)