fvSchemes.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "fvSchemes.H"
27 #include "Time.H"
28 #include "steadyStateDdtScheme.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(fvSchemes, 0);
35 }
36 
37 
38 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
39 
40 void Foam::fvSchemes::clear()
41 {
42  ddtSchemes_.clear();
43  defaultDdtScheme_.clear();
44  d2dt2Schemes_.clear();
45  defaultD2dt2Scheme_.clear();
46  interpolationSchemes_.clear();
47  defaultInterpolationScheme_.clear();
48  divSchemes_.clear();
49  defaultDivScheme_.clear();
50  gradSchemes_.clear();
51  defaultGradScheme_.clear();
52  snGradSchemes_.clear();
53  defaultSnGradScheme_.clear();
54  laplacianSchemes_.clear();
55  defaultLaplacianScheme_.clear();
56  // Do not clear fluxRequired settings
57 }
58 
59 
60 void Foam::fvSchemes::read(const dictionary& dict)
61 {
62  if (dict.found("ddtSchemes"))
63  {
64  ddtSchemes_ = dict.subDict("ddtSchemes");
65  }
66  else
67  {
68  ddtSchemes_.set("default", "none");
69  }
70 
71  if
72  (
73  ddtSchemes_.found("default")
74  && word(ddtSchemes_.lookup("default")) != "none"
75  )
76  {
77  defaultDdtScheme_ = ddtSchemes_.lookup("default");
78  steady_ =
79  (
80  word(defaultDdtScheme_)
81  == fv::steadyStateDdtScheme<scalar>::typeName
82  );
83  }
84 
85 
86  if (dict.found("d2dt2Schemes"))
87  {
88  d2dt2Schemes_ = dict.subDict("d2dt2Schemes");
89  }
90  else
91  {
92  d2dt2Schemes_.set("default", "none");
93  }
94 
95  if
96  (
97  d2dt2Schemes_.found("default")
98  && word(d2dt2Schemes_.lookup("default")) != "none"
99  )
100  {
101  defaultD2dt2Scheme_ = d2dt2Schemes_.lookup("default");
102  }
103 
104 
105  if (dict.found("interpolationSchemes"))
106  {
107  interpolationSchemes_ = dict.subDict("interpolationSchemes");
108  }
109  else if (!interpolationSchemes_.found("default"))
110  {
111  interpolationSchemes_.add("default", "linear");
112  }
113 
114  if
115  (
116  interpolationSchemes_.found("default")
117  && word(interpolationSchemes_.lookup("default")) != "none"
118  )
119  {
120  defaultInterpolationScheme_ =
121  interpolationSchemes_.lookup("default");
122  }
123 
124 
125  divSchemes_ = dict.subDict("divSchemes");
126 
127  if
128  (
129  divSchemes_.found("default")
130  && word(divSchemes_.lookup("default")) != "none"
131  )
132  {
133  defaultDivScheme_ = divSchemes_.lookup("default");
134  }
135 
136 
137  gradSchemes_ = dict.subDict("gradSchemes");
138 
139  if
140  (
141  gradSchemes_.found("default")
142  && word(gradSchemes_.lookup("default")) != "none"
143  )
144  {
145  defaultGradScheme_ = gradSchemes_.lookup("default");
146  }
147 
148 
149  if (dict.found("snGradSchemes"))
150  {
151  snGradSchemes_ = dict.subDict("snGradSchemes");
152  }
153  else if (!snGradSchemes_.found("default"))
154  {
155  snGradSchemes_.add("default", "corrected");
156  }
157 
158  if
159  (
160  snGradSchemes_.found("default")
161  && word(snGradSchemes_.lookup("default")) != "none"
162  )
163  {
164  defaultSnGradScheme_ = snGradSchemes_.lookup("default");
165  }
166 
167 
168  laplacianSchemes_ = dict.subDict("laplacianSchemes");
169 
170  if
171  (
172  laplacianSchemes_.found("default")
173  && word(laplacianSchemes_.lookup("default")) != "none"
174  )
175  {
176  defaultLaplacianScheme_ = laplacianSchemes_.lookup("default");
177  }
178 
179 
180  if (dict.found("fluxRequired"))
181  {
182  fluxRequired_.merge(dict.subDict("fluxRequired"));
183 
184  if
185  (
186  fluxRequired_.found("default")
187  && word(fluxRequired_.lookup("default")) != "none"
188  )
189  {
190  defaultFluxRequired_ = Switch(fluxRequired_.lookup("default"));
191  }
192  }
193 }
194 
195 
196 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
197 
199 :
201  (
202  IOobject
203  (
204  "fvSchemes",
205  obr.time().system(),
206  obr,
207  IOobject::MUST_READ_IF_MODIFIED,
208  IOobject::NO_WRITE
209  )
210  ),
211  ddtSchemes_
212  (
213  ITstream
214  (
215  objectPath() + ".ddtSchemes",
216  tokenList()
217  )()
218  ),
219  defaultDdtScheme_
220  (
221  ddtSchemes_.name() + ".default",
222  tokenList()
223  ),
224  d2dt2Schemes_
225  (
226  ITstream
227  (
228  objectPath() + ".d2dt2Schemes",
229  tokenList()
230  )()
231  ),
232  defaultD2dt2Scheme_
233  (
234  d2dt2Schemes_.name() + ".default",
235  tokenList()
236  ),
237  interpolationSchemes_
238  (
239  ITstream
240  (
241  objectPath() + ".interpolationSchemes",
242  tokenList()
243  )()
244  ),
245  defaultInterpolationScheme_
246  (
247  interpolationSchemes_.name() + ".default",
248  tokenList()
249  ),
250  divSchemes_
251  (
252  ITstream
253  (
254  objectPath() + ".divSchemes",
255  tokenList()
256  )()
257  ),
258  defaultDivScheme_
259  (
260  divSchemes_.name() + ".default",
261  tokenList()
262  ),
263  gradSchemes_
264  (
265  ITstream
266  (
267  objectPath() + ".gradSchemes",
268  tokenList()
269  )()
270  ),
271  defaultGradScheme_
272  (
273  gradSchemes_.name() + ".default",
274  tokenList()
275  ),
276  snGradSchemes_
277  (
278  ITstream
279  (
280  objectPath() + ".snGradSchemes",
281  tokenList()
282  )()
283  ),
284  defaultSnGradScheme_
285  (
286  snGradSchemes_.name() + ".default",
287  tokenList()
288  ),
289  laplacianSchemes_
290  (
291  ITstream
292  (
293  objectPath() + ".laplacianSchemes",
294  tokenList()
295  )()
296  ),
297  defaultLaplacianScheme_
298  (
299  laplacianSchemes_.name() + ".default",
300  tokenList()
301  ),
302  fluxRequired_
303  (
304  ITstream
305  (
306  objectPath() + ".fluxRequired",
307  tokenList()
308  )()
309  ),
310  defaultFluxRequired_(false),
311  steady_(false)
312 {
313  read(dict());
314 }
315 
316 
317 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
318 
320 {
321  if (regIOobject::read())
322  {
323  // Clear current settings except fluxRequired
324  clear();
325 
326  read(dict());
327 
328  return true;
329  }
330  else
331  {
332  return false;
333  }
334 }
335 
336 
338 {
339  if (found("select"))
340  {
341  return subDict(word(lookup("select")));
342  }
343  else
344  {
345  return *this;
346  }
347 }
348 
349 
351 {
352  if (debug)
353  {
354  Info<< "Lookup ddtScheme for " << name << endl;
355  }
356 
357  if (ddtSchemes_.found(name) || defaultDdtScheme_.empty())
358  {
359  return ddtSchemes_.lookup(name);
360  }
361  else
362  {
363  const_cast<ITstream&>(defaultDdtScheme_).rewind();
364  return const_cast<ITstream&>(defaultDdtScheme_);
365  }
366 }
367 
368 
370 {
371  if (debug)
372  {
373  Info<< "Lookup d2dt2Scheme for " << name << endl;
374  }
375 
376  if (d2dt2Schemes_.found(name) || defaultD2dt2Scheme_.empty())
377  {
378  return d2dt2Schemes_.lookup(name);
379  }
380  else
381  {
382  const_cast<ITstream&>(defaultD2dt2Scheme_).rewind();
383  return const_cast<ITstream&>(defaultD2dt2Scheme_);
384  }
385 }
386 
387 
389 {
390  if (debug)
391  {
392  Info<< "Lookup interpolationScheme for " << name << endl;
393  }
394 
395  if
396  (
397  interpolationSchemes_.found(name)
398  || defaultInterpolationScheme_.empty()
399  )
400  {
401  return interpolationSchemes_.lookup(name);
402  }
403  else
404  {
405  const_cast<ITstream&>(defaultInterpolationScheme_).rewind();
406  return const_cast<ITstream&>(defaultInterpolationScheme_);
407  }
408 }
409 
410 
412 {
413  if (debug)
414  {
415  Info<< "Lookup divScheme for " << name << endl;
416  }
417 
418  if (divSchemes_.found(name) || defaultDivScheme_.empty())
419  {
420  return divSchemes_.lookup(name);
421  }
422  else
423  {
424  const_cast<ITstream&>(defaultDivScheme_).rewind();
425  return const_cast<ITstream&>(defaultDivScheme_);
426  }
427 }
428 
429 
431 {
432  if (debug)
433  {
434  Info<< "Lookup gradScheme for " << name << endl;
435  }
436 
437  if (gradSchemes_.found(name) || defaultGradScheme_.empty())
438  {
439  return gradSchemes_.lookup(name);
440  }
441  else
442  {
443  const_cast<ITstream&>(defaultGradScheme_).rewind();
444  return const_cast<ITstream&>(defaultGradScheme_);
445  }
446 }
447 
448 
450 {
451  if (debug)
452  {
453  Info<< "Lookup snGradScheme for " << name << endl;
454  }
455 
456  if (snGradSchemes_.found(name) || defaultSnGradScheme_.empty())
457  {
458  return snGradSchemes_.lookup(name);
459  }
460  else
461  {
462  const_cast<ITstream&>(defaultSnGradScheme_).rewind();
463  return const_cast<ITstream&>(defaultSnGradScheme_);
464  }
465 }
466 
467 
469 {
470  if (debug)
471  {
472  Info<< "Lookup laplacianScheme for " << name << endl;
473  }
474 
475  if (laplacianSchemes_.found(name) || defaultLaplacianScheme_.empty())
476  {
477  return laplacianSchemes_.lookup(name);
478  }
479  else
480  {
481  const_cast<ITstream&>(defaultLaplacianScheme_).rewind();
482  return const_cast<ITstream&>(defaultLaplacianScheme_);
483  }
484 }
485 
486 
488 {
489  if (debug)
490  {
491  Info<< "Setting fluxRequired for " << name << endl;
492  }
493 
494  fluxRequired_.add(name, true, true);
495 }
496 
497 
499 {
500  if (debug)
501  {
502  Info<< "Lookup fluxRequired for " << name << endl;
503  }
504 
505  if (fluxRequired_.found(name))
506  {
507  return true;
508  }
509  else
510  {
511  return defaultFluxRequired_;
512  }
513 }
514 
515 
516 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:663
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:325
virtual bool read()
Read object.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
fvSchemes(const objectRegistry &obr)
Construct for objectRegistry.
Definition: fvSchemes.C:198
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
ITstream & div(const word &name) const
Definition: fvSchemes.C:411
ITstream & interpolation(const word &name) const
Definition: fvSchemes.C:388
bool read()
Read the fvSchemes.
Definition: fvSchemes.C:319
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
ITstream & laplacian(const word &name) const
Definition: fvSchemes.C:468
void setFluxRequired(const word &name) const
Definition: fvSchemes.C:487
const dictionary & dict() const
Definition: fvSchemes.C:337
ITstream & d2dt2(const word &name) const
Definition: fvSchemes.C:369
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1153
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:1002
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:109
A class for handling words, derived from string.
Definition: word.H:59
defineTypeNameAndDebug(combustionModel, 0)
ITstream & grad(const word &name) const
Definition: fvSchemes.C:430
ITstream & snGrad(const word &name) const
Definition: fvSchemes.C:449
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
bool fluxRequired(const word &name) const
Definition: fvSchemes.C:498
messageStream Info
ITstream & ddt(const word &name) const
Definition: fvSchemes.C:350
Registry of regIOobjects.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
Input token stream.
Definition: ITstream.H:49
Namespace for OpenFOAM.
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1230
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864