timeSelector - handle cases with missing constant/ or 0/ directories

This commit is contained in:
Mark Olesen
2008-12-02 15:55:51 +01:00
parent 507e7a1b98
commit a13f97d59d
2 changed files with 49 additions and 26 deletions

View File

@ -28,6 +28,7 @@ Description
#include "argList.H" #include "argList.H"
#include "Time.H" #include "Time.H"
#include "timeSelector.H"
using namespace Foam; using namespace Foam;
@ -36,13 +37,18 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
argList::noParallel();
Foam::timeSelector::addOptions();
# include "setRootCase.H" # include "setRootCase.H"
# include "createTime.H" # include "createTime.H"
Info<< runTime.times() << endl; Info<< "Times found:" << runTime.times() << endl;
Info << "End\n" << endl; instantList timeDirs = Foam::timeSelector::select0(runTime, args);
Info<< "Times selected:" << timeDirs << endl;
Info<< "\nEnd\n" << endl;
return 0; return 0;
} }

View File

@ -56,22 +56,12 @@ Foam::List<bool> Foam::timeSelector::selected(const List<instant>& Times) const
{ {
List<bool> lst(Times.size(), false); List<bool> lst(Times.size(), false);
// check ranges // check ranges, avoid false positive on constant/
forAll(Times, i) forAll(Times, timeI)
{ {
if (selected(Times[i])) if (Times[timeI].name() != "constant" && selected(Times[timeI]))
{ {
lst[i] = true; lst[timeI] = true;
}
}
// avoid false positive on "constant"
forAll(Times, i)
{
if (Times[i].name() == "constant")
{
lst[i] = false;
break;
} }
} }
@ -85,15 +75,15 @@ Foam::List<bool> Foam::timeSelector::selected(const List<instant>& Times) const
int nearestIndex = -1; int nearestIndex = -1;
scalar nearestDiff = Foam::GREAT; scalar nearestDiff = Foam::GREAT;
forAll(Times, timeIndex) forAll(Times, timeI)
{ {
if (Times[timeIndex].name() == "constant") continue; if (Times[timeI].name() == "constant") continue;
scalar diff = fabs(Times[timeIndex].value() - target); scalar diff = fabs(Times[timeI].value() - target);
if (diff < nearestDiff) if (diff < nearestDiff)
{ {
nearestDiff = diff; nearestDiff = diff;
nearestIndex = timeIndex; nearestIndex = timeI;
} }
} }
@ -156,6 +146,27 @@ Foam::List<Foam::instant> Foam::timeSelector::select
{ {
List<bool> selectTimes(timeDirs.size(), true); List<bool> selectTimes(timeDirs.size(), true);
// determine locations of constant/ and 0/ directories
label constantIdx = -1;
label zeroIdx = -1;
forAll(timeDirs, timeI)
{
if (timeDirs[timeI].name() == "constant")
{
constantIdx = timeI;
}
else if (timeDirs[timeI].value() == 0)
{
zeroIdx = timeI;
}
if (constantIdx >= 0 && zeroIdx >= 0)
{
break;
}
}
if (args.options().found("time")) if (args.options().found("time"))
{ {
selectTimes = timeSelector selectTimes = timeSelector
@ -166,25 +177,31 @@ Foam::List<Foam::instant> Foam::timeSelector::select
else if (args.options().found("latestTime")) else if (args.options().found("latestTime"))
{ {
selectTimes = false; selectTimes = false;
const label latestIdx = timeDirs.size() - 1;
// avoid false match on constant/ or 0/ // avoid false match on constant/ or 0/
if (timeDirs.size() > 2) if (latestIdx != constantIdx && latestIdx != zeroIdx)
{ {
selectTimes[timeDirs.size() - 1] = true; selectTimes[latestIdx] = true;
} }
} }
if (timeDirs.size() > 1) // special treatment for constant/
if (constantIdx >= 0)
{ {
selectTimes[0] = args.options().found("constant"); selectTimes[constantIdx] = args.options().found("constant");
}
// special treatment for 0/
if (zeroIdx >= 0)
{
if (args.options().found("noZero")) if (args.options().found("noZero"))
{ {
selectTimes[1] = false; selectTimes[zeroIdx] = false;
} }
else if (argList::validOptions.found("zeroTime")) else if (argList::validOptions.found("zeroTime"))
{ {
selectTimes[1] = args.options().found("zeroTime"); selectTimes[zeroIdx] = args.options().found("zeroTime");
} }
} }