dune-alugrid  2.8-git
entityseed.hh
Go to the documentation of this file.
1 #ifndef ALU3DGRID_ENTITYKEY_HH
2 #define ALU3DGRID_ENTITYKEY_HH
3 
4 #include "alu3dinclude.hh"
5 
6 namespace Dune
7 {
8 
9 // Forward declarations
10 template<int cd, class GridImp>
11 class ALU3dGridEntitySeed ;
12 
13 template<int cd, int dim, class GridImp>
14 class ALU3dGridEntity;
15 
16 //**********************************************************************
17 //
18 // --ALU3dGridEntitySeed
19 // --EntitySeed
20 //**********************************************************************
21 template< int codim, class GridImp >
23 {
24 protected:
26  enum { dim = GridImp::dimension };
27  enum { dimworld = GridImp::dimensionworld };
28 
29  typedef typename GridImp::MPICommunicatorType Comm;
30 
32  typedef typename ImplTraits::template Codim<dim, codim>::ImplementationType ImplementationType;
33  typedef typename ImplTraits::template Codim<dim, codim>::InterfaceType HElementType;
34  typedef typename ImplTraits::template Codim<dim, codim>::EntitySeedType KeyType ;
35 
36  typedef typename ImplTraits::BNDFaceType BNDFaceType;
37  typedef typename ImplTraits::HBndSegType HBndSegType;
38 
39  template <int cd, class Key>
40  struct Bnd
41  {
42  static Key* toKey(const HBndSegType*)
43  {
44  return (Key*) 0;
45  }
47  {
48  return static_cast< HElementType* > ( key );
49  }
50  static bool isGhost(KeyType*) { return false; }
51  static BNDFaceType* ghost( KeyType* ) { return ( BNDFaceType* ) 0; }
52  };
53  template <class Key>
54  struct Bnd<0, Key>
55  {
56  static Key* toKey(const HBndSegType* ghostFace)
57  {
58  return static_cast< KeyType* > (const_cast< BNDFaceType* >( static_cast<const BNDFaceType*> (ghostFace)));
59  }
61  {
62  if( key )
63  {
64  if( key->isboundary() )
65  {
66  return ((static_cast< BNDFaceType* > ( key ))->getGhost().first);
67  }
68  else
69  {
70  // we cannot cast to HElement here, since only the implementation is derived
71  // from hasFace
72  return static_cast< HElementType * > (static_cast< ImplementationType* > (key));
73  }
74  }
75  else
76  return static_cast< HElementType * > (0) ;
77  }
78  static bool isGhost(KeyType* key) { alugrid_assert ( key ); return key->isboundary(); }
79  static BNDFaceType* ghost( KeyType* key ) { alugrid_assert ( key ); return (static_cast< BNDFaceType* > ( key )); }
80  };
81 public:
82  static const int defaultValue = -1 ;
83  static const int defaultTwist = 0 ;
84 
85  enum { codimension = codim };
86 
88  typedef typename GridImp::template Codim<codimension>::Entity Entity;
90  typedef typename GridImp::template Codim<codimension>::EntityImp EntityImp;
91 
94 
97 
100  {
101 #ifdef ALUGRIDDEBUG
102  // clear pointer
103  clear();
104 #endif
105  }
106 
109 
112 
115 
118 
120  //
121  // interface methods
122  //
126 
127  bool isValid () const { return bool( item_ ); }
128 
131  {
132  return equals( i );
133  }
134 
137  {
138  return ! equals( i );
139  }
140 
142  ThisType & operator = (const ThisType & org);
143 
145  //
146  // non-interface methods
147  //
150  bool equals (const ALU3dGridEntitySeedType& i) const;
151 
153  void clear()
154  {
155  item_ = 0;
156  }
157 
160 
163  {
164  alugrid_assert ( ! isGhost() );
165  return static_cast< HElementType * > (static_cast< ImplementationType* > (item_));
166  }
167 
169  bool isGhost() const { return Bnd<codim,KeyType>::isGhost( item_ ); }
171  {
172  alugrid_assert ( isGhost() );
174  }
175 
177  {
178  return static_cast< KeyType* > (const_cast< ImplementationType* > (static_cast<const ImplementationType* > (item)));
179  }
180 
181  void set(const HElementType& item)
182  {
183  item_ = toKey( &item );
184  }
185 
186  KeyType* toKey( const HBndSegType* ghostFace )
187  {
188  return Bnd<codim,KeyType>::toKey( ghostFace );
189  }
190 
191  void set(const HBndSegType& ghostFace)
192  {
193  item_ = toKey( &ghostFace );
194  }
195 
196  int level () const
197  {
198  alugrid_assert( isValid() );
199  return item()->level();
200  }
201 
202  int twist () const { return defaultTwist; }
203 
204 protected:
205  // pointer to item
206  mutable KeyType* item_;
207 };
208 
209 template<int cd, class GridImp>
211 public ALU3dGridEntitySeedBase<cd,GridImp>
212 {
214 
216  enum { dim = GridImp::dimension };
217  enum { dimworld = GridImp::dimensionworld };
218 
219  typedef typename GridImp::MPICommunicatorType Comm;
220 
222  typedef typename ImplTraits::template Codim<dim, cd>::ImplementationType ImplementationType;
223  typedef typename ImplTraits::template Codim<dim, cd>::InterfaceType HElementType;
224 
225  typedef typename ImplTraits::BNDFaceType BNDFaceType;
227 
228 public:
231 
233  typedef typename GridImp::template Codim<cd>::Entity Entity;
234 
237 
239  ALU3dGridEntitySeed(const ImplementationType & item)
240  {
241  // this constructor should only be called by codim=0 entity keys
242  alugrid_assert ( false );
243  abort();
244  }
245 
247  ALU3dGridEntitySeed(const HElementType & item,
248  const int level,
249  const int twist = defaultTwist
250  );
251 
255  {}
256 
259  : ALU3dGridEntitySeedBase<cd,GridImp> (entity.getItem()),
260  level_(entity.level()),
262  {}
263 
266 
268  ThisType & operator = (const ThisType & org);
269 
271  void clear();
272 
274  void set(const HElementType & item, const int level )
275  {
277  level_ = level ;
278  }
279 
281  int level () const { return level_ ; }
283  int twist () const { return twist_ ; }
284 
285  using BaseType :: set ;
286 
288  {
289  return equals( i );
290  }
291 
293  {
294  return ! equals( i );
295  }
296 
298  bool equals (const ALU3dGridEntitySeedType& key) const
299  {
300  // only compare the item pointer, this is the real key
301  return BaseType :: equals( key ) && (level() == key.level());
302  }
303 
304 protected:
305  // level of entity
306  int level_;
307  // twist of face, for codim 1 only
308  int twist_;
309 };
310 
314 template<class GridImp>
315 class ALU3dGridEntitySeed<0,GridImp> :
316 public ALU3dGridEntitySeedBase<0,GridImp>
317 {
318 protected:
320 
321  enum { cd = 0 };
323  enum { dim = GridImp::dimension };
324  enum { dimworld = GridImp::dimensionworld };
325 
326  typedef typename GridImp::MPICommunicatorType Comm;
327 
329  typedef typename ImplTraits::template Codim<dim, cd>::ImplementationType ImplementationType;
330  typedef typename ImplTraits::template Codim<dim, cd>::InterfaceType HElementType;
331 
332  typedef typename ImplTraits::BNDFaceType BNDFaceType;
333  typedef typename ImplTraits::HBndSegType HBndSegType;
334 
336 
337 public:
340 
342  typedef typename GridImp::template Codim<cd>::Entity Entity;
343 
346 
349 
352  : ALU3dGridEntitySeedBase<cd,GridImp> (item) {}
353 
356  : ALU3dGridEntitySeedBase<cd,GridImp> (item) {}
357 
359  ALU3dGridEntitySeed(const HBndSegType& ghostFace )
360  : ALU3dGridEntitySeedBase<cd,GridImp> ( ghostFace ) {}
361 
364  : ALU3dGridEntitySeedBase<cd,GridImp> (org)
365  {
366  }
367 };
368 
369 
371 template <int cd, class GridImp>
372 inline std :: ostream &operator<< ( std :: ostream &out,
374 {
375  out << key.item() << " " << key.level() << " " << key.twist() << " " << key.face();
376  return out;
377 }
378 
379 
380 //*******************************************************************
381 //
382 // Implementation
383 //
384 //*******************************************************************
385 template<int codim, class GridImp >
388  : item_( 0 )
389 {
390 }
391 
392 template<int codim, class GridImp >
395  : item_( toKey(&item) )
396 {
397 }
398 
399 template<int codim, class GridImp >
401 ALU3dGridEntitySeedBase(const HBndSegType& ghostFace )
402  : item_( toKey(&ghostFace) )
403 {
404 }
405 
406 template<int codim, class GridImp >
409  : item_(org.item_)
410 {
411 }
412 
413 template<int codim, class GridImp >
417 {
418  item_ = org.item_;
419  return *this;
420 }
421 
422 template<int codim, class GridImp >
425 {
426  // check equality of underlying items
427  return (item_ == i.item_);
428 }
429 
431 //
432 // specialisation for higher codims
433 //
435 
436 template<int codim, class GridImp >
438 ALU3dGridEntitySeed(const HElementType &item,
439  const int level,
440  const int twist )
441  : ALU3dGridEntitySeedBase<codim,GridImp> (item)
442  , level_(level)
443  , twist_ (twist)
444 {
445 }
446 
447 template<int codim, class GridImp >
450  : ALU3dGridEntitySeedBase<codim,GridImp>(org)
451  , level_(org.level_)
452  , twist_(org.twist_)
453 {
454 }
455 
456 template<int codim, class GridImp >
460 {
461  // docu and cleanup
462  BaseType :: operator = ( org );
463 
464  // clone other stuff
465  level_ = org.level_;
466  twist_ = org.twist_;
467  return *this;
468 }
469 
470 template<int codim, class GridImp >
471 inline void
473 {
474  BaseType :: clear();
475  level_ = defaultValue ;
476  twist_ = defaultTwist ;
477 }
478 
479 } // end namespace Dune
480 #endif
#define alugrid_assert(EX)
Definition: alugrid_assert.hh:20
Definition: alu3dinclude.hh:63
std ::ostream & operator<<(std ::ostream &out, const ALU3dGridEntitySeed< cd, GridImp > &key)
print alugrid entity key to std::stream
Definition: entityseed.hh:372
Definition: alu3dinclude.hh:242
Definition: entity.hh:48
ALU3dGridEntitySeed(const ALU3dGridEntitySeedType &org)
copy constructor
Definition: entityseed.hh:449
GridImp::template Codim< cd >::Entity Entity
type of Entity
Definition: entityseed.hh:233
ThisType & operator=(const ThisType &org)
assignment operator
Definition: entityseed.hh:459
int twist() const
return twist
Definition: entityseed.hh:283
bool equals(const ALU3dGridEntitySeedType &key) const
equality, calls BaseType equals
Definition: entityseed.hh:298
bool operator!=(const ALU3dGridEntitySeedType &i) const
Definition: entityseed.hh:292
void set(const HElementType &item, const int level)
set element and level
Definition: entityseed.hh:274
int twist_
Definition: entityseed.hh:308
void clear()
clear the key data structure
Definition: entityseed.hh:472
int level() const
return level
Definition: entityseed.hh:281
ALU3dGridEntitySeed()
Constructor for EntitySeed that points to an element.
Definition: entityseed.hh:253
ALU3dGridEntitySeed< cd, GridImp > ALU3dGridEntitySeedType
typedef of my type
Definition: entityseed.hh:236
int level_
Definition: entityseed.hh:306
ALU3dGridEntitySeed(const ALU3dGridEntityType &entity)
Constructor for EntitySeed that points to given entity.
Definition: entityseed.hh:258
ALU3dGridEntitySeed(const HElementType &item, const int level, const int twist=defaultTwist)
Constructor for EntitySeed that points to an element.
Definition: entityseed.hh:438
bool operator==(const ALU3dGridEntitySeedType &i) const
Definition: entityseed.hh:287
ALU3dGridEntitySeed(const ImplementationType &item)
Constructor for EntitySeed that points to an element.
Definition: entityseed.hh:239
Definition: entityseed.hh:23
static const int defaultValue
Definition: entityseed.hh:82
GridImp::template Codim< codimension >::Entity Entity
type of Entity
Definition: entityseed.hh:88
KeyType * toKey(const HBndSegType *ghostFace)
Definition: entityseed.hh:186
ALU3dGridEntitySeed< codimension, GridImp > EntitySeedImp
make type of entity pointer implementation available in derived classes
Definition: entityseed.hh:96
ThisType ALU3dGridEntitySeedType
typedef of my type
Definition: entityseed.hh:93
@ codimension
Definition: entityseed.hh:85
ALU3dGridEntitySeedBase(const HElementType *item, const HBndSegType *ghostFace)
Constructor for EntitySeed that points to an element.
void set(const HElementType &item)
Definition: entityseed.hh:181
@ dim
Definition: entityseed.hh:26
bool isGhost() const
methods for ghosts
Definition: entityseed.hh:169
KeyType * item_
Definition: entityseed.hh:206
ALU3dGridEntitySeedBase(const ALU3dGridEntitySeedType &org)
copy constructor
Definition: entityseed.hh:408
ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits
Definition: entityseed.hh:31
GridImp::template Codim< codimension >::EntityImp EntityImp
underlying EntityImplementation
Definition: entityseed.hh:90
ThisType & operator=(const ThisType &org)
assignment operator
Definition: entityseed.hh:416
KeyType * toKey(const HElementType *item)
Definition: entityseed.hh:176
int twist() const
Definition: entityseed.hh:202
ALU3dGridEntitySeedBase< codim, GridImp > ThisType
Definition: entityseed.hh:25
static const int defaultTwist
Definition: entityseed.hh:83
void clear()
invalidate seed
Definition: entityseed.hh:153
GridImp::MPICommunicatorType Comm
Definition: entityseed.hh:29
ImplTraits::template Codim< dim, codim >::ImplementationType ImplementationType
Definition: entityseed.hh:32
void set(const HBndSegType &ghostFace)
Definition: entityseed.hh:191
HElementType * interior() const
return iterior item
Definition: entityseed.hh:162
ALU3dGridEntitySeedBase(const HBndSegType &ghostFace)
Constructor for EntitySeed that points to an ghost.
Definition: entityseed.hh:401
ImplTraits::template Codim< dim, codim >::InterfaceType HElementType
Definition: entityseed.hh:33
ALU3dGridEntitySeedBase(const HElementType &item)
Constructor for EntitySeed that points to an element.
Definition: entityseed.hh:394
ImplTraits::BNDFaceType BNDFaceType
Definition: entityseed.hh:36
ImplTraits::HBndSegType HBndSegType
Definition: entityseed.hh:37
bool isValid() const
Definition: entityseed.hh:127
int level() const
Definition: entityseed.hh:196
bool operator==(const ALU3dGridEntitySeedType &i) const
equality operator
Definition: entityseed.hh:130
~ALU3dGridEntitySeedBase()
Destructor.
Definition: entityseed.hh:99
HElementType * item() const
get item from key
Definition: entityseed.hh:159
ALU3dGridEntitySeedBase()
Constructor for EntitySeed that points to an element.
Definition: entityseed.hh:387
BNDFaceType * ghost() const
Definition: entityseed.hh:170
ImplTraits::template Codim< dim, codim >::EntitySeedType KeyType
Definition: entityseed.hh:34
bool operator!=(const ALU3dGridEntitySeedType &i) const
inequality operator
Definition: entityseed.hh:136
@ dimworld
Definition: entityseed.hh:27
bool equals(const ALU3dGridEntitySeedType &i) const
equality
Definition: entityseed.hh:424
Definition: entityseed.hh:41
static bool isGhost(KeyType *)
Definition: entityseed.hh:50
static BNDFaceType * ghost(KeyType *)
Definition: entityseed.hh:51
static Key * toKey(const HBndSegType *)
Definition: entityseed.hh:42
static HElementType * getItem(KeyType *key)
Definition: entityseed.hh:46
static Key * toKey(const HBndSegType *ghostFace)
Definition: entityseed.hh:56
static bool isGhost(KeyType *key)
Definition: entityseed.hh:78
static HElementType * getItem(KeyType *key)
Definition: entityseed.hh:60
static BNDFaceType * ghost(KeyType *key)
Definition: entityseed.hh:79
ImplTraits::template Codim< dim, cd >::ImplementationType ImplementationType
Definition: entityseed.hh:329
ALU3dGridEntitySeed(const HElementType &item, int, int)
Constructor for EntitySeed that points to an interior element.
Definition: entityseed.hh:355
ImplTraits::template Codim< dim, cd >::InterfaceType HElementType
Definition: entityseed.hh:330
ALU3dGridEntitySeed(const HElementType &item)
Constructor for EntitySeed that points to an interior element.
Definition: entityseed.hh:351
ALU3dGridEntitySeed(const HBndSegType &ghostFace)
Constructor for EntitySeed that points to an ghost.
Definition: entityseed.hh:359
ALU3dGridEntitySeed(const ALU3dGridEntitySeedType &org)
copy constructor
Definition: entityseed.hh:363
ImplTraits::BNDFaceType BNDFaceType
Definition: entityseed.hh:332
ALU3dGridEntity< 0, dim, GridImp > ALU3dGridEntityType
Definition: entityseed.hh:335
ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits
Definition: entityseed.hh:328
ALU3dGridEntitySeed< cd, GridImp > ThisType
Definition: entityseed.hh:322
ALU3dGridEntitySeed()
Constructor for EntitySeed that points to an element.
Definition: entityseed.hh:348
ImplTraits::HBndSegType HBndSegType
Definition: entityseed.hh:333
ALU3dGridEntitySeedBase< 0, GridImp > BaseType
Definition: entityseed.hh:319
GridImp::MPICommunicatorType Comm
Definition: entityseed.hh:326
GridImp::template Codim< cd >::Entity Entity
type of Entity
Definition: entityseed.hh:342
ThisType ALU3dGridEntitySeedType
typedef of my type
Definition: entityseed.hh:345