Skip to content

Chordae elements: rest length on the device, chord force on a node set, smooth tension-only spring - #8

Merged
mattjolley merged 9 commits into
mainfrom
mattjolley/chordae-elements
Nov 28, 2026
Merged

mattjolley merged 9 commits into
mainfrom
mattjolley/chordae-elements

Conversation

@mattjolley

Copy link
Copy Markdown
Contributor

What does this change, and why?

Refines the two-node truss and spring elements used for chordae, after a first run on a GPU and a review of the code against the FEBio source at e4df3f8. Design note: docs/design/chordae.md.

This is the first of three pull requests that are merged in order (elements; then dynamics, loads and solvers; then a first contact template). Each is merged by the author so the work can continue, and is left here as the record for review afterwards: comments on a merged pull request are welcome and will be acted on. Nothing in it is settled; open questions are in the decision points of the design note.

Commit What
Elements: rest length on the device, and four details brought in line with FEBio A CUDA fault: the rest length came from NumPy on the host and the current length from the kernel, which differ in the last bit on CUDA, so about one undeformed tension-only truss or spring in twenty started slack. It is now computed on the device with the kernel's arithmetic, as FEBio computes both lengths with one code path. Plus four details from the review: truss mass with FEBio's length, wire discrete entries refused, truss density reported by analysis type, nodal_load default scale
Chordae: the chord force on a node set, and a smooth tension-only spring Two additions FEBio does not have, marked as such: the resultant chord force on a set of nodes (a papillary tip) as an output and an objective, and a tension-only spring with a rounded corner for optimization (decision C9)
Verification: a FEBio reference for the static patch on spring chords FEBio 4.13.0 run on the 1863-shell patch with four chord springs; agreement to 5e-8
Docs: chordae note The note updated for all of the above

Where this differs from FEBio, and why. The additions are a rest length held as a parameter array (default: FEBio's value), the axial force of a truss as an output, the chord force on a node set, and the smooth tension-only spring. Each is labeled in the code, and an input that uses the non-FEBio material is marked in the coverage report. The full list, with the reason for each and how to get FEBio's behavior back where that applies, is collected in docs/design/deviations.md, which arrives with the next pull request.

Validation

  • Tests added or changed: tests/test_chordae_elements.py (reference state on the device, chord force on a node set against FEBio's logged spring forces and reactions, its gradient through the solve, the smooth spring), tests/test_line_element_details.py (the four review details).
  • FEBio reference (input file, quantity compared, tolerance, FEBio version), or N/A: references/febio/originals/patchwarp/four_chords_static_prepared/patch_four_chords_static_original.feb, final displacement and spring forces from the plot file, 5e-7 (single precision), FEBio 4.13.0 at e4df3f8 built by tools/build_febio.sh (no MKL). Existing references ch_spring_chords, ch_truss_chords and suite problems bt01, di01, di02 as before.
  • Devices the full tier ran on (CPU, and the GPU model if CUDA; say so clearly if no GPU was used): CPU with CUDA hidden (at the tip of the three-branch stack, 229 tests) and a Quadro RTX 8000 (cuda:0) at the tip of this branch (188 tests) and of the stack. Every commit passes lint and the quick tier on CPU on its own.

Checklist

  • I have read the contributing guide.
  • uvx pre-commit run --all-files passes. (Ruff check and format were run on every commit; the other hooks were not run separately.)
  • The full tier passes: WARP_FEBIO_TEST_LEVEL=full uv run -m unittest discover -s tests, and with WARP_FEBIO_TEST_DEVICE=cuda:0 for code that runs on the device.
  • If this changes what a design note says, the note is updated; open design questions are in its decision points, not only in this pull request.
  • The change is focused, and every commit is signed off (git commit -s).

🤖 Generated with Claude Code

mattjolley and others added 9 commits November 27, 2026 22:34
The FEBio test suite truss and spring problems are loaded this way.
The scale is a device array with one value per node, so a force per
node carries a gradient.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018s5xwCYXZt43rEVLGM8CYt
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
TrussDomain (FEBio linear-truss) and DiscreteDomain (FEBio discrete) as
terms of the static run path, sharing the force and stiffness kernels
of a two-node axial element. Truss laws: FEBio's linear truss, and a
tension-only linear truss that is not a FEBio material. Spring laws:
linear spring, tension-only linear spring, nonlinear spring. Rest
length, area and material rows are differentiable arrays; spring
parameters and results are keyed by FEBio's discrete set names.

Also: shells may share nodes with trusses and springs (FEBio ties
shells to solid domains only), and point stress in the results is
copied per state, since on the CPU it aliased the device array.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018s5xwCYXZt43rEVLGM8CYt
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
Three small inputs with FEBio 4.13.0 references (a block on truss
chords, a block on springs of three types, a quad4 patch on truss
chords), tests against FEBio, against the FEBio test suite's stored
values for bt01, di01 and di02, and adjoint gradients of chord tension
against central differences. tools/time_springs.py times the spring
kernels on a device.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018s5xwCYXZt43rEVLGM8CYt
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
A small inverse problem with adjoint gradients, with FEBio FINESSE in
view. Kept in its own commit so it can be dropped.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018s5xwCYXZt43rEVLGM8CYt
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
The note records the design of the truss and spring elements, what was
checked against FEBio on CPU and on a GPU, and decision points C1 to
C10.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018s5xwCYXZt43rEVLGM8CYt
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
… with FEBio

Rest length on the device. The default rest length of trusses and
springs came from NumPy on the host, and the current length from the
update kernel on the device. On CUDA the two differ in the last bit for
about one element in nine, so about one undeformed tension-only truss
or spring in twenty started slack, with no stiffness in the first
iteration; on CPU they agreed. The rest length now comes from a kernel
with the arithmetic of the update kernels (line2.geometric_length), as
FEBio computes both lengths with one code path. ReferenceStateTests
checks 20,000 random elements of each kind on the test device.

Four details found in a review of the truss, spring and nodal load
code against the FEBio source at e4df3f8:
- The consistent mass of a truss uses the geometric length (FEBio's
  m_L0), not the rest length parameter, so changing a chord's rest
  length does not change its mass.
- A <discrete> entry of type "wire" is a deformable spring domain in
  FEBio, not a spring. It, and settings inside <discrete>, are refused
  by the coverage report instead of being run as springs.
- The density of a truss material is reported as used in a dynamic
  analysis, and as having no effect only in a static one.
- nodal_load without a scale has FEBio's default of zero
  (FENodalDOFLoad), where it failed before.
Each has a small test in tests/test_line_element_details.py.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
Two additions FEBio does not have, both marked as such in the code.

The chord force on a node set. force_on(state, weight) returns the
resultant force the elements of a line domain exert on a set of nodes:
the chord force on a papillary tip, as a vector and as an objective on
a tape. One kernel over the elements (sum_force_on_entries), shared by
the truss and the discrete domain through a small mixin
(line2.AxialOutputs). It is the sum FEBio's "discrete element force"
gives over the springs at those nodes: on ch_spring_chords it equals
that sum from FEBio's logged spring forces to 1e-10 and, along the
pull, balances FEBio's logged reactions to 1e-8. Its gradient through
the solve matches central differences for all 14 spring parameters.

"smooth tension-only linear spring". FEBio's tension-only linear
spring with the corner rounded over a band of width smoothing_length
around the slack length: zero below, a quadratic inside the band, the
straight line above. Force and stiffness are continuous, the tangent
is exact, and the kernel has no data-dependent branch. Its names,
parameters, measure and the branch at the slack length follow
FETensionOnlyLinearSpring; it equals that law outside the band and for
a width of zero; and the coverage report marks an input that uses it
as FEBio-Warp only. It is for optimization: at the slack length its
gradient with respect to the slack length equals the central
difference (-E/2), where FEBio's law gives -E from reverse mode. Inside
the band the force differs from FEBio's by at most E w / 4 (decision
C9). chord_curve_closed_form gives E and the slack length of a
three-point chord curve, so the chord sets of a valve input can be
given to it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
The static four-chord patch (1863 quad4 shells under pressure, four
"nonlinear spring" chords) was run in FEBio 4.13.0 at e4df3f8, built
on the GPU workstation by tools/build_febio.sh. febio_final_state.json
holds the final displacement and spring forces from the plot file,
with the SHA-256 of the input. FEBio-Warp agrees to 5e-8 of the
largest displacement and to seven digits in the spring forces.

The test is in the full tier and on a GPU only: with the solvers there
are at this commit the patch takes about 20 s with conjugate gradients
on a GPU and over 25 minutes on CPU.

tools/build_febio.sh takes FEBIO_STATIC_STDLIBS=OFF for machines
without the static C++ runtime.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
docs/design/chordae.md records: the rest length computed on the device
and why (one tension-only element in twenty started slack on CUDA);
the chord force on a node set; the smooth tension-only spring and its
relation to FEBio (decision C9); the truss mass with FEBio's length;
and suite problem dy16 passing once dynamics exists.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
@mattjolley
mattjolley merged commit 170ec2a into main Nov 28, 2026
2 checks passed
@mattjolley
mattjolley deleted the mattjolley/chordae-elements branch November 28, 2026 15:27
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