DUNE-FEM (unstable)

basicfilterwrapper.hh
1#ifndef DUNE_FEM_GRIDPART_FILTER_BASICFILTERWRAPPER_HH
2#define DUNE_FEM_GRIDPART_FILTER_BASICFILTERWRAPPER_HH
3
4#include <algorithm>
5#include <vector>
6
7#include <dune/grid/common/gridenums.hh>
8
9#include <dune/fem/gridpart/filter/filter.hh>
10
11namespace Dune
12{
13
14 namespace Fem
15 {
16
17 // forward declarations
18 // --------------------
19
20 template< class > class FilterDefaultImplementation;
21 template< class, class > class BasicFilterWrapper;
22
23
24 // BasicFilterWrapperTraits
25 // ------------------------
26
27 template< class GridPartImp, class BasicFilterImp >
28 struct BasicFilterWrapperTraits
29 {
31 typedef GridPartImp GridPartType;
32
34 typedef BasicFilterImp BasicFilterType;
35
37 typedef BasicFilterWrapper< GridPartType, BasicFilterType > FilterType;
38
40 template < int cd >
41 struct Codim
42 {
44 typedef typename GridPartType::template Codim< cd >::EntityType EntityType;
45 };
46
48 typedef typename Codim< 0 >::EntityType EntityType;
49 };
50
51
52 // BasicFilterWrapper
53 // ------------------
54
55 template< class GridPartImp, class BasicFilterImp >
56 class BasicFilterWrapper
57 : public FilterDefaultImplementation< BasicFilterWrapperTraits< GridPartImp, BasicFilterImp > >
58 {
59 // basic filter type
60 typedef BasicFilterImp BasicFilterType;
61
62 // type of grid part
63 typedef GridPartImp GridPartType;
64
65 // type of traits
66 typedef BasicFilterWrapperTraits< GridPartType, BasicFilterType > Traits;
67
68 // this type
69 typedef BasicFilterWrapper< GridPartType, BasicFilterType > ThisType;
70
71 // base type
72 typedef FilterDefaultImplementation< Traits > BaseType;
73
74 static const int dimension = GridPartType::GridType::dimension;
75
76 static const int nCodim = dimension+1;
77
78 template< int codim, class GridPart, class BasicFilter >
79 struct Contains
80 {
81 // entity type
82 typedef typename ThisType::template Codim< codim >::EntityType EntityType;
83
84 // return true, if entity is contained in filtered gridpart
85 static inline bool value ( const EntityType & entity,
86 const GridPart & gridPart,
87 const BasicFilter & filter,
88 std::vector< bool > & contains )
89 {
90 if( contains.size() != size_t(gridPart.indexSet().size(codim)) )
91 update< All_Partition >( gridPart, filter, contains );
92
93 // get index of entity
94 typedef typename GridPartType::IndexSetType IndexSetType;
95 const IndexSetType & indexSet = gridPart.indexSet();
96 size_t index = size_t( indexSet.index( entity ) );
97
98 return contains[ index ];
99 }
100
101 // update vector
102 template< PartitionIteratorType pitype >
103 static inline void update ( const GridPart & gridPart,
104 const BasicFilter & filter,
105 std::vector< bool > & contains )
106 {
107 // type of index set
108 typedef typename GridPartType::IndexSetType IndexSetType;
109
110 // get index set
111 const IndexSetType & indexSet = gridPart.indexSet();
112
113 // resize vector
114 contains.resize( indexSet.size( codim ) );
115
116 // fill vector
117 std::fill( contains.begin(), contains.end(), false );
118
119 // codim 0 iterator type
120 typedef typename GridPart::template Codim< 0 >::template Partition< pitype >::IteratorType IteratorType;
121
122 // traverse grid
123 IteratorType it = gridPart.template begin< 0, pitype >();
124 const IteratorType end = gridPart.template end< 0, pitype >();
125 for( ; it != end; ++it )
126 {
127 const typename IteratorType::Entity & entity = *it;
128
129 // continue, if codim 0 entity is not contained in filtered grid part
130 if( !filter.contains( entity ) )
131 continue;
132
133 const int count = entity.subEntities( codim );
134 for( int i = 0; i < count; ++i )
135 {
136 size_t subIndex = size_t( indexSet.subIndex( entity, i , codim ) );
137 contains[ subIndex ] = true;
138 }
139 }
140 }
141 };
142
143 template< class GridPart, class BasicFilter >
144 struct Contains< 0, GridPart, BasicFilter >
145 {
146 // entity type
147 typedef typename ThisType::template Codim< 0 >::EntityType EntityType;
148
149 // call BasicFilter::contains()
150 static inline bool value ( const EntityType & entity,
151 const GridPart &,
152 const BasicFilter & filter,
153 std::vector< bool > & )
154 {
155 return filter.contains( entity );
156 }
157 };
158
159 public:
161 typedef typename Traits::FilterType FilterType;
162
163 template< int cd >
164 struct Codim
165 {
166 typedef typename Traits::template Codim< cd >::EntityType EntityType;
167 };
168
170 typedef typename Traits::EntityType EntityType;
171
173 BasicFilterWrapper ( const GridPartType & gridPart, const BasicFilterType & filter )
174 : gridPart_( gridPart ),
175 filter_( filter )
176 { }
177
179 template< typename ... Args >
180 BasicFilterWrapper ( const GridPartType & gridPart, Args && ... args )
181 : gridPart_( gridPart ),
182 filter_( args ... )
183 { }
184
186 BasicFilterWrapper ( const ThisType & other )
187 : gridPart_( other.gridPart_ ),
188 filter_( other.filter_ )
189 {
190 reset();
191 }
192
194 ThisType & operator= ( const ThisType & other )
195 {
196 gridPart_ = other.gridPart_;
197 filter_ = other.filter_;
198 reset();
199 return *this;
200 }
201
203 template< class Intersection >
204 bool interiorIntersection( const Intersection &intersection ) const
205 {
206 return filter().interiorIntersection( intersection );
207 }
208
210 template< int cd >
211 bool contains ( const typename Codim< cd >::EntityType & entity ) const
212 {
213 return Contains< cd, GridPartType, BasicFilterType >::value( entity, gridPart_, filter_, contains_[ cd ] );
214 }
215
217 template< class Entity >
218 bool contains ( const Entity & entity ) const
219 {
220 enum { cc = Entity::codimension };
221 return contains< cc >( entity );
222 }
223
225 template< class Intersection >
226 bool intersectionBoundary( const Intersection & intersection ) const
227 {
228 return filter().intersectionBoundary( intersection );
229 }
230
232 template< class Intersection >
233 int intersectionBoundaryId ( const Intersection & intersection ) const
234 {
235 return filter().intersectionBoundaryId( intersection );
236 }
237
239 template< class Intersection >
240 bool intersectionNeighbor ( const Intersection & intersection ) const
241 {
242 return filter().intersectionNeighbor( intersection );
243 }
244
246 void reset ()
247 {
248 for( int codim = 0; codim < nCodim; ++codim )
249 contains_[ codim ].clear();
250 }
251
252 private:
253 // reference to basic filter
254 const BasicFilterType & filter () const
255 {
256 return filter_;
257 }
258
259 const GridPartType & gridPart_;
260 BasicFilterType filter_;
261 mutable std::vector< bool > contains_[ nCodim ];
262 };
263
264 } // namespace Fem
265
266} // namespace Dune
267
268#endif // #ifndef DUNE_FEM_GRIDPART_FILTER_BASICFILTERWRAPPER_HH
static constexpr int codimension
Know your own codimension.
Definition: entity.hh:106
consecutive, persistent index set for the leaf level based on the grid's hierarchy index set
Definition: adaptiveleafindexset.hh:1351
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::bool_constant<((II==value)||...)> contains(std::integer_sequence< T, II... >, std::integral_constant< T, value >)
Checks whether or not a given sequence contains a value.
Definition: integersequence.hh:137
Static tag representing a codimension.
Definition: dimension.hh:24
entity types
Definition: basicfilterwrapper.hh:42
GridPartType::template Codim< cd >::EntityType EntityType
entity type for given codimension
Definition: basicfilterwrapper.hh:44
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)