]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add python bind for compute_aspect_ratio_of_cells
authorAlexander Grayver <agrayver@erdw.ethz.ch>
Fri, 24 Jan 2020 11:08:15 +0000 (12:08 +0100)
committerAlexander Grayver <agrayver@erdw.ethz.ch>
Tue, 4 Feb 2020 09:20:28 +0000 (10:20 +0100)
contrib/python-bindings/include/triangulation_wrapper.h
contrib/python-bindings/source/export_triangulation.cc
contrib/python-bindings/source/triangulation_wrapper.cc

index 83450a9f612d93d2a878b9abf69a61463d4f23c8..1c2517c7a5e861ed8c9fc59124fe9510e966ff66 100644 (file)
@@ -23,6 +23,7 @@
 #include <manifold_wrapper.h>
 #include <mapping_wrapper.h>
 #include <point_wrapper.h>
+#include <quadrature_wrapper.h>
 
 #include <string>
 #include <vector>
@@ -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.
index 8b3e4b6111e8f90d99bb2127bd0b8a247948db17..629de32fcb3f7b3b8f24052475f4586242028ee8 100644 (file)
@@ -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,
index cb49a92cf7e1de0a1e6548a0149b8345e3b97912..b3faf5d51ecdbf3d7458a29eb004104d8f66655e 100644 (file)
@@ -558,6 +558,34 @@ namespace python
     }
 
 
+    template <int dim, int spacedim>
+    boost::python::list
+    compute_aspect_ratio_of_cells(MappingQGenericWrapper &mapping_wrapper,
+                                  QuadratureWrapper &     quadrature_wrapper,
+                                  TriangulationWrapper &  triangulation_wrapper)
+    {
+      const Triangulation<dim, spacedim> *tria =
+        static_cast<const Triangulation<dim, spacedim> *>(
+          triangulation_wrapper.get_triangulation());
+
+      Quadrature<dim> *quad =
+        static_cast<Quadrature<dim> *>(quadrature_wrapper.get_quadrature());
+
+      const MappingQGeneric<dim, spacedim> *mapping =
+        static_cast<const MappingQGeneric<dim, spacedim> *>(
+          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 <int dim, int spacedim>
     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)
   {

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.