3#ifndef DUNE_GEOMETRY_GENERICGEOMETRY_SUBTOPOLOGIES_HH 
    4#define DUNE_GEOMETRY_GENERICGEOMETRY_SUBTOPOLOGIES_HH 
   14#include <dune/geometry/genericgeometry/topologytypes.hh> 
   19  namespace GenericGeometry
 
   22    template< 
class Topology, 
unsigned int codim >
 
   25    template< 
class Topology, 
unsigned int codim, 
unsigned int i >
 
   28    template< 
class Topology, 
unsigned int codim, 
unsigned int subcodim >
 
   29    class SubTopologySize;
 
   31    template< 
class Topology, 
unsigned int codim, 
unsigned int subcodim >
 
   32    class GenericSubTopologyNumbering;
 
   34    template< 
class Topology, 
unsigned int codim, 
unsigned int subcodim >
 
   35    class SubTopologyNumbering;
 
   42    template< 
class Topology, 
unsigned int dim, 
unsigned int codim >
 
   45    template< 
unsigned int dim, 
unsigned int codim >
 
   46    class SizeImpl< Point, dim, codim >
 
   48      typedef Point Topology;
 
   49      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
   50      static_assert((codim <= dim), 
"Invalid codimension");
 
   56    template< 
class BaseTopology, 
unsigned int dim, 
unsigned int codim >
 
   57    class SizeImpl< Prism< BaseTopology >, dim, codim >
 
   59      typedef Prism< BaseTopology > Topology;
 
   60      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
   61      static_assert((codim <= dim), 
"Invalid codimension");
 
   63      enum { m = Size< BaseTopology, codim-1 > :: value };
 
   64      enum { n = Size< BaseTopology, codim > :: value };
 
   67      enum { value = n + 2*m };
 
   70    template< 
class BaseTopology, 
unsigned int dim >
 
   71    class SizeImpl< Prism< BaseTopology >, dim, 0 >
 
   73      typedef Prism< BaseTopology > Topology;
 
   74      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
   80    template< 
class BaseTopology, 
unsigned int dim >
 
   81    class SizeImpl< Prism< BaseTopology >, dim, dim >
 
   83      typedef Prism< BaseTopology > Topology;
 
   84      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
   86      enum { m = Size< BaseTopology, dim-1 > :: value };
 
   92    template< 
class BaseTopology, 
unsigned int dim, 
unsigned int codim >
 
   93    class SizeImpl< Pyramid< BaseTopology >, dim, codim >
 
   95      typedef Pyramid< BaseTopology > Topology;
 
   96      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
   97      static_assert((codim <= dim), 
"Invalid codimension");
 
   99      enum { m = Size< BaseTopology, codim-1 > :: value };
 
  100      enum { n = Size< BaseTopology, codim > :: value };
 
  103      enum { value = m+n };
 
  106    template< 
class BaseTopology, 
unsigned int dim >
 
  107    class SizeImpl< Pyramid< BaseTopology >, dim, 0 >
 
  109      typedef Pyramid< BaseTopology > Topology;
 
  110      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
  116    template< 
class BaseTopology, 
unsigned int dim >
 
  117    class SizeImpl< Pyramid< BaseTopology >, dim, dim >
 
  119      typedef Pyramid< BaseTopology > Topology;
 
  120      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
  122      enum { m = Size< BaseTopology, dim-1 > :: value };
 
  125      enum { value = m+1 };
 
  129    template< 
class Topology, 
unsigned int codim >
 
  132      enum { value = SizeImpl< Topology, Topology :: dimension, codim > :: value };
 
  139    unsigned int size ( 
unsigned int topologyId, 
int dim, 
int codim );
 
  146    template< 
class Topology, 
unsigned int dim, 
unsigned int codim, 
unsigned int i >
 
  147    class SubTopologyImpl;
 
  149    template< 
unsigned int dim, 
unsigned int codim, 
unsigned int i >
 
  150    class SubTopologyImpl< Point, dim, codim, i >
 
  152      typedef Point Topology;
 
  153      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
  154      static_assert((codim <= dim), 
"Invalid codimension");
 
  155      static_assert((i < Size< Topology, codim > :: value), 
"Invalid subentity index");
 
  158      typedef Topology type;
 
  161    template< 
class BaseTopology, 
unsigned int dim, 
unsigned int codim, 
unsigned int i >
 
  162    class SubTopologyImpl< Prism< BaseTopology >, dim, codim, i >
 
  164      typedef Prism< BaseTopology > Topology;
 
  165      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
  166      static_assert((codim <= dim), 
"Invalid codimension");
 
  167      static_assert((i < Size< Topology, codim > :: value), 
"Invalid subentity index");
 
  169      enum { m = Size< BaseTopology, codim-1 > :: value };
 
  170      enum { n = Size< BaseTopology, codim > :: value };
 
  172      enum { s = (i < n+m ? 0 : 1) };
 
  177        typedef Prism< typename SubTopology< BaseTopology, codim, i > :: type > type;
 
  183        typedef typename SubTopology< BaseTopology, codim-1, i-(n+s*m) > :: type type;
 
  187      typedef typename conditional< (i < n), PrismSub<true>, BaseSub<false> > :: type :: type type;
 
  190    template< 
class BaseTopology, 
unsigned int dim, 
unsigned int i >
 
  191    class SubTopologyImpl< Prism< BaseTopology >, dim, 0, i >
 
  193      typedef Prism< BaseTopology > Topology;
 
  194      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
  195      static_assert((i < Size< Topology, 0 > :: value), 
"Invalid subentity index");
 
  197      typedef Topology type;
 
  200    template< 
class BaseTopology, 
unsigned int dim, 
unsigned int i >
 
  201    class SubTopologyImpl< Prism< BaseTopology >, dim, dim, i >
 
  203      typedef Prism< BaseTopology > Topology;
 
  204      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
  205      static_assert((i < Size< Topology, dim > :: value), 
"Invalid subentity index");
 
  210    template< 
class BaseTopology, 
unsigned int dim, 
unsigned int codim, 
unsigned int i >
 
  211    class SubTopologyImpl< Pyramid< BaseTopology >, dim, codim, i >
 
  213      typedef Pyramid< BaseTopology > Topology;
 
  214      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
  215      static_assert((codim <= dim), 
"Invalid codimension" );
 
  216      static_assert((i < Size< Topology, codim > :: value), 
"Invalid subentity index");
 
  218      enum { m = Size< BaseTopology, codim-1 > :: value };
 
  223        typedef typename SubTopology< BaseTopology, codim-1, i > :: type type;
 
  229        typedef Pyramid< 
typename SubTopology< BaseTopology, codim, i-m > :: type > type;
 
  233      typedef typename conditional< (i < m), BaseSub<true>, PyramidSub<false> > :: type :: type type;
 
  236    template< 
class BaseTopology, 
unsigned int dim, 
unsigned int i >
 
  237    class SubTopologyImpl< Pyramid< BaseTopology >, dim, 0, i >
 
  239      typedef Pyramid< BaseTopology > Topology;
 
  240      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
  241      static_assert((i < Size< Topology, 0 > :: value), 
"Invalid subentity index");
 
  244      typedef Topology type;
 
  247    template< 
class BaseTopology, 
unsigned int dim, 
unsigned int i >
 
  248    class SubTopologyImpl< Pyramid< BaseTopology >, dim, dim, i >
 
  250      typedef Pyramid< BaseTopology > Topology;
 
  251      static_assert((dim == Topology :: dimension), 
"Wrong dimension");
 
  252      static_assert((i < Size< Topology, dim > :: value), 
"Invalid subentity index");
 
  258    template< 
class Topology, 
unsigned int codim, 
unsigned int i >
 
  261      typedef typename SubTopologyImpl< Topology, Topology :: dimension, codim, i > :: type type;
 
  273    unsigned int subTopologyId ( 
unsigned int topologyId, 
int dim, 
int codim, 
unsigned int i );
 
  280    template< 
class Topology, 
unsigned int codim, 
unsigned int subcodim >
 
  281    class SubTopologySize
 
  286      unsigned int size_[ Size< Topology, codim > :: value ];
 
  290        ForLoop< Builder, 0, Size< Topology, codim > :: value-1 >
 
  294      SubTopologySize ( 
const SubTopologySize & );
 
  296      DUNE_EXPORT static const SubTopologySize &instance ()
 
  298        static SubTopologySize inst;
 
  303      static unsigned int size ( 
unsigned int i )
 
  305        assert( (i < Size< Topology, codim > :: value) );
 
  306        return instance().size_[ i ];
 
  310    template< 
class Topology, 
unsigned int codim, 
unsigned int subcodim >
 
  312    struct SubTopologySize< Topology, codim, subcodim > :: Builder
 
  314      typedef GenericGeometry :: SubTopologySize< Topology, codim, subcodim >
 
  316      typedef typename GenericGeometry :: SubTopology< Topology, codim, i > :: type
 
  319      static void apply ( SubTopologySize &subTopologySize )
 
  321        subTopologySize.size_[ i ] = Size< SubTopology, subcodim > :: value;
 
  328    template< 
class Topology, 
unsigned int codim,
 
  329        unsigned int subdim, 
unsigned int subcodim >
 
  330    struct GenericSubTopologyNumberingHelper;
 
  332    template< 
class BaseTopology, 
unsigned int codim,
 
  333        unsigned int subdim, 
unsigned int subcodim >
 
  334    struct GenericSubTopologyNumberingHelper
 
  335    < Prism< BaseTopology >, codim, subdim, subcodim >
 
  337      typedef Prism< BaseTopology > Topology;
 
  339      enum { m = Size< BaseTopology, codim-1 > :: value };
 
  340      enum { n = Size< BaseTopology, codim > :: value };
 
  342      enum { mb = Size< BaseTopology, codim+subcodim-1 > :: value };
 
  343      enum { nb = Size< BaseTopology, codim+subcodim > :: value };
 
  345      static unsigned int number ( 
unsigned int i, 
unsigned int j )
 
  347        const unsigned int s = (i < n+m ? 0 : 1);
 
  350          const unsigned int ms = SubTopologySize< BaseTopology, codim, subcodim-1 > :: size( i );
 
  351          const unsigned int ns = SubTopologySize< BaseTopology, codim, subcodim > :: size( i );
 
  352          const unsigned int ss = (j < ns+ms ? 0 : 1);
 
  354            return GenericSubTopologyNumbering< BaseTopology, codim, subcodim >
 
  357            return GenericSubTopologyNumbering< BaseTopology, codim, subcodim-1 >
 
  358                   :: number( i, j-(ns+ss*ms) ) + nb + ss*mb;
 
  361          return GenericSubTopologyNumbering< BaseTopology, codim-1, subcodim >
 
  362                 :: number( i-(n+s*m), j ) + nb + s*mb;
 
  366    template< 
class BaseTopology, 
unsigned int codim, 
unsigned int subdim >
 
  367    struct GenericSubTopologyNumberingHelper
 
  368    < Prism< BaseTopology >, codim, subdim, 0 >
 
  370      typedef Prism< BaseTopology > Topology;
 
  372      static unsigned int number ( 
unsigned int i, 
unsigned int j )
 
  379    template< 
class BaseTopology, 
unsigned int codim, 
unsigned int subdim >
 
  380    struct GenericSubTopologyNumberingHelper
 
  381    < Prism< BaseTopology >, codim, subdim, subdim >
 
  383      typedef Prism< BaseTopology > Topology;
 
  385      enum { m = Size< BaseTopology, codim-1 > :: value };
 
  386      enum { n = Size< BaseTopology, codim > :: value };
 
  388      enum { mb = Size< BaseTopology, codim+subdim-1 > :: value };
 
  390      static unsigned int number ( 
unsigned int i, 
unsigned int j )
 
  392        const unsigned int s = (i < n+m ? 0 : 1);
 
  395          const unsigned int ms = SubTopologySize< BaseTopology, codim, subdim-1 > :: size( i );
 
  396          const unsigned int ss = (j < ms ? 0 : 1);
 
  397          return GenericSubTopologyNumbering< BaseTopology, codim, subdim-1 >
 
  398                 :: number( i, j-ss*ms ) + ss*mb;
 
  401          return GenericSubTopologyNumbering< BaseTopology, codim-1, subdim >
 
  402                 :: number( i-(n+s*m), j ) + s*mb;
 
  406    template< 
class BaseTopology, 
unsigned int codim,
 
  407        unsigned int subdim, 
unsigned int subcodim >
 
  408    struct GenericSubTopologyNumberingHelper
 
  409    < Pyramid< BaseTopology >, codim, subdim, subcodim >
 
  411      typedef Pyramid< BaseTopology > Topology;
 
  413      enum { m = Size< BaseTopology, codim-1 > :: value };
 
  415      enum { mb = Size< BaseTopology, codim+subcodim-1 > :: value };
 
  417      static unsigned int number ( 
unsigned int i, 
unsigned int j )
 
  420          return GenericSubTopologyNumbering< BaseTopology, codim-1, subcodim >
 
  424          const unsigned int ms = SubTopologySize< BaseTopology, codim, subcodim-1 > :: size( i-m );
 
  426            return GenericSubTopologyNumbering< BaseTopology, codim, subcodim-1 >
 
  429            return GenericSubTopologyNumbering< BaseTopology, codim, subcodim >
 
  430                   :: number( i-m, j-ms ) + mb;
 
  435    template< 
class BaseTopology, 
unsigned int codim, 
unsigned int subdim >
 
  436    struct GenericSubTopologyNumberingHelper
 
  437    < Pyramid< BaseTopology >, codim, subdim, 0 >
 
  439      typedef Pyramid< BaseTopology > Topology;
 
  441      static unsigned int number ( 
unsigned int i, 
unsigned int j )
 
  448    template< 
class BaseTopology, 
unsigned int codim, 
unsigned int subdim >
 
  449    struct GenericSubTopologyNumberingHelper
 
  450    < Pyramid< BaseTopology >, codim, subdim, subdim >
 
  452      typedef Pyramid< BaseTopology > Topology;
 
  454      enum { m = Size< BaseTopology, codim-1 > :: value };
 
  456      enum { mb = Size< BaseTopology, codim+subdim-1 > :: value };
 
  458      static unsigned int number ( 
unsigned int i, 
unsigned int j )
 
  461          return GenericSubTopologyNumbering< BaseTopology, codim-1, subdim >
 
  465          const unsigned int ms = SubTopologySize< BaseTopology, codim, subdim-1 > :: size( i-m );
 
  467            return GenericSubTopologyNumbering< BaseTopology, codim, subdim-1 >
 
  475    template< 
class Topology, 
unsigned int codim, 
unsigned int subcodim >
 
  476    class GenericSubTopologyNumbering
 
  478      static_assert((codim <= Topology :: dimension), 
"Invalid codimension");
 
  479      static_assert((codim + subcodim <= Topology :: dimension), 
"Invalid subcodimension");
 
  484        static unsigned int number ( 
unsigned int i, 
unsigned int j )
 
  486          return (codim == 0 ? j : i );
 
  493        static unsigned int number ( 
unsigned int i, 
unsigned int j )
 
  495          return GenericSubTopologyNumberingHelper
 
  496                 < Topology, codim, Topology :: dimension - codim, subcodim >
 
  502      static unsigned int number ( 
unsigned int i, 
unsigned int j )
 
  504        assert( (j <= SubTopologySize< Topology, codim, subcodim > :: size( i )) );
 
  506               < (codim == 0) || (codim == Topology :: dimension), BorderCodim<true>, InnerCodim<false> >
 
  507               :: type :: number( i, j );
 
  516    void subTopologyNumbering ( 
unsigned int topologyId, 
int dim, 
int codim, 
unsigned int i, 
int subcodim,
 
  517                                unsigned int *beginOut, 
unsigned int *endOut );
 
  524    template< 
class Topology, 
unsigned int codim, 
unsigned int subcodim >
 
  525    class SubTopologyNumbering
 
  527      typedef GenericSubTopologyNumbering< Topology, codim, subcodim >
 
  530      std :: vector< unsigned int > numbering_[ Size< Topology, codim > :: value ];
 
  533      static unsigned int number ( 
unsigned int i, 
unsigned int j )
 
  535        assert( (j <= SubTopologySize< Topology, codim, subcodim > :: size( i )) );
 
  536        return instance().numbering_[ i ][ j ];
 
  540      SubTopologyNumbering ()
 
  542        for( 
unsigned int i = 0; i < Size< Topology, codim > :: value; ++i )
 
  544          const unsigned int size = SubTopologySize< Topology, codim, subcodim > :: size( i );
 
  545          numbering_[ i ].resize( size );
 
  546          for( 
unsigned int j = 0; j < size; ++j )
 
  547            numbering_[ i ][ j ] = GenericNumbering :: number( i, j );
 
  551      DUNE_EXPORT static const SubTopologyNumbering &instance ()
 
  553        static SubTopologyNumbering inst;
 
  562    template< 
class Topology >
 
  563    class SubTopologyMapper
 
  565      static const unsigned int dimension = Topology::dimension;
 
  567      template< 
class A, 
class B >
 
  570        static const unsigned int value = A::value + B::value;
 
  573      template< 
int codim >
 
  576        static const unsigned int value = GenericGeometry::Size< Topology, codim >::value;
 
  579      template< 
int codim >
 
  582        static void apply ( 
unsigned int (&offsets)[ dimension+2 ] )
 
  584          offsets[ codim+1 ] = offsets[ codim ] + Size< codim >::value;
 
  589      static const unsigned int staticSize = GenericForLoop< StaticSum, Size, 0, dimension >::value;
 
  594        ForLoop< CalcOffset, 0, dimension >::apply( offsets_ );
 
  595        assert( size() == staticSize );
 
  598      unsigned int operator() ( 
const unsigned int codim, 
const unsigned int subEntity )
 const 
  600        const unsigned int offset = offsets_[ codim ];
 
  601        assert( offset + subEntity < offsets_[ codim+1 ] );
 
  602        return offset + subEntity;
 
  605      unsigned int size ()
 const 
  607        return offsets_[ dimension+1 ];
 
  611      unsigned int offsets_[ dimension+2 ];
 
A static for loop for template meta-programming.
 
Dune namespace.
Definition: alignment.hh:10
 
Statically compute the number of subentities of a given codimension.
Definition: subtopologies.hh:131
 
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