55 ProcessWallNormalData::create,
56 "Export data in wall-normal direction from a single point on the wall.");
60 f->m_writeBndFld =
false;
63 "The point to be projected onto the wall to get the \
64 sampling origin. default=[0.5,0,0]");
66 "The direction to project the point onto the wall to \
67 get the sampling origin. default=[0,1,0]");
69 "Distance to limit projection distance to find the \
70 desired sampling origin. defalut=1.0");
72 "Sampling distance along the wall normal at the \
73 sampling origin. default=0.1");
75 "Number of sampling points along the wall normal. \
78 "The parameter that controls the sampling points' \
79 distribution. d should be in the range (0,inf). d \
80 in (0,0.95] gives controled points; d in (0.95,inf) \
81 gives evenly spaced points");
115 const int nfields =
m_f->m_variables.size();
116 const int nCoordDim =
m_f->m_exp[0]->GetCoordim(0);
118 const int nBndLcoordDim = nCoordDim - 1;
123 std::vector<NekDouble> xorig, searchDir;
125 "Failed to interpret origin coordinates string");
127 "Failed to interpret search direction string");
130 const int nptsH =
m_config[
"nptsH"].as<
int>();
135 for (
int i=0; i<3; ++i)
137 orig[i] = (xorig.size()>=(i+1)) ? xorig[i] : 0.0;
138 projDir[i] = (searchDir.size()>=(i+1)) ? searchDir[i] : 0.0;
145 projDir, 1, projDir, 1);
148 if (
m_f->m_numHomogeneousDir==1)
150 int nPlanes =
m_f->m_exp[0]->GetHomogeneousBasis()->GetZ().size();
152 if (orig[2]<0.0 || orig[2]>lHom)
159 NekDouble zTmp, zCur=0.0, distTmp, distCur = 999.0;
160 for(
int i=0; i<=nPlanes; ++i)
163 distTmp = fabs(orig[2] - zTmp);
164 if(distTmp < distCur)
181 m_f->m_exp[0]->GetGraph());
184 map<int, int> BndRegionMap;
186 for (
auto &breg_it : bregions)
188 BndRegionMap[breg_it.first] = cnt++;
190 int bnd = BndRegionMap[
m_f->m_bndRegionsToWrite[0]];
194 for (
int i = 0; i < nfields; ++i) {
195 BndExp[i] =
m_f->m_exp[i]->UpdateBndCondExpansion(bnd);
205 bool isInside =
false;
208 const int nElmts = BndExp[0]->GetNumElmts();
209 for (elmtid=0; elmtid<nElmts; ++elmtid)
211 bndGeom = BndExp[0]->GetExp(elmtid)->GetGeom();
220 ASSERTL0(isInside,
"Failed to find the sampling origin on the boundary.");
225 const int npts = bndXmap->GetTotPoints();
229 for (
int i=0; i<nCoordDim; ++i)
232 bndCoeffs[i] = bndGeom->GetCoeffs(i);
233 bndXmap->BwdTrans(bndCoeffs[i], pts[i]);
234 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];
278 cout <<
", " << xorig[2] <<
"]\n";
282 cout <<
", " << 0.0 <<
"]\n";
284 cout <<
"Projection direction:\n";
285 cout <<
" - [vx,vy,vz] = ["
286 << projDir[0] <<
", " << projDir[1] <<
", " << projDir[2] <<
"]\n";
287 cout <<
"Sampling origin on the wall:\n";
288 cout <<
" - [Ox,Oy,Oz] = ["
289 << orig[0] <<
", " << orig[1] <<
", " << orig[2] <<
"]\n";
290 cout <<
"Normals at the origin:\n";
291 cout <<
" - [nx,ny,nz] = ["
292 << normals[0] <<
", " << normals[1] <<
", " << normals[2] <<
"]\n";
293 cout <<
"Ref normals (at quadrature points in the projected element):\n";
294 for (
int i=0; i<from_nPtsPerElmt; ++i)
296 cout <<
" - " << i <<
": [nx,ny,nz] = ["
297 << -normalsQ[0][elmtid*from_nPtsPerElmt+i] <<
", "
298 << -normalsQ[1][elmtid*from_nPtsPerElmt+i];
301 cout <<
", " << -normalsQ[2][elmtid*from_nPtsPerElmt+i] <<
"]\n";
315 if (delta > 0 && delta <= 0.95)
324 for (
int i=1; i<nptsH; ++i)
326 tmp1 = 1.0 - i * tmp2;
327 h[i] = 1 - tanh(tmp1*tmp4)*tmp5;
331 else if (delta > 0.95)
335 for (
int i=1; i<nptsH; ++i)
343 ASSERTL0(
false,
"Input error. Delta needs to be greater than 0.0.");
348 for (
int i=0; i<totVars; ++i)
355 for(
int j=0; j<nptsH; ++j)
357 ptsH[i][j] = orig[i] + h[j] * normals[i];
387 tmp1 =
Vmath::Dot(3, gloCoord, 1, projDir, 1);
388 Vmath::Smul(3, distToOrig-tmp1, projDir, 1, tmp2, 1);
389 Vmath::Vadd(3, gloCoord, 1, tmp2, 1, projGloCoord,1);
407 const int nCoordDim = pts.size();
408 const int npts = pts[0].size();
413 for (
int i=0; i<npts; ++i)
416 for (
int j=0; j<nCoordDim; ++j)
418 singlePnt[j] = pts[j][i];
422 tmp1 =
Vmath::Dot(nCoordDim, singlePnt, 1, projDir, 1);
423 Vmath::Smul(nCoordDim, distToOrig-tmp1, projDir, 1, tmp2, 1);
424 Vmath::Vadd(nCoordDim, singlePnt, 1, tmp2, 1, singlePnt,1);
427 for (
int j=0; j<nCoordDim; ++j)
429 projPts[j][i] = singlePnt[j];
451 const NekDouble npts = projPts[0].size();
455 vec1[0] = projPts[0][0] - projGloCoord[0];
456 vec1[1] = projPts[1][0] - projGloCoord[1];
457 vec2[0] = projPts[0][npts-1] - projGloCoord[0];
458 vec2[1] = projPts[1][npts-1] - projGloCoord[1];
465 if( (fabs(vec1[0]+vec2[0]) + fabs(vec1[1]+vec2[1])) < paralTol )
487 const NekDouble npts = projPts[0].size();
488 const int nptsEdge =
sqrt(npts);
489 const int nptsPolygon = 4*nptsEdge-4;
491 for (
int i=0; i<3; ++i)
495 for(
int j=0; j<nptsEdge; ++j)
497 ptsPolygon[i][j] = projPts[i][j];
499 for(
int j=0; j<nptsEdge-2; ++j)
501 ptsPolygon[i][nptsEdge+j] = projPts[i][(j+2)*nptsEdge-1];
503 for(
int j=0; j<nptsEdge; ++j)
505 ptsPolygon[i][2*nptsEdge-2+j] = projPts[i][npts-1-j];
507 for(
int j=0; j<nptsEdge-2; ++j)
509 ptsPolygon[i][3*nptsEdge-2+j] = projPts[i][nptsEdge*(nptsEdge-j-2)];
515 NekDouble angleCos, angleAbs, angleSign, angleSum = 0.0;
519 for(
int i=0; i<nptsPolygon; ++i)
522 id2 = (id1==(nptsPolygon-1)) ? 0 : (id1+1);
524 for (
int j=0; j<3; ++j)
526 vec1[j] = ptsPolygon[j][id1] - projGloCoord[j];
527 vec2[j] = ptsPolygon[j][id2] - projGloCoord[j];
536 if( ( fabs(vec1[0]+vec2[0]) + fabs(vec1[1]+vec2[1]) +
537 fabs(vec1[2]+vec2[2]) ) < paralTol )
547 vec3[0] = vec1[1]*vec2[2] - vec1[2]*vec2[1];
548 vec3[1] = vec1[2]*vec2[0] - vec1[0]*vec2[2];
549 vec3[2] = vec1[0]*vec2[1] - vec1[1]*vec2[0];
552 angleSign =
Vmath::Dot(3, vec3, 1, projDir, 1) > 0.0 ? 1.0 : -1.0;
560 else if(angleCos<-1.0)
565 angleAbs = acos(angleCos);
566 angleSum += angleSign * angleAbs;
571 angleSum = fabs(angleSum);
572 if( fabs(angleSum-2.0*M_PI) < angleTol )
616 bool isConverge =
false;
619 tmpL = bndXmap->PhysEvaluate(etaLR , pts[dirUse[0]]);
620 tmpR = bndXmap->PhysEvaluate(etaLR+1, pts[dirUse[0]]);
622 if (fabs(gloCoord[dirUse[0]]-tmpL) >= fabs(gloCoord[dirUse[0]]-tmpR))
624 etaLR[0] = 0.5 * (etaLR[0]+etaLR[1]);
628 etaLR[1] = 0.5 * (etaLR[0]+etaLR[1]);
631 if ((etaLR[1]-etaLR[0]) < iterTol)
633 locCoord[0] = 0.5 * (etaLR[0]+etaLR[1]);
644 WARNINGL1(
false,
"Bisection iteration is not converged");
667 bndGeom->GetMetricInfo()->GetJac(bndXmap->GetPointsKeys());
670 scaledTol *= iterTol;
674 const int dir1 = dirUse[0];
675 const int dir2 = dirUse[1];
683 bndXmap->PhysDeriv(pts[dir1], Dx1D1, Dx1D2);
684 bndXmap->PhysDeriv(pts[dir2], Dx2D1, Dx2D2);
691 NekDouble derx1_1, derx1_2, derx2_1, derx2_2, jac;
694 bool isConverge =
false;
698 while (cnt++ < iterMax)
700 x1map = bndXmap->PhysEvaluate(locCoord, pts[dir1]);
701 x2map = bndXmap->PhysEvaluate(locCoord, pts[dir2]);
703 F1 = gloCoord[dir1] - x1map;
704 F2 = gloCoord[dir2] - x2map;
706 if (F1 * F1 + F2 * F2 < scaledTol)
708 resid =
sqrt(F1 * F1 + F2 * F2);
714 derx1_1 = bndXmap->PhysEvaluate(locCoord, Dx1D1);
715 derx1_2 = bndXmap->PhysEvaluate(locCoord, Dx1D2);
716 derx2_1 = bndXmap->PhysEvaluate(locCoord, Dx2D1);
717 derx2_2 = bndXmap->PhysEvaluate(locCoord, Dx2D2);
719 jac = derx2_2 * derx1_1 - derx2_1 * derx1_2;
723 locCoord[0] = locCoord[0] + ( derx2_2 * (gloCoord[dir1] - x1map) -
724 derx1_2 * (gloCoord[dir2] - x2map)) / jac;
726 locCoord[1] = locCoord[1] + (-derx2_1 * (gloCoord[dir1] - x1map) +
727 derx1_1 * (gloCoord[dir2] - x2map)) / jac;
731 if( !(std::isfinite(locCoord[0]) && std::isfinite(locCoord[1])) )
734 std::ostringstream ss;
735 ss <<
"nan or inf found in NewtonIterForLocCoordOnProjBndElmt in element "
736 << bndGeom->GetGlobalID();
740 if (fabs(locCoord[0]) > LcoordDiv || fabs(locCoord[1]) > LcoordDiv)
748 bndXmap->LocCoordToLocCollapsed(locCoord, eta);
750 if(bndGeom->ClampLocCoords(eta, 0.0))
753 x1map = bndXmap->PhysEvaluate(eta, pts[dir1]);
754 x2map = bndXmap->PhysEvaluate(eta, pts[dir2]);
756 F1 = gloCoord[dir1] - x1map;
757 F2 = gloCoord[dir2] - x2map;
759 dist =
sqrt(F1 * F1 + F2 * F2);
770 bndXmap->LocCoordToLocCollapsed(locCoord, collCoords);
773 if ((collCoords[0] >= -1.0 && collCoords[0] <= 1.0) &&
774 (collCoords[1] >= -1.0 && collCoords[1] <= 1.0))
776 std::ostringstream ss;
778 ss <<
"Reached MaxIterations (" << iterMax
779 <<
") in Newton iteration ";
780 ss <<
"Init value (" << setprecision(4) << 0 <<
"," << 0
783 ss <<
"Fin value (" << locCoord[0] <<
"," << locCoord[1] <<
","
785 ss <<
"Resid = " << resid <<
" Tolerance = " <<
sqrt(scaledTol);
821 const int npts = bndXmap->GetTotPoints();
822 const int nCoordDim =
m_f->m_exp[0]->GetCoordim(0);
829 for (
int i=0; i<nCoordDim; ++i)
833 bndCoeffs[i] = bndGeom->GetCoeffs(i);
834 bndXmap->BwdTrans(bndCoeffs[i], pts[i]);
847 for (
int i=1; i<nCoordDim; ++i)
849 if (fabs(projDir[i])>fabs(projDir[dirMaxId]))
881 else if (dirMaxId==1)
903 bool isConverge, isDesired;
906 projPts, dirUse, locCoord, iterTol);
909 tmp[0] = bndXmap->PhysEvaluate(locCoord, pts[0]) - gloCoord[0];
910 tmp[1] = bndXmap->PhysEvaluate(locCoord, pts[1]) - gloCoord[1];
913 isDesired = (projDist > 0.0) && (projDist < maxDist);
915 return isConverge && isDesired;
928 bool isConverge, isDesired;
931 projPts, dirUse, locCoord, dist, iterTol);
935 std::ostringstream ss;
936 ss <<
"Collapsed locCoord out of range.\n"
937 <<
"Newton iteration gives the distance: " << dist;
942 tmp[0] = bndXmap->PhysEvaluate(locCoord, pts[0]) - gloCoord[0];
943 tmp[1] = bndXmap->PhysEvaluate(locCoord, pts[1]) - gloCoord[1];
944 tmp[2] = bndXmap->PhysEvaluate(locCoord, pts[2]) - gloCoord[2];
947 isDesired = (projDist > 0.0) && (projDist < maxDist);
949 return isConverge && isDesired;
972 const int nCoordDim =
m_f->m_exp[0]->GetCoordim(0);
976 int npts = bndXmap->GetTotPoints();
979 for (
int i=0; i<nCoordDim; ++i)
982 bndCoeffs[i] = bndGeom->GetCoeffs(i);
983 bndXmap->BwdTrans(bndCoeffs[i], pts[i]);
992 bndXmap->PhysDeriv(pts[0], DxD1);
993 bndXmap->PhysDeriv(pts[1], DyD1);
996 dxd1 = bndXmap->PhysEvaluate(locCoord, DxD1);
997 dyd1 = bndXmap->PhysEvaluate(locCoord, DyD1);
998 norm =
sqrt(dxd1*dxd1 + dyd1*dyd1);
1000 normals[0] = dyd1/norm;
1001 normals[1] = -dxd1/norm;
1013 bndXmap->PhysDeriv(pts[0], DxD1, DxD2);
1014 bndXmap->PhysDeriv(pts[1], DyD1, DyD2);
1015 bndXmap->PhysDeriv(pts[2], DzD1, DzD2);
1017 NekDouble dxd1, dyd1, dzd1, dxd2, dyd2, dzd2;
1018 dxd1 = bndXmap->PhysEvaluate(locCoord, DxD1);
1019 dxd2 = bndXmap->PhysEvaluate(locCoord, DxD2);
1020 dyd1 = bndXmap->PhysEvaluate(locCoord, DyD1);
1021 dyd2 = bndXmap->PhysEvaluate(locCoord, DyD2);
1022 dzd1 = bndXmap->PhysEvaluate(locCoord, DzD1);
1023 dzd2 = bndXmap->PhysEvaluate(locCoord, DzD2);
1026 n1 = dyd1*dzd2 - dyd2*dzd1;
1027 n2 = dzd1*dxd2 - dzd2*dxd1;
1028 n3 = dxd1*dyd2 - dxd2*dyd1;
1029 norm =
sqrt(n1*n1 + n2*n2 + n3*n3);
1031 normals[0] = n1/norm;
1032 normals[1] = n2/norm;
1033 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 std::vector< MultiRegions::ExpListSharedPtr > expInField, std::vector< MultiRegions::ExpListSharedPtr > &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.
virtual void Process(po::variables_map &vm)
Write mesh to output file.
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)
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.
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 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...
void GetNormals(SpatialDomains::GeometrySharedPtr bndGeom, const Array< OneD, const NekDouble > &locCoord, Array< OneD, NekDouble > &normals)
Get the normals for a given locCoord.
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.
virtual ~ProcessWallNormalData()
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)
vvtvp (vector times vector times vector): z = w*x*y
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.