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-2018 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 int Foam::fvSchemes::debug(Foam::debug::debugSwitch("fvSchemes", false));
33 
34 
35 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
36 
37 void Foam::fvSchemes::clear()
38 {
39  ddtSchemes_.clear();
40  defaultDdtScheme_.clear();
41  d2dt2Schemes_.clear();
42  defaultD2dt2Scheme_.clear();
43  interpolationSchemes_.clear();
44  defaultInterpolationScheme_.clear();
45  divSchemes_.clear();
46  defaultDivScheme_.clear();
47  gradSchemes_.clear();
48  defaultGradScheme_.clear();
49  snGradSchemes_.clear();
50  defaultSnGradScheme_.clear();
51  laplacianSchemes_.clear();
52  defaultLaplacianScheme_.clear();
53  // Do not clear fluxRequired settings
54 }
55 
56 
57 void Foam::fvSchemes::read(const dictionary& dict)
58 {
59  if (dict.found("ddtSchemes"))
60  {
61  ddtSchemes_ = dict.subDict("ddtSchemes");
62  }
63  else
64  {
65  ddtSchemes_.set("default", "none");
66  }
67 
68  if
69  (
70  ddtSchemes_.found("default")
71  && word(ddtSchemes_.lookup("default")) != "none"
72  )
73  {
74  defaultDdtScheme_ = ddtSchemes_.lookup("default");
75  steady_ =
76  (
77  word(defaultDdtScheme_)
78  == fv::steadyStateDdtScheme<scalar>::typeName
79  );
80  }
81 
82 
83  if (dict.found("d2dt2Schemes"))
84  {
85  d2dt2Schemes_ = dict.subDict("d2dt2Schemes");
86  }
87  else
88  {
89  d2dt2Schemes_.set("default", "none");
90  }
91 
92  if
93  (
94  d2dt2Schemes_.found("default")
95  && word(d2dt2Schemes_.lookup("default")) != "none"
96  )
97  {
98  defaultD2dt2Scheme_ = d2dt2Schemes_.lookup("default");
99  }
100 
101 
102  if (dict.found("interpolationSchemes"))
103  {
104  interpolationSchemes_ = dict.subDict("interpolationSchemes");
105  }
106  else if (!interpolationSchemes_.found("default"))
107  {
108  interpolationSchemes_.add("default", "linear");
109  }
110 
111  if
112  (
113  interpolationSchemes_.found("default")
114  && word(interpolationSchemes_.lookup("default")) != "none"
115  )
116  {
117  defaultInterpolationScheme_ =
118  interpolationSchemes_.lookup("default");
119  }
120 
121 
122  divSchemes_ = dict.subDict("divSchemes");
123 
124  if
125  (
126  divSchemes_.found("default")
127  && word(divSchemes_.lookup("default")) != "none"
128  )
129  {
130  defaultDivScheme_ = divSchemes_.lookup("default");
131  }
132 
133 
134  gradSchemes_ = dict.subDict("gradSchemes");
135 
136  if
137  (
138  gradSchemes_.found("default")
139  && word(gradSchemes_.lookup("default")) != "none"
140  )
141  {
142  defaultGradScheme_ = gradSchemes_.lookup("default");
143  }
144 
145 
146  if (dict.found("snGradSchemes"))
147  {
148  snGradSchemes_ = dict.subDict("snGradSchemes");
149  }
150  else if (!snGradSchemes_.found("default"))
151  {
152  snGradSchemes_.add("default", "corrected");
153  }
154 
155  if
156  (
157  snGradSchemes_.found("default")
158  && word(snGradSchemes_.lookup("default")) != "none"
159  )
160  {
161  defaultSnGradScheme_ = snGradSchemes_.lookup("default");
162  }
163 
164 
165  laplacianSchemes_ = dict.subDict("laplacianSchemes");
166 
167  if
168  (
169  laplacianSchemes_.found("default")
170  && word(laplacianSchemes_.lookup("default")) != "none"
171  )
172  {
173  defaultLaplacianScheme_ = laplacianSchemes_.lookup("default");
174  }
175 
176 
177  if (dict.found("fluxRequired"))
178  {
179  fluxRequired_.merge(dict.subDict("fluxRequired"));
180 
181  if
182  (
183  fluxRequired_.found("default")
184  && word(fluxRequired_.lookup("default")) != "none"
185  )
186  {
187  defaultFluxRequired_ = Switch(fluxRequired_.lookup("default"));
188  }
189  }
190 }
191 
192 
193 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
194 
196 :
198  (
199  IOobject
200  (
201  "fvSchemes",
202  obr.time().system(),
203  obr,
204  (
205  obr.readOpt() == IOobject::MUST_READ
206  || obr.readOpt() == IOobject::READ_IF_PRESENT
208  : obr.readOpt()
209  ),
211  )
212  ),
213  ddtSchemes_
214  (
215  ITstream
216  (
217  objectPath() + ".ddtSchemes",
218  tokenList()
219  )()
220  ),
221  defaultDdtScheme_
222  (
223  ddtSchemes_.name() + ".default",
224  tokenList()
225  ),
226  d2dt2Schemes_
227  (
228  ITstream
229  (
230  objectPath() + ".d2dt2Schemes",
231  tokenList()
232  )()
233  ),
234  defaultD2dt2Scheme_
235  (
236  d2dt2Schemes_.name() + ".default",
237  tokenList()
238  ),
239  interpolationSchemes_
240  (
241  ITstream
242  (
243  objectPath() + ".interpolationSchemes",
244  tokenList()
245  )()
246  ),
247  defaultInterpolationScheme_
248  (
249  interpolationSchemes_.name() + ".default",
250  tokenList()
251  ),
252  divSchemes_
253  (
254  ITstream
255  (
256  objectPath() + ".divSchemes",
257  tokenList()
258  )()
259  ),
260  defaultDivScheme_
261  (
262  divSchemes_.name() + ".default",
263  tokenList()
264  ),
265  gradSchemes_
266  (
267  ITstream
268  (
269  objectPath() + ".gradSchemes",
270  tokenList()
271  )()
272  ),
273  defaultGradScheme_
274  (
275  gradSchemes_.name() + ".default",
276  tokenList()
277  ),
278  snGradSchemes_
279  (
280  ITstream
281  (
282  objectPath() + ".snGradSchemes",
283  tokenList()
284  )()
285  ),
286  defaultSnGradScheme_
287  (
288  snGradSchemes_.name() + ".default",
289  tokenList()
290  ),
291  laplacianSchemes_
292  (
293  ITstream
294  (
295  objectPath() + ".laplacianSchemes",
296  tokenList()
297  )()
298  ),
299  defaultLaplacianScheme_
300  (
301  laplacianSchemes_.name() + ".default",
302  tokenList()
303  ),
304  fluxRequired_
305  (
306  ITstream
307  (
308  objectPath() + ".fluxRequired",
309  tokenList()
310  )()
311  ),
312  defaultFluxRequired_(false),
313  steady_(false)
314 {
315  if
316  (
320  )
321  {
322  read(schemesDict());
323  }
324 }
325 
326 
327 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
328 
330 {
331  if (regIOobject::read())
332  {
333  // Clear current settings except fluxRequired
334  clear();
335 
336  read(schemesDict());
337 
338  return true;
339  }
340  else
341  {
342  return false;
343  }
344 }
345 
346 
348 {
349  if (found("select"))
350  {
351  return subDict(word(lookup("select")));
352  }
353  else
354  {
355  return *this;
356  }
357 }
358 
359 
361 {
362  if (debug)
363  {
364  Info<< "Lookup ddtScheme for " << name << endl;
365  }
366 
367  if (ddtSchemes_.found(name) || defaultDdtScheme_.empty())
368  {
369  return ddtSchemes_.lookup(name);
370  }
371  else
372  {
373  const_cast<ITstream&>(defaultDdtScheme_).rewind();
374  return const_cast<ITstream&>(defaultDdtScheme_);
375  }
376 }
377 
378 
380 {
381  if (debug)
382  {
383  Info<< "Lookup d2dt2Scheme for " << name << endl;
384  }
385 
386  if (d2dt2Schemes_.found(name) || defaultD2dt2Scheme_.empty())
387  {
388  return d2dt2Schemes_.lookup(name);
389  }
390  else
391  {
392  const_cast<ITstream&>(defaultD2dt2Scheme_).rewind();
393  return const_cast<ITstream&>(defaultD2dt2Scheme_);
394  }
395 }
396 
397 
399 {
400  if (debug)
401  {
402  Info<< "Lookup interpolationScheme for " << name << endl;
403  }
404 
405  if
406  (
407  interpolationSchemes_.found(name)
408  || defaultInterpolationScheme_.empty()
409  )
410  {
411  return interpolationSchemes_.lookup(name);
412  }
413  else
414  {
415  const_cast<ITstream&>(defaultInterpolationScheme_).rewind();
416  return const_cast<ITstream&>(defaultInterpolationScheme_);
417  }
418 }
419 
420 
422 {
423  if (debug)
424  {
425  Info<< "Lookup divScheme for " << name << endl;
426  }
427 
428  if (divSchemes_.found(name) || defaultDivScheme_.empty())
429  {
430  return divSchemes_.lookup(name);
431  }
432  else
433  {
434  const_cast<ITstream&>(defaultDivScheme_).rewind();
435  return const_cast<ITstream&>(defaultDivScheme_);
436  }
437 }
438 
439 
441 {
442  if (debug)
443  {
444  Info<< "Lookup gradScheme for " << name << endl;
445  }
446 
447  if (gradSchemes_.found(name) || defaultGradScheme_.empty())
448  {
449  return gradSchemes_.lookup(name);
450  }
451  else
452  {
453  const_cast<ITstream&>(defaultGradScheme_).rewind();
454  return const_cast<ITstream&>(defaultGradScheme_);
455  }
456 }
457 
458 
460 {
461  if (debug)
462  {
463  Info<< "Lookup snGradScheme for " << name << endl;
464  }
465 
466  if (snGradSchemes_.found(name) || defaultSnGradScheme_.empty())
467  {
468  return snGradSchemes_.lookup(name);
469  }
470  else
471  {
472  const_cast<ITstream&>(defaultSnGradScheme_).rewind();
473  return const_cast<ITstream&>(defaultSnGradScheme_);
474  }
475 }
476 
477 
479 {
480  if (debug)
481  {
482  Info<< "Lookup laplacianScheme for " << name << endl;
483  }
484 
485  if (laplacianSchemes_.found(name) || defaultLaplacianScheme_.empty())
486  {
487  return laplacianSchemes_.lookup(name);
488  }
489  else
490  {
491  const_cast<ITstream&>(defaultLaplacianScheme_).rewind();
492  return const_cast<ITstream&>(defaultLaplacianScheme_);
493  }
494 }
495 
496 
498 {
499  if (debug)
500  {
501  Info<< "Setting fluxRequired for " << name << endl;
502  }
503 
504  fluxRequired_.add(name, true, true);
505 }
506 
507 
509 {
510  if (debug)
511  {
512  Info<< "Lookup fluxRequired for " << name << endl;
513  }
514 
515  if (fluxRequired_.found(name))
516  {
517  return true;
518  }
519  else
520  {
521  return defaultFluxRequired_;
522  }
523 }
524 
525 
526 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:438
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:313
ITstream & laplacianScheme(const word &name) const
Definition: fvSchemes.C:478
virtual bool read()
Read object.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
fvSchemes(const objectRegistry &obr)
Construct for objectRegistry.
Definition: fvSchemes.C:195
static int debug
Debug switch.
Definition: fvSchemes.H:97
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:329
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
bool headerOk()
Read and check header info.
Definition: regIOobject.C:431
void setFluxRequired(const word &name) const
Definition: fvSchemes.C:497
ITstream & ddtScheme(const word &name) const
Definition: fvSchemes.C:360
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:821
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:52
ITstream & snGradScheme(const word &name) const
Definition: fvSchemes.C:459
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:699
const dictionary & schemesDict() const
Definition: fvSchemes.C:347
dictionary()
Construct top-level dictionary null.
Definition: dictionary.C:238
ITstream & divScheme(const word &name) const
Definition: fvSchemes.C:421
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:124
A class for handling words, derived from string.
Definition: word.H:59
ITstream & interpolationScheme(const word &name) const
Definition: fvSchemes.C:398
int debugSwitch(const char *name, const int defaultValue=0)
Lookup debug switch or add default value.
Definition: debug.C:178
const word & name() const
Name function is needed to disambiguate those inherited.
ITstream & d2dt2Scheme(const word &name) const
Definition: fvSchemes.C:379
ITstream & gradScheme(const word &name) const
Definition: fvSchemes.C:440
const Time & time() const
Return time.
Definition: IOobject.C:360
bool fluxRequired(const word &name) const
Definition: fvSchemes.C:508
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:948
messageStream Info
bool merge(const dictionary &)
Merge entries from the given dictionary.
Definition: dictionary.C:1097
Registry of regIOobjects.
void clear()
Clear the dictionary.
Definition: dictionary.C:1142
readOption readOpt() const
Definition: IOobject.H:345
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:404
Input token stream.
Definition: ITstream.H:49
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1234
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583