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-2022 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 polyTopoChangeMap;
56 class polyMeshMap;
57 class argList;
58 
59 /*---------------------------------------------------------------------------*\
60  Class functionObjectList Declaration
61 \*---------------------------------------------------------------------------*/
62 
64 :
65  private PtrList<functionObject>
66 {
67  // Private Data
68 
69  //- A list of SHA1 digests for the function object dictionaries
70  List<SHA1Digest> digests_;
71 
72  //- Quick lookup of the index into functions/digests
73  HashTable<label> indices_;
74 
75  const Time& time_;
76 
77  //- The parent dictionary containing a "functions" entry
78  // This entry can either be a list or a dictionary of
79  // functionObject specifications
80  const dictionary& parentDict_;
81 
82  //- Switch for the execution of the functionObjects
83  bool execution_;
84 
85  //- Tracks if read() was called while execution is on
86  bool updated_;
87 
88 
89  // Private Member Functions
90 
91  //- Remove and return the function object pointer by name,
92  // and returns the old index via the parameter.
93  // Returns a nullptr (and index -1) if it didn't exist
94  functionObject* remove(const word&, label& oldIndex);
95 
96  //- Search the specified directory for functionObject
97  // configuration files, add to the given map and recurse
98  static void listDir(const fileName& dir, HashSet<word>& foMap);
99 
100  //- Return unset entries and their placeholder values
101  static List<Tuple2<word, string>> unsetEntries
102  (
103  const dictionary& funcDict
104  );
105 
106 
107 public:
108 
109  // Static Data Members
110 
111  //- Default relative path to the directory structure
112  // containing the functionObject dictionary files
114 
115 
116  // Constructors
117 
118  //- Construct from Time and the execution setting.
119  // The functionObject specifications are read from the controlDict
121  (
122  const Time& runTime,
123  const bool execution=true
124  );
125 
126  //- Construct from Time, a dictionary with "functions" entry
127  // and the execution setting.
128  // \param[in] t - the other Time instance to construct from
129  // \param[in] parentDict - the parent dictionary containing
130  // a "functions" entry, which can either be a list or a dictionary
131  // of functionObject specifications.
132  // \param[in] execution - whether the function objects should execute
133  // or not. Default: true.
135  (
136  const Time& runTime,
137  const dictionary& parentDict,
138  const bool execution=true
139  );
140 
141  //- Disallow default bitwise copy construction
142  functionObjectList(const functionObjectList&) = delete;
143 
144  //- Construct and return a functionObjectList for an application.
145  // If the "dict" argument is specified the functionObjectList is
146  // constructed from that dictionary which is returned as
147  // controlDict otherwise the functionObjectList is constructed
148  // from the "functions" sub-dictionary of "system/controlDict"
150  (
151  const argList& args,
152  const Time& runTime,
154  );
155 
156 
157  //- Destructor
158  virtual ~functionObjectList();
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  //- Allow addition of functionObjects to list
174 
175  //- Clear the list of function objects
176  void clear();
177 
178  //- Find the ID of a given function object by name
179  label findObjectID(const word& name) const;
180 
181  //- Return the list of functionObject configuration files in
182  // user/group/shipped directories.
183  // The search scheme allows for version-specific and
184  // version-independent files using the following hierarchy:
185  // - \b user settings:
186  // - ~/.OpenFOAM/<VERSION>/caseDicts/postProcessing
187  // - ~/.OpenFOAM/caseDicts/postProcessing
188  // - \b group (site) settings (when $WM_PROJECT_SITE is set):
189  // - $WM_PROJECT_SITE/<VERSION>/etc/caseDicts/postProcessing
190  // - $WM_PROJECT_SITE/etc/caseDicts/postProcessing
191  // - \b group (site) settings (when $WM_PROJECT_SITE is not set):
192  // - $WM_PROJECT_INST_DIR/site/<VERSION>/etc/
193  // caseDicts/postProcessing
194  // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/postProcessing
195  // - \b other (shipped) settings:
196  // - $WM_PROJECT_DIR/etc/caseDicts/postProcessing
197  static wordList list();
198 
199  //- Search for functionObject dictionary file for given region
200  // and if not present also search the case directory as well as the
201  // user/group/shipped directories.
202  // The search scheme allows for version-specific and
203  // version-independent files using the following hierarchy:
204  // - \b user settings:
205  // - ~/.OpenFOAM/<VERSION>/caseDicts/postProcessing
206  // - ~/.OpenFOAM/caseDicts/postProcessing
207  // - \b group (site) settings (when $WM_PROJECT_SITE is set):
208  // - $WM_PROJECT_SITE/<VERSION>/etc/caseDicts/postProcessing
209  // - $WM_PROJECT_SITE/etc/caseDicts/postProcessing
210  // - \b group (site) settings (when $WM_PROJECT_SITE is not set):
211  // - $WM_PROJECT_INST_DIR/site/<VERSION>/etc/
212  // caseDicts/postProcessing
213  // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/postProcessing
214  // - \b other (shipped) settings:
215  // - $WM_PROJECT_DIR/etc/caseDicts/postProcessing
216  //
217  // \return The path of the functionObject dictionary file if found
218  // otherwise null
219  static fileName findDict
220  (
221  const word& funcName,
222  const word& region = word::null
223  );
224 
225  //- Read the specified functionObject configuration dictionary
226  // parsing the optional arguments included in the string 'funcArgs',
227  // inserting 'field' or 'fields' entries as required and merging the
228  // resulting functionObject dictionary into 'functionsDict'.
229  //
230  // Parses the optional functionObject arguments:
231  // 'Q(U)' -> funcName = Q; args = (U)
232  // -> field U;
233  //
234  // Supports named arguments:
235  // 'patchAverage(patch=inlet, p,U)'
236  // or
237  // 'patchAverage(patch=inlet, field=(p U))'
238  // -> funcName = patchAverage;
239  // args = (patch=inlet, p,U)
240  // -> patch inlet;
241  // fields (p U);
242  static bool readFunctionObject
243  (
244  const string& funcArgs,
245  dictionary& functionsDict,
246  const Pair<string>& contextTypeAndValue,
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 topology using the given map
277  virtual void movePoints(const polyMesh& mesh);
278 
279  //- Update topology using the given map
280  virtual void topoChange(const polyTopoChangeMap& map);
281 
282  //- Update from another mesh using the given map
283  virtual void mapMesh(const polyMeshMap&);
284 
285 
286  // Member Operators
287 
288  //- Disallow default bitwise assignment
289  void operator=(const functionObjectList&) = delete;
290 };
291 
292 
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 
295 } // End namespace Foam
296 
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298 
299 #endif
300 
301 // ************************************************************************* //
bool read()
Read and set the function objects if their data have changed.
void operator=(const functionObjectList &)=delete
Disallow default bitwise assignment.
virtual void topoChange(const polyTopoChangeMap &map)
Update topology using the given map.
A HashTable with keys but without contents.
Definition: HashSet.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
static bool readFunctionObject(const string &funcArgs, dictionary &functionsDict, const Pair< string > &contextTypeAndValue, const word &region=word::null)
Read the specified functionObject configuration dictionary.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
static wordList list()
Return the list of functionObject configuration files in.
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
void on()
Switch the function objects on.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Abstract base-class for Time/database functionObjects.
fvMesh & mesh
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
bool start()
Called at the start of the time-loop.
bool execute()
Called at each ++ or += of the time-loop.
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
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
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
virtual ~functionObjectList()
Destructor.
List of function objects with start(), execute() and end() functions that is called for each object...
An STL-conforming hash table.
Definition: HashTable.H:61
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.
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict)
Construct and return a functionObjectList for an application.
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:76
label findObjectID(const word &name) const
Find the ID of a given function object by name.
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:50
Foam::argList args(argc, argv)
virtual void movePoints(const polyMesh &mesh)
Update topology using the given map.
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.