ENH: minor simplifications for handling region meshes

- static version of polyMesh::meshDir(), which takes a region name

      polyMesh::meshDir(regionName)
  vs
      polyMesh::regionName(regionName)/polyMesh::meshSubDir

STYLE: use polyMesh::regionName(..) instead of comparing to defaultRegion

STYLE: use getOrDefault when retrieving various -region options

FIX: polyMesh::dbDir() now checks registry name, not full path (#3033)
This commit is contained in:
Mark Olesen
2023-11-22 15:28:49 +01:00
parent f377875bc8
commit ca25929372
49 changed files with 453 additions and 147 deletions

View File

@ -13,6 +13,19 @@ License
Description Description
Search for the appropriate faMeshDefinition dictionary... Search for the appropriate faMeshDefinition dictionary...
Required Classes
- Foam::polyMesh
- Foam::IOdictionary
Required Variables
- regionName [word]
- args [argList]
- runTime [Time]
Provided Variables
- meshDefDict [IOdictionary]
- meshDictPtr [autoPtr<IOdictionary>]
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
const word dictName("faMeshDefinition"); const word dictName("faMeshDefinition");
@ -21,7 +34,7 @@ autoPtr<IOdictionary> meshDictPtr;
{ {
fileName dictPath; fileName dictPath;
const word& regionDir = polyMesh::regionName(regionName); const word& regionDir = Foam::polyMesh::regionName(regionName);
if (args.readIfPresent("dict", dictPath)) if (args.readIfPresent("dict", dictPath))
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -1317,11 +1317,12 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"
word regionName(polyMesh::defaultRegion); // Specified region or default region
#include "getRegionOption.H"
if (args.readIfPresent("region", regionName)) if (!polyMesh::regionName(regionName).empty())
{ {
Info<< "Creating polyMesh for region " << regionName << endl; Info<< "Creating polyMesh for region " << regionName << nl;
} }
const bool keepOrientation = args.found("keepOrientation"); const bool keepOrientation = args.found("keepOrientation");

View File

@ -18,11 +18,10 @@ Description
{ {
// Shadows enclosing parameter (dictName) // Shadows enclosing parameter (dictName)
const word blockMeshDictName("blockMeshDict"); const word blockMeshDictName("blockMeshDict");
const word& regionDir = polyMesh::regionName(regionName);
const fileName polyMeshPath const fileName polyMeshPath
( (
runTime.path()/meshInstance/regionDir/polyMesh::meshSubDir runTime.path()/meshInstance/polyMesh::meshDir(regionName)
); );
if (exists(polyMeshPath)) if (exists(polyMeshPath))

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -183,12 +183,12 @@ int main(int argc, char *argv[])
: blockMesh::DEFAULT_MERGE : blockMesh::DEFAULT_MERGE
); );
word regionName(polyMesh::defaultRegion); // Specified region or default region
#include "getRegionOption.H"
// Check if the region is specified otherwise mesh the default region if (!polyMesh::regionName(regionName).empty())
if (args.readIfPresent("region", regionName))
{ {
Info<< nl << "Generating mesh for region " << regionName << endl; Info<< nl << "Generating mesh for region " << regionName << nl;
} }
// Instance for resulting mesh // Instance for resulting mesh

View File

@ -18,11 +18,10 @@ Description
{ {
// Shadows enclosing parameter (dictName) // Shadows enclosing parameter (dictName)
const word blockMeshDictName("blockMeshDict"); const word blockMeshDictName("blockMeshDict");
const word& regionDir = polyMesh::regionName(regionName);
const fileName polyMeshPath const fileName polyMeshPath
( (
runTime.path()/meshInstance/regionDir/polyMesh::meshSubDir runTime.path()/meshInstance/polyMesh::meshDir(regionName)
); );
if (exists(polyMeshPath)) if (exists(polyMeshPath))

View File

@ -38,7 +38,7 @@ autoPtr<IOdictionary> meshDictPtr;
exists exists
( (
runTime.path()/runTime.constant() runTime.path()/runTime.constant()
/ regionDir/polyMesh::meshSubDir/dictName / polyMesh::meshDir(regionName)/dictName
) )
) )
{ {
@ -47,7 +47,7 @@ autoPtr<IOdictionary> meshDictPtr;
dictPath = dictPath =
( (
runTime.constant() runTime.constant()
/ regionDir/polyMesh::meshSubDir/dictName / polyMesh::meshDir(regionName)/dictName
); );

View File

@ -255,19 +255,17 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
#include "createTimeExtruded.H" #include "createTimeExtruded.H"
// Get optional regionName // Specified region or default region
word regionName(polyMesh::defaultRegion); #include "getRegionOption.H"
if (args.readIfPresent("region", regionName))
{
Info<< "Create mesh " << regionName << " for time = "
<< runTimeExtruded.timeName() << nl << endl;
}
else
{
Info<< "Create mesh for time = "
<< runTimeExtruded.timeName() << nl << endl;
}
{
Info<< "Create mesh";
if (!polyMesh::regionName(regionName).empty())
{
Info<< ' ' << regionName;
}
Info<< " for time = " << runTimeExtruded.timeName() << nl << nl;
}
const IOdictionary dict const IOdictionary dict
( (

View File

@ -1210,7 +1210,7 @@ void extrudeGeometricProperties
( (
"patchFaceCentres", "patchFaceCentres",
mesh.pointsInstance(), mesh.pointsInstance(),
mesh.meshSubDir, polyMesh::meshSubDir,
mesh, mesh,
IOobject::MUST_READ IOobject::MUST_READ
) )
@ -1222,7 +1222,7 @@ void extrudeGeometricProperties
( (
"patchEdgeCentres", "patchEdgeCentres",
mesh.pointsInstance(), mesh.pointsInstance(),
mesh.meshSubDir, polyMesh::meshSubDir,
mesh, mesh,
IOobject::MUST_READ IOobject::MUST_READ
) )
@ -1268,7 +1268,7 @@ void extrudeGeometricProperties
( (
"faceCentres", "faceCentres",
regionMesh.pointsInstance(), regionMesh.pointsInstance(),
regionMesh.meshSubDir, polyMesh::meshSubDir,
regionMesh, regionMesh,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -1352,7 +1352,7 @@ void extrudeGeometricProperties
( (
"cellCentres", "cellCentres",
regionMesh.pointsInstance(), regionMesh.pointsInstance(),
regionMesh.meshSubDir, polyMesh::meshSubDir,
regionMesh, regionMesh,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -2555,7 +2555,7 @@ int main(int argc, char *argv[])
( (
"cellToPatchFaceAddressing", "cellToPatchFaceAddressing",
regionMesh.facesInstance(), regionMesh.facesInstance(),
regionMesh.meshSubDir, polyMesh::meshSubDir,
regionMesh, regionMesh,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -2571,7 +2571,7 @@ int main(int argc, char *argv[])
( (
"faceToPatchFaceAddressing", "faceToPatchFaceAddressing",
regionMesh.facesInstance(), regionMesh.facesInstance(),
regionMesh.meshSubDir, polyMesh::meshSubDir,
regionMesh, regionMesh,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -2588,7 +2588,7 @@ int main(int argc, char *argv[])
( (
"faceToPatchEdgeAddressing", "faceToPatchEdgeAddressing",
regionMesh.facesInstance(), regionMesh.facesInstance(),
regionMesh.meshSubDir, polyMesh::meshSubDir,
regionMesh, regionMesh,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -2605,7 +2605,7 @@ int main(int argc, char *argv[])
( (
"pointToPatchPointAddressing", "pointToPatchPointAddressing",
regionMesh.facesInstance(), regionMesh.facesInstance(),
regionMesh.meshSubDir, polyMesh::meshSubDir,
regionMesh, regionMesh,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -2647,7 +2647,7 @@ int main(int argc, char *argv[])
( (
"patchFaceCentres", "patchFaceCentres",
mesh.pointsInstance(), mesh.pointsInstance(),
mesh.meshSubDir, polyMesh::meshSubDir,
mesh, mesh,
IOobject::MUST_READ IOobject::MUST_READ
); );

View File

@ -296,7 +296,7 @@ void Foam::conformalVoronoiMesh::writeMesh(const fileName& instance)
// ( // (
// "pointDualAddressing", // "pointDualAddressing",
// instance, // instance,
// "tetDualMesh"/polyMesh::meshSubDir, // polyMesh::meshDir("tetDualMesh"),
// runTime_, // runTime_,
// IOobject::NO_READ, // IOobject::NO_READ,
// IOobject::NO_WRITE, // IOobject::NO_WRITE,
@ -343,7 +343,7 @@ void Foam::conformalVoronoiMesh::writeMesh(const fileName& instance)
// ( // (
// "dualPoints", // "dualPoints",
// instance, // instance,
// "tetDualMesh"/polyMesh::meshSubDir, // polyMesh::meshDir("tetDualMesh"),
// runTime_, // runTime_,
// IOobject::NO_READ, // IOobject::NO_READ,
// IOobject::NO_WRITE, // IOobject::NO_WRITE,

View File

@ -129,7 +129,7 @@ int main(int argc, char *argv[])
const word& regionName = regionNames[regioni]; const word& regionName = regionNames[regioni];
const fileName meshDir const fileName meshDir
( (
polyMesh::regionName(regionName)/polyMesh::meshSubDir polyMesh::meshDir(regionName)
); );
if (regionNames.size() > 1) if (regionNames.size() > 1)

View File

@ -86,7 +86,7 @@ int main(int argc, char *argv[])
#include "createNamedPolyMesh.H" #include "createNamedPolyMesh.H"
const fileName setsSubPath(mesh.dbDir()/polyMesh::meshSubDir/"sets"); const fileName setsSubPath(mesh.meshDir()/"sets");
// Search for list of objects for the time of the mesh // Search for list of objects for the time of the mesh
word setsInstance = runTime.findInstance word setsInstance = runTime.findInstance

View File

@ -894,7 +894,7 @@ void createAndWriteRegion
( (
"pointRegionAddressing", "pointRegionAddressing",
newMesh().facesInstance(), newMesh().facesInstance(),
newMesh().meshSubDir, polyMesh::meshSubDir,
newMesh(), newMesh(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -913,7 +913,7 @@ void createAndWriteRegion
( (
"faceRegionAddressing", "faceRegionAddressing",
newMesh().facesInstance(), newMesh().facesInstance(),
newMesh().meshSubDir, polyMesh::meshSubDir,
newMesh(), newMesh(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -951,7 +951,7 @@ void createAndWriteRegion
( (
"cellRegionAddressing", "cellRegionAddressing",
newMesh().facesInstance(), newMesh().facesInstance(),
newMesh().meshSubDir, polyMesh::meshSubDir,
newMesh(), newMesh(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -970,7 +970,7 @@ void createAndWriteRegion
( (
"boundaryRegionAddressing", "boundaryRegionAddressing",
newMesh().facesInstance(), newMesh().facesInstance(),
newMesh().meshSubDir, polyMesh::meshSubDir,
newMesh(), newMesh(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later. This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -22,12 +22,14 @@ Provided Variables
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
Foam::Info << "Create mesh";
if (regionName != Foam::polyMesh::defaultRegion)
{ {
Foam::Info << ' ' << regionName; Foam::Info << "Create mesh";
if (!Foam::polyMesh::regionName(regionName).empty())
{
Foam::Info << ' ' << regionName;
}
Foam::Info << " for time = " << runTime.timeName() << Foam::nl;
} }
Foam::Info << " for time = " << runTime.timeName() << Foam::nl;
Foam::fvMesh mesh Foam::fvMesh mesh
( (

View File

@ -396,7 +396,7 @@ int main(int argc, char *argv[])
const word& regionName = regionNames[regioni]; const word& regionName = regionNames[regioni];
const fileName meshDir const fileName meshDir
( (
polyMesh::regionName(regionName)/polyMesh::meshSubDir polyMesh::meshDir(regionName)
); );
if (regionNames.size() > 1) if (regionNames.size() > 1)

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -296,15 +296,16 @@ int main(int argc, char *argv[])
IOobject::fileModificationChecking = IOobject::timeStamp; IOobject::fileModificationChecking = IOobject::timeStamp;
word regionName(polyMesh::defaultRegion); // Specified region or default region
if (args.readIfPresent("region", regionName)) #include "getRegionOption.H"
if (!polyMesh::regionName(regionName).empty())
{ {
Info<< "Using region " << regionName << nl << endl; Info<< "Using region " << regionName << nl << endl;
} }
const fileName meshDir const fileName meshDir
( (
polyMesh::regionName(regionName)/polyMesh::meshSubDir polyMesh::meshDir(regionName)
); );

View File

@ -813,11 +813,7 @@ int main(int argc, char *argv[])
IOobject io IOobject io
( (
"faBoundary", "faBoundary",
mesh.time().findInstance mesh.time().findInstance(mesh.meshDir(), "boundary"),
(
mesh.dbDir()/polyMesh::meshSubDir,
"boundary"
),
faMesh::meshSubDir, faMesh::meshSubDir,
mesh, mesh,
IOobject::READ_IF_PRESENT, IOobject::READ_IF_PRESENT,

View File

@ -305,7 +305,7 @@ autoPtr<mapPolyMesh> mergeSharedPoints
boundBox procBounds boundBox procBounds
( (
const PtrList<Time>& databases, const PtrList<Time>& databases,
const word& regionDir const word& regionName
) )
{ {
boundBox bb; boundBox bb;
@ -316,7 +316,7 @@ boundBox procBounds
( (
procDb.findInstance procDb.findInstance
( (
regionDir/polyMesh::meshSubDir, polyMesh::meshDir(regionName),
"points" "points"
) )
); );
@ -345,10 +345,10 @@ boundBox procBounds
"points", "points",
procDb.findInstance procDb.findInstance
( (
regionDir/polyMesh::meshSubDir, polyMesh::meshDir(regionName),
"points" "points"
), ),
regionDir/polyMesh::meshSubDir, polyMesh::meshDir(regionName),
procDb, procDb,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -771,7 +771,7 @@ int main(int argc, char *argv[])
( (
"faces", "faces",
databases[0].timeName(), databases[0].timeName(),
polyMesh::regionName(regionName)/polyMesh::meshSubDir, polyMesh::meshDir(regionName),
databases[0], databases[0],
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE

View File

@ -275,7 +275,7 @@ void Foam::masterMeshInstance
{ {
const fileName meshSubDir const fileName meshSubDir
( (
polyMesh::regionName(io.name()) / polyMesh::meshSubDir polyMesh::meshDir(io.name())
); );
if (UPstream::master()) if (UPstream::master())

View File

@ -1577,14 +1577,20 @@ int main(int argc, char *argv[])
forAll(regionNames, regioni) forAll(regionNames, regioni)
{ {
const word& regionName = regionNames[regioni]; const word& regionName = regionNames[regioni];
const word& regionDir = polyMesh::regionName(regionName);
const fileName volMeshSubDir(regionDir/polyMesh::meshSubDir); const fileName volMeshSubDir
const fileName areaMeshSubDir(regionDir/faMesh::meshSubDir); (
polyMesh::meshDir(regionName)
);
const fileName areaMeshSubDir
(
polyMesh::regionName(regionName) / faMesh::meshSubDir
);
InfoOrPout InfoOrPout
<< nl << nl
<< "Reconstructing mesh " << regionDir << nl << endl; << "Reconstructing mesh:"
<< polyMesh::regionName(regionName) << nl << endl;
bool areaMeshDetected = false; bool areaMeshDetected = false;
@ -2474,15 +2480,20 @@ int main(int argc, char *argv[])
forAll(regionNames, regioni) forAll(regionNames, regioni)
{ {
const word& regionName = regionNames[regioni]; const word& regionName = regionNames[regioni];
const word& regionDir = polyMesh::regionName(regionName);
const fileName volMeshSubDir(regionDir/polyMesh::meshSubDir); const fileName volMeshSubDir
const fileName areaMeshSubDir(regionDir/faMesh::meshSubDir); (
polyMesh::meshDir(regionName)
);
const fileName areaMeshSubDir
(
polyMesh::regionName(regionName) / faMesh::meshSubDir
);
InfoOrPout InfoOrPout
<< nl << nl << nl << nl
<< (decompose ? "Decomposing" : "Redistributing") << (decompose ? "Decomposing" : "Redistributing")
<< " mesh " << regionDir << nl << endl; << " mesh:" << polyMesh::regionName(regionName) << nl << endl;
// Get time instance directory // Get time instance directory

View File

@ -184,7 +184,7 @@ int main(int argc, char *argv[])
( (
"pointDualAddressing", "pointDualAddressing",
tetDualMesh.facesInstance(), tetDualMesh.facesInstance(),
tetDualMesh.meshSubDir, polyMesh::meshSubDir,
tetDualMesh, tetDualMesh,
IOobject::MUST_READ IOobject::MUST_READ
) )

View File

@ -540,7 +540,7 @@ int main(int argc, char *argv[])
"boundary", "boundary",
runTime.findInstance runTime.findInstance
( (
polyMesh::regionName(regionName)/polyMesh::meshSubDir, polyMesh::meshDir(regionName),
"boundary", "boundary",
IOobject::READ_IF_PRESENT IOobject::READ_IF_PRESENT
), ),

View File

@ -54,8 +54,8 @@ Foam::IOPtrList<Foam::entry> Foam::boundaryInfo::readBoundaryDict
IOobject IOobject
( (
"boundary", "boundary",
runTime.findInstance(regionName/polyMesh::meshSubDir, "boundary"), runTime.findInstance(polyMesh::meshDir(regionName), "boundary"),
regionName/polyMesh::meshSubDir, polyMesh::meshDir(regionName),
runTime, runTime,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,

View File

@ -409,15 +409,13 @@ int main(int argc, char *argv[])
} }
const bool enableEntries = args.found("enableFunctionEntries"); const bool enableEntries = args.found("enableFunctionEntries");
const word regionName =
args.getOrDefault<word>("region", polyMesh::defaultRegion);
fileName regionPrefix; fileName regionPrefix;
if (regionName != polyMesh::defaultRegion)
{ {
regionPrefix = regionName; // Specified region or default region
} #include "getRegionOption.H"
regionPrefix = polyMesh::regionName(regionName);
}
// Per cyclic patch the new name for this side and the other side // Per cyclic patch the new name for this side and the other side
HashTable<word> thisNames; HashTable<word> thisNames;

View File

@ -13,6 +13,9 @@ License
Description Description
Add multi-region command-line options: -allRegions, -regions, -region Add multi-region command-line options: -allRegions, -regions, -region
Required Classes
- Foam::argList
See Also See Also
getAllRegionOptions.H getAllRegionOptions.H

View File

@ -1,6 +1,32 @@
Foam::argList::addOption /*---------------------------------------------------------------------------*\
( ========= |
"region", \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
"name", \\ / O peration |
"Specify alternative mesh region" \\ / A nd | www.openfoam.com
); \\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Add -region option
Required Classes
- Foam::argList
\*---------------------------------------------------------------------------*/
{
Foam::argList::addOption
(
"region",
"name",
"Specify mesh region (default: region0)"
);
}
// ************************************************************************* //

View File

@ -1,3 +1,24 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Add various time-related options (see Foam::timeSelector)
Required Classes
- Foam::argList
\*---------------------------------------------------------------------------*/
Foam::argList::addBoolOption Foam::argList::addBoolOption
( (
"constant", "constant",
@ -22,3 +43,5 @@ Foam::argList::addOption
"time", "time",
"specify a single time value to select" "specify a single time value to select"
); );
// ************************************************************************* //

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2021 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later. This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -14,6 +14,10 @@ Description
Create a fvMesh (specified region or defaultRegion) with Create a fvMesh (specified region or defaultRegion) with
additional handling of -dry-run and -dry-run-write options. additional handling of -dry-run and -dry-run-write options.
Required Classes
- Foam::fvMesh
- Foam::simplifiedMeshes::columnFvMesh
Required Variables Required Variables
- args [argList] - args [argList]
- runTime [Time] - runTime [Time]
@ -26,7 +30,12 @@ Provided Variables
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
Foam::autoPtr<Foam::fvMesh> meshPtr(nullptr); Foam::autoPtr<Foam::fvMesh> meshPtr(nullptr);
Foam::word regionName(Foam::polyMesh::defaultRegion);
// "getRegionOption.H"
Foam::word regionName
(
args.getOrDefault<word>("region", Foam::polyMesh::defaultRegion)
);
if (args.dryRun() || args.found("dry-run-write")) if (args.dryRun() || args.found("dry-run-write"))
{ {
@ -34,9 +43,6 @@ if (args.dryRun() || args.found("dry-run-write"))
<< "Operating in 'dry-run' mode: case will run for 1 time step. " << "Operating in 'dry-run' mode: case will run for 1 time step. "
<< "All checks assumed OK on a clean exit" << Foam::endl; << "All checks assumed OK on a clean exit" << Foam::endl;
// Allow region in combination with dry-run
args.readIfPresent("region", regionName);
Foam::FieldBase::allowConstructFromLargerSize = true; Foam::FieldBase::allowConstructFromLargerSize = true;
// Create a simplified 1D mesh and attempt to re-create boundary conditions // Create a simplified 1D mesh and attempt to re-create boundary conditions
@ -68,7 +74,7 @@ if (args.dryRun() || args.found("dry-run-write"))
else else
{ {
Foam::Info << "Create mesh"; Foam::Info << "Create mesh";
if (args.readIfPresent("region", regionName)) if (!Foam::polyMesh::regionName(regionName).empty())
{ {
Foam::Info << ' ' << regionName; Foam::Info << ' ' << regionName;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later. This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -14,6 +14,9 @@ License
Description Description
Create a fvMesh for a specified region, or the defaultRegion Create a fvMesh for a specified region, or the defaultRegion
Required Classes
- Foam::fvMesh
Required Variables Required Variables
- args [argList] - args [argList]
- runTime [Time] - runTime [Time]
@ -24,11 +27,15 @@ Provided Variables
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
Foam::word regionName(Foam::polyMesh::defaultRegion); // "getRegionOption.H"
Foam::word regionName
(
args.getOrDefault<word>("region", Foam::polyMesh::defaultRegion)
);
{ {
Foam::Info << "Create mesh"; Foam::Info << "Create mesh";
if (args.readIfPresent("region", regionName)) if (!Foam::polyMesh::regionName(regionName).empty())
{ {
Foam::Info << ' ' << regionName; Foam::Info << ' ' << regionName;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later. This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -14,7 +14,11 @@ License
Description Description
Create a polyMesh for a specified region, or the defaultRegion Create a polyMesh for a specified region, or the defaultRegion
Required Classes
- Foam::polyMesh
Required Variables Required Variables
- args [argList]
- runTime [Time] - runTime [Time]
Provided Variables Provided Variables
@ -23,11 +27,15 @@ Provided Variables
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
Foam::word regionName(Foam::polyMesh::defaultRegion); // "getRegionOption.H"
Foam::word regionName
(
args.getOrDefault<word>("region", Foam::polyMesh::defaultRegion)
);
{ {
Foam::Info << "Create polyMesh"; Foam::Info << "Create polyMesh";
if (args.readIfPresent("region", regionName)) if (!Foam::polyMesh::regionName(regionName).empty())
{ {
Foam::Info << ' ' << regionName; Foam::Info << ' ' << regionName;
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd. Copyright (C) 2022-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later. This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -32,13 +32,13 @@ Foam::PtrList<Foam::polyMesh> meshes(regionNames.size());
{ {
forAll(regionNames, regioni) forAll(regionNames, regioni)
{ {
const Foam::word& regionName = regionNames[regioni]; const auto& regionName = regionNames[regioni];
Foam::Info<< "Create polyMesh"; Foam::Info<< "Create polyMesh";
if if
( (
regionNames.size() > 1 regionNames.size() > 1
|| regionName != Foam::polyMesh::defaultRegion || !Foam::polyMesh::regionName(regionName).empty()
) )
{ {
Foam::Info<< ' ' << regionName; Foam::Info<< ' ' << regionName;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later. This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -23,6 +23,11 @@ Note
There is no semantical difference between "-regions name" There is no semantical difference between "-regions name"
and "-region name" and "-region name"
Required Classes
- Foam::polyMesh
- Foam::regionProperties
- Foam::IOobjectOption
Required Variables Required Variables
- args [argList] - args [argList]
- runTime [Time] - runTime [Time]
@ -42,7 +47,10 @@ wordList regionNames;
if (args.found("allRegions")) if (args.found("allRegions"))
{ {
regionNames = regionNames =
regionProperties(runTime, IOobject::READ_IF_PRESENT).names(); (
Foam::regionProperties(runTime, IOobjectOption::READ_IF_PRESENT)
.names()
);
if (regionNames.empty()) if (regionNames.empty())
{ {
@ -60,17 +68,20 @@ wordList regionNames;
if if
( (
selectByName.size() == 1 selectByName.size() == 1
&& selectByName.first().isLiteral() && selectByName.front().isLiteral()
) )
{ {
// Identical to -region NAME // Identical to -region NAME
regionNames.resize(1); regionNames.resize(1);
regionNames.first() = selectByName.first(); regionNames.front() = selectByName.front();
} }
else if (selectByName.size()) else if (selectByName.size())
{ {
regionNames = regionNames =
regionProperties(runTime, IOobject::READ_IF_PRESENT).names(); (
Foam::regionProperties(runTime, IOobjectOption::READ_IF_PRESENT)
.names()
);
if (regionNames.empty()) if (regionNames.empty())
{ {
@ -99,14 +110,14 @@ wordList regionNames;
else if (args.found("region")) else if (args.found("region"))
{ {
regionNames.resize(1); regionNames.resize(1);
regionNames.first() = args.get<word>("region"); regionNames.front() = args.get<word>("region");
} }
// Fallback to defaultRegion // Fallback to defaultRegion
if (regionNames.empty()) if (regionNames.empty())
{ {
regionNames.resize(1); regionNames.resize(1);
regionNames.first() = polyMesh::defaultRegion; regionNames.front() = Foam::polyMesh::defaultRegion;
} }
} }

View File

@ -0,0 +1,33 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Get the value from the -region option
Required Classes
- Foam::polyMesh
Required Variables
- args [argList]
Provided Variables
- regionName [word]
\*---------------------------------------------------------------------------*/
Foam::word regionName
(
args.getOrDefault<word>("region", Foam::polyMesh::defaultRegion)
);
// ************************************************************************* //

View File

@ -1829,7 +1829,7 @@ const Foam::labelList& Foam::globalMeshData::sharedPointGlobalLabels() const
IOobject addrHeader IOobject addrHeader
( (
"pointProcAddressing", "pointProcAddressing",
mesh_.facesInstance()/mesh_.meshSubDir, mesh_.facesInstance()/polyMesh::meshSubDir,
mesh_, mesh_,
IOobject::MUST_READ IOobject::MUST_READ
); );

View File

@ -47,6 +47,7 @@ namespace Foam
} }
Foam::word Foam::polyMesh::defaultRegion = "region0"; Foam::word Foam::polyMesh::defaultRegion = "region0";
Foam::word Foam::polyMesh::meshSubDir = "polyMesh"; Foam::word Foam::polyMesh::meshSubDir = "polyMesh";
@ -820,11 +821,22 @@ const Foam::word& Foam::polyMesh::regionName(const word& region)
} }
Foam::fileName Foam::polyMesh::meshDir(const word& region)
{
if (region.empty() || region == polyMesh::defaultRegion)
{
return polyMesh::meshSubDir;
}
return (region / polyMesh::meshSubDir);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::fileName& Foam::polyMesh::dbDir() const const Foam::fileName& Foam::polyMesh::dbDir() const
{ {
if (objectRegistry::dbDir() == defaultRegion) if (objectRegistry::name() == polyMesh::defaultRegion)
{ {
return parent().dbDir(); return parent().dbDir();
} }

View File

@ -426,6 +426,10 @@ public:
// Regions // Regions
//- Return the local mesh directory name (eg, "polyMesh")
//- after applying filter for defaultRegion
static fileName meshDir(const word& region);
//- The mesh region name or word::null if polyMesh::defaultRegion //- The mesh region name or word::null if polyMesh::defaultRegion
static const word& regionName(const word& region); static const word& regionName(const word& region);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012 OpenFOAM Foundation Copyright (C) 2012 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd. Copyright (C) 2022-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later. This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -14,40 +14,49 @@ License
Description Description
Create a dynamicFvMesh for a specified region, or the defaultRegion Create a dynamicFvMesh for a specified region, or the defaultRegion
Required Classes
- Foam::dynamicFvMesh
Required Variables Required Variables
- args [argList]
- runTime [Time] - runTime [Time]
Provided Variables Provided Variables
- regionName [word] - regionName [word]
- mesh [dynamicFvMesh], meshPtr - mesh [dynamicFvMesh]
- meshPtr [autoPtr<dynamicFvMesh>]
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
Foam::word regionName(Foam::polyMesh::defaultRegion);
Foam::autoPtr<Foam::dynamicFvMesh> meshPtr; Foam::autoPtr<Foam::dynamicFvMesh> meshPtr;
// "getRegionOption.H"
Foam::word regionName
(
args.getOrDefault<word>("region", Foam::polyMesh::defaultRegion)
);
{ {
Foam::Info << "Create dynamic mesh"; Foam::Info << "Create dynamic mesh";
if (args.readIfPresent("region", regionName)) if (!Foam::polyMesh::regionName(regionName).empty())
{ {
Foam::Info << ' ' << regionName; Foam::Info << ' ' << regionName;
} }
Foam::Info << " for time = " << runTime.timeName() << Foam::nl; Foam::Info << " for time = " << runTime.timeName() << Foam::nl;
meshPtr = dynamicFvMesh::New meshPtr = Foam::dynamicFvMesh::New
( (
IOobject Foam::IOobject
( (
regionName, regionName,
runTime.timeName(), runTime.timeName(),
runTime, runTime,
IOobject::MUST_READ Foam::IOobject::MUST_READ
) )
); );
} }
Foam::dynamicFvMesh& mesh = meshPtr();
dynamicFvMesh& mesh = meshPtr();
Foam::Info << Foam::endl; Foam::Info << Foam::endl;

View File

@ -5671,7 +5671,7 @@ void Foam::hexRef8::removeFiles(const polyMesh& mesh)
( (
"dummy", "dummy",
mesh.facesInstance(), mesh.facesInstance(),
mesh.meshSubDir, polyMesh::meshSubDir,
mesh mesh
); );
fileName setsDir(io.path()); fileName setsDir(io.path());

View File

@ -1699,7 +1699,7 @@ void Foam::refinementHistory::removeFiles(const polyMesh& mesh)
( (
"dummy", "dummy",
mesh.facesInstance(), mesh.facesInstance(),
mesh.meshSubDir, polyMesh::meshSubDir,
mesh mesh
); );
fileName setsDir(io.path()); fileName setsDir(io.path());

View File

@ -722,6 +722,9 @@ public:
return thisDb().name(); return thisDb().name();
} }
// Regions
//- The mesh region name or word::null if polyMesh::defaultRegion //- The mesh region name or word::null if polyMesh::defaultRegion
const word& regionName() const; const word& regionName() const;

View File

@ -0,0 +1,31 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Add -area-region option
Required Classes
- Foam::argList
\*---------------------------------------------------------------------------*/
{
Foam::argList::addOption
(
"area-region",
"name",
"Specify area-mesh region"
);
}
// ************************************************************************* //

View File

@ -1 +1,34 @@
faMesh aMesh(mesh); /*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 Wikki Ltd
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Create a finite-area mesh for the defaultRegion
Required Variables
- mesh [polyMesh]
Provided Variables
- aMesh [faMesh]
\*---------------------------------------------------------------------------*/
Foam::Info << "Create finite-area mesh";
Foam::Info << Foam::nl;
Foam::faMesh aMesh
(
mesh
);
// ************************************************************************* //

View File

@ -0,0 +1,53 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Create a finite-area mesh for a specified region, or the defaultRegion
Required Classes
- Foam::polyMesh
Required Variables
- mesh [polyMesh]
- runTime [Time]
Provided Variables
- areaRegionName [word]
- aMesh [faMesh]
\*---------------------------------------------------------------------------*/
// "getFaRegionOption.H"
Foam::word areaRegionName
(
args.getOrDefault<word>("area-region", Foam::polyMesh::defaultRegion)
);
{
Foam::Info << "Create finite-area mesh";
if (!Foam::polyMesh::regionName(areaRegionName).empty())
{
Foam::Info << ' ' << areaRegionName;
}
Foam::Info << " for time = " << runTime.timeName() << Foam::nl;
}
Foam::faMesh aMesh
(
areaRegionName,
mesh
);
Foam::Info << Foam::endl;
// ************************************************************************* //

View File

@ -0,0 +1,33 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Get the value from the -area-region option
Required Classes
- Foam::polyMesh
Required Variables
- args [argList]
Provided Variables
- areaRegionName [word]
\*---------------------------------------------------------------------------*/
Foam::word areaRegionName
(
args.getOrDefault<word>("area-region", Foam::polyMesh::defaultRegion)
);
// ************************************************************************* //

View File

@ -461,7 +461,7 @@ Foam::fvMeshTools::newMesh
const fileName meshSubDir const fileName meshSubDir
( (
polyMesh::regionName(io.name()) / polyMesh::meshSubDir polyMesh::meshDir(io.name())
); );
@ -745,7 +745,7 @@ Foam::fvMeshTools::loadOrCreateMeshImpl
const fileName meshSubDir const fileName meshSubDir
( (
polyMesh::regionName(io.name()) / polyMesh::meshSubDir polyMesh::meshDir(io.name())
); );

View File

@ -64,7 +64,7 @@ bool Foam::simplifiedMeshes::columnFvMeshInfo::setPatchEntries
( (
"boundary", "boundary",
localInstance_, localInstance_,
polyMesh::regionName(regionName_)/polyMesh::meshSubDir, polyMesh::meshDir(regionName_),
runTime, runTime,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -209,7 +209,7 @@ void Foam::simplifiedMeshes::columnFvMeshInfo::initialise(const Time& runTime)
( (
"points", "points",
localInstance_, localInstance_,
polyMesh::regionName(regionName_)/polyMesh::meshSubDir, polyMesh::meshDir(regionName_),
runTime, runTime,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
@ -413,7 +413,7 @@ Foam::simplifiedMeshes::columnFvMeshInfo::columnFvMeshInfo
( (
runTime.findInstance runTime.findInstance
( (
polyMesh::regionName(regionName_)/polyMesh::meshSubDir, polyMesh::meshDir(regionName_),
"boundary", "boundary",
IOobject::READ_IF_PRESENT IOobject::READ_IF_PRESENT
) )

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015-2022 OpenCFD Ltd. Copyright (C) 2015-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -354,16 +354,9 @@ Foam::word Foam::functionObjects::externalCoupled::compositeName
} }
else if (regionNames.size() == 1) else if (regionNames.size() == 1)
{ {
if (regionNames[0] == polyMesh::defaultRegion) // For compatibility with single region cases
{ // - suppress single region name
// For compatibility with single region cases return polyMesh::regionName(regionNames[0]);
// - suppress single region name
return word::null;
}
else
{
return regionNames[0];
}
} }
// Enforce lexical ordering // Enforce lexical ordering

View File

@ -3755,7 +3755,7 @@ void Foam::meshRefinement::removeFiles(const polyMesh& mesh)
( (
"dummy", "dummy",
mesh.facesInstance(), mesh.facesInstance(),
mesh.meshSubDir, polyMesh::meshSubDir,
mesh mesh
); );
fileName setsDir(io.path()); fileName setsDir(io.path());

View File

@ -136,7 +136,7 @@ Foam::fileName Foam::topoSet::localPath
const word& name const word& name
) )
{ {
return mesh.facesInstance()/mesh.dbDir()/polyMesh::meshSubDir/"sets"/name; return mesh.facesInstance()/mesh.meshDir()/"sets"/name;
} }
@ -327,7 +327,7 @@ Foam::IOobject Foam::topoSet::findIOobject
name, name,
mesh.time().findInstance mesh.time().findInstance
( (
mesh.dbDir()/polyMesh::meshSubDir/"sets", mesh.meshDir()/"sets",
word::null, word::null,
IOobject::READ_IF_PRESENT, IOobject::READ_IF_PRESENT,
mesh.facesInstance() mesh.facesInstance()
@ -628,7 +628,7 @@ void Foam::topoSet::removeFiles(const polyMesh& mesh)
( (
"dummy", "dummy",
mesh.facesInstance(), mesh.facesInstance(),
mesh.meshSubDir/"sets", polyMesh::meshSubDir/"sets",
mesh mesh
); );
fileName setsDir(io.path()); fileName setsDir(io.path());

View File

@ -1362,7 +1362,7 @@ Foam::isoSurfacePoint::isoSurfacePoint
( (
"C", "C",
fvmesh.pointsInstance(), fvmesh.pointsInstance(),
fvmesh.meshSubDir, polyMesh::meshSubDir,
fvmesh, fvmesh,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,