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

staticPressure.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) 2009-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 "staticPressure.H"
00028 #include "volFields.H"
00029 #include "dictionary.H"
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035     defineTypeNameAndDebug(staticPressure, 0);
00036 }
00037 
00038 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00039 
00040 bool Foam::staticPressure::isKinematicPressure()
00041 {
00042     const volScalarField& p = obr_.lookupObject<volScalarField>(pName_);
00043 
00044     return p.dimensions() == sqr(dimLength)/sqr(dimTime);
00045 }
00046 
00047 
00048 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00049 
00050 Foam::staticPressure::staticPressure
00051 (
00052     const word& name,
00053     const objectRegistry& obr,
00054     const dictionary& dict,
00055     const bool loadFromFiles
00056 )
00057 :
00058     name_(name),
00059     obr_(obr),
00060     active_(true),
00061     pName_(dict.lookupOrDefault<word>("p", "p")),
00062     rho_(readScalar(dict.lookup("rho")))
00063 {
00064     // Check if the available mesh is an fvMesh, otherwise deactivate
00065     if (!isA<fvMesh>(obr_))
00066     {
00067         active_ = false;
00068         WarningIn
00069         (
00070             "staticPressure::staticPressure"
00071             "(const objectRegistry&, const dictionary&)"
00072         )   << "No fvMesh available, deactivating." << nl
00073             << endl;
00074     }
00075     else
00076     {
00077         // Check if the pressure is kinematic pressure, otherwise deactivate
00078         if (!isKinematicPressure())
00079         {
00080             active_ = false;
00081             WarningIn
00082             (
00083                 "staticPressure::staticPressure"
00084                 "(const objectRegistry&, const dictionary&)"
00085             )   << "Pressure is not kinematic pressure, deactivating." << nl
00086                 << endl;
00087         }
00088     }
00089 
00090     read(dict);
00091 }
00092 
00093 
00094 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00095 
00096 Foam::staticPressure::~staticPressure()
00097 {}
00098 
00099 
00100 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00101 
00102 void Foam::staticPressure::read(const dictionary& dict)
00103 {
00104     if (active_)
00105     {
00106         dict.readIfPresent("p", pName_);
00107         dict.lookup("rho") >> rho_;
00108     }
00109 }
00110 
00111 
00112 void Foam::staticPressure::execute()
00113 {
00114     // Do nothing - only valid on write
00115 }
00116 
00117 
00118 void Foam::staticPressure::end()
00119 {
00120     // Do nothing - only valid on write
00121 }
00122 
00123 
00124 void Foam::staticPressure::write()
00125 {
00126     if (active_)
00127     {
00128         const volScalarField& p = obr_.lookupObject<volScalarField>(pName_);
00129 
00130         volScalarField pStatic
00131         (
00132             IOobject
00133             (
00134                 "pStatic",
00135                 obr_.time().timeName(),
00136                 obr_,
00137                 IOobject::NO_READ
00138             ),
00139             dimensionedScalar("rho", dimDensity, rho_)*p
00140         );
00141 
00142         pStatic.write();
00143     }
00144 }
00145 
00146 
00147 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd