From 3de7ca1af67affea1c53eef5ed31a488db1d6981 Mon Sep 17 00:00:00 2001 From: Matthew Collins <m.t.collins@warwick.ac.uk> Date: Sun, 26 Nov 2017 13:07:46 +0000 Subject: [PATCH] sunday push --- CMakeLists.txt | 1 + matrixindexset.hh | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 matrixindexset.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index b8b1e7d5f..ec53ef38a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ set(HEADERS bcrsmatrix.hh bvector.hh iterator.hh + matrixindexset.hh operators.hh preconditioners.hh slice.hh diff --git a/matrixindexset.hh b/matrixindexset.hh new file mode 100644 index 000000000..71e9f495a --- /dev/null +++ b/matrixindexset.hh @@ -0,0 +1,57 @@ +#ifndef DUNE_PYTHON_ISTL_BCRSMATRIX_HH +#define DUNE_PYTHON_ISTL_BCRSMATRIX_HH + +#include <memory> +#include <stdexcept> +#include <string> +#include <tuple> + +#include <dune/common/fmatrix.hh> +#include <dune/common/fvector.hh> + +#if HAVE_DUNE_ISTL +#include <dune/istl/matrixindexset.hh> +#endif // #if HAVE_DUNE_ISTL + +#include <dune/python/pybind11/pybind11.h> +#include <dune/python/pybind11/stl.h> + +namespace Dune +{ + + namespace Python + { + + // registermatrixindexset + // ------------------ + +#if HAVE_DUNE_ISTL + template <class MatrixIndexSet, class... options> + void registerMatrixIndexSet(pybind11::handle scope, + pybind11::class_<MatrixIndexSet, options...> cls) + { + typedef std::size_t size_type; + + // two different possible constructors + cls.def( pybind11::init( [] () { return new MatrixIndexSet(); } ) ); + cls.def( pybind11::init( [] (size_type rows, size_type cols) { return new MatrixIndexSet(rows,cols); } ) ); + + cls.def ( "add", [] (MatrixIndexSet &self, size_type i, size_type j) {self.add(i,j); } ); + + cls.def( "exportIdx<BCRSMatrix etc...>", [] (MatrixIndexSet &self) { } ); + } + + template< class MatrixIndexSet > + pybind11::class_< MatrixIndexSet > registerMatrixIndexSet ( pybind11::handle scope, const char *clsName = "MatrixIndexSet" ) + { + pybind11::class_< MatrixIndexSet > cls( scope, clsName ); + registerMatrixIndexSet( scope, cls ); + return cls; + } +#endif // #if HAVE_DUNE_ISTL + + } // namespace Python + +} // namespace Dune + +#endif // #ifndef DUNE_PYTHON_ISTL_BCRSMATRIX_HH -- GitLab