schemesLookup.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-2015 OpenFOAM Foundation
9  Copyright (C) 2019-2021 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 "schemesLookup.H"
30 #include "Switch.H"
31 #include "Time.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
36 
37 
38 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
39 
40 void Foam::schemesLookup::clear()
41 {
42  ddtSchemes_.clear();
43  d2dt2Schemes_.clear();
44  interpSchemes_.clear();
45  divSchemes_.clear(); // optional
46  gradSchemes_.clear(); // optional
47  lnGradSchemes_.clear();
48  snGradSchemes_.clear();
49  laplacianSchemes_.clear(); // optional
50 
51  // Do not clear fluxRequired settings
52 }
53 
54 
55 void Foam::schemesLookup::checkSteady()
56 {
57  ITstream& is = ddtSchemes_.fallback();
58 
59  word schemeName;
60  if (is.peek().isWord())
61  {
62  is >> schemeName;
63  }
64 
65  steady_ =
66  (
67  schemeName == "steady"
68  || schemeName == "steadyState"
69  );
70 }
71 
72 
73 void Foam::schemesLookup::read(const dictionary& dict)
74 {
75  ddtSchemes_.populate(dict, "none");
76  d2dt2Schemes_.populate(dict, "none");
77  interpSchemes_.populate(dict, "linear");
78  divSchemes_.populate(dict, "", true); // Mandatory entry
79  gradSchemes_.populate(dict, "", true); // Mandatory entry
80  lnGradSchemes_.populate(dict, "corrected"); // (finiteArea)
81  snGradSchemes_.populate(dict, "corrected"); // (finiteVolume)
82  laplacianSchemes_.populate(dict, "", true); // Mandatory entry
83 
84  const dictionary* fluxDictPtr = dict.findDict("fluxRequired");
85  if (fluxDictPtr)
86  {
87  fluxRequired_.merge(*fluxDictPtr);
88 
89  if (fluxRequired_.found("default"))
90  {
91  Switch sw(fluxRequired_.lookup("default").peek());
92 
93  if (sw.good() && sw.type() != Switch::NONE)
94  {
95  fluxRequiredDefault_ = bool(sw);
96  }
97  }
98  }
99 
100  checkSteady();
101 }
102 
103 
104 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
105 
106 Foam::schemesLookup::schemesLookup
107 (
108  const objectRegistry& obr,
109  const word& dictName,
110  const dictionary* fallback
111 )
112 :
114  (
115  IOobject
116  (
117  dictName,
118  obr.time().system(),
119  obr,
120  (
124  : obr.readOpt()
125  ),
127  ),
128  fallback
129  ),
130 
131  // Named, but empty dictionaries and default schemes
132 
133  ddtSchemes_("ddtSchemes", objectPath()),
134  d2dt2Schemes_("d2dt2Schemes", objectPath()),
135  interpSchemes_("interpolationSchemes", objectPath()),
136  divSchemes_("divSchemes", objectPath()),
137  gradSchemes_("gradSchemes", objectPath()),
138  lnGradSchemes_("lnGradSchemes", objectPath()),
139  snGradSchemes_("snGradSchemes", objectPath()),
140  laplacianSchemes_("laplacianSchemes", objectPath()),
141 
142  fluxRequired_(objectPath() + ".fluxRequired"),
143  fluxRequiredDefault_(false),
144  steady_(false)
145 {
146  if
147  (
148  readOpt() == IOobject::MUST_READ
149  || readOpt() == IOobject::MUST_READ_IF_MODIFIED
150  || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
151  )
152  {
153  read(schemesDict());
154  }
155 }
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
161 {
162  if (regIOobject::read())
163  {
164  clear(); // Clear current settings except fluxRequired
165 
166  read(schemesDict());
167 
168  return true;
169  }
170 
171  return false;
172 }
173 
174 
176 {
177  if (found("select"))
178  {
179  return subDict(word(lookup("select")));
180  }
181  return *this;
182 }
183 
184 
186 {
187  DebugInfo<< "Lookup ddtScheme for " << name << endl;
188  return ddtSchemes_.lookup(name);
189 }
190 
191 
193 {
194  DebugInfo<< "Lookup d2dt2Scheme for " << name << endl;
195  return d2dt2Schemes_.lookup(name);
196 }
197 
198 
200 {
201  DebugInfo<< "Lookup interpolationScheme for " << name << endl;
202  return interpSchemes_.lookup(name);
203 }
204 
205 
207 {
208  DebugInfo<< "Lookup divScheme for " << name << endl;
209  return divSchemes_.lookup(name);
210 }
211 
212 
214 {
215  DebugInfo<< "Lookup gradScheme for " << name << endl;
216  return gradSchemes_.lookup(name);
217 }
218 
219 
221 {
222  DebugInfo<< "Lookup lnGradScheme for " << name << endl;
223  return lnGradSchemes_.lookup(name);
224 }
225 
226 
228 {
229  DebugInfo<< "Lookup snGradScheme for " << name << endl;
230  return snGradSchemes_.lookup(name);
231 }
232 
233 
235 {
236  DebugInfo<< "Lookup laplacianScheme for " << name << endl;
237  return laplacianSchemes_.lookup(name);
238 }
239 
240 
242 {
243  DebugInfo<< "Setting fluxRequired for " << name << endl;
244  fluxRequired_.add(name, true, true);
245 }
246 
247 
249 {
250  DebugInfo<< "Lookup fluxRequired for " << name << endl;
251  return (fluxRequired_.found(name) || fluxRequiredDefault_);
252 }
253 
254 
256 {
257  ddtSchemes_.writeEntryOptional(os);
258  d2dt2Schemes_.writeEntryOptional(os);
259  interpSchemes_.writeEntryOptional(os);
260  divSchemes_.writeEntry(os); // Mandatory entry
261  gradSchemes_.writeEntry(os); // Mandatory entry
262  lnGradSchemes_.writeEntryOptional(os); // (finiteArea)
263  snGradSchemes_.writeEntryOptional(os); // (finiteVolume)
264  laplacianSchemes_.writeEntry(os); // Mandatory entry
265 
266  if (!fluxRequired_.empty())
267  {
268  fluxRequired_.writeEntry(os);
269  }
270 }
271 
272 
273 // ************************************************************************* //
Foam::dictionary::findDict
dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary pointer if present.
Definition: dictionaryI.H:127
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::debug::debugSwitch
int debugSwitch(const char *name, const int deflt=0)
Lookup debug switch or add default value.
Definition: debug.C:225
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
dictName
const word dictName("faMeshDefinition")
Foam::schemesLookup::gradScheme
ITstream & gradScheme(const word &name) const
Get grad scheme for given name, or default.
Definition: schemesLookup.C:213
Foam::regIOobject::read
virtual bool read()
Read object.
Definition: regIOobjectRead.C:191
Foam::schemesLookup::setFluxRequired
void setFluxRequired(const word &name) const
Get flux-required for given name, or default.
Definition: schemesLookup.C:241
Foam::schemesLookup::schemesDict
const dictionary & schemesDict() const
The current schemes dictionary, respects the "select" keyword.
Definition: schemesLookup.C:175
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
schemesLookup.H
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::schemesLookup::laplacianScheme
ITstream & laplacianScheme(const word &name) const
Get laplacian scheme for given name, or default.
Definition: schemesLookup.C:234
Foam::dictionary::merge
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
Definition: dictionary.C:812
Foam::schemesLookup::fluxRequired
const dictionary & fluxRequired() const noexcept
Access to flux required dictionary.
Definition: schemesLookup.H:276
Foam::ITstream
An input stream of tokens.
Definition: ITstream.H:52
Foam::schemesLookup::interpolationScheme
ITstream & interpolationScheme(const word &name) const
Get interpolation scheme for given name, or default.
Definition: schemesLookup.C:199
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:187
Switch.H
Foam::radiation::lookup
Lookup type of boundary radiation properties.
Definition: lookup.H:63
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::schemesLookup::snGradScheme
ITstream & snGradScheme(const word &name) const
Get (finiteVolume) snGrad scheme for given name, or default.
Definition: schemesLookup.C:227
Foam::schemesLookup::divScheme
ITstream & divScheme(const word &name) const
Get div scheme for given name, or default.
Definition: schemesLookup.C:206
Foam::IOobject::readOpt
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
found
bool found
Definition: TABSMDCalcMethod2.H:32
Time.H
Foam::TimePaths::system
const word & system() const
Return system name.
Definition: TimePathsI.H:102
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
clear
patchWriters clear()
Foam::schemesLookup::ddtScheme
ITstream & ddtScheme(const word &name) const
Get ddt scheme for given name, or default.
Definition: schemesLookup.C:185
bool
bool
Definition: EEqn.H:20
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
Foam::Switch::NONE
Definition: Switch.H:93
Foam::schemesLookup::debug
static int debug
Debug switch.
Definition: schemesLookup.H:158
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::schemesLookup::read
bool read()
Read schemes from IOdictionary, respects the "select" keyword.
Definition: schemesLookup.C:160
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::schemesLookup::writeDicts
void writeDicts(Ostream &os) const
Write dictionary (possibly modified) settings.
Definition: schemesLookup.C:255
Foam::schemesLookup::d2dt2Scheme
ITstream & d2dt2Scheme(const word &name) const
Get d2dt2 scheme for given name, or default.
Definition: schemesLookup.C:192
Foam::objectRegistry::time
const Time & time() const noexcept
Return time registry.
Definition: objectRegistry.H:178
Foam::schemesLookup::lnGradScheme
ITstream & lnGradScheme(const word &name) const
Get (finiteArea) lnGrad scheme for given name, or default.
Definition: schemesLookup.C:220
Foam::IOobject::MUST_READ
Definition: IOobject.H:185