-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharnett_small_R.py
155 lines (122 loc) · 5.27 KB
/
arnett_small_R.py
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
import numpy as np
from scipy.integrate import quad
from nagy import nagy
# from mpmath import mp
# constants
tau_ni = 7.605e5 # s | nickel-56 decay time
tau_co = 9.822e6 # s | cobalt-56 decay time
e_ni = 4.78e10 # ergs /g /s | energy release of nickel decay
e_co = 2.56e8 # ergs /g /s | energy release of cobalt decay (purely from positrons)
beta = 13.7 # approximately this for a variety of cases(A80) so will use throughout this project
kappa_gamma = 0.03 # opacity of gamma rays
day2sec = 86400 # s | seconds in a day
m_sun = 1.989e33 # g | solar mass in grams
c = 2.99792458e10 # cm /s | speed of light in CGS
# model parameters:
# t - time
# m - total ejected mass
# v_sc - velocity scale factor
# For large initial radius, R?
# functions
# nickel lambda
# cobalt lambda
# nickel bolometric luminosity - do we use the same for both?
# kappa - the opacity, import from nagy.py?
def kappa_const(t):
"""placeholder"""
return 0.1
def l_ni(t, m, v_sc, kappa: callable = kappa_const):
"""Arnett eqn. 31 | Lambda(x,y)"""
tau_m = np.sqrt((2 * kappa(t) * m) / (beta * c * v_sc))
x = t / tau_m
y = tau_m / (2 * tau_ni)
def l_ni_integral(z):
"""z is the variable of integration"""
#print("NI", " x=", x, " y=", y, " z=", z, " m=", m, " v_sc=", v_sc)
res = np.exp((-2 * z * y) + np.power(z, 2)) * 2 * z
#print(f"l_ni_integral = {res: .3e}")
return res
result = np.exp(-np.power(x, 2)) * quad(l_ni_integral, 0, x)[0]
#print(f"x={x:.5f}\ty={y:.3f}\txy={(x * y):.3f}\tlambda_ni(x,y)={result:.3f}")
return x * y, result
def l_co(t, m, v_sc, kappa: callable = kappa_const):
"""Arnet eqn. 38 updated with Valenti et al."""
tau_m = np.sqrt((2 * kappa(t) * m) / (beta * c * v_sc))
x = t / tau_m
y = tau_m / (2 * tau_ni)
yp = tau_m / (2 * tau_co)
def l_co_integral(z):
"""z is the variable of integration"""
#print("CO", "x=", x, "y=", y, " z=", z)
# MATLAB: 2*z.*(exp(-2*z*yp) - exp(-2*z*y))/(1 - tau_ni/tau_co).*exp(z.^2)).
res = 2 * z * (np.exp(-2 * z * yp) - np.exp(-2 * z * y)) / (1 - tau_ni/tau_co) * np.exp(np.power(z, 2))
#print(f"lambda_co_integral={res:.3f}")
return res
result = np.exp(-np.power(x, 2)) * quad(l_co_integral, 0, x)[0]
# print(f"lambda_co(x,y)={result:.3f}")
return result
def bolo_l(t, m, v_sc, m_ni, kappa: callable = kappa_const):
#print(f"inputs: t={t}, m={m}, v_sc={v_sc}, m_ni={m_ni}")
def deposition(): # checked
tau_m = np.sqrt((2 * kappa(t) * m) / (beta * c * v_sc))
R = v_sc * tau_m # is this the correct V and tau?
rho = m / (4 / 3 * np.pi * R ** 3)
tau_56co_gamma = kappa_gamma * rho * R # difussion timescale of photons of decay from ni->co. Is this named correctly?
G = tau_56co_gamma / (tau_56co_gamma + 1.6)
D = G * (1 + 2 * G * (1 - G) * (1 - 0.75 * G))
return D
# evaluate (D_ni * e_ni * m_ni * lambda_ni) + (D_co * e_co * m_ni * lambda_co)
res = (deposition() * e_ni * m_ni * l_ni(t, m, v_sc, kappa=kappa)[1]) + ((0.966 * deposition() + 0.034) * e_co *m_ni * l_co(t, m, v_sc, kappa=kappa))
# print(f"L = {res:.3e}")
return res
if __name__ == "__main__":
from matplotlib import pyplot as plt
"""Do some test values"""
skip_days = 1 # Days to skip at start. Shock breakout dominates initially
end_day = 200 # day on which to end simulation
# test values:
m = 1.45 * m_sun
v_sc = 1.2e9
m_ni = 0.7 * m_sun
times = np.linspace(skip_days * day2sec, end_day * day2sec, 500)
# constant kappa
lni_res = []
lco_res = []
xy_res = []
lum_res = []
for t in times:
out = l_ni(t, m=m, v_sc=v_sc)
xy_res.append(out[0])
lni_res.append(out[1])
lco_res.append(l_co(t, m=m, v_sc=v_sc))
for t in times:
lum_res.append(bolo_l(t, m=m, v_sc=v_sc, m_ni=0.7*m_sun))
# variable kappa
lni_res_var = []
lco_res_var = []
xy_res_var = []
lum_res_var = []
for t in times:
out = l_ni(t, m=m, v_sc=v_sc, kappa=nagy.kappa_nagy)
xy_res_var.append(out[0])
lni_res_var.append(out[1])
lco_res_var.append(l_co(t, m=m, v_sc=v_sc, kappa=nagy.kappa_nagy))
for t in times:
lum_res_var.append(bolo_l(t, m=m, v_sc=v_sc, m_ni=0.7*m_sun, kappa=nagy.kappa_nagy))
# plotting
print(f"Using test values of m=1.45*m_sun g, v_sc=1.2e9 cm/s ")
fig, ax = plt.subplots(1, 2)
fig.set_size_inches(12, 6.4)
ax[0].loglog(times / day2sec, lni_res, '--', label=fr"$\Lambda_{{ni}}$ Constant kappa ($\kappa = {kappa_const(0)}$)")
ax[0].loglog(times / day2sec, lni_res_var, '--', label=r"$\Lambda_{{ni}}$ Variable kappa")
ax[0].loglog(times / day2sec, lco_res, '--', label=fr"$\Lambda_{{co}}$ Constant kappa ($\kappa = {kappa_const(0)}$)")
ax[0].loglog(times / day2sec, lco_res_var, '--', label=r"$\Lambda_{{co}}$ Variable kappa")
ax[0].set_xlabel(r"time (days)")
ax[0].set_ylabel(r"$\Lambda \left(x, y\right)$")
ax[0].legend()
ax[1].semilogy(times / day2sec, lum_res, label="Constant kappa")
ax[1].semilogy(times / day2sec, lum_res_var, label="Variable kappa")
ax[1].set_xlabel(r"time (days)")
ax[1].set_ylabel(r"Luminosity (ergs s$^{-1}$)")
ax[1].legend()
plt.show()