]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
data structures prepared for user index
authorkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 2 May 2007 13:26:28 +0000 (13:26 +0000)
committerkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 2 May 2007 13:26:28 +0000 (13:26 +0000)
git-svn-id: https://svn.dealii.org/trunk@14661 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/grid/tria_objects.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_objects.cc

index ce6ca946b5f2ee8c59206f9fa915c7d803ac727d..c8b001f9ecf6de7361267216288e8a08eb1db9c6 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 2006 by the deal.II authors
+//    Copyright (C) 2006, 2007 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -46,13 +46,18 @@ namespace internal
  * classes.
  *
  * @ingroup grid
- * @author Tobias Leicht, 2006
+ * @author Tobias Leicht, Guido Kanschat, 2006, 2007
  */
     
     template <typename G>
     class TriaObjects
     {
       public:
+                                        /**
+                                         * Constructor resetting some data.
+                                         */
+       TriaObjects();
+       
                                         /**
                                          *  Vector of the objects belonging to
                                          *  this level. The index of the object
@@ -127,15 +132,7 @@ namespace internal
                                          * which cell it belongs to.
                                          */
        std::vector<unsigned char> material_id;
-
-                                        /**
-                                         * Pointer which is not used by the
-                                         * library but may be accessed and set
-                                         * by the user to handle data local to
-                                         * a line/quad/etc.
-                                         */
-       std::vector<void*> user_pointers;
-
+       
                                          /**
                                           *  Assert that enough space is
                                           *  allocated to accomodate
@@ -151,6 +148,34 @@ namespace internal
                                          *  Clear all the data contained in this object.
                                          */
        void clear();
+
+                                        /**
+                                         * Access to user pointers.
+                                         */
+       void*& user_pointer(const unsigned int i);
+       
+                                        /**
+                                         * Read-only access to user pointers.
+                                         */
+       const void* user_pointer(const unsigned int i) const;
+       
+                                        /**
+                                         * Access to user indices.
+                                         */
+       unsigned int& user_index(const unsigned int i);
+       
+                                        /**
+                                         * Read-only access to user pointers.
+                                         */
+       unsigned int user_index(const unsigned int i) const;
+
+                                        /**
+                                         * Clear all user pointers or
+                                         * indices and reset their
+                                         * type, such that the next
+                                         * access may be aither or.
+                                         */
+       void clear_user_data();
        
                                          /**
                                           *  Check the memory consistency of the
@@ -179,12 +204,78 @@ namespace internal
                         << arg3 << ".");
                                          /**
                                           *  Exception
+                                         * @ingroup Exceptions
                                           */
         DeclException2 (ExcMemoryInexact,
                         int, int,
                         << "The containers have sizes " << arg1 << " and "
                         << arg2 << ", which is not as expected.");
+
+                                        /**
+                                         * Triangulation objacts can
+                                         * either access a user
+                                         * pointer or a user
+                                         * index. What you tried to
+                                         * do is trying to access one
+                                         * of those after using the
+                                         * other.
+                                         *
+                                         * @ingroup Exceptions
+                                         */
+       DeclException0 (ExcPointerIndexClash);
        
+      protected:
+                                        /**
+                                         * The data type storing user
+                                         * pointers or user indices.
+                                         */
+       union UserData
+       {
+                                            /// The entry used as user pointer.
+           void* p;
+                                            /// The entry used as user index.
+           unsigned int i;
+                                            /// Default constructor
+           UserData()
+             {
+               p = 0;
+             }
+       };
+
+                                        /**
+                                         * Enum descibing the
+                                         * possible types of
+                                         * userdata.
+                                         */
+       enum UserDataType
+       {
+                                              /// No userdata used yet.
+             data_unknown,
+                                              /// UserData contains pointers.
+             data_pointer,
+                                              /// UserData contains indices.
+             data_index
+       };
+       
+       
+                                        /**
+                                         * Pointer which is not used by the
+                                         * library but may be accessed and set
+                                         * by the user to handle data local to
+                                         * a line/quad/etc.
+                                         */
+       std::vector<UserData> user_data;
+                                        /**
+                                         * In order to avoid
+                                         * confusion between user
+                                         * pointers and indices, this
+                                         * enum is set by the first
+                                         * function accessing either
+                                         * and subsequent access will
+                                         * not be allowed to change
+                                         * the type of data accessed.
+                                         */
+       mutable UserDataType user_data_type;    
     };
 
 /**
@@ -342,10 +433,77 @@ namespace internal
                                           */
         unsigned int memory_consumption () const;          
     };
+
+    template<typename G>
+    void*& TriaObjects<G>::user_pointer (const unsigned int i)
+    {
+#ifdef DEBUG
+      Assert(user_data_type == data_unknown || user_data_type == data_pointer,
+            ExcPointerIndexClash());
+      user_data_type = data_pointer;
+#endif
+      Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
+      return user_data[i].p;
+    }
+    
+
+    template<typename G>
+    const void* TriaObjects<G>::user_pointer (const unsigned int i) const
+    {
+#ifdef DEBUG
+      Assert(user_data_type == data_unknown || user_data_type == data_pointer,
+            ExcPointerIndexClash());
+      user_data_type = data_pointer;
+#endif
+      Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
+      return user_data[i].p;
+    }
+    
+
+    template<typename G>
+    unsigned int& TriaObjects<G>::user_index (const unsigned int i)
+    {
+#ifdef DEBUG
+      Assert(user_data_type == data_unknown || user_data_type == data_index,
+            ExcPointerIndexClash());
+      user_data_type = data_index;
+#endif
+      Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
+      return user_data[i].i;
+    }
+    
+    template <typename G>
+    TriaObjects<G>::TriaObjects()
+                   :
+                   user_data_type(data_unknown)
+    {}    
+
+    template<typename G>
+    unsigned int TriaObjects<G>::user_index (const unsigned int i) const
+    {
+#ifdef DEBUG
+      Assert(user_data_type == data_unknown || user_data_type == data_index,
+            ExcPointerIndexClash());
+      user_data_type = data_index;
+#endif
+      Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
+      return user_data[i].i;
+    }
+    
+    
+    template<typename G>
+    void TriaObjects<G>::clear_user_data ()
+    {
+      user_data_type = data_unknown;
+      for (unsigned int i=0;i<user_data.size();++i)
+       user_data[i].p = 0;
+    }
     
   }
 }
 
+
+
 DEAL_II_NAMESPACE_CLOSE
 
 #endif
index f9671a5e432ca1ce8f1545d17d68fdeebabdab62..776a9515023320c78434409cd4680ea89a511c37 100644 (file)
@@ -2126,10 +2126,8 @@ void Triangulation<dim>::load_coarsen_flags (const std::vector<bool> &v)
 template <>
 void Triangulation<1>::clear_user_pointers ()
 {
-  cell_iterator cell = begin(),
-               endc = end();
-  for (; cell!=endc; ++cell)
-    cell->clear_user_pointer ();
+  for (unsigned int level=0;level<levels.size();++level)
+    levels[level]->lines.clear_user_data();
 }
 
 
@@ -2160,15 +2158,9 @@ void Triangulation<1>::clear_user_flags_hex ()
 template <>
 void Triangulation<2>::clear_user_pointers ()
 {
-  line_iterator line = begin_line(),
-               endl = end_line();
-  for (; line!=endl; ++line)
-    line->clear_user_pointer ();
-
-  cell_iterator cell = begin(),
-               endc = end();
-  for (; cell!=endc; ++cell)
-    cell->clear_user_pointer ();
+  for (unsigned int level=0;level<levels.size();++level)
+    levels[level]->quads.clear_user_data();
+  faces->lines.clear_user_data();
 }
 
 
@@ -2195,20 +2187,10 @@ void Triangulation<2>::clear_user_flags_hex ()
 template <>
 void Triangulation<3>::clear_user_pointers ()
 {
-  line_iterator line = begin_line(),
-               endl = end_line();
-  for (; line!=endl; ++line)
-    line->clear_user_pointer ();
-
-  quad_iterator quad = begin_quad(),
-               endq = end_quad();
-  for (; quad!=endq; ++quad)
-    quad->clear_user_pointer ();
-
-  cell_iterator cell = begin(),
-               endc = end();
-  for (; cell!=endc; ++cell)
-    cell->clear_user_pointer ();
+  for (unsigned int level=0;level<levels.size();++level)
+    levels[level]->hexes.clear_user_data();
+  faces->quads.clear_user_data();
+  faces->lines.clear_user_data();
 }
 
 
index 1fc68df26a6c837e9125ac29801578466a567037..ac51722d2be4ec716673c7b11f7ba29a29eb3282 100644 (file)
@@ -112,7 +112,7 @@ template <int dim>
 void TriaObjectAccessor<1, dim>::set_user_pointer (void *p) const
 {
   Assert (used(), TriaAccessorExceptions::ExcCellNotUsed());
-  lines().user_pointers[this->present_index] = p;
+  lines().user_pointer(this->present_index) = p;
 }
 
 
@@ -121,7 +121,7 @@ template <int dim>
 void TriaObjectAccessor<1, dim>::clear_user_pointer () const
 {
   Assert (used(), TriaAccessorExceptions::ExcCellNotUsed());
-  lines().user_pointers[this->present_index] = 0;
+  lines().user_pointer(this->present_index) = 0;
 }
 
 
@@ -130,7 +130,7 @@ template <int dim>
 void * TriaObjectAccessor<1, dim>::user_pointer () const
 {
   Assert (used(), TriaAccessorExceptions::ExcCellNotUsed());
-  return lines().user_pointers[this->present_index];
+  return lines().user_pointer(this->present_index);
 }
 
 
@@ -356,7 +356,7 @@ template <int dim>
 void TriaObjectAccessor<2, dim>::set_user_pointer (void *p) const
 {
   Assert (used(), TriaAccessorExceptions::ExcCellNotUsed());
-  quads().user_pointers[this->present_index] = p;
+  quads().user_pointer(this->present_index) = p;
 }
 
 
@@ -365,7 +365,7 @@ template <int dim>
 void TriaObjectAccessor<2, dim>::clear_user_pointer () const
 {
   Assert (used(), TriaAccessorExceptions::ExcCellNotUsed());
-  quads().user_pointers[this->present_index] = 0;
+  quads().user_pointer(this->present_index) = 0;
 }
 
 
@@ -374,7 +374,7 @@ template <int dim>
 void * TriaObjectAccessor<2, dim>::user_pointer () const
 {
   Assert (used(), TriaAccessorExceptions::ExcCellNotUsed());
-  return quads().user_pointers[this->present_index];
+  return quads().user_pointer(this->present_index);
 }
 
 
@@ -828,7 +828,7 @@ template <>
 void TriaObjectAccessor<3, 3>::set_user_pointer (void *p) const
 {
   Assert (used(), TriaAccessorExceptions::ExcCellNotUsed());
-  this->tria->levels[this->present_level]->hexes.user_pointers[this->present_index] = p;
+  this->tria->levels[this->present_level]->hexes.user_pointer(this->present_index) = p;
 }
 
 
@@ -836,7 +836,7 @@ template <>
 void TriaObjectAccessor<3, 3>::clear_user_pointer () const
 {
   Assert (used(), TriaAccessorExceptions::ExcCellNotUsed());
-  this->tria->levels[this->present_level]->hexes.user_pointers[this->present_index] = 0;
+  this->tria->levels[this->present_level]->hexes.user_pointer(this->present_index) = 0;
 }
 
 
@@ -844,7 +844,7 @@ template <>
 void * TriaObjectAccessor<3, 3>::user_pointer () const
 {
   Assert (used(), TriaAccessorExceptions::ExcCellNotUsed());
-  return this->tria->levels[this->present_level]->hexes.user_pointers[this->present_index];
+  return this->tria->levels[this->present_level]->hexes.user_pointer(this->present_index);
 }
 
 #endif
index 07b1f2c1b797f9abaa5777d7128d31cef3954d01..edc01981d88700ff49a33d2877a4704f5a09eb5e 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 2006 by the deal.II authors
+//    Copyright (C) 2006, 2007 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
 #include <algorithm>
 #include <functional>
 
-DEAL_II_NAMESPACE_OPEN
+    
 
+DEAL_II_NAMESPACE_OPEN
 
 namespace internal
 {
   namespace Triangulation
-  {
-    
+  {    
     template<>
     void
     TriaObjects<Line>::reserve_space (const unsigned int new_lines)
@@ -63,10 +63,10 @@ namespace internal
                              new_size-material_id.size(),
                              255);
 
-          user_pointers.reserve (new_size);
-          user_pointers.insert (user_pointers.end(),
-                               new_size-user_pointers.size(),
-                               0);
+          user_data.reserve (new_size);
+          user_data.insert (user_data.end(),
+                           new_size-user_data.size(),
+                           UserData());
         };
     }
 
@@ -108,10 +108,10 @@ namespace internal
                              new_size-material_id.size(),
                              255);
 
-          user_pointers.reserve (new_size);
-          user_pointers.insert (user_pointers.end(),
-                               new_size-user_pointers.size(),
-                               0);
+          user_data.reserve (new_size);
+          user_data.insert (user_data.end(),
+                           new_size-user_data.size(),
+                           UserData());
         };
     }
 
@@ -152,10 +152,10 @@ namespace internal
                              new_size-material_id.size(),
                              255);
 
-          user_pointers.reserve (new_size);
-          user_pointers.insert (user_pointers.end(),
-                               new_size-user_pointers.size(),
-                               0);
+          user_data.reserve (new_size);
+          user_data.insert (user_data.end(),
+                           new_size-user_data.size(),
+                           UserData());
 
           face_orientations.reserve (new_size * GeometryInfo<3>::faces_per_cell);
           face_orientations.insert (face_orientations.end(),
@@ -232,8 +232,8 @@ namespace internal
               ExcMemoryInexact (cells.size(), children.size()));
       Assert (cells.size() == material_id.size(),
               ExcMemoryInexact (cells.size(), material_id.size()));
-      Assert (cells.size() == user_pointers.size(),
-              ExcMemoryInexact (cells.size(), user_pointers.size()));
+      Assert (cells.size() == user_data.size(),
+              ExcMemoryInexact (cells.size(), user_data.size()));
     }
 
 
@@ -272,8 +272,8 @@ namespace internal
               ExcMemoryInexact (cells.size(), children.size()));
       Assert (cells.size() == material_id.size(),
               ExcMemoryInexact (cells.size(), material_id.size()));
-      Assert (cells.size() == user_pointers.size(),
-              ExcMemoryInexact (cells.size(), user_pointers.size()));
+      Assert (cells.size() == user_data.size(),
+              ExcMemoryInexact (cells.size(), user_data.size()));
     }
 
 
@@ -311,8 +311,8 @@ namespace internal
               ExcMemoryInexact (cells.size(), children.size()));
       Assert (cells.size() == material_id.size(),
               ExcMemoryInexact (cells.size(), material_id.size()));
-      Assert (cells.size() == user_pointers.size(),
-              ExcMemoryInexact (cells.size(), user_pointers.size()));
+      Assert (cells.size() == user_data.size(),
+              ExcMemoryInexact (cells.size(), user_data.size()));
       Assert (cells.size() * GeometryInfo<3>::faces_per_cell
               == face_orientations.size(),
               ExcMemoryInexact (cells.size() * GeometryInfo<3>::faces_per_cell,
@@ -356,7 +356,8 @@ namespace internal
       used.clear();
       user_flags.clear();
       material_id.clear();
-      user_pointers.clear();
+      user_data.clear();
+      user_data_type = data_unknown;
     }
     
 
@@ -387,7 +388,7 @@ namespace internal
               MemoryConsumption::memory_consumption (used) +
               MemoryConsumption::memory_consumption (user_flags) +
               MemoryConsumption::memory_consumption (material_id) +
-              MemoryConsumption::memory_consumption (user_pointers));
+             user_data.capacity() * sizeof(UserData) + sizeof(user_data));
     }
   
 

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.