functionObject.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) 2017-2021 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
27Namespace
28 Foam::functionObjects
29
30Description
31 Function objects are OpenFOAM utilities to ease workflow configurations and
32 enhance workflows by producing additional user-requested data both during
33 runtime and postprocessing calculations, typically in the form of
34 additional logging to the screen, or generating text, image and field files.
35
36 Function objects eliminate the need to store all runtime generated data,
37 hence saving considerable resources. Furthermore, function objects are
38 readily applied to batch-driven processes, improving reliability by
39 standardising the sequence of operations and reducing the amount of manual
40 interaction.
41
42 In addition, the output of most function objects, e.g. output fields, are
43 stored on the mesh database so that it can be retrieved and used for other
44 applications (e.g. directly using \c wallShearStress function object output
45 in \c fieldAverage function object to produce \c wallShearStressMean field).
46
47 \section secFunctionObjects Using function objects
48
49 Function objects can be executed by using two methods:
50
51 - \c functions sub-dictionary in the \c system/controlDict file
52 - \c postProcess command-line utility
53
54 For the first method, each selected function object should be listed inside
55 \c functions sub-dictionary of the \c system/controlDict file as a nested
56 sub-dictionary, typically as in the following example:
57
58 \verbatim
59 functions // sub-dictionary name under the system/controlDict file
60 {
61 ..optional entries..
62
63 <dictName1>
64 {
65 // Mandatory entries
66 type <functionObjectTypeName>;
67 libs (<libType>FunctionObjects);
68
69 // Mandatory entries defined in <functionObjectType>
70 ...
71
72 // Optional entries defined in <functionObjectType>
73 ...
74
75 // Optional (inherited) entries
76 region region0;
77 enabled true;
78 log true;
79 timeStart 0;
80 timeEnd 1000;
81 executeControl timeStep;
82 executeInterval 1;
83 writeControl timeStep;
84 writeInterval 1;
85 }
86
87 <dictName2>
88 {
89 ...
90 }
91
92 ...
93
94 <dictNameN>
95 {
96 ...
97 }
98 }
99 \endverbatim
100
101 where the entries mean:
102 \table
103 Property | Description | Type | Reqd | Deflt
104 type | Type name of function object | word | yes | -
105 libs | Library name(s) for implementation | words | no | -
106 enabled | Switch to turn function object on/off | bool | no | true
107 errors | Error handling (default/warn/ignore/strict) | word | no | inherits
108 log | Switch to write log info to standard output | bool | no | true
109 useNamePrefix | Add scoping prefix to names | bool | no | inherits
110 region | Name of region for multi-region cases | word | no | region0
111 timeStart | Start time for function object execution | scalar | no | 0
112 timeEnd | End time for function object execution | scalar | no | inf
113 executeControl | See time controls below | word | no | timeStep
114 executeInterval | Steps/time between execute phases | label | no | 1
115 writeControl | See time controls below | word | no | timeStep
116 writeInterval | Steps/time between write phases | label | no | 1
117 \endtable
118
119 If the \c errors entry is missing, it uses the value (if any)
120 specified within the top-level functionObjectList.
121
122 If the \c useNamePrefix entry is missing, it uses the value (if any)
123 specified within the top-level functionObjectList or otherwise
124 uses the current value of functionObject::defaultUseNamePrefix
125
126 Time controls:
127 \table
128 Option | Description
129 none | Trigger is disabled
130 timeStep | Trigger every 'Interval' time-steps
131 writeTime | Trigger every 'Interval' output times
132 runTime | Trigger every 'Interval' run time period
133 adjustableRunTime | Currently identical to "runTime"
134 clockTime | Trigger every 'Interval' clock time period
135 cpuTime | Trigger every 'Interval' CPU time period
136 onEnd | Trigger on end of simulation run
137 \endtable
138
139 The sub-dictionary name \c <userDefinedSubDictName> is chosen by the user,
140 and is typically used as the name of the output directory for any data
141 written by the function object.
142
143 As the base mandatory entries, the \c type entry defines the type of
144 function object properties that follow. Function objects are packaged into
145 separate libraries for flexibility and the \c libs entry is used to specify
146 which library should be loaded.
147
148 Each function object has two separate run phases:
149
150 - The \c execute phase is meant to be used for updating calculations
151 or for management tasks.
152 - The \c write phase is meant for writing the calculated data to disk.
153
154 For each phase the respective time controls are provided, as listed above.
155
156
157 The second method of executing function objects is to use \c postProcess
158 utility.
159
160 When specified without additional arguments, the \c postProcess utility
161 executes all function objects defined in the \c system/controlDict file
162 for all time directories:
163
164 \verbatim
165 postProcess
166 \endverbatim
167
168 Most function objects can be invoked directly without the need to specify
169 the input dictionary using the \c -func option, e.g. to execute the Courant
170 number function object:
171
172 \verbatim
173 postProcess -func CourantNo
174 \endverbatim
175
176 In addition, the \c -postProcess option is available to all solvers,
177 and operates similarly to the stand-alone \c postProcess utility.
178 For example, having completed a \c simpleFoam calculation, the following
179 will execute all function objects defined in the \c system/controlDict file
180 for all time directories:
181
182 \verbatim
183 simpleFoam -postProcess
184 \endverbatim
185
186Class
187 Foam::functionObject
188
189Description
190 Abstract base-class for Time/database function objects.
191
192See also
193 - Foam::functionObjectList
194 - Foam::functionObjects::timeControl
195
196SourceFiles
197 functionObject.C
198
199\*---------------------------------------------------------------------------*/
200
201#ifndef Foam_functionObject_H
202#define Foam_functionObject_H
203
204#include "typeInfo.H"
205#include "autoPtr.H"
207
208// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209
210namespace Foam
211{
212
213// Forward Declarations
214class Time;
215class polyMesh;
216class mapPolyMesh;
217
218/*---------------------------------------------------------------------------*\
219 Class functionObject Declaration
220\*---------------------------------------------------------------------------*/
221
222class functionObject
223{
224 // Private Data
225
226 //- Function object name
227 const word name_;
228
229 //- Flag to indicate that names should be prefixed
230 bool useNamePrefix_;
231
232
233protected:
234
235 // Protected Member Functions
236
237 //- Return a scoped (prefixed) name
238 // Used to construct local field names, controlled by useNamePrefix_
239 word scopedName(const word& name) const;
240
241
242public:
243
244 // Forward Declarations
245 class unavailableFunctionObject;
246
247
248 // Public Data
249
250 //- Flag to write log into Info
251 bool log;
252
253
254 // Static Data Members
255
256 //- Flag to execute debug content
257 static int debug;
258
259 //- Global post-processing mode switch
260 static bool postProcess;
261
262 //- Global default for useNamePrefix
263 static bool defaultUseNamePrefix;
264
265 //- Directory prefix
266 static word outputPrefix;
267
268
269 // Declare run-time constructor selection tables
270
272 (
273 autoPtr,
274 functionObject,
275 dictionary,
276 (const word& name, const Time& runTime, const dictionary& dict),
277 (name, runTime, dict)
278 );
279
280
281 // Constructors
282
283 //- Construct from components
284 explicit functionObject
285 (
286 const word& name,
287 const bool withNamePrefix = defaultUseNamePrefix
288 );
289
290 //- Return clone
291 autoPtr<functionObject> clone() const
292 {
294 return nullptr;
295 }
296
297
298 // Selectors
299
300 //- Select from dictionary, based on its "type" entry
301 static autoPtr<functionObject> New
302 (
303 const word& name,
304 const Time& runTime,
305 const dictionary& dict
306 );
307
308
309 //- Destructor
310 virtual ~functionObject() = default;
311
312
313 // Member Functions
314
315 //- Runtime type information
316 virtual const word& type() const = 0;
317
318 //- Return the name of this functionObject
319 const word& name() const noexcept;
320
321 //- Return the flag for adding a scoping name prefix
322 bool useNamePrefix() const noexcept;
323
324 //- Modify the flag for adding a scoping name prefix
325 // \return previous value.
326 bool useNamePrefix(bool on) noexcept;
327
328 //- Read and set the function object if its data have changed
329 virtual bool read(const dictionary& dict);
330
331 //- Called at each ++ or += of the time-loop.
332 // postProcess overrides the usual executeControl behaviour and
333 // forces execution (used in post-processing mode)
334 virtual bool execute() = 0;
335
336 //- Execute using the specified subIndex.
337 // The base implementation is a no-op.
338 // \param subIndex an execution sub-index corresponding to a
339 // sub-cycle or something similar.
340 virtual bool execute(const label subIndex);
341
342 //- Called at each ++ or += of the time-loop.
343 // postProcess overrides the usual writeControl behaviour and
344 // forces writing always (used in post-processing mode)
345 virtual bool write() = 0;
346
347 //- Called when Time::run() determines that the time-loop exits.
348 // The base implementation is a no-op.
349 virtual bool end();
350
351 //- Called at the end of Time::adjustDeltaT() if adjustTime is true
352 virtual bool adjustTimeStep();
353
354 //- Did any file get changed during execution?
355 virtual bool filesModified() const;
356
357 //- Update for changes of mesh
358 // The base implementation is a no-op.
359 virtual void updateMesh(const mapPolyMesh& mpm);
360
361 //- Update for changes of mesh
362 // The base implementation is a no-op.
363 virtual void movePoints(const polyMesh& mesh);
364};
365
366
367/*---------------------------------------------------------------------------*\
368 Class functionObject::unavailableFunctionObject Declaration
369\*---------------------------------------------------------------------------*/
371//- Abstract functionObject to report when a real version is unavailable.
374 public functionObject
375{
376protected:
377
378 //- Construct with name
379 explicit unavailableFunctionObject(const word& name);
380
381 //- Report it is unavailable, emitting a FatalError for try/catch
382 //- in the caller
383 void carp(std::string message = "") const;
384
385
386public:
387
388 // Member Functions
389
390 //- No nothing
391 virtual bool execute();
392
393 //- No nothing
394 virtual bool write();
395};
396
397
398// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
399
400} // End namespace Foam
402// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
403
404#endif
405
406// ************************************************************************* //
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 functionObject to report when a real version is unavailable.
Abstract base-class for Time/database function objects.
const word & name() const noexcept
Return the name of this functionObject.
declareRunTimeSelectionTable(autoPtr, functionObject, dictionary,(const word &name, const Time &runTime, const dictionary &dict),(name, runTime, dict))
virtual bool filesModified() const
Did any file get changed during execution?
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
virtual bool execute()=0
Called at each ++ or += of the time-loop.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
static word outputPrefix
Directory prefix.
autoPtr< functionObject > clone() const
Return clone.
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
bool useNamePrefix() const noexcept
Return the flag for adding a scoping name prefix.
static bool defaultUseNamePrefix
Global default for useNamePrefix.
word scopedName(const word &name) const
Return a scoped (prefixed) name.
static int debug
Flag to execute debug content.
static bool postProcess
Global post-processing mode switch.
virtual const word & type() const =0
Runtime type information.
bool log
Flag to write log into Info.
static autoPtr< functionObject > New(const word &name, const Time &runTime, const dictionary &dict)
Select from dictionary, based on its "type" entry.
virtual ~functionObject()=default
Destructor.
functionObject(const word &name, const bool withNamePrefix=defaultUseNamePrefix)
Construct from components.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
virtual bool write()=0
Called at each ++ or += of the time-loop.
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
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
engineTime & runTime
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
Namespace for OpenFOAM.
const direction noexcept
Definition: Scalar.H:223
Macros to ease declaration of run-time selection tables.
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes)
dictionary dict