From ba10afea77783cde36cc8b5db7151de041271f9d Mon Sep 17 00:00:00 2001 From: Mark Olesen 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 | 11 ++-- .../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 | 32 +++++---- .../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, 347 insertions(+), 357 deletions(-) diff --git a/applications/solvers/compressible/rhoSimpleFoam/overRhoSimpleFoam/createUpdatedDynamicFvMesh.H b/applications/solvers/compressible/rhoSimpleFoam/overRhoSimpleFoam/createUpdatedDynamicFvMesh.H index ea5823cc1c..66d37d170f 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 meshPtr +Description + Create a dynamicFvMesh, with init() + +Required Variables + - runTime [Time] + +Provided Variables + - mesh [dynamicFvMesh], meshPtr + +\*---------------------------------------------------------------------------*/ + +Foam::autoPtr 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(); +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; + + +// ************************************************************************* // diff --git a/applications/solvers/incompressible/simpleFoam/overSimpleFoam/createUpdatedDynamicFvMesh.H b/applications/solvers/incompressible/simpleFoam/overSimpleFoam/createUpdatedDynamicFvMesh.H index ea5823cc1c..66d37d170f 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 meshPtr +Description + Create a dynamicFvMesh, with init() + +Required Variables + - runTime [Time] + +Provided Variables + - mesh [dynamicFvMesh], meshPtr + +\*---------------------------------------------------------------------------*/ + +Foam::autoPtr 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(); +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; + + +// ************************************************************************* // diff --git a/applications/test/checkDecomposePar/Test-checkDecomposePar.C b/applications/test/checkDecomposePar/Test-checkDecomposePar.C index 3987a7d21e..5cc6bb2311 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 5385d38f37..a5697ea69e 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 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 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 83685328e7..fec3b4bed8 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 32d304c6b4..75fbbe7016 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 46f017fb19..9b0d60bebd 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 dae940888c..52942def33 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 46f017fb19..9b0d60bebd 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 4f81c74ccc..43f4ffecb6 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 meshDictPtr; { fileName dictPath; + const word& regionDir = polyMesh::regionName(regionName); if (args.readIfPresent("dict", dictPath)) { @@ -37,15 +38,17 @@ autoPtr 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 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 bc5fba6e60..f93e6f03af 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 map = meshMod().makeMesh diff --git a/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMeshApp.C b/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMeshApp.C index 92d91f25a9..7b235d8c48 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::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 37c3a3c528..bad6f988a0 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 ce2c8f83ce..482acaaff3 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 7e461b37a9..1b29212518 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