Initial release of the new fireFoam solver and ancillary libraries.
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / reactionThermo / reactionThermo / mixtureThermos / hRhoMixtureThermo / hRhoMixtureThermo.C
blobe12fadf8a1e86c91f3eba988e76dee9f26932097
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2009-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 "hRhoMixtureThermo.H"
28 #include "fvMesh.H"
29 #include "fixedValueFvPatchFields.H"
31 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
33 template<class MixtureType>
34 void Foam::hRhoMixtureThermo<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& rhoCells = rho_.internalField();
42     scalarField& muCells = mu_.internalField();
43     scalarField& alphaCells = alpha_.internalField();
45     forAll(TCells, celli)
46     {
47         const typename MixtureType::thermoType& mixture =
48             this->cellMixture(celli);
50         TCells[celli] = mixture.TH(hCells[celli], TCells[celli]);
51         psiCells[celli] = mixture.psi(pCells[celli], TCells[celli]);
52         rhoCells[celli] = mixture.rho(pCells[celli], TCells[celli]);
54         muCells[celli] = mixture.mu(TCells[celli]);
55         alphaCells[celli] = mixture.alpha(TCells[celli]);
56     }
58     forAll(T_.boundaryField(), patchi)
59     {
60         fvPatchScalarField& pp = p_.boundaryField()[patchi];
61         fvPatchScalarField& pT = T_.boundaryField()[patchi];
62         fvPatchScalarField& ppsi = psi_.boundaryField()[patchi];
63         fvPatchScalarField& prho = rho_.boundaryField()[patchi];
65         fvPatchScalarField& ph = h_.boundaryField()[patchi];
67         fvPatchScalarField& pmu_ = mu_.boundaryField()[patchi];
68         fvPatchScalarField& palpha_ = alpha_.boundaryField()[patchi];
70         if (pT.fixesValue())
71         {
72             forAll(pT, facei)
73             {
74                 const typename MixtureType::thermoType& mixture =
75                     this->patchFaceMixture(patchi, facei);
77                 ph[facei] = mixture.H(pT[facei]);
79                 ppsi[facei] = mixture.psi(pp[facei], pT[facei]);
80                 prho[facei] = mixture.rho(pp[facei], pT[facei]);
81                 pmu_[facei] = mixture.mu(pT[facei]);
82                 palpha_[facei] = mixture.alpha(pT[facei]);
83             }
84         }
85         else
86         {
87             forAll(pT, facei)
88             {
89                 const typename MixtureType::thermoType& mixture =
90                     this->patchFaceMixture(patchi, facei);
92                 pT[facei] = mixture.TH(ph[facei], pT[facei]);
94                 ppsi[facei] = mixture.psi(pp[facei], pT[facei]);
95                 prho[facei] = mixture.rho(pp[facei], pT[facei]);
96                 pmu_[facei] = mixture.mu(pT[facei]);
97                 palpha_[facei] = mixture.alpha(pT[facei]);
98             }
99         }
100     }
104 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
106 template<class MixtureType>
107 Foam::hRhoMixtureThermo<MixtureType>::hRhoMixtureThermo(const fvMesh& mesh)
109     hReactionThermo(mesh),
110     MixtureType(*this, mesh)
112     scalarField& hCells = h_.internalField();
113     const scalarField& TCells = T_.internalField();
115     forAll(hCells, celli)
116     {
117         hCells[celli] = this->cellMixture(celli).H(TCells[celli]);
118     }
120     forAll(h_.boundaryField(), patchi)
121     {
122         h_.boundaryField()[patchi] == h(T_.boundaryField()[patchi], patchi);
123     }
125     hBoundaryCorrection(h_);
127     calculate();
131 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
133 template<class MixtureType>
134 Foam::hRhoMixtureThermo<MixtureType>::~hRhoMixtureThermo()
138 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
140 template<class MixtureType>
141 void Foam::hRhoMixtureThermo<MixtureType>::correct()
143     if (debug)
144     {
145         Info<< "entering hRhoMixtureThermo<MixtureType>::correct()" << endl;
146     }
148     calculate();
150     if (debug)
151     {
152         Info<< "exiting hRhoMixtureThermo<MixtureType>::correct()" << endl;
153     }
157 template<class MixtureType>
158 Foam::tmp<Foam::volScalarField>
159 Foam::hRhoMixtureThermo<MixtureType>::hc() const
161     const fvMesh& mesh = T_.mesh();
163     tmp<volScalarField> thc
164     (
165         new volScalarField
166         (
167             IOobject
168             (
169                 "hc",
170                 mesh.time().timeName(),
171                 mesh,
172                 IOobject::NO_READ,
173                 IOobject::NO_WRITE
174             ),
175             mesh,
176             h_.dimensions()
177         )
178     );
180     volScalarField& hcf = thc();
181     scalarField& hcCells = hcf.internalField();
183     forAll(hcCells, celli)
184     {
185         hcCells[celli] = this->cellMixture(celli).Hc();
186     }
188     forAll(hcf.boundaryField(), patchi)
189     {
190         scalarField& hcp = hcf.boundaryField()[patchi];
192         forAll(hcp, facei)
193         {
194             hcp[facei] = this->patchFaceMixture(patchi, facei).Hc();
195         }
196     }
198     return thc;
202 template<class MixtureType>
203 Foam::tmp<Foam::scalarField>
204 Foam::hRhoMixtureThermo<MixtureType>::h
206     const scalarField& T,
207     const labelList& cells
208 ) const
210     tmp<scalarField> th(new scalarField(T.size()));
211     scalarField& h = th();
213     forAll(T, celli)
214     {
215         h[celli] = this->cellMixture(cells[celli]).H(T[celli]);
216     }
218     return th;
222 template<class MixtureType>
223 Foam::tmp<Foam::scalarField>
224 Foam::hRhoMixtureThermo<MixtureType>::h
226     const scalarField& T,
227     const label patchi
228 ) const
230     tmp<scalarField> th(new scalarField(T.size()));
231     scalarField& h = th();
233     forAll(T, facei)
234     {
235         h[facei] = this->patchFaceMixture(patchi, facei).H(T[facei]);
236     }
238     return th;
242 template<class MixtureType>
243 Foam::tmp<Foam::scalarField>
244 Foam::hRhoMixtureThermo<MixtureType>::Cp
246     const scalarField& T,
247     const label patchi
248 ) const
250     tmp<scalarField> tCp(new scalarField(T.size()));
252     scalarField& cp = tCp();
254     forAll(T, facei)
255     {
256         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
257     }
259     return tCp;
263 template<class MixtureType>
264 Foam::tmp<Foam::volScalarField>
265 Foam::hRhoMixtureThermo<MixtureType>::Cp() const
267     const fvMesh& mesh = T_.mesh();
269     tmp<volScalarField> tCp
270     (
271         new volScalarField
272         (
273             IOobject
274             (
275                 "Cp",
276                 mesh.time().timeName(),
277                 mesh,
278                 IOobject::NO_READ,
279                 IOobject::NO_WRITE
280             ),
281             mesh,
282             dimensionSet(0, 2, -2, -1, 0)
283         )
284     );
286     volScalarField& cp = tCp();
288     scalarField& cpCells = cp.internalField();
289     const scalarField& TCells = T_.internalField();
291     forAll(TCells, celli)
292     {
293         cpCells[celli] = this->cellMixture(celli).Cp(TCells[celli]);
294     }
296     forAll(T_.boundaryField(), patchi)
297     {
298         cp.boundaryField()[patchi] = Cp(T_.boundaryField()[patchi], patchi);
299     }
301     return tCp;
305 template<class MixtureType>
306 bool Foam::hRhoMixtureThermo<MixtureType>::read()
308     if (hReactionThermo::read())
309     {
310         MixtureType::read(*this);
311         return true;
312     }
313     else
314     {
315         return false;
316     }
320 // ************************************************************************* //