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

Add Tpetra tests that are already working. #16647

Merged
merged 1 commit into from
Feb 16, 2024
Merged
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
105 changes: 105 additions & 0 deletions tests/trilinos_tpetra/10.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// ---------------------------------------------------------------------
//
// 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>::operator /=

#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);

m.compress(VectorOperation::insert);

// then divide everything by 4/3 and
// make sure we retrieve the values we
// expect
m /= 4. / 3.;

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) / 4 * 3, ExcInternalError());
AssertThrow(m.el(i, j) == (i * j * .5 + .5) / 4 * 3,
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/10.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

DEAL::OK
88 changes: 88 additions & 0 deletions tests/trilinos_tpetra/11.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// ---------------------------------------------------------------------
//
// 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::Vector<double>::size()

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

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

#include <iostream>

#include "../tests.h"


void
test(LinearAlgebra::TpetraWrappers::Vector<double> &v)
{
// set only certain elements of the vector
for (unsigned int i = 0; i < v.size(); i += 1 + i)
v(i) = i;

v.compress(VectorOperation::insert);

AssertThrow(v.size() == 100, 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<double> 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;
};
}
2 changes: 2 additions & 0 deletions tests/trilinos_tpetra/11.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

DEAL::OK
100 changes: 100 additions & 0 deletions tests/trilinos_tpetra/12.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// ---------------------------------------------------------------------
//
// 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::Vector<double>::operator() in set-mode

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

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

#include <iostream>
#include <vector>

#include "../tests.h"


void
test(LinearAlgebra::TpetraWrappers::Vector<double> &v)
{
// set only certain elements of the
// vector. have a bit pattern of where we
// actually wrote elements to
std::vector<bool> pattern(v.size(), false);
for (unsigned int i = 0; i < v.size(); i += 1 + i)
{
v(i) = i;
pattern[i] = true;
}

v.compress(VectorOperation::insert);

// check that they are ok, and this time
// all of them
for (unsigned int i = 0; i < v.size(); ++i)
AssertThrow((((pattern[i] == true) && (v(i) == i)) ||
((pattern[i] == false) && (v(i) == 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::Vector<double> 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;
};
}
2 changes: 2 additions & 0 deletions tests/trilinos_tpetra/12.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

DEAL::OK