Skip to main content

2D Turbulence (SciPy + CuPy)

Project description

2D Turbulence Simulation (SciPy / CuPy)

A Direct Numerical Simulation (DNS) code for 2D homogeneous incompressible turbulence

It supports:

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

DNS solver

The solver includes:

  • PAO-style random-field initialization
  • 3/2 de-aliasing in spectral space
  • Crank–Nicolson time integration
  • CFL-based adaptive time stepping (Δt updated from the current flow state)

cupystorm GUI (PySide6)

Run an cupystorm window that:

  • Displays the flow field as a live image (fast Indexed8 palette rendering)
  • Lets you switch displayed variable:
    • U, V (velocity components)
    • K (kinetic energy)
    • Ω (vorticity)
    • φ (stream function)
  • Lets you switch colormap (several built-in palettes)
  • Lets you change simulation parameters on the fly:
    • Grid size N
    • Reynolds number Re
    • Initial spectrum peak K0
    • CFL number CFL
    • Max steps / auto-reset limit
    • GUI update interval (how often to refresh the display)
  • Includes force/initialization modes:
    • Navier-Stokes: PAO spectrum init
    • High-k forcing: High-k spectral forcing + Ekman/Rayleigh large-scale drag
    • Rain: random “kick” forcing events
    • Circle: a forcing point moves on a circular trajectory (continuous forcing)
    • Mouse: apply forcing by click/drag in the image

Keyboard shortcuts

Single-key shortcuts (application-wide) for fast control:

  • V: cycle variable
  • C: cycle colormap
  • N: cycle grid size
  • R: cycle Reynolds number
  • K: cycle K0
  • L: cycle CFL
  • S: cycle max steps
  • U: cycle update interval

Saving / exporting

From the GUI you can:

  • Save the current frame as a PNG image
  • Dump full-resolution fields to a folder as PGM images:
    • u-velocity, v-velocity, kinetic energy, vorticity

Display scaling

To keep the GUI responsive for large grids, the displayed image is automatically upscaled/downscaled depending on N. The window is resized accordingly when you change N.

Installation

Using uv

From the project root:

uv sync
uv run python -m cupystorm.turbo_main

The DNS with SciPy (256 x 256) Rain

SciPy

Full CLI

$ python -m cupystorm.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 cupystorm.turbo_simulator 256 10000 10 1001 0.75 cpu

# Auto-select backend (GPU if CuPy + CUDA are available)
$ python -m cupystorm.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
    
  2. Install CuPy into the uv environment:

    $ uv sync
    $ uv pip install cupy-cuda13x
    
  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 cupystorm.turbo_simulator 256 10000 10 1001 0.75 gpu
    

Or let the backend auto-detect:

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

The DNS with CuPy (7776 x 7776)

CuPy

Profiling

cProfile (CPU)

$ python -m cProfile -o turbo_simulator.prof -m cupystorm.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 cupystorm.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 cupystorm.turbo_simulator 256 10000 10 201 0.75 cpu

one-liner CPU/SciPy

$ curl -LsSf https://astral.sh/uv/install.sh | sh
$ uv cache clean mannetroll-cupystorm
$ uv run --python 3.13 --with "mannetroll-cupystorm==0.1.1" -- cupystorm

one-liner GPU/CuPy

$ uv run --python 3.13 --with "mannetroll-cupystorm[cuda]==0.1.1" -- cupystorm

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_cupystorm-0.1.1.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_cupystorm-0.1.1-py3-none-any.whl (1.5 MB view details)

Uploaded Python 3

File details

Details for the file mannetroll_cupystorm-0.1.1.tar.gz.

File metadata

  • Download URL: mannetroll_cupystorm-0.1.1.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_cupystorm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0a4723a292fc8a1c90acd0972dbe35ac070e7ca5e9432ca42892f930f2c8233a
MD5 d55cb991c2ba9aa530016439fa769b96
BLAKE2b-256 6ab7d3220677e298f03b91a2750ce2d97d2dcc7f95af5750d43c53102fb4a9de

See more details on using hashes here.

File details

Details for the file mannetroll_cupystorm-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mannetroll_cupystorm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e5af61dec9331d0ec664c2064b6cab0ee502c09f80c4b767f71225a3022d65f8
MD5 0031a5c0d146236e2998eeacf30a6e83
BLAKE2b-256 349ba67ea81c06c4b660ea9dfb64104097336964a136459020d6c8cb80f3e588

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