Changed the access to derived properties to ensure the old-time level values are...
[OpenFOAM-1.5.x.git] / src / thermophysicalModels / basic / hThermo / hThermo.C
blob7e32f7a0636288169e7bc36f02a3b9140c20efba
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 "hThermo.H"
28 #include "fvMesh.H"
29 #include "fixedValueFvPatchFields.H"
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 template<class MixtureType>
34 Foam::hThermo<MixtureType>::hThermo(const fvMesh& mesh)
36     basicThermo(mesh),
37     MixtureType(*this, mesh),
39     h_
40     (
41         IOobject
42         (
43             "h",
44             mesh.time().timeName(),
45             mesh,
46             IOobject::NO_READ,
47             IOobject::NO_WRITE
48         ),
49         mesh,
50         dimensionSet(0, 2, -2, 0, 0),
51         hBoundaryTypes()
52     )
54     scalarField& hCells = h_.internalField();
55     const scalarField& TCells = T_.internalField();
57     forAll(hCells, celli)
58     {
59         hCells[celli] = this->cellMixture(celli).H(TCells[celli]);
60     }
62     forAll(h_.boundaryField(), patchi)
63     {
64         h_.boundaryField()[patchi] == h(T_.boundaryField()[patchi], patchi);
65     }
67     hBoundaryCorrection(h_);
69     calculate();
70     psi_.oldTime();   // Switch on saving old time
74 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
76 template<class MixtureType>
77 Foam::hThermo<MixtureType>::~hThermo()
81 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
83 template<class MixtureType>
84 void Foam::hThermo<MixtureType>::calculate()
86     const scalarField& hCells = h_.internalField();
87     const scalarField& pCells = p_.internalField();
89     scalarField& TCells = T_.internalField();
90     scalarField& psiCells = psi_.internalField();
91     scalarField& muCells = mu_.internalField();
92     scalarField& alphaCells = alpha_.internalField();
94     forAll(TCells, celli)
95     {
96         const typename MixtureType::thermoType& mixture_ =
97             this->cellMixture(celli);
99         TCells[celli] = mixture_.TH(hCells[celli], TCells[celli]);
100         psiCells[celli] = mixture_.psi(pCells[celli], TCells[celli]);
102         muCells[celli] = mixture_.mu(TCells[celli]);
103         alphaCells[celli] = mixture_.alpha(TCells[celli]);
104     }
106     forAll(T_.boundaryField(), patchi)
107     {
108         fvPatchScalarField& pp = p_.boundaryField()[patchi];
109         fvPatchScalarField& pT = T_.boundaryField()[patchi];
110         fvPatchScalarField& ppsi = psi_.boundaryField()[patchi];
112         fvPatchScalarField& ph = h_.boundaryField()[patchi];
114         fvPatchScalarField& pmu = mu_.boundaryField()[patchi];
115         fvPatchScalarField& palpha = alpha_.boundaryField()[patchi];
117         if (pT.fixesValue())
118         {
119             forAll(pT, facei)
120             {
121                 const typename MixtureType::thermoType& mixture_ =
122                     this->patchFaceMixture(patchi, facei);
124                 ph[facei] = mixture_.H(pT[facei]);
126                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
127                 pmu[facei] = mixture_.mu(pT[facei]);
128                 palpha[facei] = mixture_.alpha(pT[facei]);
129             }
130         }
131         else
132         {
133             forAll(pT, facei)
134             {
135                 const typename MixtureType::thermoType& mixture_ =
136                     this->patchFaceMixture(patchi, facei);
138                 pT[facei] = mixture_.TH(ph[facei], pT[facei]);
140                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
141                 pmu[facei] = mixture_.mu(pT[facei]);
142                 palpha[facei] = mixture_.alpha(pT[facei]);
143             }
144         }
145     }
149 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
151 template<class MixtureType>
152 void Foam::hThermo<MixtureType>::correct()
154     if (debug)
155     {
156         Info<< "entering hThermo<MixtureType>::correct()" << endl;
157     }
159     // force the saving of the old-time values
160     psi_.oldTime();
162     calculate();
164     if (debug)
165     {
166         Info<< "exiting hThermo<MixtureType>::correct()" << endl;
167     }
171 template<class MixtureType>
172 Foam::tmp<Foam::scalarField> Foam::hThermo<MixtureType>::h
174     const scalarField& T,
175     const labelList& cells
176 ) const
178     tmp<scalarField> th(new scalarField(T.size()));
179     scalarField& h = th();
181     forAll(T, celli)
182     {
183         h[celli] = this->cellMixture(cells[celli]).H(T[celli]);
184     }
186     return th;
190 template<class MixtureType>
191 Foam::tmp<Foam::scalarField> Foam::hThermo<MixtureType>::h
193     const scalarField& T,
194     const label patchi
195 ) const
197     tmp<scalarField> th(new scalarField(T.size()));
198     scalarField& h = th();
200     forAll(T, facei)
201     {
202         h[facei] = this->patchFaceMixture(patchi, facei).H(T[facei]);
203     }
205     return th;
209 template<class MixtureType>
210 Foam::tmp<Foam::scalarField> Foam::hThermo<MixtureType>::Cp
212     const scalarField& T,
213     const label patchi
214 ) const
216     tmp<scalarField> tCp(new scalarField(T.size()));
217     scalarField& cp = tCp();
219     forAll(T, facei)
220     {
221         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
222     }
224     return tCp;
228 template<class MixtureType>
229 Foam::tmp<Foam::volScalarField> Foam::hThermo<MixtureType>::Cp() const
231     const fvMesh& mesh = T_.mesh();
233     tmp<volScalarField> tCp
234     (
235         new volScalarField
236         (
237             IOobject
238             (
239                 "Cp",
240                 mesh.time().timeName(),
241                 mesh,
242                 IOobject::NO_READ,
243                 IOobject::NO_WRITE
244             ),
245             mesh,
246             dimensionSet(0, 2, -2, -1, 0)
247         )
248     );
250     volScalarField& cp = tCp();
252     forAll(T_, celli)
253     {
254         cp[celli] = this->cellMixture(celli).Cp(T_[celli]);
255     }
257     forAll(T_.boundaryField(), patchi)
258     {
259         cp.boundaryField()[patchi] = Cp(T_.boundaryField()[patchi], patchi);
260     }
262     return tCp;
266 template<class MixtureType>
267 Foam::tmp<Foam::volScalarField> Foam::hThermo<MixtureType>::Cv() const
269     const fvMesh& mesh = T_.mesh();
271     tmp<volScalarField> tCv
272     (
273         new volScalarField
274         (
275             IOobject
276             (
277                 "Cv",
278                 mesh.time().timeName(),
279                 mesh,
280                 IOobject::NO_READ,
281                 IOobject::NO_WRITE
282             ),
283             mesh,
284             dimensionSet(0, 2, -2, -1, 0),
285             T_.boundaryField().types()
286         )
287     );
289     volScalarField& cv = tCv();
291     forAll(T_, celli)
292     {
293         cv[celli] = this->cellMixture(celli).Cv(T_[celli]);
294     }
296     forAll(T_.boundaryField(), patchi)
297     {
298         const fvPatchScalarField& pT = T_.boundaryField()[patchi];
299         fvPatchScalarField& pCv = cv.boundaryField()[patchi];
301         forAll(pT, facei)
302         {
303             pCv[facei] = this->patchFaceMixture(patchi, facei).Cv(pT[facei]);
304         }
305     }
307     return tCv;
311 template<class MixtureType>
312 bool Foam::hThermo<MixtureType>::read()
314     if (basicThermo::read())
315     {
316         MixtureType::read(*this);
317         return true;
318     }
319     else
320     {
321         return false;
322     }
326 // ************************************************************************* //