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 "timeVaryingUniformTotalPressureFvPatchScalarField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
36 timeVaryingUniformTotalPressureFvPatchScalarField
39 const DimensionedField<scalar, volMesh>& iF
42 fixedValueFvPatchScalarField(p, iF),
53 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
54 timeVaryingUniformTotalPressureFvPatchScalarField
57 const DimensionedField<scalar, volMesh>& iF,
58 const dictionary& dict
61 fixedValueFvPatchScalarField(p, iF),
62 UName_(dict.lookupOrDefault<word>("U", "U")),
63 phiName_(dict.lookupOrDefault<word>("phi", "phi")),
64 rhoName_(dict.lookupOrDefault<word>("rho", "none")),
65 psiName_(dict.lookupOrDefault<word>("psi", "none")),
66 gamma_(readScalar(dict.lookup("gamma"))),
67 p0_(readScalar(dict.lookup("p0"))),
70 if (dict.found("value"))
72 fvPatchField<scalar>::operator=
74 scalarField("value", dict, p.size())
79 fvPatchField<scalar>::operator=(p0_);
84 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
85 timeVaryingUniformTotalPressureFvPatchScalarField
87 const timeVaryingUniformTotalPressureFvPatchScalarField& ptf,
89 const DimensionedField<scalar, volMesh>& iF,
90 const fvPatchFieldMapper& mapper
93 fixedValueFvPatchScalarField(ptf, p, iF, mapper),
95 phiName_(ptf.phiName_),
96 rhoName_(ptf.rhoName_),
97 psiName_(ptf.psiName_),
100 timeSeries_(ptf.timeSeries_)
104 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
105 timeVaryingUniformTotalPressureFvPatchScalarField
107 const timeVaryingUniformTotalPressureFvPatchScalarField& tppsf
110 fixedValueFvPatchScalarField(tppsf),
111 UName_(tppsf.UName_),
112 phiName_(tppsf.phiName_),
113 rhoName_(tppsf.rhoName_),
114 psiName_(tppsf.psiName_),
115 gamma_(tppsf.gamma_),
117 timeSeries_(tppsf.timeSeries_)
121 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
122 timeVaryingUniformTotalPressureFvPatchScalarField
124 const timeVaryingUniformTotalPressureFvPatchScalarField& tppsf,
125 const DimensionedField<scalar, volMesh>& iF
128 fixedValueFvPatchScalarField(tppsf, iF),
129 UName_(tppsf.UName_),
130 phiName_(tppsf.phiName_),
131 rhoName_(tppsf.rhoName_),
132 psiName_(tppsf.psiName_),
133 gamma_(tppsf.gamma_),
135 timeSeries_(tppsf.timeSeries_)
139 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 void Foam::timeVaryingUniformTotalPressureFvPatchScalarField::updateCoeffs
143 const vectorField& Up
151 p0_ = timeSeries_(this->db().time().timeOutputValue());
153 const fvsPatchField<scalar>& phip =
154 patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
156 if (psiName_ == "none" && rhoName_ == "none")
158 operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
160 else if (rhoName_ == "none")
162 const fvPatchField<scalar>& psip =
163 patch().lookupPatchField<volScalarField, scalar>(psiName_);
167 scalar gM1ByG = (gamma_ - 1.0)/gamma_;
174 (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
181 operator==(p0_/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
184 else if (psiName_ == "none")
186 const fvPatchField<scalar>& rho =
187 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
189 operator==(p0_ - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
195 "timeVaryingUniformTotalPressureFvPatchScalarField::updateCoeffs()"
196 ) << " rho or psi set inconsitently, rho = " << rhoName_
197 << ", psi = " << psiName_ << ".\n"
198 << " Set either rho or psi or neither depending on the "
199 "definition of total pressure.\n"
200 << " Set the unused variables to 'none'.\n"
201 << " on patch " << this->patch().name()
202 << " of field " << this->dimensionedInternalField().name()
203 << " in file " << this->dimensionedInternalField().objectPath()
207 fixedValueFvPatchScalarField::updateCoeffs();
211 void Foam::timeVaryingUniformTotalPressureFvPatchScalarField::updateCoeffs()
213 updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
217 void Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
218 write(Ostream& os) const
220 fvPatchScalarField::write(os);
223 os.writeKeyword("U") << UName_ << token::END_STATEMENT << nl;
225 if (phiName_ != "phi")
227 os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
229 os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
230 os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
231 os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
232 os.writeKeyword("p0") << p0_ << token::END_STATEMENT << nl;
233 timeSeries_.write(os);
234 writeEntry("value", os);
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 timeVaryingUniformTotalPressureFvPatchScalarField
249 // ************************************************************************* //