From fea210d47d611abadc15e51c99391f5389747828 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 19 Feb 2024 16:15:59 -0700 Subject: [PATCH] Add some missing assertions. --- .../deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h | 3 +++ source/lac/petsc_matrix_base.cc | 5 +++++ source/lac/trilinos_sparse_matrix.cc | 3 +++ 3 files changed, 11 insertions(+) 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 9c20d52713..e9701d5a23 100644 --- a/include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h +++ b/include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h @@ -806,6 +806,7 @@ namespace LinearAlgebra SparseMatrix::matrix_norm_square( const Vector &v) const { + AssertDimension(m(), v.size()); Assert(matrix->isFillComplete(), ExcMatrixNotCompressed()); Assert(matrix->getRowMap()->isSameAs(*matrix->getDomainMap()), ExcNotQuadratic()); @@ -825,6 +826,8 @@ namespace LinearAlgebra const Vector &u, const Vector &v) const { + AssertDimension(m(), u.size()); + AssertDimension(m(), v.size()); Assert(matrix->isFillComplete(), ExcMatrixNotCompressed()); Assert(matrix->getRowMap()->isSameAs(*matrix->getDomainMap()), ExcNotQuadratic()); diff --git a/source/lac/petsc_matrix_base.cc b/source/lac/petsc_matrix_base.cc index 2475988e23..c1a8b98a61 100644 --- a/source/lac/petsc_matrix_base.cc +++ b/source/lac/petsc_matrix_base.cc @@ -457,6 +457,8 @@ namespace PETScWrappers PetscScalar MatrixBase::matrix_norm_square(const VectorBase &v) const { + AssertDimension(m(), v.size()); + VectorBase tmp(v); vmult(tmp, v); return tmp * v; @@ -467,6 +469,9 @@ namespace PETScWrappers MatrixBase::matrix_scalar_product(const VectorBase &u, const VectorBase &v) const { + AssertDimension(m(), u.size()); + AssertDimension(m(), v.size()); + VectorBase tmp(u); vmult(tmp, v); return u * tmp; diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index ef9cedaa83..06aeb03030 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -2101,6 +2101,7 @@ namespace TrilinosWrappers TrilinosScalar SparseMatrix::matrix_norm_square(const MPI::Vector &v) const { + AssertDimension(m(), v.size()); Assert(matrix->RowMap().SameAs(matrix->DomainMap()), ExcNotQuadratic()); MPI::Vector temp_vector; @@ -2116,6 +2117,8 @@ namespace TrilinosWrappers SparseMatrix::matrix_scalar_product(const MPI::Vector &u, const MPI::Vector &v) const { + AssertDimension(m(), u.size()); + AssertDimension(m(), v.size()); Assert(matrix->RowMap().SameAs(matrix->DomainMap()), ExcNotQuadratic()); MPI::Vector temp_vector; -- 2.39.5