DUNE-FEM (unstable)

entitysearch.hh
1#ifndef DUNE_FEM_GRIDPART_ENTITYSEARCH_HH
2#define DUNE_FEM_GRIDPART_ENTITYSEARCH_HH
3
4#include <type_traits>
5
6#include <dune/geometry/referenceelements.hh>
7
8#include <dune/grid/common/gridenums.hh>
9#include <dune/grid/common/exceptions.hh>
11
12#include <dune/fem/gridpart/common/capabilities.hh>
13
14namespace Dune
15{
16
17 namespace Fem
18 {
19
20 // DefaultEntitySearch
21 // -------------------
22
23 template< class GridPart, int codim, PartitionIteratorType partition >
24 class DefaultEntitySearch
25 {
26 typedef DefaultEntitySearch< GridPart, codim, partition > ThisType;
27
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;
32
33 typedef typename GridPart::template Codim< codimension >::GeometryType GeometryType;
34 typedef typename GridPart::template Codim< codimension >::template Partition< partition >::IteratorType IteratorType;
35
36 typedef typename GeometryType::ctype ctype;
37 typedef typename GeometryType::LocalCoordinate LocalCoordinateType;
38
39 public:
40 typedef GridPart GridPartType;
41
42 typedef typename GridPart::template Codim< codimension >::EntityType EntityType;
43
44 typedef typename GeometryType::GlobalCoordinate GlobalCoordinateType;
45
46 explicit DefaultEntitySearch ( const GridPartType &gridPart )
47 : gridPart_( gridPart )
48 {}
49
50 EntityType operator() ( const GlobalCoordinateType &x ) const
51 {
52 const auto end = gridPart_.template end< codimension, partition >();
53 for( auto it = gridPart_.template begin< codimension, partition >(); it != end; ++it )
54 {
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 ) )
59 continue;
60
61 if( referenceElement<ctype,mydimension>( geo.type() ).checkInside( z ) )
62 return entity;
63 }
64 DUNE_THROW( GridError, "Coordinate " << x << " is outside the grid." );
65 }
66
67 private:
68 const GridPartType &gridPart_;
69 };
70
71
72
73 // GridEntitySearch
74 // ----------------
75
76 template< class GridPart, int codim, PartitionIteratorType partition >
77 class GridEntitySearch
78 : public DefaultEntitySearch< GridPart, codim, partition >
79 {
80 typedef GridEntitySearch< GridPart, codim, partition > ThisType;
81 typedef DefaultEntitySearch< GridPart, codim, partition > BaseType;
82
83 public:
84 typedef typename BaseType::GridPartType GridPartType;
85
86 explicit GridEntitySearch ( const GridPartType &gridPart )
87 : BaseType( gridPart )
88 {}
89 };
90
91 template< class GridPart, PartitionIteratorType partition >
92 class GridEntitySearch< GridPart, 0, partition >
93 {
94 typedef GridEntitySearch< GridPart, 0, partition > ThisType;
95
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;
100
101 typedef typename GridPart::template Codim< codimension >::GeometryType GeometryType;
102
103 public:
104 typedef GridPart GridPartType;
105
106 typedef typename GridPart::template Codim< codimension >::EntityType EntityType;
107
108 typedef typename GeometryType::GlobalCoordinate GlobalCoordinateType;
109
110 explicit GridEntitySearch ( const GridPartType &gridPart )
111 : hierarchicSearch_( gridPart.grid(), gridPart.indexSet() )
112 {}
113
114 EntityType operator() ( const GlobalCoordinateType &x ) const
115 {
116 return hierarchicSearch_.template findEntity< partition >( x );
117 }
118
119 private:
121 };
122
123
124
125 // EntitySearch
126 // ------------
127
128 template< class GridPart, int codim = 0, PartitionIteratorType partition = All_Partition >
129 class EntitySearch
130 : public std::conditional< GridPartCapabilities::hasGrid< GridPart >::v, GridEntitySearch< GridPart, codim, partition >, DefaultEntitySearch< GridPart, codim, partition > >::type
131 {
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;
134
135 public:
136 typedef typename BaseType::GridPartType GridPartType;
137
138 explicit EntitySearch ( const GridPartType &gridPart )
139 : BaseType( gridPart )
140 {}
141 };
142
143 } // namespace Fem
144
145} // namespace Dune
146
147#endif // #ifndef DUNE_FEM_GRIDPART_ENTITYSEARCH_HH
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)