From 6f89635b52dfef4183731d618189ea633ea03a0a Mon Sep 17 00:00:00 2001
From: Marcel Koch <marcel.koch@uni-muenster.de>
Date: Mon, 31 Jul 2017 10:40:26 +0200
Subject: [PATCH] Removes element parameter from pdelab pymbolic_coefficient
 implementation.

I should work on a specific FiniteElement class or FEM for blockstructuring, s.t. I can remove the element parameter from the blockstructured implementation as well.
---
 .../dune/perftool/blockstructured/argument.py |  6 +++---
 python/dune/perftool/pdelab/basis.py          | 20 ++++++++++++++++---
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/python/dune/perftool/blockstructured/argument.py b/python/dune/perftool/blockstructured/argument.py
index 7d24a656..a4f67c2b 100644
--- a/python/dune/perftool/blockstructured/argument.py
+++ b/python/dune/perftool/blockstructured/argument.py
@@ -7,10 +7,10 @@ from loopy.types import NumpyType
 from pymbolic.primitives import Variable, Call
 import pymbolic.primitives as prim
 
-# TODO rename prim
+# TODO remove the need for element
 @kernel_cached
 @backend(interface="pymbolic_coefficient", name="blockstructured")
-def pymbolic_coefficient(container, lfs, index):
+def pymbolic_coefficient(container, lfs, element, index):
     # TODO introduce a proper type for local function spaces!
     if isinstance(lfs, str):
         valuearg(lfs, dtype=NumpyType("str"))
@@ -20,4 +20,4 @@ def pymbolic_coefficient(container, lfs, index):
     if not isinstance(lfs, Expression):
         lfs = Variable(lfs)
 
-    return Call(CoefficientAccess(container), (lfs, micro_index_to_macro_index(index),))
+    return Call(CoefficientAccess(container), (lfs, micro_index_to_macro_index(element, index),))
diff --git a/python/dune/perftool/pdelab/basis.py b/python/dune/perftool/pdelab/basis.py
index 756a8d71..eb89b04c 100644
--- a/python/dune/perftool/pdelab/basis.py
+++ b/python/dune/perftool/pdelab/basis.py
@@ -8,7 +8,9 @@ from dune.perftool.generation import (backend,
                                       kernel_cached,
                                       temporary_variable,
                                       )
-from dune.perftool.options import option_switch
+from dune.perftool.options import (option_switch,
+                                   get_option
+                                   )
 from dune.perftool.pdelab.spaces import (lfs_child,
                                          name_leaf_lfs,
                                          name_lfs,
@@ -168,7 +170,13 @@ def evaluate_coefficient(element, name, container, restriction, tree_path):
     if isinstance(sub_element, (VectorElement, TensorElement)):
         lfs = lfs_child(lfs, idims, shape=shape_as_pymbolic(shape), symmetry=element.symmetry())
 
-    coeff = get_backend("pymbolic_coefficient", selector=option_switch("blockstructured"))(container, lfs, index)
+    if get_option("blockstructured"):
+        from dune.perftool.blockstructured.argument import pymbolic_coefficient
+        coeff = pymbolic_coefficient(container, lfs, element, index)
+    else:
+        from dune.perftool.pdelab.argument import pymbolic_coefficient
+        coeff = pymbolic_coefficient(container, lfs, index)
+
     assignee = Subscript(Variable(name), tuple(Variable(i) for i in idims))
 
     reduction_expr = Product((coeff, basis))
@@ -205,7 +213,13 @@ def evaluate_coefficient_gradient(element, name, container, restriction, tree_pa
     if isinstance(sub_element, (VectorElement, TensorElement)):
         lfs = lfs_child(lfs, idims[:-1], shape=shape_as_pymbolic(shape[:-1]), symmetry=element.symmetry())
 
-    coeff = get_backend("pymbolic_coefficient", selector=option_switch("blockstructured"))(container, lfs, index)
+    if get_option("blockstructured"):
+        from dune.perftool.blockstructured.argument import pymbolic_coefficient
+        coeff = pymbolic_coefficient(container, lfs, element, index)
+    else:
+        from dune.perftool.pdelab.argument import pymbolic_coefficient
+        coeff = pymbolic_coefficient(container, lfs, index)
+
     assignee = Subscript(Variable(name), tuple(Variable(i) for i in idims))
 
     reduction_expr = Product((coeff, Subscript(Variable(get_pymbolic_basename(basis)), basis.index + (Variable(idims[-1]),))))
-- 
GitLab