Path: blob/main/examples/p4est_3d_dgsem/elixir_mhd_shockcapturing_amr.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the compressible ideal GLM-MHD equations56equations = IdealGlmMhdEquations3D(1.4)78"""9initial_condition_blast_wave(x, t, equations::IdealGlmMhdEquations3D)1011Weak magnetic blast wave setup taken from Section 6.1 of the paper:12- A. M. Rueda-Ramírez, S. Hennemann, F. J. Hindenlang, A. R. Winters, G. J. Gassner (2021)13An entropy stable nodal discontinuous Galerkin method for the resistive MHD14equations. Part II: Subcell finite volume shock capturing15[doi: 10.1016/j.jcp.2021.110580](https://doi.org/10.1016/j.jcp.2021.110580)16"""17function initial_condition_blast_wave(x, t, equations::IdealGlmMhdEquations3D)18# Center of the blast wave is selected for the domain [0, 3]^319inicenter = (1.5, 1.5, 1.5)20x_norm = x[1] - inicenter[1]21y_norm = x[2] - inicenter[2]22z_norm = x[3] - inicenter[3]23r = sqrt(x_norm^2 + y_norm^2 + z_norm^2)2425delta_0 = 0.126r_0 = 0.327lambda = exp(5.0 / delta_0 * (r - r_0))2829prim_inner = SVector(1.2, 0.1, 0.0, 0.1, 0.9, 1.0, 1.0, 1.0, 0.0)30prim_outer = SVector(1.2, 0.2, -0.4, 0.2, 0.3, 1.0, 1.0, 1.0, 0.0)31prim_vars = (prim_inner + lambda * prim_outer) / (1.0 + lambda)3233return prim2cons(prim_vars, equations)34end35initial_condition = initial_condition_blast_wave3637# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of38# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.39# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.40# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.41# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.42# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the43# `StepsizeCallback` (CFL-Condition) and less diffusion.44surface_flux = (FluxLaxFriedrichs(max_abs_speed_naive), flux_nonconservative_powell)45volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)46polydeg = 347basis = LobattoLegendreBasis(polydeg)48indicator_sc = IndicatorHennemannGassner(equations, basis,49alpha_max = 0.5,50alpha_min = 0.001,51alpha_smooth = true,52variable = density_pressure)53volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;54volume_flux_dg = volume_flux,55volume_flux_fv = surface_flux)5657solver = DGSEM(polydeg = polydeg, surface_flux = surface_flux,58volume_integral = volume_integral)5960# Mapping as described in https://arxiv.org/abs/2012.12040 but with slightly less warping.61# The mapping will be interpolated at tree level, and then refined without changing62# the geometry interpolant.63function mapping(xi_, eta_, zeta_)64# Transform input variables between -1 and 1 onto [0,3]65xi = 1.5 * xi_ + 1.566eta = 1.5 * eta_ + 1.567zeta = 1.5 * zeta_ + 1.56869y = eta +703 / 11 * (cos(1.5 * pi * (2 * xi - 3) / 3) *71cos(0.5 * pi * (2 * eta - 3) / 3) *72cos(0.5 * pi * (2 * zeta - 3) / 3))7374x = xi +753 / 11 * (cos(0.5 * pi * (2 * xi - 3) / 3) *76cos(2 * pi * (2 * y - 3) / 3) *77cos(0.5 * pi * (2 * zeta - 3) / 3))7879z = zeta +803 / 11 * (cos(0.5 * pi * (2 * x - 3) / 3) *81cos(pi * (2 * y - 3) / 3) *82cos(0.5 * pi * (2 * zeta - 3) / 3))8384return SVector(x, y, z)85end8687trees_per_dimension = (2, 2, 2)88mesh = P4estMesh(trees_per_dimension,89polydeg = 3,90mapping = mapping,91initial_refinement_level = 2,92periodicity = true)9394# create the semi discretization object95semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;96boundary_conditions = boundary_condition_periodic)9798###############################################################################99# ODE solvers, callbacks etc.100101tspan = (0.0, 0.5)102ode = semidiscretize(semi, tspan)103104summary_callback = SummaryCallback()105106analysis_interval = 100107analysis_callback = AnalysisCallback(semi, interval = analysis_interval)108109alive_callback = AliveCallback(analysis_interval = analysis_interval)110111amr_indicator = IndicatorLöhner(semi,112variable = density_pressure)113amr_controller = ControllerThreeLevel(semi, amr_indicator,114base_level = 2,115max_level = 4, max_threshold = 0.15)116amr_callback = AMRCallback(semi, amr_controller,117interval = 5,118adapt_initial_condition = true,119adapt_initial_condition_only_refine = true)120121cfl = 1.4122stepsize_callback = StepsizeCallback(cfl = cfl)123124glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)125126callbacks = CallbackSet(summary_callback,127analysis_callback,128alive_callback,129amr_callback,130stepsize_callback,131glm_speed_callback)132133###############################################################################134# run the simulation135136sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);137dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback138ode_default_options()..., callback = callbacks);139140141