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  // 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  template<class Type>
197  void getModelProperty(const word& entryName, Type& value) const;
198 
199  //- Retrieve generic property from the sub-model
200  template<class Type>
201  Type getModelProperty
202  (
203  const word& entryName,
204  const Type& defaultValue = Type(Zero)
205  ) const;
206 
207  //- Add generic property to the sub-model
208  template<class Type>
209  void setModelProperty(const word& entryName, const Type& value);
210 
211 
212  // I-O
213 
214  //- Write
215  virtual void write(Ostream& os) const;
216 };
217 
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 } // End namespace Foam
222 
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 
225 #ifdef NoRepository
226  #include "subModelBaseTemplates.C"
227 #endif
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 #endif
232 
233 // ************************************************************************* //
Foam::subModelBase
Base class for generic sub-models requiring to be read from dictionary. Provides a mechanism to read ...
Definition: subModelBase.H:54
Foam::subModelBase::modelType_
const word modelType_
Type of the sub-model.
Definition: subModelBase.H:79
Foam::subModelBase::active
virtual bool active() const
Return the model 'active' status - default active = true.
Definition: subModelBase.C:157
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::subModelBase::getModelProperty
void getModelProperty(const word &entryName, Type &value) const
Retrieve generic property from the sub-model.
Definition: subModelBaseTemplates.C:86
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::subModelBase::properties
const dictionary & properties() const
Return const access to the properties dictionary.
Definition: subModelBase.C:137
Foam::subModelBase::properties_
dictionary & properties_
Reference to properties dictionary e.g. for restart.
Definition: subModelBase.H:70
Foam::subModelBase::getBaseProperty
Type getBaseProperty(const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property from the base model.
Definition: subModelBaseTemplates.C:32
Foam::subModelBase::coeffDict_
const dictionary coeffDict_
Coefficients dictionary.
Definition: subModelBase.H:82
Foam::subModelBase::modelName
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:107
subModelBaseTemplates.C
Foam::subModelBase::setModelProperty
void setModelProperty(const word &entryName, const Type &value)
Add generic property to the sub-model.
Definition: subModelBaseTemplates.C:122
Foam::subModelBase::baseName_
const word baseName_
Name of the sub-model base class.
Definition: subModelBase.H:76
Foam::subModelBase::write
virtual void write(Ostream &os) const
Write.
Definition: subModelBase.C:212
Foam::subModelBase::dict
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:113
Foam::subModelBase::inLine
bool inLine() const
Flag to indicate whether data is/was read in-line.
Foam::subModelBase::defaultCoeffs
virtual bool defaultCoeffs(const bool printMsg) const
Returns true if defaultCoeffs is true and outputs on printMsg.
Definition: subModelBase.C:143
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::subModelBase::coeffDict
const dictionary & coeffDict() const
Return const access to the coefficients dictionary.
Definition: subModelBase.C:131
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::subModelBase::getModelDict
bool getModelDict(const word &entryName, dictionary &dict) const
Retrieve dictionary, return true if set.
Definition: subModelBase.C:185
Foam::subModelBase::modelType
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:125
Foam::subModelBase::cacheFields
virtual void cacheFields(const bool store)
Cache dependent sub-model fields.
Definition: subModelBase.C:163
Foam::subModelBase::writeTime
virtual bool writeTime() const
Flag to indicate when to write a property.
Definition: subModelBase.C:167
Foam::subModelBase::setBaseProperty
void setBaseProperty(const word &entryName, const Type &value)
Add generic property to the base model.
Definition: subModelBaseTemplates.C:66
Foam::subModelBase::~subModelBase
virtual ~subModelBase()
Destructor.
Definition: subModelBase.C:101
dictionary.H
Foam::subModelBase::baseName
const word & baseName() const
Return const access to the base name of the sub-model.
Definition: subModelBase.C:119
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::subModelBase::dict_
const dictionary dict_
Copy of dictionary used during construction.
Definition: subModelBase.H:73
Foam::subModelBase::modelName_
const word modelName_
Name of the sub-model.
Definition: subModelBase.H:67
Foam::subModelBase::subModelBase
subModelBase(dictionary &properties)
Construct null.
Definition: subModelBase.C:41
Foam::subModelBase::localPath
virtual fileName localPath() const
Output directory.
Definition: subModelBase.C:173