~ubuntu-branches/ubuntu/utopic/dune-grid/utopic-proposed

« back to all changes in this revision

Viewing changes to dune/grid/alugrid/2d/entity_imp.cc

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2014-02-14 10:49:16 UTC
  • mfrom: (1.3.1) (5.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20140214104916-2clchnny3eu7ks4w
Tags: 2.3.0-2
InstallĀ /usr/share/dune-grid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
// vi: set et ts=4 sw=2 sts=2:
1
3
#ifndef DUNE_ALU2DGRIDENTITYIMP_CC
2
4
#define DUNE_ALU2DGRIDENTITYIMP_CC
3
5
 
10
12
namespace Dune {
11
13
 
12
14
 
13
 
//**********************************************************************
14
 
//
15
 
// --ALU2dGridEntity
16
 
// --Entity
17
 
//
18
 
//**********************************************************************
19
 
 
20
 
 
21
 
//! level of this element
22
 
template<int cd, int dim, class GridImp>
23
 
inline int ALU2dGridEntity<cd, dim, GridImp> :: 
24
 
level () const {
25
 
  if (level_ == -1) {
26
 
    if (cd != 2)
27
 
      level_ = item_->level();
28
 
    else 
29
 
      level_ = item_->level() + 1;
30
 
  }
31
 
  assert(level_ != -1);
32
 
  return level_;
33
 
}
34
 
 
35
 
// forward declararion of struct ElementWrapper
36
 
template <int codim, int dim, class GridImp>
37
 
struct ElementWrapper;
38
 
 
39
 
 
40
 
template<int cd, int dim, class GridImp>
41
 
inline bool ALU2dGridEntity<cd, dim, GridImp> :: equals(const ALU2dGridEntity<cd, dim, GridImp> &org) const {  
42
 
  return ElementWrapper<cd,dim, GridImp>::isTheSame (*item_, face_, *org.item_, org.face_);  
43
 
}
44
 
  
45
 
//! Constructor 
46
 
template<int cd, int dim, class GridImp>
47
 
inline ALU2dGridEntity<cd, dim, GridImp> :: 
48
 
ALU2dGridEntity(const FactoryType& factory, int level)
49
 
  : factory_( factory ), 
50
 
    item_(0),     
51
 
    level_(level),
52
 
    face_(-1)
53
 
{
54
 
}
55
 
 
56
 
 
57
 
template<int cd, int dim, class GridImp>
58
 
inline void ALU2dGridEntity<cd,dim,GridImp>:: setElement(const ElementType &element, int face, int level) const {
59
 
  item_= const_cast<ElementType *> (&element);      
60
 
  level_ = level;
61
 
  face_ = face;  
62
 
 
63
 
  geoObj_.invalidate();
64
 
}
65
 
 
66
 
 
67
 
template<int cd, int dim, class GridImp>
68
 
inline void ALU2dGridEntity<cd,dim,GridImp>:: setElement( const EntitySeed& seed ) const 
69
 
{
70
 
  setElement( *(seed.item()), seed.face(), seed.level() );
71
 
}
72
 
 
73
 
//! set item pointer to NULL
74
 
template<int cd, int dim, class GridImp>
75
 
inline void ALU2dGridEntity<cd,dim,GridImp> :: removeElement() {
76
 
  item_ = 0;  
77
 
  geoObj_.invalidate();
78
 
}
79
 
 
80
 
//! Copy Constructor 
81
 
template<int cd, int dim, class GridImp>
82
 
inline ALU2dGridEntity<cd, dim, GridImp> :: 
83
 
ALU2dGridEntity(const ALU2dGridEntity<cd,dim,GridImp> & org)
84
 
  : factory_( org.factory_ ), 
85
 
    item_(org.item_),     
86
 
    level_(org.level_), 
87
 
    face_(org.face_)
88
 
{}
89
 
 
90
 
//! geometry of this entity
91
 
template< int cd, int dim, class GridImp >
92
 
inline typename ALU2dGridEntity< cd, dim, GridImp >::Geometry
93
 
ALU2dGridEntity< cd, dim, GridImp >::geometry () const
94
 
{
95
 
  if( !geoObj_.valid() )
96
 
    geoObj_.buildGeom( *item_,face_ );
97
 
 
98
 
  assert( geoObj_.valid() );
99
 
  return Geometry( geoObj_ );
100
 
}
101
 
 
102
 
//! geometry type of geometry of this entity
103
 
template<int cd, int dim, class GridImp>
104
 
inline GeometryType 
105
 
ALU2dGridEntity<cd, dim, GridImp> :: type () const 
106
 
{
107
 
  return geoObj_.type();
108
 
}
109
 
 
110
 
template<int cd, int dim, class GridImp>
111
 
inline int ALU2dGridEntity<cd,dim,GridImp > :: getIndex() const 
112
 
{
 
15
  //**********************************************************************
 
16
  //
 
17
  // --ALU2dGridEntity
 
18
  // --Entity
 
19
  //
 
20
  //**********************************************************************
 
21
 
 
22
 
 
23
  //! level of this element
 
24
  template<int cd, int dim, class GridImp>
 
25
  inline int ALU2dGridEntity<cd, dim, GridImp> ::
 
26
  level () const {
 
27
    if (level_ == -1) {
 
28
      if (cd != 2)
 
29
        level_ = item_->level();
 
30
      else
 
31
        level_ = item_->level() + 1;
 
32
    }
 
33
    assert(level_ != -1);
 
34
    return level_;
 
35
  }
 
36
 
 
37
  // forward declararion of struct ElementWrapper
 
38
  template <int codim, int dim, class GridImp>
 
39
  struct ElementWrapper;
 
40
 
 
41
 
 
42
  template<int cd, int dim, class GridImp>
 
43
  inline bool ALU2dGridEntity<cd, dim, GridImp> :: equals(const ALU2dGridEntity<cd, dim, GridImp> &org) const {
 
44
    return ElementWrapper<cd,dim, GridImp>::isTheSame (*item_, face_, *org.item_, org.face_);
 
45
  }
 
46
 
 
47
  //! Constructor
 
48
  template<int cd, int dim, class GridImp>
 
49
  inline ALU2dGridEntity<cd, dim, GridImp> ::
 
50
  ALU2dGridEntity(const FactoryType& factory, int level)
 
51
    : factory_( factory ),
 
52
      item_(0),
 
53
      level_(level),
 
54
      face_(-1)
 
55
  {}
 
56
 
 
57
 
 
58
  template<int cd, int dim, class GridImp>
 
59
  inline void ALU2dGridEntity<cd,dim,GridImp>:: setElement(const ElementType &element, int face, int level) const {
 
60
    item_= const_cast<ElementType *> (&element);
 
61
    level_ = level;
 
62
    face_ = face;
 
63
 
 
64
    geoObj_.invalidate();
 
65
  }
 
66
 
 
67
 
 
68
  template<int cd, int dim, class GridImp>
 
69
  inline void ALU2dGridEntity<cd,dim,GridImp>:: setElement( const EntitySeed& seed ) const
 
70
  {
 
71
    setElement( *(seed.item()), seed.face(), seed.level() );
 
72
  }
 
73
 
 
74
  //! set item pointer to NULL
 
75
  template<int cd, int dim, class GridImp>
 
76
  inline void ALU2dGridEntity<cd,dim,GridImp> :: removeElement() {
 
77
    item_ = 0;
 
78
    geoObj_.invalidate();
 
79
  }
 
80
 
 
81
  //! Copy Constructor
 
82
  template<int cd, int dim, class GridImp>
 
83
  inline ALU2dGridEntity<cd, dim, GridImp> ::
 
84
  ALU2dGridEntity(const ALU2dGridEntity<cd,dim,GridImp> & org)
 
85
    : factory_( org.factory_ ),
 
86
      item_(org.item_),
 
87
      level_(org.level_),
 
88
      face_(org.face_)
 
89
  {}
 
90
 
 
91
  //! geometry of this entity
 
92
  template< int cd, int dim, class GridImp >
 
93
  inline typename ALU2dGridEntity< cd, dim, GridImp >::Geometry
 
94
  ALU2dGridEntity< cd, dim, GridImp >::geometry () const
 
95
  {
 
96
    if( !geoObj_.valid() )
 
97
      geoObj_.buildGeom( *item_,face_ );
 
98
 
 
99
    assert( geoObj_.valid() );
 
100
    return Geometry( geoObj_ );
 
101
  }
 
102
 
 
103
  //! geometry type of geometry of this entity
 
104
  template<int cd, int dim, class GridImp>
 
105
  inline GeometryType
 
106
  ALU2dGridEntity<cd, dim, GridImp> :: type () const
 
107
  {
 
108
    return geoObj_.type();
 
109
  }
 
110
 
 
111
  template<int cd, int dim, class GridImp>
 
112
  inline int ALU2dGridEntity<cd,dim,GridImp > :: getIndex() const
 
113
  {
113
114
    assert(item_ != 0);
114
115
    return ElementWrapper<cd, dim, GridImp>::getElemIndex (grid(), *item_, face_);
115
 
}
116
 
 
117
 
/**
118
 
   \brief Id of the boundary which is associated with
119
 
   the entity, returns 0 for inner entities, arbitrary int otherwise
120
 
*/  
121
 
 
122
 
template<int cd, int dim, class GridImp>
123
 
inline int ALU2dGridEntity<cd,dim,GridImp> :: boundaryId() const {
124
 
 int isBoundary=0, i=0;    
 
116
  }
 
117
 
 
118
  /**
 
119
     \brief Id of the boundary which is associated with
 
120
     the entity, returns 0 for inner entities, arbitrary int otherwise
 
121
   */
 
122
 
 
123
  template<int cd, int dim, class GridImp>
 
124
  inline int ALU2dGridEntity<cd,dim,GridImp> :: boundaryId() const {
 
125
    int isBoundary=0, i=0;
125
126
    while(!isBoundary && i<dim) {
126
127
      if (item_->nbbnd(i)!=0)
127
 
        isBoundary = item_->nbbnd(i)->type();      
 
128
        isBoundary = item_->nbbnd(i)->type();
128
129
      ++i;
129
130
    }
130
131
    return isBoundary;
131
 
}
132
 
 
133
 
//**********************************************************************
134
 
//  
135
 
//  --ALU2dGridEntity
136
 
//  --0Entity
137
 
//
138
 
//**********************************************************************
139
 
 
140
 
//! Constructor creating empty Entity 
141
 
template<int dim, class GridImp>
142
 
inline ALU2dGridEntity<0,dim,GridImp> ::
143
 
ALU2dGridEntity(const FactoryType& factory, int level)
144
 
  : factory_( factory ) 
145
 
  , item_(0)
146
 
  , isLeaf_ (false) 
147
 
{  
148
 
}
149
 
 
150
 
//! Copy Constructor 
151
 
template<int dim, class GridImp>
152
 
inline ALU2dGridEntity<0, dim, GridImp> :: 
153
 
ALU2dGridEntity(const ALU2dGridEntity<0,dim,GridImp> & org)
154
 
  : factory_( org.factory_ ), 
155
 
    item_(org.item_), 
156
 
    isLeaf_(org.isLeaf_) 
157
 
158
 
}
159
 
 
160
 
//! level of this element
161
 
template<int dim, class GridImp>
162
 
inline int ALU2dGridEntity<0,dim,GridImp> :: level () const {
163
 
  assert( item_ );
164
 
  return (*item_).level();
165
 
}
166
 
 
167
 
//! geometry of this entity
168
 
template< int dim, class GridImp >
169
 
inline typename ALU2dGridEntity< 0, dim, GridImp >::Geometry
170
 
ALU2dGridEntity< 0, dim, GridImp >::geometry () const
171
 
{
172
 
  assert( item_ != 0 );
173
 
  if( !geoObj_.valid() ) 
174
 
    geoObj_.buildGeom( *item_ );
175
 
  
176
 
  assert( geoObj_.valid() );
177
 
  return Geometry( geoObj_ );
178
 
}
179
 
 
180
 
//! geometry type of geometry of this entity
181
 
template<int dim, class GridImp>
182
 
inline GeometryType 
183
 
ALU2dGridEntity<0, dim, GridImp> :: type () const 
184
 
{
185
 
  return geoObj_.type();
186
 
}
187
 
 
188
 
//! returns true if Entity is leaf (i.e. has no children) 
189
 
template<int dim, class GridImp>
190
 
inline bool ALU2dGridEntity<0,dim,GridImp> :: isLeaf () const {
191
 
  return isLeaf_;
192
 
}
193
 
 
194
 
//! Inter-level access to father element on coarser grid. 
195
 
//! Assumes that meshes are nested.
196
 
template<int dim, class GridImp>
197
 
inline typename ALU2dGridEntity<0, dim, GridImp> :: EntityPointer ALU2dGridEntity<0,dim,GridImp> :: father () const {
198
 
  // don't request for father on macro level
199
 
  assert(level()>0);
200
 
  return EntityPointer(factory_, *(item_->father()));  
201
 
}
202
 
 
203
 
template<int dim, class GridImp>
204
 
inline int ALU2dGridEntity<0, dim, GridImp> :: nChild() const
205
 
{
206
 
  assert( item_ );
207
 
  return item_->childNr();
208
 
}
209
 
 
210
 
template< int dim, class GridImp >
211
 
inline typename ALU2dGridEntity< 0, dim, GridImp >::LocalGeometry
212
 
ALU2dGridEntity< 0, dim, GridImp >::geometryInFather () const
213
 
{
214
 
  assert( level() > 0 );
215
 
 
216
 
  const GeometryType myType = type();
217
 
  // we need to storages in case of cube grid, 
218
 
  // one for quadrilaterals and one for triangles 
219
 
  if( (GridImp::elementType != ALU2DSPACE triangle) && myType.isCube() ) 
220
 
  {
221
 
    assert( grid().nonConform() );
222
 
    static ALULocalGeometryStorage< GridImp, LocalGeometryImpl, 4 > geoms( myType, true );
223
 
    return LocalGeometry( geoms[ nChild() ] );
224
 
  }
225
 
  else 
226
 
  {
227
 
    if( grid().nonConform() ) 
228
 
    {
229
 
      static ALULocalGeometryStorage< GridImp, LocalGeometryImpl, 4 > geoms( myType, true );
230
 
      return LocalGeometry( geoms[ nChild() ] );
231
 
    }
232
 
    else 
233
 
    {
234
 
      static ALULocalGeometryStorage< GridImp, LocalGeometryImpl, 2 > geoms( myType, false );
235
 
      return LocalGeometry( geoms[ nChild() ] );
236
 
    }
237
 
  }
238
 
}
239
 
 
240
 
template<int dim, class GridImp>
241
 
inline int ALU2dGridEntity<0,dim,GridImp> :: getIndex() const {
242
 
  assert( item_ );
243
 
  return (*item_).getIndex();
244
 
}
245
 
 
246
 
// forward declararion of struct ElementWrapper
247
 
//template <int codim, int dim, class GridImp>
248
 
//  struct ElementWrapper;
249
 
 
250
 
template<int dim, class GridImp>
251
 
template<int cc>
252
 
inline int ALU2dGridEntity<0,dim,GridImp> :: getSubIndex(int i) const {
253
 
  assert(item_ != 0);    
254
 
  return ElementWrapper<cc, dim, GridImp>::subIndex (grid(), *item_,i);
255
 
256
 
 
257
 
//! Provide access to mesh entity i of given codimension. Entities
258
 
//!  are numbered 0 ... count<cc>()-1
259
 
template<int dim, class GridImp>
260
 
template <int cc>
261
 
inline typename ALU2dGridEntity<0,dim,GridImp > ::template Codim<cc> :: EntityPointer 
262
 
ALU2dGridEntity<0,dim,GridImp> :: entity (int i) const {
263
 
  assert(item_ != 0);    
264
 
  return ElementWrapper<cc,dim, GridImp>::subEntity (factory(), *item_, i);
265
 
}  
266
 
 
267
 
template<int dim, class GridImp>
268
 
template <int cc> 
269
 
inline int ALU2dGridEntity<0,dim,GridImp> :: subBoundaryId  ( int i ) const {
270
 
  assert(item_ != 0);    
271
 
  return ElementWrapper<cc, dim, GridImp>::subBoundary (grid(), *item_,i);
272
 
}
273
 
  
274
 
template<int dim, class GridImp>
275
 
inline int ALU2dGridEntity<0,dim,GridImp> :: subIndex(int i, unsigned int codim) const 
276
 
{
277
 
  assert( item_ != 0 );
278
 
  int j = i;
279
 
  switch( codim ) 
280
 
  { 
281
 
    case 0: 
 
132
  }
 
133
 
 
134
  //**********************************************************************
 
135
  //
 
136
  //  --ALU2dGridEntity
 
137
  //  --0Entity
 
138
  //
 
139
  //**********************************************************************
 
140
 
 
141
  //! Constructor creating empty Entity
 
142
  template<int dim, class GridImp>
 
143
  inline ALU2dGridEntity<0,dim,GridImp> ::
 
144
  ALU2dGridEntity(const FactoryType& factory, int level)
 
145
    : factory_( factory )
 
146
      , item_(0)
 
147
      , isLeaf_ (false)
 
148
  {}
 
149
 
 
150
  //! Copy Constructor
 
151
  template<int dim, class GridImp>
 
152
  inline ALU2dGridEntity<0, dim, GridImp> ::
 
153
  ALU2dGridEntity(const ALU2dGridEntity<0,dim,GridImp> & org)
 
154
    : factory_( org.factory_ ),
 
155
      item_(org.item_),
 
156
      isLeaf_(org.isLeaf_)
 
157
  {}
 
158
 
 
159
  //! level of this element
 
160
  template<int dim, class GridImp>
 
161
  inline int ALU2dGridEntity<0,dim,GridImp> :: level () const {
 
162
    assert( item_ );
 
163
    return (*item_).level();
 
164
  }
 
165
 
 
166
  //! geometry of this entity
 
167
  template< int dim, class GridImp >
 
168
  inline typename ALU2dGridEntity< 0, dim, GridImp >::Geometry
 
169
  ALU2dGridEntity< 0, dim, GridImp >::geometry () const
 
170
  {
 
171
    assert( item_ != 0 );
 
172
    if( !geoObj_.valid() )
 
173
      geoObj_.buildGeom( *item_ );
 
174
 
 
175
    assert( geoObj_.valid() );
 
176
    return Geometry( geoObj_ );
 
177
  }
 
178
 
 
179
  //! geometry type of geometry of this entity
 
180
  template<int dim, class GridImp>
 
181
  inline GeometryType
 
182
  ALU2dGridEntity<0, dim, GridImp> :: type () const
 
183
  {
 
184
    return geoObj_.type();
 
185
  }
 
186
 
 
187
  //! returns true if Entity is leaf (i.e. has no children)
 
188
  template<int dim, class GridImp>
 
189
  inline bool ALU2dGridEntity<0,dim,GridImp> :: isLeaf () const {
 
190
    return isLeaf_;
 
191
  }
 
192
 
 
193
  //! Inter-level access to father element on coarser grid.
 
194
  //! Assumes that meshes are nested.
 
195
  template<int dim, class GridImp>
 
196
  inline typename ALU2dGridEntity<0, dim, GridImp> :: EntityPointer ALU2dGridEntity<0,dim,GridImp> :: father () const {
 
197
    // don't request for father on macro level
 
198
    assert(level()>0);
 
199
    return EntityPointer(factory_, *(item_->father()));
 
200
  }
 
201
 
 
202
  template<int dim, class GridImp>
 
203
  inline int ALU2dGridEntity<0, dim, GridImp> :: nChild() const
 
204
  {
 
205
    assert( item_ );
 
206
    return item_->childNr();
 
207
  }
 
208
 
 
209
  template< int dim, class GridImp >
 
210
  inline typename ALU2dGridEntity< 0, dim, GridImp >::LocalGeometry
 
211
  ALU2dGridEntity< 0, dim, GridImp >::geometryInFather () const
 
212
  {
 
213
    assert( level() > 0 );
 
214
 
 
215
    const GeometryType myType = type();
 
216
    // we need to storages in case of cube grid,
 
217
    // one for quadrilaterals and one for triangles
 
218
    if( (GridImp::elementType != ALU2DSPACE triangle) && myType.isCube() )
 
219
    {
 
220
      assert( grid().nonConform() );
 
221
      typedef ALULocalGeometryStorage< GridImp, LocalGeometryImpl, 4 >  GeometryStorage;
 
222
      return LocalGeometry( GeometryStorage::geom( myType, true, nChild() ) );
 
223
    }
 
224
    else
 
225
    {
 
226
      if( grid().nonConform() )
 
227
      {
 
228
        typedef ALULocalGeometryStorage< GridImp, LocalGeometryImpl, 4 >  GeometryStorage;
 
229
        return LocalGeometry( GeometryStorage::geom( myType, true, nChild() ) );
 
230
      }
 
231
      else
 
232
      {
 
233
        typedef ALULocalGeometryStorage< GridImp, LocalGeometryImpl, 2 >  GeometryStorage;
 
234
        return LocalGeometry( GeometryStorage::geom( myType, false, nChild() ) );
 
235
      }
 
236
    }
 
237
  }
 
238
 
 
239
  template<int dim, class GridImp>
 
240
  inline int ALU2dGridEntity<0,dim,GridImp> :: getIndex() const {
 
241
    assert( item_ );
 
242
    return (*item_).getIndex();
 
243
  }
 
244
 
 
245
  // forward declararion of struct ElementWrapper
 
246
  //template <int codim, int dim, class GridImp>
 
247
  //  struct ElementWrapper;
 
248
 
 
249
  template<int dim, class GridImp>
 
250
  template<int cc>
 
251
  inline int ALU2dGridEntity<0,dim,GridImp> :: getSubIndex(int i) const {
 
252
    assert(item_ != 0);
 
253
    return ElementWrapper<cc, dim, GridImp>::subIndex (grid(), *item_,i);
 
254
  }
 
255
 
 
256
  //! Provide access to mesh entity i of given codimension. Entities
 
257
  //!  are numbered 0 ... count<cc>()-1
 
258
  template<int dim, class GridImp>
 
259
  template <int cc>
 
260
  inline typename ALU2dGridEntity<0,dim,GridImp > ::template Codim<cc> :: EntityPointer
 
261
  ALU2dGridEntity<0,dim,GridImp> :: entity (int i) const {
 
262
    assert(item_ != 0);
 
263
    return ElementWrapper<cc,dim, GridImp>::subEntity (factory(), *item_, i);
 
264
  }
 
265
 
 
266
  template<int dim, class GridImp>
 
267
  template <int cc>
 
268
  inline int ALU2dGridEntity<0,dim,GridImp> :: subBoundaryId  ( int i ) const {
 
269
    assert(item_ != 0);
 
270
    return ElementWrapper<cc, dim, GridImp>::subBoundary (grid(), *item_,i);
 
271
  }
 
272
 
 
273
  template<int dim, class GridImp>
 
274
  inline int ALU2dGridEntity<0,dim,GridImp> :: subIndex(int i, unsigned int codim) const
 
275
  {
 
276
    assert( item_ != 0 );
 
277
    int j = i;
 
278
    switch( codim )
 
279
    {
 
280
    case 0 :
282
281
      return ElementWrapper<0, dim, GridImp>::subIndex (grid(), *item_, j);
283
 
    case 1:   
284
 
      // also apply mapping to generic ref elem by switching edges 
285
 
      if( item_->numvertices() == 3 ) 
 
282
    case 1 :
 
283
      // also apply mapping to generic ref elem by switching edges
 
284
      if( item_->numvertices() == 3 )
286
285
        j = 2 - i;
287
286
      else
288
 
        switch (i) { case 0: j=2;break;
289
 
                     case 1: j=0;break;
290
 
                     case 2: j=3;break;
291
 
                     case 3: j=1;break;
292
 
                   }
293
 
        // j = ((i^2)>>1) | ((i&1)<<1);
 
287
        switch (i) { case 0 : j=2;break;
 
288
                   case 1 : j=0;break;
 
289
                   case 2 : j=3;break;
 
290
                   case 3 : j=1;break;}
 
291
      // j = ((i^2)>>1) | ((i&1)<<1);
294
292
      return ElementWrapper<1, dim, GridImp>::subIndex (grid(), *item_, j);
295
 
    case 2:   
296
 
      if( item_->numvertices() == 4 ) 
297
 
        switch (i) { case 0: j=0;break;
298
 
                     case 1: j=1;break;
299
 
                     case 2: j=3;break;
300
 
                     case 3: j=2;break;
301
 
                   }
 
293
    case 2 :
 
294
      if( item_->numvertices() == 4 )
 
295
        switch (i) { case 0 : j=0;break;
 
296
                   case 1 : j=1;break;
 
297
                   case 2 : j=3;break;
 
298
                   case 3 : j=2;break;}
302
299
      return ElementWrapper<2, dim, GridImp>::subIndex (grid(), *item_, j);
303
 
    default: 
 
300
    default :
304
301
      assert( false );
305
302
      abort();
306
 
  }
307
 
  return -1;
308
 
}
309
 
//***************************************************************
310
 
//  Interface for Adaptation
311
 
//***************************************************************
312
 
//! marks an element for refCount refines. if refCount is negative the
313
 
//! element is coarsend -refCount times
314
 
//! mark returns true if element was marked, otherwise false
315
 
template<int dim, class GridImp>
316
 
inline bool ALU2dGridEntity<0,dim,GridImp> :: mark( int refCount ) const 
317
 
{
318
 
  if( !isLeaf() ) return false;
319
 
 
320
 
  // if this assertion is thrown then you try to mark a non leaf entity
321
 
  // which is leads to unpredictable results
322
 
  assert(item_ != 0);
323
 
 
324
 
  // mark for coarsening
325
 
  if(refCount < 0) 
326
 
  {
327
 
    if(level() <= 0) return false;
328
 
    item_->ALU2DSPACE Refco_el::mark(ALU2DSPACE Refco::crs);
329
 
    return true; 
330
 
  }
331
 
 
332
 
  // mark for refinement
333
 
  if(refCount > 0) 
334
 
  {
335
 
    item_->ALU2DSPACE Refco_el::mark(ALU2DSPACE Refco::ref);
336
 
    return true; 
337
 
  }    
338
 
 
339
 
  // mark with none 
340
 
  item_->ALU2DSPACE Refco_el::mark(ALU2DSPACE Refco::none);
341
 
  return true;  
342
 
}
343
 
 
344
 
template<int dim, class GridImp>
345
 
inline int ALU2dGridEntity<0,dim,GridImp> :: getMark() const 
346
 
{
347
 
  assert(item_ != 0);
348
 
  if(item_->ALU2DSPACE Refco_el::is(ALU2DSPACE Refco::ref)) return 1;
349
 
  if(item_->ALU2DSPACE Refco_el::is(ALU2DSPACE Refco::crs)) return -1;
350
 
  assert( item_->ALU2DSPACE Refco_el::is(ALU2DSPACE Refco::none) );
351
 
  return 0;
352
 
}
353
 
 
354
 
/*! private methods, but public because of datahandle and template
355
 
    arguments of these methods
356
 
*/
357
 
template<int dim, class GridImp>
358
 
inline void ALU2dGridEntity<0,dim,GridImp> :: 
359
 
setElement(const HElementType &element, int face, int level) const 
360
 
{
361
 
  item_= const_cast<HElementType *> (&element);  
362
 
  isLeaf_  = ((*item_).down() == 0);  
363
 
 
364
 
  geoObj_.invalidate();
365
 
}
366
 
 
367
 
template<int dim, class GridImp>
368
 
inline void ALU2dGridEntity<0,dim,GridImp> :: 
369
 
setElement(const EntitySeed& seed ) const 
370
 
{
371
 
  setElement( *(seed.item()) );//, seed.face(), seed.level() );
372
 
}
373
 
 
374
 
  
375
 
//! set actual walk level 
376
 
template<int dim, class GridImp>
377
 
inline void ALU2dGridEntity<0,dim,GridImp> :: reset ( int l )
378
 
{
379
 
  item_       = 0;  
380
 
  isLeaf_     = false;
381
 
  
382
 
  geoObj_.invalidate();
383
 
}
384
 
 
385
 
//! set item pointer to NULL
386
 
template<int dim, class GridImp>
387
 
inline void ALU2dGridEntity<0,dim,GridImp> :: removeElement() {
388
 
  item_ = 0;
389
 
  geoObj_.invalidate();
390
 
}
391
 
 
392
 
//! compare 2 entities, which means compare the item pointers 
393
 
template<int dim, class GridImp>
394
 
inline bool ALU2dGridEntity<0,dim,GridImp> :: equals ( const ALU2dGridEntity<0,dim,GridImp> & org ) const {
395
 
  return (item_ == org.item_);
396
 
}
397
 
 
398
 
 
399
 
//**********************************************************************
400
 
//
401
 
// --EntityPointer
402
 
// --EnPointer
403
 
//
404
 
//**********************************************************************
405
 
 
406
 
//! has to be called when iterator is finished
407
 
template<int cd, class GridImp>
408
 
inline void ALU2dGridEntityPointer<cd, GridImp> :: done() 
409
 
{
410
 
  // sets entity pointer in the status of an empty entity
411
 
  if(entity_)  
412
 
  {
413
 
     entityImp().removeElement();
414
 
     factory_.template freeEntity< cd > ( entity_ );
415
 
     entity_ = 0;
416
 
  }                               
417
 
  seed_.clear();
418
 
}
419
 
 
420
 
template<int cd, class GridImp>
421
 
inline bool ALU2dGridEntityPointer<cd, GridImp> :: equals(const ALU2dGridEntityPointer<cd, GridImp> & i) const 
422
 
{  
423
 
  return seed_ == i.seed_;
424
 
}
425
 
 
426
 
//! update underlying item pointer and set entity
427
 
template<int cd, class GridImp>
428
 
inline void ALU2dGridEntityPointer<cd, GridImp> :: updateEntityPointer(ElementType * item, int face, int level) 
429
 
{
430
 
  assert(item != 0);
431
 
  seed_.set( *item, level, face );
432
 
  
433
 
  if( entity_ ) 
434
 
  {   
435
 
    entityImp().setElement( seed_ );
436
 
  }    
437
 
}
438
 
 
439
 
//! Constructor for EntityPointer that points to an element 
440
 
template<int cd, class GridImp>
441
 
inline ALU2dGridEntityPointer<cd, GridImp>:: 
442
 
ALU2dGridEntityPointer(const FactoryType& factory, 
443
 
                       const ElementType& item, int face, int level) 
444
 
  : factory_( factory )
445
 
  , seed_( item, level, face )
446
 
  , entity_(0)
447
 
  { }
448
 
 
449
 
//! Constructor for EntityPointer that points to an element 
450
 
template<int cd, class GridImp>
451
 
inline ALU2dGridEntityPointer<cd, GridImp>:: 
452
 
ALU2dGridEntityPointer(const EntityImp& entity) 
453
 
  : factory_( entity.factory() )
454
 
  , seed_( entity.getItem(), entity.level(), entity.getFace() )
455
 
  , entity_(0)
456
 
  { }
457
 
 
458
 
//! Constructor for EntityPointer that points to an element 
459
 
template<int cd, class GridImp>
460
 
inline ALU2dGridEntityPointer<cd, GridImp>:: 
461
 
ALU2dGridEntityPointer(const FactoryType& factory, const EntitySeed& seed) 
462
 
  : factory_( factory )
463
 
  , seed_( seed )
464
 
  , entity_(0)
 
303
    }
 
304
    return -1;
 
305
  }
 
306
  //***************************************************************
 
307
  //  Interface for Adaptation
 
308
  //***************************************************************
 
309
  //! marks an element for refCount refines. if refCount is negative the
 
310
  //! element is coarsend -refCount times
 
311
  //! mark returns true if element was marked, otherwise false
 
312
  template<int dim, class GridImp>
 
313
  inline bool ALU2dGridEntity<0,dim,GridImp> :: mark( int refCount ) const
 
314
  {
 
315
    if( !isLeaf() ) return false;
 
316
 
 
317
    // if this assertion is thrown then you try to mark a non leaf entity
 
318
    // which is leads to unpredictable results
 
319
    assert(item_ != 0);
 
320
 
 
321
    // mark for coarsening
 
322
    if(refCount < 0)
 
323
    {
 
324
      if(level() <= 0) return false;
 
325
      item_->ALU2DSPACE Refco_el::mark(ALU2DSPACE Refco::crs);
 
326
      return true;
 
327
    }
 
328
 
 
329
    // mark for refinement
 
330
    if(refCount > 0)
 
331
    {
 
332
      item_->ALU2DSPACE Refco_el::mark(ALU2DSPACE Refco::ref);
 
333
      return true;
 
334
    }
 
335
 
 
336
    // mark with none
 
337
    item_->ALU2DSPACE Refco_el::mark(ALU2DSPACE Refco::none);
 
338
    return true;
 
339
  }
 
340
 
 
341
  template<int dim, class GridImp>
 
342
  inline int ALU2dGridEntity<0,dim,GridImp> :: getMark() const
 
343
  {
 
344
    assert(item_ != 0);
 
345
    if(item_->ALU2DSPACE Refco_el::is(ALU2DSPACE Refco::ref)) return 1;
 
346
    if(item_->ALU2DSPACE Refco_el::is(ALU2DSPACE Refco::crs)) return -1;
 
347
    assert( item_->ALU2DSPACE Refco_el::is(ALU2DSPACE Refco::none) );
 
348
    return 0;
 
349
  }
 
350
 
 
351
  /*! private methods, but public because of datahandle and template
 
352
      arguments of these methods
 
353
   */
 
354
  template<int dim, class GridImp>
 
355
  inline void ALU2dGridEntity<0,dim,GridImp> ::
 
356
  setElement(const HElementType &element, int face, int level) const
 
357
  {
 
358
    item_= const_cast<HElementType *> (&element);
 
359
    isLeaf_  = ((*item_).down() == 0);
 
360
 
 
361
    geoObj_.invalidate();
 
362
  }
 
363
 
 
364
  template<int dim, class GridImp>
 
365
  inline void ALU2dGridEntity<0,dim,GridImp> ::
 
366
  setElement(const EntitySeed& seed ) const
 
367
  {
 
368
    setElement( *(seed.item()) ); //, seed.face(), seed.level() );
 
369
  }
 
370
 
 
371
 
 
372
  //! set actual walk level
 
373
  template<int dim, class GridImp>
 
374
  inline void ALU2dGridEntity<0,dim,GridImp> :: reset ( int l )
 
375
  {
 
376
    item_       = 0;
 
377
    isLeaf_     = false;
 
378
 
 
379
    geoObj_.invalidate();
 
380
  }
 
381
 
 
382
  //! set item pointer to NULL
 
383
  template<int dim, class GridImp>
 
384
  inline void ALU2dGridEntity<0,dim,GridImp> :: removeElement() {
 
385
    item_ = 0;
 
386
    geoObj_.invalidate();
 
387
  }
 
388
 
 
389
  //! compare 2 entities, which means compare the item pointers
 
390
  template<int dim, class GridImp>
 
391
  inline bool ALU2dGridEntity<0,dim,GridImp> :: equals ( const ALU2dGridEntity<0,dim,GridImp> & org ) const {
 
392
    return (item_ == org.item_);
 
393
  }
 
394
 
 
395
 
 
396
  //**********************************************************************
 
397
  //
 
398
  // --EntityPointer
 
399
  // --EnPointer
 
400
  //
 
401
  //**********************************************************************
 
402
 
 
403
  //! has to be called when iterator is finished
 
404
  template<int cd, class GridImp>
 
405
  inline void ALU2dGridEntityPointer<cd, GridImp> :: done()
 
406
  {
 
407
    // sets entity pointer in the status of an empty entity
 
408
    if(entity_)
 
409
    {
 
410
      entityImp().removeElement();
 
411
      factory_.template freeEntity< cd > ( entity_ );
 
412
      entity_ = 0;
 
413
    }
 
414
    seed_.clear();
 
415
  }
 
416
 
 
417
  template<int cd, class GridImp>
 
418
  inline bool ALU2dGridEntityPointer<cd, GridImp> :: equals(const ALU2dGridEntityPointer<cd, GridImp> & i) const
 
419
  {
 
420
    return seed_ == i.seed_;
 
421
  }
 
422
 
 
423
  //! update underlying item pointer and set entity
 
424
  template<int cd, class GridImp>
 
425
  inline void ALU2dGridEntityPointer<cd, GridImp> :: updateEntityPointer(ElementType * item, int face, int level)
 
426
  {
 
427
    assert(item != 0);
 
428
    seed_.set( *item, level, face );
 
429
 
 
430
    if( entity_ )
 
431
    {
 
432
      entityImp().setElement( seed_ );
 
433
    }
 
434
  }
 
435
 
 
436
  //! Constructor for EntityPointer that points to an element
 
437
  template<int cd, class GridImp>
 
438
  inline ALU2dGridEntityPointer<cd, GridImp>::
 
439
  ALU2dGridEntityPointer(const FactoryType& factory,
 
440
                         const ElementType& item, int face, int level)
 
441
    : factory_( factory )
 
442
      , seed_( item, level, face )
 
443
      , entity_(0)
 
444
  { }
 
445
 
 
446
  //! Constructor for EntityPointer that points to an element
 
447
  template<int cd, class GridImp>
 
448
  inline ALU2dGridEntityPointer<cd, GridImp>::
 
449
  ALU2dGridEntityPointer(const EntityImp& entity)
 
450
    : factory_( entity.factory() )
 
451
      , seed_( entity.getItem(), entity.level(), entity.getFace() )
 
452
      , entity_(0)
 
453
  { }
 
454
 
 
455
  //! Constructor for EntityPointer that points to an element
 
456
  template<int cd, class GridImp>
 
457
  inline ALU2dGridEntityPointer<cd, GridImp>::
 
458
  ALU2dGridEntityPointer(const FactoryType& factory, const EntitySeed& seed)
 
459
    : factory_( factory )
 
460
      , seed_( seed )
 
461
      , entity_(0)
465
462
  { }
466
463
 
467
464
  //! Constructor for EntityPointer init of Level- and LeafIterator
468
 
template<int cd, class GridImp>
469
 
inline ALU2dGridEntityPointer<cd, GridImp>:: ALU2dGridEntityPointer(const FactoryType& factory) 
470
 
    : factory_( factory ) 
471
 
    , seed_()
472
 
    , entity_(0)
473
 
   { }
 
465
  template<int cd, class GridImp>
 
466
  inline ALU2dGridEntityPointer<cd, GridImp>:: ALU2dGridEntityPointer(const FactoryType& factory)
 
467
    : factory_( factory )
 
468
      , seed_()
 
469
      , entity_(0)
 
470
  { }
474
471
 
475
472
  //! Copy Constructor
476
 
template<int cd, class GridImp>
477
 
inline ALU2dGridEntityPointer<cd, GridImp>:: ALU2dGridEntityPointer(const ThisType & org) 
478
 
    : factory_( org.factory_ )  
479
 
    , seed_( org.seed_ )
480
 
    , entity_(0) 
481
 
    {  }
482
 
  
483
 
//! Destructor  
484
 
template<int cd, class GridImp>
485
 
inline ALU2dGridEntityPointer<cd, GridImp>::~ALU2dGridEntityPointer() 
486
 
{
487
 
  this->done();
488
 
489
 
 
490
 
//! dereferencing
491
 
template<int cd, class GridImp>
492
 
inline typename ALU2dGridEntityPointer<cd, GridImp>::Entity & 
493
 
ALU2dGridEntityPointer<cd, GridImp>:: dereference() const 
494
 
{
495
 
  if( ! entity_ )
496
 
  {
497
 
    entity_ = factory_.template getNewEntity<cd> (level());
498
 
    entityImp().setElement( seed_ );
499
 
  }
500
 
  assert( entity_ );  
501
 
  return *entity_; 
502
 
}
503
 
 
504
 
//! ask for level of entities 
505
 
template<int cd, class GridImp>
506
 
inline int ALU2dGridEntityPointer<cd, GridImp>:: level () const 
507
 
{
508
 
  assert( seed_.level() >= 0 );
509
 
  return seed_.level();
510
 
}
511
 
 
512
 
template<int cd, class GridImp>
513
 
inline typename ALU2dGridEntityPointer<cd, GridImp>:: ThisType &
514
 
ALU2dGridEntityPointer<cd, GridImp>:: operator = (const typename ALU2dGridEntityPointer<cd, GridImp>::ThisType & org) 
515
 
{
516
 
  this->done();
517
 
  assert(&factory_ == &org.factory_);
518
 
  seed_ = org.seed_; // copy seed 
519
 
  entity_ = 0; // is set when dereference is called 
520
 
  return *this;
521
 
}
522
 
 
523
 
template<int cd, class GridImp>
524
 
inline typename ALU2dGridEntityPointer<cd, GridImp>::EntityImp & ALU2dGridEntityPointer<cd, GridImp>::entityImp() 
525
 
526
 
  assert( entity_ ); 
527
 
  return GridImp :: getRealImplementation(*entity_); 
528
 
}
529
 
 
530
 
template<int cd, class GridImp>
531
 
inline const typename ALU2dGridEntityPointer<cd, GridImp>:: EntityImp & 
532
 
ALU2dGridEntityPointer<cd, GridImp>::entityImp() const { 
533
 
  assert( entity_ ); 
534
 
  return GridImp :: getRealImplementation(*entity_); 
535
 
}
536
 
 
537
 
//********* begin struct ElementWrapper ********************
538
 
//template <int codim, int dim, class GridImp>
539
 
//struct ElementWrapper;
540
 
// partial specialisation for codim
541
 
//
542
 
//--ElementWrapper
543
 
//**********************************************************
544
 
 
545
 
// specialisation for elements
546
 
template<int dim, class GridImp>
547
 
struct ElementWrapper<0,dim, GridImp>
548
 
549
 
  typedef typename ALU2dImplTraits< GridImp::dimensionworld, GridImp::elementType >::HElementType HElementType ;
550
 
  typedef typename GridImp :: GridObjectFactoryType  FactoryType;
551
 
 
552
 
  static inline int getElemIndex(GridImp & grid, const HElementType &elem, int i) {   
553
 
    //assert(!i);    
554
 
    return elem.getIndex();
555
 
  }
556
 
  static inline int subIndex(GridImp & grid, const HElementType &elem, int i) {   
557
 
    //assert(!i);    
558
 
    return elem.getIndex();
559
 
  }
560
 
  static inline typename ALU2dGridEntity<0,dim,GridImp > :: template Codim<0>:: EntityPointer 
561
 
  subEntity(const FactoryType& factory, const HElementType &elem, int i) {   
562
 
    //assert(!i);    
563
 
    return ALU2dGridEntityPointer<0, GridImp > (factory, elem, -1, elem.level());
564
 
  }
565
 
  static inline int subBoundary(GridImp & grid, const HElementType &elem, int i) {   
566
 
    //assert(!i);    
567
 
    return elem.nbbnd(i)->type();      
568
 
    
569
 
  }  
570
 
  static inline bool isTheSame(const HElementType * elem, int face, const HElementType * org, int org_face) {   
571
 
    return (elem == org);    
572
 
  }  
573
 
};
574
 
 
575
 
// specialisation for edges
576
 
template<int dim, class GridImp>
577
 
struct ElementWrapper<1, dim, GridImp>{ 
578
 
 
579
 
  typedef typename ALU2dImplTraits< GridImp::dimensionworld, GridImp::elementType >::HElementType HElementType ;
580
 
  typedef typename GridImp :: GridObjectFactoryType  FactoryType;
581
 
 
582
 
  static inline int getElemIndex(GridImp & grid, const HElementType &elem, int i) 
583
 
  {   
584
 
    assert(i < elem.numvertices() && i >= 0);    
585
 
    return elem.edge_idx(i);      
586
 
  }   
587
 
  static inline int subIndex(GridImp & grid, const HElementType &elem, int i) 
588
 
  {  
589
 
    assert(i < elem.numvertices() && i >= 0);    
590
 
    return elem.edge_idx(i);      
591
 
  }
592
 
  static inline typename ALU2dGridEntity<0,dim,GridImp > :: template Codim<1>:: EntityPointer 
593
 
  subEntity(const FactoryType& factory, const HElementType &elem, int i)    
594
 
  {   
595
 
    assert(i < elem.numvertices() && i >= 0);    
596
 
    return ALU2dGridEntityPointer<1, GridImp > (factory, elem, i, elem.level());
597
 
  } 
598
 
  static inline int subBoundary(GridImp & grid, const HElementType &elem, int i) {   
599
 
    DUNE_THROW(NotImplemented, "Not yet implemented for this codim!");   
600
 
    return -1;
601
 
  }   
602
 
  static inline bool isTheSame(const HElementType * elem, int face, const HElementType * org, int org_face) 
603
 
  {
604
 
    if (elem == org) 
605
 
    {
606
 
      if (face == org_face)
607
 
        return true;
608
 
      else 
609
 
        return false;
610
 
    }
611
 
    else { 
612
 
      if (elem != 0 && org != 0)
613
 
        return  (elem->edge_idx(face) == org->edge_idx(org_face));      
614
 
    }
615
 
    return false;
616
 
  }  
617
 
};
618
 
 
619
 
// specialisation for vertices
620
 
template<int dim, class GridImp>
621
 
struct ElementWrapper<2, dim, GridImp>{    
622
 
 
623
 
  typedef typename ALU2dImplTraits< GridImp::dimensionworld, GridImp::elementType >::HElementType HElementType ;
624
 
  typedef typename ALU2dImplInterface< 0, GridImp::dimensionworld, GridImp::elementType >::Type VertexType;
625
 
  typedef typename GridImp :: GridObjectFactoryType  FactoryType;
626
 
  
627
 
  static inline int getElemIndex(GridImp & grid, const VertexType &elem, int) {   
628
 
    return elem.getIndex();      
629
 
  }   
630
 
  static inline int subIndex(GridImp & grid, const HElementType &elem, int i) {  
631
 
    assert(i < elem.numvertices() && i >= 0);   
632
 
    //return elem.vertex(i)->getIndex();          
633
 
    return elem.getVertex(i)->getIndex();
634
 
  }
635
 
  static inline typename ALU2dGridEntity<0,dim,GridImp > :: template Codim<2>:: EntityPointer 
636
 
  subEntity(const FactoryType& factory, const HElementType &elem, int i)   
637
 
  {
638
 
    assert(i < elem.numvertices() && i >= 0);   
639
 
    //return ALU2dGridEntityPointer<2, GridImp > (grid, *(elem.vertex(i)), -1, elem.level());
640
 
    return ALU2dGridEntityPointer<2, GridImp > (factory, *(elem.getVertex(i)), -1, elem.level());
641
 
  }
642
 
  static inline int subBoundary(GridImp & grid, const HElementType &elem, int i) {   
643
 
    DUNE_THROW(NotImplemented, "Not yet implemented this codim!");    
644
 
    return -1;
645
 
  }  
646
 
  static inline bool isTheSame(const VertexType * elem, int face, const VertexType * org, int org_face) {   
647
 
    return (elem == org);    
648
 
  }  
649
 
};
650
 
 
651
 
//********* end struct ElementWrapper ********************
652
 
 
653
 
 
654
 
 
655
 
} //end namespace Dune 
 
473
  template<int cd, class GridImp>
 
474
  inline ALU2dGridEntityPointer<cd, GridImp>:: ALU2dGridEntityPointer(const ThisType & org)
 
475
    : factory_( org.factory_ )
 
476
      , seed_( org.seed_ )
 
477
      , entity_(0)
 
478
  {  }
 
479
 
 
480
  //! Destructor
 
481
  template<int cd, class GridImp>
 
482
  inline ALU2dGridEntityPointer<cd, GridImp>::~ALU2dGridEntityPointer()
 
483
  {
 
484
    this->done();
 
485
  }
 
486
 
 
487
  //! dereferencing
 
488
  template<int cd, class GridImp>
 
489
  inline typename ALU2dGridEntityPointer<cd, GridImp>::Entity &
 
490
  ALU2dGridEntityPointer<cd, GridImp>:: dereference() const
 
491
  {
 
492
    if( ! entity_ )
 
493
    {
 
494
      entity_ = factory_.template getNewEntity<cd> (level());
 
495
      entityImp().setElement( seed_ );
 
496
    }
 
497
    assert( entity_ );
 
498
    return *entity_;
 
499
  }
 
500
 
 
501
  //! ask for level of entities
 
502
  template<int cd, class GridImp>
 
503
  inline int ALU2dGridEntityPointer<cd, GridImp>:: level () const
 
504
  {
 
505
    assert( seed_.level() >= 0 );
 
506
    return seed_.level();
 
507
  }
 
508
 
 
509
  template<int cd, class GridImp>
 
510
  inline typename ALU2dGridEntityPointer<cd, GridImp>:: ThisType &
 
511
  ALU2dGridEntityPointer<cd, GridImp>:: operator = (const typename ALU2dGridEntityPointer<cd, GridImp>::ThisType & org)
 
512
  {
 
513
    this->done();
 
514
    assert(&factory_ == &org.factory_);
 
515
    seed_ = org.seed_; // copy seed
 
516
    entity_ = 0; // is set when dereference is called
 
517
    return *this;
 
518
  }
 
519
 
 
520
  template<int cd, class GridImp>
 
521
  inline typename ALU2dGridEntityPointer<cd, GridImp>::EntityImp & ALU2dGridEntityPointer<cd, GridImp>::entityImp()
 
522
  {
 
523
    assert( entity_ );
 
524
    return GridImp :: getRealImplementation(*entity_);
 
525
  }
 
526
 
 
527
  template<int cd, class GridImp>
 
528
  inline const typename ALU2dGridEntityPointer<cd, GridImp>:: EntityImp &
 
529
  ALU2dGridEntityPointer<cd, GridImp>::entityImp() const {
 
530
    assert( entity_ );
 
531
    return GridImp :: getRealImplementation(*entity_);
 
532
  }
 
533
 
 
534
  //********* begin struct ElementWrapper ********************
 
535
  //template <int codim, int dim, class GridImp>
 
536
  //struct ElementWrapper;
 
537
  // partial specialisation for codim
 
538
  //
 
539
  //--ElementWrapper
 
540
  //**********************************************************
 
541
 
 
542
  // specialisation for elements
 
543
  template<int dim, class GridImp>
 
544
  struct ElementWrapper<0,dim, GridImp>
 
545
  {
 
546
    typedef typename ALU2dImplTraits< GridImp::dimensionworld, GridImp::elementType >::HElementType HElementType ;
 
547
    typedef typename GridImp :: GridObjectFactoryType FactoryType;
 
548
 
 
549
    static inline int getElemIndex(GridImp & grid, const HElementType &elem, int i) {
 
550
      //assert(!i);
 
551
      return elem.getIndex();
 
552
    }
 
553
    static inline int subIndex(GridImp & grid, const HElementType &elem, int i) {
 
554
      //assert(!i);
 
555
      return elem.getIndex();
 
556
    }
 
557
    static inline typename ALU2dGridEntity<0,dim,GridImp > :: template Codim<0>:: EntityPointer
 
558
    subEntity(const FactoryType& factory, const HElementType &elem, int i) {
 
559
      //assert(!i);
 
560
      return ALU2dGridEntityPointer<0, GridImp > (factory, elem, -1, elem.level());
 
561
    }
 
562
    static inline int subBoundary(GridImp & grid, const HElementType &elem, int i) {
 
563
      //assert(!i);
 
564
      return elem.nbbnd(i)->type();
 
565
 
 
566
    }
 
567
    static inline bool isTheSame(const HElementType * elem, int face, const HElementType * org, int org_face) {
 
568
      return (elem == org);
 
569
    }
 
570
  };
 
571
 
 
572
  // specialisation for edges
 
573
  template<int dim, class GridImp>
 
574
  struct ElementWrapper<1, dim, GridImp>{
 
575
 
 
576
    typedef typename ALU2dImplTraits< GridImp::dimensionworld, GridImp::elementType >::HElementType HElementType ;
 
577
    typedef typename GridImp :: GridObjectFactoryType FactoryType;
 
578
 
 
579
    static inline int getElemIndex(GridImp & grid, const HElementType &elem, int i)
 
580
    {
 
581
      assert(i < elem.numvertices() && i >= 0);
 
582
      return elem.edge_idx(i);
 
583
    }
 
584
    static inline int subIndex(GridImp & grid, const HElementType &elem, int i)
 
585
    {
 
586
      assert(i < elem.numvertices() && i >= 0);
 
587
      return elem.edge_idx(i);
 
588
    }
 
589
    static inline typename ALU2dGridEntity<0,dim,GridImp > :: template Codim<1>:: EntityPointer
 
590
    subEntity(const FactoryType& factory, const HElementType &elem, int i)
 
591
    {
 
592
      assert(i < elem.numvertices() && i >= 0);
 
593
      return ALU2dGridEntityPointer<1, GridImp > (factory, elem, i, elem.level());
 
594
    }
 
595
    static inline int subBoundary(GridImp & grid, const HElementType &elem, int i) {
 
596
      DUNE_THROW(NotImplemented, "Not yet implemented for this codim!");
 
597
      return -1;
 
598
    }
 
599
    static inline bool isTheSame(const HElementType * elem, int face, const HElementType * org, int org_face)
 
600
    {
 
601
      if (elem == org)
 
602
      {
 
603
        if (face == org_face)
 
604
          return true;
 
605
        else
 
606
          return false;
 
607
      }
 
608
      else {
 
609
        if (elem != 0 && org != 0)
 
610
          return  (elem->edge_idx(face) == org->edge_idx(org_face));
 
611
      }
 
612
      return false;
 
613
    }
 
614
  };
 
615
 
 
616
  // specialisation for vertices
 
617
  template<int dim, class GridImp>
 
618
  struct ElementWrapper<2, dim, GridImp>{
 
619
 
 
620
    typedef typename ALU2dImplTraits< GridImp::dimensionworld, GridImp::elementType >::HElementType HElementType ;
 
621
    typedef typename ALU2dImplInterface< 0, GridImp::dimensionworld, GridImp::elementType >::Type VertexType;
 
622
    typedef typename GridImp :: GridObjectFactoryType FactoryType;
 
623
 
 
624
    static inline int getElemIndex(GridImp & grid, const VertexType &elem, int) {
 
625
      return elem.getIndex();
 
626
    }
 
627
    static inline int subIndex(GridImp & grid, const HElementType &elem, int i) {
 
628
      assert(i < elem.numvertices() && i >= 0);
 
629
      //return elem.vertex(i)->getIndex();
 
630
      return elem.getVertex(i)->getIndex();
 
631
    }
 
632
    static inline typename ALU2dGridEntity<0,dim,GridImp > :: template Codim<2>:: EntityPointer
 
633
    subEntity(const FactoryType& factory, const HElementType &elem, int i)
 
634
    {
 
635
      assert(i < elem.numvertices() && i >= 0);
 
636
      //return ALU2dGridEntityPointer<2, GridImp > (grid, *(elem.vertex(i)), -1, elem.level());
 
637
      return ALU2dGridEntityPointer<2, GridImp > (factory, *(elem.getVertex(i)), -1, elem.level());
 
638
    }
 
639
    static inline int subBoundary(GridImp & grid, const HElementType &elem, int i) {
 
640
      DUNE_THROW(NotImplemented, "Not yet implemented this codim!");
 
641
      return -1;
 
642
    }
 
643
    static inline bool isTheSame(const VertexType * elem, int face, const VertexType * org, int org_face) {
 
644
      return (elem == org);
 
645
    }
 
646
  };
 
647
 
 
648
  //********* end struct ElementWrapper ********************
 
649
 
 
650
 
 
651
 
 
652
} //end namespace Dune
656
653
 
657
654
#endif