From: guido Date: Thu, 8 Apr 1999 13:56:23 +0000 (+0000) Subject: Multigrid framework X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dde5241cdbcec68668721f817ce407b394d0b2e7;p=dealii-svn.git Multigrid framework git-svn-id: https://svn.dealii.org/trunk@1095 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 7cc7cfa6a4..b7811b0fe7 100644 --- a/deal.II/deal.II/include/multigrid/multigrid.h +++ b/deal.II/deal.II/include/multigrid/multigrid.h @@ -4,48 +4,10 @@ #define __multigrid_H /*---------------------------- multigrid.h ---------------------------*/ - +#include +#include #include - - -/** - * Vector with data for each level. - * - * This class provides auxiliary vectors for the multigrid method. It - * seems, that it is used only locally in class #MultiGrid#, so do not - * bother about it. - * - * In case your smoothing method needs auxiliary vectors, you should - * use a memory class for each level separately. If memory is short, - * one object for all levels could be a better choice. - * - * @author Guido Kanschat, 1999 - */ -class MGVector -{ - MGVector(const MGVector&); - public: - /** - * Constructor using the number of - * levels. - */ - MGVector(unsigned l); - /** - * Access to data on a specific - * level. - */ - Vector& operator[](unsigned l); - - /** - * Access to data on a specific - level. - */ - const Vector& operator[](unsigned l) const; -}; - - - /** * Basic matrix class for multigrid preconditioning. * @@ -69,177 +31,141 @@ class MGVector * * @author Guido Kanschat, 1999 * */ -class MultiGrid +class MultiGridBase { - MultiGrid(const MultiGrid&); - const MultiGrid& operator=(const MultiGrid&); - - /** Auxiliary vectors. - */ - mutable MGVector d,s; - - /** - * Highest level of cells. - */ - unsigned maxlevel; + MultiGridBase(const MultiGridBase&); + const MultiGridBase& operator=(const MultiGridBase&); + + /** Auxiliary vectors. + */ + vector > d; + vector > s; + + /** + * Highest level of cells. + */ + unsigned maxlevel; - /** - * Level for coarse grid solution. - */ - unsigned minlevel; + /** + * Level for coarse grid solution. + */ + unsigned minlevel; - /** 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. - */ - void copy_to_mg(MGVector& dst, const Vector& src) const; + /** 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. + */ + void copy_to_mg(vector >& dst, const Vector& src); - /** - * 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. - */ - void copy_from_mg(Vector& dst, const MGVector& src) const; + /** + * 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. + */ + void copy_from_mg(Vector& dst, const vector >& src); - /** - * The actual v-cycle multigrid method. - * This function is called on the - * highest level and recursively - * invokes itself down to the - * coarsest. There, it calls - * #coarse_grid_solution# and - * proceeds back up. - */ - void level_mgstep(unsigned level) const; + /** + * The actual v-cycle multigrid method. + * This function is called on the + * highest level and recursively + * invokes itself down to the + * coarsest. There, it calls + * #coarse_grid_solution# and + * proceeds back up. + */ + void level_mgstep(unsigned level); -protected: - /** - * Number of pre-smoothing steps. - */ - unsigned n_pre_smooth; + 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) const; - - /** - * The post-smoothing algorithm. - * Defaults to #smooth#. - */ - virtual void post_smooth(unsigned level, - Vector& dst, - const Vector& src, - unsigned steps) const; - - /** - * Apply operator on all - * cells of a level. - * - */ - virtual void level_vmult(unsigned level, - Vector& dst, - const Vector& src) const; - /** - * Apply operator on non-refined - * cells. - * - * The sum over all levels - * of the results of this function - * is the multiplication with the - * normal fine-grid matrix. - */ - virtual void level_active_vmult(unsigned level, - Vector& dst, - const Vector& src) const; + /** + * 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); - /** - * Restriction from #level#. - * - * This function adds the - * restriction of #src# to #dst#, - * where #src# is a vector on #level# - * and #dst# is on #level#-1. - */ - virtual void restriction(unsigned level, - Vector& dst, - const Vector& src) const; - + /** + * The post-smoothing algorithm. + * Defaults to #smooth#. + */ + virtual void post_smooth(unsigned level, + Vector& dst, + const Vector& src, + unsigned steps); - /** - * Prolongation to #level#. - * - * Adds the prolongation of - * #src# to #dst#. Here, #dst# is on - * #level# and #src# on #level#-1. - */ - virtual void prolongation(unsigned level, - Vector& dst, - const Vector& src) const; + /** + * Apply operator on all + * cells of a level. + * + */ + virtual void level_vmult(unsigned level, + Vector& dst, + const Vector& src); - /** - * Solve exactly on coarsest grid. - */ - virtual void coarse_grid_solution(unsigned l, - Vector& dst, - const Vector& src) const; + /** + * Solve exactly on coarsest grid. + */ + virtual void coarse_grid_solution(unsigned l, + Vector& dst, + const Vector& src); -public: - /** - * Constructor, subject to change. - */ - MultiGrid(); - - /** Matrix-vector multiplication. - * - * The global, non-multigrid - * matrix-vector multiplication - * used to compute the residual in - * the outer iteration. - * - */ - void vmult(Vector& dst, const Vector& src) const; - /** Multigrid preconditioning. - * - * This is the function, where the - * multigrid method is implemented. - * - */ - void precondition(Vector& dst, const Vector& src) const; + public: + /** + * Constructor, subject to change. + */ + MultiGridBase(); + virtual ~MultiGridBase(); + }; +class MGTransferBase + : + public Subscriptor +{ + public: + virtual ~MGTransferBase(); + + virtual void prolongate(unsigned l, + Vector& dst, + const Vector& src) const = 0; + virtual void restrict(unsigned l, + Vector& dst, + const Vector& src) const = 0; +}; /*---------------------------- multigrid.h ---------------------------*/ diff --git a/deal.II/deal.II/include/numerics/multigrid.h b/deal.II/deal.II/include/numerics/multigrid.h index 7cc7cfa6a4..b7811b0fe7 100644 --- a/deal.II/deal.II/include/numerics/multigrid.h +++ b/deal.II/deal.II/include/numerics/multigrid.h @@ -4,48 +4,10 @@ #define __multigrid_H /*---------------------------- multigrid.h ---------------------------*/ - +#include +#include #include - - -/** - * Vector with data for each level. - * - * This class provides auxiliary vectors for the multigrid method. It - * seems, that it is used only locally in class #MultiGrid#, so do not - * bother about it. - * - * In case your smoothing method needs auxiliary vectors, you should - * use a memory class for each level separately. If memory is short, - * one object for all levels could be a better choice. - * - * @author Guido Kanschat, 1999 - */ -class MGVector -{ - MGVector(const MGVector&); - public: - /** - * Constructor using the number of - * levels. - */ - MGVector(unsigned l); - /** - * Access to data on a specific - * level. - */ - Vector& operator[](unsigned l); - - /** - * Access to data on a specific - level. - */ - const Vector& operator[](unsigned l) const; -}; - - - /** * Basic matrix class for multigrid preconditioning. * @@ -69,177 +31,141 @@ class MGVector * * @author Guido Kanschat, 1999 * */ -class MultiGrid +class MultiGridBase { - MultiGrid(const MultiGrid&); - const MultiGrid& operator=(const MultiGrid&); - - /** Auxiliary vectors. - */ - mutable MGVector d,s; - - /** - * Highest level of cells. - */ - unsigned maxlevel; + MultiGridBase(const MultiGridBase&); + const MultiGridBase& operator=(const MultiGridBase&); + + /** Auxiliary vectors. + */ + vector > d; + vector > s; + + /** + * Highest level of cells. + */ + unsigned maxlevel; - /** - * Level for coarse grid solution. - */ - unsigned minlevel; + /** + * Level for coarse grid solution. + */ + unsigned minlevel; - /** 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. - */ - void copy_to_mg(MGVector& dst, const Vector& src) const; + /** 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. + */ + void copy_to_mg(vector >& dst, const Vector& src); - /** - * 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. - */ - void copy_from_mg(Vector& dst, const MGVector& src) const; + /** + * 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. + */ + void copy_from_mg(Vector& dst, const vector >& src); - /** - * The actual v-cycle multigrid method. - * This function is called on the - * highest level and recursively - * invokes itself down to the - * coarsest. There, it calls - * #coarse_grid_solution# and - * proceeds back up. - */ - void level_mgstep(unsigned level) const; + /** + * The actual v-cycle multigrid method. + * This function is called on the + * highest level and recursively + * invokes itself down to the + * coarsest. There, it calls + * #coarse_grid_solution# and + * proceeds back up. + */ + void level_mgstep(unsigned level); -protected: - /** - * Number of pre-smoothing steps. - */ - unsigned n_pre_smooth; + 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) const; - - /** - * The post-smoothing algorithm. - * Defaults to #smooth#. - */ - virtual void post_smooth(unsigned level, - Vector& dst, - const Vector& src, - unsigned steps) const; - - /** - * Apply operator on all - * cells of a level. - * - */ - virtual void level_vmult(unsigned level, - Vector& dst, - const Vector& src) const; - /** - * Apply operator on non-refined - * cells. - * - * The sum over all levels - * of the results of this function - * is the multiplication with the - * normal fine-grid matrix. - */ - virtual void level_active_vmult(unsigned level, - Vector& dst, - const Vector& src) const; + /** + * 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); - /** - * Restriction from #level#. - * - * This function adds the - * restriction of #src# to #dst#, - * where #src# is a vector on #level# - * and #dst# is on #level#-1. - */ - virtual void restriction(unsigned level, - Vector& dst, - const Vector& src) const; - + /** + * The post-smoothing algorithm. + * Defaults to #smooth#. + */ + virtual void post_smooth(unsigned level, + Vector& dst, + const Vector& src, + unsigned steps); - /** - * Prolongation to #level#. - * - * Adds the prolongation of - * #src# to #dst#. Here, #dst# is on - * #level# and #src# on #level#-1. - */ - virtual void prolongation(unsigned level, - Vector& dst, - const Vector& src) const; + /** + * Apply operator on all + * cells of a level. + * + */ + virtual void level_vmult(unsigned level, + Vector& dst, + const Vector& src); - /** - * Solve exactly on coarsest grid. - */ - virtual void coarse_grid_solution(unsigned l, - Vector& dst, - const Vector& src) const; + /** + * Solve exactly on coarsest grid. + */ + virtual void coarse_grid_solution(unsigned l, + Vector& dst, + const Vector& src); -public: - /** - * Constructor, subject to change. - */ - MultiGrid(); - - /** Matrix-vector multiplication. - * - * The global, non-multigrid - * matrix-vector multiplication - * used to compute the residual in - * the outer iteration. - * - */ - void vmult(Vector& dst, const Vector& src) const; - /** Multigrid preconditioning. - * - * This is the function, where the - * multigrid method is implemented. - * - */ - void precondition(Vector& dst, const Vector& src) const; + public: + /** + * Constructor, subject to change. + */ + MultiGridBase(); + virtual ~MultiGridBase(); + }; +class MGTransferBase + : + public Subscriptor +{ + public: + virtual ~MGTransferBase(); + + virtual void prolongate(unsigned l, + Vector& dst, + const Vector& src) const = 0; + virtual void restrict(unsigned l, + Vector& dst, + const Vector& src) const = 0; +}; /*---------------------------- multigrid.h ---------------------------*/ diff --git a/deal.II/deal.II/source/multigrid/multigrid.cc b/deal.II/deal.II/source/multigrid/multigrid.cc index e45aa11e36..55f840c667 100644 --- a/deal.II/deal.II/source/multigrid/multigrid.cc +++ b/deal.II/deal.II/source/multigrid/multigrid.cc @@ -5,37 +5,13 @@ #include void -MultiGrid::vmult(Vector& dst, const Vector& src) const -{ - dst = 0.; - - copy_to_mg(s,src); - - for (unsigned l=0;l& dst, const Vector& src) const -{ - copy_to_mg(s,src); - copy_to_mg(d,dst); - level_mgstep(maxlevel); -} - - -void -MultiGrid::level_mgstep(unsigned level) const +MultiGridBase::level_mgstep(unsigned level) { if (level == minlevel) - { - coarse_grid_solution(level, d[level], s[level]); - return; - } + { + coarse_grid_solution(level, d[level], s[level]); + return; + } smooth(level, d[level], s[level], n_pre_smooth); @@ -43,9 +19,12 @@ MultiGrid::level_mgstep(unsigned level) const } -void MultiGrid::post_smooth(unsigned level, - Vector& dst, const Vector& src, - unsigned steps) const +void MultiGridBase::post_smooth(unsigned level, + Vector& dst, const Vector& src, + unsigned steps) { smooth(level, dst, src, steps); } + +// ab hier Wolfgang + diff --git a/deal.II/deal.II/source/numerics/multigrid.cc b/deal.II/deal.II/source/numerics/multigrid.cc index e45aa11e36..55f840c667 100644 --- a/deal.II/deal.II/source/numerics/multigrid.cc +++ b/deal.II/deal.II/source/numerics/multigrid.cc @@ -5,37 +5,13 @@ #include void -MultiGrid::vmult(Vector& dst, const Vector& src) const -{ - dst = 0.; - - copy_to_mg(s,src); - - for (unsigned l=0;l& dst, const Vector& src) const -{ - copy_to_mg(s,src); - copy_to_mg(d,dst); - level_mgstep(maxlevel); -} - - -void -MultiGrid::level_mgstep(unsigned level) const +MultiGridBase::level_mgstep(unsigned level) { if (level == minlevel) - { - coarse_grid_solution(level, d[level], s[level]); - return; - } + { + coarse_grid_solution(level, d[level], s[level]); + return; + } smooth(level, d[level], s[level], n_pre_smooth); @@ -43,9 +19,12 @@ MultiGrid::level_mgstep(unsigned level) const } -void MultiGrid::post_smooth(unsigned level, - Vector& dst, const Vector& src, - unsigned steps) const +void MultiGridBase::post_smooth(unsigned level, + Vector& dst, const Vector& src, + unsigned steps) { smooth(level, dst, src, steps); } + +// ab hier Wolfgang +