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