FreeFOAM The Cross-Platform CFD Toolkit
fvSchemes.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/Time.H>
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 
32 int Foam::fvSchemes::debug(Foam::debug::debugSwitch("fvSchemes", false));
33 
34 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
35 
36 void Foam::fvSchemes::clear()
37 {
38  ddtSchemes_.clear();
39  defaultDdtScheme_.clear();
40  d2dt2Schemes_.clear();
41  defaultD2dt2Scheme_.clear();
42  interpolationSchemes_.clear();
43  defaultInterpolationScheme_.clear();
44  divSchemes_.clear(); // optional
45  defaultDivScheme_.clear();
46  gradSchemes_.clear(); // optional
47  defaultGradScheme_.clear();
48  snGradSchemes_.clear();
49  defaultSnGradScheme_.clear();
50  laplacianSchemes_.clear(); // optional
51  defaultLaplacianScheme_.clear();
52  fluxRequired_.clear();
53  defaultFluxRequired_ = false;
54  cacheFields_.clear();
55 }
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
59 Foam::fvSchemes::fvSchemes(const objectRegistry& obr)
60 :
62  (
63  IOobject
64  (
65  "fvSchemes",
66  obr.time().system(),
67  obr,
68  IOobject::MUST_READ,
69  IOobject::NO_WRITE
70  )
71  ),
72  ddtSchemes_
73  (
74  ITstream
75  (
76  objectPath() + "::ddtSchemes",
77  tokenList()
78  )()
79  ),
80  defaultDdtScheme_
81  (
82  ddtSchemes_.name() + "::default",
83  tokenList()
84  ),
85  d2dt2Schemes_
86  (
87  ITstream
88  (
89  objectPath() + "::d2dt2Schemes",
90  tokenList()
91  )()
92  ),
93  defaultD2dt2Scheme_
94  (
95  d2dt2Schemes_.name() + "::default",
96  tokenList()
97  ),
98  interpolationSchemes_
99  (
100  ITstream
101  (
102  objectPath() + "::interpolationSchemes",
103  tokenList()
104  )()
105  ),
106  defaultInterpolationScheme_
107  (
108  interpolationSchemes_.name() + "::default",
109  tokenList()
110  ),
111  divSchemes_
112  (
113  ITstream
114  (
115  objectPath() + "::divSchemes",
116  tokenList()
117  )()
118  ),
119  defaultDivScheme_
120  (
121  divSchemes_.name() + "::default",
122  tokenList()
123  ),
124  gradSchemes_
125  (
126  ITstream
127  (
128  objectPath() + "::gradSchemes",
129  tokenList()
130  )()
131  ),
132  defaultGradScheme_
133  (
134  gradSchemes_.name() + "::default",
135  tokenList()
136  ),
137  snGradSchemes_
138  (
139  ITstream
140  (
141  objectPath() + "::snGradSchemes",
142  tokenList()
143  )()
144  ),
145  defaultSnGradScheme_
146  (
147  snGradSchemes_.name() + "::default",
148  tokenList()
149  ),
150  laplacianSchemes_
151  (
152  ITstream
153  (
154  objectPath() + "::laplacianSchemes",
155  tokenList()
156  )()
157  ),
158  defaultLaplacianScheme_
159  (
160  laplacianSchemes_.name() + "::default",
161  tokenList()
162  ),
163  fluxRequired_
164  (
165  ITstream
166  (
167  objectPath() + "::fluxRequired",
168  tokenList()
169  )()
170  ),
171  defaultFluxRequired_(false),
172  cacheFields_
173  (
174  ITstream
175  (
176  objectPath() + "::cacheFields",
177  tokenList()
178  )()
179  )
180 {
181  read();
182 }
183 
184 
185 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
186 
188 {
189  if (regIOobject::read())
190  {
191  const dictionary& dict = schemesDict();
192 
193  // persistent settings across reads is incorrect
194  clear();
195 
196  if (dict.found("ddtSchemes"))
197  {
198  ddtSchemes_ = dict.subDict("ddtSchemes");
199  }
200  else if (dict.found("timeScheme"))
201  {
202  // For backward compatibility.
203  // The timeScheme will be deprecated with warning or removed
204  WarningIn("fvSchemes::read()")
205  << "Using deprecated 'timeScheme' instead of 'ddtSchemes'"
206  << nl << endl;
207 
208  word schemeName(dict.lookup("timeScheme"));
209 
210  if (schemeName == "EulerImplicit")
211  {
212  schemeName = "Euler";
213  }
214  else if (schemeName == "BackwardDifferencing")
215  {
216  schemeName = "backward";
217  }
218  else if (schemeName == "SteadyState")
219  {
220  schemeName = "steadyState";
221  }
222  else
223  {
224  FatalIOErrorIn("fvSchemes::read()", dict.lookup("timeScheme"))
225  << "\n Only EulerImplicit, BackwardDifferencing and "
226  "SteadyState\n are supported by the old timeScheme "
227  "specification.\n Please use ddtSchemes instead."
228  << exit(FatalIOError);
229  }
230 
231  ddtSchemes_.set("default", schemeName);
232 
233  ddtSchemes_.lookup("default")[0].lineNumber() =
234  dict.lookup("timeScheme").lineNumber();
235  }
236  else
237  {
238  ddtSchemes_.set("default", "none");
239  }
240 
241  if
242  (
243  ddtSchemes_.found("default")
244  && word(ddtSchemes_.lookup("default")) != "none"
245  )
246  {
247  defaultDdtScheme_ = ddtSchemes_.lookup("default");
248  }
249 
250 
251  if (dict.found("d2dt2Schemes"))
252  {
253  d2dt2Schemes_ = dict.subDict("d2dt2Schemes");
254  }
255  else if (dict.found("timeScheme"))
256  {
257  // For backward compatibility.
258  // The timeScheme will be deprecated with warning or removed
259  WarningIn("fvSchemes::read()")
260  << "Using deprecated 'timeScheme' instead of 'd2dt2Schemes'"
261  << nl << endl;
262 
263  word schemeName(dict.lookup("timeScheme"));
264 
265  if (schemeName == "EulerImplicit")
266  {
267  schemeName = "Euler";
268  }
269  else if (schemeName == "SteadyState")
270  {
271  schemeName = "steadyState";
272  }
273 
274  d2dt2Schemes_.set("default", schemeName);
275 
276  d2dt2Schemes_.lookup("default")[0].lineNumber() =
277  dict.lookup("timeScheme").lineNumber();
278  }
279  else
280  {
281  d2dt2Schemes_.set("default", "none");
282  }
283 
284  if
285  (
286  d2dt2Schemes_.found("default")
287  && word(d2dt2Schemes_.lookup("default")) != "none"
288  )
289  {
290  defaultD2dt2Scheme_ = d2dt2Schemes_.lookup("default");
291  }
292 
293 
294  if (dict.found("interpolationSchemes"))
295  {
296  interpolationSchemes_ = dict.subDict("interpolationSchemes");
297  }
298  else if (!interpolationSchemes_.found("default"))
299  {
300  interpolationSchemes_.add("default", "linear");
301  }
302 
303  if
304  (
305  interpolationSchemes_.found("default")
306  && word(interpolationSchemes_.lookup("default")) != "none"
307  )
308  {
309  defaultInterpolationScheme_ =
310  interpolationSchemes_.lookup("default");
311  }
312 
313 
314  divSchemes_ = dict.subDict("divSchemes");
315 
316  if
317  (
318  divSchemes_.found("default")
319  && word(divSchemes_.lookup("default")) != "none"
320  )
321  {
322  defaultDivScheme_ = divSchemes_.lookup("default");
323  }
324 
325 
326  gradSchemes_ = dict.subDict("gradSchemes");
327 
328  if
329  (
330  gradSchemes_.found("default")
331  && word(gradSchemes_.lookup("default")) != "none"
332  )
333  {
334  defaultGradScheme_ = gradSchemes_.lookup("default");
335  }
336 
337 
338  if (dict.found("snGradSchemes"))
339  {
340  snGradSchemes_ = dict.subDict("snGradSchemes");
341  }
342  else if (!snGradSchemes_.found("default"))
343  {
344  snGradSchemes_.add("default", "corrected");
345  }
346 
347  if
348  (
349  snGradSchemes_.found("default")
350  && word(snGradSchemes_.lookup("default")) != "none"
351  )
352  {
353  defaultSnGradScheme_ = snGradSchemes_.lookup("default");
354  }
355 
356 
357  laplacianSchemes_ = dict.subDict("laplacianSchemes");
358 
359  if
360  (
361  laplacianSchemes_.found("default")
362  && word(laplacianSchemes_.lookup("default")) != "none"
363  )
364  {
365  defaultLaplacianScheme_ = laplacianSchemes_.lookup("default");
366  }
367 
368 
369  if (dict.found("fluxRequired"))
370  {
371  fluxRequired_ = dict.subDict("fluxRequired");
372 
373  if
374  (
375  fluxRequired_.found("default")
376  && word(fluxRequired_.lookup("default")) != "none"
377  )
378  {
379  defaultFluxRequired_ = Switch(fluxRequired_.lookup("default"));
380  }
381  }
382 
383  if (dict.found("cacheFields"))
384  {
385  cacheFields_ = dict.subDict("cacheFields");
386  }
387 
388  return true;
389  }
390  else
391  {
392  return false;
393  }
394 }
395 
396 
398 {
399  if (found("select"))
400  {
401  return subDict(word(lookup("select")));
402  }
403  else
404  {
405  return *this;
406  }
407 }
408 
409 
411 {
412  if (debug)
413  {
414  Info<< "Lookup ddtScheme for " << name << endl;
415  }
416 
417  if (ddtSchemes_.found(name) || defaultDdtScheme_.empty())
418  {
419  return ddtSchemes_.lookup(name);
420  }
421  else
422  {
423  const_cast<ITstream&>(defaultDdtScheme_).rewind();
424  return const_cast<ITstream&>(defaultDdtScheme_);
425  }
426 }
427 
428 
430 {
431  if (debug)
432  {
433  Info<< "Lookup d2dt2Scheme for " << name << endl;
434  }
435 
436  if (d2dt2Schemes_.found(name) || defaultD2dt2Scheme_.empty())
437  {
438  return d2dt2Schemes_.lookup(name);
439  }
440  else
441  {
442  const_cast<ITstream&>(defaultD2dt2Scheme_).rewind();
443  return const_cast<ITstream&>(defaultD2dt2Scheme_);
444  }
445 }
446 
447 
449 {
450  if (debug)
451  {
452  Info<< "Lookup interpolationScheme for " << name << endl;
453  }
454 
455  if
456  (
457  interpolationSchemes_.found(name)
458  || defaultInterpolationScheme_.empty()
459  )
460  {
461  return interpolationSchemes_.lookup(name);
462  }
463  else
464  {
465  const_cast<ITstream&>(defaultInterpolationScheme_).rewind();
466  return const_cast<ITstream&>(defaultInterpolationScheme_);
467  }
468 }
469 
470 
472 {
473  if (debug)
474  {
475  Info<< "Lookup divScheme for " << name << endl;
476  }
477 
478  if (divSchemes_.found(name) || defaultDivScheme_.empty())
479  {
480  return divSchemes_.lookup(name);
481  }
482  else
483  {
484  const_cast<ITstream&>(defaultDivScheme_).rewind();
485  return const_cast<ITstream&>(defaultDivScheme_);
486  }
487 }
488 
489 
491 {
492  if (debug)
493  {
494  Info<< "Lookup gradScheme for " << name << endl;
495  }
496 
497  if (gradSchemes_.found(name) || defaultGradScheme_.empty())
498  {
499  return gradSchemes_.lookup(name);
500  }
501  else
502  {
503  const_cast<ITstream&>(defaultGradScheme_).rewind();
504  return const_cast<ITstream&>(defaultGradScheme_);
505  }
506 }
507 
508 
510 {
511  if (debug)
512  {
513  Info<< "Lookup snGradScheme for " << name << endl;
514  }
515 
516  if (snGradSchemes_.found(name) || defaultSnGradScheme_.empty())
517  {
518  return snGradSchemes_.lookup(name);
519  }
520  else
521  {
522  const_cast<ITstream&>(defaultSnGradScheme_).rewind();
523  return const_cast<ITstream&>(defaultSnGradScheme_);
524  }
525 }
526 
527 
529 {
530  if (debug)
531  {
532  Info<< "Lookup laplacianScheme for " << name << endl;
533  }
534 
535  if (laplacianSchemes_.found(name) || defaultLaplacianScheme_.empty())
536  {
537  return laplacianSchemes_.lookup(name);
538  }
539  else
540  {
541  const_cast<ITstream&>(defaultLaplacianScheme_).rewind();
542  return const_cast<ITstream&>(defaultLaplacianScheme_);
543  }
544 }
545 
546 
548 {
549  if (debug)
550  {
551  Info<< "Lookup fluxRequired for " << name << endl;
552  }
553 
554  if (fluxRequired_.found(name))
555  {
556  return true;
557  }
558  else
559  {
560  return defaultFluxRequired_;
561  }
562 }
563 
564 
565 bool Foam::fvSchemes::cache(const word& name) const
566 {
567  if (debug)
568  {
569  Info<< "Lookup cache for " << name << endl;
570  }
571 
572  if (cacheFields_.found(name))
573  {
574  return true;
575  }
576  else
577  {
578  return false;
579  }
580 }
581 
582 
583 // ************************ vim: set sw=4 sts=4 et: ************************ //