Skip to content

FluidImageBoundarySim: A creative fluid dynamics simulation framework that uses custom images to define boundary conditions.

Notifications You must be signed in to change notification settings

STOKEDMODELLER/FluidImageBoundarySim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Fluid Image Boundary Simulation v2.0.0 - GUI Edition

A comprehensive Lattice Boltzmann Method (LBM) fluid simulation package with an intuitive GUI interface for real-time visualization and parameter control.

๐Ÿš€ Major Improvements in v2.0.0

New GUI Interface

  • Interactive Parameter Control: Real-time adjustment of simulation parameters
  • Multi-view Visualization: Separate tabs for velocity, pressure, and combined views
  • Live Simulation Monitoring: Real-time diagnostics and stability analysis
  • Configuration Management: Save and load simulation configurations
  • Obstacle Mask Loading: Import custom obstacle geometries from PNG files

Improved Project Structure

  • Modular Design: Clean separation of core simulation, GUI, and utilities
  • Object-Oriented Architecture: Proper encapsulation and reusable components
  • Configuration System: JSON-based configuration management
  • Enhanced Error Handling: Robust validation and error reporting
  • Package Installation: Proper Python package with setup.py

Enhanced Simulation Features

  • Stability Analysis: Real-time Mach number and Reynolds number monitoring
  • Mathematical Validation: Built-in checks for mass and momentum conservation
  • Flexible Obstacle Creation: Support for circles, rectangles, and custom masks
  • Improved Boundary Conditions: Enhanced Zou-He implementation with numerical stability

๐Ÿ“ Project Structure

FluidImageBoundarySim/
โ”œโ”€โ”€ fluid_sim/                 # Main package
โ”‚   โ”œโ”€โ”€ core/                  # Core simulation logic
โ”‚   โ”‚   โ”œโ”€โ”€ lattice.py         # Lattice constants and methods
โ”‚   โ”‚   โ”œโ”€โ”€ simulation.py      # Main LBM simulation class
โ”‚   โ”‚   โ””โ”€โ”€ validation.py      # Validation and stability tools
โ”‚   โ”œโ”€โ”€ gui/                   # GUI interface
โ”‚   โ”‚   โ”œโ”€โ”€ main_window.py     # Main application window
โ”‚   โ”‚   โ”œโ”€โ”€ visualization.py   # Visualization panels
โ”‚   โ”‚   โ””โ”€โ”€ controls.py        # Parameter control panels
โ”‚   โ”œโ”€โ”€ utils/                 # Utility functions
โ”‚   โ”‚   โ”œโ”€โ”€ config.py          # Configuration management
โ”‚   โ”‚   โ”œโ”€โ”€ obstacles.py       # Obstacle creation tools
โ”‚   โ”‚   โ””โ”€โ”€ file_utils.py      # File operations
โ”‚   โ””โ”€โ”€ config/                # Configuration files
โ”œโ”€โ”€ examples/                  # Example scripts
โ”œโ”€โ”€ tests/                     # Test files
โ”œโ”€โ”€ docs/                      # Documentation
โ”œโ”€โ”€ gui_app.py                 # GUI application entry point
โ”œโ”€โ”€ test_new_structure.py      # Structure validation tests
โ”œโ”€โ”€ simulation_config.json     # Default configuration
โ”œโ”€โ”€ requirements.txt           # Python dependencies
โ””โ”€โ”€ setup.py                   # Package installation script

๐Ÿ› ๏ธ Installation

Option 1: Direct Installation

# Clone the repository
git clone https://github.com/STOKEDMODELLER/FluidImageBoundarySim.git
cd FluidImageBoundarySim

# Install dependencies
pip install -r requirements.txt

# Install the package
pip install -e .

Option 2: Development Installation

# Clone and install in development mode
git clone https://github.com/STOKEDMODELLER/FluidImageBoundarySim.git
cd FluidImageBoundarySim
pip install -e .[dev]

๐ŸŽฎ Usage

GUI Application

Launch the interactive GUI application:

python gui_app.py

Command Line Interface

from fluid_sim import LBMSimulation, ConfigManager

# Load configuration
config_manager = ConfigManager()
config = config_manager.load_config()

# Create simulation
sim = LBMSimulation(
    nx=config.nx, 
    ny=config.ny,
    reynolds=config.reynolds,
    flow_speed=config.flow_speed
)

# Setup obstacle
sim.setup_cylinder_obstacle(
    cx=config.obstacle_cx,
    cy=config.obstacle_cy, 
    r=config.obstacle_r
)

# Run simulation
for i in range(1000):
    diagnostics = sim.step()
    if i % 100 == 0:
        print(f"Step {i}: Max velocity = {diagnostics['max_velocity']:.4f}")

Custom Obstacle from Image

# Load obstacle from PNG file
sim.setup_from_mask("path/to/obstacle_mask.png")

# Or create geometric obstacles
from fluid_sim.utils import create_obstacle
obstacle = create_obstacle("circle", nx=250, ny=120, cx=60, cy=60, r=20)

๐ŸŽฏ GUI Features

Real-time Controls

  • Grid Parameters: Adjust simulation domain size
  • Physical Parameters: Modify Reynolds number and flow speed
  • Obstacle Parameters: Change obstacle position and size
  • Simulation Controls: Start/stop, single step, reset

Visualization Modes

  • Velocity Tab: Real-time velocity magnitude visualization
  • Pressure Tab: Pressure field visualization
  • Combined Tab: Side-by-side velocity and pressure plots

Advanced Features

  • Configuration Management: Save/load simulation setups
  • Stability Monitoring: Real-time stability analysis
  • Export Capabilities: Save visualization images
  • Diagnostics Panel: Live simulation metrics

๐Ÿ“Š Configuration Management

JSON Configuration Format

{
  "nx": 250,
  "ny": 120,
  "reynolds": 300.0,
  "flow_speed": 0.05,
  "max_iterations": 5000,
  "omega": null,
  "obstacle_cx": 62.5,
  "obstacle_cy": 60.0,
  "obstacle_r": 13.3,
  "colormap": "jet",
  "dpi": 100
}

Configuration Usage

from fluid_sim.utils import ConfigManager

# Load existing configuration
config_manager = ConfigManager()
config = config_manager.load_config("my_config.json")

# Modify parameters
config_manager.update_config(reynolds=500.0, flow_speed=0.08)

# Save configuration
config_manager.save_config(config, "updated_config.json")

๐Ÿงช Testing

Run the comprehensive test suite:

# Test new structure
python test_new_structure.py

# Test original functionality (legacy)
python test_improvements.py

๐Ÿ“‹ Mathematical Foundation

The simulation implements the D2Q9 Lattice Boltzmann Method with:

Core Equations

  • Equilibrium Distribution: Maxwell-Boltzmann expanded to second order
  • Collision Operator: BGK approximation with single relaxation time
  • Streaming Step: Advection of distribution functions
  • Boundary Conditions: Zou-He implementation for velocity/pressure boundaries

Key Physical Properties

  • Sound Speed: cs = 1/โˆš3 in lattice units
  • Kinematic Viscosity: ฮฝ = (1/ฯ‰ - 0.5)/3
  • Pressure: P = ฯ ร— csยฒ (proper equation of state)
  • Stability Condition: Mach number < 0.1 for numerical stability

๐Ÿ”ง Requirements

Core Dependencies

  • Python >= 3.8
  • numpy >= 1.19.0
  • matplotlib >= 3.3.0
  • pillow >= 8.0.0
  • scipy >= 1.6.0

Optional Dependencies

  • opencv-python >= 4.5.0 (for video output)
  • tkinter (usually included with Python)

๐Ÿ“š Examples

Basic Cylinder Flow

from fluid_sim import LBMSimulation

# Create simulation
sim = LBMSimulation(nx=200, ny=100, reynolds=100)

# Setup cylinder obstacle  
sim.setup_cylinder_obstacle(cx=50, cy=50, r=10)

# Run simulation
for i in range(1000):
    diagnostics = sim.step()
    
    # Check stability
    if not diagnostics['is_stable']:
        print(f"Warning: Simulation unstable at step {i}")

Custom Configuration

from fluid_sim.utils import ConfigManager, SimulationConfig

# Create custom configuration
config = SimulationConfig(
    nx=300,
    ny=150, 
    reynolds=500.0,
    flow_speed=0.1
)

# Validate and save
config_manager = ConfigManager()
if config_manager.validate_config(config):
    config_manager.save_config(config, "custom_config.json")

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

STOKEDMODELLER - Fluid dynamics simulation enthusiast

๐Ÿ™ Acknowledgments

  • Lattice Boltzmann Method community for theoretical foundations
  • NumPy and SciPy developers for numerical computing tools
  • Matplotlib team for visualization capabilities
  • tkinter developers for GUI framework

About

FluidImageBoundarySim: A creative fluid dynamics simulation framework that uses custom images to define boundary conditions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages