ENH: more fault-tolerance in makeFaMesh decomposition

- if the volume faceProcAddressing is missing, it is not readily
  possible to determine equivalent area procAddressing.

  Instead of throwing an error, be more fault-tolerant by having it
  create with READ_IF_PRESENT and then detect and warn
  if there are problems.
This commit is contained in:
Mark Olesen 2022-11-19 14:30:50 +01:00
parent 67b58c28c0
commit 94c7e180fb
4 changed files with 78 additions and 33 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -15,9 +15,21 @@ Description
\*---------------------------------------------------------------------------*/
// Embed do-while to support early termination
if (doDecompose && Pstream::parRun())
do
{
faMeshReconstructor reconstructor(aMesh);
faMeshReconstructor reconstructor(aMesh, IOobjectOption::READ_IF_PRESENT);
if (!reconstructor.good())
{
Info<< "Missing volume proc-addressing, "
"cannot generate area proc-addressing." << nl
<< "Also skip decomposing area fields...."
<< endl;
break;
}
reconstructor.writeAddressing();
Info<< "Wrote proc-addressing" << nl << endl;
@ -77,7 +89,7 @@ if (doDecompose && Pstream::parRun())
areaFieldsCache.decomposeAllFields(fieldDecomposer, true);
Info<< endl;
}
}
} while (false);
// ************************************************************************* //

View File

@ -402,7 +402,7 @@ class faFieldDecomposer::fieldsCache
class privateCache;
//- All field and field-field types for lagrangian
//- All field and field-field types for finiteArea
std::unique_ptr<privateCache> cache_;

View File

@ -466,7 +466,7 @@ void Foam::faMeshReconstructor::createMesh()
IOobject::NO_READ,
IOobject::NO_WRITE,
false // not registered
IOobject::NO_REGISTER
),
pointField(singlePatchPoints_), // copy
faceList(singlePatchFaces_), // copy
@ -525,10 +525,12 @@ void Foam::faMeshReconstructor::createMesh()
Foam::faMeshReconstructor::faMeshReconstructor
(
const faMesh& procMesh
const faMesh& procMesh,
IOobjectOption::readOption readVolAddressing
)
:
procMesh_(procMesh)
procMesh_(procMesh),
errors_(0)
{
if (!Pstream::parRun())
{
@ -537,32 +539,49 @@ Foam::faMeshReconstructor::faMeshReconstructor
<< exit(FatalError);
}
// Require faceProcAddressing from finiteVolume decomposition
labelIOList fvFaceProcAddressing
IOobject ioAddr
(
IOobject
(
"faceProcAddressing",
procMesh_.mesh().facesInstance(),
"faceProcAddressing",
procMesh_.mesh().facesInstance(),
// Or search?
// procMesh_.time().findInstance
// (
// // Search for polyMesh face instance
// // mesh.facesInstance()
// procMesh_.mesh().meshDir(),
// "faceProcAddressing"
// ),
// Or search?
// procMesh_.time().findInstance
// (
// // Search for polyMesh face instance
// // mesh.facesInstance()
// procMesh_.mesh().meshDir(),
// "faceProcAddressing"
// ),
polyMesh::meshSubDir,
procMesh_.mesh(), // The polyMesh db
IOobject::MUST_READ,
IOobject::NO_WRITE,
false // not registered
)
polyMesh::meshSubDir,
procMesh_.mesh(), // The polyMesh db
readVolAddressing, // Read option
IOobject::NO_WRITE,
IOobject::NO_REGISTER
);
calcAddressing(fvFaceProcAddressing);
// Require faceProcAddressing from finiteVolume decomposition
labelIOList fvFaceProcAddr(ioAddr);
// Check if any/all where read.
// Use 'headerClassName' for checking
bool fileOk
(
(fvFaceProcAddr.readOpt() != IOobjectOption::NO_READ)
&& fvFaceProcAddr.isHeaderClass<labelIOList>()
);
Pstream::reduceAnd(fileOk);
if (fileOk)
{
calcAddressing(fvFaceProcAddr);
}
else
{
errors_ = 1;
}
}
@ -572,7 +591,8 @@ Foam::faMeshReconstructor::faMeshReconstructor
const labelUList& fvFaceProcAddressing
)
:
procMesh_(procMesh)
procMesh_(procMesh),
errors_(0)
{
if (!Pstream::parRun())
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -44,8 +44,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef faMeshReconstructor_H
#define faMeshReconstructor_H
#ifndef Foam_faMeshReconstructor_H
#define Foam_faMeshReconstructor_H
#include "faMesh.H"
#include "primitivePatch.H"
@ -69,6 +69,11 @@ class faMeshReconstructor
//- The processor-specific faMesh
const faMesh& procMesh_;
// Flags
//- Problems encountered during construction?
int errors_;
// Addressing
@ -142,7 +147,12 @@ public:
// Constructors
//- Construct from components
explicit faMeshReconstructor(const faMesh& procMesh);
explicit faMeshReconstructor
(
const faMesh& procMesh,
IOobjectOption::readOption readVolProcAddr =
IOobjectOption::MUST_READ
);
//- Construct from components
faMeshReconstructor
@ -160,6 +170,9 @@ public:
// Member Functions
//- True if no construct errors encountered
bool good() const noexcept { return !errors_; }
//- Processor point addressing
const labelList& pointProcAddressing() const noexcept
{