Metadata-Version: 2.4
Name: VesselFlow
Version: 0.0.1
Summary: VesselFlow: In-Silico Vascular Modeling and Flow Simulation
Author-email: Dhaval Kadia <dhavalkadiamsu@gmail.com>
Maintainer-email: Dhaval Kadia <dhavalkadiamsu@gmail.com>
License-Expression: AGPL-3.0-only
Project-URL: Homepage, https://github.com/DhavalKadia/VesselFlow
Project-URL: Repository, https://github.com/DhavalKadia/VesselFlow
Project-URL: Issues, https://github.com/DhavalKadia/VesselFlow/issues
Project-URL: Changelog, https://github.com/DhavalKadia/VesselFlow/blob/main/CHANGELOG.md
Keywords: vascular-modeling,flow-simulation,cfd,hemodynamics
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy<3,>=1.26
Requires-Dist: pyvista>=0.39
Requires-Dist: svmorph>=0.1
Requires-Dist: vmtk>=1.5
Requires-Dist: trimesh>=4
Requires-Dist: matplotlib>=3.8
Requires-Dist: pillow>=10
Requires-Dist: PyYAML>=5.4
Requires-Dist: scipy>=1.10
Requires-Dist: meshio>=5.3
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Requires-Dist: pytest-timeout>=2.5; extra == "test"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: pytest-timeout>=2.5; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=6.1; extra == "dev"
Provides-Extra: all
Requires-Dist: pytest>=8; extra == "all"
Requires-Dist: pytest-timeout>=2.5; extra == "all"
Dynamic: license-file

# VesselFlow

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/DhavalKadia/asset/main/vesselflow/logo/banner-dark.svg">
    <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/DhavalKadia/asset/main/vesselflow/logo/banner-light.svg">
    <img alt="VesselFlow" src="https://raw.githubusercontent.com/DhavalKadia/asset/main/vesselflow/logo/logo.svg" width="440">
  </picture>
</p>

A modular, reproducible CFD pipeline for branching-vessel aneurysm growth. VesselFlow constructs a **single connected, closed lumen surface**, grows aneurysms via **svMorph** Kelvinlets, hex-meshes with OpenFOAM **`snappyHexMesh`**, solves steady incompressible flow with **`simpleFoam`**, and renders headless 3D flow and wall-hemodynamics visualizations.

## Simulations

<table>
  <tr>
    <td colspan="2" align="center">
      <img src="https://raw.githubusercontent.com/DhavalKadia/asset/main/vesselflow/gif/flow.gif" alt="Traced velocity flow animation" width="100%" /><br />
      <sub><b>Traced Velocity Flow</b> (<code>viz/flow.gif</code>)</sub>
    </td>
  </tr>
  <tr>
    <td align="center" width="50%">
      <img src="https://raw.githubusercontent.com/DhavalKadia/asset/main/vesselflow/gif/wall_pressure.gif" alt="Wall pressure" width="100%" /><br />
      <sub><b>Pressure</b> (<code>viz/pressure.gif</code>)</sub>
    </td>
    <td align="center" width="50%">
      <img src="https://raw.githubusercontent.com/DhavalKadia/asset/main/vesselflow/gif/wall_wss.gif" alt="Wall shear stress" width="100%" /><br />
      <sub><b>Wall Shear Stress</b> (<code>viz/wall_wss.gif</code>)</sub>
    </td>
  </tr>
</table>

## Pipeline Stages

1. **Vessel Tree** — Seeded, curved trunk with tapering side branches (`vessel.n_branches`) and an optional U-bend (`vessel.u_radius_mm`). The trunk supports configurable bend modes (`bend_mode`), tapering (`trunk_taper_frac`), and Murray's-law radius step-down at each bifurcation (`murray_law`). Side branches can be tuned via `branch_angle_deg` (bifurcation angle), `branch_azimuth_mode`/`branch_azimuth_deg` (departure azimuth), `branch_tortuosity` (branch meander), `branch_radius_frac`/`branch_taper_frac` (branch radius), and `branch_parent_fracs` (explicit departure locations along the trunk).
2. **Connected Surface** — Single closed, manifold lumen built via VMTK `PolyBallModeller` + `MarchingCubes`, smoothed with `trimesh`, and labeled (`wall`, `inlet`, `outlet`).
3. **Aneurysm Growth** — Self-driven svMorph Kelvinlet deformation on the trunk
   and/or side branches. Each aneurysm location pins its weak-wall arc window via
   its own per-aneurysm `start_frac`/`end_frac` (falling back to the shared trunk
   weak-region window when unset). Two morphologies select a per-vertex weak-region
   gate that confines/amplifies the raw Kelvinlet kernel:

   - **`fusiform`** — symmetric full-circumference axial cosine-bell bulge over
     `[start_frac, end_frac]` (spindle-shaped, all sides of the segment).
   - **`saccular`** — focal one-sided wall-disc bulge of radius `disk_radius_mm`
     centred at the force centre, oriented at `bulge_angle_deg` about the local
     centreline tangent. A C1-smooth one-sided angular gate (`cos_phi <= 0` → 0)
     applies zero weight to the opposite wall, leaving that circumference intact.

   Growth is self-driven: `force_scale`, `eps_radius_fraction`, and `growth_steps`
   govern the emerging sac size, capped at `max_aneurysm_radius_mm`.
4. **Meshing & CFD** — `snappyHexMesh` (`mode inside`) hexahedral polyMesh followed by incompressible `simpleFoam` (`Newtonian` or `BirdCarreau`, `laminar` or `kOmegaSST`).
5. **Hemodynamics** — Computes WSS, Reynolds/Dean/Womersley numbers, pressure drop, clinical vascular resistance, energy dissipation, and vessel/aneurysm morphometrics.
6. **Visualisation & Export** — Headless `flow.gif` (RK2-advected velocity glyphs) and `wall_*.gif` (WSS, pressure, WSSG, near-wall speed), plus representative `.vtk` meshes per GIF.

## Installation & Full Pipeline

The `install_and_run.sh` script installs VesselFlow and OpenFOAM and runs the full pipeline in one go (set `MINICONDA_ROOT` to override the conda location):

```bash
MINICONDA_ROOT=/path/to/miniconda3 ./install_and_run.sh
```

### Manual installation

#### Conda (recommended, includes OpenFOAM)

```bash
conda create -p ./env/vesselflow python=3.12 -y
conda activate ./env/vesselflow
pip install -e .
```

Install OpenFOAM into its own conda environment, use:

```bash
conda create -p ./env/openfoam -c conda-forge openfoam=2412 -y
export OPENFOAM_DIR=./env/openfoam
```

#### pip (PyPI)

```bash
python3.12 -m venv venv && source venv/bin/activate
pip install vesselflow
```

## Usage

Runs are configured by a single YAML file (default: `src/vesselflow/configs/default_config.yaml`).

```bash
# Run full pipeline (mesh + CFD + hemodynamics + viz)
vesselflow pipeline src/vesselflow/configs/default_config.yaml

# Individual subcommands
python -m vesselflow config     src/vesselflow/configs/default_config.yaml  # validate config
python -m vesselflow vessel     src/vesselflow/configs/default_config.yaml  # lumen mesh only
python -m vesselflow centerline src/vesselflow/configs/default_config.yaml  # trunk centreline
python -m vesselflow flowviz    src/vesselflow/configs/default_config.yaml  # re-render flow GIF
```

The preset names are also exposed via the Python API:

```python
from vesselflow.configs import config_path, available_configs
print(available_configs())          # ['default_config', 'trunk_double', ...]
config_path("trunk_loop")           # absolute path to trunk_loop.yaml
```

### Tests

```bash
python -m pytest tests/ -v -m "not slow"    # fast unit tests
python -m pytest tests/test_aneurysm_shapes.py -v  # fusiform vs saccular gate-shape tests
python -m pytest tests/test_pipeline.py -v  # full OpenFOAM integration tests
```

## Python API

```python
from vesselflow import build_vessel_tree, build_connected_surface, run_pipeline
from vesselflow.config import VesselConfig

# Build geometry only
tree = build_vessel_tree(VesselConfig(n_nodes=80), seed=1)
pts, tris, region = build_connected_surface(tree, n_ring=24)

# Or run the full YAML-driven pipeline
summary = run_pipeline(config_path="src/vesselflow/configs/default_config.yaml")
```

## Environment Variables

| Variable | Description |
| :--- | :--- |
| `OPENFOAM_DIR` | Path to OpenFOAM installation (`$OPENFOAM_DIR/bin`). |
| `VESSELFLOW_OUTPUT_DIR` | Default output directory (overridden by YAML `output_dir`). The legacy `VESSELLFLOW_OUTPUT_DIR` spelling is still accepted as a fallback. |
| `MPLCONFIGDIR` | Matplotlib cache directory (defaults to `~/.mplcfg_vesselflow`). |

## Note

Stay curious like cats!

## License

Licensed under **AGPL-3.0-only**. See [LICENSE](https://github.com/DhavalKadia/VesselFlow/blob/main/LICENSE) for details.

## Citation

```bibtex
@software{dhaval_kadia_2026_vesselflow,
  author  = {Kadia, Dhaval},
  title   = {VesselFlow: In-Silico Vascular Modeling and Flow Simulation},
  version = {0.0.1},
  year    = {2026},
  url     = {https://github.com/DhavalKadia/VesselFlow},
  license = {AGPL-3.0-only}
}
```
