00001 #ifndef DUNE_GRID_HIERARCHICSEARCH_HH
00002 #define DUNE_GRID_HIERARCHICSEARCH_HH
00003
00010 #include <dune/common/fvector.hh>
00011 #include <dune/grid/common/grid.hh>
00012
00013 namespace Dune
00014 {
00015
00019 template<class Grid, class IS>
00020 class HierarchicSearch
00021 {
00023 enum {dim=Grid::dimension};
00024
00026 enum {dimw=Grid::dimensionworld};
00027
00029 typedef typename Grid::ctype ct;
00030
00032 typedef typename Grid::template Codim<0>::Entity Entity;
00033
00035 typedef typename Grid::template Codim<0>::EntityPointer EntityPointer;
00036
00038 typedef typename Grid::template Codim<0>::LevelIterator LevelIterator;
00039
00041 typedef typename Grid::template Codim<0>::HierarchicIterator HierarchicIterator;
00042
00053 EntityPointer hFindEntity(const EntityPointer e,
00054 const FieldVector<ct,dimw>& global) const
00055 {
00056
00057 HierarchicIterator it = e->hbegin(e->level()+1);
00058 HierarchicIterator end = e->hend(e->level()+1);
00059 for (; it != end; ++it)
00060 {
00061 FieldVector<ct,dim> local = it->geometry().local(global);
00062 if (it->geometry().checkInside(local))
00063 {
00064
00065 if (is.contains(*it)) return it;
00066
00067 else return hFindEntity(it, global);
00068 }
00069 }
00070 DUNE_THROW(Exception, "Unexpected internal Error");
00071 }
00072
00073 public:
00077 HierarchicSearch(const Grid & _g, const IS & _is) : g(_g), is(_is) {};
00078
00083 EntityPointer findEntity(const FieldVector<ct,dimw>& global) const
00084 {
00085
00086 LevelIterator it = g.template lbegin<0>(0);
00087 LevelIterator end = g.template lend<0>(0);
00088 for (; it != end; ++it)
00089 {
00090 FieldVector<ct,dim> local = it->geometry().local(global);
00091 if (it->geometry().checkInside(local))
00092 {
00093
00094 if (is.contains(*it)) return it;
00095
00096 else return hFindEntity(it, global);
00097 }
00098 }
00099 DUNE_THROW(GridError,
00100 "Coordinate " << global << " is outside the grid");
00101 }
00102
00103 private:
00104 const Grid& g;
00105 const IS& is;
00106 };
00107
00108 };
00109
00110 #endif // DUNE_GRID_HIERARCHICSEARCH_HH
00111