]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add GridGenerator::subdivided_cylinder to the python wrappers
authorBruno Turcksin <bruno.turcksin@gmail.com>
Thu, 4 Apr 2024 17:35:10 +0000 (13:35 -0400)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Fri, 12 Apr 2024 14:42:05 +0000 (10:42 -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 7422c11ac65cb89e3f4a82a34ae39b809085e49f..a2710fa51359b5a88f234b63f11792a679fab357 100644 (file)
@@ -291,6 +291,12 @@ namespace python
     void
     generate_cylinder(const double radius = 1., const double half_length = 1.);
 
+    /*! @copydoc GridGenerator::subdivided_cylinder
+     */
+    void
+    generate_subdivided_cylinder(const unsigned int x_subdivisions,
+                                 const double       radius      = 1.,
+                                 const double       half_length = 1.);
     /*! @copydoc GridGenerator::hyper_shell
      */
     void
index 65b1bbdac0540626a2f7f77159daccd1cd11d135..76b65b8f60292e9951ddf8da4b8acfea6d1fa61c 100644 (file)
@@ -114,6 +114,10 @@ namespace python
                                          generate_cylinder,
                                          0,
                                          2)
+  BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_subdivided_cylinder_overloads,
+                                         generate_subdivided_cylinder,
+                                         1,
+                                         3)
   BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_shell_overloads,
                                          generate_hyper_shell,
                                          3,
@@ -347,6 +351,20 @@ namespace python
 
 
 
+  const char generate_subdivided_cylinder_docstring[] =
+    "Create a dim dimensional cylinder where the x-axis serves as the axis \n"
+    "of the cylinder. For the purposes of this function, a cylinder is     \n"
+    "defined as a (dim - 1) dimensional disk of given radius, extruded     \n"
+    "along the axis of the cylinder (which is the first coordinate         \n"
+    "direction). Consequently, in three dimensions, the cylinder extends   \n"
+    "from x=-half_length to x=+half_length and its projection into the     \n"
+    "yz-plane is a circle of radius radius. In two dimensions, the         \n"
+    "cylinder is a rectangle from x=-half_length to x=+half_length and     \n"
+    "from y=-radius to y=radius. This function is only implemented for     \n"
+    "dim == 3.                                                             \n";
+
+
+
   const char generate_hyper_cube_with_cylindrical_hole_docstring[] =
     "This function produces a square in the xy-plane with a cylindrical     \n"
     "hole in the middle. In 3d, this geometry is extruded in z direction    \n"
@@ -733,6 +751,12 @@ namespace python
            generate_cylinder_overloads(
              boost::python::args("self", "radius", "half_length"),
              generate_cylinder_docstring))
+      .def("generate_subdivided_cylinder",
+           &TriangulationWrapper::generate_subdivided_cylinder,
+           generate_subdivided_cylinder_overloads(
+             boost::python::args(
+               "self", "x_subdivisions", "radius", "half_length"),
+             generate_subdivided_cylinder_docstring))
       .def("generate_hyper_shell",
            &TriangulationWrapper::generate_hyper_shell,
            generate_hyper_shell_overloads(boost::python::args("self",
index 1f131c00d20ff58653141dcbfd1d08b07e53e6ba..9faa68faa9870ad4bf364cba1819739785608c1f 100644 (file)
@@ -577,6 +577,24 @@ namespace python
 
 
 
+    template <int dim>
+    void
+    generate_subdivided_cylinder(const unsigned int x_subdivisions,
+                                 const double       radius,
+                                 const double       half_length,
+                                 void              *triangulation)
+    {
+      Triangulation<dim> *tria =
+        static_cast<Triangulation<dim> *>(triangulation);
+      tria->clear();
+      GridGenerator::subdivided_cylinder(*tria,
+                                         x_subdivisions,
+                                         radius,
+                                         half_length);
+    }
+
+
+
     template <int dim, int spacedim>
     void
     scale(const double scaling_factor, void *triangulation)
@@ -1631,6 +1649,30 @@ namespace python
 
 
 
+  void
+  TriangulationWrapper::generate_subdivided_cylinder(
+    const unsigned int x_subdivisions,
+    const double       radius,
+    const double       half_length)
+  {
+    AssertThrow(
+      dim == spacedim,
+      ExcMessage(
+        "This function is only implemented for dim equal to spacedim."));
+    if (dim == 2)
+      internal::generate_subdivided_cylinder<2>(radius,
+                                                x_subdivisions,
+                                                half_length,
+                                                triangulation);
+    else
+      internal::generate_subdivided_cylinder<3>(radius,
+                                                x_subdivisions,
+                                                half_length,
+                                                triangulation);
+  }
+
+
+
   void
   TriangulationWrapper::generate_hyper_cube_with_cylindrical_hole(
     const double       inner_radius,
index 5a645be1f02b4853c1f08750d0e62d64ecbccbb1..e62cd1d3e1a964742aac9e88c37d0088c71842d4 100644 (file)
@@ -388,6 +388,13 @@ class TestTriangulationWrapper(unittest.TestCase):
             n_cells = triangulation.n_active_cells()
             self.assertEqual(n_cells, n_cells_ref)
 
+    def test_subdivided_cylinder(self):
+        triangulation = Triangulation('3D')
+        n_cells_ref = 5
+        triangulation.generate_subdivided_cylinder(2)
+        n_cells = triangulation.n_active_cells()
+        self.assertEqual(n_cells, n_cells_ref)
+
     def test_shift_and_merge(self):
         for dim in self.dim:
             triangulation_1 = self.build_hyper_cube_triangulation(dim)

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.