From: guido Date: Thu, 8 Apr 1999 15:15:13 +0000 (+0000) Subject: mg:level_step X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c560d56d5fc477d1a64853637eec4484ab67998;p=dealii-svn.git mg:level_step git-svn-id: https://svn.dealii.org/trunk@1096 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 b7811b0fe7..4c00b24dc2 100644 --- a/deal.II/deal.II/include/multigrid/multigrid.h +++ b/deal.II/deal.II/include/multigrid/multigrid.h @@ -5,8 +5,12 @@ /*---------------------------- multigrid.h ---------------------------*/ #include -#include +#include #include +#include + +class MGTransferBase; + /** * Basic matrix class for multigrid preconditioning. @@ -36,10 +40,20 @@ class MultiGridBase MultiGridBase(const MultiGridBase&); const MultiGridBase& operator=(const MultiGridBase&); - /** Auxiliary vectors. + /** + * Auxiliary vector. */ vector > d; + + /** + * Auxiliary vector. + */ vector > s; + + /** + * Auxiliary vector. + */ + Vector t; /** * Highest level of cells. @@ -50,7 +64,12 @@ class MultiGridBase * Level for coarse grid solution. */ unsigned minlevel; - + + /** + * Prolongation and restriction object. + */ + SmartPointer transfer; + /** Tranfer from dVector to * MGVector. * @@ -111,7 +130,7 @@ class MultiGridBase virtual void smooth(unsigned level, Vector& x, const Vector& b, - unsigned steps); + unsigned steps) = 0; /** * The post-smoothing algorithm. @@ -123,16 +142,26 @@ class MultiGridBase unsigned steps); /** - * Apply operator on all + * Apply residual operator on all * cells of a level. - * + * This is implemented in a + * derived class. */ - virtual void level_vmult(unsigned level, + virtual void level_residual(unsigned level, Vector& dst, - const Vector& src); + const Vector& src, + const Vector& rhs) = 0; /** * Solve exactly on coarsest grid. + * Usually, this function should + * be overloaded by a more + * sophisticated derived + * class. Still, there is a + * standard implementation doing + * #10 * (n_pre_smooth + + * n_post_smooth)# + * smoothing steps. */ virtual void coarse_grid_solution(unsigned l, Vector& dst, @@ -146,7 +175,9 @@ class MultiGridBase /** * Constructor, subject to change. */ - MultiGridBase(); + MultiGridBase(MGTransferBase& transfer, + unsigned maxlevel, unsigned minlevel, + unsigned pre_smooth, unsigned post_smooth); virtual ~MultiGridBase(); }; diff --git a/deal.II/deal.II/include/numerics/multigrid.h b/deal.II/deal.II/include/numerics/multigrid.h index b7811b0fe7..4c00b24dc2 100644 --- a/deal.II/deal.II/include/numerics/multigrid.h +++ b/deal.II/deal.II/include/numerics/multigrid.h @@ -5,8 +5,12 @@ /*---------------------------- multigrid.h ---------------------------*/ #include -#include +#include #include +#include + +class MGTransferBase; + /** * Basic matrix class for multigrid preconditioning. @@ -36,10 +40,20 @@ class MultiGridBase MultiGridBase(const MultiGridBase&); const MultiGridBase& operator=(const MultiGridBase&); - /** Auxiliary vectors. + /** + * Auxiliary vector. */ vector > d; + + /** + * Auxiliary vector. + */ vector > s; + + /** + * Auxiliary vector. + */ + Vector t; /** * Highest level of cells. @@ -50,7 +64,12 @@ class MultiGridBase * Level for coarse grid solution. */ unsigned minlevel; - + + /** + * Prolongation and restriction object. + */ + SmartPointer transfer; + /** Tranfer from dVector to * MGVector. * @@ -111,7 +130,7 @@ class MultiGridBase virtual void smooth(unsigned level, Vector& x, const Vector& b, - unsigned steps); + unsigned steps) = 0; /** * The post-smoothing algorithm. @@ -123,16 +142,26 @@ class MultiGridBase unsigned steps); /** - * Apply operator on all + * Apply residual operator on all * cells of a level. - * + * This is implemented in a + * derived class. */ - virtual void level_vmult(unsigned level, + virtual void level_residual(unsigned level, Vector& dst, - const Vector& src); + const Vector& src, + const Vector& rhs) = 0; /** * Solve exactly on coarsest grid. + * Usually, this function should + * be overloaded by a more + * sophisticated derived + * class. Still, there is a + * standard implementation doing + * #10 * (n_pre_smooth + + * n_post_smooth)# + * smoothing steps. */ virtual void coarse_grid_solution(unsigned l, Vector& dst, @@ -146,7 +175,9 @@ class MultiGridBase /** * Constructor, subject to change. */ - MultiGridBase(); + MultiGridBase(MGTransferBase& transfer, + unsigned maxlevel, unsigned minlevel, + unsigned pre_smooth, unsigned post_smooth); virtual ~MultiGridBase(); }; diff --git a/deal.II/deal.II/source/multigrid/multigrid.cc b/deal.II/deal.II/source/multigrid/multigrid.cc index 55f840c667..c0fa498bf3 100644 --- a/deal.II/deal.II/source/multigrid/multigrid.cc +++ b/deal.II/deal.II/source/multigrid/multigrid.cc @@ -4,6 +4,15 @@ #include #include +MultiGridBase::MultiGridBase(MGTransferBase& transfer, + unsigned maxlevel, unsigned minlevel, + unsigned pre_smooth, unsigned post_smooth) + : + maxlevel(maxlevel), minlevel(minlevel), + transfer(&transfer), + n_pre_smooth(pre_smooth), n_post_smooth(post_smooth) +{} + void MultiGridBase::level_mgstep(unsigned level) { @@ -13,18 +22,39 @@ MultiGridBase::level_mgstep(unsigned level) return; } + // smoothing of the residual by modifying s smooth(level, d[level], s[level], n_pre_smooth); + // t = d-As + level_residual(level, t, s[level], d[level]); + + // make t rhs of lower level + transfer->restrict(level, t, d[level-1]); + // do recursion + level_mgstep(level-1); + // 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); } -void MultiGridBase::post_smooth(unsigned level, - Vector& dst, const Vector& src, - unsigned steps) +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) +{ + smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth)); +} + // ab hier Wolfgang diff --git a/deal.II/deal.II/source/numerics/multigrid.cc b/deal.II/deal.II/source/numerics/multigrid.cc index 55f840c667..c0fa498bf3 100644 --- a/deal.II/deal.II/source/numerics/multigrid.cc +++ b/deal.II/deal.II/source/numerics/multigrid.cc @@ -4,6 +4,15 @@ #include #include +MultiGridBase::MultiGridBase(MGTransferBase& transfer, + unsigned maxlevel, unsigned minlevel, + unsigned pre_smooth, unsigned post_smooth) + : + maxlevel(maxlevel), minlevel(minlevel), + transfer(&transfer), + n_pre_smooth(pre_smooth), n_post_smooth(post_smooth) +{} + void MultiGridBase::level_mgstep(unsigned level) { @@ -13,18 +22,39 @@ MultiGridBase::level_mgstep(unsigned level) return; } + // smoothing of the residual by modifying s smooth(level, d[level], s[level], n_pre_smooth); + // t = d-As + level_residual(level, t, s[level], d[level]); + + // make t rhs of lower level + transfer->restrict(level, t, d[level-1]); + // do recursion + level_mgstep(level-1); + // 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); } -void MultiGridBase::post_smooth(unsigned level, - Vector& dst, const Vector& src, - unsigned steps) +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) +{ + smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth)); +} + // ab hier Wolfgang