Skip to content

Facet QuadratureElement on TensorProductCell - #274

Open
pbrubeck wants to merge 14 commits into
mainfrom
pbrubeck/tensor-facet-quadrature
Open

pbrubeck wants to merge 14 commits into
mainfrom
pbrubeck/tensor-facet-quadrature

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Aug 4, 2026 •

Copy link
Copy Markdown

Summary

Enable FInAT to evaluate the dual basis of facet quadrature elements on quadrilaterals and hexahedra. A FacetPointSet gathers points from every facet, and those points factor as a tensor product only when grouped by facet direction. For each direction, the normal factor contributes its two endpoints and the tangential factors contribute their quadrature rules.

Quadrilateral         facet points
  x-normal facets     endpoints(x) × quadrature(y)
  y-normal facets     quadrature(x) × endpoints(y)

Dual evaluation concatenates the directional blocks along the facet index in cell facet order and shares the quadrature point indices across blocks. Basis tabulation uses the same blocks for its facet selector, so GEM can split contractions by direction while preserving the element's basis shape and degree-of-freedom ordering.

Each union of point sets is evaluated one constituent rule at a time. Vertex rules use PointSingleton with a scalar weight, and point-set comparisons derive their default tolerance from the coordinate dtype.

count_flops now counts FloorDiv and Remainder as integer index arithmetic. Hexahedral facet orientations emit them, and the counter had no rule for them, so it reported 0 flops for every exterior facet kernel on a hexahedron.

 flops_zeroplus    # 0 + children
   LogicalNot, LogicalAnd, LogicalOr, ListTensor
+  FloorDiv, Remainder

The companion Firedrake PR exercises scalar, vector, and tensor Boundary Quadrature interpolation on quadrilaterals, and facet integrals of Boundary Quadrature coefficients on hexahedra. Firedrake #5323

Evidence

  • Before — Against the base revision, all 10 quadrilateral and hexahedron cases in test_facet_dual_evaluation failed. The quadrilateral case raised NotImplementedError: How to tabulate TensorProductElement on FacetPointSet?. On a hexahedron, u*ds with u in Q2 reported 0 flops.
  • After — All 706 FInAT and GEM tests passed, including the 32 in test/finat/test_quadrature_element.py. The regression checks that dual evaluation reproduces the reference coordinates in basis order at degrees 1–5 and retains tensor-product tabulation on quadrilaterals and hexahedra. On a hexahedron, f*u*ds with f in Boundary Quadrature of degree 2 and u in Q2 reports 772 flops, and the count_flops case for FloorDiv and Remainder in Firedrake's tests/tsfc/test_flop_count.py passes. Source and docstring lint passed.

Merge Danger

Door — Two-way. After the companion Firedrake PR merges, coordinate any revert with that PR.

Blast radius — Quadrature. The change affects facet tabulation, dual evaluation of quadrature elements, point-rule handling in FInAT, and the flop counts TSFC reports for hexahedral facet kernels.

AI assistance from Claude Code and OpenAI Codex.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BiE9EeMXhu6p14ShyaFE3o

@pbrubeck pbrubeck changed the title Dual evaluate a facet quadrature element on a product cell Facet quadrature element on TensorProductCell Aug 4, 2026
@pbrubeck pbrubeck changed the title Facet quadrature element on TensorProductCell Facet QuadratureElement on TensorProductCell Aug 4, 2026
pbrubeck added a commit to firedrakeproject/firedrake that referenced this pull request Aug 4, 2026
Point the existing FIAT install step at pbrubeck/tensor-facet-quadrature,
which is pbrubeck/fix/dual-enriched plus the facet quadrature work.  A
Boundary Quadrature space on a quadrilateral cannot be interpolated into
without it: the dual basis names the points of every facet at once, and a
TensorProductElement cannot tabulate on those.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@pbrubeck

pbrubeck commented Aug 4, 2026

Copy link
Copy Markdown
Author

Paired firedrake PR: firedrakeproject/firedrake#5323 — firedrakeproject/firedrake#5323

It carries the tsfc zero propagation this needs to reach codegen, the regression tests for quadrilaterals, and a DROP BEFORE MERGE commit pinning CI to this branch.

Comment thread finat/quadrature_element.py Outdated
# Avoid circular import dependency
from finat.tensor_product import TensorProductElement

product = getattr(self.cell, "product", None)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugly getattr go away! Use isinstance(self.cell, FlattenedDimensions)

@rckirby rckirby left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have top-level tests of correctness?

Comment thread finat/point_set.py Outdated
"""GEM expression describing the points, with free indices
``self.indices`` and shape (point dimension,)."""

def almost_equal(self, other, tolerance=1e-12):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to read the default tolerance from some underlying data type to facilitate single precision in the future?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that would be good. Currently we put a dtype on ref_el.vertices precisely becuase we only use tolerances for point inclusions/comparisons

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread test/finat/test_quadrature_element.py Outdated


@pytest.mark.parametrize("cellname", ["quadrilateral", "hexahedron"])
@pytest.mark.parametrize("degree", [1, 2, 3, 5])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not 4?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@pbrubeck
pbrubeck force-pushed the pbrubeck/fix/dual-enriched branch from cf129c7 to 7eacfd1 Compare August 18, 2026 10:03
@pbrubeck
pbrubeck force-pushed the pbrubeck/tensor-facet-quadrature branch from 47c5baf to 975634c Compare August 18, 2026 10:03
@pbrubeck
pbrubeck force-pushed the pbrubeck/fix/dual-enriched branch from 7eacfd1 to 20379ad Compare August 19, 2026 14:11
@pbrubeck
pbrubeck force-pushed the pbrubeck/tensor-facet-quadrature branch 2 times, most recently from 7167c73 to a14c69c Compare August 24, 2026 21:15
@pbrubeck
pbrubeck force-pushed the pbrubeck/fix/dual-enriched branch 2 times, most recently from a62a980 to d630222 Compare August 26, 2026 11:11
@pbrubeck
pbrubeck force-pushed the pbrubeck/tensor-facet-quadrature branch 2 times, most recently from 121951c to a099322 Compare August 26, 2026 11:57
@pbrubeck
pbrubeck force-pushed the pbrubeck/fix/dual-enriched branch 2 times, most recently from 215aa47 to 050579b Compare August 26, 2026 15:19
Base automatically changed from pbrubeck/fix/dual-enriched to main September 10, 2026 11:29
@pbrubeck
pbrubeck removed this pull request from stack #272 September 10, 2026 12:02
@pbrubeck
pbrubeck force-pushed the pbrubeck/tensor-facet-quadrature branch from 2e45b9e to 869959e Compare September 23, 2026 00:30
Comment thread test/finat/test_quadrature_element.py Resolved
Comment thread finat/point_set.py Resolved
Comment thread finat/quadrature.py Resolved
Comment thread finat/quadrature_element.py Resolved
Comment thread test/finat/test_quadrature_element.py Resolved
Comment thread test/finat/test_quadrature_element.py Resolved
Assisted-by: OpenAI Codex
Concatenate the facet directions along the facet index and share the point indices across directions. The dual evaluation and tabulation then use the same basis shape.

AI-assisted-by: OpenAI Codex
Use the same directional blocks for the facet selector and the dual evaluation so GEM can split their contraction. Keep flat tabulation for rules that do not factor by direction.

AI-assisted-by: OpenAI Codex
@pbrubeck pbrubeck added the LLM used An LLM was used in the production of this PR label Nov 23, 2026
pbrubeck and others added 8 commits November 23, 2026 11:30
Build directional facet point sets directly and preserve the facet basis axis. Cancel facet selectors before splitting concatenated contractions, and use EnrichedElement to evaluate cell quadrature unions.

AI-assisted-by: OpenAI Codex
Index a Concatenate with a literal in Indexed, next to the ListTensor rule,
and keep only the runtime index lowering to Piecewise in replace_indices.
Use delta_elimination to cancel the concatenation index in split_contraction.

Treat any UnionPointSet rule as a direct sum, so a single summand goes
through EnrichedElement instead of a special case in dual evaluation.

Derive the facet blocks of a hypercube from its unflattening map and entity
transforms, and make them public as FacetPointSet.tensor_product_blocks.

Test the runtime facet lookup that interpolation in a facet integral needs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a FacetPointSet, tabulate on each facet and stack the tabulations
with a Concatenate on the facet index, for every cell.  Tensor product
elements stack factor by factor, keeping the product structure on each
facet.  The points are stacked the same way, so the facet index enters
only through Concatenate nodes.

The dual evaluation of a facet QuadratureElement then identifies the
facet index of the points with the facet index of the basis, and
contracts only the points within a facet with the dual basis.
unconcatenate splits the facet index off before argument factorisation,
so no delta between the facet index and the basis is left to cancel.

A runtime lookup of constant per-facet tables folds into a single
Literal lookup in select_expression.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When unconcatenate splits a return variable along the facet index, a
coefficient contraction that was sum factorised over the stacked
Concatenate tables is contracted again for each block, so each facet
gets its own contraction order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stack the tabulations of a union, of a facet point set, and of each
tensor product factor on a facet with one stack_tabulations function,
and tabulate the factors of a tensor product element on an entity in
one place.

Fold the runtime indexing of a Concatenate into the general branch of
replace_indices, index its entries through Indexed, and merge the
selection of tables on matching and on different indices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiE9EeMXhu6p14ShyaFE3o
FloorDiv and Remainder decode facet orientations into quadrature point
indices. count_flops had no rule for them and returned 0 for the whole
kernel, so every exterior facet kernel on a hexahedron reported 0 flops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiE9EeMXhu6p14ShyaFE3o
Literals with equal entries and different dtypes compared equal and had equal hashes.
A memoized pass could then replace an integer table with a floating point table that has the same entries.
An array index that uses such a table is not integral, and loopy rejects it.

Negation multiplies by a -1 that has the dtype of the operand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep each facet's tensor product visible to contraction and eliminate indexed unit vectors as Kronecker deltas. Preserve real deltas under conjugation for adjoint interpolation.

AI assistance: OpenAI Codex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLM used An LLM was used in the production of this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants