From 749866f494c0c7819498b91f9fd53667f9f04096 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 10 Jul 2018 01:34:10 +0200 Subject: [PATCH] Fix GridGenerator::merge_triangulations docu and use switch --- include/deal.II/grid/grid_generator.h | 6 +- source/grid/grid_generator.cc | 170 ++++++++++++++------------ 2 files changed, 94 insertions(+), 82 deletions(-) diff --git a/include/deal.II/grid/grid_generator.h b/include/deal.II/grid/grid_generator.h index b801236da0..44eaaecbaa 100644 --- a/include/deal.II/grid/grid_generator.h +++ b/include/deal.II/grid/grid_generator.h @@ -985,10 +985,10 @@ namespace GridGenerator * * @note The function copies the material ids of the cells of the two input * triangulations into the output triangulation. If @p copy_manifold_ids is - * activated, manifold ids will be copied. Currently, boundary_ids are never + * set to @p true, manifold ids will be copied. Boundary indicators are never * copied. In other words, if the two coarse meshes have anything but the - * default boundary indicators, then you will currently have to set boundary - * indicators again by hand in the output triangulation. + * default boundary indicators, then you will have to set boundary indicators + * again by hand in the output triangulation. * * @note Unlike most GridGenerator functions, this function does not attach * any manifolds to @p result, nor does it set any manifold ids. diff --git a/source/grid/grid_generator.cc b/source/grid/grid_generator.cc index f994bf8ecd..efae7cc64a 100644 --- a/source/grid/grid_generator.cc +++ b/source/grid/grid_generator.cc @@ -3839,89 +3839,101 @@ namespace GridGenerator SubCellData subcell_data; if (copy_manifold_ids) { - if (dim == 2) + switch (dim) { - subcell_data.boundary_lines.reserve(triangulation_1.n_lines() + - triangulation_2.n_lines()); - - auto copy_line_manifold_ids = - [&](const Triangulation &tria, - const unsigned int offset) { - for (typename Triangulation::line_iterator line = - tria.begin_face(); - line != tria.end_face(); - ++line) - if (line->manifold_id() != numbers::flat_manifold_id) - { - CellData<1> boundary_line; - boundary_line.vertices[0] = - line->vertex_index(0) + offset; - boundary_line.vertices[1] = - line->vertex_index(1) + offset; - boundary_line.manifold_id = line->manifold_id(); - subcell_data.boundary_lines.push_back( - std::move(boundary_line)); - } - }; + case 1: + break; - copy_line_manifold_ids(triangulation_1, 0); - copy_line_manifold_ids(triangulation_2, - triangulation_1.n_vertices()); - } + case 2: + { + subcell_data.boundary_lines.reserve(triangulation_1.n_lines() + + triangulation_2.n_lines()); + + auto copy_line_manifold_ids = + [&](const Triangulation &tria, + const unsigned int offset) { + for (typename Triangulation::line_iterator + line = tria.begin_face(); + line != tria.end_face(); + ++line) + if (line->manifold_id() != numbers::flat_manifold_id) + { + CellData<1> boundary_line; + boundary_line.vertices[0] = + line->vertex_index(0) + offset; + boundary_line.vertices[1] = + line->vertex_index(1) + offset; + boundary_line.manifold_id = line->manifold_id(); + subcell_data.boundary_lines.push_back( + std::move(boundary_line)); + } + }; - if (dim == 3) - { - subcell_data.boundary_quads.reserve(triangulation_1.n_quads() + - triangulation_2.n_quads()); - // we can't do better here than to loop over all the lines bounding - // a face. For regular meshes an (interior) line in 3D is part of - // four cells. So this should be an appropriate guess. - subcell_data.boundary_lines.reserve(triangulation_1.n_cells() * 4 + - triangulation_2.n_cells() * 4); - - auto copy_face_and_line_manifold_ids = - [&](const Triangulation &tria, - const unsigned int offset) { - for (typename Triangulation::face_iterator face = - tria.begin_face(); - face != tria.end_face(); - ++face) - if (face->manifold_id() != numbers::flat_manifold_id) - { - CellData<2> boundary_quad; - boundary_quad.vertices[0] = - face->vertex_index(0) + offset; - boundary_quad.vertices[1] = - face->vertex_index(1) + offset; - boundary_quad.vertices[2] = - face->vertex_index(2) + offset; - boundary_quad.vertices[3] = - face->vertex_index(3) + offset; - - boundary_quad.manifold_id = face->manifold_id(); - subcell_data.boundary_quads.push_back( - std::move(boundary_quad)); - } - for (const auto &cell : tria.cell_iterators()) - for (unsigned int l = 0; l < 12; ++l) - if (cell->line(l)->manifold_id() != - numbers::flat_manifold_id) - { - CellData<1> boundary_line; - boundary_line.vertices[0] = - cell->line(l)->vertex_index(0) + offset; - boundary_line.vertices[1] = - cell->line(l)->vertex_index(1) + offset; - boundary_line.manifold_id = - cell->line(l)->manifold_id(); - subcell_data.boundary_lines.push_back( - std::move(boundary_line)); - } - }; + copy_line_manifold_ids(triangulation_1, 0); + copy_line_manifold_ids(triangulation_2, + triangulation_1.n_vertices()); + break; + } + + case 3: + { + subcell_data.boundary_quads.reserve(triangulation_1.n_quads() + + triangulation_2.n_quads()); + // we can't do better here than to loop over all the lines + // bounding a face. For regular meshes an (interior) line in 3D + // is part of four cells. So this should be an appropriate + // guess. + subcell_data.boundary_lines.reserve( + triangulation_1.n_cells() * 4 + + triangulation_2.n_cells() * 4); + + auto copy_face_and_line_manifold_ids = + [&](const Triangulation &tria, + const unsigned int offset) { + for (typename Triangulation::face_iterator + face = tria.begin_face(); + face != tria.end_face(); + ++face) + if (face->manifold_id() != numbers::flat_manifold_id) + { + CellData<2> boundary_quad; + boundary_quad.vertices[0] = + face->vertex_index(0) + offset; + boundary_quad.vertices[1] = + face->vertex_index(1) + offset; + boundary_quad.vertices[2] = + face->vertex_index(2) + offset; + boundary_quad.vertices[3] = + face->vertex_index(3) + offset; + + boundary_quad.manifold_id = face->manifold_id(); + subcell_data.boundary_quads.push_back( + std::move(boundary_quad)); + } + for (const auto &cell : tria.cell_iterators()) + for (unsigned int l = 0; l < 12; ++l) + if (cell->line(l)->manifold_id() != + numbers::flat_manifold_id) + { + CellData<1> boundary_line; + boundary_line.vertices[0] = + cell->line(l)->vertex_index(0) + offset; + boundary_line.vertices[1] = + cell->line(l)->vertex_index(1) + offset; + boundary_line.manifold_id = + cell->line(l)->manifold_id(); + subcell_data.boundary_lines.push_back( + std::move(boundary_line)); + } + }; - copy_face_and_line_manifold_ids(triangulation_1, 0); - copy_face_and_line_manifold_ids(triangulation_2, - triangulation_1.n_vertices()); + copy_face_and_line_manifold_ids(triangulation_1, 0); + copy_face_and_line_manifold_ids(triangulation_2, + triangulation_1.n_vertices()); + break; + } + default: + Assert(false, ExcNotImplemented()); } } -- 2.39.5