]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add wrappers for simplex related functions.
authorAlexander Grayver <agrayver@erdw.ethz.ch>
Fri, 15 Jan 2021 17:28:14 +0000 (18:28 +0100)
committerAlexander Grayver <agrayver@erdw.ethz.ch>
Wed, 20 Jan 2021 11:19:43 +0000 (12:19 +0100)
contrib/python-bindings/include/cell_accessor_wrapper.h
contrib/python-bindings/include/tria_accessor_wrapper.h
contrib/python-bindings/include/triangulation_wrapper.h
contrib/python-bindings/source/cell_accessor_wrapper.cc
contrib/python-bindings/source/export_cell_accessor.cc
contrib/python-bindings/source/export_triangulation.cc
contrib/python-bindings/source/tria_accessor_wrapper.cc
contrib/python-bindings/source/triangulation_wrapper.cc

index 40d43155b8d18d269163721b90849ece8cbe3e03..bf10570a37f7fb49f1402ce2c01ed9b560de09d7 100644 (file)
@@ -184,6 +184,21 @@ namespace python
     unsigned int
     vertex_index(const unsigned int i) const;
 
+    /*! @copydoc TriaAccessor::n_vertices
+     */
+    unsigned int
+    n_vertices() const;
+
+    /*! @copydoc TriaAccessor::n_lines
+     */
+    unsigned int
+    n_lines() const;
+
+    /*! @copydoc TriaAccessor::n_faces
+     */
+    unsigned int
+    n_faces() const;
+
     /**
      * Exception.
      */
index 5e56282e72f6907e87d0cf765388c6d222284190..ecb8e4720eb6ea926f13529b5d1f896a320457c8 100644 (file)
@@ -105,6 +105,21 @@ namespace python
     double
     measure() const;
 
+    /*! @copydoc TriaAccessor::n_vertices
+     */
+    unsigned int
+    n_vertices() const;
+
+    /*! @copydoc TriaAccessor::n_lines
+     */
+    unsigned int
+    n_lines() const;
+
+    /*! @copydoc TriaAccessor::n_faces
+     */
+    unsigned int
+    n_faces() const;
+
     /**
      * Exception.
      */
index 552a5735d73f305d7276f48cb3e183775d125ada..17e04bad515bb78f62ff3efcbccfff8a7f96ea84 100644 (file)
@@ -274,6 +274,11 @@ namespace python
     void
     transform(boost::python::object &transformation);
 
+    /*! @copydoc GridGenerator::convert_hypercube_to_simplex_mesh
+     */
+    void
+    convert_hypercube_to_simplex_mesh(TriangulationWrapper &tria_out);
+
     /*! @copydoc GridTools::find_active_cell_around_point
      */
     CellAccessorWrapper
index 7470d5da09b3f5944485556bb4d914e3f3e719c7..4d9dfc71141e14e9056479f9908cd96a65199bed 100644 (file)
@@ -756,6 +756,45 @@ namespace python
       return internal::cell_cast<3, 3>(cell_accessor)->vertex_index(i);
   }
 
+
+
+  unsigned int
+  CellAccessorWrapper::n_vertices() const
+  {
+    if ((dim == 2) && (spacedim == 2))
+      return internal::cell_cast<2, 2>(cell_accessor)->n_vertices();
+    else if ((dim == 2) && (spacedim == 3))
+      return internal::cell_cast<2, 3>(cell_accessor)->n_vertices();
+    else
+      return internal::cell_cast<3, 3>(cell_accessor)->n_vertices();
+  }
+
+
+
+  unsigned int
+  CellAccessorWrapper::n_lines() const
+  {
+    if ((dim == 2) && (spacedim == 2))
+      return internal::cell_cast<2, 2>(cell_accessor)->n_lines();
+    else if ((dim == 2) && (spacedim == 3))
+      return internal::cell_cast<2, 3>(cell_accessor)->n_lines();
+    else
+      return internal::cell_cast<3, 3>(cell_accessor)->n_lines();
+  }
+
+
+
+  unsigned int
+  CellAccessorWrapper::n_faces() const
+  {
+    if ((dim == 2) && (spacedim == 2))
+      return internal::cell_cast<2, 2>(cell_accessor)->n_faces();
+    else if ((dim == 2) && (spacedim == 3))
+      return internal::cell_cast<2, 3>(cell_accessor)->n_faces();
+    else
+      return internal::cell_cast<3, 3>(cell_accessor)->n_faces();
+  }
+
 } // namespace python
 
 DEAL_II_NAMESPACE_CLOSE
index 67f6ff59e0fa365ac61437b4bd547e29fa8fd78c..b14b212a60508f1859977a23a722e69f53b09355 100644 (file)
@@ -150,6 +150,21 @@ namespace python
     " for activity of a cell).                                           \n";
 
 
+
+  const char n_vertices_docstring[] =
+    " Number of vertices.                                                \n";
+
+
+
+  const char n_lines_docstring[] =
+    " Number of lines.                                                   \n";
+
+
+
+  const char n_faces_docstring[] =
+    " Number of faces.                                                   \n";
+
+
   void
   export_cell_accessor()
   {
@@ -238,7 +253,19 @@ namespace python
       .def("vertex_index",
            &CellAccessorWrapper::vertex_index,
            vertex_index_docstring,
-           boost::python::args("self", "vertex"));
+           boost::python::args("self", "vertex"))
+      .def("n_vertices",
+           &CellAccessorWrapper::n_vertices,
+           n_vertices_docstring,
+           boost::python::args("self"))
+      .def("n_lines",
+           &CellAccessorWrapper::n_lines,
+           n_lines_docstring,
+           boost::python::args("self"))
+      .def("n_faces",
+           &CellAccessorWrapper::n_faces,
+           n_faces_docstring,
+           boost::python::args("self"));
   }
 } // namespace python
 
index e23f7c4f238c7ecebdef403d80b86cbef48a835d..2690303d464a7f2dc78e36d651f77e71a9ffc436 100644 (file)
@@ -479,6 +479,13 @@ namespace python
     "Return the diameter of the largest active cell of a triangulation.    \n";
 
 
+
+  const char convert_hypercube_to_simplex_mesh_docstring[] =
+    "Convert a triangulation consisting only of hypercube cells            \n"
+    "(quadrilaterals, hexahedra) to a triangulation only consisting of     \n"
+    "simplices (triangles, tetrahedra).                                    \n";
+
+
   void
   export_triangulation()
   {
@@ -665,6 +672,10 @@ namespace python
            &TriangulationWrapper::transform,
            transform_docstring,
            boost::python::args("self", "transformation"))
+      .def("convert_hypercube_to_simplex_mesh",
+           &TriangulationWrapper::convert_hypercube_to_simplex_mesh,
+           convert_hypercube_to_simplex_mesh_docstring,
+           boost::python::args("self", "tria_out"))
       .def("find_active_cell_around_point",
            &TriangulationWrapper::find_active_cell_around_point,
            find_active_cell_around_point_overloads(
index 526d3fdc6d9454286dd23e9d22128e9a056c1805..eebd472ff4e02cbe77607712ed2d458f546faf4b 100644 (file)
@@ -171,6 +171,14 @@ namespace python
           tria_accessor);
       return accessor->measure();
     }
+
+    template <int structdim, int dim, int spacedim>
+    const TriaAccessor<structdim, dim, spacedim> *
+    tria_accessor_cast(const void *tria_accessor)
+    {
+      return static_cast<const TriaAccessor<structdim, dim, spacedim> *>(
+        tria_accessor);
+    }
   } // namespace internal
 
 
@@ -400,6 +408,45 @@ namespace python
       return internal::measure<2, 3, 3>(tria_accessor);
   }
 
+
+
+  unsigned int
+  TriaAccessorWrapper::n_vertices() const
+  {
+    if ((dim == 2) && (spacedim == 2) && (structdim == 1))
+      return internal::tria_accessor_cast<1, 2, 2>(tria_accessor)->n_vertices();
+    else if ((dim == 2) && (spacedim == 3) && (structdim == 1))
+      return internal::tria_accessor_cast<1, 2, 3>(tria_accessor)->n_vertices();
+    else
+      return internal::tria_accessor_cast<2, 3, 3>(tria_accessor)->n_vertices();
+  }
+
+
+
+  unsigned int
+  TriaAccessorWrapper::n_lines() const
+  {
+    if ((dim == 2) && (spacedim == 2) && (structdim == 1))
+      return internal::tria_accessor_cast<1, 2, 2>(tria_accessor)->n_lines();
+    else if ((dim == 2) && (spacedim == 3) && (structdim == 1))
+      return internal::tria_accessor_cast<1, 2, 3>(tria_accessor)->n_lines();
+    else
+      return internal::tria_accessor_cast<2, 3, 3>(tria_accessor)->n_lines();
+  }
+
+
+
+  unsigned int
+  TriaAccessorWrapper::n_faces() const
+  {
+    if ((dim == 2) && (spacedim == 2) && (structdim == 1))
+      return internal::tria_accessor_cast<1, 2, 2>(tria_accessor)->n_faces();
+    else if ((dim == 2) && (spacedim == 3) && (structdim == 1))
+      return internal::tria_accessor_cast<1, 2, 3>(tria_accessor)->n_faces();
+    else
+      return internal::tria_accessor_cast<2, 3, 3>(tria_accessor)->n_faces();
+  }
+
 } // namespace python
 
 DEAL_II_NAMESPACE_CLOSE
index ca8b7673bd82be5132cce0d8e5e48b8358f97bfb..511df8b73698cc3645a63ce9eea3c462e832094d 100644 (file)
@@ -555,6 +555,21 @@ namespace python
 
 
 
+    template <int dim, int spacedim>
+    void
+    convert_hypercube_to_simplex_mesh(void *                triangulation,
+                                      TriangulationWrapper &tria_out)
+    {
+      Triangulation<dim, spacedim> *tria =
+        static_cast<Triangulation<dim, spacedim> *>(triangulation);
+      Triangulation<dim, spacedim> *tria_2 =
+        static_cast<Triangulation<dim, spacedim> *>(
+          tria_out.get_triangulation());
+      GridGenerator::convert_hypercube_to_simplex_mesh(*tria, *tria_2);
+    }
+
+
+
     template <int dim, int spacedim>
     void
     replicate_triangulation(TriangulationWrapper &     tria_in,
@@ -1534,6 +1549,25 @@ namespace python
   }
 
 
+  void
+  TriangulationWrapper::convert_hypercube_to_simplex_mesh(
+    TriangulationWrapper &tria_out)
+  {
+    AssertThrow(
+      (tria_out.get_dim() == dim) && (tria_out.get_spacedim() == spacedim),
+      ExcMessage("The output Triangulation must be of the same dimension"));
+
+    if ((dim == 2) && (spacedim == 2))
+      internal::convert_hypercube_to_simplex_mesh<2, 2>(triangulation,
+                                                        tria_out);
+    else if ((dim == 2) && (spacedim == 3))
+      internal::convert_hypercube_to_simplex_mesh<2, 3>(triangulation,
+                                                        tria_out);
+    else
+      internal::convert_hypercube_to_simplex_mesh<3, 3>(triangulation,
+                                                        tria_out);
+  }
+
 
   void
   TriangulationWrapper::extrude_triangulation(
@@ -1978,6 +2012,7 @@ namespace python
     else
       AssertThrow(false, ExcMessage("Dimension needs to be 2D or 3D."));
   }
+
 } // namespace python
 
 DEAL_II_NAMESPACE_CLOSE

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.