Skip to content
Snippets Groups Projects
Commit 661cb377 authored by René Fritze's avatar René Fritze Committed by René Milk
Browse files

[py] refactor boundary_info binding

this completely eridactes multi-stage macros
parent a5f876a6
No related branches found
No related tags found
No related merge requests found
......@@ -12,25 +12,90 @@
#include <string>
#include <vector>
#include <utility>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/pybindxi/pybind11.h>
#include <dune/pybindxi/stl.h>
#include <dune/xt/grid/dd/subdomains/grid.hh>
#include <dune/xt/common/tuple.hh>
#include <python/dune/xt/common/exceptions.bindings.hh>
#include <python/dune/xt/common/bindings.hh>
#include <python/dune/xt/grid/boundaryinfo.bindings.hh>
#include <python/dune/xt/grid/available_types.hh>
using namespace Dune::XT::Common;
using namespace Dune::XT::Grid;
using InfoTypes = template_tuple<tplwrap<AllDirichletBoundaryInfo>,
tplwrap<AllNeumannBoundaryInfo>,
tplwrap<BoundarySegmentIndexBasedBoundaryInfo>,
tplwrap<NormalBasedBoundaryInfo>>;
const std::array<std::string, 4> info_names{"all_dirichlet_boundary_info",
"all_neumann_boundary_info",
"boundary_segment_index_based_boundary_info",
"normal_based_boundary_info"};
constexpr std::array<Layers, 6> layers{Layers::leaf,
Layers::level,
Layers::dd_subdomain,
Layers::dd_subdomain_oversampled,
Layers::dd_subdomain_boundary,
Layers::dd_subdomain_coupling};
template <class Grid, Layers layer, class InfoTuple = InfoTypes>
struct bind_grid_layer_info
{
static void bind(pybind11::module& m, size_t info_name_no = 0)
{
using I = extract_intersection_t<
typename Dune::XT::Grid::
Layer<Grid, layer, Dune::XT::Grid::Backends::view, Dune::XT::Grid::DD::SubdomainGrid<Grid>>::type>;
using Info = typename InfoTuple::template head_type<I>;
using binder = Dune::XT::Grid::bindings::BoundaryInfo<Info, Grid, layer>;
binder::bind(m, info_names[info_name_no], layer_names[layer]);
using Tail = typename InfoTuple::template tail_type<I>;
bind_grid_layer_info<Grid, layer, Tail>::bind(m, ++info_name_no);
}
};
template <class Grid, Layers l>
struct bind_grid_layer_info<Grid, l, null_template_tuple>
{
static void bind(pybind11::module&, size_t)
{
}
};
template <class>
void bind_grid_layer(pybind11::module& m, std::integral_constant<size_t, 0>){};
template <class Grid, size_t counter>
void bind_grid_layer(pybind11::module& m, std::integral_constant<size_t, counter>)
{
bind_grid_layer_info<Grid, layers[counter - 1]>::bind(m);
bind_grid_layer<Grid>(m, std::integral_constant<size_t, counter - 1>());
};
template <class GridTuple = Dune::XT::Grid::bindings::AvailableTypes>
void bind_grid(pybind11::module& m)
{
using Grid = typename GridTuple::head_type;
bind_grid_layer<Grid>(m, std::integral_constant<size_t, layers.size()>());
bind_grid<typename GridTuple::tail_type>(m);
}
template <>
void bind_grid<boost::tuples::null_type>(pybind11::module& m)
{
}
PYBIND11_MODULE(_boundaryinfo, m)
{
namespace py = pybind11;
using namespace pybind11::literals;
DUNE_XT_GRID_BOUNDARYINFO_BIND(m);
bind_grid(m);
}
DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(template);
\ No newline at end of file
......@@ -140,143 +140,4 @@ public:
} // namespace XT
} // namespace Dune
// begin: this is what we need for the lib
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, _G, _layer, _backend) \
prefix class Dune::XT::Grid::bindings:: \
BoundaryInfo<_B<Dune::XT::Grid::extract_intersection_t< \
typename Dune::XT::Grid::Layer<_G, \
Dune::XT::Grid::Layers::_layer, \
Dune::XT::Grid::Backends::_backend, \
Dune::XT::Grid::DD::SubdomainGrid<_G>>::type>>, \
_G, \
Dune::XT::Grid::Layers::_layer>
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_YASP(prefix, _B) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, YASP_1D_EQUIDISTANT_OFFSET, leaf, view); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, YASP_2D_EQUIDISTANT_OFFSET, leaf, view); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, YASP_1D_EQUIDISTANT_OFFSET, dd_subdomain, view); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, YASP_2D_EQUIDISTANT_OFFSET, dd_subdomain, view)
#if HAVE_DUNE_ALUGRID
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_ALU(prefix, _B) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, ALU_2D_SIMPLEX_CONFORMING, leaf, view); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, ALU_2D_SIMPLEX_CONFORMING, level, view)
/* _DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, ALU_2D_SIMPLEX_CONFORMING, dd_subdomain, view); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, ALU_2D_SIMPLEX_CONFORMING, dd_subdomain_boundary, view)*/
#else // HAVE_DUNE_ALUGRID
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_ALU(prefix, _B) static_assert(true, "Require semicolon to disable warnings")
#endif
/*#if HAVE_DUNE_UGGRID || HAVE_UG
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_UG(prefix, _B) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, UG_2D, leaf, view); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, UG_2D, level, view); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, UG_2D, dd_subdomain, view)
#else*/
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_UG(prefix, _B) static_assert(true, "Require semicolon to disable warnings")
//#endif
/*#if HAVE_ALBERTA
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_ALBERTA(prefix, _B) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, ALBERTA_2D, leaf, view); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix, _B, ALBERTA_2D, dd_subdomain, view)
#else*/
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_ALBERTA(prefix, _B) \
static_assert(true, "Require semicolon to disable warnings")
//#endif
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_ALL(prefix, _B) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_YASP(prefix, _B); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_UG(prefix, _B); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_ALBERTA(prefix, _B); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_ALU(prefix, _B)
#define DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(prefix) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_ALL(prefix, Dune::XT::Grid::AllDirichletBoundaryInfo); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_ALL(prefix, Dune::XT::Grid::AllNeumannBoundaryInfo); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_ALL(prefix, Dune::XT::Grid::BoundarySegmentIndexBasedBoundaryInfo); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB_ALL(prefix, Dune::XT::Grid::NormalBasedBoundaryInfo)
DUNE_XT_GRID_BOUNDARYINFO_BIND_LIB(extern template);
// end: this is what we need for the lib
// begin: this is what we need for the .so
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND(_m, _B, _G, _layer, _backend, _class_name, _layer_name) \
Dune::XT::Grid::bindings:: \
BoundaryInfo<_B<Dune::XT::Grid::extract_intersection_t< \
typename Dune::XT::Grid::Layer<_G, \
Dune::XT::Grid::Layers::_layer, \
Dune::XT::Grid::Backends::_backend, \
Dune::XT::Grid::DD::SubdomainGrid<_G>>::type>>, \
_G, \
Dune::XT::Grid::Layers::_layer>::bind(_m, _class_name, _layer_name)
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_YASP(_m, _B, _class_name) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND(_m, _B, YASP_1D_EQUIDISTANT_OFFSET, leaf, view, _class_name, ""); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND( \
_m, _B, YASP_1D_EQUIDISTANT_OFFSET, dd_subdomain, view, _class_name, "dd_subdomain"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND( \
_m, _B, YASP_1D_EQUIDISTANT_OFFSET, dd_subdomain_boundary, view, _class_name, "dd_subdomain_boundary"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND( \
_m, _B, YASP_1D_EQUIDISTANT_OFFSET, dd_subdomain_coupling, view, _class_name, "dd_subdomain_coupling"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND(_m, _B, YASP_2D_EQUIDISTANT_OFFSET, leaf, view, _class_name, ""); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND( \
_m, _B, YASP_2D_EQUIDISTANT_OFFSET, dd_subdomain, view, _class_name, "dd_subdomain"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND( \
_m, _B, YASP_2D_EQUIDISTANT_OFFSET, dd_subdomain_boundary, view, _class_name, "dd_subdomain_boundary"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND( \
_m, _B, YASP_2D_EQUIDISTANT_OFFSET, dd_subdomain_coupling, view, _class_name, "dd_subdomain_coupling")
#if HAVE_DUNE_ALUGRID
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_ALU(_m, _B, _class_name) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND(_m, _B, ALU_2D_SIMPLEX_CONFORMING, leaf, view, _class_name, "leaf"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND(_m, _B, ALU_2D_SIMPLEX_CONFORMING, level, view, _class_name, "level"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND(_m, _B, ALU_2D_SIMPLEX_CONFORMING, dd_subdomain, view, _class_name, "dd_subdomain"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND( \
_m, _B, ALU_2D_SIMPLEX_CONFORMING, dd_subdomain_boundary, view, _class_name, "dd_subdomain_boundary"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND( \
_m, _B, ALU_2D_SIMPLEX_CONFORMING, dd_subdomain_coupling, view, _class_name, "dd_subdomain_coupling")
#else
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_ALU(_m, _B, _class_name)
#endif
/*#if HAVE_DUNE_UGGRID
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_UG(_m, _B, _class_name) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND(_m, _B, UG_2D, leaf, view, _class_name, "leaf"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND(_m, _B, UG_2D, level, view, _class_name, "level"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND(_m, _B, UG_2D, dd_subdomain, view, _class_name, "dd_subdomain")
#else*/
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_UG(_m, _B, _class_name)
//#endif
/*#if HAVE_ALBERTA
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_ALBERTA(_m, _B, _class_name) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND(_m, _B, ALBERTA_2D, leaf, view, _class_name, ""); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND(_m, _B, ALBERTA_2D, dd_subdomain, view, _class_name, "dd_subdomain")
#else*/
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_ALBERTA(_m, _B, _class_name)
//#endif
#define _DUNE_XT_GRID_BOUNDARYINFO_BIND_ALL(_m, _B, _class_name) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_YASP(_m, Dune::XT::Grid::_B, _class_name); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_UG(_m, Dune::XT::Grid::_B, _class_name); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_ALBERTA(_m, Dune::XT::Grid::_B, _class_name); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_ALU(_m, Dune::XT::Grid::_B, _class_name)
#define DUNE_XT_GRID_BOUNDARYINFO_BIND(_m) \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_ALL(_m, AllDirichletBoundaryInfo, "all_dirichlet_boundary_info"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_ALL(_m, AllNeumannBoundaryInfo, "all_neumann_boundary_info"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_ALL( \
_m, BoundarySegmentIndexBasedBoundaryInfo, "boundary_segment_index_based_boundary_info"); \
_DUNE_XT_GRID_BOUNDARYINFO_BIND_ALL(_m, NormalBasedBoundaryInfo, "normal_based_boundary_info")
// end: this is what we need for the .so
#endif // DUNE_XT_GRID_BOUNDARYINFO_BINDINGS_HH
......@@ -18,8 +18,6 @@
#include <dune/pybindxi/pybind11.h>
#include <dune/pybindxi/stl.h>
#include <python/dune/xt/common/exceptions.bindings.hh>
#include <dune/xt/grid/dd/subdomains/grid.hh>
#include <dune/xt/grid/grids.hh>
#include <dune/xt/grid/layers.hh>
......@@ -27,7 +25,6 @@
#include <python/dune/xt/common/bindings.hh>
#include <python/dune/xt/grid/grids.bindings.hh>
#include <python/dune/xt/grid/gridprovider.hh>
#include <python/dune/xt/grid/available_types.hh>
template <class Tuple = Dune::XT::Grid::bindings::AvailableTypes>
......
......@@ -13,17 +13,16 @@
#include <string>
#include <vector>
#include <boost/tuple/tuple.hpp>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/pybindxi/pybind11.h>
#include <dune/pybindxi/stl.h>
#include <python/dune/xt/grid/available_types.hh>
#include <python/dune/xt/grid/grids.bindings.hh>
#include <boost/tuple/tuple.hpp>
template <class Tuple = Dune::XT::Grid::bindings::AvailableTypes>
void addbind_for_Grid(pybind11::module& m, std::vector<std::string>& available_types)
{
......
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