1#ifndef DUNE_SPGRID_CACHEDPARTITIONLIST_HH
2#define DUNE_SPGRID_CACHEDPARTITIONLIST_HH
6#include <dune/grid/common/exceptions.hh>
8#include <dune/grid/spgrid/partitionlist.hh>
17 class SPCachedPartitionList
18 :
public SPPartitionList< dim >
20 typedef SPCachedPartitionList< dim > This;
21 typedef SPPartitionList< dim > Base;
24 typedef typename Base::Node Node;
27 typedef typename Base::MultiIndex MultiIndex;
28 typedef typename Base::Partition Partition;
30 SPCachedPartitionList ()
31 : first_(
std::numeric_limits< unsigned int >::
max() ),
32 last_(
std::numeric_limits< unsigned int >::
min() ),
36 SPCachedPartitionList (
const This &other )
43 ~SPCachedPartitionList () {
delete[] cache_; }
45 const This &operator= (
const This &other )
47 *(Base *)
this = other;
52 bool contains (
const unsigned int number )
const;
53 bool contains (
const MultiIndex &
id,
const unsigned int number )
const;
54 const Partition &partition (
const unsigned int number )
const;
56 unsigned int minNumber ()
const;
57 unsigned int maxNumber ()
const;
62 unsigned int first_, last_;
73 SPCachedPartitionList< dim >::contains (
const unsigned int number )
const
75 const bool inRange = (number >= minNumber()) && (number <= maxNumber());
76 return inRange && (cache_[ number - minNumber() ] != 0);
82 SPCachedPartitionList< dim >
83 ::contains (
const MultiIndex &
id,
const unsigned int number )
const
85 if( contains( number ) )
86 return cache_[ number - minNumber() ]->partition().contains(
id );
93 inline const typename SPCachedPartitionList< dim >::Partition &
94 SPCachedPartitionList< dim >::partition (
const unsigned int number )
const
96 assert( contains( number ) );
97 return cache_[ number - minNumber() ]->partition();
102 inline unsigned int SPCachedPartitionList< dim >::minNumber ()
const
109 inline unsigned int SPCachedPartitionList< dim >::maxNumber ()
const
116 inline void SPCachedPartitionList< dim >::updateCache ()
121 for(
const Node *it = Base::head_; it; it = it->next() )
123 first_ = std::min( first_, it->partition().number() );
124 last_ = std::max( last_, it->partition().number() );
129 const unsigned int cacheSize = last_ - first_ + 1;
130 cache_ =
new const Node *[ cacheSize ];
131 for(
unsigned int i = 0; i < cacheSize; ++i )
135 for(
const Node *it = Base::head_; it; it = it->next() )
137 const unsigned int number = it->partition().number();
138 if( cache_[ number - first_ ] != 0 )
139 DUNE_THROW( GridError,
"Partition number " << number <<
" is not unique." );
140 cache_[ number - first_ ] = it;
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:89
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:81
Dune namespace.
Definition: alignedallocator.hh:13