From 8bdc2a7af2fe18fb962a724a442475dc2ba64e49 Mon Sep 17 00:00:00 2001 From: Alexander Grayver Date: Wed, 12 Feb 2020 16:32:52 +0100 Subject: [PATCH] Add python binding for TriaAccessor::centre --- .../include/tria_accessor_wrapper.h | 7 ++++ .../source/export_tria_accessor.cc | 9 ++++- .../source/tria_accessor_wrapper.cc | 40 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/contrib/python-bindings/include/tria_accessor_wrapper.h b/contrib/python-bindings/include/tria_accessor_wrapper.h index ebdd8aa152..71411552f3 100644 --- a/contrib/python-bindings/include/tria_accessor_wrapper.h +++ b/contrib/python-bindings/include/tria_accessor_wrapper.h @@ -54,6 +54,13 @@ namespace python PointWrapper get_barycenter() const; + /** + * Get the center of the cell. + */ + PointWrapper + get_center(const bool respect_manifold = false, + const bool interpolate_from_surrounding = false) const; + /** * Set the ith vertex of the cell to @p point_wrapper. */ diff --git a/contrib/python-bindings/source/export_tria_accessor.cc b/contrib/python-bindings/source/export_tria_accessor.cc index 37b315d665..958f720c86 100644 --- a/contrib/python-bindings/source/export_tria_accessor.cc +++ b/contrib/python-bindings/source/export_tria_accessor.cc @@ -22,6 +22,8 @@ DEAL_II_NAMESPACE_OPEN namespace python { + BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(get_center_overloads, get_center, 0, 2) + const char manifold_id_docstring[] = "Get/Set the manifold_id of the face \n"; @@ -70,8 +72,11 @@ namespace python boost::python::args("self")) .def("center", &TriaAccessorWrapper::get_center, - barycenter_docstring, - boost::python::args("self")) + get_center_overloads( + boost::python::args("self", + "respect_manifold", + "interpolate_from_surrounding"), + center_docstring)) .def("set_vertex", &TriaAccessorWrapper::set_vertex, set_vertex_docstring, diff --git a/contrib/python-bindings/source/tria_accessor_wrapper.cc b/contrib/python-bindings/source/tria_accessor_wrapper.cc index 196daad426..bf80661dfa 100644 --- a/contrib/python-bindings/source/tria_accessor_wrapper.cc +++ b/contrib/python-bindings/source/tria_accessor_wrapper.cc @@ -42,6 +42,26 @@ namespace python + template + PointWrapper + get_center(const bool respect_manifold, + const bool interpolate_from_surrounding, + const void *tria_accessor) + { + const TriaAccessor *accessor = + static_cast *>( + tria_accessor); + Point center = + accessor->center(respect_manifold, interpolate_from_surrounding); + boost::python::list center_list; + for (int i = 0; i < spacedim; ++i) + center_list.append(center[i]); + + return PointWrapper(center_list); + } + + + template void set_boundary_id(const int boundary_id, void *tria_accessor) @@ -241,6 +261,26 @@ namespace python + PointWrapper + TriaAccessorWrapper::get_center(const bool respect_manifold, + const bool interpolate_from_surrounding) const + { + if ((dim == 2) && (spacedim == 2) && (structdim == 1)) + return internal::get_center<1, 2, 2>(respect_manifold, + interpolate_from_surrounding, + tria_accessor); + else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) + return internal::get_center<1, 2, 3>(respect_manifold, + interpolate_from_surrounding, + tria_accessor); + else + return internal::get_center<2, 3, 3>(respect_manifold, + interpolate_from_surrounding, + tria_accessor); + } + + + void TriaAccessorWrapper::set_boundary_id(const int boundary_id) { -- 2.39.5