Skip to content

About

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

Resources

Contributing

Stars

1 star

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, and differ where another form suits a GPU and gradients better. 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, and an open mitral valve model runs through closure. Interfaces will change.

Try it

uv sync --extra dev                                                        # environment with Warp
uv run -m febio_warp inspect references/single_element/hex8_pressure.feb   # what the input needs, and whether it can run
uv run -m febio_warp 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; for runs on a GPU, install the gpu extra as well (uv sync --extra dev --extra gpu), which brings NVIDIA cuDSS, the linear solver on the device. Install has the details.

An existing FEBio input is run as FEBio would run it. The settings that suit FEBio-Warp where they are not FEBio's (a smooth contact potential, which is another contact model, and the exact material tangent) are a preset of the run, --preset febio_warp, and FEBio's value in every area is --preset febio, which the defaults are. --preset febio_4_13 has the tangents of mass damping and of the slide-line as FEBio 4.13.0 has them (FEBio corrected both on December 1, 2026), for comparing iteration counts with that version. run prints the settings in use before it starts, and says so in a line of its own when the contact model is not FEBio's; 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, constraints"]:::todo
        rigid["Rigid bodies under load,<br/>joints, tied 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"]:::done
    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. What is still open, and who is asked, is on one page: 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, Ogden, Fung orthotropic, Mooney-Rivlin and Veronda-Westmann (each of the last five coupled, and in its uncoupled form on the three-field solid), uncoupled Arruda-Boyce and Yeoh, fibers (fiber-exp-pow, fiber-pow-linear, coupled and uncoupled), transversely isotropic Mooney-Rivlin (coupled and uncoupled), with material axes on the material or per element (ElementData of type mat_axis), a fiber as a vector, by angles or per element, solid mixtures (coupled and uncoupled, with the mixture's own axes), and prestrain around any of them (prestrain elastic and its uncoupled form; a prestrain gradient, constant or per element, or an in-situ stretch along the fiber; FEBio's two prestrain constraints, which correct it until the mesh as given is in equilibrium); history at the integration points of hex8, penta6 and shell parts, with FEBio's viscoelastic as the first material on it; spring and linear truss laws, and an Ogden truss law for chordae (not in FEBio); 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; a mixture's axes per element; fiber distributions; uncoupled viscoelasticity Materials (diagram, decisions), prestrain constraints (diagram)
Contact contact/ FEBio's contact potential, on its own and in a run: pair search on the device, force, tangent, gradients. FEBio's form by default, and a smooth form that the contact type smooth contact potential (FEBio-Warp only) or a run (--preset febio_warp) asks for. FEBio's edge-to-surface contact potential (an edge against a surface). Smooth contact measures for objectives. Count of intersecting facet pairs. FEBio's sliding-elastic with tension against a fixed rigid target (shape enforcement), and in its penalty form between two deformable bodies (two passes, auto_penalty, friction with stick and slip). FEBio's sticky in its penalty form, with snap_tol and release by max_traction, with its primary on a deformable body or on a rigid body the input moves (a clip arm on a leaflet). FEBio's tied-elastic in its penalty form (two surfaces held at the separation they start with). FEBio's tied-node-on-facet in its penalty form, with max_distance, special and offset_shells; it and sticky are two settings of one anchored-point term 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 in augmented Lagrangian form, and their gradients; node_reloc of the tied interface; tied-elastic; sliding-elastic between two deformable bodies; sliding contact with friction; a contact potential against a moving rigid body compared with FEBio; 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, penta6 and tet4 solids on dedicated kernels (hex8 and tet4 also through warp.fem, as a cross-check); FEBio's three-field solid on hex8 and penta6 for uncoupled materials, in its penalty form; quad4 and tri3 shells; two-node trusses (regular, tension-only and smooth tension-only); springs; FEBio's beam (linear-beam, line2 and line3, static and dynamic). Mass for hex8, tet4 (FEBio's one-point rule), quad4 shell and truss rigid bodies with unknowns; the augmented Lagrangian of the three-field solid 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); 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; normal displacement on a surface, with relative; prescribed deformation of a node set; the slide-line constraint; the linear constraint set and node distance of the Constraints section, by penalty or augmented Lagrangian, also declared in a step; a rigid body that is fixed or moved by the input (rigid_fixed, rigid_displacement, rigid_rotation, a revolute joint with a prescribed rotation), as geometry; a rigid body with open components, solved for as FEBio does, static and dynamic (two entries per body, its nodes eliminated; mass and inertia; rigid_force and rigid_moment with LOAD; a body force on a rigid part; nodes tied by rigid); the rigid wall (rigid_wall, a plane) in its penalty form A body force that varies in space; for rigid bodies with open components: initial velocities, static and dynamic steps in one run, alpha_f below 1, the other load types, connectors under load, clamped shell nodes; the rigid wall with augmented Lagrangian; the linear constraint boundary condition (by elimination); Lagrange multipliers as unknowns (LAGMULT) Dynamics, constraints (diagram)
Solvers solvers/ The Newton strategy the input asks for, as FEBio runs it (BFGS, Broyden, full or modified Newton), with FEBio's line search; a material's tangent_scale applied where the input states it; full Newton whatever the input asks and the exact material tangent as options; CG, BiCGSTAB and GMRES on the device; sparse LU on the host; cuDSS on the device (the gpu extra; the default on a GPU), 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 with FEBio's automatic time stepper, for every alpha_f FEBio's rhoi and alpha give (below 1: domains at the interpolated configuration, and at 1/2 FEBio's energy-conserving stress). Several steps in sequence, as FEBio runs them, a static step after a dynamic one included: 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 Rigid and initial conditions by step; gradients through a step at alpha_f = 1/2 or through a static step after a dynamic one 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, across the boundary between analysis steps and through the history of a material; forward sensitivities of every displacement to chosen parameter directions, with the right-hand sides of all directions solved together, also through 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.
  • Open questions and decisions: what is open and who is asked (the FEBio, cuDSS and nvmath-python, and Warp teams), kept current with the code.
  • Ahead of FEBio: what runs here and is not in FEBio, and how each addition is kept equivalent to FEBio.
  • 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.
  • 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/febio_warp/ 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                                                      # CPU; add --extra gpu on a machine with a GPU
uv run -m unittest discover -s tests -v                                  # quick tier, CPU, about two minutes
FEBIO_WARP_TEST_DEVICE=cuda:0 uv run -m unittest discover -s tests -v    # the same on a GPU
FEBIO_WARP_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 on the CPU, including Warp. There are three ways to install the package:

Install What it brings For
pip install -e . NumPy only The model and the FEBio file readers and writers (febio_warp.model, febio_warp.io), also inside 3D Slicer
pip install -e ".[warp]", uv sync --extra warp Warp and SciPy Compiling and running a model on the CPU
pip install -e ".[gpu]", uv sync --extra gpu The same, and NVIDIA cuDSS through nvmath-python and CuPy (about 4 GB of CUDA 12 libraries; Linux and Windows) Running a model on a GPU
pip install -e ".[gpu-cu13]", uv sync --extra gpu-cu13 As gpu, with the CUDA 13 libraries (NVIDIA driver 580 or later) The same, where CUDA 13 is wanted; one of the two per environment

The default linear solver of a run ("auto") is the direct solve that suits the device: cuDSS on a GPU, SciPy's sparse LU on the CPU. On a GPU without a gpu extra a run still works, solves on one CPU core, and warns that it does: a valve model that takes 2.5 minutes with cuDSS took 18 without. run prints the solver it chose. A solver asked for by name is never replaced, and a run never solves with a dense matrix: if the solver's package is not installed, the run stops at its start with an error that says what to install.

Python 3.11 or later; 3.12 is the tested version and the one uv selects from .python-version. Warp is pinned to 1.20.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

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages