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