]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add python binding for TriaAccessor::centre 9510/head
authorAlexander Grayver <agrayver@erdw.ethz.ch>
Wed, 12 Feb 2020 15:32:52 +0000 (16:32 +0100)
committerAlexander Grayver <agrayver@erdw.ethz.ch>
Wed, 12 Feb 2020 15:32:52 +0000 (16:32 +0100)
contrib/python-bindings/include/tria_accessor_wrapper.h
contrib/python-bindings/source/export_tria_accessor.cc
contrib/python-bindings/source/tria_accessor_wrapper.cc

index ebdd8aa152699c939fb13ef7f8317339905a90ae..71411552f3ca4ae2a2bd39589efde2fcd0ca99b4 100644 (file)
@@ -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.
      */
index 37b315d665ea31757d3bcde8a11eaf96e0651a29..958f720c861f65eac5d623096abf4a9e82563f70 100644 (file)
@@ -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,
index 196daad426d6a27a044600cb7f8af18b67b42121..bf80661dfa6ebb708cfc3333bfa6ac01cb631d88 100644 (file)
@@ -42,6 +42,26 @@ namespace python
 
 
 
+    template <int structdim, int dim, int spacedim>
+    PointWrapper
+    get_center(const bool  respect_manifold,
+               const bool  interpolate_from_surrounding,
+               const void *tria_accessor)
+    {
+      const TriaAccessor<structdim, dim, spacedim> *accessor =
+        static_cast<const TriaAccessor<structdim, dim, spacedim> *>(
+          tria_accessor);
+      Point<spacedim> 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 <int structdim, int dim, int spacedim>
     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)
   {

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.