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