PLUTO
scvh.c File Reference

Read SCvH table. More...

#include "pluto.h"
Include dependency graph for scvh.c:

Go to the source code of this file.

Macros

#define P10(a)   pow(10.0, a)
 

Functions

void ReadSCvHTable ()
 

Detailed Description

Read SCvH table.

  • read rho(T,P) and U(T,P)
  • Loop (P/rho, rho){ set T(P/rho, rho) by inverting rho(T,P) }
  • Loop (T, rho){ Find P(T,rho), set U(T,rho) = interpolate U(T,P) }
Author
A. Mignone (migno.nosp@m.ne@p.nosp@m.h.uni.nosp@m.to.i.nosp@m.t) B. Vaidya
Date
9 June, 2014

Definition in file scvh.c.

Macro Definition Documentation

#define P10 (   a)    pow(10.0, a)

Definition at line 21 of file scvh.c.

Function Documentation

void ReadSCvHTable ( )

Definition at line 23 of file scvh.c.

24 {
25  int i, j, k, nx, ny;
26  double x, xmin, xmax, dx;
27  double y, ymin, ymax, dy;
28  double rho, p, T, c[11];
29  double unit_pressure = UNIT_DENSITY*UNIT_VELOCITY*UNIT_VELOCITY;
30  Table2D e_tab, rho_tab;
31  FILE *fp;
32 
33 /* --------------------------------------------------------------
34  1. Initialize rho(T,P)
35  -------------------------------------------------------------- */
36 
37  xmin = 2.1; xmax = 7.06; dx = 0.08; /* Log(T) */
38  ymin = 4.0; ymax = 19.0; dy = 0.2; /* Log(P) */
39 
40  nx = 1 + INT_FLOOR((xmax - xmin)/dx + 0.5);
41  ny = 1 + INT_FLOOR((ymax - ymin)/dy + 0.5);
42 
43 printf ("%f %f nx = %d, ny = %d\n",(xmax-xmin)/dx,(ymax-ymin)/dy,nx,ny);
44 
45  InitializeTable2D(&rho_tab, P10(xmin), P10(xmax), nx,
46  P10(ymin), P10(ymax), ny);
47  InitializeTable2D(&e_tab, P10(xmin), P10(xmax), nx,
48  P10(ymin), P10(ymax), ny);
49 
50  fp = fopen("H_TAB_I.A","r");
51  if (fp == NULL){
52  print1 ("! File not found\n");
53  QUIT_PLUTO(1);
54  }
55 
56  for (i = 0; i < rho_tab.nx; i++) for (j = 0; j < rho_tab.ny; j++) {
57  rho_tab.f[j][i] = -90; /* -- reset table to low values -- */
58  rho_tab.defined[j][i] = 0;
59  }
60 
61  for (i = 0; i < nx; i++){
62  fscanf (fp,"%lf %d",&x, &ny);
63  for (j = 0; j < ny; j++){
64  for (k = 0; k < 11; k++) fscanf (fp,"%lf",c+k);
65  printf ("(i,j) = (%d, %d), lnT = [%f %f], lnP = [%f %f]\n",
66  i,j, x,rho_tab.lnx[i], c[0], rho_tab.lny[j]);
67  rho = pow(10.0, c[3]); /* c[3] = Log(rho) in gr/cm^3*/
68  rho_tab.f[j][i] = rho;
69  rho_tab.defined[j][i] = 1;
70  e_tab.f[j][i] = c[5]; /* c[5] = Log(e) */
71  }
72  }
73  fclose(fp);
74 
75  WriteBinaryTable2D("scvh_rho_Tp.bin", &rho_tab);
76  WriteBinaryTable2D("scvh_e_Tp.bin",&e_tab);
77 
78 /* --------------------------------------------------------------
79  2. Loop over p/rho and rho to construct T(p, rho)
80  -------------------------------------------------------------- */
81 
82  int status;
83  Table2D Ttab;
84 
85  InitializeTable2D(&Ttab, P10(3.2), P10(20.1), 256, /* p */
86  P10(-12), P10(4.065), 256); /* rho */
87 
88 /*
89 p = P10(15.0);
90 rho = P10(-10.0);
91 status = InverseLookupTable2D(&rho_tab, p, rho, &T);
92 if (status == 0) Ttab.f[j][i] = T;
93 else {
94  printf ("! Inverse not found, Log(p) = %f, Log(rho) = %f\n",
95  log10(p), log10(rho));
96  Ttab.f[j][i] = -99999.0;
97 }
98 exit(1);
99 */
100  for (j = 0; j < Ttab.ny; j++){
101  for (i = 0; i < Ttab.nx; i++){
102  rho = Ttab.y[j];
103  p = Ttab.x[i];
104  status = InverseLookupTable2D(&rho_tab, p, rho, &T);
105  if (status == 0) Ttab.f[j][i] = T;
106  else {
107  if (log10(rho) > -3 && log10(rho) < -2){
108  printf ("! Inverse not found, Log(p) = %f, Log(rho) = %f\n",
109  log10(p), log10(rho));
110  }
111  Ttab.f[j][i] = -1.0;
112  }
113  }}
114 
115  WriteBinaryTable2D("scvh_T_prho.bin", &Ttab);
116  exit(1);
117 }
tuple T
Definition: Sph_disk.py:33
double * y
array of y-values (not uniform)
Definition: structs.h:181
#define UNIT_DENSITY
Unit density in gr/cm^3.
Definition: pluto.h:369
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
int nx
Number of columns or points in the x direction.
Definition: structs.h:174
double ** f
Definition: structs.h:186
void WriteBinaryTable2D(char *fname, Table2D *tab)
Definition: math_table2D.c:528
#define UNIT_VELOCITY
Unit velocity in cm/sec.
Definition: pluto.h:377
int InverseLookupTable2D(Table2D *tab, double y, double f, double *x)
Definition: math_table2D.c:196
#define INT_FLOOR(z)
Definition: macros.h:98
int j
Definition: analysis.c:2
int ny
Number of rows or points in the y direction.
Definition: structs.h:175
int k
Definition: analysis.c:2
tuple c
Definition: menu.py:375
double * lny
array of log10(y) values (uniform)
Definition: structs.h:185
void InitializeTable2D(Table2D *tab, double xmin, double xmax, int nx, double ymin, double ymax, int ny)
Definition: math_table2D.c:15
int i
Definition: analysis.c:2
double * lnx
array of log10(x) values (uniform)
Definition: structs.h:184
static Table2D Ttab
A 2D table containing pre-computed values of temperature stored at equally spaced node values of Log...
Definition: thermal_eos.c:56
FILE * fp
Definition: analysis.c:7
char ** defined
Definition: structs.h:173
#define P10(a)
Definition: scvh.c:21
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
double * x
array of x-values (not uniform)
Definition: structs.h:180

Here is the call graph for this function: