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-2022 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 "schemesLookup.H"
30#include "Switch.H"
31#include "Time.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
36
37
38// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
39
40void 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
55void 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 // OR: steady_ = schemeName.starts_with("steady");
66 steady_ =
67 (
68 schemeName == "steady"
69 || schemeName == "steadyState"
70 );
71}
72
73
74void Foam::schemesLookup::read(const dictionary& dict)
75{
76 ddtSchemes_.populate(dict, "none");
77 d2dt2Schemes_.populate(dict, "none");
78 interpSchemes_.populate(dict, "linear");
79 divSchemes_.populate(dict, "", true); // Mandatory entry
80 gradSchemes_.populate(dict, "", true); // Mandatory entry
81 lnGradSchemes_.populate(dict, "corrected"); // (finiteArea)
82 snGradSchemes_.populate(dict, "corrected"); // (finiteVolume)
83 laplacianSchemes_.populate(dict, "", true); // Mandatory entry
84
85 const dictionary* fluxDictPtr = dict.findDict("fluxRequired");
86 if (fluxDictPtr)
87 {
88 fluxRequired_.merge(*fluxDictPtr);
89
90 if (fluxRequired_.found("default"))
91 {
92 Switch sw(fluxRequired_.lookup("default").peek());
93
94 if (sw.good() && sw.type() != Switch::NONE)
95 {
96 fluxRequiredDefault_ = bool(sw);
97 }
98 }
99 }
100
101 checkSteady();
102}
103
104
105// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106
108(
109 const objectRegistry& obr,
110 const IOobject::readOption rOpt,
111 const word& dictName,
112 const dictionary* fallback
113)
114:
116 (
118 (
119 dictName,
120 obr.time().system(),
121 obr,
122 rOpt,
123 IOobject::NO_WRITE
124 ),
125 fallback
126 ),
127
128 // Named, but empty dictionaries and default schemes
129
130 ddtSchemes_("ddtSchemes", objectPath()),
131 d2dt2Schemes_("d2dt2Schemes", objectPath()),
132 interpSchemes_("interpolationSchemes", objectPath()),
133 divSchemes_("divSchemes", objectPath()),
134 gradSchemes_("gradSchemes", objectPath()),
135 lnGradSchemes_("lnGradSchemes", objectPath()),
136 snGradSchemes_("snGradSchemes", objectPath()),
137 laplacianSchemes_("laplacianSchemes", objectPath()),
138
139 fluxRequired_(objectPath() + ".fluxRequired"),
140 fluxRequiredDefault_(false),
141 steady_(false)
142{
143 // Treat as MUST_READ_IF_MODIFIED whenever possible
144 if
145 (
148 )
149 {
151 addWatch();
152 }
153
155 {
156 read(schemesDict());
157 }
158}
159
160
162(
163 const objectRegistry& obr,
164 const word& dictName,
165 const dictionary* fallback
166)
167:
168 schemesLookup(obr, obr.readOpt(), dictName, fallback)
169{}
170
171
172// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
173
175{
176 if (regIOobject::read())
177 {
178 clear(); // Clear current settings except fluxRequired
179
180 read(schemesDict());
181
182 return true;
183 }
184
185 return false;
186}
187
188
190{
191 if (found("select"))
192 {
193 return subDict(word(lookup("select")));
194 }
195 return *this;
196}
197
198
200{
201 DebugInfo<< "Lookup ddtScheme for " << name << endl;
202 return ddtSchemes_.lookup(name);
203}
204
205
207{
208 DebugInfo<< "Lookup d2dt2Scheme for " << name << endl;
209 return d2dt2Schemes_.lookup(name);
210}
211
212
214{
215 DebugInfo<< "Lookup interpolationScheme for " << name << endl;
216 return interpSchemes_.lookup(name);
217}
218
219
221{
222 DebugInfo<< "Lookup divScheme for " << name << endl;
223 return divSchemes_.lookup(name);
224}
225
226
228{
229 DebugInfo<< "Lookup gradScheme for " << name << endl;
230 return gradSchemes_.lookup(name);
231}
232
233
235{
236 DebugInfo<< "Lookup lnGradScheme for " << name << endl;
237 return lnGradSchemes_.lookup(name);
238}
239
240
242{
243 DebugInfo<< "Lookup snGradScheme for " << name << endl;
244 return snGradSchemes_.lookup(name);
245}
246
247
249{
250 DebugInfo<< "Lookup laplacianScheme for " << name << endl;
251 return laplacianSchemes_.lookup(name);
252}
253
254
256{
257 DebugInfo<< "Setting fluxRequired for " << name << endl;
258 fluxRequired_.add(name, true, true);
259}
260
261
263{
264 DebugInfo<< "Lookup fluxRequired for " << name << endl;
265 return (fluxRequired_.found(name) || fluxRequiredDefault_);
266}
267
268
270{
271 ddtSchemes_.writeEntryOptional(os);
272 d2dt2Schemes_.writeEntryOptional(os);
273 interpSchemes_.writeEntryOptional(os);
274 divSchemes_.writeEntry(os); // Mandatory entry
275 gradSchemes_.writeEntry(os); // Mandatory entry
276 lnGradSchemes_.writeEntryOptional(os); // (finiteArea)
277 snGradSchemes_.writeEntryOptional(os); // (finiteVolume)
278 laplacianSchemes_.writeEntry(os); // Mandatory entry
279
280 if (!fluxRequired_.empty())
281 {
282 fluxRequired_.writeEntry(os);
283 }
284}
285
286
287// ************************************************************************* //
bool found
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
readOption
Enumeration defining the read options.
Definition: IOobject.H:177
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:180
An input stream of tokens.
Definition: ITstream.H:56
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 * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary pointer if present.
Definition: dictionaryI.H:127
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
Definition: dictionary.C:812
Abstract base class for finite area calculus div schemes.
Definition: faDivScheme.H:70
Abstract base class for finite area calculus gradient schemes.
Definition: faGradScheme.H:66
Abstract base class for finite area calculus laplacian schemes.
Abstract base class for lnGrad schemes.
Definition: lnGradScheme.H:65
Abstract base class for finite volume d2dt2 schemes.
Definition: d2dt2Scheme.H:69
Abstract base class for ddt schemes.
Definition: ddtScheme.H:87
tmp< multivariateSurfaceInterpolationScheme< Type > > interpolationScheme() const
Abstract base class for runtime selected snGrad surface normal gradient schemes.
Definition: snGradScheme.H:79
Registry of regIOobjects.
Lookup type of boundary radiation properties.
Definition: lookup.H:66
bool headerOk()
Read and check header info. Does not check the headerClassName.
Definition: regIOobject.C:438
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:267
virtual bool read()
Read object.
Selector class for finite area/finite volume differencing schemes.
Definition: schemesLookup.H:63
void setFluxRequired(const word &name) const
Get flux-required for given name, or default.
const dictionary & schemesDict() const
The current schemes dictionary, respects the "select" keyword.
void writeDicts(Ostream &os) const
Write dictionary (possibly modified) settings.
static int debug
Debug switch.
const dictionary & fluxRequired() const noexcept
Access to flux required dictionary.
bool read()
Read schemes from IOdictionary, respects the "select" keyword.
A class for handling words, derived from Foam::string.
Definition: word.H:68
bool
Definition: EEqn.H:20
patchWriters clear()
OBJstream os(runTime.globalPath()/outputName)
const word dictName("faMeshDefinition")
#define DebugInfo
Report an information message using Foam::Info.
int debugSwitch(const char *name, const int deflt=0)
Lookup debug switch or add default value.
Definition: debug.C:225
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition: MSwindows.C:1158
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
dictionary dict