diff --git a/dune/gdt/CMakeLists.txt b/dune/gdt/CMakeLists.txt index a727d6a86985d305817fb3e6f5683708341f3c0e..617777cf7728d5cd1fa2c61cb18cfcac79ee731e 100644 --- a/dune/gdt/CMakeLists.txt +++ b/dune/gdt/CMakeLists.txt @@ -74,6 +74,9 @@ if(dune-pybindxi_FOUND) # * oswald interpolation dune_pybindxi_add_module(__operators_oswaldinterpolation operators/oswaldinterpolation.bindings.cc) list(APPEND pybindxi_modules __operators_oswaldinterpolation) + # * L2 operator + dune_pybindxi_add_module(__operators_l2 operators/l2.bindings.cc) + list(APPEND pybindxi_modules __operators_l2) # * weighted L2 operator dune_pybindxi_add_module(__operators_weighted_l2 operators/weighted-l2.bindings.cc) list(APPEND pybindxi_modules __operators_weighted_l2) diff --git a/dune/gdt/operators/l2.bindings.cc b/dune/gdt/operators/l2.bindings.cc new file mode 100644 index 0000000000000000000000000000000000000000..82039538aad4ee65ad4f8a6852507e6f8b261cb6 --- /dev/null +++ b/dune/gdt/operators/l2.bindings.cc @@ -0,0 +1,121 @@ +// This file is part of the dune-gdt project: +// https://github.com/dune-community/dune-gdt +// Copyright 2010-2017 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 (2017) + +#include "config.h" + +#if HAVE_DUNE_PYBINDXI + +#include <dune/common/parallel/mpihelper.hh> + +#if HAVE_DUNE_FEM +#include <dune/fem/misc/mpimanager.hh> +#endif + +#include <dune/pybindxi/pybind11.h> +#include <dune/pybindxi/stl.h> + +#include <dune/xt/common/bindings.hh> +#include <dune/xt/grid/grids.bindings.hh> +#include <dune/xt/grid/layers.hh> + +#include <dune/gdt/operators/l2.bindings.hh> + + +PYBIND11_PLUGIN(__operators_l2) +{ + using namespace Dune; + namespace py = pybind11; + using namespace pybind11::literals; + using Dune::XT::Grid::Layers; + using namespace Dune::XT; + using Dune::GDT::SpaceType; + + py::module m("__operators_l2", "dune-gdt: L2MatrixOperator"); + + Dune::XT::Common::bindings::addbind_exceptions(m); + + py::module::import("dune.xt.common"); + py::module::import("dune.xt.grid"); + py::module::import("dune.xt.functions"); + py::module::import("dune.xt.la"); + py::module::import("dune.gdt.__spaces"); + py::module::import("dune.gdt.__discretefunction"); + +#if HAVE_DUNE_ALUGRID && HAVE_DUNE_FEM + Dune::GDT::bindings::L2MatrixOperator<ALU_2D_SIMPLEX_CONFORMING, + Layers::dd_subdomain, + SpaceType::dg, + GDT::Backends::fem, + 1, + 1, + LA::Backends::istl_sparse>::bind(m); + Dune::GDT::bindings::L2MatrixOperator<ALU_2D_SIMPLEX_CONFORMING, + Layers::leaf, + SpaceType::dg, + GDT::Backends::fem, + 1, + 1, + LA::Backends::istl_sparse>::bind(m); + Dune::GDT::bindings::L2MatrixOperator<ALU_2D_SIMPLEX_CONFORMING, + Layers::level, + SpaceType::dg, + GDT::Backends::fem, + 1, + 1, + LA::Backends::istl_sparse>::bind(m); +#endif // HAVE_DUNE_ALUGRID && HAVE_DUNE_FEM + + m.def("_init_mpi", + [](const std::vector<std::string>& args) { + int argc = Dune::XT::Common::numeric_cast<int>(args.size()); + char** argv = Dune::XT::Common::vector_to_main_args(args); + Dune::MPIHelper::instance(argc, argv); +#if HAVE_DUNE_FEM + Dune::Fem::MPIManager::initialize(argc, argv); +#endif + }, + "args"_a = std::vector<std::string>()); + + m.def("_init_logger", + [](const ssize_t max_info_level, + const ssize_t max_debug_level, + const bool enable_warnings, + const bool enable_colors, + const std::string& info_color, + const std::string& debug_color, + const std::string& warning_color) { + Dune::XT::Common::TimedLogger().create( + max_info_level, max_debug_level, enable_warnings, enable_colors, info_color, debug_color, warning_color); + }, + "max_info_level"_a = std::numeric_limits<ssize_t>::max(), + "max_debug_level"_a = std::numeric_limits<ssize_t>::max(), + "enable_warnings"_a = true, + "enable_colors"_a = true, + "info_color"_a = "blue", + "debug_color"_a = "darkgray", + "warning_color"_a = "red"); + + m.def("_test_logger", + [](const bool info, const bool debug, const bool warning) { + auto logger = Dune::XT::Common::TimedLogger().get("dune.gdt.operators.elliptic"); + if (info) + logger.info() << "info logging works!" << std::endl; + if (debug) + logger.debug() << "debug logging works!" << std::endl; + if (warning) + logger.warn() << "warning logging works!" << std::endl; + }, + "info"_a = true, + "debug"_a = true, + "warning"_a = true); + + return m.ptr(); +} + +#endif // HAVE_DUNE_PYBINDXI diff --git a/dune/gdt/operators/l2.bindings.hh b/dune/gdt/operators/l2.bindings.hh new file mode 100644 index 0000000000000000000000000000000000000000..4f6aed47d12c2b989d67301879c437fb0d99f220 --- /dev/null +++ b/dune/gdt/operators/l2.bindings.hh @@ -0,0 +1,89 @@ +// This file is part of the dune-gdt project: +// https://github.com/dune-community/dune-gdt +// Copyright 2010-2017 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 (2017) + +#ifndef DUNE_GDT_OPERATORS_L2_BINDINGS_HH +#define DUNE_GDT_OPERATORS_L2_BINDINGS_HH +#if HAVE_DUNE_PYBINDXI + +#include <dune/pybindxi/pybind11.h> + +#include <dune/xt/grid/grids.bindings.hh> +#include <dune/xt/grid/type_traits.hh> +#include <dune/xt/la/container.bindings.hh> + +#include <dune/gdt/spaces.hh> +#include <dune/gdt/spaces.bindings.hh> +#include <dune/gdt/type_traits.hh> + +#include "base.bindings.hh" +#include "l2.hh" + +namespace Dune { +namespace GDT { +namespace bindings { + + +template <class G, + XT::Grid::Layers layer_type, + GDT::SpaceType space_type, + GDT::Backends space_backend, + int p, + size_t r, + XT::LA::Backends la_backend> +class L2MatrixOperator +{ + static_assert(XT::Grid::is_grid<G>::value, ""); + typedef GDT::SpaceProvider<G, layer_type, space_type, space_backend, p, double, r, 1> RP; + typedef typename RP::type R; + typedef typename XT::LA::Container<double, la_backend>::MatrixType M; + +public: + typedef GDT::L2MatrixOperator<R, M /*, GL, S, F*/> type; + typedef pybind11::class_<type, GDT::SystemAssembler<R>> bound_type; + +public: + static bound_type bind(pybind11::module& m) + { + namespace py = pybind11; + using namespace pybind11::literals; + + const auto ClassName = XT::Common::to_camel_case("l2_matrix_operator_" + space_name<RP>::value() + "_" + + XT::LA::bindings::container_name<M>::value()); + + auto c = MatrixOperatorBase<type>::bind(m, ClassName); + + m.def(std::string("make_l2_matrix_operator_" + XT::LA::bindings::container_name<M>::value()).c_str(), + [](const R& space, const size_t over_integrate) { + return make_l2_matrix_operator<M>(space, over_integrate).release(); + }, + "space"_a, + "over_integrate"_a = 0, + py::keep_alive<0, 1>()); + + m.def("make_l2_matrix_operator", + [](M& matrix, const R& space, const size_t over_integrate) { + return make_l2_matrix_operator(matrix, space, over_integrate).release(); + }, + "matrix"_a, + "space"_a, + "over_integrate"_a = 0, + py::keep_alive<0, 1>(), + py::keep_alive<0, 2>()); + + return c; + } // ... bind(...) +}; // class L2MatrixOperator + + +} // namespace bindings +} // namespace GDT +} // namespace Dune + +#endif // HAVE_DUNE_PYBINDXI +#endif // DUNE_GDT_OPERATORS_L2_BINDINGS_HH diff --git a/dune/gdt/operators/l2.hh b/dune/gdt/operators/l2.hh index 24d6e987f9b45df0cc38c0a290f9ee56271b0191..06f7ddfc7f7cabab59089b585db2dcf6fcc30a4c 100644 --- a/dune/gdt/operators/l2.hh +++ b/dune/gdt/operators/l2.hh @@ -190,6 +190,7 @@ class L2MatrixOperator SourceSpace, Field> BaseType; + typedef L2MatrixOperator<RangeSpace, Matrix, GridLayer, SourceSpace, Field> ThisType; // We suffer from the same problem as in L2LocalizableProduct, see above for an explanation. template <bool anything> @@ -240,6 +241,9 @@ L2LocalizableProduct(...args); std::forward<Args>(args)...) { } + + L2MatrixOperator(const ThisType& other) = delete; // These need to be here for pybind11, as long as the assembler is + L2MatrixOperator(ThisType&& source) = delete; // not copyable or movable. }; // class L2MatrixOperator diff --git a/python/dune/gdt/__init__.py b/python/dune/gdt/__init__.py index 38b5079d3d7284f95206ccd7fe81b66b2c269e32..568e92bc60a7d4c9862934555bc017bbcffd9b85 100644 --- a/python/dune/gdt/__init__.py +++ b/python/dune/gdt/__init__.py @@ -35,6 +35,7 @@ _gdt_modules = ['spaces', 'operators_ESV2007', 'operators_OS2015', 'operators_RS2017', + 'operators_l2', 'operators_weighted_l2'] for module_name in _gdt_modules: