From: Bruno Turcksin Date: Fri, 22 Mar 2024 13:27:39 +0000 (-0400) Subject: Add GridGenerator::hyper_ball_balanced to the python wrappers X-Git-Tag: v9.6.0-rc1~430^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a11ea7918b42dea90a62eada24e4dac09f0136a3;p=dealii.git Add GridGenerator::hyper_ball_balanced to the python wrappers --- diff --git a/contrib/python-bindings/include/triangulation_wrapper.h b/contrib/python-bindings/include/triangulation_wrapper.h index b424cc5f1e..0a617ab24c 100644 --- a/contrib/python-bindings/include/triangulation_wrapper.h +++ b/contrib/python-bindings/include/triangulation_wrapper.h @@ -265,6 +265,12 @@ namespace python void generate_hyper_ball(PointWrapper ¢er, const double radius = 1.); + /*! @copydoc GridGenerator::hyper_ball_balanced + */ + void + generate_hyper_ball_balanced(const PointWrapper ¢er = PointWrapper(), + const double radius = 1.); + /*! @copydoc GridGenerator::hyper_sphere */ void diff --git a/contrib/python-bindings/source/export_triangulation.cc b/contrib/python-bindings/source/export_triangulation.cc index 106ecd7209..5a9b28e6e4 100644 --- a/contrib/python-bindings/source/export_triangulation.cc +++ b/contrib/python-bindings/source/export_triangulation.cc @@ -94,6 +94,10 @@ namespace python generate_hyper_ball, 1, 2) + BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_ball_balanced_overloads, + generate_hyper_ball_balanced, + 0, + 2) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_sphere_overloads, generate_hyper_sphere, 1, @@ -283,6 +287,13 @@ namespace python + const char generate_hyper_ball_balanced_docstring[] = + "This is an alternative to hyper_ball with 12 cells in 2d and 32 cells \n" + "in 3d, which provides a better balance between the size of the cells \n" + "around the outer curved boundaries and the cell in the interior. \n"; + + + const char generate_hyper_sphere_docstring[] = "Generate a hyper sphere, i.e., a surface of a ball in spacedim \n" "dimensions. This function only exists for dim+1=spacedim in 2 and 3 \n" @@ -680,6 +691,11 @@ namespace python generate_hyper_ball_overloads( boost::python::args("self", "center", "radius"), generate_hyper_ball_docstring)) + .def("generate_hyper_ball_balanced", + &TriangulationWrapper::generate_hyper_ball_balanced, + generate_hyper_ball_balanced_overloads( + boost::python::args("self", "center", "radius"), + generate_hyper_ball_balanced_docstring)) .def("generate_hyper_sphere", &TriangulationWrapper::generate_hyper_sphere, generate_hyper_sphere_overloads( diff --git a/contrib/python-bindings/source/triangulation_wrapper.cc b/contrib/python-bindings/source/triangulation_wrapper.cc index e095b12dd5..69ead0d4e6 100644 --- a/contrib/python-bindings/source/triangulation_wrapper.cc +++ b/contrib/python-bindings/source/triangulation_wrapper.cc @@ -469,6 +469,26 @@ namespace python + template + void + generate_hyper_ball_balanced(const PointWrapper ¢er, + const double radius, + void *triangulation) + { + // Cast the PointWrapper object to Point + Point center_point = + center.get_point() ? + *(static_cast *>(center.get_point())) : + Point(); + + Triangulation *tria = + static_cast *>(triangulation); + tria->clear(); + GridGenerator::hyper_ball_balanced(*tria, center_point, radius); + } + + + template void generate_hyper_sphere(PointWrapper ¢er, @@ -1500,6 +1520,22 @@ namespace python + void + TriangulationWrapper::generate_hyper_ball_balanced(const PointWrapper ¢er, + const double radius) + { + AssertThrow( + dim == spacedim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); + if (dim == 2) + internal::generate_hyper_ball_balanced<2>(center, radius, triangulation); + else + internal::generate_hyper_ball_balanced<3>(center, radius, triangulation); + } + + + void TriangulationWrapper::generate_hyper_shell(PointWrapper ¢er, const double inner_radius, diff --git a/contrib/python-bindings/tests/triangulation_wrapper.py b/contrib/python-bindings/tests/triangulation_wrapper.py index 6ce7d07cdf..a2763730fb 100644 --- a/contrib/python-bindings/tests/triangulation_wrapper.py +++ b/contrib/python-bindings/tests/triangulation_wrapper.py @@ -333,6 +333,16 @@ class TestTriangulationWrapper(unittest.TestCase): n_cells = triangulation.n_active_cells() self.assertEqual(n_cells, n_cells_ref) + def test_hyper_ball_balanced(self): + for dim in self.dim: + triangulation = Triangulation(dim[0]) + triangulation.generate_hyper_ball_balanced() + n_cells = triangulation.n_active_cells() + if (dim[0] == '2D'): + self.assertEqual(n_cells, 12) + else: + self.assertEqual(n_cells, 32) + def test_hyper_sphere(self): triangulation = Triangulation('2D', '3D') center = Point([0, 0])