Skip to content

Commit

Permalink
Add method for returning all triangulation cells
Browse files Browse the repository at this point in the history
  • Loading branch information
agrayver committed Sep 15, 2020
1 parent 165278a commit 3eaaa80
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
13 changes: 13 additions & 0 deletions contrib/python-bindings/include/triangulation_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions contrib/python-bindings/source/export_triangulation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
44 changes: 44 additions & 0 deletions contrib/python-bindings/source/triangulation_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions doc/news/changes/minor/20200903GrayverAlexander
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Added: method for returning list of all triangulation cells.
<br>
(Alexander Grayver, 2020/09/03)

0 comments on commit 3eaaa80

Please sign in to comment.