Initial release of the new fireFoam solver and ancillary libraries.
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / reactionThermo / combustionThermo / mixtureThermos / hPsiMixtureThermo / hPsiMixtureThermo.C
blobd354b3a98600b0a06c841e9c7c2c693b89063e10
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>::hc() const
162     const fvMesh& mesh = T_.mesh();
164     tmp<volScalarField> thc
165     (
166         new volScalarField
167         (
168             IOobject
169             (
170                 "hc",
171                 mesh.time().timeName(),
172                 mesh,
173                 IOobject::NO_READ,
174                 IOobject::NO_WRITE
175             ),
176             mesh,
177             h_.dimensions()
178         )
179     );
181     volScalarField& hcf = thc();
182     scalarField& hcCells = hcf.internalField();
184     forAll(hcCells, celli)
185     {
186         hcCells[celli] = this->cellMixture(celli).Hc();
187     }
189     forAll(hcf.boundaryField(), patchi)
190     {
191         scalarField& hcp = hcf.boundaryField()[patchi];
193         forAll(hcp, facei)
194         {
195             hcp[facei] = this->patchFaceMixture(patchi, facei).Hc();
196         }
197     }
199     return thc;
203 template<class MixtureType>
204 Foam::tmp<Foam::scalarField>
205 Foam::hPsiMixtureThermo<MixtureType>::h
207     const scalarField& T,
208     const labelList& cells
209 ) const
211     tmp<scalarField> th(new scalarField(T.size()));
212     scalarField& h = th();
214     forAll(T, celli)
215     {
216         h[celli] = this->cellMixture(cells[celli]).H(T[celli]);
217     }
219     return th;
223 template<class MixtureType>
224 Foam::tmp<Foam::scalarField>
225 Foam::hPsiMixtureThermo<MixtureType>::h
227     const scalarField& T,
228     const label patchi
229 ) const
231     tmp<scalarField> th(new scalarField(T.size()));
232     scalarField& h = th();
234     forAll(T, facei)
235     {
236         h[facei] = this->patchFaceMixture(patchi, facei).H(T[facei]);
237     }
239     return th;
243 template<class MixtureType>
244 Foam::tmp<Foam::scalarField>
245 Foam::hPsiMixtureThermo<MixtureType>::Cp
247     const scalarField& T,
248     const label patchi
249 ) const
251     tmp<scalarField> tCp(new scalarField(T.size()));
253     scalarField& cp = tCp();
255     forAll(T, facei)
256     {
257         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
258     }
260     return tCp;
264 template<class MixtureType>
265 Foam::tmp<Foam::volScalarField>
266 Foam::hPsiMixtureThermo<MixtureType>::Cp() const
268     const fvMesh& mesh = T_.mesh();
270     tmp<volScalarField> tCp
271     (
272         new volScalarField
273         (
274             IOobject
275             (
276                 "Cp",
277                 mesh.time().timeName(),
278                 mesh,
279                 IOobject::NO_READ,
280                 IOobject::NO_WRITE
281             ),
282             mesh,
283             dimensionSet(0, 2, -2, -1, 0)
284         )
285     );
287     volScalarField& cp = tCp();
289     scalarField& cpCells = cp.internalField();
290     const scalarField& TCells = T_.internalField();
292     forAll(TCells, celli)
293     {
294         cpCells[celli] = this->cellMixture(celli).Cp(TCells[celli]);
295     }
297     forAll(T_.boundaryField(), patchi)
298     {
299         cp.boundaryField()[patchi] = Cp(T_.boundaryField()[patchi], patchi);
300     }
302     return tCp;
306 template<class MixtureType>
307 bool Foam::hPsiMixtureThermo<MixtureType>::read()
309     if (hCombustionThermo::read())
310     {
311         MixtureType::read(*this);
312         return true;
313     }
314     else
315     {
316         return false;
317     }
321 // ************************************************************************* //