From: Wolfgang Bangerth Date: Tue, 16 Nov 2021 01:29:52 +0000 (-0700) Subject: Add tests. X-Git-Tag: v9.4.0-rc1~825^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e502f30288c2e2864dd38dd7dd1cc3b88ed219f;p=dealii.git Add tests. --- diff --git a/tests/grid/filtered_iterator_04.cc b/tests/grid/filtered_iterator_04.cc index 87ed02bef7..a902d7822b 100644 --- a/tests/grid/filtered_iterator_04.cc +++ b/tests/grid/filtered_iterator_04.cc @@ -14,7 +14,7 @@ // --------------------------------------------------------------------- -// check filtered iterators using multiple predicate +// check filtered iterators using multiple predicates #include #include diff --git a/tests/grid/filtered_iterator_04_operator.cc b/tests/grid/filtered_iterator_04_operator.cc new file mode 100644 index 0000000000..6ff6faea13 --- /dev/null +++ b/tests/grid/filtered_iterator_04_operator.cc @@ -0,0 +1,90 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 - 2021 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// Check filtered iterators using multiple predicates +// +// Compared to filtered_iterator_04, this test checks the availability +// of operator| to create the filter. + +#include +#include +#include +#include +#include + +#include + +#include "../tests.h" + +using active_cell_iterator = Triangulation<2>::active_cell_iterator; + +void +test() +{ + Triangulation<2> tria; + GridGenerator::hyper_cube(tria, -1, 1); + tria.refine_global(1); + tria.begin_active()->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + tria.refine_global(2); + + // we now have a number of cells, + // flag them with some subdomain + // ids based on their position, in + // particular we take the quadrant + // (octant) + active_cell_iterator cell = tria.begin_active(), endc = tria.end(); + for (unsigned int i = 0; cell != endc; ++cell) + { + unsigned int subdomain = i % 3; + + cell->set_subdomain_id(subdomain); + ++i; + }; + + // Count the cells that are on the boundary and have a subdomain_id of 0 + std::set cell_set; + for (cell = tria.begin_active(); cell != endc; ++cell) + if ((cell->subdomain_id() == 0) && (cell->at_boundary())) + cell_set.insert(cell); + + + unsigned int n_filtered_cells = 0; + for (auto filtered_cell : tria.active_cell_iterators() | + IteratorFilters::AtBoundary() | + IteratorFilters::SubdomainEqualTo(0)) + { + AssertThrow(cell_set.count(filtered_cell) == 1, + ExcMessage("Wrong cell filtered.")); + ++n_filtered_cells; + } + AssertThrow(n_filtered_cells == cell_set.size(), + ExcMessage("Filtered cells missing.")); +} + +int +main() +{ + initlog(); + deallog << std::setprecision(4); + + test(); + + deallog << "OK" << std::endl; + ; + + return 0; +} diff --git a/tests/grid/filtered_iterator_04_operator.output b/tests/grid/filtered_iterator_04_operator.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/grid/filtered_iterator_04_operator.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/grid/filtered_iterator_06_operator.cc b/tests/grid/filtered_iterator_06_operator.cc new file mode 100644 index 0000000000..2d8cfcc09b --- /dev/null +++ b/tests/grid/filtered_iterator_06_operator.cc @@ -0,0 +1,89 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 - 2020 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// check that we can create filtered face iterators from a face iterator +// range. Similar to filtered_iterator_05. +// +// Compared to filtered_iterator_06, this test checks the availability +// of operator| to create the filter. + +#include +#include +#include +#include +#include + +#include + +#include "../tests.h" + +template +void +test() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria); + // refine the boundary cells a few times + for (unsigned int i = 0; i < 5; ++i) + { + for (auto &cell : tria.active_cell_iterators()) + cell->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + } + + // we now have a number of cells, flag them with some manifold ids + std::size_t i = 0; + for (auto &cell : tria.active_cell_iterators()) + { + cell->set_all_manifold_ids(i % 3); + ++i; + } + + // Count the faces that are on the boundary and have a manifold_id of 0 + const types::manifold_id manifold_id = 0; + std::set::active_face_iterator> + 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)); + + std::size_t n_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; }) + { + AssertThrow(face_set.count(filtered_cell) == 1, + ExcMessage("Wrong cell filtered.")); + ++n_filtered_cells; + } + AssertThrow(n_filtered_cells == face_set.size(), + ExcMessage("Filtered cells missing.")); +} + +int +main() +{ + initlog(); + deallog << std::setprecision(4); + + test<2, 2>(); + test<2, 3>(); + test<3, 3>(); + + deallog << "OK" << std::endl; +} diff --git a/tests/grid/filtered_iterator_06_operator.output b/tests/grid/filtered_iterator_06_operator.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/grid/filtered_iterator_06_operator.output @@ -0,0 +1,2 @@ + +DEAL::OK