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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
28 
29 #include "subModelBase.H"
30 
31 // * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
32 
33 bool Foam::subModelBase::subModelBase::inLine() const
34 {
35  return (!modelName_.empty());
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 :
43  modelName_(),
44  properties_(properties),
45  dict_(),
46  baseName_(),
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),
65  baseName_(baseName),
66  modelType_(modelType),
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),
84  baseName_(baseName),
85  modelType_(modelType),
86  coeffDict_(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_),
98  coeffDict_(smb.coeffDict_),
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 
130 {
131  return coeffDict_;
132 }
133 
136 {
137  return properties_;
138 }
139 
140 
141 bool 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
147  Info<< incrIndent;
148  Info<< indent << "Employing default coefficients" << endl;
150  }
151 
152  return def;
153 }
154 
156 bool Foam::subModelBase::active() const
157 {
158  return true;
159 }
160 
161 
162 void Foam::subModelBase::cacheFields(const bool)
163 {}
164 
167 {
168  return active();
169 }
170 
171 
173 {
174  if (!modelName_.empty())
175  {
176  return modelName_;
177  }
178 
179  return baseName_;
180 }
181 
182 
184 (
185  const word& entryName,
186  dictionary& dict
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;
204  }
205  }
206 
207  return false;
208 }
209 
210 
211 void Foam::subModelBase::write(Ostream& os) const
212 {
213  os << coeffDict_;
214 }
215 
216 
217 // ************************************************************************* //
virtual fileName localPath() const
Output directory.
Definition: subModelBase.C:165
const dictionary & properties() const
Return const access to the properties dictionary.
Definition: subModelBase.C:128
dictionary dict
A class for handling file names.
Definition: fileName.H:72
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:493
dimensionedScalar log(const dimensionedScalar &ds)
subModelBase(dictionary &properties)
Construct null.
Definition: subModelBase.C:34
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:98
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:104
virtual void write(Ostream &os) const
Write.
Definition: subModelBase.C:204
A class for handling words, derived from Foam::string.
Definition: word.H:63
bool getModelDict(const word &entryName, dictionary &dict) const
Retrieve dictionary, return true if set.
Definition: subModelBase.C:177
const dictionary & coeffDict() const
Return const access to the coefficients dictionary.
Definition: subModelBase.C:122
const word & modelType() const
Return const access to the sub-model type.
Definition: subModelBase.C:116
virtual void cacheFields(const bool store)
Cache dependent sub-model fields.
Definition: subModelBase.C:155
OBJstream os(runTime.globalPath()/outputName)
virtual bool defaultCoeffs(const bool printMsg) const
Returns true if defaultCoeffs is true and outputs on printMsg.
Definition: subModelBase.C:134
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:511
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
Base class for generic sub-models requiring to be read from dictionary. Provides a mechanism to read ...
Definition: subModelBase.H:50
virtual bool writeTime() const
Flag to indicate when to write a property.
Definition: subModelBase.C:159
const word & baseName() const
Return const access to the base name of the sub-model.
Definition: subModelBase.C:110
messageStream Info
Information stream (stdout output on master, null elsewhere)
const word modelName_
Name of the sub-model.
Definition: subModelBase.H:67
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:502
virtual bool active() const
Return the model &#39;active&#39; status - default active = true.
Definition: subModelBase.C:149