Generate CFD-derived particle trajectories for MR flow simulation.
Project description
MRSimTracks
Generate CFD-derived particle trajectories for MR flow simulation.
MRSimTracks performs Lagrangian particle tracking in time-resolved (pulsatile) CFD meshes. It operates on mesh velocity fields, not MR image data. It seeds particles in a tetrahedral flow domain, advects them through a time-periodic velocity field (RK4), and recycles out-of-bounds particles back to the inflow boundaries with optional backflow-aware reseeding.
Install
MRSimTracks is published on PyPI:
uv add "mrsimtracks==0.2.0"
or with pip:
python -m pip install "mrsimtracks==0.2.0"
To install the latest source from GitHub instead:
uv add "mrsimtracks @ git+https://github.com/mcgrathcm/MRSimTracks.git"
For development from a clone:
uv sync # installs the package (editable) and dependencies
The distribution name and Python import package are both mrsimtracks.
Quick start
import numpy as np
import mrsimtracks as mt
from mrsimtracks.seeding import seed_mesh
# 1. Load a time-resolved flow field (.vtu single-file series or .pvd collection)
flow = mt.load_flow("case.pvd", active_key="Velocity")
# 2. (optional) Backflow-aware inflow reseeder from labeled cap surfaces
reseeder = mt.BoundaryReseeder(["Inlet.vtp", "Outlet.vtp"], flow, dt=0.002)
# 3. (optional) Near-wall no-penetration projection
wall_slip = mt.WallSlip(flow, caps=["Inlet.vtp", "Outlet.vtp"])
# 4. Seed and track
seeds = seed_mesh(flow.active_mesh, 200_000, rng=np.random.default_rng(0))
result = mt.track(
flow,
seeds=seeds,
dt=0.002,
reseeder=reseeder,
wall_slip=wall_slip,
)
# 5. Use / save
result.positions # (n_steps, n_particles, 3)
result.reset # (n_steps, n_particles) reseed flags
result.times # (n_steps,)
result.save("tracks.h5")
For large single-process runs, write each timestep directly to HDF5 instead of keeping all positions in RAM:
result, metrics = mt.track(
flow,
seeds=seeds,
dt=0.002,
reseeder=reseeder,
output_path="tracks.h5",
return_metrics=True,
)
result.is_file_backed # True until result.positions or result.reset is loaded
metrics["particle_steps_per_s"]
Run example.py for a complete version using the reduced fixture committed in
tests/data/. The full-cycle example flow file is tracked with Git LFS; see
example/README.md.
Large runs (multiple processes)
Each worker reloads the field, so memory scales with n_workers:
result = mt.track_parallel(
"case.pvd", seeds=seeds, dt=0.002,
caps=["Inlet.vtp", "Outlet.vtp"], active_key="Velocity",
n_workers=3, subsamp=1, wall_slip=True,
)
Key functions
| Function | Purpose |
|---|---|
load_flow(path, active_key=...) |
Load .vtu (one geometry, many time fields) or .pvd (series); auto-selects the memory-efficient reader. subsamp=N keeps every Nth frame. |
track(flow, seeds=..., dt=..., reseeder=...) |
Single-process tracking → TrackingResult. Use output_path=... for streamed HDF5 output and return_metrics=True for timing metrics. |
track_parallel(path, ..., caps=..., n_workers=...) |
Multi-process tracking → TrackingResult. |
BoundaryReseeder(caps, flow, dt=...) |
Flux-weighted, time-resolved inflow reseeder. caps = cap surface path(s) or a surface with a region_id cell array. |
WallSlip(flow, caps=..., band_frac=0.02) |
Optional near-wall no-penetration projection for track(..., wall_slip=...). Excludes cap faces so inlet/outlet flux remains open. |
Reseeding notes
- The reseeder weights every cap face by
max(-v·n, 0)·areaat the nearest flow frame, so particles re-enter only through currently-inflow faces — handling backflow and partial inflow/outflow on a single cap. BoundaryReseeder(..., dt=dt)spreads new particles over a thin inflow volume (depth~v_n·dt) so successive reseeds overlap, keeping spatial density smooth (important for MR-style uniform-density use). Omitdtfor plane seeding.flux_waveform()returns per-cap net flux over the cycle — a conservation / validation diagnostic (Σ caps ≈ 0for a well-resolved incompressible field).
Wall-slip notes
WallSlip removes only the into-wall velocity component for particles within a
thin wall band. Use it when interpolated near-wall velocities deposit particles
against no-slip walls. Pass the same cap surfaces used for reseeding so open
boundaries are excluded from the wall set:
wall_slip = mt.WallSlip(flow, caps=["Inlet.vtp", "Outlet.vtp"], band_frac=0.02)
result = mt.track(
flow,
seeds=seeds,
dt=0.002,
reseeder=reseeder,
wall_slip=wall_slip,
)
For track_parallel, set wall_slip=True; each worker builds its own
projection from the worker-local flow and caps.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mrsimtracks-0.2.0.tar.gz.
File metadata
- Download URL: mrsimtracks-0.2.0.tar.gz
- Upload date:
- Size: 3.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bba17c391545e0b6e79bbc65c03beefbe887fbac3f6e2c1a2eb20867144944e
|
|
| MD5 |
25cc24e218c055111e9f25946f69c1df
|
|
| BLAKE2b-256 |
ebd978490dbc8a65898a17a2b159f54313c1a1873f12afde2c9c10ebb012c432
|
Provenance
The following attestation bundles were made for mrsimtracks-0.2.0.tar.gz:
Publisher:
publish.yml on mcgrathcm/MRSimTracks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mrsimtracks-0.2.0.tar.gz -
Subject digest:
6bba17c391545e0b6e79bbc65c03beefbe887fbac3f6e2c1a2eb20867144944e - Sigstore transparency entry: 1934712314
- Sigstore integration time:
-
Permalink:
mcgrathcm/MRSimTracks@e3c0cae34d26a6aaf3d94425b5e28308f4aefd93 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/mcgrathcm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e3c0cae34d26a6aaf3d94425b5e28308f4aefd93 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mrsimtracks-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mrsimtracks-0.2.0-py3-none-any.whl
- Upload date:
- Size: 34.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bc0acfc736315367e75ccb868060cf5d3601359bb3171f17e6421716f27a948
|
|
| MD5 |
820fef54d1ee464eeec374c3a299a3c7
|
|
| BLAKE2b-256 |
7de3947944c82573cf1f0c8becd37f9f884dc8dce82495c42d807172ed899b47
|
Provenance
The following attestation bundles were made for mrsimtracks-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on mcgrathcm/MRSimTracks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mrsimtracks-0.2.0-py3-none-any.whl -
Subject digest:
5bc0acfc736315367e75ccb868060cf5d3601359bb3171f17e6421716f27a948 - Sigstore transparency entry: 1934712390
- Sigstore integration time:
-
Permalink:
mcgrathcm/MRSimTracks@e3c0cae34d26a6aaf3d94425b5e28308f4aefd93 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/mcgrathcm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e3c0cae34d26a6aaf3d94425b5e28308f4aefd93 -
Trigger Event:
workflow_dispatch
-
Statement type: