# psu-efd/pyhmt2d architecture

> Architecture diagram of the GitHub repository psu-efd/pyhmt2d, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/psu-efd/pyhmt2d
- Repository: https://github.com/psu-efd/pyhmt2d

## Overview

##### Main Components and Architecture

a) Core Components:
- Hydraulic Models Data Layer (Base classes and model-specific implementations)
- Calibration System
- Parametric Study System
- Command Line Interface (CLI)
- Miscellaneous Utilities

b) External Systems:
- SRH-2D Model
- HEC-RAS Model
- Backwater-1D Model
- VTK Visualization System
- File Systems (HDF5, GIS data)

##### Component Relationships

a) Data Flow:
- Input flows: Model configuration files → Hydraulic Models Data Layer
- Output flows: Hydraulic Models Data Layer → VTK/Analysis outputs
- Control flows: CLI/Python API → Model Controllers

b) Dependencies:
- Integration with external libraries (h5py, VTK, GDAL, pywin32)
- File format conversions between different model types

##### Architectural Patterns

Use these visual elements:

- Blue: Core pyHMT2D components
- Green: External hydraulic models
- Yellow: Data storage/files
- Orange: User interfaces (CLI/API)

b) Component Grouping:
- Related components in containers
- Use clear boundaries between different subsystems

##### Detailed Component Breakdown

Subcomponents:

**pyHMT2D**
- Model Controllers
- SRH-2D Controller
- HEC-RAS Controller
- Backwater-1D Controller
- Data Processing
- Results Reader
- Format Converter
- Data Analyzer
- Optimization
- Calibrator
- Parameter Manager
- Objective Functions
- Utilities
- Terrain Processing
- VTK Conversion
- GIS Tools

##### Interface Definitions

Clear interfaces for:
- Model control APIs
- Data conversion interfaces
- Calibration system interfaces
- CLI command endpoints

##### Key Design Elements

Emphasize:
- Modular architecture allowing addition of new hydraulic models
- Separation between model control and data processing
- Extensible calibration and optimization framework
- Clear data transformation pipelines

##### Implementation Notes

Annotations for:
- Windows-only compatibility
- Version compatibility with specific hydraulic models
- Required external dependencies
- File format support

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef core fill:#b3d1ff,stroke:#333,stroke-width:2px
    classDef external fill:#90EE90,stroke:#333,stroke-width:2px
    classDef data fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef ui fill:#FFA07A,stroke:#333,stroke-width:2px

    %% Main Components
    subgraph Core["Core Components"]
        HMD["Hydraulic Models Data Layer"]:::core
        CAL["Calibration System"]:::core
        PAR["Parametric Study System"]:::core
        CLI["Command Line Interface"]:::core
        UTIL["Utilities"]:::core
    end

    %% Model Controllers
    subgraph Controllers["Model Controllers"]
        SRH["SRH-2D Controller"]:::core
        HEC["HEC-RAS Controller"]:::core
        BWC["Backwater-1D Controller"]:::core
    end

    %% External Systems
    subgraph External["External Systems"]
        SRHM["SRH-2D Model"]:::external
        HECM["HEC-RAS Model"]:::external
        BWM["Backwater-1D Model"]:::external
        VTK["VTK Visualization"]:::external
    end

    %% Data Storage
    subgraph Data["Data Systems"]
        HDF["HDF5 Files"]:::data
        GIS["GIS Data"]:::data
    end

    %% Optimization Components
    subgraph Optimization["Optimization System"]
        OPT["Optimizer"]:::core
        PARAM["Parameters Manager"]:::core
        OBJ["Objective Functions"]:::core
    end

    %% Utility Components
    subgraph Utilities["Utility Components"]
        TERR["Terrain Processing"]:::core
        VTKUTIL["VTK Utilities"]:::core
        CONV["Format Converter"]:::core
    end

    %% Relationships
    CLI --> HMD
    HMD --> |Controls| Controllers
    Controllers --> External
    External --> Data
    Data --> HMD
    CAL --> Optimization
    Optimization --> HMD
    PAR --> HMD
    UTIL --> |Supports| HMD
    HMD --> VTK
    
    %% Click events
    click HMD "https://github.com/psu-efd/pyHMT2D/tree/main/pyHMT2D/Hydraulic_Models_Data/Hydraulic_Models_Data_Base/"
    click CAL "https://github.com/psu-efd/pyHMT2D/tree/main/pyHMT2D/Calibration/"
    click PAR "https://github.com/psu-efd/pyHMT2D/tree/main/pyHMT2D/Parametric_Study/"
    click CLI "https://github.com/psu-efd/pyHMT2D/tree/main/pyHMT2D/cli/"
    click SRH "https://github.com/psu-efd/pyHMT2D/blob/main/pyHMT2D/Hydraulic_Models_Data/SRH_2D/SRH_2D_Model.py"
    click HEC "https://github.com/psu-efd/pyHMT2D/blob/main/pyHMT2D/Hydraulic_Models_Data/RAS_2D/HEC_RAS_Model.py"
    click BWC "https://github.com/psu-efd/pyHMT2D/blob/main/pyHMT2D/Hydraulic_Models_Data/Backwater_1D/Backwater_1D_Model.py"
    click TERR "https://github.com/psu-efd/pyHMT2D/blob/main/pyHMT2D/Misc/Terrain.py"
    click VTKUTIL "https://github.com/psu-efd/pyHMT2D/blob/main/pyHMT2D/Misc/vtk_utilities.py"
    click CONV "https://github.com/psu-efd/pyHMT2D/blob/main/pyHMT2D/Misc/RAS_to_SRH_Converter.py"
    click OPT "https://github.com/psu-efd/pyHMT2D/blob/main/pyHMT2D/Calibration/Optimizer.py"
    click PARAM "https://github.com/psu-efd/pyHMT2D/blob/main/pyHMT2D/Calibration/Parameters.py"
    click OBJ "https://github.com/psu-efd/pyHMT2D/blob/main/pyHMT2D/Calibration/Objectives.py"
```
