From 0f980562ba805d344617d55963e0c264b50e3544 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Thu, 30 Dec 2021 08:57:08 +0100 Subject: [PATCH] Add test coverage for BoundaryID and ManifoldID iterator filters --- tests/grid/filtered_iterator_06.cc | 53 ++++++++++++++------- tests/grid/filtered_iterator_06_operator.cc | 48 +++++++++++++------ 2 files changed, 71 insertions(+), 30 deletions(-) diff --git a/tests/grid/filtered_iterator_06.cc b/tests/grid/filtered_iterator_06.cc index 1603abbabc..a3af0aaead 100644 --- a/tests/grid/filtered_iterator_06.cc +++ b/tests/grid/filtered_iterator_06.cc @@ -31,7 +31,8 @@ void test() { Triangulation tria; - GridGenerator::hyper_cube(tria); + GridGenerator::hyper_cube(tria, 0, 1, true); + // refine the boundary cells a few times for (unsigned int i = 0; i < 5; ++i) { @@ -48,29 +49,49 @@ test() ++i; } - // Count the faces that are on the boundary and have a manifold_id of 0 + // Count the faces that are on the boundary and have a boundary_id of 0 and a + // manifold_id of 0 + const types::boundary_id boundary_id = 0; const types::manifold_id manifold_id = 0; std::set::active_face_iterator> - face_set; + boundary_face_set, manifold_face_set; + for (const auto &cell : tria.active_cell_iterators()) for (const unsigned int face_n : GeometryInfo::face_indices()) - if (cell->face(face_n)->at_boundary() && - cell->face(face_n)->manifold_id() == manifold_id) - face_set.insert(cell->face(face_n)); + if (cell->face(face_n)->at_boundary()) + { + if (cell->face(face_n)->boundary_id() == boundary_id) + boundary_face_set.insert(cell->face(face_n)); + + if (cell->face(face_n)->manifold_id() == manifold_id) + manifold_face_set.insert(cell->face(face_n)); + } + + std::size_t n_boundary_filtered_cells = 0; + for (const auto &filtered_cell : + filter_iterators(tria.active_face_iterators(), + IteratorFilters::AtBoundary(), + IteratorFilters::BoundaryIdEqualTo(boundary_id))) + { + AssertThrow(boundary_face_set.count(filtered_cell) == 1, + ExcMessage("Wrong cell filtered.")); + ++n_boundary_filtered_cells; + } + AssertThrow(n_boundary_filtered_cells == boundary_face_set.size(), + ExcMessage("Boundary filtered cells missing.")); - std::size_t n_filtered_cells = 0; - for (const auto filtered_cell : filter_iterators( - tria.active_face_iterators(), - IteratorFilters::AtBoundary(), - [=](const typename Triangulation::active_face_iterator - &face) { return face->manifold_id() == manifold_id; })) + std::size_t n_manifold_filtered_cells = 0; + for (const auto &filtered_cell : + filter_iterators(tria.active_face_iterators(), + IteratorFilters::AtBoundary(), + IteratorFilters::ManifoldIdEqualTo(manifold_id))) { - AssertThrow(face_set.count(filtered_cell) == 1, + AssertThrow(manifold_face_set.count(filtered_cell) == 1, ExcMessage("Wrong cell filtered.")); - ++n_filtered_cells; + ++n_manifold_filtered_cells; } - AssertThrow(n_filtered_cells == face_set.size(), - ExcMessage("Filtered cells missing.")); + AssertThrow(n_manifold_filtered_cells == manifold_face_set.size(), + ExcMessage("Manifold filtered cells missing.")); } int diff --git a/tests/grid/filtered_iterator_06_operator.cc b/tests/grid/filtered_iterator_06_operator.cc index 2d8cfcc09b..4a0377b7a8 100644 --- a/tests/grid/filtered_iterator_06_operator.cc +++ b/tests/grid/filtered_iterator_06_operator.cc @@ -34,7 +34,8 @@ void test() { Triangulation tria; - GridGenerator::hyper_cube(tria); + GridGenerator::hyper_cube(tria, 0, 1, true); + // refine the boundary cells a few times for (unsigned int i = 0; i < 5; ++i) { @@ -51,28 +52,47 @@ test() ++i; } - // Count the faces that are on the boundary and have a manifold_id of 0 + // Count the faces that are on the boundary and have a boundary_id of 0 and a + // manifold_id of 0 + const types::boundary_id boundary_id = 0; const types::manifold_id manifold_id = 0; std::set::active_face_iterator> - face_set; + boundary_face_set, manifold_face_set; + for (const auto &cell : tria.active_cell_iterators()) for (const unsigned int face_n : GeometryInfo::face_indices()) - if (cell->face(face_n)->at_boundary() && - cell->face(face_n)->manifold_id() == manifold_id) - face_set.insert(cell->face(face_n)); + if (cell->face(face_n)->at_boundary()) + { + if (cell->face(face_n)->boundary_id() == boundary_id) + boundary_face_set.insert(cell->face(face_n)); + + if (cell->face(face_n)->manifold_id() == manifold_id) + manifold_face_set.insert(cell->face(face_n)); + } + + std::size_t n_boundary_filtered_cells = 0; + for (const auto &filtered_cell : + tria.active_face_iterators() | IteratorFilters::AtBoundary() | + IteratorFilters::BoundaryIdEqualTo(boundary_id)) + { + AssertThrow(boundary_face_set.count(filtered_cell) == 1, + ExcMessage("Wrong cell filtered.")); + ++n_boundary_filtered_cells; + } + AssertThrow(n_boundary_filtered_cells == boundary_face_set.size(), + ExcMessage("Boundary filtered cells missing.")); - std::size_t n_filtered_cells = 0; - for (const auto filtered_cell : + std::size_t n_manifold_filtered_cells = 0; + for (const auto &filtered_cell : tria.active_face_iterators() | IteratorFilters::AtBoundary() | - [=](const typename Triangulation::active_face_iterator - &face) { return face->manifold_id() == manifold_id; }) + IteratorFilters::ManifoldIdEqualTo(manifold_id)) { - AssertThrow(face_set.count(filtered_cell) == 1, + AssertThrow(manifold_face_set.count(filtered_cell) == 1, ExcMessage("Wrong cell filtered.")); - ++n_filtered_cells; + ++n_manifold_filtered_cells; } - AssertThrow(n_filtered_cells == face_set.size(), - ExcMessage("Filtered cells missing.")); + AssertThrow(n_manifold_filtered_cells == manifold_face_set.size(), + ExcMessage("Manifold filtered cells missing.")); } int -- 2.39.5