Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/structured_2d_dgsem/elixir_mhd_alfven_wave.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the compressible ideal GLM-MHD equations
6
7
gamma = 5 / 3
8
equations = IdealGlmMhdEquations2D(gamma)
9
10
initial_condition = initial_condition_convergence_test
11
12
# Get the DG approximation space
13
14
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
15
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
16
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
17
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
18
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
19
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
20
# `StepsizeCallback` (CFL-Condition) and less diffusion.
21
surface_flux = (FluxLaxFriedrichs(max_abs_speed_naive), flux_nonconservative_powell)
22
volume_flux = (flux_central, flux_nonconservative_powell)
23
solver = DGSEM(polydeg = 3, surface_flux = surface_flux,
24
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
25
26
# Get the curved quad mesh from a mapping function
27
# Mapping as described in https://arxiv.org/abs/1809.01178
28
function mapping(xi_, eta_)
29
# Transform input variables between -1 and 1 onto [0, sqrt(2)]
30
# Note, we use the domain [0, sqrt(2)]^2 for the Alfvén wave convergence test case
31
xi = 0.5 * sqrt(2) * xi_ + 0.5 * sqrt(2)
32
eta = 0.5 * sqrt(2) * eta_ + 0.5 * sqrt(2)
33
34
y = eta +
35
sqrt(2) / 12 * (cos(1.5 * pi * (2 * xi - sqrt(2)) / sqrt(2)) *
36
cos(0.5 * pi * (2 * eta - sqrt(2)) / sqrt(2)))
37
38
x = xi +
39
sqrt(2) / 12 * (cos(0.5 * pi * (2 * xi - sqrt(2)) / sqrt(2)) *
40
cos(2 * pi * (2 * y - sqrt(2)) / sqrt(2)))
41
42
return SVector(x, y)
43
end
44
45
cells_per_dimension = (4, 4)
46
mesh = StructuredMesh(cells_per_dimension, mapping)
47
48
# create the semi discretization object
49
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
50
51
###############################################################################
52
# ODE solvers, callbacks etc.
53
54
tspan = (0.0, 2.0)
55
ode = semidiscretize(semi, tspan)
56
57
summary_callback = SummaryCallback()
58
59
analysis_interval = 100
60
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
61
save_analysis = false,
62
extra_analysis_integrals = (entropy, energy_total,
63
energy_kinetic,
64
energy_internal,
65
energy_magnetic,
66
cross_helicity))
67
68
alive_callback = AliveCallback(analysis_interval = analysis_interval)
69
70
save_solution = SaveSolutionCallback(interval = 100,
71
save_initial_solution = true,
72
save_final_solution = true,
73
solution_variables = cons2prim)
74
cfl = 2.0
75
stepsize_callback = StepsizeCallback(cfl = cfl)
76
77
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
78
79
callbacks = CallbackSet(summary_callback,
80
analysis_callback,
81
alive_callback,
82
save_solution,
83
stepsize_callback,
84
glm_speed_callback)
85
86
###############################################################################
87
# run the simulation
88
89
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
90
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
91
ode_default_options()..., callback = callbacks);
92
93