Path: blob/main/docs/literate/src/files/time_stepping.jl
5591 views
#src # Explicit time stepping12# For the time integration, [Trixi.jl](https://github.com/trixi-framework/Trixi.jl) uses the package3# [OrdinaryDiffEq.jl](https://github.com/SciML/OrdinaryDiffEq.jl) and its sub-packages4# from the SciML ecosystem.5# The interface to these packages is the `solve(...)` function. It always requires an ODE problem and6# a time integration algorithm as input parameters.7# ````julia8# solve(ode, alg; kwargs...);9# ````10# In Trixi.jl, the ODE problem is created by `semidiscretize(semi, tspan)` for a semidiscretization11# `semi` and the time span `tspan`. In particular, [`semidiscretize`](@ref) returns an `ODEProblem`12# used by OrdinaryDiffEq.jl.1314# OrdinaryDiffEq.jl provides many integration algorithms, which are summarized in15# the [documentation](https://diffeq.sciml.ai/stable/solvers/ode_solve/#Full-List-of-Methods).16# Particularly interesting for Trixi.jl are their17# [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))18# and [low-storage methods](https://diffeq.sciml.ai/stable/solvers/ode_solve/#Low-Storage-Methods).19# These methods are also available from the low-dependency sub-packages20# OrdinaryDiffEqLowStorageRK.jl and OrdinaryDiffEqSSPRK.jl of OrdinaryDiffEq.jl.21# There are some differences regarding the choice of the used time step.2223# # [Error-based adaptive step sizes](@id adaptive_step_sizes)24# First, we treat time integration algorithms with adaptive step sizes, such as `SSPRK43`. It is used in25# 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)26# 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).2728# Other error-based adaptive integration algorithms are for instance `RDPK3SpFSAL35`, `RDPK3Sp35`,29# `RDPK3SpFSAL49`, `RDPK3Sp49`, `RDPK3SpFSAL510`, `RDPK3Sp510`.3031# They already contain an error-based adaptive step size control and heuristics to guess32# a starting step size. If this heuristic fails in your case, you can specify an appropriately33# small initial step size as keyword argument `dt=...` of `solve`.3435# If you run Trixi in parallel with MPI you need to pass `internalnorm=ode_norm` and you should pass `unstable_check=ode_unstable_check`36# to enable MPI aware error-based adaptive step size control. These keyword arguments are also included in [`ode_default_options`](@ref).3738# # CFL-based step size control39# The SciML ecosystem also provides time integration algorithms without adaptive time stepping on40# their own, such as `CarpenterKennedy2N54`. Moreover, you also can deactivate the automatic adaptivity41# of adaptive integration algorithms by passing `adaptive=false` in the `solve` function.4243# These algorithms require another way of setting the step size. You have to pass `dt=...`44# in the `solve` function. Without other settings, the simulation uses this fixed time step.4546# For hyperbolic PDEs, it is natural to use an adaptive CFL-based step size control. Here, the time47# step is proportional to a ratio of the local measure of mesh spacing $\Delta x_i$ for an element `i`48# and the maximum (local) wave speed $\lambda_{\max}$ related to the largest-magnitude eigenvalue of49# the flux Jacobian of the hyperbolic system.50# ```math51# \Delta t_n = \text{CFL} * \min_i \frac{\Delta x_i}{\lambda_{\max}(u_i^n)}52# ```53# We compute $\Delta x_i$ by scaling the element size by a factor of $1/(N+1)$, cf.54# [Gassner and Kopriva (2011)](https://doi.org/10.1137/100807211), Section 5.5556# Trixi.jl provides such a CFL-based step size control. It is implemented as the callback57# [`StepsizeCallback`](@ref).58# ````julia59# stepsize_callback = StepsizeCallback(; cfl=1.0)60# ````61# A suitable CFL number depends on many parameters such as the chosen grid, the integration62# algorithm and the polynomial degree of the spatial DG discretization. So, the optimal number63# for an example is mostly determined experimentally.6465# You can add this CFL-based step size control to your simulation like any other callback.66# ````julia67# callbacks = CallbackSet(stepsize_callback)68# alg = CarpenterKennedy2N54(williamson_condition=false)69# solve(ode, alg;70# dt=1.0 # solve needs some value here but it will be overwritten by the stepsize_callback71# callback=callbacks);72# ````7374# You can find simple examples with a CFL-based step size control for instance in the elixirs75# [`elixir_advection_basic.jl`](https://github.com/trixi-framework/Trixi.jl/blob/main/examples/tree_2d_dgsem/elixir_advection_basic.jl)76# or [`elixir_euler_source_terms.jl`](https://github.com/trixi-framework/Trixi.jl/blob/main/examples/tree_2d_dgsem/elixir_euler_source_terms.jl).7778# ## Package versions7980# These results were obtained using the following versions.8182using InteractiveUtils83versioninfo()8485using Pkg86Pkg.status(["Trixi"],87mode = PKGMODE_MANIFEST)888990