]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add Triangulation::active_face_iterators(). 7031/head
authorDavid Wells <drwells@email.unc.edu>
Mon, 6 Aug 2018 00:50:12 +0000 (20:50 -0400)
committerDavid Wells <drwells@email.unc.edu>
Mon, 6 Aug 2018 13:32:43 +0000 (09:32 -0400)
This function is like Triangulation::active_cell_iterators(), but for faces.

doc/news/changes/minor/20180805DavidWells [new file with mode: 0644]
include/deal.II/grid/tria.h
source/grid/tria.cc
tests/dofs/range_based_for_tria_face.cc [new file with mode: 0644]
tests/dofs/range_based_for_tria_face.output [new file with mode: 0644]
tests/grid/filtered_iterator_06.cc [new file with mode: 0644]
tests/grid/filtered_iterator_06.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20180805DavidWells b/doc/news/changes/minor/20180805DavidWells
new file mode 100644 (file)
index 0000000..9d133e0
--- /dev/null
@@ -0,0 +1,4 @@
+New: A convenience function Triangulation::active_face_iterators() (which is like
+Triangulation::active_cell_iterators(), but for faces) has been added.
+<br>
+(David Wells, 2018/08/05)
index bbba7634625ee9cd0e257ae5c1e5ea5b95b44d7d..fea118a11aeb566f84df2833577ebdd0c7f32c4f 100644 (file)
@@ -2823,6 +2823,27 @@ public:
   face_iterator
   end_face() const;
 
+  /**
+   * Return an iterator range that contains all active faces that make up this
+   * triangulation. This function is the face version of
+   * Triangulation::active_cell_iterators(), and allows one to write code
+   * like, e.g.,
+   *
+   * @code
+   *   Triangulation<dim> triangulation;
+   *   ...
+   *   for (auto &face : triangulation.active_face_iterators())
+   *     face->set_manifold_id(42);
+   * @endcode
+   *
+   * @return The half open range <code>[this->begin_active_face(),
+   * this->end_face())</code>
+   *
+   * @ingroup CPP11
+   */
+  IteratorRange<active_face_iterator>
+  active_face_iterators() const;
+
   /*
    * @}
    */
index e2325b8b61ee86ce095919e52d774c96940cd00b..947a120e0b1f024c0d78bb757c1fd2f7ec39d160 100644 (file)
@@ -12153,6 +12153,16 @@ Triangulation<dim, spacedim>::end_face() const
 }
 
 
+
+template <int dim, int spacedim>
+IteratorRange<typename Triangulation<dim, spacedim>::active_face_iterator>
+Triangulation<dim, spacedim>::active_face_iterators() const
+{
+  return IteratorRange<
+    typename Triangulation<dim, spacedim>::active_face_iterator>(
+    begin_active_face(), end_face());
+}
+
 /*------------------------ Vertex iterator functions ------------------------*/
 
 
diff --git a/tests/dofs/range_based_for_tria_face.cc b/tests/dofs/range_based_for_tria_face.cc
new file mode 100644 (file)
index 0000000..6ce8a7e
--- /dev/null
@@ -0,0 +1,58 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2018 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 face range-based for loops for triangulations
+
+#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 <string>
+
+#include "../tests.h"
+
+
+template <int dim, int spacedim>
+void
+check()
+{
+  Triangulation<dim, spacedim> tr;
+  GridGenerator::hyper_cube(tr);
+  tr.refine_global(2);
+
+  for (auto &face : tr.active_face_iterators())
+    face->set_manifold_id(42);
+
+  for (const auto &cell : tr.active_cell_iterators())
+    for (unsigned int face_n = 0; face_n < GeometryInfo<dim>::faces_per_cell;
+         ++face_n)
+      Assert(cell->face(face_n)->manifold_id() == 42, ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+int
+main()
+{
+  initlog();
+
+  check<2, 2>();
+  check<2, 3>();
+  check<3, 3>();
+}
diff --git a/tests/dofs/range_based_for_tria_face.output b/tests/dofs/range_based_for_tria_face.output
new file mode 100644 (file)
index 0000000..fb71de2
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::OK
+DEAL::OK
+DEAL::OK
diff --git a/tests/grid/filtered_iterator_06.cc b/tests/grid/filtered_iterator_06.cc
new file mode 100644 (file)
index 0000000..0ff0657
--- /dev/null
@@ -0,0 +1,88 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2018 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.
+
+#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 (unsigned int face_n = 0; face_n < GeometryInfo<dim>::faces_per_cell;
+         ++face_n)
+      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 : filter_iterators(
+         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.output b/tests/grid/filtered_iterator_06.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.