WIP: AMI cache - further updates - TO SQUASH

This commit is contained in:
Andrew Heather
2025-07-14 16:19:38 +01:00
parent 47efb65ef9
commit cb2a89fe08
6 changed files with 62 additions and 55 deletions

View File

@ -345,13 +345,13 @@ Foam::cyclicAMIFvPatchField<Type>::getNeighbourField
template<class Type> template<class Type>
bool Foam::cyclicAMIFvPatchField<Type>::cacheNeighbourField() const bool Foam::cyclicAMIFvPatchField<Type>::cacheNeighbourField() const
{ {
const auto& AMI = this->ownerAMI(); // const auto& AMI = this->ownerAMI();
if (AMI.cacheActive()) // if (AMI.cacheActive())
{ // {
return false; // return false;
} // }
else // else
{ {
return (FieldBase::localBoundaryConsistency() != 0); return (FieldBase::localBoundaryConsistency() != 0);
} }
@ -383,11 +383,12 @@ Foam::cyclicAMIFvPatchField<Type>::getPatchNeighbourField
} }
const auto& fvp = this->patch(); const auto& fvp = this->patch();
const auto& mesh = fvp.boundaryMesh().mesh();
if if
( (
patchNeighbourFieldPtr_ patchNeighbourFieldPtr_
&& !fvp.boundaryMesh().mesh().upToDatePoints(this->internalField()) && !mesh.upToDatePoints(this->internalField())
) )
{ {
//DebugPout //DebugPout
@ -451,7 +452,8 @@ template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::tmp<Foam::Field<Type>>
Foam::cyclicAMIFvPatchField<Type>::patchNeighbourField() const Foam::cyclicAMIFvPatchField<Type>::patchNeighbourField() const
{ {
return this->getPatchNeighbourField(true); // checkCommunicator = true // checkCommunicator = true
return this->getPatchNeighbourField(true);
} }

View File

@ -440,18 +440,19 @@ void Foam::cyclicACMIGAMGInterfaceField::updateInterfaceMatrix
if (cache.index0() == -1 && cache.index1() == -1) if (cache.index0() == -1 && cache.index1() == -1)
{ {
if (cyclicACMIInterface_.owner()) solveScalarField pnf(faceCells.size(), Zero);
{
work = AMI.interpolateToSource(work); AMI.weightedSum
} (
else cyclicACMIInterface_.owner(),
{ work,
work = AMI.interpolateToTarget(work); pnf, // result
} solveScalarField::null()
);
const labelUList& faceCells = lduAddr.patchAddr(patchId); const labelUList& faceCells = lduAddr.patchAddr(patchId);
this->addToInternalField(result, !add, faceCells, coeffs, work); this->addToInternalField(result, !add, faceCells, coeffs, pnf);
} }
else else
{ {

View File

@ -325,6 +325,10 @@ void Foam::cyclicAMIGAMGInterfaceField::updateInterfaceMatrix
const auto& cache = AMI.cache(); const auto& cache = AMI.cache();
// Assume that sends are also OK
sendRequests_.clear();
sendRequests1_.clear();
if (AMI.distributed() && AMI.comm() != -1) if (AMI.distributed() && AMI.comm() != -1)
{ {
if (commsType != UPstream::commsTypes::nonBlocking) if (commsType != UPstream::commsTypes::nonBlocking)

View File

@ -393,11 +393,11 @@ void Foam::cyclicAMIPolyPatch::resetAMI(const UList<point>& points) const
label refProci = -1; label refProci = -1;
if (size() > 0) if (size() > 0)
{ {
refProci = UPstream::myProcNo(); refProci = UPstream::myProcNo(comm);
} }
reduce(refProci, maxOp<label>(), UPstream::msgType(), comm); reduce(refProci, maxOp<label>(), UPstream::msgType(), comm);
if (refProci == UPstream::myProcNo()) if (refProci == UPstream::myProcNo(comm))
{ {
refPt = points[meshPoints()[0]]; refPt = points[meshPoints()[0]];
} }

View File

@ -99,7 +99,7 @@ protected:
//- Index of other half //- Index of other half
mutable label nbrPatchID_; mutable label nbrPatchID_;
//- Particle displacement fraction accross AMI //- Particle displacement fraction across AMI
const scalar fraction_; const scalar fraction_;

View File

@ -131,7 +131,7 @@ Foam::tmp<Foam::Field<Type>> Foam::cyclicAMIPolyPatch::interpolate
const tensorField ownT(cs().R(this->faceCentres())); const tensorField ownT(cs().R(this->faceCentres()));
Field<Type> localDeflt(defaultValues.size()); Field<Type> localDeflt(defaultValues.size());
if (defaultValues.size() == size()) if (defaultValues.size() != 0 && defaultValues.size() == size())
{ {
// Transform default values into cylindrical coords (using // Transform default values into cylindrical coords (using
// *this faceCentres) // *this faceCentres)
@ -275,19 +275,16 @@ void Foam::cyclicAMIPolyPatch::initInterpolate
if constexpr (transform_supported) if constexpr (transform_supported)
{ {
const cyclicAMIPolyPatch& nbrPp = this->neighbPatch();
Field<Type> localFld(fld.size());
// Only creates the co-ord system if using periodic AMI // Only creates the co-ord system if using periodic AMI
// - convert to cylindrical coordinate system // - convert to cylindrical coordinate system
auto cs = cylindricalCS(); auto cs = cylindricalCS();
if (cs) if (cs)
{ {
Field<Type> localFld(fld.size());
const cyclicAMIPolyPatch& nbrPp = this->neighbPatch();
const tensorField nbrT(cs().R(nbrPp.faceCentres())); const tensorField nbrT(cs().R(nbrPp.faceCentres()));
Foam::invTransform(localFld, nbrT, fld); Foam::invTransform(localFld, nbrT, fld);
}
initInterpolateUntransformed initInterpolateUntransformed
( (
@ -302,9 +299,11 @@ void Foam::cyclicAMIPolyPatch::initInterpolate
sendBuffers1, sendBuffers1,
recvBuffers1 recvBuffers1
); );
return;
} }
else }
{
initInterpolateUntransformed initInterpolateUntransformed
( (
fld, fld,
@ -319,7 +318,6 @@ void Foam::cyclicAMIPolyPatch::initInterpolate
recvBuffers1 recvBuffers1
); );
} }
}
template<class Type> template<class Type>
@ -333,9 +331,11 @@ Foam::tmp<Foam::Field<Type>> Foam::cyclicAMIPolyPatch::interpolate
const UList<Type>& defaultValues const UList<Type>& defaultValues
) const ) const
{ {
// Note: cannot be localFld.size() -> might have been set to null
auto tresult = tmp<Field<Type>>::New(this->size(), Zero); auto tresult = tmp<Field<Type>>::New(this->size(), Zero);
const auto& AMI = (owner() ? this->AMI() : neighbPatch().AMI()); const auto& AMI = (owner() ? this->AMI() : neighbPatch().AMI());
const auto& cache = AMI.cache(); const auto& cache = AMI.cache();
cache.setDirection(owner()); cache.setDirection(owner());
@ -426,7 +426,7 @@ Foam::tmp<Foam::Field<Type>> Foam::cyclicAMIPolyPatch::interpolate
} }
const auto& localDefaultValues = const auto& localDefaultValues =
transform_supported ? localDeflt : defaultValues; localDeflt.size() ? localDeflt : defaultValues;
if (cache.index0() == -1 && cache.index1() == -1) if (cache.index0() == -1 && cache.index1() == -1)
{ {