# hballington12/pbt architecture

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

- Interactive diagram: https://gitdiagram.com/hballington12/pbt
- Repository: https://github.com/hballington12/pbt

## Overview

##### Project type and purpose
- This is a scientific, HPC‐oriented command-line application (“PBT”) written primarily in Fortran 90, with optional C support for mesh triangulation.
- It computes light scattering (near‐field via geometric optics and far‐field via vector diffraction) for arbitrarily shaped particles.
- It provides both sequential and MPI‐parallel implementations for orientation averaging, plus optional OpenMP threading.

##### File structure
- Top level
- README.md, LICENSE, .gitignore: project meta-data
- apertures.dat, examples/: sample input data
- cache/: checkpointing mechanism (intermediate saves)
- template/: shell scripts for job submission (MPI, sequential, looping)
- src/
- main_seq.f90 & main_mpi.f90: two entry points
- modules (*.f90): domain logic split into bvh_mod, beam_loop_mod, diff_mod, input_mod, outputs_mod, types_mod, mpi_mod/pbt_mpi_mod, pbt_seq_mod
- subdirectories
– mpi/ & seq/: Makefiles and wrapper code for each build target
– tri/: C code (“Triangle”) for automatic mesh triangulation
– test/: unit-test harness with sample files
- Build scripts
- Makefiles under src/seq, src/mpi, src/tri, src/test—govern sequential, MPI, triangulation, and test builds

##### Key insights from README
- Core pipeline: parse CLI flags → generate/read particle geometry → (optional) triangulate mesh → compute near-field (geometric optics + parent grouping) → compute far-field (vector diffraction) → write outputs.
- MPI version handles orientation averaging by distributing particle rotations across ranks.
- OpenMP can be enabled within modules (e.g., diffraction loops).
- Caches intermediate beam trees for restart/resume.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Control Plane
    subgraph "Control Plane"
        CLI["CLI Front-end & Input Parser"]:::io
        CacheMgr["Cache Manager"]:::data
        Templates["Job Submission Templates"]:::ext
    end

    %% Compute Plane
    subgraph "Compute Plane"
        subgraph "Geometry Manager"
            MeshReader["Mesh & Aperture Reader"]:::io
            Triangulator["Triangle Triangulator"]:::ext
        end
        subgraph "Near-Field Engine"
            BeamLoop["Beam Loop (beam_loop_mod)"]:::compute
            BVH["BVH Acceleration (bvh_mod)"]:::compute
            HexGroup["Parent Hex Group (cc_hex_mod)"]:::compute
        end
        subgraph "Far-Field Engine"
            Diff["Diffraction (diff_mod)"]:::compute
            Outputs["Outputs Module (outputs_mod)"]:::io
        end
    end

    %% Execution Modes
    subgraph "Execution Modes"
        Seq["Sequential Controller"]:::parallel
        MPI["MPI Orchestration Layer"]:::parallel
    end

    %% Test Harness
    Test["Test Harness"]:::control

    %% Data Stores
    CacheStore["Cache Store"]:::data
    OutputFiles["Output Files"]:::data

    %% Data Flow
    CLI -->|"parse flags"| MeshReader
    CLI -->|"if -tri"| Triangulator
    MeshReader -->|"mesh data"| BeamLoop
    Triangulator -->|"triangulated mesh"| BeamLoop
    BeamLoop -->|"beam list"| BVH
    BVH -->|"grouped beams"| HexGroup
    HexGroup -->|"beam tree"| Diff
    Diff -->|"scattering data"| Outputs
    Outputs -->|"write files"| OutputFiles

    %% Caching
    BeamLoop -->|"checkpoint"| CacheStore
    Diff -->|"checkpoint"| CacheStore
    CacheStore -.->|"resume"| CLI

    %% Execution modes branching
    CLI --> Seq
    CLI --> MPI
    MPI --> BeamLoop
    MPI --> Diff
    Templates --> Seq
    Templates --> MPI

    %% Test harness linkage
    Test --> CLI
    Test --> MeshReader
    Test --> BeamLoop
    Test --> Diff

    %% Click Events
    click CLI "https://github.com/hballington12/pbt/blob/gfortran/src/main_seq.f90"
    click CLI "https://github.com/hballington12/pbt/blob/gfortran/src/main_mpi.f90"
    click CLI "https://github.com/hballington12/pbt/blob/gfortran/src/input_mod.f90"
    click MeshReader "https://github.com/hballington12/pbt/blob/gfortran/src/input_mod.f90"
    click Triangulator "https://github.com/hballington12/pbt/tree/gfortran/src/tri/"
    click BeamLoop "https://github.com/hballington12/pbt/blob/gfortran/src/beam_loop_mod.f90"
    click BVH "https://github.com/hballington12/pbt/blob/gfortran/src/bvh_mod.f90"
    click HexGroup "https://github.com/hballington12/pbt/blob/gfortran/src/cc_hex_mod.f90"
    click Diff "https://github.com/hballington12/pbt/blob/gfortran/src/diff_mod.f90"
    click Outputs "https://github.com/hballington12/pbt/blob/gfortran/src/outputs_mod.f90"
    click MPI "https://github.com/hballington12/pbt/blob/gfortran/src/mpi_mod.f90"
    click MPI "https://github.com/hballington12/pbt/blob/gfortran/src/pbt_mpi_mod.f90"
    click MPI "https://github.com/hballington12/pbt/blob/gfortran/src/main_mpi.f90"
    click MPI "https://github.com/hballington12/pbt/tree/gfortran/src/mpi/Makefile"
    click Seq "https://github.com/hballington12/pbt/blob/gfortran/src/main_seq.f90"
    click Seq "https://github.com/hballington12/pbt/blob/gfortran/src/pbt_seq_mod.f90"
    click Seq "https://github.com/hballington12/pbt/tree/gfortran/src/seq/Makefile"
    click Seq "https://github.com/hballington12/pbt/blob/gfortran/src/seq/seq.f90"
    click CacheStore "https://github.com/hballington12/pbt/tree/gfortran/cache/"
    click Templates "https://github.com/hballington12/pbt/blob/gfortran/template/abt.sh"
    click Templates "https://github.com/hballington12/pbt/blob/gfortran/template/abt_mpi.sh"
    click Templates "https://github.com/hballington12/pbt/blob/gfortran/template/adda_loop.sh"
    click Test "https://github.com/hballington12/pbt/blob/gfortran/src/test.f90"
    click Test "https://github.com/hballington12/pbt/tree/gfortran/src/test/"

    %% Styles
    classDef io fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1;
    classDef compute fill:#C8E6C9,stroke:#2E7D32,color:#2E7D32;
    classDef parallel fill:#FFE0B2,stroke:#EF6C00,color:#EF6C00;
    classDef ext fill:#E0E0E0,stroke:#424242,color:#424242;
    classDef data fill:#B2EBF2,stroke:#006064,color:#006064;
    classDef control fill:#E1BEE7,stroke:#6A1B9A,color:#6A1B9A
```
