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-2023 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 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class timeControl Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 class timeControl
51 {
52 public:
53 
54  //- The time control options
55  enum class timeControls
56  {
57  timeStep,
58  writeTime,
59  outputTime,
61  runTime,
62  runTimes,
63  clockTime,
64  cpuTime,
65  none
66  };
67 
68 
69 private:
70 
71  // Private Data
72 
73  //- Reference to time
74  const Time& time_;
75 
76  //- Prefix
77  const word prefix_;
78 
79  //- String representation of timeControls enums
80  static const NamedEnum<timeControls, 9> timeControlNames_;
81 
82  //- Type of time control
83  timeControls timeControl_;
84 
85  //- Execution interval steps for timeStep mode
86  // a value <= 1 means execute at every time step
87  label intervalSteps_;
88 
89  //- Execution interval
90  scalar interval_;
91 
92  //- List of times (for runTimes option)
93  scalarList times_;
94 
95  //- Time delta used for time -> index (for runTimes option)
96  scalar timeDelta_;
97 
98  //- Hash set of mesh mapping time indices (for runTimes option)
99  HashSet<int64_t, Hash<int64_t>> timeIndices_;
100 
101  //- Index of previous execution
102  mutable label executionIndex_;
103 
104 
105 public:
106 
107  // Constructors
108 
109  //- Construct from Time object and dictionary
111  (
112  const Time&,
113  const dictionary&,
114  const word& prefix
115  );
116 
117  //- Disallow default bitwise copy construction
118  timeControl(const timeControl&) = delete;
119 
120 
121  //- Destructor
122  ~timeControl();
123 
124 
125  // Member Functions
126 
127  //- Read from dictionary
128  void read(const dictionary&);
129 
130  //- Return Time
131  inline const Time& time() const;
132 
133  //- Flag to indicate whether to execute
134  bool execute();
135 
136  //- Return the time to the next write
137  scalar timeToNextAction();
138 
139  //- Return control
140  inline timeControls control() const;
141 
142 
143  // Member Operators
144 
145  //- Disallow default bitwise assignment
146  void operator=(const timeControl&) = delete;
147 };
148 
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 } // End namespace Foam
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 #include "timeControlI.H"
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 #endif
161 
162 // ************************************************************************* //
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 keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
General time dependent execution controller. The default to execute every time-step.
Definition: timeControl.H:50
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:55
@ 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:82
~timeControl()
Destructor.
Definition: timeControl.C:76
scalar timeToNextAction()
Return the time to the next write.
Definition: timeControl.C:277
bool execute()
Flag to indicate whether to execute.
Definition: timeControl.C:173
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:56
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