From 553fbc784cc5ddaa678f4f66dd11625732f9427c Mon Sep 17 00:00:00 2001
From: Felix Schindler <felix.schindler@wwu.de>
Date: Thu, 7 May 2020 14:49:06 +0200
Subject: [PATCH] [python|local.bilinear-forms] add bindings for element
 interface

---
 python/dune/gdt/CMakeLists.txt                |   1 +
 python/dune/gdt/__init__.py                   |   1 +
 .../local/bilinear-forms/element_interface.cc | 149 ++++++++++++++++++
 3 files changed, 151 insertions(+)
 create mode 100644 python/dune/gdt/local/bilinear-forms/element_interface.cc

diff --git a/python/dune/gdt/CMakeLists.txt b/python/dune/gdt/CMakeLists.txt
index 1a62375cf..254859c53 100644
--- a/python/dune/gdt/CMakeLists.txt
+++ b/python/dune/gdt/CMakeLists.txt
@@ -14,6 +14,7 @@
 file(GLOB_RECURSE header "*.hh")
 
 dune_pybindxi_add_module(_discretefunction EXCLUDE_FROM_ALL ${header} discretefunction/discretefunction.cc)
+dune_pybindxi_add_module(_local_bilinear_forms_element_interface EXCLUDE_FROM_ALL ${header} local/bilinear-forms/element_interface.cc)
 dune_pybindxi_add_module(_local_integrands_binary_element_interface EXCLUDE_FROM_ALL ${header} local/integrands/binary_element_interface.cc)
 dune_pybindxi_add_module(_local_integrands_laplace EXCLUDE_FROM_ALL ${header} local/integrands/laplace.cc)
 dune_pybindxi_add_module(_operators_interfaces_common EXCLUDE_FROM_ALL ${header} operators/interfaces_common.cc)
diff --git a/python/dune/gdt/__init__.py b/python/dune/gdt/__init__.py
index 87a3586d8..72df41014 100644
--- a/python/dune/gdt/__init__.py
+++ b/python/dune/gdt/__init__.py
@@ -14,6 +14,7 @@ from dune.xt import guarded_import
 
 for mod_name in ( # order should not matter!
         '_discretefunction',
+        '_local_bilinear_forms_element_interface',
         '_local_integrands_binary_element_interface',
         '_local_integrands_laplace',
         '_operators_interfaces_common',
diff --git a/python/dune/gdt/local/bilinear-forms/element_interface.cc b/python/dune/gdt/local/bilinear-forms/element_interface.cc
new file mode 100644
index 000000000..4cc8b807b
--- /dev/null
+++ b/python/dune/gdt/local/bilinear-forms/element_interface.cc
@@ -0,0 +1,149 @@
+// This file is part of the dune-gdt project:
+//   https://github.com/dune-community/dune-gdt
+// Copyright 2010-2018 dune-gdt developers and contributors. All rights reserved.
+// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
+//      or  GPL-2.0+ (http://opensource.org/licenses/gpl-license)
+//          with "runtime exception" (http://www.dune-project.org/license.html)
+// Authors:
+//   Felix Schindler (2020)
+
+#include "config.h"
+
+#include <dune/pybindxi/pybind11.h>
+#include <dune/pybindxi/stl.h>
+
+#include <dune/xt/grid/type_traits.hh>
+#include <dune/xt/grid/grids.hh>
+#include <dune/gdt/local/bilinear-forms/interfaces.hh>
+
+#include <python/dune/xt/common/configuration.hh>
+#include <python/dune/xt/common/fvector.hh>
+#include <python/dune/xt/grid/grids.bindings.hh>
+
+namespace Dune {
+namespace GDT {
+namespace bindings {
+
+
+template <class E,
+          size_t t_r = 1,
+          size_t t_rC = 1,
+          class TF = double,
+          class F = double,
+          size_t a_r = t_r,
+          size_t a_rC = t_rC,
+          class AF = TF>
+class LocalElementBilinearFormInterface
+{
+  using G = XT::Grid::extract_grid_t<E>;
+  static const size_t d = G::dimension;
+
+public:
+  using type = GDT::LocalElementBilinearFormInterface<E, t_r, t_rC, TF, F, a_r, a_rC, AF>;
+  using bound_type = pybind11::class_<type>;
+
+  static bound_type bind(pybind11::module& m,
+                         const std::string& class_id = "local_element_bilinear_form",
+                         const std::string& grid_id = XT::Grid::bindings::grid_name<G>::value(),
+                         const std::string& layer_id = "")
+  {
+    namespace py = pybind11;
+    using namespace pybind11::literals;
+
+    std::string class_name = class_id;
+    class_name += "_" + grid_id;
+    if (!layer_id.empty())
+      class_name += "_" + layer_id;
+    std::string test_string = "";
+    test_string += "_" + XT::Common::to_string(t_r) + "d";
+    if (t_rC > 1)
+      test_string += "x" + XT::Common::to_string(t_rC) + "d";
+    if (!std::is_same<TF, double>::value)
+      test_string += "_" + XT::Common::Typename<TF>::value(/*fail_wo_typeid=*/true);
+    test_string += "_test_basis";
+    std::string ansatz_string = "";
+    ansatz_string += "_" + XT::Common::to_string(a_r) + "d";
+    if (a_rC > 1)
+      ansatz_string += "x" + XT::Common::to_string(a_rC) + "d";
+    if (!std::is_same<AF, double>::value)
+      ansatz_string += "_" + XT::Common::Typename<AF>::value(/*fail_wo_typeid=*/true);
+    ansatz_string += "_ansatz_basis";
+    class_name += test_string;
+    if (!test_string.empty() && !ansatz_string.empty())
+      class_name += "_x";
+    class_name += ansatz_string;
+    class_name += "_to_scalar";
+    if (!std::is_same<F, double>::value)
+      class_name += "_" + XT::Common::Typename<F>::value(/*fail_wo_typeid=*/true);
+    class_name += "_interface";
+    const auto ClassName = XT::Common::to_camel_case(class_name);
+    bound_type c(m, ClassName.c_str(), ClassName.c_str());
+    // static information about dims
+    // ...
+    c.def("copy", [](const type& self) { return self.copy(); });
+    // apply2
+    // ...
+    //    c.def("__repr__", [](const type& self) {
+    //      std::stringstream ss;
+    //      ss << self;
+    //      return ss.str();
+    //    });
+    return c;
+  } // ... bind(...)
+}; // class LocalElementBilinearFormInterface
+
+
+} // namespace bindings
+} // namespace GDT
+} // namespace Dune
+
+
+template <class GridTypes = Dune::XT::Grid::AvailableGridTypes>
+struct LocalElementBilinearFormInterface_for_all_grids
+{
+  using G = typename GridTypes::head_type;
+  using GV = typename G::LeafGridView;
+  using E = Dune::XT::Grid::extract_entity_t<GV>;
+  static const constexpr size_t d = G::dimension;
+  using F = double;
+
+  static void bind(pybind11::module& m)
+  {
+    Dune::GDT::bindings::LocalElementBilinearFormInterface<E>::bind(m);
+    if (d > 1) {
+      Dune::GDT::bindings::LocalElementBilinearFormInterface<E, 1, 1, F, F, d, 1, F>::bind(m);
+      Dune::GDT::bindings::LocalElementBilinearFormInterface<E, 1, 1, F, F, d, d, F>::bind(m);
+      Dune::GDT::bindings::LocalElementBilinearFormInterface<E, d, 1, F, F, 1, 1, F>::bind(m);
+      Dune::GDT::bindings::LocalElementBilinearFormInterface<E, d, 1, F, F, d, 1, F>::bind(m);
+      Dune::GDT::bindings::LocalElementBilinearFormInterface<E, d, 1, F, F, d, d, F>::bind(m);
+      Dune::GDT::bindings::LocalElementBilinearFormInterface<E, d, d, F, F, 1, 1, F>::bind(m);
+      Dune::GDT::bindings::LocalElementBilinearFormInterface<E, d, d, F, F, d, 1, F>::bind(m);
+      Dune::GDT::bindings::LocalElementBilinearFormInterface<E, d, d, F, F, d, d, F>::bind(m);
+    }
+    // add your extra dimensions here
+    // ...
+    LocalElementBilinearFormInterface_for_all_grids<typename GridTypes::tail_type>::bind(m);
+  }
+};
+
+template <>
+struct LocalElementBilinearFormInterface_for_all_grids<boost::tuples::null_type>
+{
+  static void bind(pybind11::module& /*m*/) {}
+};
+
+
+PYBIND11_MODULE(_local_bilinear_forms_element_interface, m)
+{
+  namespace py = pybind11;
+  using namespace Dune;
+  using namespace Dune::XT;
+  using namespace Dune::GDT;
+
+  py::module::import("dune.xt.common");
+  py::module::import("dune.xt.la");
+  py::module::import("dune.xt.grid");
+  py::module::import("dune.xt.functions");
+
+  LocalElementBilinearFormInterface_for_all_grids<XT::Grid::AvailableGridTypes>::bind(m);
+}
-- 
GitLab