From: guido Date: Fri, 9 Apr 1999 15:23:18 +0000 (+0000) Subject: more multigrid X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b716a71c63a75598a992f3dac0f7a69ead43afe;p=dealii-svn.git more multigrid git-svn-id: https://svn.dealii.org/trunk@1117 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/multigrid/multigrid.h b/deal.II/deal.II/include/multigrid/multigrid.h index 7d60d21d34..81a59959b7 100644 --- a/deal.II/deal.II/include/multigrid/multigrid.h +++ b/deal.II/deal.II/include/multigrid/multigrid.h @@ -4,7 +4,7 @@ #define __multigrid_H /*---------------------------- multigrid.h ---------------------------*/ -#include +#include #include #include #include @@ -12,7 +12,7 @@ #include class MGTransferBase; - +class MGSmoother; /** @@ -72,30 +72,19 @@ class MultiGridBase * Prolongation and restriction object. */ SmartPointer transfer; - - /** Tranfer from dVector to - * MGVector. - * - * This function copies data from a - * dVector, that is, data on the - * locally finest level, into the - * corresponding levels of an - * MGVector. + + protected: + /** + * Number of pre-smoothing steps. Is used + * as a parameter to #pre_smooth#. */ - void copy_to_mg(vector >& dst, const Vector& src); - + unsigned n_pre_smooth; + /** - * Transfer from MGVector to - * Vector. - * - * Copies data from active portions - * of an MGVector into the - * respective positions of a - * Vector. All other entries of - * #src# are zero. + * Number of post-smoothing steps Is used + * as a parameter to #post_smooth#. */ - void copy_from_mg(Vector& dst, const vector >& src); - + unsigned n_post_smooth; /** * The actual v-cycle multigrid method. * This function is called on the @@ -105,44 +94,7 @@ class MultiGridBase * #coarse_grid_solution# and * proceeds back up. */ - void level_mgstep(unsigned level); - - protected: - /** - * Number of pre-smoothing steps. - */ - unsigned n_pre_smooth; - - /** - * Number of post-smoothing steps - */ - unsigned n_post_smooth; - /** - * The (pre-)smoothing algorithm. - * This function is required to - * perform #steps# iterations to - * smoothen the residual $Ax-b$. - * - * When overloading this function - * in derived classes, make sure - * that smoothing only applies to - * interior degrees of freedom of - * the actual level. - * - */ - virtual void smooth(unsigned level, - Vector& x, - const Vector& b, - unsigned steps) = 0; - - /** - * The post-smoothing algorithm. - * Defaults to #smooth#. - */ - virtual void post_smooth(unsigned level, - Vector& dst, - const Vector& src, - unsigned steps); + void level_mgstep(unsigned level, MGSmoother& smoother); /** * Apply residual operator on all @@ -164,7 +116,7 @@ class MultiGridBase * standard implementation doing * #10 * (n_pre_smooth + * n_post_smooth)# - * smoothing steps. + * smoothing steps of #pre_smooth#. */ virtual void coarse_grid_solution(unsigned l, Vector& dst, @@ -238,6 +190,68 @@ class MGTransferBase : public Subscriptor const Vector &src) const = 0; }; +/** + * Implementation of multigrid with matrices. + * While #MultiGridBase# was only an abstract framework for the v-cycle, + * here we have the implementation of the pure virtual functions defined there. + * Furthermore, level information is obtained from a triangulation object. + * + * @author Wolfgang Bangerth, Guido Kanschat, 1999 + */ +template +class MultiGrid +{ + public: + MultiGrid(const MGDoFHandler&); + + /** Transfer from dVector to + * MGVector. + * + * This function copies data from a + * dVector, that is, data on the + * locally finest level, into the + * corresponding levels of an + * MGVector. + */ + template + void copy_to_mg(vector >& dst, + const Vector& src) const; + + /** + * Transfer from multi-grid vector to + * normal vector. + * + * Copies data from active portions + * of an MGVector into the + * respective positions of a + * Vector. All other entries of + * #src# are zero. + */ + template + void copy_from_mg(Vector& dst, + const vector >& src) const; + private: + /** + * Associated #MGDoFHandler#. + */ + SmartPointer > dofs; + + /** + * Matrix structures for each level. + * These are generated by the constructor + * of #MultiGrid# and can be accessed + * later. + */ + vector matrix_structures; + + /** + * Matrices for each level. + * The matrices are prepared by + * the constructor of #MultiGrid# and can + * be accessed for assembling. + */ + vector > matrices; +}; /** diff --git a/deal.II/deal.II/include/numerics/multigrid.h b/deal.II/deal.II/include/numerics/multigrid.h index 7d60d21d34..81a59959b7 100644 --- a/deal.II/deal.II/include/numerics/multigrid.h +++ b/deal.II/deal.II/include/numerics/multigrid.h @@ -4,7 +4,7 @@ #define __multigrid_H /*---------------------------- multigrid.h ---------------------------*/ -#include +#include #include #include #include @@ -12,7 +12,7 @@ #include class MGTransferBase; - +class MGSmoother; /** @@ -72,30 +72,19 @@ class MultiGridBase * Prolongation and restriction object. */ SmartPointer transfer; - - /** Tranfer from dVector to - * MGVector. - * - * This function copies data from a - * dVector, that is, data on the - * locally finest level, into the - * corresponding levels of an - * MGVector. + + protected: + /** + * Number of pre-smoothing steps. Is used + * as a parameter to #pre_smooth#. */ - void copy_to_mg(vector >& dst, const Vector& src); - + unsigned n_pre_smooth; + /** - * Transfer from MGVector to - * Vector. - * - * Copies data from active portions - * of an MGVector into the - * respective positions of a - * Vector. All other entries of - * #src# are zero. + * Number of post-smoothing steps Is used + * as a parameter to #post_smooth#. */ - void copy_from_mg(Vector& dst, const vector >& src); - + unsigned n_post_smooth; /** * The actual v-cycle multigrid method. * This function is called on the @@ -105,44 +94,7 @@ class MultiGridBase * #coarse_grid_solution# and * proceeds back up. */ - void level_mgstep(unsigned level); - - protected: - /** - * Number of pre-smoothing steps. - */ - unsigned n_pre_smooth; - - /** - * Number of post-smoothing steps - */ - unsigned n_post_smooth; - /** - * The (pre-)smoothing algorithm. - * This function is required to - * perform #steps# iterations to - * smoothen the residual $Ax-b$. - * - * When overloading this function - * in derived classes, make sure - * that smoothing only applies to - * interior degrees of freedom of - * the actual level. - * - */ - virtual void smooth(unsigned level, - Vector& x, - const Vector& b, - unsigned steps) = 0; - - /** - * The post-smoothing algorithm. - * Defaults to #smooth#. - */ - virtual void post_smooth(unsigned level, - Vector& dst, - const Vector& src, - unsigned steps); + void level_mgstep(unsigned level, MGSmoother& smoother); /** * Apply residual operator on all @@ -164,7 +116,7 @@ class MultiGridBase * standard implementation doing * #10 * (n_pre_smooth + * n_post_smooth)# - * smoothing steps. + * smoothing steps of #pre_smooth#. */ virtual void coarse_grid_solution(unsigned l, Vector& dst, @@ -238,6 +190,68 @@ class MGTransferBase : public Subscriptor const Vector &src) const = 0; }; +/** + * Implementation of multigrid with matrices. + * While #MultiGridBase# was only an abstract framework for the v-cycle, + * here we have the implementation of the pure virtual functions defined there. + * Furthermore, level information is obtained from a triangulation object. + * + * @author Wolfgang Bangerth, Guido Kanschat, 1999 + */ +template +class MultiGrid +{ + public: + MultiGrid(const MGDoFHandler&); + + /** Transfer from dVector to + * MGVector. + * + * This function copies data from a + * dVector, that is, data on the + * locally finest level, into the + * corresponding levels of an + * MGVector. + */ + template + void copy_to_mg(vector >& dst, + const Vector& src) const; + + /** + * Transfer from multi-grid vector to + * normal vector. + * + * Copies data from active portions + * of an MGVector into the + * respective positions of a + * Vector. All other entries of + * #src# are zero. + */ + template + void copy_from_mg(Vector& dst, + const vector >& src) const; + private: + /** + * Associated #MGDoFHandler#. + */ + SmartPointer > dofs; + + /** + * Matrix structures for each level. + * These are generated by the constructor + * of #MultiGrid# and can be accessed + * later. + */ + vector matrix_structures; + + /** + * Matrices for each level. + * The matrices are prepared by + * the constructor of #MultiGrid# and can + * be accessed for assembling. + */ + vector > matrices; +}; /** diff --git a/deal.II/deal.II/source/multigrid/multigrid.cc b/deal.II/deal.II/source/multigrid/multigrid.cc index 835d134a7a..f17272409f 100644 --- a/deal.II/deal.II/source/multigrid/multigrid.cc +++ b/deal.II/deal.II/source/multigrid/multigrid.cc @@ -19,14 +19,15 @@ MultiGridBase::MultiGridBase(MGTransferBase& transfer, unsigned maxlevel, unsigned minlevel, unsigned pre_smooth, unsigned post_smooth) : + d(maxlevel-minlevel), + s(maxlevel-minlevel), maxlevel(maxlevel), minlevel(minlevel), transfer(&transfer), n_pre_smooth(pre_smooth), n_post_smooth(post_smooth) {} - void -MultiGridBase::level_mgstep(unsigned level) +MultiGridBase::level_mgstep(unsigned level, MGSmoother& smoother) { if (level == minlevel) { @@ -35,7 +36,7 @@ MultiGridBase::level_mgstep(unsigned level) } // smoothing of the residual by modifying s - smooth(level, d[level], s[level], n_pre_smooth); +// smooth(level, d[level], s[level], n_pre_smooth); // t = d-As level_residual(level, t, s[level], d[level]); @@ -43,31 +44,21 @@ MultiGridBase::level_mgstep(unsigned level) // make t rhs of lower level transfer->restrict(level, t, d[level-1]); // do recursion - level_mgstep(level-1); + level_mgstep(level-1, smoother); // do coarse grid correction transfer->prolongate(level, s[level], s[level-1]); // smoothing (modify s again) - post_smooth(level, d[level], s[level], n_post_smooth); +// post_smooth(level, d[level], s[level], n_post_smooth); } void -MultiGridBase::post_smooth(unsigned level, - Vector& dst, const Vector& src, - unsigned steps) -{ - smooth(level, dst, src, steps); -} - - - -void -MultiGridBase::coarse_grid_solution(unsigned level, - Vector& dst, - const Vector& src) +MultiGridBase::coarse_grid_solution(unsigned /*level*/, + Vector& /*dst*/, + const Vector& /*src*/) { - smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth)); +// smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth)); } diff --git a/deal.II/deal.II/source/numerics/multigrid.cc b/deal.II/deal.II/source/numerics/multigrid.cc index 835d134a7a..f17272409f 100644 --- a/deal.II/deal.II/source/numerics/multigrid.cc +++ b/deal.II/deal.II/source/numerics/multigrid.cc @@ -19,14 +19,15 @@ MultiGridBase::MultiGridBase(MGTransferBase& transfer, unsigned maxlevel, unsigned minlevel, unsigned pre_smooth, unsigned post_smooth) : + d(maxlevel-minlevel), + s(maxlevel-minlevel), maxlevel(maxlevel), minlevel(minlevel), transfer(&transfer), n_pre_smooth(pre_smooth), n_post_smooth(post_smooth) {} - void -MultiGridBase::level_mgstep(unsigned level) +MultiGridBase::level_mgstep(unsigned level, MGSmoother& smoother) { if (level == minlevel) { @@ -35,7 +36,7 @@ MultiGridBase::level_mgstep(unsigned level) } // smoothing of the residual by modifying s - smooth(level, d[level], s[level], n_pre_smooth); +// smooth(level, d[level], s[level], n_pre_smooth); // t = d-As level_residual(level, t, s[level], d[level]); @@ -43,31 +44,21 @@ MultiGridBase::level_mgstep(unsigned level) // make t rhs of lower level transfer->restrict(level, t, d[level-1]); // do recursion - level_mgstep(level-1); + level_mgstep(level-1, smoother); // do coarse grid correction transfer->prolongate(level, s[level], s[level-1]); // smoothing (modify s again) - post_smooth(level, d[level], s[level], n_post_smooth); +// post_smooth(level, d[level], s[level], n_post_smooth); } void -MultiGridBase::post_smooth(unsigned level, - Vector& dst, const Vector& src, - unsigned steps) -{ - smooth(level, dst, src, steps); -} - - - -void -MultiGridBase::coarse_grid_solution(unsigned level, - Vector& dst, - const Vector& src) +MultiGridBase::coarse_grid_solution(unsigned /*level*/, + Vector& /*dst*/, + const Vector& /*src*/) { - smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth)); +// smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth)); }