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_euler_free_stream.jl
5586 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 polydeg of 2 (half the solver polydeg) to ensure FSP (see above).
60
mesh = P4estMesh{3}(mesh_file, polydeg = 2,
61
mapping = mapping)
62
63
# Refine bottom left quadrant of each second tree to level 2
64
function refine_fn(p8est, which_tree, quadrant)
65
quadrant_obj = unsafe_load(quadrant)
66
if iseven(convert(Int, which_tree)) && quadrant_obj.x == 0 && quadrant_obj.y == 0 &&
67
quadrant_obj.z == 0 && quadrant_obj.level < 2
68
# return true (refine)
69
return Cint(1)
70
else
71
# return false (don't refine)
72
return Cint(0)
73
end
74
end
75
76
# Refine recursively until each bottom left quadrant of every second tree has level 2.
77
# The mesh will be rebalanced before the simulation starts.
78
refine_fn_c = @cfunction(refine_fn, Cint,
79
(Ptr{Trixi.p8est_t}, Ptr{Trixi.p4est_topidx_t},
80
Ptr{Trixi.p8est_quadrant_t}))
81
Trixi.refine_p4est!(mesh.p4est, true, refine_fn_c, C_NULL)
82
83
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
84
boundary_conditions = boundary_conditions)
85
86
###############################################################################
87
# ODE solvers, callbacks etc.
88
89
tspan = (0.0, 1.0)
90
ode = semidiscretize(semi, tspan)
91
92
summary_callback = SummaryCallback()
93
94
analysis_interval = 100
95
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
96
97
alive_callback = AliveCallback(analysis_interval = analysis_interval)
98
99
save_solution = SaveSolutionCallback(interval = 100,
100
save_initial_solution = true,
101
save_final_solution = true,
102
solution_variables = cons2prim)
103
104
stepsize_callback = StepsizeCallback(cfl = 1.2)
105
106
callbacks = CallbackSet(summary_callback,
107
analysis_callback, 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