]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Parent relation for cells.
authorMarkus Buerg <buerg@math.tamu.edu>
Thu, 26 Aug 2010 11:46:29 +0000 (11:46 +0000)
committerMarkus Buerg <buerg@math.tamu.edu>
Thu, 26 Aug 2010 11:46:29 +0000 (11:46 +0000)
git-svn-id: https://svn.dealii.org/trunk@21721 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/grid/tria_accessor.h
deal.II/deal.II/include/grid/tria_accessor.templates.h
deal.II/deal.II/include/grid/tria_levels.h
deal.II/deal.II/source/grid/tria.cc
deal.II/deal.II/source/grid/tria_accessor.cc
deal.II/deal.II/source/grid/tria_levels.cc
deal.II/doc/news/changes.h

index 01e476bae9147a2dfa1c4d18ec5e5826286a8c76..dd29903529463374ccd74294ff5fd68d21d2fd64 100644 (file)
@@ -158,6 +158,14 @@ namespace TriaAccessorExceptions
                                    * @ingroup Exceptions
                                    */
   DeclException0 (ExcCellHasNoChildren);
+                                  /**
+                                   * Trying to access the parent of
+                                   * a cell which is in the coarsest
+                                   * level of the triangulation.
+                                   *
+                                   * @ingroup Exceptions
+                                   */
+  DeclException0 (ExcCellHasNoParent);
 //TODO: Write documentation!
                                   /**
                                    * @ingroup Exceptions
@@ -1494,6 +1502,11 @@ class TriaAccessor : public TriaAccessorBase<structdim, dim, spacedim>
                                      * in the library.
                                      */
     void clear_refinement_case () const;
+    
+                     /**
+                      * Set the parent of a cell.
+                      */
+    void set_parent (const unsigned int parent_index);
 
                                     /**
                                      *  Set the index of the ith
@@ -2171,7 +2184,14 @@ class CellAccessor :  public TriaAccessor<dim,dim,spacedim>
                                      * cell.
                                      */
     void set_subdomain_id (const unsigned int new_subdomain_id) const;
-
+    
+                                    /**
+                                     *  Return an iterator to the
+                                     *  parent.
+                                     */
+    TriaIterator<CellAccessor<dim,spacedim> >
+    parent () const;
+    
                                     /**
                                      * @}
                                      */
index 2c772bab54b4d49464edcf8fbbc4ada5ba5a6d16..ea6262df86da71c80fb2e112967f718cf1d6a32f 100644 (file)
@@ -1564,6 +1564,18 @@ TriaAccessor<structdim, dim, spacedim>::set_children (const unsigned int i,
 
 
 
+template <int structdim, int dim, int spacedim>
+void
+TriaAccessor<structdim, dim, spacedim>::set_parent (const unsigned int parent_index)
+{
+  Assert (this->used(), TriaAccessorExceptions::ExcCellNotUsed());
+  Assert (this->present_level > 0, TriaAccessorExceptions::ExcCellHasNoParent ());
+  this->tria->levels[this->present_level]->parents[this->present_index / 2]
+    = parent_index;
+}
+
+
+
 template <int structdim, int dim, int spacedim>
 void
 TriaAccessor<structdim, dim, spacedim>::clear_children () const
index 1b3275815d021397d424630bb4c6915a098e1310..7f033673a022eb928cc3f9928997f94a7c3c3011 100644 (file)
@@ -139,6 +139,13 @@ namespace internal
                                           * number.
                                           */
         std::vector<unsigned int> subdomain_ids;
+        
+                                         /**
+                                          * One integer for every consecutive
+                                          * pair of cells to store which
+                                          * index their parent has.
+                                          */
+        std::vector<int> parents;
     
                                          /**
                                           *  Reserve enough space to accomodate
@@ -213,6 +220,7 @@ namespace internal
         std::vector<unsigned char> refine_flags;
         std::vector<bool> coarsen_flags;
         std::vector<std::pair<int,int> > neighbors;
+        std::vector<int> parents;
         std::vector<unsigned int> subdomain_ids;
         void reserve_space (const unsigned int total_cells,
                             const unsigned int dimension);
index 2e6a4e941e1f93703640d8c29b68808c837aac96..235eb1d221b24eca2456f7c8286360c479d96ed9 100644 (file)
@@ -4037,6 +4037,9 @@ namespace internal
                                                 // properties
                subcells[i]->set_material_id (cell->material_id());
                subcells[i]->set_subdomain_id (cell->subdomain_id());
+               
+               if (i%2==0)
+                 subcells[i]->set_parent (cell->index ());
              }
 
                                             // set child index for
@@ -4229,6 +4232,7 @@ namespace internal
                                                         next_unused_vertex));
                      first_child->set_material_id (cell->material_id());
                      first_child->set_subdomain_id (cell->subdomain_id());
+                     first_child->set_parent (cell->index ());
 
                                                       // reset neighborship info (refer
                                                       // to
@@ -6170,6 +6174,7 @@ namespace internal
                        {
                          if (i%2==0)
                            next_unused_hex=triangulation.levels[level+1]->cells.next_free_hex(triangulation,level+1);
+                         
                          else
                            ++next_unused_hex;
 
@@ -6185,6 +6190,9 @@ namespace internal
                                                           // properties
                          new_hexes[i]->set_material_id (hex->material_id());
                          new_hexes[i]->set_subdomain_id (hex->subdomain_id());
+                         
+                         if (i%2)
+                           new_hexes[i]->set_parent (hex->index ());
                                                           // set the face_orientation
                                                           // flag to true for all faces
                                                           // initially, as this is the
index a577f4dffee5111e1ec7cc4f25179545332584e6..a07972e899643c0e21bcfe3d9e521ac8e0e2dc58 100644 (file)
@@ -1282,6 +1282,19 @@ CellAccessor<dim, spacedim>::set_subdomain_id (const unsigned int new_subdomain_
 }
 
 
+template <int dim, int spacedim>
+TriaIterator<CellAccessor<dim,spacedim> >
+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]);
+  
+  return q;
+}
+
 
 template <int dim, int spacedim>
 void CellAccessor<dim, spacedim>::set_neighbor (const unsigned int i,
index 7e33d3d3df14376cecdbff1dba219ceda86581d3..c128b113761fba63fdfbeae35291df04d9f9d009 100644 (file)
@@ -50,6 +50,11 @@ namespace internal
           subdomain_ids.insert (subdomain_ids.end(),
                                 total_cells - subdomain_ids.size(),
                                 0);
+          
+          parents.reserve ((int) (total_cells + 1) / 2);
+          parents.insert (parents.end (),
+                          (total_cells + 1) / 2 - parents.size (),
+                          -1);
       
           neighbors.reserve (total_cells*(2*dimension));
           neighbors.insert (neighbors.end(),
@@ -134,6 +139,11 @@ namespace internal
           subdomain_ids.insert (subdomain_ids.end(),
                                 total_cells - subdomain_ids.size(),
                                 0);
+          
+          parents.reserve ((int) (total_cells + 1) / 2);
+          parents.insert (parents.end (),
+                          (total_cells + 1) / 2 - parents.size (),
+                          -1);
       
           neighbors.reserve (total_cells*(2*dimension));
           neighbors.insert (neighbors.end(),
index 791a71cd7cacd3f9b7d5f02a613e8cb261d1ff7c..6cf8dfa9fb91b44a111f79cc4b5be47ba54c5c06 100644 (file)
@@ -224,6 +224,13 @@ through DoFHandler::get_tria() and DoFHandler::get_fe(), respectively.
 
 <ol>
 
+  <li>
+  <p>
+  New: Data structures and a function parent to get the parent of a cell.
+  <br>
+  (Markus Buerg 2010/08/26)
+  </p>
+
   <li>
   <p>
   Improved: DoFHandler has a default constructor, so that it can be used in containers.        

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.