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
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, 0.5)
8
equations = LinearScalarAdvectionEquation3D(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
# Note: "boundary_condition_periodic" indicates that it is a periodic boundary and can be omitted on
16
# fully periodic domains. Here, however, it is included to allow easy override during testing
17
boundary_conditions = boundary_condition_periodic
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
coordinates_min = (-1.0, -1.0, -1.0) # minimum coordinates (min(x), min(y), min(z))
23
coordinates_max = (1.0, 1.0, 1.0) # maximum coordinates (max(x), max(y), max(z))
24
25
# Create a uniformly refined mesh with periodic boundaries
26
mesh = TreeMesh(coordinates_min, coordinates_max,
27
initial_refinement_level = 3,
28
n_cells_max = 30_000, # set maximum capacity of tree data structure
29
periodicity = true)
30
31
# A semidiscretization collects data structures and functions for the spatial discretization
32
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
33
boundary_conditions = boundary_conditions)
34
35
###############################################################################
36
# ODE solvers, callbacks etc.
37
38
# Create ODE problem with time span from 0.0 to 1.0
39
tspan = (0.0, 1.0)
40
ode = semidiscretize(semi, tspan)
41
42
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
43
# and resets the timers
44
summary_callback = SummaryCallback()
45
46
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
47
analysis_interval = 100
48
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
49
extra_analysis_integrals = (entropy, energy_total))
50
51
# The AliveCallback prints short status information in regular intervals
52
alive_callback = AliveCallback(analysis_interval = analysis_interval)
53
54
# The SaveRestartCallback allows to save a file from which a Trixi simulation can be restarted
55
save_restart = SaveRestartCallback(interval = 100,
56
save_final_restart = true)
57
58
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
59
save_solution = SaveSolutionCallback(interval = 100,
60
save_initial_solution = true,
61
save_final_solution = true,
62
solution_variables = cons2prim)
63
64
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
65
stepsize_callback = StepsizeCallback(cfl = 1.2)
66
67
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
68
callbacks = CallbackSet(summary_callback,
69
analysis_callback, alive_callback,
70
save_restart, save_solution,
71
stepsize_callback)
72
73
###############################################################################
74
# run the simulation
75
76
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
77
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
78
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
79
ode_default_options()..., callback = callbacks);
80
81