initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / fields / fvPatchFields / derived / totalPressure / totalPressureFvPatchScalarField.C
blob56ee8a0753d38e9eef05c766677ca1d4eccfa64d
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 "totalPressureFvPatchScalarField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
34 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
36 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
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_(p.size(), 0.0)
52 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
54     const fvPatch& p,
55     const DimensionedField<scalar, volMesh>& iF,
56     const dictionary& dict
59     fixedValueFvPatchScalarField(p, iF),
60     UName_(dict.lookupOrDefault<word>("U", "U")),
61     phiName_(dict.lookupOrDefault<word>("phi", "phi")),
62     rhoName_(dict.lookupOrDefault<word>("rho", "none")),
63     psiName_(dict.lookupOrDefault<word>("psi", "none")),
64     gamma_(readScalar(dict.lookup("gamma"))),
65     p0_("p0", dict, p.size())
67     if (dict.found("value"))
68     {
69         fvPatchField<scalar>::operator=
70         (
71             scalarField("value", dict, p.size())
72         );
73     }
74     else
75     {
76         fvPatchField<scalar>::operator=(p0_);
77     }
81 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
83     const totalPressureFvPatchScalarField& ptf,
84     const fvPatch& p,
85     const DimensionedField<scalar, volMesh>& iF,
86     const fvPatchFieldMapper& mapper
89     fixedValueFvPatchScalarField(ptf, p, iF, mapper),
90     UName_(ptf.UName_),
91     phiName_(ptf.phiName_),
92     rhoName_(ptf.rhoName_),
93     psiName_(ptf.psiName_),
94     gamma_(ptf.gamma_),
95     p0_(ptf.p0_, mapper)
99 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
101     const totalPressureFvPatchScalarField& tppsf
104     fixedValueFvPatchScalarField(tppsf),
105     UName_(tppsf.UName_),
106     phiName_(tppsf.phiName_),
107     rhoName_(tppsf.rhoName_),
108     psiName_(tppsf.psiName_),
109     gamma_(tppsf.gamma_),
110     p0_(tppsf.p0_)
114 Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
116     const totalPressureFvPatchScalarField& tppsf,
117     const DimensionedField<scalar, volMesh>& iF
120     fixedValueFvPatchScalarField(tppsf, iF),
121     UName_(tppsf.UName_),
122     phiName_(tppsf.phiName_),
123     rhoName_(tppsf.rhoName_),
124     psiName_(tppsf.psiName_),
125     gamma_(tppsf.gamma_),
126     p0_(tppsf.p0_)
130 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
132 void Foam::totalPressureFvPatchScalarField::autoMap
134     const fvPatchFieldMapper& m
137     fixedValueFvPatchScalarField::autoMap(m);
138     p0_.autoMap(m);
142 void Foam::totalPressureFvPatchScalarField::rmap
144     const fvPatchScalarField& ptf,
145     const labelList& addr
148     fixedValueFvPatchScalarField::rmap(ptf, addr);
150     const totalPressureFvPatchScalarField& tiptf =
151         refCast<const totalPressureFvPatchScalarField>(ptf);
153     p0_.rmap(tiptf.p0_, addr);
157 void Foam::totalPressureFvPatchScalarField::updateCoeffs(const vectorField& Up)
159     if (updated())
160     {
161         return;
162     }
164     const fvsPatchField<scalar>& phip =
165         patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
167     if (psiName_ == "none" && rhoName_ == "none")
168     {
169         operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
170     }
171     else if (rhoName_ == "none")
172     {
173         const fvPatchField<scalar>& psip =
174             patch().lookupPatchField<volScalarField, scalar>(psiName_);
176         if (gamma_ > 1.0)
177         {
178             scalar gM1ByG = (gamma_ - 1.0)/gamma_;
180             operator==
181             (
182                 p0_
183                /pow
184                 (
185                     (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
186                     1.0/gM1ByG
187                 )
188             );
189         }
190         else
191         {
192             operator==(p0_/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
193         }
194     }
195     else if (psiName_ == "none")
196     {
197         const fvPatchField<scalar>& rho =
198             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
200         operator==(p0_ - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
201     }
202     else
203     {
204         FatalErrorIn
205         (
206             "totalPressureFvPatchScalarField::updateCoeffs()"
207         )   << " rho or psi set inconsistently, rho = " << rhoName_
208             << ", psi = " << psiName_ << ".\n"
209             << "    Set either rho or psi or neither depending on the "
210                "definition of total pressure." << nl
211             << "    Set the unused variable(s) to 'none'.\n"
212             << "    on patch " << this->patch().name()
213             << " of field " << this->dimensionedInternalField().name()
214             << " in file " << this->dimensionedInternalField().objectPath()
215             << exit(FatalError);
216     }
218     fixedValueFvPatchScalarField::updateCoeffs();
222 void Foam::totalPressureFvPatchScalarField::updateCoeffs()
224     updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
228 void Foam::totalPressureFvPatchScalarField::write(Ostream& os) const
230     fvPatchScalarField::write(os);
231     writeEntryIfDifferent<word>(os, "U", "U", UName_);
232     writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
233     os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
234     os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
235     os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
236     p0_.writeEntry("p0", os);
237     writeEntry("value", os);
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 namespace Foam
245     makePatchTypeField
246     (
247         fvPatchScalarField,
248         totalPressureFvPatchScalarField
249     );
252 // ************************************************************************* //