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 | Copyright (C) 2011-2015 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  // Private Member Functions
55 
56  //- Disallow default bitwise assignment
57  void operator=(const subModelBase&);
58 
59 
60 protected:
61 
62  // Protected Data
63 
64  //- Name of the sub-model
65  const word modelName_;
66 
67  //- Reference to properties dictionary e.g. for restart
69 
70  //- Copy of dictionary used during construction
71  const dictionary dict_;
72 
73  //- Name of the sub-model base class
74  const word baseName_;
75 
76  //- Type of the sub-model
77  const word modelType_;
78 
79  //- Coefficients dictionary
80  const dictionary coeffDict_;
81 
82 
83  // Protected Member Functions
84 
85  //- Flag to indicate whether data is/was read in-line
86  bool inLine() const;
87 
88 
89 public:
90 
91  // Constructors
92 
93  //- Construct null
95 
96  //- Construct from components without name
98  (
100  const dictionary& dict,
101  const word& baseName,
102  const word& modelType,
103  const word& dictExt = "Coeffs"
104  );
105 
106  //- Construct from components with name
108  (
109  const word& modelName,
111  const dictionary& dict,
112  const word& baseName,
113  const word& modelType
114  );
115 
116  //- Construct as copy
117  subModelBase(const subModelBase& smb);
118 
119 
120  //- Destructor
121  virtual ~subModelBase();
122 
123 
124  // Member Functions
125 
126  // Access
127 
128  //- Return const access to the name of the sub-model
129  const word& modelName() const;
130 
131  //- Return const access to the cloud dictionary
132  const dictionary& dict() const;
133 
134  //- Return const access to the base name of the sub-model
135  const word& baseName() const;
136 
137  //- Return const access to the sub-model type
138  const word& modelType() const;
139 
140  //- Return const access to the coefficients dictionary
141  const dictionary& coeffDict() const;
142 
143  //- Return const access to the properties dictionary
144  const dictionary& properties() const;
145 
146  //- Returns true if defaultCoeffs is true and outputs on printMsg
147  virtual bool defaultCoeffs(const bool printMsg) const;
148 
149  //- Return the model 'active' status - default active = true
150  virtual bool active() const;
151 
152  //- Cache dependant sub-model fields
153  virtual void cacheFields(const bool store);
154 
155  //- Flag to indicate when to write a property
156  virtual bool outputTime() const;
157 
158 
159  // Edit
160 
161  // Base properties
162 
163  //- Retrieve generic property from the base model
164  template<class Type>
165  Type getBaseProperty
166  (
167  const word& entryName,
168  const Type& defaultValue = pTraits<Type>::zero
169  ) const;
170 
171  //- Retrieve generic property from the base model
172  template<class Type>
173  void getBaseProperty(const word& entryName, Type& value) const;
174 
175  //- Add generic property to the base model
176  template<class Type>
177  void setBaseProperty(const word& entryName, const Type& value);
178 
179 
180  // Model properties
181 
182  //- Retrieve generic property from the sub-model
183  template<class Type>
184  void getModelProperty(const word& entryName, Type& value) const;
185 
186  //- Retrieve generic property from the sub-model
187  template<class Type>
188  Type getModelProperty
189  (
190  const word& entryName,
191  const Type& defaultValue = pTraits<Type>::zero
192  ) const;
193 
194  //- Add generic property to the sub-model
195  template<class Type>
196  void setModelProperty(const word& entryName, const Type& value);
197 
198 
199  // I-O
200 
201  //- Write
202  virtual void write(Ostream& os) const;
203 };
204 
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 } // End namespace Foam
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #ifdef NoRepository
213 # include "subModelBaseTemplates.C"
214 #endif
215 
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
217 
218 #endif
219 
220 // ************************************************************************* //
Base class for generic sub-models requiring to be read from dictionary. Provides a mechanism to read ...
Definition: subModelBase.H:51
const word modelName_
Name of the sub-model.
Definition: subModelBase.H:64
virtual bool active() const
Return the model &#39;active&#39; status - default active = true.
Definition: subModelBase.C:154
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:122
void setBaseProperty(const word &entryName, const Type &value)
Add generic property to the base model.
virtual void write(Ostream &os) const
Write.
Definition: subModelBase.C:170
A class for handling words, derived from string.
Definition: word.H:59
const dictionary coeffDict_
Coefficients dictionary.
Definition: subModelBase.H:79
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:104
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
void getModelProperty(const word &entryName, Type &value) const
Retrieve generic property from the sub-model.
const word baseName_
Name of the sub-model base class.
Definition: subModelBase.H:73
Namespace for OpenFOAM.
const word modelType_
Type of the sub-model.
Definition: subModelBase.H:76
virtual bool outputTime() const
Flag to indicate when to write a property.
Definition: subModelBase.C:164
subModelBase(dictionary &properties)
Construct null.
Definition: subModelBase.C:38
virtual bool defaultCoeffs(const bool printMsg) const
Returns true if defaultCoeffs is true and outputs on printMsg.
Definition: subModelBase.C:140
const word & baseName() const
Return const access to the base name of the sub-model.
Definition: subModelBase.C:116
void setModelProperty(const word &entryName, const Type &value)
Add generic property to the sub-model.
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:110
const dictionary & properties() const
Return const access to the properties dictionary.
Definition: subModelBase.C:134
const dictionary dict_
Copy of dictionary used during construction.
Definition: subModelBase.H:70
bool inLine() const
Flag to indicate whether data is/was read in-line.
dictionary & properties_
Reference to properties dictionary e.g. for restart.
Definition: subModelBase.H:67
Traits class for primitives.
Definition: pTraits.H:50
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:53
virtual ~subModelBase()
Destructor.
Definition: subModelBase.C:98
Type getBaseProperty(const word &entryName, const Type &defaultValue=pTraits< Type >::zero) const
Retrieve generic property from the base model.
virtual void cacheFields(const bool store)
Cache dependant sub-model fields.
Definition: subModelBase.C:160