timeVaryingMappedTotalPressureFvPatchScalarField: New BC total pressure BC.
[OpenFOAM-1.6.x.git] / src / finiteVolume / fields / fvPatchFields / derived / timeVaryingMappedTotalPressure / timeVaryingMappedTotalPressureFvPatchScalarField.C
blob89db42b83a80eb4f65502a19304479acf216252f
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 "timeVaryingMappedTotalPressureFvPatchScalarField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
34 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
36 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
37 timeVaryingMappedTotalPressureFvPatchScalarField
39     const fvPatch& p,
40     const DimensionedField<scalar, volMesh>& iF
43     timeVaryingMappedFixedValueFvPatchScalarField(p, iF),
44     UName_("U"),
45     phiName_("phi"),
46     rhoName_("none"),
47     rho_(1),
48     psiName_("none"),
49     gamma_(0.0)
53 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
54 timeVaryingMappedTotalPressureFvPatchScalarField
56     const fvPatch& p,
57     const DimensionedField<scalar, volMesh>& iF,
58     const dictionary& dict
61     timeVaryingMappedFixedValueFvPatchScalarField(p, iF, dict),
62     UName_(dict.lookupOrDefault<word>("UName", "U")),
63     phiName_(dict.lookupOrDefault<word>("phiName", "phi")),
64     rhoName_(dict.lookupOrDefault<word>("rhoName", "none")),
65     rho_
66     (
67         iF.dimensions() == dimPressure/dimDensity && rhoName_ == "rho"
68         ? readScalar(dict.lookup("rho"))
69         : 1
70     ),
71     psiName_(dict.lookupOrDefault<word>("psiName", "none")),
72     gamma_
73     (
74         iF.dimensions() == dimPressure && psiName_ != "none"
75         ? readScalar(dict.lookup("gamma"))
76         : 1
77     )
81 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
82 timeVaryingMappedTotalPressureFvPatchScalarField
84     const timeVaryingMappedTotalPressureFvPatchScalarField& ptf,
85     const fvPatch& p,
86     const DimensionedField<scalar, volMesh>& iF,
87     const fvPatchFieldMapper& mapper
90     timeVaryingMappedFixedValueFvPatchScalarField(ptf, p, iF, mapper),
91     UName_(ptf.UName_),
92     phiName_(ptf.phiName_),
93     rhoName_(ptf.rhoName_),
94     rho_(ptf.rho_),
95     psiName_(ptf.psiName_),
96     gamma_(ptf.gamma_)
100 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
101 timeVaryingMappedTotalPressureFvPatchScalarField
103     const timeVaryingMappedTotalPressureFvPatchScalarField& tppsf
106     timeVaryingMappedFixedValueFvPatchScalarField(tppsf),
107     UName_(tppsf.UName_),
108     phiName_(tppsf.phiName_),
109     rhoName_(tppsf.rhoName_),
110     rho_(tppsf.rho_),
111     psiName_(tppsf.psiName_),
112     gamma_(tppsf.gamma_)
116 Foam::timeVaryingMappedTotalPressureFvPatchScalarField::
117 timeVaryingMappedTotalPressureFvPatchScalarField
119     const timeVaryingMappedTotalPressureFvPatchScalarField& tppsf,
120     const DimensionedField<scalar, volMesh>& iF
123     timeVaryingMappedFixedValueFvPatchScalarField(tppsf, iF),
124     UName_(tppsf.UName_),
125     phiName_(tppsf.phiName_),
126     rhoName_(tppsf.rhoName_),
127     rho_(tppsf.rho_),
128     psiName_(tppsf.psiName_),
129     gamma_(tppsf.gamma_)
133 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
135 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::autoMap
137     const fvPatchFieldMapper& m
140     timeVaryingMappedFixedValueFvPatchScalarField::autoMap(m);
144 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::rmap
146     const fvPatchScalarField& ptf,
147     const labelList& addr
150     timeVaryingMappedFixedValueFvPatchScalarField::rmap(ptf, addr);
154 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::updateCoeffs
156     const vectorField& Up
159     if (updated())
160     {
161         return;
162     }
164     // Map the total-pressure field onto this field
165     timeVaryingMappedFixedValueFvPatchScalarField::updateCoeffs();
166     const scalarField p0 = *this;
168     const fvsPatchField<scalar>& phip =
169         patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
171     if (dimensionedInternalField().dimensions() == dimPressure/dimDensity)
172     {
173         if (rhoName_ == "none")
174         {
175             operator==(p0 - 0.5*(1.0 - pos(phip))*magSqr(Up));
176         }
177         else if (rhoName_ == "rho")
178         {
179             operator==(p0/rho_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
180         }
181         else
182         {
183             FatalErrorIn
184             (
185                 "timeVaryingMappedTotalPressureFvPatchScalarField::"
186                 "updateCoeffs()"
187             )   << " rhoName set inconsistently, rhoName = " << rhoName_
188                 << ".\n"
189                 << "    Set rhoName to 'rho' or 'none' depending on the "
190                    "definition of total pressure." << nl
191                 << "    on patch " << this->patch().name()
192                 << " of field " << this->dimensionedInternalField().name()
193                 << " in file " << this->dimensionedInternalField().objectPath()
194                 << exit(FatalError);
195         }
196     }
197     else if (dimensionedInternalField().dimensions() == dimPressure)
198     {
199         if (rhoName_ != "none")
200         {
201             const fvPatchField<scalar>& rho =
202                 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
204             operator==(p0 - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
205         }
206         else if (psiName_ != "none")
207         {
208             const fvPatchField<scalar>& psip =
209                 patch().lookupPatchField<volScalarField, scalar>(psiName_);
211             if (gamma_ > 1.0)
212             {
213                 scalar gM1ByG = (gamma_ - 1.0)/gamma_;
215                 operator==
216                 (
217                     p0
218                     /pow
219                     (
220                         (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
221                         1.0/gM1ByG
222                     )
223                 );
224             }
225             else
226             {
227                 operator==(p0/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
228             }
229         }
230         else
231         {
232             FatalErrorIn
233             (
234                 "timeVaryingMappedTotalPressureFvPatchScalarField::"
235                 "updateCoeffs()"
236             )   << " rhoName or psiName set inconsistently, rhoName = "
237                 << rhoName_ << ", psiName = " << psiName_ << ".\n"
238                 << "    Set either rhoName or psiName depending on the "
239                    "definition of total pressure." << nl
240                 << "    Set the unused variable(s) to 'none'.\n"
241                 << "    on patch " << this->patch().name()
242                 << " of field " << this->dimensionedInternalField().name()
243                 << " in file " << this->dimensionedInternalField().objectPath()
244                 << exit(FatalError);
245         }
246     }
247     else
248     {
249         FatalErrorIn
250         (
251             "timeVaryingMappedTotalPressureFvPatchScalarField::updateCoeffs()"
252         )   << "Incorrect dimensions for pressure "
253             << dimensionedInternalField().dimensions()
254             << "    Should be either " << dimPressure
255             << " for compressible/variable density flow\n"
256             << "    or " << dimPressure/dimDensity
257             << " for incompressible flow.\n"
258             << "    on patch " << this->patch().name()
259             << " of field " << this->dimensionedInternalField().name()
260             << " in file " << this->dimensionedInternalField().objectPath()
261             << exit(FatalError);
262     }
266 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::updateCoeffs()
268     updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_));
272 void Foam::timeVaryingMappedTotalPressureFvPatchScalarField::write
274     Ostream& os
275 ) const
277     writeEntryIfDifferent<word>(os, "UName", "U", UName_);
278     writeEntryIfDifferent<word>(os, "phiName", "phi", phiName_);
279     os.writeKeyword("rhoName") << rhoName_ << token::END_STATEMENT << nl;
280     os.writeKeyword("psiName") << psiName_ << token::END_STATEMENT << nl;
281     os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
282     timeVaryingMappedFixedValueFvPatchScalarField::write(os);
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 namespace Foam
290     makePatchTypeField
291     (
292         fvPatchScalarField,
293         timeVaryingMappedTotalPressureFvPatchScalarField
294     );
297 // ************************************************************************* //