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 >
29 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
32 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
40 template<
class Topology,
unsigned int dim,
unsigned int codim >
43 template<
unsigned int dim,
unsigned int 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 >
58 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
59 dune_static_assert( (codim <= dim),
"Invalid codimension" );
65 enum { value = n + 2*m };
68 template<
class BaseTopology,
unsigned int dim >
72 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
78 template<
class BaseTopology,
unsigned int dim >
82 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
90 template<
class BaseTopology,
unsigned int dim,
unsigned int codim >
94 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
95 dune_static_assert( (codim <= dim),
"Invalid codimension" );
101 enum { value = m+n };
104 template<
class BaseTopology,
unsigned int dim >
108 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
114 template<
class BaseTopology,
unsigned int dim >
118 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
123 enum { value = m+1 };
127 template<
class Topology,
unsigned int codim >
138 template<
class Topology,
unsigned int dim,
unsigned int codim,
unsigned int i >
141 template<
unsigned int dim,
unsigned int codim,
unsigned int 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 >
158 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
159 dune_static_assert( (codim <= dim),
"Invalid codimension" );
161 "Invalid subentity index" );
166 enum { s = (i < n+m ? 0 : 1) };
181 typedef typename SelectType< (i < n), PrismSub<true>, BaseSub<false> > :: Type :: type type;
184 template<
class BaseTopology,
unsigned int dim,
unsigned int i >
188 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
190 "Invalid subentity index" );
195 template<
class BaseTopology,
unsigned int dim,
unsigned int 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 >
210 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
211 dune_static_assert( (codim <= dim),
"Invalid codimension" );
213 "Invalid subentity index" );
230 typedef typename SelectType< (i < m), BaseSub<true>, PyramidSub<false> > :: Type :: type type;
233 template<
class BaseTopology,
unsigned int dim,
unsigned int i >
237 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
239 "Invalid subentity index" );
245 template<
class BaseTopology,
unsigned int dim,
unsigned int i >
249 dune_static_assert( (dim == Topology :: dimension),
"Wrong dimension" );
251 "Invalid subentity index" );
257 template<
class Topology,
unsigned int codim,
unsigned int i >
268 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
278 ForLoop< Builder, 0, Size< Topology, codim > :: value-1 >
282 SubTopologySize (
const SubTopologySize & );
284 static const SubTopologySize &instance ()
286 static SubTopologySize inst;
291 static unsigned int size (
unsigned int i )
294 return instance().size_[ i ];
298 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
300 struct SubTopologySize< Topology, codim, subcodim > :: Builder
307 static void apply ( SubTopologySize &subTopologySize )
309 subTopologySize.size_[ i ] = Size< SubTopology, subcodim > :: value;
318 template<
class Topology,
unsigned int codim,
319 unsigned int subdim,
unsigned int subcodim >
323 unsigned int subdim,
unsigned int subcodim >
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 >
362 static unsigned int number (
unsigned int i,
unsigned int j )
368 template<
class BaseTopology,
unsigned int codim,
unsigned int subdim >
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 >
406 static unsigned int number (
unsigned int i,
unsigned int j )
424 template<
class BaseTopology,
unsigned int codim,
unsigned int subdim >
430 static unsigned int number (
unsigned int i,
unsigned int j )
436 template<
class BaseTopology,
unsigned int codim,
unsigned int subdim >
446 static unsigned int number (
unsigned int i,
unsigned int j )
463 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
464 class GenericSubTopologyNumbering
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 >
506 class SubTopologyNumbering
508 typedef GenericSubTopologyNumbering< Topology, codim, subcodim >
511 std :: vector< unsigned int > numbering_[ Size< Topology, codim > :: value ];
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