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_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(5 / 3)
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
# Shift blastwave to center of domain
12
inicenter = (sqrt(2) / 2, sqrt(2) / 2)
13
x_norm = x[1] - inicenter[1]
14
y_norm = x[2] - inicenter[2]
15
r = sqrt(x_norm^2 + y_norm^2)
16
phi = atan(y_norm, x_norm)
17
18
# Calculate primitive variables
19
rho = r > 0.5 ? 1.0 : 1.1691
20
v1 = r > 0.5 ? 0.0 : 0.1882 * cos(phi)
21
v2 = r > 0.5 ? 0.0 : 0.1882 * sin(phi)
22
p = r > 0.5 ? 1.0 : 1.245
23
24
return prim2cons(SVector(rho, v1, v2, 0.0, p, 1.0, 1.0, 1.0, 0.0), equations)
25
end
26
27
initial_condition = initial_condition_shifted_weak_blast_wave
28
29
# Get the DG approximation space
30
volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)
31
solver = DGSEM(polydeg = 6,
32
surface_flux = (flux_hindenlang_gassner, flux_nonconservative_powell),
33
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
34
35
# Get the unstructured quad mesh from a file (downloads the file if not available locally)
36
mesh_file = Trixi.download("https://gist.githubusercontent.com/andrewwinters5000/8f8cd23df27fcd494553f2a89f3c1ba4/raw/85e3c8d976bbe57ca3d559d653087b0889535295/mesh_alfven_wave_with_twist_and_flip.mesh",
37
joinpath(@__DIR__, "mesh_alfven_wave_with_twist_and_flip.mesh"))
38
39
mesh = UnstructuredMesh2D(mesh_file, periodicity = true)
40
41
# create the semi discretization object
42
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
43
44
###############################################################################
45
# ODE solvers, callbacks etc.
46
47
tspan = (0.0, 2.0)
48
ode = semidiscretize(semi, tspan)
49
50
summary_callback = SummaryCallback()
51
52
analysis_interval = 100
53
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
54
save_analysis = false,
55
extra_analysis_integrals = (entropy, energy_total,
56
energy_kinetic,
57
energy_internal,
58
energy_magnetic,
59
cross_helicity))
60
61
alive_callback = AliveCallback(analysis_interval = analysis_interval)
62
63
save_solution = SaveSolutionCallback(interval = 100,
64
save_initial_solution = true,
65
save_final_solution = true,
66
solution_variables = cons2prim)
67
cfl = 1.0
68
stepsize_callback = StepsizeCallback(cfl = cfl)
69
70
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
71
72
callbacks = CallbackSet(summary_callback,
73
analysis_callback,
74
alive_callback,
75
save_solution,
76
stepsize_callback,
77
glm_speed_callback)
78
79
###############################################################################
80
# run the simulation
81
82
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
83
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
84
ode_default_options()..., callback = callbacks);
85
86