Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add Tpetra tests. #16611

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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