DUNE-FEM (unstable)

vectorial.hh
1#ifndef DUNE_FEM_BASISFUNCTIONSET_VECTORIAL_HH
2#define DUNE_FEM_BASISFUNCTIONSET_VECTORIAL_HH
3
4#include <cstddef>
5#include <utility>
6#include <vector>
7
8#include <dune/geometry/referenceelements.hh>
10
11#include <dune/fem/space/basisfunctionset/functor.hh>
12#include <dune/fem/space/common/functionspace.hh>
13
14namespace Dune
15{
16
17 namespace Fem
18 {
19
20 // DofAlignment
21 // ------------
22
32 template< class Implementation >
34 {
35 public:
37 typedef std::size_t GlobalDofType;
41 typedef std::pair< int, std::size_t > LocalDofType;
42
43 protected:
44 DofAlignment () = default;
45
46 public:
56 {
57 return impl().globalDof( localDof );
58 }
59
69 {
70 return impl().localDof( globalDof );
71 }
72
73 protected:
74 const Implementation &impl () const
75 {
76 return static_cast< const Implementation & >( *this );
77 }
78 };
79
80
81
82 // HorizontalDofAlignment
83 // ----------------------
84
93 template< class ScalarBasisFunctionSet, class Range >
95 : public DofAlignment< HorizontalDofAlignment< ScalarBasisFunctionSet, Range > >
96 {
99
100 public:
101 typedef typename BaseType::GlobalDofType GlobalDofType;
102 typedef typename BaseType::LocalDofType LocalDofType;
103
104 HorizontalDofAlignment () = default;
105
106 explicit HorizontalDofAlignment ( const ScalarBasisFunctionSet &scalarBasisFunctionSet )
107 : scalarSize_( scalarBasisFunctionSet.size() )
108 {}
109
111 GlobalDofType globalDof ( const LocalDofType &localDof ) const
112 {
113 return GlobalDofType( localDof.first*scalarSize_ + localDof.second );
114 }
115
117 LocalDofType localDof ( const GlobalDofType &globalDof ) const
118 {
119 return LocalDofType( globalDof / scalarSize_, globalDof % scalarSize_ );
120 }
121
122 private:
123 std::size_t scalarSize_;
124 };
125
126
127
128 // VerticalDofAlignment
129 // --------------------
130
138 template< class ScalarBasisFunctionSet, class Range >
140 : public DofAlignment< VerticalDofAlignment< ScalarBasisFunctionSet, Range > >
141 {
144
145 static const int dimRange = Range::dimension;
146
147 public:
148 typedef typename BaseType::GlobalDofType GlobalDofType;
149 typedef typename BaseType::LocalDofType LocalDofType;
150
151 VerticalDofAlignment () = default;
152
153 explicit VerticalDofAlignment ( const ScalarBasisFunctionSet & ) {}
154
156 GlobalDofType globalDof ( const LocalDofType &localDof ) const
157 {
158 return GlobalDofType( localDof.first + localDof.second*dimRange );
159 }
160
162 LocalDofType localDof ( const GlobalDofType &globalDof ) const
163 {
164 return LocalDofType( globalDof % dimRange, globalDof / dimRange );
165 }
166 };
167
168
169
170 // SubDofVector
171 // ------------
172
178 template< class DofVector, class DofAlignment >
180
181 // note: DofVector can be also const DofVector
182 template< class DofVector, class ScalarBasisFunctionSet, class Range >
183 class SubDofVector< DofVector, HorizontalDofAlignment< ScalarBasisFunctionSet, Range > >
184 {
186
187 typedef typename Range::value_type RangeFieldType;
188
190 typedef typename DofAlignmentType::LocalDofType LocalDofType;
191
192 // extract correct RangeFieldType for const or non-const version
193 typedef typename std::conditional<
194 std::is_const< DofVector > :: value,
195 const RangeFieldType,
196 RangeFieldType > :: type DofType;
197
198 public:
199 typedef RangeFieldType value_type;
200
201 SubDofVector( DofVector &dofs, int coordinate, const DofAlignmentType &dofAlignment )
202 : dofs_( &(dofs[ dofAlignment.globalDof( LocalDofType( coordinate, 0 ) ) ] ) )
203 {}
204
205 DofType &operator[] ( std::size_t i )
206 {
207 return dofs_[ i ];
208 }
209
210 // const RFT& leads to problem with returning reference to temporary
211 // with dofs_ = PetscDF::LocalFunction::DofVector
212 RangeFieldType operator[] ( std::size_t i ) const
213 {
214 return dofs_[ i ];
215 }
216
217 private:
218 DofType *dofs_;
219 };
220
221 // note: DofVector can be also const DofVector
222 template< class DofVector, class ScalarBasisFunctionSet, class Range >
223 class SubDofVector< DofVector, VerticalDofAlignment< ScalarBasisFunctionSet, Range > >
224 {
225 typedef SubDofVector< DofVector, VerticalDofAlignment< ScalarBasisFunctionSet, Range > > ThisType;
226
227 typedef typename Range::value_type RangeFieldType;
228
229 typedef VerticalDofAlignment< ScalarBasisFunctionSet, Range > DofAlignmentType;
230 typedef typename DofAlignmentType::LocalDofType LocalDofType;
231
232 // extract correct RangeFieldType for const or non-const version
233 typedef typename std::conditional<
234 std::is_const< DofVector > :: value,
235 const RangeFieldType,
236 RangeFieldType > :: type DofType;
237
238 public:
239 typedef RangeFieldType value_type;
240
241 SubDofVector( DofVector &dofs, int coordinate, const DofAlignmentType &dofAlignment )
242 : dofs_( dofs ),
243 coordinate_( coordinate ),
244 dofAlignment_( dofAlignment )
245 {}
246
247 DofType &operator[] ( std::size_t i )
248 {
249 return dofs_[ dofAlignment_.globalDof( LocalDofType( coordinate_, i ) ) ];
250 }
251
252 // const RFT& leads to problem with returning reference to temporary
253 // with dofs_ = PetscDF::LocalFunction::DofVector
254 RangeFieldType operator[] ( std::size_t i ) const
255 {
256 return dofs_[ dofAlignment_.globalDof( LocalDofType( coordinate_, i ) ) ];
257 }
258
259 private:
260 DofVector &dofs_;
261 int coordinate_;
262 DofAlignmentType dofAlignment_;
263 };
264
265
266
267 // VectorialBasisFunctionSet
268 // -------------------------
269
277 template< class ScalarBasisFunctionSet, class Range, template< class, class > class DofAlignment = VerticalDofAlignment >
279 {
281
282 public:
283 typedef ScalarBasisFunctionSet ScalarBasisFunctionSetType;
284
285 typedef typename ScalarBasisFunctionSetType::EntityType EntityType;
286 typedef typename EntityType::Geometry Geometry;
287 typedef typename ScalarBasisFunctionSetType::ReferenceElementType ReferenceElementType;
288
289 private:
290 typedef typename ScalarBasisFunctionSetType::FunctionSpaceType ScalarFunctionSpaceType;
291 static const int dimRange = Range::dimension;
292
293 public:
295
296 typedef typename FunctionSpaceType::DomainType DomainType;
297 typedef typename FunctionSpaceType::RangeType RangeType;
298 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
300
302
303 typedef typename DofAlignmentType::GlobalDofType GlobalDofType;
304 typedef typename DofAlignmentType::LocalDofType LocalDofType;
305
306 typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
307 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
308
309 private:
310 struct EvaluateAll;
311 struct JacobianAll;
312 struct HessianAll;
313
314 public:
316
317 explicit VectorialBasisFunctionSet ( const ScalarBasisFunctionSetType &scalarBasisFunctionSet )
318 : scalarBasisFunctionSet_( scalarBasisFunctionSet ),
319 dofAlignment_( scalarBasisFunctionSet_ )
320 {}
321
322 int order () const { return scalarBasisFunctionSet().order(); }
323
324 std::size_t size () const { return dimRange*scalarBasisFunctionSet().size(); }
325
326 const ReferenceElementType &referenceElement () const { return scalarBasisFunctionSet().referenceElement(); }
327 Dune::GeometryType type() const { return scalarBasisFunctionSet().type(); }
328
329 template< class Point, class DofVector >
330 void axpy ( const Point &x, const RangeType &valueFactor, DofVector &dofs ) const
331 {
332 axpy< EvaluateAll >( x, valueFactor, dofs );
333 }
334
335 template< class Point, class DofVector >
336 void axpy ( const Point &x, const JacobianRangeType &jacobianFactor, DofVector &dofs ) const
337 {
338 axpy< JacobianAll >( x, jacobianFactor, dofs );
339 }
340
341 template< class Point, class DofVector >
342 void axpy ( const Point &x, const HessianRangeType &hessianFactor, DofVector &dofs ) const
343 {
344 axpyH( x, hessianFactor, dofs );
345 }
346
347 template< class Point, class DofVector >
348 void axpy ( const Point &x, const RangeType &valueFactor, const JacobianRangeType &jacobianFactor,
349 DofVector &dofs ) const
350 {
351 axpy( x, valueFactor, dofs );
352 axpy( x, jacobianFactor, dofs );
353 }
354
355 template< class Quadrature, class Vector, class DofVector >
356 void axpy ( const Quadrature &quad, const Vector &values, DofVector & dofs ) const
357 {
358 const unsigned int nop = quad.nop();
359 for( unsigned int qp = 0; qp < nop ; ++qp )
360 axpy( quad[ qp ], values[ qp ], dofs );
361 }
362
363 template< class Quadrature, class VectorA, class VectorB, class DofVector >
364 void axpy ( const Quadrature &quad, const VectorA &valuesA, const VectorB &valuesB, DofVector & dofs ) const
365 {
366 const unsigned int nop = quad.nop();
367 for( unsigned int qp = 0; qp < nop ; ++qp )
368 {
369 axpy( quad[ qp ], valuesA[ qp ], dofs );
370 axpy( quad[ qp ], valuesB[ qp ], dofs );
371 }
372 }
373
374 template< class Point, class DofVector >
375 void evaluateAll ( const Point &x, const DofVector &dofs, RangeType &value ) const
376 {
377 evaluateAll< EvaluateAll >( x, dofs, value );
378 }
379
380 template< class Point, class RangeArray >
381 void evaluateAll ( const Point &x, RangeArray &values ) const
382 {
383 evaluateAll< EvaluateAll >( x, values );
384 }
385
386 template< class Quadrature, class DofVector, class RangeArray >
387 void evaluateAll ( const Quadrature &quad, const DofVector &dofs, RangeArray &ranges ) const
388 {
389 const unsigned int nop = quad.nop();
390 for( unsigned int qp = 0; qp < nop ; ++qp )
391 evaluateAll( quad[ qp ], dofs, ranges[ qp ] );
392 }
393
394 template< class Point, class DofVector >
395 void jacobianAll ( const Point &x, const DofVector &dofs, JacobianRangeType &jacobian ) const
396 {
397 evaluateAll< JacobianAll >( x, dofs, jacobian );
398 }
399
400 template< class Point, class JacobianRangeArray >
401 void jacobianAll ( const Point &x, JacobianRangeArray &jacobians ) const
402 {
403 evaluateAll< JacobianAll >( x, jacobians );
404 }
405
406 template< class Quadrature, class DofVector, class JacobianArray >
407 void jacobianAll ( const Quadrature &quad, const DofVector &dofs, JacobianArray &jacobians ) const
408 {
409 const unsigned int nop = quad.nop();
410 for( unsigned int qp = 0; qp < nop ; ++qp )
411 jacobianAll( quad[ qp ], dofs, jacobians[ qp ] );
412 }
413
414 template< class Point, class DofVector >
415 void hessianAll ( const Point &x, const DofVector &dofs, HessianRangeType &hessian ) const
416 {
417 evaluateAll< HessianAll >( x, dofs, hessian );
418 }
419
420 template< class Point, class HessianRangeArray >
421 void hessianAll ( const Point &x, HessianRangeArray &hessians ) const
422 {
423 evaluateAll< HessianAll >( x, hessians );
424 }
425
426 template< class Quadrature, class DofVector, class HessianArray >
427 void hessianAll ( const Quadrature &quad, const DofVector &dofs, HessianArray &hessians ) const
428 {
429 const unsigned int nop = quad.nop();
430 for( unsigned int qp = 0; qp < nop ; ++qp )
431 hessianAll( quad[ qp ], dofs, hessians[ qp ] );
432 }
433
434 const EntityType &entity () const { return scalarBasisFunctionSet().entity(); }
435 const Geometry& geometry () const { return scalarBasisFunctionSet().geometry(); }
436 bool valid () const { return scalarBasisFunctionSet().valid(); }
437
438 DofAlignmentType dofAlignment () const { return dofAlignment_ ; }
439
440 const ScalarBasisFunctionSetType &scalarBasisFunctionSet () const
441 {
442 return scalarBasisFunctionSet_;
443 }
444
445 private:
446 template< class Evaluate, class Point, class DofVector >
447 void axpy ( const Point &x, const typename Evaluate::Vector &factor, DofVector &dofs ) const
448 {
449 const std::size_t size = scalarBasisFunctionSet().size();
450 std::vector< typename Evaluate::Scalar > scalars( size );
451 Evaluate::apply( scalarBasisFunctionSet(), x, scalars );
452
453 for( int r = 0; r < dimRange; ++r )
454 {
455 for( std::size_t i = 0; i < size; ++i )
456 {
457 const GlobalDofType globalDof = dofAlignment_.globalDof( LocalDofType( r, i ) );
458 dofs[ globalDof ] += factor[ r ] * scalars[ i ][ 0 ];
459 }
460 }
461 }
462 template< class Point, class DofVector >
463 void axpyH ( const Point &x, const HessianRangeType &factor, DofVector &dofs ) const
464 {
465 const std::size_t size = scalarBasisFunctionSet().size();
466 std::vector< typename HessianAll::Scalar > scalars( size );
467 HessianAll::apply( scalarBasisFunctionSet(), x, scalars );
468
469 const int xSize = DomainType::dimension;
470 for( int r = 0; r < dimRange; ++r )
471 {
472 for( std::size_t i = 0; i < size; ++i )
473 {
474 const GlobalDofType globalDof = dofAlignment_.globalDof( LocalDofType( r, i ) );
475 for ( int j = 0; j < xSize; ++j )
476 dofs[ globalDof ] += factor[ r ][ j ] * scalars[ i ][ 0 ][ j ];
477 }
478 }
479 }
480
481 template< class Evaluate, class Point, class DofVector >
482 void evaluateAll ( const Point &x, const DofVector &dofs, typename Evaluate::Vector &vector ) const
483 {
484 typename Evaluate::Scalar scalar;
485 for( int r = 0; r < dimRange; ++r )
486 {
487 SubDofVector< const DofVector, DofAlignmentType > subDofs( dofs, r, dofAlignment_ );
488 Evaluate::apply( scalarBasisFunctionSet(), x, subDofs, scalar );
489 vector[ r ] = scalar[ 0 ];
490 }
491 }
492
493 template< class Evaluate, class Point, class VectorArray >
494 void evaluateAll ( const Point &x, VectorArray &vectorials ) const
495 {
496 const std::size_t size = scalarBasisFunctionSet().size();
497 std::vector< typename Evaluate::Scalar > scalars( size );
498 Evaluate::apply( scalarBasisFunctionSet(), x, scalars );
499
500 typedef typename Evaluate::Vector Vector;
501
502 for( int r = 0; r < dimRange; ++r )
503 {
504 for( std::size_t i = 0; i < size; ++i )
505 {
506 const GlobalDofType globalDof = dofAlignment_.globalDof( LocalDofType( r, i ) );
507 Vector &vector = vectorials[ globalDof ];
508 vector = Vector( typename Vector::value_type( 0 ) );
509 vector[ r ] = scalars[ i ][ 0 ];
510 }
511 }
512 }
513
514 ScalarBasisFunctionSetType scalarBasisFunctionSet_;
515 DofAlignmentType dofAlignment_;
516 };
517
518
519
520 // VectorialBasisFunctionSet< ScalarBasisFunctionSet, Range >::EvaluateAll
521 // -----------------------------------------------------------------------
522
523 template< class ScalarBasisFunctionSet, class Range, template< class, class > class DofAlignment >
524 struct VectorialBasisFunctionSet< ScalarBasisFunctionSet, Range, DofAlignment >::EvaluateAll
525 {
526 typedef typename ScalarFunctionSpaceType::RangeType Scalar;
527 typedef RangeType Vector;
528
529 template< class Point, class SubDofVector >
530 static void apply ( const ScalarBasisFunctionSetType &scalarBasisFunctionSet,
531 const Point &x, const SubDofVector &dofs, Scalar &scalar )
532 {
533 scalarBasisFunctionSet.evaluateAll( x, dofs, scalar );
534 }
535
536 template< class Point, class ScalarArray >
537 static void apply ( const ScalarBasisFunctionSetType &scalarBasisFunctionSet,
538 const Point &x, ScalarArray &scalars )
539 {
540 scalarBasisFunctionSet.evaluateAll( x, scalars );
541 }
542 };
543
544
545
546 // VectorialBasisFunctionSet< ScalarBasisFunctionSet, Range >::JacobianAll
547 // -----------------------------------------------------------------------
548
549 template< class ScalarBasisFunctionSet, class Range, template< class, class > class DofAlignment >
550 struct VectorialBasisFunctionSet< ScalarBasisFunctionSet, Range, DofAlignment >::JacobianAll
551 {
552 typedef typename ScalarFunctionSpaceType::JacobianRangeType Scalar;
553 typedef JacobianRangeType Vector;
554
555 template< class Point, class SubDofVector >
556 static void apply ( const ScalarBasisFunctionSetType &scalarBasisFunctionSet,
557 const Point &x, const SubDofVector &dofs, Scalar &scalar )
558 {
559 scalarBasisFunctionSet.jacobianAll( x, dofs, scalar );
560 }
561
562 template< class Point, class ScalarArray >
563 static void apply ( const ScalarBasisFunctionSetType &scalarBasisFunctionSet,
564 const Point &x, ScalarArray &scalars )
565 {
566 scalarBasisFunctionSet.jacobianAll( x, scalars );
567 }
568 };
569
570
571
572 // VectorialBasisFunctionSet< ScalarBasisFunctionSet, Range >::HessianAll
573 // ----------------------------------------------------------------------
574
575 template< class ScalarBasisFunctionSet, class Range, template< class, class > class DofAlignment >
576 struct VectorialBasisFunctionSet< ScalarBasisFunctionSet, Range, DofAlignment >::HessianAll
577 {
578 typedef typename ScalarFunctionSpaceType::HessianRangeType Scalar;
579 typedef HessianRangeType Vector;
580
581 template< class Point, class SubDofVector >
582 static void apply ( const ScalarBasisFunctionSetType &scalarBasisFunctionSet,
583 const Point &x, const SubDofVector &dofs, Scalar &scalar )
584 {
585 scalarBasisFunctionSet.hessianAll( x, dofs, scalar );
586 }
587
588 template< class Point, class ScalarArray >
589 static void apply ( const ScalarBasisFunctionSetType &scalarBasisFunctionSet,
590 const Point &x, ScalarArray &scalars )
591 {
592 scalarBasisFunctionSet.hessianAll( x, scalars );
593 }
594 };
595
596 } // namespace Fem
597
598} // namespace Dune
599
600#endif // #ifndef DUNE_FEM_BASISFUNCTIONSET_VECTORIAL_HH
Interface documentation for Dof alignment classes used in VectorialBasisFunctionSet.
Definition: vectorial.hh:34
std::size_t GlobalDofType
global Dof type
Definition: vectorial.hh:37
LocalDofType localDof(const GlobalDofType &globalDof) const
map global to local Dof
Definition: vectorial.hh:68
std::pair< int, std::size_t > LocalDofType
local Dof type consists of coordinate number and Dof number in scalar basis function set
Definition: vectorial.hh:41
GlobalDofType globalDof(const LocalDofType &localDof) const
map local to global Dof
Definition: vectorial.hh:55
Definition: explicitfieldvector.hh:75
FunctionSpaceTraits::DomainFieldType DomainFieldType
Intrinsic type used for values in the domain field (usually a double)
Definition: functionspaceinterface.hh:60
FunctionSpaceTraits::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:71
FunctionSpaceTraits::LinearMappingType JacobianRangeType
Intrinsic type used for the jacobian values has a Dune::FieldMatrix type interface.
Definition: functionspaceinterface.hh:75
FunctionSpaceTraits::DomainType DomainType
Type of domain vector (using type of domain field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:67
FunctionSpaceTraits::RangeFieldType RangeFieldType
Intrinsic type used for values in the range field (usually a double)
Definition: functionspaceinterface.hh:63
Implementation of DofAlignment.
Definition: vectorial.hh:96
GlobalDofType globalDof(const LocalDofType &localDof) const
map local to global Dof
Definition: vectorial.hh:111
LocalDofType localDof(const GlobalDofType &globalDof) const
map global to local Dof
Definition: vectorial.hh:117
int nop() const
obtain the number of integration points
Definition: quadrature.hh:291
actual interface class for quadratures
Definition: quadrature.hh:401
Extract Sub dof vector for single coordinate.
Definition: vectorial.hh:179
Builds a vectorial basis function set from given scalar basis function set.
Definition: vectorial.hh:279
Implementation of DofAlignment.
Definition: vectorial.hh:141
LocalDofType localDof(const GlobalDofType &globalDof) const
map global to local Dof
Definition: vectorial.hh:162
GlobalDofType globalDof(const LocalDofType &localDof) const
map local to global Dof
Definition: vectorial.hh:156
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: interface.hh:235
Dune namespace.
Definition: alignedallocator.hh:13
convert functions space to space with new dim range
Definition: functionspace.hh:250
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 12, 23:30, 2024)