# 二维黎曼问题

## 问题描述

$\begin{split}\frac{\partial}{\partial t} \left(\begin{matrix} \rho \\ \rho u \\ \rho v \\ E \\\end{matrix} \right) + \frac{\partial}{\partial x} \left(\begin{matrix} \rho u \\ \rho u^2 + p \\ \rho u v \\ u(E + p) \\\end{matrix} \right) + \frac{\partial}{\partial y} \left(\begin{matrix} \rho v \\ \rho uv \\ \rho v^2 + p \\ v(E + p) \\\end{matrix} \right) = 0\end{split}$
$E = \frac{\rho}{\gamma - 1} + \frac{1}{2}\rho u^2$

$\begin{split}\left(\begin{matrix} \rho \\ u \\ v \\ p \\\end{matrix}\right)_{x<0.5, y>0.5} = \left(\begin{matrix} 0.5323 \\ 1.206 \\ 0.0 \\ 0.3 \\\end{matrix}\right), \quad \left(\begin{matrix} \rho \\ u \\ v \\ p \\\end{matrix}\right)_{x>0.5, y>0.5} = \left(\begin{matrix} 1.5 \\ 0.0 \\ 0.0 \\ 1.5 \\\end{matrix}\right)\end{split}$
$\begin{split}\left(\begin{matrix} \rho \\ u \\ v \\ p \\\end{matrix}\right)_{x<0.5, y<0.5} = \left(\begin{matrix} 0.138 \\ 1.206 \\ 1.206 \\ 0.029 \\\end{matrix}\right), \quad \left(\begin{matrix} \rho \\ u \\ v \\ p \\\end{matrix}\right)_{x>0.5, y<0.5} = \left(\begin{matrix} 0.5323 \\ 0.0 \\ 1.206 \\ 0.3 \\\end{matrix}\right)\end{split}$

[1]:

import mindspore as ms
from mindflow import cfd
from mindflow.cfd.runtime import RunTime
from mindflow.cfd.simulator import Simulator

from src.ic import riemann2d_ic

ms.set_context(device_target="GPU", device_id=3)


## 定义Simulator和RunTime

[2]:

config = load_yaml_config('numeric.yaml')
simulator = Simulator(config)
runtime = RunTime(config['runtime'], simulator.mesh_info, simulator.material)


## 初始条件

[3]:

mesh_x, mesh_y, _ = simulator.mesh_info.mesh_xyz()
pri_var = riemann2d_ic(mesh_x, mesh_y)
con_var = cfd.cal_con_var(pri_var, simulator.material)


## 执行仿真

[4]:

while runtime.time_loop(pri_var):
pri_var = cfd.cal_pri_var(con_var, simulator.material)
runtime.compute_timestep(pri_var)
con_var = simulator.integration_step(con_var, runtime.timestep)

current time = 0.000000, time step = 0.001005
current time = 0.001005, time step = 0.001005
current time = 0.002010, time step = 0.001005
current time = 0.003016, time step = 0.001005
current time = 0.004021, time step = 0.001005
current time = 0.005026, time step = 0.001005
current time = 0.006031, time step = 0.001005
current time = 0.007036, time step = 0.001005
current time = 0.008041, time step = 0.001005
current time = 0.009046, time step = 0.001005
current time = 0.010051, time step = 0.001005
current time = 0.011057, time step = 0.001005
current time = 0.012062, time step = 0.001005
current time = 0.013067, time step = 0.001005
current time = 0.014072, time step = 0.001005
current time = 0.015076, time step = 0.001005
current time = 0.016081, time step = 0.001005
current time = 0.017086, time step = 0.001005
current time = 0.018091, time step = 0.001005
current time = 0.019097, time step = 0.001005
current time = 0.020102, time step = 0.001005
current time = 0.021107, time step = 0.001005
current time = 0.022112, time step = 0.001005
current time = 0.023117, time step = 0.001005
current time = 0.024121, time step = 0.001005
current time = 0.025126, time step = 0.001005
current time = 0.026131, time step = 0.001005
current time = 0.027137, time step = 0.001005
current time = 0.028142, time step = 0.001005
...
current time = 0.297090, time step = 0.000760
current time = 0.297849, time step = 0.000759
current time = 0.298609, time step = 0.000759
current time = 0.299368, time step = 0.000759


## 仿真结果后处理

[5]:

pri_var = cfd.cal_pri_var(con_var, simulator.material)
vis_2d(pri_var, 'riemann2d.jpg')