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

timeVaryingMappedTotalPressureFvPatchScalarField.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 "timeVaryingMappedTotalPressureFvPatchScalarField.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 #include <finiteVolume/fvPatchFieldMapper.H>
00029 #include <finiteVolume/volFields.H>
00030 #include <finiteVolume/surfaceFields.H>
00031 
00032 
00033 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00034 
00035 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
00036 timeVaryingMappedTotalPressureFvPatchScalarField
00037 (
00038     const fvPatch& p,
00039     const DimensionedField<scalar, volMesh>& iF
00040 )
00041 :
00042     timeVaryingMappedFixedValueFvPatchScalarField(p, iF),
00043     UName_("U"),
00044     phiName_("phi"),
00045     rhoName_("none"),
00046     rho_(1),
00047     psiName_("none"),
00048     gamma_(0.0)
00049 {}
00050 
00051 
00052 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
00053 timeVaryingMappedTotalPressureFvPatchScalarField
00054 (
00055     const fvPatch& p,
00056     const DimensionedField<scalar, volMesh>& iF,
00057     const dictionary& dict
00058 )
00059 :
00060     timeVaryingMappedFixedValueFvPatchScalarField(p, iF, dict),
00061     UName_(dict.lookupOrDefault<word>("UName", "U")),
00062     phiName_(dict.lookupOrDefault<word>("phiName", "phi")),
00063     rhoName_(dict.lookupOrDefault<word>("rhoName", "none")),
00064     rho_
00065     (
00066         iF.dimensions() == dimPressure/dimDensity && rhoName_ == "rho"
00067         ? readScalar(dict.lookup("rho"))
00068         : 1
00069     ),
00070     psiName_(dict.lookupOrDefault<word>("psiName", "none")),
00071     gamma_
00072     (
00073         iF.dimensions() == dimPressure && psiName_ != "none"
00074         ? readScalar(dict.lookup("gamma"))
00075         : 1
00076     )
00077 {}
00078 
00079 
00080 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
00081 timeVaryingMappedTotalPressureFvPatchScalarField
00082 (
00083     const timeVaryingMappedTotalPressureFvPatchScalarField& ptf,
00084     const fvPatch& p,
00085     const DimensionedField<scalar, volMesh>& iF,
00086     const fvPatchFieldMapper& mapper
00087 )
00088 :
00089     timeVaryingMappedFixedValueFvPatchScalarField(ptf, p, iF, mapper),
00090     UName_(ptf.UName_),
00091     phiName_(ptf.phiName_),
00092     rhoName_(ptf.rhoName_),
00093     rho_(ptf.rho_),
00094     psiName_(ptf.psiName_),
00095     gamma_(ptf.gamma_)
00096 {}
00097 
00098 
00099 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
00100 timeVaryingMappedTotalPressureFvPatchScalarField
00101 (
00102     const timeVaryingMappedTotalPressureFvPatchScalarField& tppsf
00103 )
00104 :
00105     timeVaryingMappedFixedValueFvPatchScalarField(tppsf),
00106     UName_(tppsf.UName_),
00107     phiName_(tppsf.phiName_),
00108     rhoName_(tppsf.rhoName_),
00109     rho_(tppsf.rho_),
00110     psiName_(tppsf.psiName_),
00111     gamma_(tppsf.gamma_)
00112 {}
00113 
00114 
00115 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
00116 timeVaryingMappedTotalPressureFvPatchScalarField
00117 (
00118     const timeVaryingMappedTotalPressureFvPatchScalarField& tppsf,
00119     const DimensionedField<scalar, volMesh>& iF
00120 )
00121 :
00122     timeVaryingMappedFixedValueFvPatchScalarField(tppsf, iF),
00123     UName_(tppsf.UName_),
00124     phiName_(tppsf.phiName_),
00125     rhoName_(tppsf.rhoName_),
00126     rho_(tppsf.rho_),
00127     psiName_(tppsf.psiName_),
00128     gamma_(tppsf.gamma_)
00129 {}
00130 
00131 
00132 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00133 
00134 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::autoMap
00135 (
00136     const fvPatchFieldMapper& m
00137 )
00138 {
00139     timeVaryingMappedFixedValueFvPatchScalarField::autoMap(m);
00140 }
00141 
00142 
00143 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::rmap
00144 (
00145     const fvPatchScalarField& ptf,
00146     const labelList& addr
00147 )
00148 {
00149     timeVaryingMappedFixedValueFvPatchScalarField::rmap(ptf, addr);
00150 }
00151 
00152 
00153 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::updateCoeffs
00154 (
00155     const vectorField& Up
00156 )
00157 {
00158     if (updated())
00159     {
00160         return;
00161     }
00162 
00163     // Map the total-pressure field onto this field
00164     timeVaryingMappedFixedValueFvPatchScalarField::updateCoeffs();
00165     const scalarField p0 = *this;
00166 
00167     const fvsPatchField<scalar>& phip =
00168         patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
00169 
00170     if (dimensionedInternalField().dimensions() == dimPressure/dimDensity)
00171     {
00172         if (rhoName_ == "none")
00173         {
00174             operator==(p0 - 0.5*(1.0 - pos(phip))*magSqr(Up));
00175         }
00176         else if (rhoName_ == "rho")
00177         {
00178             operator==(p0/rho_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
00179         }
00180         else
00181         {
00182             FatalErrorIn
00183             (
00184                 "timeVaryingMappedTotalPressureFvPatchScalarField::"
00185                 "updateCoeffs()"
00186             )   << " rhoName set inconsistently, rhoName = " << rhoName_
00187                 << ".\n"
00188                 << "    Set rhoName to 'rho' or 'none' depending on the "
00189                    "definition of total pressure." << nl
00190                 << "    on patch " << this->patch().name()
00191                 << " of field " << this->dimensionedInternalField().name()
00192                 << " in file " << this->dimensionedInternalField().objectPath()
00193                 << exit(FatalError);
00194         }
00195     }
00196     else if (dimensionedInternalField().dimensions() == dimPressure)
00197     {
00198         if (rhoName_ != "none")
00199         {
00200             const fvPatchField<scalar>& rho =
00201                 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
00202 
00203             operator==(p0 - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
00204         }
00205         else if (psiName_ != "none")
00206         {
00207             const fvPatchField<scalar>& psip =
00208                 patch().lookupPatchField<volScalarField, scalar>(psiName_);
00209 
00210             if (gamma_ > 1.0)
00211             {
00212                 scalar gM1ByG = (gamma_ - 1.0)/gamma_;
00213 
00214                 operator==
00215                 (
00216                     p0
00217                     /pow
00218                     (
00219                         (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
00220                         1.0/gM1ByG
00221                     )
00222                 );
00223             }
00224             else
00225             {
00226                 operator==(p0/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
00227             }
00228         }
00229         else
00230         {
00231             FatalErrorIn
00232             (
00233                 "timeVaryingMappedTotalPressureFvPatchScalarField::"
00234                 "updateCoeffs()"
00235             )   << " rhoName or psiName set inconsistently, rhoName = "
00236                 << rhoName_ << ", psiName = " << psiName_ << ".\n"
00237                 << "    Set either rhoName or psiName depending on the "
00238                    "definition of total pressure." << nl
00239                 << "    Set the unused variable(s) to 'none'.\n"
00240                 << "    on patch " << this->patch().name()
00241                 << " of field " << this->dimensionedInternalField().name()
00242                 << " in file " << this->dimensionedInternalField().objectPath()
00243                 << exit(FatalError);
00244         }
00245     }
00246     else
00247     {
00248         FatalErrorIn
00249         (
00250             "timeVaryingMappedTotalPressureFvPatchScalarField::updateCoeffs()"
00251         )   << "Incorrect dimensions for pressure "
00252             << dimensionedInternalField().dimensions()
00253             << "    Should be either " << dimPressure
00254             << " for compressible/variable density flow\n"
00255             << "    or " << dimPressure/dimDensity
00256             << " for incompressible flow.\n"
00257             << "    on patch " << this->patch().name()
00258             << " of field " << this->dimensionedInternalField().name()
00259             << " in file " << this->dimensionedInternalField().objectPath()
00260             << exit(FatalError);
00261     }
00262 }
00263 
00264 
00265 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::updateCoeffs()
00266 {
00267     updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
00268 }
00269 
00270 
00271 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::write
00272 (
00273     Ostream& os
00274 ) const
00275 {
00276     writeEntryIfDifferent<word>(os, "UName", "U", UName_);
00277     writeEntryIfDifferent<word>(os, "phiName", "phi", phiName_);
00278     os.writeKeyword("rhoName") << rhoName_ << token::END_STATEMENT << nl;
00279     os.writeKeyword("rho") << rho_ << token::END_STATEMENT << nl;
00280     os.writeKeyword("psiName") << psiName_ << token::END_STATEMENT << nl;
00281     os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
00282     timeVaryingMappedFixedValueFvPatchScalarField::write(os);
00283 }
00284 
00285 
00286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00287 
00288 namespace Foam
00289 {
00290     makePatchTypeField
00291     (
00292         fvPatchScalarField,
00293         timeVaryingMappedTotalPressureFvPatchScalarField
00294     );
00295 }
00296 
00297 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines