From e2d140fa948aac0e87bd9b1adcf2d09a63b071ff Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 10 Dec 2008 09:14:00 +0100 Subject: [PATCH] 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 --- applications/test/findTimes/findTimes.C | 5 +- .../reconstructPar/reconstructPar.C | 4 +- .../foamToEnsightParts/foamToEnsightParts.C | 4 +- src/OpenFOAM/db/Time/timeSelector.C | 56 ++++++++----------- src/OpenFOAM/db/Time/timeSelector.H | 18 +++--- 5 files changed, 43 insertions(+), 44 deletions(-) diff --git a/applications/test/findTimes/findTimes.C b/applications/test/findTimes/findTimes.C index 2b59609006..2acc6e756c 100644 --- a/applications/test/findTimes/findTimes.C +++ b/applications/test/findTimes/findTimes.C @@ -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; diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C index 50818f4db9..3b5fca211e 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C @@ -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)\""); diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C index c8a7d89df2..05501a904d 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C @@ -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", ""); diff --git a/src/OpenFOAM/db/Time/timeSelector.C b/src/OpenFOAM/db/Time/timeSelector.C index 9d8e9c33cd..bace90c28a 100644 --- a/src/OpenFOAM/db/Time/timeSelector.C +++ b/src/OpenFOAM/db/Time/timeSelector.C @@ -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::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")) { - // can match 0/, but never constant/ + // can match 0/, but can never match constant/ selectTimes = timeSelector ( IStringStream(args.options()["time"])() ).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/ - 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::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"); } } diff --git a/src/OpenFOAM/db/Time/timeSelector.H b/src/OpenFOAM/db/Time/timeSelector.H index 7d1f15fda1..6afa92ee06 100644 --- a/src/OpenFOAM/db/Time/timeSelector.H +++ b/src/OpenFOAM/db/Time/timeSelector.H @@ -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