SwiftHohenberg¶
Systems / ODEs / Spatial fields
The prototype pattern-forming PDE — stripes and hexagons from a single scalar field near a finite-wavelength instability.
Start here¶
import tsdynamics as ts
system = ts.systems.SwiftHohenberg()
traj = system.run(final_time=50.0, dt=0.1, seed=0)
ts.plot(traj)
traj.t contains the sample times and traj.y the state array; system.info shows the defaults. In a notebook the last line displays the plot. In a Python script, call .show() on it to open a window, or .save("trajectory.svg") to export it.
With an adaptive ODE solver, dt sets the output spacing; rtol and atol control local integration error. For a fixed-step solver, reduce dt to check numerical convergence.
Illustration: N=64 · r=0.4 · simulation window: 30–100 · forward/reverse playback
This finite simulation illustrates one initial condition and view. The diagnostics below report their own inputs and observation windows.
Dynamics at the default parameters¶
Lyapunov exponents measure separation rates along an orbit. The Kaplan–Yorke dimension is derived from those rates, not a direct geometric measurement. Finite runs depend on the initial condition, transient and observation window; a value near zero needs a convergence check.
+ per-cell nonlinear terms (over the 1024-cell field)
Method and evidence
+ per-cell nonlinear terms (over the 1024-cell field)
Recorded parameters and software
{
"parameters": {
"N": 32,
"L": 40.0,
"r": 0.3
},
"parameter_expressions": {},
"state_dimension": 1024,
"explicit_time": false,
"library_version": "6.0.3",
"python": "3.14.8",
"numpy": "2.4.4",
"scipy": "1.17.1",
"protocol_version": 1
}Definition¶
@staticmethod
def _equations(Y, t, *, N, L, r):
h = L / N
inv_h2 = 1.0 / (h * h)
inv_h4 = inv_h2 * inv_h2
def idx(rr, cc):
return (rr % N) * N + (cc % N)
rhs = []
for rr in range(N):
for cc in range(N):
def u(dr, dc, rr=rr, cc=cc):
return Y(idx(rr + dr, cc + dc))
u0 = u(0, 0)
lap = (u(1, 0) + u(-1, 0) + u(0, 1) + u(0, -1) - 4 * u0) * inv_h2
# Compact 13-point biharmonic (∇⁴) stencil on a periodic grid.
bih = (
20 * u0
- 8 * (u(1, 0) + u(-1, 0) + u(0, 1) + u(0, -1))
+ 2 * (u(1, 1) + u(1, -1) + u(-1, 1) + u(-1, -1))
+ (u(2, 0) + u(-2, 0) + u(0, 2) + u(0, -2))
) * inv_h4
# u_t = r u - (1 + ∇²)² u - u³ = r u - (u + 2 ∇²u + ∇⁴u) - u³
rhs.append(r * u0 - (u0 + 2.0 * lap + bih) - u0 * u0 * u0)
return rhs
Parameters¶
| Symbol | Default | Role |
|---|---|---|
N |
32 |
grid points per side (structural — changing it recompiles) |
L |
40 |
domain length per side |
r |
0.3 |
linear growth control (unstable bandwidth) |
Explore further¶
- Lyapunov spectra and Kaplan–Yorke dimension — measure separation rates, then check convergence with a longer run.
- Fixed points and stability — find the equilibria or fixed points that organize the dynamics.
- Plotting and export — choose components, style a figure, or save it for a paper.
- Find a compatible analysis with
ts.analysis.find(system)orts.analysis.find(traj).
Reference¶
Swift & Hohenberg (1977), Phys. Rev. A 15, 319-328
doi:10.1103/physreva.15.319