3#ifndef DUNE_SIZECACHE_HH 
    4#define DUNE_SIZECACHE_HH 
   14#include <dune/geometry/referenceelements.hh> 
   16#include <dune/grid/common/gridenums.hh> 
   28  template <
class Gr
idImp>
 
   33    enum { dim    = GridImp::dimension   };
 
   36    enum { nCodim = GridImp::dimension+1 };
 
   39    typedef GridImp GridType;
 
   42    typedef typename GridType :: ctype ctype ;
 
   45    mutable std::vector< int > levelSizes_[nCodim];
 
   48    mutable std::vector< std::vector< int > > levelTypeSizes_[nCodim];
 
   51    mutable int leafSizes_[nCodim];
 
   54    mutable std::vector< int > leafTypeSizes_[nCodim];
 
   57    const GridType & grid_;
 
   60    template < 
int codim, 
bool gr
idHasCodim >
 
   61    struct CountLevelEntitiesBase
 
   63      template < 
class SzCacheType >
 
   64      static void apply(
const SzCacheType & sc, 
int level, 
int cd)
 
   68          sc.template countLevelEntities<All_Partition,codim> (level);
 
   73    template < 
int codim >
 
   74    struct CountLevelEntitiesBase< codim, false >
 
   76      template < 
class SzCacheType >
 
   77      static void apply(
const SzCacheType & sc, 
int level, 
int cd)
 
   81          sc.template countLevelEntitiesNoCodim<All_Partition,codim> (level);
 
   86    template < 
int codim >
 
   87    struct CountLevelEntities
 
   88      : 
public CountLevelEntitiesBase< codim, Capabilities :: hasEntity< GridType, codim > :: v >
 
   92    template < 
int codim, 
bool gr
idHasCodim >
 
   93    struct CountLeafEntitiesBase
 
   95      template <
class SzCacheType>
 
   96      static void apply(
const SzCacheType & sc, 
int cd)
 
  100          sc.template countLeafEntities<All_Partition,codim> ();
 
  106    template < 
int codim >
 
  107    struct CountLeafEntitiesBase< codim, false >
 
  109      template <
class SzCacheType>
 
  110      static void apply(
const SzCacheType & sc, 
int cd)
 
  114          sc.template countLeafEntitiesNoCodim<All_Partition,codim> ();
 
  119    template < 
int codim >
 
  120    struct CountLeafEntities
 
  121      : 
public CountLeafEntitiesBase< codim, Capabilities :: hasEntity< GridType, codim > :: v >
 
  126      return type.
id() >> 1 ;
 
  129    int sizeCodim( 
const int codim )
 const 
  131      const int mydim = GridType :: dimension - codim;
 
  132      return ((1 << mydim) + 1) / 2;
 
  147      for(
int codim=0; codim<nCodim; ++codim)
 
  149        leafSizes_[ codim ] = -1;
 
  150        leafTypeSizes_[ codim ].resize( sizeCodim( codim ), -1 );
 
  153      const int numMxl = grid_.maxLevel()+1;
 
  154      for(
int codim=0; codim<nCodim; ++codim)
 
  156        std::vector<int> & vec = levelSizes_[codim];
 
  158        levelTypeSizes_[codim].resize( numMxl );
 
  159        for(
int level = 0; level<numMxl; ++level)
 
  162          levelTypeSizes_[codim][level].resize( sizeCodim( codim ), -1 );
 
  171    int size (
int level, 
int codim)
 const 
  173      assert( codim >= 0 );
 
  174      assert( codim < nCodim );
 
  175      assert( level >= 0 );
 
  176      if( level >= (
int) levelSizes_[codim].
size() ) 
return 0;
 
  178      if( levelSizes_[codim][level] < 0)
 
  183      assert( levelSizes_[codim][level] >= 0 );
 
  184      return levelSizes_[codim][level];
 
  190      const int codim = GridType ::dimension - type.
dim();
 
  191      if( levelSizes_[codim][level] < 0)
 
  194      assert( levelTypeSizes_[codim][level][gtIndex( type )] >= 0 );
 
  195      return levelTypeSizes_[codim][level][gtIndex( type )];
 
  204      assert( codim >= 0 );
 
  205      assert( codim < nCodim );
 
  206      if( leafSizes_[codim] < 0 )
 
  209      assert( leafSizes_[codim] >= 0 );
 
  210      return leafSizes_[codim];
 
  216      const int codim = GridType :: dimension - type.
dim();
 
  217      if( leafSizes_[codim] < 0 )
 
  220      assert( leafTypeSizes_[codim][ gtIndex( type )] >= 0 );
 
  221      return leafTypeSizes_[codim][ gtIndex( type )];
 
  225    template <PartitionIteratorType pitype, 
int codim>
 
  226    void countLevelEntities(
int level)
 const 
  228      typedef typename GridType :: LevelGridView 
GridView ;
 
  229      typedef typename GridView :: template 
Codim< codim > :: template Partition<pitype>  :: Iterator Iterator ;
 
  230      GridView gridView = grid_.levelGridView( level );
 
  231      Iterator it  = gridView.template begin<codim,pitype> ();
 
  232      Iterator end = gridView.template end<codim,pitype>   ();
 
  233      levelSizes_[codim][level] = countElements(it,end, levelTypeSizes_[codim][level]);
 
  236    template <PartitionIteratorType pitype, 
int codim>
 
  237    void countLeafEntities()
 const 
  240      typedef typename GridType :: LeafGridView GridView ;
 
  241      typedef typename GridView :: template Codim< codim > :: template Partition<pitype>  :: Iterator Iterator ;
 
  242      GridView gridView = grid_.leafGridView();
 
  243      Iterator it  = gridView.template begin<codim,pitype> ();
 
  244      Iterator end = gridView.template end<codim,pitype>   ();
 
  245      leafSizes_[codim] = countElements(it,end, leafTypeSizes_[codim] );
 
  249    template <
class IteratorType>
 
  250    int countElements(IteratorType & it, 
const IteratorType & end, std::vector<int>& typeSizes)
 const 
  253      const size_t types = typeSizes.size();
 
  254      for(
size_t i=0; i<types; ++i) typeSizes[i] = 0;
 
  255      for( ; it != end; ++it )
 
  258        ++typeSizes[ gtIndex( type ) ];
 
  263      for(
size_t i=0; i<types; ++i) sumtypes += typeSizes[i];
 
  265      assert( overall == sumtypes );
 
  269    template <PartitionIteratorType pitype, 
int codim>
 
  270    void countLevelEntitiesNoCodim(
int level)
 const 
  272      typedef typename GridType :: LevelGridView GridView ;
 
  273      typedef typename GridView :: template 
Codim< 0 > :: template Partition<pitype>  :: Iterator Iterator ;
 
  274      GridView gridView = grid_.levelGridView( level );
 
  275      Iterator it  = gridView.template begin< 0, pitype> ();
 
  276      Iterator end = gridView.template end< 0, pitype>   ();
 
  277      levelSizes_[codim][level] = countElementsNoCodim< codim >(it,end, levelTypeSizes_[codim][level]);
 
  280    template <PartitionIteratorType pitype, 
int codim>
 
  281    void countLeafEntitiesNoCodim()
 const 
  284      typedef typename GridType :: LeafGridView GridView ;
 
  285      typedef typename GridView :: template 
Codim< 0 > :: template Partition<pitype>  :: Iterator Iterator ;
 
  286      GridView gridView = grid_.leafGridView();
 
  287      Iterator it  = gridView.template begin< 0, pitype > ();
 
  288      Iterator end = gridView.template end< 0, pitype >   ();
 
  289      leafSizes_[codim] = countElementsNoCodim< codim >(it,end, leafTypeSizes_[codim] );
 
  293    template < 
int codim, 
class IteratorType >
 
  294    int countElementsNoCodim(IteratorType & it, 
const IteratorType & end, std::vector<int>& typeSizes)
 const 
  296      typedef typename GridType :: LocalIdSet LocalIdSet ;
 
  297      typedef typename LocalIdSet :: IdType IdType ;
 
  299      typedef ReferenceElement< ctype, dim > ReferenceElementType;
 
  300      typedef ReferenceElements< ctype, dim > ReferenceElementContainerType;
 
  302      typedef std::set< IdType > CodimIdSetType ;
 
  304      typedef typename IteratorType :: Entity ElementType ;
 
  307      const LocalIdSet& idSet = grid_.localIdSet();
 
  309      const size_t types = typeSizes.size();
 
  310      for(
size_t i=0; i<types; ++i) typeSizes[ i ] = 0;
 
  312      std::vector< CodimIdSetType > typeCount( types );
 
  315      for( ; it != end; ++it )
 
  318        const ElementType& element = *it ;
 
  320        const ReferenceElementType& refElem =
 
  321          ReferenceElementContainerType :: general( element.type() );
 
  324        const int count = element.subEntities( codim );
 
  325        for( 
int i=0; i< count; ++ i )
 
  330          const IdType 
id = idSet.subId( element, i, codim );
 
  332          typeCount[ gtIndex( geomType ) ].insert( 
id );
 
  338      for(
size_t i=0; i<types; ++i)
 
  340        typeSizes[ i ] = typeCount[ i ].size();
 
  341        overall += typeSizes[ i ];
 
  349  template <
class Gr
idImp>
 
A static loop using TMP.
Definition: forloop.hh:110
 
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
 
unsigned int dim() const
Return dimension of the type.
Definition: type.hh:321
 
unsigned int id() const
Return the topology id the type.
Definition: type.hh:326
 
Grid view abstract base class.
Definition: gridview.hh:59
 
organizes the caching of sizes for one grid and one GeometryType
Definition: sizecache.hh:30
 
int size(int level, GeometryType type) const
Return number of entities per level and geometry type in this process.
Definition: sizecache.hh:188
 
int size(int level, int codim) const
Return number of grid entities of a given codim on a given level in this process.
Definition: sizecache.hh:171
 
int size(int codim) const
Return number of leaf entities of a given codim in this process.
Definition: sizecache.hh:202
 
SizeCache(const GridType &grid)
constructor taking grid reference
Definition: sizecache.hh:139
 
int size(const GeometryType type) const
Return number of leaf entities per geometry type in this process.
Definition: sizecache.hh:214
 
void reset()
reset all cached sizes
Definition: sizecache.hh:145
 
A set of traits classes to store static information about grid implementation.
 
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
 
A few common exception classes.
 
A static for loop for template meta-programming.
 
#define DUNE_DEPRECATED
Mark some entity as deprecated.
Definition: deprecated.hh:84
 
Dune namespace.
Definition: alignment.hh:10
 
Static tag representing a codimension.
Definition: dimension.hh:22
 
organizes the caching of sizes for one grid and one GeometryType
Definition: sizecache.hh:351
 
A unique label for each type of element that can occur in a grid.