Path: blob/main/examples/structured_2d_dgsem/elixir_mhd_ec.jl
5586 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, periodicity = true)5455# create the semi discretization object56semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;57boundary_conditions = boundary_condition_periodic)5859###############################################################################60# ODE solvers, callbacks etc.6162tspan = (0.0, 2.0)63ode = semidiscretize(semi, tspan)6465summary_callback = SummaryCallback()6667analysis_interval = 10068analysis_callback = AnalysisCallback(semi, interval = analysis_interval,69save_analysis = false,70extra_analysis_integrals = (entropy, energy_total,71energy_kinetic,72energy_internal,73energy_magnetic,74cross_helicity))7576alive_callback = AliveCallback(analysis_interval = analysis_interval)7778save_solution = SaveSolutionCallback(interval = 100,79save_initial_solution = true,80save_final_solution = true,81solution_variables = cons2prim)82cfl = 1.083stepsize_callback = StepsizeCallback(cfl = cfl)8485glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)8687callbacks = CallbackSet(summary_callback,88analysis_callback,89alive_callback,90save_solution,91stepsize_callback,92glm_speed_callback)9394###############################################################################95# run the simulation9697sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);98dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback99ode_default_options()..., callback = callbacks);100101102