1 #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_SUBTOPOLOGIES_HH
2 #define DUNE_GEOMETRY_GENERICGEOMETRY_SUBTOPOLOGIES_HH
7 #include <dune/common/forloop.hh>
8 #include <dune/common/static_assert.hh>
9 #include <dune/common/typetraits.hh>
17 namespace GenericGeometry
20 template<
class Topology,
unsigned int codim >
23 template<
class Topology,
unsigned int codim,
unsigned int i >
26 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
27 class SubTopologySize;
29 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
30 class GenericSubTopologyNumbering;
32 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
33 class SubTopologyNumbering;
40 template<
class Topology,
unsigned int dim,
unsigned int codim >
43 template<
unsigned int dim,
unsigned int codim >
44 class SizeImpl<
Point, dim, codim >
47 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
48 dune_static_assert( (codim <= dim),
"Invalid codimension" );
54 template<
class BaseTopology,
unsigned int dim,
unsigned int codim >
55 class SizeImpl<
Prism< BaseTopology >, dim, codim >
58 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
59 dune_static_assert( (codim <= dim),
"Invalid codimension" );
61 enum { m =
Size< BaseTopology, codim-1 > :: value };
65 enum { value = n + 2*m };
68 template<
class BaseTopology,
unsigned int dim >
69 class SizeImpl<
Prism< BaseTopology >, dim, 0 >
72 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
78 template<
class BaseTopology,
unsigned int dim >
79 class SizeImpl<
Prism< BaseTopology >, dim, dim >
82 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
84 enum { m =
Size< BaseTopology, dim-1 > :: value };
90 template<
class BaseTopology,
unsigned int dim,
unsigned int codim >
91 class SizeImpl<
Pyramid< BaseTopology >, dim, codim >
94 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
95 dune_static_assert( (codim <= dim),
"Invalid codimension" );
97 enum { m =
Size< BaseTopology, codim-1 > :: value };
101 enum { value = m+n };
104 template<
class BaseTopology,
unsigned int dim >
105 class SizeImpl<
Pyramid< BaseTopology >, dim, 0 >
108 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
114 template<
class BaseTopology,
unsigned int dim >
115 class SizeImpl<
Pyramid< BaseTopology >, dim, dim >
118 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
120 enum { m =
Size< BaseTopology, dim-1 > :: value };
123 enum { value = m+1 };
127 template<
class Topology,
unsigned int codim >
130 enum {
value = SizeImpl< Topology, Topology :: dimension, codim >
:: value };
138 template<
class Topology,
unsigned int dim,
unsigned int codim,
unsigned int i >
139 class SubTopologyImpl;
141 template<
unsigned int dim,
unsigned int codim,
unsigned int i >
142 class SubTopologyImpl<
Point, dim, codim, i >
145 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
146 dune_static_assert( (codim <= dim),
"Invalid codimension" );
148 "Invalid subentity index" );
154 template<
class BaseTopology,
unsigned int dim,
unsigned int codim,
unsigned int i >
155 class SubTopologyImpl<
Prism< BaseTopology >, dim, codim, i >
158 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
159 dune_static_assert( (codim <= dim),
"Invalid codimension" );
161 "Invalid subentity index" );
163 enum { m =
Size< BaseTopology, codim-1 > :: value };
166 enum { s = (i < n+m ? 0 : 1) };
177 typedef typename SubTopology< BaseTopology, codim-1, i-(n+s*m) > :: type type;
181 typedef typename SelectType< (i < n), PrismSub<true>, BaseSub<false> > :: Type :: type type;
184 template<
class BaseTopology,
unsigned int dim,
unsigned int i >
185 class SubTopologyImpl<
Prism< BaseTopology >, dim, 0, i >
188 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
190 "Invalid subentity index" );
195 template<
class BaseTopology,
unsigned int dim,
unsigned int i >
196 class SubTopologyImpl<
Prism< BaseTopology >, dim, dim, i >
199 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
201 "Invalid subentity index" );
206 template<
class BaseTopology,
unsigned int dim,
unsigned int codim,
unsigned int i >
207 class SubTopologyImpl<
Pyramid< BaseTopology >, dim, codim, i >
210 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
211 dune_static_assert( (codim <= dim),
"Invalid codimension" );
213 "Invalid subentity index" );
215 enum { m =
Size< BaseTopology, codim-1 > :: value };
220 typedef typename SubTopology< BaseTopology, codim-1, i > :: type type;
230 typedef typename SelectType< (i < m), BaseSub<true>, PyramidSub<false> > :: Type :: type type;
233 template<
class BaseTopology,
unsigned int dim,
unsigned int i >
234 class SubTopologyImpl<
Pyramid< BaseTopology >, dim, 0, i >
237 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
239 "Invalid subentity index" );
245 template<
class BaseTopology,
unsigned int dim,
unsigned int i >
246 class SubTopologyImpl<
Pyramid< BaseTopology >, dim, dim, i >
249 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
251 "Invalid subentity index" );
257 template<
class Topology,
unsigned int codim,
unsigned int i >
260 typedef typename SubTopologyImpl< Topology, Topology :: dimension, codim, i >
:: type type;
268 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
278 ForLoop< Builder, 0, Size< Topology, codim > :: value-1 >
291 static unsigned int size (
unsigned int i )
294 return instance().size_[ i ];
298 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
318 template<
class Topology,
unsigned int codim,
319 unsigned int subdim,
unsigned int subcodim >
320 struct GenericSubTopologyNumberingHelper;
322 template<
class BaseTopology,
unsigned int codim,
323 unsigned int subdim,
unsigned int subcodim >
324 struct GenericSubTopologyNumberingHelper
325 <
Prism< BaseTopology >, codim, subdim, subcodim >
329 enum { m =
Size< BaseTopology, codim-1 > :: value };
332 enum { mb =
Size< BaseTopology, codim+subcodim-1 > :: value };
335 static unsigned int number (
unsigned int i,
unsigned int j )
337 const unsigned int s = (i < n+m ? 0 : 1);
342 const unsigned int ss = (j < ns+ms ? 0 : 1);
348 :: number( i, j-(ns+ss*ms) ) + nb + ss*mb;
356 template<
class BaseTopology,
unsigned int codim,
unsigned int subdim >
357 struct GenericSubTopologyNumberingHelper
358 <
Prism< BaseTopology >, codim, subdim, 0 >
362 static unsigned int number (
unsigned int i,
unsigned int j )
368 template<
class BaseTopology,
unsigned int codim,
unsigned int subdim >
369 struct GenericSubTopologyNumberingHelper
370 <
Prism< BaseTopology >, codim, subdim, subdim >
374 enum { m =
Size< BaseTopology, codim-1 > :: value };
377 enum { mb =
Size< BaseTopology, codim+subdim-1 > :: value };
379 static unsigned int number (
unsigned int i,
unsigned int j )
381 const unsigned int s = (i < n+m ? 0 : 1);
385 const unsigned int ss = (j < ms ? 0 : 1);
395 template<
class BaseTopology,
unsigned int codim,
396 unsigned int subdim,
unsigned int subcodim >
397 struct GenericSubTopologyNumberingHelper
398 <
Pyramid< BaseTopology >, codim, subdim, subcodim >
402 enum { m =
Size< BaseTopology, codim-1 > :: value };
404 enum { mb =
Size< BaseTopology, codim+subcodim-1 > :: value };
406 static unsigned int number (
unsigned int i,
unsigned int j )
424 template<
class BaseTopology,
unsigned int codim,
unsigned int subdim >
425 struct GenericSubTopologyNumberingHelper
426 <
Pyramid< BaseTopology >, codim, subdim, 0 >
430 static unsigned int number (
unsigned int i,
unsigned int j )
436 template<
class BaseTopology,
unsigned int codim,
unsigned int subdim >
437 struct GenericSubTopologyNumberingHelper
438 <
Pyramid< BaseTopology >, codim, subdim, subdim >
442 enum { m =
Size< BaseTopology, codim-1 > :: value };
444 enum { mb =
Size< BaseTopology, codim+subdim-1 > :: value };
446 static unsigned int number (
unsigned int i,
unsigned int j )
463 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
466 dune_static_assert( (codim <= Topology :: dimension),
"Invalid codimension" );
467 dune_static_assert( (codim + subcodim <= Topology :: dimension),
468 "Invalid subcodimension" );
473 static unsigned int number (
unsigned int i,
unsigned int j )
475 return (codim == 0 ? j : i );
482 static unsigned int number (
unsigned int i,
unsigned int j )
484 return GenericSubTopologyNumberingHelper
485 <
Topology, codim, Topology :: dimension - codim, subcodim >
491 static unsigned int number (
unsigned int i,
unsigned int j )
495 < (codim == 0) || (codim == Topology :: dimension), BorderCodim<true>, InnerCodim<false> >
496 :: Type :: number( i, j );
505 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
514 static unsigned int number (
unsigned int i,
unsigned int j )
517 return instance().numbering_[ i ][ j ];
523 for(
unsigned int i = 0; i < Size< Topology, codim > :: value; ++i )
526 numbering_[ i ].resize( size );
527 for(
unsigned int j = 0; j < size; ++j )
528 numbering_[ i ][ j ] = GenericNumbering :: number( i, j );
532 static const SubTopologyNumbering &instance ()
534 static SubTopologyNumbering inst;
544 template<
class Topology,
unsigned int codim >
555 template<
class Topology >
558 static const unsigned int dimension = Topology::dimension;
560 template<
class A,
class B >
563 static const unsigned int value = A::value + B::value;
566 template<
int codim >
572 template<
int codim >
575 static void apply (
unsigned int (&offsets)[ dimension+2 ] )
577 offsets[ codim+1 ] = offsets[ codim ] + Size< codim >::value;
582 static const unsigned int staticSize = GenericForLoop< StaticSum, Size, 0, dimension >::value;
587 ForLoop< CalcOffset, 0, dimension >::apply( offsets_ );
588 assert( size() == staticSize );
591 unsigned int operator() (
const unsigned int codim,
const unsigned int subEntity )
const
593 const unsigned int offset = offsets_[ codim ];
594 assert( offset + subEntity < offsets_[ codim+1 ] );
595 return offset + subEntity;
598 unsigned int size ()
const
600 return offsets_[ dimension+1 ];
604 unsigned int offsets_[ dimension+2 ];
611 #endif // #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_SUBTOPOLOGIES_HH