initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / finiteVolume / fvSchemes / fvSchemes.C
blobf9354e3d8405227954d85ea99c0ecc252c708b5b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
28 #include "Time.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 int Foam::fvSchemes::debug(Foam::debug::debugSwitch("fvSchemes", false));
35 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
37 void Foam::fvSchemes::clear()
39     ddtSchemes_.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;
55     cacheFields_.clear();
58 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
60 Foam::fvSchemes::fvSchemes(const objectRegistry& obr)
62     IOdictionary
63     (
64         IOobject
65         (
66             "fvSchemes",
67             obr.time().system(),
68             obr,
69             IOobject::MUST_READ,
70             IOobject::NO_WRITE
71         )
72     ),
73     ddtSchemes_
74     (
75         ITstream
76         (
77             objectPath() + "::ddtSchemes",
78             tokenList()
79         )()
80     ),
81     defaultDdtScheme_
82     (
83         ddtSchemes_.name() + "::default",
84         tokenList()
85     ),
86     d2dt2Schemes_
87     (
88         ITstream
89         (
90             objectPath() + "::d2dt2Schemes",
91             tokenList()
92         )()
93     ),
94     defaultD2dt2Scheme_
95     (
96         d2dt2Schemes_.name() + "::default",
97         tokenList()
98     ),
99     interpolationSchemes_
100     (
101         ITstream
102         (
103             objectPath() + "::interpolationSchemes",
104             tokenList()
105         )()
106     ),
107     defaultInterpolationScheme_
108     (
109         interpolationSchemes_.name() + "::default",
110         tokenList()
111     ),
112     divSchemes_
113     (
114         ITstream
115         (
116             objectPath() + "::divSchemes",
117             tokenList()
118         )()
119     ),
120     defaultDivScheme_
121     (
122         divSchemes_.name() + "::default",
123         tokenList()
124     ),
125     gradSchemes_
126     (
127         ITstream
128         (
129             objectPath() + "::gradSchemes",
130             tokenList()
131         )()
132     ),
133     defaultGradScheme_
134     (
135         gradSchemes_.name() + "::default",
136         tokenList()
137     ),
138     snGradSchemes_
139     (
140         ITstream
141         (
142             objectPath() + "::snGradSchemes",
143             tokenList()
144         )()
145     ),
146     defaultSnGradScheme_
147     (
148         snGradSchemes_.name() + "::default",
149         tokenList()
150     ),
151     laplacianSchemes_
152     (
153         ITstream
154         (
155             objectPath() + "::laplacianSchemes",
156             tokenList()
157         )()
158     ),
159     defaultLaplacianScheme_
160     (
161         laplacianSchemes_.name() + "::default",
162         tokenList()
163     ),
164     fluxRequired_
165     (
166         ITstream
167         (
168             objectPath() + "::fluxRequired",
169             tokenList()
170         )()
171     ),
172     defaultFluxRequired_(false),
173     cacheFields_
174     (
175         ITstream
176         (
177             objectPath() + "::cacheFields",
178             tokenList()
179         )()
180     )
182     read();
186 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
188 bool Foam::fvSchemes::read()
190     if (regIOobject::read())
191     {
192         const dictionary& dict = schemesDict();
194         // persistent settings across reads is incorrect
195         clear();
197         if (dict.found("ddtSchemes"))
198         {
199             ddtSchemes_ = dict.subDict("ddtSchemes");
200         }
201         else if (dict.found("timeScheme"))
202         {
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'"
207                 << nl << endl;
209             word schemeName(dict.lookup("timeScheme"));
211             if (schemeName == "EulerImplicit")
212             {
213                 schemeName = "Euler";
214             }
215             else if (schemeName == "BackwardDifferencing")
216             {
217                 schemeName = "backward";
218             }
219             else if (schemeName == "SteadyState")
220             {
221                 schemeName = "steadyState";
222             }
223             else
224             {
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);
230             }
232             ddtSchemes_.set("default", schemeName);
234             ddtSchemes_.lookup("default")[0].lineNumber() =
235                 dict.lookup("timeScheme").lineNumber();
236         }
237         else
238         {
239             ddtSchemes_.set("default", "none");
240         }
242         if
243         (
244             ddtSchemes_.found("default")
245          && word(ddtSchemes_.lookup("default")) != "none"
246         )
247         {
248             defaultDdtScheme_ = ddtSchemes_.lookup("default");
249         }
252         if (dict.found("d2dt2Schemes"))
253         {
254             d2dt2Schemes_ = dict.subDict("d2dt2Schemes");
255         }
256         else if (dict.found("timeScheme"))
257         {
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'"
262                 << nl << endl;
264             word schemeName(dict.lookup("timeScheme"));
266             if (schemeName == "EulerImplicit")
267             {
268                 schemeName = "Euler";
269             }
270             else if (schemeName == "SteadyState")
271             {
272                 schemeName = "steadyState";
273             }
275             d2dt2Schemes_.set("default", schemeName);
277             d2dt2Schemes_.lookup("default")[0].lineNumber() =
278                 dict.lookup("timeScheme").lineNumber();
279         }
280         else
281         {
282             d2dt2Schemes_.set("default", "none");
283         }
285         if
286         (
287             d2dt2Schemes_.found("default")
288          && word(d2dt2Schemes_.lookup("default")) != "none"
289         )
290         {
291             defaultD2dt2Scheme_ = d2dt2Schemes_.lookup("default");
292         }
295         if (dict.found("interpolationSchemes"))
296         {
297             interpolationSchemes_ = dict.subDict("interpolationSchemes");
298         }
299         else if (!interpolationSchemes_.found("default"))
300         {
301             interpolationSchemes_.add("default", "linear");
302         }
304         if
305         (
306             interpolationSchemes_.found("default")
307          && word(interpolationSchemes_.lookup("default")) != "none"
308         )
309         {
310             defaultInterpolationScheme_ =
311                 interpolationSchemes_.lookup("default");
312         }
315         divSchemes_ = dict.subDict("divSchemes");
317         if
318         (
319             divSchemes_.found("default")
320          && word(divSchemes_.lookup("default")) != "none"
321         )
322         {
323             defaultDivScheme_ = divSchemes_.lookup("default");
324         }
327         gradSchemes_ = dict.subDict("gradSchemes");
329         if
330         (
331             gradSchemes_.found("default")
332          && word(gradSchemes_.lookup("default")) != "none"
333         )
334         {
335             defaultGradScheme_ = gradSchemes_.lookup("default");
336         }
339         if (dict.found("snGradSchemes"))
340         {
341             snGradSchemes_ = dict.subDict("snGradSchemes");
342         }
343         else if (!snGradSchemes_.found("default"))
344         {
345             snGradSchemes_.add("default", "corrected");
346         }
348         if
349         (
350             snGradSchemes_.found("default")
351          && word(snGradSchemes_.lookup("default")) != "none"
352         )
353         {
354             defaultSnGradScheme_ = snGradSchemes_.lookup("default");
355         }
358         laplacianSchemes_ = dict.subDict("laplacianSchemes");
360         if
361         (
362             laplacianSchemes_.found("default")
363          && word(laplacianSchemes_.lookup("default")) != "none"
364         )
365         {
366             defaultLaplacianScheme_ = laplacianSchemes_.lookup("default");
367         }
370         if (dict.found("fluxRequired"))
371         {
372             fluxRequired_ = dict.subDict("fluxRequired");
374             if
375             (
376                 fluxRequired_.found("default")
377              && word(fluxRequired_.lookup("default")) != "none"
378             )
379             {
380                 defaultFluxRequired_ = Switch(fluxRequired_.lookup("default"));
381             }
382         }
384         if (dict.found("cacheFields"))
385         {
386             cacheFields_ = dict.subDict("cacheFields");
387         }
389         return true;
390     }
391     else
392     {
393         return false;
394     }
398 const Foam::dictionary& Foam::fvSchemes::schemesDict() const
400     if (found("select"))
401     {
402         return subDict(word(lookup("select")));
403     }
404     else
405     {
406         return *this;
407     }
411 Foam::ITstream& Foam::fvSchemes::ddtScheme(const word& name) const
413     if (debug)
414     {
415         Info<< "Lookup ddtScheme for " << name << endl;
416     }
418     if (ddtSchemes_.found(name) || defaultDdtScheme_.empty())
419     {
420         return ddtSchemes_.lookup(name);
421     }
422     else
423     {
424         const_cast<ITstream&>(defaultDdtScheme_).rewind();
425         return const_cast<ITstream&>(defaultDdtScheme_);
426     }
430 Foam::ITstream& Foam::fvSchemes::d2dt2Scheme(const word& name) const
432     if (debug)
433     {
434         Info<< "Lookup d2dt2Scheme for " << name << endl;
435     }
437     if (d2dt2Schemes_.found(name) || defaultD2dt2Scheme_.empty())
438     {
439         return d2dt2Schemes_.lookup(name);
440     }
441     else
442     {
443         const_cast<ITstream&>(defaultD2dt2Scheme_).rewind();
444         return const_cast<ITstream&>(defaultD2dt2Scheme_);
445     }
449 Foam::ITstream& Foam::fvSchemes::interpolationScheme(const word& name) const
451     if (debug)
452     {
453         Info<< "Lookup interpolationScheme for " << name << endl;
454     }
456     if
457     (
458         interpolationSchemes_.found(name)
459      || defaultInterpolationScheme_.empty()
460     )
461     {
462         return interpolationSchemes_.lookup(name);
463     }
464     else
465     {
466         const_cast<ITstream&>(defaultInterpolationScheme_).rewind();
467         return const_cast<ITstream&>(defaultInterpolationScheme_);
468     }
472 Foam::ITstream& Foam::fvSchemes::divScheme(const word& name) const
474     if (debug)
475     {
476         Info<< "Lookup divScheme for " << name << endl;
477     }
479     if (divSchemes_.found(name) || defaultDivScheme_.empty())
480     {
481         return divSchemes_.lookup(name);
482     }
483     else
484     {
485         const_cast<ITstream&>(defaultDivScheme_).rewind();
486         return const_cast<ITstream&>(defaultDivScheme_);
487     }
491 Foam::ITstream& Foam::fvSchemes::gradScheme(const word& name) const
493     if (debug)
494     {
495         Info<< "Lookup gradScheme for " << name << endl;
496     }
498     if (gradSchemes_.found(name) || defaultGradScheme_.empty())
499     {
500         return gradSchemes_.lookup(name);
501     }
502     else
503     {
504         const_cast<ITstream&>(defaultGradScheme_).rewind();
505         return const_cast<ITstream&>(defaultGradScheme_);
506     }
510 Foam::ITstream& Foam::fvSchemes::snGradScheme(const word& name) const
512     if (debug)
513     {
514         Info<< "Lookup snGradScheme for " << name << endl;
515     }
517     if (snGradSchemes_.found(name) || defaultSnGradScheme_.empty())
518     {
519         return snGradSchemes_.lookup(name);
520     }
521     else
522     {
523         const_cast<ITstream&>(defaultSnGradScheme_).rewind();
524         return const_cast<ITstream&>(defaultSnGradScheme_);
525     }
529 Foam::ITstream& Foam::fvSchemes::laplacianScheme(const word& name) const
531     if (debug)
532     {
533         Info<< "Lookup laplacianScheme for " << name << endl;
534     }
536     if (laplacianSchemes_.found(name) || defaultLaplacianScheme_.empty())
537     {
538         return laplacianSchemes_.lookup(name);
539     }
540     else
541     {
542         const_cast<ITstream&>(defaultLaplacianScheme_).rewind();
543         return const_cast<ITstream&>(defaultLaplacianScheme_);
544     }
548 bool Foam::fvSchemes::fluxRequired(const word& name) const
550     if (debug)
551     {
552         Info<< "Lookup fluxRequired for " << name << endl;
553     }
555     if (fluxRequired_.found(name))
556     {
557         return true;
558     }
559     else
560     {
561         return defaultFluxRequired_;
562     }
566 bool Foam::fvSchemes::cache(const word& name) const
568     if (debug)
569     {
570         Info<< "Lookup cache for " << name << endl;
571     }
573     if (cacheFields_.found(name))
574     {
575         return true;
576     }
577     else
578     {
579         return false;
580     }
584 // ************************************************************************* //