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-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::functionObjectList
29 
30 Description
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  - \c default : warn on construction errors, fatal on runtime errors
67  - \c warn : warn on construction and runtime errors
68  - \c ignore : ignore construction and runtime errors
69  - \c strict : fatal on construction and runtime errors
70  .
71 
72 See also
73  Foam::functionObject
74  Foam::functionObjects::timeControl
75 
76 SourceFiles
77  functionObjectList.C
78 
79 \*---------------------------------------------------------------------------*/
80 
81 #ifndef functionObjectList_H
82 #define functionObjectList_H
83 
84 #include "PtrList.H"
85 #include "Enum.H"
86 #include "functionObject.H"
87 #include "SHA1Digest.H"
88 #include "HashTable.H"
89 #include "IOdictionary.H"
90 #include "HashSet.H"
92 
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 
95 namespace Foam
96 {
97 
98 // Forward Declarations
99 class argList;
100 class mapPolyMesh;
101 class wordRe;
102 
103 /*---------------------------------------------------------------------------*\
104  Class functionObjectList Declaration
105 \*---------------------------------------------------------------------------*/
106 
107 class functionObjectList
108 :
109  private PtrList<functionObject>
110 {
111  // Data Types
112 
113  //- Handling of construction or execution errors
114  enum class errorHandlingType : uint8_t
115  {
116  DEFAULT = 0,
117  WARN,
118  IGNORE,
119  STRICT,
120  };
121 
122  //- Names for error handling types
123  static const Enum<errorHandlingType> errorHandlingNames_;
124 
125 
126  // Private Data
127 
128  //- A list of error/warning handling
129  List<errorHandlingType> errorHandling_;
130 
131  //- A list of SHA1 digests for the function object dictionaries
132  List<SHA1Digest> digests_;
133 
134  //- Quick lookup of the index into functions/digests/errorHandling
135  HashTable<label> indices_;
136 
137  //- Track the number of warnings per function object and limit
138  // to a predefined number to avoid flooding the display.
139  // Clear on re-read of functions.
140  HashTable<uint32_t> warnings_;
141 
142  //- Reference to Time
143  const Time& time_;
144 
145  //- The parent dictionary containing a "functions" sub-dictionary
146  //- of functionObject specifications
147  const dictionary& parentDict_;
148 
149  //- Function object properties - stores state information
150  mutable autoPtr<functionObjects::properties> propsDictPtr_;
151 
152  //- Function objects output registry
153  mutable autoPtr<objectRegistry> objectsRegistryPtr_;
154 
155  //- Switch for the execution of the functionObjects
156  bool execution_;
157 
158  //- Tracks if read() was called while execution is on
159  bool updated_;
160 
161 
162  // Private Member Functions
163 
164  //- List of functions
165  const PtrList<functionObject>& functions() const { return *this; }
166 
167  //- List of functions
168  PtrList<functionObject>& functions() { return *this; }
169 
170  //- Create properties dictionary - attached to Time.
171  void createPropertiesDict() const;
172 
173  //- Create registry for output objects - attached to Time.
174  void createOutputRegistry() const;
175 
176  //- Remove and return the function object pointer by name,
177  //- and returns the old index (into digest) via the parameter.
178  // Returns nullptr (and index -1) if it didn't exist
179  autoPtr<functionObject> remove(const word& key, label& oldIndex);
180 
181  //- Search the specified directory for functionObject
182  //- configuration files, add to the given map and recurse
183  static void listDir(const fileName& dir, wordHashSet& available);
184 
185  //- Like Enum::getOrDefault, but with additional code to warn if
186  //- the 'key' is not a primitive entry.
187  //
188  // This additional treatment is to ensure that potentially existing
189  // code with an "errors" functionObject will continue to run.
190  errorHandlingType getOrDefaultErrorHandling
191  (
192  const word& key,
193  const dictionary& dict,
194  const errorHandlingType deflt
195  ) const;
196 
197 
198  //- No copy construct
199  functionObjectList(const functionObjectList&) = delete;
200 
201  //- No copy assignment
202  void operator=(const functionObjectList&) = delete;
203 
204 
205 public:
206 
207  // Static data members
208 
209  //- Default relative path ("caseDicts/postProcessing") to the
210  //- directory structure containing functionObject dictionary files.
211  static fileName functionObjectDictPath;
212 
213 
214  // Constructors
215 
216  //- Construct from Time and the execution setting.
217  // The functionObject specifications are read from the controlDict
218  functionObjectList
219  (
220  const Time& runTime,
221  const bool execution=true
222  );
223 
224  //- Construct from Time, a dictionary with a "functions" entry
225  //- and the execution setting.
226  // \param[in] runTime - the other Time instance to construct from
227  // \param[in] parentDict - the parent dictionary containing
228  // a "functions" sub-dictionary of functionObject specifications.
229  // \param[in] execution - whether the function objects should execute
230  // or not. Default: true.
231  functionObjectList
232  (
233  const Time& runTime,
234  const dictionary& parentDict,
235  const bool execution=true
236  );
237 
238  //- Construct and return a functionObjectList for an application.
239  // If the "dict" argument is specified the functionObjectList is
240  // constructed from that dictionary which is returned as
241  // controlDict otherwise the functionObjectList is constructed
242  // from the "functions" sub-dictionary of "system/controlDict"
244  (
245  const argList& args,
246  const Time& runTime,
248  HashSet<wordRe>& requiredFields
249  );
250 
251 
252  //- Destructor
253  ~functionObjectList() = default;
254 
255 
256  // Member Functions
257 
258  //- Return the number of elements in the List.
260 
261  //- Return true if the List is empty (ie, size() is zero).
263 
264  //- Access to the functionObjects
266 
267  //- Return the current trigger index (read from the propsDict)
268  label triggerIndex() const;
269 
270  //- Reset/read properties dictionary for current time
271  void resetPropertiesDict();
272 
273  //- Write access to the properties dictionary
274  //- ("functionObjectProperties") registered on Time
276 
277  //- Const access to the properties dictionary
278  //- ("functionObjectProperties") registered on Time
280 
281  //- Write access to the output objects ("functionObjectObjects")
282  //- registered on Time
284 
285  //- Const access to the output objects ("functionObjectObjects")
286  //- registered on Time
287  const objectRegistry& storedObjects() const;
288 
289  //- Clear the list of function objects
290  void clear();
291 
292  //- Find the ID of a given function object by name, -1 if not found.
293  label findObjectID(const word& objName) const;
294 
295  //- Print a list of functionObject configuration files in the
296  //- directories located using
297  //- Foam::findEtcDirs("caseDicts/postProcessing")
298  //
299  // -# \b user settings
300  // - ~/.OpenFOAM/{PROJECT_API}/"caseDicts/postProcessing"
301  // - ~/.OpenFOAM/"caseDicts/postProcessing"
302  // -# \b group settings
303  // - $WM_PROJECT_SITE/{PROJECT_API}/"etc/caseDicts/postProcessing"
304  // - $WM_PROJECT_SITE/"etc/caseDicts/postProcessing"
305  // -# \b other (shipped) settings
306  // - $WM_PROJECT_DIR/etc/"caseDicts/postProcessing"
307  //
308  // Where {PROJECT_API} is the value of the OPENFOAM define.
309  // See further notes in Foam::findEtcEntries()
310  static void list();
311 
312  //- Find a functionObject dictionary file in the case
313  //- <system> directory or any directory located using
314  //- Foam::findEtcDirs("caseDicts/postProcessing")
315  //
316  // \return The path of the functionObject dictionary file found
317  // or an empty path
318  static fileName findDict(const word& funcName);
319 
320  //- Read the specified functionObject configuration dictionary parsing
321  //- the optional arguments included in the name 'funcNameArgs0',
322  //- inserting 'field' or 'fields' entries as required and merging the
323  //- resulting functionObject dictionary into 'functionsDict'. Any
324  //- fields required to execute the functionObject are added to
325  //- 'requiredFields'
326  //
327  // Uses functionObjectList::findDict() for searching
328  static bool readFunctionObject
329  (
330  const string& funcNameArgs0,
331  dictionary& functionsDict,
332  HashSet<wordRe>& requiredFields,
333  const word& region = word::null
334  );
335 
336  //- Read and set the function objects if their data have changed
337  bool read();
338 
339  //- Switch the function objects on
340  void on();
341 
342  //- Switch the function objects off
343  void off();
344 
345  //- Return the execution status (on/off) of the function objects
346  bool status() const;
347 
348  //- Called at the start of the time-loop
349  bool start();
350 
351  //- Called at each ++ or += of the time-loop.
352  // postProcess overrides the usual executeControl behaviour and
353  // forces execution (used in post-processing mode)
354  bool execute();
355 
356  //- Execute function objects using the specified subIndex.
357  // \param subIndex an execution sub-index corresponding to a
358  // sub-cycle or something similar
359  bool execute(const label subIndex);
360 
361  //- Execute a subset of function objects using the specified subIndex.
362  // \param functionNames names or regex of existing functions to
363  // execute
364  // \param subIndex an execution sub-index corresponding to a
365  // sub-cycle or something similar
366  bool execute(const UList<wordRe>& functionNames, const label subIndex);
367 
368  //- Called when Time::run() determines that the time-loop exits
369  bool end();
370 
371  //- Called at the end of Time::adjustDeltaT() if adjustTime is true
372  bool adjustTimeStep();
373 
374  //- Did any file get changed during execution?
375  bool filesModified() const;
376 
377  //- Update for changes of mesh
378  void updateMesh(const mapPolyMesh& mpm);
379 
380  //- Update for changes of mesh
381  void movePoints(const polyMesh& mesh);
382 };
383 
384 
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
386 
387 } // End namespace Foam
388 
389 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
390 
391 #endif
392 
393 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjectList::movePoints
void movePoints(const polyMesh &mesh)
Update for changes of mesh.
Definition: functionObjectList.C:1233
Foam::functionObjectList::list
static void list()
Definition: functionObjectList.C:192
Foam::Enum< errorHandlingType >
Foam::functionObjectList::status
bool status() const
Return the execution status (on/off) of the function objects.
Definition: functionObjectList.C:612
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObjectList::adjustTimeStep
bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
Definition: functionObjectList.C:902
Foam::functionObjectList::findDict
static fileName findDict(const word &funcName)
Definition: functionObjectList.C:208
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
HashTable.H
Foam::functionObjectList::on
void on()
Switch the function objects on.
Definition: functionObjectList.C:599
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::functionObjectList::updateMesh
void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Definition: functionObjectList.C:1221
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:123
Foam::functionObjectList::execute
bool execute()
Called at each ++ or += of the time-loop.
Definition: functionObjectList.C:624
Foam::HashSet< word, Hash< word > >
Foam::functionObjectList
List of function objects with start(), execute() and end() functions that is called for each object.
Definition: functionObjectList.H:130
Foam::functionObjectList::start
bool start()
Called at the start of the time-loop.
Definition: functionObjectList.C:618
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::functionObjectList::clear
void clear()
Clear the list of function objects.
Definition: functionObjectList.C:570
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
SHA1Digest.H
functionObjectProperties.H
Foam::functionObjectList::off
void off()
Switch the function objects off.
Definition: functionObjectList.C:605
Foam::functionObjectList::triggerIndex
label triggerIndex() const
Return the current trigger index (read from the propsDict)
Definition: functionObjectList.C:511
controlDict
runTime controlDict().readEntry("adjustTimeStep"
Definition: debug.C:143
Foam::functionObjectList::findObjectID
label findObjectID(const word &objName) const
Find the ID of a given function object by name, -1 if not found.
Definition: functionObjectList.C:581
Foam::functionObjectList::functionObjectDictPath
static fileName functionObjectDictPath
Definition: functionObjectList.H:234
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::functionObjectList::resetPropertiesDict
void resetPropertiesDict()
Reset/read properties dictionary for current time.
Definition: functionObjectList.C:517
Foam::functionObjectList::~functionObjectList
~functionObjectList()=default
Destructor.
HashSet.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjectList::propsDict
functionObjects::properties & propsDict()
Definition: functionObjectList.C:525
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::functionObjectList::New
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict, HashSet< wordRe > &requiredFields)
Construct and return a functionObjectList for an application.
Definition: functionObjectList.C:424
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::bounds::normalBounding::WARN
Issue warning and clamp value (this is a good default)
Foam::HashTable< label >
IOdictionary.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::functionObjectList::readFunctionObject
static bool readFunctionObject(const string &funcNameArgs0, dictionary &functionsDict, HashSet< wordRe > &requiredFields, const word &region=word::null)
Definition: functionObjectList.C:233
Foam::functionObjects::properties
Storage for function object properties, derived from IOdictionary. Provides functionality to read/wri...
Definition: functionObjectProperties.H:62
Foam::List< errorHandlingType >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::wordHashSet
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:77
PtrList.H
Foam::functionObjectList::read
bool read()
Read and set the function objects if their data have changed.
Definition: functionObjectList.C:933
functionObject.H
args
Foam::argList args(argc, argv)
Foam::functionObjectList::end
bool end()
Called when Time::run() determines that the time-loop exits.
Definition: functionObjectList.C:835
Foam::functionObjectList::storedObjects
objectRegistry & storedObjects()
Definition: functionObjectList.C:548
Foam::functionObjectList::filesModified
bool filesModified() const
Did any file get changed during execution?
Definition: functionObjectList.C:1206
Enum.H