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_advection_nonconforming.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# Semidiscretization of the linear advection equation.
6
7
advection_velocity = (0.2, -0.7, 0.5)
8
equations = LinearScalarAdvectionEquation3D(advection_velocity)
9
10
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux.
11
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
12
13
coordinates_min = (-1.0, -1.0, -1.0) # minimum coordinates (min(x), min(y), min(z))
14
coordinates_max = (1.0, 1.0, 1.0) # maximum coordinates (max(x), max(y), max(z))
15
trees_per_dimension = (1, 1, 1)
16
17
# Note that it is not necessary to use mesh polydeg lower than the solver polydeg
18
# on a Cartesian mesh.
19
# See https://doi.org/10.1007/s10915-018-00897-9, Section 6.
20
mesh = T8codeMesh(trees_per_dimension, polydeg = 3,
21
coordinates_min = coordinates_min, coordinates_max = coordinates_max,
22
initial_refinement_level = 2)
23
24
# Note: This is actually a `p8est_quadrant_t` which is much bigger than the
25
# following struct. But we only need the first four fields for our purpose.
26
struct t8_dhex_t
27
x::Int32
28
y::Int32
29
z::Int32
30
level::Int8
31
# [...] # See `p8est.h` in `p4est` for more info.
32
end
33
34
# Refine bottom left quadrant of each second tree to level 2
35
function adapt_callback(forest, ltreeid, eclass_scheme, lelemntid, elements, is_family,
36
user_data)
37
el = unsafe_load(Ptr{t8_dhex_t}(elements[1]))
38
39
if iseven(convert(Int, ltreeid)) && el.x == 0 && el.y == 0 && el.z == 0 &&
40
el.level < 3
41
# return true (refine)
42
return 1
43
else
44
# return false (don't refine)
45
return 0
46
end
47
end
48
49
Trixi.adapt!(mesh, adapt_callback)
50
51
# A semidiscretization collects data structures and functions for the spatial discretization
52
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
53
solver)
54
55
###############################################################################
56
# ODE solvers, callbacks etc.
57
58
# Create ODE problem with time span from 0.0 to 1.0
59
tspan = (0.0, 1.0)
60
ode = semidiscretize(semi, tspan)
61
62
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
63
# and resets the timers
64
summary_callback = SummaryCallback()
65
66
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
67
analysis_callback = AnalysisCallback(semi, interval = 100)
68
69
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
70
save_solution = SaveSolutionCallback(interval = 100,
71
solution_variables = cons2prim)
72
73
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
74
stepsize_callback = StepsizeCallback(cfl = 1.6)
75
76
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
77
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
78
stepsize_callback)
79
80
###############################################################################
81
# run the simulation
82
83
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
84
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
85
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
86
ode_default_options()..., callback = callbacks);
87
88