How amanotk/pic-nix works
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.