1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "totalPressureFvPatchScalarField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #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(const vectorField& Up)
163 const fvsPatchField<scalar>& phip =
164 patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
166 if (psiName_ == "none" && rhoName_ == "none")
168 operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
170 else if (rhoName_ == "none")
172 const fvPatchField<scalar>& psip =
173 patch().lookupPatchField<volScalarField, scalar>(psiName_);
177 scalar gM1ByG = (gamma_ - 1.0)/gamma_;
184 (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
191 operator==(p0_/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
194 else if (psiName_ == "none")
196 const fvPatchField<scalar>& rho =
197 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
199 operator==(p0_ - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
205 "totalPressureFvPatchScalarField::updateCoeffs()"
206 ) << " rho or psi set inconsistently, rho = " << rhoName_
207 << ", psi = " << psiName_ << ".\n"
208 << " Set either rho or psi or neither depending on the "
209 "definition of total pressure." << nl
210 << " Set the unused variable(s) to 'none'.\n"
211 << " on patch " << this->patch().name()
212 << " of field " << this->dimensionedInternalField().name()
213 << " in file " << this->dimensionedInternalField().objectPath()
217 fixedValueFvPatchScalarField::updateCoeffs();
221 void Foam::totalPressureFvPatchScalarField::updateCoeffs()
223 updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
227 void Foam::totalPressureFvPatchScalarField::write(Ostream& os) const
229 fvPatchScalarField::write(os);
230 writeEntryIfDifferent<word>(os, "U", "U", UName_);
231 writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
232 os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
233 os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
234 os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
235 p0_.writeEntry("p0", os);
236 writeEntry("value", os);
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 totalPressureFvPatchScalarField
251 // ************************************************************************* //