Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving pre-assembled linear system: adjoint not working #2835

Open
nbouziani opened this issue Mar 19, 2023 · 0 comments
Open

Solving pre-assembled linear system: adjoint not working #2835

nbouziani opened this issue Mar 19, 2023 · 0 comments

Comments

@nbouziani
Copy link
Contributor

Despite having a dedicated block and annotation mechanism, it seems that solving a pre-assembled linear system (i.e. via solve(A, x, b)) is not adjoint compatible. The corresponding block seems wrong, e.g it assumes the rhs is not a ufl.Coefficient (cf. here). Also, the pyadjoint core block class for solve (i.e. GenericSolveBlock), which is currently used to compute the adjoint/tlm of solving pre-assembled systems, is not equipped for that case.

I think this has been going off the radar because there are no tests hitting that implementation.

Example:

from firedrake import *
from firedrake_adjoint import *

mesh = IntervalMesh(10, 0, 1)
V = FunctionSpace(mesh, "Lagrange", 1)

f = Function(V)
f.vector()[:] = 1

u = TrialFunction(V)
v = TestFunction(V)
bc = DirichletBC(V, Constant(1), "on_boundary")

a = inner(grad(u), grad(v))*dx
A = assemble(a, bcs=bc)

L = f * v * dx
b = assemble(L)

u_ = Function(V)
# This doesn't work (relies on `SolveLinearSystemBlock`)
solve(A, u_, b)
# This works (relies on `SolveVarFormBlock`)
# solve(a == L, u_, bcs=bc)

J = assemble(u_**2*dx)
Jhat = ReducedFunctional(J, Control(f))
Jhat.derivative()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant