Path: blob/main/examples/tree_3d_dgsem/elixir_mhd_convergence.jl
5586 views
using Trixi1using OrdinaryDiffEqLowStorageRK23###############################################################################4# semidiscretization of the compressible ideal GLM-MHD equations56gamma() = 2.0 # required to make solution below working!7equations = IdealGlmMhdEquations3D(gamma())89"""10initial_condition_convergence(x, t, equations::IdealGlmMhdEquations3D)1112Manufactured solution for the 3D(only!) compressible ideal GLM-MHD equations.13Proposed in14- Marvin Bohm, Andrew R Winters, Gregor J Gassner, Dominik Derigs, Florian Hindenlang, Joachim Saur (2020):15An entropy stable nodal discontinuous Galerkin method for the resistive MHD equations.16Part I: Theory and numerical verification17[10.1016/j.jcp.2018.06.027](https://doi.org/10.1016/j.jcp.2018.06.027)18"""19@inline function initial_condition_convergence(x, t, equations::IdealGlmMhdEquations3D)20h = 0.5f0 * sinpi(2 * (x[1] + x[2] + x[3] - t)) + 22122u_1 = h23u_2 = h24u_3 = h25u_4 = 026u_5 = 2 * h^2 + h2728u_6 = h29u_7 = -h30u_8 = 031u_9 = 03233return SVector(u_1, u_2, u_3, u_4, u_5, u_6, u_7, u_8, u_9)34end3536"""37source_terms_convergence(x, t, equations::IdealGlmMhdEquations3D)3839Manufactured solution for the 3D(only!) compressible ideal GLM-MHD equations.40Proposed in41- Marvin Bohm, Andrew R Winters, Gregor J Gassner, Dominik Derigs, Florian Hindenlang, Joachim Saur (2020):42An entropy stable nodal discontinuous Galerkin method for the resistive MHD equations.43Part I: Theory and numerical verification44[10.1016/j.jcp.2018.06.027](https://doi.org/10.1016/j.jcp.2018.06.027)4546For the version without parabolic terms see the implementation in FLUXO:47https://github.com/project-fluxo/fluxo/blob/c7e0cc9b7fd4569dcab67bbb6e5a25c0a84859f1/src/equation/mhd/equation.f90#L1539-L155448"""49function source_terms_convergence(u, x, t, equations::IdealGlmMhdEquations3D)50h = 0.5f0 * sinpi(2 * (x[1] + x[2] + x[3] - t)) + 251h_x = pi * cospi(2 * (x[1] + x[2] + x[3] - t))5253s_1 = h_x54s_2 = h_x + 4 * h * h_x55s_3 = h_x + 4 * h * h_x56s_4 = 4 * h * h_x57s_5 = h_x + 12 * h * h_x58s_6 = h_x59s_7 = -h_x60s_8 = 061s_9 = 06263return SVector(s_1, s_2, s_3, s_4, s_5, s_6, s_7, s_8, s_9)64end6566surface_flux = (flux_hll, flux_nonconservative_powell)67volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)6869polydeg = 370basis = LobattoLegendreBasis(polydeg)7172volume_integral = VolumeIntegralFluxDifferencing(volume_flux)73solver = DGSEM(basis, surface_flux, volume_integral)7475coordinates_min = (0.0, 0.0, 0.0)76coordinates_max = (1.0, 1.0, 1.0)7778mesh = TreeMesh(coordinates_min, coordinates_max,79initial_refinement_level = 2,80periodicity = true,81n_cells_max = 100_000)8283semi = SemidiscretizationHyperbolic(mesh, equations,84initial_condition_convergence, solver;85source_terms = source_terms_convergence,86boundary_conditions = boundary_condition_periodic)8788###############################################################################89# ODE solvers, callbacks etc.9091tspan = (0.0, 1.0)92ode = semidiscretize(semi, tspan)9394summary_callback = SummaryCallback()9596analysis_interval = 5097analysis_callback = AnalysisCallback(semi, interval = analysis_interval)9899alive_callback = AliveCallback(analysis_interval = analysis_interval)100101cfl = 1.8102stepsize_callback = StepsizeCallback(cfl = cfl)103104glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)105106callbacks = CallbackSet(summary_callback,107analysis_callback,108alive_callback,109stepsize_callback,110glm_speed_callback)111112###############################################################################113# run the simulation114115sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);116dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback117ode_default_options()..., callback = callbacks);118119120