dune-fem  2.8-git
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 
8 namespace 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 >
36  BaseType;
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 
219  const DomainSpaceType &domainSpace () const
220  {
221  CHECK_INTERFACE_IMPLEMENTATION( asImp().domainSpace() );
222  return asImp().domainSpace();
223  }
224 
226  const RangeSpaceType &rangeSpace () const
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 
252  const RangeEntityType &rangeEntity () const
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  protected:
310  const RangeSpaceType &rangeSpace )
313  domainBaseSet_(),
314  rangeBaseSet_()
315  {}
316 
317  template< class DomainEntityType, class RangeEntityType >
319  const RangeSpaceType &rangeSpace,
324  domainBaseSet_( domainSpace.basisFunctionSet( domainEntity ) ),
325  rangeBaseSet_( rangeSpace.basisFunctionSet( rangeEntity ) )
326  {}
327 
329  : domainSpace_( org.domainSpace_ ),
330  rangeSpace_( org.rangeSpace_ ),
333  {}
334 
335  public:
338  {
340  }
341 
344  {
345  domainBaseSet_ = domainSpace_.basisFunctionSet( domainEntity );
346  rangeBaseSet_ = rangeSpace_.basisFunctionSet( rangeEntity );
347  }
348 
350  void unbind ()
351  {
354  }
355 
357  void resort () {}
358 
360  void finalize () {}
361 
363  int rows () const { return rangeBaseSet_.size(); }
364 
366  int columns () const { return domainBaseSet_.size(); }
367 
369  const DomainSpaceType &domainSpace () const { return domainSpace_; }
370 
372  const RangeSpaceType &rangeSpace () const { return rangeSpace_; }
373 
376  {
377  return domainBaseSet_;
378  }
379 
382  {
383  return rangeBaseSet_;
384  }
385 
386  const DomainEntityType &domainEntity () const { return domainBasisFunctionSet().entity(); }
387  const RangeEntityType &rangeEntity () const { return rangeBasisFunctionSet().entity(); }
388 
390  template <class DomainLocalFunctionType,
391  class RangeLocalFunctionType>
392  void multiplyAdd(const DomainLocalFunctionType& lhs,
393  RangeLocalFunctionType& rhs) const
394  {
395  const int row = this->rows();
396  const int col = this->columns();
397  for(int i=0; i<row; ++i)
398  {
399  for(int j=0; j<col; ++j)
400  {
401  rhs[i] += this->get(i,j) * lhs[j];
402  }
403  }
404  }
405 
407  void clearRow( const int localRow )
408  {
409  const int col = this->columns();
410  for(int j = 0; j < col; ++j)
411  {
412  this->set(localRow, j, 0);
413  }
414  }
415 
417  void clearCol( const int localCol )
418  {
419  const int row = this->rows();
420  for(int i = 0; i < row; ++i)
421  {
422  this->set(i, localCol, 0);
423  }
424  }
425  };
426 
427  template <class Traits>
429  {
430  public:
432  typedef typename Traits :: LocalMatrixType LocalMatrixType;
433 
435  typedef typename Traits :: RangeSpaceType RangeSpaceType;
436 
438  typedef typename RangeSpaceType :: RangeType RangeType ;
440  typedef typename RangeSpaceType :: JacobianRangeType JacobianRangeType ;
442  typedef typename RangeSpaceType :: RangeFieldType RangeFieldType ;
443 
444  protected:
445  // reference to local matrix
447  // local column number
448  const unsigned int column_;
449 
451  MatrixColumnObject( LocalMatrixType& localMatrix, const unsigned int col )
452  : localMatrix_( localMatrix ),
453  column_( col )
454  {
455  }
456 
457  // at the moment only allow LocalMatrixInterface to construct this object
458  friend class LocalMatrixInterface< Traits >;
459 
460  public:
461 
474  template <class RangeVectorType>
475  void axpy( const RangeVectorType& phi,
476  const Explicit<RangeType>& factor,
477  const RangeFieldType& weight = RangeFieldType(1) )
478  {
479  const unsigned int numBasisFunctions = localMatrix_.rows();
480  assert( phi.size() >= numBasisFunctions );
481  for( unsigned int row = 0; row < numBasisFunctions; ++ row )
482  {
483  RangeFieldType value = factor * phi[ row ];
484  localMatrix_.add( row, column_, weight * value );
485  }
486  }
487 
500  template <class JacobianVectorType>
501  void axpy( const JacobianVectorType& dphi,
502  const JacobianRangeType& jacobianFactor,
503  const RangeFieldType& weight = RangeFieldType(1) )
504  {
505  const unsigned int numBasisFunctions = localMatrix_.rows();
506  assert( dphi.size() >= numBasisFunctions );
507  for( unsigned int row = 0; row < numBasisFunctions; ++ row )
508  {
509  RangeFieldType value = 0;
510  for( int k = 0; k < jacobianFactor.rows; ++k )
511  value += jacobianFactor[ k ] * dphi[ row ][ k ];
512 
513  localMatrix_.add( row, column_, weight * value );
514  }
515  }
516 
531  template <class RangeVectorType, class JacobianVectorType>
532  void axpy( const RangeVectorType& phi,
533  const JacobianVectorType& dphi,
534  const Explicit<RangeType>& factor,
535  const JacobianRangeType& jacobianFactor,
536  const RangeFieldType& weight = RangeFieldType(1) )
537  {
538  const unsigned int numBasisFunctions = localMatrix_.rows();
539  assert( phi.size() >= numBasisFunctions );
540  assert( dphi.size() >= numBasisFunctions );
541  for( unsigned int row = 0; row < numBasisFunctions; ++ row )
542  {
543  RangeFieldType value = factor * phi[ row ];
544  for( int k = 0; k < jacobianFactor.rows; ++k )
545  value += jacobianFactor[ k ] * dphi[ row ][ k ];
546 
547  localMatrix_.add( row, column_, weight * value );
548  }
549  }
550  };
551 
553 
554  } // namespace Fem
555 
556 } // namespace Dune
557 
558 #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:429
LocalMatrixType & localMatrix_
Definition: localmatrix.hh:446
RangeSpaceType ::JacobianRangeType JacobianRangeType
type of jacobian range
Definition: localmatrix.hh:440
void axpy(const RangeVectorType &phi, const Explicit< RangeType > &factor, const RangeFieldType &weight=RangeFieldType(1))
axpy operation for local matrices
Definition: localmatrix.hh:475
RangeSpaceType ::RangeType RangeType
type of range
Definition: localmatrix.hh:438
Traits ::RangeSpaceType RangeSpaceType
type of domain discrete function space
Definition: localmatrix.hh:435
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:532
void axpy(const JacobianVectorType &dphi, const JacobianRangeType &jacobianFactor, const RangeFieldType &weight=RangeFieldType(1))
axpy operation for local matrices
Definition: localmatrix.hh:501
MatrixColumnObject(LocalMatrixType &localMatrix, const unsigned int col)
constructor taking local matrix and column number
Definition: localmatrix.hh:451
Traits ::LocalMatrixType LocalMatrixType
type of local matrix implementation
Definition: localmatrix.hh:432
const unsigned int column_
Definition: localmatrix.hh:448
RangeSpaceType ::RangeFieldType RangeFieldType
type of range field
Definition: localmatrix.hh:442
Interface for local matrix classes.
Definition: localmatrix.hh:32
void unbind()
clear local matrix from entities
Definition: localmatrix.hh:103
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:240
void resort()
resort ordering in global matrix (if possible)
Definition: localmatrix.hh:199
const RangeSpaceType & rangeSpace() const
access to the range space
Definition: localmatrix.hh:226
DomainSpaceType ::BasisFunctionSetType DomainBasisFunctionSetType
type of base function sets within domain function space
Definition: localmatrix.hh:59
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 ::RangeFieldType RangeFieldType
type of range field
Definition: localmatrix.hh:49
LocalMatrixInterface()
constructor
Definition: localmatrix.hh:77
RangeSpaceType ::BasisFunctionSetType RangeBasisFunctionSetType
type of base function sets within range function space
Definition: localmatrix.hh:63
const RangeEntityType & rangeEntity() const
Definition: localmatrix.hh:252
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 DomainEntityType & domainEntity() const
Definition: localmatrix.hh:246
static const Implementation & asImp(const ThisType &other)
Definition: bartonnackmaninterface.hh:27
Traits ::RangeSpaceType RangeSpaceType
type of range discrete function space
Definition: localmatrix.hh:55
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 DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:233
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
Traits ::DomainSpaceType DomainSpaceType
type of domain discrete function space
Definition: localmatrix.hh:52
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
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
void finalize()
finalize local matrix setup and possibly add values to real matrix
Definition: localmatrix.hh:270
MatrixColumnObject< Traits > MatrixColumnType
Definition: localmatrix.hh:71
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
Traits ::LittleBlockType LittleBlockType
Definition: localmatrix.hh:69
int columns() const
get number of columns within the matrix
Definition: localmatrix.hh:212
const DomainSpaceType & domainSpace() const
access to the domain space
Definition: localmatrix.hh:219
Traits ::LocalMatrixType LocalMatrixType
type of local matrix implementation
Definition: localmatrix.hh:46
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
Default implementation for local matrix classes.
Definition: localmatrix.hh:285
void clearRow(const int localRow)
set row to zero values
Definition: localmatrix.hh:407
void bind(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrix.hh:343
void resort()
resort ordering in global matrix (if possible)
Definition: localmatrix.hh:357
const DomainSpaceType & domainSpace() const
access to the domain space
Definition: localmatrix.hh:369
void init(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrix.hh:337
LocalMatrixDefault(const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace, const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
Definition: localmatrix.hh:318
const DomainSpaceType & domainSpace_
Definition: localmatrix.hh:302
int rows() const
get number of rows within the matrix
Definition: localmatrix.hh:363
DomainBasisFunctionSetType domainBaseSet_
Definition: localmatrix.hh:305
int columns() const
get number of columns within the matrix
Definition: localmatrix.hh:366
const DomainEntityType & domainEntity() const
Definition: localmatrix.hh:386
const RangeSpaceType & rangeSpace_
Definition: localmatrix.hh:303
void clearCol(const int localCol)
ser column entries to zero
Definition: localmatrix.hh:417
BaseType::DomainBasisFunctionSetType DomainBasisFunctionSetType
Definition: localmatrix.hh:295
BaseType::RangeBasisFunctionSetType RangeBasisFunctionSetType
Definition: localmatrix.hh:296
BaseType::RangeEntityType RangeEntityType
Definition: localmatrix.hh:299
LocalMatrixTraits Traits
Definition: localmatrix.hh:290
const RangeSpaceType & rangeSpace() const
access to the range space
Definition: localmatrix.hh:372
void unbind()
clear local matrix from entities
Definition: localmatrix.hh:350
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:375
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:392
const RangeEntityType & rangeEntity() const
Definition: localmatrix.hh:387
BaseType::DomainSpaceType DomainSpaceType
Definition: localmatrix.hh:292
BaseType::RangeSpaceType RangeSpaceType
Definition: localmatrix.hh:293
LocalMatrixDefault(const LocalMatrixDefault &org)
Definition: localmatrix.hh:328
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:381
LocalMatrixDefault(const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace)
Definition: localmatrix.hh:309
RangeBasisFunctionSetType rangeBaseSet_
Definition: localmatrix.hh:306
void finalize()
finalize local matrix setup and possibly add values to real matrix
Definition: localmatrix.hh:360