From b81a2f2fa68ed8bc3cd252c11231b6340917f74f Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Fri, 10 Aug 2018 14:41:32 +0200 Subject: [PATCH] STYLE: use edge::unitVec() for improved code clarity --- .../utilities/mesh/advanced/splitCells/splitCells.C | 3 +-- .../utilities/surface/surfaceHookUp/surfaceHookUp.C | 6 ++---- .../primitiveMesh/PatchTools/PatchToolsSortEdges.C | 3 +-- .../polyTopoChange/polyTopoChange/edgeCollapser.C | 12 +++--------- src/finiteArea/faMesh/faMeshDemandDrivenData.C | 6 ++---- .../refinementFeatures/refinementFeatures.C | 8 ++++---- src/meshTools/cellFeatures/cellFeatures.C | 6 ++---- src/meshTools/meshTools/meshTools.C | 6 +----- .../searchableExtrudedCircle.C | 4 ++-- 9 files changed, 18 insertions(+), 36 deletions(-) diff --git a/applications/utilities/mesh/advanced/splitCells/splitCells.C b/applications/utilities/mesh/advanced/splitCells/splitCells.C index a1e5a8fc019..4d97d4e45ec 100644 --- a/applications/utilities/mesh/advanced/splitCells/splitCells.C +++ b/applications/utilities/mesh/advanced/splitCells/splitCells.C @@ -319,8 +319,7 @@ bool splitCell { const edge& e = mesh.edges()[edgeI]; - vector eVec = e.vec(mesh.points()); - eVec /= mag(eVec); + const vector eVec = e.unitVec(mesh.points()); vector planeN = eVec ^ halfNorm; diff --git a/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C b/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C index 9e28c823f8e..a62ecb2877e 100644 --- a/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C +++ b/applications/utilities/surface/surfaceHookUp/surfaceHookUp.C @@ -127,8 +127,7 @@ void greenRefine //{ // const edge& e = surf.edges()[edgeIndex]; -// vector eVec = e.vec(surf.localPoints()); -// eVec /= mag(eVec) + SMALL; +// const vector eVec = e.unitVec(surf.localPoints()); // const labelList& pEdges = surf.pointEdges()[pointIndex]; // @@ -136,8 +135,7 @@ void greenRefine // { // const edge& nearE = surf.edges()[pEdges[eI]]; -// vector nearEVec = nearE.vec(surf.localPoints()); -// nearEVec /= mag(nearEVec) + SMALL; +// const vector nearEVec = nearE.unitVec(surf.localPoints()); // const scalar dot = eVec & nearEVec; // const scalar minCos = degToRad(angle); diff --git a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSortEdges.C b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSortEdges.C index 4f70b4ca851..cdc0bac9ea8 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSortEdges.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSortEdges.C @@ -63,8 +63,7 @@ Foam::PatchTools::sortedEdgeFaces const point& edgePt = localPoints[e.start()]; - vector e2 = e.vec(localPoints); - e2 /= mag(e2) + VSMALL; + const vector e2 = e.unitVec(localPoints); // Get the vertex on 0th face that forms a vector with the first // edge point that has the largest angle with the edge diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.C index 1df70acf076..0608d45f7b3 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.C @@ -410,13 +410,9 @@ void Foam::edgeCollapser::faceCollapseAxisAndAspectRatio if (detJ < 1e-5) { - collapseAxis = f.edges()[f.longestEdge(pts)].vec(pts); - // It is possible that all the points of a face are the same - if (magSqr(collapseAxis) > VSMALL) - { - collapseAxis /= mag(collapseAxis); - } + + collapseAxis = f.edges()[f.longestEdge(pts)].unitVec(pts); // Empirical correlation for high aspect ratio faces @@ -433,9 +429,7 @@ void Foam::edgeCollapser::faceCollapseAxisAndAspectRatio // Cannot necessarily determine linearly independent // eigenvectors, or any at all, use longest edge direction. - collapseAxis = f.edges()[f.longestEdge(pts)].vec(pts); - - collapseAxis /= mag(collapseAxis); + collapseAxis = f.edges()[f.longestEdge(pts)].unitVec(pts); aspectRatio = 1.0; } diff --git a/src/finiteArea/faMesh/faMeshDemandDrivenData.C b/src/finiteArea/faMesh/faMeshDemandDrivenData.C index 82ae59060da..25552744506 100644 --- a/src/finiteArea/faMesh/faMeshDemandDrivenData.C +++ b/src/finiteArea/faMesh/faMeshDemandDrivenData.C @@ -529,8 +529,7 @@ void Foam::faMesh::calcEdgeAreaNormals() const forAll(edgeAreaNormals.internalField(), edgeI) { - vector e = edges()[edgeI].vec(points()); - e /= mag(e); + const vector e = edges()[edgeI].unitVec(points()); // scalar wStart = // 1.0 - sqr(mag(e^pointNormals[edges()[edgeI].end()])); @@ -580,8 +579,7 @@ void Foam::faMesh::calcEdgeAreaNormals() const pointNormals[patchEdges[edgeI].start()] + pointNormals[patchEdges[edgeI].end()]; - vector e = patchEdges[edgeI].vec(points()); - e /= mag(e); + const vector e = patchEdges[edgeI].unitVec(points()); edgeAreaNormals.boundaryFieldRef()[patchI][edgeI] -= e*(e&edgeAreaNormals.boundaryField()[patchI][edgeI]); diff --git a/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C b/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C index d9cb3ecddfa..050d7215a98 100644 --- a/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C +++ b/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C @@ -575,8 +575,8 @@ void Foam::refinementFeatures::findNearestEdge const treeDataEdge& td = tree.shapes(); const edge& e = td.edges()[nearInfo[sampleI].index()]; - nearNormal[sampleI] = e.vec(td.points()); - nearNormal[sampleI] /= mag(nearNormal[sampleI])+VSMALL; + + nearNormal[sampleI] = e.unitVec(td.points()); } } } @@ -638,8 +638,8 @@ void Foam::refinementFeatures::findNearestRegionEdge ); const edge& e = td.edges()[nearInfo[sampleI].index()]; - nearNormal[sampleI] = e.vec(td.points()); - nearNormal[sampleI] /= mag(nearNormal[sampleI])+VSMALL; + + nearNormal[sampleI] = e.unitVec(td.points()); } } } diff --git a/src/meshTools/cellFeatures/cellFeatures.C b/src/meshTools/cellFeatures/cellFeatures.C index 8e0ab780d19..0c509928be0 100644 --- a/src/meshTools/cellFeatures/cellFeatures.C +++ b/src/meshTools/cellFeatures/cellFeatures.C @@ -429,13 +429,11 @@ bool Foam::cellFeatures::isFeaturePoint(const label edge0, const label edge1) const edge& e0 = mesh_.edges()[edge0]; - vector e0Vec = e0.vec(mesh_.points()); - e0Vec /= mag(e0Vec); + const vector e0Vec = e0.unitVec(mesh_.points()); const edge& e1 = mesh_.edges()[edge1]; - vector e1Vec = e1.vec(mesh_.points()); - e1Vec /= mag(e1Vec); + const vector e1Vec = e1.unitVec(mesh_.points()); scalar cosAngle; diff --git a/src/meshTools/meshTools/meshTools.C b/src/meshTools/meshTools/meshTools.C index 07fc46bec47..2890daf70b2 100644 --- a/src/meshTools/meshTools/meshTools.C +++ b/src/meshTools/meshTools/meshTools.C @@ -192,11 +192,7 @@ Foam::vector Foam::meshTools::normEdgeVec const label edgeI ) { - vector eVec = mesh.edges()[edgeI].vec(mesh.points()); - - eVec /= mag(eVec); - - return eVec; + return mesh.edges()[edgeI].unitVec(mesh.points()); } diff --git a/src/meshTools/searchableSurfaces/searchableExtrudedCircle/searchableExtrudedCircle.C b/src/meshTools/searchableSurfaces/searchableExtrudedCircle/searchableExtrudedCircle.C index f531578355f..0180a5e032e 100644 --- a/src/meshTools/searchableSurfaces/searchableExtrudedCircle/searchableExtrudedCircle.C +++ b/src/meshTools/searchableSurfaces/searchableExtrudedCircle/searchableExtrudedCircle.C @@ -432,8 +432,8 @@ void Foam::searchableExtrudedCircle::getNormal normal[i] = info[i].hitPoint()-curvePt.hitPoint(); // Subtract axial direction - vector axialVec = edges[curvePt.index()].vec(points); - axialVec /= mag(axialVec); + const vector axialVec = edges[curvePt.index()].unitVec(points); + normal[i] -= (normal[i]&axialVec)*axialVec; normal[i] /= mag(normal[i]); } -- GitLab