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
5586 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
boundary_conditions = boundary_condition_periodic
17
18
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
19
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
20
21
coordinates_min = -1.0 # minimum coordinate
22
coordinates_max = 1.0 # maximum coordinate
23
24
# Create a uniformly refined mesh with periodic boundaries
25
mesh = TreeMesh(coordinates_min, coordinates_max,
26
initial_refinement_level = 4,
27
n_cells_max = 30_000, # set maximum capacity of tree data structure
28
periodicity = true)
29
30
# A semidiscretization collects data structures and functions for the spatial discretization
31
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
32
boundary_conditions = boundary_conditions)
33
34
###############################################################################
35
# ODE solvers, callbacks etc.
36
37
# Create ODE problem with time span from 0.0 to 1.0
38
tspan = (0.0, 1.0)
39
ode = semidiscretize(semi, tspan)
40
41
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
42
# and resets the timers
43
summary_callback = SummaryCallback()
44
45
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
46
analysis_interval = 100
47
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
48
extra_analysis_integrals = (entropy, energy_total))
49
50
# The AliveCallback prints short status information in regular intervals
51
alive_callback = AliveCallback(analysis_interval = analysis_interval)
52
53
# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted
54
save_restart = SaveRestartCallback(interval = 100,
55
save_final_restart = true)
56
57
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
58
save_solution = SaveSolutionCallback(interval = 100,
59
save_initial_solution = true,
60
save_final_solution = true,
61
solution_variables = cons2prim)
62
63
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
64
stepsize_callback = StepsizeCallback(cfl = 1.6)
65
66
# Enable in-situ visualization with a new plot generated at every time step
67
visualization = VisualizationCallback(semi; interval = 1)
68
69
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
70
callbacks = CallbackSet(summary_callback,
71
analysis_callback, alive_callback,
72
save_restart,
73
save_solution, visualization,
74
stepsize_callback)
75
76
###############################################################################
77
# run the simulation
78
79
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
80
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
81
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
82
ode_default_options()..., callback = callbacks);
83
84