1#ifndef DUNE_GRID_SPGRID_TREE_HH
2#define DUNE_GRID_SPGRID_TREE_HH
6#include <dune/grid/common/entity.hh>
7#include <dune/grid/common/entityiterator.hh>
8#include <dune/grid/common/intersection.hh>
9#include <dune/grid/common/intersectioniterator.hh>
11#include <dune/grid/spgrid/declaration.hh>
12#include <dune/grid/spgrid/entityinfo.hh>
13#include <dune/grid/spgrid/entity.hh>
14#include <dune/grid/spgrid/intersection.hh>
22 template<
int codim,
class Gr
id,
class IsLeaf >
25 template<
class Gr
id,
class IsLeaf >
26 class IntersectionTree;
36 template<
class,
class >
44 template<
int codim,
int dim,
class Gr
id,
template<
int,
int,
class >
class EImpl,
class IsLeaf >
45 class TreeIterator<
Dune::Entity< codim, dim, Grid, EImpl >, IsLeaf >
47 typedef TreeIterator< Dune::Entity< codim, dim, Grid, EImpl >, IsLeaf > This;
50 typedef typename std::remove_const< Grid >::type::Traits Traits;
52 static const int dimension = Traits::ReferenceCube::dimension;
53 static const int codimension = codim;
54 static const int mydimension = dimension - codimension;
56 typedef typename Traits::template Codim< codimension >::Entity Entity;
59 typedef EImpl< codimension, dimension, Grid > EntityImpl;
62 typedef typename EntityImpl::EntityInfo EntityInfo;
63 typedef typename EntityImpl::GridLevel GridLevel;
65 TreeIterator () =
default;
67 explicit TreeIterator (
const IsLeaf &isLeaf ) : isLeaf_( isLeaf ) {}
69 explicit TreeIterator (
const Entity &entity,
const IsLeaf &isLeaf )
70 : entityInfo_( entity.impl().entityInfo() ),
71 rootLevel_( &gridLevel() ),
75 Entity dereference ()
const {
return EntityImpl( entityInfo() ); }
77 bool equals (
const This &other )
const {
return entityInfo().equals( other.entityInfo() ); }
81 if( isLeaf_( dereference() ) || (&gridLevel() == &leafLevel()) )
85 if( entityInfo().nextChild() )
89 entityInfo() = EntityInfo();
95 const EntityInfo &entityInfo ()
const {
return entityInfo_; }
96 EntityInfo &entityInfo () {
return entityInfo_; }
98 const GridLevel &gridLevel ()
const {
return entityInfo().gridLevel(); }
101 const GridLevel &leafLevel ()
const {
return gridLevel().grid().leafLevel(); }
103 bool isDone ()
const {
return (&gridLevel() == rootLevel_); }
105 EntityInfo entityInfo_;
106 const GridLevel *rootLevel_ =
nullptr;
115 template<
class Gr
id,
class IntersectionImpl,
class IsLeaf >
116 class TreeIterator<
Dune::Intersection< Grid, IntersectionImpl >, IsLeaf >
118 typedef TreeIterator< Dune::Intersection< Grid, IntersectionImpl >, IsLeaf > This;
123 static const int dimension = Intersection::dimension;
124 static const int codimension = Intersection::codimension;
127 typedef typename IntersectionImpl::EntityInfo EntityInfo;
128 typedef typename IntersectionImpl::ElementInfo ElementInfo;
129 typedef typename IntersectionImpl::GridLevel GridLevel;
131 TreeIterator () =
default;
133 explicit TreeIterator (
int face,
const IsLeaf &isLeaf )
134 : intersection_( IntersectionImpl( ElementInfo(), face ) )
137 explicit TreeIterator (
const Intersection &intersection,
const IsLeaf &isLeaf )
138 : intersection_( intersection ),
139 rootLevel_( &intersection.impl().gridLevel() ),
143 TreeIterator (
const This & ) =
default;
144 TreeIterator ( This && ) =
default;
146 This &operator= (
const This & ) =
default;
147 This &operator= ( This && ) =
default;
149 const Intersection &dereference ()
const {
return intersection_; }
151 bool equals (
const This &other )
const
153 return intersection_.impl().equals( other.intersection_.impl() );
158 if( isLeaf_( intersection_ ) || (&gridLevel() == &leafLevel()) )
160 EntityInfo info = entityInfo();
161 while( !isDone( info ) )
163 if( info.nextChild() )
165 intersection_.impl().setEntityInfo( info );
170 intersection_.impl().setInside( ElementInfo() );
174 EntityInfo info = entityInfo();
176 intersection_.impl().setEntityInfo( info );
181 EntityInfo entityInfo ()
const {
return intersection_.impl().entityInfo(); }
183 const GridLevel &gridLevel ()
const {
return entityInfo().gridLevel(); }
184 const GridLevel &leafLevel ()
const {
return gridLevel().grid().leafLevel(); }
186 bool isDone (
const EntityInfo &entityInfo )
const {
return (&entityInfo.gridLevel() == rootLevel_); }
188 Intersection intersection_;
189 const GridLevel *rootLevel_;
200 template<
int codim,
class ct,
int dim,
template<
int >
class Ref,
class Comm,
class IsLeaf >
201 class EntityTree< codim, SPGrid< ct, dim, Ref, Comm >, IsLeaf >
204 typedef SPGrid< ct, dim, Ref, Comm > Grid;
209 EntityTree (
const Grid &grid,
const Entity &entity,
const IsLeaf &isLeaf )
210 : entity_( entity ), isLeaf_( isLeaf )
213 Iterator begin ()
const {
return __SPGrid::TreeIterator< Entity, IsLeaf >( entity_, isLeaf_ ); }
214 Iterator end ()
const {
return __SPGrid::TreeIterator< Entity, IsLeaf >( isLeaf_ ); }
216 bool empty ()
const {
return false; }
228 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm,
class IsLeaf >
229 class IntersectionTree< SPGrid< ct, dim, Ref, Comm >, IsLeaf >
232 typedef SPGrid< ct, dim, Ref, Comm > Grid;
237 IntersectionTree (
const Grid &grid,
const Intersection &intersection,
const IsLeaf &isLeaf )
238 : intersection_( intersection ), isLeaf_( isLeaf )
241 Iterator begin ()
const {
return __SPGrid::TreeIterator< Intersection, IsLeaf >( intersection_, isLeaf_ ); }
242 Iterator end ()
const {
return __SPGrid::TreeIterator< Intersection, IsLeaf >( intersection_.indexInInside(), isLeaf_ ); }
244 bool empty ()
const {
return false; }
247 Intersection intersection_;
interface class for an iterator over grid entities
Definition: entityiterator.hh:32
Mesh entities of codimension 0 ("elements") allow to visit all intersections with "neighboring" eleme...
Definition: intersectioniterator.hh:83
static constexpr int mydimension
dimension of the intersection
Definition: intersection.hh:207
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:402
Dune namespace.
Definition: alignedallocator.hh:13