]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Tpetra: Add frobenius_norm to SparseMatrix 16648/head
authorDaniel Arndt <arndtd@ornl.gov>
Wed, 14 Feb 2024 21:31:28 +0000 (16:31 -0500)
committerDaniel Arndt <arndtd@ornl.gov>
Wed, 14 Feb 2024 21:35:12 +0000 (16:35 -0500)
include/deal.II/lac/trilinos_tpetra_sparse_matrix.h
include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h

index 5fbf291cfd9ce3ffd06e214bc4ee4ba86cc83608..48de7bd615105dfe438e2f0a405ab5e1a9a730f2 100644 (file)
@@ -706,6 +706,20 @@ namespace LinearAlgebra
                  const Vector<Number, MemorySpace> &src) const;
       /** @} */
 
+      /**
+       * @name Matrix norms
+       */
+      /** @{ */
+
+      /**
+       * Return the frobenius norm of the matrix, i.e. the square root of the
+       * sum of squares of all entries in the matrix.
+       */
+      Number
+      frobenius_norm() const;
+
+      /** @} */
+
       /**
        * @name Mixed Stuff
        */
index 6dd1acaa63904115f6cc752c0c97cf8884c61c4b..de1d09db5053e49a6ec6b051e7af6073e5bdc4c2 100644 (file)
@@ -588,6 +588,16 @@ namespace LinearAlgebra
 
 
 
+    template <typename Number, typename MemorySpace>
+    Number
+    SparseMatrix<Number, MemorySpace>::frobenius_norm() const
+    {
+      Assert(matrix->isFillComplete(), ExcMatrixNotCompressed());
+      return matrix->getFrobeniusNorm();
+    }
+
+
+
     template <typename Number, typename MemorySpace>
     void
     SparseMatrix<Number, MemorySpace>::set(const size_type  row,
@@ -919,9 +929,9 @@ namespace LinearAlgebra
                                                const bool      no_error) const
     {
       // Extract local indices in the matrix.
-      const int      trilinos_i = matrix->getRowMap()->getLocalElement(i);
-      const int      trilinos_j = matrix->getColMap()->getLocalElement(j);
-      TrilinosScalar value      = 0.;
+      const int trilinos_i = matrix->getRowMap()->getLocalElement(i);
+      const int trilinos_j = matrix->getColMap()->getLocalElement(j);
+      Number    value      = 0.;
 
       if (trilinos_i == Teuchos::OrdinalTraits<int>::invalid() ||
           trilinos_j == Teuchos::OrdinalTraits<int>::invalid())

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.