From 7b5da77f5fb08fcc016ee473058baac9d07d3138 Mon Sep 17 00:00:00 2001 From: Henry <Henry> Date: Fri, 31 Jan 2014 14:51:55 +0000 Subject: [PATCH] symmetryPlanePolyPatch: calculate the plane normal during construction to guarantee parallel consistency --- .../symmetryPlane/symmetryPlanePolyPatch.C | 63 +++++++++---------- .../symmetryPlane/symmetryPlanePolyPatch.H | 14 ++++- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/symmetryPlane/symmetryPlanePolyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/symmetryPlane/symmetryPlanePolyPatch.C index bd0e06166ae..9b0d5411c92 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/symmetryPlane/symmetryPlanePolyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/symmetryPlane/symmetryPlanePolyPatch.C @@ -50,7 +50,7 @@ Foam::symmetryPlanePolyPatch::symmetryPlanePolyPatch ) : polyPatch(name, size, start, index, bm, patchType), - n_(vector::zero) + n_(calcNormal()) {} @@ -64,7 +64,7 @@ Foam::symmetryPlanePolyPatch::symmetryPlanePolyPatch ) : polyPatch(name, dict, index, bm, patchType), - n_(vector::zero) + n_(calcNormal()) {} @@ -75,7 +75,7 @@ Foam::symmetryPlanePolyPatch::symmetryPlanePolyPatch ) : polyPatch(pp, bm), - n_(vector::zero) + n_(calcNormal()) {} @@ -89,7 +89,7 @@ Foam::symmetryPlanePolyPatch::symmetryPlanePolyPatch ) : polyPatch(pp, bm, index, newSize, newStart), - n_(vector::zero) + n_(calcNormal()) {} @@ -103,47 +103,42 @@ Foam::symmetryPlanePolyPatch::symmetryPlanePolyPatch ) : polyPatch(pp, bm, index, mapAddressing, newStart), - n_(vector::zero) + n_(calcNormal()) {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * * // -const Foam::vector& Foam::symmetryPlanePolyPatch::n() const +Foam::vector Foam::symmetryPlanePolyPatch::calcNormal() const { - // If the symmetry normal is not set calculate it - // as the average face-normal - if (magSqr(n_) < 0.5) + if (returnReduce(size(), sumOp<label>()) == 0) { - if (returnReduce(size(), sumOp<label>()) == 0) - { - // No faces in patch. Avoid gAverage complaining and set - // normal to nonsense value to catch any use - n_ = vector::rootMax; - } - else - { - const vectorField& nf(faceNormals()); - n_ = gAverage(nf); + // No faces in patch. Avoid gAverage complaining and set + // normal to nonsense value to catch any use + return vector::rootMax; + } + else + { + const vectorField& nf(faceNormals()); + vector n = gAverage(nf); - // Check the symmetry plane is planar - forAll(nf, facei) + // Check the symmetry plane is planar + forAll(nf, facei) + { + if (magSqr(n - nf[facei]) > SMALL) { - if (magSqr(n_ - nf[facei]) > SMALL) - { - FatalErrorIn("symmetryPlanePolyPatch::n()") - << "Symmetry plane '" << name() << "' is not planar." - << endl - << " Either split the patch into planar parts" - << " or use the " << symmetryPolyPatch::typeName - << " patch type" - << exit(FatalError); - } + FatalErrorIn("symmetryPlanePolyPatch::n()") + << "Symmetry plane '" << name() << "' is not planar." + << endl + << " Either split the patch into planar parts" + << " or use the " << symmetryPolyPatch::typeName + << " patch type" + << exit(FatalError); } } - } - return n_; + return n; + } } diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/symmetryPlane/symmetryPlanePolyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/symmetryPlane/symmetryPlanePolyPatch.H index 81b8afcd728..3b5c5336a06 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/symmetryPlane/symmetryPlanePolyPatch.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/symmetryPlane/symmetryPlanePolyPatch.H @@ -52,8 +52,13 @@ class symmetryPlanePolyPatch { // Private data - //- Symmetry plane normal (calculated on demand) - mutable vector n_; + //- Symmetry plane normal + vector n_; + + // Private member functions + + //- Calculate and return the symmetry plane normal + vector calcNormal() const; public: @@ -162,7 +167,10 @@ public: // Member Functions //- Return symmetry plane normal - const vector& n() const; + const vector& n() const + { + return n_; + } }; -- GitLab