Loading...
Searching...
No Matches
timeSelector Class Reference

The timeSelector provides a convenient means of selecting multiple times. More...

#include <timeSelector.H>

Public Member Functions

 timeSelector () noexcept=default
 Default construct.
 timeSelector (const std::string &str)
 Construct by parsing string for time ranges.
bool contains (const scalar value) const
 True if value is within any of the ranges.
bool contains (const instant &t) const
 True if value of the instant is within any of the ranges.
bool selected (const instant &t) const
 True if value of the instant is within any of the ranges.
List< bool > selected (const instantList &times) const
 Return the set of selected instants in the given list that are within the ranges.
instantList select (const instantList &times) const
 Select a list of Time values that are within the ranges.
void inplaceSelect (instantList &times) const
 Select a list of Time values that are within the ranges.

Static Public Member Functions

static void addOptions (const bool constant=true, const bool withZero=false)
 Add timeSelector options to argList::validOptions.
static void addOptions_singleTime ()
 Add single-time timeSelector options to argList::validOptions().
static instantList select (const instantList &times, const argList &args, const word &constantName="constant")
 Return the set of times selected based on the argList options.
static instantList select0 (Time &runTime, const argList &args)
 Return the set of times selected based on the argList options and also set the runTime to the first instance or the constant/ directory if no instances are specified or available.
static instantList selectIfPresent (Time &runTime, const argList &args)
 If any time option provided return the set of times - as per select0() - otherwise return just the current time.
static bool setTimeIfPresent (Time &runTime, const argList &args, const bool forceInitial=false)
 Set the runTime based on -constant (if present), -time (value), or -latestTime.

Detailed Description

The timeSelector provides a convenient means of selecting multiple times.

A typical use would be the following:

timeSelector::addOptions();
...
#include "setRootCase.H"
#include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args);
...
forAll(timeDirs, timei)
{
    ...
}

With the addOptions() method, application receives -time, -latestTime, -constant and -noZero options. The -constant option explicitly includes the constant/ directory in the time list and the -noZero option explicitly excludes the 0/ directory from the time list. There may however also be many cases in which neither the constant/ directory nor the 0/ directory contain particularly relevant information. This might occur, for example, when post-processing results. In this case, addOptions is called with optional boolean arguments.

timeSelector::addOptions(false, true);

The first argument avoids adding the -constant option. The second argument adds an additional -withZero option and also prevents the 0/ directory from being included in the default time range and in the -latestTime selection.

It is also possible to use the timeSelector for setting a single time. Typical use would be the following:

timeSelector::addOptions_singleTime();
...
#include "setRootCase.H"
#include "createTime.H"
timeSelector::setTimeIfPresent(runTime, args);

With the addOptions_singleTime() method, application receives -time, -latestTime, -constant options. In the case, the -time option is intended to be a single value and not include any ranges.

The subsequent call to setTimeIfPresent() will scan the arguments for relevant time options and use them to set the time.

Source files

Definition at line 106 of file timeSelector.H.

Constructor & Destructor Documentation

◆ timeSelector() [1/2]

timeSelector ( )
defaultnoexcept

Default construct.

References contains(), Foam::noexcept, and timeSelector().

Referenced by select(), and timeSelector().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timeSelector() [2/2]

timeSelector ( const std::string & str)
explicit

Construct by parsing string for time ranges.

Definition at line 29 of file timeSelector.C.

Member Function Documentation

◆ contains() [1/2]

bool contains ( const scalar value) const

True if value is within any of the ranges.

Definition at line 37 of file timeSelector.C.

Referenced by selected(), selected(), and timeSelector().

Here is the caller graph for this function:

◆ contains() [2/2]

bool contains ( const instant & t) const

True if value of the instant is within any of the ranges.

Definition at line 43 of file timeSelector.C.

References Instant< T >::value().

Here is the call graph for this function:

◆ selected() [1/2]

bool selected ( const instant & t) const
inline

True if value of the instant is within any of the ranges.

Definition at line 146 of file timeSelector.H.

References contains(), and selected().

Referenced by inplaceSelect(), select(), and selected().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ selected() [2/2]

Foam::List< bool > selected ( const instantList & times) const

Return the set of selected instants in the given list that are within the ranges.

Definition at line 49 of file timeSelector.C.

References contains(), TimePaths::findClosestTimeIndex(), forAll, range, and UList< T >::size().

Here is the call graph for this function:

◆ select() [1/2]

Foam::instantList select ( const instantList & times) const

Select a list of Time values that are within the ranges.

Definition at line 88 of file timeSelector.C.

References selected(), and Foam::subset().

Referenced by select0().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ inplaceSelect()

void inplaceSelect ( instantList & times) const

Select a list of Time values that are within the ranges.

Definition at line 94 of file timeSelector.C.

References Foam::inplaceSubset(), and selected().

Here is the call graph for this function:

◆ addOptions()

void addOptions ( const bool constant = true,
const bool withZero = false )
static

Add timeSelector options to argList::validOptions.

Options added:
  • -constant
  • -time
  • -latestTime
  • -noZero
  • -withZero
Parameters
constantAdd the -constant option to include the constant/ directory
withZeroEnable the -withZero option and alter the normal time selection behaviour (and -latestTime behaviour) to exclude the 0/ directory. The 0/ directory will only be included when -withZero is specified. The -noZero option has precedence over the -withZero option.

Definition at line 100 of file timeSelector.C.

References argList::addBoolOption(), and argList::addOption().

Here is the call graph for this function:

◆ addOptions_singleTime()

void addOptions_singleTime ( )
static

Add single-time timeSelector options to argList::validOptions().

Options added:
  • -constant
  • -time
  • -latestTime
  • -noZero (ignored)

Definition at line 146 of file timeSelector.C.

References argList::addBoolOption(), and argList::addOption().

Here is the call graph for this function:

◆ select() [2/2]

Foam::instantList select ( const instantList & times,
const argList & args,
const word & constantName = "constant" )
static

Return the set of times selected based on the argList options.

Definition at line 172 of file timeSelector.C.

References args, forAll, found, name, UList< T >::size(), Foam::subset(), timeSelector(), and argList::validOptions.

Here is the call graph for this function:

◆ select0()

Foam::instantList select0 ( Time & runTime,
const argList & args )
static

Return the set of times selected based on the argList options and also set the runTime to the first instance or the constant/ directory if no instances are specified or available.

Definition at line 259 of file timeSelector.C.

References args, UList< T >::empty(), Foam::endl(), UList< T >::front(), List< T >::push_back(), runTime, select(), and WarningInFunction.

Referenced by selectIfPresent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ selectIfPresent()

Foam::instantList selectIfPresent ( Time & runTime,
const argList & args )
static

If any time option provided return the set of times - as per select0() - otherwise return just the current time.

Also set the runTime to the first instance

Definition at line 290 of file timeSelector.C.

References args, runTime, and select0().

Here is the call graph for this function:

◆ setTimeIfPresent()

bool setTimeIfPresent ( Time & runTime,
const argList & args,
const bool forceInitial = false )
static

Set the runTime based on -constant (if present), -time (value), or -latestTime.

This method is a no-op if no relevant options have been specified.

Parameters
forceInitialForce initial time (default: 0) even if no options specified

Definition at line 313 of file timeSelector.C.

References args, TimePaths::findClosestTimeIndex(), runTime, UList< T >::size(), and argList::validOptions.

Here is the call graph for this function:

The documentation for this class was generated from the following files: