Example #1
0
def one_step_lax_friedrichs(u_last, X, delta_t, delta_x, time):
    u_next = np.zeros((X, 2))
    u_next[0, :] = c.RHO_0, func.safe_v(c.RHO_0)
    u_next[0, :] = u_last[1][0], func.safe_v(u_last[1][0])
    for j in range(1, X - 1):
        position = j * delta_x - c.L / 2
        u_next[j] = u_next_lax_friedrichs(u_last, delta_t, delta_x, j, time,
                                          position)
        u_next[j][0] = min(c.RHO_MAX, u_next[j][0])
        u_next[j][1] = max(0, u_next[j][1])
    u_next[X - 1] = 2 * u_next[X - 2] - u_next[X - 3]
    return u_next
Example #2
0
def one_step_lax_wendroff(u_last, X, delta_t, delta_x, time, rho0, L):
    u_next = np.zeros((X, 2))
    u_next[0, :] = rho0, func.safe_v(rho0)
    u_halfstep = np.zeros((X, 2))
    u_halfstep[0, :] = u_next_half_step(u_last, delta_t, delta_x, 0, time,
                                        -L / 2)
    for j in range(1, X - 1):
        position = j * delta_x - L / 2
        u_next[j] = u_next_lax_wendroff(u_last, u_halfstep, delta_t, delta_x,
                                        j, time, position)
    u_next[X - 1] = 2 * u_next[X - 2] - u_next[X - 3]
    return u_next
Example #3
0
def one_step_mac_cormack(u_last, X, delta_t, delta_x, time, rho0, L):
    u_next = np.zeros((X, 2))
    u_next[0, :] = u_last[1, 0], func.safe_v(u_last[1, 0])
    u_approx = np.zeros((X, 2))
    u_approx[0] = u_approx_mac_cormack(u_last, delta_t, delta_x, 0, time,
                                       delta_x)
    u_approx[1] = u_approx_mac_cormack(u_last, delta_t, delta_x, 1, time,
                                       delta_x - L / 2)
    for j in range(1, X - 2):
        position = j * delta_x - L / 2
        u_approx[j + 1] = u_approx_mac_cormack(u_last, delta_t, delta_x, j + 1,
                                               time, position + delta_x)
        u_next[j] = u_next_mac_cormack(u_last, u_approx, delta_t, delta_x, j,
                                       time, position)
        u_next[j][0] = min(c.RHO_MAX, u_next[j][0])
        u_next[j][1] = max(0, u_next[j][1])
    u_next[X - 2] = 2 * u_next[X - 3] - u_next[X - 4]
    u_next[X - 1] = 2 * u_next[X - 2] - u_next[X - 3]
    return u_next