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-2019 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 See also
35  Foam::functionObject
36  Foam::functionObjects::timeControl
37 
38 SourceFiles
39  functionObjectList.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef functionObjectList_H
44 #define functionObjectList_H
45 
46 #include "PtrList.H"
47 #include "functionObject.H"
48 #include "SHA1Digest.H"
49 #include "HashTable.H"
50 #include "IOdictionary.H"
51 #include "HashSet.H"
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 // Forward declarations
59 class argList;
60 class mapPolyMesh;
61 class wordRe;
62 
63 /*---------------------------------------------------------------------------*\
64  Class functionObjectList Declaration
65 \*---------------------------------------------------------------------------*/
66 
68 :
69  private PtrList<functionObject>
70 {
71  // Private data
72 
73  //- A list of SHA1 digests for the function object dictionaries
74  List<SHA1Digest> digests_;
75 
76  //- Quick lookup of the index into functions/digests
77  HashTable<label> indices_;
78 
79  //- Reference to Time
80  const Time& time_;
81 
82  //- The parent dictionary containing a "functions" entry
83  // This entry can either be a list or a dictionary of
84  // functionObject specifications
85  const dictionary& parentDict_;
86 
87  //- Function object properties - stores state information
88  mutable autoPtr<IOdictionary> stateDictPtr_;
89 
90  //- Function objects output registry
91  mutable autoPtr<objectRegistry> objectsRegistryPtr_;
92 
93  //- Switch for the execution of the functionObjects
94  bool execution_;
95 
96  //- Tracks if read() was called while execution is on
97  bool updated_;
98 
99 
100  // Private Member Functions
101 
102  //- List of functions
103  const PtrList<functionObject>& functions() const { return *this; }
104 
105  //- List of functions
106  PtrList<functionObject>& functions() { return *this; }
107 
108  //- Create state dictionary - attached to Time.
109  void createStateDict() const;
110 
111  //- Create registry for output objects - attached to Time.
112  void createOutputRegistry() const;
113 
114  //- Remove and return the function object pointer by name,
115  //- and returns the old index (into digest) via the parameter.
116  // Returns nullptr (and index -1) if it didn't exist
117  autoPtr<functionObject> remove(const word& key, label& oldIndex);
118 
119  //- Search the specified directory for functionObject
120  //- configuration files, add to the given map and recurse
121  static void listDir(const fileName& dir, wordHashSet& available);
122 
123  //- No copy construct
124  functionObjectList(const functionObjectList&) = delete;
125 
126  //- No copy assignment
127  void operator=(const functionObjectList&) = delete;
128 
129 
130 public:
131 
132  // Static data members
133 
134  //- Default relative path ("caseDicts/postProcessing") to the
135  //- directory structure containing functionObject dictionary files.
137 
138 
139  // Constructors
140 
141  //- Construct from Time and the execution setting.
142  // The functionObject specifications are read from the controlDict
144  (
145  const Time& runTime,
146  const bool execution=true
147  );
148 
149  //- Construct from Time, a dictionary with "functions" entry
150  // and the execution setting.
151  // \param[in] runTime - the other Time instance to construct from
152  // \param[in] parentDict - the parent dictionary containing
153  // a "functions" entry, which can either be a list or a dictionary
154  // of functionObject specifications.
155  // \param[in] execution - whether the function objects should execute
156  // or not. Default: true.
158  (
159  const Time& runTime,
160  const dictionary& parentDict,
161  const bool execution=true
162  );
163 
164  //- Construct and return a functionObjectList for an application.
165  // If the "dict" argument is specified the functionObjectList is
166  // constructed from that dictionary which is returned as
167  // controlDict otherwise the functionObjectList is constructed
168  // from the "functions" sub-dictionary of "system/controlDict"
170  (
171  const argList& args,
172  const Time& runTime,
174  HashSet<wordRe>& requiredFields
175  );
176 
177 
178  //- Destructor
179  ~functionObjectList() = default;
180 
181 
182  // Member Functions
183 
184  //- Return the number of elements in the List.
186 
187  //- Return true if the List is empty (ie, size() is zero).
189 
190  //- Access to the functionObjects
192 
193  //- Return the current trigger index (read from the stateDict)
194  label triggerIndex() const;
195 
196  //- Reset/read state dictionary for current time
197  void resetState();
198 
199  //- Write access to the state dictionary ("functionObjectProperties")
200  //- registered on Time
202 
203  //- Const access to the state dictionary ("functionObjectProperties")
204  //- registered on Time
205  const IOdictionary& stateDict() const;
206 
207  //- Write access to the output objects ("functionObjectObjects")
208  //- registered on Time
210 
211  //- Const access to the output objects ("functionObjectObjects")
212  //- registered on Time
213  const objectRegistry& storedObjects() const;
214 
215  //- Clear the list of function objects
216  void clear();
217 
218  //- Find the ID of a given function object by name, -1 if not found.
219  label findObjectID(const word& name) const;
220 
221  //- Print a list of functionObject configuration files in the
222  //- directories located using
223  //- Foam::findEtcDirs("caseDicts/postProcessing")
224  //
225  // -# \b user settings
226  // - ~/.OpenFOAM/{PROJECT_API}/"caseDicts/postProcessing"
227  // - ~/.OpenFOAM/"caseDicts/postProcessing"
228  // -# \b group settings
229  // - $WM_PROJECT_SITE/{PROJECT_API}/"etc/caseDicts/postProcessing"
230  // - $WM_PROJECT_SITE/"etc/caseDicts/postProcessing"
231  // -# \b other (shipped) settings
232  // - $WM_PROJECT_DIR/etc/"caseDicts/postProcessing"
233  //
234  // Where {PROJECT_API} is the value of the OPENFOAM define.
235  // See further notes in Foam::findEtcEntries()
236  static void list();
237 
238  //- Find a functionObject dictionary file in the case
239  //- <system> directory or any directory located using
240  //- Foam::findEtcDirs("caseDicts/postProcessing")
241  //
242  // \return The path of the functionObject dictionary file found
243  // or an empty path
244  static fileName findDict(const word& funcName);
245 
246  //- Read the specified functionObject configuration dictionary parsing
247  //- the optional arguments included in the name 'funcNameArgs0',
248  //- inserting 'field' or 'fields' entries as required and merging the
249  //- resulting functionObject dictionary into 'functionsDict'. Any
250  //- fields required to execute the functionObject are added to
251  //- 'requiredFields'
252  //
253  // Uses functionObjectList::findDict() for searching
254  static bool readFunctionObject
255  (
256  const string& funcNameArgs0,
257  dictionary& functionsDict,
258  HashSet<wordRe>& requiredFields,
259  const word& region = word::null
260  );
261 
262  //- Read and set the function objects if their data have changed
263  bool read();
264 
265  //- Switch the function objects on
266  void on();
267 
268  //- Switch the function objects off
269  void off();
270 
271  //- Return the execution status (on/off) of the function objects
272  bool status() const;
273 
274  //- Called at the start of the time-loop
275  bool start();
276 
277  //- Called at each ++ or += of the time-loop.
278  // postProcess overrides the usual executeControl behaviour and
279  // forces execution (used in post-processing mode)
280  bool execute();
281 
282  //- Execute function objects using the specified subIndex.
283  // \param subIndex an execution sub-index corresponding to a
284  // sub-cycle or something similar
285  bool execute(const label subIndex);
286 
287  //- Execute a subset of function objects using the specified subIndex.
288  // \param functionNames names or regex of existing functions to
289  // execute
290  // \param subIndex an execution sub-index corresponding to a
291  // sub-cycle or something similar
292  bool execute(const UList<wordRe>& functionNames, const label subIndex);
293 
294  //- Called when Time::run() determines that the time-loop exits
295  bool end();
296 
297  //- Called at the end of Time::adjustDeltaT() if adjustTime is true
298  bool adjustTimeStep();
299 
300  //- Did any file get changed during execution?
301  bool filesModified() const;
302 
303  //- Update for changes of mesh
304  void updateMesh(const mapPolyMesh& mpm);
305 
306  //- Update for changes of mesh
307  void movePoints(const polyMesh& mesh);
308 };
309 
310 
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 
313 } // End namespace Foam
314 
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 
317 #endif
318 
319 // ************************************************************************* //
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:968
Foam::functionObjectList::list
static void list()
Definition: functionObjectList.C:142
Foam::functionObjectList::status
bool status() const
Return the execution status (on/off) of the function objects.
Definition: functionObjectList.C:580
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:705
Foam::functionObjectList::findDict
static fileName findDict(const word &funcName)
Definition: functionObjectList.C:158
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:567
Foam::functionObjectList::stateDict
IOdictionary & stateDict()
Definition: functionObjectList.C:496
Foam::functionObjectList::updateMesh
void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Definition: functionObjectList.C:956
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:592
Foam::HashSet< word >
Foam::functionObjectList
List of function objects with start(), execute() and end() functions that is called for each object.
Definition: functionObjectList.H:66
Foam::functionObjectList::start
bool start()
Called at the start of the time-loop.
Definition: functionObjectList.C:586
Foam::functionObjectList::findObjectID
label findObjectID(const word &name) const
Find the ID of a given function object by name, -1 if not found.
Definition: functionObjectList.C:549
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:540
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
SHA1Digest.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::functionObjectList::off
void off()
Switch the function objects off.
Definition: functionObjectList.C:573
Foam::functionObjectList::triggerIndex
label triggerIndex() const
Return the current trigger index (read from the stateDict)
Definition: functionObjectList.C:479
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
controlDict
runTime controlDict().readEntry("adjustTimeStep"
Definition: debug.C:143
Foam::functionObjectList::functionObjectDictPath
static fileName functionObjectDictPath
Definition: functionObjectList.H:135
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:65
Foam::functionObjectList::~functionObjectList
~functionObjectList()=default
Destructor.
HashSet.H
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:390
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
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:183
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
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:160
PtrList.H
Foam::functionObjectList::read
bool read()
Read and set the function objects if their data have changed.
Definition: functionObjectList.C:730
functionObject.H
Foam::functionObjectList::resetState
void resetState()
Reset/read state dictionary for current time.
Definition: functionObjectList.C:488
args
Foam::argList args(argc, argv)
Foam::functionObjectList::end
bool end()
Called when Time::run() determines that the time-loop exits.
Definition: functionObjectList.C:680
Foam::functionObjectList::storedObjects
objectRegistry & storedObjects()
Definition: functionObjectList.C:518
Foam::functionObjectList::filesModified
bool filesModified() const
Did any file get changed during execution?
Definition: functionObjectList.C:941