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 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::functionObjects::properties
28 
29 Description
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 
38 See also
39  Foam::functionObject
40 
41 SourceFiles
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 
54 namespace Foam
55 {
56 namespace functionObjects
57 {
58 
59 /*---------------------------------------------------------------------------*\
60  Class properties Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class properties
64 :
65  public IOdictionary
66 {
67  // Private Member Data
68 
69  //- Name of the results dictionary
70  static const word resultsName_;
71 
72 
73 protected:
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;
82 
83 
84 public:
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>
140  Type getObjectProperty
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>
149  bool getObjectProperty
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>
158  void setObjectProperty
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
206  wordList objectResultNames() const;
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 // ************************************************************************* //
dictionary dict
properties(const properties &)=delete
No copy construct.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Storage for function object properties, derived from IOdictionary. Provides functionality to read/wri...
dictionary & getObjectDict(const word &objectName)
Get dictionary for named object. Creates one if required.
wordList objectNames() const
Return list of object names.
label getTrigger() const
Get the current trigger index.
void writeAllResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
wordList objectResultEntries(const word &objectName) const
Return result entries for named object.
bool foundObjectProperty(const word &objectName, const word &entryName) const
Return true if the property exists.
bool setTrigger(const label triggeri)
Set new trigger index.
void setObjectResult(const word &objectName, const word &entryName, const Type &value)
Add result from named object.
Type getObjectResult(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve result from named object.
wordList objectResultNames() const
Return list of objects with results.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
virtual ~properties()=default
Destructor.
void writeResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
bool hasResultObjectEntry(const word &objectName, const word &entryName) const
Return true if the object with objectName exists and has entryName in its results.
void setObjectProperty(const word &objectName, const word &entryName, const Type &value)
Add generic property from named object.
void clearTrigger()
Remove the trigger index from the properties.
A class for handling words, derived from Foam::string.
Definition: word.H:63
dictionary & propertyDict(const word &objectName)
Return access to the property dictionary.
bool hasObjectDict(const word &objectName) const
Return true if the object with objectName exists.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
bool hasResultObject(const word &objectName) const
Return true if the object with objectName exists in results.
OBJstream os(runTime.globalPath()/outputName)
void operator=(const properties &)=delete
No copy assignment.
Type getObjectProperty(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property from named object.
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
bool getObjectResultDict(const word &objectName, dictionary &dict) const
Get dictionary of object results, return true if set.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127