Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/t8code_3d_dgsem/elixir_euler_ec.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the compressible Euler equations
6
7
equations = CompressibleEulerEquations3D(5 / 3)
8
9
initial_condition = initial_condition_weak_blast_wave
10
11
boundary_conditions = Dict(:all => boundary_condition_slip_wall)
12
13
# Get the DG approximation space
14
15
volume_flux = flux_ranocha
16
solver = DGSEM(polydeg = 5, surface_flux = flux_ranocha,
17
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
18
19
# Get the curved quad mesh from a file
20
21
# Mapping as described in https://arxiv.org/abs/2012.12040
22
function mapping(xi_, eta_, zeta_)
23
# Transform input variables between -1 and 1 onto [0,3]
24
xi = 1.5 * xi_ + 1.5
25
eta = 1.5 * eta_ + 1.5
26
zeta = 1.5 * zeta_ + 1.5
27
28
y = eta +
29
3 / 8 * (cos(1.5 * pi * (2 * xi - 3) / 3) *
30
cos(0.5 * pi * (2 * eta - 3) / 3) *
31
cos(0.5 * pi * (2 * zeta - 3) / 3))
32
33
x = xi +
34
3 / 8 * (cos(0.5 * pi * (2 * xi - 3) / 3) *
35
cos(2 * pi * (2 * y - 3) / 3) *
36
cos(0.5 * pi * (2 * zeta - 3) / 3))
37
38
z = zeta +
39
3 / 8 * (cos(0.5 * pi * (2 * x - 3) / 3) *
40
cos(pi * (2 * y - 3) / 3) *
41
cos(0.5 * pi * (2 * zeta - 3) / 3))
42
43
return SVector(x, y, z)
44
end
45
46
# Unstructured mesh with 48 cells of the cube domain [-1, 1]^3
47
mesh_file = Trixi.download("https://gist.githubusercontent.com/efaulhaber/b8df0033798e4926dec515fc045e8c2c/raw/b9254cde1d1fb64b6acc8416bc5ccdd77a240227/cube_unstructured_2.inp",
48
joinpath(@__DIR__, "cube_unstructured_2.inp"))
49
50
mesh = T8codeMesh(mesh_file, 3; polydeg = 5,
51
mapping = mapping,
52
initial_refinement_level = 0)
53
54
# Create the semidiscretization object.
55
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
56
boundary_conditions = boundary_conditions)
57
58
###############################################################################
59
# ODE solvers, callbacks etc.
60
61
tspan = (0.0, 2.0)
62
ode = semidiscretize(semi, tspan)
63
64
summary_callback = SummaryCallback()
65
66
analysis_interval = 100
67
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
68
69
alive_callback = AliveCallback(analysis_interval = analysis_interval)
70
71
# Add `:thermodynamic_entropy` to `extra_node_variables` tuple ...
72
extra_node_variables = (:thermodynamic_entropy,)
73
74
# ... and specify the function `get_node_variable` for this symbol,
75
# with first argument matching the symbol (turned into a type via `Val`) for dispatching.
76
function Trixi.get_node_variable(::Val{:thermodynamic_entropy}, u, mesh, equations,
77
dg, cache)
78
n_nodes = nnodes(dg)
79
n_elements = nelements(dg, cache)
80
# By definition, the variable must be provided at every node of every element!
81
# Otherwise, the `SaveSolutionCallback` will crash.
82
entropy_array = zeros(eltype(cache.elements),
83
ntuple(_ -> n_nodes, ndims(mesh))..., # equivalent: `n_nodes, n_nodes, n_nodes`
84
n_elements)
85
86
# We can accelerate the computation by thread-parallelizing the loop over elements
87
# by using the `@threaded` macro.
88
Trixi.@threaded for element in eachelement(dg, cache)
89
for k in eachnode(dg), j in eachnode(dg), i in eachnode(dg)
90
u_node = get_node_vars(u, equations, dg, i, j, k, element)
91
92
entropy_array[i, j, k, element] = Trixi.entropy_thermodynamic(u_node, equations)
93
end
94
end
95
96
return entropy_array
97
end
98
save_solution = SaveSolutionCallback(interval = 100,
99
save_initial_solution = true,
100
save_final_solution = true,
101
extra_node_variables = extra_node_variables) # Supply the additional `extra_node_variables` here
102
103
stepsize_callback = StepsizeCallback(cfl = 1.0)
104
105
callbacks = CallbackSet(summary_callback,
106
analysis_callback,
107
alive_callback,
108
save_solution,
109
stepsize_callback)
110
111
###############################################################################
112
# run the simulation
113
114
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
115
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
116
ode_default_options()..., callback = callbacks);
117
118