subModelBase.C
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-2020 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
27\*---------------------------------------------------------------------------*/
28
29#include "subModelBase.H"
30
31// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
32
33bool Foam::subModelBase::subModelBase::inLine() const
34{
35 return (modelName_ != word::null);
36}
37
38
39// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40
42:
43 modelName_(),
44 properties_(properties),
45 dict_(),
46 baseName_(),
47 modelType_(),
48 coeffDict_()
49{}
50
51
53(
54 dictionary& properties,
55 const dictionary& dict,
56 const word& baseName,
57 const word& modelType,
58 const word& dictExt
59)
60:
61 modelName_(),
62 properties_(properties),
63 dict_(dict),
64 baseName_(baseName),
65 modelType_(modelType),
66 coeffDict_(dict.subDict(modelType + dictExt))
67{}
68
69
71(
72 const word& modelName,
73 dictionary& properties,
74 const dictionary& dict,
75 const word& baseName,
76 const word& modelType
77)
78:
79 modelName_(modelName),
80 properties_(properties),
81 dict_(dict),
82 baseName_(baseName),
83 modelType_(modelType),
84 coeffDict_(dict)
85{}
86
87
89:
90 modelName_(smb.modelName_),
91 properties_(smb.properties_),
92 dict_(smb.dict_),
93 baseName_(smb.baseName_),
94 modelType_(smb.modelType_),
95 coeffDict_(smb.coeffDict_)
96{}
97
98
99// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
100
102{}
103
104
105// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106
108{
109 return modelName_;
110}
111
112
114{
115 return dict_;
116}
117
118
120{
121 return baseName_;
122}
123
124
126{
127 return modelType_;
128}
129
130
132{
133 return coeffDict_;
134}
135
136
138{
139 return properties_;
140}
141
142
143bool Foam::subModelBase::defaultCoeffs(const bool printMsg) const
144{
145 bool def = coeffDict_.getOrDefault("defaultCoeffs", false);
146 if (printMsg && def)
147 {
149 Info<< indent << "Employing default coefficients" << endl;
151 }
152
153 return def;
154}
155
156
158{
159 return true;
160}
161
162
164{}
165
166
168{
169 return active();
170}
171
172
174{
175 if (modelName_ != word::null)
176 {
177 return modelName_;
178 }
179
180 return baseName_;
181}
182
183
185(
186 const word& entryName,
188) const
189{
190 if (properties_.found(baseName_))
191 {
192 const dictionary& baseDict = properties_.subDict(baseName_);
193
194 if (inLine() && baseDict.found(modelName_))
195 {
196 const dictionary& modelDict = baseDict.subDict(modelName_);
197 dict = modelDict.subOrEmptyDict(entryName);
198 return true;
199 }
200 else if (baseDict.found(modelType_))
201 {
202 const dictionary& modelDict = baseDict.subDict(modelType_);
203 dict = modelDict.subOrEmptyDict(entryName);
204 return true;
205 }
206 }
207
208 return false;
209}
210
211
213{
214 os << coeffDict_;
215}
216
217
218// ************************************************************************* //
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
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Definition: dictionary.C:540
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
A class for handling file names.
Definition: fileName.H:76
virtual bool write()
Write the output fields.
Base class for generic sub-models requiring to be read from dictionary. Provides a mechanism to read ...
Definition: subModelBase.H:55
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
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
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 & 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
virtual bool writeTime() const
Flag to indicate when to write a property.
Definition: subModelBase.C:167
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:349
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:356
dictionary dict