Skip to content

tsfc: cancel Jacobian products and reciprocal factors#5230

Draft
pbrubeck wants to merge 5 commits into
mainfrom
pbrubeck/cancel-jacobian
Draft

tsfc: cancel Jacobian products and reciprocal factors#5230
pbrubeck wants to merge 5 commits into
mainfrom
pbrubeck/cancel-jacobian

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

Companion PRs (required):

Piola-mapped elements generate expressions of the form J * inv(J) that were not simplified, because JacobianInverse was expanded into individual matrix entries too early in form preprocessing. This PR enables the new UFL pipeline that preserves the Jacobian quantities as terminals, cancels IndexSum(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: enable do_cancel_jacobian_products in compute_form_data, and apply the same simplifications in preprocess_expression (interpolation and point evaluation paths).
  • tsfc/spectral.py: cancel reciprocal factors after replace_division.
  • tsfc/driver.py: cancel reciprocal factors in dual evaluation, where the Piola pullback's detJ**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:

baseline this PR change
2D flops 27020 18728 -31%
2D compile time 0.52 s 0.36 s -31%
2D kernel size 47 kB 29 kB -38%
3D flops 763527 444574 -42%
3D compile time 3.62 s 1.81 s -51%
3D kernel size 323 kB 143 kB -56%

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

pbrubeck and others added 2 commits July 10, 2026 00:16
- 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>
Comment thread .github/actions/install/action.yml
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