Dune Core Modules (2.3.1)

entityseed.hh
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
6namespace Dune
7{
8
9 template<int cd, class GridImp>
10 class ALU3dGridEntitySeed ;
11
12 //**********************************************************************
13 //
14 // --ALU3dGridEntitySeed
15 // --EntitySeed
16 //**********************************************************************
17 template< int codim, class GridImp >
18 class ALU3dGridEntitySeedBase
19 {
20 protected:
21 typedef ALU3dGridEntitySeedBase< codim, GridImp > ThisType;
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 }
47 static HElementType* getItem(KeyType* key)
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 }
61 static HElementType* getItem(KeyType* key)
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;
91 typedef MakeableInterfaceObject<Entity> EntityObject;
92 typedef typename EntityObject :: ImplementationType EntityImp;
93
95 typedef ThisType ALU3dGridEntitySeedType;
96
98 typedef ALU3dGridEntitySeed<codimension,GridImp> EntitySeedImp;
99
101 ~ALU3dGridEntitySeedBase()
102 {
103#ifndef NDEBUG
104 // clear pointer
105 clear();
106#endif
107 }
108
110 ALU3dGridEntitySeedBase();
111
113 ALU3dGridEntitySeedBase(const HElementType& item);
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
165 HElementType* item() const { return Bnd<codim,KeyType>::getItem( item_ ); }
166
168 HElementType* interior() const
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_ ); }
176 BNDFaceType* ghost() const
177 {
178 assert( isGhost() );
179 return Bnd<codim,KeyType>::ghost( item_ );
180 }
181
182 KeyType* toKey(const HElementType* item)
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
242 typedef ALU3dGridEntitySeed<cd,GridImp> ALU3dGridEntitySeedType;
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
260 ALU3dGridEntitySeed()
261 : BaseType(), level_(defaultValue), twist_(defaultTwist), face_(defaultValue) {}
262
264 ALU3dGridEntitySeed(const ALU3dGridEntityType& entity)
265 : ALU3dGridEntitySeedBase<cd,GridImp> (entity.getItem()),
266 level_(entity.level()), twist_(defaultTwist), face_(defaultValue)
267 {}
268
270 ALU3dGridEntitySeed(const ALU3dGridEntitySeedType & org);
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
294 bool operator == (const ALU3dGridEntitySeedType& i) const
295 {
296 return equals( i );
297 }
298
299 bool operator != (const ALU3dGridEntitySeedType& i) const
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:
328 typedef ALU3dGridEntitySeedBase<0,GridImp> BaseType;
329
330 enum { cd = 0 };
331 typedef ALU3dGridEntitySeed <cd,GridImp> ThisType;
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
364 ALU3dGridEntitySeed(const HElementType& item)
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
376 ALU3dGridEntitySeed(const ALU3dGridEntitySeedType & org)
377 : ALU3dGridEntitySeedBase<cd,GridImp> (org)
378 {}
379 };
380
381
383 template <int cd, class GridImp>
384 inline std :: ostream &operator<< ( std :: ostream &out,
385 const ALU3dGridEntitySeed<cd,GridImp>& key)
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 >
398 inline ALU3dGridEntitySeedBase<codim,GridImp> ::
399 ALU3dGridEntitySeedBase()
400 : item_( 0 )
401 {}
402
403 template<int codim, class GridImp >
404 inline ALU3dGridEntitySeedBase<codim,GridImp> ::
405 ALU3dGridEntitySeedBase(const HElementType &item)
406 : item_( toKey(&item) )
407 {}
408
409 template<int codim, class GridImp >
410 inline ALU3dGridEntitySeedBase<codim,GridImp> ::
411 ALU3dGridEntitySeedBase(const HBndSegType& ghostFace )
412 : item_( toKey(&ghostFace) )
413 {}
414
415 template<int codim, class GridImp >
416 inline ALU3dGridEntitySeedBase<codim,GridImp> ::
417 ALU3dGridEntitySeedBase(const ALU3dGridEntitySeedType & org)
418 : item_(org.item_)
419 {}
420
421 template<int codim, class GridImp >
422 inline ALU3dGridEntitySeedBase<codim,GridImp> &
423 ALU3dGridEntitySeedBase<codim,GridImp> ::
424 operator = (const ALU3dGridEntitySeedType & org)
425 {
426 item_ = org.item_;
427 return *this;
428 }
429
430 template<int codim, class GridImp >
431 inline bool ALU3dGridEntitySeedBase<codim,GridImp>::
432 equals (const ALU3dGridEntitySeedBase<codim,GridImp>& i) const
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 >
445 inline ALU3dGridEntitySeed<codim,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 >
457 inline ALU3dGridEntitySeed<codim,GridImp> ::
458 ALU3dGridEntitySeed(const ALU3dGridEntitySeedType & org)
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 >
466 inline ALU3dGridEntitySeed<codim,GridImp> &
467 ALU3dGridEntitySeed<codim,GridImp>::
468 operator = (const ALU3dGridEntitySeedType & org)
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
482 ALU3dGridEntitySeed<codim,GridImp>::clear ()
483 {
484 BaseType :: clear();
485 level_ = defaultValue ;
486 twist_ = defaultTwist ;
487 face_ = defaultValue ;
488 }
489
490} // end namespace Dune
491#endif
ALU3dGridEntitySeed(const HElementType &item, int, int, int)
Constructor for EntitySeed that points to an interior element.
Definition: entityseed.hh:368
ALU3dGridEntitySeed(const HElementType &item)
Constructor for EntitySeed that points to an interior element.
Definition: entityseed.hh:364
ALU3dGridEntitySeed(const HBndSegType &ghostFace)
Constructor for EntitySeed that points to an ghost.
Definition: entityseed.hh:372
ALU3dGridEntitySeed(const ALU3dGridEntitySeedType &org)
copy constructor
Definition: entityseed.hh:376
Definition: entity.hh:47
[ provides Dune::Grid ]
Definition: grid.hh:406
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:159
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:231
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:253
Dune namespace.
Definition: alignment.hh:14
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:80
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)