From 1f9fd259fdfc36a131b3308ebb4bd9d336470079 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 29 Nov 2011 13:06:25 +0000 Subject: [PATCH] ENH: Added option to reverse the direction of the AMI target patch --- .../AMIInterpolation/AMIInterpolation.C | 14 ++++- .../AMIInterpolation/AMIInterpolation.H | 20 +++++-- .../faceAreaIntersect/faceAreaIntersect.C | 8 ++- .../faceAreaIntersect/faceAreaIntersect.H | 6 +- .../cyclicAMIPolyPatch/cyclicAMIPolyPatch.C | 13 ++++- .../cyclicAMIPolyPatch/cyclicAMIPolyPatch.H | 3 + .../mappedPolyPatch/mappedPatchBase.C | 56 ++++++++++++------- .../mappedPolyPatch/mappedPatchBase.H | 3 + 8 files changed, 90 insertions(+), 33 deletions(-) diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C index 1ebf90faf0..ad0882c84c 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C @@ -902,7 +902,7 @@ Foam::scalar Foam::AMIInterpolation::interArea } // create intersection object - faceAreaIntersect inter(srcPoints, tgtPoints); + faceAreaIntersect inter(srcPoints, tgtPoints, reverseTarget_); // crude resultant norm - face normals should be opposite const vector n = 0.5*(tgt.normal(tgtPoints) - src.normal(srcPoints)); @@ -1432,14 +1432,17 @@ Foam::AMIInterpolation::AMIInterpolation ( const SourcePatch& srcPatch, const TargetPatch& tgtPatch, - const faceAreaIntersect::triangulationMode& triMode + const faceAreaIntersect::triangulationMode& triMode, + const bool reverseTarget ) : + reverseTarget_(reverseTarget), singlePatchProc_(-999), srcAddress_(), srcWeights_(), tgtAddress_(), tgtWeights_(), + treePtr_(NULL), startSeedI_(0), triMode_(triMode), srcMapPtr_(NULL), @@ -1462,14 +1465,17 @@ Foam::AMIInterpolation::AMIInterpolation const SourcePatch& srcPatch, const TargetPatch& tgtPatch, const autoPtr& surfPtr, - const faceAreaIntersect::triangulationMode& triMode + const faceAreaIntersect::triangulationMode& triMode, + const bool reverseTarget ) : + reverseTarget_(reverseTarget), singlePatchProc_(-999), srcAddress_(), srcWeights_(), tgtAddress_(), tgtWeights_(), + treePtr_(NULL), startSeedI_(0), triMode_(triMode), srcMapPtr_(NULL), @@ -1551,11 +1557,13 @@ Foam::AMIInterpolation::AMIInterpolation const labelList& targetRestrictAddressing ) : + reverseTarget_(fineAMI.reverseTarget_), singlePatchProc_(fineAMI.singlePatchProc_), srcAddress_(), srcWeights_(), tgtAddress_(), tgtWeights_(), + treePtr_(NULL), startSeedI_(0), triMode_(fineAMI.triMode_), srcMapPtr_(NULL), diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H index 12646e5061..ed62292430 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H @@ -34,6 +34,10 @@ Description projection, Farrell PE and Maddison JR, 2011, Comput. Methods Appl. Mech Engrg, Volume 200, Issues 1-4, pp 89-100 + Interpolation requires that the two patches should have opposite + orientations (opposite normals). The 'reverseTarget' flag can be used to + reverse the orientation of the target patch. + SourceFiles AMIInterpolation.C @@ -109,6 +113,9 @@ class AMIInterpolation // Private data + //- Flag to indicate that the two patches are co-directional and + // that the orientation of the target patch should be reversed + const bool reverseTarget_; //- Index of processor that holds all of both sides. -1 in all other // cases @@ -332,7 +339,8 @@ public: ( const SourcePatch& srcPatch, const TargetPatch& tgtPatch, - const faceAreaIntersect::triangulationMode& triMode + const faceAreaIntersect::triangulationMode& triMode, + const bool reverseTarget = false ); //- Construct from components, with projection surface @@ -341,11 +349,12 @@ public: const SourcePatch& srcPatch, const TargetPatch& tgtPatch, const autoPtr& surf, - const faceAreaIntersect::triangulationMode& triMode + const faceAreaIntersect::triangulationMode& triMode, + const bool reverseTarget = false ); //- Construct from agglomeration of AMIInterpolation. Agglomeration - // passed in as new coarse size and addressing from fine from coarse. + // passed in as new coarse size and addressing from fine from coarse AMIInterpolation ( const AMIInterpolation& fineAMI, @@ -362,9 +371,11 @@ public: // Access - //- -1 or the processor holding all faces (both sides) of the AMI + //- Set to -1, or the processor holding all faces (both sides) of + // the AMI label singlePatchProc() const; + // Source patch //- Return const access to source patch face areas @@ -497,6 +508,7 @@ public: const tmp >& tFld ) const; + // Checks //- Write face connectivity as OBJ file diff --git a/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.C b/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.C index 3d3a72e3a4..db8a0ba294 100644 --- a/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.C +++ b/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.C @@ -298,11 +298,13 @@ Foam::scalar Foam::faceAreaIntersect::triangleIntersect Foam::faceAreaIntersect::faceAreaIntersect ( const pointField& pointsA, - const pointField& pointsB + const pointField& pointsB, + const bool reverseB ) : pointsA_(pointsA), - pointsB_(pointsB) + pointsB_(pointsB), + reverseB_(reverseB) {} @@ -362,7 +364,7 @@ Foam::scalar Foam::faceAreaIntersect::calc { forAll(trisB, tB) { - triPoints tpB = getTriPoints(pointsB_, trisB[tB], true); + triPoints tpB = getTriPoints(pointsB_, trisB[tB], !reverseB_); // if (triArea(tpB) > ROOTVSMALL) { diff --git a/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.H b/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.H index f2c8d13e2c..2a27e30960 100644 --- a/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.H +++ b/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.H @@ -74,6 +74,9 @@ private: //- Reference to the points of sideB const pointField& pointsB_; + //- Flag to reverse B faces + const bool reverseB_; + // Private Member Functions @@ -142,7 +145,8 @@ public: faceAreaIntersect ( const pointField& pointsA, - const pointField& pointsB + const pointField& pointsB, + const bool reverseB = false ); diff --git a/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C b/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C index f3dbc36d80..821ef00dec 100644 --- a/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C +++ b/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C @@ -278,7 +278,8 @@ void Foam::cyclicAMIPolyPatch::resetAMI() const *this, nbrPatch0, surfPtr(), - faceAreaIntersect::tmMesh + faceAreaIntersect::tmMesh, + AMIReverse_ ) ); } @@ -363,6 +364,7 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch rotationCentre_(point::zero), separationVector_(vector::zero), AMIPtr_(NULL), + AMIReverse_(false), surfPtr_(NULL), surfDict_(dictionary::null) { @@ -387,6 +389,7 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch rotationCentre_(point::zero), separationVector_(vector::zero), AMIPtr_(NULL), + AMIReverse_(dict.lookupOrDefault("flipNormals", false)), surfPtr_(NULL), surfDict_(dict.subOrEmptyDict("surface")) { @@ -469,6 +472,7 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch rotationCentre_(pp.rotationCentre_), separationVector_(pp.separationVector_), AMIPtr_(NULL), + AMIReverse_(pp.AMIReverse_), surfPtr_(NULL), surfDict_(dictionary::null) { @@ -495,6 +499,7 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch rotationCentre_(pp.rotationCentre_), separationVector_(pp.separationVector_), AMIPtr_(NULL), + AMIReverse_(pp.AMIReverse_), surfPtr_(NULL), surfDict_(dictionary::null) { @@ -535,6 +540,7 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch rotationCentre_(pp.rotationCentre_), separationVector_(pp.separationVector_), AMIPtr_(NULL), + AMIReverse_(pp.AMIReverse_), surfPtr_(NULL), surfDict_(pp.surfDict_) {} @@ -813,6 +819,11 @@ void Foam::cyclicAMIPolyPatch::write(Ostream& os) const } } + if (AMIReverse_) + { + os.writeKeyword("flipNormals") << AMIReverse_ + << token::END_STATEMENT << nl; + } if (surfDict_ != dictionary::null) { diff --git a/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H b/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H index dcd26799c0..7765ba2ac2 100644 --- a/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H +++ b/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H @@ -88,6 +88,9 @@ private: //- AMI interpolation class mutable autoPtr AMIPtr_; + //- Flag to indicate that slave patch should be reversed for AMI + const bool AMIReverse_; + //- Projection surface mutable autoPtr surfPtr_; diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C index 9d7ed47e89..2b62b29e34 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C @@ -650,7 +650,8 @@ void Foam::mappedPatchBase::calcAMI() const patch_, samplePolyPatch(), // nbrPatch0, surfPtr(), - faceAreaIntersect::tmMesh + faceAreaIntersect::tmMesh, + AMIReverse_ ) ); } @@ -674,6 +675,7 @@ Foam::mappedPatchBase::mappedPatchBase sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()), mapPtr_(NULL), AMIPtr_(NULL), + AMIReverse_(false), surfPtr_(NULL), surfDict_(dictionary::null) {} @@ -699,6 +701,7 @@ Foam::mappedPatchBase::mappedPatchBase sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()), mapPtr_(NULL), AMIPtr_(NULL), + AMIReverse_(false), surfPtr_(NULL), surfDict_(dictionary::null) {} @@ -724,6 +727,7 @@ Foam::mappedPatchBase::mappedPatchBase sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()), mapPtr_(NULL), AMIPtr_(NULL), + AMIReverse_(false), surfPtr_(NULL), surfDict_(dictionary::null) {} @@ -749,6 +753,7 @@ Foam::mappedPatchBase::mappedPatchBase sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()), mapPtr_(NULL), AMIPtr_(NULL), + AMIReverse_(false), surfPtr_(NULL), surfDict_(dictionary::null) {} @@ -778,6 +783,7 @@ Foam::mappedPatchBase::mappedPatchBase sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()), mapPtr_(NULL), AMIPtr_(NULL), + AMIReverse_(dict.lookupOrDefault("flipNormals", false)), surfPtr_(NULL), surfDict_(dict.subOrEmptyDict("surface")) { @@ -836,45 +842,47 @@ Foam::mappedPatchBase::mappedPatchBase Foam::mappedPatchBase::mappedPatchBase ( const polyPatch& pp, - const mappedPatchBase& dmp + const mappedPatchBase& mpb ) : patch_(pp), - sampleRegion_(dmp.sampleRegion_), - mode_(dmp.mode_), - samplePatch_(dmp.samplePatch_), - offsetMode_(dmp.offsetMode_), - offset_(dmp.offset_), - offsets_(dmp.offsets_), - distance_(dmp.distance_), - sameRegion_(dmp.sameRegion_), + sampleRegion_(mpb.sampleRegion_), + mode_(mpb.mode_), + samplePatch_(mpb.samplePatch_), + offsetMode_(mpb.offsetMode_), + offset_(mpb.offset_), + offsets_(mpb.offsets_), + distance_(mpb.distance_), + sameRegion_(mpb.sameRegion_), mapPtr_(NULL), AMIPtr_(NULL), + AMIReverse_(mpb.AMIReverse_), surfPtr_(NULL), - surfDict_(dmp.surfDict_) + surfDict_(mpb.surfDict_) {} Foam::mappedPatchBase::mappedPatchBase ( const polyPatch& pp, - const mappedPatchBase& dmp, + const mappedPatchBase& mpb, const labelUList& mapAddressing ) : patch_(pp), - sampleRegion_(dmp.sampleRegion_), - mode_(dmp.mode_), - samplePatch_(dmp.samplePatch_), - offsetMode_(dmp.offsetMode_), - offset_(dmp.offset_), - offsets_(dmp.offsets_, mapAddressing), - distance_(dmp.distance_), - sameRegion_(dmp.sameRegion_), + sampleRegion_(mpb.sampleRegion_), + mode_(mpb.mode_), + samplePatch_(mpb.samplePatch_), + offsetMode_(mpb.offsetMode_), + offset_(mpb.offset_), + offsets_(mpb.offsets_, mapAddressing), + distance_(mpb.distance_), + sameRegion_(mpb.sameRegion_), mapPtr_(NULL), AMIPtr_(NULL), + AMIReverse_(mpb.AMIReverse_), surfPtr_(NULL), - surfDict_(dmp.surfDict_) + surfDict_(mpb.surfDict_) {} @@ -991,6 +999,12 @@ void Foam::mappedPatchBase::write(Ostream& os) const if (mode_ == NEARESTPATCHFACEAMI) { + if (AMIReverse_) + { + os.writeKeyword("flipNormals") << AMIReverse_ + << token::END_STATEMENT << nl; + } + os.writeKeyword(surfDict_.dictName()); os << surfDict_; } diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H index d6de7c9656..43c19a671c 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H @@ -192,6 +192,9 @@ protected: //- Pointer to AMI interpolator mutable autoPtr AMIPtr_; + //- Flag to indicate that slave patch should be reversed for AMI + const bool AMIReverse_; + //- Pointer to projection surface employed by AMI interpolator mutable autoPtr surfPtr_;