From 2caccc70033eef75e9a3daef840421b828e416a2 Mon Sep 17 00:00:00 2001 From: Alexander Grayver Date: Fri, 15 Jan 2021 18:28:14 +0100 Subject: [PATCH] Add wrappers for simplex related functions. --- .../include/cell_accessor_wrapper.h | 15 ++++++ .../include/tria_accessor_wrapper.h | 15 ++++++ .../include/triangulation_wrapper.h | 5 ++ .../source/cell_accessor_wrapper.cc | 39 +++++++++++++++ .../source/export_cell_accessor.cc | 29 +++++++++++- .../source/export_triangulation.cc | 11 +++++ .../source/tria_accessor_wrapper.cc | 47 +++++++++++++++++++ .../source/triangulation_wrapper.cc | 35 ++++++++++++++ 8 files changed, 195 insertions(+), 1 deletion(-) diff --git a/contrib/python-bindings/include/cell_accessor_wrapper.h b/contrib/python-bindings/include/cell_accessor_wrapper.h index 40d43155b8..bf10570a37 100644 --- a/contrib/python-bindings/include/cell_accessor_wrapper.h +++ b/contrib/python-bindings/include/cell_accessor_wrapper.h @@ -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. */ diff --git a/contrib/python-bindings/include/tria_accessor_wrapper.h b/contrib/python-bindings/include/tria_accessor_wrapper.h index 5e56282e72..ecb8e4720e 100644 --- a/contrib/python-bindings/include/tria_accessor_wrapper.h +++ b/contrib/python-bindings/include/tria_accessor_wrapper.h @@ -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. */ diff --git a/contrib/python-bindings/include/triangulation_wrapper.h b/contrib/python-bindings/include/triangulation_wrapper.h index 552a5735d7..17e04bad51 100644 --- a/contrib/python-bindings/include/triangulation_wrapper.h +++ b/contrib/python-bindings/include/triangulation_wrapper.h @@ -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 diff --git a/contrib/python-bindings/source/cell_accessor_wrapper.cc b/contrib/python-bindings/source/cell_accessor_wrapper.cc index 7470d5da09..4d9dfc7114 100644 --- a/contrib/python-bindings/source/cell_accessor_wrapper.cc +++ b/contrib/python-bindings/source/cell_accessor_wrapper.cc @@ -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 diff --git a/contrib/python-bindings/source/export_cell_accessor.cc b/contrib/python-bindings/source/export_cell_accessor.cc index 67f6ff59e0..b14b212a60 100644 --- a/contrib/python-bindings/source/export_cell_accessor.cc +++ b/contrib/python-bindings/source/export_cell_accessor.cc @@ -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 diff --git a/contrib/python-bindings/source/export_triangulation.cc b/contrib/python-bindings/source/export_triangulation.cc index e23f7c4f23..2690303d46 100644 --- a/contrib/python-bindings/source/export_triangulation.cc +++ b/contrib/python-bindings/source/export_triangulation.cc @@ -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( diff --git a/contrib/python-bindings/source/tria_accessor_wrapper.cc b/contrib/python-bindings/source/tria_accessor_wrapper.cc index 526d3fdc6d..eebd472ff4 100644 --- a/contrib/python-bindings/source/tria_accessor_wrapper.cc +++ b/contrib/python-bindings/source/tria_accessor_wrapper.cc @@ -171,6 +171,14 @@ namespace python tria_accessor); return accessor->measure(); } + + template + const TriaAccessor * + tria_accessor_cast(const void *tria_accessor) + { + return static_cast *>( + 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 diff --git a/contrib/python-bindings/source/triangulation_wrapper.cc b/contrib/python-bindings/source/triangulation_wrapper.cc index ca8b7673bd..511df8b736 100644 --- a/contrib/python-bindings/source/triangulation_wrapper.cc +++ b/contrib/python-bindings/source/triangulation_wrapper.cc @@ -555,6 +555,21 @@ namespace python + template + void + convert_hypercube_to_simplex_mesh(void * triangulation, + TriangulationWrapper &tria_out) + { + Triangulation *tria = + static_cast *>(triangulation); + Triangulation *tria_2 = + static_cast *>( + tria_out.get_triangulation()); + GridGenerator::convert_hypercube_to_simplex_mesh(*tria, *tria_2); + } + + + template 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 -- 2.39.5