Forward compatibility: flex
[foam-extend-3.2.git] / src / thermophysicalModels / basic / psiThermo / hPsiThermo / hPsiThermo.C
blob49e9f002beba418cb665477ed595c07738db726d
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 "hPsiThermo.H"
28 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
30 template<class MixtureType>
31 void Foam::hPsiThermo<MixtureType>::calculate()
33     const scalarField& hCells = h_.internalField();
34     const scalarField& pCells = this->p_.internalField();
36     scalarField& TCells = this->T_.internalField();
37     scalarField& psiCells = this->psi_.internalField();
38     scalarField& muCells = this->mu_.internalField();
39     scalarField& alphaCells = this->alpha_.internalField();
41     forAll(TCells, celli)
42     {
43         const typename MixtureType::thermoType& mixture_ =
44             this->cellMixture(celli);
46         TCells[celli] = mixture_.TH(hCells[celli], TCells[celli]);
47         psiCells[celli] = mixture_.psi(pCells[celli], TCells[celli]);
49         muCells[celli] = mixture_.mu(TCells[celli]);
50         alphaCells[celli] = mixture_.alpha(TCells[celli]);
51     }
53     forAll(T_.boundaryField(), patchi)
54     {
55         fvPatchScalarField& pp = this->p_.boundaryField()[patchi];
56         fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
57         fvPatchScalarField& ppsi = this->psi_.boundaryField()[patchi];
59         fvPatchScalarField& ph = h_.boundaryField()[patchi];
61         fvPatchScalarField& pmu = this->mu_.boundaryField()[patchi];
62         fvPatchScalarField& palpha = this->alpha_.boundaryField()[patchi];
64         if (pT.fixesValue())
65         {
66             forAll(pT, facei)
67             {
68                 const typename MixtureType::thermoType& mixture_ =
69                     this->patchFaceMixture(patchi, facei);
71                 ph[facei] = mixture_.H(pT[facei]);
73                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
74                 pmu[facei] = mixture_.mu(pT[facei]);
75                 palpha[facei] = mixture_.alpha(pT[facei]);
76             }
77         }
78         else
79         {
80             forAll(pT, facei)
81             {
82                 const typename MixtureType::thermoType& mixture_ =
83                     this->patchFaceMixture(patchi, facei);
85                 pT[facei] = mixture_.TH(ph[facei], pT[facei]);
87                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
88                 pmu[facei] = mixture_.mu(pT[facei]);
89                 palpha[facei] = mixture_.alpha(pT[facei]);
90             }
91         }
92     }
96 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
98 template<class MixtureType>
99 Foam::hPsiThermo<MixtureType>::hPsiThermo
101     const fvMesh& mesh,
102     const objectRegistry& obj
105     basicPsiThermo(mesh, obj),
106     MixtureType(*this, mesh, obj),
108     h_
109     (
110         IOobject
111         (
112             "h",
113             mesh.time().timeName(),
114             mesh,
115             IOobject::NO_READ,
116             IOobject::NO_WRITE
117         ),
118         mesh,
119         dimensionSet(0, 2, -2, 0, 0),
120         this->hBoundaryTypes()
121     )
123     scalarField& hCells = h_.internalField();
124     const scalarField& TCells = this->T_.internalField();
126     forAll(hCells, celli)
127     {
128         hCells[celli] = this->cellMixture(celli).H(TCells[celli]);
129     }
131     forAll(h_.boundaryField(), patchi)
132     {
133         h_.boundaryField()[patchi] ==
134             h(this->T_.boundaryField()[patchi], patchi);
135     }
137     hBoundaryCorrection(h_);
139     calculate();
141     // Switch on saving old time
142     this->psi_.oldTime();
146 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
148 template<class MixtureType>
149 Foam::hPsiThermo<MixtureType>::~hPsiThermo()
153 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
155 template<class MixtureType>
156 void Foam::hPsiThermo<MixtureType>::correct()
158     if (debug)
159     {
160         Info<< "entering hPsiThermo<MixtureType>::correct()" << endl;
161     }
163     // force the saving of the old-time values
164     this->psi_.oldTime();
166     calculate();
168     if (debug)
169     {
170         Info<< "exiting hPsiThermo<MixtureType>::correct()" << endl;
171     }
175 template<class MixtureType>
176 Foam::tmp<Foam::scalarField> Foam::hPsiThermo<MixtureType>::h
178     const scalarField& T,
179     const labelList& cells
180 ) const
182     tmp<scalarField> th(new scalarField(T.size()));
183     scalarField& h = th();
185     forAll(T, celli)
186     {
187         h[celli] = this->cellMixture(cells[celli]).H(T[celli]);
188     }
190     return th;
194 template<class MixtureType>
195 Foam::tmp<Foam::scalarField> Foam::hPsiThermo<MixtureType>::h
197     const scalarField& T,
198     const label patchi
199 ) const
201     tmp<scalarField> th(new scalarField(T.size()));
202     scalarField& h = th();
204     forAll(T, facei)
205     {
206         h[facei] = this->patchFaceMixture(patchi, facei).H(T[facei]);
207     }
209     return th;
213 template<class MixtureType>
214 Foam::tmp<Foam::scalarField> Foam::hPsiThermo<MixtureType>::Cp
216     const scalarField& T,
217     const label patchi
218 ) const
220     tmp<scalarField> tCp(new scalarField(T.size()));
221     scalarField& cp = tCp();
223     forAll(T, facei)
224     {
225         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
226     }
228     return tCp;
232 template<class MixtureType>
233 Foam::tmp<Foam::scalarField> Foam::hPsiThermo<MixtureType>::Cp
235     const scalarField& T,
236     const labelList& cells
237 ) const
239     tmp<scalarField> tCp(new scalarField(T.size()));
240     scalarField& cp = tCp();
242     forAll(T, celli)
243     {
244         cp[celli] = this->cellMixture(cells[celli]).Cp(T[celli]);
245     }
247     return tCp;
251 template<class MixtureType>
252 Foam::tmp<Foam::volScalarField> Foam::hPsiThermo<MixtureType>::Cp() const
254     const fvMesh& mesh = this->T_.mesh();
256     tmp<volScalarField> tCp
257     (
258         new volScalarField
259         (
260             IOobject
261             (
262                 "Cp",
263                 mesh.time().timeName(),
264                 this->T_.db(),
265                 IOobject::NO_READ,
266                 IOobject::NO_WRITE
267             ),
268             mesh,
269             dimensionSet(0, 2, -2, -1, 0)
270         )
271     );
273     volScalarField& cp = tCp();
275     forAll(this->T_, celli)
276     {
277         cp[celli] = this->cellMixture(celli).Cp(this->T_[celli]);
278     }
280     forAll(this->T_.boundaryField(), patchi)
281     {
282         const fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
283         fvPatchScalarField& pCp = cp.boundaryField()[patchi];
285         forAll(pT, facei)
286         {
287             pCp[facei] = this->patchFaceMixture(patchi, facei).Cp(pT[facei]);
288         }
289     }
291     return tCp;
295 template<class MixtureType>
296 Foam::tmp<Foam::scalarField> Foam::hPsiThermo<MixtureType>::Cv
298     const scalarField& T,
299     const label patchi
300 ) const
302     tmp<scalarField> tCv(new scalarField(T.size()));
303     scalarField& cv = tCv();
305     forAll(T, facei)
306     {
307         cv[facei] = this->patchFaceMixture(patchi, facei).Cv(T[facei]);
308     }
310     return tCv;
314 template<class MixtureType>
315 Foam::tmp<Foam::volScalarField> Foam::hPsiThermo<MixtureType>::Cv() const
317     const fvMesh& mesh = this->T_.mesh();
319     tmp<volScalarField> tCv
320     (
321         new volScalarField
322         (
323             IOobject
324             (
325                 "Cv",
326                 mesh.time().timeName(),
327                 this->T_.db(),
328                 IOobject::NO_READ,
329                 IOobject::NO_WRITE
330             ),
331             mesh,
332             dimensionSet(0, 2, -2, -1, 0)
333         )
334     );
336     volScalarField& cv = tCv();
338     forAll(this->T_, celli)
339     {
340         cv[celli] = this->cellMixture(celli).Cv(this->T_[celli]);
341     }
343     forAll(this->T_.boundaryField(), patchi)
344     {
345         cv.boundaryField()[patchi] =
346             Cv(this->T_.boundaryField()[patchi], patchi);
347     }
349     return tCv;
353 template<class MixtureType>
354 bool Foam::hPsiThermo<MixtureType>::read()
356     if (basicPsiThermo::read())
357     {
358         MixtureType::read(*this);
359         return true;
360     }
361     else
362     {
363         return false;
364     }
368 // ************************************************************************* //