ENH: use vector::normalise and VectorSpace::normalised for clarity

This commit is contained in:
Mark Olesen
2018-08-10 15:18:29 +02:00
parent c1964d7807
commit 4d6f0498d6
75 changed files with 302 additions and 354 deletions

View File

@ -124,15 +124,11 @@ bool Foam::cellFeatures::isCellFeatureEdge
// Check the angle between them by comparing the face normals.
vector n0 = mesh_.faceAreas()[face0];
n0 /= mag(n0);
vector n1 = mesh_.faceAreas()[face1];
n1 /= mag(n1);
const vector n0 = normalised(mesh_.faceAreas()[face0]);
const vector n1 = normalised(mesh_.faceAreas()[face1]);
scalar cosAngle = n0 & n1;
const edge& e = mesh_.edges()[edgeI];
const face& f0 = mesh_.faces()[face0];
@ -167,10 +163,8 @@ bool Foam::cellFeatures::isCellFeatureEdge
{
return true;
}
else
{
return false;
}
return false;
}

View File

@ -250,14 +250,11 @@ Foam::volumeType Foam::treeDataFace::getVolumeType
vector pointNormal(Zero);
forAll(pFaces, i)
for (const label facei : pFaces)
{
if (isTreeFace_.test(pFaces[i]))
if (isTreeFace_.test(facei))
{
vector n = mesh_.faceAreas()[pFaces[i]];
n /= mag(n) + VSMALL;
pointNormal += n;
pointNormal += normalised(mesh_.faceAreas()[facei]);
}
}
@ -319,14 +316,11 @@ Foam::volumeType Foam::treeDataFace::getVolumeType
vector edgeNormal(Zero);
forAll(eFaces, i)
for (const label facei : eFaces)
{
if (isTreeFace_.test(eFaces[i]))
if (isTreeFace_.test(facei))
{
vector n = mesh_.faceAreas()[eFaces[i]];
n /= mag(n) + VSMALL;
edgeNormal += n;
edgeNormal += normalised(mesh_.faceAreas()[facei]);
}
}
@ -369,11 +363,8 @@ Foam::volumeType Foam::treeDataFace::getVolumeType
vector ePrev = points[f[f.rcIndex(fp)]] - fc;
vector eNext = points[f[f.fcIndex(fp)]] - fc;
vector nLeft = ePrev ^ e;
nLeft /= mag(nLeft) + VSMALL;
vector nRight = e ^ eNext;
nRight /= mag(nRight) + VSMALL;
vector nLeft = normalised(ePrev ^ e);
vector nRight = normalised(e ^ eNext);
if (debug & 2)
{

View File

@ -310,11 +310,8 @@ Foam::volumeType Foam::treeDataPrimitivePatch<PatchType>::getVolumeType
vector ePrev = points[f[f.rcIndex(fp)]] - fc;
vector eNext = points[f[f.fcIndex(fp)]] - fc;
vector nLeft = ePrev ^ e;
nLeft /= mag(nLeft) + VSMALL;
vector nRight = e ^ eNext;
nRight /= mag(nRight) + VSMALL;
vector nLeft = normalised(ePrev ^ e);
vector nRight = normalised(e ^ eNext);
if (debug & 2)
{

View File

@ -810,8 +810,7 @@ Foam::List<Foam::pointIndexHit> Foam::meshSearch::intersections
{
DynamicList<pointIndexHit> hits;
vector edgeVec = pEnd - pStart;
edgeVec /= mag(edgeVec);
const vector edgeVec = normalised(pEnd - pStart);
point pt = pStart;

View File

@ -800,7 +800,7 @@ Foam::vector Foam::meshTools::edgeToCutDir
edgeI = meshTools::walkFace(mesh, facei, edgeI, vertI, 2);
}
avgVec /= mag(avgVec) + VSMALL;
avgVec.normalise();
return avgVec;
}

View File

@ -579,8 +579,7 @@ bool Foam::primitiveMeshGeometry::checkFaceSkewness
// Boundary faces: consider them to have only skewness error.
// (i.e. treat as if mirror cell on other side)
vector faceNormal = faceAreas[facei];
faceNormal /= mag(faceNormal) + VSMALL;
const vector faceNormal = normalised(faceAreas[facei]);
vector dOwn = faceCentres[facei] - cellCentres[own[facei]];
@ -767,8 +766,7 @@ bool Foam::primitiveMeshGeometry::checkFaceAngles
const face& f = fcs[facei];
vector faceNormal = faceAreas[facei];
faceNormal /= mag(faceNormal) + VSMALL;
const vector faceNormal = normalised(faceAreas[facei]);
// Get edge from f[0] to f[size-1];
vector ePrev(p[f.first()] - p[f.last()]);

View File

@ -107,15 +107,8 @@ void Foam::searchableCone::findNearestAndNormal
// Remove the parallel component and normalise
v -= parallel*unitDir_;
scalar magV = mag(v);
if (magV < ROOTVSMALL)
{
v = Zero;
}
else
{
v /= magV;
}
const scalar magV = mag(v);
v.normalise();
// Nearest and normal on disk at point1
point disk1Point(point1_ + min(max(magV, innerRadius1_), radius1_)*v);
@ -143,31 +136,30 @@ void Foam::searchableCone::findNearestAndNormal
p1 /= mag(p1);
// Find vector along the two end of cone
vector b(projPt2 - projPt1);
scalar magS = mag(b);
b /= magS;
const vector b = normalised(projPt2 - projPt1);
// Find the vector along sample pt and pt at one end of cone
vector a(sample - projPt1);
vector a = (sample - projPt1);
if (mag(a) <= ROOTVSMALL)
{
// Exception: sample on disk1. Redo with projPt2.
vector a(sample - projPt2);
a = (sample - projPt2);
// Find normal unitvector
nearCone = (a & b)*b+projPt2;
nearCone = (a & b)*b + projPt2;
vector b1 = (p1 & b)*b;
normalCone = p1 - b1;
normalCone /= mag(normalCone);
normalCone = normalised(p1 - b1);
}
else
{
// Find neartest point on cone surface
nearCone = (a & b)*b+projPt1;
// Find nearest point on cone surface
nearCone = (a & b)*b + projPt1;
// Find projection along surface of cone
vector b1 = (p1 & b)*b;
normalCone = p1 - b1;
normalCone /= mag(normalCone);
normalCone = normalised(p1 - b1);
}
if (innerRadius1_ > 0 || innerRadius2_ > 0)
@ -176,13 +168,10 @@ void Foam::searchableCone::findNearestAndNormal
point iCprojPt1 = point1_+ innerRadius1_*v;
point iCprojPt2 = point2_+ innerRadius2_*v;
vector iCp1 = (iCprojPt1 - point1_);
iCp1 /= mag(iCp1);
const vector iCp1 = normalised(iCprojPt1 - point1_);
// Find vector along the two end of cone
vector iCb(iCprojPt2 - iCprojPt1);
magS = mag(iCb);
iCb /= magS;
const vector iCb = normalised(iCprojPt2 - iCprojPt1);
// Find the vector along sample pt and pt at one end of conde
@ -190,22 +179,22 @@ void Foam::searchableCone::findNearestAndNormal
if (mag(iCa) <= ROOTVSMALL)
{
vector iCa(sample - iCprojPt2);
iCa = (sample - iCprojPt2);
// Find normal unitvector
iCnearCone = (iCa & iCb)*iCb+iCprojPt2;
vector b1 = (iCp1 & iCb)*iCb;
iCnormalCone = iCp1 - b1;
iCnormalCone /= mag(iCnormalCone);
iCnormalCone = normalised(iCp1 - b1);
}
else
{
// Find nearest point on cone surface
iCnearCone = (iCa & iCb)*iCb+iCprojPt1;
// Find projection along surface of cone
vector b1 = (iCp1 & iCb)*iCb;
iCnormalCone = iCp1 - b1;
iCnormalCone /= mag(iCnormalCone);
iCnormalCone = normalised(iCp1 - b1);
}
}
}
@ -234,8 +223,9 @@ void Foam::searchableCone::findNearestAndNormal
scalar para = (v1 & unitDir_);
// Remove the parallel component and normalise
v1 -= para*unitDir_;
scalar magV1 = mag(v1);
const scalar magV1 = mag(v1);
v1 = v1/magV1;
if (para < 0.0 && magV1 >= radius1_)
{
// Near point 1. Set point to intersection of disk and cone.
@ -281,7 +271,8 @@ void Foam::searchableCone::findNearestAndNormal
scalar para = (v1 & unitDir_);
// Remove the parallel component and normalise
v1 -= para*unitDir_;
scalar magV1 = mag(v1);
const scalar magV1 = mag(v1);
v1 = v1/magV1;
if (para < 0.0 && magV1 >= innerRadius1_)
@ -382,7 +373,7 @@ void Foam::searchableCone::findLineAll
{
// Find dot product: mag(s)>VSMALL suggest that it is greater
scalar s = (V&unitDir_);
scalar s = (V & unitDir_);
if (mag(s) > VSMALL)
{
tPoint1 = -s1/s;
@ -471,8 +462,7 @@ void Foam::searchableCone::findLineAll
else
{
vector va = cone.unitDir_;
vector v1(end-start);
v1 = v1/mag(v1);
vector v1 = normalised(end-start);
scalar p = (va&v1);
vector a1 = (v1-p*va);

View File

@ -89,8 +89,8 @@ Foam::searchableExtrudedCircle::searchableExtrudedCircle
vector halfSpan(0.5*bounds().span());
point ctr(bounds().midpoint());
bounds().min() = ctr - mag(halfSpan)*vector(1, 1, 1);
bounds().max() = ctr + mag(halfSpan)*vector(1, 1, 1);
bounds().min() = ctr - mag(halfSpan) * vector::one;
bounds().max() = ctr + mag(halfSpan) * vector::one;
// Calculate bb of all points
treeBoundBox bb(bounds());
@ -182,8 +182,9 @@ void Foam::searchableExtrudedCircle::findNearest
if (info[i].hit())
{
vector d(samples[i]-info[i].hitPoint());
info[i].setPoint(info[i].hitPoint() + d/mag(d)*radius_);
const vector d = normalised(samples[i] - info[i].hitPoint());
info[i].setPoint(info[i].hitPoint() + d*radius_);
}
}
}
@ -360,7 +361,8 @@ void Foam::searchableExtrudedCircle::findParametricNearest
{
radialStart = start-curvePoints[0];
radialStart -= (radialStart&axialVecs[0])*axialVecs[0];
radialStart /= mag(radialStart);
radialStart.normalise();
qStart = quaternion(radialStart, 0.0);
info[0] = pointIndexHit(true, start, 0);
@ -370,11 +372,12 @@ void Foam::searchableExtrudedCircle::findParametricNearest
{
vector radialEnd(end-curvePoints.last());
radialEnd -= (radialEnd&axialVecs.last())*axialVecs.last();
radialEnd /= mag(radialEnd);
radialEnd.normalise();
vector projectedEnd = radialEnd;
projectedEnd -= (projectedEnd&axialVecs[0])*axialVecs[0];
projectedEnd /= mag(projectedEnd);
projectedEnd.normalise();
qProjectedEnd = quaternion(projectedEnd, 0.0);
info.last() = pointIndexHit(true, end, 0);
@ -385,8 +388,8 @@ void Foam::searchableExtrudedCircle::findParametricNearest
quaternion q(slerp(qStart, qProjectedEnd, lambdas[i]));
vector radialDir(q.transform(radialStart));
radialDir -= (radialDir&axialVecs[i])*axialVecs.last();
radialDir /= mag(radialDir);
radialDir -= (radialDir & axialVecs[i]) * axialVecs.last();
radialDir.normalise();
info[i] = pointIndexHit(true, curvePoints[i]+radius_*radialDir, 0);
}
@ -434,8 +437,8 @@ void Foam::searchableExtrudedCircle::getNormal
// Subtract axial direction
const vector axialVec = edges[curvePt.index()].unitVec(points);
normal[i] -= (normal[i]&axialVec)*axialVec;
normal[i] /= mag(normal[i]);
normal[i] -= (normal[i] & axialVec) * axialVec;
normal[i].normalise();
}
}
}

View File

@ -336,9 +336,7 @@ void Foam::searchableSphere::getNormal
{
if (info[i].hit())
{
normal[i] = info[i].hitPoint() - centre_;
normal[i] /= mag(normal[i])+VSMALL;
normal[i] = normalised(info[i].hitPoint() - centre_);
}
else
{

View File

@ -51,7 +51,7 @@ Foam::topoSetSource::addToUsageTable Foam::normalToFace::usage_
void Foam::normalToFace::setNormal()
{
normal_ /= mag(normal_) + VSMALL;
normal_.normalise();
Info<< " normalToFace : Normalized vector to " << normal_ << endl;
@ -116,8 +116,7 @@ void Foam::normalToFace::applyToSet
forAll(mesh_.faceAreas(), facei)
{
vector n = mesh_.faceAreas()[facei];
n /= mag(n) + VSMALL;
const vector n = normalised(mesh_.faceAreas()[facei]);
if (mag(1 - (n & normal_)) < tol_)
{
@ -136,8 +135,7 @@ void Foam::normalToFace::applyToSet
{
const label facei = iter.key();
vector n = mesh_.faceAreas()[facei];
n /= mag(n) + VSMALL;
const vector n = normalised(mesh_.faceAreas()[facei]);
if (mag(1 - (n & normal_)) < tol_)
{

View File

@ -433,11 +433,14 @@ Foam::label Foam::intersectedSurface::nextEdge
const edge& prevE = edges[prevEdgei];
// x-axis of coordinate system
vector e0 = n ^ (points[prevE.otherVertex(prevVerti)] - points[prevVerti]);
e0 /= mag(e0) + VSMALL;
const vector e0 =
normalised
(
n ^ (points[prevE.otherVertex(prevVerti)] - points[prevVerti])
);
// Get y-axis of coordinate system
vector e1 = n ^ e0;
// y-axis of coordinate system
const vector e1 = n ^ e0;
if (mag(mag(e1) - 1) > SMALL)
{
@ -489,10 +492,12 @@ Foam::label Foam::intersectedSurface::nextEdge
)
{
// Calculate angle of edge with respect to base e0, e1
vector vec =
n ^ (points[e.otherVertex(prevVerti)] - points[prevVerti]);
vec /= mag(vec) + VSMALL;
const vector vec =
normalised
(
n
^ (points[e.otherVertex(prevVerti)] - points[prevVerti])
);
scalar angle = pseudoAngle(e0, e1, vec);

View File

@ -118,8 +118,7 @@ void Foam::edgeIntersections::intersectEdges
const point& pStart = points1[meshPoints[e.start()]];
const point& pEnd = points1[meshPoints[e.end()]];
const vector eVec(pEnd - pStart);
const vector n(eVec/(mag(eVec) + VSMALL));
const vector n = normalised(pEnd - pStart);
// Start tracking somewhat before pStart and up to somewhat after p1.
// Note that tolerances here are smaller than those used to classify
@ -252,8 +251,7 @@ bool Foam::edgeIntersections::inlinePerturb
label v0 = surf1.meshPoints()[e[0]];
label v1 = surf1.meshPoints()[e[1]];
vector eVec(points1[v1] - points1[v0]);
vector n = eVec/mag(eVec);
const vector n = normalised(points1[v1] - points1[v0]);
if (perturbStart)
{
@ -326,9 +324,7 @@ bool Foam::edgeIntersections::rotatePerturb
n /= magN;
rndVec -= n*(n & rndVec);
// Normalize
rndVec /= mag(rndVec) + VSMALL;
rndVec.normalise();
// Scale to be moved by tolerance.
rndVec *= 0.01*magN;

View File

@ -410,8 +410,7 @@ void Foam::triSurfaceSearch::findLineAll
if (inter.hit())
{
vector lineVec = end[pointi] - start[pointi];
lineVec /= mag(lineVec) + VSMALL;
const vector lineVec = normalised(end[pointi] - start[pointi]);
if
(

View File

@ -107,8 +107,7 @@ Foam::pointToPointPlanarInterpolation::calcCoordinateSystem
<< exit(FatalError);
}
vector n = e1^(points[index2]-p0);
n /= mag(n);
const vector n = normalised(e1 ^ (points[index2]-p0));
if (debug)
{

View File

@ -315,11 +315,8 @@ Foam::scalar Foam::triSurfaceTools::faceCosAngle
const vector base0(pLeft - pStart);
const vector base1(pRight - pStart);
vector n0(common ^ base0);
n0 /= Foam::mag(n0);
vector n1(base1 ^ common);
n1 /= Foam::mag(n1);
const vector n0 = normalised(common ^ base0);
const vector n1 = normalised(base1 ^ common);
return n0 & n1;
}
@ -2068,11 +2065,11 @@ Foam::vector Foam::triSurfaceTools::surfaceNormal
vector edgeNormal(Zero);
forAll(eFaces, i)
for (const label facei : eFaces)
{
edgeNormal += surf.faceNormals()[eFaces[i]];
edgeNormal += surf.faceNormals()[facei];
}
return edgeNormal/(mag(edgeNormal) + VSMALL);
return normalised(edgeNormal);
}
else
{
@ -2626,14 +2623,13 @@ void Foam::triSurfaceTools::calcInterpolationWeights
edge[1] = tri.a()-tri.c();
edge[2] = tri.b()-tri.a();
vector triangleFaceNormal = edge[1] ^ edge[2];
const vector triangleFaceNormal = edge[1] ^ edge[2];
// calculate edge normal (pointing inwards)
FixedList<vector, 3> normal;
for (label i=0; i<3; i++)
{
normal[i] = triangleFaceNormal ^ edge[i];
normal[i] /= mag(normal[i]) + VSMALL;
normal[i] = normalised(triangleFaceNormal ^ edge[i]);
}
weights[0] = ((p-tri.b()) & normal[0]) / max(VSMALL, normal[0] & edge[1]);