mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: handle try-construct faMesh (#2399)
- a try/catch approach is not really robust enough (or even possible)
since read failures likely do not occur on all ranks simultaneously.
This leads to situations where the master has thrown an exception
(and thus exiting the current routine) while other ranks are still
waiting to receive data and the program blocks completely.
Since this primarily affects data conversion routines such as
foamToEnsight etc, treat similarly to lagrangian: check for the
existence of essential files before proceeding or not. This is
wrapped into a TryNew factory method:
autoPtr<faMesh> faMeshPtr(faMesh::TryNew(mesh));
if (faMeshPtr) ...
This commit is contained in:
@ -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.
|
||||
@ -65,18 +65,7 @@ PtrList<ensightFaMesh> ensightMeshesFa(regionNames.size());
|
||||
|
||||
if (doFiniteArea)
|
||||
{
|
||||
autoPtr<faMesh> faMeshPtr;
|
||||
|
||||
const bool oldThrowingError = FatalError.throwing(true);
|
||||
try
|
||||
{
|
||||
faMeshPtr.reset(new faMesh(mesh));
|
||||
}
|
||||
catch (const Foam::error& err)
|
||||
{
|
||||
faMeshPtr.reset(nullptr);
|
||||
}
|
||||
FatalError.throwing(oldThrowingError);
|
||||
autoPtr<faMesh> faMeshPtr(faMesh::TryNew(mesh));
|
||||
|
||||
if (faMeshPtr)
|
||||
{
|
||||
@ -91,7 +80,7 @@ PtrList<ensightFaMesh> ensightMeshesFa(regionNames.size());
|
||||
)
|
||||
);
|
||||
|
||||
meshesFa.set(regioni, faMeshPtr);
|
||||
meshesFa.set(regioni, std::move(faMeshPtr));
|
||||
|
||||
ensightMeshesFa.set
|
||||
(
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -46,16 +46,7 @@ if (doFiniteArea)
|
||||
|
||||
if (nAreaFields)
|
||||
{
|
||||
const bool oldThrowingError = FatalError.throwing(true);
|
||||
try
|
||||
{
|
||||
faMeshPtr.reset(new faMesh(meshProxy.baseMesh()));
|
||||
}
|
||||
catch (const Foam::error& err)
|
||||
{
|
||||
faMeshPtr.clear();
|
||||
}
|
||||
FatalError.throwing(oldThrowingError);
|
||||
faMeshPtr = faMesh::TryNew(meshProxy.baseMesh());
|
||||
}
|
||||
|
||||
if (faMeshPtr && nAreaFields)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
faMesh/faGlobalMeshData/faGlobalMeshData.C
|
||||
faMesh/faMesh.C
|
||||
faMesh/faMeshNew.C
|
||||
faMesh/faMeshDemandDrivenData.C
|
||||
faMesh/faMeshPatches.C
|
||||
faMesh/faMeshTopology.C
|
||||
|
||||
@ -43,8 +43,8 @@ Author
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef faMesh_H
|
||||
#define faMesh_H
|
||||
#ifndef Foam_faMesh_H
|
||||
#define Foam_faMesh_H
|
||||
|
||||
#include "MeshObject.H"
|
||||
#include "polyMesh.H"
|
||||
@ -454,6 +454,15 @@ class faMesh
|
||||
}
|
||||
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Test if faSchemes/faSolution files are available
|
||||
static bool hasSystemFiles(const polyMesh& pMesh);
|
||||
|
||||
//- Test if all files needed for read construction are available
|
||||
static bool hasFiles(const polyMesh& pMesh);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Public Typedefs
|
||||
@ -504,6 +513,12 @@ public:
|
||||
virtual ~faMesh();
|
||||
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Read construction from polyMesh if all files are available
|
||||
static autoPtr<faMesh> TryNew(const polyMesh& pMesh);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Helpers
|
||||
|
||||
157
src/finiteArea/faMesh/faMeshNew.C
Normal file
157
src/finiteArea/faMesh/faMeshNew.C
Normal file
@ -0,0 +1,157 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "faMesh.H"
|
||||
#include "polyMesh.H"
|
||||
#include "fileOperation.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::faMesh::hasSystemFiles(const polyMesh& pMesh)
|
||||
{
|
||||
// Expect
|
||||
// - system/faSchemes
|
||||
// - system/faSolution
|
||||
|
||||
const fileOperation& fp = Foam::fileHandler();
|
||||
|
||||
bool looksValid = true;
|
||||
|
||||
// Global files: system/{faSchemes,faSolution}
|
||||
for
|
||||
(
|
||||
const word& expect
|
||||
: List<word>
|
||||
({
|
||||
{"faSchemes"},
|
||||
{"faSolution"}
|
||||
})
|
||||
)
|
||||
{
|
||||
fileName found
|
||||
(
|
||||
fp.filePath
|
||||
(
|
||||
true, // global
|
||||
IOobject
|
||||
(
|
||||
expect,
|
||||
pMesh.time().system(),
|
||||
pMesh,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
),
|
||||
expect // typeName (ununsed?)
|
||||
)
|
||||
);
|
||||
|
||||
if (found.empty())
|
||||
{
|
||||
looksValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
Pstream::broadcast(looksValid);
|
||||
|
||||
return looksValid;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::faMesh::hasFiles(const polyMesh& pMesh)
|
||||
{
|
||||
// As well as system/{faSchemes,faSolution}
|
||||
//
|
||||
// expect these:
|
||||
// - timeValue/faMesh/faBoundary
|
||||
// - timeValue/instance/faMesh/faceLabels
|
||||
|
||||
bool looksValid = hasSystemFiles(pMesh);
|
||||
|
||||
if (looksValid)
|
||||
{
|
||||
const fileOperation& fp = Foam::fileHandler();
|
||||
|
||||
fileName subDir(pMesh.dbDir()/faMesh::meshSubDir);
|
||||
|
||||
for
|
||||
(
|
||||
const wordPair& expect
|
||||
: List<wordPair>
|
||||
({
|
||||
{"faBoundary", "faBoundaryMesh"},
|
||||
{"faceLabels", "labelList"}
|
||||
})
|
||||
)
|
||||
{
|
||||
const word& dataFile = expect.first();
|
||||
const word& dataClass = expect.second();
|
||||
|
||||
fileName found
|
||||
(
|
||||
fp.filePath
|
||||
(
|
||||
false, // non-global
|
||||
IOobject
|
||||
(
|
||||
dataFile,
|
||||
pMesh.time().findInstance(subDir, dataFile),
|
||||
faMesh::meshSubDir,
|
||||
pMesh,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
),
|
||||
dataClass // typeName (ununsed?)
|
||||
)
|
||||
);
|
||||
|
||||
if (found.empty())
|
||||
{
|
||||
looksValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
Pstream::broadcast(looksValid);
|
||||
}
|
||||
|
||||
return looksValid;
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::faMesh> Foam::faMesh::TryNew(const polyMesh& pMesh)
|
||||
{
|
||||
if (faMesh::hasFiles(pMesh))
|
||||
{
|
||||
return autoPtr<faMesh>::New(pMesh);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user