fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / finiteVolume / fields / fvPatchFields / derived / totalPressure / totalPressureFvPatchScalarField.C
blobfc43fe4ec64a17e3e6e35ec6cae09c15a9cc1b76
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 "totalPressureFvPatchScalarField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
33 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
35 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
37     const fvPatch& p,
38     const DimensionedField<scalar, volMesh>& iF
41     fixedValueFvPatchScalarField(p, iF),
42     UName_("U"),
43     phiName_("phi"),
44     rhoName_("none"),
45     psiName_("none"),
46     gamma_(0.0),
47     p0_(p.size(), 0.0)
51 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
53     const fvPatch& p,
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"))
67     {
68         fvPatchField<scalar>::operator=
69         (
70             scalarField("value", dict, p.size())
71         );
72     }
73     else
74     {
75         fvPatchField<scalar>::operator=(p0_);
76     }
80 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
82     const totalPressureFvPatchScalarField& ptf,
83     const fvPatch& p,
84     const DimensionedField<scalar, volMesh>& iF,
85     const fvPatchFieldMapper& mapper
88     fixedValueFvPatchScalarField(ptf, p, iF, mapper),
89     UName_(ptf.UName_),
90     phiName_(ptf.phiName_),
91     rhoName_(ptf.rhoName_),
92     psiName_(ptf.psiName_),
93     gamma_(ptf.gamma_),
94     p0_(ptf.p0_, mapper)
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_),
109     p0_(tppsf.p0_)
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_),
125     p0_(tppsf.p0_)
129 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
131 void Foam::totalPressureFvPatchScalarField::autoMap
133     const fvPatchFieldMapper& m
136     fixedValueFvPatchScalarField::autoMap(m);
137     p0_.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)
158     if (updated())
159     {
160         return;
161     }
163     const fvsPatchField<scalar>& phip =
164         patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
166     if (psiName_ == "none" && rhoName_ == "none")
167     {
168         operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
169     }
170     else if (rhoName_ == "none")
171     {
172         const fvPatchField<scalar>& psip =
173             patch().lookupPatchField<volScalarField, scalar>(psiName_);
175         if (gamma_ > 1.0)
176         {
177             scalar gM1ByG = (gamma_ - 1.0)/gamma_;
179             operator==
180             (
181                 p0_
182                /pow
183                 (
184                     (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
185                     1.0/gM1ByG
186                 )
187             );
188         }
189         else
190         {
191             operator==(p0_/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
192         }
193     }
194     else if (psiName_ == "none")
195     {
196         const fvPatchField<scalar>& rho =
197             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
199         operator==(p0_ - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
200     }
201     else
202     {
203         FatalErrorIn
204         (
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()
214             << exit(FatalError);
215     }
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 namespace Foam
244     makePatchTypeField
245     (
246         fvPatchScalarField,
247         totalPressureFvPatchScalarField
248     );
251 // ************************************************************************* //