1#ifndef DUNE_SPGRID_HIERARCHICSEARCH_HH
2#define DUNE_SPGRID_HIERARCHICSEARCH_HH
8#include <dune/grid/common/gridenums.hh>
10#include <dune/grid/spgrid/declaration.hh>
11#include <dune/grid/spgrid/entity.hh>
12#include <dune/grid/spgrid/refinement.hh>
20 template<
class Gr
id >
23 template<
class Gr
id,
class IndexSet >
24 class HierarchicSearch;
31 template<
class Gr
id >
32 class SPBasicHierarchicSearch
36 typedef typename Grid::template Codim< 0 >::Entity Entity;
42 SPBasicHierarchicSearch (
const Grid &grid )
46 Entity findEntity (
const GlobalVector &global,
int level )
const
48 typedef SPEntity< 0, dimension, const Grid > EntityImpl;
49 typedef typename Grid::GridLevel GridLevel;
50 typedef typename GridLevel::PartitionList PartitionList;
52 assert( grid_.domain().contains( global ) );
53 const GridLevel &gridLevel = grid_.gridLevel( level );
54 const PartitionList &partitionList = gridLevel.template partition< All_Partition >();
56 const GlobalVector y = global - grid_.domain().cube().origin();
58 SPDirectionIterator< dimension, 0 > dirIt;
59 gridLevel.template geometryCache< 0 >( *dirIt ).jacobianInverseTransposed().mv( y, z );
61 typename GridLevel::MultiIndex id;
62 for(
int i = 0; i < dimension; ++i )
63 id[ i ] = 2*
int( z[ i ] ) + 1;
65 const typename PartitionList::Partition *partition = partitionList.findPartition(
id );
67 return Entity( EntityImpl( gridLevel,
id, partition->number() ) );
70 for(
int i = 0; i < dimension; ++i )
73 if(
id[ i ] - 1 == 2*gridLevel.localMesh().bound( 1 )[ i ] )
74 id[ i ] = 2*int( z[ i ] ) - 1;
76 const typename PartitionList::Partition *leftPartition = partitionList.findPartition(
id );
79 return Entity( EntityImpl( gridLevel,
id, leftPartition->number() ) );
81 DUNE_THROW( GridError,
"Coordinate " << global <<
" is outside the grid." );
94 template<
class Gr
id,
class IndexSet >
95 class SPHierarchicSearch
96 :
protected SPBasicHierarchicSearch< Grid >
98 typedef SPBasicHierarchicSearch< Grid > Base;
101 typedef typename Base::ctype ctype;
102 typedef typename Base::Entity Entity;
104 using Base::dimension;
106 typedef typename Base::GlobalVector GlobalVector;
108 SPHierarchicSearch (
const Grid &grid,
const IndexSet &indexSet )
110 indexSet_( indexSet )
113 Entity findEntity (
const GlobalVector &global )
const
115 const Entity e = Base::findEntity( global, 0 );
116 return (indexSet_.contains( e ) ? e : hFindEntity( e, global ));
120 typedef GlobalVector LocalVector;
121 typedef typename Entity::HierarchicIterator HierarchicIterator;
123 Entity hFindEntity (
const Entity &e,
const GlobalVector &global )
const
126 const HierarchicIterator end = e.hend( e.level()+1 );
127 for( HierarchicIterator it = e.hbegin( e.level()+1 ); it != end; ++it )
129 const Entity &
child = *it;
130 LocalVector local =
child.geometry().local( global );
132 return (indexSet_.contains(
child ) ?
child : hFindEntity(
child, global ));
134 DUNE_THROW( Exception,
"Unexpected internal Error" );
141 const IndexSet &indexSet_;
149 template<
class Gr
id >
150 class SPHierarchicSearch< Grid, SPIndexSet< Grid > >
151 :
protected SPBasicHierarchicSearch< Grid >
153 typedef SPBasicHierarchicSearch< Grid > Base;
154 typedef SPIndexSet< Grid > IndexSet;
157 typedef typename Base::Entity Entity;
159 typedef typename Base::GlobalVector GlobalVector;
161 SPHierarchicSearch (
const Grid &grid,
const IndexSet &indexSet )
163 indexSet_( indexSet )
166 Entity findEntity (
const GlobalVector &global )
const
168 return Base::findEntity( global, indexSet_.gridLevel().level() );
172 const IndexSet &indexSet_;
180 template<
class Gr
id >
181 class SPHierarchicSearch< Grid, IndexSet< Grid, SPIndexSet< Grid >, typename SPIndexSet< Grid >::IndexType > >
182 :
public SPHierarchicSearch< Grid, SPIndexSet< Grid > >
184 typedef SPHierarchicSearch< Grid, SPIndexSet< Grid > > Base;
188 SPHierarchicSearch (
const Grid &grid,
const IndexSet &indexSet )
189 : Base( grid, static_cast< const SPIndexSet< Grid > & >( indexSet ) )
198 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm,
class IndexSet >
199 class HierarchicSearch< SPGrid< ct, dim, Ref, Comm >, IndexSet >
200 :
public SPHierarchicSearch< SPGrid< ct, dim, Ref, Comm >, IndexSet >
202 typedef SPHierarchicSearch< SPGrid< ct, dim, Ref, Comm >, IndexSet > Base;
203 typedef SPGrid< ct, dim, Ref, Comm > Grid;
206 typedef typename Base::Entity Entity;
207 typedef typename Base::GlobalVector GlobalVector;
210 : Base( grid, indexSet )
213 Entity
findEntity (
const GlobalVector &global )
const
215 return Base::findEntity( global );
218 template< PartitionIteratorType pitype >
219 Entity
findEntity (
const GlobalVector &global )
const
221 const Entity entity = Base::findEntity( global );
222 if( !contains< pitype >( entity.partitionType() ) )
223 DUNE_THROW( GridError,
"Coordinate " << global <<
" does not belong to partition " << pitype );
228 template< PartitionIteratorType pitype >
252 DUNE_THROW( InvalidStateException,
"wrong PartitionIteratorType: " << pitype <<
"." );
static constexpr int dimension
The dimension of the grid.
Definition: grid.hh:387
ct ctype
Define type used for coordinates in grid module.
Definition: grid.hh:532
Entity findEntity(const FieldVector< ct, dimw > &global) const
Search the IndexSet of this HierarchicSearch for an Entity containing point global.
Definition: hierarchicsearch.hh:127
HierarchicSearch(const Grid &g, const IS &is)
Construct a HierarchicSearch object from a Grid and an IndexSet.
Definition: hierarchicsearch.hh:118
Index Set Interface base class.
Definition: indexidset.hh:78
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Provides base classes for index and id sets.
Dune namespace.
Definition: alignedallocator.hh:13
static const ReferenceElement & cube()
get hypercube reference elements
Definition: referenceelements.hh:210