1#ifndef DUNE_FEM_ISTLMATRIXWRAPPER_HH
2#define DUNE_FEM_ISTLMATRIXWRAPPER_HH
24#include <dune/istl/experimental/bcrsmatrix.hh>
50 template<
class MatrixObject >
51 class ISTLLocalMatrix;
53 template <
class DomainSpaceImp,
class RangeSpaceImp,
56 class ISTLMatrixObject;
61 template <
class LittleBlockType,
class RowDiscreteFunctionImp,
class ColDiscreteFunctionImp = RowDiscreteFunctionImp>
62 class ImprovedBCRSMatrix :
63#ifdef USE_IBCRS_MATRIX
66 public BCRSMatrix<LittleBlockType>
69 friend struct MatrixDimension<ImprovedBCRSMatrix>;
71 typedef RowDiscreteFunctionImp RowDiscreteFunctionType;
72 typedef ColDiscreteFunctionImp ColDiscreteFunctionType;
74#ifdef USE_IBCRS_MATRIX
77 typedef BCRSMatrix<LittleBlockType> BaseType;
80 typedef BaseType MatrixBaseType;
81 typedef typename BaseType :: RowIterator RowIteratorType ;
82 typedef typename BaseType :: ColIterator ColIteratorType ;
84 typedef ImprovedBCRSMatrix< LittleBlockType, RowDiscreteFunctionImp, ColDiscreteFunctionImp > ThisType;
86 typedef typename BaseType :: size_type
size_type;
91 typedef typename BaseType::field_type field_type;
94 typedef typename BaseType::block_type block_type;
97 typedef typename BaseType:: allocator_type allocator_type;
100 typedef typename BaseType :: row_type row_type;
103 typedef typename BaseType :: ColIterator ColIterator;
106 typedef typename BaseType :: ConstColIterator ConstColIterator;
109 typedef typename BaseType :: RowIterator RowIterator;
112 typedef typename BaseType :: ConstRowIterator ConstRowIterator;
115 typedef typename ColDiscreteFunctionType :: DiscreteFunctionSpaceType RangeSpaceType;
118 typedef typename RowDiscreteFunctionType :: DofStorageType RowBlockVectorType;
121 typedef typename ColDiscreteFunctionType :: DofStorageType ColBlockVectorType;
124 typedef typename RangeSpaceType :: GridType :: Traits :: Communication CommunicationType ;
126 typedef typename BaseType :: BuildMode BuildMode ;
128#ifdef USE_IBCRS_MATRIX
132 ReversedIterator(
const ConstRowIterator& it )
136 ReversedIterator( ConstRowIterator&& it )
137 : IterBaseType(
std::
move(it) )
145 void isNewIterator()
const {}
148 ReversedIterator
beforeBegin()
const {
return ReversedIterator( this->
begin() ); }
149 ReversedIterator
beforeEnd()
const {
return ReversedIterator( this->
end() ); }
151 using SlicedConstIterator = ConstRowIterator;
156 ImprovedBCRSMatrix(size_type rows, size_type cols, size_type nnz,
double overflowFraction) :
157 BaseType (
rows,
cols, nnz, overflowFraction, BaseType::implicit)
161 ImprovedBCRSMatrix(size_type rows, size_type cols, size_type nz = 0 ) :
162 BaseType (
rows,
cols, BaseType :: row_wise)
166 ImprovedBCRSMatrix( ) :
171 ImprovedBCRSMatrix(
const ImprovedBCRSMatrix& org) :
175 RowIterator slicedRowIt( size_type row )
177 return this->
begin() + row;
180 ConstRowIterator slicedRowIt( size_type row )
const
182 return this->
begin() + row;
185 ConstRowIterator slicedBegin( size_type row )
const {
return slicedRowIt( row ); }
186 ConstRowIterator slicedEnd( size_type row )
const {
return slicedRowIt( row ); }
190 const size_type sliceSize = this->
N() / numThreads ;
191 const size_type sliceBegin = thread * sliceSize ;
192 const size_type sliceEnd = ( thread == numThreads-1 ) ? this->
N() : (sliceBegin + sliceSize) ;
197 template <
class X,
class Y,
bool isMV>
198 void mvThreadedImpl( [[maybe_unused]]
const field_type&
alpha,
201 auto doMV = [
this, &
alpha, &x, &y] ()
205 if constexpr ( isMV )
207 [[maybe_unused]] field_type a =
alpha;
210 const auto slice = sliceBeginEnd( MPIManager::thread(), MPIManager::numThreads() );
211 const ConstRowIterator endi = slicedEnd( slice.second );
212 for (ConstRowIterator i = slicedBegin(slice.first); i!=endi; ++i)
214 if constexpr ( isMV )
217 ConstColIterator endj = (*i).end();
218 for (ConstColIterator j=(*i).begin(); j!=endj; ++j)
220 auto&& xj = Dune::Impl::asVector(x[j.index()]);
221 auto&& yi = Dune::Impl::asVector(y[i.index()]);
222 if constexpr ( isMV )
223 Dune::Impl::asMatrix(*j).umv(xj, yi);
225 Dune::Impl::asMatrix(*j).usmv(
alpha, xj, yi);
232 MPIManager :: run ( doMV );
234 catch (
const SingleThreadModeError& e )
237 if constexpr ( isMV )
241 DUNE_THROW(SingleThreadModeError,
"ImprovedBCRSMatrix::usmvThreaded: Cannot recover from threading error. Disable threading!");
248 template <
class X,
class Y>
249 void usmvThreaded(
const field_type&
alpha,
const X& x, Y& y )
const
254 template <
class X,
class Y>
255 void mvThreaded(
const X& x, Y& y )
const
260 template <
class SparsityPattern >
261 void createEntries(
const SparsityPattern& sparsityPattern)
263 const auto spEnd = sparsityPattern.end();
266 auto endcreate = this->createend();
269 const auto row = sparsityPattern.find(
create.index() );
271 if( row == spEnd )
continue;
274 for (
const auto& col : row->second )
282 const auto endrow = this->
end();
283 for (
auto row = this->
begin(); row !=endrow; ++row)
285 const auto colend = (*row).end();
286 for (
auto col = (*row).begin();
col != colend; ++
col )
292 void unitRow(
const size_t row )
294 block_type idBlock( 0 );
295 for (
int i = 0; i < idBlock.rows; ++i)
298 auto matRow = slicedRowIt( row );
299 assert( matRow != this->
end() );
300 auto colIt = (*matRow).begin();
301 const auto& colEndIt = (*matRow).end();
302 for (; colIt != colEndIt; ++colIt)
304 if( colIt.index() == row )
312 template <
class HangingNodesType>
313 void setup(ThisType& oldMatrix,
const HangingNodesType& hangingNodes)
323 auto rowend = oldMatrix.
end();
324 for(
auto it = oldMatrix.begin(); it != rowend; ++it)
326 const auto row = it.index();
327 auto& localIndices = indices[ row ];
329 if( hangingNodes.isHangingNode( row ) )
332 const auto&
cols = hangingNodes.associatedDofs( row );
333 const auto colSize =
cols.size();
334 for(
auto i=0; i<colSize; ++i)
336 assert( ! hangingNodes.isHangingNode( cols[i].first ) );
339 auto& localColIndices = indices[
cols[i].first ];
340 auto& localEntry = entries[
cols[i].first ];
343 auto endj = (*it).
end();
344 for (
auto j= (*it).begin(); j!=endj; ++j)
346 localColIndices.insert( j.index () );
347 localEntry.insert(
std::make_pair( j.index(), (cols[i].second * (*j)) ));
352 localIndices.insert( row );
353 for(
auto i=0; i<colSize; ++i)
354 localIndices.insert( cols[i].first );
359 auto endj = (*it).end();
360 for (
auto j= (*it).begin(); j!=endj; ++j)
361 localIndices.insert( j.index () );
366 createEntries( indices );
369 auto rowit = oldMatrix.begin();
371 auto endcreate = this->
end();
374 assert( rowit != oldMatrix.end() );
376 const auto row =
create.index();
377 if( hangingNodes.isHangingNode( row ) )
379 const auto&
cols = hangingNodes.associatedDofs( row );
383 assert( block_type :: rows == 1 );
385 const auto colSize =
cols.size();
386 for(
auto i=0; i<colSize; ++i)
387 colMap[ cols[i].first ] = -cols[i].second;
391 auto endj = (*create).
end();
392 for (
auto j= (*create).begin(); j!=endj; ++j)
394 assert( colMap.
find( j.index() ) != colMap.
end() );
395 (*j) = colMap[ j.index() ];
399 else if ( entries.find( row ) == entries.end() )
401 auto colit = (*rowit).
begin();
402 auto endj = (*create).end();
403 for (
auto j= (*create).begin(); j!=endj; ++j, ++colit )
405 assert( colit != (*rowit).end() );
414 auto colend = (*rowit).
end();
415 for(
auto colit = (*rowit).begin(); colit != colend; ++colit)
416 oldCols[ colit.index() ] = 0;
419 auto entry = entries.find( row );
420 assert( entry != entries.end ());
423 auto endcol = (*entry).second.end();
424 for(
auto co = (*entry).second.begin(); co != endcol; ++co)
425 oldCols[ (*co).first ] = 0;
429 auto colend = (*rowit).end();
430 for(
auto colit = (*rowit).begin(); colit != colend; ++colit)
431 oldCols[ colit.index() ] += (*colit);
435 auto endcol = (*entry).second.end();
436 for(
auto co = (*entry).second.begin(); co != endcol; ++co)
437 oldCols[ (*co).first ] += (*co).second;
440 auto endj = (*create).end();
441 for (
auto j= (*create).begin(); j!=endj; ++j )
443 auto colEntry = oldCols.
find( j.index() );
444 if( colEntry != oldCols.
end() )
445 (*j) = (*colEntry).second;
454 void extractDiagonal( ColBlockVectorType& diag )
const
456 const auto endi = this->
end();
457 for (
auto i = this->
begin(); i!=endi; ++i)
460 const auto row = i.index();
461 auto entry = (*i).find( row );
462 const LittleBlockType& block = (*entry);
463 enum { blockSize = LittleBlockType :: rows };
464 for(
auto l=0; l<blockSize; ++l )
465 diag[ row ][ l ] = block[ l ][ l ];
473 const std::size_t blockRow(row/(LittleBlockType :: rows));
474 const std::size_t localRowIdx(row%(LittleBlockType :: rows));
475 const std::size_t blockCol(col/(LittleBlockType :: cols));
476 const std::size_t localColIdx(col%(LittleBlockType :: cols));
478 const auto& matrixRow(this->
operator[](blockRow));
479 auto entry = matrixRow.find( blockCol );
480 const LittleBlockType& block = (*entry);
481 return block[localRowIdx][localColIdx];
488 const std::size_t blockRow(row/(LittleBlockType :: rows));
489 const std::size_t localRowIdx(row%(LittleBlockType :: rows));
490 const std::size_t blockCol(col/(LittleBlockType :: cols));
491 const std::size_t localColIdx(col%(LittleBlockType :: cols));
493 auto& matrixRow(this->
operator[](blockRow));
494 auto entry = matrixRow.find( blockCol );
495 LittleBlockType& block = (*entry);
496 block[localRowIdx][localColIdx] =
value;
503 const auto endi=this->
end();
504 for (
auto i=this->
begin(); i!=endi; ++i)
506 const auto endj = (*i).end();
507 for (
auto j=(*i).begin(); j!=endj; ++j)
508 if( (*j).infinity_norm() > 1.e-15)
509 s << i.index()+offset <<
" " << j.index()+offset <<
" " << *j <<
std::endl;
519 template<
class MatrixObject >
520 struct ISTLLocalMatrixTraits
522 typedef typename MatrixObject::DomainSpaceType DomainSpaceType;
523 typedef typename MatrixObject::RangeSpaceType RangeSpaceType;
524 typedef typename DomainSpaceType::RangeFieldType RangeFieldType;
526 typedef ISTLLocalMatrix< MatrixObject > LocalMatrixType;
527 typedef typename MatrixObject::MatrixType::block_type LittleBlockType;
534 template<
class MatrixObject >
535 class ISTLLocalMatrix
536 :
public LocalMatrixDefault< ISTLLocalMatrixTraits< MatrixObject > >
540 typedef LocalMatrixDefault< ISTLLocalMatrixTraits< MatrixObject > > BaseType;
543 typedef MatrixObject MatrixObjectType;
545 typedef typename MatrixObjectType::MatrixType MatrixType;
547 typedef typename MatrixType::block_type LittleBlockType;
549 typedef typename MatrixType :: size_type
size_type;
551 typedef typename MatrixObjectType::DomainSpaceType DomainSpaceType;
552 typedef typename MatrixObjectType::RangeSpaceType RangeSpaceType;
554 typedef typename MatrixObjectType::DomainEntityType DomainEntityType;
555 typedef typename MatrixObjectType::RangeEntityType RangeEntityType;
558 typedef typename DomainSpaceType::RangeFieldType DofType;
559 typedef typename MatrixType::row_type RowType;
562 typedef typename DomainSpaceType::BlockMapperType ColMapperType;
564 typedef typename RangeSpaceType::BlockMapperType RowMapperType;
566 static const int littleCols = MatrixObjectType::littleCols;
567 static const int littleRows = MatrixObjectType::littleRows;
569 typedef typename MatrixType::size_type Index;
574 [[deprecated(
"Use TemporaryLocalMatrix,LocalContribution and {get,add,set}LocalMatrix")]]
575 ISTLLocalMatrix (
const MatrixObjectType& mObj,
const DomainSpaceType& domainSpace,
const RangeSpaceType& rangeSpace )
576 : BaseType( domainSpace, rangeSpace ),
577 rowMapper_( rangeSpace.blockMapper() ),
578 colMapper_( domainSpace.blockMapper() ),
579 numRows_( rowMapper_.maxNumDofs() ),
580 numCols_( colMapper_.maxNumDofs() ),
587 [[deprecated(
"Use TemporaryLocalMatrix,LocalContribution and {get,add,set}LocalMatrix")]]
588 ISTLLocalMatrix (
const ISTLLocalMatrix& org )
590 rowMapper_(org.rowMapper_),
591 colMapper_(org.colMapper_),
592 numRows_( org.numRows_ ),
593 numCols_( org.numCols_ ),
594 matrices_(org.matrices_),
595 matrixObj_(org.matrixObj_)
599 void init (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity )
602 BaseType :: init ( domainEntity, rangeEntity );
604 numRows_ = rowMapper_.numDofs( rangeEntity );
605 numCols_ = colMapper_.numDofs( domainEntity );
608 matrices_.resize( numRows_ );
609 for(
auto& row : matrices_ )
611 row.resize( numCols_,
nullptr );
614 if( matrixObj_.implicitModeActive() )
618 return matrixObj_.matrix().entry(
index.first,
index.second );
620 initBlocks( blockAccess, domainEntity, rangeEntity );
626 return matrixObj_.matrix()[
index.first ][
index.second ];
628 initBlocks( blockAccess, domainEntity, rangeEntity );
632 template <
class BlockAccess>
633 void initBlocks( BlockAccess& blockAccess,
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity )
640 rowMapper_.mapEach( rangeEntity,
makePairFunctor( colMapper_, domainEntity, functor ) );
645 void check(
int localRow,
int localCol)
const
648 const std::size_t row = (int) localRow / littleRows;
650 const int lRow = localRow%littleRows;
651 const int lCol = localCol%littleCols;
652 assert( row < matrices_.size() ) ;
653 assert( col < matrices_[row].
size() );
654 assert( lRow < littleRows );
655 assert( lCol < littleCols );
659 DofType& getValue(
const int localRow,
const int localCol)
661 const int row = (int) localRow / littleRows;
662 const int col = (int) localCol / littleCols;
663 const int lRow = localRow%littleRows;
664 const int lCol = localCol%littleCols;
665 return (*matrices_[row][col])[lRow][lCol];
669 const DofType
get(
const int localRow,
const int localCol)
const
671 const int row = (int) localRow / littleRows;
672 const int col = (int) localCol / littleCols;
673 const int lRow = localRow%littleRows;
674 const int lCol = localCol%littleCols;
675 return (*matrices_[row][col])[lRow][lCol];
678 void scale (
const DofType& scalar)
680 const size_type nrows = matrices_.size();
681 for(size_type i=0; i<nrows; ++i)
683 const size_type ncols = matrices_[i].size();
684 for(size_type j=0; j<ncols; ++j)
686 (*matrices_[i][j]) *= scalar;
691 void add(
const int localRow,
const int localCol ,
const DofType value)
694 check(localRow,localCol);
696 getValue(localRow,localCol) +=
value;
699 void set(
const int localRow,
const int localCol ,
const DofType value)
702 check(localRow,localCol);
704 getValue(localRow,localCol) =
value;
708 void unitRow(
const int localRow)
710 const int row = (int) localRow / littleRows;
711 const int lRow = localRow%littleRows;
714 doClearRow( row, lRow );
717 (*matrices_[row][row])[lRow][lRow] = 1;
723 const size_type nrows = matrices_.size();
724 for(size_type i=0; i<nrows; ++i)
726 const size_type ncols = matrices_[i].size();
727 for(size_type j=0; j<ncols; ++j)
729 (*matrices_[i][j]) = (DofType) 0;
735 void clearRow (
const int localRow )
737 const int row = (int) localRow / littleRows;
738 const int lRow = localRow%littleRows;
741 doClearRow( row, lRow );
750 void doClearRow (
const int row,
const int lRow )
753 const auto col = this->columns();
754 for(
auto localCol=0; localCol<
col; ++localCol)
756 const int col = (int) localCol / littleCols;
757 const int lCol = localCol%littleCols;
758 (*matrices_[row][
col])[lRow][lCol] = 0;
764 const RowMapperType& rowMapper_;
765 const ColMapperType& colMapper_;
775 const MatrixObjectType& matrixObj_;
780 template <
class DomainSpaceImp,
class RangeSpaceImp,
class DomainBlock,
class RangeBlock >
781 class ISTLMatrixObject
785 typedef DomainSpaceImp DomainSpaceType;
787 typedef RangeSpaceImp RangeSpaceType;
790 typedef ISTLMatrixObject< DomainSpaceImp, RangeSpaceImp, DomainBlock, RangeBlock > ThisType;
791 typedef ThisType PreconditionMatrixType;
793 typedef typename DomainSpaceType::GridType GridType;
795 typedef typename RangeSpaceType :: EntityType RangeEntityType ;
796 typedef typename DomainSpaceType :: EntityType DomainEntityType ;
798 enum { littleCols = DomainSpaceType :: localBlockSize };
799 enum { littleRows = RangeSpaceType :: localBlockSize };
801 typedef FieldMatrix<typename DomainSpaceType :: RangeFieldType, littleRows, littleCols> LittleBlockType;
802 typedef LittleBlockType block_type;
803 typedef LittleBlockType MatrixBlockType;
805 typedef ISTLBlockVectorDiscreteFunction< RangeSpaceType, RangeBlock > RowDiscreteFunctionType;
806 typedef ISTLBlockVectorDiscreteFunction< DomainSpaceType, DomainBlock > ColumnDiscreteFunctionType;
808 typedef typename RowDiscreteFunctionType :: DofStorageType RowBlockVectorType;
809 typedef typename ColumnDiscreteFunctionType :: DofStorageType ColumnBlockVectorType;
811 typedef typename RangeSpaceType :: BlockMapperType RowMapperType;
812 typedef typename DomainSpaceType :: BlockMapperType ColMapperType;
815 typedef ImprovedBCRSMatrix< LittleBlockType , ColumnDiscreteFunctionType , RowDiscreteFunctionType > MatrixType;
816 typedef ISTLParallelMatrixAdapterInterface< MatrixType > MatrixAdapterType;
819 typedef ISTLLocalMatrix<ThisType> ObjectType;
820 friend class ISTLLocalMatrix<ThisType>;
822 typedef ThisType LocalMatrixFactoryType;
825 typedef LocalMatrixWrapper< LocalMatrixStackType > LocalMatrixType;
826 typedef ColumnObject< ThisType > LocalColumnObjectType;
829 const DomainSpaceType& domainSpace_;
830 const RangeSpaceType& rangeSpace_;
833 RowMapperType& rowMapper_;
835 ColMapperType& colMapper_;
842 mutable LocalMatrixStackType localMatrixStack_;
846 const double overflowFraction_;
847 const bool threading_ ;
849 ISTLSolverParameter param_;
854 ISTLMatrixObject(
const ISTLMatrixObject&) =
delete;
859 ISTLMatrixObject (
const DomainSpaceType &domainSpace,
const RangeSpaceType &rangeSpace,
const ISTLSolverParameter& param = ISTLSolverParameter() ) :
860 domainSpace_(domainSpace)
861 , rangeSpace_(rangeSpace)
862 , rowMapper_( rangeSpace.blockMapper() )
863 , colMapper_( domainSpace.blockMapper() )
866 , localMatrixStack_( *this )
867 , overflowFraction_( param.overflowFraction() )
868 , threading_( param.threading() )
875 MatrixType&
matrix()
const
882 bool threading()
const {
return threading_; }
886 out <<
"ISTL MatrixObj: ";
896 void createMatrixAdapter (
const ISTLSolverParameter& param )
const
900 matrixAdap_ = ISTLMatrixAdapterFactory< ThisType > :: matrixAdapter( *
this, param );
902 assert( matrixAdap_ );
906 MatrixAdapterType& matrixAdapter(
const ISTLSolverParameter& parameter )
const
908 const ISTLSolverParameter* param =
dynamic_cast< const ISTLSolverParameter*
> (¶meter);
910 createMatrixAdapter( *param );
913 ISTLSolverParameter newparam( parameter );
914 createMatrixAdapter( newparam );
922 MatrixAdapterType& matrixAdapter()
const
924 return matrixAdapter( param_ );
928 MatrixType& exportMatrix()
const
934 bool implicitModeActive()
const
940#ifndef USE_IBCRS_MATRIX
941 if(
matrix().buildMode() == MatrixType::implicit &&
matrix().buildStage() == MatrixType::building )
948 void finalizeAssembly()
const
951 const_cast< ThisType&
> (*this).compress();
957 if( implicitModeActive() )
971 void unitRow(
const size_t row )
977 template <
class Container>
978 void setUnitRowImpl(
const Container &rows,
const double diagonal )
980 for (
const auto& r :
rows)
982 const std::size_t blockRow( r/(LittleBlockType :: rows) );
983 const std::size_t localRowIdx( r%(LittleBlockType :: rows) );
985 auto row =
matrix().slicedRowIt( blockRow );
987 const auto endcol = (*row).end();
991 for (
auto col=(*row).begin();
col!=endcol; ++
col)
993 for (
auto& entry : (*
col)[localRowIdx])
995 if (
col.index() == blockRow)
997 (*col)[localRowIdx][localRowIdx] =
diagonal;
1008 template <
class Container>
1009 void setUnitRows(
const Container& unitRows,
const Container& auxRows )
1011 setUnitRowImpl( unitRows, 1.0 );
1012 setUnitRowImpl( auxRows, 0.0 );
1018 reserve( Stencil<DomainSpaceType,RangeSpaceType>(domainSpace_, rangeSpace_),
false );
1022 template <
class Set>
1025 reserve( StencilWrapper< DomainSpaceType,RangeSpaceType, Set >( sparsityPattern ),
false );
1029 template <
class Stencil>
1030 void reserve(
const Stencil &stencil,
const bool proposeImplicit =
false )
1033 if(sequence_ != domainSpace().sequence())
1038 const bool implicit =
1039#ifdef USE_IBCRS_MATRIX
1042 proposeImplicit && MPIManager::numThreads() == 1;
1047 auto nnz = stencil.maxNonZerosEstimate();
1050 if (domainSpace_.begin() != domainSpace_.end() && rangeSpace_.begin() != rangeSpace_.end())
1052 Stencil tmpStencil( stencil );
1053 tmpStencil.fill( *(domainSpace_.begin()), *(rangeSpace_.begin()) );
1054 nnz = tmpStencil.maxNonZerosEstimate();
1057 matrix_.
reset(
new MatrixType( rowMapper_.size(), colMapper_.size(), nnz, overflowFraction_ ) );
1061 matrix_.
reset(
new MatrixType( rowMapper_.size(), colMapper_.size() ) );
1062 matrix().createEntries( stencil.globalStencil() );
1065 sequence_ = domainSpace().sequence();
1070 template <
class HangingNodesType>
1071 void changeHangingNodes(
const HangingNodesType& hangingNodes)
1074 MatrixType* newMatrix =
new MatrixType(rowMapper_.size(), colMapper_.size());
1077 newMatrix->setup( *matrix_ , hangingNodes );
1083 matrix_.
reset( newMatrix );
1088 void extractDiagonal( ColumnDiscreteFunctionType& diag )
const
1091 matrix().extractDiagonal( diag.blockVector() );
1095 bool rightPrecondition()
const
1101 void apply(
const ColumnDiscreteFunctionType& arg, RowDiscreteFunctionType& dest)
const
1103 matrixAdapter().apply( arg.blockVector(), dest.blockVector() );
1107 template <
class CDF,
class RDF>
1108 void apply(
const CDF& arg, RDF& dest)
const
1112 istlArg_.
reset(
new ColumnDiscreteFunctionType(
"ISTLMatrixObj::istlArg_", domainSpace() ) );
1117 istlDest_.
reset(
new RowDiscreteFunctionType(
"ISTLMatrixObj::istlDest_", rangeSpace() ) );
1120 istlArg_->assign( arg );
1121 apply( *istlArg_, *istlDest_ );
1122 dest.assign( *istlDest_ );
1131 void createPreconditionMatrix()
1140 const DomainSpaceType& domainSpace()
const
1142 return domainSpace_;
1144 const RangeSpaceType& rangeSpace()
const
1149 const RowMapperType& rowMapper()
const
1153 const ColMapperType& colMapper()
const
1159 ObjectType* newObject()
const
1161 return new ObjectType(*
this, domainSpace(), rangeSpace());
1168 [[deprecated(
"Use TemporaryLocalMatrix,LocalContribution and {get,add,set}LocalMatrix")]]
1169 LocalMatrixType localMatrix(
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity )
const
1171 return LocalMatrixType( localMatrixStack_, domainEntity, rangeEntity );
1178 [[deprecated(
"Use TemporaryLocalMatrix,LocalContribution and {get,add,set}LocalMatrix")]]
1179 LocalMatrixType localMatrix()
const
1181 return LocalMatrixType( localMatrixStack_ );
1184 LocalColumnObjectType localColumn(
const DomainEntityType &domainEntity )
const
1186 return LocalColumnObjectType ( *
this, domainEntity );
1190 template<
class LocalBlock,
class Operation >
1191 void applyToBlock (
const size_t row,
const size_t col,
1192 const LocalBlock &localBlock,
1193 Operation& operation )
1195 LittleBlockType& block = ( implicitModeActive() ) ?
matrix().entry( row, col ) :
matrix()[ row ][
col ];
1196 for(
int i = 0; i < littleRows; ++i )
1197 for(
int j = 0; j < littleCols; ++j )
1198 operation( block[ i ][ j ], localBlock[ i ][ j ] );
1201 template<
class LocalBlock >
1202 void setBlock (
const size_t row,
const size_t col,
1203 const LocalBlock &localBlock )
1205 typedef typename DomainSpaceType :: RangeFieldType Field;
1206 auto copy = [] ( Field& a,
const typename LocalBlock::field_type& b ) { a = b; };
1207 applyToBlock( row, col, localBlock, copy );
1210 template<
class LocalBlock >
1211 void addBlock (
const size_t row,
const size_t col,
1212 const LocalBlock &localBlock )
1214 typedef typename DomainSpaceType :: RangeFieldType Field;
1215 auto add = [] ( Field& a,
const typename LocalBlock::field_type& b ) { a += b; };
1216 applyToBlock( row, col, localBlock,
add );
1220 template<
class LocalMatrix,
class Operation >
1221 void applyToLocalMatrix (
const DomainEntityType &domainEntity,
1222 const RangeEntityType &rangeEntity,
1223 const LocalMatrix &localMat,
1224 Operation& operation )
1226 typedef typename MatrixType::size_type Index;
1227#ifndef USE_IBCRS_MATRIX
1228 if( implicitModeActive() )
1236 LittleBlockType& block = blockAccess(
index );
1237 for(
int i = 0; i < littleRows; ++i )
1238 for(
int j = 0; j < littleCols; ++j )
1239 operation( block[ i ][ j ], localMat.get(
local.first * littleRows + i,
local.second *littleCols + j ) );
1241 rowMapper_.mapEach( rangeEntity,
makePairFunctor( colMapper_, domainEntity, functor ) );
1252 LittleBlockType& block = blockAccess(
index );
1253 for(
int i = 0; i < littleRows; ++i )
1254 for(
int j = 0; j < littleCols; ++j )
1255 operation( block[ i ][ j ], localMat.get(
local.first * littleRows + i,
local.second *littleCols + j ) );
1257 rowMapper_.mapEach( rangeEntity,
makePairFunctor( colMapper_, domainEntity, functor ) );
1261 template<
class LocalMatrix >
1262 void setLocalMatrix (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity,
const LocalMatrix &localMat )
1264 typedef typename DomainSpaceType :: RangeFieldType RangeFieldType;
1265 auto operation = [] ( RangeFieldType& a,
const RangeFieldType& b )
1269 applyToLocalMatrix( domainEntity, rangeEntity, localMat, operation );
1272 template<
class LocalMatrix >
1273 void addLocalMatrix (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity,
const LocalMatrix &localMat )
1275 typedef typename DomainSpaceType :: RangeFieldType RangeFieldType;
1276 auto operation = [] ( RangeFieldType& a,
const RangeFieldType& b )
1280 applyToLocalMatrix( domainEntity, rangeEntity, localMat, operation );
1283 template<
class LocalMatrix,
class Scalar >
1284 void addScaledLocalMatrix (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity,
const LocalMatrix &localMat,
const Scalar &s )
1286 typedef typename DomainSpaceType :: RangeFieldType RangeFieldType;
1287 auto operation = [ &s ] ( RangeFieldType& a,
const RangeFieldType& b )
1291 applyToLocalMatrix( domainEntity, rangeEntity, localMat, operation );
1294 template<
class LocalMatrix >
1295 void getLocalMatrix (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity, LocalMatrix &localMat )
const
1300 typedef typename MatrixType::size_type Index;
1305 localMat.set(
local.first * littleRows + i,
local.second *littleCols + j,
1309 rowMapper_.mapEach( rangeEntity,
makePairFunctor( colMapper_, domainEntity, functor ) );
1313 void preConErrorMsg(
int preCon)
const
1320 matrixAdap_.
reset(
nullptr );
BCRSMatrix< FieldMatrix< T, n, m >, A >::size_type size_type
static type * create(const M &mat, bool verbose, bool reusevector)
OperatorHierarchy::ParallelMatrixHierarchy::ConstIterator matrix
void init(const Matrix *matrix)
void add(const Vertex &vertex)
auto rows(Matrix const &matrix)
auto cols(Matrix const &matrix)
static TupleAccessTraits< typenameAtType< N, Tuple >::Type >::NonConstType get(Tuple &t)
static constexpr size_type N()
void mv(const X &x, Y &y) const
std::ptrdiff_t index() const
const FieldVector< K, n > & diagonal() const
virtual void operator()()=0
#define DUNE_THROW(E,...)
const GlobalIndex & global() const
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
PairFunctor< Mapper, Entity, Functor > makePairFunctor(const Mapper &mapper, const Entity &entity, Functor functor)
Definition operator/matrix/functor.hh:65