dune-fem 2.8.0
Loading...
Searching...
No Matches
basicfilterwrapper.hh
Go to the documentation of this file.
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
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 >
29 {
31 typedef GridPartImp GridPartType;
32
34 typedef BasicFilterImp BasicFilterType;
35
38
40 template < int cd >
41 struct Codim
42 {
44 typedef typename GridPartType::template Codim< cd >::EntityType EntityType;
45 };
46
49 };
50
51
52 // BasicFilterWrapper
53 // ------------------
54
55 template< class GridPartImp, class BasicFilterImp >
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
67
68 // this type
70
71 // base type
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:
162
163 template< int cd >
164 struct Codim
165 {
166 typedef typename Traits::template Codim< cd >::EntityType EntityType;
167 };
168
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
Definition: bindguard.hh:11
Definition: filter/filter.hh:156
Definition: basicfilterwrapper.hh:58
bool intersectionBoundary(const Intersection &intersection) const
returns true if an intersection is a boundary intersection
Definition: basicfilterwrapper.hh:226
bool interiorIntersection(const Intersection &intersection) const
default implementation returns contains from neighbor
Definition: basicfilterwrapper.hh:204
BasicFilterWrapper(const ThisType &other)
copy constructor
Definition: basicfilterwrapper.hh:186
bool contains(const typename Codim< cd >::EntityType &entity) const
returns true if the given entity of the pointer in the domain
Definition: basicfilterwrapper.hh:211
BasicFilterWrapper(const GridPartType &gridPart, const BasicFilterType &filter)
constructor
Definition: basicfilterwrapper.hh:173
Traits::FilterType FilterType
type of the filter implementation
Definition: basicfilterwrapper.hh:161
bool intersectionNeighbor(const Intersection &intersection) const
returns true if for an intersection a neighbor exsits
Definition: basicfilterwrapper.hh:240
int intersectionBoundaryId(const Intersection &intersection) const
returns the boundary id for an intersection
Definition: basicfilterwrapper.hh:233
Traits::EntityType EntityType
type of codim 0 entity
Definition: basicfilterwrapper.hh:170
void reset()
reset cached values
Definition: basicfilterwrapper.hh:246
BasicFilterWrapper(const GridPartType &gridPart, Args &&... args)
constructor
Definition: basicfilterwrapper.hh:180
bool contains(const Entity &entity) const
returns true if the given entity of the pointer in the domain
Definition: basicfilterwrapper.hh:218
ThisType & operator=(const ThisType &other)
assignment operator
Definition: basicfilterwrapper.hh:194
Definition: basicfilterwrapper.hh:29
BasicFilterImp BasicFilterType
export basic filter type
Definition: basicfilterwrapper.hh:34
GridPartImp GridPartType
grid part type
Definition: basicfilterwrapper.hh:31
BasicFilterWrapper< GridPartType, BasicFilterType > FilterType
filter type
Definition: basicfilterwrapper.hh:37
Codim< 0 >::EntityType EntityType
entity type for codimension 0
Definition: basicfilterwrapper.hh:48
entity types
Definition: basicfilterwrapper.hh:42
GridPartType::template Codim< cd >::EntityType EntityType
entity type for given codimension
Definition: basicfilterwrapper.hh:44
Definition: basicfilterwrapper.hh:165
Traits::template Codim< cd >::EntityType EntityType
Definition: basicfilterwrapper.hh:166