Loading...
Searching...
No Matches
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
35 return (!modelName_.empty());
36}
37
38
39// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40
42:
43 modelName_(),
44 properties_(properties),
45 dict_(),
47 modelType_(),
48 coeffDict_(),
49 log(properties.getOrDefault<bool>("log", true))
50{}
51
52
54(
55 dictionary& properties,
56 const dictionary& dict,
57 const word& baseName,
58 const word& modelType,
59 const word& dictExt
60)
61:
62 modelName_(),
63 properties_(properties),
64 dict_(dict),
67 coeffDict_(dict.subDict(modelType + dictExt)),
68 log(coeffDict_.getOrDefault<bool>("log", true))
69{}
70
71
73(
74 const word& modelName,
75 dictionary& properties,
76 const dictionary& dict,
77 const word& baseName,
78 const word& modelType
79)
80:
81 modelName_(modelName),
82 properties_(properties),
83 dict_(dict),
87 log(coeffDict_.getOrDefault<bool>("log", true))
88{}
89
90
92:
93 modelName_(smb.modelName_),
94 properties_(smb.properties_),
95 dict_(smb.dict_),
96 baseName_(smb.baseName_),
97 modelType_(smb.modelType_),
99 log(coeffDict_.getOrDefault<bool>("log", true))
100{}
101
102
103// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106{
107 return modelName_;
108}
109
112{
113 return dict_;
114}
115
118{
119 return baseName_;
120}
121
124{
125 return modelType_;
126}
127
132}
133
136{
137 return properties_;
138}
139
140
141bool Foam::subModelBase::defaultCoeffs(const bool printMsg) const
142{
143 bool def = coeffDict_.getOrDefault("defaultCoeffs", false);
144 if (printMsg && def)
145 {
146 // Note: not using Log<< for output
148 Info<< indent << "Employing default coefficients" << endl;
150 }
151
152 return def;
153}
154
157{
158 return true;
160
161
162void Foam::subModelBase::cacheFields(const bool)
163{}
164
167{
168 return active();
169}
170
171
173{
174 if (!modelName_.empty())
175 {
177 }
178
179 return baseName_;
180}
181
182
184(
185 const word& entryName,
187) const
188{
189 if (properties_.found(baseName_))
190 {
191 const dictionary& baseDict = properties_.subDict(baseName_);
192
193 if (inLine() && baseDict.found(modelName_))
194 {
195 const dictionary& modelDict = baseDict.subDict(modelName_);
196 dict = modelDict.subOrEmptyDict(entryName);
197 return true;
198 }
199 else if (baseDict.found(modelType_))
200 {
201 const dictionary& modelDict = baseDict.subDict(modelType_);
202 dict = modelDict.subOrEmptyDict(entryName);
203 return true;
205 }
206
207 return false;
208}
209
210
212{
213 os << coeffDict_;
214}
215
216
217// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Find and return a sub-dictionary as a copy, otherwise return an empty dictionary.
Definition dictionary.C:521
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition dictionary.C:441
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
A class for handling file names.
Definition fileName.H:75
Base class for generic sub-models requiring to be read from dictionary. Provides a mechanism to read ...
const word modelType_
Type of the sub-model.
const word modelName_
Name of the sub-model.
const word & baseName() const
Return const access to the base name of the sub-model.
virtual void cacheFields(const bool store)
Cache dependent sub-model fields.
bool inLine() const
Flag to indicate whether data is/was read in-line.
virtual fileName localPath() const
Output directory.
virtual void write(Ostream &os) const
Write.
const dictionary & coeffDict() const
Return const access to the coefficients dictionary.
const dictionary & properties() const
Return const access to the properties dictionary.
bool getModelDict(const word &entryName, dictionary &dict) const
Retrieve dictionary, return true if set.
const dictionary coeffDict_
Coefficients dictionary.
const word baseName_
Name of the sub-model base class.
const dictionary dict_
Copy of dictionary used during construction.
const dictionary & dict() const
Return const access to the cloud dictionary.
const word & modelName() const
Return const access to the name of the sub-model.
const word & modelType() const
Return const access to the sub-model type.
virtual bool active() const
Return the model 'active' status - default active = true.
virtual bool defaultCoeffs(const bool printMsg) const
Returns true if defaultCoeffs is true and outputs on printMsg.
bool log
Flag to write log into Info.
subModelBase(dictionary &properties)
Construct null.
dictionary & properties_
Reference to properties dictionary e.g. for restart.
virtual bool writeTime() const
Flag to indicate when to write a property.
A class for handling words, derived from Foam::string.
Definition word.H:66
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:490
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
Ostream & indent(Ostream &os)
Indent stream.
Definition Ostream.H:481
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition Ostream.H:499
dictionary dict