forked from ShawnHoose/planet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HotJupiter.cpp
65 lines (46 loc) · 1.36 KB
/
HotJupiter.cpp
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
#include<iostream>
#include<cmath>
#include<fstream>
#include<iomanip>
using namespace std;
int main(){
ofstream data_output;
double P1, Pc,dP, Lad, Lin;
double R , z , den1 , grav , T1, Td;
double exp1, exp2;
double X = 1.0;
double P2, dz, den2, T2;
int alpha=1, beta=0;//, count = 0;
//Declaration Block
Td = 1500.0;
Pc = 1.0e9;
dP = 2e3;
Lad = (2.0/7.0);
Lin = (1.0/2.0);
grav = -1.0e3;
R = (1.38e-16)/(2.34*1.66e-24);
exp1=1 + alpha;
exp2=(1.0/(4.0-beta));
P1 = 1.0e9;
z=0;
//Open data file
data_output.open ("newmodelcpp.hse",ios::out);
data_output << "# npts = 499999" << '\n' << "# num of variables = 4" << '\n' << "# density" << '\n' << "# temperature" <<'\n' << "# pressure" << '\n' << "# X " << '\n';
//Iterate over values until density is 0 using constant dP
do{
P2 = P1-dP;
T1 = Td * pow(1.0 + (Lad / (Lin - Lad))*pow((P1/Pc),exp1),exp2);
T2 = Td * pow(1.0 + (Lad / (Lin - Lad))*pow((P2/Pc),exp1),exp2);
den1 = (P1/(R*T1));
den2 = (P2/(R*T2));
dz = - (P1-P2)* (1.0/grav)*(1.0/2.0)*((1.0/den1)+(1.0/den2));
data_output << setprecision(10) << z << ' ' << den1 << ' ' << T1 << ' ' << P1 << ' '<< X << '\n';
z = z + dz;
P1 = P2;
/* cout << count << '\n';
count++;*/
}while(den1 > 1e-7);
//Close data file
data_output.close();
return 0;
}