1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "fvSchemes.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 int Foam::fvSchemes::debug(Foam::debug::debugSwitch("fvSchemes", false));
35 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
37 void Foam::fvSchemes::clear()
40 defaultDdtScheme_.clear();
41 d2dt2Schemes_.clear();
42 defaultD2dt2Scheme_.clear();
43 interpolationSchemes_.clear();
44 defaultInterpolationScheme_.clear();
45 divSchemes_.clear(); // optional
46 defaultDivScheme_.clear();
47 gradSchemes_.clear(); // optional
48 defaultGradScheme_.clear();
49 snGradSchemes_.clear();
50 defaultSnGradScheme_.clear();
51 laplacianSchemes_.clear(); // optional
52 defaultLaplacianScheme_.clear();
53 fluxRequired_.clear();
54 defaultFluxRequired_ = false;
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 Foam::fvSchemes::fvSchemes(const objectRegistry& obr)
77 objectPath() + "::ddtSchemes",
83 ddtSchemes_.name() + "::default",
90 objectPath() + "::d2dt2Schemes",
96 d2dt2Schemes_.name() + "::default",
103 objectPath() + "::interpolationSchemes",
107 defaultInterpolationScheme_
109 interpolationSchemes_.name() + "::default",
116 objectPath() + "::divSchemes",
122 divSchemes_.name() + "::default",
129 objectPath() + "::gradSchemes",
135 gradSchemes_.name() + "::default",
142 objectPath() + "::snGradSchemes",
148 snGradSchemes_.name() + "::default",
155 objectPath() + "::laplacianSchemes",
159 defaultLaplacianScheme_
161 laplacianSchemes_.name() + "::default",
168 objectPath() + "::fluxRequired",
172 defaultFluxRequired_(false),
177 objectPath() + "::cacheFields",
186 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
188 bool Foam::fvSchemes::read()
190 if (regIOobject::read())
192 const dictionary& dict = schemesDict();
194 // persistent settings across reads is incorrect
197 if (dict.found("ddtSchemes"))
199 ddtSchemes_ = dict.subDict("ddtSchemes");
201 else if (dict.found("timeScheme"))
203 // For backward compatibility.
204 // The timeScheme will be deprecated with warning or removed
205 WarningIn("fvSchemes::read()")
206 << "Using deprecated 'timeScheme' instead of 'ddtSchemes'"
209 word schemeName(dict.lookup("timeScheme"));
211 if (schemeName == "EulerImplicit")
213 schemeName = "Euler";
215 else if (schemeName == "BackwardDifferencing")
217 schemeName = "backward";
219 else if (schemeName == "SteadyState")
221 schemeName = "steadyState";
225 FatalIOErrorIn("fvSchemes::read()", dict.lookup("timeScheme"))
226 << "\n Only EulerImplicit, BackwardDifferencing and "
227 "SteadyState\n are supported by the old timeScheme "
228 "specification.\n Please use ddtSchemes instead."
229 << exit(FatalIOError);
232 ddtSchemes_.set("default", schemeName);
234 ddtSchemes_.lookup("default")[0].lineNumber() =
235 dict.lookup("timeScheme").lineNumber();
239 ddtSchemes_.set("default", "none");
244 ddtSchemes_.found("default")
245 && word(ddtSchemes_.lookup("default")) != "none"
248 defaultDdtScheme_ = ddtSchemes_.lookup("default");
252 if (dict.found("d2dt2Schemes"))
254 d2dt2Schemes_ = dict.subDict("d2dt2Schemes");
256 else if (dict.found("timeScheme"))
258 // For backward compatibility.
259 // The timeScheme will be deprecated with warning or removed
260 WarningIn("fvSchemes::read()")
261 << "Using deprecated 'timeScheme' instead of 'd2dt2Schemes'"
264 word schemeName(dict.lookup("timeScheme"));
266 if (schemeName == "EulerImplicit")
268 schemeName = "Euler";
270 else if (schemeName == "SteadyState")
272 schemeName = "steadyState";
275 d2dt2Schemes_.set("default", schemeName);
277 d2dt2Schemes_.lookup("default")[0].lineNumber() =
278 dict.lookup("timeScheme").lineNumber();
282 d2dt2Schemes_.set("default", "none");
287 d2dt2Schemes_.found("default")
288 && word(d2dt2Schemes_.lookup("default")) != "none"
291 defaultD2dt2Scheme_ = d2dt2Schemes_.lookup("default");
295 if (dict.found("interpolationSchemes"))
297 interpolationSchemes_ = dict.subDict("interpolationSchemes");
299 else if (!interpolationSchemes_.found("default"))
301 interpolationSchemes_.add("default", "linear");
306 interpolationSchemes_.found("default")
307 && word(interpolationSchemes_.lookup("default")) != "none"
310 defaultInterpolationScheme_ =
311 interpolationSchemes_.lookup("default");
315 divSchemes_ = dict.subDict("divSchemes");
319 divSchemes_.found("default")
320 && word(divSchemes_.lookup("default")) != "none"
323 defaultDivScheme_ = divSchemes_.lookup("default");
327 gradSchemes_ = dict.subDict("gradSchemes");
331 gradSchemes_.found("default")
332 && word(gradSchemes_.lookup("default")) != "none"
335 defaultGradScheme_ = gradSchemes_.lookup("default");
339 if (dict.found("snGradSchemes"))
341 snGradSchemes_ = dict.subDict("snGradSchemes");
343 else if (!snGradSchemes_.found("default"))
345 snGradSchemes_.add("default", "corrected");
350 snGradSchemes_.found("default")
351 && word(snGradSchemes_.lookup("default")) != "none"
354 defaultSnGradScheme_ = snGradSchemes_.lookup("default");
358 laplacianSchemes_ = dict.subDict("laplacianSchemes");
362 laplacianSchemes_.found("default")
363 && word(laplacianSchemes_.lookup("default")) != "none"
366 defaultLaplacianScheme_ = laplacianSchemes_.lookup("default");
370 if (dict.found("fluxRequired"))
372 fluxRequired_ = dict.subDict("fluxRequired");
376 fluxRequired_.found("default")
377 && word(fluxRequired_.lookup("default")) != "none"
380 defaultFluxRequired_ = Switch(fluxRequired_.lookup("default"));
384 if (dict.found("cacheFields"))
386 cacheFields_ = dict.subDict("cacheFields");
398 const Foam::dictionary& Foam::fvSchemes::schemesDict() const
402 return subDict(word(lookup("select")));
411 Foam::ITstream& Foam::fvSchemes::ddtScheme(const word& name) const
415 Info<< "Lookup ddtScheme for " << name << endl;
418 if (ddtSchemes_.found(name) || defaultDdtScheme_.empty())
420 return ddtSchemes_.lookup(name);
424 const_cast<ITstream&>(defaultDdtScheme_).rewind();
425 return const_cast<ITstream&>(defaultDdtScheme_);
430 Foam::ITstream& Foam::fvSchemes::d2dt2Scheme(const word& name) const
434 Info<< "Lookup d2dt2Scheme for " << name << endl;
437 if (d2dt2Schemes_.found(name) || defaultD2dt2Scheme_.empty())
439 return d2dt2Schemes_.lookup(name);
443 const_cast<ITstream&>(defaultD2dt2Scheme_).rewind();
444 return const_cast<ITstream&>(defaultD2dt2Scheme_);
449 Foam::ITstream& Foam::fvSchemes::interpolationScheme(const word& name) const
453 Info<< "Lookup interpolationScheme for " << name << endl;
458 interpolationSchemes_.found(name)
459 || defaultInterpolationScheme_.empty()
462 return interpolationSchemes_.lookup(name);
466 const_cast<ITstream&>(defaultInterpolationScheme_).rewind();
467 return const_cast<ITstream&>(defaultInterpolationScheme_);
472 Foam::ITstream& Foam::fvSchemes::divScheme(const word& name) const
476 Info<< "Lookup divScheme for " << name << endl;
479 if (divSchemes_.found(name) || defaultDivScheme_.empty())
481 return divSchemes_.lookup(name);
485 const_cast<ITstream&>(defaultDivScheme_).rewind();
486 return const_cast<ITstream&>(defaultDivScheme_);
491 Foam::ITstream& Foam::fvSchemes::gradScheme(const word& name) const
495 Info<< "Lookup gradScheme for " << name << endl;
498 if (gradSchemes_.found(name) || defaultGradScheme_.empty())
500 return gradSchemes_.lookup(name);
504 const_cast<ITstream&>(defaultGradScheme_).rewind();
505 return const_cast<ITstream&>(defaultGradScheme_);
510 Foam::ITstream& Foam::fvSchemes::snGradScheme(const word& name) const
514 Info<< "Lookup snGradScheme for " << name << endl;
517 if (snGradSchemes_.found(name) || defaultSnGradScheme_.empty())
519 return snGradSchemes_.lookup(name);
523 const_cast<ITstream&>(defaultSnGradScheme_).rewind();
524 return const_cast<ITstream&>(defaultSnGradScheme_);
529 Foam::ITstream& Foam::fvSchemes::laplacianScheme(const word& name) const
533 Info<< "Lookup laplacianScheme for " << name << endl;
536 if (laplacianSchemes_.found(name) || defaultLaplacianScheme_.empty())
538 return laplacianSchemes_.lookup(name);
542 const_cast<ITstream&>(defaultLaplacianScheme_).rewind();
543 return const_cast<ITstream&>(defaultLaplacianScheme_);
548 bool Foam::fvSchemes::fluxRequired(const word& name) const
552 Info<< "Lookup fluxRequired for " << name << endl;
555 if (fluxRequired_.found(name))
561 return defaultFluxRequired_;
566 bool Foam::fvSchemes::cache(const word& name) const
570 Info<< "Lookup cache for " << name << endl;
573 if (cacheFields_.found(name))
584 // ************************************************************************* //