예제 #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
import numpy as np 
import time
import matplotlib.pyplot as plt 

from simbi_py import Hydro

from state import PyStateSR

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])
예제 #4
0
rho[:] = 1.0  #(rho0(n, theta)).reshape(N+1, 1)

# print(rho)
# zzz = input()
vx = np.zeros((N + 1, N + 1), np.double)
vy = np.zeros((N + 1, N + 1), np.double)

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)
예제 #5
0
    #print(v)
    #zzz = input('')

    # Get velocity at center of the wave
    center, coordinate = find_nearest(x, 0.5)
    v_wave = v[center]
    lx = x[-1] - x[0]
    dx = lx / npts
    dt = 1.e-4

    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])
예제 #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
    r = rho(alpha, x)
    p = pressure(gamma, r)
    v = velocity(gamma, r, p)

    # Get velocity at center of the wave
    center, coordinate = find_nearest(x, 0.5)
    v_wave = v[center]
    lx = x[-1] - x[0]
    dx = lx / npts
    dt = 1.e-4

    tend = 0.1

    #print('End Time:', tend)
    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])
예제 #8
0
from simbi_py import Hydro

from state import PyState, PyState2D

gamma = 1.4
tend = 4.0
N = 200
dt = 1.e-4

stationary = ((1.4, 1.0, 0.0), (1.0, 1.0, 0.0))
sod = ((1.0, 1.0, 0.0), (0.1, 0.125, 0.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)
예제 #9
0
plt.show()
vx += vx_rand
vy += vy_rand

tend = 2.0

dt = 1.e-4
S = np.zeros(shape=rho.shape)
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))
예제 #10
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()
예제 #11
0
파일: spherical.py 프로젝트: EigenDev/simbi
                     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()


# Object used for the linearly spaced grid
sedov = Hydro(gamma=gamma,
              initial_state=(rho, p, v),
              Npts=N,
              geometry=(r_min, r_max),
              n_vars=3)


def plot_rpv():

    re = 0.8
    dt = 1.e-6
    tend = (beta * re)**(5 / 2) * (rho0 / epsilon)**(1 / 2)
    # Simulate with linearly-spaced radial zones
    u = sedov.simulate(tend=tend, first_order=False, dt=dt, linspace=True)

    # get the pressure and velocity
    p, v = sedov.cons2prim(u)[1:]
예제 #12
0
# zzz = input('')

rho = np.zeros((N, N), float)
rho[:, :] = rho_init

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)
예제 #13
0
n = 2.0
rho = np.zeros((ntheta, nr), float)
rho[:] = 1.0  #(rho0(n, theta)).reshape(ntheta, 1)

# print(rho)
# zzz = input()
vx = np.zeros((ntheta, nr), np.double)
vy = np.zeros((ntheta, nr), np.double)

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))
예제 #14
0
파일: 2dsod.py 프로젝트: EigenDev/simbi
p[:, np.where(r < 0.5)] = pL
p[:, np.where(r > 0.5)] = pR

tend = 0.1
dtheta = theta_max / ynpts
dt = 0.4 * (rmin * dtheta)
#dt = 0.1*(rmax/xnpts)
print("dt: {}".format(dt))
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),