From 84d8c0c62f36ec341ca1286a0fdba2906addadb4 Mon Sep 17 00:00:00 2001
From: Felix Schindler <felix.schindler@wwu.de>
Date: Sun, 5 Aug 2018 17:00:53 +0200
Subject: [PATCH] [discretefunction.default] some improvements

This

* adds a proper check of the template arguments, giving better static errors
* adds a local_discrete_function(element) method
* fixes make_const_discrete_function for Vector&&
---
 dune/gdt/discretefunction/default.hh | 48 ++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 9 deletions(-)

diff --git a/dune/gdt/discretefunction/default.hh b/dune/gdt/discretefunction/default.hh
index 4f7363f46..6d6ec5fde 100644
--- a/dune/gdt/discretefunction/default.hh
+++ b/dune/gdt/discretefunction/default.hh
@@ -26,17 +26,33 @@
 
 namespace Dune {
 namespace GDT {
+namespace internal {
 
 
-template <class Vector, class GridView, size_t range_dim = 1, size_t range_dim_cols = 1, class RangeField = double>
-class ConstDiscreteFunction
-    : public XT::Functions::
-          GridFunctionInterface<XT::Grid::extract_entity_t<GridView>, range_dim, range_dim_cols, RangeField>
+template <class Vector, class GridView>
+struct AssertArgumentsOfConstDiscreteFunction
 {
   static_assert(XT::LA::is_vector<Vector>::value, "");
+  static_assert(XT::Grid::is_view<GridView>::value, "");
+  using E = XT::Grid::extract_entity_t<GridView>;
+};
+
+
+} // namespace internal
+
 
-  using BaseType =
-      XT::Functions::GridFunctionInterface<XT::Grid::extract_entity_t<GridView>, range_dim, range_dim_cols, RangeField>;
+template <class Vector, class GridView, size_t range_dim = 1, size_t range_dim_cols = 1, class RangeField = double>
+class ConstDiscreteFunction : public XT::Functions::GridFunctionInterface<
+                                  typename internal::AssertArgumentsOfConstDiscreteFunction<Vector, GridView>::E,
+                                  range_dim,
+                                  range_dim_cols,
+                                  RangeField>
+{
+  using BaseType = XT::Functions::GridFunctionInterface<
+      typename internal::AssertArgumentsOfConstDiscreteFunction<Vector, GridView>::E,
+      range_dim,
+      range_dim_cols,
+      RangeField>;
   using ThisType = ConstDiscreteFunction<Vector, GridView, range_dim, range_dim_cols, RangeField>;
 
 public:
@@ -79,6 +95,13 @@ public:
     return std::make_unique<ConstLocalDiscreteFunctionType>(space_, dofs_);
   }
 
+  std::unique_ptr<ConstLocalDiscreteFunctionType> local_discrete_function(const ElementType& grid_element) const
+  {
+    auto ldf = local_discrete_function();
+    ldf->bind(grid_element);
+    return ldf;
+  }
+
   /**
    * \name ``These methods are required by XT::Functions::GridFunctionInterface.''
    * \{
@@ -128,9 +151,9 @@ private:
 
 template <class V, class GV, size_t r, size_t rC, class R>
 ConstDiscreteFunction<typename XT::LA::VectorInterface<V>::derived_type, GV, r, rC, R>
-make_const_discrete_function(const SpaceInterface<GV, r, rC, R>& space,
-                             const XT::LA::VectorInterface<V>& vector,
-                             const std::string nm = "dune.gdt.constdiscretefunction")
+make_discrete_function(const SpaceInterface<GV, r, rC, R>& space,
+                       const XT::LA::VectorInterface<V>& vector,
+                       const std::string nm = "dune.gdt.constdiscretefunction")
 {
   return ConstDiscreteFunction<typename XT::LA::VectorInterface<V>::derived_type, GV, r, rC, R>(
       space, vector.as_imp(), nm);
@@ -194,6 +217,13 @@ public:
     return std::make_unique<LocalDiscreteFunctionType>(space_, dofs_);
   }
 
+  std::unique_ptr<LocalDiscreteFunctionType> local_discrete_function(const ElementType& grid_element)
+  {
+    auto ldf = local_discrete_function();
+    ldf->bind(grid_element);
+    return ldf;
+  }
+
   /**
    * \name ``These methods are required by XT::Functions::GridFunctionInterface.''
    * \{
-- 
GitLab