FreeFOAM The Cross-Platform CFD Toolkit
hPsiThermo.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "hPsiThermo.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class MixtureType>
32 {
33  const scalarField& hCells = h_.internalField();
34  const scalarField& pCells = this->p_.internalField();
35 
36  scalarField& TCells = this->T_.internalField();
37  scalarField& psiCells = this->psi_.internalField();
38  scalarField& muCells = this->mu_.internalField();
39  scalarField& alphaCells = this->alpha_.internalField();
40 
41  forAll(TCells, celli)
42  {
43  const typename MixtureType::thermoType& mixture_ =
44  this->cellMixture(celli);
45 
46  TCells[celli] = mixture_.TH(hCells[celli], TCells[celli]);
47  psiCells[celli] = mixture_.psi(pCells[celli], TCells[celli]);
48 
49  muCells[celli] = mixture_.mu(TCells[celli]);
50  alphaCells[celli] = mixture_.alpha(TCells[celli]);
51  }
52 
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];
58 
59  fvPatchScalarField& ph = h_.boundaryField()[patchi];
60 
61  fvPatchScalarField& pmu = this->mu_.boundaryField()[patchi];
62  fvPatchScalarField& palpha = this->alpha_.boundaryField()[patchi];
63 
64  if (pT.fixesValue())
65  {
66  forAll(pT, facei)
67  {
68  const typename MixtureType::thermoType& mixture_ =
69  this->patchFaceMixture(patchi, facei);
70 
71  ph[facei] = mixture_.H(pT[facei]);
72 
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);
84 
85  pT[facei] = mixture_.TH(ph[facei], pT[facei]);
86 
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  }
93 }
94 
95 
96 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
97 
98 template<class MixtureType>
100 :
101  basicPsiThermo(mesh),
102  MixtureType(*this, mesh),
103 
104  h_
105  (
106  IOobject
107  (
108  "h",
109  mesh.time().timeName(),
110  mesh,
111  IOobject::NO_READ,
112  IOobject::NO_WRITE
113  ),
114  mesh,
115  dimensionSet(0, 2, -2, 0, 0),
116  this->hBoundaryTypes()
117  )
118 {
119  scalarField& hCells = h_.internalField();
120  const scalarField& TCells = this->T_.internalField();
121 
122  forAll(hCells, celli)
123  {
124  hCells[celli] = this->cellMixture(celli).H(TCells[celli]);
125  }
126 
128  {
129  h_.boundaryField()[patchi] ==
130  h(this->T_.boundaryField()[patchi], patchi);
131  }
132 
134 
135  calculate();
136 
137  // Switch on saving old time
138  this->psi_.oldTime();
139 }
140 
141 
142 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
143 
144 template<class MixtureType>
146 {}
147 
148 
149 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
150 
151 template<class MixtureType>
153 {
154  if (debug)
155  {
156  Info<< "entering hPsiThermo<MixtureType>::correct()" << endl;
157  }
158 
159  // force the saving of the old-time values
160  this->psi_.oldTime();
161 
162  calculate();
163 
164  if (debug)
165  {
166  Info<< "exiting hPsiThermo<MixtureType>::correct()" << endl;
167  }
168 }
169 
170 
171 template<class MixtureType>
173 (
174  const scalarField& T,
175  const labelList& cells
176 ) const
177 {
178  tmp<scalarField> th(new scalarField(T.size()));
179  scalarField& h = th();
180 
181  forAll(T, celli)
182  {
183  h[celli] = this->cellMixture(cells[celli]).H(T[celli]);
184  }
185 
186  return th;
187 }
188 
189 
190 template<class MixtureType>
192 (
193  const scalarField& T,
194  const label patchi
195 ) const
196 {
197  tmp<scalarField> th(new scalarField(T.size()));
198  scalarField& h = th();
199 
200  forAll(T, facei)
201  {
202  h[facei] = this->patchFaceMixture(patchi, facei).H(T[facei]);
203  }
204 
205  return th;
206 }
207 
208 
209 template<class MixtureType>
211 (
212  const scalarField& T,
213  const label patchi
214 ) const
215 {
216  tmp<scalarField> tCp(new scalarField(T.size()));
217  scalarField& cp = tCp();
218 
219  forAll(T, facei)
220  {
221  cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
222  }
223 
224  return tCp;
225 }
226 
227 
228 template<class MixtureType>
230 {
231  const fvMesh& mesh = this->T_.mesh();
232 
234  (
235  new volScalarField
236  (
237  IOobject
238  (
239  "Cp",
240  mesh.time().timeName(),
241  mesh,
244  ),
245  mesh,
246  dimensionSet(0, 2, -2, -1, 0)
247  )
248  );
249 
250  volScalarField& cp = tCp();
251 
252  forAll(this->T_, celli)
253  {
254  cp[celli] = this->cellMixture(celli).Cp(this->T_[celli]);
255  }
256 
257  forAll(this->T_.boundaryField(), patchi)
258  {
259  const fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
261 
262  forAll(pT, facei)
263  {
264  pCp[facei] = this->patchFaceMixture(patchi, facei).Cp(pT[facei]);
265  }
266  }
267 
268  return tCp;
269 }
270 
271 
272 template<class MixtureType>
274 (
275  const scalarField& T,
276  const label patchi
277 ) const
278 {
279  tmp<scalarField> tCv(new scalarField(T.size()));
280  scalarField& cv = tCv();
281 
282  forAll(T, facei)
283  {
284  cv[facei] = this->patchFaceMixture(patchi, facei).Cv(T[facei]);
285  }
286 
287  return tCv;
288 }
289 
290 
291 template<class MixtureType>
293 {
294  const fvMesh& mesh = this->T_.mesh();
295 
297  (
298  new volScalarField
299  (
300  IOobject
301  (
302  "Cv",
303  mesh.time().timeName(),
304  mesh,
307  ),
308  mesh,
309  dimensionSet(0, 2, -2, -1, 0)
310  )
311  );
312 
313  volScalarField& cv = tCv();
314 
315  forAll(this->T_, celli)
316  {
317  cv[celli] = this->cellMixture(celli).Cv(this->T_[celli]);
318  }
319 
320  forAll(this->T_.boundaryField(), patchi)
321  {
322  cv.boundaryField()[patchi] =
323  Cv(this->T_.boundaryField()[patchi], patchi);
324  }
325 
326  return tCv;
327 }
328 
329 
330 template<class MixtureType>
332 {
333  if (basicPsiThermo::read())
334  {
335  MixtureType::read(*this);
336  return true;
337  }
338  else
339  {
340  return false;
341  }
342 }
343 
344 
345 // ************************ vim: set sw=4 sts=4 et: ************************ //