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  //- Add result from named object
169  template<class Type>
170  void setObjectResult
171  (
172  const word& objectName,
173  const word& entryName,
174  const Type& value
175  );
176 
177  //- Retrieve result from named object
178  template<class Type>
179  Type getObjectResult
180  (
181  const word& objectName,
182  const word& entryName,
183  const Type& defaultValue = Type(Zero)
184  ) const;
185 
186  //- Set result from named object, return true if set
187  template<class Type>
188  bool getObjectResult
189  (
190  const word& objectName,
191  const word& entryName,
192  Type& value
193  ) const;
194 
195  //- Return true if the object with objectName exists in results
196  bool hasResultObject(const word& objectName) const;
197 
198  //- Return list of objects with results
199  wordList objectResultNames() const;
200 
201  //- Return true if the object with objectName exists and has
202  //- entryName in its results
204  (
205  const word& objectName,
206  const word& entryName
207  ) const;
208 
209  //- Return the type of result
211  (
212  const word& objectName,
213  const word& entryName
214  ) const;
215 
216  //- Return result entries for named object
217  wordList objectResultEntries(const word& objectName) const;
218 
219  //- Write the results entries for all objects to stream
220  void writeResultEntries(Ostream& os) const;
221 
222  //- Write the results entries for named object to stream
223  void writeResultEntries(const word& objectName, Ostream& os) const;
224 
225  //- Write the results entries for all objects to stream
226  void writeAllResultEntries(Ostream& os) const;
227 };
228 
229 
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 
232 } // End namespace functionObjects
233 } // End namespace Foam
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 #ifdef NoRepository
239 #endif
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 #endif
244 
245 // ************************************************************************* //
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:120
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:55
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)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:171
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:133