DUNE-FEM (unstable)

localmatrix.hh
1#ifndef DUNE_FEM_LOCALMATRIX_HH
2#define DUNE_FEM_LOCALMATRIX_HH
3
4#include <optional>
5
6//- Dune includes
7#include <dune/fem/misc/bartonnackmaninterface.hh>
8#include "../../common/explicitfieldvector.hh"
9
10namespace Dune
11{
12
13 namespace Fem
14 {
15
20 //- forward declaration of MatrixColumnObject, see below
21 template <class Traits>
22 class MatrixColumnObject ;
23
24
25
26 // LocalMatrixInterface
27 // --------------------
28
30 template< class LocalMatrixTraits >
32 : public BartonNackmanInterface< LocalMatrixInterface< LocalMatrixTraits >,
33 typename LocalMatrixTraits::LocalMatrixType >
34 {
36 typedef BartonNackmanInterface< LocalMatrixInterface< LocalMatrixTraits >,
37 typename LocalMatrixTraits::LocalMatrixType >
38 BaseType;
39
40 public:
42 typedef LocalMatrixTraits Traits;
43
45 typedef ThisType LocalMatrixInterfaceType;
46
48 typedef typename Traits :: LocalMatrixType LocalMatrixType;
49
51 typedef typename Traits :: RangeFieldType RangeFieldType;
52
54 typedef typename Traits :: DomainSpaceType DomainSpaceType;
55
57 typedef typename Traits :: RangeSpaceType RangeSpaceType;
58
60 typedef typename DomainSpaceType :: BasisFunctionSetType
62
64 typedef typename RangeSpaceType :: BasisFunctionSetType
66
67 typedef typename DomainSpaceType::EntityType DomainEntityType;
68 typedef typename RangeSpaceType::EntityType RangeEntityType;
69
71 typedef typename Traits :: LittleBlockType LittleBlockType;
72
73 typedef MatrixColumnObject< Traits > MatrixColumnType;
74
75 protected:
76 using BaseType::asImp;
77
80 {}
81
82 public:
87 void init ( const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity )
88 {
90 ( asImp().init( domainEntity, rangeEntity ) );
91 }
92
97 void bind ( const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity )
98 {
100 ( asImp().bind( domainEntity, rangeEntity ) );
101 }
102
105 void unbind ()
106 {
108 }
109
116 void add ( const int localRow,
117 const int localCol,
118 const RangeFieldType &value )
119 {
121 asImp().add(localRow,localCol,value));
122 }
123
130 void set ( const int localRow,
131 const int localCol,
132 const RangeFieldType &value )
133 {
135 asImp().set(localRow,localCol,value));
136 }
137
141 void clearRow( const int localRow )
142 {
144 asImp().clearRow( localRow ));
145 }
146
151 void clearCol( const int localCol )
152 {
154 asImp().clearCol( localCol ));
155 }
156
157
163 template <class DomainLocalFunctionType,
164 class RangeLocalFunctionType>
165 void multiplyAdd(const DomainLocalFunctionType& lhs,
166 RangeLocalFunctionType& rhs) const
167 {
169 asImp().multiplyAdd( lhs, rhs ) );
170 }
171
178 const RangeFieldType get ( const int localRow,
179 const int localCol ) const
180 {
181 CHECK_INTERFACE_IMPLEMENTATION( asImp().get(localRow,localCol));
182 return asImp().get(localRow,localCol);
183 }
184
188 void scale ( const RangeFieldType& scalar )
189 {
191 asImp().scale( scalar ) );
192 }
193
195 void clear ()
196 {
198 }
199
201 void resort ()
202 {
204 }
205
207 int rows () const
208 {
210 return asImp().rows();
211 }
212
214 int columns () const
215 {
217 return asImp().columns();
218 }
219
222 {
223 CHECK_INTERFACE_IMPLEMENTATION( asImp().domainSpace() );
224 return asImp().domainSpace();
225 }
226
229 {
230 CHECK_INTERFACE_IMPLEMENTATION( asImp().rangeSpace() );
231 return asImp().rangeSpace();
232 }
233
236 {
237 CHECK_INTERFACE_IMPLEMENTATION( asImp().domainBasisFunctionSet() );
238 return asImp().domainBasisFunctionSet();
239 }
240
243 {
244 CHECK_INTERFACE_IMPLEMENTATION( asImp().rangeBasisFunctionSet() );
245 return asImp().rangeBasisFunctionSet();
246 }
247
248 const DomainEntityType &domainEntity () const
249 {
250 CHECK_INTERFACE_IMPLEMENTATION( asImp().domainEntity() );
251 return asImp().domainEntity();
252 }
253
254 const RangeEntityType &rangeEntity () const
255 {
256 CHECK_INTERFACE_IMPLEMENTATION( asImp().rangeEntity() );
257 return asImp().rangeEntity();
258 }
259
266 MatrixColumnType column( const unsigned int col )
267 {
268 return MatrixColumnType( asImp(), col );
269 }
270
272 void finalize()
273 {
275 }
276 };
277
278
279
280 // LocalMatrixDefault
281 // ------------------
282
284 template< class LocalMatrixTraits >
286 : public LocalMatrixInterface< LocalMatrixTraits >
287 {
290
291 public:
292 typedef LocalMatrixTraits Traits;
293
294 typedef typename BaseType::DomainSpaceType DomainSpaceType;
295 typedef typename BaseType::RangeSpaceType RangeSpaceType;
296
299
300 typedef typename BaseType::DomainEntityType DomainEntityType;
301 typedef typename BaseType::RangeEntityType RangeEntityType;
302
303 protected:
304 const DomainSpaceType &domainSpace_;
305 const RangeSpaceType &rangeSpace_;
306
307 DomainBasisFunctionSetType domainBaseSet_;
308 RangeBasisFunctionSetType rangeBaseSet_;
309
310 std::optional< DomainEntityType > domainEntity_;
311 std::optional< RangeEntityType > rangeEntity_;
312
313 protected:
314 LocalMatrixDefault ( const DomainSpaceType &domainSpace,
315 const RangeSpaceType &rangeSpace )
316 : domainSpace_( domainSpace ),
317 rangeSpace_( rangeSpace ),
318 domainBaseSet_(),
319 rangeBaseSet_()
320 {}
321
322 template< class DomainEntityType, class RangeEntityType >
323 LocalMatrixDefault ( const DomainSpaceType &domainSpace,
324 const RangeSpaceType &rangeSpace,
325 const DomainEntityType &domainEntity,
326 const RangeEntityType &rangeEntity )
327 : domainSpace_( domainSpace ),
328 rangeSpace_( rangeSpace ),
329 domainBaseSet_(),
330 rangeBaseSet_()
331 {
332 bind( domainEntity, rangeEntity );
333 }
334
336 : domainSpace_( org.domainSpace_ ),
337 rangeSpace_( org.rangeSpace_ ),
338 domainBaseSet_( org.domainBaseSet_ ),
339 rangeBaseSet_( org.rangeBaseSet_ ),
340 domainEntity_( org.domainEntity_ ),
341 rangeEntity_( org.rangeEntity_ )
342 {}
343
344 public:
346 void init ( const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity )
347 {
348 bind( domainEntity, rangeEntity );
349 }
350
352 void bind ( const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity )
353 {
354 domainBaseSet_ = domainSpace_.basisFunctionSet( domainEntity );
355 rangeBaseSet_ = rangeSpace_.basisFunctionSet( rangeEntity );
356 domainEntity_.emplace(domainEntity);
357 rangeEntity_.emplace(rangeEntity);
358 }
359
361 void unbind ()
362 {
363 domainBaseSet_ = DomainBasisFunctionSetType();
364 rangeBaseSet_ = RangeBasisFunctionSetType();
365 domainEntity_.reset();
366 rangeEntity_.reset();
367 }
368
370 void resort () {}
371
373 void finalize () {}
374
376 int rows () const { return rangeBaseSet_.size(); }
377
379 int columns () const { return domainBaseSet_.size(); }
380
382 const DomainSpaceType &domainSpace () const { return domainSpace_; }
383
385 const RangeSpaceType &rangeSpace () const { return rangeSpace_; }
386
389 {
390 return domainBaseSet_;
391 }
392
395 {
396 return rangeBaseSet_;
397 }
398
399 const DomainEntityType &domainEntity () const { return domainEntity_.value(); }
400 const RangeEntityType &rangeEntity () const { return rangeEntity_.value(); }
401
403 template <class DomainLocalFunctionType,
404 class RangeLocalFunctionType>
405 void multiplyAdd(const DomainLocalFunctionType& lhs,
406 RangeLocalFunctionType& rhs) const
407 {
408 const int row = this->rows();
409 const int col = this->columns();
410 for(int i=0; i<row; ++i)
411 {
412 for(int j=0; j<col; ++j)
413 {
414 rhs[i] += this->get(i,j) * lhs[j];
415 }
416 }
417 }
418
420 void clearRow( const int localRow )
421 {
422 const int col = this->columns();
423 for(int j = 0; j < col; ++j)
424 {
425 this->set(localRow, j, 0);
426 }
427 }
428
430 void clearCol( const int localCol )
431 {
432 const int row = this->rows();
433 for(int i = 0; i < row; ++i)
434 {
435 this->set(i, localCol, 0);
436 }
437 }
438 };
439
440 template <class Traits>
441 class MatrixColumnObject
442 {
443 public:
445 typedef typename Traits :: LocalMatrixType LocalMatrixType;
446
448 typedef typename Traits :: RangeSpaceType RangeSpaceType;
449
451 typedef typename RangeSpaceType :: RangeType RangeType ;
453 typedef typename RangeSpaceType :: JacobianRangeType JacobianRangeType ;
455 typedef typename RangeSpaceType :: RangeFieldType RangeFieldType ;
456
457 protected:
458 // reference to local matrix
459 LocalMatrixType& localMatrix_;
460 // local column number
461 const unsigned int column_;
462
464 MatrixColumnObject( LocalMatrixType& localMatrix, const unsigned int col )
465 : localMatrix_( localMatrix ),
466 column_( col )
467 {
468 }
469
470 // at the moment only allow LocalMatrixInterface to construct this object
471 friend class LocalMatrixInterface< Traits >;
472
473 public:
474
487 template <class RangeVectorType>
488 void axpy( const RangeVectorType& phi,
489 const Explicit<RangeType>& factor,
490 const RangeFieldType& weight = RangeFieldType(1) )
491 {
492 const unsigned int numBasisFunctions = localMatrix_.rows();
493 assert( phi.size() >= numBasisFunctions );
494 for( unsigned int row = 0; row < numBasisFunctions; ++ row )
495 {
496 RangeFieldType value = factor * phi[ row ];
497 localMatrix_.add( row, column_, weight * value );
498 }
499 }
500
513 template <class JacobianVectorType>
514 void axpy( const JacobianVectorType& dphi,
515 const JacobianRangeType& jacobianFactor,
516 const RangeFieldType& weight = RangeFieldType(1) )
517 {
518 const unsigned int numBasisFunctions = localMatrix_.rows();
519 assert( dphi.size() >= numBasisFunctions );
520 for( unsigned int row = 0; row < numBasisFunctions; ++ row )
521 {
522 RangeFieldType value = 0;
523 for( int k = 0; k < jacobianFactor.rows; ++k )
524 value += jacobianFactor[ k ] * dphi[ row ][ k ];
525
526 localMatrix_.add( row, column_, weight * value );
527 }
528 }
529
544 template <class RangeVectorType, class JacobianVectorType>
545 void axpy( const RangeVectorType& phi,
546 const JacobianVectorType& dphi,
547 const Explicit<RangeType>& factor,
548 const JacobianRangeType& jacobianFactor,
549 const RangeFieldType& weight = RangeFieldType(1) )
550 {
551 const unsigned int numBasisFunctions = localMatrix_.rows();
552 assert( phi.size() >= numBasisFunctions );
553 assert( dphi.size() >= numBasisFunctions );
554 for( unsigned int row = 0; row < numBasisFunctions; ++ row )
555 {
556 RangeFieldType value = factor * phi[ row ];
557 for( int k = 0; k < jacobianFactor.rows; ++k )
558 value += jacobianFactor[ k ] * dphi[ row ][ k ];
559
560 localMatrix_.add( row, column_, weight * value );
561 }
562 }
563 };
564
566
567 } // namespace Fem
568
569} // namespace Dune
570
571#endif // #ifndef DUNE_FEM_LOCALMATRIX_HH
#define CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(__interface_method_to_call__)
Definition: bartonnackmanifcheck.hh:61
Default implementation for local matrix classes.
Definition: localmatrix.hh:287
void clearRow(const int localRow)
set row to zero values
Definition: localmatrix.hh:420
void bind(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrix.hh:352
void resort()
resort ordering in global matrix (if possible)
Definition: localmatrix.hh:370
void init(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrix.hh:346
int rows() const
get number of rows within the matrix
Definition: localmatrix.hh:376
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:394
const RangeSpaceType & rangeSpace() const
access to the range space
Definition: localmatrix.hh:385
int columns() const
get number of columns within the matrix
Definition: localmatrix.hh:379
void clearCol(const int localCol)
ser column entries to zero
Definition: localmatrix.hh:430
void unbind()
clear local matrix from entities
Definition: localmatrix.hh:361
const DomainSpaceType & domainSpace() const
access to the domain space
Definition: localmatrix.hh:382
void multiplyAdd(const DomainLocalFunctionType &lhs, RangeLocalFunctionType &rhs) const
multiply left hand side with local matrix and add to right hand side rhs += Matrix * lhs
Definition: localmatrix.hh:405
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:388
void finalize()
finalize local matrix setup and possibly add values to real matrix
Definition: localmatrix.hh:373
Interface for local matrix classes.
Definition: localmatrix.hh:34
void unbind()
clear local matrix from entities
Definition: localmatrix.hh:105
void resort()
resort ordering in global matrix (if possible)
Definition: localmatrix.hh:201
Traits::LittleBlockType LittleBlockType
Definition: localmatrix.hh:71
const RangeFieldType get(const int localRow, const int localCol) const
get value of matrix entry (row,col) where row and col are local row and local column
Definition: localmatrix.hh:178
void clear()
set all entries of local matrix to zero
Definition: localmatrix.hh:195
void scale(const RangeFieldType &scalar)
scale matrix with scalar value
Definition: localmatrix.hh:188
Traits::LocalMatrixType LocalMatrixType
type of local matrix implementation
Definition: localmatrix.hh:48
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:235
LocalMatrixInterface()
constructor
Definition: localmatrix.hh:79
Traits::DomainSpaceType DomainSpaceType
type of domain discrete function space
Definition: localmatrix.hh:54
void add(const int localRow, const int localCol, const RangeFieldType &value)
add value to matrix entry (row,col) where row and col are local row and local column
Definition: localmatrix.hh:116
void init(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrix.hh:87
int rows() const
get number of rows within the matrix
Definition: localmatrix.hh:207
const DomainSpaceType & domainSpace() const
access to the domain space
Definition: localmatrix.hh:221
Traits::RangeSpaceType RangeSpaceType
type of range discrete function space
Definition: localmatrix.hh:57
void set(const int localRow, const int localCol, const RangeFieldType &value)
set value of matrix entry (row,col) where row and col are local row and local column
Definition: localmatrix.hh:130
void bind(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrix.hh:97
RangeSpaceType::BasisFunctionSetType RangeBasisFunctionSetType
type of base function sets within range function space
Definition: localmatrix.hh:65
DomainSpaceType::BasisFunctionSetType DomainBasisFunctionSetType
type of base function sets within domain function space
Definition: localmatrix.hh:61
void multiplyAdd(const DomainLocalFunctionType &lhs, RangeLocalFunctionType &rhs) const
multiply left hand side with local matrix and add to right hand side rhs += Matrix * lhs
Definition: localmatrix.hh:165
void clearRow(const int localRow)
set row to zero values
Definition: localmatrix.hh:141
Traits::RangeFieldType RangeFieldType
type of range field
Definition: localmatrix.hh:51
void finalize()
finalize local matrix setup and possibly add values to real matrix
Definition: localmatrix.hh:272
const RangeSpaceType & rangeSpace() const
access to the range space
Definition: localmatrix.hh:228
ThisType LocalMatrixInterfaceType
type of this interface
Definition: localmatrix.hh:45
LocalMatrixTraits Traits
type of traits class
Definition: localmatrix.hh:42
int columns() const
get number of columns within the matrix
Definition: localmatrix.hh:214
MatrixColumnType column(const unsigned int col)
return column object for local matrix which contains axpy methods for convenience
Definition: localmatrix.hh:266
void clearCol(const int localCol)
ser column entries to zero
Definition: localmatrix.hh:151
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:242
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)