# openmdao/cadre architecture

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

- Interactive diagram: https://gitdiagram.com/openmdao/cadre
- Repository: https://github.com/openmdao/cadre

## Overview

##### Project Type and Purpose
- This is a Python-based scientific/engineering library implementing the CADRE CubeSat design problem using the OpenMDAO framework.
- Its primary purpose is to model and optimize satellite subsystems (power, attitude, communication, thermal, propulsion, etc.) via a composite OpenMDAO Group and optionally drive a Markov Decision Process (MDP) solver or an optimizer (SNOPT, MPI-parallel runs with PETSc4py).

##### File Structure Analysis
- Top level:
- CADRE/            ← Package source
- examples/         ← Entry-point scripts demonstrating usage
- benchmark/, profile/ ← Performance tests
- .github/, CI config
- pyproject.toml    ← Build and dependency metadata
- CADRE/ directory:
- CADRE_group.py    ← Assembles the OpenMDAO model (Group)
- CADRE_mdp.py      ← Defines the MDP formulation for discrete decision problems
- Modules for each subsystem: attitude.py, battery.py, comm.py, kinematics.py, orbit.py, power.py, reactionwheel.py, solar.py, sun.py, thermal_temperature.py
- integrators: explicit.py, rk4.py
- parameters.py     ← Shared input parameters
- data/             ← Tables and files used by subsystem models
- test/             ← Unit tests and pickled test data

##### Key Insights from README
- Relies on OpenMDAO 3.x, optional dependencies for optimization (pyOptSparse/SNOPT) and parallel runs (mpi4py, petsc4py).
- Contains examples (mdp.py, mppt.py, plot_progress.py) illustrating how to instantiate and run the model.

##### Main Components
- User Entry Points (examples/*.py)
- CADRE_group (OpenMDAO Group)
- Subsystem Components (one per Python module: Power, Solar, Battery, Comm, Attitude, ReactionWheel, Kinematics, Orbit, Thermal, Sun)
- Numerical Tools (RK4 integrator, explicit derivative methods)
- MDP Solver (CADRE_mdp)
- Data Sources (CSV, DAT, Fortran scripts under CADRE/data)
- Optimization Layer (pyOptSparse→SNOPT or OpenMDAO drivers)
- Parallel Infrastructure (mpi4py → PETSc4py)
- Output/Visualization (plot_progress example, console logs, benchmark outputs)

##### Relationships and Data Flow
- Example script → instantiates CADRE_group → supplies parameters →
- Data Sources feed initialization of subsystem components
- Each component computes outputs (power generation, battery state, attitude control torques, communication link margins, thermal balance)
- RK4/explicit integrate dynamic states over time
- CADRE_group collects outputs, computes objective(s) & constraints
- For MDP problems: CADRE_mdp orchestrates sequences of calls to the OpenMDAO model
- Optimization driver (SNOPT or OpenMDAO’s built-in drivers) interrogates CADRE_group via fwd/rev mode for gradients
- For parallel runs: driver and model distributed via MPI/PETSc
- Final results passed back to user or written to disk

##### Architectural Patterns and Design Principles
- Modular component architecture: each subsystem is an independent OpenMDAO Component
- Composite pattern: CADRE_group assembles subsystems into a coupled system
- Separation of concerns: data, model definition, integration, optimization, and test code live in distinct folders
- Extensibility via standard OpenMDAO APIs: adding new subsystems or solvers
- Optional parallelism and pluggable optimizers

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interface Layer
    subgraph "User Entry Points"
        direction TB
        MDPScript["examples/mdp.py"]:::ui
        MPPTScript["examples/mppt.py"]:::ui
        PlotScript["examples/plot_progress.py"]:::ui
    end

    %% Assembly Layer
    subgraph "Assembly Layer"
        direction TB
        Group["CADRE_group"]:::assembly
        MDPWrapper["CADRE_mdp"]:::assembly
    end

    %% Component Layer
    subgraph "Component Layer"
        direction TB
        Attitude["Attitude Component"]:::component
        Battery["Battery Component"]:::component
        Comm["Communication Component"]:::component
        Kinematics["Kinematics Component"]:::component
        Orbit["Orbit Component"]:::component
        Power["Power Component"]:::component
        ReactionWheel["Reaction Wheel Component"]:::component
        Solar["Solar Array Component"]:::component
        Sun["Sun Model Component"]:::component
        Thermal["Thermal Temperature Component"]:::component
        Parameters["Shared Parameters"]:::component
    end

    %% Numerical Tools
    subgraph "Numerical Tools"
        direction TB
        Explicit["Explicit Derivative Integrator"]:::component
        RK4["RK4 Integrator"]:::component
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DataFolder["CADRE/data"]:::data
    end

    %% Solver/Driver Layer
    subgraph "Solver/Driver Layer"
        direction TB
        OpenMDAO["OpenMDAO Driver"]:::solver
        SNOPT["SNOPT Driver"]:::solver
    end

    %% Parallel Infrastructure
    subgraph "Parallel Infrastructure"
        direction TB
        MPI["mpi4py"]:::external
        PETSc["petsc4py"]:::external
    end

    %% Benchmark & Test
    subgraph "Testing & Benchmarking"
        direction TB
        Tests["CADRE/test"]:::external
        Benchmarks["benchmark/"]:::external
        Profiling["profile/"]:::external
    end

    %% Connections
    MDPScript -->|"runs MDP"| MDPWrapper
    MPPTScript -->|instantiates| Group
    PlotScript -->|reads results| Group

    DataFolder -->|feeds parameters| Attitude
    DataFolder -->|feeds parameters| Battery
    DataFolder -->|feeds parameters| Comm
    DataFolder -->|feeds parameters| Kinematics
    DataFolder -->|feeds parameters| Orbit
    DataFolder -->|feeds parameters| Power
    DataFolder -->|feeds parameters| ReactionWheel
    DataFolder -->|feeds parameters| Solar
    DataFolder -->|feeds parameters| Sun
    DataFolder -->|feeds parameters| Thermal
    DataFolder -->|feeds parameters| Parameters

    Attitude -->|component| Group
    Battery -->|component| Group
    Comm -->|component| Group
    Kinematics -->|component| Group
    Orbit -->|component| Group
    Power -->|component| Group
    ReactionWheel -->|component| Group
    Solar -->|component| Group
    Sun -->|component| Group
    Thermal -->|component| Group
    Parameters -->|shared inputs| Group

    Solar -->|sunlight| Power
    Orbit -->|geometry| Sun

    Explicit -->|integration| Group
    RK4 -->|integration| Group

    Group -->|"control"| OpenMDAO
    Group -->|"objective/constraint"| SNOPT
    MDPWrapper -->|"calls model"| Group

    OpenMDAO -->|parallel| MPI
    SNOPT -->|parallel| PETSc

    Tests -->|validate| Group
    Benchmarks -->|performance| Group
    Profiling -->|profiling| Group

    %% Click Events
    click MDPScript "https://github.com/openmdao/cadre/blob/master/examples/mdp.py"
    click MPPTScript "https://github.com/openmdao/cadre/blob/master/examples/mppt.py"
    click PlotScript "https://github.com/openmdao/cadre/blob/master/examples/plot_progress.py"
    click Group "https://github.com/openmdao/cadre/blob/master/CADRE/CADRE_group.py"
    click MDPWrapper "https://github.com/openmdao/cadre/blob/master/CADRE/CADRE_mdp.py"
    click Attitude "https://github.com/openmdao/cadre/blob/master/CADRE/attitude.py"
    click Battery "https://github.com/openmdao/cadre/blob/master/CADRE/battery.py"
    click Comm "https://github.com/openmdao/cadre/blob/master/CADRE/comm.py"
    click Kinematics "https://github.com/openmdao/cadre/blob/master/CADRE/kinematics.py"
    click Orbit "https://github.com/openmdao/cadre/blob/master/CADRE/orbit.py"
    click Power "https://github.com/openmdao/cadre/blob/master/CADRE/power.py"
    click ReactionWheel "https://github.com/openmdao/cadre/blob/master/CADRE/reactionwheel.py"
    click Solar "https://github.com/openmdao/cadre/blob/master/CADRE/solar.py"
    click Sun "https://github.com/openmdao/cadre/blob/master/CADRE/sun.py"
    click Thermal "https://github.com/openmdao/cadre/blob/master/CADRE/thermal_temperature.py"
    click Explicit "https://github.com/openmdao/cadre/blob/master/CADRE/explicit.py"
    click RK4 "https://github.com/openmdao/cadre/blob/master/CADRE/rk4.py"
    click Parameters "https://github.com/openmdao/cadre/blob/master/CADRE/parameters.py"
    click DataFolder "https://github.com/openmdao/cadre/tree/master/CADRE/data/"
    click Tests "https://github.com/openmdao/cadre/tree/master/CADRE/test/"
    click Benchmarks "https://github.com/openmdao/cadre/tree/master/benchmark/"
    click Profiling "https://github.com/openmdao/cadre/tree/master/profile/"

    %% Styles
    classDef ui fill:#f9f,stroke:#333,stroke-width:1px
    classDef assembly fill:#0d3,stroke:#023,stroke-width:2px
    classDef component fill:#bbf,stroke:#88f,stroke-width:1px
    classDef data fill:#ccc,stroke:#666,stroke-width:1px,stroke-dasharray: 4 2
    classDef solver fill:#faa,stroke:#c33,stroke-width:1px
    classDef external fill:#ffeb99,stroke:#aa6,stroke-width:1px,stroke-dasharray: 2 2
```
