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-2020 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  (
208  obr.readOpt() == IOobject::MUST_READ
209  || obr.readOpt() == IOobject::READ_IF_PRESENT
210  ? IOobject::MUST_READ_IF_MODIFIED
211  : obr.readOpt()
212  ),
213  IOobject::NO_WRITE
214  )
215  ),
216  ddtSchemes_
217  (
218  ITstream
219  (
220  objectPath() + ".ddtSchemes",
221  tokenList()
222  )()
223  ),
224  defaultDdtScheme_
225  (
226  ddtSchemes_.name() + ".default",
227  tokenList()
228  ),
229  d2dt2Schemes_
230  (
231  ITstream
232  (
233  objectPath() + ".d2dt2Schemes",
234  tokenList()
235  )()
236  ),
237  defaultD2dt2Scheme_
238  (
239  d2dt2Schemes_.name() + ".default",
240  tokenList()
241  ),
242  interpolationSchemes_
243  (
244  ITstream
245  (
246  objectPath() + ".interpolationSchemes",
247  tokenList()
248  )()
249  ),
250  defaultInterpolationScheme_
251  (
252  interpolationSchemes_.name() + ".default",
253  tokenList()
254  ),
255  divSchemes_
256  (
257  ITstream
258  (
259  objectPath() + ".divSchemes",
260  tokenList()
261  )()
262  ),
263  defaultDivScheme_
264  (
265  divSchemes_.name() + ".default",
266  tokenList()
267  ),
268  gradSchemes_
269  (
270  ITstream
271  (
272  objectPath() + ".gradSchemes",
273  tokenList()
274  )()
275  ),
276  defaultGradScheme_
277  (
278  gradSchemes_.name() + ".default",
279  tokenList()
280  ),
281  snGradSchemes_
282  (
283  ITstream
284  (
285  objectPath() + ".snGradSchemes",
286  tokenList()
287  )()
288  ),
289  defaultSnGradScheme_
290  (
291  snGradSchemes_.name() + ".default",
292  tokenList()
293  ),
294  laplacianSchemes_
295  (
296  ITstream
297  (
298  objectPath() + ".laplacianSchemes",
299  tokenList()
300  )()
301  ),
302  defaultLaplacianScheme_
303  (
304  laplacianSchemes_.name() + ".default",
305  tokenList()
306  ),
307  fluxRequired_
308  (
309  ITstream
310  (
311  objectPath() + ".fluxRequired",
312  tokenList()
313  )()
314  ),
315  defaultFluxRequired_(false),
316  steady_(false)
317 {
318  if
319  (
323  )
324  {
325  read(schemesDict());
326  }
327 }
328 
329 
330 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
331 
333 {
334  if (regIOobject::read())
335  {
336  // Clear current settings except fluxRequired
337  clear();
338 
339  read(schemesDict());
340 
341  return true;
342  }
343  else
344  {
345  return false;
346  }
347 }
348 
349 
351 {
352  if (found("select"))
353  {
354  return subDict(word(lookup("select")));
355  }
356  else
357  {
358  return *this;
359  }
360 }
361 
362 
364 {
365  if (debug)
366  {
367  Info<< "Lookup ddtScheme for " << name << endl;
368  }
369 
370  if (ddtSchemes_.found(name) || defaultDdtScheme_.empty())
371  {
372  return ddtSchemes_.lookup(name);
373  }
374  else
375  {
376  const_cast<ITstream&>(defaultDdtScheme_).rewind();
377  return const_cast<ITstream&>(defaultDdtScheme_);
378  }
379 }
380 
381 
383 {
384  if (debug)
385  {
386  Info<< "Lookup d2dt2Scheme for " << name << endl;
387  }
388 
389  if (d2dt2Schemes_.found(name) || defaultD2dt2Scheme_.empty())
390  {
391  return d2dt2Schemes_.lookup(name);
392  }
393  else
394  {
395  const_cast<ITstream&>(defaultD2dt2Scheme_).rewind();
396  return const_cast<ITstream&>(defaultD2dt2Scheme_);
397  }
398 }
399 
400 
402 {
403  if (debug)
404  {
405  Info<< "Lookup interpolationScheme for " << name << endl;
406  }
407 
408  if
409  (
410  interpolationSchemes_.found(name)
411  || defaultInterpolationScheme_.empty()
412  )
413  {
414  return interpolationSchemes_.lookup(name);
415  }
416  else
417  {
418  const_cast<ITstream&>(defaultInterpolationScheme_).rewind();
419  return const_cast<ITstream&>(defaultInterpolationScheme_);
420  }
421 }
422 
423 
425 {
426  if (debug)
427  {
428  Info<< "Lookup divScheme for " << name << endl;
429  }
430 
431  if (divSchemes_.found(name) || defaultDivScheme_.empty())
432  {
433  return divSchemes_.lookup(name);
434  }
435  else
436  {
437  const_cast<ITstream&>(defaultDivScheme_).rewind();
438  return const_cast<ITstream&>(defaultDivScheme_);
439  }
440 }
441 
442 
444 {
445  if (debug)
446  {
447  Info<< "Lookup gradScheme for " << name << endl;
448  }
449 
450  if (gradSchemes_.found(name) || defaultGradScheme_.empty())
451  {
452  return gradSchemes_.lookup(name);
453  }
454  else
455  {
456  const_cast<ITstream&>(defaultGradScheme_).rewind();
457  return const_cast<ITstream&>(defaultGradScheme_);
458  }
459 }
460 
461 
463 {
464  if (debug)
465  {
466  Info<< "Lookup snGradScheme for " << name << endl;
467  }
468 
469  if (snGradSchemes_.found(name) || defaultSnGradScheme_.empty())
470  {
471  return snGradSchemes_.lookup(name);
472  }
473  else
474  {
475  const_cast<ITstream&>(defaultSnGradScheme_).rewind();
476  return const_cast<ITstream&>(defaultSnGradScheme_);
477  }
478 }
479 
480 
482 {
483  if (debug)
484  {
485  Info<< "Lookup laplacianScheme for " << name << endl;
486  }
487 
488  if (laplacianSchemes_.found(name) || defaultLaplacianScheme_.empty())
489  {
490  return laplacianSchemes_.lookup(name);
491  }
492  else
493  {
494  const_cast<ITstream&>(defaultLaplacianScheme_).rewind();
495  return const_cast<ITstream&>(defaultLaplacianScheme_);
496  }
497 }
498 
499 
501 {
502  if (debug)
503  {
504  Info<< "Setting fluxRequired for " << name << endl;
505  }
506 
507  fluxRequired_.add(name, true, true);
508 }
509 
510 
512 {
513  if (debug)
514  {
515  Info<< "Lookup fluxRequired for " << name << endl;
516  }
517 
518  if (fluxRequired_.found(name))
519  {
520  return true;
521  }
522  else
523  {
524  return defaultFluxRequired_;
525  }
526 }
527 
528 
529 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:643
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:325
ITstream & laplacianScheme(const word &name) const
Definition: fvSchemes.C:481
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
bool read()
Read the fvSchemes.
Definition: fvSchemes.C:332
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool headerOk()
Read and check header info.
Definition: regIOobject.C:397
void setFluxRequired(const word &name) const
Definition: fvSchemes.C:500
ITstream & ddtScheme(const word &name) const
Definition: fvSchemes.C:363
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1133
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
ITstream & snGradScheme(const word &name) const
Definition: fvSchemes.C:462
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:982
const dictionary & schemesDict() const
Definition: fvSchemes.C:350
ITstream & divScheme(const word &name) const
Definition: fvSchemes.C:424
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:109
A class for handling words, derived from string.
Definition: word.H:59
ITstream & interpolationScheme(const word &name) const
Definition: fvSchemes.C:401
defineTypeNameAndDebug(combustionModel, 0)
ITstream & d2dt2Scheme(const word &name) const
Definition: fvSchemes.C:382
ITstream & gradScheme(const word &name) const
Definition: fvSchemes.C:443
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
bool fluxRequired(const word &name) const
Definition: fvSchemes.C:511
messageStream Info
Registry of regIOobjects.
readOption readOpt() const
Definition: IOobject.H:353
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
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:844