From: young Date: Sun, 20 Oct 2013 14:29:03 +0000 (+0000) Subject: Clone five solver tests to verify that using petsc-scalar=complex does not affect... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d42af7124ad2dbb7f37b7779f4b837c1e298fce;p=dealii-svn.git Clone five solver tests to verify that using petsc-scalar=complex does not affect the usual real arithmetic (syntax and results). Note: */cmp/generic are cloned too. git-svn-id: https://svn.dealii.org/branches/branch_petscscalar_complex@31336 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/petsc_scalar_complex/solver_real_01.cc b/tests/petsc_scalar_complex/solver_real_01.cc new file mode 100644 index 0000000000..d794ff3da5 --- /dev/null +++ b/tests/petsc_scalar_complex/solver_real_01.cc @@ -0,0 +1,98 @@ +// --------------------------------------------------------------------- +// $Id: solver_real_01.cc +// +// Copyright (C) 2013 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 the PETSc Richardson solver + +// 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 + +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 (std::exception &e) + { + deallog << e.what() << std::endl; + // it needs to be expected for the + // richardson solver that we end up + // here, so don't abort + } + + deallog << "Solver stopped after " << solver.control().last_step() + << " iterations" << std::endl; +} + + +int main(int argc, char **argv) +{ + std::ofstream logfile("solver_real_01/output"); + deallog.attach(logfile); + deallog << std::setprecision(4); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + 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); + + deallog << "Size " << size << " Unknowns " << dim << std::endl; + + // Make matrix + FDMatrix testproblem(size, size); + PETScWrappers::SparseMatrix A(dim, dim, 5); + testproblem.five_point(A); + + PETScWrappers::Vector f(dim); + PETScWrappers::Vector u(dim); + f = 1.; + A.compress (VectorOperation::add); + f.compress (VectorOperation::add); + u.compress (VectorOperation::add); + + PETScWrappers::SolverRichardson solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + +} + diff --git a/tests/petsc_scalar_complex/solver_real_01/cmp/generic b/tests/petsc_scalar_complex/solver_real_01/cmp/generic new file mode 100644 index 0000000000..208bfd4911 --- /dev/null +++ b/tests/petsc_scalar_complex/solver_real_01/cmp/generic @@ -0,0 +1,7 @@ + +DEAL::Size 32 Unknowns 961 +DEAL::Solver type: N6dealii13PETScWrappers16SolverRichardsonE +DEAL::Starting value 7.750 +DEAL::Failure step 100 value 4.004 +DEAL::Iterative method reported convergence failure in step 100 with residual 4.00437 +DEAL::Solver stopped after 100 iterations diff --git a/tests/petsc_scalar_complex/solver_real_02.cc b/tests/petsc_scalar_complex/solver_real_02.cc new file mode 100644 index 0000000000..fce802f013 --- /dev/null +++ b/tests/petsc_scalar_complex/solver_real_02.cc @@ -0,0 +1,96 @@ +// --------------------------------------------------------------------- +// $Id: solver_real_02.cc +// +// Copyright (C) 2013 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 the PETSc Chebychev solver + +// Note: This is (almost) a clone of the tests/petsc/solver_02.cc + +#include "../tests.h" +#include "../lac/testmatrix.h" +#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 (std::exception &e) + { + deallog << e.what() << std::endl; + // just like for Richardson: we end up + // here normally for this solver + } + + deallog << "Solver stopped after " << solver.control().last_step() + << " iterations" << std::endl; +} + + +int main(int argc, char **argv) +{ + std::ofstream logfile("solver_real_02/output"); + deallog.attach(logfile); + deallog << std::setprecision(4); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + 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); + + deallog << "Size " << size << " Unknowns " << dim << std::endl; + + // Make matrix + FDMatrix testproblem(size, size); + PETScWrappers::SparseMatrix A(dim, dim, 5); + testproblem.five_point(A); + + PETScWrappers::Vector f(dim); + PETScWrappers::Vector u(dim); + f = 1.; + A.compress (VectorOperation::add); + f.compress (VectorOperation::add); + u.compress (VectorOperation::add); + + PETScWrappers::SolverChebychev solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + +} + diff --git a/tests/petsc_scalar_complex/solver_real_02/cmp/generic b/tests/petsc_scalar_complex/solver_real_02/cmp/generic new file mode 100644 index 0000000000..47abf08e11 --- /dev/null +++ b/tests/petsc_scalar_complex/solver_real_02/cmp/generic @@ -0,0 +1,7 @@ + +DEAL::Size 32 Unknowns 961 +DEAL::Solver type: N6dealii13PETScWrappers15SolverChebychevE +DEAL::Starting value 7.551 +DEAL::Failure step 100 value 2.942 +DEAL::Iterative method reported convergence failure in step 100 with residual 2.94179 +DEAL::Solver stopped after 100 iterations diff --git a/tests/petsc_scalar_complex/solver_real_03.cc b/tests/petsc_scalar_complex/solver_real_03.cc new file mode 100644 index 0000000000..8a7e3b0bad --- /dev/null +++ b/tests/petsc_scalar_complex/solver_real_03.cc @@ -0,0 +1,95 @@ +// --------------------------------------------------------------------- +// $Id: solver_real_03.cc +// +// Copyright (C) 2013 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 the PETSc CG solver + +// Note: This is (almost) a clone of the tests/petsc/solver_03.cc + +#include "../tests.h" +#include "../lac/testmatrix.h" +#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 (std::exception &e) + { + deallog << e.what() << std::endl; + abort (); + } + + deallog << "Solver stopped after " << solver.control().last_step() + << " iterations" << std::endl; +} + + +int main(int argc, char **argv) +{ + std::ofstream logfile("solver_real_03/output"); + deallog.attach(logfile); + deallog << std::setprecision(4); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + 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); + + deallog << "Size " << size << " Unknowns " << dim << std::endl; + + // Make matrix + FDMatrix testproblem(size, size); + PETScWrappers::SparseMatrix A(dim, dim, 5); + testproblem.five_point(A); + + PETScWrappers::Vector f(dim); + PETScWrappers::Vector u(dim); + f = 1.; + A.compress (VectorOperation::add); + f.compress (VectorOperation::add); + u.compress (VectorOperation::add); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + +} + diff --git a/tests/petsc_scalar_complex/solver_real_03/cmp/generic b/tests/petsc_scalar_complex/solver_real_03/cmp/generic new file mode 100644 index 0000000000..2237281800 --- /dev/null +++ b/tests/petsc_scalar_complex/solver_real_03/cmp/generic @@ -0,0 +1,6 @@ + +DEAL::Size 32 Unknowns 961 +DEAL::Solver type: N6dealii13PETScWrappers8SolverCGE +DEAL::Starting value 7.750 +DEAL::Convergence step 41 value 0.0006730 +DEAL::Solver stopped after 41 iterations diff --git a/tests/petsc_scalar_complex/solver_real_03_mf.cc b/tests/petsc_scalar_complex/solver_real_03_mf.cc new file mode 100644 index 0000000000..ad816220e6 --- /dev/null +++ b/tests/petsc_scalar_complex/solver_real_03_mf.cc @@ -0,0 +1,101 @@ +// --------------------------------------------------------------------- +// $Id: solver_03_mf.cc 30045 2013-07-18 19:18:00Z maier $ +// +// Copyright (C) 2004 - 2013 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 the PETSc CG solver with PETSc MatrixFree class + +// Note: This is (almost) a clone of the tests/petsc/solver_03_mf.cc + +#include "../tests.h" +#include "../petsc/petsc_mf_testmatrix.h" // It is tempting to copy + // ../petsc/petsc_mf_testmatrix.h + // into this directory and + // play with it, but, by + // using *that* file + // directly is itself a test + // of syntax compatibility + // between petsc-scalar=real + // and petsc-scalar=complex. +#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 (std::exception &e) + { + std::cout << e.what() << std::endl; + deallog << e.what() << std::endl; + abort (); + } + + deallog << "Solver stopped after " << solver.control().last_step() + << " iterations" << std::endl; +} + + +int main(int argc, char **argv) +{ + std::ofstream logfile("solver_real_03_mf/output"); + deallog.attach(logfile); + deallog << std::setprecision(4); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + 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); + + deallog << "Size " << size << " Unknowns " << dim << std::endl; + + PetscFDMatrix A(size, dim); + + PETScWrappers::Vector f(dim); + PETScWrappers::Vector u(dim); + f = 1.; + A.compress (VectorOperation::add); + f.compress (VectorOperation::add); + u.compress (VectorOperation::add); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionNone preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + +} + diff --git a/tests/petsc_scalar_complex/solver_real_03_mf/cmp/generic b/tests/petsc_scalar_complex/solver_real_03_mf/cmp/generic new file mode 100644 index 0000000000..bea3eb1acb --- /dev/null +++ b/tests/petsc_scalar_complex/solver_real_03_mf/cmp/generic @@ -0,0 +1,6 @@ + +DEAL::Size 32 Unknowns 961 +DEAL::Solver type: N6dealii13PETScWrappers8SolverCGE +DEAL::Starting value 31.00 +DEAL::Convergence step 43 value 0.0008189 +DEAL::Solver stopped after 43 iterations diff --git a/tests/petsc_scalar_complex/solver_real_04.cc b/tests/petsc_scalar_complex/solver_real_04.cc new file mode 100644 index 0000000000..470697b053 --- /dev/null +++ b/tests/petsc_scalar_complex/solver_real_04.cc @@ -0,0 +1,95 @@ +// --------------------------------------------------------------------- +// $Id: solver_real_04.cc +// +// Copyright (C) 2013 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 the PETSc BiCG solver + +// Note: This is (almost) a clone of the tests/petsc/solver_03.cc + +#include "../tests.h" +#include "../lac/testmatrix.h" +#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 (std::exception &e) + { + deallog << e.what() << std::endl; + abort (); + } + + deallog << "Solver stopped after " << solver.control().last_step() + << " iterations" << std::endl; +} + + +int main(int argc, char **argv) +{ + std::ofstream logfile("solver_real_04/output"); + deallog.attach(logfile); + deallog << std::setprecision(4); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + 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); + + deallog << "Size " << size << " Unknowns " << dim << std::endl; + + // Make matrix + FDMatrix testproblem(size, size); + PETScWrappers::SparseMatrix A(dim, dim, 5); + testproblem.five_point(A); + + PETScWrappers::Vector f(dim); + PETScWrappers::Vector u(dim); + f = 1.; + A.compress (VectorOperation::add); + f.compress (VectorOperation::add); + u.compress (VectorOperation::add); + + PETScWrappers::SolverBiCG solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + +} + diff --git a/tests/petsc_scalar_complex/solver_real_04/cmp/generic b/tests/petsc_scalar_complex/solver_real_04/cmp/generic new file mode 100644 index 0000000000..d69ef9440f --- /dev/null +++ b/tests/petsc_scalar_complex/solver_real_04/cmp/generic @@ -0,0 +1,6 @@ + +DEAL::Size 32 Unknowns 961 +DEAL::Solver type: N6dealii13PETScWrappers10SolverBiCGE +DEAL::Starting value 7.750 +DEAL::Convergence step 41 value 0.0006730 +DEAL::Solver stopped after 41 iterations