From 3eaaa80b9e544fe9e2a8cbe5cce27c13d99a0755 Mon Sep 17 00:00:00 2001 From: Alexander Grayver Date: Thu, 3 Sep 2020 16:06:41 +0200 Subject: [PATCH] Add method for returning all triangulation cells --- .../include/triangulation_wrapper.h | 13 ++++++ .../source/export_triangulation.cc | 18 ++++++++ .../source/triangulation_wrapper.cc | 44 +++++++++++++++++++ .../changes/minor/20200903GrayverAlexander | 3 ++ 4 files changed, 78 insertions(+) create mode 100644 doc/news/changes/minor/20200903GrayverAlexander diff --git a/contrib/python-bindings/include/triangulation_wrapper.h b/contrib/python-bindings/include/triangulation_wrapper.h index 4d34e525bc..552a5735d7 100644 --- a/contrib/python-bindings/include/triangulation_wrapper.h +++ b/contrib/python-bindings/include/triangulation_wrapper.h @@ -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 diff --git a/contrib/python-bindings/source/export_triangulation.cc b/contrib/python-bindings/source/export_triangulation.cc index 14b9163e73..e23f7c4f23 100644 --- a/contrib/python-bindings/source/export_triangulation.cc +++ b/contrib/python-bindings/source/export_triangulation.cc @@ -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, diff --git a/contrib/python-bindings/source/triangulation_wrapper.cc b/contrib/python-bindings/source/triangulation_wrapper.cc index 019b79dc60..ca8b7673bd 100644 --- a/contrib/python-bindings/source/triangulation_wrapper.cc +++ b/contrib/python-bindings/source/triangulation_wrapper.cc @@ -724,6 +724,24 @@ namespace python + template + boost::python::list + cells(TriangulationWrapper &triangulation_wrapper) + { + Triangulation *tria = + static_cast *>( + 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 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)).n_cells(); + else if ((dim == 2) && (spacedim == 3)) + return (*static_cast *>(triangulation)).n_cells(); + else + return (*static_cast *>(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 index 0000000000..212342d978 --- /dev/null +++ b/doc/news/changes/minor/20200903GrayverAlexander @@ -0,0 +1,3 @@ +Added: method for returning list of all triangulation cells. +
+(Alexander Grayver, 2020/09/03) -- 2.39.5