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