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-2022 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 polyTopoChangeMap;
136 class polyMeshMap;
137 
138 /*---------------------------------------------------------------------------*\
139  Class functionObject Declaration
140 \*---------------------------------------------------------------------------*/
141 
142 class functionObject
143 {
144  // Private Data
145 
146  //- Name
147  const word name_;
148 
149 
150 public:
151 
152  ClassName("functionObject");
153 
154  //- Runtime type information
155  virtual const word& type() const = 0;
156 
157  //- Global post-processing mode switch
158  static bool postProcess;
159 
160  //- Switch write log to Info
161  Switch log;
162 
163  //- Switch write log to Info
164  Switch executeAtStart_;
165 
166 
167  // Declare run-time constructor selection tables
168 
170  (
171  autoPtr,
173  dictionary,
174  (const word& name, const Time& runTime, const dictionary& dict),
175  (name, runTime, dict)
176  );
177 
178 
179  // Constructors
180 
181  //- Construct from components
182  functionObject(const word& name);
183 
184  //- Return clone
185  autoPtr<functionObject> clone() const
186  {
188  return autoPtr<functionObject>(nullptr);
189  }
190 
191  //- Disallow default bitwise copy construction
192  functionObject(const functionObject&) = delete;
193 
194 
195  // Selectors
196 
197  //- Select from dictionary, based on its "type" entry
198  static autoPtr<functionObject> New
199  (
200  const word& name,
201  const Time&,
202  const dictionary&
203  );
204 
205 
206  //- Destructor
207  virtual ~functionObject();
208 
209 
210  // Member Functions
211 
212  //- Return the name of this functionObject
213  const word& name() const;
214 
215  //- Read and set the functionObject if its data have changed
216  virtual bool read(const dictionary&);
217 
218  //- Return the list of fields required
219  virtual wordList fields() const = 0;
220 
221  //- Return true if the functionObject should be executed at the start
222  virtual bool executeAtStart() const;
223 
224  //- Called at each ++ or += of the time-loop.
225  // postProcess overrides the usual executeControl behaviour and
226  // forces execution (used in post-processing mode)
227  virtual bool execute() = 0;
228 
229  //- Called at each ++ or += of the time-loop.
230  // postProcess overrides the usual writeControl behaviour and
231  // forces writing always (used in post-processing mode)
232  virtual bool write() = 0;
233 
234  //- Called when Time::run() determines that the time-loop exits.
235  virtual bool end();
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 topology using the given map
243  virtual void movePoints(const polyMesh& mesh);
244 
245  //- Update topology using the given map
246  virtual void topoChange(const polyTopoChangeMap& map);
247 
248  //- Update from another mesh using the given map
249  virtual void mapMesh(const polyMeshMap&);
250 
251 
252  // Member Operators
253 
254  //- Disallow default bitwise assignment
255  void operator=(const functionObject&) = delete;
256 };
257 
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 } // End namespace Foam
262 
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 
265 #endif
266 
267 // ************************************************************************* //
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
dictionary dict
virtual wordList fields() const =0
Return the list of fields required.
virtual ~functionObject()
Destructor.
const word & name() const
Return the name of this functionObject.
static bool postProcess
Global post-processing mode switch.
virtual bool execute()=0
Called at each ++ or += of the time-loop.
virtual void topoChange(const polyTopoChangeMap &map)
Update topology using the given map.
Abstract base-class for Time/database functionObjects.
fvMesh & mesh
virtual bool end()
Called when Time::run() determines that the time-loop exits.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
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.
List< word > wordList
A List of words.
Definition: fileName.H:54
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:76
Macros to ease declaration of run-time selection tables.
Switch log
Switch write log to Info.
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:50
virtual scalar timeToNextWrite()
Called by Time::adjustTimeStep(). Allows the functionObject to.
virtual void movePoints(const polyMesh &mesh)
Update topology using the given map.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
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.