Skip to content

About

Focused port of GPU-accelerated, differentiable biomechanics in warp-python

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

FEBio-Warp-Python

GPU-accelerated, differentiable finite element mechanics for cardiovascular simulation, written in Python on Warp and built in concert with the FEBio team to support the P3 CHD project. The formulations follow FEBio, but deviate where it makes sense for warp. The architecture is designed for the GPU and for differentiation, follows the development conventions of Warp, and is meant to work with Newton, 3D Slicer, SlicerHeart and SlicerSimVascular.

FEBio-Warp is intended to stand next to FEBio, not to replace it. FEBio remains the place for broad constitutive modeling and general biomechanics. FEBio-Warp targets a focused set of applications where speed and gradients matter.

Project status

Early stage, nothing released. First implementations of the areas in the table below are on main. They agree with FEBio on single elements, small meshes and problems of the FEBio test suite, on CPU and on a GPU. Interfaces will change.

Try it

uv sync --extra dev                                                        # environment with Warp
uv run -m warp_febio inspect references/single_element/hex8_pressure.feb   # what the input needs, and whether it can run
uv run -m warp_febio run references/single_element/hex8_pressure.feb -o hex8_pressure.xplt
uv run examples/run_path/basic_example.py                                  # the run path step by step, with gradients

inspect lists every feature of a FEBio input by its FEBio name and says whether FEBio-Warp implements it. run solves the input and writes a FEBio plot file (.xplt) and, where the input asks for them, FEBio's log data files beside it. The example prints each stage, compares the result with FEBio, and ends with adjoint gradients. Add --device cuda:0 to run, or cuda:0 after the example, to use a GPU. Install has the details.

Where FEBio-Warp has a form of its own that suits a GPU and gradients better, FEBio's behavior is one argument away (--febio), and run prints the choices in use; see where this code differs from FEBio.

Design and status

flowchart TB
    feb([".feb"]):::done --> model["Model and I/O"]:::done
    model --> system
    subgraph system["System on the device"]
        direction TB
        mat["Materials"]:::done
        elem["Solids and shells<br/>hex8, tet4, quad4"]:::done
        chord["Trusses and springs<br/>for chordae"]:::done
        loads["Pressure, nodal loads,<br/>body force, mass damping,<br/>load curves"]:::done
        bcs["Fixed and prescribed<br/>displacements"]:::done
        shape["Shape enforcement<br/>sliding-elastic to a fixed<br/>target, slide-line"]:::done
        pot["Contact potential,<br/>on its own and in a run"]:::done
        beams["Beams, three-field<br/>solid, constraints"]:::todo
        rigid["Rigid bodies that move,<br/>joints, sticky contact,<br/>friction"]:::todo
        mat ~~~ loads ~~~ pot
        elem ~~~ bcs ~~~ beams
        chord ~~~ shape ~~~ rigid
    end
    system --> run
    subgraph run["Run path"]
        direction TB
        steps["Static and dynamic steps<br/>in sequence,<br/>activation by step"]:::done
        newton["Newton or FEBio's<br/>quasi-Newton,<br/>FEBio's line search"]:::done
        linear["Linear solve<br/>iterative, sparse LU,<br/>cuDSS"]:::done
        pre["Preconditioning<br/>for shells"]:::todo
        steps --> newton --> linear
        steps ~~~ pre
    end
    run --> results([".xplt, log data,<br/>VTKHDF"]):::done
    febio["FEBio, same input"] -.->|verification| results
    run -.-> grad["Gradients through<br/>one equilibrium solve"]:::done
    grad -.-> traj["Gradients over the steps<br/>of a dynamic run"]:::done
    traj -.-> hist["Gradients through<br/>material history"]:::todo
    classDef done fill:#d8f0e1,stroke:#1a7f47,color:#0b3d20
    classDef todo fill:#f6f6f6,stroke:#8a8a8a,color:#444444,stroke-dasharray:5 4
Loading

Green boxes work today, as first templates. Dashed boxes have no code yet; most have a design note.

The table gives the same picture by area. "Works today" means code on main, tested on CPU and on a GPU, and compared with FEBio where a counterpart exists. It is a first implementation, not a settled design: the run path in particular is a template, and each design note ends with decision points that are still open.

Open question for the FEBio and Warp teams: how should a new term enter the system? Today each new domain, load, interface or constraint is added by editing shared functions in analysis/steps.py, where FEBio registers each class under its type string and creates it through a factory. Whether a registry of that kind is the structure to choose here is decision P1 of the work plan. Work continues the current way in the meantime.

Every open question and decision, with who is asked, is listed on one page that is kept current: open questions and decisions.

Area Package Works today Still to do Design notes and diagrams
Model, input and output model/, io/, output/ One model object for a FEBio input. Reads and writes .feb and .xplt; writes VTKHDF; mesh exchange with 3D Slicer. Coverage report (inspect). A registry of FEBio's plot variables and FEBio's log data files, with the outputs the open mitral closure input requests Results streamed to the writer; plot and log variables that need a value not held yet (accelerations, strain energy density) Model and I/O (diagram, decisions), output (diagram)
Materials materials/ Neo-Hookean, isotropic elastic, isotropic Lee-Sacks, HGO (unconstrained; the uncoupled form at the material level only, since a run of it needs the three-field solid), solid mixtures; spring and linear truss laws; effective-modulus nitinol (Zelonis et al., Maheshwari et al.). One Warp kernel per material tree, with gradients; tangent_scale of isotropic Lee-Sacks as an option for Newton's tangent Redesign after review; superelastic nitinol; Ogden; per-element material axes Materials (diagram, decisions)
Contact contact/ FEBio's contact potential, on its own and in a run: pair search on the device, force, tangent, gradients. FEBio's form and a smooth form. Smooth contact measures for objectives. Count of intersecting facet pairs. FEBio's sliding-elastic with tension against a fixed rigid target (shape enforcement) Element-pair w_tol; step cut on a facet crossing; gradients in the radii and the exponent of the potential (kc has one); sticky and tied contact; sliding contact with friction; contact against rigid bodies that move; activation by step for sliding-elastic (a contact potential of a step is built) Contact (diagram, decisions), contact in a run (diagram), shape enforcement (diagram)
Elements elements/ hex8 and tet4 solids; quad4 shell; two-node trusses (regular and tension-only); springs. Consistent mass for hex8, quad4 shell and truss tet4 mass; rigid bodies; three-field solid, penta6, tri3 shell; beams Trusses and springs (diagram), elements (diagram)
Unknowns and assembly discretization/, assembly/ Unknowns by (node, variable); full assembly of residual and tangent into a block sparse matrix with a fixed pattern How a new term enters the system (open question P1); timing on a GPU at application size Run path (diagram, decisions), assembly
Loads and constraints loads/, constraints/ Follower pressure; nodal loads; mass damping; a constant body force (const, body force); load curves on mass damping C and on contact kc; FEBio's four extend modes of a load curve; body loads on an element set, applied as FEBio applies them; fixed and prescribed displacements, also one value per node from a map; the slide-line constraint; a fixed rigid body as geometry A body force that varies in space; rigid boundary conditions and joints; normal-displacement and multipoint constraints Dynamics, constraints (diagram)
Solvers solvers/ Full Newton with FEBio's line search, and FEBio's quasi-Newton strategies (BFGS, Broyden) with tangent_scale as an option; CG, BiCGSTAB and GMRES on the device; sparse LU on the host; optional cuDSS on the device, also with a pattern that only grows and factors reused across solves Preconditioning for shells; transpose solve from cuDSS factors Run path (one Newton iteration), linear solve (diagram)
Analysis analysis/ Static and implicit dynamic steps (alpha_f = 1) with FEBio's automatic time stepper. Several steps in sequence, as FEBio runs them: each with its own Control, and with the conditions, loads and interfaces declared in it acting while it runs. inspect reports which records act in which step alpha_f below 1; a static step after a dynamic one; rigid and initial conditions by step Run path, dynamics (one dynamic step), several steps (diagram, decisions)
Sensitivity sensitivity/ Adjoint gradients through one equilibrium solve and through the steps of a dynamic run, also with self-contact and across the boundary between analysis steps Material history; the radii and the exponent of the contact potential; the mass; transpose solve on cuDSS factors Sensitivity (diagram)
Verification tests/, references/ FEBio references for material points, single elements, small meshes and small problems; FEBio test suite problems; closure of an open mitral valve model. Quick and full test tiers, CPU and GPU Field comparison against a pinned FEBio build; the remaining application inputs Verification (diagram, decisions)

Where to read more:

  • Design overview: how the pieces fit (the whole path, one run), and where the design follows FEBio and where it differs. Start here.
  • Remaining areas (diagram): for each area, what is built and what still stands between the code and the applications, in order, with the open decisions listed by who is best placed to make them.
  • Work plan: the work packages, their state, and what can start now.
  • All design notes, each with a flow diagram and its decision points.

Testing uses the FEBio test suite first, then the open models in the FEBio model repository user projects, with small generated inputs only where neither has a case that fits.

Relation to FEBio's structure

The package layout under src/warp_febio/ follows FEBio's separation of concerns.

FEBio-Warp FEBio counterpart
mesh/, discretization/ FECore mesh, degrees of freedom, element traits
elements/ FEBioMech domains
materials/ FEBioMech materials
loads/, constraints/, contact/ FEBioMech loads, constraints and contact interfaces
assembly/, solvers/ FECore solver interfaces, NumCore linear solvers
analysis/ FECore analysis steps
io/ FEBioXML, FEBioPlot
output/ FEBioMech plot and log data classes (FEBioMechPlot, FEBioMechData)
sensitivity/ Added here

Contributing

Large new sections start as a design note in docs/design/: a template of the approach and its open decisions, for discussion before and alongside the code. Exploratory work is welcome and belongs in pilots/ until it has been designed, reviewed and verified against FEBio. See CONTRIBUTING.md.

Pilot work

The initial prototypes were contributed by @aslanseda9: an explicit membrane patch solver, Lee-Sacks and neo-Hookean material-point functions, and a solid elasticity check built on warp.fem. They were written to explore the approach, not as verified implementations, and each one lists what it does and does not establish. They remain available and runnable in pilots/ and at the pilot-2026-11 tag. They are not maintained and are not a dependency of the package.

The FEBio inputs and results assembled during the pilot phase are kept in references/febio/. They will be reviewed for inclusion in the verification harness and should not be read as verified benchmarks until then.

Install

The project uses uv for environments and Ruff for linting and formatting, as Warp does.

uv sync --extra dev
uv run -m unittest discover -s tests -v                                  # quick tier, CPU, about two minutes
WARP_FEBIO_TEST_DEVICE=cuda:0 uv run -m unittest discover -s tests -v    # the same on a GPU
WARP_FEBIO_TEST_LEVEL=full uv run -m unittest discover -s tests -v       # full tier, before merging

The tests run on CPU or on a GPU and come in two tiers; CONTRIBUTING has the details, with formatting and the pre-commit hooks.

uv sync creates .venv with the versions recorded in uv.lock. The dev extra installs everything the tests use, including Warp. To use the package, the warp extra (uv sync --extra warp, or pip install -e ".[warp]") installs Warp, which compiling and running a model needs. Without it, pip install -e . installs only the model and the FEBio file readers and writers (warp_febio.model, warp_febio.io), which depend on NumPy alone and can be used inside 3D Slicer.

Python 3.11 or later; 3.12 is the tested version and the one uv selects from .python-version. Warp is pinned to 1.19.0; see the Warp installation guide.

Acknowledgments

FEBio-Warp builds on the formulations, documentation and test suites of FEBio, developed at the University of Utah, and on Warp.

License

FEBio-Warp-Python is released under the Apache License 2.0, the same license as Warp. Contributions are accepted under the same terms.

FEBio is distributed separately under the MIT license. Material in this repository that derives from FEBio, including the reference inputs under references/febio/, keeps its attribution to the FEBio project.

About

Focused port of GPU-accelerated, differentiable biomechanics in warp-python

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages