// PetscScalar in accordance with gcc.gnu.org bug 7263.
// deal.II includes
+#include "../tests.h"
#include <deal.II/base/logstream.h>
#include <fstream>
#include <iostream>
#include <cassert>
-#ifdef PETSC_USE_COMPLEX
std::ofstream logfile ("00-manipulate_petsc_scalar/output");
<< " should be 0.5+1i"
<< std::endl;
- assert (alpha==beta);
+ Assert (alpha==beta, ExcInternalError());
}
// Initialize a std::complex number from an PETSc complex number
<< "i"
<< std::endl;
- // even this works
- assert (alpha==beta);
+ Assert (alpha==beta, ExcInternalError());
}
// Initialize a PETSc complex number from an std::complex number
<< "i"
<< std::endl;
- assert (alpha==beta);
+ Assert (alpha==beta, ExcInternalError());
}
// Initialize a PETSc complex number directly.
<< "i"
<< " should be 1+2i"
<< std::endl;
+
+ Assert (alpha==std::complex<double> (1.,2.), ExcInternalError());
}
<< " should be 0+0i"
<< std::endl;
- assert (alpha==beta);
+ Assert (alpha==beta, ExcInternalError());
}
int main (int argc, char **argv)
return 0;
}
-#endif // PETSC_USE_COMPLEX
+
--- /dev/null
+// ---------------------------------------------------------------------
+// $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 <deal.II/lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+void test_real (PETScWrappers::SparseMatrix &m)
+{
+ deallog << "Real test" << std::endl;
+
+ // first set a few entries
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ m.set (i,j, i*j*.5+.5);
+
+ m.compress (VectorOperation::add);
+
+ // then make sure we retrieve the same ones
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ Assert (m(i,j) == std::complex<double> (i*j*.5+.5,0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (i*j*.5+.5,0.), ExcInternalError());
+ }
+ else
+ {
+ Assert (m(i,j) == std::complex<double> (0.,0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ m.set (i,j, std::complex<double> (0.,i*j*.5+.5));
+
+ m.compress (VectorOperation::add);
+
+ // then make sure we retrieve the same ones
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ Assert (m(i,j) == std::complex<double> (0.,i*j*.5+.5), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (0.,i*j*.5+.5), ExcInternalError());
+ }
+ else
+ {
+ Assert (m(i,j) == std::complex<double> (0.,0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (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;
+ };
+}
--- /dev/null
+
+DEAL::Real test
+DEAL::OK
+DEAL::Complex test
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+// $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 <deal.II/lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+void test_real (PETScWrappers::SparseMatrix &m)
+{
+ deallog << "Real test" << std::endl;
+
+ // first set a few entries
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ m.add (i,j, i*j*.5+.5);
+
+ m.compress (VectorOperation::add);
+
+ // then make sure we retrieve the same ones
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ Assert (m(i,j) == std::complex<double> (i*j*.5+.5,0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (i*j*.5+.5,0.), ExcInternalError());
+ }
+ else
+ {
+ Assert (m(i,j) == std::complex<double> (0.,0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ m.add (i,j, std::complex<double> (0.,i*j*.5+.5));
+
+ m.compress (VectorOperation::add);
+
+ // then make sure we retrieve the same ones
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ Assert (m(i,j) == std::complex<double> (0.,i*j*.5+.5), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (0.,i*j*.5+.5), ExcInternalError());
+ }
+ else
+ {
+ Assert (m(i,j) == std::complex<double> (0.,0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (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;
+ };
+}
--- /dev/null
+
+DEAL::Real test
+DEAL::OK
+DEAL::Complex test
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+// $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 <deal.II/lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+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;
+ };
+}
--- /dev/null
+
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+// $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 <deal.II/lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ m.set (i,j, 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;
+}
+
+
+void test_complex (PETScWrappers::SparseMatrix &m)
+{
+ deallog << "Complex test" << std::endl;
+
+ // first set a few entries. count how many entries we have
+ unsigned int counter = 0;
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ m.set (i,j, std::complex<double> (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;
+ };
+}
--- /dev/null
+
+DEAL::Real test
+DEAL::8
+DEAL::OK
+DEAL::Complex test
+DEAL::8
+DEAL::OK
+DEAL::Compare real-complex test
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+// $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 <deal.II/lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ m.set (i,j, 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;
+}
+
+
+void test_complex (PETScWrappers::SparseMatrix &m)
+{
+ deallog << "Complex test" << std::endl;
+
+ // first set a few entries. count how many entries we have
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ m.set (i,j, std::complex<double> (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;
+ };
+}
--- /dev/null
+
+DEAL::Real test
+DEAL::7.00000
+DEAL::OK
+DEAL::Complex test
+DEAL::7.00000
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+// $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 <deal.II/lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ m.set (i,j, 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;
+}
+
+void test_complex (PETScWrappers::SparseMatrix &m)
+{
+ deallog << "Complex test" << std::endl;
+
+ // first set a few entries. count how many entries we have
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ m.set (i,j, std::complex<double> (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;
+ };
+}
+
+
--- /dev/null
+
+DEAL::Real test
+DEAL::8.50000
+DEAL::OK
+DEAL::Complex test
+DEAL::8.50000
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+// $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 <deal.II/lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+
+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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ m.set (i,j, 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;
+}
+
+void test_complex (PETScWrappers::SparseMatrix &m)
+{
+ deallog << "Complex test" << std::endl;
+
+ // first set a few entries. count how many entries we have
+ PetscScalar norm = 0;
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ m.set (i,j, std::complex<double> (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;
+ };
+}
+
+
--- /dev/null
+
+DEAL::Real test
+DEAL::9.04157
+DEAL::OK
+DEAL::Complex test
+DEAL::9.04157
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+// $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 <deal.II/lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+
+void test_real (PETScWrappers::SparseMatrix &m)
+{
+ deallog << "Real test" << std::endl;
+
+ // first set a few entries
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ // put like this, ie. just adding real numbers, imaginary
+ // entries are automagically zero
+ m.set (i,j, i*j*.5+.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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ Assert (m(i,j) == std::complex<double> ((i*j*.5+.5)*1.25,0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> ((i*j*.5+.5)*1.25,0.), ExcInternalError());
+ }
+ else
+ {
+ Assert (m(i,j) == std::complex<double> (0.,0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ // put like this, matrix enteries had better be imaginary
+ m.set (i,j, std::complex<double> (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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ Assert (m(i,j) == std::complex<double> ((i*j*.5+.5)*1.25,i*j*.5*1.25), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> ((i*j*.5+.5)*1.25,i*j*.5*1.25), ExcInternalError());
+ }
+ else
+ {
+ Assert (m(i,j) == std::complex<double> (0.,0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (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;
+ };
+}
+
+
--- /dev/null
+
+DEAL::Real test
+DEAL::OK
+DEAL::Complex test
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+// $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 <deal.II/lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+
+void test_real (PETScWrappers::SparseMatrix &m)
+{
+ deallog << "Real test" << std::endl;
+
+ // first set a few entries
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ m.set (i,j, 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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ Assert (m(i,j) == std::complex<double> ((i*j*.5+.5)/4*3, 0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> ((i*j*.5+.5)/4*3, 0.), ExcInternalError());
+ }
+ else
+ {
+ Assert (m(i,j) == std::complex<double> (0.,0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ m.set (i,j, std::complex<double> (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<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ Assert (m(i,j) == std::complex<double> (0.,(i*j*.5+.5)/4*3), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (0.,(i*j*.5+.5)/4*3), ExcInternalError());
+ }
+ else
+ {
+ Assert (m(i,j) == std::complex<double> (0.,0.), ExcInternalError());
+ Assert (m.el(i,j) == std::complex<double> (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;
+ };
+}
+
+
--- /dev/null
+
+DEAL::Real test
+DEAL::OK
+DEAL::Complex test
+DEAL::OK