From: Bruno Blais Date: Thu, 5 Dec 2019 14:45:58 +0000 (-0500) Subject: Added the colorize option to subdivided_hyper_cube grid generator X-Git-Tag: v9.2.0-rc1~808^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63fac2d64f1977730c0c214c28c99b5a4e28d8ee;p=dealii.git Added the colorize option to subdivided_hyper_cube grid generator The subdivided_hyper_cube is the one of the only grid generator which does not allow the boundaries to be colorized. This is a non-standard behavior, because all of the other generators (hyper_cube, hyper_rectangle, subdivided_hyper_rectangle) allow one to colorize the boundaries. This small pull request addresses this by adding the colorize option to the subdivided_hyper_cube grid. It also fixes the grid_generator_from_name to make it coherent with the new implementaiton. --- diff --git a/doc/news/changes/minor/20191205BrunoBlais b/doc/news/changes/minor/20191205BrunoBlais new file mode 100644 index 0000000000..72f61b3fd7 --- /dev/null +++ b/doc/news/changes/minor/20191205BrunoBlais @@ -0,0 +1,3 @@ +Improved: GridGenerator::subdivided_hyper_cube() gained an option to also set boundary ids. +
+(Bruno Blais, 2019/12/05) diff --git a/include/deal.II/grid/grid_generator.h b/include/deal.II/grid/grid_generator.h index 616b3eaa48..4a50c738bc 100644 --- a/include/deal.II/grid/grid_generator.h +++ b/include/deal.II/grid/grid_generator.h @@ -147,13 +147,16 @@ namespace GridGenerator * @param left Lower bound for the interval used to create the hyper cube. * * @param right Upper bound for the interval used to create the hyper cube. + * + * @param colorize Assign different boundary ids if set to true. */ template void subdivided_hyper_cube(Triangulation &tria, const unsigned int repetitions, - const double left = 0., - const double right = 1.); + const double left = 0., + const double right = 1., + const bool colorize = false); /** * Create a coordinate-parallel brick from the two diagonally opposite diff --git a/source/grid/grid_generator.cc b/source/grid/grid_generator.cc index 4309dfb59b..dc938b892d 100644 --- a/source/grid/grid_generator.cc +++ b/source/grid/grid_generator.cc @@ -1234,7 +1234,8 @@ namespace GridGenerator subdivided_hyper_cube(Triangulation &tria, const unsigned int repetitions, const double left, - const double right) + const double right, + const bool colorize) { Assert(repetitions >= 1, ExcInvalidRepetitions(repetitions)); Assert(left < right, @@ -1248,7 +1249,7 @@ namespace GridGenerator } std::vector reps(dim, repetitions); - subdivided_hyper_rectangle(tria, reps, p0, p1); + subdivided_hyper_rectangle(tria, reps, p0, p1, colorize); } diff --git a/source/grid/grid_generator.inst.in b/source/grid/grid_generator.inst.in index 8b0d1ebdc3..76522efd9f 100644 --- a/source/grid/grid_generator.inst.in +++ b/source/grid/grid_generator.inst.in @@ -38,7 +38,8 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS) Triangulation &, const unsigned int, const double, - const double); + const double, + const bool); template void diff --git a/source/grid/grid_generator_from_name.cc b/source/grid/grid_generator_from_name.cc index 321824e268..7cf00ec86a 100644 --- a/source/grid/grid_generator_from_name.cc +++ b/source/grid/grid_generator_from_name.cc @@ -322,7 +322,7 @@ namespace GridGenerator arguments, tria); else if (name == "subdivided_hyper_cube") - parse_and_create( + parse_and_create( subdivided_hyper_cube, arguments, tria); else if (name == "hyper_rectangle") parse_and_create + +#include +#include + +#include "../tests.h" + +template +void +test() +{ + deallog << "dim = " << dim << std::endl; + Triangulation tr; + GridGenerator::subdivided_hyper_cube(tr, 1, -1, 1, true); + for (const auto &cell : tr.active_cell_iterators()) + { + deallog << "cell:" << std::endl; + + for (const auto &face : cell->face_iterators()) + { + if (face->at_boundary()) + deallog << "boundary id = " << face->boundary_id() + << " center = " << face->center() + << " faceidx = " << face->index() << std::endl; + } + } +} + +int +main() +{ + initlog(); + test<2>(); + test<3>(); +} diff --git a/tests/grid/grid_generator_subdivided_hyper_cube_01.output b/tests/grid/grid_generator_subdivided_hyper_cube_01.output new file mode 100644 index 0000000000..49679ef00a --- /dev/null +++ b/tests/grid/grid_generator_subdivided_hyper_cube_01.output @@ -0,0 +1,15 @@ + +DEAL::dim = 2 +DEAL::cell: +DEAL::boundary id = 0 center = -1.00000 0.00000 faceidx = 1 +DEAL::boundary id = 1 center = 1.00000 0.00000 faceidx = 2 +DEAL::boundary id = 2 center = 0.00000 -1.00000 faceidx = 0 +DEAL::boundary id = 3 center = 0.00000 1.00000 faceidx = 3 +DEAL::dim = 3 +DEAL::cell: +DEAL::boundary id = 0 center = -1.00000 0.00000 0.00000 faceidx = 2 +DEAL::boundary id = 1 center = 1.00000 0.00000 0.00000 faceidx = 3 +DEAL::boundary id = 2 center = 0.00000 -1.00000 0.00000 faceidx = 0 +DEAL::boundary id = 3 center = 0.00000 1.00000 0.00000 faceidx = 4 +DEAL::boundary id = 4 center = 0.00000 0.00000 -1.00000 faceidx = 1 +DEAL::boundary id = 5 center = 0.00000 0.00000 1.00000 faceidx = 5