From cc554f8809585851194591c234b270bb5af63bfc Mon Sep 17 00:00:00 2001 From: David Wells Date: Sat, 22 May 2021 15:36:45 -0400 Subject: [PATCH] Avoid deprecated features in PETSc tests. --- tests/petsc/64.cc | 19 +++++++++++--- tests/petsc/slowness_03.cc | 46 ++++++++++++++++++++++++++++++--- tests/petsc/slowness_04.cc | 46 ++++++++++++++++++++++++++++++--- tests/petsc/sparse_matrix_01.cc | 6 ++--- 4 files changed, 104 insertions(+), 13 deletions(-) diff --git a/tests/petsc/64.cc b/tests/petsc/64.cc index 9cf1a0db5c..27ee8f4cac 100644 --- a/tests/petsc/64.cc +++ b/tests/petsc/64.cc @@ -28,6 +28,8 @@ #include "../tests.h" +#include "../testmatrix.h" + template void @@ -53,7 +55,8 @@ main(int argc, char **argv) { Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); { - const unsigned int n_dofs = 420; + const unsigned int N = 20; + const unsigned int n_dofs = N * N; // check // PETScWrappers::SparseMatrix PETScWrappers::SparseMatrix v1(n_dofs, n_dofs, 5); @@ -67,8 +70,18 @@ main(int argc, char **argv) const unsigned int n_mpi_processes = static_cast(n_jobs); Assert(n_dofs % n_mpi_processes == 0, ExcInternalError()); const unsigned int n_local_dofs = n_dofs / n_mpi_processes; - PETScWrappers::MPI::SparseMatrix v2( - mpi_communicator, n_dofs, n_dofs, n_local_dofs, n_local_dofs, 5); + PETScWrappers::MPI::SparseMatrix v2; + { + FDMatrix fd_matrix(N, N); + DynamicSparsityPattern dsp(n_dofs, n_dofs); + fd_matrix.five_point_structure(dsp); + dsp.add(0, 0); // be sure that we have this one + SparsityPattern sparsity_pattern; + sparsity_pattern.copy_from(dsp); + IndexSet all_dofs(n_dofs); + all_dofs.add_range(0, n_dofs); + v2.reinit(all_dofs, all_dofs, sparsity_pattern, PETSC_COMM_WORLD); + } test(v2); } } diff --git a/tests/petsc/slowness_03.cc b/tests/petsc/slowness_03.cc index b44aa82ea0..1b079257ff 100644 --- a/tests/petsc/slowness_03.cc +++ b/tests/petsc/slowness_03.cc @@ -22,9 +22,11 @@ // // the tests build the 5-point stencil matrix for a uniform grid of size N*N +#include #include #include #include +#include #include @@ -34,11 +36,47 @@ void test() { - const unsigned int N = 200; + const unsigned int N = 200; + const unsigned int n_dofs = N * N; - // build the sparse matrix - PETScWrappers::MPI::SparseMatrix matrix( - PETSC_COMM_WORLD, N * N, N * N, N * N, N * N, 5); + DynamicSparsityPattern dsp(n_dofs, n_dofs); + // An older version of this test relied on PETSc doing dynamic allocation, but + // we require sparsity patterns in constructors now so we need the sparsity + // pattern ahead of time - hence this is done twice + for (unsigned int i = 0; i < N; i++) + for (unsigned int j = 0; j < N; j++) + { + const unsigned int global = i * N + j; + dsp.add(global, global); + if (j > 0) + { + dsp.add(global - 1, global); + dsp.add(global, global - 1); + } + if (j < N - 1) + { + dsp.add(global + 1, global); + dsp.add(global, global + 1); + } + if (i > 0) + { + dsp.add(global - N, global); + dsp.add(global, global - N); + } + if (i < N - 1) + { + dsp.add(global + N, global); + dsp.add(global, global + N); + } + } + + SparsityPattern sparsity_pattern; + sparsity_pattern.copy_from(dsp); + IndexSet all_dofs(n_dofs); + all_dofs.add_range(0, n_dofs); + + PETScWrappers::MPI::SparseMatrix matrix; + matrix.reinit(all_dofs, all_dofs, sparsity_pattern, PETSC_COMM_WORLD); for (unsigned int i = 0; i < N; i++) for (unsigned int j = 0; j < N; j++) { diff --git a/tests/petsc/slowness_04.cc b/tests/petsc/slowness_04.cc index 51d212f006..221b9c3c2e 100644 --- a/tests/petsc/slowness_04.cc +++ b/tests/petsc/slowness_04.cc @@ -28,9 +28,11 @@ // matrix in a consecutive fashion, but rather according to the order of // degrees of freedom in the sequence of cells that we traverse +#include #include #include #include +#include #include @@ -40,7 +42,47 @@ void test() { - const unsigned int N = 200; + const unsigned int N = 200; + const unsigned int n_dofs = N * N; + + DynamicSparsityPattern dsp(n_dofs, n_dofs); + // An older version of this test relied on PETSc doing dynamic allocation, but + // we require sparsity patterns in constructors now so we need the sparsity + // pattern ahead of time - hence this is done twice + for (unsigned int i = 0; i < N; i++) + for (unsigned int j = 0; j < N; j++) + { + const unsigned int global = i * N + j; + dsp.add(global, global); + if (j > 0) + { + dsp.add(global - 1, global); + dsp.add(global, global - 1); + } + if (j < N - 1) + { + dsp.add(global + 1, global); + dsp.add(global, global + 1); + } + if (i > 0) + { + dsp.add(global - N, global); + dsp.add(global, global - N); + } + if (i < N - 1) + { + dsp.add(global + N, global); + dsp.add(global, global + N); + } + } + + SparsityPattern sparsity_pattern; + sparsity_pattern.copy_from(dsp); + IndexSet all_dofs(n_dofs); + all_dofs.add_range(0, n_dofs); + + PETScWrappers::MPI::SparseMatrix matrix; + matrix.reinit(all_dofs, all_dofs, sparsity_pattern, PETSC_COMM_WORLD); // first find a random permutation of the // indices @@ -65,8 +107,6 @@ test() } // build the sparse matrix - PETScWrappers::MPI::SparseMatrix matrix( - PETSC_COMM_WORLD, N * N, N * N, N * N, N * N, 5); for (unsigned int i_ = 0; i_ < N; i_++) for (unsigned int j_ = 0; j_ < N; j_++) { diff --git a/tests/petsc/sparse_matrix_01.cc b/tests/petsc/sparse_matrix_01.cc index 87b4225818..32fa0ae71e 100644 --- a/tests/petsc/sparse_matrix_01.cc +++ b/tests/petsc/sparse_matrix_01.cc @@ -15,7 +15,7 @@ -// check SparseMatrix::add(other, factor) +// check SparseMatrix::add(factor, other) #include @@ -51,14 +51,14 @@ test() deallog << m(i, i) << " "; deallog << std::endl; - m.add(m2, 1.0); + m.add(1.0, m2); deallog << "after: " << m(0, 1) << std::endl; for (unsigned int i = 0; i < s; ++i) deallog << m(i, i) << " "; 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 i = 0; i < s; ++i) -- 2.39.5