From d0dfb1a8439d867ad19d2f5b82c1f9d3fbc1d152 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Mon, 14 May 2018 19:51:54 +0100 Subject: [PATCH] decomposePar, reconstructPar: Rationalized the handling of the allRegions option --- .../decomposePar/decomposePar.C | 44 +------ .../reconstructPar/reconstructPar.C | 109 ++++++------------ src/OpenFOAM/include/addAllRegionsOption.H | 5 + .../regionProperties/regionProperties.C | 53 ++++++++- .../regionProperties/regionProperties.H | 7 +- 5 files changed, 99 insertions(+), 119 deletions(-) create mode 100644 src/OpenFOAM/include/addAllRegionsOption.H diff --git a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C index 4dd6568a8..92e2950f5 100644 --- a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C +++ b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C @@ -218,11 +218,7 @@ int main(int argc, char *argv[]) argList::noParallel(); #include "addRegionOption.H" - argList::addBoolOption - ( - "allRegions", - "operate on all regions in regionProperties" - ); + #include "addAllRegionsOption.H" argList::addBoolOption ( "cellDist", @@ -273,7 +269,6 @@ int main(int argc, char *argv[]) #include "setRootCase.H" bool region = args.optionFound("region"); - bool allRegions = args.optionFound("allRegions"); bool writeCellDist = args.optionFound("cellDist"); bool copyZero = args.optionFound("copyZero"); bool copyUniform = args.optionFound("copyUniform"); @@ -310,40 +305,7 @@ int main(int argc, char *argv[]) // Allow override of time instantList times = timeSelector::selectIfPresent(runTime, args); - wordList regionNames; - wordList regionDirs; - if (allRegions) - { - Info<< "Decomposing all regions in regionProperties" << nl << endl; - regionProperties rp(runTime); - forAllConstIter(HashTable, rp, iter) - { - const wordList& regions = iter(); - forAll(regions, i) - { - if (findIndex(regionNames, regions[i]) == -1) - { - regionNames.append(regions[i]); - } - } - } - regionDirs = regionNames; - } - else - { - word regionName; - if (args.optionReadIfPresent("region", regionName)) - { - regionNames = wordList(1, regionName); - regionDirs = regionNames; - } - else - { - regionNames = wordList(1, fvMesh::defaultRegion); - regionDirs = wordList(1, word::null); - } - } - + const wordList regionNames(selectRegionNames(args, runTime)); { // Determine the existing processor count directly @@ -416,7 +378,7 @@ int main(int argc, char *argv[]) forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = regionDirs[regioni]; + const word& regionDir = Foam::regionDir(regionName); Info<< "\n\nDecomposing mesh " << regionName << nl << endl; diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C index 9fafcc1a5..c51e5842b 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C @@ -49,21 +49,24 @@ Description // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -bool haveAllTimes -( - const HashSet& masterTimeDirSet, - const instantList& timeDirs -) +namespace Foam { - // Loop over all times - forAll(timeDirs, timei) + bool haveAllTimes + ( + const HashSet& masterTimeDirSet, + const instantList& timeDirs + ) { - if (!masterTimeDirSet.found(timeDirs[timei].name())) + // Loop over all times + forAll(timeDirs, timei) { - return false; + if (!masterTimeDirSet.found(timeDirs[timei].name())) + { + return false; + } } + return true; } - return true; } @@ -79,11 +82,7 @@ int main(int argc, char *argv[]) timeSelector::addOptions(true, true); argList::noParallel(); #include "addRegionOption.H" - argList::addBoolOption - ( - "allRegions", - "operate on all regions in regionProperties" - ); + #include "addAllRegionsOption.H" argList::addOption ( "fields", @@ -169,48 +168,11 @@ int main(int argc, char *argv[]) args.optionLookup("lagrangianFields")() >> selectedLagrangianFields; } - - const bool newTimes = args.optionFound("newTimes"); - const bool allRegions = args.optionFound("allRegions"); - - - wordList regionNames; - wordList regionDirs; - if (allRegions) - { - Info<< "Reconstructing for all regions in regionProperties" << nl - << endl; - regionProperties rp(runTime); - forAllConstIter(HashTable, rp, iter) - { - const wordList& regions = iter(); - forAll(regions, i) - { - if (findIndex(regionNames, regions[i]) == -1) - { - regionNames.append(regions[i]); - } - } - } - regionDirs = regionNames; - } - else - { - word regionName; - if (args.optionReadIfPresent("region", regionName)) - { - regionNames = wordList(1, regionName); - regionDirs = regionNames; - } - else - { - regionNames = wordList(1, fvMesh::defaultRegion); - regionDirs = wordList(1, word::null); - } - } + const wordList regionNames(selectRegionNames(args, runTime)); // Determine the processor count - label nProcs = fileHandler().nProcs(args.path(), regionDirs[0]); + const label nProcs = + fileHandler().nProcs(args.path(), regionDir(regionNames[0])); if (!nProcs) { @@ -253,26 +215,37 @@ int main(int argc, char *argv[]) // - can be illogical // + any point motion handled through mesh.readUpdate - if (timeDirs.empty()) { - WarningInFunction << "No times selected"; + WarningInFunction << "No times selected" << endl; exit(1); } - // Get current times if -newTimes + const bool newTimes = args.optionFound("newTimes"); instantList masterTimeDirs; if (newTimes) { masterTimeDirs = runTime.times(); } + HashSet masterTimeDirSet(2*masterTimeDirs.size()); forAll(masterTimeDirs, i) { masterTimeDirSet.insert(masterTimeDirs[i].name()); } + if + ( + newTimes + && regionNames.size() == 1 + && regionNames[0] == fvMesh::defaultRegion + && haveAllTimes(masterTimeDirSet, timeDirs) + ) + { + Info<< "All times already reconstructed.\n\nEnd\n" << endl; + return 0; + } // Set all times on processor meshes equal to reconstructed mesh forAll(databases, proci) @@ -280,30 +253,14 @@ int main(int argc, char *argv[]) databases[proci].setTime(runTime); } - forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = regionDirs[regioni]; + const word& regionDir = Foam::regionDir(regionName); Info<< "\n\nReconstructing fields for mesh " << regionName << nl << endl; - if - ( - newTimes - && regionNames.size() == 1 - && regionDirs[0].empty() - && haveAllTimes(masterTimeDirSet, timeDirs) - ) - { - Info<< "Skipping region " << regionName - << " since already have all times" - << endl << endl; - continue; - } - - fvMesh mesh ( IOobject @@ -311,7 +268,7 @@ int main(int argc, char *argv[]) regionName, runTime.timeName(), runTime, - Foam::IOobject::MUST_READ + IOobject::MUST_READ ) ); diff --git a/src/OpenFOAM/include/addAllRegionsOption.H b/src/OpenFOAM/include/addAllRegionsOption.H new file mode 100644 index 000000000..31a1e01ef --- /dev/null +++ b/src/OpenFOAM/include/addAllRegionsOption.H @@ -0,0 +1,5 @@ +Foam::argList::addBoolOption +( + "allRegions", + "operate on all regions in regionProperties" +); diff --git a/src/regionModels/regionModel/regionProperties/regionProperties.C b/src/regionModels/regionModel/regionProperties/regionProperties.C index 7a7d6a646..06fb15251 100644 --- a/src/regionModels/regionModel/regionProperties/regionProperties.C +++ b/src/regionModels/regionModel/regionProperties/regionProperties.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,8 @@ License #include "regionProperties.H" #include "IOdictionary.H" +#include "argList.H" +#include "polyMesh.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -53,4 +55,53 @@ Foam::regionProperties::~regionProperties() {} +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +const Foam::word& Foam::regionDir(const word& regionName) +{ + return + regionName == polyMesh::defaultRegion + ? word::null + : regionName; +} + + +Foam::wordList Foam::selectRegionNames(const argList& args, const Time& runTime) +{ + const bool allRegions = args.optionFound("allRegions"); + + wordList regionNames; + + if (allRegions) + { + const regionProperties rp(runTime); + forAllConstIter(HashTable, rp, iter) + { + const wordList& regions = iter(); + forAll(regions, i) + { + if (findIndex(regionNames, regions[i]) == -1) + { + regionNames.append(regions[i]); + } + } + } + } + else + { + word regionName; + if (args.optionReadIfPresent("region", regionName)) + { + regionNames = wordList(1, regionName); + } + else + { + regionNames = wordList(1, polyMesh::defaultRegion); + } + } + + return regionNames; +} + + // ************************************************************************* // diff --git a/src/regionModels/regionModel/regionProperties/regionProperties.H b/src/regionModels/regionModel/regionProperties/regionProperties.H index 937285ace..1b62807f9 100644 --- a/src/regionModels/regionModel/regionProperties/regionProperties.H +++ b/src/regionModels/regionModel/regionProperties/regionProperties.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -76,6 +76,11 @@ public: }; +const word& regionDir(const word& regionName); + +wordList selectRegionNames(const argList& args, const Time& runTime); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam