FEniCS / ufl

UFL - Unified Form Language
https://fenicsproject.org
GNU Lesser General Public License v3.0
97 stars 64 forks source link

Error when using a coefficient derivative map of a vector coefficient w.r.t. a scalar #123

Closed cianwilson closed 1 year ago

cianwilson commented 1 year ago

Taking the derivative of a form containing a vector coefficient w.r.t. a scalar coefficient and supplying a coefficient derivative map results in an error, e.g.:

test.py:

from ufl import (triangle, FiniteElement, VectorElement, TestFunction, Coefficient, inner, dx, derivative)

V = FiniteElement("Lagrange", triangle, 1)
VV = VectorElement("Lagrange", triangle, 1)

dv = TestFunction(V)

df = Coefficient(VV)
g = Coefficient(VV)
f = Coefficient(VV)
u = Coefficient(V)
cd = {f: df}

integrand = inner(f, g)

F = integrand*dx
J = derivative(F, u, dv, cd)

forms = [F, J]

ffcx test.py results in:

ufl.log.UFLException: Component and shape length don't match.

I have a fix that's working for my usage case that I'll put in a PR for comment.