Repository navigation
Chordae elements: rest length on the device, chord force on a node set, smooth tension-only spring - #8
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
wirediscrete entries refused, truss density reported by analysis type,nodal_loaddefault scaleWhere 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/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).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 ate4df3f8built bytools/build_febio.sh(no MKL). Existing referencesch_spring_chords,ch_truss_chordsand suite problemsbt01,di01,di02as before.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
uvx pre-commit run --all-filespasses. (Ruff check and format were run on every commit; the other hooks were not run separately.)WARP_FEBIO_TEST_LEVEL=full uv run -m unittest discover -s tests, and withWARP_FEBIO_TEST_DEVICE=cuda:0for code that runs on the device.git commit -s).🤖 Generated with Claude Code