DUNE-FEM (unstable)

codimensionmapper.hh
1#ifndef DUNE_FEM_SPACE_MAPPER_CODIMENSIONMAPPER_HH
2#define DUNE_FEM_SPACE_MAPPER_CODIMENSIONMAPPER_HH
3
4#include <cassert>
5
6#include <algorithm>
7#include <type_traits>
8
10
11#include <dune/geometry/referenceelements.hh>
12#include <dune/geometry/type.hh>
13
14#include <dune/fem/gridpart/common/indexset.hh>
15#include <dune/fem/misc/functor.hh>
16#include <dune/fem/space/common/allgeomtypes.hh>
17#include <dune/fem/space/mapper/dofmapper.hh>
18
19namespace Dune
20{
21
22 namespace Fem
23 {
24
25 // Internal forward declaration
26 // ----------------------------
27
28 template< class GridPart, int codim >
29 class CodimensionMapper;
30
31
32
33#ifndef DOXYGEN
34
35 namespace __CodimensionMapper
36 {
37
38 // Traits
39 // ------
40
41 template< class GridPart, int codim >
42 struct Traits
43 {
44 typedef CodimensionMapper< GridPart, codim > DofMapperType;
45
46 static const int codimension = codim;
47
48 typedef GridPart GridPartType;
49 typedef typename GridPartType::IndexSetType IndexSetType;
50
51 typedef typename GridPartType::template Codim< 0 >::EntityType ElementType;
52 //typedef typename IndexSetType::IndexType SizeType;
53 typedef std::size_t SizeType;
54 typedef SizeType GlobalKeyType;
55 };
56
57
58
59 // DofMapper
60 // ---------
61
62 template< class T, template< class > class Base = Dune::Fem::DofMapper >
63 class DofMapper
64 : public Base< T >
65 {
66 typedef Base< T > BaseType;
67
68 public:
69 typedef typename BaseType::Traits Traits;
70
71 static const int codimension = Traits::codimension;
72
73 typedef typename Traits::GridPartType GridPartType;
74 typedef typename Traits::IndexSetType IndexSetType;
75
76 typedef typename BaseType::ElementType ElementType;
77 typedef typename BaseType::SizeType SizeType;
78 typedef typename Traits::GlobalKeyType GlobalKeyType;
79
80 explicit DofMapper ( const GridPartType &gridPart )
81 : DofMapper( gridPart.indexSet() )
82 {}
83
84 explicit DofMapper ( const IndexSetType &indexSet )
85 : indexSet_( indexSet ),
86 extension_( 0 ),
87 maxNumDofs_( 0 )
88 {
89 AllGeomTypes< IndexSetType, typename GridPartType::GridType > types( indexSet );
90 for( GeometryType type : types.geomTypes( 0 ) )
91 maxNumDofs_ = std::max( maxNumDofs_, referenceElement( type ).size( codimension ) );
92
93 if constexpr ( Capabilities::isDuneFemIndexSet< IndexSetType >:: v )
94 {
95 // submit codimension request to index set to enable support
96 std::vector< int > codimensions( 1, int(Traits::codimension) );
97 indexSet_.requestCodimensions( codimensions );
98 }
99 }
100
101 /* \name DofMapper interface methods
102 * \{
103 */
104
105 SizeType size () const
106 {
107 return indexSet().size( codimension ) + extension_;
108 }
109
110 static constexpr bool contains ( int codim ) noexcept
111 {
112 return codim == codimension;
113 }
114
115 static constexpr bool fixedDataSize ( int codim ) noexcept
116 {
117 return true;
118 }
119
120 template< class Function >
121 void mapEach ( const ElementType &element, Function function ) const
122 {
123 if( codimension == 0 )
124 function( 0, indexSet().index( element ) );
125 else
126 {
127 const SizeType numDofs = this->numDofs( element );
128 for( SizeType i = 0; i < numDofs; ++i )
129 function( i, indexSet().subIndex( element, i, codimension ) );
130 }
131 }
132
133 void map ( const ElementType &element, std::vector< GlobalKeyType > &indices ) const
134 {
135 indices.resize( numDofs( element ) );
136 mapEach( element, [ &indices ] ( int local, GlobalKeyType global ) { indices[ local ] = global; } );
137 }
138
139 template< class Entity >
140 void mapEntityDofs ( const Entity &entity, std::vector< GlobalKeyType > &indices ) const
141 {
142 indices.resize( numEntityDofs( entity ) );
143 mapEachEntityDof( entity, AssignFunctor< std::vector< GlobalKeyType > >( indices ) );
144 }
145
146 template< class Entity, class Function >
147 void mapEachEntityDof ( const Entity &entity, Function function ) const
148 {
149 assert( Entity::codimension == codimension );
150 function( 0, indexSet().index( entity ) );
151 }
152
153 int maxNumDofs () const { return maxNumDofs_; }
154
155 SizeType numDofs ( const ElementType &element ) const
156 {
157 return element.subEntities( codimension );
158 }
159
160 template< class Entity >
161 static constexpr SizeType numEntityDofs ( const Entity &entity ) noexcept
162 {
163 return contains( Entity::codimension ) ? 1 : 0;
164 }
165
166 void update () {}
167
168 void extendSize( const SizeType extension )
169 {
170 extension_ = extension;
171 }
172
173 [[deprecated("Use onSubEntity method with char vector instead")]]
174 void onSubEntity ( const ElementType &element, int i, int c, std::vector< bool > &indices ) const
175 {
176 std::vector< char > _idx;
177 onSubEntity(element, i, c, _idx);
178 indices.resize( _idx.size() );
179 for (std::size_t i=0; i<_idx.size();++i)
180 _idx[i] = indices[i] > 0;
181 }
182 void onSubEntity ( const ElementType &element, int i, int c, std::vector< char > &indices ) const
183 {
184 indices.resize( numDofs(element) );
185 std::fill(indices.begin(),indices.end(),0);
186 indices[i] = 1;
187 }
188
189 /* \} */
190
191 /* \name AdaptiveDofMapper interface methods
192 * \{
193 */
194
195 /* Compatibility methods; users expect an AdaptiveDiscreteFunction to
196 * compile over spaces built on top of a LeafGridPart or LevelGridPart.
197 *
198 * The AdaptiveDiscreteFunction requires the block mapper (i.e. this
199 * type) to be adaptive. The CodimensionMapper however is truly
200 * adaptive if and only if the underlying index set is adaptive. We
201 * don't want to wrap the index set as 1) it hides the actual problem
202 * (don't use the AdaptiveDiscreteFunction with non-adaptive index
203 * sets), and 2) other dune-fem classes may make correct use of the
204 * index set's capabilities.
205 */
206
207 static constexpr bool consecutive () noexcept { return false; }
208
209 SizeType numBlocks () const
210 {
211 DUNE_THROW( NotImplemented, "Method numBlocks() called on non-adaptive block mapper" );
212 }
213
214 SizeType numberOfHoles ( int ) const
215 {
216 DUNE_THROW( NotImplemented, "Method numberOfHoles() called on non-adaptive block mapper" );
217 }
218
219 GlobalKeyType oldIndex ( int hole, int ) const
220 {
221 DUNE_THROW( NotImplemented, "Method oldIndex() called on non-adaptive block mapper" );
222 }
223
224 GlobalKeyType newIndex ( int hole, int ) const
225 {
226 DUNE_THROW( NotImplemented, "Method newIndex() called on non-adaptive block mapper" );
227 }
228
229 SizeType oldOffSet ( int ) const
230 {
231 DUNE_THROW( NotImplemented, "Method oldOffSet() called on non-adaptive block mapper" );
232 }
233
234 SizeType offSet ( int ) const
235 {
236 DUNE_THROW( NotImplemented, "Method offSet() called on non-adaptive block mapper" );
237 }
238
239 /* \} */
240
241 protected:
242 const IndexSetType &indexSet () const { return indexSet_; }
243
244 private:
245 static auto referenceElement ( GeometryType type )
247 {
249 }
250
251 const IndexSetType &indexSet_;
252 SizeType extension_;
253 int maxNumDofs_;
254 };
255
256
257
258 // AdaptiveDofMapper
259 // -----------------
260
261 template< class Traits >
262 class AdaptiveDofMapper
263 : public DofMapper< Traits, Dune::Fem::AdaptiveDofMapper >
264 {
265 typedef DofMapper< Traits, Dune::Fem::AdaptiveDofMapper > BaseType;
266
267 public:
268 static const int codimension = BaseType::codimension;
269
270 typedef typename BaseType::SizeType SizeType;
271 typedef typename BaseType::GlobalKeyType GlobalKeyType;
272
273 protected:
274 using BaseType::indexSet;
275
276 public:
277 explicit AdaptiveDofMapper ( const typename BaseType::GridPartType &gridPart )
278 : BaseType( gridPart )
279 {}
280
281 explicit AdaptiveDofMapper ( const typename BaseType::IndexSetType &indexSet )
282 : BaseType( indexSet )
283 {}
284
285 static constexpr bool consecutive () noexcept { return true; }
286
287 static constexpr SizeType numBlocks () noexcept
288 {
289 return 1;
290 }
291
292 SizeType numberOfHoles ( int ) const
293 {
294 return indexSet().numberOfHoles( codimension );
295 }
296
297 GlobalKeyType oldIndex ( int hole, int ) const
298 {
299 return indexSet().oldIndex( hole, codimension );
300 }
301
302 GlobalKeyType newIndex ( int hole, int ) const
303 {
304 return indexSet().newIndex( hole, codimension );
305 }
306
307 static constexpr SizeType oldOffSet ( int ) noexcept
308 {
309 return 0;
310 }
311
312 static constexpr SizeType offSet ( int ) noexcept
313 {
314 return 0;
315 }
316 };
317
318
319
320 // Implementation
321 // --------------
322
323 template< class GridPart, int codim,
324 bool adaptive = Capabilities::isAdaptiveIndexSet< typename GridPart::IndexSetType >::v >
325 class Implementation
326 {
327 typedef __CodimensionMapper::Traits< GridPart, codim > Traits;
328
329 public:
330 typedef typename std::conditional< adaptive,
331 AdaptiveDofMapper< Traits >,
332 DofMapper< Traits >
333 >::type Type;
334 };
335
336 } // namespace __CodimensionMapper
337
338#endif // #ifndef DOXYGEN
339
340
341
342 // CodimensionMapper
343 // -----------------
344
354 template< class GridPart, int codim >
356 : public __CodimensionMapper::template Implementation< GridPart, codim >::Type
357 {
358 typedef typename __CodimensionMapper::template Implementation< GridPart, codim >::Type BaseType;
359
360 public:
361 explicit CodimensionMapper ( const typename BaseType::GridPartType &gridPart )
362 : BaseType( gridPart )
363 {}
364
365 explicit CodimensionMapper ( const typename BaseType::IndexSetType *indexSet )
366 : BaseType( *indexSet )
367 {}
368
369 explicit CodimensionMapper ( const typename BaseType::IndexSetType &indexSet )
370 : BaseType( indexSet )
371 {}
372 };
373
374
375 // Capabilities
376 // ------------
377
378 namespace Capabilities
379 {
380 // isAdaptiveDofMapper
381 // -------------------
382
383 template< class GridPart, int codim >
384 struct isAdaptiveDofMapper< CodimensionMapper< GridPart, codim > >
385 {
387 };
388
389
390 // isConsecutiveIndexSet
391 // ---------------------
392
393 template< class GridPart, int codim >
394 struct isConsecutiveIndexSet< __CodimensionMapper::AdaptiveDofMapper< __CodimensionMapper::Traits< GridPart, codim > > >
395 {
396 static const bool v = true;
397 };
398
399 } // namespace Capabilities
400
401 } // namespace Fem
402
403} // namespace Dune
404
405#endif // #ifndef DUNE_FEM_SPACE_MAPPER_CODIMENSIONMAPPER_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
specialize with true if index set implements the interface for adaptive index sets
Definition: indexset.hh:83
mapper allocating one DoF per subentity of a given codimension
Definition: codimensionmapper.hh:357
Interface for calculating the size of a function space for a grid on a specified level....
Definition: dofmapper.hh:43
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
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 const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)