first_o = Hydro(gamma, initial_state=(r, p, v), Npts=npts, geometry=(0, 1.0)) second_o = Hydro(gamma, initial_state=(r, p, v), Npts=npts, geometry=(0, 1.0)) results[npts] = first_o.simulate(tend=tend, dt=dt, periodic=True) sims[npts] = second_o.simulate(tend=tend, dt=dt, first_order=False, periodic=True) f_p = first_o.cons2prim(results[npts]) s_p = second_o.cons2prim(sims[npts]) # h = 1/npts # print(f_p[1][3]) # print(p[3]) # l1 = h*np.sum(np.absolute(s_p[1]/(s_p[0]**gamma) - 1.)) # print(l1) # zzz = input('') fig, ax = plt.subplots(1, 1, figsize=(15, 11)) ax.plot(x, results[npts][0], 'rs', fillstyle='none', label='First Order') ax.plot(x, sims[npts][0], 'b-', label='Higher Order') # ax.plot(x, p/(r**gamma), '.') # ax.plot(x, r, 'g--', label='Initial') ax.set_xlim(x[0], x[-1])
sedov = Hydro(gamma=gamma, initial_state=(rho, p, vx, vy), Npts=(N + 1, N + 1), geometry=((rmin, rmax), (0., np.pi)), n_vars=4) t1 = (time.time() * u.s).to(u.min) sol = sedov.simulate(tend=tend, first_order=False, dt=dt, coordinates=b"spherical", hllc=True) print("The 2D Sedov Simulation for N = {} took {:.3f}".format( N, (time.time() * u.s).to(u.min) - t1)) density = sedov.cons2prim(sol)[0] rr, tt = np.meshgrid(r, theta) rr, t2 = np.meshgrid(r, theta_mirror) fig, ax = plt.subplots(1, 1, figsize=(15, 10), subplot_kw=dict(projection='polar')) c1 = ax.contourf(tt, rr, density, cmap='plasma') c2 = ax.contourf(t2, rr, np.flip(density, axis=0), cmap='plasma') fig.suptitle('Sedov Explosion at t={} s on {} x {} grid'.format(tend, N, N), fontsize=20) ax.set_title(r'$\rho(\theta) = 2.0 + \sin(n \theta)$ with n = {}'.format(n), fontsize=25) cbar = fig.colorbar(c1)
def plot_rho_vs_xi(omega=0, spacing='linspace', dt=1.e-6): def R(epsilon, t, alpha, rho0=1., nu=3, omega=0): return (epsilon * t**2 / (alpha * rho0))**(1 / (nu + 2 - omega)) def Rdot(epsilon, t, Rs): return (2 * Rs / ((nu + 2 - omega) * t)) def D(gamma, rho, rho0): return ((gamma - 1.) / (gamma + 1.)) * (rho / rho0) def V(gamma, v, Rdot): return ((gamma + 1) / 2) * (v / Rdot) def P(gamma, p, rho0, Rdot): return ((gamma + 1) / 2) * (p / (rho0 * Rdot**2)) if spacing == 'linspace': r = np.linspace(r_min, r_max, N) space = True else: r = np.logspace(np.log(r_min), np.log(r_max), N, base=np.exp(1)) space = False N_exp = 5 dr = r[N_exp] p_exp = init_pressure(gamma, epsilon, nu, dr) delta_r = dr - r_min p_zones = find_nearest(r, (r_min + dr))[0] p_zones = int(p_zones / 2.5) print(p_zones) #zzz = input('') p = np.zeros(N, float) p[:p_zones] = p_exp p[p_zones:] = p_amb rho = rho0 * r**(-omega) v = np.zeros(N, float) alph = alpha(nu, omega, gamma) re = 1.0 rsedov = 10 * (r_min + dr) tend = calc_t(alph, rho0, epsilon, re, nu, omega) tmin = calc_t(alph, rho0, epsilon, rsedov, nu, omega) ts = np.array([tmin, 2 * tmin, tend]) # Plot stuff fig = plt.figure(figsize=(15, 9)) for idx, t in enumerate(ts): ax = fig.add_subplot(1, 3, idx + 1) sedov = Hydro(gamma=gamma, initial_state=(rho, p, v), Npts=N, geometry=(r_min, r_max), n_vars=3) t1 = (time.time() * u.s).to(u.min) us = sedov.simulate(tend=t, first_order=False, CFL=0.4, dt=dt, linspace=space, coordinates=b'spherical') print("Simulation for t={} took {:.3f}".format( t, (time.time() * u.s).to(u.min) - t1)) pressure, vel = sedov.cons2prim(us)[1:] rs = R(epsilon, t, alpha=alph, nu=nu, omega=omega) rdot = Rdot(epsilon, t, rs) d = D(gamma, us[0], rho) vx = V(gamma, vel, rdot) px = P(gamma, pressure, rho, rdot) xi = r / (rs) max_idx = find_nearest(xi, 1)[0] print("R Max: {} at idx {}".format(r[np.argmax(us[0])], np.argmax(us[0]))) print("R Shock: {} at idx {}".format(rs, max_idx)) #zzz = input('') ax.plot(xi[:max_idx], d[:max_idx], ':', label=r'$D(\xi)$'.format(t)) ax.plot(xi[:max_idx], vx[:max_idx], '.', label=r'$V(\xi)$'.format(t)) ax.plot(xi[:max_idx], px[:max_idx], '--', label=r'$P(\xi)$'.format(t)) # Make the plot pretty ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.set_title("t = {:.3f}".format(t), fontsize=12) ax.set_xlim(xi[0], 1) ax.set_xlabel(r"$ \xi $", fontsize=15) #ax.set_xlim(0, 1) #plt.setp(ax.get_xticklabels(), fontsize=15) plt.suptitle( "1D Sedov Self Similarity with N = {}, $\omega = {:.3f}, \gamma = {:.3f} $" .format(N, omega, gamma), fontsize=20) ax.legend(fontsize=15) fig.savefig("Sedov_densty_xi_linspace.pdf") plt.show()