diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C index e753d53d8a..b1cd7a02f6 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C @@ -60,27 +60,35 @@ const NamedEnum // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +Foam::label Foam::cyclicPolyPatch::findMaxArea +( + const pointField& points, + const faceList& faces +) +{ + label maxI = -1; + scalar maxAreaSqr = -GREAT; + + forAll(faces, faceI) + { + scalar areaSqr = magSqr(faces[faceI].normal(points)); + + if (areaSqr > maxAreaSqr) + { + maxAreaSqr = areaSqr; + maxI = faceI; + } + } + return maxI; +} + + void Foam::cyclicPolyPatch::calcTransforms() { if (size() > 0) { const pointField& points = this->points(); - maxI_ = -1; - scalar maxAreaSqr = -GREAT; - - for (label faceI = 0; faceI < size()/2; faceI++) - { - const face& f = operator[](faceI); - scalar areaSqr = magSqr(f.normal(points)); - - if (areaSqr > maxAreaSqr) - { - maxAreaSqr = areaSqr; - maxI_ = faceI; - } - } - primitivePatch half0 ( SubList @@ -369,6 +377,9 @@ bool Foam::cyclicPolyPatch::getGeometricHalves } +// Given a split of faces into left and right half calculate the centres +// and anchor points. Transform the left points so they align with the +// right ones. void Foam::cyclicPolyPatch::getCentresAndAnchors ( const primitivePatch& pp, @@ -403,11 +414,17 @@ void Foam::cyclicPolyPatch::getCentresAndAnchors } default: { - // Assumes that cyclic is correctly ordered, so that face[maxI_] - // on each side is equivalent. - n0 = half0Faces[maxI_].normal(pp.points()); + // Assumes that cyclic is planar. This is also the initial + // condition for patches without faces. + + // Determine the face with max area on both halves. These + // two faces are used to determine the transformation tensors + label max0I = findMaxArea(pp.points(), half0Faces); + n0 = half0Faces[max0I].normal(pp.points()); n0 /= mag(n0) + VSMALL; - n1 = half1Faces[maxI_].normal(pp.points()); + + label max1I = findMaxArea(pp.points(), half1Faces); + n1 = half1Faces[max1I].normal(pp.points()); n1 /= mag(n1) + VSMALL; } } @@ -596,7 +613,6 @@ Foam::cyclicPolyPatch::cyclicPolyPatch coupledPointsPtr_(NULL), coupledEdgesPtr_(NULL), featureCos_(0.9), - maxI_(-1), transform_(UNKNOWN), rotationAxis_(vector::zero), rotationCentre_(point::zero) @@ -617,7 +633,6 @@ Foam::cyclicPolyPatch::cyclicPolyPatch coupledPointsPtr_(NULL), coupledEdgesPtr_(NULL), featureCos_(0.9), - maxI_(-1), transform_(UNKNOWN), rotationAxis_(vector::zero), rotationCentre_(point::zero) @@ -658,7 +673,6 @@ Foam::cyclicPolyPatch::cyclicPolyPatch coupledPointsPtr_(NULL), coupledEdgesPtr_(NULL), featureCos_(pp.featureCos_), - maxI_(pp.maxI_), transform_(pp.transform_), rotationAxis_(pp.rotationAxis_), rotationCentre_(pp.rotationCentre_) @@ -680,7 +694,6 @@ Foam::cyclicPolyPatch::cyclicPolyPatch coupledPointsPtr_(NULL), coupledEdgesPtr_(NULL), featureCos_(pp.featureCos_), - maxI_(pp.maxI_), transform_(pp.transform_), rotationAxis_(pp.rotationAxis_), rotationCentre_(pp.rotationCentre_) diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H index 418dbcb003..f9c4e66dbb 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H @@ -98,9 +98,6 @@ private: // Used to split cyclic into halves. scalar featureCos_; - //- Index of largest cell face - label maxI_; - //- Type of transformation - rotational or translational transformType transform_; @@ -113,8 +110,12 @@ private: // Private member functions + //- Find amongst selected faces the one with the largest area + static label findMaxArea(const pointField&, const faceList&); + void calcTransforms(); + // Face ordering //- Find the two parts of the faces of pp using feature edges. @@ -169,16 +170,16 @@ protected: // Protected Member functions //- Initialise the calculation of the patch geometry - void initGeometry(); + virtual void initGeometry(); //- Calculate the patch geometry - void calcGeometry(); + virtual void calcGeometry(); //- Initialise the patches for moving points - void initMovePoints(const pointField&); + virtual void initMovePoints(const pointField&); //- Correct patches after moving points - void movePoints(const pointField&); + virtual void movePoints(const pointField&); //- Initialise the update of the patch topology virtual void initUpdateMesh();