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-2026 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  );
99 
100  //- Construct from components with name
102  (
103  const word& modelName,
105  const dictionary& dict,
106  const word& baseName,
107  const word& modelType
108  );
109 
110  //- Copy constructor
111  subModelBase(const subModelBase& smb);
112 
113 
114  //- Destructor
115  virtual ~subModelBase();
116 
117 
118  // Member Functions
119 
120  // Access
121 
122  //- Return const access to the name of the sub-model
123  const word& modelName() const;
124 
125  //- Return const access to the cloud dictionary
126  const dictionary& dict() const;
127 
128  //- Return const access to the base name of the sub-model
129  const word& baseName() const;
130 
131  //- Return const access to the sub-model type
132  const word& modelType() const;
133 
134  //- Return const access to the coefficients dictionary
135  const dictionary& typeDict() const;
136 
137  //- Return const access to the properties dictionary
138  const dictionary& properties() const;
139 
140  //- Returns true if defaultCoeffs is true and outputs on printMsg
141  virtual bool defaultCoeffs(const bool printMsg) const;
142 
143  //- Cache dependent sub-model fields
144  virtual void cacheFields(const bool store);
145 
146  //- Flag to indicate when to write a property
147  virtual bool writeTime() const = 0;
148 
149 
150  // Edit
151 
152  // Base properties
153 
154  //- Retrieve generic property from the base model
155  template<class Type>
156  Type getBaseProperty
157  (
158  const word& entryName,
159  const Type& defaultValue = pTraits<Type>::zero
160  ) const;
161 
162  //- Retrieve generic property from the base model
163  template<class Type>
164  void getBaseProperty(const word& entryName, Type& value) const;
165 
166  //- Add generic property to the base model
167  template<class Type>
168  void setBaseProperty(const word& entryName, const Type& value);
169 
170 
171  // Model properties
172 
173  //- Retrieve generic property from the sub-model
174  template<class Type>
175  void getModelProperty(const word& entryName, Type& value) const;
176 
177  //- Retrieve generic property from the sub-model
178  template<class Type>
179  Type getModelProperty
180  (
181  const word& entryName,
182  const Type& defaultValue = pTraits<Type>::zero
183  ) const;
184 
185  //- Add generic property to the sub-model
186  template<class Type>
187  void setModelProperty(const word& entryName, const Type& value);
188 
189 
190  // I-O
191 
192  //- Write
193  virtual void write(Ostream& os) const;
194 
195 
196  // Member Operators
197 
198  //- Disallow default bitwise assignment
199  void operator=(const subModelBase&) = delete;
200 };
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 } // End namespace Foam
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 #ifdef NoRepository
210  #include "subModelBaseTemplates.C"
211 #endif
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 #endif
216 
217 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Traits class for primitives.
Definition: pTraits.H:53
Base class for generic sub-models requiring to be read from dictionary. Provides a mechanism to read ...
Definition: subModelBase.H:52
const word modelType_
Type of the sub-model.
Definition: subModelBase.H:71
void operator=(const subModelBase &)=delete
Disallow default bitwise assignment.
const word modelName_
Name of the sub-model.
Definition: subModelBase.H:59
virtual ~subModelBase()
Destructor.
Definition: subModelBase.C:97
const word & baseName() const
Return const access to the base name of the sub-model.
Definition: subModelBase.C:115
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 dependent sub-model fields.
Definition: subModelBase.C:153
bool inLine() const
Flag to indicate whether data is/was read in-line.
void getModelProperty(const word &entryName, Type &value) const
Retrieve generic property from the sub-model.
virtual void write(Ostream &os) const
Write.
Definition: subModelBase.C:157
const dictionary & typeDict() const
Return const access to the coefficients dictionary.
Definition: subModelBase.C:127
const dictionary & properties() const
Return const access to the properties dictionary.
Definition: subModelBase.C:133
const dictionary coeffDict_
Coefficients dictionary.
Definition: subModelBase.H:74
const word baseName_
Name of the sub-model base class.
Definition: subModelBase.H:68
const dictionary dict_
Copy of dictionary used during construction.
Definition: subModelBase.H:65
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:109
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:103
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:121
virtual bool writeTime() const =0
Flag to indicate when to write a property.
virtual bool defaultCoeffs(const bool printMsg) const
Returns true if defaultCoeffs is true and outputs on printMsg.
Definition: subModelBase.C:139
subModelBase(dictionary &properties)
Construct null.
Definition: subModelBase.C:38
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:62
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:63
Namespace for OpenFOAM.