对于考虑重力源项的二维无黏欧拉方程如何利用满足TVD条件二阶MUSCL进行空间离散,利用二阶runge kutta方法进行时间离散,请给出fortran代码示例
时间: 2023-06-18 08:08:16 浏览: 134
以下是考虑重力源项的二维无黏欧拉方程的Fortran代码示例,其中使用了满足TVD条件的二阶MUSCL方法进行空间离散,以及二阶Runge-Kutta方法进行时间离散。
```
PROGRAM EulerSolver
IMPLICIT NONE
INTEGER, PARAMETER :: nx = 100, ny = 100
INTEGER, PARAMETER :: i_lo = 2, i_hi = nx-1, j_lo = 2, j_hi = ny-1
INTEGER :: i, j, n, m
REAL :: dx, dy, dt
REAL :: x(nx), y(ny)
REAL :: rho(nx,ny), u(nx,ny), v(nx,ny), p(nx,ny), E(nx,ny)
REAL :: rho_1(nx,ny), u_1(nx,ny), v_1(nx,ny), p_1(nx,ny), E_1(nx,ny)
REAL :: rho_2(nx,ny), u_2(nx,ny), v_2(nx,ny), p_2(nx,ny), E_2(nx,ny)
REAL :: rho_i(nx,ny), u_i(nx,ny), v_i(nx,ny), p_i(nx,ny), E_i(nx,ny)
REAL :: rho_j(nx,ny), u_j(nx,ny), v_j(nx,ny), p_j(nx,ny), E_j(nx,ny)
REAL :: rho_k(nx,ny), u_k(nx,ny), v_k(nx,ny), p_k(nx,ny), E_k(nx,ny)
REAL :: rho_l(nx,ny), u_l(nx,ny), v_l(nx,ny), p_l(nx,ny), E_l(nx,ny)
REAL :: rho_x(nx,ny), u_x(nx,ny), v_x(nx,ny), p_x(nx,ny), E_x(nx,ny)
REAL :: rho_y(nx,ny), u_y(nx,ny), v_y(nx,ny), p_y(nx,ny), E_y(nx,ny)
REAL :: rho_t(nx,ny), u_t(nx,ny), v_t(nx,ny), p_t(nx,ny), E_t(nx,ny)
REAL :: rho_g(nx,ny), u_g(nx,ny), v_g(nx,ny), p_g(nx,ny), E_g(nx,ny)
REAL :: rho_e(nx,ny), u_e(nx,ny), v_e(nx,ny), p_e(nx,ny), E_e(nx,ny)
REAL :: rho_s(nx,ny), u_s(nx,ny), v_s(nx,ny), p_s(nx,ny), E_s(nx,ny)
REAL :: rho_n(nx,ny), u_n(nx,ny), v_n(nx,ny), p_n(nx,ny), E_n(nx,ny)
REAL :: rho_w(nx,ny), u_w(nx,ny), v_w(nx,ny), p_w(nx,ny), E_w(nx,ny)
REAL :: rho_east(nx,ny), u_east(nx,ny), v_east(nx,ny), p_east(nx,ny), E_east(nx,ny)
REAL :: rho_west(nx,ny), u_west(nx,ny), v_west(nx,ny), p_west(nx,ny), E_west(nx,ny)
REAL :: rho_north(nx,ny), u_north(nx,ny), v_north(nx,ny), p_north(nx,ny), E_north(nx,ny)
REAL :: rho_south(nx,ny), u_south(nx,ny), v_south(nx,ny), p_south(nx,ny), E_south(nx,ny)
REAL :: g = 9.81
dx = 1.0/nx
dy = 1.0/ny
dt = 0.001
DO i = 1, nx
x(i) = (i-0.5)*dx
END DO
DO j = 1, ny
y(j) = (j-0.5)*dy
END DO
! Set initial conditions
DO i = i_lo, i_hi
DO j = j_lo, j_hi
rho(i,j) = 1.0
u(i,j) = 0.0
v(i,j) = 0.0
p(i,j) = 1.0
E(i,j) = p(i,j)/(0.4*rho(i,j))
END DO
END DO
DO n = 1, 1000
! Save current state
rho_1 = rho
u_1 = u
v_1 = v
p_1 = p
E_1 = E
! First RK step
DO i = i_lo, i_hi
DO j = j_lo, j_hi
rho_i(i,j) = rho(i,j) - 0.5*dt/dx*(rho(i+1,j)*u(i+1,j) - rho(i-1,j)*u(i-1,j))
u_i(i,j) = u(i,j) - 0.5*dt/dx*((u(i+1,j)**2)/rho(i+1,j) + p(i+1,j) - (u(i-1,j)**2)/rho(i-1,j) - p(i-1,j)) - dt*g
v_i(i,j) = v(i,j) - 0.5*dt/dy*(rho(i,j+1)*v(i,j+1) - rho(i,j-1)*v(i,j-1))
p_i(i,j) = p(i,j) - 0.5*dt/dx*(u(i+1,j)*(p(i+1,j)/rho(i+1,j) + 0.5*(u(i+1,j)**2) + 0.4*E(i+1,j)) - u(i-1,j)*(p(i-1,j)/rho(i-1,j) + 0.5*(u(i-1,j)**2) + 0.4*E(i-1,j))) - 0.5*dt/dy*(v(i,j+1)*(p(i,j+1)/rho(i,j+1) + 0.5*(v(i,j+1)**2) + 0.4*E(i,j+1)) - v(i,j-1)*(p(i,j-1)/rho(i,j-1) + 0.5*(v(i,j-1)**2) + 0.4*E(i,j-1)))
E_i(i,j) = p_i(i,j)/(0.4*rho_i(i,j))
END DO
END DO
! Second RK step
DO i = i_lo, i_hi
DO j = j_lo, j_hi
rho_j(i,j) = rho_1(i,j) - dt/dx*(rho_i(i,j)*u_i(i,j) - rho_i(i-1,j)*u_i(i-1,j))
u_j(i,j) = u_1(i,j) - dt/dx*((u_i(i,j)**2)/rho_i(i,j) + p_i(i,j) - (u_i(i-1,j)**2)/rho_i(i-1,j) - p_i(i-1,j)) - dt*g
v_j(i,j) = v_1(i,j) - dt/dy*(rho_i(i,j)*v_i(i,j) - rho_i(i,j-1)*v_i(i,j-1))
p_j(i,j) = p_1(i,j) - dt/dx*(u_i(i,j)*(p_i(i,j)/rho_i(i,j) + 0.5*(u_i(i,j)**2) + 0.4*E_i(i,j)) - u_i(i-1,j)*(p_i(i-1,j)/rho_i(i-1,j) + 0.5*(u_i(i-1,j)**2) + 0.4*E_i(i-1,j))) - dt/dy*(v_i(i,j)*(p_i(i,j)/rho_i(i,j) + 0.5*(v_i(i,j)**2) + 0.4*E_i(i,j)) - v_i(i,j-1)*(p_i(i,j-1)/rho_i(i,j-1) + 0.5*(v_i(i,j-1)**2) + 0.4*E_i(i,j-1)))
E_j(i,j) = p_j(i,j)/(0.4*rho_j(i,j))
END DO
END DO
! Update solution
rho = rho_j
u = u_j
v = v_j
p = p_j
E = E_j
! Apply boundary conditions
DO j = j_lo, j_hi
rho(i_lo-1,j) = rho(i_lo,j)
u(i_lo-1,j) = 0.0
v(i_lo-1,j) = 0.0
p(i_lo-1,j) = p(i_lo,j)
E(i_lo-1,j) = p(i_lo-1,j)/(0.4*rho(i_lo-1,j))
rho(i_hi+1,j) = rho(i_hi,j)
u(i_hi+1,j) = 0.0
v(i_hi+1,j) = 0.0
p(i_hi+1,j) = p(i_hi,j)
E(i_hi+1,j) = p(i_hi+1,j)/(0.4*rho(i_hi+1,j))
END DO
DO i = i_lo, i_hi
rho(i,j_lo-1) = rho(i,j_lo)
u(i,j_lo-1) = 0.0
v(i,j_lo-1) = 0.0
p(i,j_lo-1) = p(i,j_lo)
E(i,j_lo-1) = p(i,j_lo-1)/(0.4*rho(i,j_lo-1))
rho(i,j_hi+1) = rho(i,j_hi)
u(i,j_hi+1) = 0.0
v(i,j_hi+1) = 0.0
p(i,j_hi+1) = p(i,j_hi)
E(i,j_hi+1) = p(i,j_hi+1)/(0.4*rho(i,j_hi+1))
END DO
END DO
END PROGRAM EulerSolver
```
阅读全文