stateFunctionObject.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) 2015 OpenFOAM Foundation
9  Copyright (C) 2015-2021 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::functionObjects::stateFunctionObject
29 
30 Description
31  Base class for function objects, adding functionality to read/write state
32  information (data required for smooth restart behaviour) and results
33  to/from the state dictionary
34 
35  Note: cannot access the state dictionary until after construction of the
36  function objects, since the owner container functionObjectList is owned
37  by time, and time owns the state dictionary i.e. need to wait for time
38  to be fully constructed.
39 
40 See also
41  Foam::functionObject
42 
43 SourceFiles
44  stateFunctionObject.C
45  stateFunctionObjectTemplates.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef functionObjects_stateFunctionObject_H
50 #define functionObjects_stateFunctionObject_H
51 
52 #include "timeFunctionObject.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // Forward Declarations
61 class IOdictionary;
62 
63 namespace functionObjects
64 {
65 
66 /*---------------------------------------------------------------------------*\
67  Class stateFunctionObject Declaration
68 \*---------------------------------------------------------------------------*/
69 
71 :
73 {
74  // Private Member Data
75 
76  //- Name of the results dictionary
77  static const word resultsName_;
78 
79 
80 protected:
81 
82  // Protected Member Functions
83 
84  //- Return a const reference to the state dictionary
86 
87  //- Return non-const access to the state dictionary
89 
90 
91  //- No copy construct
93 
94  //- No copy assignment
95  void operator=(const stateFunctionObject&) = delete;
96 
97 
98 public:
99 
100  // Constructors
101 
102  //- Construct from components
103  stateFunctionObject(const word& name, const Time& runTime);
104 
105 
106  //- Destructor
107  virtual ~stateFunctionObject() = default;
108 
109 
110  // Member Functions
111 
112  //- Return access to the property dictionary
114 
115 
116  // Properties
117 
118  //- Return true if the property exists
119  bool foundProperty(const word& entryName) const;
120 
121  //- Remove the trigger index from the properties
122  void clearTrigger();
123 
124  //- Get the current trigger index
125  label getTrigger() const;
126 
127  //- Set new trigger index.
128  // \return True if the index changed
129  bool setTrigger(const label triggeri);
130 
131  //- Set dictionary, return true if set
132  bool getDict
133  (
134  const word& entryName,
136  ) const;
137 
138  //- Set dictionary from named object, return true if set
139  bool getObjectDict
140  (
141  const word& objectName,
142  const word& entryName,
144  ) const;
145 
146  //- Retrieve generic property
147  template<class Type>
148  Type getProperty
149  (
150  const word& entryName,
151  const Type& defaultValue = Type(Zero)
152  ) const;
153 
154  //- Set generic property, return true if set
155  template<class Type>
156  bool getProperty(const word& entryName, Type& value) const;
157 
158  //- Add generic property
159  template<class Type>
160  void setProperty(const word& entryName, const Type& value);
161 
162  //- Retrieve generic property from named object
163  template<class Type>
164  Type getObjectProperty
165  (
166  const word& objectName,
167  const word& entryName,
168  const Type& defaultValue = Type(Zero)
169  ) const;
170 
171  //- Set generic property from named object, return true if set
172  template<class Type>
173  bool getObjectProperty
174  (
175  const word& objectName,
176  const word& entryName,
177  Type& value
178  ) const;
179 
180  //- Add generic property from named object
181  template<class Type>
182  void setObjectProperty
183  (
184  const word& objectName,
185  const word& entryName,
186  const Type& value
187  );
188 
189 
190  // Results
191 
192  //- Add result
193  template<class Type>
194  void setResult
195  (
196  const word& entryName,
197  const Type& value
198  );
199 
200  //- Add result from named object
201  template<class Type>
202  void setObjectResult
203  (
204  const word& objectName,
205  const word& entryName,
206  const Type& value
207  );
208 
209  //- Retrieve result
210  template<class Type>
211  Type getResult
212  (
213  const word& entryName,
214  const Type& defaultValue = Type(Zero)
215  ) const;
216 
217  //- Retrieve result from named object
218  template<class Type>
219  Type getObjectResult
220  (
221  const word& objectName,
222  const word& entryName,
223  const Type& defaultValue = Type(Zero)
224  ) const;
225 
226  //- Set result from named object, return true if set
227  template<class Type>
228  bool getObjectResult
229  (
230  const word& objectName,
231  const word& entryName,
232  Type& value
233  ) const;
234 
235  //- Retrieve the result type
236  word resultType(const word& entryName) const;
237 
238  //- Return the type of result
240  (
241  const word& objectName,
242  const word& entryName
243  ) const;
244 
245  //- Retrieve the result entries
247 
248  //- Return result entries for named object
249  wordList objectResultEntries(const word& objectName) const;
250 
251  //- Write the results entries for all objects to stream
252  void writeResultEntries(Ostream& os) const;
253 
254  //- Write the results entries for named object to stream
255  void writeResultEntries(const word& objectName, Ostream& os) const;
256 
257  //- Write the results entries for all objects to stream
258  void writeAllResultEntries(Ostream& os) const;
259 };
260 
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 } // End namespace functionObjects
265 } // End namespace Foam
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 #ifdef NoRepository
271 #endif
272 
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 
275 #endif
276 
277 // ************************************************************************* //
wordList objectResultEntries() const
Retrieve the result entries.
Type getProperty(const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property.
dictionary dict
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
void writeAllResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
Storage for function object properties, derived from IOdictionary. Provides functionality to read/wri...
bool getDict(const word &entryName, dictionary &dict) const
Set dictionary, return true if set.
engineTime & runTime
void setResult(const word &entryName, const Type &value)
Add result.
void setObjectProperty(const word &objectName, const word &entryName, const Type &value)
Add generic property from named object.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
const word & name() const noexcept
Return the name of this functionObject.
const functionObjects::properties & stateDict() const
Return a const reference to the state dictionary.
void writeResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
bool setTrigger(const label triggeri)
Set new trigger index.
stateFunctionObject(const stateFunctionObject &)=delete
No copy construct.
A class for handling words, derived from Foam::string.
Definition: word.H:63
word resultType(const word &entryName) const
Retrieve the result type.
Type getObjectResult(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve result from named object.
void setObjectResult(const word &objectName, const word &entryName, const Type &value)
Add result from named object.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
label getTrigger() const
Get the current trigger index.
OBJstream os(runTime.globalPath()/outputName)
void setProperty(const word &entryName, const Type &value)
Add generic property.
Type getResult(const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve result.
dictionary & propertyDict()
Return access to the property dictionary.
bool getObjectDict(const word &objectName, const word &entryName, dictionary &dict) const
Set dictionary from named object, return true if set.
void clearTrigger()
Remove the trigger index from the properties.
virtual ~stateFunctionObject()=default
Destructor.
Type getObjectProperty(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property from named object.
Base class for function objects, adding functionality to read/write state information (data required ...
bool foundProperty(const word &entryName) const
Return true if the property exists.
void operator=(const stateFunctionObject &)=delete
No copy assignment.
Virtual base class for function objects with a reference to Time.
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:157