diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H index 8e8a9607d7..ac717307ab 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H @@ -61,7 +61,7 @@ SourceFiles #include "indexedOctree.H" #include "treeDataPrimitivePatch.H" #include "runTimeSelectionTables.H" - +#include "lowWeightCorrectionBase.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -512,39 +512,21 @@ public: //- Normalise the weights void normaliseWeights(const bool conformal, const bool output); + //- Remove source face connection + void removeSourceConnection(const label facei); + + //- Remove target face connection + void removeTargetConnection(const label facei); + // Evaluation // Low-level - //- Weighted sum of contributions + //- Interpolate with supplied op to combine existing value + //- with remote value and weight template - static void weightedSum - ( - const scalar lowWeightCorrection, - const labelListList& allSlots, - const scalarListList& allWeights, - const scalarField& weightsSum, - const UList& fld, - const CombineOp& cop, - List& result, - const UList& defaultValues - ); - - //- Weighted sum of contributions - template - void weightedSum - ( - const bool interpolateToSource, - const UList& fld, - List& result, - const UList& defaultValues - ) const; - - //- Interpolate from target to source with supplied op - //- to combine existing value with remote value and weight - template - void interpolateToSource + void interpolate ( const UList& fld, const CombineOp& cop, @@ -552,48 +534,18 @@ public: const UList& defaultValues = UList::null() ) const; - //- Interpolate from source to target with supplied op - //- to combine existing value with remote value and weight - template - void interpolateToTarget - ( - const UList& fld, - const CombineOp& cop, - List& result, - const UList& defaultValues = UList::null() - ) const; - - - //- Interpolate from target to source with supplied op + //- Interpolate with supplied op template - tmp> interpolateToSource + tmp> interpolate ( const Field& fld, const CombineOp& cop, const UList& defaultValues = UList::null() ) const; - //- Interpolate from target tmp field to source with supplied op + //- Interpolate with supplied op template - tmp> interpolateToSource - ( - const tmp>& tFld, - const CombineOp& cop, - const UList& defaultValues = UList::null() - ) const; - - //- Interpolate from source to target with supplied op - template - tmp> interpolateToTarget - ( - const Field& fld, - const CombineOp& cop, - const UList& defaultValues = UList::null() - ) const; - - //- Interpolate from source tmp field to target with supplied op - template - tmp> interpolateToTarget + tmp> interpolate ( const tmp>& tFld, const CombineOp& cop, @@ -605,7 +557,9 @@ public: tmp> interpolateToSource ( const Field& fld, - const UList& defaultValues = UList::null() + const UList& defaultValues = UList::null(), + const lowWeightCorrectionBase::option& lwOption = + lowWeightCorrectionBase::option::ASSIGN ) const; //- Interpolate from target tmp field @@ -613,7 +567,9 @@ public: tmp> interpolateToSource ( const tmp>& tFld, - const UList& defaultValues = UList::null() + const UList& defaultValues = UList::null(), + const lowWeightCorrectionBase::option& lwOption = + lowWeightCorrectionBase::option::ASSIGN ) const; //- Interpolate from source to target @@ -621,7 +577,9 @@ public: tmp> interpolateToTarget ( const Field& fld, - const UList& defaultValues = UList::null() + const UList& defaultValues = UList::null(), + const lowWeightCorrectionBase::option& lwOption = + lowWeightCorrectionBase::option::ASSIGN ) const; //- Interpolate from source tmp field @@ -629,7 +587,9 @@ public: tmp> interpolateToTarget ( const tmp>& tFld, - const UList& defaultValues = UList::null() + const UList& defaultValues = UList::null(), + const lowWeightCorrectionBase::option& lwOption = + lowWeightCorrectionBase::option::ASSIGN ) const; diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationTemplates.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationTemplates.C index 535b35ca56..c78214f6f5 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationTemplates.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationTemplates.C @@ -28,266 +28,80 @@ License #include "profiling.H" #include "mapDistribute.H" +#include "AMIFieldOps.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template -void Foam::AMIInterpolation::weightedSum +void Foam::AMIInterpolation::interpolate ( - const scalar lowWeightCorrection, - const labelListList& allSlots, - const scalarListList& allWeights, - const scalarField& weightsSum, const UList& fld, const CombineOp& cop, List& result, const UList& defaultValues -) +) const { - if (lowWeightCorrection > 0) - { - forAll(result, facei) - { - if (weightsSum[facei] < lowWeightCorrection) - { - result[facei] = defaultValues[facei]; - } - else - { - const labelList& slots = allSlots[facei]; - const scalarList& weights = allWeights[facei]; + addProfiling(ami, "AMIInterpolation::interpolate"); - forAll(slots, i) - { - cop(result[facei], facei, fld[slots[i]], weights[i]); - } - } - } + label inSize = cop.toSource() ? tgtAddress_.size() : srcAddress_.size(); + + if (fld.size() != inSize) + { + FatalErrorInFunction + << "Supplied field size is not equal to expected field size (" + << inSize << ")" << nl + << " source patch = " << srcAddress_.size() << nl + << " target patch = " << tgtAddress_.size() << nl + << " supplied field = " << fld.size() + << abort(FatalError); + } + + + label outSize = cop.toSource() ? srcAddress_.size() : tgtAddress_.size(); + result.resize_nocopy(outSize); + + if (distributed()) + { + const auto& map = cop.toSource() ? tgtMapPtr_() : srcMapPtr_(); + List work = fld; // deep copy + map.distribute(work); + + // Apply interpolation + cop(result, work, defaultValues); } else { - forAll(result, facei) - { - const labelList& slots = allSlots[facei]; - const scalarList& weights = allWeights[facei]; - - forAll(slots, i) - { - cop(result[facei], facei, fld[slots[i]], weights[i]); - } - } + // Apply interpolation + cop(result, fld, defaultValues); } } -template -void Foam::AMIInterpolation::weightedSum -( - const bool interpolateToSource, - const UList& fld, - List& result, - const UList& defaultValues -) const -{ - weightedSum - ( - lowWeightCorrection_, - (interpolateToSource ? srcAddress_ : tgtAddress_), - (interpolateToSource ? srcWeights_ : tgtWeights_), - (interpolateToSource ? srcWeightsSum_ : tgtWeightsSum_), - fld, - multiplyWeightedOp>(plusEqOp()), - result, - defaultValues - ); -} - - template -void Foam::AMIInterpolation::interpolateToTarget -( - const UList& fld, - const CombineOp& cop, - List& result, - const UList& defaultValues -) const -{ - addProfiling(ami, "AMIInterpolation::interpolateToTarget"); - - if (fld.size() != srcAddress_.size()) - { - FatalErrorInFunction - << "Supplied field size is not equal to source patch size" << nl - << " source patch = " << srcAddress_.size() << nl - << " target patch = " << tgtAddress_.size() << nl - << " supplied field = " << fld.size() - << abort(FatalError); - } - else if - ( - (lowWeightCorrection_ > 0) - && (defaultValues.size() != tgtAddress_.size()) - ) - { - FatalErrorInFunction - << "Employing default values when sum of weights falls below " - << lowWeightCorrection_ - << " but supplied default field size is not equal to target " - << "patch size" << nl - << " default values = " << defaultValues.size() << nl - << " target patch = " << tgtAddress_.size() << nl - << abort(FatalError); - } - - result.setSize(tgtAddress_.size()); - List work; - - if (distributed()) - { - const mapDistribute& map = srcMapPtr_(); - work = fld; // deep copy - map.distribute(work); - } - - weightedSum - ( - lowWeightCorrection_, - tgtAddress_, - tgtWeights_, - tgtWeightsSum_, - (distributed() ? work : fld), - cop, - result, - defaultValues - ); -} - - -template -void Foam::AMIInterpolation::interpolateToSource -( - const UList& fld, - const CombineOp& cop, - List& result, - const UList& defaultValues -) const -{ - addProfiling(ami, "AMIInterpolation::interpolateToSource"); - - if (fld.size() != tgtAddress_.size()) - { - FatalErrorInFunction - << "Supplied field size is not equal to target patch size" << nl - << " source patch = " << srcAddress_.size() << nl - << " target patch = " << tgtAddress_.size() << nl - << " supplied field = " << fld.size() - << abort(FatalError); - } - else if - ( - (lowWeightCorrection_ > 0) - && (defaultValues.size() != srcAddress_.size()) - ) - { - FatalErrorInFunction - << "Employing default values when sum of weights falls below " - << lowWeightCorrection_ - << " but number of default values is not equal to source " - << "patch size" << nl - << " default values = " << defaultValues.size() << nl - << " source patch = " << srcAddress_.size() << nl - << abort(FatalError); - } - - result.setSize(srcAddress_.size()); - List work; - - if (distributed()) - { - const mapDistribute& map = tgtMapPtr_(); - work = fld; // deep copy - map.distribute(work); - } - - weightedSum - ( - lowWeightCorrection_, - srcAddress_, - srcWeights_, - srcWeightsSum_, - (distributed() ? work : fld), - cop, - result, - defaultValues - ); -} - - -template -Foam::tmp> Foam::AMIInterpolation::interpolateToSource +Foam::tmp> Foam::AMIInterpolation::interpolate ( const Field& fld, const CombineOp& cop, const UList& defaultValues ) const { - auto tresult = tmp>::New(srcAddress_.size(), Zero); + auto tresult = tmp>::New(); - interpolateToSource - ( - fld, - multiplyWeightedOp(cop), - tresult.ref(), - defaultValues - ); + interpolate(fld, cop, tresult.ref(), defaultValues); return tresult; } template -Foam::tmp> Foam::AMIInterpolation::interpolateToSource +Foam::tmp> Foam::AMIInterpolation::interpolate ( const tmp>& tFld, const CombineOp& cop, const UList& defaultValues ) const { - return interpolateToSource(tFld(), cop, defaultValues); -} - - -template -Foam::tmp> Foam::AMIInterpolation::interpolateToTarget -( - const Field& fld, - const CombineOp& cop, - const UList& defaultValues -) const -{ - auto tresult = tmp>::New(tgtAddress_.size(), Zero); - - interpolateToTarget - ( - fld, - multiplyWeightedOp(cop), - tresult.ref(), - defaultValues - ); - - return tresult; -} - - -template -Foam::tmp> Foam::AMIInterpolation::interpolateToTarget -( - const tmp>& tFld, - const CombineOp& cop, - const UList& defaultValues -) const -{ - return interpolateToTarget(tFld(), cop, defaultValues); + return interpolate(tFld(), cop, defaultValues); } @@ -295,10 +109,13 @@ template Foam::tmp> Foam::AMIInterpolation::interpolateToSource ( const Field& fld, - const UList& defaultValues + const UList& defaultValues, + const lowWeightCorrectionBase::option& lwOption ) const { - return interpolateToSource(fld, plusEqOp(), defaultValues); + AMICorrectedMultiplyWeightedOp cop(*this, true, lwOption); + + return interpolate(fld, cop, defaultValues); } @@ -306,10 +123,11 @@ template Foam::tmp> Foam::AMIInterpolation::interpolateToSource ( const tmp>& tFld, - const UList& defaultValues + const UList& defaultValues, + const lowWeightCorrectionBase::option& lwOption ) const { - return interpolateToSource(tFld(), plusEqOp(), defaultValues); + return interpolateToSource(tFld(), defaultValues, lwOption); } @@ -317,10 +135,13 @@ template Foam::tmp> Foam::AMIInterpolation::interpolateToTarget ( const Field& fld, - const UList& defaultValues + const UList& defaultValues, + const lowWeightCorrectionBase::option& lwOption ) const { - return interpolateToTarget(fld, plusEqOp(), defaultValues); + AMICorrectedMultiplyWeightedOp cop(*this, false, lwOption); + + return interpolate(fld, cop, defaultValues); } @@ -328,10 +149,11 @@ template Foam::tmp> Foam::AMIInterpolation::interpolateToTarget ( const tmp>& tFld, - const UList& defaultValues + const UList& defaultValues, + const lowWeightCorrectionBase::option& lwOption ) const { - return interpolateToTarget(tFld(), plusEqOp(), defaultValues); + return interpolateToTarget(tFld(), defaultValues, lwOption); }