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)
This commit is contained in:
Mark Olesen
2022-05-20 11:02:49 +02:00
parent f00f236cb3
commit ba10afea77
50 changed files with 347 additions and 357 deletions

View File

@ -1,9 +1,33 @@
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
(
dynamicFvMesh::New
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
(
IOobject
(
@ -12,11 +36,17 @@
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;
// ************************************************************************* //

View File

@ -1,9 +1,33 @@
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
(
dynamicFvMesh::New
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
(
IOobject
(
@ -12,11 +36,17 @@
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;
// ************************************************************************* //

View File

@ -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;

View File

@ -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

View File

@ -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))
{

View File

@ -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

View File

@ -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))

View File

@ -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());

View File

@ -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))

View File

@ -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

View File

@ -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

View File

@ -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
)
);
}

View File

@ -331,7 +331,7 @@ void Foam::conformalVoronoiMesh::writeMesh(const fileName& instance)
// (
// IOobject
// (
// Foam::polyMesh::defaultRegion,
// polyMesh::defaultRegion,
// instance,
// runTime_,
// IOobject::MUST_READ

View File

@ -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)

View File

@ -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;

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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
)
);

View File

@ -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())
{

View File

@ -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
(

View File

@ -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])
{

View File

@ -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);

View File

@ -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());

View File

@ -29,14 +29,11 @@ if (timeDirs.size() && doLagrangian)
auto& cloudFields = regionCloudFields[regioni];
const word& regionName = regionNames[regioni];
const word& regionDir =
(
regionName != polyMesh::defaultRegion
? regionName
: word::null
);
const fileName cloudPrefix(regionDir/cloud::prefix);
const fileName cloudPrefix
(
polyMesh::regionName(regionName)/cloud::prefix
);
for (const instant& inst : timeDirs)
{

View File

@ -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)
{

View File

@ -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 regionOutDir(outputDir/polyMesh::regionName(regionName));
fileName regionalDir(outputDir/regionDir);
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;
}

View File

@ -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
),

View File

@ -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;

View File

@ -78,14 +78,11 @@ Foam::dictionary Foam::solverTemplate::readFluidFieldTemplates
{
Info<< " Reading fluid field templates";
if (regionName == word::null)
if (!regionName.empty())
{
Info<< " for region " << regionName;
}
Info<< endl;
}
else
{
Info<< " for region " << regionName << endl;
}
dictionary fieldTemplates = solverDict.subDict("fluidFields");

View File

@ -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");

View File

@ -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");

View File

@ -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 ".."

View File

@ -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;
}

View File

@ -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();

View File

@ -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

View File

@ -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();

View File

@ -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);
}

View File

@ -1,21 +1,40 @@
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
(
dynamicFvMesh::New
meshPtr = dynamicFvMesh::New
(
IOobject
(
@ -24,7 +43,13 @@
runTime,
IOobject::MUST_READ
)
)
);
}
dynamicFvMesh& mesh = meshPtr();
dynamicFvMesh& mesh = meshPtr();
Foam::Info << Foam::endl;
// ************************************************************************* //

View File

@ -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,

View File

@ -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();

View File

@ -665,7 +665,7 @@ public:
inline bool hasInternalEdgeLabels() const noexcept;
// Access
// Database
//- Return true if thisDb() is a valid DB
virtual bool hasDb() const;
@ -680,6 +680,12 @@ public:
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;

View File

@ -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
);

View File

@ -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
);

View File

@ -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
)

View File

@ -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

View File

@ -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);

View File

@ -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();
}

View File

@ -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];

View File

@ -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())
);

View File

@ -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);