#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.
*
* 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
#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.
*
* 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
// Copyright Guido Kanschat, Universitaet Heidelberg, 1999
#include <numerics/multigrid.h>
+#include <lac/dvector.h>
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<maxlevel;++l)
+ for (unsigned l=0;l<maxlevel;++l)
{
- level_active_vmult(l,d,s);
+ level_active_vmult(l,d[l],s[l]);
}
copy_from_mg(dst,d);
}
void
-MGMatrix::precondition(dVector& dst, const dVector& src) const
+MultiGrid::precondition(dVector& dst, const dVector& src) const
{
copy_to_mg(s,src);
- d = 0.;
-
-
+ copy_to_mg(d,dst);
+ level_mgstep(maxlevel);
}
void
-MGMatrix::level_mgstep(int level)
+MultiGrid::level_mgstep(unsigned level) const
{
- for (int i=0; i< n_presmooth; ++i)
+ if (level == minlevel)
+ {
+ coarse_grid_solution(level, d[level], s[level]);
+ return;
+ }
+
+ for (unsigned i=0; i< n_presmooth; ++i)
{
- smooth(level, d, s);
+ smooth(level, d[level], s[level]);
}
}
// Copyright Guido Kanschat, Universitaet Heidelberg, 1999
#include <numerics/multigrid.h>
+#include <lac/dvector.h>
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<maxlevel;++l)
+ for (unsigned l=0;l<maxlevel;++l)
{
- level_active_vmult(l,d,s);
+ level_active_vmult(l,d[l],s[l]);
}
copy_from_mg(dst,d);
}
void
-MGMatrix::precondition(dVector& dst, const dVector& src) const
+MultiGrid::precondition(dVector& dst, const dVector& src) const
{
copy_to_mg(s,src);
- d = 0.;
-
-
+ copy_to_mg(d,dst);
+ level_mgstep(maxlevel);
}
void
-MGMatrix::level_mgstep(int level)
+MultiGrid::level_mgstep(unsigned level) const
{
- for (int i=0; i< n_presmooth; ++i)
+ if (level == minlevel)
+ {
+ coarse_grid_solution(level, d[level], s[level]);
+ return;
+ }
+
+ for (unsigned i=0; i< n_presmooth; ++i)
{
- smooth(level, d, s);
+ smooth(level, d[level], s[level]);
}
}