# hmella/feelmri architecture

> Architecture diagram of the GitHub repository hmella/feelmri, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hmella/feelmri
- Repository: https://github.com/hmella/feelmri

## Overview

1. **Project shape**
   - FEelMRI is a Python-first scientific imaging library with a compiled C++ backend.
   - The core purpose is to turn finite-element simulation data into synthetic MRI signals and reconstructed images.

2. **Top-level execution model**
   - Users typically run Python example scripts from `examples/`, often under `mpirun`.
   - Inputs come from parameter YAML files, phantom datasets, and optionally FE mesh/solution data.
   - Outputs are simulated MR signals, k-space data, and reconstructed images/plots.

3. **Python package is the orchestration layer**
   - `python/feelmri/` contains the main application logic and most of the user-facing API.
   - Modules are split by concern: physics (`Bloch.py`, `Motion.py`), acquisition (`KSpaceTraj.py`, `MRImaging.py`), reconstruction (`Recon.py`), data models (`MRObjects.py`, `Phantom.py`), configuration (`Parameters.py`), I/O (`IO.py`), filtering/noise/math (`Filters.py`, `Noise.py`, `Math.py`), plotting (`Plotter.py`), and MPI support (`MPIUtilities.py`).

4. **Physics and signal simulation boundary**
   - `Bloch.py` and `Motion.py` represent the MRI physics layer, including spin evolution and motion effects.
   - This layer sits between the FE simulation domain and the acquisition domain: it transforms spatial/temporal state into MR signal evolution.
   - The README’s emphasis on PDE-driven FE simulations and arbitrary cell geometries matches this boundary.

5. **Compiled C++ backend**
   - `cpp/feelmri/` provides performance-critical implementation for assembly and Bloch simulation.
   - Key components include `BlochSimulator`, `Assemble`, `MRIAssemble`, `PODHelper`, and `FEUtils`.
   - This backend is likely the bridge between discrete FE data structures and efficient numerical MR simulation, exposed to Python as an extension module built with CMake.

6. **Data model and configuration flow**
   - `Parameters.py` and the YAML files in `examples/parameters/` define experiment setup: sequence parameters, trajectories, phantoms, and reconstruction settings.
   - `MRObjects.py` provides the structured objects passed through the pipeline.
   - `Phantom.py` and the files in `examples/phantoms/` provide synthetic anatomy/material distributions used as simulation sources.

7. **Acquisition pipeline**
   - `KSpaceTraj.py` defines k-space sampling trajectories.
   - `MRImaging.py` coordinates the simulated acquisition using the chosen sequence, trajectory, and physics modules.
   - The output of this stage is typically complex-valued signal or k-space measurements rather than final images.

8. **Reconstruction and post-processing**
   - `Recon.py` converts simulated acquisition data into image-space outputs.
   - `Filters.py`, `Noise.py`, and `Math.py` support signal conditioning and numerical utilities around the main reconstruction path.
   - `Plotter.py` is used for visual inspection and result generation, especially in the example workflows.

9. **MPI and parallel execution**
   - `MPIUtilities.py` and the README’s `mpirun` instructions indicate the simulation is designed to scale across multiple processes.
   - Parallelism is an architectural boundary: examples are run in distributed fashion, and tests include `test_parallel.py`.
   - This matters for diagramming because simulation work is not single-process-only; it is expected to be partitioned across cores.

10. **Examples as system demonstrations**
   - `examples/` is not just documentation; it is the main integration surface showing end-to-end use cases.
   - The scripts cover distinct MRI scenarios: `4dflow.py`, `free_running.py`, `phase_contrast.py`, `spamm.py`, `water_and_fat.py`, and others.
   - The `examples/planning/` ParaView state files and scripts support FOV planning and geometry setup before simulation.

11. **Build and deployment boundaries**
   - The repo uses `pyproject.toml` plus `CMakeLists.txt` to combine Python packaging with a native extension build.
   - `docker/Dockerfile` provides a reproducible Linux container for the full stack, including MPI and GUI-capable plotting if needed.
   - CI in `.github/workflows/ci.yml` and tests under `tests/` validate imports, example execution, and parallel behavior.

12. **End-to-end architecture summary**
   - The main flow is: configuration/phantom/FE data in → Python orchestration → C++-accelerated FE/Bloch computation → k-space acquisition → reconstruction/post-processing → images/plots out.
   - The important boundary is between the scientific Python orchestration layer and the native C++ numerical backend.
   - A second boundary is between simulation and visualization/planning tooling, which is provided but separate from the core computation path.

Main entry points: [`python/feelmri/MRImaging.py`](https://github.com/hmella/feelmri/blob/main/python/feelmri/MRImaging.py) (MR Imaging), [`examples/4dflow.py`](https://github.com/hmella/feelmri/blob/main/examples/4dflow.py) (Example Suite), [`python/feelmri/Recon.py`](https://github.com/hmella/feelmri/blob/main/python/feelmri/Recon.py) (Recon), [`python/feelmri/Parameters.py`](https://github.com/hmella/feelmri/blob/main/python/feelmri/Parameters.py) (Parameters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_python["Python package"]
  node_n_parameters["Parameters<br/>config/models<br/>[Parameters.py]"]
  node_n_mrobjects["MR Objects<br/>data models<br/>[MRObjects.py]"]
  node_n_phantom["Phantom<br/>data source<br/>[Phantom.py]"]
  node_n_bloch["Bloch<br/>physics<br/>[Bloch.py]"]
  node_n_motion["Motion<br/>physics<br/>[Motion.py]"]
  node_n_kspace["K-space Traj<br/>acquisition<br/>[KSpaceTraj.py]"]
  node_n_mrimaging["MR Imaging<br/>acquisition engine<br/>[MRImaging.py]"]
  node_n_recon["Recon<br/>[Recon.py]"]
  node_n_io["IO<br/>[IO.py]"]
  node_n_plotter["Plotter<br/>visualization<br/>[Plotter.py]"]
  node_n_mpi["MPI Utils<br/>parallel runtime<br/>[MPIUtilities.py]"]
  node_n_filters["Filters<br/>signal tools<br/>[Filters.py]"]
  node_n_noise["Noise<br/>signal tools<br/>[Noise.py]"]
  node_n_math["Math<br/>numerics<br/>[Math.py]"]
end

subgraph group_g_native["Native backend"]
  node_n_cpp_bloch["Bloch Simulator<br/>c++ extension<br/>[BlochSimulator.cpp]"]
  node_n_cpp_assemble["Assemble<br/>c++ extension<br/>[Assemble.cpp]"]
  node_n_cpp_mriassemble["MRI Assemble<br/>c++ extension<br/>[MRIAssemble.cpp]"]
  node_n_cpp_pod["POD Helper<br/>c++ support<br/>[PODHelper.cpp]"]
end

subgraph group_g_examples["Examples"]
  node_n_examples_suite["Example Suite<br/>workflows<br/>[4dflow.py]"]
  node_n_examples_planning["Planning Assets<br/>[README.md]"]
end

subgraph group_g_build["Build and CI"]
  node_n_build["Build System<br/>packaging<br/>[CMakeLists.txt]"]
  node_n_ci["CI and Container<br/>validation/runtime<br/>[ci.yml]"]
end

node_n_parameters -->|"configures"| node_n_phantom
node_n_parameters -->|"selects"| node_n_kspace
node_n_parameters -->|"drives"| node_n_mrimaging
node_n_phantom -->|"feeds"| node_n_mrimaging
node_n_mrobjects -->|"structures"| node_n_mrimaging
node_n_bloch -->|"physics"| node_n_mrimaging
node_n_motion -->|"motion"| node_n_mrimaging
node_n_kspace -->|"samples"| node_n_mrimaging
node_n_mrimaging -->|"produces"| node_n_recon
node_n_recon -->|"visualized by"| node_n_plotter
node_n_filters -->|"supports"| node_n_recon
node_n_noise -->|"supports"| node_n_recon
node_n_math -->|"supports"| node_n_mrimaging
node_n_math -->|"supports"| node_n_recon
node_n_mpi -->|"parallelizes"| node_n_mrimaging
node_n_examples_suite -->|"loads"| node_n_parameters
node_n_examples_suite -->|"runs"| node_n_mrimaging
node_n_examples_suite -->|"renders"| node_n_plotter
node_n_examples_suite -->|"executes with"| node_n_mpi
node_n_examples_planning -->|"supports"| node_n_examples_suite
node_n_cpp_assemble -->|"feeds"| node_n_cpp_mriassemble
node_n_cpp_mriassemble -->|"supports"| node_n_cpp_bloch
node_n_build -->|"builds"| node_n_cpp_bloch
node_n_build -->|"packages"| node_n_mrimaging
node_n_ci -->|"validates"| node_n_examples_suite
node_n_ci -->|"verifies"| node_n_build

click node_n_parameters "https://github.com/hmella/feelmri/blob/main/python/feelmri/Parameters.py"
click node_n_mrobjects "https://github.com/hmella/feelmri/blob/main/python/feelmri/MRObjects.py"
click node_n_phantom "https://github.com/hmella/feelmri/blob/main/python/feelmri/Phantom.py"
click node_n_bloch "https://github.com/hmella/feelmri/blob/main/python/feelmri/Bloch.py"
click node_n_motion "https://github.com/hmella/feelmri/blob/main/python/feelmri/Motion.py"
click node_n_kspace "https://github.com/hmella/feelmri/blob/main/python/feelmri/KSpaceTraj.py"
click node_n_mrimaging "https://github.com/hmella/feelmri/blob/main/python/feelmri/MRImaging.py"
click node_n_recon "https://github.com/hmella/feelmri/blob/main/python/feelmri/Recon.py"
click node_n_io "https://github.com/hmella/feelmri/blob/main/python/feelmri/IO.py"
click node_n_plotter "https://github.com/hmella/feelmri/blob/main/python/feelmri/Plotter.py"
click node_n_mpi "https://github.com/hmella/feelmri/blob/main/python/feelmri/MPIUtilities.py"
click node_n_filters "https://github.com/hmella/feelmri/blob/main/python/feelmri/Filters.py"
click node_n_noise "https://github.com/hmella/feelmri/blob/main/python/feelmri/Noise.py"
click node_n_math "https://github.com/hmella/feelmri/blob/main/python/feelmri/Math.py"
click node_n_cpp_bloch "https://github.com/hmella/feelmri/blob/main/cpp/feelmri/BlochSimulator.cpp"
click node_n_cpp_assemble "https://github.com/hmella/feelmri/blob/main/cpp/feelmri/Assemble.cpp"
click node_n_cpp_mriassemble "https://github.com/hmella/feelmri/blob/main/cpp/feelmri/MRIAssemble.cpp"
click node_n_cpp_pod "https://github.com/hmella/feelmri/blob/main/cpp/feelmri/PODHelper.cpp"
click node_n_examples_suite "https://github.com/hmella/feelmri/blob/main/examples/4dflow.py"
click node_n_examples_planning "https://github.com/hmella/feelmri/blob/main/examples/planning/README.md"
click node_n_build "https://github.com/hmella/feelmri/blob/main/CMakeLists.txt"
click node_n_ci "https://github.com/hmella/feelmri/blob/main/.github/workflows/ci.yml"

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_n_parameters,node_n_mrobjects,node_n_phantom,node_n_bloch,node_n_motion,node_n_kspace,node_n_mrimaging,node_n_recon,node_n_io,node_n_plotter,node_n_mpi,node_n_filters,node_n_noise,node_n_math toneBlue
class node_n_cpp_bloch,node_n_cpp_assemble,node_n_cpp_mriassemble,node_n_cpp_pod toneAmber
class node_n_examples_suite,node_n_examples_planning toneMint
class node_n_build,node_n_ci toneRose
```

## Components

### Python package

User-facing orchestration layer and scientific MRI pipeline modules.

- [Parameters](https://github.com/hmella/feelmri/blob/main/python/feelmri/Parameters.py): config/models · Experiment setup, sequence options, and runtime configuration objects. · `python/feelmri/Parameters.py`
- [MR Objects](https://github.com/hmella/feelmri/blob/main/python/feelmri/MRObjects.py): data models · Structured objects passed through acquisition and reconstruction stages. · `python/feelmri/MRObjects.py`
- [Phantom](https://github.com/hmella/feelmri/blob/main/python/feelmri/Phantom.py): data source · Synthetic anatomy and material distributions used as simulation inputs. · `python/feelmri/Phantom.py`
- [Bloch](https://github.com/hmella/feelmri/blob/main/python/feelmri/Bloch.py): physics · MRI spin evolution and signal formation logic in Python. · `python/feelmri/Bloch.py`
- [Motion](https://github.com/hmella/feelmri/blob/main/python/feelmri/Motion.py): physics · Motion and deformation effects coupled into the simulated signal. · `python/feelmri/Motion.py`
- [K-space Traj](https://github.com/hmella/feelmri/blob/main/python/feelmri/KSpaceTraj.py): acquisition · Definitions of k-space sampling trajectories. · `python/feelmri/KSpaceTraj.py`
- [MR Imaging](https://github.com/hmella/feelmri/blob/main/python/feelmri/MRImaging.py): acquisition engine · Coordinates simulation of acquisition from physics, trajectory, and inputs. · `python/feelmri/MRImaging.py`
- [Recon](https://github.com/hmella/feelmri/blob/main/python/feelmri/Recon.py): reconstruction · Converts simulated measurements into image-space outputs. · `python/feelmri/Recon.py`
- [IO](https://github.com/hmella/feelmri/blob/main/python/feelmri/IO.py): io · File loading and persistence for inputs and outputs. · `python/feelmri/IO.py`
- [Plotter](https://github.com/hmella/feelmri/blob/main/python/feelmri/Plotter.py): visualization · Visualization and result generation for simulations and examples. · `python/feelmri/Plotter.py`
- [MPI Utils](https://github.com/hmella/feelmri/blob/main/python/feelmri/MPIUtilities.py): parallel runtime · MPI-oriented helpers for distributed execution. · `python/feelmri/MPIUtilities.py`
- [Filters](https://github.com/hmella/feelmri/blob/main/python/feelmri/Filters.py): signal tools · Signal conditioning and filtering utilities. · `python/feelmri/Filters.py`
- [Noise](https://github.com/hmella/feelmri/blob/main/python/feelmri/Noise.py): signal tools · Noise models and perturbation utilities. · `python/feelmri/Noise.py`
- [Math](https://github.com/hmella/feelmri/blob/main/python/feelmri/Math.py): numerics · Numerical helper routines shared across the Python pipeline. · `python/feelmri/Math.py`

### Native backend

C++ extension code for performance-critical finite-element and Bloch simulation work.

- [Bloch Simulator](https://github.com/hmella/feelmri/blob/main/cpp/feelmri/BlochSimulator.cpp): c++ extension · Native Bloch simulation implementation for performance-critical workloads. · `cpp/feelmri/BlochSimulator.cpp`
- [Assemble](https://github.com/hmella/feelmri/blob/main/cpp/feelmri/Assemble.cpp): c++ extension · Finite-element assembly routines for simulation inputs. · `cpp/feelmri/Assemble.cpp`
- [MRI Assemble](https://github.com/hmella/feelmri/blob/main/cpp/feelmri/MRIAssemble.cpp): c++ extension · Native bridge from FE data structures to MRI-oriented assembly. · `cpp/feelmri/MRIAssemble.cpp`
- [POD Helper](https://github.com/hmella/feelmri/blob/main/cpp/feelmri/PODHelper.cpp): c++ support · Helper routines for low-dimensional numerical support paths. · `cpp/feelmri/PODHelper.cpp`

### Examples

End-to-end workflows, parameters, phantoms, meshes, and planning assets.

- [Example Suite](https://github.com/hmella/feelmri/blob/main/examples/4dflow.py): workflows · End-to-end executable scenarios demonstrating the main simulation pipeline. · `examples/4dflow.py`
- [Planning Assets](https://github.com/hmella/feelmri/blob/main/examples/planning/README.md): planning · ParaView states and setup artifacts for geometry and field-of-view planning. · `examples/planning/README.md`

### Build and CI

Packaging, native build, containerization, and validation infrastructure.

- [Build System](https://github.com/hmella/feelmri/blob/main/CMakeLists.txt): packaging · Python packaging plus native build integration. · `CMakeLists.txt`
- [CI and Container](https://github.com/hmella/feelmri/blob/main/.github/workflows/ci.yml): validation/runtime · Automated validation and reproducible containerized runtime support. · `.github/workflows/ci.yml`

## Connections

- Parameters → Phantom: configures · Parameters define the phantom and experiment setup.
- Parameters → K-space Traj: selects · Parameters specify the sampling trajectory and sequence settings.
- Parameters → MR Imaging: drives · Runtime options flow into the acquisition engine.
- Phantom → MR Imaging: feeds · Phantom data provides the simulated object being imaged.
- MR Objects → MR Imaging: structures · Shared objects carry experiment state into acquisition.
- Bloch → MR Imaging: physics · Bloch dynamics are used during signal simulation.
- Motion → MR Imaging: motion · Motion effects perturb acquisition and signal evolution.
- K-space Traj → MR Imaging: samples · Trajectory definition determines how k-space is traversed.
- MR Imaging → Recon: produces · Simulated measurements are passed to reconstruction.
- Recon → Plotter: visualized by · Reconstructed images are rendered for inspection.
- Filters → Recon: supports · Filtering assists reconstruction and post-processing.
- Noise → Recon: supports · Noise utilities model or adjust measurement contamination.
- Math → MR Imaging: supports · Shared numerical helpers support the simulation pipeline.
- Math → Recon: supports · Shared numerical helpers support reconstruction routines.
- MPI Utils → MR Imaging: parallelizes · MPI helpers support distributed simulation execution.
- Example Suite → Parameters: loads · Example scripts consume YAML parameter files.
- Example Suite → MR Imaging: runs · Examples execute the main simulation pipeline.
- Example Suite → Plotter: renders · Examples generate plots and result figures.
- Example Suite → MPI Utils: executes with · Examples are often launched under MPI.
- Planning Assets → Example Suite: supports · Planning assets prepare geometry and acquisition setup for examples.
- Assemble → MRI Assemble: feeds · Assembly routines underpin MRI-oriented native assembly.
- MRI Assemble → Bloch Simulator: supports · Native assembly and Bloch simulation cooperate in the backend.
- Build System → Bloch Simulator: builds · CMake integrates the native extension build.
- Build System → MR Imaging: packages · The build system packages the Python orchestration layer.
- CI and Container → Example Suite: validates · CI checks that examples run successfully.
- CI and Container → Build System: verifies · CI validates packaging and native build integration.
