Dune Core Modules (2.9.0)

hierarchicsearch.hh
1#ifndef DUNE_SPGRID_HIERARCHICSEARCH_HH
2#define DUNE_SPGRID_HIERARCHICSEARCH_HH
3
6
8#include <dune/grid/common/gridenums.hh>
9
10#include <dune/grid/spgrid/declaration.hh>
11#include <dune/grid/spgrid/entity.hh>
12#include <dune/grid/spgrid/refinement.hh>
13
14namespace Dune
15{
16
17 // External Forward Declarations
18 // -----------------------------
19
20 template< class Grid >
21 class SPIndexSet;
22
23 template< class Grid, class IndexSet >
24 class HierarchicSearch;
25
26
27
28 // SPBasicHierarchicSearch
29 // -----------------------
30
31 template< class Grid >
32 class SPBasicHierarchicSearch
33 {
34 public:
35 typedef typename Grid::ctype ctype;
36 typedef typename Grid::template Codim< 0 >::Entity Entity;
37
38 static const int dimension = Grid::dimension;
39
40 typedef FieldVector< ctype, dimension > GlobalVector;
41
42 SPBasicHierarchicSearch ( const Grid &grid )
43 : grid_( grid )
44 {}
45
46 Entity findEntity ( const GlobalVector &global, int level ) const
47 {
48 typedef SPEntity< 0, dimension, const Grid > EntityImpl;
49 typedef typename Grid::GridLevel GridLevel;
50 typedef typename GridLevel::PartitionList PartitionList;
51
52 assert( grid_.domain().contains( global ) );
53 const GridLevel &gridLevel = grid_.gridLevel( level );
54 const PartitionList &partitionList = gridLevel.template partition< All_Partition >();
55
56 const GlobalVector y = global - grid_.domain().cube().origin();
57 GlobalVector z;
58 SPDirectionIterator< dimension, 0 > dirIt;
59 gridLevel.template geometryCache< 0 >( *dirIt ).jacobianInverseTransposed().mv( y, z );
60
61 typename GridLevel::MultiIndex id;
62 for( int i = 0; i < dimension; ++i )
63 id[ i ] = 2*int( z[ i ] ) + 1;
64
65 const typename PartitionList::Partition *partition = partitionList.findPartition( id );
66 if( partition )
67 return Entity( EntityImpl( gridLevel, id, partition->number() ) );
68 else
69 {
70 for( int i = 0; i < dimension; ++i )
71 {
72 // check upper bound
73 if( id[ i ] - 1 == 2*gridLevel.localMesh().bound( 1 )[ i ] )
74 id[ i ] = 2*int( z[ i ] ) - 1;
75 }
76 const typename PartitionList::Partition *leftPartition = partitionList.findPartition( id );
77
78 if( leftPartition )
79 return Entity( EntityImpl( gridLevel, id, leftPartition->number() ) );
80 else
81 DUNE_THROW( GridError, "Coordinate " << global << " is outside the grid." );
82 }
83 }
84
85 protected:
86 const Grid &grid_;
87 };
88
89
90
91 // SPHierarchicSearch
92 // ------------------
93
94 template< class Grid, class IndexSet >
95 class SPHierarchicSearch
96 : protected SPBasicHierarchicSearch< Grid >
97 {
98 typedef SPBasicHierarchicSearch< Grid > Base;
99
100 public:
101 typedef typename Base::ctype ctype;
102 typedef typename Base::Entity Entity;
103
104 using Base::dimension;
105
106 typedef typename Base::GlobalVector GlobalVector;
107
108 SPHierarchicSearch ( const Grid &grid, const IndexSet &indexSet )
109 : Base( grid ),
110 indexSet_( indexSet )
111 {}
112
113 Entity findEntity ( const GlobalVector &global ) const
114 {
115 const Entity e = Base::findEntity( global, 0 );
116 return (indexSet_.contains( e ) ? e : hFindEntity( e, global ));
117 }
118
119 private:
120 typedef GlobalVector LocalVector;
121 typedef typename Entity::HierarchicIterator HierarchicIterator;
122
123 Entity hFindEntity ( const Entity &e, const GlobalVector &global ) const
124 {
125 // To Do: This method should use the Cartesian structure, too
126 const HierarchicIterator end = e.hend( e.level()+1 );
127 for( HierarchicIterator it = e.hbegin( e.level()+1 ); it != end; ++it )
128 {
129 const Entity &child = *it;
130 LocalVector local = child.geometry().local( global );
131 if( ReferenceElements< ctype, dimension >::cube().checkInside( local ) )
132 return (indexSet_.contains( child ) ? child : hFindEntity( child, global ));
133 }
134 DUNE_THROW( Exception, "Unexpected internal Error" );
135 }
136
137 protected:
138 using Base::grid_;
139
140 private:
141 const IndexSet &indexSet_;
142 };
143
144
145
146 // SPHierarchicSearch for SPIndexSet
147 // ---------------------------------
148
149 template< class Grid >
150 class SPHierarchicSearch< Grid, SPIndexSet< Grid > >
151 : protected SPBasicHierarchicSearch< Grid >
152 {
153 typedef SPBasicHierarchicSearch< Grid > Base;
154 typedef SPIndexSet< Grid > IndexSet;
155
156 public:
157 typedef typename Base::Entity Entity;
158
159 typedef typename Base::GlobalVector GlobalVector;
160
161 SPHierarchicSearch ( const Grid &grid, const IndexSet &indexSet )
162 : Base( grid ),
163 indexSet_( indexSet )
164 {}
165
166 Entity findEntity ( const GlobalVector &global ) const
167 {
168 return Base::findEntity( global, indexSet_.gridLevel().level() );
169 }
170
171 private:
172 const IndexSet &indexSet_;
173 };
174
175
176
177 // SPHierarchicSearch for IndexSet< SPIndexSet >
178 // ---------------------------------------------
179
180 template< class Grid >
181 class SPHierarchicSearch< Grid, IndexSet< Grid, SPIndexSet< Grid >, typename SPIndexSet< Grid >::IndexType > >
182 : public SPHierarchicSearch< Grid, SPIndexSet< Grid > >
183 {
184 typedef SPHierarchicSearch< Grid, SPIndexSet< Grid > > Base;
185 typedef Dune::IndexSet< Grid, SPIndexSet< Grid >, typename SPIndexSet< Grid >::IndexType > IndexSet;
186
187 public:
188 SPHierarchicSearch ( const Grid &grid, const IndexSet &indexSet )
189 : Base( grid, static_cast< const SPIndexSet< Grid > & >( indexSet ) )
190 {}
191 };
192
193
194
195 // HierarchicSearch for SPGrid
196 // ---------------------------
197
198 template< class ct, int dim, template< int > class Ref, class Comm, class IndexSet >
199 class HierarchicSearch< SPGrid< ct, dim, Ref, Comm >, IndexSet >
200 : public SPHierarchicSearch< SPGrid< ct, dim, Ref, Comm >, IndexSet >
201 {
202 typedef SPHierarchicSearch< SPGrid< ct, dim, Ref, Comm >, IndexSet > Base;
203 typedef SPGrid< ct, dim, Ref, Comm > Grid;
204
205 public:
206 typedef typename Base::Entity Entity;
207 typedef typename Base::GlobalVector GlobalVector;
208
209 HierarchicSearch ( const Grid &grid, const IndexSet &indexSet )
210 : Base( grid, indexSet )
211 {}
212
213 Entity findEntity ( const GlobalVector &global ) const
214 {
215 return Base::findEntity( global );
216 }
217
218 template< PartitionIteratorType pitype >
219 Entity findEntity ( const GlobalVector &global ) const
220 {
221 const Entity entity = Base::findEntity( global );
222 if( !contains< pitype >( entity.partitionType() ) )
223 DUNE_THROW( GridError, "Coordinate " << global << " does not belong to partition " << pitype );
224 return entity;
225 }
226
227 private:
228 template< PartitionIteratorType pitype >
229 static bool contains ( const PartitionType partitionType )
230 {
231 switch( pitype )
232 {
234 return ( partitionType == InteriorEntity );
235
237 return ( partitionType == InteriorEntity || partitionType == BorderEntity );
238
240 return ( partitionType != FrontEntity && partitionType != GhostEntity );
241
243 return ( partitionType != GhostEntity );
244
245 case All_Partition:
246 return true;
247
248 case Ghost_Partition:
249 return ( partitionType == GhostEntity );
250
251 default:
252 DUNE_THROW( InvalidStateException, "wrong PartitionIteratorType: " << pitype << "." );
253 }
254 }
255 };
256
257} // namespace Dune
258
259#endif // #infdef DUNE_SPGRID_HIERARCHICSEARCH_HH
static constexpr int dimension
The dimension of the grid.
Definition: grid.hh:387
ct ctype
Define type used for coordinates in grid module.
Definition: grid.hh:532
Entity findEntity(const FieldVector< ct, dimw > &global) const
Search the IndexSet of this HierarchicSearch for an Entity containing point global.
Definition: hierarchicsearch.hh:127
HierarchicSearch(const Grid &g, const IS &is)
Construct a HierarchicSearch object from a Grid and an IndexSet.
Definition: hierarchicsearch.hh:118
Index Set Interface base class.
Definition: indexidset.hh:78
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:30
@ All_Partition
all entities
Definition: gridenums.hh:141
@ OverlapFront_Partition
interior, border, overlap and front entities
Definition: gridenums.hh:140
@ Interior_Partition
only interior entities
Definition: gridenums.hh:137
@ InteriorBorder_Partition
interior and border entities
Definition: gridenums.hh:138
@ Overlap_Partition
interior, border, and overlap entities
Definition: gridenums.hh:139
@ Ghost_Partition
only ghost entities
Definition: gridenums.hh:142
@ FrontEntity
on boundary between overlap and ghost
Definition: gridenums.hh:34
@ InteriorEntity
all interior entities
Definition: gridenums.hh:31
@ GhostEntity
ghost entities
Definition: gridenums.hh:35
@ BorderEntity
on boundary between interior and overlap
Definition: gridenums.hh:32
ImplementationDefined child(Node &&node, Indices... indices)
Extracts the child of a node given by a sequence of compile-time and run-time indices.
Definition: childextraction.hh:126
Provides base classes for index and id sets.
Dune namespace.
Definition: alignedallocator.hh:13
static const ReferenceElement & cube()
get hypercube reference elements
Definition: referenceelements.hh:210
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)