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)");
92 cc_ =
new cholmod_common();
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)");
110 cc_ =
new cholmod_common();
111 cholmod_l_start(cc_);
116 SPQR() : matrixIsLoaded_(false), verbose_(0)
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)");
121 cc_ =
new cholmod_common();
122 cholmod_l_start(cc_);
128 if ((spqrMatrix_.N() + spqrMatrix_.M() > 0) || matrixIsLoaded_)
130 cholmod_l_finish(cc_);
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];
140 cholmod_dense* BTemp = B_;
141 B_ = SuiteSparseQR_qmult<T>(0, spqrfactorization_, B_, cc_);
142 cholmod_dense* X = SuiteSparseQR_solve<T>(1, spqrfactorization_, B_, cc_);
143 cholmod_l_free_dense(&BTemp, cc_);
145 for(std::size_t k = 0; k != dimMat; ++k)
146 x [k] = (static_cast<T*>(X->x))[k];
147 cholmod_l_free_dense(&X, cc_);
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;
166 DUNE_UNUSED_PARAMETER(reduction);
172 DUNE_UNUSED_PARAMETER(option);
173 DUNE_UNUSED_PARAMETER(value);
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_;
227 cholmod_l_free_sparse(&A_, cc_);
228 cholmod_l_free_dense(&B_, cc_);
229 SuiteSparseQR_free<T>(&spqrfactorization_, cc_);
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]);
252 A_ = cholmod_l_allocate_sparse(dimMat, dimMat, nnz, 1, 1, 0, 1, cc_);
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];
262 B_ = cholmod_l_allocate_dense(dimMat, 1, dimMat, A_->xtype, cc_);
264 spqrfactorization_=SuiteSparseQR_factorize<T>(SPQR_ORDERING_DEFAULT,SPQR_DEFAULT_TOL,A_,cc_);
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>
290 #endif //HAVE_SUITESPARSE_SPQR 291 #endif //DUNE_ISTL_SPQR_HH Definition: solvertype.hh:27
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, InverseOperatorResult &res)
Apply inverse operator,.
Definition: spqr.hh:134
SuiteSparseQR_factorization< T > * getFactorization()
Return the matrix factorization.
Definition: spqr.hh:207
Statistics about the application of an inverse operator.
Definition: solver.hh:31
void free()
Free allocated space.
Definition: spqr.hh:225
Implementations of the inverse operator interface.
Inititializer for the ColCompMatrix as needed by OverlappingSchwarz.
Definition: colcompmatrix.hh:153
void setVerbosity(int v)
Sets the verbosity level for the solver.
Definition: spqr.hh:198
SPQR(const Matrix &matrix, int verbose=0)
Construct a solver object from a BCRSMatrix.
Definition: spqr.hh:87
Dune::ColCompMatrix< Matrix > SPQRMatrix
The corresponding SuperLU Matrix type.
Definition: spqr.hh:71
Templates characterizing the type of a solver.
void setOption(unsigned int option, double value)
Definition: spqr.hh:170
Definition: colcompmatrix.hh:160
void setSubMatrix(const Matrix &matrix, const S &rowIndexSet)
Definition: spqr.hh:186
Definition: solvertype.hh:13
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
Definition: matrixutils.hh:25
Use the SPQR package to directly solve linear systems – empty default class.
Definition: spqr.hh:45
void setMatrix(const Matrix &matrix)
Initialize data from given matrix.
Definition: spqr.hh:177
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:411
int iterations
Number of iterations.
Definition: solver.hh:50
Definition: basearray.hh:19
bool converged
True if convergence criterion has been met.
Definition: solver.hh:56
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
A vector of blocks with memory management.
Definition: bvector.hh:308
virtual void apply(domain_type &x, range_type &b, double reduction, InverseOperatorResult &res)
apply inverse operator, with given convergence criteria.
Definition: spqr.hh:164
const char * name()
Get method name.
Definition: spqr.hh:235
Abstract base class for all solvers.
Definition: solver.hh:79
Definition: colcompmatrix.hh:250
Sequential overlapping Schwarz preconditioner.
Definition: colcompmatrix.hh:157
virtual ~SPQR()
Destructor.
Definition: spqr.hh:126
SPQR()
Default constructor.
Definition: spqr.hh:116