3#ifndef DUNE_GEOGRID_ITERATOR_HH
4#define DUNE_GEOGRID_ITERATOR_HH
11#include <dune/geometry/referenceelements.hh>
14#include <dune/grid/geometrygrid/capabilities.hh>
15#include <dune/grid/geometrygrid/declaration.hh>
16#include <dune/grid/geometrygrid/entity.hh>
28 bool fake = !Capabilities::hasHostEntity< Grid, codim >::v >
31 template<
class Gr
id >
32 class HierarchicIterator;
39 template<
int codim, PartitionIteratorType pitype,
class Gr
id >
40 struct PartitionIteratorFilter;
42 template<
int codim,
class Gr
id >
45 static const int dimension = std::remove_const< Grid >::type::dimension;
46 static const int codimension = codim;
50 typedef typename std::remove_const< Grid >::type::ctype ctype;
51 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
52 typedef ReferenceElement< ctype, dimension > RefElement;
54 static bool apply (
const RefElement &refElement,
55 const Element &element,
int subEntity )
57 const int size = refElement.size( subEntity, codim, dimension );
58 for(
int i = 0; i < size; ++i )
60 const int j = refElement.subEntity( subEntity, codim, i, dimension );
61 PartitionType type = element.template subEntity< dimension >( j ).partitionType();
69 template<
int codim,
class Gr
id >
72 static const int dimension = std::remove_const< Grid >::type::dimension;
73 static const int codimension = codim;
77 typedef typename std::remove_const< Grid >::type::ctype ctype;
78 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
79 typedef ReferenceElement< ctype, dimension > RefElement;
81 static bool apply (
const RefElement &refElement,
82 const Element &element,
int subEntity )
88 template<
int codim,
class Gr
id >
91 static const int dimension = std::remove_const< Grid >::type::dimension;
92 static const int codimension = codim;
96 typedef typename std::remove_const< Grid >::type::ctype ctype;
97 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
98 typedef ReferenceElement< ctype, dimension > RefElement;
100 static bool apply (
const RefElement &refElement,
101 const Element &element,
int subEntity )
106 const int size = refElement.size( subEntity, codim, dimension );
107 for(
int i = 0; i < size; ++i )
109 const int j = refElement.subEntity( subEntity, codim, i, dimension );
110 PartitionType type = element.template subEntity< dimension >( j ).partitionType();
118 template<
int codim,
class Gr
id >
121 static const int dimension = std::remove_const< Grid >::type::dimension;
122 static const int codimension = codim;
126 typedef typename std::remove_const< Grid >::type::ctype ctype;
127 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
128 typedef ReferenceElement< ctype, dimension > RefElement;
130 static bool apply (
const RefElement &refElement,
131 const Element &element,
int subEntity )
137 template<
int codim,
class Gr
id >
140 static const int dimension = std::remove_const< Grid >::type::dimension;
141 static const int codimension = codim;
145 typedef typename std::remove_const< Grid >::type::ctype ctype;
146 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
147 typedef ReferenceElement< ctype, dimension > RefElement;
149 static bool apply (
const RefElement &refElement,
150 const Element &element,
int subEntity )
156 template<
int codim,
class Gr
id >
159 static const int dimension = std::remove_const< Grid >::type::dimension;
160 static const int codimension = codim;
164 typedef typename std::remove_const< Grid >::type::ctype ctype;
165 typedef typename std::remove_const< Grid >::type::Traits::template Codim< 0 >::Entity Element;
166 typedef ReferenceElement< ctype, dimension > RefElement;
168 static bool apply (
const RefElement &refElement,
169 const Element &element,
int subEntity )
171 const int size = refElement.size( subEntity, codim, dimension );
172 for(
int i = 0; i < size; ++i )
174 const int j = refElement.subEntity( subEntity, codim, i, dimension );
175 PartitionType type = element.template subEntity< dimension >( j ).partitionType();
188 template<
class HostGr
idView,
int codim, PartitionIteratorType pitype,
class G >
189 class Iterator< HostGridView, codim, pitype, G, false >
191 typedef typename std::remove_const< G >::type::Traits Traits;
194 typedef typename Traits::Grid Grid;
196 static const int codimension = codim;
198 typedef typename Traits::template Codim< codimension >::Entity Entity;
200 static const bool fake =
false;
203 typedef GeoGrid::Entity< codimension, Traits::dimension, G > EntityImpl;
205 typedef typename HostGridView::template Codim< codim >::template Partition< pitype >::Iterator HostEntityIterator;
208 Iterator () : grid_( nullptr ) {}
210 Iterator (
const Grid &grid, HostEntityIterator hostEntityIterator )
212 hostEntityIterator_(
std::move( hostEntityIterator ) )
217 ++hostEntityIterator_;
220 bool equals (
const Iterator &rhs )
const
222 return hostEntityIterator_ == rhs.hostEntityIterator_;
225 Entity dereference ()
const
227 return EntityImpl( grid(), *hostEntityIterator_ );
230 int level ()
const {
return hostEntityIterator_.level(); }
232 const Grid &grid ()
const
238 static Iterator begin (
const Grid &grid,
const HostGridView &hostGridView )
240 HostEntityIterator hostEntityIterator = hostGridView.template begin< codimension, pitype >();
241 return Iterator( grid, std::move( hostEntityIterator ) );
244 static Iterator end (
const Grid &grid,
const HostGridView &hostGridView )
246 HostEntityIterator hostEntityIterator = hostGridView.template end< codimension, pitype >();
247 return Iterator( grid, std::move( hostEntityIterator ) );
250 operator Dune::DefaultEntityPointer< Entity > ()
const
252 return Dune::DefaultEntityPointer< Entity >( dereference() );
255 bool equals (
const Dune::DefaultEntityPointer< Entity > &rhs )
const
257 return dereference() == rhs.dereference();
262 HostEntityIterator hostEntityIterator_;
270 template<
class HostGr
idView,
int codim, PartitionIteratorType pitype,
class G >
271 class Iterator< HostGridView, codim, pitype, G, true >
273 typedef typename std::remove_const< G >::type::Traits Traits;
276 typedef typename Traits::Grid Grid;
278 static const int codimension = codim;
280 typedef typename Traits::template Codim< codimension >::Entity Entity;
283 typedef GeoGrid::Entity< codimension, Traits::dimension, G > EntityImpl;
285 typedef PartitionIteratorFilter< codim, pitype, typename HostGridView::Grid > Filter;
287 typedef typename HostGridView::template Codim<0>::template Partition< Filter::Element_Partition >::Iterator HostElementIterator;
288 typedef typename HostElementIterator::Entity HostElement;
289 typedef typename HostGridView::IndexSet HostIndexSet;
292 Iterator () : grid_( nullptr ), subEntity_( -1 ), hostIndexSet_( nullptr ) {}
294 Iterator (
const Grid &grid, HostElementIterator hostElementIterator, HostElementIterator hostEnd,
const HostIndexSet &hostIndexSet )
296 hostElementIterator_( hostElementIterator ),
299 hostIndexSet_( &hostIndexSet )
301 if( hostElementIterator_ != hostEnd_ )
303 visited_.resize( hostIndexSet_->size( codimension ),
false );
310 typedef typename Traits::ctype ctype;
312 while( hostElementIterator_ != hostEnd_ )
314 const HostElement &hostElement = *hostElementIterator_;
316 const ReferenceElement< ctype, Traits::dimension > &refElement
320 const int count = refElement.size( codimension );
321 for( ; subEntity_ < count; ++subEntity_ )
323 if( !Filter::apply( refElement, hostElement, subEntity_ ) )
326 const size_t index = hostIndexSet_->subIndex( hostElement, subEntity_, codimension );
327 if( !visited_[ index ] )
329 visited_[ index ] =
true;
333 ++hostElementIterator_;
338 bool equals (
const Iterator &rhs )
const
340 return hostElementIterator_ == rhs.hostElementIterator_ && ( hostElementIterator_ == hostEnd_ || subEntity_ == rhs.subEntity_ );
343 Entity dereference ()
const
345 return EntityImpl( grid(), *hostElementIterator_, subEntity_ );
348 int level ()
const {
return hostElementIterator_.level(); }
350 const Grid &grid ()
const
356 static Iterator begin (
const Grid &grid,
const HostGridView &hostGridView )
358 HostElementIterator first = hostGridView.template begin< 0, Filter::Element_Partition >();
359 HostElementIterator last = hostGridView.template end< 0, Filter::Element_Partition >();
360 return Iterator( grid, std::move( first ), std::move( last ), hostGridView.indexSet() );
363 static Iterator end (
const Grid &grid,
const HostGridView &hostGridView )
365 HostElementIterator last = hostGridView.template end< 0, Filter::Element_Partition >();
366 return Iterator( grid, last, last, hostGridView.indexSet() );
369 operator Dune::DefaultEntityPointer< Entity > ()
const
371 return Dune::DefaultEntityPointer< Entity >( dereference() );
374 bool equals (
const Dune::DefaultEntityPointer< Entity > &rhs )
const
376 return dereference() == rhs.dereference();
381 HostElementIterator hostElementIterator_, hostEnd_;
383 const HostIndexSet *hostIndexSet_;
384 std::vector< bool > visited_;
393 class HierarchicIterator
395 typedef typename std::remove_const< G >::type::Traits Traits;
398 typedef typename Traits::Grid Grid;
400 static const int codimension = 0;
402 typedef typename Traits::template Codim< codimension >::Entity Entity;
405 typedef GeoGrid::Entity< codimension, Traits::dimension, G > EntityImpl;
407 typedef typename Grid::HostGrid::HierarchicIterator HostEntityIterator;
410 HierarchicIterator () : grid_( nullptr ) {}
412 HierarchicIterator (
const Grid &grid, HostEntityIterator hostEntityIterator )
414 hostEntityIterator_(
std::move( hostEntityIterator ) )
419 ++hostEntityIterator_;
422 bool equals (
const HierarchicIterator &rhs )
const
424 return hostEntityIterator_ == rhs.hostEntityIterator_;
427 Entity dereference ()
const
429 return EntityImpl( grid(), *hostEntityIterator_ );
432 int level ()
const {
return hostEntityIterator_.level(); }
434 const Grid &grid ()
const
440 operator Dune::DefaultEntityPointer< Entity > ()
const
442 return Dune::DefaultEntityPointer< Entity >( dereference() );
445 bool equals (
const Dune::DefaultEntityPointer< Entity > &rhs )
const
447 return dereference() == rhs.dereference();
452 HostEntityIterator hostEntityIterator_;
Wrapper and interface class for a static iterator (EntityPointer)
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:441
Dune namespace.
Definition: alignment.hh:11
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:758