38 #include <boost/shared_ptr.hpp>
43 namespace SpatialDomains
53 "Coordinate dimension should be at least 2 for a 2D geometry");
101 const Array<OneD, const NekDouble> &coords,
102 const Array<OneD, const NekDouble> &ptsx,
103 const Array<OneD, const NekDouble> &ptsy,
104 Array<OneD, NekDouble> &Lcoords,
108 const int MaxIterations = 51;
114 Array<OneD, const NekDouble > Jac =
122 NekDouble derx_1, derx_2, dery_1, dery_2,jac;
125 NekDouble init0 = Lcoords[0], init1 = Lcoords[1];
127 Array<OneD, NekDouble> DxD1(ptsx.num_elements());
128 Array<OneD, NekDouble> DxD2(ptsx.num_elements());
129 Array<OneD, NekDouble> DyD1(ptsx.num_elements());
130 Array<OneD, NekDouble> DyD2(ptsx.num_elements());
133 m_xmap->PhysDeriv(ptsx,DxD1,DxD2);
134 m_xmap->PhysDeriv(ptsy,DyD1,DyD2);
137 Array<OneD, DNekMatSharedPtr > I(2);
138 Array<OneD, NekDouble> eta(2);
142 while(cnt++ < MaxIterations)
145 m_xmap->LocCoordToLocCollapsed(Lcoords,eta);
146 I[0] =
m_xmap->GetBasis(0)->GetI(eta);
147 I[1] =
m_xmap->GetBasis(1)->GetI(eta+1);
150 xmap =
m_xmap->PhysEvaluate(I, ptsx);
151 ymap =
m_xmap->PhysEvaluate(I, ptsy);
153 F1 = coords[0] - xmap;
154 F2 = coords[1] - ymap;
156 if(F1*F1 + F2*F2 < ScaledTol)
158 resid = sqrt(F1*F1 + F2*F2);
163 derx_1 =
m_xmap->PhysEvaluate(I, DxD1);
164 derx_2 =
m_xmap->PhysEvaluate(I, DxD2);
165 dery_1 =
m_xmap->PhysEvaluate(I, DyD1);
166 dery_2 =
m_xmap->PhysEvaluate(I, DyD2);
168 jac = dery_2*derx_1 - dery_1*derx_2;
172 Lcoords[0] = Lcoords[0] + (dery_2*(coords[0]-xmap) -
173 derx_2*(coords[1]-ymap))/jac;
175 Lcoords[1] = Lcoords[1] + ( - dery_1*(coords[0]-xmap)
176 + derx_1*(coords[1]-ymap))/jac;
178 if(fabs(Lcoords[0]) > LcoordDiv || fabs(Lcoords[1]) > LcoordDiv)
184 resid = sqrt(F1*F1 + F2*F2);
186 if(cnt >= MaxIterations)
188 Array<OneD, NekDouble> collCoords(2);
189 m_xmap->LocCoordToLocCollapsed(Lcoords,collCoords);
192 if((collCoords[0] >= -1.0 && collCoords[0] <= 1.0)&&
193 (collCoords[1] >= -1.0 && collCoords[1] <= 1.0))
195 std::ostringstream ss;
197 ss <<
"Reached MaxIterations (" << MaxIterations
198 <<
") in Newton iteration ";
199 ss <<
"Init value ("<< setprecision(4) << init0 <<
","
200 << init1<<
"," <<
") ";
201 ss <<
"Fin value ("<<Lcoords[0] <<
"," << Lcoords[1]
203 ss <<
"Resid = " << resid <<
" Tolerance = "
214 "This function is only valid for shape type geometries");
221 "This function is only valid for shape type geometries");
230 "This function is only valid for shape type geometries");
237 "This function is only valid for shape type geometries");
245 "This function is only valid for shape type geometries");
253 "This function is only valid for shape type geometries");
260 "This function is only valid for shape type geometries");
268 "This function is only valid for shape type geometries");
275 "This function is only valid for shape type geometries");
282 "This function is only valid for shape type geometries");
289 "This function is only valid for shape type geometries");
299 const Array<OneD, const NekDouble>& gloCoord,
303 "This function has not been defined for this geometry");