From 9fa154a9c1ca6cce282ba3e3ec41f2e826be4395 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 2 Feb 2024 16:58:02 -0500 Subject: [PATCH] Enable a couple unit tests for LinearAlgebra::TpetraWrappers::Vector --- .../lac/trilinos_tpetra_sparse_matrix.h | 40 +++++++++++++++++ include/deal.II/lac/trilinos_tpetra_vector.h | 45 +++++++++++++++++++ tests/lac/linear_operator_04.cc | 32 +++++++++---- tests/lac/vector_reinit_02.cc | 6 +++ 4 files changed, 114 insertions(+), 9 deletions(-) diff --git a/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h b/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h index 858115ca85..7e1eab0da5 100644 --- a/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h +++ b/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h @@ -598,6 +598,28 @@ namespace LinearAlgebra trilinos_rcp(); /** @} */ + /** + * @name Partitioners + */ + /** @{ */ + + /** + * Return the partitioning of the domain space of this matrix, i.e., the + * partitioning of the vectors this matrix has to be multiplied with. + */ + IndexSet + locally_owned_domain_indices() const; + + /** + * Return the partitioning of the range space of this matrix, i.e., the + * partitioning of the vectors that are result from matrix-vector + * products. + */ + IndexSet + locally_owned_range_indices() const; + + /** @} */ + /** * @addtogroup Exceptions */ @@ -760,6 +782,24 @@ namespace LinearAlgebra return matrix; } + + + template + inline IndexSet + SparseMatrix::locally_owned_domain_indices() const + { + return IndexSet(matrix->getDomainMap()); + } + + + + template + inline IndexSet + SparseMatrix::locally_owned_range_indices() const + { + return IndexSet(matrix->getRangeMap()); + } + } // namespace TpetraWrappers } // namespace LinearAlgebra diff --git a/include/deal.II/lac/trilinos_tpetra_vector.h b/include/deal.II/lac/trilinos_tpetra_vector.h index 1411617a8f..63f871badf 100644 --- a/include/deal.II/lac/trilinos_tpetra_vector.h +++ b/include/deal.II/lac/trilinos_tpetra_vector.h @@ -1200,6 +1200,51 @@ namespace LinearAlgebra } // namespace LinearAlgebra + +namespace internal +{ + namespace LinearOperatorImplementation + { + template + class ReinitHelper; + + /** + * A helper class used internally in linear_operator.h. Specialization for + * LinearAlgebra::TpetraWrappers::Vector. + */ + template + class ReinitHelper< + LinearAlgebra::TpetraWrappers::Vector> + { + public: + template + static void + reinit_range_vector( + const Matrix &matrix, + LinearAlgebra::TpetraWrappers::Vector &v, + bool omit_zeroing_entries) + { + v.reinit(matrix.locally_owned_range_indices(), + matrix.get_mpi_communicator(), + omit_zeroing_entries); + } + + template + static void + reinit_domain_vector( + const Matrix &matrix, + LinearAlgebra::TpetraWrappers::Vector &v, + bool omit_zeroing_entries) + { + v.reinit(matrix.locally_owned_domain_indices(), + matrix.get_mpi_communicator(), + omit_zeroing_entries); + } + }; + + } // namespace LinearOperatorImplementation +} /* namespace internal */ + /** * Declare dealii::LinearAlgebra::TpetraWrappers::Vector as distributed vector. */ diff --git a/tests/lac/linear_operator_04.cc b/tests/lac/linear_operator_04.cc index 598e4025fd..31e235a5a8 100644 --- a/tests/lac/linear_operator_04.cc +++ b/tests/lac/linear_operator_04.cc @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include "../tests.h" @@ -33,15 +35,27 @@ main(int argc, char *argv[]) initlog(); deallog << std::setprecision(10); - TrilinosWrappers::SparseMatrix a; - - auto op_a = linear_operator(a); - auto op_a2 = linear_operator(a); - - TrilinosWrappers::BlockSparseMatrix b; - - auto op_b = linear_operator(b); - auto op_b3 = linear_operator(b); + { + TrilinosWrappers::SparseMatrix a; + auto op_a = linear_operator(a); + auto op_a2 = linear_operator(a); + } + +#ifdef DEAL_II_TRILINOS_WITH_TPETRA + { + LinearAlgebra::TpetraWrappers::SparseMatrix a; + auto op_a = + linear_operator>(a); + auto op_a2 = + linear_operator>(a); + } +#endif + + { + TrilinosWrappers::BlockSparseMatrix b; + auto op_b = linear_operator(b); + auto op_b3 = linear_operator(b); + } deallog << "OK" << std::endl; diff --git a/tests/lac/vector_reinit_02.cc b/tests/lac/vector_reinit_02.cc index 3a2df37243..657e39c3ab 100644 --- a/tests/lac/vector_reinit_02.cc +++ b/tests/lac/vector_reinit_02.cc @@ -21,6 +21,7 @@ #include +#include #include #include @@ -113,4 +114,9 @@ main(int argc, char **argv) do_test(); do_test(); + +#ifdef DEAL_II_TRILINOS_WITH_TPETRA + do_test>(); + do_test>(); +#endif } -- 2.39.5