]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add GridGenerator::plate_with_a_hole to the python wrappers
authorBruno Turcksin <bruno.turcksin@gmail.com>
Wed, 20 Mar 2024 14:24:13 +0000 (10:24 -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/point_wrapper.cc
contrib/python-bindings/source/triangulation_wrapper.cc
contrib/python-bindings/tests/triangulation_wrapper.py

index cfd40a690bda919e17e4cd6d0809aa92be72e929..24f55941e1466e4627de473d5374960f93541829 100644 (file)
@@ -192,6 +192,22 @@ namespace python
     void
     generate_cheese(boost::python::list &holes);
 
+    /*! @copydoc GridGenerator::plate_with_a_hole
+     */
+    void
+    generate_plate_with_a_hole(const double        inner_radius = 0.4,
+                               const double        outer_radius = 1.,
+                               const double        pad_bottom   = 2.,
+                               const double        pad_top      = 2.,
+                               const double        pad_left     = 1.,
+                               const double        pad_right    = 1.,
+                               const PointWrapper &center = PointWrapper(),
+                               const int           polar_manifold_id = 0,
+                               const int           tfi_manifold_id   = 1,
+                               const double        L                 = 1.,
+                               const unsigned int  n_slices          = 2,
+                               const bool          colorize          = false);
+
     /*! @copydoc GridGenerator::general_cell
      */
     void
index 298649df79f84300bb6bb228bf31dd2ae3206762..196ee9c0e8c9ff451bc4f8ca9e715b8a8dce5e98 100644 (file)
@@ -81,6 +81,10 @@ namespace python
     generate_hyper_cube_with_cylindrical_hole,
     0,
     5)
+  BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_plate_with_a_hole_overloads,
+                                         generate_plate_with_a_hole,
+                                         0,
+                                         12)
   BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_ball_overloads,
                                          generate_hyper_ball,
                                          1,
@@ -317,6 +321,14 @@ namespace python
 
 
 
+  const char generate_plate_with_a_hole_docstring[] =
+    "Generate a rectangular plate with an (offset) cylindrical hole.       \n"
+    "The geometry consists of 2 regions: The first is a square region      \n"
+    "with length outer_radius and a hole of radius inner_radius.           \n"
+    "The second region describes the remainder of the bulk material.       \n";
+
+
+
   const char shift_docstring[] =
     "Shift every vertex of the Triangulation by the given shift vector.     \n";
 
@@ -591,6 +603,23 @@ namespace python
            &TriangulationWrapper::generate_cheese,
            generate_cheese_docstring,
            boost::python::args("self", "holes"))
+      .def("generate_plate_with_a_hole",
+           &TriangulationWrapper::generate_plate_with_a_hole,
+           generate_plate_with_a_hole_overloads(
+             boost::python::args("self",
+                                 "inner_radius",
+                                 "outer_radius",
+                                 "pad_bottom",
+                                 "pad_top",
+                                 "pad_left",
+                                 "pad_right",
+                                 "center",
+                                 "polar_manifold_id",
+                                 "tfi_manifold_id",
+                                 "L",
+                                 "n_slices",
+                                 "colorize"),
+             generate_plate_with_a_hole_docstring))
       .def("generate_general_cell",
            &TriangulationWrapper::generate_general_cell,
            generate_general_cell_overloads(
index 89a743e0ecb6396b99d2f0bb6fa09e6a7c046676..0710b7b75c7c097307971fb48362287ff1589d70 100644 (file)
@@ -557,9 +557,6 @@ namespace python
   {
     dim = other.dim;
 
-    AssertThrow(other.point != nullptr,
-                ExcMessage("Underlying point does not exist."));
-
     if (dim == 2)
       {
         Point<2> *other_point = static_cast<Point<2> *>(other.point);
@@ -572,8 +569,9 @@ namespace python
           new Point<3>((*other_point)[0], (*other_point)[1], (*other_point)[2]);
       }
     else
-      AssertThrow(false,
-                  ExcMessage("The dimension of the point should be 2 or 3."));
+      {
+        point = nullptr;
+      }
   }
 } // namespace python
 
index 70b4a5dfa46e342b40013ef24e8140393f0d6d2f..93c62adffe17bc0a5f382ada91237c08e039b9e9 100644 (file)
@@ -260,6 +260,48 @@ namespace python
 
 
 
+    template <int dim>
+    void
+    generate_plate_with_a_hole(const double        inner_radius,
+                               const double        outer_radius,
+                               const double        pad_bottom,
+                               const double        pad_top,
+                               const double        pad_left,
+                               const double        pad_right,
+                               const PointWrapper &center,
+                               const int           polar_manifold_id,
+                               const int           tfi_manifold_id,
+                               const double        L,
+                               const unsigned int  n_slices,
+                               const bool          colorize,
+                               void               *triangulation)
+    {
+      // Cast the PointWrapper object to Point<dim>
+      Point<dim> point =
+        center.get_point() ?
+          *(static_cast<const Point<dim> *>(center.get_point())) :
+          Point<dim>();
+
+      Triangulation<dim, dim> *tria =
+        static_cast<Triangulation<dim, dim> *>(triangulation);
+      tria->clear();
+      GridGenerator::plate_with_a_hole(*tria,
+                                       inner_radius,
+                                       outer_radius,
+                                       pad_bottom,
+                                       pad_top,
+                                       pad_left,
+                                       pad_right,
+                                       point,
+                                       polar_manifold_id,
+                                       tfi_manifold_id,
+                                       L,
+                                       n_slices,
+                                       colorize);
+    }
+
+
+
     template <int dim>
     void
     generate_general_cell(std::vector<PointWrapper> &wrapped_points,
@@ -1188,6 +1230,52 @@ namespace python
 
 
 
+  void
+  TriangulationWrapper::generate_plate_with_a_hole(const double inner_radius,
+                                                   const double outer_radius,
+                                                   const double pad_bottom,
+                                                   const double pad_top,
+                                                   const double pad_left,
+                                                   const double pad_right,
+                                                   const PointWrapper &center,
+                                                   const int polar_manifold_id,
+                                                   const int tfi_manifold_id,
+                                                   const double       L,
+                                                   const unsigned int n_slices,
+                                                   const bool         colorize)
+  {
+    if (dim == 2)
+      internal::generate_plate_with_a_hole<2>(inner_radius,
+                                              outer_radius,
+                                              pad_bottom,
+                                              pad_top,
+                                              pad_left,
+                                              pad_right,
+                                              center,
+                                              polar_manifold_id,
+                                              tfi_manifold_id,
+                                              L,
+                                              n_slices,
+                                              colorize,
+                                              triangulation);
+    else
+      internal::generate_plate_with_a_hole<3>(inner_radius,
+                                              outer_radius,
+                                              pad_bottom,
+                                              pad_top,
+                                              pad_left,
+                                              pad_right,
+                                              center,
+                                              polar_manifold_id,
+                                              tfi_manifold_id,
+                                              L,
+                                              n_slices,
+                                              colorize,
+                                              triangulation);
+  }
+
+
+
   void
   TriangulationWrapper::generate_general_cell(boost::python::list &vertices,
                                               const bool           colorize)
index b7f6bf4164b819bc6997fb24355bed4b4bd29451..c8f858b3d52543d05354519ddc757cab5c49e23d 100644 (file)
@@ -181,6 +181,13 @@ class TestTriangulationWrapper(unittest.TestCase):
                 n_cells = triangulation.n_active_cells()
                 self.assertEqual(n_cells, 175)
 
+    def test_generate_plate_with_hole(self):
+        for dim in self.dim:
+            triangulation = Triangulation(dim[0])
+            triangulation.generate_plate_with_a_hole()
+            n_cells = triangulation.n_active_cells()
+            self.assertEqual(n_cells, 28)
+
     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.