EquationBC
doesn't seem to work in adjoint optimization problems
#2774
-
Hello everybody, First of all, thanks for the work and effort you put into this framework. Especially the adjoint feature feels almost like a magical piece of technology and I have very much enjoyed solving PDEs with it. I'm working on a topological optimization problem that under the hood uses the Below is a toy Poisson problem that works fine in "pure" Firedrake: from firedrake import *
# from firedrake_adjoint import * # if uncommented, instantiation of `EquationBC` fails
mesh_num = 16
mesh = UnitSquareMesh(mesh_num, mesh_num)
V = FunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
f = Function(V)
x, y = SpatialCoordinate(mesh)
f.interpolate(- 8.0 * pi * pi * cos(x * pi * 2) * cos(y * pi * 2))
a = - inner(grad(u), grad(v)) * dx
L = inner(f, v) * dx
g = Function(V)
g.interpolate(cos(2 * pi * x) * cos(2 * pi * y))
u_ = Function(V)
bc1 = EquationBC(inner(u, v) * ds(1) == inner(g, v) * ds(1), u_, 1)
solve(a == L, u_, bcs=[bc1])
f.interpolate(cos(x * pi * 2) * cos(y * pi * 2))
cost = sqrt(assemble(inner(u_ - f, u_ - f) * dx)) Once the
I noticed that the implementation of There's a relatively simple workaround in my case - to add Neumann/Robin BC terms to the weak form of the PDE. So the problem isn't a deal breaker; I just want to satisfy my intelectual curiosity and find out the answer. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You are right that |
Beta Was this translation helpful? Give feedback.
You are right that
EquationBC
currently does not work with adjoint. There is a work-in-progress PR on this (#2036), but we have yet to do some work to make this fully functional.Thanks!