FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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