From: guido Date: Wed, 5 May 1999 11:29:39 +0000 (+0000) Subject: PreconditionMG X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79050d85ea37b1e331209fa1398e8bf0fddd7246;p=dealii-svn.git PreconditionMG git-svn-id: https://svn.dealii.org/trunk@1271 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/multigrid/mg_base.h b/deal.II/deal.II/include/multigrid/mg_base.h index c30ef1930c..2a45a3a826 100644 --- a/deal.II/deal.II/include/multigrid/mg_base.h +++ b/deal.II/deal.II/include/multigrid/mg_base.h @@ -10,6 +10,7 @@ #include #include +#include #define FLOAT float @@ -20,8 +21,15 @@ * grid solution in a derived class. */ class MGCoarseGridSolver + : + public Subscriptor { public: + /** + * Virtual destructor. + */ + virtual ~MGCoarseGridSolver(); + /** * Coarse grid solving method. * This is only the interface for @@ -98,7 +106,9 @@ class MGSmootherIdentity * * @author Wolfgang Bangerth, Guido Kanschat, 1999 */ -class MGTransferBase : public Subscriptor +class MGTransferBase + : + public Subscriptor { public: /** @@ -274,6 +284,8 @@ class MGCoarseGridLACIteration * @author Guido Kanschat, 1999 * */ class MGBase + : + public Subscriptor { private: MGBase(const MGBase&); @@ -368,6 +380,59 @@ class MGBase }; + +/** + * Multi-level preconditioner. + * Here, we collect all information needed for multi-level preconditioning + * and provide the standard interface for LAC iterative methods. + * + * The template parameter class #MG# is required to inherit #MGBase#. + * Furthermore, it needs functions #void copy_to_mg(const VECTOR&)# + * to store #src# in the right hand side of the multi-level method and + * #void copy_from_mg(VECTOR&)# to store the result of the v-cycle in #dst#. + * @author Guido Kanschat, 1999 + */ +template +class PreconditionMG +{ + public: + /** + * Constructor. + * Arguments are the multigrid object, + * pre-smoother, post-smoother and + * coarse grid solver. + */ + PreconditionMG(MG& mg, + const MGSmootherBase& pre, + const MGSmootherBase& post, + const MGCoarseGridSolver& coarse); + /** + * Preconditioning operator. + * This is the operator used by LAC + * iterative solvers. + */ + void operator() (VECTOR& dst, const VECTOR& src) const; + private: + /** + * The mulrigrid object. + */ + SmartPointer multigrid; + /** + * The pre-smoothing object. + */ + SmartPointer pre; + /** + * The post-smoothing object. + */ + SmartPointer post; + /** + * The coarse grid solver. + */ + SmartPointer coarse; +}; + + + template MGCoarseGridLACIteration ::MGCoarseGridLACIteration(SOLVER& s, const MATRIX& m, const PRECOND& p) @@ -437,5 +502,28 @@ MGMatrix::operator[](unsigned int i) const return vector::operator[](i-minlevel); } +////////////////////////////////////////////////////////////////////// + +template +PreconditionMG::PreconditionMG(MG& mg, + const MGSmootherBase& pre, + const MGSmootherBase& post, + const MGCoarseGridSolver& coarse) + : + multigrid(&mg), + pre(&pre), + post(&post), + coarse(&coarse) +{} + +template +void +PreconditionMG::operator() (VECTOR& dst, const VECTOR& src) const +{ + multigrid->copy_to_mg(src); + multigrid->vcycle(*pre, *post, *coarse); + multigrid->copy_from_mg(dst); +} + #endif diff --git a/deal.II/deal.II/source/multigrid/mg_base.cc b/deal.II/deal.II/source/multigrid/mg_base.cc index 73a80470fb..b7e475a798 100644 --- a/deal.II/deal.II/source/multigrid/mg_base.cc +++ b/deal.II/deal.II/source/multigrid/mg_base.cc @@ -79,6 +79,12 @@ MGBase::level_mgstep(unsigned level, } +////////////////////////////////////////////////////////////////////// + +MGCoarseGridSolver::~MGCoarseGridSolver() +{} + + ////////////////////////////////////////////////////////////////////// MGTransferBase::~MGTransferBase() diff --git a/deal.II/lac/include/lac/mgbase.h b/deal.II/lac/include/lac/mgbase.h index 54c15ce614..4192a16bd6 100644 --- a/deal.II/lac/include/lac/mgbase.h +++ b/deal.II/lac/include/lac/mgbase.h @@ -10,6 +10,7 @@ #include #include +#include #define FLOAT float @@ -20,8 +21,15 @@ * grid solution in a derived class. */ class MGCoarseGridSolver + : + public Subscriptor { public: + /** + * Virtual destructor. + */ + virtual ~MGCoarseGridSolver(); + /** * Coarse grid solving method. * This is only the interface for @@ -98,7 +106,9 @@ class MGSmootherIdentity * * @author Wolfgang Bangerth, Guido Kanschat, 1999 */ -class MGTransferBase : public Subscriptor +class MGTransferBase + : + public Subscriptor { public: /** @@ -274,6 +284,8 @@ class MGCoarseGridLACIteration * @author Guido Kanschat, 1999 * */ class MGBase + : + public Subscriptor { private: MGBase(const MGBase&); @@ -368,6 +380,59 @@ class MGBase }; + +/** + * Multi-level preconditioner. + * Here, we collect all information needed for multi-level preconditioning + * and provide the standard interface for LAC iterative methods. + * + * The template parameter class #MG# is required to inherit #MGBase#. + * Furthermore, it needs functions #void copy_to_mg(const VECTOR&)# + * to store #src# in the right hand side of the multi-level method and + * #void copy_from_mg(VECTOR&)# to store the result of the v-cycle in #dst#. + * @author Guido Kanschat, 1999 + */ +template +class PreconditionMG +{ + public: + /** + * Constructor. + * Arguments are the multigrid object, + * pre-smoother, post-smoother and + * coarse grid solver. + */ + PreconditionMG(MG& mg, + const MGSmootherBase& pre, + const MGSmootherBase& post, + const MGCoarseGridSolver& coarse); + /** + * Preconditioning operator. + * This is the operator used by LAC + * iterative solvers. + */ + void operator() (VECTOR& dst, const VECTOR& src) const; + private: + /** + * The mulrigrid object. + */ + SmartPointer multigrid; + /** + * The pre-smoothing object. + */ + SmartPointer pre; + /** + * The post-smoothing object. + */ + SmartPointer post; + /** + * The coarse grid solver. + */ + SmartPointer coarse; +}; + + + template MGCoarseGridLACIteration ::MGCoarseGridLACIteration(SOLVER& s, const MATRIX& m, const PRECOND& p) @@ -437,5 +502,28 @@ MGMatrix::operator[](unsigned int i) const return vector::operator[](i-minlevel); } +////////////////////////////////////////////////////////////////////// + +template +PreconditionMG::PreconditionMG(MG& mg, + const MGSmootherBase& pre, + const MGSmootherBase& post, + const MGCoarseGridSolver& coarse) + : + multigrid(&mg), + pre(&pre), + post(&post), + coarse(&coarse) +{} + +template +void +PreconditionMG::operator() (VECTOR& dst, const VECTOR& src) const +{ + multigrid->copy_to_mg(src); + multigrid->vcycle(*pre, *post, *coarse); + multigrid->copy_from_mg(dst); +} + #endif diff --git a/deal.II/lac/source/mgbase.cc b/deal.II/lac/source/mgbase.cc index 73a80470fb..b7e475a798 100644 --- a/deal.II/lac/source/mgbase.cc +++ b/deal.II/lac/source/mgbase.cc @@ -79,6 +79,12 @@ MGBase::level_mgstep(unsigned level, } +////////////////////////////////////////////////////////////////////// + +MGCoarseGridSolver::~MGCoarseGridSolver() +{} + + ////////////////////////////////////////////////////////////////////// MGTransferBase::~MGTransferBase()