From: Wolfgang Bangerth Date: Wed, 15 Apr 1998 15:55:57 +0000 (+0000) Subject: Add a function computing the norm with respect to a matrix. X-Git-Tag: v8.0.0~23076 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2fb086d8a2242bdd7847a18da7173a53698a0e0;p=dealii.git Add a function computing the norm with respect to a matrix. git-svn-id: https://svn.dealii.org/trunk@178 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/dsmatrix.h b/deal.II/lac/include/lac/dsmatrix.h index d8eef99fd6..b7b5f8979f 100644 --- a/deal.II/lac/include/lac/dsmatrix.h +++ b/deal.II/lac/include/lac/dsmatrix.h @@ -54,7 +54,7 @@ public: ////////// void compress (); ////////// - int operator() (const unsigned int i, const unsigned int j); + int operator() (const unsigned int i, const unsigned int j) const; ////////// void add (const unsigned int i, const unsigned int j); ////////// @@ -83,6 +83,12 @@ public: * access to the rowstart array, but * readonly. * + * Though the return value is declared + * #const#, you shoudl be aware that it + * may change if you call any nonconstant + * function of objects which operate on + * it. + * * You should use this interface very * carefully and only if you are absolutely * sure to know what you do. You should @@ -100,6 +106,12 @@ public: * access to the colnums array, but * readonly. * + * Though the return value is declared + * #const#, you shoudl be aware that it + * may change if you call any nonconstant + * function of objects which operate on + * it. + * * You should use this interface very * carefully and only if you are absolutely * sure to know what you do. You should @@ -146,7 +158,7 @@ CLASS */ class dSMatrix { - dSMatrixStruct * cols; + const dSMatrixStruct * cols; double* val; unsigned int max_len; public: @@ -287,6 +299,30 @@ class dSMatrix // void Tvmult (dVector& dst,const dVector& src) const; + + /** + * Return the norm of the vector #v# with + * respect to the norm induced by this + * matrix, i.e. $\left$. This + * is useful, e.g. in the finite element + * context, where the $L_2$ norm of a + * function equals the matrix norm with + * respect to the mass matrix of the vector + * representing the nodal values of the + * finite element function. + * + * Note the order in which the matrix + * appears. For non-symmetric matrices + * there is a difference whether the + * matrix operates on the first + * or on the second operand of the + * scalar product. + * + * Obviously, the matrix needs to be square + * for this operation. + */ + double matrix_norm (const dVector &v) const; + // double residual (dVector& dst, const dVector& x, const dVector& b); // @@ -309,6 +345,12 @@ class dSMatrix * Return a (constant) reference to the * underlying sparsity pattern of this * matrix. + * + * Though the return value is declared + * #const#, you shoudl be aware that it + * may change if you call any nonconstant + * function of objects which operate on + * it. */ const dSMatrixStruct & get_sparsity_pattern () const; diff --git a/deal.II/lac/source/dsmatrix.cc b/deal.II/lac/source/dsmatrix.cc index be393ca0a1..b387aa2aa3 100644 --- a/deal.II/lac/source/dsmatrix.cc +++ b/deal.II/lac/source/dsmatrix.cc @@ -232,8 +232,11 @@ dSMatrixStruct::compress () int -dSMatrixStruct::operator () (const unsigned int i, const unsigned int j) +dSMatrixStruct::operator () (const unsigned int i, const unsigned int j) const { + Assert (irowstart[i]; jrowstart[i+1]; ++j) + s += val[j] * v(cols->colnums[j]); + sum += s*v(i); + }; + + return sum; +} + + + double dSMatrix::residual (dVector& dst, const dVector& u, const dVector& b) {