# priyanshuiitghy2006/opentrim architecture

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

- Interactive diagram: https://gitdiagram.com/priyanshuiitghy2006/opentrim
- Repository: https://github.com/priyanshuiitghy2006/opentrim

## Overview

OpenTRIM is a Monte Carlo ion-transport and radiation-damage simulator, exposed as a command-line program, a GUI, and a C++ library. The central workflow configures and validates a run, creates a simulation driver, transports ions and recoil cascades through a material target, tallies results, and saves output. The README documents the CLI and GUI capabilities; source excerpts and the SOURCE INDEX support the driver/core relationships and identify the physics modules. Several GUI and persistence details are documented but their implementation was not sampled, so those links are limited to documented behavior.

Main entry points: [`source/lib/mccore.cpp`](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/mccore.cpp) (Monte Carlo core), [`source/cli/main.cpp`](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/cli/main.cpp) (CLI application), [`source/gui`](https://github.com/priyanshuiitghy2006/opentrim/tree/main/source/gui) (GUI application), [`source/gui/tabularview.cpp`](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/gui/tabularview.cpp) (GUI results)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["CLI application<br/>[main.cpp]"]
  node_gui["GUI application"]
  node_gui_config["GUI configuration"]
  node_gui_target["Target editor"]
  node_gui_results["GUI results<br/>[tabularview.cpp]"]
end

subgraph group_control["Run control"]
  node_config["Simulation config<br/>[mcdriver.h]"]
  node_json["JSON parsing<br/>[parse_json.cpp]"]
  node_driver["Simulation driver<br/>[mcdriver.cpp]"]
end

subgraph group_physics["Transport physics"]
  node_core["Monte Carlo core<br/>[mccore.cpp]"]
  node_ions["Ion state<br/>[ion.cpp]"]
  node_beam["Ion beam<br/>[ion_beam.cpp]"]
  node_target["Target materials<br/>[target.cpp]"]
  node_geometry["Geometry<br/>[geometry.h]"]
  node_scattering["Scattering<br/>[scattering.h]"]
  node_stopping["Stopping and straggling<br/>[dedx.cpp]"]
  node_cascade["Recoil cascades<br/>[cascade.cpp]"]
  node_flight["Flight paths<br/>[flight_path.cpp]"]
end

subgraph group_results["Results and storage"]
  node_tallies["Damage tallies<br/>[tally.cpp]"]
  node_user_tallies["Custom tallies<br/>[user_tally.cpp]"]
  node_events["Event stream<br/>[event_stream.cpp]"]
  node_hdf5[("HDF5 archive<br/>[h5serialize.cpp]")]
end

node_user(("User"))
node_archive[("HDF5 file")]

node_user -->|"runs batch"| node_cli
node_user -->|"configures and runs"| node_gui
node_gui -.->|"configures through"| node_gui_config
node_gui -.->|"edits target"| node_gui_target
node_gui -.->|"evaluates results"| node_gui_results
node_cli -->|"executes"| node_driver
node_cli -->|"sets run options"| node_config
node_cli -->|"saves results"| node_hdf5
node_config -.->|"parses configuration"| node_json
node_driver -->|"creates and runs"| node_core
node_core -->|"uses scattering"| node_scattering
node_core -->|"transports through"| node_target
node_core -->|"calculates energy loss"| node_stopping
node_core -->|"generates ions from"| node_beam
node_core -->|"transports ions"| node_ions
node_core -->|"calculates flight paths"| node_flight
node_core -->|"processes recoils"| node_cascade
node_core -->|"updates tallies"| node_tallies
node_core -->|"supports tallies"| node_user_tallies
node_core -->|"records events"| node_events
node_target -->|"defines spatial layout"| node_geometry
node_hdf5 -.->|"writes"| node_archive
node_gui_results -->|"displays tally data"| node_tallies

click node_cli "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/cli/main.cpp"
click node_gui "https://github.com/priyanshuiitghy2006/opentrim/tree/main/source/gui"
click node_gui_config "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/gui/simulationoptionsview.cpp"
click node_gui_target "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/gui/materialsdefview.cpp"
click node_gui_results "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/gui/tabularview.cpp"
click node_config "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/include/mcdriver.h"
click node_json "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/parse_json.cpp"
click node_driver "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/mcdriver.cpp"
click node_core "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/mccore.cpp"
click node_ions "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/ion.cpp"
click node_beam "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/ion_beam.cpp"
click node_target "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/target.cpp"
click node_geometry "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/include/geometry.h"
click node_scattering "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/include/scattering.h"
click node_stopping "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/dedx.cpp"
click node_cascade "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/cascade.cpp"
click node_flight "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/flight_path.cpp"
click node_tallies "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/tally.cpp"
click node_user_tallies "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/user_tally.cpp"
click node_events "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/event_stream.cpp"
click node_hdf5 "https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/h5serialize.cpp"

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_cli,node_gui,node_gui_config,node_gui_target,node_gui_results,node_user toneBlue
class node_config,node_json,node_driver,node_archive toneAmber
class node_core,node_ions,node_beam,node_target,node_geometry,node_scattering,node_stopping,node_cascade,node_flight toneMint
class node_tallies,node_user_tallies,node_events,node_hdf5 toneRose
```

## Components

### User interfaces

- [CLI application](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/cli/main.cpp): `source/cli/main.cpp`
- [GUI application](https://github.com/priyanshuiitghy2006/opentrim/tree/main/source/gui): `source/gui`
- [GUI configuration](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/gui/simulationoptionsview.cpp): `source/gui/simulationoptionsview.cpp`
- [Target editor](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/gui/materialsdefview.cpp): `source/gui/materialsdefview.cpp`
- [GUI results](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/gui/tabularview.cpp): `source/gui/tabularview.cpp`

### Run control

- [Simulation config](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/include/mcdriver.h): `source/include/mcdriver.h`
- [JSON parsing](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/parse_json.cpp): `source/lib/parse_json.cpp`
- [Simulation driver](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/mcdriver.cpp): `source/lib/mcdriver.cpp`

### Transport physics

- [Monte Carlo core](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/mccore.cpp): `source/lib/mccore.cpp`
- [Ion state](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/ion.cpp): `source/lib/ion.cpp`
- [Ion beam](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/ion_beam.cpp): `source/lib/ion_beam.cpp`
- [Target materials](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/target.cpp): `source/lib/target.cpp`
- [Geometry](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/include/geometry.h): `source/include/geometry.h`
- [Scattering](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/include/scattering.h): `source/include/scattering.h`
- [Stopping and straggling](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/dedx.cpp): `source/lib/dedx.cpp`
- [Recoil cascades](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/cascade.cpp): `source/lib/cascade.cpp`
- [Flight paths](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/flight_path.cpp): `source/lib/flight_path.cpp`

### Results and storage

- [Damage tallies](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/tally.cpp): `source/lib/tally.cpp`
- [Custom tallies](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/user_tally.cpp): `source/lib/user_tally.cpp`
- [Event stream](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/event_stream.cpp): `source/lib/event_stream.cpp`
- [HDF5 archive](https://github.com/priyanshuiitghy2006/opentrim/blob/main/source/lib/h5serialize.cpp): `source/lib/h5serialize.cpp`

### Other components

- **User**
- **HDF5 file**

## Connections

- User → CLI application: runs batch (evidence: `README.md`)
- User → GUI application: configures and runs (evidence: `README.md`)
- GUI application → GUI configuration: configures through
- GUI application → Target editor: edits target (evidence: `source/gui/materialsdefview.cpp`)
- GUI application → GUI results: evaluates results (evidence: `README.md`)
- CLI application → Simulation driver: executes (evidence: `source/cli/main.cpp`)
- CLI application → Simulation config: sets run options (evidence: `source/cli/main.cpp`)
- CLI application → HDF5 archive: saves results (evidence: `README.md`)
- Simulation config → JSON parsing: parses configuration (evidence: `source/lib/parse_json.cpp`)
- Simulation driver → Monte Carlo core: creates and runs
- Monte Carlo core → Scattering: uses scattering (evidence: `source/lib/mccore.cpp`)
- Monte Carlo core → Target materials: transports through
- Monte Carlo core → Stopping and straggling: calculates energy loss
- Monte Carlo core → Ion beam: generates ions from
- Monte Carlo core → Ion state: transports ions
- Monte Carlo core → Flight paths: calculates flight paths
- Monte Carlo core → Recoil cascades: processes recoils (evidence: `source/lib/mccore.cpp`)
- Monte Carlo core → Damage tallies: updates tallies
- Monte Carlo core → Custom tallies: supports tallies
- Monte Carlo core → Event stream: records events
- Target materials → Geometry: defines spatial layout
- HDF5 archive → HDF5 file: writes (evidence: `README.md`)
- GUI results → Damage tallies: displays tally data (evidence: `source/gui/tabularview.cpp`)
