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