]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add GridGenerator::truncated_cone to the python wrappers
authorBruno Turcksin <bruno.turcksin@gmail.com>
Thu, 4 Apr 2024 17:59:19 +0000 (13:59 -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 a2710fa51359b5a88f234b63f11792a679fab357..ee91e67a29fd1e4af84f102f44df0ffef5dfc21b 100644 (file)
@@ -297,6 +297,14 @@ namespace python
     generate_subdivided_cylinder(const unsigned int x_subdivisions,
                                  const double       radius      = 1.,
                                  const double       half_length = 1.);
+
+    /*! @copydoc GridGenerator::truncated_cone
+     */
+    void
+    generate_truncated_cone(const double radius_0    = 1.,
+                            const double radius_1    = 0.5,
+                            const double half_length = 1.0);
+
     /*! @copydoc GridGenerator::hyper_shell
      */
     void
index 76b65b8f60292e9951ddf8da4b8acfea6d1fa61c..332f2a5994ee6d6410e0885202c51970f55f34d0 100644 (file)
@@ -118,6 +118,10 @@ namespace python
                                          generate_subdivided_cylinder,
                                          1,
                                          3)
+  BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_truncated_cone_overloads,
+                                         generate_truncated_cone,
+                                         0,
+                                         3)
   BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_shell_overloads,
                                          generate_hyper_shell,
                                          3,
@@ -365,10 +369,22 @@ namespace python
 
 
 
+  const char generate_truncated_cone_docstring[] =
+    "Create a cut cone around the x-axis. The cone extends from            \n"
+    "x=-half_length to x=half_length and its projection into the yz-plane  \n"
+    "is a circle of radius radius_0 at x=-half_length and a circle of      \n"
+    "radius radius_1 at x=+half_length. In between the radius is linearly  \n"
+    "decreasing. In two dimensions, the cone is a trapezoid from           \n"
+    "x=-half_length to x=+half_length and from y=-radius_0 to y=radius_0   \n"
+    "at x=-half_length and from y=-radius_1 to y=radius_1 at               \n"
+    "x=+half_length. In between the range of y is linearly decreasing.     \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"
-    "to the interval [0,L].                                                 \n";
+    "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"
+    "to the interval [0,L].                                                \n";
 
 
 
@@ -757,6 +773,11 @@ namespace python
              boost::python::args(
                "self", "x_subdivisions", "radius", "half_length"),
              generate_subdivided_cylinder_docstring))
+      .def("generate_truncated_cone",
+           &TriangulationWrapper::generate_truncated_cone,
+           generate_truncated_cone_overloads(
+             boost::python::args("self", "radius_0", "radius", "half_length"),
+             generate_truncated_cone_docstring))
       .def("generate_hyper_shell",
            &TriangulationWrapper::generate_hyper_shell,
            generate_hyper_shell_overloads(boost::python::args("self",
index 9faa68faa9870ad4bf364cba1819739785608c1f..17f0056a9824d6ac26a3a89a8b88a591006c8c24 100644 (file)
@@ -595,6 +595,21 @@ namespace python
 
 
 
+    template <int dim>
+    void
+    generate_truncated_cone(const double radius_0,
+                            const double radius_1,
+                            const double half_length,
+                            void        *triangulation)
+    {
+      Triangulation<dim> *tria =
+        static_cast<Triangulation<dim> *>(triangulation);
+      tria->clear();
+      GridGenerator::truncated_cone(*tria, radius_0, radius_1, half_length);
+    }
+
+
+
     template <int dim, int spacedim>
     void
     scale(const double scaling_factor, void *triangulation)
@@ -1673,6 +1688,29 @@ namespace python
 
 
 
+  void
+  TriangulationWrapper::generate_truncated_cone(const double radius_0,
+                                                const double radius_1,
+                                                const double half_length)
+  {
+    AssertThrow(
+      dim == spacedim,
+      ExcMessage(
+        "This function is only implemented for dim equal to spacedim."));
+    if (dim == 2)
+      internal::generate_truncated_cone<2>(radius_0,
+                                           radius_1,
+                                           half_length,
+                                           triangulation);
+    else
+      internal::generate_truncated_cone<3>(radius_0,
+                                           radius_1,
+                                           half_length,
+                                           triangulation);
+  }
+
+
+
   void
   TriangulationWrapper::generate_hyper_cube_with_cylindrical_hole(
     const double       inner_radius,
index e62cd1d3e1a964742aac9e88c37d0088c71842d4..94abfbf0062570bfa4064882f5af7f35b6309d23 100644 (file)
@@ -395,6 +395,17 @@ class TestTriangulationWrapper(unittest.TestCase):
         n_cells = triangulation.n_active_cells()
         self.assertEqual(n_cells, n_cells_ref)
 
+    def test_truncated_cone(self):
+        for dim in self.dim:
+            triangulation = Triangulation(dim[0])
+            if (dim[0] == '2D'):
+                n_cells_ref = 1
+            else:
+                n_cells_ref = 5
+            triangulation.generate_truncated_cone()
+            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.