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-2020 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  //- Cache dependent sub-model fields
145  virtual void cacheFields(const bool store);
146 
147  //- Flag to indicate when to write a property
148  virtual bool writeTime() const = 0;
149 
150 
151  // Edit
152 
153  // Base properties
154 
155  //- Retrieve generic property from the base model
156  template<class Type>
157  Type getBaseProperty
158  (
159  const word& entryName,
160  const Type& defaultValue = pTraits<Type>::zero
161  ) const;
162 
163  //- Retrieve generic property from the base model
164  template<class Type>
165  void getBaseProperty(const word& entryName, Type& value) const;
166 
167  //- Add generic property to the base model
168  template<class Type>
169  void setBaseProperty(const word& entryName, const Type& value);
170 
171 
172  // Model properties
173 
174  //- Retrieve generic property from the sub-model
175  template<class Type>
176  void getModelProperty(const word& entryName, Type& value) const;
177 
178  //- Retrieve generic property from the sub-model
179  template<class Type>
180  Type getModelProperty
181  (
182  const word& entryName,
183  const Type& defaultValue = pTraits<Type>::zero
184  ) const;
185 
186  //- Add generic property to the sub-model
187  template<class Type>
188  void setModelProperty(const word& entryName, const Type& value);
189 
190 
191  // I-O
192 
193  //- Write
194  virtual void write(Ostream& os) const;
195 
196 
197  // Member Operators
198 
199  //- Disallow default bitwise assignment
200  void operator=(const subModelBase&) = delete;
201 };
202 
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 } // End namespace Foam
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 #ifdef NoRepository
211  #include "subModelBaseTemplates.C"
212 #endif
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 #endif
217 
218 // ************************************************************************* //
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:156
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
virtual bool writeTime() const =0
Flag to indicate when to write a property.
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:158
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:154
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
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
Namespace for OpenFOAM.