Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/unstructured_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
# Get the unstructured quad mesh from a file (downloads the file if not available locally)
29
mesh_file = Trixi.download("https://gist.githubusercontent.com/patrickersing/8fe7e61bf1e79eeafa031ec2e355803d/raw/7b26d86f15a419152a505934ae742457826d99b5/mesh_mhd_onion.mesh",
30
joinpath(@__DIR__, "mesh_mhd_onion.mesh"))
31
mesh = UnstructuredMesh2D(mesh_file, periodicity = false)
32
33
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
34
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
35
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
36
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
37
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
38
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
39
# `StepsizeCallback` (CFL-Condition) and less diffusion.
40
surface_flux = (FluxLaxFriedrichs(max_abs_speed_naive), flux_nonconservative_powell)
41
volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)
42
solver = DGSEM(polydeg = 3, surface_flux = surface_flux,
43
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
44
45
boundary_conditions = Dict(:Bottom => BoundaryConditionDirichlet(initial_condition),
46
:Top => BoundaryConditionDirichlet(initial_condition),
47
:Right => BoundaryConditionDirichlet(initial_condition),
48
:Left => BoundaryConditionDirichlet(initial_condition))
49
50
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
51
boundary_conditions = boundary_conditions)
52
53
###############################################################################
54
# ODE solvers, callbacks etc.
55
56
tspan = (0.0, 0.1)
57
ode = semidiscretize(semi, tspan)
58
59
summary_callback = SummaryCallback()
60
61
analysis_interval = 100
62
63
analysis_callback = AnalysisCallback(semi, interval = 100)
64
65
alive_callback = AliveCallback(analysis_interval = analysis_interval)
66
67
save_solution = SaveSolutionCallback(interval = 50,
68
save_initial_solution = true,
69
save_final_solution = true,
70
solution_variables = cons2prim)
71
72
cfl = 1.0
73
74
stepsize_callback = StepsizeCallback(cfl = cfl)
75
76
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
77
78
callbacks = CallbackSet(summary_callback,
79
analysis_callback, alive_callback,
80
save_solution,
81
stepsize_callback,
82
glm_speed_callback)
83
84
###############################################################################
85
# run the simulation
86
87
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
88
dt = 0.01, # solve needs some value here but it will be overwritten by the stepsize_callback
89
ode_default_options()..., callback = callbacks);
90
91