-
Notifications
You must be signed in to change notification settings - Fork 0
/
testscvheosisentropic.c
114 lines (91 loc) · 3.02 KB
/
testscvheosisentropic.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
/*
* A simple program to test the SCVH EOS library.
*
* Test the isentropic calculation of u2(rho1, u1, rho2).
*
* Author: Christian Reinhardt
* Created: 16.08.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;
//int iMat = SCVHEOS_HHE;
double dKpcUnit = 0.0;
double dMsolUnit = 0.0;
double *logrhoAxis;
double *logTAxis;
int nRho;
int nT;
FILE *fp;
fprintf(stderr, "SCVHEOS: Initializing material %i\n", iMat);
Mat = scvheosInitMaterial(iMat, dKpcUnit, dMsolUnit);
fprintf(stderr, "\n");
nRho = Mat->nRho*10;
nT = Mat->nT*10;
/* Generate rho and T axis. */
logrhoAxis = (double *) calloc(nRho, sizeof(double));
logTAxis = (double *) calloc(nT, sizeof(double));
for (int i=0; i<nRho; i++) {
logrhoAxis[i] = Mat->dLogRhoAxis[0] + i*(Mat->dLogRhoAxis[Mat->nRho-1]-Mat->dLogRhoAxis[0])/(nRho-1);
}
for (int i=0; i<nT; i++) {
logTAxis[i] = Mat->dLogTAxis[0] + i*(Mat->dLogTAxis[Mat->nT-1]-Mat->dLogTAxis[0])/(nT-1);
}
#if 0
nRho = (Mat->nRho-1)*2+1;
nT = (Mat->nT-1)*2+1;
/* Generate rho and T axis. */
logrhoAxis = (double *) calloc(nRho, sizeof(double));
logTAxis = (double *) calloc(nT, sizeof(double));
for (int i=0; i<Mat->nRho-1; i++) {
for (int j=0; j<2; j++) {
logrhoAxis[i*2+j] = Mat->dLogRhoAxis[i] + j*(Mat->dLogRhoAxis[i+1]-Mat->dLogRhoAxis[i])/2;
}
}
logrhoAxis[nRho-1] = Mat->dLogRhoAxis[Mat->nRho-1];
for (int i=0; i<Mat->nT-1; i++) {
for (int j=0; j<2; j++) {
logTAxis[i*2+j] = Mat->dLogTAxis[i] + j*(Mat->dLogTAxis[i+1]-Mat->dLogTAxis[i])/2;
}
}
logTAxis[nT-1] = Mat->dLogTAxis[Mat->nT-1];
#endif
/* Write both axis to a file. */
fp = fopen("testscvheosisentropic_rhoaxis.txt", "w");
for (int i=0; i<nRho; i++) {
fprintf(fp, "%15.7E\n", logrhoAxis[i]);
}
fclose(fp);
fp = fopen("testscvheosisentropic_taxis.txt", "w");
for (int i=0; i<nT; i++) {
fprintf(fp, "%15.7E\n", logTAxis[i]);
}
fclose(fp);
#if 0
/* Calculate the relative error on logT(logrho, logu). */
fprintf(stderr, "Calculate logT(logrho, logu) on a logrho x logT grid.\n");
fp = fopen("testscvheosinv_logtoflogrhologu.txt", "w");
fprintf(fp, "# logT(logrho, logu) (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++) {
double logu = scvheosLogUofLogRhoLogT(Mat, logrhoAxis[j], logTAxis[i]);
double logT = scvheosLogTofLogRhoLogU(Mat, logrhoAxis[j], logu);
fprintf(fp, "%15.7E", fabs((logT-logTAxis[i])/logT));
}
fprintf(fp, "\n");
}
fclose(fp);
#endif
/* Free memory. */
scvheosFinalizeMaterial(Mat);
//free(logrhoAxis);
//free(logTAxis);
return 0;
}