timeControl.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-2024 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::timeControl
26 
27 Description
28  General time dependent execution controller.
29  The default to execute every time-step.
30 
31 SourceFiles
32  timeControl.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef timeControl_H
37 #define timeControl_H
38 
39 #include "Time.H"
40 #include "scalarList.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class timeControl Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 class timeControl
52 {
53 public:
54 
55  //- The time control options
56  enum class timeControls
57  {
58  timeStep,
59  writeTime,
60  outputTime,
62  runTime,
63  runTimes,
64  clockTime,
65  cpuTime,
66  none
67  };
68 
69 
70 private:
71 
72  // Private Data
73 
74  //- Reference to time
75  const Time& time_;
76 
77  //- Prefix
78  const word prefix_;
79 
80  //- String representation of timeControls enums
81  static const NamedEnum<timeControls, 9> timeControlNames_;
82 
83  //- Type of time control
84  timeControls timeControl_;
85 
86  //- Start time for execution - defaults to beginTime
87  scalar startTime_;
88 
89  //- End time for execution - defaults to vGreat
90  scalar endTime_;
91 
92  //- Execution interval steps for timeStep mode
93  // a value <= 1 means execute at every time step
94  label intervalSteps_;
95 
96  //- Execution interval
97  scalar interval_;
98 
99  //- List of times (for runTimes option)
100  scalarList times_;
101 
102  //- Time delta used for time -> index (for runTimes option)
103  scalar timeDelta_;
104 
105  //- Hash set of mesh mapping time indices (for runTimes option)
106  HashSet<int64_t, Hash<int64_t>> timeIndices_;
107 
108  //- Index of previous execution
109  mutable label executionIndex_;
110 
111 
112 public:
113 
114  // Constructors
115 
116  //- Construct from Time object and dictionary
118  (
119  const Time&,
120  const dictionary&,
121  const word& prefix
122  );
123 
124  //- Disallow default bitwise copy construction
125  timeControl(const timeControl&) = delete;
126 
127 
128  //- Destructor
129  ~timeControl();
130 
131 
132  // Member Functions
133 
134  //- Read from dictionary
135  void read(const dictionary&);
136 
137  //- Return Time
138  inline const Time& time() const;
139 
140  //- Returns true the time is within the start to end period
141  bool active() const;
142 
143  //- Flag to indicate whether to execute
144  bool execute();
145 
146  //- Return the time to the next write
147  scalar timeToNextAction();
148 
149  //- Return control
150  inline timeControls control() const;
151 
152 
153  // Member Operators
154 
155  //- Disallow default bitwise assignment
156  void operator=(const timeControl&) = delete;
157 };
158 
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 } // End namespace Foam
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 #include "timeControlI.H"
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 #endif
171 
172 // ************************************************************************* //
A HashTable with keys but without contents.
Definition: HashSet.H:62
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
General time dependent execution controller. The default to execute every time-step.
Definition: timeControl.H:51
const Time & time() const
Return Time.
Definition: timeControlI.H:28
timeControls control() const
Return control.
Definition: timeControlI.H:34
timeControls
The time control options.
Definition: timeControl.H:56
@ adjustableRunTime
Execute/write every 'Interval' run time period.
@ runTime
Execute/write every 'Interval' run time period.
@ clockTime
Execute/write every 'Interval' CPU time period.
@ cpuTime
Execute/write every 'Interval' CPU time period.
@ runTimes
Execute/write at specified list of run times.
@ writeTime
Execute/write every 'Interval' write times.
@ timeStep
Execute/write every 'Interval' time-steps.
@ outputTime
Execute/write every 'Interval' write times.
void read(const dictionary &)
Read from dictionary.
Definition: timeControl.C:87
~timeControl()
Destructor.
Definition: timeControl.C:81
bool active() const
Returns true the time is within the start to end period.
Definition: timeControl.C:48
scalar timeToNextAction()
Return the time to the next write.
Definition: timeControl.C:359
bool execute()
Flag to indicate whether to execute.
Definition: timeControl.C:253
void operator=(const timeControl &)=delete
Disallow default bitwise assignment.
timeControl(const Time &, const dictionary &, const word &prefix)
Construct from Time object and dictionary.
Definition: timeControl.C:59
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59