From e4cd1b949daaf8d541044a42a2cd82816fe2a429 Mon Sep 17 00:00:00 2001 From: laurence Date: Mon, 22 Jul 2013 16:20:29 +0100 Subject: [PATCH] ENH: plane: Add member function that mirrors a point in a plane --- .../conformalVoronoiMeshFeaturePoints.C | 35 +++++-------------- .../meshes/primitiveShapes/plane/plane.C | 15 ++++++++ .../meshes/primitiveShapes/plane/plane.H | 3 ++ 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C index 1cdd66490d..ac17397ad2 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C @@ -301,8 +301,8 @@ void Foam::conformalVoronoiMesh::createEdgePointGroupByCirculating Foam::point pt1 = edgePt + s + ppDist*normal; Foam::point pt2 = edgePt - s + ppDist*normal; - Foam::point pt3 = reflectPointInPlane(pt1, facePlane); - Foam::point pt4 = reflectPointInPlane(pt2, facePlane); + Foam::point pt3 = facePlane.mirror(pt1); + Foam::point pt4 = facePlane.mirror(pt2); pts.append(Vb(pt1, Vb::vtInternalFeatureEdge)); pts.append(Vb(pt2, Vb::vtInternalFeatureEdge)); @@ -449,7 +449,7 @@ void Foam::conformalVoronoiMesh::createEdgePointGroupByCirculating if (masterPointReflectionsPrev.found(iter.key())) { const Foam::point reflectedPt = - reflectPointInPlane(pt, masterPointReflectionsPrev[iter.key()]); + masterPointReflectionsPrev[iter.key()].mirror(pt); // Info<< " Adding Prev " << reflectedPt << " " // << indexedVertexEnum::vertexTypeNames_[reflectedPtType] @@ -461,7 +461,7 @@ void Foam::conformalVoronoiMesh::createEdgePointGroupByCirculating if (masterPointReflectionsNext.found(iter.key())) { const Foam::point reflectedPt = - reflectPointInPlane(pt, masterPointReflectionsNext[iter.key()]); + masterPointReflectionsNext[iter.key()].mirror(pt); // Info<< " Adding Next " << reflectedPt << " " // << indexedVertexEnum::vertexTypeNames_[reflectedPtType] @@ -815,8 +815,8 @@ void Foam::conformalVoronoiMesh::createOpenEdgePointGroup Foam::point pt1 = edgePt + s + ppDist*n; Foam::point pt2 = edgePt - s + ppDist*n; - Foam::point pt3 = reflectPointInPlane(pt1, facePlane); - Foam::point pt4 = reflectPointInPlane(pt2, facePlane); + Foam::point pt3 = facePlane.mirror(pt1); + Foam::point pt4 = facePlane.mirror(pt2); pts.append(Vb(pt1, Vb::vtInternalSurface)); pts.append(Vb(pt2, Vb::vtInternalSurface)); @@ -1235,8 +1235,7 @@ void Foam::conformalVoronoiMesh::addMasterAndSlavePoints const plane& reflPlane = masterPointPlanes[planeI](); - const Foam::point slavePt = - reflectPointInPlane(masterPt, reflPlane); + const Foam::point slavePt = reflPlane.mirror(masterPt); // Info<< " Slave " << planeI << " = " << slavePt << endl; @@ -1717,27 +1716,9 @@ Foam::List Foam::conformalVoronoiMesh::reflectPointInPlanes forAll(planes, planeI) { - reflectedPoints[planeI] = reflectPointInPlane(p, planes[planeI]()); + reflectedPoints[planeI] = planes[planeI]().mirror(p); } return reflectedPoints; } - -Foam::point Foam::conformalVoronoiMesh::reflectPointInPlane -( - const Foam::point p, - const plane& planeN -) const -{ - const vector reflectedPtDir = p - planeN.nearestPoint(p); - - if ((planeN.normal() & reflectedPtDir) > 0) - { - return p - 2.0*planeN.distance(p)*planeN.normal(); - } - else - { - return p + 2.0*planeN.distance(p)*planeN.normal(); - } -} diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C index 410b20b387..fe4f649f15 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C @@ -447,6 +447,21 @@ Foam::plane::side Foam::plane::sideOfPlane(const point& p) const } +Foam::point Foam::plane::mirror(const point& p) const +{ + const vector mirroredPtDir = p - nearestPoint(p); + + if ((normal() & mirroredPtDir) > 0) + { + return p - 2.0*distance(p)*normal(); + } + else + { + return p + 2.0*distance(p)*normal(); + } +} + + void Foam::plane::writeDict(Ostream& os) const { os.writeKeyword("planeType") << "pointAndNormal" diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H index 3a47e6bf2e..44564fa92a 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H @@ -194,6 +194,9 @@ public: // If the point is on the plane, then returns NORMAL. side sideOfPlane(const point& p) const; + //- Mirror the supplied point in the plane. Return the mirrored point. + point mirror(const point& p) const; + //- Write to dictionary void writeDict(Ostream&) const;