dune-grid  2.4.1
alugrid/3d/entityseed.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef ALU3DGRID_ENTITYKEY_HH
4 #define ALU3DGRID_ENTITYKEY_HH
5 
6 namespace Dune
7 {
8 
9  template<int cd, class GridImp>
11 
12  //**********************************************************************
13  //
14  // --ALU3dGridEntitySeed
15  // --EntitySeed
16  //**********************************************************************
17  template< int codim, class GridImp >
19  {
20  protected:
22  enum { dim = GridImp::dimension };
23  enum { dimworld = GridImp::dimensionworld };
24 
25 
26  typedef typename GridImp::MPICommunicatorType Comm;
27 
28  friend class ALU3dGridEntity<codim,dim,GridImp>;
29  friend class ALU3dGridEntity< 0,dim,GridImp>;
30  friend class ALU3dGrid < GridImp::elementType, Comm >;
31 
32  typedef ALU3dImplTraits<GridImp::elementType, Comm > ImplTraits;
33  typedef typename ImplTraits::template Codim<codim>::ImplementationType ImplementationType;
34  typedef typename ImplTraits::template Codim<codim>::InterfaceType HElementType;
35  typedef typename ImplTraits::template Codim<codim>::EntitySeedType KeyType ;
36 
37  typedef typename ImplTraits::BNDFaceType BNDFaceType;
38  typedef typename ImplTraits::HBndSegType HBndSegType;
39 
40  template <int cd, class Key>
41  struct Bnd
42  {
43  static Key* toKey(const HBndSegType*)
44  {
45  return (Key*) 0;
46  }
48  {
49  return static_cast< HElementType* > ( key );
50  }
51  static bool isGhost(KeyType*) { return false; }
52  static BNDFaceType* ghost( KeyType* ) { return ( BNDFaceType* ) 0; }
53  };
54  template <class Key>
55  struct Bnd<0, Key>
56  {
57  static Key* toKey(const HBndSegType* ghostFace)
58  {
59  return static_cast< KeyType* > (const_cast< BNDFaceType* >( static_cast<const BNDFaceType*> (ghostFace)));
60  }
62  {
63  if( key )
64  {
65  if( key->isboundary() )
66  {
67  return ((static_cast< BNDFaceType* > ( key ))->getGhost().first);
68  }
69  else
70  {
71  // we cannot cast to HElement here, since only the implementation is derived
72  // from hasFace
73  return static_cast< HElementType * > (static_cast< ImplementationType* > (key));
74  }
75  }
76  else
77  return static_cast< HElementType * > (0) ;
78  }
79  static bool isGhost(KeyType* key) { assert( key ); return key->isboundary(); }
80  static BNDFaceType* ghost( KeyType* key ) { assert( key ); return (static_cast< BNDFaceType* > ( key )); }
81  };
82  public:
83  static const int defaultValue = -1 ;
84  static const int defaultTwist = 0 ;
85 
86  enum { codimension = codim };
87 
89  typedef typename GridImp::template Codim<codimension>::Entity Entity;
93 
95  typedef ThisType ALU3dGridEntitySeedType;
96 
99 
102  {
103 #ifndef NDEBUG
104  // clear pointer
105  clear();
106 #endif
107  }
108 
111 
114 
116  ALU3dGridEntitySeedBase(const HElementType* item, const HBndSegType* ghostFace );
117 
119  ALU3dGridEntitySeedBase(const HBndSegType& ghostFace );
120 
122  //
123  // interface methods
124  //
127  ALU3dGridEntitySeedBase(const ALU3dGridEntitySeedType & org);
128 
130  bool operator == (const ALU3dGridEntitySeedType& i) const
131  {
132  return equals( i );
133  }
134 
136  bool operator != (const ALU3dGridEntitySeedType& i) const
137  {
138  return ! equals( i );
139  }
140 
142  ThisType & operator = (const ThisType & org);
143 
145  bool isValid () const
146  {
147  return item_ != 0;
148  }
149 
151  //
152  // non-interface methods
153  //
156  bool equals (const ALU3dGridEntitySeedType& i) const;
157 
159  void clear()
160  {
161  item_ = 0;
162  }
163 
166 
169  {
170  assert( ! isGhost() );
171  return static_cast< HElementType * > (static_cast< ImplementationType* > (item_));
172  }
173 
175  bool isGhost() const { return Bnd<codim,KeyType>::isGhost( item_ ); }
177  {
178  assert( isGhost() );
180  }
181 
183  {
184  return static_cast< KeyType* > (const_cast< ImplementationType* > (static_cast<const ImplementationType* > (item)));
185  }
186 
187  void set(const HElementType& item)
188  {
189  item_ = toKey( &item );
190  }
191 
192  KeyType* toKey( const HBndSegType* ghostFace )
193  {
194  return Bnd<codim,KeyType>::toKey( ghostFace );
195  }
196 
197  void set(const HBndSegType& ghostFace)
198  {
199  item_ = toKey( &ghostFace );
200  }
201 
202  int level () const { return defaultValue; }
203  int twist () const { return defaultTwist; }
204  int face () const { return defaultValue; }
205 
206  protected:
207  // pointer to item
208  mutable KeyType* item_;
209  };
210 
211  template<int cd, class GridImp>
212  class ALU3dGridEntitySeed :
213  public ALU3dGridEntitySeedBase<cd,GridImp>
214  {
215  typedef ALU3dGridEntitySeedBase<cd,GridImp> BaseType;
216 
217  typedef ALU3dGridEntitySeed <cd,GridImp> ThisType;
218  enum { dim = GridImp::dimension };
219  enum { dimworld = GridImp::dimensionworld };
220 
221  typedef typename GridImp::MPICommunicatorType Comm;
222 
223  friend class ALU3dGridEntity<cd,dim,GridImp>;
224  friend class ALU3dGridEntity< 0,dim,GridImp>;
225  friend class ALU3dGrid < GridImp::elementType, Comm >;
226 
227  typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits;
228  typedef typename ImplTraits::template Codim<cd>::ImplementationType ImplementationType;
229  typedef typename ImplTraits::template Codim<cd>::InterfaceType HElementType;
230 
231  typedef typename ImplTraits::BNDFaceType BNDFaceType;
232  typedef ALU3dGridEntity<cd,dim,GridImp> ALU3dGridEntityType;
233 
234  public:
235  using BaseType :: defaultValue ;
236  using BaseType :: defaultTwist ;
237 
239  typedef typename GridImp::template Codim<cd>::Entity Entity;
240 
243 
245  ALU3dGridEntitySeed(const ImplementationType & item)
246  {
247  // this constructor should only be called by codim=0 entity keys
248  assert( false );
249  abort();
250  }
251 
253  ALU3dGridEntitySeed(const HElementType & item,
254  const int level,
255  const int twist = defaultTwist,
256  const int duneFace = defaultValue
257  );
258 
262 
265  : ALU3dGridEntitySeedBase<cd,GridImp> (entity.getItem()),
267  {}
268 
271 
273  ThisType & operator = (const ThisType & org);
274 
276  void clear();
277 
279  void set(const HElementType & item, const int level )
280  {
281  BaseType :: set( item );
282  level_ = level ;
283  }
284 
286  int level () const { return level_ ; }
288  int twist () const { return twist_ ; }
290  int face () const { return face_ ; }
291 
292  using BaseType :: set ;
293 
295  {
296  return equals( i );
297  }
298 
300  {
301  return ! equals( i );
302  }
303 
305  bool equals (const ALU3dGridEntitySeedType& key) const
306  {
307  // only compare the item pointer, this is the real key
308  return BaseType :: equals( key ) && (level() == key.level());
309  }
310 
311  protected:
312  // level of entity
313  int level_;
314  // twist of face, for codim 1 only
315  int twist_;
316  // face number, for codim 1 only
317  int face_;
318  };
319 
323  template<class GridImp>
324  class ALU3dGridEntitySeed<0,GridImp> :
325  public ALU3dGridEntitySeedBase<0,GridImp>
326  {
327  protected:
329 
330  enum { cd = 0 };
332  enum { dim = GridImp::dimension };
333  enum { dimworld = GridImp::dimensionworld };
334 
335  typedef typename GridImp::MPICommunicatorType Comm;
336 
337  friend class ALU3dGridEntity<cd,dim,GridImp>;
338  friend class ALU3dGridEntity< 0,dim,GridImp>;
339  friend class ALU3dGrid < GridImp::elementType, Comm >;
340 
341  typedef ALU3dImplTraits<GridImp::elementType, Comm > ImplTraits;
342  typedef typename ImplTraits::template Codim<cd>::ImplementationType ImplementationType;
343  typedef typename ImplTraits::template Codim<cd>::InterfaceType HElementType;
344 
345  typedef typename ImplTraits::BNDFaceType BNDFaceType;
346  typedef typename ImplTraits::HBndSegType HBndSegType;
347 
348  typedef ALU3dGridEntity< 0,dim,GridImp> ALU3dGridEntityType ;
349 
350  public:
351  using BaseType :: defaultValue ;
352  using BaseType :: defaultTwist ;
353 
355  typedef typename GridImp::template Codim<cd>::Entity Entity;
356 
358  typedef ThisType ALU3dGridEntitySeedType;
359 
361  ALU3dGridEntitySeed() : BaseType() {}
362 
365  : ALU3dGridEntitySeedBase<cd,GridImp> (item) {}
366 
368  ALU3dGridEntitySeed(const HElementType& item, int , int , int )
369  : ALU3dGridEntitySeedBase<cd,GridImp> (item) {}
370 
372  ALU3dGridEntitySeed(const HBndSegType& ghostFace )
373  : ALU3dGridEntitySeedBase<cd,GridImp> ( ghostFace ) {}
374 
377  : ALU3dGridEntitySeedBase<cd,GridImp> (org)
378  {}
379  };
380 
381 
383  template <int cd, class GridImp>
384  inline std :: ostream &operator<< ( std :: ostream &out,
386  {
387  out << key.item() << " " << key.level() << " " << key.twist() << " " << key.face();
388  return out;
389  }
390 
391 
392  //*******************************************************************
393  //
394  // Implementation
395  //
396  //*******************************************************************
397  template<int codim, class GridImp >
400  : item_( 0 )
401  {}
402 
403  template<int codim, class GridImp >
406  : item_( toKey(&item) )
407  {}
408 
409  template<int codim, class GridImp >
412  : item_( toKey(&ghostFace) )
413  {}
414 
415  template<int codim, class GridImp >
418  : item_(org.item_)
419  {}
420 
421  template<int codim, class GridImp >
425  {
426  item_ = org.item_;
427  return *this;
428  }
429 
430  template<int codim, class GridImp >
433  {
434  // check equality of underlying items
435  return (item_ == i.item_);
436  }
437 
439  //
440  // specialisation for higher codims
441  //
443 
444  template<int codim, class GridImp >
446  ALU3dGridEntitySeed(const HElementType &item,
447  const int level,
448  const int twist,
449  const int duneFace )
450  : ALU3dGridEntitySeedBase<codim,GridImp> (item)
451  , level_(level)
452  , twist_ (twist)
453  , face_(duneFace) // duneFace can be -1 when face was created by Face Iterator
454  {}
455 
456  template<int codim, class GridImp >
459  : ALU3dGridEntitySeedBase<codim,GridImp>(org)
460  , level_(org.level_)
461  , twist_(org.twist_)
462  , face_(org.face_)
463  {}
464 
465  template<int codim, class GridImp >
469  {
470  // docu and cleanup
471  BaseType :: operator = ( org );
472 
473  // clone other stuff
474  level_ = org.level_;
475  twist_ = org.twist_;
476  face_ = org.face_;
477  return *this;
478  }
479 
480  template<int codim, class GridImp >
481  inline void
483  {
484  BaseType :: clear();
485  level_ = defaultValue ;
486  twist_ = defaultTwist ;
487  face_ = defaultValue ;
488  }
489 
490 } // end namespace Dune
491 #endif
ImplTraits::template Codim< cd >::ImplementationType ImplementationType
Definition: alugrid/3d/entityseed.hh:342
Definition: alu3dinclude.hh:201
int face_
Definition: alugrid/3d/entityseed.hh:317
int face() const
return face
Definition: alugrid/3d/entityseed.hh:290
Definition: alugrid/3d/entityseed.hh:22
ALU3dGridEntitySeed< cd, GridImp > ThisType
Definition: alugrid/3d/entityseed.hh:331
ThisType ALU3dGridEntitySeedType
typedef of my type
Definition: alugrid/3d/entityseed.hh:95
void set(const HBndSegType &ghostFace)
Definition: alugrid/3d/entityseed.hh:197
EntityObject::ImplementationType EntityImp
Definition: alugrid/3d/entityseed.hh:92
void clear()
clear the key data structure
Definition: alugrid/3d/entityseed.hh:482
KeyType * toKey(const HBndSegType *ghostFace)
Definition: alugrid/3d/entityseed.hh:192
bool isGhost() const
methods for ghosts
Definition: alugrid/3d/entityseed.hh:175
KeyType * item_
Definition: alugrid/3d/entityseed.hh:208
ALU3dGridEntitySeedBase()
Constructor for EntitySeed that points to an element.
Definition: alugrid/3d/entityseed.hh:399
KeyType * toKey(const HElementType *item)
Definition: alugrid/3d/entityseed.hh:182
bool operator!=(const ALU3dGridEntitySeedType &i) const
Definition: alugrid/3d/entityseed.hh:299
ALU3dGridEntitySeedBase< 0, GridImp > BaseType
Definition: alugrid/3d/entityseed.hh:328
ImplTraits::template Codim< codim >::EntitySeedType KeyType
Definition: alugrid/3d/entityseed.hh:35
BNDFaceType * ghost() const
Definition: alugrid/3d/entityseed.hh:176
bool operator!=(const ALU3dGridEntitySeedType &i) const
inequality operator
Definition: alugrid/3d/entityseed.hh:136
static HElementType * getItem(KeyType *key)
Definition: alugrid/3d/entityseed.hh:61
static bool isGhost(KeyType *key)
Definition: alugrid/3d/entityseed.hh:79
HElementType * item() const
get item from key
Definition: alugrid/3d/entityseed.hh:165
MakeableInterfaceObject< Entity > EntityObject
underlying EntityImplementation
Definition: alugrid/3d/entityseed.hh:91
int twist() const
Definition: alugrid/3d/entityseed.hh:203
HElementType * interior() const
return iterior item
Definition: alugrid/3d/entityseed.hh:168
Definition: alugrid/3d/entity.hh:202
int face() const
Definition: alugrid/3d/entityseed.hh:204
bool operator==(const ALU3dGridEntitySeedType &i) const
Definition: alugrid/3d/entityseed.hh:294
ALU3dGridEntitySeedBase< codim, GridImp > ThisType
Definition: alugrid/3d/entityseed.hh:21
static HElementType * getItem(KeyType *key)
Definition: alugrid/3d/entityseed.hh:47
GridImp::template Codim< codimension >::Entity Entity
type of Entity
Definition: alugrid/3d/entityseed.hh:89
ThisType & operator=(const ThisType &org)
assignment operator
Definition: alugrid/3d/entityseed.hh:468
bool equals(const ALU3dGridEntitySeedType &key) const
equality, calls BaseType equals
Definition: alugrid/3d/entityseed.hh:305
Definition: alugrid/3d/entityseed.hh:86
int twist_
Definition: alugrid/3d/entityseed.hh:315
std::ostream & operator<<(std::ostream &out, const ALU2dGridEntitySeed< cd, GridImp > &key)
print alugrid entity key to std::stream
Definition: alugrid/2d/entityseed.hh:286
ImplTraits::template Codim< codim >::ImplementationType ImplementationType
Definition: alugrid/3d/entityseed.hh:33
bool isValid() const
check for valid seed
Definition: alugrid/3d/entityseed.hh:145
int level() const
Definition: alugrid/3d/entityseed.hh:202
void clear()
invalidate seed
Definition: alugrid/3d/entityseed.hh:159
static Key * toKey(const HBndSegType *)
Definition: alugrid/3d/entityseed.hh:43
Definition: alugrid/3d/entityseed.hh:41
static BNDFaceType * ghost(KeyType *key)
Definition: alugrid/3d/entityseed.hh:80
ThisType & operator=(const ThisType &org)
assignment operator
Definition: alugrid/3d/entityseed.hh:424
ImplTraits::template Codim< codim >::InterfaceType HElementType
Definition: alugrid/3d/entityseed.hh:34
Definition: alugrid/3d/entity.hh:22
static BNDFaceType * ghost(KeyType *)
Definition: alugrid/3d/entityseed.hh:52
Definition: alugrid/3d/entityseed.hh:10
static const int defaultTwist
Definition: alugrid/3d/entityseed.hh:84
GridImp::template Codim< cd >::Entity Entity
type of Entity
Definition: alugrid/3d/entityseed.hh:355
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:84
static Key * toKey(const HBndSegType *ghostFace)
Definition: alugrid/3d/entityseed.hh:57
ImplTraits::HBndSegType HBndSegType
Definition: alugrid/3d/entityseed.hh:38
static const int defaultValue
Definition: alugrid/3d/entityseed.hh:83
void set(const HElementType &item)
Definition: alugrid/3d/entityseed.hh:187
int level() const
return level
Definition: alugrid/3d/entityseed.hh:286
GridImp::MPICommunicatorType Comm
Definition: alugrid/3d/entityseed.hh:26
ALU3dGridEntitySeed(const ALU3dGridEntitySeedType &org)
copy constructor
Definition: alugrid/3d/entityseed.hh:376
ALU3dGridEntitySeed< codimension, GridImp > EntitySeedImp
make type of entity pointer implementation available in derived classes
Definition: alugrid/3d/entityseed.hh:98
ALU3dGridEntitySeed(const HElementType &item, int, int, int)
Constructor for EntitySeed that points to an interior element.
Definition: alugrid/3d/entityseed.hh:368
static bool isGhost(KeyType *)
Definition: alugrid/3d/entityseed.hh:51
ImplTraits::BNDFaceType BNDFaceType
Definition: alugrid/3d/entityseed.hh:345
~ALU3dGridEntitySeedBase()
Destructor.
Definition: alugrid/3d/entityseed.hh:101
void set(const HElementType &item, const int level)
set element and level
Definition: alugrid/3d/entityseed.hh:279
int level_
Definition: alugrid/3d/entityseed.hh:313
Entity::Implementation ImplementationType
Definition: common/grid.hh:1468
int twist() const
return twist
Definition: alugrid/3d/entityseed.hh:288
[ provides Dune::Grid ]
Definition: alugrid/3d/entity.hh:36
ALU3dGridEntitySeed(const ALU3dGridEntityType &entity)
Constructor for EntitySeed that points to given entity.
Definition: alugrid/3d/entityseed.hh:264
Definition: alugrid/3d/entityseed.hh:23
ImplTraits::BNDFaceType BNDFaceType
Definition: alugrid/3d/entityseed.hh:37
Include standard header files.
Definition: agrid.hh:59
ALU3dGridEntitySeed< cd, GridImp > ALU3dGridEntitySeedType
typedef of my type
Definition: alugrid/3d/entityseed.hh:242
bool operator==(const ALU3dGridEntitySeedType &i) const
equality operator
Definition: alugrid/3d/entityseed.hh:130
GridImp::MPICommunicatorType Comm
Definition: alugrid/3d/entityseed.hh:335
bool equals(const ALU3dGridEntitySeedType &i) const
equality
Definition: alugrid/3d/entityseed.hh:432
ALU3dGridEntitySeed()
Constructor for EntitySeed that points to an element.
Definition: alugrid/3d/entityseed.hh:260
ImplTraits::template Codim< cd >::InterfaceType HElementType
Definition: alugrid/3d/entityseed.hh:343
ImplTraits::HBndSegType HBndSegType
Definition: alugrid/3d/entityseed.hh:346
Definition: alugrid/3d/entityseed.hh:18
ALU3dGridEntitySeed(const HBndSegType &ghostFace)
Constructor for EntitySeed that points to an ghost.
Definition: alugrid/3d/entityseed.hh:372
ALU3dGridEntitySeed(const HElementType &item)
Constructor for EntitySeed that points to an interior element.
Definition: alugrid/3d/entityseed.hh:364
GridImp::template Codim< cd >::Entity Entity
type of Entity
Definition: alugrid/3d/entityseed.hh:239