# amanotk/pic-nix architecture

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

- Interactive diagram: https://gitdiagram.com/amanotk/pic-nix
- Repository: https://github.com/amanotk/pic-nix

## Overview

##### Overall Project Identification
- Type: Specialized simulation application for kinetic plasma dynamics (a PIC simulation code).
- Purpose: To simulate collisionless space plasmas—with a strong emphasis on modular simulation components, parallelization (MPI and OpenMP), and integrated diagnostics.

##### Break Down the Main Components
a. Build and Configuration:
– A CMake build system with multiple pre-configured toolchain files (e.g., “linux-gcc.cmake”, “fugaku…” files).
– Out-of-source build pattern that produces executables (such as “main.out”) under build directories.
b. Core Simulation Libraries and Engine:
– “nix” directory: Contains the majority of simulation core functionality (e.g., physics models, MPI I/O routines, state handling, random generators, interpolation routines, and various utilities). Also includes third-party libraries (plog for logging, taskflow for parallel task management, xtensor for multidimensional arrays, etc.).
– “pic” directory: Contains the specific PIC engine components. Files here (like “pic_application.cpp”, “pic_engine.hpp”, “pic_chunk.cpp”, etc.) implement the particle and field handling for the PIC simulation.
c. Examples / Experiment Configurations:
– “example” directory: Offers several subdirectories (beam, cherenkov, fireball, mrx, shock, thermal) each with its own CMakeLists.txt, configuration TOML files, and sometimes associated Python “batch.py” scripts for post-run processing (i.e., diagnostic plotting, movie generation).
d. Diagnostics and Python Analysis:

##### Relationships and Interactions
- The CMake configuration builds the simulation engine, linking necessary third-party libraries from the “nix/thirdparty” folder.
- The “pic” module relies on the core functionality provided in “nix”; together they form the simulation executable.
- Users launch simulations (e.g., using mpiexec) by providing a configuration file (TOML format) from one of the example directories.
- The simulation writes out output files (for snapshots, profile data, etc.) that are later picked up by the diagnostic Python scripts from “script” (e.g., “batch.py”).
- MPI (via mpicxx and mpiexec) and OpenMP are explicitly used, which means that parallel aspects and multi-threading are crucial in the overall energy and data flow.

##### Architectural Patterns & Design Principles
- Modularity: The separation between the core simulation (nix), the PIC-specific implementation (pic), and the example/diagnostic scripts.
- Layered Design: The build system (CMake) configures and wires together lower-level libraries (nix and third-party code) with higher-level application logic (PIC simulation and experiments).
- Extensibility: A rich set of examples and diagnostic tools indicates that users can extend or experiment with new simulation configurations.
- Parallelism: Explicitly using MPI and OpenMP suggests a design that is highly conscious of parallel execution and computational efficiency.

## Diagram (Mermaid)

```mermaid
graph TD
    A["CMake Build System"]:::build
    B["Simulation Core (nix)"]:::core
    C["PIC Simulation Module (pic)"]:::pic
    D["Simulation Executable"]:::exe
    E["Example Configurations"]:::examples
    F["Diagnostics & Visualization (Python)"]:::diagnostics
    G["Parallelization (MPI/OpenMP)"]:::parallel

    A -->|"configures"| B
    A -->|"configures"| C
    G -->|"enables"| B
    G -->|"enables"| C
    B -->|"linksTo"| D
    C -->|"linksTo"| D
    E -->|"providesConfig"| D
    D -->|"outputsData"| F
    F -->|"analyzes"| D

    click A "https://github.com/amanotk/pic-nix/tree/main/cmake"
    click B "https://github.com/amanotk/pic-nix/tree/main/nix"
    click C "https://github.com/amanotk/pic-nix/tree/main/pic"
    click E "https://github.com/amanotk/pic-nix/tree/main/example"
    click F "https://github.com/amanotk/pic-nix/tree/main/script"

    classDef build fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef core fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef pic fill:#f94144,stroke:#333,stroke-width:2px;
    classDef exe fill:#a8dadc,stroke:#333,stroke-width:2px;
    classDef examples fill:#577590,stroke:#fff,stroke-width:2px;
    classDef diagnostics fill:#277da1,stroke:#fff,stroke-width:2px;
    classDef parallel fill:#f3722c,stroke:#333,stroke-width:2px;
```
