timeSelector.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2018 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::timeSelector
29
30Description
31 A List of scalarRange for selecting times.
32
33 The timeSelector provides a convenient means of selecting multiple
34 times. A typical use would be the following:
35
36 \verbatim
37 timeSelector::addOptions();
38 // add other options
39 #include "setRootCase.H"
40 #include "createTime.H"
41 instantList timeDirs = timeSelector::select0(runTime, args);
42 ...
43 forAll(timeDirs, timei)
44 {
45 ...
46 }
47 \endverbatim
48
49 The result program would receive \b -time, \b -latestTime, \b -constant
50 and \b -noZero options. The \b -constant option explicitly includes the
51 \c constant/ directory in the time list and the \b -noZero option
52 explicitly excludes the \c 0/ directory from the time list.
53
54 There may however also be many cases in which neither the \c constant/
55 directory nor the \c 0/ directory contain particularly relevant
56 information. This might occur, for example, when post-processing
57 results. In this case, addOptions is called with optional boolean
58 arguments.
59
60 \verbatim
61 timeSelector::addOptions(false, true);
62 \endverbatim
63
64 The first argument avoids adding the \b -constant option. The second
65 argument adds an additional \b -withZero option and also prevents the
66 \c 0/ directory from being included in the default time range and in the
67 \b -latestTime selection.
68
69SourceFiles
70 timeSelector.C
71
72\*---------------------------------------------------------------------------*/
73
74#ifndef timeSelector_H
75#define timeSelector_H
76
77#include "scalarRanges.H"
78#include "instantList.H"
79
80// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81
82namespace Foam
83{
84
85// Forward Declarations
86class argList;
87class Time;
88
89/*---------------------------------------------------------------------------*\
90 Class timeSelector Declaration
91\*---------------------------------------------------------------------------*/
93class timeSelector
94:
95 private scalarRanges
96{
97public:
98
99 // Constructors
100
101 //- Default construct
102 timeSelector() = default;
103
104 //- Construct by parsing string for time ranges
105 explicit timeSelector(const std::string& str);
106
107
108 // Member Functions
109
110 //- Return true if the given instant is within the ranges
111 bool selected(const instant& value) const;
112
113 //- Return the set of selected instants in the given list that are
114 //- within the ranges
115 List<bool> selected(const instantList& times) const;
116
117 //- Select a list of Time values that are within the ranges
118 instantList select(const instantList& times) const;
119
120 //- Select a list of Time values that are within the ranges
121 void inplaceSelect(instantList& times) const;
122
123
124 // Static Member Functions
125
126 //- Add timeSelector options to argList::validOptions
127 //
128 // \param constant
129 // Add the \b -constant option to include the \c constant/ directory
130 //
131 // \param withZero
132 // Enable the \b -withZero option and alter the normal time selection
133 // behaviour (and \b -latestTime behaviour) to exclude the \c 0/
134 // directory. The \c 0/ directory will only be included when
135 // \b -withZero is specified.
136 // The \b -noZero option has precedence over the \b -withZero option.
137 static void addOptions
138 (
139 const bool constant=true,
140 const bool withZero=false
141 );
142
143 //- Return the set of times selected based on the argList options
144 static instantList select
145 (
146 const instantList& times,
147 const argList& args,
148 const word& constantName = "constant"
149 );
150
151 //- Return the set of times selected based on the argList options
152 //- and also set the runTime to the first instance or the
153 //- \c constant/ directory if no instances are specified or available
154 static instantList select0
155 (
156 Time& runTime,
157 const argList& args
158 );
159
160 //- If any time option provided return the set of times (as select0)
161 //- otherwise return just the current time.
162 // Also set the runTime to the first instance
164 (
165 Time& runTime,
166 const argList& args
167 );
168};
169
170
171// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172
173} // End namespace Foam
174
175// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176
177#endif
178
179// ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:124
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Definition: instant.H:56
constant condensation/saturation model.
A collection of scalar bounds to be used as a unary predicate.
Definition: scalarRanges.H:58
A List of scalarRange for selecting times.
Definition: timeSelector.H:95
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
Definition: timeSelector.C:102
bool selected(const instant &value) const
Return true if the given instant is within the ranges.
Definition: timeSelector.C:44
static instantList select0(Time &runTime, const argList &args)
Definition: timeSelector.C:235
static instantList selectIfPresent(Time &runTime, const argList &args)
Definition: timeSelector.C:266
timeSelector()=default
Default construct.
void inplaceSelect(instantList &times) const
Select a list of Time values that are within the ranges.
Definition: timeSelector.C:95
instantList select(const instantList &times) const
Select a list of Time values that are within the ranges.
Definition: timeSelector.C:89
A class for handling words, derived from Foam::string.
Definition: word.H:68
engineTime & runTime
Namespace for OpenFOAM.
Foam::argList args(argc, argv)