Transferred copyright to the OpenFOAM Foundation
[OpenFOAM-2.0.x.git] / src / thermophysicalModels / basic / psiThermo / ePsiThermo / ePsiThermo.C
blobb883fb85bdcb340aab2b2e42402932c5a0e4814e
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 "ePsiThermo.H"
27 #include "fvMesh.H"
28 #include "fixedValueFvPatchFields.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 template<class MixtureType>
33 void Foam::ePsiThermo<MixtureType>::calculate()
35     const scalarField& eCells = e_.internalField();
36     const scalarField& pCells = this->p_.internalField();
38     scalarField& TCells = this->T_.internalField();
39     scalarField& psiCells = this->psi_.internalField();
40     scalarField& muCells = this->mu_.internalField();
41     scalarField& alphaCells = this->alpha_.internalField();
43     forAll(TCells, celli)
44     {
45         const typename MixtureType::thermoType& mixture_ =
46             this->cellMixture(celli);
48         TCells[celli] = mixture_.TE(eCells[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(this->T_.boundaryField(), patchi)
56     {
57         fvPatchScalarField& pp = this->p_.boundaryField()[patchi];
58         fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
59         fvPatchScalarField& ppsi = this->psi_.boundaryField()[patchi];
61         fvPatchScalarField& pe = e_.boundaryField()[patchi];
63         fvPatchScalarField& pmu = this->mu_.boundaryField()[patchi];
64         fvPatchScalarField& palpha = this->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                 pe[facei] = mixture_.E(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_.TE(pe[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::ePsiThermo<MixtureType>::ePsiThermo(const fvMesh& mesh)
103     basicPsiThermo(mesh),
104     MixtureType(*this, mesh),
106     e_
107     (
108         IOobject
109         (
110             "e",
111             mesh.time().timeName(),
112             mesh,
113             IOobject::NO_READ,
114             IOobject::NO_WRITE
115         ),
116         mesh,
117         dimEnergy/dimMass,
118         this->eBoundaryTypes()
119     )
121     scalarField& eCells = e_.internalField();
122     const scalarField& TCells = this->T_.internalField();
124     forAll(eCells, celli)
125     {
126         eCells[celli] = this->cellMixture(celli).E(TCells[celli]);
127     }
129     forAll(e_.boundaryField(), patchi)
130     {
131         e_.boundaryField()[patchi] ==
132             e(this->T_.boundaryField()[patchi], patchi);
133     }
135     this->eBoundaryCorrection(e_);
137     calculate();
139     // Switch on saving old time
140     this->psi_.oldTime();
144 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
146 template<class MixtureType>
147 Foam::ePsiThermo<MixtureType>::~ePsiThermo()
151 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
153 template<class MixtureType>
154 void Foam::ePsiThermo<MixtureType>::correct()
156     if (debug)
157     {
158         Info<< "entering ePsiThermo<MixtureType>::correct()" << endl;
159     }
161     // force the saving of the old-time values
162     this->psi_.oldTime();
164     calculate();
166     if (debug)
167     {
168         Info<< "exiting ePsiThermo<MixtureType>::correct()" << endl;
169     }
173 template<class MixtureType>
174 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::e
176     const scalarField& T,
177     const labelList& cells
178 ) const
180     tmp<scalarField> te(new scalarField(T.size()));
181     scalarField& h = te();
183     forAll(T, celli)
184     {
185         h[celli] = this->cellMixture(cells[celli]).E(T[celli]);
186     }
188     return te;
192 template<class MixtureType>
193 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::e
195     const scalarField& T,
196     const label patchi
197 ) const
199     tmp<scalarField> te(new scalarField(T.size()));
200     scalarField& h = te();
202     forAll(T, facei)
203     {
204         h[facei] = this->patchFaceMixture(patchi, facei).E(T[facei]);
205     }
207     return te;
211 template<class MixtureType>
212 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::Cp
214     const scalarField& T,
215     const label patchi
216 ) const
218     tmp<scalarField> tCp(new scalarField(T.size()));
219     scalarField& cp = tCp();
221     forAll(T, facei)
222     {
223         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
224     }
226     return tCp;
230 template<class MixtureType>
231 Foam::tmp<Foam::volScalarField> Foam::ePsiThermo<MixtureType>::Cp() const
233     const fvMesh& mesh = this->T_.mesh();
235     tmp<volScalarField> tCp
236     (
237         new volScalarField
238         (
239             IOobject
240             (
241                 "Cp",
242                 mesh.time().timeName(),
243                 mesh,
244                 IOobject::NO_READ,
245                 IOobject::NO_WRITE
246             ),
247             mesh,
248             dimEnergy/dimMass/dimTemperature
249         )
250     );
252     volScalarField& cp = tCp();
254     forAll(this->T_, celli)
255     {
256         cp[celli] = this->cellMixture(celli).Cp(this->T_[celli]);
257     }
259     forAll(this->T_.boundaryField(), patchi)
260     {
261         const fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
262         fvPatchScalarField& pCp = cp.boundaryField()[patchi];
264         forAll(pT, facei)
265         {
266             pCp[facei] = this->patchFaceMixture(patchi, facei).Cp(pT[facei]);
267         }
268     }
270     return tCp;
274 template<class MixtureType>
275 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::Cv
277     const scalarField& T,
278     const label patchi
279 ) const
281     tmp<scalarField> tCv(new scalarField(T.size()));
282     scalarField& cv = tCv();
284     forAll(T, facei)
285     {
286         cv[facei] = this->patchFaceMixture(patchi, facei).Cv(T[facei]);
287     }
289     return tCv;
293 template<class MixtureType>
294 Foam::tmp<Foam::volScalarField> Foam::ePsiThermo<MixtureType>::Cv() const
296     const fvMesh& mesh = this->T_.mesh();
298     tmp<volScalarField> tCv
299     (
300         new volScalarField
301         (
302             IOobject
303             (
304                 "Cv",
305                 mesh.time().timeName(),
306                 mesh,
307                 IOobject::NO_READ,
308                 IOobject::NO_WRITE
309             ),
310             mesh,
311             dimEnergy/dimMass/dimTemperature
312         )
313     );
315     volScalarField& cv = tCv();
317     forAll(this->T_, celli)
318     {
319         cv[celli] = this->cellMixture(celli).Cv(this->T_[celli]);
320     }
322     forAll(this->T_.boundaryField(), patchi)
323     {
324         cv.boundaryField()[patchi] =
325             Cv(this->T_.boundaryField()[patchi], patchi);
326     }
328     return tCv;
332 template<class MixtureType>
333 bool Foam::ePsiThermo<MixtureType>::read()
335     if (basicPsiThermo::read())
336     {
337         MixtureType::read(*this);
338         return true;
339     }
340     else
341     {
342         return false;
343     }
347 // ************************************************************************* //