4 #ifndef DUNE_GRID_HIERARCHICSEARCH_HH
5 #define DUNE_GRID_HIERARCHICSEARCH_HH
17 #include <dune/common/classname.hh>
18 #include <dune/common/exceptions.hh>
19 #include <dune/common/fvector.hh>
30 template<
class Gr
id,
class IS>
43 typedef typename Grid::template Codim<0>::Entity Entity;
46 typedef typename Grid::template Codim<0>::EntityPointer EntityPointer;
51 static std::string formatEntityInformation (
const Entity &e ) {
53 std::ostringstream info;
54 info <<
"level=" << e.level() <<
" "
55 <<
"partition=" << e.partitionType() <<
" "
56 <<
"center=(" << geo.center() <<
") "
57 <<
"corners=[(" << geo.corner(0) <<
")";
58 for(
int i = 1; i < geo.corners(); ++i)
59 info <<
" (" << e.geometry().corner(i) <<
")";
74 EntityPointer hFindEntity (
const Entity &e,
75 const FieldVector<ct,dimw>& global)
const
78 const HierarchicIterator end = e.hend(e.level()+1);
79 for( HierarchicIterator it = e.hbegin( e.level()+1 ); it != end; ++it )
81 FieldVector<ct,dim> local = it->geometry().local(global);
82 if (GenericReferenceElements<double, dim>::general(it->type()).checkInside(local))
85 if( is.contains( *it ) )
86 return EntityPointer( it );
88 return hFindEntity( *it, global );
91 std::ostringstream children;
92 HierarchicIterator it = e.hbegin( e.level()+1 );
94 children <<
"{" << formatEntityInformation(*it) <<
"}";
95 for( ++it; it != end; ++it )
96 children <<
" {" << formatEntityInformation(*it) <<
"}";
98 DUNE_THROW(Exception,
"{" << className(*
this) <<
"} Unexpected "
99 "internal Error: none of the children of the entity "
100 "{" << formatEntityInformation(e) <<
"} contains "
101 "coordinate (" << global <<
"). Children are: "
102 "[" << children.str() <<
"].");
118 EntityPointer
findEntity(
const FieldVector<ct,dimw>& global)
const
119 {
return findEntity<All_Partition>(global); }
128 template<PartitionIteratorType partition>
129 EntityPointer
findEntity(
const FieldVector<ct,dimw>& global)
const
131 typedef typename Grid::template Partition<partition>::LevelGridView
133 const LevelGV &gv = g.template levelView<partition>(0);
136 typedef typename LevelGV::template Codim<0>::Iterator
LevelIterator;
139 LevelIterator it = gv.template begin<0>();
140 LevelIterator end = gv.template end<0>();
141 for (; it != end; ++it)
143 const Entity &e = *it;
146 FieldVector< ct, dim > local = geo.local( global );
147 if( !GenericReferenceElements< double, dim >::general( geo.type() ).checkInside( local ) )
150 if( (
int(dim) != int(dimw)) && ((geo.global( local ) - global).two_norm() > 1e-8) )
154 if( is.contains( *it ) )
155 return EntityPointer( it );
157 return hFindEntity( *it, global );
159 DUNE_THROW(
GridError,
"Coordinate " << global <<
" is outside the grid." );
169 #endif // DUNE_GRID_HIERARCHICSEARCH_HH