#define __multigrid_H
/*---------------------------- multigrid.h ---------------------------*/
-#include <vector>
-#include <base/smartpointer.h>
+#include <base/subscriptor.h>
#include <lac/forward-declarations.h>
+#include <basic/forward-declarations.h>
+#include <lac/sparsematrix.h>
#include <lac/vector.h>
+#include <vector>
class MGTransferBase;
+
/**
* Basic matrix class for multigrid preconditioning.
*
};
-class MGTransferBase
- :
- public Subscriptor
+
+/**
+ * Base class used to declare the operations needed by a concrete class
+ * implementing prolongation and restriction of vectors in the multigrid
+ * context. This class is an abstract one and has no implementations of
+ * possible algorithms for these operations.
+ *
+ * @author Wolfgang Bangerth, Guido Kanschat, 1999
+ */
+class MGTransferBase : public Subscriptor
{
public:
+ /**
+ * Destructor. Does nothing here, but
+ * needs to be declared virtual anyway.
+ */
virtual ~MGTransferBase();
- virtual void prolongate(unsigned l,
- Vector<float>& dst,
- const Vector<float>& src) const = 0;
- virtual void restrict(unsigned l,
- Vector<float>& dst,
- const Vector<float>& src) const = 0;
+ /**
+ * Prolongate a vector from level
+ * #to_level-1# to level #to_level#.
+ *
+ * #src# is assumed to be a vector with
+ * as many elements as there are degrees
+ * of freedom on the coarser level of
+ * the two involved levels, while #src#
+ * shall have as many elements as there
+ * are degrees of freedom on the finer
+ * level.
+ */
+ virtual void prolongate (const unsigned int to_level,
+ Vector<float> &dst,
+ const Vector<float> &src) const = 0;
+
+ /**
+ * Restrict a vector from level
+ * #from_level# to level
+ * #from_level-1#.
+ *
+ * #src# is assumed to be a vector with
+ * as many elements as there are degrees
+ * of freedom on the finer level of
+ * the two involved levels, while #src#
+ * shall have as many elements as there
+ * are degrees of freedom on the coarser
+ * level.
+ */
+ virtual void restrict (const unsigned int from_level,
+ Vector<float> &dst,
+ const Vector<float> &src) const = 0;
};
+
+/**
+ * Implementation of the #MGTransferBase# interface for which the transfer
+ * operations are prebuilt upon construction of the object of this class as
+ * matrices. This is the fast way, since it only needs to build the operation
+ * once by looping over all cells and storing the result in a matrix for
+ * each level, but requires additional memory.
+ *
+ * @author Wolfgang Bangerth, Guido Kanschat, 1999
+ */
+class MGTransferPrebuilt : public MGTransferBase
+{
+ public:
+
+ /**
+ * Destructor.
+ */
+ virtual ~MGTransferPrebuilt ();
+
+ /**
+ * Actually build the prolongation
+ * matrices for each level.
+ */
+ template <int dim>
+ void build_matrices (const MGDoFHandler<dim> &mg_dof);
+
+ /**
+ * Prolongate a vector from level
+ * #to_level-1# to level #to_level#.
+ *
+ * #src# is assumed to be a vector with
+ * as many elements as there are degrees
+ * of freedom on the coarser level of
+ * the two involved levels, while #src#
+ * shall have as many elements as there
+ * are degrees of freedom on the finer
+ * level.
+ */
+ virtual void prolongate (const unsigned int to_level,
+ Vector<float> &dst,
+ const Vector<float> &src) const = 0;
+
+ /**
+ * Restrict a vector from level
+ * #from_level# to level
+ * #from_level-1#.
+ *
+ * #src# is assumed to be a vector with
+ * as many elements as there are degrees
+ * of freedom on the finer level of
+ * the two involved levels, while #src#
+ * shall have as many elements as there
+ * are degrees of freedom on the coarser
+ * level.
+ */
+ virtual void restrict (const unsigned int from_level,
+ Vector<float> &dst,
+ const Vector<float> &src) const = 0;
+
+ private:
+
+ vector<SparseMatrixStruct> prolongation_sparsities;
+
+ /**
+ * The actual prolongation matrix.
+ * column indices belong to the
+ * dof indices of the mother cell,
+ * i.e. the coarse level.
+ * while row indices belong to the
+ * child cell, i.e. the fine level.
+ */
+ vector<SparseMatrix<float> > prolongation_matrices;
+};
+
+
+
/*---------------------------- multigrid.h ---------------------------*/
/* end of #ifndef __multigrid_H */
#endif
#define __multigrid_H
/*---------------------------- multigrid.h ---------------------------*/
-#include <vector>
-#include <base/smartpointer.h>
+#include <base/subscriptor.h>
#include <lac/forward-declarations.h>
+#include <basic/forward-declarations.h>
+#include <lac/sparsematrix.h>
#include <lac/vector.h>
+#include <vector>
class MGTransferBase;
+
/**
* Basic matrix class for multigrid preconditioning.
*
};
-class MGTransferBase
- :
- public Subscriptor
+
+/**
+ * Base class used to declare the operations needed by a concrete class
+ * implementing prolongation and restriction of vectors in the multigrid
+ * context. This class is an abstract one and has no implementations of
+ * possible algorithms for these operations.
+ *
+ * @author Wolfgang Bangerth, Guido Kanschat, 1999
+ */
+class MGTransferBase : public Subscriptor
{
public:
+ /**
+ * Destructor. Does nothing here, but
+ * needs to be declared virtual anyway.
+ */
virtual ~MGTransferBase();
- virtual void prolongate(unsigned l,
- Vector<float>& dst,
- const Vector<float>& src) const = 0;
- virtual void restrict(unsigned l,
- Vector<float>& dst,
- const Vector<float>& src) const = 0;
+ /**
+ * Prolongate a vector from level
+ * #to_level-1# to level #to_level#.
+ *
+ * #src# is assumed to be a vector with
+ * as many elements as there are degrees
+ * of freedom on the coarser level of
+ * the two involved levels, while #src#
+ * shall have as many elements as there
+ * are degrees of freedom on the finer
+ * level.
+ */
+ virtual void prolongate (const unsigned int to_level,
+ Vector<float> &dst,
+ const Vector<float> &src) const = 0;
+
+ /**
+ * Restrict a vector from level
+ * #from_level# to level
+ * #from_level-1#.
+ *
+ * #src# is assumed to be a vector with
+ * as many elements as there are degrees
+ * of freedom on the finer level of
+ * the two involved levels, while #src#
+ * shall have as many elements as there
+ * are degrees of freedom on the coarser
+ * level.
+ */
+ virtual void restrict (const unsigned int from_level,
+ Vector<float> &dst,
+ const Vector<float> &src) const = 0;
};
+
+/**
+ * Implementation of the #MGTransferBase# interface for which the transfer
+ * operations are prebuilt upon construction of the object of this class as
+ * matrices. This is the fast way, since it only needs to build the operation
+ * once by looping over all cells and storing the result in a matrix for
+ * each level, but requires additional memory.
+ *
+ * @author Wolfgang Bangerth, Guido Kanschat, 1999
+ */
+class MGTransferPrebuilt : public MGTransferBase
+{
+ public:
+
+ /**
+ * Destructor.
+ */
+ virtual ~MGTransferPrebuilt ();
+
+ /**
+ * Actually build the prolongation
+ * matrices for each level.
+ */
+ template <int dim>
+ void build_matrices (const MGDoFHandler<dim> &mg_dof);
+
+ /**
+ * Prolongate a vector from level
+ * #to_level-1# to level #to_level#.
+ *
+ * #src# is assumed to be a vector with
+ * as many elements as there are degrees
+ * of freedom on the coarser level of
+ * the two involved levels, while #src#
+ * shall have as many elements as there
+ * are degrees of freedom on the finer
+ * level.
+ */
+ virtual void prolongate (const unsigned int to_level,
+ Vector<float> &dst,
+ const Vector<float> &src) const = 0;
+
+ /**
+ * Restrict a vector from level
+ * #from_level# to level
+ * #from_level-1#.
+ *
+ * #src# is assumed to be a vector with
+ * as many elements as there are degrees
+ * of freedom on the finer level of
+ * the two involved levels, while #src#
+ * shall have as many elements as there
+ * are degrees of freedom on the coarser
+ * level.
+ */
+ virtual void restrict (const unsigned int from_level,
+ Vector<float> &dst,
+ const Vector<float> &src) const = 0;
+
+ private:
+
+ vector<SparseMatrixStruct> prolongation_sparsities;
+
+ /**
+ * The actual prolongation matrix.
+ * column indices belong to the
+ * dof indices of the mother cell,
+ * i.e. the coarse level.
+ * while row indices belong to the
+ * child cell, i.e. the fine level.
+ */
+ vector<SparseMatrix<float> > prolongation_matrices;
+};
+
+
+
/*---------------------------- multigrid.h ---------------------------*/
/* end of #ifndef __multigrid_H */
#endif
// $Id$
// Copyright Guido Kanschat, Universitaet Heidelberg, 1999
+#include <grid/tria.h>
+#include <grid/mg_dof.h>
+#include <grid/mg_dof_accessor.h>
+#include <grid/tria_iterator.h>
+#include <fe/fe.h>
#include <numerics/multigrid.h>
#include <lac/vector.h>
+
MultiGridBase::MultiGridBase(MGTransferBase& transfer,
unsigned maxlevel, unsigned minlevel,
unsigned pre_smooth, unsigned post_smooth)
n_pre_smooth(pre_smooth), n_post_smooth(post_smooth)
{}
+
void
MultiGridBase::level_mgstep(unsigned level)
{
smooth(level, dst, src, steps);
}
+
+
void
MultiGridBase::coarse_grid_solution(unsigned level,
Vector<float>& dst,
smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth));
}
+
+
+
// ab hier Wolfgang
+
+
+/* ------------------------------ MGTransferBase --------------------------- */
+
+MGTransferBase::~MGTransferBase ()
+{};
+
+
+
+/* ----------------------------- MGTransferPrebuilt ------------------------ */
+
+
+<<<<<<< multigrid.cc
+/*
+MGTransferPrebuilt::~MGTransferPrebuilt ()
+{};
+
+
+
+template <int dim>
+void MGTransferPrebuilt::build_matrices (const MGDoFHandler<dim> &mg_dof)
+{
+ const unsigned int n_levels = mg_dof.get_tria().n_levels();
+ const unsigned int dofs_per_cell = mg_dof.get_fe().total_dofs;
+
+ // reset the size of the array of
+ // matrices
+ prolongation_sparsities.clear ();
+ prolongation_matrices.clear ();
+ prolongation_sparsities.reserve (n_levels-1);
+ prolongation_matrices.reserve (n_levels-1);
+
+
+ // two fields which will store the
+ // indices of the multigrid dofs
+ // for a cell and one of its children
+ vector<int> dof_indices_mother (dofs_per_cell);
+ vector<int> dof_indices_child (dofs_per_cell);
+
+ // for each level: first build the sparsity
+ // pattern of the matrices and then build the
+ // matrices themselves. note that we only
+ // need to take care of cells on the coarser
+ // level which have children
+ for (unsigned int level=0; level<n_levels-1; ++level)
+ {
+ prolongation_sparsities.push_back (SparseMatrixStruct());
+
+ for (typename MGDoFHandler<dim>::cell_iterator cell=mg_dof.begin(level);
+ cell != mg_dof.end(level); ++cell)
+ if (cell->has_children())
+ {
+ cell->get_mg_dof_indices (dof_indices_mother);
+
+ for (unsigned int child=0;
+ child<GeometryInfo<dim>::children_per_cell; ++child)
+ {
+ // set an alias to the
+ // prolongation matrix for
+ // this child
+ const FullMatrix<double> &prolongation
+ = mg_dof.get_fe().prolongate(child);
+
+ cell->child(child)->get_dof_indices (dof_indices_child);
+
+ // now tag the entries in the
+ // matrix which will be used
+ // for this pair of mother/child
+ for (unsigned int i=0; i<dofs_per_cell; ++i)
+ for (unsigned int j=0; j<dofs_per_cell; ++j)
+ if (prolongation(i,j) != 0)
+ {
+ prolongation_sparsities[level].add
+ (dof_indices_child[i],
+ dof_indices_mother[j]);
+ };
+ };
+ };
+
+ prolongation_matrices[level].matrix.reinit (prolongation_matrices[level].sparsity);
+
+
+ // now actually build the matrices
+ for (MGDoFHandler<dim>::cell_iterator cell=mg_dof.begin(level);
+ cell != mg_dof.end(level); ++cell)
+ if (cell->has_children())
+ {
+ cell->get_mg_dof_indices (dof_indices_mother);
+
+ for (unsigned int child=0;
+ child<GeometryInfo<dim>::children_per_cell; ++child)
+ {
+ // set an alias to the
+ // prolongation matrix for
+ // this child
+ const FullMatrix<double> &prolongation
+ = mg_dof.get_fe().prolongate(child);
+
+ cell->child(child)->get_dof_indices (dof_indices_child);
+
+ // now set the entries in the
+ // matrix
+ for (unsigned int i=0; i<dofs_per_cell; ++i)
+ for (unsigned int j=0; j<dofs_per_cell; ++j)
+ if (prolongation(i,j) != 0)
+ {
+ prolongation_matrices[level]
+ (dof_indices_child[i],
+ dof_indices_mother[j],
+ prolongation(i,j));
+ };
+ };
+ };
+ };
+};
+
+
+
+
+
+// explicit instatations
+template
+void MGTransferPrebuilt::build_matrices (const MGDoFHandler<deal_II_dimension> &mg_dof);
+
+*/
// $Id$
// Copyright Guido Kanschat, Universitaet Heidelberg, 1999
+#include <grid/tria.h>
+#include <grid/mg_dof.h>
+#include <grid/mg_dof_accessor.h>
+#include <grid/tria_iterator.h>
+#include <fe/fe.h>
#include <numerics/multigrid.h>
#include <lac/vector.h>
+
MultiGridBase::MultiGridBase(MGTransferBase& transfer,
unsigned maxlevel, unsigned minlevel,
unsigned pre_smooth, unsigned post_smooth)
n_pre_smooth(pre_smooth), n_post_smooth(post_smooth)
{}
+
void
MultiGridBase::level_mgstep(unsigned level)
{
smooth(level, dst, src, steps);
}
+
+
void
MultiGridBase::coarse_grid_solution(unsigned level,
Vector<float>& dst,
smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth));
}
+
+
+
// ab hier Wolfgang
+
+
+/* ------------------------------ MGTransferBase --------------------------- */
+
+MGTransferBase::~MGTransferBase ()
+{};
+
+
+
+/* ----------------------------- MGTransferPrebuilt ------------------------ */
+
+
+<<<<<<< multigrid.cc
+/*
+MGTransferPrebuilt::~MGTransferPrebuilt ()
+{};
+
+
+
+template <int dim>
+void MGTransferPrebuilt::build_matrices (const MGDoFHandler<dim> &mg_dof)
+{
+ const unsigned int n_levels = mg_dof.get_tria().n_levels();
+ const unsigned int dofs_per_cell = mg_dof.get_fe().total_dofs;
+
+ // reset the size of the array of
+ // matrices
+ prolongation_sparsities.clear ();
+ prolongation_matrices.clear ();
+ prolongation_sparsities.reserve (n_levels-1);
+ prolongation_matrices.reserve (n_levels-1);
+
+
+ // two fields which will store the
+ // indices of the multigrid dofs
+ // for a cell and one of its children
+ vector<int> dof_indices_mother (dofs_per_cell);
+ vector<int> dof_indices_child (dofs_per_cell);
+
+ // for each level: first build the sparsity
+ // pattern of the matrices and then build the
+ // matrices themselves. note that we only
+ // need to take care of cells on the coarser
+ // level which have children
+ for (unsigned int level=0; level<n_levels-1; ++level)
+ {
+ prolongation_sparsities.push_back (SparseMatrixStruct());
+
+ for (typename MGDoFHandler<dim>::cell_iterator cell=mg_dof.begin(level);
+ cell != mg_dof.end(level); ++cell)
+ if (cell->has_children())
+ {
+ cell->get_mg_dof_indices (dof_indices_mother);
+
+ for (unsigned int child=0;
+ child<GeometryInfo<dim>::children_per_cell; ++child)
+ {
+ // set an alias to the
+ // prolongation matrix for
+ // this child
+ const FullMatrix<double> &prolongation
+ = mg_dof.get_fe().prolongate(child);
+
+ cell->child(child)->get_dof_indices (dof_indices_child);
+
+ // now tag the entries in the
+ // matrix which will be used
+ // for this pair of mother/child
+ for (unsigned int i=0; i<dofs_per_cell; ++i)
+ for (unsigned int j=0; j<dofs_per_cell; ++j)
+ if (prolongation(i,j) != 0)
+ {
+ prolongation_sparsities[level].add
+ (dof_indices_child[i],
+ dof_indices_mother[j]);
+ };
+ };
+ };
+
+ prolongation_matrices[level].matrix.reinit (prolongation_matrices[level].sparsity);
+
+
+ // now actually build the matrices
+ for (MGDoFHandler<dim>::cell_iterator cell=mg_dof.begin(level);
+ cell != mg_dof.end(level); ++cell)
+ if (cell->has_children())
+ {
+ cell->get_mg_dof_indices (dof_indices_mother);
+
+ for (unsigned int child=0;
+ child<GeometryInfo<dim>::children_per_cell; ++child)
+ {
+ // set an alias to the
+ // prolongation matrix for
+ // this child
+ const FullMatrix<double> &prolongation
+ = mg_dof.get_fe().prolongate(child);
+
+ cell->child(child)->get_dof_indices (dof_indices_child);
+
+ // now set the entries in the
+ // matrix
+ for (unsigned int i=0; i<dofs_per_cell; ++i)
+ for (unsigned int j=0; j<dofs_per_cell; ++j)
+ if (prolongation(i,j) != 0)
+ {
+ prolongation_matrices[level]
+ (dof_indices_child[i],
+ dof_indices_mother[j],
+ prolongation(i,j));
+ };
+ };
+ };
+ };
+};
+
+
+
+
+
+// explicit instatations
+template
+void MGTransferPrebuilt::build_matrices (const MGDoFHandler<deal_II_dimension> &mg_dof);
+
+*/