solve_navier_stokes_2d
Solve 2D incompressible Navier-Stokes with periodic boundaries via FFT spectral method and RK2. Input initial vorticity, viscosity, grid, and time span.
Instructions
Solve 2D incompressible Navier-Stokes on [0, 2*pi]^2 with periodic boundaries.
Vorticity-streamfunction form: ``omega_t + u*omega_x + v*omega_y =
nu*laplacian(omega)``, with ``laplacian(psi) = -omega``, ``u = psi_y``,
``v = -psi_x``. The Poisson solve and all spatial derivatives use FFT
(Fourier spectral method); time integration is explicit RK2 (midpoint).
``initial_vorticity`` is a sympy expression in x and y (no Python eval).
The grid is periodic with ``nx`` x ``ny`` points and spacing
``2*pi/nx``, ``2*pi/ny``. Before stepping, the tool requires
``nu*dt/dx^2 <= 0.5`` and ``max|u|*dt/dx <= 0.5`` (``dx`` = smaller
spacing, ``dt = t_end/nt``); otherwise it returns ``err`` and asks for a
larger ``nt``. ``nx``/``ny`` are limited to 8..256 with
``nx*ny <= 65536``, and ``nt <= 100000``.
The full (t, y, x) vorticity history, grid and energy/enstrophy series are
saved to .npz. Returned arrays are downsampled to at most 50 x 50 spatial
points and 20 time levels. This is not a general CFD solver.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nt | No | ||
| nu | Yes | ||
| nx | No | ||
| ny | No | ||
| t_end | No | ||
| initial_vorticity | No | -2*sin(x)*sin(y) |