Path: blob/main/examples/structured_2d_dgsem/elixir_mhd_alfven_wave.jl
2802 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the compressible ideal GLM-MHD equations56gamma = 5 / 37equations = IdealGlmMhdEquations2D(gamma)89initial_condition = initial_condition_convergence_test1011# Get the DG approximation space1213# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of14# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.15# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.16# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.17# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.18# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the19# `StepsizeCallback` (CFL-Condition) and less diffusion.20surface_flux = (FluxLaxFriedrichs(max_abs_speed_naive), flux_nonconservative_powell)21volume_flux = (flux_central, flux_nonconservative_powell)22solver = DGSEM(polydeg = 3, surface_flux = surface_flux,23volume_integral = VolumeIntegralFluxDifferencing(volume_flux))2425# Get the curved quad mesh from a mapping function26# Mapping as described in https://arxiv.org/abs/1809.0117827function mapping(xi_, eta_)28# Transform input variables between -1 and 1 onto [0, sqrt(2)]29# Note, we use the domain [0, sqrt(2)]^2 for the Alfvén wave convergence test case30xi = 0.5 * sqrt(2) * xi_ + 0.5 * sqrt(2)31eta = 0.5 * sqrt(2) * eta_ + 0.5 * sqrt(2)3233y = eta +34sqrt(2) / 12 * (cos(1.5 * pi * (2 * xi - sqrt(2)) / sqrt(2)) *35cos(0.5 * pi * (2 * eta - sqrt(2)) / sqrt(2)))3637x = xi +38sqrt(2) / 12 * (cos(0.5 * pi * (2 * xi - sqrt(2)) / sqrt(2)) *39cos(2 * pi * (2 * y - sqrt(2)) / sqrt(2)))4041return SVector(x, y)42end4344cells_per_dimension = (4, 4)45mesh = StructuredMesh(cells_per_dimension, mapping, periodicity = true)4647# create the semi discretization object48semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;49boundary_conditions = boundary_condition_periodic)5051###############################################################################52# ODE solvers, callbacks etc.5354tspan = (0.0, 2.0)55ode = semidiscretize(semi, tspan)5657summary_callback = SummaryCallback()5859analysis_interval = 10060analysis_callback = AnalysisCallback(semi, interval = analysis_interval,61save_analysis = false,62extra_analysis_integrals = (entropy, energy_total,63energy_kinetic,64energy_internal,65energy_magnetic,66cross_helicity))6768alive_callback = AliveCallback(analysis_interval = analysis_interval)6970save_solution = SaveSolutionCallback(interval = 100,71save_initial_solution = true,72save_final_solution = true,73solution_variables = cons2prim)74cfl = 2.075stepsize_callback = StepsizeCallback(cfl = cfl)7677glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)7879callbacks = CallbackSet(summary_callback,80analysis_callback,81alive_callback,82save_solution,83stepsize_callback,84glm_speed_callback)8586###############################################################################87# run the simulation8889sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);90dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback91ode_default_options()..., callback = callbacks);929394