How japanese-maple/finite-element-method-fem-rom-reduced-order-modeling works
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: Stokes_felib.py Stokes FEM library · Exchanger_device.npz Solution archives · snapshot_generator.py Snapshot generator · Mesh_processing.py Mesh processing
Components 16
Mesh & discretization
- Mesh archives · Precomputed geometry and connectivity inputs.
Meshes/exchanger_device_mesh_data.npz - Mesh processing · Builds coarse pressure and refined velocity meshes.
Utilities/Mesh_processing.py
Full-order Stokes FEM
- Stokes FEM library · Assembles stiffness, coupling, and mass blocks.
Utilities/Stokes_felib.py - Exchanger-device solver · Applies conditions, solves the saddle-point system, and persists fields.
Solvers/Exchanger_Device.py
Results & analysis
- Solution archives · Persisted full-order fields for reuse and analysis.
Solutions/Exchanger_device.npz - Plot functions
Utilities/Plot_functions.py - Flow examples · Visualizes solved flow fields.
Demonstrations/Flow_examples.ipynb - Convergence study · Compares stored refinement solutions.
Demonstrations/Stokes_Convergence.ipynb - LBB stability study · Evaluates the discrete inf-sup condition.
Demonstrations/Stokes_Stability.ipynb
Reduced-order modeling
- Viscosity generator
Reduced_Order_Modeling/No_Online_Offline_phase/viscosity_generator.py - Snapshot generator · Solves parameterized full-order cases.
Reduced_Order_Modeling/No_Online_Offline_phase/snapshot_generator.py - Parallel snapshot generation
Reduced_Order_Modeling/No_Online_Offline_phase/parallelized_sg.py - Snapshot archives · Stores viscosity and Stokes solution snapshots.
- Affine decomposition · Prepares parameter-separated reduced operators and basis fields.
Reduced_Order_Modeling/Online_Offline_phase/Affine_Decomposition.py - Offline ROM data · A1–A5 operators and basis fields for online evaluation.
Reduced_Order_Modeling/Online_Offline_phase/Data/A1.npz - Offline/online ROM demo · Consumes offline data for low-cost online evaluation.
Demonstrations/ROM_OfflineIOnline.ipynb
Connections 19
- 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