Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into annotation_assemble…
Browse files Browse the repository at this point in the history
…_1-form
  • Loading branch information
nbouziani committed Nov 19, 2022
2 parents 6994441 + e21c031 commit 45dc32e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 2 additions & 6 deletions dolfin_adjoint_common/blocks/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,12 @@ def evaluate_adj_component(self, inputs, adj_inputs, block_variable, idx,
# Linear combination
expr, adj_input_func = prepared
adj_output = self.backend.Function(adj_input_func.function_space())
if block_variable.saved_output.ufl_shape == adj_input_func.ufl_shape:
if not isinstance(block_variable.output, self.backend.Constant):
diff_expr = ufl.algorithms.expand_derivatives(
ufl.derivative(expr, block_variable.saved_output, adj_input_func)
)
adj_output.assign(diff_expr)
else:
# Assume current variable is scalar constant.
# This assumption might be wrong for firedrake.
assert isinstance(block_variable.output, self.backend.Constant)

diff_expr = ufl.algorithms.expand_derivatives(
ufl.derivative(expr, block_variable.saved_output, self.backend.Constant(1.))
)
Expand Down Expand Up @@ -138,7 +134,7 @@ def recompute_component(self, inputs, block_variable, idx, prepared):
if self.expr is None:
prepared = inputs[0]
output = self.backend.Function(block_variable.output.function_space())
self.backend.Function.assign(output, prepared)
output.assign(prepared)
return output

def __str__(self):
Expand Down
9 changes: 4 additions & 5 deletions tests/firedrake_adjoint/test_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_assign_tlm():
assert taylor_test(rf, f, h, dJdm=J.block_variable.tlm_value) > 1.9


def test_assign_tlm_wit_constant():
def test_assign_tlm_with_constant():
mesh = IntervalMesh(10, 0, 1)
V = FunctionSpace(mesh, "CG", 1)

Expand All @@ -83,7 +83,7 @@ def test_assign_tlm_wit_constant():
c = Constant(5.0)

u = Function(V)
u.assign(c * f ** 2)
u.interpolate(c * f**2)

c.block_variable.tlm_value = Constant(0.3)
tape = get_working_tape()
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_assign_nonlincom():
g = interpolate(sin(x[0]), V)
u = Function(V)

u.assign(f*g)
u.interpolate(f*g)

J = assemble(u ** 2 * dx)
rf = ReducedFunctional(J, Control(f))
Expand All @@ -151,7 +151,6 @@ def test_assign_with_constant():

u.assign(c*f+d**3)

# J = c**2/3 + cd**3 + d**6
J = assemble(u ** 2 * dx)

rf = ReducedFunctional(J, Control(c))
Expand Down Expand Up @@ -182,7 +181,7 @@ def test_assign_nonlin_changing():

u = Function(V)

u.assign(f*sol*g)
u.interpolate(f*sol*g)

J = assemble(u ** 2 * dx)
rf = ReducedFunctional(J, control)
Expand Down

0 comments on commit 45dc32e

Please sign in to comment.