]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Tests: Fix petsc/solver_(01|02) to test for convergence
authorMatthias Maier <tamiko@43-1.org>
Tue, 12 Jul 2016 16:33:23 +0000 (11:33 -0500)
committerMatthias Maier <tamiko@43-1.org>
Tue, 12 Jul 2016 16:33:23 +0000 (11:33 -0500)
tests/petsc/solver_01.cc
tests/petsc/solver_01.output
tests/petsc/solver_02.cc
tests/petsc/solver_02.output

index bd393536d3825b91d362acf3fe6f5ec5b4cea4e9..9efe7af4a27715d8fc48dbc38910da725fae7245 100644 (file)
@@ -1,6 +1,6 @@
 // ---------------------------------------------------------------------
 //
-// Copyright (C) 2004 - 2015 by the deal.II authors
+// Copyright (C) 2004 - 2016 by the deal.II authors
 //
 // This file is part of the deal.II library.
 //
 //
 // ---------------------------------------------------------------------
 
-
 // test the PETSc Richardson solver
 
-
 #include "../tests.h"
 #include "../lac/testmatrix.h"
-#include <cmath>
-#include <fstream>
-#include <iostream>
-#include <iomanip>
-#include <deal.II/base/logstream.h>
+
 #include <deal.II/lac/petsc_sparse_matrix.h>
 #include <deal.II/lac/petsc_vector.h>
 #include <deal.II/lac/petsc_solver.h>
 #include <deal.II/lac/petsc_precondition.h>
-#include <deal.II/lac/vector_memory.h>
-#include <typeinfo>
-
-template<typename SolverType, typename MatrixType, typename VectorType, class PRECONDITION>
-void
-check_solve(SolverType          &solver,
-            const SolverControl &solver_control,
-            const MatrixType    &A,
-            VectorType          &u,
-            VectorType          &f,
-            const PRECONDITION  &P)
-{
-  deallog << "Solver type: " << typeid(solver).name() << std::endl;
-
-  u = 0.;
-  f = 1.;
-  try
-    {
-      solver.solve(A,u,f,P);
-    }
-  catch (dealii::SolverControl::NoConvergence &e)
-    {
-      deallog << "Exception: " << e.get_exc_name() << std::endl;
-    }
-
-  deallog << "Solver stopped after " << solver_control.last_step()
-          << " iterations" << std::endl;
-}
-
 
 int main(int argc, char **argv)
 {
-  std::ofstream logfile("output");
-  deallog.attach(logfile);
-  deallog << std::setprecision(4);
-  deallog.threshold_double(1.e-10);
+  initlog();
 
   Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, 1);
   {
-    SolverControl control(100, 1.e-3);
-
     const unsigned int size = 32;
     unsigned int dim = (size-1)*(size-1);
 
@@ -81,12 +41,24 @@ int main(int argc, char **argv)
 
     PETScWrappers::Vector  f(dim);
     PETScWrappers::Vector  u(dim);
+
     f = 1.;
+    u = 0.;
+
     A.compress (VectorOperation::insert);
+    f.compress (VectorOperation::insert);
+    u.compress (VectorOperation::insert);
+
+    // Richardson is a tricky smoother for the kind of FD matrix we use in
+    // this test. So, simply test that we're able to reduce the residual to
+    // a reasonably small value of 1.e-4.
+    SolverControl control(2500, 1.e-4);
 
     PETScWrappers::SolverRichardson solver(control);
     PETScWrappers::PreconditionJacobi preconditioner(A);
-    check_solve (solver, control, A,u,f, preconditioner);
-  }
 
+    check_solver_within_range(
+      solver.solve(A,u,f, preconditioner),
+      control.last_step(), 2295, 2300);
+  }
 }
index dbab15846c21d4adc218d78c53b97ac68bb0b1e8..60a06149f0ca766a1cad3e9061a3cae514b02c2a 100644 (file)
@@ -1,7 +1,3 @@
 
 DEAL::Size 32 Unknowns 961
-DEAL::Solver type: N6dealii13PETScWrappers16SolverRichardsonE
-DEAL::Starting value 7.750
-DEAL::Failure step 100 value 4.004
-DEAL::Exception: SolverControl::NoConvergence (solver_control.last_step(), solver_control.last_value())
-DEAL::Solver stopped after 100 iterations
+DEAL::Solver stopped within 2295 - 2300 iterations
index 9a3566ad656d89b9be90e907c22df57b28e6da0a..a016d736d3aa07f73500f1b7835ba23912f192ec 100644 (file)
@@ -1,6 +1,6 @@
 // ---------------------------------------------------------------------
 //
-// Copyright (C) 2004 - 2015 by the deal.II authors
+// Copyright (C) 2004 - 2016 by the deal.II authors
 //
 // This file is part of the deal.II library.
 //
 //
 // ---------------------------------------------------------------------
 
-
 // test the PETSc Chebychev solver
 
-
 #include "../tests.h"
 #include "../lac/testmatrix.h"
-#include <cmath>
-#include <fstream>
-#include <iostream>
-#include <iomanip>
-#include <deal.II/base/logstream.h>
+
 #include <deal.II/lac/petsc_sparse_matrix.h>
 #include <deal.II/lac/petsc_vector.h>
 #include <deal.II/lac/petsc_solver.h>
 #include <deal.II/lac/petsc_precondition.h>
-#include <deal.II/lac/vector_memory.h>
-#include <typeinfo>
-
-template<typename SolverType, typename MatrixType, typename VectorType, class PRECONDITION>
-void
-check_solve(SolverType          &solver,
-            const SolverControl &solver_control,
-            const MatrixType    &A,
-            VectorType          &u,
-            VectorType          &f,
-            const PRECONDITION  &P)
-{
-  deallog << "Solver type: " << typeid(solver).name() << std::endl;
-
-  u = 0.;
-  f = 1.;
-  try
-    {
-      deallog.depth_file(0);
-      solver.solve(A,u,f,P);
-      deallog.depth_file(3);
-    }
-  catch (dealii::SolverControl::NoConvergence &e)
-    {
-      deallog.depth_file(3);
-      deallog << "Exception: " << e.get_exc_name() << std::endl;
-    }
-
-  deallog << "Solver stopped after " << solver_control.last_step()
-          << " iterations" << std::endl;
-}
-
 
 int main(int argc, char **argv)
 {
-  std::ofstream logfile("output");
-  deallog.attach(logfile);
-  deallog << std::setprecision(4);
-  deallog.threshold_double(1.e-10);
+  initlog();
 
-  Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, 1);
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
   {
-    SolverControl control(100, 1.e-3);
-
     const unsigned int size = 32;
     unsigned int dim = (size-1)*(size-1);
 
@@ -84,12 +41,24 @@ int main(int argc, char **argv)
 
     PETScWrappers::Vector  f(dim);
     PETScWrappers::Vector  u(dim);
+
     f = 1.;
+    u = 0.;
+
     A.compress (VectorOperation::insert);
+    f.compress (VectorOperation::insert);
+    u.compress (VectorOperation::insert);
+
+    // Chebychev is a tricky smoother for the kind of FD matrix we use in
+    // this test. So, simply test that we're able to reduce the residual to
+    // a reasonably small value of 1.e-3.
+    SolverControl control(2500, 1.e-3);
 
     PETScWrappers::SolverChebychev solver(control);
     PETScWrappers::PreconditionJacobi preconditioner(A);
-    check_solve (solver, control, A,u,f, preconditioner);
-  }
 
+    check_solver_within_range(
+      solver.solve(A,u,f, preconditioner),
+      control.last_step(), 1120, 1125);
+  }
 }
index 1c90dd386c707c792ee1e02d8e2f9ebc0b02c2b4..8e5ffc60890ccf502e3b24fcb8a223ec952eda33 100644 (file)
@@ -1,5 +1,3 @@
 
 DEAL::Size 32 Unknowns 961
-DEAL::Solver type: N6dealii13PETScWrappers15SolverChebychevE
-DEAL::Exception: SolverControl::NoConvergence (solver_control.last_step(), solver_control.last_value())
-DEAL::Solver stopped after 100 iterations
+DEAL::Solver stopped within 1120 - 1125 iterations

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.