Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/t8code_2d_dgsem/elixir_advection_extended.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)
8
equations = LinearScalarAdvectionEquation2D(advection_velocity)
9
10
initial_condition = initial_condition_convergence_test
11
12
# BCs must be passed as Dict
13
boundary_condition = BoundaryConditionDirichlet(initial_condition)
14
boundary_conditions = Dict(:x_neg => boundary_condition,
15
:x_pos => boundary_condition,
16
:y_neg => boundary_condition,
17
:y_pos => boundary_condition)
18
19
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
20
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
21
22
# The initial condition is 2-periodic
23
coordinates_min = (-1.5, 1.3) # minimum coordinates (min(x), min(y))
24
coordinates_max = (0.5, 5.3) # maximum coordinates (max(x), max(y))
25
26
trees_per_dimension = (19, 37)
27
28
# Create curved mesh with 19 x 37 elements
29
mesh = T8codeMesh(trees_per_dimension, polydeg = 3,
30
coordinates_min = coordinates_min, coordinates_max = coordinates_max,
31
periodicity = false)
32
33
# A semidiscretization collects data structures and functions for the spatial discretization
34
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
35
boundary_conditions = boundary_conditions)
36
37
###############################################################################
38
# ODE solvers, callbacks etc.
39
40
# Create ODE problem with time span from 0.0 to 1.0
41
tspan = (0.0, 1.0)
42
ode = semidiscretize(semi, tspan)
43
44
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
45
# and resets the timers
46
summary_callback = SummaryCallback()
47
48
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
49
analysis_interval = 100
50
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
51
extra_analysis_integrals = (entropy, energy_total))
52
53
# The AliveCallback prints short status information in regular intervals
54
alive_callback = AliveCallback(analysis_interval = analysis_interval)
55
56
# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted
57
save_restart = SaveRestartCallback(interval = 100,
58
save_final_restart = true)
59
60
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
61
save_solution = SaveSolutionCallback(interval = 100,
62
save_initial_solution = true,
63
save_final_solution = true,
64
solution_variables = cons2prim)
65
66
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
67
stepsize_callback = StepsizeCallback(cfl = 1.6)
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, save_solution,
73
stepsize_callback)
74
75
###############################################################################
76
# run the simulation
77
78
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
79
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
80
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
81
ode_default_options()..., callback = callbacks);
82
83