From: Bruno Turcksin Date: Wed, 20 Mar 2024 14:24:13 +0000 (-0400) Subject: Add GridGenerator::plate_with_a_hole to the python wrappers X-Git-Tag: v9.6.0-rc1~430^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b969052a173e33ae44e3dcf743062afcc3765d1;p=dealii.git Add GridGenerator::plate_with_a_hole to the python wrappers --- diff --git a/contrib/python-bindings/include/triangulation_wrapper.h b/contrib/python-bindings/include/triangulation_wrapper.h index cfd40a690b..24f55941e1 100644 --- a/contrib/python-bindings/include/triangulation_wrapper.h +++ b/contrib/python-bindings/include/triangulation_wrapper.h @@ -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 ¢er = 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 diff --git a/contrib/python-bindings/source/export_triangulation.cc b/contrib/python-bindings/source/export_triangulation.cc index 298649df79..196ee9c0e8 100644 --- a/contrib/python-bindings/source/export_triangulation.cc +++ b/contrib/python-bindings/source/export_triangulation.cc @@ -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( diff --git a/contrib/python-bindings/source/point_wrapper.cc b/contrib/python-bindings/source/point_wrapper.cc index 89a743e0ec..0710b7b75c 100644 --- a/contrib/python-bindings/source/point_wrapper.cc +++ b/contrib/python-bindings/source/point_wrapper.cc @@ -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 *>(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 diff --git a/contrib/python-bindings/source/triangulation_wrapper.cc b/contrib/python-bindings/source/triangulation_wrapper.cc index 70b4a5dfa4..93c62adffe 100644 --- a/contrib/python-bindings/source/triangulation_wrapper.cc +++ b/contrib/python-bindings/source/triangulation_wrapper.cc @@ -260,6 +260,48 @@ namespace python + template + 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 ¢er, + 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 + Point point = + center.get_point() ? + *(static_cast *>(center.get_point())) : + Point(); + + Triangulation *tria = + static_cast *>(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 void generate_general_cell(std::vector &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 ¢er, + 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) diff --git a/contrib/python-bindings/tests/triangulation_wrapper.py b/contrib/python-bindings/tests/triangulation_wrapper.py index b7f6bf4164..c8f858b3d5 100644 --- a/contrib/python-bindings/tests/triangulation_wrapper.py +++ b/contrib/python-bindings/tests/triangulation_wrapper.py @@ -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])