From 94c7e180fbd2313f2a96adf1f1dd26a8cb42a24e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sat, 19 Nov 2022 14:30:50 +0100 Subject: [PATCH] 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. --- .../finiteArea/makeFaMesh/decomposeFaFields.H | 18 ++++- .../decompose/faDecompose/faFieldDecomposer.H | 2 +- .../faReconstruct/faMeshReconstructor.C | 70 ++++++++++++------- .../faReconstruct/faMeshReconstructor.H | 21 ++++-- 4 files changed, 78 insertions(+), 33 deletions(-) diff --git a/applications/utilities/finiteArea/makeFaMesh/decomposeFaFields.H b/applications/utilities/finiteArea/makeFaMesh/decomposeFaFields.H index 373d5c71e1..00068a1dea 100644 --- a/applications/utilities/finiteArea/makeFaMesh/decomposeFaFields.H +++ b/applications/utilities/finiteArea/makeFaMesh/decomposeFaFields.H @@ -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); // ************************************************************************* // diff --git a/src/parallel/decompose/faDecompose/faFieldDecomposer.H b/src/parallel/decompose/faDecompose/faFieldDecomposer.H index 8816cdc4be..deaf82a174 100644 --- a/src/parallel/decompose/faDecompose/faFieldDecomposer.H +++ b/src/parallel/decompose/faDecompose/faFieldDecomposer.H @@ -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 cache_; diff --git a/src/parallel/reconstruct/faReconstruct/faMeshReconstructor.C b/src/parallel/reconstruct/faReconstruct/faMeshReconstructor.C index e8b3345785..4a51a54725 100644 --- a/src/parallel/reconstruct/faReconstruct/faMeshReconstructor.C +++ b/src/parallel/reconstruct/faReconstruct/faMeshReconstructor.C @@ -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() + ); + + 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()) { diff --git a/src/parallel/reconstruct/faReconstruct/faMeshReconstructor.H b/src/parallel/reconstruct/faReconstruct/faMeshReconstructor.H index 8cf5154f44..9ffc740003 100644 --- a/src/parallel/reconstruct/faReconstruct/faMeshReconstructor.H +++ b/src/parallel/reconstruct/faReconstruct/faMeshReconstructor.H @@ -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 {