Skip to content

Transient problems

What a march keeps — only the frames you ask for

Evaluated eagerly (fem.solve(...).fn(), fem.solve(k=2.0)), a march keeps no past on the device. Each step writes its state into a save slot when a frame at save_ts will read it (a save time on the grid, or the two grid points either side of one off it) and into a scratch row otherwise, and the frames come back as a host NumPy array.

Saving every step of a march whose frames would outgrow 1/16 of the device runs it in chunks: each chunk's frames are copied out while the next chunk is already queued, with nothing inside the compiled step (no callback, no sync). The answer is bit-identical to the one-scan march on CPU, under every scheme below; on a GPU it moves only by the run-to-run noise the old march had (measured 4–7e-11, scatter-add order).

Measured (RTX 3070, 2-D linear heat, 22,801 DOFs, 5 frames saved): peak device memory 186 → 59 MiB at 500 steps and 708 → 59 MiB at 2,000 steps; wall time unchanged.

Pass save_ts= for a long march. The default saves every grid point, which keeps the whole trajectory — on the host now, not the device. Under jit/grad (jno.core, an inverse problem) the march stays one lax.scan holding every step: the adjoint needs the states.

What a march's Newton keeps — its tangent

A nonlinear march's default per-step Newton is jno.solve.newton(reuse=True): it keeps the assembled step tangent while that still contracts the residual (‖r_new‖ < ‖r_old‖/2), refreshes it the moment it does not, and rejects a step that fails to reduce the residual -- so a stale tangent costs at most one wasted solve, never a divergence. Evaluated eagerly, the march also carries the tangent from step to step (on the step-merge plan's fixed sparsity pattern), because a march's tangent changes little between steps.

The step's convergence record reuses the norms Newton already computed instead of evaluating the residual twice more. And on a kept tangent the inner Krylov solve is inexact: a step contracts the residual by the tangent's own contraction, not by the accuracy of the linear solve, so each correction is solved only to a forcing tolerance -- half the outer target over the current residual, floored at 1e-3, capped at 0.1 (Dembo, Eisenstat & Steihaug 1982) -- instead of to 1e-10.

Measured (RTX 3070, the Taylor–Green LES of the turbulence tutorial: residual-based VMS + Vreman, P1/P1, BDF2): at 55,296 DOFs one tangent for an 8-step march instead of two per step, 0.80 → 0.30 s per step; at 442,368 DOFs, where the Krylov solves dominate once the tangent is kept, the inexact solves take 1,200 → 160 matvecs per step, 2.14 → 1.50 s per step -- same trajectory (energy identical to 6 digits).

The answer moves only within the Newton tolerance: a reused tangent converges linearly, so the final residual lands under the test rather than far below it. Pass nonlinear=jno.solve.newton() for a fresh tangent at every iteration. Under jit/grad the march keeps the tangent within a step but not across steps (the reverse pass would store one tangent per step).

Time schemes — fem.solve(time=…)

Scheme Order Stability Use
jno.solve.theta(1.0) 1 L-stable the default — robust, damps everything
jno.solve.theta(0.5) 2 A-stable only smooth problems; rings on stiff modes
jno.solve.bdf2() 2 L-stable stiff / saddle-point systems — flow's workhorse
jno.solve.bdf(order=None\|1..5) 1–5, chosen per step L-stable to 2, A(α) above stiff transients on error-controlled steps: one implicit solve per step
jno.solve.sdirk(order=2\|3) 2 or 3 L-stable, stiffly accurate higher order where BDF2 is not enough; state-dependent mass allowed
jno.solve.rosenbrock("ros34pw2"\|"ros2") 3 or 2 L-stable nonlinear blocks without Newton: one linear solve per stage
jno.solve.exponential() exact in time unconditional linear, autonomous blocks (mass="consistent" for the system the other schemes solve)
…​.adaptive(rtol=…) wraps a one-step scheme — multi-rate transients

bdf2 exists because theta cannot be second order and L-stable at once. Crank–Nicolson's amplification factor tends to -1 for a stiff mode, so the mode does not decay — it alternates in sign. Measured on a heat problem whose initial condition is incompatible with its boundary (8 steps, T = 0.5, so the exact field is long dead): Crank–Nicolson reaches min u = -0.70 and still carries 0.33 at the end; BDF2 reaches -0.023.

Rows with no time derivative (Dirichlet rows, a pressure, an FDM flux row) are constraints, and every θ-scheme imposes them at the new time, as backward Euler does. The θ-average would make Crank–Nicolson satisfy them only on average over the step (a boundary started off its value would flip sign every step and never settle), and would leave forward Euler with a singular step. On a Navier–Stokes saddle system, where the pressure has no time derivative at all, that ringing is exactly what you do not want.

The first BDF2 step is plain backward Euler — a multistep method has no second level to start from. A state-dependent mass c(u)·u_t is marched in BDF2's non-conservative form c(uⁿ⁺¹)(3uⁿ⁺¹ − 4uⁿ + uⁿ⁻¹)/(2Δt), second order in time (measured on a manufactured c(u) = 1 + u²); it is not the conservative form an enthalpy mass H(u)_t would want.

It composes with periodic ties (the march carries the reduced state; the mass action is reduced like the residual). Refused loudly rather than mis-integrated: a second-order-in-time (u_tt) block (assembled at θ=½ so that it is not damped). bdf2().adaptive(rtol=…) is the variable-step march of bdf(order=2), below.

Variable-step, variable-order BDF — bdf()

jno.solve.bdf() is the stiff integrator of MATLAB's ode15s and SUNDIALS CVODE: backward differentiation formulas of order 1 to 5 on error-controlled steps, the order chosen per step for the largest step (Shampine & Reichelt, SIAM J. Sci. Comput. 18, 1997).

Each step is ONE implicit solve, and the error estimate comes from the predictor, so no stage or step is taken twice. The coefficients are those of the actual, unequal past steps (variable-coefficient BDF), and the default ndf=True adds the Klopfenstein–Shampine correction, which keeps the stability and shrinks the error constant.

sol = fem.solve(time=jno.solve.bdf())                                  # orders 1-5, rtol 1e-4
sol = fem.solve(time=jno.solve.bdf().adaptive(rtol=1e-6, atol=1e-9))
sol = fem.solve(time=jno.solve.bdf(order=2).adaptive(rtol=1e-5))       # order held at 2

The step is a backward-Euler step from a shifted state, so it carries what that step carries: Newton on a nonlinear block, the solver slots, Dirichlet and algebraic rows, a state-dependent mass (non-conservative form), complex and periodic fields, and reverse-mode gradients at the realized step schedule.

Measured on a two-mode heat problem: the error at all save times follows rtol (1e-4 → 2e-4, 1e-6 → 5e-6), and at rtol = 1e-6 the variable-order march needs about a quarter of the attempts of order 2 held. Scope: orders 3–5 are A(α)-stable only (α = 86°, 73°, 51°), so a lightly damped oscillation loses accuracy there; use sdirk, theta(0.5) or bdf(order=2) for it. A u_tt block is refused. Every attempt is kept for the gradient, so memory grows with max_steps.

Every scheme needs each transient term linear in u_t — c(u)·u_t, or u_t inside a contraction such as τ (u·∇v)·u_t (the time derivative inside a residual-based stabilisation). A term quadratic in u_t, or u_t inside a nonlinear function, is refused: it used to be marched with (u − u_prev)²/Δt where /Δt² belonged. The u_t⊗u_t piece of a residual-based VMS Reynolds stress is such a term — drop that piece.

The exponential scheme on every element

exponential(mass="consistent") integrates the same semidiscrete system as every other scheme, exactly in time: on each element family's heat-type test problem (Lagrange P1–P3, Q1/Q2, tets, hexes, lines, vector, coupled, Hermite, cover, Morley, N1E in 2-D and 3-D) it lands within 1e-8 to 1e-10 of a tight adaptive SDIRK3, and within 7e-4 on Argyris, whose mass is too ill-conditioned for its CG mass solve.

The default mass="lumped" replaces M by its row sums: a different spatial discretisation (4e-2 off the consistent one on P1 triangles, 8e-2 on Q1 hexes), refused where the row sums are not positive (a P2 vertex, a Hermite slope, an edge DOF). symmetric=True (Lanczos) is refused on an operator that is not symmetric on its free DOFs, such as a one-way coupling between fields; pass symmetric=False. Algebraic rows other than walls (a pressure, an RT flux) are refused as before.

A trainable coefficient, network or initial condition is fine as long as the operator does not read time (a time-dependent source is): exponential() then takes the operator at the runtime values and is reverse-mode differentiable on both mass treatments, matching finite differences to 1e-9. An operator that reads time is refused. The refusals above run once when fem.solve(time=jno.solve.exponential(...)) is called, on the operator at the stored values, so they also hold inside jno.core, where the march itself is traced.

Higher order — sdirk and rosenbrock

jno.solve.sdirk(order=3) is Alexander's 3-stage, order-3 SDIRK method (order 2: 2 stages; SIAM J. Numer. Anal. 14(6), 1977). Each stage is one backward-Euler step of size γ·dt from a shifted start state, so everything the default step does carries over: Dirichlet and zero-mass rows, solver slots, Newton on a nonlinear block, the complex path. All stages share one step operator, so a constant one is built and preconditioned once. A state-dependent mass c(u)·u_t is integrated at full order in its non-conservative form.

jno.solve.rosenbrock() is linearly implicit: every stage is one linear solve with the same matrix W = M + γh·J, J the tangent at the step's start — no Newton loop on a nonlinear block. The default "ros34pw2" (Rang & Angermann, BIT 45, 2005) is order 3, stiffly accurate and consistent for index-1 DAEs; "ros2" (Verwer et al., SIAM J. Sci. Comput. 20(4), 1999) is order 2.

A time-varying Dirichlet row lands exactly on g(tₙ₊₁) under the default, which is stiffly accurate; "ros2" is not, and holds it only to its order (g = e^{-2t}: 5.3e-4 off at T = 0.5 after 16 steps, 1.4e-3 at the first step — see the measured orders). Re-imposing g after each step would make the wall exact, but was measured to leave an O(dt) error in the interior, so it is not done. Rosenbrock refuses a time-, parameter- or state-dependent mass (use sdirk or bdf2).

sol = fem.solve(time=jno.solve.sdirk(order=3))
sol = fem.solve(time=jno.solve.rosenbrock())                 # ros34pw2
sol = fem.solve(time=jno.solve.rosenbrock().adaptive(rtol=1e-4))

Both expose a stepper, so .adaptive() works, and both refuse second-order-in-time (u_tt) blocks. SDIRK and ROS34PW2 carry an embedded lower-order solution built from the same stages (order 2 for SDIRK3 and ROS34PW2, order 1 for SDIRK2), so the controller gets its error estimate without extra solves; every other base is sized by step doubling (one step against two half-steps).

A step over the tolerance is rejected and retried smaller; the step sizes are treated as constants in the gradient. The error norm leaves out index-2 rows (zero mass and a zero diagonal, the incompressibility row of a saddle problem), whose error converges an order lower: counted, they drove SDIRK3 on unsteady Stokes to the step floor. Dirichlet rows and pressure pins stay in.

On the 2-D heat test of tests/test_fem_adaptive_timestep.py at rtol=1e-5, the embedded pair needed about 40% fewer base steps than step doubling for an error no larger. On a nonlinear heat problem, ROS34PW2 reached a given accuracy in the least wall time of the schemes compared (θ, BDF2, SDIRK, ROS2). Time-to-accuracy depends on the problem, so compare on yours.

The slots configure the per-step solves of the default theta-method integrator: linear/precond see the step operator M + θ·dt·A — when it is time-independent the step matrix is formed once and the preconditioner materialized once before the time loop — and nonlinear drives each implicit step of a nonlinear block. Second-order-in-time (u_tt) flows through the same augmented block. Each step warm-starts from the previous state; the first state is the initial condition (u.initialize(u0) or u(initial) - u0).

With no linear=/precond=, a linear block's step is solved by Jacobi-BiCGStab with a GMRES rescue, except on a saddle: a row with zero mass and a zero diagonal (the incompressibility row of unsteady Stokes) gets jno.solve.lu() instead.

Jacobi has nothing to scale on those rows and the Schur complement shrinks with dt; measured on unsteady Stokes (P2/P1), the Krylov step was right at dt = 1e-3 and NaN at dt = 1e-4. A Krylov step that does not converge raises at the end of the solve, naming the step solve, instead of returning a NaN trajectory.

A constant step operator factorizes once, not once per step

The step matrix is formed once (above), and the host factorization is cached on the operator's content, so a march that solves against the same matrix every step pays one factorization for the whole trajectory — and the transpose solve reuses it, so the adjoint pass adds none.

On a 51-step heat march that is worth 1.55× of whole-solve wall clock at 8,355 DOFs and 2.9× at 23,934. The gain grows with mesh size, because factorization cost grows faster than the per-step solve; at 513 DOFs it is 1.05×, where the factorization is sub-millisecond.

What it does not help: a nonlinear march, or any Newton loop. There the tangent's values change every iteration, so every call legitimately misses and pays a content hash (~1–2% of a factorization) for nothing. Reusing only the symbolic analysis — which genuinely is constant when the sparsity pattern is fixed — is not something SuperLU exposes through scipy. It is also host-path-only: lu() on GPU goes through cuSolver's spsolve, a single fused call with no factorization object to keep.

Adjoint memory — the march is gradient-checkpointed

Reverse-mode through the default integrator rematerializes each step in the backward pass instead of storing every step's solver internals for the whole trajectory. Measured at 8,355 DOFs × 399 steps: peak memory 968 → 112 MB (8.6×) for a gradient cost of +60% (2.98 → 4.76 s), gradient identical to 10 digits. The trade is deliberate: a differentiable march OOMs long before it is time-walled on consumer cards. A pure forward solve is unaffected — checkpointing is the identity outside differentiation.