2D Riemann
This notebook requires MindSpore version >= 2.0.0 to support new APIs including: mindspore.jit, mindspore.jit_class.
A Riemann problem, named after Bernhard Riemann, is a specific initial value problem composed of a conservation equation together with piecewise constant initial data which has a single discontinuity in the domain of interest. The Riemann problem is very useful for the understanding of equations like Euler conservation equations because all properties, such as shocks and rarefaction waves, appear as characteristics in the solution. It also gives an exact solution to some complex nonlinear equations, such as the Euler equations.
In numerical analysis, Riemann problems appear in a natural way in finite volume methods for the solution of conservation law equations due to the discreteness of the grid. For that it is widely used in computational fluid dynamics and in computational magnetohydrodynamics simulations.
Problem Description
The definition of the 2 dimensional Riemann problem is:
where \(\gamma = 1.4\) for ideal gas. The initial condition is:
The following src
pacakage can be downloaded in src.
[1]:
import mindspore as ms
from mindflow import load_yaml_config, vis_2d
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)
Defining Simulator and RunTime
The mesh, material, runtime, boundary conditions and numerical methods are defined in numeric.yaml.
[2]:
config = load_yaml_config('numeric.yaml')
simulator = Simulator(config)
runtime = RunTime(config['runtime'], simulator.mesh_info, simulator.material)
Initial Condition
Initial condition is determined according to mesh coordinates.
[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)
Running Simulation
Run CFD simulation with time marching.
[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)
runtime.advance()
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
Post Processing
You can view the density, pressure and velocity.
[5]:
pri_var = cfd.cal_pri_var(con_var, simulator.material)
vis_2d(pri_var, 'riemann2d.jpg')