From: Daniel Arndt Date: Wed, 14 Feb 2024 21:31:28 +0000 (-0500) Subject: Tpetra: Add frobenius_norm to SparseMatrix X-Git-Tag: relicensing~36^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16648%2Fhead;p=dealii.git Tpetra: Add frobenius_norm to SparseMatrix --- diff --git a/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h b/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h index 5fbf291cfd..48de7bd615 100644 --- a/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h +++ b/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h @@ -706,6 +706,20 @@ namespace LinearAlgebra const Vector &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 */ diff --git a/include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h b/include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h index 6dd1acaa63..de1d09db50 100644 --- a/include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h +++ b/include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h @@ -588,6 +588,16 @@ namespace LinearAlgebra + template + Number + SparseMatrix::frobenius_norm() const + { + Assert(matrix->isFillComplete(), ExcMatrixNotCompressed()); + return matrix->getFrobeniusNorm(); + } + + + template void SparseMatrix::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::invalid() || trilinos_j == Teuchos::OrdinalTraits::invalid())