Path: blob/main/examples/tree_3d_dgsem/elixir_euler_amr.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the compressible Euler equations56equations = CompressibleEulerEquations3D(1.4)78"""9initial_condition_density_pulse(x, t, equations::CompressibleEulerEquations3D)1011A Gaussian pulse in the density with constant velocity and pressure; reduces the12compressible Euler equations to the linear advection equations.13"""14function initial_condition_density_pulse(x, t, equations::CompressibleEulerEquations3D)15rho = 1 + exp(-(x[1]^2 + x[2]^2 + x[3]^2)) / 216v1 = 117v2 = 118v3 = 119rho_v1 = rho * v120rho_v2 = rho * v221rho_v3 = rho * v322p = 123rho_e_total = p / (equations.gamma - 1) + 1 / 2 * rho * (v1^2 + v2^2 + v3^2)24return SVector(rho, rho_v1, rho_v2, rho_v3, rho_e_total)25end26initial_condition = initial_condition_density_pulse27# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of28# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.29# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.30# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.31# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.32# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the33# `StepsizeCallback` (CFL-Condition) and less diffusion.34solver = DGSEM(polydeg = 3, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive))3536coordinates_min = (-5.0, -5.0, -5.0)37coordinates_max = (5.0, 5.0, 5.0)38mesh = TreeMesh(coordinates_min, coordinates_max,39initial_refinement_level = 4,40n_cells_max = 10_000, periodicity = true)4142semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;43boundary_conditions = boundary_condition_periodic)4445###############################################################################46# ODE solvers, callbacks etc.4748tspan = (0.0, 10.0)49ode = semidiscretize(semi, tspan)5051summary_callback = SummaryCallback()5253analysis_interval = 10054analysis_callback = AnalysisCallback(semi, interval = analysis_interval,55extra_analysis_integrals = (entropy,))5657alive_callback = AliveCallback(analysis_interval = analysis_interval)5859save_restart = SaveRestartCallback(interval = 100,60save_final_restart = true)6162save_solution = SaveSolutionCallback(interval = 100,63save_initial_solution = true,64save_final_solution = true,65solution_variables = cons2prim)6667amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable = first),68base_level = 4,69med_level = 5, med_threshold = 1.05,70max_level = 6, max_threshold = 1.3)71amr_callback = AMRCallback(semi, amr_controller,72interval = 5,73adapt_initial_condition = true,74adapt_initial_condition_only_refine = true)7576stepsize_callback = StepsizeCallback(cfl = 0.9)7778callbacks = CallbackSet(summary_callback,79analysis_callback, alive_callback,80save_restart, save_solution,81amr_callback, stepsize_callback);8283###############################################################################84# run the simulation8586sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);87dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback88ode_default_options()..., callback = callbacks);899091