28import matplotlib.pyplot
as plt
29from scipy
import stats
30from scipy.special
import gamma
as Gamma
39Computes the analytical solution of the 3D Sedov blast wave.
40The script works for a given initial box and dumped energy and computes the
41solution at a later time t.
44python3 plotSolution.py time
47@param time_step_sim : time to plot solution of
54 time = float(sys.argv[1])
60pvdfile =
"particles.pvd"
61reader = ParticleVTUReader(pvdfile=pvdfile, snapshot_time=time)
62partData = reader.load()
63time = reader.get_snapshot_time()
66x = partData.x[:, 0] - 0.5 * boxsize
67y = partData.x[:, 1] - 0.5 * boxsize
68vel_x = partData.v[:, 0]
69vel_y = partData.v[:, 1]
70pressure = partData.pressure
71density = partData.density
75r = np.sqrt(x**2 + y**2)
76v_r = (x * vel_x + y * vel_y) / r
86 exponents of the polynomials of the sedov solution
87 g - the polytropic gamma
93 a[2] = (1 - g) / (2 * (g - 1) + nu)
94 a[3] = nu / (2 * (g - 1) + nu)
96 a[6] = g / (2 * (g - 1) + nu)
98 a[1] = (((nu + 2) * g) / (2.0 + nu * (g - 1.0))) * (
99 (2.0 * nu * (2.0 - g)) / (g * (nu + 2.0) ** 2) - a[2]
101 a[4] = a[1] * (nu + 2) / (2 - g)
102 a[7] = (2 + nu * (g - 1)) * a[1] / (nu * (2 - g))
108 beta values for the sedov solution (coefficients of the polynomials of the similarity variables)
109 v - the similarity variable
110 g - the polytropic gamma
123 / ((nu + 2) * (g + 1) - 2 * (2 + nu * (g - 1))),
129 beta = np.outer(beta, v)
131 beta += (g + 1) * np.array(
135 (nu + 2) / ((nu + 2) * (g + 1) - 2.0 * (2 + nu * (g - 1))),
143def sedov(t, E0, rho0, g, n=1000, nu=3):
145 solve the sedov problem
147 E0 - the initial energy
148 rho0 - the initial density
149 n - number of points (10000)
151 g - the polytropic gas gamma
154 v_min = 2.0 / ((nu + 2) * g)
155 v_max = 4.0 / ((nu + 2) * (g + 1))
157 v = v_min + np.arange(n) * (v_max - v_min) / (n - 1.0)
163 r = np.exp(-a[0] * lbeta[0] - a[2] * lbeta[1] - a[1] * lbeta[2])
164 rho = ((g + 1.0) / (g - 1.0)) * np.exp(
165 a[3] * lbeta[1] + a[5] * lbeta[3] + a[4] * lbeta[2]
168 nu * a[0] * lbeta[0] + (a[5] + 1) * lbeta[3] + (a[4] - 2 * a[1]) * lbeta[2]
170 u = beta[0] * r * 4.0 / ((g + 1) * (nu + 2))
171 p *= 8.0 / ((g + 1) * (nu + 2) * (nu + 2))
183 vol = (np.pi ** (nu / 2.0) / Gamma(nu / 2.0 + 1)) * np.power(r, nu)
192 de = rho * u * u * 0.5 + p / (g - 1)
194 q = np.inner(de[1:] + de[:-1], np.diff(vol)) * 0.5
197 fac = (q * (t**nu) * rho0 / E0) ** (-1.0 / (nu + 2))
200 shock_speed = fac * (2.0 / (nu + 2))
201 rho_s = ((g + 1) / (g - 1)) * rho0
202 r_s = shock_speed * t * (nu + 2) / 2.0
203 p_s = (2.0 * rho0 * shock_speed * shock_speed) / (g + 1)
204 u_s = (2.0 * shock_speed) / (g + 1)
208 p *= fac * fac * rho0
210 return r, p, rho, u, r_s, p_s, rho_s, u_s, shock_speed
220r_s, P_s, rho_s, v_s, r_shock, _, _, _, _ =
sedov(time, E_0, rho_0, gas_gamma, 1000, 2)
223r_s = np.insert(r_s, np.size(r_s), [r_shock, r_shock * 3])
224rho_s = np.insert(rho_s, np.size(rho_s), [rho_0, rho_0])
225P_s = np.insert(P_s, np.size(P_s), [P_0, P_0])
226v_s = np.insert(v_s, np.size(v_s), [0, 0])
229u_s = P_s / (rho_s * (gas_gamma - 1.0))
240 "markeredgecolor":
"none",
254fig = plt.figure(figsize=(7.0, 7.0))
255fig.suptitle(f
"t={time}")
257ax1 = fig.add_subplot(2, 2, 1)
258ax2 = fig.add_subplot(2, 2, 2)
259ax3 = fig.add_subplot(2, 2, 3)
260ax4 = fig.add_subplot(2, 2, 4)
262ax1.plot(r, v_r, **sim_props)
263ax1.plot(r_s, v_s, **solution_props)
264ax1.set_ylabel(
r"Radial velocity $v_r$")
265ax1.set_ylim(-0.2, 3.8)
267ax2.plot(r, density, **sim_props)
268ax2.plot(r_s, rho_s, **solution_props)
269ax2.set_ylabel(
r"Density $\rho$")
270ax2.set_ylim(-0.2, 5.2)
272ax3.plot(r, pressure, **sim_props)
273ax3.plot(r_s, P_s, **solution_props)
274ax3.set_ylabel(
r"Pressure $p$")
275ax3.set_ylim(-1.0, 12.5)
277ax4.plot(r, energy, **sim_props)
278ax4.plot(r_s, u_s, **solution_props)
279ax4.set_ylabel(
r"Internal Energy $u$")
280ax4.set_ylim(-2.0, 22)
283 ax.tick_params(direction=
"in", top=
True, right=
True)
284 ax.set_xlim(0, 1.3 * r_shock)
285 ax.set_xlabel(
r"Radius $r$")
288fname = f
"sedov_profile-{time:.4f}.png"
Reads in particle fields from a single .vtu file, or all .vtu at a given snapshot time specified in t...
calc_beta(v, g, nu=3)
beta values for the sedov solution (coefficients of the polynomials of the similarity variables) v - ...
calc_a(g, nu=3)
exponents of the polynomials of the sedov solution g - the polytropic gamma nu - the dimension