functionObjectState.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 | Copyright (C) 2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::functionObjectState
26 
27 Description
28  Base class for function objects, adding functionality to read/write state
29  information (data required for smooth restart behaviour) and results
30  to/from the state dictionary
31 
32 See Also
33  Foam::functionObject
34 
35 SourceFiles
36  functionObjectState.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef functionObjectState_H
41 #define functionObjectState_H
42 
43 #include "objectRegistry.H"
44 #include "IOdictionary.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class functionObjectState Declaration
53 \*---------------------------------------------------------------------------*/
54 
56 {
57 private:
58 
59  // Private data
60 
61  //- Name of the results dictionary
62  static const word resultsName_;
63 
64  //- Reference to the database
65  const objectRegistry& obr_;
66 
67 
68 protected:
69 
70  // Protected data
71 
72  //- Name of model
73  const word name_;
74 
75  //- Flag to indicate whether the object is active
76  bool active_;
77 
78  //- Reference to the state dictionary
80 
81 
82 protected:
83 
84  // Protected Member Functions
85 
86  //- Disallow default bitwise copy construct
88 
89  //- Disallow default bitwise assignment
90  void operator=(const functionObjectState&);
91 
92 
93 public:
94 
95  // Constructors
96 
97  //- Construct from components
99  (
100  const objectRegistry& obr,
101  const word& name
102  );
103 
104 
105  //- Destructor
106  virtual ~functionObjectState();
107 
108 
109  // Member Functions
110 
111  //- Return the name
112  const word& name() const;
113 
114  //- Return the active flag
115  bool active() const;
116 
117  //- Return access to the state dictionary
118  const IOdictionary& stateDict() const;
119 
120  //- Return access to the property dictionary
122 
123  //- Set the active status by querying objectRegistry type
124  // returns new active status
125  template<class Type>
126  bool setActive();
127 
128 
129  // Properties
130 
131  //- Return true if the property exists
132  bool foundProperty(const word& entryName) const;
133 
134  //- Retrieve generic property
135  template<class Type>
136  Type getProperty
137  (
138  const word& entryName,
139  const Type& defaultValue = pTraits<Type>::zero
140  ) const;
141 
142  //- Retrieve generic property
143  template<class Type>
144  void getProperty(const word& entryName, Type& value) const;
145 
146  //- Add generic property
147  template<class Type>
148  void setProperty(const word& entryName, const Type& value);
149 
150  //- Retrieve generic property from named object
151  template<class Type>
152  Type getObjectProperty
153  (
154  const word& objectName,
155  const word& entryName,
156  const Type& defaultValue = pTraits<Type>::zero
157  ) const;
158 
159  //- Retrieve generic property from named object
160  template<class Type>
161  void getObjectProperty
162  (
163  const word& objectName,
164  const word& entryName,
165  Type& value
166  ) const;
167 
168  //- Add generic property from named object
169  template<class Type>
170  void setObjectProperty
171  (
172  const word& objectName,
173  const word& entryName,
174  const Type& value
175  );
176 
177 
178  // Results
179 
180  //- Add result
181  template<class Type>
182  void setResult
183  (
184  const word& entryName,
185  const Type& value
186  );
187 
188  //- Add result from named object
189  template<class Type>
190  void setObjectResult
191  (
192  const word& objectName,
193  const word& entryName,
194  const Type& value
195  );
196 
197  //- Retrieve result
198  template<class Type>
199  Type getResult
200  (
201  const word& entryName,
202  const Type& defaultValue = pTraits<Type>::zero
203  ) const;
204 
205  //- Retrieve result from named object
206  template<class Type>
207  Type getObjectResult
208  (
209  const word& objectName,
210  const word& entryName,
211  const Type& defaultValue = pTraits<Type>::zero
212  ) const;
213 
214  //- Retrieve result from named object
215  template<class Type>
216  void getObjectResult
217  (
218  const word& objectName,
219  const word& entryName,
220  Type& value
221  ) const;
222 
223  //- Retrieve the result type
224  word resultType(const word& entryName) const;
225 
226  //- Return the type of result
228  (
229  const word& objectName,
230  const word& entryName
231  ) const;
232 
233  //- Retrieve the result entries
235 
236  //- Return result entries for named object
237  List<word> objectResultEntries(const word& objectName) const;
238 };
239 
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 } // End namespace Foam
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 #ifdef NoRepository
249 #endif
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 
253 #endif
254 
255 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::functionObjectState::getProperty
Type getProperty(const word &entryName, const Type &defaultValue=pTraits< Type >::zero) const
Retrieve generic property.
Definition: functionObjectStateTemplates.C:48
Foam::functionObjectState
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: functionObjectState.H:54
Foam::functionObjectState::~functionObjectState
virtual ~functionObjectState()
Destructor.
Definition: functionObjectState.C:52
objectRegistry.H
Foam::functionObjectState::setActive
bool setActive()
Set the active status by querying objectRegistry type.
Definition: functionObjectStateTemplates.C:29
Foam::functionObjectState::objectResultType
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
Definition: functionObjectState.C:106
Foam::functionObjectState::resultType
word resultType(const word &entryName) const
Retrieve the result type.
Definition: functionObjectState.C:99
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::functionObjectState::setProperty
void setProperty(const word &entryName, const Type &value)
Add generic property.
Definition: functionObjectStateTemplates.C:72
Foam::functionObjectState::setObjectResult
void setObjectResult(const word &objectName, const word &entryName, const Type &value)
Add result from named object.
Definition: functionObjectStateTemplates.C:152
Foam::functionObjectState::functionObjectState
functionObjectState(const functionObjectState &)
Disallow default bitwise copy construct.
Foam::functionObjectState::getResult
Type getResult(const word &entryName, const Type &defaultValue=pTraits< Type >::zero) const
Retrieve result.
Definition: functionObjectStateTemplates.C:187
Foam::functionObjectState::obr_
const objectRegistry & obr_
Reference to the database.
Definition: functionObjectState.H:64
Foam::functionObjectState::setResult
void setResult(const word &entryName, const Type &value)
Add result.
Definition: functionObjectStateTemplates.C:141
Foam::functionObjectState::setObjectProperty
void setObjectProperty(const word &objectName, const word &entryName, const Type &value)
Add generic property from named object.
Definition: functionObjectStateTemplates.C:123
Foam::functionObjectState::active
bool active() const
Return the active flag.
Definition: functionObjectState.C:64
Foam::functionObjectState::operator=
void operator=(const functionObjectState &)
Disallow default bitwise assignment.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::functionObjectState::getObjectResult
Type getObjectResult(const word &objectName, const word &entryName, const Type &defaultValue=pTraits< Type >::zero) const
Retrieve result from named object.
Definition: functionObjectStateTemplates.C:198
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::functionObjectState::active_
bool active_
Flag to indicate whether the object is active.
Definition: functionObjectState.H:75
Foam::functionObjectState::resultsName_
static const word resultsName_
Name of the results dictionary.
Definition: functionObjectState.H:61
IOdictionary.H
Foam::functionObjectState::stateDict_
IOdictionary & stateDict_
Reference to the state dictionary.
Definition: functionObjectState.H:78
Foam::functionObjectState::name_
const word name_
Name of model.
Definition: functionObjectState.H:72
Foam::List< word >
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::functionObjectState::propertyDict
dictionary & propertyDict()
Return access to the property dictionary.
Definition: functionObjectState.C:76
Foam::functionObjectState::getObjectProperty
Type getObjectProperty(const word &objectName, const word &entryName, const Type &defaultValue=pTraits< Type >::zero) const
Retrieve generic property from named object.
Definition: functionObjectStateTemplates.C:83
Foam::functionObjectState::foundProperty
bool foundProperty(const word &entryName) const
Return true if the property exists.
Definition: functionObjectState.C:87
Foam::functionObjectState::objectResultEntries
List< word > objectResultEntries() const
Retrieve the result entries.
Definition: functionObjectState.C:137
Foam::functionObjectState::stateDict
const IOdictionary & stateDict() const
Return access to the state dictionary.
Definition: functionObjectState.C:70
functionObjectStateTemplates.C
Foam::functionObjectState::name
const word & name() const
Return the name.
Definition: functionObjectState.C:58