STYLE: date
[OpenFOAM-2.0.x.git] / src / finiteVolume / fields / fvPatchFields / derived / totalPressure / totalPressureFvPatchScalarField.C
blobe60f802e5ab39bfc9ea3a278d0009060f011078d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2011 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "totalPressureFvPatchScalarField.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #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
158     const scalarField& p0p,
159     const vectorField& Up
162     if (updated())
163     {
164         return;
165     }
167     const fvsPatchField<scalar>& phip =
168         patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
170     if (psiName_ == "none" && rhoName_ == "none")
171     {
172         operator==(p0p - 0.5*(1.0 - pos(phip))*magSqr(Up));
173     }
174     else if (rhoName_ == "none")
175     {
176         const fvPatchField<scalar>& psip =
177             patch().lookupPatchField<volScalarField, scalar>(psiName_);
179         if (gamma_ > 1.0)
180         {
181             scalar gM1ByG = (gamma_ - 1.0)/gamma_;
183             operator==
184             (
185                 p0p
186                /pow
187                 (
188                     (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
189                     1.0/gM1ByG
190                 )
191             );
192         }
193         else
194         {
195             operator==(p0p/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
196         }
197     }
198     else if (psiName_ == "none")
199     {
200         const fvPatchField<scalar>& rho =
201             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
203         operator==(p0p - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
204     }
205     else
206     {
207         FatalErrorIn
208         (
209             "totalPressureFvPatchScalarField::updateCoeffs()"
210         )   << " rho or psi set inconsistently, rho = " << rhoName_
211             << ", psi = " << psiName_ << ".\n"
212             << "    Set either rho or psi or neither depending on the "
213                "definition of total pressure." << nl
214             << "    Set the unused variable(s) to 'none'.\n"
215             << "    on patch " << this->patch().name()
216             << " of field " << this->dimensionedInternalField().name()
217             << " in file " << this->dimensionedInternalField().objectPath()
218             << exit(FatalError);
219     }
221     fixedValueFvPatchScalarField::updateCoeffs();
225 void Foam::totalPressureFvPatchScalarField::updateCoeffs()
227     updateCoeffs
228     (
229         p0(),
230         patch().lookupPatchField<volVectorField, vector>(UName())
231     );
235 void Foam::totalPressureFvPatchScalarField::write(Ostream& os) const
237     fvPatchScalarField::write(os);
238     writeEntryIfDifferent<word>(os, "U", "U", UName_);
239     writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
240     os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
241     os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
242     os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
243     p0_.writeEntry("p0", os);
244     writeEntry("value", os);
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 namespace Foam
252     makePatchTypeField
253     (
254         fvPatchScalarField,
255         totalPressureFvPatchScalarField
256     );
259 // ************************************************************************* //