Forward compatibility: flex
[foam-extend-3.2.git] / src / thermophysicalModels / reactionThermo / combustionThermo / mixtureThermos / hPsiMixtureThermo / hPsiMixtureThermo.C
blob9a1c7013989d3b754baecb5a8c4c378a14697943
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 "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
103     const fvMesh& mesh,
104     const objectRegistry& obj
107     hCombustionThermo(mesh, obj),
108     MixtureType(*this, mesh, obj)
110     scalarField& hCells = h_.internalField();
111     const scalarField& TCells = T_.internalField();
113     forAll(hCells, celli)
114     {
115         hCells[celli] = this->cellMixture(celli).H(TCells[celli]);
116     }
118     forAll(h_.boundaryField(), patchi)
119     {
120         h_.boundaryField()[patchi] == h(T_.boundaryField()[patchi], patchi);
121     }
123     hBoundaryCorrection(h_);
125     calculate();
127     // Switch on saving old time
128     psi_.oldTime();
132 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
134 template<class MixtureType>
135 Foam::hPsiMixtureThermo<MixtureType>::~hPsiMixtureThermo()
139 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
141 template<class MixtureType>
142 void Foam::hPsiMixtureThermo<MixtureType>::correct()
144     if (debug)
145     {
146         Info<< "entering hPsiMixtureThermo<MixtureType>::correct()" << endl;
147     }
149     // force the saving of the old-time values
150     psi_.oldTime();
152     calculate();
154     if (debug)
155     {
156         Info<< "exiting hPsiMixtureThermo<MixtureType>::correct()" << endl;
157     }
161 template<class MixtureType>
162 Foam::tmp<Foam::volScalarField>
163 Foam::hPsiMixtureThermo<MixtureType>::hc() const
165     const fvMesh& mesh = T_.mesh();
167     tmp<volScalarField> thc
168     (
169         new volScalarField
170         (
171             IOobject
172             (
173                 "hc",
174                 mesh.time().timeName(),
175                 this->T_.db(),
176                 IOobject::NO_READ,
177                 IOobject::NO_WRITE
178             ),
179             mesh,
180             h_.dimensions()
181         )
182     );
184     volScalarField& hcf = thc();
185     scalarField& hcCells = hcf.internalField();
187     forAll(hcCells, celli)
188     {
189         hcCells[celli] = this->cellMixture(celli).Hc();
190     }
192     forAll(hcf.boundaryField(), patchi)
193     {
194         scalarField& hcp = hcf.boundaryField()[patchi];
196         forAll(hcp, facei)
197         {
198             hcp[facei] = this->patchFaceMixture(patchi, facei).Hc();
199         }
200     }
202     return thc;
206 template<class MixtureType>
207 Foam::tmp<Foam::scalarField>
208 Foam::hPsiMixtureThermo<MixtureType>::h
210     const scalarField& T,
211     const labelList& cells
212 ) const
214     tmp<scalarField> th(new scalarField(T.size()));
215     scalarField& h = th();
217     forAll(T, celli)
218     {
219         h[celli] = this->cellMixture(cells[celli]).H(T[celli]);
220     }
222     return th;
226 template<class MixtureType>
227 Foam::tmp<Foam::scalarField>
228 Foam::hPsiMixtureThermo<MixtureType>::h
230     const scalarField& T,
231     const label patchi
232 ) const
234     tmp<scalarField> th(new scalarField(T.size()));
235     scalarField& h = th();
237     forAll(T, facei)
238     {
239         h[facei] = this->patchFaceMixture(patchi, facei).H(T[facei]);
240     }
242     return th;
246 template<class MixtureType>
247 Foam::tmp<Foam::scalarField>
248 Foam::hPsiMixtureThermo<MixtureType>::Cp
250     const scalarField& T,
251     const label patchi
252 ) const
254     tmp<scalarField> tCp(new scalarField(T.size()));
256     scalarField& cp = tCp();
258     forAll(T, facei)
259     {
260         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
261     }
263     return tCp;
267 template<class MixtureType>
268 Foam::tmp<Foam::scalarField>
269 Foam::hPsiMixtureThermo<MixtureType>::Cp
271     const scalarField& T,
272     const labelList& cells
273 ) const
275     tmp<scalarField> tCp(new scalarField(T.size()));
276     scalarField& cp = tCp();
278     forAll(T, celli)
279     {
280         cp[celli] = this->cellMixture(cells[celli]).Cp(T[celli]);
281     }
283     return tCp;
287 template<class MixtureType>
288 Foam::tmp<Foam::volScalarField>
289 Foam::hPsiMixtureThermo<MixtureType>::Cp() const
291     const fvMesh& mesh = T_.mesh();
293     tmp<volScalarField> tCp
294     (
295         new volScalarField
296         (
297             IOobject
298             (
299                 "Cp",
300                 mesh.time().timeName(),
301                 this->T_.db(),
302                 IOobject::NO_READ,
303                 IOobject::NO_WRITE
304             ),
305             mesh,
306             dimensionSet(0, 2, -2, -1, 0)
307         )
308     );
310     volScalarField& cp = tCp();
312     scalarField& cpCells = cp.internalField();
313     const scalarField& TCells = T_.internalField();
315     forAll(TCells, celli)
316     {
317         cpCells[celli] = this->cellMixture(celli).Cp(TCells[celli]);
318     }
320     forAll(T_.boundaryField(), patchi)
321     {
322         cp.boundaryField()[patchi] = Cp(T_.boundaryField()[patchi], patchi);
323     }
325     return tCp;
329 template<class MixtureType>
330 bool Foam::hPsiMixtureThermo<MixtureType>::read()
332     if (hCombustionThermo::read())
333     {
334         MixtureType::read(*this);
335         return true;
336     }
337     else
338     {
339         return false;
340     }
344 // ************************************************************************* //