From abf2c3ef87b5b48f32a07f160e389598e4540169 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 14 Feb 2024 16:31:28 -0500 Subject: [PATCH] Tpetra: Add frobenius_norm to SparseMatrix --- .../deal.II/lac/trilinos_tpetra_sparse_matrix.h | 14 ++++++++++++++ .../trilinos_tpetra_sparse_matrix.templates.h | 16 +++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) 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()) -- 2.39.5