diff --git a/applications/utilities/mesh/manipulation/topoSet/topoSet.C b/applications/utilities/mesh/manipulation/topoSet/topoSet.C index d34cc58257..2f15bdce1d 100644 --- a/applications/utilities/mesh/manipulation/topoSet/topoSet.C +++ b/applications/utilities/mesh/manipulation/topoSet/topoSet.C @@ -26,7 +26,6 @@ Description \*---------------------------------------------------------------------------*/ -#include "timeSelector.H" #include "argList.H" #include "Time.H" #include "polyMesh.H" @@ -35,6 +34,7 @@ Description #include "faceSet.H" #include "pointSet.H" #include "globalMeshData.H" +#include "timeSelector.H" using namespace Foam; @@ -114,13 +114,8 @@ int main(int argc, char *argv[]) # include "setRootCase.H" # include "createTime.H" - instantList timeDirs = timeSelector::select0 - ( - runTime, - args, - false // not override runTime if no time options - ); + instantList timeDirs = timeSelector::selectIfPresent(runTime, args); # include "createNamedPolyMesh.H" @@ -159,14 +154,13 @@ int main(int argc, char *argv[]) IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) - ) + ) ); // Read set construct info from dictionary PtrList actions(topoSetDict.lookup("actions")); - forAll(timeDirs, timeI) { runTime.setTime(timeDirs[timeI], timeI); diff --git a/src/OpenFOAM/db/Time/timeSelector.C b/src/OpenFOAM/db/Time/timeSelector.C index f912433bc3..2c17d11678 100644 --- a/src/OpenFOAM/db/Time/timeSelector.C +++ b/src/OpenFOAM/db/Time/timeSelector.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -51,7 +51,7 @@ bool Foam::timeSelector::selected(const instant& value) const } -Foam::List Foam::timeSelector::selected(const List& Times) const +Foam::List Foam::timeSelector::selected(const instantList& Times) const { List lst(Times.size(), false); @@ -97,19 +97,14 @@ Foam::List Foam::timeSelector::selected(const List& Times) const } -Foam::List Foam::timeSelector::select -( - const List& Times -) const +Foam::List Foam::timeSelector::select(const instantList& Times) +const { return subset(selected(Times), Times); } -void Foam::timeSelector::inplaceSelect -( - List& Times -) const +void Foam::timeSelector::inplaceSelect(instantList& Times) const { inplaceSubset(selected(Times), Times); } @@ -159,7 +154,7 @@ void Foam::timeSelector::addOptions Foam::List Foam::timeSelector::select ( - const List& timeDirs, + const instantList& timeDirs, const argList& args ) { @@ -270,4 +265,29 @@ Foam::List Foam::timeSelector::select0 } +Foam::List Foam::timeSelector::selectIfPresent +( + Time& runTime, + const argList& args +) +{ + if + ( + args.optionFound("latestTime") + || args.optionFound("time") + || args.optionFound("constant") + || args.optionFound("noZero") + || args.optionFound("zeroTime") + ) + { + return select0(runTime, args); + } + else + { + // No timeSelector option specified. Do not change runTime. + return instantList(1, instant(runTime.value(), runTime.timeName())); + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/Time/timeSelector.H b/src/OpenFOAM/db/Time/timeSelector.H index 6c3ed747b1..3bfa07f47e 100644 --- a/src/OpenFOAM/db/Time/timeSelector.H +++ b/src/OpenFOAM/db/Time/timeSelector.H @@ -72,7 +72,7 @@ SourceFiles #define timeSelector_H #include "scalarRanges.H" -#include "instant.H" +#include "instantList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -109,13 +109,13 @@ public: //- Return the set of selected instants in the given list that are // within the ranges - List selected(const List&) const; + List selected(const instantList&) const; //- Select a list of Time values that are within the ranges - List select(const List&) const; + instantList select(const instantList&) const; //- Select a list of Time values that are within the ranges - void inplaceSelect(List&) const; + void inplaceSelect(instantList&) const; //- Add the options handled by timeSelector to argList::validOptions // @@ -135,15 +135,24 @@ public: ); //- Return the set of times selected based on the argList options - static List select + static instantList select ( - const List&, + const instantList&, const argList& args ); //- Return the set of times selected based on the argList options // also set the runTime to the first instance - static List select0 + static instantList select0 + ( + Time& runTime, + const argList& args + ); + + //- If any time option provided return the set of times (as select0) + // otherwise return just the current time. + // Also set the runTime to the first instance + static instantList selectIfPresent ( Time& runTime, const argList& args