4 #ifndef DUNE_GRID_HIERARCHICSEARCH_HH
5 #define DUNE_GRID_HIERARCHICSEARCH_HH
18 #include <dune/common/classname.hh>
19 #include <dune/common/exceptions.hh>
20 #include <dune/common/fvector.hh>
31 template<
class Gr
id,
class IS>
44 typedef typename Grid::template Codim<0>::Entity Entity;
47 typedef typename Grid::template Codim<0>::EntityPointer EntityPointer;
52 static std::string formatEntityInformation (
const Entity &e ) {
54 std::ostringstream
info;
55 info <<
"level=" << e.level() <<
" "
56 <<
"partition=" << e.partitionType() <<
" "
57 <<
"center=(" << geo.center() <<
") "
58 <<
"corners=[(" << geo.corner(0) <<
")";
59 for(
int i = 1; i < geo.corners(); ++i)
60 info <<
" (" << e.geometry().corner(i) <<
")";
75 Entity hFindEntity (
const Entity &entity,
76 const FieldVector<ct,dimw>& global)
const
83 const int childLevel = entity.level()+1 ;
85 const HierarchicIterator end = entity.hend( childLevel );
86 for( HierarchicIterator it = entity.hbegin( childLevel ); it != end; ++it )
89 const Geometry &geo = child.geometry();
91 LocalCoordinate local = geo.
local(global);
92 if (ReferenceElements<double, dim>::general( child.type() ).checkInside(local))
95 if( indexSet_.contains( child ) )
98 return hFindEntity( child, global );
101 std::ostringstream children;
102 HierarchicIterator it = entity.hbegin( childLevel );
104 children <<
"{" << formatEntityInformation(*it) <<
"}";
105 for( ++it; it != end; ++it )
106 children <<
" {" << formatEntityInformation(*it) <<
"}";
108 DUNE_THROW(Exception,
"{" << className(*
this) <<
"} Unexpected "
109 "internal Error: none of the children of the entity "
110 "{" << formatEntityInformation(entity) <<
"} contains "
111 "coordinate (" << global <<
"). Children are: "
112 "[" << children.str() <<
"].");
129 {
return findEntity<All_Partition>(global); }
138 template<PartitionIteratorType partition>
142 const LevelGV &gv = grid_.template levelGridView(0);
145 typedef typename LevelGV::template Codim<0>::template Partition<partition>::Iterator LevelIterator;
153 const LevelIterator end = gv.template end<0, partition>();
154 for (LevelIterator it = gv.template begin<0, partition>(); it != end; ++it)
157 const Geometry &geo = entity.geometry();
159 LocalCoordinate local = geo.
local( global );
160 if( !ReferenceElements< double, dim >::general( geo.
type() ).checkInside( local ) )
163 if( (
int(dim) != int(dimw)) && ((geo.
global( local ) - global).two_norm() > 1e-8) )
167 if( indexSet_.contains( entity ) )
170 return hFindEntity( entity, global );
172 DUNE_THROW(
GridError,
"Coordinate " << global <<
" is outside the grid." );
182 #endif // DUNE_GRID_HIERARCHICSEARCH_HH
The dimension of the world the grid lives in.
Definition: common/grid.hh:408
Search an IndexSet for an Entity containing a given point.
Definition: hierarchicsearch.hh:32
GridImp::template Codim< cd >::Geometry Geometry
The corresponding geometry type.
Definition: common/entity.hh:97
LocalCoordinate local(const GlobalCoordinate &global) const
Evaluate the inverse map .
Definition: common/geometry.hh:174
FieldVector< ctype, mydim > LocalCoordinate
type of local coordinates
Definition: common/geometry.hh:101
Partition< All_Partition >::LevelGridView LevelGridView
View types for All_Partition.
Definition: common/grid.hh:428
static void(*)(*)(*)(*)(*)(*) move(const double *)
Definition: partitiondisplay.cc:122
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
Different resources needed by all grid implementations.
Wrapper class for geometries.
Definition: common/geometry.hh:65
Definition: grapecommon.hh:49
Entity findEntity(const FieldVector< ct, dimw > &global) const
Search the IndexSet of this HierarchicSearch for an Entity containing point global.
Definition: hierarchicsearch.hh:128
Entity findEntity(const FieldVector< ct, dimw > &global) const
Search the IndexSet of this HierarchicSearch for an Entity containing point global.
Definition: hierarchicsearch.hh:139
HierarchicSearch(const Grid &g, const IS &is)
Construct a HierarchicSearch object from a Grid and an IndexSet.
Definition: hierarchicsearch.hh:119
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:388
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: common/geometry.hh:131
The dimension of the grid.
Definition: common/grid.hh:402
ct ctype
Define type used for coordinates in grid module.
Definition: common/grid.hh:548
Include standard header files.
Definition: agrid.hh:59
GridFamily::Traits::HierarchicIterator HierarchicIterator
A type that is a model of Dune::HierarchicIterator A type of iterator that allows to examine...
Definition: common/grid.hh:512
GlobalCoordinate global(const LocalCoordinate &local) const
Evaluate the map .
Definition: common/geometry.hh:165