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-2024 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  functionObjects are selected by entries in the $FOAM_CASE/system/functions
36  dictionary e.g. to select the \c functionObjectType functionObject the
37  following entry would be specified:
38 
39  \verbatim
40  <functionObjectName>
41  {
42  type functionObjectType;
43  libs ("libMyFunctionObjectlib.so");
44  region defaultRegion;
45  enabled yes;
46  startTime 0;
47  endTime 10;
48  writeControl writeTime;
49  writeInterval 1;
50  ...
51  }
52  \endverbatim
53 
54  Where:
55  \table
56  Property | Description | Required | Default value
57  type | Type of functionObject | yes |
58  libs | Shared libraries | no |
59  region | Name of region | no |
60  enabled | On/off switch | no | yes
61  log | Print data to log | no | no
62  startTime | Start time | no |
63  endTime | End time | no |
64  executeAtStart | Execute at start time switch | no | yes
65  executeControl | See time controls below | no | timeStep
66  executeInterval | Steps between each execution | no |
67  executeTimes | List of execution times | no |
68  writeControl | See time controls below | no | timeStep
69  writeInterval | Steps between each write | no |
70  writeTimes | List of write times | no |
71  writeFrequencies | List of write frequencies | no |
72  \endtable
73 
74  Time controls:
75  \table
76  Option | Description
77  timeStep | Execute/write every 'Interval' time-steps
78  writeTime | Execute/write every 'Interval' write times
79  adjustableRunTime | Execute/write every 'Interval' run time period
80  runTime | Execute/write every 'Interval' run time period
81  runTimes | Execute/write at specified list of run times
82  clockTime | Execute/write every 'Interval' clock time period
83  cpuTime | Execute/write every 'Interval' CPU time period
84  none | No execution
85  \endtable
86 
87  The sub-dictionary name \c <functionObjectName> is chosen by the user, and
88  is typically used as the name of the output directory for any data written
89  by the functionObject. The \c type entry defines the type of function
90  object properties that follow. FunctionObjects are packaged into separate
91  libraries and the \c libs entry is used to specify which library should be
92  loaded.
93 
94  Each functionObject has two separate run phases:
95 
96  - The \c execute phase is meant to be used for updating calculations
97  or for management tasks.
98  - The \c write phase is meant for writing the calculated data to disk.
99 
100  For each phase the respective time controls are provided, as listed above.
101 
102 Class
103  Foam::functionObject
104 
105 Description
106  Abstract base-class for Time/database functionObjects.
107 
108 See also
109  Foam::functionObjectList
110  Foam::functionObjects::timeControl
111 
112 SourceFiles
113  functionObject.C
114 
115 \*---------------------------------------------------------------------------*/
116 
117 #ifndef functionObject_H
118 #define functionObject_H
119 
120 #include "typeInfo.H"
121 #include "autoPtr.H"
122 #include "Switch.H"
123 #include "runTimeSelectionTables.H"
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 namespace Foam
128 {
129 
130 // Forward declaration of classes
131 class Time;
132 class polyMesh;
133 class polyTopoChangeMap;
134 class polyMeshMap;
135 class polyDistributionMap;
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 protected:
150 
151  //- Reference to time
152  const Time& time_;
153 
154 
155 public:
156 
157  ClassName("functionObject");
158 
159  //- Runtime type information
160  virtual const word& type() const = 0;
161 
162  //- Global post-processing mode switch
163  static bool postProcess;
164 
165  //- Switch write log to Info
166  Switch log;
167 
168  //- Switch write log to Info
169  Switch executeAtStart_;
170 
171 
172  // Declare run-time constructor selection tables
173 
175  (
176  autoPtr,
178  dictionary,
179  (const word& name, const Time& runTime, const dictionary& dict),
180  (name, runTime, dict)
181  );
182 
183 
184  // Constructors
185 
186  //- Construct from components
187  functionObject(const word& name, const Time& runTime);
188 
189  //- Return clone
190  autoPtr<functionObject> clone() const
191  {
193  return autoPtr<functionObject>(nullptr);
194  }
195 
196  //- Disallow default bitwise copy construction
197  functionObject(const functionObject&) = delete;
198 
199 
200  // Selectors
201 
202  //- Select from dictionary, based on its "type" entry
203  static autoPtr<functionObject> New
204  (
205  const word& name,
206  const Time&,
207  const dictionary&
208  );
209 
210 
211  //- Destructor
212  virtual ~functionObject();
213 
214 
215  // Member Functions
216 
217  //- Return the name of this functionObject
218  const word& name() const;
219 
220  //- Read and set the functionObject if its data have changed
221  virtual bool read(const dictionary&);
222 
223  //- Return the list of fields required
224  virtual wordList fields() const = 0;
225 
226  //- Return true if the functionObject should be executed at the start
227  virtual bool executeAtStart() const;
228 
229  //- Called at each ++ or += of the time-loop.
230  // foamPostProcess overrides the usual executeControl behaviour and
231  // forces execution (used in post-processing mode)
232  virtual bool execute() = 0;
233 
234  //- Called at each ++ or += of the time-loop.
235  // foamPostProcess overrides the usual writeControl behaviour and
236  // forces writing always (used in post-processing mode)
237  virtual bool write() = 0;
238 
239  //- Called when Time::run() determines that the time-loop exits.
240  virtual bool end();
241 
242  //- Called by Time::adjustTimeStep(). Allows the functionObject to
243  // insert a write time earlier than that already in use by the run
244  // time. Returns the write time, or vGreat.
245  virtual scalar timeToNextAction();
246 
247  //- Return the maximum time-step for stable operation
248  virtual scalar maxDeltaT() const;
249 
250  //- Update topology using the given map
251  virtual void movePoints(const polyMesh& mesh);
252 
253  //- Update topology using the given map
254  virtual void topoChange(const polyTopoChangeMap& map);
255 
256  //- Update from another mesh using the given map
257  virtual void mapMesh(const polyMeshMap&);
258 
259  //- Redistribute or update using the given distribution map
260  virtual void distribute(const polyDistributionMap&);
261 
262 
263  // Member Operators
264 
265  //- Disallow default bitwise assignment
266  void operator=(const functionObject&) = delete;
267 };
268 
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 } // End namespace Foam
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 #endif
277 
278 // ************************************************************************* //
Abstract base-class for Time/database functionObjects.
Switch log
Switch write log to Info.
virtual const word & type() const =0
Runtime type information.
const Time & time_
Reference to time.
functionObject(const word &name, const Time &runTime)
Construct from components.
virtual ~functionObject()
Destructor.
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.
autoPtr< functionObject > clone() const
Return clone.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual scalar maxDeltaT() const
Return the maximum time-step for stable operation.
virtual void movePoints(const polyMesh &mesh)
Update topology using the given map.
virtual bool execute()=0
Called at each ++ or += of the time-loop.
ClassName("functionObject")
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual wordList fields() const =0
Return the list of fields required.
void operator=(const functionObject &)=delete
Disallow default bitwise assignment.
Switch executeAtStart_
Switch write log to Info.
static autoPtr< functionObject > New(const word &name, const Time &, const dictionary &)
Select from dictionary, based on its "type" entry.
static bool postProcess
Global post-processing mode switch.
virtual scalar timeToNextAction()
Called by Time::adjustTimeStep(). Allows the functionObject to.
const word & name() const
Return the name of this functionObject.
virtual void topoChange(const polyTopoChangeMap &map)
Update topology using the given map.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
virtual bool read(const dictionary &)
Read and set the functionObject if its data have changed.
virtual bool write()=0
Called at each ++ or += of the time-loop.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
Macros to ease declaration of run-time selection tables.
dictionary dict
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...