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

timeVaryingUniformTotalPressureFvPatchScalarField.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 "timeVaryingUniformTotalPressureFvPatchScalarField.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 #include <finiteVolume/fvPatchFieldMapper.H>
00029 #include <finiteVolume/volFields.H>
00030 #include <finiteVolume/surfaceFields.H>
00031 
00032 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00033 
00034 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
00035 timeVaryingUniformTotalPressureFvPatchScalarField
00036 (
00037     const fvPatch& p,
00038     const DimensionedField<scalar, volMesh>& iF
00039 )
00040 :
00041     fixedValueFvPatchScalarField(p, iF),
00042     UName_("U"),
00043     phiName_("phi"),
00044     rhoName_("none"),
00045     psiName_("none"),
00046     gamma_(0.0),
00047     p0_(0.0),
00048     timeSeries_()
00049 {}
00050 
00051 
00052 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
00053 timeVaryingUniformTotalPressureFvPatchScalarField
00054 (
00055     const fvPatch& p,
00056     const DimensionedField<scalar, volMesh>& iF,
00057     const dictionary& dict
00058 )
00059 :
00060     fixedValueFvPatchScalarField(p, iF),
00061     UName_(dict.lookupOrDefault<word>("U", "U")),
00062     phiName_(dict.lookupOrDefault<word>("phi", "phi")),
00063     rhoName_(dict.lookupOrDefault<word>("rho", "none")),
00064     psiName_(dict.lookupOrDefault<word>("psi", "none")),
00065     gamma_(readScalar(dict.lookup("gamma"))),
00066     p0_(readScalar(dict.lookup("p0"))),
00067     timeSeries_(dict)
00068 {
00069     if (dict.found("value"))
00070     {
00071         fvPatchField<scalar>::operator=
00072         (
00073             scalarField("value", dict, p.size())
00074         );
00075     }
00076     else
00077     {
00078         fvPatchField<scalar>::operator=(p0_);
00079     }
00080 }
00081 
00082 
00083 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
00084 timeVaryingUniformTotalPressureFvPatchScalarField
00085 (
00086     const timeVaryingUniformTotalPressureFvPatchScalarField& ptf,
00087     const fvPatch& p,
00088     const DimensionedField<scalar, volMesh>& iF,
00089     const fvPatchFieldMapper& mapper
00090 )
00091 :
00092     fixedValueFvPatchScalarField(ptf, p, iF, mapper),
00093     UName_(ptf.UName_),
00094     phiName_(ptf.phiName_),
00095     rhoName_(ptf.rhoName_),
00096     psiName_(ptf.psiName_),
00097     gamma_(ptf.gamma_),
00098     p0_(ptf.p0_),
00099     timeSeries_(ptf.timeSeries_)
00100 {}
00101 
00102 
00103 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
00104 timeVaryingUniformTotalPressureFvPatchScalarField
00105 (
00106     const timeVaryingUniformTotalPressureFvPatchScalarField& tppsf
00107 )
00108 :
00109     fixedValueFvPatchScalarField(tppsf),
00110     UName_(tppsf.UName_),
00111     phiName_(tppsf.phiName_),
00112     rhoName_(tppsf.rhoName_),
00113     psiName_(tppsf.psiName_),
00114     gamma_(tppsf.gamma_),
00115     p0_(tppsf.p0_),
00116     timeSeries_(tppsf.timeSeries_)
00117 {}
00118 
00119 
00120 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
00121 timeVaryingUniformTotalPressureFvPatchScalarField
00122 (
00123     const timeVaryingUniformTotalPressureFvPatchScalarField& tppsf,
00124     const DimensionedField<scalar, volMesh>& iF
00125 )
00126 :
00127     fixedValueFvPatchScalarField(tppsf, iF),
00128     UName_(tppsf.UName_),
00129     phiName_(tppsf.phiName_),
00130     rhoName_(tppsf.rhoName_),
00131     psiName_(tppsf.psiName_),
00132     gamma_(tppsf.gamma_),
00133     p0_(tppsf.p0_),
00134     timeSeries_(tppsf.timeSeries_)
00135 {}
00136 
00137 
00138 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00139 
00140 void Foam::timeVaryingUniformTotalPressureFvPatchScalarField::updateCoeffs
00141 (
00142     const vectorField& Up
00143 )
00144 {
00145     if (updated())
00146     {
00147         return;
00148     }
00149 
00150     p0_ = timeSeries_(this->db().time().timeOutputValue());
00151 
00152     const fvsPatchField<scalar>& phip =
00153         patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
00154 
00155     if (psiName_ == "none" && rhoName_ == "none")
00156     {
00157         operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
00158     }
00159     else if (rhoName_ == "none")
00160     {
00161         const fvPatchField<scalar>& psip =
00162             patch().lookupPatchField<volScalarField, scalar>(psiName_);
00163 
00164         if (gamma_ > 1.0)
00165         {
00166             scalar gM1ByG = (gamma_ - 1.0)/gamma_;
00167 
00168             operator==
00169             (
00170                 p0_
00171                /pow
00172                 (
00173                     (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
00174                     1.0/gM1ByG
00175                 )
00176             );
00177         }
00178         else
00179         {
00180             operator==(p0_/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
00181         }
00182     }
00183     else if (psiName_ == "none")
00184     {
00185         const fvPatchField<scalar>& rho =
00186             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
00187 
00188         operator==(p0_ - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
00189     }
00190     else
00191     {
00192         FatalErrorIn
00193         (
00194             "timeVaryingUniformTotalPressureFvPatchScalarField::updateCoeffs()"
00195         )   << " rho or psi set inconsitently, rho = " << rhoName_
00196             << ", psi = " << psiName_ << ".\n"
00197             << "    Set either rho or psi or neither depending on the "
00198                "definition of total pressure.\n"
00199             << "    Set the unused variables to 'none'.\n"
00200             << "    on patch " << this->patch().name()
00201             << " of field " << this->dimensionedInternalField().name()
00202             << " in file " << this->dimensionedInternalField().objectPath()
00203             << exit(FatalError);
00204     }
00205 
00206     fixedValueFvPatchScalarField::updateCoeffs();
00207 }
00208 
00209 
00210 void Foam::timeVaryingUniformTotalPressureFvPatchScalarField::updateCoeffs()
00211 {
00212     updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
00213 }
00214 
00215 
00216 void Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
00217 write(Ostream& os) const
00218 {
00219     fvPatchScalarField::write(os);
00220     if (UName_ != "U")
00221     {
00222         os.writeKeyword("U") << UName_ << token::END_STATEMENT << nl;
00223     }
00224     if (phiName_ != "phi")
00225     {
00226         os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
00227     }
00228     os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
00229     os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
00230     os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
00231     os.writeKeyword("p0") << p0_ << token::END_STATEMENT << nl;
00232     timeSeries_.write(os);
00233     writeEntry("value", os);
00234 }
00235 
00236 
00237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00238 
00239 namespace Foam
00240 {
00241     makePatchTypeField
00242     (
00243         fvPatchScalarField,
00244         timeVaryingUniformTotalPressureFvPatchScalarField
00245     );
00246 }
00247 
00248 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines