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-2020 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 | yes
68  startTime| Start time | no |
69  endTime | End time | no |
70  executeControl | See time controls below | no | timeStep
71  executeInterval | Steps between each execute phase | no |
72  writeControl | See time controls below | no | timeStep
73  writeInterval | Steps between each write phase | no |
74  \endtable
75 
76  Time controls:
77  \table
78  Option | Description
79  timeStep | Execute/write every 'Interval' time-steps
80  writeTime | Execute/write every 'Interval' output times
81  adjustableRunTime | Execute/write every 'Interval' run time period
82  runTime | Execute/write every 'Interval' run time period
83  clockTime | Execute/write every 'Interval' clock time period
84  cpuTime | Execute/write every 'Interval' CPU time period
85  none | Execute/write every time-step
86  \endtable
87 
88  The sub-dictionary name \c <functionObjectName> is chosen by the user, and
89  is typically used as the name of the output directory for any data written
90  by the functionObject. The \c type entry defines the type of function
91  object properties that follow. FunctionObjects are packaged into separate
92  libraries and the \c libs entry is used to specify which library should be
93  loaded.
94 
95  Each functionObject has two separate run phases:
96 
97  - The \c execute phase is meant to be used for updating calculations
98  or for management tasks.
99  - The \c write phase is meant for writing the calculated data to disk.
100 
101  For each phase the respective time controls are provided, as listed above.
102 
103 Class
104  Foam::functionObject
105 
106 Description
107  Abstract base-class for Time/database functionObjects.
108 
109 See also
110  Foam::functionObjectList
111  Foam::functionObjects::timeControl
112 
113 SourceFiles
114  functionObject.C
115 
116 \*---------------------------------------------------------------------------*/
117 
118 #ifndef functionObject_H
119 #define functionObject_H
120 
121 #include "typeInfo.H"
122 #include "autoPtr.H"
123 #include "Switch.H"
124 #include "runTimeSelectionTables.H"
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 namespace Foam
129 {
130 
131 // Forward declaration of classes
132 class Time;
133 class polyMesh;
134 class mapPolyMesh;
135 
136 /*---------------------------------------------------------------------------*\
137  Class functionObject Declaration
138 \*---------------------------------------------------------------------------*/
139 
140 class functionObject
141 {
142  // Private Data
143 
144  //- Name
145  const word name_;
146 
147 
148 public:
149 
150  ClassName("functionObject");
151 
152  //- Runtime type information
153  virtual const word& type() const = 0;
154 
155  //- Global post-processing mode switch
156  static bool postProcess;
157 
158  //- Switch write log to Info
159  Switch log;
160 
161  //- Switch write log to Info
162  Switch executeAtStart_;
163 
164 
165  // Declare run-time constructor selection tables
166 
168  (
169  autoPtr,
171  dictionary,
172  (const word& name, const Time& runTime, const dictionary& dict),
173  (name, runTime, dict)
174  );
175 
176 
177  // Constructors
178 
179  //- Construct from components
180  functionObject(const word& name);
181 
182  //- Return clone
183  autoPtr<functionObject> clone() const
184  {
186  return autoPtr<functionObject>(nullptr);
187  }
188 
189  //- Disallow default bitwise copy construction
190  functionObject(const functionObject&) = delete;
191 
192 
193  // Selectors
194 
195  //- Select from dictionary, based on its "type" entry
196  static autoPtr<functionObject> New
197  (
198  const word& name,
199  const Time&,
200  const dictionary&
201  );
202 
203 
204  //- Destructor
205  virtual ~functionObject();
206 
207 
208  // Member Functions
209 
210  //- Return the name of this functionObject
211  const word& name() const;
212 
213  //- Read and set the functionObject if its data have changed
214  virtual bool read(const dictionary&);
215 
216  //- Return true if the functionObject should be executed at the start
217  virtual bool executeAtStart() const;
218 
219  //- Called at each ++ or += of the time-loop.
220  // postProcess overrides the usual executeControl behaviour and
221  // forces execution (used in post-processing mode)
222  virtual bool execute() = 0;
224  //- Called at each ++ or += of the time-loop.
225  // postProcess overrides the usual writeControl behaviour and
226  // forces writing always (used in post-processing mode)
227  virtual bool write() = 0;
228 
229  //- Called when Time::run() determines that the time-loop exits.
230  virtual bool end();
231 
232  //- Called by Time::setDeltaT(). Allows the functionObject to override
233  // the time-step value.
234  // Returns whether or not the value was overridden.
235  virtual bool setTimeStep();
236 
237  //- Called by Time::adjustTimeStep(). Allows the functionObject to
238  // insert a write time earlier than that already in use by the run
239  // time. Returns the write time, or vGreat.
240  virtual scalar timeToNextWrite();
241 
242  //- Update for changes of mesh
243  virtual void updateMesh(const mapPolyMesh& mpm);
244 
245  //- Update for changes of mesh
246  virtual void movePoints(const polyMesh& mesh);
247 
248 
249  // Member Operators
250 
251  //- Disallow default bitwise assignment
252  void operator=(const functionObject&) = delete;
253 };
254 
255 
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 
258 } // End namespace Foam
259 
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 
262 #endif
263 
264 // ************************************************************************* //
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.
virtual bool setTimeStep()
Called by Time::setDeltaT(). Allows the functionObject to override.
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:366
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.