From 82099399ccfeea3bc6a6b2e58f287170c86abc1d Mon Sep 17 00:00:00 2001 From: David Wells Date: Sun, 27 Oct 2019 15:13:33 -0400 Subject: [PATCH] Implement two helper index functions in (Cell,Tria)Accessor. --- doc/news/changes/minor/20191027DavidWells-2 | 5 ++ include/deal.II/grid/tria_accessor.h | 27 +++++++++ .../deal.II/grid/tria_accessor.templates.h | 55 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 doc/news/changes/minor/20191027DavidWells-2 diff --git a/doc/news/changes/minor/20191027DavidWells-2 b/doc/news/changes/minor/20191027DavidWells-2 new file mode 100644 index 0000000000..ea7c1035a6 --- /dev/null +++ b/doc/news/changes/minor/20191027DavidWells-2 @@ -0,0 +1,5 @@ +New: Added convenience functions CellAccessor::face_iterator_to_index() +and TriaAccessor::child_iterator_to_index() for computing face and child numbers +from iterators. +
+(David Wells, 2019/10/27) diff --git a/include/deal.II/grid/tria_accessor.h b/include/deal.II/grid/tria_accessor.h index b0d530c8cb..f961522042 100644 --- a/include/deal.II/grid/tria_accessor.h +++ b/include/deal.II/grid/tria_accessor.h @@ -982,6 +982,14 @@ public: TriaIterator> child(const unsigned int i) const; + /** + * Return the child number of @p child on the current cell. This is the + * inverse function of TriaAccessor::child(). + */ + unsigned int + child_iterator_to_index( + const TriaIterator> &child) const; + /** * Return an iterator to that object that is identical to the ith child for * isotropic refinement. If the current object is refined isotropically, @@ -2044,6 +2052,12 @@ public: static unsigned int max_refinement_depth(); + /** + * @brief Return an invalid unsigned integer. + */ + static unsigned int + child_iterator_to_index(const TriaIterator> &); + /** * @brief Return an invalid object. */ @@ -2497,6 +2511,12 @@ public: static unsigned int max_refinement_depth(); + /** + * @brief Return an invalid unsigned integer. + */ + static unsigned int + child_iterator_to_index(const TriaIterator> &); + /** * @brief Return an invalid object */ @@ -2735,6 +2755,13 @@ public: TriaIterator> face(const unsigned int i) const; + /** + * Return the face number of @p face on the current cell. This is the + * inverse function of TriaAccessor::face(). + */ + unsigned int + face_iterator_to_index( + const TriaIterator> &face) const; /** * Return an array of iterators to all faces of this cell. diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index 13d98ab322..01c730bf4e 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -1510,6 +1510,23 @@ TriaAccessor::child(const unsigned int i) const +template +inline unsigned int +TriaAccessor::child_iterator_to_index( + const TriaIterator> &child) const +{ + const auto n_children = this->n_children(); + for (unsigned int child_n = 0; child_n < n_children; ++child_n) + if (this->child(child_n) == child) + return child_n; + + Assert(false, + ExcMessage("The given child is not a child of the current object.")); + return numbers::invalid_unsigned_int; +} + + + template inline TriaIterator> TriaAccessor::isotropic_child( @@ -2590,6 +2607,16 @@ TriaAccessor<0, dim, spacedim>::max_refinement_depth() +template +inline unsigned int +TriaAccessor<0, dim, spacedim>::child_iterator_to_index( + const TriaIterator> &) +{ + return numbers::invalid_unsigned_int; +} + + + template inline TriaIterator> TriaAccessor<0, dim, spacedim>::child(const unsigned int) @@ -3004,6 +3031,17 @@ TriaAccessor<0, 1, spacedim>::max_refinement_depth() } + +template +inline unsigned int +TriaAccessor<0, 1, spacedim>::child_iterator_to_index( + const TriaIterator> &) +{ + return numbers::invalid_unsigned_int; +} + + + template inline TriaIterator> TriaAccessor<0, 1, spacedim>::child(const unsigned int) @@ -3181,6 +3219,23 @@ CellAccessor::face(const unsigned int i) const +template +inline unsigned int +CellAccessor::face_iterator_to_index( + const TriaIterator> &face) const +{ + for (unsigned int face_n = 0; face_n < GeometryInfo::faces_per_cell; + ++face_n) + if (this->face(face_n) == face) + return face_n; + + Assert(false, + ExcMessage("The given face is not a face of the current cell.")); + return numbers::invalid_unsigned_int; +} + + + template inline std::array>, GeometryInfo::faces_per_cell> -- 2.39.5