]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add GridGenerator::hyper_ball_balanced to the python wrappers
authorBruno Turcksin <bruno.turcksin@gmail.com>
Fri, 22 Mar 2024 13:27:39 +0000 (09:27 -0400)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Wed, 27 Mar 2024 16:40:47 +0000 (12:40 -0400)
contrib/python-bindings/include/triangulation_wrapper.h
contrib/python-bindings/source/export_triangulation.cc
contrib/python-bindings/source/triangulation_wrapper.cc
contrib/python-bindings/tests/triangulation_wrapper.py

index b424cc5f1e4a548c8fe6ac1512d1758af4087d59..0a617ab24c8033c55699f20359e77e82c2086627 100644 (file)
@@ -265,6 +265,12 @@ namespace python
     void
     generate_hyper_ball(PointWrapper &center, const double radius = 1.);
 
+    /*! @copydoc GridGenerator::hyper_ball_balanced
+     */
+    void
+    generate_hyper_ball_balanced(const PointWrapper &center = PointWrapper(),
+                                 const double        radius = 1.);
+
     /*! @copydoc GridGenerator::hyper_sphere
      */
     void
index 106ecd720925014005609a991860b1a4d502fb40..5a9b28e6e43cda4b6f19822db3fc038099d648a0 100644 (file)
@@ -94,6 +94,10 @@ namespace python
                                          generate_hyper_ball,
                                          1,
                                          2)
+  BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_ball_balanced_overloads,
+                                         generate_hyper_ball_balanced,
+                                         0,
+                                         2)
   BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_sphere_overloads,
                                          generate_hyper_sphere,
                                          1,
@@ -283,6 +287,13 @@ namespace python
 
 
 
+  const char generate_hyper_ball_balanced_docstring[] =
+    "This is an alternative to hyper_ball with 12 cells in 2d and 32 cells  \n"
+    "in 3d, which provides a better balance between the size of the cells   \n"
+    "around the outer curved boundaries and the cell in the interior.       \n";
+
+
+
   const char generate_hyper_sphere_docstring[] =
     "Generate a hyper sphere, i.e., a surface of a ball in spacedim         \n"
     "dimensions. This function only exists for dim+1=spacedim in 2 and 3    \n"
@@ -680,6 +691,11 @@ namespace python
            generate_hyper_ball_overloads(
              boost::python::args("self", "center", "radius"),
              generate_hyper_ball_docstring))
+      .def("generate_hyper_ball_balanced",
+           &TriangulationWrapper::generate_hyper_ball_balanced,
+           generate_hyper_ball_balanced_overloads(
+             boost::python::args("self", "center", "radius"),
+             generate_hyper_ball_balanced_docstring))
       .def("generate_hyper_sphere",
            &TriangulationWrapper::generate_hyper_sphere,
            generate_hyper_sphere_overloads(
index e095b12dd5594434ce01949e990c4c41361393e8..69ead0d4e60dcf9f49507c54a9186e31a6eb316a 100644 (file)
@@ -469,6 +469,26 @@ namespace python
 
 
 
+    template <int dim>
+    void
+    generate_hyper_ball_balanced(const PointWrapper &center,
+                                 const double        radius,
+                                 void               *triangulation)
+    {
+      // Cast the PointWrapper object to Point<dim>
+      Point<dim> center_point =
+        center.get_point() ?
+          *(static_cast<const Point<dim> *>(center.get_point())) :
+          Point<dim>();
+
+      Triangulation<dim> *tria =
+        static_cast<Triangulation<dim> *>(triangulation);
+      tria->clear();
+      GridGenerator::hyper_ball_balanced(*tria, center_point, radius);
+    }
+
+
+
     template <int dim, int spacedim>
     void
     generate_hyper_sphere(PointWrapper &center,
@@ -1500,6 +1520,22 @@ namespace python
 
 
 
+  void
+  TriangulationWrapper::generate_hyper_ball_balanced(const PointWrapper &center,
+                                                     const double        radius)
+  {
+    AssertThrow(
+      dim == spacedim,
+      ExcMessage(
+        "This function is only implemented for dim equal to spacedim."));
+    if (dim == 2)
+      internal::generate_hyper_ball_balanced<2>(center, radius, triangulation);
+    else
+      internal::generate_hyper_ball_balanced<3>(center, radius, triangulation);
+  }
+
+
+
   void
   TriangulationWrapper::generate_hyper_shell(PointWrapper  &center,
                                              const double   inner_radius,
index 6ce7d07cdf9cb3133a307dbc19eca2a236f33691..a2763730fbca878173f9da5c495e7864bd15ff01 100644 (file)
@@ -333,6 +333,16 @@ class TestTriangulationWrapper(unittest.TestCase):
             n_cells = triangulation.n_active_cells()
             self.assertEqual(n_cells, n_cells_ref)
 
+    def test_hyper_ball_balanced(self):
+        for dim in self.dim:
+            triangulation = Triangulation(dim[0])
+            triangulation.generate_hyper_ball_balanced()
+            n_cells = triangulation.n_active_cells()
+            if (dim[0] == '2D'):
+                self.assertEqual(n_cells, 12)
+            else:
+                self.assertEqual(n_cells, 32)
+
     def test_hyper_sphere(self):
          triangulation = Triangulation('2D', '3D')
          center = Point([0, 0])

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.