Skip to content

Commit

Permalink
Add remaining Tpetra tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bangerth committed Apr 17, 2024
1 parent d521cc2 commit 3d89ae2
Show file tree
Hide file tree
Showing 281 changed files with 23,864 additions and 0 deletions.
117 changes: 117 additions & 0 deletions tests/trilinos_tpetra/03b.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2004 - 2018 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------



// check setting elements in a petsc matrix using set() and add()
// intermixed. this poses PETSc some problems, since one has to flush some
// buffer in between these two types of operations
//
// in contrast to trilinos_03a, we set and add the same elements here twice,
// then overwrite them again to get the original value back

#include <deal.II/base/utilities.h>

#include <deal.II/lac/trilinos_tpetra_sparse_matrix.h>

#include <iostream>

#include "../tests.h"


void
test(LinearAlgebra::TpetraWrappers::SparseMatrix<double> &m)
{
// first set a few entries
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);
// then add the same elements again
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.add(i, j, i * j * .5 + .5);

m.compress(VectorOperation::add);

// and overwrite everything again
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);

m.compress(VectorOperation::insert);

// then make sure we retrieve the same ones
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)
{
AssertThrow(m(i, j) == i * j * .5 + .5, ExcInternalError());
AssertThrow(m.el(i, j) == i * j * .5 + .5, ExcInternalError());
}
else
{
AssertThrow(m.el(i, j) == 0, 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<double> 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;
};
}
2 changes: 2 additions & 0 deletions tests/trilinos_tpetra/03b.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

DEAL::OK
93 changes: 93 additions & 0 deletions tests/trilinos_tpetra/06.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2004 - 2018 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------



// check LinearAlgebra::TpetraWrappers::SparseMatrix<double>::l1_norm

#include <deal.II/base/utilities.h>

#include <deal.II/lac/trilinos_tpetra_sparse_matrix.h>

#include <iostream>

#include "../tests.h"


void
test(LinearAlgebra::TpetraWrappers::SparseMatrix<double> &m)
{
// first set a few entries. count how many
// entries we have
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);

m.compress(VectorOperation::insert);

// compare against the exact value of the
// l1-norm (max col-sum)
deallog << m.l1_norm() << std::endl;
Assert(m.l1_norm() == 7, 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<double> 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;
};
}
3 changes: 3 additions & 0 deletions tests/trilinos_tpetra/06.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

DEAL::7.00000
DEAL::OK
93 changes: 93 additions & 0 deletions tests/trilinos_tpetra/07.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2004 - 2018 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------



// check LinearAlgebra::TpetraWrappers::SparseMatrix<double>::linfty_norm

#include <deal.II/base/utilities.h>

#include <deal.II/lac/trilinos_tpetra_sparse_matrix.h>

#include <iostream>

#include "../tests.h"


void
test(LinearAlgebra::TpetraWrappers::SparseMatrix<double> &m)
{
// first set a few entries. count how many
// entries we have
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);

m.compress(VectorOperation::insert);

// compare against the exact value of the
// linfty-norm (max row-sum)
deallog << m.linfty_norm() << std::endl;
Assert(m.linfty_norm() == 8.5, 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<double> 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;
};
}
3 changes: 3 additions & 0 deletions tests/trilinos_tpetra/07.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

DEAL::8.50000
DEAL::OK

0 comments on commit 3d89ae2

Please sign in to comment.