Forward compatibility: flex
[foam-extend-3.2.git] / src / thermophysicalModels / reactionThermo / combustionThermo / mixtureThermos / hsPsiMixtureThermo / hsPsiMixtureThermo.C
blob5dfcd1cc78277698c708923e342f0b9469c6423e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  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
35     const fvMesh& mesh,
36     const objectRegistry& obj
39     hsCombustionThermo(mesh, obj),
40     MixtureType(*this, mesh, obj)
42     scalarField& hCells = hs_.internalField();
43     const scalarField& TCells = T_.internalField();
45     forAll(hCells, celli)
46     {
47         hCells[celli] = this->cellMixture(celli).Hs(TCells[celli]);
48     }
50     forAll(hs_.boundaryField(), patchi)
51     {
52         hs_.boundaryField()[patchi] == hs(T_.boundaryField()[patchi], patchi);
53     }
55     hBoundaryCorrection(hs_);
57     calculate();
58     psi_.oldTime();   // Switch on saving old time
62 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
64 template<class MixtureType>
65 Foam::hsPsiMixtureThermo<MixtureType>::~hsPsiMixtureThermo()
69 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
71 template<class MixtureType>
72 void Foam::hsPsiMixtureThermo<MixtureType>::calculate()
74     const scalarField& hsCells = hs_.internalField();
75     const scalarField& pCells = p_.internalField();
77     scalarField& TCells = T_.internalField();
78     scalarField& psiCells = psi_.internalField();
79     scalarField& muCells = mu_.internalField();
80     scalarField& alphaCells = alpha_.internalField();
82     forAll(TCells, celli)
83     {
84         const typename MixtureType::thermoType& mixture_ =
85             this->cellMixture(celli);
87         TCells[celli] = mixture_.THs(hsCells[celli], TCells[celli]);
88         psiCells[celli] = mixture_.psi(pCells[celli], TCells[celli]);
90         muCells[celli] = mixture_.mu(TCells[celli]);
91         alphaCells[celli] = mixture_.alpha(TCells[celli]);
92     }
94     forAll(T_.boundaryField(), patchi)
95     {
96         fvPatchScalarField& pp = p_.boundaryField()[patchi];
97         fvPatchScalarField& pT = T_.boundaryField()[patchi];
98         fvPatchScalarField& ppsi = psi_.boundaryField()[patchi];
100         fvPatchScalarField& phs = hs_.boundaryField()[patchi];
102         fvPatchScalarField& pmu_ = mu_.boundaryField()[patchi];
103         fvPatchScalarField& palpha_ = alpha_.boundaryField()[patchi];
105         if (pT.fixesValue())
106         {
107             forAll(pT, facei)
108             {
109                 const typename MixtureType::thermoType& mixture_ =
110                     this->patchFaceMixture(patchi, facei);
112                 phs[facei] = mixture_.Hs(pT[facei]);
114                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
115                 pmu_[facei] = mixture_.mu(pT[facei]);
116                 palpha_[facei] = mixture_.alpha(pT[facei]);
117             }
118         }
119         else
120         {
121             forAll(pT, facei)
122             {
123                 const typename MixtureType::thermoType& mixture_ =
124                     this->patchFaceMixture(patchi, facei);
126                 pT[facei] = mixture_.THs(phs[facei], pT[facei]);
128                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
129                 pmu_[facei] = mixture_.mu(pT[facei]);
130                 palpha_[facei] = mixture_.alpha(pT[facei]);
131             }
132         }
133     }
137 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
139 template<class MixtureType>
140 void Foam::hsPsiMixtureThermo<MixtureType>::correct()
142     if (debug)
143     {
144         Info<< "entering hMixtureThermo<MixtureType>::correct()" << endl;
145     }
147     // force the saving of the old-time values
148     psi_.oldTime();
150     calculate();
152     if (debug)
153     {
154         Info<< "exiting hMixtureThermo<MixtureType>::correct()" << endl;
155     }
158 template<class MixtureType>
159 Foam::tmp<Foam::volScalarField>
160 Foam::hsPsiMixtureThermo<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                 this->T_.db(),
173                 IOobject::NO_READ,
174                 IOobject::NO_WRITE
175             ),
176             mesh,
177             hs_.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::hsPsiMixtureThermo<MixtureType>::hs
207     const scalarField& T,
208     const labelList& cells
209 ) const
211     tmp<scalarField> ths(new scalarField(T.size()));
212     scalarField& hs = ths();
214     forAll(T, celli)
215     {
216         hs[celli] = this->cellMixture(cells[celli]).Hs(T[celli]);
217     }
219     return ths;
223 template<class MixtureType>
224 Foam::tmp<Foam::scalarField>
225 Foam::hsPsiMixtureThermo<MixtureType>::hs
227     const scalarField& T,
228     const label patchi
229 ) const
231     tmp<scalarField> ths(new scalarField(T.size()));
232     scalarField& hs = ths();
234     forAll(T, facei)
235     {
236         hs[facei] = this->patchFaceMixture(patchi, facei).Hs(T[facei]);
237     }
239     return ths;
243 template<class MixtureType>
244 Foam::tmp<Foam::scalarField>
245 Foam::hsPsiMixtureThermo<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::scalarField>
266 Foam::hsPsiMixtureThermo<MixtureType>::Cp
268     const scalarField& T,
269     const labelList& cells
270 ) const
272     tmp<scalarField> tCp(new scalarField(T.size()));
273     scalarField& cp = tCp();
275     forAll(T, celli)
276     {
277         cp[celli] = this->cellMixture(cells[celli]).Cp(T[celli]);
278     }
280     return tCp;
284 template<class MixtureType>
285 Foam::tmp<Foam::volScalarField>
286 Foam::hsPsiMixtureThermo<MixtureType>::Cp() const
288     const fvMesh& mesh = T_.mesh();
290     tmp<volScalarField> tCp
291     (
292         new volScalarField
293         (
294             IOobject
295             (
296                 "Cp",
297                 mesh.time().timeName(),
298                 this->T_.db(),
299                 IOobject::NO_READ,
300                 IOobject::NO_WRITE
301             ),
302             mesh,
303             dimEnergy/dimMass/dimTemperature
304         )
305     );
307     volScalarField& cp = tCp();
309     scalarField& cpCells = cp.internalField();
310     const scalarField& TCells = T_.internalField();
312     forAll(TCells, celli)
313     {
314         cpCells[celli] = this->cellMixture(celli).Cp(TCells[celli]);
315     }
317     forAll(T_.boundaryField(), patchi)
318     {
319         cp.boundaryField()[patchi] = Cp(T_.boundaryField()[patchi], patchi);
320     }
322     return tCp;
326 template<class MixtureType>
327 bool Foam::hsPsiMixtureThermo<MixtureType>::read()
329     if (hsCombustionThermo::read())
330     {
331         MixtureType::read(*this);
332         return true;
333     }
334     else
335     {
336         return false;
337     }
341 // ************************************************************************* //