From 9124732b084370244fbf459f9d785f87cdba026b Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Sun, 12 Jun 2022 21:02:42 +0200 Subject: [PATCH] Fix two tests with complex PETSc --- tests/petsc_complex/assemble_01.cc | 18 +++++++++++++++--- tests/petsc_complex/sparse_matrix_01.cc | 6 +++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/petsc_complex/assemble_01.cc b/tests/petsc_complex/assemble_01.cc index d675fee099..e31b5a3c49 100644 --- a/tests/petsc_complex/assemble_01.cc +++ b/tests/petsc_complex/assemble_01.cc @@ -19,6 +19,7 @@ // combinations of PETScWrappers objects is correctly instantiated and works. #include +#include #include #include #include @@ -37,9 +38,20 @@ main(int argc, char **argv) const unsigned int n = 4; - PETScWrappers::SparseMatrix serial_matrix(n, n, n); - PETScWrappers::MPI::SparseMatrix mpi_matrix(MPI_COMM_WORLD, n, n, n, n, n); - PETScWrappers::MPI::Vector mpi_vector(MPI_COMM_WORLD, n, n); + PETScWrappers::SparseMatrix serial_matrix(n, n, n); + + // PETSc requires us to set up the sparsity pattern ahead of construction + DynamicSparsityPattern dsp(n, n); + for (unsigned int i = 0; i < n; ++i) + for (unsigned int j = 0; j < n; ++j) + dsp.add(i, j); + IndexSet all_dofs(n); + all_dofs.add_range(0, n); + + PETScWrappers::MPI::SparseMatrix mpi_matrix; + mpi_matrix.reinit(all_dofs, all_dofs, dsp, MPI_COMM_WORLD); + + PETScWrappers::MPI::Vector mpi_vector(MPI_COMM_WORLD, n, n); FullMatrix cell_matrix(n, n); Vector cell_rhs(n); diff --git a/tests/petsc_complex/sparse_matrix_01.cc b/tests/petsc_complex/sparse_matrix_01.cc index 09b9a7acc5..69a1e32e7e 100644 --- a/tests/petsc_complex/sparse_matrix_01.cc +++ b/tests/petsc_complex/sparse_matrix_01.cc @@ -14,7 +14,7 @@ // --------------------------------------------------------------------- -// check SparseMatrix::add(other, factor) +// check SparseMatrix::add(factor, other) #include @@ -50,14 +50,14 @@ test() deallog << m(k, k) << ' '; deallog << std::endl; - m.add(m2, 1.0); + m.add(1.0, m2); deallog << "after: " << m(0, 1) << std::endl; for (unsigned int k = 0; k < s; ++k) deallog << m(k, k) << ' '; deallog << std::endl; - m.add(m2, -1.0); + m.add(-1.0, m2); deallog << "back to original: " << m(0, 1) << std::endl; for (unsigned int k = 0; k < s; ++k) -- 2.39.5