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_onion.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# Vertical magnetic streamlines with a bend in the center.
6
# This makes the streamlines look like a section of an onion.
7
8
# Define the initial condition as a vertical field with a bend in the center.
9
function initial_condition_onion(x, t, equations::IdealGlmMhdEquations2D)
10
rho = 1.0
11
v1 = 0.0
12
v2 = 0.0
13
v3 = 0.0
14
p = rho^equations.gamma
15
B1 = -2 * x[1] * x[2] * exp(-x[1]^2 - x[2]^2)
16
B2 = (2 * x[1]^2 - 1) * exp(-x[1]^2 - x[2]^2) + 1
17
B3 = 0.0
18
psi = 0.0
19
20
return prim2cons(SVector(rho, v1, v2, v3, p, B1, B2, B3, psi), equations)
21
end
22
23
gamma = 5 / 3
24
equations = IdealGlmMhdEquations2D(gamma)
25
26
initial_condition = initial_condition_onion
27
28
cells_per_dimension = (32, 32)
29
coordinates_min = (-3.0, -3.0)
30
coordinates_max = (3.0, 3.0)
31
mesh = StructuredMesh(cells_per_dimension,
32
coordinates_min,
33
coordinates_max,
34
periodicity = (false, false))
35
36
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
37
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
38
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
39
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
40
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
41
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
42
# `StepsizeCallback` (CFL-Condition) and less diffusion.
43
surface_flux = (FluxLaxFriedrichs(max_abs_speed_naive), flux_nonconservative_powell)
44
volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)
45
solver = DGSEM(polydeg = 3, surface_flux = surface_flux,
46
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
47
48
boundary_conditions = (x_neg = BoundaryConditionDirichlet(initial_condition),
49
x_pos = BoundaryConditionDirichlet(initial_condition),
50
y_neg = BoundaryConditionDirichlet(initial_condition),
51
y_pos = BoundaryConditionDirichlet(initial_condition))
52
53
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
54
boundary_conditions = boundary_conditions)
55
56
###############################################################################
57
# ODE solvers, callbacks etc.
58
59
tspan = (0.0, 0.1)
60
ode = semidiscretize(semi, tspan)
61
62
summary_callback = SummaryCallback()
63
64
analysis_interval = 100
65
66
analysis_callback = AnalysisCallback(semi, interval = 100)
67
68
alive_callback = AliveCallback(analysis_interval = analysis_interval)
69
70
save_solution = SaveSolutionCallback(interval = 50,
71
save_initial_solution = true,
72
save_final_solution = true,
73
solution_variables = cons2prim)
74
75
cfl = 1.0
76
77
stepsize_callback = StepsizeCallback(cfl = cfl)
78
79
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
80
81
callbacks = CallbackSet(summary_callback,
82
analysis_callback, 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 = 0.01, # solve needs some value here but it will be overwritten by the stepsize_callback
92
ode_default_options()..., callback = callbacks);
93
94