This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to compute residual of adjoint functional with dolfin-adjoint?

+1 vote

There is a function which computes solution of adjoint problem: http://www.dolfin-adjoint.org/en/latest/documentation/api.html#dolfin_adjoint.compute_adjoint

J = Functional(inner(u, u)*dx*dt[FINISH_TIME])
for (variable, solution) in compute_adjoint(J):

But I need not only solution, but also its residual. So, I need adjoint equations. I thought it should be somewhere in adjointer class, but I grepped the source code and it seems there is no way to get it. I think I'm missing something, because how could dolfin adjoint find solution without forming the equations first? Or is those steps are hidden inside C library libadjoint?


asked Apr 9, 2017 by gtt FEniCS Novice (630 points)

Why the residual? The adjoint equation is linear and it is solved exactly by dolfin-adjoint. The residual should be zero.

1) Depending on condition number of system residual may not be close to zero, but you have a point.
2) Assuming I have non-linear equation, will residual of adjoint equation still be zero?

The adjoint equation is always linear. Yes, if you use an iterative solver and decide to stop it with a high tolerance, the residual will not be zero. This could be useful in early iterations of an optimization when you don't need the gradient to be very accurate. What's your equation and what are you trying to do?

I'm trying to implement error analysis from http://www.dolfin-adjoint.org/en/latest/documentation/maths/5-applications.html

Also, I'm struggling with something which is like very simple task: I want to compute gradient of reduced functional J_hat by lib-adjoint to implement certain optimization method manually:
dJdm = J_hat.derivative()
a = a + dJdm
but dolfin says "a" and "dJdm" are of different types.

...