From 2fd34ac36d6eeb7ea939614c0deef3f3e16e4e72 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Wed, 5 Jan 2022 19:15:21 +0100 Subject: [PATCH] Add some more tests for iterator filters --- tests/grid/filtered_iterator_07.cc | 129 ++++++++++++++++++ tests/grid/filtered_iterator_07.output | 2 + tests/grid/filtered_iterator_07_operator.cc | 128 +++++++++++++++++ .../grid/filtered_iterator_07_operator.output | 2 + 4 files changed, 261 insertions(+) create mode 100644 tests/grid/filtered_iterator_07.cc create mode 100644 tests/grid/filtered_iterator_07.output create mode 100644 tests/grid/filtered_iterator_07_operator.cc create mode 100644 tests/grid/filtered_iterator_07_operator.output diff --git a/tests/grid/filtered_iterator_07.cc b/tests/grid/filtered_iterator_07.cc new file mode 100644 index 0000000000..e4d300d820 --- /dev/null +++ b/tests/grid/filtered_iterator_07.cc @@ -0,0 +1,129 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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 that we can create iterators filtered using ActiveFEIndexEqualTo. + + +#include + +#include + +#include +#include + +#include + +#include "../tests.h" + + +template +void +test() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria, 0, 1, true); + tria.refine_global(1); + + const FE_Q fe(1); + + DoFHandler dof_handler(tria); + dof_handler.distribute_dofs(fe); + + int n_cells_visited = 0; + for (const auto &cell : + filter_iterators(dof_handler.active_cell_iterators(), + IteratorFilters::ActiveFEIndexEqualTo(0))) + { + ++n_cells_visited; + (void)cell; + } + + Assert(n_cells_visited == Utilities::fixed_power(2), + ExcMessage("Wrong number of cells visited.")); + + n_cells_visited = 0; + for (const auto &cell : + filter_iterators(dof_handler.active_cell_iterators(), + IteratorFilters::ActiveFEIndexEqualTo(1))) + { + ++n_cells_visited; + (void)cell; + } + + Assert(n_cells_visited == 0, ExcMessage("Wrong number of cells visited.")); +} + + +template +void +test_hp() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria, 0, 1, true); + tria.refine_global(1); + + const hp::FECollection fe_collection{FE_Q(1), + FE_Q(1)}; + + DoFHandler dof_handler(tria); + + for (auto &cell : dof_handler.active_cell_iterators()) + if (cell == dof_handler.begin_active()) + cell->set_active_fe_index(1); + else + cell->set_active_fe_index(0); + + dof_handler.distribute_dofs(fe_collection); + + int n_cells_visited = 0; + for (const auto &cell : + filter_iterators(dof_handler.active_cell_iterators(), + IteratorFilters::ActiveFEIndexEqualTo(0))) + { + ++n_cells_visited; + (void)cell; + } + + Assert(n_cells_visited == Utilities::fixed_power(2) - 1, + ExcMessage("Wrong number of cells visited.")); + + n_cells_visited = 0; + for (const auto &cell : + filter_iterators(dof_handler.active_cell_iterators(), + IteratorFilters::ActiveFEIndexEqualTo(1))) + { + ++n_cells_visited; + (void)cell; + } + + Assert(n_cells_visited == 1, ExcMessage("Wrong number of cells visited.")); +} + + +int +main() +{ + initlog(); + + test<2, 2>(); + test<2, 3>(); + test<3, 3>(); + + test_hp<2, 2>(); + test_hp<2, 3>(); + test_hp<3, 3>(); + + deallog << "OK" << std::endl; +} diff --git a/tests/grid/filtered_iterator_07.output b/tests/grid/filtered_iterator_07.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/grid/filtered_iterator_07.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/grid/filtered_iterator_07_operator.cc b/tests/grid/filtered_iterator_07_operator.cc new file mode 100644 index 0000000000..6af9dc70c9 --- /dev/null +++ b/tests/grid/filtered_iterator_07_operator.cc @@ -0,0 +1,128 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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 that we can create iterators filtered using ActiveFEIndexEqualTo. +// +// Compared to filtered_iterator_07, this test checks the availability +// of operator| to create the filter. + + +#include + +#include + +#include +#include + +#include + +#include "../tests.h" + + +template +void +test() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria, 0, 1, true); + tria.refine_global(1); + + const FE_Q fe(1); + + DoFHandler dof_handler(tria); + dof_handler.distribute_dofs(fe); + + int n_cells_visited = 0; + for (const auto &cell : dof_handler.active_cell_iterators() | + IteratorFilters::ActiveFEIndexEqualTo(0)) + { + ++n_cells_visited; + (void)cell; + } + + Assert(n_cells_visited == Utilities::fixed_power(2), + ExcMessage("Wrong number of cells visited.")); + + n_cells_visited = 0; + for (const auto &cell : dof_handler.active_cell_iterators() | + IteratorFilters::ActiveFEIndexEqualTo(1)) + { + ++n_cells_visited; + (void)cell; + } + + Assert(n_cells_visited == 0, ExcMessage("Wrong number of cells visited.")); +} + + +template +void +test_hp() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria, 0, 1, true); + tria.refine_global(1); + + const hp::FECollection fe_collection{FE_Q(1), + FE_Q(1)}; + + DoFHandler dof_handler(tria); + + for (auto &cell : dof_handler.active_cell_iterators()) + if (cell == dof_handler.begin_active()) + cell->set_active_fe_index(1); + else + cell->set_active_fe_index(0); + + dof_handler.distribute_dofs(fe_collection); + + int n_cells_visited = 0; + for (const auto &cell : dof_handler.active_cell_iterators() | + IteratorFilters::ActiveFEIndexEqualTo(0)) + { + ++n_cells_visited; + (void)cell; + } + + Assert(n_cells_visited == Utilities::fixed_power(2) - 1, + ExcMessage("Wrong number of cells visited.")); + + n_cells_visited = 0; + for (const auto &cell : dof_handler.active_cell_iterators() | + IteratorFilters::ActiveFEIndexEqualTo(1)) + { + ++n_cells_visited; + (void)cell; + } + + Assert(n_cells_visited == 1, ExcMessage("Wrong number of cells visited.")); +} + + +int +main() +{ + initlog(); + + test<2, 2>(); + test<2, 3>(); + test<3, 3>(); + + test_hp<2, 2>(); + test_hp<2, 3>(); + test_hp<3, 3>(); + + deallog << "OK" << std::endl; +} diff --git a/tests/grid/filtered_iterator_07_operator.output b/tests/grid/filtered_iterator_07_operator.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/grid/filtered_iterator_07_operator.output @@ -0,0 +1,2 @@ + +DEAL::OK -- 2.39.5