decomposePar, reconstructPar: Rationalized the handling of the allRegions option

This commit is contained in:
Henry Weller
2018-05-14 19:51:54 +01:00
parent e57a62b400
commit d0dfb1a843
5 changed files with 99 additions and 119 deletions

View File

@ -218,11 +218,7 @@ int main(int argc, char *argv[])
argList::noParallel(); argList::noParallel();
#include "addRegionOption.H" #include "addRegionOption.H"
argList::addBoolOption #include "addAllRegionsOption.H"
(
"allRegions",
"operate on all regions in regionProperties"
);
argList::addBoolOption argList::addBoolOption
( (
"cellDist", "cellDist",
@ -273,7 +269,6 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
bool region = args.optionFound("region"); bool region = args.optionFound("region");
bool allRegions = args.optionFound("allRegions");
bool writeCellDist = args.optionFound("cellDist"); bool writeCellDist = args.optionFound("cellDist");
bool copyZero = args.optionFound("copyZero"); bool copyZero = args.optionFound("copyZero");
bool copyUniform = args.optionFound("copyUniform"); bool copyUniform = args.optionFound("copyUniform");
@ -310,40 +305,7 @@ int main(int argc, char *argv[])
// Allow override of time // Allow override of time
instantList times = timeSelector::selectIfPresent(runTime, args); instantList times = timeSelector::selectIfPresent(runTime, args);
wordList regionNames; const wordList regionNames(selectRegionNames(args, runTime));
wordList regionDirs;
if (allRegions)
{
Info<< "Decomposing all regions in regionProperties" << nl << endl;
regionProperties rp(runTime);
forAllConstIter(HashTable<wordList>, 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);
}
}
{ {
// Determine the existing processor count directly // Determine the existing processor count directly
@ -416,7 +378,7 @@ 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 = regionDirs[regioni]; const word& regionDir = Foam::regionDir(regionName);
Info<< "\n\nDecomposing mesh " << regionName << nl << endl; Info<< "\n\nDecomposing mesh " << regionName << nl << endl;

View File

@ -49,12 +49,14 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool haveAllTimes namespace Foam
( {
bool haveAllTimes
(
const HashSet<word>& masterTimeDirSet, const HashSet<word>& masterTimeDirSet,
const instantList& timeDirs const instantList& timeDirs
) )
{ {
// Loop over all times // Loop over all times
forAll(timeDirs, timei) forAll(timeDirs, timei)
{ {
@ -64,6 +66,7 @@ bool haveAllTimes
} }
} }
return true; return true;
}
} }
@ -79,11 +82,7 @@ int main(int argc, char *argv[])
timeSelector::addOptions(true, true); timeSelector::addOptions(true, true);
argList::noParallel(); argList::noParallel();
#include "addRegionOption.H" #include "addRegionOption.H"
argList::addBoolOption #include "addAllRegionsOption.H"
(
"allRegions",
"operate on all regions in regionProperties"
);
argList::addOption argList::addOption
( (
"fields", "fields",
@ -169,48 +168,11 @@ int main(int argc, char *argv[])
args.optionLookup("lagrangianFields")() >> selectedLagrangianFields; args.optionLookup("lagrangianFields")() >> selectedLagrangianFields;
} }
const wordList regionNames(selectRegionNames(args, runTime));
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<wordList>, 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);
}
}
// Determine the processor count // Determine the processor count
label nProcs = fileHandler().nProcs(args.path(), regionDirs[0]); const label nProcs =
fileHandler().nProcs(args.path(), regionDir(regionNames[0]));
if (!nProcs) if (!nProcs)
{ {
@ -253,26 +215,37 @@ int main(int argc, char *argv[])
// - can be illogical // - can be illogical
// + any point motion handled through mesh.readUpdate // + any point motion handled through mesh.readUpdate
if (timeDirs.empty()) if (timeDirs.empty())
{ {
WarningInFunction << "No times selected"; WarningInFunction << "No times selected" << endl;
exit(1); exit(1);
} }
// Get current times if -newTimes // Get current times if -newTimes
const bool newTimes = args.optionFound("newTimes");
instantList masterTimeDirs; instantList masterTimeDirs;
if (newTimes) if (newTimes)
{ {
masterTimeDirs = runTime.times(); masterTimeDirs = runTime.times();
} }
HashSet<word> masterTimeDirSet(2*masterTimeDirs.size()); HashSet<word> masterTimeDirSet(2*masterTimeDirs.size());
forAll(masterTimeDirs, i) forAll(masterTimeDirs, i)
{ {
masterTimeDirSet.insert(masterTimeDirs[i].name()); 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 // Set all times on processor meshes equal to reconstructed mesh
forAll(databases, proci) forAll(databases, proci)
@ -280,30 +253,14 @@ int main(int argc, char *argv[])
databases[proci].setTime(runTime); databases[proci].setTime(runTime);
} }
forAll(regionNames, regioni) forAll(regionNames, regioni)
{ {
const word& regionName = 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 Info<< "\n\nReconstructing fields for mesh " << regionName << nl
<< endl; << 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 fvMesh mesh
( (
IOobject IOobject
@ -311,7 +268,7 @@ int main(int argc, char *argv[])
regionName, regionName,
runTime.timeName(), runTime.timeName(),
runTime, runTime,
Foam::IOobject::MUST_READ IOobject::MUST_READ
) )
); );

View File

@ -0,0 +1,5 @@
Foam::argList::addBoolOption
(
"allRegions",
"operate on all regions in regionProperties"
);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,6 +25,8 @@ License
#include "regionProperties.H" #include "regionProperties.H"
#include "IOdictionary.H" #include "IOdictionary.H"
#include "argList.H"
#include "polyMesh.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * 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<wordList>, 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;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -76,6 +76,11 @@ public:
}; };
const word& regionDir(const word& regionName);
wordList selectRegionNames(const argList& args, const Time& runTime);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam