From: Peter Munch Date: Tue, 16 Jul 2024 17:31:50 +0000 (+0200) Subject: Support codim-1 in hyper_shell() and hyper_cube_with_cylindrical_hole() X-Git-Tag: v9.6.0-rc1~92^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=baa00935b3d24677da6c924617f16754c4807d94;p=dealii.git Support codim-1 in hyper_shell() and hyper_cube_with_cylindrical_hole() --- diff --git a/doc/news/changes/minor/20240716Munch b/doc/news/changes/minor/20240716Munch new file mode 100644 index 0000000000..7d90ecaf98 --- /dev/null +++ b/doc/news/changes/minor/20240716Munch @@ -0,0 +1,5 @@ +New: The functions GridGenerator::hyper_shell() and +GridGenerator::hyper_cube_with_cylindrical_hole() now support +dim=2 and spacedim=3. +
+(Peter Munch, 2024/07/16) diff --git a/include/deal.II/grid/grid_generator.h b/include/deal.II/grid/grid_generator.h index e083008c66..29d8fe4928 100644 --- a/include/deal.II/grid/grid_generator.h +++ b/include/deal.II/grid/grid_generator.h @@ -1451,14 +1451,14 @@ namespace GridGenerator * `triangulation.generate_hyper_shell(center, inner_radius, outer_radius, * n_cells = 0, colorize = false)`. */ - template + template void - hyper_shell(Triangulation &tria, - const Point ¢er, - const double inner_radius, - const double outer_radius, - const unsigned int n_cells = 0, - bool colorize = false); + hyper_shell(Triangulation &tria, + const Point ¢er, + const double inner_radius, + const double outer_radius, + const unsigned int n_cells = 0, + bool colorize = false); /** * Produce an eccentric hyper-shell, the region between two spheres centered @@ -1708,14 +1708,14 @@ namespace GridGenerator * `triangulation.generate_hyper_cube_with_cylindrical_hole(inner_radius = * 0.25, outer_radius = 0.5, L = 0.5, repetitions = 1, colorize = false)`. */ - template + template void - hyper_cube_with_cylindrical_hole(Triangulation &triangulation, - const double inner_radius = .25, - const double outer_radius = .5, - const double L = .5, - const unsigned int repetitions = 1, - const bool colorize = false); + hyper_cube_with_cylindrical_hole(Triangulation &triangulation, + const double inner_radius = .25, + const double outer_radius = .5, + const double L = .5, + const unsigned int repetitions = 1, + const bool colorize = false); /** * Produce a grid consisting of concentric shells. The primary difference diff --git a/source/grid/grid_generator.cc b/source/grid/grid_generator.cc index 3ef230e19a..76229e99a5 100644 --- a/source/grid/grid_generator.cc +++ b/source/grid/grid_generator.cc @@ -1341,9 +1341,10 @@ namespace GridGenerator * Assign boundary number zero to the inner shell boundary and 1 to the * outer. */ + template void - colorize_hyper_shell(Triangulation<2> &tria, - const Point<2> &, + colorize_hyper_shell(Triangulation<2, spacdim> &tria, + const Point &, const double, const double) { @@ -1353,9 +1354,7 @@ namespace GridGenerator // For the mesh based on cube, // this is highly irregular - for (Triangulation<2>::cell_iterator cell = tria.begin(); - cell != tria.end(); - ++cell) + for (auto cell = tria.begin(); cell != tria.end(); ++cell) { Assert(cell->face(2)->at_boundary(), ExcInternalError()); cell->face(2)->set_all_boundary_ids(1); @@ -4340,14 +4339,14 @@ namespace GridGenerator - template <> + template void - hyper_shell(Triangulation<2> &tria, - const Point<2> ¢er, - const double inner_radius, - const double outer_radius, - const unsigned int n_cells, - const bool colorize) + hyper_shell_2D(Triangulation<2, spacedim> &tria, + const Point ¢er, + const double inner_radius, + const double outer_radius, + const unsigned int n_cells, + const bool colorize) { Assert((inner_radius > 0) && (inner_radius < outer_radius), ExcInvalidRadii()); @@ -4375,12 +4374,14 @@ namespace GridGenerator // first N ones are on the // outer one, and all are // numbered counter-clockwise - std::vector> vertices(2 * N); + std::vector> vertices(2 * N); for (unsigned int i = 0; i < N; ++i) { - vertices[i] = - Point<2>(std::cos(2 * pi * i / N), std::sin(2 * pi * i / N)) * - outer_radius; + Point point; + point[0] = std::cos(2 * pi * i / N); + point[1] = std::sin(2 * pi * i / N); + + vertices[i] = point * outer_radius; vertices[i + N] = vertices[i] * (inner_radius / outer_radius); vertices[i] += center; @@ -4405,7 +4406,35 @@ namespace GridGenerator colorize_hyper_shell(tria, center, inner_radius, outer_radius); tria.set_all_manifold_ids(0); - tria.set_manifold(0, SphericalManifold<2>(center)); + tria.set_manifold(0, SphericalManifold<2, spacedim>(center)); + } + + + + template <> + void + hyper_shell(Triangulation<2> &tria, + const Point<2> ¢er, + const double inner_radius, + const double outer_radius, + const unsigned int n_cells, + const bool colorize) + { + hyper_shell_2D(tria, center, inner_radius, outer_radius, n_cells, colorize); + } + + + + template <> + void + hyper_shell(Triangulation<2, 3> &tria, + const Point<3> ¢er, + const double inner_radius, + const double outer_radius, + const unsigned int n_cells, + const bool colorize) + { + hyper_shell_2D(tria, center, inner_radius, outer_radius, n_cells, colorize); } @@ -7350,21 +7379,21 @@ namespace GridGenerator - template <> + template void - hyper_cube_with_cylindrical_hole(Triangulation<2> &triangulation, - const double inner_radius, - const double outer_radius, - const double, // width, - const unsigned int, // width_repetition, - const bool colorize) + hyper_cube_with_cylindrical_hole_2D(Triangulation<2, spacedim> &triangulation, + const double inner_radius, + const double outer_radius, + const double, // width, + const unsigned int, // width_repetition, + const bool colorize) { const int dim = 2; Assert(inner_radius < outer_radius, ExcMessage("outer_radius has to be bigger than inner_radius.")); - const Point center; + const Point center; // We create a hyper_shell (i.e., an annulus) in two dimensions, and then we // modify it by pulling the vertices on the diagonals out to where the @@ -7425,7 +7454,45 @@ namespace GridGenerator } } } - triangulation.set_manifold(0, PolarManifold<2>(center)); + triangulation.set_manifold(0, PolarManifold<2, spacedim>(center)); + } + + + + template <> + void + hyper_cube_with_cylindrical_hole(Triangulation<2, 2> &triangulation, + const double inner_radius, + const double outer_radius, + const double width, + const unsigned int width_repetition, + const bool colorize) + { + hyper_cube_with_cylindrical_hole_2D(triangulation, + inner_radius, + outer_radius, + width, + width_repetition, + colorize); + } + + + + template <> + void + hyper_cube_with_cylindrical_hole(Triangulation<2, 3> &triangulation, + const double inner_radius, + const double outer_radius, + const double width, + const unsigned int width_repetition, + const bool colorize) + { + hyper_cube_with_cylindrical_hole_2D(triangulation, + inner_radius, + outer_radius, + width, + width_repetition, + colorize); } diff --git a/tests/grid/grid_generator_04.cc b/tests/grid/grid_generator_04.cc index 07548761be..c8089765de 100644 --- a/tests/grid/grid_generator_04.cc +++ b/tests/grid/grid_generator_04.cc @@ -24,13 +24,13 @@ -template +template void test(std::ostream &out) { GridOut go; go.set_flags(GridOutFlags::Ucd(false, true)); - Triangulation tr; + Triangulation tr; std::vector radii; radii.push_back(.2); @@ -106,6 +106,9 @@ main() deallog.push("2d"); test<2>(deallog.get_file_stream()); deallog.pop(); + deallog.push("2d-3d"); + test<2, 3>(deallog.get_file_stream()); + deallog.pop(); deallog.push("3d"); test<3>(deallog.get_file_stream()); deallog.pop(); diff --git a/tests/grid/grid_generator_04.output b/tests/grid/grid_generator_04.output index c67ec7930b..8afae007f4 100644 --- a/tests/grid/grid_generator_04.output +++ b/tests/grid/grid_generator_04.output @@ -245,6 +245,246 @@ Outer radius = 0.300000 Depth = 0.100000 Nzs = 2 No colorize ==================== +16 16 0 0 0 +1 0.300000 0.00000 0.00000 +2 0.300000 0.300000 0.00000 +3 1.83697e-17 0.300000 0.00000 +4 -0.300000 0.300000 0.00000 +5 -0.300000 3.67394e-17 0.00000 +6 -0.300000 -0.300000 0.00000 +7 -5.51091e-17 -0.300000 0.00000 +8 0.300000 -0.300000 0.00000 +9 0.200000 0.00000 0.00000 +10 0.141421 0.141421 0.00000 +11 1.22465e-17 0.200000 0.00000 +12 -0.141421 0.141421 0.00000 +13 -0.200000 2.44929e-17 0.00000 +14 -0.141421 -0.141421 0.00000 +15 -3.67394e-17 -0.200000 0.00000 +16 0.141421 -0.141421 0.00000 +1 0 quad 1 2 10 9 +2 0 quad 2 3 11 10 +3 0 quad 3 4 12 11 +4 0 quad 4 5 13 12 +5 0 quad 5 6 14 13 +6 0 quad 6 7 15 14 +7 0 quad 7 8 16 15 +8 0 quad 8 1 9 16 +9 1 line 9 10 +10 1 line 10 11 +11 1 line 11 12 +12 1 line 12 13 +13 1 line 13 14 +14 1 line 14 15 +15 1 line 15 16 +16 1 line 16 9 +Colorize ==================== +16 22 0 0 0 +1 0.300000 0.00000 0.00000 +2 0.300000 0.300000 0.00000 +3 1.83697e-17 0.300000 0.00000 +4 -0.300000 0.300000 0.00000 +5 -0.300000 3.67394e-17 0.00000 +6 -0.300000 -0.300000 0.00000 +7 -5.51091e-17 -0.300000 0.00000 +8 0.300000 -0.300000 0.00000 +9 0.200000 0.00000 0.00000 +10 0.141421 0.141421 0.00000 +11 1.22465e-17 0.200000 0.00000 +12 -0.141421 0.141421 0.00000 +13 -0.200000 2.44929e-17 0.00000 +14 -0.141421 -0.141421 0.00000 +15 -3.67394e-17 -0.200000 0.00000 +16 0.141421 -0.141421 0.00000 +1 0 quad 1 2 10 9 +2 0 quad 2 3 11 10 +3 0 quad 3 4 12 11 +4 0 quad 4 5 13 12 +5 0 quad 5 6 14 13 +6 0 quad 6 7 15 14 +7 0 quad 7 8 16 15 +8 0 quad 8 1 9 16 +9 1 line 1 2 +10 3 line 2 3 +11 3 line 3 4 +12 2 line 6 7 +13 2 line 7 8 +14 1 line 8 1 +15 4 line 9 10 +16 4 line 10 11 +17 4 line 11 12 +18 4 line 12 13 +19 4 line 13 14 +20 4 line 14 15 +21 4 line 15 16 +22 4 line 16 9 + ==================== + ==================== +Inner radius = 0.300000 +Outer radius = 0.400000 +Depth = 0.100000 +Nzs = 2 +No colorize ==================== +16 16 0 0 0 +1 0.400000 0.00000 0.00000 +2 0.400000 0.400000 0.00000 +3 2.44929e-17 0.400000 0.00000 +4 -0.400000 0.400000 0.00000 +5 -0.400000 4.89859e-17 0.00000 +6 -0.400000 -0.400000 0.00000 +7 -7.34788e-17 -0.400000 0.00000 +8 0.400000 -0.400000 0.00000 +9 0.300000 0.00000 0.00000 +10 0.212132 0.212132 0.00000 +11 1.83697e-17 0.300000 0.00000 +12 -0.212132 0.212132 0.00000 +13 -0.300000 3.67394e-17 0.00000 +14 -0.212132 -0.212132 0.00000 +15 -5.51091e-17 -0.300000 0.00000 +16 0.212132 -0.212132 0.00000 +1 0 quad 1 2 10 9 +2 0 quad 2 3 11 10 +3 0 quad 3 4 12 11 +4 0 quad 4 5 13 12 +5 0 quad 5 6 14 13 +6 0 quad 6 7 15 14 +7 0 quad 7 8 16 15 +8 0 quad 8 1 9 16 +9 1 line 9 10 +10 1 line 10 11 +11 1 line 11 12 +12 1 line 12 13 +13 1 line 13 14 +14 1 line 14 15 +15 1 line 15 16 +16 1 line 16 9 +Colorize ==================== +16 22 0 0 0 +1 0.400000 0.00000 0.00000 +2 0.400000 0.400000 0.00000 +3 2.44929e-17 0.400000 0.00000 +4 -0.400000 0.400000 0.00000 +5 -0.400000 4.89859e-17 0.00000 +6 -0.400000 -0.400000 0.00000 +7 -7.34788e-17 -0.400000 0.00000 +8 0.400000 -0.400000 0.00000 +9 0.300000 0.00000 0.00000 +10 0.212132 0.212132 0.00000 +11 1.83697e-17 0.300000 0.00000 +12 -0.212132 0.212132 0.00000 +13 -0.300000 3.67394e-17 0.00000 +14 -0.212132 -0.212132 0.00000 +15 -5.51091e-17 -0.300000 0.00000 +16 0.212132 -0.212132 0.00000 +1 0 quad 1 2 10 9 +2 0 quad 2 3 11 10 +3 0 quad 3 4 12 11 +4 0 quad 4 5 13 12 +5 0 quad 5 6 14 13 +6 0 quad 6 7 15 14 +7 0 quad 7 8 16 15 +8 0 quad 8 1 9 16 +9 1 line 1 2 +10 3 line 2 3 +11 3 line 3 4 +12 2 line 6 7 +13 2 line 7 8 +14 1 line 8 1 +15 4 line 9 10 +16 4 line 10 11 +17 4 line 11 12 +18 4 line 12 13 +19 4 line 13 14 +20 4 line 14 15 +21 4 line 15 16 +22 4 line 16 9 + ==================== + ==================== +Inner radius = 0.400000 +Outer radius = 0.500000 +Depth = 0.100000 +Nzs = 2 +No colorize ==================== +16 16 0 0 0 +1 0.500000 0.00000 0.00000 +2 0.500000 0.500000 0.00000 +3 3.06162e-17 0.500000 0.00000 +4 -0.500000 0.500000 0.00000 +5 -0.500000 6.12323e-17 0.00000 +6 -0.500000 -0.500000 0.00000 +7 -9.18485e-17 -0.500000 0.00000 +8 0.500000 -0.500000 0.00000 +9 0.400000 0.00000 0.00000 +10 0.282843 0.282843 0.00000 +11 2.44929e-17 0.400000 0.00000 +12 -0.282843 0.282843 0.00000 +13 -0.400000 4.89859e-17 0.00000 +14 -0.282843 -0.282843 0.00000 +15 -7.34788e-17 -0.400000 0.00000 +16 0.282843 -0.282843 0.00000 +1 0 quad 1 2 10 9 +2 0 quad 2 3 11 10 +3 0 quad 3 4 12 11 +4 0 quad 4 5 13 12 +5 0 quad 5 6 14 13 +6 0 quad 6 7 15 14 +7 0 quad 7 8 16 15 +8 0 quad 8 1 9 16 +9 1 line 9 10 +10 1 line 10 11 +11 1 line 11 12 +12 1 line 12 13 +13 1 line 13 14 +14 1 line 14 15 +15 1 line 15 16 +16 1 line 16 9 +Colorize ==================== +16 22 0 0 0 +1 0.500000 0.00000 0.00000 +2 0.500000 0.500000 0.00000 +3 3.06162e-17 0.500000 0.00000 +4 -0.500000 0.500000 0.00000 +5 -0.500000 6.12323e-17 0.00000 +6 -0.500000 -0.500000 0.00000 +7 -9.18485e-17 -0.500000 0.00000 +8 0.500000 -0.500000 0.00000 +9 0.400000 0.00000 0.00000 +10 0.282843 0.282843 0.00000 +11 2.44929e-17 0.400000 0.00000 +12 -0.282843 0.282843 0.00000 +13 -0.400000 4.89859e-17 0.00000 +14 -0.282843 -0.282843 0.00000 +15 -7.34788e-17 -0.400000 0.00000 +16 0.282843 -0.282843 0.00000 +1 0 quad 1 2 10 9 +2 0 quad 2 3 11 10 +3 0 quad 3 4 12 11 +4 0 quad 4 5 13 12 +5 0 quad 5 6 14 13 +6 0 quad 6 7 15 14 +7 0 quad 7 8 16 15 +8 0 quad 8 1 9 16 +9 1 line 1 2 +10 3 line 2 3 +11 3 line 3 4 +12 2 line 6 7 +13 2 line 7 8 +14 1 line 8 1 +15 4 line 9 10 +16 4 line 10 11 +17 4 line 11 12 +18 4 line 12 13 +19 4 line 13 14 +20 4 line 14 15 +21 4 line 15 16 +22 4 line 16 9 + ==================== + ==================== +Inner radius = 0.200000 +Outer radius = 0.300000 +Depth = 0.100000 +Nzs = 2 +No colorize ==================== 48 32 0 0 0 1 0.300000 0.00000 0.00000 2 0.300000 0.300000 0.00000