Skip to content

Time stepping ​

This page describes the mathematics and internal implementation of SpeedyWeather.jl's time integration schemes. For how to create and configure a time stepper and pass it to the model constructor, see Time integration in the Usage section.

SpeedyWeather.jl supports several time integration schemes, selected by passing a time_stepping component to the model constructor:

  • Leapfrog, a 2-step leapfrog scheme with a Robert-Asselin and Williams filter (the default for ShallowWaterModel, PrimitiveDryModel and PrimitiveWetModel), described below.

  • StochasticLeapfrog, the leapfrog scheme with additive Wiener noise.

  • NCycleLorenz, a family of semi-implicit Lorenz N-cycle schemes ((); the default for BarotropicModel).

All schemes share a common framework (see Time steppers and variable steps) in which the time stepper decides, for every model component, which stored step of each variable to read or write. This decouples the dynamical core and parameterizations from the time-stepping bookkeeping: e.g. leapfrog stores two steps of the prognostic variables, while the Lorenz N-cycle stores only one but keeps a second tendency for its weighted accumulation.

Leapfrog ​

SpeedyWeather.jl's default time integration is the Leapfrog time integration, which, for relative vorticity , is in its simplest form

meaning we step from the previous time step  , leapfrogging over the current time step to the next time step   by evaluating the tendencies on the right-hand side at the current time step . The time stepping is done in spectral space (see LowerTriangularArrays for how spectral coefficients are stored). Once the right-hand side is evaluated, leapfrogging is a linear operation, meaning that its simply applied to every spectral coefficient as one would evaluate it on every grid point in grid-point models.

For the Leapfrog time integration two time steps of the prognostic variables have to be stored,   and . Time step is used to evaluate the tendencies which are then added to   in a step that also swaps the indices for the next time step    and   , so that no additional memory than two time steps have to be stored at the same time.

Leapfrog initialisation ​

The Leapfrog time integration has to be initialized with an Euler forward step in order to have a second time step   available when starting from to actually leapfrog over. SpeedyWeather.jl therefore does two initial time steps that are different from the leapfrog time steps that follow and that have been described above.

  1. an Euler forward step with , then

  2. one leapfrog time step with , then

  3. leapfrog with till the end

This is particularly done in a way that after 2. we have   at   and   at available so that 3. can start the leapfrogging without any offset from the intuitive spacing . The following schematic can be useful

time at step  time at step time step at  
Initial conditions 
1: Euler(T)    
2: Leapfrog with  (T)    
3 to : Leapfrog with  (T)     

The time step that is used to evaluate the tendencies is denoted with (T). It is always the time step furthest in time that is available.

Before the time integration starts, the initial conditions – which only occupy step   – are also copied into step . This is purely a bookkeeping convenience: it lets which_prognostic_step always return step (2) as the one to evaluate the right-hand side on, without a special case for the very first (Euler) step where step would otherwise not yet exist.

The initial Euler step is not filtered, see Robert-Asselin and Williams filter below. On the first two steps (Euler, and the first leapfrog step) Leapfrog's update_prognostic! therefore disables the filter weights (both are 0), and enables them for every step after that.

Robert-Asselin and Williams filter ​

The standard leapfrog time integration is often combined with a Robert-Asselin filter (; ) to dampen a computational mode. The idea is to start with a standard leapfrog step to obtain the next time step   but then to correct the current time step by applying a filter which dampens the computational mode. The filter looks like a discrete Laplacian in time with a   stencil, and so, maybe unsurprisingly, is efficient to filter out a "grid-scale oscillation" in time, aka the computational mode. Let be the unfiltered variable and be the filtered variable, the right-hand side tendency, then the standard leapfrog step is

Meaning we start with a filtered variable at the previous time step  , evaluate the tendency based on the current time step to obtain an unfiltered next time step . We then filter the current time step (which will become   on the next iteration)

by adding a discrete Laplacian with coefficient to it, evaluated from the available filtered and unfiltered time steps centred around : is not available anymore because it was overwritten by the filtering at the previous iteration, are not filtered yet when applying the Laplacian. The filter parameter is typically chosen between 0.01-0.2, with stronger filtering for higher values.

then proposed an additional filter step to regain accuracy that is otherwise lost with a strong Robert-Asselin filter (; ). Now let be unfiltered, be once filtered, and twice filtered, then

with the Williams filter parameter  . For   we're back with the Robert-Asselin filter (the first two lines).

The Laplacian in the parentheses is often called a displacement, meaning that the filtered value is displaced (or corrected) in the direction of the two surrounding time steps. The Williams filter now also applies the same displacement, but in the opposite direction to the next time step   as a correction step (line 3 above) for a once-filtered value which will then be twice-filtered by the Robert-Asselin filter on the next iteration. For more details see the referenced publications.

The initial Euler step (see Leapfrog initialisation) is not filtered. Both the the Robert-Asselin and Williams filter are then switched on for all following leapfrog time steps.

Implementation-wise, update_prognostic! for Leapfrog folds both filters into two weights   and   (both zero on the unfiltered initial steps) and applies the leapfrog step, the Robert-Asselin and the Williams filter in a single kernel per spectral coefficient (and vertical layer).

Stochastic leapfrog ​

StochasticLeapfrog is the leapfrog scheme above with additive Wiener noise, it integrates the stochastic differential equation

for every prognostic variable with the deterministic tendencies of the model and white noise of a fixed amplitude (AdditiveWienerNoise: independent in time, between variables and between layers, spectrally flat by default). Every time step a new pattern of unit variance is drawn and is added to the tendencies, so that the state receives increments , whose variance grows linearly in time independent of the time step.

The scheme is drift-implicit: the noise is treated explicitly and is added to the complete explicit tendencies right before the implicit terms of the time stepping. Splitting the tendencies    into the terms that are treated explicitly and the linear terms that are treated implicitly (the horizontal diffusion with   and the gravity waves of the semi-implicit time stepping with the centering   by default), a time step is

followed by the Robert-Asselin and Williams filter. The noise is therefore on the right-hand side of the implicit solves like every explicit tendency and the implicit terms damp it within the time step, as they do in the exact solution of the linear problem, in which the noise enters as . Implementation-wise, time_step! calls random_process!(vars, time_stepping, model) between the dynamical core and diffusion_and_implicit!, which for StochasticLeapfrog adds the noise to the spectral tendencies and does nothing for the other time steppers. The pattern for the next time step is drawn after update_prognostic! by update_random!(vars, model), which advances all random processes once per time step, including model.random_process of the stochastic physics.

This is how stiff linear terms are treated in the standard schemes for stochastic differential equations

  • The implicit Euler schemes of (chapter 12) and the stochastic theta method () evaluate the drift (partly) at the new time step and add the Wiener increment explicitly,      .

  • The stochastic semi-implicit leapfrog scheme analysed for geophysical models by , in its weak version ()      .

Two properties of the scheme here are worth knowing

  • One increment is added per leapfrog step, not the sum of two increments as in . The physical mode (the mean of the two interleaved leapfrog sequences) receives the same  , but the noise also excites the computational mode, which the time filter damps. The filter is hence part of the stochastic scheme.

  • The alternative of adding the noise after the implicit terms, a split-step scheme (), converges to the same equation for   and injects exactly the specified noise covariance. However, it leaves the noise undamped in the stiff modes, which are implicit because they are stiff: the smallest scales (  at the truncation wavenumber with the default resolution and diffusion) and the fast gravity waves. The two variants agree where is small, i.e. on the large scales.

The diffusion the noise injects is the nominal ( is the standard deviation of the pattern) only for modes for which neither the implicit terms nor the time filter matter, it should be measured for the scales of interest. Ocean and land variables have no implicit terms and are stepped with EulerForward (see Ocean, sea ice and land), for them the scheme is the Euler-Maruyama method with grid-point white noise.

SpeedyWeather.StochasticLeapfrog Type

Leapfrog time stepping with additive Wiener noise, i.e. the stochastic differential equation

with the deterministic tendencies of the model, white noise patterns of fixed amplitude (see AdditiveWienerNoise) and the semi-implicit leapfrog scheme of Leapfrog (Euler start, Robert-Asselin-Williams filter, implicit diffusion and gravity waves).

The scheme is drift-implicit: the noise is explicit and added to the tendencies as with a new pattern (standard deviation standard_deviation) every time step, right before the implicit terms, i.e. after the parameterizations and the dynamical core. Schematically, with the linear terms that are treated implicitly,

(  for the horizontal diffusion, = centering for the gravity waves of the semi-implicit correction; for the first Euler step instead of ). The noise is on the right-hand side of the implicit solves like every explicit tendency, so the implicit terms damp it within the time step, as the exact solution   of the linear problem does. This is how stiff linear terms are treated in the standard schemes for stochastic differential equations:

  • the implicit Euler schemes of Kloeden and Platen (1992, chapter 12) and the stochastic theta method (Higham, 2000) evaluate (part of) the drift at the new time step and add the Wiener increment explicitly,      ,

  • the stochastic semi-implicit leapfrog scheme of Ewald and Témam (2005) and its weak version (Ewald),       with the implicit part .

Here one increment   is added per leapfrog step instead of Ewald and Témam's sum of two: the physical mode (the mean of the two interleaved leapfrog sequences) receives the same   , the computational mode that is excited in addition is damped by the time filter. The alternative of adding the noise after the implicit terms is a valid scheme too (split-step, Higham, Mao and Stuart, 2002) and converges to the same equation for  , but it leaves the noise in the stiff modes (the smallest scales, fast gravity waves) undamped by the terms that are implicit because they are stiff. Ocean and land variables have no implicit terms and are stepped with EulerForward, for them the scheme is the Euler-Maruyama method.

The diffusion this scheme injects per variable is the nominal ( the standard_deviation) only where neither the implicit terms nor the time filter matter, and should be measured where it matters (e.g. 1.33× nominal for a T8 barotropic model).

The pattern applied in a time step is drawn at the end of the previous time step and stored in the variables (vars.prognostic.wiener_pattern, vars.prognostic.wiener_pattern_surface), so the first time step of a new simulation is deterministic and a simulation continued with another run! continues with the stored pattern. The noise realisation is reproducible through seed, independent of other random processes.

StochasticLeapfrog is a Leapfrog whose noise field holds an AbstractWienerNoise (a type alias, not a new time stepper): every method of Leapfrog applies, only the Wiener increment is added. Use as time_stepping = StochasticLeapfrog(spectral_grid; seed = 123), keyword arguments other than those of Leapfrog are passed on to AdditiveWienerNoise, or equivalently Leapfrog(spectral_grid; noise = AdditiveWienerNoise(spectral_grid; seed = 123)). All amplitudes zero gives the same trajectory as Leapfrog without noise.

References

  • Ewald, B. D. and R. Témam, 2005. Numerical analysis of stochastic schemes in geophysics. SIAM J. Numer. Anal. 42(6), 2257-2276, doi:10.1137/S0036142902418333

  • Ewald, B. D. Weak versions of stochastic Adams-Bashforth and semi-implicit leapfrog schemes for SDEs (scheme 4.3), https://www.math.fsu.edu/~ewald/

  • Higham, D. J., 2000. Mean-square and asymptotic stability of the stochastic theta method. SIAM J. Numer. Anal. 38(3), 753-769, doi:10.1137/S003614299834736X

  • Higham, D. J., X. Mao and A. M. Stuart, 2002. Strong convergence of Euler-type methods for nonlinear stochastic differential equations. SIAM J. Numer. Anal. 40(3), 1041-1063, doi:10.1137/S0036142901389530

  • Kloeden, P. E. and E. Platen, 1992. Numerical solution of stochastic differential equations. Springer, doi:10.1007/978-3-662-12616-5

source
SpeedyWeather.AdditiveWienerNoise Type

Additive Wiener noise for the prognostic variables, used by StochasticLeapfrog. Every prognostic variable x and every layer is forced by its own independent white noise pattern ξ (independent in time, between variables and between layers) with a fixed amplitude a, so the noise is additive: its covariance depends neither on the state nor on any parameter of the model. With time step Δt the tendency receives a/√Δt ⋅ taper ⋅ ξ, so the state receives an increment ∝ a√Δt ⋅ ξ per step, a Wiener increment whose variance is independent of the time step. Δt is the time step of the respective time stepper at the current step, half of it for a leapfrog step, see wiener_scale.

The amplitudes are given per variable by the name of its tendency, e.g. AdditiveWienerNoise(spectral_grid; vorticity = 3e-8, η = 1e-3, soil_temperature = 1e-4), variables not listed get no noise. Units are those of the variable per √s, e.g. 1/s^(3/2) for vorticity and divergence, K/s^(1/2) for temperature. Which variables there are is inferred from the tendencies of the model (tendency_names, ocean_tendency_names, land_tendency_names):

  • atmospheric variables are forced with one SpectralWhiteNoiseProcess (spectrally flat by default) that has a pattern slot for every layer of every variable (variables with layers first, then single-layer variables, each in the order of tendency_names), also for zero amplitudes, so that switching one amplitude on or off does not change the noise realisation of the others. The noise is added to the spectral tendencies, so its covariance is diagonal in the spectral coefficients. The pattern has no global mean, the noise therefore conserves e.g. the mass (surface pressure). Variables with layers are tapered with tapering(σ).

  • ocean and land variables (e.g. sea surface temperature) with a nonzero amplitude are forced by a GridWhiteNoiseProcess, independently at every grid point and layer.

The amplitudes multiply a pattern of standard deviation standard_deviation (1/3 by default, as for SpectralAR1Process). The defaults are the amplitudes used for T32 L8 PrimitiveWet models in a 1500-year stochastic control run: climate-neutral, stable, humidity bounded by clipping rather than by the climate (see the docstring of StochasticLeapfrog). They are not universal, check them for other resolutions, time steps or models. The noise is drawn on the model's architecture (see architecture_rng); draw_on_cpu = true draws it on the CPU also on GPU (slower, but the same numbers as on CPU).

Fields are

  • amplitudes::NamedTuple: [OPTION] Noise amplitude per variable, by the name of its tendency, zero for all others

  • tapering::Any: [OPTION] Vertical tapering as a function of sigma, for atmospheric variables with layers

  • taper::Any: [DERIVED] Vertical tapering per layer

  • spectral::Any: [OPTION] White noise process in spectral space for the atmospheric variables

  • grid::Any: [OPTION] White noise process in grid space for the ocean and land variables

source

Time steppers and variable steps ​

Different time integration schemes need to store a different number of past states of the prognostic variables and/or tendencies. Leapfrog needs the two spectral steps   and ; the Lorenz N-cycle needs only one prognostic step but a second tendency to accumulate weighted tendencies. SpeedyWeather handles this generically: prognostic variables and tendencies carry an extra Step dimension (the last dimension of their underlying array), and the time stepper decides how many steps to allocate and which step each model component should read or write.

The number of steps is requested by the time stepper through prognostic_steps and tendency_steps (with prognostic_grid_steps, prognostic_spectral_steps, tendency_grid_steps, tendency_spectral_steps to distinguish grid/spectral and dispatch over the model). For example leapfrog requests two spectral prognostic steps but, in the primitive-equation models, also two grid steps (because the parameterizations are evaluated at the previous grid state):

julia
prognostic_steps(::AbstractLeapfrog) = 2
prognostic_grid_steps(::AbstractLeapfrog, ::PrimitiveEquation) = 2
tendency_steps(::AbstractLeapfrog) = 1

The Lorenz N-cycle, by contrast, only needs one prognostic step (the state is updated in place) but two spectral tendency steps – one for the explicit tendency , one for the weighted accumulation – and only one grid tendency step ( is only ever needed in spectral space):

julia
prognostic_steps(::NCycleLorenz) = 1
tendency_steps(::NCycleLorenz) = 2          # also for ocean and land variables, stepped directly on the grid
tendency_grid_steps(::NCycleLorenz) = 1     # atmospheric grid tendencies only hold F

Throughout the dynamical core and parameterizations a variable is then accessed with get_prognostic_step / get_tendency_step, which return a view of the appropriate step:

julia
# in a model component, e.g. the spectral→grid transform or a tendency term
vor  = get_prognostic_step(vars.prognostic.vorticity, time_stepping, component)
ζtend = get_tendency_step(vars.tendencies.vorticity,  time_stepping, component)

Which step is returned is decided by the time stepper via which_prognostic_step / which_tendency_step, dispatched on the variable, the time stepper, the component and (optionally) the model — so a scheme can choose a different step per process. The fallback is step 1, and leapfrog for instance overrides it to read the current (2nd) step for transforms and the nonlinear dynamical core, but the previous (1st) step for the linear terms and horizontal diffusion:

julia
which_prognostic_step(var, ::AbstractLeapfrog, ::AbstractSpectralTransform)       = 2  # current
which_prognostic_step(var, ::AbstractLeapfrog, ::LinearDynamicalCore)             = 1  # previous
which_prognostic_step(var, ::AbstractLeapfrog, ::AbstractHorizontalDiffusion)     = 1  # previous

For the Lorenz N-cycle, only the explicit tendency is reset to zero every substep for accumulation into ; the fallback step 1 covers this and every other component that only ever needs one tendency step:

julia
which_tendency_step(var, ::AbstractNCycleLorenz, ::ResetTendencies) = 1

get_step(var, i) is the low-level accessor used by all of the above. Which array dimension is the step dimension is taken from the variable's dimension tag (see Array dimensions): get_step selects the dimension tagged as time T, so for a variable tagged XYT, XYZT, LMT or LMZT it returns a view of step i. A variable without a time tag (XY, XYZ, LM, LMZ) has no step dimension to select from — the full variable is returned as a view and i is ignored. Model components can therefore call it unconditionally, whether or not the variable they are handed has steps. get_steps(var) returns all steps as a tuple of views (a 1-tuple for a variable without a step dimension), and get_steps(var, Val(N)) does the same with a compile-time length, which is what Enzyme needs.

Dispatching on whether a variable has a step dimension at all is done with the AbstractFieldWithTime / LowerTriangularArrayWithTime aliases, as nsteps does:

julia
nsteps(var::Union{AbstractFieldWithTime, LowerTriangularArrayWithTime}) = size(var, ndims(var))
nsteps(::Union{AbstractField, LowerTriangularArray}) = 1
SpeedyWeather.get_step Function
julia
get_step(var)

Select the step dimension from a variable, when no step is provided as 2nd argument select the last step as this typically represents the "current" step (and not any previous ones). But this depends on the time stepping a variable with step dimension was created for. Variables without a step dimension have a single step, so get_step(var) returns the full variable as a view.

source
julia
get_step(
    var::LowerTriangularArray{T, 1, A, S, SpeedyWeatherInternals.ArrayDimensions.LM},
    step::Integer
) where {T, A, S}

Get the i-th step of a LowerTriangularArray as a view (wrapped into a LowerTriangularArray). "step" refers to the time dimension T in the variable's ArrayDimensions, for prognostic variables e.g. used for the leapfrog time step. These methods are for spectral variables WITHOUT a time dimension (LM, LMZ), which have no step dimension to select from: the full array is returned as a view and step is ignored (it should be 1).

source
julia
get_step(
    var::LowerTriangularArray{T, 2, A, S, SpeedyWeatherInternals.ArrayDimensions.LMT},
    step::Integer
) where {T, A, S}

Get the i-th step of a LowerTriangularArray as a view (wrapped into a LowerTriangularArray). "step" refers to the time dimension T in the variable's ArrayDimensions, for prognostic variables e.g. used for the leapfrog time step. These methods are for spectral variables WITH a time dimension (LMT horizontal + time, LMZT horizontal + vertical + time), whose last dimension is the step dimension.

source
julia
get_step(
    var::AbstractField2D{T, A, G, SpeedyWeatherInternals.ArrayDimensions.XY},
    step::Integer
) where {T, A, G}

Get the i-th step of a field as a view (wrapped into the same type as the input variable). "step" refers to the time dimension T in the variable's ArrayDimensions, for prognostic variables e.g. used for the leapfrog time step. These methods are for fields WITHOUT a time dimension (XY, XYZ), which have no step dimension to select from: the full array is returned as a view and step is ignored (it should be 1).

source
julia
get_step(
    var::AbstractField{T, 1, A, G, SpeedyWeatherInternals.ArrayDimensions.XYT},
    step::Integer
) where {T, A, G}

Get the i-th step of a field as a view (wrapped into the same type as the input variable). "step" refers to the time dimension T in the variable's ArrayDimensions, for prognostic variables e.g. used for the leapfrog time step. These methods are for fields WITH a time dimension (XYT horizontal + time, XYZT horizontal + vertical + time), whose last dimension is the step dimension.

source
SpeedyWeather.get_steps Function

Get all steps of a variable as a tuple of views (wrapped into the same type as the input variable) as defined by get_step. "Steps" refer to the step dimension, i.e. the time dimension T in the variable's ArrayDimensions (e.g. XYT, LMZT), for prognostic variables e.g. used for the leapfrog time step. Variables without a time dimension have no steps to splat, so a 1-tuple holding the full variable (as a view, consistent with get_step) is returned.

source

When writing a new time stepper you implement the *_steps methods (how many steps to store), the which_*_step methods (which step each component reads/writes) and an update_prognostic! method (how a tendency advances the state); the rest of the model is agnostic to the scheme.

Time steppers can also reorder how diffusion and the semi-implicit correction are applied via diffusion_and_implicit!: Leapfrog applies the implicit correction first, then horizontal diffusion, while the Lorenz N-cycle applies diffusion first, then the implicit correction (consistent with the ordering in ). Right before, a stochastic time stepper adds its noise to the complete explicit tendencies with random_process!, see Stochastic leapfrog.

Ocean, sea ice and land ​

Dynamic ocean, sea ice and land components (e.g. SlabOcean, ThermodynamicSeaIce, LandBucketTemperature, LandBucketMoisture, SnowModel) write tendencies into vars.tendencies.ocean and vars.tendencies.land. The variables in these namespaces are time stepped with their own time stepper within the time stepping setup model.time_stepping, SpeedyWeather.time_stepper(model.time_stepping, :ocean) and (model.time_stepping, :land) (sea ice lives in the :ocean namespace). By default this is the time stepper of the atmosphere, but Leapfrog has ocean and land fields which default to EulerForward, which steps the variables with Euler forward over :

julia
time_stepping = Leapfrog(spectral_grid)                             # Euler forward for ocean and land
time_stepping = Leapfrog(spectral_grid, land = nothing)             # leapfrog land as the atmosphere
model = PrimitiveWetModel(spectral_grid; time_stepping)

NCycleLorenz has the same ocean and land fields, defaulting to nothing, i.e. the same N-cycle as the atmosphere. Any time stepper can be used for ocean and land, e.g. Leapfrog(spectral_grid, land = NCycleLorenz(spectral_grid)).

The variables are allocated with the number of steps of their time stepper (prognostic_steps and tendency_steps, see SpeedyWeather.get_nsteps(time_stepping, :land)), so with EulerForward ocean and land variables have only one step, with NCycleLorenz one prognostic step and two tendency steps. The time step of ocean and land is always set to the of the leapfrog (also with set!(model, Δt=...)), and on the first two leapfrog steps, which each only advance the clock by , also Euler steps with .

Why not leapfrog? The tendencies are computed from surface fluxes (sensible and latent heat, longwave radiation) that the parameterizations evaluate at the previous (1st) step, and they contain stiff relaxation terms, e.g. the sensible heat flux feedback on the thin top soil layer has timescales of about an hour in strong winds. Leapfrogging those over from   is an Euler step of , which halves the stability limit compared to an Euler step of and made long integrations unstable. Terms that are meant to act "within one time step" (e.g. restoring sea surface temperatures to freezing when sea ice forms) use SpeedyWeather.time_step(model.time_stepping, :ocean, clock) for the same reason.

SpeedyWeather.EulerForward Type

Euler forward time stepping, used by default for the ocean and land namespaces with Leapfrog (see its ocean and land fields). Defined by the following fields

  • Δt_at_T32::Any: [OPTION] Time step for T32, scale linearly to spectral resolution truncation

  • adjust_with_output::Any: [OPTION] Adjust Δt_at_T32 with the output interval to output exactly after integer time steps

  • Δt_millisec::Any: [DERIVED] Time step Δt in milliseconds at specified resolution

  • Δt::Any: [DERIVED] Time step Δt [s] at specified resolution

source

Lorenz N-cycle ​

The Lorenz N-cycle NCycleLorenz is a semi-implicit time integration following . Over a cycle of substeps it advances the state , per substep, as

where are the explicit tendencies, the linear (gravity-wave) terms treated implicitly, and a substep-dependent weight coefficient. Only one prognostic step is stored (the state is updated in place), but two tendencies are kept: (the current tendency) and (the weighted accumulation that carries memory across substeps), hence tendency_spectral_steps(::NCycleLorenz) = 2. In SpeedyWeather's implementation the implicit solve      is folded into the same implicit_correction! step used by Leapfrog (see Semi-implicit time stepping for the primitive equations and Semi-implicit time integration for the shallow water model – both implicit solves are shared between time steppers), so update_prognostic! for NCycleLorenz itself only performs the weighted accumulation and the explicit state update

for every spectral coefficient (and vertical layer), with the implicit correction applied to beforehand by diffusion_and_implicit!.

Four weight variants are available, following the naming in , selected via the variant option:

VariantWeight for substep    ( )Steps per periodNotes
NCycleLorenzA (default)  
NCycleLorenzB 
NCycleLorenzABalternates a full cycle of A, then a full cycle of B2 cycles per period
NCycleLorenzABBAsequence A, B, B, A4th-order accurate for  ; other run but without that accuracy guarantee

"Steps per period" is the number of substeps after which the weight sequence repeats. These substeps can be interpreted in two ways: as sub-stages of a single step, the way a Runge-Kutta method would use them, where the full time step is only completed once all substeps of a period have run; or as a multi-step method with changing weights that restarts every period, where every substep already advances the state by a full (as in the update     above). SpeedyWeather.jl uses the latter, so the computational cost of the Lorenz N-cycle is independent of but, like leapfrog, inversely proportional to .

The cycle length is set with steps (3 or 4 recommended, 4 is more stable). The current substep is current_substep(L, clock) = mod(clock.step_counter, L.steps), and the weight for that substep is computed by weight_coefficient, dispatched on the variant.

SpeedyWeather.NCycleLorenz Type
julia
NCycleLorenz{NF, V, ...} <: AbstractTimeStepper

A semi-implicit Lorenz N-cycle time integration scheme following Hotta et al. (2016).

Algorithm (per substep of a cycle)

  1. G = w_F_E(x) + (1-w)_G (weighted tendency accumulation)

  2. dx = (I - α_Δt_L_I)^(-1) * (G + L_I*x) (implicit solve)

  3. x = x + Δt*dx (state update)

  • steps::Any: [OPTION] Number of steps N in a cycle (3 or 4 recommended, 4 is more stable)

  • variant::Any: [OPTION] Variant: NCycleLorenzA() (default), B, AB, or ABBA

  • Δt_at_T32::Any: [OPTION] Time step for T32 resolution, scale linearly with resolution

  • adjust_with_output::Any: [OPTION] Adjust Δt_at_T32 with the interval to reach interval exactly

  • Δt_millisec::Any: [DERIVED] Time step Δt in milliseconds at specified resolution

  • Δt::Any: [DERIVED] Time step Δt [s] at specified resolution

  • ocean::Any: [OPTION] Time stepper for the ocean (incl sea ice) variables, nothing for the same N-cycle as the atmosphere

  • land::Any: [OPTION] Time stepper for the land variables, nothing for the same N-cycle as the atmosphere

source
SpeedyWeather.NCycleLorenzA Type

Version A: weights w_k = N/(N-k) for k=1,...,N-1; w_0 = 1

source
SpeedyWeather.NCycleLorenzB Type

Version B: weights w_k = N/k for k=1,...,N-1; w_0 = 1

source
SpeedyWeather.NCycleLorenzAB Type

Version AB: alternates A and B every N steps

source
SpeedyWeather.NCycleLorenzABBA Type

Version ABBA: uses A-B-B-A sequence (only for N=4, provides 4th order accuracy)

source

Periodic schedules ​

Many components don't need to do something on every time step but only periodically, e.g. the semi-implicit solver of the primitive equations, which recomputes its reference temperature profile (and with it the implicit operators) once a day by default. SpeedyWeather.jl has three schedules for this, all subtypes of AbstractSchedule and all used with isscheduled(schedule, clock), which returns true on the time steps on which to execute

ScheduleMutablePeriodicEventsInitialized withPrimarily used for
Scheduleyesevery::Secondtimes::Vector{DateTime}initialize!(schedule, clock) at every run!callbacks, see Schedules
PeriodicScheduleyesevery::Second–initialize!(schedule, time_stepping) in initialize!(model)model components
StepSchedulenoevery_n_steps::Int–nothing to initializemodel components

The Schedule precomputes a BitVector of all time steps of a simulation, so that it can combine periodic execution with events at given times. But for that it needs the start time and the length of the simulation, which are only known in run!. PeriodicSchedule and StepSchedule are purely periodic and only need the time step, so they can be part of model components that are initialized with initialize!(model) before run! is called. A model component would typically use them as

julia
@kwdef struct MyComponent <: SpeedyWeather.AbstractModelComponent
    schedule::PeriodicSchedule = PeriodicSchedule(every = Day(1))
    # other fields
end

function SpeedyWeather.initialize!(component::MyComponent, model::AbstractModel)
    initialize!(component.schedule, model.time_stepping)    # converts every to every_n_steps
    # initialize other things here
end

function SpeedyWeather.timestep!(vars::Variables, component::MyComponent, model::AbstractModel)
    isscheduled(component.schedule, vars.prognostic.clock) || return nothing
    # do something every day only
end

PeriodicSchedule vs StepSchedule ​

A PeriodicSchedule is defined by a period of time, every, which is converted into a number of time steps every_n_steps with the model's time step on initialize!. every is rounded to a multiple of the time step, and is at least one time step; every = Second(0) means never. It also counts its executions in counter.

julia
using SpeedyWeather
spectral_grid = SpectralGrid(truncation = 32, nlayers = 1)
time_stepping = Leapfrog(spectral_grid)
periodic_schedule = PeriodicSchedule(every = Hour(6))
initialize!(periodic_schedule, time_stepping)
PeriodicSchedule <: SpeedyWeather.AbstractSchedule
├ every::Second = 21600 seconds
├ every_n_steps::Int64 = 9
└ counter::Int64 = 0

so with a time step of time_stepping.Δt_millisec at T32 executing every 6 hours means every periodic_schedule.every_n_steps time steps. Changing the resolution therefore changes every_n_steps but not (up to rounding) every. A StepSchedule on the other hand is immutable and directly defined by the number of time steps every_n_steps, independent of the time step; every_n_steps = 0 means never

julia
step_schedule = StepSchedule(every_n_steps = 4)
StepSchedule <: SpeedyWeather.AbstractSchedule
└ every_n_steps::Int64 = 4

which is useful if something should execute every n-th time step regardless of resolution. StepSchedule(1) executes on every time step (but the first), e.g. for the semi-implicit solver to always recompute its reference temperature profile

julia
reference_temperature = GlobalMeanReferenceTemperature()
implicit = ImplicitPrimitiveEquation(spectral_grid; schedule = StepSchedule(1), reference_temperature)
model = PrimitiveWetModel(spectral_grid; implicit)

The semi-implicit corrections are centred in time by default, centering = 0.5 (Crank-Nicolson). centering = 1 is backward Euler, which damps the gravity waves. With (near-)uniformly spaced σ levels, i.e. SigmaCoordinates(spectral_grid), Crank-Nicolson can be unstable over steep orography (a warning is raised), use the default FriersonSigmaCoordinates or centering = 1 there. The schedule is only used with a reference temperature profile that is recomputed from the global-mean temperature. The semi-implicit solver linearises about a reference temperature profile , chosen with reference_temperature

Reference temperatureProfile Recomputed
IsothermalReferenceTemperature(temperature = 300) (default)constant temperatureonly when the time step changes
GlobalMeanReferenceTemperature(offset = 0)global-mean temperature + offseton the schedule
MaximumReferenceTemperature(margin = 30)constant, maximum temperature + marginon the schedule

A warm isothermal reference profile is the most stable choice (Simmons, Hoskins and Burridge, 1978), as also used in other models, e.g. 300 K in Isca and the IFS. The warmer the reference temperature, the more the gravity waves treated implicitly are slowed down. MaximumReferenceTemperature therefore follows the model's climate, e.g. for a snowball Earth or a hot climate, with an isothermal reference temperature just above the warmest temperature in the model.

Scheduling and the leapfrog spin-up ​

All schedules count the time steps with clock.time_step_counter which excludes the initial conditions and the spin-up of the Leapfrog initialisation: the first Euler forward step with does not count. With every 4th time step, i.e. Schedule(every = 4Δt), PeriodicSchedule(every = 4Δt) or StepSchedule(4), all three schedules execute on the same steps, after 4, 8, ... of simulated time. For the first 10 leapfrog time steps (clock shown after each step)

Time stepper stepLeapfrog stepclock.step_counterclock.time_step_counterClock timeisscheduled
(initial)-000
1Euler, (spin-up)10
2Leapfrog, (spin-up end)21
3Leapfrog, 32
4Leapfrog, 43
5Leapfrog, 54✅
6Leapfrog, 65
7Leapfrog, 76
8Leapfrog, 87
9Leapfrog, 98✅
10Leapfrog, 109

Callbacks are evaluated after the clock is stepped forward, so they see the clock as in the table. Model components inside the time step, like the semi-implicit solver, are evaluated before the clock is stepped forward. They see the same clock one time stepper step later, e.g. the semi-implicit solver recomputes its reference temperature profile at the beginning of time stepper step 6, computing the tendencies at time . With events, Schedule(times = ...), a Schedule executes on the first time step on or after the given time, see Scheduling logic.

SpeedyWeather.PeriodicSchedule Type

A periodic schedule, to execute something every period every (first time step excluded), rounded to a multiple of the time step. Unlike Schedule it does not need the clock (start time or length of the simulation) and can therefore be initialized with the time stepper only, e.g. in initialize!(model), converting every into every_n_steps. Use as

julia
@kwdef struct MyComponent
    schedule::PeriodicSchedule = PeriodicSchedule(every = Day(1))
end

with isscheduled(component.schedule, clock) || return nothing. Fields

  • every::Second = Day(1): [OPTION] Execute every time period, rounded to a multiple of the time step, Second(0) = never

  • every_n_steps::Int64 = 0: [DERIVED] every in time steps (at least 1), 0 = never

  • counter::Int64 = 0: [DERIVED] Count up the number of executions

source
SpeedyWeather.StepSchedule Type

An immutable schedule executing every every_n_steps time steps (first time step and spin-up steps excluded), 0 = never, 1 = every time step. Needs no initialization. Use as isscheduled(component.schedule, clock) || return nothing. Fields

  • every_n_steps::Int64 = 1: [OPTION] Execute every n time steps, 0 = never
source