Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_2d_dgsem/elixir_advection_timeintegration_adaptive.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)
8
equations = LinearScalarAdvectionEquation2D(advection_velocity)
9
10
initial_condition = initial_condition_convergence_test
11
12
# you can either use a single function to impose the BCs weakly in all
13
# 1*ndims == 2 directions or you can pass a tuple containing BCs for
14
# each direction
15
boundary_conditions = boundary_condition_periodic
16
17
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
18
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
19
20
coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
21
coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))
22
23
# Create a uniformly refined mesh with periodic boundaries
24
mesh = TreeMesh(coordinates_min, coordinates_max,
25
initial_refinement_level = 4,
26
n_cells_max = 30_000, # set maximum capacity of tree data structure
27
periodicity = true)
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.jl simulation can be restarted
53
save_restart = SaveRestartCallback(interval = 40,
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
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
63
callbacks = CallbackSet(summary_callback,
64
analysis_callback, alive_callback,
65
save_restart, save_solution)
66
67
###############################################################################
68
# run the simulation
69
70
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
71
alg = RDPK3SpFSAL49()
72
sol = solve(ode, alg;
73
callback = callbacks,
74
ode_default_options()...);
75
76