dune-fem 2.12-git
Loading...
Searching...
No Matches
localmatrix.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_LOCALMATRIX_HH
2#define DUNE_FEM_LOCALMATRIX_HH
3
4#include <optional>
5
6//- Dune includes
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 {
37 typename LocalMatrixTraits::LocalMatrixType >
39
40 public:
42 typedef LocalMatrixTraits Traits;
43
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
74
75 protected:
76 using BaseType::asImp;
77
81
82 public:
92
102
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
199
205
207 int rows () const
208 {
210 return asImp().rows();
211 }
212
214 int columns () const
215 {
217 return asImp().columns();
218 }
219
222 {
224 return asImp().domainSpace();
225 }
226
229 {
231 return asImp().rangeSpace();
232 }
233
236 {
238 return asImp().domainBasisFunctionSet();
239 }
240
243 {
245 return asImp().rangeBasisFunctionSet();
246 }
247
249 {
251 return asImp().domainEntity();
252 }
253
255 {
257 return asImp().rangeEntity();
258 }
259
266 MatrixColumnType column( const unsigned int col )
267 {
268 return MatrixColumnType( asImp(), col );
269 }
270
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
296
299
302
303 protected:
306
309
312
313 protected:
321
322 template< class DomainEntityType, class RangeEntityType >
334
343
344 public:
350
359
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>
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
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 >;
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
Col col
X & lhs()
Y & rhs()
#define CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(__interface_method_to_call__)
#define CHECK_INTERFACE_IMPLEMENTATION(dummy)
typename MakeExplicit< FV >::Type Explicit
Definition explicitfieldvector.hh:171
Definition bartonnackmaninterface.hh:17
const Implementation & asImp() const
Definition bartonnackmaninterface.hh:37
Definition localmatrix.hh:442
Traits::LocalMatrixType LocalMatrixType
type of local matrix implementation
Definition localmatrix.hh:445
Traits::RangeSpaceType RangeSpaceType
type of domain discrete function space
Definition localmatrix.hh:448
RangeSpaceType::JacobianRangeType JacobianRangeType
type of jacobian range
Definition localmatrix.hh:453
RangeSpaceType::RangeType RangeType
type of range
Definition localmatrix.hh:451
LocalMatrixType & localMatrix_
Definition localmatrix.hh:459
RangeSpaceType::RangeFieldType RangeFieldType
type of range field
Definition localmatrix.hh:455
void axpy(const RangeVectorType &phi, const Explicit< RangeType > &factor, const RangeFieldType &weight=RangeFieldType(1))
axpy operation for local matrices
Definition localmatrix.hh:488
void axpy(const RangeVectorType &phi, const JacobianVectorType &dphi, const Explicit< RangeType > &factor, const JacobianRangeType &jacobianFactor, const RangeFieldType &weight=RangeFieldType(1))
axpy operation for local matrices
Definition localmatrix.hh:545
void axpy(const JacobianVectorType &dphi, const JacobianRangeType &jacobianFactor, const RangeFieldType &weight=RangeFieldType(1))
axpy operation for local matrices
Definition localmatrix.hh:514
const unsigned int column_
Definition localmatrix.hh:461
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
const Implementation & asImp() const
Definition bartonnackmaninterface.hh:37
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
RangeSpaceType::EntityType RangeEntityType
Definition localmatrix.hh:68
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
MatrixColumnObject< Traits > MatrixColumnType
Definition localmatrix.hh:73
const RangeSpaceType & rangeSpace() const
access to the range space
Definition localmatrix.hh:228
ThisType LocalMatrixInterfaceType
type of this interface
Definition localmatrix.hh:45
DomainSpaceType::EntityType DomainEntityType
Definition localmatrix.hh:67
LocalMatrixTraits Traits
type of traits class
Definition localmatrix.hh:42
int columns() const
get number of columns within the matrix
Definition localmatrix.hh:214
const RangeEntityType & rangeEntity() const
Definition localmatrix.hh:254
const DomainEntityType & domainEntity() const
Definition localmatrix.hh:248
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
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
const RangeEntityType & rangeEntity() const
Definition localmatrix.hh:400
void init(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition localmatrix.hh:346
LocalMatrixDefault(const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace, const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
Definition localmatrix.hh:323
const DomainSpaceType & domainSpace_
Definition localmatrix.hh:304
int rows() const
get number of rows within the matrix
Definition localmatrix.hh:376
const DomainEntityType & domainEntity() const
Definition localmatrix.hh:399
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
DomainBasisFunctionSetType domainBaseSet_
Definition localmatrix.hh:307
int columns() const
get number of columns within the matrix
Definition localmatrix.hh:379
const RangeSpaceType & rangeSpace_
Definition localmatrix.hh:305
void clearCol(const int localCol)
ser column entries to zero
Definition localmatrix.hh:430
std::optional< DomainEntityType > domainEntity_
Definition localmatrix.hh:310
BaseType::DomainBasisFunctionSetType DomainBasisFunctionSetType
Definition localmatrix.hh:297
BaseType::RangeBasisFunctionSetType RangeBasisFunctionSetType
Definition localmatrix.hh:298
BaseType::RangeEntityType RangeEntityType
Definition localmatrix.hh:301
std::optional< RangeEntityType > rangeEntity_
Definition localmatrix.hh:311
LocalMatrixTraits Traits
Definition localmatrix.hh:292
void unbind()
clear local matrix from entities
Definition localmatrix.hh:361
const DomainSpaceType & domainSpace() const
access to the domain space
Definition localmatrix.hh:382
BaseType::DomainEntityType DomainEntityType
Definition localmatrix.hh:300
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
BaseType::DomainSpaceType DomainSpaceType
Definition localmatrix.hh:294
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition localmatrix.hh:388
BaseType::RangeSpaceType RangeSpaceType
Definition localmatrix.hh:295
LocalMatrixDefault(const LocalMatrixDefault &org)
Definition localmatrix.hh:335
LocalMatrixDefault(const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace)
Definition localmatrix.hh:314
RangeBasisFunctionSetType rangeBaseSet_
Definition localmatrix.hh:308
void finalize()
finalize local matrix setup and possibly add values to real matrix
Definition localmatrix.hh:373
T emplace(T... args)
T reset(T... args)
T value(T... args)