# cmudrc/megaflow2d architecture

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

- Interactive diagram: https://gitdiagram.com/cmudrc/megaflow2d
- Repository: https://github.com/cmudrc/megaflow2d

## Overview

##### Project type and purpose
- MegaFlow2D is a Python dataset package and example‐driven library for parameterized CFD (computational fluid dynamics) simulation data, specifically designed to feed graph‐based ML/super‐resolution workflows.
- Its core purpose is to (a) ingest raw simulation outputs (via FEniCS/dolfin), (b) store them in HDF5, (c) expose them as PyTorch‐Geometric graph datasets, and (d) demonstrate usage via example training scripts.

##### File structure
- Top level:
- setup.py / pyproject.toml: packaging and dependency configuration
- megaflow/: the main library
- examples/: training/demo scripts and models
- test.py: ad hoc test harness
- megaflow/common/: utility modules for metrics, I/O helpers
- megaflow/dataset/: the MegaFlow2D class, HDF5 storage layout, processing logic
- examples/model/: placeholder for user‐supplied ML model definitions
- examples/train.py: CLI wrapper that ties together dataset, model, training loop
- External dependencies declared: h5py, FEniCS/dolfin, torch‐geometric

##### README for additional insights
- Describes HDF5 storage hierarchy: geometry → resolution → timestep → dataset
- Explains automatic processing if raw HDF5 is missing
- Notes multi‐threaded HDF5 writes via process()
- Illustrates dataset usage and example training command line

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interface Layer
    subgraph "User Interface" 
        direction TB
        CLI["examples/train.py"]:::user
    end

    %% Core Library Layer
    subgraph "Core Library"
        direction TB
        subgraph "megaflow"
            direction TB
            MF["megaflow/__init__.py"]:::core
            Version["megaflow/version.py"]:::core
            subgraph "dataset"
                direction TB
                Loader["MegaFlow2D"]:::core
            end
            subgraph "common"
                direction TB
                Metrics["metrics.py"]:::core
                Utils["utils.py"]:::core
            end
        end
    end

    %% Storage Layer
    HDF5["HDF5 Storage"]:::storage

    %% External Dependencies Layer
    subgraph "External Dependencies"
        direction TB
        FEN["FEniCS/dolfin"]:::external
        H5PY["h5py"]:::external
        TG["torch-geometric"]:::external
    end

    %% Examples and Test Layer
    subgraph "Examples / Models"
        direction TB
        Model["examples/model/model.py"]:::user
        ExUtils["examples/utils.py"]:::user
        Test["test.py"]:::user
    end

    %% Packaging Configuration
    SetupCfg["setup.py / pyproject.toml"]:::config

    %% Connections
    CLI -->|calls Dataset Loader| Loader
    CLI -->|starts Training Loop with| Model
    Loader -->|reads/writes| HDF5
    Loader -->|uses| Metrics
    Loader -->|uses| Utils
    Loader -->|invokes| FEN
    Loader -->|via h5py| H5PY
    Loader -->|produces Data object for| TG
    TG -->|fed into| Model
    ExUtils -->|utility support for| CLI
    Test -->|tests| Loader
    SetupCfg -->|defines package for| MF

    %% Click Events
    click CLI "https://github.com/cmudrc/megaflow2d/blob/main/examples/train.py"
    click MF "https://github.com/cmudrc/megaflow2d/blob/main/megaflow/__init__.py"
    click Version "https://github.com/cmudrc/megaflow2d/blob/main/megaflow/version.py"
    click Loader "https://github.com/cmudrc/megaflow2d/blob/main/megaflow/dataset/MegaFlow2D.py"
    click Metrics "https://github.com/cmudrc/megaflow2d/blob/main/megaflow/common/metrics.py"
    click Utils "https://github.com/cmudrc/megaflow2d/blob/main/megaflow/common/utils.py"
    click Model "https://github.com/cmudrc/megaflow2d/blob/main/examples/model/model.py"
    click ExUtils "https://github.com/cmudrc/megaflow2d/blob/main/examples/utils.py"
    click Test "https://github.com/cmudrc/megaflow2d/blob/main/test.py"
    click SetupCfg "https://github.com/cmudrc/megaflow2d/blob/main/setup.py"
    click SetupCfg "https://github.com/cmudrc/megaflow2d/blob/main/pyproject.toml"

    %% Styles
    classDef core fill:#cfe2f3,stroke:#2e6da4,color:#0b2e13,stroke-width:1px;
    classDef user fill:#d4edda,stroke:#155724,color:#155724,stroke-width:1px;
    classDef external fill:#ececec,stroke:#666666,color:#333333,stroke-width:1px;
    classDef storage fill:#ffe5b4,stroke:#cc8400,color:#663300,stroke-width:1px;
    classDef config fill:#f3e5f5,stroke:#8e44ad,color:#4a235a,stroke-width:1px;
```
