From 6917da50467e91025a579dccbb3421a3af469063 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20He=C3=9F?= <rene.hess@iwr.uni-heidelberg.de>
Date: Thu, 18 Aug 2016 09:43:46 +0200
Subject: [PATCH] Some small improvements and bugfixes

---
 python/dune/perftool/loopy/transformer.py     |  4 ++--
 python/dune/perftool/pdelab/driver.py         |  2 +-
 python/dune/perftool/pdelab/localoperator.py  | 10 +++++++---
 python/dune/perftool/ufl/execution.py         |  8 --------
 .../dune/perftool/ufl/modified_terminals.py   | 19 ++++++-------------
 5 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/python/dune/perftool/loopy/transformer.py b/python/dune/perftool/loopy/transformer.py
index 3cad73b4..630ed6e8 100644
--- a/python/dune/perftool/loopy/transformer.py
+++ b/python/dune/perftool/loopy/transformer.py
@@ -51,8 +51,8 @@ class UFL2LoopyVisitor(ModifiedTerminalTracker, UFL2PymbolicMapper, GeometryMapp
         # We therefore gather a list of modified trial functions too.
         from dune.perftool.ufl.modified_terminals import extract_modified_arguments
         test_ma = extract_modified_arguments(o,)
-        trial_ma = extract_modified_arguments(o, testfunction=False, trialfunction=True)
-        apply_ma = extract_modified_arguments(o, testfunction=False, applyfunction=True)
+        trial_ma = extract_modified_arguments(o, coeffcount=0)
+        apply_ma = extract_modified_arguments(o, coeffcount=1)
 
         # All test and trial functions on boundary integrals are technically restricted
         import itertools
diff --git a/python/dune/perftool/pdelab/driver.py b/python/dune/perftool/pdelab/driver.py
index 8f3fb655..ff87bd11 100644
--- a/python/dune/perftool/pdelab/driver.py
+++ b/python/dune/perftool/pdelab/driver.py
@@ -907,7 +907,7 @@ def dune_solve():
         if get_option("matrix_free"):
             go = name_gridoperator()
             x = name_vector()
-            include_file("dune/perftool/matrixfree.hh", filetag="drive")
+            include_file("dune/perftool/matrixfree.hh", filetag="driver")
             return "solveMatrixFree({},{});".format(go, x)
         else:
             slp = name_stationarylinearproblemsolver()
diff --git a/python/dune/perftool/pdelab/localoperator.py b/python/dune/perftool/pdelab/localoperator.py
index 1c027044..b539e14f 100644
--- a/python/dune/perftool/pdelab/localoperator.py
+++ b/python/dune/perftool/pdelab/localoperator.py
@@ -379,11 +379,15 @@ def generate_localoperator_kernels(formdata, data):
 
         # Jacobian apply methods for matrix-free computations
         if get_option("matrix_free"):
-            from dune.perftool.ufl.execution import ApplyCoefficient
-            apply_coefficient = ApplyCoefficient(form.coefficients()[0]. ufl_element(), 1)
+            # The apply vector has reserved index 1 so we directly use Coefficient class from ufl
+            from ufl import Coefficient
+            apply_coefficient = Coefficient(form.coefficients()[0].ufl_element(), 1)
+
+            # Create application of jacobian on vector
             from ufl import action
-            jac_apply_form = action(expand_derivatives(derivative(form, form.coefficients()[0])), apply_coefficient)
+            jac_apply_form = action(jacform, apply_coefficient)
 
+            # Create kernel for jacobian application
             with global_context(form_type="jacobian_apply"):
                 for measure in set(i.integral_type() for i in jac_apply_form.integrals()):
                     with global_context(integral_type=measure):
diff --git a/python/dune/perftool/ufl/execution.py b/python/dune/perftool/ufl/execution.py
index 981471d0..5fe6975b 100644
--- a/python/dune/perftool/ufl/execution.py
+++ b/python/dune/perftool/ufl/execution.py
@@ -26,14 +26,6 @@ class TrialFunction(ufl.Coefficient):
         ufl.Coefficient.__init__(self, element, count=0)
 
 
-class ApplyCoefficient(ufl.Coefficient):
-    """ A coefficient that always takes the reserved index 1 """
-    def __init__(self, element, count=None):
-        if count and count is not 1:
-            raise ValueError("The jacobian apply coefficient must be of index 1 in uflpdelab")
-        ufl.Coefficient.__init__(self, element, count=1)
-
-
 class Coefficient(ufl.Coefficient):
     """ A coefficient that honors the reserved index 0. """
     def __init__(self, element, count=None):
diff --git a/python/dune/perftool/ufl/modified_terminals.py b/python/dune/perftool/ufl/modified_terminals.py
index 88eed958..82bb8eee 100644
--- a/python/dune/perftool/ufl/modified_terminals.py
+++ b/python/dune/perftool/ufl/modified_terminals.py
@@ -103,11 +103,9 @@ class ModifiedArgumentDescriptor(MultiFunction):
 class _ModifiedArgumentExtractor(MultiFunction):
     """ A multifunction that extracts and returns the set of modified arguments """
 
-    def __call__(self, o, argnumber=None, testfunction=True, trialfunction=False, applyfunction=False):
+    def __call__(self, o, argnumber=None, coeffcount=None):
         self.argnumber = argnumber
-        self.trialfunction = trialfunction
-        self.testfunction = testfunction
-        self.applyfunction = applyfunction
+        self.coeffcount = coeffcount
         self.modified_arguments = set()
         ret = self.call(o)
         if ret:
@@ -133,17 +131,12 @@ class _ModifiedArgumentExtractor(MultiFunction):
     function_view = pass_on
 
     def argument(self, o):
-        if self.testfunction:
-            if self.argnumber is None or o.number() == self.argnumber:
-                return o
+        if self.argnumber is None or o.number() == self.argnumber:
+            return o
 
     def coefficient(self, o):
-        if self.trialfunction:
-            if o.count() == 0:
-                return o
-        if self.applyfunction:
-            if o.count() == 1:
-                return o
+        if o.count() == self.coeffcount:
+            return o
 
     call = MultiFunction.__call__
 
-- 
GitLab