changes to thermophysicalModels
[foam-extend-3.2.git] / src / thermophysicalModels / reactionThermo / combustionThermo / mixtureThermos / hPsiMixtureThermo / hPsiMixtureThermo.C
blobf36ca9d9a7fcb4eda21b9815a6d5e2962099e405
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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
104     const fvMesh& mesh,
105     const objectRegistry& obj
108     hCombustionThermo(mesh, obj),
109     MixtureType(*this, mesh, obj)
111     scalarField& hCells = h_.internalField();
112     const scalarField& TCells = T_.internalField();
114     forAll(hCells, celli)
115     {
116         hCells[celli] = this->cellMixture(celli).H(TCells[celli]);
117     }
119     forAll(h_.boundaryField(), patchi)
120     {
121         h_.boundaryField()[patchi] == h(T_.boundaryField()[patchi], patchi);
122     }
124     hBoundaryCorrection(h_);
126     calculate();
128     // Switch on saving old time
129     psi_.oldTime();
133 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
135 template<class MixtureType>
136 Foam::hPsiMixtureThermo<MixtureType>::~hPsiMixtureThermo()
140 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
142 template<class MixtureType>
143 void Foam::hPsiMixtureThermo<MixtureType>::correct()
145     if (debug)
146     {
147         Info<< "entering hPsiMixtureThermo<MixtureType>::correct()" << endl;
148     }
150     // force the saving of the old-time values
151     psi_.oldTime();
153     calculate();
155     if (debug)
156     {
157         Info<< "exiting hPsiMixtureThermo<MixtureType>::correct()" << endl;
158     }
162 template<class MixtureType>
163 Foam::tmp<Foam::volScalarField>
164 Foam::hPsiMixtureThermo<MixtureType>::hc() const
166     const fvMesh& mesh = T_.mesh();
168     tmp<volScalarField> thc
169     (
170         new volScalarField
171         (
172             IOobject
173             (
174                 "hc",
175                 mesh.time().timeName(),
176                 this->T_.db(),
177                 IOobject::NO_READ,
178                 IOobject::NO_WRITE
179             ),
180             mesh,
181             h_.dimensions()
182         )
183     );
185     volScalarField& hcf = thc();
186     scalarField& hcCells = hcf.internalField();
188     forAll(hcCells, celli)
189     {
190         hcCells[celli] = this->cellMixture(celli).Hc();
191     }
193     forAll(hcf.boundaryField(), patchi)
194     {
195         scalarField& hcp = hcf.boundaryField()[patchi];
197         forAll(hcp, facei)
198         {
199             hcp[facei] = this->patchFaceMixture(patchi, facei).Hc();
200         }
201     }
203     return thc;
207 template<class MixtureType>
208 Foam::tmp<Foam::scalarField>
209 Foam::hPsiMixtureThermo<MixtureType>::h
211     const scalarField& T,
212     const labelList& cells
213 ) const
215     tmp<scalarField> th(new scalarField(T.size()));
216     scalarField& h = th();
218     forAll(T, celli)
219     {
220         h[celli] = this->cellMixture(cells[celli]).H(T[celli]);
221     }
223     return th;
227 template<class MixtureType>
228 Foam::tmp<Foam::scalarField>
229 Foam::hPsiMixtureThermo<MixtureType>::h
231     const scalarField& T,
232     const label patchi
233 ) const
235     tmp<scalarField> th(new scalarField(T.size()));
236     scalarField& h = th();
238     forAll(T, facei)
239     {
240         h[facei] = this->patchFaceMixture(patchi, facei).H(T[facei]);
241     }
243     return th;
247 template<class MixtureType>
248 Foam::tmp<Foam::scalarField>
249 Foam::hPsiMixtureThermo<MixtureType>::Cp
251     const scalarField& T,
252     const label patchi
253 ) const
255     tmp<scalarField> tCp(new scalarField(T.size()));
257     scalarField& cp = tCp();
259     forAll(T, facei)
260     {
261         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
262     }
264     return tCp;
268 template<class MixtureType>
269 Foam::tmp<Foam::volScalarField>
270 Foam::hPsiMixtureThermo<MixtureType>::Cp() const
272     const fvMesh& mesh = T_.mesh();
274     tmp<volScalarField> tCp
275     (
276         new volScalarField
277         (
278             IOobject
279             (
280                 "Cp",
281                 mesh.time().timeName(),
282                 this->T_.db(),
283                 IOobject::NO_READ,
284                 IOobject::NO_WRITE
285             ),
286             mesh,
287             dimensionSet(0, 2, -2, -1, 0)
288         )
289     );
291     volScalarField& cp = tCp();
293     scalarField& cpCells = cp.internalField();
294     const scalarField& TCells = T_.internalField();
296     forAll(TCells, celli)
297     {
298         cpCells[celli] = this->cellMixture(celli).Cp(TCells[celli]);
299     }
301     forAll(T_.boundaryField(), patchi)
302     {
303         cp.boundaryField()[patchi] = Cp(T_.boundaryField()[patchi], patchi);
304     }
306     return tCp;
310 template<class MixtureType>
311 bool Foam::hPsiMixtureThermo<MixtureType>::read()
313     if (hCombustionThermo::read())
314     {
315         MixtureType::read(*this);
316         return true;
317     }
318     else
319     {
320         return false;
321     }
325 // ************************************************************************* //