Loading...
Searching...
No Matches
timeControl.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-2016 OpenFOAM Foundation
9 Copyright (C) 2019, 2025 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::timeControl
29
30Description
31 General time dependent execution controller.
32 The execution parameters are given by the "Control" and (optionally)
33 the "Interval", with the default being to execute every time-step.
34
35 For example, an "execute" control every tenth write time:
36 \verbatim
37 executeControl writeTime;
38 executeInterval 10;
39 \endverbatim
40
41 See Foam::functionObject for a list of known selection types.
42
43SourceFiles
44 timeControl.C
45
46\*---------------------------------------------------------------------------*/
47
48#ifndef timeControl_H
49#define timeControl_H
50
51#include "Time.H"
52
53// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54
55namespace Foam
56{
58/*---------------------------------------------------------------------------*\
59 Class timeControl Declaration
60\*---------------------------------------------------------------------------*/
61
62class timeControl
63{
77 ocOnStart,
78 ocOnEnd
79 };
80
81
82private:
83
84 //- The selection names for timeControls enumerations
85 static const Enum<timeControls> controlNames_;
86
87
88 // Private Data
89
90 //- Time object
91 const Time& time_;
92
93 //- The prefix for the control name (eg, "write", "execute", ...)
94 const word prefix_;
95
96 //- Type of time control
97 timeControls timeControl_;
98
99 //- Execution interval steps (timeStep | writeTime).
100 // A value <= 1 means execute at every time-step or writeTime.
101 label intInterval_;
102
103 //- Execution interval (clockTime | runTime | cpuTime | adjustable)
104 scalar interval_;
105
106 //- Index of previous execution
107 label executionIndex_;
108
109
110 // Private Member Functions
111
112 //- No copy construct
113 timeControl(const timeControl&) = delete;
114
115 //- No copy assignment
116 void operator=(const timeControl&) = delete;
117
118
119public:
120
121 // Constructors
122
123 //- Construct a control object that executes each time-step.
124 // For places where a time control object is required, but should
125 // not actually intervene.
126 explicit timeControl(const Time& runTime, const word& prefix = "");
127
128 //- Construct from Time object, dictionary and the prefix for the
129 //- control name.
131 (
132 const Time& runTime,
133 const dictionary& dict,
134 const word& prefix
135 );
136
137
138 //- Destructor
139 ~timeControl() = default;
140
141
142 // Member Functions
143
144 //- Identify if a timeControl object is present in the dictionary
145 // Matches prefix + "Control"
146 static bool entriesPresent(const dictionary& dict, const word& prefix);
147
148 //- Read from dictionary
149 void read(const dictionary& dict);
150
151 //- Return the Time
152 inline const Time& time() const;
153
154 //- Return the name (prefix)
155 inline const word& name() const;
156
157 //- Return the named control enumeration as its 'type'
158 inline const word& type() const;
159
160 //- Reset control to 'always' - ie, no intervention
161 void clear();
163 //- Return the control enumeration
164 inline timeControls control() const;
165
166 //- Return true if the control will always execute - ie, no intervention
167 inline bool always() const;
168
169 //- Flag to indicate whether to execute
170 bool execute();
171
172 //- Return interval
173 inline scalar interval() const;
174
175 //- Return the index of the previous execution
176 inline label executionIndex() const;
177};
178
179
180// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181
182} // End namespace Foam
183
184// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185
186#include "timeControlI.H"
187
188// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189
190#endif
191
192// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
General time dependent execution controller. The execution parameters are given by the "Control" and ...
Definition timeControl.H:58
scalar interval() const
Return interval.
const Time & time() const
Return the Time.
static bool entriesPresent(const dictionary &dict, const word &prefix)
Identify if a timeControl object is present in the dictionary.
Definition timeControl.C:81
void read(const dictionary &dict)
Read from dictionary.
timeControls control() const
Return the control enumeration.
timeControls
The time control options.
Definition timeControl.H:65
@ ocClockTime
Use clock time for execution.
Definition timeControl.H:72
@ ocOnStart
Execute on first step of run.
Definition timeControl.H:74
@ ocNone
No execution.
Definition timeControl.H:66
@ ocAlways
Always execute.
Definition timeControl.H:67
@ ocCpuTime
Use CPU time for execution.
Definition timeControl.H:73
@ ocRunTime
Use run-time for execution.
Definition timeControl.H:70
@ ocOnEnd
Execute on end of run.
Definition timeControl.H:75
@ ocAdjustableRunTime
Currently identical to "runTime".
Definition timeControl.H:71
@ ocWriteTime
Execution coupled to write-time.
Definition timeControl.H:69
@ ocTimeStep
Execution coupled to time-step (default).
Definition timeControl.H:68
~timeControl()=default
Destructor.
void clear()
Reset control to 'always' - ie, no intervention.
Definition timeControl.C:94
label executionIndex() const
Return the index of the previous execution.
const word & name() const
Return the name (prefix).
bool execute()
Flag to indicate whether to execute.
bool always() const
Return true if the control will always execute - ie, no intervention.
const word & type() const
Return the named control enumeration as its 'type'.
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
Namespace for OpenFOAM.
dictionary dict