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-2019 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"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 class IOdictionary;
60 
61 namespace functionObjects
62 {
63 
64 /*---------------------------------------------------------------------------*\
65  Class stateFunctionObject Declaration
66 \*---------------------------------------------------------------------------*/
67 
69 :
71 {
72  // Private Member Data
73 
74  //- Name of the results dictionary
75  static const word resultsName_;
76 
77 
78 protected:
79 
80  // Protected Member Functions
81 
82  //- Return a const reference to the state dictionary
83  const IOdictionary& stateDict() const;
84 
85  //- Return non-const access to the state dictionary
87 
88 
89  //- No copy construct
91 
92  //- No copy assignment
93  void operator=(const stateFunctionObject&) = delete;
94 
95 
96 public:
97 
98  // Constructors
99 
100  //- Construct from components
101  stateFunctionObject(const word& name, const Time& runTime);
102 
103 
104  //- Destructor
105  virtual ~stateFunctionObject() = default;
106 
107 
108  // Member Functions
109 
110  //- Return access to the property dictionary
112 
113 
114  // Properties
115 
116  //- Return true if the property exists
117  bool foundProperty(const word& entryName) const;
118 
119  //- Get the current trigger index
120  label getTrigger() const;
121 
122  //- Set the current trigger index
123  bool setTrigger(const label triggeri);
124 
125  //- Set dictionary, return true if set
126  bool getDict
127  (
128  const word& entryName,
130  ) const;
131 
132  //- Set dictionary from named object, return true if set
133  bool getObjectDict
134  (
135  const word& objectName,
136  const word& entryName,
138  ) const;
139 
140  //- Retrieve generic property
141  template<class Type>
142  Type getProperty
143  (
144  const word& entryName,
145  const Type& defaultValue = Type(Zero)
146  ) const;
147 
148  //- Set generic property, return true if set
149  template<class Type>
150  bool getProperty(const word& entryName, Type& value) const;
151 
152  //- Add generic property
153  template<class Type>
154  void setProperty(const word& entryName, const Type& value);
155 
156  //- Retrieve generic property from named object
157  template<class Type>
158  Type getObjectProperty
159  (
160  const word& objectName,
161  const word& entryName,
162  const Type& defaultValue = Type(Zero)
163  ) const;
164 
165  //- Set generic property from named object, return true if set
166  template<class Type>
167  bool getObjectProperty
168  (
169  const word& objectName,
170  const word& entryName,
171  Type& value
172  ) const;
173 
174  //- Add generic property from named object
175  template<class Type>
176  void setObjectProperty
177  (
178  const word& objectName,
179  const word& entryName,
180  const Type& value
181  );
182 
183 
184  // Results
185 
186  //- Add result
187  template<class Type>
188  void setResult
189  (
190  const word& entryName,
191  const Type& value
192  );
193 
194  //- Add result from named object
195  template<class Type>
196  void setObjectResult
197  (
198  const word& objectName,
199  const word& entryName,
200  const Type& value
201  );
202 
203  //- Retrieve result
204  template<class Type>
205  Type getResult
206  (
207  const word& entryName,
208  const Type& defaultValue = Type(Zero)
209  ) const;
210 
211  //- Retrieve result from named object
212  template<class Type>
213  Type getObjectResult
214  (
215  const word& objectName,
216  const word& entryName,
217  const Type& defaultValue = Type(Zero)
218  ) const;
219 
220  //- Set result from named object, return true if set
221  template<class Type>
222  bool getObjectResult
223  (
224  const word& objectName,
225  const word& entryName,
226  Type& value
227  ) const;
228 
229  //- Retrieve the result type
230  word resultType(const word& entryName) const;
231 
232  //- Return the type of result
234  (
235  const word& objectName,
236  const word& entryName
237  ) const;
238 
239  //- Retrieve the result entries
241 
242  //- Return result entries for named object
243  List<word> objectResultEntries(const word& objectName) const;
244 
245  //- Write the results entries for all objects to stream
246  void writeResultEntries(Ostream& os) const;
247 
248  //- Write the results entries for named object to stream
249  void writeResultEntries(const word& objectName, Ostream& os) const;
250 
251  //- Write the results entries for all objects to stream
252  void writeAllResultEntries(Ostream& os) const;
253 };
254 
255 
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 
258 } // End namespace functionObjects
259 } // End namespace Foam
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 #ifdef NoRepository
265 #endif
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 #endif
270 
271 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
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:67
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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:67
Foam::functionObjects::timeFunctionObject
Virtual base class for function objects with a reference to Time.
Definition: timeFunctionObject.H:56
Foam::functionObjects::stateFunctionObject::setTrigger
bool setTrigger(const label triggeri)
Set the current trigger index.
Definition: stateFunctionObject.C:81
Foam::functionObjects::stateFunctionObject::resultType
word resultType(const word &entryName) const
Retrieve the result type.
Definition: stateFunctionObject.C:159
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:100
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:136
Foam::functionObjects::stateFunctionObject::writeAllResultEntries
void writeAllResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
Definition: stateFunctionObject.C:282
Foam::functionObjects::stateFunctionObject::foundProperty
bool foundProperty(const word &entryName) const
Return true if the property exists.
Definition: stateFunctionObject.C:109
stateFunctionObjectTemplates.C
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:121
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:126
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::stateFunctionObject::~stateFunctionObject
virtual ~stateFunctionObject()=default
Destructor.
Foam::functionObjects::stateFunctionObject::stateDict
const IOdictionary & stateDict() const
Return a const reference to the state dictionary.
Definition: stateFunctionObject.C:41
Foam::functionObjects::stateFunctionObject::objectResultType
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
Definition: stateFunctionObject.C:168
Foam::functionObjects::stateFunctionObject::objectResultEntries
List< word > objectResultEntries() const
Retrieve the result entries.
Definition: stateFunctionObject.C:201
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
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:183
Foam::functionObjects::stateFunctionObject::setObjectResult
void setObjectResult(const word &objectName, const word &entryName, const Type &value)
Add result from named object.
Definition: stateFunctionObjectTemplates.C:135
Foam::functionObjects::stateFunctionObject::setObjectProperty
void setObjectProperty(const word &objectName, const word &entryName, const Type &value)
Add generic property from named object.
Definition: stateFunctionObjectTemplates.C:104
Foam::functionObjects::stateFunctionObject::writeResultEntries
void writeResultEntries(Ostream &os) const
Write the results entries for all objects to stream.
Definition: stateFunctionObject.C:241
Foam::functionObjects::stateFunctionObject::setResult
void setResult(const word &entryName, const Type &value)
Add result.
Definition: stateFunctionObjectTemplates.C:124
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:172
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