ENH: improve handling of finiteArea mesh with distributed roots

- in makeFaMesh, the serial fields are now only read on the master
  process and broadcast to the other ranks. The read+distribute is
  almost identical to that used in redistributePar, except that in
  this case entire fields are sent and not a zero-sized subset.

- improved internal faMesh checking for files so that the TryNew
  method works with distributed roots.
This commit is contained in:
Mark Olesen
2022-11-20 15:16:31 +01:00
parent 21e7ce8f42
commit 013f3cccc4
17 changed files with 440 additions and 243 deletions

View File

@ -95,7 +95,8 @@ int main(int argc, char *argv[])
Info<< "Time = " << runTime.timeName() << nl << endl;
#include "printMeshSummary.H"
// Mesh information (verbose)
faMeshTools::printMeshChecks(aMesh);
if (args.found("write-vtk"))
{

View File

@ -1,183 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Summary of faMesh information
\*---------------------------------------------------------------------------*/
{
const faBoundaryMesh& patches = aMesh.boundary();
const label nNonProcessor = patches.nNonProcessor();
const label nPatches = patches.size();
label nLocalProcEdges = 0;
if (Pstream::parRun())
{
for (const faPatch& fap : patches)
{
const auto* cpp = isA<processorFaPatch>(fap);
if (cpp)
{
nLocalProcEdges += fap.nEdges();
}
}
}
const labelList nFaces
(
UPstream::listGatherValues<label>(aMesh.nFaces())
);
const labelList nPoints
(
UPstream::listGatherValues<label>(aMesh.nPoints())
);
const labelList nEdges
(
UPstream::listGatherValues<label>(aMesh.nEdges())
);
const labelList nIntEdges
(
UPstream::listGatherValues<label>(aMesh.nInternalEdges())
);
// The "real" (non-processor) boundary edges
const labelList nBndEdges
(
UPstream::listGatherValues<label>
(
aMesh.nBoundaryEdges() - nLocalProcEdges
)
);
const labelList nProcEdges
(
UPstream::listGatherValues<label>(nLocalProcEdges)
);
// Format output as
// Number of faces: ...
// per-proc: (...)
const auto reporter =
[&](const char* tag, const labelList& list)
{
Info<< " Number of " << tag << ": " << sum(list) << nl;
if (Pstream::parRun())
{
int padding = static_cast<int>
(
// strlen(" Number of ") - strlen("per-proc")
(12 - 8)
+ strlen(tag)
);
do { Info<< ' '; } while (--padding > 0);
Info<< "per-proc: " << flatOutput(list) << nl;
}
};
Info<< "----------------" << nl
<< "Mesh Information" << nl
<< "----------------" << nl
<< " " << "boundingBox: " << boundBox(aMesh.points()) << nl;
if (Pstream::master())
{
reporter("faces", nFaces);
reporter("points", nPoints);
reporter("edges", nEdges);
reporter("internal edges", nIntEdges);
reporter("boundary edges", nBndEdges);
if (Pstream::parRun())
{
reporter("processor edges", nProcEdges);
}
}
Info<< "----------------" << nl
<< "Patches" << nl
<< "----------------" << nl;
for (label patchi = 0; patchi < nNonProcessor; ++patchi)
{
const faPatch& p = patches[patchi];
// Report physical size (nEdges) not virtual size
Info<< " " << "patch " << p.index()
<< " (size: " << returnReduce(p.nEdges(), sumOp<label>())
<< ") name: " << p.name()
<< nl;
}
Info<< "----------------" << nl
<< "Used polyPatches: " << flatOutput(aMesh.whichPolyPatches()) << nl;
// Geometry information
Info<< nl;
{
scalarMinMax limit(gMinMax(aMesh.S().field()));
Info<< "Face area:" << nl
<< " min = " << limit.min() << " max = " << limit.max() << nl;
}
{
scalarMinMax limit(minMax(aMesh.magLe().primitiveField()));
// Include processor boundaries into 'internal' edges
if (Pstream::parRun())
{
for (label patchi = nNonProcessor; patchi < nPatches; ++patchi)
{
limit.add(minMax(aMesh.magLe().boundaryField()[patchi]));
}
reduce(limit, minMaxOp<scalar>());
}
Info<< "Edge length (internal):" << nl
<< " min = " << limit.min() << " max = " << limit.max() << nl;
// Include (non-processor) boundaries
for (label patchi = 0; patchi < nNonProcessor; ++patchi)
{
limit.add(minMax(aMesh.magLe().boundaryField()[patchi]));
}
if (Pstream::parRun())
{
reduce(limit, minMaxOp<scalar>());
}
Info<< "Edge length:" << nl
<< " min = " << limit.min() << " max = " << limit.max() << nl;
}
// Not particularly meaningful
#if 0
{
MinMax<vector> limit(gMinMax(aMesh.faceAreaNormals().field()));
Info<< "Face area normals:" << nl
<< " min = " << limit.min() << " max = " << limit.max() << nl;
}
#endif
}
// ************************************************************************* //

View File

@ -30,44 +30,63 @@ do
break;
}
reconstructor.writeAddressing();
reconstructor.writeMesh(); // Writes on master only
reconstructor.writeAddressing(); // Writes per-proc
Info<< "Wrote proc-addressing" << nl << endl;
Info<< "Wrote proc-addressing and serial mesh" << nl << endl;
// Handle area fields
// ------------------
faFieldDecomposer::fieldsCache areaFieldsCache;
const faMesh& fullMesh = reconstructor.mesh();
const faMesh& serialMesh = reconstructor.mesh();
if (doDecompFields)
{
// Use uncollated (or master uncollated) file handler here.
// - each processor is reading in the identical serial fields.
// - nothing should be parallel-coordinated.
// The serial finite-area mesh exists and is identical on all
// processors, but its fields can only reliably be read on the
// master (eg, running with distributed roots).
//
// - mark mesh fields as readable on master only (haveMeshOnProc)
// - 'subset' entire serial mesh so that a full copy will be
// broadcast to other ranks (subsetterPtr)
// - scan available IOobjects on the master only
// Similarly, if we write the serial finite-area mesh, this is only
// done from one processor!
bitSet haveMeshOnProc;
std::unique_ptr<faMeshSubset> subsetter;
IOobjectList objects(0);
reconstructor.writeMesh();
const bool oldDistributed = fileHandler().distributed();
auto oldHandler = fileHandler(fileOperation::NewUncollated());
fileHandler().distributed(true);
if (doDecompFields)
if (Pstream::master())
{
const bool oldDistributed = fileHandler().distributed();
auto oldHandler = fileHandler(fileOperation::NewUncollated());
fileHandler().distributed(true);
haveMeshOnProc.set(Pstream::myProcNo());
subsetter.reset(new faMeshSubset(serialMesh));
IOobjectList objects(fullMesh.time(), runTime.timeName());
const bool oldParRun = Pstream::parRun(false);
areaFieldsCache.readAllFields(fullMesh, objects);
objects = IOobjectList(serialMesh.time(), runTime.timeName());
// Restore old settings
if (oldHandler)
{
fileHandler(std::move(oldHandler));
}
fileHandler().distributed(oldDistributed);
Pstream::parRun(oldParRun);
}
// Restore old settings
if (oldHandler)
{
fileHandler(std::move(oldHandler));
}
fileHandler().distributed(oldDistributed);
areaFieldsCache.readAllFields
(
haveMeshOnProc,
subsetter.get(),
serialMesh,
objects
);
}
const label nAreaFields = areaFieldsCache.size();
@ -78,7 +97,7 @@ do
faFieldDecomposer fieldDecomposer
(
fullMesh,
serialMesh,
aMesh,
reconstructor.edgeProcAddressing(),
reconstructor.faceProcAddressing(),

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.
@ -42,13 +42,14 @@ Original Authors
#include "argList.H"
#include "OSspecific.H"
#include "faMesh.H"
#include "faMeshTools.H"
#include "IOdictionary.H"
#include "IOobjectList.H"
#include "areaFields.H"
#include "edgeFields.H"
#include "faFieldDecomposer.H"
#include "faMeshReconstructor.H"
#include "faMeshSubset.H"
#include "PtrListOps.H"
#include "foamVtkIndPatchWriter.H"
#include "OBJstream.H"
@ -131,8 +132,8 @@ int main(int argc, char *argv[])
// Create
faMesh aMesh(mesh, meshDefDict);
// Mesh information
#include "printMeshSummary.H"
// Mesh information (less verbose)
faMeshTools::printMeshChecks(aMesh, 0);
if (args.found("write-edges-obj"))
{

View File

@ -1,104 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Summary of faMesh information
\*---------------------------------------------------------------------------*/
{
const faBoundaryMesh& patches = aMesh.boundary();
const label nNonProcessor = patches.nNonProcessor();
const label nPatches = patches.size();
Info<< "----------------" << nl
<< "Mesh Information" << nl
<< "----------------" << nl
<< " " << "boundingBox: " << boundBox(aMesh.points()) << nl
<< " " << "nFaces: " << returnReduce(aMesh.nFaces(), sumOp<label>())
<< nl;
Info<< "----------------" << nl
<< "Patches" << nl
<< "----------------" << nl;
for (label patchi = 0; patchi < nNonProcessor; ++patchi)
{
const faPatch& p = patches[patchi];
// Report physical size (nEdges) not virtual size
Info<< " " << "patch " << p.index()
<< " (size: " << returnReduce(p.nEdges(), sumOp<label>())
<< ") name: " << p.name()
<< nl;
}
Info<< "----------------" << nl
<< "Used polyPatches: " << flatOutput(aMesh.whichPolyPatches()) << nl;
// Geometry information
Info<< nl;
{
scalarMinMax limit(gMinMax(aMesh.S().field()));
Info<< "Face area:" << nl
<< " min = " << limit.min() << " max = " << limit.max() << nl;
}
{
scalarMinMax limit(minMax(aMesh.magLe().primitiveField()));
// Include processor boundaries into 'internal' edges
if (Pstream::parRun())
{
for (label patchi = nNonProcessor; patchi < nPatches; ++patchi)
{
limit.add(minMax(aMesh.magLe().boundaryField()[patchi]));
}
reduce(limit, minMaxOp<scalar>());
}
Info<< "Edge length (internal):" << nl
<< " min = " << limit.min() << " max = " << limit.max() << nl;
// Include (non-processor) boundaries
for (label patchi = 0; patchi < nNonProcessor; ++patchi)
{
limit.add(minMax(aMesh.magLe().boundaryField()[patchi]));
}
if (Pstream::parRun())
{
reduce(limit, minMaxOp<scalar>());
}
Info<< "Edge length:" << nl
<< " min = " << limit.min()
<< " max = " << limit.max() << nl;
}
// Not particularly meaningful
#if 0
{
MinMax<vector> limit(gMinMax(aMesh.faceAreaNormals().field()));
Info<< "Face area normals:" << nl
<< " min = " << limit.min() << " max = " << limit.max() << nl;
}
#endif
}
// ************************************************************************* //