]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add tests.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 16 Nov 2021 01:29:52 +0000 (18:29 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 17 Nov 2021 04:39:57 +0000 (21:39 -0700)
tests/grid/filtered_iterator_04.cc
tests/grid/filtered_iterator_04_operator.cc [new file with mode: 0644]
tests/grid/filtered_iterator_04_operator.output [new file with mode: 0644]
tests/grid/filtered_iterator_06_operator.cc [new file with mode: 0644]
tests/grid/filtered_iterator_06_operator.output [new file with mode: 0644]

index 87ed02bef7b5f6a60d49a1999a47069e1918a2ba..a902d7822b89a94b214c49fae03bf58f07fedc22 100644 (file)
@@ -14,7 +14,7 @@
 // ---------------------------------------------------------------------
 
 
-// check filtered iterators using multiple predicate
+// check filtered iterators using multiple predicates
 
 #include <deal.II/grid/filtered_iterator.h>
 #include <deal.II/grid/grid_generator.h>
diff --git a/tests/grid/filtered_iterator_04_operator.cc b/tests/grid/filtered_iterator_04_operator.cc
new file mode 100644 (file)
index 0000000..6ff6fae
--- /dev/null
@@ -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 <deal.II/grid/filtered_iterator.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/tria_iterator.h>
+
+#include <set>
+
+#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<active_cell_iterator> 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 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -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 (file)
index 0000000..2d8cfcc
--- /dev/null
@@ -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 <deal.II/grid/filtered_iterator.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/tria_iterator.h>
+
+#include <set>
+
+#include "../tests.h"
+
+template <int dim, int spacedim>
+void
+test()
+{
+  Triangulation<dim, spacedim> 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<typename Triangulation<dim, spacedim>::active_face_iterator>
+    face_set;
+  for (const auto &cell : tria.active_cell_iterators())
+    for (const unsigned int face_n : GeometryInfo<dim>::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<dim, spacedim>::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 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.