ENH: more consistent use of AMIInterpolation distributed() query

This commit is contained in:
Mark Olesen
2023-07-24 13:03:15 +02:00
parent 32903d337e
commit 5e334c0686
12 changed files with 132 additions and 77 deletions

View File

@ -144,18 +144,19 @@ public:
return cyclicAMIPolyPatch_; return cyclicAMIPolyPatch_;
} }
//- Return neighbour //- Does this side own the patch?
virtual label neighbPatchID() const
{
return cyclicAMIPolyPatch_.neighbPatchID();
}
virtual bool owner() const virtual bool owner() const
{ {
return cyclicAMIPolyPatch_.owner(); return cyclicAMIPolyPatch_.owner();
} }
//- Return processor number //- Return neighbour patch ID
virtual label neighbPatchID() const
{
return cyclicAMIPolyPatch_.neighbPatchID();
}
//- Return a reference to the neighbour patch
virtual const cyclicAMIFvPatch& neighbPatch() const virtual const cyclicAMIFvPatch& neighbPatch() const
{ {
return refCast<const cyclicAMIFvPatch> return refCast<const cyclicAMIFvPatch>

View File

@ -55,7 +55,7 @@ void Foam::functionObjects::AMIWeights::writeFileHeader(Ostream& os)
writeTabbed(os, "Patch"); writeTabbed(os, "Patch");
writeTabbed(os, "nbr_patch"); writeTabbed(os, "nbr_patch");
if (Pstream::parRun()) if (UPstream::parRun())
{ {
writeTabbed(os, "distributed"); writeTabbed(os, "distributed");
} }
@ -85,7 +85,7 @@ void Foam::functionObjects::AMIWeights::reportPatch
{ {
const word& nbrPatchName = pp.neighbPatchName(); const word& nbrPatchName = pp.neighbPatchName();
const Switch distributed = pp.AMI().singlePatchProc() == -1; const Switch distributed = pp.AMI().distributed();
const scalarField& srcWeightsSum = pp.AMI().srcWeightsSum(); const scalarField& srcWeightsSum = pp.AMI().srcWeightsSum();
const scalar srcMinWeight = gMin(srcWeightsSum); const scalar srcMinWeight = gMin(srcWeightsSum);
@ -141,7 +141,7 @@ void Foam::functionObjects::AMIWeights::reportPatch
<< nbrPatchName << tab; << nbrPatchName << tab;
if (Pstream::parRun()) if (UPstream::parRun())
{ {
file() << distributed << tab; file() << distributed << tab;
} }
@ -165,7 +165,7 @@ void Foam::functionObjects::AMIWeights::reportPatch
<< " Source: " << pp.name() << nl << " Source: " << pp.name() << nl
<< " Target: " << nbrPatchName << nl; << " Target: " << nbrPatchName << nl;
if (Pstream::parRun()) if (UPstream::parRun())
{ {
Log << " Parallel distributed: " << distributed << nl; Log << " Parallel distributed: " << distributed << nl;
} }

View File

@ -41,28 +41,19 @@ License
template<class ParticleType> template<class ParticleType>
void Foam::Cloud<ParticleType>::checkPatches() const void Foam::Cloud<ParticleType>::checkPatches() const
{ {
bool ok = true;
for (const polyPatch& pp : polyMesh_.boundaryMesh()) for (const polyPatch& pp : polyMesh_.boundaryMesh())
{ {
const auto* camipp = isA<cyclicAMIPolyPatch>(pp); const auto* camipp = isA<cyclicAMIPolyPatch>(pp);
if (camipp && camipp->owner()) if (camipp && camipp->owner() && camipp->AMI().distributed())
{ {
ok = (camipp->AMI().singlePatchProc() != -1); FatalErrorInFunction
if (!ok) << "Particle tracking across AMI patches is only currently "
{ << "supported for cases where the AMI patches reside on a "
break; << "single processor" << abort(FatalError);
} break;
} }
} }
if (!ok)
{
FatalErrorInFunction
<< "Particle tracking across AMI patches is only currently "
<< "supported for cases where the AMI patches reside on a "
<< "single processor" << abort(FatalError);
}
} }

View File

@ -1132,7 +1132,7 @@ const
bool Foam::AMIInterpolation::checkSymmetricWeights(const bool log) const bool Foam::AMIInterpolation::checkSymmetricWeights(const bool log) const
{ {
if (Pstream::parRun() && (singlePatchProc_ == -1)) if (UPstream::parRun() && this->distributed())
{ {
Log << "Checks only valid for serial running (currently)" << endl; Log << "Checks only valid for serial running (currently)" << endl;

View File

@ -104,8 +104,8 @@ protected:
//- Threshold weight below which interpolation is deactivated //- Threshold weight below which interpolation is deactivated
const scalar lowWeightCorrection_; const scalar lowWeightCorrection_;
//- Index of processor that holds all of both sides. -1 in all other //- Index of processor that holds all of both sides.
//- cases //- The value is -1 for distributed cases
label singlePatchProc_; label singlePatchProc_;
@ -309,14 +309,14 @@ public:
// Constructors // Constructors
//- Construct from dictionary //- Construct from dictionary
AMIInterpolation explicit AMIInterpolation
( (
const dictionary& dict, const dictionary& dict,
const bool reverseTarget = false const bool reverseTarget = false
); );
//- Construct from components //- Construct from components
AMIInterpolation explicit AMIInterpolation
( (
const bool requireMatch = true, const bool requireMatch = true,
const bool reverseTarget = false, const bool reverseTarget = false,
@ -361,24 +361,20 @@ public:
return old; return old;
} }
//- Access to the up-to-date flag //- Distributed across processors (singlePatchProc == -1)
// \deprecated Prefer the upToDate(bool) setter (JAN-2023) inline bool distributed() const noexcept;
bool upToDate() noexcept { return upToDate_; }
//- Access to the distributed flag //- Return the requireMatch flag
inline bool distributed() const; inline bool requireMatch() const noexcept;
//- Access to the requireMatch flag //- Set the require match flag, return the \em new value
inline bool requireMatch() const; inline bool setRequireMatch(bool flag) noexcept;
//- Access to the requireMatch flag
inline bool setRequireMatch(const bool flag);
//- Return true if requireMatch and lowWeightCorrectionin active //- Return true if requireMatch and lowWeightCorrectionin active
inline bool mustMatchFaces() const; inline bool mustMatchFaces() const;
//- Access to the reverseTarget flag //- Access to the reverseTarget flag
inline bool reverseTarget() const; inline bool reverseTarget() const noexcept;
//- Threshold weight below which interpolation is deactivated //- Threshold weight below which interpolation is deactivated
inline scalar lowWeightCorrection() const; inline scalar lowWeightCorrection() const;
@ -386,9 +382,9 @@ public:
//- Return true if employing a 'lowWeightCorrection' //- Return true if employing a 'lowWeightCorrection'
inline bool applyLowWeightCorrection() const; inline bool applyLowWeightCorrection() const;
//- Set to -1, or the processor holding all faces (both sides) of //- The processor holding all faces (both sides),
//- the AMI //- or -1 if distributed
inline label singlePatchProc() const; inline label singlePatchProc() const noexcept;
// Source patch // Source patch
@ -425,11 +421,15 @@ public:
//- Return access to source patch face centroids //- Return access to source patch face centroids
inline pointListList& srcCentroids(); inline pointListList& srcCentroids();
//- Source map pointer - valid only if singlePatchProc = -1 //- Source map - valid only if singlePatchProc = -1
//- This gets source data into a form to be consumed by //- This gets source data into a form to be consumed by
//- tgtAddress, tgtWeights //- tgtAddress, tgtWeights
inline const mapDistribute& srcMap() const; inline const mapDistribute& srcMap() const;
//- Pointer to the source map (if distributed).
//- Can be checked as a bool.
inline const mapDistribute* hasSrcMap() const noexcept;
// Target patch // Target patch
@ -459,11 +459,15 @@ public:
//- patch weights (i.e. the sum before normalisation) //- patch weights (i.e. the sum before normalisation)
inline scalarField& tgtWeightsSum(); inline scalarField& tgtWeightsSum();
//- Target map pointer - valid only if singlePatchProc=-1. //- Target map - valid only if singlePatchProc=-1.
//- This gets target data into a form to be consumed by //- This gets target data into a form to be consumed by
//- srcAddress, srcWeights //- srcAddress, srcWeights
inline const mapDistribute& tgtMap() const; inline const mapDistribute& tgtMap() const;
//- Pointer to the target map (if distributed).
//- Can be checked as a bool.
inline const mapDistribute* hasTgtMap() const noexcept;
// Manipulation // Manipulation
@ -637,6 +641,13 @@ public:
//- Write //- Write
virtual void write(Ostream& os) const; virtual void write(Ostream& os) const;
// Housekeeping
//- Non-const access to the up-to-date flag
// \deprecated Prefer the upToDate(bool) setter (JAN-2023)
bool& upToDate() noexcept { return upToDate_; }
}; };

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -53,19 +53,19 @@ inline const Foam::primitivePatch& Foam::AMIInterpolation::tgtPatch0() const
} }
inline bool Foam::AMIInterpolation::distributed() const inline bool Foam::AMIInterpolation::distributed() const noexcept
{ {
return singlePatchProc_ == -1; return (singlePatchProc_ == -1);
} }
inline bool Foam::AMIInterpolation::requireMatch() const inline bool Foam::AMIInterpolation::requireMatch() const noexcept
{ {
return requireMatch_; return requireMatch_;
} }
inline bool Foam::AMIInterpolation::setRequireMatch(const bool flag) inline bool Foam::AMIInterpolation::setRequireMatch(bool flag) noexcept
{ {
requireMatch_ = flag; requireMatch_ = flag;
return requireMatch_; return requireMatch_;
@ -78,7 +78,7 @@ inline bool Foam::AMIInterpolation::mustMatchFaces() const
} }
inline bool Foam::AMIInterpolation::reverseTarget() const inline bool Foam::AMIInterpolation::reverseTarget() const noexcept
{ {
return reverseTarget_; return reverseTarget_;
} }
@ -96,7 +96,7 @@ inline bool Foam::AMIInterpolation::applyLowWeightCorrection() const
} }
inline Foam::label Foam::AMIInterpolation::singlePatchProc() const inline Foam::label Foam::AMIInterpolation::singlePatchProc() const noexcept
{ {
return singlePatchProc_; return singlePatchProc_;
} }
@ -168,6 +168,13 @@ inline const Foam::mapDistribute& Foam::AMIInterpolation::srcMap() const
} }
inline const Foam::mapDistribute*
Foam::AMIInterpolation::hasSrcMap() const noexcept
{
return srcMapPtr_.get();
}
inline const Foam::List<Foam::scalar>& Foam::AMIInterpolation::tgtMagSf() const inline const Foam::List<Foam::scalar>& Foam::AMIInterpolation::tgtMagSf() const
{ {
return tgtMagSf_; return tgtMagSf_;
@ -221,4 +228,12 @@ inline const Foam::mapDistribute& Foam::AMIInterpolation::tgtMap() const
return *tgtMapPtr_; return *tgtMapPtr_;
} }
inline const Foam::mapDistribute*
Foam::AMIInterpolation::hasTgtMap() const noexcept
{
return tgtMapPtr_.get();
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -24,10 +24,16 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::AMIPatchToPatchInterpolation
Description
Patch-to-patch interpolation == Foam::AMIInterpolation
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef AMIPatchToPatchInterpolation_H #ifndef Foam_AMIPatchToPatchInterpolation_H
#define AMIPatchToPatchInterpolation_H #define Foam_AMIPatchToPatchInterpolation_H
#include "AMIInterpolation.H" #include "AMIInterpolation.H"

View File

@ -311,7 +311,7 @@ void Foam::cyclicAMIPolyPatch::setAMIFaces()
autoPtr<mapDistribute> srcToTgtMap1; autoPtr<mapDistribute> srcToTgtMap1;
autoPtr<mapDistribute> tgtToSrcMap1; autoPtr<mapDistribute> tgtToSrcMap1;
if (AMIPtr_->singlePatchProc() == -1) if (AMIPtr_->distributed())
{ {
// Parallel running // Parallel running

View File

@ -443,7 +443,7 @@ void Foam::meshToMesh::calculate(const word& methodName, const bool normalise)
singleMeshProc_ = calcDistribution(srcRegion_, tgtRegion_); singleMeshProc_ = calcDistribution(srcRegion_, tgtRegion_);
if (singleMeshProc_ == -1) if (singleMeshProc_ == -1) // -> distributed()
{ {
// create global indexing for src and tgt meshes // create global indexing for src and tgt meshes
globalIndex globalSrcCells(srcRegion_.nCells()); globalIndex globalSrcCells(srcRegion_.nCells());

View File

@ -137,8 +137,8 @@ private:
//- Cell total volume in overlap region [m3] //- Cell total volume in overlap region [m3]
scalar V_; scalar V_;
//- Index of processor that holds all of both sides. -1 in all other //- Index of processor that holds all of both sides.
// cases //- The value is -1 for distributed cases
label singleMeshProc_; label singleMeshProc_;
//- Source map pointer - parallel running only //- Source map pointer - parallel running only
@ -404,13 +404,24 @@ public:
patchAMIs() const; patchAMIs() const;
// Explicit access. Can probably be done with combine operator. // Mapping
//- Source map pointer - valid if no singleMeshProc //- Distributed across processors (singleMeshProc == -1)
inline const autoPtr<mapDistribute>& srcMap() const; inline bool distributed() const noexcept;
//- Target map pointer - valid if no singleMeshProc //- Pointer to the source map (if distributed).
inline const autoPtr<mapDistribute>& tgtMap() const; //- Can be checked as a bool.
inline const mapDistribute* hasSrcMap() const noexcept;
//- Pointer to the target map (if distributed).
//- Can be checked as a bool.
inline const mapDistribute* hasTgtMap() const noexcept;
//- Source map pointer - valid if no singleMeshProc
inline const autoPtr<mapDistribute>& srcMap() const noexcept;
//- Target map pointer - valid if no singleMeshProc
inline const autoPtr<mapDistribute>& tgtMap() const noexcept;
// Evaluation // Evaluation

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2014 OpenFOAM Foundation Copyright (C) 2012-2014 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -84,15 +84,35 @@ inline Foam::scalar Foam::meshToMesh::V() const
} }
inline bool Foam::meshToMesh::distributed() const noexcept
{
return (singleMeshProc_ == -1);
}
inline const Foam::mapDistribute*
Foam::meshToMesh::hasSrcMap() const noexcept
{
return srcMapPtr_.get();
}
inline const Foam::mapDistribute*
Foam::meshToMesh::hasTgtMap() const noexcept
{
return tgtMapPtr_.get();
}
inline const Foam::autoPtr<Foam::mapDistribute>& inline const Foam::autoPtr<Foam::mapDistribute>&
Foam::meshToMesh::srcMap() const Foam::meshToMesh::srcMap() const noexcept
{ {
return srcMapPtr_; return srcMapPtr_;
} }
inline const Foam::autoPtr<Foam::mapDistribute>& inline const Foam::autoPtr<Foam::mapDistribute>&
Foam::meshToMesh::tgtMap() const Foam::meshToMesh::tgtMap() const noexcept
{ {
return tgtMapPtr_; return tgtMapPtr_;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd. Copyright (C) 2015-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -69,7 +69,7 @@ void Foam::meshToMesh::mapSrcToTgt
multiplyWeightedOp<Type, CombineOp> cbop(cop); multiplyWeightedOp<Type, CombineOp> cbop(cop);
if (singleMeshProc_ == -1) if (distributed())
{ {
const mapDistribute& map = srcMapPtr_(); const mapDistribute& map = srcMapPtr_();
@ -138,7 +138,7 @@ void Foam::meshToMesh::mapSrcToTgt
multiplyWeightedOp<Type, CombineOp> cbop(cop); multiplyWeightedOp<Type, CombineOp> cbop(cop);
if (singleMeshProc_ == -1) if (distributed())
{ {
if (returnReduceAnd(tgtToSrcCellVec_.empty())) if (returnReduceAnd(tgtToSrcCellVec_.empty()))
{ {
@ -284,7 +284,7 @@ void Foam::meshToMesh::mapTgtToSrc
multiplyWeightedOp<Type, CombineOp> cbop(cop); multiplyWeightedOp<Type, CombineOp> cbop(cop);
if (singleMeshProc_ == -1) if (distributed())
{ {
const mapDistribute& map = tgtMapPtr_(); const mapDistribute& map = tgtMapPtr_();
@ -351,7 +351,7 @@ void Foam::meshToMesh::mapTgtToSrc
multiplyWeightedOp<Type, CombineOp> cbop(cop); multiplyWeightedOp<Type, CombineOp> cbop(cop);
if (singleMeshProc_ == -1) if (distributed())
{ {
if (returnReduceAnd(srcToTgtCellVec_.empty())) if (returnReduceAnd(srcToTgtCellVec_.empty()))
{ {
@ -551,8 +551,8 @@ void Foam::meshToMesh::mapSrcToTgt
( (
AMIList[i].singlePatchProc(), AMIList[i].singlePatchProc(),
( (
AMIList[i].singlePatchProc() == -1 AMIList[i].distributed()
? &AMIList[i].srcMap() ? AMIList[i].hasSrcMap() // pointer to map
: nullptr : nullptr
), ),
AMIList[i].tgtAddress(), AMIList[i].tgtAddress(),
@ -783,8 +783,8 @@ void Foam::meshToMesh::mapTgtToSrc
( (
AMIList[i].singlePatchProc(), AMIList[i].singlePatchProc(),
( (
AMIList[i].singlePatchProc() == -1 AMIList[i].distributed()
? &AMIList[i].tgtMap() ? AMIList[i].hasTgtMap() // pointer to map
: nullptr : nullptr
), ),
AMIList[i].srcAddress(), AMIList[i].srcAddress(),