OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

fvSchemes.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "fvSchemes.H"
00028 #include "Time.H"
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 
00033 int Foam::fvSchemes::debug(Foam::debug::debugSwitch("fvSchemes", false));
00034 
00035 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
00036 
00037 void Foam::fvSchemes::clear()
00038 {
00039     ddtSchemes_.clear();
00040     defaultDdtScheme_.clear();
00041     d2dt2Schemes_.clear();
00042     defaultD2dt2Scheme_.clear();
00043     interpolationSchemes_.clear();
00044     defaultInterpolationScheme_.clear();
00045     divSchemes_.clear(); // optional
00046     defaultDivScheme_.clear();
00047     gradSchemes_.clear(); // optional
00048     defaultGradScheme_.clear();
00049     snGradSchemes_.clear();
00050     defaultSnGradScheme_.clear();
00051     laplacianSchemes_.clear(); // optional
00052     defaultLaplacianScheme_.clear();
00053     fluxRequired_.clear();
00054     defaultFluxRequired_ = false;
00055     cacheFields_.clear();
00056 }
00057 
00058 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00059 
00060 Foam::fvSchemes::fvSchemes(const objectRegistry& obr)
00061 :
00062     IOdictionary
00063     (
00064         IOobject
00065         (
00066             "fvSchemes",
00067             obr.time().system(),
00068             obr,
00069             IOobject::MUST_READ,
00070             IOobject::NO_WRITE
00071         )
00072     ),
00073     ddtSchemes_
00074     (
00075         ITstream
00076         (
00077             objectPath() + "::ddtSchemes",
00078             tokenList()
00079         )()
00080     ),
00081     defaultDdtScheme_
00082     (
00083         ddtSchemes_.name() + "::default",
00084         tokenList()
00085     ),
00086     d2dt2Schemes_
00087     (
00088         ITstream
00089         (
00090             objectPath() + "::d2dt2Schemes",
00091             tokenList()
00092         )()
00093     ),
00094     defaultD2dt2Scheme_
00095     (
00096         d2dt2Schemes_.name() + "::default",
00097         tokenList()
00098     ),
00099     interpolationSchemes_
00100     (
00101         ITstream
00102         (
00103             objectPath() + "::interpolationSchemes",
00104             tokenList()
00105         )()
00106     ),
00107     defaultInterpolationScheme_
00108     (
00109         interpolationSchemes_.name() + "::default",
00110         tokenList()
00111     ),
00112     divSchemes_
00113     (
00114         ITstream
00115         (
00116             objectPath() + "::divSchemes",
00117             tokenList()
00118         )()
00119     ),
00120     defaultDivScheme_
00121     (
00122         divSchemes_.name() + "::default",
00123         tokenList()
00124     ),
00125     gradSchemes_
00126     (
00127         ITstream
00128         (
00129             objectPath() + "::gradSchemes",
00130             tokenList()
00131         )()
00132     ),
00133     defaultGradScheme_
00134     (
00135         gradSchemes_.name() + "::default",
00136         tokenList()
00137     ),
00138     snGradSchemes_
00139     (
00140         ITstream
00141         (
00142             objectPath() + "::snGradSchemes",
00143             tokenList()
00144         )()
00145     ),
00146     defaultSnGradScheme_
00147     (
00148         snGradSchemes_.name() + "::default",
00149         tokenList()
00150     ),
00151     laplacianSchemes_
00152     (
00153         ITstream
00154         (
00155             objectPath() + "::laplacianSchemes",
00156             tokenList()
00157         )()
00158     ),
00159     defaultLaplacianScheme_
00160     (
00161         laplacianSchemes_.name() + "::default",
00162         tokenList()
00163     ),
00164     fluxRequired_
00165     (
00166         ITstream
00167         (
00168             objectPath() + "::fluxRequired",
00169             tokenList()
00170         )()
00171     ),
00172     defaultFluxRequired_(false),
00173     cacheFields_
00174     (
00175         ITstream
00176         (
00177             objectPath() + "::cacheFields",
00178             tokenList()
00179         )()
00180     )
00181 {
00182     read();
00183 }
00184 
00185 
00186 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00187 
00188 bool Foam::fvSchemes::read()
00189 {
00190     if (regIOobject::read())
00191     {
00192         const dictionary& dict = schemesDict();
00193 
00194         // persistent settings across reads is incorrect
00195         clear();
00196 
00197         if (dict.found("ddtSchemes"))
00198         {
00199             ddtSchemes_ = dict.subDict("ddtSchemes");
00200         }
00201         else if (dict.found("timeScheme"))
00202         {
00203             // For backward compatibility.
00204             // The timeScheme will be deprecated with warning or removed
00205             WarningIn("fvSchemes::read()")
00206                 << "Using deprecated 'timeScheme' instead of 'ddtSchemes'"
00207                 << nl << endl;
00208 
00209             word schemeName(dict.lookup("timeScheme"));
00210 
00211             if (schemeName == "EulerImplicit")
00212             {
00213                 schemeName = "Euler";
00214             }
00215             else if (schemeName == "BackwardDifferencing")
00216             {
00217                 schemeName = "backward";
00218             }
00219             else if (schemeName == "SteadyState")
00220             {
00221                 schemeName = "steadyState";
00222             }
00223             else
00224             {
00225                 FatalIOErrorIn("fvSchemes::read()", dict.lookup("timeScheme"))
00226                     << "\n    Only EulerImplicit, BackwardDifferencing and "
00227                        "SteadyState\n    are supported by the old timeScheme "
00228                        "specification.\n    Please use ddtSchemes instead."
00229                     << exit(FatalIOError);
00230             }
00231 
00232             ddtSchemes_.set("default", schemeName);
00233 
00234             ddtSchemes_.lookup("default")[0].lineNumber() =
00235                 dict.lookup("timeScheme").lineNumber();
00236         }
00237         else
00238         {
00239             ddtSchemes_.set("default", "none");
00240         }
00241 
00242         if
00243         (
00244             ddtSchemes_.found("default")
00245          && word(ddtSchemes_.lookup("default")) != "none"
00246         )
00247         {
00248             defaultDdtScheme_ = ddtSchemes_.lookup("default");
00249         }
00250 
00251 
00252         if (dict.found("d2dt2Schemes"))
00253         {
00254             d2dt2Schemes_ = dict.subDict("d2dt2Schemes");
00255         }
00256         else if (dict.found("timeScheme"))
00257         {
00258             // For backward compatibility.
00259             // The timeScheme will be deprecated with warning or removed
00260             WarningIn("fvSchemes::read()")
00261                 << "Using deprecated 'timeScheme' instead of 'd2dt2Schemes'"
00262                 << nl << endl;
00263 
00264             word schemeName(dict.lookup("timeScheme"));
00265 
00266             if (schemeName == "EulerImplicit")
00267             {
00268                 schemeName = "Euler";
00269             }
00270             else if (schemeName == "SteadyState")
00271             {
00272                 schemeName = "steadyState";
00273             }
00274 
00275             d2dt2Schemes_.set("default", schemeName);
00276 
00277             d2dt2Schemes_.lookup("default")[0].lineNumber() =
00278                 dict.lookup("timeScheme").lineNumber();
00279         }
00280         else
00281         {
00282             d2dt2Schemes_.set("default", "none");
00283         }
00284 
00285         if
00286         (
00287             d2dt2Schemes_.found("default")
00288          && word(d2dt2Schemes_.lookup("default")) != "none"
00289         )
00290         {
00291             defaultD2dt2Scheme_ = d2dt2Schemes_.lookup("default");
00292         }
00293 
00294 
00295         if (dict.found("interpolationSchemes"))
00296         {
00297             interpolationSchemes_ = dict.subDict("interpolationSchemes");
00298         }
00299         else if (!interpolationSchemes_.found("default"))
00300         {
00301             interpolationSchemes_.add("default", "linear");
00302         }
00303 
00304         if
00305         (
00306             interpolationSchemes_.found("default")
00307          && word(interpolationSchemes_.lookup("default")) != "none"
00308         )
00309         {
00310             defaultInterpolationScheme_ =
00311                 interpolationSchemes_.lookup("default");
00312         }
00313 
00314 
00315         divSchemes_ = dict.subDict("divSchemes");
00316 
00317         if
00318         (
00319             divSchemes_.found("default")
00320          && word(divSchemes_.lookup("default")) != "none"
00321         )
00322         {
00323             defaultDivScheme_ = divSchemes_.lookup("default");
00324         }
00325 
00326 
00327         gradSchemes_ = dict.subDict("gradSchemes");
00328 
00329         if
00330         (
00331             gradSchemes_.found("default")
00332          && word(gradSchemes_.lookup("default")) != "none"
00333         )
00334         {
00335             defaultGradScheme_ = gradSchemes_.lookup("default");
00336         }
00337 
00338 
00339         if (dict.found("snGradSchemes"))
00340         {
00341             snGradSchemes_ = dict.subDict("snGradSchemes");
00342         }
00343         else if (!snGradSchemes_.found("default"))
00344         {
00345             snGradSchemes_.add("default", "corrected");
00346         }
00347 
00348         if
00349         (
00350             snGradSchemes_.found("default")
00351          && word(snGradSchemes_.lookup("default")) != "none"
00352         )
00353         {
00354             defaultSnGradScheme_ = snGradSchemes_.lookup("default");
00355         }
00356 
00357 
00358         laplacianSchemes_ = dict.subDict("laplacianSchemes");
00359 
00360         if
00361         (
00362             laplacianSchemes_.found("default")
00363          && word(laplacianSchemes_.lookup("default")) != "none"
00364         )
00365         {
00366             defaultLaplacianScheme_ = laplacianSchemes_.lookup("default");
00367         }
00368 
00369 
00370         if (dict.found("fluxRequired"))
00371         {
00372             fluxRequired_ = dict.subDict("fluxRequired");
00373 
00374             if
00375             (
00376                 fluxRequired_.found("default")
00377              && word(fluxRequired_.lookup("default")) != "none"
00378             )
00379             {
00380                 defaultFluxRequired_ = Switch(fluxRequired_.lookup("default"));
00381             }
00382         }
00383 
00384         if (dict.found("cacheFields"))
00385         {
00386             cacheFields_ = dict.subDict("cacheFields");
00387         }
00388 
00389         return true;
00390     }
00391     else
00392     {
00393         return false;
00394     }
00395 }
00396 
00397 
00398 const Foam::dictionary& Foam::fvSchemes::schemesDict() const
00399 {
00400     if (found("select"))
00401     {
00402         return subDict(word(lookup("select")));
00403     }
00404     else
00405     {
00406         return *this;
00407     }
00408 }
00409 
00410 
00411 Foam::ITstream& Foam::fvSchemes::ddtScheme(const word& name) const
00412 {
00413     if (debug)
00414     {
00415         Info<< "Lookup ddtScheme for " << name << endl;
00416     }
00417 
00418     if (ddtSchemes_.found(name) || defaultDdtScheme_.empty())
00419     {
00420         return ddtSchemes_.lookup(name);
00421     }
00422     else
00423     {
00424         const_cast<ITstream&>(defaultDdtScheme_).rewind();
00425         return const_cast<ITstream&>(defaultDdtScheme_);
00426     }
00427 }
00428 
00429 
00430 Foam::ITstream& Foam::fvSchemes::d2dt2Scheme(const word& name) const
00431 {
00432     if (debug)
00433     {
00434         Info<< "Lookup d2dt2Scheme for " << name << endl;
00435     }
00436 
00437     if (d2dt2Schemes_.found(name) || defaultD2dt2Scheme_.empty())
00438     {
00439         return d2dt2Schemes_.lookup(name);
00440     }
00441     else
00442     {
00443         const_cast<ITstream&>(defaultD2dt2Scheme_).rewind();
00444         return const_cast<ITstream&>(defaultD2dt2Scheme_);
00445     }
00446 }
00447 
00448 
00449 Foam::ITstream& Foam::fvSchemes::interpolationScheme(const word& name) const
00450 {
00451     if (debug)
00452     {
00453         Info<< "Lookup interpolationScheme for " << name << endl;
00454     }
00455 
00456     if
00457     (
00458         interpolationSchemes_.found(name)
00459      || defaultInterpolationScheme_.empty()
00460     )
00461     {
00462         return interpolationSchemes_.lookup(name);
00463     }
00464     else
00465     {
00466         const_cast<ITstream&>(defaultInterpolationScheme_).rewind();
00467         return const_cast<ITstream&>(defaultInterpolationScheme_);
00468     }
00469 }
00470 
00471 
00472 Foam::ITstream& Foam::fvSchemes::divScheme(const word& name) const
00473 {
00474     if (debug)
00475     {
00476         Info<< "Lookup divScheme for " << name << endl;
00477     }
00478 
00479     if (divSchemes_.found(name) || defaultDivScheme_.empty())
00480     {
00481         return divSchemes_.lookup(name);
00482     }
00483     else
00484     {
00485         const_cast<ITstream&>(defaultDivScheme_).rewind();
00486         return const_cast<ITstream&>(defaultDivScheme_);
00487     }
00488 }
00489 
00490 
00491 Foam::ITstream& Foam::fvSchemes::gradScheme(const word& name) const
00492 {
00493     if (debug)
00494     {
00495         Info<< "Lookup gradScheme for " << name << endl;
00496     }
00497 
00498     if (gradSchemes_.found(name) || defaultGradScheme_.empty())
00499     {
00500         return gradSchemes_.lookup(name);
00501     }
00502     else
00503     {
00504         const_cast<ITstream&>(defaultGradScheme_).rewind();
00505         return const_cast<ITstream&>(defaultGradScheme_);
00506     }
00507 }
00508 
00509 
00510 Foam::ITstream& Foam::fvSchemes::snGradScheme(const word& name) const
00511 {
00512     if (debug)
00513     {
00514         Info<< "Lookup snGradScheme for " << name << endl;
00515     }
00516 
00517     if (snGradSchemes_.found(name) || defaultSnGradScheme_.empty())
00518     {
00519         return snGradSchemes_.lookup(name);
00520     }
00521     else
00522     {
00523         const_cast<ITstream&>(defaultSnGradScheme_).rewind();
00524         return const_cast<ITstream&>(defaultSnGradScheme_);
00525     }
00526 }
00527 
00528 
00529 Foam::ITstream& Foam::fvSchemes::laplacianScheme(const word& name) const
00530 {
00531     if (debug)
00532     {
00533         Info<< "Lookup laplacianScheme for " << name << endl;
00534     }
00535 
00536     if (laplacianSchemes_.found(name) || defaultLaplacianScheme_.empty())
00537     {
00538         return laplacianSchemes_.lookup(name);
00539     }
00540     else
00541     {
00542         const_cast<ITstream&>(defaultLaplacianScheme_).rewind();
00543         return const_cast<ITstream&>(defaultLaplacianScheme_);
00544     }
00545 }
00546 
00547 
00548 bool Foam::fvSchemes::fluxRequired(const word& name) const
00549 {
00550     if (debug)
00551     {
00552         Info<< "Lookup fluxRequired for " << name << endl;
00553     }
00554 
00555     if (fluxRequired_.found(name))
00556     {
00557         return true;
00558     }
00559     else
00560     {
00561         return defaultFluxRequired_;
00562     }
00563 }
00564 
00565 
00566 bool Foam::fvSchemes::cache(const word& name) const
00567 {
00568     if (debug)
00569     {
00570         Info<< "Lookup cache for " << name << endl;
00571     }
00572 
00573     if (cacheFields_.found(name))
00574     {
00575         return true;
00576     }
00577     else
00578     {
00579         return false;
00580     }
00581 }
00582 
00583 
00584 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd