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-2023 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 const Foam::dictionary& Foam::schemesLookup::selectedDict() const
106 {
107  word select;
108 
109  if (readIfPresent("select", select, keyType::LITERAL))
110  {
111  return subDict(select);
112  }
113 
114  return *this;
115 }
116 
117 
118 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
119 
120 Foam::schemesLookup::schemesLookup
121 (
122  const objectRegistry& obr,
124  const word& dictName,
125  const dictionary* fallback
126 )
127 :
129  (
130  IOobject
131  (
132  dictName,
133  obr.time().system(),
134  obr,
135  rOpt,
136  IOobject::NO_WRITE
137  ),
138  fallback
139  ),
140 
141  // Named, but empty dictionaries and default schemes
142 
143  ddtSchemes_("ddtSchemes", objectPath()),
144  d2dt2Schemes_("d2dt2Schemes", objectPath()),
145  interpSchemes_("interpolationSchemes", objectPath()),
146  divSchemes_("divSchemes", objectPath()),
147  gradSchemes_("gradSchemes", objectPath()),
148  lnGradSchemes_("lnGradSchemes", objectPath()),
149  snGradSchemes_("snGradSchemes", objectPath()),
150  laplacianSchemes_("laplacianSchemes", objectPath()),
151 
152  fluxRequired_(objectPath() / "fluxRequired"),
153  fluxRequiredDefault_(false),
154  steady_(false)
155 {
156  // Treat as MUST_READ_IF_MODIFIED whenever possible
157  if
158  (
160  || (isReadOptional() && headerOk())
161  )
162  {
164  addWatch();
165  }
166 
168  {
169  read(selectedDict());
170  }
171 }
172 
173 
174 Foam::schemesLookup::schemesLookup
175 (
176  const objectRegistry& obr,
177  const word& dictName,
178  const dictionary* fallback
179 )
180 :
181  schemesLookup(obr, obr.readOpt(), dictName, fallback)
182 {}
183 
184 
185 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
186 
188 {
189  if (regIOobject::read())
190  {
191  clear(); // Clear current settings except fluxRequired
192 
193  read(selectedDict());
194 
195  return true;
196  }
197 
198  return false;
199 }
200 
201 
203 {
204  DebugInfo<< "Lookup ddt scheme for " << name << endl;
205  return ddtSchemes_.lookup(name);
206 }
207 
208 
210 {
211  DebugInfo<< "Lookup d2dt2 scheme for " << name << endl;
212  return d2dt2Schemes_.lookup(name);
213 }
214 
215 
217 {
218  DebugInfo<< "Lookup interpolation scheme for " << name << endl;
219  return interpSchemes_.lookup(name);
220 }
221 
222 
224 {
225  DebugInfo<< "Lookup div scheme for " << name << endl;
226  return divSchemes_.lookup(name);
227 }
228 
229 
231 {
232  DebugInfo<< "Lookup grad scheme for " << name << endl;
233  return gradSchemes_.lookup(name);
234 }
235 
236 
238 {
239  DebugInfo<< "Lookup lnGrad scheme for " << name << endl;
240  return lnGradSchemes_.lookup(name);
241 }
242 
243 
245 {
246  DebugInfo<< "Lookup snGrad scheme for " << name << endl;
247  return snGradSchemes_.lookup(name);
248 }
249 
250 
252 {
253  DebugInfo<< "Lookup laplacian scheme for " << name << endl;
254  return laplacianSchemes_.lookup(name);
255 }
256 
257 
259 {
260  DebugInfo<< "Setting fluxRequired for " << name << endl;
261  fluxRequired_.add(name, true, true);
262 }
263 
264 
266 {
267  DebugInfo<< "Lookup fluxRequired for " << name << endl;
268  return (fluxRequired_.found(name) || fluxRequiredDefault_);
269 }
270 
273 {
274  return selectedDict();
275 }
276 
277 
279 {
280  ddtSchemes_.writeEntryOptional(os);
281  d2dt2Schemes_.writeEntryOptional(os);
282  interpSchemes_.writeEntryOptional(os);
283  divSchemes_.writeEntry(os); // Mandatory entry
284  gradSchemes_.writeEntry(os); // Mandatory entry
285  lnGradSchemes_.writeEntryOptional(os); // (finiteArea)
286  snGradSchemes_.writeEntryOptional(os); // (finiteVolume)
287  laplacianSchemes_.writeEntry(os); // Mandatory entry
288 
289  if (!fluxRequired_.empty())
290  {
291  fluxRequired_.writeEntry(os);
292  }
293 }
294 
295 
296 // ************************************************************************* //
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:129
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition: BitOps.C:134
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:531
bool headerOk()
Read and check header info. Does not check the headerClassName.
Definition: regIOobject.C:505
ITstream & d2dt2Scheme(const word &name) const
Get d2dt2 scheme for given name, or default.
const dictionary & fluxRequired() const noexcept
Access flux-required dictionary.
bool isReadOptional() const noexcept
True if (LAZY_READ) bits are set [same as READ_IF_PRESENT].
void setFluxRequired(const word &name) const
Set flux-required for given name (mutable)
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:127
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:799
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
ITstream & gradScheme(const word &name) const
Get grad scheme for given name, or default.
const dictionary & schemesDict() const
The entire dictionary or the optional "select" sub-dictionary.
patchWriters clear()
String literal.
Definition: keyType.H:82
#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:56
Selector class for finite area/finite volume differencing schemes.
OBJstream os(runTime.globalPath()/outputName)
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:277
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.
meshDefDict readIfPresent("polyMeshPatches", polyPatchNames)
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition: POSIX.C:1702
Registry of regIOobjects.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
static int debug
Debug switch.
An input stream of tokens.
Definition: ITstream.H:52
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:124
readOption
Enumeration defining read preferences.