Loading...
Searching...
No Matches
functionObjectProperties.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) 2021-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::functionObjects::properties
28
29Description
30 Storage for function object properties, derived from IOdictionary.
31 Provides functionality to read/write state information (data required for
32 smooth restart behaviour) and results to/from the state dictionary
33
34 Note: cannot be accessed until after construction of thefunction objects,
35 since the owner container functionObjectList is owned by time, and time owns
36 [this] i.e. need to wait for time to be fully constructed.
37
38See also
39 Foam::functionObject
40
41SourceFiles
42 functionObjectProperties.C
43 functionObjectPropertiesTemplates.C
44
45\*---------------------------------------------------------------------------*/
46
47#ifndef functionObjects_properties_H
48#define functionObjects_properties_H
49
50#include "IOdictionary.H"
51
52// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53
54namespace Foam
55{
56namespace functionObjects
57{
59/*---------------------------------------------------------------------------*\
60 Class properties Declaration
61\*---------------------------------------------------------------------------*/
62
63class properties
64:
65 public IOdictionary
66{
67 // Private Member Data
68
69 //- Name of the results dictionary
70 static const word resultsName_;
71
72
73protected:
74
75 // Protected Member Functions
76
77 //- No copy construct
78 properties(const properties&) = delete;
79
80 //- No copy assignment
81 void operator=(const properties&) = delete;
83
84public:
85
86 // Constructors
87
88 //- Construct from components
89 explicit properties(const IOobject& io);
90
91
92 //- Destructor
93 virtual ~properties() = default;
94
95
96 // Member Functions
97
98 //- Return list of object names
99 wordList objectNames() const;
100
101 //- Return true if the object with objectName exists
102 bool hasObjectDict(const word& objectName) const;
103
104 //- Return access to the property dictionary
105 dictionary& propertyDict(const word& objectName);
106
107
108 // Properties
109
110 //- Get dictionary for named object. Creates one if required
111 dictionary& getObjectDict(const word& objectName);
112
113 //- Return true if the property exists
115 (
116 const word& objectName,
117 const word& entryName
118 ) const;
119
120 //- Remove the trigger index from the properties
121 void clearTrigger();
122
123 //- Get the current trigger index
124 label getTrigger() const;
125
126 //- Set new trigger index.
127 // \return True if the index changed
128 bool setTrigger(const label triggeri);
129
130 //- Set dictionary from named object, return true if set
131 bool getObjectDict
132 (
133 const word& objectName,
134 const word& entryName,
136 ) const;
137
138 //- Retrieve generic property from named object
139 template<class Type>
141 (
142 const word& objectName,
143 const word& entryName,
144 const Type& defaultValue = Type(Zero)
145 ) const;
146
147 //- Set generic property from named object, return true if set
148 template<class Type>
150 (
151 const word& objectName,
152 const word& entryName,
153 Type& value
154 ) const;
155
156 //- Add generic property from named object
157 template<class Type>
159 (
160 const word& objectName,
161 const word& entryName,
162 const Type& value
163 );
164
165
166 // Results
167
168 //- Get dictionary of object results, return true if set
170 (
171 const word& objectName,
173 ) const;
174
175 //- Add result from named object
176 template<class Type>
177 void setObjectResult
178 (
179 const word& objectName,
180 const word& entryName,
181 const Type& value
182 );
183
184 //- Retrieve result from named object
185 template<class Type>
186 Type getObjectResult
187 (
188 const word& objectName,
189 const word& entryName,
190 const Type& defaultValue = Type(Zero)
191 ) const;
192
193 //- Set result from named object, return true if set
194 template<class Type>
195 bool getObjectResult
196 (
197 const word& objectName,
198 const word& entryName,
199 Type& value
200 ) const;
201
202 //- Return true if the object with objectName exists in results
203 bool hasResultObject(const word& objectName) const;
204
205 //- Return list of objects with results
207
208 //- Return true if the object with objectName exists and has
209 //- entryName in its results
211 (
212 const word& objectName,
213 const word& entryName
214 ) const;
215
216 //- Return the type of result
218 (
219 const word& objectName,
220 const word& entryName
221 ) const;
222
223 //- Return result entries for named object
224 wordList objectResultEntries(const word& objectName) const;
225
226 //- Write the results entries for all objects to stream
227 void writeResultEntries(Ostream& os) const;
228
229 //- Write the results entries for named object to stream
230 void writeResultEntries(const word& objectName, Ostream& os) const;
231
232 //- Write the results entries for all objects to stream
233 void writeAllResultEntries(Ostream& os) const;
234};
235
236
237// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238
239} // End namespace functionObjects
240} // End namespace Foam
241
242// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243
244#ifdef NoRepository
246#endif
247
248// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249
250#endif
251
252// ************************************************************************* //
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
dictionary()
Default construct, a top-level empty dictionary.
Definition dictionary.C:68
void operator=(const properties &)=delete
No copy assignment.
void setObjectResult(const word &objectName, const word &entryName, const Type &value)
Add result from named object.
properties(const properties &)=delete
No copy construct.
Type getObjectProperty(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property from named object.
wordList objectNames() const
Return list of object names.
dictionary & propertyDict(const word &objectName)
Return access to the property dictionary.
dictionary & getObjectDict(const word &objectName)
Get dictionary for named object. Creates one if required.
bool setTrigger(const label triggeri)
Set new trigger index.
bool foundObjectProperty(const word &objectName, const word &entryName) const
Return true if the property exists.
bool hasResultObjectEntry(const word &objectName, const word &entryName) const
Return true if the object with objectName exists and has entryName in its results.
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.
void setObjectProperty(const word &objectName, const word &entryName, const Type &value)
Add generic property from named object.
void writeResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
bool hasResultObject(const word &objectName) const
Return true if the object with objectName exists in results.
bool getObjectResultDict(const word &objectName, dictionary &dict) const
Get dictionary of object results, return true if set.
bool hasObjectDict(const word &objectName) const
Return true if the object with objectName exists.
void clearTrigger()
Remove the trigger index from the properties.
wordList objectResultEntries(const word &objectName) const
Return result entries for named object.
virtual ~properties()=default
Destructor.
label getTrigger() const
Get the current trigger index.
wordList objectResultNames() const
Return list of objects with results.
Type getObjectResult(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve result from named object.
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
const auto & io
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