]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add frobenius_norm method to BlockMatrixBase
authorJonathan Robey <class4kayaker@gmail.com>
Tue, 6 Aug 2019 20:27:28 +0000 (14:27 -0600)
committerJonathan Robey <class4kayaker@gmail.com>
Tue, 6 Aug 2019 20:38:43 +0000 (14:38 -0600)
Fix to #7629

include/deal.II/lac/block_matrix_base.h

index daee645f62f084fc81e8dc5415c70914adbba401..ce2649802f9e8db975fbc2702dbd047c176cf48c 100644 (file)
@@ -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<MatrixType>::matrix_norm_square(const BlockVectorType &v) const
 
 
 
+template <class MatrixType>
+typename BlockMatrixBase<MatrixType>::value_type
+BlockMatrixBase<MatrixType>::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 <class MatrixType>
 template <class BlockVectorType>
 typename BlockMatrixBase<MatrixType>::value_type

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.