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