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

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2018 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
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
timeSelector::addOptions(true, true); // constant(true), zero(true)
argList::noParallel();
#include "addRegionOption.H"
argList::addBoolOption
(
"allRegions",
"Operate on all regions in regionProperties"
);
#include "addAllRegionOptions.H"
argList::addOption
(
"fields",
@ -171,30 +168,24 @@ int main(int argc, char *argv[])
}
const bool newTimes = args.found("newTimes");
const bool allRegions = args.found("allRegions");
wordList regionNames;
wordList regionDirs;
if (allRegions)
// Get region names
#include "getAllRegionOptions.H"
wordList regionDirs(regionNames);
if (regionNames.size() == 1)
{
regionNames = regionProperties(runTime).names();
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()))
if (regionNames[0] == polyMesh::defaultRegion)
{
regionDirs.first() = regionNames.first();
regionDirs[0].clear();
}
else
{
Info<< "Using region: " << regionNames[0] << nl << endl;
}
}
// Determine the processor count
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 -zeroTime to prevent accidentally trashing the initial fields
timeSelector::addOptions(true, true);
#include "addRegionOption.H"
argList::addBoolOption
(
"allRegions",
"operate on all regions in regionProperties"
);
#include "addAllRegionOptions.H"
#include "addOverwriteOption.H"
argList::addBoolOption("decompose", "Decompose case");
argList::addBoolOption("reconstruct", "Reconstruct case");
@ -2506,20 +2503,12 @@ int main(int argc, char *argv[])
const fileName decompDictFile =
args.getOrDefault<fileName>("decomposeParDict", "");
// Get all region names
wordList regionNames;
if (args.found("allRegions"))
{
regionNames = regionProperties(runTime).names();
// Get region names
#include "getAllRegionOptions.H"
Info<< "Decomposing all regions in regionProperties" << nl
<< " " << flatOutput(regionNames) << nl << endl;
}
else
if (regionNames.size() == 1 && regionNames[0] != polyMesh::defaultRegion)
{
regionNames.resize(1);
regionNames.first() =
args.getOrDefault<word>("region", fvMesh::defaultRegion);
Info<< "Using region: " << regionNames[0] << nl << endl;
}
@ -2553,12 +2542,11 @@ int main(int argc, char *argv[])
forAll(regionNames, regioni)
{
const word& regionName = regionNames[regioni];
const fileName meshSubDir
const word& regionDir =
(
regionName == fvMesh::defaultRegion
? fileName(polyMesh::meshSubDir)
: regionNames[regioni]/polyMesh::meshSubDir
regionName == polyMesh::defaultRegion ? word::null : regionName
);
const fileName meshSubDir(regionDir/polyMesh::meshSubDir);
Info<< "\n\nReconstructing mesh " << regionName << nl << endl;