functionObjectList.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-2020 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 Class
25  Foam::functionObjectList
26 
27 Description
28  List of function objects with start(), execute() and end() functions
29  that is called for each object.
30 
31 See also
32  Foam::functionObject
33  Foam::functionObjects::timeControl
34 
35 SourceFiles
36  functionObjectList.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef functionObjectList_H
41 #define functionObjectList_H
42 
43 #include "PtrList.H"
44 #include "functionObject.H"
45 #include "SHA1Digest.H"
46 #include "HashTable.H"
47 #include "HashSet.H"
48 #include "dictionary.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 class mapPolyMesh;
56 class argList;
57 
58 /*---------------------------------------------------------------------------*\
59  Class functionObjectList Declaration
60 \*---------------------------------------------------------------------------*/
61 
63 :
64  private PtrList<functionObject>
65 {
66  // Private Data
67 
68  //- A list of SHA1 digests for the function object dictionaries
69  List<SHA1Digest> digests_;
70 
71  //- Quick lookup of the index into functions/digests
72  HashTable<label> indices_;
73 
74  const Time& time_;
75 
76  //- The parent dictionary containing a "functions" entry
77  // This entry can either be a list or a dictionary of
78  // functionObject specifications
79  const dictionary& parentDict_;
80 
81  //- Switch for the execution of the functionObjects
82  bool execution_;
83 
84  //- Tracks if read() was called while execution is on
85  bool updated_;
86 
87 
88  // Private Member Functions
89 
90  //- Remove and return the function object pointer by name,
91  // and returns the old index via the parameter.
92  // Returns a nullptr (and index -1) if it didn't exist
93  functionObject* remove(const word&, label& oldIndex);
94 
95  //- Search the specified directory for functionObject
96  // configuration files, add to the given map and recurse
97  static void listDir(const fileName& dir, HashSet<word>& foMap);
98 
99  static void checkUnsetEntries
100  (
101  const string& funcNameArgs,
102  const dictionary& funcArgsDict,
103  const dictionary& funcDict,
104  const string& context
105  );
106 
107 
108 public:
109 
110  // Static Data Members
111 
112  //- Default relative path to the directory structure
113  // containing the functionObject dictionary files
115 
116 
117  // Constructors
118 
119  //- Construct from Time and the execution setting.
120  // The functionObject specifications are read from the controlDict
122  (
123  const Time& runTime,
124  const bool execution=true
125  );
126 
127  //- Construct from Time, a dictionary with "functions" entry
128  // and the execution setting.
129  // \param[in] t - the other Time instance to construct from
130  // \param[in] parentDict - the parent dictionary containing
131  // a "functions" entry, which can either be a list or a dictionary
132  // of functionObject specifications.
133  // \param[in] execution - whether the function objects should execute
134  // or not. Default: true.
136  (
137  const Time& runTime,
138  const dictionary& parentDict,
139  const bool execution=true
140  );
141 
142  //- Disallow default bitwise copy construction
143  functionObjectList(const functionObjectList&) = delete;
144 
145  //- Construct and return a functionObjectList for an application.
146  // If the "dict" argument is specified the functionObjectList is
147  // constructed from that dictionary which is returned as
148  // controlDict otherwise the functionObjectList is constructed
149  // from the "functions" sub-dictionary of "system/controlDict"
151  (
152  const argList& args,
153  const Time& runTime,
155  HashSet<word>& requiredFields
156  );
157 
158 
159  //- Destructor
161 
162 
163  // Member Functions
164 
165  //- Return the number of elements in the List.
167 
168  //- Return true if the List is empty (ie, size() is zero).
170 
171  //- Access to the functionObjects
173 
174  //- Clear the list of function objects
175  void clear();
176 
177  //- Find the ID of a given function object by name
178  label findObjectID(const word& name) const;
179 
180  //- Print a list of functionObject configuration files in
181  // user/group/shipped directories.
182  // The search scheme allows for version-specific and
183  // version-independent files using the following hierarchy:
184  // - \b user settings:
185  // - ~/.OpenFOAM/<VERSION>/caseDicts/postProcessing
186  // - ~/.OpenFOAM/caseDicts/postProcessing
187  // - \b group (site) settings (when $WM_PROJECT_SITE is set):
188  // - $WM_PROJECT_SITE/<VERSION>/etc/caseDicts/postProcessing
189  // - $WM_PROJECT_SITE/etc/caseDicts/postProcessing
190  // - \b group (site) settings (when $WM_PROJECT_SITE is not set):
191  // - $WM_PROJECT_INST_DIR/site/<VERSION>/etc/
192  // caseDicts/postProcessing
193  // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/postProcessing
194  // - \b other (shipped) settings:
195  // - $WM_PROJECT_DIR/etc/caseDicts/postProcessing
196  static void list();
197 
198  //- Search for functionObject dictionary file for given region
199  // and if not present also search the case directory as well as the
200  // user/group/shipped directories.
201  // The search scheme allows for version-specific and
202  // version-independent files using the following hierarchy:
203  // - \b user settings:
204  // - ~/.OpenFOAM/<VERSION>/caseDicts/postProcessing
205  // - ~/.OpenFOAM/caseDicts/postProcessing
206  // - \b group (site) settings (when $WM_PROJECT_SITE is set):
207  // - $WM_PROJECT_SITE/<VERSION>/etc/caseDicts/postProcessing
208  // - $WM_PROJECT_SITE/etc/caseDicts/postProcessing
209  // - \b group (site) settings (when $WM_PROJECT_SITE is not set):
210  // - $WM_PROJECT_INST_DIR/site/<VERSION>/etc/
211  // caseDicts/postProcessing
212  // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/postProcessing
213  // - \b other (shipped) settings:
214  // - $WM_PROJECT_DIR/etc/caseDicts/postProcessing
215  //
216  // \return The path of the functionObject dictionary file if found
217  // otherwise null
218  static fileName findDict
219  (
220  const word& funcName,
221  const word& region = word::null
222  );
223 
224  //- Read the specified functionObject configuration dictionary
225  // parsing the optional arguments included in the string 'funcCall',
226  // inserting 'field' or 'fields' entries as required and merging the
227  // resulting functionObject dictionary into 'functionsDict'.
228  // Any fields required to execute the functionObject are added to
229  // 'requiredFields'
230  //
231  // Parses the optional functionObject arguments:
232  // 'Q(U)' -> funcName = Q; args = (U)
233  // -> field U;
234  //
235  // Supports named arguments:
236  // 'patchAverage(patch=inlet, p,U)'
237  // or
238  // 'patchAverage(patch=inlet, field=(p U))'
239  // -> funcName = patchAverage;
240  // args = (patch=inlet, p,U)
241  // -> patch inlet;
242  // fields (p U);
243  static bool readFunctionObject
244  (
245  const string& funcCall,
246  dictionary& functionsDict,
247  const string& context,
248  HashSet<word>& requiredFields,
249  const word& region = word::null
250  );
251 
252  //- Read and set the function objects if their data have changed
253  bool read();
254 
255  //- Switch the function objects on
256  void on();
257 
258  //- Switch the function objects off
259  void off();
260 
261  //- Return the execution status (on/off) of the function objects
262  bool status() const;
263 
264  //- Called at the start of the time-loop
265  bool start();
266 
267  //- Called at each ++ or += of the time-loop.
268  // postProcess overrides the usual executeControl behaviour and
269  // forces execution (used in post-processing mode)
270  bool execute();
271 
272  //- Called when Time::run() determines that the time-loop exits
273  bool end();
274 
275  //- Override the time-step value
276  bool setTimeStep();
277 
278  //- Return the time to the next write
279  scalar timeToNextWrite();
280 
281  //- Update for changes of mesh
282  void updateMesh(const mapPolyMesh& mpm);
283 
284  //- Update for changes of mesh
285  void movePoints(const polyMesh& mesh);
286 
287 
288  // Member Operators
289 
290  //- Disallow default bitwise assignment
291  void operator=(const functionObjectList&) = delete;
292 };
293 
294 
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 
297 } // End namespace Foam
298 
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300 
301 #endif
302 
303 // ************************************************************************* //
bool read()
Read and set the function objects if their data have changed.
void operator=(const functionObjectList &)=delete
Disallow default bitwise assignment.
A HashTable with keys but without contents.
Definition: HashSet.H:59
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:59
A class for handling file names.
Definition: fileName.H:79
functionObjectList(const Time &runTime, const bool execution=true)
Construct from Time and the execution setting.
void off()
Switch the function objects off.
scalar timeToNextWrite()
Return the time to the next write.
runTime controlDict().lookup("adjustTimeStep") >> adjustTimeStep
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
static void list()
Print a list of functionObject configuration files in.
engineTime & runTime
void on()
Switch the function objects on.
Abstract base-class for Time/database functionObjects.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
bool start()
Called at the start of the time-loop.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
bool execute()
Called at each ++ or += of the time-loop.
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
static bool readFunctionObject(const string &funcCall, dictionary &functionsDict, const string &context, HashSet< word > &requiredFields, const word &region=word::null)
Read the specified functionObject configuration dictionary.
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
static const word null
An empty word.
Definition: word.H:77
List of function objects with start(), execute() and end() functions that is called for each object...
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
void clear()
Clear the list of function objects.
bool setTimeStep()
Override the time-step value.
bool status() const
Return the execution status (on/off) of the function objects.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
label findObjectID(const word &name) const
Find the ID of a given function object by name.
void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict, HashSet< word > &requiredFields)
Construct and return a functionObjectList for an application.
Foam::argList args(argc, argv)
void movePoints(const polyMesh &mesh)
Update for changes of mesh.
static fileName functionObjectDictPath
Default relative path to the directory structure.
bool end()
Called when Time::run() determines that the time-loop exits.
Namespace for OpenFOAM.
static fileName findDict(const word &funcName, const word &region=word::null)
Search for functionObject dictionary file for given region.