]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add tests wherein solver is reused in sequential LinearOperator ops. 3866/head
authorJean-Paul Pelteret <jppelteret@gmail.com>
Sun, 29 Jan 2017 14:03:39 +0000 (15:03 +0100)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Mon, 30 Jan 2017 13:28:31 +0000 (14:28 +0100)
tests/trilinos/solver_control_04.cc [new file with mode: 0644]
tests/trilinos/solver_control_04.with_cxx11=on.output [new file with mode: 0644]
tests/trilinos/solver_control_05.cc [new file with mode: 0644]
tests/trilinos/solver_control_05.with_cxx11=on.output [new file with mode: 0644]

diff --git a/tests/trilinos/solver_control_04.cc b/tests/trilinos/solver_control_04.cc
new file mode 100644 (file)
index 0000000..cef5b7b
--- /dev/null
@@ -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 <deal.II/base/utilities.h>
+#include "../testmatrix.h"
+#include <cmath>
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/trilinos_sparse_matrix.h>
+#include <deal.II/lac/trilinos_vector.h>
+#include <deal.II/lac/trilinos_solver.h>
+#include <deal.II/lac/trilinos_precondition.h>
+#include <deal.II/lac/trilinos_linear_operator.h>
+#include <deal.II/lac/linear_operator.h>
+#include <deal.II/lac/packaged_operation.h>
+
+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<TrilinosWrappers::Vector>(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 (file)
index 0000000..93fb900
--- /dev/null
@@ -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 (file)
index 0000000..dd637c0
--- /dev/null
@@ -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 <deal.II/base/utilities.h>
+#include <cmath>
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
+#include <deal.II/lac/trilinos_sparse_matrix.h>
+#include <deal.II/lac/trilinos_vector.h>
+#include <deal.II/lac/trilinos_solver.h>
+#include <deal.II/lac/trilinos_precondition.h>
+#include <deal.II/lac/trilinos_linear_operator.h>
+#include <deal.II/lac/linear_operator.h>
+#include <deal.II/lac/packaged_operation.h>
+
+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<dim; row++)
+      csp.add(row,row);
+
+    TrilinosWrappers::SparseMatrix  A;
+    A.reinit(csp);
+    for (unsigned int row=0; row<dim; row++)
+      A.set(row,row, 2.0*(row+1));
+
+    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<TrilinosWrappers::Vector>(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 (file)
index 0000000..0cbfa84
--- /dev/null
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.