Path: blob/main/examples/p4est_3d_dgsem/elixir_mhd_shockcapturing_subcell.jl
5586 views
using Trixi12###############################################################################3# semidiscretization of the compressible ideal GLM-MHD equations45equations = IdealGlmMhdEquations3D(1.4)67"""8initial_condition_blast_wave(x, t, equations::IdealGlmMhdEquations3D)910Weak magnetic blast wave setup taken from Section 6.1 of the paper:11- A. M. Rueda-Ramírez, S. Hennemann, F. J. Hindenlang, A. R. Winters, G. J. Gassner (2021)12An entropy stable nodal discontinuous Galerkin method for the resistive MHD13equations. Part II: Subcell finite volume shock capturing14[doi: 10.1016/j.jcp.2021.110580](https://doi.org/10.1016/j.jcp.2021.110580)15"""16function initial_condition_blast_wave(x, t, equations::IdealGlmMhdEquations3D)17# Center of the blast wave is selected for the domain [0, 3]^318inicenter = (1.5, 1.5, 1.5)19x_norm = x[1] - inicenter[1]20y_norm = x[2] - inicenter[2]21z_norm = x[3] - inicenter[3]22r = sqrt(x_norm^2 + y_norm^2 + z_norm^2)2324delta_0 = 0.125r_0 = 0.326lambda = exp(5.0 / delta_0 * (r - r_0))2728p_inner = 0.929p_outer = 5e-230prim_inner = SVector(1.2, 0.1, 0.0, 0.1, p_inner, 1.0, 1.0, 1.0, 0.0)31prim_outer = SVector(1.2, 0.2, -0.4, 0.2, p_outer, 1.0, 1.0, 1.0, 0.0)32prim_vars = (prim_inner + lambda * prim_outer) / (1.0 + lambda)3334return prim2cons(prim_vars, equations)35end36initial_condition = initial_condition_blast_wave3738surface_flux = (flux_lax_friedrichs, flux_nonconservative_powell_local_symmetric)39volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell_local_symmetric)40polydeg = 341basis = LobattoLegendreBasis(polydeg)42limiter_idp = SubcellLimiterIDP(equations, basis;43positivity_variables_cons = ["rho"],44positivity_variables_nonlinear = [pressure])45volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;46volume_flux_dg = volume_flux,47volume_flux_fv = surface_flux)48solver = DGSEM(basis, surface_flux, volume_integral)4950# Mapping as described in https://arxiv.org/abs/2012.12040 but with slightly less warping.51# The mapping will be interpolated at tree level, and then refined without changing52# the geometry interpolant.53function mapping(xi_, eta_, zeta_)54# Transform input variables between -1 and 1 onto [0,3]55xi = 1.5 * xi_ + 1.556eta = 1.5 * eta_ + 1.557zeta = 1.5 * zeta_ + 1.55859y = eta +603 / 11 * (cos(1.5 * pi * (2 * xi - 3) / 3) *61cos(0.5 * pi * (2 * eta - 3) / 3) *62cos(0.5 * pi * (2 * zeta - 3) / 3))6364x = xi +653 / 11 * (cos(0.5 * pi * (2 * xi - 3) / 3) *66cos(2 * pi * (2 * y - 3) / 3) *67cos(0.5 * pi * (2 * zeta - 3) / 3))6869z = zeta +703 / 11 * (cos(0.5 * pi * (2 * x - 3) / 3) *71cos(pi * (2 * y - 3) / 3) *72cos(0.5 * pi * (2 * zeta - 3) / 3))7374return SVector(x, y, z)75end7677trees_per_dimension = (2, 2, 2)78mesh = P4estMesh(trees_per_dimension,79polydeg = 3,80mapping = mapping,81initial_refinement_level = 2,82periodicity = true)8384semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;85boundary_conditions = boundary_condition_periodic)8687###############################################################################88# ODE solvers, callbacks etc.8990tspan = (0.0, 0.5)91ode = semidiscretize(semi, tspan)9293summary_callback = SummaryCallback()9495analysis_interval = 10096analysis_callback = AnalysisCallback(semi, interval = analysis_interval)9798alive_callback = AliveCallback(analysis_interval = analysis_interval)99100save_solution = SaveSolutionCallback(interval = 100,101save_initial_solution = true,102save_final_solution = true,103solution_variables = cons2prim,104extra_node_variables = (:limiting_coefficient,))105106cfl = 0.9107stepsize_callback = StepsizeCallback(cfl = cfl)108109glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)110111callbacks = CallbackSet(summary_callback,112analysis_callback,113alive_callback,114save_solution,115stepsize_callback,116glm_speed_callback)117118###############################################################################119# run the simulation120stage_callbacks = (SubcellLimiterIDPCorrection(), BoundsCheckCallback())121122sol = Trixi.solve(ode, Trixi.SimpleSSPRK33(stage_callbacks = stage_callbacks);123dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback124callback = callbacks);125126127