3#ifndef DUNE_ISTL_SPQR_HH
4#define DUNE_ISTL_SPQR_HH
6#if HAVE_SUITESPARSE_SPQR || defined DOXYGEN
11#include <SuiteSparseQR.hpp>
13#include <dune/common/exceptions.hh>
14#include <dune/common/unused.hh>
33 template<
class M,
class T,
class TM,
class TD,
class TA>
34 class SeqOverlappingSchwarz;
36 template<
class T,
bool tag>
37 struct SeqOverlappingSchwarzAssemblerHelper;
44 template<
class Matrix>
61 template<
typename T,
typename A,
int n,
int m>
63 :
public InverseOperator<BlockVector<FieldVector<T,m>, typename A::template rebind<FieldVector<T,m> >::other>,
64 BlockVector<FieldVector<T,n>, typename A::template rebind<FieldVector<T,n> >::other> >
87 SPQR(
const Matrix& matrix,
int verbose=0) : matrixIsLoaded_(
false), verbose_(verbose)
90 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
91 "Unsupported Type in SPQR (only double and std::complex<double> supported)");
105 SPQR(
const Matrix& matrix,
int verbose,
bool) : matrixIsLoaded_(
false), verbose_(verbose)
108 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
109 "Unsupported Type in SPQR (only double and std::complex<double> supported)");
119 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
120 "Unsupported Type in SPQR (only double and std::complex<double> supported)");
128 if ((spqrMatrix_.N() + spqrMatrix_.M() > 0) || matrixIsLoaded_)
136 const std::size_t
dimMat(spqrMatrix_.N());
138 for(std::size_t k = 0; k !=
dimMat; ++k)
139 (
static_cast<T*
>(B_->x))[k] = b[k];
145 for(std::size_t k = 0; k !=
dimMat; ++k)
146 x [k] = (
static_cast<T*
>(X->x))[k];
150 res.converged =
true;
153 std::cout<<std::endl<<
"Solving with SuiteSparseQR"<<std::endl;
154 std::cout<<
"Flops Taken: "<<cc_->SPQR_flopcount<<std::endl;
155 std::cout<<
"Analysis Time: "<<cc_->SPQR_analyze_time<<
" s"<<std::endl;
156 std::cout<<
"Factorize Time: "<<cc_->SPQR_factorize_time<<
" s"<<std::endl;
157 std::cout<<
"Backsolve Time: "<<cc_->SPQR_solve_time<<
" s"<<std::endl;
158 std::cout<<
"Peak Memory Usage: "<<cc_->memory_usage<<
" bytes"<<std::endl;
159 std::cout<<
"Rank Estimate: "<<cc_->SPQR_istat[4]<<std::endl<<std::endl;
179 if ((spqrMatrix_.N() + spqrMatrix_.M() > 0) || matrixIsLoaded_)
181 spqrMatrix_ = matrix;
188 if ((spqrMatrix_.N() + spqrMatrix_.M() > 0) || matrixIsLoaded_)
190 spqrMatrix_.setMatrix(matrix,rowIndexSet);
209 return spqrfactorization_;
231 matrixIsLoaded_ =
false;
241 template<
class M,
class X,
class TM,
class TD,
class T1>
249 const std::size_t
dimMat(spqrMatrix_.N());
250 const std::size_t nnz(spqrMatrix_.getColStart()[
dimMat]);
254 for(std::size_t k = 0; k != (
dimMat+1); ++k)
255 (
static_cast<long int *
>(A_->p))[k] = spqrMatrix_.getColStart()[k];
256 for(std::size_t k = 0; k != nnz; ++k)
258 (
static_cast<long int*
>(A_->i))[k] = spqrMatrix_.getRowIndex()[k];
259 (
static_cast<T*
>(A_->x))[k] = spqrMatrix_.getValues()[k];
267 SPQRMatrix spqrMatrix_;
268 bool matrixIsLoaded_;
273 SuiteSparseQR_factorization<T>* spqrfactorization_;
276 template<
typename T,
typename A,
int n,
int m>
282 template<
typename T,
typename A,
int n,
int m>
Implementations of the inverse operator interface.
Templates characterizing the type of a solver.
Dune::BCRSMatrix< FieldMatrix< T, n, m >, A > matrix_type
Definition spqr.hh:69
virtual ~SPQR()
Destructor.
Definition spqr.hh:126
SPQR(const Matrix &matrix, int verbose, bool)
Constructor for compatibility with SuperLU standard constructor.
Definition spqr.hh:105
SPQRMatrix & getInternalMatrix()
Return the column coppressed matrix.
Definition spqr.hh:216
void setMatrix(const Matrix &matrix)
Initialize data from given matrix.
Definition spqr.hh:177
Dune::BCRSMatrix< FieldMatrix< T, n, m >, A > Matrix
The matrix type.
Definition spqr.hh:68
SPQR()
Default constructor.
Definition spqr.hh:116
const char * name()
Get method name.
Definition spqr.hh:235
SuiteSparseQR_factorization< T > * getFactorization()
Return the matrix factorization.
Definition spqr.hh:207
void setVerbosity(int v)
Sets the verbosity level for the solver.
Definition spqr.hh:198
Dune::ColCompMatrix< Matrix > SPQRMatrix
The corresponding SuperLU Matrix type.
Definition spqr.hh:71
Dune::BlockVector< FieldVector< T, m >, typename A::template rebind< FieldVector< T, m > >::other > domain_type
The type of the domain of the solver.
Definition spqr.hh:75
virtual void apply(domain_type &x, range_type &b, double reduction, InverseOperatorResult &res)
apply inverse operator, with given convergence criteria.
Definition spqr.hh:164
void free()
Free allocated space.
Definition spqr.hh:225
Dune::BlockVector< FieldVector< T, n >, typename A::template rebind< FieldVector< T, n > >::other > range_type
The type of the range of the solver.
Definition spqr.hh:77
ColCompMatrixInitializer< BCRSMatrix< FieldMatrix< T, n, m >, A > > MatrixInitializer
Type of an associated initializer class.
Definition spqr.hh:73
void setSubMatrix(const Matrix &matrix, const S &rowIndexSet)
Definition spqr.hh:186
virtual void apply(domain_type &x, range_type &b, InverseOperatorResult &res)
Apply inverse operator,.
Definition spqr.hh:134
void setOption(unsigned int option, double value)
Definition spqr.hh:170
SPQR(const Matrix &matrix, int verbose=0)
Construct a solver object from a BCRSMatrix.
Definition spqr.hh:87
Definition basearray.hh:19
Statistics about compression achieved in implicit mode.
Definition bcrsmatrix.hh:81
A sparse block matrix with compressed row storage.
Definition bcrsmatrix.hh:412
A vector of blocks with memory management.
Definition bvector.hh:309
Sequential overlapping Schwarz preconditioner.
Definition overlappingschwarz.hh:742
Definition overlappingschwarz.hh:683
Definition matrixutils.hh:25
Statistics about the application of an inverse operator.
Definition solver.hh:32
Abstract base class for all solvers.
Definition solver.hh:79
Definition solvertype.hh:14
@ value
Whether this is a direct solver.
Definition solvertype.hh:22
Definition solvertype.hh:28
@ value
whether the solver internally uses column compressed storage
Definition solvertype.hh:34
Use the SPQR package to directly solve linear systems – empty default class.
Definition spqr.hh:46