All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
subModelBase.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
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::subModelBase
26 
27 Description
28  Base class for generic sub-models requiring to be read from dictionary.
29  Provides a mechanism to read and write properties from a dictionary to
30  enable clean re-starts. Used by, e.g. clou dsub-models.
31 
32 SourceFiles
33  subModelBase.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef subModelBase_H
38 #define subModelBase_H
39 
40 #include "dictionary.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 
48 /*---------------------------------------------------------------------------*\
49  Class subModelBase Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class subModelBase
53 {
54 
55 protected:
56 
57  // Protected Data
58 
59  //- Name of the sub-model
60  const word modelName_;
61 
62  //- Reference to properties dictionary e.g. for restart
64 
65  //- Copy of dictionary used during construction
66  const dictionary dict_;
67 
68  //- Name of the sub-model base class
69  const word baseName_;
70 
71  //- Type of the sub-model
72  const word modelType_;
73 
74  //- Coefficients dictionary
75  const dictionary coeffDict_;
76 
77 
78  // Protected Member Functions
79 
80  //- Flag to indicate whether data is/was read in-line
81  bool inLine() const;
82 
83 
84 public:
85 
86  // Constructors
87 
88  //- Construct null
90 
91  //- Construct from components without name
93  (
95  const dictionary& dict,
96  const word& baseName,
97  const word& modelType,
98  const word& dictExt = "Coeffs"
99  );
100 
101  //- Construct from components with name
103  (
104  const word& modelName,
106  const dictionary& dict,
107  const word& baseName,
108  const word& modelType
109  );
110 
111  //- Copy constructor
112  subModelBase(const subModelBase& smb);
113 
114 
115  //- Destructor
116  virtual ~subModelBase();
117 
118 
119  // Member Functions
120 
121  // Access
122 
123  //- Return const access to the name of the sub-model
124  const word& modelName() const;
125 
126  //- Return const access to the cloud dictionary
127  const dictionary& dict() const;
128 
129  //- Return const access to the base name of the sub-model
130  const word& baseName() const;
131 
132  //- Return const access to the sub-model type
133  const word& modelType() const;
134 
135  //- Return const access to the coefficients dictionary
136  const dictionary& coeffDict() const;
137 
138  //- Return const access to the properties dictionary
139  const dictionary& properties() const;
140 
141  //- Returns true if defaultCoeffs is true and outputs on printMsg
142  virtual bool defaultCoeffs(const bool printMsg) const;
143 
144  //- Return the model 'active' status - default active = true
145  virtual bool active() const;
146 
147  //- Cache dependent sub-model fields
148  virtual void cacheFields(const bool store);
149 
150  //- Flag to indicate when to write a property
151  virtual bool writeTime() const;
152 
153 
154  // Edit
155 
156  // Base properties
157 
158  //- Retrieve generic property from the base model
159  template<class Type>
160  Type getBaseProperty
161  (
162  const word& entryName,
163  const Type& defaultValue = pTraits<Type>::zero
164  ) const;
165 
166  //- Retrieve generic property from the base model
167  template<class Type>
168  void getBaseProperty(const word& entryName, Type& value) const;
169 
170  //- Add generic property to the base model
171  template<class Type>
172  void setBaseProperty(const word& entryName, const Type& value);
173 
174 
175  // Model properties
176 
177  //- Retrieve generic property from the sub-model
178  template<class Type>
179  void getModelProperty(const word& entryName, Type& value) const;
180 
181  //- Retrieve generic property from the sub-model
182  template<class Type>
183  Type getModelProperty
184  (
185  const word& entryName,
186  const Type& defaultValue = pTraits<Type>::zero
187  ) const;
188 
189  //- Add generic property to the sub-model
190  template<class Type>
191  void setModelProperty(const word& entryName, const Type& value);
192 
193 
194  // I-O
195 
196  //- Write
197  virtual void write(Ostream& os) const;
198 
199 
200  // Member Operators
201 
202  //- Disallow default bitwise assignment
203  void operator=(const subModelBase&) = delete;
204 };
205 
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 } // End namespace Foam
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 #ifdef NoRepository
214  #include "subModelBaseTemplates.C"
215 #endif
216 
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 
219 #endif
220 
221 // ************************************************************************* //
const dictionary & properties() const
Return const access to the properties dictionary.
Definition: subModelBase.C:134
void getModelProperty(const word &entryName, Type &value) const
Retrieve generic property from the sub-model.
subModelBase(dictionary &properties)
Construct null.
Definition: subModelBase.C:38
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
const word modelType_
Type of the sub-model.
Definition: subModelBase.H:71
dictionary & properties_
Reference to properties dictionary e.g. for restart.
Definition: subModelBase.H:62
Traits class for primitives.
Definition: pTraits.H:50
const word baseName_
Name of the sub-model base class.
Definition: subModelBase.H:68
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:104
const dictionary coeffDict_
Coefficients dictionary.
Definition: subModelBase.H:74
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:110
virtual void write(Ostream &os) const
Write.
Definition: subModelBase.C:170
void setModelProperty(const word &entryName, const Type &value)
Add generic property to the sub-model.
A class for handling words, derived from string.
Definition: word.H:59
bool inLine() const
Flag to indicate whether data is/was read in-line.
const dictionary & coeffDict() const
Return const access to the coefficients dictionary.
Definition: subModelBase.C:128
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:122
virtual void cacheFields(const bool store)
Cache dependent sub-model fields.
Definition: subModelBase.C:160
virtual bool defaultCoeffs(const bool printMsg) const
Returns true if defaultCoeffs is true and outputs on printMsg.
Definition: subModelBase.C:140
virtual ~subModelBase()
Destructor.
Definition: subModelBase.C:98
Base class for generic sub-models requiring to be read from dictionary. Provides a mechanism to read ...
Definition: subModelBase.H:51
virtual bool writeTime() const
Flag to indicate when to write a property.
Definition: subModelBase.C:164
const word & baseName() const
Return const access to the base name of the sub-model.
Definition: subModelBase.C:116
void setBaseProperty(const word &entryName, const Type &value)
Add generic property to the base model.
void operator=(const subModelBase &)=delete
Disallow default bitwise assignment.
const dictionary dict_
Copy of dictionary used during construction.
Definition: subModelBase.H:65
Type getBaseProperty(const word &entryName, const Type &defaultValue=pTraits< Type >::zero) const
Retrieve generic property from the base model.
const word modelName_
Name of the sub-model.
Definition: subModelBase.H:59
virtual bool active() const
Return the model &#39;active&#39; status - default active = true.
Definition: subModelBase.C:154
Namespace for OpenFOAM.