# tfdzarm/picfoam architecture

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

- Interactive diagram: https://gitdiagram.com/tfdzarm/picfoam
- Repository: https://github.com/tfdzarm/picfoam

## Overview

##### Project type and purpose
- This is an open-source scientific simulation tool—specifically, a fully kinetic electrostatic Particle-in-Cell (PIC) solver with Monte Carlo Collisions (MCC) built on top of the OpenFOAM C++ framework.
- Purpose: simulate non-equilibrium plasma physics using mesh-based Finite Volume Methods (FVM) and particle methods.

##### High-level architectural components
a. External dependencies
- OpenFOAM core libraries (FVM mesh/data structures, field algebra, parallel IO, time-loop management)
- Third-party tools: Gmsh for mesh generation; ParaView for visualization; MPI/OpenMPI for distributed runs
b. Core library (PICMCCFVM)
- “clouds” (particle cloud management)
- “parcels” (particle collection operations)
- “submodels” (physics kernels: boundary events, collision, charge weighting, Maxwell solver, particle pusher, etc.)
c. Pre-processing module
- preProcess/picInitialise: builds initial particle distributions using various InitializationModel plugins
d. Solver executable
- solver/picFoam: ties OpenFOAM time‐loop to PICMCCFVM core, updates fields & particles each timestep
e. Post-processing module
- postProcess/functionObjects/picFields: computes derived quantities (field averages, charge density, fluxes)
f. Tutorials/case directories
- provide example meshes, controlDict settings, picInitialiseDict, blockMeshDict, run.sh scripts

##### Data flows & interactions
- User places case in tutorials (mesh + system + constant directories)
→ preProcess/picInitialise reads picInitialiseDict → generates particle cloud data
→ solver/picFoam runs time-loop:
- reads mesh & fields
- calls PICMCCFVM core submodels (charge weighting → field solve → particle push → collisions → diagnostics)
→ intermediate data stored in OpenFOAM time directories (fields, particle dumps)
→ postProcess/functionObjects invoked at end or during run to write derived outputs
→ ParaView reads case directories for visualization

##### Architectural patterns & design principles
- Plugin/Factory pattern: each physics submodel (e.g., CollisionModel, BoundaryModel) implements a common interface and is selected via run-time dictionaries
- Layered separation:
1. OpenFOAM framework (mesh & field management)
2. PICMCCFVM core (clouds, parcels, submodels)
3. I/O & control (preProcess, solver, postProcess)
4. User cases (tutorials)
- Modular C++ templates to avoid code duplication in submodel implementations
- Make-based build integration (Allwmake, per-folder Make options)

##### Essential elements
- Clear component labels (module names, directories)
- Extension point marker near “Submodels” to show new plugin slots

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Tools & User Cases"
        UC["Tutorials / Example Cases"]:::external
        Gmsh["Gmsh"]:::external
        blockMesh["blockMesh"]:::external
        MPI["MPI / OpenMPI"]:::external
        PV["ParaView"]:::external
        Build["Allwmake & EXTENSION_INSTRUCTIONS.md"]:::external
    end

    subgraph "OpenFOAM Framework"
        direction TB
        Mesh["Mesh & Field Manager"]:::openfoam
        TimeLoop["Time-loop Controller"]:::openfoam
        Pre["preProcess/picInitialise"]:::util
        Solver["solver/picFoam"]:::openfoam
        Post["postProcess/functionObjects/picFields"]:::util
    end

    subgraph "PICMCCFVM Core"
        direction TB
        Clouds["Clouds Management"]:::core
        Parcels["Parcels Operations"]:::core
        Submodels["Physics Submodels"]:::core
    end

    UC --> Pre
    Gmsh --> Mesh
    blockMesh --> Mesh
    Mesh --> TimeLoop
    TimeLoop --> Pre
    Pre --> Solver
    MPI --> Solver
    Solver --> Clouds
    Solver --> Parcels
    Solver --> Submodels
    Solver --> Post
    Post --> PV
    Build --> Pre
    Build --> Solver
    Build --> Post
    Build --> Submodels

    Pre --> InitModels["InitializationModel Plugins"]:::util
    Solver --> FoamC["picFoam.C"]:::openfoam
    Solver --> FoamH["createFields.H"]:::openfoam
    Post --> FieldsC["picFields.C"]:::util
    Post --> FieldsH["picFields.H"]:::util

    classDef openfoam fill:#cce5ff,stroke:#004085,color:#004085;
    classDef core fill:#d4edda,stroke:#155724,color:#155724;
    classDef util fill:#fff3cd,stroke:#856404,color:#856404;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d;

    click Clouds "https://github.com/tfdzarm/picfoam/tree/master/PICMCCFVM/clouds"
    click Parcels "https://github.com/tfdzarm/picfoam/tree/master/PICMCCFVM/parcels"
    click Submodels "https://github.com/tfdzarm/picfoam/tree/master/PICMCCFVM/submodels"
    click Pre "https://github.com/tfdzarm/picfoam/tree/master/preProcess/picInitialise"
    click InitModels "https://github.com/tfdzarm/picfoam/tree/master/preProcess/picInitialise/InitializationModel"
    click Solver "https://github.com/tfdzarm/picfoam/tree/master/solver/picFoam"
    click FoamC "https://github.com/tfdzarm/picfoam/blob/master/solver/picFoam/picFoam.C"
    click FoamH "https://github.com/tfdzarm/picfoam/blob/master/solver/picFoam/createFields.H"
    click Post "https://github.com/tfdzarm/picfoam/tree/master/postProcess/functionObjects/picFields"
    click FieldsC "https://github.com/tfdzarm/picfoam/blob/master/postProcess/functionObjects/picFields/picFields.C"
    click FieldsH "https://github.com/tfdzarm/picfoam/blob/master/postProcess/functionObjects/picFields/picFields.H"
    click Build "https://github.com/tfdzarm/picfoam/blob/master/EXTENSION_INSTRUCTIONS.md"
    click UC "https://github.com/tfdzarm/picfoam/tree/master/tutorials/"
```
