52 ModuleKey ProcessWallNormalData::className =
55 ProcessWallNormalData::create,
56 "Export data in wall-normal direction from a single point on the "
62 f->m_writeBndFld =
false;
66 "The point to be projected onto the wall to get the \
67 sampling origin. default=[0.5,0,0]");
70 "The direction to project the point onto the wall to \
71 get the sampling origin. default=[0,1,0]");
73 false,
"1.0",
"Distance to limit projection distance to find the \
74 desired sampling origin. defalut=1.0");
76 false,
"0.01",
"Sampling distance along the wall normal at the \
77 sampling origin. default=0.1");
79 false,
"5",
"Number of sampling points along the wall normal. \
82 false,
"0.1",
"The parameter that controls the sampling points' \
83 distribution. d should be in the range (0,inf). d \
84 in (0,0.95] gives controled points; d in (0.95,inf) \
85 gives evenly spaced points");
121 const int nfields =
m_f->m_variables.size();
122 const int nCoordDim =
m_f->m_exp[0]->GetCoordim(0);
123 const int nBndLcoordDim = nCoordDim - 1;
127 std::vector<NekDouble> xorig, searchDir;
129 "Failed to interpret origin coordinates string");
132 "Failed to interpret search direction string");
135 const int nptsH =
m_config[
"nptsH"].as<
int>();
139 for (
int i = 0; i < 3; ++i)
141 orig[i] = (xorig.size() >= (i + 1)) ? xorig[i] : 0.0;
142 projDir[i] = (searchDir.size() >= (i + 1)) ? searchDir[i] : 0.0;
152 if (
m_f->m_numHomogeneousDir == 1)
154 int nPlanes =
m_f->m_exp[0]->GetHomogeneousBasis()->GetZ().size();
156 if (orig[2] < 0.0 || orig[2] > lHom)
163 NekDouble zTmp, zCur = 0.0, distTmp, distCur = 999.0;
164 for (
int i = 0; i <= nPlanes; ++i)
167 distTmp = fabs(orig[2] - zTmp);
168 if (distTmp < distCur)
184 m_f->m_exp[0]->GetGraph());
187 map<int, int> BndRegionMap;
189 for (
auto &breg_it : bregions)
191 BndRegionMap[breg_it.first] = cnt++;
193 int bnd = BndRegionMap[
m_f->m_bndRegionsToWrite[0]];
197 for (
int i = 0; i < nfields; ++i)
199 BndExp[i] =
m_f->m_exp[i]->UpdateBndCondExpansion(bnd);
208 bool isInside =
false;
211 const int nElmts = BndExp[0]->GetNumElmts();
212 for (elmtid = 0; elmtid < nElmts; ++elmtid)
214 bndGeom = BndExp[0]->GetExp(elmtid)->GetGeom();
222 ASSERTL0(isInside,
"Failed to find the sampling origin on the boundary.");
226 const int npts = bndXmap->GetTotPoints();
230 for (
int i = 0; i < nCoordDim; ++i)
233 bndCoeffs[i] = bndGeom->GetCoeffs(i);
234 bndXmap->BwdTrans(bndCoeffs[i], pts[i]);
235 orig[i] = bndXmap->PhysEvaluate(locCoord, pts[i]);
241 m_f->m_exp[0]->GetBoundaryNormals(bnd, normalsQ);
246 int from_nPtsPerElmt = 1;
247 for (
int i = 0; i < nBndLcoordDim; ++i)
249 from_key[i] = BndExp[0]->GetExp(elmtid)->GetBasis(i)->GetPointsKey();
250 from_nPtsPerElmt *= from_key[i].GetNumPoints();
255 int refId = elmtid * from_nPtsPerElmt + 0;
258 normalsRef[i] = normalsQ[i][refId];
273 cout <<
"------ wallNormalData module ------\n";
274 cout <<
"Input point:\n";
275 cout <<
" - [Px,Py,Pz] = [" << xorig[0] <<
", " << xorig[1];
276 if (xorig.size() >= 3)
278 cout <<
", " << xorig[2] <<
"]\n";
282 cout <<
", " << 0.0 <<
"]\n";
284 cout <<
"Projection direction:\n";
285 cout <<
" - [vx,vy,vz] = [" << projDir[0] <<
", " << projDir[1] <<
", "
286 << projDir[2] <<
"]\n";
287 cout <<
"Sampling origin on the wall:\n";
288 cout <<
" - [Ox,Oy,Oz] = [" << orig[0] <<
", " << orig[1] <<
", "
290 cout <<
"Normals at the origin:\n";
291 cout <<
" - [nx,ny,nz] = [" << normals[0] <<
", " << normals[1] <<
", "
292 << normals[2] <<
"]\n";
294 <<
"Ref normals (at quadrature points in the projected element):\n";
295 for (
int i = 0; i < from_nPtsPerElmt; ++i)
297 cout <<
" - " << i <<
": [nx,ny,nz] = ["
298 << -normalsQ[0][elmtid * from_nPtsPerElmt + i] <<
", "
299 << -normalsQ[1][elmtid * from_nPtsPerElmt + i];
302 cout <<
", " << -normalsQ[2][elmtid * from_nPtsPerElmt + i]
316 if (delta > 0 && delta <= 0.95)
325 for (
int i = 1; i < nptsH; ++i)
327 tmp1 = 1.0 - i * tmp2;
328 h[i] = 1 - tanh(tmp1 * tmp4) * tmp5;
332 else if (delta > 0.95)
336 for (
int i = 1; i < nptsH; ++i)
344 ASSERTL0(
false,
"Input error. Delta needs to be greater than 0.0.");
349 for (
int i = 0; i < totVars; ++i)
356 for (
int j = 0; j < nptsH; ++j)
358 ptsH[i][j] = orig[i] + h[j] * normals[i];
386 tmp1 =
Vmath::Dot(3, gloCoord, 1, projDir, 1);
387 Vmath::Smul(3, distToOrig - tmp1, projDir, 1, tmp2,
389 Vmath::Vadd(3, gloCoord, 1, tmp2, 1, projGloCoord, 1);
405 const int nCoordDim = pts.size();
406 const int npts = pts[0].size();
411 for (
int i = 0; i < npts; ++i)
414 for (
int j = 0; j < nCoordDim; ++j)
416 singlePnt[j] = pts[j][i];
420 tmp1 =
Vmath::Dot(nCoordDim, singlePnt, 1, projDir, 1);
421 Vmath::Smul(nCoordDim, distToOrig - tmp1, projDir, 1, tmp2, 1);
422 Vmath::Vadd(nCoordDim, singlePnt, 1, tmp2, 1, singlePnt, 1);
425 for (
int j = 0; j < nCoordDim; ++j)
427 projPts[j][i] = singlePnt[j];
447 const NekDouble npts = projPts[0].size();
451 vec1[0] = projPts[0][0] - projGloCoord[0];
452 vec1[1] = projPts[1][0] - projGloCoord[1];
453 vec2[0] = projPts[0][npts - 1] - projGloCoord[0];
454 vec2[1] = projPts[1][npts - 1] - projGloCoord[1];
461 if ((fabs(vec1[0] + vec2[0]) + fabs(vec1[1] + vec2[1])) < paralTol)
480 const NekDouble npts = projPts[0].size();
483 const int nptsPolygon = 4 * nptsEdge - 4;
485 for (
int i = 0; i < 3; ++i)
489 for (
int j = 0; j < nptsEdge; ++j)
491 ptsPolygon[i][j] = projPts[i][j];
493 for (
int j = 0; j < nptsEdge - 2; ++j)
495 ptsPolygon[i][nptsEdge + j] = projPts[i][(j + 2) * nptsEdge - 1];
497 for (
int j = 0; j < nptsEdge; ++j)
499 ptsPolygon[i][2 * nptsEdge - 2 + j] = projPts[i][npts - 1 - j];
501 for (
int j = 0; j < nptsEdge - 2; ++j)
503 ptsPolygon[i][3 * nptsEdge - 2 + j] =
504 projPts[i][nptsEdge * (nptsEdge - j - 2)];
509 NekDouble angleCos, angleAbs, angleSign, angleSum = 0.0;
513 for (
int i = 0; i < nptsPolygon; ++i)
516 id2 = (id1 == (nptsPolygon - 1)) ? 0 : (id1 + 1);
518 for (
int j = 0; j < 3; ++j)
520 vec1[j] = ptsPolygon[j][id1] - projGloCoord[j];
521 vec2[j] = ptsPolygon[j][id2] - projGloCoord[j];
529 if ((fabs(vec1[0] + vec2[0]) + fabs(vec1[1] + vec2[1]) +
530 fabs(vec1[2] + vec2[2])) < paralTol)
540 vec3[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
541 vec3[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
542 vec3[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
545 angleSign =
Vmath::Dot(3, vec3, 1, projDir, 1) > 0.0 ? 1.0 : -1.0;
553 else if (angleCos < -1.0)
558 angleAbs = acos(angleCos);
559 angleSum += angleSign * angleAbs;
564 angleSum = fabs(angleSum);
565 if (fabs(angleSum - 2.0 * M_PI) < angleTol)
594 const NekDouble iterTol,
const int iterMax)
605 bool isConverge =
false;
606 while (cnt < iterMax)
608 tmpL = bndXmap->PhysEvaluate(etaLR, pts[dirUse[0]]);
609 tmpR = bndXmap->PhysEvaluate(etaLR + 1, pts[dirUse[0]]);
611 if (fabs(gloCoord[dirUse[0]] - tmpL) >=
612 fabs(gloCoord[dirUse[0]] - tmpR))
614 etaLR[0] = 0.5 * (etaLR[0] + etaLR[1]);
618 etaLR[1] = 0.5 * (etaLR[0] + etaLR[1]);
621 if ((etaLR[1] - etaLR[0]) < iterTol)
623 locCoord[0] = 0.5 * (etaLR[0] + etaLR[1]);
634 WARNINGL1(
false,
"Bisection iteration is not converged");
653 bndGeom->GetMetricInfo()->GetJac(bndXmap->GetPointsKeys());
656 scaledTol *= iterTol;
659 const int dir1 = dirUse[0];
660 const int dir2 = dirUse[1];
668 bndXmap->PhysDeriv(pts[dir1], Dx1D1, Dx1D2);
669 bndXmap->PhysDeriv(pts[dir2], Dx2D1, Dx2D2);
676 NekDouble derx1_1, derx1_2, derx2_1, derx2_2, jac;
679 bool isConverge =
false;
682 resid =
sqrt(F1 * F1 + F2 * F2);
683 while (cnt++ < iterMax)
685 x1map = bndXmap->PhysEvaluate(locCoord, pts[dir1]);
686 x2map = bndXmap->PhysEvaluate(locCoord, pts[dir2]);
688 F1 = gloCoord[dir1] - x1map;
689 F2 = gloCoord[dir2] - x2map;
691 if (F1 * F1 + F2 * F2 < scaledTol)
693 resid =
sqrt(F1 * F1 + F2 * F2);
699 derx1_1 = bndXmap->PhysEvaluate(locCoord, Dx1D1);
700 derx1_2 = bndXmap->PhysEvaluate(locCoord, Dx1D2);
701 derx2_1 = bndXmap->PhysEvaluate(locCoord, Dx2D1);
702 derx2_2 = bndXmap->PhysEvaluate(locCoord, Dx2D2);
704 jac = derx2_2 * derx1_1 - derx2_1 * derx1_2;
708 locCoord[0] = locCoord[0] + (derx2_2 * (gloCoord[dir1] - x1map) -
709 derx1_2 * (gloCoord[dir2] - x2map)) /
712 locCoord[1] = locCoord[1] + (-derx2_1 * (gloCoord[dir1] - x1map) +
713 derx1_1 * (gloCoord[dir2] - x2map)) /
717 if (!(std::isfinite(locCoord[0]) && std::isfinite(locCoord[1])))
720 std::ostringstream ss;
721 ss <<
"nan or inf found in NewtonIterForLocCoordOnProjBndElmt in "
723 << bndGeom->GetGlobalID();
727 if (fabs(locCoord[0]) > LcoordDiv || fabs(locCoord[1]) > LcoordDiv)
735 bndXmap->LocCoordToLocCollapsed(locCoord, eta);
737 if (bndGeom->ClampLocCoords(eta, 0.0))
740 x1map = bndXmap->PhysEvaluate(eta, pts[dir1]);
741 x2map = bndXmap->PhysEvaluate(eta, pts[dir2]);
743 F1 = gloCoord[dir1] - x1map;
744 F2 = gloCoord[dir2] - x2map;
746 dist =
sqrt(F1 * F1 + F2 * F2);
757 bndXmap->LocCoordToLocCollapsed(locCoord, collCoords);
760 if ((collCoords[0] >= -1.0 && collCoords[0] <= 1.0) &&
761 (collCoords[1] >= -1.0 && collCoords[1] <= 1.0))
763 std::ostringstream ss;
765 ss <<
"Reached MaxIterations (" << iterMax
766 <<
") in Newton iteration ";
767 ss <<
"Init value (" << setprecision(4) << 0 <<
"," << 0 <<
","
769 ss <<
"Fin value (" << locCoord[0] <<
"," << locCoord[1] <<
","
771 ss <<
"Resid = " << resid <<
" Tolerance = " <<
sqrt(scaledTol);
803 const int npts = bndXmap->GetTotPoints();
804 const int nCoordDim =
m_f->m_exp[0]->GetCoordim(0);
811 for (
int i = 0; i < nCoordDim; ++i)
815 bndCoeffs[i] = bndGeom->GetCoeffs(i);
816 bndXmap->BwdTrans(bndCoeffs[i], pts[i]);
829 for (
int i = 1; i < nCoordDim; ++i)
831 if (fabs(projDir[i]) > fabs(projDir[dirMaxId]))
863 else if (dirMaxId == 1)
883 bool isConverge, isDesired;
886 bndGeom, projGloCoord, projPts, dirUse, locCoord, iterTol);
889 tmp[0] = bndXmap->PhysEvaluate(locCoord, pts[0]) - gloCoord[0];
890 tmp[1] = bndXmap->PhysEvaluate(locCoord, pts[1]) - gloCoord[1];
893 isDesired = (projDist > 0.0) && (projDist < maxDist);
895 return isConverge && isDesired;
908 bool isConverge, isDesired;
912 dirUse, locCoord, dist, iterTol);
916 std::ostringstream ss;
917 ss <<
"Collapsed locCoord out of range.\n"
918 <<
"Newton iteration gives the distance: " << dist;
923 tmp[0] = bndXmap->PhysEvaluate(locCoord, pts[0]) - gloCoord[0];
924 tmp[1] = bndXmap->PhysEvaluate(locCoord, pts[1]) - gloCoord[1];
925 tmp[2] = bndXmap->PhysEvaluate(locCoord, pts[2]) - gloCoord[2];
928 isDesired = (projDist > 0.0) && (projDist < maxDist);
930 return isConverge && isDesired;
950 const int nCoordDim =
m_f->m_exp[0]->GetCoordim(0);
954 int npts = bndXmap->GetTotPoints();
957 for (
int i = 0; i < nCoordDim; ++i)
960 bndCoeffs[i] = bndGeom->GetCoeffs(i);
961 bndXmap->BwdTrans(bndCoeffs[i], pts[i]);
970 bndXmap->PhysDeriv(pts[0], DxD1);
971 bndXmap->PhysDeriv(pts[1], DyD1);
974 dxd1 = bndXmap->PhysEvaluate(locCoord, DxD1);
975 dyd1 = bndXmap->PhysEvaluate(locCoord, DyD1);
976 norm =
sqrt(dxd1 * dxd1 + dyd1 * dyd1);
978 normals[0] = dyd1 / norm;
979 normals[1] = -dxd1 / norm;
991 bndXmap->PhysDeriv(pts[0], DxD1, DxD2);
992 bndXmap->PhysDeriv(pts[1], DyD1, DyD2);
993 bndXmap->PhysDeriv(pts[2], DzD1, DzD2);
995 NekDouble dxd1, dyd1, dzd1, dxd2, dyd2, dzd2;
996 dxd1 = bndXmap->PhysEvaluate(locCoord, DxD1);
997 dxd2 = bndXmap->PhysEvaluate(locCoord, DxD2);
998 dyd1 = bndXmap->PhysEvaluate(locCoord, DyD1);
999 dyd2 = bndXmap->PhysEvaluate(locCoord, DyD2);
1000 dzd1 = bndXmap->PhysEvaluate(locCoord, DzD1);
1001 dzd2 = bndXmap->PhysEvaluate(locCoord, DzD2);
1004 n1 = dyd1 * dzd2 - dyd2 * dzd1;
1005 n2 = dzd1 * dxd2 - dzd2 * dxd1;
1006 n3 = dxd1 * dyd2 - dxd2 * dyd1;
1007 norm =
sqrt(n1 * n1 + n2 * n2 + n3 * n3);
1009 normals[0] = n1 / norm;
1010 normals[1] = n2 / norm;
1011 normals[2] = n3 / norm;
#define WARNINGL1(condition, msg)
#define ASSERTL0(condition, msg)
A class that contains algorithms for interpolation between pts fields, expansions and different meshe...
FIELD_UTILS_EXPORT void Interpolate(const T expInField, T &expOutField, NekDouble def_value=0.0)
Interpolate from an expansion to an expansion.
FieldSharedPtr m_f
Field object.
std::map< std::string, ConfigOption > m_config
List of configuration values.
void ProjectPoint(const Array< OneD, const NekDouble > &gloCoord, const Array< OneD, const NekDouble > &projDir, const NekDouble distToOrig, Array< OneD, NekDouble > &projGloCoord)
Project a single point along the given direction to a plane.
bool BndElmtContainsPoint(SpatialDomains::GeometrySharedPtr bndGeom, const Array< OneD, const NekDouble > &gloCoord, const Array< OneD, const NekDouble > &projDir, Array< OneD, NekDouble > &locCoord, NekDouble &projDist, const NekDouble maxDist=1.0, const NekDouble iterTol=1.0e-8)
Check if a point can be projected onto an oundary element in a given direction. If yes,...
bool NewtonIterForLocCoordOnBndElmt(SpatialDomains::GeometrySharedPtr bndGeom, const Array< OneD, const NekDouble > &gloCoord, const Array< OneD, const Array< OneD, NekDouble >> &pts, const Array< OneD, const int > &dirUse, Array< OneD, NekDouble > &locCoord, NekDouble &dist, const NekDouble iterTol=1.0e-8, const int iterMax=51)
void ProjectVertices(const Array< OneD, const Array< OneD, NekDouble >> &pts, const Array< OneD, const NekDouble > &projDir, const NekDouble distToOrig, Array< OneD, Array< OneD, NekDouble >> &projPts)
Project a single point along the given direction to a plane.
void GetNormals(SpatialDomains::GeometrySharedPtr bndGeom, const Array< OneD, const NekDouble > &locCoord, Array< OneD, NekDouble > &normals)
Get the normals for a given locCoord.
virtual void v_Process(po::variables_map &vm) override
Write mesh to output file.
bool BisectionForLocCoordOnBndElmt(SpatialDomains::GeometrySharedPtr bndGeom, const Array< OneD, const NekDouble > &gloCoord, const Array< OneD, const Array< OneD, NekDouble >> &pts, const Array< OneD, const int > &dirUse, Array< OneD, NekDouble > &locCoord, const NekDouble iterTol=1.0e-8, const int iterMax=51)
Use iteration to get the locCoord. This routine should be used after we have checked the projected po...
virtual ~ProcessWallNormalData()
bool isInProjectedArea3D(const Array< OneD, const NekDouble > &projGloCoord, const Array< OneD, const Array< OneD, NekDouble >> &projPts, const Array< OneD, const NekDouble > &projDir, const NekDouble paralTol=1.0e-12, const NekDouble angleTol=1.0e-6)
bool isInProjectedArea2D(const Array< OneD, const NekDouble > &projGloCoord, const Array< OneD, const Array< OneD, NekDouble >> &projPts, const NekDouble paralTol=1.0e-12)
Determine if the projected point is inside the projected element.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
const BoundaryRegionCollection & GetBoundaryRegions(void) const
std::shared_ptr< Field > FieldSharedPtr
std::pair< ModuleType, std::string > ModuleKey
ModuleFactory & GetModuleFactory()
static std::map< PtsInfo, int > NullPtsInfoMap
static const NekDouble kNekUnsetDouble
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
std::shared_ptr< Geometry > GeometrySharedPtr
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
The above copyright notice and this permission notice shall be included.
void Neg(int n, T *x, const int incx)
Negate x = -x.
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
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
scalarT< T > sqrt(scalarT< T > in)
Represents a command-line configuration option.