Path: blob/main/examples/tree_2d_dgsem/elixir_euler_positivity.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the compressible Euler equations5gamma = 1.46equations = CompressibleEulerEquations2D(gamma)78"""9initial_condition_sedov_blast_wave(x, t, equations::CompressibleEulerEquations2D)1011The Sedov blast wave setup based on Flash12- https://flash.rochester.edu/site/flashcode/user_support/flash_ug_devel/node187.html#SECTION01011400000000000000013"""14function initial_condition_sedov_blast_wave(x, t, equations::CompressibleEulerEquations2D)15# Set up polar coordinates16RealT = eltype(x)17inicenter = SVector(0, 0)18x_norm = x[1] - inicenter[1]19y_norm = x[2] - inicenter[2]20r = sqrt(x_norm^2 + y_norm^2)2122# Setup based on https://flash.rochester.edu/site/flashcode/user_support/flash_ug_devel/node187.html#SECTION01011400000000000000023r0 = 0.21875f0 # = 3.5 * smallest dx (for domain length=4 and max-ref=6)24# r0 = 0.5 # = more reasonable setup25E = 126p0_inner = 3 * (equations.gamma - 1) * E / (3 * convert(RealT, pi) * r0^2)27p0_outer = convert(RealT, 1.0e-5) # = true Sedov setup28# p0_outer = 1.0e-3 # = more reasonable setup2930# Calculate primitive variables31rho = 132v1 = 033v2 = 034p = r > r0 ? p0_outer : p0_inner3536return prim2cons(SVector(rho, v1, v2, p), equations)37end38initial_condition = initial_condition_sedov_blast_wave3940# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of41# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.42# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.43# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.44# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.45# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the46# `StepsizeCallback` (CFL-Condition) and less diffusion.47surface_flux = FluxLaxFriedrichs(max_abs_speed_naive)48volume_flux = flux_ranocha49basis = LobattoLegendreBasis(3)50indicator_sc = IndicatorHennemannGassner(equations, basis,51alpha_max = 0.5,52alpha_min = 0.001,53alpha_smooth = true,54variable = density_pressure)55volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;56volume_flux_dg = volume_flux,57volume_flux_fv = surface_flux)58solver = DGSEM(basis, surface_flux, volume_integral)5960coordinates_min = (-2.0, -2.0)61coordinates_max = (2.0, 2.0)62mesh = TreeMesh(coordinates_min, coordinates_max,63initial_refinement_level = 6,64n_cells_max = 100_000)6566semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)6768###############################################################################69# ODE solvers, callbacks etc.7071tspan = (0.0, 4.0)72ode = semidiscretize(semi, tspan)7374summary_callback = SummaryCallback()7576analysis_interval = 50077analysis_callback = AnalysisCallback(semi, interval = analysis_interval)7879alive_callback = AliveCallback(analysis_interval = analysis_interval)8081save_solution = SaveSolutionCallback(interval = 100,82save_initial_solution = true,83save_final_solution = true,84solution_variables = cons2prim)8586amr_indicator = IndicatorLöhner(semi,87variable = density_pressure)88amr_controller = ControllerThreeLevel(semi, amr_indicator,89base_level = 4,90med_level = 0, med_threshold = 0.1, # med_level = current level91max_level = 6, max_threshold = 0.3)92amr_callback = AMRCallback(semi, amr_controller,93interval = 2,94adapt_initial_condition = true,95adapt_initial_condition_only_refine = true)9697stepsize_callback = StepsizeCallback(cfl = 0.8)9899callbacks = CallbackSet(summary_callback,100analysis_callback, alive_callback,101save_solution,102amr_callback, stepsize_callback)103104stage_limiter! = PositivityPreservingLimiterZhangShu(thresholds = (5.0e-6, 5.0e-6),105variables = (Trixi.density, pressure))106107###############################################################################108# run the simulation109110sol = solve(ode, CarpenterKennedy2N54(stage_limiter!, williamson_condition = false);111dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback112ode_default_options()..., callback = callbacks);113114115