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
5586 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
boundary_conditions = boundary_condition_periodic)
44
45
###############################################################################
46
# ODE solvers, callbacks etc.
47
48
tspan = (0.0, 2.0)
49
ode = semidiscretize(semi, tspan)
50
51
summary_callback = SummaryCallback()
52
53
analysis_interval = 100
54
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
55
save_analysis = false,
56
extra_analysis_integrals = (entropy, energy_total,
57
energy_kinetic,
58
energy_internal,
59
energy_magnetic,
60
cross_helicity))
61
62
alive_callback = AliveCallback(analysis_interval = analysis_interval)
63
64
save_solution = SaveSolutionCallback(interval = 100,
65
save_initial_solution = true,
66
save_final_solution = true,
67
solution_variables = cons2prim)
68
cfl = 1.0
69
stepsize_callback = StepsizeCallback(cfl = cfl)
70
71
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
72
73
callbacks = CallbackSet(summary_callback,
74
analysis_callback,
75
alive_callback,
76
save_solution,
77
stepsize_callback,
78
glm_speed_callback)
79
80
###############################################################################
81
# run the simulation
82
83
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
84
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
85
ode_default_options()..., callback = callbacks);
86
87