ENH: centralized handling of -allRegions, -regions, -region (#2072)

Step 1.
    include "addAllRegionOptions.H"

    Adds the -allRegions, -regions and -region options to argList.

Step 2.
    include "getAllRegionOptions.H"

    Processes the options with -allRegions selecting everything
    from the regionProperties.

    OR use -regions to specify multiple regions (from
       regionProperties), and can also contain regular expressions

    OR use the -region option

    Specifying a single -regions NAME (not a regular expresssion)
    is the same as -region NAME and doesn't use regionProperties

    Creates a `wordList regionNames`

Step 3.
    Do something with the region names.
    Either directly, or quite commonly with the following

    include "createNamedMeshes.H"

    Creates a `PtrList<fvMesh> meshes`

STYLE: add description to some central include files
This commit is contained in:
Mark Olesen
2021-05-05 14:18:55 +02:00
parent 86a2ae4f03
commit c410edf928
26 changed files with 595 additions and 364 deletions

View File

@ -55,12 +55,8 @@ int main(int argc, char *argv[])
argList::noParallel(); argList::noParallel();
argList::noBanner(); argList::noBanner();
#include "addRegionOption.H" #include "addAllRegionOptions.H"
argList::addBoolOption
(
"allRegions",
"operate on all regions in regionProperties"
);
argList::addBoolOption argList::addBoolOption
( (
"verbose", "verbose",
@ -76,11 +72,11 @@ int main(int argc, char *argv[])
const auto decompFile = args.get<fileName>(1); const auto decompFile = args.get<fileName>(1);
const bool region = args.found("region"); const bool region = args.found("region");
const bool allRegions = args.found("allRegions");
const bool verbose = args.found("verbose"); const bool verbose = args.found("verbose");
// Set time from database // Set time from database
#include "createTime.H" #include "createTime.H"
// Allow override of time // Allow override of time
instantList times = timeSelector::selectIfPresent(runTime, args); instantList times = timeSelector::selectIfPresent(runTime, args);
@ -88,31 +84,18 @@ int main(int argc, char *argv[])
const fileName decompDictFile = const fileName decompDictFile =
args.getOrDefault<fileName>("decomposeParDict", ""); args.getOrDefault<fileName>("decomposeParDict", "");
wordList regionNames; // Get region names
wordList regionDirs; #include "getAllRegionOptions.H"
if (allRegions)
wordList regionDirs(regionNames);
if (regionDirs.size() == 1 && regionDirs[0] == polyMesh::defaultRegion)
{ {
Info<< "Decomposing all regions in regionProperties" << nl << endl; regionDirs[0].clear();
regionProperties rp(runTime);
forAllConstIters(rp, iter)
{
const wordList& regions = iter();
forAll(regions, i)
{
regionNames.appendUniq(regions[i]);
}
}
regionDirs = regionNames;
} }
else else
{ {
regionNames.resize(1, fvMesh::defaultRegion); Info<< "Decomposing regions: "
regionDirs.resize(1, word::null); << flatOutput(regionNames) << nl << endl;
if (args.readIfPresent("region", regionNames.first()))
{
regionDirs.first() = regionNames.first();
}
} }
labelList cellToProc; labelList cellToProc;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd. Copyright (C) 2017-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -62,12 +62,9 @@ int main(int argc, char *argv[])
"file", "file",
"Use specified file for decomposePar dictionary" "Use specified file for decomposePar dictionary"
); );
#include "addRegionOption.H"
argList::addBoolOption #include "addAllRegionOptions.H"
(
"allRegions",
"Operate on all regions in regionProperties"
);
argList::addBoolOption argList::addBoolOption
( (
"verbose", "verbose",
@ -107,7 +104,6 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
const bool optRegion = args.found("region"); const bool optRegion = args.found("region");
const bool allRegions = args.found("allRegions");
const bool verbose = args.found("verbose"); const bool verbose = args.found("verbose");
const label numSubdomains = args.getOrDefault<label>("domains", 0); const label numSubdomains = args.getOrDefault<label>("domains", 0);
@ -122,27 +118,20 @@ int main(int argc, char *argv[])
const fileName decompDictFile = const fileName decompDictFile =
args.getOrDefault<fileName>("decomposeParDict", ""); args.getOrDefault<fileName>("decomposeParDict", "");
// Get all region names // Get region names
wordList regionNames; #include "getAllRegionOptions.H"
if (allRegions)
{ Info<< "Decomposing regions: "
regionNames = regionProperties(runTime).names(); << flatOutput(regionNames) << nl << endl;
Info<< "Decomposing all regions in regionProperties" << nl
<< " " << flatOutput(regionNames) << nl << endl;
}
else
{
regionNames.resize(1);
regionNames.first() =
args.getOrDefault<word>("region", fvMesh::defaultRegion);
}
forAll(regionNames, regioni) forAll(regionNames, regioni)
{ {
const word& regionName = regionNames[regioni]; const word& regionName = regionNames[regioni];
const word& regionDir = const word& regionDir =
(regionName == fvMesh::defaultRegion ? word::null : regionName); (
regionName == polyMesh::defaultRegion ? word::null : regionName
);
Info<< "\n\nDecomposing mesh " << regionName << nl << endl; Info<< "\n\nDecomposing mesh " << regionName << nl << endl;
Info<< "Create mesh..." << flush; Info<< "Create mesh..." << flush;

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-2020 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -294,12 +294,9 @@ int main(int argc, char *argv[])
"file", "file",
"Use specified file for decomposePar dictionary" "Use specified file for decomposePar dictionary"
); );
#include "addRegionOption.H"
argList::addBoolOption #include "addAllRegionOptions.H"
(
"allRegions",
"Operate on all regions in regionProperties"
);
argList::addBoolOption argList::addBoolOption
( (
"dry-run", "dry-run",
@ -354,8 +351,6 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
const bool dryrun = args.found("dry-run"); const bool dryrun = args.found("dry-run");
const bool optRegion = args.found("region");
const bool allRegions = args.found("allRegions");
const bool writeCellDist = args.found("cellDist"); const bool writeCellDist = args.found("cellDist");
const bool verbose = args.found("verbose"); const bool verbose = args.found("verbose");
@ -391,27 +386,24 @@ int main(int argc, char *argv[])
decompDictFile = runTime.globalPath()/decompDictFile; decompDictFile = runTime.globalPath()/decompDictFile;
} }
// Get all region names // Get region names
wordList regionNames; #include "getAllRegionOptions.H"
if (allRegions)
{
regionNames = regionProperties(runTime).names();
Info<< "Decomposing all regions in regionProperties" << nl const bool optRegions =
<< " " << flatOutput(regionNames) << nl << endl; (regionNames.size() != 1 || regionNames[0] != polyMesh::defaultRegion);
}
else if (regionNames.size() == 1 && regionNames[0] != polyMesh::defaultRegion)
{ {
regionNames.resize(1); Info<< "Using region: " << regionNames[0] << nl << endl;
regionNames.first() =
args.getOrDefault<word>("region", fvMesh::defaultRegion);
} }
forAll(regionNames, regioni) forAll(regionNames, regioni)
{ {
const word& regionName = regionNames[regioni]; const word& regionName = regionNames[regioni];
const word& regionDir = const word& regionDir =
(regionName == fvMesh::defaultRegion ? word::null : regionName); (
regionName == polyMesh::defaultRegion ? word::null : regionName
);
if (dryrun) if (dryrun)
{ {
@ -436,7 +428,12 @@ int main(int argc, char *argv[])
continue; continue;
} }
Info<< "\n\nDecomposing mesh " << regionName << nl << endl; Info<< "\n\nDecomposing mesh";
if (!regionDir.empty())
{
Info<< ' ' << regionName;
}
Info<< nl << endl;
// Determine the existing processor count directly // Determine the existing processor count directly
label nProcs = fileHandler().nProcs(runTime.path(), regionDir); label nProcs = fileHandler().nProcs(runTime.path(), regionDir);
@ -495,7 +492,7 @@ int main(int argc, char *argv[])
Info<< "Using existing processor directories" << nl; Info<< "Using existing processor directories" << nl;
} }
if (allRegions || optRegion) if (optRegions)
{ {
procDirsProblem = false; procDirsProblem = false;
forceOverwrite = false; forceOverwrite = false;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2018 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -89,12 +89,9 @@ int main(int argc, char *argv[])
// Enable -withZero to prevent accidentally trashing the initial fields // Enable -withZero to prevent accidentally trashing the initial fields
timeSelector::addOptions(true, true); // constant(true), zero(true) timeSelector::addOptions(true, true); // constant(true), zero(true)
argList::noParallel(); argList::noParallel();
#include "addRegionOption.H"
argList::addBoolOption #include "addAllRegionOptions.H"
(
"allRegions",
"Operate on all regions in regionProperties"
);
argList::addOption argList::addOption
( (
"fields", "fields",
@ -171,30 +168,24 @@ int main(int argc, char *argv[])
} }
const bool newTimes = args.found("newTimes"); const bool newTimes = args.found("newTimes");
const bool allRegions = args.found("allRegions");
wordList regionNames; // Get region names
wordList regionDirs; #include "getAllRegionOptions.H"
if (allRegions)
wordList regionDirs(regionNames);
if (regionNames.size() == 1)
{ {
regionNames = regionProperties(runTime).names(); if (regionNames[0] == polyMesh::defaultRegion)
regionDirs = regionNames;
Info<< "Reconstructing all regions in regionProperties" << nl
<< " " << flatOutput(regionNames) << nl << endl;
}
else
{
regionNames.resize(1, fvMesh::defaultRegion);
regionDirs.resize(1, word::null);
if (args.readIfPresent("region", regionNames.first()))
{ {
regionDirs.first() = regionNames.first(); regionDirs[0].clear();
}
else
{
Info<< "Using region: " << regionNames[0] << nl << endl;
} }
} }
// Determine the processor count // Determine the processor count
label nProcs = fileHandler().nProcs(args.path(), regionDirs[0]); label nProcs = fileHandler().nProcs(args.path(), regionDirs[0]);

View File

@ -2263,12 +2263,9 @@ int main(int argc, char *argv[])
// enable -constant ... if someone really wants it // enable -constant ... if someone really wants it
// enable -zeroTime to prevent accidentally trashing the initial fields // enable -zeroTime to prevent accidentally trashing the initial fields
timeSelector::addOptions(true, true); timeSelector::addOptions(true, true);
#include "addRegionOption.H"
argList::addBoolOption #include "addAllRegionOptions.H"
(
"allRegions",
"operate on all regions in regionProperties"
);
#include "addOverwriteOption.H" #include "addOverwriteOption.H"
argList::addBoolOption("decompose", "Decompose case"); argList::addBoolOption("decompose", "Decompose case");
argList::addBoolOption("reconstruct", "Reconstruct case"); argList::addBoolOption("reconstruct", "Reconstruct case");
@ -2506,20 +2503,12 @@ int main(int argc, char *argv[])
const fileName decompDictFile = const fileName decompDictFile =
args.getOrDefault<fileName>("decomposeParDict", ""); args.getOrDefault<fileName>("decomposeParDict", "");
// Get all region names // Get region names
wordList regionNames; #include "getAllRegionOptions.H"
if (args.found("allRegions"))
{
regionNames = regionProperties(runTime).names();
Info<< "Decomposing all regions in regionProperties" << nl if (regionNames.size() == 1 && regionNames[0] != polyMesh::defaultRegion)
<< " " << flatOutput(regionNames) << nl << endl;
}
else
{ {
regionNames.resize(1); Info<< "Using region: " << regionNames[0] << nl << endl;
regionNames.first() =
args.getOrDefault<word>("region", fvMesh::defaultRegion);
} }
@ -2553,12 +2542,11 @@ int main(int argc, char *argv[])
forAll(regionNames, regioni) forAll(regionNames, regioni)
{ {
const word& regionName = regionNames[regioni]; const word& regionName = regionNames[regioni];
const fileName meshSubDir const word& regionDir =
( (
regionName == fvMesh::defaultRegion regionName == polyMesh::defaultRegion ? word::null : regionName
? fileName(polyMesh::meshSubDir)
: regionNames[regioni]/polyMesh::meshSubDir
); );
const fileName meshSubDir(regionDir/polyMesh::meshSubDir);
Info<< "\n\nReconstructing mesh " << regionName << nl << endl; Info<< "\n\nReconstructing mesh " << regionName << nl << endl;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -39,7 +39,7 @@ if (doLagrangian)
( (
readDir readDir
( (
runTime.timePath()/regionPrefix/cloud::prefix, runTime.timePath()/regionDir/cloud::prefix,
fileName::DIRECTORY fileName::DIRECTORY
) )
); );

View File

@ -7,7 +7,7 @@ HashTable<HashTable<word>> cloudFields;
if (timeDirs.size() && doLagrangian) if (timeDirs.size() && doLagrangian)
{ {
const fileName& baseDir = mesh.time().path(); const fileName& baseDir = mesh.time().path();
const fileName cloudPrefix(regionPrefix/cloud::prefix); const fileName cloudPrefix(regionDir/cloud::prefix);
Info<< "Searching for lagrangian ... " << flush; Info<< "Searching for lagrangian ... " << flush;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -313,12 +313,10 @@ int main(int argc, char *argv[])
#include "createNamedMesh.H" #include "createNamedMesh.H"
fileName regionPrefix; // Mesh instance (region0 gets filtered out) const word& regionDir =
if (regionName != polyMesh::defaultRegion) (
{ regionName == polyMesh::defaultRegion ? word::null : regionName
regionPrefix = regionName; );
}
// //
// Configuration // Configuration

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -67,7 +67,7 @@ if (doFiniteArea)
pp, pp,
writeOpts, writeOpts,
( (
outputDir/regionPrefix/"finite-area" outputDir/regionDir/"finite-area"
/ "finiteArea" + timeDesc / "finiteArea" + timeDesc
), ),
Pstream::parRun() Pstream::parRun()

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -31,7 +31,7 @@ Description
if (doLagrangian) if (doLagrangian)
{ {
const fileName cloudPrefix = (regionPrefix/cloud::prefix); const fileName cloudPrefix = (regionDir/cloud::prefix);
wordList cloudNames = ListOps::create<word> wordList cloudNames = ListOps::create<word>
( (
@ -89,7 +89,7 @@ if (doLagrangian)
writeOpts, writeOpts,
// Output name for the cloud // Output name for the cloud
( (
outputDir/regionPrefix/cloud::prefix outputDir/regionDir/cloud::prefix
/ cloudName/cloudName + timeDesc / cloudName/cloudName + timeDesc
), ),
Pstream::parRun() Pstream::parRun()

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -47,7 +47,7 @@ Description
fileName vtmOutputBase fileName vtmOutputBase
( (
outputDir/regionPrefix/vtkName + timeDesc outputDir/regionDir/vtkName + timeDesc
); );
// Naming // Naming

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -102,7 +102,7 @@ Description
meshProxy.mesh(), meshProxy.mesh(),
writeOpts, writeOpts,
( (
outputDir/regionPrefix outputDir/regionDir
/ "surface-fields"/"surfaceFields" + timeDesc / "surface-fields"/"surfaceFields" + timeDesc
), ),
Pstream::parRun() Pstream::parRun()
@ -205,7 +205,7 @@ Description
pp, pp,
writeOpts, writeOpts,
( (
outputDir/regionPrefix/fz.name() outputDir/regionDir/fz.name()
/ (meshProxy.useSubMesh() ? meshProxy.name() : fz.name()) / (meshProxy.useSubMesh() ? meshProxy.name() : fz.name())
+ timeDesc + timeDesc
), ),

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -39,7 +39,7 @@ if (faceSetName.size())
fileName outputName fileName outputName
( (
outputDir/regionPrefix/"face-set" outputDir/regionDir/"face-set"
/ set.name()/set.name() + timeDesc / set.name()/set.name() + timeDesc
); );
@ -67,7 +67,7 @@ if (pointSetName.size())
fileName outputName fileName outputName
( (
outputDir/regionPrefix/"point-set" outputDir/regionDir/"point-set"
/ set.name()/set.name() + timeDesc / set.name()/set.name() + timeDesc
); );

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -65,7 +65,7 @@ Description
fileName vtmOutputBase fileName vtmOutputBase
( (
outputDir/regionPrefix/vtkName + timeDesc outputDir/regionDir/vtkName + timeDesc
); );
// Combined internal + boundary in a vtm file // Combined internal + boundary in a vtm file
@ -148,7 +148,7 @@ Description
writeOpts.legacy() writeOpts.legacy()
? ?
( (
outputDir/regionPrefix/"boundary" outputDir/regionDir/"boundary"
/ (meshProxy.useSubMesh() ? meshProxy.name() : "boundary") / (meshProxy.useSubMesh() ? meshProxy.name() : "boundary")
+ timeDesc + timeDesc
) )
@ -203,7 +203,7 @@ Description
writeOpts.legacy() writeOpts.legacy()
? ?
( (
outputDir/regionPrefix/pp.name() outputDir/regionDir/pp.name()
/ (meshProxy.useSubMesh() ? meshProxy.name() : pp.name()) / (meshProxy.useSubMesh() ? meshProxy.name() : pp.name())
+ timeDesc + timeDesc
) )
@ -461,7 +461,7 @@ Description
series.write(seriesName); series.write(seriesName);
// Add to multi-region vtm // Add to multi-region vtm
vtmMultiRegion.add(regionName, regionPrefix, vtmWriter); vtmMultiRegion.add(regionName, regionDir, vtmWriter);
} }
if (vtmBoundaries.size()) if (vtmBoundaries.size())

View File

@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Additional mesh accounting (foamToVTK)
\*---------------------------------------------------------------------------*/
PtrList<fvMeshSubsetProxy> meshProxies(meshes.size());
PtrList<vtk::vtuCells> vtuMappings(meshes.size());
{
forAll(meshes, regioni)
{
// Mesh subsetting, or pass through
meshProxies.set
(
regioni,
new fvMeshSubsetProxy
(
meshes[regioni],
cellSubsetType,
cellSelectionName
)
);
// VTU sizing and decomposition information
vtuMappings.set
(
regioni,
new vtk::vtuCells(writeOpts, decomposePoly)
);
}
}
// ************************************************************************* //

View File

@ -1,58 +0,0 @@
PtrList<fvMesh> meshes(regionNames.size());
PtrList<fvMeshSubsetProxy> meshProxies(regionNames.size());
PtrList<vtk::vtuCells> vtuMappings(regionNames.size());
forAll(regionNames, regioni)
{
const word& regionName = regionNames[regioni];
Info<< "Create mesh";
if (regionName != fvMesh::defaultRegion)
{
Info<< ' ' << regionName;
}
Info<< " for time = " << runTime.timeName() << nl << endl;
meshes.set
(
regioni,
new fvMesh
(
IOobject
(
regionName,
runTime.timeName(),
runTime,
IOobject::MUST_READ
)
)
);
// Mesh subsetting, or pass through
meshProxies.set
(
regioni,
new fvMeshSubsetProxy
(
meshes[regioni],
cellSubsetType,
cellSelectionName
)
);
// VTU sizing and decomposition information
vtuMappings.set
(
regioni,
new vtk::vtuCells(writeOpts, decomposePoly)
);
}
Info<< "VTK mesh topology: "
<< timer.cpuTimeIncrement() << " s, "
<< mem.update().size() << " kB" << endl;
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -405,20 +405,7 @@ int main(int argc, char *argv[])
); );
argList::addOptionCompat("one-boundary", {"allPatches", 1806}); argList::addOptionCompat("one-boundary", {"allPatches", 1806});
#include "addRegionOption.H" #include "addAllRegionOptions.H"
argList::addOption
(
"regions",
"wordRes",
"Operate on selected regions from regionProperties.\n"
"Eg, '( gas \"solid.*\" )'"
);
argList::addBoolOption
(
"allRegions",
"Operate on all regions in regionProperties"
);
argList::addOption argList::addOption
( (
@ -473,7 +460,6 @@ int main(int argc, char *argv[])
const bool oneBoundary = args.found("one-boundary") && doBoundary; const bool oneBoundary = args.found("one-boundary") && doBoundary;
const bool nearCellValue = args.found("nearCellValue") && doBoundary; const bool nearCellValue = args.found("nearCellValue") && doBoundary;
const bool allRegions = args.found("allRegions");
const vtk::outputOptions writeOpts = getOutputOptions(args); const vtk::outputOptions writeOpts = getOutputOptions(args);
@ -563,80 +549,8 @@ int main(int argc, char *argv[])
// Information for file series // Information for file series
HashTable<vtk::seriesWriter, fileName> vtkSeries; HashTable<vtk::seriesWriter, fileName> vtkSeries;
wordList regionNames; // Handle -allRegions, -regions, -region
wordRes selectRegions; #include "getAllRegionOptions.H"
if (allRegions)
{
regionNames =
regionProperties(runTime, IOobject::READ_IF_PRESENT).names();
if (regionNames.empty())
{
Info<< "Warning: "
<< "No regionProperties - assuming default region"
<< nl << endl;
regionNames.resize(1);
regionNames.first() = fvMesh::defaultRegion;
}
else
{
Info<< "Using all regions in regionProperties" << nl
<< " "<< flatOutput(regionNames) << nl;
}
}
else if (args.readListIfPresent<wordRe>("regions", selectRegions))
{
if (selectRegions.empty())
{
regionNames.resize(1);
regionNames.first() = fvMesh::defaultRegion;
}
else if
(
selectRegions.size() == 1 && selectRegions.first().isLiteral()
)
{
// Identical to -region NAME
regionNames.resize(1);
regionNames.first() = selectRegions.first();
}
else
{
regionNames =
regionProperties(runTime, IOobject::READ_IF_PRESENT).names();
if (regionNames.empty())
{
Info<< "Warning: "
<< "No regionProperties - assuming default region"
<< nl << endl;
regionNames.resize(1);
regionNames.first() = fvMesh::defaultRegion;
}
else
{
inplaceSubsetStrings(selectRegions, regionNames);
if (regionNames.empty())
{
Info<< "No matching regions ... stopping" << nl << endl;
return 1;
}
Info<< "Using matching regions: "
<< flatOutput(regionNames) << nl;
}
}
}
else
{
regionNames.resize(1);
regionNames.first() =
args.getOrDefault<word>("region", fvMesh::defaultRegion);
}
// Names for sets and zones // Names for sets and zones
word cellSelectionName; word cellSelectionName;
@ -686,13 +600,7 @@ int main(int argc, char *argv[])
} }
} }
// ------------------------------------------------------------------------
cpuTime timer;
memInfo mem;
Info<< "Initial memory " << mem.update().size() << " kB" << endl;
#include "createMeshes.H"
// Directory management // Directory management
// Sub-directory for output // Sub-directory for output
@ -705,29 +613,39 @@ int main(int argc, char *argv[])
// Overwrite or create the VTK/regionName directories. // Overwrite or create the VTK/regionName directories.
// For the default region, this is simply "VTK/" // For the default region, this is simply "VTK/"
fileName regionDir;
for (const word& regionName : regionNames) for (const word& regionName : regionNames)
{ {
if (regionName != polyMesh::defaultRegion) const word& regionDir =
{ (
regionDir = outputDir / regionName; regionName == polyMesh::defaultRegion ? word::null : regionName
} );
else
{
regionDir = outputDir;
}
if (args.found("overwrite") && isDir(regionDir)) fileName regionalDir(outputDir/regionDir);
if (args.found("overwrite") && Foam::isDir(regionalDir))
{ {
Info<< "Removing old directory " Info<< "Removing old directory "
<< args.relativePath(regionDir) << args.relativePath(regionalDir)
<< nl << endl; << nl << endl;
rmDir(regionDir); Foam::rmDir(regionalDir);
} }
mkDir(regionDir); Foam::mkDir(regionalDir);
} }
} }
// ------------------------------------------------------------------------
cpuTime timer;
memInfo mem;
Info<< "Initial memory " << mem.update().size() << " kB" << endl;
#include "createNamedMeshes.H"
#include "createMeshAccounting.H"
Info<< "VTK mesh topology: "
<< timer.cpuTimeIncrement() << " s, "
<< mem.update().size() << " kB" << endl;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -749,11 +667,13 @@ 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 =
fileName regionPrefix; (
if (regionName != polyMesh::defaultRegion) regionName == polyMesh::defaultRegion ? word::null : regionName
);
if (regionNames.size() > 1 || !regionDir.empty())
{ {
regionPrefix = regionName; Info<< "region = " << regionName << nl;
} }
auto& meshProxy = meshProxies[regioni]; auto& meshProxy = meshProxies[regioni];

View File

@ -0,0 +1,45 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Add multi-region command-line options: -allRegions, -regions, -region
See Also
getAllRegionOptions.H
\*---------------------------------------------------------------------------*/
{
Foam::argList::addBoolOption
(
"allRegions",
"Use all regions in regionProperties"
);
Foam::argList::addOption
(
"regions",
"wordRes",
"Use specified mesh region. Eg, -regions gas\n"
"Or from regionProperties. Eg, -regions '(gas \"solid.*\")'"
);
Foam::argList::addOption
(
"region",
"name",
"Use specified mesh region. Eg, -region gas"
);
}
// ************************************************************************* //

View File

@ -1,5 +1,32 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Create a fvMesh (specified region or defaultRegion) with
additional handling of -dry-run and -dry-run-write options.
Required Variables
- args [argList]
- runTime [Time]
Provided Variables
- regionName [word]
- mesh [fvMesh]
- meshPtr [autoPtr<fvMesh>]
\*---------------------------------------------------------------------------*/
Foam::autoPtr<Foam::fvMesh> meshPtr(nullptr); Foam::autoPtr<Foam::fvMesh> meshPtr(nullptr);
Foam::word regionName = Foam::fvMesh::defaultRegion; Foam::word regionName(Foam::polyMesh::defaultRegion);
if (args.found("dry-run") || args.found("dry-run-write")) if (args.found("dry-run") || args.found("dry-run-write"))
{ {
@ -42,16 +69,13 @@ else
{ {
if (args.readIfPresent("region", regionName)) if (args.readIfPresent("region", regionName))
{ {
Foam::Info Foam::Info << "Create mesh " << regionName;
<< "Create mesh " << regionName << " for time = "
<< runTime.timeName() << Foam::nl << Foam::endl;
} }
else else
{ {
Foam::Info Foam::Info << "Create mesh";
<< "Create mesh for time = "
<< runTime.timeName() << Foam::nl << Foam::endl;
} }
Foam::Info << " for time = " << runTime.timeName() << Foam::nl;
meshPtr.reset meshPtr.reset
( (
@ -68,6 +92,11 @@ else
) )
); );
meshPtr().init(true); // initialise all (lower levels and current) meshPtr().init(true); // initialise all (lower levels and current)
Foam::Info << Foam::endl;
} }
Foam::fvMesh& mesh = meshPtr(); Foam::fvMesh& mesh = meshPtr();
// ************************************************************************* //

View File

@ -1,4 +1,29 @@
// Currently identical to createMesh.H /*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Create a fvMesh (defaultRegion)
Required Variables
- runTime [Time]
Provided Variables
- mesh [fvMesh]
Notes
Currently identical to non-dry-run version of createMesh.H
\*---------------------------------------------------------------------------*/
Foam::Info Foam::Info
<< "Create mesh, no clear-out for time = " << "Create mesh, no clear-out for time = "
@ -14,3 +39,6 @@ Foam::fvMesh mesh
Foam::IOobject::MUST_READ Foam::IOobject::MUST_READ
) )
); );
// ************************************************************************* //

View File

@ -1,18 +1,44 @@
Foam::word regionName = Foam::fvMesh::defaultRegion; /*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Create a fvMesh for a specified region, or the defaultRegion
Required Variables
- args [argList]
- runTime [Time]
Provided Variables
- regionName [word]
- mesh [fvMesh]
\*---------------------------------------------------------------------------*/
Foam::word regionName(Foam::polyMesh::defaultRegion);
if (args.readIfPresent("region", regionName))
{ {
Foam::Info if (args.readIfPresent("region", regionName))
<< "Create mesh " << regionName << " for time = " {
<< runTime.timeName() << Foam::nl << Foam::endl; Foam::Info << "Create mesh " << regionName;
} }
else else
{ {
Foam::Info Foam::Info << "Create mesh";
<< "Create mesh for time = " }
<< runTime.timeName() << Foam::nl << Foam::endl; Foam::Info << " for time = " << runTime.timeName() << Foam::nl;
} }
Foam::fvMesh mesh Foam::fvMesh mesh
( (
Foam::IOobject Foam::IOobject
@ -24,4 +50,10 @@ Foam::fvMesh mesh
), ),
false false
); );
mesh.init(true); // initialise all (lower levels and current)
mesh.init(true); // Initialise all (lower levels and current)
Foam::Info << Foam::endl;
// ************************************************************************* //

View File

@ -0,0 +1,73 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Create single or multiple regions based on the wordList 'regionNames'
Required Variables
- runTime [Time]
- regionNames [wordList]
Provided Variables
- meshes [PtrList<fvMesh>]
See Also
addAllRegionOptions.H
getAllRegionOptions.H
\*---------------------------------------------------------------------------*/
Foam::PtrList<Foam::fvMesh> meshes(regionNames.size());
{
forAll(regionNames, regioni)
{
const Foam::word& regionName = regionNames[regioni];
Foam::Info<< "Create mesh";
if
(
regionNames.size() > 1
|| regionName != Foam::polyMesh::defaultRegion
)
{
Foam::Info<< ' ' << regionName;
}
Foam::Info<< " for time = " << runTime.timeName() << Foam::nl;
meshes.set
(
regioni,
new Foam::fvMesh
(
Foam::IOobject
(
regionName,
runTime.timeName(),
runTime,
Foam::IOobject::MUST_READ
),
false // Do not initialise
)
);
}
for (auto& mesh : meshes)
{
mesh.init(true); // Initialise all (lower levels and current)
}
Foam::Info<< Foam::endl;
}
// ************************************************************************* //

View File

@ -1,18 +1,43 @@
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) 2011 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Create a polyMesh for a specified region, or the defaultRegion
Required Variables
- runTime [Time]
Provided Variables
- regionName [word]
- mesh [polyMesh]
\*---------------------------------------------------------------------------*/
Foam::word regionName(Foam::polyMesh::defaultRegion);
if (args.readIfPresent("region", regionName))
{ {
Foam::Info if (args.readIfPresent("region", regionName))
<< "Create polyMesh " << regionName << " for time = " {
<< runTime.timeName() << Foam::nl << Foam::endl; Foam::Info << "Create polyMesh " << regionName;
} }
else else
{ {
Foam::Info Foam::Info << "Create polyMesh";
<< "Create polyMesh for time = " }
<< runTime.timeName() << Foam::nl << Foam::endl; Foam::Info << " for time = " << runTime.timeName() << Foam::nl;
} }
Foam::polyMesh mesh Foam::polyMesh mesh
( (
Foam::IOobject Foam::IOobject
@ -23,3 +48,7 @@ Foam::polyMesh mesh
Foam::IOobject::MUST_READ Foam::IOobject::MUST_READ
) )
); );
Foam::Info << Foam::endl;
// ************************************************************************* //

View File

@ -1,6 +1,30 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Create a polyMesh (defaultRegion only)
Required Variables
- runTime [Time]
Provided Variables
- mesh [polyMesh]
\*---------------------------------------------------------------------------*/
Foam::Info Foam::Info
<< "Create polyMesh for time = " << "Create polyMesh for time = "
<< runTime.timeName() << Foam::nl << Foam::endl; << runTime.timeName() << Foam::nl;
Foam::polyMesh mesh Foam::polyMesh mesh
( (
@ -12,3 +36,7 @@ Foam::polyMesh mesh
Foam::IOobject::MUST_READ Foam::IOobject::MUST_READ
) )
); );
Foam::Info << Foam::endl;
// ************************************************************************* //

View File

@ -0,0 +1,114 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Gets single or multiple region names based on command-line options:
(-allRegions | -regions | -regions)
Priority
1. -allRegions
2. -regions = specify multiple regions to select, or a single region
3. -region = specify a single region
Note
There is no semantical difference between "-regions name"
and "-region name"
Required Variables
- args [argList]
- runTime [Time]
Provides Variables
- regionNames [wordList]
See Also
addAllRegionOptions.H
\*---------------------------------------------------------------------------*/
wordList regionNames;
{
wordRes selectByName;
if (args.found("allRegions"))
{
regionNames =
regionProperties(runTime, IOobject::READ_IF_PRESENT).names();
if (regionNames.empty())
{
InfoErr
<< "Warning: No regionProperties, assume default region"
<< nl << endl;
}
else
{
Info<< "Using all regions: " << flatOutput(regionNames) << nl;
}
}
else if (args.readListIfPresent<wordRe>("regions", selectByName))
{
if
(
selectByName.size() == 1
&& selectByName.first().isLiteral()
)
{
// Identical to -region NAME
regionNames.resize(1);
regionNames.first() = selectByName.first();
}
else if (selectByName.size())
{
regionNames =
regionProperties(runTime, IOobject::READ_IF_PRESENT).names();
if (regionNames.empty())
{
Info<< "Warning: No regionProperties, assume default region"
<< nl << endl;
}
else
{
const labelList matching = selectByName.matching(regionNames);
if (matching.empty())
{
InfoErr
<< "No match in regions: "
<< flatOutput(regionNames) << nl
<< "... stopping" << nl << endl;
return 1;
}
regionNames = wordList(regionNames, matching);
Info<< "Using regions: " << flatOutput(regionNames) << nl;
}
}
}
else if (args.found("region"))
{
regionNames.resize(1);
regionNames.first() = args.get<word>("region");
}
// Fallback to defaultRegion
if (regionNames.empty())
{
regionNames.resize(1);
regionNames.first() = polyMesh::defaultRegion;
}
}
// ************************************************************************* //

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd. Copyright (C) 2017-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -280,11 +280,10 @@ bool Foam::functionObjects::vtkWrite::write()
label regioni = 0; label regioni = 0;
for (const word& regionName : meshes_.sortedToc()) for (const word& regionName : meshes_.sortedToc())
{ {
fileName regionPrefix; const word& regionDir =
if (regionName != polyMesh::defaultRegion) (
{ regionName == polyMesh::defaultRegion ? word::null : regionName
regionPrefix = regionName; );
}
auto& meshProxy = meshSubsets_[regioni]; auto& meshProxy = meshSubsets_[regioni];
auto& vtuMeshCells = vtuMappings_[regioni]; auto& vtuMeshCells = vtuMappings_[regioni];
@ -331,7 +330,7 @@ bool Foam::functionObjects::vtkWrite::write()
fileName vtmOutputBase fileName vtmOutputBase
( (
outputDir_/regionPrefix/vtkName + timeDesc outputDir_/regionDir/vtkName + timeDesc
); );
// Combined internal + boundary in a vtm file // Combined internal + boundary in a vtm file
@ -412,7 +411,7 @@ bool Foam::functionObjects::vtkWrite::write()
// Output name for one patch: "boundary" // Output name for one patch: "boundary"
( (
writeOpts_.legacy() writeOpts_.legacy()
? (outputDir_/regionPrefix/"boundary"/"boundary" + timeDesc) ? (outputDir_/regionDir/"boundary"/"boundary" + timeDesc)
: (vtmOutputBase / "boundary") : (vtmOutputBase / "boundary")
), ),
Pstream::parRun() Pstream::parRun()
@ -464,7 +463,7 @@ bool Foam::functionObjects::vtkWrite::write()
writeOpts_.legacy() writeOpts_.legacy()
? ?
( (
outputDir_/regionPrefix/pp.name() outputDir_/regionDir/pp.name()
/ (pp.name()) + timeDesc / (pp.name()) + timeDesc
) )
: (vtmOutputBase / "boundary" / pp.name()) : (vtmOutputBase / "boundary" / pp.name())
@ -704,7 +703,7 @@ bool Foam::functionObjects::vtkWrite::write()
series.write(seriesName); series.write(seriesName);
// Add to multi-region vtm // Add to multi-region vtm
vtmMultiRegion.add(regionName, regionPrefix, vtmWriter); vtmMultiRegion.add(regionName, regionDir, vtmWriter);
} }
if (vtmBoundaries.size()) if (vtmBoundaries.size())