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> >
82 return SolverCategory::Category::sequential;
93 SPQR(
const Matrix& matrix,
int verbose=0) : matrixIsLoaded_(false), verbose_(verbose)
96 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
97 "Unsupported Type in SPQR (only double and std::complex<double> supported)");
98 cc_ =
new cholmod_common();
111 SPQR(
const Matrix& matrix,
int verbose,
bool) : matrixIsLoaded_(false), verbose_(verbose)
114 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
115 "Unsupported Type in SPQR (only double and std::complex<double> supported)");
116 cc_ =
new cholmod_common();
117 cholmod_l_start(cc_);
122 SPQR() : matrixIsLoaded_(false), verbose_(0)
125 static_assert((std::is_same<T,double>::value) || (std::is_same<T,std::complex<double> >::value),
126 "Unsupported Type in SPQR (only double and std::complex<double> supported)");
127 cc_ =
new cholmod_common();
128 cholmod_l_start(cc_);
134 if ((spqrMatrix_.N() + spqrMatrix_.M() > 0) || matrixIsLoaded_)
136 cholmod_l_finish(cc_);
142 const std::size_t dimMat(spqrMatrix_.N());
144 for(std::size_t k = 0; k != dimMat; ++k)
145 (static_cast<T*>(B_->x))[k] = b[k];
146 cholmod_dense* BTemp = B_;
147 B_ = SuiteSparseQR_qmult<T>(0, spqrfactorization_, B_, cc_);
148 cholmod_dense* X = SuiteSparseQR_solve<T>(1, spqrfactorization_, B_, cc_);
149 cholmod_l_free_dense(&BTemp, cc_);
151 for(std::size_t k = 0; k != dimMat; ++k)
152 x [k] = (static_cast<T*>(X->x))[k];
153 cholmod_l_free_dense(&X, cc_);
159 std::cout<<std::endl<<
"Solving with SuiteSparseQR"<<std::endl;
160 std::cout<<
"Flops Taken: "<<cc_->SPQR_flopcount<<std::endl;
161 std::cout<<
"Analysis Time: "<<cc_->SPQR_analyze_time<<
" s"<<std::endl;
162 std::cout<<
"Factorize Time: "<<cc_->SPQR_factorize_time<<
" s"<<std::endl;
163 std::cout<<
"Backsolve Time: "<<cc_->SPQR_solve_time<<
" s"<<std::endl;
164 std::cout<<
"Peak Memory Usage: "<<cc_->memory_usage<<
" bytes"<<std::endl;
165 std::cout<<
"Rank Estimate: "<<cc_->SPQR_istat[4]<<std::endl<<std::endl;
172 DUNE_UNUSED_PARAMETER(reduction);
178 DUNE_UNUSED_PARAMETER(option);
179 DUNE_UNUSED_PARAMETER(value);
185 if ((spqrMatrix_.N() + spqrMatrix_.M() > 0) || matrixIsLoaded_)
187 spqrMatrix_ = matrix;
194 if ((spqrMatrix_.N() + spqrMatrix_.M() > 0) || matrixIsLoaded_)
196 spqrMatrix_.setMatrix(matrix,rowIndexSet);
215 return spqrfactorization_;
233 cholmod_l_free_sparse(&A_, cc_);
234 cholmod_l_free_dense(&B_, cc_);
235 SuiteSparseQR_free<T>(&spqrfactorization_, cc_);
237 matrixIsLoaded_ =
false;
247 template<
class M,
class X,
class TM,
class TD,
class T1>
255 const std::size_t dimMat(spqrMatrix_.N());
256 const std::size_t nnz(spqrMatrix_.getColStart()[dimMat]);
258 A_ = cholmod_l_allocate_sparse(dimMat, dimMat, nnz, 1, 1, 0, 1, cc_);
260 for(std::size_t k = 0; k != (dimMat+1); ++k)
261 (static_cast<long int *>(A_->p))[k] = spqrMatrix_.getColStart()[k];
262 for(std::size_t k = 0; k != nnz; ++k)
264 (
static_cast<long int*
>(A_->i))[k] = spqrMatrix_.getRowIndex()[k];
265 (
static_cast<T*
>(A_->x))[k] = spqrMatrix_.getValues()[k];
268 B_ = cholmod_l_allocate_dense(dimMat, 1, dimMat, A_->xtype, cc_);
270 spqrfactorization_=SuiteSparseQR_factorize<T>(SPQR_ORDERING_DEFAULT,SPQR_DEFAULT_TOL,A_,cc_);
273 SPQRMatrix spqrMatrix_;
274 bool matrixIsLoaded_;
279 SuiteSparseQR_factorization<T>* spqrfactorization_;
282 template<
typename T,
typename A,
int n,
int m>
288 template<
typename T,
typename A,
int n,
int m>
296 #endif //HAVE_SUITESPARSE_SPQR 297 #endif //DUNE_ISTL_SPQR_HH SuiteSparseQR_factorization< T > * getFactorization()
Return the matrix factorization.
Definition: spqr.hh:213
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
Inititializer for the ColCompMatrix as needed by OverlappingSchwarz.
Definition: colcompmatrix.hh:153
Definition: allocator.hh:7
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:422
void setVerbosity(int v)
Sets the verbosity level for the solver.
Definition: spqr.hh:204
Implementations of the inverse operator interface.
virtual void apply(domain_type &x, range_type &b, double reduction, InverseOperatorResult &res)
apply inverse operator, with given convergence criteria.
Definition: spqr.hh:170
Definition: colcompmatrix.hh:160
void setSubMatrix(const Matrix &matrix, const S &rowIndexSet)
Definition: spqr.hh:192
virtual ~SPQR()
Destructor.
Definition: spqr.hh:132
SPQR()
Default constructor.
Definition: spqr.hh:122
Definition: solvertype.hh:27
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
Definition: colcompmatrix.hh:250
void setMatrix(const Matrix &matrix)
Initialize data from given matrix.
Definition: spqr.hh:183
Sequential overlapping Schwarz preconditioner.
Definition: colcompmatrix.hh:157
bool converged
True if convergence criterion has been met.
Definition: solver.hh:65
Abstract base class for all solvers.
Definition: solver.hh:91
void free()
Free allocated space.
Definition: spqr.hh:231
virtual void apply(domain_type &x, range_type &b, InverseOperatorResult &res)
Apply inverse operator,.
Definition: spqr.hh:140
SPQR(const Matrix &matrix, int verbose, bool)
Constructor for compatibility with SuperLU standard constructor.
Definition: spqr.hh:111
Category
Definition: solvercategory.hh:21
Definition: solvertype.hh:13
SPQRMatrix & getInternalMatrix()
Return the column coppressed matrix.
Definition: spqr.hh:222
Dune::ColCompMatrix< Matrix > SPQRMatrix
The corresponding SuperLU Matrix type.
Definition: spqr.hh:71
A vector of blocks with memory management.
Definition: bvector.hh:316
Use the SPQR package to directly solve linear systems – empty default class.
Definition: spqr.hh:45
virtual SolverCategory::Category category() const
Category of the solver (see SolverCategory::Category)
Definition: spqr.hh:80
Statistics about the application of an inverse operator.
Definition: solver.hh:40
SPQR(const Matrix &matrix, int verbose=0)
Construct a solver object from a BCRSMatrix.
Definition: spqr.hh:93
int iterations
Number of iterations.
Definition: solver.hh:59
Templates characterizing the type of a solver.
const char * name()
Get method name.
Definition: spqr.hh:241
void setOption(unsigned int option, double value)
Definition: spqr.hh:176