From 78cdc55b4eb09747d45a410ab29024998cd090f1 Mon Sep 17 00:00:00 2001 From: Jan Philipp Thiele Date: Fri, 19 Jul 2024 13:49:45 +0200 Subject: [PATCH] Add set of passing Tpetra tests --- tests/trilinos_tpetra/08.cc | 96 +++++++++++++++ tests/trilinos_tpetra/08.output | 3 + tests/trilinos_tpetra/49.cc | 97 +++++++++++++++ tests/trilinos_tpetra/49.output | 2 + tests/trilinos_tpetra/n_nonzeros_01.cc | 79 ++++++++++++ tests/trilinos_tpetra/n_nonzeros_01.output | 2 + tests/trilinos_tpetra/n_nonzeros_02.cc | 106 ++++++++++++++++ tests/trilinos_tpetra/n_nonzeros_02.output | 2 + tests/trilinos_tpetra/sparse_matrix_02.cc | 62 ++++++++++ tests/trilinos_tpetra/sparse_matrix_02.output | 17 +++ tests/trilinos_tpetra/sparse_matrix_03.cc | 62 ++++++++++ tests/trilinos_tpetra/sparse_matrix_03.output | 17 +++ tests/trilinos_tpetra/sparse_matrix_04.cc | 62 ++++++++++ tests/trilinos_tpetra/sparse_matrix_04.output | 17 +++ .../sparse_matrix_copy_from_02.cc | 113 +++++++++++++++++ ...from_02.with_trilinos=true.mpirun=3.output | 5 + .../sparse_matrix_iterator_01.cc | 90 ++++++++++++++ .../sparse_matrix_iterator_01.output | 5 + .../sparse_matrix_vector_08.cc | 115 ++++++++++++++++++ .../sparse_matrix_vector_08.output | 2 + tests/trilinos_tpetra/vector_assign_01.cc | 100 +++++++++++++++ tests/trilinos_tpetra/vector_assign_01.output | 2 + tests/trilinos_tpetra/vector_assign_02.cc | 99 +++++++++++++++ tests/trilinos_tpetra/vector_assign_02.output | 2 + tests/trilinos_tpetra/vector_equality_1.cc | 95 +++++++++++++++ .../trilinos_tpetra/vector_equality_1.output | 2 + tests/trilinos_tpetra/vector_equality_2.cc | 98 +++++++++++++++ .../trilinos_tpetra/vector_equality_2.output | 2 + tests/trilinos_tpetra/vector_equality_3.cc | 95 +++++++++++++++ .../trilinos_tpetra/vector_equality_3.output | 2 + tests/trilinos_tpetra/vector_equality_4.cc | 97 +++++++++++++++ .../trilinos_tpetra/vector_equality_4.output | 2 + 32 files changed, 1550 insertions(+) create mode 100644 tests/trilinos_tpetra/08.cc create mode 100644 tests/trilinos_tpetra/08.output create mode 100644 tests/trilinos_tpetra/49.cc create mode 100644 tests/trilinos_tpetra/49.output create mode 100644 tests/trilinos_tpetra/n_nonzeros_01.cc create mode 100644 tests/trilinos_tpetra/n_nonzeros_01.output create mode 100644 tests/trilinos_tpetra/n_nonzeros_02.cc create mode 100644 tests/trilinos_tpetra/n_nonzeros_02.output create mode 100644 tests/trilinos_tpetra/sparse_matrix_02.cc create mode 100644 tests/trilinos_tpetra/sparse_matrix_02.output create mode 100644 tests/trilinos_tpetra/sparse_matrix_03.cc create mode 100644 tests/trilinos_tpetra/sparse_matrix_03.output create mode 100644 tests/trilinos_tpetra/sparse_matrix_04.cc create mode 100644 tests/trilinos_tpetra/sparse_matrix_04.output create mode 100644 tests/trilinos_tpetra/sparse_matrix_copy_from_02.cc create mode 100644 tests/trilinos_tpetra/sparse_matrix_copy_from_02.with_trilinos=true.mpirun=3.output create mode 100644 tests/trilinos_tpetra/sparse_matrix_iterator_01.cc create mode 100644 tests/trilinos_tpetra/sparse_matrix_iterator_01.output create mode 100644 tests/trilinos_tpetra/sparse_matrix_vector_08.cc create mode 100644 tests/trilinos_tpetra/sparse_matrix_vector_08.output create mode 100644 tests/trilinos_tpetra/vector_assign_01.cc create mode 100644 tests/trilinos_tpetra/vector_assign_01.output create mode 100644 tests/trilinos_tpetra/vector_assign_02.cc create mode 100644 tests/trilinos_tpetra/vector_assign_02.output create mode 100644 tests/trilinos_tpetra/vector_equality_1.cc create mode 100644 tests/trilinos_tpetra/vector_equality_1.output create mode 100644 tests/trilinos_tpetra/vector_equality_2.cc create mode 100644 tests/trilinos_tpetra/vector_equality_2.output create mode 100644 tests/trilinos_tpetra/vector_equality_3.cc create mode 100644 tests/trilinos_tpetra/vector_equality_3.output create mode 100644 tests/trilinos_tpetra/vector_equality_4.cc create mode 100644 tests/trilinos_tpetra/vector_equality_4.output diff --git a/tests/trilinos_tpetra/08.cc b/tests/trilinos_tpetra/08.cc new file mode 100644 index 0000000000..6b08722953 --- /dev/null +++ b/tests/trilinos_tpetra/08.cc @@ -0,0 +1,96 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +// check LinearAlgebra::TpetraWrappers::SparseMatrix::frobenius_norm + +#include + +#include + +#include + +#include "../tests.h" + + +void +test(LinearAlgebra::TpetraWrappers::SparseMatrix &m) +{ + // first set a few entries. count how many + // entries we have + TrilinosScalar norm = 0; + for (unsigned int i = 0; i < m.m(); ++i) + for (unsigned int j = 0; j < m.m(); ++j) + if ((i + 2 * j + 1) % 3 == 0) + { + m.set(i, j, i * j * .5 + .5); + norm += (i * j * .5 + .5) * (i * j * .5 + .5); + } + norm = std::sqrt(norm); + + m.compress(VectorOperation::insert); + + // compare against the exact value of the + // l2-norm (max row-sum) + deallog << m.frobenius_norm() << std::endl; + Assert(m.frobenius_norm() == norm, ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + + try + { + { + LinearAlgebra::TpetraWrappers::SparseMatrix m(5U, 5U, 3U); + test(m); + } + } + catch (const std::exception &exc) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/08.output b/tests/trilinos_tpetra/08.output new file mode 100644 index 0000000000..d4083f6573 --- /dev/null +++ b/tests/trilinos_tpetra/08.output @@ -0,0 +1,3 @@ + +DEAL::9.04157 +DEAL::OK diff --git a/tests/trilinos_tpetra/49.cc b/tests/trilinos_tpetra/49.cc new file mode 100644 index 0000000000..56e31989b2 --- /dev/null +++ b/tests/trilinos_tpetra/49.cc @@ -0,0 +1,97 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// check LinearAlgebra::TpetraWrappers::Vector::operator = +// (dealii::Vector) + +#include + +#include +#include + +#include +#include + +#include "../tests.h" + + +void +test(LinearAlgebra::TpetraWrappers::Vector &v) +{ + dealii::Vector w(v.size()); + + for (unsigned int i = 0; i < w.size(); ++i) + w(i) = i; + + v = w; + + + // make sure we get the expected result + for (unsigned int i = 0; i < v.size(); ++i) + { + AssertThrow(w(i) == i, ExcInternalError()); + AssertThrow(v(i) == i, ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + + try + { + { + LinearAlgebra::TpetraWrappers::Vector v; + v.reinit(complete_index_set(100), MPI_COMM_WORLD); + test(v); + } + } + catch (const std::exception &exc) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/49.output b/tests/trilinos_tpetra/49.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/trilinos_tpetra/49.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/trilinos_tpetra/n_nonzeros_01.cc b/tests/trilinos_tpetra/n_nonzeros_01.cc new file mode 100644 index 0000000000..cca9edf331 --- /dev/null +++ b/tests/trilinos_tpetra/n_nonzeros_01.cc @@ -0,0 +1,79 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +// check n_nonzero_elements() for an empty matrix + +#include +#include +#include + +#include "../tests.h" + + +void +test() +{ + // create an empty sparsity pattern + LinearAlgebra::TpetraWrappers::SparsityPattern sparsity(4, 5, 1); + sparsity.compress(); + + // attach a sparse matrix to it + LinearAlgebra::TpetraWrappers::SparseMatrix A(sparsity); + + // see how many nonzero elements it reports + deallog << A.n_nonzero_elements() << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + try + { + test(); + } + catch (const std::exception &exc) + { + deallog << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + deallog << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/n_nonzeros_01.output b/tests/trilinos_tpetra/n_nonzeros_01.output new file mode 100644 index 0000000000..199228a5ad --- /dev/null +++ b/tests/trilinos_tpetra/n_nonzeros_01.output @@ -0,0 +1,2 @@ + +DEAL::0 diff --git a/tests/trilinos_tpetra/n_nonzeros_02.cc b/tests/trilinos_tpetra/n_nonzeros_02.cc new file mode 100644 index 0000000000..9089ed4729 --- /dev/null +++ b/tests/trilinos_tpetra/n_nonzeros_02.cc @@ -0,0 +1,106 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// check n_nonzero_elements() for an empty matrix + +#include +#include + +#include + +#include + +#include +#include +#include + +#include "../tests.h" + + +void +test() +{ + Triangulation<2> tria; + GridGenerator::hyper_cube(tria); + + FE_Q<2> fe(1); + DoFHandler<2> dof_handler(tria); + dof_handler.distribute_dofs(fe); + + Table<2, DoFTools::Coupling> coupling(1, 1); + coupling.fill(DoFTools::none); + + // create an empty sparsity pattern + LinearAlgebra::TpetraWrappers::SparsityPattern sparsity; + sparsity.reinit(dof_handler.n_dofs(), dof_handler.n_dofs()); + DoFTools::make_sparsity_pattern(dof_handler, + coupling, + sparsity, + AffineConstraints(), + false, + Utilities::MPI::this_mpi_process( + MPI_COMM_WORLD)); + sparsity.compress(); + + // attach a sparse matrix to it + LinearAlgebra::TpetraWrappers::SparseMatrix A; + A.reinit(sparsity); + + // see how many nonzero elements it reports + deallog << A.n_nonzero_elements() << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + try + { + test(); + } + catch (const std::exception &exc) + { + deallog << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + deallog << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/n_nonzeros_02.output b/tests/trilinos_tpetra/n_nonzeros_02.output new file mode 100644 index 0000000000..199228a5ad --- /dev/null +++ b/tests/trilinos_tpetra/n_nonzeros_02.output @@ -0,0 +1,2 @@ + +DEAL::0 diff --git a/tests/trilinos_tpetra/sparse_matrix_02.cc b/tests/trilinos_tpetra/sparse_matrix_02.cc new file mode 100644 index 0000000000..d01a631773 --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_02.cc @@ -0,0 +1,62 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// test LinearAlgebra::TpetraWrappers::SparseMatrix::reinit with a +// dealii::SparseMatrix and where we copy all values + +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + initlog(); + + SparsityPattern sparsity(5, 5, 5); + sparsity.add(1, 2); + sparsity.add(2, 3); + sparsity.add(3, 4); + sparsity.add(4, 3); + sparsity.compress(); + SparseMatrix matrix(sparsity); + { + double value = 1; + for (SparseMatrix::iterator p = matrix.begin(); p != matrix.end(); + ++p, ++value) + p->value() = value; + } + deallog << "Original:" << std::endl; + matrix.print_formatted(deallog.get_file_stream()); + + // now copy everything into a Trilinos matrix + const auto local_rows = complete_index_set(5); + LinearAlgebra::TpetraWrappers::SparseMatrix tmatrix; + tmatrix.reinit(local_rows, local_rows, matrix, MPI_COMM_SELF); + + deallog << "Copy with all values:" << std::endl; + tmatrix.print(deallog.get_file_stream()); +} diff --git a/tests/trilinos_tpetra/sparse_matrix_02.output b/tests/trilinos_tpetra/sparse_matrix_02.output new file mode 100644 index 0000000000..abdb4e34ea --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_02.output @@ -0,0 +1,17 @@ + +DEAL::Original: +1.000e+00 + 2.000e+00 3.000e+00 + 4.000e+00 5.000e+00 + 6.000e+00 7.000e+00 + 9.000e+00 8.000e+00 +DEAL::Copy with all values: +(0,0) 1.00000 +(1,1) 2.00000 +(1,2) 3.00000 +(2,2) 4.00000 +(2,3) 5.00000 +(3,3) 6.00000 +(3,4) 7.00000 +(4,3) 9.00000 +(4,4) 8.00000 diff --git a/tests/trilinos_tpetra/sparse_matrix_03.cc b/tests/trilinos_tpetra/sparse_matrix_03.cc new file mode 100644 index 0000000000..d7bf2e2292 --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_03.cc @@ -0,0 +1,62 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// test LinearAlgebra::TpetraWrappers::SparseMatrix::reinit with a +// dealii::SparseMatrix with a drop tolerance + +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + initlog(); + + SparsityPattern sparsity(5, 5, 5); + sparsity.add(1, 2); + sparsity.add(2, 3); + sparsity.add(3, 4); + sparsity.add(4, 3); + sparsity.compress(); + SparseMatrix matrix(sparsity); + { + double value = 1; + for (SparseMatrix::iterator p = matrix.begin(); p != matrix.end(); + ++p, ++value) + p->value() = value; + } + deallog << "Original:" << std::endl; + matrix.print_formatted(deallog.get_file_stream()); + + // now copy everything into a Trilinos matrix + const auto local_rows = complete_index_set(5); + LinearAlgebra::TpetraWrappers::SparseMatrix tmatrix; + tmatrix.reinit(local_rows, local_rows, matrix, MPI_COMM_SELF, 4.); + + deallog << "Copy with a drop tolerance of 4:" << std::endl; + tmatrix.print(deallog.get_file_stream()); +} diff --git a/tests/trilinos_tpetra/sparse_matrix_03.output b/tests/trilinos_tpetra/sparse_matrix_03.output new file mode 100644 index 0000000000..2ec3dc60db --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_03.output @@ -0,0 +1,17 @@ + +DEAL::Original: +1.000e+00 + 2.000e+00 3.000e+00 + 4.000e+00 5.000e+00 + 6.000e+00 7.000e+00 + 9.000e+00 8.000e+00 +DEAL::Copy with a drop tolerance of 4: +(0,0) 0.00000 +(1,1) 0.00000 +(1,2) 0.00000 +(2,2) 0.00000 +(2,3) 5.00000 +(3,3) 6.00000 +(3,4) 7.00000 +(4,3) 9.00000 +(4,4) 8.00000 diff --git a/tests/trilinos_tpetra/sparse_matrix_04.cc b/tests/trilinos_tpetra/sparse_matrix_04.cc new file mode 100644 index 0000000000..304762a628 --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_04.cc @@ -0,0 +1,62 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// test LinearAlgebra::TpetraWrappers::SparseMatrix::reinit with a +// dealii::SparseMatrix without copying values + +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + initlog(); + + SparsityPattern sparsity(5, 5, 5); + sparsity.add(1, 2); + sparsity.add(2, 3); + sparsity.add(3, 4); + sparsity.add(4, 3); + sparsity.compress(); + SparseMatrix matrix(sparsity); + { + double value = 1; + for (SparseMatrix::iterator p = matrix.begin(); p != matrix.end(); + ++p, ++value) + p->value() = value; + } + deallog << "Original:" << std::endl; + matrix.print_formatted(deallog.get_file_stream()); + + // now copy everything into a Trilinos matrix + const auto local_rows = complete_index_set(5); + LinearAlgebra::TpetraWrappers::SparseMatrix tmatrix; + tmatrix.reinit(local_rows, local_rows, matrix, MPI_COMM_SELF, 0, false); + + deallog << "Copy structure only:" << std::endl; + tmatrix.print(deallog.get_file_stream()); +} diff --git a/tests/trilinos_tpetra/sparse_matrix_04.output b/tests/trilinos_tpetra/sparse_matrix_04.output new file mode 100644 index 0000000000..add5135bf7 --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_04.output @@ -0,0 +1,17 @@ + +DEAL::Original: +1.000e+00 + 2.000e+00 3.000e+00 + 4.000e+00 5.000e+00 + 6.000e+00 7.000e+00 + 9.000e+00 8.000e+00 +DEAL::Copy structure only: +(0,0) 0.00000 +(1,1) 0.00000 +(1,2) 0.00000 +(2,2) 0.00000 +(2,3) 0.00000 +(3,3) 0.00000 +(3,4) 0.00000 +(4,3) 0.00000 +(4,4) 0.00000 diff --git a/tests/trilinos_tpetra/sparse_matrix_copy_from_02.cc b/tests/trilinos_tpetra/sparse_matrix_copy_from_02.cc new file mode 100644 index 0000000000..d64e1a9658 --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_copy_from_02.cc @@ -0,0 +1,113 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// Test +// LinearAlgebra::TpetraWrappers::SparseMatrix::copy_from(other_matrix) +// for the case of a non-contiguous set of rows. + +#include +#include +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + +void +test() +{ + const unsigned int MyPID = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + const unsigned int NumProc = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD); + + if (MyPID == 0) + deallog << "NumProc=" << NumProc << std::endl; + + // create non-contiguous index set for NumProc > 1 + dealii::IndexSet parallel_partitioning(NumProc * 2); + + // non-contiguous + parallel_partitioning.add_index(MyPID); + parallel_partitioning.add_index(NumProc + MyPID); + + // create sparsity pattern from parallel_partitioning + + // The sparsity pattern corresponds to a [FE_DGQ<1>(p=0)]^2 FESystem, + // on a triangulation in which each MPI process owns 2 cells, + // with reordered dofs by its components, such that the rows in the + // final matrix are locally not in a contiguous set. + + dealii::LinearAlgebra::TpetraWrappers::SparsityPattern sp_M( + parallel_partitioning, MPI_COMM_WORLD, 2); + + sp_M.add(MyPID, MyPID); + sp_M.add(MyPID, NumProc + MyPID); + sp_M.add(NumProc + MyPID, MyPID); + sp_M.add(NumProc + MyPID, NumProc + MyPID); + + sp_M.compress(); + + // create matrix with dummy entries on the diagonal + dealii::LinearAlgebra::TpetraWrappers::SparseMatrix M0; + M0.reinit(sp_M); + M0 = 0; + + for (const auto &i : parallel_partitioning) + M0.set(i, i, dealii::numbers::PI); + + M0.compress(dealii::VectorOperation::insert); + + //////////////////////////////////////////////////////////////////////// + // test ::add(TrilinosScalar, SparseMatrix) + // + + dealii::LinearAlgebra::TpetraWrappers::SparseMatrix M1; + M1.reinit(sp_M); // avoid deep copy + M1 = 0; + M1.copy_from(M0); + + // check + for (const auto &i : parallel_partitioning) + { + const auto &el = M1.el(i, i); + + if (MyPID == 0) + deallog << "i = " << i << " , j = " << i << " , el = " << el + << std::endl; + + AssertThrow(el == dealii::numbers::PI, dealii::ExcInternalError()); + } + + if (MyPID == 0) + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + test(); +} diff --git a/tests/trilinos_tpetra/sparse_matrix_copy_from_02.with_trilinos=true.mpirun=3.output b/tests/trilinos_tpetra/sparse_matrix_copy_from_02.with_trilinos=true.mpirun=3.output new file mode 100644 index 0000000000..dea2eaf38a --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_copy_from_02.with_trilinos=true.mpirun=3.output @@ -0,0 +1,5 @@ + +DEAL::NumProc=3 +DEAL::i = 0 , j = 0 , el = 3.14159 +DEAL::i = 3 , j = 3 , el = 3.14159 +DEAL::OK diff --git a/tests/trilinos_tpetra/sparse_matrix_iterator_01.cc b/tests/trilinos_tpetra/sparse_matrix_iterator_01.cc new file mode 100644 index 0000000000..0657d1c22e --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_iterator_01.cc @@ -0,0 +1,90 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// test LinearAlgebra::TpetraWrappers::MatrixBase::const_iterator + +#include + +#include + +#include + +#include "../tests.h" + + +void +test() +{ + LinearAlgebra::TpetraWrappers::SparseMatrix m(5U, 5U, 5U); + m.set(0, 0, 1); + m.set(1, 1, 2); + m.set(1, 2, 3); + m.compress(VectorOperation::insert); + LinearAlgebra::TpetraWrappers::SparseMatrix::const_iterator i = + m.begin(); + deallog << i->row() << ' ' << i->column() << ' ' << i->value() << std::endl; + ++i; + deallog << i->row() << ' ' << i->column() << ' ' << i->value() << std::endl; + i++; + deallog << i->row() << ' ' << i->column() << ' ' << i->value() << std::endl; + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + + try + { + { + test(); + } + } + catch (const std::exception &exc) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/sparse_matrix_iterator_01.output b/tests/trilinos_tpetra/sparse_matrix_iterator_01.output new file mode 100644 index 0000000000..e6bdc2e87e --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_iterator_01.output @@ -0,0 +1,5 @@ + +DEAL::0 0 1.00000 +DEAL::1 1 2.00000 +DEAL::1 2 3.00000 +DEAL::OK diff --git a/tests/trilinos_tpetra/sparse_matrix_vector_08.cc b/tests/trilinos_tpetra/sparse_matrix_vector_08.cc new file mode 100644 index 0000000000..47e28b6b4b --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_vector_08.cc @@ -0,0 +1,115 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// check SparseMatrix::vmult, vmult_add with deal.II vector + +#include + +#include +#include + +#include +#include + +#include "../tests.h" + + +void +test(Vector &v, Vector &w) +{ + LinearAlgebra::TpetraWrappers::SparseMatrix m(w.size(), + v.size(), + v.size()); + for (unsigned int i = 0; i < m.m(); ++i) + for (unsigned int j = 0; j < m.n(); ++j) + m.set(i, j, i + 2 * j); + + for (unsigned int i = 0; i < v.size(); ++i) + v(i) = i; + + m.compress(VectorOperation::insert); + + // w:=Mv + m.vmult(w, v); + + // make sure we get the expected result + for (unsigned int i = 0; i < m.m(); ++i) + { + double result = 0; + for (unsigned int j = 0; j < m.n(); ++j) + result += (i + 2 * j) * j; + AssertThrow(w(i) == result, ExcInternalError()); + } + + m.vmult_add(w, v); + // make sure we get the expected result + for (unsigned int i = 0; i < m.m(); ++i) + { + double result = 0; + for (unsigned int j = 0; j < m.n(); ++j) + result += (i + 2 * j) * j; + AssertThrow(w(i) == result + result, ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + + try + { + { + Vector v(100); + Vector w(95); + test(v, w); + } + } + catch (const std::exception &exc) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/sparse_matrix_vector_08.output b/tests/trilinos_tpetra/sparse_matrix_vector_08.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/trilinos_tpetra/sparse_matrix_vector_08.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/trilinos_tpetra/vector_assign_01.cc b/tests/trilinos_tpetra/vector_assign_01.cc new file mode 100644 index 0000000000..43fa1cbaf8 --- /dev/null +++ b/tests/trilinos_tpetra/vector_assign_01.cc @@ -0,0 +1,100 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// when calling LinearAlgebra::TpetraWrappers::Vector::operator() (), +// the return type is a reference object, not a reference to the actual element. +// this leads to the funny situation that an assignment like v2(i)=v1(i) isn't +// really what it looks like: it tries to copy the reference objects, not the +// values they point to, as one would expect +// +// this was fixed 2004-04-05, and this test checks that it works + +#include + +#include + +#include +#include + +#include "../tests.h" + + +void +test(LinearAlgebra::TpetraWrappers::Vector &v, + LinearAlgebra::TpetraWrappers::Vector &w) +{ + // set the first vector + for (unsigned int i = 0; i < v.size(); ++i) + v(i) = i; + + // copy elements by reference + for (unsigned int i = 0; i < v.size(); ++i) + w(i) = v(i); + + // check that they're equal + AssertThrow(v == w, ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + + try + { + { + LinearAlgebra::TpetraWrappers::Vector v; + v.reinit(complete_index_set(100), MPI_COMM_WORLD); + LinearAlgebra::TpetraWrappers::Vector w; + w.reinit(complete_index_set(100), MPI_COMM_WORLD); + test(v, w); + } + } + catch (const std::exception &exc) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/vector_assign_01.output b/tests/trilinos_tpetra/vector_assign_01.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/trilinos_tpetra/vector_assign_01.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/trilinos_tpetra/vector_assign_02.cc b/tests/trilinos_tpetra/vector_assign_02.cc new file mode 100644 index 0000000000..9a25a63ccf --- /dev/null +++ b/tests/trilinos_tpetra/vector_assign_02.cc @@ -0,0 +1,99 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// this is equivalent to the trilinos_vector_assign_02 test, except that we use +// operator+= instead of operator=. Now, this does not present a problem, +// since the compiler does not automatically generate a version of this +// operator, but simply performs the conversion to TrilinosScalar, i.e. the +// argument to the user-defined operator+=. This is not exciting, but since I +// wrote the test to make sure it works this way, let's keep it then... + +#include + +#include + +#include +#include + +#include "../tests.h" + + +void +test(LinearAlgebra::TpetraWrappers::Vector &v, + LinearAlgebra::TpetraWrappers::Vector &w) +{ + // set the first vector + for (unsigned int i = 0; i < v.size(); ++i) + v(i) = i; + + // add elements by reference + for (unsigned int i = 0; i < v.size(); ++i) + w(i) += v(i); + + // check that they're equal + AssertThrow(v == w, ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + + try + { + { + LinearAlgebra::TpetraWrappers::Vector v; + v.reinit(complete_index_set(100), MPI_COMM_WORLD); + LinearAlgebra::TpetraWrappers::Vector w; + w.reinit(complete_index_set(100), MPI_COMM_WORLD); + test(v, w); + } + } + catch (const std::exception &exc) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/vector_assign_02.output b/tests/trilinos_tpetra/vector_assign_02.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/trilinos_tpetra/vector_assign_02.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/trilinos_tpetra/vector_equality_1.cc b/tests/trilinos_tpetra/vector_equality_1.cc new file mode 100644 index 0000000000..5b74a951b2 --- /dev/null +++ b/tests/trilinos_tpetra/vector_equality_1.cc @@ -0,0 +1,95 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +// check +// LinearAlgebra::TpetraWrappers::Vector::operator==(LinearAlgebra::TpetraWrappers::Vector) +// for vectors that are not equal + +#include + +#include + +#include +#include + +#include "../tests.h" + + +void +test(LinearAlgebra::TpetraWrappers::Vector &v, + LinearAlgebra::TpetraWrappers::Vector &w) +{ + // set only certain elements of each + // vector + for (unsigned int i = 0; i < v.size(); ++i) + { + v(i) = i; + if (i % 3 == 0) + w(i) = i + 1.; + } + + AssertThrow(!(v == w), ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + + try + { + { + LinearAlgebra::TpetraWrappers::Vector v; + v.reinit(complete_index_set(100), MPI_COMM_WORLD); + LinearAlgebra::TpetraWrappers::Vector w; + w.reinit(complete_index_set(100), MPI_COMM_WORLD); + test(v, w); + } + } + catch (const std::exception &exc) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/vector_equality_1.output b/tests/trilinos_tpetra/vector_equality_1.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/trilinos_tpetra/vector_equality_1.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/trilinos_tpetra/vector_equality_2.cc b/tests/trilinos_tpetra/vector_equality_2.cc new file mode 100644 index 0000000000..a7b43e2f9d --- /dev/null +++ b/tests/trilinos_tpetra/vector_equality_2.cc @@ -0,0 +1,98 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// check +// LinearAlgebra::TpetraWrappers::Vector::operator==(LinearAlgebra::TpetraWrappers::Vector) +// for vectors that are equal + +#include + +#include + +#include +#include + +#include "../tests.h" + + +void +test(LinearAlgebra::TpetraWrappers::Vector &v, + LinearAlgebra::TpetraWrappers::Vector &w) +{ + // set only certain elements of each + // vector + for (unsigned int i = 0; i < v.size(); ++i) + { + v(i) = i; + if (i % 3 == 0) + w(i) = i + 1.; + } + // but then copy elements and make sure the + // vectors are actually equal + v = w; + AssertThrow(v == w, ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + + try + { + { + LinearAlgebra::TpetraWrappers::Vector v; + v.reinit(complete_index_set(100), MPI_COMM_WORLD); + LinearAlgebra::TpetraWrappers::Vector w; + w.reinit(complete_index_set(100), MPI_COMM_WORLD); + test(v, w); + } + } + catch (const std::exception &exc) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/vector_equality_2.output b/tests/trilinos_tpetra/vector_equality_2.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/trilinos_tpetra/vector_equality_2.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/trilinos_tpetra/vector_equality_3.cc b/tests/trilinos_tpetra/vector_equality_3.cc new file mode 100644 index 0000000000..0e189172f7 --- /dev/null +++ b/tests/trilinos_tpetra/vector_equality_3.cc @@ -0,0 +1,95 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +// check +// LinearAlgebra::TpetraWrappers::Vector::operator!=(LinearAlgebra::TpetraWrappers::Vector) +// for vectors that are not equal + +#include + +#include + +#include +#include + +#include "../tests.h" + + +void +test(LinearAlgebra::TpetraWrappers::Vector &v, + LinearAlgebra::TpetraWrappers::Vector &w) +{ + // set only certain elements of each + // vector + for (unsigned int i = 0; i < v.size(); ++i) + { + v(i) = i; + if (i % 3 == 0) + w(i) = i + 1.; + } + + AssertThrow(v != w, ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + + try + { + { + LinearAlgebra::TpetraWrappers::Vector v; + v.reinit(complete_index_set(100), MPI_COMM_WORLD); + LinearAlgebra::TpetraWrappers::Vector w; + w.reinit(complete_index_set(100), MPI_COMM_WORLD); + test(v, w); + } + } + catch (const std::exception &exc) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/vector_equality_3.output b/tests/trilinos_tpetra/vector_equality_3.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/trilinos_tpetra/vector_equality_3.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/trilinos_tpetra/vector_equality_4.cc b/tests/trilinos_tpetra/vector_equality_4.cc new file mode 100644 index 0000000000..e86fc16318 --- /dev/null +++ b/tests/trilinos_tpetra/vector_equality_4.cc @@ -0,0 +1,97 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +// check +// LinearAlgebra::TpetraWrappers::Vector::operator!=(LinearAlgebra::TpetraWrappers::Vector) +// for vectors that are equal + +#include + +#include + +#include +#include + +#include "../tests.h" + + +void +test(LinearAlgebra::TpetraWrappers::Vector &v, + LinearAlgebra::TpetraWrappers::Vector &w) +{ + // set only certain elements of each + // vector + for (unsigned int i = 0; i < v.size(); ++i) + { + v(i) = i; + if (i % 3 == 0) + w(i) = i + 1.; + } + // but then copy elements and make sure the + // vectors are actually equal + v = w; + AssertThrow(!(v != w), ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + + try + { + { + LinearAlgebra::TpetraWrappers::Vector v; + v.reinit(complete_index_set(100), MPI_COMM_WORLD); + LinearAlgebra::TpetraWrappers::Vector w; + w.reinit(complete_index_set(100), MPI_COMM_WORLD); + test(v, w); + } + } + catch (const std::exception &exc) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/trilinos_tpetra/vector_equality_4.output b/tests/trilinos_tpetra/vector_equality_4.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/trilinos_tpetra/vector_equality_4.output @@ -0,0 +1,2 @@ + +DEAL::OK -- 2.39.5