Question on ufl.diff()

Hi,

I need to implement the UFL equivalent of

\frac{\partial \Psi(C)}{\partial C}\Big\rvert_{C_{n+\frac{1}{2}}}

as part of a variational formulation (hyperelasticity, one might guess ;)).
\Psi(C) is a nonlinear function of a UFL tensor C=C(u) and u an actual FEniCS vector function.
The index corresponds to time discretization, C_{n+\frac{1}{2}} = \frac{1}{2}(C_{n+1} + C_n), with C_{n+1} = C(u_{n+1}) and C_n=C(u_n).

Is this correctly implemented by

C = 0.5*(C0 + C1)
C = variable(C)
Psi = some_function(C)
DPsi =  diff(Psi, C)

? I.e., will diff() compute the derivative of Psi wrt C, and evaluate in C = 0.5*(C0 + C1)?

I don’t see what else these lines could be doing, but I am not really sure. Thank you for clearing up my confusion :slight_smile:

That sounds like the correct interpretation to me.

1 Like

Thanks for the feedback!