]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Take over implementation of the CellAccessor<dim>::neighbor_of_coarser_neighbor funct...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 21 Nov 2001 10:59:03 +0000 (10:59 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 21 Nov 2001 10:59:03 +0000 (10:59 +0000)
git-svn-id: https://svn.dealii.org/branches/Branch-3-2@5231 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/grid/tria_accessor.h
deal.II/deal.II/source/grid/tria_accessor.cc

index 5385ceff5e76133f10eeadcf1f9c5022271e062c..dbfc55ccd37672c9088e1aa7860ca8237f14b63b 100644 (file)
@@ -17,6 +17,7 @@
 #include <base/exceptions.h>
 #include <grid/tria_iterator_base.h>
 
+
 template <int dim> class Point;
 
 template <int dim> class Triangulation;
@@ -26,6 +27,12 @@ template <int dim, typename Accessor> class TriaActiveIterator;
 class Line;
 class Quad;
 class Hexahedron;
+namespace std
+{
+  template<class T1, class T2>
+  struct pair;
+}
+
 
 
 // note: the file tria_accessor.templates.h is included at the end of
@@ -220,6 +227,10 @@ class TriaAccessor
                                      * Exception
                                      */
     DeclException0 (ExcNeighborIsCoarser);
+                                    /**
+                                     * Exception
+                                     */
+    DeclException0 (ExcNeighborIsNotCoarser);
                                     /*@}*/
        
   protected:
@@ -1856,15 +1867,25 @@ class CellAccessor :  public TriaObjectAccessor<dim,dim>
                                      * the present cell
                                      * (i.e. @p{cell->neighbor(neighbor)->level()}
                                      * needs to be equal to
-                                     * @p{cell->level()}, since
-                                     * otherwise the neighbors of the
-                                     * neighbor cell are on a coarser
-                                     * level than the present one and
-                                     * you can't get back from there
-                                     * to this cell.
+                                     * @p{cell->level()}. Use the
+                                     * @p{neighbor_of_coarser_neighbor}
+                                     * function in that case.
                                      */
     unsigned int neighbor_of_neighbor (const unsigned int neighbor) const;
     
+                                    /**
+                                     * This function is a
+                                     * generalization of the
+                                     * @p{neighbor_of_neighbor}
+                                     * function for the case of a
+                                     * coarser neighbor. It returns a
+                                     * pair of numbers, face_no and
+                                     * subface_no, with the following
+                                     * property:
+                                     * @p{cell->neighbor(neighbor)->face(face_no)->child(subface_no)==cell}.
+                                     */
+    std::pair<unsigned int, unsigned int> neighbor_of_coarser_neighbor (const unsigned int neighbor) const;
+    
                                     /**
                                      *  Return whether the @p{i}th
                                      *  vertex or face (depending on
index c1c548281d1e9985287ab19ed6cf166c99b54e14..5019e76d6974fea1006dc8a11a4beacd79b8c80c 100644 (file)
@@ -1786,6 +1786,71 @@ unsigned int CellAccessor<dim>::neighbor_of_neighbor (const unsigned int neighbo
 
 
 
+template <int dim>
+pair<unsigned int, unsigned int>
+CellAccessor<dim>::neighbor_of_coarser_neighbor (const unsigned int neighbor) const
+{
+                                  // make sure that the neighbor is
+                                  // on a coarser level
+  Assert (neighbor_level(neighbor) < present_level,
+         typename TriaAccessor<dim>::ExcNeighborIsNotCoarser());
+  Assert (neighbor < GeometryInfo<dim>::faces_per_cell,
+         typename TriaAccessor<dim>::ExcInvalidNeighbor(neighbor));
+
+  const TriaIterator<dim,TriaObjectAccessor<dim-1, dim> > this_face=face(neighbor);
+  const TriaIterator<dim,CellAccessor<dim> > neighbor_cell = this->neighbor(neighbor);
+  
+                                  // usually, on regular patches of
+                                  // the grid, this cell is just on
+                                  // the opposite side of the
+                                  // neighbor that the neighbor is of
+                                  // this cell. for example in 2d, if
+                                  // we want to know the
+                                  // neighbor_of_neighbor if
+                                  // neighbor==1 (the right
+                                  // neighbor), then we will get 3
+                                  // (the left neighbor) in most
+                                  // cases. look up this relationship
+                                  // in the table provided by
+                                  // GeometryInfo and try it
+  const unsigned int face_no_guess
+    = GeometryInfo<dim>::opposite_face[neighbor];
+
+  const TriaIterator<dim,TriaObjectAccessor<dim-1, dim> > face_guess
+    =neighbor_cell->face(face_no_guess);
+  
+  if (face_guess->has_children())
+    for (unsigned int subface_no=0; subface_no<GeometryInfo<dim>::subfaces_per_face; ++subface_no)
+      if (face_guess->child(subface_no)==this_face)
+       return pair<unsigned int,unsigned int> (face_no_guess, subface_no);
+
+                                    // if the guess was false, then
+                                    // we need to loop over all faces
+                                    // and subfaces and find the
+                                    // number the hard way
+  for (unsigned int face_no=0; face_no<GeometryInfo<dim>::faces_per_cell; ++face_no)
+    {
+      if (face_no!=face_no_guess)
+       {
+         const TriaIterator<dim,TriaObjectAccessor<dim-1, dim> > face
+           =neighbor_cell->face(face_no);
+         if (face->has_children())
+           for (unsigned int subface_no=0; subface_no<GeometryInfo<dim>::subfaces_per_face; ++subface_no)
+             if (face->child(subface_no)==this_face)
+               return pair<unsigned int,unsigned int> (face_no, subface_no);
+       }
+    }
+  
+                                  // we should never get here,
+                                  // since then we did not find
+                                  // our way back...
+  Assert (false, ExcInternalError());
+  return pair<unsigned int,unsigned int> (static_cast<unsigned int>(-1),
+                                         static_cast<unsigned int>(-1));
+};
+
+
+
 template <int dim>
 bool CellAccessor<dim>::at_boundary (const unsigned int i) const
 {

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.