From 71a956ce42bc4383af770a1b055739b87c46eaac Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 8 Apr 1999 15:48:39 +0000 Subject: [PATCH] Test commitment to pass changes to Guido. git-svn-id: https://svn.dealii.org/trunk@1101 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/multigrid/multigrid.h | 138 ++++++++++++++++-- deal.II/deal.II/include/numerics/multigrid.h | 138 ++++++++++++++++-- deal.II/deal.II/source/multigrid/multigrid.cc | 137 +++++++++++++++++ deal.II/deal.II/source/numerics/multigrid.cc | 137 +++++++++++++++++ 4 files changed, 528 insertions(+), 22 deletions(-) diff --git a/deal.II/deal.II/include/multigrid/multigrid.h b/deal.II/deal.II/include/multigrid/multigrid.h index 4c00b24dc2..f9c6b52f2c 100644 --- a/deal.II/deal.II/include/multigrid/multigrid.h +++ b/deal.II/deal.II/include/multigrid/multigrid.h @@ -4,14 +4,17 @@ #define __multigrid_H /*---------------------------- multigrid.h ---------------------------*/ -#include -#include +#include #include +#include +#include #include +#include class MGTransferBase; + /** * Basic matrix class for multigrid preconditioning. * @@ -183,22 +186,135 @@ class MultiGridBase }; -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& dst, - const Vector& src) const = 0; - virtual void restrict(unsigned l, - Vector& dst, - const Vector& 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 &dst, + const Vector &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 &dst, + const Vector &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 + void build_matrices (const MGDoFHandler &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 &dst, + const Vector &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 &dst, + const Vector &src) const = 0; + + private: + + vector 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 > prolongation_matrices; +}; + + + /*---------------------------- multigrid.h ---------------------------*/ /* end of #ifndef __multigrid_H */ #endif diff --git a/deal.II/deal.II/include/numerics/multigrid.h b/deal.II/deal.II/include/numerics/multigrid.h index 4c00b24dc2..f9c6b52f2c 100644 --- a/deal.II/deal.II/include/numerics/multigrid.h +++ b/deal.II/deal.II/include/numerics/multigrid.h @@ -4,14 +4,17 @@ #define __multigrid_H /*---------------------------- multigrid.h ---------------------------*/ -#include -#include +#include #include +#include +#include #include +#include class MGTransferBase; + /** * Basic matrix class for multigrid preconditioning. * @@ -183,22 +186,135 @@ class MultiGridBase }; -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& dst, - const Vector& src) const = 0; - virtual void restrict(unsigned l, - Vector& dst, - const Vector& 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 &dst, + const Vector &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 &dst, + const Vector &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 + void build_matrices (const MGDoFHandler &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 &dst, + const Vector &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 &dst, + const Vector &src) const = 0; + + private: + + vector 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 > prolongation_matrices; +}; + + + /*---------------------------- multigrid.h ---------------------------*/ /* end of #ifndef __multigrid_H */ #endif diff --git a/deal.II/deal.II/source/multigrid/multigrid.cc b/deal.II/deal.II/source/multigrid/multigrid.cc index c0fa498bf3..5d2a69805f 100644 --- a/deal.II/deal.II/source/multigrid/multigrid.cc +++ b/deal.II/deal.II/source/multigrid/multigrid.cc @@ -1,9 +1,15 @@ // $Id$ // Copyright Guido Kanschat, Universitaet Heidelberg, 1999 +#include +#include +#include +#include +#include #include #include + MultiGridBase::MultiGridBase(MGTransferBase& transfer, unsigned maxlevel, unsigned minlevel, unsigned pre_smooth, unsigned post_smooth) @@ -13,6 +19,7 @@ MultiGridBase::MultiGridBase(MGTransferBase& transfer, n_pre_smooth(pre_smooth), n_post_smooth(post_smooth) {} + void MultiGridBase::level_mgstep(unsigned level) { @@ -48,6 +55,8 @@ MultiGridBase::post_smooth(unsigned level, smooth(level, dst, src, steps); } + + void MultiGridBase::coarse_grid_solution(unsigned level, Vector& dst, @@ -56,5 +65,133 @@ MultiGridBase::coarse_grid_solution(unsigned level, smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth)); } + + + // ab hier Wolfgang + + +/* ------------------------------ MGTransferBase --------------------------- */ + +MGTransferBase::~MGTransferBase () +{}; + + + +/* ----------------------------- MGTransferPrebuilt ------------------------ */ + + +<<<<<<< multigrid.cc +/* +MGTransferPrebuilt::~MGTransferPrebuilt () +{}; + + + +template +void MGTransferPrebuilt::build_matrices (const MGDoFHandler &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 dof_indices_mother (dofs_per_cell); + vector 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::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::children_per_cell; ++child) + { + // set an alias to the + // prolongation matrix for + // this child + const FullMatrix &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::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::children_per_cell; ++child) + { + // set an alias to the + // prolongation matrix for + // this child + const FullMatrix &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 &mg_dof); + +*/ diff --git a/deal.II/deal.II/source/numerics/multigrid.cc b/deal.II/deal.II/source/numerics/multigrid.cc index c0fa498bf3..5d2a69805f 100644 --- a/deal.II/deal.II/source/numerics/multigrid.cc +++ b/deal.II/deal.II/source/numerics/multigrid.cc @@ -1,9 +1,15 @@ // $Id$ // Copyright Guido Kanschat, Universitaet Heidelberg, 1999 +#include +#include +#include +#include +#include #include #include + MultiGridBase::MultiGridBase(MGTransferBase& transfer, unsigned maxlevel, unsigned minlevel, unsigned pre_smooth, unsigned post_smooth) @@ -13,6 +19,7 @@ MultiGridBase::MultiGridBase(MGTransferBase& transfer, n_pre_smooth(pre_smooth), n_post_smooth(post_smooth) {} + void MultiGridBase::level_mgstep(unsigned level) { @@ -48,6 +55,8 @@ MultiGridBase::post_smooth(unsigned level, smooth(level, dst, src, steps); } + + void MultiGridBase::coarse_grid_solution(unsigned level, Vector& dst, @@ -56,5 +65,133 @@ MultiGridBase::coarse_grid_solution(unsigned level, smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth)); } + + + // ab hier Wolfgang + + +/* ------------------------------ MGTransferBase --------------------------- */ + +MGTransferBase::~MGTransferBase () +{}; + + + +/* ----------------------------- MGTransferPrebuilt ------------------------ */ + + +<<<<<<< multigrid.cc +/* +MGTransferPrebuilt::~MGTransferPrebuilt () +{}; + + + +template +void MGTransferPrebuilt::build_matrices (const MGDoFHandler &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 dof_indices_mother (dofs_per_cell); + vector 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::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::children_per_cell; ++child) + { + // set an alias to the + // prolongation matrix for + // this child + const FullMatrix &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::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::children_per_cell; ++child) + { + // set an alias to the + // prolongation matrix for + // this child + const FullMatrix &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 &mg_dof); + +*/ -- 2.39.5