I don’t think I understand what
derivative does in fenics and am hoping to clear this up with the following simple problem.
I have a form
J in terms of a regular (as in not a trial or test function) function
alpha that I am trying to take the derivative of, but for some reason this derivative is incorrect.
from fenics import * mesh = UnitSquareMesh(16,16) K = FunctionSpace(mesh,"DG",0) alpha = Function(K) alpha.interpolate(Constant(1)) J = inner(alpha,alpha)*dx dJ = Function(K,assemble(derivative(J, alpha))) dJtrue = 2*alpha print(assemble(inner(dJ,dJ)*dx)) print(assemble(inner(dJtrue,dJtrue)*dx))
When running the above test code I would expect to get twice
4, as the derivative of
2*alpha, however I get
1.5e-5 instead for the first output.
edit: the exact output is: