Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::functionObjects::stateFunctionObject
29
30Description
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
40See also
41 Foam::functionObject
42
43SourceFiles
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
57namespace Foam
58{
59
60// Forward Declarations
61class IOdictionary;
62
63namespace functionObjects
64{
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
80protected:
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
98public:
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>
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>
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>
183 (
184 const word& objectName,
185 const word& entryName,
186 const Type& value
187 );
188
189
190 // Results
191
193 (
194 const word& objectName,
196 ) const;
197
198 //- Add result
199 template<class Type>
200 void setResult
201 (
202 const word& entryName,
203 const Type& value
204 );
205
206 //- Add result from named object
207 template<class Type>
208 void setObjectResult
209 (
210 const word& objectName,
211 const word& entryName,
212 const Type& value
213 );
214
215 //- Retrieve result
216 template<class Type>
217 Type getResult
218 (
219 const word& entryName,
220 const Type& defaultValue = Type(Zero)
221 ) const;
222
223 //- Retrieve result from named object
224 template<class Type>
225 Type getObjectResult
226 (
227 const word& objectName,
228 const word& entryName,
229 const Type& defaultValue = Type(Zero)
230 ) const;
231
232 //- Set result from named object, return true if set
233 template<class Type>
234 bool getObjectResult
235 (
236 const word& objectName,
237 const word& entryName,
238 Type& value
239 ) const;
240
241 //- Retrieve the result type
242 word resultType(const word& entryName) const;
243
244 //- Return the type of result
246 (
247 const word& objectName,
248 const word& entryName
249 ) const;
250
251 //- Retrieve the result entries
253
254 //- Return result entries for named object
255 wordList objectResultEntries(const word& objectName) const;
256
257 //- Write the results entries for all objects to stream
258 void writeResultEntries(Ostream& os) const;
259
260 //- Write the results entries for named object to stream
261 void writeResultEntries(const word& objectName, Ostream& os) const;
262
263 //- Write the results entries for all objects to stream
264 void writeAllResultEntries(Ostream& os) const;
265};
266
267
268// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269
270} // End namespace functionObjects
271} // End namespace Foam
272
273// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274
275#ifdef NoRepository
277#endif
278
279// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280
281#endif
282
283// ************************************************************************* //
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const word & name() const noexcept
Return the name of this functionObject.
Storage for function object properties, derived from IOdictionary. Provides functionality to read/wri...
bool getObjectDict(const word &objectName, const word &entryName, dictionary &dict) const
Set dictionary from named object, return true if set.
void setObjectResult(const word &objectName, const word &entryName, const Type &value)
Add result from named object.
void setResult(const word &entryName, const Type &value)
Add result.
Type getObjectProperty(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property from named object.
bool getDict(const word &entryName, dictionary &dict) const
Set dictionary, return true if set.
bool setTrigger(const label triggeri)
Set new trigger index.
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
bool foundProperty(const word &entryName) const
Return true if the property exists.
void setProperty(const word &entryName, const Type &value)
Add generic property.
void writeAllResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
void setObjectProperty(const word &objectName, const word &entryName, const Type &value)
Add generic property from named object.
stateFunctionObject(const stateFunctionObject &)=delete
No copy construct.
Type getProperty(const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property.
virtual ~stateFunctionObject()=default
Destructor.
void writeResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
void operator=(const stateFunctionObject &)=delete
No copy assignment.
bool getObjectResultDict(const word &objectName, dictionary &dict) const
void clearTrigger()
Remove the trigger index from the properties.
Type getResult(const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve result.
const functionObjects::properties & stateDict() const
Return a const reference to the state dictionary.
label getTrigger() const
Get the current trigger index.
dictionary & propertyDict()
Return access to the property dictionary.
wordList objectResultEntries() const
Retrieve the result entries.
Type getObjectResult(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve result from named object.
word resultType(const word &entryName) const
Retrieve the result type.
Virtual base class for function objects with a reference to Time.
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
dictionary dict