# weiche/reference-fmus-min architecture

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

- Interactive diagram: https://gitdiagram.com/weiche/reference-fmus-min
- Repository: https://github.com/weiche/reference-fmus-min

## Overview

##### Main Components
- FMU Models: Represented by directories like BouncingBall, Clocks, Dahlquist, Feedthrough, Resource, Stair, StateSpace, and VanDerPol. Each of these folders includes model-specific code and XML model descriptions (e.g., FMI1CS.xml, FMI2.xml, FMI3.xml) along with a model implementation file (model.c) and associated configuration files.
- Core Simulation Engine (fmusim): Found in the “fmusim” directory, this executable integrates the FMI simulation infrastructure and uses the functions defined in the common modules.
- Graphical User Interface (fmusim-gui): A separate component offering a GUI (with MainWindow, Models, various dialogs, and resource management) that wraps around the simulation engine.
- Common FMI Library: Located in “include” and “src” directories. These files define the generic interface (e.g., model.h, cosimulation.h) and provide FMI-related function implementations (e.g., fmi1Functions.c, fmi2Functions.c, fmi3Functions.c).
- Build and Integration Infrastructure: This encompasses CMakeLists.txt at the root and in subdirectories, the “build” directory with various Python build scripts, and GitHub actions in “.github/workflows.” These scripts coordinate the building of both FMU models and the simulation executables.
- Examples and Tests: “examples” and “tests” directories provide sample client codes and automated tests that show integration and proper functionality of the simulation tools.

##### Relationships and Interactions
- FMU Models <→ Core FMI Library: Each FMU model folder supplies model-specific data (XML, model.c, config.h) that is integrated via the common FMI functions defined in “include” and “src.”
- Core FMI Library <→ Simulation Engine (fmusim): The simulation executable calls upon the common standards implementations (solvers, model description parsers, CSV handling, etc.) to run simulations.
- Simulation Engine (fmusim) <→ fmusim-gui: The GUI component wraps around or interacts with the simulation engine. This might be shown as the GUI initiating simulation commands (e.g., via command-line calls or API invocations) and receiving outputs (like CSV results).

##### Architectural Patterns and Technologies
- Separation of Concerns: The system is organized by dividing model specific code, core FMI function implementations, simulation executables, and the GUI.
- Modularization: Independent FMU directories make the system extensible. Additionally, the separation between command-line simulation (fmusim) and the GUI (fmusim-gui) is clearly evident.
- Build and Integration: Use of CMake, Python build scripts, and GitHub workflows shows a robust automated build and integration process.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build and Integration Infrastructure
    subgraph "Build Infrastructure"
        direction TB
        BI("Build Infrastructure"):::build
        CMake("CMakeLists.txt"):::build
        BS("build (Python scripts)"):::build
        CI(".github/workflows"):::build
    end

    %% FMU Models (Model Library)
    subgraph "FMU Models"
        direction TB
        BB("BouncingBall"):::fmu
        CL("Clocks"):::fmu
        DA("Dahlquist"):::fmu
        FT("Feedthrough"):::fmu
        RE("Resource"):::fmu
        ST("Stair"):::fmu
        SS("StateSpace"):::fmu
        VP("VanDerPol"):::fmu
    end

    %% Common FMI Library
    subgraph "Common FMI Library"
        direction TB
        Inc("Include"):::lib
        Src("Src"):::lib
    end

    %% Simulation Engine (CLI)
    Engine("fmusim (CLI Simulation Engine)"):::sim

    %% Graphical User Interface
    GUI("fmusim-gui (Graphical Interface)"):::sim

    %% Examples and Tests
    subgraph "Examples & Tests"
        direction TB
        Ex("Examples"):::test
        Te("Tests"):::test
    end

    %% Build Infrastructure arrows to main components
    BI -->|"builds"| VP
    BI -->|"builds"| Inc
    BI -->|"builds"| Engine
    BI -->|"builds"| GUI
    BI -->|"builds"| Ex
    BI -->|"builds"| Te

    %% Relationships between components
    VP -->|"model_integration"| Inc
    Src -->|"FMI_functions"| Engine
    Engine <-->|"simulation_interface"| GUI
    Ex -->|"example_calls"| Engine
    Te -->|"automated_tests"| Engine

    %% Click Events for FMU Models
    click BB "https://github.com/weiche/reference-fmus-min/tree/main/BouncingBall"
    click CL "https://github.com/weiche/reference-fmus-min/tree/main/Clocks"
    click DA "https://github.com/weiche/reference-fmus-min/tree/main/Dahlquist"
    click FT "https://github.com/weiche/reference-fmus-min/tree/main/Feedthrough"
    click RE "https://github.com/weiche/reference-fmus-min/tree/main/Resource"
    click ST "https://github.com/weiche/reference-fmus-min/tree/main/Stair"
    click SS "https://github.com/weiche/reference-fmus-min/tree/main/StateSpace"
    click VP "https://github.com/weiche/reference-fmus-min/tree/main/VanDerPol"

    %% Click Events for Simulation Engine and GUI
    click Engine "https://github.com/weiche/reference-fmus-min/tree/main/fmusim"
    click GUI "https://github.com/weiche/reference-fmus-min/tree/main/fmusim-gui"

    %% Click Events for Common FMI Library
    click Inc "https://github.com/weiche/reference-fmus-min/tree/main/include"
    click Src "https://github.com/weiche/reference-fmus-min/tree/main/src"

    %% Click Events for Build Infrastructure
    click CMake "https://github.com/weiche/reference-fmus-min/blob/main/CMakeLists.txt"
    click BS "https://github.com/weiche/reference-fmus-min/tree/main/build"
    click CI "https://github.com/weiche/reference-fmus-min/tree/main/.github/workflows"
    click BI "https://github.com/weiche/reference-fmus-min/blob/main/CMakeLists.txt"

    %% Click Events for Examples and Tests
    click Ex "https://github.com/weiche/reference-fmus-min/tree/main/examples"
    click Te "https://github.com/weiche/reference-fmus-min/tree/main/tests"

    %% Styles
    classDef build fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef fmu fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef lib fill:#ffa500,stroke:#000,stroke-width:1px;
    classDef sim fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef test fill:#ffeb3b,stroke:#000,stroke-width:1px;
```
