Path: blob/main/examples/unstructured_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_onion2627# Get the unstructured quad mesh from a file (downloads the file if not available locally)28mesh_file = Trixi.download("https://gist.githubusercontent.com/patrickersing/8fe7e61bf1e79eeafa031ec2e355803d/raw/7b26d86f15a419152a505934ae742457826d99b5/mesh_mhd_onion.mesh",29joinpath(@__DIR__, "mesh_mhd_onion.mesh"))30mesh = UnstructuredMesh2D(mesh_file, periodicity = false)3132# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of33# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.34# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.35# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.36# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.37# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the38# `StepsizeCallback` (CFL-Condition) and less diffusion.39surface_flux = (FluxLaxFriedrichs(max_abs_speed_naive), flux_nonconservative_powell)40volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)41solver = DGSEM(polydeg = 3, surface_flux = surface_flux,42volume_integral = VolumeIntegralFluxDifferencing(volume_flux))4344boundary_conditions = Dict(:Bottom => BoundaryConditionDirichlet(initial_condition),45:Top => BoundaryConditionDirichlet(initial_condition),46:Right => BoundaryConditionDirichlet(initial_condition),47:Left => BoundaryConditionDirichlet(initial_condition))4849semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,50boundary_conditions = boundary_conditions)5152###############################################################################53# ODE solvers, callbacks etc.5455tspan = (0.0, 0.1)56ode = semidiscretize(semi, tspan)5758summary_callback = SummaryCallback()5960analysis_interval = 1006162analysis_callback = AnalysisCallback(semi, interval = 100)6364alive_callback = AliveCallback(analysis_interval = analysis_interval)6566save_solution = SaveSolutionCallback(interval = 50,67save_initial_solution = true,68save_final_solution = true,69solution_variables = cons2prim)7071cfl = 1.07273stepsize_callback = StepsizeCallback(cfl = cfl)7475glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)7677callbacks = CallbackSet(summary_callback,78analysis_callback, alive_callback,79save_solution,80stepsize_callback,81glm_speed_callback)8283###############################################################################84# run the simulation8586sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);87dt = 0.01, # solve needs some value here but it will be overwritten by the stepsize_callback88ode_default_options()..., callback = callbacks);899091