initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / basic / rhoThermo / hRhoThermo / hRhoThermo.C
blobce3486fa152124a02503f5bdd6c6787eb888438c
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 "hRhoThermo.H"
29 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
31 template<class MixtureType>
32 void Foam::hRhoThermo<MixtureType>::calculate()
34     const scalarField& hCells = this->h_.internalField();
35     const scalarField& pCells = this->p_.internalField();
37     scalarField& TCells = this->T_.internalField();
38     scalarField& psiCells = this->psi_.internalField();
39     scalarField& rhoCells = this->rho_.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_.TH(hCells[celli], TCells[celli]);
49         psiCells[celli] = mixture_.psi(pCells[celli], TCells[celli]);
50         rhoCells[celli] = mixture_.rho(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];
61         fvPatchScalarField& prho = this->rho_.boundaryField()[patchi];
63         fvPatchScalarField& ph = this->h_.boundaryField()[patchi];
65         fvPatchScalarField& pmu = this->mu_.boundaryField()[patchi];
66         fvPatchScalarField& palpha = this->alpha_.boundaryField()[patchi];
68         if (pT.fixesValue())
69         {
70             forAll(pT, facei)
71             {
72                 const typename MixtureType::thermoType& mixture_ =
73                     this->patchFaceMixture(patchi, facei);
75                 ph[facei] = mixture_.H(pT[facei]);
77                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
78                 prho[facei] = mixture_.rho(pp[facei], pT[facei]);
79                 pmu[facei] = mixture_.mu(pT[facei]);
80                 palpha[facei] = mixture_.alpha(pT[facei]);
81             }
82         }
83         else
84         {
85             forAll(pT, facei)
86             {
87                 const typename MixtureType::thermoType& mixture_ =
88                     this->patchFaceMixture(patchi, facei);
90                 pT[facei] = mixture_.TH(ph[facei], pT[facei]);
92                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
93                 prho[facei] = mixture_.rho(pp[facei], pT[facei]);
94                 pmu[facei] = mixture_.mu(pT[facei]);
95                 palpha[facei] = mixture_.alpha(pT[facei]);
96             }
97         }
98     }
102 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
104 template<class MixtureType>
105 Foam::hRhoThermo<MixtureType>::hRhoThermo(const fvMesh& mesh)
107     basicRhoThermo(mesh),
108     MixtureType(*this, mesh),
110     h_
111     (
112         IOobject
113         (
114             "h",
115             mesh.time().timeName(),
116             mesh,
117             IOobject::NO_READ,
118             IOobject::NO_WRITE
119         ),
120         mesh,
121         dimensionSet(0, 2, -2, 0, 0),
122         this->hBoundaryTypes()
123     )
125     scalarField& hCells = h_.internalField();
126     const scalarField& TCells = this->T_.internalField();
128     forAll(hCells, celli)
129     {
130         hCells[celli] = this->cellMixture(celli).H(TCells[celli]);
131     }
133     forAll(h_.boundaryField(), patchi)
134     {
135         h_.boundaryField()[patchi] ==
136             h(this->T_.boundaryField()[patchi], patchi);
137     }
139     hBoundaryCorrection(h_);
141     calculate();
145 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
147 template<class MixtureType>
148 Foam::hRhoThermo<MixtureType>::~hRhoThermo()
152 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
154 template<class MixtureType>
155 void Foam::hRhoThermo<MixtureType>::correct()
157     if (debug)
158     {
159         Info<< "entering hRhoThermo<MixtureType>::correct()" << endl;
160     }
162     calculate();
164     if (debug)
165     {
166         Info<< "exiting hRhoThermo<MixtureType>::correct()" << endl;
167     }
171 template<class MixtureType>
172 Foam::tmp<Foam::scalarField> Foam::hRhoThermo<MixtureType>::h
174     const scalarField& T,
175     const labelList& cells
176 ) const
178     tmp<scalarField> th(new scalarField(T.size()));
179     scalarField& h = th();
181     forAll(T, celli)
182     {
183         h[celli] = this->cellMixture(cells[celli]).H(T[celli]);
184     }
186     return th;
190 template<class MixtureType>
191 Foam::tmp<Foam::scalarField> Foam::hRhoThermo<MixtureType>::h
193     const scalarField& T,
194     const label patchi
195 ) const
197     tmp<scalarField> th(new scalarField(T.size()));
198     scalarField& h = th();
200     forAll(T, facei)
201     {
202         h[facei] = this->patchFaceMixture(patchi, facei).H(T[facei]);
203     }
205     return th;
209 template<class MixtureType>
210 Foam::tmp<Foam::scalarField> Foam::hRhoThermo<MixtureType>::Cp
212     const scalarField& T,
213     const label patchi
214 ) const
216     tmp<scalarField> tCp(new scalarField(T.size()));
217     scalarField& cp = tCp();
219     forAll(T, facei)
220     {
221         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
222     }
224     return tCp;
228 template<class MixtureType>
229 Foam::tmp<Foam::volScalarField> Foam::hRhoThermo<MixtureType>::Cp() const
231     const fvMesh& mesh = this->T_.mesh();
233     tmp<volScalarField> tCp
234     (
235         new volScalarField
236         (
237             IOobject
238             (
239                 "Cp",
240                 mesh.time().timeName(),
241                 mesh,
242                 IOobject::NO_READ,
243                 IOobject::NO_WRITE
244             ),
245             mesh,
246             dimensionSet(0, 2, -2, -1, 0),
247             this->T_.boundaryField().types()
248         )
249     );
251     volScalarField& cp = tCp();
253     forAll(this->T_, celli)
254     {
255         cp[celli] = this->cellMixture(celli).Cp(this->T_[celli]);
256     }
258     forAll(this->T_.boundaryField(), patchi)
259     {
260         const fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
261         fvPatchScalarField& pCp = cp.boundaryField()[patchi];
263         forAll(pT, facei)
264         {
265             pCp[facei] = this->patchFaceMixture(patchi, facei).Cp(pT[facei]);
266         }
267     }
269     return tCp;
273 template<class MixtureType>
274 Foam::tmp<Foam::scalarField> Foam::hRhoThermo<MixtureType>::Cv
276     const scalarField& T,
277     const label patchi
278 ) const
280     tmp<scalarField> tCv(new scalarField(T.size()));
281     scalarField& cv = tCv();
283     forAll(T, facei)
284     {
285         cv[facei] = this->patchFaceMixture(patchi, facei).Cv(T[facei]);
286     }
288     return tCv;
292 template<class MixtureType>
293 Foam::tmp<Foam::volScalarField> Foam::hRhoThermo<MixtureType>::Cv() const
295     const fvMesh& mesh = this->T_.mesh();
297     tmp<volScalarField> tCv
298     (
299         new volScalarField
300         (
301             IOobject
302             (
303                 "Cv",
304                 mesh.time().timeName(),
305                 mesh,
306                 IOobject::NO_READ,
307                 IOobject::NO_WRITE
308             ),
309             mesh,
310             dimensionSet(0, 2, -2, -1, 0)
311         )
312     );
314     volScalarField& cv = tCv();
316     forAll(this->T_, celli)
317     {
318         cv[celli] = this->cellMixture(celli).Cv(this->T_[celli]);
319     }
321     forAll(this->T_.boundaryField(), patchi)
322     {
323         cv.boundaryField()[patchi] =
324             Cv(this->T_.boundaryField()[patchi], patchi);
325     }
327     return tCv;
331 template<class MixtureType>
332 bool Foam::hRhoThermo<MixtureType>::read()
334     if (basicRhoThermo::read())
335     {
336         MixtureType::read(*this);
337         return true;
338     }
339     else
340     {
341         return false;
342     }
346 // ************************************************************************* //