Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_3d_dgsem/elixir_advection_extended.jl
5586 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
initial_condition = initial_condition_convergence_test
11
12
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
13
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
14
15
coordinates_min = (-1.0, -1.0, -1.0) # minimum coordinates (min(x), min(y), min(z))
16
coordinates_max = (1.0, 1.0, 1.0) # maximum coordinates (max(x), max(y), max(z))
17
18
# Create a uniformly refined mesh with periodic boundaries
19
mesh = TreeMesh(coordinates_min, coordinates_max,
20
initial_refinement_level = 3,
21
n_cells_max = 30_000, # set maximum capacity of tree data structure
22
periodicity = true)
23
24
# you can either use a single function to impose the BCs weakly in all
25
# 2*ndims == 6 directions or you can pass a named tuple containing BCs for
26
# each direction
27
boundary_conditions = boundary_condition_periodic
28
29
# A semidiscretization collects data structures and functions for the spatial discretization
30
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
31
boundary_conditions = boundary_conditions)
32
33
###############################################################################
34
# ODE solvers, callbacks etc.
35
36
# Create ODE problem with time span from 0.0 to 1.0
37
tspan = (0.0, 1.0)
38
ode = semidiscretize(semi, tspan)
39
40
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
41
# and resets the timers
42
summary_callback = SummaryCallback()
43
44
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
45
analysis_interval = 100
46
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
47
extra_analysis_integrals = (entropy, energy_total))
48
49
# The AliveCallback prints short status information in regular intervals
50
alive_callback = AliveCallback(analysis_interval = analysis_interval)
51
52
# The SaveRestartCallback allows to save a file from which a Trixi simulation can be restarted
53
save_restart = SaveRestartCallback(interval = 100,
54
save_final_restart = true)
55
56
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
57
save_solution = SaveSolutionCallback(interval = 100,
58
save_initial_solution = true,
59
save_final_solution = true,
60
solution_variables = cons2prim)
61
62
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
63
stepsize_callback = StepsizeCallback(cfl = 1.2)
64
65
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
66
callbacks = CallbackSet(summary_callback,
67
analysis_callback, alive_callback,
68
save_restart, save_solution,
69
stepsize_callback)
70
71
###############################################################################
72
# run the simulation
73
74
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
75
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
76
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
77
ode_default_options()..., callback = callbacks);
78
79