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-2019 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 function objects
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 function object | 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 function object 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 function objects.
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  //- Runtime type information
151  virtual const word& type() const = 0;
152 
153  static int debug;
154 
155  //- Global post-processing mode switch
156  static bool postProcess;
157 
158  //- Switch write log to Info
159  Switch log;
160 
161 
162  // Declare run-time constructor selection tables
163 
165  (
166  autoPtr,
168  dictionary,
169  (const word& name, const Time& runTime, const dictionary& dict),
170  (name, runTime, dict)
171  );
172 
173 
174  // Constructors
175 
176  //- Construct from components
177  functionObject(const word& name);
178 
179  //- Return clone
180  autoPtr<functionObject> clone() const
181  {
183  return autoPtr<functionObject>(nullptr);
184  }
185 
186  //- Disallow default bitwise copy construction
187  functionObject(const functionObject&) = delete;
188 
189 
190  // Selectors
191 
192  //- Select from dictionary, based on its "type" entry
193  static autoPtr<functionObject> New
194  (
195  const word& name,
196  const Time&,
197  const dictionary&
198  );
199 
200 
201  //- Destructor
202  virtual ~functionObject();
203 
204 
205  // Member Functions
206 
207  //- Return the name of this functionObject
208  const word& name() const;
209 
210  //- Read and set the function object if its data have changed
211  virtual bool read(const dictionary&);
212 
213  //- Called at each ++ or += of the time-loop.
214  // postProcess overrides the usual executeControl behaviour and
215  // forces execution (used in post-processing mode)
216  virtual bool execute() = 0;
217 
218  //- Called at each ++ or += of the time-loop.
219  // postProcess overrides the usual writeControl behaviour and
220  // forces writing always (used in post-processing mode)
221  virtual bool write() = 0;
222 
223  //- Called when Time::run() determines that the time-loop exits.
224  // By default it simply calls execute().
225  virtual bool end();
226 
227  //- Called by Time::setDeltaT(). Allows the function object to override
228  // the time-step value.
229  // Returns whether or not the value was overridden.
230  virtual bool setTimeStep();
231 
232  //- Called by Time::adjustTimeStep(). Allows the function object to
233  // insert a write time earlier than that already in use by the run
234  // time. Returns the write time, or vGreat.
235  virtual scalar timeToNextWrite();
237  //- Update for changes of mesh
238  virtual void updateMesh(const mapPolyMesh& mpm);
240  //- Update for changes of mesh
241  virtual void movePoints(const polyMesh& mesh);
243 
244  // Member Operators
245 
246  //- Disallow default bitwise assignment
247  void operator=(const functionObject&) = delete;
248 };
249 
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 
253 } // End namespace Foam
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 #endif
258 
259 // ************************************************************************* //
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 function objects.
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 function object to override.
void operator=(const functionObject &)=delete
Disallow default bitwise assignment.
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
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.
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 function object 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))