]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add method for returning all triangulation cells 10885/head
authorAlexander Grayver <agrayver@erdw.ethz.ch>
Thu, 3 Sep 2020 14:06:41 +0000 (16:06 +0200)
committerAlexander Grayver <agrayver@erdw.ethz.ch>
Tue, 15 Sep 2020 10:40:02 +0000 (12:40 +0200)
contrib/python-bindings/include/triangulation_wrapper.h
contrib/python-bindings/source/export_triangulation.cc
contrib/python-bindings/source/triangulation_wrapper.cc
doc/news/changes/minor/20200903GrayverAlexander [new file with mode: 0644]

index 4d34e525bc4db3dcd62f3608146ba692ef9787fa..552a5735d73f305d7276f48cb3e183775d125ada 100644 (file)
@@ -72,6 +72,12 @@ namespace python
     unsigned int
     n_active_cells() const;
 
+    /**
+     * Return the number of cells.
+     */
+    unsigned int
+    n_cells() const;
+
     /*! @copydoc GridGenerator::hyper_cube
      */
     void
@@ -307,6 +313,13 @@ namespace python
     boost::python::list
     active_cells();
 
+    /**
+     * Return the list of cell accessors associated to the underlying
+     * Triangulation.
+     */
+    boost::python::list
+    cells();
+
     /*! @copydoc GridTools::minimal_cell_diameter
      */
     double
index 14b9163e735d9fb35027f79452a0d32ce22d960b..e23f7c4f238c7ecebdef403d80b86cbef48a835d 100644 (file)
@@ -121,6 +121,11 @@ namespace python
 
 
 
+  const char n_cells_docstring[] =
+    "Return the number of cells.                                            \n";
+
+
+
   const char dim_docstring[] =
     "Return the dimension of the Triangulation                              \n";
 
@@ -389,6 +394,11 @@ namespace python
 
 
 
+  const char cells_docstring[] =
+    "Return the list of cell accessors of the Triangulation.                \n";
+
+
+
   const char write_docstring[] =
     "Write the mesh to the output file according to the given data format.  \n"
     "The possible formats are:                                              \n"
@@ -493,6 +503,10 @@ namespace python
            &TriangulationWrapper::n_active_cells,
            n_active_cells_docstring,
            boost::python::args("self"))
+      .def("n_cells",
+           &TriangulationWrapper::n_cells,
+           n_cells_docstring,
+           boost::python::args("self"))
       .def("minimal_cell_diameter",
            &TriangulationWrapper::minimal_cell_diameter,
            minimal_cell_diameter_docstring,
@@ -676,6 +690,10 @@ namespace python
            &TriangulationWrapper::active_cells,
            active_cells_docstring,
            boost::python::args("self"))
+      .def("cells",
+           &TriangulationWrapper::cells,
+           cells_docstring,
+           boost::python::args("self"))
       .def("write",
            &TriangulationWrapper::write,
            write_docstring,
index 019b79dc60001705295e2a00deb7621df1e1cda6..ca8b7673bd82be5132cce0d8e5e48b8358f97bfb 100644 (file)
@@ -724,6 +724,24 @@ namespace python
 
 
 
+    template <int dim, int spacedim>
+    boost::python::list
+    cells(TriangulationWrapper &triangulation_wrapper)
+    {
+      Triangulation<dim, spacedim> *tria =
+        static_cast<Triangulation<dim, spacedim> *>(
+          triangulation_wrapper.get_triangulation());
+      boost::python::list cells_list;
+      for (auto &cell : tria->cell_iterators())
+        cells_list.append(CellAccessorWrapper(triangulation_wrapper,
+                                              cell->level(),
+                                              cell->index()));
+
+      return cells_list;
+    }
+
+
+
     template <int dim, int spacedim>
     double
     maximal_cell_diameter(const void *triangulation)
@@ -889,6 +907,19 @@ namespace python
 
 
 
+  unsigned int
+  TriangulationWrapper::n_cells() const
+  {
+    if ((dim == 2) && (spacedim == 2))
+      return (*static_cast<Triangulation<2, 2> *>(triangulation)).n_cells();
+    else if ((dim == 2) && (spacedim == 3))
+      return (*static_cast<Triangulation<2, 3> *>(triangulation)).n_cells();
+    else
+      return (*static_cast<Triangulation<3, 3> *>(triangulation)).n_cells();
+  }
+
+
+
   void
   TriangulationWrapper::create_triangulation(
     const boost::python::list &vertices,
@@ -1832,6 +1863,19 @@ namespace python
 
 
 
+  boost::python::list
+  TriangulationWrapper::cells()
+  {
+    if ((dim == 2) && (spacedim == 2))
+      return internal::cells<2, 2>(*this);
+    else if ((dim == 2) && (spacedim == 3))
+      return internal::cells<2, 3>(*this);
+    else
+      return internal::cells<3, 3>(*this);
+  }
+
+
+
   void
   TriangulationWrapper::set_manifold(const int        number,
                                      ManifoldWrapper &manifold)
diff --git a/doc/news/changes/minor/20200903GrayverAlexander b/doc/news/changes/minor/20200903GrayverAlexander
new file mode 100644 (file)
index 0000000..212342d
--- /dev/null
@@ -0,0 +1,3 @@
+Added: method for returning list of all triangulation cells.
+<br>
+(Alexander Grayver, 2020/09/03)

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.