From 09bb30799a6d453c9afca6212fdaad79e3c63f41 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, 31 Oct 2016 09:31:24 +0100
Subject: [PATCH] Remove unused code and unnec. temporary

This removes:
- The now obsolete quadrature_loop_statement.
- Quadrature weights are now a globalarg and we do not create a
temporary anymore.
---
 python/dune/perftool/loopy/target.py         | 12 ------
 python/dune/perftool/pdelab/__init__.py      | 10 +++--
 python/dune/perftool/pdelab/localoperator.py |  6 ---
 python/dune/perftool/pdelab/quadrature.py    | 39 ++++++--------------
 python/dune/perftool/sumfact/amatrix.py      |  2 +-
 python/dune/perftool/ufl/visitor.py          |  3 +-
 6 files changed, 21 insertions(+), 51 deletions(-)

diff --git a/python/dune/perftool/loopy/target.py b/python/dune/perftool/loopy/target.py
index ae8cd548..b1c738b3 100644
--- a/python/dune/perftool/loopy/target.py
+++ b/python/dune/perftool/loopy/target.py
@@ -40,18 +40,6 @@ class DuneASTBuilder(CASTBuilder):
         # type system!
         return []
 
-    # def emit_sequential_loop(self, codegen_state, iname, iname_dtype, static_lbound, static_ubound, inner):
-    #     # Some of our loops are special as they use PDELab specific concepts.
-    #     # Fortunately those loops are tied to specific inames.
-    #     from dune.perftool.pdelab.quadrature import quadrature_iname
-    #     if iname == quadrature_iname():
-    #         from cgen import CustomLoop
-    #         from dune.perftool.pdelab.quadrature import quadrature_loop_statement
-    #         loop_stmt = quadrature_loop_statement()
-    #         return CustomLoop("for({})".format(loop_stmt), inner)
-    #     else:
-    #         return CASTBuilder.emit_sequential_loop(self, codegen_state, iname, iname_dtype, static_lbound, static_ubound, inner)
-
 
 class DuneTarget(TargetBase):
     def __init__(self):
diff --git a/python/dune/perftool/pdelab/__init__.py b/python/dune/perftool/pdelab/__init__.py
index 76aaff91..370efeec 100644
--- a/python/dune/perftool/pdelab/__init__.py
+++ b/python/dune/perftool/pdelab/__init__.py
@@ -22,7 +22,8 @@ from dune.perftool.pdelab.index import (name_index,
 from dune.perftool.pdelab.parameter import (cell_parameter_function,
                                             intersection_parameter_function,
                                             )
-from dune.perftool.pdelab.quadrature import (name_quadrature_weight,
+from dune.perftool.pdelab.quadrature import (name_quadrature_weights,
+                                             quadrature_iname,
                                              )
 from dune.perftool.pdelab.spaces import (lfs_iname,
                                          )
@@ -102,5 +103,8 @@ class PDELabInterface(object):
     # Quadrature related generator functions
     #
 
-    def name_quadrature_weight(self):
-        return name_quadrature_weight()
+    def quadrature_iname(self):
+        return quadrature_iname()
+
+    def name_quadrature_weights(self):
+        return name_quadrature_weights()
diff --git a/python/dune/perftool/pdelab/localoperator.py b/python/dune/perftool/pdelab/localoperator.py
index 5f9ac0d9..156721f4 100644
--- a/python/dune/perftool/pdelab/localoperator.py
+++ b/python/dune/perftool/pdelab/localoperator.py
@@ -504,12 +504,6 @@ def generate_kernel(integrals):
     from dune.perftool.loopy.stages import finalize_stage_instructions
     kernel = finalize_stage_instructions(kernel)
 
-    # This is also silly, but 1D DG Schemes never need the geometry, so the quadrature
-    # statement actually introduces a preamble at a stage where preambles cannot be generated
-    # anymore. TODO think about how to avoid this!!!
-    from dune.perftool.pdelab.quadrature import quadrature_loop_statement
-    quadrature_loop_statement()
-
     # Loopy might have introduced some temporary variables during preprocessing. As I want to have my own
     # temporary declaration code right now, I call the declaration preamble manually.
     for added_tv in set(kernel.temporary_variables.keys()) - set(temporaries.keys()):
diff --git a/python/dune/perftool/pdelab/quadrature.py b/python/dune/perftool/pdelab/quadrature.py
index ae80479b..c4bfa744 100644
--- a/python/dune/perftool/pdelab/quadrature.py
+++ b/python/dune/perftool/pdelab/quadrature.py
@@ -1,13 +1,17 @@
+import numpy
+
 from dune.perftool.generation import (backend,
                                       cached,
                                       class_member,
                                       domain,
                                       get_global_context_value,
+                                      globalarg,
                                       iname,
                                       include_file,
                                       instruction,
                                       preamble,
                                       temporary_variable,
+                                      valuearg,
                                       )
 from dune.perftool.pdelab.localoperator import lop_template_range_field
 from dune.perftool.options import get_option
@@ -38,6 +42,10 @@ def define_quadrature_bound(name):
 def name_quadrature_bound():
     name = "quadrature_size"
     define_quadrature_bound(name)
+
+    # Quadrature bound is a valuearg for loopy
+    valuearg(name, dtype=numpy.int32)
+
     return name
 
 
@@ -84,7 +92,6 @@ def fill_quadrature_points_cache(name):
 
 @class_member("operator")
 def typedef_quadrature_points(name):
-    # TODO: Maybe not consistent
     range_field = lop_template_range_field()
     dim = _local_dim()
     return "using {} = typename Dune::QuadraturePoint<{}, {}>::Vector;".format(name, range_field, dim)
@@ -155,7 +162,6 @@ def fill_quadrature_weights_cache(name):
 
 @class_member("operator")
 def typedef_quadrature_weights(name):
-    # TODO: Maybe not consistent
     range_field = lop_template_range_field()
     dim = _local_dim()
     return "using {} = typename Dune::QuadraturePoint<{}, {}>::Field;".format(name, range_field, dim)
@@ -179,21 +185,11 @@ def name_quadrature_weights():
     name = "qw_" + str(dim)
     define_quadrature_weights(name)
     fill_quadrature_weights_cache(name)
-    return name
-
-
-def define_quadrature_weight(name):
-    quad_weights = name_quadrature_weights()
-    quad_iname = quadrature_iname()
-    return quadrature_preamble(code="auto {} = {}[{}];".format(name, quad_weights, quad_iname),
-                               assignees=frozenset({name})
-                               )
 
+    # Quadrature weighs is a globar argument for loopy
+    shape = name_quadrature_bound()
+    globalarg(name, shape=(shape,), dtype=numpy.float64)
 
-def name_quadrature_weight():
-    name = 'weight'
-    temporary_variable(name, shape=())
-    define_quadrature_weight(name)
     return name
 
 
@@ -232,16 +228,3 @@ def name_quadrature_order():
     # Quadrature order from UFL estimation
     quad_order = quadrature_order()
     return str(quad_order)
-
-
-def quadrature_loop_statement():
-    pass
-#     include_file('dune/pdelab/common/quadraturerules.hh', filetag='operatorfile')
-#     qp = name_quadrature_point()
-#     from dune.perftool.pdelab.geometry import name_geometry
-#     geo = name_geometry()
-#     order = name_quadrature_order()
-#     return "const auto& {} : quadratureRule({}, {})".format(qp,
-#                                                             geo,
-#                                                             order,
-#                                                             )
diff --git a/python/dune/perftool/sumfact/amatrix.py b/python/dune/perftool/sumfact/amatrix.py
index b84d1788..cf9f33c4 100644
--- a/python/dune/perftool/sumfact/amatrix.py
+++ b/python/dune/perftool/sumfact/amatrix.py
@@ -230,7 +230,7 @@ def define_theta(name, transpose):
         shape = (basis_functions_per_direction(), quadrature_points_per_direction())
     else:
         shape = (quadrature_points_per_direction(), basis_functions_per_direction())
-    globalarg(name, shape=shape, dtype=numpy.float32, dim_tags="f,f")
+    globalarg(name, shape=shape, dtype=numpy.float64, dim_tags="f,f")
     initializer_list(name, [str(axis) for axis in shape], classtag="operator")
     construct_theta(name, transpose)
     return "{} {};".format(theta_type, name)
diff --git a/python/dune/perftool/ufl/visitor.py b/python/dune/perftool/ufl/visitor.py
index d87c5dcf..e05411a0 100644
--- a/python/dune/perftool/ufl/visitor.py
+++ b/python/dune/perftool/ufl/visitor.py
@@ -256,7 +256,8 @@ class UFL2LoopyVisitor(ModifiedTerminalTracker):
             return Variable(self.interface.name_unit_inner_normal())
 
     def quadrature_weight(self, o):
-        return Variable(self.interface.name_quadrature_weight())
+        self.inames.append(self.interface.quadrature_iname())
+        return Subscript(Variable(self.interface.name_quadrature_weights()), (Variable(self.interface.quadrature_iname()),))
 
     def jacobian_determinant(self, o):
         return Variable(self.interface.name_jacobian_determinant())
-- 
GitLab