1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "totalPressureFvPatchScalarField.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #include "surfaceFields.H"
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
38 const DimensionedField<scalar, volMesh>& iF
41 fixedValueFvPatchScalarField(p, iF),
51 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
54 const DimensionedField<scalar, volMesh>& iF,
55 const dictionary& dict
58 fixedValueFvPatchScalarField(p, iF),
59 UName_(dict.lookupOrDefault<word>("U", "U")),
60 phiName_(dict.lookupOrDefault<word>("phi", "phi")),
61 rhoName_(dict.lookupOrDefault<word>("rho", "none")),
62 psiName_(dict.lookupOrDefault<word>("psi", "none")),
63 gamma_(readScalar(dict.lookup("gamma"))),
64 p0_("p0", dict, p.size())
66 if (dict.found("value"))
68 fvPatchField<scalar>::operator=
70 scalarField("value", dict, p.size())
75 fvPatchField<scalar>::operator=(p0_);
80 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
82 const totalPressureFvPatchScalarField& ptf,
84 const DimensionedField<scalar, volMesh>& iF,
85 const fvPatchFieldMapper& mapper
88 fixedValueFvPatchScalarField(ptf, p, iF, mapper),
90 phiName_(ptf.phiName_),
91 rhoName_(ptf.rhoName_),
92 psiName_(ptf.psiName_),
98 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
100 const totalPressureFvPatchScalarField& tppsf
103 fixedValueFvPatchScalarField(tppsf),
104 UName_(tppsf.UName_),
105 phiName_(tppsf.phiName_),
106 rhoName_(tppsf.rhoName_),
107 psiName_(tppsf.psiName_),
108 gamma_(tppsf.gamma_),
113 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
115 const totalPressureFvPatchScalarField& tppsf,
116 const DimensionedField<scalar, volMesh>& iF
119 fixedValueFvPatchScalarField(tppsf, iF),
120 UName_(tppsf.UName_),
121 phiName_(tppsf.phiName_),
122 rhoName_(tppsf.rhoName_),
123 psiName_(tppsf.psiName_),
124 gamma_(tppsf.gamma_),
129 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 void Foam::totalPressureFvPatchScalarField::autoMap
133 const fvPatchFieldMapper& m
136 fixedValueFvPatchScalarField::autoMap(m);
141 void Foam::totalPressureFvPatchScalarField::rmap
143 const fvPatchScalarField& ptf,
144 const labelList& addr
147 fixedValueFvPatchScalarField::rmap(ptf, addr);
149 const totalPressureFvPatchScalarField& tiptf =
150 refCast<const totalPressureFvPatchScalarField>(ptf);
152 p0_.rmap(tiptf.p0_, addr);
156 void Foam::totalPressureFvPatchScalarField::updateCoeffs
158 const scalarField& p0p,
159 const vectorField& Up
167 const fvsPatchField<scalar>& phip =
168 patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
170 if (psiName_ == "none" && rhoName_ == "none")
172 operator==(p0p - 0.5*(1.0 - pos(phip))*magSqr(Up));
174 else if (rhoName_ == "none")
176 const fvPatchField<scalar>& psip =
177 patch().lookupPatchField<volScalarField, scalar>(psiName_);
181 scalar gM1ByG = (gamma_ - 1.0)/gamma_;
188 (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
195 operator==(p0p/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
198 else if (psiName_ == "none")
200 const fvPatchField<scalar>& rho =
201 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
203 operator==(p0p - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
209 "totalPressureFvPatchScalarField::updateCoeffs()"
210 ) << " rho or psi set inconsistently, rho = " << rhoName_
211 << ", psi = " << psiName_ << ".\n"
212 << " Set either rho or psi or neither depending on the "
213 "definition of total pressure." << nl
214 << " Set the unused variable(s) to 'none'.\n"
215 << " on patch " << this->patch().name()
216 << " of field " << this->dimensionedInternalField().name()
217 << " in file " << this->dimensionedInternalField().objectPath()
221 fixedValueFvPatchScalarField::updateCoeffs();
225 void Foam::totalPressureFvPatchScalarField::updateCoeffs()
230 patch().lookupPatchField<volVectorField, vector>(UName())
235 void Foam::totalPressureFvPatchScalarField::write(Ostream& os) const
237 fvPatchScalarField::write(os);
238 writeEntryIfDifferent<word>(os, "U", "U", UName_);
239 writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
240 os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
241 os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
242 os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
243 p0_.writeEntry("p0", os);
244 writeEntry("value", os);
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 totalPressureFvPatchScalarField
259 // ************************************************************************* //