Skip to main content

2D Turbulence (SciPy + CuPy)

Project description

cupyxturbo — 2D Turbulence Simulation (SciPy / CuPy)

scipyturbo is a Direct Numerical Simulation (DNS) code for 2D Homogeneous Turbulence

It supports:

  • SciPy for CPU runs
  • CuPy (optional) for GPU acceleration on CUDA devices (e.g. RTX 3090)

The solver contains:

  • PAO-style random-field initialization
  • 3/2 de-aliasing in spectral space
  • Crank–Nicolson time integration
  • CFL-based adaptive time-stepping

Installation

Using uv

From the project root:

$ uv sync
$ uv run python -m scipyturbo.turbo_main

The DNS with SciPy (384 x 384)

SciPy

Full CLI

$ python -m scipyturbo.turbo_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 (SciPy with 4 workers)
$ python -m scipyturbo.turbo_simulator 256 10000 10 1001 0.75 cpu

# Auto-select backend (GPU if CuPy + CUDA are available)
$ python -m scipyturbo.turbo_simulator 256 10000 10 1001 0.75 auto

Enabling GPU with CuPy (CUDA 13)

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 scipyturbo.turbo_simulator 256 10000 10 1001 0.75 gpu
    

Or let the backend auto-detect:

   $ uv run python -m scipyturbo.turbo_simulator 256 10000 10 1001 0.75 auto

The DNS with CuPy (4096 x 4096)

CuPy

Profiling

cProfile (CPU)

$ python -m cProfile -o turbo_simulator.prof -m scipyturbo.turbo_simulator    

Inspect the results:

$ python -m pstats turbo_simulator.prof
# inside pstats:
turbo_simulator.prof% sort time
turbo_simulator.prof% stats 20

GUI profiling with SnakeViz

Install SnakeViz:

$ uv pip install snakeviz

Visualize the profile:

$ snakeviz turbo_simulator.prof

Memory & CPU profiling with Scalene (GUI)

Install Scalene:

$ uv pip install scalene

Run with GUI report:

$ scalene -m scipyturbo.turbo_simulator 256 10000 10 201 0.75 cpu

Memory & CPU profiling with Scalene (CLI only)

For a terminal-only summary:

$ scalene --cli --cpu -m scipyturbo.turbo_simulator 256 10000 10 201 0.75 cpu

Project layout (key modules)

  • scipyturbo/turbo_main.py
    PyQt6 GUI viewer; displays DNS fields (U, V, ω, kinetic) in real time.

  • scipyturbo/turbo_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)
  • scipyturbo/turbo_wrapper.py
    Thin wrapper for programmatic use.

one-liner

$ curl -LsSf https://astral.sh/uv/install.sh | sh
$ uv cache clean mannetroll-cupyxturbo
$ uv run --python 3.13 --with mannetroll-cupyxturbo==0.1.0 python -m scipyturbo.turbo_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_cupyxturbo-0.1.0.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

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

mannetroll_cupyxturbo-0.1.0-py3-none-any.whl (1.5 MB view details)

Uploaded Python 3

File details

Details for the file mannetroll_cupyxturbo-0.1.0.tar.gz.

File metadata

  • Download URL: mannetroll_cupyxturbo-0.1.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for mannetroll_cupyxturbo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c473362efb3c7256b420ce38a6ecbade5c490aa232559f375faadd563ef167c6
MD5 c391551fba934c1de6f92491beb88c4d
BLAKE2b-256 c6d3375a5238cdbbf35460f81a79db60ec46f2370c208c9d0c3fb038aef0da8f

See more details on using hashes here.

File details

Details for the file mannetroll_cupyxturbo-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mannetroll_cupyxturbo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff46b827ffd371f0af48c71e6ddda01109a6b2ca911348daf43215f933668b55
MD5 c335b8e57d9f4033d1606a4ceaab38d8
BLAKE2b-256 f91fe0819c234e0d48e1ad792d8cf38005b18247f3e0379cbc993f1ae03767b2

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