Transferred copyright to the OpenFOAM Foundation
[OpenFOAM-2.0.x.git] / src / thermophysicalModels / reactionThermo / combustionThermo / mixtureThermos / hPsiMixtureThermo / hPsiMixtureThermo.C
blobd604d13c17d9c2a519190a3085cd5d31b3039324
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "hPsiMixtureThermo.H"
27 #include "fvMesh.H"
28 #include "fixedValueFvPatchFields.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 template<class MixtureType>
33 void Foam::hPsiMixtureThermo<MixtureType>::calculate()
35     const scalarField& hCells = h_.internalField();
36     const scalarField& pCells = p_.internalField();
38     scalarField& TCells = T_.internalField();
39     scalarField& psiCells = psi_.internalField();
40     scalarField& muCells = mu_.internalField();
41     scalarField& alphaCells = alpha_.internalField();
43     forAll(TCells, celli)
44     {
45         const typename MixtureType::thermoType& mixture =
46             this->cellMixture(celli);
48         TCells[celli] = mixture.TH(hCells[celli], TCells[celli]);
49         psiCells[celli] = mixture.psi(pCells[celli], TCells[celli]);
51         muCells[celli] = mixture.mu(TCells[celli]);
52         alphaCells[celli] = mixture.alpha(TCells[celli]);
53     }
55     forAll(T_.boundaryField(), patchi)
56     {
57         fvPatchScalarField& pp = p_.boundaryField()[patchi];
58         fvPatchScalarField& pT = T_.boundaryField()[patchi];
59         fvPatchScalarField& ppsi = psi_.boundaryField()[patchi];
61         fvPatchScalarField& ph = h_.boundaryField()[patchi];
63         fvPatchScalarField& pmu_ = mu_.boundaryField()[patchi];
64         fvPatchScalarField& palpha_ = alpha_.boundaryField()[patchi];
66         if (pT.fixesValue())
67         {
68             forAll(pT, facei)
69             {
70                 const typename MixtureType::thermoType& mixture =
71                     this->patchFaceMixture(patchi, facei);
73                 ph[facei] = mixture.H(pT[facei]);
75                 ppsi[facei] = mixture.psi(pp[facei], pT[facei]);
76                 pmu_[facei] = mixture.mu(pT[facei]);
77                 palpha_[facei] = mixture.alpha(pT[facei]);
78             }
79         }
80         else
81         {
82             forAll(pT, facei)
83             {
84                 const typename MixtureType::thermoType& mixture =
85                     this->patchFaceMixture(patchi, facei);
87                 pT[facei] = mixture.TH(ph[facei], pT[facei]);
89                 ppsi[facei] = mixture.psi(pp[facei], pT[facei]);
90                 pmu_[facei] = mixture.mu(pT[facei]);
91                 palpha_[facei] = mixture.alpha(pT[facei]);
92             }
93         }
94     }
98 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
100 template<class MixtureType>
101 Foam::hPsiMixtureThermo<MixtureType>::hPsiMixtureThermo(const fvMesh& mesh)
103     hCombustionThermo(mesh),
104     MixtureType(*this, mesh)
106     scalarField& hCells = h_.internalField();
107     const scalarField& TCells = T_.internalField();
109     forAll(hCells, celli)
110     {
111         hCells[celli] = this->cellMixture(celli).H(TCells[celli]);
112     }
114     forAll(h_.boundaryField(), patchi)
115     {
116         h_.boundaryField()[patchi] == h(T_.boundaryField()[patchi], patchi);
117     }
119     hBoundaryCorrection(h_);
121     calculate();
123     // Switch on saving old time
124     psi_.oldTime();
128 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
130 template<class MixtureType>
131 Foam::hPsiMixtureThermo<MixtureType>::~hPsiMixtureThermo()
135 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
137 template<class MixtureType>
138 void Foam::hPsiMixtureThermo<MixtureType>::correct()
140     if (debug)
141     {
142         Info<< "entering hPsiMixtureThermo<MixtureType>::correct()" << endl;
143     }
145     // force the saving of the old-time values
146     psi_.oldTime();
148     calculate();
150     if (debug)
151     {
152         Info<< "exiting hPsiMixtureThermo<MixtureType>::correct()" << endl;
153     }
157 template<class MixtureType>
158 Foam::tmp<Foam::volScalarField>
159 Foam::hPsiMixtureThermo<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::hPsiMixtureThermo<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::hPsiMixtureThermo<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::hPsiMixtureThermo<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::hPsiMixtureThermo<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             dimEnergy/dimMass/dimTemperature
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::hPsiMixtureThermo<MixtureType>::read()
308     if (hCombustionThermo::read())
309     {
310         MixtureType::read(*this);
311         return true;
312     }
313     else
314     {
315         return false;
316     }
320 // ************************************************************************* //