From: young Date: Fri, 18 Oct 2013 10:08:30 +0000 (+0000) Subject: A set of tests that check real and complex parts of PETSc matrices. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec39229b621eacb73661344baf640cf38d457a38;p=dealii-svn.git A set of tests that check real and complex parts of PETSc matrices. git-svn-id: https://svn.dealii.org/branches/branch_petscscalar_complex@31295 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/petsc_scalar_complex/00-manipulate_petsc_scalar.cc b/tests/petsc_scalar_complex/00-manipulate_petsc_scalar.cc index 5cab80c1d2..3d490f1140 100644 --- a/tests/petsc_scalar_complex/00-manipulate_petsc_scalar.cc +++ b/tests/petsc_scalar_complex/00-manipulate_petsc_scalar.cc @@ -13,13 +13,13 @@ // PetscScalar in accordance with gcc.gnu.org bug 7263. // deal.II includes +#include "../tests.h" #include #include #include #include -#ifdef PETSC_USE_COMPLEX std::ofstream logfile ("00-manipulate_petsc_scalar/output"); @@ -52,7 +52,7 @@ void divide_petsc_complex_by_a_number () << " should be 0.5+1i" << std::endl; - assert (alpha==beta); + Assert (alpha==beta, ExcInternalError()); } // Initialize a std::complex number from an PETSc complex number @@ -67,8 +67,7 @@ void make_std_complex_from_petsc_complex () << "i" << std::endl; - // even this works - assert (alpha==beta); + Assert (alpha==beta, ExcInternalError()); } // Initialize a PETSc complex number from an std::complex number @@ -83,7 +82,7 @@ void make_petsc_complex_from_std_complex () << "i" << std::endl; - assert (alpha==beta); + Assert (alpha==beta, ExcInternalError()); } // Initialize a PETSc complex number directly. @@ -97,6 +96,8 @@ void make_petsc_complex () << "i" << " should be 1+2i" << std::endl; + + Assert (alpha==std::complex (1.,2.), ExcInternalError()); } @@ -122,7 +123,7 @@ void init_petsc_complex () << " should be 0+0i" << std::endl; - assert (alpha==beta); + Assert (alpha==beta, ExcInternalError()); } int main (int argc, char **argv) @@ -215,4 +216,4 @@ int main (int argc, char **argv) return 0; } -#endif // PETSC_USE_COMPLEX + diff --git a/tests/petsc_scalar_complex/01.cc b/tests/petsc_scalar_complex/01.cc new file mode 100644 index 0000000000..28d71cc34c --- /dev/null +++ b/tests/petsc_scalar_complex/01.cc @@ -0,0 +1,133 @@ +// --------------------------------------------------------------------- +// $Id: +// +// Copyright (C) 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check setting elements in a petsc matrix using +// PETScWrappers::SparseMatrix::set() + +#include "../tests.h" +#include +#include +#include + + +void test_real (PETScWrappers::SparseMatrix &m) +{ + deallog << "Real test" << std::endl; + + // first set a few entries + for (unsigned int i=0; i (i*j*.5+.5,0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex (i*j*.5+.5,0.), ExcInternalError()); + } + else + { + Assert (m(i,j) == std::complex (0.,0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex (0.,0.), ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + +void test_complex (PETScWrappers::SparseMatrix &m) +{ + deallog << "Complex test" << std::endl; + + // first set a few entries + for (unsigned int i=0; i (0.,i*j*.5+.5)); + + m.compress (VectorOperation::add); + + // then make sure we retrieve the same ones + for (unsigned int i=0; i (0.,i*j*.5+.5), ExcInternalError()); + Assert (m.el(i,j) == std::complex (0.,i*j*.5+.5), ExcInternalError()); + } + else + { + Assert (m(i,j) == std::complex (0.,0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex (0.,0.), ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int main (int argc,char **argv) +{ + std::ofstream logfile("01/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; + + m.reinit (5,5,3); + test_real (m); + + m.reinit (5,5,3); + test_complex (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 --git a/tests/petsc_scalar_complex/01/cmp/generic b/tests/petsc_scalar_complex/01/cmp/generic new file mode 100644 index 0000000000..d2ebc39535 --- /dev/null +++ b/tests/petsc_scalar_complex/01/cmp/generic @@ -0,0 +1,5 @@ + +DEAL::Real test +DEAL::OK +DEAL::Complex test +DEAL::OK diff --git a/tests/petsc_scalar_complex/02.cc b/tests/petsc_scalar_complex/02.cc new file mode 100644 index 0000000000..064e47b347 --- /dev/null +++ b/tests/petsc_scalar_complex/02.cc @@ -0,0 +1,134 @@ +// --------------------------------------------------------------------- +// $Id: +// +// 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::add() + +#include "../tests.h" +#include +#include +#include + + +void test_real (PETScWrappers::SparseMatrix &m) +{ + deallog << "Real test" << std::endl; + + // first set a few entries + for (unsigned int i=0; i (i*j*.5+.5,0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex (i*j*.5+.5,0.), ExcInternalError()); + } + else + { + Assert (m(i,j) == std::complex (0.,0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex (0.,0.), ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + +void test_complex (PETScWrappers::SparseMatrix &m) +{ + deallog << "Complex test" << std::endl; + + // first set a few entries + for (unsigned int i=0; i (0.,i*j*.5+.5)); + + m.compress (VectorOperation::add); + + // then make sure we retrieve the same ones + for (unsigned int i=0; i (0.,i*j*.5+.5), ExcInternalError()); + Assert (m.el(i,j) == std::complex (0.,i*j*.5+.5), ExcInternalError()); + } + else + { + Assert (m(i,j) == std::complex (0.,0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex (0.,0.), ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int main (int argc,char **argv) +{ + std::ofstream logfile("02/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; + + m.reinit (5,5,3); + test_real (m); + + m.reinit (5,5,3); + test_complex (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 --git a/tests/petsc_scalar_complex/02/cmp/generic b/tests/petsc_scalar_complex/02/cmp/generic new file mode 100644 index 0000000000..d2ebc39535 --- /dev/null +++ b/tests/petsc_scalar_complex/02/cmp/generic @@ -0,0 +1,5 @@ + +DEAL::Real test +DEAL::OK +DEAL::Complex test +DEAL::OK diff --git a/tests/petsc_scalar_complex/04.cc b/tests/petsc_scalar_complex/04.cc new file mode 100644 index 0000000000..56a8d3553b --- /dev/null +++ b/tests/petsc_scalar_complex/04.cc @@ -0,0 +1,76 @@ +// --------------------------------------------------------------------- +// $Id: 04.cc 30045 2013-07-18 19:18:00Z maier $ +// +// Copyright (C) 2004 - 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check querying matrix sizes + +#include "../tests.h" +#include +#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("04/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 --git a/tests/petsc_scalar_complex/04/cmp/generic b/tests/petsc_scalar_complex/04/cmp/generic new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/petsc_scalar_complex/04/cmp/generic @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/petsc_scalar_complex/05.cc b/tests/petsc_scalar_complex/05.cc new file mode 100644 index 0000000000..5c64b6a961 --- /dev/null +++ b/tests/petsc_scalar_complex/05.cc @@ -0,0 +1,126 @@ +// --------------------------------------------------------------------- +// $Id: +// +// Copyright (C) 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check querying the number of nonzero elements in +// PETScWrappers::SparseMatrix + +#include "../tests.h" +#include +#include +#include + + +void test_real (PETScWrappers::SparseMatrix &m) +{ + deallog << "Real test" << std::endl; + + // first set a few entries. count how many entries we have + unsigned int counter = 0; + for (unsigned int i=0; i (0.,i*j*.5+.5)); + ++counter; + } + + m.compress (VectorOperation::add); + + deallog << m.n_nonzero_elements() << std::endl; + Assert (m.n_nonzero_elements() == counter, + ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int main (int argc,char **argv) +{ + std::ofstream logfile("05/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_real (m); + + PETScWrappers::SparseMatrix n (5,5,3); + test_complex (n); + + // this last bit is unnecessarry fun... + deallog << "Compare real-complex test" << std::endl; + Assert (m.n_nonzero_elements() == n.n_nonzero_elements(), + ExcInternalError()); + deallog << "OK" << std::endl; + } + + } + 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 --git a/tests/petsc_scalar_complex/05/cmp/generic b/tests/petsc_scalar_complex/05/cmp/generic new file mode 100644 index 0000000000..8d69c4efd8 --- /dev/null +++ b/tests/petsc_scalar_complex/05/cmp/generic @@ -0,0 +1,9 @@ + +DEAL::Real test +DEAL::8 +DEAL::OK +DEAL::Complex test +DEAL::8 +DEAL::OK +DEAL::Compare real-complex test +DEAL::OK diff --git a/tests/petsc_scalar_complex/06.cc b/tests/petsc_scalar_complex/06.cc new file mode 100644 index 0000000000..cef7c22366 --- /dev/null +++ b/tests/petsc_scalar_complex/06.cc @@ -0,0 +1,113 @@ +// --------------------------------------------------------------------- +// $Id: 06.cc 30045 2013-07-18 19:18:00Z maier $ +// +// Copyright (C) 2004 - 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check PETScWrappers::SparseMatrix::l1_norm + +#include "../tests.h" +#include +#include +#include + + +void test_real (PETScWrappers::SparseMatrix &m) +{ + deallog << "Real test" << std::endl; + + // first set a few entries. count how many entries we have + for (unsigned int i=0; i (0.,i*j*.5+.5)); + + m.compress (VectorOperation::add); + + // compare against the exact value of the l1-norm (max col-sum) + deallog << m.l1_norm() << std::endl; + Assert (m.l1_norm() == 7, ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int main (int argc,char **argv) +{ + std::ofstream logfile("06/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; + + m.reinit (5,5,3); + test_real (m); + + m.reinit (5,5,3); + test_complex (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 --git a/tests/petsc_scalar_complex/06/cmp/generic b/tests/petsc_scalar_complex/06/cmp/generic new file mode 100644 index 0000000000..e183811702 --- /dev/null +++ b/tests/petsc_scalar_complex/06/cmp/generic @@ -0,0 +1,7 @@ + +DEAL::Real test +DEAL::7.00000 +DEAL::OK +DEAL::Complex test +DEAL::7.00000 +DEAL::OK diff --git a/tests/petsc_scalar_complex/07.cc b/tests/petsc_scalar_complex/07.cc new file mode 100644 index 0000000000..68574f6d46 --- /dev/null +++ b/tests/petsc_scalar_complex/07.cc @@ -0,0 +1,112 @@ +// --------------------------------------------------------------------- +// $Id: +// +// Copyright (C) 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check PETScWrappers::SparseMatrix::linfty_norm + +#include "../tests.h" +#include +#include +#include + + +void test_real (PETScWrappers::SparseMatrix &m) +{ + deallog << "Real test" << std::endl; + + // first set a few entries. count how many entries we have + for (unsigned int i=0; i (0.,i*j*.5+.5)); + + m.compress (VectorOperation::add); + + // compare against the exact value of the linfty-norm (max row-sum). + deallog << m.linfty_norm() << std::endl; + Assert (m.linfty_norm() == 8.5, ExcInternalError()); + + deallog << "OK" << std::endl; +} + +int main (int argc,char **argv) +{ + std::ofstream logfile("07/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; + + m.reinit (5,5,3); + test_real (m); + + m.reinit (5,5,3); + test_complex (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 --git a/tests/petsc_scalar_complex/07/cmp/generic b/tests/petsc_scalar_complex/07/cmp/generic new file mode 100644 index 0000000000..3f88f56376 --- /dev/null +++ b/tests/petsc_scalar_complex/07/cmp/generic @@ -0,0 +1,7 @@ + +DEAL::Real test +DEAL::8.50000 +DEAL::OK +DEAL::Complex test +DEAL::8.50000 +DEAL::OK diff --git a/tests/petsc_scalar_complex/08.cc b/tests/petsc_scalar_complex/08.cc new file mode 100644 index 0000000000..8c2206cd7c --- /dev/null +++ b/tests/petsc_scalar_complex/08.cc @@ -0,0 +1,125 @@ +// --------------------------------------------------------------------- +// $Id: +// +// 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::SparseMatrix::frobenius_norm + +#include "../tests.h" +#include +#include +#include + + + +void test_real (PETScWrappers::SparseMatrix &m) +{ + deallog << "Real test" << std::endl; + + // first set a few entries. count how many entries we have + PetscScalar norm = 0; + for (unsigned int i=0; i (0.,i*j*.5+.5)); + norm += (i*j*.5+.5)*(i*j*.5+.5); + } + norm = std::sqrt(norm); + + m.compress (VectorOperation::add); + + // compare against the exact value of the l2-norm (max row-sum) + deallog << m.frobenius_norm() << std::endl; + Assert (m.frobenius_norm() == norm, ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int main (int argc,char **argv) +{ + std::ofstream logfile("08/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; + + m.reinit (5,5,3); + test_real (m); + + m.reinit (5,5,3); + test_complex (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 --git a/tests/petsc_scalar_complex/08/cmp/generic b/tests/petsc_scalar_complex/08/cmp/generic new file mode 100644 index 0000000000..35c2568f44 --- /dev/null +++ b/tests/petsc_scalar_complex/08/cmp/generic @@ -0,0 +1,7 @@ + +DEAL::Real test +DEAL::9.04157 +DEAL::OK +DEAL::Complex test +DEAL::9.04157 +DEAL::OK diff --git a/tests/petsc_scalar_complex/09.cc b/tests/petsc_scalar_complex/09.cc new file mode 100644 index 0000000000..72a9ec62a5 --- /dev/null +++ b/tests/petsc_scalar_complex/09.cc @@ -0,0 +1,148 @@ +// --------------------------------------------------------------------- +// $Id: 09.cc 30045 2013-07-18 19:18:00Z maier $ +// +// Copyright (C) 2004 - 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check PETScWrappers::SparseMatrix::operator *= + +#include "../tests.h" +#include +#include +#include + + + +void test_real (PETScWrappers::SparseMatrix &m) +{ + deallog << "Real test" << std::endl; + + // first set a few entries + for (unsigned int i=0; i ((i*j*.5+.5)*1.25,0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex ((i*j*.5+.5)*1.25,0.), ExcInternalError()); + } + else + { + Assert (m(i,j) == std::complex (0.,0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex (0.,0.), ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + +void test_complex (PETScWrappers::SparseMatrix &m) +{ + deallog << "Complex test" << std::endl; + + // first set a few entries + for (unsigned int i=0; i (i*j*.5+.5,i*j*.5)); + } + + m.compress (VectorOperation::add); + + // then multiply everything by 1.25 + m *= 1.25; + + // and make sure we retrieve the values we expect + for (unsigned int i=0; i ((i*j*.5+.5)*1.25,i*j*.5*1.25), ExcInternalError()); + Assert (m.el(i,j) == std::complex ((i*j*.5+.5)*1.25,i*j*.5*1.25), ExcInternalError()); + } + else + { + Assert (m(i,j) == std::complex (0.,0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex (0.,0.), ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int main (int argc,char **argv) +{ + std::ofstream logfile("09/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; + + m.reinit (5,5,3); + test_real (m); + + m.reinit (5,5,3); + test_complex (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 --git a/tests/petsc_scalar_complex/09/cmp/generic b/tests/petsc_scalar_complex/09/cmp/generic new file mode 100644 index 0000000000..d2ebc39535 --- /dev/null +++ b/tests/petsc_scalar_complex/09/cmp/generic @@ -0,0 +1,5 @@ + +DEAL::Real test +DEAL::OK +DEAL::Complex test +DEAL::OK diff --git a/tests/petsc_scalar_complex/10.cc b/tests/petsc_scalar_complex/10.cc new file mode 100644 index 0000000000..63aab12a95 --- /dev/null +++ b/tests/petsc_scalar_complex/10.cc @@ -0,0 +1,140 @@ +// --------------------------------------------------------------------- +// $id: +// +// Copyright (C) 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +// check PETScWrappers::SparseMatrix::operator /= + +#include "../tests.h" +#include +#include +#include + + + +void test_real (PETScWrappers::SparseMatrix &m) +{ + deallog << "Real test" << std::endl; + + // first set a few entries + for (unsigned int i=0; i ((i*j*.5+.5)/4*3, 0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex ((i*j*.5+.5)/4*3, 0.), ExcInternalError()); + } + else + { + Assert (m(i,j) == std::complex (0.,0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex (0.,0.), ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + +void test_complex (PETScWrappers::SparseMatrix &m) +{ + deallog << "Complex test" << std::endl; + + // first set a few entries + for (unsigned int i=0; i (0.,i*j*.5+.5)); + + m.compress (VectorOperation::add); + + // then divide everything by 4/3 and make sure we retrieve the + // values we expect + m /= 4./3.; + + for (unsigned int i=0; i (0.,(i*j*.5+.5)/4*3), ExcInternalError()); + Assert (m.el(i,j) == std::complex (0.,(i*j*.5+.5)/4*3), ExcInternalError()); + } + else + { + Assert (m(i,j) == std::complex (0.,0.), ExcInternalError()); + Assert (m.el(i,j) == std::complex (0.,0.), ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int main (int argc,char **argv) +{ + std::ofstream logfile("10/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; + + m.reinit (5,5,3); + test_real (m); + + m.reinit (5,5,3); + test_complex (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 --git a/tests/petsc_scalar_complex/10/cmp/generic b/tests/petsc_scalar_complex/10/cmp/generic new file mode 100644 index 0000000000..d2ebc39535 --- /dev/null +++ b/tests/petsc_scalar_complex/10/cmp/generic @@ -0,0 +1,5 @@ + +DEAL::Real test +DEAL::OK +DEAL::Complex test +DEAL::OK