-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesteoslookupu.c
157 lines (122 loc) · 3.37 KB
/
testeoslookupu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* This is a simple program to test the Tillotson EOS library.
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <assert.h>
#include "tillotson.h"
#define MAX(A,B) ((A) > (B) ? (A) : (B))
#define MIN(A,B) ((A) > (B) ? (B) : (A))
#define INDEX(i, j) ((i*tillmat->nTableV) + (j))
//#define TILL_PRESS_NP
double dudrho(TILLMATERIAL *mat, double rho, double u)
{
double P = (mat->dConstGamma-1.0)*rho*u/(1.0-mat->b*rho);
return (P/(rho*rho));
// return (eosPressure(mat, rho, u)/(rho*rho));
}
void main(int argc, char **argv)
{
/*
* Calculate u(rho) along an isentrope and compare to the result obtained
* from eosLookupU().
*/
double dKpcUnit = 2.06701e-13;
double dMsolUnit = 4.80438e-08;
double rhomin = 1e-4;
double rhomax = 10.0;
double vmax = 100.0;
double umin = 0.0;
double umax = 100.0;
double rho, rho1, rho2;
double u, u1, u2;
double drho, du;
// Needed for RK2
double k1u, k2u;
int nTableRho = 100;
int nTableV = 100;
// The larger mean molecular weight the more points are needed for precission
int nRho = 10000;
int nU = 10;
TILLMATERIAL *tillmat;
FILE *fp = NULL;
int i = 0;
int j = 0;
fprintf(stderr, "Initializing material...\n");
// Do not convert to code units (does this really work?)
dKpcUnit = 0.0;
dMsolUnit = 0.0;
tillmat = tillInitMaterial(IDEALGAS, dKpcUnit, dMsolUnit, nTableRho, nTableV, rhomax, vmax, 1);
fprintf(stderr, "Done.\n");
/*
* Solve isentropes numerically for different inital u.
*/
fp = fopen("testeoslookupu.txt","w");
assert(fp != NULL);
rhomax = 1.0/tillmat->b;
fprintf(stderr, "rhomax= %g b= %g\n", rhomax, tillmat->b);
rhomax *= 0.9;
drho = (rhomax - rhomin)/(nRho - 1);
du = (umax - umin)/(nU - 1);
for (i=0; i< nU; i++)
{
u = umin + i*du;
rho = rhomin;
for (j=0; j<nRho; j++)
{
/*
* Midpoint Runga-Kutta (2nd order).
*/
k1u = drho*dudrho(tillmat, rho, u);
k2u = drho*dudrho(tillmat, rho+0.5*drho, u+0.5*k1u);
u += k2u;
rho += drho;
/*
* Note: All isentropes are written into two columns and then split
* into different vectors in python.
*/
fprintf(fp, "%15.7E %15.7E\n", rho, u);
}
}
#if 0
u = 0.1;
rho = rhomin;
for (j=0; j<nRho; j++)
{
/*
* Midpoint Runga-Kutta (2nd order).
*/
k1u = drho*dudrho(tillmat, rho, u);
k2u = drho*dudrho(tillmat, rho+0.5*drho, u+0.5*k1u);
u += k2u;
rho += drho;
fprintf(fp, "%15.7E %15.7E\n", rho, u);
}
rho1 = rhomin;
u1 = 0.1;
rho2 = 0.9*rhomax;
u2 = eosLookupU(tillmat, rho1, u1, rho2, i);
printf("rho1= %15.7E u1= %15.7E rho2= %15.7E u2= %15.7E\n", rho1, u1, rho2, u2);
#endif
/*
* Use analytic solution.
*/
for (i=0; i< nU; i++)
{
u1 = umin + i*du;
rho1 = rhomin;
printf("%15.7E %15.7E\n", rho1, u1);
for (j=0; j<nRho-1; j++)
{
rho2 = (j+1)*drho;
u2 = eosLookupU(tillmat, rho1, u1, rho2, i);
printf("%15.7E %15.7E\n", rho2, u2);
rho1 = rho2;
u1 = u2;
}
}
fclose(fp);
tillFinalizeMaterial(tillmat);
}