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-2018 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  timeStart 0;
52  timeEnd 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  timeStart| Start time | no |
69  timeEnd | 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  // Private Member Functions
149 
150  //- Disallow default bitwise copy construct
151  functionObject(const functionObject&);
152 
153  //- Disallow default bitwise assignment
154  void operator=(const functionObject&);
155 
156 
157 public:
158 
159  //- Runtime type information
160  virtual const word& type() const = 0;
161 
162  static int debug;
163 
164  //- Global post-processing mode switch
165  static bool postProcess;
166 
167  //- Switch write log to Info
168  Switch log;
169 
170 
171  // Declare run-time constructor selection tables
172 
174  (
175  autoPtr,
176  functionObject,
177  dictionary,
178  (const word& name, const Time& runTime, const dictionary& dict),
179  (name, runTime, dict)
180  );
181 
182 
183  // Constructors
184 
185  //- Construct from components
186  functionObject(const word& name);
187 
188  //- Return clone
189  autoPtr<functionObject> clone() const
190  {
192  return autoPtr<functionObject>(nullptr);
193  }
194 
195 
196  // Selectors
197 
198  //- Select from dictionary, based on its "type" entry
199  static autoPtr<functionObject> New
200  (
201  const word& name,
202  const Time&,
203  const dictionary&
204  );
205 
206 
207  //- Destructor
208  virtual ~functionObject();
209 
210 
211  // Member Functions
212 
213  //- Return the name of this functionObject
214  const word& name() const;
215 
216  //- Read and set the function object if its data have changed
217  virtual bool read(const dictionary&);
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  // By default it simply calls execute().
231  virtual bool end();
232 
233  //- Called by Time::setDeltaT(). Allows the function object to override
234  // the time-step value.
235  // Returns whether or not the value was overridden.
236  virtual bool setTimeStep();
237 
238  //- Called by Time::adjustTimeStep(). Allows the function object to
239  // insert a write time earlier than that already in use by the run
240  // time. Returns the write time, or vGreat.
241  virtual scalar timeToNextWrite();
242 
243  //- Update for changes of mesh
244  virtual void updateMesh(const mapPolyMesh& mpm);
246  //- Update for changes of mesh
247  virtual void movePoints(const polyMesh& mesh);
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.
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.
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
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))