-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextrap_scvh_on_grid.c
121 lines (93 loc) · 3.25 KB
/
extrap_scvh_on_grid.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
/*
* Extrapolate the SCvH EOS table for H-He on a different grid to check if details how the table is
* extended make a significant difference.
*
* Author: Christian Reinhardt
* Created: 30.11.2022
* Modified:
*/
#include <math.h>
#include <stdio.h>
#include <assert.h>
#include "scvheos.h"
int main(int argc, char **argv) {
// SCvH material
SCVHEOSMAT *Mat;
int iMat = SCVHEOS_HHE_LOWRHOT;
double dKpcUnit = 0.0;
double dMsolUnit = 0.0;
double *logrho;
double *logT;
double logrho_min = -14.0;
double logrho_max = -4.0;
double logT_min = 1.06;
double logT_max = 3.46;
int nRho = 201;
int nT = 31;
FILE *fp;
fprintf(stderr, "SCVHEOS: Initializing material %i\n", iMat);
Mat = scvheosInitMaterial(iMat, dKpcUnit, dMsolUnit);
/* Generate rho and T axis. */
logrho = (double *) calloc(nRho, sizeof(double));
logT = (double *) calloc(nT, sizeof(double));
for (int i=0; i<nRho; i++) {
logrho[i] = logrho_min + i*(logrho_max-logrho_min)/(nRho-1);
}
for (int i=0; i<nT; i++) {
logT[i] = logT_min + i*(logT_max-logT_min)/(nT-1);
}
/* Write an EOS table for the extrapolated values. */
fp = fopen("extrap_scvh_on_grid.txt", "w");
fprintf(fp, "# logT [K] logRho [g/cc] logP [barye] logE [erg/g] logS [erg/g/K]\n");
for (int i=0; i<nT; i++) {
for (int j=0; j<nRho; j++) {
double logP = scvheosLogPofLogRhoLogT(Mat, logrho[j], logT[i]);
double logu = scvheosLogUofLogRhoLogT(Mat, logrho[j], logT[i]);
double logs = scvheosLogSofLogRhoLogT(Mat, logrho[j], logT[i]);
fprintf(fp, "%.8e %.8e %.8e %.8e %.8e\n", logT[i], logrho[j], logP, logu, logs);
}
}
fclose(fp);
#if 0
/* Write both axis to a file. */
fp = fopen("extrap_scvh_on_grid_rhoaxis.txt", "w");
for (int i=0; i<nRho; i++) {
fprintf(fp, "%15.7E\n", logrho[i]);
}
fclose(fp);
fp = fopen("extrap_scvh_on_grid_taxis.txt", "w");
for (int i=0; i<nT; i++) {
fprintf(fp, "%15.7E\n", logT[i]);
}
fclose(fp);
/* logP(logrho, logT). */
fprintf(stderr, "Interpolating logP(logrho, logT).\n");
fp = fopen("testscvheosinterp_logpress.txt", "w");
fprintf(fp, "# Pressure logP(logrho, logT) (nRho = %i nT= %i)\n", nRho, nT);
fprintf(fp, "# Interpolator: %s (GSL)\n", gsl_interp2d_name(Mat->InterpLogP));
for (int i=0; i<nT; i++) {
for (int j=0; j<nRho; j++) {
fprintf(fp, "%15.7E", scvheosLogPofLogRhoLogT(Mat, logrhoAxis[j], logTAxis[i]));
}
fprintf(fp, "\n");
}
fclose(fp);
/* logu(logrho, logT). */
fprintf(stderr, "Interpolating logU(logrho, logT).\n");
fp = fopen("testscvheosinterp_logintenergy.txt", "w");
fprintf(fp, "# Internal energy logU(logrho, logT) (nRho = %i nT= %i)\n", nRho, nT);
fprintf(fp, "# Interpolator: %s (GSL)\n", gsl_interp2d_name(Mat->InterpLogU));
for (int i=0; i<nT; i++) {
for (int j=0; j<nRho; j++) {
fprintf(fp, "%15.7E", scvheosLogUofLogRhoLogT(Mat, logrhoAxis[j], logTAxis[i]));
}
fprintf(fp, "\n");
}
fclose(fp);
#endif
/* Free memory. */
scvheosFinalizeMaterial(Mat);
free(logrho);
free(logT);
return 0;
}