Exemplo n.º 1
0
def godunov(rho, u, p, dt, dx, gamma=1.4):
    # Boundary values are the same.
    rho_new = rho.copy()
    rho_new[1:-1] = 0.0
    u_new = u.copy()
    u_new[1:-1] = 0.0
    p_new = p.copy()
    p_new[1:-1] = 0.0

    for i in range(1, len(rho) - 1):
        # Left flux
        W_i = np.array([rho[i], u[i], p[i]])
        W_l = np.array([rho[i - 1], u[i - 1], p[i - 1]])
        W_r = W_i
        riemann = Riemann(W_l, W_r, gamma, x0=0)
        W = riemann.evaluate_single_state(0, 1)  # dx/dt = 0
        F_left = W2F(W, gamma=gamma)
        # Right flux
        W_l = W_i
        W_r = np.array([rho[i + 1], u[i + 1], p[i + 1]])
        riemann = Riemann(W_l, W_r, gamma, x0=0)
        W = riemann.evaluate_single_state(0, 1)
        F_right = W2F(W, gamma=gamma)
        # Compute at next time step
        U_i = W2U(W_i, gamma=gamma)
        U_new = U_i - dt / dx * (F_right - F_left)
        rho_new[i], u_new[i], p_new[i] = U2W(U_new)

    return rho_new, u_new, p_new
Exemplo n.º 2
0
def godunov(rho, u, p, dt, dx, gamma=1.4):
    # Boundary values are the same.
    rho_new = rho.copy()
    rho_new[1:-1] = 0.0
    u_new = u.copy()
    u_new[1:-1] = 0.0
    p_new = p.copy()
    p_new[1:-1] = 0.0

    for i in range(1, len(rho) - 1):
        # Left flux
        W_i = np.array([rho[i], u[i], p[i]])
        W_l = np.array([rho[i - 1], u[i - 1], p[i - 1]])
        W_r = W_i
        riemann = Riemann(W_l, W_r, gamma, x0=0)
        W = riemann.evaluate_single_state(0, 1)  # dx/dt = 0
        F_left = W2F(W, gamma=gamma)
        # Right flux
        W_l = W_i
        W_r = np.array([rho[i + 1], u[i + 1], p[i + 1]])
        riemann = Riemann(W_l, W_r, gamma, x0=0)
        W = riemann.evaluate_single_state(0, 1)
        F_right = W2F(W, gamma=gamma)
        # Compute at next time step
        U_i = W2U(W_i, gamma=gamma)
        U_new = U_i - dt/dx*(F_right - F_left)
        rho_new[i], u_new[i], p_new[i] = U2W(U_new)

    return rho_new, u_new, p_new
Exemplo n.º 3
0
def MUSCL(rho, u, p, dt, dx, gamma=1.4, limiter='zero'):
    # Boundary values are the same.
    rho_new = rho.copy()
    rho_new[1:-1] = 0.0
    u_new = u.copy()
    u_new[1:-1] = 0.0
    p_new = p.copy()
    p_new[1:-1] = 0.0
    # Update fluxes and conservative
    W = np.empty((len(rho), 3))
    U = np.empty_like(W)
    for i in range(len(U)):
        W[i] = np.array([rho[i], u[i], p[i]])
        U[i] = W2U(W[i], gamma=gamma)

    ##################
    # Predictor Step #
    ##################
    # Compute limited slope
    delta_W = limiters.limiter(W, name=limiter)
    F_l = np.empty_like(delta_W)
    F_r = F_l.copy()
    U_tilde = F_l.copy()
    W_tilde = F_l.copy()
    for i in range(len(delta_W)):
        F_l[i] = W2F(W[i] + 0.5 * delta_W[i])
        F_r[i] = W2F(W[i] - 0.5 * delta_W[i])
        U_tilde[i] = U[i] - dt / dx * (F_l[i] - F_r[i])
        W_tilde[i] = U2W(U_tilde[i])

    ####################
    ## Corrector Step ##
    ####################
    # Godunov-like
    W_l = 0.5 * (W + W_tilde + delta_W)
    W_r = 0.5 * (W + W_tilde - delta_W)
    W_rs = np.zeros_like(W_l)
    F_rs = W_rs.copy()
    for i in range(0, len(W_l) - 1):
        # Left flux
        riemann = Riemann(W_l[i], W_r[i + 1], gamma, x0=0)
        W_rs[i] = riemann.evaluate_single_state(0, 1)
        F_rs[i] = W2F(W_rs[i])

    U_new = U.copy()
    U_new[1:-1] = U[1:-1] - dt / dx * (F_rs[1:-1] - F_rs[0:-2])

    for i in range(len(U_new)):
        rho_new[i], u_new[i], p_new[i] = U2W(U_new[i])

    # pdb.set_trace()
    return rho_new, u_new, p_new
Exemplo n.º 4
0
def MUSCL(rho, u, p, dt, dx, gamma=1.4, limiter='zero'):
    # Boundary values are the same.
    rho_new = rho.copy()
    rho_new[1:-1] = 0.0
    u_new = u.copy()
    u_new[1:-1] = 0.0
    p_new = p.copy()
    p_new[1:-1] = 0.0
    # Update fluxes and conservative
    W = np.empty((len(rho), 3))
    U = np.empty_like(W)
    for i in range(len(U)):
        W[i] = np.array([rho[i], u[i], p[i]])
        U[i] = W2U(W[i], gamma=gamma)

    ##################
    # Predictor Step #
    ##################
    # Compute limited slope
    delta_W = limiters.limiter(W, name=limiter)
    F_l = np.empty_like(delta_W)
    F_r = F_l.copy()
    U_tilde = F_l.copy()
    W_tilde = F_l.copy()
    for i in range(len(delta_W)):
        F_l[i] = W2F(W[i] + 0.5*delta_W[i])
        F_r[i] = W2F(W[i] - 0.5*delta_W[i])
        U_tilde[i] = U[i] - dt/dx*(F_l[i] - F_r[i])
        W_tilde[i] = U2W(U_tilde[i])

    ####################
    ## Corrector Step ##
    ####################
    # Godunov-like
    W_l = 0.5*(W + W_tilde + delta_W)
    W_r = 0.5*(W + W_tilde - delta_W)
    W_rs = np.zeros_like(W_l)
    F_rs = W_rs.copy()
    for i in range(0, len(W_l) - 1):
        # Left flux
        riemann = Riemann(W_l[i], W_r[i+1], gamma, x0=0)
        W_rs[i] = riemann.evaluate_single_state(0, 1)
        F_rs[i] = W2F(W_rs[i])

    U_new = U.copy()
    U_new[1:-1] = U[1:-1] - dt/dx*(F_rs[1:-1] - F_rs[0:-2])

    for i in range(len(U_new)):
        rho_new[i], u_new[i], p_new[i] = U2W(U_new[i])

    # pdb.set_trace()
    return rho_new, u_new, p_new
Exemplo n.º 5
0
def _test_sample_singleeval(test_file, W_l, W_r, gamma, t, x0=0):
    target_results = np.genfromtxt(test_file, skip_header=1)
    riemann = Riemann(W_l, W_r, gamma,  x0)
    for x, rho, u, p in target_results:
        W_actual = riemann.evaluate_single_state(x, t)
        W_target = np.array([rho, u, p])
        try:
            compare(W_actual, W_target, 0.002)
        except AssertionError:
            print("x:", x)
            print("t:", t)
            print("S:", x / t)
            raise
Exemplo n.º 6
0
def _test_sample_singleeval(test_file, W_l, W_r, gamma, t, x0=0):
    target_results = np.genfromtxt(test_file, skip_header=1)
    riemann = Riemann(W_l, W_r, gamma, x0)
    for x, rho, u, p in target_results:
        W_actual = riemann.evaluate_single_state(x, t)
        W_target = np.array([rho, u, p])
        try:
            compare(W_actual, W_target, 0.002)
        except AssertionError:
            print("x:", x)
            print("t:", t)
            print("S:", x / t)
            raise