From: Matthias Maier Date: Tue, 12 Jul 2016 15:34:41 +0000 (-0500) Subject: Tests: Fix petsc_complex/solver_real_(01|02) to test for convergence X-Git-Tag: v8.5.0-rc1~860^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44708244a3ec7cb362b0758b7869834473e48b5d;p=dealii.git Tests: Fix petsc_complex/solver_real_(01|02) to test for convergence --- diff --git a/tests/petsc_complex/solver_real_01.cc b/tests/petsc_complex/solver_real_01.cc index 383e017417..5d1564580a 100644 --- a/tests/petsc_complex/solver_real_01.cc +++ b/tests/petsc_complex/solver_real_01.cc @@ -18,56 +18,20 @@ // Note: This is (almost) a clone of the tests/petsc/solver_01.cc - #include "../tests.h" #include "../lac/testmatrix.h" -#include -#include -#include -#include -#include + +#include +#include #include #include -#include -#include -#include -#include - -template -void -check_solve( SOLVER &solver, const MATRIX &A, - VECTOR &u, VECTOR &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.depth_console(0); - 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); @@ -80,13 +44,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, A,u,f, preconditioner); + + check_solver_within_range( + solver.solve(A,u,f, preconditioner), + control.last_step(), 2295, 2300); } } diff --git a/tests/petsc_complex/solver_real_01.output b/tests/petsc_complex/solver_real_01.output index dbab15846c..60a06149f0 100644 --- a/tests/petsc_complex/solver_real_01.output +++ b/tests/petsc_complex/solver_real_01.output @@ -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 diff --git a/tests/petsc_complex/solver_real_02.cc b/tests/petsc_complex/solver_real_02.cc index 8536e318f1..d8b1040b02 100644 --- a/tests/petsc_complex/solver_real_02.cc +++ b/tests/petsc_complex/solver_real_02.cc @@ -20,53 +20,18 @@ #include "../tests.h" #include "../lac/testmatrix.h" -#include -#include -#include -#include -#include + +#include +#include #include #include -#include -#include -#include -#include - -template -void -check_solve( SOLVER &solver, const MATRIX &A, - VECTOR &u, VECTOR &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.depth_console(0); - 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); @@ -79,14 +44,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, A,u,f, preconditioner); - } + check_solver_within_range( + solver.solve(A,u,f, preconditioner), + control.last_step(), 1120, 1125); + } } diff --git a/tests/petsc_complex/solver_real_02.output b/tests/petsc_complex/solver_real_02.output index 00c1e2226c..8e5ffc6089 100644 --- a/tests/petsc_complex/solver_real_02.output +++ b/tests/petsc_complex/solver_real_02.output @@ -1,7 +1,3 @@ DEAL::Size 32 Unknowns 961 -DEAL::Solver type: N6dealii13PETScWrappers15SolverChebychevE -DEAL::Starting value 7.551 -DEAL::Failure step 100 value 2.937 -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