From 6644cf8ddb5208063283357e414c645fd898672b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 6 May 2022 14:43:07 +0200 Subject: [PATCH] ENH: cleanup/reorganize parts of redistributePar - separate out lagrangian routines etc - align names with regular decompose/reconstruct methods --- .../redistributePar/Make/files | 6 +- ...econstructor.C => parFvFieldDistributor.C} | 66 +- ...econstructor.H => parFvFieldDistributor.H} | 127 +-- .../parFvFieldDistributorFields.C | 62 ++ ...lds.C => parFvFieldDistributorTemplates.C} | 419 +++++----- ...stributor.C => parLagrangianDistributor.C} | 12 +- ...stributor.H => parLagrangianDistributor.H} | 136 ++-- .../parLagrangianDistributorFields.C | 195 +++++ ....C => parLagrangianDistributorTemplates.C} | 98 ++- .../redistributePar/redistributeLagrangian.H | 230 ++++++ .../redistributePar/redistributePar.C | 740 ++---------------- 11 files changed, 1039 insertions(+), 1052 deletions(-) rename applications/utilities/parallelProcessing/redistributePar/{parFvFieldReconstructor.C => parFvFieldDistributor.C} (65%) rename applications/utilities/parallelProcessing/redistributePar/{parFvFieldReconstructor.H => parFvFieldDistributor.H} (60%) create mode 100644 applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributorFields.C rename applications/utilities/parallelProcessing/redistributePar/{parFvFieldReconstructorFields.C => parFvFieldDistributorTemplates.C} (53%) rename applications/utilities/parallelProcessing/redistributePar/{parLagrangianRedistributor.C => parLagrangianDistributor.C} (96%) rename applications/utilities/parallelProcessing/redistributePar/{parLagrangianRedistributor.H => parLagrangianDistributor.H} (69%) create mode 100644 applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributorFields.C rename applications/utilities/parallelProcessing/redistributePar/{parLagrangianRedistributorFields.C => parLagrangianDistributorTemplates.C} (79%) create mode 100644 applications/utilities/parallelProcessing/redistributePar/redistributeLagrangian.H diff --git a/applications/utilities/parallelProcessing/redistributePar/Make/files b/applications/utilities/parallelProcessing/redistributePar/Make/files index 6e45d2d8cc..2dacc462a9 100644 --- a/applications/utilities/parallelProcessing/redistributePar/Make/files +++ b/applications/utilities/parallelProcessing/redistributePar/Make/files @@ -1,7 +1,9 @@ passivePositionParticleCloud.C -parLagrangianRedistributor.C +parLagrangianDistributor.C +parLagrangianDistributorFields.C parPointFieldDistributor.C -parFvFieldReconstructor.C +parFvFieldDistributor.C +parFvFieldDistributorFields.C loadOrCreateMesh.C redistributePar.C diff --git a/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructor.C b/applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributor.C similarity index 65% rename from applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructor.C rename to applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributor.C index 45acf1bf56..16187c06fc 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructor.C +++ b/applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributor.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,48 +26,47 @@ License \*---------------------------------------------------------------------------*/ -#include "parFvFieldReconstructor.H" +#include "parFvFieldDistributor.H" +#include "bitSet.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +int Foam::parFvFieldDistributor::verbose_ = 1; + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::parFvFieldReconstructor::createPatchFaceMaps() +void Foam::parFvFieldDistributor::createPatchFaceMaps() { - const fvBoundaryMesh& fvb = procMesh_.boundary(); + const fvBoundaryMesh& fvb = srcMesh_.boundary(); - patchFaceMaps_.setSize(fvb.size()); - forAll(fvb, patchI) + patchFaceMaps_.resize(fvb.size()); + + forAll(fvb, patchi) { - if (!isA(fvb[patchI])) + if (!isA(fvb[patchi])) { - // Create map for patch faces only - - // Mark all used elements (i.e. destination patch faces) - boolList faceIsUsed(distMap_.faceMap().constructSize(), false); - const polyPatch& basePatch = baseMesh_.boundaryMesh()[patchI]; - forAll(basePatch, i) - { - faceIsUsed[basePatch.start()+i] = true; - } + // Create compact map for patch faces only + // - compact for used faces only (destination patch faces) + labelList oldToNewSub; + labelList oldToNewConstruct; // Copy face map patchFaceMaps_.set ( - patchI, + patchi, new mapDistributeBase(distMap_.faceMap()) ); - // Compact out unused elements - labelList oldToNewSub; - labelList oldToNewConstruct; - patchFaceMaps_[patchI].compact + patchFaceMaps_[patchi].compactRemoteData ( - faceIsUsed, - procMesh_.nFaces(), // maximum index of subMap + bitSet(tgtMesh_.boundaryMesh()[patchi].range()), oldToNewSub, oldToNewConstruct, + srcMesh_.nFaces(), // max index of subMap UPstream::msgType() ); - //Pout<< "patchMap:" << patchFaceMaps_[patchI] << endl; + //Pout<< "patchMap:" << patchFaceMaps_[patchi] << endl; } } } @@ -74,16 +74,16 @@ void Foam::parFvFieldReconstructor::createPatchFaceMaps() // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::parFvFieldReconstructor::parFvFieldReconstructor +Foam::parFvFieldDistributor::parFvFieldDistributor ( - fvMesh& baseMesh, - const fvMesh& procMesh, + const fvMesh& srcMesh, + fvMesh& tgtMesh, const mapDistributePolyMesh& distMap, const bool isWriteProc ) : - baseMesh_(baseMesh), - procMesh_(procMesh), + srcMesh_(srcMesh), + tgtMesh_(tgtMesh), distMap_(distMap), isWriteProc_(isWriteProc) { @@ -93,7 +93,7 @@ Foam::parFvFieldReconstructor::parFvFieldReconstructor // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::parFvFieldReconstructor::reconstructPoints() +void Foam::parFvFieldDistributor::reconstructPoints() { // Reconstruct the points for moving mesh cases and write them out distributedFieldMapper mapper @@ -101,11 +101,13 @@ void Foam::parFvFieldReconstructor::reconstructPoints() labelUList::null(), distMap_.pointMap() ); - pointField basePoints(procMesh_.points(), mapper); - baseMesh_.movePoints(basePoints); + + pointField newPoints(srcMesh_.points(), mapper); + tgtMesh_.movePoints(newPoints); + if (Pstream::master()) { - baseMesh_.write(); + tgtMesh_.write(); } } diff --git a/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructor.H b/applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributor.H similarity index 60% rename from applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructor.H rename to applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributor.H index 374c5bf8d1..cb4a76a304 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructor.H +++ b/applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributor.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,22 +25,24 @@ License along with OpenFOAM. If not, see . Class - Foam::parFvFieldReconstructor + Foam::parFvFieldDistributor Description Finite volume reconstructor for volume and surface fields. - Runs in parallel. Reconstructs from procMesh to baseMesh. baseMesh - is non-zero cells on processor0 only. + Runs in parallel. + Reconstructs/redistributes from procMesh to baseMesh. + baseMesh is non-zero cells on processor0 only. SourceFiles - parFvFieldReconstructor.C - parFvFieldReconstructorFields.C + parFvFieldDistributor.C + parFvFieldDistributorFields.C + parFvFieldDistributorTemplates.C \*---------------------------------------------------------------------------*/ -#ifndef parFvFieldReconstructor_H -#define parFvFieldReconstructor_H +#ifndef Foam_parFvFieldDistributor_H +#define Foam_parFvFieldDistributor_H #include "PtrList.H" #include "fvMesh.H" @@ -50,34 +52,34 @@ SourceFiles namespace Foam { -// Forward declarations +// Forward Declarations class mapDistributePolyMesh; class mapDistributeBase; class IOobjectList; /*---------------------------------------------------------------------------*\ - Class parFvFieldReconstructor Declaration + Class parFvFieldDistributor Declaration \*---------------------------------------------------------------------------*/ -class parFvFieldReconstructor +class parFvFieldDistributor { - // Private data + // Private Data - //- Reconstructed mesh reference - fvMesh& baseMesh_; + //- Processor mesh reference (source mesh) + const fvMesh& srcMesh_; - //- Processor mesh reference - const fvMesh& procMesh_; + //- Destination mesh reference (eg, reconstructed mesh) + fvMesh& tgtMesh_; //- Distribution map reference const mapDistributePolyMesh& distMap_; - //- Do I need to to write (usually master only) - const bool isWriteProc_; - //- Patch mappers PtrList patchFaceMaps_; + //- Do I need to write (eg, master only for reconstruct) + bool isWriteProc_; + // Private Member Functions @@ -85,21 +87,30 @@ class parFvFieldReconstructor void createPatchFaceMaps(); //- No copy construct - parFvFieldReconstructor(const parFvFieldReconstructor&) = delete; + parFvFieldDistributor(const parFvFieldDistributor&) = delete; //- No copy assignment - void operator=(const parFvFieldReconstructor&) = delete; + void operator=(const parFvFieldDistributor&) = delete; public: + //- Output verbosity when writing + static int verbose_; + + // Constructors //- Construct from components - parFvFieldReconstructor + // + // \param srcMesh The source mesh (eg, processor) + // \param tgtMesh The target mesh (eg, reconstructed) + // \param distMap The distribution map + // \param isWriteProc Tagged for output writing (on this proc) + parFvFieldDistributor ( - fvMesh& baseMesh, - const fvMesh& procMesh, + const fvMesh& srcMesh, + fvMesh& tgtMesh, const mapDistributePolyMesh& distMap, const bool isWriteProc ); @@ -107,61 +118,85 @@ public: // Member Functions - //- Reconstruct volume internal field + //- Get status of write enabled (on this proc) + bool isWriteProc() const noexcept + { + return isWriteProc_; + } + + //- Change status of write enabled (on this proc) + bool isWriteProc(const bool on) noexcept + { + bool old(isWriteProc_); + isWriteProc_ = on; + return old; + } + + + //- Helper: reconstruct and write mesh points + // (note: should be moved to something like processorMeshes class) + void reconstructPoints(); + + //- Distribute all fields for known field types + void distributeAllFields + ( + const IOobjectList& objects, + const wordRes& selectedFields + ) const; + + //- Redistribute volume internal field template tmp> - reconstructFvVolumeInternalField + distributeField ( const DimensionedField& ) const; - //- Read and reconstruct volume internal field + //- Read and distribute volume internal field template tmp> - reconstructFvVolumeInternalField(const IOobject& fieldIoObject) const; + distributeInternalField(const IOobject& fieldObject) const; - - //- Reconstruct volume field + //- Redistribute volume field template tmp> - reconstructFvVolumeField + distributeField ( const GeometricField& fld ) const; - //- Read and reconstruct volume field + //- Read and distribute volume field template tmp> - reconstructFvVolumeField(const IOobject& fieldIoObject) const; + distributeVolumeField(const IOobject& fieldObject) const; - - //- Reconstruct surface field + //- Redistribute surface field template tmp> - reconstructFvSurfaceField + distributeField ( const GeometricField& ) const; - //- Read and reconstruct surface field + //- Read and distribute surface field template tmp> - reconstructFvSurfaceField(const IOobject& fieldIoObject) const; + distributeSurfaceField(const IOobject& fieldObject) const; - //- Read, reconstruct and write all/selected volume internal fields + //- Read, redistribute and write all/selected volume internal fields template - label reconstructFvVolumeInternalFields + label distributeInternalFields ( const IOobjectList& objects, const wordRes& selectedFields = wordRes() ) const; - //- Read, reconstruct and write all/selected volume fields + //- Read, redistribute and write all/selected volume fields template - label reconstructFvVolumeFields + label distributeVolumeFields ( const IOobjectList& objects, const wordRes& selectedFields = wordRes() @@ -169,15 +204,11 @@ public: //- Read, reconstruct and write all/selected surface fields template - label reconstructFvSurfaceFields + label distributeSurfaceFields ( const IOobjectList& objects, const wordRes& selectedFields = wordRes() ) const; - - //- Helper: reconstruct and write mesh points - // (note: should be moved to something like processorMeshes class) - void reconstructPoints(); }; @@ -188,7 +219,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository -# include "parFvFieldReconstructorFields.C" +# include "parFvFieldDistributorTemplates.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributorFields.C b/applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributorFields.C new file mode 100644 index 0000000000..3a0ae73d04 --- /dev/null +++ b/applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributorFields.C @@ -0,0 +1,62 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "parFvFieldDistributor.H" +#include "volFields.H" +#include "surfaceFields.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::parFvFieldDistributor::distributeAllFields +( + const IOobjectList& objects, + const wordRes& selectedFields +) const +{ + do + { + #undef doLocalCode + #define doLocalCode(Method) \ + { \ + this->Method (objects, selectedFields); \ + this->Method (objects, selectedFields); \ + this->Method (objects, selectedFields); \ + this->Method (objects, selectedFields); \ + this->Method (objects, selectedFields); \ + } + + doLocalCode(distributeInternalFields); + doLocalCode(distributeVolumeFields); + doLocalCode(distributeSurfaceFields); + + #undef doLocalCode + } + while (false); +} + + +// ************************************************************************* // diff --git a/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructorFields.C b/applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributorTemplates.C similarity index 53% rename from applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructorFields.C rename to applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributorTemplates.C index 4a31401764..7bbdf59c64 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructorFields.C +++ b/applications/utilities/parallelProcessing/redistributePar/parFvFieldDistributorTemplates.C @@ -26,7 +26,7 @@ License \*---------------------------------------------------------------------------*/ -#include "parFvFieldReconstructor.H" +#include "parFvFieldDistributor.H" #include "Time.H" #include "PtrList.H" #include "fvPatchFields.H" @@ -44,36 +44,33 @@ License template Foam::tmp> -Foam::parFvFieldReconstructor::reconstructFvVolumeInternalField +Foam::parFvFieldDistributor::distributeField ( const DimensionedField& fld ) const { + // Create internalField by remote mapping + distributedFieldMapper mapper ( labelUList::null(), distMap_.cellMap() ); - Field internalField(fld, mapper); - - // Construct a volField - IOobject baseIO - ( - fld.name(), - baseMesh_.time().timeName(), - fld.local(), - baseMesh_, - IOobject::NO_READ, - IOobject::NO_WRITE - ); - auto tfield = tmp>::New ( - baseIO, - baseMesh_, + IOobject + ( + fld.name(), + tgtMesh_.time().timeName(), + fld.local(), + tgtMesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + tgtMesh_, fld.dimensions(), - internalField + Field(fld, mapper) ); tfield.ref().oriented() = fld.oriented(); @@ -82,98 +79,86 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeInternalField } -template -Foam::tmp> -Foam::parFvFieldReconstructor::reconstructFvVolumeInternalField -( - const IOobject& fieldIoObject -) const -{ - // Read the field - DimensionedField fld - ( - fieldIoObject, - procMesh_ - ); - - // Distribute onto baseMesh - return reconstructFvVolumeInternalField(fld); -} - - -// Reconstruct a field onto the baseMesh template Foam::tmp> -Foam::parFvFieldReconstructor::reconstructFvVolumeField +Foam::parFvFieldDistributor::distributeField ( const GeometricField& fld ) const { - // Create the internalField by remote mapping - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - + // Create internalField by remote mapping distributedFieldMapper mapper ( labelUList::null(), distMap_.cellMap() ); - Field internalField(fld.internalField(), mapper); + DimensionedField internalField + ( + IOobject + ( + fld.name(), + tgtMesh_.time().timeName(), + fld.local(), + tgtMesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + tgtMesh_, + fld.dimensions(), + Field(fld.internalField(), mapper) + ); + + internalField.oriented() = fld.oriented(); + // Create patchFields by remote mapping + // Note: patchFields still on source mesh, not target mesh - // Create the patchFields by remote mapping - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // Note: patchFields still on mesh, not baseMesh - - PtrList> patchFields(fld.mesh().boundary().size()); + PtrList> oldPatchFields(fld.mesh().boundary().size()); const auto& bfld = fld.boundaryField(); - forAll(bfld, patchI) + forAll(bfld, patchi) { - if (patchFaceMaps_.set(patchI)) + if (patchFaceMaps_.set(patchi)) { // Clone local patch field - patchFields.set(patchI, bfld[patchI].clone()); + oldPatchFields.set(patchi, bfld[patchi].clone()); distributedFvPatchFieldMapper mapper ( labelUList::null(), - patchFaceMaps_[patchI] + patchFaceMaps_[patchi] ); // Map into local copy - patchFields[patchI].autoMap(mapper); + oldPatchFields[patchi].autoMap(mapper); } } - PtrList> basePatchFields - ( - baseMesh_.boundary().size() - ); - - // Clone the patchFields onto the base patches. This is just to reset + // Clone the oldPatchFields onto the target patches. This is just to reset // the reference to the patch, size and content stay the same. - forAll(patchFields, patchI) - { - if (patchFields.set(patchI)) - { - const fvPatch& basePatch = baseMesh_.boundary()[patchI]; - const fvPatchField& pfld = patchFields[patchI]; + PtrList> newPatchFields(tgtMesh_.boundary().size()); + + forAll(oldPatchFields, patchi) + { + if (oldPatchFields.set(patchi)) + { + const auto& pfld = oldPatchFields[patchi]; labelList dummyMap(identity(pfld.size())); directFvPatchFieldMapper dummyMapper(dummyMap); - basePatchFields.set + newPatchFields.set ( - patchI, + patchi, fvPatchField::New ( pfld, - basePatch, + tgtMesh_.boundary()[patchi], DimensionedField::null(), dummyMapper ) @@ -181,162 +166,143 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeField } } - // Add some empty patches on remaining patches (tbd.probably processor - // patches) - forAll(basePatchFields, patchI) + // Add some empty patches on remaining patches + // (... probably processor patches) + + forAll(newPatchFields, patchi) { - if (patchI >= patchFields.size() || !patchFields.set(patchI)) + if (!newPatchFields.set(patchi)) { - basePatchFields.set + newPatchFields.set ( - patchI, + patchi, fvPatchField::New ( emptyFvPatchField::typeName, - baseMesh_.boundary()[patchI], + tgtMesh_.boundary()[patchi], DimensionedField::null() ) ); } } - // Construct a volField - IOobject baseIO + // Return geometric field + + return tmp>::New ( - fld.name(), - baseMesh_.time().timeName(), - fld.local(), - baseMesh_, - IOobject::NO_READ, - IOobject::NO_WRITE + std::move(internalField), + newPatchFields ); - - auto tfield = tmp>::New - ( - baseIO, - baseMesh_, - fld.dimensions(), - internalField, - basePatchFields - ); - - tfield.ref().oriented()= fld.oriented(); - - return tfield; -} - - -template -Foam::tmp> -Foam::parFvFieldReconstructor::reconstructFvVolumeField -( - const IOobject& fieldIoObject -) const -{ - // Read the field - GeometricField fld - ( - fieldIoObject, - procMesh_ - ); - - // Distribute onto baseMesh - return reconstructFvVolumeField(fld); } template Foam::tmp> -Foam::parFvFieldReconstructor::reconstructFvSurfaceField +Foam::parFvFieldDistributor::distributeField ( const GeometricField& fld ) const { - // Create the internalField by remote mapping - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - + // Create internalField by remote mapping distributedFieldMapper mapper ( labelUList::null(), distMap_.faceMap() ); - // Create flat field of internalField + all patch fields - Field flatFld(fld.mesh().nFaces(), Type(Zero)); - SubList(flatFld, fld.internalField().size()) = fld.internalField(); - forAll(fld.boundaryField(), patchI) - { - const fvsPatchField& fvp = fld.boundaryField()[patchI]; - SubList(flatFld, fvp.size(), fvp.patch().start()) = fvp; + Field primitiveField; + { + // Create flat field of internalField + all patch fields + Field flatFld(fld.mesh().nFaces(), Type(Zero)); + SubList(flatFld, fld.internalField().size()) + = fld.internalField(); + + for (const fvsPatchField& fvp : fld.boundaryField()) + { + SubList(flatFld, fvp.size(), fvp.patch().start()) = fvp; + } + + // Map all faces + primitiveField = Field(flatFld, mapper, fld.oriented()()); + + // Trim to internal faces (note: could also have special mapper) + primitiveField.resize + ( + min + ( + primitiveField.size(), + tgtMesh_.nInternalFaces() + ) + ); } - // Map all faces - Field internalField(flatFld, mapper, fld.oriented()()); - // Trim to internal faces (note: could also have special mapper) - internalField.setSize + DimensionedField internalField ( - min + IOobject ( - internalField.size(), - baseMesh_.nInternalFaces() - ) + fld.name(), + tgtMesh_.time().timeName(), + fld.local(), + tgtMesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + tgtMesh_, + fld.dimensions(), + std::move(primitiveField) ); + internalField.oriented() = fld.oriented(); - // Create the patchFields by remote mapping - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // Note: patchFields still on mesh, not baseMesh - PtrList> patchFields(fld.mesh().boundary().size()); + // Create patchFields by remote mapping + // Note: patchFields still on source mesh, not target mesh + + PtrList> oldPatchFields(fld.mesh().boundary().size()); const auto& bfld = fld.boundaryField(); - forAll(bfld, patchI) + forAll(bfld, patchi) { - if (patchFaceMaps_.set(patchI)) + if (patchFaceMaps_.set(patchi)) { // Clone local patch field - patchFields.set(patchI, bfld[patchI].clone()); + oldPatchFields.set(patchi, bfld[patchi].clone()); distributedFvPatchFieldMapper mapper ( labelUList::null(), - patchFaceMaps_[patchI] + patchFaceMaps_[patchi] ); // Map into local copy - patchFields[patchI].autoMap(mapper); + oldPatchFields[patchi].autoMap(mapper); } } - PtrList> basePatchFields - ( - baseMesh_.boundary().size() - ); + PtrList> newPatchFields(tgtMesh_.boundary().size()); // Clone the patchFields onto the base patches. This is just to reset // the reference to the patch, size and content stay the same. - forAll(patchFields, patchI) + forAll(oldPatchFields, patchi) { - if (patchFields.set(patchI)) + if (oldPatchFields.set(patchi)) { - const fvPatch& basePatch = baseMesh_.boundary()[patchI]; - - const fvsPatchField& pfld = patchFields[patchI]; + const fvsPatchField& pfld = oldPatchFields[patchi]; labelList dummyMap(identity(pfld.size())); directFvPatchFieldMapper dummyMapper(dummyMap); - basePatchFields.set + newPatchFields.set ( - patchI, + patchi, fvsPatchField::New ( pfld, - basePatch, + tgtMesh_.boundary()[patchi], DimensionedField::null(), dummyMapper ) @@ -344,71 +310,94 @@ Foam::parFvFieldReconstructor::reconstructFvSurfaceField } } - // Add some empty patches on remaining patches (tbd.probably processor - // patches) - forAll(basePatchFields, patchI) + // Add some empty patches on remaining patches + // (... probably processor patches) + forAll(newPatchFields, patchi) { - if (patchI >= patchFields.size() || !patchFields.set(patchI)) + if (!newPatchFields.set(patchi)) { - basePatchFields.set + newPatchFields.set ( - patchI, + patchi, fvsPatchField::New ( emptyFvsPatchField::typeName, - baseMesh_.boundary()[patchI], + tgtMesh_.boundary()[patchi], DimensionedField::null() ) ); } } - // Construct a volField - IOobject baseIO + + // Return geometric field + return tmp>::New ( - fld.name(), - baseMesh_.time().timeName(), - fld.local(), - baseMesh_, - IOobject::NO_READ, - IOobject::NO_WRITE + std::move(internalField), + newPatchFields + ); +} + + +template +Foam::tmp> +Foam::parFvFieldDistributor::distributeInternalField +( + const IOobject& fieldObject +) const +{ + // Read field + DimensionedField fld + ( + fieldObject, + srcMesh_ ); - auto tfield = tmp>::New + // Distribute + return distributeField(fld); +} + + +template +Foam::tmp> +Foam::parFvFieldDistributor::distributeVolumeField +( + const IOobject& fieldObject +) const +{ + // Read field + GeometricField fld ( - baseIO, - baseMesh_, - fld.dimensions(), - internalField, - basePatchFields + fieldObject, + srcMesh_ ); - tfield.ref().oriented() = fld.oriented(); - - return tfield; + // Distribute + return distributeField(fld); } template Foam::tmp> -Foam::parFvFieldReconstructor::reconstructFvSurfaceField +Foam::parFvFieldDistributor::distributeSurfaceField ( - const IOobject& fieldIoObject + const IOobject& fieldObject ) const { - // Read the field + // Read field GeometricField fld ( - fieldIoObject, - procMesh_ + fieldObject, + srcMesh_ ); - return reconstructFvSurfaceField(fld); + // Distribute + return distributeField(fld); } template -Foam::label Foam::parFvFieldReconstructor::reconstructFvVolumeInternalFields +Foam::label Foam::parFvFieldDistributor::distributeInternalFields ( const IOobjectList& objects, const wordRes& selectedFields @@ -427,17 +416,25 @@ Foam::label Foam::parFvFieldReconstructor::reconstructFvVolumeInternalFields label nFields = 0; for (const word& fieldName : fieldNames) { - if (!nFields++) + if ("cellDist" == fieldName) { - Info<< " Reconstructing " - << fieldType::typeName << "s\n" << nl; + // There is an odd chance this is an internal field + continue; } - - Info<< " " << fieldName << nl; + if (verbose_) + { + if (!nFields) + { + Info<< " Reconstructing " + << fieldType::typeName << "s\n" << nl; + } + Info<< " " << fieldName << nl; + } + ++nFields; tmp tfld ( - reconstructFvVolumeInternalField(*(objects[fieldName])) + distributeInternalField(*(objects[fieldName])) ); if (isWriteProc_) { @@ -445,13 +442,13 @@ Foam::label Foam::parFvFieldReconstructor::reconstructFvVolumeInternalFields } } - if (nFields) Info<< endl; + if (nFields && verbose_) Info<< endl; return nFields; } template -Foam::label Foam::parFvFieldReconstructor::reconstructFvVolumeFields +Foam::label Foam::parFvFieldDistributor::distributeVolumeFields ( const IOobjectList& objects, const wordRes& selectedFields @@ -474,16 +471,20 @@ Foam::label Foam::parFvFieldReconstructor::reconstructFvVolumeFields { continue; } - if (!nFields++) + if (verbose_) { - Info<< " Reconstructing " - << fieldType::typeName << "s\n" << nl; + if (!nFields) + { + Info<< " Reconstructing " + << fieldType::typeName << "s\n" << nl; + } + Info<< " " << fieldName << nl; } - Info<< " " << fieldName << nl; + ++nFields; tmp tfld ( - reconstructFvVolumeField(*(objects[fieldName])) + distributeVolumeField(*(objects[fieldName])) ); if (isWriteProc_) { @@ -491,13 +492,13 @@ Foam::label Foam::parFvFieldReconstructor::reconstructFvVolumeFields } } - if (nFields) Info<< endl; + if (nFields && verbose_) Info<< endl; return nFields; } template -Foam::label Foam::parFvFieldReconstructor::reconstructFvSurfaceFields +Foam::label Foam::parFvFieldDistributor::distributeSurfaceFields ( const IOobjectList& objects, const wordRes& selectedFields @@ -516,16 +517,20 @@ Foam::label Foam::parFvFieldReconstructor::reconstructFvSurfaceFields label nFields = 0; for (const word& fieldName : fieldNames) { - if (!nFields++) + if (verbose_) { - Info<< " Reconstructing " - << fieldType::typeName << "s\n" << nl; + if (!nFields) + { + Info<< " Reconstructing " + << fieldType::typeName << "s\n" << nl; + } + Info<< " " << fieldName << nl; } - Info<< " " << fieldName << nl; + ++nFields; tmp tfld ( - reconstructFvSurfaceField(*(objects[fieldName])) + distributeSurfaceField(*(objects[fieldName])) ); if (isWriteProc_) { @@ -533,7 +538,7 @@ Foam::label Foam::parFvFieldReconstructor::reconstructFvSurfaceFields } } - if (nFields) Info<< endl; + if (nFields && verbose_) Info<< endl; return nFields; } diff --git a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.C b/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributor.C similarity index 96% rename from applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.C rename to applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributor.C index d0be2c50bb..2d8bb57a2d 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.C +++ b/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributor.C @@ -27,12 +27,12 @@ License \*---------------------------------------------------------------------------*/ #include "ListOps.H" -#include "parLagrangianRedistributor.H" +#include "parLagrangianDistributor.H" #include "passivePositionParticleCloud.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::parLagrangianRedistributor::parLagrangianRedistributor +Foam::parLagrangianDistributor::parLagrangianDistributor ( const fvMesh& srcMesh, const fvMesh& tgtMesh, @@ -59,7 +59,7 @@ Foam::parLagrangianRedistributor::parLagrangianRedistributor // Find all clouds (on all processors) and for each cloud all the objects. // Result will be synchronised on all processors -void Foam::parLagrangianRedistributor::findClouds +void Foam::parLagrangianDistributor::findClouds ( const fvMesh& mesh, wordList& cloudNames, @@ -129,7 +129,7 @@ void Foam::parLagrangianRedistributor::findClouds Foam::autoPtr -Foam::parLagrangianRedistributor::redistributeLagrangianPositions +Foam::parLagrangianDistributor::distributeLagrangianPositions ( passivePositionParticleCloud& lpi ) const @@ -314,7 +314,7 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions Foam::autoPtr -Foam::parLagrangianRedistributor::redistributeLagrangianPositions +Foam::parLagrangianDistributor::distributeLagrangianPositions ( const word& cloudName ) const @@ -322,7 +322,7 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions // Load cloud and send particle passivePositionParticleCloud lpi(srcMesh_, cloudName, false); - return redistributeLagrangianPositions(lpi); + return distributeLagrangianPositions(lpi); } diff --git a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.H b/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributor.H similarity index 69% rename from applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.H rename to applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributor.H index 5d66468efa..344c323a04 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributor.H +++ b/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributor.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ License along with OpenFOAM. If not, see . Class - Foam::parLagrangianRedistributor + Foam::parLagrangianDistributor Description Lagrangian field redistributor. @@ -33,13 +33,14 @@ Description Runs in parallel. Redistributes from fromMesh to toMesh. SourceFiles - parLagrangianRedistributor.C - parLagrangianRedistributorFields.C + parLagrangianDistributor.C + parLagrangianDistributorFields.C + parLagrangianDistributorTemplates.C \*---------------------------------------------------------------------------*/ -#ifndef parLagrangianRedistributor_H -#define parLagrangianRedistributor_H +#ifndef Foam_parLagrangianDistributor_H +#define Foam_parLagrangianDistributor_H #include "PtrList.H" #include "fvMesh.H" @@ -49,19 +50,19 @@ SourceFiles namespace Foam { -// Forward declarations +// Forward Declarations class mapDistributePolyMesh; class mapDistributeBase; class IOobjectList; class passivePositionParticleCloud; /*---------------------------------------------------------------------------*\ - Class parLagrangianRedistributor Declaration + Class parLagrangianDistributor Declaration \*---------------------------------------------------------------------------*/ -class parLagrangianRedistributor +class parLagrangianDistributor { - // Private data + // Private Data //- Source mesh reference const fvMesh& srcMesh_; @@ -82,10 +83,10 @@ class parLagrangianRedistributor // Private Member Functions //- No copy construct - parLagrangianRedistributor(const parLagrangianRedistributor&) = delete; + parLagrangianDistributor(const parLagrangianDistributor&) = delete; //- No copy assignment - void operator=(const parLagrangianRedistributor&) = delete; + void operator=(const parLagrangianDistributor&) = delete; public: @@ -93,7 +94,7 @@ public: // Constructors //- Construct from components - parLagrangianRedistributor + parLagrangianDistributor ( const fvMesh& srcMesh, const fvMesh& tgtMesh, @@ -102,10 +103,10 @@ public: ); - // Member Functions + // Static Functions //- Find all clouds (on all processors) and for each cloud all - // the objects. Result will be synchronised on all processors + //- the objects. Result will be synchronised on all processors static void findClouds ( const fvMesh&, @@ -113,18 +114,6 @@ public: List& objectNames ); - //- Redistribute and write lagrangian positions - autoPtr redistributeLagrangianPositions - ( - passivePositionParticleCloud& cloud - ) const; - - //- Read, redistribute and write lagrangian positions - autoPtr redistributeLagrangianPositions - ( - const word& cloudName - ) const; - //- Pick up any fields of a given type template static wordList filterObjects @@ -133,26 +122,6 @@ public: const wordRes& selectedFields = wordRes() ); - //- Read, redistribute and write all/selected lagrangian fields - template - label redistributeFields - ( - const mapDistributeBase& map, - const word& cloudName, - const IOobjectList& objects, - const wordRes& selectedFields = wordRes() - ) const; - - //- Read, redistribute and write all/selected lagrangian fieldFields - template - label redistributeFieldFields - ( - const mapDistributeBase& map, - const word& cloudName, - const IOobjectList& objects, - const wordRes& selectedFields = wordRes() - ) const; - //- Read and store all fields of a cloud template static label readFields @@ -162,14 +131,81 @@ public: const wordRes& selectedFields = wordRes() ); + //- Read and store all fields for known cloud field types + static label readAllFields + ( + const passivePositionParticleCloud& cloud, + const IOobjectList& objects, + const wordRes& selectedFields = wordRes() + ); + + //- Read and store all fields for known cloud field types + // Uses the current cloud instance to obtain the IOobjectList + static label readAllFields + ( + const passivePositionParticleCloud& cloud, + const wordRes& selectedFields = wordRes() + ); + + + // Member Functions + + //- Redistribute and write lagrangian positions + autoPtr distributeLagrangianPositions + ( + passivePositionParticleCloud& cloud + ) const; + + //- Read, redistribute and write lagrangian positions + autoPtr distributeLagrangianPositions + ( + const word& cloudName + ) const; + + //- Redistribute all fields for known cloud field types + label distributeAllFields + ( + const mapDistributeBase& lagrangianMap, + const word& cloudName, + const IOobjectList& cloudObjs, + const wordRes& selectedFields + ) const; + + //- Redistribute and write all stored lagrangian fields + label distributeAllStoredFields + ( + const mapDistributeBase& lagrangianMap, + passivePositionParticleCloud& cloud + ) const; + + + //- Read, redistribute and write all/selected lagrangian fields + template + label distributeFields + ( + const mapDistributeBase& map, + const word& cloudName, + const IOobjectList& objects, + const wordRes& selectedFields = wordRes() + ) const; + + //- Read, redistribute and write all/selected lagrangian fieldFields + template + label distributeFieldFields + ( + const mapDistributeBase& map, + const word& cloudName, + const IOobjectList& objects, + const wordRes& selectedFields = wordRes() + ) const; + //- Redistribute and write stored lagrangian fields template - label redistributeStoredFields + label distributeStoredFields ( const mapDistributeBase& map, passivePositionParticleCloud& cloud ) const; - }; @@ -180,7 +216,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository -# include "parLagrangianRedistributorFields.C" +# include "parLagrangianDistributorTemplates.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributorFields.C b/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributorFields.C new file mode 100644 index 0000000000..730c3fcc1b --- /dev/null +++ b/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributorFields.C @@ -0,0 +1,195 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "parLagrangianDistributor.H" +#include "unmappedPassivePositionParticleCloud.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::label Foam::parLagrangianDistributor::readAllFields +( + const passivePositionParticleCloud& cloud, + const IOobjectList& cloudObjs, + const wordRes& selectedFields +) +{ + label nTotal = 0; + + do + { + #undef doLocalCode + #define doLocalCode(Type) \ + { \ + nTotal += parLagrangianDistributor::readFields \ + > \ + ( \ + cloud, \ + cloudObjs, \ + selectedFields \ + ); \ + \ + nTotal += parLagrangianDistributor::readFields \ + >> \ + ( \ + cloud, \ + cloudObjs, \ + selectedFields \ + ); \ + \ + nTotal += parLagrangianDistributor::readFields \ + , Type>> \ + ( \ + cloud, \ + cloudObjs, \ + selectedFields \ + ); \ + } + + doLocalCode(label); + doLocalCode(scalar); + doLocalCode(vector); + doLocalCode(sphericalTensor); + doLocalCode(symmTensor); + doLocalCode(tensor); + + #undef doLocalCode + } + while (false); + + return nTotal; +} + + +Foam::label Foam::parLagrangianDistributor::readAllFields +( + const passivePositionParticleCloud& cloud, + const wordRes& selectedFields +) +{ + IOobjectList cloudObjs(cloud, cloud.time().timeName()); + return readAllFields(cloud, cloudObjs, selectedFields); +} + + +Foam::label Foam::parLagrangianDistributor::distributeAllFields +( + const mapDistributeBase& lagrangianMap, + const word& cloudName, + const IOobjectList& cloudObjs, + const wordRes& selectedFields +) const +{ + label nTotal = 0; + + do + { + #undef doLocalCode + #define doLocalCode(Type) \ + { \ + nTotal += this->distributeFields \ + ( \ + lagrangianMap, \ + cloudName, \ + cloudObjs, \ + selectedFields \ + ); \ + \ + nTotal += this->distributeFieldFields \ + ( \ + lagrangianMap, \ + cloudName, \ + cloudObjs, \ + selectedFields \ + ); \ + } + + doLocalCode(label); + doLocalCode(scalar); + doLocalCode(vector); + doLocalCode(sphericalTensor); + doLocalCode(symmTensor); + doLocalCode(tensor); + + #undef doLocalCode + } + while (false); + + return nTotal; +} + + +Foam::label Foam::parLagrangianDistributor::distributeAllStoredFields +( + const mapDistributeBase& lagrangianMap, + passivePositionParticleCloud& cloud +) const +{ + label nTotal = 0; + + do + { + #undef doLocalCode + #define doLocalCode(Type) \ + { \ + nTotal += this->distributeStoredFields \ + > \ + ( \ + lagrangianMap, \ + cloud \ + ); \ + \ + nTotal += this->distributeStoredFields \ + >> \ + ( \ + lagrangianMap, \ + cloud \ + ); \ + \ + nTotal += this->distributeStoredFields \ + , Type>> \ + ( \ + lagrangianMap, \ + cloud \ + ); \ + } + + doLocalCode(label); + doLocalCode(scalar); + doLocalCode(vector); + doLocalCode(sphericalTensor); + doLocalCode(symmTensor); + doLocalCode(tensor); + + #undef doLocalCode + } + while (false); + + return nTotal; +} + + +// ************************************************************************* // diff --git a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributorFields.C b/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributorTemplates.C similarity index 79% rename from applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributorFields.C rename to applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributorTemplates.C index 0bbf52f8ff..c30fd6f7b6 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributorFields.C +++ b/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributorTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,18 +26,19 @@ License \*---------------------------------------------------------------------------*/ -#include "parLagrangianRedistributor.H" +#include "parLagrangianDistributor.H" #include "Time.H" #include "IOobjectList.H" #include "mapDistributePolyMesh.H" #include "cloud.H" #include "CompactIOField.H" +#include "DynamicList.H" #include "passivePositionParticleCloud.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -Foam::wordList Foam::parLagrangianRedistributor::filterObjects +Foam::wordList Foam::parLagrangianDistributor::filterObjects ( const IOobjectList& objects, const wordRes& selectedFields @@ -64,7 +65,7 @@ Foam::wordList Foam::parLagrangianRedistributor::filterObjects template -Foam::label Foam::parLagrangianRedistributor::redistributeFields +Foam::label Foam::parLagrangianDistributor::distributeFields ( const mapDistributeBase& map, const word& cloudName, @@ -76,7 +77,7 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFields const wordList fieldNames ( - filterObjects> + filterObjects ( objects, selectedFields @@ -88,7 +89,7 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFields { if (!nFields) { - Info<< " Redistributing lagrangian " + Info<< " Distributing lagrangian " << fieldType::typeName << "s\n" << endl; } Info<< " " << objectName << endl; @@ -125,11 +126,7 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFields if (field.size()) { - IOField - ( - fieldIO, - std::move(field) - ).write(); + IOField(fieldIO, std::move(field)).write(); } else { @@ -146,7 +143,7 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFields template -Foam::label Foam::parLagrangianRedistributor::redistributeFieldFields +Foam::label Foam::parLagrangianDistributor::distributeFieldFields ( const mapDistributeBase& map, const word& cloudName, @@ -156,7 +153,9 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFieldFields { typedef CompactIOField, Type> fieldType; - wordList fieldNames + DynamicList fieldNames; + + fieldNames.append ( filterObjects ( @@ -166,27 +165,30 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFieldFields ); // Append IOField Field names - { - wordList ioFieldNames + fieldNames.append + ( + filterObjects>> ( - filterObjects>> - ( - objects, - selectedFields - ) - ); - fieldNames.append(ioFieldNames); - } + objects, + selectedFields + ) + ); + + const bool verbose_ = true; label nFields = 0; for (const word& objectName : fieldNames) { - if (!nFields++) + if (verbose_) { - Info<< " Redistributing lagrangian " - << fieldType::typeName << "s\n" << nl; + if (!nFields) + { + Info<< " Distributing lagrangian " + << fieldType::typeName << "s\n" << nl; + } + Info<< " " << objectName << nl; } - Info<< " " << objectName << nl; + ++nFields; // Read if present CompactIOField, Type> field @@ -237,13 +239,13 @@ Foam::label Foam::parLagrangianRedistributor::redistributeFieldFields } } - if (nFields) Info<< endl; + if (nFields && verbose_) Info<< endl; return nFields; } template -Foam::label Foam::parLagrangianRedistributor::readFields +Foam::label Foam::parLagrangianDistributor::readFields ( const passivePositionParticleCloud& cloud, const IOobjectList& objects, @@ -261,15 +263,21 @@ Foam::label Foam::parLagrangianRedistributor::readFields ) ); + const bool verbose_ = true; + label nFields = 0; for (const word& objectName : fieldNames) { - if (!nFields++) + if (verbose_) { - Info<< " Reading lagrangian " - << Container::typeName << "s\n" << nl; + if (!nFields) + { + Info<< " Reading lagrangian " + << Container::typeName << "s\n" << nl; + } + Info<< " " << objectName << nl; } - Info<< " " << objectName << nl; + ++nFields; // Read if present Container* fieldPtr = new Container @@ -288,12 +296,13 @@ Foam::label Foam::parLagrangianRedistributor::readFields fieldPtr->store(); } + if (nFields && verbose_) Info<< endl; return nFields; } template -Foam::label Foam::parLagrangianRedistributor::redistributeStoredFields +Foam::label Foam::parLagrangianDistributor::distributeStoredFields ( const mapDistributeBase& map, passivePositionParticleCloud& cloud @@ -304,17 +313,23 @@ Foam::label Foam::parLagrangianRedistributor::redistributeStoredFields cloud.lookupClass() ); + const bool verbose_ = true; + label nFields = 0; forAllIters(fields, iter) { Container& field = *(iter.val()); - if (!nFields++) + if (verbose_) { - Info<< " Redistributing lagrangian " - << Container::typeName << "s\n" << endl; + if (!nFields) + { + Info<< " Distributing lagrangian " + << Container::typeName << "s\n" << endl; + } + Info<< " " << field.name() << endl; } - Info<< " " << field.name() << endl; + ++nFields; map.distribute(field); @@ -331,11 +346,7 @@ Foam::label Foam::parLagrangianRedistributor::redistributeStoredFields if (field.size()) { - Container - ( - fieldIO, - std::move(field) - ).write(); + Container(fieldIO, std::move(field)).write(); } else { @@ -347,6 +358,7 @@ Foam::label Foam::parLagrangianRedistributor::redistributeStoredFields } } + if (nFields && verbose_) Info<< endl; return nFields; } diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributeLagrangian.H b/applications/utilities/parallelProcessing/redistributePar/redistributeLagrangian.H new file mode 100644 index 0000000000..99f08b3c29 --- /dev/null +++ b/applications/utilities/parallelProcessing/redistributePar/redistributeLagrangian.H @@ -0,0 +1,230 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2015-2022 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Description + Reading, reconstruct, redistribution of lagrangian fields. + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_redistributeLagrangian_H +#define Foam_redistributeLagrangian_H + +#include "parLagrangianDistributor.H" +#include "unmappedPassivePositionParticleCloud.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Read clouds (note: might not be present on all processors) +PtrList +readLagrangian +( + const fvMesh& mesh, + const wordList& cloudNames, + const wordRes& selectedFields +) +{ + PtrList clouds(cloudNames.size()); + + if (!cloudNames.empty()) + { + (void)mesh.tetBasePtIs(); + } + + // Setup clouds + forAll(cloudNames, i) + { + //Pout<< "Loading cloud " << cloudNames[i] << endl; + clouds.set + ( + i, + new unmappedPassivePositionParticleCloud(mesh, cloudNames[i], false) + ); + + //for (passivePositionParticle& p : clouds[i])) + //{ + // Pout<< "Particle position:" << p.position() + // << " cell:" << p.cell() + // << " with cc:" << mesh.cellCentres()[p.cell()] + // << endl; + //} + + IOobjectList cloudObjs(clouds[i], clouds[i].time().timeName()); + + //Pout<< "Found cloud objects:" << cloudObjs.names() << endl; + + parLagrangianDistributor::readAllFields + ( + clouds[i], + cloudObjs, + selectedFields + ); + } + + return clouds; +} + + +// Read clouds (note: might not be present on all processors) +PtrList +readLagrangian +( + const fvMesh& mesh, + const wordRes& selectedFields +) +{ + wordList cloudNames; + List fieldNames; + // Find all cloudNames on all processors + parLagrangianDistributor::findClouds(mesh, cloudNames, fieldNames); + + return readLagrangian(mesh, cloudNames, selectedFields); +} + + +void reconstructLagrangian +( + autoPtr& distributorPtr, + const fvMesh& baseMesh, + const fvMesh& mesh, + const mapDistributePolyMesh& distMap, + const wordRes& selectedFields +) +{ + // Clouds (note: might not be present on all processors) + + wordList cloudNames; + List fieldNames; + // Find all cloudNames on all processors + parLagrangianDistributor::findClouds(mesh, cloudNames, fieldNames); + + if (cloudNames.empty()) + { + // Nothing to do + return; + } + + // Use existing or create distributor + if (!distributorPtr) + { + distributorPtr.reset + ( + new parLagrangianDistributor + ( + mesh, + baseMesh, + mesh.nCells(), // range of cell indices in clouds + distMap + ) + ); + } + const auto& distributor = *distributorPtr; + + for (const word& cloudName : cloudNames) + { + Info<< "Reconstructing lagrangian fields for cloud " + << cloudName << nl << endl; + + IOobjectList cloudObjs + ( + mesh, + mesh.time().timeName(), + cloud::prefix/cloudName + ); + + autoPtr lagrangianMapPtr = + distributor.distributeLagrangianPositions + ( + cloudName + ); + + distributor.distributeAllFields + ( + lagrangianMapPtr(), + cloudName, + cloudObjs, + selectedFields + ); + } +} + + +void redistributeLagrangian +( + autoPtr& distributorPtr, + const fvMesh& mesh, + const label nOldCells, + const mapDistributePolyMesh& distMap, + PtrList& clouds +) +{ + if (clouds.empty()) + { + // Nothing to do + return; + } + + // Use existing or create distributor + if (!distributorPtr) + { + distributorPtr.reset + ( + new parLagrangianDistributor + ( + mesh, + mesh, + nOldCells, // range of cell indices in clouds + distMap + ) + ); + } + const auto& distributor = *distributorPtr; + + for (auto& cloud : clouds) + { + autoPtr lagrangianMapPtr = + distributor.distributeLagrangianPositions(cloud); + + distributor.distributeAllStoredFields + ( + lagrangianMapPtr(), + cloud + ); + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C index c148c3d9e8..f4d5a4cda4 100644 --- a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C +++ b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C @@ -94,14 +94,15 @@ Usage #include "topoSet.H" #include "regionProperties.H" -#include "parFvFieldReconstructor.H" +#include "parFvFieldDistributor.H" #include "parPointFieldDistributor.H" -#include "parLagrangianRedistributor.H" -#include "unmappedPassivePositionParticleCloud.H" #include "hexRef8Data.H" #include "meshRefinement.H" #include "pointFields.H" +#include "readDistributedFields.H" +#include "redistributeLagrangian.H" + #include "cyclicACMIFvPatch.H" #include "masterUncollatedFileOperation.H" #include "uncollatedFileOperation.H" @@ -498,7 +499,7 @@ void determineDecomposition if (Pstream::master() && decompose) { - Info<< "Restoring caseName to " << proc0CaseName << endl; + Info<< "Restoring caseName" << endl; tm.caseName() = proc0CaseName; tm.processorCase(oldProcCase); } @@ -519,7 +520,7 @@ void determineDecomposition tm.caseName() = baseRunTime.caseName(); tm.processorCase(false); writeDecomposition("cellDist", mesh, decomp); - Info<< "Restoring caseName to " << proc0CaseName << endl; + Info<< "Restoring caseName" << endl; tm.caseName() = proc0CaseName; tm.processorCase(oldProcCase); @@ -539,14 +540,8 @@ void determineDecomposition template void correctCoupledBoundaryConditions(fvMesh& mesh) { - HashTable flds - ( - mesh.objectRegistry::lookupClass() - ); - - for (const word& fldName : flds.sortedToc()) + for (GeoField& fld : mesh.sorted()) { - GeoField& fld = *(flds[fldName]); fld.boundaryFieldRef().template evaluateCoupled(); } } @@ -755,7 +750,7 @@ autoPtr redistributeAndWrite fvMeshDistribute distributor(mesh); // Do all the distribution of mesh and fields - autoPtr rawMap = distributor.distribute(decomp); + autoPtr distMap = distributor.distribute(decomp); // Print some statistics Info<< "After distribution:" << endl; @@ -786,7 +781,7 @@ autoPtr redistributeAndWrite // Construct new pointMesh from distributed mesh const pointMesh& newPointMesh = pointMesh::New(mesh); - pointDistributor.resetTarget(newPointMesh, rawMap()); + pointDistributor.resetTarget(newPointMesh, distMap()); pointDistributor.distributeAndStore(pointScalarFields); pointDistributor.distributeAndStore(pointVectorFields); @@ -811,19 +806,20 @@ autoPtr redistributeAndWrite } - IOmapDistributePolyMesh map + // Register mapDistributePolyMesh for automatic writing... + IOmapDistributePolyMeshRef distMapRef ( IOobject ( "procAddressing", mesh.facesInstance(), polyMesh::meshSubDir, - mesh, + mesh.thisDb(), IOobject::NO_READ, IOobject::AUTO_WRITE - ) + ), + distMap() ); - map.transfer(rawMap()); if (reconstruct) @@ -839,7 +835,7 @@ autoPtr redistributeAndWrite topoSet::removeFiles(mesh); // Now we've written all. Reset caseName on master - Info<< "Restoring caseName to " << proc0CaseName << endl; + Info<< "Restoring caseName" << endl; runTime.caseName() = proc0CaseName; runTime.processorCase(oldProcCase); } @@ -860,8 +856,8 @@ autoPtr redistributeAndWrite } topoSet::removeFiles(mesh); } - Info<< "Written redistributed mesh to " << mesh.facesInstance() << nl - << endl; + Info<< "Written redistributed mesh to " + << mesh.facesInstance() << nl << endl; if (decompose || reconstruct) @@ -871,7 +867,7 @@ autoPtr redistributeAndWrite fvMeshTools::writeProcAddressing ( mesh, - map, + distMap(), decompose, std::move(writeHandler) ); @@ -917,7 +913,7 @@ autoPtr redistributeAndWrite refData.sync(io); // Distribute - refData.distribute(map); + refData.distribute(distMap()); // Now we've read refinement data we can remove it @@ -937,7 +933,7 @@ autoPtr redistributeAndWrite refData.write(); // Now we've written all. Reset caseName on master - Info<< "Restoring caseName to " << proc0CaseName << endl; + Info<< "Restoring caseName" << endl; runTime.caseName() = proc0CaseName; runTime.processorCase(oldProcCase); @@ -971,7 +967,7 @@ autoPtr redistributeAndWrite // // forAll(cellSets, i) // { - // cellSets[i].distribute(map); + // cellSets[i].distribute(distMap()); // } // // if (reconstruct) @@ -985,11 +981,11 @@ autoPtr redistributeAndWrite // // forAll(cellSets, i) // { - // cellSets[i].distribute(map); + // cellSets[i].distribute(distMap()); // } // // // Now we've written all. Reset caseName on master - // Info<< "Restoring caseName to " << proc0CaseName << endl; + // Info<< "Restoring caseName" << endl; // runTime.caseName() = proc0CaseName; // runTime.processorCase(oldProcCase); // } @@ -998,592 +994,19 @@ autoPtr redistributeAndWrite // { // forAll(cellSets, i) // { - // cellSets[i].distribute(map); + // cellSets[i].distribute(distMap()); // } // } //} - return autoPtr::New(std::move(map)); + return distMap; } -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// -// Field Mapping -// -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -void reconstructMeshFields -( - const parFvFieldReconstructor& fvReconstructor, - const IOobjectList& objects, - const wordRes& selectedFields -) -{ - // Dimensioned fields - - fvReconstructor.reconstructFvVolumeInternalFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvVolumeInternalFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvVolumeInternalFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvVolumeInternalFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvVolumeInternalFields - ( - objects, - selectedFields - ); - - - // volFields - - fvReconstructor.reconstructFvVolumeFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvVolumeFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvVolumeFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvVolumeFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvVolumeFields - ( - objects, - selectedFields - ); - - - // surfaceFields - - fvReconstructor.reconstructFvSurfaceFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvSurfaceFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvSurfaceFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvSurfaceFields - ( - objects, - selectedFields - ); - fvReconstructor.reconstructFvSurfaceFields - ( - objects, - selectedFields - ); -} - - -void reconstructLagrangian -( - autoPtr& lagrangianReconstructorPtr, - const fvMesh& baseMesh, - const fvMesh& mesh, - const mapDistributePolyMesh& distMap, - const wordRes& selectedLagrangianFields -) -{ - // Clouds (note: might not be present on all processors) - - wordList cloudNames; - List fieldNames; - // Find all cloudNames on all processors - parLagrangianRedistributor::findClouds(mesh, cloudNames, fieldNames); - - if (cloudNames.size()) - { - if (!lagrangianReconstructorPtr) - { - lagrangianReconstructorPtr.reset - ( - new parLagrangianRedistributor - ( - mesh, - baseMesh, - mesh.nCells(), // range of cell indices in clouds - distMap - ) - ); - } - const parLagrangianRedistributor& lagrangianReconstructor = - *lagrangianReconstructorPtr; - - for (const word& cloudName : cloudNames) - { - Info<< "Reconstructing lagrangian fields for cloud " - << cloudName << nl << endl; - - autoPtr lagrangianMapPtr = - lagrangianReconstructor.redistributeLagrangianPositions - ( - cloudName - ); - - const mapDistributeBase& lagrangianMap = *lagrangianMapPtr; - - IOobjectList cloudObjs - ( - mesh, - mesh.time().timeName(), - cloud::prefix/cloudName - ); - - lagrangianReconstructor.redistributeFields