-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestscvheosinterp.c
176 lines (135 loc) · 5.08 KB
/
testscvheosinterp.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* A simple program to test the SCVH EOS library.
*
* Test if interpolations works correctly.
*
* Author: Christian Reinhardt
* Created: 09.08.2022
* Modified: 12.08.2022
*/
#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, "Doing %s interpolation for logP(logrho, logT)\n", gsl_interp2d_name(Mat->InterpLogP));
fprintf(stderr, "\n");
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];
/* Write both axis to a file. */
fp = fopen("testscvheosinterp_rhoaxis.txt", "w");
for (int i=0; i<nRho; i++) {
fprintf(fp, "%15.7E\n", logrhoAxis[i]);
}
fclose(fp);
fp = fopen("testscvheosinterp_taxis.txt", "w");
for (int i=0; i<nT; i++) {
fprintf(fp, "%15.7E\n", logTAxis[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);
/* logs(logrho, logT). */
fprintf(stderr, "Interpolating logS(logrho, logT).\n");
fp = fopen("testscvheosinterp_logentropy.txt", "w");
fprintf(fp, "# Entropy logS(logrho, logT) (nRho = %i nT= %i)\n", nRho, nT);
fprintf(fp, "# Interpolator: %s (GSL)\n", gsl_interp2d_name(Mat->InterpLogS));
for (int i=0; i<nT; i++) {
for (int j=0; j<nRho; j++) {
fprintf(fp, "%15.7E", scvheosLogSofLogRhoLogT(Mat, logrhoAxis[j], logTAxis[i]));
}
fprintf(fp, "\n");
}
fclose(fp);
/* P(rho, T). */
fprintf(stderr, "Interpolating P(rho, T).\n");
fp = fopen("testscvheosinterp_press.txt", "w");
fprintf(fp, "# Pressure P(rho, T) (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", scvheosPofRhoT(Mat, pow(Mat->dLogBase, logrhoAxis[j]), pow(Mat->dLogBase, logTAxis[i])));
}
fprintf(fp, "\n");
}
fclose(fp);
/* u(rho, T). */
fprintf(stderr, "Interpolating U(rho, T).\n");
fp = fopen("testscvheosinterp_intenergy.txt", "w");
fprintf(fp, "# Internal energy U(rho, T) (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", scvheosUofRhoT(Mat, pow(Mat->dLogBase, logrhoAxis[j]), pow(Mat->dLogBase, logTAxis[i])));
}
fprintf(fp, "\n");
}
fclose(fp);
/* s(rho, T). */
fprintf(stderr, "Interpolating S(rho, T).\n");
fp = fopen("testscvheosinterp_entropy.txt", "w");
fprintf(fp, "# Entropy S(rho, T) (nRho = %i nT= %i)\n", nRho, nT);
fprintf(fp, "# Interpolator: %s (GSL)\n", gsl_interp2d_name(Mat->InterpLogS));
for (int i=0; i<nT; i++) {
for (int j=0; j<nRho; j++) {
fprintf(fp, "%15.7E", scvheosSofRhoT(Mat, pow(Mat->dLogBase, logrhoAxis[j]), pow(Mat->dLogBase, logTAxis[i])));
}
fprintf(fp, "\n");
}
fclose(fp);
/* Free memory. */
scvheosFinalizeMaterial(Mat);
free(logrhoAxis);
free(logTAxis);
return 0;
}