]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Parent Function for DoFIterators
authorMarkus Buerg <buerg@math.tamu.edu>
Mon, 30 Aug 2010 10:36:23 +0000 (10:36 +0000)
committerMarkus Buerg <buerg@math.tamu.edu>
Mon, 30 Aug 2010 10:36:23 +0000 (10:36 +0000)
git-svn-id: https://svn.dealii.org/trunk@21789 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/dofs/dof_accessor.h
deal.II/deal.II/include/dofs/dof_accessor.templates.h
deal.II/deal.II/include/grid/tria_accessor.h
deal.II/deal.II/include/grid/tria_accessor.templates.h
deal.II/deal.II/include/multigrid/mg_dof_accessor.h
deal.II/deal.II/source/grid/tria_accessor.cc
deal.II/deal.II/source/multigrid/mg_dof_accessor.cc
deal.II/doc/news/changes.h

index 975d7b6ee3cadd748a0d5d9e22909660a39b59c6..f401d9bfbadafbceb150560d6742be89849cb310 100644 (file)
@@ -288,6 +288,13 @@ class DoFAccessor : public internal::DoFAccessor::Inheritance<structdim, DH::dim
                                      * coordinates of the TriaAccessor.
                                      */
     void copy_from (const TriaAccessorBase<structdim, DH::dimension, DH::space_dimension> &da);
+    
+                                    /**
+                                     * Return an iterator pointing to
+                                     * the the parent.
+                                     */
+    TriaIterator<DoFAccessor<structdim,DH> >
+    parent () const;
 
                                     /**
                                      *  @name Accessing sub-objects
@@ -833,6 +840,18 @@ class DoFCellAccessor :  public DoFAccessor<DH::dimension,DH>
                                      * @}
                                      */
 
+                                /**
+                                     * Return the parent as a DoF
+                                     * cell iterator. This
+                                     * function is needed since the
+                                     * parent function of the base
+                                     * class returns a cell accessor
+                                     * without access to the DoF
+                                     * data.
+                                     */
+    typename internal::DoFHandler::Iterators<DH>::cell_iterator
+    parent () const;
+    
                                     /**
                                      *  @name Accessing sub-objects and neighbors
                                      */
index 9f10acedf59c87bf5cc3bdbc16475a941939af0a..f567fe5b2a0be8d07cfbddf6453bd396dfb415bb 100644 (file)
@@ -186,6 +186,33 @@ DoFAccessor<structdim,DH>::child (const unsigned int i) const
 }
 
 
+template <int structdim, class DH>
+inline
+TriaIterator<DoFAccessor<structdim,DH> >
+DoFAccessor<structdim,DH>::parent () const
+{
+  Assert (static_cast<unsigned int>(this->level()) < this->dof_handler->levels.size(),
+          ExcMessage ("DoFHandler not initialized"));
+  Assert (this->level () > 0,
+          ExcMessage ("Cell is at coarsest level."));
+
+  int previous_level;
+  
+  if (DH::dimension==structdim)
+    previous_level = this->level () - 1;
+  
+  else
+    previous_level = 0;
+
+  TriaIterator<DoFAccessor<structdim,DH> > q (this->tria,
+                                             previous_level,
+                                             this->parent_index (),
+                                             this->dof_handler);
+
+  return q;
+}
+
+
 
 namespace internal
 {
@@ -2749,6 +2776,20 @@ DoFCellAccessor<DH>::child (const unsigned int i) const
 }
 
 
+template <class DH>
+inline
+typename internal::DoFHandler::Iterators<DH>::cell_iterator
+DoFCellAccessor<DH>::parent () const
+{
+  typename internal::DoFHandler::Iterators<DH>::cell_iterator
+    q (this->tria,
+       this->level() - 1,
+       this->parent_index (),
+       this->dof_handler);
+
+  return q;
+}
+
 
 template <class DH>
 typename internal::DoFHandler::Iterators<DH>::face_iterator
index dd29903529463374ccd74294ff5fd68d21d2fd64..aa91f89254b5ddccbacd3d3510a8162e8bd77834 100644 (file)
@@ -698,6 +698,17 @@ class TriaAccessor : public TriaAccessorBase<structdim, dim, spacedim>
                                      */
     bool used () const;
 
+                                    /**
+                                     *  Index of the parent.
+                                     *  The level of the parent is one
+                                     *  lower than that of the
+                                     *  present cell, if the parent
+                                     *  of a cell is accessed. If the
+                                     *  parent does not exist, -1 is
+                                     *  returned.
+                                     */
+    int parent_index () const;
+    
 
                                     /**
                                      *  @name Accessing sub-objects
index ea6262df86da71c80fb2e112967f718cf1d6a32f..69e83a4bc26006612a467a9b390b00cafbf25bfd 100644 (file)
@@ -1305,6 +1305,19 @@ TriaAccessor<structdim, dim, spacedim>::clear_used_flag () const
 }
 
 
+template <int structdim, int dim, int spacedim>
+int
+TriaAccessor<structdim, dim, spacedim>::
+parent_index () const
+{
+  Assert (this->present_level > 0, TriaAccessorExceptions::ExcCellHasNoParent ());
+  
+                                       // the parent of two consecutive cells
+                                       // is stored only once, since it is
+                                       // the same
+  return this->tria->levels[this->present_level]->parents[this->present_index / 2];
+}
+
 
 template <int structdim, int dim, int spacedim>
 int
index 12f2feffedada1e260de8918f09516abddfadcb4..c7d363e9883c534adc60c08fceb9e3653831c3ba 100644 (file)
@@ -338,6 +338,13 @@ class MGDoFAccessor : public internal::MGDoFAccessor::Inheritance<structdim,dim,
                                      * @}
                                      */
 
+                                    /**
+                                     * Return an iterator pointing to
+                                     * the the parent.
+                                     */
+    TriaIterator<MGDoFAccessor<structdim,dim,spacedim> >
+    parent () const;
+
                                     /**
                                      * Implement the copy operator needed
                                      * for the iterator classes.
@@ -578,6 +585,16 @@ class MGDoFCellAccessor :  public MGDoFAccessor<dim,dim,spacedim>
                                     /**
                                      * @}
                                      */
+                                     
+                                /**
+                                     * Return the parent as a MGDoF cell
+                                     * iterator. This function is needed since
+                                     * the parent function of the base
+                                     * class returns a cell accessor without
+                                     * access to the DoF data.
+                                     */
+    TriaIterator<MGDoFCellAccessor<dim,spacedim> >
+    parent () const;
 };
 
 /*@}*/
index a07972e899643c0e21bcfe3d9e521ac8e0e2dc58..b8c5d208155cfe43a45850d21f3e351eb64d89f9 100644 (file)
@@ -1289,8 +1289,7 @@ CellAccessor<dim, spacedim>::parent () const
   Assert (this->used(), TriaAccessorExceptions::ExcCellNotUsed());
   Assert (this->present_level > 0, TriaAccessorExceptions::ExcCellHasNoParent ());
   TriaIterator<CellAccessor<dim,spacedim> >
-    q (this->tria, this->present_level-1,
-       this->tria->levels[this->present_level]->parents[this->present_index / 2]);
+    q (this->tria, this->present_level-1, this->parent_index ());
   
   return q;
 }
index dca07a47cf6fa88b4cf6d6ab51ab1a222e6df72f..c644a2cd2bcf6d649dfbb2abd954cee59aa33292 100644 (file)
@@ -175,6 +175,24 @@ MGDoFAccessor<structdim, dim, spacedim>::child (const unsigned int i) const
 }
 
 
+template <int structdim, int dim, int spacedim>
+TriaIterator<MGDoFAccessor<structdim,dim,spacedim> >
+MGDoFAccessor<structdim, dim, spacedim>::parent () const
+{
+  Assert (this->level () > 0,
+          ExcMessage ("Cell is at coarsest level."));
+  
+  const TriaIterator<MGDoFAccessor<structdim,dim,spacedim> >
+    q (this->tria,
+       (structdim == dim ?
+       this->level() - 1 :
+       0),
+       this->parent_index (),
+       this->mg_dof_handler);
+
+  return q;
+}
+
 
 template <int structdim, int dim, int spacedim>
 void
@@ -518,6 +536,20 @@ MGDoFCellAccessor<dim,spacedim>::child (const unsigned int i) const
 }
 
 
+template <int dim, int spacedim>
+TriaIterator<MGDoFCellAccessor<dim,spacedim> >
+MGDoFCellAccessor<dim, spacedim>::parent () const
+{
+  const TriaIterator<MGDoFCellAccessor<dim,spacedim> >
+    q (this->tria,
+          this->level() - 1,
+       this->parent_index (),
+       this->mg_dof_handler);
+
+  return q;
+}
+
+
 template <int dim, int spacedim>
 typename internal::MGDoFHandler::Iterators<dim,spacedim>::face_iterator
 MGDoFCellAccessor<dim,spacedim>::face (const unsigned int i) const
index 96613acfc64a0ced5bcf8b41a9d23dfa1b177d26..d0a93a2e81c05e8d6adff773adafd509209b922d 100644 (file)
@@ -224,6 +224,15 @@ through DoFHandler::get_tria() and DoFHandler::get_fe(), respectively.
 
 <ol>
 
+  <li>
+  <p>
+  New: Reimplementation of the parent function in the various DoFCellAccessors so
+  that one can call the parent function from a DoFIterator and also gets a
+  DoFIterator returned.
+  <br>
+  (Markus Buerg 2010/08/30)
+  </p>
+
   <li>
   <p>
   New: FETools::compute_embedding_matrices now computes the embedding matrix

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.