From 5c6203309bc96ef5d9ac6711027f17ba0a41afc6 Mon Sep 17 00:00:00 2001 From: Henry Weller <http://cfd.direct> Date: Wed, 24 Jun 2015 10:04:29 +0100 Subject: [PATCH] timeSelector: Add support for -newTimes option //- Return the set of times selected based on the argList options // including support for \b -newTimes in which times are selected // if the file <fName> does not exist in the time directory. // Also set the runTime to the first instance or the // \c constant/ directory if no instances are specified or available static instantList select ( Time& runTime, const argList& args, const word& fName ); This is experimental functionality and currently on test in the yPlus post-processing utility. --- .../postProcessing/wall/yPlus/yPlus.C | 2 +- src/OpenFOAM/db/Time/timeSelector.C | 52 ++++++++++++++++--- src/OpenFOAM/db/Time/timeSelector.H | 12 +++++ 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/applications/utilities/postProcessing/wall/yPlus/yPlus.C b/applications/utilities/postProcessing/wall/yPlus/yPlus.C index 775e79bc6ef..5adf65869f8 100644 --- a/applications/utilities/postProcessing/wall/yPlus/yPlus.C +++ b/applications/utilities/postProcessing/wall/yPlus/yPlus.C @@ -191,7 +191,7 @@ int main(int argc, char *argv[]) #include "setRootCase.H" #include "createTime.H" - instantList timeDirs = timeSelector::select0(runTime, args); + instantList timeDirs = timeSelector::select(runTime, args, "yPlus"); #include "createNamedMesh.H" const bool compressible = args.optionFound("compressible"); diff --git a/src/OpenFOAM/db/Time/timeSelector.C b/src/OpenFOAM/db/Time/timeSelector.C index 61f3d9a6434..5b66e7a2640 100644 --- a/src/OpenFOAM/db/Time/timeSelector.C +++ b/src/OpenFOAM/db/Time/timeSelector.C @@ -97,7 +97,7 @@ Foam::List<bool> Foam::timeSelector::selected(const instantList& Times) const } -Foam::List<Foam::instant> Foam::timeSelector::select(const instantList& Times) +Foam::instantList Foam::timeSelector::select(const instantList& Times) const { return subset(selected(Times), Times); @@ -143,6 +143,11 @@ void Foam::timeSelector::addOptions "latestTime", "select the latest time" ); + argList::addBoolOption + ( + "newTimes", + "select the new times" + ); argList::addOption ( "time", @@ -152,7 +157,7 @@ void Foam::timeSelector::addOptions } -Foam::List<Foam::instant> Foam::timeSelector::select +Foam::instantList Foam::timeSelector::select ( const instantList& timeDirs, const argList& args, @@ -244,17 +249,20 @@ Foam::List<Foam::instant> Foam::timeSelector::select } -Foam::List<Foam::instant> Foam::timeSelector::select0 +Foam::instantList Foam::timeSelector::select0 ( Time& runTime, const argList& args ) { - instantList timeDirs = timeSelector::select + instantList timeDirs ( - runTime.times(), - args, - runTime.constant() + timeSelector::select + ( + runTime.times(), + args, + runTime.constant() + ) ); if (timeDirs.empty()) @@ -272,7 +280,7 @@ Foam::List<Foam::instant> Foam::timeSelector::select0 } -Foam::List<Foam::instant> Foam::timeSelector::selectIfPresent +Foam::instantList Foam::timeSelector::selectIfPresent ( Time& runTime, const argList& args @@ -297,4 +305,32 @@ Foam::List<Foam::instant> Foam::timeSelector::selectIfPresent } +Foam::instantList Foam::timeSelector::select +( + Time& runTime, + const argList& args, + const word& fName +) +{ + instantList timeDirs(timeSelector::select0(runTime, args)); + + if (timeDirs.size() && args.optionFound("newTimes")) + { + List<bool> selectTimes(timeDirs.size(), true); + + forAll(timeDirs, timeI) + { + selectTimes[timeI] = + !exists(runTime.path()/timeDirs[timeI].name()/fName); + } + + return subset(selectTimes, timeDirs); + } + else + { + return timeDirs; + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/Time/timeSelector.H b/src/OpenFOAM/db/Time/timeSelector.H index 590da7a1b7c..ad8ce4d454d 100644 --- a/src/OpenFOAM/db/Time/timeSelector.H +++ b/src/OpenFOAM/db/Time/timeSelector.H @@ -159,6 +159,18 @@ public: Time& runTime, const argList& args ); + + //- Return the set of times selected based on the argList options + // including support for \b -newTimes in which times are selected + // if the file <fName> does not exist in the time directory. + // Aslso set the runTime to the first instance or the + // \c constant/ directory if no instances are specified or available + static instantList select + ( + Time& runTime, + const argList& args, + const word& fName + ); }; -- GitLab