Loading...
Searching...
No Matches
functionObjectList.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2015-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::functionObjectList
29
30Description
31 List of function objects with start(), execute() and end() functions
32 that is called for each object.
33
34 \verbatim
35 functions // sub-dictionary name under the system/controlDict file
36 {
37 ..optional entries..
38
39 <userDict1>
40 {
41 // Mandatory entries
42 type <typeName>;
43 libs (<libName> .. <libName>);
44 ...
45 }
46
47 <userDict2>
48 {
49 ...
50 }
51
52 ...
53 }
54 \endverbatim
55
56 with optional entries:
57 \table
58 Property | Description | Type | Reqd | Deflt
59 libs | Preloaded library names | words | no | -
60 errors | Error handling (default/warn/ignore/strict) | word | no | inherits
61 useNamePrefix | Default enable/disable scoping prefix | bool | no | no-op
62 \endtable
63
64 The optional \c errors entry controls how FatalError is caught
65 during construction and execute/write. FatalIOError is unaffected.
66 <br>
67 Behaviour for \c errors enumerations:
68 \table
69 Enum | Error on construction | Runtime error
70 default | warn | fatal
71 warn | warn | warn
72 ignore | silent | silent
73 strict | fatal | fatal
74 \endtable
75
76See also
77 Foam::functionObject
78 Foam::functionObjects::timeControl
79
80SourceFiles
81 functionObjectList.C
82
83\*---------------------------------------------------------------------------*/
84
85#ifndef Foam_functionObjectList_H
86#define Foam_functionObjectList_H
87
88#include "PtrList.H"
89#include "functionObject.H"
90#include "SHA1Digest.H"
91#include "HashTable.H"
92#include "IOdictionary.H"
93#include "HashSet.H"
95
96// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97
98namespace Foam
99{
100
101// Forward Declarations
102class argList;
103class mapPolyMesh;
104class wordRe;
105
106/*---------------------------------------------------------------------------*\
107 Class functionObjectList Declaration
108\*---------------------------------------------------------------------------*/
109
111:
112 private PtrList<functionObject>
113{
114 // Private Data
115
116 //- A list of error/warning handling
117 List<error::handlerTypes> errorHandling_;
118
119 //- A list of SHA1 digests for the function object dictionaries
120 List<SHA1Digest> digests_;
121
122 //- Quick lookup of the index into functions/digests/errorHandling
123 HashTable<label> indices_;
124
125 //- Track the number of warnings per function object and limit
126 // to a predefined number to avoid flooding the display.
127 // Clear on re-read of functions.
128 HashTable<unsigned> warnings_;
129
130 //- Reference to Time
131 const Time& time_;
132
133 //- The parent dictionary containing a "functions" sub-dictionary
134 //- of functionObject specifications
135 const dictionary& parentDict_;
136
137 //- Function object properties - stores state information
138 mutable autoPtr<functionObjects::properties> propsDictPtr_;
139
140 //- Function objects output registry
141 mutable autoPtr<objectRegistry> objectsRegistryPtr_;
142
143 //- Switch for the execution of the functionObjects
144 bool execution_;
145
146 //- Tracks if read() was called while execution is on
147 bool updated_;
148
150 // Private Member Functions
151
152 //- List of functions
153 const PtrList<functionObject>& functions() const { return *this; }
154
155 //- List of functions
156 PtrList<functionObject>& functions() { return *this; }
157
158 //- Create properties dictionary - attached to Time.
159 void createPropertiesDict() const;
160
161 //- Create registry for output objects - attached to Time.
162 void createOutputRegistry() const;
163
164 //- Remove and return the function object pointer by name,
165 //- and returns the old index (into digest) via the parameter.
166 // Returns nullptr (and index -1) if it didn't exist
167 autoPtr<functionObject> remove(const word& key, label& oldIndex);
168
169 //- Search the specified directory for functionObject
170 //- configuration files, add to the given map and recurse
171 static void listDir(const fileName& dir, wordHashSet& available);
172
173 //- Like Enum::getOrDefault, but with additional code to warn if
174 //- the 'key' is not a primitive entry.
175 //
176 // This additional treatment is to ensure that potentially existing
177 // code with an "errors" functionObject will continue to run.
178 error::handlerTypes getOrDefaultErrorHandling
179 (
180 const word& key,
181 const dictionary& dict,
182 const error::handlerTypes deflt
183 ) const;
184
185
186 //- No copy construct
187 functionObjectList(const functionObjectList&) = delete;
188
189 //- No copy assignment
190 void operator=(const functionObjectList&) = delete;
191
192
193public:
194
195 // Static data members
196
197 //- Default relative path ("caseDicts/postProcessing") to the
198 //- directory structure containing functionObject dictionary files.
199 static fileName functionObjectDictPath;
200
201
202 // Constructors
203
204 //- Construct from Time and the execution setting.
205 // The functionObject specifications are read from the controlDict
206 functionObjectList
207 (
208 const Time& runTime,
209 const bool execution=true
210 );
211
212 //- Construct from Time, a dictionary with a "functions" entry
213 //- and the execution setting.
214 // \param[in] runTime - the other Time instance to construct from
215 // \param[in] parentDict - the parent dictionary containing
216 // a "functions" sub-dictionary of functionObject specifications.
217 // \param[in] execution - whether the function objects should execute
218 // or not. Default: true.
219 functionObjectList
220 (
221 const Time& runTime,
222 const dictionary& parentDict,
223 const bool execution=true
224 );
225
226 //- Construct and return a functionObjectList for an application.
227 // If the "dict" argument is specified the functionObjectList is
228 // constructed from that dictionary which is returned as
229 // controlDict otherwise the functionObjectList is constructed
230 // from the "functions" sub-dictionary of "system/controlDict"
231 static autoPtr<functionObjectList> New
232 (
233 const argList& args,
234 const Time& runTime,
236 HashSet<wordRe>& requiredFields
237 );
238
239
240 //- Destructor
241 ~functionObjectList() = default;
242
243
244 // Member Functions
245
246 //- Return the number of elements in the List.
247 using PtrList<functionObject>::size;
248
249 //- Return true if the List is empty (ie, size() is zero).
250 using PtrList<functionObject>::empty;
251
252 //- Access to the functionObjects
253 using PtrList<functionObject>::operator[];
254
255 //- Return the current trigger index (read from the propsDict)
256 label triggerIndex() const;
257
258 //- Reset/read properties dictionary for current time
259 void resetPropertiesDict();
260
261 //- Write access to the properties dictionary
262 //- ("functionObjectProperties") registered on Time
263 functionObjects::properties& propsDict();
264
265 //- Const access to the properties dictionary
266 //- ("functionObjectProperties") registered on Time
268
269 //- Write access to the output objects ("functionObjectObjects")
270 //- registered on Time
271 objectRegistry& storedObjects();
272
273 //- Const access to the output objects ("functionObjectObjects")
274 //- registered on Time
275 const objectRegistry& storedObjects() const;
276
277 //- Clear the list of function objects
278 void clear();
279
280 //- Find the ID of a given function object by name, -1 if not found.
281 label findObjectID(const word& objName) const;
282
283 //- Print a list of functionObject configuration files in the
284 //- directories located using
285 //- Foam::findEtcDirs("caseDicts/postProcessing")
286 //
287 // -# \b user settings
288 // - ~/.OpenFOAM/{PROJECT_API}/"caseDicts/postProcessing"
289 // - ~/.OpenFOAM/"caseDicts/postProcessing"
290 // -# \b group settings
291 // - $WM_PROJECT_SITE/{PROJECT_API}/"etc/caseDicts/postProcessing"
292 // - $WM_PROJECT_SITE/"etc/caseDicts/postProcessing"
293 // -# \b other (shipped) settings
294 // - $WM_PROJECT_DIR/etc/"caseDicts/postProcessing"
295 //
296 // Where {PROJECT_API} is the value of the OPENFOAM define.
297 // See further notes in Foam::findEtcEntries()
298 static void list();
299
300 //- Find a functionObject dictionary file in the case
301 //- <system> directory or any directory located using
302 //- Foam::findEtcDirs("caseDicts/postProcessing")
303 //
304 // \return The path of the functionObject dictionary file found
305 // or an empty path
306 static fileName findDict(const word& funcName);
307
308 //- Read the specified functionObject configuration dictionary parsing
309 //- the optional arguments included in the name 'funcNameArgs0',
310 //- inserting 'field' or 'fields' entries as required and merging the
311 //- resulting functionObject dictionary into 'functionsDict'. Any
312 //- fields required to execute the functionObject are added to
313 //- 'requiredFields'
314 //
315 // Uses functionObjectList::findDict() for searching
316 static bool readFunctionObject
317 (
318 const string& funcNameArgs0,
319 dictionary& functionsDict,
320 HashSet<wordRe>& requiredFields,
321 const word& region = word::null
322 );
323
324 //- Read and set the function objects if their data have changed
325 bool read();
326
327 //- Switch the function objects on
328 void on();
329
330 //- Switch the function objects off
331 void off();
332
333 //- Return the execution status (on/off) of the function objects
334 bool status() const;
335
336 //- Called at the start of the time-loop
337 bool start();
338
339 //- Called at each ++ or += of the time-loop.
340 // postProcess overrides the usual executeControl behaviour and
341 // forces execution (used in post-processing mode)
342 bool execute(bool writeProperties = true);
343
344 //- Execute function objects using the specified subIndex.
345 // \param subIndex an execution sub-index corresponding to a
346 // sub-cycle or something similar
347 bool execute(const label subIndex);
348
349 //- Execute a subset of function objects using the specified subIndex.
350 // \param functionNames names or regex of existing functions to
351 // execute
352 // \param subIndex an execution sub-index corresponding to a
353 // sub-cycle or something similar
354 bool execute(const UList<wordRe>& functionNames, const label subIndex);
355
356 //- Called when Time::run() determines that the time-loop exits
357 bool end();
358
359 //- Called at the end of Time::adjustDeltaT() if adjustTime is true
360 bool adjustTimeStep();
361
362 //- Did any file get changed during execution?
363 bool filesModified() const;
364
365 //- Update for changes of mesh
366 void updateMesh(const mapPolyMesh& mpm);
367
368 //- Update for changes of mesh
369 void movePoints(const polyMesh& mesh);
370};
371
372
373// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374
375} // End namespace Foam
376
377// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
378
379#endif
380
381// ************************************************************************* //
A HashTable with keys but without contents that is similar to std::unordered_set.
Definition HashSet.H:96
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
constexpr PtrList() noexcept
Definition PtrListI.H:29
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
bool empty() const noexcept
Definition UPtrListI.H:99
label size() const noexcept
Definition UPtrListI.H:106
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
handlerTypes
Handling of errors. The exact handling depends on the local context.
Definition error.H:110
A class for handling file names.
Definition fileName.H:75
List of function objects with start(), execute() and end() functions that is called for each object.
static fileName findDict(const word &funcName)
Find a functionObject dictionary file in the case <system> directory or any directory located using F...
void off()
Switch the function objects off.
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict, HashSet< wordRe > &requiredFields)
Construct and return a functionObjectList for an application.
objectRegistry & storedObjects()
Write access to the output objects ("functionObjectObjects") registered on Time.
bool filesModified() const
Did any file get changed during execution?
void movePoints(const polyMesh &mesh)
Update for changes of mesh.
label findObjectID(const word &objName) const
Find the ID of a given function object by name, -1 if not found.
bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
static void list()
Print a list of functionObject configuration files in the directories located using Foam::findEtcDirs...
bool start()
Called at the start of the time-loop.
bool execute(bool writeProperties=true)
Called at each ++ or += of the time-loop.
void clear()
Clear the list of function objects.
void resetPropertiesDict()
Reset/read properties dictionary for current time.
functionObjects::properties & propsDict()
Write access to the properties dictionary ("functionObjectProperties") registered on Time.
bool status() const
Return the execution status (on/off) of the function objects.
label triggerIndex() const
Return the current trigger index (read from the propsDict).
~functionObjectList()=default
Destructor.
static bool readFunctionObject(const string &funcNameArgs0, dictionary &functionsDict, HashSet< wordRe > &requiredFields, const word &region=word::null)
Read the specified functionObject configuration dictionary parsing the optional arguments included in...
static fileName functionObjectDictPath
Default relative path ("caseDicts/postProcessing") to the directory structure containing functionObje...
bool end()
Called when Time::run() determines that the time-loop exits.
void on()
Switch the function objects on.
bool read()
Read and set the function objects if their data have changed.
Abstract base-class for Time/database function objects.
Storage for function object properties, derived from IOdictionary. Provides functionality to read/wri...
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Registry of regIOobjects.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition wordRe.H:81
A class for handling words, derived from Foam::string.
Definition word.H:66
static const word null
An empty word.
Definition word.H:84
runTime controlDict().readEntry("adjustTimeStep"
dynamicFvMesh & mesh
engineTime & runTime
Namespace for OpenFOAM.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition HashSet.H:80
dictionary dict
Foam::argList args(argc, argv)