Path: blob/main/examples/structured_2d_dgsem/elixir_mhdmultiion_convergence_twospecies.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4"""5electron_pressure_alpha(u, equations::IdealGlmMhdMultiIonEquations2D)6Returns a fraction (alpha) of the total ion pressure for the electron pressure.7"""8function electron_pressure_alpha(u, equations::IdealGlmMhdMultiIonEquations2D)9alpha = 0.210prim = cons2prim(u, equations)11p_e = zero(u[1])12for k in eachcomponent(equations)13_, _, _, _, p_k = Trixi.get_component(k, prim, equations)14p_e += p_k15end16return alpha * p_e17end18# semidiscretization of the ideal multi-ion MHD equations19equations = IdealGlmMhdMultiIonEquations2D(gammas = (2.0, 4.0),20charge_to_mass = (2.0, 1.0),21electron_pressure = electron_pressure_alpha)2223"""24Initial (and exact) solution for the the manufactured solution test. Runs with25* gammas = (2.0, 4.0),26* charge_to_mass = (2.0, 1.0)27* Domain size: [-1,1]²28"""29function initial_condition_manufactured_solution(x, t,30equations::IdealGlmMhdMultiIonEquations2D)31am = 0.132om = π33h = am * sin(om * (x[1] + x[2] - t)) + 234hh1 = am * 0.4 * sin(om * (x[1] + x[2] - t)) + 135hh2 = h - hh13637u1 = hh138u2 = hh139u3 = hh140u4 = 0.1 * hh141u5 = 2 * hh1^2 + hh142u6 = hh243u7 = hh244u8 = hh245u9 = 0.1 * hh246u10 = 2 * hh2^2 + hh247u11 = 0.25 * h48u12 = -0.25 * h49u13 = 0.1 * h5051return SVector{nvariables(equations), real(equations)}(u11, u12, u13,52u1, u2, u3, u4, u5,53u6, u7, u8, u9, u10,540)55end5657"""58Source term that corresponds to the manufactured solution test. Runs with59* gammas = (2.0, 4.0),60* charge_to_mass = (2.0, 1.0)61* Domain size: [-1,1]²62"""63function source_terms_manufactured_solution_pe(u, x, t,64equations::IdealGlmMhdMultiIonEquations2D)65am = 0.166om = pi67h1 = am * sin(om * (x[1] + x[2] - t))68hx = am * om * cos(om * (x[1] + x[2] - t))6970s1 = (2 * hx) / 571s2 = (38055 * hx * h1^2 + 185541 * hx * h1 + 220190 * hx) / (35000 * h1 + 75000)72s3 = (38055 * hx * h1^2 + 185541 * hx * h1 + 220190 * hx) / (35000 * h1 + 75000)73s4 = hx / 2574s5 = (1835811702576186755 * hx * h1^2 + 8592627463681183181 * hx * h1 +759884050459977240490 * hx) / (652252660543767500 * h1 + 1397684272593787500)76s6 = (3 * hx) / 577s7 = (76155 * hx * h1^2 + 295306 * hx * h1 + 284435 * hx) / (17500 * h1 + 37500)78s8 = (76155 * hx * h1^2 + 295306 * hx * h1 + 284435 * hx) / (17500 * h1 + 37500)79s9 = (3 * hx) / 5080s10 = (88755 * hx * h1^2 + 338056 * hx * h1 + 318185 * hx) / (8750 * h1 + 18750)81s11 = hx / 482s12 = -hx / 483s13 = hx / 108485s = SVector{nvariables(equations), real(equations)}(s11, s12, s13,86s1, s2, s3, s4, s5,87s6, s7, s8, s9, s10,880)89S_std = source_terms_lorentz(u, x, t, equations::IdealGlmMhdMultiIonEquations2D)9091return SVector{nvariables(equations), real(equations)}(S_std .+ s)92end9394initial_condition = initial_condition_manufactured_solution95source_terms = source_terms_manufactured_solution_pe9697volume_flux = (flux_ruedaramirez_etal, flux_nonconservative_ruedaramirez_etal)98surface_flux = (FluxLaxFriedrichs(max_abs_speed_naive),99flux_nonconservative_central) # Also works with flux_nonconservative_ruedaramirez_etal100101solver = DGSEM(polydeg = 3, surface_flux = surface_flux,102volume_integral = VolumeIntegralFluxDifferencing(volume_flux))103104coordinates_min = (-1.0, -1.0)105coordinates_max = (1.0, 1.0)106107# To test convergence use:108# convergence_test("../examples/structured_2d_dgsem/elixir_mhdmultiion_convergence_twospecies.jl", 3, cells_per_dimension = (2, 2), polydeg = 3)109# Mapping as described in https://arxiv.org/abs/2012.12040110function mapping(xi_, eta_)111# Transform input variables between -1 and 1 onto [0,3]112xi = 1.5 * xi_ + 1.5113eta = 1.5 * eta_ + 1.5114115y = eta +1160.05 * (cospi(1.5 * (2 * xi - 3) / 3) *117cospi(0.5 * (2 * eta - 3) / 3))118119x = xi +1200.05 * (cospi(0.5 * (2 * xi - 3) / 3) *121cospi(2 * (2 * y - 3) / 3))122123# Go back to [-1,1]^3124x = x * 2 / 3 - 1125y = y * 2 / 3 - 1126127return SVector(x, y)128end129cells_per_dimension = (2, 2)130mesh = StructuredMesh(cells_per_dimension, mapping;131periodicity = true)132133# # Alternatively, you can test with a TreeMesh134# # convergence_test("../examples/structured_2d_dgsem/elixir_mhdmultiion_convergence_twospecies.jl", 3, initial_refinement_level = 1, polydeg = 3)135# initial_refinement_level = 1136# mesh = TreeMesh(coordinates_min, coordinates_max,137# initial_refinement_level = initial_refinement_level,138# n_cells_max = 1_000_000,139# periodicity = true)140141semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,142source_terms = source_terms,143boundary_conditions = boundary_condition_periodic)144145###############################################################################146# ODE solvers, callbacks etc.147148tspan = (0.0, 1.0)149ode = semidiscretize(semi, tspan)150151summary_callback = SummaryCallback()152153analysis_interval = 100154analysis_callback = AnalysisCallback(semi, interval = analysis_interval)155alive_callback = AliveCallback(analysis_interval = analysis_interval)156157save_solution = SaveSolutionCallback(interval = 1000,158save_initial_solution = true,159save_final_solution = true,160solution_variables = cons2prim)161162cfl = 0.5163stepsize_callback = StepsizeCallback(cfl = cfl)164165glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)166167callbacks = CallbackSet(summary_callback,168analysis_callback, alive_callback,169save_solution,170stepsize_callback,171glm_speed_callback)172173###############################################################################174# run the simulation175176sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),177dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback178save_everystep = false, callback = callbacks);179180181