From f03e54f6966c9c0081401a3f2f54069bd1ee1ec7 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Sun, 29 Jan 2017 15:03:39 +0100 Subject: [PATCH] Add tests wherein solver is reused in sequential LinearOperator ops. --- tests/trilinos/solver_control_04.cc | 95 ++++++++++++++++++ .../solver_control_04.with_cxx11=on.output | 7 ++ tests/trilinos/solver_control_05.cc | 98 +++++++++++++++++++ .../solver_control_05.with_cxx11=on.output | 7 ++ 4 files changed, 207 insertions(+) create mode 100644 tests/trilinos/solver_control_04.cc create mode 100644 tests/trilinos/solver_control_04.with_cxx11=on.output create mode 100644 tests/trilinos/solver_control_05.cc create mode 100644 tests/trilinos/solver_control_05.with_cxx11=on.output diff --git a/tests/trilinos/solver_control_04.cc b/tests/trilinos/solver_control_04.cc new file mode 100644 index 0000000000..cef5b7bc81 --- /dev/null +++ b/tests/trilinos/solver_control_04.cc @@ -0,0 +1,95 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2004 - 2015 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// test that we can reuse a Trilinos solver in a LinearOperator + + +#include "../tests.h" +#include +#include "../testmatrix.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + std::ofstream logfile("output"); + logfile.precision(4); + deallog.attach(logfile); + deallog.threshold_double(1.e-10); + + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads()); + + + { + 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); + TrilinosWrappers::SparseMatrix A; + A.reinit(csp); + testproblem.five_point(A); + + TrilinosWrappers::Vector f(dim); + TrilinosWrappers::Vector u1(dim); + TrilinosWrappers::Vector u2(dim); + f = 1.; + A.compress (VectorOperation::insert); + f.compress (VectorOperation::insert); + u1.compress (VectorOperation::insert); + u2.compress (VectorOperation::insert); + + TrilinosWrappers::PreconditionJacobi preconditioner; + preconditioner.initialize(A); + + SolverControl solver_control(2000, 1.e-3); + TrilinosWrappers::SolverCG solver(solver_control); + + const auto lo_A = linear_operator(A); + const auto lo_A_inv = inverse_operator(lo_A, + solver, + preconditioner); + + deallog.push("First use"); + { + u1 = lo_A_inv * f; + deallog << "OK" << std::endl; + } + deallog.pop(); + deallog.push("Second use"); + { + u2 = lo_A_inv * f; + deallog << "OK" << std::endl; + } + deallog.pop(); + } + + deallog << "OK" << std::endl; +} diff --git a/tests/trilinos/solver_control_04.with_cxx11=on.output b/tests/trilinos/solver_control_04.with_cxx11=on.output new file mode 100644 index 0000000000..93fb9009e8 --- /dev/null +++ b/tests/trilinos/solver_control_04.with_cxx11=on.output @@ -0,0 +1,7 @@ + +DEAL::Size 32 Unknowns 961 +DEAL:First use::Convergence step 43 value 0.000818932 +DEAL:First use::OK +DEAL:Second use::Convergence step 43 value 0.000818932 +DEAL:Second use::OK +DEAL::OK diff --git a/tests/trilinos/solver_control_05.cc b/tests/trilinos/solver_control_05.cc new file mode 100644 index 0000000000..dd637c0817 --- /dev/null +++ b/tests/trilinos/solver_control_05.cc @@ -0,0 +1,98 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2004 - 2015 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// test that we can reuse a Trilinos solver in a LinearOperator +// This tests differs from solver_control_04 in that here we have a diagonal +// matrix, i.e. one that will converge in 1 step. + + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + std::ofstream logfile("output"); + logfile.precision(4); + deallog.attach(logfile); + deallog.threshold_double(1.e-10); + + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads()); + + + { + unsigned int dim = 10; + + deallog << " Unknowns " << dim << std::endl; + + // Make matrix + DynamicSparsityPattern csp (dim, dim); + for (unsigned int row=0; row(A); + const auto lo_A_inv = inverse_operator(lo_A, + solver, + preconditioner); + + deallog.push("First use"); + { + u1 = lo_A_inv * f; + deallog << "OK" << std::endl; + } + deallog.pop(); + deallog.push("Second use"); + { + u2 = lo_A_inv * f; + deallog << "OK" << std::endl; + } + deallog.pop(); + } + + deallog << "OK" << std::endl; +} diff --git a/tests/trilinos/solver_control_05.with_cxx11=on.output b/tests/trilinos/solver_control_05.with_cxx11=on.output new file mode 100644 index 0000000000..0cbfa84c05 --- /dev/null +++ b/tests/trilinos/solver_control_05.with_cxx11=on.output @@ -0,0 +1,7 @@ + +DEAL:: Unknowns 10 +DEAL:First use::Convergence step 1 value 0 +DEAL:First use::OK +DEAL:Second use::Convergence step 1 value 0 +DEAL:Second use::OK +DEAL::OK -- 2.39.5