Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/docs/literate/src/files/time_stepping.jl
5591 views
1
#src # Explicit time stepping
2
3
# For the time integration, [Trixi.jl](https://github.com/trixi-framework/Trixi.jl) uses the package
4
# [OrdinaryDiffEq.jl](https://github.com/SciML/OrdinaryDiffEq.jl) and its sub-packages
5
# from the SciML ecosystem.
6
# The interface to these packages is the `solve(...)` function. It always requires an ODE problem and
7
# a time integration algorithm as input parameters.
8
# ````julia
9
# solve(ode, alg; kwargs...);
10
# ````
11
# In Trixi.jl, the ODE problem is created by `semidiscretize(semi, tspan)` for a semidiscretization
12
# `semi` and the time span `tspan`. In particular, [`semidiscretize`](@ref) returns an `ODEProblem`
13
# used by OrdinaryDiffEq.jl.
14
15
# OrdinaryDiffEq.jl provides many integration algorithms, which are summarized in
16
# the [documentation](https://diffeq.sciml.ai/stable/solvers/ode_solve/#Full-List-of-Methods).
17
# Particularly interesting for Trixi.jl are their
18
# [strong stability preserving (SSP) methods](https://diffeq.sciml.ai/stable/solvers/ode_solve/#Explicit-Strong-Stability-Preserving-Runge-Kutta-Methods-for-Hyperbolic-PDEs-(Conservation-Laws))
19
# and [low-storage methods](https://diffeq.sciml.ai/stable/solvers/ode_solve/#Low-Storage-Methods).
20
# These methods are also available from the low-dependency sub-packages
21
# OrdinaryDiffEqLowStorageRK.jl and OrdinaryDiffEqSSPRK.jl of OrdinaryDiffEq.jl.
22
# There are some differences regarding the choice of the used time step.
23
24
# # [Error-based adaptive step sizes](@id adaptive_step_sizes)
25
# First, we treat time integration algorithms with adaptive step sizes, such as `SSPRK43`. It is used in
26
# some elixirs, like [`elixir_euler_colliding_flow.jl`](https://github.com/trixi-framework/Trixi.jl/blob/main/examples/tree_2d_dgsem/elixir_euler_colliding_flow.jl)
27
# or [`elixir_euler_astro_jet_amr.jl`](https://github.com/trixi-framework/Trixi.jl/blob/main/examples/tree_2d_dgsem/elixir_euler_astro_jet_amr.jl).
28
29
# Other error-based adaptive integration algorithms are for instance `RDPK3SpFSAL35`, `RDPK3Sp35`,
30
# `RDPK3SpFSAL49`, `RDPK3Sp49`, `RDPK3SpFSAL510`, `RDPK3Sp510`.
31
32
# They already contain an error-based adaptive step size control and heuristics to guess
33
# a starting step size. If this heuristic fails in your case, you can specify an appropriately
34
# small initial step size as keyword argument `dt=...` of `solve`.
35
36
# If you run Trixi in parallel with MPI you need to pass `internalnorm=ode_norm` and you should pass `unstable_check=ode_unstable_check`
37
# to enable MPI aware error-based adaptive step size control. These keyword arguments are also included in [`ode_default_options`](@ref).
38
39
# # CFL-based step size control
40
# The SciML ecosystem also provides time integration algorithms without adaptive time stepping on
41
# their own, such as `CarpenterKennedy2N54`. Moreover, you also can deactivate the automatic adaptivity
42
# of adaptive integration algorithms by passing `adaptive=false` in the `solve` function.
43
44
# These algorithms require another way of setting the step size. You have to pass `dt=...`
45
# in the `solve` function. Without other settings, the simulation uses this fixed time step.
46
47
# For hyperbolic PDEs, it is natural to use an adaptive CFL-based step size control. Here, the time
48
# step is proportional to a ratio of the local measure of mesh spacing $\Delta x_i$ for an element `i`
49
# and the maximum (local) wave speed $\lambda_{\max}$ related to the largest-magnitude eigenvalue of
50
# the flux Jacobian of the hyperbolic system.
51
# ```math
52
# \Delta t_n = \text{CFL} * \min_i \frac{\Delta x_i}{\lambda_{\max}(u_i^n)}
53
# ```
54
# We compute $\Delta x_i$ by scaling the element size by a factor of $1/(N+1)$, cf.
55
# [Gassner and Kopriva (2011)](https://doi.org/10.1137/100807211), Section 5.
56
57
# Trixi.jl provides such a CFL-based step size control. It is implemented as the callback
58
# [`StepsizeCallback`](@ref).
59
# ````julia
60
# stepsize_callback = StepsizeCallback(; cfl=1.0)
61
# ````
62
# A suitable CFL number depends on many parameters such as the chosen grid, the integration
63
# algorithm and the polynomial degree of the spatial DG discretization. So, the optimal number
64
# for an example is mostly determined experimentally.
65
66
# You can add this CFL-based step size control to your simulation like any other callback.
67
# ````julia
68
# callbacks = CallbackSet(stepsize_callback)
69
# alg = CarpenterKennedy2N54(williamson_condition=false)
70
# solve(ode, alg;
71
# dt=1.0 # solve needs some value here but it will be overwritten by the stepsize_callback
72
# callback=callbacks);
73
# ````
74
75
# You can find simple examples with a CFL-based step size control for instance in the elixirs
76
# [`elixir_advection_basic.jl`](https://github.com/trixi-framework/Trixi.jl/blob/main/examples/tree_2d_dgsem/elixir_advection_basic.jl)
77
# or [`elixir_euler_source_terms.jl`](https://github.com/trixi-framework/Trixi.jl/blob/main/examples/tree_2d_dgsem/elixir_euler_source_terms.jl).
78
79
# ## Package versions
80
81
# These results were obtained using the following versions.
82
83
using InteractiveUtils
84
versioninfo()
85
86
using Pkg
87
Pkg.status(["Trixi"],
88
mode = PKGMODE_MANIFEST)
89
90