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