From 0b805d02a3880697af7e800efa35542489730b83 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Thu, 10 Mar 2005 17:30:34 +0000 Subject: [PATCH] new PreconditionRichardson git-svn-id: https://svn.dealii.org/trunk@10079 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.html | 59 ++++++---- deal.II/lac/include/lac/precondition.h | 153 ++++++++++++++++++++++++- tests/lac/solver.cc | 21 +++- 3 files changed, 207 insertions(+), 26 deletions(-) diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html index 70c631a8b5..a98486c5b1 100644 --- a/deal.II/doc/news/changes.html +++ b/deal.II/doc/news/changes.html @@ -42,6 +42,13 @@ inconvenience this causes.
    +
  1. Changed: the file multigrid/mg_dof_tools.h was + renamed to multigrid/mg_tools.h in order to match the name + of the class contained. +
    + (GK 2005/03/09) +

    +
  2. Changed: DoFTools::make_flux_sparsity_pattern, MGTools::

  3. - Fixed: The BlockSparseMatrix class had no local - typedef value_type like all other classes, which + New: The PreconditionRichardson + implements a Richardson preconditioner. + +
    + (GK, 2005/03/10) +

    + +
  4. Fixed: The BlockSparseMatrix + class had no local typedef value_type like all other classes, which made it a little awkward to use in some places. This has now been fixed. +
    (WB, 2005/03/03)

    -
  5. - Fixed: The PETScWrappers::MatrixBase class - documented that adding or setting a value that hasn't been in - the sparsity pattern before will lead to an exception being - thrown. This is of course wrong: PETSc allocates matrix entries - dynamically, as needed. The documentation is now fixed. -
    - (WB, 2005/03/03) +

  6. Fixed: The PETScWrappers::MatrixBase class documented that adding + or setting a value that hasn't been in the sparsity pattern + before will lead to an exception being thrown. This is of + course wrong: PETSc allocates matrix entries dynamically, as + needed. The documentation is now fixed. +
    (WB, 2005/03/03)

    -
  7. - New: The SparseMatrix iterators had no operator - >, only an operator <. The missing operator - is now implemented. The same holds for the FullMatrix - class. -
    - (WB, 2005/03/01) +

  8. New: The SparseMatrix iterators + had no operator >, only an operator <. The missing operator is + now implemented. The same holds for the FullMatrix class. +
    (WB, 2005/03/01)

    -
  9. - Fixed: The SparseMatrix iterators could not be compared - using operator <: the compiler complained that a - private member was accessed. This is now fixed. -
    - (WB, 2005/03/01) +

  10. Fixed: The SparseMatrix + iterators could not be compared using operator <: the compiler complained + that a private member was accessed. This is now fixed. +
    (WB, 2005/03/01)

diff --git a/deal.II/lac/include/lac/precondition.h b/deal.II/lac/include/lac/precondition.h index e71047fae8..e4ee2156fa 100644 --- a/deal.II/lac/include/lac/precondition.h +++ b/deal.II/lac/include/lac/precondition.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors +// Copyright (C) 1998 - 2005 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -72,6 +72,97 @@ class PreconditionIdentity : public Subscriptor +/** + * Preconditioning with Richardson's method. This preconditioner just + * scales the vector with a constant relaxation factor provided by the + * #AdditionalData object. + * + * In Krylov-space methods, this preconditioner should not have any + * effect. Using SolverRichardson, the two relaxation parameters will + * be just multiplied. Still, this class is usefull in multigrid + * smoother objects (MGSmootherRelaxation). + * + * @author Guido Kanschat, 2005 + */ +class PreconditionRichardson : public Subscriptor +{ + public: + /** + * Parameters for Richardson + * preconditioner. + */ + class AdditionalData + { + public: + /** + * Constructor. Block size + * must be given since there + * is no reasonable default + * parameter. + */ + AdditionalData (const double relaxation = 1.); + + /** + * Relaxation parameter. + */ + double relaxation; + }; + + /** + * Constructor with optional + * setting of the relaxation + * parameter + */ + PreconditionRichardson(const AdditionalData = AdditionalData()); + + /** + * Change the relaxaton parameter + * in a way consistent with other + * preconditioners. + */ + void initialize (const AdditionalData parameters); + + /** + * Apply preconditioner. + */ + template + void vmult (VECTOR&, const VECTOR&) const; + + /** + * Apply transpose + * preconditioner. Since this is + * the identity, this function is + * the same as + * vmult(). + */ + template + void Tvmult (VECTOR&, const VECTOR&) const; + /** + * Apply preconditioner, adding to the previous value. + */ + template + void vmult_add (VECTOR&, const VECTOR&) const; + + /** + * Apply transpose + * preconditioner, adding. Since this is + * the identity, this function is + * the same as + * vmult_add(). + */ + template + void Tvmult_add (VECTOR&, const VECTOR&) const; + + private: + /** + * The relaxation parameter + * multiplied with the vectors. + */ + double relaxation; +}; + + + /** * Preconditioner using a matrix-builtin function. * This class forms a preconditioner suitable for the LAC solver @@ -641,6 +732,66 @@ PreconditionIdentity::Tvmult_add (VECTOR &dst, const VECTOR &src) const //----------------------------------------------------------------------// +inline +PreconditionRichardson::AdditionalData::AdditionalData ( + const double relaxation) + : + relaxation(relaxation) +{} + + +inline +PreconditionRichardson::PreconditionRichardson ( + const PreconditionRichardson::AdditionalData parameters) + : + relaxation(parameters.relaxation) +{} + + + +inline void +PreconditionRichardson::initialize ( + const PreconditionRichardson::AdditionalData parameters) +{ + relaxation = parameters.relaxation; +} + + + +template +inline void +PreconditionRichardson::vmult (VECTOR &dst, const VECTOR &src) const +{ + dst.equ(relaxation,src); +} + + + +template +inline void +PreconditionRichardson::Tvmult (VECTOR &dst, const VECTOR &src) const +{ + dst.equ(relaxation,src); +} + +template +inline void +PreconditionRichardson::vmult_add (VECTOR &dst, const VECTOR &src) const +{ + dst.add(relaxation,src); +} + + + +template +inline void +PreconditionRichardson::Tvmult_add (VECTOR &dst, const VECTOR &src) const +{ + dst.add(relaxation,src); +} + +//----------------------------------------------------------------------// + template inline void PreconditionRelaxation::initialize (const MATRIX &rA, diff --git a/tests/lac/solver.cc b/tests/lac/solver.cc index 3c905fc123..9c41ed07e8 100644 --- a/tests/lac/solver.cc +++ b/tests/lac/solver.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors +// Copyright (C) 1998 - 2005 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -99,6 +99,7 @@ int main() testproblem.five_point(A); PreconditionIdentity prec_no; + PreconditionRichardson prec_richardson(0.6); PreconditionSOR<> prec_sor; prec_sor.initialize(A, 1.2); PreconditionSSOR<> prec_ssor; @@ -157,12 +158,28 @@ int main() deallog.pop(); deallog.push("no"); - + + rich.set_omega(1./A.diag_element(0)); + check_solve(rich,A,u,f,prec_no); check_solve(cg,A,u,f,prec_no); check_solve(bicgstab,A,u,f,prec_no); check_solve(gmres,A,u,f,prec_no); check_solve(gmresright,A,u,f,prec_no); check_solve(qmrs,A,u,f,prec_no); + rich.set_omega(1.); + + deallog.pop(); + + deallog.push("rich"); + + rich.set_omega(1./A.diag_element(0)); + check_solve(rich,A,u,f,prec_richardson); + check_solve(cg,A,u,f,prec_richardson); + check_solve(bicgstab,A,u,f,prec_richardson); + check_solve(gmres,A,u,f,prec_richardson); + check_solve(gmresright,A,u,f,prec_richardson); + check_solve(qmrs,A,u,f,prec_richardson); + rich.set_omega(1.); deallog.pop(); -- 2.39.5