Skip to main content

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)

DNS NumPy

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):

  1. Check that the driver/CUDA are available:

    nvidia-smi | head -n 3
    
  2. Install CuPy into the uv environment:

    uv sync
    uv pip install cupy
    
  3. Verify that CuPy sees the GPU:

    uv run python -c "import cupy as cp; x = cp.arange(5); print(x, x.device)"
    
  4. 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)

DNS CuPy

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mannetroll_cupyturbo-0.1.4.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mannetroll_cupyturbo-0.1.4-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

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

Hashes for mannetroll_cupyturbo-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b0bef7b3e42f25a475dfb4aa58ba68a94eceadcab3fae0228cedb22d82d2fe95
MD5 3c6d34912d484c4c520c9adb63a7fe43
BLAKE2b-256 578427034a67cfd4ee4f9c600849ff0db60031157e1c98a8181181b7c88bf304

See more details on using hashes here.

File details

Details for the file mannetroll_cupyturbo-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for mannetroll_cupyturbo-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4096ecebce35e06cf5bac51006b04adf1a570a8637385bcbef3b7fdc2a91c0ce
MD5 f966606677aef7bd4cdfedfe6be9addc
BLAKE2b-256 0a0ccf4004e6a841947538cdb7b16cae182312bfa752ff8905c0f84d7f3ab5e3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page