3#ifndef DUNE_GEOMETRY_GENERICGEOMETRY_SUBTOPOLOGIES_HH
4#define DUNE_GEOMETRY_GENERICGEOMETRY_SUBTOPOLOGIES_HH
15#include <dune/geometry/genericgeometry/topologytypes.hh>
20 namespace GenericGeometry
23 template<
class Topology,
unsigned int codim >
26 template<
class Topology,
unsigned int codim,
unsigned int i >
29 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
30 class SubTopologySize;
32 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
33 class GenericSubTopologyNumbering;
35 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
36 class SubTopologyNumbering;
43 template<
class Topology,
unsigned int dim,
unsigned int codim >
46 template<
unsigned int dim,
unsigned int codim >
47 class SizeImpl< Point, dim, codim >
49 typedef Point Topology;
57 template<
class BaseTopology,
unsigned int dim,
unsigned int codim >
58 class SizeImpl< Prism< BaseTopology >, dim, codim >
60 typedef Prism< BaseTopology > Topology;
64 enum { m = Size< BaseTopology, codim-1 > :: value };
65 enum { n = Size< BaseTopology, codim > :: value };
68 enum { value = n + 2*m };
71 template<
class BaseTopology,
unsigned int dim >
72 class SizeImpl< Prism< BaseTopology >, dim, 0 >
74 typedef Prism< BaseTopology > Topology;
81 template<
class BaseTopology,
unsigned int dim >
82 class SizeImpl< Prism< BaseTopology >, dim, dim >
84 typedef Prism< BaseTopology > Topology;
87 enum { m = Size< BaseTopology, dim-1 > :: value };
93 template<
class BaseTopology,
unsigned int dim,
unsigned int codim >
94 class SizeImpl< Pyramid< BaseTopology >, dim, codim >
96 typedef Pyramid< BaseTopology > Topology;
100 enum { m = Size< BaseTopology, codim-1 > :: value };
101 enum { n = Size< BaseTopology, codim > :: value };
104 enum { value = m+n };
107 template<
class BaseTopology,
unsigned int dim >
108 class SizeImpl< Pyramid< BaseTopology >, dim, 0 >
110 typedef Pyramid< BaseTopology > Topology;
117 template<
class BaseTopology,
unsigned int dim >
118 class SizeImpl< Pyramid< BaseTopology >, dim, dim >
120 typedef Pyramid< BaseTopology > Topology;
123 enum { m = Size< BaseTopology, dim-1 > :: value };
126 enum { value = m+1 };
130 template<
class Topology,
unsigned int codim >
133 enum { value = SizeImpl< Topology, Topology :: dimension, codim > :: value };
140 unsigned int size (
unsigned int topologyId,
int dim,
int codim );
147 template<
class Topology,
unsigned int dim,
unsigned int codim,
unsigned int i >
148 class SubTopologyImpl;
150 template<
unsigned int dim,
unsigned int codim,
unsigned int i >
151 class SubTopologyImpl< Point, dim, codim, i >
153 typedef Point Topology;
157 "Invalid subentity index" );
160 typedef Topology type;
163 template<
class BaseTopology,
unsigned int dim,
unsigned int codim,
unsigned int i >
164 class SubTopologyImpl< Prism< BaseTopology >, dim, codim, i >
166 typedef Prism< BaseTopology > Topology;
170 "Invalid subentity index" );
172 enum { m = Size< BaseTopology, codim-1 > :: value };
173 enum { n = Size< BaseTopology, codim > :: value };
175 enum { s = (i < n+m ? 0 : 1) };
180 typedef Prism< typename SubTopology< BaseTopology, codim, i > :: type > type;
186 typedef typename SubTopology< BaseTopology, codim-1, i-(n+s*m) > :: type type;
190 typedef typename conditional< (i < n), PrismSub<true>, BaseSub<false> > :: type :: type type;
193 template<
class BaseTopology,
unsigned int dim,
unsigned int i >
194 class SubTopologyImpl< Prism< BaseTopology >, dim, 0, i >
196 typedef Prism< BaseTopology > Topology;
199 "Invalid subentity index" );
201 typedef Topology type;
204 template<
class BaseTopology,
unsigned int dim,
unsigned int i >
205 class SubTopologyImpl< Prism< BaseTopology >, dim, dim, i >
207 typedef Prism< BaseTopology > Topology;
210 "Invalid subentity index" );
215 template<
class BaseTopology,
unsigned int dim,
unsigned int codim,
unsigned int i >
216 class SubTopologyImpl< Pyramid< BaseTopology >, dim, codim, i >
218 typedef Pyramid< BaseTopology > Topology;
222 "Invalid subentity index" );
224 enum { m = Size< BaseTopology, codim-1 > :: value };
229 typedef typename SubTopology< BaseTopology, codim-1, i > :: type type;
235 typedef Pyramid<
typename SubTopology< BaseTopology, codim, i-m > :: type > type;
239 typedef typename conditional< (i < m), BaseSub<true>, PyramidSub<false> > :: type :: type type;
242 template<
class BaseTopology,
unsigned int dim,
unsigned int i >
243 class SubTopologyImpl< Pyramid< BaseTopology >, dim, 0, i >
245 typedef Pyramid< BaseTopology > Topology;
248 "Invalid subentity index" );
251 typedef Topology type;
254 template<
class BaseTopology,
unsigned int dim,
unsigned int i >
255 class SubTopologyImpl< Pyramid< BaseTopology >, dim, dim, i >
257 typedef Pyramid< BaseTopology > Topology;
260 "Invalid subentity index" );
266 template<
class Topology,
unsigned int codim,
unsigned int i >
269 typedef typename SubTopologyImpl< Topology, Topology :: dimension, codim, i > :: type type;
281 unsigned int subTopologyId (
unsigned int topologyId,
int dim,
int codim,
unsigned int i );
288 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
289 class SubTopologySize
294 unsigned int size_[ Size< Topology, codim > :: value ];
298 ForLoop< Builder, 0, Size< Topology, codim > :: value-1 >
302 SubTopologySize (
const SubTopologySize & );
304 DUNE_EXPORT static const SubTopologySize &instance ()
306 static SubTopologySize inst;
311 static unsigned int size (
unsigned int i )
313 assert( (i < Size< Topology, codim > :: value) );
314 return instance().size_[ i ];
318 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
320 struct SubTopologySize< Topology, codim, subcodim > :: Builder
322 typedef GenericGeometry :: SubTopologySize< Topology, codim, subcodim >
324 typedef typename GenericGeometry :: SubTopology< Topology, codim, i > :: type
327 static void apply ( SubTopologySize &subTopologySize )
329 subTopologySize.size_[ i ] = Size< SubTopology, subcodim > :: value;
336 template<
class Topology,
unsigned int codim,
337 unsigned int subdim,
unsigned int subcodim >
338 struct GenericSubTopologyNumberingHelper;
340 template<
class BaseTopology,
unsigned int codim,
341 unsigned int subdim,
unsigned int subcodim >
342 struct GenericSubTopologyNumberingHelper
343 < Prism< BaseTopology >, codim, subdim, subcodim >
345 typedef Prism< BaseTopology > Topology;
347 enum { m = Size< BaseTopology, codim-1 > :: value };
348 enum { n = Size< BaseTopology, codim > :: value };
350 enum { mb = Size< BaseTopology, codim+subcodim-1 > :: value };
351 enum { nb = Size< BaseTopology, codim+subcodim > :: value };
353 static unsigned int number (
unsigned int i,
unsigned int j )
355 const unsigned int s = (i < n+m ? 0 : 1);
358 const unsigned int ms = SubTopologySize< BaseTopology, codim, subcodim-1 > :: size( i );
359 const unsigned int ns = SubTopologySize< BaseTopology, codim, subcodim > :: size( i );
360 const unsigned int ss = (j < ns+ms ? 0 : 1);
362 return GenericSubTopologyNumbering< BaseTopology, codim, subcodim >
365 return GenericSubTopologyNumbering< BaseTopology, codim, subcodim-1 >
366 :: number( i, j-(ns+ss*ms) ) + nb + ss*mb;
369 return GenericSubTopologyNumbering< BaseTopology, codim-1, subcodim >
370 :: number( i-(n+s*m), j ) + nb + s*mb;
374 template<
class BaseTopology,
unsigned int codim,
unsigned int subdim >
375 struct GenericSubTopologyNumberingHelper
376 < Prism< BaseTopology >, codim, subdim, 0 >
378 typedef Prism< BaseTopology > Topology;
380 static unsigned int number (
unsigned int i,
unsigned int j )
387 template<
class BaseTopology,
unsigned int codim,
unsigned int subdim >
388 struct GenericSubTopologyNumberingHelper
389 < Prism< BaseTopology >, codim, subdim, subdim >
391 typedef Prism< BaseTopology > Topology;
393 enum { m = Size< BaseTopology, codim-1 > :: value };
394 enum { n = Size< BaseTopology, codim > :: value };
396 enum { mb = Size< BaseTopology, codim+subdim-1 > :: value };
398 static unsigned int number (
unsigned int i,
unsigned int j )
400 const unsigned int s = (i < n+m ? 0 : 1);
403 const unsigned int ms = SubTopologySize< BaseTopology, codim, subdim-1 > :: size( i );
404 const unsigned int ss = (j < ms ? 0 : 1);
405 return GenericSubTopologyNumbering< BaseTopology, codim, subdim-1 >
406 :: number( i, j-ss*ms ) + ss*mb;
409 return GenericSubTopologyNumbering< BaseTopology, codim-1, subdim >
410 :: number( i-(n+s*m), j ) + s*mb;
414 template<
class BaseTopology,
unsigned int codim,
415 unsigned int subdim,
unsigned int subcodim >
416 struct GenericSubTopologyNumberingHelper
417 < Pyramid< BaseTopology >, codim, subdim, subcodim >
419 typedef Pyramid< BaseTopology > Topology;
421 enum { m = Size< BaseTopology, codim-1 > :: value };
423 enum { mb = Size< BaseTopology, codim+subcodim-1 > :: value };
425 static unsigned int number (
unsigned int i,
unsigned int j )
428 return GenericSubTopologyNumbering< BaseTopology, codim-1, subcodim >
432 const unsigned int ms = SubTopologySize< BaseTopology, codim, subcodim-1 > :: size( i-m );
434 return GenericSubTopologyNumbering< BaseTopology, codim, subcodim-1 >
437 return GenericSubTopologyNumbering< BaseTopology, codim, subcodim >
438 :: number( i-m, j-ms ) + mb;
443 template<
class BaseTopology,
unsigned int codim,
unsigned int subdim >
444 struct GenericSubTopologyNumberingHelper
445 < Pyramid< BaseTopology >, codim, subdim, 0 >
447 typedef Pyramid< BaseTopology > Topology;
449 static unsigned int number (
unsigned int i,
unsigned int j )
456 template<
class BaseTopology,
unsigned int codim,
unsigned int subdim >
457 struct GenericSubTopologyNumberingHelper
458 < Pyramid< BaseTopology >, codim, subdim, subdim >
460 typedef Pyramid< BaseTopology > Topology;
462 enum { m = Size< BaseTopology, codim-1 > :: value };
464 enum { mb = Size< BaseTopology, codim+subdim-1 > :: value };
466 static unsigned int number (
unsigned int i,
unsigned int j )
469 return GenericSubTopologyNumbering< BaseTopology, codim-1, subdim >
473 const unsigned int ms = SubTopologySize< BaseTopology, codim, subdim-1 > :: size( i-m );
475 return GenericSubTopologyNumbering< BaseTopology, codim, subdim-1 >
483 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
484 class GenericSubTopologyNumbering
488 "Invalid subcodimension" );
493 static unsigned int number (
unsigned int i,
unsigned int j )
495 return (codim == 0 ? j : i );
502 static unsigned int number (
unsigned int i,
unsigned int j )
504 return GenericSubTopologyNumberingHelper
505 < Topology, codim, Topology :: dimension - codim, subcodim >
511 static unsigned int number (
unsigned int i,
unsigned int j )
513 assert( (j <= SubTopologySize< Topology, codim, subcodim > :: size( i )) );
515 < (codim == 0) || (codim == Topology :: dimension), BorderCodim<true>, InnerCodim<false> >
516 :: type :: number( i, j );
525 void subTopologyNumbering (
unsigned int topologyId,
int dim,
int codim,
unsigned int i,
int subcodim,
526 unsigned int *beginOut,
unsigned int *endOut );
533 template<
class Topology,
unsigned int codim,
unsigned int subcodim >
534 class SubTopologyNumbering
536 typedef GenericSubTopologyNumbering< Topology, codim, subcodim >
539 std :: vector< unsigned int > numbering_[ Size< Topology, codim > :: value ];
542 static unsigned int number (
unsigned int i,
unsigned int j )
544 assert( (j <= SubTopologySize< Topology, codim, subcodim > :: size( i )) );
545 return instance().numbering_[ i ][ j ];
549 SubTopologyNumbering ()
551 for(
unsigned int i = 0; i < Size< Topology, codim > :: value; ++i )
553 const unsigned int size = SubTopologySize< Topology, codim, subcodim > :: size( i );
554 numbering_[ i ].resize( size );
555 for(
unsigned int j = 0; j < size; ++j )
556 numbering_[ i ][ j ] = GenericNumbering :: number( i, j );
560 DUNE_EXPORT static const SubTopologyNumbering &instance ()
562 static SubTopologyNumbering inst;
571 template<
class Topology >
572 class SubTopologyMapper
574 static const unsigned int dimension = Topology::dimension;
576 template<
class A,
class B >
579 static const unsigned int value = A::value + B::value;
582 template<
int codim >
585 static const unsigned int value = GenericGeometry::Size< Topology, codim >::value;
588 template<
int codim >
591 static void apply (
unsigned int (&offsets)[ dimension+2 ] )
593 offsets[ codim+1 ] = offsets[ codim ] + Size< codim >::value;
598 static const unsigned int staticSize = GenericForLoop< StaticSum, Size, 0, dimension >::value;
603 ForLoop< CalcOffset, 0, dimension >::apply( offsets_ );
604 assert( size() == staticSize );
607 unsigned int operator() (
const unsigned int codim,
const unsigned int subEntity )
const
609 const unsigned int offset = offsets_[ codim ];
610 assert( offset + subEntity < offsets_[ codim+1 ] );
611 return offset + subEntity;
614 unsigned int size ()
const
616 return offsets_[ dimension+1 ];
620 unsigned int offsets_[ dimension+2 ];
A static for loop for template meta-programming.
#define dune_static_assert(COND, MSG)
Helper template so that compilation fails if condition is not true.
Definition: static_assert.hh:79
Dune namespace.
Definition: alignment.hh:14
Fallback implementation of the C++0x static_assert feature.
Statically compute the number of subentities of a given codimension.
Definition: subtopologies.hh:132
Traits for type conversions and type information.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
Definition of macros controlling symbol visibility at the ABI level.
#define DUNE_EXPORT
Export a symbol as part of the public ABI.
Definition: visibility.hh:18