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-2024 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  IOobjectOption::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 READ_MODIFIED whenever possible
157  if
158  (
160  || (isReadOptional() && headerOk())
161  )
162  {
164  addWatch();
165  }
166 
167  // Update: from values read or copied in
168  if
169  (
171  || !dictionary::empty()
172  )
173  {
174  read(selectedDict());
175  }
176 }
177 
178 
179 Foam::schemesLookup::schemesLookup
180 (
181  const objectRegistry& obr,
182  const word& dictName,
183  const dictionary* fallback
184 )
185 :
186  schemesLookup(obr, obr.readOpt(), dictName, fallback)
187 {}
188 
189 
190 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
191 
193 {
194  if (regIOobject::read())
195  {
196  clear(); // Clear current settings except fluxRequired
197 
198  read(selectedDict());
199 
200  return true;
201  }
202 
203  return false;
204 }
205 
206 
208 {
209  DebugInfo<< "Lookup ddt scheme for " << name << endl;
210  return ddtSchemes_.lookup(name);
211 }
212 
213 
215 {
216  DebugInfo<< "Lookup d2dt2 scheme for " << name << endl;
217  return d2dt2Schemes_.lookup(name);
218 }
219 
220 
222 {
223  DebugInfo<< "Lookup interpolation scheme for " << name << endl;
224  return interpSchemes_.lookup(name);
225 }
226 
227 
229 {
230  DebugInfo<< "Lookup div scheme for " << name << endl;
231  return divSchemes_.lookup(name);
232 }
233 
234 
236 {
237  DebugInfo<< "Lookup grad scheme for " << name << endl;
238  return gradSchemes_.lookup(name);
239 }
240 
241 
243 {
244  DebugInfo<< "Lookup lnGrad scheme for " << name << endl;
245  return lnGradSchemes_.lookup(name);
246 }
247 
248 
250 {
251  DebugInfo<< "Lookup snGrad scheme for " << name << endl;
252  return snGradSchemes_.lookup(name);
253 }
254 
255 
257 {
258  DebugInfo<< "Lookup laplacian scheme for " << name << endl;
259  return laplacianSchemes_.lookup(name);
260 }
261 
262 
264 {
265  DebugInfo<< "Setting fluxRequired for " << name << endl;
266  fluxRequired_.add(name, true, true);
267 }
268 
269 
271 {
272  DebugInfo<< "Lookup fluxRequired for " << name << endl;
273  return (fluxRequired_.found(name) || fluxRequiredDefault_);
274 }
275 
278 {
279  return selectedDict();
280 }
281 
282 
284 {
285  ddtSchemes_.writeEntryOptional(os);
286  d2dt2Schemes_.writeEntryOptional(os);
287  interpSchemes_.writeEntryOptional(os);
288  divSchemes_.writeEntry(os); // Mandatory entry
289  gradSchemes_.writeEntry(os); // Mandatory entry
290  lnGradSchemes_.writeEntryOptional(os); // (finiteArea)
291  snGradSchemes_.writeEntryOptional(os); // (finiteVolume)
292  laplacianSchemes_.writeEntry(os); // Mandatory entry
293 
294  if (!fluxRequired_.empty())
295  {
296  fluxRequired_.writeEntry(os);
297  }
298 }
299 
300 
301 // ************************************************************************* //
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.
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.
surface1 clear()
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
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:180
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 it is a dictionary) otherwise return nullptr...
Definition: dictionaryI.H:124
readOption
Enumeration defining read preferences.