# natlabrockies/fastsim architecture

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

- Interactive diagram: https://gitdiagram.com/natlabrockies/fastsim
- Repository: https://github.com/natlabrockies/fastsim

## Overview

1. **What this repo is**
   - FASTSim-3 is a vehicle energy and powertrain simulation system centered on a Rust core, with Python bindings and a small CLI.
   - The main architectural goal is to simulate a vehicle over a drive cycle and return cumulative and optionally time-resolved results, with stronger model modularity than FASTSim-2.

2. **Top-level layering**
   - **`fastsim-core`** is the simulation engine and domain model library.
   - **`fastsim-py`** and **`python/fastsim`** expose the Rust engine to Python users.
   - **`fastsim-cli`** provides a command-line entry point.
   - The rest of the repo is support code: validation/calibration, benchmarks, docs, and CI/release automation.

3. **Core simulation boundary**
   - `fastsim-core` contains the actual physics/model logic: vehicle behavior, drive-cycle handling, road load, energy conversion, and result tracking.
   - The runtime flow is: vehicle definition + drive cycle + model parameters → simulation step loop → cumulative outputs and optional saved history.
   - The README’s `save_interval` behavior is reflected in the architecture: the engine can retain every timestep, every Nth timestep, or only the final cumulative state for speed and memory savings.

4. **Vehicle model subsystem**
   - `fastsim-core/src/vehicle` is the main domain boundary for model types.
   - It is organized into component-centric models such as `conv` (conventional), `hev`, `bev`, `cabin`, `hvac`, `chassis`, and `powertrain`.
   - Powertrain internals are split further into `electric_machine`, `fuel_converter`, `fuel_storage`, `reversible_energy_storage`, and `transmission`, which supports the repo’s “component-specific vehicle models” design.
   - `vehicle_model` and `vehicle_utils` provide higher-level assembly and compatibility logic, including FASTSim-2 interop.

5. **Drive cycle and motion inputs**
   - `fastsim-core/src/drive_cycle` and `resources/cycles` define the motion profile inputs, with CSV cycle resources such as `udds.csv` and `hwfet.csv`.
   - This subsystem includes cycle manipulation and maneuver utilities, indicating the engine can transform or augment raw cycle data before simulation.
   - `simdrive` is the operational layer that combines vehicle + cycle + road load to produce results.

6. **Results, state, and interpolation**
   - `utils/interp.rs`, `tracked_state.rs`, and `traits` suggest a reusable infrastructure for interpolation, state tracking, and polymorphic model behavior.
   - `simdrivelabel` and `longparams.json` appear to define standardized output labels/parameter naming for simulation results.
   - `resources/interpolators` holds YAML-defined interpolation tables, which is important because the repo emphasizes more accurate interpolation and flexible model interfacing.

7. **Compile-time extensibility**
   - `fastsim-core/fastsim-proc-macros` is a separate proc-macro crate used to derive common behavior such as serde support, Python API helpers, cycle-related traits, and history vector handling.
   - This is a meaningful architectural boundary: runtime simulation lives in `fastsim-core`, while repetitive interface/serialization code is generated at compile time.

8. **Python integration layer**
   - `fastsim-py` is the Rust crate that builds the Python extension module.
   - `python/fastsim` is the user-facing Python package, with typed stubs (`fastsim.pyi`), utilities, demos, and tests.
   - The Python layer is not the simulation engine itself; it is a wrapper and convenience API around the Rust core, which is what enables the high-performance Python experience described in the README.

9. **User-facing Python workflows**
   - `python/fastsim/demos` contains scenario scripts for conventional, HEV, BEV, thermal, stop-start, trace-miss, and CAVS-style workflows.
   - `python/fastsim/tests` validates serialization, resource loading, utilities, and performance-related behavior.
   - `python/fastsim/utils` and `copy_stub_docstrings.py` support packaging quality and API ergonomics, not core simulation logic.

10. **CLI and executable entry points**
   - `fastsim-cli/src/main.rs` is the standalone command-line application layer.
   - `fastsim-core/src/bin/...` includes at least one Rust binary example for running a specific simulation scenario directly from the core crate.
   - These entry points sit on top of the same domain engine used by Python, so diagrammatically they are alternative front doors into the same simulation core.

11. **Calibration and validation pipeline**
   - `cal_and_val` contains a substantial validation harness, including `f2-to-f3` translation tests and thermal validation for BEV/HEV models.
   - The `f2-vehicles` and `f3-vehicles` directories provide paired FASTSim-2 and FASTSim-3 vehicle definitions for regression/comparison.
   - `cal_and_val/thermal` adds BEV/HEV thermal calibration/validation scripts and dyno data handling, showing that the repo includes model verification as a first-class workflow rather than a separate project.

12. **Benchmarking and performance focus**
   - `benchmarks` includes Python benchmark scripts and test harnesses, which aligns with the README’s emphasis on speed and memory reduction.
   - The performance axis is part of the architecture: the engine is designed to support different levels of output retention, and the benchmark suite measures those tradeoffs.

13. **Data and asset model**
   - The repository is data-driven: vehicles, cycles, interpolators, and validation fixtures are stored as YAML/CSV/JSON resources alongside code.
   - This separation matters architecturally because many simulations are parameterized by resource files rather than hardcoded model instances.
   - The core crate’s `resources/vehicles` and `src/vehicle/*.yaml` show both packaged examples and regression fixtures for expected model behavior.

14. **Build, docs, and release plumbing**
   - GitHub Actions workflows cover build/test, release, and docs deployment.
   - `docs` is an mdBook-style documentation site, likely used as the hosted product documentation referenced in the README.
   - `Cargo.toml`, `pyproject.toml`, `MANIFEST.in`, and lockfiles show the repo is a mixed Rust/Python package with coordinated packaging and release steps.

15. **How to draw the architecture**
   - Put **Rust core simulation** in the center.
   - Feed it with **vehicle definitions**, **cycle inputs**, and **interpolator/resource files**.
   - Show two primary consumers: **Python package/bindings** and **CLI/binary entry points**.
   - Surround the core with **validation/calibration**, **benchmarks**, and **docs/CI**, which are not runtime dependencies but are essential supporting subsystems.

Main entry points: [`fastsim-core/src/lib.rs`](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/lib.rs) (Core engine), [`fastsim-core/src/simdrive.rs`](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/simdrive.rs) (SimDrive), [`cal_and_val/f2-validation.py`](https://github.com/natlabrockies/fastsim/blob/fastsim-3/cal_and_val/f2-validation.py) (Validation), [`fastsim-py/src/lib.rs`](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-py/src/lib.rs) (Py bindings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Rust core"]
  node_core_lib["Core engine<br/>rust crate<br/>[lib.rs]"]
  node_simdrive["SimDrive<br/>simulation loop<br/>[simdrive.rs]"]
  node_vehicle_model["Vehicle model<br/>domain assembly<br/>[vehicle_model.rs]"]
  node_powertrain["Powertrain<br/>component models<br/>[mod.rs]"]
  node_drive_cycle["Drive cycle<br/>motion inputs<br/>[drive_cycle.rs]"]
  node_roadload["Road load<br/>resistance model<br/>[roadload.rs]"]
  node_results["Results state<br/>tracking/output<br/>[tracked_state.rs]"]
  node_interp["Interpolation<br/>[interp.rs]"]
  node_traits["Shared traits<br/>abstractions<br/>[traits.rs]"]
  node_proc_macros["Proc macros<br/>macro crate<br/>[lib.rs]"]
  node_resources[("Resources<br/>data assets<br/>[udds.csv]")]
end

subgraph group_python["Python layer"]
  node_fastsim_py_crate["Py bindings<br/>rust extension<br/>[lib.rs]"]
  node_python_pkg["Python package<br/>[__init__.py]"]
  node_demos["Demos<br/>examples<br/>[demo_conv.py]"]
end

subgraph group_support["Supporting workflows"]
  node_cli["CLI<br/>rust binary<br/>[main.rs]"]
  node_validation["Validation<br/>calibration suite<br/>[f2-validation.py]"]
  node_benchmarks["Benchmarks<br/>performance suite"]
  node_docs["Docs<br/>book<br/>[intro.md]"]
  node_ci["CI / release<br/>automation"]
end

node_repo{{"fastsim<br/>monorepo"}}

node_repo -->|"contains"| node_core_lib
node_repo -->|"contains"| node_fastsim_py_crate
node_repo -->|"contains"| node_python_pkg
node_repo -->|"contains"| node_cli
node_repo -->|"contains"| node_validation
node_repo -->|"contains"| node_benchmarks
node_repo -->|"contains"| node_docs
node_repo -->|"contains"| node_ci
node_core_lib -->|"orchestrates"| node_simdrive
node_simdrive -->|"uses"| node_vehicle_model
node_simdrive -->|"uses"| node_drive_cycle
node_simdrive -->|"computes"| node_roadload
node_vehicle_model -->|"composes"| node_powertrain
node_simdrive -->|"emits"| node_results
node_results -->|"relies on"| node_interp
node_core_lib -->|"defines"| node_traits
node_core_lib -.->|"augmented by"| node_proc_macros
node_core_lib -->|"loads"| node_resources
node_fastsim_py_crate -->|"wraps"| node_core_lib
node_python_pkg -->|"imports"| node_fastsim_py_crate
node_demos -->|"uses"| node_python_pkg
node_cli -->|"invokes"| node_core_lib
node_validation -->|"compares"| node_core_lib
node_validation -->|"uses"| node_resources
node_benchmarks -->|"measures"| node_core_lib
node_docs -.->|"documents"| node_core_lib
node_ci -.->|"automates"| node_repo

click node_core_lib "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/lib.rs"
click node_simdrive "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/simdrive.rs"
click node_vehicle_model "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/vehicle/vehicle_model.rs"
click node_powertrain "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/vehicle/powertrain/mod.rs"
click node_drive_cycle "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/drive_cycle.rs"
click node_roadload "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/simdrive/roadload.rs"
click node_results "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/utils/tracked_state.rs"
click node_interp "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/utils/interp.rs"
click node_traits "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/traits.rs"
click node_proc_macros "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/fastsim-proc-macros/src/lib.rs"
click node_resources "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/resources/cycles/udds.csv"
click node_fastsim_py_crate "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-py/src/lib.rs"
click node_python_pkg "https://github.com/natlabrockies/fastsim/blob/fastsim-3/python/fastsim/__init__.py"
click node_demos "https://github.com/natlabrockies/fastsim/blob/fastsim-3/python/fastsim/demos/demo_conv.py"
click node_cli "https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-cli/src/main.rs"
click node_validation "https://github.com/natlabrockies/fastsim/blob/fastsim-3/cal_and_val/f2-validation.py"
click node_benchmarks "https://github.com/natlabrockies/fastsim/blob/fastsim-3/benchmarks/f3-save-int-none.py"
click node_docs "https://github.com/natlabrockies/fastsim/blob/fastsim-3/docs/src/intro.md"
click node_ci "https://github.com/natlabrockies/fastsim/blob/fastsim-3/.github/workflows/build_and_test.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_core_lib,node_simdrive,node_vehicle_model,node_powertrain,node_drive_cycle,node_roadload,node_results,node_interp,node_traits,node_proc_macros,node_resources toneBlue
class node_fastsim_py_crate,node_python_pkg,node_demos toneAmber
class node_cli,node_validation,node_benchmarks,node_docs,node_ci toneMint
class node_repo toneNeutral
```

## Components

### Rust core

Simulation engine, domain model, and compile-time extension layer.

- [Core engine](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/lib.rs): rust crate · Main simulation library and domain model boundary. · `fastsim-core/src/lib.rs`
- [SimDrive](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/simdrive.rs): simulation loop · Combines vehicle, cycle, and road load to produce results. · `fastsim-core/src/simdrive.rs`
- [Vehicle model](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/vehicle/vehicle_model.rs): domain assembly · High-level vehicle composition and FASTSim-2 compatibility layer. · `fastsim-core/src/vehicle/vehicle_model.rs`
- [Powertrain](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/vehicle/powertrain/mod.rs): component models · Electric, fuel, storage, and transmission submodels. · `fastsim-core/src/vehicle/powertrain/mod.rs`
- [Drive cycle](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/drive_cycle.rs): motion inputs · Cycle handling, manipulation, and maneuver utilities. · `fastsim-core/src/drive_cycle.rs`
- [Road load](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/simdrive/roadload.rs): resistance model · Road-load calculations used during the simulation step loop. · `fastsim-core/src/simdrive/roadload.rs`
- [Results state](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/utils/tracked_state.rs): tracking/output · Tracked state, interpolation, and labeled cumulative outputs. · `fastsim-core/src/utils/tracked_state.rs`
- [Interpolation](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/utils/interp.rs): utility · Reusable interpolation helpers and lookup behavior. · `fastsim-core/src/utils/interp.rs`
- [Shared traits](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/src/traits.rs): abstractions · Common trait interfaces and serde-related behavior. · `fastsim-core/src/traits.rs`
- [Proc macros](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/fastsim-proc-macros/src/lib.rs): macro crate · Derives and helpers for serde, Python, cycle, and history behavior. · `fastsim-core/fastsim-proc-macros/src/lib.rs`
- [Resources](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-core/resources/cycles/udds.csv): data assets · Packaged vehicles, cycles, and interpolation tables. · `fastsim-core/resources/cycles/udds.csv`

### Python layer

Bindings, package API, demos, and Python-side utilities.

- [Py bindings](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-py/src/lib.rs): rust extension · Rust crate that builds the Python extension module. · `fastsim-py/src/lib.rs`
- [Python package](https://github.com/natlabrockies/fastsim/blob/fastsim-3/python/fastsim/__init__.py): package · User-facing Python API and type stubs. · `python/fastsim/__init__.py`
- [Demos](https://github.com/natlabrockies/fastsim/blob/fastsim-3/python/fastsim/demos/demo_conv.py): examples · Scenario scripts for vehicle and thermal workflows. · `python/fastsim/demos/demo_conv.py`

### Supporting workflows

Validation, benchmarking, docs, and release automation.

- [CLI](https://github.com/natlabrockies/fastsim/blob/fastsim-3/fastsim-cli/src/main.rs): rust binary · Standalone command-line entry point. · `fastsim-cli/src/main.rs`
- [Validation](https://github.com/natlabrockies/fastsim/blob/fastsim-3/cal_and_val/f2-validation.py): calibration suite · FASTSim-2/3 regression, translation, and thermal validation. · `cal_and_val/f2-validation.py`
- [Benchmarks](https://github.com/natlabrockies/fastsim/blob/fastsim-3/benchmarks/f3-save-int-none.py): performance suite · Python benchmarks used to measure runtime and save-interval tradeoffs. · `benchmarks/f3-save-int-none.py`
- [Docs](https://github.com/natlabrockies/fastsim/blob/fastsim-3/docs/src/intro.md): book · Documentation site and release notes content. · `docs/src/intro.md`
- [CI / release](https://github.com/natlabrockies/fastsim/blob/fastsim-3/.github/workflows/build_and_test.yaml): automation · Workflow automation for build, test, docs, and release. · `.github/workflows/build_and_test.yaml`

### Other components

- **fastsim**: monorepo · Mixed Rust/Python repository for vehicle energy simulation.

## Connections

- fastsim → Core engine: contains · Repository includes the Rust simulation core.
- fastsim → Py bindings: contains · Repository includes the Python extension crate.
- fastsim → Python package: contains · Repository includes the user-facing Python package.
- fastsim → CLI: contains · Repository includes the command-line entry point.
- fastsim → Validation: contains · Repository includes calibration and validation workflows.
- fastsim → Benchmarks: contains · Repository includes benchmark scripts.
- fastsim → Docs: contains · Repository includes documentation sources.
- fastsim → CI / release: contains · Repository includes workflow automation.
- Core engine → SimDrive: orchestrates · Core library centers the simulation loop.
- SimDrive → Vehicle model: uses · Simulation loop consumes vehicle definitions and assembly.
- SimDrive → Drive cycle: uses · Simulation loop consumes drive-cycle inputs.
- SimDrive → Road load: computes · Road-load model feeds the stepwise energy demand.
- Vehicle model → Powertrain: composes · Vehicle model is built from component-centric powertrain models.
- SimDrive → Results state: emits · Simulation produces cumulative and optional time-resolved outputs.
- Results state → Interpolation: relies on · Output/state handling uses interpolation helpers.
- Core engine → Shared traits: defines · Core library exposes shared abstractions and behavior contracts.
- Core engine → Proc macros: augmented by · Compile-time macros generate repetitive API and serialization code.
- Core engine → Resources: loads · Core simulation is parameterized by packaged resource files.
- Py bindings → Core engine: wraps · Python extension exposes the Rust core.
- Python package → Py bindings: imports · Package API sits on top of the extension module.
- Demos → Python package: uses · Demos exercise the Python API.
- CLI → Core engine: invokes · CLI is an alternate front door into the same core engine.
- Validation → Core engine: compares · Validation checks FASTSim-2/3 behavior against the core.
- Validation → Resources: uses · Validation relies on paired vehicle and thermal fixtures.
- Benchmarks → Core engine: measures · Benchmarks quantify runtime and save-interval behavior.
- Docs → Core engine: documents · Docs describe the simulation engine and workflows.
- CI / release → fastsim: automates · Workflows build, test, publish, and deploy documentation.
