# pmocz/dsmc-python architecture

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

- Interactive diagram: https://gitdiagram.com/pmocz/dsmc-python
- Repository: https://github.com/pmocz/dsmc-python

## Overview

This is a compact, single-script DSMC simulation of dilute gas in the Rayleigh problem. Running `dsmc.py` configures the simulation, initializes sampling particles, advances them through drift, wall interactions and cell-based collisions, records velocity statistics, then compares the result with BGK theory and plots and saves the figures. These stages are implemented together in one file rather than separate modules; the graph preserves their runtime order and shows the external numerical and plotting libraries.

Main entry points: [`dsmc.py`](https://github.com/pmocz/dsmc-python/blob/main/dsmc.py) (Simulation setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_simulation["Simulation"]
  node_entry["Run simulation<br/>[dsmc.py]"]
  node_setup["Simulation setup<br/>[dsmc.py]"]
  node_particles["Particle initialization<br/>[dsmc.py]"]
  node_motion["Particle drift<br/>[dsmc.py]"]
  node_walls["Wall interactions<br/>[dsmc.py]"]
  node_collisions["Cell collisions<br/>[dsmc.py]"]
end

subgraph group_analysis["Analysis and plots"]
  node_statistics["Velocity statistics<br/>[dsmc.py]"]
  node_theory["BGK comparison<br/>[dsmc.py]"]
  node_visualization["Plot results<br/>[dsmc.py]"]
end

node_user(("User"))
node_numpy["NumPy"]
node_scipy["SciPy special"]
node_matplotlib["Matplotlib"]
node_figure["Saved figure"]

node_user -->|"runs"| node_entry
node_entry -->|"configures"| node_setup
node_setup -->|"sets parameters"| node_particles
node_particles -->|"advances"| node_motion
node_motion -->|"handles boundaries"| node_walls
node_walls -->|"updates particles"| node_collisions
node_collisions -->|"records velocities"| node_statistics
node_statistics -->|"compares with"| node_theory
node_theory -->|"plots comparison"| node_visualization
node_visualization -->|"saves"| node_figure
node_setup -->|"computes with"| node_numpy
node_particles -->|"samples with"| node_numpy
node_collisions -->|"computes with"| node_numpy
node_theory -->|"uses Bessel function"| node_scipy
node_visualization -->|"plots and saves"| node_matplotlib

click node_entry "https://github.com/pmocz/dsmc-python/blob/main/dsmc.py"
click node_setup "https://github.com/pmocz/dsmc-python/blob/main/dsmc.py"
click node_particles "https://github.com/pmocz/dsmc-python/blob/main/dsmc.py"
click node_motion "https://github.com/pmocz/dsmc-python/blob/main/dsmc.py"
click node_walls "https://github.com/pmocz/dsmc-python/blob/main/dsmc.py"
click node_collisions "https://github.com/pmocz/dsmc-python/blob/main/dsmc.py"
click node_statistics "https://github.com/pmocz/dsmc-python/blob/main/dsmc.py"
click node_theory "https://github.com/pmocz/dsmc-python/blob/main/dsmc.py"
click node_visualization "https://github.com/pmocz/dsmc-python/blob/main/dsmc.py"

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_entry,node_setup,node_particles,node_motion,node_walls,node_collisions,node_user toneBlue
class node_statistics,node_theory,node_visualization toneAmber
class node_numpy,node_scipy,node_matplotlib,node_figure toneIndigo
```

## Components

### Simulation

- [Run simulation](https://github.com/pmocz/dsmc-python/blob/main/dsmc.py): `dsmc.py`
- [Simulation setup](https://github.com/pmocz/dsmc-python/blob/main/dsmc.py): `dsmc.py`
- [Particle initialization](https://github.com/pmocz/dsmc-python/blob/main/dsmc.py): `dsmc.py`
- [Particle drift](https://github.com/pmocz/dsmc-python/blob/main/dsmc.py): `dsmc.py`
- [Wall interactions](https://github.com/pmocz/dsmc-python/blob/main/dsmc.py): `dsmc.py`
- [Cell collisions](https://github.com/pmocz/dsmc-python/blob/main/dsmc.py): `dsmc.py`

### Analysis and plots

- [Velocity statistics](https://github.com/pmocz/dsmc-python/blob/main/dsmc.py): `dsmc.py`
- [BGK comparison](https://github.com/pmocz/dsmc-python/blob/main/dsmc.py): `dsmc.py`
- [Plot results](https://github.com/pmocz/dsmc-python/blob/main/dsmc.py): `dsmc.py`

### Other components

- **User**
- **NumPy**
- **SciPy special**
- **Matplotlib**
- **Saved figure**

## Connections

- User → Run simulation: runs (evidence: `README.md`)
- Run simulation → Simulation setup: configures (evidence: `dsmc.py`)
- Simulation setup → Particle initialization: sets parameters (evidence: `dsmc.py`)
- Particle initialization → Particle drift: advances (evidence: `dsmc.py`)
- Particle drift → Wall interactions: handles boundaries (evidence: `dsmc.py`)
- Wall interactions → Cell collisions: updates particles (evidence: `dsmc.py`)
- Cell collisions → Velocity statistics: records velocities (evidence: `dsmc.py`)
- Velocity statistics → BGK comparison: compares with (evidence: `dsmc.py`)
- BGK comparison → Plot results: plots comparison (evidence: `dsmc.py`)
- Plot results → Saved figure: saves (evidence: `dsmc.py`)
- Simulation setup → NumPy: computes with (evidence: `dsmc.py`)
- Particle initialization → NumPy: samples with (evidence: `dsmc.py`)
- Cell collisions → NumPy: computes with (evidence: `dsmc.py`)
- BGK comparison → SciPy special: uses Bessel function (evidence: `dsmc.py`)
- Plot results → Matplotlib: plots and saves (evidence: `dsmc.py`)
