Enable access to cell-based Cp from basicThermo
[foam-extend-3.2.git] / src / thermophysicalModels / basic / psiThermo / hPsiThermo / hPsiThermo.C
bloba76dc32a55550a013c72333db2c21e25ede36c91
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 "hPsiThermo.H"
29 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
31 template<class MixtureType>
32 void Foam::hPsiThermo<MixtureType>::calculate()
34     const scalarField& hCells = h_.internalField();
35     const scalarField& pCells = this->p_.internalField();
37     scalarField& TCells = this->T_.internalField();
38     scalarField& psiCells = this->psi_.internalField();
39     scalarField& muCells = this->mu_.internalField();
40     scalarField& alphaCells = this->alpha_.internalField();
42     forAll(TCells, celli)
43     {
44         const typename MixtureType::thermoType& mixture_ =
45             this->cellMixture(celli);
47         TCells[celli] = mixture_.TH(hCells[celli], TCells[celli]);
48         psiCells[celli] = mixture_.psi(pCells[celli], TCells[celli]);
50         muCells[celli] = mixture_.mu(TCells[celli]);
51         alphaCells[celli] = mixture_.alpha(TCells[celli]);
52     }
54     forAll(T_.boundaryField(), patchi)
55     {
56         fvPatchScalarField& pp = this->p_.boundaryField()[patchi];
57         fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
58         fvPatchScalarField& ppsi = this->psi_.boundaryField()[patchi];
60         fvPatchScalarField& ph = h_.boundaryField()[patchi];
62         fvPatchScalarField& pmu = this->mu_.boundaryField()[patchi];
63         fvPatchScalarField& palpha = this->alpha_.boundaryField()[patchi];
65         if (pT.fixesValue())
66         {
67             forAll(pT, facei)
68             {
69                 const typename MixtureType::thermoType& mixture_ =
70                     this->patchFaceMixture(patchi, facei);
72                 ph[facei] = mixture_.H(pT[facei]);
74                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
75                 pmu[facei] = mixture_.mu(pT[facei]);
76                 palpha[facei] = mixture_.alpha(pT[facei]);
77             }
78         }
79         else
80         {
81             forAll(pT, facei)
82             {
83                 const typename MixtureType::thermoType& mixture_ =
84                     this->patchFaceMixture(patchi, facei);
86                 pT[facei] = mixture_.TH(ph[facei], pT[facei]);
88                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
89                 pmu[facei] = mixture_.mu(pT[facei]);
90                 palpha[facei] = mixture_.alpha(pT[facei]);
91             }
92         }
93     }
97 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
99 template<class MixtureType>
100 Foam::hPsiThermo<MixtureType>::hPsiThermo(const fvMesh& mesh, const objectRegistry& obj)
102     basicPsiThermo(mesh, obj),
103     MixtureType(*this, mesh, obj),
105     h_
106     (
107         IOobject
108         (
109             "h",
110             mesh.time().timeName(),
111             mesh,
112             IOobject::NO_READ,
113             IOobject::NO_WRITE
114         ),
115         mesh,
116         dimensionSet(0, 2, -2, 0, 0),
117         this->hBoundaryTypes()
118     )
120     scalarField& hCells = h_.internalField();
121     const scalarField& TCells = this->T_.internalField();
123     forAll(hCells, celli)
124     {
125         hCells[celli] = this->cellMixture(celli).H(TCells[celli]);
126     }
128     forAll(h_.boundaryField(), patchi)
129     {
130         h_.boundaryField()[patchi] ==
131             h(this->T_.boundaryField()[patchi], patchi);
132     }
134     hBoundaryCorrection(h_);
136     calculate();
138     // Switch on saving old time
139     this->psi_.oldTime();
143 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
145 template<class MixtureType>
146 Foam::hPsiThermo<MixtureType>::~hPsiThermo()
150 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
152 template<class MixtureType>
153 void Foam::hPsiThermo<MixtureType>::correct()
155     if (debug)
156     {
157         Info<< "entering hPsiThermo<MixtureType>::correct()" << endl;
158     }
160     // force the saving of the old-time values
161     this->psi_.oldTime();
163     calculate();
165     if (debug)
166     {
167         Info<< "exiting hPsiThermo<MixtureType>::correct()" << endl;
168     }
172 template<class MixtureType>
173 Foam::tmp<Foam::scalarField> Foam::hPsiThermo<MixtureType>::h
175     const scalarField& T,
176     const labelList& cells
177 ) const
179     tmp<scalarField> th(new scalarField(T.size()));
180     scalarField& h = th();
182     forAll(T, celli)
183     {
184         h[celli] = this->cellMixture(cells[celli]).H(T[celli]);
185     }
187     return th;
191 template<class MixtureType>
192 Foam::tmp<Foam::scalarField> Foam::hPsiThermo<MixtureType>::h
194     const scalarField& T,
195     const label patchi
196 ) const
198     tmp<scalarField> th(new scalarField(T.size()));
199     scalarField& h = th();
201     forAll(T, facei)
202     {
203         h[facei] = this->patchFaceMixture(patchi, facei).H(T[facei]);
204     }
206     return th;
210 template<class MixtureType>
211 Foam::tmp<Foam::scalarField> Foam::hPsiThermo<MixtureType>::Cp
213     const scalarField& T,
214     const label patchi
215 ) const
217     tmp<scalarField> tCp(new scalarField(T.size()));
218     scalarField& cp = tCp();
220     forAll(T, facei)
221     {
222         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
223     }
225     return tCp;
229 template<class MixtureType>
230 Foam::tmp<Foam::scalarField> Foam::hPsiThermo<MixtureType>::Cp
232     const scalarField& T,
233     const labelList& cells
234 ) const
236     tmp<scalarField> tCp(new scalarField(T.size()));
237     scalarField& cp = tCp();
239     forAll(T, celli)
240     {
241         cp[celli] = this->cellMixture(cells[celli]).Cp(T[celli]);
242     }
244     return tCp;
248 template<class MixtureType>
249 Foam::tmp<Foam::volScalarField> Foam::hPsiThermo<MixtureType>::Cp() const
251     const fvMesh& mesh = this->T_.mesh();
253     tmp<volScalarField> tCp
254     (
255         new volScalarField
256         (
257             IOobject
258             (
259                 "Cp",
260                 mesh.time().timeName(),
261                 this->T_.db(),
262                 IOobject::NO_READ,
263                 IOobject::NO_WRITE
264             ),
265             mesh,
266             dimensionSet(0, 2, -2, -1, 0)
267         )
268     );
270     volScalarField& cp = tCp();
272     forAll(this->T_, celli)
273     {
274         cp[celli] = this->cellMixture(celli).Cp(this->T_[celli]);
275     }
277     forAll(this->T_.boundaryField(), patchi)
278     {
279         const fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
280         fvPatchScalarField& pCp = cp.boundaryField()[patchi];
282         forAll(pT, facei)
283         {
284             pCp[facei] = this->patchFaceMixture(patchi, facei).Cp(pT[facei]);
285         }
286     }
288     return tCp;
292 template<class MixtureType>
293 Foam::tmp<Foam::scalarField> Foam::hPsiThermo<MixtureType>::Cv
295     const scalarField& T,
296     const label patchi
297 ) const
299     tmp<scalarField> tCv(new scalarField(T.size()));
300     scalarField& cv = tCv();
302     forAll(T, facei)
303     {
304         cv[facei] = this->patchFaceMixture(patchi, facei).Cv(T[facei]);
305     }
307     return tCv;
311 template<class MixtureType>
312 Foam::tmp<Foam::volScalarField> Foam::hPsiThermo<MixtureType>::Cv() const
314     const fvMesh& mesh = this->T_.mesh();
316     tmp<volScalarField> tCv
317     (
318         new volScalarField
319         (
320             IOobject
321             (
322                 "Cv",
323                 mesh.time().timeName(),
324                 this->T_.db(),
325                 IOobject::NO_READ,
326                 IOobject::NO_WRITE
327             ),
328             mesh,
329             dimensionSet(0, 2, -2, -1, 0)
330         )
331     );
333     volScalarField& cv = tCv();
335     forAll(this->T_, celli)
336     {
337         cv[celli] = this->cellMixture(celli).Cv(this->T_[celli]);
338     }
340     forAll(this->T_.boundaryField(), patchi)
341     {
342         cv.boundaryField()[patchi] =
343             Cv(this->T_.boundaryField()[patchi], patchi);
344     }
346     return tCv;
350 template<class MixtureType>
351 bool Foam::hPsiThermo<MixtureType>::read()
353     if (basicPsiThermo::read())
354     {
355         MixtureType::read(*this);
356         return true;
357     }
358     else
359     {
360         return false;
361     }
365 // ************************************************************************* //