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
2055 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 = Dict(: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
initial_refinement_level = 0)
62
63
# Note: This is actually a `p8est_quadrant_t` which is much bigger than the
64
# following struct. But we only need the first four fields for our purpose.
65
struct t8_dhex_t
66
x::Int32
67
y::Int32
68
z::Int32
69
level::Int8
70
# [...] # See `p8est.h` in `p4est` for more info.
71
end
72
73
# Refine bottom left quadrant of each second tree to level 2
74
function adapt_callback(forest, ltreeid, eclass_scheme, lelemntid, elements, is_family,
75
user_data)
76
el = unsafe_load(Ptr{t8_dhex_t}(elements[1]))
77
78
if iseven(convert(Int, ltreeid)) && el.x == 0 && el.y == 0 && el.z == 0 &&
79
el.level < 2
80
# return true (refine)
81
return 1
82
else
83
# return false (don't refine)
84
return 0
85
end
86
end
87
88
Trixi.adapt!(mesh, adapt_callback)
89
90
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
91
boundary_conditions = boundary_conditions)
92
93
###############################################################################
94
# ODE solvers, callbacks etc.
95
96
tspan = (0.0, 1.0)
97
ode = semidiscretize(semi, tspan)
98
99
summary_callback = SummaryCallback()
100
101
analysis_interval = 100
102
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
103
104
alive_callback = AliveCallback(analysis_interval = analysis_interval)
105
106
save_solution = SaveSolutionCallback(interval = 100,
107
save_initial_solution = true,
108
save_final_solution = true,
109
solution_variables = cons2prim)
110
111
stepsize_callback = StepsizeCallback(cfl = 1.2)
112
113
callbacks = CallbackSet(summary_callback,
114
analysis_callback, alive_callback,
115
save_solution,
116
stepsize_callback)
117
118
###############################################################################
119
# run the simulation
120
121
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
122
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
123
ode_default_options()..., callback = callbacks);
124
125