dune-fem 2.8.0
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//- Dune includes
6#include "../../common/explicitfieldvector.hh"
7
8namespace Dune
9{
10
11 namespace Fem
12 {
13
18 //- forward declaration of MatrixColumnObject, see below
19 template <class Traits>
20 class MatrixColumnObject ;
21
22
23
24 // LocalMatrixInterface
25 // --------------------
26
28 template< class LocalMatrixTraits >
30 : public BartonNackmanInterface< LocalMatrixInterface< LocalMatrixTraits >,
31 typename LocalMatrixTraits::LocalMatrixType >
32 {
35 typename LocalMatrixTraits::LocalMatrixType >
37
38 public:
40 typedef LocalMatrixTraits Traits;
41
44
46 typedef typename Traits :: LocalMatrixType LocalMatrixType;
47
49 typedef typename Traits :: RangeFieldType RangeFieldType;
50
52 typedef typename Traits :: DomainSpaceType DomainSpaceType;
53
55 typedef typename Traits :: RangeSpaceType RangeSpaceType;
56
58 typedef typename DomainSpaceType :: BasisFunctionSetType
60
62 typedef typename RangeSpaceType :: BasisFunctionSetType
64
65 typedef typename DomainSpaceType::EntityType DomainEntityType;
66 typedef typename RangeSpaceType::EntityType RangeEntityType;
67
69 typedef typename Traits :: LittleBlockType LittleBlockType;
70
72
73 protected:
74 using BaseType::asImp;
75
78 {}
79
80 public:
86 {
87 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
89 }
90
96 {
97 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
99 }
100
103 void unbind ()
104 {
105 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().unbind() );
106 }
107
114 void add ( const int localRow,
115 const int localCol,
116 const RangeFieldType &value )
117 {
118 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(
119 asImp().add(localRow,localCol,value));
120 }
121
128 void set ( const int localRow,
129 const int localCol,
130 const RangeFieldType &value )
131 {
132 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(
133 asImp().set(localRow,localCol,value));
134 }
135
139 void clearRow( const int localRow )
140 {
141 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(
142 asImp().clearRow( localRow ));
143 }
144
149 void clearCol( const int localCol )
150 {
151 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(
152 asImp().clearCol( localCol ));
153 }
154
155
161 template <class DomainLocalFunctionType,
162 class RangeLocalFunctionType>
163 void multiplyAdd(const DomainLocalFunctionType& lhs,
164 RangeLocalFunctionType& rhs) const
165 {
166 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(
167 asImp().multiplyAdd( lhs, rhs ) );
168 }
169
176 const RangeFieldType get ( const int localRow,
177 const int localCol ) const
178 {
179 CHECK_INTERFACE_IMPLEMENTATION( asImp().get(localRow,localCol));
180 return asImp().get(localRow,localCol);
181 }
182
186 void scale ( const RangeFieldType& scalar )
187 {
188 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(
189 asImp().scale( scalar ) );
190 }
191
193 void clear ()
194 {
195 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(asImp().clear());
196 }
197
199 void resort ()
200 {
201 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(asImp().resort());
202 }
203
205 int rows () const
206 {
207 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().rows() );
208 return asImp().rows();
209 }
210
212 int columns () const
213 {
214 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().columns() );
215 return asImp().columns();
216 }
217
220 {
221 CHECK_INTERFACE_IMPLEMENTATION( asImp().domainSpace() );
222 return asImp().domainSpace();
223 }
224
227 {
228 CHECK_INTERFACE_IMPLEMENTATION( asImp().rangeSpace() );
229 return asImp().rangeSpace();
230 }
231
234 {
235 CHECK_INTERFACE_IMPLEMENTATION( asImp().domainBasisFunctionSet() );
236 return asImp().domainBasisFunctionSet();
237 }
238
241 {
242 CHECK_INTERFACE_IMPLEMENTATION( asImp().rangeBasisFunctionSet() );
243 return asImp().rangeBasisFunctionSet();
244 }
245
247 {
248 CHECK_INTERFACE_IMPLEMENTATION( asImp().domainEntity() );
249 return asImp().domainEntity();
250 }
251
253 {
254 CHECK_INTERFACE_IMPLEMENTATION( asImp().rangeEntity() );
255 return asImp().rangeEntity();
256 }
257
264 MatrixColumnType column( const unsigned int col )
265 {
266 return MatrixColumnType( asImp(), col );
267 }
268
270 void finalize()
271 {
272 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(asImp().finalize());
273 }
274 };
275
276
277
278 // LocalMatrixDefault
279 // ------------------
280
282 template< class LocalMatrixTraits >
284 : public LocalMatrixInterface< LocalMatrixTraits >
285 {
288
289 public:
290 typedef LocalMatrixTraits Traits;
291
294
297
300
301 protected:
304
307
308 std::optional< DomainEntityType > domainEntity_;
309 std::optional< RangeEntityType > rangeEntity_;
310
311 protected:
318 {}
319
320 template< class DomainEntityType, class RangeEntityType >
329 {
331 }
332
334 : domainSpace_( org.domainSpace_ ),
340 {}
341
342 public:
345 {
347 }
348
351 {
352 domainBaseSet_ = domainSpace_.basisFunctionSet( domainEntity );
353 rangeBaseSet_ = rangeSpace_.basisFunctionSet( rangeEntity );
355 rangeEntity_.emplace(rangeEntity);
356 }
357
359 void unbind ()
360 {
363 domainEntity_.reset();
364 rangeEntity_.reset();
365 }
366
368 void resort () {}
369
371 void finalize () {}
372
374 int rows () const { return rangeBaseSet_.size(); }
375
377 int columns () const { return domainBaseSet_.size(); }
378
380 const DomainSpaceType &domainSpace () const { return domainSpace_; }
381
383 const RangeSpaceType &rangeSpace () const { return rangeSpace_; }
384
387 {
388 return domainBaseSet_;
389 }
390
393 {
394 return rangeBaseSet_;
395 }
396
397 const DomainEntityType &domainEntity () const { return domainEntity_.value(); }
398 const RangeEntityType &rangeEntity () const { return rangeEntity_.value(); }
399
401 template <class DomainLocalFunctionType,
402 class RangeLocalFunctionType>
403 void multiplyAdd(const DomainLocalFunctionType& lhs,
404 RangeLocalFunctionType& rhs) const
405 {
406 const int row = this->rows();
407 const int col = this->columns();
408 for(int i=0; i<row; ++i)
409 {
410 for(int j=0; j<col; ++j)
411 {
412 rhs[i] += this->get(i,j) * lhs[j];
413 }
414 }
415 }
416
418 void clearRow( const int localRow )
419 {
420 const int col = this->columns();
421 for(int j = 0; j < col; ++j)
422 {
423 this->set(localRow, j, 0);
424 }
425 }
426
428 void clearCol( const int localCol )
429 {
430 const int row = this->rows();
431 for(int i = 0; i < row; ++i)
432 {
433 this->set(i, localCol, 0);
434 }
435 }
436 };
437
438 template <class Traits>
440 {
441 public:
443 typedef typename Traits :: LocalMatrixType LocalMatrixType;
444
446 typedef typename Traits :: RangeSpaceType RangeSpaceType;
447
449 typedef typename RangeSpaceType :: RangeType RangeType ;
451 typedef typename RangeSpaceType :: JacobianRangeType JacobianRangeType ;
453 typedef typename RangeSpaceType :: RangeFieldType RangeFieldType ;
454
455 protected:
456 // reference to local matrix
458 // local column number
459 const unsigned int column_;
460
462 MatrixColumnObject( LocalMatrixType& localMatrix, const unsigned int col )
463 : localMatrix_( localMatrix ),
464 column_( col )
465 {
466 }
467
468 // at the moment only allow LocalMatrixInterface to construct this object
469 friend class LocalMatrixInterface< Traits >;
470
471 public:
485 template <class RangeVectorType>
486 void axpy( const RangeVectorType& phi,
487 const Explicit<RangeType>& factor,
488 const RangeFieldType& weight = RangeFieldType(1) )
489 {
490 const unsigned int numBasisFunctions = localMatrix_.rows();
491 assert( phi.size() >= numBasisFunctions );
492 for( unsigned int row = 0; row < numBasisFunctions; ++ row )
493 {
494 RangeFieldType value = factor * phi[ row ];
495 localMatrix_.add( row, column_, weight * value );
496 }
497 }
498
511 template <class JacobianVectorType>
512 void axpy( const JacobianVectorType& dphi,
513 const JacobianRangeType& jacobianFactor,
514 const RangeFieldType& weight = RangeFieldType(1) )
515 {
516 const unsigned int numBasisFunctions = localMatrix_.rows();
517 assert( dphi.size() >= numBasisFunctions );
518 for( unsigned int row = 0; row < numBasisFunctions; ++ row )
519 {
520 RangeFieldType value = 0;
521 for( int k = 0; k < jacobianFactor.rows; ++k )
522 value += jacobianFactor[ k ] * dphi[ row ][ k ];
523
524 localMatrix_.add( row, column_, weight * value );
525 }
526 }
527
542 template <class RangeVectorType, class JacobianVectorType>
543 void axpy( const RangeVectorType& phi,
544 const JacobianVectorType& dphi,
545 const Explicit<RangeType>& factor,
546 const JacobianRangeType& jacobianFactor,
547 const RangeFieldType& weight = RangeFieldType(1) )
548 {
549 const unsigned int numBasisFunctions = localMatrix_.rows();
550 assert( phi.size() >= numBasisFunctions );
551 assert( dphi.size() >= numBasisFunctions );
552 for( unsigned int row = 0; row < numBasisFunctions; ++ row )
553 {
554 RangeFieldType value = factor * phi[ row ];
555 for( int k = 0; k < jacobianFactor.rows; ++k )
556 value += jacobianFactor[ k ] * dphi[ row ][ k ];
557
558 localMatrix_.add( row, column_, weight * value );
559 }
560 }
561 };
562
564
565 } // namespace Fem
566
567} // namespace Dune
568
569#endif // #ifndef DUNE_FEM_LOCALMATRIX_HH
Definition: bindguard.hh:11
typename MakeExplicit< FV >::Type Explicit
Definition: explicitfieldvector.hh:171
Definition: bartonnackmaninterface.hh:17
const Implementation & asImp() const
Definition: bartonnackmaninterface.hh:37
Definition: localmatrix.hh:440
Traits::LocalMatrixType LocalMatrixType
type of local matrix implementation
Definition: localmatrix.hh:443
Traits::RangeSpaceType RangeSpaceType
type of domain discrete function space
Definition: localmatrix.hh:446
RangeSpaceType::JacobianRangeType JacobianRangeType
type of jacobian range
Definition: localmatrix.hh:451
RangeSpaceType::RangeType RangeType
type of range
Definition: localmatrix.hh:449
LocalMatrixType & localMatrix_
Definition: localmatrix.hh:457
RangeSpaceType::RangeFieldType RangeFieldType
type of range field
Definition: localmatrix.hh:453
void axpy(const RangeVectorType &phi, const Explicit< RangeType > &factor, const RangeFieldType &weight=RangeFieldType(1))
axpy operation for local matrices
Definition: localmatrix.hh:486
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:543
void axpy(const JacobianVectorType &dphi, const JacobianRangeType &jacobianFactor, const RangeFieldType &weight=RangeFieldType(1))
axpy operation for local matrices
Definition: localmatrix.hh:512
const unsigned int column_
Definition: localmatrix.hh:459
Interface for local matrix classes.
Definition: localmatrix.hh:32
void unbind()
clear local matrix from entities
Definition: localmatrix.hh:103
void resort()
resort ordering in global matrix (if possible)
Definition: localmatrix.hh:199
Traits::LittleBlockType LittleBlockType
Definition: localmatrix.hh:69
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:176
void clear()
set all entries of local matrix to zero
Definition: localmatrix.hh:193
void scale(const RangeFieldType &scalar)
scale matrix with scalar value
Definition: localmatrix.hh:186
Traits::LocalMatrixType LocalMatrixType
type of local matrix implementation
Definition: localmatrix.hh:46
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:233
LocalMatrixInterface()
constructor
Definition: localmatrix.hh:77
Traits::DomainSpaceType DomainSpaceType
type of domain discrete function space
Definition: localmatrix.hh:52
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:114
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:85
int rows() const
get number of rows within the matrix
Definition: localmatrix.hh:205
const DomainSpaceType & domainSpace() const
access to the domain space
Definition: localmatrix.hh:219
Traits::RangeSpaceType RangeSpaceType
type of range discrete function space
Definition: localmatrix.hh:55
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:128
RangeSpaceType::EntityType RangeEntityType
Definition: localmatrix.hh:66
void bind(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrix.hh:95
RangeSpaceType::BasisFunctionSetType RangeBasisFunctionSetType
type of base function sets within range function space
Definition: localmatrix.hh:63
DomainSpaceType::BasisFunctionSetType DomainBasisFunctionSetType
type of base function sets within domain function space
Definition: localmatrix.hh:59
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:163
void clearRow(const int localRow)
set row to zero values
Definition: localmatrix.hh:139
Traits::RangeFieldType RangeFieldType
type of range field
Definition: localmatrix.hh:49
void finalize()
finalize local matrix setup and possibly add values to real matrix
Definition: localmatrix.hh:270
MatrixColumnObject< Traits > MatrixColumnType
Definition: localmatrix.hh:71
const RangeSpaceType & rangeSpace() const
access to the range space
Definition: localmatrix.hh:226
ThisType LocalMatrixInterfaceType
type of this interface
Definition: localmatrix.hh:43
DomainSpaceType::EntityType DomainEntityType
Definition: localmatrix.hh:65
LocalMatrixTraits Traits
type of traits class
Definition: localmatrix.hh:40
int columns() const
get number of columns within the matrix
Definition: localmatrix.hh:212
const RangeEntityType & rangeEntity() const
Definition: localmatrix.hh:252
const DomainEntityType & domainEntity() const
Definition: localmatrix.hh:246
MatrixColumnType column(const unsigned int col)
return column object for local matrix which contains axpy methods for convenience
Definition: localmatrix.hh:264
void clearCol(const int localCol)
ser column entries to zero
Definition: localmatrix.hh:149
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:240
Default implementation for local matrix classes.
Definition: localmatrix.hh:285
void clearRow(const int localRow)
set row to zero values
Definition: localmatrix.hh:418
void bind(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrix.hh:350
void resort()
resort ordering in global matrix (if possible)
Definition: localmatrix.hh:368
const RangeEntityType & rangeEntity() const
Definition: localmatrix.hh:398
void init(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrix.hh:344
LocalMatrixDefault(const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace, const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
Definition: localmatrix.hh:321
const DomainSpaceType & domainSpace_
Definition: localmatrix.hh:302
int rows() const
get number of rows within the matrix
Definition: localmatrix.hh:374
const DomainEntityType & domainEntity() const
Definition: localmatrix.hh:397
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:392
const RangeSpaceType & rangeSpace() const
access to the range space
Definition: localmatrix.hh:383
DomainBasisFunctionSetType domainBaseSet_
Definition: localmatrix.hh:305
int columns() const
get number of columns within the matrix
Definition: localmatrix.hh:377
const RangeSpaceType & rangeSpace_
Definition: localmatrix.hh:303
void clearCol(const int localCol)
ser column entries to zero
Definition: localmatrix.hh:428
std::optional< DomainEntityType > domainEntity_
Definition: localmatrix.hh:308
BaseType::DomainBasisFunctionSetType DomainBasisFunctionSetType
Definition: localmatrix.hh:295
BaseType::RangeBasisFunctionSetType RangeBasisFunctionSetType
Definition: localmatrix.hh:296
BaseType::RangeEntityType RangeEntityType
Definition: localmatrix.hh:299
std::optional< RangeEntityType > rangeEntity_
Definition: localmatrix.hh:309
LocalMatrixTraits Traits
Definition: localmatrix.hh:290
void unbind()
clear local matrix from entities
Definition: localmatrix.hh:359
const DomainSpaceType & domainSpace() const
access to the domain space
Definition: localmatrix.hh:380
BaseType::DomainEntityType DomainEntityType
Definition: localmatrix.hh:298
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:403
BaseType::DomainSpaceType DomainSpaceType
Definition: localmatrix.hh:292
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:386
BaseType::RangeSpaceType RangeSpaceType
Definition: localmatrix.hh:293
LocalMatrixDefault(const LocalMatrixDefault &org)
Definition: localmatrix.hh:333
LocalMatrixDefault(const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace)
Definition: localmatrix.hh:312
RangeBasisFunctionSetType rangeBaseSet_
Definition: localmatrix.hh:306
void finalize()
finalize local matrix setup and possibly add values to real matrix
Definition: localmatrix.hh:371