Derivative of derivative

Sometime I like to solve the variational problem directly by setting up an energy functional energy = H*dx and then solving with a residual

R=derivative(H,u,du)

If I want to get the ‘exact’ Jacobian of then taking

derivative(R,u,du)

leads to

ValueError: Can only create arguments automatically for non-indexed coefficients.

What is the right way to do this? I want to solve a time-dependent problem so it would be good to not build the solver in each time step and calculate this jacobian first. My hope is to let ufl/fenicsx do this all without me calculating the derivative myself.

You need to make a minimal reproducible example.

For documentation, see for instance:
http://jsdokken.com/FEniCS-workshop/src/applications/optimal_control.html#the-forward-problem

That’s a nice resource. It has given me some ideas. I’ll get back to you if my question still makes sense. Thanks for the link… very helpful info there.

ok so that resource was very helpful and it solves my issue. The ordering of my operations has led to nice speedups. Thanks. I guess I’d just delete this question?

You can keep the question as other people might have the same question in the future.