I have defined a Function
U
and an Expression
V
as follows:
import fenics as fe
nelements = 8
degree = 2
m = fe.UnitIntervalMesh(nelements)
DE = fe.FiniteElement('DG', m.ufl_cell(), degree)
DS = fe.FunctionSpace(m, DE)
U = fe.Function(DS)
wU = fe.TestFunction(DS)
Vstr = '-beta*log(alpha + U)'
V = fe.Expression(Vstr, degree = degree, alpha=1, beta=1, U=U)
This works exactly as I hoped it would. V
depends on U
. For instance, if I do this:
U.vector()[1] = 1
then plot V
, I find it has changed. Also,
dxx = fe.Measure('dx', m)
fe.assemble(V*dxx)
gives the entirely plausible result -0.014440566261665524
.
Now I want to compute the derivative of the integral of V
with respect to the degrees of freedom of U
. So, with consummate naivete, I tried this:
fe.derivative(V*dxx, U)
dV = fe.assemble(fe.derivative(V*dxx, U))
dV.array()
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
It sort of works, in that I, now getting a vector result, but this is not the answer I was hoping for... Is there a way to get the differentiation to propagate through the Expression
?