-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsneg.c
77 lines (63 loc) · 1.53 KB
/
csneg.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
/*
* Calculate the region where cs2<0 for the Tillotson EOS.
*
* Author: Christian Reinhardt
* Date: 29.12.2019
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "tillotson.h"
int main(int argc, char **argv) {
// Tillotson EOS library
TILLMATERIAL *tillMat;
double dKpcUnit = 2.06701e-13;
double dMsolUnit = 4.80438e-08;
double rho;
double a, b, c;
double Pa, Pb, Pc;
double cs2a, cs2b, cs2c;
tillMat = tillInitMaterial(GRANITE, dKpcUnit, dMsolUnit);
/*
** Find where P<0 for 0 < rho < rho0.
*/
rho=TILL_RHO_MIN;
#ifdef TILL_PRESS_MELOSH
/* In this case the pressure is set to zero for eta<0.8. */
fprintf(stderr,"TILL_PRESS_MELOSH defined!\n");
exit(1);
#endif
while (rho <= tillMat->rho0)
{
/* Do bisection to find where P<0. */
a = 1e-10;
b = tillMat->us2;
c = 0.0;
Pa = tillPressureSoundNP(tillMat, rho, a, &cs2a);
Pb = tillPressureSoundNP(tillMat, rho, b, &cs2b);
cs2c = 0.0;
fprintf(stderr, "a= %g b= %g c= %g cs2a= %g cs2b= %g cs2c= %g\n", a, b, c, cs2a, cs2b, cs2c);
while (b-a > 1e-14)
{
c = 0.5*(a + b);
Pc = tillPressureSoundNP(tillMat, rho, c, &cs2c);
if (cs2c < 0)
{
// Set a = c
a = c;
cs2a = cs2c;
} else {
// Set b = c
b = c;
cs2b = cs2c;
}
fprintf(stderr, "a= %g b= %g c= %g cs2a= %g cs2b= %g cs2c= %g\n", a, b, c, cs2a, cs2b, cs2c);
}
printf("%15.7E %15.7E\n", rho, c);
rho += 0.01;
}
fprintf(stderr,"Done.\n");
tillFinalizeMaterial(tillMat);
return 0;
}