ENH: Propagated AMI API code changes across dependant code

This commit is contained in:
Andrew Heather 2024-05-03 17:26:00 +01:00
parent de8dd7a5cf
commit 1307c4eb2e
10 changed files with 213 additions and 143 deletions

View File

@ -29,6 +29,7 @@ License
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "faceAreaWeightAMI.H" #include "faceAreaWeightAMI.H"
#include "turbulentDFSEMInletFvPatchVectorField.H" #include "turbulentDFSEMInletFvPatchVectorField.H"
#include "AMIFieldOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -82,14 +83,8 @@ void Foam::turbulentDigitalFilterInletFvPatchField<Type>::mapL
} }
// Map two-point correlations (integral scales) // Map two-point correlations (integral scales)
plusEqOp<Type> cop; AMIMultiplyWeightedOp<Type> cop(AMIPtr_(), true);
AMIPtr_->interpolateToSource AMIPtr_->interpolate(sourceFld, cop, fld, UList<Type>::null());
(
sourceFld,
multiplyWeightedOp<Type, plusEqOp<Type>>(cop),
fld,
UList<Type>::null()
);
// Map forward-stepwise method correlations if requested // Map forward-stepwise method correlations if requested
if (L_.fsm()) if (L_.fsm())

View File

@ -100,12 +100,19 @@ void Foam::cyclicACMIFvPatch::makeWeights(scalarField& w) const
// These deltas are of the cyclic part alone - they are // These deltas are of the cyclic part alone - they are
// not affected by the amount of overlap with the nonOverlapPatch // not affected by the amount of overlap with the nonOverlapPatch
scalarField nbrDeltas scalarField nbrDeltas;
const auto& AMI = owner() ? this->AMI() : nbrPatch.AMI();
// Multiply-weighted op - no low weight correction
auto cop = AMIMultiplyWeightedOp<scalar>(AMI, owner());
AMI.interpolate
( (
interpolate (nbrPatch.nf() & nbrPatch.coupledFvPatch::delta())(),
( cop,
nbrPatch.nf() & nbrPatch.coupledFvPatch::delta() nbrDeltas,
) UList<scalar>()
); );
const scalar tol = cyclicACMIPolyPatch::tolerance(); const scalar tol = cyclicACMIPolyPatch::tolerance();
@ -244,31 +251,35 @@ Foam::tmp<Foam::vectorField> Foam::cyclicACMIFvPatch::delta() const
const vectorField patchD(coupledFvPatch::delta()); const vectorField patchD(coupledFvPatch::delta());
vectorField nbrPatchD(interpolate(nbrPatch.coupledFvPatch::delta())); const auto& AMI = owner() ? this->AMI() : nbrPatch.AMI();
// Multiply-weighted op - no low weight correction
auto cop = AMIMultiplyWeightedOp<vector>(AMI, owner());
vectorField nbrPatchD;
AMI.interpolate
(
nbrPatch.coupledFvPatch::delta()(),
cop,
nbrPatchD,
UList<vector>()
);
// Do the transformation if necessary
if (!parallel())
{
transform(nbrPatchD, forwardT()[0], nbrPatchD);
}
auto tpdv = tmp<vectorField>::New(patchD.size()); auto tpdv = tmp<vectorField>::New(patchD.size());
vectorField& pdv = tpdv.ref(); vectorField& pdv = tpdv.ref();
// do the transformation if necessary forAll(patchD, facei)
if (parallel())
{ {
forAll(patchD, facei) const vector& ddi = patchD[facei];
{ const vector& dni = nbrPatchD[facei];
const vector& ddi = patchD[facei]; pdv[facei] = ddi - dni;
const vector& dni = nbrPatchD[facei]; pdv[facei] = ddi - dni;
pdv[facei] = ddi - dni;
}
}
else
{
forAll(patchD, facei)
{
const vector& ddi = patchD[facei];
const vector& dni = nbrPatchD[facei];
pdv[facei] = ddi - transform(forwardT()[0], dni);
}
} }
return tpdv; return tpdv;

View File

@ -251,7 +251,7 @@ public:
localFld, localFld,
requests, requests,
recvBuffers, recvBuffers,
UList<Type>() UList<Type>::null()
); );
} }

View File

@ -97,32 +97,50 @@ void Foam::cyclicAMIFvPatch::makeWeights(scalarField& w) const
{ {
const cyclicAMIFvPatch& nbrPatch = neighbFvPatch(); const cyclicAMIFvPatch& nbrPatch = neighbFvPatch();
const scalarField deltas(nf() & coupledFvPatch::delta()); const auto& AMI = owner() ? this->AMI() : nbrPatch.AMI();
tmp<scalarField> tnbrDeltas; auto tnbrDeltas = tmp<scalarField>::New();
if (applyLowWeightCorrection()) if (applyLowWeightCorrection())
{ {
tnbrDeltas = // Use 'assign' correction for geometric interpolation
interpolate auto cop = AMICorrectedMultiplyWeightedOp<scalar>
( (
nbrPatch.nf() & nbrPatch.coupledFvPatch::delta(), AMI,
scalarField(this->size(), 1.0) owner(),
); lowWeightCorrectionBase::option::ASSIGN
);
// Faces with invalid interpolation weights converted to one-sided
AMI.interpolate
(
(nbrPatch.nf() & nbrPatch.coupledFvPatch::delta())(),
cop,
tnbrDeltas.ref(),
scalarList(this->size(), 1.0)
);
} }
else else
{ {
tnbrDeltas = // Multiply-weighted op - no low weight correction
interpolate(nbrPatch.nf() & nbrPatch.coupledFvPatch::delta()); auto cop = AMIMultiplyWeightedOp<scalar>(AMI, owner());
AMI.interpolate
(
(nbrPatch.nf() & nbrPatch.coupledFvPatch::delta())(),
cop,
tnbrDeltas.ref(),
UList<scalar>::null()
);
} }
const scalarField& nbrDeltas = tnbrDeltas(); const scalarField& nbrDeltas = tnbrDeltas();
const scalarField deltas(nf() & coupledFvPatch::delta());
forAll(deltas, facei) forAll(deltas, facei)
{ {
// Note use of mag // Note use of mag
scalar di = mag(deltas[facei]); scalar di = mag(deltas[facei]);
scalar dni = mag(nbrDeltas[facei]); scalar dni = mag(nbrDeltas[facei]);
w[facei] = dni/(di + dni); w[facei] = dni/(di + dni);
} }
} }
@ -162,46 +180,58 @@ Foam::tmp<Foam::vectorField> Foam::cyclicAMIFvPatch::delta() const
{ {
const vectorField patchD(coupledFvPatch::delta()); const vectorField patchD(coupledFvPatch::delta());
tmp<vectorField> tnbrPatchD; const auto& AMI = owner() ? this->AMI() : nbrPatch.AMI();
auto tnbrPatchD = tmp<vectorField>::New();
if (applyLowWeightCorrection()) if (applyLowWeightCorrection())
{ {
tnbrPatchD = // Use 'assign' correction for geometric interpolation
interpolate auto cop = AMICorrectedMultiplyWeightedOp<vector>
( (
nbrPatch.coupledFvPatch::delta(), AMI,
vectorField(this->size(), Zero) owner(),
); lowWeightCorrectionBase::option::ASSIGN
);
// Faces with invalid interpolation weights converted to one-sided
AMI.interpolate
(
nbrPatch.coupledFvPatch::delta()(),
cop,
tnbrPatchD.ref(),
vectorField(this->size(), Zero)
);
} }
else else
{ {
tnbrPatchD = interpolate(nbrPatch.coupledFvPatch::delta()); // Multiply-weighted op - no low weight correction
auto cop = AMIMultiplyWeightedOp<vector>(AMI, owner());
AMI.interpolate
(
nbrPatch.coupledFvPatch::delta()(),
cop,
tnbrPatchD.ref(),
UList<vector>::null()
);
} }
const vectorField& nbrPatchD = tnbrPatchD(); vectorField& nbrPatchD = tnbrPatchD.ref();
// Do the transformation if necessary
if (!parallel())
{
transform(nbrPatchD, forwardT()[0], nbrPatchD);
}
auto tpdv = tmp<vectorField>::New(patchD.size()); auto tpdv = tmp<vectorField>::New(patchD.size());
vectorField& pdv = tpdv.ref(); vectorField& pdv = tpdv.ref();
// do the transformation if necessary forAll(patchD, facei)
if (parallel())
{ {
forAll(patchD, facei) const vector& ddi = patchD[facei];
{ const vector& dni = nbrPatchD[facei];
const vector& ddi = patchD[facei]; pdv[facei] = ddi - dni;
const vector& dni = nbrPatchD[facei];
pdv[facei] = ddi - dni;
}
}
else
{
forAll(patchD, facei)
{
const vector& ddi = patchD[facei];
const vector& dni = nbrPatchD[facei];
pdv[facei] = ddi - transform(forwardT()[0], dni);
}
} }
return tpdv; return tpdv;

View File

@ -292,14 +292,15 @@ void Foam::cyclicACMIGAMGInterfaceField::updateInterfaceMatrix
recvRequests_.clear(); recvRequests_.clear();
solveScalarField pnf(faceCells.size(), Zero); solveScalarField pnf(faceCells.size(), Zero);
AMI.weightedSum
AMIMultiplyWeightedOp<solveScalar> cop
( (
cyclicACMIInterface_.owner(), AMI,
work, cyclicACMIInterface_.owner()
pnf, // result
solveScalarField::null()
); );
cop(pnf, work, solveScalarField::null());
// Add result using coefficients // Add result using coefficients
this->addToInternalField(result, !add, faceCells, coeffs, pnf); this->addToInternalField(result, !add, faceCells, coeffs, pnf);
} }

View File

@ -306,13 +306,14 @@ void Foam::cyclicAMIGAMGInterfaceField::updateInterfaceMatrix
recvRequests_.clear(); recvRequests_.clear();
solveScalarField pnf(faceCells.size(), Zero); solveScalarField pnf(faceCells.size(), Zero);
AMI.weightedSum
// Note: no low-weight correction
AMIMultiplyWeightedOp<solveScalar> cop
( (
cyclicAMIInterface_.owner(), AMI,
work, cyclicAMIInterface_.owner()
pnf, // result
defaultValues
); );
cop(pnf, work, defaultValues);
// Add result using coefficients // Add result using coefficients
this->addToInternalField(result, !add, faceCells, coeffs, pnf); this->addToInternalField(result, !add, faceCells, coeffs, pnf);
@ -329,13 +330,14 @@ void Foam::cyclicAMIGAMGInterfaceField::updateInterfaceMatrix
transformCoupleField(work, cmpt); transformCoupleField(work, cmpt);
solveScalarField pnf(faceCells.size(), Zero); solveScalarField pnf(faceCells.size(), Zero);
AMI.weightedSum
// Note: no low-weight correction
AMIMultiplyWeightedOp<solveScalar> cop
( (
cyclicAMIInterface_.owner(), AMI,
work, cyclicAMIInterface_.owner()
pnf, // result
defaultValues
); );
cop(pnf, work, defaultValues);
// Add result using coefficients // Add result using coefficients
this->addToInternalField(result, !add, faceCells, coeffs, pnf); this->addToInternalField(result, !add, faceCells, coeffs, pnf);

View File

@ -38,6 +38,7 @@ License
#include "typeInfo.H" #include "typeInfo.H"
#include "SubField.H" #include "SubField.H"
#include "globalMeshData.H" #include "globalMeshData.H"
#include "AMIFieldOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -95,6 +96,73 @@ namespace Foam
} }
} }
}; };
// Combine operator for AMIInterpolation
template<class Type, class TrackingData>
class combineField
:
public AMIFieldOpBase
{
// Private Data
FaceCellWave<Type, TrackingData>& solver_;
const cyclicAMIPolyPatch& patch_;
public:
combineField
(
FaceCellWave<Type, TrackingData>& solver,
const cyclicAMIPolyPatch& patch
)
:
AMIFieldOpBase(patch.AMI(), patch.owner()),
solver_(solver),
patch_(patch)
{}
void operator()
(
List<Type>& result,
const UList<Type>& fld,
const UList<Type>& /* unused defaultValues */
) const
{
const auto& allSlots = address();
forAll(result, facei)
{
const labelList& slots = allSlots[facei];
for (const label sloti : slots)
{
if (fld[sloti].valid(solver_.data()))
{
label meshFacei = -1;
if (patch_.owner())
{
meshFacei = patch_.start() + facei;
}
else
{
meshFacei =
patch_.neighbPatch().start() + facei;
}
result[facei].updateFace
(
solver_.mesh(),
meshFacei,
fld[sloti],
solver_.propagationTol(),
solver_.data()
);
}
}
}
}
};
} }
@ -782,7 +850,7 @@ void Foam::FaceCellWave<Type, TrackingData>::handleAMICyclicPatches()
} }
// Transfer sendInfo to cycPatch // Transfer sendInfo to cycPatch
combine<Type, TrackingData> cmb(*this, cycPatch); combineField<Type, TrackingData> cmb(*this, cycPatch);
if (cycPatch.applyLowWeightCorrection()) if (cycPatch.applyLowWeightCorrection())
{ {

View File

@ -26,6 +26,9 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "AMIFieldOps.H"
template<class Type> template<class Type>
void Foam::mappedPatchBase::distribute(List<Type>& lst) const void Foam::mappedPatchBase::distribute(List<Type>& lst) const
{ {
@ -120,7 +123,9 @@ void Foam::mappedPatchBase::distribute
const label oldWarnComm = UPstream::commWarn(myComm); const label oldWarnComm = UPstream::commWarn(myComm);
const label oldWorldComm = UPstream::commWorld(myComm); const label oldWorldComm = UPstream::commWorld(myComm);
lst = interp.interpolateToSource(Field<Type>(std::move(lst)), cop); const auto op = AMIFieldOp<Type, CombineOp>(interp, cop, true);
lst = interp.interpolate(Field<Type>(std::move(lst)), op);
UPstream::commWarn(oldWarnComm); UPstream::commWarn(oldWarnComm);
UPstream::commWorld(oldWorldComm); UPstream::commWorld(oldWorldComm);
@ -206,7 +211,9 @@ void Foam::mappedPatchBase::reverseDistribute
const label oldWarnComm = UPstream::commWarn(myComm); const label oldWarnComm = UPstream::commWarn(myComm);
const label oldWorldComm = UPstream::commWorld(myComm); const label oldWorldComm = UPstream::commWorld(myComm);
lst = interp.interpolateToTarget(Field<Type>(std::move(lst)), cop); const auto op = AMIFieldOp<Type, CombineOp>(interp, false);
lst = interp.interpolate(Field<Type>(std::move(lst)), op);
UPstream::commWarn(oldWarnComm); UPstream::commWarn(oldWarnComm);
UPstream::commWorld(oldWorldComm); UPstream::commWorld(oldWorldComm);

View File

@ -78,44 +78,8 @@ void Foam::decompositionConstraint::getMinBoundaryValue
const labelList nbrDecomp(decomposition, nbrPp.faceCells()); const labelList nbrDecomp(decomposition, nbrPp.faceCells());
labelList thisDecomp(decomposition, cycPp.faceCells()); labelList thisDecomp(decomposition, cycPp.faceCells());
if (cycPp.owner()) AMIMinOp<label> cop(cycPp.AMI(), cycPp.owner());
{ cop(thisDecomp, nbrDecomp, thisDecomp);
cycPp.AMI().interpolateToSource
(
nbrDecomp,
[]
(
label& res,
const label facei,
const label& fld,
const scalar& w
)
{
res = min(res, fld);
},
thisDecomp,
thisDecomp // used in case of low-weight-corr
);
}
else
{
nbrPp.AMI().interpolateToTarget
(
nbrDecomp,
[]
(
label& res,
const label facei,
const label& fld,
const scalar& w
)
{
res = min(res, fld);
},
thisDecomp,
thisDecomp // used in case of low-weight-corr
);
}
forAll(thisDecomp, i) forAll(thisDecomp, i)
{ {

View File

@ -492,13 +492,9 @@ void Foam::meshToMesh::mapAndOpSrcToTgt
{ {
tgtField = Type(Zero); tgtField = Type(Zero);
AMI.interpolateToTarget const AMIMultiplyWeightedOp<Type, CombineOp> amicop(AMI, false);
(
srcField, AMI.interpolate(srcField, amicop, tgtField, UList<Type>::null());
multiplyWeightedOp<Type, CombineOp>(cop),
tgtField,
UList<Type>::null()
);
} }
@ -725,13 +721,9 @@ void Foam::meshToMesh::mapAndOpTgtToSrc
{ {
srcField = Type(Zero); srcField = Type(Zero);
AMI.interpolateToSource const AMIMultiplyWeightedOp<Type, CombineOp> amicop(AMI, true);
(
tgtField, AMI.interpolate(tgtField, amicop, srcField, UList<Type>::null());
multiplyWeightedOp<Type, CombineOp>(cop),
srcField,
UList<Type>::null()
);
} }