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

@ -49,21 +49,24 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool haveAllTimes
(
const HashSet<word>& masterTimeDirSet,
const instantList& timeDirs
)
namespace Foam
{
// Loop over all times
forAll(timeDirs, timei)
bool haveAllTimes
(
const HashSet<word>& 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<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);
}
}
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<word> 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
)
);