From c410edf928b4c3bb58189eba01faa8079da06149 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 5 May 2021 14:18:55 +0200 Subject: [PATCH] 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 meshes` STYLE: add description to some central include files --- .../Test-checkDecomposePar.C | 39 ++--- .../test/decomposePar/Test-decomposePar.C | 35 ++--- .../decomposePar/decomposePar.C | 45 +++--- .../reconstructPar/reconstructPar.C | 41 ++--- .../redistributePar/redistributePar.C | 32 ++-- .../foamToEnsight/convertLagrangian.H | 4 +- .../foamToEnsight/findCloudFields.H | 2 +- .../foamToEnsight/foamToEnsight.C | 12 +- .../foamToVTK/convertAreaFields.H | 4 +- .../foamToVTK/convertLagrangian.H | 6 +- .../foamToVTK/convertProcessorPatches.H | 4 +- .../foamToVTK/convertSurfaceFields.H | 6 +- .../dataConversion/foamToVTK/convertTopoSet.H | 6 +- .../foamToVTK/convertVolumeFields.H | 10 +- .../foamToVTK/createMeshAccounting.H | 46 ++++++ .../dataConversion/foamToVTK/createMeshes.H | 58 ------- .../dataConversion/foamToVTK/foamToVTK.C | 148 ++++-------------- src/OpenFOAM/include/addAllRegionOptions.H | 45 ++++++ src/OpenFOAM/include/createMesh.H | 43 ++++- src/OpenFOAM/include/createMeshNoClear.H | 30 +++- src/OpenFOAM/include/createNamedMesh.H | 56 +++++-- src/OpenFOAM/include/createNamedMeshes.H | 73 +++++++++ src/OpenFOAM/include/createNamedPolyMesh.H | 51 ++++-- src/OpenFOAM/include/createPolyMesh.H | 30 +++- src/OpenFOAM/include/getAllRegionOptions.H | 114 ++++++++++++++ .../utilities/vtkWrite/vtkWrite.C | 19 ++- 26 files changed, 595 insertions(+), 364 deletions(-) create mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/createMeshAccounting.H delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/createMeshes.H create mode 100644 src/OpenFOAM/include/addAllRegionOptions.H create mode 100644 src/OpenFOAM/include/createNamedMeshes.H create mode 100644 src/OpenFOAM/include/getAllRegionOptions.H diff --git a/applications/test/checkDecomposePar/Test-checkDecomposePar.C b/applications/test/checkDecomposePar/Test-checkDecomposePar.C index 41e46a9cf6..52ca8f9961 100644 --- a/applications/test/checkDecomposePar/Test-checkDecomposePar.C +++ b/applications/test/checkDecomposePar/Test-checkDecomposePar.C @@ -55,12 +55,8 @@ int main(int argc, char *argv[]) argList::noParallel(); argList::noBanner(); - #include "addRegionOption.H" - argList::addBoolOption - ( - "allRegions", - "operate on all regions in regionProperties" - ); + #include "addAllRegionOptions.H" + argList::addBoolOption ( "verbose", @@ -76,11 +72,11 @@ int main(int argc, char *argv[]) const auto decompFile = args.get(1); const bool region = args.found("region"); - const bool allRegions = args.found("allRegions"); const bool verbose = args.found("verbose"); // Set time from database #include "createTime.H" + // Allow override of time instantList times = timeSelector::selectIfPresent(runTime, args); @@ -88,31 +84,18 @@ int main(int argc, char *argv[]) const fileName decompDictFile = args.getOrDefault("decomposeParDict", ""); - wordList regionNames; - wordList regionDirs; - if (allRegions) + // Get region names + #include "getAllRegionOptions.H" + + wordList regionDirs(regionNames); + if (regionDirs.size() == 1 && regionDirs[0] == polyMesh::defaultRegion) { - Info<< "Decomposing all regions in regionProperties" << nl << endl; - regionProperties rp(runTime); - forAllConstIters(rp, iter) - { - const wordList& regions = iter(); - forAll(regions, i) - { - regionNames.appendUniq(regions[i]); - } - } - regionDirs = regionNames; + regionDirs[0].clear(); } else { - regionNames.resize(1, fvMesh::defaultRegion); - regionDirs.resize(1, word::null); - - if (args.readIfPresent("region", regionNames.first())) - { - regionDirs.first() = regionNames.first(); - } + Info<< "Decomposing regions: " + << flatOutput(regionNames) << nl << endl; } labelList cellToProc; diff --git a/applications/test/decomposePar/Test-decomposePar.C b/applications/test/decomposePar/Test-decomposePar.C index 2192f1007d..d94e29df39 100644 --- a/applications/test/decomposePar/Test-decomposePar.C +++ b/applications/test/decomposePar/Test-decomposePar.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -62,12 +62,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 ( "verbose", @@ -107,7 +104,6 @@ int main(int argc, char *argv[]) #include "setRootCase.H" const bool optRegion = args.found("region"); - const bool allRegions = args.found("allRegions"); const bool verbose = args.found("verbose"); const label numSubdomains = args.getOrDefault