initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / basic / psiThermo / ePsiThermo / ePsiThermo.C
blob789f35bed9e275c24e24abb0555fd92ce54b9894
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 "ePsiThermo.H"
28 #include "fvMesh.H"
29 #include "fixedValueFvPatchFields.H"
31 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
33 template<class MixtureType>
34 void Foam::ePsiThermo<MixtureType>::calculate()
36     const scalarField& eCells = e_.internalField();
37     const scalarField& pCells = this->p_.internalField();
39     scalarField& TCells = this->T_.internalField();
40     scalarField& psiCells = this->psi_.internalField();
41     scalarField& muCells = this->mu_.internalField();
42     scalarField& alphaCells = this->alpha_.internalField();
44     forAll(TCells, celli)
45     {
46         const typename MixtureType::thermoType& mixture_ =
47             this->cellMixture(celli);
49         TCells[celli] = mixture_.TE(eCells[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(this->T_.boundaryField(), patchi)
57     {
58         fvPatchScalarField& pp = this->p_.boundaryField()[patchi];
59         fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
60         fvPatchScalarField& ppsi = this->psi_.boundaryField()[patchi];
62         fvPatchScalarField& pe = e_.boundaryField()[patchi];
64         fvPatchScalarField& pmu = this->mu_.boundaryField()[patchi];
65         fvPatchScalarField& palpha = this->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                 pe[facei] = mixture_.E(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_.TE(pe[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::ePsiThermo<MixtureType>::ePsiThermo(const fvMesh& mesh)
104     basicPsiThermo(mesh),
105     MixtureType(*this, mesh),
107     e_
108     (
109         IOobject
110         (
111             "e",
112             mesh.time().timeName(),
113             mesh,
114             IOobject::NO_READ,
115             IOobject::NO_WRITE
116         ),
117         mesh,
118         dimensionSet(0, 2, -2, 0, 0),
119         this->eBoundaryTypes()
120     )
122     scalarField& eCells = e_.internalField();
123     const scalarField& TCells = this->T_.internalField();
125     forAll(eCells, celli)
126     {
127         eCells[celli] = this->cellMixture(celli).E(TCells[celli]);
128     }
130     forAll(e_.boundaryField(), patchi)
131     {
132         e_.boundaryField()[patchi] ==
133             e(this->T_.boundaryField()[patchi], patchi);
134     }
136     this->eBoundaryCorrection(e_);
138     calculate();
140     // Switch on saving old time
141     this->psi_.oldTime();
145 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
147 template<class MixtureType>
148 Foam::ePsiThermo<MixtureType>::~ePsiThermo()
152 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
154 template<class MixtureType>
155 void Foam::ePsiThermo<MixtureType>::correct()
157     if (debug)
158     {
159         Info<< "entering ePsiThermo<MixtureType>::correct()" << endl;
160     }
162     // force the saving of the old-time values
163     this->psi_.oldTime();
165     calculate();
167     if (debug)
168     {
169         Info<< "exiting ePsiThermo<MixtureType>::correct()" << endl;
170     }
174 template<class MixtureType>
175 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::e
177     const scalarField& T,
178     const labelList& cells
179 ) const
181     tmp<scalarField> te(new scalarField(T.size()));
182     scalarField& h = te();
184     forAll(T, celli)
185     {
186         h[celli] = this->cellMixture(cells[celli]).E(T[celli]);
187     }
189     return te;
193 template<class MixtureType>
194 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::e
196     const scalarField& T,
197     const label patchi
198 ) const
200     tmp<scalarField> te(new scalarField(T.size()));
201     scalarField& h = te();
203     forAll(T, facei)
204     {
205         h[facei] = this->patchFaceMixture(patchi, facei).E(T[facei]);
206     }
208     return te;
212 template<class MixtureType>
213 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::Cp
215     const scalarField& T,
216     const label patchi
217 ) const
219     tmp<scalarField> tCp(new scalarField(T.size()));
220     scalarField& cp = tCp();
222     forAll(T, facei)
223     {
224         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
225     }
227     return tCp;
231 template<class MixtureType>
232 Foam::tmp<Foam::volScalarField> Foam::ePsiThermo<MixtureType>::Cp() const
234     const fvMesh& mesh = this->T_.mesh();
236     tmp<volScalarField> tCp
237     (
238         new volScalarField
239         (
240             IOobject
241             (
242                 "Cp",
243                 mesh.time().timeName(),
244                 mesh,
245                 IOobject::NO_READ,
246                 IOobject::NO_WRITE
247             ),
248             mesh,
249             dimensionSet(0, 2, -2, -1, 0),
250             this->T_.boundaryField().types()
251         )
252     );
254     volScalarField& cp = tCp();
256     forAll(this->T_, celli)
257     {
258         cp[celli] = this->cellMixture(celli).Cp(this->T_[celli]);
259     }
261     forAll(this->T_.boundaryField(), patchi)
262     {
263         const fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
264         fvPatchScalarField& pCp = cp.boundaryField()[patchi];
266         forAll(pT, facei)
267         {
268             pCp[facei] = this->patchFaceMixture(patchi, facei).Cp(pT[facei]);
269         }
270     }
272     return tCp;
276 template<class MixtureType>
277 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::Cv
279     const scalarField& T,
280     const label patchi
281 ) const
283     tmp<scalarField> tCv(new scalarField(T.size()));
284     scalarField& cv = tCv();
286     forAll(T, facei)
287     {
288         cv[facei] = this->patchFaceMixture(patchi, facei).Cv(T[facei]);
289     }
291     return tCv;
295 template<class MixtureType>
296 Foam::tmp<Foam::volScalarField> Foam::ePsiThermo<MixtureType>::Cv() const
298     const fvMesh& mesh = this->T_.mesh();
300     tmp<volScalarField> tCv
301     (
302         new volScalarField
303         (
304             IOobject
305             (
306                 "Cv",
307                 mesh.time().timeName(),
308                 mesh,
309                 IOobject::NO_READ,
310                 IOobject::NO_WRITE
311             ),
312             mesh,
313             dimensionSet(0, 2, -2, -1, 0)
314         )
315     );
317     volScalarField& cv = tCv();
319     forAll(this->T_, celli)
320     {
321         cv[celli] = this->cellMixture(celli).Cv(this->T_[celli]);
322     }
324     forAll(this->T_.boundaryField(), patchi)
325     {
326         cv.boundaryField()[patchi] =
327             Cv(this->T_.boundaryField()[patchi], patchi);
328     }
330     return tCv;
334 template<class MixtureType>
335 bool Foam::ePsiThermo<MixtureType>::read()
337     if (basicPsiThermo::read())
338     {
339         MixtureType::read(*this);
340         return true;
341     }
342     else
343     {
344         return false;
345     }
349 // ************************************************************************* //