]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test for IteratorFilter::AtBoundary.
authorBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 22 Feb 2016 23:08:41 +0000 (18:08 -0500)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Fri, 4 Mar 2016 14:26:13 +0000 (09:26 -0500)
tests/grid/filtered_iterator_04.cc [new file with mode: 0644]
tests/grid/filtered_iterator_04.output [new file with mode: 0644]

diff --git a/tests/grid/filtered_iterator_04.cc b/tests/grid/filtered_iterator_04.cc
new file mode 100644 (file)
index 0000000..2cae8c5
--- /dev/null
@@ -0,0 +1,88 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// check filtered iterators using two predicate
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria_iterator.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/filtered_iterator.h>
+#include <set>
+
+typedef Triangulation<2>::active_cell_iterator 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);
+
+  const IteratorFilters::AtBoundary predicate_1;
+  const IteratorFilters::SubdomainEqualTo predicate_2(0);
+  FilteredIterator<active_cell_iterator> fi_cell(predicate_1),
+                   end_fi_cell(predicate_1, tria.end());
+  fi_cell.set_to_next_positive(tria.begin_active());
+  FilteredIterator<FilteredIterator<active_cell_iterator> > filtered_cell(predicate_2, fi_cell),
+                   end_filtered_cell(predicate_2, end_fi_cell);
+  unsigned int n_filtered_cells = 0;
+  for (; filtered_cell!=end_filtered_cell; ++filtered_cell)
+    {
+      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);
+  deallog.threshold_double(1.e-10);
+
+  test ();
+
+  deallog << "OK" << std::endl;;
+
+  return 0;
+}
+
diff --git a/tests/grid/filtered_iterator_04.output b/tests/grid/filtered_iterator_04.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.