3#ifndef DUNE_GEOGRID_ITERATOR_HH
4#define DUNE_GEOGRID_ITERATOR_HH
11#include <dune/geometry/referenceelements.hh>
13#include <dune/grid/geometrygrid/capabilities.hh>
14#include <dune/grid/geometrygrid/declaration.hh>
15#include <dune/grid/geometrygrid/entity.hh>
27 bool fake = !Capabilities::hasHostEntity< Grid, codim >::v >
30 template<
class Gr
id >
31 class HierarchicIterator;
38 template<
int codim, PartitionIteratorType pitype,
class Gr
id >
39 struct PartitionIteratorFilter;
41 template<
int codim,
class Gr
id >
44 static const int dimension = std::remove_const< Grid >::type::dimension;
45 static const int codimension = codim;
49 typedef typename std::remove_const< Grid >::type::ctype ctype;
50 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
51 typedef Transitional::ReferenceElement< ctype, Dim<dimension> > RefElement;
53 static bool apply (
const RefElement &refElement,
54 const Element &element,
int subEntity )
56 const int size = refElement.size( subEntity, codim, dimension );
57 for(
int i = 0; i < size; ++i )
59 const int j = refElement.subEntity( subEntity, codim, i, dimension );
60 PartitionType type = element.template subEntity< dimension >( j ).partitionType();
68 template<
int codim,
class Gr
id >
71 static const int dimension = std::remove_const< Grid >::type::dimension;
72 static const int codimension = codim;
76 typedef typename std::remove_const< Grid >::type::ctype ctype;
77 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
78 typedef Transitional::ReferenceElement< ctype, Dim<dimension> > RefElement;
80 static bool apply (
const RefElement &refElement,
81 const Element &element,
int subEntity )
87 template<
int codim,
class Gr
id >
90 static const int dimension = std::remove_const< Grid >::type::dimension;
91 static const int codimension = codim;
95 typedef typename std::remove_const< Grid >::type::ctype ctype;
96 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
97 typedef Transitional::ReferenceElement< ctype, Dim<dimension> > RefElement;
99 static bool apply (
const RefElement &refElement,
100 const Element &element,
int subEntity )
105 const int size = refElement.size( subEntity, codim, dimension );
106 for(
int i = 0; i < size; ++i )
108 const int j = refElement.subEntity( subEntity, codim, i, dimension );
109 PartitionType type = element.template subEntity< dimension >( j ).partitionType();
117 template<
int codim,
class Gr
id >
120 static const int dimension = std::remove_const< Grid >::type::dimension;
121 static const int codimension = codim;
125 typedef typename std::remove_const< Grid >::type::ctype ctype;
126 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
127 typedef Transitional::ReferenceElement< ctype, Dim<dimension> > RefElement;
129 static bool apply (
const RefElement &refElement,
130 const Element &element,
int subEntity )
136 template<
int codim,
class Gr
id >
139 static const int dimension = std::remove_const< Grid >::type::dimension;
140 static const int codimension = codim;
144 typedef typename std::remove_const< Grid >::type::ctype ctype;
145 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
146 typedef Transitional::ReferenceElement< ctype, Dim<dimension> > RefElement;
148 static bool apply (
const RefElement &refElement,
149 const Element &element,
int subEntity )
155 template<
int codim,
class Gr
id >
158 static const int dimension = std::remove_const< Grid >::type::dimension;
159 static const int codimension = codim;
163 typedef typename std::remove_const< Grid >::type::ctype ctype;
164 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
165 typedef Transitional::ReferenceElement< ctype, Dim<dimension> > RefElement;
167 static bool apply (
const RefElement &refElement,
168 const Element &element,
int subEntity )
170 const int size = refElement.size( subEntity, codim, dimension );
171 for(
int i = 0; i < size; ++i )
173 const int j = refElement.subEntity( subEntity, codim, i, dimension );
174 PartitionType type = element.template subEntity< dimension >( j ).partitionType();
187 template<
class HostGr
idView,
int codim, PartitionIteratorType pitype,
class G >
188 class Iterator< HostGridView, codim, pitype, G, false >
190 typedef typename std::remove_const< G >::type::Traits Traits;
193 typedef typename Traits::Grid Grid;
195 static const int codimension = codim;
197 typedef typename Traits::template Codim< codimension >::Entity Entity;
199 static const bool fake =
false;
202 typedef GeoGrid::Entity< codimension, Traits::dimension, G > EntityImpl;
204 typedef typename HostGridView::template Codim< codim >::template Partition< pitype >::Iterator HostEntityIterator;
207 Iterator () : grid_( nullptr ) {}
209 Iterator (
const Grid &grid, HostEntityIterator hostEntityIterator )
211 hostEntityIterator_(
std::move( hostEntityIterator ) )
216 ++hostEntityIterator_;
219 bool equals (
const Iterator &rhs )
const
221 return hostEntityIterator_ == rhs.hostEntityIterator_;
224 Entity dereference ()
const
226 return EntityImpl( grid(), *hostEntityIterator_ );
229 int level ()
const {
return hostEntityIterator_.level(); }
231 const Grid &grid ()
const
237 static Iterator begin (
const Grid &grid,
const HostGridView &hostGridView )
239 HostEntityIterator hostEntityIterator = hostGridView.template begin< codimension, pitype >();
240 return Iterator( grid, std::move( hostEntityIterator ) );
243 static Iterator end (
const Grid &grid,
const HostGridView &hostGridView )
245 HostEntityIterator hostEntityIterator = hostGridView.template end< codimension, pitype >();
246 return Iterator( grid, std::move( hostEntityIterator ) );
251 HostEntityIterator hostEntityIterator_;
259 template<
class HostGr
idView,
int codim, PartitionIteratorType pitype,
class G >
260 class Iterator< HostGridView, codim, pitype, G, true >
262 typedef typename std::remove_const< G >::type::Traits Traits;
265 typedef typename Traits::Grid Grid;
267 static const int codimension = codim;
269 typedef typename Traits::template Codim< codimension >::Entity Entity;
272 typedef GeoGrid::Entity< codimension, Traits::dimension, G > EntityImpl;
274 typedef PartitionIteratorFilter< codim, pitype, typename HostGridView::Grid > Filter;
276 typedef typename HostGridView::template Codim<0>::template Partition< Filter::Element_Partition >::Iterator HostElementIterator;
277 typedef typename HostElementIterator::Entity HostElement;
278 typedef typename HostGridView::IndexSet HostIndexSet;
281 Iterator () : grid_( nullptr ), subEntity_( -1 ), hostIndexSet_( nullptr ) {}
283 Iterator (
const Grid &grid, HostElementIterator hostElementIterator, HostElementIterator hostEnd,
const HostIndexSet &hostIndexSet )
285 hostElementIterator_( hostElementIterator ),
288 hostIndexSet_( &hostIndexSet )
290 if( hostElementIterator_ != hostEnd_ )
292 visited_.resize( hostIndexSet_->size( codimension ),
false );
299 typedef typename Traits::ctype ctype;
301 while( hostElementIterator_ != hostEnd_ )
303 const HostElement &hostElement = *hostElementIterator_;
305 auto refElement = referenceElement< ctype, Traits::dimension >( hostElement.type() );
308 const int count = refElement.size( codimension );
309 for( ; subEntity_ < count; ++subEntity_ )
311 if( !Filter::apply( refElement, hostElement, subEntity_ ) )
314 const size_t index = hostIndexSet_->subIndex( hostElement, subEntity_, codimension );
315 if( !visited_[ index ] )
317 visited_[ index ] =
true;
321 ++hostElementIterator_;
326 bool equals (
const Iterator &rhs )
const
328 return hostElementIterator_ == rhs.hostElementIterator_ && ( hostElementIterator_ == hostEnd_ || subEntity_ == rhs.subEntity_ );
331 Entity dereference ()
const
333 return EntityImpl( grid(), *hostElementIterator_, subEntity_ );
336 int level ()
const {
return hostElementIterator_.level(); }
338 const Grid &grid ()
const
344 static Iterator begin (
const Grid &grid,
const HostGridView &hostGridView )
346 HostElementIterator first = hostGridView.template begin< 0, Filter::Element_Partition >();
347 HostElementIterator last = hostGridView.template end< 0, Filter::Element_Partition >();
348 return Iterator( grid, std::move( first ), std::move( last ), hostGridView.indexSet() );
351 static Iterator end (
const Grid &grid,
const HostGridView &hostGridView )
353 HostElementIterator last = hostGridView.template end< 0, Filter::Element_Partition >();
354 return Iterator( grid, last, last, hostGridView.indexSet() );
359 HostElementIterator hostElementIterator_, hostEnd_;
361 const HostIndexSet *hostIndexSet_;
362 std::vector< bool > visited_;
371 class HierarchicIterator
373 typedef typename std::remove_const< G >::type::Traits Traits;
376 typedef typename Traits::Grid Grid;
378 static const int codimension = 0;
380 typedef typename Traits::template Codim< codimension >::Entity Entity;
383 typedef GeoGrid::Entity< codimension, Traits::dimension, G > EntityImpl;
385 typedef typename Grid::HostGrid::HierarchicIterator HostEntityIterator;
388 HierarchicIterator () : grid_( nullptr ) {}
390 HierarchicIterator (
const Grid &grid, HostEntityIterator hostEntityIterator )
392 hostEntityIterator_(
std::move( hostEntityIterator ) )
397 ++hostEntityIterator_;
400 bool equals (
const HierarchicIterator &rhs )
const
402 return hostEntityIterator_ == rhs.hostEntityIterator_;
405 Entity dereference ()
const
407 return EntityImpl( grid(), *hostEntityIterator_ );
410 int level ()
const {
return hostEntityIterator_.level(); }
412 const Grid &grid ()
const
420 HostEntityIterator hostEntityIterator_;
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:400
Dune namespace.
Definition: alignedallocator.hh:11