From 776f0548b991ff59c1faad0b2eb39cd730ab8f26 Mon Sep 17 00:00:00 2001 From: kronbichler Date: Tue, 29 Oct 2013 11:03:34 +0000 Subject: [PATCH] Fix an issue with the Chebyshev preconditioner. git-svn-id: https://svn.dealii.org/trunk@31479 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/lac/precondition.h | 13 ++- tests/lac/precondition_chebyshev_01.cc | 111 +++++++++++++++++++++ tests/lac/precondition_chebyshev_01.output | 5 + 3 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 tests/lac/precondition_chebyshev_01.cc create mode 100644 tests/lac/precondition_chebyshev_01.output diff --git a/deal.II/include/deal.II/lac/precondition.h b/deal.II/include/deal.II/lac/precondition.h index d2e059fd36..598152b2f3 100644 --- a/deal.II/include/deal.II/lac/precondition.h +++ b/deal.II/include/deal.II/lac/precondition.h @@ -1818,11 +1818,16 @@ PreconditionChebyshev::initialize (const MATRIX &matrix, cg_message.erase(0, pos+5); std::string first = cg_message; - first.erase(cg_message.find_first_of(" "), std::string::npos); + if (cg_message.find_first_of(" ") != std::string::npos) + first.erase(cg_message.find_first_of(" "), std::string::npos); std::istringstream(first) >> min_eigenvalue; - cg_message.erase(0, cg_message.find_last_of(" ")+1); - std::istringstream(cg_message) >> max_eigenvalue; + if (cg_message.find_last_of(" ") != std::string::npos) + { + cg_message.erase(0, cg_message.find_last_of(" ")+1); + std::istringstream(cg_message) >> max_eigenvalue; + } + else max_eigenvalue = min_eigenvalue; } else min_eigenvalue = max_eigenvalue = 1; @@ -1910,7 +1915,7 @@ PreconditionChebyshev::Tvmult (VECTOR &dst, (src, data.matrix_diagonal_inverse, true, 0., 1./theta, update1, update2, dst); - for (unsigned int k=0; kTvmult (update2, dst); const double rhokp = 1./(2.*sigma-rhok); diff --git a/tests/lac/precondition_chebyshev_01.cc b/tests/lac/precondition_chebyshev_01.cc new file mode 100644 index 0000000000..215456ab59 --- /dev/null +++ b/tests/lac/precondition_chebyshev_01.cc @@ -0,0 +1,111 @@ +// --------------------------------------------------------------------- +// $Id$ +// +// Copyright (C) 2005 - 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. +// +// --------------------------------------------------------------------- + + +// Tests PreconditionChebyshev::vmult and PreconditionChebyshev::Tvmult + + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include +#include +#include + + +class FullMatrixModified : public FullMatrix +{ +public: + FullMatrixModified (unsigned int size1, unsigned int size2) + : + FullMatrix(size1,size2) + {} + + double el(unsigned int i, unsigned int j) const + { + return this->operator()(i,j); + } +}; + + +void +check() +{ + const unsigned int size = 10; + FullMatrixModified m(size,size); + for (unsigned int i=0; i in (size), out(size); + for (unsigned int i=0; i > prec; + typename PreconditionChebyshev >::AdditionalData + data; + data.smoothing_range = 2 * size; + data.degree = 3; + prec.initialize(m, data); + + deallog << "Check vmult orig: "; + prec.vmult(out, in); + for (unsigned int i=0; i matrix_diagonal(size); + matrix_diagonal = 1; + data.matrix_diagonal_inverse = matrix_diagonal; + prec.initialize(m, data); + + deallog << "Check vmult diag: "; + prec.vmult(out, in); + for (unsigned int i=0; i