2D DNS turbulence simulator (NumPy + CuPy)
Project description
cupyturbo — 2D Turbulence Simulation (NumPy / CuPy)
cupyturbo is a small playground Direct Numerical Simulation (DNS) code for
2D Homogeneous, Incompressible Turbulence, structurally ported from a legacy FORTRAN 77 implementation.
It supports:
- NumPy for CPU runs
- CuPy (optional) for GPU acceleration on CUDA devices (e.g. RTX 3090)
The solver mirrors the original structure:
- PAO-style random-field initialization
- 3/2 de-aliasing in spectral space
- Crank–Nicolson time integration
Installation
Using uv (recommended)
From the project root:
uv sync
uv run python -m cupyturbo.dns_main
This creates a virtual environment and installs the project and its dependencies from pyproject.toml.
Using plain pip
From a cloned repo:
python -m venv .venv
source .venv/bin/activate # on Windows: .venv\Scripts\activate
pip install -e .
python -m cupyturbo.dns_main
The DNS with NumPy (256 x 256)
Full CLI
python -m cupyturbo.dns_simulator N Re K0 STEPS CFL BACKEND
Where:
- N — grid size (e.g. 256, 512)
- Re — Reynolds number (e.g. 10000)
- K0 — peak wavenumber of the energy spectrum
- STEPS — number of time steps
- CFL — target CFL number (e.g. 0.75)
- BACKEND — "cpu", "gpu", or "auto"
Examples:
# CPU run (NumPy)
python -m cupyturbo.dns_simulator 256 10000 10 1001 0.75 cpu
# Auto-select backend (GPU if CuPy + CUDA are available)
python -m cupyturbo.dns_simulator 256 10000 10 1001 0.75 auto
Enabling GPU with CuPy (CUDA 13.1)
On a CUDA machine (e.g. RTX 3090):
-
Check that the driver/CUDA are available:
nvidia-smi | head -n 3 -
Install CuPy into the uv environment:
uv sync uv pip install cupy -
Verify that CuPy sees the GPU:
uv run python -c "import cupy as cp; x = cp.arange(5); print(x, x.device)" -
Run in GPU mode:
uv run python -m cupyturbo.dns_simulator 256 10000 10 1001 0.75 gpu
Or let the backend auto-detect:
uv run python -m cupyturbo.dns_simulator 256 10000 10 1001 0.75 auto
The DNS with CuPy (4096 x 4096)
Profiling
cProfile (CPU)
python -m cProfile -o dns_simulator.prof -m cupyturbo.dns_simulator
Inspect the results:
python -m pstats dns_simulator.prof
# inside pstats:
sort time
stats 20
GUI profiling with SnakeViz
Install SnakeViz:
uv pip install snakeviz
Visualize the profile:
snakeviz dns_simulator.prof
Memory & CPU profiling with Scalene (GUI)
Install Scalene:
uv pip install scalene
Run with GUI report:
scalene -m cupyturbo.dns_simulator 256 10000 10 201 0.75 cpu
Memory & CPU profiling with Scalene (CLI only)
For a terminal-only summary:
scalene --cli --cpu -m cupyturbo.dns_simulator 256 10000 10 201 0.75 cpu
Project layout (key modules)
-
cupyturbo/dns_main.py
PyQt6 GUI viewer; displays DNS fields (U, V, ω, kinetic) in real time. -
cupyturbo/dns_simulator.py
Headless CLI DNS solver:- PAO initialization (dns_pao_host_init)
- FFT helpers (vfft_full_*)
- STEP2A, STEP2B, STEP3
- CFL-based time-step control (compute_cflm, next_dt)
-
cupyturbo/dns_wrapper.py
Thin wrapper for programmatic use.
one-liner
curl -LsSf https://astral.sh/uv/install.sh | sh
uv cache clean mannetroll-cupyturbo
uv run --python 3.13 --with mannetroll-cupyturbo==0.1.4 python -m cupyturbo.dns_main
License
Copyright © Mannetroll See the project repository for license details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mannetroll_cupyturbo-0.1.4.tar.gz.
File metadata
- Download URL: mannetroll_cupyturbo-0.1.4.tar.gz
- Upload date:
- Size: 29.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0bef7b3e42f25a475dfb4aa58ba68a94eceadcab3fae0228cedb22d82d2fe95
|
|
| MD5 |
3c6d34912d484c4c520c9adb63a7fe43
|
|
| BLAKE2b-256 |
578427034a67cfd4ee4f9c600849ff0db60031157e1c98a8181181b7c88bf304
|
File details
Details for the file mannetroll_cupyturbo-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mannetroll_cupyturbo-0.1.4-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4096ecebce35e06cf5bac51006b04adf1a570a8637385bcbef3b7fdc2a91c0ce
|
|
| MD5 |
f966606677aef7bd4cdfedfe6be9addc
|
|
| BLAKE2b-256 |
0a0ccf4004e6a841947538cdb7b16cae182312bfa752ff8905c0f84d7f3ab5e3
|