Time-step with ClimaTimeSteppers
ClimaCore fields and field vectors are the state vectors of ClimaTimeSteppers.jl, which provides explicit, implicit-explicit (IMEX), and Rosenbrock Runge–Kutta methods. This page shows how a ClimaCore tendency plugs in; the algorithms and their properties are ClimaTimeSteppers's documentation.
Prerequisites
import ClimaTimeSteppers as CTS in a project that has both packages.
Steps
Put the state in a
Field(for one variable or aNamedTupleof them on one space) or aFields.FieldVector(for variables on different spaces, e.g. centers and faces):Y = Fields.FieldVector(; c = center_state, f = face_state)Write the tendency in place, with the signature
(∂ₜY, Y, p, t), wherepholds parameters and caches. Complete spectral-element results by DSS or with atendency_completioninside the tendency, or pass adss!callback to the stepper (step 4).function T_exp!(∂ₜY, Y, p, t) @. ∂ₜY.c = -wdiv(flux(Y.c, p)) Operators.complete_tendency!(p.completion, ∂ₜY.c, Y.c, p) return nothing endFor an explicit method, wrap the tendency in a
ClimaODEFunctionand solve:prob = CTS.ODEProblem(CTS.ClimaODEFunction(; T_exp!), Y, (t0, t_end), p) sol = CTS.solve(prob, CTS.ExplicitAlgorithm(CTS.SSP33ShuOsher()); dt, saveat)For an IMEX method, split the tendency into
T_exp!andT_imp!, and give the implicit part a Jacobian. The Jacobian of a column-local implicit tendency is a banded matrix per column;MatrixFieldsstores it as a field of matrix rows andFieldMatrixWithSolversolves it (Build an implicit vertical solver):T_imp = CTS.ODEFunction( T_imp!; jac_prototype = MatrixFields.FieldMatrixWithSolver(jacobian, Y), Wfact, # Wfact(W, Y, p, dtγ, t) fills W = dtγ ∂T_imp/∂Y − I ) dss!(Y, p, t) = Spaces.weighted_dss!(Y.c) prob = CTS.ODEProblem(CTS.ClimaODEFunction(; T_exp!, T_imp!, dss!), Y, (t0, t_end), p) integrator = CTS.init(prob, CTS.IMEXAlgorithm(CTS.ARS343(), CTS.NewtonsMethod(; max_iters = 1)); dt) CTS.solve!(integrator)ARS343is the third-order additive scheme of [8] that the atmosphere uses; with only the acoustic and gravity-wave terms implicit one Newton iteration per stage suffices [9]. Thedss!callback runs after each stage so that the state is continuous when the next stage evaluates it.Save output through
saveat, or step manually withCTS.step!(integrator)and inspectintegrator.ubetween steps.
Where time stepping is demonstrated
- Solve a column PDE: explicit, one field.
- Shallow water on a plane: explicit,
NamedTuplestate, DSS inside the tendency. - Three dimensions on the cubed sphere: implicit vertical diffusion with a
MatrixFieldsJacobian and adss!callback. examples/hybrid/driver.jlwithexamples/hybrid/ode_config.jl: the IMEX configuration of the staggered nonhydrostatic model, including the Jacobian inexamples/hybrid/implicit_equation_jacobian.jl.