# japanese-maple/finite-element-method-fem-rom-reduced-order-modeling architecture

> Architecture diagram of the GitHub repository japanese-maple/finite-element-method-fem-rom-reduced-order-modeling, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling
- Repository: https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling

## Overview

#### Purpose and Entry Points
This is a Python/NumPy/SciPy research codebase for 2D incompressible steady Stokes flow using stable P1-iso-P1 mixed FEM, plus reduced-order modeling (ROM). Primary executable workflow is `Solvers/Exchanger_Device.py`; interactive entry points are notebooks under `Demonstrations/`, notably `Demonstrations/Flow_examples.ipynb`, `Demonstrations/Stokes_Stability.ipynb`, and `Demonstrations/ROM_OfflineIOnline.ipynb`.

#### Mesh and Discretization Boundary
Precomputed `.npz` mesh archives provide domain geometry and connectivity, e.g. `Meshes/exchanger_device_mesh_data.npz` and `Meshes/LBB_test_mesh_data.npz`. `Utilities/Mesh_processing.py` transforms these inputs into the coarse pressure mesh and uniformly refined velocity mesh required by P1-iso-P1. This separates geometry/refinement concerns from PDE assembly.

#### Full-Order FEM Assembly
`Utilities/Stokes_felib.py` is the core FEM layer. It assembles sparse velocity stiffness, velocity-pressure divergence/coupling, and mass operators, enforcing the mixed saddle-point structure and supporting LBB analysis. It consumes processed mesh data and material viscosity, producing matrix blocks for the solver and diagnostic workflows.

#### Full-Order Solve and Persisted Results
`Solvers/Exchanger_Device.py` orchestrates a specific exchanger-device solve: load mesh, apply boundary/lifting conditions, construct the saddle-point system, address pressure null space, solve for velocity and pressure, and persist fields. Result archives such as `Solutions/Exchanger_device.npz`, `Solutions/Winding_pipe_solution.npz`, and `Solutions/Reference_Solution.npz` are the boundary between expensive numerical computation and later analysis.

#### Visualization and Verification
`Utilities/Plot_functions.py` renders mesh and solution fields for notebooks. `Demonstrations/Stokes_Convergence.ipynb` compares stored refinement solutions, while `Demonstrations/Stokes_Stability.ipynb` consumes FEM mass/divergence operators and solutions to evaluate the discrete inf-sup/LBB condition. `Demonstrations/Flow_examples.ipynb` presents solved flow fields.

#### Snapshot-Based ROM
The non-offline/online branch samples viscosity fields in `Reduced_Order_Modeling/No_Online_Offline_phase/viscosity_generator.py`, solves corresponding full-order cases through `Reduced_Order_Modeling/No_Online_Offline_phase/snapshot_generator.py`, and parallelizes generation with `Reduced_Order_Modeling/No_Online_Offline_phase/parallelized_sg.py`. Artifacts are persisted as `stokes_solution_snapshots.npz` and `viscosity_snapshots.npz`; this workflow relies on the same full-order mesh/FEM boundary.

#### Affine Offline/Online ROM
`Reduced_Order_Modeling/Online_Offline_phase/Affine_Decomposition.py` prepares parameter-separated reduced operators and basis fields. Its offline outputs—`Reduced_Order_Modeling/Online_Offline_phase/Data/A1.npz` through `A5.npz` and `basis_fields.npz`—are consumed by `Demonstrations/ROM_OfflineIOnline.ipynb` for low-cost online evaluation. The architecture is file-backed rather than service-based: NumPy archives are the integration contract across solver, ROM, and notebooks.

Main entry points: [`Utilities/Stokes_felib.py`](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Utilities/Stokes_felib.py) (Stokes FEM library), [`Solutions/Exchanger_device.npz`](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Solutions/Exchanger_device.npz) (Solution archives), [`Reduced_Order_Modeling/No_Online_Offline_phase/snapshot_generator.py`](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Reduced_Order_Modeling/No_Online_Offline_phase/snapshot_generator.py) (Snapshot generator), [`Utilities/Mesh_processing.py`](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Utilities/Mesh_processing.py) (Mesh processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mesh["Mesh &amp; discretization"]
  node_mesh_archives[("Mesh archives<br/>NumPy mesh data")]
  node_mesh_processing["Mesh processing<br/>P1-iso-P1 refinement<br/>[Mesh_processing.py]"]
end

subgraph group_fom["Full-order Stokes FEM"]
  node_stokes_felib["Stokes FEM library<br/>sparse mixed assembly<br/>[Stokes_felib.py]"]
  node_exchanger_solver["Exchanger-device solver<br/>full-order solve"]
end

subgraph group_analysis["Results &amp; analysis"]
  node_solution_archives[("Solution archives<br/>NumPy field data")]
  node_plot_functions["Plot functions<br/>visualization<br/>[Plot_functions.py]"]
  node_flow_examples["Flow examples<br/>interactive notebook"]
  node_convergence_notebook["Convergence study<br/>verification notebook"]
  node_stability_notebook["LBB stability study<br/>diagnostic notebook"]
end

subgraph group_rom["Reduced-order modeling"]
  node_viscosity_generator["Viscosity generator<br/>ROM sampling"]
  node_snapshot_generator["Snapshot generator<br/>ROM full-order sampling"]
  node_parallel_snapshot_generation["Parallel snapshot generation<br/>parallel ROM driver<br/>[parallelized_sg.py]"]
  node_snapshot_archives[("Snapshot archives<br/>NumPy ROM data")]
  node_affine_decomposition["Affine decomposition<br/>offline ROM assembly"]
  node_offline_rom_data[("Offline ROM data<br/>reduced operators &amp; bases<br/>[A1.npz]")]
  node_rom_notebook["Offline/online ROM demo<br/>interactive notebook"]
end

node_mesh_archives -->|"geometry &amp; connectivity"| node_mesh_processing
node_mesh_processing -->|"P1-iso-P1 meshes"| node_stokes_felib
node_stokes_felib -->|"mixed matrix blocks"| node_exchanger_solver
node_mesh_archives -->|"device mesh"| node_exchanger_solver
node_exchanger_solver -->|"velocity &amp; pressure fields"| node_solution_archives
node_solution_archives -->|"solved fields"| node_flow_examples
node_plot_functions -->|"rendering"| node_flow_examples
node_solution_archives -->|"refinement results"| node_convergence_notebook
node_stokes_felib -->|"mass &amp; divergence operators"| node_stability_notebook
node_solution_archives -->|"solution data"| node_stability_notebook
node_viscosity_generator -->|"sampled viscosities"| node_parallel_snapshot_generation
node_parallel_snapshot_generation -->|"parallel jobs"| node_snapshot_generator
node_mesh_processing -.->|"shared mesh boundary"| node_snapshot_generator
node_stokes_felib -.->|"shared FEM assembly"| node_snapshot_generator
node_snapshot_generator -->|"solution snapshots"| node_snapshot_archives
node_viscosity_generator -->|"viscosity snapshots"| node_snapshot_archives
node_snapshot_archives -->|"training data"| node_affine_decomposition
node_affine_decomposition -->|"A1–A5 &amp; basis fields"| node_offline_rom_data
node_offline_rom_data -->|"online reduced evaluation"| node_rom_notebook

click node_mesh_archives "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Meshes/exchanger_device_mesh_data.npz"
click node_mesh_processing "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Utilities/Mesh_processing.py"
click node_stokes_felib "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Utilities/Stokes_felib.py"
click node_exchanger_solver "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Solvers/Exchanger_Device.py"
click node_solution_archives "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Solutions/Exchanger_device.npz"
click node_plot_functions "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Utilities/Plot_functions.py"
click node_flow_examples "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Demonstrations/Flow_examples.ipynb"
click node_convergence_notebook "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Demonstrations/Stokes_Convergence.ipynb"
click node_stability_notebook "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Demonstrations/Stokes_Stability.ipynb"
click node_viscosity_generator "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Reduced_Order_Modeling/No_Online_Offline_phase/viscosity_generator.py"
click node_snapshot_generator "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Reduced_Order_Modeling/No_Online_Offline_phase/snapshot_generator.py"
click node_parallel_snapshot_generation "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Reduced_Order_Modeling/No_Online_Offline_phase/parallelized_sg.py"
click node_affine_decomposition "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Reduced_Order_Modeling/Online_Offline_phase/Affine_Decomposition.py"
click node_offline_rom_data "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Reduced_Order_Modeling/Online_Offline_phase/Data/A1.npz"
click node_rom_notebook "https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Demonstrations/ROM_OfflineIOnline.ipynb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mesh_archives,node_mesh_processing toneBlue
class node_stokes_felib,node_exchanger_solver toneAmber
class node_solution_archives,node_plot_functions,node_flow_examples,node_convergence_notebook,node_stability_notebook toneMint
class node_viscosity_generator,node_snapshot_generator,node_parallel_snapshot_generation,node_snapshot_archives,node_affine_decomposition,node_offline_rom_data,node_rom_notebook toneRose
```

## Components

### Mesh & discretization

- [Mesh archives](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Meshes/exchanger_device_mesh_data.npz): NumPy mesh data · Precomputed geometry and connectivity inputs. · `Meshes/exchanger_device_mesh_data.npz`
- [Mesh processing](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Utilities/Mesh_processing.py): P1-iso-P1 refinement · Builds coarse pressure and refined velocity meshes. · `Utilities/Mesh_processing.py`

### Full-order Stokes FEM

- [Stokes FEM library](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Utilities/Stokes_felib.py): sparse mixed assembly · Assembles stiffness, coupling, and mass blocks. · `Utilities/Stokes_felib.py`
- [Exchanger-device solver](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Solvers/Exchanger_Device.py): full-order solve · Applies conditions, solves the saddle-point system, and persists fields. · `Solvers/Exchanger_Device.py`

### Results & analysis

- [Solution archives](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Solutions/Exchanger_device.npz): NumPy field data · Persisted full-order fields for reuse and analysis. · `Solutions/Exchanger_device.npz`
- [Plot functions](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Utilities/Plot_functions.py): visualization · `Utilities/Plot_functions.py`
- [Flow examples](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Demonstrations/Flow_examples.ipynb): interactive notebook · Visualizes solved flow fields. · `Demonstrations/Flow_examples.ipynb`
- [Convergence study](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Demonstrations/Stokes_Convergence.ipynb): verification notebook · Compares stored refinement solutions. · `Demonstrations/Stokes_Convergence.ipynb`
- [LBB stability study](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Demonstrations/Stokes_Stability.ipynb): diagnostic notebook · Evaluates the discrete inf-sup condition. · `Demonstrations/Stokes_Stability.ipynb`

### Reduced-order modeling

- [Viscosity generator](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Reduced_Order_Modeling/No_Online_Offline_phase/viscosity_generator.py): ROM sampling · `Reduced_Order_Modeling/No_Online_Offline_phase/viscosity_generator.py`
- [Snapshot generator](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Reduced_Order_Modeling/No_Online_Offline_phase/snapshot_generator.py): ROM full-order sampling · Solves parameterized full-order cases. · `Reduced_Order_Modeling/No_Online_Offline_phase/snapshot_generator.py`
- [Parallel snapshot generation](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Reduced_Order_Modeling/No_Online_Offline_phase/parallelized_sg.py): parallel ROM driver · `Reduced_Order_Modeling/No_Online_Offline_phase/parallelized_sg.py`
- **Snapshot archives**: NumPy ROM data · Stores viscosity and Stokes solution snapshots.
- [Affine decomposition](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Reduced_Order_Modeling/Online_Offline_phase/Affine_Decomposition.py): offline ROM assembly · Prepares parameter-separated reduced operators and basis fields. · `Reduced_Order_Modeling/Online_Offline_phase/Affine_Decomposition.py`
- [Offline ROM data](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Reduced_Order_Modeling/Online_Offline_phase/Data/A1.npz): reduced operators & bases · A1–A5 operators and basis fields for online evaluation. · `Reduced_Order_Modeling/Online_Offline_phase/Data/A1.npz`
- [Offline/online ROM demo](https://github.com/japanese-maple/finite-element-method-fem-rom-reduced-order-modeling/blob/main/Demonstrations/ROM_OfflineIOnline.ipynb): interactive notebook · Consumes offline data for low-cost online evaluation. · `Demonstrations/ROM_OfflineIOnline.ipynb`

## Connections

- Mesh archives → Mesh processing: geometry & connectivity
- Mesh processing → Stokes FEM library: P1-iso-P1 meshes
- Stokes FEM library → Exchanger-device solver: mixed matrix blocks
- Mesh archives → Exchanger-device solver: device mesh
- Exchanger-device solver → Solution archives: velocity & pressure fields
- Solution archives → Flow examples: solved fields
- Plot functions → Flow examples: rendering
- Solution archives → Convergence study: refinement results
- Stokes FEM library → LBB stability study: mass & divergence operators
- Solution archives → LBB stability study: solution data
- Viscosity generator → Parallel snapshot generation: sampled viscosities
- Parallel snapshot generation → Snapshot generator: parallel jobs
- Mesh processing → Snapshot generator: shared mesh boundary
- Stokes FEM library → Snapshot generator: shared FEM assembly
- Snapshot generator → Snapshot archives: solution snapshots
- Viscosity generator → Snapshot archives: viscosity snapshots
- Snapshot archives → Affine decomposition: training data
- Affine decomposition → Offline ROM data: A1–A5 & basis fields
- Offline ROM data → Offline/online ROM demo: online reduced evaluation
