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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::functionObjects::stateFunctionObject
29 
30 Description
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 
40 See also
41  Foam::functionObject
42 
43 SourceFiles
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 
57 namespace Foam
58 {
59 
60 // Forward Declarations
61 class IOdictionary;
62 
63 namespace functionObjects
64 {
65 
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 
80 protected:
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 
98 public:
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 the trigger index. Normally only if greater than current
128  //
129  // \param triggeri the new trigger index
130  // \param increaseOnly (default) only change if new index
131  // is greater than the current index.
132  //
133  // \return True if the index changed
134  bool setTrigger(const label triggeri, bool increaseOnly = true);
135 
136  //- Set dictionary, return true if set
137  bool getDict
138  (
139  const word& entryName,
141  ) const;
142 
143  //- Set dictionary from named object, return true if set
144  bool getObjectDict
145  (
146  const word& objectName,
147  const word& entryName,
149  ) const;
150 
151  //- Retrieve generic property
152  template<class Type>
153  Type getProperty
154  (
155  const word& entryName,
156  const Type& defaultValue = Type(Zero)
157  ) const;
158 
159  //- Set generic property, return true if set
160  template<class Type>
161  bool getProperty(const word& entryName, Type& value) const;
162 
163  //- Add generic property
164  template<class Type>
165  void setProperty(const word& entryName, const Type& value);
166 
167  //- Retrieve generic property from named object
168  template<class Type>
169  Type getObjectProperty
170  (
171  const word& objectName,
172  const word& entryName,
173  const Type& defaultValue = Type(Zero)
174  ) const;
175 
176  //- Set generic property from named object, return true if set
177  template<class Type>
178  bool getObjectProperty
179  (
180  const word& objectName,
181  const word& entryName,
182  Type& value
183  ) const;
184 
185  //- Add generic property from named object
186  template<class Type>
187  void setObjectProperty
188  (
189  const word& objectName,
190  const word& entryName,
191  const Type& value
192  );
193 
194 
195  // Results
196 
197  //- Add result
198  template<class Type>
199  void setResult
200  (
201  const word& entryName,
202  const Type& value
203  );
204 
205  //- Add result from named object
206  template<class Type>
207  void setObjectResult
208  (
209  const word& objectName,
210  const word& entryName,
211  const Type& value
212  );
213 
214  //- Retrieve result
215  template<class Type>
216  Type getResult
217  (
218  const word& entryName,
219  const Type& defaultValue = Type(Zero)
220  ) const;
221 
222  //- Retrieve result from named object
223  template<class Type>
224  Type getObjectResult
225  (
226  const word& objectName,
227  const word& entryName,
228  const Type& defaultValue = Type(Zero)
229  ) const;
230 
231  //- Set result from named object, return true if set
232  template<class Type>
233  bool getObjectResult
234  (
235  const word& objectName,
236  const word& entryName,
237  Type& value
238  ) const;
239 
240  //- Retrieve the result type
241  word resultType(const word& entryName) const;
242 
243  //- Return the type of result
245  (
246  const word& objectName,
247  const word& entryName
248  ) const;
249 
250  //- Retrieve the result entries
252 
253  //- Return result entries for named object
254  wordList objectResultEntries(const word& objectName) const;
255 
256  //- Write the results entries for all objects to stream
257  void writeResultEntries(Ostream& os) const;
258 
259  //- Write the results entries for named object to stream
260  void writeResultEntries(const word& objectName, Ostream& os) const;
261 
262  //- Write the results entries for all objects to stream
263  void writeAllResultEntries(Ostream& os) const;
264 };
265 
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 } // End namespace functionObjects
270 } // End namespace Foam
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 #ifdef NoRepository
276 #endif
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 #endif
281 
282 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObjects::stateFunctionObject::propertyDict
dictionary & propertyDict()
Return access to the property dictionary.
Definition: stateFunctionObject.C:71
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::stateFunctionObject
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: stateFunctionObject.H:69
Foam::functionObjects::timeFunctionObject
Virtual base class for function objects with a reference to Time.
Definition: timeFunctionObject.H:56
Foam::functionObjects::stateFunctionObject::resultType
word resultType(const word &entryName) const
Retrieve the result type.
Definition: stateFunctionObject.C:130
Foam::functionObjects::stateFunctionObject::stateFunctionObject
stateFunctionObject(const stateFunctionObject &)=delete
No copy construct.
Foam::functionObjects::stateFunctionObject::getProperty
Type getProperty(const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property.
Definition: stateFunctionObjectTemplates.C:35
Foam::functionObjects::stateFunctionObject::getTrigger
label getTrigger() const
Get the current trigger index.
Definition: stateFunctionObject.C:83
timeFunctionObject.H
Foam::functionObjects::stateFunctionObject::getObjectDict
bool getObjectDict(const word &objectName, const word &entryName, dictionary &dict) const
Set dictionary from named object, return true if set.
Definition: stateFunctionObject.C:119
functionObjectProperties.H
Foam::functionObjects::stateFunctionObject::writeAllResultEntries
void writeAllResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
Definition: stateFunctionObject.C:185
Foam::functionObjects::stateFunctionObject::objectResultEntries
wordList objectResultEntries() const
Retrieve the result entries.
Definition: stateFunctionObject.C:149
Foam::functionObjects::stateFunctionObject::clearTrigger
void clearTrigger()
Remove the trigger index from the properties.
Definition: stateFunctionObject.C:77
Foam::functionObjects::stateFunctionObject::foundProperty
bool foundProperty(const word &entryName) const
Return true if the property exists.
Definition: stateFunctionObject.C:100
stateFunctionObjectTemplates.C
Foam::functionObjects::stateFunctionObject::setTrigger
bool setTrigger(const label triggeri, bool increaseOnly=true)
Set the trigger index. Normally only if greater than current.
Definition: stateFunctionObject.C:90
dict
dictionary dict
Definition: searchingEngine.H:14
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::stateFunctionObject::operator=
void operator=(const stateFunctionObject &)=delete
No copy assignment.
Foam::functionObjects::stateFunctionObject::getDict
bool getDict(const word &entryName, dictionary &dict) const
Set dictionary, return true if set.
Definition: stateFunctionObject.C:109
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::stateFunctionObject::~stateFunctionObject
virtual ~stateFunctionObject()=default
Destructor.
Foam::functionObjects::stateFunctionObject::objectResultType
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
Definition: stateFunctionObject.C:139
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
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::stateFunctionObject::getObjectResult
Type getObjectResult(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve result from named object.
Definition: stateFunctionObjectTemplates.C:142
Foam::functionObjects::stateFunctionObject::setObjectResult
void setObjectResult(const word &objectName, const word &entryName, const Type &value)
Add result from named object.
Definition: stateFunctionObjectTemplates.C:119
Foam::functionObjects::stateFunctionObject::setObjectProperty
void setObjectProperty(const word &objectName, const word &entryName, const Type &value)
Add generic property from named object.
Definition: stateFunctionObjectTemplates.C:96
Foam::functionObjects::stateFunctionObject::stateDict
const functionObjects::properties & stateDict() const
Return a const reference to the state dictionary.
Definition: stateFunctionObject.C:41
Foam::functionObjects::stateFunctionObject::writeResultEntries
void writeResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
Definition: stateFunctionObject.C:166
Foam::functionObjects::stateFunctionObject::setResult
void setResult(const word &entryName, const Type &value)
Add result.
Definition: stateFunctionObjectTemplates.C:108
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::functionObjects::stateFunctionObject::setProperty
void setProperty(const word &entryName, const Type &value)
Add generic property.
Definition: stateFunctionObjectTemplates.C:59
Foam::functionObjects::stateFunctionObject::getResult
Type getResult(const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve result.
Definition: stateFunctionObjectTemplates.C:131
Foam::functionObjects::stateFunctionObject::getObjectProperty
Type getObjectProperty(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property from named object.
Definition: stateFunctionObjectTemplates.C:70