ENH: vector mag(), magSqr() methods - complementary to dist(), distSqr()

ENH: use direct access to pointHit as point(), use dist(), distSqr()

- if the pointHit has already been checked for hit(), can/should
  simply use point() noexcept access subsequently to avoid redundant
  checks. Using vector distSqr() methods provides a minor optimization
  (no itermediate temporary), but can also make for clearer code.

ENH: copy construct pointIndexHit with different index

- symmetric with constructing from a pointHit with an index

STYLE: prefer pointHit point() instead of rawPoint()
This commit is contained in:
Mark Olesen
2022-11-01 12:15:08 +01:00
committed by Andrew Heather
parent 5ec435aca3
commit 27c2cdc040
112 changed files with 669 additions and 674 deletions

View File

@ -869,9 +869,7 @@ Foam::DistributedDelaunayMesh<Triangulation>::rangeInsertReferredWithInfo
if (!bb.contains(samplePoint))
{
const Foam::point nearestPoint = bb.nearest(samplePoint);
distFromBbSqr = magSqr(nearestPoint - samplePoint);
distFromBbSqr = bb.nearest(samplePoint).distSqr(samplePoint);
}
pointsBbDistSqr.append

View File

@ -1119,10 +1119,7 @@ Foam::labelList Foam::backgroundMeshDecomposition::processorNearestPosition
if (info.hit())
{
distanceSqrToCandidate[tPI] = magSqr
(
testPoints[tPI] - info.hitPoint()
);
distanceSqrToCandidate[tPI] = info.point().distSqr(testPoints[tPI]);
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -132,10 +132,7 @@ Foam::word Foam::cellShapeControlMesh::meshSubDir = "cellShapeControlMesh";
//
// if (spokeHit.hit())
// {
// scalar spokeHitDistance = mag
// (
// spokeHit.hitPoint() - pt
// );
// scalar spokeHitDistance = spokeHit.point().dist(pt);
//
// if (spokeHitDistance < closestSpokeHitDistance)
// {
@ -159,10 +156,7 @@ Foam::word Foam::cellShapeControlMesh::meshSubDir = "cellShapeControlMesh";
//
// if (spokeHit.hit())
// {
// scalar spokeHitDistance = mag
// (
// spokeHit.hitPoint() - mirrorPt
// );
// scalar spokeHitDistance = spokeHit.point().dist(mirrorPt);
//
// if (spokeHitDistance < closestSpokeHitDistance)
// {
@ -202,10 +196,10 @@ Foam::word Foam::cellShapeControlMesh::meshSubDir = "cellShapeControlMesh";
// FatalErrorInFunction
// << "Parallel normals detected in spoke search." << nl
// << "point: " << pt << nl
// << "closest surface point: " << surfHit.hitPoint() << nl
// << "closest spoke hit: " << closestSpokeHit.hitPoint() << nl
// << "np: " << surfHit.hitPoint() + np << nl
// << "ns: " << closestSpokeHit.hitPoint() + na << nl
// << "closest surface point: " << surfHit.point() << nl
// << "closest spoke hit: " << closestSpokeHit.point() << nl
// << "np: " << surfHit.point() + np << nl
// << "ns: " << closestSpokeHit.point() + na << nl
// << exit(FatalError);
// }
//

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -439,7 +439,7 @@ void Foam::searchableSurfaceControl::initialVertices
{
// Limit cell size
const vector vN =
infoList[0].hitPoint()
infoList[0].point()
- 2.0*normals[0]*defaultCellSize_;
List<pointIndexHit> intersectionList;
@ -453,8 +453,7 @@ void Foam::searchableSurfaceControl::initialVertices
// if (intersectionList[0].hit())
// {
// scalar dist =
// mag(intersectionList[0].hitPoint() - pts[pI]);
// scalar dist = intersectionList[0].point().dist(pts[pI]);
//
// limitedCellSize = dist/2.0;
// }

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2015 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -739,7 +740,7 @@ Foam::label Foam::controlMeshRefinement::refineMesh
if (hitPt.hit())
{
const Foam::point& pt = hitPt.hitPoint();
const Foam::point& pt = hitPt.point();
if (!geometryToConformTo_.inside(pt))
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -155,10 +155,10 @@ bool Foam::linearDistance::cellSize(const point& pt, scalar& size) const
if (hitInfo.hit())
{
const point& hitPt = hitInfo.hitPoint();
const point& hitPt = hitInfo.point();
const label hitIndex = hitInfo.index();
const scalar dist = mag(pt - hitPt);
const scalar dist = hitPt.dist(pt);
if (sideMode_ == rmBothsides)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -206,10 +206,10 @@ bool Foam::surfaceOffsetLinearDistance::cellSize
if (hitInfo.hit())
{
const point& hitPt = hitInfo.hitPoint();
const point& hitPt = hitInfo.point();
const label hitIndex = hitInfo.index();
const scalar dist = mag(pt - hitPt);
const scalar dist = hitPt.dist(pt);
if (sideMode_ == rmBothsides)
{
@ -220,7 +220,7 @@ bool Foam::surfaceOffsetLinearDistance::cellSize
// If the nearest point is essentially on the surface, do not do a
// getVolumeType calculation, as it will be prone to error.
if (mag(pt - hitInfo.hitPoint()) < snapToSurfaceTol_)
if (hitInfo.point().dist(pt) < snapToSurfaceTol_)
{
size = sizeFunction(hitPt, 0, hitIndex);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -97,7 +98,7 @@ bool uniform::cellSize
if (hitInfo.hit())
{
const point& hitPt = hitInfo.hitPoint();
const point& hitPt = hitInfo.point();
const label index = hitInfo.index();
if (sideMode_ == rmBothsides)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -134,7 +134,7 @@ bool Foam::uniformDistance::cellSize
if (hitInfo.hit())
{
const point& hitPt = hitInfo.hitPoint();
const point& hitPt = hitInfo.point();
const label index = hitInfo.index();
if (sideMode_ == rmBothsides)
@ -146,7 +146,7 @@ bool Foam::uniformDistance::cellSize
// If the nearest point is essentially on the surface, do not do a
// getVolumeType calculation, as it will be prone to error.
if (mag(pt - hitInfo.hitPoint()) < snapToSurfaceTol_)
if (hitInfo.point().dist(pt) < snapToSurfaceTol_)
{
size = surfaceCellSizeFunction_().interpolate(hitPt, index);

View File

@ -231,7 +231,7 @@ void Foam::conformalVoronoiMesh::insertSurfacePointPairs
const vector& normal = norm[0];
const Foam::point& surfacePt(surfaceHit.hitPoint());
const Foam::point& surfacePt = surfaceHit.hitPoint();
extendedFeatureEdgeMesh::sideVolumeType meshableSide =
geometryToConformTo_.meshableSide(featureIndex, surfaceHit);

View File

@ -488,7 +488,7 @@ Foam::label Foam::conformalVoronoiMesh::mergeIdenticalDualVertices
////
//// if (surfHit.hit())
//// {
//// pt += (surfHit.hitPoint() - pt)
//// pt += (surfHit.point() - pt)
//// *pow
//// (
//// foamyHexMeshControls()
@ -969,7 +969,7 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::findOffsetPatchFaces
if
(
pHit.hit()
&& (mag(pHit.hitPoint() - faceCentre) > allowedOffset*targetSize)
&& (pHit.point().dist(faceCentre) > allowedOffset*targetSize)
)
{
offsetBoundaryCells.insert(fCell[pLFI]);
@ -1362,10 +1362,10 @@ void Foam::conformalVoronoiMesh::indexDualVertices
if (debug)
{
Info<< "Dual = " << dual << nl
<< " Nearest = " << fpHit.hitPoint() << endl;
<< " Nearest = " << fpHit.point() << endl;
}
pts[cit->cellIndex()] = fpHit.hitPoint();
pts[cit->cellIndex()] = fpHit.point();
}
}
}
@ -1401,7 +1401,7 @@ void Foam::conformalVoronoiMesh::indexDualVertices
// );
//
// pointFromPoint nearestPointOnTet =
// tet.nearestPoint(dual).rawPoint();
// tet.nearestPoint(dual).point();
//
// // Get nearest point on surface from tet.
// geometryToConformTo_.findSurfaceNearest
@ -1440,10 +1440,10 @@ void Foam::conformalVoronoiMesh::indexDualVertices
// snapping2.writeLine
// (
// nearestPointOnTet,
// hitInfo.hitPoint()
// hitInfo.point()
// );
//
// pts[cit->cellIndex()] = hitInfo.hitPoint();
// pts[cit->cellIndex()] = hitInfo.point();
// }
// }
// }

View File

@ -311,7 +311,7 @@ void Foam::conformalVoronoiMesh::buildSurfaceConformation()
)
{
// meshTools::writeOBJ(Pout, vert);
// meshTools::writeOBJ(Pout, surfHit.hitPoint());
// meshTools::writeOBJ(Pout, surfHit.point());
// Pout<< "l cr0 cr1" << endl;
addSurfaceAndEdgeHits
@ -804,7 +804,7 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseEdgeTrees
if (nearest.hit())
{
// Pout<< "Not inserting " << peI << " " << pt << " "
// << nearest.rawPoint() << " on proc " << proci
// << nearest.point() << " on proc " << proci
// << ", near edge = " << nearest
// << " near ftPt = "<< info
// << " " << featureEdgeExclusionDistanceSqr(pt)
@ -1477,9 +1477,9 @@ void Foam::conformalVoronoiMesh::reportProcessorOccupancy()
// << vit->type() << nl
// << vit->ppMaster() << nl
// << "nearFeaturePt "
// << nearFeaturePt(surfHit.hitPoint()) << nl
// << nearFeaturePt(surfHit.point()) << nl
// << vert << nl
// << surfHit.hitPoint()
// << surfHit.point()
// << endl;
// }
// }
@ -1614,7 +1614,7 @@ void Foam::conformalVoronoiMesh::limitDisplacement
{
limit = true;
if (magSqr(pt - surfHit.hitPoint()) <= searchDistanceSqr)
if (surfHit.point().distSqr(pt) <= searchDistanceSqr)
{
// Cannot limit displacement, point closer than tolerance
displacement = Zero;
@ -1711,7 +1711,7 @@ bool Foam::conformalVoronoiMesh::nearSurfacePoint
(
closeToSurfacePt
&& (
magSqr(pt - closePoint.hitPoint())
closePoint.hitPoint().distSqr(pt)
> sqr(pointPairDistance(pt))
)
)
@ -2079,7 +2079,7 @@ void Foam::conformalVoronoiMesh::addSurfaceAndEdgeHits
if (edHit.hit())
{
const Foam::point& edPt = edHit.hitPoint();
const Foam::point& edPt = edHit.point();
if
(
@ -2095,7 +2095,7 @@ void Foam::conformalVoronoiMesh::addSurfaceAndEdgeHits
{
if
(
magSqr(edPt - surfPt)
surfPt.distSqr(edPt)
< surfacePtReplaceDistCoeffSqr*cellSizeSqr
)
{
@ -2141,7 +2141,7 @@ void Foam::conformalVoronoiMesh::addSurfaceAndEdgeHits
surfacePtToEdgePtDist.insert
(
existingEdgeLocations_.size() - 1,
magSqr(edPt - surfPt)
surfPt.distSqr(edPt)
);
}
else if (firstPass)
@ -2152,7 +2152,7 @@ void Foam::conformalVoronoiMesh::addSurfaceAndEdgeHits
if
(
magSqr(edPt - surfPt)
surfPt.distSqr(edPt)
< surfacePtToEdgePtDist[hitIndex]
)
{
@ -2162,7 +2162,7 @@ void Foam::conformalVoronoiMesh::addSurfaceAndEdgeHits
existingEdgeLocations_[hitIndex] =
edHit.hitPoint();
surfacePtToEdgePtDist[hitIndex] =
magSqr(edPt - surfPt);
surfPt.distSqr(edPt);
// Change edge location in featureEdgeHits
// remove index from edge tree

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -746,7 +746,7 @@ Foam::Field<bool> Foam::conformationSurfaces::wellInOutSide
const vector hitDir =
normalised
(
info[0].rawPoint() - samplePts[i]
info[0].point() - samplePts[i]
);
pointIndexHit surfHit;
@ -755,7 +755,7 @@ Foam::Field<bool> Foam::conformationSurfaces::wellInOutSide
findSurfaceNearestIntersection
(
samplePts[i],
info[0].rawPoint() - 1e-3*mag(hitDir)*hitDir,
info[0].point() - 1e-3*mag(hitDir)*hitDir,
surfHit,
hitSurface
);
@ -1057,7 +1057,7 @@ void Foam::conformationSurfaces::findFeaturePointNearest
if (hitInfo.hit())
{
minDistSqr = magSqr(hitInfo.hitPoint()- sample);
minDistSqr = hitInfo.point().distSqr(sample);
fpHit = hitInfo;
featureHit = testI;
}
@ -1123,11 +1123,9 @@ void Foam::conformationSurfaces::findEdgeNearest
{
if (hitInfo[pointi].hit())
{
minDistSqr[pointi] = magSqr
(
hitInfo[pointi].hitPoint()
- samples[pointi]
);
minDistSqr[pointi] =
hitInfo[pointi].point().distSqr(samples[pointi]);
edgeHits[pointi] = hitInfo[pointi];
featuresHit[pointi] = testI;
}
@ -1167,7 +1165,7 @@ void Foam::conformationSurfaces::findEdgeNearestByType
{
if (hitInfo[typeI].hit())
{
minDistSqr[typeI] = magSqr(hitInfo[typeI].hitPoint() - sample);
minDistSqr[typeI] = hitInfo[typeI].point().distSqr(sample);
edgeHits[typeI] = hitInfo[typeI];
featuresHit[typeI] = testI;
}
@ -1207,6 +1205,7 @@ void Foam::conformationSurfaces::findAllNearestEdges
if (hitInfo[hitI].hit())
{
anyHit = true;
break;
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2015 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -238,7 +238,7 @@ Foam::List<Vb::Point> Foam::rayShooting::initialPoints() const
if ((normStart[0] & normEnd[0]) < 0)
{
line<point, point> l(fC, surfHitEnd.hitPoint());
line<point, point> l(fC, surfHitEnd.point());
if (Pstream::parRun())
{
@ -256,7 +256,7 @@ Foam::List<Vb::Point> Foam::rayShooting::initialPoints() const
line<point, point>
(
l.start(),
procIntersection.hitPoint()
procIntersection.point()
);
}
}

View File

@ -353,7 +353,7 @@ tmp<scalarField> signedDistance
forAll(volType, i)
{
label pointi = surfIndices[i];
scalar dist = mag(points[pointi] - nearest[pointi].hitPoint());
scalar dist = points[pointi].dist(nearest[pointi].hitPoint());
volumeType vT = volType[i];

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2015 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -113,7 +113,7 @@ bool Foam::CV2D::insertPointPairAtIntersection
if (pHit.hit())
{
scalar dist2 =
magSqr(toPoint2D(pHit.hitPoint()) - vertices[vi]);
toPoint2D(pHit.point()).distSqr(vertices[vi]);
// Check the point is further away than the furthest so far
if (dist2 > interDist2)
@ -131,7 +131,7 @@ bool Foam::CV2D::insertPointPairAtIntersection
if (dist2 > mps2)
{
found = true;
interPoint = toPoint2D(pHit.hitPoint());
interPoint = toPoint2D(pHit.point());
interTri = pHit.index();
interDist2 = dist2;
interHitSurface = hitSurface;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2015 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -89,7 +90,7 @@ void Foam::CV2D::insertSurfaceNearPointPairs()
insertPointPair
(
meshControls().ppDist(),
toPoint2D(pHit.hitPoint()),
toPoint2D(pHit.point()),
toPoint2D(norm[0])
);