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
This commit is contained in:
Mark Olesen
2008-12-10 09:14:00 +01:00
parent 31e1b1ba0e
commit e2d140fa94
5 changed files with 43 additions and 44 deletions

View File

@ -38,14 +38,15 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
argList::noParallel(); argList::noParallel();
Foam::timeSelector::addOptions(); // timeSelector::addOptions();
timeSelector::addOptions(true, true);
# include "setRootCase.H" # include "setRootCase.H"
# include "createTime.H" # include "createTime.H"
Info<< "Times found:" << runTime.times() << endl; 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<< "Times selected:" << timeDirs << endl;
Info<< "\nEnd\n" << endl; Info<< "\nEnd\n" << endl;

View File

@ -45,8 +45,10 @@ Description
int main(int argc, char *argv[]) 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(); argList::noParallel();
timeSelector::addOptions();
# include "addRegionOption.H" # include "addRegionOption.H"
argList::validOptions.insert("fields", "\"(list of fields)\""); argList::validOptions.insert("fields", "\"(list of fields)\"");

View File

@ -74,7 +74,9 @@ using namespace Foam;
int main(int argc, char *argv[]) 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); timeSelector::addOptions(true, false);
argList::noParallel(); argList::noParallel();
argList::validOptions.insert("ascii", ""); argList::validOptions.insert("ascii", "");

View File

@ -131,9 +131,8 @@ void Foam::timeSelector::addOptions
argList::validOptions.insert("zeroTime", ""); argList::validOptions.insert("zeroTime", "");
} }
argList::validOptions.insert("noZero", ""); argList::validOptions.insert("noZero", "");
argList::validOptions.insert("time", "time"); argList::validOptions.insert("time", "ranges");
argList::validOptions.insert("latestTime", ""); argList::validOptions.insert("latestTime", "");
argList::validOptions.insert("latestTime0", "");
} }
@ -168,35 +167,35 @@ Foam::List<Foam::instant> Foam::timeSelector::select
} }
} }
// determine latestTime selection (if any)
// this must appear before the -time option processing
label latestIdx = -1;
if (args.options().found("latestTime"))
{
selectTimes = false;
latestIdx = timeDirs.size() - 1;
// avoid false match on constant/
if (latestIdx == constantIdx)
{
latestIdx = -1;
}
}
if (args.options().found("time")) if (args.options().found("time"))
{ {
// can match 0/, but never constant/ // can match 0/, but can never match constant/
selectTimes = timeSelector selectTimes = timeSelector
( (
IStringStream(args.options()["time"])() IStringStream(args.options()["time"])()
).selected(timeDirs); ).selected(timeDirs);
} }
else if (args.options().found("latestTime0"))
{
selectTimes = false;
const label latestIdx = timeDirs.size() - 1;
// avoid false match on constant/
if (latestIdx != constantIdx)
{
selectTimes[latestIdx] = true;
}
}
else if (args.options().found("latestTime"))
{
selectTimes = false;
const label latestIdx = timeDirs.size() - 1;
// avoid false match on constant/ or 0/ // add in latestTime (if selected)
if (latestIdx != constantIdx && latestIdx != zeroIdx) if (latestIdx >= 0)
{ {
selectTimes[latestIdx] = true; selectTimes[latestIdx] = true;
}
} }
if (constantIdx >= 0) if (constantIdx >= 0)
@ -215,17 +214,8 @@ Foam::List<Foam::instant> Foam::timeSelector::select
} }
else if (argList::validOptions.found("zeroTime")) else if (argList::validOptions.found("zeroTime"))
{ {
// with -zeroTime enabled // with -zeroTime enabled, drop 0/ unless specifically requested
if (args.options().found("zeroTime")) selectTimes[zeroIdx] = 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");
}
} }
} }

View File

@ -60,8 +60,9 @@ Description
@endverbatim @endverbatim
The first argument avoids adding the @b -constant option. The second The first argument avoids adding the @b -constant option. The second
argument adds an additional @b -zeroTime option and prevents the @c 0/ argument adds an additional @b -zeroTime option and also prevents the
directory from being included in the default time range. @c 0/ directory from being included in the default time range and in the
@b -latestTime selection.
SourceFiles SourceFiles
timeSelector.C timeSelector.C
@ -121,14 +122,17 @@ public:
// //
// @param constant // @param constant
// Add the @b -constant option to include the @c constant/ directory // Add the @b -constant option to include the @c constant/ directory
//
// @param zeroTime // @param zeroTime
// Additional to the @b -noZero option (explicitly exclude the // Enable the @b -zeroTime option and alter the normal time selection
// @c 0/ directory), add the @b -zeroTime option to include the // behaviour (and @b -latestTime behaviour) to exclude the @c 0/
// @c 0/ directory. The @b -noZero option has precedence. // 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 static void addOptions
( (
const bool constant = true, const bool constant=true,
const bool zeroTime = false const bool zeroTime=false
); );
//- Return the set of times selected based on the argList options //- Return the set of times selected based on the argList options