View in NBViewer Open in binder Download notebook View source


8.3. Stochastic and random forcing

The package also handles a forcing with a random component, for the equation

\[ \mathrm{d}\mathbf{u} + \left(\mathbf{u}\cdot\nabla\mathbf{u} + \nabla p\right)\mathrm{d}t = \nu\Delta\mathbf{u}\,\mathrm{d}t + \mathbf{f}\,\mathrm{d}t + N_t\,\mathrm{d}t + \sigma\Phi\,\mathrm{d}W_t, \qquad \nabla\cdot\mathbf{u} = 0, \]

where \(\mathbf{f}\) is a steady forcing, as before, \(W_t\) is an \(n\)-dimensional Wiener process, \(\Phi : \mathbb{R}^n \to H\) maps it onto divergence-free velocity fields (the modes forced stochastically), and \(N_t\) is an arbitrary stochastic process with values in \(H\), such as an Ornstein-Uhlenbeck process, a compound Poisson process, or the output of an embedded low-dimensional chaotic system. Each term may be absent. In vorticity form, the curls of these terms are added to the equation.

With a stochastic forcing, problems are built with kind = :sde, for the solvers of StochasticDiffEq.jl (e.g. EM(), SRA1(), SOSRA()), or integrated with the fixed-step schemes of the package: StochasticETDRK4(), StochasticExpEuler() and SplitStochasticRK(:rk4) or SplitStochasticRK(:ssprk3). A random forcing alone is a time-dependent forcing, and the problem can be solved with any of the deterministic methods of the previous pages.

Packages

using NSEPeriodic2D
using OrdinaryDiffEq: Tsit5
using Plots
using Printf
using Random: Xoshiro

plotfield(grid, f; kwargs...) = heatmap(grid.x, grid.y, permutedims(f);
    aspect_ratio = 1, xlims = (0, grid.Lx), ylims = (0, grid.Ly), xlabel = "x", ylabel = "y",
    color = :balance, clims = (-1, 1) .* maximum(abs, f), titlefont = 10, kwargs...)
nothing

A flow driven by an additive noise

A \(64 \times 64\) grid, viscosity \(\nu = 10^{-2}\), and a white-in-time forcing on all the modes with \(3 \leq |\boldsymbol{\kappa}| \leq 5\), with energy injection rate \(\varepsilon = 0.1\) and no deterministic forcing:

grid = Grid(Lx = 2π, Nx = 64)
modes = fourier_modes(grid, 3, 5)
ε = 0.1
noise = AdditiveNoise(modes; σ = sqrt(2ε / length(modes)))
AdditiveNoise(σ = 0.05976143046671969, 56 modes, ε = 0.1)
model = NSEModel(grid; ν = 1e-2, noise)
NSEModel(ν = 0.01, Grid(Lx = 6.283185307179586, Ly = 6.283185307179586, Nx = 64, Ny = 64, retained |κx| ≤ 21.0, |κy| ≤ 21.0), AdditiveNoise(σ = 0.05976143046671969, 56 modes, ε = 0.1))

Starting from rest, we integrate with the stochastic ETDRK4 scheme, with a fixed step:

prob = NSEProblem(model, zeros(grid.Nx, grid.Ny), (0.0, 400.0); kind = :sde)
res = simulate(prob, StochasticETDRK4(); dt = 0.01, save_every = 0.5, seed = 2026)
SimulationResult(Success, 800 samples in [0.5, 400.0], wall time 7.13 s)
plot(res.t, [res.energy res.enstrophy], xlabel = "t", label = ["E" "Z"],
    title = "Energy and enstrophy, driven by the noise", titlefont = 10)

In a statistically steady state, the mean energy and enstrophy budgets close exactly: \(2\nu\langle Z\rangle = \varepsilon\) and \(2\nu\langle P\rangle = \eta\), with \(Z\) the enstrophy and \(P\) the palinstrophy. This holds for any flow, chaotic or not, so it is a check of a numerical method that does not depend on the trajectory. After the transient, over this short window, the ratios below should be within a few percent of 1, the size of the sampling error (they change from one build of this page to another); see the comparison of methods at the end for longer runs:

s = res.t .> 150
@printf("2ν⟨Z⟩/ε = %.3f,   2ν⟨P⟩/η = %.3f\n", 2 * model.ν * sum(res.enstrophy[s]) / count(s) / ε,
    2 * model.ν * sum(res.palinstrophy[s]) / count(s) / enstrophy_injection_rate(noise))
2ν⟨Z⟩/ε = 1.007,   2ν⟨P⟩/η = 1.017
plotfield(grid, vorticity(model, res.w_hat_final); title = "vorticity at t = 400")

Random forcing: Ornstein-Uhlenbeck, compound Poisson, and a chaotic process

Now a random forcing on the four modes with wavenumbers \((1, 2)\) and \((2, 1)\), driven by three kinds of processes, with no noise:

rmodes = fourier_modes(grid, [(1, 2), (2, 1)])
tspan = (0.0, 200.0)

ou = ou_path(4, tspan; θ = 0.5, s = 0.3, dt = 0.01, rng = Xoshiro(1))
cp = compound_poisson_path(4, tspan; rate = 0.2, θ = 0.2, jump = rng -> 0.3randn(rng), rng = Xoshiro(2))
lz = lorenz_path(tspan; timescale = 5.0, scale = 0.3)
lz4(t) = (x = lz(t); [x[1], x[2], x[3], 0.0])
nothing
ts = 0:0.1:200
plot(
    plot(ts, reduce(hcat, [copy(ou(t)) for t in ts])', label = false, title = "Ornstein-Uhlenbeck", titlefont = 10),
    plot(ts, reduce(hcat, [copy(cp(t)) for t in ts])', label = false, title = "compound Poisson, with decay", titlefont = 10),
    plot(ts, reduce(hcat, [lz4(t) for t in ts])', label = false, title = "Lorenz-63", titlefont = 10, xlabel = "t"),
    layout = (3, 1), size = (700, 600)
)

A random forcing alone is a time-dependent forcing, so the deterministic solvers apply, path by path; for the compound Poisson process, with jumps, we give the jump times to the adaptive solver as tstops:

runs = map([("Ornstein-Uhlenbeck", ou, (;)), ("compound Poisson", cp, (; tstops = jump_times(cp))), ("Lorenz-63", lz4, (;))]) do (name, η, kw)
    m = NSEModel(grid; ν = 1e-2, random_forcing = RandomForcing(rmodes, η))
    name => simulate(NSEProblem(m, zeros(grid.Nx, grid.Ny), tspan), Tsit5(); reltol = 1e-6, abstol = 1e-9,
        save_every = 0.5, spectrum = false, kw...)
end
plot([r.t for (_, r) in runs], [r.energy for (_, r) in runs], label = permutedims(first.(runs)),
    xlabel = "t", ylabel = "E", title = "Energy of flows driven by random forcings", titlefont = 10)

Both terms can be combined, with the stochastic schemes: here, the noise of the first example together with the Ornstein-Uhlenbeck forcing:

model2 = NSEModel(grid; ν = 1e-2, noise, random_forcing = RandomForcing(rmodes, ou))
res2 = simulate(NSEProblem(model2, zeros(grid.Nx, grid.Ny), tspan; kind = :sde), StochasticETDRK4();
    dt = 0.01, save_every = 0.5, seed = 7)
plot(res2.t, res2.energy, xlabel = "t", label = "E", title = "Noise and Ornstein-Uhlenbeck forcing", titlefont = 10)

Comparison of methods

To compare the methods, we use the flow of the first example (noise on the modes with \(3 \leq |\boldsymbol{\kappa}| \leq 5\), \(\varepsilon = 0.1\), \(\nu = 10^{-2}\), \(64 \times 64\)) and the exact budgets \(2\nu\langle Z\rangle = \varepsilon\) and \(2\nu\langle P\rangle = \eta\) as references. Each method starts from the same state, at \(t = 600\) after a warm-up from rest with the stochastic ETDRK4 scheme, and runs for 2000 time units, with independent noise. The tables give the relative imbalances \(2\nu\langle Z\rangle/\varepsilon - 1\) and \(2\nu\langle P\rangle/\eta - 1\) (corrected for the change of \(E\) and \(Z\) over the run), with 95% confidence intervals from 10 batch means, the time-averaged energy, the maximum CFL number for the fixed-step methods (with \(k_{\max} = 21\)) and the cost. These results were obtained once, on a 4-core Linux container, with each run single-threaded and four runs at a time, and are static: the code that produced them is in the folder benchmarks/stochastic/ of the repository. The timings are indicative only. In the pilot run, the flow was statistically steady after about 150 time units, with \(\max(|u| + |v|) \approx 8\) and \(\kappa_\sigma \approx 4.1\).

Methoddt or toleranceStatusMax CFLEnergy balance 2ν⟨Z⟩/ε - 1Enstrophy balance 2ν⟨P⟩/η - 1⟨E⟩Nonlinear evaluations per time unitSteps per time unitWall time per time unit (s)
Stochastic ETDRK4dt = 0.025stable4.43+0.005 ± 0.011+0.003 ± 0.0122.261160400.0104
Stochastic ETDRK4dt = 0.02stable3.71+0.007 ± 0.012+0.006 ± 0.0132.272200500.0121
Stochastic ETDRK4dt = 0.01stable1.83+0.002 ± 0.013+0.002 ± 0.0122.2804001000.0234
Stochastic ETDRK4dt = 0.005stable0.92-0.004 ± 0.012-0.005 ± 0.0122.2478002000.0485
Split RK4dt = 0.025stable4.39-0.007 ± 0.013-0.006 ± 0.0132.222160400.0116
Split RK4dt = 0.02stable3.48-0.004 ± 0.019-0.003 ± 0.0192.253200500.0130
Split RK4dt = 0.01stable1.72+0.000 ± 0.019-0.002 ± 0.0152.2664001000.0252
Split RK4dt = 0.005stable0.93+0.001 ± 0.014-0.003 ± 0.0152.2528002000.0522
Split SSPRK3dt = 0.025blew up at t = 602–––––––
Split SSPRK3dt = 0.02stable3.49+0.003 ± 0.011+0.002 ± 0.0132.295150500.0105
Split SSPRK3dt = 0.01stable1.78-0.010 ± 0.011-0.005 ± 0.0092.2293001000.0209
Split SSPRK3dt = 0.005stable0.89-0.004 ± 0.011-0.001 ± 0.0142.2696002000.0415
Stochastic exponential Eulerdt = 0.002blew up at t = 658–––––––
Stochastic exponential Eulerdt = 0.001stable0.19+0.033 ± 0.009+0.052 ± 0.0102.362100010000.0888
Stochastic exponential Eulerdt = 0.0005stable0.09+0.002 ± 0.011+0.015 ± 0.0102.266200020000.1816
Euler-Maruyamadt = 0.001stable0.18+0.045 ± 0.012+0.064 ± 0.0102.377100010000.0565
Euler-Maruyamadt = 0.0005stable0.09+0.023 ± 0.011+0.032 ± 0.0112.352200020000.1114
SRA1tol = 1.0stable–-0.005 ± 0.015-0.005 ± 0.0162.240–960.0132
SRA1tol = 0.1stable–+0.000 ± 0.013-0.002 ± 0.0112.281–16320.1977
SOSRAtol = 1.0stable–+0.008 ± 0.010+0.008 ± 0.0082.287–1580.0281

For the adaptive methods of StochasticDiffEq, tol is reltol = abstol. Their solver statistics do not count the evaluations of the drift, so only the steps are given.

Energy balance

Enstrophy balance

Discussion

Recommendation. For advection-dominated flows driven by additive noise, the stochastic ETDRK4 scheme (or the split RK4 scheme) with a fixed step chosen from the CFL condition, as in 7.5. Time stepping for weakly turbulent flows, with \(\sigma \approx 2\) to \(3\) relative to the largest velocities. The stochastic ETDRK4 scheme also integrates the viscous term exactly, so it handles stiff viscous terms as well. Euler-Maruyama and the stochastic exponential Euler scheme should be avoided for such flows. The comparison is for a single configuration, and differences in the statistics smaller than about 1% cannot be detected with these runs.



Last modified: November 21, 2026. Built with Franklin.jl, using the Book Template.