-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_input.py
More file actions
156 lines (119 loc) · 4.56 KB
/
sample_input.py
File metadata and controls
156 lines (119 loc) · 4.56 KB
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
154
155
156
import numpy
import scipy.integrate as integrate
import tools # type: ignore
import method
import physics
import matplotlib.pyplot as plt
# Define temperature-dependent coefficients as functions
def FC_opacity(T, nu, k0, mesh):
def num_func(n):
return (n**7)*(1-numpy.exp(-mesh.H*n/(mesh.K*T)))**-3
def dem_func(n):
return (n**4)*(1-numpy.exp(-mesh.H*n/(mesh.K*T)))**-2
numerator, err = integrate.quad(num_func, nu[0], nu[1])
denominator, err = integrate.quad(dem_func, nu[0], nu[1])
if numerator == 0:
print(T)
print(nu)
print(numerator)
print(denominator)
return (1000**3)*k0 * denominator/(numerator*((mesh.H)**3))
def group_FC_opacity(mesh, T, k0):
kappa = numpy.zeros((mesh.ng, mesh.nx))
for g in range(0, mesh.ng):
for x in range(0, mesh.nx):
kappa[g, x] = FC_opacity(T[x], mesh.groups[g:g+2], k0, mesh)
return kappa
def FC_heatcap(T_b, mesh):
return (0.5917*mesh.A_R*(T_b)**3) * numpy.ones(mesh.cell_centers.size)
numpy.set_printoptions(precision=8)
scale = tools.Scales()
mesh = tools.Discretization()
k_star = 27
mesh.groups = numpy.array([0.00000, 0.3, 0.6, 0.8, 1.2, 1.5, 1.8, 2.4,
2.7, 3, 4, 5, 7, 9, 11, 15, 20, 1e4])*(1000/mesh.H)
mesh.dx = 0.4
mesh.t_stops = numpy.array([0, 2e-3]) * 1e-8
mesh.dt = 1e-4 * 1e-8 # seconds
mesh.eps = 1e-4
mesh.eps_c = 1e-3
T_prev = (100/mesh.K)*numpy.ones((mesh.nx))
T_bound = (1000/mesh.K)*numpy.ones((mesh.nx))
mesh.I_BC = numpy.zeros((mesh.ng, 2))
mesh.F_BC = numpy.zeros((mesh.ng, 2))
mesh.I_BC[:, 0] = 0.5*(physics.group_planck(mesh, T_bound))[:, 0]
mesh.F_BC[:, 0] = 0.25*(physics.group_planck(mesh, T_bound))[:, 0]
Cv = FC_heatcap(1.0/mesh.K, mesh)
Q = numpy.zeros((mesh.ng, mesh.nx))
sol_prev = tools.Transport_solution(mesh.nx, mesh.ng, numpy.zeros((mesh.ng, 4*mesh.nx)))
sol_prev.intensity[:,:] = tools.dbl(physics.group_planck(mesh, T_prev))
# Plot and compare to FC IMC results
T_out, I_out, unacc_iters = method.solve_diffusion(mesh, scale, group_FC_opacity, sol_prev, T_prev, Cv, accelerated=False)
T_out, I_out, acc_iters = method.solve_diffusion(mesh, scale, group_FC_opacity, sol_prev, T_prev, Cv, accelerated=True)
time_vales_ct = mesh.t_stops[1:]*mesh.C
time_labels = []
for t in time_vales_ct:
time_labels.append(f"ct={t:.2f} cm")
FC_x = [0.2,0.6,1,1.4,1.8,2.2,2.6,3,3.4,3.8]
FC_T = 1000*numpy.array([[0.795,0.64,0.425,0.23,0.15,0.09,0.06,0.04,0.03,0.02],
[0.87,0.85,0.78,0.685,0.585,0.495,0.35,0.27,0.21,0.16],
[0.93,0.945,0.92,0.89,0.89,0.87,0.82,0.78,0.715,0.605]])
plt.figure()
ax = plt.gca()
for i in range(0, len(I_out)):
lines = tools.LD_plottable(mesh, physics.ev_to_erg*I_out[i].vec)
tools.plot_LD_grey(ax, lines.grey_intensity)
plt.title(f"Grey intensity over time")
plt.xlabel("x [cm]")
plt.legend(time_labels)
plt.autoscale()
plt.figure()
ax = plt.gca()
for i in range(0, len(I_out)):
lines = tools.LD_plottable(mesh, (1/mesh.C)*physics.ev_to_erg*I_out[i].vec)
tools.plot_LD_grey(ax, lines.grey_intensity)
plt.title(f"Energy density over time")
plt.xlabel("x [cm]")
plt.legend(time_labels)
plt.autoscale()
plt.figure()
for i in range(0, len(T_out)):
plt.plot(mesh.cell_centers, mesh.K*T_out[i], label = f"t={mesh.t_stops[i+1]:.1e} s")
for t in range(0, FC_T.shape[0]):
plt.scatter(FC_x, FC_T[t])
plt.legend()
plt.xlabel("x [cm]")
plt.ylabel("T [eV]")
plt.title("Temperature over time")
s = numpy.sum(mesh.nt)
plt.figure()
plt.plot(mesh.C*numpy.linspace(1, s, s)*mesh.dt, unacc_iters[1], label="Unaccelerated")
plt.plot(mesh.C*numpy.linspace(1, s, s)*mesh.dt, acc_iters[1], label="Accelerated")
plt.xlabel("ct [cm]")
plt.ylabel("count")
plt.title("Inner Iterations")
plt.legend()
plt.figure()
plt.plot(mesh.C*numpy.linspace(1, s, s)*mesh.dt, unacc_iters[0], label="Unaccelerated")
plt.plot(mesh.C*numpy.linspace(1, s, s)*mesh.dt, acc_iters[0], label="Accelerated")
plt.xlabel("ct [cm]")
plt.ylabel("count")
plt.title("Outer Iterations")
plt.legend()
plt.figure()
plt.plot(mesh.C*numpy.linspace(1, s, s)*mesh.dt, unacc_iters[0], label="Outer Iterations")
plt.plot(mesh.C*numpy.linspace(1, s, s)*mesh.dt, unacc_iters[1], label="Inner Iterations")
plt.xlabel("ct [cm]")
plt.ylabel("count")
plt.title("Uanccelerated Solve")
plt.legend()
lim = plt.gca().get_ylim()
plt.figure()
plt.plot(mesh.C*numpy.linspace(1, s, s)*mesh.dt, acc_iters[0], label="Outer Iterations")
plt.plot(mesh.C*numpy.linspace(1, s, s)*mesh.dt, acc_iters[1], label="Inner Iterations")
plt.xlabel("ct [cm]")
plt.ylabel("count")
plt.title("Accelerated Solve")
plt.legend()
plt.ylim(lim)
plt.show()