From: Toby D. Young Date: Tue, 23 Feb 2016 06:57:45 +0000 (+0100) Subject: add unit tests for complex-valued PETSc and SLEPc X-Git-Tag: v8.5.0-rc1~1217^2~9 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c0b410f2ed7ca1e1e03e52fc894b8d4dc0353fe;p=dealii.git add unit tests for complex-valued PETSc and SLEPc --- diff --git a/tests/petsc_complex/00.cc b/tests/petsc_complex/00.cc new file mode 100644 index 0000000000..f00cdb481b --- /dev/null +++ b/tests/petsc_complex/00.cc @@ -0,0 +1,218 @@ +// --------------------------------------------------------------------- +// $Id: 00.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. +// +// --------------------------------------------------------------------- + + +// PETSc includes: We would like to do this cleanly +// +#include +#include +#include +// +// though a horrible warning message +// +// warning: imaginary constants are a GCC extension [enabled by default] +// +// appears. This seems to be related to the direct useage of +// PetscScalar in accordance with gcc.gnu.org bug 7263. + +// deal.II includes +#include "../tests.h" +#include + +#include +#include +#include + +// These tests were used while building extensions for +// PetscSclar=complex. They check that std::complex and +// PetscScalar complex are compatible without explicitly casting. +// +// These tests look archaic - they are the original tests used to +// figure out how PetscScalar complex works... + +// Multiply a PETSc complex number by a complex number. +void multiply_petsc_complex_by_a_number () +{ + deallog << "Check PetscScalar multiply" << std::endl; + + // make alpha + const PetscScalar alpha = 1.0 + 2.0*PETSC_i; + + // make beta + const PetscScalar beta = 2.0 + 1.0*PETSC_i; + + // multiply them together + const PetscScalar gamma = alpha * beta; + + // Check real access + Assert (PetscRealPart (gamma)==0., ExcInternalError()); + Assert (PetscImaginaryPart (gamma) ==5., ExcInternalError()); + + // This is legal too! + Assert (gamma==std::complex (0.,5), ExcInternalError()); + + deallog << "OK" << std::endl; +} + +// Divide a PETSc complex number by a real number. +void divide_petsc_complex_by_a_number () +{ + deallog << "Check PetscScalar division" << std::endl; + + // make alpha + PetscScalar alpha = 1.0 + 2.0*PETSC_i; + + // make beta <- alpha/2 + const PetscScalar beta = alpha/2.; + + // Check real access + Assert (PetscRealPart (alpha)==1., ExcInternalError()); + Assert (PetscRealPart (beta) ==0.5, ExcInternalError()); + + // operate on alpha (now alpha==beta) + alpha /= 2.; + + // Check complex access + Assert (PetscImaginaryPart (alpha)==1., ExcInternalError()); + Assert (PetscImaginaryPart (beta) ==1., ExcInternalError()); + + // This is legal too! + Assert (alpha==beta, ExcInternalError()); + + deallog << "OK" << std::endl; +} + +// Initialize a std::complex number from an PETSc complex number +void make_std_complex_from_petsc_complex () +{ + deallog << "Check std initialised from PetscScalar" << std::endl; + const PetscScalar alpha = 1.0 + 2.0*PETSC_i; + const std::complex beta = alpha; + + // These should be the same of course + Assert (alpha==beta, ExcInternalError()); + + deallog << "OK" << std::endl; +} + +// Initialize a PETSc complex number from an std::complex number +void make_petsc_complex_from_std_complex () +{ + deallog << "Check PetscScalar initialised from std" << std::endl; + const std::complex beta (1,2); + const PetscScalar alpha = beta; + + // These should be the same of course + Assert (alpha==beta, ExcInternalError()); + + deallog << "OK" << std::endl; +} + +// Initialize a PETSc complex number directly. +void make_petsc_complex () +{ + deallog << "Check a nonzero PetscScalar" << std::endl; + + // init + const PetscScalar alpha = 1.0 + 2.0*PETSC_i; + + // Test if PetscScalar is an std::complex. + Assert (alpha==std::complex (1.,2.), ExcInternalError()); + + deallog << "OK" << std::endl; +} + +// Initialize a PETSc complex number directly only, check he is +// initialised to 0+0i. +void init_petsc_complex () +{ + deallog << "Check PetscScalar initialisation" << std::endl; + + // Initialise (no argument) to zero. + const PetscScalar alpha; + Assert (alpha==std::complex (0.,0.), ExcInternalError()); + + // Initialise (real argument) to zero. + const PetscScalar beta = 0.; + Assert (beta==alpha, ExcInternalError()); + + // Initialise (real+complex argument) to zero. + const PetscScalar gamma = 0. + 0.*PETSC_i; + Assert (gamma==beta, ExcInternalError()); + + // If alpha==beta==gamma, then: + Assert (alpha==gamma, ExcInternalError()); + + deallog << "OK" << std::endl; +} + +int main (int argc, char **argv) +{ + std::ofstream logfile ("output"); + dealii::deallog.attach (logfile); + dealii::deallog.depth_console (0); + deallog.threshold_double(1.e-10); + + try + { + PetscInitialize (&argc, &argv, (char *) 0, (char *) 0); + { + // initialisation (zero and nonzero) + init_petsc_complex (); + make_petsc_complex (); + + // initialisation from std::complex (and vice versa) + make_petsc_complex_from_std_complex (); + make_std_complex_from_petsc_complex (); + + // some operators + divide_petsc_complex_by_a_number (); + multiply_petsc_complex_by_a_number (); + } + PetscFinalize (); + } + + 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; + } + + logfile << std::endl; + + return 0; +} + + diff --git a/tests/petsc_complex/00.output b/tests/petsc_complex/00.output new file mode 100644 index 0000000000..8fc890b1ae --- /dev/null +++ b/tests/petsc_complex/00.output @@ -0,0 +1,14 @@ + +DEAL::Check PetscScalar initialisation +DEAL::OK +DEAL::Check a nonzero PetscScalar +DEAL::OK +DEAL::Check PetscScalar initialised from std +DEAL::OK +DEAL::Check std initialised from PetscScalar +DEAL::OK +DEAL::Check PetscScalar division +DEAL::OK +DEAL::Check PetscScalar multiply +DEAL::OK + diff --git a/tests/petsc_complex/01.cc b/tests/petsc_complex/01.cc new file mode 100644 index 0000000000..4dbcfec56c --- /dev/null +++ b/tests/petsc_complex/01.cc @@ -0,0 +1,95 @@ +// --------------------------------------------------------------------- +// $Id: 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. +// +// --------------------------------------------------------------------- + +// 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 (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("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_complex/01.output b/tests/petsc_complex/01.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/petsc_complex/01.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/petsc_complex/02.cc b/tests/petsc_complex/02.cc new file mode 100644 index 0000000000..dd70f49c83 --- /dev/null +++ b/tests/petsc_complex/02.cc @@ -0,0 +1,96 @@ +// --------------------------------------------------------------------- +// $Id: 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. +// +// --------------------------------------------------------------------- + + +// check setting elements in a petsc matrix using +// PETScWrappers::SparseMatrix::add() + + +#include "../tests.h" +#include +#include +#include + + +void test (PETScWrappers::SparseMatrix &m) +{ + // 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("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_complex/02.output b/tests/petsc_complex/02.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/petsc_complex/02.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/petsc_complex/04.cc b/tests/petsc_complex/04.cc new file mode 100644 index 0000000000..b0a8d51e01 --- /dev/null +++ b/tests/petsc_complex/04.cc @@ -0,0 +1,75 @@ +// --------------------------------------------------------------------- +// $Id: 04.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 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("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_complex/04.output b/tests/petsc_complex/04.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/petsc_complex/04.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/petsc_complex/05.cc b/tests/petsc_complex/05.cc new file mode 100644 index 0000000000..dd468a6e0b --- /dev/null +++ b/tests/petsc_complex/05.cc @@ -0,0 +1,91 @@ +// --------------------------------------------------------------------- +// $Id: 05.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 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 (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("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); + + 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_complex/05.output b/tests/petsc_complex/05.output new file mode 100644 index 0000000000..ab056528b5 --- /dev/null +++ b/tests/petsc_complex/05.output @@ -0,0 +1,4 @@ + +DEAL::8 +DEAL::OK +DEAL::OK diff --git a/tests/petsc_complex/06.cc b/tests/petsc_complex/06.cc new file mode 100644 index 0000000000..e3cc027519 --- /dev/null +++ b/tests/petsc_complex/06.cc @@ -0,0 +1,84 @@ +// --------------------------------------------------------------------- +// $Id: 06.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::SparseMatrix::l1_norm + +#include "../tests.h" +#include +#include +#include + + +void test (PETScWrappers::SparseMatrix &m) +{ + // 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("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_complex/06.output b/tests/petsc_complex/06.output new file mode 100644 index 0000000000..c3a0c690b9 --- /dev/null +++ b/tests/petsc_complex/06.output @@ -0,0 +1,3 @@ + +DEAL::7.00000 +DEAL::OK diff --git a/tests/petsc_complex/07.cc b/tests/petsc_complex/07.cc new file mode 100644 index 0000000000..3a1cafb1a9 --- /dev/null +++ b/tests/petsc_complex/07.cc @@ -0,0 +1,87 @@ +// --------------------------------------------------------------------- +// $Id: 07.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::SparseMatrix::linfty_norm + +#include "../tests.h" +#include +#include +#include + + +void test (PETScWrappers::SparseMatrix &m) +{ + // 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("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_complex/07.output b/tests/petsc_complex/07.output new file mode 100644 index 0000000000..22d8c0e810 --- /dev/null +++ b/tests/petsc_complex/07.output @@ -0,0 +1,3 @@ + +DEAL::8.50000 +DEAL::OK diff --git a/tests/petsc_complex/08.cc b/tests/petsc_complex/08.cc new file mode 100644 index 0000000000..e34a00a744 --- /dev/null +++ b/tests/petsc_complex/08.cc @@ -0,0 +1,92 @@ +// --------------------------------------------------------------------- +// $Id: 08.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::SparseMatrix::frobenius_norm + +#include "../tests.h" +#include +#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 (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("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_complex/08.output b/tests/petsc_complex/08.output new file mode 100644 index 0000000000..d4083f6573 --- /dev/null +++ b/tests/petsc_complex/08.output @@ -0,0 +1,3 @@ + +DEAL::9.04157 +DEAL::OK diff --git a/tests/petsc_complex/09.cc b/tests/petsc_complex/09.cc new file mode 100644 index 0000000000..e04c644cc6 --- /dev/null +++ b/tests/petsc_complex/09.cc @@ -0,0 +1,101 @@ +// --------------------------------------------------------------------- +// $Id: 09.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::SparseMatrix::operator *= + +#include "../tests.h" +#include +#include +#include + + +void test (PETScWrappers::SparseMatrix &m) +{ + // 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("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_complex/09.output b/tests/petsc_complex/09.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/petsc_complex/09.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/petsc_complex/10.cc b/tests/petsc_complex/10.cc new file mode 100644 index 0000000000..5d27dd617a --- /dev/null +++ b/tests/petsc_complex/10.cc @@ -0,0 +1,100 @@ +// --------------------------------------------------------------------- +// $id: 10.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::SparseMatrix::operator /= + +#include "../tests.h" +#include +#include +#include + + + +void test (PETScWrappers::SparseMatrix &m) +{ + // 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("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_complex/10.output b/tests/petsc_complex/10.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/petsc_complex/10.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/petsc_complex/11.cc b/tests/petsc_complex/11.cc new file mode 100644 index 0000000000..2b332d9d5b --- /dev/null +++ b/tests/petsc_complex/11.cc @@ -0,0 +1,80 @@ +// --------------------------------------------------------------------- +// $Id: 11.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::size() + +#include "../tests.h" +#include +#include +#include + + +void test (PETScWrappers::Vector &v) +{ + // set only certain elements of the vector + for (unsigned int k=0; k (k,.5*k); + + v.compress (VectorOperation::add); + + Assert (v.size() == 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::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 --git a/tests/petsc_complex/11.output b/tests/petsc_complex/11.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/petsc_complex/11.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/petsc_complex/12.cc b/tests/petsc_complex/12.cc new file mode 100644 index 0000000000..608fa3baee --- /dev/null +++ b/tests/petsc_complex/12.cc @@ -0,0 +1,97 @@ +// --------------------------------------------------------------------- +// $Id: 12.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() in set-mode + +#include "../tests.h" +#include +#include +#include +#include + + + +void test (PETScWrappers::Vector &v) +{ + deallog << "Complex test" << std::endl; + + // 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 k=0; k (0.,k); + pattern[k] = true; + } + + v.compress (VectorOperation::add); + + // check that they are ok, and this time all of them + for (unsigned int k=0; k +#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 (1.,1.)) ) || + ( (pattern[i]==false) && (v(i).real()==0.) && (v(i).imag()==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::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 --git a/tests/petsc_complex/13.output b/tests/petsc_complex/13.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/petsc_complex/13.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/petsc_complex/17.cc b/tests/petsc_complex/17.cc new file mode 100644 index 0000000000..a4c85e11a7 --- /dev/null +++ b/tests/petsc_complex/17.cc @@ -0,0 +1,85 @@ +// --------------------------------------------------------------------- +// $Id: 17.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::l1_norm() + +#include "../tests.h" +#include +#include +#include +#include + + +void test (PETScWrappers::Vector &v) +{ + // set some elements of the vector + double norm = 0; + for (unsigned int k=0; k +#include +#include +#include + + +void test (PETScWrappers::Vector &v) +{ + // set some elements of the vector + double norm = 0; + for (unsigned int k=0; k +#include +#include +#include + + +void test (PETScWrappers::Vector &v) +{ + // set some elements of the vector + double norm = 0; + for (unsigned int k=0; k (k,2.*k); + + // Ugly, but equal. + norm = std::max (norm,std::fabs (std::sqrt ((k*k + 2.*k*2.*k)))); + } + + v.compress (VectorOperation::add); + + // then check the norm + Assert (v.linfty_norm() == norm, 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 --git a/tests/petsc_complex/19.output b/tests/petsc_complex/19.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/petsc_complex/19.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/petsc_complex/20.cc b/tests/petsc_complex/20.cc new file mode 100644 index 0000000000..0774b2cef2 --- /dev/null +++ b/tests/petsc_complex/20.cc @@ -0,0 +1,100 @@ +// --------------------------------------------------------------------- +// $Id: 23.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*(Vector) on two vectors that are +// not orthogonal + +#include "../tests.h" +#include +#include +#include +#include + + +void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) +{ + // set only certain elements of each + // vector, and record the expected scalar + // product + PetscScalar product = PetscScalar(0); + for (unsigned int i=0; i (i, (i%2)*2.0); + v(i) = vi; + if (i%3 == 0) + { + const PetscScalar wi = std::complex (5.0-i,2.5*(i%6)); + w(i) = wi; + product += PetscConj(vi)*wi; + } + } + + v.compress (VectorOperation::add); + w.compress (VectorOperation::add); + + // make sure the scalar product is zero + Assert (v*w == product, 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); + 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; + }; +} diff --git a/tests/petsc_complex/20.output b/tests/petsc_complex/20.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/petsc_complex/20.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/petsc_complex/CMakeLists.txt b/tests/petsc_complex/CMakeLists.txt new file mode 100644 index 0000000000..d8809e062e --- /dev/null +++ b/tests/petsc_complex/CMakeLists.txt @@ -0,0 +1,6 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9) +INCLUDE(../setup_testsubproject.cmake) +PROJECT(testsuite CXX) +IF(DEAL_II_WITH_PETSC AND PETSC_WITH_COMPLEX) + DEAL_II_PICKUP_TESTS() +ENDIF() diff --git a/tests/petsc_complex/element_access_00.cc b/tests/petsc_complex/element_access_00.cc new file mode 100644 index 0000000000..a088479882 --- /dev/null +++ b/tests/petsc_complex/element_access_00.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. +// +// --------------------------------------------------------------------- + + +// deal.II includes +#include "../tests.h" +#include + +#include +#include +#include + +#include + +// test dealii::internal::VectorReference::real() +// test dealii::internal::VectorReference::imag() +// on vector + +// vector elements +void test_vector (PETScWrappers::Vector &v) +{ + deallog << "Check vector access" << std::endl; + + // fill up a vector with some numbers + for (unsigned int k=0; k (k,v.size()-k); + + v.compress (VectorOperation::add); + + // check that is what we get by casting PetscScalar to std::real() + // and std::imag() + for (unsigned int k=0; k > (v(k)).real ()==k) && + (static_cast > (v(k)).imag ()==v.size()-k), + ExcInternalError()); + + // check that is what we get by + // dealii::internal::VectorReference::real() and + // dealii::internal::VectorReference::imag() + for (unsigned int k=0; k + +#include +#include +#include + +#include + +// test read/write access to matrices using explicit cast always. + +// sparse matrix elements +void test_matrix (PETScWrappers::SparseMatrix &m) +{ + deallog << "Check 01 matrix access" << std::endl; + + // fill up a matrix with some numbers + for (unsigned int k=0; k (k+l); + PetscReal el_i = static_cast (-1.*(k+l)); + m.set (k,l, std::complex (el_r,el_i)); + } + + m.compress (VectorOperation::add); + + for (unsigned int k=0; k (k+l); + PetscReal el_i = static_cast (-1.*(k+l)); + + Assert ((m(k,l).real ()==el_r) && (m(k,l).imag ()==el_i), + ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + +int main (int argc, char **argv) +{ + std::ofstream logfile ("output"); + dealii::deallog.attach (logfile); + dealii::deallog.depth_console (0); + deallog.threshold_double(1.e-10); + + try + { + PetscInitialize (&argc, &argv, (char *) 0, (char *) 0); + { + PETScWrappers::SparseMatrix m (5,5,5); + test_matrix (m); + + deallog << "matrix:" << std::endl; + m.print (logfile); + } + PetscFinalize (); + } + + + 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; + } + + logfile << std::endl; + + return 0; +} + + diff --git a/tests/petsc_complex/element_access_01.output b/tests/petsc_complex/element_access_01.output new file mode 100644 index 0000000000..faa0818801 --- /dev/null +++ b/tests/petsc_complex/element_access_01.output @@ -0,0 +1,30 @@ + +DEAL::Check 01 matrix access +DEAL::OK +DEAL::matrix: +(0,0) (0.00000,0.00000) +(0,1) (1.00000,-1.00000) +(0,2) (2.00000,-2.00000) +(0,3) (3.00000,-3.00000) +(0,4) (4.00000,-4.00000) +(1,0) (1.00000,-1.00000) +(1,1) (2.00000,-2.00000) +(1,2) (3.00000,-3.00000) +(1,3) (4.00000,-4.00000) +(1,4) (5.00000,-5.00000) +(2,0) (2.00000,-2.00000) +(2,1) (3.00000,-3.00000) +(2,2) (4.00000,-4.00000) +(2,3) (5.00000,-5.00000) +(2,4) (6.00000,-6.00000) +(3,0) (3.00000,-3.00000) +(3,1) (4.00000,-4.00000) +(3,2) (5.00000,-5.00000) +(3,3) (6.00000,-6.00000) +(3,4) (7.00000,-7.00000) +(4,0) (4.00000,-4.00000) +(4,1) (5.00000,-5.00000) +(4,2) (6.00000,-6.00000) +(4,3) (7.00000,-7.00000) +(4,4) (8.00000,-8.00000) + diff --git a/tests/petsc_complex/element_access_02.cc b/tests/petsc_complex/element_access_02.cc new file mode 100644 index 0000000000..0b66ad3801 --- /dev/null +++ b/tests/petsc_complex/element_access_02.cc @@ -0,0 +1,99 @@ + +// --------------------------------------------------------------------- +// $Id: element_access_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. +// +// --------------------------------------------------------------------- + + +// deal.II includes +#include "../tests.h" +#include + +#include +#include +#include + +// sparse matrix elements +void test (PETScWrappers::SparseMatrix &m) +{ + deallog << "Check matrix access" << std::endl; + + // fill up a matrix with some numbers + for (unsigned int k=0; kl) + m.set (k,l, PetscScalar (k+l,-1.*(k+l))); + + m.compress (VectorOperation::add); + + // check the matrix is correctly filled + for (unsigned int k=0; k +#include + +#include +#include +#include + +#include + +// test read/write element access using unsigned int and double. + + +// sparse matrix elements +void test_matrix (PETScWrappers::SparseMatrix &m) +{ + deallog << "Check matrix access" << std::endl; + + const double r = dealii::numbers::PI; + const double i = -1.*dealii::numbers::PI; + + // fill up a matrix with some numbers + for (unsigned int k=0; k +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include + +#include +#include + +using namespace dealii; + +static const unsigned int dim = 2; + +void test () +{ + + MPI_Comm mpi_communicator (MPI_COMM_WORLD); + const unsigned int n_mpi_processes (Utilities::MPI::n_mpi_processes(mpi_communicator)); + const unsigned int this_mpi_process (Utilities::MPI::this_mpi_process(mpi_communicator)); + + ConditionalOStream pcout (std::cout, + (Utilities::MPI::this_mpi_process(mpi_communicator) + == 0)); + + parallel::distributed::Triangulation tria(mpi_communicator, + typename Triangulation::MeshSmoothing + (Triangulation::smoothing_on_refinement | + Triangulation::smoothing_on_coarsening)); + + + GridGenerator::hyper_cube (tria, -1,0); + tria.refine_global (2); + + + const unsigned int poly_degree = 1; + FE_Q fe(poly_degree); + + DoFHandler dof_handler(tria); + dof_handler.distribute_dofs(fe); + + IndexSet locally_owned_dofs = dof_handler.locally_owned_dofs (); + IndexSet locally_relevant_dofs; + DoFTools::extract_locally_relevant_dofs (dof_handler,locally_relevant_dofs); + + PETScWrappers::MPI::Vector vector, vector_locally_relevant; + TrilinosWrappers::MPI::Vector vector_Re, vector_Re_locally_relevant, + vector_Im, vector_Im_locally_relevant; + vector.reinit(locally_owned_dofs, mpi_communicator); + vector_locally_relevant.reinit (locally_owned_dofs, + locally_relevant_dofs,mpi_communicator); + + vector_Re.reinit(locally_owned_dofs, mpi_communicator); + vector_Re_locally_relevant.reinit (locally_owned_dofs, + locally_relevant_dofs,mpi_communicator); + + vector_Im.reinit(locally_owned_dofs, mpi_communicator); + vector_Im_locally_relevant.reinit (locally_owned_dofs, + locally_relevant_dofs,mpi_communicator); + + const types::global_dof_index n_local_dofs = locally_owned_dofs.n_elements(); + + ConstraintMatrix constraints; + constraints.reinit(locally_relevant_dofs); + DoFTools::make_hanging_node_constraints (dof_handler, constraints); + constraints.close (); + //set vector: + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + for (unsigned int i = 0; i < locally_owned_dofs.n_elements(); i++) + { + const PetscScalar val = 1.0+myid+ (myid+i%2)*2.0*PETSC_i; + vector ( locally_owned_dofs.nth_index_in_set(i)) = val; + vector_Re( locally_owned_dofs.nth_index_in_set(i)) = PetscRealPart (val); + vector_Im( locally_owned_dofs.nth_index_in_set(i)) = PetscImaginaryPart (val); + + } + vector.compress(VectorOperation::insert); + vector_Re.compress(VectorOperation::insert); + vector_Im.compress(VectorOperation::insert); + + vector_locally_relevant = vector; + vector_Re_locally_relevant = vector_Re; + vector_Im_locally_relevant = vector_Im; + + //test get_function_values: + { + //a separate quadrature formula + //enough for mass and kinetic matrices assembly + QGauss quadrature_formula(poly_degree+1); + FEValues fe_values (fe, quadrature_formula, + update_values | update_JxW_values); + + const unsigned int dofs_per_cell = fe.dofs_per_cell; + const unsigned int n_q_points = quadrature_formula.size(); + + std::vector values(n_q_points); + std::vector values_Re(n_q_points), + values_Im(n_q_points); + + std::vector local_dof_indices (dofs_per_cell); + + typename DoFHandler::active_cell_iterator + cell = dof_handler.begin_active (), + endc = dof_handler.end (); + for (; cell!=endc; ++cell) + if (cell->is_locally_owned()) + { + fe_values.reinit (cell); + fe_values.get_function_values (vector_locally_relevant, values); + fe_values.get_function_values (vector_Re_locally_relevant, values_Re); + fe_values.get_function_values (vector_Im_locally_relevant, values_Im); + + for (unsigned int q=0; q +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include + +using namespace dealii; + +template +void test (const unsigned int poly_degree = 1) +{ + + MPI_Comm mpi_communicator (MPI_COMM_WORLD); + const unsigned int n_mpi_processes (Utilities::MPI::n_mpi_processes(mpi_communicator)); + const unsigned int this_mpi_process (Utilities::MPI::this_mpi_process(mpi_communicator)); + + parallel::distributed::Triangulation tria(mpi_communicator, + typename Triangulation::MeshSmoothing + (Triangulation::smoothing_on_refinement | + Triangulation::smoothing_on_coarsening)); + + GridGenerator::hyper_cube (tria, -1,0); + tria.refine_global (3); + + FE_Q fe(poly_degree); + + DoFHandler dof_handler(tria); + dof_handler.distribute_dofs(fe); + + IndexSet locally_owned_dofs = dof_handler.locally_owned_dofs (); + IndexSet locally_relevant_dofs; + DoFTools::extract_locally_relevant_dofs (dof_handler,locally_relevant_dofs); + + PETScWrappers::MPI::Vector vector; + PETScWrappers::MPI::SparseMatrix mass_matrix; + + + vector.reinit(locally_owned_dofs, mpi_communicator); + const types::global_dof_index n_local_dofs = locally_owned_dofs.n_elements(); + mass_matrix.reinit (mpi_communicator, + dof_handler.n_dofs(), + dof_handler.n_dofs(), + n_local_dofs, + n_local_dofs, + dof_handler.max_couplings_between_dofs()); + + ConstraintMatrix constraints; + constraints.reinit(locally_relevant_dofs); + DoFTools::make_hanging_node_constraints (dof_handler, constraints); + constraints.close (); + + //assemble mass matrix: + mass_matrix = 0.0; + { + QGauss quadrature_formula(poly_degree+1); + FEValues fe_values (fe, quadrature_formula, + update_values | update_gradients | update_JxW_values); + + const unsigned int dofs_per_cell = fe.dofs_per_cell; + const unsigned int n_q_points = quadrature_formula.size(); + + FullMatrix cell_mass_matrix (dofs_per_cell, dofs_per_cell); + + std::vector local_dof_indices (dofs_per_cell); + + typename DoFHandler::active_cell_iterator + cell = dof_handler.begin_active (), + endc = dof_handler.end (); + for (; cell!=endc; ++cell) + if (cell->is_locally_owned()) + { + fe_values.reinit (cell); + cell_mass_matrix = PetscScalar(0); + + for (unsigned int q_point=0; q_pointget_dof_indices (local_dof_indices); + + constraints + .distribute_local_to_global (cell_mass_matrix, + local_dof_indices, + mass_matrix); + } + mass_matrix.compress (VectorOperation::add); + } + + for (unsigned int i = 0; i < locally_owned_dofs.n_elements(); i++) + { + double re = 0, + im = 0; + if ( i % 2 ) + { + re = 1.0*i; + im = 1.0*(this_mpi_process+1); + } + else if (i % 3) + { + re = 0.0; + im = -1.0*(this_mpi_process+1); + } + else + { + re = 3.0*i; + im = 0.0; + } + const PetscScalar val = re+im*PETSC_i; + vector ( locally_owned_dofs.nth_index_in_set(i)) = val; + } + vector.compress(VectorOperation::insert); + constraints.distribute(vector); + + deallog<<"symmetric: "< norm1 = vector*tmp; + deallog<<"(conj(vector),M vector): "< norm2 = + mass_matrix.matrix_scalar_product(vector, vector); + deallog<<"matrix_scalar_product(vec,vec): "< norm3 = + mass_matrix.matrix_norm_square(vector); + deallog<<"matrix_norm_square(vec): "<(); + +} \ No newline at end of file diff --git a/tests/petsc_complex/parallel_sparse_matrix_01.mpirun=3.output b/tests/petsc_complex/parallel_sparse_matrix_01.mpirun=3.output new file mode 100644 index 0000000000..a75f75beb6 --- /dev/null +++ b/tests/petsc_complex/parallel_sparse_matrix_01.mpirun=3.output @@ -0,0 +1,12 @@ + +DEAL::symmetric: 1 +DEAL::hermitian: 1 +DEAL::(conj(vector),M vector): +DEAL::real part: 337.563 +DEAL::imaginary part: 0 +DEAL::matrix_scalar_product(vec,vec): +DEAL::real part: 337.563 +DEAL::imaginary part: 0 +DEAL::matrix_norm_square(vec): +DEAL::real part: 337.563 +DEAL::imaginary part: 0 diff --git a/tests/petsc_complex/solver_real_01.cc b/tests/petsc_complex/solver_real_01.cc new file mode 100644 index 0000000000..9c045ca958 --- /dev/null +++ b/tests/petsc_complex/solver_real_01.cc @@ -0,0 +1,97 @@ +// --------------------------------------------------------------------- +// $Id: solver_real_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. +// +// --------------------------------------------------------------------- + + +// test the PETSc Richardson solver + +// Note: This is (almost) a clone of the tests/petsc/solver_01.cc + + +#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; + // it needs to be expected for the + // richardson solver that we end up + // here, so don't 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 (VectorOperation::add); + f.compress (VectorOperation::add); + u.compress (VectorOperation::add); + + PETScWrappers::SolverRichardson solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } +} + diff --git a/tests/petsc_complex/solver_real_01.output b/tests/petsc_complex/solver_real_01.output new file mode 100644 index 0000000000..94aba8fe1f --- /dev/null +++ b/tests/petsc_complex/solver_real_01.output @@ -0,0 +1,18 @@ + +DEAL::Size 32 Unknowns 961 +DEAL::Solver type: N6dealii13PETScWrappers16SolverRichardsonE +DEAL::Starting value 7.750 +DEAL::Failure step 100 value 4.004 +DEAL:: +-------------------------------------------------------- +An error occurred in file in function + void dealii::PETScWrappers::SolverBase::solve(const dealii::PETScWrappers::MatrixBase&, dealii::PETScWrappers::VectorBase&, const dealii::PETScWrappers::VectorBase&, const dealii::PETScWrappers::PreconditionerBase&) +The violated condition was: + false +The name and call sequence of the exception was: + SolverControl::NoConvergence (solver_control.last_step(), solver_control.last_value()) +Additional Information: +Iterative method reported convergence failure in step 100 with residual 4.00437 +-------------------------------------------------------- + +DEAL::Solver stopped after 100 iterations diff --git a/tests/petsc_complex/solver_real_02.cc b/tests/petsc_complex/solver_real_02.cc new file mode 100644 index 0000000000..28f4e0484b --- /dev/null +++ b/tests/petsc_complex/solver_real_02.cc @@ -0,0 +1,96 @@ +// --------------------------------------------------------------------- +// $Id: solver_real_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. +// +// --------------------------------------------------------------------- + + +// test the PETSc Chebychev solver + +// Note: This is (almost) a clone of the tests/petsc/solver_02.cc + +#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; + // just like for Richardson: we end up + // here normally for this solver + } + + 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 (VectorOperation::add); + f.compress (VectorOperation::add); + u.compress (VectorOperation::add); + + PETScWrappers::SolverChebychev solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + +} + diff --git a/tests/petsc_complex/solver_real_02.output b/tests/petsc_complex/solver_real_02.output new file mode 100644 index 0000000000..de02386e0c --- /dev/null +++ b/tests/petsc_complex/solver_real_02.output @@ -0,0 +1,18 @@ + +DEAL::Size 32 Unknowns 961 +DEAL::Solver type: N6dealii13PETScWrappers15SolverChebychevE +DEAL::Starting value 7.551 +DEAL::Failure step 100 value 2.942 +DEAL:: +-------------------------------------------------------- +An error occurred in file in function + void dealii::PETScWrappers::SolverBase::solve(const dealii::PETScWrappers::MatrixBase&, dealii::PETScWrappers::VectorBase&, const dealii::PETScWrappers::VectorBase&, const dealii::PETScWrappers::PreconditionerBase&) +The violated condition was: + false +The name and call sequence of the exception was: + SolverControl::NoConvergence (solver_control.last_step(), solver_control.last_value()) +Additional Information: +Iterative method reported convergence failure in step 100 with residual 2.94179 +-------------------------------------------------------- + +DEAL::Solver stopped after 100 iterations diff --git a/tests/petsc_complex/solver_real_03.cc b/tests/petsc_complex/solver_real_03.cc new file mode 100644 index 0000000000..0b69601e07 --- /dev/null +++ b/tests/petsc_complex/solver_real_03.cc @@ -0,0 +1,95 @@ +// --------------------------------------------------------------------- +// $Id: solver_real_03.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. +// +// --------------------------------------------------------------------- + + +// test the PETSc CG solver + +// Note: This is (almost) a clone of the tests/petsc/solver_03.cc + +#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 (VectorOperation::add); + f.compress (VectorOperation::add); + u.compress (VectorOperation::add); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + +} + diff --git a/tests/petsc_complex/solver_real_03.output b/tests/petsc_complex/solver_real_03.output new file mode 100644 index 0000000000..2237281800 --- /dev/null +++ b/tests/petsc_complex/solver_real_03.output @@ -0,0 +1,6 @@ + +DEAL::Size 32 Unknowns 961 +DEAL::Solver type: N6dealii13PETScWrappers8SolverCGE +DEAL::Starting value 7.750 +DEAL::Convergence step 41 value 0.0006730 +DEAL::Solver stopped after 41 iterations diff --git a/tests/petsc_complex/solver_real_03_mf.cc b/tests/petsc_complex/solver_real_03_mf.cc new file mode 100644 index 0000000000..b3197e70ea --- /dev/null +++ b/tests/petsc_complex/solver_real_03_mf.cc @@ -0,0 +1,105 @@ +// --------------------------------------------------------------------- +// $Id: solver_03_mf.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. +// +// --------------------------------------------------------------------- + + +// test the PETSc CG solver with PETSc MatrixFree class + +// Note: This is (almost) a clone of the tests/petsc/solver_03_mf.cc + +#include "../tests.h" +#include "../petsc/petsc_mf_testmatrix.h" // It is tempting to copy +// ../petsc/petsc_mf_testmatrix.h +// into this directory and +// play with it, but, by +// using *that* file +// directly is instead +// represents a test of +// syntax compatibility +// between petsc-scalar=real +// and assigning real +// numbers to a possibly +// complex matrix where +// petsc-scalar=complex. +#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 (VectorOperation::add); + f.compress (VectorOperation::add); + u.compress (VectorOperation::add); + + PETScWrappers::SolverCG solver(control); + PETScWrappers::PreconditionNone preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + +} + diff --git a/tests/petsc_complex/solver_real_03_mf.output b/tests/petsc_complex/solver_real_03_mf.output new file mode 100644 index 0000000000..bea3eb1acb --- /dev/null +++ b/tests/petsc_complex/solver_real_03_mf.output @@ -0,0 +1,6 @@ + +DEAL::Size 32 Unknowns 961 +DEAL::Solver type: N6dealii13PETScWrappers8SolverCGE +DEAL::Starting value 31.00 +DEAL::Convergence step 43 value 0.0008189 +DEAL::Solver stopped after 43 iterations diff --git a/tests/petsc_complex/solver_real_04.cc b/tests/petsc_complex/solver_real_04.cc new file mode 100644 index 0000000000..9ace49088c --- /dev/null +++ b/tests/petsc_complex/solver_real_04.cc @@ -0,0 +1,95 @@ +// --------------------------------------------------------------------- +// $Id: solver_real_04.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. +// +// --------------------------------------------------------------------- + + +// test the PETSc BiCG solver + +// Note: This is (almost) a clone of the tests/petsc/solver_03.cc + +#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 (VectorOperation::add); + f.compress (VectorOperation::add); + u.compress (VectorOperation::add); + + PETScWrappers::SolverBiCG solver(control); + PETScWrappers::PreconditionJacobi preconditioner(A); + check_solve (solver, A,u,f, preconditioner); + } + +} + diff --git a/tests/petsc_complex/solver_real_04.output b/tests/petsc_complex/solver_real_04.output new file mode 100644 index 0000000000..d69ef9440f --- /dev/null +++ b/tests/petsc_complex/solver_real_04.output @@ -0,0 +1,6 @@ + +DEAL::Size 32 Unknowns 961 +DEAL::Solver type: N6dealii13PETScWrappers10SolverBiCGE +DEAL::Starting value 7.750 +DEAL::Convergence step 41 value 0.0006730 +DEAL::Solver stopped after 41 iterations diff --git a/tests/petsc_complex/sparse_matrix_01.cc b/tests/petsc_complex/sparse_matrix_01.cc new file mode 100644 index 0000000000..7d7a749b1c --- /dev/null +++ b/tests/petsc_complex/sparse_matrix_01.cc @@ -0,0 +1,112 @@ +// --------------------------------------------------------------------- +// $Id sparse_matrix_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. +// +// --------------------------------------------------------------------- + + +// check SparseMatrix::add(other, factor) + +#include "../tests.h" +#include +#include +#include +#include +#include + + +void test () +{ + const unsigned int s = 10; + PETScWrappers::SparseMatrix m(s,s,s); + for (unsigned int k=0; k +#include +#include +#include +#include + + +void test () +{ + const unsigned int s = 10; + PETScWrappers::Vector v(s); + for (unsigned int k=0; k +#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 (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) +{ + // set the first vector + for (unsigned int k=0; k +#include +#include +#include + + +void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) +{ + // 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("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 (v,w); + + // SOme output + 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_complex/vector_equality_1.output b/tests/petsc_complex/vector_equality_1.output new file mode 100644 index 0000000000..450c4b40d9 --- /dev/null +++ b/tests/petsc_complex/vector_equality_1.output @@ -0,0 +1,6 @@ + +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_complex/vector_equality_2.cc b/tests/petsc_complex/vector_equality_2.cc new file mode 100644 index 0000000000..53aa85cce2 --- /dev/null +++ b/tests/petsc_complex/vector_equality_2.cc @@ -0,0 +1,96 @@ +// --------------------------------------------------------------------- +// $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 (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("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 (v,w); + + // Output + 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_complex/vector_equality_2.output b/tests/petsc_complex/vector_equality_2.output new file mode 100644 index 0000000000..b49f220c60 --- /dev/null +++ b/tests/petsc_complex/vector_equality_2.output @@ -0,0 +1,6 @@ + +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_complex/vector_print.cc b/tests/petsc_complex/vector_print.cc new file mode 100644 index 0000000000..7d7b64cf1b --- /dev/null +++ b/tests/petsc_complex/vector_print.cc @@ -0,0 +1,77 @@ +// --------------------------------------------------------------------- +// $Id: vector_print.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. +// +// --------------------------------------------------------------------- + + + +// verify that VectorBase::print uses the precision parameter correctly and +// restores the previous value of the stream precision + +#include "../tests.h" +#include +#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 k=0; k +#include +#include +#include + + +void test (PETScWrappers::Vector &v, + PETScWrappers::Vector &w) +{ + // set the first vector + for (unsigned int k=0; k (k,0.5*k); + + // copy elements by reference + for (unsigned int k=0; k +#include +#include +#include +#include + + +std::ofstream logfile ("output"); + +int main (int argc, char **argv) +{ + deallog.attach (logfile); + deallog.depth_console (1); + + try + { + logfile << "Initializing SLEPc (PETSc): " + << std::flush; + + SlepcInitialize (&argc, &argv, 0, 0); + { + logfile << "ok" + << std::endl; + + // Do something simple with PETSc + logfile << "Using PetscScalar:" + << std::endl; + + const PetscScalar pi_1i = numbers::PI + 1.*PETSC_i; + const PetscScalar two = 2.; + + logfile << " pi+1i: " << pi_1i + << std::endl + << " two: " << two + << std::endl + << " two times pi+1i: " << two *pi_1i + << std::endl; + + + logfile << "Finalizing SLEPc (PETSc): " + << std::flush; + + } + SlepcFinalize (); + + logfile << "ok" + << std::endl << 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/slepc_complex/00.output b/tests/slepc_complex/00.output new file mode 100644 index 0000000000..10a07daa27 --- /dev/null +++ b/tests/slepc_complex/00.output @@ -0,0 +1,8 @@ + +Initializing SLEPc (PETSc): ok +Using PetscScalar: + pi+1i: (3.14159,1.00000) + two: (2.00000,0.00000) + two times pi+1i: (6.28319,2.00000) +Finalizing SLEPc (PETSc): ok + diff --git a/tests/slepc_complex/CMakeLists.txt b/tests/slepc_complex/CMakeLists.txt new file mode 100644 index 0000000000..a16db9093b --- /dev/null +++ b/tests/slepc_complex/CMakeLists.txt @@ -0,0 +1,6 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9) +INCLUDE(../setup_testsubproject.cmake) +PROJECT(testsuite CXX) +IF(DEAL_II_WITH_PETSC AND DEAL_II_WITH_SLEPC AND PETSC_WITH_COMPLEX) + DEAL_II_PICKUP_TESTS() +ENDIF()