Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/p4est_3d_dgsem/elixir_mhdmultiion_ec.jl
5586 views
1
2
using OrdinaryDiffEqLowStorageRK
3
using Trixi
4
5
###############################################################################
6
# Compute non-trivial electron pressure as 0.2 * total_pressure
7
function electron_pressure(u, equations::IdealGlmMhdMultiIonEquations3D)
8
prim = cons2prim(u, equations)
9
pe = zero(eltype(u))
10
for k in eachcomponent(equations)
11
rho, v1, v2, v3, p = get_component(k, prim, equations)
12
pe += 0.2 * p
13
end
14
return zero(u[1])
15
end
16
17
# semidiscretization of the ideal GLM-MHD multi-ion equations
18
equations = IdealGlmMhdMultiIonEquations3D(gammas = (1.4, 1.667),
19
charge_to_mass = (1.0, 2.0))
20
21
initial_condition = initial_condition_weak_blast_wave
22
23
volume_flux = (flux_ruedaramirez_etal, flux_nonconservative_ruedaramirez_etal)
24
surface_flux = (flux_ruedaramirez_etal, flux_nonconservative_ruedaramirez_etal)
25
# For provably entropy-stable surface fluxes, use
26
# surface_flux = (FluxPlusDissipation(flux_ruedaramirez_etal, DissipationLaxFriedrichsEntropyVariables()),
27
# flux_nonconservative_ruedaramirez_etal)
28
solver = DGSEM(polydeg = 3, surface_flux = surface_flux,
29
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
30
31
# Mapping as described in https://arxiv.org/abs/2012.12040
32
function mapping(xi_, eta_, zeta_)
33
# Transform input variables between -1 and 1 onto [0,3]
34
xi = 1.5 * xi_ + 1.5
35
eta = 1.5 * eta_ + 1.5
36
zeta = 1.5 * zeta_ + 1.5
37
38
y = eta +
39
3 / 8 * (cos(1.5 * pi * (2 * xi - 3) / 3) *
40
cos(0.5 * pi * (2 * eta - 3) / 3) *
41
cos(0.5 * pi * (2 * zeta - 3) / 3))
42
43
x = xi +
44
3 / 8 * (cos(0.5 * pi * (2 * xi - 3) / 3) *
45
cos(2 * pi * (2 * y - 3) / 3) *
46
cos(0.5 * pi * (2 * zeta - 3) / 3))
47
48
z = zeta +
49
3 / 8 * (cos(0.5 * pi * (2 * x - 3) / 3) *
50
cos(pi * (2 * y - 3) / 3) *
51
cos(0.5 * pi * (2 * zeta - 3) / 3))
52
53
return SVector(x, y, z)
54
end
55
56
trees_per_dimension = (8, 8, 8)
57
mesh = P4estMesh(trees_per_dimension,
58
polydeg = 3, mapping = mapping,
59
periodicity = true)
60
61
# The multi-ion GLM-MHD equations require the inclusion of source_terms_lorentz
62
# whenever multiple ion species are present
63
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
64
source_terms = source_terms_lorentz,
65
boundary_conditions = boundary_condition_periodic)
66
67
###############################################################################
68
# ODE solvers, callbacks etc.
69
70
tspan = (0.0, 0.4)
71
ode = semidiscretize(semi, tspan)
72
73
summary_callback = SummaryCallback()
74
75
analysis_interval = 10
76
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
77
alive_callback = AliveCallback(analysis_interval = analysis_interval)
78
79
save_solution = SaveSolutionCallback(dt = 0.1,
80
save_initial_solution = true,
81
save_final_solution = true,
82
solution_variables = cons2prim)
83
84
cfl = 0.5
85
86
stepsize_callback = StepsizeCallback(cfl = cfl)
87
88
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
89
90
callbacks = CallbackSet(summary_callback,
91
analysis_callback, alive_callback,
92
save_solution,
93
stepsize_callback,
94
glm_speed_callback)
95
96
###############################################################################
97
# run the simulation
98
99
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
100
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
101
ode_default_options()..., callback = callbacks);
102
103