# w-wuxian/additive_schwarz_method architecture

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

- Interactive diagram: https://gitdiagram.com/w-wuxian/additive_schwarz_method
- Repository: https://github.com/w-wuxian/additive_schwarz_method

## Overview

##### Project type and purpose
- This is a scientific HPC code written in Fortran, parallelized with MPI, whose goal is to solve the 2D heat equation on a Cartesian grid via finite differences.
- It contains two major parts:
a. MPI_EQ_CHALEUR – a baseline MPI‐parallel heat‐equation solver
b. ADDITIVE_SCHWARZ_METHOD – two variants of a domain‐decomposition solver (Dirichlet and mixed/Robin boundary conditions)

##### File structure
- Top‐level directories:
- MPI_EQ_CHALEUR: main.f90 + Fortran modules (ModData.f90, ModF.f90, ModGC.f90, ModSOL.f90), Makefile, scripts & README.
- Code_Dirichlet_LAST and DD_Neuman_TRUE_LAST: share subfolders CHARGE, EXACTE_ERREUR, MAT_VIZU, SOL_NUMERIQUE plus per‐variant modules (mod_charge, mod_comm, mod_constr_mat in Neumann, mod_gradconj or mod_gmres, etc.), main.f90 and makefile.
- Common elements:
- mod_parametres.f90 houses all tunable parameters (grid sizes, time steps, overlap).
- Build scripts rely on mpif90 and standard make targets (make, clean, cleanREP).
- Execution via mpirun ‑n X --mca pml ob1 ./run
- Visualization is done post‐run with gnuplot scripts (VIZU_PLT.plt, VIZU_2_PLT.plt, VIZU_2_PLT.plt).

##### Extracted architectural patterns
- Layered/modules architecture:
a. Data/Parameters layer (mod_parametres, ModData)
b. Initialization and loading of boundary/initial conditions (mod_charge / CHARGE folder)
c. Discrete operator assembly (mod_matsys / mod_constr_mat)
d. Solver kernel (mod_gradconj or mod_gmres in Neumann, ModGC in MPI_EQ_CHALEUR)
e. Communication layer (mod_comm handling halo exchanges via MPI)
f. Post‐processing (EXACTE_ERREUR for error norms, SOL_NUMERIQUE for storing results, MAT_VIZU + gnuplot scripts)
- Domain decomposition: each MPI rank owns a subdomain; overlap (halo) region exchanges with rank−1 and rank+1.

- Build System (Makefile + mpif90)
- Executable (run / main.f90)
- Parameter Module (mod_parametres)
- Data Module (ModData / mod_charge)
- Discretization & Assembly Module (mod_matsys / mod_constr_mat)
- Solver Module (mod_gradconj, mod_gmres, ModGC, ModSOL)
- Communication Module (mod_comm)
- Output & Visualization (SOL_NUMERIQUE, MAT_VIZU, gnuplot scripts)
- Build System → compiles all modules → Executable
- Executable → reads parameters → Parameter Module
- Executable → calls Data Module to set initial conditions
- Executable → calls Discretization Module → constructs system matrix
- Solver Module ↔ Communication Module (halo exchanges)
- Solver Module → updates solution → Output Module
- Output Module → writes data files → Visualization scripts
c. Domain decomposition:
d. Technologies / frameworks:
- Fortran 90/95 modules
- MPI (point‐to‐point halo exchange)
- make / mpif90 build chain
- gnuplot for plotting

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Build System"
        BS_Dir["Dirichlet Makefile"]:::build
        BS_Neu["Neumann Makefile"]:::build
        BS_MPI["MPI_EQ Makefile"]:::build
    end
    BS_Dir --> Exec_Dir["Dirichlet main.f90"]:::compute
    BS_Neu --> Exec_Neu["Neumann main.f90"]:::compute
    BS_MPI --> Exec_MPI["MPI_EQ main.f90"]:::compute

    subgraph "Runtime (MPI Ranks)"
        subgraph "Dirichlet-DD Rank"
            Exec_Dir --> Param_Dir["mod_parametres.f90"]:::compute
            Param_Dir --> Data_Dir["mod_charge.f90"]:::compute
            Data_Dir --> Assem_Dir["mod_matsys.f90"]:::compute
            Assem_Dir --> Solv_Dir["mod_gradconj.f90"]:::compute
            Solv_Dir <-->|"halo exchange"| Comm_Dir["mod_comm.f90"]:::comm
            Solv_Dir --> Store_Dir["mod_sol.f90"]:::compute
        end
        subgraph "Neumann-DD Rank"
            Exec_Neu --> Param_Neu["mod_parametres.f90"]:::compute
            Param_Neu --> Data_Neu["mod_charge.f90"]:::compute
            Data_Neu --> Assem_Neu["mod_constr_mat.f90"]:::compute
            Assem_Neu --> Solv_Neu1["mod_gradconj.f90"]:::compute
            Assem_Neu --> Solv_Neu2["mod_gmres.f90"]:::compute
            Solv_Neu1 <-->|"halo exchange"| Comm_Neu["mod_comm.f90"]:::comm
            Solv_Neu2 <-->|"halo exchange"| Comm_Neu
            Solv_Neu2 --> Store_Neu["mod_sol.f90"]:::compute
        end
        subgraph "MPI_EQ Rank"
            Exec_MPI --> Data_MPI["ModData.f90"]:::compute
            Data_MPI --> Assem_MPI["ModGC.f90"]:::compute
            Assem_MPI --> Solv_MPI["ModSOL.f90"]:::compute
            Solv_MPI <-->|"halo exchange"| Comm_MPI["mod_comm"]:::comm
            Solv_MPI --> Store_MPI["ModSOL.f90"]:::compute
        end
    end

    subgraph "Post-Processing & Visualization"
        Store_Dir --> Err_Dir["EXACTE_ERREUR/"]:::io
        Store_Dir --> Viz_Dir["MAT_VIZU/"]:::io
        Viz_Dir --> Plot_Dir["VIZU_PLT.plt"]:::io

        Store_Neu --> Err_Neu["EXACTE_ERREUR/"]:::io
        Store_Neu --> Viz_Neu["MAT_VIZU/"]:::io
        Viz_Neu --> Plot_Neu["VIZU_PLT.plt"]:::io

        Store_MPI --> Viz_MPI["VIZU_PLT.plt"]:::io
        Store_MPI --> Plot2_MPI["VIZU_2_PLT.plt"]:::io
    end

    click BS_Dir "https://github.com/w-wuxian/additive_schwarz_method/tree/master/Code_Dirichlet_LAST/makefile"
    click BS_Neu "https://github.com/w-wuxian/additive_schwarz_method/tree/master/DD_Neuman_TRUE_LAST/makefile"
    click BS_MPI "https://github.com/w-wuxian/additive_schwarz_method/tree/master/MPI_EQ_CHALEUR/Makefile"
    click Exec_Dir "https://github.com/w-wuxian/additive_schwarz_method/blob/master/Code_Dirichlet_LAST/main.f90"
    click Exec_Neu "https://github.com/w-wuxian/additive_schwarz_method/blob/master/DD_Neuman_TRUE_LAST/main.f90"
    click Exec_MPI "https://github.com/w-wuxian/additive_schwarz_method/blob/master/MPI_EQ_CHALEUR/main.f90"
    click Param_Dir "https://github.com/w-wuxian/additive_schwarz_method/blob/master/Code_Dirichlet_LAST/mod_parametres.f90"
    click Param_Neu "https://github.com/w-wuxian/additive_schwarz_method/blob/master/DD_Neuman_TRUE_LAST/mod_parametres.f90"
    click Data_Dir "https://github.com/w-wuxian/additive_schwarz_method/blob/master/Code_Dirichlet_LAST/mod_charge.f90"
    click Data_Neu "https://github.com/w-wuxian/additive_schwarz_method/blob/master/DD_Neuman_TRUE_LAST/mod_charge.f90"
    click Data_MPI "https://github.com/w-wuxian/additive_schwarz_method/blob/master/MPI_EQ_CHALEUR/ModData.f90"
    click Assem_Dir "https://github.com/w-wuxian/additive_schwarz_method/blob/master/Code_Dirichlet_LAST/mod_matsys.f90"
    click Assem_Neu "https://github.com/w-wuxian/additive_schwarz_method/blob/master/DD_Neuman_TRUE_LAST/mod_constr_mat.f90"
    click Assem_MPI "https://github.com/w-wuxian/additive_schwarz_method/blob/master/MPI_EQ_CHALEUR/ModGC.f90"
    click Solv_Dir "https://github.com/w-wuxian/additive_schwarz_method/blob/master/Code_Dirichlet_LAST/mod_gradconj.f90"
    click Solv_Neu1 "https://github.com/w-wuxian/additive_schwarz_method/blob/master/DD_Neuman_TRUE_LAST/mod_gradconj.f90"
    click Solv_Neu2 "https://github.com/w-wuxian/additive_schwarz_method/blob/master/DD_Neuman_TRUE_LAST/mod_gmres.f90"
    click Solv_MPI "https://github.com/w-wuxian/additive_schwarz_method/blob/master/MPI_EQ_CHALEUR/ModSOL.f90"
    click Comm_Dir "https://github.com/w-wuxian/additive_schwarz_method/blob/master/Code_Dirichlet_LAST/mod_comm.f90"
    click Comm_Neu "https://github.com/w-wuxian/additive_schwarz_method/blob/master/DD_Neuman_TRUE_LAST/mod_comm.f90"
    click Store_Dir "https://github.com/w-wuxian/additive_schwarz_method/blob/master/Code_Dirichlet_LAST/mod_sol.f90"
    click Store_Neu "https://github.com/w-wuxian/additive_schwarz_method/blob/master/DD_Neuman_TRUE_LAST/mod_sol.f90"
    click Err_Dir "https://github.com/w-wuxian/additive_schwarz_method/tree/master/Code_Dirichlet_LAST/EXACTE_ERREUR/"
    click Err_Neu "https://github.com/w-wuxian/additive_schwarz_method/tree/master/DD_Neuman_TRUE_LAST/EXACTE_ERREUR/"
    click Viz_Dir "https://github.com/w-wuxian/additive_schwarz_method/tree/master/Code_Dirichlet_LAST/MAT_VIZU/"
    click Viz_Neu "https://github.com/w-wuxian/additive_schwarz_method/tree/master/DD_Neuman_TRUE_LAST/MAT_VIZU/"
    click Plot_Dir "https://github.com/w-wuxian/additive_schwarz_method/blob/master/Code_Dirichlet_LAST/VIZU_PLT.plt"
    click Plot_Neu "https://github.com/w-wuxian/additive_schwarz_method/blob/master/DD_Neuman_TRUE_LAST/VIZU_PLT.plt"
    click Viz_MPI "https://github.com/w-wuxian/additive_schwarz_method/blob/master/MPI_EQ_CHALEUR/VIZU_PLT.plt"
    click Plot2_MPI "https://github.com/w-wuxian/additive_schwarz_method/blob/master/MPI_EQ_CHALEUR/VIZU_2_PLT.plt"

    classDef build fill:#cccccc,stroke:#333,stroke-width:1px
    classDef compute fill:#9fc5e8,stroke:#333,stroke-width:1px
    classDef comm fill:#a2c4c9,stroke:#333,stroke-width:1px
    classDef io fill:#f9cb9c,stroke:#333,stroke-width:1px
```
