programmer's documentation
cs_cf_thermo.h
Go to the documentation of this file.
1 #ifndef __CS_CF_THERMO_H__
2 #define __CS_CF_THERMO_H__
3 
4 /*============================================================================
5  * Thermodynamic laws for the compressible module
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2015 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 
31 #include "cs_defs.h"
32 
33 /*----------------------------------------------------------------------------
34  * Standard C library headers
35  *----------------------------------------------------------------------------*/
36 
37 /*----------------------------------------------------------------------------
38  * Local headers
39  *----------------------------------------------------------------------------*/
40 
41 /*----------------------------------------------------------------------------*/
42 
44 
45 /*============================================================================
46  * Private function definitions
47  *============================================================================*/
48 
49 /*----------------------------------------------------------------------------*/
58 /*----------------------------------------------------------------------------*/
59 
60 inline static void
62  cs_real_t *cv,
64  cs_lnum_t l_size)
65 {
66  /* Local variables */
68 
69  /* Gamma is supposed to be superior or equal to 1.
70  It is computed at each call, even if this may seem costly,
71  to be coherent with the "constant gamma" case for which this
72  constant is not saved. */
73 
74  /* single ideal gas - constant gamma
75  or ideal gas mix - gamma for the mixture */
76  if (ieos == 1 || ieos == 3) {
77  for (cs_lnum_t ii = 0; ii < l_size; ii++) {
78  gamma[ii] = cp[ii]/cv[ii];
79  if (gamma[ii] < 1.)
80  bft_error(__FILE__, __LINE__, 0,
81  _("Error in thermodynamics computations for "
82  "compressible flows:\n"
83  "Value of gamma smaller to 1. encountered.\n"
84  "Gamma (specific heat ratio) must be a real number "
85  "greater or equal to 1.\n"));
86  }
87  }
88  /* stiffened gas - constant gamma (parameter of the law) */
89  else if (ieos == 2) {
90  for (cs_lnum_t ii = 0; ii < l_size; ii++)
91  gamma[ii] = cs_glob_fluid_properties->gammasg;
92  }
93 }
94 
95 /*=============================================================================
96  * Public function prototypes
97  *============================================================================*/
98 
99 /*----------------------------------------------------------------------------
100  * Set variability of isobaric specific heat and isochoric specific heat
101  * according to the chosen thermodynamic law.
102  *----------------------------------------------------------------------------*/
103 
104 void
106 
107 /*----------------------------------------------------------------------------
108  * Initialize density, total energy and isochoric specific heat
109  * according to the chosen thermodynamic law using the default parameters.
110  *----------------------------------------------------------------------------*/
111 
112 void
114 
115 // TODO: the check function should be generalized (pass the name as argument).
116 
117 /*----------------------------------------------------------------------------
118  * Check the positivity of the pressure.
119  *
120  * parameters:
121  * pres <-- array of pressure values
122  * l_size <-- l_size of the array
123  *----------------------------------------------------------------------------*/
124 
125 void
127  cs_lnum_t l_size);
128 
129 /*----------------------------------------------------------------------------
130  * Check the positivity of the internal energy.
131  *
132  * parameters:
133  * ener <-- array of total energy values
134  * l_size <-- l_size of the array
135  * vel <-- array of velocity values
136  *----------------------------------------------------------------------------*/
137 
138 void
140  cs_lnum_t l_size,
141  cs_real_3_t *vel);
142 
143 /*----------------------------------------------------------------------------
144  * Check the positivity of the density given by the user.
145  *
146  * parameters:
147  * dens <-- array of density values
148  * l_size <-- l_size of the array
149  *----------------------------------------------------------------------------*/
150 
151 void
153  cs_lnum_t l_size);
154 
155 /*----------------------------------------------------------------------------
156  * Check strict positivity of temperature (Celsius) given by the user.
157  *
158  * parameters:
159  * temp <-- array of temperature values
160  * l_size <-- l_size of the array
161  *----------------------------------------------------------------------------*/
162 
163 void
165  cs_lnum_t l_size);
166 
167 /*----------------------------------------------------------------------------
168  * Compute temperature and total energy from density and pressure.
169  *
170  * parameters:
171  * cp <-- array of isobaric specific heat values
172  * cv <-- array of isochoric specific heat values
173  * pres <-- array of pressure values
174  * dens <-- array of density values
175  * temp --> array of temperature values
176  * ener --> array of total energy values
177  * vel <-- array of velocity component values
178  * l_size <-- l_size of the array
179  *----------------------------------------------------------------------------*/
180 
181 void
183  cs_real_t *cv,
184  cs_real_t *pres,
185  cs_real_t *dens,
186  cs_real_t *temp,
187  cs_real_t *ener,
188  cs_real_3_t *vel,
189  cs_lnum_t l_size);
190 
191 /*----------------------------------------------------------------------------
192  * Compute density and total energy from pressure and temperature
193  *
194  * parameters:
195  * cp <-- array of isobaric specific heat values
196  * cv <-- array of isochoric specific heat values
197  * pres <-- array of pressure values
198  * temp <-- array of temperature values
199  * dens --> array of density values
200  * ener --> array of total energy values
201  * vel <-- array of velocity component values
202  * l_size <-- l_size of the array
203  *----------------------------------------------------------------------------*/
204 
205 void
207  cs_real_t *cv,
208  cs_real_t *pres,
209  cs_real_t *temp,
210  cs_real_t *dens,
211  cs_real_t *ener,
212  cs_real_3_t *vel,
213  cs_lnum_t l_size);
214 
215 /*----------------------------------------------------------------------------
216  * Compute density and temperature from pressure and total energy.
217  *
218  * parameters:
219  * cp <-- array of isobaric specific heat values
220  * cv <-- array of isochoric specific heat values
221  * pres <-- array of pressure values
222  * ener <-- array of total energy values
223  * dens --> array of density values
224  * temp --> array of temperature values
225  * vel <-- array of velocity component values
226  * l_size <-- l_size of the array
227  *----------------------------------------------------------------------------*/
228 
229 void
231  cs_real_t *cv,
232  cs_real_t *pres,
233  cs_real_t *ener,
234  cs_real_t *dens,
235  cs_real_t *temp,
236  cs_real_3_t *vel,
237  cs_lnum_t l_size);
238 
239 /*----------------------------------------------------------------------------
240  * Compute pressure and total energy from density and temperature
241  *
242  * parameters:
243  * cp <-- array of isobaric specific heat values
244  * cv <-- array of isochoric specific heat values
245  * dens <-- array of density values
246  * temp <-- array of temperature values
247  * pres --> array of pressure values
248  * ener --> array of total energy values
249  * vel <-- array of velocity component values
250  * l_size <-- l_size of the array
251  *----------------------------------------------------------------------------*/
252 
253 void
255  cs_real_t *cv,
256  cs_real_t *dens,
257  cs_real_t *temp,
258  cs_real_t *pres,
259  cs_real_t *ener,
260  cs_real_3_t *vel,
261  cs_lnum_t l_size);
262 
263 /*----------------------------------------------------------------------------
264  * Compute pressure and temperature from density and total energy.
265  *
266  * parameters:
267  * cp <-- array of isobaric specific heat values
268  * cv <-- array of isochoric specific heat values
269  * dens <-- array of density values
270  * ener <-- array of total energy values
271  * pres --> array of pressure values
272  * temp --> array of temperature values
273  * vel <-- array of velocity component values
274  * l_size <-- l_size of the array
275  *----------------------------------------------------------------------------*/
276 
277 void
279  cs_real_t *cv,
280  cs_real_t *dens,
281  cs_real_t *ener,
282  cs_real_t *pres,
283  cs_real_t *temp,
284  cs_real_3_t *vel,
285  cs_lnum_t l_size);
286 
287 /*----------------------------------------------------------------------------
288  * Compute square of sound velocity for perfect gas.
289  *
290  * parameters:
291  * cp <-- array of isobaric specific heat values
292  * cv <-- array of isochoric specific heat values
293  * pres <-- array of pressure values
294  * dens <-- array of density values
295  * c2 --> array of the values of the square of sound velocity
296  * l_size <-- l_size of the array
297  *----------------------------------------------------------------------------*/
298 
299 void
301  cs_real_t *cv,
302  cs_real_t *pres,
303  cs_real_t *dens,
304  cs_real_t *c2,
305  cs_lnum_t l_size);
306 
307 /*----------------------------------------------------------------------------
308  * Compute the thermal expansion coefficient for a perfect gas.
309  *
310  * parameters:
311  * cp <-- array of isobaric specific heat values
312  * cv <-- array of isochoric specific heat values
313  * dens <-- array of density values
314  * beta --> array of beta values
315  * l_size <-- l_size of the array
316  *----------------------------------------------------------------------------*/
317 
318 void
320  cs_real_t *cv,
321  cs_real_t *dens,
322  cs_real_t *beta,
323  cs_lnum_t l_size);
324 
325 /*----------------------------------------------------------------------------
326  * Compute the isochoric specific heat:
327  *
328  * parameters:
329  * cp <-- array of isobaric specific heat values
330  * xmasml <-- array of molar mass values
331  * cv --> array of isochoric specific heat values
332  * l_size <-- l_size of the array
333  *----------------------------------------------------------------------------*/
334 
335 void
337  cs_real_t *xmasml,
338  cs_real_t *cv,
339  cs_lnum_t l_size);
340 
341 /*----------------------------------------------------------------------------
342  * Compute entropy from pressure and density:
343  *
344  * parameters:
345  * cp <-- array of isobaric specific heat values
346  * cv <-- array of isochoric specific heat values
347  * dens <-- array of density values
348  * pres <-- array of pressure values
349  * entr --> array of total energy values
350  * l_size <-- l_size of the array
351  *----------------------------------------------------------------------------*/
352 
353 void
355  cs_real_t *cv,
356  cs_real_t *dens,
357  cs_real_t *pres,
358  cs_real_t *entr,
359  cs_lnum_t l_size);
360 
361 /*----------------------------------------------------------------------------
362  * Compute wall boundary condition values.
363  *
364  * parameters:
365  * wbfa --> output work array
366  * wbfb --> output work array
367  * face_id <-- boundary face index
368  *----------------------------------------------------------------------------*/
369 
370 void
372  cs_real_t *wbfb,
373  cs_lnum_t face_id);
374 
375 /*----------------------------------------------------------------------------
376  * Compute subsonic outlet boundary conditions values.
377  *
378  * parameters:
379  * bc_en <--> total energy values at boundary faces
380  * bc_pr <--> pressure values at boundary faces
381  * bc_vel <--> velocity values at boundary faces
382  * face_id <-- boundary face index
383  *----------------------------------------------------------------------------*/
384 
385 void
387  cs_real_t *bc_pr,
388  cs_real_3_t *bc_vel,
389  cs_lnum_t face_id);
390 
391 /*----------------------------------------------------------------------------
392  * Compute inlet boundary condition with total pressure and total
393  * enthalpy imposed.
394  *
395  * parameters:
396  * bc_en <--> total energy values at boundary faces
397  * bc_pr <--> pressure values at boundary faces
398  * bc_vel <--> velocity values at boundary faces
399  * face_id <-- boundary face number
400  *----------------------------------------------------------------------------*/
401 
402 void
404  cs_real_t *bc_pr,
405  cs_real_3_t *bc_vel,
406  cs_lnum_t face_id);
407 
408 /*----------------------------------------------------------------------------
409  * Compute epsilon sup for perfect gas.
410  *
411  * parameters:
412  * dens <-- array of density values
413  * eps_sup --> epsilon sup array
414  * l_size <-- l_size of the array
415  *----------------------------------------------------------------------------*/
416 
417 void
419  cs_real_t *eps_sup,
420  cs_lnum_t l_size);
421 
422 /*----------------------------------------------------------------------------
423  * This subroutine is a driver allowing to call the appropriate
424  * thermodynamical functions depending on the quantities provided by the user.
425  * Hence it is only used during the initialization step and at the boundaries
426  * of type supersonic inlet. It is described in the following how to select the
427  * quantity to be returned.
428  *
429  * When calling the user subroutine, the integer 'iccfth' specifies which
430  * calculation has to be performed (and which quantity has to be returned).
431  * The values for 'iccfth' for each case are provided below.
432  *
433  * The variables are referred to using a different index i:
434  *
435  * - pressure: 2
436  * - density: 3
437  * - temperature: 5
438  * - internal energy: 7
439  * - entropy: 13
440  *
441  * iccfth is as follows, depending on which quantity needs to be computed:
442  * - variables at cell centers from variable i and variable j (i<j):
443  * iccfth = i*j*10000
444  * - variables at boundary faces from variable i and variable j (i<j):
445  * iccfth = i*j*10000+900
446  *
447  * Detailed values of iccfth and corresponding computations:
448  *
449  * Values at the cell centers:
450  *
451  * - temperature and energy from pressure and density: iccfth = 60000
452  * - density and energy from pressure and temperature: iccfth = 100000
453  * - density and temperature from pressure and energy: iccfth = 140000
454  * - pressure and energy from density and temperature: iccfth = 150000
455  * - pressure and temperature from density and energy: iccfth = 210000
456  *
457  * Values at the faces for boundary conditions:
458  * - temperature and energy from pressure and density: iccfth = 60900
459  * - density and energy from pressure and temperature: iccfth = 100900
460  * - density and temperature from pressure and energy: iccfth = 140900
461  * - pressure and energy from density and temperature: iccfth = 150900
462  * - pressure and temperature from density and energy: iccfth = 210900
463  *
464  * parameters:
465  * iccfth --> id of computation
466  * face_id --> face index if the computation is for a B.C.
467  * bc_en <-- total energy values at boundary faces
468  * bc_pr <-- pressure values at boundary faces
469  * bc_tk <-- temperature values at boundary faces
470  * bc_vel <-- velocity values at boundary faces
471  *----------------------------------------------------------------------------*/
472 
473 void
474 cs_cf_thermo(const int iccfth,
475  cs_lnum_t face_id,
476  cs_real_t *bc_en,
477  cs_real_t *bc_pr,
478  cs_real_t *bc_tk,
479  cs_real_3_t *bc_vel);
480 
481 /*----------------------------------------------------------------------------*/
482 
484 
485 #endif /* __CS_CF_THERMO_H__ */
void cs_cf_thermo_te_from_dp(cs_real_t *cp, cs_real_t *cv, cs_real_t *pres, cs_real_t *dens, cs_real_t *temp, cs_real_t *ener, cs_real_3_t *vel, cs_lnum_t l_size)
Compute temperature and total energy from density and pressure.
Definition: cs_cf_thermo.c:344
void cs_cf_thermo_pe_from_dt(cs_real_t *cp, cs_real_t *cv, cs_real_t *dens, cs_real_t *temp, cs_real_t *pres, cs_real_t *ener, cs_real_3_t *vel, cs_lnum_t l_size)
Compute pressure and total energy from density and temperature.
Definition: cs_cf_thermo.c:565
void cs_cf_check_density(cs_real_t *dens, cs_lnum_t l_size)
Check the positivity of the density given by the user.
Definition: cs_cf_thermo.c:264
#define BEGIN_C_DECLS
Definition: cs_defs.h:429
void cs_cf_set_thermo_options(void)
Set variability of isobaric specific heat and isochoric specific heat according to the chosen thermod...
Definition: cs_cf_thermo.c:94
int ieos
Definition: cs_physical_constants.h:66
double precision, dimension(ncharm), save beta
Definition: cpincl.f90:97
Definition: cs_field_pointer.h:100
void bft_error(const char *const file_name, const int line_num, const int sys_error_code, const char *const format,...)
Calls the error handler (set by bft_error_handler_set() or default).
Definition: bft_error.c:193
void cs_cf_check_internal_energy(cs_real_t *ener, cs_lnum_t l_size, cs_real_3_t *vel)
Check the positivity of the internal energy.
Definition: cs_cf_thermo.c:221
double precision, dimension(ncharm), save c2
Definition: cpincl.f90:226
void cs_cf_thermo(const int iccfth, cs_lnum_t face_id, cs_real_t *bc_en, cs_real_t *bc_pr, cs_real_t *bc_tk, cs_real_3_t *bc_vel)
This subroutine is a driver allowing to call the appropriate thermodynamical functions depending on t...
Definition: cs_cf_thermo.c:1666
void cs_cf_thermo_wall_bc(cs_real_t *wbfa, cs_real_t *wbfb, cs_lnum_t face_id)
Compute wall boundary condition values.
Definition: cs_cf_thermo.c:918
void cs_cf_thermo_subsonic_outlet_bc(cs_real_t *bc_en, cs_real_t *bc_pr, cs_real_3_t *bc_vel, cs_lnum_t face_id)
Compute subsonic outlet boundary conditions values.
Definition: cs_cf_thermo.c:1023
void cs_cf_thermo_dt_from_pe(cs_real_t *cp, cs_real_t *cv, cs_real_t *pres, cs_real_t *ener, cs_real_t *dens, cs_real_t *temp, cs_real_3_t *vel, cs_lnum_t l_size)
Compute density and temperature from pressure and total energy;.
Definition: cs_cf_thermo.c:487
void cs_cf_check_temperature(cs_real_t *temp, cs_lnum_t l_size)
Check strict positivity of temperature (Celsius) given by the user.
Definition: cs_cf_thermo.c:301
void cs_cf_check_pressure(cs_real_t *pres, cs_lnum_t l_size)
Check the positivity of the pressure.
Definition: cs_cf_thermo.c:180
void cs_cf_thermo_pt_from_de(cs_real_t *cp, cs_real_t *cv, cs_real_t *dens, cs_real_t *ener, cs_real_t *pres, cs_real_t *temp, cs_real_3_t *vel, cs_lnum_t l_size)
Compute pressure and temperature from density and total energy.
Definition: cs_cf_thermo.c:633
Definition: cs_field_pointer.h:101
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:307
double precision, dimension(ncharm), save gamma
Definition: cpincl.f90:97
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:292
void cs_cf_thermo_s_from_dp(cs_real_t *cp, cs_real_t *cv, cs_real_t *dens, cs_real_t *pres, cs_real_t *entr, cs_lnum_t l_size)
Compute entropy from pressure and density:
Definition: cs_cf_thermo.c:862
void cs_cf_thermo_ph_inlet_bc(cs_real_t *bc_en, cs_real_t *bc_pr, cs_real_3_t *bc_vel, cs_lnum_t face_id)
Compute inlet boundary condition with total pressure and total enthalpy imposed.
Definition: cs_cf_thermo.c:1269
void cs_cf_thermo_cv(cs_real_t *cp, cs_real_t *xmasml, cs_real_t *cv, cs_lnum_t l_size)
Compute the isochoric specific heat:
Definition: cs_cf_thermo.c:824
void cs_cf_thermo_default_init(void)
Initialize density, total energy and isochoric specific heat according to the chosen thermodynamic la...
Definition: cs_cf_thermo.c:121
#define END_C_DECLS
Definition: cs_defs.h:430
#define _(String)
Definition: cs_defs.h:52
double cs_real_t
Definition: cs_defs.h:296
void cs_cf_thermo_de_from_pt(cs_real_t *cp, cs_real_t *cv, cs_real_t *pres, cs_real_t *temp, cs_real_t *dens, cs_real_t *ener, cs_real_3_t *vel, cs_lnum_t l_size)
Compute density and total energy from pressure and temperature.
Definition: cs_cf_thermo.c:416
void cs_cf_thermo_c_square(cs_real_t *cp, cs_real_t *cv, cs_real_t *pres, cs_real_t *dens, cs_real_t *c2, cs_lnum_t l_size)
Compute square of sound velocity:
Definition: cs_cf_thermo.c:714
static void cs_cf_thermo_gamma(cs_real_t *cp, cs_real_t *cv, cs_real_t *gamma, cs_lnum_t l_size)
Compute .
Definition: cs_cf_thermo.h:61
double gammasg
Definition: cs_physical_constants.h:88
integer(c_int), pointer, save ieos
indicates the equation of state for compressible module. Only perfect gas with a constant adiabatic c...
Definition: cstphy.f90:81
void cs_cf_thermo_beta(cs_real_t *cp, cs_real_t *cv, cs_real_t *dens, cs_real_t *beta, cs_lnum_t l_size)
Compute the thermal expansion coefficient:
Definition: cs_cf_thermo.c:773
void cs_cf_thermo_eps_sup(cs_real_t *dens, cs_real_t *eps_sup, cs_lnum_t l_size)
Compute epsilon sup:
Definition: cs_cf_thermo.c:1596
const cs_fluid_properties_t * cs_glob_fluid_properties
Definition: cs_physical_constants.c:310