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"
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
39 const DimensionedField<scalar, volMesh>& iF
42 fixedValueFvPatchScalarField(p, iF),
52 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
55 const DimensionedField<scalar, volMesh>& iF,
56 const dictionary& dict
59 fixedValueFvPatchScalarField(p, iF),
60 UName_(dict.lookupOrDefault<word>("U", "U")),
61 phiName_(dict.lookupOrDefault<word>("phi", "phi")),
62 rhoName_(dict.lookupOrDefault<word>("rho", "none")),
63 psiName_(dict.lookupOrDefault<word>("psi", "none")),
64 gamma_(readScalar(dict.lookup("gamma"))),
65 p0_("p0", dict, p.size())
67 if (dict.found("value"))
69 fvPatchField<scalar>::operator=
71 scalarField("value", dict, p.size())
76 fvPatchField<scalar>::operator=(p0_);
81 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
83 const totalPressureFvPatchScalarField& ptf,
85 const DimensionedField<scalar, volMesh>& iF,
86 const fvPatchFieldMapper& mapper
89 fixedValueFvPatchScalarField(ptf, p, iF, mapper),
91 phiName_(ptf.phiName_),
92 rhoName_(ptf.rhoName_),
93 psiName_(ptf.psiName_),
99 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
101 const totalPressureFvPatchScalarField& tppsf
104 fixedValueFvPatchScalarField(tppsf),
105 UName_(tppsf.UName_),
106 phiName_(tppsf.phiName_),
107 rhoName_(tppsf.rhoName_),
108 psiName_(tppsf.psiName_),
109 gamma_(tppsf.gamma_),
114 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
116 const totalPressureFvPatchScalarField& tppsf,
117 const DimensionedField<scalar, volMesh>& iF
120 fixedValueFvPatchScalarField(tppsf, iF),
121 UName_(tppsf.UName_),
122 phiName_(tppsf.phiName_),
123 rhoName_(tppsf.rhoName_),
124 psiName_(tppsf.psiName_),
125 gamma_(tppsf.gamma_),
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 void Foam::totalPressureFvPatchScalarField::autoMap
134 const fvPatchFieldMapper& m
137 fixedValueFvPatchScalarField::autoMap(m);
142 void Foam::totalPressureFvPatchScalarField::rmap
144 const fvPatchScalarField& ptf,
145 const labelList& addr
148 fixedValueFvPatchScalarField::rmap(ptf, addr);
150 const totalPressureFvPatchScalarField& tiptf =
151 refCast<const totalPressureFvPatchScalarField>(ptf);
153 p0_.rmap(tiptf.p0_, addr);
157 void Foam::totalPressureFvPatchScalarField::updateCoeffs(const vectorField& Up)
164 const fvsPatchField<scalar>& phip =
165 patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
167 if (psiName_ == "none" && rhoName_ == "none")
169 operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
171 else if (rhoName_ == "none")
173 const fvPatchField<scalar>& psip =
174 patch().lookupPatchField<volScalarField, scalar>(psiName_);
178 scalar gM1ByG = (gamma_ - 1.0)/gamma_;
185 (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
192 operator==(p0_/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
195 else if (psiName_ == "none")
197 const fvPatchField<scalar>& rho =
198 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
200 operator==(p0_ - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
206 "totalPressureFvPatchScalarField::updateCoeffs()"
207 ) << " rho or psi set inconsistently, rho = " << rhoName_
208 << ", psi = " << psiName_ << ".\n"
209 << " Set either rho or psi or neither depending on the "
210 "definition of total pressure." << nl
211 << " Set the unused variable(s) to 'none'.\n"
212 << " on patch " << this->patch().name()
213 << " of field " << this->dimensionedInternalField().name()
214 << " in file " << this->dimensionedInternalField().objectPath()
218 fixedValueFvPatchScalarField::updateCoeffs();
222 void Foam::totalPressureFvPatchScalarField::updateCoeffs()
224 updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
228 void Foam::totalPressureFvPatchScalarField::write(Ostream& os) const
230 fvPatchScalarField::write(os);
231 writeEntryIfDifferent<word>(os, "U", "U", UName_);
232 writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
233 os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
234 os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
235 os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
236 p0_.writeEntry("p0", os);
237 writeEntry("value", os);
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 totalPressureFvPatchScalarField
252 // ************************************************************************* //