diff --git a/python/dune/xt/grid/CMakeLists.txt b/python/dune/xt/grid/CMakeLists.txt index 9a3070a47c3204b45c460f16f3959888c03105ae..38b32b223f88ab1ff863c90696cc7033b840271b 100644 --- a/python/dune/xt/grid/CMakeLists.txt +++ b/python/dune/xt/grid/CMakeLists.txt @@ -18,6 +18,10 @@ dune_pybindxi_add_module(_grid_boundaryinfo_allreflecting EXCLUDE_FROM_ALL bound dune_pybindxi_add_module(_grid_boundaryinfo_interfaces EXCLUDE_FROM_ALL boundaryinfo/interfaces.cc) dune_pybindxi_add_module(_grid_boundaryinfo_normalbased EXCLUDE_FROM_ALL boundaryinfo/normalbased.cc) dune_pybindxi_add_module(_grid_boundaryinfo_types EXCLUDE_FROM_ALL boundaryinfo/types.cc) +dune_pybindxi_add_module(_grid_functors_boundary_detector EXCLUDE_FROM_ALL functors/boundary-detector.cc) +# dune_pybindxi_add_module(_grid_functors_bounding_box EXCLUDE_FROM_ALL functors/bounding-box.cc) +dune_pybindxi_add_module(_grid_functors_interfaces EXCLUDE_FROM_ALL functors/interfaces.cc) +# dune_pybindxi_add_module(_grid_functors_refinement EXCLUDE_FROM_ALL functors/refinement.cc) dune_pybindxi_add_module(_grid_gridprovider_cube EXCLUDE_FROM_ALL gridprovider/cube.cc) dune_pybindxi_add_module(_grid_gridprovider_provider EXCLUDE_FROM_ALL gridprovider/provider.cc) dune_pybindxi_add_module(_grid_traits EXCLUDE_FROM_ALL traits.cc) diff --git a/python/dune/xt/grid/__init__.py b/python/dune/xt/grid/__init__.py index e428d719da7ce93afb13d39ef9445efe20ec4d41..01390b0531cccf222c9a011edaf775bc0cdf0b55 100644 --- a/python/dune/xt/grid/__init__.py +++ b/python/dune/xt/grid/__init__.py @@ -22,6 +22,10 @@ for mod_name in ( '_grid_boundaryinfo_interfaces', '_grid_boundaryinfo_normalbased', '_grid_boundaryinfo_types', + '_grid_functors_boundary_detector', + # '_grid_functors_bounding_box', + '_grid_functors_interfaces', + # '_grid_functors_refinement', '_grid_gridprovider_cube', '_grid_gridprovider_provider', '_grid_traits', diff --git a/python/dune/xt/grid/functors/boundary-detector.cc b/python/dune/xt/grid/functors/boundary-detector.cc new file mode 100644 index 0000000000000000000000000000000000000000..9c3d0fe3bf2f3c4f5c8ba74fb366438d9ac8740a --- /dev/null +++ b/python/dune/xt/grid/functors/boundary-detector.cc @@ -0,0 +1,109 @@ +// This file is part of the dune-xt project: +// https://github.com/dune-community/dune-xt +// Copyright 2009-2018 dune-xt 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/xt/grid/functors/boundary-detector.hh> + +#include "interfaces.hh" + + +namespace Dune { +namespace XT { +namespace Grid { +namespace bindings { + + +template <class G> +class BoundaryDetectorFunctor +{ + static_assert(is_grid<G>::value, ""); + using GV = typename G::LeafGridView; + using I = extract_intersection_t<GV>; + +public: + using type = Grid::BoundaryDetectorFunctor<GV>; + using base_type = Grid::IntersectionFunctor<GV>; + using bound_type = pybind11::class_<type, base_type>; + + static bound_type bind(pybind11::module& m, + const std::string& class_id = "boundary_detector_functor", + const std::string& grid_id = grid_name<G>::value()) + { + namespace py = pybind11; + using namespace pybind11::literals; + + auto ClassId = Common::to_camel_case(class_id); + auto ClassName = Common::to_camel_case(class_id + "_" + grid_id); + bound_type c(m, ClassName.c_str(), std::string(ClassId + "( " + grid_id + " variant)").c_str()); + c.def(py::init([](const BoundaryInfo<I>& boundary_info, + const BoundaryType& boundary_type, + const std::string& logging_prefix) { + return std::make_unique<type>(boundary_info, boundary_type, logging_prefix); + }), + "boundary_info"_a, + "boundary_type"_a, + "logging_prefix"_a = "", + py::keep_alive<0, 1>()); + c.def("__repr__", [ClassId](type&) { return ClassId + "(boundary_info=, boundary_type=)"; }); + c.def_property_readonly("result", [](const type& self) { return self.result(); }); + + m.def(ClassId.c_str(), + [](const GridProvider<G>&, + const BoundaryInfo<I>& boundary_info, + const BoundaryType& boundary_type, + const std::string& logging_prefix) { + return std::make_unique<type>(boundary_info, boundary_type, logging_prefix); + }, + "grid_provider"_a, + "boundary_info"_a, + "boundary_type"_a, + "logging_prefix"_a = "", + py::keep_alive<0, 2>()); + + return c; + } // ... bind(...) +}; // class BoundaryDetectorFunctor + + +} // namespace bindings +} // namespace Grid +} // namespace XT +} // namespace Dune + + +template <class GridTypes = Dune::XT::Grid::AvailableGridTypes> +struct BoundaryDetectorFunctor_for_all_grids +{ + static void bind(pybind11::module& m) + { + Dune::XT::Grid::bindings::BoundaryDetectorFunctor<typename GridTypes::head_type>::bind(m); + BoundaryDetectorFunctor_for_all_grids<typename GridTypes::tail_type>::bind(m); + } +}; + +template <> +struct BoundaryDetectorFunctor_for_all_grids<boost::tuples::null_type> +{ + static void bind(pybind11::module& /*m*/) {} +}; + + +PYBIND11_MODULE(_grid_functors_boundary_detector, m) +{ + namespace py = pybind11; + + py::module::import("dune.xt.grid._grid_boundaryinfo_interfaces"); + py::module::import("dune.xt.grid._grid_boundaryinfo_types"); + py::module::import("dune.xt.grid._grid_gridprovider_provider"); + py::module::import("dune.xt.grid._grid_functors_interfaces"); + + BoundaryDetectorFunctor_for_all_grids<>::bind(m); +} diff --git a/python/dune/xt/grid/functors/bounding-box.cc b/python/dune/xt/grid/functors/bounding-box.cc new file mode 100644 index 0000000000000000000000000000000000000000..8a8303941b11dbcb505d47403c0394ad7d806fc4 --- /dev/null +++ b/python/dune/xt/grid/functors/bounding-box.cc @@ -0,0 +1,89 @@ +// This file is part of the dune-xt project: +// https://github.com/dune-community/dune-xt +// Copyright 2009-2018 dune-xt 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/xt/grid/functors/bounding-box.hh> +#include <python/dune/xt/common/fvector.hh> + +#include "interfaces.hh" + + +namespace Dune { +namespace XT { +namespace Grid { +namespace bindings { + + +template <class G> +class MinMaxCoordinateFunctor +{ + static_assert(is_grid<G>::value, ""); + using GV = typename G::LeafGridView; + using I = extract_intersection_t<GV>; + +public: + using type = Grid::MinMaxCoordinateFunctor<GV>; + using base_type = Grid::ElementFunctor<GV>; + using bound_type = pybind11::class_<type, base_type>; + + static bound_type bind(pybind11::module& m, + const std::string& class_id = "bounding_box_functor", + const std::string& grid_id = grid_name<G>::value()) + { + namespace py = pybind11; + using namespace pybind11::literals; + + auto ClassId = Common::to_camel_case(class_id); + auto ClassName = Common::to_camel_case(class_id + "_" + grid_id); + bound_type c(m, ClassName.c_str(), std::string(ClassId + "( " + grid_id + " variant)").c_str()); + c.def(py::init()); + c.def("__repr__", [ClassId](type&) { return ClassId + "()"; }); + c.def_property_readonly("result", [](const type& self) { return self.result(); }); + + m.def(ClassId.c_str(), [](const GridProvider<G>&) { return type(); }, "grid_provider"_a); + + return c; + } // ... bind(...) +}; // class MinMaxCoordinateFunctor + + +} // namespace bindings +} // namespace Grid +} // namespace XT +} // namespace Dune + + +template <class GridTypes = Dune::XT::Grid::AvailableGridTypes> +struct MinMaxCoordinateFunctor_for_all_grids +{ + static void bind(pybind11::module& m) + { + Dune::XT::Grid::bindings::MinMaxCoordinateFunctor<typename GridTypes::head_type>::bind(m); + MinMaxCoordinateFunctor_for_all_grids<typename GridTypes::tail_type>::bind(m); + } +}; + +template <> +struct MinMaxCoordinateFunctor_for_all_grids<boost::tuples::null_type> +{ + static void bind(pybind11::module& /*m*/) {} +}; + + +PYBIND11_MODULE(_grid_functors_bounding_box, m) +{ + namespace py = pybind11; + + py::module::import("dune.xt.grid._grid_gridprovider_provider"); + py::module::import("dune.xt.grid._grid_functors_interfaces"); + + MinMaxCoordinateFunctor_for_all_grids<>::bind(m); +} diff --git a/python/dune/xt/grid/functors/interfaces.cc b/python/dune/xt/grid/functors/interfaces.cc new file mode 100644 index 0000000000000000000000000000000000000000..f78e9cdd4a0c99da7ef0c0dd143adb2e75a6d580 --- /dev/null +++ b/python/dune/xt/grid/functors/interfaces.cc @@ -0,0 +1,73 @@ +// This file is part of the dune-xt project: +// https://github.com/dune-community/dune-xt +// Copyright 2009-2018 dune-xt 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/xt/grid/grids.hh> + +#include "interfaces.hh" + + +template <class GridTypes = Dune::XT::Grid::AvailableGridTypes> +struct ElementFunctor_for_all_grids +{ + static void bind(pybind11::module& m) + { + Dune::XT::Grid::bindings::ElementFunctor<typename GridTypes::head_type>::bind(m); + ElementFunctor_for_all_grids<typename GridTypes::tail_type>::bind(m); + } +}; + +template <> +struct ElementFunctor_for_all_grids<boost::tuples::null_type> +{ + static void bind(pybind11::module& /*m*/) {} +}; + + +template <class GridTypes = Dune::XT::Grid::AvailableGridTypes> +struct IntersectionFunctor_for_all_grids +{ + static void bind(pybind11::module& m) + { + Dune::XT::Grid::bindings::IntersectionFunctor<typename GridTypes::head_type>::bind(m); + IntersectionFunctor_for_all_grids<typename GridTypes::tail_type>::bind(m); + } +}; + +template <> +struct IntersectionFunctor_for_all_grids<boost::tuples::null_type> +{ + static void bind(pybind11::module& /*m*/) {} +}; + + +template <class GridTypes = Dune::XT::Grid::AvailableGridTypes> +struct ElementAndIntersectionFunctor_for_all_grids +{ + static void bind(pybind11::module& m) + { + Dune::XT::Grid::bindings::ElementAndIntersectionFunctor<typename GridTypes::head_type>::bind(m); + ElementAndIntersectionFunctor_for_all_grids<typename GridTypes::tail_type>::bind(m); + } +}; + +template <> +struct ElementAndIntersectionFunctor_for_all_grids<boost::tuples::null_type> +{ + static void bind(pybind11::module& /*m*/) {} +}; + + +PYBIND11_MODULE(_grid_functors_interfaces, m) +{ + ElementFunctor_for_all_grids<>::bind(m); + IntersectionFunctor_for_all_grids<>::bind(m); + ElementAndIntersectionFunctor_for_all_grids<>::bind(m); +} diff --git a/python/dune/xt/grid/functors/interfaces.hh b/python/dune/xt/grid/functors/interfaces.hh new file mode 100644 index 0000000000000000000000000000000000000000..ea545a6a7b86e63bda80c63f32311e6e222a93ce --- /dev/null +++ b/python/dune/xt/grid/functors/interfaces.hh @@ -0,0 +1,105 @@ +// This file is part of the dune-xt project: +// https://github.com/dune-community/dune-xt +// Copyright 2009-2018 dune-xt 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) + +#ifndef PYTHON_DUNE_XT_GRID_FUNCTORS_INTERFACES_HH +#define PYTHON_DUNE_XT_GRID_FUNCTORS_INTERFACES_HH + +#include <dune/pybindxi/pybind11.h> + +#include <dune/xt/common/string.hh> +#include <dune/xt/grid/functors/interfaces.hh> +#include <dune/xt/grid/grids.hh> +#include <dune/xt/grid/gridprovider/provider.hh> +#include <python/dune/xt/common/timedlogging.hh> +#include <python/dune/xt/grid/grids.bindings.hh> + +namespace Dune { +namespace XT { +namespace Grid { +namespace bindings { + + +template <class G> +class ElementFunctor +{ + static_assert(is_grid<G>::value, ""); + using GV = typename G::LeafGridView; + +public: + using type = Grid::ElementFunctor<GV>; + using bound_type = pybind11::class_<type>; + + static bound_type bind(pybind11::module& m, + const std::string& class_id = "element_functor", + const std::string& grid_id = grid_name<G>::value()) + { + auto ClassName = Common::to_camel_case(class_id + "_" + grid_id); + bound_type c(m, ClassName.c_str(), ClassName.c_str()); + c.def_readwrite("logger", &type::logger); + c.def("prepare", [](type& self) { self.prepare(); }); + c.def("finalize", [](type& self) { self.finalize(); }); + return c; + } +}; // class ElementFunctor + + +template <class G> +class IntersectionFunctor +{ + static_assert(is_grid<G>::value, ""); + using GV = typename G::LeafGridView; + +public: + using type = Grid::IntersectionFunctor<GV>; + using bound_type = pybind11::class_<type>; + + static bound_type bind(pybind11::module& m, + const std::string& class_id = "intersection_functor", + const std::string& grid_id = grid_name<G>::value()) + { + auto ClassName = Common::to_camel_case(class_id + "_" + grid_id); + bound_type c(m, ClassName.c_str(), ClassName.c_str()); + c.def_readwrite("logger", &type::logger); + c.def("prepare", [](type& self) { self.prepare(); }); + c.def("finalize", [](type& self) { self.finalize(); }); + return c; + } +}; // class IntersectionFunctor + + +template <class G> +class ElementAndIntersectionFunctor +{ + static_assert(is_grid<G>::value, ""); + using GV = typename G::LeafGridView; + +public: + using type = Grid::ElementAndIntersectionFunctor<GV>; + using bound_type = pybind11::class_<type>; + + static bound_type bind(pybind11::module& m, + const std::string& class_id = "element_and_intersection_functor", + const std::string& grid_id = grid_name<G>::value()) + { + auto ClassName = Common::to_camel_case(class_id + "_" + grid_id); + bound_type c(m, ClassName.c_str(), ClassName.c_str()); + c.def_readwrite("logger", &type::logger); + c.def("prepare", [](type& self) { self.prepare(); }); + c.def("finalize", [](type& self) { self.finalize(); }); + return c; + } +}; // class ElementAndIntersectionFunctor + + +} // namespace bindings +} // namespace Grid +} // namespace XT +} // namespace Dune + +#endif // PYTHON_DUNE_XT_GRID_FUNCTORS_INTERFACES_HH diff --git a/python/dune/xt/grid/functors/refinement.cc b/python/dune/xt/grid/functors/refinement.cc new file mode 100644 index 0000000000000000000000000000000000000000..4132a1c3e841fd8a7bed067e4a68aa2c4107d697 --- /dev/null +++ b/python/dune/xt/grid/functors/refinement.cc @@ -0,0 +1,101 @@ +// This file is part of the dune-xt project: +// https://github.com/dune-community/dune-xt +// Copyright 2009-2018 dune-xt 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/xt/grid/functors/refinement.hh> + +#include "interfaces.hh" + + +namespace Dune { +namespace XT { +namespace Grid { +namespace bindings { + + +template <class G> +class MaximumEntityVolumeRefineFunctorFunctor +{ + static_assert(is_grid<G>::value, ""); + using GV = typename G::LeafGridView; + using I = extract_intersection_t<GV>; + +public: + using type = Grid::MaximumEntityVolumeRefineFunctorFunctor<GV>; + using base_type = Grid::ElementFunctor<GV>; + using bound_type = pybind11::class_<type, base_type>; + + static bound_type bind(pybind11::module& m, + const std::string& class_id = "maximum_element_volume_refine_functor", + const std::string& grid_id = grid_name<G>::value()) + { + namespace py = pybind11; + using namespace pybind11::literals; + + auto ClassId = Common::to_camel_case(class_id); + auto ClassName = Common::to_camel_case(class_id + "_" + grid_id); + bound_type c(m, ClassName.c_str(), std::string(ClassId + "( " + grid_id + " variant)").c_str()); + c.def(py::init([](GridProvider<G>& grid_provider, const double& volume) { + return std::make_unique<type>(grid_provider.grid(), volume, 1.); + }), + "grid_provider"_a, + "volume"_a, + py::keep_alive<0, 1>()); + c.def("__repr__", [ClassId](type&) { return ClassId + "(grid_provider=\?\?\?, volume=\?\?\?)"; }); + c.def_property_readonly("result", [](const type& self) { return self.result(); }); + + m.def(ClassId.c_str(), + [](GridProvider<G>& grid_provider, const double& volume) { + return std::make_unique<type>(grid_provider.grid(), volume, 1.); + }, + "grid_provider"_a, + "volume"_a, + py::keep_alive<0, 1>()); + + return c; + } // ... bind(...) +}; // class MaximumEntityVolumeRefineFunctorFunctor + + +} // namespace bindings +} // namespace Grid +} // namespace XT +} // namespace Dune + + +template <class GridTypes = Dune::XT::Grid::AvailableGridTypes> +struct MaximumEntityVolumeRefineFunctorFunctor_for_all_grids +{ + static void bind(pybind11::module& m) + { + Dune::XT::Grid::bindings::MaximumEntityVolumeRefineFunctorFunctor<typename GridTypes::head_type>::bind(m); + MaximumEntityVolumeRefineFunctorFunctor_for_all_grids<typename GridTypes::tail_type>::bind(m); + } +}; + +template <> +struct MaximumEntityVolumeRefineFunctorFunctor_for_all_grids<boost::tuples::null_type> +{ + static void bind(pybind11::module& /*m*/) {} +}; + + +PYBIND11_MODULE(_grid_functors_refinement, m) +{ + namespace py = pybind11; + + py::module::import("dune.xt.grid._grid_boundaryinfo_interfaces"); + py::module::import("dune.xt.grid._grid_boundaryinfo_types"); + py::module::import("dune.xt.grid._grid_gridprovider_provider"); + py::module::import("dune.xt.grid._grid_functors_interfaces"); + + MaximumEntityVolumeRefineFunctorFunctor_for_all_grids<>::bind(m); +}