From 108821ff4b6eb0c7018890ce21ee7094f2002fae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20He=C3=9F?= <rene.hess@iwr.uni-heidelberg.de>
Date: Mon, 12 Feb 2018 10:52:21 +0100
Subject: [PATCH] Replace coefficient only in nonlinear case

---
 python/dune/perftool/pdelab/localoperator.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/python/dune/perftool/pdelab/localoperator.py b/python/dune/perftool/pdelab/localoperator.py
index 8b3e012b..190882c0 100644
--- a/python/dune/perftool/pdelab/localoperator.py
+++ b/python/dune/perftool/pdelab/localoperator.py
@@ -740,10 +740,11 @@ def generate_localoperator_kernels(operator):
         objective_jacobian = derivative(objective, objective.coefficients()[0])
 
         # Replace coefficient belonging to ansatz function with new coefficient
-        element = adjoint_jacform.coefficients()[0].ufl_element()
+        element = objective.coefficients()[0].ufl_element()
         coeff = Coefficient(element, count=3)
-        adjoint_jacform = replace(adjoint_jacform, {adjoint_jacform.coefficients()[0]: coeff})
         objective_jacobian = replace(objective_jacobian, {objective.coefficients()[0]: coeff})
+        if len(adjoint_jacform.coefficients()) > 0:
+            adjoint_jacform = replace(adjoint_jacform, {adjoint_jacform.coefficients()[0]: coeff})
 
         # Residual of the adjoint form
         adjoint_form = action(adjoint_jacform, original_form.coefficients()[0])
-- 
GitLab