From 9a0492148a187ea86594a7cc5fe5b504709c34a1 Mon Sep 17 00:00:00 2001 From: kanschat Date: Tue, 3 Apr 2012 18:45:11 +0000 Subject: [PATCH] add coarse grid solver based on SVD git-svn-id: https://svn.dealii.org/trunk@25377 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/multigrid/mg_coarse.h | 90 ++++++++++++++++--- 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/deal.II/include/deal.II/multigrid/mg_coarse.h b/deal.II/include/deal.II/multigrid/mg_coarse.h index 7a2dba4035..afb28b8dfc 100644 --- a/deal.II/include/deal.II/multigrid/mg_coarse.h +++ b/deal.II/include/deal.II/multigrid/mg_coarse.h @@ -134,25 +134,58 @@ class MGCoarseGridHouseholder : public MGCoarseGridBase * Initialize for a new matrix. */ void initialize (const FullMatrix& A); + + void operator() (const unsigned int level, + VECTOR &dst, + const VECTOR &src) const; + private: /** - * Release matrix pointer. + * Matrix for QR-factorization. */ - void clear (); + Householder householder; +}; +/** + * Coarse grid solver using singular value decomposition of LAPACK matrices. + * + * Upon initialization, the singular value decomposition of the matrix is + * computed. then, the operator() uses + * + * @author Guido Kanschat, 2003, 2012 + */ +template > +class MGCoarseGridSVD : public MGCoarseGridBase +{ + public: + /** + * Constructor leaving an + * uninitialized object. + */ + MGCoarseGridSVD (); + /** - * Solution operator, defined in - * the base class. + * Initialize for a new + * matrix. This resets the + * dimensions to the */ + void initialize (const FullMatrix& A, const double threshold = 1.e-12); + void operator() (const unsigned int level, VECTOR &dst, const VECTOR &src) const; - + + /** + * Write the singular values to #deallog. + */ + void log () const; + private: + /** - * Matrix for QR-factorization. + * Matrix for singular value decomposition. */ - Householder householder; + LAPACKFullMatrix matrix; }; /*@}*/ @@ -274,21 +307,58 @@ MGCoarseGridHouseholder::initialize( template void -MGCoarseGridHouseholder::clear() +MGCoarseGridHouseholder::operator() ( + const unsigned int, + VECTOR &dst, + const VECTOR &src) const +{ + householder.least_squares(dst, src); +} + +//--------------------------------------------------------------------------- + +template +inline +MGCoarseGridSVD::MGCoarseGridSVD() {} template void -MGCoarseGridHouseholder::operator() ( +MGCoarseGridSVD::initialize( + const FullMatrix& A, + double threshold) +{ + matrix.reinit(A.n_rows(), A.n_cols()); + matrix = A; + matrix.compute_inverse_svd(threshold); +} + + +template +void +MGCoarseGridSVD::operator() ( const unsigned int, VECTOR &dst, const VECTOR &src) const { - householder.least_squares(dst, src); + matrix.vmult(dst, src); } + +template +void +MGCoarseGridSVD::log() const +{ + const unsigned int n = std::min(matrix.n_rows(), matrix.n_cols()); + + for (unsigned int i=0;i