From: Jonathan Robey Date: Tue, 6 Aug 2019 20:27:28 +0000 (-0600) Subject: Add frobenius_norm method to BlockMatrixBase X-Git-Tag: v9.2.0-rc1~1286^2~7 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43370d37647e4d446e8681b754a7e3122b2d8663;p=dealii.git Add frobenius_norm method to BlockMatrixBase Fix to #7629 --- diff --git a/include/deal.II/lac/block_matrix_base.h b/include/deal.II/lac/block_matrix_base.h index daee645f62..ce2649802f 100644 --- a/include/deal.II/lac/block_matrix_base.h +++ b/include/deal.II/lac/block_matrix_base.h @@ -698,6 +698,13 @@ public: value_type matrix_norm_square(const BlockVectorType &v) const; + /** + * Return the frobenius norm of the matrix, i.e. the square root of the sum + * of squares of all entries in the matrix. + */ + value_type + frobenius_norm() const; + /** * Compute the matrix scalar product $\left(u,Mv\right)$. */ @@ -2401,6 +2408,29 @@ BlockMatrixBase::matrix_norm_square(const BlockVectorType &v) const +template +typename BlockMatrixBase::value_type +BlockMatrixBase::frobenius_norm() const +{ + value_type norm_sqr = 0; + + + // For each block, get the Frobenius norm, and add the square to the + // accumulator for the full matrix + for (unsigned int row = 0; row < n_block_rows(); ++row) + { + for (unsigned int col = 0; col < n_block_cols(); ++col) + { + const value_type block_norm = block(row, col).frobenius_norm(); + norm_sqr += block_norm * block_norm; + } + } + + return std::sqrt(norm_sqr); +} + + + template template typename BlockMatrixBase::value_type