Dune Core Modules (2.4.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 ALU2DGRID_ENTITYKEY_HH
4#define ALU2DGRID_ENTITYKEY_HH
5
6namespace Dune
7{
8
9 template<int cd, class GridImp>
10 class ALU2dGridEntitySeed ;
11
12 //**********************************************************************
13 //
14 // --ALU2dGridEntitySeed
15 // --EntitySeed
16 //**********************************************************************
17 template< int codim, class GridImp >
18 class ALU2dGridEntitySeedBase
19 {
20 protected:
21 typedef ALU2dGridEntitySeedBase< codim, GridImp > ThisType;
22 enum { dim = GridImp::dimension };
23 enum { dimworld = GridImp::dimensionworld };
24
25
26 friend class ALU2dGridEntity<codim,dim,GridImp>;
27 friend class ALU2dGridEntity< 0,dim,GridImp>;
28 friend class ALU2dGrid <GridImp :: dimension, GridImp::dimensionworld, GridImp::elementType >;
29
30 typedef ALU2dImplTraits< GridImp::dimensionworld, GridImp::elementType > ImplTraits;
31 typedef typename ImplTraits::template Codim<codim>::InterfaceType ImplementationType;
32 typedef ImplementationType HElementType;
33 typedef ImplementationType KeyType;
34
35 public:
36 static const int defaultValue = -1 ;
37
38 enum { codimension = codim };
39
41 typedef typename GridImp::template Codim<codimension>::Entity Entity;
43 typedef MakeableInterfaceObject<Entity> EntityObject;
44 typedef typename EntityObject :: ImplementationType EntityImp;
45
47 typedef ThisType ALU2dGridEntitySeedType;
48
50 typedef ALU2dGridEntitySeed<codimension,GridImp> EntitySeedImp;
51
53 ~ALU2dGridEntitySeedBase()
54 {
55#ifndef NDEBUG
56 // clear pointer
57 clear();
58#endif
59 }
60
62 ALU2dGridEntitySeedBase();
63
65 ALU2dGridEntitySeedBase(const HElementType& item);
66
68 //
69 // interface methods
70 //
73 ALU2dGridEntitySeedBase(const ALU2dGridEntitySeedType & org);
74
76 bool operator == (const ALU2dGridEntitySeedType& i) const
77 {
78 return equals( i );
79 }
80
82 bool operator != (const ALU2dGridEntitySeedType& i) const
83 {
84 return ! equals( i );
85 }
86
88 ThisType & operator = (const ThisType & org);
89
91 bool isValid () const
92 {
93 return item_ != 0;
94 }
95
97 //
98 // non-interface methods
99 //
102 bool equals (const ALU2dGridEntitySeedType& i) const;
103
105 void clear()
106 {
107 item_ = 0;
108 }
109
111 HElementType* item() const { return item_; }
112
113 KeyType* toKey(const HElementType* item)
114 {
115 return static_cast< KeyType* > (const_cast< ImplementationType* > (static_cast<const ImplementationType* > (item)));
116 }
117
118 void set(const HElementType& item, const int level = -1 , const int face = -1 )
119 {
120 item_ = toKey( &item );
121 }
122
123 int level () const { return ( item_ ) ? item_->level() : defaultValue; }
124 int face () const { return defaultValue; }
125
126 protected:
127 // pointer to item
128 mutable KeyType* item_;
129 };
130
131 template<int cd, class GridImp>
132 class ALU2dGridEntitySeed :
133 public ALU2dGridEntitySeedBase<cd,GridImp>
134 {
135 typedef ALU2dGridEntitySeedBase<cd,GridImp> BaseType;
136
137 typedef ALU2dGridEntitySeed <cd,GridImp> ThisType;
138 enum { dim = GridImp::dimension };
139 enum { dimworld = GridImp::dimensionworld };
140
141 friend class ALU2dGridEntity<cd,dim,GridImp>;
142 friend class ALU2dGridEntity< 0,dim,GridImp>;
143 friend class ALU2dGrid <GridImp :: dimension, GridImp::dimensionworld, GridImp::elementType >;
144
145 typedef ALU2dImplTraits< GridImp::dimensionworld, GridImp::elementType > ImplTraits;
146 typedef typename ImplTraits::template Codim<cd>::InterfaceType ImplementationType;
147 typedef ImplementationType HElementType;
148
149 typedef ALU2dGridEntity<cd,dim,GridImp> ALU2dGridEntityType;
150
151 public:
152 using BaseType :: defaultValue ;
153
155 typedef typename GridImp::template Codim<cd>::Entity Entity;
156
158 typedef ALU2dGridEntitySeed<cd,GridImp> ALU2dGridEntitySeedType;
159
161 ALU2dGridEntitySeed(const ImplementationType & item)
162 {
163 // this constructor should only be called by codim=0 entity keys
164 assert( false );
165 abort();
166 }
167
169 ALU2dGridEntitySeed(const HElementType & item,
170 const int level,
171 const int duneFace = defaultValue
172 );
173
175 ALU2dGridEntitySeed()
176 : BaseType(), level_(defaultValue), face_(defaultValue) {}
177
179 ALU2dGridEntitySeed(const ALU2dGridEntityType& entity)
180 : ALU2dGridEntitySeedBase<cd,GridImp> (entity.getItem()),
181 level_(entity.level()), face_(defaultValue)
182 {}
183
185 ALU2dGridEntitySeed(const ALU2dGridEntitySeedType & org);
186
188 ThisType & operator = (const ThisType & org);
189
191 void clear();
192
194 void set(const HElementType & item, const int level, const int duneFace )
195 {
196 BaseType :: set( item );
197 level_ = level ;
198 face_ = duneFace ;
199 }
200
202 int level () const { return level_ ; }
204 int face () const { return face_ ; }
205
206 using BaseType :: set ;
207
208 bool operator == (const ALU2dGridEntitySeedType& i) const
209 {
210 return equals( i );
211 }
212
213 bool operator != (const ALU2dGridEntitySeedType& i) const
214 {
215 return ! equals( i );
216 }
217
219 bool equals (const ALU2dGridEntitySeedType& key) const
220 {
221 // only compare the item pointer, this is the real key
222 return BaseType :: equals( key ) && (level() == key.level());
223 }
224
225 protected:
226 // level of entity
227 int level_;
228 // face number, for codim 1 only
229 int face_;
230 };
231
235 template<class GridImp>
236 class ALU2dGridEntitySeed<0,GridImp> :
237 public ALU2dGridEntitySeedBase<0,GridImp>
238 {
239 protected:
240 typedef ALU2dGridEntitySeedBase<0,GridImp> BaseType;
241
242 enum { cd = 0 };
243 typedef ALU2dGridEntitySeed <cd,GridImp> ThisType;
244 enum { dim = GridImp::dimension };
245 enum { dimworld = GridImp::dimensionworld };
246
247 friend class ALU2dGridEntity<cd,dim,GridImp>;
248 friend class ALU2dGridEntity< 0,dim,GridImp>;
249 friend class ALU2dGrid <GridImp :: dimension, GridImp::dimensionworld, GridImp::elementType >;
250
251 typedef ALU2dImplTraits< GridImp::dimensionworld, GridImp::elementType > ImplTraits;
252 typedef typename ImplTraits::template Codim<cd>::InterfaceType ImplementationType;
253 typedef ImplementationType HElementType;
254
255 typedef ALU2dGridEntity< 0,dim,GridImp> ALU2dGridEntityType ;
256
257 public:
258 using BaseType :: defaultValue ;
259
261 typedef typename GridImp::template Codim<cd>::Entity Entity;
262
264 typedef ThisType ALU2dGridEntitySeedType;
265
267 ALU2dGridEntitySeed() : BaseType() {}
268
270 ALU2dGridEntitySeed(const HElementType& item)
271 : ALU2dGridEntitySeedBase<cd,GridImp> (item) {}
272
274 ALU2dGridEntitySeed(const HElementType& item, int , int )
275 : ALU2dGridEntitySeedBase<cd,GridImp> (item) {}
276
278 ALU2dGridEntitySeed(const ALU2dGridEntitySeedType & org)
279 : ALU2dGridEntitySeedBase<cd,GridImp> (org)
280 {}
281 };
282
283
285 template <int cd, class GridImp>
286 inline std :: ostream &operator<< ( std :: ostream &out,
287 const ALU2dGridEntitySeed<cd,GridImp>& key)
288 {
289 out << key.item() << " " << key.level() << " " << key.face();
290 return out;
291 }
292
293
294 //*******************************************************************
295 //
296 // Implementation
297 //
298 //*******************************************************************
299 template<int codim, class GridImp >
300 inline ALU2dGridEntitySeedBase<codim,GridImp> ::
301 ALU2dGridEntitySeedBase()
302 : item_( 0 )
303 {}
304
305 template<int codim, class GridImp >
306 inline ALU2dGridEntitySeedBase<codim,GridImp> ::
307 ALU2dGridEntitySeedBase(const HElementType &item)
308 : item_( toKey(&item) )
309 {}
310
311 template<int codim, class GridImp >
312 inline ALU2dGridEntitySeedBase<codim,GridImp> ::
313 ALU2dGridEntitySeedBase(const ALU2dGridEntitySeedType & org)
314 : item_(org.item_)
315 {}
316
317 template<int codim, class GridImp >
318 inline ALU2dGridEntitySeedBase<codim,GridImp> &
319 ALU2dGridEntitySeedBase<codim,GridImp> ::
320 operator = (const ALU2dGridEntitySeedType & org)
321 {
322 item_ = org.item_;
323 return *this;
324 }
325
326 template<int codim, class GridImp >
327 inline bool ALU2dGridEntitySeedBase<codim,GridImp>::
328 equals (const ALU2dGridEntitySeedBase<codim,GridImp>& i) const
329 {
330 // check equality of underlying items
331 return (item_ == i.item_);
332 }
333
335 //
336 // specialisation for higher codims
337 //
339
340 template<int codim, class GridImp >
341 inline ALU2dGridEntitySeed<codim,GridImp> ::
342 ALU2dGridEntitySeed(const HElementType &item,
343 const int level,
344 const int duneFace )
345 : ALU2dGridEntitySeedBase<codim,GridImp> (item)
346 , level_(level)
347 , face_(duneFace)
348 {
349 assert( (codim == 1) ? (face_ >= 0) : 1 );
350 }
351
352 template<int codim, class GridImp >
353 inline ALU2dGridEntitySeed<codim,GridImp> ::
354 ALU2dGridEntitySeed(const ALU2dGridEntitySeedType & org)
355 : ALU2dGridEntitySeedBase<codim,GridImp>(org)
356 , level_(org.level_)
357 , face_(org.face_)
358 {}
359
360 template<int codim, class GridImp >
361 inline ALU2dGridEntitySeed<codim,GridImp> &
362 ALU2dGridEntitySeed<codim,GridImp>::
363 operator = (const ALU2dGridEntitySeedType & org)
364 {
365 // docu and cleanup
366 BaseType :: operator = ( org );
367
368 // clone other stuff
369 level_ = org.level_;
370 face_ = org.face_;
371 return *this;
372 }
373
374 template<int codim, class GridImp >
375 inline void
376 ALU2dGridEntitySeed<codim,GridImp>::clear ()
377 {
378 BaseType :: clear();
379 level_ = defaultValue ;
380 face_ = defaultValue ;
381 }
382
383} // end namespace Dune
384#endif
ALU2dGridEntitySeed(const HElementType &item)
Constructor for EntitySeed that points to an interior element.
Definition: entityseed.hh:270
ALU2dGridEntitySeed(const ALU2dGridEntitySeedType &org)
copy constructor
Definition: entityseed.hh:278
ALU2dGridEntitySeed(const HElementType &item, int, int)
Constructor for EntitySeed that points to an interior element.
Definition: entityseed.hh:274
Definition: entity.hh:55
[ provides Dune::Grid ]
Definition: grid.hh:212
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:26
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:84
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:230
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:252
Dune namespace.
Definition: alignment.hh:10
Static tag representing a codimension.
Definition: dimension.hh:22
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)