diff --git a/applications/solvers/incompressible/pimpleFoam/overPimpleDyMFoam/interpolatedFaces.H b/applications/solvers/incompressible/pimpleFoam/overPimpleDyMFoam/interpolatedFaces.H index 5a3386be77..00838f5fea 100644 --- a/applications/solvers/incompressible/pimpleFoam/overPimpleDyMFoam/interpolatedFaces.H +++ b/applications/solvers/incompressible/pimpleFoam/overPimpleDyMFoam/interpolatedFaces.H @@ -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 diff --git a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C index 3ba6e82b72..a60ba21ae8 100644 --- a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C +++ b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/laserDTRM.C @@ -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_; diff --git a/applications/utilities/mesh/advanced/splitCells/splitCells.C b/applications/utilities/mesh/advanced/splitCells/splitCells.C index 4d97d4e45e..ea6f01a8ef 100644 --- a/applications/utilities/mesh/advanced/splitCells/splitCells.C +++ b/applications/utilities/mesh/advanced/splitCells/splitCells.C @@ -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 ( diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellShapeControl/cellAspectRatioControl/cellAspectRatioControl.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellShapeControl/cellAspectRatioControl/cellAspectRatioControl.C index 191ddf53a9..0a0b973122 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellShapeControl/cellAspectRatioControl/cellAspectRatioControl.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellShapeControl/cellAspectRatioControl/cellAspectRatioControl.C @@ -45,7 +45,7 @@ Foam::cellAspectRatioControl::cellAspectRatioControl ) { // Normalise the direction - aspectRatioDirection_ /= mag(aspectRatioDirection_) + SMALL; + aspectRatioDirection_.normalise(); Info<< nl << "Cell Aspect Ratio Control" << nl diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellShapeControl/cellSizeAndAlignmentControl/searchableSurfaceControl/searchableSurfaceControl.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellShapeControl/cellSizeAndAlignmentControl/searchableSurfaceControl/searchableSurfaceControl.C index 25b8507bf5..6da2b5e6c0 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellShapeControl/cellSizeAndAlignmentControl/searchableSurfaceControl/searchableSurfaceControl.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellShapeControl/cellSizeAndAlignmentControl/searchableSurfaceControl/searchableSurfaceControl.C @@ -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])); diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C index f92686b321..edb36f528c 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C @@ -1137,7 +1137,7 @@ void Foam::conformalVoronoiMesh::move() alignmentDirs[aA] = a + sign(dotProduct)*b; - alignmentDirs[aA] /= mag(alignmentDirs[aA]); + alignmentDirs[aA].normalise(); } } } diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C index a4a4d0a8f0..9a653df699 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C @@ -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 ( diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C index 37db9dab40..bc71e6d0f1 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C @@ -738,8 +738,11 @@ Foam::Field 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; diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/CV2D.C b/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/CV2D.C index 278bc76f92..e0ce3b1ce0 100644 --- a/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/CV2D.C +++ b/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/CV2D.C @@ -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()); diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/insertFeaturePoints.C b/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/insertFeaturePoints.C index c746d95dc6..45a51ee384 100644 --- a/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/insertFeaturePoints.C +++ b/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/insertFeaturePoints.C @@ -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) { diff --git a/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C b/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C index a7132dae22..9356e6d1a9 100644 --- a/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C +++ b/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C @@ -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]); diff --git a/applications/utilities/preProcessing/engineSwirl/createFields.H b/applications/utilities/preProcessing/engineSwirl/createFields.H index a77933c8f7..bb8b2b0d23 100644 --- a/applications/utilities/preProcessing/engineSwirl/createFields.H +++ b/applications/utilities/preProcessing/engineSwirl/createFields.H @@ -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(); diff --git a/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C b/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C index 814cec9ce9..d0cdb3a944 100644 --- a/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C +++ b/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C @@ -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); diff --git a/applications/utilities/surface/surfaceInflate/surfaceInflate.C b/applications/utilities/surface/surfaceInflate/surfaceInflate.C index 3d5e9fd906..731d583065 100644 --- a/applications/utilities/surface/surfaceInflate/surfaceInflate.C +++ b/applications/utilities/surface/surfaceInflate/surfaceInflate.C @@ -189,7 +189,7 @@ tmp calcPointNormals { if (nNormals[pointI] > 0) { - pointNormals[pointI] /= mag(pointNormals[pointI]); + pointNormals[pointI].normalise(); } } } diff --git a/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C b/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C index 9d590fb9aa..1ea1c8a175 100644 --- a/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C +++ b/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C @@ -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; } diff --git a/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C b/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C index 10d389e857..51499c59ec 100644 --- a/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C +++ b/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C @@ -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]); diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index c25c9fb4a8..374b2a9355 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -94,7 +94,7 @@ void Foam::polyMesh::calcDirections() const { reduce(emptyDirVec, sumOp()); - emptyDirVec /= mag(emptyDirVec); + emptyDirVec.normalise(); for (direction cmpt=0; cmpt()); - wedgeDirVec /= mag(wedgeDirVec); + wedgeDirVec.normalise(); for (direction cmpt=0; cmpt 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 ( diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C index a513934b28..9a76270169 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C @@ -286,7 +286,7 @@ calcPointNormals() const curNormal += faceUnitNormals[facei]; } - curNormal /= mag(curNormal) + VSMALL; + curNormal.normalise(); } if (debug) diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C index 5c860a0c2c..3fb4b324da 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C @@ -78,8 +78,7 @@ Foam::scalar Foam::primitiveMeshTools::boundaryFaceSkewness { vector Cpf = fCtrs[facei] - ownCc; - vector normal = fAreas[facei]; - normal /= mag(normal) + ROOTVSMALL; + vector normal = normalised(fAreas[facei]); vector d = normal*(normal & Cpf); diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C index 9d8ad5de9c..d6c18d1cb8 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C @@ -389,8 +389,7 @@ Foam::tmp Foam::fvMeshDistribute::generateTestField const fvMesh& mesh ) { - vector testNormal(1, 1, 1); - testNormal /= mag(testNormal); + const vector testNormal = normalised(vector::one); tmp tfld ( @@ -440,8 +439,7 @@ void Foam::fvMeshDistribute::testField(const surfaceScalarField& fld) { const fvMesh& mesh = fld.mesh(); - vector testNormal(1, 1, 1); - testNormal /= mag(testNormal); + const vector testNormal = normalised(vector::one); const surfaceVectorField n(mesh.Sf()/mesh.magSf()); diff --git a/src/dynamicMesh/meshCut/cellLooper/geomCellLooper.C b/src/dynamicMesh/meshCut/cellLooper/geomCellLooper.C index 5528d9dad5..fbe7c6469f 100644 --- a/src/dynamicMesh/meshCut/cellLooper/geomCellLooper.C +++ b/src/dynamicMesh/meshCut/cellLooper/geomCellLooper.C @@ -159,9 +159,7 @@ void Foam::geomCellLooper::getBase(const vector& n, vector& e0, vector& e1) // Use component normal to n as base vector. - e0 = base - nComp*n; - - e0 /= mag(e0) + VSMALL; + e0 = normalised(base - nComp * n); e1 = n ^ e0; @@ -404,8 +402,7 @@ bool Foam::geomCellLooper::cut forAll(sortedAngles, i) { - vector toCtr(loopPoints[i] - ctr); - toCtr /= mag(toCtr); + const vector toCtr = normalised(loopPoints[i] - ctr); sortedAngles[i] = pseudoAngle(e0, e1, toCtr); } diff --git a/src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C b/src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C index b7637869d6..483960ca24 100644 --- a/src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C +++ b/src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C @@ -262,8 +262,7 @@ Foam::label Foam::topoCellLooper::getAlignedNonFeatureEdge vector e0 = mesh().points()[e.start()] - ctr; vector e1 = mesh().points()[e.end()] - ctr; - vector n = e0 ^ e1; - n /= mag(n); + const vector n = normalised(e0 ^ e1); scalar cosAngle = mag(refDir & n); diff --git a/src/dynamicMesh/meshCut/directions/directions.C b/src/dynamicMesh/meshCut/directions/directions.C index b525891344..68deece254 100644 --- a/src/dynamicMesh/meshCut/directions/directions.C +++ b/src/dynamicMesh/meshCut/directions/directions.C @@ -315,8 +315,7 @@ Foam::directions::directions vector tan2(globalDict.lookup("tan2")); check2D(correct2DPtr, tan2); - vector normal = tan1 ^ tan2; - normal /= mag(normal); + const vector normal = normalised(tan1 ^ tan2); Info<< "Global Coordinate system:" << endl << " normal : " << normal << endl diff --git a/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C b/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C index c5419bfc10..2a0b294eba 100644 --- a/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C +++ b/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C @@ -1498,8 +1498,7 @@ bool Foam::polyMeshGeometry::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()]); @@ -1692,20 +1691,30 @@ bool Foam::polyMeshGeometry::checkFaceTwist if (mesh.isInternalFace(facei)) { - nf = cellCentres[nei[facei]] - cellCentres[own[facei]]; - nf /= mag(nf) + VSMALL; + nf = + normalised + ( + cellCentres[nei[facei]] + - cellCentres[own[facei]] + ); } else if (patches[patches.whichPatch(facei)].coupled()) { nf = - neiCc[facei-mesh.nInternalFaces()] - - cellCentres[own[facei]]; - nf /= mag(nf) + VSMALL; + normalised + ( + neiCc[facei-mesh.nInternalFaces()] + - cellCentres[own[facei]] + ); } else { - nf = faceCentres[facei] - cellCentres[own[facei]]; - nf /= mag(nf) + VSMALL; + nf = + normalised + ( + faceCentres[facei] + - cellCentres[own[facei]] + ); } if (nf != vector::zero) diff --git a/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C b/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C index 79efcbc1be..be4b283afd 100644 --- a/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C +++ b/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C @@ -458,8 +458,11 @@ Foam::label Foam::faceCoupleInfo::mostAlignedCutEdge eVec /= magEVec; - vector eToEndPoint(localPoints[edgeEnd] - localPoints[otherPointi]); - eToEndPoint /= mag(eToEndPoint); + const vector eToEndPoint = + normalised + ( + localPoints[edgeEnd] - localPoints[otherPointi] + ); scalar cosAngle = eVec & eToEndPoint; diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C index 3e0e48fe3e..4cd0f0e0ae 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C @@ -213,11 +213,8 @@ Foam::label Foam::removePoints::countPointUsage label vLeft = e0.otherVertex(common); label vRight = e1.otherVertex(common); - vector e0Vec = points[common] - points[vLeft]; - e0Vec /= mag(e0Vec) + VSMALL; - - vector e1Vec = points[vRight] - points[common]; - e1Vec /= mag(e1Vec) + VSMALL; + const vector e0Vec = normalised(points[common] - points[vLeft]); + const vector e1Vec = normalised(points[vRight] - points[common]); if ((e0Vec & e1Vec) > minCos) { diff --git a/src/dynamicMesh/slidingInterface/enrichedPatch/enrichedPatchCutFaces.C b/src/dynamicMesh/slidingInterface/enrichedPatch/enrichedPatchCutFaces.C index 4887943021..2b6354aa8c 100644 --- a/src/dynamicMesh/slidingInterface/enrichedPatch/enrichedPatchCutFaces.C +++ b/src/dynamicMesh/slidingInterface/enrichedPatch/enrichedPatchCutFaces.C @@ -220,10 +220,9 @@ void Foam::enrichedPatch::calcCutFaces() const // Get the vector along the edge and the right vector vector ahead = curPoint - lp[prevPointLabel]; ahead -= normal*(normal & ahead); - ahead /= mag(ahead); + ahead.normalise(); - vector right = normal ^ ahead; - right /= mag(right); + const vector right = normalised(normal ^ ahead); // Pout<< "normal: " << normal // << " ahead: " << ahead diff --git a/src/dynamicMesh/slidingInterface/slidingInterfaceProjectPoints.C b/src/dynamicMesh/slidingInterface/slidingInterfaceProjectPoints.C index ca6d503b0d..cbcdb3a682 100644 --- a/src/dynamicMesh/slidingInterface/slidingInterfaceProjectPoints.C +++ b/src/dynamicMesh/slidingInterface/slidingInterfaceProjectPoints.C @@ -920,15 +920,16 @@ bool Foam::slidingInterface::projectPoints() const // projected-master-to-edge distance is used, to avoid // problems with badly defined master planes. HJ, // 17/Oct/2004 - vector edgeNormalInPlane = - edgeVec - ^ ( - slavePointNormals[curEdge.start()] - + slavePointNormals[curEdge.end()] + const vector edgeNormalInPlane = + normalised + ( + edgeVec + ^ ( + slavePointNormals[curEdge.start()] + + slavePointNormals[curEdge.end()] + ) ); - edgeNormalInPlane /= mag(edgeNormalInPlane); - for (const label cmp : curMasterPoints) { // Skip the current point if the edge start or end has diff --git a/src/finiteArea/faMesh/faMeshDemandDrivenData.C b/src/finiteArea/faMesh/faMeshDemandDrivenData.C index e9cc68d9cc..e4050c7610 100644 --- a/src/finiteArea/faMesh/faMeshDemandDrivenData.C +++ b/src/finiteArea/faMesh/faMeshDemandDrivenData.C @@ -1281,10 +1281,11 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit() const // Transform points const vector& origin = points[curPoint]; - vector axis(result[curPoint]/mag(result[curPoint])); + const vector axis = normalised(result[curPoint]); vector dir(allPoints[0] - points[curPoint]); dir -= axis*(axis&dir); - dir /= mag(dir); + dir.normalise(); + coordinateSystem cs("cs", origin, axis, dir); forAll(allPoints, pI) @@ -1563,10 +1564,11 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit() const // Transform points const vector& origin = points[curPoint]; - vector axis(result[curPoint]/mag(result[curPoint])); + const vector axis = normalised(result[curPoint]); vector dir(allPoints[0] - points[curPoint]); dir -= axis*(axis&dir); - dir /= mag(dir); + dir.normalise(); + const coordinateSystem cs("cs", origin, axis, dir); scalarField W(allPoints.size(), 1.0); @@ -1734,10 +1736,11 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit() const // Transform points const vector& origin = points[curPoint]; - vector axis(result[curPoint]/mag(result[curPoint])); + const vector axis = normalised(result[curPoint]); vector dir(allPoints[0] - points[curPoint]); dir -= axis*(axis&dir); - dir /= mag(dir); + dir.normalise(); + coordinateSystem cs("cs", origin, axis, dir); scalarField W(allPoints.size(), 1.0); diff --git a/src/finiteArea/interpolation/edgeInterpolation/edgeInterpolation.C b/src/finiteArea/interpolation/edgeInterpolation/edgeInterpolation.C index 47292d1377..692d6f79f9 100644 --- a/src/finiteArea/interpolation/edgeInterpolation/edgeInterpolation.C +++ b/src/finiteArea/interpolation/edgeInterpolation/edgeInterpolation.C @@ -404,19 +404,16 @@ void Foam::edgeInterpolation::makeDeltaCoeffs() const forAll(owner, edgeI) { // Edge normal - area normal - vector edgeNormal = lengths[edgeI]^edges[edgeI].vec(points); - edgeNormal /= mag(edgeNormal); - + vector edgeNormal = + normalised(lengths[edgeI] ^ edges[edgeI].vec(points)); // Unit delta vector vector unitDelta = faceCentres[neighbour[edgeI]] - faceCentres[owner[edgeI]]; - unitDelta -= - edgeNormal*(edgeNormal&unitDelta); - - unitDelta /= mag(unitDelta); + unitDelta -= edgeNormal*(edgeNormal & unitDelta); + unitDelta.normalise(); // Calc PN arc length @@ -447,7 +444,7 @@ void Foam::edgeInterpolation::makeDeltaCoeffs() const // Edge normal - area tangent - edgeNormal = lengths[edgeI]/mag(lengths[edgeI]); + edgeNormal = normalised(lengths[edgeI]); // Delta coefficient as per definition // dc[edgeI] = 1.0/(lPN*(unitDelta & edgeNormal)); @@ -496,7 +493,6 @@ void Foam::edgeInterpolation::makeCorrectionVectors() const const labelUList& neighbour = mesh().neighbour(); const edgeVectorField& lengths = mesh().Le(); - const edgeScalarField& magLengths = mesh().magLe(); const edgeList& edges = mesh().edges(); const pointField& points = mesh().points(); @@ -508,8 +504,8 @@ void Foam::edgeInterpolation::makeCorrectionVectors() const forAll(owner, edgeI) { // Edge normal - area normal - vector edgeNormal = lengths[edgeI] ^ edges[edgeI].vec(points); - edgeNormal /= mag(edgeNormal); + vector edgeNormal = + normalised(lengths[edgeI] ^ edges[edgeI].vec(points)); // Unit delta vector vector unitDelta = @@ -517,11 +513,10 @@ void Foam::edgeInterpolation::makeCorrectionVectors() const - faceCentres[owner[edgeI]]; unitDelta -= edgeNormal*(edgeNormal & unitDelta); - - unitDelta /= mag(unitDelta); + unitDelta.normalise(); // Edge normal - area tangent - edgeNormal = lengths[edgeI]/magLengths[edgeI]; + edgeNormal = normalised(lengths[edgeI]); // Delta coeffs deltaCoeffs[edgeI] = 1.0/(unitDelta & edgeNormal); diff --git a/src/finiteVolume/cfdTools/general/SRF/SRFModel/SRFModel/SRFModel.C b/src/finiteVolume/cfdTools/general/SRF/SRFModel/SRFModel/SRFModel.C index 9d7d2c2516..d8ef7244b5 100644 --- a/src/finiteVolume/cfdTools/general/SRF/SRFModel/SRFModel/SRFModel.C +++ b/src/finiteVolume/cfdTools/general/SRF/SRFModel/SRFModel/SRFModel.C @@ -59,14 +59,11 @@ Foam::SRF::SRFModel::SRFModel ), Urel_(Urel), mesh_(Urel_.mesh()), - origin_("origin", dimLength, lookup("origin")), - axis_(lookup("axis")), + origin_("origin", dimLength, get("origin")), + axis_(normalised(get("axis"))), SRFModelCoeffs_(optionalSubDict(type + "Coeffs")), omega_(dimensionedVector("omega", dimless/dimTime, Zero)) -{ - // Normalise the axis - axis_ /= mag(axis_); -} +{} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // @@ -82,21 +79,19 @@ bool Foam::SRF::SRFModel::read() if (regIOobject::read()) { // Re-read origin - lookup("origin") >> origin_; + readEntry("origin", origin_); // Re-read axis - lookup("axis") >> axis_; - axis_ /= mag(axis_); + readEntry("axis", axis_); + axis_.normalise(); // Re-read sub-model coeffs SRFModelCoeffs_ = optionalSubDict(type() + "Coeffs"); return true; } - else - { - return false; - } + + return false; } diff --git a/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutCell/isoCutCell.C b/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutCell/isoCutCell.C index 0b3179edd9..7bd47b8991 100644 --- a/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutCell/isoCutCell.C +++ b/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutCell/isoCutCell.C @@ -267,12 +267,11 @@ void Foam::isoCutCell::calcIsoFacePointsFromEdges() // Defining local coordinates with zhat along isoface normal and xhat from // isoface centre to first point in isoFaceEdges_ - const vector zhat = isoFaceArea_/mag(isoFaceArea_); + const vector zhat = normalised(isoFaceArea_); vector xhat = isoFaceEdges_[0][0] - isoFaceCentre_; xhat = (xhat - (xhat & zhat)*zhat); - xhat /= mag(xhat); - vector yhat = zhat^xhat; - yhat /= mag(yhat); + xhat.normalise(); + vector yhat = normalised(zhat ^ xhat); DebugPout << "Calculated local coordinates" << endl; diff --git a/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutFace/isoCutFace.C b/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutFace/isoCutFace.C index e0e335b55d..62a6ed602a 100644 --- a/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutFace/isoCutFace.C +++ b/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutFace/isoCutFace.C @@ -735,12 +735,12 @@ void Foam::isoCutFace::quadAreaCoeffs if (Bx > 10*SMALL) { // If |AB| > 0 ABCD we use AB to define xhat - xhat = (B - A)/mag(B - A); + xhat = normalised(B - A); } else if (mag(C - D) > 10*SMALL) { // If |AB| ~ 0 ABCD is a triangle ACD and we use CD for xhat - xhat = (C - D)/mag(C - D); + xhat = normalised(C - D); } else { diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/findCellPointFaceTet.H b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/findCellPointFaceTet.H index 07baf8e69e..11b6377918 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/findCellPointFaceTet.H +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/findCellPointFaceTet.H @@ -81,10 +81,11 @@ bool interpolationCellPointFace::findTet referencePoint = tetPoints[p1]; faceNormal = - (tetPoints[p3] - tetPoints[p1]) - ^ (tetPoints[p2] - tetPoints[p1]); - - faceNormal /= mag(faceNormal); + normalised + ( + (tetPoints[p3] - tetPoints[p1]) + ^ (tetPoints[p2] - tetPoints[p1]) + ); // correct normal to point into the tet vector v0 = tetPoints[n] - referencePoint; diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/findCellPointFaceTriangle.H b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/findCellPointFaceTriangle.H index e6b2fea84b..2c721d1556 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/findCellPointFaceTriangle.H +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/findCellPointFaceTriangle.H @@ -57,8 +57,7 @@ bool interpolationCellPointFace::findTriangle // calculate edge normal (pointing inwards) for (label i=0; i<3; i++) { - normal[i] = triangleFaceNormal ^ edge[i]; - normal[i] /= mag(normal[i]) + VSMALL; + normal[i] = normalised(triangleFaceNormal ^ edge[i]); } // check if position is inside triangle diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.C b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.C index d7b130a1ca..9b21816430 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.C @@ -88,12 +88,9 @@ Type Foam::interpolationCellPointFace::interpolate label closestFace = -1; scalar minDistance = GREAT; - forAll(cellFaces, facei) + for (const label nFace : cellFaces) { - label nFace = cellFaces[facei]; - - vector normal = this->pMeshFaceAreas_[nFace]; - normal /= mag(normal); + const vector normal = normalised(this->pMeshFaceAreas_[nFace]); const vector& faceCentreTmp = this->pMeshFaceCentres_[nFace]; diff --git a/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/pointMVCWeight.C b/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/pointMVCWeight.C index 064bf94aea..f9f98c5ba2 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/pointMVCWeight.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/pointMVCWeight.C @@ -156,10 +156,8 @@ void Foam::pointMVCWeight::calcWeights label jPlus1 = f.fcIndex(j); //Pout<< " uj:" << u[j] << " ujPlus1:" << u[jPlus1] << endl; - vector n0 = u[j]^v; - n0 /= mag(n0); - vector n1 = u[jPlus1]^v; - n1 /= mag(n1); + const vector n0 = normalised(u[j] ^ v); + const vector n1 = normalised(u[jPlus1] ^ v); scalar l = min(mag(n0 - n1), 2.0); //Pout<< " l:" << l << endl; diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/FitData/FitData.C b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/FitData/FitData.C index 6fe277786b..d157e4478c 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/FitData/FitData.C +++ b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/FitData/FitData.C @@ -76,8 +76,7 @@ void Foam::FitData::findFaceDirs { const fvMesh& mesh = this->mesh(); - idir = mesh.faceAreas()[facei]; - idir /= mag(idir); + idir = normalised(mesh.faceAreas()[facei]); #ifndef SPHERICAL_GEOMETRY if (mesh.nGeometricD() <= 2) // find the normal direction diff --git a/src/lagrangian/DSMC/parcels/Templates/DSMCParcel/DSMCParcel.C b/src/lagrangian/DSMC/parcels/Templates/DSMCParcel/DSMCParcel.C index cdc5ec680c..843dfb1a39 100644 --- a/src/lagrangian/DSMC/parcels/Templates/DSMCParcel/DSMCParcel.C +++ b/src/lagrangian/DSMC/parcels/Templates/DSMCParcel/DSMCParcel.C @@ -116,8 +116,7 @@ void Foam::DSMCParcel::hitWallPatch scalar m = constProps.mass(); - vector nw = wpp.faceAreas()[wppLocalFace]; - nw /= mag(nw); + const vector nw = normalised(wpp.faceAreas()[wppLocalFace]); scalar U_dot_nw = U_ & nw; diff --git a/src/lagrangian/DSMC/submodels/InflowBoundaryModel/FreeStream/FreeStream.C b/src/lagrangian/DSMC/submodels/InflowBoundaryModel/FreeStream/FreeStream.C index 154faee32b..4d6b0a184c 100644 --- a/src/lagrangian/DSMC/submodels/InflowBoundaryModel/FreeStream/FreeStream.C +++ b/src/lagrangian/DSMC/submodels/InflowBoundaryModel/FreeStream/FreeStream.C @@ -265,18 +265,15 @@ void Foam::FreeStream::inflow() // Normal unit vector *negative* so normal is pointing into the // domain - vector n = patch.faceAreas()[pFI]; - n /= -mag(n); + const vector n = -normalised(patch.faceAreas()[pFI]); // Wall tangential unit vector. Use the direction between the // face centre and the first vertex in the list - vector t1 = fC - (mesh.points()[f[0]]); - t1 /= mag(t1); + const vector t1 = normalised(fC - (mesh.points()[f[0]])); // Other tangential unit vector. Rescaling in case face is not // flat and n and t1 aren't perfectly orthogonal - vector t2 = n^t1; - t2 /= mag(t2); + const vector t2 = normalised(n ^ t1); scalar faceTemperature = boundaryT[patchi][pFI]; diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C index 0adce43d20..d8bca67835 100644 --- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C @@ -167,7 +167,7 @@ void Foam::ParticleCollector::initConcentricCircles() { refDir = this->coeffDict().lookup("refDir"); refDir -= normal_[0]*(normal_[0] & refDir); - refDir /= mag(refDir); + refDir.normalise(); } else { @@ -581,8 +581,7 @@ Foam::ParticleCollector::ParticleCollector forAll(polygons, polyI) { polygons[polyI] = polygonAndNormal[polyI].first(); - normal_[polyI] = polygonAndNormal[polyI].second(); - normal_[polyI] /= mag(normal_[polyI]) + ROOTVSMALL; + normal_[polyI] = normalised(polygonAndNormal[polyI].second()); } initPolygons(polygons); diff --git a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/ConeInjection/ConeInjection.C b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/ConeInjection/ConeInjection.C index db0296b914..1e203baca6 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/ConeInjection/ConeInjection.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/ConeInjection/ConeInjection.C @@ -104,8 +104,7 @@ Foam::ConeInjection::ConeInjection forAll(positionAxis_, i) { vector& axis = positionAxis_[i].second(); - - axis /= mag(axis); + axis.normalise(); vector tangent = Zero; scalar magTangent = 0.0; @@ -277,7 +276,7 @@ void Foam::ConeInjection::setProperties vector normal = alpha*(tanVec1_[i]*cos(beta) + tanVec2_[i]*sin(beta)); vector dirVec = dcorr*positionAxis_[i].second(); dirVec += normal; - dirVec /= mag(dirVec); + dirVec.normalise(); parcel.U() = Umag_.value(t)*dirVec; diff --git a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/ConeNozzleInjection/ConeNozzleInjection.C b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/ConeNozzleInjection/ConeNozzleInjection.C index 065bf81248..eba6578fcb 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/ConeNozzleInjection/ConeNozzleInjection.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/ConeNozzleInjection/ConeNozzleInjection.C @@ -206,7 +206,7 @@ Foam::ConeNozzleInjection::ConeNozzleInjection Random& rndGen = this->owner().rndGen(); // Normalise direction vector - direction_ /= mag(direction_); + direction_.normalise(); // Determine direction vectors tangential to direction vector tangent = Zero; @@ -436,7 +436,7 @@ void Foam::ConeNozzleInjection::setProperties vector normal = alpha*normal_; vector dirVec = dcorr*direction_; dirVec += normal; - dirVec /= mag(dirVec); + dirVec.normalise(); switch (flowType_) { diff --git a/src/lagrangian/molecularDynamics/molecule/molecule/moleculeI.H b/src/lagrangian/molecularDynamics/molecule/molecule/moleculeI.H index 947998d4c0..80b5045dfa 100644 --- a/src/lagrangian/molecularDynamics/molecule/molecule/moleculeI.H +++ b/src/lagrangian/molecularDynamics/molecule/molecule/moleculeI.H @@ -90,9 +90,11 @@ inline Foam::molecule::constantProperties::constantProperties Info<< nl << "Linear molecule." << endl; - vector dir = siteReferencePositions_[1] - siteReferencePositions_[0]; - - dir /= mag(dir); + const vector dir = + normalised + ( + siteReferencePositions_[1] - siteReferencePositions_[0] + ); tensor Q = rotationTensor(dir, vector(1,0,0)); @@ -334,9 +336,11 @@ inline bool Foam::molecule::constantProperties::linearMoleculeTest() const return true; } - vector refDir = siteReferencePositions_[1] - siteReferencePositions_[0]; - - refDir /= mag(refDir); + const vector refDir = + normalised + ( + siteReferencePositions_[1] - siteReferencePositions_[0] + ); for ( @@ -345,9 +349,11 @@ inline bool Foam::molecule::constantProperties::linearMoleculeTest() const i++ ) { - vector dir = siteReferencePositions_[i] - siteReferencePositions_[i-1]; - - dir /= mag(dir); + const vector dir = + normalised + ( + siteReferencePositions_[i] - siteReferencePositions_[i-1] + ); if (mag(refDir & dir) < 1 - SMALL) { diff --git a/src/lagrangian/spray/submodels/AtomizationModel/LISAAtomization/LISAAtomization.C b/src/lagrangian/spray/submodels/AtomizationModel/LISAAtomization/LISAAtomization.C index bc228d90fb..3a0be87711 100644 --- a/src/lagrangian/spray/submodels/AtomizationModel/LISAAtomization/LISAAtomization.C +++ b/src/lagrangian/spray/submodels/AtomizationModel/LISAAtomization/LISAAtomization.C @@ -43,7 +43,7 @@ Foam::LISAAtomization::LISAAtomization SMDCalcMethod_(this->coeffDict().lookup("SMDCalculationMethod")) { // Note: Would be good if this could be picked up from the injector - injectorDirection_ /= mag(injectorDirection_); + injectorDirection_.normalise(); if (SMDCalcMethod_ == "method1") { diff --git a/src/mesh/extrudeModel/linearDirection/linearDirection.C b/src/mesh/extrudeModel/linearDirection/linearDirection.C index 36a0094d2e..fba6823022 100644 --- a/src/mesh/extrudeModel/linearDirection/linearDirection.C +++ b/src/mesh/extrudeModel/linearDirection/linearDirection.C @@ -45,11 +45,9 @@ addToRunTimeSelectionTable(extrudeModel, linearDirection, dictionary); linearDirection::linearDirection(const dictionary& dict) : extrudeModel(typeName, dict), - direction_(coeffDict_.lookup("direction")), - thickness_(readScalar(coeffDict_.lookup("thickness"))) + direction_(coeffDict_.get("direction").normalise()), + thickness_(coeffDict_.get("thickness")) { - direction_ /= mag(direction_); - if (thickness_ <= 0) { FatalErrorInFunction diff --git a/src/mesh/snappyHexMesh/externalDisplacementMeshMover/fieldSmoother/fieldSmoother.C b/src/mesh/snappyHexMesh/externalDisplacementMeshMover/fieldSmoother/fieldSmoother.C index 9253faac3b..42560a2639 100644 --- a/src/mesh/snappyHexMesh/externalDisplacementMeshMover/fieldSmoother/fieldSmoother.C +++ b/src/mesh/snappyHexMesh/externalDisplacementMeshMover/fieldSmoother/fieldSmoother.C @@ -129,8 +129,7 @@ void Foam::fieldSmoother::smoothNormals { //full smoothing neighbours + point value average[pointI] = 0.5*(normals[pointI]+average[pointI]); - normals[pointI] = average[pointI]; - normals[pointI] /= mag(normals[pointI]) + VSMALL; + normals[pointI] = normalised(average[pointI]); } } } @@ -196,8 +195,7 @@ void Foam::fieldSmoother::smoothPatchNormals { // full smoothing neighbours + point value average[pointI] = 0.5*(normals[pointI]+average[pointI]); - normals[pointI] = average[pointI]; - normals[pointI] /= mag(normals[pointI]) + VSMALL; + normals[pointI] = normalised(average[pointI]); } } } diff --git a/src/mesh/snappyHexMesh/externalDisplacementMeshMover/medialAxisMeshMover.C b/src/mesh/snappyHexMesh/externalDisplacementMeshMover/medialAxisMeshMover.C index 094d83af79..40095d5233 100644 --- a/src/mesh/snappyHexMesh/externalDisplacementMeshMover/medialAxisMeshMover.C +++ b/src/mesh/snappyHexMesh/externalDisplacementMeshMover/medialAxisMeshMover.C @@ -1441,12 +1441,14 @@ void Foam::medialAxisMeshMover::calculateDisplacement //- Option 2: Look at component in the direction // of nearest (medial axis or static) point. - vector n = - patchDisp[patchPointI] - / (mag(patchDisp[patchPointI]) + VSMALL); - vector mVec = medialVec_[pointI]-mesh().points()[pointI]; - mVec /= mag(mVec)+VSMALL; - thicknessRatio *= (n&mVec); + const vector n = normalised(patchDisp[patchPointI]); + const vector mVec = + normalised + ( + medialVec_[pointI] - mesh().points()[pointI] + ); + + thicknessRatio *= (n & mVec); if (thicknessRatio > maxThicknessToMedialRatio) { diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C index d0da764d78..da0ea0bee7 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C @@ -172,8 +172,7 @@ void Foam::meshRefinement::calcNeighbourData forAll(faceCells, i) { // Extrapolate the face centre. - vector fn = faceAreas[i]; - fn /= mag(fn)+VSMALL; + const vector fn = normalised(faceAreas[i]); label own = faceCells[i]; label ownLevel = cellLevel[own]; @@ -2344,7 +2343,7 @@ Foam::autoPtr Foam::meshRefinement::splitMeshRegions label nRemove = findRegions ( mesh_, - mergeDistance_*vector(1,1,1), // perturbVec + mergeDistance_ * vector::one, // perturbVec locationsInMesh, locationsOutsideMesh, cellRegion.nRegions(), diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C index 30abfceaa1..5ca36811c7 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C @@ -1649,7 +1649,7 @@ void Foam::meshRefinement::findCellZoneInsideWalk ( mesh_, cellRegion, - mergeDistance_*vector(1,1,1), + mergeDistance_ * vector::one, insidePoint ); @@ -1916,7 +1916,7 @@ void Foam::meshRefinement::findCellZoneTopo ( mesh_, cellRegion, - mergeDistance_*vector(1,1,1), + mergeDistance_ * vector::one, keepPoint ); @@ -3875,7 +3875,7 @@ Foam::autoPtr Foam::meshRefinement::splitMesh findRegions ( mesh_, - mergeDistance_*vector(1,1,1), // perturbVec + mergeDistance_ * vector::one, // perturbVec locationsInMesh, locationsOutsideMesh, cellRegion.nRegions(), diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C index f229cfa391..8b147255b8 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C @@ -243,8 +243,7 @@ Foam::Map Foam::meshRefinement::findEdgeConnectedProblemCells { label facei = candidateFaces[i]; - vector n = mesh_.faceAreas()[facei]; - n /= mag(n); + const vector n = normalised(mesh_.faceAreas()[facei]); label region = surfaces_.globalRegion ( diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C index 8d2d28579b..a2e7969f90 100644 --- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C +++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C @@ -1101,9 +1101,7 @@ void Foam::snappySnapDriver::detectNearSurfaces //// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // //{ - // const scalar cos45 = Foam::cos(degToRad(45.0)); - // vector n(cos45, cos45, cos45); - // n /= mag(n); + // const vector n = normalised(vector::one); // // pointField start(14*pp.nPoints()); // pointField end(start.size()); diff --git a/src/meshTools/cellFeatures/cellFeatures.C b/src/meshTools/cellFeatures/cellFeatures.C index 0c509928be..3f68579b51 100644 --- a/src/meshTools/cellFeatures/cellFeatures.C +++ b/src/meshTools/cellFeatures/cellFeatures.C @@ -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; } diff --git a/src/meshTools/indexedOctree/treeDataFace.C b/src/meshTools/indexedOctree/treeDataFace.C index 2548717c69..7efb12332b 100644 --- a/src/meshTools/indexedOctree/treeDataFace.C +++ b/src/meshTools/indexedOctree/treeDataFace.C @@ -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) { diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C index 3b3a8bb2f3..3fde178bcf 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C @@ -310,11 +310,8 @@ Foam::volumeType Foam::treeDataPrimitivePatch::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) { diff --git a/src/meshTools/meshSearch/meshSearch.C b/src/meshTools/meshSearch/meshSearch.C index e49b2a7675..9a9c7a2fd1 100644 --- a/src/meshTools/meshSearch/meshSearch.C +++ b/src/meshTools/meshSearch/meshSearch.C @@ -810,8 +810,7 @@ Foam::List Foam::meshSearch::intersections { DynamicList hits; - vector edgeVec = pEnd - pStart; - edgeVec /= mag(edgeVec); + const vector edgeVec = normalised(pEnd - pStart); point pt = pStart; diff --git a/src/meshTools/meshTools/meshTools.C b/src/meshTools/meshTools/meshTools.C index 2890daf70b..96300c8cad 100644 --- a/src/meshTools/meshTools/meshTools.C +++ b/src/meshTools/meshTools/meshTools.C @@ -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; } diff --git a/src/meshTools/primitiveMeshGeometry/primitiveMeshGeometry.C b/src/meshTools/primitiveMeshGeometry/primitiveMeshGeometry.C index 5ab9d5ea3f..65180a3499 100644 --- a/src/meshTools/primitiveMeshGeometry/primitiveMeshGeometry.C +++ b/src/meshTools/primitiveMeshGeometry/primitiveMeshGeometry.C @@ -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()]); diff --git a/src/meshTools/searchableSurfaces/searchableCone/searchableCone.C b/src/meshTools/searchableSurfaces/searchableCone/searchableCone.C index a28dc3600d..1ffa831b51 100644 --- a/src/meshTools/searchableSurfaces/searchableCone/searchableCone.C +++ b/src/meshTools/searchableSurfaces/searchableCone/searchableCone.C @@ -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); diff --git a/src/meshTools/searchableSurfaces/searchableExtrudedCircle/searchableExtrudedCircle.C b/src/meshTools/searchableSurfaces/searchableExtrudedCircle/searchableExtrudedCircle.C index 0180a5e032..226c782d49 100644 --- a/src/meshTools/searchableSurfaces/searchableExtrudedCircle/searchableExtrudedCircle.C +++ b/src/meshTools/searchableSurfaces/searchableExtrudedCircle/searchableExtrudedCircle.C @@ -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(); } } } diff --git a/src/meshTools/searchableSurfaces/searchableSphere/searchableSphere.C b/src/meshTools/searchableSurfaces/searchableSphere/searchableSphere.C index 16b9430ad4..5691a89e31 100644 --- a/src/meshTools/searchableSurfaces/searchableSphere/searchableSphere.C +++ b/src/meshTools/searchableSurfaces/searchableSphere/searchableSphere.C @@ -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 { diff --git a/src/meshTools/sets/faceSources/normalToFace/normalToFace.C b/src/meshTools/sets/faceSources/normalToFace/normalToFace.C index efc6d136ce..d16998d626 100644 --- a/src/meshTools/sets/faceSources/normalToFace/normalToFace.C +++ b/src/meshTools/sets/faceSources/normalToFace/normalToFace.C @@ -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_) { diff --git a/src/meshTools/triSurface/booleanOps/intersectedSurface/intersectedSurface.C b/src/meshTools/triSurface/booleanOps/intersectedSurface/intersectedSurface.C index dd6857c0ad..9cfed82774 100644 --- a/src/meshTools/triSurface/booleanOps/intersectedSurface/intersectedSurface.C +++ b/src/meshTools/triSurface/booleanOps/intersectedSurface/intersectedSurface.C @@ -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); diff --git a/src/meshTools/triSurface/booleanOps/surfaceIntersection/edgeIntersections.C b/src/meshTools/triSurface/booleanOps/surfaceIntersection/edgeIntersections.C index 2f9101a461..612ffb3bf1 100644 --- a/src/meshTools/triSurface/booleanOps/surfaceIntersection/edgeIntersections.C +++ b/src/meshTools/triSurface/booleanOps/surfaceIntersection/edgeIntersections.C @@ -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; diff --git a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C index 4ef1974fe5..abe113cceb 100644 --- a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C +++ b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C @@ -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 ( diff --git a/src/meshTools/triSurface/triSurfaceTools/pointToPointPlanarInterpolation.C b/src/meshTools/triSurface/triSurfaceTools/pointToPointPlanarInterpolation.C index 5f87ba232e..ac28865272 100644 --- a/src/meshTools/triSurface/triSurfaceTools/pointToPointPlanarInterpolation.C +++ b/src/meshTools/triSurface/triSurfaceTools/pointToPointPlanarInterpolation.C @@ -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) { diff --git a/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C b/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C index 75808f63ea..46c36f7deb 100644 --- a/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C +++ b/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C @@ -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 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]); diff --git a/src/sampling/sampledSet/circle/circleSet.C b/src/sampling/sampledSet/circle/circleSet.C index b5387e23ca..062bcdcb06 100644 --- a/src/sampling/sampledSet/circle/circleSet.C +++ b/src/sampling/sampledSet/circle/circleSet.C @@ -94,8 +94,7 @@ void Foam::circleSet::calcSamples label nPoint = 1; while (theta < 360) { - axis1 = axis1*cosAlpha + (axis1^circleAxis_)*sinAlpha; - axis1 /= mag(axis1); + axis1 = normalised(axis1*cosAlpha + (axis1^circleAxis_)*sinAlpha); point pt = origin_ + radius*axis1; label celli = searchEngine().findCell(pt); diff --git a/src/sampling/sampledSet/sampledSet/sampledSet.C b/src/sampling/sampledSet/sampledSet/sampledSet.C index cc05329330..856ce6a401 100644 --- a/src/sampling/sampledSet/sampledSet/sampledSet.C +++ b/src/sampling/sampledSet/sampledSet/sampledSet.C @@ -172,9 +172,7 @@ Foam::scalar Foam::sampledSet::calcSign vec /= magVec; - vector n = mesh().faceAreas()[facei]; - - n /= mag(n) + VSMALL; + const vector n = normalised(mesh().faceAreas()[facei]); return n & vec; } diff --git a/src/thermophysicalModels/radiation/radiationModels/solarLoad/solarLoad.C b/src/thermophysicalModels/radiation/radiationModels/solarLoad/solarLoad.C index 85740809ae..973482e8dd 100644 --- a/src/thermophysicalModels/radiation/radiationModels/solarLoad/solarLoad.C +++ b/src/thermophysicalModels/radiation/radiationModels/solarLoad/solarLoad.C @@ -294,10 +294,9 @@ void Foam::radiation::solarLoad::updateSkyDiffusiveRadiation void Foam::radiation::solarLoad::initialise(const dictionary& coeffs) { - if (coeffs.found("gridUp")) + if (coeffs.readIfPresent("gridUp", verticalDir_)) { - coeffs.lookup("gridUp") >> verticalDir_; - verticalDir_ /= mag(verticalDir_); + verticalDir_.normalise(); } else if (mesh_.foundObject("g")) { diff --git a/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.C b/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.C index 7c720f5ab0..f95d517c18 100644 --- a/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.C +++ b/src/thermophysicalModels/radiation/submodels/solarCalculator/solarCalculator.C @@ -123,12 +123,8 @@ void Foam::solarCalculator::calculateBetaTetha() void Foam::solarCalculator::calculateSunDirection() { - - dict_.lookup("gridUp") >> gridUp_; - gridUp_ /= mag(gridUp_); - - dict_.lookup("gridEast") >> eastDir_; - eastDir_ /= mag(eastDir_); + gridUp_ = normalised(dict_.get("gridUp")); + eastDir_ = normalised(dict_.get("gridEast")); coord_.reset ( @@ -140,7 +136,7 @@ void Foam::solarCalculator::calculateSunDirection() direction_.y() = cos(beta_)*cos(tetha_); // South axis direction_.x() = cos(beta_)*sin(tetha_); // West axis - direction_ /= mag(direction_); + direction_.normalise(); if (debug) { @@ -163,10 +159,9 @@ void Foam::solarCalculator::init() { case mSunDirConstant: { - if (dict_.found("sunDirection")) + if (dict_.readIfPresent("sunDirection", direction_)) { - dict_.lookup("sunDirection") >> direction_; - direction_ /= mag(direction_); + direction_.normalise(); } else { diff --git a/src/waveModels/waveModel/waveModel.C b/src/waveModels/waveModel/waveModel.C index 324ac5ed5b..829cd89d59 100644 --- a/src/waveModels/waveModel/waveModel.C +++ b/src/waveModels/waveModel/waveModel.C @@ -57,8 +57,7 @@ void Foam::waveModel::initialiseGeometry() // - X: streamwise: patch normal // - Y: spanwise: Z^X // - Z: up: (negative) gravity direction - vector x(-gAverage(patch_.faceAreas())); - x /= mag(x) + ROOTVSMALL; + vector x = normalised(-gAverage(patch_.faceAreas())); vector z = -g_/mag(g_); vector y = z^x;