Path: blob/main/examples/structured_2d_dgsem/elixir_mhd_onion.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# Vertical magnetic streamlines with a bend in the center.5# This makes the streamlines look like a section of an onion.67# Define the initial condition as a vertical field with a bend in the center.8function initial_condition_onion(x, t, equations::IdealGlmMhdEquations2D)9rho = 1.010v1 = 0.011v2 = 0.012v3 = 0.013p = rho^equations.gamma14B1 = -2 * x[1] * x[2] * exp(-x[1]^2 - x[2]^2)15B2 = (2 * x[1]^2 - 1) * exp(-x[1]^2 - x[2]^2) + 116B3 = 0.017psi = 0.01819return prim2cons(SVector(rho, v1, v2, v3, p, B1, B2, B3, psi), equations)20end2122gamma = 5 / 323equations = IdealGlmMhdEquations2D(gamma)2425initial_condition = initial_condition_onion2627cells_per_dimension = (32, 32)28coordinates_min = (-3.0, -3.0)29coordinates_max = (3.0, 3.0)30mesh = StructuredMesh(cells_per_dimension,31coordinates_min,32coordinates_max,33periodicity = (false, false))3435# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of36# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.37# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.38# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.39# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.40# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the41# `StepsizeCallback` (CFL-Condition) and less diffusion.42surface_flux = (FluxLaxFriedrichs(max_abs_speed_naive), flux_nonconservative_powell)43volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)44solver = DGSEM(polydeg = 3, surface_flux = surface_flux,45volume_integral = VolumeIntegralFluxDifferencing(volume_flux))4647boundary_conditions = (x_neg = BoundaryConditionDirichlet(initial_condition),48x_pos = BoundaryConditionDirichlet(initial_condition),49y_neg = BoundaryConditionDirichlet(initial_condition),50y_pos = BoundaryConditionDirichlet(initial_condition))5152semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,53boundary_conditions = boundary_conditions)5455###############################################################################56# ODE solvers, callbacks etc.5758tspan = (0.0, 0.1)59ode = semidiscretize(semi, tspan)6061summary_callback = SummaryCallback()6263analysis_interval = 1006465analysis_callback = AnalysisCallback(semi, interval = 100)6667alive_callback = AliveCallback(analysis_interval = analysis_interval)6869save_solution = SaveSolutionCallback(interval = 50,70save_initial_solution = true,71save_final_solution = true,72solution_variables = cons2prim)7374cfl = 1.07576stepsize_callback = StepsizeCallback(cfl = cfl)7778glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)7980callbacks = CallbackSet(summary_callback,81analysis_callback, alive_callback,82save_solution,83stepsize_callback,84glm_speed_callback)8586###############################################################################87# run the simulation8889sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);90dt = 0.01, # solve needs some value here but it will be overwritten by the stepsize_callback91ode_default_options()..., callback = callbacks);929394