ENH: code modernization for decompose/reconstruct

- simplify procAddressing read/write

- avoid accessing points in faMeshReconstructor.
  Can rely on the patch meshPoints (labelList), which does not need
  access to a pointField

- report number of points on decomposed mesh.
  Can be useful additional information.
  Additional statistics for finite area decomposition

- provide bundled reconstructAllFields for various reconstructors

- remove reconstructPar checks for very old face addressing
  (from foam2.0 - ie, older than OpenFOAM itself)

- bundle all reading into fieldsDistributor tools,
  where it can be reused by various utilities as required.

- combine decomposition fields as respective fieldsCache
  which eliminates most of the clutter from decomposePar
  and similfies reuse in the future.

STYLE: remove old wordHashSet selection (deprecated in 2018)

BUG: incorrect face flip handling for faMeshReconstructor

- a latent bug which is not yet triggered since the faMesh faces are
  currently only definable on boundary faces (which never flip)
This commit is contained in:
Mark Olesen
2022-04-24 15:06:40 +02:00
committed by Andrew Heather
parent eccc998ed2
commit 3b6761afed
51 changed files with 3270 additions and 2443 deletions

View File

@ -25,11 +25,7 @@ if (doDecompose && Pstream::parRun())
// Handle area fields
// ------------------
PtrList<areaScalarField> areaScalarFields;
PtrList<areaVectorField> areaVectorFields;
PtrList<areaSphericalTensorField> areaSphTensorFields;
PtrList<areaSymmTensorField> areaSymmTensorFields;
PtrList<areaTensorField> areaTensorFields;
faFieldDecomposer::fieldsCache areaFieldsCache;
const faMesh& fullMesh = reconstructor.mesh();
@ -51,26 +47,7 @@ if (doDecompose && Pstream::parRun())
IOobjectList objects(fullMesh.time(), runTime.timeName());
faFieldDecomposer::readFields
(
fullMesh, objects, areaScalarFields
);
faFieldDecomposer::readFields
(
fullMesh, objects, areaVectorFields
);
faFieldDecomposer::readFields
(
fullMesh, objects, areaSphTensorFields
);
faFieldDecomposer::readFields
(
fullMesh, objects, areaSymmTensorFields
);
faFieldDecomposer::readFields
(
fullMesh, objects, areaTensorFields
);
areaFieldsCache.readAllFields(fullMesh, objects);
// Restore old settings
if (oldHandler)
@ -81,14 +58,7 @@ if (doDecompose && Pstream::parRun())
}
}
const label nAreaFields =
(
areaScalarFields.size()
+ areaVectorFields.size()
+ areaSphTensorFields.size()
+ areaSymmTensorFields.size()
+ areaTensorFields.size()
);
const label nAreaFields = areaFieldsCache.size();
if (nAreaFields)
{
@ -103,41 +73,8 @@ if (doDecompose && Pstream::parRun())
reconstructor.boundaryProcAddressing()
);
if (areaScalarFields.size())
{
Info<< " scalars: "
<< flatOutput(PtrListOps::names(areaScalarFields)) << nl;
fieldDecomposer.decomposeFields(areaScalarFields);
}
if (areaVectorFields.size())
{
Info<< " vectors: "
<< flatOutput(PtrListOps::names(areaVectorFields)) << nl;
fieldDecomposer.decomposeFields(areaVectorFields);
}
if (areaSphTensorFields.size())
{
Info<< " sphTensors: "
<< flatOutput(PtrListOps::names(areaSphTensorFields)) << nl;
fieldDecomposer.decomposeFields(areaSphTensorFields);
}
if (areaSymmTensorFields.size())
{
Info<< " symmTensors: "
<< flatOutput(PtrListOps::names(areaSymmTensorFields)) << nl;
fieldDecomposer.decomposeFields(areaSymmTensorFields);
}
if (areaTensorFields.size())
{
Info<< " tensors: "
<< flatOutput(PtrListOps::names(areaTensorFields)) << nl;
fieldDecomposer.decomposeFields(areaTensorFields);
}
// Report
areaFieldsCache.decomposeAllFields(fieldDecomposer, true);
Info<< endl;
}
}

View File

@ -46,6 +46,7 @@ Original Authors
#include "IOobjectList.H"
#include "areaFields.H"
#include "edgeFields.H"
#include "faFieldDecomposer.H"
#include "faMeshReconstructor.H"
#include "PtrListOps.H"

View File

@ -8,6 +8,4 @@ domainDecompositionWrite.C
domainDecompositionDryRun.C
domainDecompositionDryRunWrite.C
lagrangianFieldDecomposer.C
EXE = $(FOAM_APPBIN)/decomposePar

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -150,29 +150,19 @@ Usage
#include "domainDecomposition.H"
#include "domainDecompositionDryRun.H"
#include "labelIOField.H"
#include "labelFieldIOField.H"
#include "scalarIOField.H"
#include "scalarFieldIOField.H"
#include "vectorIOField.H"
#include "vectorFieldIOField.H"
#include "sphericalTensorIOField.H"
#include "sphericalTensorFieldIOField.H"
#include "symmTensorIOField.H"
#include "symmTensorFieldIOField.H"
#include "tensorIOField.H"
#include "tensorFieldIOField.H"
#include "pointFields.H"
#include "regionProperties.H"
#include "readFields.H"
#include "fieldsDistributor.H"
#include "fvFieldDecomposer.H"
#include "pointFields.H"
#include "pointFieldDecomposer.H"
#include "lagrangianFieldDecomposer.H"
#include "emptyFaPatch.H"
#include "faMeshDecomposition.H"
#include "faFieldDecomposer.H"
#include "faMeshDecomposition.H"
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
@ -838,58 +828,14 @@ int main(int argc, char *argv[])
}
// Vol fields
// ~~~~~~~~~~
PtrList<volScalarField> volScalarFields;
PtrList<volVectorField> volVectorFields;
PtrList<volSphericalTensorField> volSphTensorFields;
PtrList<volSymmTensorField> volSymmTensorFields;
PtrList<volTensorField> volTensorFields;
// Volume/surface/internal fields
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fvFieldDecomposer::fieldsCache volumeFieldCache;
if (doDecompFields)
{
readFields(mesh, objects, volScalarFields, false);
readFields(mesh, objects, volVectorFields, false);
readFields(mesh, objects, volSphTensorFields, false);
readFields(mesh, objects, volSymmTensorFields, false);
readFields(mesh, objects, volTensorFields, false);
}
// Internal fields
// ~~~~~~~~~~~~~~~
PtrList<DimensionedField<scalar, volMesh>> dimScalarFields;
PtrList<DimensionedField<vector, volMesh>> dimVectorFields;
PtrList<DimensionedField<sphericalTensor, volMesh>>
dimSphTensorFields;
PtrList<DimensionedField<symmTensor, volMesh>>
dimSymmTensorFields;
PtrList<DimensionedField<tensor, volMesh>> dimTensorFields;
if (doDecompFields)
{
readFields(mesh, objects, dimScalarFields);
readFields(mesh, objects, dimVectorFields);
readFields(mesh, objects, dimSphTensorFields);
readFields(mesh, objects, dimSymmTensorFields);
readFields(mesh, objects, dimTensorFields);
}
// Surface fields
// ~~~~~~~~~~~~~~
PtrList<surfaceScalarField> surfaceScalarFields;
PtrList<surfaceVectorField> surfaceVectorFields;
PtrList<surfaceSphericalTensorField>
surfaceSphTensorFields;
PtrList<surfaceSymmTensorField> surfaceSymmTensorFields;
PtrList<surfaceTensorField> surfaceTensorFields;
if (doDecompFields)
{
readFields(mesh, objects, surfaceScalarFields, false);
readFields(mesh, objects, surfaceVectorFields, false);
readFields(mesh, objects, surfaceSphTensorFields, false);
readFields(mesh, objects, surfaceSymmTensorFields, false);
readFields(mesh, objects, surfaceTensorFields, false);
volumeFieldCache.readAllFields(mesh, objects);
}
@ -897,19 +843,11 @@ int main(int argc, char *argv[])
// ~~~~~~~~~~~~
const pointMesh& pMesh = pointMesh::New(mesh);
PtrList<pointScalarField> pointScalarFields;
PtrList<pointVectorField> pointVectorFields;
PtrList<pointSphericalTensorField> pointSphTensorFields;
PtrList<pointSymmTensorField> pointSymmTensorFields;
PtrList<pointTensorField> pointTensorFields;
pointFieldDecomposer::fieldsCache pointFieldCache;
if (doDecompFields)
{
readFields(pMesh, objects, pointScalarFields, false);
readFields(pMesh, objects, pointVectorFields, false);
readFields(pMesh, objects, pointSphTensorFields, false);
readFields(pMesh, objects, pointSymmTensorFields, false);
readFields(pMesh, objects, pointTensorFields, false);
pointFieldCache.readAllFields(pMesh, objects);
}
@ -938,63 +876,10 @@ int main(int argc, char *argv[])
cloudDirs.size()
);
PtrList<PtrList<labelIOField>> lagrangianLabelFields
lagrangianFieldDecomposer::fieldsCache lagrangianFieldCache
(
cloudDirs.size()
);
PtrList<PtrList<labelFieldCompactIOField>>
lagrangianLabelFieldFields
(
cloudDirs.size()
);
PtrList<PtrList<scalarIOField>> lagrangianScalarFields
(
cloudDirs.size()
);
PtrList<PtrList<scalarFieldCompactIOField>>
lagrangianScalarFieldFields
(
cloudDirs.size()
);
PtrList<PtrList<vectorIOField>> lagrangianVectorFields
(
cloudDirs.size()
);
PtrList<PtrList<vectorFieldCompactIOField>>
lagrangianVectorFieldFields
(
cloudDirs.size()
);
PtrList<PtrList<sphericalTensorIOField>>
lagrangianSphTensorFields
(
cloudDirs.size()
);
PtrList<PtrList<sphericalTensorFieldCompactIOField>>
lagrangianSphTensorFieldFields
(
cloudDirs.size()
);
PtrList<PtrList<symmTensorIOField>>
lagrangianSymmTensorFields
(
cloudDirs.size()
);
PtrList<PtrList<symmTensorFieldCompactIOField>>
lagrangianSymmTensorFieldFields
(
cloudDirs.size()
);
PtrList<PtrList<tensorIOField>> lagrangianTensorFields
(
cloudDirs.size()
);
PtrList<PtrList<tensorFieldCompactIOField>>
lagrangianTensorFieldFields
(
cloudDirs.size()
);
label cloudI = 0;
@ -1095,88 +980,10 @@ int main(int argc, char *argv[])
false
);
lagrangianFieldDecomposer::readFields
lagrangianFieldCache.readAllFields
(
cloudI,
lagrangianObjects,
lagrangianLabelFields
);
lagrangianFieldDecomposer::readFieldFields
(
cloudI,
lagrangianObjects,
lagrangianLabelFieldFields
);
lagrangianFieldDecomposer::readFields
(
cloudI,
lagrangianObjects,
lagrangianScalarFields
);
lagrangianFieldDecomposer::readFieldFields
(
cloudI,
lagrangianObjects,
lagrangianScalarFieldFields
);
lagrangianFieldDecomposer::readFields
(
cloudI,
lagrangianObjects,
lagrangianVectorFields
);
lagrangianFieldDecomposer::readFieldFields
(
cloudI,
lagrangianObjects,
lagrangianVectorFieldFields
);
lagrangianFieldDecomposer::readFields
(
cloudI,
lagrangianObjects,
lagrangianSphTensorFields
);
lagrangianFieldDecomposer::readFieldFields
(
cloudI,
lagrangianObjects,
lagrangianSphTensorFieldFields
);
lagrangianFieldDecomposer::readFields
(
cloudI,
lagrangianObjects,
lagrangianSymmTensorFields
);
lagrangianFieldDecomposer::readFieldFields
(
cloudI,
lagrangianObjects,
lagrangianSymmTensorFieldFields
);
lagrangianFieldDecomposer::readFields
(
cloudI,
lagrangianObjects,
lagrangianTensorFields
);
lagrangianFieldDecomposer::readFieldFields
(
cloudI,
lagrangianObjects,
lagrangianTensorFieldFields
lagrangianObjects
);
++cloudI;
@ -1185,18 +992,7 @@ int main(int argc, char *argv[])
lagrangianPositions.resize(cloudI);
cellParticles.resize(cloudI);
lagrangianLabelFields.resize(cloudI);
lagrangianLabelFieldFields.resize(cloudI);
lagrangianScalarFields.resize(cloudI);
lagrangianScalarFieldFields.resize(cloudI);
lagrangianVectorFields.resize(cloudI);
lagrangianVectorFieldFields.resize(cloudI);
lagrangianSphTensorFields.resize(cloudI);
lagrangianSphTensorFieldFields.resize(cloudI);
lagrangianSymmTensorFields.resize(cloudI);
lagrangianSymmTensorFieldFields.resize(cloudI);
lagrangianTensorFields.resize(cloudI);
lagrangianTensorFieldFields.resize(cloudI);
lagrangianFieldCache.resize(cloudI);
Info<< endl;
@ -1291,35 +1087,11 @@ int main(int argc, char *argv[])
)
);
}
const fvFieldDecomposer& fieldDecomposer =
fieldDecomposerList[proci];
// Vol fields
fieldDecomposer.decomposeFields(volScalarFields);
fieldDecomposer.decomposeFields(volVectorFields);
fieldDecomposer.decomposeFields(volSphTensorFields);
fieldDecomposer.decomposeFields(volSymmTensorFields);
fieldDecomposer.decomposeFields(volTensorFields);
// Surface fields
fieldDecomposer.decomposeFields(surfaceScalarFields);
fieldDecomposer.decomposeFields(surfaceVectorFields);
fieldDecomposer.decomposeFields
volumeFieldCache.decomposeAllFields
(
surfaceSphTensorFields
fieldDecomposerList[proci]
);
fieldDecomposer.decomposeFields
(
surfaceSymmTensorFields
);
fieldDecomposer.decomposeFields(surfaceTensorFields);
// internal fields
fieldDecomposer.decomposeFields(dimScalarFields);
fieldDecomposer.decomposeFields(dimVectorFields);
fieldDecomposer.decomposeFields(dimSphTensorFields);
fieldDecomposer.decomposeFields(dimSymmTensorFields);
fieldDecomposer.decomposeFields(dimTensorFields);
if (times.size() == 1)
{
@ -1330,14 +1102,7 @@ int main(int argc, char *argv[])
// Point fields
if
(
pointScalarFields.size()
|| pointVectorFields.size()
|| pointSphTensorFields.size()
|| pointSymmTensorFields.size()
|| pointTensorFields.size()
)
if (!pointFieldCache.empty())
{
const labelIOList& pointProcAddressing = procAddressing
(
@ -1363,15 +1128,11 @@ int main(int argc, char *argv[])
)
);
}
const pointFieldDecomposer& pointDecomposer =
pointFieldDecomposerList[proci];
pointDecomposer.decomposeFields(pointScalarFields);
pointDecomposer.decomposeFields(pointVectorFields);
pointDecomposer.decomposeFields(pointSphTensorFields);
pointDecomposer.decomposeFields(pointSymmTensorFields);
pointDecomposer.decomposeFields(pointTensorFields);
pointFieldCache.decomposeAllFields
(
pointFieldDecomposerList[proci]
);
if (times.size() == 1)
{
@ -1382,9 +1143,9 @@ int main(int argc, char *argv[])
// If there is lagrangian data write it out
forAll(lagrangianPositions, cloudI)
forAll(lagrangianPositions, cloudi)
{
if (lagrangianPositions[cloudI].size())
if (lagrangianPositions[cloudi].size())
{
lagrangianFieldDecomposer fieldDecomposer
(
@ -1392,74 +1153,18 @@ int main(int argc, char *argv[])
procMesh,
faceProcAddressing,
cellProcAddressing,
cloudDirs[cloudI],
lagrangianPositions[cloudI],
cellParticles[cloudI]
cloudDirs[cloudi],
lagrangianPositions[cloudi],
cellParticles[cloudi]
);
// Lagrangian fields
{
fieldDecomposer.decomposeFields
(
cloudDirs[cloudI],
lagrangianLabelFields[cloudI]
);
fieldDecomposer.decomposeFieldFields
(
cloudDirs[cloudI],
lagrangianLabelFieldFields[cloudI]
);
fieldDecomposer.decomposeFields
(
cloudDirs[cloudI],
lagrangianScalarFields[cloudI]
);
fieldDecomposer.decomposeFieldFields
(
cloudDirs[cloudI],
lagrangianScalarFieldFields[cloudI]
);
fieldDecomposer.decomposeFields
(
cloudDirs[cloudI],
lagrangianVectorFields[cloudI]
);
fieldDecomposer.decomposeFieldFields
(
cloudDirs[cloudI],
lagrangianVectorFieldFields[cloudI]
);
fieldDecomposer.decomposeFields
(
cloudDirs[cloudI],
lagrangianSphTensorFields[cloudI]
);
fieldDecomposer.decomposeFieldFields
(
cloudDirs[cloudI],
lagrangianSphTensorFieldFields[cloudI]
);
fieldDecomposer.decomposeFields
(
cloudDirs[cloudI],
lagrangianSymmTensorFields[cloudI]
);
fieldDecomposer.decomposeFieldFields
(
cloudDirs[cloudI],
lagrangianSymmTensorFieldFields[cloudI]
);
fieldDecomposer.decomposeFields
(
cloudDirs[cloudI],
lagrangianTensorFields[cloudI]
);
fieldDecomposer.decomposeFieldFields
(
cloudDirs[cloudI],
lagrangianTensorFieldFields[cloudI]
);
}
lagrangianFieldCache.decomposeAllFields
(
cloudi,
cloudDirs[cloudi],
fieldDecomposer
);
}
}
@ -1506,38 +1211,17 @@ int main(int argc, char *argv[])
aMesh.writeDecomposition();
// Area fields
// ~~~~~~~~~~~
PtrList<areaScalarField> areaScalarFields;
PtrList<areaVectorField> areaVectorFields;
PtrList<areaSphericalTensorField> areaSphTensorFields;
PtrList<areaSymmTensorField> areaSymmTensorFields;
PtrList<areaTensorField> areaTensorFields;
// Area/edge fields
// ~~~~~~~~~~~~~~~~
// Edge fields (limited number of types)
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PtrList<edgeScalarField> edgeScalarFields;
faFieldDecomposer::fieldsCache areaFieldCache;
if (doDecompFields)
{
readFields(aMesh, objects, areaScalarFields);
readFields(aMesh, objects, areaVectorFields);
readFields(aMesh, objects, areaSphTensorFields);
readFields(aMesh, objects, areaSymmTensorFields);
readFields(aMesh, objects, areaTensorFields);
readFields(aMesh, objects, edgeScalarFields);
areaFieldCache.readAllFields(aMesh, objects);
}
const label nAreaFields =
(
areaScalarFields.size()
+ areaVectorFields.size()
+ areaSphTensorFields.size()
+ areaSymmTensorFields.size()
+ areaTensorFields.size()
+ edgeScalarFields.size()
);
const label nAreaFields = areaFieldCache.size();
Info<< endl;
Info<< "Finite area field transfer: "
@ -1634,13 +1318,7 @@ int main(int argc, char *argv[])
boundaryProcAddressing
);
fieldDecomposer.decomposeFields(areaScalarFields);
fieldDecomposer.decomposeFields(areaVectorFields);
fieldDecomposer.decomposeFields(areaSphTensorFields);
fieldDecomposer.decomposeFields(areaSymmTensorFields);
fieldDecomposer.decomposeFields(areaTensorFields);
fieldDecomposer.decomposeFields(edgeScalarFields);
areaFieldCache.decomposeAllFields(fieldDecomposer);
}
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2021 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -37,6 +37,7 @@ License
#include "DynamicList.H"
#include "fvFieldDecomposer.H"
#include "IOobjectList.H"
#include "PtrDynList.H"
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
@ -178,32 +179,32 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
}
PtrList<const cellSet> cellSets;
PtrList<const faceSet> faceSets;
PtrList<const pointSet> pointSets;
PtrDynList<const cellSet> cellSets;
PtrDynList<const faceSet> faceSets;
PtrDynList<const pointSet> pointSets;
if (decomposeSets)
{
// Read sets
IOobjectList objects(*this, facesInstance(), "polyMesh/sets");
{
IOobjectList cSets(objects.lookupClass(cellSet::typeName));
forAllConstIters(cSets, iter)
IOobjectList sets(objects.lookupClass<cellSet>());
forAllConstIters(sets, iter)
{
cellSets.append(new cellSet(*iter()));
cellSets.append(new cellSet(*(iter.val())));
}
}
{
IOobjectList fSets(objects.lookupClass(faceSet::typeName));
forAllConstIters(fSets, iter)
IOobjectList sets(objects.lookupClass<faceSet>());
forAllConstIters(sets, iter)
{
faceSets.append(new faceSet(*iter()));
faceSets.append(new faceSet(*(iter.val())));
}
}
{
IOobjectList pSets(objects.lookupClass(pointSet::typeName));
forAllConstIters(pSets, iter)
IOobjectList sets(objects.lookupClass<pointSet>());
forAllConstIters(sets, iter)
{
pointSets.append(new pointSet(*iter()));
pointSets.append(new pointSet(*(iter.val())));
}
}
}
@ -225,13 +226,11 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
);
label maxProcCells = 0;
label maxProcFaces = 0;
label totProcFaces = 0;
label maxProcPatches = 0;
label totProcPatches = 0;
label maxProcFaces = 0;
// Write out the meshes
for (label proci = 0; proci < nProcs_; proci++)
@ -265,7 +264,6 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
{
// Mark the original face as used
// Remember to decrement the index by one (turning index)
//
label curF = mag(curFaceLabels[facei]) - 1;
faceLookup[curF] = facei;
@ -855,31 +853,35 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
Info<< "Number of cells = " << procMesh.nCells() << nl;
if (procMesh.nCells())
{
Info<< " Number of points = " << procMesh.nPoints() << nl;
}
maxProcCells = max(maxProcCells, procMesh.nCells());
label nBoundaryFaces = 0;
label nProcPatches = 0;
label nProcFaces = 0;
forAll(procMesh.boundaryMesh(), patchi)
for (const polyPatch& pp : procMesh.boundaryMesh())
{
if (isA<processorPolyPatch>(procMesh.boundaryMesh()[patchi]))
const auto* cpp = isA<processorPolyPatch>(pp);
if (cpp)
{
const processorPolyPatch& ppp =
refCast<const processorPolyPatch>
(
procMesh.boundaryMesh()[patchi]
);
const auto& procPatch = *cpp;
Info<< " Number of faces shared with processor "
<< ppp.neighbProcNo() << " = " << ppp.size() << endl;
<< procPatch.neighbProcNo() << " = "
<< procPatch.size() << nl;
nProcPatches++;
nProcFaces += ppp.size();
nProcFaces += procPatch.size();
++nProcPatches;
}
else
{
nBoundaryFaces += procMesh.boundaryMesh()[patchi].size();
nBoundaryFaces += pp.size();
}
}
@ -892,103 +894,79 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
totProcFaces += nProcFaces;
totProcPatches += nProcPatches;
maxProcPatches = max(maxProcPatches, nProcPatches);
maxProcFaces = max(maxProcFaces, nProcFaces);
maxProcPatches = max(maxProcPatches, nProcPatches);
// create and write the addressing information
labelIOList pointProcAddressing
(
IOobject
(
"pointProcAddressing",
procMesh.facesInstance(),
procMesh.meshSubDir,
procMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procPointAddressing_[proci]
);
pointProcAddressing.write();
// Write the addressing information
labelIOList faceProcAddressing
IOobject ioAddr
(
IOobject
(
"faceProcAddressing",
procMesh.facesInstance(),
procMesh.meshSubDir,
procMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFaceAddressing_[proci]
"procAddressing",
procMesh.facesInstance(),
polyMesh::meshSubDir,
procMesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false // not registered
);
faceProcAddressing.write();
labelIOList cellProcAddressing
(
IOobject
(
"cellProcAddressing",
procMesh.facesInstance(),
procMesh.meshSubDir,
procMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procCellAddressing_[proci]
);
cellProcAddressing.write();
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
IOListRef<label>(ioAddr, procPointAddressing_[proci]).write();
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
IOListRef<label>(ioAddr, procFaceAddressing_[proci]).write();
// cellProcAddressing
ioAddr.rename("cellProcAddressing");
IOListRef<label>(ioAddr, procCellAddressing_[proci]).write();
// Write patch map for backwards compatibility.
// (= identity map for original patches, -1 for processor patches)
label nMeshPatches = curPatchSizes.size();
labelList procBoundaryAddressing(identity(nMeshPatches));
procBoundaryAddressing.setSize(nMeshPatches+nProcPatches, -1);
labelList procBoundaryAddr(identity(nMeshPatches));
procBoundaryAddr.resize(nMeshPatches+nProcPatches, -1);
labelIOList boundaryProcAddressing
(
IOobject
(
"boundaryProcAddressing",
procMesh.facesInstance(),
procMesh.meshSubDir,
procMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procBoundaryAddressing
);
boundaryProcAddressing.write();
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
IOListRef<label>(ioAddr, procBoundaryAddr).write();
}
scalar avgProcCells = scalar(nCells())/nProcs_;
scalar avgProcPatches = scalar(totProcPatches)/nProcs_;
scalar avgProcFaces = scalar(totProcFaces)/nProcs_;
// In case of all faces on one processor. Just to avoid division by 0.
if (totProcPatches == 0)
{
avgProcPatches = 1;
}
if (totProcFaces == 0)
{
avgProcFaces = 1;
}
// Summary stats
Info<< nl
<< "Number of processor faces = " << totProcFaces/2 << nl
<< "Max number of cells = " << maxProcCells
<< " (" << 100.0*(maxProcCells-avgProcCells)/avgProcCells
<< "% above average " << avgProcCells << ")" << nl
<< "Max number of processor patches = " << maxProcPatches
<< " (" << 100.0*(maxProcPatches-avgProcPatches)/avgProcPatches
<< "% above average " << avgProcPatches << ")" << nl
<< "Max number of faces between processors = " << maxProcFaces
<< " (" << 100.0*(maxProcFaces-avgProcFaces)/avgProcFaces
<< "% above average " << avgProcFaces << ")" << nl
<< endl;
<< "Number of processor faces = " << (totProcFaces/2) << nl
<< "Max number of cells = " << maxProcCells;
if (maxProcCells != nCells())
{
scalar avgValue = scalar(nCells())/nProcs_;
Info<< " (" << 100.0*(maxProcCells-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl;
Info<< "Max number of processor patches = " << maxProcPatches;
if (totProcPatches)
{
scalar avgValue = scalar(totProcPatches)/nProcs_;
Info<< " (" << 100.0*(maxProcPatches-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl;
Info<< "Max number of faces between processors = " << maxProcFaces;
if (totProcFaces)
{
scalar avgValue = scalar(totProcFaces)/nProcs_;
Info<< " (" << 100.0*(maxProcFaces-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl << endl;
return true;
}

View File

@ -1,90 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
-------------------------------------------------------------------------------
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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "GeometricField.H"
#include "readFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::readFields
(
const typename GeoMesh::Mesh& mesh,
const IOobjectList& objects,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields,
const bool readOldTime
)
{
typedef GeometricField<Type, PatchField, GeoMesh> GeoField;
// Search list of objects for fields of type GeoField
IOobjectList fieldObjects(objects.lookupClass<GeoField>());
// Use sorted set of names
// (different processors might read objects in different order)
const wordList masterNames(fieldObjects.sortedNames());
// Construct the fields
fields.resize(masterNames.size());
forAll(masterNames, i)
{
const IOobject& io = *fieldObjects[masterNames[i]];
fields.set(i, new GeoField(io, mesh, readOldTime));
}
}
template<class Mesh, class GeoField>
void Foam::readFields
(
const Mesh& mesh,
const IOobjectList& objects,
PtrList<GeoField>& fields
)
{
// Search list of objects for fields of type GeomField
IOobjectList fieldObjects(objects.lookupClass<GeoField>());
// Use sorted set of names
// (different processors might read objects in different order)
const wordList masterNames(fieldObjects.sortedNames());
// Construct the fields
fields.resize(masterNames.size());
forAll(masterNames, i)
{
const IOobject& io = *fieldObjects[masterNames[i]];
fields.set(i, new GeoField(io, mesh));
}
}
// ************************************************************************* //

View File

@ -1,48 +0,0 @@
{
// Foam version 2.1 changes the addressing of faces in faceProcAddressing
// The following code checks and modifies the addressing for cases where
// the decomposition has been done with the foam2.0 and earlier tools, but
// the reconstruction is attempted with version 2.1 or later
label minFaceIndex = labelMax;
PtrList<labelIOList>& faceProcAddressing = procMeshes.faceProcAddressing();
forAll(faceProcAddressing, proci)
{
const labelList& curFaceAddr = faceProcAddressing[proci];
forAll(curFaceAddr, facei)
{
if (mag(curFaceAddr[facei]) < minFaceIndex)
{
minFaceIndex = mag(curFaceAddr[facei]);
}
}
}
if (minFaceIndex < 1)
{
WarningInFunction
<< "parallel decomposition addressing." << endl
<< "It looks like you are trying to reconstruct the case "
<< "decomposed with an earlier version of FOAM, which could\n"
<< "potentially cause compatibility problems. The code will "
<< "attempt to update the addressing automatically; in case of\n"
<< "failure, please repeat the decomposition of the case using "
<< "the current version fo decomposePar"
<< endl;
forAll(faceProcAddressing, proci)
{
labelList& curFaceAddr = faceProcAddressing[proci];
forAll(curFaceAddr, facei)
{
curFaceAddr[facei] += sign(curFaceAddr[facei]);
}
faceProcAddressing[proci].write();
}
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -334,11 +334,6 @@ int main(int argc, char *argv[])
// Read all meshes and addressing to reconstructed mesh
processorMeshes procMeshes(databases, regionName);
// Check face addressing for meshes that have been decomposed
// with a very old foam version
#include "checkFaceAddressingComp.H"
// Loop over all times
forAll(timeDirs, timei)
{
@ -362,11 +357,11 @@ int main(int argc, char *argv[])
}
// Check if any new meshes need to be read.
fvMesh::readUpdateState meshStat = mesh.readUpdate();
polyMesh::readUpdateState meshStat = mesh.readUpdate();
fvMesh::readUpdateState procStat = procMeshes.readUpdate();
polyMesh::readUpdateState procStat = procMeshes.readUpdate();
if (procStat == fvMesh::POINTS_MOVED)
if (procStat == polyMesh::POINTS_MOVED)
{
// Reconstruct the points for moving mesh cases and write
// them out
@ -407,83 +402,7 @@ int main(int argc, char *argv[])
procMeshes.boundaryProcAddressing()
);
reconstructor.reconstructFvVolumeInternalFields<scalar>
(
objects,
selectedFields
);
reconstructor.reconstructFvVolumeInternalFields<vector>
(
objects,
selectedFields
);
reconstructor.reconstructFvVolumeInternalFields<sphericalTensor>
(
objects,
selectedFields
);
reconstructor.reconstructFvVolumeInternalFields<symmTensor>
(
objects,
selectedFields
);
reconstructor.reconstructFvVolumeInternalFields<tensor>
(
objects,
selectedFields
);
reconstructor.reconstructFvVolumeFields<scalar>
(
objects,
selectedFields
);
reconstructor.reconstructFvVolumeFields<vector>
(
objects,
selectedFields
);
reconstructor.reconstructFvVolumeFields<sphericalTensor>
(
objects,
selectedFields
);
reconstructor.reconstructFvVolumeFields<symmTensor>
(
objects,
selectedFields
);
reconstructor.reconstructFvVolumeFields<tensor>
(
objects,
selectedFields
);
reconstructor.reconstructFvSurfaceFields<scalar>
(
objects,
selectedFields
);
reconstructor.reconstructFvSurfaceFields<vector>
(
objects,
selectedFields
);
reconstructor.reconstructFvSurfaceFields<sphericalTensor>
(
objects,
selectedFields
);
reconstructor.reconstructFvSurfaceFields<symmTensor>
(
objects,
selectedFields
);
reconstructor.reconstructFvSurfaceFields<tensor>
(
objects,
selectedFields
);
reconstructor.reconstructAllFields(objects, selectedFields);
if (reconstructor.nReconstructed() == 0)
{
@ -515,31 +434,7 @@ int main(int argc, char *argv[])
procMeshes.boundaryProcAddressing()
);
reconstructor.reconstructFields<scalar>
(
objects,
selectedFields
);
reconstructor.reconstructFields<vector>
(
objects,
selectedFields
);
reconstructor.reconstructFields<sphericalTensor>
(
objects,
selectedFields
);
reconstructor.reconstructFields<symmTensor>
(
objects,
selectedFields
);
reconstructor.reconstructFields<tensor>
(
objects,
selectedFields
);
reconstructor.reconstructAllFields(objects, selectedFields);
if (reconstructor.nReconstructed() == 0)
{
@ -631,78 +526,7 @@ int main(int argc, char *argv[])
reconstructor.reconstructPositions(cloudName);
reconstructor.reconstructFields<label>
(
cloudName,
cloudObjs,
selectedLagrangianFields
);
reconstructor.reconstructFieldFields<label>
(
cloudName,
cloudObjs,
selectedLagrangianFields
);
reconstructor.reconstructFields<scalar>
(
cloudName,
cloudObjs,
selectedLagrangianFields
);
reconstructor.reconstructFieldFields<scalar>
(
cloudName,
cloudObjs,
selectedLagrangianFields
);
reconstructor.reconstructFields<vector>
(
cloudName,
cloudObjs,
selectedLagrangianFields
);
reconstructor.reconstructFieldFields<vector>
(
cloudName,
cloudObjs,
selectedLagrangianFields
);
reconstructor.reconstructFields<sphericalTensor>
(
cloudName,
cloudObjs,
selectedLagrangianFields
);
reconstructor.reconstructFieldFields<sphericalTensor>
(
cloudName,
cloudObjs,
selectedLagrangianFields
);
reconstructor.reconstructFields<symmTensor>
(
cloudName,
cloudObjs,
selectedLagrangianFields
);
reconstructor.reconstructFieldFields<symmTensor>
(
cloudName,
cloudObjs,
selectedLagrangianFields
);
reconstructor.reconstructFields<tensor>
(
cloudName,
cloudObjs,
selectedLagrangianFields
);
reconstructor.reconstructFieldFields<tensor>
reconstructor.reconstructAllFields
(
cloudName,
cloudObjs,
@ -724,12 +548,12 @@ int main(int argc, char *argv[])
}
else if
(
objects.lookupClass(areaScalarField::typeName).size()
|| objects.lookupClass(areaVectorField::typeName).size()
|| objects.lookupClass(areaSphericalTensorField::typeName).size()
|| objects.lookupClass(areaSymmTensorField::typeName).size()
|| objects.lookupClass(areaTensorField::typeName).size()
|| objects.lookupClass(edgeScalarField::typeName).size()
objects.count<areaScalarField>()
|| objects.count<areaVectorField>()
|| objects.count<areaSphericalTensorField>()
|| objects.count<areaSymmTensorField>()
|| objects.count<areaTensorField>()
|| objects.count<edgeScalarField>()
)
{
Info << "Reconstructing FA fields" << nl << endl;
@ -747,13 +571,7 @@ int main(int argc, char *argv[])
procFaMeshes.boundaryProcAddressing()
);
reconstructor.reconstructFaAreaFields<scalar>(objects);
reconstructor.reconstructFaAreaFields<vector>(objects);
reconstructor.reconstructFaAreaFields<sphericalTensor>(objects);
reconstructor.reconstructFaAreaFields<symmTensor>(objects);
reconstructor.reconstructFaAreaFields<tensor>(objects);
reconstructor.reconstructFaEdgeFields<scalar>(objects);
reconstructor.reconstructAllFields(objects);
}
else
{
@ -782,21 +600,19 @@ int main(int argc, char *argv[])
polyMesh::meshSubDir/"sets"
);
IOobjectList cSets(objects.lookupClass(cellSet::typeName));
forAllConstIters(cSets, iter)
for (const word& setName : objects.sortedNames<cellSet>())
{
cSetNames.insert(iter.key(), cSetNames.size());
cSetNames.insert(setName, cSetNames.size());
}
IOobjectList fSets(objects.lookupClass(faceSet::typeName));
forAllConstIters(fSets, iter)
for (const word& setName : objects.sortedNames<faceSet>())
{
fSetNames.insert(iter.key(), fSetNames.size());
fSetNames.insert(setName, fSetNames.size());
}
IOobjectList pSets(objects.lookupClass(pointSet::typeName));
forAllConstIters(pSets, iter)
for (const word& setName : objects.sortedNames<pointSet>())
{
pSetNames.insert(iter.key(), pSetNames.size());
pSetNames.insert(setName, pSetNames.size());
}
}
@ -840,30 +656,25 @@ int main(int argc, char *argv[])
const labelList& cellMap =
procMeshes.cellProcAddressing()[proci];
IOobjectList cSets
(
objects.lookupClass(cellSet::typeName)
);
forAllConstIters(cSets, iter)
for (const IOobject& io : objects.sorted<cellSet>())
{
// Load cellSet
const cellSet procSet(*iter());
label setI = cSetNames[iter.key()];
if (!cellSets.set(setI))
const cellSet procSet(io);
const label seti = cSetNames[io.name()];
if (!cellSets.set(seti))
{
cellSets.set
(
setI,
seti,
new cellSet
(
mesh,
iter.key(),
io.name(),
procSet.size()
)
);
}
cellSet& cSet = cellSets[setI];
cellSet& cSet = cellSets[seti];
cSet.instance() = runTime.timeName();
for (const label celli : procSet)
@ -876,30 +687,25 @@ int main(int argc, char *argv[])
const labelList& faceMap =
procMeshes.faceProcAddressing()[proci];
IOobjectList fSets
(
objects.lookupClass(faceSet::typeName)
);
forAllConstIters(fSets, iter)
for (const IOobject& io : objects.sorted<faceSet>())
{
// Load faceSet
const faceSet procSet(*iter());
label setI = fSetNames[iter.key()];
if (!faceSets.set(setI))
const faceSet procSet(io);
const label seti = fSetNames[io.name()];
if (!faceSets.set(seti))
{
faceSets.set
(
setI,
seti,
new faceSet
(
mesh,
iter.key(),
io.name(),
procSet.size()
)
);
}
faceSet& fSet = faceSets[setI];
faceSet& fSet = faceSets[seti];
fSet.instance() = runTime.timeName();
for (const label facei : procSet)
@ -911,32 +717,28 @@ int main(int argc, char *argv[])
const labelList& pointMap =
procMeshes.pointProcAddressing()[proci];
IOobjectList pSets
(
objects.lookupClass(pointSet::typeName)
);
forAllConstIters(pSets, iter)
for (const IOobject& io : objects.sorted<pointSet>())
{
// Load pointSet
const pointSet propSet(*iter());
label setI = pSetNames[iter.key()];
if (!pointSets.set(setI))
const pointSet procSet(io);
const label seti = pSetNames[io.name()];
if (!pointSets.set(seti))
{
pointSets.set
(
setI,
seti,
new pointSet
(
mesh,
iter.key(),
propSet.size()
io.name(),
procSet.size()
)
);
}
pointSet& pSet = pointSets[setI];
pointSet& pSet = pointSets[seti];
pSet.instance() = runTime.timeName();
for (const label pointi : propSet)
for (const label pointi : procSet)
{
pSet.insert(pointMap[pointi]);
}

View File

@ -522,14 +522,11 @@ void writeMaps
Info<< " pointProcAddressing" << endl;
ioAddr.rename("pointProcAddressing");
labelIOList(ioAddr, pointProcAddressing).write();
IOListRef<label>(ioAddr, pointProcAddressing).write();
// From processor face to reconstructed mesh face
Info<< " faceProcAddressing" << endl;
ioAddr.rename("faceProcAddressing");
labelIOList faceProcAddr(ioAddr, faceProcAddressing);
// Now add turning index to faceProcAddressing.
@ -572,17 +569,15 @@ void writeMaps
// From processor cell to reconstructed mesh cell
Info<< " cellProcAddressing" << endl;
ioAddr.rename("cellProcAddressing");
labelIOList(ioAddr, cellProcAddressing).write();
IOListRef<label>(ioAddr, cellProcAddressing).write();
// From processor patch to reconstructed mesh patch
Info<< " boundaryProcAddressing" << endl;
ioAddr.rename("boundaryProcAddressing");
labelIOList(ioAddr, boundProcAddressing).write();
IOListRef<label>(ioAddr, boundProcAddressing).write();
Info<< endl;
}

View File

@ -78,6 +78,7 @@ Usage
#include "fvMesh.H"
#include "fvMeshTools.H"
#include "fvMeshDistribute.H"
#include "fieldsDistributor.H"
#include "decompositionMethod.H"
#include "decompositionModel.H"
#include "timeSelector.H"
@ -260,7 +261,6 @@ void printMeshData(const polyMesh& mesh)
{
// Collect all data on master
globalIndex globalCells(mesh.nCells());
labelListList patchNeiProcNo(Pstream::nProcs());
labelListList patchSize(Pstream::nProcs());
const labelList& pPatches = mesh.globalData().processorPatches();
@ -281,74 +281,94 @@ void printMeshData(const polyMesh& mesh)
// Print stats
globalIndex globalBoundaryFaces(mesh.nBoundaryFaces());
const globalIndex globalCells(mesh.nCells());
const globalIndex globalBoundaryFaces(mesh.nBoundaryFaces());
label maxProcCells = 0;
label maxProcFaces = 0;
label totProcFaces = 0;
label maxProcPatches = 0;
label totProcPatches = 0;
label maxProcFaces = 0;
for (const int procI : Pstream::allProcs())
for (const int proci : Pstream::allProcs())
{
const label nLocalCells = globalCells.localSize(proci);
const label nBndFaces = globalBoundaryFaces.localSize(proci);
Info<< nl
<< "Processor " << procI << nl
<< " Number of cells = " << globalCells.localSize(procI)
<< endl;
<< "Processor " << proci;
label nProcFaces = 0;
const labelList& nei = patchNeiProcNo[procI];
forAll(patchNeiProcNo[procI], i)
if (!nLocalCells)
{
Info<< " Number of faces shared with processor "
<< patchNeiProcNo[procI][i] << " = " << patchSize[procI][i]
<< endl;
nProcFaces += patchSize[procI][i];
Info<< " (empty)" << endl;
continue;
}
else
{
Info<< nl
<< " Number of cells = " << nLocalCells << endl;
}
Info<< " Number of processor patches = " << nei.size() << nl
<< " Number of processor faces = " << nProcFaces << nl
<< " Number of boundary faces = "
<< globalBoundaryFaces.localSize(procI)-nProcFaces << endl;
label nProcFaces = 0;
const labelList& nei = patchNeiProcNo[proci];
maxProcCells = max(maxProcCells, globalCells.localSize(procI));
forAll(patchNeiProcNo[proci], i)
{
Info<< " Number of faces shared with processor "
<< patchNeiProcNo[proci][i] << " = "
<< patchSize[proci][i] << nl;
nProcFaces += patchSize[proci][i];
}
{
Info<< " Number of processor patches = " << nei.size() << nl
<< " Number of processor faces = " << nProcFaces << nl
<< " Number of boundary faces = "
<< nBndFaces-nProcFaces << endl;
}
maxProcCells = max(maxProcCells, nLocalCells);
totProcFaces += nProcFaces;
totProcPatches += nei.size();
maxProcPatches = max(maxProcPatches, nei.size());
maxProcFaces = max(maxProcFaces, nProcFaces);
maxProcPatches = max(maxProcPatches, nei.size());
}
// Stats
scalar avgProcCells = scalar(globalCells.size())/Pstream::nProcs();
scalar avgProcPatches = scalar(totProcPatches)/Pstream::nProcs();
scalar avgProcFaces = scalar(totProcFaces)/Pstream::nProcs();
// In case of all faces on one processor. Just to avoid division by 0.
if (totProcPatches == 0)
{
avgProcPatches = 1;
}
if (totProcFaces == 0)
{
avgProcFaces = 1;
}
// Summary stats
Info<< nl
<< "Number of processor faces = " << totProcFaces/2 << nl
<< "Max number of cells = " << maxProcCells
<< " (" << 100.0*(maxProcCells-avgProcCells)/avgProcCells
<< "% above average " << avgProcCells << ")" << nl
<< "Max number of processor patches = " << maxProcPatches
<< " (" << 100.0*(maxProcPatches-avgProcPatches)/avgProcPatches
<< "% above average " << avgProcPatches << ")" << nl
<< "Max number of faces between processors = " << maxProcFaces
<< " (" << 100.0*(maxProcFaces-avgProcFaces)/avgProcFaces
<< "% above average " << avgProcFaces << ")" << nl
<< endl;
<< "Number of processor faces = " << (totProcFaces/2) << nl
<< "Max number of cells = " << maxProcCells;
if (maxProcCells != globalCells.totalSize())
{
scalar avgValue = scalar(globalCells.totalSize())/Pstream::nProcs();
Info<< " (" << 100.0*(maxProcCells-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl;
Info<< "Max number of processor patches = " << maxProcPatches;
if (totProcPatches)
{
scalar avgValue = scalar(totProcPatches)/Pstream::nProcs();
Info<< " (" << 100.0*(maxProcPatches-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl;
Info<< "Max number of faces between processors = " << maxProcFaces;
if (totProcFaces)
{
scalar avgValue = scalar(totProcFaces)/Pstream::nProcs();
Info<< " (" << 100.0*(maxProcFaces-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl << endl;
}
@ -513,180 +533,6 @@ void determineDecomposition
}
// Generic mesh-based field reading
template<class GeoField>
void readField
(
const IOobject& io,
const fvMesh& mesh,
const label i,
PtrList<GeoField>& fields
)
{
fields.set(i, new GeoField(io, mesh));
}
// Definition of readField for GeometricFields only
template<class Type, template<class> class PatchField, class GeoMesh>
void readField
(
const IOobject& io,
const fvMesh& mesh,
const label i,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields
)
{
fields.set
(
i,
new GeometricField<Type, PatchField, GeoMesh>(io, mesh, false)
);
}
// Read vol or surface fields
template<class GeoField>
void readFields
(
const boolList& haveMesh,
const fvMesh& mesh,
const autoPtr<fvMeshSubset>& subsetterPtr,
IOobjectList& allObjects,
PtrList<GeoField>& fields
)
{
// Get my objects of type
IOobjectList objects(allObjects.lookupClass(GeoField::typeName));
// Check that we all have all objects
wordList objectNames = objects.sortedNames();
// Get master names
wordList masterNames(objectNames);
Pstream::scatter(masterNames);
if (haveMesh[Pstream::myProcNo()] && objectNames != masterNames)
{
FatalErrorInFunction
<< "Objects not synchronised across processors." << nl
<< "Master has " << flatOutput(masterNames) << nl
<< "Processor " << Pstream::myProcNo()
<< " has " << flatOutput(objectNames)
<< exit(FatalError);
}
fields.setSize(masterNames.size());
// Have master send all fields to processors that don't have a mesh. The
// issue is if a patchField does any parallel operations inside its
// construct-from-dictionary. This will not work when going to more
// processors (e.g. decompose = 1 -> many) ! We could make a special
// exception for decomposePar but nicer would be to have read-communicator
// ... For now detect if decomposing & disable parRun
if (Pstream::master())
{
// Work out if we're decomposing - none of the subprocs has a mesh
bool decompose = true;
for (const int procI : Pstream::subProcs())
{
if (haveMesh[procI])
{
decompose = false;
}
}
forAll(masterNames, i)
{
const word& name = masterNames[i];
IOobject& io = *objects[name];
io.writeOpt(IOobject::AUTO_WRITE);
// Load field (but not oldTime)
const bool oldParRun = Pstream::parRun();
if (decompose)
{
Pstream::parRun(false);
}
readField(io, mesh, i, fields);
if (decompose)
{
Pstream::parRun(oldParRun);
}
// Create zero sized field and send
if (subsetterPtr)
{
const bool oldParRun = Pstream::parRun(false);
tmp<GeoField> tsubfld = subsetterPtr().interpolate(fields[i]);
Pstream::parRun(oldParRun);
// Send to all processors that don't have a mesh
for (const int procI : Pstream::subProcs())
{
if (!haveMesh[procI])
{
OPstream toProc(Pstream::commsTypes::blocking, procI);
toProc<< tsubfld();
}
}
}
}
}
else if (!haveMesh[Pstream::myProcNo()])
{
// Don't have mesh (nor fields). Receive empty field from master.
forAll(masterNames, i)
{
const word& name = masterNames[i];
// Receive field
IPstream fromMaster
(
Pstream::commsTypes::blocking,
Pstream::masterNo()
);
dictionary fieldDict(fromMaster);
fields.set
(
i,
new GeoField
(
IOobject
(
name,
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
fieldDict
)
);
//// Write it for next time round (since mesh gets written as well)
//fields[i].write();
}
}
else
{
// Have mesh so just try to load
forAll(masterNames, i)
{
const word& name = masterNames[i];
IOobject& io = *objects[name];
io.writeOpt(IOobject::AUTO_WRITE);
// Load field (but not oldtime)
readField(io, mesh, i, fields);
}
}
}
// Variant of GeometricField::correctBoundaryConditions that only
// evaluates selected patch fields
template<class GeoField, class CoupledPatchType>
@ -817,7 +663,8 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
runTime.caseName() = baseRunTime.caseName();
runTime.processorCase(false);
}
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -826,7 +673,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
volScalarFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -835,7 +682,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
volVectorFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -844,7 +691,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
volSphereTensorFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -853,7 +700,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
volSymmTensorFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -865,7 +712,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
// surfaceFields
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -874,7 +721,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
surfScalarFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -883,7 +730,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
surfVectorFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -892,7 +739,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
surfSphereTensorFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -901,7 +748,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
surfSymmTensorFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -912,7 +759,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
// Dimensioned internal fields
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -921,7 +768,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
dimScalarFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -930,7 +777,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
dimVectorFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -939,7 +786,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
dimSphereTensorFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,
@ -948,7 +795,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
dimSymmTensorFields
);
readFields
fieldsDistributor::readFields
(
haveMesh,
mesh,

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -23,29 +23,69 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Global
readFields
Class
fieldsDistributor
Description
Common methods/utilities for field decomposers/distributors etc.
SourceFiles
readFields.C
fieldsDistributorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef readFields_H
#define readFields_H
#ifndef Foam_fieldsDistributor_H
#define Foam_fieldsDistributor_H
#include "IOobjectList.H"
#include "boolList.H"
#include "PtrList.H"
#include "GeometricField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Read the fields and hold on the pointer list
/*---------------------------------------------------------------------------*\
Class fieldsDistributor Declaration
\*---------------------------------------------------------------------------*/
class fieldsDistributor
{
public:
// Reading helpers
//- Generic mesh-based field reading
template<class GeoField>
static void readField
(
const IOobject& io,
const typename GeoField::Mesh& mesh,
const label i,
PtrList<GeoField>& fields
);
//- Definition of readField for GeometricFields only
template<class Type, template<class> class PatchField, class GeoMesh>
void readFields
static void readField
(
const IOobject& io,
const typename GeoMesh::Mesh& mesh,
const label i,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields
);
//- Read fields and store on the pointer list
template
<
class Type,
template<class> class PatchField,
class GeoMesh
>
static void readFields
(
const typename GeoMesh::Mesh& mesh,
const IOobjectList& objects,
@ -53,21 +93,39 @@ namespace Foam
const bool readOldTime
);
// Read the fields and hold on the pointer list
//- Read fields and hold on the pointer list
template<class Mesh, class GeoField>
void readFields
static void readFields
(
const Mesh& mesh,
const IOobjectList& objects,
PtrList<GeoField>& fields
);
}
//- Read volume/surface/point/area fields that may or may not exist
//- on all processors
template<class GeoField, class MeshSubsetter>
static void readFields
(
const boolList& haveMeshOnProc,
const typename GeoField::Mesh& mesh,
const autoPtr<MeshSubsetter>& subsetterPtr,
IOobjectList& allObjects,
PtrList<GeoField>& fields,
const bool deregister = false
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "readFields.C"
#include "fieldsDistributorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,330 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class GeoField>
void Foam::fieldsDistributor::readField
(
const IOobject& io,
const typename GeoField::Mesh& mesh,
const label i,
PtrList<GeoField>& fields
)
{
fields.set(i, new GeoField(io, mesh));
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::fieldsDistributor::readField
(
const IOobject& io,
const typename GeoMesh::Mesh& mesh,
const label i,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields
)
{
fields.set
(
i,
new GeometricField<Type, PatchField, GeoMesh>(io, mesh, false)
);
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::fieldsDistributor::readFields
(
const typename GeoMesh::Mesh& mesh,
const IOobjectList& objects,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields,
const bool readOldTime
)
{
typedef GeometricField<Type, PatchField, GeoMesh> GeoField;
// GeoField fields - sorted for consistent order on all processors
UPtrList<const IOobject> fieldObjects(objects.sorted<GeoField>());
// Construct the fields
fields.resize(fieldObjects.size());
forAll(fieldObjects, i)
{
fields.set(i, new GeoField(fieldObjects[i], mesh, readOldTime));
}
}
template<class Mesh, class GeoField>
void Foam::fieldsDistributor::readFields
(
const Mesh& mesh,
const IOobjectList& objects,
PtrList<GeoField>& fields
)
{
// GeoField fields - sorted for consistent order on all processors
UPtrList<const IOobject> fieldObjects(objects.sorted<GeoField>());
// Construct the fields
fields.resize(fieldObjects.size());
forAll(fieldObjects, i)
{
fields.set(i, new GeoField(fieldObjects[i], mesh));
}
}
template<class GeoField, class MeshSubsetter>
void Foam::fieldsDistributor::readFields
(
const boolList& haveMeshOnProc,
const typename GeoField::Mesh& mesh,
const autoPtr<MeshSubsetter>& subsetterPtr,
IOobjectList& allObjects,
PtrList<GeoField>& fields,
const bool deregister
)
{
// Get my objects of type
IOobjectList objects(allObjects.lookupClass<GeoField>());
// Check that we all have all objects
wordList objectNames = objects.sortedNames();
// Get master names
wordList masterNames(objectNames);
Pstream::broadcast(masterNames);
if (haveMeshOnProc[Pstream::myProcNo()] && objectNames != masterNames)
{
FatalErrorInFunction
<< "Objects not synchronised across processors." << nl
<< "Master has " << flatOutput(masterNames) << nl
<< "Processor " << Pstream::myProcNo()
<< " has " << flatOutput(objectNames)
<< exit(FatalError);
}
fields.clear();
fields.resize(masterNames.size());
if (fields.empty())
{
if (deregister)
{
// Extra safety - remove all such types
HashTable<const GeoField*> other
(
mesh.thisDb().objectRegistry::template lookupClass<GeoField>()
);
forAllConstIters(other, iter)
{
GeoField& fld = const_cast<GeoField&>(*iter.val());
if (!fld.ownedByRegistry())
{
fld.checkOut();
}
}
}
// Early exit
return;
}
// Have master send all fields to processors that don't have a mesh. The
// issue is if a patchField does any parallel operations inside its
// construct-from-dictionary. This will not work when going to more
// processors (e.g. decompose = 1 -> many) ! We could make a special
// exception for decomposePar but nicer would be to have read-communicator
// ... For now detect if decomposing & disable parRun
if (Pstream::master())
{
// Work out if we're decomposing - none of the subprocs has a mesh
bool decompose = true;
for (const int proci : Pstream::subProcs())
{
if (haveMeshOnProc[proci])
{
decompose = false;
}
}
const bool oldParRun = Pstream::parRun();
if (decompose)
{
Pstream::parRun(false);
}
forAll(masterNames, i)
{
const word& name = masterNames[i];
IOobject& io = *objects[name];
io.writeOpt(IOobject::AUTO_WRITE);
// Load field (but not oldTime)
readField(io, mesh, i, fields);
}
Pstream::parRun(oldParRun); // Restore any changes
}
else if (haveMeshOnProc[Pstream::myProcNo()])
{
// Have mesh so just try to load
forAll(masterNames, i)
{
const word& name = masterNames[i];
IOobject& io = *objects[name];
io.writeOpt(IOobject::AUTO_WRITE);
/// Pout<< "Attempt read: " << name << endl;
// Load field (but not oldTime)
readField(io, mesh, i, fields);
}
}
// Missing fields on any processors?
// - construct from dictionary
PtrList<dictionary> fieldDicts;
if (Pstream::master())
{
// Broadcast zero sized fields everywhere (if needed)
// Send like a list of dictionaries
OPBstream toProcs(UPstream::masterNo()); // worldComm
const label nDicts = (subsetterPtr ? fields.size() : label(0));
toProcs << nDicts << token::BEGIN_LIST; // Begin list
if (nDicts)
{
// Disable communication for interpolate() method
const bool oldParRun = Pstream::parRun(false);
const auto& subsetter = subsetterPtr();
forAll(fields, i)
{
tmp<GeoField> tsubfld = subsetter.interpolate(fields[i]);
// Surround each with {} as dictionary entry
toProcs.beginBlock();
toProcs << tsubfld();
toProcs.endBlock();
}
Pstream::parRun(oldParRun); // Restore state
}
toProcs << token::END_LIST << token::NL; // End list
}
else
{
// Receive the broadcast...
IPBstream fromMaster(UPstream::masterNo()); // worldComm
// But only consume where needed...
if (!haveMeshOnProc[Pstream::myProcNo()])
{
fromMaster >> fieldDicts;
}
}
// Use the received dictionaries to create fields
// (will be empty if we didn't require them)
// Disable communication when constructing from dictionary
const bool oldParRun = Pstream::parRun(false);
forAll(fieldDicts, i)
{
fields.set
(
i,
new GeoField
(
IOobject
(
masterNames[i],
mesh.time().timeName(),
mesh.thisDb(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
fieldDicts[i]
)
);
}
Pstream::parRun(oldParRun); // Restore any changes
// Finally. Can checkOut of registry as required
if (deregister)
{
/// Info<< "De-registering fields:";
for (auto& fld : fields)
{
/// Info<< " " << fld.name();
// Ensure it is not destroyed by polyMesh deletion
fld.checkOut();
}
/// Info<< nl;
// Extra safety - remove all such types
HashTable<const GeoField*> other
(
mesh.thisDb().objectRegistry::template lookupClass<GeoField>()
);
forAllConstIters(other, iter)
{
GeoField& fld = const_cast<GeoField&>(*iter.val());
if (!fld.ownedByRegistry())
{
fld.checkOut();
}
}
}
}
// ************************************************************************* //

View File

@ -2,7 +2,14 @@ decompositionInformation.C
decompositionModel.C
dimFieldDecomposer.C
fvFieldDecomposer.C
fvFieldDecomposerCache.C
pointFieldDecomposer.C
pointFieldDecomposerCache.C
lagrangianFieldDecomposer.C
lagrangianFieldDecomposerCache.C
LIB = $(FOAM_LIBBIN)/libdecompose

View File

@ -32,12 +32,12 @@ Description
SourceFiles
dimFieldDecomposer.C
dimFieldDecomposerFields.C
dimFieldDecomposerTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef dimFieldDecomposer_H
#define dimFieldDecomposer_H
#ifndef Foam_dimFieldDecomposer_H
#define Foam_dimFieldDecomposer_H
#include "fvMesh.H"
#include "surfaceFields.H"
@ -121,7 +121,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "dimFieldDecomposerFields.C"
#include "dimFieldDecomposerTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -47,8 +47,8 @@ Foam::dimFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_,
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,6 +28,11 @@ License
#include "fvFieldDecomposer.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::fvFieldDecomposer::verbose_ = 1;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fvFieldDecomposer::patchFieldDecomposer::patchFieldDecomposer
@ -95,7 +100,7 @@ processorVolPatchFieldDecomposer
Foam::fvFieldDecomposer::processorVolPatchFieldDecomposer::
processorVolPatchFieldDecomposer
(
const fvMesh& mesh,
const polyMesh& mesh,
const labelUList& addressingSlice
)
:

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,12 +32,13 @@ Description
SourceFiles
fvFieldDecomposer.C
fvFieldDecomposerFields.C
fvFieldDecomposerCache.C
fvFieldDecomposerTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef fvFieldDecomposer_H
#define fvFieldDecomposer_H
#ifndef Foam_fvFieldDecomposer_H
#define Foam_fvFieldDecomposer_H
#include "fvMesh.H"
#include "fvPatchFieldMapper.H"
@ -48,6 +49,9 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class IOobjectList;
/*---------------------------------------------------------------------------*\
Class fvFieldDecomposer Declaration
\*---------------------------------------------------------------------------*/
@ -56,6 +60,8 @@ class fvFieldDecomposer
{
public:
// Public Classes
//- Patch field decomposer class
class patchFieldDecomposer
:
@ -126,7 +132,7 @@ public:
//- Construct given addressing from complete mesh
processorVolPatchFieldDecomposer
(
const fvMesh& mesh,
const polyMesh& mesh,
const labelUList& addressingSlice
);
@ -232,13 +238,24 @@ private:
PtrList<scalarField> faceSign_;
// Private Member Functions
//- No copy construct
fvFieldDecomposer(const fvFieldDecomposer&) = delete;
//- No copy assignment
void operator=(const fvFieldDecomposer&) = delete;
public:
//- No copy construct
fvFieldDecomposer(const fvFieldDecomposer&) = delete;
// Public Classes
class fieldsCache;
//- No copy assignment
void operator=(const fvFieldDecomposer&) = delete;
// Static Data
//- Output verbosity when writing
static int verbose_;
// Constructors
@ -336,6 +353,69 @@ public:
};
/*---------------------------------------------------------------------------*\
Class fvFieldDecomposer::fieldsCache Declaration
\*---------------------------------------------------------------------------*/
class fvFieldDecomposer::fieldsCache
{
// Private Data
class privateCache;
//- All field and field-field types for lagrangian
std::unique_ptr<privateCache> cache_;
// Private Member Functions
//- No copy construct
fieldsCache(const fieldsCache&) = delete;
//- No copy assignment
void operator=(const fieldsCache&) = delete;
public:
// Constructors
//- Default construct
fieldsCache();
//- Destructor
~fieldsCache();
// Member Functions
//- No fields
bool empty() const;
//- Total number of fields
label size() const;
//- Clear out
void clear();
//- Read all fields given mesh and objects
void readAllFields
(
const fvMesh& mesh,
const IOobjectList& objects
);
//- Decompose and write all fields
void decomposeAllFields
(
const fvFieldDecomposer& decomposer,
bool report = false
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
@ -343,7 +423,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fvFieldDecomposerFields.C"
#include "fvFieldDecomposerTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,228 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fvFieldDecomposer.H"
#include "fieldsDistributor.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "IOobjectList.H"
#include "PtrListOps.H"
// * * * * * * * * * * * * * * * * Declarations * * * * * * * * * * * * * * //
namespace Foam
{
// All volume internal types
class fvFieldDecomposer::fieldsCache::privateCache
{
public:
#undef declareField
#define declareField(Type) \
PtrList<DimensionedField<Type, volMesh>> Type##DimFields_; \
PtrList<GeometricField<Type, fvPatchField, volMesh>> Type##VolFields_; \
PtrList<GeometricField<Type, fvsPatchField, surfaceMesh>> Type##SurfFields_;
declareField(scalar);
declareField(vector);
declareField(sphericalTensor);
declareField(symmTensor);
declareField(tensor);
#undef declareField
label size() const noexcept
{
label count = 0;
#undef doLocalCode
#define doLocalCode(Type) \
{ \
count += Type##DimFields_.size(); \
count += Type##VolFields_.size(); \
count += Type##SurfFields_.size(); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
return count;
}
bool empty() const noexcept { return !size(); }
void readAll(const fvMesh& mesh, const IOobjectList& objects)
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##DimFields_ \
); \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##VolFields_, \
false /* readOldTime = false */ \
); \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##SurfFields_, \
false /* readOldTime = false */ \
); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
template<class GeoField>
static void decompose
(
const fvFieldDecomposer& decomposer,
const PtrList<GeoField>& fields,
bool report
)
{
if (!fields.empty())
{
if (report)
{
Info<< " "
<< pTraits<typename GeoField::value_type>::typeName
<< "s: "
<< flatOutput(PtrListOps::names(fields)) << nl;
}
decomposer.decomposeFields(fields);
}
}
void decomposeAll
(
const fvFieldDecomposer& decomposer,
bool report
) const
{
#undef doLocalCode
#define doLocalCode(Flavour) \
{ \
decompose(decomposer, scalar##Flavour##Fields_, report); \
decompose(decomposer, vector##Flavour##Fields_, report); \
decompose(decomposer, sphericalTensor##Flavour##Fields_, report); \
decompose(decomposer, symmTensor##Flavour##Fields_, report); \
decompose(decomposer, tensor##Flavour##Fields_, report); \
}
doLocalCode(Vol);
doLocalCode(Surf);
doLocalCode(Dim);
#undef doLocalCode
}
};
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fvFieldDecomposer::fieldsCache::fieldsCache()
:
cache_(new privateCache)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// Destructor not in header (used incomplete type)
Foam::fvFieldDecomposer::fieldsCache::~fieldsCache()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fvFieldDecomposer::fieldsCache::empty() const
{
return (!cache_ || cache_->empty());
}
Foam::label Foam::fvFieldDecomposer::fieldsCache::size() const
{
return (cache_ ? cache_->size() : label(0));
}
void Foam::fvFieldDecomposer::fieldsCache::clear()
{
cache_.reset(new privateCache);
}
void Foam::fvFieldDecomposer::fieldsCache::readAllFields
(
const fvMesh& mesh,
const IOobjectList& objects
)
{
if (cache_)
{
cache_->readAll(mesh, objects);
}
}
void Foam::fvFieldDecomposer::fieldsCache::decomposeAllFields
(
const fvFieldDecomposer& decomposer,
bool report
) const
{
if (cache_)
{
cache_->decomposeAll(decomposer, report);
}
}
// ************************************************************************* //

View File

@ -32,6 +32,8 @@ License
#include "processorCyclicFvPatchField.H"
#include "processorCyclicFvsPatchField.H"
#include "emptyFvPatchFields.H"
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -52,8 +54,8 @@ Foam::fvFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_,
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
@ -100,8 +102,8 @@ Foam::fvFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_,
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -118,7 +120,7 @@ Foam::fvFieldDecomposer::decomposeField
// 2. Change the fvPatchFields to the correct type using a mapper
// constructor (with reference to the now correct internal field)
typename VolFieldType::Boundary& bf = resF.boundaryFieldRef();
auto& bf = resF.boundaryFieldRef();
forAll(bf, patchi)
{
@ -272,8 +274,8 @@ Foam::fvFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_,
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -289,7 +291,7 @@ Foam::fvFieldDecomposer::decomposeField
// 2. Change the fvsPatchFields to the correct type using a mapper
// constructor (with reference to the now correct internal field)
typename SurfaceFieldType::Boundary& bf = resF.boundaryFieldRef();
auto& bf = resF.boundaryFieldRef();
forAll(boundaryAddressing_, patchi)
{

View File

@ -94,7 +94,7 @@ Foam::lagrangianFieldDecomposer::lagrangianFieldDecomposer
}
}
particleIndices_.setSize(pi);
particleIndices_.resize(pi);
IOPosition<Cloud<passiveParticle>>(positions_).write();
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -31,12 +32,14 @@ Description
SourceFiles
lagrangianFieldDecomposer.C
lagrangianFieldDecomposerFields.C
lagrangianFieldDecomposerCache.C
lagrangianFieldDecomposerReadFields.C
lagrangianFieldDecomposerTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef lagrangianFieldDecomposer_H
#define lagrangianFieldDecomposer_H
#ifndef Foam_lagrangianFieldDecomposer_H
#define Foam_lagrangianFieldDecomposer_H
#include "Cloud.H"
#include "CompactIOField.H"
@ -48,6 +51,7 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class IOobjectList;
/*---------------------------------------------------------------------------*\
@ -56,7 +60,7 @@ class IOobjectList;
class lagrangianFieldDecomposer
{
// Private data
// Private Data
//- Reference to processor mesh
const polyMesh& procMesh_;
@ -79,6 +83,10 @@ class lagrangianFieldDecomposer
public:
// Public Classes
class fieldsCache;
// Constructors
//- Construct from components
@ -94,29 +102,29 @@ public:
);
// Member Functions
// Field Reading
// Read the fields and hold on the pointer list
//- Read the fields and store on the pointer list
template<class Type>
static void readFields
(
const label cloudI,
const label cloudi,
const IOobjectList& lagrangianObjects,
PtrList<PtrList<IOField<Type>>>& lagrangianFields
PtrList<PtrList<IOField<Type>>>& cloudFields
);
//- Read the field-fields and store on the pointer list
template<class Type>
static void readFieldFields
(
const label cloudI,
const label cloudi,
const IOobjectList& lagrangianObjects,
PtrList
<
PtrList<CompactIOField<Field<Type>, Type>>
>& lagrangianFields
PtrList<PtrList<CompactIOField<Field<Type>, Type>>>& cloudFields
);
// Member Functions
//- Decompose volume field
template<class Type>
tmp<IOField<Type>> decomposeField
@ -149,6 +157,77 @@ public:
};
/*---------------------------------------------------------------------------*\
Class lagrangianFieldDecomposer::fieldsCache Declaration
\*---------------------------------------------------------------------------*/
class lagrangianFieldDecomposer::fieldsCache
{
// Private Data
class privateCache;
//- All field and field-field types for lagrangian
std::unique_ptr<privateCache> cache_;
// Private Member Functions
//- No copy construct
fieldsCache(const fieldsCache&) = delete;
//- No copy assignment
void operator=(const fieldsCache&) = delete;
public:
// Constructors
//- Default construct (no clouds)
fieldsCache();
//- Construct for given number of clouds
explicit fieldsCache(const label nClouds);
//- Destructor
~fieldsCache();
// Member Functions
//- No clouds
bool empty() const;
//- Number of clouds
label size() const;
//- Clear out
void clear();
//- Resize for the number of clouds
void resize(const label nClouds);
//- Read all fields and field-fields for given cloud and objects
void readAllFields
(
const label cloudi,
const IOobjectList& lagrangianObjects
);
//- Decompose and write all fields and field-fields for given cloud
void decomposeAllFields
(
const label cloudi,
const fileName& cloudDir,
const lagrangianFieldDecomposer& decomposer,
bool report = false
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
@ -156,7 +235,8 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "lagrangianFieldDecomposerFields.C"
#include "lagrangianFieldDecomposerReadFields.C"
#include "lagrangianFieldDecomposerTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,241 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "lagrangianFieldDecomposer.H"
#include "labelIOField.H"
#include "labelFieldIOField.H"
#include "scalarIOField.H"
#include "scalarFieldIOField.H"
#include "vectorIOField.H"
#include "vectorFieldIOField.H"
#include "sphericalTensorIOField.H"
#include "sphericalTensorFieldIOField.H"
#include "symmTensorIOField.H"
#include "symmTensorFieldIOField.H"
#include "tensorIOField.H"
#include "tensorFieldIOField.H"
// * * * * * * * * * * * * * * * * Declarations * * * * * * * * * * * * * * //
namespace Foam
{
// All lagrangian field/field-field types
class lagrangianFieldDecomposer::fieldsCache::privateCache
{
public:
#undef declareField
#define declareField(Type) \
PtrList<PtrList<IOField<Type>>> Type##Fields_; \
PtrList<PtrList<CompactIOField<Field<Type>, Type>>> Type##FieldFields_;
declareField(label);
declareField(scalar);
declareField(vector);
declareField(sphericalTensor);
declareField(symmTensor);
declareField(tensor);
#undef declareField
bool empty() const noexcept { return labelFields_.empty(); }
label size() const noexcept { return labelFields_.size(); }
void resize(const label len)
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
Type##Fields_.resize(len); \
Type##FieldFields_.resize(len); \
}
doLocalCode(label);
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
void readAll(const label cloudi, const IOobjectList& lagrangianObjects)
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
lagrangianFieldDecomposer::readFields \
( \
cloudi, \
lagrangianObjects, \
Type##Fields_ \
); \
lagrangianFieldDecomposer::readFieldFields \
( \
cloudi, \
lagrangianObjects, \
Type##FieldFields_ \
); \
}
doLocalCode(label);
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
void decomposeAll
(
const label cloudi,
const fileName& cloudDir,
const lagrangianFieldDecomposer& decomposer,
bool report /* unused */
) const
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
decomposer.decomposeFields \
( \
cloudDir, \
Type##Fields_[cloudi] \
); \
decomposer.decomposeFieldFields \
( \
cloudDir, \
Type##FieldFields_[cloudi] \
); \
}
doLocalCode(label);
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
};
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lagrangianFieldDecomposer::fieldsCache::fieldsCache()
:
cache_(new privateCache)
{}
Foam::lagrangianFieldDecomposer::fieldsCache::fieldsCache
(
const label nClouds
)
:
cache_(new privateCache)
{
cache_->resize(nClouds);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// Destructor not in header (used incomplete type)
Foam::lagrangianFieldDecomposer::fieldsCache::~fieldsCache()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::lagrangianFieldDecomposer::fieldsCache::empty() const
{
return (!cache_ || cache_->empty());
}
Foam::label Foam::lagrangianFieldDecomposer::fieldsCache::size() const
{
return (cache_ ? cache_->size() : label(0));
}
void Foam::lagrangianFieldDecomposer::fieldsCache::clear()
{
cache_.reset(new privateCache);
}
void Foam::lagrangianFieldDecomposer::fieldsCache::resize
(
const label nClouds
)
{
if (cache_)
{
cache_->resize(nClouds);
}
}
void Foam::lagrangianFieldDecomposer::fieldsCache::readAllFields
(
const label cloudi,
const IOobjectList& lagrangianObjects
)
{
if (cache_)
{
cache_->readAll(cloudi, lagrangianObjects);
}
}
void Foam::lagrangianFieldDecomposer::fieldsCache::decomposeAllFields
(
const label cloudi,
const fileName& cloudDir,
const lagrangianFieldDecomposer& decomposer,
bool report
) const
{
if (cache_)
{
cache_->decomposeAll(cloudi, cloudDir, decomposer, report);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,108 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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) 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "lagrangianFieldDecomposer.H"
#include "IOobjectList.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::lagrangianFieldDecomposer::readFields
(
const label cloudi,
const IOobjectList& lagrangianObjects,
PtrList<PtrList<IOField<Type>>>& lagrangianFields
)
{
// List of lagrangian field objects
UPtrList<const IOobject> fieldObjects
(
lagrangianObjects.sorted<IOField<Type>>()
);
lagrangianFields.set
(
cloudi,
new PtrList<IOField<Type>>(fieldObjects.size())
);
label fieldi = 0;
for (const IOobject& io : fieldObjects)
{
lagrangianFields[cloudi].set(fieldi++, new IOField<Type>(io));
}
}
template<class Type>
void Foam::lagrangianFieldDecomposer::readFieldFields
(
const label cloudi,
const IOobjectList& lagrangianObjects,
PtrList<PtrList<CompactIOField<Field<Type>, Type>>>& lagrangianFields
)
{
// List of lagrangian field objects
UPtrList<const IOobject> fieldObjects;
fieldObjects.append
(
lagrangianObjects.sorted<IOField<Field<Type>>>()
);
fieldObjects.append
(
lagrangianObjects.sorted<CompactIOField<Field<Type>, Type>>()
);
Foam::sort(fieldObjects, nameOp<IOobject>());
lagrangianFields.set
(
cloudi,
new PtrList<CompactIOField<Field<Type>, Type>>(fieldObjects.size())
);
label fieldi = 0;
for (const IOobject& io : fieldObjects)
{
lagrangianFields[cloudi].set
(
fieldi++,
new CompactIOField<Field<Type>, Type>(io)
);
}
}
// ************************************************************************* //

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -30,95 +31,6 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::lagrangianFieldDecomposer::readFields
(
const label cloudI,
const IOobjectList& lagrangianObjects,
PtrList<PtrList<IOField<Type>>>& lagrangianFields
)
{
// Search list of objects for lagrangian fields
IOobjectList lagrangianTypeObjects
(
lagrangianObjects.lookupClass(IOField<Type>::typeName)
);
lagrangianFields.set
(
cloudI,
new PtrList<IOField<Type>>
(
lagrangianTypeObjects.size()
)
);
label lagrangianFieldi = 0;
forAllConstIters(lagrangianTypeObjects, iter)
{
lagrangianFields[cloudI].set
(
lagrangianFieldi++,
new IOField<Type>(*iter())
);
}
}
template<class Type>
void Foam::lagrangianFieldDecomposer::readFieldFields
(
const label cloudI,
const IOobjectList& lagrangianObjects,
PtrList<PtrList<CompactIOField<Field<Type>, Type>>>& lagrangianFields
)
{
// Search list of objects for lagrangian fields
IOobjectList lagrangianTypeObjectsA
(
lagrangianObjects.lookupClass(IOField<Field<Type>>::typeName)
);
IOobjectList lagrangianTypeObjectsB
(
lagrangianObjects.lookupClass
(
CompactIOField<Field<Type>,
Type>::typeName
)
);
lagrangianFields.set
(
cloudI,
new PtrList<CompactIOField<Field<Type>, Type>>
(
lagrangianTypeObjectsA.size() + lagrangianTypeObjectsB.size()
)
);
label lagrangianFieldi = 0;
forAllConstIters(lagrangianTypeObjectsA, iter)
{
lagrangianFields[cloudI].set
(
lagrangianFieldi++,
new CompactIOField<Field<Type>, Type>(*iter())
);
}
forAllConstIters(lagrangianTypeObjectsB, iter)
{
lagrangianFields[cloudI].set
(
lagrangianFieldi++,
new CompactIOField<Field<Type>, Type>(*iter())
);
}
}
template<class Type>
Foam::tmp<Foam::IOField<Type>>
Foam::lagrangianFieldDecomposer::decomposeField
@ -127,9 +39,6 @@ Foam::lagrangianFieldDecomposer::decomposeField
const IOField<Type>& field
) const
{
// Create and map the internal field values
Field<Type> procField(field, particleIndices_);
// Create the field for the processor
return tmp<IOField<Type>>::New
(
@ -143,7 +52,8 @@ Foam::lagrangianFieldDecomposer::decomposeField
IOobject::NO_WRITE,
false
),
procField
// Mapping internal field values
Field<Type>(field, particleIndices_)
);
}
@ -156,9 +66,6 @@ Foam::lagrangianFieldDecomposer::decomposeFieldField
const CompactIOField<Field<Type>, Type>& field
) const
{
// Create and map the internal field values
Field<Field<Type>> procField(field, particleIndices_);
// Create the field for the processor
return tmp<CompactIOField<Field<Type>, Type>>::New
(
@ -172,7 +79,8 @@ Foam::lagrangianFieldDecomposer::decomposeFieldField
IOobject::NO_WRITE,
false
),
procField
// Mapping internal field values
Field<Field<Type>>(field, particleIndices_)
);
}
@ -184,13 +92,11 @@ void Foam::lagrangianFieldDecomposer::decomposeFields
const PtrList<GeoField>& fields
) const
{
//if (particleIndices_.size())
const bool existsOnProc = (particleIndices_.size() > 0);
for (const GeoField& fld : fields)
{
bool valid = particleIndices_.size() > 0;
forAll(fields, fieldi)
{
decomposeField(cloudName, fields[fieldi])().write(valid);
}
decomposeField(cloudName, fld)().write(existsOnProc);
}
}
@ -202,13 +108,11 @@ void Foam::lagrangianFieldDecomposer::decomposeFieldFields
const PtrList<GeoField>& fields
) const
{
//if (particleIndices_.size())
const bool existsOnProc = (particleIndices_.size() > 0);
for (const GeoField& fld : fields)
{
bool valid = particleIndices_.size() > 0;
forAll(fields, fieldi)
{
decomposeFieldField(cloudName, fields[fieldi])().write(valid);
}
decomposeFieldField(cloudName, fld)().write(existsOnProc);
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,12 +32,13 @@ Description
SourceFiles
pointFieldDecomposer.C
pointFieldDecomposerFields.C
pointFieldDecomposerCache.C
pointFieldDecomposerTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef pointFieldDecomposer_H
#define pointFieldDecomposer_H
#ifndef Foam_pointFieldDecomposer_H
#define Foam_pointFieldDecomposer_H
#include "pointMesh.H"
#include "pointPatchFieldMapperPatchRef.H"
@ -48,6 +49,9 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class IOobjectList;
/*---------------------------------------------------------------------------*\
Class pointFieldDecomposer Declaration
\*---------------------------------------------------------------------------*/
@ -56,6 +60,8 @@ class pointFieldDecomposer
{
public:
// Public Classes
//- Point patch field decomposer class
class patchFieldDecomposer
:
@ -122,13 +128,18 @@ private:
PtrList<patchFieldDecomposer> patchFieldDecomposerPtrs_;
// Private Member Functions
//- No copy construct
pointFieldDecomposer(const pointFieldDecomposer&) = delete;
//- No copy assignment
void operator=(const pointFieldDecomposer&) = delete;
public:
//- No copy construct
pointFieldDecomposer(const pointFieldDecomposer&) = delete;
//- No copy assignment
void operator=(const pointFieldDecomposer&) = delete;
// Public Classes
class fieldsCache;
// Constructors
@ -184,6 +195,69 @@ public:
};
/*---------------------------------------------------------------------------*\
Class pointFieldDecomposer::fieldsCache Declaration
\*---------------------------------------------------------------------------*/
class pointFieldDecomposer::fieldsCache
{
// Private Data
class privateCache;
//- All field and field-field types for lagrangian
std::unique_ptr<privateCache> cache_;
// Private Member Functions
//- No copy construct
fieldsCache(const fieldsCache&) = delete;
//- No copy assignment
void operator=(const fieldsCache&) = delete;
public:
// Constructors
//- Default construct
fieldsCache();
//- Destructor
~fieldsCache();
// Member Functions
//- No fields
bool empty() const;
//- Total number of fields
label size() const;
//- Clear out
void clear();
//- Read all fields given mesh and objects
void readAllFields
(
const pointMesh& mesh,
const IOobjectList& objects
);
//- Decompose and write all fields
void decomposeAllFields
(
const pointFieldDecomposer& decomposer,
bool report = false
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
@ -191,7 +265,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "pointFieldDecomposerFields.C"
#include "pointFieldDecomposerTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,208 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "pointFieldDecomposer.H"
#include "fieldsDistributor.H"
#include "pointFields.H"
#include "IOobjectList.H"
#include "PtrListOps.H"
// * * * * * * * * * * * * * * * * Declarations * * * * * * * * * * * * * * //
namespace Foam
{
// All point field types
class pointFieldDecomposer::fieldsCache::privateCache
{
public:
#undef declareField
#define declareField(Type) \
PtrList<GeometricField<Type, pointPatchField, pointMesh>> Type##Fields_;
declareField(scalar);
declareField(vector);
declareField(sphericalTensor);
declareField(symmTensor);
declareField(tensor);
#undef declareField
label size() const noexcept
{
label count = 0;
#undef doLocalCode
#define doLocalCode(Type) \
{ \
count += Type##Fields_.size(); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
return count;
}
bool empty() const noexcept { return !size(); }
void readAll(const pointMesh& mesh, const IOobjectList& objects)
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##Fields_, \
false /* readOldTime = false */ \
); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
template<class GeoField>
static void decompose
(
const pointFieldDecomposer& decomposer,
const PtrList<GeoField>& fields,
bool report
)
{
if (!fields.empty())
{
if (report)
{
Info<< " "
<< pTraits<typename GeoField::value_type>::typeName
<< "s: "
<< flatOutput(PtrListOps::names(fields)) << nl;
}
decomposer.decomposeFields(fields);
}
}
void decomposeAll
(
const pointFieldDecomposer& decomposer,
bool report
) const
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
decompose(decomposer, Type##Fields_, report); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
};
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pointFieldDecomposer::fieldsCache::fieldsCache()
:
cache_(new privateCache)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// Destructor not in header (used incomplete type)
Foam::pointFieldDecomposer::fieldsCache::~fieldsCache()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::pointFieldDecomposer::fieldsCache::empty() const
{
return (!cache_ || cache_->empty());
}
Foam::label Foam::pointFieldDecomposer::fieldsCache::size() const
{
return (cache_ ? cache_->size() : label(0));
}
void Foam::pointFieldDecomposer::fieldsCache::clear()
{
cache_.reset(new privateCache);
}
void Foam::pointFieldDecomposer::fieldsCache::readAllFields
(
const pointMesh& mesh,
const IOobjectList& objects
)
{
if (cache_)
{
cache_->readAll(mesh, objects);
}
}
void Foam::pointFieldDecomposer::fieldsCache::decomposeAllFields
(
const pointFieldDecomposer& decomposer,
bool report
) const
{
if (cache_)
{
cache_->decomposeAll(decomposer, report);
}
}
// ************************************************************************* //

View File

@ -82,8 +82,8 @@ Foam::pointFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_().time().timeName(),
procMesh_(),
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false

View File

@ -1,4 +1,6 @@
faFieldDecomposer.C
faFieldDecomposerCache.C
faMeshDecomposition.C
LIB = $(FOAM_LIBBIN)/libfaDecompose

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,12 +36,13 @@ Author
SourceFiles
faFieldDecomposer.C
faFieldDecomposerFields.C
fvFieldDecomposerCache.C
faFieldDecomposerTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef faFieldDecomposer_H
#define faFieldDecomposer_H
#ifndef Foam_faFieldDecomposer_H
#define Foam_faFieldDecomposer_H
#include "faMesh.H"
#include "faPatchFieldMapper.H"
@ -63,6 +64,8 @@ class faFieldDecomposer
{
public:
// Public Classes
//- Patch field decomposer class
class patchFieldDecomposer
:
@ -270,13 +273,17 @@ private:
public:
// Public Classes
class fieldsCache;
// Constructors
//- Construct without mappers, added later with reset()
faFieldDecomposer
(
const Foam::zero,
const faMesh& procMesh,
const faMesh& procMesh, // Target mesh
const labelList& edgeAddressing,
const labelList& faceAddressing,
const labelList& boundaryAddressing
@ -285,8 +292,8 @@ public:
//- Construct from components using information from the complete mesh
faFieldDecomposer
(
const faMesh& completeMesh,
const faMesh& procMesh,
const faMesh& completeMesh, // Source mesh
const faMesh& procMesh, // Target mesh
const labelList& edgeAddressing,
const labelList& faceAddressing,
const labelList& boundaryAddressing
@ -302,7 +309,7 @@ public:
const labelUList& edgeNeigbour,
// Addressing for processor mesh
const faMesh& procMesh,
const faMesh& procMesh, // Target mesh
const labelList& edgeAddressing,
const labelList& faceAddressing,
const labelList& boundaryAddressing
@ -358,7 +365,7 @@ public:
// Reading helpers
//- Read the fields and hold on the pointer list
//- Read the fields and store on the pointer list
template
<
class Type,
@ -373,7 +380,7 @@ public:
const bool readOldTime
);
//- Read fields and hold on the pointer list
//- Read fields and store on the pointer list
template<class Mesh, class GeoField>
static void readFields
(
@ -384,6 +391,70 @@ public:
};
/*---------------------------------------------------------------------------*\
Class faFieldDecomposer::fieldsCache Declaration
\*---------------------------------------------------------------------------*/
class faFieldDecomposer::fieldsCache
{
// Private Data
class privateCache;
//- All field and field-field types for lagrangian
std::unique_ptr<privateCache> cache_;
// Private Member Functions
//- No copy construct
fieldsCache(const fieldsCache&) = delete;
//- No copy assignment
void operator=(const fieldsCache&) = delete;
public:
// Constructors
//- Default construct
fieldsCache();
//- Destructor
~fieldsCache();
// Member Functions
//- No fields
bool empty() const;
//- Number of fields
label size() const;
//- Clear out
void clear();
//- Read all fields given mesh and objects
void readAllFields
(
const faMesh& mesh,
const IOobjectList& objects
);
//- Decompose and write all fields
void decomposeAllFields
(
const faFieldDecomposer& decomposer,
bool report = false
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
@ -391,8 +462,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "faFieldDecomposerFields.C"
#include "faFieldDecomposerReadFields.C"
#include "faFieldDecomposerTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,221 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "faFieldDecomposer.H"
#include "fieldsDistributor.H"
#include "areaFields.H"
#include "edgeFields.H"
#include "IOobjectList.H"
#include "PtrListOps.H"
// * * * * * * * * * * * * * * * * Declarations * * * * * * * * * * * * * * //
namespace Foam
{
// All area/edge field types
class faFieldDecomposer::fieldsCache::privateCache
{
public:
#undef declareField
#define declareField(Type) \
PtrList<GeometricField<Type, faPatchField, areaMesh>> Type##AreaFields_; \
PtrList<GeometricField<Type, faePatchField, edgeMesh>> Type##EdgeFields_;
declareField(scalar);
declareField(vector);
declareField(sphericalTensor);
declareField(symmTensor);
declareField(tensor);
#undef declareField
label size() const noexcept
{
label count = 0;
#undef doLocalCode
#define doLocalCode(Type) \
{ \
count += Type##AreaFields_.size(); \
count += Type##EdgeFields_.size(); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
return count;
}
bool empty() const noexcept { return !size(); }
void readAll(const faMesh& mesh, const IOobjectList& objects)
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##AreaFields_ \
); \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##AreaFields_, \
false /* readOldTime = false */ \
); \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##EdgeFields_, \
false /* readOldTime = false */ \
); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
template<class GeoField>
static void decompose
(
const faFieldDecomposer& decomposer,
const PtrList<GeoField>& fields,
bool report
)
{
if (!fields.empty())
{
if (report)
{
Info<< " "
<< pTraits<typename GeoField::value_type>::typeName
<< "s: "
<< flatOutput(PtrListOps::names(fields)) << nl;
}
decomposer.decomposeFields(fields);
}
}
void decomposeAll(const faFieldDecomposer& decomposer, bool report) const
{
#undef doLocalCode
#define doLocalCode(Flavour) \
{ \
decompose(decomposer, scalar##Flavour##Fields_, report); \
decompose(decomposer, vector##Flavour##Fields_, report); \
decompose(decomposer, sphericalTensor##Flavour##Fields_, report); \
decompose(decomposer, symmTensor##Flavour##Fields_, report); \
decompose(decomposer, tensor##Flavour##Fields_, report); \
}
doLocalCode(Area);
doLocalCode(Edge);
#undef doLocalCode
}
};
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::faFieldDecomposer::fieldsCache::fieldsCache()
:
cache_(new privateCache)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// Destructor not in header (used incomplete type)
Foam::faFieldDecomposer::fieldsCache::~fieldsCache()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::faFieldDecomposer::fieldsCache::empty() const
{
return (!cache_ || cache_->empty());
}
Foam::label Foam::faFieldDecomposer::fieldsCache::size() const
{
return (cache_ ? cache_->size() : label(0));
}
void Foam::faFieldDecomposer::fieldsCache::clear()
{
cache_.reset(new privateCache);
}
void Foam::faFieldDecomposer::fieldsCache::readAllFields
(
const faMesh& mesh,
const IOobjectList& objects
)
{
if (cache_)
{
cache_->readAll(mesh, objects);
}
}
void Foam::faFieldDecomposer::fieldsCache::decomposeAllFields
(
const faFieldDecomposer& decomposer,
bool report
) const
{
if (cache_)
{
cache_->decomposeAll(decomposer, report);
}
}
// ************************************************************************* //

View File

@ -1,92 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "faFieldDecomposer.H"
#include "GeometricField.H"
#include "IOobjectList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::faFieldDecomposer::readFields
(
const typename GeoMesh::Mesh& mesh,
const IOobjectList& objects,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields,
const bool readOldTime
)
{
typedef GeometricField<Type, PatchField, GeoMesh> GeoField;
// Search list of objects for fields of type GeoField
IOobjectList fieldObjects(objects.lookupClass<GeoField>());
// Use sorted set of names
// (different processors might read objects in different order)
const wordList masterNames(fieldObjects.sortedNames());
// Construct the fields
fields.resize(masterNames.size());
forAll(masterNames, i)
{
const IOobject& io = *fieldObjects[masterNames[i]];
fields.set(i, new GeoField(io, mesh, readOldTime));
}
}
template<class Mesh, class GeoField>
void Foam::faFieldDecomposer::readFields
(
const Mesh& mesh,
const IOobjectList& objects,
PtrList<GeoField>& fields
)
{
// Search list of objects for fields of type GeomField
IOobjectList fieldObjects(objects.lookupClass<GeoField>());
// Use sorted set of names
// (different processors might read objects in different order)
const wordList masterNames(fieldObjects.sortedNames());
// Construct the fields
fields.resize(masterNames.size());
forAll(masterNames, i)
{
const IOobject& io = *fieldObjects[masterNames[i]];
fields.set(i, new GeoField(io, mesh));
}
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,6 +27,8 @@ License
\*---------------------------------------------------------------------------*/
#include "faFieldDecomposer.H"
#include "GeometricField.H"
#include "IOobjectList.H"
#include "processorFaPatchField.H"
#include "processorFaePatchField.H"
@ -89,8 +91,8 @@ Foam::faFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_(),
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -200,8 +202,8 @@ Foam::faFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_(),
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),

View File

@ -47,16 +47,16 @@ void Foam::faMeshDecomposition::distributeFaces()
cpuTime decompositionTime;
for (label procI = 0; procI < nProcs(); procI++)
for (label proci = 0; proci < nProcs(); ++proci)
{
Time processorDb
(
Time::controlDictName,
time().rootPath(),
time().caseName()/("processor" + Foam::name(procI))
time().caseName()/("processor" + Foam::name(proci))
);
polyMesh procMesh
polyMesh procFvMesh
(
IOobject
(
@ -66,6 +66,24 @@ void Foam::faMeshDecomposition::distributeFaces()
)
);
IOobject ioAddr
(
"procAddressing",
"constant",
polyMesh::meshSubDir,
procFvMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false // not registered
);
// faceProcAddressing (polyMesh)
ioAddr.rename("faceProcAddressing");
labelIOList fvFaceProcAddressing(ioAddr);
labelHashSet faceProcAddressingHash(2*fvFaceProcAddressing.size());
// If faMesh's fvPatch is a part of the global face zones, faces of that
// patch will be present on all processors. Because of that, looping
// through faceProcAddressing will decompose global faMesh faces to the
@ -76,77 +94,31 @@ void Foam::faMeshDecomposition::distributeFaces()
// Vanja Skuric, 2016-04-21
if (hasGlobalFaceZones_)
{
labelList faceProcAddressing
(
labelIOList
(
IOobject
(
"faceProcAddressing",
"constant",
procMesh.meshSubDir,
procMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
const label ownerSize =
(
labelIOList
(
IOobject
(
"owner",
"constant",
procMesh.meshSubDir,
procMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
).size();
labelHashSet faceProcAddressingHash(ownerSize);
// owner (polyMesh)
ioAddr.rename("owner");
const label ownerSize = labelIOList(ioAddr).size();
for (int i = 0; i < ownerSize; ++i)
{
faceProcAddressingHash.insert(faceProcAddressing[i]);
}
forAll(faceLabels(), faceI)
{
if (faceProcAddressingHash.found(faceLabels()[faceI] + 1))
{
faceToProc_[faceI] = procI;
}
faceProcAddressingHash.insert(fvFaceProcAddressing[i]);
}
}
else
{
labelHashSet faceProcAddressingHash
faceProcAddressingHash.insert
(
labelIOList
(
IOobject
(
"faceProcAddressing",
"constant",
procMesh.meshSubDir,
procMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
static_cast<labelList&>(fvFaceProcAddressing)
);
}
forAll(faceLabels(), faceI)
forAll(faceLabels(), facei)
{
// With +1 for lookup in faceMap with flip encoding
const label index = (faceLabels()[facei] + 1);
if (faceProcAddressingHash.found(index))
{
if (faceProcAddressingHash.found(faceLabels()[faceI] + 1))
{
faceToProc_[faceI] = procI;
}
faceToProc_[facei] = proci;
}
}
}
@ -276,40 +248,37 @@ void Foam::faMeshDecomposition::decomposeMesh()
)
);
labelIOList fvPointProcAddressing
IOobject ioAddr
(
IOobject
(
"pointProcAddressing",
"constant",
procFvMesh.meshSubDir,
procFvMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
"procAddressing",
"constant",
polyMesh::meshSubDir,
procFvMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false // not registered
);
// pointProcAddressing (polyMesh)
ioAddr.rename("pointProcAddressing");
labelIOList fvPointProcAddressing(ioAddr);
Map<label> fvFaceProcAddressingHash;
{
labelIOList fvFaceProcAddressing
(
IOobject
(
"faceProcAddressing",
"constant",
procFvMesh.meshSubDir,
procFvMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
// faceProcAddressing (polyMesh)
ioAddr.rename("faceProcAddressing");
labelIOList fvFaceProcAddressing(ioAddr);
forAll(fvFaceProcAddressing, faceI)
fvFaceProcAddressingHash.resize(2*fvFaceProcAddressing.size());
forAll(fvFaceProcAddressing, facei)
{
fvFaceProcAddressingHash.insert
(
fvFaceProcAddressing[faceI], faceI
fvFaceProcAddressing[facei],
facei
);
}
};
@ -365,17 +334,16 @@ void Foam::faMeshDecomposition::decomposeMesh()
const uindirectPrimitivePatch& procPatch = procMesh.patch();
const vectorField& procPoints = procPatch.localPoints();
const labelList& procMeshPoints = procPatch.meshPoints();
const edgeList& procEdges = procPatch.edges();
labelList& curPatchPointAddressing = procPatchPointAddressing_[procI];
curPatchPointAddressing.setSize(procPoints.size(), -1);
curPatchPointAddressing.resize(procMeshPoints.size(), -1);
forAll(procPoints, pointI)
forAll(procMeshPoints, pointi)
{
curPatchPointAddressing[pointI] =
map[fvPointProcAddressing[procMeshPoints[pointI]]];
curPatchPointAddressing[pointi] =
map[fvPointProcAddressing[procMeshPoints[pointi]]];
}
labelList& curPatchEdgeAddressing = procPatchEdgeAddressing_[procI];
@ -1154,9 +1122,12 @@ bool Foam::faMeshDecomposition::writeDecomposition()
sharedPointLookup.insert(globallySharedPoints_[pointi], pointi);
}
label maxProcFaces = 0;
label totProcFaces = 0;
label maxProcEdges = 0;
label totProcEdges = 0;
label maxProcPatches = 0;
label maxProcEdges = 0;
label totProcPatches = 0;
// Write out the meshes
for (label procI = 0; procI < nProcs(); procI++)
@ -1193,7 +1164,7 @@ bool Foam::faMeshDecomposition::writeDecomposition()
(
"boundaryProcAddressing",
"constant",
procFvMesh.meshSubDir,
polyMesh::meshSubDir,
procFvMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
@ -1286,19 +1257,35 @@ bool Foam::faMeshDecomposition::writeDecomposition()
procMesh.write();
Info<< endl
<< "Processor " << procI << nl
<< " Number of faces = " << procMesh.nFaces()
<< endl;
// Statistics
Info<< nl << "Processor " << procI;
if (procMesh.nFaces())
{
Info<< nl << " ";
}
else
{
Info<< ": ";
}
Info<< "Number of faces = " << procMesh.nFaces() << nl;
if (procMesh.nFaces())
{
Info<< " Number of points = " << procMesh.nPoints() << nl;
}
totProcFaces += procMesh.nFaces();
maxProcFaces = max(maxProcFaces, procMesh.nFaces());
label nBoundaryEdges = 0;
label nProcPatches = 0;
label nProcEdges = 0;
forAll(procMesh.boundary(), patchi)
for (const faPatch& fap : procMesh.boundary())
{
const auto* ppp =
isA<processorFaPatch>(procMesh.boundary()[patchi]);
const auto* ppp = isA<processorFaPatch>(fap);
if (ppp)
{
@ -1306,92 +1293,93 @@ bool Foam::faMeshDecomposition::writeDecomposition()
Info<< " Number of edges shared with processor "
<< procPatch.neighbProcNo() << " = "
<< procPatch.size() << endl;
<< procPatch.size() << nl;
nProcEdges += procPatch.size();
++nProcPatches;
}
else
{
nBoundaryEdges += procMesh.boundary()[patchi].size();
nBoundaryEdges += fap.size();
}
}
Info<< " Number of processor patches = " << nProcPatches << nl
<< " Number of processor edges = " << nProcEdges << nl
<< " Number of boundary edges = " << nBoundaryEdges << endl;
if (procMesh.nFaces() && (nBoundaryEdges || nProcEdges))
{
Info<< " Number of processor patches = " << nProcPatches << nl
<< " Number of processor edges = " << nProcEdges << nl
<< " Number of boundary edges = " << nBoundaryEdges << nl;
}
totProcEdges += nProcEdges;
maxProcPatches = max(maxProcPatches, nProcPatches);
totProcPatches += nProcPatches;
maxProcEdges = max(maxProcEdges, nProcEdges);
maxProcPatches = max(maxProcPatches, nProcPatches);
// create and write the addressing information
labelIOList pointProcAddressing
(
IOobject
(
"pointProcAddressing",
"constant",
procMesh.meshSubDir,
procFvMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procPatchPointAddressing_[procI]
);
pointProcAddressing.write();
// Write the addressing information
labelIOList edgeProcAddressing
IOobject ioAddr
(
IOobject
(
"edgeProcAddressing",
"constant",
procMesh.meshSubDir,
procFvMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procEdgeAddressing_[procI]
"procAddressing",
"constant",
faMesh::meshSubDir,
procMesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false // not registered
);
edgeProcAddressing.write();
labelIOList faceProcAddressing
(
IOobject
(
"faceProcAddressing",
"constant",
procMesh.meshSubDir,
procFvMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFaceAddressing_[procI]
);
faceProcAddressing.write();
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
IOListRef<label>(ioAddr, procPatchPointAddressing_[procI]).write();
labelIOList boundaryProcAddressing
(
IOobject
(
"boundaryProcAddressing",
"constant",
procMesh.meshSubDir,
procFvMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procBoundaryAddressing_[procI]
);
boundaryProcAddressing.write();
// edgeProcAddressing
ioAddr.rename("edgeProcAddressing");
IOListRef<label>(ioAddr, procEdgeAddressing_[procI]).write();
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
IOListRef<label>(ioAddr, procFaceAddressing_[procI]).write();
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
IOListRef<label>(ioAddr, procBoundaryAddressing_[procI]).write();
}
// Summary stats
Info<< nl
<< "Number of processor edges = " << totProcEdges/2 << nl
<< "Max number of processor patches = " << maxProcPatches << nl
<< "Max number of faces between processors = " << maxProcEdges
<< endl;
<< "Number of processor edges = " << (totProcEdges/2) << nl
<< "Max number of faces = " << maxProcFaces;
if (maxProcFaces != totProcFaces)
{
scalar avgValue = scalar(totProcFaces)/nProcs_;
Info<< " (" << 100.0*(maxProcFaces-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl;
Info<< "Max number of processor patches = " << maxProcPatches;
if (totProcPatches)
{
scalar avgValue = scalar(totProcPatches)/nProcs_;
Info<< " (" << 100.0*(maxProcPatches-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl;
Info<< "Max number of edges between processors = " << maxProcEdges;
if (totProcEdges)
{
scalar avgValue = scalar(totProcEdges)/nProcs_;
Info<< " (" << 100.0*(maxProcEdges-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl << endl;
return true;
}

View File

@ -39,8 +39,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef faMeshDecomposition_H
#define faMeshDecomposition_H
#ifndef Foam_faMeshDecomposition_H
#define Foam_faMeshDecomposition_H
#include "polyMesh.H"
#include "faMesh.H"

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,6 +27,13 @@ License
\*---------------------------------------------------------------------------*/
#include "faFieldReconstructor.H"
#include "areaFields.H"
#include "edgeFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::faFieldReconstructor::verbose_ = 1;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -42,8 +50,42 @@ Foam::faFieldReconstructor::faFieldReconstructor
procMeshes_(procMeshes),
edgeProcAddressing_(edgeProcAddressing),
faceProcAddressing_(faceProcAddressing),
boundaryProcAddressing_(boundaryProcAddressing)
boundaryProcAddressing_(boundaryProcAddressing),
nReconstructed_(0)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::faFieldReconstructor::reconstructAllFields
(
const IOobjectList& objects,
const wordRes& selected
)
{
label nTotal = 0;
do
{
#undef doLocalCode
#define doLocalCode(Method) \
{ \
nTotal += this->Method <scalar> (objects, selected); \
nTotal += this->Method <vector> (objects, selected); \
nTotal += this->Method <sphericalTensor> (objects, selected); \
nTotal += this->Method <symmTensor> (objects, selected); \
nTotal += this->Method <tensor> (objects, selected); \
}
doLocalCode(reconstructAreaFields);
doLocalCode(reconstructEdgeFields);
#undef doLocalCode
}
while (false);
return nTotal;
}
// ************************************************************************* //

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,12 +36,12 @@ Author
SourceFiles
faFieldReconstructor.C
faFieldReconstructorFields.C
faFieldReconstructorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef faFieldReconstructor_H
#define faFieldReconstructor_H
#ifndef Foam_faFieldReconstructor_H
#define Foam_faFieldReconstructor_H
#include "PtrList.H"
#include "faMesh.H"
@ -59,7 +60,7 @@ namespace Foam
class faFieldReconstructor
{
// Private data
// Private Data
//- Reconstructed mesh reference
faMesh& mesh_;
@ -76,6 +77,9 @@ class faFieldReconstructor
//- List of processor boundary addressing lists
const PtrList<labelIOList>& boundaryProcAddressing_;
//- Number of fields reconstructed
label nReconstructed_;
// Private Member Functions
@ -88,6 +92,8 @@ class faFieldReconstructor
public:
// Public Classes
class faPatchFieldReconstructor
:
public faPatchFieldMapper
@ -111,7 +117,7 @@ public:
{}
// Member functions
// Member Functions
virtual label size() const
{
@ -140,13 +146,19 @@ public:
};
// Static Data
//- Output verbosity when writing
static int verbose_;
// Constructors
//- Construct from components
faFieldReconstructor
(
faMesh& mesh,
const PtrList<faMesh>& procMeshes,
faMesh& mesh, // Target mesh
const PtrList<faMesh>& procMeshes, // Source meshes
const PtrList<labelIOList>& edgeProcAddressing,
const PtrList<labelIOList>& faceProcAddressing,
const PtrList<labelIOList>& boundaryProcAddressing
@ -155,34 +167,80 @@ public:
// Member Functions
//- Return number of fields reconstructed
label nReconstructed() const noexcept
{
return nReconstructed_;
}
//- Reconstruct area field
template<class Type>
tmp<GeometricField<Type, faPatchField, areaMesh>>
reconstructFaAreaField
reconstructField
(
const IOobject& fieldIoObject
);
const IOobject& fieldObject,
const PtrList<GeometricField<Type, faPatchField, areaMesh>>&
) const;
//- Read and reconstruct area field
template<class Type>
tmp<GeometricField<Type, faPatchField, areaMesh>>
reconstructAreaField(const IOobject& fieldObject);
//- Reconstruct edge field
template<class Type>
tmp<GeometricField<Type, faePatchField, edgeMesh>>
reconstructFaEdgeField
reconstructField
(
const IOobject& fieldIoObject
const IOobject& fieldObject,
const PtrList<GeometricField<Type, faePatchField, edgeMesh>>&
) const;
//- Read and reconstruct edge field
template<class Type>
tmp<GeometricField<Type, faePatchField, edgeMesh>>
reconstructEdgeField(const IOobject& fieldObject);
//- Read, reconstruct and write specified area fields
template<class Type>
label reconstructAreaFields
(
const UPtrList<const IOobject>& fieldObjects
);
//- Reconstruct and write all area fields
//- Read, reconstruct and write specified edge fields
template<class Type>
void reconstructFaAreaFields
label reconstructEdgeFields
(
const IOobjectList& objects
const UPtrList<const IOobject>& fieldObjects
);
//- Reconstruct and write all area fields
//- Read, reconstruct and write all/selected area fields
// An empty wordRes corresponds to select ALL.
template<class Type>
void reconstructFaEdgeFields
label reconstructAreaFields
(
const IOobjectList& objects
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
//- Read, reconstruct and write all/selected edge fields
// An empty wordRes corresponds to select ALL.
template<class Type>
label reconstructEdgeFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
//- Reconstruct all supported area/edge field types
label reconstructAllFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
};
@ -194,7 +252,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "faFieldReconstructorFields.C"
# include "faFieldReconstructorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,37 +38,12 @@ License
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::faPatchField, Foam::areaMesh>>
Foam::faFieldReconstructor::reconstructFaAreaField
Foam::faFieldReconstructor::reconstructField
(
const IOobject& fieldIoObject
)
const IOobject& fieldObject,
const PtrList<GeometricField<Type, faPatchField, areaMesh>>& procFields
) const
{
// Read the field for all the processors
PtrList<GeometricField<Type, faPatchField, areaMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, procI)
{
procFields.set
(
procI,
new GeometricField<Type, faPatchField, areaMesh>
(
IOobject
(
fieldIoObject.name(),
procMeshes_[procI].time().timeName(),
procMeshes_[procI](),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[procI]
)
);
}
// Create the internalField
Field<Type> internalField(mesh_.nFaces());
@ -278,9 +253,9 @@ Foam::faFieldReconstructor::reconstructFaAreaField
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_(),
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -294,38 +269,12 @@ Foam::faFieldReconstructor::reconstructFaAreaField
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::faePatchField, Foam::edgeMesh>>
Foam::faFieldReconstructor::reconstructFaEdgeField
Foam::faFieldReconstructor::reconstructField
(
const IOobject& fieldIoObject
)
const IOobject& fieldObject,
const PtrList<GeometricField<Type, faePatchField, edgeMesh>>& procFields
) const
{
// Read the field for all the processors
PtrList<GeometricField<Type, faePatchField, edgeMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, procI)
{
procFields.set
(
procI,
new GeometricField<Type, faePatchField, edgeMesh>
(
IOobject
(
fieldIoObject.name(),
procMeshes_[procI].time().timeName(),
procMeshes_[procI](),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[procI]
)
);
}
// Create the internalField
Field<Type> internalField(mesh_.nInternalEdges());
@ -555,9 +504,9 @@ Foam::faFieldReconstructor::reconstructFaEdgeField
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_(),
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -569,58 +518,209 @@ Foam::faFieldReconstructor::reconstructFaEdgeField
}
// Reconstruct and write all area fields
template<class Type>
void Foam::faFieldReconstructor::reconstructFaAreaFields
Foam::tmp<Foam::GeometricField<Type, Foam::faPatchField, Foam::areaMesh>>
Foam::faFieldReconstructor::reconstructAreaField
(
const IOobjectList& objects
const IOobject& fieldObject
)
{
const word& clsName =
GeometricField<Type, faPatchField, areaMesh>::typeName;
// Read the field for all the processors
PtrList<GeometricField<Type, faPatchField, areaMesh>> procFields
(
procMeshes_.size()
);
const wordList fieldNames = objects.sortedNames(clsName);
if (fieldNames.size())
forAll(procMeshes_, proci)
{
Info<< " Reconstructing " << clsName << "s\n" << endl;
procFields.set
(
proci,
new GeometricField<Type, faPatchField, areaMesh>
(
IOobject
(
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
for (const word& fieldName : fieldNames)
{
Info << " " << fieldName << endl;
reconstructFaAreaField<Type>(*(objects[fieldName]))().write();
}
if (fieldNames.size()) Info<< endl;
return reconstructField
(
IOobject
(
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
// Reconstruct and write all edge fields
template<class Type>
void Foam::faFieldReconstructor::reconstructFaEdgeFields
Foam::tmp<Foam::GeometricField<Type, Foam::faePatchField, Foam::edgeMesh>>
Foam::faFieldReconstructor::reconstructEdgeField
(
const IOobjectList& objects
const IOobject& fieldObject
)
{
const word& clsName =
GeometricField<Type, faePatchField, edgeMesh>::typeName;
// Read the field for all the processors
PtrList<GeometricField<Type, faePatchField, edgeMesh>> procFields
(
procMeshes_.size()
);
const wordList fieldNames = objects.sortedNames(clsName);
if (fieldNames.size())
forAll(procMeshes_, proci)
{
Info<< " Reconstructing " << clsName << "s\n" << endl;
procFields.set
(
proci,
new GeometricField<Type, faePatchField, edgeMesh>
(
IOobject
(
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
for (const word& fieldName : fieldNames)
{
Info << " " << fieldName << endl;
return reconstructField
(
IOobject
(
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
reconstructFaEdgeField<Type>(*(objects[fieldName]))().write();
template<class Type>
Foam::label Foam::faFieldReconstructor::reconstructAreaFields
(
const UPtrList<const IOobject>& fieldObjects
)
{
typedef GeometricField<Type, faPatchField, areaMesh> fieldType;
label nFields = 0;
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructAreaField<Type>(io)().write();
++nReconstructed_;
}
}
if (fieldNames.size()) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::faFieldReconstructor::reconstructEdgeFields
(
const UPtrList<const IOobject>& fieldObjects
)
{
typedef GeometricField<Type, faePatchField, edgeMesh> fieldType;
label nFields = 0;
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructEdgeField<Type>(io)().write();
++nReconstructed_;
}
}
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::faFieldReconstructor::reconstructAreaFields
(
const IOobjectList& objects,
const wordRes& selectedFields
)
{
typedef GeometricField<Type, faPatchField, areaMesh> fieldType;
return reconstructAreaFields<Type>
(
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
}
template<class Type>
Foam::label Foam::faFieldReconstructor::reconstructEdgeFields
(
const IOobjectList& objects,
const wordRes& selectedFields
)
{
typedef GeometricField<Type, faePatchField, edgeMesh> fieldType;
return reconstructEdgeFields<Type>
(
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
}

View File

@ -77,7 +77,7 @@ void Foam::faMeshReconstructor::calcAddressing
for (label& facei : faFaceProcAddr_)
{
// Use finiteVolume info, ignoring face flips
facei = mag(fvFaceProcAddr[facei] - 1);
facei = mag(fvFaceProcAddr[facei])-1;
}
@ -449,7 +449,7 @@ void Foam::faMeshReconstructor::initPatch() const
void Foam::faMeshReconstructor::createMesh()
{
const Time& runTime = procMesh_.mesh().time();
const Time& runTime = procMesh_.thisDb().time();
// Time for non-parallel case (w/o functionObjects or libs)
serialRunTime_ = Time::New(runTime.globalPath().toAbsolute());
@ -654,7 +654,7 @@ void Foam::faMeshReconstructor::writeAddressing(const word& timeName) const
"procAddressing",
timeName,
faMesh::meshSubDir,
procMesh_.mesh(), // The polyMesh
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false // not registered
@ -662,19 +662,19 @@ void Foam::faMeshReconstructor::writeAddressing(const word& timeName) const
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
labelIOList(ioAddr, faBoundaryProcAddr_).write();
IOListRef<label>(ioAddr, faBoundaryProcAddr_).write();
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
labelIOList(ioAddr, faFaceProcAddr_).write();
IOListRef<label>(ioAddr, faFaceProcAddr_).write();
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
labelIOList(ioAddr, faPointProcAddr_).write();
IOListRef<label>(ioAddr, faPointProcAddr_).write();
// edgeProcAddressing
ioAddr.rename("edgeProcAddressing");
labelIOList(ioAddr, faEdgeProcAddr_).write();
IOListRef<label>(ioAddr, faEdgeProcAddr_).write();
}
@ -699,7 +699,7 @@ void Foam::faMeshReconstructor::writeMesh(const word& timeName) const
IOobject io(fullMesh.boundary());
io.rename("faceLabels");
labelIOList(io, singlePatchFaceLabels_).write();
IOListRef<label>(io, singlePatchFaceLabels_).write();
fullMesh.boundary().write();

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,102 +28,50 @@ License
#include "processorFaMeshes.H"
#include "Time.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::processorFaMeshes::read()
{
forAll(fvMeshes_, procI)
forAll(fvMeshes_, proci)
{
meshes_.set
meshes_.set(proci, new faMesh(fvMeshes_[proci]));
// Read the addressing information
IOobject ioAddr
(
procI,
new faMesh(fvMeshes_[procI])
"procAddressing",
"constant", // Placeholder
faMesh::meshSubDir,
meshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
);
pointProcAddressing_.set
(
procI,
new labelIOList
(
IOobject
(
"pointProcAddressing",
meshes_[procI].time().findInstance
(
meshes_[procI].meshDir(),
"pointProcAddressing"
),
meshes_[procI].meshSubDir,
fvMeshes_[procI],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
const auto& runTime = meshes_[proci].thisDb().time();
const auto& meshDir = meshes_[proci].meshDir();
edgeProcAddressing_.set
(
procI,
new labelIOList
(
IOobject
(
"edgeProcAddressing",
meshes_[procI].time().findInstance
(
meshes_[procI].meshDir(),
"edgeProcAddressing"
),
meshes_[procI].meshSubDir,
fvMeshes_[procI],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// pointProcAddressing (faMesh)
ioAddr.rename("pointProcAddressing");
ioAddr.instance() = runTime.findInstance(meshDir, ioAddr.name());
pointProcAddressing_.set(proci, new labelIOList(ioAddr));
faceProcAddressing_.set
(
procI,
new labelIOList
(
IOobject
(
"faceProcAddressing",
meshes_[procI].time().findInstance
(
meshes_[procI].meshDir(),
"faceProcAddressing"
),
meshes_[procI].meshSubDir,
fvMeshes_[procI],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// edgeProcAddressing (faMesh)
ioAddr.rename("edgeProcAddressing");
ioAddr.instance() = runTime.findInstance(meshDir, ioAddr.name());
edgeProcAddressing_.set(proci, new labelIOList(ioAddr));
boundaryProcAddressing_.set
(
procI,
new labelIOList
(
IOobject
(
"boundaryProcAddressing",
meshes_[procI].time().findInstance
(
meshes_[procI].meshDir(),
"faceProcAddressing"
),
meshes_[procI].meshSubDir,
fvMeshes_[procI],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// faceProcAddressing (faMesh)
ioAddr.rename("faceProcAddressing");
ioAddr.instance() = runTime.findInstance(meshDir, ioAddr.name());
faceProcAddressing_.set(proci, new labelIOList(ioAddr));
// boundaryProcAddressing (faMesh)
ioAddr.rename("boundaryProcAddressing");
ioAddr.instance() = runTime.findInstance(meshDir, ioAddr.name());
boundaryProcAddressing_.set(proci, new labelIOList(ioAddr));
}
}
@ -131,11 +80,11 @@ void Foam::processorFaMeshes::read()
Foam::processorFaMeshes::processorFaMeshes
(
const UPtrList<fvMesh>& processorFvMeshes
const UPtrList<fvMesh>& procFvMeshes
)
:
fvMeshes_(processorFvMeshes),
meshes_(processorFvMeshes.size()),
fvMeshes_(procFvMeshes),
meshes_(procFvMeshes.size()),
pointProcAddressing_(meshes_.size()),
edgeProcAddressing_(meshes_.size()),
faceProcAddressing_(meshes_.size()),
@ -145,4 +94,40 @@ Foam::processorFaMeshes::processorFaMeshes
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::processorFaMeshes::removeFiles(const faMesh& mesh)
{
IOobject ioAddr
(
"procAddressing",
mesh.facesInstance(),
faMesh::meshSubDir,
mesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false // not registered
);
// procAddressing
rm(ioAddr.objectPath());
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
rm(ioAddr.objectPath());
// edgeProcAddressing
ioAddr.rename("edgeProcAddressing");
rm(ioAddr.objectPath());
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
rm(ioAddr.objectPath());
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
rm(ioAddr.objectPath());
}
// ************************************************************************* //

View File

@ -37,8 +37,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef processorFaMeshes_H
#define processorFaMeshes_H
#ifndef Foam_processorFaMeshes_H
#define Foam_processorFaMeshes_H
#include "PtrList.H"
#include "faMesh.H"
@ -57,7 +57,7 @@ namespace Foam
class processorFaMeshes
{
// Private data
// Private Data
//- List of processor finite volume meshes
const UPtrList<fvMesh>& fvMeshes_;
@ -95,40 +95,44 @@ public:
// Constructors
//- Construct from components
explicit processorFaMeshes(const UPtrList<fvMesh>& processorFvMeshes);
explicit processorFaMeshes(const UPtrList<fvMesh>& procFvMeshes);
// Member Functions
const PtrList<faMesh>& meshes() const
const PtrList<faMesh>& meshes() const noexcept
{
return meshes_;
}
PtrList<faMesh>& meshes()
PtrList<faMesh>& meshes() noexcept
{
return meshes_;
}
const PtrList<labelIOList>& pointProcAddressing() const
const PtrList<labelIOList>& pointProcAddressing() const noexcept
{
return pointProcAddressing_;
}
PtrList<labelIOList>& edgeProcAddressing()
PtrList<labelIOList>& edgeProcAddressing() noexcept
{
return edgeProcAddressing_;
}
const PtrList<labelIOList>& faceProcAddressing() const
const PtrList<labelIOList>& faceProcAddressing() const noexcept
{
return faceProcAddressing_;
}
const PtrList<labelIOList>& boundaryProcAddressing() const
const PtrList<labelIOList>& boundaryProcAddressing() const noexcept
{
return boundaryProcAddressing_;
}
//- Helper: remove all procAddressing files from mesh instance
static void removeFiles(const faMesh& mesh);
};

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,6 +27,13 @@ License
\*---------------------------------------------------------------------------*/
#include "fvFieldReconstructor.H"
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::fvFieldReconstructor::verbose_ = 1;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -71,4 +79,38 @@ Foam::fvFieldReconstructor::fvFieldReconstructor
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::fvFieldReconstructor::reconstructAllFields
(
const IOobjectList& objects,
const wordRes& selected
)
{
label nTotal = 0;
do
{
#undef doLocalCode
#define doLocalCode(Method) \
{ \
nTotal += this->Method <scalar> (objects, selected); \
nTotal += this->Method <vector> (objects, selected); \
nTotal += this->Method <sphericalTensor> (objects, selected); \
nTotal += this->Method <symmTensor> (objects, selected); \
nTotal += this->Method <tensor> (objects, selected); \
}
doLocalCode(reconstructInternalFields);
doLocalCode(reconstructVolumeFields);
doLocalCode(reconstructSurfaceFields);
#undef doLocalCode
}
while (false);
return nTotal;
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,12 +32,12 @@ Description
SourceFiles
fvFieldReconstructor.C
fvFieldReconstructorFields.C
fvFieldReconstructorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef fvFieldReconstructor_H
#define fvFieldReconstructor_H
#ifndef Foam_fvFieldReconstructor_H
#define Foam_fvFieldReconstructor_H
#include "PtrList.H"
#include "fvMesh.H"
@ -56,7 +56,7 @@ namespace Foam
class fvFieldReconstructor
{
// Private data
// Private Data
//- Reconstructed mesh reference
fvMesh& mesh_;
@ -88,6 +88,8 @@ class fvFieldReconstructor
public:
// Public Classes
//- Mapper for sizing only - does not do any actual mapping.
class fvPatchFieldReconstructor
:
@ -130,6 +132,12 @@ public:
};
// Static Data
//- Output verbosity when writing
static int verbose_;
// Constructors
//- Construct from components
@ -146,7 +154,7 @@ public:
// Member Functions
//- Return number of fields reconstructed
label nReconstructed() const
label nReconstructed() const noexcept
{
return nReconstructed_;
}
@ -154,76 +162,74 @@ public:
//- Reconstruct volume internal field
template<class Type>
tmp<DimensionedField<Type, volMesh>>
reconstructFvVolumeInternalField
reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<DimensionedField<Type, volMesh>>& procFields
) const;
//- Read and reconstruct volume internal field
template<class Type>
tmp<DimensionedField<Type, volMesh>>
reconstructFvVolumeInternalField(const IOobject& fieldIoObject) const;
reconstructInternalField(const IOobject& fieldObject) const;
//- Reconstruct volume field
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh>>
reconstructFvVolumeField
reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<GeometricField<Type, fvPatchField, volMesh>>&
) const;
//- Read and reconstruct volume field
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh>>
reconstructFvVolumeField(const IOobject& fieldIoObject) const;
reconstructVolumeField(const IOobject& fieldObject) const;
//- Reconstruct surface field
template<class Type>
tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>
reconstructFvSurfaceField
reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<GeometricField<Type, fvsPatchField, surfaceMesh>>&
) const;
//- Read and reconstruct surface field
template<class Type>
tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>
reconstructFvSurfaceField(const IOobject& fieldIoObject) const;
reconstructSurfaceField(const IOobject& fieldObject) const;
//- Read, reconstruct and write specified volume internal fields
template<class Type>
label reconstructFvVolumeInternalFields
label reconstructInternalFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
);
//- Read, reconstruct and write specified volume fields
template<class Type>
label reconstructFvVolumeFields
label reconstructVolumeFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
);
//- Read, reconstruct and write specified surface fields
template<class Type>
label reconstructFvSurfaceFields
label reconstructSurfaceFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
);
//- Read, reconstruct and write all/selected volume internal fields
// An empty wordRes corresponds to select ALL.
template<class Type>
label reconstructFvVolumeInternalFields
label reconstructInternalFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
@ -232,7 +238,7 @@ public:
//- Read, reconstruct and write all/selected volume fields
// An empty wordRes corresponds to select ALL.
template<class Type>
label reconstructFvVolumeFields
label reconstructVolumeFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
@ -241,40 +247,17 @@ public:
//- Read, reconstruct and write all/selected surface fields
// An empty wordRes corresponds to select ALL.
template<class Type>
label reconstructFvSurfaceFields
label reconstructSurfaceFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
//- Read, reconstruct and write all/selected volume internal fields
// An empty wordHashSet corresponds to select ALL.
// \note this may be removed in the future (2018-11)
template<class Type>
label reconstructFvVolumeInternalFields
//- Reconstruct all known field types
label reconstructAllFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
);
//- Read, reconstruct and write all/selected volume fields
// An empty wordHashSet corresponds to select ALL.
// \note this may be removed in the future (2018-11)
template<class Type>
label reconstructFvVolumeFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
);
//- Read, reconstruct and write all/selected surface fields
// An empty wordHashSet corresponds to select ALL.
// \note this may be removed in the future (2018-11)
template<class Type>
label reconstructFvSurfaceFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
const wordRes& selectedFields = wordRes()
);
};
@ -286,7 +269,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fvFieldReconstructorFields.C"
#include "fvFieldReconstructorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,9 +38,9 @@ License
template<class Type>
Foam::tmp<Foam::DimensionedField<Type, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
Foam::fvFieldReconstructor::reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<DimensionedField<Type, volMesh>>& procFields
) const
{
@ -61,7 +61,7 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
auto tfield = tmp<DimensionedField<Type, volMesh>>::New
(
fieldIoObject,
fieldObject,
mesh_,
procFields[0].dimensions(),
internalField
@ -73,59 +73,11 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
}
template<class Type>
Foam::tmp<Foam::DimensionedField<Type, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
(
const IOobject& fieldIoObject
) const
{
// Read the field for all the processors
PtrList<DimensionedField<Type, volMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new DimensionedField<Type, volMesh>
(
IOobject
(
fieldIoObject.name(),
procMeshes_[proci].time().timeName(),
procMeshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
return reconstructFvVolumeInternalField
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructFvVolumeField
Foam::fvFieldReconstructor::reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<GeometricField<Type, fvPatchField, volMesh>>& procFields
) const
{
@ -137,8 +89,7 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
forAll(procFields, proci)
{
const GeometricField<Type, fvPatchField, volMesh>& procField =
procFields[proci];
const auto& procField = procFields[proci];
// Set the cell values in the reconstructed field
internalField.rmap
@ -287,7 +238,7 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
// setting the internalField and patchFields
auto tfield = tmp<GeometricField<Type, fvPatchField, volMesh>>::New
(
fieldIoObject,
fieldObject,
mesh_,
procFields[0].dimensions(),
internalField,
@ -300,59 +251,11 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructFvVolumeField
(
const IOobject& fieldIoObject
) const
{
// Read the field for all the processors
PtrList<GeometricField<Type, fvPatchField, volMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new GeometricField<Type, fvPatchField, volMesh>
(
IOobject
(
fieldIoObject.name(),
procMeshes_[proci].time().timeName(),
procMeshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
return reconstructFvVolumeField
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh>>
Foam::fvFieldReconstructor::reconstructFvSurfaceField
Foam::fvFieldReconstructor::reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<GeometricField<Type, fvsPatchField, surfaceMesh>>& procFields
) const
{
@ -365,8 +268,7 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
forAll(procMeshes_, proci)
{
const GeometricField<Type, fvsPatchField, surfaceMesh>& procField =
procFields[proci];
const auto& procField = procFields[proci];
// Set the face values in the reconstructed field
@ -529,7 +431,7 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
// setting the internalField and patchFields
auto tfield = tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>::New
(
fieldIoObject,
fieldObject,
mesh_,
procFields[0].dimensions(),
internalField,
@ -543,10 +445,106 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh>>
Foam::fvFieldReconstructor::reconstructFvSurfaceField
Foam::tmp<Foam::DimensionedField<Type, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructInternalField
(
const IOobject& fieldIoObject
const IOobject& fieldObject
) const
{
// Read the field for all the processors
PtrList<DimensionedField<Type, volMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new DimensionedField<Type, volMesh>
(
IOobject
(
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
return reconstructField
(
IOobject
(
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructVolumeField
(
const IOobject& fieldObject
) const
{
// Read the field for all the processors
PtrList<GeometricField<Type, fvPatchField, volMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new GeometricField<Type, fvPatchField, volMesh>
(
IOobject
(
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
return reconstructField
(
IOobject
(
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh>>
Foam::fvFieldReconstructor::reconstructSurfaceField
(
const IOobject& fieldObject
) const
{
// Read the field for all the processors
@ -564,9 +562,9 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
(
IOobject
(
fieldIoObject.name(),
procMeshes_[proci].time().timeName(),
procMeshes_[proci],
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
@ -575,13 +573,13 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
);
}
return reconstructFvSurfaceField
return reconstructField
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_,
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -591,103 +589,113 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeInternalFields
Foam::label Foam::fvFieldReconstructor::reconstructInternalFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
)
{
typedef DimensionedField<Type, volMesh> fieldType;
label nFields = 0;
for (const word& fieldName : fieldNames)
{
const IOobject* io = objects.cfindObject<fieldType>(fieldName);
if (io)
{
if (!nFields++)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructFvVolumeInternalField<Type>(*io)().write();
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructInternalField<Type>(io)().write();
++nReconstructed_;
}
}
if (nFields) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeFields
Foam::label Foam::fvFieldReconstructor::reconstructVolumeFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
)
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
label nFields = 0;
for (const word& fieldName : fieldNames)
{
const IOobject* io = objects.cfindObject<fieldType>(fieldName);
if (io)
{
if (!nFields++)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructFvVolumeField<Type>(*io)().write();
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructVolumeField<Type>(io)().write();
++nReconstructed_;
}
}
if (nFields) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvSurfaceFields
Foam::label Foam::fvFieldReconstructor::reconstructSurfaceFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
)
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> fieldType;
label nFields = 0;
for (const word& fieldName : fieldNames)
{
const IOobject* io = objects.cfindObject<fieldType>(fieldName);
if (io)
{
if (!nFields++)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructFvSurfaceField<Type>(*io)().write();
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructSurfaceField<Type>(io)().write();
++nReconstructed_;
}
}
if (nFields) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeInternalFields
Foam::label Foam::fvFieldReconstructor::reconstructInternalFields
(
const IOobjectList& objects,
const wordRes& selectedFields
@ -695,19 +703,19 @@ Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeInternalFields
{
typedef DimensionedField<Type, volMesh> fieldType;
const wordList fieldNames =
return reconstructInternalFields<Type>
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
return reconstructFvVolumeInternalFields<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeFields
Foam::label Foam::fvFieldReconstructor::reconstructVolumeFields
(
const IOobjectList& objects,
const wordRes& selectedFields
@ -715,19 +723,19 @@ Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeFields
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const wordList fieldNames =
return reconstructVolumeFields<Type>
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
return reconstructFvVolumeFields<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvSurfaceFields
Foam::label Foam::fvFieldReconstructor::reconstructSurfaceFields
(
const IOobjectList& objects,
const wordRes& selectedFields
@ -735,74 +743,14 @@ Foam::label Foam::fvFieldReconstructor::reconstructFvSurfaceFields
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> fieldType;
const wordList fieldNames =
return reconstructSurfaceFields<Type>
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
return reconstructFvSurfaceFields<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeInternalFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
)
{
typedef DimensionedField<Type, volMesh> fieldType;
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
);
return reconstructFvVolumeInternalFields<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
)
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
);
return reconstructFvVolumeField<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvSurfaceFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
)
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> fieldType;
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
);
return reconstructFvSurfaceFields<Type>(objects, fieldNames);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018,2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -29,6 +29,11 @@ License
#include "lagrangianReconstructor.H"
#include "passivePositionParticleCloud.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::lagrangianReconstructor::verbose_ = 1;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lagrangianReconstructor::lagrangianReconstructor
@ -142,4 +147,44 @@ Foam::label Foam::lagrangianReconstructor::reconstructPositions
}
void Foam::lagrangianReconstructor::reconstructAllFields
(
const word& cloudName,
const IOobjectList& cloudObjs,
const wordRes& selectedFields
)
{
do
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
this->reconstructFields<Type> \
( \
cloudName, \
cloudObjs, \
selectedFields \
); \
\
this->reconstructFieldFields<Type> \
( \
cloudName, \
cloudObjs, \
selectedFields \
); \
}
doLocalCode(label);
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
while (false);
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,12 +32,12 @@ Description
SourceFiles
lagrangianReconstructor.C
lagrangianReconstructorFields.C
lagrangianReconstructorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef lagrangianReconstructor_H
#define lagrangianReconstructor_H
#ifndef Foam_lagrangianReconstructor_H
#define Foam_lagrangianReconstructor_H
#include "cloud.H"
#include "polyMesh.H"
@ -56,7 +56,7 @@ namespace Foam
class lagrangianReconstructor
{
// Private data
// Private Data
//- Mesh reference
const fvMesh& mesh_;
@ -82,6 +82,12 @@ class lagrangianReconstructor
public:
// Static Data
//- Output verbosity when writing
static int verbose_;
// Constructors
//- Construct from components
@ -101,7 +107,8 @@ public:
//- Reconstruct a single field for given cloud
template<class Type>
tmp<IOField<Type>> reconstructField
tmp<IOField<Type>>
reconstructField
(
const word& cloudName,
const word& fieldName
@ -109,7 +116,8 @@ public:
//- Reconstruct a single field-field for given cloud
template<class Type>
tmp<CompactIOField<Field<Type>, Type>> reconstructFieldField
tmp<CompactIOField<Field<Type>, Type>>
reconstructFieldField
(
const word& cloudName,
const word& fieldName
@ -120,8 +128,7 @@ public:
label reconstructFields
(
const word& cloudName,
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
);
//- Reconstruct multiple fields for given cloud
@ -141,6 +148,14 @@ public:
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
//- Reconstruct all fields for known cloud field types
void reconstructAllFields
(
const word& cloudName,
const IOobjectList& cloudObjs,
const wordRes& selectedFields = wordRes()
);
};
@ -151,7 +166,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "lagrangianReconstructorFields.C"
#include "lagrangianReconstructorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -153,30 +153,33 @@ template<class Type>
Foam::label Foam::lagrangianReconstructor::reconstructFields
(
const word& cloudName,
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
)
{
typedef IOField<Type> fieldType;
label nFields = 0;
for (const word& fieldName : fieldNames)
{
const IOobject* io = objects.cfindObject<fieldType>(fieldName);
if (io)
{
if (nFields++)
{
Info<< " Reconstructing lagrangian "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructField<Type>(cloudName, fieldName)().write();
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing lagrangian "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructField<Type>(cloudName, io.name())().write();
}
}
if (nFields) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
@ -191,14 +194,15 @@ Foam::label Foam::lagrangianReconstructor::reconstructFields
{
typedef IOField<Type> fieldType;
const wordList fieldNames =
return reconstructFields<Type>
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
cloudName,
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
return reconstructFields<Type>(cloudName, objects, fieldNames);
}
@ -211,38 +215,41 @@ Foam::label Foam::lagrangianReconstructor::reconstructFieldFields
)
{
typedef CompactIOField<Field<Type>, Type> fieldType;
typedef IOField<Field<Type>> fieldTypeB;
wordList fieldNames =
(
selectedFields.empty()
? objects.names<fieldType>()
: objects.names<fieldType>(selectedFields)
);
UPtrList<const IOobject> fieldObjects;
// Append IOField Field names
fieldNames.append
(
objects.empty()
? objects.names<IOField<Field<Type>>>()
: objects.names<IOField<Field<Type>>>(selectedFields)
);
Foam::sort(fieldNames);
label nFields = 0;
for (const word& fieldName : fieldNames)
if (selectedFields.empty())
{
if (!nFields++)
{
Info<< " Reconstructing lagrangian "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructFieldField<Type>(cloudName, fieldName)().write();
fieldObjects.append(objects.sorted<fieldType>());
fieldObjects.append(objects.sorted<fieldTypeB>());
}
else
{
fieldObjects.append(objects.sorted<fieldType>(selectedFields));
fieldObjects.append(objects.sorted<fieldTypeB>(selectedFields));
}
if (nFields) Info<< endl;
Foam::sort(fieldObjects, nameOp<IOobject>());
label nFields = 0;
for (const IOobject& io : fieldObjects)
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing lagrangian "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructFieldField<Type>(cloudName, io.name())().write();
}
if (verbose_ && nFields) Info<< endl;
return nFields;
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,6 +27,12 @@ License
\*---------------------------------------------------------------------------*/
#include "pointFieldReconstructor.H"
#include "pointFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::pointFieldReconstructor::verbose_ = 1;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -95,4 +102,24 @@ Foam::pointFieldReconstructor::pointFieldReconstructor
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::pointFieldReconstructor::reconstructAllFields
(
const IOobjectList& objects,
const wordRes& selected
)
{
label nTotal = 0;
nTotal += reconstructPointFields<scalar>(objects, selected);
nTotal += reconstructPointFields<vector>(objects, selected);
nTotal += reconstructPointFields<symmTensor>(objects, selected);
nTotal += reconstructPointFields<sphericalTensor>(objects, selected);
nTotal += reconstructPointFields<tensor>(objects, selected);
return nTotal;
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,12 +32,12 @@ Description
SourceFiles
pointFieldReconstructor.C
pointFieldReconstructorFields.C
pointFieldReconstructorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef pointFieldReconstructor_H
#define pointFieldReconstructor_H
#ifndef Foam_pointFieldReconstructor_H
#define Foam_pointFieldReconstructor_H
#include "pointMesh.H"
#include "pointFields.H"
@ -55,7 +55,7 @@ namespace Foam
class pointFieldReconstructor
{
// Private data
// Private Data
//- Reconstructed mesh reference
const pointMesh& mesh_;
@ -87,6 +87,8 @@ class pointFieldReconstructor
public:
// Public Classes
class pointPatchFieldReconstructor
:
public pointPatchFieldMapper
@ -128,6 +130,12 @@ public:
};
// Static Data
//- Output verbosity when writing
static int verbose_;
// Constructors
//- Construct from components
@ -143,41 +151,48 @@ public:
// Member Functions
//- Return number of fields reconstructed
label nReconstructed() const
label nReconstructed() const noexcept
{
return nReconstructed_;
}
//- Reconstruct field
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh>>
reconstructField(const IOobject& fieldIoObject);
//- Reconstruct and write specified fields
template<class Type>
label reconstructFields
reconstructField
(
const IOobjectList& objects,
const UList<word>& fieldNames
const IOobject& fieldObject,
const PtrList<GeometricField<Type, pointPatchField, pointMesh>>&
) const;
//- Read and reconstruct point field
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh>>
reconstructPointField(const IOobject& fieldObject);
//- Reconstruct and write specified point fields
template<class Type>
label reconstructPointFields
(
const UPtrList<const IOobject>& fieldObjects
);
//- Reconstruct and write all or selected fields
//- Reconstruct and write all or selected point fields
// An empty wordRes corresponds to select ALL.
template<class Type>
label reconstructFields
label reconstructPointFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
//- Reconstruct and write all or selected fields
// An empty wordHashSet corresponds to select ALL.
// \note this may be removed in the future (2018-11)
template<class Type>
label reconstructFields
//- Reconstruct and write all known field types
label reconstructAllFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
const wordRes& selectedFields = wordRes()
);
};
@ -189,7 +204,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "pointFieldReconstructorFields.C"
#include "pointFieldReconstructorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,34 +32,13 @@ License
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::pointPatchField, Foam::pointMesh>>
Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
Foam::pointFieldReconstructor::reconstructField
(
const IOobject& fieldObject,
const PtrList<GeometricField<Type, pointPatchField, pointMesh>>& procFields
) const
{
// Read the field for all the processors
PtrList<GeometricField<Type, pointPatchField, pointMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new GeometricField<Type, pointPatchField, pointMesh>
(
IOobject
(
fieldIoObject.name(),
procMeshes_[proci]().time().timeName(),
procMeshes_[proci](),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
typedef GeometricField<Type, pointPatchField, pointMesh> fieldType;
// Create the internalField
Field<Type> internalField(mesh_.size());
@ -70,8 +49,7 @@ Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
forAll(procMeshes_, proci)
{
const GeometricField<Type, pointPatchField, pointMesh>&
procField = procFields[proci];
const auto& procField = procFields[proci];
// Get processor-to-global addressing for use in rmap
const labelList& procToGlobalAddr = pointProcAddressing_[proci];
@ -120,13 +98,13 @@ Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
// Construct and write the field
// setting the internalField and patchFields
return tmp<GeometricField<Type, pointPatchField, pointMesh>>::New
return tmp<fieldType>::New
(
IOobject
(
fieldIoObject.name(),
mesh_().time().timeName(),
mesh_(),
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -139,39 +117,89 @@ Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
template<class Type>
Foam::label Foam::pointFieldReconstructor::reconstructFields
Foam::tmp<Foam::GeometricField<Type, Foam::pointPatchField, Foam::pointMesh>>
Foam::pointFieldReconstructor::reconstructPointField
(
const IOobjectList& objects,
const UList<word>& fieldNames
const IOobject& fieldObject
)
{
typedef GeometricField<Type, pointPatchField, pointMesh> fieldType;
// Read the field for all the processors
PtrList<fieldType> procFields(procMeshes_.size());
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new fieldType
(
IOobject
(
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
return reconstructField
(
IOobject
(
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
template<class Type>
Foam::label Foam::pointFieldReconstructor::reconstructPointFields
(
const UPtrList<const IOobject>& fieldObjects
)
{
typedef GeometricField<Type, pointPatchField, pointMesh> fieldType;
label nFields = 0;
for (const word& fieldName : fieldNames)
{
const IOobject* io = objects.cfindObject<fieldType>(fieldName);
if (io)
{
if (!nFields++)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructField<Type>(*io)().write();
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructPointField<Type>(io)().write();
++nReconstructed_;
}
}
if (nFields) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::pointFieldReconstructor::reconstructFields
Foam::label Foam::pointFieldReconstructor::reconstructPointFields
(
const IOobjectList& objects,
const wordRes& selectedFields
@ -179,34 +207,14 @@ Foam::label Foam::pointFieldReconstructor::reconstructFields
{
typedef GeometricField<Type, pointPatchField, pointMesh> fieldType;
const wordList fieldNames =
return reconstructPointFields<Type>
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
return reconstructFields<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::pointFieldReconstructor::reconstructFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
)
{
typedef GeometricField<Type, pointPatchField, pointMesh> fieldType;
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
);
return reconstructFields<Type>(objects, fieldNames);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,8 +28,9 @@ License
#include "processorMeshes.H"
#include "Time.H"
#include "IndirectList.H"
#include "primitiveMesh.H"
#include "topoSet.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -70,73 +71,33 @@ void Foam::processorMeshes::read()
)
);
pointProcAddressing_.set
// Read the addressing information
IOobject ioAddr
(
proci,
new labelIOList
(
IOobject
(
"pointProcAddressing",
meshes_[proci].facesInstance(),
meshes_[proci].meshSubDir,
meshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
"procAddressing",
meshes_[proci].facesInstance(),
polyMesh::meshSubDir,
meshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
);
faceProcAddressing_.set
(
proci,
new labelIOList
(
IOobject
(
"faceProcAddressing",
meshes_[proci].facesInstance(),
meshes_[proci].meshSubDir,
meshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// pointProcAddressing (polyMesh)
ioAddr.rename("pointProcAddressing");
pointProcAddressing_.set(proci, new labelIOList(ioAddr));
cellProcAddressing_.set
(
proci,
new labelIOList
(
IOobject
(
"cellProcAddressing",
meshes_[proci].facesInstance(),
meshes_[proci].meshSubDir,
meshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// faceProcAddressing (polyMesh)
ioAddr.rename("faceProcAddressing");
faceProcAddressing_.set(proci, new labelIOList(ioAddr));
boundaryProcAddressing_.set
(
proci,
new labelIOList
(
IOobject
(
"boundaryProcAddressing",
meshes_[proci].facesInstance(),
meshes_[proci].meshSubDir,
meshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// cellProcAddressing (polyMesh)
ioAddr.rename("cellProcAddressing");
cellProcAddressing_.set(proci, new labelIOList(ioAddr));
// boundaryProcAddressing (polyMesh)
ioAddr.rename("boundaryProcAddressing");
boundaryProcAddressing_.set(proci, new labelIOList(ioAddr));
}
}
@ -163,17 +124,17 @@ Foam::processorMeshes::processorMeshes
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::fvMesh::readUpdateState Foam::processorMeshes::readUpdate()
Foam::polyMesh::readUpdateState Foam::processorMeshes::readUpdate()
{
fvMesh::readUpdateState stat = fvMesh::UNCHANGED;
polyMesh::readUpdateState stat = polyMesh::UNCHANGED;
forAll(databases_, proci)
{
// Check if any new meshes need to be read.
fvMesh::readUpdateState procStat = meshes_[proci].readUpdate();
polyMesh::readUpdateState procStat = meshes_[proci].readUpdate();
/*
if (procStat != fvMesh::UNCHANGED)
if (procStat != polyMesh::UNCHANGED)
{
Info<< "Processor " << proci
<< " at time " << databases_[proci].timeName()
@ -183,7 +144,7 @@ Foam::fvMesh::readUpdateState Foam::processorMeshes::readUpdate()
*/
// Combine into overall mesh change status
if (stat == fvMesh::UNCHANGED)
if (stat == polyMesh::UNCHANGED)
{
stat = procStat;
}
@ -203,8 +164,8 @@ Foam::fvMesh::readUpdateState Foam::processorMeshes::readUpdate()
if
(
stat == fvMesh::TOPO_CHANGE
|| stat == fvMesh::TOPO_PATCH_CHANGE
stat == polyMesh::TOPO_CHANGE
|| stat == polyMesh::TOPO_PATCH_CHANGE
)
{
// Reread all meshes and addressing
@ -231,7 +192,7 @@ void Foam::processorMeshes::reconstructPoints(fvMesh& mesh)
"points",
meshes_[proci].time().timeName(),
polyMesh::meshSubDir,
meshes_[proci],
meshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
@ -247,23 +208,19 @@ void Foam::processorMeshes::reconstructPoints(fvMesh& mesh)
{
const vectorField& procPoints = procsPoints[proci];
// Set the cell values in the reconstructed field
const labelList& pointProcAddr = pointProcAddressing_[proci];
const labelList& pointProcAddressingI = pointProcAddressing_[proci];
if (pointProcAddressingI.size() != procPoints.size())
if (pointProcAddr.size() != procPoints.size())
{
FatalErrorInFunction
<< "problem :"
<< " pointProcAddressingI:" << pointProcAddressingI.size()
<< " pointProcAddr:" << pointProcAddr.size()
<< " procPoints:" << procPoints.size()
<< abort(FatalError);
}
forAll(pointProcAddressingI, pointi)
{
newPoints[pointProcAddressingI[pointi]] = procPoints[pointi];
}
UIndirectList<point>(newPoints, pointProcAddr) = procPoints;
// or: newPoints.rmap(procPoints, pointProcAddr)
}
mesh.movePoints(newPoints);
@ -273,59 +230,35 @@ void Foam::processorMeshes::reconstructPoints(fvMesh& mesh)
void Foam::processorMeshes::removeFiles(const polyMesh& mesh)
{
fileName pointPath
IOobject ioAddr
(
IOobject
(
"pointProcAddressing",
mesh.facesInstance(),
mesh.meshSubDir,
mesh
).objectPath()
"procAddressing",
mesh.facesInstance(),
polyMesh::meshSubDir,
mesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false // not registered
);
if (topoSet::debug) DebugVar(pointPath);
rm(pointPath);
rm
(
IOobject
(
"faceProcAddressing",
mesh.facesInstance(),
mesh.meshSubDir,
mesh
).objectPath()
);
rm
(
IOobject
(
"cellProcAddressing",
mesh.facesInstance(),
mesh.meshSubDir,
mesh
).objectPath()
);
rm
(
IOobject
(
"boundaryProcAddressing",
mesh.facesInstance(),
mesh.meshSubDir,
mesh
).objectPath()
);
rm
(
IOobject
(
"procAddressing",
mesh.facesInstance(),
mesh.meshSubDir,
mesh
).objectPath()
);
// procAddressing
rm(ioAddr.objectPath());
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
rm(ioAddr.objectPath());
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
rm(ioAddr.objectPath());
// cellProcAddressing
ioAddr.rename("cellProcAddressing");
rm(ioAddr.objectPath());
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
rm(ioAddr.objectPath());
}

View File

@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef processorMeshes_H
#define processorMeshes_H
#ifndef Foam_processorMeshes_H
#define Foam_processorMeshes_H
#include "PtrList.H"
#include "fvMesh.H"
@ -54,7 +54,7 @@ namespace Foam
class processorMeshes
{
// Private data
// Private Data
const word meshName_;
@ -104,41 +104,42 @@ public:
// Member Functions
//- Update the meshes based on the mesh files saved in time directories
fvMesh::readUpdateState readUpdate();
polyMesh::readUpdateState readUpdate();
//- Reconstruct point position after motion in parallel
void reconstructPoints(fvMesh&);
const PtrList<fvMesh>& meshes() const
const PtrList<fvMesh>& meshes() const noexcept
{
return meshes_;
}
PtrList<fvMesh>& meshes()
PtrList<fvMesh>& meshes() noexcept
{
return meshes_;
}
const PtrList<labelIOList>& pointProcAddressing() const
const PtrList<labelIOList>& pointProcAddressing() const noexcept
{
return pointProcAddressing_;
}
PtrList<labelIOList>& faceProcAddressing()
PtrList<labelIOList>& faceProcAddressing() noexcept
{
return faceProcAddressing_;
}
const PtrList<labelIOList>& cellProcAddressing() const
const PtrList<labelIOList>& cellProcAddressing() const noexcept
{
return cellProcAddressing_;
}
const PtrList<labelIOList>& boundaryProcAddressing() const
const PtrList<labelIOList>& boundaryProcAddressing() const noexcept
{
return boundaryProcAddressing_;
}
//- Helper: remove all procAddressing files from mesh instance
static void removeFiles(const polyMesh& mesh);
};