From ba10afea77783cde36cc8b5db7151de041271f9d Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Fri, 20 May 2022 11:02:49 +0200 Subject: [PATCH] ENH: add 'filtered' polyMesh regionName() method - in various situations with mesh regions it is also useful to filter out or remove the defaultRegion name (ie, "region0"). Can now do that conveniently from the polyMesh itself or as a static function. Simply use this const word& regionDir = polyMesh::regionName(regionName); OR mesh.regionName() instead of const word& regionDir = ( regionName != polyMesh::defaultRegion ? regionName : word::null ); Additionally, since the string '/' join operator filters out empty strings, the following will work correctly: (polyMesh::regionName(regionName)/polyMesh::meshSubDir) (mesh.regionName()/polyMesh::meshSubDir) --- .../createUpdatedDynamicFvMesh.H | 60 ++++++++++++----- .../createUpdatedDynamicFvMesh.H | 60 ++++++++++++----- .../Test-checkDecomposePar.C | 7 +- .../makeFaMesh/findMeshDefinitionDict.H | 12 ++-- .../mesh/conversion/gmshToFoam/gmshToFoam.C | 2 +- .../generation/PDRblockMesh/PDRblockMesh.C | 3 +- .../PDRblockMesh/cleanMeshDirectory.H | 5 +- .../mesh/generation/blockMesh/blockMesh.C | 5 +- .../generation/blockMesh/cleanMeshDirectory.H | 5 +- .../generation/blockMesh/findBlockMeshDict.H | 13 ++-- .../extrude/extrudeMesh/extrudeMesh.C | 15 +++-- .../extrude2DMesh/extrude2DMeshApp.C | 6 +- .../conformalVoronoiMeshIO.C | 2 +- .../manipulation/checkMesh/checkGeometry.C | 6 +- .../mesh/manipulation/checkMesh/checkTools.C | 11 +--- .../mesh/manipulation/rotateMesh/rotateMesh.C | 7 +- .../transformPoints/transformPoints.C | 5 +- .../foamFormatConvert/foamFormatConvert.C | 23 ++++--- .../decomposePar/decomposePar.C | 7 +- .../reconstructPar/reconstructPar.C | 9 +-- .../reconstructParMesh/reconstructParMesh.C | 35 ++-------- .../redistributePar/redistributePar.C | 11 +--- .../foamToEnsight/createMeshAccounting.H | 7 +- .../foamToEnsight/findCloudFields.H | 9 +-- .../foamToEnsight/foamToEnsight.C | 7 +- .../dataConversion/foamToVTK/foamToVTK.C | 23 +++---- .../changeDictionary/changeDictionary.C | 11 +--- .../createZeroDirectory/createZeroDirectory.C | 4 +- .../createZeroDirectory/solverTemplate.C | 9 +-- .../preProcessing/mapFields/mapFields.C | 20 +++--- .../preProcessing/mapFieldsPar/mapFieldsPar.C | 14 ++-- .../db/functionObjects/writeFile/writeFile.C | 13 ++-- src/OpenFOAM/include/createNamedMeshes.H | 6 +- src/OpenFOAM/meshes/polyMesh/polyMesh.C | 20 +++++- src/OpenFOAM/meshes/polyMesh/polyMesh.H | 15 ++++- .../pointHistory/pointHistory.C | 6 +- .../dynamicFvMesh/dynamicFvMeshNew.C | 40 ++++-------- .../include/createNamedDynamicFvMesh.H | 65 +++++++++++++------ .../simplifiedDynamicFvMesh.C | 2 +- src/finiteArea/faMesh/faMesh.C | 6 ++ src/finiteArea/faMesh/faMesh.H | 28 ++++---- .../faMesh/faMeshTools/faMeshTools.C | 6 +- .../fvMesh/fvMeshTools/fvMeshTools.C | 6 +- .../columnFvMesh/columnFvMesh.C | 16 ++--- .../columnFvMesh/columnFvMesh.H | 6 +- .../field/streamLine/streamLineBase.C | 9 +-- .../hydrostaticPressure/hydrostaticPressure.C | 4 +- .../utilities/vtkWrite/vtkWrite.C | 5 +- src/sampling/probes/probes.C | 10 +-- .../sampledSet/sampledSets/sampledSets.C | 22 ++----- 50 files changed, 344 insertions(+), 354 deletions(-) diff --git a/applications/solvers/compressible/rhoSimpleFoam/overRhoSimpleFoam/createUpdatedDynamicFvMesh.H b/applications/solvers/compressible/rhoSimpleFoam/overRhoSimpleFoam/createUpdatedDynamicFvMesh.H index ea5823cc1c3..66d37d170f0 100644 --- a/applications/solvers/compressible/rhoSimpleFoam/overRhoSimpleFoam/createUpdatedDynamicFvMesh.H +++ b/applications/solvers/compressible/rhoSimpleFoam/overRhoSimpleFoam/createUpdatedDynamicFvMesh.H @@ -1,22 +1,52 @@ - Info<< "Create dynamic mesh for time = " - << runTime.timeName() << nl << endl; +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2017 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. - autoPtr<dynamicFvMesh> meshPtr +Description + Create a dynamicFvMesh, with init() + +Required Variables + - runTime [Time] + +Provided Variables + - mesh [dynamicFvMesh], meshPtr + +\*---------------------------------------------------------------------------*/ + +Foam::autoPtr<Foam::dynamicFvMesh> meshPtr; + +{ + Foam::Info << "Create dynamic mesh for time = " + << runTime.timeName() << Foam::nl; + + meshPtr = dynamicFvMesh::New ( - dynamicFvMesh::New + IOobject ( - IOobject - ( - polyMesh::defaultRegion, - runTime.timeName(), - runTime, - IOobject::MUST_READ - ) + polyMesh::defaultRegion, + runTime.timeName(), + runTime, + IOobject::MUST_READ ) ); +} + + +dynamicFvMesh& mesh = meshPtr(); + +// Calculate initial mesh-to-mesh mapping. Note that this should be +// done under the hood, e.g. as a MeshObject +mesh.update(); + +Foam::Info << Foam::endl; - dynamicFvMesh& mesh = meshPtr(); - // Calculate initial mesh-to-mesh mapping. Note that this should be - // done under the hood, e.g. as a MeshObject - mesh.update(); +// ************************************************************************* // diff --git a/applications/solvers/incompressible/simpleFoam/overSimpleFoam/createUpdatedDynamicFvMesh.H b/applications/solvers/incompressible/simpleFoam/overSimpleFoam/createUpdatedDynamicFvMesh.H index ea5823cc1c3..66d37d170f0 100644 --- a/applications/solvers/incompressible/simpleFoam/overSimpleFoam/createUpdatedDynamicFvMesh.H +++ b/applications/solvers/incompressible/simpleFoam/overSimpleFoam/createUpdatedDynamicFvMesh.H @@ -1,22 +1,52 @@ - Info<< "Create dynamic mesh for time = " - << runTime.timeName() << nl << endl; +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2017 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. - autoPtr<dynamicFvMesh> meshPtr +Description + Create a dynamicFvMesh, with init() + +Required Variables + - runTime [Time] + +Provided Variables + - mesh [dynamicFvMesh], meshPtr + +\*---------------------------------------------------------------------------*/ + +Foam::autoPtr<Foam::dynamicFvMesh> meshPtr; + +{ + Foam::Info << "Create dynamic mesh for time = " + << runTime.timeName() << Foam::nl; + + meshPtr = dynamicFvMesh::New ( - dynamicFvMesh::New + IOobject ( - IOobject - ( - polyMesh::defaultRegion, - runTime.timeName(), - runTime, - IOobject::MUST_READ - ) + polyMesh::defaultRegion, + runTime.timeName(), + runTime, + IOobject::MUST_READ ) ); +} + + +dynamicFvMesh& mesh = meshPtr(); + +// Calculate initial mesh-to-mesh mapping. Note that this should be +// done under the hood, e.g. as a MeshObject +mesh.update(); + +Foam::Info << Foam::endl; - dynamicFvMesh& mesh = meshPtr(); - // Calculate initial mesh-to-mesh mapping. Note that this should be - // done under the hood, e.g. as a MeshObject - mesh.update(); +// ************************************************************************* // diff --git a/applications/test/checkDecomposePar/Test-checkDecomposePar.C b/applications/test/checkDecomposePar/Test-checkDecomposePar.C index 3987a7d21e9..5cc6bb23117 100644 --- a/applications/test/checkDecomposePar/Test-checkDecomposePar.C +++ b/applications/test/checkDecomposePar/Test-checkDecomposePar.C @@ -89,12 +89,7 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - // const word& regionDir = - // ( - // regionName != polyMesh::defaultRegion - // ? regionName - // : word::null - // ); + // const word& regionDir = polyMesh::regionName(regionName); Info<< "\n\nDecomposing mesh " << regionName << nl << endl; Info<< "Create mesh..." << flush; diff --git a/applications/utilities/finiteArea/makeFaMesh/findMeshDefinitionDict.H b/applications/utilities/finiteArea/makeFaMesh/findMeshDefinitionDict.H index 5385d38f370..a5697ea69e3 100644 --- a/applications/utilities/finiteArea/makeFaMesh/findMeshDefinitionDict.H +++ b/applications/utilities/finiteArea/makeFaMesh/findMeshDefinitionDict.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. @@ -21,9 +21,7 @@ autoPtr<IOdictionary> meshDictPtr; { fileName dictPath; - - const word& regionDir = - (regionName == polyMesh::defaultRegion ? word::null : regionName); + const word& regionDir = polyMesh::regionName(regionName); if (args.readIfPresent("dict", dictPath)) { @@ -40,15 +38,17 @@ autoPtr<IOdictionary> meshDictPtr; exists ( runTime.path()/runTime.caseConstant() - /regionDir/faMesh::meshSubDir/dictName + / regionDir/faMesh::meshSubDir/dictName ) ) { // Dictionary present in constant faMesh directory (old-style) dictPath = + ( runTime.constant() - /regionDir/faMesh::meshSubDir/dictName; + / regionDir/faMesh::meshSubDir/dictName + ); // Warn that constant/faMesh/faMeshDefinition was used // instead of system/faMeshDefinition diff --git a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C index 83685328e70..fec3b4bed8d 100644 --- a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C +++ b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C @@ -1317,7 +1317,7 @@ int main(int argc, char *argv[]) #include "setRootCase.H" #include "createTime.H" - word regionName = polyMesh::defaultRegion; + word regionName(polyMesh::defaultRegion); if (args.readIfPresent("region", regionName)) { diff --git a/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C b/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C index 32d304c6b4c..75fbbe7016a 100644 --- a/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C +++ b/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -130,7 +130,6 @@ int main(int argc, char *argv[]) const bool noOuterRegion = args.found("no-outer"); const word regionName(polyMesh::defaultRegion); - const word regionPath; // Instance for resulting mesh diff --git a/applications/utilities/mesh/generation/PDRblockMesh/cleanMeshDirectory.H b/applications/utilities/mesh/generation/PDRblockMesh/cleanMeshDirectory.H index 46f017fb196..9b0d60bebd6 100644 --- a/applications/utilities/mesh/generation/PDRblockMesh/cleanMeshDirectory.H +++ b/applications/utilities/mesh/generation/PDRblockMesh/cleanMeshDirectory.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -18,10 +18,11 @@ Description { // Shadows enclosing parameter (dictName) const word blockMeshDictName("blockMeshDict"); + const word& regionDir = polyMesh::regionName(regionName); const fileName polyMeshPath ( - runTime.path()/meshInstance/regionPath/polyMesh::meshSubDir + runTime.path()/meshInstance/regionDir/polyMesh::meshSubDir ); if (exists(polyMeshPath)) diff --git a/applications/utilities/mesh/generation/blockMesh/blockMesh.C b/applications/utilities/mesh/generation/blockMesh/blockMesh.C index dae940888c4..52942def33d 100644 --- a/applications/utilities/mesh/generation/blockMesh/blockMesh.C +++ b/applications/utilities/mesh/generation/blockMesh/blockMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -184,16 +184,13 @@ int main(int argc, char *argv[]) ); word regionName(polyMesh::defaultRegion); - word regionPath; // Check if the region is specified otherwise mesh the default region if (args.readIfPresent("region", regionName)) { Info<< nl << "Generating mesh for region " << regionName << endl; - regionPath = regionName; } - // Instance for resulting mesh bool useTime = false; word meshInstance(runTime.constant()); diff --git a/applications/utilities/mesh/generation/blockMesh/cleanMeshDirectory.H b/applications/utilities/mesh/generation/blockMesh/cleanMeshDirectory.H index 46f017fb196..9b0d60bebd6 100644 --- a/applications/utilities/mesh/generation/blockMesh/cleanMeshDirectory.H +++ b/applications/utilities/mesh/generation/blockMesh/cleanMeshDirectory.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -18,10 +18,11 @@ Description { // Shadows enclosing parameter (dictName) const word blockMeshDictName("blockMeshDict"); + const word& regionDir = polyMesh::regionName(regionName); const fileName polyMeshPath ( - runTime.path()/meshInstance/regionPath/polyMesh::meshSubDir + runTime.path()/meshInstance/regionDir/polyMesh::meshSubDir ); if (exists(polyMeshPath)) diff --git a/applications/utilities/mesh/generation/blockMesh/findBlockMeshDict.H b/applications/utilities/mesh/generation/blockMesh/findBlockMeshDict.H index 4f81c74ccc9..43f4ffecb6e 100644 --- a/applications/utilities/mesh/generation/blockMesh/findBlockMeshDict.H +++ b/applications/utilities/mesh/generation/blockMesh/findBlockMeshDict.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. @@ -22,6 +22,7 @@ autoPtr<IOdictionary> meshDictPtr; { fileName dictPath; + const word& regionDir = polyMesh::regionName(regionName); if (args.readIfPresent("dict", dictPath)) { @@ -37,15 +38,17 @@ autoPtr<IOdictionary> meshDictPtr; exists ( runTime.path()/runTime.constant() - /regionPath/polyMesh::meshSubDir/dictName + / regionDir/polyMesh::meshSubDir/dictName ) ) { // Dictionary present in constant polyMesh directory (old-style) dictPath = + ( runTime.constant() - /regionPath/polyMesh::meshSubDir/dictName; + / regionDir/polyMesh::meshSubDir/dictName + ); // Warn that constant/polyMesh/blockMeshDict was used @@ -54,14 +57,14 @@ autoPtr<IOdictionary> meshDictPtr; << "Using the old blockMeshDict location: " << dictPath << nl << " instead of the default location: " - << runTime.system()/regionPath/dictName << nl + << runTime.system()/regionDir/dictName << nl << endl; } else { // Assume dictionary is to be found in the system directory - dictPath = runTime.system()/regionPath/dictName; + dictPath = runTime.system()/regionDir/dictName; } IOobject meshDictIO diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C b/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C index bc5fba6e600..f93e6f03afa 100644 --- a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C +++ b/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2021 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -256,21 +256,19 @@ int main(int argc, char *argv[]) #include "createTimeExtruded.H" // Get optional regionName - word regionName; - word regionDir; + word regionName(polyMesh::defaultRegion); if (args.readIfPresent("region", regionName)) { - regionDir = regionName; Info<< "Create mesh " << regionName << " for time = " << runTimeExtruded.timeName() << nl << endl; } else { - regionName = fvMesh::defaultRegion; Info<< "Create mesh for time = " << runTimeExtruded.timeName() << nl << endl; } + const IOdictionary dict ( IOobject::selectIO @@ -755,7 +753,12 @@ int main(int argc, char *argv[]) // Create dummy fvSchemes, fvSolution - fvMeshTools::createDummyFvMeshFiles(mesh, regionDir, true); + fvMeshTools::createDummyFvMeshFiles + ( + mesh, + polyMesh::regionName(regionName), + true + ); // Create actual mesh from polyTopoChange container autoPtr<mapPolyMesh> map = meshMod().makeMesh diff --git a/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMeshApp.C b/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMeshApp.C index 92d91f25a91..7b235d8c485 100644 --- a/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMeshApp.C +++ b/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMeshApp.C @@ -234,12 +234,12 @@ int main(int argc, char *argv[]) { mesh = autoPtr<polyMesh>::New ( - Foam::IOobject + IOobject ( - Foam::polyMesh::defaultRegion, + polyMesh::defaultRegion, runTimeExtruded.timeName(), runTimeExtruded, - Foam::IOobject::MUST_READ + IOobject::MUST_READ ) ); } diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C index 37c3a3c528e..bad6f988a03 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C @@ -331,7 +331,7 @@ void Foam::conformalVoronoiMesh::writeMesh(const fileName& instance) // ( // IOobject // ( -// Foam::polyMesh::defaultRegion, +// polyMesh::defaultRegion, // instance, // runTime_, // IOobject::MUST_READ diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C index ce2c8f83ce1..482acaaff37 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C @@ -1015,10 +1015,8 @@ Foam::label Foam::checkGeometry const fileName outputDir ( - mesh.time().globalPath() - /functionObject::outputPrefix - /(mesh.name() == polyMesh::defaultRegion ? word::null : mesh.name()) - /"checkMesh" + mesh.time().globalPath()/functionObject::outputPrefix + / mesh.regionName()/"checkMesh" ); forAll(pbm, patchi) diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C index 7e461b37a92..1b292125189 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C @@ -52,15 +52,8 @@ License void Foam::printMeshStats(const polyMesh& mesh, const bool allTopology) { - if (mesh.name() == Foam::polyMesh::defaultRegion) - { - Info<< "Mesh stats" << nl; - } - else - { - Info<< "Mesh " << mesh.name() << " stats" << nl; - } - Info<< " points: " + Info<< "Mesh stats " << mesh.regionName() << nl + << " points: " << returnReduce(mesh.points().size(), sumOp<label>()) << nl; diff --git a/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C b/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C index 9950dc0e69b..d2e53138ea1 100644 --- a/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C +++ b/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -130,11 +130,10 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = + const fileName meshDir ( - regionName == polyMesh::defaultRegion ? word::null : regionName + polyMesh::regionName(regionName)/polyMesh::meshSubDir ); - const fileName meshDir = regionDir/polyMesh::meshSubDir; if (regionNames.size() > 1) { diff --git a/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C b/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C index 2fdcf6edd0e..dd82546f4e9 100644 --- a/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C +++ b/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C @@ -369,11 +369,10 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = + const fileName meshDir ( - regionName == polyMesh::defaultRegion ? word::null : regionName + polyMesh::regionName(regionName)/polyMesh::meshSubDir ); - const fileName meshDir = regionDir/polyMesh::meshSubDir; if (regionNames.size() > 1) { diff --git a/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C b/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C index 518e2510c64..44ef3d3f7c6 100644 --- a/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C +++ b/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C @@ -297,16 +297,18 @@ int main(int argc, char *argv[]) IOobject::fileModificationChecking = IOobject::timeStamp; - fileName meshDir = polyMesh::meshSubDir; - fileName regionPrefix = ""; - word regionName = polyMesh::defaultRegion; + word regionName(polyMesh::defaultRegion); if (args.readIfPresent("region", regionName)) { Info<< "Using region " << regionName << nl << endl; - regionPrefix = regionName; - meshDir = regionName/polyMesh::meshSubDir; } + const fileName meshDir + ( + polyMesh::regionName(regionName)/polyMesh::meshSubDir + ); + + Foam::instantList timeDirs = Foam::timeSelector::select0(runTime, args); forAll(timeDirs, timeI) @@ -349,7 +351,7 @@ int main(int argc, char *argv[]) writeMeshObject<pointIOField> ( "internalDelaunayVertices", - regionPrefix, + polyMesh::regionName(regionName), runTime ); @@ -365,7 +367,12 @@ int main(int argc, char *argv[]) } // Get list of objects from the database - IOobjectList objects(runTime, runTime.timeName(), regionPrefix); + IOobjectList objects + ( + runTime, + runTime.timeName(), + polyMesh::regionName(regionName) + ); forAllConstIters(objects, iter) { @@ -417,7 +424,7 @@ int main(int argc, char *argv[]) fileHandler().filePath ( runTime.timePath() - / regionPrefix + / polyMesh::regionName(regionName) / cloud::prefix ) ); diff --git a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C index 7157fa89dd4..a2510f30867 100644 --- a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C +++ b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C @@ -274,7 +274,7 @@ void decomposeUniform // Link with relative paths string parentPath = string("..")/".."; - if (regionDir != word::null) + if (!regionDir.empty()) { parentPath = parentPath/".."; } @@ -479,10 +479,7 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = - ( - regionName == polyMesh::defaultRegion ? word::null : regionName - ); + const word& regionDir = polyMesh::regionName(regionName); if (args.dryRun()) { diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C index 5ea758d2548..4e3968cd331 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C @@ -294,12 +294,7 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = - ( - regionName != polyMesh::defaultRegion - ? regionName - : word::null - ); + const word& regionDir = polyMesh::regionName(regionName); Info<< "\n\nReconstructing fields" << nl << "region=" << regionName << nl << endl; @@ -925,7 +920,7 @@ int main(int argc, char *argv[]) // For the first region of a multi-region case additionally // copy the "uniform" directory in the time directory - if (regioni == 0 && regionDir != word::null) + if (regioni == 0 && !regionDir.empty()) { fileName uniformDir0 ( diff --git a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C index 7679e08ed3d..4b57c890dca 100644 --- a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C +++ b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -450,18 +450,11 @@ void writeMesh const labelListList& cellProcAddressing ) { - const word& regionDir = - ( - mesh.name() == polyMesh::defaultRegion - ? word::null - : mesh.name() - ); - const fileName outputDir ( mesh.time().path() / mesh.time().timeName() - / regionDir + / mesh.regionName() / polyMesh::meshSubDir ); @@ -489,18 +482,11 @@ void writeMaps const labelUList& boundProcAddressing ) { - const word& regionDir = - ( - procMesh.name() == polyMesh::defaultRegion - ? word::null - : procMesh.name() - ); - const fileName outputDir ( procMesh.time().caseName() / procMesh.facesInstance() - / regionDir + / procMesh.regionName() / polyMesh::meshSubDir ); @@ -775,18 +761,12 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = - ( - regionName == polyMesh::defaultRegion - ? word::null - : regionName - ); IOobject facesIO ( "faces", databases[0].timeName(), - regionDir/polyMesh::meshSubDir, + polyMesh::regionName(regionName)/polyMesh::meshSubDir, databases[0], IOobject::NO_READ, IOobject::NO_WRITE @@ -817,12 +797,7 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = - ( - regionName == polyMesh::defaultRegion - ? word::null - : regionName - ); + const word& regionDir = polyMesh::regionName(regionName); if (!hasRegionMesh[regioni]) { diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C index 36643487d66..9010cd6db23 100644 --- a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C +++ b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C @@ -1313,10 +1313,7 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = - ( - regionName == polyMesh::defaultRegion ? word::null : regionName - ); + const word& regionDir = polyMesh::regionName(regionName); const fileName volMeshSubDir(regionDir/polyMesh::meshSubDir); const fileName areaMeshSubDir(regionDir/faMesh::meshSubDir); @@ -2087,10 +2084,8 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = - ( - regionName == polyMesh::defaultRegion ? word::null : regionName - ); + const word& regionDir = polyMesh::regionName(regionName); + const fileName volMeshSubDir(regionDir/polyMesh::meshSubDir); const fileName areaMeshSubDir(regionDir/faMesh::meshSubDir); diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.H index 7d33588a569..43c274ebfca 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.H @@ -28,12 +28,7 @@ PtrList<ensightFaMesh> ensightMeshesFa(regionNames.size()); const fvMesh& mesh = meshes[regioni]; const word& regionName = regionNames[regioni]; - const word& regionDir = - ( - regionName != polyMesh::defaultRegion - ? regionName - : word::null - ); + const word& regionDir = polyMesh::regionName(regionName); fileName ensCasePath(outputDir); word ensCaseName(args.globalCaseName()); diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/findCloudFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/findCloudFields.H index debff3288a0..30adf8ed22f 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/findCloudFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/findCloudFields.H @@ -29,15 +29,12 @@ if (timeDirs.size() && doLagrangian) auto& cloudFields = regionCloudFields[regioni]; const word& regionName = regionNames[regioni]; - const word& regionDir = + + const fileName cloudPrefix ( - regionName != polyMesh::defaultRegion - ? regionName - : word::null + polyMesh::regionName(regionName)/cloud::prefix ); - const fileName cloudPrefix(regionDir/cloud::prefix); - for (const instant& inst : timeDirs) { const word& timeName = inst.name(); diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C index 12b4891c3df..fab7b60eb85 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C @@ -512,12 +512,7 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = - ( - regionName != polyMesh::defaultRegion - ? regionName - : word::null - ); + const word& regionDir = polyMesh::regionName(regionName); if (regionNames.size() > 1) { diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C index 9f02a529bcc..a14329a0be8 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C @@ -697,21 +697,16 @@ int main(int argc, char *argv[]) for (const word& regionName : regionNames) { - const word& regionDir = - ( - regionName == polyMesh::defaultRegion ? word::null : regionName - ); - - fileName regionalDir(outputDir/regionDir); + fileName regionOutDir(outputDir/polyMesh::regionName(regionName)); - if (args.found("overwrite") && Foam::isDir(regionalDir)) + if (args.found("overwrite") && Foam::isDir(regionOutDir)) { Info<< "Removing old directory " - << args.relativePath(regionalDir) + << args.relativePath(regionOutDir) << nl << endl; - Foam::rmDir(regionalDir); + Foam::rmDir(regionOutDir); } - Foam::mkDir(regionalDir); + Foam::mkDir(regionOutDir); } } @@ -749,11 +744,9 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = - ( - regionName == polyMesh::defaultRegion ? word::null : regionName - ); - if (regionNames.size() > 1 || !regionDir.empty()) + const word& regionDir = polyMesh::regionName(regionName); + + if (regionNames.size() > 1) { Info<< "region = " << regionName << nl; } diff --git a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C index 458dc61e8ad..b28e45f8313 100644 --- a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C +++ b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -498,13 +498,6 @@ int main(int argc, char *argv[]) } - fileName regionPrefix; - if (regionName != polyMesh::defaultRegion) - { - regionPrefix = regionName; - } - - // Make sure we do not use the master-only reading since we read // fields (different per processor) as dictionaries. IOobject::fileModificationChecking = IOobject::timeStamp; @@ -547,7 +540,7 @@ int main(int argc, char *argv[]) "boundary", runTime.findInstance ( - regionPrefix/polyMesh::meshSubDir, + polyMesh::regionName(regionName)/polyMesh::meshSubDir, "boundary", IOobject::READ_IF_PRESENT ), diff --git a/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C b/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C index 5c09e1bbd67..3cdc15bff73 100644 --- a/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C +++ b/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C @@ -145,7 +145,7 @@ void createFieldFiles fileName regionPath = "/"; - if (regionName != word::null) + if (!regionName.empty()) { regionPath += regionName + '/'; } @@ -294,7 +294,7 @@ int main(int argc, char *argv[]) { const word& regionName = solver.regionName(regionI); - if (regionName == word::null) + if (regionName.empty()) { Info<< "Region: " << polyMesh::defaultRegion << " (default)" << endl; diff --git a/applications/utilities/preProcessing/createZeroDirectory/solverTemplate.C b/applications/utilities/preProcessing/createZeroDirectory/solverTemplate.C index aa1a5cf9bc6..deeaec63824 100644 --- a/applications/utilities/preProcessing/createZeroDirectory/solverTemplate.C +++ b/applications/utilities/preProcessing/createZeroDirectory/solverTemplate.C @@ -78,14 +78,11 @@ Foam::dictionary Foam::solverTemplate::readFluidFieldTemplates { Info<< " Reading fluid field templates"; - if (regionName == word::null) + if (!regionName.empty()) { - Info<< endl; - } - else - { - Info<< " for region " << regionName << endl; + Info<< " for region " << regionName; } + Info<< endl; dictionary fieldTemplates = solverDict.subDict("fluidFields"); diff --git a/applications/utilities/preProcessing/mapFields/mapFields.C b/applications/utilities/preProcessing/mapFields/mapFields.C index 047e6132092..8b5b24dd294 100644 --- a/applications/utilities/preProcessing/mapFields/mapFields.C +++ b/applications/utilities/preProcessing/mapFields/mapFields.C @@ -290,21 +290,21 @@ int main(int argc, char *argv[]) const fileName rootDirSource = casePath.path().toAbsolute(); const fileName caseDirSource = casePath.name(); - Info<< "Source: " << rootDirSource << " " << caseDirSource << endl; - word sourceRegion = polyMesh::defaultRegion; - if (args.found("sourceRegion")) + Info<< "Source: " << rootDirSource << ' ' << caseDirSource; + word sourceRegion(polyMesh::defaultRegion); + if (args.readIfPresent("sourceRegion", sourceRegion)) { - sourceRegion = args["sourceRegion"]; - Info<< "Source region: " << sourceRegion << endl; + Info<< " (region " << sourceRegion << ')'; } + Info<< endl; - Info<< "Target: " << rootDirTarget << " " << caseDirTarget << endl; - word targetRegion = polyMesh::defaultRegion; - if (args.found("targetRegion")) + Info<< "Target: " << rootDirTarget << ' ' << caseDirTarget; + word targetRegion(polyMesh::defaultRegion); + if (args.readIfPresent("targetRegion", targetRegion)) { - targetRegion = args["targetRegion"]; - Info<< "Target region: " << targetRegion << endl; + Info<< " (region " << targetRegion << ')'; } + Info<< endl; const bool parallelSource = args.found("parallelSource"); const bool parallelTarget = args.found("parallelTarget"); diff --git a/applications/utilities/preProcessing/mapFieldsPar/mapFieldsPar.C b/applications/utilities/preProcessing/mapFieldsPar/mapFieldsPar.C index 8b494325f25..cb610d4549a 100644 --- a/applications/utilities/preProcessing/mapFieldsPar/mapFieldsPar.C +++ b/applications/utilities/preProcessing/mapFieldsPar/mapFieldsPar.C @@ -220,19 +220,21 @@ int main(int argc, char *argv[]) const fileName rootDirSource = casePath.path(); const fileName caseDirSource = casePath.name(); - Info<< "Source: " << rootDirSource << " " << caseDirSource << endl; - word sourceRegion = polyMesh::defaultRegion; + Info<< "Source: " << rootDirSource << ' ' << caseDirSource; + word sourceRegion(polyMesh::defaultRegion); if (args.readIfPresent("sourceRegion", sourceRegion)) { - Info<< "Source region: " << sourceRegion << endl; + Info<< " (region " << sourceRegion << ')'; } + Info<< endl; - Info<< "Target: " << rootDirTarget << " " << caseDirTarget << endl; - word targetRegion = polyMesh::defaultRegion; + Info<< "Target: " << rootDirTarget << ' ' << caseDirTarget; + word targetRegion(polyMesh::defaultRegion); if (args.readIfPresent("targetRegion", targetRegion)) { - Info<< "Target region: " << targetRegion << endl; + Info<< " (region " << targetRegion << ')'; } + Info<< endl; const bool consistent = args.found("consistent"); diff --git a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C index 51be217fda8..8c2d9f2cc46 100644 --- a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C +++ b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2018 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -58,14 +58,11 @@ Foam::fileName Foam::functionObjects::writeFile::baseFileDir() const / functionObject::outputPrefix ); - // Append mesh name if not default region - if (isA<polyMesh>(fileObr_)) + // Append mesh region name if not default region + const auto* meshPtr = isA<polyMesh>(fileObr_); + if (meshPtr) { - const polyMesh& mesh = refCast<const polyMesh>(fileObr_); - if (mesh.name() != polyMesh::defaultRegion) - { - baseDir /= mesh.name(); - } + baseDir /= meshPtr->regionName(); } baseDir.clean(); // Remove unneeded ".." diff --git a/src/OpenFOAM/include/createNamedMeshes.H b/src/OpenFOAM/include/createNamedMeshes.H index a1d1512939d..64af72a3de9 100644 --- a/src/OpenFOAM/include/createNamedMeshes.H +++ b/src/OpenFOAM/include/createNamedMeshes.H @@ -34,11 +34,7 @@ Foam::PtrList<Foam::fvMesh> meshes(regionNames.size()); const Foam::word& regionName = regionNames[regioni]; Foam::Info<< "Create mesh"; - if - ( - regionNames.size() > 1 - || regionName != Foam::polyMesh::defaultRegion - ) + if (regionNames.size() > 1) { Foam::Info<< ' ' << regionName; } diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index 466c82fde1a..f7fb0e115ce 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -44,11 +44,11 @@ License namespace Foam { defineTypeNameAndDebug(polyMesh, 0); - - word polyMesh::defaultRegion = "region0"; - word polyMesh::meshSubDir = "polyMesh"; } +Foam::word Foam::polyMesh::defaultRegion = "region0"; +Foam::word Foam::polyMesh::meshSubDir = "polyMesh"; + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -824,6 +824,14 @@ Foam::polyMesh::~polyMesh() } +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +const Foam::word& Foam::polyMesh::regionName(const word& region) +{ + return (region == polyMesh::defaultRegion ? word::null : region); +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // const Foam::fileName& Foam::polyMesh::dbDir() const @@ -843,6 +851,12 @@ Foam::fileName Foam::polyMesh::meshDir() const } +const Foam::word& Foam::polyMesh::regionName() const +{ + return polyMesh::regionName(objectRegistry::name()); +} + + const Foam::fileName& Foam::polyMesh::pointsInstance() const { return points_.instance(); diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.H b/src/OpenFOAM/meshes/polyMesh/polyMesh.H index b5512d75fb4..f0cdcf83c9c 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017, 2020 OpenFOAM Foundation - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,8 +41,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef polyMesh_H -#define polyMesh_H +#ifndef Foam_polyMesh_H +#define Foam_polyMesh_H #include "objectRegistry.H" #include "primitiveMesh.H" @@ -418,6 +418,15 @@ public: ); + // Regions + + //- The mesh region name or word::null if polyMesh::defaultRegion + static const word& regionName(const word& region); + + //- The mesh region name or word::null if polyMesh::defaultRegion + const word& regionName() const; + + // Access //- Return raw points diff --git a/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/pointHistory/pointHistory.C b/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/pointHistory/pointHistory.C index d1060b286f3..4cb7288cc62 100644 --- a/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/pointHistory/pointHistory.C +++ b/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/pointHistory/pointHistory.C @@ -48,8 +48,7 @@ namespace Foam bool Foam::pointHistory::writeData() { - const fvMesh& mesh = - time_.lookupObject<fvMesh>(polyMesh::defaultRegion); + const fvMesh& mesh = time_.lookupObject<fvMesh>(polyMesh::defaultRegion); vector position(Zero); @@ -98,8 +97,7 @@ Foam::pointHistory::pointHistory dict.readIfPresent("region", regionName_); dict.readIfPresent("historyPointID", historyPointID_); - const fvMesh& mesh = - time_.lookupObject<fvMesh>(regionName_); + const fvMesh& mesh = time_.lookupObject<fvMesh>(regionName_); const vectorField& points = mesh.points(); diff --git a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C index ea6a5d9a020..35643811290 100644 --- a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C +++ b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -43,7 +43,7 @@ Foam::autoPtr<Foam::dynamicFvMesh> Foam::dynamicFvMesh::New(const IOobject& io) ( "dynamicMeshDict", io.time().constant(), - (io.name() == polyMesh::defaultRegion ? "" : io.name()), + polyMesh::regionName(io.name()), io.db(), IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE, @@ -124,6 +124,14 @@ Foam::autoPtr<Foam::dynamicFvMesh> Foam::dynamicFvMesh::New const Time& runTime ) { + const IOobject meshIO + ( + polyMesh::defaultRegion, + runTime.timeName(), + runTime, + IOobject::MUST_READ + ); + if (args.dryRun() || args.found("dry-run-write")) { Info @@ -148,32 +156,10 @@ Foam::autoPtr<Foam::dynamicFvMesh> Foam::dynamicFvMesh::New functionObject::outputPrefix = "postProcessing-dry-run"; - return - simplifiedMeshes::simplifiedDynamicFvMeshBase::New - ( - IOobject - ( - polyMesh::defaultRegion, - runTime.timeName(), - runTime, - IOobject::MUST_READ - ) - ); - } - else - { - return - New - ( - IOobject - ( - polyMesh::defaultRegion, - runTime.timeName(), - runTime, - IOobject::MUST_READ - ) - ); + return simplifiedMeshes::simplifiedDynamicFvMeshBase::New(meshIO); } + + return New(meshIO); } diff --git a/src/dynamicFvMesh/include/createNamedDynamicFvMesh.H b/src/dynamicFvMesh/include/createNamedDynamicFvMesh.H index 6cb1444055d..dd659f2481f 100644 --- a/src/dynamicFvMesh/include/createNamedDynamicFvMesh.H +++ b/src/dynamicFvMesh/include/createNamedDynamicFvMesh.H @@ -1,30 +1,55 @@ - Foam::word regionName = Foam::polyMesh::defaultRegion; +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2012 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. +Description + Create a dynamicFvMesh for a specified region, or the defaultRegion + +Required Variables + - runTime [Time] + +Provided Variables + - regionName [word] + - mesh [dynamicFvMesh], meshPtr + +\*---------------------------------------------------------------------------*/ + +Foam::word regionName(Foam::polyMesh::defaultRegion); +Foam::autoPtr<Foam::dynamicFvMesh> meshPtr; + +{ + Foam::Info << "Create dynamic mesh"; if (args.readIfPresent("region", regionName)) { - Foam::Info - << "Create mesh " << regionName << " for time = " - << runTime.timeName() << Foam::nl << Foam::endl; - } - else - { - Foam::Info - << "Create mesh for time = " - << runTime.timeName() << Foam::nl << Foam::endl; + Foam::Info << ' ' << regionName; } + Foam::Info << " for time = " << runTime.timeName() << Foam::nl; - autoPtr<dynamicFvMesh> meshPtr + meshPtr = dynamicFvMesh::New ( - dynamicFvMesh::New + IOobject ( - IOobject - ( - regionName, - runTime.timeName(), - runTime, - IOobject::MUST_READ - ) + regionName, + runTime.timeName(), + runTime, + IOobject::MUST_READ ) ); +} + + +dynamicFvMesh& mesh = meshPtr(); + +Foam::Info << Foam::endl; + - dynamicFvMesh& mesh = meshPtr(); +// ************************************************************************* // diff --git a/src/dynamicFvMesh/simplifiedDynamicFvMesh/simplifiedDynamicFvMesh.C b/src/dynamicFvMesh/simplifiedDynamicFvMesh/simplifiedDynamicFvMesh.C index 92403dedf1b..c7db30f8af2 100644 --- a/src/dynamicFvMesh/simplifiedDynamicFvMesh/simplifiedDynamicFvMesh.C +++ b/src/dynamicFvMesh/simplifiedDynamicFvMesh/simplifiedDynamicFvMesh.C @@ -51,7 +51,7 @@ Foam::simplifiedMeshes::simplifiedDynamicFvMeshBase::New ( "dynamicMeshDict", io.time().constant(), - (io.name() == polyMesh::defaultRegion ? "" : io.name()), + polyMesh::regionName(io.name()), io.db(), IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE, diff --git a/src/finiteArea/faMesh/faMesh.C b/src/finiteArea/faMesh/faMesh.C index 32de35d34a6..eeda85f1d5f 100644 --- a/src/finiteArea/faMesh/faMesh.C +++ b/src/finiteArea/faMesh/faMesh.C @@ -601,6 +601,12 @@ const Foam::objectRegistry& Foam::faMesh::thisDb() const } +const Foam::word& Foam::faMesh::regionName() const +{ + return polyMesh::regionName(thisDb().name()); +} + + void Foam::faMesh::removeFiles(const fileName& instanceDir) const { fileName meshFilesPath = thisDb().time().path()/instanceDir/meshDir(); diff --git a/src/finiteArea/faMesh/faMesh.H b/src/finiteArea/faMesh/faMesh.H index 4d59b4ac796..633ecd56fc2 100644 --- a/src/finiteArea/faMesh/faMesh.H +++ b/src/finiteArea/faMesh/faMesh.H @@ -665,20 +665,26 @@ public: inline bool hasInternalEdgeLabels() const noexcept; - // Access + // Database - //- Return true if thisDb() is a valid DB - virtual bool hasDb() const; + //- Return true if thisDb() is a valid DB + virtual bool hasDb() const; - //- Return reference to the mesh database - virtual const objectRegistry& thisDb() const; + //- Return reference to the mesh database + virtual const objectRegistry& thisDb() const; - //- Name function is needed to disambiguate those inherited - //- from base classes - const word& name() const - { - return thisDb().name(); - } + //- Name function is needed to disambiguate those inherited + //- from base classes + const word& name() const + { + return thisDb().name(); + } + + //- The mesh region name or word::null if polyMesh::defaultRegion + const word& regionName() const; + + + // Access //- Return constant reference to boundary mesh inline const faBoundaryMesh& boundary() const noexcept; diff --git a/src/finiteArea/faMesh/faMeshTools/faMeshTools.C b/src/finiteArea/faMesh/faMeshTools/faMeshTools.C index 24b46edf5e1..b7bbf8b90d3 100644 --- a/src/finiteArea/faMesh/faMeshTools/faMeshTools.C +++ b/src/finiteArea/faMesh/faMeshTools/faMeshTools.C @@ -77,8 +77,7 @@ Foam::autoPtr<Foam::faMesh> Foam::faMeshTools::newMesh const fileName meshSubDir ( - (pMesh.name() == polyMesh::defaultRegion ? word::null : pMesh.name()) - / faMesh::meshSubDir + pMesh.regionName() / faMesh::meshSubDir ); @@ -260,8 +259,7 @@ Foam::autoPtr<Foam::faMesh> Foam::faMeshTools::loadOrCreateMesh const fileName meshSubDir ( - (pMesh.name() == polyMesh::defaultRegion ? word::null : pMesh.name()) - / faMesh::meshSubDir + pMesh.regionName() / faMesh::meshSubDir ); diff --git a/src/finiteVolume/fvMesh/fvMeshTools/fvMeshTools.C b/src/finiteVolume/fvMesh/fvMeshTools/fvMeshTools.C index 719aea05fd3..565c8a9223e 100644 --- a/src/finiteVolume/fvMesh/fvMeshTools/fvMeshTools.C +++ b/src/finiteVolume/fvMesh/fvMeshTools/fvMeshTools.C @@ -459,8 +459,7 @@ Foam::fvMeshTools::newMesh const fileName meshSubDir ( - (io.name() == polyMesh::defaultRegion ? word::null : io.name()) - / polyMesh::meshSubDir + polyMesh::regionName(io.name()) / polyMesh::meshSubDir ); @@ -744,8 +743,7 @@ Foam::fvMeshTools::loadOrCreateMesh const fileName meshSubDir ( - (io.name() == polyMesh::defaultRegion ? word::null : io.name()) - / polyMesh::meshSubDir + polyMesh::regionName(io.name()) / polyMesh::meshSubDir ); diff --git a/src/finiteVolume/fvMesh/simplifiedFvMesh/columnFvMesh/columnFvMesh.C b/src/finiteVolume/fvMesh/simplifiedFvMesh/columnFvMesh/columnFvMesh.C index c373ab314b3..7a242f9525f 100644 --- a/src/finiteVolume/fvMesh/simplifiedFvMesh/columnFvMesh/columnFvMesh.C +++ b/src/finiteVolume/fvMesh/simplifiedFvMesh/columnFvMesh/columnFvMesh.C @@ -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. @@ -64,7 +64,7 @@ bool Foam::simplifiedMeshes::columnFvMeshInfo::setPatchEntries ( "boundary", localInstance_, - regionPrefix_ + polyMesh::meshSubDir, + polyMesh::regionName(regionName_)/polyMesh::meshSubDir, runTime, IOobject::MUST_READ, IOobject::NO_WRITE, @@ -103,7 +103,7 @@ bool Foam::simplifiedMeshes::columnFvMeshInfo::setPatchEntries ( runTime, runTime.timeName(), - (regionName_ == polyMesh::defaultRegion ? "" : regionName_) + polyMesh::regionName(regionName_) ); if (objects.empty()) @@ -209,7 +209,7 @@ void Foam::simplifiedMeshes::columnFvMeshInfo::initialise(const Time& runTime) ( "points", localInstance_, - regionPrefix_ + polyMesh::meshSubDir, + polyMesh::regionName(regionName_)/polyMesh::meshSubDir, runTime, IOobject::MUST_READ, IOobject::NO_WRITE, @@ -409,17 +409,11 @@ Foam::simplifiedMeshes::columnFvMeshInfo::columnFvMeshInfo ) : regionName_(regionName), - regionPrefix_ - ( - regionName_ == polyMesh::defaultRegion - ? "" - : regionName_ + '/' - ), localInstance_ ( runTime.findInstance ( - regionPrefix_ + polyMesh::meshSubDir, + polyMesh::regionName(regionName_)/polyMesh::meshSubDir, "boundary", IOobject::READ_IF_PRESENT ) diff --git a/src/finiteVolume/fvMesh/simplifiedFvMesh/columnFvMesh/columnFvMesh.H b/src/finiteVolume/fvMesh/simplifiedFvMesh/columnFvMesh/columnFvMesh.H index 4e345ac3acf..6096bca444d 100644 --- a/src/finiteVolume/fvMesh/simplifiedFvMesh/columnFvMesh/columnFvMesh.H +++ b/src/finiteVolume/fvMesh/simplifiedFvMesh/columnFvMesh/columnFvMesh.H @@ -73,14 +73,11 @@ class columnFvMeshInfo protected: - // Protected data + // Protected Data //- Region of existing mesh const word regionName_; - //- Additional prefix for region. Empty if default region - const fileName regionPrefix_; - //- Location of existing mesh (if present) const word localInstance_; @@ -111,6 +108,7 @@ protected: //- Number of patches with at least 1 local face label nPatchWithFace_; + // Protected Member Functions //- Add the patches to the mesh diff --git a/src/functionObjects/field/streamLine/streamLineBase.C b/src/functionObjects/field/streamLine/streamLineBase.C index 67cf07f6faf..2540476981d 100644 --- a/src/functionObjects/field/streamLine/streamLineBase.C +++ b/src/functionObjects/field/streamLine/streamLineBase.C @@ -661,13 +661,10 @@ bool Foam::functionObjects::streamLineBase::writeToFile() fileName vtkPath ( - time_.globalPath()/functionObject::outputPrefix/"sets"/name() + time_.globalPath()/functionObject::outputPrefix/"sets" + / name()/mesh_.regionName() + / mesh_.time().timeName() ); - if (mesh_.name() != polyMesh::defaultRegion) - { - vtkPath = vtkPath/mesh_.name(); - } - vtkPath = vtkPath/mesh_.time().timeName(); mkDir(vtkPath); diff --git a/src/functionObjects/initialisation/hydrostaticPressure/hydrostaticPressure.C b/src/functionObjects/initialisation/hydrostaticPressure/hydrostaticPressure.C index 2edb8e74a2d..53b38700816 100644 --- a/src/functionObjects/initialisation/hydrostaticPressure/hydrostaticPressure.C +++ b/src/functionObjects/initialisation/hydrostaticPressure/hydrostaticPressure.C @@ -87,9 +87,9 @@ void Foam::functionObjects::hydrostaticPressure::calculateAndWrite() auto& p = thermo.p(); Info<< "Performing hydrostatic pressure initialisation"; - if (mesh_.name() != polyMesh::defaultRegion) + if (!mesh_.regionName().empty()) { - Info<< "for region " << mesh_.name(); + Info<< " region=" << mesh_.name(); } diff --git a/src/functionObjects/utilities/vtkWrite/vtkWrite.C b/src/functionObjects/utilities/vtkWrite/vtkWrite.C index 5f92c2a7cdc..84e49ab664f 100644 --- a/src/functionObjects/utilities/vtkWrite/vtkWrite.C +++ b/src/functionObjects/utilities/vtkWrite/vtkWrite.C @@ -280,10 +280,7 @@ bool Foam::functionObjects::vtkWrite::write() label regioni = 0; for (const word& regionName : meshes_.sortedToc()) { - const word& regionDir = - ( - regionName == polyMesh::defaultRegion ? word::null : regionName - ); + const word& regionDir = polyMesh::regionName(regionName); auto& meshProxy = meshSubsets_[regioni]; auto& vtuMeshCells = vtuMappings_[regioni]; diff --git a/src/sampling/probes/probes.C b/src/sampling/probes/probes.C index 849803e57a9..bf2e91f9e63 100644 --- a/src/sampling/probes/probes.C +++ b/src/sampling/probes/probes.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2021 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,17 +76,11 @@ void Foam::probes::createProbeFiles(const wordList& fieldNames) // Put in undecomposed case // (Note: gives problems for distributed data running) - fileName probeSubDir = name(); - if (mesh_.name() != polyMesh::defaultRegion) - { - probeSubDir = probeSubDir/mesh_.name(); - } - fileName probeDir ( mesh_.time().globalPath() / functionObject::outputPrefix - / probeSubDir + / name()/mesh_.regionName() // Use startTime as the instance for output files / mesh_.time().timeName(mesh_.time().startTime().value()) ); diff --git a/src/sampling/sampledSet/sampledSets/sampledSets.C b/src/sampling/sampledSet/sampledSets/sampledSets.C index 22a103472d4..63248a47aeb 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSets.C +++ b/src/sampling/sampledSet/sampledSets/sampledSets.C @@ -88,17 +88,11 @@ Foam::OFstream* Foam::sampledSets::createProbeFile(const word& fieldName) // Put in undecomposed case // (Note: gives problems for distributed data running) - fileName probeSubDir = name(); - if (mesh_.name() != polyMesh::defaultRegion) - { - probeSubDir = probeSubDir/mesh_.name(); - } - fileName probeDir ( mesh_.time().globalPath() / functionObject::outputPrefix - / probeSubDir + / name()/mesh_.regionName() // Use startTime as the instance for output files / mesh_.time().timeName(mesh_.time().startTime().value()) ); @@ -446,7 +440,8 @@ Foam::sampledSets::sampledSets writeAsProbes_(false), outputPath_ ( - time_.globalPath()/functionObject::outputPrefix/name + time_.globalPath()/functionObject::outputPrefix + / name/mesh_.regionName() ), searchEngine_(mesh_), samplePointScheme_(), @@ -459,10 +454,6 @@ Foam::sampledSets::sampledSets gatheredSorting_(), globalIndices_() { - if (mesh_.name() != polyMesh::defaultRegion) - { - outputPath_ /= mesh_.name(); - } outputPath_.clean(); // Remove unneeded ".." read(dict); @@ -487,7 +478,8 @@ Foam::sampledSets::sampledSets writeAsProbes_(false), outputPath_ ( - time_.globalPath()/functionObject::outputPrefix/name + time_.globalPath()/functionObject::outputPrefix + / name/mesh_.regionName() ), searchEngine_(mesh_), samplePointScheme_(), @@ -500,10 +492,6 @@ Foam::sampledSets::sampledSets gatheredSorting_(), globalIndices_() { - if (mesh_.name() != polyMesh::defaultRegion) - { - outputPath_ /= mesh_.name(); - } outputPath_.clean(); // Remove unneeded ".." read(dict); -- GitLab