From d439ee767432ccb7e51a0b2215295b15bd804877 Mon Sep 17 00:00:00 2001 From: Bruno Turcksin Date: Fri, 22 Mar 2024 09:05:11 -0400 Subject: [PATCH] Add GridGenerator::channel_with_cylinder to the python wrappers --- .../include/triangulation_wrapper.h | 8 +++++ .../source/export_triangulation.cc | 22 ++++++++++++ .../source/triangulation_wrapper.cc | 34 +++++++++++++++++++ .../tests/triangulation_wrapper.py | 10 ++++++ 4 files changed, 74 insertions(+) diff --git a/contrib/python-bindings/include/triangulation_wrapper.h b/contrib/python-bindings/include/triangulation_wrapper.h index 24f55941e1..b424cc5f1e 100644 --- a/contrib/python-bindings/include/triangulation_wrapper.h +++ b/contrib/python-bindings/include/triangulation_wrapper.h @@ -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 diff --git a/contrib/python-bindings/source/export_triangulation.cc b/contrib/python-bindings/source/export_triangulation.cc index 196ee9c0e8..106ecd7209 100644 --- a/contrib/python-bindings/source/export_triangulation.cc +++ b/contrib/python-bindings/source/export_triangulation.cc @@ -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( diff --git a/contrib/python-bindings/source/triangulation_wrapper.cc b/contrib/python-bindings/source/triangulation_wrapper.cc index 93c62adffe..e095b12dd5 100644 --- a/contrib/python-bindings/source/triangulation_wrapper.cc +++ b/contrib/python-bindings/source/triangulation_wrapper.cc @@ -302,6 +302,23 @@ namespace python + template + void + generate_channel_with_cylinder(const double shell_region_width, + const unsigned int n_shells, + const double skewness, + const bool colorize, + void *triangulation) + { + Triangulation *tria = + static_cast *>(triangulation); + tria->clear(); + GridGenerator::channel_with_cylinder( + *tria, shell_region_width, n_shells, skewness, colorize); + } + + + template void generate_general_cell(std::vector &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) diff --git a/contrib/python-bindings/tests/triangulation_wrapper.py b/contrib/python-bindings/tests/triangulation_wrapper.py index c8f858b3d5..6ce7d07cdf 100644 --- a/contrib/python-bindings/tests/triangulation_wrapper.py +++ b/contrib/python-bindings/tests/triangulation_wrapper.py @@ -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]) -- 2.39.5