From: Peter Munch Date: Wed, 14 Aug 2019 13:43:31 +0000 (+0200) Subject: Add cell->face_iterators() X-Git-Tag: v9.2.0-rc1~1232^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c88e78d86d5095f7799cfb3315ee6a7b58459cf3;p=dealii.git Add cell->face_iterators() --- diff --git a/doc/news/changes/minor/20190814PeterMunchBangerthDanielArndt b/doc/news/changes/minor/20190814PeterMunchBangerthDanielArndt new file mode 100644 index 0000000000..078af40ff4 --- /dev/null +++ b/doc/news/changes/minor/20190814PeterMunchBangerthDanielArndt @@ -0,0 +1,3 @@ +New: Add an iterator over all faces of a cell(accessor). +
+(Peter Munch, Wolfgang Bangerth, Daniel Arndt, 2019/08/14) diff --git a/include/deal.II/grid/tria_accessor.h b/include/deal.II/grid/tria_accessor.h index 3c53e712f2..fbee75dc69 100644 --- a/include/deal.II/grid/tria_accessor.h +++ b/include/deal.II/grid/tria_accessor.h @@ -2733,6 +2733,14 @@ public: TriaIterator> face(const unsigned int i) const; + + /** + * Return an array of iterators to all faces of this cell. + */ + std::array>, + GeometryInfo::faces_per_cell> + face_iterators() const; + /** * Return the (global) index of the @p ith face of this cell. * diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index e6965efb00..2f0b2b589b 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -3173,6 +3173,24 @@ CellAccessor::face(const unsigned int i) const +template +inline std::array>, + GeometryInfo::faces_per_cell> +CellAccessor::face_iterators() const +{ + std::array>, + GeometryInfo::faces_per_cell> + face_iterators; + + for (unsigned int i = 0; i < GeometryInfo::faces_per_cell; ++i) + face_iterators[i] = + dealii::internal::CellAccessorImplementation::get_face(*this, i); + + return face_iterators; +} + + + template inline unsigned int CellAccessor::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 index 0000000000..5d783ee32f --- /dev/null +++ b/tests/grid/accessor_02.cc @@ -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 + +#include +#include +#include +#include + +#include "../tests.h" + +using namespace dealii; + + +template +void +test() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(1); + + std::map::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 index 0000000000..f3a1f23a0c --- /dev/null +++ b/tests/grid/accessor_02.output @@ -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