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 execute at start time
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  //- Construct from dictionary
191  (
192  const word& name,
193  const Time& runTime,
194  const dictionary& dict
195  );
196 
197  //- Return clone
198  autoPtr<functionObject> clone() const
199  {
201  return autoPtr<functionObject>(nullptr);
202  }
203 
204  //- Disallow default bitwise copy construction
205  functionObject(const functionObject&) = delete;
206 
207 
208  // Selectors
209 
210  //- Select from dictionary, based on its "type" entry
211  static autoPtr<functionObject> New
212  (
213  const word& name,
214  const Time&,
215  const dictionary&
216  );
217 
218 
219  //- Destructor
220  virtual ~functionObject();
221 
222 
223  // Member Functions
224 
225  //- Return the name of this functionObject
226  const word& name() const;
227 
228  //- Read and set the functionObject if its data have changed
229  virtual bool read(const dictionary&);
230 
231  //- Return the list of fields required
232  virtual wordList fields() const = 0;
233 
234  //- Return true if the functionObject should be executed at the start
235  virtual bool executeAtStart() const;
236 
237  //- Called at each ++ or += of the time-loop.
238  // foamPostProcess overrides the usual executeControl behaviour and
239  // forces execution (used in post-processing mode)
240  virtual bool execute() = 0;
241 
242  //- Called at each ++ or += of the time-loop.
243  // foamPostProcess overrides the usual writeControl behaviour and
244  // forces writing always (used in post-processing mode)
245  virtual bool write() = 0;
246 
247  //- Called when Time::run() determines that the time-loop exits.
248  virtual bool end();
249 
250  //- Called by Time::adjustTimeStep(). Allows the functionObject to
251  // insert a write time earlier than that already in use by the run
252  // time. Returns the write time, or vGreat.
253  virtual scalar timeToNextAction();
254 
255  //- Return the maximum time-step for stable operation
256  virtual scalar maxDeltaT() const;
257 
258  //- Update topology using the given map
259  virtual void movePoints(const polyMesh& mesh);
260 
261  //- Update topology using the given map
262  virtual void topoChange(const polyTopoChangeMap& map);
263 
264  //- Update from another mesh using the given map
265  virtual void mapMesh(const polyMeshMap&);
266 
267  //- Redistribute or update using the given distribution map
268  virtual void distribute(const polyDistributionMap&);
269 
270 
271  // Member Operators
272 
273  //- Disallow default bitwise assignment
274  void operator=(const functionObject&) = delete;
275 };
276 
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 } // End namespace Foam
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 #endif
285 
286 // ************************************************************************* //
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 execute at start time.
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.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#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...