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_ec.jl
5586 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the compressible ideal GLM-MHD equations
6
7
equations = IdealGlmMhdEquations2D(1.4)
8
9
function initial_condition_shifted_weak_blast_wave(x, t, equations::IdealGlmMhdEquations2D)
10
# Adapted MHD version of the weak blast wave from Hennemann & Gassner JCP paper 2020 (Sec. 6.3)
11
# Same discontinuity in the velocities but with magnetic fields
12
# Set up polar coordinates
13
inicenter = (1.5, 1.5)
14
x_norm = x[1] - inicenter[1]
15
y_norm = x[2] - inicenter[2]
16
r = sqrt(x_norm^2 + y_norm^2)
17
phi = atan(y_norm, x_norm)
18
19
# Calculate primitive variables
20
rho = r > 0.5 ? 1.0 : 1.1691
21
v1 = r > 0.5 ? 0.0 : 0.1882 * cos(phi)
22
v2 = r > 0.5 ? 0.0 : 0.1882 * sin(phi)
23
p = r > 0.5 ? 1.0 : 1.245
24
25
return prim2cons(SVector(rho, v1, v2, 0.0, p, 1.0, 1.0, 1.0, 0.0), equations)
26
end
27
28
initial_condition = initial_condition_shifted_weak_blast_wave
29
30
# Get the DG approximation space
31
volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)
32
solver = DGSEM(polydeg = 5,
33
surface_flux = (flux_hindenlang_gassner, flux_nonconservative_powell),
34
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
35
36
# Get the curved quad mesh from a mapping function
37
# Mapping as described in https://arxiv.org/abs/2012.12040, but reduced to 2D
38
function mapping(xi_, eta_)
39
# Transform input variables between -1 and 1 onto [0,3]
40
xi = 1.5 * xi_ + 1.5
41
eta = 1.5 * eta_ + 1.5
42
43
y = eta + 3 / 8 * (cos(1.5 * pi * (2 * xi - 3) / 3) *
44
cos(0.5 * pi * (2 * eta - 3) / 3))
45
46
x = xi + 3 / 8 * (cos(0.5 * pi * (2 * xi - 3) / 3) *
47
cos(2 * pi * (2 * y - 3) / 3))
48
49
return SVector(x, y)
50
end
51
52
# Create curved mesh with 8 x 8 elements
53
cells_per_dimension = (8, 8)
54
mesh = StructuredMesh(cells_per_dimension, mapping, periodicity = true)
55
56
# create the semi discretization object
57
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
58
boundary_conditions = boundary_condition_periodic)
59
60
###############################################################################
61
# ODE solvers, callbacks etc.
62
63
tspan = (0.0, 2.0)
64
ode = semidiscretize(semi, tspan)
65
66
summary_callback = SummaryCallback()
67
68
analysis_interval = 100
69
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
70
save_analysis = false,
71
extra_analysis_integrals = (entropy, energy_total,
72
energy_kinetic,
73
energy_internal,
74
energy_magnetic,
75
cross_helicity))
76
77
alive_callback = AliveCallback(analysis_interval = analysis_interval)
78
79
save_solution = SaveSolutionCallback(interval = 100,
80
save_initial_solution = true,
81
save_final_solution = true,
82
solution_variables = cons2prim)
83
cfl = 1.0
84
stepsize_callback = StepsizeCallback(cfl = cfl)
85
86
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
87
88
callbacks = CallbackSet(summary_callback,
89
analysis_callback,
90
alive_callback,
91
save_solution,
92
stepsize_callback,
93
glm_speed_callback)
94
95
###############################################################################
96
# run the simulation
97
98
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
99
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
100
ode_default_options()..., callback = callbacks);
101
102