diff --git a/applications/utilities/preProcessing/mapFields/mapFields.C b/applications/utilities/preProcessing/mapFields/mapFields.C index 6a6e6e0ed0..5a293d7970 100644 --- a/applications/utilities/preProcessing/mapFields/mapFields.C +++ b/applications/utilities/preProcessing/mapFields/mapFields.C @@ -41,7 +41,8 @@ void mapConsistentMesh ( const fvMesh& meshSource, const fvMesh& meshTarget, - const meshToMesh::interpolationMethod& mapMethod, + const word& mapMethod, + const word& AMIMapMethod, const bool subtract, const HashSet& selectedFields, const bool noLagrangian @@ -50,7 +51,7 @@ void mapConsistentMesh Info<< nl << "Consistently creating and mapping fields for time " << meshSource.time().timeName() << nl << endl; - meshToMesh interp(meshSource, meshTarget, mapMethod); + meshToMesh interp(meshSource, meshTarget, mapMethod, AMIMapMethod); if (subtract) { @@ -79,7 +80,8 @@ void mapSubMesh const fvMesh& meshTarget, const HashTable& patchMap, const wordList& cuttingPatches, - const meshToMesh::interpolationMethod& mapMethod, + const word& mapMethod, + const word& AMIMapMethod, const bool subtract, const HashSet& selectedFields, const bool noLagrangian @@ -93,6 +95,7 @@ void mapSubMesh meshSource, meshTarget, mapMethod, + AMIMapMethod, patchMap, cuttingPatches ); @@ -186,6 +189,12 @@ int main(int argc, char *argv[]) "word", "specify the mapping method (direct|mapNearest|cellVolumeWeight)" ); + argList::addOption + ( + "patchMapMethod", + "word", + "specify the patch mapping method (direct|mapNearest|faceAreaWeight)" + ); argList::addBoolOption ( "subtract", @@ -231,17 +240,50 @@ int main(int argc, char *argv[]) const bool consistent = args.optionFound("consistent"); - meshToMesh::interpolationMethod mapMethod = - meshToMesh::imCellVolumeWeight; - if (args.optionFound("mapMethod")) + word mapMethod = meshToMesh::interpolationMethodNames_ + [ + meshToMesh::imCellVolumeWeight + ]; + + if (args.optionReadIfPresent("mapMethod", mapMethod)) { - mapMethod = meshToMesh::interpolationMethodNames_[args["mapMethod"]]; - - Info<< "Mapping method: " - << meshToMesh::interpolationMethodNames_[mapMethod] << endl; + Info<< "Mapping method: " << mapMethod << endl; } + + word patchMapMethod; + if (meshToMesh::interpolationMethodNames_.found(mapMethod)) + { + // Lookup corresponding AMI method + meshToMesh::interpolationMethod method = + meshToMesh::interpolationMethodNames_[mapMethod]; + + patchMapMethod = AMIPatchToPatchInterpolation::interpolationMethodToWord + ( + meshToMesh::interpolationMethodAMI(method) + ); + } + + // Optionally override + if (args.optionFound("patchMapMethod")) + { + patchMapMethod = args["patchMapMethod"]; + + Info<< "Patch mapping method: " << patchMapMethod << endl; + } + + + if (patchMapMethod.empty()) + { + FatalErrorIn(args.executable()) + << "No valid patchMapMethod for method " << mapMethod + << ". Please supply one through the 'patchMapMethod' option" + << exit(FatalError); + } + + + const bool subtract = args.optionFound("subtract"); if (subtract) { @@ -314,6 +356,7 @@ int main(int argc, char *argv[]) meshSource, meshTarget, mapMethod, + patchMapMethod, subtract, selectedFields, noLagrangian @@ -328,6 +371,7 @@ int main(int argc, char *argv[]) patchMap, addProcessorPatches(meshTarget, cuttingPatches), mapMethod, + patchMapMethod, subtract, selectedFields, noLagrangian diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C index ea79e0699c..58fb989e5c 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C @@ -536,66 +536,13 @@ void Foam::AMIInterpolation::agglomerate } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - template -Foam::AMIInterpolation::AMIInterpolation +void Foam::AMIInterpolation::constructFromSurface ( const SourcePatch& srcPatch, const TargetPatch& tgtPatch, - const faceAreaIntersect::triangulationMode& triMode, - const bool requireMatch, - const interpolationMethod& method, - const scalar lowWeightCorrection, - const bool reverseTarget + const autoPtr& surfPtr ) -: - method_(method), - reverseTarget_(reverseTarget), - requireMatch_(requireMatch), - singlePatchProc_(-999), - lowWeightCorrection_(lowWeightCorrection), - srcAddress_(), - srcWeights_(), - srcWeightsSum_(), - tgtAddress_(), - tgtWeights_(), - tgtWeightsSum_(), - triMode_(triMode), - srcMapPtr_(NULL), - tgtMapPtr_(NULL) -{ - update(srcPatch, tgtPatch); -} - - -template -Foam::AMIInterpolation::AMIInterpolation -( - const SourcePatch& srcPatch, - const TargetPatch& tgtPatch, - const autoPtr& surfPtr, - const faceAreaIntersect::triangulationMode& triMode, - const bool requireMatch, - const interpolationMethod& method, - const scalar lowWeightCorrection, - const bool reverseTarget -) -: - method_(method), - reverseTarget_(reverseTarget), - requireMatch_(requireMatch), - singlePatchProc_(-999), - lowWeightCorrection_(lowWeightCorrection), - srcAddress_(), - srcWeights_(), - srcWeightsSum_(), - tgtAddress_(), - tgtWeights_(), - tgtWeightsSum_(), - triMode_(triMode), - srcMapPtr_(NULL), - tgtMapPtr_(NULL) { if (surfPtr.valid()) { @@ -658,6 +605,134 @@ Foam::AMIInterpolation::AMIInterpolation } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::AMIInterpolation::AMIInterpolation +( + const SourcePatch& srcPatch, + const TargetPatch& tgtPatch, + const faceAreaIntersect::triangulationMode& triMode, + const bool requireMatch, + const interpolationMethod& method, + const scalar lowWeightCorrection, + const bool reverseTarget +) +: + methodName_(interpolationMethodToWord(method)), + reverseTarget_(reverseTarget), + requireMatch_(requireMatch), + singlePatchProc_(-999), + lowWeightCorrection_(lowWeightCorrection), + srcAddress_(), + srcWeights_(), + srcWeightsSum_(), + tgtAddress_(), + tgtWeights_(), + tgtWeightsSum_(), + triMode_(triMode), + srcMapPtr_(NULL), + tgtMapPtr_(NULL) +{ + update(srcPatch, tgtPatch); +} + + +template +Foam::AMIInterpolation::AMIInterpolation +( + const SourcePatch& srcPatch, + const TargetPatch& tgtPatch, + const faceAreaIntersect::triangulationMode& triMode, + const bool requireMatch, + const word& methodName, + const scalar lowWeightCorrection, + const bool reverseTarget +) +: + methodName_(methodName), + reverseTarget_(reverseTarget), + requireMatch_(requireMatch), + singlePatchProc_(-999), + lowWeightCorrection_(lowWeightCorrection), + srcAddress_(), + srcWeights_(), + srcWeightsSum_(), + tgtAddress_(), + tgtWeights_(), + tgtWeightsSum_(), + triMode_(triMode), + srcMapPtr_(NULL), + tgtMapPtr_(NULL) +{ + update(srcPatch, tgtPatch); +} + + +template +Foam::AMIInterpolation::AMIInterpolation +( + const SourcePatch& srcPatch, + const TargetPatch& tgtPatch, + const autoPtr& surfPtr, + const faceAreaIntersect::triangulationMode& triMode, + const bool requireMatch, + const interpolationMethod& method, + const scalar lowWeightCorrection, + const bool reverseTarget +) +: + methodName_(interpolationMethodToWord(method)), + reverseTarget_(reverseTarget), + requireMatch_(requireMatch), + singlePatchProc_(-999), + lowWeightCorrection_(lowWeightCorrection), + srcAddress_(), + srcWeights_(), + srcWeightsSum_(), + tgtAddress_(), + tgtWeights_(), + tgtWeightsSum_(), + triMode_(triMode), + srcMapPtr_(NULL), + tgtMapPtr_(NULL) +{ + constructFromSurface(srcPatch, tgtPatch, surfPtr); +} + + +template +Foam::AMIInterpolation::AMIInterpolation +( + const SourcePatch& srcPatch, + const TargetPatch& tgtPatch, + const autoPtr& surfPtr, + const faceAreaIntersect::triangulationMode& triMode, + const bool requireMatch, + const word& methodName, + const scalar lowWeightCorrection, + const bool reverseTarget +) +: + methodName_(methodName), + reverseTarget_(reverseTarget), + requireMatch_(requireMatch), + singlePatchProc_(-999), + lowWeightCorrection_(lowWeightCorrection), + srcAddress_(), + srcWeights_(), + srcWeightsSum_(), + tgtAddress_(), + tgtWeights_(), + tgtWeightsSum_(), + triMode_(triMode), + srcMapPtr_(NULL), + tgtMapPtr_(NULL) +{ + constructFromSurface(srcPatch, tgtPatch, surfPtr); +} + + template Foam::AMIInterpolation::AMIInterpolation ( @@ -666,7 +741,7 @@ Foam::AMIInterpolation::AMIInterpolation const labelList& targetRestrictAddressing ) : - method_(fineAMI.method_), + methodName_(fineAMI.methodName_), reverseTarget_(fineAMI.reverseTarget_), requireMatch_(fineAMI.requireMatch_), singlePatchProc_(fineAMI.singlePatchProc_), @@ -883,7 +958,7 @@ void Foam::AMIInterpolation::update ( AMIMethod::New ( - interpolationMethodToWord(method_), + methodName_, srcPatch, newTgtPatch, srcMagSf_, @@ -1000,7 +1075,7 @@ void Foam::AMIInterpolation::update ( AMIMethod::New ( - interpolationMethodToWord(method_), + methodName_, srcPatch, tgtPatch, srcMagSf_, diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H index 7dbacd9efa..27d077f126 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H @@ -110,7 +110,7 @@ private: // Private data //- Interpolation method - interpolationMethod method_; + const word methodName_; //- Flag to indicate that the two patches are co-directional and // that the orientation of the target patch should be reversed @@ -250,7 +250,7 @@ private: ); - // Constructor helper + // Constructor helpers static void agglomerate ( @@ -269,6 +269,12 @@ private: autoPtr& tgtMap ); + void constructFromSurface + ( + const SourcePatch& srcPatch, + const TargetPatch& tgtPatch, + const autoPtr& surfPtr + ); public: @@ -286,6 +292,19 @@ public: const bool reverseTarget = false ); + //- Construct from components + AMIInterpolation + ( + const SourcePatch& srcPatch, + const TargetPatch& tgtPatch, + const faceAreaIntersect::triangulationMode& triMode, + const bool requireMatch = true, + const word& methodName = + interpolationMethodToWord(imFaceAreaWeight), + const scalar lowWeightCorrection = -1, + const bool reverseTarget = false + ); + //- Construct from components, with projection surface AMIInterpolation ( @@ -299,6 +318,20 @@ public: const bool reverseTarget = false ); + //- Construct from components, with projection surface + AMIInterpolation + ( + const SourcePatch& srcPatch, + const TargetPatch& tgtPatch, + const autoPtr& surf, + const faceAreaIntersect::triangulationMode& triMode, + const bool requireMatch = true, + const word& methodName = + interpolationMethodToWord(imFaceAreaWeight), + const scalar lowWeightCorrection = -1, + const bool reverseTarget = false + ); + //- Construct from agglomeration of AMIInterpolation. Agglomeration // passed in as new coarse size and addressing from fine from coarse AMIInterpolation diff --git a/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.C b/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.C index 2b2b7e978d..91c998ce4c 100644 --- a/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.C +++ b/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.C @@ -119,6 +119,7 @@ void Foam::meshToMesh::normaliseWeights void Foam::meshToMesh::calcAddressing ( + const word& methodName, const polyMesh& src, const polyMesh& tgt ) @@ -127,7 +128,7 @@ void Foam::meshToMesh::calcAddressing ( meshToMeshMethod::New ( - interpolationMethodNames_[method_], + methodName, src, tgt ) @@ -150,11 +151,11 @@ void Foam::meshToMesh::calcAddressing } -void Foam::meshToMesh::calculate() +void Foam::meshToMesh::calculate(const word& methodName) { Info<< "Creating mesh-to-mesh addressing for " << srcRegion_.name() << " and " << tgtRegion_.name() << " regions using " - << interpolationMethodNames_[method_] << endl; + << methodName << endl; singleMeshProc_ = calcDistribution(srcRegion_, tgtRegion_); @@ -241,7 +242,7 @@ void Foam::meshToMesh::calculate() } } - calcAddressing(srcRegion_, newTgt); + calcAddressing(methodName, srcRegion_, newTgt); // per source cell the target cell address in newTgt mesh forAll(srcToTgtCellAddr_, i) @@ -320,7 +321,7 @@ void Foam::meshToMesh::calculate() } else { - calcAddressing(srcRegion_, tgtRegion_); + calcAddressing(methodName, srcRegion_, tgtRegion_); normaliseWeights ( @@ -342,12 +343,9 @@ void Foam::meshToMesh::calculate() Foam::AMIPatchToPatchInterpolation::interpolationMethod -Foam::meshToMesh::interpolationMethodAMI -( - const interpolationMethod method -) const +Foam::meshToMesh::interpolationMethodAMI(const interpolationMethod method) { - switch (method_) + switch (method) { case imDirect: { @@ -374,7 +372,7 @@ Foam::meshToMesh::interpolationMethodAMI "const interpolationMethod method" ") const" ) - << "Unhandled enumeration " << method_ + << "Unhandled enumeration " << method << abort(FatalError); } } @@ -383,90 +381,66 @@ Foam::meshToMesh::interpolationMethodAMI } -const Foam::PtrList& -Foam::meshToMesh::patchAMIs() const +void Foam::meshToMesh::calculatePatchAMIs(const word& AMIMethodName) { - if (patchAMIs_.empty()) + if (!patchAMIs_.empty()) { - const word amiMethod = - AMIPatchToPatchInterpolation::interpolationMethodToWord - ( - interpolationMethodAMI(method_) - ); - - patchAMIs_.setSize(srcPatchID_.size()); - - forAll(srcPatchID_, i) - { - label srcPatchI = srcPatchID_[i]; - label tgtPatchI = tgtPatchID_[i]; - - const polyPatch& srcPP = srcRegion_.boundaryMesh()[srcPatchI]; - const polyPatch& tgtPP = tgtRegion_.boundaryMesh()[tgtPatchI]; - - Info<< "Creating AMI between source patch " << srcPP.name() - << " and target patch " << tgtPP.name() - << " using " << amiMethod - << endl; - - Info<< incrIndent; - - patchAMIs_.set - ( - i, - new AMIPatchToPatchInterpolation - ( - srcPP, - tgtPP, - faceAreaIntersect::tmMesh, - false, - interpolationMethodAMI(method_), - -1, - true // flip target patch since patch normals are aligned - ) - ); - - Info<< decrIndent; - } + FatalErrorIn("meshToMesh::calculatePatchAMIs()") + << "patch AMI already calculated" + << exit(FatalError); } - return patchAMIs_; + patchAMIs_.setSize(srcPatchID_.size()); + + forAll(srcPatchID_, i) + { + label srcPatchI = srcPatchID_[i]; + label tgtPatchI = tgtPatchID_[i]; + + const polyPatch& srcPP = srcRegion_.boundaryMesh()[srcPatchI]; + const polyPatch& tgtPP = tgtRegion_.boundaryMesh()[tgtPatchI]; + + Info<< "Creating AMI between source patch " << srcPP.name() + << " and target patch " << tgtPP.name() + << " using " << AMIMethodName + << endl; + + Info<< incrIndent; + + patchAMIs_.set + ( + i, + new AMIPatchToPatchInterpolation + ( + srcPP, + tgtPP, + faceAreaIntersect::tmMesh, + false, + AMIMethodName, + -1, + true // flip target patch since patch normals are aligned + ) + ); + + Info<< decrIndent; + } } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::meshToMesh::meshToMesh +void Foam::meshToMesh::constructNoCuttingPatches ( - const polyMesh& src, - const polyMesh& tgt, - const interpolationMethod& method, - bool interpAllPatches + const word& methodName, + const word& AMIMethodName, + const bool interpAllPatches ) -: - srcRegion_(src), - tgtRegion_(tgt), - srcPatchID_(), - tgtPatchID_(), - patchAMIs_(), - cuttingPatches_(), - srcToTgtCellAddr_(), - tgtToSrcCellAddr_(), - srcToTgtCellWght_(), - tgtToSrcCellWght_(), - method_(method), - V_(0.0), - singleMeshProc_(-1), - srcMapPtr_(NULL), - tgtMapPtr_(NULL) { if (interpAllPatches) { - const polyBoundaryMesh& srcBM = src.boundaryMesh(); - const polyBoundaryMesh& tgtBM = tgt.boundaryMesh(); + const polyBoundaryMesh& srcBM = srcRegion_.boundaryMesh(); + const polyBoundaryMesh& tgtBM = tgtRegion_.boundaryMesh(); - DynamicList