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  // Public Enumerations
84 
85  //- Control mode
86  enum class controlMode
87  {
88  TIME,
89  TRIGGER,
92  };
93 
95 
96 
97 private:
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 
188 public:
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 // ************************************************************************* //
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:65
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:332
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:93
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:123
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 noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
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:85
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