Skip to content
Snippets Groups Projects
Commit 433ce454 authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[python|grid.functors] add bindings

Bindings for bounding box and refinement have to be enabled after the
respective functors have been fixed.
parent 5cbfd01d
No related branches found
No related tags found
2 merge requests!20Update bindings,!11WIP: Update bindings
......@@ -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)
......
......@@ -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',
......
// 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);
}
// 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);
}
// 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);
}
// 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
// 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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment