1#ifndef DUNE_FEM_GRIDPART_ENTITYSEARCH_HH
2#define DUNE_FEM_GRIDPART_ENTITYSEARCH_HH
6#include <dune/geometry/referenceelements.hh>
8#include <dune/grid/common/gridenums.hh>
9#include <dune/grid/common/exceptions.hh>
12#include <dune/fem/gridpart/common/capabilities.hh>
23 template<
class Gr
idPart,
int codim, PartitionIteratorType partition >
24 class DefaultEntitySearch
26 typedef DefaultEntitySearch< GridPart, codim, partition > ThisType;
28 static const int dimension = GridPart::dimension;
29 static const int dimensionworld = GridPart::dimensionworld;
30 static const int codimension = codim;
31 static const int mydimension = dimension - codimension;
33 typedef typename GridPart::template Codim< codimension >::GeometryType
GeometryType;
34 typedef typename GridPart::template Codim< codimension >::template Partition< partition >::IteratorType IteratorType;
36 typedef typename GeometryType::ctype ctype;
37 typedef typename GeometryType::LocalCoordinate LocalCoordinateType;
40 typedef GridPart GridPartType;
42 typedef typename GridPart::template Codim< codimension >::EntityType EntityType;
44 typedef typename GeometryType::GlobalCoordinate GlobalCoordinateType;
46 explicit DefaultEntitySearch (
const GridPartType &gridPart )
47 : gridPart_( gridPart )
50 EntityType operator() (
const GlobalCoordinateType &x )
const
52 const auto end = gridPart_.template end< codimension, partition >();
53 for(
auto it = gridPart_.template begin< codimension, partition >(); it != end; ++it )
55 const auto& entity = *it;
56 const auto geo = entity.geometry();
57 const auto z = geo.local( x );
58 if( (mydimension < dimensionworld) && ((geo.global( z ) - x).two_norm() > 1e-8 ) )
61 if( referenceElement<ctype,mydimension>( geo.type() ).checkInside( z ) )
64 DUNE_THROW( GridError,
"Coordinate " << x <<
" is outside the grid." );
68 const GridPartType &gridPart_;
76 template<
class Gr
idPart,
int codim, PartitionIteratorType partition >
77 class GridEntitySearch
78 :
public DefaultEntitySearch< GridPart, codim, partition >
80 typedef GridEntitySearch< GridPart, codim, partition > ThisType;
81 typedef DefaultEntitySearch< GridPart, codim, partition > BaseType;
84 typedef typename BaseType::GridPartType GridPartType;
86 explicit GridEntitySearch (
const GridPartType &gridPart )
87 : BaseType( gridPart )
91 template<
class Gr
idPart, PartitionIteratorType partition >
92 class GridEntitySearch< GridPart, 0, partition >
94 typedef GridEntitySearch< GridPart, 0, partition > ThisType;
96 static const int dimension = GridPart::dimension;
97 static const int dimensionworld = GridPart::dimensionworld;
98 static const int codimension = 0;
99 static const int mydimension = dimension - codimension;
101 typedef typename GridPart::template Codim< codimension >::GeometryType
GeometryType;
104 typedef GridPart GridPartType;
106 typedef typename GridPart::template Codim< codimension >::EntityType EntityType;
108 typedef typename GeometryType::GlobalCoordinate GlobalCoordinateType;
110 explicit GridEntitySearch (
const GridPartType &gridPart )
111 : hierarchicSearch_( gridPart.grid(), gridPart.indexSet() )
114 EntityType operator() (
const GlobalCoordinateType &x )
const
116 return hierarchicSearch_.template findEntity< partition >( x );
128 template<
class Gr
idPart,
int codim = 0, PartitionIteratorType partition = All_Partition >
130 :
public std::conditional< GridPartCapabilities::hasGrid< GridPart >::v, GridEntitySearch< GridPart, codim, partition >, DefaultEntitySearch< GridPart, codim, partition > >::type
132 typedef EntitySearch< GridPart, codim, partition > ThisType;
133 typedef typename std::conditional< GridPartCapabilities::hasGrid< GridPart >::v, GridEntitySearch< GridPart, codim, partition >, DefaultEntitySearch< GridPart, codim, partition > >::type BaseType;
136 typedef typename BaseType::GridPartType GridPartType;
138 explicit EntitySearch (
const GridPartType &gridPart )
139 : BaseType( gridPart )
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Utility class for hierarchically searching for an Entity containing a given point.
Dune namespace.
Definition: alignedallocator.hh:13