1 | #!/usr/bin/env python
|
---|
2 |
|
---|
3 | #Need to add n_p, the neutral density at planet surface to problem.data
|
---|
4 |
|
---|
5 | import math
|
---|
6 |
|
---|
7 | Gamma, M_p, T_p, Lambda_p, rho_p, Lx, Nx, max_L = (None for i in range(8))
|
---|
8 |
|
---|
9 | # read these from astrobear constant file
|
---|
10 | G = 6.67e-8
|
---|
11 | k_B = 1.381e-16
|
---|
12 | m_H = 1.673e-24
|
---|
13 | sigma = 6.3e-18
|
---|
14 | M_J = 1.898e30
|
---|
15 | R_J = 7.1492e9
|
---|
16 |
|
---|
17 | # read in dx, Gamma, M_p, Cs_p, R_p
|
---|
18 | with open('physics.data') as infile:
|
---|
19 | for line in infile:
|
---|
20 | sline = line.strip().split('!', 1)[0]
|
---|
21 | if sline is "":
|
---|
22 | continue
|
---|
23 | if sline.split()[0] == "gamma":
|
---|
24 | Gamma = float(sline.split()[2].replace("d", "e"))
|
---|
25 | with open('problem.data') as infile:
|
---|
26 | for line in infile:
|
---|
27 | sline = line.strip().split('!', 1)[0]
|
---|
28 | if sline is "":
|
---|
29 | continue
|
---|
30 | sline = sline.split()
|
---|
31 | if sline[0] == "planetMass":
|
---|
32 | M_p = float(sline[2].replace("d", "e"))*M_J
|
---|
33 | if sline[0] == "planetTemp":
|
---|
34 | T_p = float(sline[2].replace("d", "e"))
|
---|
35 | if sline[0] == "planetRadius":
|
---|
36 | R_p = float(sline[2].replace("d", "e"))*R_J
|
---|
37 | if sline[0] == "planetDensity":
|
---|
38 | rho_p = float(sline[2].replace("d", "e"))
|
---|
39 | with open('global.data') as infile:
|
---|
40 | for line in infile:
|
---|
41 | sline = line.strip().split('!', 1)[0]
|
---|
42 | if sline == "":
|
---|
43 | continue
|
---|
44 | sline = sline.split()
|
---|
45 | if sline[0] == "GmX":
|
---|
46 | Nx = int(sline[2].split(',')[0].replace("d", "e"))
|
---|
47 | if sline[0] == "GxBounds":
|
---|
48 | Lx = float(sline[2].split(',')[3].replace("d", "e")) \
|
---|
49 | -float(sline[2].split(',')[0].replace("d", "e"))
|
---|
50 | if sline[0] == "MaxLevel":
|
---|
51 | max_L = int(float(sline[2].replace("d", "e")))
|
---|
52 |
|
---|
53 | if Gamma < 1.01:
|
---|
54 | print ("Warning: default gamma = %f, changing to 5/3 for calculation" % Gamma)
|
---|
55 | Gamma = 5./3.
|
---|
56 |
|
---|
57 | Cs_p2 = (k_B*T_p)/m_H
|
---|
58 | n_p = rho_p/m_H
|
---|
59 | Nx=Nx*(2**max_L)
|
---|
60 | dx = Lx/Nx
|
---|
61 | print Lx, Nx, dx
|
---|
62 | Gamma_1 = Gamma - 1.0
|
---|
63 | r_crit = (Gamma_1*G*M_p)/(Gamma*Cs_p2*R_p)
|
---|
64 | r_zero = (r_crit)/(r_crit-1.0)
|
---|
65 | n_rho = 1.0/Gamma_1
|
---|
66 | n_prs = Gamma/Gamma_1
|
---|
67 | rScale = rho_p
|
---|
68 | lScale = R_p
|
---|
69 | pScale = rho_p*Cs_p2
|
---|
70 |
|
---|
71 | #atmopshere profile
|
---|
72 | def atm_profile(r):
|
---|
73 | return (r_crit*(1./r - 1./r_zero))**(1./Gamma_1)
|
---|
74 |
|
---|
75 | #radiative transfer
|
---|
76 | h = 1.0e-6/3.
|
---|
77 | tau = 0.0
|
---|
78 | i=0
|
---|
79 | if r_zero < 0:
|
---|
80 | print "Warning: infinitely extended atmosphere"
|
---|
81 | r_start = 3.
|
---|
82 | else:
|
---|
83 | r_start = r_zero
|
---|
84 |
|
---|
85 | while (tau < 1):
|
---|
86 | rad = r_start - i*3.*h
|
---|
87 | tau += 3.*h/8.*(sigma*n_p*R_p)* \
|
---|
88 | ( atm_profile(rad) + 3.*atm_profile(rad-h) + \
|
---|
89 | 3.*atm_profile(rad-2.*h) + atm_profile(rad-3.*h) )
|
---|
90 | i += 1
|
---|
91 |
|
---|
92 | r_tau1 = 1
|
---|
93 | r_ib = r_zero/(1+(r_zero-r_tau1)/r_tau1*math.exp(3*Gamma_1))
|
---|
94 | r_mask = r_ib - 5*Lx/Nx
|
---|
95 | r_ob = r_zero/(1+(r_zero-r_tau1)/r_tau1*.1**Gamma_1)
|
---|
96 |
|
---|
97 | with open('adiabat.data', 'w') as outfile:
|
---|
98 | nEntries = int(math.ceil((r_zero-r_mask)/dx))
|
---|
99 | outfile.write("%d\n" % (nEntries+1))
|
---|
100 | outfile.write("r_mask, r_ib, r_tau1, r_ob, r_crit, r_zero\n")
|
---|
101 | outfile.write(str("%e %e %e %e %e %e\n" % (r_mask, r_ib, r_tau1, r_ob, r_crit, r_zero)).replace("e",
|
---|
102 | "d"))
|
---|
103 | outfile.write("r/r_p, rho/rho_p, P/P_p\n")
|
---|
104 | for i in range(0, nEntries):
|
---|
105 | rad = r_mask + i*dx
|
---|
106 | f_rad = r_crit*(1.0/rad-1.0/r_zero)
|
---|
107 | rho = f_rad**n_rho
|
---|
108 | P = f_rad**n_prs
|
---|
109 | outfile.write(str("%e" % rad).replace("e", "d")) #r/r_p
|
---|
110 | outfile.write(str(" %e" % rho).replace("e", "d")) #rho/rho_p
|
---|
111 | outfile.write(str(" %e" % P).replace("e", "d")) #E/E_p
|
---|
112 | outfile.write("\n")
|
---|
113 | rad = r_zero
|
---|
114 | f_rad = r_crit*(1.0/rad-1.0/r_zero)
|
---|
115 | rho = f_rad**n_rho
|
---|
116 | P = f_rad**n_prs
|
---|
117 | outfile.write(str("%e" % rad).replace("e", "d")) #r/r_p
|
---|
118 | outfile.write(str(" %e" % rho).replace("e", "d")) #rho/rho_p
|
---|
119 | outfile.write(str(" %e" % P).replace("e", "d")) #E/E_p
|
---|
120 |
|
---|
121 |
|
---|
122 | print "For local problem suggest setting:"
|
---|
123 | print "rScale = %s" % (str("%e" % (rScale)).replace("e", "d"))
|
---|
124 | print "pScale = %s" % (str("%e" % (pScale)).replace("e", "d"))
|
---|
125 | print "lScale = %s" % (str("%e" % (lScale)).replace("e", "d"))
|
---|