def viscous_shock_ns(): """ 10.1016/j.jcp.2016.02.015 4.13 Viscous shock profile """ tf = 0.2 nx = 200 x = arange(-0.5, 0.5, 1 / nx) ρ = zeros(nx) p = zeros(nx) v = zeros(nx) for i in range(nx): ρ[i], p[i], v[i] = viscous_shock_exact(x[i]) v -= v[0] # Velocity in shock 0 u = zeros([nx, 5]) for i in range(nx): u[i] = make_Q(ρ[i], p[i], array([v[i], 0, 0])) L = [1.] ret = pde_solver(u, tf, L, F=F_navier_stokes, cfl=0.6) plt.plot(ret[-1, :, 2] / ret[-1, :, 0]) plt.show() return ret
def viscous_shock_gpr(): """ 10.1016/j.jcp.2016.02.015 4.13 Viscous shock profile """ tf = 0.2 nx = 200 x = arange(-0.5, 0.5, 1 / nx) ρ = zeros(nx) p = zeros(nx) v = zeros(nx) for i in range(nx): ρ[i], p[i], v[i] = viscous_shock_exact(x[i]) v -= v[0] # Velocity in shock 0 u = zeros([nx, 17]) for i in range(nx): A = (ρ[i])**(1 / 3) * eye(3) J = zeros(3) u[i] = Cvec(ρ[i], p[i], array([v[i], 0, 0]), A, J) L = [1.] ret = pde_solver(u, tf, L, F=F_gpr, B=B_gpr, S=S_gpr, cfl=0.6) plt.plot(ret[-1, :, 2] / ret[-1, :, 0]) plt.show() return ret
def detonation_wave(): nx = 400 ρL = 1.4 pL = 1 vL = [0, 0, 0] λL = 0 EL = energy(ρL, pL, vL, λL) ρR = 0.887565 pR = 0.191709 vR = [-0.57735, 0, 0] λR = 1 ER = energy(ρR, pR, vR, λR) QL = ρL * array([1, EL] + vL + [λL]) QR = ρR * array([1, ER] + vR + [λR]) u = zeros([nx, 6]) for i in range(nx): if i / nx < 0.25: u[i] = QL else: u[i] = QR tf = 0.5 L = [1.] ret = pde_solver(u, tf, L, F=F_reactive_euler, S=S_reactive_euler, stiff=False, cfl=0.6, flux='roe', order=3) plt.plot(ret[-1, :, 0]) plt.show() return ret
def taylor_green_vortex_2d(): """ 10.1016/j.jcp.2016.02.015 4.10 2D Taylor-Green Vortex """ L = [2 * pi, 2 * pi] nx = 50 ny = 50 tf = 1 C = 100 / γ ρ = 1 v = zeros(3) u = zeros([nx, ny, 5]) for i in range(nx): for j in range(ny): x = (i + 0.5) * L[0] / nx y = (j + 0.5) * L[1] / ny v[0] = sin(x) * cos(y) v[1] = -cos(x) * sin(y) p = C + (cos(2 * x) + cos(2 * y)) / 4 u[i, j] = make_Q(ρ, p, v) ret = pde_solver(u, tf, L, F=F_navier_stokes, cfl=0.9, order=2, boundaryTypes='periodic') x = linspace(0, L[0], nx) y = linspace(0, L[1], ny) ut = ret[-1, :, :, 2] / ret[-1, :, :, 0] vt = ret[-1, :, :, 3] / ret[-1, :, :, 0] plt.streamplot(x, y, ut, vt) plt.show() return ret
def sod_shock(): nx = 200 ny = 5 ρL = 1 pL = 1 vL = 0 ρR = 0.125 pR = 0.1 vR = 0 QL = ρL * array([1., energy(ρL, pL, vL), vL]) QR = ρR * array([1., energy(ρR, pR, vR), vR]) u_ = zeros([nx, 3]) for i in range(nx): if i / nx < 0.5: u_[i] = QL else: u_[i] = QR tf = 0.2 u = zeros([nx, ny, 3]) for i in range(ny): u[:, i] = u_ L = [1., .2] boundaryTypes = ['transitive', 'periodic'] ret = pde_solver(u, tf, L, F=F_euler, stiff=False, boundaryTypes=boundaryTypes) plot_2d(L, ret[-1, :, :, 0]) return ret