Solving unsteady problems
The main entry point of the package is solve_unsteady:
state, outputs = solve_unsteady(;
setup,
start = (; u),
tlims = (0.0, 1.0),
params = (; viscosity = 1e-3),
)It steps the initial start state (a named tuple of fields, e.g. (; u) or (; u, temp)) through the time interval tlims and returns the final state and the processor outputs.
Forces and parameters
The right-hand side is a function force!(force, state, t; setup, cache, params...) passed as the force! keyword. The built-in forces are navierstokes! (convection and diffusion, the default) and boussinesq! (adds a coupled temperature equation). Physical parameters are passed in the params named tuple and forwarded to force! as keyword arguments, e.g. params = (; viscosity = 1e-3) for navierstokes!. Custom forces follow the same signature; see examples/Kolmogorov2D.jl for a custom body force and examples/ChannelFlow.jl for adding an eddy-viscosity closure model.
Time step and method
By default, the time step is chosen adaptively from a CFL condition on the convective and diffusive limits (tune with the cfl keyword); pass a fixed Δt to disable this. The time integration method defaults to the low-storage third-order Runge-Kutta method LMWray3; any explicit Runge-Kutta tableau from RKMethods can be passed via the method keyword. The theory is discussed in Spatial and temporal discretization.
For finer control than solve_unsteady, the stepping primitives create_stepper and timestep/timestep! can be called directly, e.g. to write a custom (differentiable) simulation loop.
API
IncompressibleNavierStokes.boussinesq! Method
boussinesq!(
force,
state,
t;
setup,
cache,
viscosity,
conductivity,
gdir,
gravity,
dodissipation
)Boussinesq forcing (Navier-Stokes + gravity for u, convection-diffusion for temp).
IncompressibleNavierStokes.boussinesq Method
boussinesq(
state,
t;
setup,
viscosity,
conductivity,
gdir,
gravity,
dodissipation
)Boussinesq forcing (Navier-Stokes + gravity for u, convection-diffusion for temp).
IncompressibleNavierStokes.get_state Method
get_state(
stepper
) -> Union{NamedTuple, DataStructures.SortedMultiDict}Get state (; u, temp, t, n) from stepper.
IncompressibleNavierStokes.navierstokes! Method
navierstokes!(force, state, t; setup, cache, viscosity)Navier-Stokes momentum forcing (convection + diffusion).
sourceIncompressibleNavierStokes.navierstokes Method
navierstokes(state, t; setup, viscosity)Navier-Stokes momentum forcing (convection + diffusion).
sourceIncompressibleNavierStokes.solve_unsteady Method
solve_unsteady(
;
setup,
tlims,
start,
force!,
docopy,
method,
psolver,
Δt,
Δt_min,
cfl,
n_adapt_Δt,
processors,
params,
ode_cache,
force_cache
)Solve unsteady problem using method.
The initial start state is a named tuple of fields, e.g. (; u) or (; u, temp). The right-hand side force! is called as force!(force, state, t; setup, cache, params...), where params is a named tuple of parameters passed as keyword arguments (e.g. params = (; viscosity) for the default navierstokes!, or (; viscosity, conductivity, gdir, gravity, dodissipation) for boussinesq!).
If Δt is a real number, it is rounded such that (t_end - t_start) / Δt is an integer. If Δt = nothing, the time step is chosen every n_adapt_Δt iteration with CFL-number cfl. If Δt_min is given, the adaptive time step never goes below it.
The processors are called after every time step.
Note that the state observable passed to the processor.initialize function contains fields living on the device, and you may have to move them back to the host using Array in the processor.
Return (; state..., t), outputs, where outputs is a named tuple with the outputs of processors with the same field names.
Time stepping
IncompressibleNavierStokes.AbstractODEMethod Type
abstract type AbstractODEMethod{T}Abstract ODE method.
Fields
sourceIncompressibleNavierStokes.AbstractRungeKuttaMethod Type
abstract type AbstractRungeKuttaMethod{T} <: IncompressibleNavierStokes.AbstractODEMethod{T}Abstract Runge Kutta method.
Fields
sourceIncompressibleNavierStokes.ExplicitRungeKuttaMethod Type
struct ExplicitRungeKuttaMethod{T} <: IncompressibleNavierStokes.AbstractRungeKuttaMethod{T}Explicit Runge Kutta method. See Sanderse [6].
Consider the velocity field
For
where
Finally, we return
Note that each of the sub-step velocities
Fields
Abcrp_add_solve
IncompressibleNavierStokes.LMWray3 Type
struct LMWray3{T} <: IncompressibleNavierStokes.AbstractRungeKuttaMethod{T}Low memory Wray 3rd order scheme [8]. Uses 3 vector fields and one scalar field.
Fields
sourceIncompressibleNavierStokes.runge_kutta_method Method
runge_kutta_method(
A,
b,
c,
r;
T,
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethodGet Runge Kutta method. The function checks whether the method is explicit.
p_add_solve: whether to add a pressure solve step to the method.
For implicit RK methods: newton_type, maxiter, abstol, reltol.
IncompressibleNavierStokes.create_stepper Function
create_stepper(method; setup, psolver, state, t, n = 0)Create time stepper.
sourceIncompressibleNavierStokes.timestep Function
timestep(method, force, stepper, Δt; params = nothing)Perform one time step.
Non-mutating/allocating/out-of-place version.
See also timestep!.
IncompressibleNavierStokes.timestep! Function
timestep!(method, force!, stepper, Δt; params = nothing, ode_cache, force_cache)Perform one time step.
Mutating/non-allocating/in-place version.
See also timestep.
IncompressibleNavierStokes.get_cache Function
get_cache(method, state, setup)Get time stepper cache for the given ODE method.
The method get_cache(force!, setup) returns the cache for a right-hand-side function force! instead.
Runge-Kutta methods
IncompressibleNavierStokes.RKMethods Module
Set up Butcher arrays A, b, and c, as well as and SSP coefficient r. For families of methods, optional input s is the number of stages.
Original (MATLAB) by David Ketcheson, extended by Benjamin Sanderse.
Exports
IncompressibleNavierStokes.RKMethods.DOPRI6 Method
DOPRI6(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}Dormand-Prince pair.
sourceIncompressibleNavierStokes.RKMethods.FE11 Method
FE11(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}FE11 (Forward Euler).
sourceIncompressibleNavierStokes.RKMethods.HEM3 Method
HEM3(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}Brasey and Hairer.
sourceIncompressibleNavierStokes.RKMethods.HEM3BS Method
HEM3BS(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}HEM3BS.
sourceIncompressibleNavierStokes.RKMethods.HEM5 Method
HEM5(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}Brasey and Hairer, 5 stage, 4th order.
sourceIncompressibleNavierStokes.RKMethods.Heun33 Method
Heun33(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}Heun33.
sourceIncompressibleNavierStokes.RKMethods.MTE22 Method
MTE22(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}Minimal truncation error 22 method (Heun).
sourceIncompressibleNavierStokes.RKMethods.Mid22 Method
Mid22(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}Midpoint 22 method.
sourceIncompressibleNavierStokes.RKMethods.NSSP21 Method
NSSP21(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}NSSP21.
sourceIncompressibleNavierStokes.RKMethods.NSSP32 Method
NSSP32(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}NSSP32.
sourceIncompressibleNavierStokes.RKMethods.NSSP33 Method
NSSP33(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}NSSP33.
sourceIncompressibleNavierStokes.RKMethods.NSSP53 Method
NSSP53(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}NSSP53.
sourceIncompressibleNavierStokes.RKMethods.RK33C2 Method
RK33C2(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}RK3 satisfying C(2) for i=3.
sourceIncompressibleNavierStokes.RKMethods.RK33P2 Method
RK33P2(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}RK3 satisfying the second order condition for the pressure.
sourceIncompressibleNavierStokes.RKMethods.RK44 Method
RK44(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}Classical fourth order.
sourceIncompressibleNavierStokes.RKMethods.RK44C2 Method
RK44C2(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}RK4 satisfying C(2) for i=3.
sourceIncompressibleNavierStokes.RKMethods.RK44C23 Method
RK44C23(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}RK4 satisfying C(2) for i=3 and c2=c3.
sourceIncompressibleNavierStokes.RKMethods.RK44P2 Method
RK44P2(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}RK4 satisfying the second order condition for the pressure (but not third order).
sourceIncompressibleNavierStokes.RKMethods.RK56 Method
RK56(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}RK56.
sourceIncompressibleNavierStokes.RKMethods.SSP104 Method
SSP104(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}SSP104.
sourceIncompressibleNavierStokes.RKMethods.SSP22 Method
SSP22(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}SSP22.
sourceIncompressibleNavierStokes.RKMethods.SSP33 Method
SSP33(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}SSP33.
sourceIncompressibleNavierStokes.RKMethods.SSP42 Method
SSP42(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}SSP42.
sourceIncompressibleNavierStokes.RKMethods.SSP43 Method
SSP43(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}SSP43.
sourceIncompressibleNavierStokes.RKMethods.Wray3 Method
Wray3(
;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod{Float64}Wray's RK3.
sourceIncompressibleNavierStokes.RKMethods.rSSPs2 Function
rSSPs2(
;
...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod
rSSPs2(
s;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethodRational (optimal, low-storage) s-stage 2nd order SSP.
IncompressibleNavierStokes.RKMethods.rSSPs3 Function
rSSPs3(
;
...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethod
rSSPs3(
s;
kwargs...
) -> IncompressibleNavierStokes.ExplicitRungeKuttaMethodRational (optimal, low-storage) s^2-stage 3rd order SSP.