From: young Date: Sun, 20 Oct 2013 23:23:20 +0000 (+0000) Subject: Restore missing tree. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fd1f6107b6793f18684a7d259cd120e652ab530;p=dealii-svn.git Restore missing tree. git-svn-id: https://svn.dealii.org/branches/branch_petscscalar_complex@31364 0785d39b-7218-0410-832d-ea1e28bc413d --- 6fd1f6107b6793f18684a7d259cd120e652ab530 diff --cc tests/petsc/01.cc index 0000000000,5f3cc2ad78..56d6479250 mode 000000,100644..100644 --- a/tests/petsc/01.cc +++ b/tests/petsc/01.cc @@@ -1,0 -1,97 +1,97 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: 01.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check setting elements in a petsc matrix using + // PETScWrappers::SparseMatrix::set() + + #include "../tests.h" + #include + #include + #include + + + void test (PETScWrappers::SparseMatrix &m) + { + // first set a few entries + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::SparseMatrix &m) + { + // first set a few entries + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::SparseMatrix &m) + { + Assert (m.m() == 5, ExcInternalError()); + Assert (m.n() == 5, ExcInternalError()); + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + PETScWrappers::SparseMatrix m (5,5,3); + test (m); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/05.cc index 0000000000,3991d6ecb0..4536b19b09 mode 000000,100644..100644 --- a/tests/petsc/05.cc +++ b/tests/petsc/05.cc @@@ -1,0 -1,92 +1,92 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: 05.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check querying the number of nonzero elements in + // PETScWrappers::SparseMatrix + + #include "../tests.h" + #include + #include + #include + + + void test (PETScWrappers::SparseMatrix &m) + { + // first set a few entries. count how many + // entries we have + unsigned int counter = 0; + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::SparseMatrix &m) + { + // first set a few entries. count how many + // entries we have + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::SparseMatrix &m) + { + // first set a few entries. count how many + // entries we have + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::SparseMatrix &m) + { + // first set a few entries. count how many + // entries we have + PetscScalar norm = 0; + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::SparseMatrix &m) + { + // first set a few entries + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::SparseMatrix &m) + { + // first set a few entries + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the + // vector. have a bit pattern of where we + // actually wrote elements to + std::vector pattern (v.size(), false); + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the + // vector. have a bit pattern of where we + // actually wrote elements to + std::vector pattern (v.size(), false); + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some elements of the vector + double norm = 0; + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some elements of the vector + PetscScalar norm = 0; + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some elements of the vector + double norm = 0; + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the + // vector. have a bit pattern of where we + // actually wrote elements to + std::vector pattern (v.size(), false); + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the + // vector. have a bit pattern of where we + // actually wrote elements to + std::vector pattern (v.size(), false); + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + // set only certain elements of each + // vector, but disjoint sets of elements + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + // set only certain elements of each + // vector, and record the expected scalar + // product + double product = 0; + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some entries of the vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some entries of the vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some entries of the vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some entries of the vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some entries of the vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + v.reinit (13, true); + + Assert (v.size() == 13, ExcInternalError()); + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + PETScWrappers::Vector v (100); + test (v); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/30.cc index 0000000000,368a4d9194..256ece53f1 mode 000000,100644..100644 --- a/tests/petsc/30.cc +++ b/tests/petsc/30.cc @@@ -1,0 -1,87 +1,87 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: 30.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check PETScWrappers::Vector::reinit(!fast) + + #include "../tests.h" + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some entries of the vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some elements of the vector + PetscScalar norm = 0; + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some elements of the vector + PetscScalar sum = 0; + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some elements of the vector + PetscScalar sum = 0; + for (unsigned int i=0; i (1./3.)); + Assert (std::fabs(v.lp_norm(3) - true_value) < eps*true_value, + ExcInternalError()); + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + PETScWrappers::Vector v (100); + test (v); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/34.cc index 0000000000,d2ce01c600..4d26ab53ff mode 000000,100644..100644 --- a/tests/petsc/34.cc +++ b/tests/petsc/34.cc @@@ -1,0 -1,90 +1,90 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: 34.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check PETScWrappers::Vector::all_zero + + #include "../tests.h" + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some elements of the vector + double sum = 0; + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + // set only certain elements of each + // vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + // set only certain elements of each + // vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w, + PETScWrappers::Vector &x) + { + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w, + PETScWrappers::Vector &x) + { + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w, + PETScWrappers::Vector &x, + PETScWrappers::Vector &y) + { + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w, + PETScWrappers::Vector &x) + { + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w, + PETScWrappers::Vector &x) + { + for (unsigned int i=0; i) + + #include "../tests.h" + #include + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + Vector w (v.size()); + + for (unsigned int i=0; i) with T!=PetscScalar + + #include "../tests.h" + #include + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + Vector w (v.size()); + Vector x (v.size()); + + for (unsigned int i=0; i must be different from + // PetscScalar + v = w; + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set some entries of the vector + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::SparseMatrix &m) + { + // first set a few entries + for (unsigned int i=0; i row_lengths (5, 3U); + row_lengths.back() = 2; + PETScWrappers::SparseMatrix m (5,5,row_lengths); + test (m); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/55.cc index 0000000000,a6dd450067..59edea4281 mode 000000,100644..100644 --- a/tests/petsc/55.cc +++ b/tests/petsc/55.cc @@@ -1,0 -1,97 +1,97 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: 55.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check PETScWrappers::Vector::operator() in set, and later in *= mode + + #include "../tests.h" + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the + // vector. have a bit pattern of where we + // actually wrote elements to + std::vector pattern (v.size(), false); + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the + // vector. have a bit pattern of where we + // actually wrote elements to + std::vector pattern (v.size(), false); + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the + // vector. they are all positive + std::vector pattern (v.size(), false); + for (unsigned int i=0; i + #include + + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the + // vector. + std::vector pattern (v.size(), false); + for (unsigned int i=0; i w (v); + Vector x (v); + + for (unsigned int i=0; i + #include + + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the + // vector. + std::vector pattern (v.size(), false); + for (unsigned int i=0; i w (v); + Vector x (v); + + PETScWrappers::Vector w1 (w); + PETScWrappers::Vector x1 (x); + + for (unsigned int i=0; i + #include + + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the + // vector. + std::vector pattern (v.size(), false); + for (unsigned int i=0; i w; + w=v; + Vector x; + x=v; + + for (unsigned int i=0; i + #include + + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + // set only certain elements of the + // vector. + std::vector pattern (v.size(), false); + for (unsigned int i=0; i w; + w=v; + Vector x; + x=v; + + PETScWrappers::Vector w1; + w1=w; + PETScWrappers::Vector x1; + x1=x; + + for (unsigned int i=0; i + #include + + #include + #include + #include + + + void test (PETScWrappers::MatrixBase &m) + { + Assert (m.m() != 0, ExcInternalError()); + Assert (m.n() != 0, ExcInternalError()); + + m.clear (); + + Assert (m.m() == 0, ExcInternalError()); + Assert (m.n() == 0, ExcInternalError()); + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + PETScWrappers::SparseMatrix v (100,100,5); + test (v); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/63.cc index 0000000000,8b604a8309..b425a356aa mode 000000,100644..100644 --- a/tests/petsc/63.cc +++ b/tests/petsc/63.cc @@@ -1,0 -1,83 +1,83 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: 63.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + #include "../tests.h" + #include + #include + + #include + #include + #include + + + void test (PETScWrappers::MatrixBase &m) + { + Assert (m.m() == 100, ExcInternalError()); + Assert (m.n() == 100, ExcInternalError()); + + m = 0; + + Assert (m.m() == 100, ExcInternalError()); + Assert (m.n() == 100, ExcInternalError()); + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + PETScWrappers::SparseMatrix v (100,100,5); + test (v); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/64.cc index 0000000000,f3ac698435..b161c724ab mode 000000,100644..100644 --- a/tests/petsc/64.cc +++ b/tests/petsc/64.cc @@@ -1,0 -1,104 +1,104 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: 64.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // This test should be run on multiple processors. note that this test also + // started to fail with the upgrade to petsc 2.2.1 which required a fix in + // PETScWrappers::MatrixBase::operator= + + + #include "../tests.h" + #include + #include + #include + + #include + #include + #include + + + template + void test (MatrixType &m) + { + m.add(0,0,1); + m = 0; + m.compress(); + + Assert(fabs(m.frobenius_norm())<1e-15, ExcInternalError()); + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + const unsigned int n_dofs=420; + // check + // PETScWrappers::SparseMatrix + PETScWrappers::SparseMatrix + v1 (n_dofs, n_dofs, 5); + test (v1); + + // check + // PETScWrappers::MPI::SparseMatrix + MPI_Comm mpi_communicator (MPI_COMM_WORLD); + int n_jobs=1; + MPI_Comm_size (mpi_communicator, &n_jobs); + const unsigned int n_mpi_processes=static_cast(n_jobs); + Assert(n_dofs%n_mpi_processes==0, ExcInternalError()); + const unsigned int n_local_dofs=n_dofs/n_mpi_processes; + PETScWrappers::MPI::SparseMatrix + v2 (mpi_communicator, n_dofs, n_dofs, n_local_dofs, n_local_dofs, 5); + test (v2); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/65.cc index 0000000000,cf425c8b45..0cad084911 mode 000000,100644..100644 --- a/tests/petsc/65.cc +++ b/tests/petsc/65.cc @@@ -1,0 -1,81 +1,81 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: 65.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // This test used to fail after upgrading to petsc 2.2.1 + + + #include "../tests.h" + #include + + #include + #include + #include + + + void test () + { + PETScWrappers::MPI::Vector v(PETSC_COMM_WORLD, 100, 100); + v(0) = 1; + v.compress(VectorOperation::insert); + v = 0; + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + test (); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/66.cc index 0000000000,a921906e92..4d0a9d550b mode 000000,100644..100644 --- a/tests/petsc/66.cc +++ b/tests/petsc/66.cc @@@ -1,0 -1,139 +1,139 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: 66.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check PETScWrappers::MatrixBase::clear_row () + + #include "../tests.h" + #include + #include + + #include + #include + #include + + + void test (PETScWrappers::MatrixBase &m) + { + Assert (m.m() != 0, ExcInternalError()); + Assert (m.n() != 0, ExcInternalError()); + + // build a tri-diagonal pattern + double norm_sqr = 0; + unsigned int nnz = 0; + const unsigned int N = m.m(); + for (unsigned int i=0; i=5) + { + const double s = rand(); + m.add (i,i-5, s); + norm_sqr += s*s; + ++nnz; + } + + if (i + #include + + #include + #include + #include + + + void test (PETScWrappers::MatrixBase &m) + { + typedef PETScWrappers::MatrixBase::size_type size_type; + + Assert (m.m() != 0, ExcInternalError()); + Assert (m.n() != 0, ExcInternalError()); + + // build a tri-diagonal pattern + double norm_sqr = 0; + unsigned int nnz = 0; + const size_type N = m.m(); + for (size_type i=0; i=5) + { + const double s = rand(); + m.add (i,i-5, s); + norm_sqr += s*s; + ++nnz; + } + + if (i(&rows[0], &rows[2])); + + deallog << m.frobenius_norm() << ' ' << std::sqrt (norm_sqr) + << std::endl; + deallog << m.n_nonzero_elements() << ' ' << nnz << std::endl; + + Assert (std::fabs (m.frobenius_norm() - std::sqrt(norm_sqr)) + < std::fabs (std::sqrt (norm_sqr)), + ExcInternalError()); + + // make sure that zeroing out rows does at + // least not add new nonzero entries (it + // may remove some, though) + Assert (m.n_nonzero_elements() <= nnz, ExcInternalError()); + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + PETScWrappers::SparseMatrix v (14,14,3); + test (v); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/68.cc index 0000000000,676a852245..5e0d049a68 mode 000000,100644..100644 --- a/tests/petsc/68.cc +++ b/tests/petsc/68.cc @@@ -1,0 -1,143 +1,143 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: 68.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check PETScWrappers::MatrixBase::clear_row () with used second argument + + #include "../tests.h" + #include + #include + + #include + #include + #include + + + void test (PETScWrappers::MatrixBase &m) + { + Assert (m.m() != 0, ExcInternalError()); + Assert (m.n() != 0, ExcInternalError()); + + // build a tri-diagonal pattern + double norm_sqr = 0; + unsigned int nnz = 0; + const unsigned int N = m.m(); + for (unsigned int i=0; i=5) + { + const double s = rand(); + m.add (i,i-5, s); + norm_sqr += s*s; + ++nnz; + } + + if (i + #include + + #include + #include + #include + + + void test (PETScWrappers::MatrixBase &m) + { + Assert (m.m() != 0, ExcInternalError()); + Assert (m.n() != 0, ExcInternalError()); + + typedef PETScWrappers::MatrixBase::size_type size_type; + + // build a tri-diagonal pattern + double norm_sqr = 0; + unsigned int nnz = 0; + const size_type N = m.m(); + for (size_type i=0; i=5) + { + const double s = rand(); + m.add (i,i-5, s); + norm_sqr += s*s; + ++nnz; + } + + if (i(&rows[0], &rows[2]), rnd); + + deallog << m.frobenius_norm() << ' ' << std::sqrt (norm_sqr) + << std::endl; + deallog << m.n_nonzero_elements() << ' ' << nnz << std::endl; + + Assert (std::fabs (m.frobenius_norm() - std::sqrt(norm_sqr)) + < std::fabs (std::sqrt (norm_sqr)), + ExcInternalError()); + + // make sure that zeroing out rows does at + // least not add new nonzero entries (it + // may remove some, though) + Assert (m.n_nonzero_elements() <= nnz, ExcInternalError()); + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + PETScWrappers::SparseMatrix v (14,14,3); + test (v); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/70.cc index 0000000000,bc4132c6be..c2a353b39e mode 000000,100644..100644 --- a/tests/petsc/70.cc +++ b/tests/petsc/70.cc @@@ -1,0 -1,40 +1,40 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: 70.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check PetscScalar + + #include "../tests.h" + #include + #include + + #include + + int main () + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + if (typeid(PetscScalar)==typeid(double)) + deallog << "double" << std::endl; + else if (typeid(PetscScalar)==typeid(float)) + deallog << "float" << std::endl; + else + Assert(false, ExcNotImplemented()); + } diff --cc tests/petsc/block_vector_iterator_01.cc index 0000000000,e6fa61832a..cfd8a87a66 mode 000000,100644..100644 --- a/tests/petsc/block_vector_iterator_01.cc +++ b/tests/petsc/block_vector_iterator_01.cc @@@ -1,0 -1,121 +1,121 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: block_vector_iterator_01.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // make sure that block vector iterator allows reading and writing correctly + + #include "../tests.h" + #include + #include + #include + + + void test () + { + PETScWrappers::BlockVector v(2,1); + v(0) = 1; + v(1) = 2; + + // first check reading through a const + // iterator + { + PETScWrappers::BlockVector::const_iterator i=v.begin(); + Assert (*i == 1, ExcInternalError()); + ++i; + Assert (*i == 2, ExcInternalError()); + } + + // same, but create iterator in a different + // way + { + PETScWrappers::BlockVector::const_iterator + i=const_cast(v).begin(); + Assert (*i == 1, ExcInternalError()); + ++i; + Assert (*i == 2, ExcInternalError()); + } + + // read through a read-write iterator + { + PETScWrappers::BlockVector::iterator i = v.begin(); + Assert (*i == 1, ExcInternalError()); + ++i; + Assert (*i == 2, ExcInternalError()); + } + + // write through a read-write iterator + { + PETScWrappers::BlockVector::iterator i = v.begin(); + + *i = 2; + ++i; + *i = 3; + } + + // and read again + { + PETScWrappers::BlockVector::iterator i = v.begin(); + Assert (*i == 2, ExcInternalError()); + ++i; + Assert (*i == 3, ExcInternalError()); + } + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + test (); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/block_vector_iterator_02.cc index 0000000000,117bc79696..79e5b7ef72 mode 000000,100644..100644 --- a/tests/petsc/block_vector_iterator_02.cc +++ b/tests/petsc/block_vector_iterator_02.cc @@@ -1,0 -1,115 +1,115 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: block_vector_iterator_02.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // like _01, except that we use operator[] instead of operator* + + #include "../tests.h" + #include + #include + #include + + + void test () + { + PETScWrappers::BlockVector v(2,1); + v(0) = 1; + v(1) = 2; + + // first check reading through a const + // iterator + { + PETScWrappers::BlockVector::const_iterator i=v.begin(); + Assert (i[0] == 1, ExcInternalError()); + Assert (i[1] == 2, ExcInternalError()); + } + + // same, but create iterator in a different + // way + { + PETScWrappers::BlockVector::const_iterator + i=const_cast(v).begin(); + Assert (i[0] == 1, ExcInternalError()); + Assert (i[1] == 2, ExcInternalError()); + } + + // read through a read-write iterator + { + PETScWrappers::BlockVector::iterator i = v.begin(); + Assert (i[0] == 1, ExcInternalError()); + Assert (i[1] == 2, ExcInternalError()); + } + + // write through a read-write iterator + { + PETScWrappers::BlockVector::iterator i = v.begin(); + i[0] = 2; + i[1] = 3; + } + + // and read again + { + PETScWrappers::BlockVector::iterator i = v.begin(); + Assert (i[0] == 2, ExcInternalError()); + Assert (i[1] == 3, ExcInternalError()); + } + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + test (); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/block_vector_iterator_03.cc index 0000000000,8ed06ee623..efdf599c47 mode 000000,100644..100644 --- a/tests/petsc/block_vector_iterator_03.cc +++ b/tests/petsc/block_vector_iterator_03.cc @@@ -1,0 -1,370 +1,370 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: block_vector_iterator_03.cc 31349 2013-10-20 19:07:06Z maier $ + // + // Copyright (C) 2000 - 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. + // + // --------------------------------------------------------------------- + + + // this test is an adaptation of lac/block_vector_iterator for PETSc block + // vectors + + #include "../tests.h" + #include + #include + #include + #include + #include + #include + #include + #include + #include + + template + bool operator == (const PETScWrappers::BlockVector &v1, + const PETScWrappers::BlockVector &v2) + { + if (v1.size() != v2.size()) + return false; + for (unsigned int i=0; i ivector(4); + ivector[0] = 2; + ivector[1] = 4; + ivector[2] = 3; + ivector[3] = 5; + + // Check 1: initialization via + // iterators + if (true) + { + PETScWrappers::BlockVector v1(ivector); + PETScWrappers::BlockVector v2(ivector); + + // initialize first vector with + // simple loop + for (unsigned int i=0; i(v1.size()) ? + "true" : "false") + << std::endl; + + // check std::copy + PETScWrappers::BlockVector v2(ivector); + std::copy (v1.begin(), v1.end(), v2.begin()); + deallog << "Check 6: " << (v1 == v2 ? "true" : "false") << std::endl; + + // check std::transform + std::transform (v1.begin(), v1.end(), v2.begin(), + std::bind2nd (std::multiplies(), + 2.0)); + v2 *= 1./2.; + deallog << "Check 7: " << (v1 == v2 ? "true" : "false") << std::endl; + + + // check operators +/-, +=/-= + deallog << "Check 8: " + << (std::distance(v1.begin(), v1.begin()+3) == 3 ? + "true" : "false") + << std::endl; + deallog << "Check 9: " + << (std::distance(v1.end()-6, v1.end()) == 6 ? + "true" : "false") + << std::endl; + deallog << "Check 10: " + << (std::distance(v1.begin(), v1.end()) == (signed)v1.size() ? + "true" : "false") + << std::endl; + deallog << "Check 11: " + << (std::distance(v1.begin(), (v1.begin()+=7)) == 7 ? + "true" : "false") + << std::endl; + deallog << "Check 12: " + << (std::distance((v1.end()-=4), v1.end()) == 4 ? + "true" : "false") + << std::endl; + + // check advance + PETScWrappers::BlockVector::iterator p2 = v1.begin(); + std::advance (p2, v1.size()); + deallog << "Check 13: " << (p2 == v1.end() ? "true" : "false") << std::endl; + + PETScWrappers::BlockVector::const_iterator p3 = v1.begin(); + std::advance (p3, v1.size()); + deallog << "Check 14: " << (p3 == v1.end() ? "true" : "false") << std::endl; + }; + + // Check 15: initialization through + // iterators + if (true) + { + PETScWrappers::BlockVector v1(ivector); + // initialize first vector with + // simple loop + for (unsigned int i=0; i v2(v1.begin(), v1.end()); + + // and reverse way + PETScWrappers::BlockVector v3(ivector, v2.begin(), v2.end()); + deallog << "Check 15: " << (v1==v3 ? "true" : "false") << std::endl; + }; + + // Check 16: initialization through + // iterators. variant with one + // constant object + if (true) + { + PETScWrappers::BlockVector v1(ivector); + // initialize first vector with + // simple loop + for (unsigned int i=0; i v2(v1.begin(), v1.end()); + + // and reverse way + PETScWrappers::BlockVector v3(ivector, v2.begin(), v2.end()); + deallog << "Check 16: " << (v1==v3 ? "true" : "false") << std::endl; + }; + + // Check 17: initialization through + // iterators. variant with two + // constant object + if (true) + { + PETScWrappers::BlockVector v1(ivector); + // initialize first vector with + // simple loop + for (unsigned int i=0; i v2(v1.begin(), v1.end()); + + // and reverse way + const PETScWrappers::BlockVector v3(ivector, v2.begin(), v2.end()); + deallog << "Check 17: " << (v1==v3 ? "true" : "false") << std::endl; + }; + + // Check 18: initialization through + // iterators. variant with three + // constant object + if (true) + { + PETScWrappers::BlockVector v0(ivector); + // initialize first vector with + // simple loop + for (unsigned int i=0; i v2(v1.begin(), v1.end()); + + // and reverse way + const PETScWrappers::BlockVector v3(ivector, v2.begin(), v2.end()); + deallog << "Check 18: " << (v1==v3 ? "true" : "false") << std::endl; + }; + + // Check 19: operator[] + if (true) + { + PETScWrappers::BlockVector v1(ivector); + for (unsigned int i=0; i + #include + #include + #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 (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("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 (); + f.compress (); + u.compress (); + + GrowingVectorMemory mem; + SolverCG solver(control,mem); + PreconditionIdentity preconditioner; + check_solve (solver, A,u,f, preconditioner); + } + GrowingVectorMemory::release_unused_memory (); + + } + diff --cc tests/petsc/deal_solver_02.cc index 0000000000,46f04c6fa5..4956cb16fc mode 000000,100644..100644 --- a/tests/petsc/deal_solver_02.cc +++ b/tests/petsc/deal_solver_02.cc @@@ -1,0 -1,103 +1,103 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: deal_solver_02.cc 31349 2013-10-20 19:07:06Z 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 BiCGStab solver using the PETSc matrix and vector classes + + + + #include "../tests.h" + #include "../lac/testmatrix.h" + #include + #include + #include + #include + #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 (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("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-10); + + 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 (); + f.compress (); + u.compress (); + + GrowingVectorMemory mem; + SolverBicgstab solver(control,mem); + PreconditionIdentity preconditioner; + check_solve (solver, A,u,f, preconditioner); + } + GrowingVectorMemory::release_unused_memory (); + + } + diff --cc tests/petsc/deal_solver_03.cc index 0000000000,831ebb38ec..186e427779 mode 000000,100644..100644 --- a/tests/petsc/deal_solver_03.cc +++ b/tests/petsc/deal_solver_03.cc @@@ -1,0 -1,103 +1,103 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: deal_solver_03.cc 31349 2013-10-20 19:07:06Z 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 GMRES solver using the PETSc matrix and vector classes + + + + #include "../tests.h" + #include "../lac/testmatrix.h" + #include + #include + #include + #include + #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 (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("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 (); + f.compress (); + u.compress (); + + GrowingVectorMemory mem; + SolverGMRES solver(control,mem); + PreconditionIdentity preconditioner; + check_solve (solver, A,u,f, preconditioner); + } + GrowingVectorMemory::release_unused_memory (); + + } + diff --cc tests/petsc/deal_solver_04.cc index 0000000000,f4a88b8bc4..78354c3fba mode 000000,100644..100644 --- a/tests/petsc/deal_solver_04.cc +++ b/tests/petsc/deal_solver_04.cc @@@ -1,0 -1,102 +1,102 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: deal_solver_04.cc 31349 2013-10-20 19:07:06Z 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 MINRES solver using the PETSc matrix and vector classes + + + #include "../tests.h" + #include "../lac/testmatrix.h" + #include + #include + #include + #include + #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 (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("output"); + logfile.precision(4); + deallog.attach(logfile); + 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 (); + f.compress (); + u.compress (); + + GrowingVectorMemory mem; + SolverMinRes solver(control,mem); + PreconditionIdentity preconditioner; + check_solve (solver, A,u,f, preconditioner); + } + GrowingVectorMemory::release_unused_memory (); + + } + diff --cc tests/petsc/deal_solver_05.cc index 0000000000,033b498db6..4df0110708 mode 000000,100644..100644 --- a/tests/petsc/deal_solver_05.cc +++ b/tests/petsc/deal_solver_05.cc @@@ -1,0 -1,101 +1,101 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: deal_solver_05.cc 31349 2013-10-20 19:07:06Z 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 QMRS solver using the PETSc matrix and vector classes + + + #include "../tests.h" + #include "../lac/testmatrix.h" + #include + #include + #include + #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 (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("output"); + logfile.precision(4); + deallog.attach(logfile); + 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 (); + f.compress (); + u.compress (); + + GrowingVectorMemory mem; + SolverQMRS solver(control,mem); + PreconditionIdentity preconditioner; + check_solve (solver, A,u,f, preconditioner); + } + GrowingVectorMemory::release_unused_memory (); + + } + diff --cc tests/petsc/full_matrix_01.cc index 0000000000,6125db2d92..6eef69a87b mode 000000,100644..100644 --- a/tests/petsc/full_matrix_01.cc +++ b/tests/petsc/full_matrix_01.cc @@@ -1,0 -1,97 +1,97 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: full_matrix_01.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check setting elements in a petsc matrix using + // PETScWrappers::FullMatrix::set() + + #include "../tests.h" + #include + #include + #include + + + void test (PETScWrappers::FullMatrix &m) + { + // first set a few entries + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::FullMatrix &m) + { + // first set a few entries + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::FullMatrix &m) + { + Assert (m.m() == 5, ExcInternalError()); + Assert (m.n() == 5, ExcInternalError()); + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + PETScWrappers::FullMatrix m (5,5); + test (m); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/full_matrix_05.cc index 0000000000,36851aa8fc..f4566f42ad mode 000000,100644..100644 --- a/tests/petsc/full_matrix_05.cc +++ b/tests/petsc/full_matrix_05.cc @@@ -1,0 -1,93 +1,93 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: full_matrix_05.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check querying the number of nonzero elements in + // PETScWrappers::FullMatrix + + #include "../tests.h" + #include + #include + #include + + + void test (PETScWrappers::FullMatrix &m) + { + // first set a few entries. count how many + // entries we have + unsigned int counter = 0; + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::FullMatrix &m) + { + // first set a few entries. count how many + // entries we have + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::FullMatrix &m) + { + // first set a few entries. count how many + // entries we have + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::FullMatrix &m) + { + // first set a few entries. count how many + // entries we have + PetscScalar norm = 0; + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::FullMatrix &m) + { + // first set a few entries + for (unsigned int i=0; i + #include + #include + + + void test (PETScWrappers::FullMatrix &m) + { + // first set a few entries + for (unsigned int i=0; i + #include + #include + + + void test () + { + PETScWrappers::FullMatrix m(5,5); + m.set (0,0,1); + m.set (1,1,2); + m.set (1,2,3); + m.compress (); + PETScWrappers::FullMatrix::const_iterator i = m.begin(); + deallog << i->row() << ' ' << i->column() << ' ' << i->value() << std::endl; + ++i; + deallog << i->row() << ' ' << i->column() << ' ' << i->value() << std::endl; + i++; + deallog << i->row() << ' ' << i->column() << ' ' << i->value() << std::endl; + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + test (); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/full_matrix_vector_01.cc index 0000000000,daabd47328..efabc33eef mode 000000,100644..100644 --- a/tests/petsc/full_matrix_vector_01.cc +++ b/tests/petsc/full_matrix_vector_01.cc @@@ -1,0 -1,104 +1,104 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: full_matrix_vector_01.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check FullMatrix::vmult + + #include "../tests.h" + #include + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + PETScWrappers::FullMatrix m(v.size(),v.size()); + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + PETScWrappers::FullMatrix m(v.size(),v.size()); + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + PETScWrappers::FullMatrix m(v.size(),v.size()); + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + PETScWrappers::FullMatrix m(v.size(),v.size()); + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + PETScWrappers::FullMatrix m(v.size(),v.size()); + for (unsigned int i=0; i + const PetscScalar s = m.matrix_scalar_product (w,v); + + // make sure we get the expected result + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + PETScWrappers::FullMatrix m(v.size(),v.size()); + for (unsigned int i=0; i + const PetscScalar s = m.matrix_norm_square (v); + + // make sure we get the expected result + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w, + PETScWrappers::Vector &x) + { + PETScWrappers::FullMatrix m(v.size(),v.size()); + for (unsigned int i=0; i + #include + #include + #include + + + unsigned int + get_n_mpi_processes () + { + int n_jobs; + MPI_Comm_size (MPI_COMM_WORLD, &n_jobs); + + return n_jobs; + } + + + + unsigned int + get_this_mpi_process () + { + int rank; + MPI_Comm_rank (MPI_COMM_WORLD, &rank); + + return rank; + } + + + void test () + { + typedef PETScWrappers::MPI::SparseMatrix::size_type size_type; + + // create a parallel matrix where the first + // process has 10 rows, the second one 20, + // the third one 30, and so on + unsigned int N = 0; + std::vector local_rows_per_process (get_n_mpi_processes()); + std::vector start_row (get_n_mpi_processes()); + for (unsigned int i=0; i local_rows_per_process.back()) + csp.add (i,i-local_rows_per_process.back()); + } + + // here is a sparsity pattern for which no + // Inodes are used, but it doesn't allocate + // additional memory + // for (unsigned int bi=0; bi + #include + #include + #include + + // A variant of the tests/lac/testmatrix.h file that uses the PETSc + // matrix free interface + + + /** + * Finite difference PETSc matrix-free object on uniform grid. + * Generator for simple 5-point discretization of Laplace problem. + */ + + class PetscFDMatrix : public dealii::PETScWrappers::MatrixFree + { + public: + /** + * Constructor specifying grid resolution. + */ + PetscFDMatrix(unsigned int size, unsigned int dim); + + /** + * Matrix-vector multiplication: + * let dst = M*src with + * M being this matrix. + * + * Source and destination must + * not be the same vector. + */ + void vmult (dealii::PETScWrappers::VectorBase &dst, + const dealii::PETScWrappers::VectorBase &src) const; + + /** + * Matrix-vector multiplication: let + * dst = MT*src with + * M being this matrix. This + * function does the same as @p vmult() + * but takes the transposed matrix. + * + * Source and destination must + * not be the same vector. + */ + void Tvmult (dealii::PETScWrappers::VectorBase &dst, + const dealii::PETScWrappers::VectorBase &src) const; + + /** + * Adding Matrix-vector + * multiplication. Add + * M*src on dst + * with M being this + * matrix. + * + * Source and destination must + * not be the same vector. + */ + void vmult_add (dealii::PETScWrappers::VectorBase &dst, + const dealii::PETScWrappers::VectorBase &src) const; + + /** + * Adding Matrix-vector + * multiplication. Add + * MT*src to + * dst with M being + * this matrix. This function + * does the same as @p vmult_add() + * but takes the transposed + * matrix. + * + * Source and destination must + * not be the same vector. + */ + void Tvmult_add (dealii::PETScWrappers::VectorBase &dst, + const dealii::PETScWrappers::VectorBase &src) const; + + private: + /** + * Number of gridpoints in x-direction. + */ + unsigned int nx; + + /** + * Number of gridpoints in y-direction. + */ + unsigned int ny; + }; + + + // --------------- inline and template functions ----------------- + + inline + PetscFDMatrix::PetscFDMatrix(unsigned int size, unsigned int dim) + : PETScWrappers::MatrixFree (dim, dim, dim, dim), + nx (size), ny (size) + {} + + + + inline + void + PetscFDMatrix::vmult_add (dealii::PETScWrappers::VectorBase &dst, + const dealii::PETScWrappers::VectorBase &src) const + { + for (unsigned int i=0; i<=ny-2; i++) + { + for (unsigned int j=0; j<=nx-2; j++) + { + // Number of the row to be entered + unsigned int row = j+(nx-1)*i; + + dst(row) += 4. * src(row); // A.set(row, row, 4.); + + if (j>0) + { + dst(row-1) += -1. * src(row); // A.set(row-1, row, -1.); + dst(row) += -1. * src(row-1); // A.set(row, row-1, -1.); + } + if (i>0) + { + dst(row-(nx-1)) += -1. * src(row); // A.set(row-(nx-1), row, -1.); + dst(row) += -1. * src(row-(nx-1)); // A.set(row, row-(nx-1), -1.); + } + } + } + } + + + + inline + void + PetscFDMatrix::vmult (dealii::PETScWrappers::VectorBase &dst, + const dealii::PETScWrappers::VectorBase &src) const + { + dst = 0; + vmult_add (dst, src); + } + + + + inline + void + PetscFDMatrix::Tvmult (dealii::PETScWrappers::VectorBase &dst, + const dealii::PETScWrappers::VectorBase &src) const + { + dst = 0; + vmult_add (dst, src); + } + + + + inline + void + PetscFDMatrix::Tvmult_add (dealii::PETScWrappers::VectorBase &dst, + const dealii::PETScWrappers::VectorBase &src) const + { + vmult_add (dst, src); + } + + diff --cc tests/petsc/slowness_01.cc index 0000000000,7290ec6caa..38cd2ad60d mode 000000,100644..100644 --- a/tests/petsc/slowness_01.cc +++ b/tests/petsc/slowness_01.cc @@@ -1,0 -1,149 +1,149 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: slowness_01.cc 31349 2013-10-20 19:07:06Z maier $ + // + // Copyright (C) 2005 - 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. + // + // --------------------------------------------------------------------- + + + + // this is part of a whole suite of tests that checks the relative speed of + // using PETSc for sparse matrices as compared to the speed of our own + // library. the tests therefore may not all actually use PETSc, but they are + // meant to compare it + // + // the tests build the 5-point stencil matrix for a uniform grid of size N*N + + #include "../tests.h" + #include + #include + #include + #include + #include + + + void test () + { + const unsigned int N = 200; + + // first build the sparsity pattern + SparsityPattern sparsity (N*N, N*N, 5); + for (unsigned int i=0; i0) + { + sparsity.add(global-1, global); + sparsity.add(global, global-1); + } + if (j0) + { + sparsity.add(global-N, global); + sparsity.add(global, global-N); + } + if (i matrix (sparsity); + for (unsigned int i=0; i0) + { + matrix.add(global-1, global, -1); + matrix.add(global, global-1, -1); + } + if (j0) + { + matrix.add(global-N, global, -1); + matrix.add(global, global-N, -1); + } + if (i v1(N*N), v2(N*N); + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test () + { + const unsigned int N = 200; + + // build the sparse matrix + PETScWrappers::SparseMatrix matrix (N*N, N*N, 5); + for (unsigned int i=0; i0) + { + matrix.add(global-1, global, -1); + matrix.add(global, global-1, -1); + } + if (j0) + { + matrix.add(global-N, global, -1); + matrix.add(global, global-N, -1); + } + if (i + #include + #include + #include + #include + + + void test () + { + const unsigned int N = 200; + + // build the sparse matrix + PETScWrappers::MPI::SparseMatrix matrix (PETSC_COMM_WORLD, + N*N, N*N, + N*N, N*N, + 5); + for (unsigned int i=0; i0) + { + matrix.add(global-1, global, -1); + matrix.add(global, global-1, -1); + } + if (j0) + { + matrix.add(global-N, global, -1); + matrix.add(global, global-N, -1); + } + if (i + #include + #include + #include + #include + + + void test () + { + const unsigned int N = 200; + + // first find a random permutation of the + // indices + std::vector permutation (N); + { + std::vector unused_indices (N); + for (unsigned int i=0; i0) + { + matrix.add(global-1, global, rand()); + matrix.add(global, global-1, rand()); + } + if (j0) + { + matrix.add(global-N, global, rand()); + matrix.add(global, global-N, rand()); + } + if (i + #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); + + 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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverRichardson solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_02.cc index 0000000000,baf08b9793..a4c0ba388e mode 000000,100644..100644 --- a/tests/petsc/solver_02.cc +++ b/tests/petsc/solver_02.cc @@@ -1,0 -1,93 +1,93 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_02.cc 31349 2013-10-20 19:07:06Z 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 Chebychev solver + + + #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 (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); + + 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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverChebychev solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_03.cc index 0000000000,57b908cc00..5fbdca2b27 mode 000000,100644..100644 --- a/tests/petsc/solver_03.cc +++ b/tests/petsc/solver_03.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_03.cc 31349 2013-10-20 19:07:06Z 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 + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_03_mf.cc index 0000000000,84428afb54..abd162aeab mode 000000,100644..100644 --- a/tests/petsc/solver_03_mf.cc +++ b/tests/petsc/solver_03_mf.cc @@@ -1,0 -1,92 +1,92 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_03_mf.cc 31349 2013-10-20 19:07:06Z 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 + + + #include "../tests.h" + #include "petsc_mf_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) + { + 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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionNone preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_03_precondition_boomeramg.cc index 0000000000,8c452a78b1..9063e66030 mode 000000,100644..100644 --- a/tests/petsc/solver_03_precondition_boomeramg.cc +++ b/tests/petsc/solver_03_precondition_boomeramg.cc @@@ -1,0 -1,95 +1,95 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_03_precondition_boomeramg.cc 31349 2013-10-20 19:07:06Z 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 the PreconditionBoomerAMG + // preconditioner + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionBoomerAMG preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_03_precondition_boomeramg_symmetric.cc index 0000000000,73a442f1a5..24bca339ea mode 000000,100644..100644 --- a/tests/petsc/solver_03_precondition_boomeramg_symmetric.cc +++ b/tests/petsc/solver_03_precondition_boomeramg_symmetric.cc @@@ -1,0 -1,96 +1,96 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_03_precondition_boomeramg_symmetric.cc 31349 2013-10-20 19:07:06Z 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 the PreconditionBoomerAMG + // preconditioner. allow the preconditioner to exploit symmetry of the + // matrix + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionBoomerAMG preconditioner(A, true); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_03_precondition_eisenstat.cc index 0000000000,6551a25c05..767429cb03 mode 000000,100644..100644 --- a/tests/petsc/solver_03_precondition_eisenstat.cc +++ b/tests/petsc/solver_03_precondition_eisenstat.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_03_precondition_eisenstat.cc 31349 2013-10-20 19:07:06Z 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 + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionEisenstat preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_03_precondition_icc.cc index 0000000000,6849d74979..80ce3747f7 mode 000000,100644..100644 --- a/tests/petsc/solver_03_precondition_icc.cc +++ b/tests/petsc/solver_03_precondition_icc.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_03_precondition_icc.cc 31349 2013-10-20 19:07:06Z 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 + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionICC preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_03_precondition_ilu.cc index 0000000000,faad508f0a..1dab2d8631 mode 000000,100644..100644 --- a/tests/petsc/solver_03_precondition_ilu.cc +++ b/tests/petsc/solver_03_precondition_ilu.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_03_precondition_ilu.cc 31349 2013-10-20 19:07:06Z 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 + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionILU preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_03_precondition_lu.cc index 0000000000,beabcf434a..dcc93aa586 mode 000000,100644..100644 --- a/tests/petsc/solver_03_precondition_lu.cc +++ b/tests/petsc/solver_03_precondition_lu.cc @@@ -1,0 -1,101 +1,101 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_03_precondition_lu.cc 31349 2013-10-20 19:07:06Z 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 the PreconditionLU + // preconditioner. This should converge in exactly one iteration + + + #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; + + // we use a direct solver as a + // preconditioner. this should + // converge in one step! + Assert (solver.control().last_step() == 1, + ExcInternalError()); + } + + + 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); + + 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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionLU preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_03_precondition_parasails.cc index 0000000000,05ffee26f7..5b0ea95b21 mode 000000,100644..100644 --- a/tests/petsc/solver_03_precondition_parasails.cc +++ b/tests/petsc/solver_03_precondition_parasails.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_03_precondition_parasails.cc 31349 2013-10-20 19:07:06Z 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 + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionParaSails preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_03_precondition_sor.cc index 0000000000,f0700eebc5..af7be7a3ff mode 000000,100644..100644 --- a/tests/petsc/solver_03_precondition_sor.cc +++ b/tests/petsc/solver_03_precondition_sor.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_03_precondition_sor.cc 31349 2013-10-20 19:07:06Z 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 + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionSOR preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_03_precondition_ssor.cc index 0000000000,67fd339d47..cf01bc3f1d mode 000000,100644..100644 --- a/tests/petsc/solver_03_precondition_ssor.cc +++ b/tests/petsc/solver_03_precondition_ssor.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_03_precondition_ssor.cc 31349 2013-10-20 19:07:06Z 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 + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionSSOR preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_04.cc index 0000000000,2d9819fba4..4db245a1b6 mode 000000,100644..100644 --- a/tests/petsc/solver_04.cc +++ b/tests/petsc/solver_04.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_04.cc 31349 2013-10-20 19:07:06Z 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 BiCG solver + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverBiCG solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_05.cc index 0000000000,15f6466e8c..98561a2c5a mode 000000,100644..100644 --- a/tests/petsc/solver_05.cc +++ b/tests/petsc/solver_05.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_05.cc 31349 2013-10-20 19:07:06Z 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 GMRES solver + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverGMRES solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_06.cc index 0000000000,e19bddaf0c..6500756f50 mode 000000,100644..100644 --- a/tests/petsc/solver_06.cc +++ b/tests/petsc/solver_06.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_06.cc 31349 2013-10-20 19:07:06Z 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 Bicgstab solver + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverBicgstab solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_07.cc index 0000000000,12d44a6ae2..947b584db2 mode 000000,100644..100644 --- a/tests/petsc/solver_07.cc +++ b/tests/petsc/solver_07.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_07.cc 31349 2013-10-20 19:07:06Z 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 CGS solver + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCGS solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_08.cc index 0000000000,56b38ef60d..fbad082117 mode 000000,100644..100644 --- a/tests/petsc/solver_08.cc +++ b/tests/petsc/solver_08.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_08.cc 31349 2013-10-20 19:07:06Z 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 TFQMR solver + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverTFQMR solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_09.cc index 0000000000,3297bd8fe2..3b52a48e3d mode 000000,100644..100644 --- a/tests/petsc/solver_09.cc +++ b/tests/petsc/solver_09.cc @@@ -1,0 -1,98 +1,98 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_09.cc 31349 2013-10-20 19:07:06Z 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 TCQMR solver + // + // note that this test fails on PETSc 2.1.6 due to a bug in the TCQMR + // implementation. this is reported and should be fixed soonish + + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverTCQMR solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_10.cc index 0000000000,df81e7dbd2..488b11300e mode 000000,100644..100644 --- a/tests/petsc/solver_10.cc +++ b/tests/petsc/solver_10.cc @@@ -1,0 -1,94 +1,94 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_10.cc 31349 2013-10-20 19:07:06Z 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 CR solver + + + #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("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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverCR solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_11.cc index 0000000000,a7e585eb33..9fff4d6cea mode 000000,100644..100644 --- a/tests/petsc/solver_11.cc +++ b/tests/petsc/solver_11.cc @@@ -1,0 -1,95 +1,95 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_11.cc 31349 2013-10-20 19:07:06Z 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 LSQR solver + + + #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 (dealii::SolverControl::NoConvergence &e) + { + // just like for Richardson: expect to + // get here, don't abort the program + deallog << "Catched exception dealii::SolverControl::NoConvergence" << 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); + + 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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverLSQR solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_12.cc index 0000000000,79e44183a9..f2d0ba07d8 mode 000000,100644..100644 --- a/tests/petsc/solver_12.cc +++ b/tests/petsc/solver_12.cc @@@ -1,0 -1,91 +1,91 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_12.cc 31349 2013-10-20 19:07:06Z 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 PreOnly solver + + + #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.; + + solver.solve(A,u,f,P); + + 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); + + 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 (); + f.compress (); + u.compress (); + + PETScWrappers::SolverPreOnly solver(control); + + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + + //run twice because this errored out at some point + check_solve (solver, A,u,f, preconditioner); + } + + } + diff --cc tests/petsc/solver_13.cc index 0000000000,b28e88cafe..e77d2044f3 mode 000000,100644..100644 --- a/tests/petsc/solver_13.cc +++ b/tests/petsc/solver_13.cc @@@ -1,0 -1,100 +1,100 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: solver_13.cc 31349 2013-10-20 19:07:06Z 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 PETScWrapper::Precondition*::vmult + + + #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; + + solver.solve(A,u,f,P); + + 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); + + 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); + u = 0.; + f = 1.; + A.compress (); + f.compress (); + u.compress (); + PETScWrappers::Vector t=u; + + PETScWrappers::SolverPreOnly solver(control); + + PETScWrappers::PreconditionJacobi preconditioner(A); + + check_solve (solver, A,u,f, preconditioner); + + deallog << u.l2_norm() << std::endl; + + check_solve (solver, A,t,u, preconditioner); + + deallog << t.l2_norm() << std::endl; + + u = 0; + preconditioner.vmult(u, f); + deallog << u.l2_norm() << std::endl; + preconditioner.vmult(t, u); + deallog << t.l2_norm() << std::endl; + } + + } + diff --cc tests/petsc/sparse_direct_mumps.cc index 0000000000,01956e4e02..6a60135011 mode 000000,100644..100644 --- a/tests/petsc/sparse_direct_mumps.cc +++ b/tests/petsc/sparse_direct_mumps.cc @@@ -1,0 -1,98 +1,98 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: sparse_direct_mumps.cc 31349 2013-10-20 19:07:06Z 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 SparseDirectMumps solver + + + #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("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); + { + 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); + u = 0.; + f = 1.; + A.compress (); + f.compress (); + u.compress (); + + SolverControl cn; + PETScWrappers::SparseDirectMUMPS solver(cn); + // solver.set_symmetric_mode(true); + solver.solve(A,u,f); + + PETScWrappers::Vector tmp(dim); + deallog << "residual = " << A.residual (tmp, u, f) + << std::endl; + } + + } + diff --cc tests/petsc/sparse_matrix_iterator_01.cc index 0000000000,b070cc721c..bc6e0143cb mode 000000,100644..100644 --- a/tests/petsc/sparse_matrix_iterator_01.cc +++ b/tests/petsc/sparse_matrix_iterator_01.cc @@@ -1,0 -1,85 +1,85 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: sparse_matrix_iterator_01.cc 31349 2013-10-20 19:07:06Z 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 PETScWrappers::MatrixBase::const_iterator + + #include "../tests.h" + #include + #include + #include + + + void test () + { + PETScWrappers::SparseMatrix m(5,5,5); + m.set (0,0,1); + m.set (1,1,2); + m.set (1,2,3); + m.compress (); + PETScWrappers::SparseMatrix::const_iterator i = m.begin(); + deallog << i->row() << ' ' << i->column() << ' ' << i->value() << std::endl; + ++i; + deallog << i->row() << ' ' << i->column() << ' ' << i->value() << std::endl; + i++; + deallog << i->row() << ' ' << i->column() << ' ' << i->value() << std::endl; + + deallog << "OK" << std::endl; + } + + + + int main (int argc,char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + test (); + } + + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + } diff --cc tests/petsc/sparse_matrix_vector_01.cc index 0000000000,6562499418..9bf41c0d4d mode 000000,100644..100644 --- a/tests/petsc/sparse_matrix_vector_01.cc +++ b/tests/petsc/sparse_matrix_vector_01.cc @@@ -1,0 -1,104 +1,104 @@@ + // --------------------------------------------------------------------- -// $Id$ ++// $Id: sparse_matrix_vector_01.cc 31349 2013-10-20 19:07:06Z 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. + // + // --------------------------------------------------------------------- + + + + // check SparseMatrix::vmult + + #include "../tests.h" + #include + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + PETScWrappers::SparseMatrix m(v.size(),v.size(),v.size()); + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + PETScWrappers::SparseMatrix m(v.size(),v.size(),v.size()); + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + PETScWrappers::SparseMatrix m(v.size(),v.size(),v.size()); + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + PETScWrappers::SparseMatrix m(v.size(),v.size(),v.size()); + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + PETScWrappers::SparseMatrix m(v.size(),v.size(),v.size()); + for (unsigned int i=0; i + const PetscScalar s = m.matrix_scalar_product (w,v); + + // make sure we get the expected result + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v) + { + PETScWrappers::SparseMatrix m(v.size(),v.size(),v.size()); + for (unsigned int i=0; i + const PetscScalar s = m.matrix_norm_square (v); + + // make sure we get the expected result + for (unsigned int i=0; i + #include + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w, + PETScWrappers::Vector &x) + { + PETScWrappers::SparseMatrix m(v.size(),v.size(),v.size()); + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + // set the first vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + // set the first vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + // set only certain elements of each + // vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + // set only certain elements of each + // vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + // set only certain elements of each + // vector + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + // set only certain elements of each + // vector + for (unsigned int i=0; i + #include + #include + #include + + + int main (int argc, char **argv) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + { + PETScWrappers::Vector v (5); + for (unsigned int i=0; i + #include + #include + #include + + + void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) + { + // set the first vector + for (unsigned int i=0; i