From fc50c28380874d166afb734fe314596b9a6f137c Mon Sep 17 00:00:00 2001 From: guido Date: Fri, 22 Jan 1999 15:31:36 +0000 Subject: [PATCH] multigrid compiles now... sorry! git-svn-id: https://svn.dealii.org/trunk@741 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/multigrid/multigrid.h | 133 +++++++++++++++++- deal.II/deal.II/include/numerics/multigrid.h | 133 +++++++++++++++++- deal.II/deal.II/source/multigrid/multigrid.cc | 26 ++-- deal.II/deal.II/source/numerics/multigrid.cc | 26 ++-- 4 files changed, 292 insertions(+), 26 deletions(-) diff --git a/deal.II/deal.II/include/multigrid/multigrid.h b/deal.II/deal.II/include/multigrid/multigrid.h index d3951e87d9..6a65244517 100644 --- a/deal.II/deal.II/include/multigrid/multigrid.h +++ b/deal.II/deal.II/include/multigrid/multigrid.h @@ -4,6 +4,36 @@ #define __multigrid_H /*---------------------------- multigrid.h ---------------------------*/ +class dVector; + +/** + * Vector with data for each level. + */ +class MGVector +{ + MGVector(const MGVector&); +public: + /** + * Constructor using the number of + * levels. + */ + MGVector(unsigned l); + /** + * Access to data on a specific + level. + */ + dVector& operator[](unsigned l); + + /** + * Access to data on a specific + level. + */ + const dVector& operator[](unsigned l) const; + +}; + + + /** * Basic matrix class for multigrid preconditioning. * @@ -16,11 +46,108 @@ * classes... * */ -class MGMatrix +class MultiGrid { - MGMatrix(const MGMatrix&); - operator=(const MGMatrix&); + MultiGrid(const MultiGrid&); + const MultiGrid& operator=(const MultiGrid&); + + /** Auxiliary vectors. + */ + mutable MGVector d,s; + + /** + * Highest level of cells. + */ + unsigned maxlevel; + + /** + * 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 dVector& src) const; + + /** + * Transfer from MGVector to + * dVector. + * + * Copies data from active portions + * of an MGVector into the + * respective positions of a + * dVector. + */ + void copy_from_mg(dVector& dst, const MGVector& src) 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) const; + +protected: + /** + * Number of pre-smoothing steps. + */ + unsigned n_presmooth; + + /** + * Number of post-smoothing steps + */ + unsigned n_postsmooth; + /** + * The (pre-)smoothing algorithm. + */ + virtual void smooth(unsigned level, + dVector& dst, + const dVector& src) const; + + /** + * The post-smoothing algorithm. + * Defaults to #smooth#. + */ + virtual void post_smooth(unsigned level, + dVector& dst, + const dVector& src) const; + + /** + * Apply operator on non-refined + * cells. + */ + virtual void level_active_vmult(unsigned level, + dVector& dst, + const dVector& src) const; + + /** + * Solve exactly on coarsest grid. + */ + virtual void coarse_grid_solution(unsigned l, + dVector& dst, + const dVector& src) const; + + + + + public: + /** + * Constructor, subject to change. + */ + MultiGrid(); + /** Matrix-vector multiplication. * * The global, non-multigrid diff --git a/deal.II/deal.II/include/numerics/multigrid.h b/deal.II/deal.II/include/numerics/multigrid.h index d3951e87d9..6a65244517 100644 --- a/deal.II/deal.II/include/numerics/multigrid.h +++ b/deal.II/deal.II/include/numerics/multigrid.h @@ -4,6 +4,36 @@ #define __multigrid_H /*---------------------------- multigrid.h ---------------------------*/ +class dVector; + +/** + * Vector with data for each level. + */ +class MGVector +{ + MGVector(const MGVector&); +public: + /** + * Constructor using the number of + * levels. + */ + MGVector(unsigned l); + /** + * Access to data on a specific + level. + */ + dVector& operator[](unsigned l); + + /** + * Access to data on a specific + level. + */ + const dVector& operator[](unsigned l) const; + +}; + + + /** * Basic matrix class for multigrid preconditioning. * @@ -16,11 +46,108 @@ * classes... * */ -class MGMatrix +class MultiGrid { - MGMatrix(const MGMatrix&); - operator=(const MGMatrix&); + MultiGrid(const MultiGrid&); + const MultiGrid& operator=(const MultiGrid&); + + /** Auxiliary vectors. + */ + mutable MGVector d,s; + + /** + * Highest level of cells. + */ + unsigned maxlevel; + + /** + * 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 dVector& src) const; + + /** + * Transfer from MGVector to + * dVector. + * + * Copies data from active portions + * of an MGVector into the + * respective positions of a + * dVector. + */ + void copy_from_mg(dVector& dst, const MGVector& src) 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) const; + +protected: + /** + * Number of pre-smoothing steps. + */ + unsigned n_presmooth; + + /** + * Number of post-smoothing steps + */ + unsigned n_postsmooth; + /** + * The (pre-)smoothing algorithm. + */ + virtual void smooth(unsigned level, + dVector& dst, + const dVector& src) const; + + /** + * The post-smoothing algorithm. + * Defaults to #smooth#. + */ + virtual void post_smooth(unsigned level, + dVector& dst, + const dVector& src) const; + + /** + * Apply operator on non-refined + * cells. + */ + virtual void level_active_vmult(unsigned level, + dVector& dst, + const dVector& src) const; + + /** + * Solve exactly on coarsest grid. + */ + virtual void coarse_grid_solution(unsigned l, + dVector& dst, + const dVector& src) const; + + + + + public: + /** + * Constructor, subject to change. + */ + MultiGrid(); + /** Matrix-vector multiplication. * * The global, non-multigrid diff --git a/deal.II/deal.II/source/multigrid/multigrid.cc b/deal.II/deal.II/source/multigrid/multigrid.cc index 08646d86be..1a58b75b5c 100644 --- a/deal.II/deal.II/source/multigrid/multigrid.cc +++ b/deal.II/deal.II/source/multigrid/multigrid.cc @@ -2,37 +2,43 @@ // Copyright Guido Kanschat, Universitaet Heidelberg, 1999 #include +#include void -MGMatrix::vmult(dVector& dst, const dVector& src) const +MultiGrid::vmult(dVector& dst, const dVector& src) const { dst = 0.; copy_to_mg(s,src); - for (int l=0;l +#include void -MGMatrix::vmult(dVector& dst, const dVector& src) const +MultiGrid::vmult(dVector& dst, const dVector& src) const { dst = 0.; copy_to_mg(s,src); - for (int l=0;l