Thermodynamics: Corrected the boundary condition for Cp.
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / basic / psiThermo / hsPsiThermo / hsPsiThermo.C
blobcb33763fd680116e47aacffe2ccb69d1bffa68bc
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2010-2010 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 "hsPsiThermo.H"
29 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
31 template<class MixtureType>
32 void Foam::hsPsiThermo<MixtureType>::calculate()
34     const scalarField& hsCells = hs_.internalField();
35     const scalarField& pCells = this->p_.internalField();
37     scalarField& TCells = this->T_.internalField();
38     scalarField& psiCells = this->psi_.internalField();
39     scalarField& muCells = this->mu_.internalField();
40     scalarField& alphaCells = this->alpha_.internalField();
42     forAll(TCells, celli)
43     {
44         const typename MixtureType::thermoType& mixture_ =
45             this->cellMixture(celli);
47         TCells[celli] = mixture_.THs(hsCells[celli], TCells[celli]);
48         psiCells[celli] = mixture_.psi(pCells[celli], TCells[celli]);
50         muCells[celli] = mixture_.mu(TCells[celli]);
51         alphaCells[celli] = mixture_.alpha(TCells[celli]);
52     }
54     forAll(T_.boundaryField(), patchi)
55     {
56         fvPatchScalarField& pp = this->p_.boundaryField()[patchi];
57         fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
58         fvPatchScalarField& ppsi = this->psi_.boundaryField()[patchi];
60         fvPatchScalarField& phs = hs_.boundaryField()[patchi];
62         fvPatchScalarField& pmu = this->mu_.boundaryField()[patchi];
63         fvPatchScalarField& palpha = this->alpha_.boundaryField()[patchi];
65         if (pT.fixesValue())
66         {
67             forAll(pT, facei)
68             {
69                 const typename MixtureType::thermoType& mixture_ =
70                     this->patchFaceMixture(patchi, facei);
72                 phs[facei] = mixture_.Hs(pT[facei]);
74                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
75                 pmu[facei] = mixture_.mu(pT[facei]);
76                 palpha[facei] = mixture_.alpha(pT[facei]);
77             }
78         }
79         else
80         {
81             forAll(pT, facei)
82             {
83                 const typename MixtureType::thermoType& mixture_ =
84                     this->patchFaceMixture(patchi, facei);
86                 pT[facei] = mixture_.THs(phs[facei], pT[facei]);
88                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
89                 pmu[facei] = mixture_.mu(pT[facei]);
90                 palpha[facei] = mixture_.alpha(pT[facei]);
91             }
92         }
93     }
97 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
99 template<class MixtureType>
100 Foam::hsPsiThermo<MixtureType>::hsPsiThermo(const fvMesh& mesh)
102     basicPsiThermo(mesh),
103     MixtureType(*this, mesh),
105     hs_
106     (
107         IOobject
108         (
109             "hs",
110             mesh.time().timeName(),
111             mesh,
112             IOobject::NO_READ,
113             IOobject::NO_WRITE
114         ),
115         mesh,
116         dimEnergy/dimMass,
117         this->hBoundaryTypes()
118     )
120     scalarField& hsCells = hs_.internalField();
121     const scalarField& TCells = this->T_.internalField();
123     forAll(hsCells, celli)
124     {
125         hsCells[celli] = this->cellMixture(celli).Hs(TCells[celli]);
126     }
128     forAll(hs_.boundaryField(), patchi)
129     {
130         hs_.boundaryField()[patchi] ==
131             hs(this->T_.boundaryField()[patchi], patchi);
132     }
134     hBoundaryCorrection(hs_);
136     calculate();
138     // Switch on saving old time
139     this->psi_.oldTime();
143 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
145 template<class MixtureType>
146 Foam::hsPsiThermo<MixtureType>::~hsPsiThermo()
150 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
152 template<class MixtureType>
153 void Foam::hsPsiThermo<MixtureType>::correct()
155     if (debug)
156     {
157         Info<< "entering hsPsiThermo<MixtureType>::correct()" << endl;
158     }
160     // force the saving of the old-time values
161     this->psi_.oldTime();
163     calculate();
165     if (debug)
166     {
167         Info<< "exiting hsPsiThermo<MixtureType>::correct()" << endl;
168     }
172 template<class MixtureType>
173 Foam::tmp<Foam::scalarField> Foam::hsPsiThermo<MixtureType>::hs
175     const scalarField& T,
176     const labelList& cells
177 ) const
179     tmp<scalarField> ths(new scalarField(T.size()));
180     scalarField& hs = ths();
182     forAll(T, celli)
183     {
184         hs[celli] = this->cellMixture(cells[celli]).Hs(T[celli]);
185     }
187     return ths;
191 template<class MixtureType>
192 Foam::tmp<Foam::scalarField> Foam::hsPsiThermo<MixtureType>::hs
194     const scalarField& T,
195     const label patchi
196 ) const
198     tmp<scalarField> ths(new scalarField(T.size()));
199     scalarField& hs = ths();
201     forAll(T, facei)
202     {
203         hs[facei] = this->patchFaceMixture(patchi, facei).Hs(T[facei]);
204     }
206     return ths;
210 template<class MixtureType>
211 Foam::tmp<Foam::scalarField> Foam::hsPsiThermo<MixtureType>::Cp
213     const scalarField& T,
214     const label patchi
215 ) const
217     tmp<scalarField> tCp(new scalarField(T.size()));
218     scalarField& cp = tCp();
220     forAll(T, facei)
221     {
222         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
223     }
225     return tCp;
229 template<class MixtureType>
230 Foam::tmp<Foam::volScalarField> Foam::hsPsiThermo<MixtureType>::Cp() const
232     const fvMesh& mesh = this->T_.mesh();
234     tmp<volScalarField> tCp
235     (
236         new volScalarField
237         (
238             IOobject
239             (
240                 "Cp",
241                 mesh.time().timeName(),
242                 mesh,
243                 IOobject::NO_READ,
244                 IOobject::NO_WRITE
245             ),
246             mesh,
247             dimensionSet(0, 2, -2, -1, 0)
248         )
249     );
251     volScalarField& cp = tCp();
253     forAll(this->T_, celli)
254     {
255         cp[celli] = this->cellMixture(celli).Cp(this->T_[celli]);
256     }
258     forAll(this->T_.boundaryField(), patchi)
259     {
260         const fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
261         fvPatchScalarField& pCp = cp.boundaryField()[patchi];
263         forAll(pT, facei)
264         {
265             pCp[facei] = this->patchFaceMixture(patchi, facei).Cp(pT[facei]);
266         }
267     }
269     return tCp;
273 template<class MixtureType>
274 Foam::tmp<Foam::scalarField> Foam::hsPsiThermo<MixtureType>::Cv
276     const scalarField& T,
277     const label patchi
278 ) const
280     tmp<scalarField> tCv(new scalarField(T.size()));
281     scalarField& cv = tCv();
283     forAll(T, facei)
284     {
285         cv[facei] = this->patchFaceMixture(patchi, facei).Cv(T[facei]);
286     }
288     return tCv;
292 template<class MixtureType>
293 Foam::tmp<Foam::volScalarField> Foam::hsPsiThermo<MixtureType>::Cv() const
295     const fvMesh& mesh = this->T_.mesh();
297     tmp<volScalarField> tCv
298     (
299         new volScalarField
300         (
301             IOobject
302             (
303                 "Cv",
304                 mesh.time().timeName(),
305                 mesh,
306                 IOobject::NO_READ,
307                 IOobject::NO_WRITE
308             ),
309             mesh,
310             dimEnergy/dimMass/dimTemperature
311         )
312     );
314     volScalarField& cv = tCv();
316     forAll(this->T_, celli)
317     {
318         cv[celli] = this->cellMixture(celli).Cv(this->T_[celli]);
319     }
321     forAll(this->T_.boundaryField(), patchi)
322     {
323         cv.boundaryField()[patchi] =
324             Cv(this->T_.boundaryField()[patchi], patchi);
325     }
327     return tCv;
331 template<class MixtureType>
332 bool Foam::hsPsiThermo<MixtureType>::read()
334     if (basicPsiThermo::read())
335     {
336         MixtureType::read(*this);
337         return true;
338     }
339     else
340     {
341         return false;
342     }
346 // ************************************************************************* //