From 7af972dca2a39b7bbcd7a7ed476117736bcfd28f Mon Sep 17 00:00:00 2001 From: hartmann Date: Fri, 26 Feb 1999 17:42:24 +0000 Subject: [PATCH] Add the l1 (max sum of columns) and linfty (max sum of rows) matrix norms. These are the natural matrix norms that are compatible with the l1 and linfty norms of vectors git-svn-id: https://svn.dealii.org/trunk@920 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/full_matrix.h | 27 +++++++++++++ .../lac/include/lac/full_matrix.templates.h | 35 +++++++++++++++++ deal.II/lac/include/lac/sparse_matrix.h | 29 +++++++++++++- .../lac/include/lac/sparse_matrix.templates.h | 38 +++++++++++++++++++ 4 files changed, 128 insertions(+), 1 deletion(-) diff --git a/deal.II/lac/include/lac/full_matrix.h b/deal.II/lac/include/lac/full_matrix.h index fa539f6445..9d2f480c14 100644 --- a/deal.II/lac/include/lac/full_matrix.h +++ b/deal.II/lac/include/lac/full_matrix.h @@ -333,6 +333,33 @@ class FullMatrix */ template double matrix_scalar_product (const Vector &u, const Vector &v) const; + + /** + * Return the l1-norm of the matrix, i.e. + * $|M|_1=max_{all columns j}\sum_{all + * rows i} |M_ij|$, + * (max. sum of columns). + * This is the + * natural matrix norm that is compatible + * to the l1-norm for vectors, i.e. + * $|Mv|_1\leq |M|_1 |v|_1$. + * (cf. Rannacher Numerik0) + */ + number l1_norm () const; + + /** + * Return the linfty-norm of the + * matrix, i.e. + * $|M|_infty=max_{all rows i}\sum_{all + * columns j} |M_ij|$, + * (max. sum of rows). + * This is the + * natural matrix norm that is compatible + * to the linfty-norm of vectors, i.e. + * $|Mv|_infty \leq |M|_infty |v|_infty$. + * (cf. Rannacher Numerik0) + */ + number linfty_norm () const; /** * A=Inverse(A). Inversion of this by diff --git a/deal.II/lac/include/lac/full_matrix.templates.h b/deal.II/lac/include/lac/full_matrix.templates.h index 0ca8d63e56..2a153096f5 100644 --- a/deal.II/lac/include/lac/full_matrix.templates.h +++ b/deal.II/lac/include/lac/full_matrix.templates.h @@ -674,6 +674,41 @@ double FullMatrix::matrix_scalar_product (const Vector &u, cons }; +template +number FullMatrix::l1_norm () const +{ + number sum=0, max=0; + const unsigned int n_rows = m(), n_cols = n(); + + for (unsigned int col=0; col max) + max = sum; + } + return max; +}; + + +template +number FullMatrix::linfty_norm () const +{ + number sum=0, max=0; + const unsigned int n_rows = m(), n_cols = n(); + + for (unsigned int row=0; row max) + max = sum; + } + return max; +}; + template void diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index 10a72bc5e1..c686b4fa00 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -623,7 +623,34 @@ class SparseMatrix */ template double matrix_norm (const Vector &v) const; - + + /** + * Return the l1-norm of the matrix, i.e. + * $|M|_1=max_{all columns j}\sum_{all + * rows i} |M_ij|$, + * (max. sum of columns). + * This is the + * natural matrix norm that is compatible + * to the l1-norm for vectors, i.e. + * $|Mv|_1\leq |M|_1 |v|_1$. + * (cf. Rannacher Numerik0) + */ + number l1_norm () const; + + /** + * Return the linfty-norm of the + * matrix, i.e. + * $|M|_infty=max_{all rows i}\sum_{all + * columns j} |M_ij|$, + * (max. sum of rows). + * This is the + * natural matrix norm that is compatible + * to the linfty-norm of vectors, i.e. + * $|Mv|_infty \leq |M|_infty |v|_infty$. + * (cf. Rannacher Numerik0) + */ + number linfty_norm () const; + // template double residual (Vector& dst, const Vector& x, diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index 0e741caa99..b12f40b4fa 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -215,6 +215,44 @@ SparseMatrix::matrix_norm (const Vector& v) const }; +template +number SparseMatrix::l1_norm () const +{ + Assert (cols != 0, ExcMatrixNotInitialized()); + Assert (val != 0, ExcMatrixNotInitialized()); + + Vector column_sums(n()); + const unsigned int n_rows = m(); + for (unsigned int row=0; rowrowstart[row]; jrowstart[row+1] ; ++j) + column_sums(cols->colnums[j])+=fabs(val[j]); + + return column_sums.linfty_norm(); +}; + + +template +number SparseMatrix::linfty_norm () const +{ + Assert (cols != 0, ExcMatrixNotInitialized()); + Assert (val != 0, ExcMatrixNotInitialized()); + + const number *val_ptr = &val[cols->rowstart[0]]; + + number sum, max=0; + const unsigned int n_rows = m(); + for (unsigned int row=0; rowrowstart[row+1]]; + while (val_ptr != val_end_of_row) + sum += fabs(*val_ptr++); + if (sum > max) + max = sum; + } + return max; +}; + template template -- 2.39.5