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_free_stream.jl
5585 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the compressible Euler equations
6
7
equations = CompressibleEulerEquations3D(1.4)
8
9
initial_condition = initial_condition_constant
10
11
boundary_conditions = (; all = BoundaryConditionDirichlet(initial_condition))
12
13
# Solver with polydeg=4 to ensure free stream preservation (FSP) on non-conforming meshes.
14
# The polydeg of the solver must be at least twice as big as the polydeg of the mesh.
15
# See https://doi.org/10.1007/s10915-018-00897-9, Section 6.
16
17
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
18
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
19
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
20
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
21
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
22
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
23
# `StepsizeCallback` (CFL-Condition) and less diffusion.
24
solver = DGSEM(polydeg = 4, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive),
25
volume_integral = VolumeIntegralWeakForm())
26
27
# Mapping as described in https://arxiv.org/abs/2012.12040 but with less warping.
28
# The mapping will be interpolated at tree level, and then refined without changing
29
# the geometry interpolant. This can yield problematic geometries if the unrefined mesh
30
# is not fine enough.
31
function mapping(xi_, eta_, zeta_)
32
# Transform input variables between -1 and 1 onto [0,3]
33
xi = 1.5 * xi_ + 1.5
34
eta = 1.5 * eta_ + 1.5
35
zeta = 1.5 * zeta_ + 1.5
36
37
y = eta +
38
1 / 6 * (cos(1.5 * pi * (2 * xi - 3) / 3) *
39
cos(0.5 * pi * (2 * eta - 3) / 3) *
40
cos(0.5 * pi * (2 * zeta - 3) / 3))
41
42
x = xi +
43
1 / 6 * (cos(0.5 * pi * (2 * xi - 3) / 3) *
44
cos(2 * pi * (2 * y - 3) / 3) *
45
cos(0.5 * pi * (2 * zeta - 3) / 3))
46
47
z = zeta +
48
1 / 6 * (cos(0.5 * pi * (2 * x - 3) / 3) *
49
cos(pi * (2 * y - 3) / 3) *
50
cos(0.5 * pi * (2 * zeta - 3) / 3))
51
52
return SVector(x, y, z)
53
end
54
55
# Unstructured mesh with 68 cells of the cube domain [-1, 1]^3
56
mesh_file = Trixi.download("https://gist.githubusercontent.com/efaulhaber/d45c8ac1e248618885fa7cc31a50ab40/raw/37fba24890ab37cfa49c39eae98b44faf4502882/cube_unstructured_1.inp",
57
joinpath(@__DIR__, "cube_unstructured_1.inp"))
58
59
mesh = T8codeMesh(mesh_file, 3; polydeg = 2,
60
mapping = mapping)
61
62
# Note: This is actually a `p8est_quadrant_t` which is much bigger than the
63
# following struct. But we only need the first four fields for our purpose.
64
struct t8_dhex_t
65
x::Int32
66
y::Int32
67
z::Int32
68
level::Int8
69
# [...] # See `p8est.h` in `p4est` for more info.
70
end
71
72
# Refine bottom left quadrant of each second tree to level 2
73
function adapt_callback(forest, ltreeid, eclass_scheme, lelemntid, elements, is_family,
74
user_data)
75
el = unsafe_load(Ptr{t8_dhex_t}(elements[1]))
76
77
if iseven(convert(Int, ltreeid)) && el.x == 0 && el.y == 0 && el.z == 0 &&
78
el.level < 2
79
# return true (refine)
80
return 1
81
else
82
# return false (don't refine)
83
return 0
84
end
85
end
86
87
Trixi.adapt!(mesh, adapt_callback)
88
89
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
90
boundary_conditions = boundary_conditions)
91
92
###############################################################################
93
# ODE solvers, callbacks etc.
94
95
tspan = (0.0, 1.0)
96
ode = semidiscretize(semi, tspan)
97
98
summary_callback = SummaryCallback()
99
100
analysis_interval = 100
101
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
102
103
alive_callback = AliveCallback(analysis_interval = analysis_interval)
104
105
save_solution = SaveSolutionCallback(interval = 100,
106
save_initial_solution = true,
107
save_final_solution = true,
108
solution_variables = cons2prim)
109
110
stepsize_callback = StepsizeCallback(cfl = 1.2)
111
112
callbacks = CallbackSet(summary_callback,
113
analysis_callback, alive_callback,
114
save_solution,
115
stepsize_callback)
116
117
###############################################################################
118
# run the simulation
119
120
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
121
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
122
ode_default_options()..., callback = callbacks);
123
124