timeControlFunctionObject.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) 2016 OpenFOAM Foundation
9 Copyright (C) 2017 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::functionObjects::timeControl
29
30Description
31 Wrapper around functionObjects to add time control.
32
33 Adds
34 - timeStart, timeEnd activation
35 - deltaT modification to hit writeInterval (note: if adjustableRunTime
36 also in controlDict this has to be an integer multiple)
37 - smooth deltaT variation through optional deltaTCoeff parameter
38
39Note
40 Since the timeIndex is used directly from Foam::Time, it is unaffected
41 by user-time conversions. For example, Foam::engineTime might cause \a
42 writeInterval to be degrees crank angle, but the functionObject
43 execution \a interval would still be in timestep.
44
45 The function object can be limited to operate within a time range using
46 the timeStart and timEnd options. All objects are read (and the
47 OutputFilter allocated) on construction. However, if a timeEnd is
48 supplied, the object will call the 'end' function of the filter
49 at the timeEnd time and destroy the filter.
50 Any other callback (execute(), write(), timeSet() etc) will only operate
51 if within the timeStart, timeEnd time range. Note that the time range
52 uses 0.5 * deltaT as a comparison tolerance to account for precision errors.
53
54SourceFiles
55 timeControlFunctionObject.C
56
57\*---------------------------------------------------------------------------*/
58
59#ifndef functionObjects_timeControl_H
60#define functionObjects_timeControl_H
61
62#include "timeFunctionObject.H"
63#include "dictionary.H"
64#include "timeControl.H"
65
66// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67
68namespace Foam
69{
70namespace functionObjects
71{
72
73/*---------------------------------------------------------------------------*\
74 Class functionObjects::timeControl Declaration
75\*---------------------------------------------------------------------------*/
77class timeControl
78:
80{
81public:
82
83 // Public Enumerations
84
85 //- Control mode
86 enum class controlMode
87 {
88 TIME,
89 TRIGGER,
92 };
95
96
97private:
98
99 // Private Data
100
101 //- Input dictionary
102 dictionary dict_;
103
104
105 // Optional user inputs
106
107 //- Control mode (combination of time/trigger behaviour)
108 controlMode controlMode_;
109
110 //- Activation time - defaults to -VGREAT (ie, active)
111 scalar timeStart_;
112
113 //- De-activation time - defaults to VGREAT
114 scalar timeEnd_;
115
116 //- Activation trigger index - defaults to labelMax (ie, inactive)
117 label triggerStart_;
118
119 //- De-activation trigger index - defaults to labelMax
120 label triggerEnd_;
121
122 //- Max time step change
123 scalar deltaTCoeff_;
124
125 //- Number of steps before the dump-time during which deltaT
126 // may be changed (valid for adjustableRunTime)
127 label nStepsToStartTimeChange_;
128
129
130 //- Execute controls
131 Foam::timeControl executeControl_;
132
133 //- Write controls
134 Foam::timeControl writeControl_;
135
136 //- The functionObject to execute
138
139 //- Time index of the last execute call
140 label executeTimeIndex_;
141
142
143 // For time-step change limiting (deltaTCoeff supplied) only:
144
145 //- Store the old deltaT value
146 scalar deltaT0_;
147
148 //- Store the series expansion coefficient value
149 scalar seriesDTCoeff_;
150
151
152
153 // Private Member Functions
154
155 //- Read relevant dictionary entries
156 void readControls();
157
158 //- Returns true if within time bounds
159 bool active() const;
160
161 //- Return expansion ratio (deltaT change) that gives overall time
162 static scalar calcExpansion
163 (
164 const scalar startRatio,
165 const scalar y,
166 const label n
167 );
168
169 //- Calculate deltaT change such that the next write interval is
170 // obeyed. Updates requiredDeltaTCoeff
171 void calcDeltaTCoeff
172 (
173 scalar& requiredDeltaTCoeff,
174 const scalar wantedDT,
175 const label nSteps,
176 const scalar presentTime,
177 const scalar timeToNextWrite,
178 const bool rampDirectionUp
179 );
180
181 //- No copy construct
182 timeControl(const timeControl&) = delete;
183
184 //- No copy assignment
185 void operator=(const timeControl&) = delete;
186
187
188public:
189
190 //- Runtime type information
191 TypeName("timeControl");
192
193
194 // Constructors
195
196 //- Construct from components
198 (
199 const word& name,
200 const Time& runTime,
201 const dictionary& dict
202 );
203
204
205 // Member Functions
206
207 // Access
208
209 //- Return the input dictionary
210 inline const dictionary& dict() const;
211
212 //- Return the execute control object
213 inline const Foam::timeControl& executeControl() const;
214
215 //- Return the write control object
216 inline const Foam::timeControl& writeControl() const;
217
218 //- Return the functionObject filter
219 inline const functionObject& filter() const;
220
221
222 // Function object control
223
224 //- Helper function to identify if a timeControl object is present
225 // in the dictionary
226 static bool entriesPresent(const dictionary& dict);
227
228 //- Called at each ++ or += of the time-loop.
229 // postProcess overrides the usual executeControl behaviour and
230 // forces execution (used in post-processing mode)
231 virtual bool execute();
232
233 //- Execute using the specified subIndex.
234 virtual bool execute(const label subIndex);
235
236 //- Called at each ++ or += of the time-loop.
237 // postProcess overrides the usual writeControl behaviour and
238 // forces writing (used in post-processing mode)
239 virtual bool write();
240
241 //- Called when Time::run() determines that the time-loop exits
242 virtual bool end();
243
244 //- Called at the end of Time::adjustDeltaT() if adjustTime is true
245 virtual bool adjustTimeStep();
246
247 //- Did any file get changed during execution?
248 virtual bool filesModified() const;
249
250 //- Read and set the function object if its data have changed
251 virtual bool read(const dictionary&);
252
253 //- Update for changes of mesh
254 virtual void updateMesh(const mapPolyMesh& mpm);
255
256 //- Update for changes of mesh
257 virtual void movePoints(const polyMesh& mesh);
258};
259
260
261// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262
263} // End namespace functionObjects
264} // End namespace Foam
265
266// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267
269
270// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271
272#endif
273
274// ************************************************************************* //
scalar y
label n
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
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base-class for Time/database function objects.
const word & name() const noexcept
Return the name of this functionObject.
Wrapper around functionObjects to add time control.
const Foam::timeControl & writeControl() const
Return the write control object.
static const Enum< controlMode > controlModeNames_
virtual bool filesModified() const
Did any file get changed during execution?
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
static bool entriesPresent(const dictionary &dict)
Helper function to identify if a timeControl object is present.
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
const dictionary & dict() const
Return the input dictionary.
TypeName("timeControl")
Runtime type information.
virtual bool execute()
Called at each ++ or += of the time-loop.
const Foam::timeControl & executeControl() const
Return the execute control object.
virtual bool write()
Called at each ++ or += of the time-loop.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
const functionObject & filter() const
Return the functionObject filter.
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
Virtual base class for function objects with a reference to Time.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:162
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
General time dependent execution controller. The execution parameters are given by the "Control" and ...
Definition: timeControl.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
engineTime & runTime
Namespace for OpenFOAM.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73