1#ifndef DUNE_FEM_SPMATRIX_HH 
    2#define DUNE_FEM_SPMATRIX_HH 
   15#include <dune/fem/function/adaptivefunction/adaptivefunction.hh> 
   16#include <dune/fem/misc/functor.hh> 
   17#include <dune/fem/operator/common/localmatrix.hh> 
   18#include <dune/fem/operator/common/localmatrixwrapper.hh> 
   19#include <dune/fem/io/file/asciiparser.hh> 
   20#include <dune/fem/io/parameter.hh> 
   21#include <dune/fem/operator/common/operator.hh> 
   22#include <dune/fem/operator/matrix/columnobject.hh> 
   23#include <dune/fem/space/mapper/nonblockmapper.hh> 
   24#include <dune/fem/storage/objectstack.hh> 
   25#include <dune/fem/operator/common/stencil.hh> 
   26#include <dune/fem/operator/matrix/functor.hh> 
   27#include <dune/fem/solver/parameter.hh> 
   36    template <
class T, 
class IndexT = std::size_t,
 
   37              class ValuesVector = std::vector< T >,
 
   38              class IndicesVector = std::vector< IndexT > >
 
   53      static const int firstCol = 0;
 
   59        values_(0), columns_(0), rows_(0), dim_({{0,0}}), maxNzPerRow_(0), compressed_( 
false ), threading_( threading )
 
   65        values_(0), columns_(0), rows_(0), dim_({{0,0}}), maxNzPerRow_(0), compressed_( 
false ), threading_( threading )
 
   79      template <
class Stencil>
 
   85        for( 
const auto& entry : sparsityPattern )
 
   87          const auto& blockRow = entry.first;
 
   88          const auto& blockColumnSet = entry.second;
 
   91          const size_type nextRow = (blockRow + 1) * rowBlockSize;
 
   92          for( 
size_type row = blockRow * rowBlockSize; row < nextRow; ++row )
 
   95            for( 
const auto& blockColEntry : blockColumnSet )
 
   97              size_type col = blockColEntry * colBlockSize;
 
   98              for( 
size_type c = 0; c<colBlockSize; ++c, ++col, ++column )
 
  100                assert( column < endRow( row ) );
 
  101                columns_[ column ] = col ;
 
  123        assert((col>=0) && (col < dim_[1]));
 
  124        assert((row>=0) && (row < dim_[0]));
 
  127        assert( column != defaultCol && column != zeroCol );
 
  129        values_ [ column ] = val;
 
  130        columns_[ column ] = col;
 
  136        assert((col>=0) && (col < dim_[1]));
 
  137        assert((row>=0) && (row < dim_[0]));
 
  140        assert( column != defaultCol && column != zeroCol );
 
  142        values_ [ column ] += val;
 
  143        columns_[ column ] = col;
 
  147      template<
class ArgDFType, 
class DestDFType>
 
  148      void apply(
const ArgDFType& f, DestDFType& ret )
 const 
  150        bool runParallel = threading_;
 
  152        auto doApply = [
this, &f, &ret, &runParallel]()
 
  154          constexpr auto blockSize = ArgDFType::DiscreteFunctionSpaceType::localBlockSize;
 
  157          const auto slice = runParallel ?
 
  158                  sliceBeginEnd( MPIManager::thread(), MPIManager::numThreads(), std::true_type() ) :
 
  159                  sliceBeginEnd( 0, 1, std::true_type() ) ;
 
  162          auto ret_it = ret.dofVector().find( slice.first );
 
  164          const auto& fDofVec = f.dofVector();
 
  165          for(
size_type row = slice.first; row<slice.second; ++row)
 
  169            for(
size_type col = startRow( row ); col<endrow; ++col)
 
  171              const auto realCol = columns_[ col ];
 
  173              if( ! compressed_ && ((realCol == defaultCol) || (realCol == zeroCol)) )
 
  176              const auto blockNr = realCol / blockSize ;
 
  177              const auto dofNr   = realCol % blockSize ;
 
  178              (*ret_it) += values_[ col ] * fDofVec[ blockNr ][ dofNr ];
 
  189            MPIManager :: run ( doApply );
 
  207        assert((col>=0) && (col < dim_[1]));
 
  208        assert((row>=0) && (row < dim_[0]));
 
  211        for( 
size_type i = startRow( row ); i<endrow; ++i )
 
  213          if(columns_[ i ] == col)
 
  222        std::fill( values_.begin(), values_.end(), 0 );
 
  223        for (
auto &c : columns_) c = defaultCol;
 
  229        assert((row>=0) && (row < dim_[0]));
 
  232        for(
size_type idx = startRow( row ); idx<endrow; ++idx )
 
  243        assert((row>=0) && (row < 
rows()) );
 
  244        assert((col>=0) && (col < 
cols()) );
 
  247        assert( column != defaultCol && column != zeroCol );
 
  250        values_ [ column ] *= val;
 
  264        return dim_[0] > 0 ? rows_[ dim_[0] ] : 0;
 
  271        assert( row >= 0 && row < dim_[0] );
 
  272        return endRow( row ) - startRow( row );
 
  279        return std::pair<const field_type, size_type>(values_[index], columns_[index]);
 
  283      void print(std::ostream& s=std::cout, 
unsigned int offset=0)
 const 
  288          for( 
size_type pos = startRow( row ); pos<endrow; ++pos )
 
  291            const auto column(rv.second);
 
  292            const auto value(rv.first);
 
  293            if((std::abs(value) > 1.e-15) && (column != defaultCol))
 
  294              s << row+offset << 
" " << column+offset << 
" " << value << std::endl;
 
  299      template <
class SizeT, 
class NumericT >
 
  300      void fillCSRStorage( std::vector< std::map<SizeT, NumericT> >& matrix )
 const 
  302        matrix.resize( dim_[0] );
 
  305        for(
size_type row = 0; row<dim_[ 0 ]; ++row )
 
  307          auto& matRow = matrix[ row ];
 
  309          for(
size_type col = startRow( row ); col<endrow; ++col)
 
  311            const size_type realCol = columns_[ col ];
 
  313            if( ! compressed_ && (realCol == defaultCol || realCol == zeroCol) )
 
  316            matRow[ realCol ] = values_[ thisCol ];
 
  323        if( ! compressed_ && (dim_[0] != 0) && (dim_[1] != 0))
 
  327          for( newpos = startRow( 0 ); newpos < endRow( 0 ); ++newpos )
 
  329            if( columns_[ newpos ] == defaultCol )
 
  333          for( 
size_type row = 1; row<dim_[0]; ++row )
 
  338            rows_[ row ] = newpos;
 
  339            for(; col<endrow; ++col, ++newpos )
 
  341              if( columns_[ col ] == defaultCol )
 
  344              assert( newpos <= col );
 
  345              values_ [ newpos ] = values_ [ col ];
 
  346              columns_[ newpos ] = columns_[ col ];
 
  349          rows_[ dim_[0] ] = newpos ;
 
  364        return rows_[ row+1 ];
 
  367      std::tuple< ValuesVector&, IndicesVector&, IndicesVector& > exportCRS()
 
  371        return std::tie(values_,columns_,rows_);
 
  375      template<
class DiagType, 
class ArgDFType, 
class DestDFType, 
class WType>
 
  376      void forwardIterative(
const DiagType& diagInv, 
const ArgDFType& b, 
const DestDFType& xold, DestDFType& xnew, 
const WType& w )
 const 
  378        parallelIterative(diagInv, b, xold, xnew, w, std::true_type() );
 
  382      template<
class DiagType, 
class ArgDFType, 
class DestDFType, 
class WType>
 
  383      void backwardIterative(
const DiagType& diagInv, 
const ArgDFType& b, 
const DestDFType& xold, DestDFType& xnew, 
const WType& w )
 const 
  385        parallelIterative(diagInv, b, xold, xnew, w, std::false_type() );
 
  390      std::pair< size_type, size_type > sliceBeginEnd(
const size_type thread,  
const size_type numThreads, std::true_type )
 const 
  393        const size_type sliceBegin = (thread * sliceSize) ;
 
  394        const size_type sliceEnd   = (thread == numThreads-1 ) ? this->
rows(): (sliceBegin + sliceSize);
 
  395        return std::make_pair( sliceBegin, sliceEnd );
 
  399      std::pair< size_type, size_type > sliceBeginEnd(
const size_type thread, 
const size_type numThreads, std::false_type )
 const 
  401        std::pair< size_type, size_type > beginEnd = sliceBeginEnd( thread, numThreads, std::true_type() );
 
  402        return std::make_pair( beginEnd.second-1, beginEnd.first-1 );
 
  405      template<
class DiagType, 
class ArgDFType, 
class DestDFType, 
class WType, 
bool forward >
 
  406      void parallelIterative(
const DiagType& diagInv, 
const ArgDFType& b, 
const DestDFType& xold, DestDFType& xnew,
 
  407                             const WType& w, std::integral_constant<bool, forward> direction )
 const 
  409        bool runParallel = threading_ && (&xold != &xnew) ; 
 
  411        auto doIterate = [
this, &diagInv, &b, &xold, &xnew, &w, &direction, &runParallel] ()
 
  414          const auto slice = runParallel ?
 
  415                  sliceBeginEnd( MPIManager::thread(), MPIManager::numThreads(), direction ) :
 
  416                  sliceBeginEnd( 0, 1, direction ) ;
 
  419                               b.dofVector().find( slice.first ),
 
  421                               xnew.dofVector().find( slice.first ),
 
  432            MPIManager :: run ( doIterate );
 
  434          catch ( 
const SingleThreadModeError& e )
 
  448      template<
class DiagIt, 
class ArgDFIt, 
class DestDFType, 
class DestDFIt,
 
  449               class WType, 
bool forward>
 
  453                               std::integral_constant<bool, forward> )
 const 
  455        constexpr auto blockSize = DestDFType::DiscreteFunctionSpaceType::localBlockSize;
 
  457        const auto nextRow = [&diag, &xit, &bit](
size_type &row)
 
  459          if constexpr ( forward )
 
  461            ++diag; ++xit; ++bit; ++row;
 
  465            --diag; --xit; --bit; --row;
 
  469        const auto& xOldVec = xold.dofVector();
 
  470        for(; row != end; nextRow(row))
 
  475          for(
size_type col = startRow( row ); col<endrow; ++col)
 
  477            const auto realCol = columns_[ col ];
 
  479            if( (realCol == row ) || (! compressed_ && ((realCol == defaultCol) || (realCol == zeroCol))) )
 
  482            const auto blockNr = realCol / blockSize ;
 
  483            const auto dofNr   = realCol % blockSize ;
 
  485            rhs -= values_[ col ] * xOldVec[ blockNr ][ dofNr ] ;
 
  488          (*xit) = w * (rhs * (*diag));
 
  494        constexpr auto colVal = defaultCol;
 
  495        values_.resize( 
rows*nz , 0 );
 
  496        columns_.resize( 
rows*nz , colVal );
 
  497        rows_.resize( 
rows+1 , 0 );
 
  501          rows_[ i ] = rows_[ i-1 ] + nz ;
 
  507        maxNzPerRow_ = nz+firstCol;
 
  513        assert((col>=0) && (col < dim_[1]));
 
  514        assert((row>=0) && (row < dim_[0]));
 
  519        for( ;  i < endR; ++i )
 
  521          if( columns_[ i ] == defaultCol || columns_[ i ] == zeroCol || columns_[ i ] == col )
 
  567      ValuesVector  values_;
 
  568      IndicesVector columns_;
 
  571      std::array<size_type,2> dim_;
 
  574      const bool threading_;
 
  580    template< 
class DomainSpace, 
class RangeSpace,
 
  585      template< 
class MatrixObject >
 
  588      template< 
class MatrixObject >
 
  592      typedef DomainSpace DomainSpaceType;
 
  593      typedef RangeSpace RangeSpaceType;
 
  594      typedef typename DomainSpaceType::EntityType DomainEntityType;
 
  595      typedef typename RangeSpaceType::EntityType RangeEntityType;
 
  596      typedef typename DomainSpaceType::EntityType ColumnEntityType;
 
  597      typedef typename RangeSpaceType::EntityType RowEntityType;
 
  599      typedef typename DomainSpaceType::BlockMapperType DomainBlockMapperType;
 
  601      typedef typename RangeSpaceType::BlockMapperType RangeBlockMapperType;
 
  609      static const size_type domainLocalBlockSize = DomainSpaceType::dimRange;
 
  610      static const size_type rangeLocalBlockSize  = RangeSpaceType::dimRange;
 
  620      typedef LocalMatrixWrapper< LocalMatrixStackType > LocalMatrixType;
 
  621      typedef ColumnObject< ThisType > LocalColumnObjectType;
 
  626                             const SolverParameter& param = SolverParameter() )
 
  629        domainMapper_( domainSpace_.blockMapper() ),
 
  630        rangeMapper_( rangeSpace_.blockMapper() ),
 
  632        matrix_( param.threading() ),
 
  633        localMatrixStack_( *this )
 
  655      void finalizeAssembly()
 const { 
const_cast< ThisType& 
> (*this).compress(); }
 
  669        return new ObjectType( *
this, domainSpace_, rangeSpace_, domainMapper_, rangeMapper_ );
 
  676      [[deprecated(
"Use TemporaryLocalMatrix,LocalContribution and {get,add,set}LocalMatrix")]]
 
  677      LocalMatrixType 
localMatrix( 
const DomainEntityType &domainEntity, 
const RangeEntityType &rangeEntity )
 const 
  679        return LocalMatrixType( localMatrixStack_, domainEntity, rangeEntity );
 
  686      [[deprecated(
"Use TemporaryLocalMatrix,LocalContribution and {get,add,set}LocalMatrix")]]
 
  689        return LocalMatrixType( localMatrixStack_ );
 
  693      LocalColumnObjectType 
localColumn( 
const DomainEntityType &domainEntity )
 const 
  695        return LocalColumnObjectType( *
this, domainEntity );
 
  698      void unitRow( 
const size_type row )
 
  700        for( 
unsigned int i=0, r = row * domainLocalBlockSize; i<domainLocalBlockSize; ++i, ++r )
 
  702          matrix_.clearRow( r );
 
  703          matrix_.set( r, r, 1.0 );
 
  707      template <
class LocalBlock>
 
  708      void addBlock( 
const size_type row, 
const size_type col, 
const LocalBlock& block )
 
  710        std::array< size_type, rangeLocalBlockSize  > rows;
 
  711        std::array< size_type, domainLocalBlockSize > cols;
 
  712        for( 
unsigned int i=0, r = row * domainLocalBlockSize, c = col * domainLocalBlockSize; i<domainLocalBlockSize; ++i, ++r, ++c )
 
  718        for( 
unsigned int i=0; i<domainLocalBlockSize; ++i )
 
  720          for( 
unsigned int j=0; j<domainLocalBlockSize; ++j )
 
  722            matrix_.add( rows[ i ], cols[ j ], block[ i ][ j ]);
 
  727      template <
class LocalBlock>
 
  728      void setBlock( 
const size_type row, 
const size_type col, 
const LocalBlock& block )
 
  730        std::array< size_type, rangeLocalBlockSize  > rows;
 
  731        std::array< size_type, domainLocalBlockSize > cols;
 
  732        for( 
unsigned int i=0, r = row * domainLocalBlockSize, c = col * domainLocalBlockSize; i<domainLocalBlockSize; ++i, ++r, ++c )
 
  738        for( 
unsigned int i=0; i<domainLocalBlockSize; ++i )
 
  740          for( 
unsigned int j=0; j<domainLocalBlockSize; ++j )
 
  742            matrix_.set( rows[ i ], cols[ j ], block[ i ][ j ]);
 
  747      template< 
class LocalMatrix >
 
  748      void addLocalMatrix ( 
const DomainEntityType &domainEntity, 
const RangeEntityType &rangeEntity, 
const LocalMatrix &localMat )
 
  750        auto functor = [ &localMat, this ] ( std::pair< int, int > local, 
const std::pair< size_type, size_type >& global )
 
  752          matrix_.add( global.first, global.second, localMat.get( local.first, local.second ) );
 
  755        rangeMapper_.mapEach( rangeEntity, makePairFunctor( domainMapper_, domainEntity, functor ) );
 
  758      template< 
class LocalMatrix, 
class Scalar >
 
  759      void addScaledLocalMatrix ( 
const DomainEntityType &domainEntity, 
const RangeEntityType &rangeEntity, 
const LocalMatrix &localMat, 
const Scalar &s )
 
  761        auto functor = [ &localMat, &s, this ] ( std::pair< int, int > local, 
const std::pair< size_type, size_type >& global )
 
  763          matrix_.add( global.first, global.second, s * localMat.get( local.first, local.second ) );
 
  766        rangeMapper_.mapEach( rangeEntity, makePairFunctor( domainMapper_, domainEntity, functor ) );
 
  769      template< 
class LocalMatrix >
 
  770      void setLocalMatrix ( 
const DomainEntityType &domainEntity, 
const RangeEntityType &rangeEntity, 
const LocalMatrix &localMat )
 
  772        auto functor = [ &localMat, this ] ( std::pair< int, int > local, 
const std::pair< size_type, size_type >& global )
 
  774          matrix_.set( global.first, global.second, localMat.get( local.first, local.second ) );
 
  777        rangeMapper_.mapEach( rangeEntity, makePairFunctor( domainMapper_, domainEntity, functor ) );
 
  780      template< 
class LocalMatrix >
 
  781      void getLocalMatrix ( 
const DomainEntityType &domainEntity, 
const RangeEntityType &rangeEntity, LocalMatrix &localMat )
 const 
  783        auto functor = [ &localMat, this ] ( std::pair< int, int > local, 
const std::pair< size_type, size_type >& global )
 
  785          localMat.set( local.first, local.second, matrix_.get( global.first, global.second ) );
 
  788        rangeMapper_.mapEach( rangeEntity, makePairFunctor( domainMapper_, domainEntity, functor ) );
 
  801      void reserve (
const std::vector< Set >& sparsityPattern )
 
  807      template <
class Stencil>
 
  810        if( sequence_ != domainSpace_.sequence() )
 
  813          if( (domainSpace_.begin() != domainSpace_.end()) && (rangeSpace_.begin() != rangeSpace_.end()) )
 
  818              std::cout << 
"Reserve Matrix with (" << rangeSpace_.size() << 
"," << domainSpace_.size()<< 
")" << std::endl;
 
  819              std::cout << 
"Max number of base functions = (" << rangeMapper_.maxNumDofs() << 
"," 
  820                << domainMapper_.maxNumDofs() << 
")" << std::endl;
 
  824            const auto nonZeros = std::max( 
static_cast<size_type
>(stencil.
maxNonZerosEstimate()*DomainSpaceType::localBlockSize),
 
  825                                            matrix_.maxNzPerRow() );
 
  826            matrix_.reserve( rangeSpace_.size(), domainSpace_.size(), nonZeros );
 
  827            matrix_.fillPattern( stencil, RangeSpaceType::localBlockSize, DomainSpaceType::localBlockSize );
 
  829          sequence_ = domainSpace_.sequence();
 
  834      template< 
class DomainFunction, 
class RangeFunction >
 
  835      void apply( 
const DomainFunction &arg, RangeFunction &dest )
 const 
  838        matrix_.apply( arg, dest );
 
  845      template < 
class DiscreteFunctionType >
 
  848        assert( matrix_.rows() == matrix_.cols() );
 
  849        const auto dofEnd = diag.
dend();
 
  851        for( 
auto dofIt = diag.
dbegin(); dofIt != dofEnd; ++dofIt, ++row )
 
  853          assert( row < matrix_.rows() );
 
  854          (*dofIt) = matrix_.get( row, row );
 
  858      template <
class Container>
 
  859      void setUnitRows( 
const Container& unitRows, 
const Container& auxRows )
 
  861        for (
const auto& r : unitRows )
 
  864          matrix_.set(r, r, 1.0);
 
  867        for (
const auto& r : auxRows )
 
  885      const DomainSpaceType &domainSpace_;
 
  886      const RangeSpaceType &rangeSpace_;
 
  887      DomainMapperType domainMapper_ ;
 
  888      RangeMapperType rangeMapper_ ;
 
  890      mutable MatrixType matrix_;
 
  891      mutable LocalMatrixStackType localMatrixStack_;
 
  897    template< 
class DomainSpace, 
class RangeSpace, 
class Matrix >
 
  898    template< 
class MatrixObject >
 
  901      typedef DomainSpace DomainSpaceType;
 
  902      typedef RangeSpace RangeSpaceType;
 
  908      typedef typename RangeSpaceType::RangeFieldType RangeFieldType;
 
  909      typedef RangeFieldType LittleBlockType;
 
  918    template< 
class DomainSpace, 
class RangeSpace, 
class Matrix >
 
  919    template< 
class MatrixObject >
 
  951      typedef std::vector< typename RangeMapperType::SizeType > RowIndicesType;
 
  952      typedef std::vector< typename DomainMapperType::SizeType > ColumnIndicesType;
 
  961        matrix_( matrixObject.
matrix() ),
 
  962        domainMapper_( domainMapper ),
 
  963        rangeMapper_( rangeMapper )
 
  968      void init( 
const DomainEntityType &domainEntity, 
const RangeEntityType &rangeEntity )
 
  971        BaseType::init( domainEntity, rangeEntity );
 
  973        rowIndices_.resize( rangeMapper_.numDofs( rangeEntity ) );
 
  974        rangeMapper_.mapEach( rangeEntity, AssignFunctor< RowIndicesType >( rowIndices_ ) );
 
  976        columnIndices_.resize( domainMapper_.numDofs( domainEntity ) );
 
  977        domainMapper_.mapEach( domainEntity, AssignFunctor< ColumnIndicesType >( columnIndices_ ) );
 
  983        return rowIndices_.size();
 
  989        return columnIndices_.size();
 
  993      void add(size_type localRow, size_type localCol, 
DofType value)
 
  995        assert( value == value );
 
  996        assert( (localRow >= 0) && (localRow < rows()) );
 
  997        assert( (localCol >= 0) && (localCol < columns()) );
 
  998        matrix_.add( rowIndices_[ localRow ], columnIndices_[ localCol ], value );
 
 1004        assert( (localRow >= 0) && (localRow < rows()) );
 
 1005        assert( (localCol >= 0) && (localCol < columns()) );
 
 1006        return matrix_.get( rowIndices_[ localRow ], columnIndices_[ localCol ] );
 
 1012        assert( (localRow >= 0) && (localRow < rows()) );
 
 1013        assert( (localCol >= 0) && (localCol < columns()) );
 
 1014        matrix_.set( rowIndices_[ localRow ], columnIndices_[ localCol ], value );
 
 1020        assert( (localRow >= 0) && (localRow < rows()) );
 
 1021        matrix_.unitRow( rowIndices_[ localRow ] );
 
 1027        assert( (localRow >= 0) && (localRow < rows()) );
 
 1028        matrix_.clearRow( rowIndices_[localRow]);
 
 1034        assert( (localCol >= 0) && (localCol < columns()) );
 
 1035        matrix_.clearCol( columnIndices_[localCol] );
 
 1041        const size_type nrows = rows();
 
 1042        for(size_type i=0; i < nrows; ++i )
 
 1043          matrix_.clearRow( rowIndices_[ i ] );
 
 1058        const size_type nrows = rows();
 
 1059        const size_type ncols = columns();
 
 1060        for(size_type i=0; i < nrows; ++i )
 
 1062          for( size_type j=0; j < ncols; ++j )
 
 1064            scale(i, j, value );
 
 1073        assert( (localRow >= 0) && (localRow < rows()) );
 
 1074        assert( (localCol >= 0) && (localCol < columns()) );
 
 1075        matrix_.scale( rowIndices_[ localRow ], columnIndices_[ localCol ], value );
 
 1082      RowIndicesType rowIndices_;
 
 1083      ColumnIndicesType columnIndices_;
 
ConstDofIteratorType dbegin() const
Obtain the constant iterator pointing to the first dof.
Definition: discretefunction.hh:761
 
ConstDofIteratorType dend() const
Obtain the constant iterator pointing to the last dof.
Definition: discretefunction.hh:773
 
Default implementation for local matrix classes.
Definition: localmatrix.hh:287
 
Exception thrown when a code segment that is supposed to be only accessed in single thread mode is ac...
Definition: mpimanager.hh:43
 
LocalMatrix.
Definition: spmatrix.hh:922
 
void clearRow(size_type localRow)
set matrix row to zero
Definition: spmatrix.hh:1025
 
void add(size_type localRow, size_type localCol, DofType value)
add value to matrix entry
Definition: spmatrix.hh:993
 
MatrixObjectType::MatrixType MatrixType
type of matrix
Definition: spmatrix.hh:935
 
void clearCol(size_type localCol)
set matrix column to zero
Definition: spmatrix.hh:1032
 
void resort()
resort all global rows of matrix to have ascending numbering
Definition: spmatrix.hh:1047
 
size_type columns() const
return number of columns
Definition: spmatrix.hh:987
 
size_type rows() const
return number of rows
Definition: spmatrix.hh:981
 
Traits::RangeFieldType RangeFieldType
type of entries of little blocks
Definition: spmatrix.hh:938
 
DofType get(size_type localRow, size_type localCol) const
get matrix entry
Definition: spmatrix.hh:1002
 
MatrixObject MatrixObjectType
type of matrix object
Definition: spmatrix.hh:925
 
Traits::DomainMapperType DomainMapperType
type of nonblocked domain mapper
Definition: spmatrix.hh:947
 
Traits::RangeMapperType RangeMapperType
type of nonblocked domain mapper
Definition: spmatrix.hh:949
 
LocalMatrixTraits< MatrixObjectType > Traits
type of the traits
Definition: spmatrix.hh:928
 
LocalMatrix(const MatrixObjectType &matrixObject, const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace, const DomainMapperType &domainMapper, const RangeMapperType &rangeMapper)
constructor
Definition: spmatrix.hh:955
 
void scale(const DofType &value)
scale local matrix with a certain value
Definition: spmatrix.hh:1056
 
RangeFieldType DofType
type of the DoFs
Definition: spmatrix.hh:941
 
void scale(size_type localRow, size_type localCol, DofType value)
scale matrix entry with value
Definition: spmatrix.hh:1071
 
void clear()
clear all entries belonging to local matrix
Definition: spmatrix.hh:1039
 
Traits::LittleBlockType LittleBlockType
type of little blocks
Definition: spmatrix.hh:944
 
void set(size_type localRow, size_type localCol, DofType value)
set matrix entry to value
Definition: spmatrix.hh:1010
 
void unitRow(size_type localRow)
set matrix row to zero except diagonla entry
Definition: spmatrix.hh:1018
 
SparseRowMatrixObject.
Definition: spmatrix.hh:583
 
const DomainSpaceType & domainSpace() const
get domain space (i.e. space that builds the rows)
Definition: spmatrix.hh:637
 
LocalMatrixType localMatrix() const
Definition: spmatrix.hh:687
 
MatrixType & exportMatrix() const
get reference to storage object
Definition: spmatrix.hh:659
 
void apply(const DomainFunction &arg, RangeFunction &dest) const
apply matrix to discrete function
Definition: spmatrix.hh:835
 
SparseRowMatrixObject(const DomainSpaceType &domainSpace, const RangeSpaceType &rangeSpace, const SolverParameter ¶m=SolverParameter())
construct matrix object
Definition: spmatrix.hh:624
 
LocalColumnObjectType localColumn(const DomainEntityType &domainEntity) const
get local column
Definition: spmatrix.hh:693
 
void extractDiagonal(DiscreteFunctionType &diag) const
Definition: spmatrix.hh:846
 
LocalMatrixType localMatrix(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity) const
Definition: spmatrix.hh:677
 
ObjectType * newObject() const
interface method from LocalMatrixFactory
Definition: spmatrix.hh:667
 
void reserve(const Stencil &stencil, bool verbose=false)
reserve memory
Definition: spmatrix.hh:808
 
void compress()
compress matrix to a real CRS format
Definition: spmatrix.hh:798
 
void resort()
resort row numbering in matrix to have ascending numbering
Definition: spmatrix.hh:877
 
void clear()
clear matrix
Definition: spmatrix.hh:792
 
const RangeSpaceType & rangeSpace() const
get range space (i.e. space that builds the columns)
Definition: spmatrix.hh:643
 
MatrixType & matrix() const
get reference to storage object, for internal use
Definition: spmatrix.hh:650
 
SparseRowMatrix.
Definition: spmatrix.hh:40
 
void print(std::ostream &s=std::cout, unsigned int offset=0) const
print matrix
Definition: spmatrix.hh:283
 
size_type colIndex(size_type row, size_type col)
returns local col index for given global (row,col)
Definition: spmatrix.hh:511
 
std::pair< const field_type, size_type > realValue(size_type index) const
Definition: spmatrix.hh:277
 
SparseRowMatrix(const bool threading=true)
construct matrix of zero size
Definition: spmatrix.hh:58
 
void clearRow(const size_type row)
set all entries in row to zero
Definition: spmatrix.hh:227
 
IndexT size_type
matrix index type
Definition: spmatrix.hh:45
 
void add(const size_type row, const size_type col, const field_type val)
add value to row,col entry
Definition: spmatrix.hh:134
 
void apply(const ArgDFType &f, DestDFType &ret) const
ret = A*f
Definition: spmatrix.hh:148
 
size_type numNonZeros(size_type row) const
Definition: spmatrix.hh:269
 
void reserve(const size_type rows, const size_type cols, const size_type nz)
reserve memory for given rows, columns and number of non zeros
Definition: spmatrix.hh:71
 
void clear()
set all matrix entries to zero
Definition: spmatrix.hh:220
 
size_type numNonZeros() const
Definition: spmatrix.hh:262
 
void forwardIterative(const DiagType &diagInv, const ArgDFType &b, const DestDFType &xold, DestDFType &xnew, const WType &w) const
Apply Jacobi/SOR method.
Definition: spmatrix.hh:376
 
field_type get(const size_type row, const size_type col) const
return value of entry (row,col)
Definition: spmatrix.hh:205
 
void doParallelIterative(DiagIt diag, ArgDFIt bit, const DestDFType &xold, DestDFIt xit, const WType &w, size_type row, const size_type end, std::integral_constant< bool, forward >) const
Apply Jacobi/SOR method.
Definition: spmatrix.hh:450
 
void set(const size_type row, const size_type col, const field_type val)
set entry to value (also setting 0 will result in an entry)
Definition: spmatrix.hh:121
 
void resize(size_type rows, size_type cols, size_type nz)
resize matrix
Definition: spmatrix.hh:492
 
size_type rows() const
return number of rows
Definition: spmatrix.hh:109
 
size_type cols() const
return number of columns
Definition: spmatrix.hh:115
 
void scale(const size_type row, const size_type col, const field_type val)
scale all entries in row with a given value
Definition: spmatrix.hh:241
 
size_type maxNzPerRow() const
Definition: spmatrix.hh:255
 
void backwardIterative(const DiagType &diagInv, const ArgDFType &b, const DestDFType &xold, DestDFType &xnew, const WType &w) const
Apply Jacobi/SOR method.
Definition: spmatrix.hh:383
 
SparseRowMatrix(const size_type rows, const size_type cols, const size_type nz, const bool threading=true)
Definition: spmatrix.hh:64
 
ThisType MatrixBaseType
Definition: spmatrix.hh:49
 
void fillPattern(const Stencil &stencil, const size_type rowBlockSize, const size_type colBlockSize)
reserve memory for given rows, columns and number of non zeros
Definition: spmatrix.hh:80
 
T field_type
matrix field type
Definition: spmatrix.hh:43
 
a simple wrapper class for sparsity patterns provide as vector< set< size_t > >
Definition: stencil.hh:234
 
default implementation for a general operator stencil
Definition: stencil.hh:35
 
const GlobalStencilType & globalStencil() const
Return the full stencil.
Definition: stencil.hh:116
 
int maxNonZerosEstimate() const
Return an upper bound for the maximum number of non-zero entries in all rows.
Definition: stencil.hh:123
 
forward declaration
Definition: discretefunction.hh:51
 
A dense n x m matrix.
Definition: fmatrix.hh:117
 
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:375
 
A generic dynamic dense matrix.
Definition: matrix.hh:561
 
A::size_type size_type
Type for indices and sizes.
Definition: matrix.hh:577
 
typename Imp::BlockTraits< T >::field_type field_type
Export the type representing the underlying field.
Definition: matrix.hh:565
 
Default exception for dummy implementations.
Definition: exceptions.hh:357
 
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
 
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:485
 
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: interface.hh:235
 
Dune namespace.
Definition: alignedallocator.hh:13
 
LocalMatrixTraits.
Definition: spmatrix.hh:900