# jviquerat/lbm architecture

> Architecture diagram of the GitHub repository jviquerat/lbm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jviquerat/lbm
- Repository: https://github.com/jviquerat/lbm

## Overview

##### Main Components

a) Core Components:
- Lattice System (D2Q9)
- Collision Operator (TRT)
- Boundary Conditions Handler (Zou-He)
- Numba-accelerated Computing Core

b) Application Layer:
- Simulation Apps (Cavity, Poiseuille, Turek, etc.)
- Factory Pattern Implementation
- Results Management

**┌─ User Interface Layer ─────────────────┐**
- start.py (Entry Point)              │
- Configuration Management            │
- ┬───────────────────────┘
- ↓
**┌─ Application Layer ──────────────────┐**
- ┌─ Factory ─────┐ ┌─ Apps ────────┐ │
- AppFactory  │ │ - Cavity      │ │
- ┘ │ - Poiseuille   │ │
- Turek        │ │
- Array        │ │
- Step         │ │
- ┬┘ │
- ┬──┘
- ↓
**┌─ Core Simulation Layer ─────────────┐**
- ┌─ Lattice ─────┐ ┌─ Physics ────┐ │
- D2Q9 Layout │ │ - TRT        │ │
- Geometry    │ │ - Zou-He BC  │ │
- ┘ │ - IBB        │ │
- ┘ │
- ┘
- ↕
**┌─ Performance Layer ────────────────┐**
- Numba Acceleration              │
- Computational Optimizations     │
- ┘
- ↕
**┌─ I/O Layer ───────────────────────┐**
- Results Storage                 │
- Visualization                   │
- Data Export                     │
- ┘

##### Important Elements to Highlight

a) Data Flow:
- How simulation parameters flow from the user interface through the application layer
- How computational results move through the system
- Feedback loop for visualization and analysis

b) Key Components:
- Core LBM components (lattice, collision, boundary conditions)
- Numba acceleration integration
- Relationship between different simulation apps

##### Implementation Details

- src/core/ contains the fundamental simulation components
- src/app/ houses the different application implementations
- src/utils/ provides supporting functionality
- src/plot/ handles visualization

##### Special Features to Note

- Factory pattern implementation for application management
- Modular design allowing easy addition of new simulation types
- Clear separation between core simulation logic and application-specific code
- Built-in benchmarking capabilities

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef ui fill:#E6F3FF,stroke:#000
    classDef app fill:#E6FFE6,stroke:#000
    classDef core fill:#FFE6CC,stroke:#000
    classDef perf fill:#F3E6FF,stroke:#000
    classDef io fill:#F0F0F0,stroke:#000

    %% User Interface Layer
    subgraph UI["User Interface Layer"]
        Entry["start.py"]
        Config["Configuration Management"]
    end

    %% Application Layer
    subgraph APP["Application Layer"]
        AppFactory["Application Factory"]
        
        subgraph Apps["Simulation Apps"]
            BaseApp["Base Application"]
            Cavity["Cavity Flow"]
            Poiseuille["Poiseuille Flow"]
            Turek["Turek Flow"]
            Array["Array Simulation"]
            Step["Step Flow"]
        end
    end

    %% Core Simulation Layer
    subgraph CORE["Core Simulation Layer"]
        subgraph Lattice["Lattice System"]
            D2Q9["D2Q9 Layout"]
            Geometry["Geometry Handler"]
        end

        subgraph Physics["Physics Engine"]
            TRT["TRT Collision"]
            BC["Zou-He BC"]
            IBB["Immersed Boundary"]
        end

        Runner["Simulation Runner"]
        Obstacle["Obstacle Handler"]
    end

    %% Performance Layer
    subgraph PERF["Performance Layer"]
        Numba["Numba Acceleration"]
        Buffer["Buffer Management"]
    end

    %% I/O Layer
    subgraph IO["I/O Layer"]
        Results["Results Storage"]
        Viz["Visualization"]
        Shapes["Shape Definitions"]
        Tests["Testing Framework"]
    end

    %% Relationships
    Entry --> Config
    Config --> AppFactory
    AppFactory --> BaseApp
    BaseApp --> |Extends| Cavity
    BaseApp --> |Extends| Poiseuille
    BaseApp --> |Extends| Turek
    BaseApp --> |Extends| Array
    BaseApp --> |Extends| Step
    
    Apps --> Runner
    Runner --> Lattice
    Runner --> Physics
    Runner --> Obstacle
    
    Lattice <--> Numba
    Physics <--> Numba
    Numba <--> Buffer
    
    Runner --> Results
    Results --> Viz
    Shapes --> Obstacle

    %% Click Events
    click Entry "https://github.com/jviquerat/lbm/blob/master/start.py"
    click AppFactory "https://github.com/jviquerat/lbm/blob/master/lbm/src/core/factory.py"
    click Cavity "https://github.com/jviquerat/lbm/blob/master/lbm/src/app/cavity.py"
    click Poiseuille "https://github.com/jviquerat/lbm/blob/master/lbm/src/app/poiseuille.py"
    click Turek "https://github.com/jviquerat/lbm/blob/master/lbm/src/app/turek.py"
    click Array "https://github.com/jviquerat/lbm/blob/master/lbm/src/app/array.py"
    click Step "https://github.com/jviquerat/lbm/blob/master/lbm/src/app/step.py"
    click BaseApp "https://github.com/jviquerat/lbm/blob/master/lbm/src/app/base_app.py"
    click D2Q9 "https://github.com/jviquerat/lbm/blob/master/lbm/src/core/lattice.py"
    click Numba "https://github.com/jviquerat/lbm/blob/master/lbm/src/core/nb.py"
    click Obstacle "https://github.com/jviquerat/lbm/blob/master/lbm/src/core/obstacle.py"
    click Runner "https://github.com/jviquerat/lbm/blob/master/lbm/src/core/run.py"
    click Viz "https://github.com/jviquerat/lbm/blob/master/lbm/src/plot/plot.py"
    click Results "https://github.com/jviquerat/lbm/tree/master/lbm/save/"
    click Buffer "https://github.com/jviquerat/lbm/blob/master/lbm/src/utils/buff.py"
    click Shapes "https://github.com/jviquerat/lbm/blob/master/lbm/src/utils/shapes.py"
    click Tests "https://github.com/jviquerat/lbm/tree/master/lbm/tst/"

    %% Style Applications
    class Entry,Config ui
    class AppFactory,BaseApp,Cavity,Poiseuille,Turek,Array,Step app
    class D2Q9,Geometry,TRT,BC,IBB,Runner,Obstacle core
    class Numba,Buffer perf
    class Results,Viz,Shapes,Tests io
```
