dnsjax
A GPU-accelerated pseudo-spectral solver for direct numerical simulation of the 3D incompressible Navier–Stokes equations, written in JAX.
Periodic directions are pseudo-spectral (Fourier); up to one wall-bounded direction uses banded finite differences, where an influence-matrix method reconciles incompressibility with the wall boundary conditions. Five flow systems across four geometries share one stepping core, and further flows plug in without editing it. The same code works on CPUs and GPUs, and distributes across many.
The released package is the solver core along with the core geometries and flows. The GitHub repository holds far more, developed alongside the core: The lab.
Turbulent channel flow at Reτ ≈ 180: streamwise
velocity fluctuations on three wall-parallel planes (near each
wall, and at the centreline), over 10 advective time units.
🔗 See one near-wall
plane by itself.
Highlights
- Runs where JAX runs, tested on CPUs and NVIDIA GPUs — on one or
many, double or single precision, all from the same code path: a run
moves to a GPU with one install extra and one flag,
--dist.platform cuda(On a GPU). Wall-normal solves go through a custom Pallas/Triton banded-LU kernel on NVIDIA and AMD GPUs. - Measured from 1 to 64 CPU nodes — on ARCHER2 (two 64-core AMD
EPYC 7742 and 256 GB of DDR4-3200 per node), a turbulent channel at
1280 × 383 × 384runs 60 times faster on 64 nodes (8192 MPI ranks) than on one, at a parallel efficiency of 0.75 to 0.94 on every node count from 2 to 64 (figure). - Machine-precision discrete incompressibility, by default — a stepped state's divergence sits at round-off at any resolution, with less operator storage than in a primitive-variable formulation (also available as an option).
- Five flow systems across four geometries, all on one stepping core; a package of your own adds flows, parameter fields and run-loop sections through entry points, without editing the solver — as the repository's lab does, with five flows more (The lab).
- Non-modal optimal growth built on the solver itself — linear transient growth about an arbitrary wall-normal profile, reusing the solver's own linear step mode by mode.
- Post-processing that needs no solver — snapshots are ordinary tar archives wrapping a zarr3 store, and the reading API imports nothing but NumPy.
Quick start
git clone https://github.com/gokhanyalniz/dnsjax.git
cd dnsjax
uv sync
The only prerequisite is uv: uv sync
fetches the pinned Python (3.14; the floor is 3.12) and every
dependency by itself, JAX in its CPU build; a GPU needs one extra more
(On a GPU). An MPI runtime is needed only to launch
several processes, which every multi-CPU run does — not for a single
process that drives all of one node's GPUs, and not for the
post-processing API. Multi-CPU runs should also let MPI carry their
collectives: docs/cpu-collectives.md.
Output goes to the working directory, so launch from a scratch dir:
mkdir -p /tmp/run && cd /tmp/run
/path/to/dnsjax/.venv/bin/dnsjax \
--phys.system pipe --phys.re 2500 --geo.lz 8 \
--phys.driving constant_bulk_velocity \
--res.nz 24 --res.nr 32 --res.ntheta 32 \
--init.localized_rolls True \
--init.localized_rolls_amplitude 0.3 --init.localized_rolls_width 1.5 \
--step.dt 0.01 --stop.max_sim_time 200 \
--outs.it_stats 50
Four diameters of pipe at Re = 2500, seeded with a localized roll that
breaks down into turbulence, which in a cell this short is transient
and decays again — a few minutes on one core of a modern CPU. The first
step takes noticeably longer than the rest (JIT compilation);
statistics then stream to stats.dat. The same run as a configuration
file is
examples/pipe-re2500/parameters.toml.
examples/ has three more — plane-Poiseuille,
plane-Couette and Kolmogorov flow (sinusoidally driven flow in a
triply-periodic box) — each small enough to run easily on one core of a
modern laptop.
dnsjax --help lists the global parameters and the flows, --help pipe
one flow's full surface (replace pipe for other flows), and
--sample-toml pipe prints an annotated template. For a walkthrough of
more flags, the four start modes (from a snapshot file, a random
perturbation of the laminar flow, localized rolls, and the laminar flow
itself), and the output streams, see
docs/running.md.
On a GPU
One install extra and one flag. Sync JAX's CUDA build in place of
its CPU one, then add --dist.platform cuda to any run; nothing else
changes. The pipe above, from its configuration file:
cd /path/to/dnsjax && uv sync --extra cuda13
mkdir -p /tmp/run-gpu && cd /tmp/run-gpu
cp /path/to/dnsjax/examples/pipe-re2500/parameters.toml .
/path/to/dnsjax/.venv/bin/dnsjax --dist.platform cuda
From PyPI the install is pip install "dnsjax[cuda13]" or
uv add "dnsjax[cuda13]". The extras are JAX's own, one per
environment, as its installation guide defines them: cuda12, cuda13, cuda12-local, cuda13-local
(the -local pair uses the CUDA already installed), rocm7-local,
oneapi, tpu and cpu. --dist.platform then names the backend:
cuda for an NVIDIA GPU, rocm for an AMD GPU, oneapi for an Intel
GPU and tpu for a Google Cloud TPU, with cpu the default.
Flows and geometries
| Flow | Geometry | Laminar base / driving | Defining controls |
|---|---|---|---|
| Pipe | cylindrical | U_z = 1 - r², pressure-driven |
re, axial length lz |
| Taylor–Couette | annular | U_θ = A_0 r + B_0/r, wall rotation |
re1, re2, eta, lz |
| Plane-Poiseuille | Cartesian | U = 1 - y², pressure-driven |
re, lx, lz, tilt_degree |
| Plane-Couette | Cartesian | U = y, wall-driven |
re, lx, lz, tilt_degree |
| Kolmogorov | triply-periodic | U = sin(2π y / L_y), sine body force |
re, lx, lz, tilt_degree |
Each flow exposes only the parameters that apply to it, under the names
natural to its geometry: a pipe takes
--geo.lz/--res.nz/--res.nr/--res.ntheta where a plane channel
takes --geo.lx/--res.nx/--res.ny/--res.nz (the pipe's nz is
axial, the channel's spanwise). For the various conventions involved,
see
Conventions.
The repository's lab adds five flows on the same geometries, installed
by the same uv sync and run the same way (The lab).
Parallelization
One time step: the spectral state is inverse-transformed onto the
3/2-oversampled grid (which dealiases the quadratic
nonlinearity), the rotational nonlinear term is formed pointwise, and
the result is transformed back and truncated. Two reshards carry the
data across the device grid each way. By default, a semi-implicit
predictor is then corrected toward the Crank–Nicolson fixed point, each
iteration solving a few small banded systems per Fourier mode. Every
device holds the full wall-normal extent in spectral space, so those
solves need no communication at all.
The two sharded axes are not equivalent: the np1 exchange moves
3/2 as many bytes as the np0 one, and a second grid axis adds an
exchange rather than subdividing the first, so the choice of device grid
is not trivial. docs/scaling.md has the array layout
per geometry, a symbolic memory model linear in n_x n_y n_z that sizes
a configuration before it is launched, and how to pick the device grid
(n_p0, n_p1) on one node and across many.
The tools behind those numbers — a layout and strong-scaling sweep driver, a per-rank memory budget from XLA's buffer assignment, a per-node memory sampler and GPU profiles of the banded solve — are the lab's: performance scripts.
Strong scaling of a turbulent channel at 1280 × 383 × 384 on ARCHER2, from 1 to 64 nodes (128 to 8192 MPI ranks, one per core), against the fastest one-node run; each point is the mean of all its runs, two to four, its bar their range. A node: two 64-core AMD EPYC 7742 (Zen 2, 2.25 GHz nominal, run at 2.0) with 256 GB of DDR4-3200 over eight channels per socket, Infinity Fabric within a socket and three xGMI links between the two, and HPE Slingshot between nodes, as the site documented them on 7 October 2026.
Every run reproduces the same trajectory to round-off. The efficiency's
rise after 16 nodes is a per-rank speed-up, not the network's: one node
shows it too when each of its ranks holds the same share of the problem.
docs/scaling.md has the
machine, the method, the tables and that breakdown.
Validation
The optimal-growth module reproduces published values for all four of
its flows to about 2 % or better, and the rest of the suite pins the
discrete divergence, the energy budget, the temporal order, the banded
kernel against the pure-JAX sweep and a dense reference, and the
analysis API against the solver's own operators. Every claim is mapped
to the test that backs it in docs/validation.md.
The lab's flows and tools have a page of their own,
lab/docs/validation.md.
Design decisions
- Banded finite differences in the wall-normal direction, not Chebyshev. A Chebyshev basis fixes a Chebyshev–Gauss–Lobatto (CGL) grid for the wall-normal direction, whereas finite differences leave the grid free, which is especially helpful for large-Re studies. CGL is still the default, stretched tanh grids are built in, and arbitrary grids are also supported.
- Velocity–vorticity (internally), not primitive variables. Advancing the wall-normal velocity and vorticity and reconstructing the tangential pair removes the discrete pressure entirely. Continuity is then an algebraic identity, instead of a convergent truncation error. User-facing arrays are always velocity components. A primitive-variable-based stepping is optionally provided.
- Influence matrix, not a projection. One wall condition can only be
fixed indirectly: the wall pressure in the primitive form, and
(D_1 v)|_wall = 0in the velocity–vorticity one. Precomputing the homogeneous responses once turns that into a1×1or2×2per-mode solve. Tangential no-slip is then exact as a consequence rather than a separately imposed condition — which is why the wall values ofuandwdouble as a live diagnostic that the influence matrix is healthy. A fractional-step projection avoids all of it at the cost of a splitting error no resolution removes. - Two sharded axes, deliberately asymmetric. The linear wall-normal solves stay simple and communication-free only while the wall-normal data are device-local. The device mesh is built around that first; keeping data transposes to a minimum comes second.
- Tests as standalone scripts. Configuration lives in module-level
singletons captured at import, and JAX's platform and precision are
process-wide, so a test has to own its process: each runs as its own
script, and
pytestcollects them through a subprocess bridge. - JAX rather than CUDA or Fortran kernels. One source targets CPU, GPU and Google Cloud TPU and shards across devices without a second implementation. Where standard JAX is not enough, such as for the wall-normal banded sweep, a Pallas kernel is used under the same API.
What's in the box
| Banded-LU GPU kernel | O(N_y p) factors instead of dense O(N_y²), with a dense reference solver; checked in interpret mode and by lowering to CUDA on GPU-less machines |
| Differentiable time steps | jax.grad through a step, opt-in: a fixed-count corrector replaces the one construct reverse mode cannot traverse, and the banded GPU kernel carries a custom adjoint — docs/differentiability.md |
| Optimal-growth analysis | linear optimal energy growth G(t) about an arbitrary wall-normal profile, reusing the solver's own linear step per mode — docs/validation.md |
| Two-axis device mesh | (n_p0, n_p1) with an in-FFT reshard pipeline — docs/scaling.md |
| A memory–throughput dial | solver.rhs_transform_chunks splits the batched inverse transform k ways, cutting its working set k-fold at identical results |
| Snapshots and resume | tar + zarr3, written by every device in parallel; resume across any device count, re-gridding every changed axis — docs/snapshots.md |
| Reduced-resolution snapshots | on a cadence of their own: Fourier axes truncated, the wall-normal axis interpolated, every field computed at full resolution first, optionally with the static pressure on the plane channels — docs/running.md |
| External-data import | pack a field produced elsewhere into a valid snapshot — docs/snapshots.md |
| Initial conditions | divergence-free random fields and deterministic localized spots, reproducible independent of device count |
| Adaptive CFL stepping | re-selects Δ t and rebuilds the implicit operators on device with no recompilation |
| Moving frame | integrate in a translating frame, implicitly in both time schemes |
| Crash-consistent diagnostics | buffered streams flushed before snapshots and on termination; a NaN or inf aborts naming the quantity and writes no snapshot of the broken state |
| Graceful shutdown | an ISO 8601 wall-time budget ends the run cleanly, final snapshot included, before a queue kills it |
| Laminarization auto-stop | a run ends once the perturbation energy falls below a threshold |
| In the lab | five further flows (a curved pipe, quasi-Keplerian Taylor–Couette, Dean, and viscoelastic pipe and Dean) and the performance and diagnostic tools — The lab |
Documentation
| file | what it covers |
|---|---|
docs/numerics.md |
equations, discretization, wall-normal grids, the influence-matrix method, per-flow conventions |
docs/scaling.md |
array layout, the memory model, choosing the device grid, measured strong scaling |
docs/running.md |
a worked run, start modes, seeds, the moving frame, every output stream |
docs/configuration.md |
how the parameter layers combine; extension sections; where each field is documented |
docs/snapshots.md |
the snapshot format, resume and re-gridding, the JAX-free API, the importer |
docs/validation.md |
what is checked against what, and which test pins each claim |
docs/differentiability.md |
what differentiates through a step, the two opt-in knobs, the banded solve's adjoint |
docs/extending.md |
adding a flow system, in this package or from your own |
docs/cpu-collectives.md |
routing multi-process CPU collectives through MPI |
tests/README.md |
how the suite is laid out and how to run it |
scripts/README.md |
the offline tools: figures, a snapshot perturbation, wall-normal resolution |
CONTRIBUTING.md |
setup, lint, tests, adding a flow, commit style |
lab/README.md |
the lab: its flows, scripts and tests |
lab/docs/numerics.md |
the lab flows' equations and conventions |
lab/docs/validation.md |
what the lab's flows and tools are checked against |
Testing
41 standalone scripts under tests/, run directly
(uv run python tests/test_cartesian.py) or through a pytest bridge that
shells each one out as a subprocess. They pin the solvers and operators
against independent constructions; the physics (laminar fixed points at
machine precision, the full nonlinear path for every distinct stepping
machinery, second-order temporal convergence, energy-budget closure); the
machinery (snapshot round-trips, device-count-agnostic resume, the
JAX-free import guarantee); and the published optimal-growth values.
Several launch real mpirun multi-device runs; none needs a GPU. See
tests/README.md. The lab's suite adds 36 scripts of
its own, collected by the same pytest
(lab/README.md).
Extending
Adding a flow system on an existing geometry is a two-file operation: a
FlowSpec and the flow module it names — in this package, under
src/dnsjax/flows/<family>/specs/, or in a package of your own that
registers its specs through the dnsjax.flows entry point — and
nothing else is edited: the surfaces, the dispatch and the analysis
geometry sets all derive from the registry. A flow with a metric of its
own adds a geometry module as well, and parameter fields and run-loop
sections plug in the same way:
docs/extending.md. The lab's five flows are the
worked example: one has a metric of its own, and they bring parameter
fields of their own (lab/README.md).
Limitations
- Tested on CPUs and NVIDIA GPUs. The code paths are
backend-agnostic and the solver accepts
cuda,rocm,oneapiandtpualike, but only CPU and CUDA are exercised regularly; AMD (ROCm) has had minimal testing, and Intel GPUs (oneAPI) and Google Cloud TPUs none at all. The banded kernel's adjoint has its numerics checked in interpret mode and is lowered for CUDA, but reverse mode through it has not yet been run on a GPU. - No banded-LU kernel on Intel GPUs or Google Cloud TPUs. The
kernel is written for Pallas's Triton backend, which JAX (0.11.2)
lowers for CUDA and ROCm only; a TPU lowers Pallas through Mosaic
instead. A wall-bounded run on
oneapiortputherefore takes the portable pure-JAX sweep, andsolver.pallas_kernel = trueis refused there. - One wall-bounded direction. The discretization admits at most one non-periodic direction.
- CPU collectives over MPI are untested on macOS, where the library search cannot fire — docs/cpu-collectives.md.
References
The numerics follow these references:
- A. P. Willis, The Openpipeflow Navier–Stokes solver, SoftwareX 6,
124–127 (2017). Predictor–corrector time stepping and the decoupled
u_±pipe/annular formulation. - S. A. Orszag, On the elimination of aliasing in finite-difference schemes by filtering high-wavenumber components, J. Atmos. Sci. 28(6), 1074 (1971). The 3/2 dealiasing rule.
- C. Canuto, M. Y. Hussaini, A. Quarteroni and T. A. Zang, Spectral Methods in Fluid Dynamics, Springer (1988). Pseudo-spectral methods, and the continuity argument behind the influence-matrix method.
- L. Kleiser and U. Schumann, Treatment of incompressibility and boundary conditions in 3-D numerical spectral simulations of plane channel flows, in Proc. 3rd GAMM Conference on Numerical Methods in Fluid Mechanics, 165–173, Vieweg (1980). The influence-matrix method.
- J. Kim, P. Moin and R. Moser, Turbulence statistics in fully developed channel flow at low Reynolds number, J. Fluid Mech. 177, 133–166 (1987). The wall-normal velocity–vorticity formulation, and the split of its fourth-order equation into two second-order solves.
- B. Fornberg, Calculation of weights in finite difference formulas, SIAM Review 40(3), 685–691 (1998). Finite-difference weights on non-uniform grids.
- L. N. Trefethen, Spectral Methods in MATLAB, SIAM (2000). Clenshaw–Curtis quadrature and spectral differentiation.
The lab
This repository also holds lab/, a second package
of flows and features in development alongside the solver, not shipped
with its release archives outside GitHub. It plugs into the solver
through the same entry points a package of your own would use, and
uv sync installs both into one environment. What it adds:
- Five flows on the solver's geometries — the curved pipe,
quasi-Keplerian Taylor–Couette, Dean, and the viscoelastic pipe and
Dean —
lab/README.md, their equations inlab/docs/numerics.mdand their checks inlab/docs/validation.md. - Scripts: the performance tools (benchmarks, profiles, memory
sizing, the scaling figure) and functionality checks
(differentiability, GPU kernel and storage diagnostics) —
lab/README.md. - Tests: 36 scripts of its own, collected by the same
pytest—lab/README.md.
Its own limitations: lab/README.md.
License and citation
Released under the Apache License 2.0, © 2025–2026 Gökhan Yalnız.
If dnsjax supports your work, a citation of this repository
(https://github.com/gokhanyalniz/dnsjax) is appreciated.
Use of AI
The first version of this solver — the triply-periodic geometry, the predictor–corrector stepper, and the Kolmogorov flow — was designed and written by hand. The extension to the wall-bounded geometries grew out of that core with extensive use of LLM coding assistants.
None of the mathematics here is new: the predictor–corrector stepping, the influence-matrix treatment of the wall conditions, the Fornberg finite-difference weights, the 3/2 dealiasing rule and the rest are long established. What is mine is the selection and the assembly — which formulation to use where, and how the pieces have to fit together to make one solver rather than a collection of methods — together with the strategy for deciding whether the result is right: a dense reference solver to check the fast path against, per-geometry operators checked against independent constructions, and published values to land on. Every assisted change was planned, reviewed and iterated on against that.
Metadata
Release files for dnsjax 0.1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dnsjax-0.1.0.1.tar.gz | 3.5 MB | With provenance | Details for dnsjax-0.1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dnsjax-0.1.0.1-py3-none-any.whl | Python 3 | none | any | Details for dnsjax-0.1.0.1-py3-none-any.whl |
Total release size: 4.0 MB
Release files / dnsjax-0.1.0.1.tar.gz
| Download URL | dnsjax-0.1.0.1.tar.gz |
|---|---|
| Size | 3.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6bf34d62b2e628608f7cab058a691f59b3872dd02a66332976a95120a0bc646
|
|
BLAKE2b-256 checksum How to use checksums |
bb05dbaaef26695709d653f51033e8fee4f20a9261be6aee0c341ea99ca85a8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logRelease files / dnsjax-0.1.0.1-py3-none-any.whl
| Download URL | dnsjax-0.1.0.1-py3-none-any.whl |
|---|---|
| Size | 515.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c6cca1839253b3763284e1e4a8eb970146255deedbd63f8407e8c68cc4c6ae4
|
|
BLAKE2b-256 checksum How to use checksums |
f30cb63b4d1d369cc0ce8d265e5aa82e18daa80923b9ba9c71b466bc65af3c23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logSecurity for dnsjax 0.1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for dnsjax-0.1.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.