Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
Nektar::SpatialDomains::GeometryLocator3D Class Referencefinal

Inverse mapping for a tetrahedron, pyramid, prism or hexahedron. More...

#include <GeometryLocator.h>

Inheritance diagram for Nektar::SpatialDomains::GeometryLocator3D:
[legend]

Public Member Functions

 GeometryLocator (Geometry *geom)
 
- Public Member Functions inherited from Nektar::SpatialDomains::GeometryLocator
 GeometryLocator (Geometry *geom)
 
virtual ~GeometryLocator ()=default
 
void Build ()
 Populate the cache. Called by Create() once the concrete type exists, since it dispatches virtually.
 
Geometry * GetGeometry () const
 
std::array< NekDouble, 6 > GetBoundingBox ()
 Generates the bounding box for the element.
 
void ClearBoundingBox ()
 
bool ContainsPoint (const Array< OneD, const NekDouble > &gloCoord, NekDouble tol=0.0)
 Determine whether the element contains a Cartesian coordinate.
 
bool ContainsPoint (const Array< OneD, const NekDouble > &gloCoord, Array< OneD, NekDouble > &locCoord, NekDouble tol)
 Determine whether the element contains a Cartesian coordinate.
 
bool ContainsPoint (const Array< OneD, const NekDouble > &gloCoord, Array< OneD, NekDouble > &locCoord, NekDouble tol, NekDouble &dist)
 
NekDouble GetLocCoords (const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
 Determine the local collapsed coordinates corresponding to a given Cartesian coordinate.
 
NekDouble FindDistance (const Array< OneD, const NekDouble > &xs, Array< OneD, NekDouble > &xi)
 
int PreliminaryCheck (const Array< OneD, const NekDouble > &gloCoord, NekDouble &edgeDist)
 A fast and robust check if a given global coord is outside of a deformed element. For regular elements, this check is unnecessary.
 
bool MinMaxCheck (const Array< OneD, const NekDouble > &gloCoord)
 Check if given global coord is within the BoundingBox of the element.
 

Protected Member Functions

NekDouble v_GetLocCoords (const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords) override
 
void v_CalculateInverseIsoParam () override
 
- Protected Member Functions inherited from Nektar::SpatialDomains::GeometryLocator
virtual NekDouble v_FindDistance (const Array< OneD, const NekDouble > &xs, Array< OneD, NekDouble > &xi)
 
virtual int v_AllLeftCheck (const Array< OneD, const NekDouble > &gloCoord, NekDouble &edgeDist)
 
virtual void v_PreSolveStraightEdge ()
 

Private Member Functions

void NewtonIterationForLocCoord (const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords, NekDouble &dist)
 
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)
 

Additional Inherited Members

- Static Public Member Functions inherited from Nektar::SpatialDomains::GeometryLocator
static std::unique_ptr< GeometryLocator > Create (Geometry *geom)
 Build the locator appropriate to geom's dimension, with its cache already populated.
 
static bool ClampLocCoords (Array< OneD, NekDouble > &locCoord, int dim, NekDouble tol=std::numeric_limits< NekDouble >::epsilon())
 Clamp local coordinates into the reference element \([-1-tol,1+tol]^{dim}\), returning whether anything was clamped. Depends only on the reference element, so it needs no locator.
 
- Protected Attributes inherited from Nektar::SpatialDomains::GeometryLocator
Geometry * m_geom
 The geometry being searched. Not owned.
 
IsoParam m_iso
 The shape's isoparametric coefficients. The straight-edged 2D solve rewrites them into a factored form, so the locator keeps its own copy rather than sharing the geometry's.
 
int m_straightEdge = 0
 Non-zero if every \(\chi\) basis is linear. Bits 1 and 2 are used by the 2D straight-edged solve to record which axes were swapped.
 
std::array< std::array< NekDouble, kMaxGeomDim >, kMaxGeomDim > m_invIsoParam {}
 Inverse of the linear part of m_iso, for regular elements.
 
bool m_newtonConverged = false
 Whether the Newton iteration of the last GetLocCoords call converged, i.e. whether its local coordinates map to the point. Set only by elements located by Newton iteration; read by ContainsPoint.
 
bool m_hasBoundingBox = false
 Element bounding box as (xmin, ymin, zmin, xmax, ymax, zmax).
 
std::array< NekDouble, 6 > m_boundingBox {}
 
bool m_edgeNormalBuilt = false
 2D only: inward edge normals used to reject points outside straight-sided elements. A curved edge gets no normal, so m_hasEdgeNormal records which entries are usable.
 
std::array< bool, kMaxGeomVerts > m_hasEdgeNormal {}
 
std::array< std::array< NekDouble, 2 >, kMaxGeomVerts > m_edgeNormal {}
 

Detailed Description

Inverse mapping for a tetrahedron, pyramid, prism or hexahedron.

Definition at line 239 of file GeometryLocator.h.

Member Function Documentation

◆ GeometryLocator()

Nektar::SpatialDomains::GeometryLocator::GeometryLocator ( Geometry *  geom)
explicit

Definition at line 105 of file GeometryLocator.cpp.

50 : m_geom(geom)
51{
52 ASSERTL0(m_geom != nullptr, "A locator needs a geometry to search.");
53}
#define ASSERTL0(condition, msg)
Geometry * m_geom
The geometry being searched. Not owned.

◆ NewtonIterationForLocCoord() [1/2]

void Nektar::SpatialDomains::GeometryLocator3D::NewtonIterationForLocCoord ( const Array< OneD, const NekDouble > &  coords,
Array< OneD, NekDouble > &  Lcoords,
NekDouble &  dist 
)
private

Definition at line 1328 of file GeometryLocator.cpp.

1331{
1332 auto &isoParam = m_iso.m_coeff;
1333 const int nIso = m_iso.m_nCoeff;
1334
1335 // maximum iterations for convergence
1336 const int MaxIterations = 51;
1337 // |x-xp|^2 < EPSILON error tolerance
1338 const NekDouble Tol = 1.e-8;
1339 // |r,s| > LcoordDIV stop the search
1340 const NekDouble LcoordDiv = 15.0;
1341
1343 Array<OneD, const NekDouble> Jac =
1344 m_geom->GenGeomFactors(ptsKeys)->GetJac();
1345
1346 NekDouble ScaledTol =
1347 Vmath::Vsum(Jac.size(), Jac, 1) / ((NekDouble)Jac.size());
1348 ScaledTol *= Tol * Tol;
1349
1350 NekDouble xmap, ymap, zmap, res;
1351 int cnt = 0;
1352 Array<OneD, NekDouble> var(8, 1.);
1353 Array<OneD, NekDouble> deriv(9);
1354 Array<OneD, NekDouble> tmp(3);
1355 m_newtonConverged = false;
1356 while (cnt++ < MaxIterations)
1357 {
1358 var[1] = Lcoords[0];
1359 var[2] = Lcoords[1];
1360 var[3] = Lcoords[2];
1361 var[4] = Lcoords[0] * Lcoords[1];
1362 var[5] = Lcoords[1] * Lcoords[2];
1363 var[6] = Lcoords[0] * Lcoords[2];
1364 var[7] = var[4] * Lcoords[2];
1365 // calculate the global point corresponding to Lcoords
1366 xmap = Vmath::Dot(nIso, var.data(), 1, isoParam[0].data(), 1);
1367 ymap = Vmath::Dot(nIso, var.data(), 1, isoParam[1].data(), 1);
1368 zmap = Vmath::Dot(nIso, var.data(), 1, isoParam[2].data(), 1);
1369
1370 tmp[0] = coords[0] - xmap;
1371 tmp[1] = coords[1] - ymap;
1372 tmp[2] = coords[2] - zmap;
1373
1374 res = tmp[0] * tmp[0] + tmp[1] * tmp[1] + tmp[2] * tmp[2];
1375 if (res < ScaledTol)
1376 {
1377 m_newtonConverged = true;
1378 dist = 0.;
1379 return;
1380 }
1381
1382 // Interpolate derivative metric at Lcoords (ddx1, ddx2, ddx3)
1383 deriv[0] = isoParam[0][1] + isoParam[0][4] * Lcoords[1];
1384 deriv[1] = isoParam[0][2] + isoParam[0][4] * Lcoords[0];
1385 deriv[2] = isoParam[0][3];
1386 deriv[3] = isoParam[1][1] + isoParam[1][4] * Lcoords[1];
1387 deriv[4] = isoParam[1][2] + isoParam[1][4] * Lcoords[0];
1388 deriv[5] = isoParam[1][3];
1389 deriv[6] = isoParam[2][1] + isoParam[2][4] * Lcoords[1];
1390 deriv[7] = isoParam[2][2] + isoParam[2][4] * Lcoords[0];
1391 deriv[8] = isoParam[2][3];
1392 if (nIso >= 6)
1393 {
1394 deriv[1] += isoParam[0][5] * Lcoords[2];
1395 deriv[2] += isoParam[0][5] * Lcoords[1];
1396 deriv[4] += isoParam[1][5] * Lcoords[2];
1397 deriv[5] += isoParam[1][5] * Lcoords[1];
1398 deriv[7] += isoParam[2][5] * Lcoords[2];
1399 deriv[8] += isoParam[2][5] * Lcoords[1];
1400 }
1401 if (nIso >= 8)
1402 {
1403 deriv[0] += isoParam[0][6] * Lcoords[2] + isoParam[0][7] * var[5];
1404 deriv[1] += isoParam[0][7] * var[6];
1405 deriv[2] += isoParam[0][6] * Lcoords[0] + isoParam[0][7] * var[4];
1406 deriv[3] += isoParam[1][6] * Lcoords[2] + isoParam[1][7] * var[5];
1407 deriv[4] += isoParam[1][7] * var[6];
1408 deriv[5] += isoParam[1][6] * Lcoords[0] + isoParam[1][7] * var[4];
1409 deriv[6] += isoParam[2][6] * Lcoords[2] + isoParam[2][7] * var[5];
1410 deriv[7] += isoParam[2][7] * var[6];
1411 deriv[8] += isoParam[2][6] * Lcoords[0] + isoParam[2][7] * var[4];
1412 }
1413 DNekMatSharedPtr mat =
1415 Vmath::Vcopy(9, deriv, 1, mat->GetPtr(), 1);
1416 mat->Invert();
1417 Lcoords[0] += Vmath::Dot(3, mat->GetPtr(), 1, tmp, 1);
1418 Lcoords[1] += Vmath::Dot(3, mat->GetPtr() + 3, 1, tmp, 1);
1419 Lcoords[2] += Vmath::Dot(3, mat->GetPtr() + 6, 1, tmp, 1);
1420
1421 if (!(std::isfinite(Lcoords[0]) && std::isfinite(Lcoords[1]) &&
1422 std::isfinite(Lcoords[2])) ||
1423 fabs(Lcoords[0]) > LcoordDiv || fabs(Lcoords[1]) > LcoordDiv ||
1424 fabs(Lcoords[2]) > LcoordDiv)
1425 {
1426 std::ostringstream ss;
1427 ss << "Iteration has diverged in NewtonIterationForLocCoord in "
1428 "element "
1429 << m_geom->GetGlobalID();
1430 WARNINGL1(false, ss.str());
1431 return;
1432 }
1433 }
1434
1435 // Not converged: Lcoords does not map to coords, so report the residual
1436 // rather than claiming a match
1437 var[1] = Lcoords[0];
1438 var[2] = Lcoords[1];
1439 var[3] = Lcoords[2];
1440 var[4] = Lcoords[0] * Lcoords[1];
1441 var[5] = Lcoords[1] * Lcoords[2];
1442 var[6] = Lcoords[0] * Lcoords[2];
1443 var[7] = var[4] * Lcoords[2];
1444 for (int i = 0; i < 3; ++i)
1445 {
1446 tmp[i] =
1447 coords[i] - Vmath::Dot(nIso, var.data(), 1, isoParam[i].data(), 1);
1448 }
1449 dist = std::sqrt(tmp[0] * tmp[0] + tmp[1] * tmp[1] + tmp[2] * tmp[2]);
1450
1451 std::ostringstream ss;
1452
1453 ss << "Reached MaxIterations (" << MaxIterations
1454 << ") in Newton iteration ";
1455
1456 WARNINGL1(cnt < MaxIterations, ss.str());
1457}
#define WARNINGL1(condition, msg)
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
int GetGlobalID(void) const
Get the ID of this object.
Definition Geometry.h:465
StdRegions::StdExpansion * GetXmap() const
The expansion holding the mapping from the standard element to this one. Shared between geometries a...
Definition Geometry.h:571
GeomFactorsUniquePtr GenGeomFactors(LibUtilities::PointsKeyVector &keyTgt)
Build the #GeomFactors for this object at the quadrature points keyTgt.
Definition Geometry.h:565
IsoParam m_iso
The shape's isoparametric coefficients. The straight-edged 2D solve rewrites them into a factored for...
bool m_newtonConverged
Whether the Newton iteration of the last GetLocCoords call converged, i.e. whether its local coordina...
const LibUtilities::PointsKeyVector GetPointsKeys() const
std::vector< PointsKey > PointsKeyVector
Definition Points.h:309
std::shared_ptr< DNekMat > DNekMatSharedPtr
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
Definition Vmath.hpp:611
T Dot(int n, const T *w, const T *x)
dot product
Definition Vmath.hpp:764
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:828
int m_nCoeff
Coefficients per coordinate direction. Only the leading m_nCoeff entries of each row are meaningful,...
std::array< std::array< NekDouble, kMaxGeomIsoCoeff >, kMaxGeomDim > m_coeff

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Vmath::Dot(), Nektar::eFULL, Nektar::SpatialDomains::Geometry::GenGeomFactors(), Nektar::SpatialDomains::Geometry::GetGlobalID(), Nektar::StdRegions::StdExpansion::GetPointsKeys(), Nektar::SpatialDomains::Geometry::GetXmap(), Nektar::SpatialDomains::IsoParam::m_coeff, Nektar::SpatialDomains::GeometryLocator::m_geom, Nektar::SpatialDomains::GeometryLocator::m_iso, Nektar::SpatialDomains::IsoParam::m_nCoeff, Nektar::SpatialDomains::GeometryLocator::m_newtonConverged, Vmath::Vcopy(), Vmath::Vsum(), and WARNINGL1.

Referenced by v_GetLocCoords().

◆ NewtonIterationForLocCoord() [2/2]

void Nektar::SpatialDomains::GeometryLocator3D::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 
)
private

Definition at line 1459 of file GeometryLocator.cpp.

1465{
1466 // maximum iterations for convergence
1467 const int MaxIterations = NekConstants::kNewtonIterations;
1468 // |x-xp|^2 < EPSILON error tolerance
1469 const NekDouble Tol = 1.e-8;
1470 // |r,s| > LcoordDIV stop the search
1471 const NekDouble LcoordDiv = 15.0;
1472
1474 Array<OneD, const NekDouble> Jac =
1475 m_geom->GenGeomFactors(ptsKeys)->GetJac();
1476
1477 NekDouble ScaledTol =
1478 Vmath::Vsum(Jac.size(), Jac, 1) / ((NekDouble)Jac.size());
1479 ScaledTol *= Tol;
1480
1481 NekDouble xmap, ymap, zmap, F1, F2, F3;
1482
1483 NekDouble derx_1, derx_2, derx_3, dery_1, dery_2, dery_3, derz_1, derz_2,
1484 derz_3, jac;
1485
1486 // save intiial guess for later reference if required.
1487 NekDouble init0 = Lcoords[0], init1 = Lcoords[1], init2 = Lcoords[2];
1488
1489 Array<OneD, NekDouble> DxD1(ptsx.size());
1490 Array<OneD, NekDouble> DxD2(ptsx.size());
1491 Array<OneD, NekDouble> DxD3(ptsx.size());
1492 Array<OneD, NekDouble> DyD1(ptsx.size());
1493 Array<OneD, NekDouble> DyD2(ptsx.size());
1494 Array<OneD, NekDouble> DyD3(ptsx.size());
1495 Array<OneD, NekDouble> DzD1(ptsx.size());
1496 Array<OneD, NekDouble> DzD2(ptsx.size());
1497 Array<OneD, NekDouble> DzD3(ptsx.size());
1498
1499 // Ideally this will be stored in m_geomfactors
1500 m_geom->GetXmap()->PhysDeriv(ptsx, DxD1, DxD2, DxD3);
1501 m_geom->GetXmap()->PhysDeriv(ptsy, DyD1, DyD2, DyD3);
1502 m_geom->GetXmap()->PhysDeriv(ptsz, DzD1, DzD2, DzD3);
1503
1504 int cnt = 0;
1505 Array<OneD, DNekMatSharedPtr> I(3);
1506 Array<OneD, NekDouble> eta(3);
1507
1508 F1 = F2 = F3 = 2000; // Starting value of Function
1509 NekDouble resid = sqrt(F1 * F1 + F2 * F2 + F3 * F3);
1510 m_newtonConverged = false;
1511 while (cnt++ < MaxIterations)
1512 {
1513 // evaluate lagrange interpolant at Lcoords
1514 m_geom->GetXmap()->LocCoordToLocCollapsed(Lcoords, eta);
1515 I[0] = m_geom->GetXmap()->GetBasis(0)->GetI(eta);
1516 I[1] = m_geom->GetXmap()->GetBasis(1)->GetI(eta + 1);
1517 I[2] = m_geom->GetXmap()->GetBasis(2)->GetI(eta + 2);
1518
1519 // calculate the global point `corresponding to Lcoords
1520 xmap = m_geom->GetXmap()->PhysEvaluate(I, ptsx);
1521 ymap = m_geom->GetXmap()->PhysEvaluate(I, ptsy);
1522 zmap = m_geom->GetXmap()->PhysEvaluate(I, ptsz);
1523
1524 F1 = coords[0] - xmap;
1525 F2 = coords[1] - ymap;
1526 F3 = coords[2] - zmap;
1527
1528 if (F1 * F1 + F2 * F2 + F3 * F3 < ScaledTol)
1529 {
1530 resid = sqrt(F1 * F1 + F2 * F2 + F3 * F3);
1531 m_newtonConverged = true;
1532 break;
1533 }
1534
1535 // Interpolate derivative metric at Lcoords
1536 derx_1 = m_geom->GetXmap()->PhysEvaluate(I, DxD1);
1537 derx_2 = m_geom->GetXmap()->PhysEvaluate(I, DxD2);
1538 derx_3 = m_geom->GetXmap()->PhysEvaluate(I, DxD3);
1539 dery_1 = m_geom->GetXmap()->PhysEvaluate(I, DyD1);
1540 dery_2 = m_geom->GetXmap()->PhysEvaluate(I, DyD2);
1541 dery_3 = m_geom->GetXmap()->PhysEvaluate(I, DyD3);
1542 derz_1 = m_geom->GetXmap()->PhysEvaluate(I, DzD1);
1543 derz_2 = m_geom->GetXmap()->PhysEvaluate(I, DzD2);
1544 derz_3 = m_geom->GetXmap()->PhysEvaluate(I, DzD3);
1545
1546 jac = derx_1 * (dery_2 * derz_3 - dery_3 * derz_2) -
1547 derx_2 * (dery_1 * derz_3 - dery_3 * derz_1) +
1548 derx_3 * (dery_1 * derz_2 - dery_2 * derz_1);
1549
1550 // use analytical inverse of derivitives which are also similar to
1551 // those of metric factors.
1552 Lcoords[0] =
1553 Lcoords[0] +
1554 ((dery_2 * derz_3 - dery_3 * derz_2) * (coords[0] - xmap) -
1555 (derx_2 * derz_3 - derx_3 * derz_2) * (coords[1] - ymap) +
1556 (derx_2 * dery_3 - derx_3 * dery_2) * (coords[2] - zmap)) /
1557 jac;
1558
1559 Lcoords[1] =
1560 Lcoords[1] -
1561 ((dery_1 * derz_3 - dery_3 * derz_1) * (coords[0] - xmap) -
1562 (derx_1 * derz_3 - derx_3 * derz_1) * (coords[1] - ymap) +
1563 (derx_1 * dery_3 - derx_3 * dery_1) * (coords[2] - zmap)) /
1564 jac;
1565
1566 Lcoords[2] =
1567 Lcoords[2] +
1568 ((dery_1 * derz_2 - dery_2 * derz_1) * (coords[0] - xmap) -
1569 (derx_1 * derz_2 - derx_2 * derz_1) * (coords[1] - ymap) +
1570 (derx_1 * dery_2 - derx_2 * dery_1) * (coords[2] - zmap)) /
1571 jac;
1572
1573 if (!(std::isfinite(Lcoords[0]) && std::isfinite(Lcoords[1]) &&
1574 std::isfinite(Lcoords[2])))
1575 {
1576 dist = 1e16;
1577 std::ostringstream ss;
1578 ss << "nan or inf found in NewtonIterationForLocCoord in element "
1579 << m_geom->GetGlobalID();
1580 WARNINGL1(false, ss.str());
1581 return;
1582 }
1583 if (fabs(Lcoords[0]) > LcoordDiv || fabs(Lcoords[1]) > LcoordDiv ||
1584 fabs(Lcoords[2]) > LcoordDiv)
1585 {
1586 break; // lcoords have diverged so stop iteration
1587 }
1588 }
1589
1590 m_geom->GetXmap()->LocCoordToLocCollapsed(Lcoords, eta);
1591 if (ClampLocCoords(eta, m_geom->GetShapeDim(), 0.))
1592 {
1593 I[0] = m_geom->GetXmap()->GetBasis(0)->GetI(eta);
1594 I[1] = m_geom->GetXmap()->GetBasis(1)->GetI(eta + 1);
1595 I[2] = m_geom->GetXmap()->GetBasis(2)->GetI(eta + 2);
1596 // calculate the global point corresponding to Lcoords
1597 xmap = m_geom->GetXmap()->PhysEvaluate(I, ptsx);
1598 ymap = m_geom->GetXmap()->PhysEvaluate(I, ptsy);
1599 zmap = m_geom->GetXmap()->PhysEvaluate(I, ptsz);
1600 F1 = coords[0] - xmap;
1601 F2 = coords[1] - ymap;
1602 F3 = coords[2] - zmap;
1603 dist = sqrt(F1 * F1 + F2 * F2 + F3 * F3);
1604 }
1605 else if (m_newtonConverged)
1606 {
1607 dist = 0.;
1608 }
1609 else
1610 {
1611 // Inside the element but not converged: Lcoords does not map to
1612 // coords, so report the residual rather than claiming a match
1613 I[0] = m_geom->GetXmap()->GetBasis(0)->GetI(eta);
1614 I[1] = m_geom->GetXmap()->GetBasis(1)->GetI(eta + 1);
1615 I[2] = m_geom->GetXmap()->GetBasis(2)->GetI(eta + 2);
1616 xmap = m_geom->GetXmap()->PhysEvaluate(I, ptsx);
1617 ymap = m_geom->GetXmap()->PhysEvaluate(I, ptsy);
1618 zmap = m_geom->GetXmap()->PhysEvaluate(I, ptsz);
1619 F1 = coords[0] - xmap;
1620 F2 = coords[1] - ymap;
1621 F3 = coords[2] - zmap;
1622 dist = std::sqrt(F1 * F1 + F2 * F2 + F3 * F3);
1623 resid = dist;
1624 }
1625
1626 if (cnt >= MaxIterations)
1627 {
1628 Array<OneD, NekDouble> collCoords(3);
1629 m_geom->GetXmap()->LocCoordToLocCollapsed(Lcoords, collCoords);
1630
1631 // if coordinate is inside element dump error!
1632 if ((collCoords[0] >= -1.0 && collCoords[0] <= 1.0) &&
1633 (collCoords[1] >= -1.0 && collCoords[1] <= 1.0) &&
1634 (collCoords[2] >= -1.0 && collCoords[2] <= 1.0))
1635 {
1636 std::ostringstream ss;
1637
1638 ss << "Reached MaxIterations (" << MaxIterations
1639 << ") in Newton iteration ";
1640 ss << "Init value (" << std::setprecision(4) << init0 << ","
1641 << init1 << "," << init2 << ") ";
1642 ss << "Fin value (" << Lcoords[0] << "," << Lcoords[1] << ","
1643 << Lcoords[2] << ") ";
1644 ss << "Resid = " << resid
1645 << " Tolerance = " << std::sqrt(ScaledTol);
1646
1647 WARNINGL1(cnt < MaxIterations, ss.str());
1648 }
1649 }
1650}
int GetShapeDim() const
Dimension of the shape itself, which may be less than GetCoordim().
Definition Geometry.h:557
static bool ClampLocCoords(Array< OneD, NekDouble > &locCoord, int dim, NekDouble tol=std::numeric_limits< NekDouble >::epsilon())
Clamp local coordinates into the reference element , returning whether anything was clamped....
const LibUtilities::BasisSharedPtr & GetBasis(int dir) const
This function gets the shared point to basis in the dir direction.
void LocCoordToLocCollapsed(const Array< OneD, const NekDouble > &xi, Array< OneD, NekDouble > &eta)
Convert local cartesian coordinate xi into local collapsed coordinates eta.
NekDouble PhysEvaluate(const Array< OneD, const NekDouble > &coords, const Array< OneD, const NekDouble > &physvals)
This function evaluates the expansion at a single (arbitrary) point of the domain.
void PhysDeriv(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &out_d0, Array< OneD, NekDouble > &out_d1=NullNekDouble1DArray, Array< OneD, NekDouble > &out_d2=NullNekDouble1DArray)
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT jac
static const unsigned int kNewtonIterations
scalarT< T > sqrt(scalarT< T > in)
Definition scalar.hpp:289

References Nektar::SpatialDomains::GeometryLocator::ClampLocCoords(), Nektar::SpatialDomains::Geometry::GenGeomFactors(), Nektar::StdRegions::StdExpansion::GetBasis(), Nektar::SpatialDomains::Geometry::GetGlobalID(), Nektar::StdRegions::StdExpansion::GetPointsKeys(), Nektar::SpatialDomains::Geometry::GetShapeDim(), Nektar::SpatialDomains::Geometry::GetXmap(), Nektar::NekConstants::kNewtonIterations, Nektar::StdRegions::StdExpansion::LocCoordToLocCollapsed(), Nektar::SpatialDomains::GeometryLocator::m_geom, Nektar::SpatialDomains::GeometryLocator::m_newtonConverged, Nektar::StdRegions::StdExpansion::PhysDeriv(), Nektar::StdRegions::StdExpansion::PhysEvaluate(), tinysimd::sqrt(), Vmath::Vsum(), and WARNINGL1.

◆ v_CalculateInverseIsoParam()

void Nektar::SpatialDomains::GeometryLocator3D::v_CalculateInverseIsoParam ( )
overrideprotectedvirtual

Nothing to do by default. Build() drives this for every shape, but only the 2D and 3D inverse maps are expressed through an inverted coefficient matrix; a segment inverts \(\chi\) in closed form straight from its quadrature points.

See also
Geometry1D::v_GetLocCoords

Nothing to do by default. Build() drives this for every shape, but only the 2D and 3D inverse maps are expressed through an inverted coefficient matrix; a segment inverts \(\chi\) in closed form straight from its quadrature points.

See also
Geometry1D::v_GetLocCoords

Reimplemented from Nektar::SpatialDomains::GeometryLocator.

Definition at line 1724 of file GeometryLocator.cpp.

1725{
1726 DNekMatSharedPtr mat =
1728 for (int i = 0; i < 3; ++i)
1729 {
1730 for (int j = 0; j < 3; ++j)
1731 {
1732
1733 mat->SetValue(i, j, m_iso.m_coeff[i][j + 1]);
1734 }
1735 }
1736 mat->Invert();
1737 for (int i = 0; i < 3; ++i)
1738 {
1739 for (int j = 0; j < 3; ++j)
1740 {
1741 m_invIsoParam[i][j] = mat->GetValue(i, j);
1742 }
1743 }
1744}
std::array< std::array< NekDouble, kMaxGeomDim >, kMaxGeomDim > m_invIsoParam
Inverse of the linear part of m_iso, for regular elements.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::eFULL, Nektar::SpatialDomains::IsoParam::m_coeff, Nektar::SpatialDomains::GeometryLocator::m_invIsoParam, and Nektar::SpatialDomains::GeometryLocator::m_iso.

◆ v_GetLocCoords()

NekDouble Nektar::SpatialDomains::GeometryLocator3D::v_GetLocCoords ( const Array< OneD, const NekDouble > &  coords,
Array< OneD, NekDouble > &  Lcoords 
)
overrideprotectedvirtual

Reimplemented from Nektar::SpatialDomains::GeometryLocator.

Definition at line 1652 of file GeometryLocator.cpp.

1654{
1655 NekDouble dist = std::numeric_limits<double>::max();
1656 Array<OneD, NekDouble> tmpcoords(3);
1657 tmpcoords[0] = coords[0];
1658 tmpcoords[1] = coords[1];
1659 tmpcoords[2] = coords[2];
1660 if (m_geom->CalcGeomType() == eRegular)
1661 {
1662 tmpcoords[0] -= m_iso.m_coeff[0][0];
1663 tmpcoords[1] -= m_iso.m_coeff[1][0];
1664 tmpcoords[2] -= m_iso.m_coeff[2][0];
1665 Lcoords[0] = m_invIsoParam[0][0] * tmpcoords[0] +
1666 m_invIsoParam[0][1] * tmpcoords[1] +
1667 m_invIsoParam[0][2] * tmpcoords[2];
1668 Lcoords[1] = m_invIsoParam[1][0] * tmpcoords[0] +
1669 m_invIsoParam[1][1] * tmpcoords[1] +
1670 m_invIsoParam[1][2] * tmpcoords[2];
1671 Lcoords[2] = m_invIsoParam[2][0] * tmpcoords[0] +
1672 m_invIsoParam[2][1] * tmpcoords[1] +
1673 m_invIsoParam[2][2] * tmpcoords[2];
1674 }
1675 else if (m_straightEdge && m_iso.m_nCoeff > 0)
1676 {
1677 // Straight-sided, and the shape has a polynomial form of its mapping
1678 // to iterate on. A pyramid with a non-parallelogram base has not.
1679 ClampLocCoords(Lcoords, m_geom->GetShapeDim(), 0.);
1680 NewtonIterationForLocCoord(tmpcoords, Lcoords, dist);
1681 }
1682 else
1683 {
1684 m_geom->FillGeom();
1685 // Determine nearest point of coords to values in m_geom->GetXmap()
1686 int npts = m_geom->GetXmap()->GetTotPoints();
1687 Array<OneD, NekDouble> ptsx(npts), ptsy(npts), ptsz(npts);
1688 Array<OneD, NekDouble> tmp1(npts), tmp2(npts);
1689
1690 m_geom->GetXmap()->BwdTrans(m_geom->GetCoeffs(0), ptsx);
1691 m_geom->GetXmap()->BwdTrans(m_geom->GetCoeffs(1), ptsy);
1692 m_geom->GetXmap()->BwdTrans(m_geom->GetCoeffs(2), ptsz);
1693
1694 const Array<OneD, const NekDouble> za = m_geom->GetXmap()->GetPoints(0);
1695 const Array<OneD, const NekDouble> zb = m_geom->GetXmap()->GetPoints(1);
1696 const Array<OneD, const NekDouble> zc = m_geom->GetXmap()->GetPoints(2);
1697
1698 // guess the first local coords based on nearest point
1699 Vmath::Sadd(npts, -coords[0], ptsx, 1, tmp1, 1);
1700 Vmath::Vmul(npts, tmp1, 1, tmp1, 1, tmp1, 1);
1701 Vmath::Sadd(npts, -coords[1], ptsy, 1, tmp2, 1);
1702 Vmath::Vvtvp(npts, tmp2, 1, tmp2, 1, tmp1, 1, tmp1, 1);
1703 Vmath::Sadd(npts, -coords[2], ptsz, 1, tmp2, 1);
1704 Vmath::Vvtvp(npts, tmp2, 1, tmp2, 1, tmp1, 1, tmp1, 1);
1705
1706 int min_i = Vmath::Imin(npts, tmp1, 1);
1707
1708 // Get Local coordinates
1709 int qa = za.size(), qb = zb.size();
1710
1711 Array<OneD, NekDouble> eta(3, 0.);
1712 eta[2] = zc[min_i / (qa * qb)];
1713 min_i = min_i % (qa * qb);
1714 eta[1] = zb[min_i / qa];
1715 eta[0] = za[min_i % qa];
1716 m_geom->GetXmap()->LocCollapsedToLocCoord(eta, Lcoords);
1717
1718 // Perform newton iteration to find local coordinates
1719 NewtonIterationForLocCoord(coords, ptsx, ptsy, ptsz, Lcoords, dist);
1720 }
1721 return dist;
1722}
GeomType CalcGeomType()
Classify whether this shape is regular or deformed.
Definition Geometry.cpp:151
void FillGeom()
Gather the coefficients of from this object's boundary, unless that has already been done.
Definition Geometry.h:591
const Array< OneD, const NekDouble > & GetCoeffs(const int i)
The coefficients of in coordinate direction i, filling them first if that has not happened yet.
Definition Geometry.h:576
void NewtonIterationForLocCoord(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords, NekDouble &dist)
int m_straightEdge
Non-zero if every basis is linear. Bits 1 and 2 are used by the 2D straight-edged solve to record wh...
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
const Array< OneD, const NekDouble > & GetPoints(const int dir) const
This function returns a pointer to the array containing the quadrature points in dir direction.
void BwdTrans(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray)
This function performs the Backward transformation from coefficient space to physical space.
void LocCollapsedToLocCoord(const Array< OneD, const NekDouble > &eta, Array< OneD, NekDouble > &xi)
Convert local collapsed coordinates eta into local cartesian coordinate xi.
@ eRegular
Geometry is straight-sided with constant geometric factors.
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.
Definition Vmath.hpp:74
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
Definition Vmath.hpp:368
int Imin(int n, const T *x, const int incx)
Return the index of the minimum element in x.
Definition Vmath.hpp:707
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
Definition Vmath.hpp:196

References Nektar::StdRegions::StdExpansion::BwdTrans(), Nektar::SpatialDomains::Geometry::CalcGeomType(), Nektar::SpatialDomains::GeometryLocator::ClampLocCoords(), Nektar::SpatialDomains::eRegular, Nektar::SpatialDomains::Geometry::FillGeom(), Nektar::SpatialDomains::Geometry::GetCoeffs(), Nektar::StdRegions::StdExpansion::GetPoints(), Nektar::SpatialDomains::Geometry::GetShapeDim(), Nektar::StdRegions::StdExpansion::GetTotPoints(), Nektar::SpatialDomains::Geometry::GetXmap(), Vmath::Imin(), Nektar::StdRegions::StdExpansion::LocCollapsedToLocCoord(), Nektar::SpatialDomains::IsoParam::m_coeff, Nektar::SpatialDomains::GeometryLocator::m_geom, Nektar::SpatialDomains::GeometryLocator::m_invIsoParam, Nektar::SpatialDomains::GeometryLocator::m_iso, Nektar::SpatialDomains::IsoParam::m_nCoeff, Nektar::SpatialDomains::GeometryLocator::m_straightEdge, NewtonIterationForLocCoord(), Vmath::Sadd(), Vmath::Vmul(), and Vmath::Vvtvp().