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
2802 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, periodicity = true)
47
48
# create the semi discretization object
49
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
50
boundary_conditions = boundary_condition_periodic)
51
52
###############################################################################
53
# ODE solvers, callbacks etc.
54
55
tspan = (0.0, 2.0)
56
ode = semidiscretize(semi, tspan)
57
58
summary_callback = SummaryCallback()
59
60
analysis_interval = 100
61
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
62
save_analysis = false,
63
extra_analysis_integrals = (entropy, energy_total,
64
energy_kinetic,
65
energy_internal,
66
energy_magnetic,
67
cross_helicity))
68
69
alive_callback = AliveCallback(analysis_interval = analysis_interval)
70
71
save_solution = SaveSolutionCallback(interval = 100,
72
save_initial_solution = true,
73
save_final_solution = true,
74
solution_variables = cons2prim)
75
cfl = 2.0
76
stepsize_callback = StepsizeCallback(cfl = cfl)
77
78
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
79
80
callbacks = CallbackSet(summary_callback,
81
analysis_callback,
82
alive_callback,
83
save_solution,
84
stepsize_callback,
85
glm_speed_callback)
86
87
###############################################################################
88
# run the simulation
89
90
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
91
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
92
ode_default_options()..., callback = callbacks);
93
94