]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
New objectdim variable. Overload level function. Make sure level() is not called...
authorhartmann <hartmann@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 30 Jun 2006 12:57:50 +0000 (12:57 +0000)
committerhartmann <hartmann@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 30 Jun 2006 12:57:50 +0000 (12:57 +0000)
git-svn-id: https://svn.dealii.org/trunk@13321 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_iterator.h
deal.II/deal.II/source/grid/tria_accessor.cc

index 8126d60535879c5da6e8360321c4fe823b9492eb..06a8834568cbe2bec4fed85b84d5375c019d7f69 100644 (file)
@@ -320,6 +320,14 @@ class TriaAccessor
                                      */
     const Triangulation<dim> *tria;
 
+  private:
+    
+                                    /**
+                                     * Dimension of the TriaObject
+                                     * this accessor gives access to.
+                                     */
+    static const unsigned int objectdim = dim;
+
     template <int anydim, typename Accessor> friend class TriaRawIterator;
     template <int anydim, typename Accessor> friend class TriaIterator;
     template <int anydim, typename Accessor> friend class TriaActiveIterator;
@@ -380,6 +388,13 @@ class TriaObjectAccessor :  public TriaAccessor<dim>
                                      * <tt>celldim==3</tt>.
                                      */
     void set (const internal::Triangulation::Hexahedron&) const;
+
+                                    /**
+                                     *  Return the level the element
+                                     *  pointed to belongs to.
+                                     *  This is only valid for cells.
+                                     */
+    int level () const;
     
                                     /**
                                      *  Index of vertex. The
@@ -838,6 +853,14 @@ class TriaObjectAccessor :  public TriaAccessor<dim>
                                      *  previous level is accessed.
                                      */
     void operator -- ();
+
+  private:
+    
+                                    /**
+                                     * Dimension of the TriaObject
+                                     * this accessor gives access to.
+                                     */
+    static const unsigned int objectdim = celldim;
                                     /*@}*/
 
                                     /**
@@ -916,6 +939,13 @@ class TriaObjectAccessor<1, dim> :  public TriaAccessor<dim>
                                      */
     void set (const internal::Triangulation::Line &l) const;
 
+                                    /**
+                                     *  Return the level the element
+                                     *  pointed to belongs to.
+                                     *  This is only valid for cells.
+                                     */
+    int level () const;
+
                                     /**
                                      *  Return the index of vertex
                                      *  <tt>i=0,1</tt> of a line.
@@ -1358,6 +1388,14 @@ class TriaObjectAccessor<1, dim> :  public TriaAccessor<dim>
                                      */
     internal::Triangulation::TriaObjects<internal::Triangulation::Line> & lines() const;
 
+  private:
+    
+                                    /**
+                                     * Dimension of the TriaObject
+                                     * this accessor gives access to.
+                                     */
+    static const unsigned int objectdim = 1;
+
                                     /*@}*/
 
                                     /**
@@ -1400,6 +1438,13 @@ class TriaObjectAccessor<2, dim> :  public TriaAccessor<dim>
                                      *  Copy the data of the given quad.
                                      */
     void set (const internal::Triangulation::Quad &q) const;
+
+                                    /**
+                                     *  Return the level the element
+                                     *  pointed to belongs to.
+                                     *  This is only valid for cells.
+                                     */
+    int level () const;
     
                                     /**
                                      * Return index of a vertex of a
@@ -1893,6 +1938,14 @@ class TriaObjectAccessor<2, dim> :  public TriaAccessor<dim>
                                      * without specialization.
                                      */
     internal::Triangulation::TriaObjects<internal::Triangulation::Quad> & quads() const;
+
+  private:
+    
+                                    /**
+                                     * Dimension of the TriaObject
+                                     * this accessor gives access to.
+                                     */
+    static const unsigned int objectdim = 2;
                                     /*@}*/
 
                                     /**
@@ -2428,6 +2481,14 @@ class TriaObjectAccessor<3, dim> :  public TriaAccessor<dim>
                                      *  previous level is accessed.
                                      */
     void operator -- ();
+
+  private:
+    
+                                    /**
+                                     * Dimension of the TriaObject
+                                     * this accessor gives access to.
+                                     */
+    static const unsigned int objectdim = 3;
                                     /*@}*/
 
                                     /**
@@ -2814,6 +2875,7 @@ class CellAccessor :  public TriaObjectAccessor<dim,dim>
     DeclException0 (ExcCellFlaggedForCoarsening);
     
   private:
+    
                                     /**
                                      *  Copy operator. This is
                                      *  normally used in a context
index 6d11f0602c87f5587238cbd420c97900e1565ec4..712de028435d1b9de6a04595471784bb00d2b854 100644 (file)
@@ -160,6 +160,16 @@ TriaObjectAccessor<1,dim>::lines() const
 
 
 
+template <int dim>
+inline
+int
+TriaObjectAccessor<1,dim>::level () const
+{
+  return TriaAccessor<dim>::level();
+}
+
+
+
 template <int dim>
 inline
 bool
@@ -409,6 +419,16 @@ TriaObjectAccessor<2,dim>::quads() const
 
 
 
+template <int dim>
+inline
+int
+TriaObjectAccessor<2,dim>::level () const
+{
+  return TriaAccessor<dim>::level();
+}
+
+
+
 template <int dim>
 inline
 bool
index a69633518bd16af00348a95e5a10dda2a56cf8b2..8c315f169389e5993d1b8f35217a7f45d5d09b3c 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -480,11 +480,12 @@ class TriaRawIterator :
                                     /**@name Exceptions*/
                                     /*@{*/
                                     /**
-                                     *  Exception
+                                     *  Exception for TriaObjects with
+                                     *  level, i.e. cells.
                                      */
-    DeclException1 (ExcDereferenceInvalidObject,
+    DeclException1 (ExcDereferenceInvalidCell,
                    Accessor,
-                   << "You tried to dereference an iterator for which this "
+                   << "You tried to dereference a cell iterator for which this "
                    << "is not possible. More information on this iterator: "
                    << "level=" << arg1.level()
                    << ", index=" << arg1.index()
@@ -493,6 +494,22 @@ class TriaRawIterator :
                        (arg1.state() == IteratorState::past_the_end ?
                         "past_the_end" : "invalid")));
 
+                                    /**
+                                     *  Exception for
+                                     *  lower-dimensional TriaObjects
+                                     *  without level, i.e. objects
+                                     *  faces are constructed with.
+                                     */
+    DeclException1 (ExcDereferenceInvalidObject,
+                   Accessor,
+                   << "You tried to dereference an iterator for which this "
+                   << "is not possible. More information on this iterator: "
+                   << "index=" << arg1.index()
+                   << ", state="
+                   << (arg1.state() == IteratorState::valid ? "valid" :
+                       (arg1.state() == IteratorState::past_the_end ?
+                        "past_the_end" : "invalid")));
+
 #ifdef DEAL_II_NESTED_CLASS_FRIEND_BUG
                                     // the above exception class is
                                     // supposed to report information
@@ -891,8 +908,13 @@ inline
 const Accessor &
 TriaRawIterator<dim,Accessor>::operator * () const
 {
-  Assert (state() == IteratorState::valid,
+  Assert (Accessor::objectdim!=dim ||
+         state() == IteratorState::valid,
+         ExcDereferenceInvalidCell(accessor));
+  Assert (Accessor::objectdim==dim ||
+         state() == IteratorState::valid,
          ExcDereferenceInvalidObject(accessor));
+  
   return accessor;
 }
 
@@ -903,8 +925,13 @@ inline
 Accessor &
 TriaRawIterator<dim,Accessor>::operator * ()
 {
-  Assert (state() == IteratorState::valid,
+  Assert (Accessor::objectdim!=dim ||
+         state() == IteratorState::valid,
+         ExcDereferenceInvalidCell(accessor));
+  Assert (Accessor::objectdim==dim ||
+         state() == IteratorState::valid,
          ExcDereferenceInvalidObject(accessor));
+
   return accessor;
 }
 
@@ -945,20 +972,37 @@ inline
 bool
 TriaRawIterator<dim,Accessor>::operator < (const TriaRawIterator &i) const
 {
-  Assert (state() != IteratorState::invalid,
+  Assert (Accessor::objectdim!=dim ||
+         state() != IteratorState::invalid,
+         ExcDereferenceInvalidCell(accessor));
+  Assert (Accessor::objectdim==dim ||
+         state() != IteratorState::invalid,
          ExcDereferenceInvalidObject(accessor));
-  Assert (i.state() != IteratorState::invalid,
+
+  Assert (Accessor::objectdim!=dim ||
+         i.state() != IteratorState::invalid,
+         ExcDereferenceInvalidCell(i.accessor));
+  Assert (Accessor::objectdim==dim ||
+         i.state() != IteratorState::invalid,
          ExcDereferenceInvalidObject(i.accessor));
+
   Assert (&accessor.get_triangulation() == &i.accessor.get_triangulation(),
          ExcInvalidComparison());
-  
-  return ((((accessor.level() < i.accessor.level()) ||
-           ((accessor.level() == i.accessor.level()) &&
-            (accessor.index() < i.accessor.index()))        ) &&
-          (state()==IteratorState::valid)                     &&
-          (i.state()==IteratorState::valid)                 ) ||
-         ((state()==IteratorState::valid) &&
-          (i.state()==IteratorState::past_the_end)));
+
+  if (Accessor::objectdim==dim)
+    return ((((accessor.level() < i.accessor.level()) ||
+             ((accessor.level() == i.accessor.level()) &&
+              (accessor.index() < i.accessor.index()))        ) &&
+            (state()==IteratorState::valid)                     &&
+            (i.state()==IteratorState::valid)                 ) ||
+           ((state()==IteratorState::valid) &&
+            (i.state()==IteratorState::past_the_end)));
+  else
+    return ((((accessor.index() < i.accessor.index())          ) &&
+            (state()==IteratorState::valid)                     &&
+            (i.state()==IteratorState::valid)                 ) ||
+           ((state()==IteratorState::valid) &&
+            (i.state()==IteratorState::past_the_end)));
 }
 
 
@@ -993,7 +1037,10 @@ inline
 void
 TriaRawIterator<dim,Accessor>::print (std::ostream &out) const
 {
-  out << accessor.level() << "." << accessor.index();
+  if (Accessor::objectdim==dim)
+    out << accessor.level() << "." << accessor.index();
+  else
+    out << accessor.index();
 }
 
 
index e63c3cfcc87bedad1232d48f971e748dbc75db27..430e97833cc120281b59c86c88357b9b63832e4d 100644 (file)
 #include <cmath>
 
 
+template <int dim>
+const unsigned int TriaAccessor<dim>::objectdim;
+
 
 /*------------------------ Functions: LineAccessor ---------------------------*/
 
+template <int dim>
+const unsigned int TriaObjectAccessor<1, dim>::objectdim;
+
+
 template <int dim>
 void
 TriaObjectAccessor<1, dim>::set (const internal::Triangulation::Line &line) const
@@ -255,6 +262,10 @@ unsigned int TriaObjectAccessor<1, dim>::number_of_children () const
 
 /*------------------------ Functions: QuadAccessor ---------------------------*/
 
+template <int dim>
+const unsigned int TriaObjectAccessor<2, dim>::objectdim;
+
+
 template <int dim>
 void
 TriaObjectAccessor<2, dim>::set (const internal::Triangulation::Quad &quad) const
@@ -666,6 +677,11 @@ unsigned int TriaObjectAccessor<2, dim>::number_of_children () const
 
 /*------------------------ Functions: TriaObjectAccessor ---------------------------*/
 
+
+template <int dim>
+const unsigned int TriaObjectAccessor<3, dim>::objectdim;
+
+
 #if deal_II_dimension == 3
 
 template <>

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.