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

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