]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add GridGenerator::channel_with_cylinder to the python wrappers
authorBruno Turcksin <bruno.turcksin@gmail.com>
Fri, 22 Mar 2024 13:05:11 +0000 (09:05 -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 24f55941e1466e4627de473d5374960f93541829..b424cc5f1e4a548c8fe6ac1512d1758af4087d59 100644 (file)
@@ -208,6 +208,14 @@ namespace python
                                const unsigned int  n_slices          = 2,
                                const bool          colorize          = false);
 
+    /*! @copydoc GridGenerator::generate_channel_with_cylinder
+     */
+    void
+    generate_channel_with_cylinder(const double       shell_region_width = 0.03,
+                                   const unsigned int n_shells           = 2,
+                                   const double       skewness           = 2.,
+                                   const bool         colorize = false);
+
     /*! @copydoc GridGenerator::general_cell
      */
     void
index 196ee9c0e8c9ff451bc4f8ca9e715b8a8dce5e98..106ecd720925014005609a991860b1a4d502fb40 100644 (file)
@@ -85,6 +85,11 @@ namespace python
                                          generate_plate_with_a_hole,
                                          0,
                                          12)
+  BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(
+    generate_channel_with_cylinder_overloads,
+    generate_channel_with_cylinder,
+    0,
+    4)
   BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_ball_overloads,
                                          generate_hyper_ball,
                                          1,
@@ -329,6 +334,17 @@ namespace python
 
 
 
+  const char generate_channel_with_cylinder_docstring[] =
+    "Generate a grid consisting of a channel with a cylinder.              \n"
+    "The channel has three distinct regions:                               \n"
+    "  1. If n_shells is greater than zero, then there are that many       \n"
+    "     shells centered around the cylinder,                             \n"
+    "  2. a blending region between the shells and the rest of the         \n"
+    "     triangulation, and                                               \n"
+    "  3. a bulk region consisting of Cartesian cells.                     \n";
+
+
+
   const char shift_docstring[] =
     "Shift every vertex of the Triangulation by the given shift vector.     \n";
 
@@ -620,6 +636,12 @@ namespace python
                                  "n_slices",
                                  "colorize"),
              generate_plate_with_a_hole_docstring))
+      .def("generate_channel_with_cylinder",
+           &TriangulationWrapper::generate_channel_with_cylinder,
+           generate_channel_with_cylinder_overloads(
+             boost::python::args(
+               "shell_region_width", "n_shells", "skewness", "colorize"),
+             generate_channel_with_cylinder_docstring))
       .def("generate_general_cell",
            &TriangulationWrapper::generate_general_cell,
            generate_general_cell_overloads(
index 93c62adffe17bc0a5f382ada91237c08e039b9e9..e095b12dd5594434ce01949e990c4c41361393e8 100644 (file)
@@ -302,6 +302,23 @@ namespace python
 
 
 
+    template <int dim>
+    void
+    generate_channel_with_cylinder(const double       shell_region_width,
+                                   const unsigned int n_shells,
+                                   const double       skewness,
+                                   const bool         colorize,
+                                   void              *triangulation)
+    {
+      Triangulation<dim, dim> *tria =
+        static_cast<Triangulation<dim, dim> *>(triangulation);
+      tria->clear();
+      GridGenerator::channel_with_cylinder(
+        *tria, shell_region_width, n_shells, skewness, colorize);
+    }
+
+
+
     template <int dim>
     void
     generate_general_cell(std::vector<PointWrapper> &wrapped_points,
@@ -1276,6 +1293,23 @@ namespace python
 
 
 
+  void
+  TriangulationWrapper::generate_channel_with_cylinder(
+    const double       shell_region_width,
+    const unsigned int n_shells,
+    const double       skewness,
+    const bool         colorize)
+  {
+    if (dim == 2)
+      internal::generate_channel_with_cylinder<2>(
+        shell_region_width, n_shells, skewness, colorize, triangulation);
+    else
+      internal::generate_channel_with_cylinder<3>(
+        shell_region_width, n_shells, skewness, colorize, triangulation);
+  }
+
+
+
   void
   TriangulationWrapper::generate_general_cell(boost::python::list &vertices,
                                               const bool           colorize)
index c8f858b3d52543d05354519ddc757cab5c49e23d..6ce7d07cdf9cb3133a307dbc19eca2a236f33691 100644 (file)
@@ -188,6 +188,16 @@ class TestTriangulationWrapper(unittest.TestCase):
             n_cells = triangulation.n_active_cells()
             self.assertEqual(n_cells, 28)
 
+    def test_generate_channel_with_cylinder(self):
+        for dim in self.dim:
+            triangulation = Triangulation(dim[0])
+            triangulation.generate_channel_with_cylinder()
+            n_cells = triangulation.n_active_cells()
+            if (dim[0] == '2D'):
+                self.assertEqual(n_cells, 108)
+            else:
+                self.assertEqual(n_cells, 432)
+
     def test_generate_general_cell(self):
         for dim in self.restricted_dim:
             triangulation = Triangulation(dim[0], dim[1])

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.