From 5e334c0686d11c925d38fa3232002337b251aeae Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 24 Jul 2023 13:03:15 +0200 Subject: [PATCH] ENH: more consistent use of AMIInterpolation distributed() query --- .../constraint/cyclicAMI/cyclicAMIFvPatch.H | 15 +++--- .../field/AMIWeights/AMIWeights.C | 8 +-- src/lagrangian/basic/Cloud/Cloud.C | 21 +++----- .../AMIInterpolation/AMIInterpolation.C | 2 +- .../AMIInterpolation/AMIInterpolation.H | 51 +++++++++++-------- .../AMIInterpolation/AMIInterpolationI.H | 29 ++++++++--- .../AMIPatchToPatchInterpolation.H | 10 +++- .../cyclicAMIPolyPatchTopologyChange.C | 2 +- src/sampling/meshToMesh/meshToMesh.C | 2 +- src/sampling/meshToMesh/meshToMesh.H | 25 ++++++--- src/sampling/meshToMesh/meshToMeshI.H | 26 ++++++++-- src/sampling/meshToMesh/meshToMeshTemplates.C | 18 +++---- 12 files changed, 132 insertions(+), 77 deletions(-) diff --git a/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.H b/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.H index ea902b98d7..30ec8fc718 100644 --- a/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.H +++ b/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.H @@ -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 diff --git a/src/functionObjects/field/AMIWeights/AMIWeights.C b/src/functionObjects/field/AMIWeights/AMIWeights.C index 8b34a883fc..004853d8f5 100644 --- a/src/functionObjects/field/AMIWeights/AMIWeights.C +++ b/src/functionObjects/field/AMIWeights/AMIWeights.C @@ -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; } diff --git a/src/lagrangian/basic/Cloud/Cloud.C b/src/lagrangian/basic/Cloud/Cloud.C index 3cbc131223..18741d9623 100644 --- a/src/lagrangian/basic/Cloud/Cloud.C +++ b/src/lagrangian/basic/Cloud/Cloud.C @@ -41,28 +41,19 @@ License template void Foam::Cloud::checkPatches() const { - bool ok = true; for (const polyPatch& pp : polyMesh_.boundaryMesh()) { const auto* camipp = isA(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); - } } diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C index 5a743787fa..3da6f28823 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C @@ -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; diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H index e8a69e5eae..58ac94685c 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H @@ -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_; } }; diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H index fa0c51c943..9ff46e95b1 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H @@ -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::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(); +} + + // ************************************************************************* // diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIPatchToPatchInterpolation.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIPatchToPatchInterpolation.H index 43a8a3e5cc..b43c6ab3b6 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIPatchToPatchInterpolation.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIPatchToPatchInterpolation.H @@ -24,10 +24,16 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . +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" diff --git a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatchTopologyChange.C b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatchTopologyChange.C index ad098dd3ca..749267c93d 100644 --- a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatchTopologyChange.C +++ b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatchTopologyChange.C @@ -311,7 +311,7 @@ void Foam::cyclicAMIPolyPatch::setAMIFaces() autoPtr srcToTgtMap1; autoPtr tgtToSrcMap1; - if (AMIPtr_->singlePatchProc() == -1) + if (AMIPtr_->distributed()) { // Parallel running diff --git a/src/sampling/meshToMesh/meshToMesh.C b/src/sampling/meshToMesh/meshToMesh.C index 69ba954e7e..eaa6f79e0e 100644 --- a/src/sampling/meshToMesh/meshToMesh.C +++ b/src/sampling/meshToMesh/meshToMesh.C @@ -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()); diff --git a/src/sampling/meshToMesh/meshToMesh.H b/src/sampling/meshToMesh/meshToMesh.H index f8ec022958..60f5ca623d 100644 --- a/src/sampling/meshToMesh/meshToMesh.H +++ b/src/sampling/meshToMesh/meshToMesh.H @@ -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& srcMap() const; + //- Distributed across processors (singleMeshProc == -1) + inline bool distributed() const noexcept; - //- Target map pointer - valid if no singleMeshProc - inline const autoPtr& 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& srcMap() const noexcept; + + //- Target map pointer - valid if no singleMeshProc + inline const autoPtr& tgtMap() const noexcept; // Evaluation diff --git a/src/sampling/meshToMesh/meshToMeshI.H b/src/sampling/meshToMesh/meshToMeshI.H index bb25ab1443..0c1095bef0 100644 --- a/src/sampling/meshToMesh/meshToMeshI.H +++ b/src/sampling/meshToMesh/meshToMeshI.H @@ -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::meshToMesh::srcMap() const +Foam::meshToMesh::srcMap() const noexcept { return srcMapPtr_; } inline const Foam::autoPtr& -Foam::meshToMesh::tgtMap() const +Foam::meshToMesh::tgtMap() const noexcept { return tgtMapPtr_; } diff --git a/src/sampling/meshToMesh/meshToMeshTemplates.C b/src/sampling/meshToMesh/meshToMeshTemplates.C index adde5edb2d..caf36c97c7 100644 --- a/src/sampling/meshToMesh/meshToMeshTemplates.C +++ b/src/sampling/meshToMesh/meshToMeshTemplates.C @@ -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 cbop(cop); - if (singleMeshProc_ == -1) + if (distributed()) { const mapDistribute& map = srcMapPtr_(); @@ -138,7 +138,7 @@ void Foam::meshToMesh::mapSrcToTgt multiplyWeightedOp cbop(cop); - if (singleMeshProc_ == -1) + if (distributed()) { if (returnReduceAnd(tgtToSrcCellVec_.empty())) { @@ -284,7 +284,7 @@ void Foam::meshToMesh::mapTgtToSrc multiplyWeightedOp cbop(cop); - if (singleMeshProc_ == -1) + if (distributed()) { const mapDistribute& map = tgtMapPtr_(); @@ -351,7 +351,7 @@ void Foam::meshToMesh::mapTgtToSrc multiplyWeightedOp 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(),