Path: blob/main/examples/structured_2d_dgsem/elixir_mhd_ec.jl
2055 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the compressible ideal GLM-MHD equations56equations = IdealGlmMhdEquations2D(1.4)78function initial_condition_shifted_weak_blast_wave(x, t, equations::IdealGlmMhdEquations2D)9# Adapted MHD version of the weak blast wave from Hennemann & Gassner JCP paper 2020 (Sec. 6.3)10# Same discontinuity in the velocities but with magnetic fields11# Set up polar coordinates12inicenter = (1.5, 1.5)13x_norm = x[1] - inicenter[1]14y_norm = x[2] - inicenter[2]15r = sqrt(x_norm^2 + y_norm^2)16phi = atan(y_norm, x_norm)1718# Calculate primitive variables19rho = r > 0.5 ? 1.0 : 1.169120v1 = r > 0.5 ? 0.0 : 0.1882 * cos(phi)21v2 = r > 0.5 ? 0.0 : 0.1882 * sin(phi)22p = r > 0.5 ? 1.0 : 1.2452324return prim2cons(SVector(rho, v1, v2, 0.0, p, 1.0, 1.0, 1.0, 0.0), equations)25end2627initial_condition = initial_condition_shifted_weak_blast_wave2829# Get the DG approximation space30volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)31solver = DGSEM(polydeg = 5,32surface_flux = (flux_hindenlang_gassner, flux_nonconservative_powell),33volume_integral = VolumeIntegralFluxDifferencing(volume_flux))3435# Get the curved quad mesh from a mapping function36# Mapping as described in https://arxiv.org/abs/2012.12040, but reduced to 2D37function mapping(xi_, eta_)38# Transform input variables between -1 and 1 onto [0,3]39xi = 1.5 * xi_ + 1.540eta = 1.5 * eta_ + 1.54142y = eta + 3 / 8 * (cos(1.5 * pi * (2 * xi - 3) / 3) *43cos(0.5 * pi * (2 * eta - 3) / 3))4445x = xi + 3 / 8 * (cos(0.5 * pi * (2 * xi - 3) / 3) *46cos(2 * pi * (2 * y - 3) / 3))4748return SVector(x, y)49end5051# Create curved mesh with 8 x 8 elements52cells_per_dimension = (8, 8)53mesh = StructuredMesh(cells_per_dimension, mapping)5455# create the semi discretization object56semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)5758###############################################################################59# ODE solvers, callbacks etc.6061tspan = (0.0, 2.0)62ode = semidiscretize(semi, tspan)6364summary_callback = SummaryCallback()6566analysis_interval = 10067analysis_callback = AnalysisCallback(semi, interval = analysis_interval,68save_analysis = false,69extra_analysis_integrals = (entropy, energy_total,70energy_kinetic,71energy_internal,72energy_magnetic,73cross_helicity))7475alive_callback = AliveCallback(analysis_interval = analysis_interval)7677save_solution = SaveSolutionCallback(interval = 100,78save_initial_solution = true,79save_final_solution = true,80solution_variables = cons2prim)81cfl = 1.082stepsize_callback = StepsizeCallback(cfl = cfl)8384glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)8586callbacks = CallbackSet(summary_callback,87analysis_callback,88alive_callback,89save_solution,90stepsize_callback,91glm_speed_callback)9293###############################################################################94# run the simulation9596sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);97dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback98ode_default_options()..., callback = callbacks);99100101