Skip to main content

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.

Greyscale center-slice particle animation through the U-bend Selected speed-colored particle trajectories through the U-bend Speed-colored particles tracked through the full pulsatile U-bend example

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)·area at 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). Omit dt for plane seeding.
  • flux_waveform() returns per-cap net flux over the cycle — a conservation / validation diagnostic (Σ caps ≈ 0 for 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mrsimtracks-0.2.1.tar.gz (3.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mrsimtracks-0.2.1-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file mrsimtracks-0.2.1.tar.gz.

File metadata

  • Download URL: mrsimtracks-0.2.1.tar.gz
  • Upload date:
  • Size: 3.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mrsimtracks-0.2.1.tar.gz
Algorithm Hash digest
SHA256 775960b0d9a81b9bfb30bf655553757bcb76dadd66ca58df596493d6ede49cfb
MD5 2b75b506a0359209a8e73fbeba2df8b3
BLAKE2b-256 ad3472d58c79166ae9d93aef11a6dc68f046df4c34d76429a2cebaa0c058610c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mrsimtracks-0.2.1.tar.gz:

Publisher: publish.yml on mcgrathcm/MRSimTracks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mrsimtracks-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mrsimtracks-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mrsimtracks-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 084038ebfe2cf2cfb0f48a1469a6d2bc7c9e8a418d3f301f94a79b8dc391bcef
MD5 43b49f953d539a0ba740a92865260011
BLAKE2b-256 2672c50567bde1e70ec3782a444000f8a75cc46f800af4ae99c165e7601f25c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for mrsimtracks-0.2.1-py3-none-any.whl:

Publisher: publish.yml on mcgrathcm/MRSimTracks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page