Repository navigation
Description
Describe the bug
Symbolic interpolate(v, T) where v is a TestFunction or TrialFunction on a VectorFunctionSpace of a physically mapped element (Hermite, Reduced-Hermite, Morley, Argyris, Bell) fails to compile in the default "spectral" mode with gem.refactorise.FactorisationError. The same form compiles and assembles with form_compiler_parameters={"mode": "vanilla"}.
The failure does not depend on the target space (vector/tensor CG1, DG1, N1curl, Bernardi-Raugel and Rotated-Bernardi-Raugel all fail) or on whether a gradient is taken first. It does not occur for scalar spaces of the same elements, for vector spaces of non-mapped elements (e.g. vector CG2), or for forms that use the vector-valued Argument directly without interpolate (e.g. inner(grad(u), grad(v))*dx).
The node rejected by _collect_monomials (gem/refactorise.py:206) is an Indexed(ListTensor([...]), (Index(...),)) whose entries contain Delta(Index, 0) factors, i.e. an argument-dependent ListTensor indexed by a free index, which the argument factorisation cannot split.
This came up while testing #5688 (with firedrakeproject/fiat#316 and FEniCS/ufl#571) on a discrete Kirchhoff triangle formulation: w in VectorFunctionSpace(mesh, "Reduced-Hermite", 3, dim=3), discrete gradient interpolate(grad(w), VectorFunctionSpace(mesh, "Rotated-Bernardi-Raugel", 1, dim=3)). #5688 fixes the coordinate-mapping assertion for the vector Rotated-Bernardi-Raugel target, after which every residual and Jacobian term containing a test or trial function hits this error. It is not a regression from #5688: the minimal example below also fails on the commits #5688 is based on (firedrake 350cd70, fiat 91b20b48, ufl f4183ef2).
Steps to Reproduce
from firedrake import *
mesh = UnitSquareMesh(2, 2)
V = VectorFunctionSpace(mesh, "Hermite", 3) # also Morley, Argyris, Bell, Reduced-Hermite
T = VectorFunctionSpace(mesh, "CG", 1) # any target space fails the same way
v = TestFunction(V)
L = inner(interpolate(v, T), Constant((1, 0))) * dx
assemble(L, form_compiler_parameters={"mode": "vanilla"})
print("vanilla: OK")
assemble(L) # default "spectral" mode
print("spectral: OK")Run with python bug3_vector_zany_argument_interpolate.py.
Expected behavior
The form assembles in spectral mode, as it does in vanilla mode and as the scalar-valued equivalent does.
Error message
vanilla: OK
Traceback (most recent call last):
File "bug3_vector_zany_argument_interpolate.py", line 13, in <module>
assemble(L) # default "spectral" mode
...
File ".../tsfc/kernel_interface/common.py", line 319, in compile_gem
assignments.extend(mode.flatten(var_reps.items(), ctx['index_cache']))
File ".../tsfc/spectral.py", line 96, in flatten
monomial_sums = collect_monomials(expressions, classifier)
File ".../gem/refactorise.py", line 344, in collect_monomials
return list(map(mapper, expressions))
File ".../gem/refactorise.py", line 208, in _collect_monomials
sums.append(MonomialSum.sum(*map(self, summands)))
File ".../gem/refactorise.py", line 206, in _collect_monomials
raise FactorisationError(expr)
gem.refactorise.FactorisationError: Indexed(ListTensor([Product(Delta(Index(58), 0, None), Literal(array(0.33333333), ...
The full message is a very long GEM expression; complete log attached (bug3_vector_zany_argument_interpolate.log).
Environment:
- OS: Linux (Pop!_OS 24.04, x86_64)
- Python version: 3.12.3
- firedrake: Fix interpolation into wrapped physically mapped elements #5688 fix commits (0ec6399, 7a02124) cherry-picked onto main @ 350cd70, since the Fix interpolation into wrapped physically mapped elements #5688 branch itself needs PETSc main
- fenics-ufl: Report base form operator spaces and elements by rank FEniCS/ufl#571 @ 26e7b0226f978e9e84092e09e5300373e8fb03a0
- firedrake-fiat: Propagate coordinate mapping through FInAT wrappers fiat#316 @ a41def8972faa87087b346eeb395e7e03408f1e6
- PETSc / petsc4py 3.26.0
- Also reproduced on firedrake 350cd70, firedrake-fiat 91b20b48, fenics-ufl f4183ef2 (before the three PRs).
Additional Info
Workaround: form_compiler_parameters={"mode": "vanilla"} in assemble/solve. Related: #5686, #5687, #5688.
Activity