Commit e2d140fa authored by Mark Olesen's avatar Mark Olesen
Browse files

timeSelector: improved functionality

- the improved side-effect of enabling -zeroTimea alters default selection
  behaviour and -latestTime selection behaviour for utilities in which
  accidentally using the 0/ directory can cause damage (eg, reconstructPar)
- can combine -time ranges and -latestTime
parent 31e1b1ba
......@@ -38,14 +38,15 @@ using namespace Foam;
int main(int argc, char *argv[])
{
argList::noParallel();
Foam::timeSelector::addOptions();
// timeSelector::addOptions();
timeSelector::addOptions(true, true);
# include "setRootCase.H"
# include "createTime.H"
Info<< "Times found:" << runTime.times() << endl;
instantList timeDirs = Foam::timeSelector::select0(runTime, args);
instantList timeDirs = timeSelector::select0(runTime, args);
Info<< "Times selected:" << timeDirs << endl;
Info<< "\nEnd\n" << endl;
......
......@@ -45,8 +45,10 @@ Description
int main(int argc, char *argv[])
{
// enable -constant ... if someone really wants it
// enable -zeroTime to prevent accidentally trashing the initial fields
timeSelector::addOptions(true, true);
argList::noParallel();
timeSelector::addOptions();
# include "addRegionOption.H"
argList::validOptions.insert("fields", "\"(list of fields)\"");
......
......@@ -74,7 +74,9 @@ using namespace Foam;
int main(int argc, char *argv[])
{
// with -constant and -zeroTime
// enable -constant
// probably don't need -zeroTime though, since the fields are vetted
// afterwards anyhow
timeSelector::addOptions(true, false);
argList::noParallel();
argList::validOptions.insert("ascii", "");
......
......@@ -131,9 +131,8 @@ void Foam::timeSelector::addOptions
argList::validOptions.insert("zeroTime", "");
}
argList::validOptions.insert("noZero", "");
argList::validOptions.insert("time", "time");
argList::validOptions.insert("time", "ranges");
argList::validOptions.insert("latestTime", "");
argList::validOptions.insert("latestTime0", "");
}
......@@ -168,35 +167,35 @@ Foam::List<Foam::instant> Foam::timeSelector::select
}
}
if (args.options().found("time"))
{
// can match 0/, but never constant/
selectTimes = timeSelector
(
IStringStream(args.options()["time"])()
).selected(timeDirs);
}
else if (args.options().found("latestTime0"))
// determine latestTime selection (if any)
// this must appear before the -time option processing
label latestIdx = -1;
if (args.options().found("latestTime"))
{
selectTimes = false;
const label latestIdx = timeDirs.size() - 1;
latestIdx = timeDirs.size() - 1;
// avoid false match on constant/
if (latestIdx != constantIdx)
if (latestIdx == constantIdx)
{
selectTimes[latestIdx] = true;
latestIdx = -1;
}
}
else if (args.options().found("latestTime"))
if (args.options().found("time"))
{
selectTimes = false;
const label latestIdx = timeDirs.size() - 1;
// can match 0/, but can never match constant/
selectTimes = timeSelector
(
IStringStream(args.options()["time"])()
).selected(timeDirs);
}
// avoid false match on constant/ or 0/
if (latestIdx != constantIdx && latestIdx != zeroIdx)
{
selectTimes[latestIdx] = true;
}
// add in latestTime (if selected)
if (latestIdx >= 0)
{
selectTimes[latestIdx] = true;
}
if (constantIdx >= 0)
......@@ -215,17 +214,8 @@ Foam::List<Foam::instant> Foam::timeSelector::select
}
else if (argList::validOptions.found("zeroTime"))
{
// with -zeroTime enabled
if (args.options().found("zeroTime"))
{
// include 0/ if specifically requested
selectTimes[zeroIdx] = true;
}
else
{
// normally drop 0/, except with -latestTime0 option
selectTimes[zeroIdx] = args.options().found("latestTime0");
}
// with -zeroTime enabled, drop 0/ unless specifically requested
selectTimes[zeroIdx] = args.options().found("zeroTime");
}
}
......
......@@ -60,8 +60,9 @@ Description
@endverbatim
The first argument avoids adding the @b -constant option. The second
argument adds an additional @b -zeroTime option and prevents the @c 0/
directory from being included in the default time range.
argument adds an additional @b -zeroTime option and also prevents the
@c 0/ directory from being included in the default time range and in the
@b -latestTime selection.
SourceFiles
timeSelector.C
......@@ -121,14 +122,17 @@ public:
//
// @param constant
// Add the @b -constant option to include the @c constant/ directory
//
// @param zeroTime
// Additional to the @b -noZero option (explicitly exclude the
// @c 0/ directory), add the @b -zeroTime option to include the
// @c 0/ directory. The @b -noZero option has precedence.
// Enable the @b -zeroTime option and alter the normal time selection
// behaviour (and @b -latestTime behaviour) to exclude the @c 0/
// directory. The @c 0/ directory will only be included when
// @b -zeroTime is specified.
// The @b -noZero option has precedence over the @b -zeroTime option.
static void addOptions
(
const bool constant = true,
const bool zeroTime = false
const bool constant=true,
const bool zeroTime=false
);
//- Return the set of times selected based on the argList options
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment