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 neighbour
virtual label neighbPatchID() const
{
return cyclicAMIPolyPatch_.neighbPatchID();
}
//- Does this side own the patch?
virtual bool owner() const
{
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
{
return refCast<const cyclicAMIFvPatch>

View File

@ -55,7 +55,7 @@ void Foam::functionObjects::AMIWeights::writeFileHeader(Ostream& os)
writeTabbed(os, "Patch");
writeTabbed(os, "nbr_patch");
if (Pstream::parRun())
if (UPstream::parRun())
{
writeTabbed(os, "distributed");
}
@ -85,7 +85,7 @@ void Foam::functionObjects::AMIWeights::reportPatch
{
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 scalar srcMinWeight = gMin(srcWeightsSum);
@ -141,7 +141,7 @@ void Foam::functionObjects::AMIWeights::reportPatch
<< nbrPatchName << tab;
if (Pstream::parRun())
if (UPstream::parRun())
{
file() << distributed << tab;
}
@ -165,7 +165,7 @@ void Foam::functionObjects::AMIWeights::reportPatch
<< " Source: " << pp.name() << nl
<< " Target: " << nbrPatchName << nl;
if (Pstream::parRun())
if (UPstream::parRun())
{
Log << " Parallel distributed: " << distributed << nl;
}

View File

@ -41,28 +41,19 @@ License
template<class ParticleType>
void Foam::Cloud<ParticleType>::checkPatches() const
{
bool ok = true;
for (const polyPatch& pp : polyMesh_.boundaryMesh())
{
const auto* camipp = isA<cyclicAMIPolyPatch>(pp);
if (camipp && camipp->owner())
if (camipp && camipp->owner() && camipp->AMI().distributed())
{
ok = (camipp->AMI().singlePatchProc() != -1);
if (!ok)
{
break;
}
FatalErrorInFunction
<< "Particle tracking across AMI patches is only currently "
<< "supported for cases where the AMI patches reside on a "
<< "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
{
if (Pstream::parRun() && (singlePatchProc_ == -1))
if (UPstream::parRun() && this->distributed())
{
Log << "Checks only valid for serial running (currently)" << endl;

View File

@ -104,8 +104,8 @@ protected:
//- Threshold weight below which interpolation is deactivated
const scalar lowWeightCorrection_;
//- Index of processor that holds all of both sides. -1 in all other
//- cases
//- Index of processor that holds all of both sides.
//- The value is -1 for distributed cases
label singlePatchProc_;
@ -309,14 +309,14 @@ public:
// Constructors
//- Construct from dictionary
AMIInterpolation
explicit AMIInterpolation
(
const dictionary& dict,
const bool reverseTarget = false
);
//- Construct from components
AMIInterpolation
explicit AMIInterpolation
(
const bool requireMatch = true,
const bool reverseTarget = false,
@ -361,24 +361,20 @@ public:
return old;
}
//- Access to the up-to-date flag
// \deprecated Prefer the upToDate(bool) setter (JAN-2023)
bool upToDate() noexcept { return upToDate_; }
//- Distributed across processors (singlePatchProc == -1)
inline bool distributed() const noexcept;
//- Access to the distributed flag
inline bool distributed() const;
//- Return the requireMatch flag
inline bool requireMatch() const noexcept;
//- Access to the requireMatch flag
inline bool requireMatch() const;
//- Access to the requireMatch flag
inline bool setRequireMatch(const bool flag);
//- Set the require match flag, return the \em new value
inline bool setRequireMatch(bool flag) noexcept;
//- Return true if requireMatch and lowWeightCorrectionin active
inline bool mustMatchFaces() const;
//- Access to the reverseTarget flag
inline bool reverseTarget() const;
inline bool reverseTarget() const noexcept;
//- Threshold weight below which interpolation is deactivated
inline scalar lowWeightCorrection() const;
@ -386,9 +382,9 @@ public:
//- Return true if employing a 'lowWeightCorrection'
inline bool applyLowWeightCorrection() const;
//- Set to -1, or the processor holding all faces (both sides) of
//- the AMI
inline label singlePatchProc() const;
//- The processor holding all faces (both sides),
//- or -1 if distributed
inline label singlePatchProc() const noexcept;
// Source patch
@ -425,11 +421,15 @@ public:
//- Return access to source patch face centroids
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
//- tgtAddress, tgtWeights
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
@ -459,11 +459,15 @@ public:
//- patch weights (i.e. the sum before normalisation)
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
//- srcAddress, srcWeights
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
@ -637,6 +641,13 @@ public:
//- Write
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 |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
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_;
}
inline bool Foam::AMIInterpolation::setRequireMatch(const bool flag)
inline bool Foam::AMIInterpolation::setRequireMatch(bool flag) noexcept
{
requireMatch_ = flag;
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_;
}
@ -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_;
}
@ -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
{
return tgtMagSf_;
@ -221,4 +228,12 @@ inline const Foam::mapDistribute& Foam::AMIInterpolation::tgtMap() const
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
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::AMIPatchToPatchInterpolation
Description
Patch-to-patch interpolation == Foam::AMIInterpolation
\*---------------------------------------------------------------------------*/
#ifndef AMIPatchToPatchInterpolation_H
#define AMIPatchToPatchInterpolation_H
#ifndef Foam_AMIPatchToPatchInterpolation_H
#define Foam_AMIPatchToPatchInterpolation_H
#include "AMIInterpolation.H"

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2014 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
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>&
Foam::meshToMesh::srcMap() const
Foam::meshToMesh::srcMap() const noexcept
{
return srcMapPtr_;
}
inline const Foam::autoPtr<Foam::mapDistribute>&
Foam::meshToMesh::tgtMap() const
Foam::meshToMesh::tgtMap() const noexcept
{
return tgtMapPtr_;
}

View File

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