diff --git a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.C b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.C index 20dc01bc60aa4394bc07a7e3bd507f6a4d01576f..c54e6bd693be7842c582d6d701c365d2890307bc 100644 --- a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.C +++ b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.C @@ -50,6 +50,34 @@ namespace Foam const NamedEnum<directMappedPatchBase::sampleMode, 3> directMappedPatchBase::sampleModeNames_; + + + //- Private class for finding nearest + // - point+local index + // - sqr(distance) + // - processor + typedef Tuple2<pointIndexHit, Tuple2<scalar, label> > nearInfo; + + class nearestEqOp + { + + public: + + void operator()(nearInfo& x, const nearInfo& y) const + { + if (y.first().hit()) + { + if (!x.first().hit()) + { + x = y; + } + else if (y.second().first() < x.second().first()) + { + x = y; + } + } + } + }; } @@ -70,7 +98,7 @@ void Foam::directMappedPatchBase::collectSamples labelListList globalFaces(Pstream::nProcs()); globalFc[Pstream::myProcNo()] = patch_.faceCentres(); - globalSamples[Pstream::myProcNo()] = globalFc[Pstream::myProcNo()]+offset_; + globalSamples[Pstream::myProcNo()] = globalFc[Pstream::myProcNo()]+offsets_; globalFaces[Pstream::myProcNo()] = identity(patch_.size()); // Distribute to all processors @@ -365,17 +393,17 @@ void Foam::directMappedPatchBase::calcMapping() const if ( - offset_ == vector::zero + gAverage(mag(offsets_)) <= ROOTVSMALL && mode_ == NEARESTPATCHFACE && sampleRegion_ == patch_.boundaryMesh().mesh().name() && samplePatch_ == patch_.name() ) { WarningIn("directMappedPatchBase::calcMapping() const") - << "Invalid offset " << offset_ << endl + << "Invalid offset " << offsets_ << endl << "Offset is the vector added to the patch face centres to" << " find the patch face supplying the data." << endl - << "Setting it to " << offset_ + << "Setting it to " << offsets_ << " on the same patch, on the same region" << " will find the faces themselves which does not make sense" << " for anything but testing." << endl @@ -383,7 +411,7 @@ void Foam::directMappedPatchBase::calcMapping() const << "sampleRegion_:" << sampleRegion_ << endl << "mode_:" << sampleModeNames_[mode_] << endl << "samplePatch_:" << samplePatch_ << endl - << "offset_:" << offset_ << endl; + << "offsets_:" << offsets_ << endl; } @@ -447,34 +475,38 @@ void Foam::directMappedPatchBase::calcMapping() const } - // Check that actual offset vector (sampleLocations - patchFc) is more or - // less constant. - if (Pstream::master()) - { - const scalarField magOffset(mag(sampleLocations - patchFc)); - const scalar avgOffset(average(magOffset)); - - forAll(magOffset, sampleI) - { - if (mag(magOffset[sampleI]-avgOffset) > max(SMALL, 0.001*avgOffset)) - { - WarningIn("directMappedPatchBase::calcMapping() const") - << "The actual cell/face centres picked up using offset " - << offset_ << " are not" << endl - << " on a single plane." - << " This might give numerical problems." << endl - << " At patchface " << patchFc[sampleI] - << " the sampled cell/face " << sampleLocations[sampleI] - << endl - << " is not on a plane " << avgOffset - << " offset from the patch." << endl - << " You might want to shift your plane offset." - << " Set the debug flag to get a dump of sampled cells." - << endl; - break; - } - } - } + //// Check that actual offset vector (sampleLocations - patchFc) is more or + //// less constant. + //if (Pstream::master()) + //{ + // const scalarField magOffset(mag(sampleLocations - patchFc)); + // const scalar avgOffset(average(magOffset)); + // + // forAll(magOffset, sampleI) + // { + // if + // ( + // mag(magOffset[sampleI]-avgOffset) + // > max(SMALL, 0.001*avgOffset) + // ) + // { + // WarningIn("directMappedPatchBase::calcMapping() const") + // << "The actual cell/face centres picked up using offset " + // << offsets_ << " are not" << endl + // << " on a single plane." + // << " This might give numerical problems." << endl + // << " At patchface " << patchFc[sampleI] + // << " the sampled cell/face " << sampleLocations[sampleI] + // << endl + // << " is not on a plane " << avgOffset + // << " offset from the patch." << endl + // << " You might want to shift your plane offset." + // << " Set the debug flag to get a dump of sampled cells." + // << endl; + // break; + // } + // } + //} // Determine schedule. @@ -556,14 +588,36 @@ void Foam::directMappedPatchBase::calcMapping() const Foam::directMappedPatchBase::directMappedPatchBase ( - const polyPatch& pp + const polyPatch& pp ) : patch_(pp), sampleRegion_(patch_.boundaryMesh().mesh().name()), mode_(NEARESTPATCHFACE), samplePatch_("none"), + uniformOffset_(true), offset_(vector::zero), + offsets_(pp.size(), offset_), + sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()), + mapPtr_(NULL) +{} + + +Foam::directMappedPatchBase::directMappedPatchBase +( + const polyPatch& pp, + const word& sampleRegion, + const sampleMode mode, + const word& samplePatch, + const vectorField& offsets +) +: + patch_(pp), + sampleRegion_(sampleRegion), + mode_(mode), + samplePatch_(samplePatch), + uniformOffset_(false), + offsets_(offsets), sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()), mapPtr_(NULL) {} @@ -586,7 +640,19 @@ Foam::directMappedPatchBase::directMappedPatchBase ), mode_(sampleModeNames_.read(dict.lookup("sampleMode"))), samplePatch_(dict.lookup("samplePatch")), - offset_(dict.lookup("offset")), + uniformOffset_(dict.found("offset")), + offset_ + ( + uniformOffset_ + ? point(dict.lookup("offset")) + : vector::zero + ), + offsets_ + ( + uniformOffset_ + ? pointField(patch_.size(), offset_) + : dict.lookup("offsets") + ), sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()), mapPtr_(NULL) {} @@ -602,7 +668,9 @@ Foam::directMappedPatchBase::directMappedPatchBase sampleRegion_(dmp.sampleRegion_), mode_(dmp.mode_), samplePatch_(dmp.samplePatch_), + uniformOffset_(dmp.uniformOffset_), offset_(dmp.offset_), + offsets_(dmp.offsets_), sameRegion_(dmp.sameRegion_), mapPtr_(NULL) {} @@ -660,7 +728,14 @@ void Foam::directMappedPatchBase::write(Ostream& os) const << token::END_STATEMENT << nl; os.writeKeyword("samplePatch") << samplePatch_ << token::END_STATEMENT << nl; - os.writeKeyword("offset") << offset_ << token::END_STATEMENT << nl; + if (uniformOffset_) + { + os.writeKeyword("offset") << offset_ << token::END_STATEMENT << nl; + } + else + { + os.writeKeyword("offsets") << offsets_ << token::END_STATEMENT << nl; + } } diff --git a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.H b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.H index a3d936757eaa5fc190dfb7890ff2f0194406f9a8..99761bd4debf025d3af910335cadf18a8e3b369f 100644 --- a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.H +++ b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.H @@ -87,12 +87,18 @@ private: //- What to sample const sampleMode mode_; - //- Patch (only if NEARESTBOUNDARY) + //- Patch (only if NEARESTPATCHFACE) const word samplePatch_; - //- Offset vector + //- For backwards compatibility : reading/writing of uniform offset. + const bool uniformOffset_; + + //- Offset vector (uniform) const vector offset_; + //- Offset vector + const vectorField offsets_; + //- Same region const bool sameRegion_; @@ -130,36 +136,6 @@ private: void calcMapping() const; - // Private class - - //- Private class for finding nearest - // - point+local index - // - sqr(distance) - // - processor - typedef Tuple2<pointIndexHit, Tuple2<scalar, label> > nearInfo; - - class nearestEqOp - { - - public: - - void operator()(nearInfo& x, const nearInfo& y) const - { - if (y.first().hit()) - { - if (!x.first().hit()) - { - x = y; - } - else if (y.second().first() < x.second().first()) - { - x = y; - } - } - } - }; - - public: //- Runtime type information @@ -168,9 +144,19 @@ public: // Constructors - //- Construct from components + //- Construct from patch directMappedPatchBase(const polyPatch&); + //- Construct from components + directMappedPatchBase + ( + const polyPatch& pp, + const word& sampleRegion, + const sampleMode sampleMode, + const word& samplePatch, + const vectorField& offset + ); + //- Construct from dictionary directMappedPatchBase(const polyPatch&, const dictionary&); @@ -210,6 +196,12 @@ public: return offset_; } + //- Offset vector (from patch faces to destination mesh objects) + const vectorField& offsets() const + { + return offsets_; + } + //- Return reference to the parallel distribution map const mapDistribute& map() const { diff --git a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.C b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.C index 0058c84d0df42bd5448ff9e3ba15fd4f1674c95e..814ff7a25dbb3f01018bbf25120b0612efab16cb 100644 --- a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.C +++ b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.C @@ -57,6 +57,31 @@ Foam::directMappedPolyPatch::directMappedPolyPatch {} +Foam::directMappedPolyPatch::directMappedPolyPatch +( + const word& name, + const label size, + const label start, + const label index, + const word& sampleRegion, + const directMappedPatchBase::sampleMode mode, + const word& samplePatch, + const vectorField& offset, + const polyBoundaryMesh& bm +) +: + polyPatch(name, size, start, index, bm), + directMappedPatchBase + ( + static_cast<const polyPatch&>(*this), + sampleRegion, + mode, + samplePatch, + offset + ) +{} + + Foam::directMappedPolyPatch::directMappedPolyPatch ( const word& name, diff --git a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.H b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.H index fdd4baec85c9547ded1b7911c765d696c0d10946..bfdbae7257164d16e896c89430f5e5b913bbfea5 100644 --- a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.H +++ b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.H @@ -101,6 +101,20 @@ public: const polyBoundaryMesh& bm ); + //- Construct from components + directMappedPolyPatch + ( + const word& name, + const label size, + const label start, + const label index, + const word& sampleRegion, + const directMappedPatchBase::sampleMode mode, + const word& samplePatch, + const vectorField& offset, + const polyBoundaryMesh& bm + ); + //- Construct from dictionary directMappedPolyPatch ( diff --git a/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.C b/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.C index daaee3bcb4adf2b275627ede0a7489de6ca1115a..30558f61c1dd47c7d9afe4e4a4c7d1b987833eea 100644 --- a/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.C +++ b/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.C @@ -62,6 +62,31 @@ Foam::directMappedWallPolyPatch::directMappedWallPolyPatch {} +Foam::directMappedWallPolyPatch::directMappedWallPolyPatch +( + const word& name, + const label size, + const label start, + const label index, + const word& sampleRegion, + const directMappedPatchBase::sampleMode mode, + const word& samplePatch, + const vectorField& offset, + const polyBoundaryMesh& bm +) +: + wallPolyPatch(name, size, start, index, bm), + directMappedPatchBase + ( + static_cast<const polyPatch&>(*this), + sampleRegion, + mode, + samplePatch, + offset + ) +{} + + Foam::directMappedWallPolyPatch::directMappedWallPolyPatch ( const word& name, diff --git a/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.H b/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.H index 457552e42140f9a92a49b1ca3fd40ba99d1df1c9..b7de43c0ada8741ff89dd42e05eb5abeb57cdec6 100644 --- a/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.H +++ b/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.H @@ -101,6 +101,20 @@ public: const polyBoundaryMesh& bm ); + //- Construct from components + directMappedWallPolyPatch + ( + const word& name, + const label size, + const label start, + const label index, + const word& sampleRegion, + const directMappedPatchBase::sampleMode mode, + const word& samplePatch, + const vectorField& offset, + const polyBoundaryMesh& bm + ); + //- Construct from dictionary directMappedWallPolyPatch (