initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / fields / fvPatchFields / derived / timeVaryingUniformTotalPressure / timeVaryingUniformTotalPressureFvPatchScalarField.C
blob1ee28c88a3af1547e5b51a5737608b8ed6c56883
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
38     const fvPatch& p,
39     const DimensionedField<scalar, volMesh>& iF
42     fixedValueFvPatchScalarField(p, iF),
43     UName_("U"),
44     phiName_("phi"),
45     rhoName_("none"),
46     psiName_("none"),
47     gamma_(0.0),
48     p0_(0.0),
49     timeSeries_()
53 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
54 timeVaryingUniformTotalPressureFvPatchScalarField
56     const fvPatch& p,
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"))),
68     timeSeries_(dict)
70     if (dict.found("value"))
71     {
72         fvPatchField<scalar>::operator=
73         (
74             scalarField("value", dict, p.size())
75         );
76     }
77     else
78     {
79         fvPatchField<scalar>::operator=(p0_);
80     }
84 Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
85 timeVaryingUniformTotalPressureFvPatchScalarField
87     const timeVaryingUniformTotalPressureFvPatchScalarField& ptf,
88     const fvPatch& p,
89     const DimensionedField<scalar, volMesh>& iF,
90     const fvPatchFieldMapper& mapper
93     fixedValueFvPatchScalarField(ptf, p, iF, mapper),
94     UName_(ptf.UName_),
95     phiName_(ptf.phiName_),
96     rhoName_(ptf.rhoName_),
97     psiName_(ptf.psiName_),
98     gamma_(ptf.gamma_),
99     p0_(ptf.p0_),
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_),
116     p0_(tppsf.p0_),
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_),
134     p0_(tppsf.p0_),
135     timeSeries_(tppsf.timeSeries_)
139 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
141 void Foam::timeVaryingUniformTotalPressureFvPatchScalarField::updateCoeffs
143     const vectorField& Up
146     if (updated())
147     {
148         return;
149     }
151     p0_ = timeSeries_(this->db().time().timeOutputValue());
153     const fvsPatchField<scalar>& phip =
154         patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
156     if (psiName_ == "none" && rhoName_ == "none")
157     {
158         operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
159     }
160     else if (rhoName_ == "none")
161     {
162         const fvPatchField<scalar>& psip =
163             patch().lookupPatchField<volScalarField, scalar>(psiName_);
165         if (gamma_ > 1.0)
166         {
167             scalar gM1ByG = (gamma_ - 1.0)/gamma_;
169             operator==
170             (
171                 p0_
172                /pow
173                 (
174                     (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
175                     1.0/gM1ByG
176                 )
177             );
178         }
179         else
180         {
181             operator==(p0_/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
182         }
183     }
184     else if (psiName_ == "none")
185     {
186         const fvPatchField<scalar>& rho =
187             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
189         operator==(p0_ - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
190     }
191     else
192     {
193         FatalErrorIn
194         (
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()
204             << exit(FatalError);
205     }
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);
221     if (UName_ != "U")
222     {
223         os.writeKeyword("U") << UName_ << token::END_STATEMENT << nl;
224     }
225     if (phiName_ != "phi")
226     {
227         os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
228     }
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 namespace Foam
242     makePatchTypeField
243     (
244         fvPatchScalarField,
245         timeVaryingUniformTotalPressureFvPatchScalarField
246     );
249 // ************************************************************************* //