diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.H index 909d3dfedf..13c7a6034d 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.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. @@ -65,18 +65,7 @@ PtrList ensightMeshesFa(regionNames.size()); if (doFiniteArea) { - autoPtr 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 faMeshPtr(faMesh::TryNew(mesh)); if (faMeshPtr) { @@ -91,7 +80,7 @@ PtrList ensightMeshesFa(regionNames.size()); ) ); - meshesFa.set(regioni, faMeshPtr); + meshesFa.set(regioni, std::move(faMeshPtr)); ensightMeshesFa.set ( diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H index f9f15fb482..ddcebf63e4 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H @@ -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) diff --git a/src/finiteArea/Make/files b/src/finiteArea/Make/files index 2badfb337d..7c2cdd4123 100644 --- a/src/finiteArea/Make/files +++ b/src/finiteArea/Make/files @@ -1,5 +1,6 @@ faMesh/faGlobalMeshData/faGlobalMeshData.C faMesh/faMesh.C +faMesh/faMeshNew.C faMesh/faMeshDemandDrivenData.C faMesh/faMeshPatches.C faMesh/faMeshTopology.C diff --git a/src/finiteArea/faMesh/faMesh.H b/src/finiteArea/faMesh/faMesh.H index 8a3ff124bb..731a2c8208 100644 --- a/src/finiteArea/faMesh/faMesh.H +++ b/src/finiteArea/faMesh/faMesh.H @@ -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 TryNew(const polyMesh& pMesh); + + // Member Functions // Helpers diff --git a/src/finiteArea/faMesh/faMeshNew.C b/src/finiteArea/faMesh/faMeshNew.C new file mode 100644 index 0000000000..1fcfe24458 --- /dev/null +++ b/src/finiteArea/faMesh/faMeshNew.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#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 + ({ + {"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 + ({ + {"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::TryNew(const polyMesh& pMesh) +{ + if (faMesh::hasFiles(pMesh)) + { + return autoPtr::New(pMesh); + } + + return nullptr; +} + + +// ************************************************************************* //