Skip to content

integration⚓︎

Time stepping (integration) tools.

FD_Jac(func, eps=1e-07) ⚓︎

Finite-diff approx. of Jacobian of func.

The function func(x) must be compatible with x.ndim == 1 and 2, where, in the 2D case, each row is seen as one function input.

Returns:

Type Description
function

The first input argument is that of which the derivative is taken.

Examples:

>>> dstep_dx = FD_Jac(step)

integrate_TLM(TLM, dt, method='approx') ⚓︎

Compute the resolvent.

The resolvent may also be called

  • the Jacobian of the step func.
  • the integral of (with M as the TLM):
\[ \frac{d U}{d t} = M U, \quad U_0 = I . \]

The tangent linear model (TLM)

is assumed constant (for each method below).

Parameters:

Name Type Description Default
method str
  • 'approx' : derived from the forward-euler scheme.
  • 'rk4' : higher-precision approx.
  • 'analytic': exact.

Warning

"'analytic' typically requries higher inflation in the ExtKF."

'approx'
See Also

FD_Jac.

rk4(f, x, t, dt, stages=4, s=0) ⚓︎

Runge-Kutta (explicit, non-adaptive) numerical (S)ODE solvers.

For ODEs, the order of convergence equals the number of stages.

For SDEs with additive noise (s>0), the order of convergence (both weak and strong) is 1 for stages equal to 1 or 4. These correspond to the classic Euler-Maruyama scheme and the Runge-Kutta scheme for S-ODEs respectively, see grudzien2020a for a DA-specific discussion on integration schemes and their discretization errors.

Parameters:

Name Type Description Default
f function

The time derivative of the dynamical system. Must be of the form f(t, x)

required
x ndarray or float

State vector of the forcing term

required
t float

Starting time of the integration

required
dt float

Integration time step.

required
stages int

The number of stages of the RK method. When stages=1, this becomes the Euler (-Maruyama) scheme. Default: 4.

4
s float

The diffusion coeffient (std. dev) for models with additive noise. Default: 0, yielding deterministic integration.

0

Returns:

Type Description
ndarray

State vector at the new time, t+dt

with_recursion(func, prog=False) ⚓︎

Make function recursive in its 1st arg.

Return a version of func whose 2nd argument (k) specifies the number of times to times apply func on its output.

!!! warning Only the first argument to func will change, so, for example, if func is step(x, t, dt), it will get fed the same t and dt at each iteration.

Parameters:

Name Type Description Default
func function

Function to recurse with.

required
prog bool or str

Enable/Disable progressbar. If str, set its name to this.

False

Returns:

Name Type Description
fun_k function

A function that returns the sequence generated by recursively running func, i.e. the trajectory of system's evolution.

Examples:

>>> def dxdt(x):
...     return -x
>>> step_1  = with_rk4(dxdt, autonom=True)
>>> step_k  = with_recursion(step_1)
>>> x0      = np.arange(3)
>>> x7      = step_k(x0, 7, t0=np.nan, dt=0.1)[-1]
>>> x7_true = x0 * np.exp(-0.7)
>>> np.allclose(x7, x7_true)
True

with_rk4(dxdt, autonom=False, stages=4, s=0) ⚓︎

Wrap dxdt in rk4.