Commit 4d6f0498 authored by Mark Olesen's avatar Mark Olesen
Browse files

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

parent c1964d78
......@@ -239,11 +239,9 @@ forAll(isNeiInterpolatedFace, faceI)
n1 = vector(-n.z(), 0, n.x());
}
}
n1.normalise();
n1 /= mag(n1);
vector n2 = n ^ n1;
n2 /= mag(n2);
const vector n2 = normalised(n ^ n1);
tensor rot =
tensor
......
......@@ -165,8 +165,7 @@ void Foam::radiation::laserDTRM::initialise()
const scalar t = mesh_.time().value();
const vector lPosition = focalLaserPosition_->value(t);
vector lDir = laserDirection_->value(t);
lDir /= mag(lDir);
const vector lDir = normalised(laserDirection_->value(t));
if (debug)
{
......@@ -175,7 +174,7 @@ void Foam::radiation::laserDTRM::initialise()
}
// Find a vector on the area plane. Normal to laser direction
vector rArea = vector::zero;
vector rArea = Zero;
scalar magr = 0.0;
{
......@@ -188,7 +187,7 @@ void Foam::radiation::laserDTRM::initialise()
magr = mag(rArea);
}
}
rArea /= mag(rArea);
rArea.normalise();
scalar dr = focalLaserRadius_/ndr_;
scalar dTheta = mathematical::twoPi/ndTheta_;
......
......@@ -135,8 +135,11 @@ bool largerAngle
// Get cos between faceCentre and normal vector to determine in
// which quadrant angle is. (Is correct for unwarped faces only!)
// Correct for non-outwards pointing normal.
vector c1c0(mesh.faceCentres()[f1] - mesh.faceCentres()[f0]);
c1c0 /= mag(c1c0) + VSMALL;
const vector c1c0 =
normalised
(
mesh.faceCentres()[f1] - mesh.faceCentres()[f0]
);
scalar fcCosAngle = n0 & c1c0;
......@@ -327,8 +330,7 @@ bool splitCell
// halfway on fully regular meshes (since we want cuts
// to be snapped to vertices)
planeN += 0.01*halfNorm;
planeN /= mag(planeN);
planeN.normalise();
// Define plane through edge
plane cutPlane(mesh.points()[e.start()], planeN);
......@@ -409,11 +411,8 @@ void collectCuts
label f0, f1;
meshTools::getEdgeFaces(mesh, celli, edgeI, f0, f1);
vector n0 = faceAreas[f0];
n0 /= mag(n0);
vector n1 = faceAreas[f1];
n1 /= mag(n1);
const vector n0 = normalised(faceAreas[f0]);
const vector n1 = normalised(faceAreas[f1]);
if
(
......
......@@ -45,7 +45,7 @@ Foam::cellAspectRatioControl::cellAspectRatioControl
)
{
// Normalise the direction
aspectRatioDirection_ /= mag(aspectRatioDirection_) + SMALL;
aspectRatioDirection_.normalise();
Info<< nl
<< "Cell Aspect Ratio Control" << nl
......
......@@ -428,7 +428,7 @@ void Foam::searchableSurfaceControl::initialVertices
if (mag(normals[0]) < SMALL)
{
normals[0] = vector(1, 1, 1);
normals[0] = vector::one;
}
pointAlignment.reset(new triad(normals[0]));
......
......@@ -1137,7 +1137,7 @@ void Foam::conformalVoronoiMesh::move()
alignmentDirs[aA] = a + sign(dotProduct)*b;
alignmentDirs[aA] /= mag(alignmentDirs[aA]);
alignmentDirs[aA].normalise();
}
}
}
......
......@@ -220,8 +220,7 @@ void Foam::conformalVoronoiMesh::createEdgePointGroupByCirculating
// << endl;
// Calculate master point
vector masterPtVec(normalDir + nextNormalDir);
masterPtVec /= mag(masterPtVec) + SMALL;
const vector masterPtVec = normalised(normalDir + nextNormalDir);
if
(
......
......@@ -738,8 +738,11 @@ Foam::Field<bool> Foam::conformationSurfaces::wellInOutSide
surface.findNearest(sample, nearestDistSqr, info);
vector hitDir = info[0].rawPoint() - samplePts[i];
hitDir /= mag(hitDir) + SMALL;
const vector hitDir =
normalised
(
info[0].rawPoint() - samplePts[i]
);
pointIndexHit surfHit;
label hitSurface;
......
......@@ -558,7 +558,7 @@ void Foam::CV2D::newPoints()
alignmentDirs[aA] = a + sign(dotProduct)*b;
alignmentDirs[aA] /= mag(alignmentDirs[aA]);
alignmentDirs[aA].normalise();
}
}
}
......@@ -845,7 +845,7 @@ void Foam::CV2D::newPoints()
cd0 = vector2D(cd0.x() + cd0.y(), cd0.y() - cd0.x());
// Normalise the primary coordinate direction
cd0 /= mag(cd0);
cd0.normalise();
// Calculate the orthogonal coordinate direction
vector2D cd1(-cd0.y(), cd0.x());
......
......@@ -123,7 +123,7 @@ void Foam::CV2D::insertFeaturePoints()
vector2DField fpn = toPoint2D(feMesh.edgeNormals(edgeI));
vector2D cornerNormal = sum(fpn);
cornerNormal /= mag(cornerNormal);
cornerNormal.normalise();
if (debug)
{
......
......@@ -280,8 +280,8 @@ int main(int argc, char *argv[])
(
args.lookup("rotate")()
);
n1n2[0] /= mag(n1n2[0]);
n1n2[1] /= mag(n1n2[1]);
n1n2[0].normalise();
n1n2[1].normalise();
const tensor rotT = rotationTensor(n1n2[0], n1n2[1]);
......
......@@ -74,6 +74,6 @@ if (mag(yT) < SMALL)
}
//swirlAxis doesn't have to be of unit length.
xT /= mag(xT);
yT /= mag(yT);
zT /= mag(zT);
xT.normalise();
yT.normalise();
zT.normalise();
......@@ -317,11 +317,9 @@ label calcNormalDirection
const vector& pointOnEdge
)
{
vector cross = (normal ^ edgeDir);
cross /= mag(cross);
const vector cross = normalised(normal ^ edgeDir);
vector fC0tofE0 = faceCentre - pointOnEdge;
fC0tofE0 /= mag(fC0tofE0);
const vector fC0tofE0 = normalised(faceCentre - pointOnEdge);
label nDir = ((cross & fC0tofE0) > 0.0 ? 1 : -1);
......
......@@ -189,7 +189,7 @@ tmp<vectorField> calcPointNormals
{
if (nNormals[pointI] > 0)
{
pointNormals[pointI] /= mag(pointNormals[pointI]);
pointNormals[pointI].normalise();
}
}
}
......
......@@ -565,16 +565,24 @@ void calcPointVecs
if (face0I != -1)
{
label v0 = triSurfaceTools::oppositeVertex(surf, face0I, edgeI);
vector e0 = (points[v0] - points[e.start()]) ^ eVec;
e0 /= mag(e0);
const vector e0 =
normalised
(
(points[v0] - points[e.start()]) ^ eVec
);
midVec = e0;
}
if (face1I != -1)
{
label v1 = triSurfaceTools::oppositeVertex(surf, face1I, edgeI);
vector e1 = (points[e.start()] - points[v1]) ^ eVec;
e1 /= mag(e1);
const vector e1 =
normalised
(
(points[e.start()] - points[v1]) ^ eVec
);
midVec += e1;
}
......@@ -895,8 +903,7 @@ int main(int argc, char *argv[])
{
scalar minLen = minEdgeLen(surf, pointi);
vector n = borderPointVec[pointi];
n /= mag(n);
const vector n = normalised(borderPointVec[pointi]);
newPoints[newPointi] = newPoints[pointi] + 0.1 * minLen * n;
}
......
......@@ -175,8 +175,8 @@ int main(int argc, char *argv[])
(
args.lookup("rotate")()
);
n1n2[0] /= mag(n1n2[0]);
n1n2[1] /= mag(n1n2[1]);
n1n2[0].normalise();
n1n2[1].normalise();
const tensor rotT = rotationTensor(n1n2[0], n1n2[1]);
......
......@@ -94,7 +94,7 @@ void Foam::polyMesh::calcDirections() const
{
reduce(emptyDirVec, sumOp<vector>());
emptyDirVec /= mag(emptyDirVec);
emptyDirVec.normalise();
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
{
......@@ -118,7 +118,7 @@ void Foam::polyMesh::calcDirections() const
{
reduce(wedgeDirVec, sumOp<vector>());
wedgeDirVec /= mag(wedgeDirVec);
wedgeDirVec.normalise();
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
{
......
......@@ -308,10 +308,17 @@ void Foam::oldCyclicPolyPatch::getCentresAndAnchors
label face0 = getConsistentRotationFace(half0Ctrs);
label face1 = getConsistentRotationFace(half1Ctrs);
vector n0 = ((half0Ctrs[face0] - rotationCentre_) ^ rotationAxis_);
vector n1 = ((half1Ctrs[face1] - rotationCentre_) ^ -rotationAxis_);
n0 /= mag(n0) + VSMALL;
n1 /= mag(n1) + VSMALL;
const vector n0 =
normalised
(
(half0Ctrs[face0] - rotationCentre_) ^ rotationAxis_
);
const vector n1 =
normalised
(
(half1Ctrs[face1] - rotationCentre_) ^ -rotationAxis_
);
if (debug)
{
......
......@@ -86,7 +86,7 @@ void Foam::wedgePolyPatch::calcGeometry(PstreamBuffers&)
sign(n_.y())*(max(mag(n_.y()), 0.5) - 0.5),
sign(n_.z())*(max(mag(n_.z()), 0.5) - 0.5)
);
centreNormal_ /= mag(centreNormal_);
centreNormal_.normalise();
cosAngle_ = centreNormal_ & n_;
......
......@@ -76,8 +76,11 @@ Foam::PatchTools::sortedEdgeFaces
{
if (f0[fpI] != e.start())
{
vector faceEdgeDir = localPoints[f0[fpI]] - edgePt;
faceEdgeDir /= mag(faceEdgeDir) + VSMALL;
const vector faceEdgeDir =
normalised
(
localPoints[f0[fpI]] - edgePt
);
const scalar angle = e2 & faceEdgeDir;
......@@ -91,11 +94,10 @@ Foam::PatchTools::sortedEdgeFaces
// Get vector normal both to e2 and to edge from opposite vertex
// to edge (will be x-axis of our coordinate system)
vector e0 = e2 ^ maxAngleEdgeDir;
e0 /= mag(e0) + VSMALL;
const vector e0 = normalised(e2 ^ maxAngleEdgeDir);
// Get y-axis of coordinate system
vector e1 = e2 ^ e0;
const vector e1 = e2 ^ e0;
SortableList<scalar> faceAngles(faceNbs.size());
......@@ -115,8 +117,11 @@ Foam::PatchTools::sortedEdgeFaces
{
if (f[fpI] != e.start())
{
vector faceEdgeDir = localPoints[f[fpI]] - edgePt;
faceEdgeDir /= mag(faceEdgeDir) + VSMALL;
const vector faceEdgeDir =
normalised
(
localPoints[f[fpI]] - edgePt
);
const scalar angle = e2 & faceEdgeDir;
......@@ -128,8 +133,7 @@ Foam::PatchTools::sortedEdgeFaces
}
}
vector vec = e2 ^ maxAngleEdgeDir;
vec /= mag(vec) + VSMALL;
const vector vec = normalised(e2 ^ maxAngleEdgeDir);
faceAngles[nbI] = pseudoAngle
(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment