A real-time fluid dynamics simulation implemented in Python using CUDA for GPU acceleration, featuring interactive ASCII visualization and automated movement patterns.
- CUDA GPU Acceleration: Leverages GPU parallel processing for real-time fluid simulation
- 80x80 Grid Resolution: High-resolution simulation with 6,400 fluid cells
- Real-time Physics: Implements a stable, semi-Lagrangian approximation of the Navier-Stokes equations for incompressible fluids
- Manual Control: Arrow keys and buttons for cursor movement
- Force Application: Add directional forces and density sources
- Multiple Input Methods: Button interface + keyboard shortcuts
- Real-time Interaction: Immediate response to user input
- Three Display Modes:
- Density Mode: Blue gradient showing fluid concentration
- Velocity Mode: Rainbow arrows showing flow direction and speed
- Combined Mode: Dynamic switching between density and velocity visualization
- Enhanced Color Schemes: 10+ color gradients for better visual clarity
- ASCII Art Rendering: Monospace character-based fluid representation
- 6 Movement Patterns:
- ๐ฒ Random Walk: Chaotic Brownian motion with random forces
- ๐ Spiral: Expanding spiral with tangential forces
- โ Figure-8: Smooth parametric figure-eight pattern
- โฝ Bouncing Ball: Physics-based collision simulation
- ๐ช๏ธ Vortex Dance: Multiple moving vortices interaction
- ๐ฏ Random Pattern: Randomly selected pattern
- 100 Frame Sequences: Extended animations for pattern analysis
Navier-Stokes Equations Implementation:
- Velocity diffusion with viscosity
- Density advection and diffusion
- Pressure projection for incompressibility
- Boundary condition enforcement
add_source
: Density injectiondiffuse
: Heat equation solveradvect
: Semi-Lagrangian advectionproject
: Pressure Poisson solverapply_force
: Force field applicationclear_fields
: Memory reset
- GPU memory allocation for all field variables
- Efficient device-to-host transfers
- Automatic cleanup on exit
Key | Action |
---|---|
โโโโ |
Move cursor & add directional force |
Space |
Add density at cursor position |
S |
Single simulation step |
A |
Toggle auto-update mode |
C |
Clear simulation (reset all fields) |
M |
Cycle through display modes |
- Navigation: Arrow buttons for precise movement
- Simulation Control: Step, Auto, Clear, Mode, Quit
- Force Control: Directional forces and density injection
- Animation Control: 6 automated movement patterns
- Purpose: Visualize fluid concentration and distribution
- Colors: Blue gradient (dark blue โ light blue โ yellow โ orange โ red)
- Characters:
.ยท:;!|โชโซโชโ
(increasing density)
- Purpose: Show flow direction and speed
- Colors: Rainbow gradient (green โ yellow โ orange โ red)
- Characters: Directional arrows
โโโโโโโโ
- Purpose: Dynamic visualization switching
- Logic: Shows velocity arrows when flow > threshold, otherwise density
- Benefit: Comprehensive fluid state visualization
- Behavior: Chaotic movement with random directional forces
- Physics: Brownian motion simulation
- Parameters: Random force magnitude (1.0-3.0), density (20-60)
- Behavior: Expanding spiral with tangential forces
-
Mathematics:
$r \space = \space frame \cdot 0.1$ ,$\spaceฮธ = frame \cdot 0.3$ - Forces: Perpendicular to radius for circulation
- Behavior: Smooth parametric motion
-
Mathematics:
$x \space = \space scale \cdot \sin(t)$ ,$\space y \space = \space scale \cdot \sin(t) \cdot \cos(t)$ - Pattern: Classical Lissajous curve
- Behavior: Physics-based collision with walls
- Features: Velocity damping, realistic bouncing
- Physics: Elastic collision with energy loss
- Behavior: Three moving vortices creating complex flow
- Pattern: Orbital motion with phase shifts
- Interaction: Multiple vortex interference patterns
- Educational Tool: Visualize Navier-Stokes equation solutions
- Pattern Analysis: Study vortex formation and decay
- Boundary Effects: Observe wall interaction effects
- GPU Programming: CUDA kernel optimization examples
- Numerical Methods: Finite difference schemes
- Real-time Simulation: Interactive parameter exploration
- GPU: CUDA-compatible graphics card
- Memory: 2GB+ GPU memory recommended
- Software: Python 3.7+, PyCUDA, Jupyter/Colab
- Grid Size: 80ร80 = 6,400 cells
- Update Rate: ~5-10 FPS (depending on hardware)
- Memory Usage: ~50MB GPU memory
- Precision: 32-bit floating point
- 3D visualization support
- Variable viscosity and diffusion
- Particle tracking overlay
- Video export functionality
- Real-time parameter adjustment
- Multiple fluid interaction
- Texture rendering options
- Lattice Boltzmann method
- Free surface tracking
- Heat transfer simulation
- Magnetic field effects
- Navier-Stokes Equations: Foundation of fluid dynamics
- Jos Stam's Method: "Real-Time Fluid Dynamics for Games" (1999)
- Semi-Lagrangian Advection: Stable numerical scheme
- Pressure Projection: Helmholtz-Hodge decomposition
- CUDA Programming: NVIDIA CUDA Toolkit Documentation
- Numerical Methods: "Numerical Recipes" computational techniques
- Interactive Visualization: Jupyter widgets and HTML5