]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add cell->face_iterators() 8569/head
authorPeter Munch <peterrmuench@gmail.com>
Wed, 14 Aug 2019 13:43:31 +0000 (15:43 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Thu, 15 Aug 2019 01:51:45 +0000 (03:51 +0200)
doc/news/changes/minor/20190814PeterMunchBangerthDanielArndt [new file with mode: 0644]
include/deal.II/grid/tria_accessor.h
include/deal.II/grid/tria_accessor.templates.h
tests/grid/accessor_02.cc [new file with mode: 0644]
tests/grid/accessor_02.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20190814PeterMunchBangerthDanielArndt b/doc/news/changes/minor/20190814PeterMunchBangerthDanielArndt
new file mode 100644 (file)
index 0000000..078af40
--- /dev/null
@@ -0,0 +1,3 @@
+New: Add an iterator over all faces of a cell(accessor).
+<br>
+(Peter Munch, Wolfgang Bangerth, Daniel Arndt, 2019/08/14)
index 3c53e712f2e6453d62b20a4d2f54834da39ae113..fbee75dc697d493a9326177638a4b3aa6e279011 100644 (file)
@@ -2733,6 +2733,14 @@ public:
   TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>
   face(const unsigned int i) const;
 
+
+  /**
+   * Return an array of iterators to all faces of this cell.
+   */
+  std::array<TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>,
+             GeometryInfo<dim>::faces_per_cell>
+  face_iterators() const;
+
   /**
    * Return the (global) index of the @p ith face of this cell.
    *
index e6965efb004426239c4d3d276968470497eddade..2f0b2b589b42d9bcd459397be787ddb05003aaa3 100644 (file)
@@ -3173,6 +3173,24 @@ CellAccessor<dim, spacedim>::face(const unsigned int i) const
 
 
 
+template <int dim, int spacedim>
+inline std::array<TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>,
+                  GeometryInfo<dim>::faces_per_cell>
+CellAccessor<dim, spacedim>::face_iterators() const
+{
+  std::array<TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>,
+             GeometryInfo<dim>::faces_per_cell>
+    face_iterators;
+
+  for (unsigned int i = 0; i < GeometryInfo<dim>::faces_per_cell; ++i)
+    face_iterators[i] =
+      dealii::internal::CellAccessorImplementation::get_face(*this, i);
+
+  return face_iterators;
+}
+
+
+
 template <int dim, int spacedim>
 inline unsigned int
 CellAccessor<dim, spacedim>::face_index(const unsigned int i) const
diff --git a/tests/grid/accessor_02.cc b/tests/grid/accessor_02.cc
new file mode 100644 (file)
index 0000000..5d783ee
--- /dev/null
@@ -0,0 +1,71 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2018 - 2019 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// TriaAccessor<0,dim,spacedim> and TriaAccessor<0,1,spacedim> lacked
+// get_triangulation() member functions because they are not derived
+// from TriaAccessorBase. This led to awkward follow-up errors in
+// strange places when using them in certain contexts.
+
+#include <deal.II/base/logstream.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 "../tests.h"
+
+using namespace dealii;
+
+
+template <int dim, int spacedim>
+void
+test()
+{
+  Triangulation<dim, spacedim> tria;
+  GridGenerator::hyper_cube(tria);
+  tria.refine_global(1);
+
+  std::map<typename Triangulation<dim, spacedim>::face_iterator, int> mymap;
+
+  for (auto &cell : tria.active_cell_iterators())
+    {
+      for (auto &face : cell->face_iterators())
+        {
+          if (mymap.find(face) == mymap.end())
+            {
+              mymap[face] = cell->index();
+            }
+        }
+    }
+
+  for (auto it : mymap)
+    deallog << it.first << ": " << it.second << std::endl;
+}
+
+
+int
+main()
+{
+  initlog();
+
+  test<1, 1>();
+  test<1, 2>();
+  test<2, 2>();
+  test<2, 3>();
+  test<3, 3>();
+}
diff --git a/tests/grid/accessor_02.output b/tests/grid/accessor_02.output
new file mode 100644 (file)
index 0000000..f3a1f23
--- /dev/null
@@ -0,0 +1,67 @@
+
+DEAL::0: 0
+DEAL::1: 1
+DEAL::2: 0
+DEAL::0: 0
+DEAL::1: 1
+DEAL::2: 0
+DEAL::4: 0
+DEAL::5: 1
+DEAL::6: 0
+DEAL::7: 2
+DEAL::8: 1
+DEAL::9: 3
+DEAL::10: 2
+DEAL::11: 3
+DEAL::12: 0
+DEAL::13: 2
+DEAL::14: 0
+DEAL::15: 1
+DEAL::4: 0
+DEAL::5: 1
+DEAL::6: 0
+DEAL::7: 2
+DEAL::8: 1
+DEAL::9: 3
+DEAL::10: 2
+DEAL::11: 3
+DEAL::12: 0
+DEAL::13: 2
+DEAL::14: 0
+DEAL::15: 1
+DEAL::6: 0
+DEAL::7: 4
+DEAL::8: 1
+DEAL::9: 5
+DEAL::10: 0
+DEAL::11: 1
+DEAL::12: 2
+DEAL::13: 3
+DEAL::14: 0
+DEAL::15: 2
+DEAL::16: 4
+DEAL::17: 6
+DEAL::18: 1
+DEAL::19: 3
+DEAL::20: 5
+DEAL::21: 7
+DEAL::22: 2
+DEAL::23: 6
+DEAL::24: 3
+DEAL::25: 7
+DEAL::26: 4
+DEAL::27: 5
+DEAL::28: 6
+DEAL::29: 7
+DEAL::30: 3
+DEAL::31: 2
+DEAL::32: 1
+DEAL::33: 0
+DEAL::34: 5
+DEAL::35: 1
+DEAL::36: 4
+DEAL::37: 0
+DEAL::38: 6
+DEAL::39: 4
+DEAL::40: 2
+DEAL::41: 0

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.