--- /dev/null
+// ---------------------------------------------------------------------
+// $Id: vector_assign_01.cc
+//
+// Copyright (C) 2013 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// when calling PETScWrappers::Vector::operator() (), the return type is a
+// reference object, not a reference to the actual element. this leads to the
+// funny situation that an assignment like v2(i)=v1(i) isn't really what it
+// looks like: it tries to copy the reference objects, not the values they
+// point to, as one would expect
+//
+// this was fixed 2004-04-05, and this test checks that it works
+
+#include "../tests.h"
+#include <deal.II/lac/petsc_vector.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (PETScWrappers::Vector &v,
+ PETScWrappers::Vector &w)
+{
+ // set the first vector
+ for (unsigned int k=0; k<v.size(); ++k)
+ v(k) = std::complex<double> (k,k*k);
+
+ // copy elements by reference
+ for (unsigned int k=0; k<v.size(); ++k)
+ w(k) = v(k);
+
+ // check that they're equal
+ Assert (v==w, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+int main (int argc, char **argv)
+{
+ std::ofstream logfile("vector_assign_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::Vector v (100);
+ PETScWrappers::Vector w (100);
+ test (v,w);
+ }
+
+ }
+ 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: vector_assign_02.cc
+//
+// Copyright (C) 2013 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// this is equivalent to the petsc_vector_assign_01 test, except that we use
+// operator+= instead of operator=. This is also not exciting...
+
+#include "../tests.h"
+#include <deal.II/lac/petsc_vector.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test_real (PETScWrappers::Vector &v,
+ PETScWrappers::Vector &w)
+{
+ deallog << "Real test" << std::endl;
+
+ // set the first vector
+ for (unsigned int k=0; k<v.size(); ++k)
+ v(k) = k;
+
+ // add elements by reference
+ for (unsigned int k=0; k<v.size(); ++k)
+ w(k) += v(k);
+
+ // check that they're equal
+ Assert (v==w, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+void test_complex (PETScWrappers::Vector &v,
+ PETScWrappers::Vector &w)
+{
+ deallog << "Complex test" << std::endl;
+
+ // set the first vector
+ for (unsigned int k=0; k<v.size(); ++k)
+ v(k) = PetscScalar (k,k*k);
+
+ // add elements by reference
+ for (unsigned int k=0; k<v.size(); ++k)
+ w(k) += v(k);
+
+ // check that they're equal
+ Assert (v==w, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+int main (int argc, char **argv)
+{
+ std::ofstream logfile ("vector_assign_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::Vector v (20);
+ PETScWrappers::Vector w (20);
+ test_real (v,w);
+
+ v.reinit (20);
+ w.reinit (20);
+ test_complex (v,w);
+
+ // We are really only interested in checking that assignment
+ // of the complex part is correct.
+ deallog << "Complex vectors: " << std::endl;
+ deallog << "v: " << std::flush;
+ v.print (logfile, 0, false, true);
+ deallog << "w: " << std::flush;
+ w.print (logfile, 0, false, true);
+ 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::OK
+DEAL::Complex test
+DEAL::OK
+DEAL::Complex vectors:
+DEAL::v: (0.,0.) (1.,1.) (2.,4.) (3.,9.) (4.,16.) (5.,25.) (6.,36.) (7.,49.) (8.,64.) (9.,81.) (10.,100.) (11.,121.) (12.,144.) (13.,169.) (14.,196.) (15.,225.) (16.,256.) (17.,289.) (18.,324.) (19.,361.)
+w: (0.,0.) (1.,1.) (2.,4.) (3.,9.) (4.,16.) (5.,25.) (6.,36.) (7.,49.) (8.,64.) (9.,81.) (10.,100.) (11.,121.) (12.,144.) (13.,169.) (14.,196.) (15.,225.) (16.,256.) (17.,289.) (18.,324.) (19.,361.)
+OK
--- /dev/null
+// ---------------------------------------------------------------------
+// $Id: vector_equality_1.cc
+//
+// Copyright (C) 2013 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check PETScWrappers::Vector::operator==(PETScWrappers::Vector) for vectors that are not
+// equal
+
+#include "../tests.h"
+#include <deal.II/lac/petsc_vector.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test_real (PETScWrappers::Vector &v,
+ PETScWrappers::Vector &w)
+{
+ deallog << "Real test" << std::endl;
+
+ // set only certain elements of each vector
+ for (unsigned int k=0; k<v.size(); ++k)
+ {
+ v(k) = k;
+ if (k%3 == 0)
+ w(k) = k+1.;
+ }
+
+ Assert (!(v==w), ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+void test_complex (PETScWrappers::Vector &v,
+ PETScWrappers::Vector &w)
+{
+ deallog << "Complex test" << std::endl;
+
+ // set only certain elements of each vector
+ for (unsigned int k=0; k<v.size(); ++k)
+ {
+ v(k) = std::complex<double> (k,k);
+ if (k%3 == 0)
+ w(k) = std::complex<double> (k+1.,k+1.);
+ }
+
+ Assert (!(v==w), ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+ std::ofstream logfile("vector_equality_1/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 (20);
+ PETScWrappers::Vector w (20);
+ test_real (v,w);
+
+ // Just incase, *read* these vectors are correct.
+ deallog << "Real vectors: " << std::endl;
+ v.print (logfile, 0, false, true);
+ w.print (logfile, 0, false, true);
+ deallog << "OK" << std::endl;
+
+ v.reinit (20);
+ w.reinit (20);
+ test_complex (v,w);
+
+ // Just incase, *read* these vectors are correct.
+ deallog << "Complex vectors: " << std::endl;
+ v.print (logfile, 0, false, true);
+ w.print (logfile, 0, false, true);
+ 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::OK
+DEAL::Real vectors:
+(0.,0.) (1.,0.) (2.,0.) (3.,0.) (4.,0.) (5.,0.) (6.,0.) (7.,0.) (8.,0.) (9.,0.) (10.,0.) (11.,0.) (12.,0.) (13.,0.) (14.,0.) (15.,0.) (16.,0.) (17.,0.) (18.,0.) (19.,0.)
+(1.,0.) (0.,0.) (0.,0.) (4.,0.) (0.,0.) (0.,0.) (7.,0.) (0.,0.) (0.,0.) (10.,0.) (0.,0.) (0.,0.) (13.,0.) (0.,0.) (0.,0.) (16.,0.) (0.,0.) (0.,0.) (19.,0.) (0.,0.)
+DEAL::OK
+DEAL::Complex test
+DEAL::OK
+DEAL::Complex vectors:
+(0.,0.) (1.,1.) (2.,2.) (3.,3.) (4.,4.) (5.,5.) (6.,6.) (7.,7.) (8.,8.) (9.,9.) (10.,10.) (11.,11.) (12.,12.) (13.,13.) (14.,14.) (15.,15.) (16.,16.) (17.,17.) (18.,18.) (19.,19.)
+(1.,1.) (0.,0.) (0.,0.) (4.,4.) (0.,0.) (0.,0.) (7.,7.) (0.,0.) (0.,0.) (10.,10.) (0.,0.) (0.,0.) (13.,13.) (0.,0.) (0.,0.) (16.,16.) (0.,0.) (0.,0.) (19.,19.) (0.,0.)
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+// $Id: vector_equality_2.cc
+//
+// Copyright (C) 2013 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check PETScWrappers::Vector::operator==(PETScWrappers::Vector) for vectors that are
+// equal
+
+#include "../tests.h"
+#include <deal.II/lac/petsc_vector.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test_real (PETScWrappers::Vector &v,
+ PETScWrappers::Vector &w)
+{
+ // set only certain elements of each vector where, on the "master
+ // vector", some elements are complex and the other is real.
+ for (unsigned int k=0; k<v.size(); ++k)
+ {
+ v(k) = k;
+ if (k%3 == 0)
+ w(k) = std::complex<double> (k+1.,k+1);
+ }
+
+ // then copy elements and make sure the vectors are actually equal
+ v = w;
+ Assert (v==w, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+void test_complex (PETScWrappers::Vector &v,
+ PETScWrappers::Vector &w)
+{
+ // set only certain elements of each vector
+ for (unsigned int k=0; k<v.size(); ++k)
+ {
+ v(k) = PetscScalar (k,k);
+ if (k%3 == 0)
+ w(k) = std::complex<double> (k+1.,k+1);
+ }
+
+ // then copy elements and make sure the vectors are actually equal
+ v = w;
+ Assert (v==w, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+ std::ofstream logfile("vector_equality_2/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 (20);
+ PETScWrappers::Vector w (20);
+ test_real (v,w);
+
+ // Just incase, *read* these vectors are correct.
+ deallog << "Real vectors: " << std::endl;
+ v.print (logfile, 0, false, true);
+ w.print (logfile, 0, false, true);
+ deallog << "OK" << std::endl;
+
+ v.reinit (20);
+ w.reinit (20);
+ test_complex (v,w);
+
+ // Just incase, *read* these vectors are correct.
+ deallog << "Complex vectors: " << std::endl;
+ v.print (logfile, 0, false, true);
+ w.print (logfile, 0, false, true);
+ 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::OK
+DEAL::Real vectors:
+(1.,1.) (0.,0.) (0.,0.) (4.,4.) (0.,0.) (0.,0.) (7.,7.) (0.,0.) (0.,0.) (10.,10.) (0.,0.) (0.,0.) (13.,13.) (0.,0.) (0.,0.) (16.,16.) (0.,0.) (0.,0.) (19.,19.) (0.,0.)
+(1.,1.) (0.,0.) (0.,0.) (4.,4.) (0.,0.) (0.,0.) (7.,7.) (0.,0.) (0.,0.) (10.,10.) (0.,0.) (0.,0.) (13.,13.) (0.,0.) (0.,0.) (16.,16.) (0.,0.) (0.,0.) (19.,19.) (0.,0.)
+DEAL::OK
+DEAL::OK
+DEAL::Complex vectors:
+(1.,1.) (0.,0.) (0.,0.) (4.,4.) (0.,0.) (0.,0.) (7.,7.) (0.,0.) (0.,0.) (10.,10.) (0.,0.) (0.,0.) (13.,13.) (0.,0.) (0.,0.) (16.,16.) (0.,0.) (0.,0.) (19.,19.) (0.,0.)
+(1.,1.) (0.,0.) (0.,0.) (4.,4.) (0.,0.) (0.,0.) (7.,7.) (0.,0.) (0.,0.) (10.,10.) (0.,0.) (0.,0.) (13.,13.) (0.,0.) (0.,0.) (16.,16.) (0.,0.) (0.,0.) (19.,19.) (0.,0.)
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+// $Id: vector_equality_5.cc
+//
+// Copyright (C) 2013 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check PETScWrappers::Vector::operator=(PETScWrappers::Vector) for vectors that are
+// equal and initialised from PETScWrappers::Vector (PETScWrappers::Vector)
+
+#include "../tests.h"
+#include <deal.II/lac/petsc_vector.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test_real (PETScWrappers::Vector &v)
+{
+ deallog << "Real test" << std::endl;
+
+ // set only certain elements of vector
+ for (unsigned int k=0; k<v.size(); ++k)
+ if (k%3 == 0)
+ v(k) = k;
+
+ PETScWrappers::Vector w (v);
+
+ Assert (v==w, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+void test_complex (PETScWrappers::Vector &v)
+{
+ deallog << "Complex test" << std::endl;
+
+ // set only certain elements of vector
+ for (unsigned int k=0; k<v.size(); ++k)
+ if (k%3 == 0)
+ v(k) = std::complex<double> (k,k+1.);
+
+ PETScWrappers::Vector w (v);
+
+ Assert (v==w, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+ std::ofstream logfile("vector_equality_5/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_real (v);
+
+ v.reinit (100);
+ test_complex (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;
+ };
+}
--- /dev/null
+
+DEAL::Real test
+DEAL::OK
+DEAL::Complex test
+DEAL::OK