BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / thermophysicalModels / reactionThermo / combustionThermo / mixtureThermos / hsPsiMixtureThermo / hsPsiMixtureThermo.C
blob08814a64fcebc03e8581703824eb06d6df30ad50
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 "hsPsiMixtureThermo.H"
27 #include "fvMesh.H"
28 #include "fixedValueFvPatchFields.H"
30 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
32 template<class MixtureType>
33 Foam::hsPsiMixtureThermo<MixtureType>::hsPsiMixtureThermo(const fvMesh& mesh)
35     hsCombustionThermo(mesh),
36     MixtureType(*this, mesh)
38     scalarField& hCells = hs_.internalField();
39     const scalarField& TCells = T_.internalField();
41     forAll(hCells, celli)
42     {
43         hCells[celli] = this->cellMixture(celli).Hs(TCells[celli]);
44     }
46     forAll(hs_.boundaryField(), patchi)
47     {
48         hs_.boundaryField()[patchi] == hs(T_.boundaryField()[patchi], patchi);
49     }
51     hBoundaryCorrection(hs_);
53     calculate();
54     psi_.oldTime();   // Switch on saving old time
58 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
60 template<class MixtureType>
61 Foam::hsPsiMixtureThermo<MixtureType>::~hsPsiMixtureThermo()
65 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
67 template<class MixtureType>
68 void Foam::hsPsiMixtureThermo<MixtureType>::calculate()
70     const scalarField& hsCells = hs_.internalField();
71     const scalarField& pCells = p_.internalField();
73     scalarField& TCells = T_.internalField();
74     scalarField& psiCells = psi_.internalField();
75     scalarField& muCells = mu_.internalField();
76     scalarField& alphaCells = alpha_.internalField();
78     forAll(TCells, celli)
79     {
80         const typename MixtureType::thermoType& mixture_ =
81             this->cellMixture(celli);
83         TCells[celli] = mixture_.THs(hsCells[celli], TCells[celli]);
84         psiCells[celli] = mixture_.psi(pCells[celli], TCells[celli]);
86         muCells[celli] = mixture_.mu(TCells[celli]);
87         alphaCells[celli] = mixture_.alpha(TCells[celli]);
88     }
90     forAll(T_.boundaryField(), patchi)
91     {
92         fvPatchScalarField& pp = p_.boundaryField()[patchi];
93         fvPatchScalarField& pT = T_.boundaryField()[patchi];
94         fvPatchScalarField& ppsi = psi_.boundaryField()[patchi];
96         fvPatchScalarField& phs = hs_.boundaryField()[patchi];
98         fvPatchScalarField& pmu_ = mu_.boundaryField()[patchi];
99         fvPatchScalarField& palpha_ = alpha_.boundaryField()[patchi];
101         if (pT.fixesValue())
102         {
103             forAll(pT, facei)
104             {
105                 const typename MixtureType::thermoType& mixture_ =
106                     this->patchFaceMixture(patchi, facei);
108                 phs[facei] = mixture_.Hs(pT[facei]);
110                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
111                 pmu_[facei] = mixture_.mu(pT[facei]);
112                 palpha_[facei] = mixture_.alpha(pT[facei]);
113             }
114         }
115         else
116         {
117             forAll(pT, facei)
118             {
119                 const typename MixtureType::thermoType& mixture_ =
120                     this->patchFaceMixture(patchi, facei);
122                 pT[facei] = mixture_.THs(phs[facei], pT[facei]);
124                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
125                 pmu_[facei] = mixture_.mu(pT[facei]);
126                 palpha_[facei] = mixture_.alpha(pT[facei]);
127             }
128         }
129     }
133 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
135 template<class MixtureType>
136 void Foam::hsPsiMixtureThermo<MixtureType>::correct()
138     if (debug)
139     {
140         Info<< "entering hMixtureThermo<MixtureType>::correct()" << endl;
141     }
143     // force the saving of the old-time values
144     psi_.oldTime();
146     calculate();
148     if (debug)
149     {
150         Info<< "exiting hMixtureThermo<MixtureType>::correct()" << endl;
151     }
154 template<class MixtureType>
155 Foam::tmp<Foam::volScalarField>
156 Foam::hsPsiMixtureThermo<MixtureType>::hc() const
158     const fvMesh& mesh = T_.mesh();
160     tmp<volScalarField> thc
161     (
162         new volScalarField
163         (
164             IOobject
165             (
166                 "hc",
167                 mesh.time().timeName(),
168                 mesh,
169                 IOobject::NO_READ,
170                 IOobject::NO_WRITE
171             ),
172             mesh,
173             hs_.dimensions()
174         )
175     );
177     volScalarField& hcf = thc();
178     scalarField& hcCells = hcf.internalField();
180     forAll(hcCells, celli)
181     {
182         hcCells[celli] = this->cellMixture(celli).Hc();
183     }
185     forAll(hcf.boundaryField(), patchi)
186     {
187         scalarField& hcp = hcf.boundaryField()[patchi];
189         forAll(hcp, facei)
190         {
191             hcp[facei] = this->patchFaceMixture(patchi, facei).Hc();
192         }
193     }
195     return thc;
199 template<class MixtureType>
200 Foam::tmp<Foam::scalarField>
201 Foam::hsPsiMixtureThermo<MixtureType>::hs
203     const scalarField& T,
204     const labelList& cells
205 ) const
207     tmp<scalarField> ths(new scalarField(T.size()));
208     scalarField& hs = ths();
210     forAll(T, celli)
211     {
212         hs[celli] = this->cellMixture(cells[celli]).Hs(T[celli]);
213     }
215     return ths;
219 template<class MixtureType>
220 Foam::tmp<Foam::scalarField>
221 Foam::hsPsiMixtureThermo<MixtureType>::hs
223     const scalarField& T,
224     const label patchi
225 ) const
227     tmp<scalarField> ths(new scalarField(T.size()));
228     scalarField& hs = ths();
230     forAll(T, facei)
231     {
232         hs[facei] = this->patchFaceMixture(patchi, facei).Hs(T[facei]);
233     }
235     return ths;
239 template<class MixtureType>
240 Foam::tmp<Foam::scalarField>
241 Foam::hsPsiMixtureThermo<MixtureType>::Cp
243     const scalarField& T,
244     const label patchi
245 ) const
247     tmp<scalarField> tCp(new scalarField(T.size()));
249     scalarField& cp = tCp();
251     forAll(T, facei)
252     {
253         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
254     }
256     return tCp;
260 template<class MixtureType>
261 Foam::tmp<Foam::volScalarField>
262 Foam::hsPsiMixtureThermo<MixtureType>::Cp() const
264     const fvMesh& mesh = T_.mesh();
266     tmp<volScalarField> tCp
267     (
268         new volScalarField
269         (
270             IOobject
271             (
272                 "Cp",
273                 mesh.time().timeName(),
274                 mesh,
275                 IOobject::NO_READ,
276                 IOobject::NO_WRITE
277             ),
278             mesh,
279             dimEnergy/dimMass/dimTemperature
280         )
281     );
283     volScalarField& cp = tCp();
285     scalarField& cpCells = cp.internalField();
286     const scalarField& TCells = T_.internalField();
288     forAll(TCells, celli)
289     {
290         cpCells[celli] = this->cellMixture(celli).Cp(TCells[celli]);
291     }
293     forAll(T_.boundaryField(), patchi)
294     {
295         cp.boundaryField()[patchi] = Cp(T_.boundaryField()[patchi], patchi);
296     }
298     return tCp;
302 template<class MixtureType>
303 bool Foam::hsPsiMixtureThermo<MixtureType>::read()
305     if (hsCombustionThermo::read())
306     {
307         MixtureType::read(*this);
308         return true;
309     }
310     else
311     {
312         return false;
313     }
317 // ************************************************************************* //