]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement a user pointer for each line/quad/etc and access through the accessors...
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 23 Jul 1998 13:53:29 +0000 (13:53 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 23 Jul 1998 13:53:29 +0000 (13:53 +0000)
git-svn-id: https://svn.dealii.org/trunk@454 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/Todo
deal.II/deal.II/include/grid/tria_accessor.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

index 0645b9a276a03684654f7d2a169255f3d1d5a521..4a93bbc95961225a9efaf9af9d3954a682768871 100644 (file)
@@ -123,6 +123,9 @@ Review the restruction matrices. I'm not really sure about their
   elements and they are not implemented at all for quadratic ones.
 
 
+Document the user pointer interface of the triangulation.
+
+
 
 DEAL:
 Is dvector::operator= (double) really useful or does it make more
index cb06f6648dafdbb81bc0a5ebfc84e26a949b1c21..9ae2a286172b4720d95bab7287c8af0898a15f93 100644 (file)
@@ -331,6 +331,24 @@ class LineAccessor :  public TriaAccessor<dim> {
                                      */
     void clear_user_flag () const;
 
+                                    /**
+                                     * Set the user pointer of this line
+                                     * to #p#.
+                                     */
+    void set_user_pointer (void *p) const;
+
+                                    /**
+                                     * Reset the user pointer of this line
+                                     * to a #NULL# pointer.
+                                     */
+    void clear_user_pointer () const;
+
+                                    /**
+                                     * Access the value of the user pointer
+                                     * of this line.
+                                     */
+    void * user_pointer () const;
+    
                                     /**
                                      *  Return a pointer to the #i#th
                                      *  child.
@@ -573,6 +591,24 @@ class QuadAccessor :  public TriaAccessor<dim> {
                                      */
     void clear_user_flag () const;
 
+                                    /**
+                                     * Set the user pointer of this line
+                                     * to #p#.
+                                     */
+    void set_user_pointer (void *p) const;
+
+                                    /**
+                                     * Reset the user pointer of this line
+                                     * to a #NULL# pointer.
+                                     */
+    void clear_user_pointer () const;
+
+                                    /**
+                                     * Access the value of the user pointer
+                                     * of this line.
+                                     */
+    void * user_pointer () const;
+
                                     /**
                                      *  Return a pointer to the #i#th
                                      *  child.
index db4f3fe701289c35e894e01cf02ad279c047bdd7..0eea3ae51bc90f14379cbbdef04fe804a6ac6369 100644 (file)
@@ -261,6 +261,14 @@ class TriangulationLevel<1> : public TriangulationLevel<0> {
                                          * which cell it belongs to.
                                          */
        vector<unsigned char> material_id;
+
+                                        /**
+                                         * Pointer which is not used by the
+                                         * library but may be accessed an set
+                                         * by the user to handle data local to
+                                         * a line/quad/etc.
+                                         */
+       vector<void*> user_pointers;
     };
     
   public:
@@ -371,6 +379,15 @@ class TriangulationLevel<2> :  public TriangulationLevel<1>
                                          * which cell it belongs to.
                                          */
        vector<unsigned char> material_id;
+
+    
+                                        /**
+                                         * Pointer which is not used by the
+                                         * library but may be accessed an set
+                                         * by the user to handle data local to
+                                         * a line/quad/etc.
+                                         */
+       vector<void*> user_pointers;
     };
     
   public:
index 2b72797abd4b4e8ffee3b3dfad3cf5ac820cc73f..3f2c8887edc53d08a9e923e19441d613e4241540 100644 (file)
@@ -156,6 +156,7 @@ void Triangulation<1>::create_triangulation (const vector<Point<1> >    &v,
       next_free_line->set (Line (cells[cell].vertices[0], cells[cell].vertices[1]));
       next_free_line->set_used_flag ();
       next_free_line->set_material_id (cells[cell].material_id);
+      next_free_line->clear_user_pointer ();
       
                                       // note that this cell
                                       // is adjacent to these vertices
@@ -419,6 +420,7 @@ void Triangulation<2>::create_triangulation (const vector<Point<2> >    &v,
        {
          line->set (Line(i->first.first, i->first.second));
          line->set_used_flag ();
+         line->clear_user_pointer ();
          i->second = line;
        };
     };
@@ -447,7 +449,8 @@ void Triangulation<2>::create_triangulation (const vector<Point<2> >    &v,
                          lines[3]->index()));
          
          cell->set_used_flag ();
-         cell->set_material_id (cells[c].material_id);   
+         cell->set_material_id (cells[c].material_id);
+         cell->clear_user_pointer ();
                                           // note that this cell is adjacent
                                           // to the four lines
          for (unsigned int line=0; line<4; ++line)
@@ -2227,11 +2230,13 @@ void Triangulation<1>::execute_refinement () {
              ++next_unused_cell;
            first_child = next_unused_cell;
            first_child->set_used_flag ();
+           first_child->clear_user_pointer ();
            ++next_unused_cell;
            Assert (next_unused_cell->used() == false,
                    ExcCellShouldBeUnused());
            second_child = next_unused_cell;
            second_child->set_used_flag ();
+           second_child->clear_user_pointer ();
 
                                             // insert first child
            cell->set_children (first_child->index());
@@ -2711,11 +2716,13 @@ void Triangulation<2>::execute_refinement () {
                                                  new_vertices[2*nb+1]));
                        new_lines[nb*2]->set_used_flag ();
                        new_lines[nb*2]->clear_children ();
+                       new_lines[nb*2]->clear_user_pointer ();
                        
                        new_lines[nb*2+1]->set(Line(new_vertices[2*nb+1],
                                                    new_vertices[(2*nb+2)%8]));
                        new_lines[nb*2+1]->set_used_flag ();
                        new_lines[nb*2+1]->clear_children ();
+                       new_lines[nb*2+1]->clear_user_pointer ();
                      } else {
                        new_lines[nb*2+1] = next_unused_line;
                        ++next_unused_line;
@@ -2727,11 +2734,13 @@ void Triangulation<2>::execute_refinement () {
                                                    new_vertices[2*nb]));
                        new_lines[nb*2]->set_used_flag ();
                        new_lines[nb*2]->clear_children ();
+                       new_lines[nb*2]->clear_user_pointer ();
 
                        new_lines[nb*2+1]->set(Line(new_vertices[(2*nb+2)%8],
                                                    new_vertices[2*nb+1]));
                        new_lines[nb*2+1]->set_used_flag ();
-                       new_lines[nb*2+1]->clear_children ();                   
+                       new_lines[nb*2+1]->clear_children ();
+                       new_lines[nb*2+1]->clear_user_pointer ();
                      };
                  };
              };
@@ -2766,6 +2775,7 @@ void Triangulation<2>::execute_refinement () {
                                   new_vertices[8]));
            new_lines[8]->set_used_flag ();
            new_lines[8]->clear_children ();
+           new_lines[8]->clear_user_pointer ();
            
            while (next_unused_line->used() == true)
              ++next_unused_line;
@@ -2774,6 +2784,7 @@ void Triangulation<2>::execute_refinement () {
                                   new_vertices[5]));
            new_lines[9]->set_used_flag ();
            new_lines[9]->clear_children ();
+           new_lines[9]->clear_user_pointer ();
 
            while (next_unused_line->used() == true)
              ++next_unused_line;
@@ -2782,7 +2793,8 @@ void Triangulation<2>::execute_refinement () {
                                    new_vertices[8]));
            new_lines[10]->set_used_flag ();
            new_lines[10]->clear_children ();
-
+           new_lines[10]->clear_user_pointer ();
+           
            while (next_unused_line->used() == true)
              ++next_unused_line;
            new_lines[11] = next_unused_line;
@@ -2790,7 +2802,7 @@ void Triangulation<2>::execute_refinement () {
                                    new_vertices[3]));
            new_lines[11]->set_used_flag ();
            new_lines[11]->clear_children ();
-
+           new_lines[11]->clear_user_pointer ();
                                             // set the boundary indicators of
                                             // the outer cells.
            new_lines[0]->set_boundary_indicator (cell->line(0)->boundary_indicator());
@@ -2834,25 +2846,28 @@ void Triangulation<2>::execute_refinement () {
                                   new_lines[10]->index(), new_lines[7]->index()));
            subcells[0]->set_used_flag();
            subcells[0]->clear_children();
-
+           subcells[0]->clear_user_pointer ();
 
            subcells[1]->set (Quad(new_lines[1]->index(),  new_lines[2]->index(),
                                   new_lines[11]->index(), new_lines[8]->index()));
            subcells[1]->set_used_flag();
            subcells[1]->clear_children();
+           subcells[1]->clear_user_pointer ();
 
 
            subcells[2]->set (Quad(new_lines[11]->index(),  new_lines[3]->index(),
                                   new_lines[4]->index(), new_lines[9]->index()));
            subcells[2]->set_used_flag();
            subcells[2]->clear_children();
-
+           subcells[2]->clear_user_pointer ();
+           
 
            subcells[3]->set (Quad(new_lines[10]->index(),  new_lines[9]->index(),
                                   new_lines[5]->index(), new_lines[6]->index()));
            subcells[3]->set_used_flag();
            subcells[3]->clear_children();
-
+           subcells[3]->clear_user_pointer ();
+           
                                             // finally set neighborship info of
                                             // external cells
                                             // (neighbor_mapping is the mapping
@@ -3415,6 +3430,15 @@ void Triangulation<2>::delete_cell (cell_iterator &cell) {
                                   // second of the second line of the
                                   // first child
   vertices_used[cell->child(0)->line(1)->vertex_index(1)] = false;
+
+                                  // clear user pointers, to avoid that
+                                  // they may appear at unwanted places
+                                  // later on...
+  cell->child(0)->line(1)->clear_user_pointer();
+  cell->child(0)->line(2)->clear_user_pointer();
+  cell->child(2)->line(0)->clear_user_pointer();
+  cell->child(2)->line(3)->clear_user_pointer();
+  
                                   // delete the four interior lines
   cell->child(0)->line(1)->clear_used_flag();
   cell->child(0)->line(2)->clear_used_flag();
@@ -3438,14 +3462,21 @@ void Triangulation<2>::delete_cell (cell_iterator &cell) {
                                         // delete the two subfaces
        for (unsigned int subface=0;
             subface<GeometryInfo<dim>::subfaces_per_face; ++subface)
-         cell->face(face)->child(subface)->clear_used_flag ();
+         {
+           cell->face(face)->child(subface)->clear_user_pointer ();
+           cell->face(face)->child(subface)->clear_used_flag ();
+         };
        
        cell->face(face)->clear_children();
       };
   
                                   // invalidate children
   for (unsigned int child=0; child<GeometryInfo<dim>::children_per_cell; ++child)
-    cell->child(child)->clear_used_flag();
+    {
+      cell->child(child)->clear_user_pointer();
+      cell->child(child)->clear_used_flag();
+    };
+  
   
                                   // delete pointer to children
   cell->set_children (-1);
@@ -3608,6 +3639,10 @@ void TriangulationLevel<1>::reserve_space (const unsigned int new_lines) {
       lines.material_id.insert (lines.material_id.end(),
                                new_size-lines.material_id.size(),
                                255);
+
+      lines.user_pointers.reserve (new_size);
+      lines.user_pointers.insert (lines.user_pointers.end(),
+                                 new_size-lines.user_pointers.size(), 0);
     };
 };
 
@@ -3639,6 +3674,8 @@ void TriangulationLevel<1>::monitor_memory (const unsigned int true_dimension) c
          ExcMemoryInexact (lines.lines.size(), lines.children.size()));
   Assert (lines.lines.size() == lines.material_id.size(),
          ExcMemoryInexact (lines.lines.size(), lines.material_id.size()));
+  Assert (lines.lines.size() == lines.user_pointers.size(),
+         ExcMemoryInexact (lines.lines.size(), lines.user_pointers.size()));
 
   TriangulationLevel<0>::monitor_memory (true_dimension);
 };
@@ -3674,6 +3711,10 @@ void TriangulationLevel<2>::reserve_space (const unsigned int new_quads) {
       quads.material_id.insert (quads.material_id.end(),
                                new_size-quads.material_id.size(),
                                255);
+
+      quads.user_pointers.reserve (new_size);
+      quads.user_pointers.insert (quads.user_pointers.end(),
+                                 new_size-quads.user_pointers.size(), 0);
     };
 };
 
@@ -3704,6 +3745,8 @@ void TriangulationLevel<2>::monitor_memory (const unsigned int true_dimension) c
          ExcMemoryInexact (quads.quads.size(), quads.children.size()));
   Assert (quads.quads.size() == quads.material_id.size(),
          ExcMemoryInexact (quads.quads.size(), quads.material_id.size()));
+  Assert (quads.quads.size() == quads.user_pointers.size(),
+         ExcMemoryInexact (quads.quads.size(), quads.user_pointers.size()));
 
   TriangulationLevel<1>::monitor_memory (true_dimension);
 };
index 51d54549cd343dc12d8e0a532e438eb6095dfdd1..0dbe2fe6ad3d228ffceb31874d22f9c3e70f757e 100644 (file)
@@ -136,6 +136,31 @@ void LineAccessor<dim>::set_user_flag () const {
 
 
 
+template <int dim>
+void LineAccessor<dim>::set_user_pointer (void *p) const {
+  Assert (used(), ExcCellNotUsed());
+  tria->levels[present_level]->lines.user_pointers[present_index] = p;
+};
+
+
+
+template <int dim>
+void LineAccessor<dim>::clear_user_pointer () const {
+  Assert (used(), ExcCellNotUsed());
+  tria->levels[present_level]->lines.user_pointers[present_index] = 0;
+};
+
+
+
+template <int dim>
+void * LineAccessor<dim>::user_pointer () const {
+  Assert (used(), ExcCellNotUsed());
+  return tria->levels[present_level]->lines.user_pointers[present_index];
+};
+
+  
+
+
 template <int dim>
 void LineAccessor<dim>::clear_user_flag () const {
   Assert (used(), ExcCellNotUsed());
@@ -354,6 +379,30 @@ void QuadAccessor<dim>::clear_user_flag () const {
 
 
 
+template <int dim>
+void QuadAccessor<dim>::set_user_pointer (void *p) const {
+  Assert (used(), ExcCellNotUsed());
+  tria->levels[present_level]->quads.user_pointers[present_index] = p;
+};
+
+
+
+template <int dim>
+void QuadAccessor<dim>::clear_user_pointer () const {
+  Assert (used(), ExcCellNotUsed());
+  tria->levels[present_level]->quads.user_pointers[present_index] = 0;
+};
+
+
+
+template <int dim>
+void * QuadAccessor<dim>::user_pointer () const {
+  Assert (used(), ExcCellNotUsed());
+  return tria->levels[present_level]->quads.user_pointers[present_index];
+};
+
+
+
 
 template <int dim>
 TriaIterator<dim,LineAccessor<dim> >

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.