1#ifndef DUNE_FEM_PETSCLINEAROPERATOR_HH
2#define DUNE_FEM_PETSCLINEAROPERATOR_HH
44 struct PetscSolverParameter :
public LocalParameter< SolverParameter, PetscSolverParameter >
46 typedef LocalParameter< SolverParameter, PetscSolverParameter > BaseType;
49 using BaseType :: parameter ;
50 using BaseType :: keyPrefix ;
52 PetscSolverParameter(
const ParameterReader ¶meter = Parameter::container() )
53 : BaseType( parameter )
56 PetscSolverParameter(
const SolverParameter& sp )
57 : PetscSolverParameter( sp.keyPrefix(), sp.parameter() )
60 PetscSolverParameter(
const std::string &keyPrefix,
const ParameterReader ¶meter = Parameter::container() )
61 : BaseType( keyPrefix, parameter )
64 bool isPetscSolverParameter()
const {
return true; }
66 static const int boomeramg = 0;
67 static const int parasails = 1;
68 static const int pilut = 2;
70 int hypreMethod()
const
72 const std::string hyprePCNames[] = {
"boomer-amg",
"parasails",
"pilu-t" };
74 if (parameter().
exists(
"petsc.preconditioning.method"))
76 hypreType = parameter().getEnum(
"petsc.preconditioning.hypre.method", hyprePCNames, 0 );
77 std::cout <<
"WARNING: using deprecated parameter 'petsc.preconditioning.hypre.method' use "
78 << keyPrefix() <<
"preconditioning.hypre.method instead\n";
81 hypreType = parameter().getEnum( keyPrefix()+
"hypre.method", hyprePCNames, 0 );
85 int superluMethod()
const
87 const std::string factorizationNames[] = {
"petsc",
"superlu",
"mumps" };
89 if (parameter().
exists(
"petsc.preconditioning.lu.method"))
91 factorType = parameter().getEnum(
"petsc.preconditioning.lu.method", factorizationNames, 0 );
92 std::cout <<
"WARNING: using deprecated parameter 'petsc.preconditioning.lu.method' use "
93 << keyPrefix() <<
"preconditioning.lu.method instead\n";
96 factorType = parameter().getEnum( keyPrefix()+
"preconditioning.lu.method", factorizationNames, 0 );
101 bool viennaCL ()
const {
102 return parameter().getValue<
bool > ( keyPrefix() +
"petsc.viennacl", false );
106 bool blockedMode ()
const {
107 return parameter().getValue<
bool > ( keyPrefix() +
"petsc.blockedmode", true );
112 using Dune::Petsc::Backend;
113 return parameter_.getEnum( keyPrefix() +
"petsc.backend", Backend::availableBackend(), Backend::defaultBackend );
122 template<
typename DomainFunction,
typename RangeFunction >
123 class PetscLinearOperator
124 :
public Fem::AssembledOperator< DomainFunction, RangeFunction >
126 typedef PetscLinearOperator< DomainFunction, RangeFunction > ThisType;
128 typedef Mat MatrixType;
129 typedef DomainFunction DomainFunctionType;
130 typedef RangeFunction RangeFunctionType;
131 typedef typename DomainFunctionType::RangeFieldType DomainFieldType;
132 typedef typename RangeFunctionType::RangeFieldType RangeFieldType;
133 typedef typename DomainFunctionType::DiscreteFunctionSpaceType DomainSpaceType;
134 typedef typename RangeFunctionType::DiscreteFunctionSpaceType RangeSpaceType;
136 typedef PetscDiscreteFunction< DomainSpaceType > PetscDomainFunctionType;
137 typedef PetscDiscreteFunction< RangeSpaceType > PetscRangeFunctionType;
139 typedef typename DomainSpaceType::EntityType DomainEntityType;
140 typedef typename RangeSpaceType::EntityType RangeEntityType;
142 static const unsigned int domainLocalBlockSize = DomainSpaceType::localBlockSize;
143 static const unsigned int rangeLocalBlockSize = RangeSpaceType::localBlockSize;
145 static constexpr bool squareBlocked = domainLocalBlockSize == rangeLocalBlockSize ;
146 static constexpr bool blockedMatrix = domainLocalBlockSize > 1 && squareBlocked;
150 typedef FlatFieldMatrix< RangeFieldType, domainLocalBlockSize, rangeLocalBlockSize > MatrixBlockType;
151 typedef MatrixBlockType block_type;
154 enum Status {statAssembled=0,statAdd=1,statInsert=2,statGet=3,statNothing=4};
156 typedef PetscMappers< DomainSpaceType > DomainMappersType;
157 typedef PetscMappers< RangeSpaceType > RangeMappersType;
159 typedef AuxiliaryDofs< typename DomainSpaceType::GridPartType, typename DomainMappersType::GhostMapperType > DomainAuxiliaryDofsType;
160 typedef AuxiliaryDofs< typename RangeSpaceType::GridPartType, typename RangeMappersType::GhostMapperType > RangeAuxiliaryDofsType;
166 struct LocalMatrixTraits
168 typedef typename DomainFunctionType::DiscreteFunctionSpaceType DomainSpaceType;
169 typedef typename RangeFunctionType::DiscreteFunctionSpaceType RangeSpaceType;
170 typedef LocalMatrix LocalMatrixType;
171 typedef typename RangeSpaceType::RangeFieldType RangeFieldType;
174 typedef RangeFieldType LittleBlockType;
178 typedef LocalMatrix ObjectType;
179 typedef ThisType LocalMatrixFactoryType;
183 typedef LocalMatrixWrapper< LocalMatrixStackType > LocalMatrixType;
184 typedef ColumnObject< ThisType > LocalColumnObjectType;
186 PetscLinearOperator (
const DomainSpaceType &domainSpace,
const RangeSpaceType &rangeSpace,
187 const PetscSolverParameter& param = PetscSolverParameter() )
188 : domainMappers_( domainSpace ),
189 rangeMappers_( rangeSpace ),
190 localMatrixStack_( *this ),
191 status_(statNothing),
192 backend_( param.backend() )
195 PetscLinearOperator (
const std::string &,
const DomainSpaceType &domainSpace,
const RangeSpaceType &rangeSpace,
196 const PetscSolverParameter& param = PetscSolverParameter() )
197 : PetscLinearOperator( domainSpace, rangeSpace, param )
201 ~PetscLinearOperator ()
208 ::Dune::Petsc::MatAssemblyBegin( petscMatrix_, MAT_FLUSH_ASSEMBLY );
209 ::Dune::Petsc::MatAssemblyEnd ( petscMatrix_, MAT_FLUSH_ASSEMBLY );
211 status_ = statAssembled;
216 if( ! finalizedAlready() )
218 ::Dune::Petsc::MatAssemblyBegin( petscMatrix_, MAT_FINAL_ASSEMBLY );
219 ::Dune::Petsc::MatAssemblyEnd ( petscMatrix_, MAT_FINAL_ASSEMBLY );
221 setUnitRowsImpl( unitRows_, auxRows_ );
229 bool finalizedAlready()
const
231 PetscBool assembled = PETSC_FALSE ;
232 ::Dune::Petsc::MatAssembled( petscMatrix_, &assembled );
233 return assembled == PETSC_TRUE;
236 void finalizeAssembly ()
const
238 const_cast< ThisType&
> (*this).finalize();
242 const DomainSpaceType &domainSpace ()
const {
return domainMappers_.space(); }
243 const RangeSpaceType &rangeSpace ()
const {
return rangeMappers_.space(); }
248 template <
class DF,
class RF>
249 void apply (
const DF &arg, RF &dest )
const
252 petscArg_.reset(
new PetscDomainFunctionType(
"PetscOp-arg", domainSpace(), backend() ) );
254 petscDest_.reset(
new PetscRangeFunctionType(
"PetscOp-dest", rangeSpace(), backend() ) );
256 petscArg_->assign( arg );
257 apply( *petscArg_, *petscDest_ );
258 dest.assign( *petscDest_ );
262 void apply (
const PetscDomainFunctionType &arg, PetscRangeFunctionType &dest )
const
266 ::Dune::Petsc::MatMult( petscMatrix_, *arg.petscVec() , *dest.petscVec() );
269 void operator() (
const DomainFunctionType &arg, RangeFunctionType &dest )
const
276 reserve( SimpleStencil<DomainSpaceType,RangeSpaceType>(0),
true );
282 reserve( StencilWrapper< DomainSpaceType,RangeSpaceType, Set >( sparsityPattern ),
true );
286 template <
class StencilType>
287 void reserve (
const StencilType &stencil,
const bool isSimpleStencil =
false )
289 domainMappers_.update();
290 rangeMappers_.update();
292 if(sequence_ != domainSpace().sequence())
302 ::Dune::Petsc::MatCreate( domainSpace().gridPart().
comm(), &petscMatrix_ );
305 const PetscInt localCols = domainMappers_.ghostMapper().interiorSize() * domainLocalBlockSize;
306 const PetscInt localRows = rangeMappers_.ghostMapper().interiorSize() * rangeLocalBlockSize;
308 const PetscInt globalCols = domainMappers_.parallelMapper().size() * domainLocalBlockSize;
309 const PetscInt globalRows = rangeMappers_.parallelMapper().size() * rangeLocalBlockSize;
311 ::Dune::Petsc::MatSetSizes( petscMatrix_, localRows, localCols, globalRows, globalCols );
314 ::Dune::Petsc::MatSetType( petscMatrix_, ::Dune::Petsc::Backend::toMatType( backend_ ) );
317 bs = domainLocalBlockSize ;
319 ::Dune::Petsc::MatSetBlockSize( petscMatrix_, bs );
338 if( isSimpleStencil ||
std::is_same< StencilType,SimpleStencil<DomainSpaceType,RangeSpaceType> >::value )
340 ::Dune::Petsc::MatSetUp( petscMatrix_, bs, domainLocalBlockSize * stencil.maxNonZerosEstimate() );
344 DomainAuxiliaryDofsType domainAuxiliaryDofs( domainMappers_.ghostMapper() );
345 RangeAuxiliaryDofsType rangeAuxiliaryDofs( rangeMappers_.ghostMapper() );
349 for(
const auto& entry : stencil.globalStencil() )
351 const int petscIndex = rangeMappers_.ghostIndex( entry.first );
352 if( rangeAuxiliaryDofs.contains( petscIndex ) )
355 for (
unsigned int rb = 0; rb<rangeLocalBlockSize/bs; ++rb)
357 const size_t row = petscIndex*rangeLocalBlockSize/bs + rb;
360 assert( row <
size_t(localRows/bs) );
361 d_nnz[ row ] = o_nnz[ row ] = 0;
362 for(
const auto local : entry.second )
364 if( !domainAuxiliaryDofs.contains( domainMappers_.ghostIndex(
local ) ) )
365 d_nnz[ row ] += domainLocalBlockSize/bs;
367 o_nnz[ row ] += domainLocalBlockSize/bs;
371 ::Dune::Petsc::MatSetUp( petscMatrix_, bs, &d_nnz[0], &o_nnz[0] );
373 sequence_ = domainSpace().sequence();
377 status_ = statAssembled ;
380 virtual void clear ()
383 ::Dune::Petsc::MatZeroEntries( petscMatrix_ );
393 ::Dune::Petsc::MatZeroRows( petscMatrix_, r.
size(), r.
data(), 1.0 );
394 ::Dune::Petsc::MatZeroRows( petscMatrix_, a.
size(), a.
data(), 0.0 );
397 template <
class Container>
398 void setUnitRows(
const Container& unitRows,
const Container& auxRows )
406 for(
const auto& row :
rows )
408 const PetscInt block = this->rangeMappers_.parallelIndex( row / rangeLocalBlockSize );
409 r.
push_back( block * rangeLocalBlockSize + (row % rangeLocalBlockSize) );
413 setupRows( unitRows, r );
414 setupRows( auxRows, a );
416 if( finalizedAlready() )
418 setUnitRowsImpl( r, a );
422 unitRows_.reserve( unitRows_.size() + r.
size() );
423 for(
const auto& row : r )
426 auxRows_.reserve( auxRows_.size() + a.
size() );
427 for(
const auto& row : a )
433 ObjectType* newObject()
const
435 return new ObjectType( *
this, domainSpace(), rangeSpace() );
442 [[deprecated(
"Use TemporaryLocalMatrix,LocalContribution and {get,add,set}LocalMatrix")]]
443 LocalMatrixType localMatrix (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity )
const
445 return LocalMatrixType(localMatrixStack_, domainEntity, rangeEntity);
448 LocalColumnObjectType localColumn(
const DomainEntityType &colEntity )
const
450 return LocalColumnObjectType ( *
this, colEntity );
454 void unitRow(
const PetscInt localRow,
const PetscScalar diag = 1.0 )
457 const PetscInt row = rangeMappers_.parallelIndex( localRow );
458 for(
unsigned int i=0, r = row * domainLocalBlockSize; i<domainLocalBlockSize; ++i, ++r )
463 if( finalizedAlready() )
466 ::Dune::Petsc::MatZeroRows( petscMatrix_, domainLocalBlockSize,
rows.data(), diag );
471 assert(
std::abs( diag - 1. ) < 1e-12 );
472 unitRows_.reserve( unitRows_.size() + domainLocalBlockSize );
473 for(
const auto& r :
rows )
475 unitRows_.push_back( r );
480 bool blockedMode()
const {
return backend() == Dune::Petsc::Backend::block; }
483 const int backend ()
const {
return backend_; }
486 template<
class PetscOp >
487 void applyToBlock (
const PetscInt localRow,
const PetscInt localCol,
const MatrixBlockType& block, PetscOp op )
490 const PetscInt localCols = domainMappers_.ghostMapper().interiorSize() * domainLocalBlockSize;
491 const PetscInt localRows = rangeMappers_.ghostMapper().interiorSize() * rangeLocalBlockSize;
492 assert( localRow < localRows );
493 assert( localCol < localCols );
499 const PetscInt row = rangeMappers_.parallelIndex( localRow );
500 const PetscInt
col = rangeMappers_.parallelIndex( localCol );
501 ::Dune::Petsc::MatSetValuesBlocked( petscMatrix_, 1, &row, 1, &col, block.data(), op );
506 const PetscInt row = rangeMappers_.parallelIndex( localRow );
507 const PetscInt
col = rangeMappers_.parallelIndex( localCol );
510 for(
unsigned int i=0, r = row * domainLocalBlockSize, c = col * domainLocalBlockSize; i<domainLocalBlockSize; ++i, ++r, ++c )
517 ::Dune::Petsc::MatSetValues( petscMatrix_, domainLocalBlockSize,
rows.data(), domainLocalBlockSize,
cols.data(), block.data(), op );
519 setStatus( statAssembled );
522 template<
class LocalBlock,
class PetscOp >
523 void applyToBlock (
const size_t row,
const size_t col,
const LocalBlock& block, PetscOp op )
525 assert( block.rows() == rangeLocalBlockSize );
526 assert( block.cols() == domainLocalBlockSize );
529 MatrixBlockType matBlock( block );
530 applyToBlock( row, col, matBlock, op );
533 template<
class LocalBlock >
534 void setBlock (
const size_t row,
const size_t col,
const LocalBlock& block )
536#ifndef USE_SMP_PARALLEL
537 assert( status_==statAssembled || status_==statInsert );
542 setStatus( statInsert );
543 applyToBlock(
static_cast< PetscInt
> (row),
static_cast< PetscInt
> (col), block, INSERT_VALUES );
546 template<
class LocalBlock >
547 void addBlock (
const size_t row,
const size_t col,
const LocalBlock& block )
549#ifndef USE_SMP_PARALLEL
550 assert( status_==statAssembled || status_==statInsert );
555 setStatus( statAdd );
556 applyToBlock(
static_cast< PetscInt
> (row),
static_cast< PetscInt
> (col), block, ADD_VALUES );
560 typedef TemporaryLocalMatrix< DomainSpaceType, RangeSpaceType > TemporaryLocalMatrixType;
563 template <
class Operation>
564 const PetscScalar* getValues(
const unsigned int rSize,
const unsigned int cSize,
565 const TemporaryLocalMatrixType &localMat,
const Operation&,
568 return localMat.data();
572 template <
class LM,
class Operation>
573 const PetscScalar* getValues(
const unsigned int rSize,
const unsigned int cSize,
574 const Assembly::Impl::LocalMatrixGetter< LM >& localMat,
const Operation&,
577 return localMat.localMatrix().data();
581 template <
class LocalMatrix,
class Operation,
bool T>
582 const PetscScalar* getValues(
const unsigned int rSize,
const unsigned int cSize,
583 const LocalMatrix &localMat,
const Operation& operation,
587 v.
resize( rSize * cSize );
588 for(
unsigned int i = 0, ic = 0 ; i< rSize; ++i )
590 for(
unsigned int j =0; j< cSize; ++j, ++ic )
592 v[ ic ] = operation( localMat.get( i, j ) );
598 template<
class LocalMatrix,
class Operation,
class PetscOp,
bool T >
599 void applyLocalMatrix (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity,
600 const LocalMatrix &localMat,
const Operation& operation,
604 auto& rcTemp = *(rcTemp_);
610 setupIndicesBlocked( rangeMappers_, rangeEntity, r );
611 setupIndicesBlocked( domainMappers_, domainEntity, c );
614 const unsigned int rSize = r.
size() * domainLocalBlockSize ;
615 const unsigned int cSize = c.
size() * domainLocalBlockSize ;
617 const PetscScalar* values = getValues( rSize, cSize, localMat, operation, scaled );
618 ::Dune::Petsc::MatSetValuesBlocked( petscMatrix_, r.
size(), r.
data(), c.
size(), c.
data(), values, petscOp );
622 setupIndices( rangeMappers_, rangeEntity, r );
623 setupIndices( domainMappers_, domainEntity, c );
625 const unsigned int rSize = r.
size();
626 const unsigned int cSize = c.
size();
628 const PetscScalar* values = getValues( rSize, cSize, localMat, operation, scaled );
629 ::Dune::Petsc::MatSetValues( petscMatrix_, rSize, r.
data(), cSize, c.
data(), values, petscOp );
631 setStatus( statAssembled );
635 template<
class LocalMatrix >
636 void addLocalMatrix (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity,
const LocalMatrix &localMat )
638#ifndef USE_SMP_PARALLEL
639 assert( status_==statAssembled || status_==statAdd );
641 setStatus( statAdd );
643 auto operation = [] (
const PetscScalar&
value ) -> PetscScalar {
return value; };
648 template<
class LocalMatrix,
class Scalar >
649 void addScaledLocalMatrix (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity,
const LocalMatrix &localMat,
const Scalar &s )
651#ifndef USE_SMP_PARALLEL
652 assert( status_==statAssembled || status_==statAdd );
654 setStatus( statAdd );
656 auto operation = [ &s ] (
const PetscScalar&
value ) -> PetscScalar {
return s *
value; };
661 template<
class LocalMatrix >
662 void setLocalMatrix (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity,
const LocalMatrix &localMat )
664#ifndef USE_SMP_PARALLEL
665 assert( status_==statAssembled || status_==statInsert );
667 setStatus( statInsert );
669 auto operation = [] (
const PetscScalar&
value ) -> PetscScalar {
return value; };
674 template<
class LocalMatrix >
675 void getLocalMatrix (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity, LocalMatrix &localMat )
const
680#ifndef USE_SMP_PARALLEL
681 assert( status_==statAssembled || status_==statGet );
683 setStatus( statGet );
685 auto& rcTemp = *(rcTemp_);
690 setupIndices( rangeMappers_, rangeEntity, r );
691 setupIndices( domainMappers_, domainEntity, c );
698 localMat.set( i, j, v[ i * c.
size() +j ] );
700 setStatus( statAssembled );
703 void scaleLocalMatrix (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity,
const RangeFieldType &s )
708#ifndef USE_SMP_PARALLEL
709 assert( status_==statAssembled || status_==statGet );
711 setStatus( statGet );
713 auto& rcTemp = *(rcTemp_);
718 setupIndices( rangeMappers_, rangeEntity, r );
719 setupIndices( domainMappers_, domainEntity, c );
721 const unsigned int rSize = r.
size();
722 const unsigned int cSize = c.
size();
734 ::Dune::Petsc::MatSetValues( petscMatrix_, rSize, r.
data(), cSize, c.
data(), v.
data(), INSERT_VALUES );
735 setStatus( statAssembled );
741 ::Dune::Petsc::MatView( petscMatrix_, PETSC_VIEWER_STDOUT_WORLD );
754 Mat& exportMatrix ()
const
762 PetscLinearOperator ();
767 if( status_ != statNothing )
769 ::Dune::Petsc::MatDestroy( &petscMatrix_ );
770 status_ = statNothing ;
777 void setStatus (
const Status &newstatus)
const
780#ifndef USE_SMP_PARALLEL
785 template<
class DFS,
class Entity >
788 NonBlockMapper< const typename PetscMappers< DFS >::ParallelMapperType, DFS::localBlockSize > nonBlockMapper( mappers.parallelMapper() );
789 nonBlockMapper.map( entity, indices );
792 template<
class DFS,
class Entity >
795 mappers.parallelMapper().map( entity, indices );
801 DomainMappersType domainMappers_;
802 RangeMappersType rangeMappers_;
805 mutable Mat petscMatrix_;
807 mutable LocalMatrixStackType localMatrixStack_;
808 mutable Status status_;
815 mutable ThreadSafeValue< std::vector< PetscScalar > > v_;
827 template<
typename DomainFunction,
typename RangeFunction >
828 class PetscLinearOperator< DomainFunction, RangeFunction >::LocalMatrix
829 :
public LocalMatrixDefault< typename PetscLinearOperator< DomainFunction, RangeFunction >::LocalMatrixTraits >
831 typedef LocalMatrix ThisType;
832 typedef LocalMatrixDefault< typename PetscLinearOperator< DomainFunction, RangeFunction >::LocalMatrixTraits > BaseType;
834 typedef PetscLinearOperator< DomainFunction, RangeFunction > PetscLinearOperatorType;
838 typedef PetscInt DofIndexType;
840 typedef typename DomainFunction::DiscreteFunctionSpaceType DomainSpaceType;
841 typedef typename RangeFunction::DiscreteFunctionSpaceType RangeSpaceType;
842 typedef typename DomainSpaceType::BasisFunctionSetType DomainBasisFunctionSetType;
843 typedef typename RangeSpaceType::BasisFunctionSetType RangeBasisFunctionSetType;
845 enum { rangeBlockSize = RangeSpaceType::localBlockSize };
846 enum { domainBlockSize = DomainSpaceType ::localBlockSize };
851 template<
typename PetscMapping >
852 struct PetscAssignFunctor
854 explicit PetscAssignFunctor (
const PetscMapping &petscMapping, IndexVectorType &indices )
855 : petscMapping_( petscMapping ),
859 template<
typename T >
860 void operator() (
const std::size_t localIndex, T globalIndex ) { indices_[ localIndex ] = petscMapping_.globalMapping( globalIndex ); }
863 const PetscMapping &petscMapping_;
864 IndexVectorType &indices_;
868 [[deprecated(
"Use TemporaryLocal Matrix and {add,set,get}LocalMatrix")]]
869 LocalMatrix (
const PetscLinearOperatorType &petscLinOp,
870 const DomainSpaceType &domainSpace,
871 const RangeSpaceType &rangeSpace )
872 : BaseType( domainSpace, rangeSpace ),
873 petscLinearOperator_( petscLinOp )
880 void init (
const DomainEntityType &domainEntity,
const RangeEntityType &rangeEntity )
883 BaseType :: init( domainEntity, rangeEntity );
893 setupIndices( petscLinearOperator_.rangeMappers_, rangeEntity, rowIndices_ );
894 setupIndices( petscLinearOperator_.domainMappers_, domainEntity, colIndices_ );
896 status_ = statAssembled;
897 petscLinearOperator_.setStatus(status_);
900 inline void add (
const int localRow,
const int localCol,
const RangeFieldType &value )
902 assert( status_==statAssembled || status_==statAdd );
904 petscLinearOperator_.setStatus(status_);
905 ::Dune::Petsc::MatSetValue( petscMatrix(), globalRowIndex( localRow ), globalColIndex( localCol ) , value, ADD_VALUES );
908 inline void set(
const int localRow,
const int localCol,
const RangeFieldType &value )
910 assert( status_==statAssembled || status_==statInsert );
911 status_ = statInsert;
912 petscLinearOperator_.setStatus(status_);
913 ::Dune::Petsc::MatSetValue( petscMatrix(), globalRowIndex( localRow ), globalColIndex( localCol ) , value, INSERT_VALUES );
917 void clearRow (
const int localRow )
919 assert( status_==statAssembled || status_==statInsert );
920 status_ = statInsert;
921 petscLinearOperator_.setStatus(status_);
922 const int col = this->columns();
923 const int globalRowIdx = globalRowIndex( localRow );
924 for(
int localCol=0; localCol<
col; ++localCol)
926 ::Dune::Petsc::MatSetValue( petscMatrix(), globalRowIdx, globalColIndex( localCol ), 0.0, INSERT_VALUES );
930 inline const RangeFieldType
get (
const int localRow,
const int localCol )
const
932 assert( status_==statAssembled || status_==statGet );
934 petscLinearOperator_.setStatus(status_);
936 const int r[] = {globalRowIndex( localRow )};
937 const int c[] = {globalColIndex( localCol )};
938 ::Dune::Petsc::MatGetValues( petscMatrix(), 1, r, 1, c, v );
942 inline void scale (
const RangeFieldType &factor )
944 const_cast< PetscLinearOperatorType&
> (petscLinearOperator_).scaleLocalMatrix( this->domainEntity(), this->rangeEntity(), factor );
950 Mat& petscMatrix () {
return petscLinearOperator_.petscMatrix_; }
951 const Mat& petscMatrix ()
const {
return petscLinearOperator_.petscMatrix_; }
954 int rows()
const {
return rowIndices_.size(); }
955 int columns()
const {
return colIndices_.size(); }
958 DofIndexType globalRowIndex(
const int localRow )
const
960 assert( localRow <
static_cast< int >( rowIndices_.size() ) );
961 return rowIndices_[ localRow ];
964 DofIndexType globalColIndex(
const int localCol )
const
966 assert( localCol <
static_cast< int >( colIndices_.size() ) );
967 return colIndices_[ localCol ];
973 const PetscLinearOperatorType &petscLinearOperator_;
974 IndexVectorType rowIndices_;
975 IndexVectorType colIndices_;
976 mutable Status status_;
void init(const Matrix *matrix)
void add(const Vertex &vertex)
auto rows(Matrix const &matrix)
auto cols(Matrix const &matrix)
void push_back(const MemberType &item)
static TupleAccessTraits< typenameAtType< N, Tuple >::Type >::NonConstType get(Tuple &t)
bool exists(size_type i, size_type j) const
virtual void operator()()=0
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
const Communication & comm() const
Dune::Fem::Double abs(const Dune::Fem::Double &a)
Definition double.hh:942
GridImp::template Codim< cd >::Entity Entity