|
| 1 | +using OrdinaryDiffEq |
| 2 | +using Trixi |
| 3 | + |
| 4 | +############################################################################### |
| 5 | +# semidiscretization of the compressible ideal GLM-MHD equations |
| 6 | +equations = IdealGlmMhdEquations2D(1.4) |
| 7 | + |
| 8 | +""" |
| 9 | + initial_condition_rotor(x, t, equations::IdealGlmMhdEquations2D) |
| 10 | +
|
| 11 | +The classical MHD rotor test case. Here, the setup is taken from |
| 12 | +- Dominik Derigs, Gregor J. Gassner, Stefanie Walch & Andrew R. Winters (2018) |
| 13 | + Entropy Stable Finite Volume Approximations for Ideal Magnetohydrodynamics |
| 14 | + [doi: 10.1365/s13291-018-0178-9](https://doi.org/10.1365/s13291-018-0178-9) |
| 15 | +""" |
| 16 | +function initial_condition_rotor(x, t, equations::IdealGlmMhdEquations2D) |
| 17 | + # setup taken from Derigs et al. DMV article (2018) |
| 18 | + # domain must be [0, 1] x [0, 1], γ = 1.4 |
| 19 | + dx = x[1] - 0.5 |
| 20 | + dy = x[2] - 0.5 |
| 21 | + r = sqrt(dx^2 + dy^2) |
| 22 | + f = (0.115 - r) / 0.015 |
| 23 | + if r <= 0.1 |
| 24 | + rho = 10.0 |
| 25 | + v1 = -20.0 * dy |
| 26 | + v2 = 20.0 * dx |
| 27 | + elseif r >= 0.115 |
| 28 | + rho = 1.0 |
| 29 | + v1 = 0.0 |
| 30 | + v2 = 0.0 |
| 31 | + else |
| 32 | + rho = 1.0 + 9.0 * f |
| 33 | + v1 = -20.0 * f * dy |
| 34 | + v2 = 20.0 * f * dx |
| 35 | + end |
| 36 | + v3 = 0.0 |
| 37 | + p = 1.0 |
| 38 | + B1 = 5.0 / sqrt(4.0 * pi) |
| 39 | + B2 = 0.0 |
| 40 | + B3 = 0.0 |
| 41 | + psi = 0.0 |
| 42 | + return prim2cons(SVector(rho, v1, v2, v3, p, B1, B2, B3, psi), equations) |
| 43 | +end |
| 44 | +initial_condition = initial_condition_rotor |
| 45 | + |
| 46 | +surface_flux = (flux_lax_friedrichs, flux_nonconservative_powell) |
| 47 | +volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell) |
| 48 | +polydeg = 4 |
| 49 | +basis = LobattoLegendreBasis(polydeg) |
| 50 | +indicator_sc = IndicatorHennemannGassner(equations, basis, |
| 51 | + alpha_max = 0.5, |
| 52 | + alpha_min = 0.001, |
| 53 | + alpha_smooth = true, |
| 54 | + variable = density_pressure) |
| 55 | +volume_integral = VolumeIntegralShockCapturingHG(indicator_sc; |
| 56 | + volume_flux_dg = volume_flux, |
| 57 | + volume_flux_fv = surface_flux) |
| 58 | +solver = DGSEM(basis, surface_flux, volume_integral) |
| 59 | + |
| 60 | +# Affine type mapping to take the [-1,1]^2 domain from the mesh file |
| 61 | +# and put it onto the rotor domain [0,1]^2 and then warp it with a mapping |
| 62 | +# as described in https://arxiv.org/abs/2012.12040 |
| 63 | +function mapping_twist(xi, eta) |
| 64 | + y = 0.5 * (eta + 1.0) + |
| 65 | + 0.05 * cos(1.5 * pi * (2.0 * xi - 1.0)) * cos(0.5 * pi * (2.0 * eta - 1.0)) |
| 66 | + x = 0.5 * (xi + 1.0) + 0.05 * cos(0.5 * pi * (2.0 * xi - 1.0)) * cos(2.0 * pi * y) |
| 67 | + return SVector(x, y) |
| 68 | +end |
| 69 | + |
| 70 | +mesh_file = Trixi.download("https://gist.githubusercontent.com/efaulhaber/63ff2ea224409e55ee8423b3a33e316a/raw/7db58af7446d1479753ae718930741c47a3b79b7/square_unstructured_2.inp", |
| 71 | + joinpath(@__DIR__, "square_unstructured_2.inp")) |
| 72 | + |
| 73 | +mesh = P4estMesh{2}(mesh_file, |
| 74 | + polydeg = 4, |
| 75 | + mapping = mapping_twist, |
| 76 | + initial_refinement_level = 1) |
| 77 | + |
| 78 | +boundary_condition = BoundaryConditionDirichlet(initial_condition) |
| 79 | +boundary_conditions = Dict(:all => boundary_condition) |
| 80 | + |
| 81 | +semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, |
| 82 | + boundary_conditions = boundary_conditions) |
| 83 | + |
| 84 | +############################################################################### |
| 85 | +# ODE solvers, callbacks etc. |
| 86 | + |
| 87 | +tspan = (0.0, 0.15) |
| 88 | +ode = semidiscretize(semi, tspan) |
| 89 | + |
| 90 | +summary_callback = SummaryCallback() |
| 91 | + |
| 92 | +analysis_interval = 100 |
| 93 | +analysis_callback = AnalysisCallback(semi, interval = analysis_interval) |
| 94 | + |
| 95 | +alive_callback = AliveCallback(analysis_interval = analysis_interval) |
| 96 | + |
| 97 | +save_solution = SaveSolutionCallback(interval = 100, |
| 98 | + save_initial_solution = true, |
| 99 | + save_final_solution = true, |
| 100 | + solution_variables = cons2prim) |
| 101 | + |
| 102 | +amr_indicator = IndicatorLöhner(semi, |
| 103 | + variable = density_pressure) |
| 104 | + |
| 105 | +amr_controller = ControllerThreeLevel(semi, amr_indicator, |
| 106 | + base_level = 1, |
| 107 | + med_level = 3, med_threshold = 0.05, |
| 108 | + max_level = 5, max_threshold = 0.1) |
| 109 | +amr_callback = AMRCallback(semi, amr_controller, |
| 110 | + interval = 3, |
| 111 | + adapt_initial_condition = true, |
| 112 | + adapt_initial_condition_only_refine = true) |
| 113 | + |
| 114 | +# increase the CFL number linearly from cfl_0() at time 0 |
| 115 | +# to cfl_t_ramp() at time t = t_ramp(), keep it constant afterward |
| 116 | +cfl_0() = 0.5 |
| 117 | +cfl_t_ramp() = 1.2 |
| 118 | +t_ramp() = 0.1 |
| 119 | +cfl(t) = min(cfl_0() + (cfl_t_ramp() - cfl_0()) / t_ramp() * t, cfl_t_ramp()) |
| 120 | + |
| 121 | +stepsize_callback = StepsizeCallback(cfl = cfl) |
| 122 | + |
| 123 | +glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl) |
| 124 | + |
| 125 | +callbacks = CallbackSet(summary_callback, |
| 126 | + analysis_callback, |
| 127 | + alive_callback, |
| 128 | + save_solution, |
| 129 | + amr_callback, |
| 130 | + stepsize_callback, |
| 131 | + glm_speed_callback) |
| 132 | + |
| 133 | +############################################################################### |
| 134 | +# run the simulation |
| 135 | + |
| 136 | +sol = solve(ode, |
| 137 | + CarpenterKennedy2N54(thread = OrdinaryDiffEq.True(), |
| 138 | + williamson_condition = false), |
| 139 | + dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback |
| 140 | + save_everystep = false, callback = callbacks); |
| 141 | +summary_callback() # print the timer summary |
0 commit comments