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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::functionObjects::timeControl
29 
30 Description
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 
39 Note
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 
54 SourceFiles
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 
68 namespace Foam
69 {
70 namespace functionObjects
71 {
72 
73 /*---------------------------------------------------------------------------*\
74  Class functionObjects::timeControl Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 class timeControl
78 :
80 {
81 public:
82 
83 
84  // Public enumerations
85 
86  //- Control mode
87  enum class controlMode
88  {
89  TIME,
90  TRIGGER,
93  };
94 
96 
97 
98 private:
99 
100  // Private data
101 
102  //- Input dictionary
103  dictionary dict_;
104 
105 
106  // Optional user inputs
107 
108  //- Control mode (combination of time/trigger behaviour)
109  controlMode controlMode_;
110 
111  //- Activation time - defaults to -VGREAT
112  scalar timeStart_;
113 
114  //- De-activation time - defaults to VGREAT
115  scalar timeEnd_;
116 
117  //- Activation trigger index - defaults to labelMin
118  label triggerStart_;
119 
120  //- De-activation trigger index - defaults to labelMax
121  label triggerEnd_;
122 
123  //- Max time step change
124  scalar deltaTCoeff_;
125 
126  //- Number of steps before the dump-time during which deltaT
127  // may be changed (valid for adjustableRunTime)
128  label nStepsToStartTimeChange_;
129 
130 
131  //- Execute controls
132  Foam::timeControl executeControl_;
133 
134  //- Write controls
135  Foam::timeControl writeControl_;
136 
137  //- The functionObject to execute
139 
140  //- Time index of the last execute call
141  label executeTimeIndex_;
142 
143 
144  // For time-step change limiting (deltaTCoeff supplied) only:
145 
146  //- Store the old deltaT value
147  scalar deltaT0_;
148 
149  //- Store the series expansion coefficient value
150  scalar seriesDTCoeff_;
151 
152 
153 
154  // Private Member Functions
155 
156  //- Read relevant dictionary entries
157  void readControls();
158 
159  //- Returns true if within time bounds
160  bool active() const;
161 
162  //- Return expansion ratio (deltaT change) that gives overall time
163  static scalar calcExpansion
164  (
165  const scalar startRatio,
166  const scalar y,
167  const label n
168  );
169 
170  //- Calculate deltaT change such that the next write interval is
171  // obeyed. Updates requiredDeltaTCoeff
172  void calcDeltaTCoeff
173  (
174  scalar& requiredDeltaTCoeff,
175  const scalar wantedDT,
176  const label nSteps,
177  const scalar presentTime,
178  const scalar timeToNextWrite,
179  const bool rampDirectionUp
180  );
181 
182  //- No copy construct
183  timeControl(const timeControl&) = delete;
184 
185  //- No copy assignment
186  void operator=(const timeControl&) = delete;
187 
188 
189 public:
190 
191  //- Runtime type information
192  TypeName("timeControl");
193 
194 
195  // Constructors
196 
197  //- Construct from components
199  (
200  const word& name,
201  const Time& runTime,
202  const dictionary& dict
203  );
204 
205 
206  // Member Functions
207 
208  // Access
209 
210  //- Return the input dictionary
211  inline const dictionary& dict() const;
212 
213  //- Return the execute control object
214  inline const Foam::timeControl& executeControl() const;
215 
216  //- Return the write control object
217  inline const Foam::timeControl& writeControl() const;
218 
219  //- Return the functionObject filter
220  inline const functionObject& filter() const;
221 
222 
223  // Function object control
224 
225  //- Helper function to identify if a timeControl object is present
226  // in the dictionary
227  static bool entriesPresent(const dictionary& dict);
228 
229  //- Called at each ++ or += of the time-loop.
230  // postProcess overrides the usual executeControl behaviour and
231  // forces execution (used in post-processing mode)
232  virtual bool execute();
233 
234  //- Execute using the specified subIndex.
235  virtual bool execute(const label subIndex);
236 
237  //- Called at each ++ or += of the time-loop.
238  // postProcess overrides the usual writeControl behaviour and
239  // forces writing (used in post-processing mode)
240  virtual bool write();
241 
242  //- Called when Time::run() determines that the time-loop exits
243  virtual bool end();
244 
245  //- Called at the end of Time::adjustDeltaT() if adjustTime is true
246  virtual bool adjustTimeStep();
247 
248  //- Did any file get changed during execution?
249  virtual bool filesModified() const;
250 
251  //- Read and set the function object if its data have changed
252  virtual bool read(const dictionary&);
253 
254  //- Update for changes of mesh
255  virtual void updateMesh(const mapPolyMesh& mpm);
256 
257  //- Update for changes of mesh
258  virtual void movePoints(const polyMesh& mesh);
259 };
260 
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 } // End namespace functionObjects
265 } // End namespace Foam
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #endif
274 
275 // ************************************************************************* //
Foam::functionObjects::timeControl::controlMode::TIME_AND_TRIGGER
Foam::functionObjects::timeControl::movePoints
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
Definition: timeControlFunctionObject.C:817
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Enum< controlMode >
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::timeControl::end
virtual bool end()
Called when Time::run() determines that the time-loop exits.
Definition: timeControlFunctionObject.C:538
Foam::functionObjects::timeControl
Wrapper around functionObjects to add time control.
Definition: timeControlFunctionObject.H:76
Foam::functionObjects::timeFunctionObject
Virtual base class for function objects with a reference to Time.
Definition: timeFunctionObject.H:56
Foam::functionObjects::timeControl::controlMode::TIME
Foam::functionObjects::timeControl::writeControl
const Foam::timeControl & writeControl() const
Return the write control object.
Definition: timeControlFunctionObjectI.H:44
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:321
timeFunctionObject.H
timeControl.H
Foam::functionObjects::timeControl::read
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
Definition: timeControlFunctionObject.C:784
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::functionObjects::timeControl::controlModeNames_
static const Enum< controlMode > controlModeNames_
Definition: timeControlFunctionObject.H:94
Foam::timeControl
General time dependent execution controller. The execution parameters are given by the "Control" and ...
Definition: timeControl.H:61
Foam::functionObjects::timeControl::dict
const dictionary & dict() const
Return the input dictionary.
Definition: timeControlFunctionObjectI.H:30
Foam::functionObjects::timeControl::adjustTimeStep
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
Definition: timeControlFunctionObject.C:549
Foam::functionObjects::timeControl::controlMode::TRIGGER
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::functionObjects::timeControl::filesModified
virtual bool filesModified() const
Did any file get changed during execution?
Definition: timeControlFunctionObject.C:802
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::timeControl::write
virtual bool write()
Called at each ++ or += of the time-loop.
Definition: timeControlFunctionObject.C:520
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
Foam::functionObjects::timeControl::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Definition: timeControlFunctionObject.C:808
dictionary.H
Foam::functionObjects::timeControl::controlMode
controlMode
Control mode.
Definition: timeControlFunctionObject.H:86
Foam::functionObjects::timeControl::controlMode::TIME_OR_TRIGGER
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::functionObjects::timeControl::entriesPresent
static bool entriesPresent(const dictionary &dict)
Helper function to identify if a timeControl object is present.
Definition: timeControlFunctionObject.C:473
timeControlFunctionObjectI.H
Foam::functionObjects::timeControl::filter
const functionObject & filter() const
Return the functionObject filter.
Definition: timeControlFunctionObjectI.H:51
Foam::functionObjects::timeControl::TypeName
TypeName("timeControl")
Runtime type information.
Foam::functionObjects::timeControl::executeControl
const Foam::timeControl & executeControl() const
Return the execute control object.
Definition: timeControlFunctionObjectI.H:37
Foam::functionObjects::timeControl::execute
virtual bool execute()
Called at each ++ or += of the time-loop.
Definition: timeControlFunctionObject.C:493
y
scalar y
Definition: LISASMDCalcMethod1.H:14