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-2021 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  //- Return unset entries and their placeholder values
100  static List<Tuple2<word, string>> unsetEntries
101  (
102  const dictionary& funcDict
103  );
104 
105 
106 public:
107 
108  // Static Data Members
109 
110  //- Default relative path to the directory structure
111  // containing the functionObject dictionary files
113 
114 
115  // Constructors
116 
117  //- Construct from Time and the execution setting.
118  // The functionObject specifications are read from the controlDict
120  (
121  const Time& runTime,
122  const bool execution=true
123  );
124 
125  //- Construct from Time, a dictionary with "functions" entry
126  // and the execution setting.
127  // \param[in] t - the other Time instance to construct from
128  // \param[in] parentDict - the parent dictionary containing
129  // a "functions" entry, which can either be a list or a dictionary
130  // of functionObject specifications.
131  // \param[in] execution - whether the function objects should execute
132  // or not. Default: true.
134  (
135  const Time& runTime,
136  const dictionary& parentDict,
137  const bool execution=true
138  );
139 
140  //- Disallow default bitwise copy construction
141  functionObjectList(const functionObjectList&) = delete;
142 
143  //- Construct and return a functionObjectList for an application.
144  // If the "dict" argument is specified the functionObjectList is
145  // constructed from that dictionary which is returned as
146  // controlDict otherwise the functionObjectList is constructed
147  // from the "functions" sub-dictionary of "system/controlDict"
149  (
150  const argList& args,
151  const Time& runTime,
153  HashSet<word>& requiredFields
154  );
155 
156 
157  //- Destructor
159 
160 
161  // Member Functions
162 
163  //- Return the number of elements in the List.
165 
166  //- Return true if the List is empty (ie, size() is zero).
168 
169  //- Access to the functionObjects
171 
172  //- Clear the list of function objects
173  void clear();
174 
175  //- Find the ID of a given function object by name
176  label findObjectID(const word& name) const;
177 
178  //- Print a list of functionObject configuration files in
179  // user/group/shipped directories.
180  // The search scheme allows for version-specific and
181  // version-independent files using the following hierarchy:
182  // - \b user settings:
183  // - ~/.OpenFOAM/<VERSION>/caseDicts/postProcessing
184  // - ~/.OpenFOAM/caseDicts/postProcessing
185  // - \b group (site) settings (when $WM_PROJECT_SITE is set):
186  // - $WM_PROJECT_SITE/<VERSION>/etc/caseDicts/postProcessing
187  // - $WM_PROJECT_SITE/etc/caseDicts/postProcessing
188  // - \b group (site) settings (when $WM_PROJECT_SITE is not set):
189  // - $WM_PROJECT_INST_DIR/site/<VERSION>/etc/
190  // caseDicts/postProcessing
191  // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/postProcessing
192  // - \b other (shipped) settings:
193  // - $WM_PROJECT_DIR/etc/caseDicts/postProcessing
194  static void list();
195 
196  //- Search for functionObject dictionary file for given region
197  // and if not present also search the case directory as well as the
198  // user/group/shipped directories.
199  // The search scheme allows for version-specific and
200  // version-independent files using the following hierarchy:
201  // - \b user settings:
202  // - ~/.OpenFOAM/<VERSION>/caseDicts/postProcessing
203  // - ~/.OpenFOAM/caseDicts/postProcessing
204  // - \b group (site) settings (when $WM_PROJECT_SITE is set):
205  // - $WM_PROJECT_SITE/<VERSION>/etc/caseDicts/postProcessing
206  // - $WM_PROJECT_SITE/etc/caseDicts/postProcessing
207  // - \b group (site) settings (when $WM_PROJECT_SITE is not set):
208  // - $WM_PROJECT_INST_DIR/site/<VERSION>/etc/
209  // caseDicts/postProcessing
210  // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/postProcessing
211  // - \b other (shipped) settings:
212  // - $WM_PROJECT_DIR/etc/caseDicts/postProcessing
213  //
214  // \return The path of the functionObject dictionary file if found
215  // otherwise null
216  static fileName findDict
217  (
218  const word& funcName,
219  const word& region = word::null
220  );
221 
222  //- Read the specified functionObject configuration dictionary
223  // parsing the optional arguments included in the string 'funcArgs',
224  // inserting 'field' or 'fields' entries as required and merging the
225  // resulting functionObject dictionary into 'functionsDict'.
226  // Any fields required to execute the functionObject are added to
227  // 'requiredFields'
228  //
229  // Parses the optional functionObject arguments:
230  // 'Q(U)' -> funcName = Q; args = (U)
231  // -> field U;
232  //
233  // Supports named arguments:
234  // 'patchAverage(patch=inlet, p,U)'
235  // or
236  // 'patchAverage(patch=inlet, field=(p U))'
237  // -> funcName = patchAverage;
238  // args = (patch=inlet, p,U)
239  // -> patch inlet;
240  // fields (p U);
241  static bool readFunctionObject
242  (
243  const string& funcArgs,
244  dictionary& functionsDict,
245  const Pair<string>& contextTypeAndValue,
246  HashSet<word>& requiredFields,
247  const word& region = word::null
248  );
249 
250  //- Read and set the function objects if their data have changed
251  bool read();
252 
253  //- Switch the function objects on
254  void on();
255 
256  //- Switch the function objects off
257  void off();
258 
259  //- Return the execution status (on/off) of the function objects
260  bool status() const;
261 
262  //- Called at the start of the time-loop
263  bool start();
264 
265  //- Called at each ++ or += of the time-loop.
266  // postProcess overrides the usual executeControl behaviour and
267  // forces execution (used in post-processing mode)
268  bool execute();
269 
270  //- Called when Time::run() determines that the time-loop exits
271  bool end();
272 
273  //- Return the time to the next write
274  scalar timeToNextWrite();
275 
276  //- Update for changes of mesh
277  void updateMesh(const mapPolyMesh& mpm);
278 
279  //- Update for changes of mesh
280  void movePoints(const polyMesh& mesh);
281 
282 
283  // Member Operators
284 
285  //- Disallow default bitwise assignment
286  void operator=(const functionObjectList&) = delete;
287 };
288 
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 } // End namespace Foam
293 
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 
296 #endif
297 
298 // ************************************************************************* //
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:156
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
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
A class for handling words, derived from string.
Definition: word.H:59
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 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 bool readFunctionObject(const string &funcArgs, dictionary &functionsDict, const Pair< string > &contextTypeAndValue, HashSet< word > &requiredFields, const word &region=word::null)
Read the specified functionObject configuration dictionary.
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.