initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / reactionThermo / combustionThermo / mixtureThermos / hPsiMixtureThermo / hPsiMixtureThermo.C
blob5a788049a62d2a649e1761ca4ae1df31f9d80047
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 "hPsiMixtureThermo.H"
28 #include "fvMesh.H"
29 #include "fixedValueFvPatchFields.H"
31 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
33 template<class MixtureType>
34 void Foam::hPsiMixtureThermo<MixtureType>::calculate()
36     const scalarField& hCells = h_.internalField();
37     const scalarField& pCells = p_.internalField();
39     scalarField& TCells = T_.internalField();
40     scalarField& psiCells = psi_.internalField();
41     scalarField& muCells = mu_.internalField();
42     scalarField& alphaCells = alpha_.internalField();
44     forAll(TCells, celli)
45     {
46         const typename MixtureType::thermoType& mixture =
47             this->cellMixture(celli);
49         TCells[celli] = mixture.TH(hCells[celli], TCells[celli]);
50         psiCells[celli] = mixture.psi(pCells[celli], TCells[celli]);
52         muCells[celli] = mixture.mu(TCells[celli]);
53         alphaCells[celli] = mixture.alpha(TCells[celli]);
54     }
56     forAll(T_.boundaryField(), patchi)
57     {
58         fvPatchScalarField& pp = p_.boundaryField()[patchi];
59         fvPatchScalarField& pT = T_.boundaryField()[patchi];
60         fvPatchScalarField& ppsi = psi_.boundaryField()[patchi];
62         fvPatchScalarField& ph = h_.boundaryField()[patchi];
64         fvPatchScalarField& pmu_ = mu_.boundaryField()[patchi];
65         fvPatchScalarField& palpha_ = alpha_.boundaryField()[patchi];
67         if (pT.fixesValue())
68         {
69             forAll(pT, facei)
70             {
71                 const typename MixtureType::thermoType& mixture =
72                     this->patchFaceMixture(patchi, facei);
74                 ph[facei] = mixture.H(pT[facei]);
76                 ppsi[facei] = mixture.psi(pp[facei], pT[facei]);
77                 pmu_[facei] = mixture.mu(pT[facei]);
78                 palpha_[facei] = mixture.alpha(pT[facei]);
79             }
80         }
81         else
82         {
83             forAll(pT, facei)
84             {
85                 const typename MixtureType::thermoType& mixture =
86                     this->patchFaceMixture(patchi, facei);
88                 pT[facei] = mixture.TH(ph[facei], pT[facei]);
90                 ppsi[facei] = mixture.psi(pp[facei], pT[facei]);
91                 pmu_[facei] = mixture.mu(pT[facei]);
92                 palpha_[facei] = mixture.alpha(pT[facei]);
93             }
94         }
95     }
99 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
101 template<class MixtureType>
102 Foam::hPsiMixtureThermo<MixtureType>::hPsiMixtureThermo(const fvMesh& mesh)
104     hCombustionThermo(mesh),
105     MixtureType(*this, mesh)
107     scalarField& hCells = h_.internalField();
108     const scalarField& TCells = T_.internalField();
110     forAll(hCells, celli)
111     {
112         hCells[celli] = this->cellMixture(celli).H(TCells[celli]);
113     }
115     forAll(h_.boundaryField(), patchi)
116     {
117         h_.boundaryField()[patchi] == h(T_.boundaryField()[patchi], patchi);
118     }
120     hBoundaryCorrection(h_);
122     calculate();
124     // Switch on saving old time
125     psi_.oldTime();
129 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
131 template<class MixtureType>
132 Foam::hPsiMixtureThermo<MixtureType>::~hPsiMixtureThermo()
136 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
138 template<class MixtureType>
139 void Foam::hPsiMixtureThermo<MixtureType>::correct()
141     if (debug)
142     {
143         Info<< "entering hPsiMixtureThermo<MixtureType>::correct()" << endl;
144     }
146     // force the saving of the old-time values
147     psi_.oldTime();
149     calculate();
151     if (debug)
152     {
153         Info<< "exiting hPsiMixtureThermo<MixtureType>::correct()" << endl;
154     }
158 template<class MixtureType>
159 Foam::tmp<Foam::volScalarField>
160 Foam::hPsiMixtureThermo<MixtureType>::hs() const
162     const fvMesh& mesh = T_.mesh();
164     tmp<volScalarField> ths
165     (
166         new volScalarField
167         (
168             IOobject
169             (
170                 "hs",
171                 mesh.time().timeName(),
172                 mesh,
173                 IOobject::NO_READ,
174                 IOobject::NO_WRITE
175             ),
176             mesh,
177             h_.dimensions()
178         )
179     );
181     volScalarField& hsf = ths();
182     scalarField& hsCells = hsf.internalField();
183     const scalarField& TCells = T_.internalField();
185     forAll(TCells, celli)
186     {
187         hsCells[celli] = this->cellMixture(celli).Hs(TCells[celli]);
188     }
190     forAll(T_.boundaryField(), patchi)
191     {
192         scalarField& hsp = hsf.boundaryField()[patchi];
193         const scalarField& Tp = T_.boundaryField()[patchi];
195         forAll(Tp, facei)
196         {
197             hsp[facei] = this->patchFaceMixture(patchi, facei).Hs(Tp[facei]);
198         }
199     }
201     return ths;
205 template<class MixtureType>
206 Foam::tmp<Foam::volScalarField>
207 Foam::hPsiMixtureThermo<MixtureType>::hc() const
209     const fvMesh& mesh = T_.mesh();
211     tmp<volScalarField> thc
212     (
213         new volScalarField
214         (
215             IOobject
216             (
217                 "hc",
218                 mesh.time().timeName(),
219                 mesh,
220                 IOobject::NO_READ,
221                 IOobject::NO_WRITE
222             ),
223             mesh,
224             h_.dimensions()
225         )
226     );
228     volScalarField& hcf = thc();
229     scalarField& hcCells = hcf.internalField();
231     forAll(hcCells, celli)
232     {
233         hcCells[celli] = this->cellMixture(celli).Hc();
234     }
236     forAll(hcf.boundaryField(), patchi)
237     {
238         scalarField& hcp = hcf.boundaryField()[patchi];
240         forAll(hcp, facei)
241         {
242             hcp[facei] = this->patchFaceMixture(patchi, facei).Hc();
243         }
244     }
246     return thc;
250 template<class MixtureType>
251 Foam::tmp<Foam::scalarField>
252 Foam::hPsiMixtureThermo<MixtureType>::h
254     const scalarField& T,
255     const labelList& cells
256 ) const
258     tmp<scalarField> th(new scalarField(T.size()));
259     scalarField& h = th();
261     forAll(T, celli)
262     {
263         h[celli] = this->cellMixture(cells[celli]).H(T[celli]);
264     }
266     return th;
270 template<class MixtureType>
271 Foam::tmp<Foam::scalarField>
272 Foam::hPsiMixtureThermo<MixtureType>::h
274     const scalarField& T,
275     const label patchi
276 ) const
278     tmp<scalarField> th(new scalarField(T.size()));
279     scalarField& h = th();
281     forAll(T, facei)
282     {
283         h[facei] = this->patchFaceMixture(patchi, facei).H(T[facei]);
284     }
286     return th;
290 template<class MixtureType>
291 Foam::tmp<Foam::scalarField>
292 Foam::hPsiMixtureThermo<MixtureType>::Cp
294     const scalarField& T,
295     const label patchi
296 ) const
298     tmp<scalarField> tCp(new scalarField(T.size()));
300     scalarField& cp = tCp();
302     forAll(T, facei)
303     {
304         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
305     }
307     return tCp;
311 template<class MixtureType>
312 Foam::tmp<Foam::volScalarField>
313 Foam::hPsiMixtureThermo<MixtureType>::Cp() const
315     const fvMesh& mesh = T_.mesh();
317     tmp<volScalarField> tCp
318     (
319         new volScalarField
320         (
321             IOobject
322             (
323                 "Cp",
324                 mesh.time().timeName(),
325                 mesh,
326                 IOobject::NO_READ,
327                 IOobject::NO_WRITE
328             ),
329             mesh,
330             dimensionSet(0, 2, -2, -1, 0)
331         )
332     );
334     volScalarField& cp = tCp();
336     scalarField& cpCells = cp.internalField();
337     const scalarField& TCells = T_.internalField();
339     forAll(TCells, celli)
340     {
341         cpCells[celli] = this->cellMixture(celli).Cp(TCells[celli]);
342     }
344     forAll(T_.boundaryField(), patchi)
345     {
346         cp.boundaryField()[patchi] = Cp(T_.boundaryField()[patchi], patchi);
347     }
349     return tCp;
353 template<class MixtureType>
354 bool Foam::hPsiMixtureThermo<MixtureType>::read()
356     if (hCombustionThermo::read())
357     {
358         MixtureType::read(*this);
359         return true;
360     }
361     else
362     {
363         return false;
364     }
368 // ************************************************************************* //