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 "timeVaryingMappedTotalPressureFvPatchScalarField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
37 timeVaryingMappedTotalPressureFvPatchScalarField
40 const DimensionedField<scalar, volMesh>& iF
43 timeVaryingMappedFixedValueFvPatchScalarField(p, iF),
53 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
54 timeVaryingMappedTotalPressureFvPatchScalarField
57 const DimensionedField<scalar, volMesh>& iF,
58 const dictionary& dict
61 timeVaryingMappedFixedValueFvPatchScalarField(p, iF, dict),
62 UName_(dict.lookupOrDefault<word>("UName", "U")),
63 phiName_(dict.lookupOrDefault<word>("phiName", "phi")),
64 rhoName_(dict.lookupOrDefault<word>("rhoName", "none")),
67 iF.dimensions() == dimPressure/dimDensity && rhoName_ == "rho"
68 ? readScalar(dict.lookup("rho"))
71 psiName_(dict.lookupOrDefault<word>("psiName", "none")),
74 iF.dimensions() == dimPressure && psiName_ != "none"
75 ? readScalar(dict.lookup("gamma"))
81 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
82 timeVaryingMappedTotalPressureFvPatchScalarField
84 const timeVaryingMappedTotalPressureFvPatchScalarField& ptf,
86 const DimensionedField<scalar, volMesh>& iF,
87 const fvPatchFieldMapper& mapper
90 timeVaryingMappedFixedValueFvPatchScalarField(ptf, p, iF, mapper),
92 phiName_(ptf.phiName_),
93 rhoName_(ptf.rhoName_),
95 psiName_(ptf.psiName_),
100 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
101 timeVaryingMappedTotalPressureFvPatchScalarField
103 const timeVaryingMappedTotalPressureFvPatchScalarField& tppsf
106 timeVaryingMappedFixedValueFvPatchScalarField(tppsf),
107 UName_(tppsf.UName_),
108 phiName_(tppsf.phiName_),
109 rhoName_(tppsf.rhoName_),
111 psiName_(tppsf.psiName_),
116 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
117 timeVaryingMappedTotalPressureFvPatchScalarField
119 const timeVaryingMappedTotalPressureFvPatchScalarField& tppsf,
120 const DimensionedField<scalar, volMesh>& iF
123 timeVaryingMappedFixedValueFvPatchScalarField(tppsf, iF),
124 UName_(tppsf.UName_),
125 phiName_(tppsf.phiName_),
126 rhoName_(tppsf.rhoName_),
128 psiName_(tppsf.psiName_),
133 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::autoMap
137 const fvPatchFieldMapper& m
140 timeVaryingMappedFixedValueFvPatchScalarField::autoMap(m);
144 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::rmap
146 const fvPatchScalarField& ptf,
147 const labelList& addr
150 timeVaryingMappedFixedValueFvPatchScalarField::rmap(ptf, addr);
154 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::updateCoeffs
156 const vectorField& Up
164 // Map the total-pressure field onto this field
165 timeVaryingMappedFixedValueFvPatchScalarField::updateCoeffs();
166 const scalarField p0 = *this;
168 const fvsPatchField<scalar>& phip =
169 patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
171 if (dimensionedInternalField().dimensions() == dimPressure/dimDensity)
173 if (rhoName_ == "none")
175 operator==(p0 - 0.5*(1.0 - pos(phip))*magSqr(Up));
177 else if (rhoName_ == "rho")
179 operator==(p0/rho_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
185 "timeVaryingMappedTotalPressureFvPatchScalarField::"
187 ) << " rhoName set inconsistently, rhoName = " << rhoName_
189 << " Set rhoName to 'rho' or 'none' depending on the "
190 "definition of total pressure." << nl
191 << " on patch " << this->patch().name()
192 << " of field " << this->dimensionedInternalField().name()
193 << " in file " << this->dimensionedInternalField().objectPath()
197 else if (dimensionedInternalField().dimensions() == dimPressure)
199 if (rhoName_ != "none")
201 const fvPatchField<scalar>& rho =
202 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
204 operator==(p0 - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
206 else if (psiName_ != "none")
208 const fvPatchField<scalar>& psip =
209 patch().lookupPatchField<volScalarField, scalar>(psiName_);
213 scalar gM1ByG = (gamma_ - 1.0)/gamma_;
220 (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
227 operator==(p0/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
234 "timeVaryingMappedTotalPressureFvPatchScalarField::"
236 ) << " rhoName or psiName set inconsistently, rhoName = "
237 << rhoName_ << ", psiName = " << psiName_ << ".\n"
238 << " Set either rhoName or psiName depending on the "
239 "definition of total pressure." << nl
240 << " Set the unused variable(s) to 'none'.\n"
241 << " on patch " << this->patch().name()
242 << " of field " << this->dimensionedInternalField().name()
243 << " in file " << this->dimensionedInternalField().objectPath()
251 "timeVaryingMappedTotalPressureFvPatchScalarField::updateCoeffs()"
252 ) << "Incorrect dimensions for pressure "
253 << dimensionedInternalField().dimensions()
254 << " Should be either " << dimPressure
255 << " for compressible/variable density flow\n"
256 << " or " << dimPressure/dimDensity
257 << " for incompressible flow.\n"
258 << " on patch " << this->patch().name()
259 << " of field " << this->dimensionedInternalField().name()
260 << " in file " << this->dimensionedInternalField().objectPath()
266 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::updateCoeffs()
268 updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
272 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::write
277 writeEntryIfDifferent<word>(os, "UName", "U", UName_);
278 writeEntryIfDifferent<word>(os, "phiName", "phi", phiName_);
279 os.writeKeyword("rhoName") << rhoName_ << token::END_STATEMENT << nl;
280 os.writeKeyword("rho") << rho_ << token::END_STATEMENT << nl;
281 os.writeKeyword("psiName") << psiName_ << token::END_STATEMENT << nl;
282 os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
283 timeVaryingMappedFixedValueFvPatchScalarField::write(os);
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 timeVaryingMappedTotalPressureFvPatchScalarField
298 // ************************************************************************* //