From: Alexander Grayver Date: Fri, 24 Jan 2020 11:08:15 +0000 (+0100) Subject: Add python bind for compute_aspect_ratio_of_cells X-Git-Tag: v9.2.0-rc1~555^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce869f8dd308081fc5fecfa2911a2b0d6b3630db;p=dealii.git Add python bind for compute_aspect_ratio_of_cells --- diff --git a/contrib/python-bindings/include/triangulation_wrapper.h b/contrib/python-bindings/include/triangulation_wrapper.h index 83450a9f61..1c2517c7a5 100644 --- a/contrib/python-bindings/include/triangulation_wrapper.h +++ b/contrib/python-bindings/include/triangulation_wrapper.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -415,6 +416,14 @@ namespace python double maximal_cell_diameter() const; + /** + * Computes an aspect ratio measure for all active cells and fills a vector + * with one entry per cell. + */ + boost::python::list + compute_aspect_ratio_of_cells(MappingQGenericWrapper mapping, + QuadratureWrapper quadrature); + /** * Write mesh to the output file @filename according to the given data * format. diff --git a/contrib/python-bindings/source/export_triangulation.cc b/contrib/python-bindings/source/export_triangulation.cc index 8b3e4b6111..629de32fcb 100644 --- a/contrib/python-bindings/source/export_triangulation.cc +++ b/contrib/python-bindings/source/export_triangulation.cc @@ -413,6 +413,12 @@ namespace python + const char compute_aspect_ratio_of_cells_docstring[] = + "Computes an aspect ratio measure for all active cells and fills \n" + "a vector with one entry per cell. \n"; + + + const char find_cells_adjacent_to_vertex_docstring[] = "Find and return a list of active cells that surround a given \n" "vertex with index vertex_index. \n"; @@ -593,6 +599,10 @@ namespace python &TriangulationWrapper::find_cells_adjacent_to_vertex, find_cells_adjacent_to_vertex_docstring, boost::python::args("self", "vertex_index")) + .def("compute_aspect_ratio_of_cells", + &TriangulationWrapper::compute_aspect_ratio_of_cells, + compute_aspect_ratio_of_cells_docstring, + boost::python::args("self", "mapping", "quadrature")) .def("refine_global", &TriangulationWrapper::refine_global, refine_global_docstring, diff --git a/contrib/python-bindings/source/triangulation_wrapper.cc b/contrib/python-bindings/source/triangulation_wrapper.cc index cb49a92cf7..b3faf5d51e 100644 --- a/contrib/python-bindings/source/triangulation_wrapper.cc +++ b/contrib/python-bindings/source/triangulation_wrapper.cc @@ -558,6 +558,34 @@ namespace python } + template + boost::python::list + compute_aspect_ratio_of_cells(MappingQGenericWrapper &mapping_wrapper, + QuadratureWrapper & quadrature_wrapper, + TriangulationWrapper & triangulation_wrapper) + { + const Triangulation *tria = + static_cast *>( + triangulation_wrapper.get_triangulation()); + + Quadrature *quad = + static_cast *>(quadrature_wrapper.get_quadrature()); + + const MappingQGeneric *mapping = + static_cast *>( + mapping_wrapper.get_mapping()); + + auto aspect_ratios = + GridTools::compute_aspect_ratio_of_cells(*tria, *mapping, *quad); + + boost::python::list ratios; + for (size_t i = 0; i < aspect_ratios.size(); ++i) + ratios.append(aspect_ratios[i]); + + return ratios; + } + + template boost::python::list find_cells_adjacent_to_vertex(const unsigned int vertex_index, @@ -1413,6 +1441,27 @@ namespace python + boost::python::list + TriangulationWrapper::compute_aspect_ratio_of_cells( + MappingQGenericWrapper mapping, + QuadratureWrapper quadrature) + { + if ((dim == 2) && (spacedim == 2)) + return internal::compute_aspect_ratio_of_cells<2, 2>(mapping, + quadrature, + *this); + else if ((dim == 3) && (spacedim == 3)) + return internal::compute_aspect_ratio_of_cells<3, 3>(mapping, + quadrature, + *this); + else + AssertThrow(false, + ExcMessage( + "Thie combination of dim-spacedim is not supported.")); + } + + + void TriangulationWrapper::refine_global(const unsigned int n) {