コード例 #1
0
ファイル: spherical.py プロジェクト: EigenDev/simbi
def sod():
    tend = 0.1
    fig, ax = plt.subplots(1, 1, figsize=(13, 11))

    r_min = 0.1
    r_max = 1.
    r = [
        np.linspace(r_min, r_max, N),
        np.logspace(np.log(r_min), np.log(r_max), N, base=np.exp(1))
    ]
    y = 0
    order = ['First Order', 'Higher Order']
    linny = [':', '--']
    for i in [True, False]:
        # Object used for the linearly spaced grid
        sedov = Hydro(gamma=gamma,
                      initial_state=((1.0, 1.0, 0.0), (0.1, 0.125, 0.0)),
                      Npts=N,
                      geometry=(r_min, r_max, 0.5),
                      n_vars=3)

        s = sedov.simulate(tend=tend,
                           first_order=i,
                           dt=dt,
                           CFL=0.4,
                           linspace=False,
                           coordinates=b'spherical')

        ax.plot(r[1], s[0], linestyle=linny[y], label=order[y])

        y ^= 1

    # Make the plot pretty
    ax.spines['right'].set_visible(False)
    ax.spines['top'].set_visible(False)
    ax.set_xlim(r_min, r_max)
    ax.set_xlabel("R", fontsize=15)
    ax.set_ylabel("Density", fontsize=15)
    ax.set_title("1D Sod after t={:.1f}s with N = {}".format(tend, N),
                 fontsize=20)
    ax.legend(fontsize=15)

    fig.savefig('sod.pdf')

    plt.show()
コード例 #2
0
ファイル: spherical.py プロジェクト: EigenDev/simbi
def plot_logvlin():
    fig, ax = plt.subplots(1, 1, figsize=(13, 11))
    y = 0
    tend = 0.05
    for i in [True, False]:
        sedov = Hydro(gamma=gamma,
                      initial_state=(rho, p, v),
                      Npts=N,
                      geometry=(r_min, r_max),
                      n_vars=3)

        u = sedov.simulate(tend=tend, first_order=True, dt=dt, linspace=i)

        r = [
            np.linspace(r_min, r_max, N),
            np.logspace(np.log(r_min), np.log(r_max), N, base=np.exp(1))
        ]
        linny = [':', '--']
        label = ['linspace', 'logspace']

        ax.plot(r[y], u[0], linestyle=linny[y], label=label[y])

        # Make the plot pretty
        ax.spines['right'].set_visible(False)
        ax.spines['top'].set_visible(False)
        ax.set_xlim(r_min, r_max)
        ax.set_xlabel("R", fontsize=15)
        ax.set_ylabel("Density", fontsize=15)
        ax.set_title("1D Sedov after t={:.3f} s at N = {}".format(tend, N),
                     fontsize=20)
        ax.legend(fontsize=15)

        y ^= 1
    rs = (epsilon * tend**2 / rho0)**(1 / 5)
    ax.axvline(rs)
    plt.setp(ax.get_xticklabels(), fontsize=15)
    plt.setp(ax.get_yticklabels(), fontsize=15)
    fig.savefig('Log_v_linear.pdf')
    plt.show()
コード例 #3
0
gamma = 4/3 
tend = 1.0
N = 100
dt = 1.e-4


stationary = ((1.4, 1.0, 0.0), (1.0, 1.0, 0.0))
hydro2 = Hydro(gamma=gamma, initial_state = stationary,
        Npts=N, geometry=(0.0,1.0,0.5), n_vars=3, regime="relativistic")

hydro = Hydro(gamma=gamma, initial_state = stationary,
        Npts=N, geometry=(0.0,1.0,0.5), n_vars=3, regime="relativistic")



h = hydro2.simulate(tend=tend, first_order=False, CFL=0.4, hllc=True)
u = hydro.simulate(tend=tend, first_order=False, CFL=0.4, hllc=False)


x = np.linspace(0, 1, N)
fig, ax = plt.subplots(1, 1, figsize=(15, 11))

# print("RHLLC Density: {}", h[0])

ax.plot(x, u[0], 'o', fillstyle='none', label='RHLLE')
ax.plot(x, h[0], label='RHLLC')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.set_ylabel('Density', fontsize=20)

コード例 #4
0
vx[:, :] = v_init
vy[:, :] = v_init

tend = 0.2
dt = 1.e-5

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')
コード例 #5
0
    tend = 0.1

    #print('End Time:', tend)
    first_o = Hydro(gamma,
                    initial_state=(r, p, v),
                    Npts=npts,
                    geometry=(0, 1.0),
                    regime="relativistic")
    second_o = Hydro(gamma,
                     initial_state=(r, p, v),
                     Npts=npts,
                     geometry=(0, 1.0),
                     regime="relativistic")

    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
    #l1 = h*np.sum(np.absolute(sims[npts][1]/(sims[npts][0]**gamma) - K))
    #print(l1)
    #zzz = input('')
    #fig, ax = plt.subplots(1,1, figsize=(15,11))
    #
    #ax.plot(x, results[npts][1],'rs',fillstyle='none', label='First Order')
コード例 #6
0
tend = 3.0
r = np.logspace(np.log10(rmin), np.log10(rmax), n)

n_exp = 2
dr = r[n_exp]
p_exp = (gamma - 1.0) * energy / (4 * np.pi * dr**3)

print(p_exp)
rho = 10 * np.ones(n) * r**(-omega)
v = np.zeros(n)
p = np.ones(n)

p[:n_exp] = p_exp
p[n_exp:] = p_amb

sedov = Hydro(gamma, (rho, p, v), n, (rmin, rmax), 3, "spherical")
solution = sedov.simulate(first_order=False, tend=tend, linspace=False)

rho = solution[0]
m = solution[1]
e = solution[2]

fig, ax = plt.subplots(1, 1, figsize=(10, 10))

ax.loglog(r, rho)
ax.set_title("1D Sedov Sherical Explosion at t={:.1f}".format(tend),
             fontsize=30)
ax.set_xlabel("r", fontsize=20)
ax.set_ylabel("rho", fontsize=20)
plt.show()
コード例 #7
0
fig, axs = plt.subplots(1, 2, figsize=(20, 10), sharex=True)

hydro = Hydro(gamma=1.4,
              initial_state=stationary,
              Npts=N,
              geometry=(0.0, 1.0, 0.5),
              n_vars=3)

hydro2 = Hydro(gamma=1.4,
               initial_state=stationary,
               Npts=N,
               geometry=(0.0, 1.0, 0.5),
               n_vars=3)

t1 = time.time()
poll = hydro.simulate(tend=tend, dt=dt, first_order=False, hllc=False)
print("Time for HLLE Simulation: {} sec".format(time.time() - t1))

t2 = time.time()
bar = hydro2.simulate(tend=tend, dt=dt, first_order=False, hllc=True)
print("Time for HLLC Simulation: {} sec".format(time.time() - t2))

u = bar[1] / bar[0]
v = poll[1] / poll[0]

#print(bar[0])
x = np.linspace(0, 1, N)
fig.suptitle("Stationary Wave Problem at t = {} with N = {}".format(tend, N))
axs[0].plot(x[::], poll[0][::], 'r--', fillstyle='none', label='HLLE')
axs[0].plot(x, bar[0], 'b', label='HLLC')
axs[0].set_xlabel('X', fontsize=20)
コード例 #8
0
xx, yy = np.meshgrid(x, y)

fig, ax = plt.subplots(1, 1, figsize=(8, 10), constrained_layout=False)

# HLLC Simulation
SodHLLC = Hydro(gamma=gamma,
                initial_state=(rho, p, vx, vy),
                Npts=(xnpts, ynpts),
                geometry=((xmin, xmax), (ymin, ymax)),
                n_vars=4)

t1 = (time.time() * u.s).to(u.min)
hllc_result = SodHLLC.simulate(tend=tend,
                               first_order=False,
                               dt=dt,
                               linspace=True,
                               CFL=0.8,
                               hllc=True,
                               periodic=True)

print("The 2D KH Simulation for ({}, {}) grid took {:.3f}".format(
    xnpts, ynpts, (time.time() * u.s).to(u.min) - t1))

rho, mx, my, E = hllc_result
print(rho)

rnorm = colors.LogNorm(vmin=0.9, vmax=2.1)

c1 = ax.pcolormesh(xx,
                   yy,
                   rho,
コード例 #9
0
ファイル: spherical.py プロジェクト: EigenDev/simbi
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()
コード例 #10
0
vx = np.zeros((N, N), np.double)
vy = np.zeros((N, N), np.double)

vx[:, :] = v_init
vy[:, :] = v_init

tend = 0.01

sedov = Hydro(gamma=gamma,
              initial_state=(rho, pr, vx, vy),
              Npts=(N, N),
              geometry=((-1., 1.), (-1., 1.)),
              n_vars=4)

t1 = (time.time() * u.s).to(u.min)
sol = sedov.simulate(tend=tend, first_order=False, dt=1.e-5, hllc=True)
print("The 2D Sedov Simulation for N = {} took {:.3f}".format(
    N, (time.time() * u.s).to(u.min) - t1))

rho = sol[0]

x = np.linspace(-1., 1, N)
y = np.linspace(-1., 1, N)

xx, yy = np.meshgrid(x, y)

fig, ax = plt.subplots(1, 1, figsize=(15, 10))
c1 = ax.pcolormesh(xx, yy, rho, cmap='plasma', shading='auto')
ax.set_title('Density at t={} s on {} x {} grid'.format(tend, N, N),
             fontsize=20)
cbar = fig.colorbar(c1)
コード例 #11
0
tend = 0.5
dt = 1.e-8
# with PackageResource() as bm:
#     bm.Hydro()
bm = Hydro(gamma=gamma,
           initial_state=(rho, p, vx, vy),
           Npts=(nr, ntheta),
           geometry=((rmin, rmax), (theta_min, theta_max)),
           n_vars=4,
           regime="relativistic")

t1 = (time.time() * u.s).to(u.min)
sol = bm.simulate(tend=tend,
                  first_order=False,
                  dt=dt,
                  coordinates="spherical",
                  CFL=0.4,
                  hllc=False,
                  linspace=False)

print("The 2D BM Simulation for N = {} took {:.3f}".format(
    ntheta, (time.time() * u.s).to(u.min) - t1))

#density = b.cons2prim(sol)[0]

W = 1 / np.sqrt(1 - sol[1]**2 + sol[2]**2)
print(sol[1].max())
rr, tt = np.meshgrid(r, theta)
rr, t2 = np.meshgrid(r, theta_mirror)

fig, ax = plt.subplots(1,
コード例 #12
0
ファイル: 2dsod.py プロジェクト: EigenDev/simbi
print("Rmin: {}".format(rmin))
print("Dim: {}x{}".format(ynpts, xnpts))

S = np.zeros(shape=rho.shape)

SodHLLE = Hydro(gamma=gamma,
                initial_state=(rho, p, vr, vt),
                Npts=(xnpts, ynpts),
                geometry=((rmin, rmax), (theta_min, theta_max)),
                n_vars=4)

t1 = (time.time() * u.s).to(u.min)
hlle_result = SodHLLE.simulate(tend=tend,
                               first_order=False,
                               dt=dt,
                               coordinates="spherical",
                               linspace=False,
                               CFL=0.4,
                               hllc=False)

# HLLC Simulation
SodHLLC = Hydro(gamma=gamma,
                initial_state=(rho, p, vr, vt),
                Npts=(xnpts, ynpts),
                geometry=((rmin, rmax), (theta_min, theta_max)),
                n_vars=4)

t1 = (time.time() * u.s).to(u.min)
hllc_result = SodHLLC.simulate(tend=tend,
                               first_order=False,
                               dt=dt,