subModelBase.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::subModelBase
29
30Description
31 Base class for generic sub-models requiring to be read from dictionary.
32 Provides a mechanism to read and write properties from a dictionary to
33 enable clean re-starts. Used by, e.g. clou dsub-models.
34
35SourceFiles
36 subModelBase.C
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef subModelBase_H
41#define subModelBase_H
42
43#include "dictionary.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50
51/*---------------------------------------------------------------------------*\
52 Class subModelBase Declaration
53\*---------------------------------------------------------------------------*/
55class subModelBase
56{
57 // Private Member Functions
58
59 //- No copy assignment
60 void operator=(const subModelBase&) = delete;
61
62
63protected:
64
65 // Protected Data
66
67 //- Name of the sub-model
68 const word modelName_;
69
70 //- Reference to properties dictionary e.g. for restart
72
73 //- Copy of dictionary used during construction
74 const dictionary dict_;
75
76 //- Name of the sub-model base class
77 const word baseName_;
78
79 //- Type of the sub-model
80 const word modelType_;
81
82 //- Coefficients dictionary
84
85
86 // Protected Member Functions
87
88 //- Flag to indicate whether data is/was read in-line
89 bool inLine() const;
90
91
92public:
93
94 // Constructors
95
96 //- Construct null
98
99 //- Construct from components without name
101 (
103 const dictionary& dict,
104 const word& baseName,
105 const word& modelType,
106 const word& dictExt = "Coeffs"
107 );
108
109 //- Construct from components with name
111 (
112 const word& modelName,
114 const dictionary& dict,
115 const word& baseName,
116 const word& modelType
117 );
118
119 //- Construct as copy
120 subModelBase(const subModelBase& smb);
121
122
123 //- Destructor
124 virtual ~subModelBase();
125
126
127 // Member Functions
128
129 // Access
130
131 //- Return const access to the name of the sub-model
132 const word& modelName() const;
133
134 //- Return const access to the cloud dictionary
135 const dictionary& dict() const;
136
137 //- Return const access to the base name of the sub-model
138 const word& baseName() const;
139
140 //- Return const access to the sub-model type
141 const word& modelType() const;
142
143 //- Return const access to the coefficients dictionary
144 const dictionary& coeffDict() const;
145
146 //- Return const access to the properties dictionary
147 const dictionary& properties() const;
148
149 //- Returns true if defaultCoeffs is true and outputs on printMsg
150 virtual bool defaultCoeffs(const bool printMsg) const;
151
152 //- Return the model 'active' status - default active = true
153 virtual bool active() const;
154
155 //- Cache dependent sub-model fields
156 virtual void cacheFields(const bool store);
157
158 //- Flag to indicate when to write a property
159 virtual bool writeTime() const;
160
161 //- Output directory
162 virtual fileName localPath() const;
163
164
165 // Edit
166
167 // Base properties
168
169 //- Retrieve generic property from the base model
170 template<class Type>
171 Type getBaseProperty
172 (
173 const word& entryName,
174 const Type& defaultValue = Type(Zero)
175 ) const;
176
177 //- Retrieve generic property from the base model
178 template<class Type>
179 void getBaseProperty(const word& entryName, Type& value) const;
180
181 //- Add generic property to the base model
182 template<class Type>
183 void setBaseProperty(const word& entryName, const Type& value);
184
185
186 // Model properties
187
188 //- Retrieve dictionary, return true if set
189 bool getModelDict
190 (
191 const word& entryName,
193 ) const;
194
195 //- Retrieve generic property from the sub-model
196 // Return true if found
197 template<class Type>
198 bool getModelProperty(const word& entryName, Type& value) const;
199
200 //- Retrieve generic property from the sub-model
201 template<class Type>
203 (
204 const word& entryName,
205 const Type& defaultValue = Type(Zero)
206 ) const;
207
208 //- Add generic property to the sub-model
209 template<class Type>
210 void setModelProperty(const word& entryName, const Type& value);
211
212
213 // I-O
214
215 //- Write
216 virtual void write(Ostream& os) const;
217};
218
219
220// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221
222} // End namespace Foam
223
224// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225
226#ifdef NoRepository
227 #include "subModelBaseTemplates.C"
228#endif
229
230// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231
232#endif
233
234// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
Base class for generic sub-models requiring to be read from dictionary. Provides a mechanism to read ...
Definition: subModelBase.H:55
bool getModelProperty(const word &entryName, Type &value) const
Retrieve generic property from the sub-model.
const word modelType_
Type of the sub-model.
Definition: subModelBase.H:79
const word modelName_
Name of the sub-model.
Definition: subModelBase.H:67
virtual ~subModelBase()
Destructor.
Definition: subModelBase.C:101
const word & baseName() const
Return const access to the base name of the sub-model.
Definition: subModelBase.C:119
virtual void cacheFields(const bool store)
Cache dependent sub-model fields.
Definition: subModelBase.C:163
bool inLine() const
Flag to indicate whether data is/was read in-line.
Definition: subModelBase.C:33
virtual fileName localPath() const
Output directory.
Definition: subModelBase.C:173
const dictionary & coeffDict() const
Return const access to the coefficients dictionary.
Definition: subModelBase.C:131
Type getBaseProperty(const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property from the base model.
const dictionary & properties() const
Return const access to the properties dictionary.
Definition: subModelBase.C:137
bool getModelDict(const word &entryName, dictionary &dict) const
Retrieve dictionary, return true if set.
Definition: subModelBase.C:185
const dictionary coeffDict_
Coefficients dictionary.
Definition: subModelBase.H:82
const word baseName_
Name of the sub-model base class.
Definition: subModelBase.H:76
const dictionary dict_
Copy of dictionary used during construction.
Definition: subModelBase.H:73
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:113
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:107
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:125
virtual bool active() const
Return the model 'active' status - default active = true.
Definition: subModelBase.C:157
virtual bool defaultCoeffs(const bool printMsg) const
Returns true if defaultCoeffs is true and outputs on printMsg.
Definition: subModelBase.C:143
void setBaseProperty(const word &entryName, const Type &value)
Add generic property to the base model.
dictionary & properties_
Reference to properties dictionary e.g. for restart.
Definition: subModelBase.H:70
virtual bool writeTime() const
Flag to indicate when to write a property.
Definition: subModelBase.C:167
void setModelProperty(const word &entryName, const Type &value)
Add generic property to the sub-model.
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
runTime write()