PLUTO
radiat.c
Go to the documentation of this file.
1 #include "pluto.h"
2 /* ***************************************************************** */
3 void Radiat (double *v, double *rhs)
4 /*!
5  * Provide r.h.s. for tabulated cooling.
6  *
7  ******************************************************************* */
8 {
9  int klo, khi, kmid;
10  static int ntab;
11  double mu, T, Tmid, scrh, dT, prs;
12  static double *L_tab, *T_tab, E_cost;
13 
14  FILE *fcool;
15 
16 /* -------------------------------------------
17  Read tabulated cooling function
18  ------------------------------------------- */
19 
20  if (T_tab == NULL){
21  print1 (" > Reading table from disk...\n");
22  fcool = fopen("cooltable.dat","r");
23  if (fcool == NULL){
24  print1 ("! Radiat: cooltable.dat could not be found.\n");
25  QUIT_PLUTO(1);
26  }
27  L_tab = ARRAY_1D(20000, double);
28  T_tab = ARRAY_1D(20000, double);
29 
30  ntab = 0;
31  while (fscanf(fcool, "%lf %lf\n", T_tab + ntab,
32  L_tab + ntab)!=EOF) {
33  ntab++;
34  }
35  E_cost = UNIT_LENGTH/UNIT_DENSITY/pow(UNIT_VELOCITY, 3.0);
36  }
37 
38 /* ---------------------------------------------
39  Get pressure and temperature
40  --------------------------------------------- */
41 
42  prs = v[RHOE]*(g_gamma-1.0);
43  if (prs < 0.0) {
44  prs = g_smallPressure;
45  v[RHOE] = prs/(g_gamma - 1.0);
46  }
47 
48  mu = MeanMolecularWeight(v);
49  T = prs/v[RHO]*KELVIN*mu;
50 
51  if (T != T){
52  printf (" ! Nan found in radiat \n");
53  printf (" ! rho = %12.6e, prs = %12.6e\n",v[RHO], prs);
54  QUIT_PLUTO(1);
55  }
56 
57  if (T < g_minCoolingTemp) {
58  rhs[RHOE] = 0.0;
59  return;
60  }
61 
62 /* ----------------------------------------------
63  Table lookup by binary search
64  ---------------------------------------------- */
65 
66  klo = 0;
67  khi = ntab - 1;
68 
69  if (T > T_tab[khi] || T < T_tab[klo]){
70  print (" ! T out of range %12.6e\n",T);
71  QUIT_PLUTO(1);
72  }
73 
74  while (klo != (khi - 1)){
75  kmid = (klo + khi)/2;
76  Tmid = T_tab[kmid];
77  if (T <= Tmid){
78  khi = kmid;
79  }else if (T > Tmid){
80  klo = kmid;
81  }
82  }
83 
84 /* -----------------------------------------------
85  Compute r.h.s
86  ----------------------------------------------- */
87 
88  dT = T_tab[khi] - T_tab[klo];
89  scrh = L_tab[klo]*(T_tab[khi] - T)/dT + L_tab[khi]*(T - T_tab[klo])/dT;
90  rhs[RHOE] = -scrh*v[RHO]*v[RHO];
91 
92  scrh = UNIT_DENSITY/(CONST_amu*mu);
93  rhs[RHOE] *= E_cost*scrh*scrh;
94 }
tuple T
Definition: Sph_disk.py:33
double g_gamma
Definition: globals.h:112
#define UNIT_DENSITY
Unit density in gr/cm^3.
Definition: pluto.h:369
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
#define RHO
Definition: mod_defs.h:19
tuple scrh
Definition: configure.py:200
#define CONST_amu
Atomic mass unit.
Definition: pluto.h:253
void Radiat(double *v, double *rhs)
Definition: radiat.c:94
double g_smallPressure
Small value for pressure fix.
Definition: globals.h:110
#define KELVIN
Definition: pluto.h:401
#define UNIT_VELOCITY
Unit velocity in cm/sec.
Definition: pluto.h:377
#define UNIT_LENGTH
Unit Length in cm.
Definition: pluto.h:373
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
double g_minCoolingTemp
The minimum temperature (in K) below which cooling is suppressed.
Definition: globals.h:106
PLUTO main header file.
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
double MeanMolecularWeight(double *V)
#define QUIT_PLUTO(e_code)
Definition: macros.h:125