All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
functionObject.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Namespace
25  Foam::functionObjects
26 
27 Description
28  Namespace for functionObjects.
29 
30  OpenFOAM includes a collection of functionObjects selected by the user at
31  run-time to manipulate the simulation and provide mechanisms to extract
32  field and derived quantities. Alternatively, the same actions can be
33  executed after the simulation using the \c -postProcess command-line option.
34 
35  \subsection secFunctionObjects Using functionObjects
36 
37  FunctionObjects are selected by additional entries in the
38  $FOAM_CASE/system/controlDict dictionary. Each object is listed in the \c
39  functions sub-dictionary, e.g. to select the \c functionObjectType
40  functionObject the following entry would be specified:
41 
42  \verbatim
43  functions
44  {
45  <functionObjectName>
46  {
47  type functionObjectType;
48  libs ("libMyFunctionObjectlib.so");
49  region defaultRegion;
50  enabled yes;
51  startTime 0;
52  endTime 10;
53  writeControl writeTime;
54  writeInterval 1;
55  ...
56  }
57  }
58  \endverbatim
59 
60  Where:
61  \table
62  Property | Description | Required | Default value
63  type | Type of functionObject | yes |
64  libs | Libraries containing implementation | yes |
65  region | Name of region for multi-region cases | no |
66  enabled | On/off switch | no | yes
67  log | Log information to standard output | no | no
68  startTime| Start time | no |
69  endTime | End time | no |
70  executeAtStart | Execute at start time switch | no | yes
71  executeControl | See time controls below | no | timeStep
72  executeInterval | Steps between each execute phase | no |
73  writeControl | See time controls below | no | timeStep
74  writeInterval | Steps between each write phase | no |
75  \endtable
76 
77  Time controls:
78  \table
79  Option | Description
80  timeStep | Execute/write every 'Interval' time-steps
81  writeTime | Execute/write every 'Interval' output times
82  adjustableRunTime | Execute/write every 'Interval' run time period
83  runTime | Execute/write every 'Interval' run time period
84  clockTime | Execute/write every 'Interval' clock time period
85  cpuTime | Execute/write every 'Interval' CPU time period
86  none | Execute/write every time-step
87  \endtable
88 
89  The sub-dictionary name \c <functionObjectName> is chosen by the user, and
90  is typically used as the name of the output directory for any data written
91  by the functionObject. The \c type entry defines the type of function
92  object properties that follow. FunctionObjects are packaged into separate
93  libraries and the \c libs entry is used to specify which library should be
94  loaded.
95 
96  Each functionObject has two separate run phases:
97 
98  - The \c execute phase is meant to be used for updating calculations
99  or for management tasks.
100  - The \c write phase is meant for writing the calculated data to disk.
101 
102  For each phase the respective time controls are provided, as listed above.
103 
104 Class
105  Foam::functionObject
106 
107 Description
108  Abstract base-class for Time/database functionObjects.
109 
110 See also
111  Foam::functionObjectList
112  Foam::functionObjects::timeControl
113 
114 SourceFiles
115  functionObject.C
116 
117 \*---------------------------------------------------------------------------*/
118 
119 #ifndef functionObject_H
120 #define functionObject_H
121 
122 #include "typeInfo.H"
123 #include "autoPtr.H"
124 #include "Switch.H"
125 #include "runTimeSelectionTables.H"
126 
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 
129 namespace Foam
130 {
131 
132 // Forward declaration of classes
133 class Time;
134 class polyMesh;
135 class mapPolyMesh;
136 
137 /*---------------------------------------------------------------------------*\
138  Class functionObject Declaration
139 \*---------------------------------------------------------------------------*/
140 
141 class functionObject
142 {
143  // Private Data
144 
145  //- Name
146  const word name_;
147 
148 
149 public:
150 
151  ClassName("functionObject");
152 
153  //- Runtime type information
154  virtual const word& type() const = 0;
155 
156  //- Global post-processing mode switch
157  static bool postProcess;
158 
159  //- Switch write log to Info
160  Switch log;
161 
162  //- Switch write log to Info
163  Switch executeAtStart_;
164 
165 
166  // Declare run-time constructor selection tables
167 
169  (
170  autoPtr,
172  dictionary,
173  (const word& name, const Time& runTime, const dictionary& dict),
174  (name, runTime, dict)
175  );
176 
177 
178  // Constructors
179 
180  //- Construct from components
181  functionObject(const word& name);
182 
183  //- Return clone
184  autoPtr<functionObject> clone() const
185  {
187  return autoPtr<functionObject>(nullptr);
188  }
189 
190  //- Disallow default bitwise copy construction
191  functionObject(const functionObject&) = delete;
192 
193 
194  // Selectors
195 
196  //- Select from dictionary, based on its "type" entry
197  static autoPtr<functionObject> New
198  (
199  const word& name,
200  const Time&,
201  const dictionary&
202  );
203 
204 
205  //- Destructor
206  virtual ~functionObject();
207 
208 
209  // Member Functions
210 
211  //- Return the name of this functionObject
212  const word& name() const;
213 
214  //- Read and set the functionObject if its data have changed
215  virtual bool read(const dictionary&);
216 
217  //- Return true if the functionObject should be executed at the start
218  virtual bool executeAtStart() const;
219 
220  //- Called at each ++ or += of the time-loop.
221  // postProcess overrides the usual executeControl behaviour and
222  // forces execution (used in post-processing mode)
223  virtual bool execute() = 0;
224 
225  //- Called at each ++ or += of the time-loop.
226  // postProcess overrides the usual writeControl behaviour and
227  // forces writing always (used in post-processing mode)
228  virtual bool write() = 0;
230  //- Called when Time::run() determines that the time-loop exits.
231  virtual bool end();
232 
233  //- Called by Time::adjustTimeStep(). Allows the functionObject to
234  // insert a write time earlier than that already in use by the run
235  // time. Returns the write time, or vGreat.
236  virtual scalar timeToNextWrite();
237 
238  //- Update for changes of mesh
239  virtual void updateMesh(const mapPolyMesh& mpm);
240 
241  //- Update for changes of mesh
242  virtual void movePoints(const polyMesh& mesh);
243 
244 
245  // Member Operators
246 
247  //- Disallow default bitwise assignment
248  void operator=(const functionObject&) = delete;
249 };
250 
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 
254 } // End namespace Foam
255 
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 
258 #endif
259 
260 // ************************************************************************* //
dictionary dict
virtual ~functionObject()
Destructor.
const word & name() const
Return the name of this functionObject.
static bool postProcess
Global post-processing mode switch.
engineTime & runTime
virtual bool execute()=0
Called at each ++ or += of the time-loop.
Abstract base-class for Time/database functionObjects.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
virtual bool end()
Called when Time::run() determines that the time-loop exits.
dynamicFvMesh & mesh
virtual const word & type() const =0
Runtime type information.
void operator=(const functionObject &)=delete
Disallow default bitwise assignment.
virtual bool read(const dictionary &)
Read and set the functionObject if its data have changed.
Switch executeAtStart_
Switch write log to Info.
functionObject(const word &name)
Construct from components.
static autoPtr< functionObject > New(const word &name, const Time &, const dictionary &)
Select from dictionary, based on its "type" entry.
autoPtr< functionObject > clone() const
Return clone.
virtual bool write()=0
Called at each ++ or += of the time-loop.
ClassName("functionObject")
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Macros to ease declaration of run-time selection tables.
Switch log
Switch write log to Info.
virtual scalar timeToNextWrite()
Called by Time::adjustTimeStep(). Allows the functionObject to.
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:370
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Namespace for OpenFOAM.
declareRunTimeSelectionTable(autoPtr, functionObject, dictionary,(const word &name, const Time &runTime, const dictionary &dict),(name, runTime, dict))
virtual bool executeAtStart() const
Return true if the functionObject should be executed at the start.