Path: blob/main/examples/structured_2d_dgsem/elixir_mhd_alfven_wave.jl
2055 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)4647# create the semi discretization object48semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)4950###############################################################################51# ODE solvers, callbacks etc.5253tspan = (0.0, 2.0)54ode = semidiscretize(semi, tspan)5556summary_callback = SummaryCallback()5758analysis_interval = 10059analysis_callback = AnalysisCallback(semi, interval = analysis_interval,60save_analysis = false,61extra_analysis_integrals = (entropy, energy_total,62energy_kinetic,63energy_internal,64energy_magnetic,65cross_helicity))6667alive_callback = AliveCallback(analysis_interval = analysis_interval)6869save_solution = SaveSolutionCallback(interval = 100,70save_initial_solution = true,71save_final_solution = true,72solution_variables = cons2prim)73cfl = 2.074stepsize_callback = StepsizeCallback(cfl = cfl)7576glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)7778callbacks = CallbackSet(summary_callback,79analysis_callback,80alive_callback,81save_solution,82stepsize_callback,83glm_speed_callback)8485###############################################################################86# run the simulation8788sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);89dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback90ode_default_options()..., callback = callbacks);919293