-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestscvheoscv.c
112 lines (88 loc) · 3.26 KB
/
testscvheoscv.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
/*
* A simple program to test the SCVH EOS library.
*
* Calculate the specific heat capacity from dUdT at constant rho.
*
* Author: Christian Reinhardt
* Created: 06.04.2020
* Modified:
*/
#include <math.h>
#include <stdio.h>
#include <assert.h>
#include "scvheos.h"
int main(int argc, char **argv) {
SCVHEOSMAT *Mat;
int iMat = SCVHEOS_H;
//double dKpcUnit = 2.06701e-13;
//double dMsolUnit = 4.80438e-08;
double dKpcUnit = 0.0;
double dMsolUnit = 0.0;
double rho, T;
double cv;
FILE *fp;
int i, j;
printf("SCVH EOS: Initializing material %i\n", iMat);
Mat = scvheosInitMaterial(iMat, dKpcUnit, dMsolUnit);
printf("Done.\n");
/* Calculate the specific heat capacity at the grid points that are within the range of REOS3. */
fp = fopen("testscvheoscv_grid.txt", "w");
for (j=10; j<Mat->nRho-1; j++) {
rho = pow(Mat->dLogBase, Mat->dLogRhoAxis[j]);
for (i=15; i<Mat->nT-1; i++) {
T = pow(Mat->dLogBase, Mat->dLogTAxis[i]);
// if ((i==0) && (j==0)) printf("rho0= %g T= %g\n", rho, T);
//cv = scvheosdUdTofRhoT(Mat, rho, T);
cv = T*scvheosdSdTofRhoT(Mat, rho, T);
cv = (pow(Mat->dLogBase, Mat->dLogUArray[i+1][j])-pow(Mat->dLogBase, Mat->dLogUArray[i][j]))/(pow(Mat->dLogBase, Mat->dLogTAxis[i+1])-pow(Mat->dLogBase, Mat->dLogTAxis[i]));
if (cv > 0.0) {
} else {
//fprintf(stderr, "rho= %15.7E T= %15.7E cv= %15.7E\n", rho, T, cv);
fprintf(stderr, "rho= %15.7g T= %15.7g cv= %15.7g\n", rho, T, cv);
}
fprintf(fp, "%15.7E", cv);
}
fprintf(fp, "\n");
}
fclose(fp);
/* Calculate the difference in the specific heat capacity if it is calculated from u or s. */
fp = fopen("testscvheoscv_grid_diff.txt", "w");
for (j=0; j<Mat->nRho-1; j++) {
rho = pow(Mat->dLogBase, Mat->dLogRhoAxis[j]);
for (i=0; i<Mat->nT-1; i++) {
T = pow(Mat->dLogBase, Mat->dLogTAxis[i]);
cv = T*scvheosdSdTofRhoT(Mat, rho, T);
if (fabs(cv-scvheosdUdTofRhoT(Mat, rho, T))/cv < 1e-2) {
fprintf(fp, "%3i", 1);
} else if (fabs(cv-scvheosdUdTofRhoT(Mat, rho, T))/cv < 1e-1) {
fprintf(fp, "%3i", 2);
} else {
fprintf(fp, "%3i", 3);
}
//fprintf(fp, "%15.7E", (cv-scvheosdUdTofRhoT(Mat, rho, T))/cv);
}
fprintf(fp, "\n");
}
fclose(fp);
/* Mark where cv < 0. */
fp = fopen("testscvheoscv_grid_neg.txt", "w");
for (j=10; j<Mat->nRho-1; j++) {
rho = pow(Mat->dLogBase, Mat->dLogRhoAxis[j]);
for (i=15; i<Mat->nT-1; i++) {
T = pow(Mat->dLogBase, Mat->dLogTAxis[i]);
//cv = T*scvheosdSdTofRhoT(Mat, rho, T);
cv = scvheosdUdTofRhoT(Mat, rho, T);
if (cv > 0.0) {
fprintf(fp, "%3i", 1);
} else {
fprintf(fp, "%3i", 0);
}
//fprintf(fp, "%15.7E", (cv-scvheosdUdTofRhoT(Mat, rho, T))/cv);
}
fprintf(fp, "\n");
}
printf("Free memory\n");
scvheosFinalizeMaterial(Mat);
printf("Done.\n");
return 0;
}