Skip to content

Commit

Permalink
Add tests for deal solvers with TpetraWrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
jpthiele committed Feb 10, 2024
1 parent 6c536cf commit 4bed5f3
Show file tree
Hide file tree
Showing 12 changed files with 554 additions and 0 deletions.
87 changes: 87 additions & 0 deletions tests/trilinos_tpetra/deal_solver_01.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2004 - 2024 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.
//
// ---------------------------------------------------------------------


// test the CG solver using the Trilinos matrix and vector classes


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

#include <deal.II/lac/precondition.h>
#include <deal.II/lac/solver_bicgstab.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/solver_control.h>
#include <deal.II/lac/solver_gmres.h>
#include <deal.II/lac/solver_qmrs.h>
#include <deal.II/lac/solver_richardson.h>
#include <deal.II/lac/trilinos_tpetra_sparse_matrix.h>
#include <deal.II/lac/vector_memory.h>

#include <iostream>
#include <typeinfo>

#include "../tests.h"

#include "../testmatrix.h"


int
main(int argc, char **argv)
{
initlog();
deallog << std::setprecision(4);

Utilities::MPI::MPI_InitFinalize mpi_initialization(
argc, argv, testing_max_num_threads());


{
SolverControl control(200, 1.e-3);

const unsigned int size = 32;
unsigned int dim = (size - 1) * (size - 1);

deallog << "Size " << size << " Unknowns " << dim << std::endl;

// Make matrix
FDMatrix testproblem(size, size);
DynamicSparsityPattern csp(dim, dim);
testproblem.five_point_structure(csp);
LinearAlgebra::TpetraWrappers::SparseMatrix<double> A;
A.reinit(csp);
testproblem.five_point(A);

LinearAlgebra::TpetraWrappers::Vector<double> f;
f.reinit(complete_index_set(dim), MPI_COMM_WORLD);
LinearAlgebra::TpetraWrappers::Vector<double> u;
u.reinit(complete_index_set(dim), MPI_COMM_WORLD);
f.trilinos_rcp()->putScalar(1.0);
A.compress(VectorOperation::insert);
f.compress(VectorOperation::insert);
u.compress(VectorOperation::insert);

GrowingVectorMemory<LinearAlgebra::TpetraWrappers::Vector<double>> mem;
SolverCG<LinearAlgebra::TpetraWrappers::Vector<double>> solver(control,
mem);
PreconditionIdentity preconditioner;

deallog << "Solver type: " << typeid(solver).name() << std::endl;

check_solver_within_range(solver.solve(A, u, f, preconditioner),
control.last_step(),
42,
44);
}
}
4 changes: 4 additions & 0 deletions tests/trilinos_tpetra/deal_solver_01.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

DEAL::Size 32 Unknowns 961
DEAL::Solver type: N6dealii8SolverCGINS_13LinearAlgebra14TpetraWrappers6VectorIdNS_11MemorySpace4HostEEEEE
DEAL::Solver stopped within 42 - 44 iterations
88 changes: 88 additions & 0 deletions tests/trilinos_tpetra/deal_solver_02.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2004 - 2024 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.
//
// ---------------------------------------------------------------------


// test the BiCGStab solver using the Trilinos matrix and vector classes



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

#include <deal.II/lac/precondition.h>
#include <deal.II/lac/solver_bicgstab.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/solver_control.h>
#include <deal.II/lac/solver_gmres.h>
#include <deal.II/lac/solver_qmrs.h>
#include <deal.II/lac/solver_richardson.h>
#include <deal.II/lac/trilinos_tpetra_sparse_matrix.h>
#include <deal.II/lac/vector_memory.h>

#include <iostream>
#include <typeinfo>

#include "../tests.h"

#include "../testmatrix.h"


int
main(int argc, char **argv)
{
initlog();
deallog << std::setprecision(4);

Utilities::MPI::MPI_InitFinalize mpi_initialization(
argc, argv, testing_max_num_threads());


{
SolverControl control(200, 1.3e-10);

const unsigned int size = 32;
unsigned int dim = (size - 1) * (size - 1);

deallog << "Size " << size << " Unknowns " << dim << std::endl;

// Make matrix
FDMatrix testproblem(size, size);
DynamicSparsityPattern csp(dim, dim);
testproblem.five_point_structure(csp);
LinearAlgebra::TpetraWrappers::SparseMatrix<double> A;
A.reinit(csp);
testproblem.five_point(A);

LinearAlgebra::TpetraWrappers::Vector<double> f;
f.reinit(complete_index_set(dim), MPI_COMM_WORLD);
LinearAlgebra::TpetraWrappers::Vector<double> u;
u.reinit(complete_index_set(dim), MPI_COMM_WORLD);
f.trilinos_rcp()->putScalar(1.0);
A.compress(VectorOperation::insert);
f.compress(VectorOperation::insert);
u.compress(VectorOperation::insert);

GrowingVectorMemory<LinearAlgebra::TpetraWrappers::Vector<double>> mem;
SolverBicgstab<LinearAlgebra::TpetraWrappers::Vector<double>> solver(
control, mem);
PreconditionIdentity preconditioner;

deallog << "Solver type: " << typeid(solver).name() << std::endl;

check_solver_within_range(solver.solve(A, u, f, preconditioner),
control.last_step(),
49,
51);
}
}
4 changes: 4 additions & 0 deletions tests/trilinos_tpetra/deal_solver_02.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

DEAL::Size 32 Unknowns 961
DEAL::Solver type: N6dealii14SolverBicgstabINS_13LinearAlgebra14TpetraWrappers6VectorIdNS_11MemorySpace4HostEEEEE
DEAL::Solver stopped within 49 - 51 iterations
90 changes: 90 additions & 0 deletions tests/trilinos_tpetra/deal_solver_03.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2004 - 2024 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.
//
// ---------------------------------------------------------------------


// test the GMRES solver using the Trilinos matrix and vector classes



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

#include <deal.II/lac/precondition.h>
#include <deal.II/lac/solver.h>
#include <deal.II/lac/solver_bicgstab.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/solver_control.h>
#include <deal.II/lac/solver_gmres.h>
#include <deal.II/lac/solver_qmrs.h>
#include <deal.II/lac/solver_richardson.h>
#include <deal.II/lac/trilinos_tpetra_sparse_matrix.h>
#include <deal.II/lac/trilinos_vector.h>
#include <deal.II/lac/vector_memory.h>

#include <iostream>
#include <typeinfo>

#include "../tests.h"

#include "../testmatrix.h"


int
main(int argc, char **argv)
{
initlog();
deallog << std::setprecision(2);

Utilities::MPI::MPI_InitFinalize mpi_initialization(
argc, argv, testing_max_num_threads());


{
SolverControl control(2000, 1.e-3);

const unsigned int size = 32;
unsigned int dim = (size - 1) * (size - 1);

deallog << "Size " << size << " Unknowns " << dim << std::endl;

// Make matrix
FDMatrix testproblem(size, size);
DynamicSparsityPattern csp(dim, dim);
testproblem.five_point_structure(csp);
LinearAlgebra::TpetraWrappers::SparseMatrix<double> A;
A.reinit(csp);
testproblem.five_point(A);

LinearAlgebra::TpetraWrappers::Vector<double> f;
f.reinit(complete_index_set(dim), MPI_COMM_WORLD);
LinearAlgebra::TpetraWrappers::Vector<double> u;
u.reinit(complete_index_set(dim), MPI_COMM_WORLD);
f.trilinos_rcp()->putScalar(1.0);
A.compress(VectorOperation::insert);
f.compress(VectorOperation::insert);
u.compress(VectorOperation::insert);

GrowingVectorMemory<LinearAlgebra::TpetraWrappers::Vector<double>> mem;
SolverGMRES<LinearAlgebra::TpetraWrappers::Vector<double>> solver(control,
mem);
PreconditionIdentity preconditioner;

deallog << "Solver type: " << typeid(solver).name() << std::endl;

check_solver_within_range(solver.solve(A, u, f, preconditioner),
control.last_step(),
74,
76);
}
}
4 changes: 4 additions & 0 deletions tests/trilinos_tpetra/deal_solver_03.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

DEAL::Size 32 Unknowns 961
DEAL::Solver type: N6dealii11SolverGMRESINS_13LinearAlgebra14TpetraWrappers6VectorIdNS_11MemorySpace4HostEEEEE
DEAL::Solver stopped within 74 - 76 iterations
89 changes: 89 additions & 0 deletions tests/trilinos_tpetra/deal_solver_04.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2004 - 2024 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.
//
// ---------------------------------------------------------------------


// test the MINRES solver using the Trilinos matrix and vector classes


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

#include <deal.II/lac/precondition.h>
#include <deal.II/lac/solver_bicgstab.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/solver_control.h>
#include <deal.II/lac/solver_gmres.h>
#include <deal.II/lac/solver_minres.h>
#include <deal.II/lac/solver_qmrs.h>
#include <deal.II/lac/solver_richardson.h>
#include <deal.II/lac/trilinos_tpetra_sparse_matrix.h>
#include <deal.II/lac/trilinos_vector.h>
#include <deal.II/lac/vector_memory.h>

#include <iostream>
#include <typeinfo>

#include "../tests.h"

#include "../testmatrix.h"


int
main(int argc, char **argv)
{
initlog();
deallog << std::setprecision(4);

Utilities::MPI::MPI_InitFinalize mpi_initialization(
argc, argv, testing_max_num_threads());


{
SolverControl control(100, 1.e-3);

const unsigned int size = 32;
unsigned int dim = (size - 1) * (size - 1);

deallog << "Size " << size << " Unknowns " << dim << std::endl;

// Make matrix
FDMatrix testproblem(size, size);
DynamicSparsityPattern csp(dim, dim);
testproblem.five_point_structure(csp);
LinearAlgebra::TpetraWrappers::SparseMatrix<double> A;
A.reinit(csp);
testproblem.five_point(A);

LinearAlgebra::TpetraWrappers::Vector<double> f;
f.reinit(complete_index_set(dim), MPI_COMM_WORLD);
LinearAlgebra::TpetraWrappers::Vector<double> u;
u.reinit(complete_index_set(dim), MPI_COMM_WORLD);
f.trilinos_rcp()->putScalar(1.0);
A.compress(VectorOperation::insert);
f.compress(VectorOperation::insert);
u.compress(VectorOperation::insert);

GrowingVectorMemory<LinearAlgebra::TpetraWrappers::Vector<double>> mem;
SolverMinRes<LinearAlgebra::TpetraWrappers::Vector<double>> solver(control,
mem);
PreconditionIdentity preconditioner;

deallog << "Solver type: " << typeid(solver).name() << std::endl;

check_solver_within_range(solver.solve(A, u, f, preconditioner),
control.last_step(),
0,
42);
}
}
4 changes: 4 additions & 0 deletions tests/trilinos_tpetra/deal_solver_04.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

DEAL::Size 32 Unknowns 961
DEAL::Solver type: N6dealii12SolverMinResINS_13LinearAlgebra14TpetraWrappers6VectorIdNS_11MemorySpace4HostEEEEE
DEAL::Solver stopped after 43 iterations

0 comments on commit 4bed5f3

Please sign in to comment.