1#ifndef DUNE_FEM_LOCALMATRIX_HH
2#define DUNE_FEM_LOCALMATRIX_HH
7#include <dune/fem/misc/bartonnackmaninterface.hh>
8#include "../../common/explicitfieldvector.hh"
21 template <
class Traits>
22 class MatrixColumnObject ;
30 template<
class LocalMatrixTraits >
32 :
public BartonNackmanInterface< LocalMatrixInterface< LocalMatrixTraits >,
33 typename LocalMatrixTraits::LocalMatrixType >
36 typedef BartonNackmanInterface< LocalMatrixInterface< LocalMatrixTraits >,
37 typename LocalMatrixTraits::LocalMatrixType >
60 typedef typename DomainSpaceType :: BasisFunctionSetType
64 typedef typename RangeSpaceType :: BasisFunctionSetType
67 typedef typename DomainSpaceType::EntityType DomainEntityType;
68 typedef typename RangeSpaceType::EntityType RangeEntityType;
73 typedef MatrixColumnObject< Traits > MatrixColumnType;
76 using BaseType::asImp;
87 void init (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity )
90 ( asImp().
init( domainEntity, rangeEntity ) );
97 void bind (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity )
100 ( asImp().
bind( domainEntity, rangeEntity ) );
116 void add (
const int localRow,
121 asImp().
add(localRow,localCol,value));
130 void set (
const int localRow,
135 asImp().
set(localRow,localCol,value));
163 template <
class DomainLocalFunctionType,
164 class RangeLocalFunctionType>
166 RangeLocalFunctionType& rhs)
const
179 const int localCol )
const
181 CHECK_INTERFACE_IMPLEMENTATION( asImp().
get(localRow,localCol));
182 return asImp().get(localRow,localCol);
191 asImp().
scale( scalar ) );
210 return asImp().rows();
217 return asImp().columns();
223 CHECK_INTERFACE_IMPLEMENTATION( asImp().
domainSpace() );
224 return asImp().domainSpace();
230 CHECK_INTERFACE_IMPLEMENTATION( asImp().
rangeSpace() );
231 return asImp().rangeSpace();
238 return asImp().domainBasisFunctionSet();
245 return asImp().rangeBasisFunctionSet();
248 const DomainEntityType &domainEntity ()
const
250 CHECK_INTERFACE_IMPLEMENTATION( asImp().domainEntity() );
251 return asImp().domainEntity();
254 const RangeEntityType &rangeEntity ()
const
256 CHECK_INTERFACE_IMPLEMENTATION( asImp().rangeEntity() );
257 return asImp().rangeEntity();
266 MatrixColumnType
column(
const unsigned int col )
268 return MatrixColumnType( asImp(), col );
284 template<
class LocalMatrixTraits >
292 typedef LocalMatrixTraits
Traits;
300 typedef typename BaseType::DomainEntityType DomainEntityType;
301 typedef typename BaseType::RangeEntityType RangeEntityType;
304 const DomainSpaceType &domainSpace_;
305 const RangeSpaceType &rangeSpace_;
310 std::optional< DomainEntityType > domainEntity_;
311 std::optional< RangeEntityType > rangeEntity_;
322 template<
class DomainEntityType,
class RangeEntityType >
325 const DomainEntityType &domainEntity,
326 const RangeEntityType &rangeEntity )
332 bind( domainEntity, rangeEntity );
336 : domainSpace_( org.domainSpace_ ),
337 rangeSpace_( org.rangeSpace_ ),
338 domainBaseSet_( org.domainBaseSet_ ),
339 rangeBaseSet_( org.rangeBaseSet_ ),
340 domainEntity_( org.domainEntity_ ),
341 rangeEntity_( org.rangeEntity_ )
346 void init (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity )
348 bind( domainEntity, rangeEntity );
352 void bind (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity )
354 domainBaseSet_ = domainSpace_.basisFunctionSet( domainEntity );
355 rangeBaseSet_ = rangeSpace_.basisFunctionSet( rangeEntity );
356 domainEntity_.emplace(domainEntity);
357 rangeEntity_.emplace(rangeEntity);
365 domainEntity_.reset();
366 rangeEntity_.reset();
376 int rows ()
const {
return rangeBaseSet_.size(); }
379 int columns ()
const {
return domainBaseSet_.size(); }
382 const DomainSpaceType &
domainSpace ()
const {
return domainSpace_; }
385 const RangeSpaceType &
rangeSpace ()
const {
return rangeSpace_; }
390 return domainBaseSet_;
396 return rangeBaseSet_;
399 const DomainEntityType &domainEntity ()
const {
return domainEntity_.value(); }
400 const RangeEntityType &rangeEntity ()
const {
return rangeEntity_.value(); }
403 template <
class DomainLocalFunctionType,
404 class RangeLocalFunctionType>
406 RangeLocalFunctionType& rhs)
const
408 const int row = this->
rows();
409 const int col = this->
columns();
410 for(
int i=0; i<row; ++i)
412 for(
int j=0; j<col; ++j)
414 rhs[i] += this->
get(i,j) * lhs[j];
422 const int col = this->
columns();
423 for(
int j = 0; j < col; ++j)
425 this->
set(localRow, j, 0);
432 const int row = this->
rows();
433 for(
int i = 0; i < row; ++i)
435 this->
set(i, localCol, 0);
440 template <
class Traits>
441 class MatrixColumnObject
445 typedef typename Traits :: LocalMatrixType LocalMatrixType;
448 typedef typename Traits :: RangeSpaceType RangeSpaceType;
451 typedef typename RangeSpaceType :: RangeType RangeType ;
453 typedef typename RangeSpaceType :: JacobianRangeType JacobianRangeType ;
455 typedef typename RangeSpaceType :: RangeFieldType RangeFieldType ;
459 LocalMatrixType& localMatrix_;
461 const unsigned int column_;
464 MatrixColumnObject( LocalMatrixType& localMatrix,
const unsigned int col )
465 : localMatrix_( localMatrix ),
471 friend class LocalMatrixInterface< Traits >;
487 template <
class RangeVectorType>
488 void axpy(
const RangeVectorType& phi,
489 const Explicit<RangeType>& factor,
490 const RangeFieldType& weight = RangeFieldType(1) )
492 const unsigned int numBasisFunctions = localMatrix_.rows();
493 assert( phi.size() >= numBasisFunctions );
494 for(
unsigned int row = 0; row < numBasisFunctions; ++ row )
496 RangeFieldType value = factor * phi[ row ];
497 localMatrix_.add( row, column_, weight * value );
513 template <
class JacobianVectorType>
514 void axpy(
const JacobianVectorType& dphi,
515 const JacobianRangeType& jacobianFactor,
516 const RangeFieldType& weight = RangeFieldType(1) )
518 const unsigned int numBasisFunctions = localMatrix_.rows();
519 assert( dphi.size() >= numBasisFunctions );
520 for(
unsigned int row = 0; row < numBasisFunctions; ++ row )
522 RangeFieldType value = 0;
523 for(
int k = 0; k < jacobianFactor.rows; ++k )
524 value += jacobianFactor[ k ] * dphi[ row ][ k ];
526 localMatrix_.add( row, column_, weight * value );
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) )
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 )
556 RangeFieldType value = factor * phi[ row ];
557 for(
int k = 0; k < jacobianFactor.rows; ++k )
558 value += jacobianFactor[ k ] * dphi[ row ][ k ];
560 localMatrix_.add( row, column_, weight * value );
#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