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