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 -------------------------------------------------------------------------------
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  // OR: steady_ = schemeName.starts_with("steady");
66  steady_ =
67  (
68  schemeName == "steady"
69  || schemeName == "steadyState"
70  );
71 }
72 
73 
74 void 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 
107 Foam::schemesLookup::schemesLookup
108 (
109  const objectRegistry& obr,
111  const word& dictName,
112  const dictionary* fallback
113 )
114 :
116  (
117  IOobject
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  (
147  || (isReadOptional() && headerOk())
148  )
149  {
151  addWatch();
152  }
153 
155  {
156  read(schemesDict());
157  }
158 }
159 
160 
161 Foam::schemesLookup::schemesLookup
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 // ************************************************************************* //
dictionary dict
ITstream & ddtScheme(const word &name) const
Get ddt scheme for given name, or default.
readOption readOpt() const noexcept
Get the read option.
virtual bool read()
Read object.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
int debugSwitch(const char *name, const int deflt=0)
Lookup debug switch or add default value.
Definition: debug.C:222
const word dictName("faMeshDefinition")
void writeDicts(Ostream &os) const
Write dictionary (possibly modified) settings.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
bool headerOk()
Read and check header info. Does not check the headerClassName.
Definition: regIOobject.C:434
ITstream & d2dt2Scheme(const word &name) const
Get d2dt2 scheme for given name, or default.
const dictionary & fluxRequired() const noexcept
Access to flux required dictionary.
Lookup type of boundary radiation properties.
Definition: lookup.H:57
bool isReadOptional() const noexcept
True if (READ_IF_PRESENT) bits are set.
void setFluxRequired(const word &name) const
Get flux-required for given name, or default.
ITstream & interpolationScheme(const word &name) const
Get interpolation scheme for given name, or default.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:125
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
Definition: dictionary.C:811
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
A class for handling words, derived from Foam::string.
Definition: word.H:63
Reading required, file watched for runTime modification.
ITstream & gradScheme(const word &name) const
Get grad scheme for given name, or default.
const dictionary & schemesDict() const
The current schemes dictionary, respects the "select" keyword.
patchWriters clear()
#define DebugInfo
Report an information message using Foam::Info.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
Selector class for finite area/finite volume differencing schemes.
Definition: schemesLookup.H:56
OBJstream os(runTime.globalPath()/outputName)
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:263
ITstream & lnGradScheme(const word &name) const
Get (finiteArea) lnGrad scheme for given name, or default.
ITstream & laplacianScheme(const word &name) const
Get laplacian scheme for given name, or default.
ITstream & snGradScheme(const word &name) const
Get (finiteVolume) snGrad scheme for given name, or default.
ITstream & divScheme(const word &name) const
Get div scheme for given name, or default.
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition: POSIX.C:1655
Registry of regIOobjects.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
bool found
static int debug
Debug switch.
An input stream of tokens.
Definition: ITstream.H:48
bool read()
Read schemes from IOdictionary, respects the "select" keyword.
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and a sub-dictionary) otherwise return nullptr...
Definition: dictionaryI.H:120
readOption
Enumeration defining read preferences.