From: guido Date: Wed, 27 Jun 2001 17:10:10 +0000 (+0000) Subject: shifted matrices in a separate file X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7970e4e75a21ddfdbf65f4cee567dae6b24e2729;p=dealii-svn.git shifted matrices in a separate file git-svn-id: https://svn.dealii.org/trunk@4766 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/eigen.h b/deal.II/lac/include/lac/eigen.h index c2886da3ba..fb43f77a54 100644 --- a/deal.II/lac/include/lac/eigen.h +++ b/deal.II/lac/include/lac/eigen.h @@ -14,65 +14,13 @@ #define __deal2__eigen_h +#include #include #include #include #include #include -/** - * Matrix with shifted diagonal values. - * - * Given a matrix $A$, this class implements a matrix-vector product with - * $A+\sigma I$, where sigma is a provided shift parameter. - * - * @author Guido Kanschat, 2000 - */ -template -class ShiftedMatrix -{ - public: - /** - * Constructor. - * Provide the base matrix and a shift parameter. - */ - ShiftedMatrix (const MATRIX& A, const double sigma); - - /** - * Set the shift parameter. - */ - void shift (const double sigma); - - /** - * Access to the shift parameter. - */ - double shift () const; - - /** - * Matrix-vector-product. - */ - template - void vmult (VECTOR& dst, const VECTOR& src) const; - - /** - * Residual. - */ - template - double residual (VECTOR& dst, const VECTOR& src, const VECTOR& rhs) const; - - private: - /** - * Storage for base matrix. - */ - const MATRIX& A; - - /** - * Shift parameter. - */ - double sigma; -}; - - /** * Power method (von Mises). * @@ -230,58 +178,6 @@ class EigenInverse : private Solver AdditionalData additional_data; }; -//----------------------------------------------------------------------// - -template -inline -ShiftedMatrix::ShiftedMatrix (const MATRIX& A, const double sigma) - : - A(A), sigma(sigma) -{} - - - -template -inline void -ShiftedMatrix::shift (const double s) -{ - sigma = s; -} - - -template -inline double -ShiftedMatrix::shift () const -{ - return sigma; -} - - - -template -template -inline void -ShiftedMatrix::vmult (VECTOR& dst, const VECTOR& src) const -{ - A.vmult(dst, src); - dst.add(sigma, src); -} - - -template -template -inline double -ShiftedMatrix::residual (VECTOR& dst, - const VECTOR& src, - const VECTOR& rhs) const -{ - A.vmult(dst, src); - dst.add(sigma, src); - dst.sadd(-1.,1.,rhs); - return dst.l2_norm (); -} - - //---------------------------------------------------------------------- diff --git a/deal.II/lac/include/lac/shifted_matrix.h b/deal.II/lac/include/lac/shifted_matrix.h new file mode 100644 index 0000000000..57849269c9 --- /dev/null +++ b/deal.II/lac/include/lac/shifted_matrix.h @@ -0,0 +1,242 @@ +//---------------------------- eigen.h --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2001 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- eigen.h --------------------------- +#ifndef __deal2__shifted_matrix_h +#define __deal2__shifted_matrix_h + + +#include + +/** + * Matrix with shifted diagonal values. + * + * Given a matrix p{A}, this class implements a matrix-vector product with + * @p{A+\sigma I}, where sigma is a provided shift parameter. + * + * @author Guido Kanschat, 2000, 2001 + */ +template +class ShiftedMatrix +{ + public: + /** + * Constructor. + * Provide the base matrix and a shift parameter. + */ + ShiftedMatrix (const MATRIX& A, const double sigma); + + /** + * Set the shift parameter. + */ + void shift (const double sigma); + + /** + * Access to the shift parameter. + */ + double shift () const; + + /** + * Matrix-vector-product. + */ + template + void vmult (VECTOR& dst, const VECTOR& src) const; + + /** + * Residual. + */ + template + double residual (VECTOR& dst, const VECTOR& src, const VECTOR& rhs) const; + + private: + /** + * Storage for base matrix. + */ + SmartPointer A; + + /** + * Shift parameter. + */ + double sigma; +}; + + + +/** + * Matrix with shifted diagonal values with respect to a certain scalar product. + * + * Given a matrix @p{A}, this class implements a matrix-vector product + * with @p{A+\sigma M}, where sigma is a provided shift parameter and + * @p{M} is the matrix representing the identity + * + * @author Guido Kanschat, 2001 + */ +template +class ShiftedMatrixGeneralized +{ + public: + /** + * Constructor. + * Provide the base matrix and a shift parameter. + */ + ShiftedMatrixGeneralized (const MATRIX& A, + const MASSMATRIX& M, + const double sigma); + + /** + * Set the shift parameter. + */ + void shift (const double sigma); + + /** + * Access to the shift parameter. + */ + double shift () const; + + /** + * Matrix-vector-product. + */ + template + void vmult (VECTOR& dst, const VECTOR& src) const; + + /** + * Residual. + */ + template + double residual (VECTOR& dst, const VECTOR& src, const VECTOR& rhs) const; + + private: + /** + * Storage for base matrix. + */ + SmartPointer A; + /** + * Storage for mass matrix. + */ + SmartPointer M; + + /** + * Shift parameter. + */ + double sigma; +}; + + + +//----------------------------------------------------------------------// + +template +inline +ShiftedMatrix::ShiftedMatrix (const MATRIX& A, const double sigma) + : + A(&A), sigma(sigma) +{} + + + +template +inline void +ShiftedMatrix::shift (const double s) +{ + sigma = s; +} + + +template +inline double +ShiftedMatrix::shift () const +{ + return sigma; +} + + + +template +template +inline void +ShiftedMatrix::vmult (VECTOR& dst, const VECTOR& src) const +{ + A.vmult(dst, src); + dst.add(sigma, src); +} + + +template +template +inline double +ShiftedMatrix::residual (VECTOR& dst, + const VECTOR& src, + const VECTOR& rhs) const +{ + A.vmult(dst, src); + dst.add(sigma, src); + dst.sadd(-1.,1.,rhs); + return dst.l2_norm (); +} + + +//----------------------------------------------------------------------// + +template +inline +ShiftedMatrixGeneralized +::ShiftedMatrixGeneralized (const MATRIX& A, + const MASSMATRIX& M, + const double sigma) + : + A(&A), M(&M), sigma(sigma) +{} + + + +template +inline void +ShiftedMatrixGeneralized::shift (const double s) +{ + sigma = s; +} + + +template +inline double +ShiftedMatrixGeneralized::shift () const +{ + return sigma; +} + + + +template +template +inline void +ShiftedMatrixGeneralized::vmult (VECTOR& dst, + const VECTOR& src) const +{ + A.vmult(dst, src); + dst.add(sigma, src); +} + + +template +template +inline double +ShiftedMatrixGeneralized::residual (VECTOR& dst, + const VECTOR& src, + const VECTOR& rhs) const +{ + A.vmult(dst, src); + dst.add(sigma, src); + dst.sadd(-1.,1.,rhs); + return dst.l2_norm (); +} + + +#endif