tsfc: cancel Jacobian products and reciprocal factors#5230
Draft
pbrubeck wants to merge 5 commits into
Draft
Conversation
- Enable do_cancel_jacobian_products in compute_form_data, so that contractions of the Jacobian with its inverse are cancelled before the inverse is expanded into individual matrix entries, and apply the same simplifications in preprocess_expression. - Cancel reciprocal factors, such as detJ**2 * (1 / detJ)**2, in spectral mode and in dual evaluation. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
pbrubeck
commented
Jul 10, 2026
…t/firedrake into pbrubeck/cancel-jacobian
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.
Description
Companion PRs (required):
Piola-mapped elements generate expressions of the form
J * inv(J)that were not simplified, becauseJacobianInversewas expanded into individual matrix entries too early in form preprocessing. This PR enables the new UFL pipeline that preserves the Jacobian quantities as terminals, cancelsIndexSum(J[a,k] * K[k,b] * factors, k) -> factors * delta_ab, eliminates the resulting Kronecker deltas, and cancels reciprocal determinant powers, before lowering geometry as usual:tsfc/ufl_utils.py: enabledo_cancel_jacobian_productsincompute_form_data, and apply the same simplifications inpreprocess_expression(interpolation and point evaluation paths).tsfc/spectral.py: cancel reciprocal factors afterreplace_division.tsfc/driver.py: cancel reciprocal factors in dual evaluation, where the Piola pullback'sdetJ**2(from UFL) meets the inverse basis transformation's(1/detJ)**2(from FInAT); previously this product multiplied every term of the kernel.Benchmark
Johnson-Mercier
inner(u, v)*dx + inner(div(u), div(v))*dx, spectral mode, cold cache:On affine cells the div-div integrand now reaches TSFC as
(1/detJ**2) J : rdiv(sigma), with all second-derivative geometry terms folded at the UFL level. Assembled JM matrices agree with the unoptimised pipeline to machine precision on perturbed simplices in 2D and 3D.🤖 Generated with Claude Code