From abaef92c8929357a69a4bf366a271346bae6bd3c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Robert=20Kl=C3=B6fkorn?= <robertk@dune-project.org>
Date: Thu, 13 Oct 2005 08:35:23 +0000
Subject: [PATCH] some asserts and minor face lifts.

[[Imported from SVN: r3162]]
---
 grid/albertagrid/agrid.hh       | 23 +++++-------------
 grid/albertagrid/albertagrid.cc | 43 +++++++++++++++++++++++++++------
 2 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/grid/albertagrid/agrid.hh b/grid/albertagrid/agrid.hh
index bdd17cf0f..db1452a43 100644
--- a/grid/albertagrid/agrid.hh
+++ b/grid/albertagrid/agrid.hh
@@ -1550,27 +1550,16 @@ namespace Dune
     const HierarchicIndexSet & hierarchicIndexSet () const { return hIndexSet_; }
 
     //! return level index set for given level
-    const typename Traits :: LevelIndexSet & levelIndexSet (int level= 0) const
-    {
-      if(!levelIndexVec_[level]) levelIndexVec_[level] = new LevelIndexSetImp (*this,level);
-      return *(levelIndexVec_[level]);
-    }
+    const typename Traits :: LevelIndexSet & levelIndexSet (int level) const;
 
     //! return leaf index set
-    const typename Traits :: LeafIndexSet & leafIndexSet () const {
-      if(!leafIndexSet_) leafIndexSet_ = new LeafIndexSet (*this);
-      return *leafIndexSet_;
-    }
+    const typename Traits :: LeafIndexSet & leafIndexSet () const;
 
     //! return global IdSet
-    const GlobalIdSet & globalIdSet () const {
-      return globalIdSet_;
-    }
+    const GlobalIdSet & globalIdSet () const { return globalIdSet_; }
 
     //! return local IdSet
-    const LocalIdSet & localIdSet () const {
-      return globalIdSet_;
-    }
+    const LocalIdSet & localIdSet () const { return globalIdSet_; }
 
     //! access to mesh pointer, needed by some methods
     ALBERTA MESH* getMesh () const { return mesh_; };
@@ -1781,10 +1770,10 @@ namespace Dune
     //********************************************************************
 
     // set owner of element, for partioning
-    bool setOwner ( ALBERTA EL * el , int proc );
+    bool setOwner ( const ALBERTA EL * el , int proc );
 
     // return the processor number of element
-    int getOwner ( ALBERTA EL * el ) const;
+    int getOwner ( const ALBERTA EL * el ) const;
 
     // PartitionType (InteriorEntity , BorderEntity, GhostEntity )
     PartitionType partitionType ( ALBERTA EL_INFO * elinfo) const;
diff --git a/grid/albertagrid/albertagrid.cc b/grid/albertagrid/albertagrid.cc
index 95a19e8b1..32289becc 100644
--- a/grid/albertagrid/albertagrid.cc
+++ b/grid/albertagrid/albertagrid.cc
@@ -1678,7 +1678,8 @@ namespace Dune
   template< class GridImp >
   inline bool AlbertaGridIntersectionIterator<GridImp>::neighbor() const
   {
-    return (elInfo_->neigh[neighborCount_] != 0);
+    // use ALBERTA macro to get neighbour
+    return (NEIGH(elInfo_->el,elInfo_)[neighborCount_] != 0);
   }
 
   template<class GridImp>
@@ -1837,7 +1838,8 @@ namespace Dune
 
     assert( neighborCount_ < dim+1 );
     // set the neighbor element as element
-    neighElInfo_->el = elInfo_->neigh[neighborCount_];
+    // use ALBERTA macro to get neighbour
+    neighElInfo_->el = NEIGH(elInfo_->el,elInfo_)[neighborCount_];
 #if DIM==3
     neighElInfo_->orientation = elInfo_->orientation;
 #endif
@@ -2107,7 +2109,8 @@ namespace Dune
     // check elInfo pointer before we start anything
     assert(elInfo);
 
-    const ALBERTA EL * neighbour = (elInfo->neigh[face_]);
+    // get neighbour of this element
+    const ALBERTA EL * neighbour = NEIGH(elInfo->el,elInfo)[face_];
     if( neighbour )
     {
       // get element
@@ -2325,7 +2328,7 @@ namespace Dune
         // here we have the interior element, now check the neighbours
         for(int i=0; i<dim+1; i++)
         {
-          ALBERTA EL * neigh = NEIGH(elinfo->el,elinfo)[i];
+          const ALBERTA EL * neigh = NEIGH(elinfo->el,elinfo)[i];
           if(neigh)
           {
             if(this->grid_.getOwner(neigh) == this->grid_.myRank())
@@ -3249,6 +3252,9 @@ namespace Dune
   inline bool AlbertaGrid < dim, dimworld >::
   globalRefine(int refCount)
   {
+    // only MAXL level allowed
+    assert( (refCount + maxlevel_) < MAXL );
+
     typedef LeafIterator LeafIt;
     LeafIt endit = this->leafend(this->maxLevel());
 
@@ -3298,7 +3304,7 @@ namespace Dune
   }
 
   template < int dim, int dimworld >
-  inline int AlbertaGrid < dim, dimworld >::getOwner (ALBERTA EL *el) const
+  inline int AlbertaGrid < dim, dimworld >::getOwner (const ALBERTA EL *el) const
   {
     // if element is new then entry in dofVec is 1
     return ownerVec_ [el->dof[dof_][nv_]];
@@ -3706,7 +3712,7 @@ namespace Dune
   }
 
   template < int dim, int dimworld >
-  inline bool AlbertaGrid < dim, dimworld >::setOwner (ALBERTA EL *el, int proc)
+  inline bool AlbertaGrid < dim, dimworld >::setOwner (const ALBERTA EL *el, int proc)
   {
     // if element is new then entry in dofVec is 1
     int dof = el->dof[dof_][nv_];
@@ -3729,7 +3735,7 @@ namespace Dune
     {
       for(int i=0; i<dim+1; i++)
       {
-        ALBERTA EL * neigh = NEIGH(elinfo->el,elinfo)[i];
+        const ALBERTA EL * neigh = NEIGH(elinfo->el,elinfo)[i];
         if(neigh)
         {
           if(getOwner(neigh) != myRank())
@@ -3792,6 +3798,27 @@ namespace Dune
     return this->leafIndexSet().size(codim,simplex);
   }
 
+  template < int dim, int dimworld >
+  inline const typename AlbertaGrid < dim, dimworld > :: Traits :: LevelIndexSet &
+  AlbertaGrid < dim, dimworld > :: levelIndexSet (int level) const
+  {
+    // assert that given level is in range
+    assert( level >= 0 );
+    assert( level < (int) levelIndexVec_.size() );
+
+    if(!levelIndexVec_[level]) levelIndexVec_[level] = new LevelIndexSetImp (*this,level);
+    return *(levelIndexVec_[level]);
+  }
+
+  template < int dim, int dimworld >
+  inline const typename AlbertaGrid < dim, dimworld > :: Traits :: LeafIndexSet &
+  AlbertaGrid < dim, dimworld > :: leafIndexSet () const
+  {
+    if(!leafIndexSet_) leafIndexSet_ = new LeafIndexSet (*this);
+    return *leafIndexSet_;
+  }
+
+
   template < int dim, int dimworld >
   inline void AlbertaGrid < dim, dimworld >::arrangeDofVec()
   {
@@ -3852,6 +3879,8 @@ namespace Dune
 
     // determine new maxlevel
     maxlevel_ = ALBERTA AlbertHelp::calcMaxAbsoluteValueOfVector( dofvecs_.elNewCheck );
+    assert( maxlevel_ >= 0);
+    assert( maxlevel_ < MAXL);
 #ifndef NDEBUG
     int mlvl = ALBERTA AlbertHelp::calcMaxLevel(mesh_);
     assert( mlvl == maxlevel_ );
-- 
GitLab