schemesLookup.H
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) 2020-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 Class
28  Foam::schemesLookup
29 
30 Description
31  Selector class for finite area/finite volume differencing schemes.
32 
33  The file will contain these types of entries:
34  \table
35  Name | Description | Type | Reqd | Default
36  ddtSchemes | ddt | dict | no | none
37  d2dt2Schemes | d2dt2 (currently only finite-area) | dict | no | none
38  interpolationSchemes | interpolation | dict | no | linear
39  divSchemes | div | dict | yes | -
40  gradSchemes | grad | dict | yes | -
41  lnGradSchemes | line-normal grad (finite-area) | dict | no | corrected
42  snGradSchemes | surface-normal grad | dict | no | corrected
43  laplacianSchemes | laplacian | dict | yes | -
44  fluxRequired | | dict | no | -
45  \endtable
46 
47  \par select
48  This is a rarely used feature to select between different groups of
49  settings within the file. If unspecified, the file contents are used
50  directly.
51 
52 Note
53  The schemes data are treated as \c READ_MODIFIED even if the
54  requested \p readOption is nominally MUST_READ or READ_IF_PRESENT.
55  This allows run-time modifications to behave as expected. <br>
56  The optional fallback dictionary content for constructors is used
57  when a file is missing or for a NO_READ, with a null pointer being
58  treated like an empty dictionary.
59 
60 SourceFiles
61  schemesLookup.C
62  schemesLookupDetail.C
63 
64 \*---------------------------------------------------------------------------*/
65 
66 #ifndef Foam_schemesLookup_H
67 #define Foam_schemesLookup_H
68 
69 #include "IOdictionary.H"
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 
73 namespace Foam
74 {
75 
76 /*---------------------------------------------------------------------------*\
77  Class schemesLookup Declaration
78 \*---------------------------------------------------------------------------*/
79 
80 class schemesLookup
81 :
82  public IOdictionary
83 {
84  // Private Class
85 
86  //- Lightweight grouping of scheme dictionary and default
87  struct lookupDetail
88  {
89  word name_;
90  dictionary dict_;
91  ITstream default_;
92 
93 
94  // Constructors
95 
96  //- Construct empty with given sub-dictionary name
97  lookupDetail
98  (
99  const word& dictName,
100  const fileName& parentDictPath
101  );
102 
103 
104  // Member Functions
105 
106  //- Clear dictionary and default scheme
107  void clear();
108 
109  //- Return the default scheme (if any)
110  ITstream& fallback() const;
111 
112  //- Lookup named scheme from dictionary, or return default
113  ITstream& lookup(const word& name) const;
114 
115  //- Populate dictionary and/or default
116  void populate
117  (
118  const dictionary& dict,
119  const word& defaultName,
120  const bool mandatory = false
121  );
122 
123  //- Write dictionary entry
124  void writeEntry(Ostream& os) const;
125 
126  //- Write dictionary entry if non-empty
127  void writeEntryOptional(Ostream& os) const;
128  };
129 
130 
131  // Private Data
132 
133  //- ddt
134  lookupDetail ddtSchemes_;
136  //- d2dt2
137  lookupDetail d2dt2Schemes_;
138 
139  //- interpolation
140  lookupDetail interpSchemes_;
141 
142  //- div
143  lookupDetail divSchemes_;
144 
145  //- grad
146  lookupDetail gradSchemes_;
147 
148  //- lnGrad (finiteArea)
149  lookupDetail lnGradSchemes_;
150 
151  //- snGrad (finiteVolume)
152  lookupDetail snGradSchemes_;
153 
154  //- laplacian
155  lookupDetail laplacianSchemes_;
156 
157  //- flux
158  mutable dictionary fluxRequired_;
159  bool fluxRequiredDefault_;
160 
161  //- True if default ddtScheme is steady-state
162  bool steady_;
163 
164 
165  // Private Member Functions
166 
167  //- Clear dictionaries and streams before reading
168  void clear();
169 
170  //- Check if default ddtScheme is steady-state
171  void checkSteady();
172 
173  //- Read settings from the dictionary
174  void read(const dictionary& dict);
175 
176  //- The entire dictionary or the optional "select" sub-dictionary.
177  const dictionary& selectedDict() const;
178 
179 
180  // Generated Methods
181 
182  //- No copy construct
183  schemesLookup(const schemesLookup&) = delete;
184 
185  //- No copy assignment
186  void operator=(const schemesLookup&) = delete;
187 
188 
189 public:
190 
191  //- Debug switch
192  static int debug;
193 
194 
195  // Constructors
196 
197  //- Construct for objectRegistry, readOption, (system) dictionary name.
199  (
200  const objectRegistry& obr,
202  const word& dictName,
203  const dictionary* fallback = nullptr
204  );
205 
206  //- Construct for objectRegistry, (system) dictionary name
207  //- using the readOption from the registry.
209  (
210  const objectRegistry& obr,
211  const word& dictName,
212  const dictionary* fallback = nullptr
213  );
214 
215 
216  // Member Functions
217 
218  //- True if default ddt scheme is steady-state
219  bool steady() const noexcept { return steady_; }
220 
221  //- True if default ddt scheme is not steady-state
222  bool transient() const noexcept { return !steady_; }
223 
224  //- The entire dictionary or the optional "select" sub-dictionary.
225  const dictionary& schemesDict() const;
226 
227 
228  // Lookup Access
229 
230  //- Get ddt scheme for given name, or default
231  ITstream& ddtScheme(const word& name) const;
232 
233  //- Get d2dt2 scheme for given name, or default
234  ITstream& d2dt2Scheme(const word& name) const;
235 
236  //- Get interpolation scheme for given name, or default
237  ITstream& interpolationScheme(const word& name) const;
238 
239  //- Get div scheme for given name, or default
240  ITstream& divScheme(const word& name) const;
241 
242  //- Get grad scheme for given name, or default
243  ITstream& gradScheme(const word& name) const;
244 
245  //- Get (finiteArea) lnGrad scheme for given name, or default
246  ITstream& lnGradScheme(const word& name) const;
247 
248  //- Get (finiteVolume) snGrad scheme for given name, or default
249  ITstream& snGradScheme(const word& name) const;
250 
251  //- Get laplacian scheme for given name, or default
252  ITstream& laplacianScheme(const word& name) const;
253 
254  //- Set flux-required for given name (mutable)
255  void setFluxRequired(const word& name) const;
256 
257  //- Get flux-required for given name, or default
258  bool fluxRequired(const word& name) const;
259 
260 
261  // Read Access
262 
263  //- Access ddt schemes dictionary
264  const dictionary& ddtSchemes() const noexcept
265  {
266  return ddtSchemes_.dict_;
267  }
268 
269  //- Access d2dt2 schemes dictionary
270  const dictionary& d2dt2Schemes() const noexcept
271  {
272  return d2dt2Schemes_.dict_;
273  }
274 
275  //- Access interpolation schemes dictionary
277  {
278  return interpSchemes_.dict_;
279  }
280 
281  //- Access div schemes dictionary
282  const dictionary& divSchemes() const noexcept
283  {
284  return divSchemes_.dict_;
285  }
286 
287  //- Access grad schemes dictionary
288  const dictionary& gradSchemes() const noexcept
289  {
290  return gradSchemes_.dict_;
291  }
292 
293  //- Access lnGrad schemes dictionary (finiteArea)
294  const dictionary& lnGradSchemes() const noexcept
295  {
296  return lnGradSchemes_.dict_;
297  }
298 
299  //- Access snGrad schemes dictionary (finiteVolume)
300  const dictionary& snGradSchemes() const noexcept
301  {
302  return snGradSchemes_.dict_;
303  }
304 
305  //- Access laplacian schemes dictionary
306  const dictionary& laplacianSchemes() const noexcept
307  {
308  return laplacianSchemes_.dict_;
309  }
310 
311  //- Access flux-required dictionary
312  const dictionary& fluxRequired() const noexcept
313  {
314  return fluxRequired_;
315  }
316 
317 
318  // Edit Access
319 
320  //- Access ddt schemes dictionary
322  {
323  return ddtSchemes_.dict_;
324  }
325 
326  //- Access d2dt2 schemes dictionary
328  {
329  return d2dt2Schemes_.dict_;
330  }
331 
332  //- Access interpolation schemes dictionary
334  {
335  return interpSchemes_.dict_;
336  }
337 
338  //- Access div schemes dictionary
340  {
341  return divSchemes_.dict_;
342  }
343 
344  //- Access grad schemes dictionary
346  {
347  return gradSchemes_.dict_;
348  }
349 
350  //- Access lnGrad schemes dictionary (finiteArea)
352  {
353  return lnGradSchemes_.dict_;
354  }
355 
356  //- Access snGrad schemes dictionary (finiteVolume)
358  {
359  return snGradSchemes_.dict_;
360  }
361 
362  //- Access laplacian schemes dictionary
364  {
365  return laplacianSchemes_.dict_;
366  }
367 
368  //- Access flux-required dictionary
370  {
371  return fluxRequired_;
372  }
373 
374 
375  // Read
376 
377  //- Read schemes from IOdictionary, respects the "select" keyword
378  bool read();
379 
380 
381  // Write
382 
383  //- Write dictionary (possibly modified) settings
384  void writeDicts(Ostream& os) const;
385 };
386 
387 
388 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
389 
390 //- Global file type for schemesLookup - same content for all ranks
391 template<>
392 struct is_globalIOobject<schemesLookup> : std::true_type {};
393 
394 
395 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
396 
397 } // End namespace Foam
398 
399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
400 
401 #endif
402 
403 // ************************************************************************* //
void writeEntry(Ostream &os) const
Write sub-dictionary with its dictName as its header.
Definition: dictionaryIO.C:157
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:53
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream. FatalIOError if not found, or not a stream. ...
Definition: dictionary.C:367
dictionary dict
ITstream & ddtScheme(const word &name) const
Get ddt scheme for given name, or default.
const dictionary & interpolationSchemes() const noexcept
Access interpolation schemes dictionary.
const dictionary & gradSchemes() const noexcept
Access grad schemes dictionary.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const dictionary & d2dt2Schemes() const noexcept
Access d2dt2 schemes dictionary.
const dictionary & divSchemes() const noexcept
Access div schemes dictionary.
void writeDicts(Ostream &os) const
Write dictionary (possibly modified) settings.
ITstream & d2dt2Scheme(const word &name) const
Get d2dt2 scheme for given name, or default.
const dictionary & fluxRequired() const noexcept
Access flux-required dictionary.
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.
const dictionary & lnGradSchemes() const noexcept
Access lnGrad schemes dictionary (finiteArea)
const dictionary & laplacianSchemes() const noexcept
Access laplacian schemes dictionary.
dictionary()
Default construct, a top-level empty dictionary.
Definition: dictionary.C:68
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()
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
const direction noexcept
Definition: Scalar.H:258
Selector class for finite area/finite volume differencing schemes.
OBJstream os(runTime.globalPath()/outputName)
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.
bool steady() const noexcept
True if default ddt scheme is steady-state.
Registry of regIOobjects.
static int debug
Debug switch.
const dictionary & ddtSchemes() const noexcept
Access ddt schemes dictionary.
Namespace for OpenFOAM.
bool read()
Read schemes from IOdictionary, respects the "select" keyword.
const dictionary & snGradSchemes() const noexcept
Access snGrad schemes dictionary (finiteVolume)
readOption
Enumeration defining read preferences.