# echowve/meshgraphnets_pytorch architecture

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

- Interactive diagram: https://gitdiagram.com/echowve/meshgraphnets_pytorch
- Repository: https://github.com/echowve/meshgraphnets_pytorch

## Overview

##### Project Components
- Data Handling & Preprocessing:
- The dataset folder and the script parse_tfrecord.py handle reading and preprocessing simulation datasets (converted from TFRecord to .h5). This component is responsible for data ingestion.
- Model Architecture:
- The model folder (with model.py, blocks.py, simulator.py) contains the definitions of the graph network’s architecture, the simulation builder, and any network blocks. This is the core computational engine that processes the mesh-based data.
- Utility Functions:
- The utils folder (with modules like noise.py, normalization.py, utils.py) provides helper functions for data processing, normalization, and potentially enforcing additional constraints important for simulation.
- Training Pipeline:
- The train.py script initiates the training process by tying together dataset loading, model invocation, loss computation, and model update. This component reflects how the components interact during learning.
- Simulation/Rollout and Visualization:
- The rollout.py script carries out forward passes (simulation) with the trained model.
- The render_results.py script then takes the simulation outputs (saved as pickle or similar format) and converts them into rendered videos (placed in the videos directory) for visualization of the simulation results.

##### Relationships and Data Flow
- Once parsed, this data is accessed by the “Training Pipeline” (train.py), which uses functions from the “Dataset Module” (dataset folder) and “Utilities” (utils modules) for pre-processing.
- The “Model Component” (inside the model folder) is central and receives data from the Training Pipeline. It also outputs predictions or simulation results.
- After training, the “Simulation Module” (rollout.py) uses the trained model to generate simulation rollouts.
- Finally, the “Visualization Component” (render_results.py), consuming the simulation outputs, produces video feedback (saving files in the videos directory).

##### Architectural Patterns and Technologies
- Modularity: Each major functional area (data, model, utils, simulation, visualization) is clearly separated into its own directory or script, illustrating a modular approach.
- Pipeline Flow: The simulation setup follows a data-processing → training → inference → visualization pipeline.
- Graph Networks & PyTorch Technologies: Highlight that the model leverages graph network architectures built on top of PyTorch and PyTorch Geometric, as well as physics-informed design cues from the referenced research papers.

- Data Source / Dataset (external/preprocessed)
- Data Parser (parse_tfrecord.py)
- Dataset Module (dataset directory: fpc.py and __init__.py)
- Utility Functions (utils, e.g., normalization, noise)
- Model & Simulation Engine (model directory: blocks.py, model.py, simulator.py)
- Training Script (train.py)
- Rollout/Inference (rollout.py)
- Visualization (render_results.py and videos folder)
- From Data Source → Data Parser → Dataset Module
- From Dataset Module and Utility Functions → Training Script → Model
- From Trained Model → Rollout/Inference → Visualization
- Use clear labels on each node; for example, indicate “Graph Network Model (PyTorch & PyG)” for the model component, and note “Dataset Parsing & Preprocessing” in data-related nodes.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Nodes
    DS["Data Source (Cylinder Flow Dataset)"]:::external
    DP["Data Parser (parse_tfrecord.py)"]:::preprocessing
    TP["Training Pipeline (train.py)"]:::training
    RO["Rollout (rollout.py)"]:::rollout

    %% Subgraph: Dataset Module
    subgraph "Dataset Module"
        DS1["fpc.py"]:::preprocessing
        DS2["__init__.py"]:::preprocessing
    end

    %% Subgraph: Utility Functions
    subgraph "Utility Functions (utils)"
        U1["noise.py"]:::utils
        U2["normalization.py"]:::utils
        U3["utils.py"]:::utils
    end

    %% Subgraph: Model Architecture
    subgraph "Model Architecture"
        M1["Blocks (model/blocks.py)"]:::modelComp
        M2["Model (model/model.py)"]:::modelComp
        M3["Simulator (model/simulator.py)"]:::modelComp
    end

    %% Subgraph: Visualization
    subgraph "Visualization"
        V1["Rendering (render_results.py)"]:::visualization
        V2["Video Output (videos/)"]:::visualization
    end

    %% Connections
    DS -->|"providesData"| DP
    DP -->|"parsesTo"| DS1
    DP -->|"parsesTo"| DS2
    
    DS1 -->|"feeds"| TP
    DS2 -->|"feeds"| TP

    U1 -->|"supports"| TP
    U2 -->|"supports"| TP
    U3 -->|"supports"| TP

    TP -->|"trains"| M2
    M2 -->|"guides"| RO
    RO -->|"rollsOutTo"| V1
    V1 -->|"rendersInto"| V2

    %% Click Events
    click DP "https://github.com/echowve/meshgraphnets_pytorch/blob/master/parse_tfrecord.py"
    click DS1 "https://github.com/echowve/meshgraphnets_pytorch/blob/master/dataset/fpc.py"
    click DS2 "https://github.com/echowve/meshgraphnets_pytorch/blob/master/dataset/__init__.py"
    click U1 "https://github.com/echowve/meshgraphnets_pytorch/blob/master/utils/noise.py"
    click U2 "https://github.com/echowve/meshgraphnets_pytorch/blob/master/utils/normalization.py"
    click U3 "https://github.com/echowve/meshgraphnets_pytorch/blob/master/utils/utils.py"
    click M1 "https://github.com/echowve/meshgraphnets_pytorch/blob/master/model/blocks.py"
    click M2 "https://github.com/echowve/meshgraphnets_pytorch/blob/master/model/model.py"
    click M3 "https://github.com/echowve/meshgraphnets_pytorch/blob/master/model/simulator.py"
    click TP "https://github.com/echowve/meshgraphnets_pytorch/blob/master/train.py"
    click RO "https://github.com/echowve/meshgraphnets_pytorch/blob/master/rollout.py"
    click V1 "https://github.com/echowve/meshgraphnets_pytorch/blob/master/render_results.py"
    click V2 "https://github.com/echowve/meshgraphnets_pytorch/tree/master/videos/"

    %% Styles
    classDef external fill:#f8c,stroke:#333,stroke-width:2px;
    classDef preprocessing fill:#ccf,stroke:#333,stroke-width:2px;
    classDef utils fill:#ffc,stroke:#333,stroke-width:2px;
    classDef training fill:#cfc,stroke:#333,stroke-width:2px;
    classDef modelComp fill:#fcf,stroke:#333,stroke-width:2px;
    classDef rollout fill:#ffe,stroke:#333,stroke-width:2px;
    classDef visualization fill:#cff,stroke:#333,stroke-width:2px;
```
