Dune Core Modules (2.9.0)

entityseed.hh
1#ifndef ALU3DGRID_ENTITYKEY_HH
2#define ALU3DGRID_ENTITYKEY_HH
3
4#include "alu3dinclude.hh"
5
6namespace Dune
7{
8
9// Forward declarations
10template<int cd, class GridImp>
11class ALU3dGridEntitySeed ;
12
13template<int cd, int dim, class GridImp>
14class ALU3dGridEntity;
15
16//**********************************************************************
17//
18// --ALU3dGridEntitySeed
19// --EntitySeed
20//**********************************************************************
21template< int codim, class GridImp >
22class ALU3dGridEntitySeedBase
23{
24protected:
25 typedef ALU3dGridEntitySeedBase< codim, GridImp > ThisType;
26 enum { dim = GridImp::dimension };
27 enum { dimworld = GridImp::dimensionworld };
28
29 typedef typename GridImp::MPICommunicatorType Comm;
30
31 typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits;
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 nullptr;
45 }
46 static HElementType* getItem(KeyType* key)
47 {
48 return static_cast< HElementType* > ( key );
49 }
50 static bool isGhost(KeyType*) { return false; }
51 static BNDFaceType* ghost( KeyType* ) { return nullptr; }
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 }
60 static HElementType* getItem(KeyType* key)
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 nullptr;
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 };
81public:
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
93 typedef ThisType ALU3dGridEntitySeedType;
94
96 typedef ALU3dGridEntitySeed<codimension,GridImp> EntitySeedImp;
97
99 ~ALU3dGridEntitySeedBase()
100 {
101#ifdef ALUGRIDDEBUG
102 // clear pointer
103 clear();
104#endif
105 }
106
108 ALU3dGridEntitySeedBase();
109
111 ALU3dGridEntitySeedBase(const HElementType& item);
112
114 ALU3dGridEntitySeedBase(const HElementType* item, const HBndSegType* ghostFace );
115
117 ALU3dGridEntitySeedBase(const HBndSegType& ghostFace );
118
120 //
121 // interface methods
122 //
125 ALU3dGridEntitySeedBase(const ALU3dGridEntitySeedType & org);
126
127 bool isValid () const { return bool( item_ ); }
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 //
146 // non-interface methods
147 //
150 bool equals (const ALU3dGridEntitySeedType& i) const;
151
153 void clear()
154 {
155 item_ = nullptr;
156 }
157
159 HElementType* item() const { return Bnd<codim,KeyType>::getItem( item_ ); }
160
162 HElementType* interior() const
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_ ); }
170 BNDFaceType* ghost() const
171 {
172 alugrid_assert ( isGhost() );
173 return Bnd<codim,KeyType>::ghost( item_ );
174 }
175
176 KeyType* toKey(const HElementType* item)
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
204protected:
205 // pointer to item
206 mutable KeyType* item_;
207};
208
209template<int cd, class GridImp>
210class ALU3dGridEntitySeed :
211public ALU3dGridEntitySeedBase<cd,GridImp>
212{
213 typedef ALU3dGridEntitySeedBase<cd,GridImp> BaseType;
214
215 typedef ALU3dGridEntitySeed <cd,GridImp> ThisType;
216 enum { dim = GridImp::dimension };
217 enum { dimworld = GridImp::dimensionworld };
218
219 typedef typename GridImp::MPICommunicatorType Comm;
220
221 typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits;
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;
226 typedef ALU3dGridEntity<cd,dim,GridImp> ALU3dGridEntityType;
227
228public:
229 using BaseType :: defaultValue ;
230 using BaseType :: defaultTwist ;
231
233 typedef typename GridImp::template Codim<cd>::Entity Entity;
234
236 typedef ALU3dGridEntitySeed<cd,GridImp> ALU3dGridEntitySeedType;
237
240 ALU3dGridEntitySeed(const ImplementationType & item) = delete;
241
243 ALU3dGridEntitySeed(const HElementType & item,
244 const int level,
245 const int twist = defaultTwist
246 );
247
249 ALU3dGridEntitySeed()
250 : BaseType(), level_(defaultValue), twist_(defaultTwist)
251 {}
252
254 ALU3dGridEntitySeed(const ALU3dGridEntityType& entity)
255 : ALU3dGridEntitySeedBase<cd,GridImp> (entity.getItem()),
256 level_(entity.level()),
257 twist_(defaultTwist)
258 {}
259
261 ALU3dGridEntitySeed(const ALU3dGridEntitySeedType & org);
262
264 ThisType & operator = (const ThisType & org);
265
267 void clear();
268
270 void set(const HElementType & item, const int level )
271 {
272 BaseType :: set( item );
273 level_ = level ;
274 }
275
277 int level () const { return level_ ; }
279 int twist () const { return twist_ ; }
280
281 using BaseType :: set ;
282
283 bool operator == (const ALU3dGridEntitySeedType& i) const
284 {
285 return equals( i );
286 }
287
288 bool operator != (const ALU3dGridEntitySeedType& i) const
289 {
290 return ! equals( i );
291 }
292
294 bool equals (const ALU3dGridEntitySeedType& key) const
295 {
296 // only compare the item pointer, this is the real key
297 return BaseType :: equals( key ) && (level() == key.level());
298 }
299
300protected:
301 // level of entity
302 int level_;
303 // twist of face, for codim 1 only
304 int twist_;
305};
306
310template<class GridImp>
311class ALU3dGridEntitySeed<0,GridImp> :
312public ALU3dGridEntitySeedBase<0,GridImp>
313{
314protected:
315 typedef ALU3dGridEntitySeedBase<0,GridImp> BaseType;
316
317 enum { cd = 0 };
318 typedef ALU3dGridEntitySeed <cd,GridImp> ThisType;
319 enum { dim = GridImp::dimension };
320 enum { dimworld = GridImp::dimensionworld };
321
322 typedef typename GridImp::MPICommunicatorType Comm;
323
324 typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits;
325 typedef typename ImplTraits::template Codim<dim, cd>::ImplementationType ImplementationType;
326 typedef typename ImplTraits::template Codim<dim, cd>::InterfaceType HElementType;
327
328 typedef typename ImplTraits::BNDFaceType BNDFaceType;
329 typedef typename ImplTraits::HBndSegType HBndSegType;
330
332
333public:
334 using BaseType :: defaultValue ;
335 using BaseType :: defaultTwist ;
336
338 typedef typename GridImp::template Codim<cd>::Entity Entity;
339
341 typedef ThisType ALU3dGridEntitySeedType;
342
344 ALU3dGridEntitySeed() : BaseType() {}
345
347 ALU3dGridEntitySeed(const HElementType& item)
348 : ALU3dGridEntitySeedBase<cd,GridImp> (item) {}
349
351 ALU3dGridEntitySeed(const HElementType& item, int , int )
352 : ALU3dGridEntitySeedBase<cd,GridImp> (item) {}
353
355 ALU3dGridEntitySeed(const HBndSegType& ghostFace )
356 : ALU3dGridEntitySeedBase<cd,GridImp> ( ghostFace ) {}
357
359 ALU3dGridEntitySeed(const ALU3dGridEntitySeedType & org)
360 : ALU3dGridEntitySeedBase<cd,GridImp> (org)
361 {
362 }
363
365 ThisType & operator = (const ThisType & org)
366 {
367 BaseType :: operator = (org);
368 return *this;
369 }
370};
371
372
374template <int cd, class GridImp>
375inline std :: ostream &operator<< ( std :: ostream &out,
376 const ALU3dGridEntitySeed<cd,GridImp>& key)
377{
378 out << key.item() << " " << key.level() << " " << key.twist() << " " << key.face();
379 return out;
380}
381
382
383//*******************************************************************
384//
385// Implementation
386//
387//*******************************************************************
388template<int codim, class GridImp >
389inline ALU3dGridEntitySeedBase<codim,GridImp> ::
390ALU3dGridEntitySeedBase()
391 : item_( 0 )
392{
393}
394
395template<int codim, class GridImp >
396inline ALU3dGridEntitySeedBase<codim,GridImp> ::
397ALU3dGridEntitySeedBase(const HElementType &item)
398 : item_( toKey(&item) )
399{
400}
401
402template<int codim, class GridImp >
403inline ALU3dGridEntitySeedBase<codim,GridImp> ::
404ALU3dGridEntitySeedBase(const HBndSegType& ghostFace )
405 : item_( toKey(&ghostFace) )
406{
407}
408
409template<int codim, class GridImp >
410inline ALU3dGridEntitySeedBase<codim,GridImp> ::
411ALU3dGridEntitySeedBase(const ALU3dGridEntitySeedType & org)
412 : item_(org.item_)
413{
414}
415
416template<int codim, class GridImp >
417inline ALU3dGridEntitySeedBase<codim,GridImp> &
418ALU3dGridEntitySeedBase<codim,GridImp> ::
419operator = (const ALU3dGridEntitySeedType & org)
420{
421 item_ = org.item_;
422 return *this;
423}
424
425template<int codim, class GridImp >
427equals (const ALU3dGridEntitySeedBase<codim,GridImp>& i) const
428{
429 // check equality of underlying items
430 return (item_ == i.item_);
431}
432
434//
435// specialisation for higher codims
436//
438
439template<int codim, class GridImp >
440inline ALU3dGridEntitySeed<codim,GridImp> ::
441ALU3dGridEntitySeed(const HElementType &item,
442 const int level,
443 const int twist )
444 : ALU3dGridEntitySeedBase<codim,GridImp> (item)
445 , level_(level)
446 , twist_ (twist)
447{
448}
449
450template<int codim, class GridImp >
451inline ALU3dGridEntitySeed<codim,GridImp> ::
452ALU3dGridEntitySeed(const ALU3dGridEntitySeedType & org)
453 : ALU3dGridEntitySeedBase<codim,GridImp>(org)
454 , level_(org.level_)
455 , twist_(org.twist_)
456{
457}
458
459template<int codim, class GridImp >
460inline ALU3dGridEntitySeed<codim,GridImp> &
461ALU3dGridEntitySeed<codim,GridImp>::
462operator = (const ALU3dGridEntitySeedType & org)
463{
464 // docu and cleanup
465 BaseType :: operator = ( org );
466
467 // clone other stuff
468 level_ = org.level_;
469 twist_ = org.twist_;
470 return *this;
471}
472
473template<int codim, class GridImp >
474inline void
475ALU3dGridEntitySeed<codim,GridImp>::clear ()
476{
477 BaseType :: clear();
478 level_ = defaultValue ;
479 twist_ = defaultTwist ;
480}
481
482} // end namespace Dune
483#endif
ALU3dGridEntitySeed(const HElementType &item, int, int)
Constructor for EntitySeed that points to an interior element.
Definition: entityseed.hh:351
ALU3dGridEntitySeed(const HElementType &item)
Constructor for EntitySeed that points to an interior element.
Definition: entityseed.hh:347
ALU3dGridEntitySeed(const HBndSegType &ghostFace)
Constructor for EntitySeed that points to an ghost.
Definition: entityseed.hh:355
ALU3dGridEntitySeed(const ALU3dGridEntitySeedType &org)
copy constructor
Definition: entityseed.hh:359
ALU3dGridEntitySeed()
Constructor for EntitySeed that points to an element.
Definition: entityseed.hh:344
GridImp::template Codim< cd >::Entity Entity
type of Entity
Definition: entityseed.hh:338
ThisType ALU3dGridEntitySeedType
typedef of my type
Definition: entityseed.hh:341
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:402
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:237
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:259
constexpr Ghost ghost
PartitionSet for the ghost partition.
Definition: partitionset.hh:284
constexpr Interior interior
PartitionSet for the interior partition.
Definition: partitionset.hh:272
Dune namespace.
Definition: alignedallocator.hh:13
Static tag representing a codimension.
Definition: dimension.hh:24
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)