From 3a96bc00aafaba250371ae8efc5138cfa714191b Mon Sep 17 00:00:00 2001 From: young Date: Sun, 20 Oct 2013 13:40:18 +0000 Subject: [PATCH] Port a bunch of vector tests to petsc scalar complex. Add one equality-initialiser test. git-svn-id: https://svn.dealii.org/branches/branch_petscscalar_complex@31330 0785d39b-7218-0410-832d-ea1e28bc413d --- .../petsc_scalar_complex/vector_assign_01.cc | 93 +++++++++++++ .../vector_assign_01/cmp/generic | 2 + .../petsc_scalar_complex/vector_assign_02.cc | 123 +++++++++++++++++ .../vector_assign_02/cmp/generic | 9 ++ .../petsc_scalar_complex/vector_equality_1.cc | 124 +++++++++++++++++ .../vector_equality_1/cmp/generic | 13 ++ .../petsc_scalar_complex/vector_equality_2.cc | 125 ++++++++++++++++++ .../vector_equality_2/cmp/generic | 11 ++ .../petsc_scalar_complex/vector_equality_5.cc | 107 +++++++++++++++ .../vector_equality_5/cmp/generic | 5 + 10 files changed, 612 insertions(+) create mode 100644 tests/petsc_scalar_complex/vector_assign_01.cc create mode 100644 tests/petsc_scalar_complex/vector_assign_01/cmp/generic create mode 100644 tests/petsc_scalar_complex/vector_assign_02.cc create mode 100644 tests/petsc_scalar_complex/vector_assign_02/cmp/generic create mode 100644 tests/petsc_scalar_complex/vector_equality_1.cc create mode 100644 tests/petsc_scalar_complex/vector_equality_1/cmp/generic create mode 100644 tests/petsc_scalar_complex/vector_equality_2.cc create mode 100644 tests/petsc_scalar_complex/vector_equality_2/cmp/generic create mode 100644 tests/petsc_scalar_complex/vector_equality_5.cc create mode 100644 tests/petsc_scalar_complex/vector_equality_5/cmp/generic diff --git a/tests/petsc_scalar_complex/vector_assign_01.cc b/tests/petsc_scalar_complex/vector_assign_01.cc new file mode 100644 index 0000000000..be73daa364 --- /dev/null +++ b/tests/petsc_scalar_complex/vector_assign_01.cc @@ -0,0 +1,93 @@ +// --------------------------------------------------------------------- +// $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 +#include +#include +#include + + +void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) +{ + // set the first vector + for (unsigned int k=0; k (k,k*k); + + // copy elements by reference + for (unsigned int k=0; k +#include +#include +#include + + +void test_real (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) +{ + deallog << "Real test" << std::endl; + + // set the first vector + for (unsigned int k=0; k +#include +#include +#include + + +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 (k,k); + if (k%3 == 0) + w(k) = std::complex (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; + }; +} diff --git a/tests/petsc_scalar_complex/vector_equality_1/cmp/generic b/tests/petsc_scalar_complex/vector_equality_1/cmp/generic new file mode 100644 index 0000000000..8b5a3a1343 --- /dev/null +++ b/tests/petsc_scalar_complex/vector_equality_1/cmp/generic @@ -0,0 +1,13 @@ + +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 diff --git a/tests/petsc_scalar_complex/vector_equality_2.cc b/tests/petsc_scalar_complex/vector_equality_2.cc new file mode 100644 index 0000000000..908100ae07 --- /dev/null +++ b/tests/petsc_scalar_complex/vector_equality_2.cc @@ -0,0 +1,125 @@ +// --------------------------------------------------------------------- +// $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 +#include +#include +#include + + +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 (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 (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; + }; +} diff --git a/tests/petsc_scalar_complex/vector_equality_2/cmp/generic b/tests/petsc_scalar_complex/vector_equality_2/cmp/generic new file mode 100644 index 0000000000..fe71e404f7 --- /dev/null +++ b/tests/petsc_scalar_complex/vector_equality_2/cmp/generic @@ -0,0 +1,11 @@ + +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 diff --git a/tests/petsc_scalar_complex/vector_equality_5.cc b/tests/petsc_scalar_complex/vector_equality_5.cc new file mode 100644 index 0000000000..6d95254c6c --- /dev/null +++ b/tests/petsc_scalar_complex/vector_equality_5.cc @@ -0,0 +1,107 @@ +// --------------------------------------------------------------------- +// $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 +#include +#include +#include + + +void test_real (PETScWrappers::Vector &v) +{ + deallog << "Real test" << std::endl; + + // set only certain elements of vector + for (unsigned int k=0; k (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; + }; +} diff --git a/tests/petsc_scalar_complex/vector_equality_5/cmp/generic b/tests/petsc_scalar_complex/vector_equality_5/cmp/generic new file mode 100644 index 0000000000..d2ebc39535 --- /dev/null +++ b/tests/petsc_scalar_complex/vector_equality_5/cmp/generic @@ -0,0 +1,5 @@ + +DEAL::Real test +DEAL::OK +DEAL::Complex test +DEAL::OK -- 2.39.5