Skip to content

Add native CPU, Metal, and CUDA microfluidic flow solvers - #3

Open
marpaia wants to merge 4 commits into
marpaia/microfluidics-primitivesfrom
marpaia/microfluidics-flow-solvers
Open

Add native CPU, Metal, and CUDA microfluidic flow solvers#3
marpaia wants to merge 4 commits into
marpaia/microfluidics-primitivesfrom
marpaia/microfluidics-flow-solvers

Conversation

@marpaia

@marpaia marpaia commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Purpose

This PR adds microfluidic flow solving to the native ComputeBackend interface. PR #2 supplies voxel obstacles, boundary conditions, and face-staggered velocity storage; this layer turns those authored device inputs into steady velocity fields on the CPU, Metal, or CUDA backend selected by a Simulation. Cell motion under the solved field remains in PR #4.

Native backend architecture

  • cm/flow.hpp defines backend-neutral parameters, convergence reports, and results for depth-averaged and resolved flow. ComputeBackend declares both operations, and Simulation exposes them to C++ and Python.
  • The CPU backend is the readable C++ reference implementation. The Metal backend implements the operators, Krylov vector updates, and reductions in MSL. The CUDA backend implements the corresponding operations in CUDA C++. Accelerator vectors remain in device memory during a solve; only scalar reduction results and the final field return to the host. Neither accelerator implementation calls the CPU solver.
  • The Python modules cellmodeller2.flow and cellmodeller2.stokes construct dense geometry and coefficient arrays, validate arguments, and dispatch through the selected Simulation. They no longer contain NumPy implementations of the linear solvers.

Numerical methods

  • Depth-averaged flow: solve div(m grad p) = 0 over fluid voxels, with harmonic face mobility, fixed pressure at the inlet and outlet, and zero flux across solid or non-flow boundaries. The matrix-free symmetric positive-definite system uses Jacobi-preconditioned conjugate gradient. Face velocities are reconstructed as -m grad p and rescaled to the requested mean inlet speed.
  • Resolved flow: discretize mu lap(v) - mu d(x) v - grad(p) = 0 with div(v) = 0 on the engine MAC grid. Fluid-solid faces impose no slip, flow-axis boundaries impose pressure, and optional Brinkman drag represents porous colony resistance. A matrix-free pressure Schur solve uses an outer preconditioned conjugate-gradient iteration and inner preconditioned momentum solves.
  • Both interfaces use binary32 fields, default relative tolerances of 1e-6, explicit iteration limits, convergence reports, and the same face layout consumed by signal transport.

Device authoring

TrapChannelDevice and BiopixelTrapDevice generate mechanics walls, a conservative solid mask, fixed reservoirs, gap-height mobility, and an initial flow field from one set of dimensions. gap_mobility, colony_mobility, and colony_drag prepare coefficients for native solves. Simulation.set_velocity_field installs a re-solved field atomically for transport, drift, and checkpointing.

Scientific scope

  • The depth-averaged solver is a Hele-Shaw closure. It omits resolved side-wall boundary layers and returns gap-mean velocity.
  • The MAC solver resolves viscous profiles only to the supplied voxel grid; min_gap_voxels reports the narrowest transverse resolution.
  • Both solvers prescribe a unit pressure shape and normalize velocity to a requested mean inlet speed. They model constant-flow operation rather than predicting pressure drop.
  • Colony mobility and drag are phenomenological closures whose coefficients, voxel size, and update cadence require sensitivity analysis.
  • The benchmark suite verifies the discretizations against exact and literature reference solutions. It is not experimental validation of a physical device.

Stack

PR 2 of 5.

Base: #2 (marpaia/microfluidics-primitives), unchanged by this rewrite.

Next: #4 (marpaia/microfluidics-experimental-coupling).

Validation at 1c7a725

  • Full pre-commit suite, including Ruff, clang-format, and Pyright: passed
  • CPU native tests: 22 of 22 passed
  • Metal native tests on Apple M4 Max: 23 of 23 passed, including flow conformance and the backend contract
  • Python suite: 249 passed, 42 skipped
  • CPU and Metal analytic flow benchmarks: 10 of 10 checks passed on each backend
  • CUDA 12.8 compile and link gate: 72 targets built and 23 tests registered; no NVIDIA runtime was available, so CUDA runtime conformance remains pending

@marpaia
marpaia force-pushed the marpaia/microfluidics-flow-solvers branch from 90c7b60 to 1ac63e0 Compare August 20, 2026 20:52
@marpaia
marpaia marked this pull request as ready for review August 20, 2026 23:47
@marpaia marpaia changed the title Add numerical flow solvers for device authoring Add native CPU, Metal, and CUDA microfluidic flow solvers Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant