};
+/**
+ * Multilevel matrix base. This class sets up the interface needed by
+ * multilevel algorithms. It has no relation to the actual matrix type
+ * and takes the vector class as only template argument.
+ *
+ * Usually, the derived class @ref{MGMatrix}, operating on an
+ * @ref{MGLevelObject} of matrices will be sufficient for applications.
+ *
+ * @author Guido Kanschat, 2002
+ */
+template <class VECTOR>
+class MGMatrixBase : public Subscriptor
+{
+ public:
+ /*
+ * Virtual destructor.
+ */
+ virtual ~MGMatrixBase();
+
+ /**
+ * Matrix-vector-multiplication on
+ * a certain level.
+ */
+ virtual void vmult(unsigned int level, VECTOR& dst,
+ const VECTOR& src) const = 0;
+};
+
+
+/**
+ * Multilevel matrix. This class implements the interface defined by
+ * @ref{MGMatrixBase}, using @ref{MGLevelObject} of an arbitrary
+ * matrix class.
+ *
+ * @author Guido Kanschat, 2002
+ */
+template <class MATRIX, class VECTOR>
+class MGMatrix : public MGMatrixBase<VECTOR>,
+ public SmartPointer<MGLevelObject<MATRIX> >
+{
+ public:
+ /**
+ * Constructor. The argument is
+ * handed over to the
+ * @p{SmartPointer} constructor.
+ */
+ MGMatrix (MGLevelObject<MATRIX>* = 0);
+
+ /**
+ * Matrix-vector-multiplication on
+ * a certain level.
+ */
+ virtual void vmult(unsigned int level, VECTOR& dst,
+ const VECTOR& src) const;
+
+};
+
/**
* Coarse grid solver using LAC iterative methods.
return minlevel + objects.size() - 1;
};
+/*----------------------------------------------------------------------*/
+
+template <class MATRIX, class VECTOR>
+MGMatrix<MATRIX, VECTOR>::MGMatrix (MGLevelObject<MATRIX>* p)
+ :
+ SmartPointer<MGLevelObject<MATRIX> > (p)
+{}
+
+
+
+template <class MATRIX, class VECTOR>
+void
+MGMatrix<MATRIX, VECTOR>::vmult (unsigned int level,
+ VECTOR& dst,
+ const VECTOR& src) const
+{
+ const MGLevelObject<MATRIX>& m = **this;
+ m[level].vmult(dst, src);
+}
+
/* ------------------ Functions for MGCoarseGridLACIteration ------------ */
*/
template <int dim>
Multigrid(const MGDoFHandler<dim>& mg_dof_handler,
+ const MGMatrixBase<VECTOR>& matrix,
const MGTransfer<VECTOR>& transfer,
const MGSmoother<VECTOR>& pre_smooth,
const MGSmoother<VECTOR>& post_smooth,
* function is done in
* @p{level_mgstep}.
*/
- template <class MATRIX, class COARSE>
- void vcycle(const MGLevelObject<MATRIX>& matrix,
- const COARSE& cgs);
+ template <class COARSE>
+ void vcycle(const COARSE& cgs);
/**
* Print a level vector using
* is used to solve the matrix of
* this level.
*/
- template <class MATRIX, class COARSE>
- void level_mgstep (const unsigned int level,
- const MGLevelObject<MATRIX>& matrix,
- const COARSE& cgs);
+ template <class COARSE>
+ void level_mgstep (const unsigned int level,
+ const COARSE& cgs);
/**
* Level for coarse grid solution.
*/
private:
+ /**
+ * The matrix for each level.
+ */
+ SmartPointer<const MGMatrixBase<VECTOR> > matrix;
+
/**
* Object for grid tranfer.
*/
DeclException2(ExcSwitchedLevels, int, int,
<< "minlevel and maxlevel switched, should be: "
<< arg1 << "<=" << arg2);
- template<int dim, class MATRIX, class VECTOR2, class TRANSFER, class COARSE> friend class PreconditionMG;
+ template<int dim, class VECTOR2, class TRANSFER, class COARSE> friend class PreconditionMG;
};
*
* @author Guido Kanschat, 1999, 2000, 2001, 2002
*/
-template<int dim, class MATRIX, class VECTOR, class TRANSFER, class COARSE>
+template<int dim, class VECTOR, class TRANSFER, class COARSE>
class PreconditionMG : public Subscriptor
{
public:
*/
PreconditionMG(const MGDoFHandler<dim>& mg_dof,
Multigrid<VECTOR>& mg,
- const MGLevelObject<MATRIX>& matrix,
const TRANSFER& transfer,
const COARSE& coarse);
*/
SmartPointer<Multigrid<VECTOR> > multigrid;
- /**
- * Matrices for each level. The
- * matrices are prepared by the
- * constructor of @p{Multigrid} and
- * can be accessed for
- * assembling.
- */
- SmartPointer<const MGLevelObject<MATRIX> > level_matrices;
-
/**
* Object for grid tranfer.
*/
template <class VECTOR>
template <int dim>
Multigrid<VECTOR>::Multigrid (const MGDoFHandler<dim>& mg_dof_handler,
+ const MGMatrixBase<VECTOR>& matrix,
const MGTransfer<VECTOR>& transfer,
const MGSmoother<VECTOR>& pre_smooth,
const MGSmoother<VECTOR>& post_smooth,
const unsigned int max_level)
:
minlevel(min_level),
- maxlevel(std::min(mg_dof_handler.get_tria().n_levels()-1,
- max_level)),
- defect(minlevel,maxlevel),
- solution(minlevel,maxlevel),
- t(minlevel,maxlevel),
- transfer(&transfer),
- pre_smooth(&pre_smooth),
- post_smooth(&post_smooth)
+ maxlevel(std::min(mg_dof_handler.get_tria().n_levels()-1,
+ max_level)),
+ defect(minlevel,maxlevel),
+ solution(minlevel,maxlevel),
+ t(minlevel,maxlevel),
+ matrix(&matrix),
+ transfer(&transfer),
+ pre_smooth(&pre_smooth),
+ post_smooth(&post_smooth)
{
};
template <class VECTOR>
-template <class MATRIX, class COARSE>
+template <class COARSE>
void
Multigrid<VECTOR>::level_mgstep(const unsigned int level,
- const MGLevelObject<MATRIX>& matrix,
const COARSE &coarse_grid_solver)
{
#ifdef MG_DEBUG
#endif
// t = -A*solution[level]
- matrix[level].vmult(t[level], solution[level]);
+ matrix->vmult(level, t[level], solution[level]);
t[level].scale(-1);
// make t rhs of lower level
// edge_vmult(level, defect[level-1], defect[level]);
// do recursion
- level_mgstep(level-1, matrix, coarse_grid_solver);
+ level_mgstep(level-1, coarse_grid_solver);
// reset size of the auxiliary
// vector, since it has been
template <class VECTOR>
-template <class MATRIX, class COARSE>
+template <class COARSE>
void
-Multigrid<VECTOR>::vcycle(const MGLevelObject<MATRIX>& matrix,
- const COARSE &coarse_grid_solver)
+Multigrid<VECTOR>::vcycle(const COARSE &coarse_grid_solver)
{
// The defect vector has been
// initialized by copy_to_mg. Now
t[level].reinit(defect[level]);
}
- level_mgstep (maxlevel, matrix, coarse_grid_solver);
+ level_mgstep (maxlevel, coarse_grid_solver);
// abort ();
}
/* ------------------------------------------------------------------- */
-template<int dim, class MATRIX, class VECTOR, class TRANSFER, class COARSE>
-PreconditionMG<dim, MATRIX, VECTOR, TRANSFER, COARSE>
+template<int dim, class VECTOR, class TRANSFER, class COARSE>
+PreconditionMG<dim, VECTOR, TRANSFER, COARSE>
::PreconditionMG(const MGDoFHandler<dim>& mg_dof_handler,
Multigrid<VECTOR>& mg,
- const MGLevelObject<MATRIX>& matrix,
const TRANSFER& transfer,
const COARSE& coarse)
:
mg_dof_handler(&mg_dof_handler),
multigrid(&mg),
- level_matrices(&matrix),
transfer(&transfer),
coarse(&coarse)
{}
-template<int dim, class MATRIX, class VECTOR, class TRANSFER, class COARSE>
+template<int dim, class VECTOR, class TRANSFER, class COARSE>
void
-PreconditionMG<dim, MATRIX, VECTOR, TRANSFER, COARSE>::vmult (
+PreconditionMG<dim, VECTOR, TRANSFER, COARSE>::vmult (
VECTOR& dst,
const VECTOR& src) const
{
multigrid->defect,
src);
- multigrid->vcycle(*level_matrices, *coarse);
+ multigrid->vcycle(*coarse);
transfer->copy_from_mg(*mg_dof_handler,
dst,
}
-template<int dim, class MATRIX, class VECTOR, class TRANSFER, class COARSE>
+template<int dim, class VECTOR, class TRANSFER, class COARSE>
void
-PreconditionMG<dim, MATRIX, VECTOR, TRANSFER, COARSE>::vmult_add (
+PreconditionMG<dim, VECTOR, TRANSFER, COARSE>::vmult_add (
VECTOR& dst,
const VECTOR& src) const
{
multigrid->defect,
src);
- multigrid->vcycle(*level_matrices, *coarse);
+ multigrid->vcycle(*coarse);
transfer->copy_from_mg_add(*mg_dof_handler,
dst,
}
-template<int dim, class MATRIX, class VECTOR, class TRANSFER, class COARSE>
+template<int dim, class VECTOR, class TRANSFER, class COARSE>
void
-PreconditionMG<dim, MATRIX, VECTOR, TRANSFER, COARSE>::Tvmult (
+PreconditionMG<dim, VECTOR, TRANSFER, COARSE>::Tvmult (
VECTOR&,
const VECTOR&) const
{
}
-template<int dim, class MATRIX, class VECTOR, class TRANSFER, class COARSE>
+template<int dim, class VECTOR, class TRANSFER, class COARSE>
void
-PreconditionMG<dim, MATRIX, VECTOR, TRANSFER, COARSE>::Tvmult_add (
+PreconditionMG<dim, VECTOR, TRANSFER, COARSE>::Tvmult_add (
VECTOR&,
const VECTOR&) const
{