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-2018 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 Namespace
28  Foam::functionObjects
29 
30 Description
31  Namespace for functionObjects.
32 
33  OpenFOAM includes a collection of functionObjects selected by the user at
34  run-time to manipulate the simulation and provide mechanisms to extract
35  field and derived quantities. Alternatively, the same actions can be
36  executed after the simulation using the \c -postProcess command-line option.
37 
38  \section secFunctionObjects Using function objects
39 
40  FunctionObjects are selected by additional entries in the global case
41  system/controlDict dictionary. Each object is listed in the \c
42  functions sub-dictionary, e.g. to select the \c functionObjectType
43  functionObject the following entry would be specified:
44 
45  \verbatim
46  functions
47  {
48  <functionObjectName>
49  {
50  type functionObjectType;
51  libs ("libMyFunctionObjectlib.so");
52  region defaultRegion;
53  enabled yes;
54  timeStart 0;
55  timeEnd 10;
56  writeControl writeTime;
57  writeInterval 1;
58  ...
59  }
60  }
61  \endverbatim
62 
63  Where:
64  \table
65  Property | Description | Required | Default
66  type | Type of function object | yes |
67  libs | Libraries containing implementation | yes |
68  region | Name of region for multi-region cases | no |
69  enabled | On/off switch | no | yes
70  log | Log information to standard output | no | yes
71  timeStart| Start time | no |
72  timeEnd | End time | no |
73  executeControl | See time controls below | no | timeStep
74  executeInterval | Steps/time between execute phases | no | 1
75  writeControl | See time controls below | no | timeStep
76  writeInterval | Steps/time between write phases | no | 1
77  \endtable
78 
79  Time controls:
80  \table
81  Option | Description
82  none | Trigger is disabled
83  timeStep | Trigger every 'Interval' time-steps
84  writeTime | Trigger every 'Interval' output times
85  runTime | Trigger every 'Interval' run time period
86  adjustableRunTime | Currently identical to "runTime"
87  clockTime | Trigger every 'Interval' clock time period
88  cpuTime | Trigger every 'Interval' CPU time period
89  onEnd | Trigger on end of run
90  \endtable
91 
92  The sub-dictionary name \c <functionObjectName> is chosen by the user, and
93  is typically used as the name of the output directory for any data written
94  by the functionObject. The \c type entry defines the type of function
95  object properties that follow. FunctionObjects are packaged into separate
96  libraries and the \c libs entry is used to specify which library should be
97  loaded.
98 
99  Each function object has two separate run phases:
100 
101  - The \c execute phase is meant to be used for updating calculations
102  or for management tasks.
103  - The \c write phase is meant for writing the calculated data to disk.
104 
105  For each phase the respective time controls are provided, as listed above.
106 
107 Class
108  Foam::functionObject
109 
110 Description
111  Abstract base-class for Time/database function objects.
112 
113 See also
114  Foam::functionObjectList
115  Foam::functionObjects::timeControl
116 
117 SourceFiles
118  functionObject.C
119 
120 \*---------------------------------------------------------------------------*/
121 
122 #ifndef functionObject_H
123 #define functionObject_H
124 
125 #include "typeInfo.H"
126 #include "autoPtr.H"
127 #include "runTimeSelectionTables.H"
128 
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130 
131 namespace Foam
132 {
133 
134 // Forward declarations
135 class Time;
136 class polyMesh;
137 class mapPolyMesh;
138 
139 /*---------------------------------------------------------------------------*\
140  Class functionObject Declaration
141 \*---------------------------------------------------------------------------*/
142 
143 class functionObject
144 {
145  // Private data
146 
147  //- Name
148  const word name_;
149 
150 
151 protected:
152 
153  // Protected Member Functions
154 
155  //- Return a scoped name, e.g. used to construct local field names
156  word scopedName(const word& name) const;
157 
158 
159 public:
160 
161  // Forward declarations
162  class unavailableFunctionObject;
163 
164  //- Runtime type information
165  virtual const word& type() const = 0;
166 
167  static int debug;
168 
169  //- Global post-processing mode switch
170  static bool postProcess;
171 
172  //- Directory prefix
173  static word outputPrefix;
174 
175  //- Switch write log to Info
176  bool log;
177 
178 
179  // Declare run-time constructor selection tables
180 
182  (
183  autoPtr,
185  dictionary,
186  (const word& name, const Time& runTime, const dictionary& dict),
187  (name, runTime, dict)
188  );
189 
190 
191  // Constructors
192 
193  //- Construct from components
194  functionObject(const word& name);
195 
196  //- Return clone
197  autoPtr<functionObject> clone() const
198  {
200  return nullptr;
201  }
202 
203 
204  // Selectors
205 
206  //- Select from dictionary, based on its "type" entry
207  static autoPtr<functionObject> New
208  (
209  const word& name,
210  const Time& runTime,
211  const dictionary& dict
212  );
213 
214 
215  //- Destructor
216  virtual ~functionObject() = default;
217 
218 
219  // Member Functions
220 
221  //- Return the name of this functionObject
222  const word& name() const;
223 
224  //- Read and set the function object if its data have changed
225  virtual bool read(const dictionary& dict);
226 
227  //- Called at each ++ or += of the time-loop.
228  // postProcess overrides the usual executeControl behaviour and
229  // forces execution (used in post-processing mode)
230  virtual bool execute() = 0;
231 
232  //- Execute using the specified subIndex.
233  // The base implementation is a no-op.
234  // \param subIndex an execution sub-index corresponding to a
235  // sub-cycle or something similar.
236  virtual bool execute(const label subIndex);
237 
238  //- Called at each ++ or += of the time-loop.
239  // postProcess overrides the usual writeControl behaviour and
240  // forces writing always (used in post-processing mode)
241  virtual bool write() = 0;
242 
243  //- Called when Time::run() determines that the time-loop exits.
244  // The base implementation is a no-op.
245  virtual bool end();
246 
247  //- Called at the end of Time::adjustDeltaT() if adjustTime is true
248  virtual bool adjustTimeStep();
249 
250  //- Did any file get changed during execution?
251  virtual bool filesModified() const;
252 
253  //- Update for changes of mesh
254  // The base implementation is a no-op.
255  virtual void updateMesh(const mapPolyMesh& mpm);
256 
257  //- Update for changes of mesh
258  // The base implementation is a no-op.
259  virtual void movePoints(const polyMesh& mesh);
260 };
261 
262 
263 /*---------------------------------------------------------------------------*\
264  Class functionObject::unavailableFunctionObject Declaration
265 \*---------------------------------------------------------------------------*/
266 
267 //- Abstract functionObject to report when a real version is unavailable.
269 :
270  public functionObject
271 {
272 protected:
273 
274  //- Construct with name
276 
277  //- Report it is unavailable, emitting a FatalError for try/catch
278  //- in the caller
279  void carp(std::string message = "") const;
280 
281 
282 public:
283 
284  // Member Functions
285 
286  //- No nothing
287  virtual bool execute();
288 
289  //- No nothing
290  virtual bool write();
291 };
292 
293 
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 
296 } // End namespace Foam
297 
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 
300 #endif
301 
302 // ************************************************************************* //
Foam::functionObject::unavailableFunctionObject::execute
virtual bool execute()
No nothing.
Definition: functionObject.C:212
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObject::execute
virtual bool execute()=0
Called at each ++ or += of the time-loop.
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObject::write
virtual bool write()=0
Called at each ++ or += of the time-loop.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
typeInfo.H
Foam::functionObject::New
static autoPtr< functionObject > New(const word &name, const Time &runTime, const dictionary &dict)
Select from dictionary, based on its "type" entry.
Definition: functionObject.C:67
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:229
Foam::functionObject::unavailableFunctionObject::unavailableFunctionObject
unavailableFunctionObject(const word &name)
Construct with name.
Definition: functionObject.C:183
Foam::functionObject::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, functionObject, dictionary,(const word &name, const Time &runTime, const dictionary &dict),(name, runTime, dict))
Foam::functionObject::unavailableFunctionObject::write
virtual bool write()
No nothing.
Definition: functionObject.C:218
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:419
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::functionObject::~functionObject
virtual ~functionObject()=default
Destructor.
Foam::functionObject::postProcess
static bool postProcess
Global post-processing mode switch.
Definition: functionObject.H:256
Foam::functionObject::read
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Definition: functionObject.C:137
Foam::functionObject::outputPrefix
static word outputPrefix
Directory prefix.
Definition: functionObject.H:259
Foam::functionObject::clone
autoPtr< functionObject > clone() const
Return clone.
Definition: functionObject.H:283
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::functionObject::adjustTimeStep
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
Definition: functionObject.C:160
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObject::movePoints
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
Definition: functionObject.C:176
Foam::functionObject::unavailableFunctionObject::carp
void carp(std::string message="") const
Definition: functionObject.C:192
Foam::functionObject::end
virtual bool end()
Called when Time::run() determines that the time-loop exits.
Definition: functionObject.C:154
Foam::functionObject::scopedName
word scopedName(const word &name) const
Return a scoped name, e.g. used to construct local field names.
Definition: functionObject.C:49
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::functionObject::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Definition: functionObject.C:172
Foam::functionObject::unavailableFunctionObject
Abstract functionObject to report when a real version is unavailable.
Definition: functionObject.H:354
Foam::functionObject::debug
static int debug
Definition: functionObject.H:253
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::functionObject::type
virtual const word & type() const =0
Runtime type information.
Foam::functionObject::filesModified
virtual bool filesModified() const
Did any file get changed during execution?
Definition: functionObject.C:166
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::functionObject::log
bool log
Switch write log to Info.
Definition: functionObject.H:262
Foam::functionObject::functionObject
functionObject(const word &name)
Construct from components.
Definition: functionObject.C:57
autoPtr.H