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 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 the trigger index. Normally only if greater than current
127  //
128  // \param triggeri the new trigger index
129  // \param increaseOnly (default) only change if new index
130  // is greater than the current index.
131  //
132  // \return True if the index changed
133  bool setTrigger(const label triggeri, bool increaseOnly = true);
134 
135  //- Set dictionary from named object, return true if set
136  bool getObjectDict
137  (
138  const word& objectName,
139  const word& entryName,
141  ) const;
142 
143  //- Retrieve generic property from named object
144  template<class Type>
145  Type getObjectProperty
146  (
147  const word& objectName,
148  const word& entryName,
149  const Type& defaultValue = Type(Zero)
150  ) const;
151 
152  //- Set generic property from named object, return true if set
153  template<class Type>
154  bool getObjectProperty
155  (
156  const word& objectName,
157  const word& entryName,
158  Type& value
159  ) const;
160 
161  //- Add generic property from named object
162  template<class Type>
163  void setObjectProperty
164  (
165  const word& objectName,
166  const word& entryName,
167  const Type& value
168  );
169 
170 
171  // Results
172 
173  //- Add result from named object
174  template<class Type>
175  void setObjectResult
176  (
177  const word& objectName,
178  const word& entryName,
179  const Type& value
180  );
181 
182  //- Retrieve result from named object
183  template<class Type>
184  Type getObjectResult
185  (
186  const word& objectName,
187  const word& entryName,
188  const Type& defaultValue = Type(Zero)
189  ) const;
190 
191  //- Set result from named object, return true if set
192  template<class Type>
193  bool getObjectResult
194  (
195  const word& objectName,
196  const word& entryName,
197  Type& value
198  ) const;
199 
200  //- Return true if the object with objectName exists in results
201  bool hasResultObject(const word& objectName) const;
202 
203  //- Return list of objects with results
204  wordList objectResultNames() const;
205 
206  //- Return true if the object with objectName exists and has
207  //- entryName in its results
209  (
210  const word& objectName,
211  const word& entryName
212  ) const;
213 
214  //- Return the type of result
216  (
217  const word& objectName,
218  const word& entryName
219  ) const;
220 
221  //- Return result entries for named object
222  wordList objectResultEntries(const word& objectName) const;
223 
224  //- Write the results entries for all objects to stream
225  void writeResultEntries(Ostream& os) const;
226 
227  //- Write the results entries for named object to stream
228  void writeResultEntries(const word& objectName, Ostream& os) const;
229 
230  //- Write the results entries for all objects to stream
231  void writeAllResultEntries(Ostream& os) const;
232 };
233 
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 } // End namespace functionObjects
238 } // End namespace Foam
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 #ifdef NoRepository
244 #endif
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 #endif
249 
250 // ************************************************************************* //
Foam::functionObjects::properties::getObjectProperty
Type getObjectProperty(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property from named object.
Definition: functionObjectPropertiesTemplates.C:34
Foam::functionObjects::properties::hasObjectDict
bool hasObjectDict(const word &objectName) const
Return true if the object with objectName exists.
Definition: functionObjectProperties.C:60
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::functionObjects::properties::propertyDict
dictionary & propertyDict(const word &objectName)
Return access to the property dictionary.
Foam::functionObjects::properties::operator=
void operator=(const properties &)=delete
No copy assignment.
Foam::functionObjects::properties::getObjectDict
dictionary & getObjectDict(const word &objectName)
Get dictionary for named object. Creates one if required.
Definition: functionObjectProperties.C:69
Foam::functionObjects::properties::hasResultObject
bool hasResultObject(const word &objectName) const
Return true if the object with objectName exists in results.
Definition: functionObjectProperties.C:156
Foam::functionObjects::properties::getTrigger
label getTrigger() const
Get the current trigger index.
Definition: functionObjectProperties.C:88
Foam::functionObjects::properties::clearTrigger
void clearTrigger()
Remove the trigger index from the properties.
Definition: functionObjectProperties.C:82
Foam::functionObjects::properties::foundObjectProperty
bool foundObjectProperty(const word &objectName, const word &entryName) const
Return true if the property exists.
Definition: functionObjectProperties.C:118
Foam::functionObjects::properties::objectResultType
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
Definition: functionObjectProperties.C:211
Foam::functionObjects::properties::getObjectResult
Type getObjectResult(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve result from named object.
Definition: functionObjectPropertiesTemplates.C:119
Foam::functionObjects::properties::setObjectProperty
void setObjectProperty(const word &objectName, const word &entryName, const Type &value)
Add generic property from named object.
Definition: functionObjectPropertiesTemplates.C:66
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjects::properties::properties
properties(const properties &)=delete
No copy construct.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::functionObjects::properties::setTrigger
bool setTrigger(const label triggeri, bool increaseOnly=true)
Set the trigger index. Normally only if greater than current.
Definition: functionObjectProperties.C:98
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::properties::~properties
virtual ~properties()=default
Destructor.
IOdictionary.H
Foam::functionObjects::properties::objectResultNames
wordList objectResultNames() const
Return list of objects with results.
Definition: functionObjectProperties.C:169
Foam::functionObjects::properties::objectNames
wordList objectNames() const
Return list of object names.
Definition: functionObjectProperties.C:50
Foam::functionObjects::properties
Storage for function object properties, derived from IOdictionary. Provides functionality to read/wri...
Definition: functionObjectProperties.H:62
Foam::List< word >
Foam::functionObjects::properties::writeAllResultEntries
void writeAllResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
Definition: functionObjectProperties.C:302
Foam::functionObjects::properties::hasResultObjectEntry
bool hasResultObjectEntry(const word &objectName, const word &entryName) const
Definition: functionObjectProperties.C:181
Foam::functionObjects::properties::writeResultEntries
void writeResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
functionObjectPropertiesTemplates.C
Foam::functionObjects::properties::setObjectResult
void setObjectResult(const word &objectName, const word &entryName, const Type &value)
Add result from named object.
Definition: functionObjectPropertiesTemplates.C:84
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::functionObjects::properties::objectResultEntries
wordList objectResultEntries(const word &objectName) const
Return result entries for named object.
Definition: functionObjectProperties.C:241