From bf30ebf803ed0ce4d792af043b7a49d220b894e5 Mon Sep 17 00:00:00 2001
From: Ali Samii <a.samii@gmail.com>
Date: Thu, 24 Mar 2016 10:47:30 -0500
Subject: [PATCH] Added neighbor_or_periodic_neighbor

neighbor_or_periodic_neighbor is added.

Added neighbor_or_periodic_neighbor
---
 include/deal.II/grid/tria_accessor.h | 15 +++++++++++++--
 source/grid/tria_accessor.cc         | 15 +++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/include/deal.II/grid/tria_accessor.h b/include/deal.II/grid/tria_accessor.h
index 1e863e86bc..5ddae5fa41 100644
--- a/include/deal.II/grid/tria_accessor.h
+++ b/include/deal.II/grid/tria_accessor.h
@@ -2526,6 +2526,16 @@ public:
   TriaIterator<CellAccessor<dim, spacedim> >
   periodic_neighbor (const unsigned int i) const;
 
+  /**
+   * For a cell whose @c ith face is not at a boundary, this function returns
+   * the same result as neighbor(). If the @c ith face is at a periodic boundary
+   * this function returns the same result as periodic_neighbor(). If neither of
+   * the aforementioned conditions are met, i.e. the @c ith face is on a
+   * nonperiodic boundary, an exception will be thrown.
+   */
+  TriaIterator<CellAccessor<dim, spacedim> >
+  neighbor_or_periodic_neighbor (const unsigned int i) const;
+
   /**
    * Returns an iterator to the periodic neighbor of the cell at a given
    * face and subface number. The general guidelines for using this function
@@ -2588,8 +2598,9 @@ public:
   periodic_neighbor_of_periodic_neighbor (const unsigned int i) const;
 
   /**
-   * If a cell has periodic neighbor, this function returns the face number
-   * of the neighbor, which is connected to this cell.
+   * If a cell has a periodic neighbor at its @c ith face, this function
+   * returns the face number of the periodic neighbor, which is connected
+   * to the @c ith face of this cell.
    */
   unsigned int
   periodic_neighbor_face_no (const unsigned int i) const;
diff --git a/source/grid/tria_accessor.cc b/source/grid/tria_accessor.cc
index 0cf66d063b..4377710d09 100644
--- a/source/grid/tria_accessor.cc
+++ b/source/grid/tria_accessor.cc
@@ -1933,6 +1933,21 @@ periodic_neighbor (const unsigned int i_face) const
 
 
 
+template <int dim, int spacedim>
+TriaIterator<CellAccessor<dim,spacedim> >
+CellAccessor<dim, spacedim>::
+neighbor_or_periodic_neighbor (const unsigned int i_face) const
+{
+  if (!(this->face(i_face)->at_boundary()))
+    return this->neighbor(i_face);
+  else if (this->has_periodic_neighbor(i_face))
+    return this->periodic_neighbor(i_face);
+  else
+    Assert (false, TriaAccessorExceptions::ExcNoPeriodicNeighbor());
+}
+
+
+
 template <int dim, int spacedim>
 TriaIterator<CellAccessor<dim, spacedim> >
 CellAccessor<dim, spacedim>::
-- 
2.39.5