From: guido Date: Tue, 20 Apr 1999 15:00:28 +0000 (+0000) Subject: more mulitgrid and some cosmetics X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1c1c06c3265d49fe4d3b7cc165e1ec297140a48;p=dealii-svn.git more mulitgrid and some cosmetics git-svn-id: https://svn.dealii.org/trunk@1193 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/dofs/dof_handler.h b/deal.II/deal.II/include/dofs/dof_handler.h index 6252b03017..6a1fd77c0d 100644 --- a/deal.II/deal.II/include/dofs/dof_handler.h +++ b/deal.II/deal.II/include/dofs/dof_handler.h @@ -347,7 +347,11 @@ class DoFDimensionInfo<3> { * * @author Wolfgang Bangerth, 1998 */ template -class DoFHandler : public DoFDimensionInfo { +class DoFHandler + : + public Subscriptor, + public DoFDimensionInfo +{ public: typedef typename DoFDimensionInfo::raw_line_iterator raw_line_iterator; typedef typename DoFDimensionInfo::line_iterator line_iterator; diff --git a/deal.II/deal.II/include/dofs/mg_dof_handler.h b/deal.II/deal.II/include/dofs/mg_dof_handler.h index 1d6a7d7fb1..f433d1ce4b 100644 --- a/deal.II/deal.II/include/dofs/mg_dof_handler.h +++ b/deal.II/deal.II/include/dofs/mg_dof_handler.h @@ -121,7 +121,10 @@ class MGDoFDimensionInfo<3> { template -class MGDoFHandler : public DoFHandler { +class MGDoFHandler + : + public DoFHandler +{ public: typedef typename MGDoFDimensionInfo::raw_line_iterator raw_line_iterator; typedef typename MGDoFDimensionInfo::line_iterator line_iterator; diff --git a/deal.II/deal.II/include/multigrid/mg_dof_handler.h b/deal.II/deal.II/include/multigrid/mg_dof_handler.h index 1d6a7d7fb1..f433d1ce4b 100644 --- a/deal.II/deal.II/include/multigrid/mg_dof_handler.h +++ b/deal.II/deal.II/include/multigrid/mg_dof_handler.h @@ -121,7 +121,10 @@ class MGDoFDimensionInfo<3> { template -class MGDoFHandler : public DoFHandler { +class MGDoFHandler + : + public DoFHandler +{ public: typedef typename MGDoFDimensionInfo::raw_line_iterator raw_line_iterator; typedef typename MGDoFDimensionInfo::line_iterator line_iterator; diff --git a/deal.II/deal.II/include/multigrid/mg_smoother.h b/deal.II/deal.II/include/multigrid/mg_smoother.h index 2703b910cf..9f49892d2b 100644 --- a/deal.II/deal.II/include/multigrid/mg_smoother.h +++ b/deal.II/deal.II/include/multigrid/mg_smoother.h @@ -7,21 +7,55 @@ #include #include -#include +#include #include +/** + * Abstract base class for multigrid smoothers. + * In fact, this class only provides the interface of the smoothing function. + * Using deal.II grid handling, #MGSmoother# is a good point to start. + * + * @author Wolfgang Bangerth, Guido Kanschat, 1999 + */ +class MGSmootherBase + : + public Subscriptor +{ + public: + /** + * Virtual destructor. + */ + virtual ~MGSmootherBase(); + + /** + * Smoothen the residual of #u# on the given + * level. This function should keep the interior + * level boundary values, so you may want + * to call #set_zero_interior_boundary# + * in the derived class #MGSmoother# + * somewhere in your derived function, + * or another function doing similar + * things. + */ + virtual void smooth (const unsigned int level, + Vector &u, + const Vector &rhs) const = 0; + +}; /** - * Abstract base class for multigrid smoothers. It declares the interface - * to smoothers and implements some functionality for setting the values + * Base class for multigrid smoothers. It declares the interface + * to smoothers by inheriting #MGSmootherBase# and implements some functionality for setting + * the values * of vectors at interior boundaries (i.e. boundaries between differing * levels of the triangulation) to zero, by building a list of these degrees * of freedom's indices at construction time. * * @author Wolfgang Bangerth, Guido Kanschat, 1999 */ -class MGSmoother : public Subscriptor +class MGSmoother + : public MGSmootherBase { private: /** @@ -60,44 +94,12 @@ class MGSmoother : public Subscriptor * the different levels, which are * needed by the function * #set_zero_interior_boundaries#. - */ - template - MGSmoother (const MGDoFHandler &mg_dof); - - /** - * Destructor, made virtual. - */ - virtual ~MGSmoother (); - - /** - * Smooth the vector #u# on the given - * level. This function should set the - * interior boundary values of u to zero - * at the end of its work, so you may want - * to call #set_zero_interior_boundary# - * at the end of your derived function, - * or another function doing similar - * things. * - * This function is responsible for the - * presmoothing, postsmoothing is done - * by another function, which, however, - * calls this function if not overloaded. - */ - virtual void pre_smooth (const unsigned int level, - Vector &u) const = 0; - - /** - * Postsmoothing; the same applies as for - * the presmoothing function. If you - * want pre- and postsmoothing to do the - * same operations, you may want to not - * overload this function, since its - * default implementation simply calls - * #pre_smooth#. + * The parameter steps indicates the number of smoothing + * steps to be executed by #smooth#. */ - virtual void post_smooth (const unsigned int level, - Vector &u) const; + template + MGSmoother (const MGDoFHandler &mg_dof, unsigned int steps); /** * Reset the values of the degrees of @@ -111,8 +113,20 @@ class MGSmoother : public Subscriptor */ void set_zero_interior_boundary (const unsigned int level, Vector &u) const; + /** + * Modify the number of smoothing steps. + */ + void set_steps(unsigned int steps); + /** + * How many steps should be used? + */ + unsigned int get_steps() const; private: + /** + * Number of smoothing steps. + */ + unsigned int steps; /** * For each level, we store a list of * degree of freedom indices which are @@ -123,11 +137,66 @@ class MGSmoother : public Subscriptor * entry refers to the second level. * * These arrays are set by the constructor. + * The entries for each level are sorted ascendingly. */ vector > interior_boundary_dofs; }; +/** + * Implementation of an SOR smoother. + * + * This class is an implementation of a smootin algorithm for multigrid. It + * knows the actual instance of the multigrid matrix and uses the SOR method of the level + * matrices. + * @author Wolfgang Bangerth, Guido Kanschat, 1999 + */ +class MGSmootherSOR + : + public MGSmoother +{ + public: + /** + * Constructor. + * The constructor uses an #MGDoFHandler# to initialize + * data structures for interior level boundary handling + * in #MGSmoother#. Furthermore, it takes a pointer to the + * matrices and the number of SOR steps required in each + * smoothing operation. + */ + + template + MGSmootherSOR(const MGDoFHandler &mg_dof, + const MGMatrix& matrix, + unsigned int steps); + /** + * Implementation of the interface in #MGSmootherBase#. + * We use the SOR method in #SparseMatrix# for the real work + * and find a way to keep the boundary values. + */ + virtual void smooth (const unsigned int level, + Vector &u, + const Vector &rhs) const; + private: + /** + * Pointer to the matrices. + */ + SmartPointer< const MGMatrix > matrix; +}; + +inline +void +MGSmoother::set_steps(unsigned int i) +{ + steps = i; +} + +inline +unsigned int +MGSmoother::get_steps() const +{ + return steps; +} /*---------------------------- mg_smoother.h ---------------------------*/ diff --git a/deal.II/deal.II/include/multigrid/multigrid.h b/deal.II/deal.II/include/multigrid/multigrid.h index 81a59959b7..942166e8cd 100644 --- a/deal.II/deal.II/include/multigrid/multigrid.h +++ b/deal.II/deal.II/include/multigrid/multigrid.h @@ -4,6 +4,7 @@ #define __multigrid_H /*---------------------------- multigrid.h ---------------------------*/ +#include #include #include #include @@ -12,7 +13,7 @@ #include class MGTransferBase; -class MGSmoother; +class MGSmootherBase; /** @@ -44,12 +45,12 @@ class MultiGridBase const MultiGridBase& operator=(const MultiGridBase&); /** - * Auxiliary vector. + * Auxiliary vector, defect. */ vector > d; /** - * Auxiliary vector. + * Auxiliary vector, solution. */ vector > s; @@ -58,33 +59,22 @@ class MultiGridBase */ Vector t; - /** - * Highest level of cells. - */ - unsigned maxlevel; - - /** - * Level for coarse grid solution. - */ - unsigned minlevel; - /** * Prolongation and restriction object. */ - SmartPointer transfer; + SmartPointer transfer; protected: /** - * Number of pre-smoothing steps. Is used - * as a parameter to #pre_smooth#. + * Highest level of cells. */ - unsigned n_pre_smooth; - + unsigned int maxlevel; + /** - * Number of post-smoothing steps Is used - * as a parameter to #post_smooth#. + * Level for coarse grid solution. */ - unsigned n_post_smooth; + unsigned int minlevel; + /** * The actual v-cycle multigrid method. * This function is called on the @@ -94,7 +84,9 @@ class MultiGridBase * #coarse_grid_solution# and * proceeds back up. */ - void level_mgstep(unsigned level, MGSmoother& smoother); + void level_mgstep(unsigned int level, + const MGSmootherBase& pre_smooth, + const MGSmootherBase& post_smooth); /** * Apply residual operator on all @@ -102,7 +94,7 @@ class MultiGridBase * This is implemented in a * derived class. */ - virtual void level_residual(unsigned level, + virtual void level_residual(unsigned int level, Vector& dst, const Vector& src, const Vector& rhs) = 0; @@ -118,7 +110,7 @@ class MultiGridBase * n_post_smooth)# * smoothing steps of #pre_smooth#. */ - virtual void coarse_grid_solution(unsigned l, + virtual void coarse_grid_solution(unsigned int l, Vector& dst, const Vector& src); @@ -130,9 +122,8 @@ class MultiGridBase /** * Constructor, subject to change. */ - MultiGridBase(MGTransferBase& transfer, - unsigned maxlevel, unsigned minlevel, - unsigned pre_smooth, unsigned post_smooth); + MultiGridBase(const MGTransferBase& transfer, + unsigned int maxlevel, unsigned int minlevel); virtual ~MultiGridBase(); }; @@ -190,6 +181,30 @@ class MGTransferBase : public Subscriptor const Vector &src) const = 0; }; +/** + * An array of matrices for each level. + * This class provides the functionality of #vector ># combined + * with a subscriptor for smart pointers. + * @author Guido Kanschat, 1999 + */ +class MGMatrix + : + public Subscriptor, + public Vector > +{ + public: + /** + * Standard constructor. + */ + MGMatrix() + {} + /** + * Constructor allowing to initialize the number of levels. + */ + MGMatrix(unsigned int n_levels); +}; + + /** * Implementation of multigrid with matrices. * While #MultiGridBase# was only an abstract framework for the v-cycle, @@ -198,11 +213,13 @@ class MGTransferBase : public Subscriptor * * @author Wolfgang Bangerth, Guido Kanschat, 1999 */ -template +template class MultiGrid + : + public MultiGridBase { public: - MultiGrid(const MGDoFHandler&); + MultiGrid(const MGDoFHandler&, const MGTransferBase& transfer); /** Transfer from dVector to * MGVector. @@ -230,11 +247,32 @@ class MultiGrid template void copy_from_mg(Vector& dst, const vector >& src) const; + + /** + * Access to matrix structure. + */ + SparseMatrixStruct& get_sparsity_pattern(unsigned int level); + + /** + * Read-only access to matrix structure. + */ + const SparseMatrixStruct& get_sparsity_pattern(unsigned int level) const; + + /** + * Access to level matrices. + */ + SparseMatrix& get_matrix(unsigned int level); + + /** + * Read-only access to level matrices. + */ + const SparseMatrix& get_matrix(unsigned int level) const; + private: /** * Associated #MGDoFHandler#. */ - SmartPointer > dofs; + SmartPointer > dofs; /** * Matrix structures for each level. @@ -327,6 +365,26 @@ class MGTransferPrebuilt : public MGTransferBase vector > prolongation_matrices; }; +template +inline +SparseMatrix& +MultiGrid::get_matrix(unsigned int level) +{ + Assert((level>=minlevel) && (level +inline +const SparseMatrix& +MultiGrid::get_matrix(unsigned int level) const +{ + Assert((level>=minlevel) && (level #include -#include +#include #include +/** + * Abstract base class for multigrid smoothers. + * In fact, this class only provides the interface of the smoothing function. + * Using deal.II grid handling, #MGSmoother# is a good point to start. + * + * @author Wolfgang Bangerth, Guido Kanschat, 1999 + */ +class MGSmootherBase + : + public Subscriptor +{ + public: + /** + * Virtual destructor. + */ + virtual ~MGSmootherBase(); + + /** + * Smoothen the residual of #u# on the given + * level. This function should keep the interior + * level boundary values, so you may want + * to call #set_zero_interior_boundary# + * in the derived class #MGSmoother# + * somewhere in your derived function, + * or another function doing similar + * things. + */ + virtual void smooth (const unsigned int level, + Vector &u, + const Vector &rhs) const = 0; + +}; /** - * Abstract base class for multigrid smoothers. It declares the interface - * to smoothers and implements some functionality for setting the values + * Base class for multigrid smoothers. It declares the interface + * to smoothers by inheriting #MGSmootherBase# and implements some functionality for setting + * the values * of vectors at interior boundaries (i.e. boundaries between differing * levels of the triangulation) to zero, by building a list of these degrees * of freedom's indices at construction time. * * @author Wolfgang Bangerth, Guido Kanschat, 1999 */ -class MGSmoother : public Subscriptor +class MGSmoother + : public MGSmootherBase { private: /** @@ -60,44 +94,12 @@ class MGSmoother : public Subscriptor * the different levels, which are * needed by the function * #set_zero_interior_boundaries#. - */ - template - MGSmoother (const MGDoFHandler &mg_dof); - - /** - * Destructor, made virtual. - */ - virtual ~MGSmoother (); - - /** - * Smooth the vector #u# on the given - * level. This function should set the - * interior boundary values of u to zero - * at the end of its work, so you may want - * to call #set_zero_interior_boundary# - * at the end of your derived function, - * or another function doing similar - * things. * - * This function is responsible for the - * presmoothing, postsmoothing is done - * by another function, which, however, - * calls this function if not overloaded. - */ - virtual void pre_smooth (const unsigned int level, - Vector &u) const = 0; - - /** - * Postsmoothing; the same applies as for - * the presmoothing function. If you - * want pre- and postsmoothing to do the - * same operations, you may want to not - * overload this function, since its - * default implementation simply calls - * #pre_smooth#. + * The parameter steps indicates the number of smoothing + * steps to be executed by #smooth#. */ - virtual void post_smooth (const unsigned int level, - Vector &u) const; + template + MGSmoother (const MGDoFHandler &mg_dof, unsigned int steps); /** * Reset the values of the degrees of @@ -111,8 +113,20 @@ class MGSmoother : public Subscriptor */ void set_zero_interior_boundary (const unsigned int level, Vector &u) const; + /** + * Modify the number of smoothing steps. + */ + void set_steps(unsigned int steps); + /** + * How many steps should be used? + */ + unsigned int get_steps() const; private: + /** + * Number of smoothing steps. + */ + unsigned int steps; /** * For each level, we store a list of * degree of freedom indices which are @@ -123,11 +137,66 @@ class MGSmoother : public Subscriptor * entry refers to the second level. * * These arrays are set by the constructor. + * The entries for each level are sorted ascendingly. */ vector > interior_boundary_dofs; }; +/** + * Implementation of an SOR smoother. + * + * This class is an implementation of a smootin algorithm for multigrid. It + * knows the actual instance of the multigrid matrix and uses the SOR method of the level + * matrices. + * @author Wolfgang Bangerth, Guido Kanschat, 1999 + */ +class MGSmootherSOR + : + public MGSmoother +{ + public: + /** + * Constructor. + * The constructor uses an #MGDoFHandler# to initialize + * data structures for interior level boundary handling + * in #MGSmoother#. Furthermore, it takes a pointer to the + * matrices and the number of SOR steps required in each + * smoothing operation. + */ + + template + MGSmootherSOR(const MGDoFHandler &mg_dof, + const MGMatrix& matrix, + unsigned int steps); + /** + * Implementation of the interface in #MGSmootherBase#. + * We use the SOR method in #SparseMatrix# for the real work + * and find a way to keep the boundary values. + */ + virtual void smooth (const unsigned int level, + Vector &u, + const Vector &rhs) const; + private: + /** + * Pointer to the matrices. + */ + SmartPointer< const MGMatrix > matrix; +}; + +inline +void +MGSmoother::set_steps(unsigned int i) +{ + steps = i; +} + +inline +unsigned int +MGSmoother::get_steps() const +{ + return steps; +} /*---------------------------- mg_smoother.h ---------------------------*/ diff --git a/deal.II/deal.II/include/numerics/multigrid.h b/deal.II/deal.II/include/numerics/multigrid.h index 81a59959b7..942166e8cd 100644 --- a/deal.II/deal.II/include/numerics/multigrid.h +++ b/deal.II/deal.II/include/numerics/multigrid.h @@ -4,6 +4,7 @@ #define __multigrid_H /*---------------------------- multigrid.h ---------------------------*/ +#include #include #include #include @@ -12,7 +13,7 @@ #include class MGTransferBase; -class MGSmoother; +class MGSmootherBase; /** @@ -44,12 +45,12 @@ class MultiGridBase const MultiGridBase& operator=(const MultiGridBase&); /** - * Auxiliary vector. + * Auxiliary vector, defect. */ vector > d; /** - * Auxiliary vector. + * Auxiliary vector, solution. */ vector > s; @@ -58,33 +59,22 @@ class MultiGridBase */ Vector t; - /** - * Highest level of cells. - */ - unsigned maxlevel; - - /** - * Level for coarse grid solution. - */ - unsigned minlevel; - /** * Prolongation and restriction object. */ - SmartPointer transfer; + SmartPointer transfer; protected: /** - * Number of pre-smoothing steps. Is used - * as a parameter to #pre_smooth#. + * Highest level of cells. */ - unsigned n_pre_smooth; - + unsigned int maxlevel; + /** - * Number of post-smoothing steps Is used - * as a parameter to #post_smooth#. + * Level for coarse grid solution. */ - unsigned n_post_smooth; + unsigned int minlevel; + /** * The actual v-cycle multigrid method. * This function is called on the @@ -94,7 +84,9 @@ class MultiGridBase * #coarse_grid_solution# and * proceeds back up. */ - void level_mgstep(unsigned level, MGSmoother& smoother); + void level_mgstep(unsigned int level, + const MGSmootherBase& pre_smooth, + const MGSmootherBase& post_smooth); /** * Apply residual operator on all @@ -102,7 +94,7 @@ class MultiGridBase * This is implemented in a * derived class. */ - virtual void level_residual(unsigned level, + virtual void level_residual(unsigned int level, Vector& dst, const Vector& src, const Vector& rhs) = 0; @@ -118,7 +110,7 @@ class MultiGridBase * n_post_smooth)# * smoothing steps of #pre_smooth#. */ - virtual void coarse_grid_solution(unsigned l, + virtual void coarse_grid_solution(unsigned int l, Vector& dst, const Vector& src); @@ -130,9 +122,8 @@ class MultiGridBase /** * Constructor, subject to change. */ - MultiGridBase(MGTransferBase& transfer, - unsigned maxlevel, unsigned minlevel, - unsigned pre_smooth, unsigned post_smooth); + MultiGridBase(const MGTransferBase& transfer, + unsigned int maxlevel, unsigned int minlevel); virtual ~MultiGridBase(); }; @@ -190,6 +181,30 @@ class MGTransferBase : public Subscriptor const Vector &src) const = 0; }; +/** + * An array of matrices for each level. + * This class provides the functionality of #vector ># combined + * with a subscriptor for smart pointers. + * @author Guido Kanschat, 1999 + */ +class MGMatrix + : + public Subscriptor, + public Vector > +{ + public: + /** + * Standard constructor. + */ + MGMatrix() + {} + /** + * Constructor allowing to initialize the number of levels. + */ + MGMatrix(unsigned int n_levels); +}; + + /** * Implementation of multigrid with matrices. * While #MultiGridBase# was only an abstract framework for the v-cycle, @@ -198,11 +213,13 @@ class MGTransferBase : public Subscriptor * * @author Wolfgang Bangerth, Guido Kanschat, 1999 */ -template +template class MultiGrid + : + public MultiGridBase { public: - MultiGrid(const MGDoFHandler&); + MultiGrid(const MGDoFHandler&, const MGTransferBase& transfer); /** Transfer from dVector to * MGVector. @@ -230,11 +247,32 @@ class MultiGrid template void copy_from_mg(Vector& dst, const vector >& src) const; + + /** + * Access to matrix structure. + */ + SparseMatrixStruct& get_sparsity_pattern(unsigned int level); + + /** + * Read-only access to matrix structure. + */ + const SparseMatrixStruct& get_sparsity_pattern(unsigned int level) const; + + /** + * Access to level matrices. + */ + SparseMatrix& get_matrix(unsigned int level); + + /** + * Read-only access to level matrices. + */ + const SparseMatrix& get_matrix(unsigned int level) const; + private: /** * Associated #MGDoFHandler#. */ - SmartPointer > dofs; + SmartPointer > dofs; /** * Matrix structures for each level. @@ -327,6 +365,26 @@ class MGTransferPrebuilt : public MGTransferBase vector > prolongation_matrices; }; +template +inline +SparseMatrix& +MultiGrid::get_matrix(unsigned int level) +{ + Assert((level>=minlevel) && (level +inline +const SparseMatrix& +MultiGrid::get_matrix(unsigned int level) const +{ + Assert((level>=minlevel) && (level > refine_flags, coarsen_flags; + vector > refine_flags; + + /** + * @see refine_flags + */ + vector > coarsen_flags; /** * Restore the grid according to the saved @@ -1504,7 +1509,11 @@ struct TimeStepBase_Tria::RefinementFlags * (first: top deviation, second: bottom * deviation). */ - const double cell_number_corridor_top, cell_number_corridor_bottom; + const double cell_number_corridor_top; + /** + * @see cell_number_corridor_top + */ + const double cell_number_corridor_bottom; /** * List of relaxations to the correction diff --git a/deal.II/deal.II/source/multigrid/mg_smoother.cc b/deal.II/deal.II/source/multigrid/mg_smoother.cc index bc6a227a85..98fe594fca 100644 --- a/deal.II/deal.II/source/multigrid/mg_smoother.cc +++ b/deal.II/deal.II/source/multigrid/mg_smoother.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -13,7 +14,9 @@ #if deal_II_dimension == 1 -MGSmoother::MGSmoother (const MGDoFHandler<1> &/*mg_dof*/) +MGSmoother::MGSmoother (const MGDoFHandler<1> &/*mg_dof*/, unsigned int steps) + : + steps(steps) { Assert (false, ExcNotImplemented()); }; @@ -24,7 +27,9 @@ MGSmoother::MGSmoother (const MGDoFHandler<1> &/*mg_dof*/) #if deal_II_dimension > 1 template -MGSmoother::MGSmoother (const MGDoFHandler &mg_dof) +MGSmoother::MGSmoother (const MGDoFHandler &mg_dof, unsigned int steps) + : + steps(steps) { const unsigned int n_levels = mg_dof.get_tria().n_levels(); @@ -83,12 +88,12 @@ MGSmoother::MGSmoother (const MGDoFHandler &mg_dof) #endif +////////////////////////////////////////////////////////////////////// - -MGSmoother::~MGSmoother () +MGSmootherBase::~MGSmootherBase () {}; - +////////////////////////////////////////////////////////////////////// void MGSmoother::set_zero_interior_boundary (const unsigned int level, @@ -102,22 +107,32 @@ MGSmoother::set_zero_interior_boundary (const unsigned int level, u(*p) = 0; }; +////////////////////////////////////////////////////////////////////// - +template +MGSmootherSOR::MGSmootherSOR(const MGDoFHandler &mg_dof, + const MGMatrix& matrix, + unsigned int steps) + : + MGSmoother(mg_dof, steps), + matrix(&matrix) +{} void -MGSmoother::post_smooth (const unsigned int level, - Vector &u) const +MGSmootherSOR::smooth (const unsigned int /*level*/, + Vector &/*u*/, + const Vector &/*rhs*/) const { - pre_smooth (level, u); -}; - - +} // explicit instantiations // don't do the following instantiation in 1d, since there is a specialized // function there #if deal_II_dimension > 1 -template MGSmoother::MGSmoother (const MGDoFHandler&); +template MGSmoother::MGSmoother (const MGDoFHandler&, unsigned int); #endif + +template MGSmootherSOR::MGSmootherSOR(const MGDoFHandler &mg_dof, + const MGMatrix& matrix, unsigned int steps); + diff --git a/deal.II/deal.II/source/multigrid/multigrid.cc b/deal.II/deal.II/source/multigrid/multigrid.cc index f17272409f..8578b44254 100644 --- a/deal.II/deal.II/source/multigrid/multigrid.cc +++ b/deal.II/deal.II/source/multigrid/multigrid.cc @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include @@ -15,19 +17,19 @@ MultiGridBase::~MultiGridBase () -MultiGridBase::MultiGridBase(MGTransferBase& transfer, - unsigned maxlevel, unsigned minlevel, - unsigned pre_smooth, unsigned post_smooth) +MultiGridBase::MultiGridBase(const MGTransferBase& transfer, + unsigned maxlevel, unsigned minlevel) : d(maxlevel-minlevel), s(maxlevel-minlevel), - maxlevel(maxlevel), minlevel(minlevel), transfer(&transfer), - n_pre_smooth(pre_smooth), n_post_smooth(post_smooth) + maxlevel(maxlevel), minlevel(minlevel) {} void -MultiGridBase::level_mgstep(unsigned level, MGSmoother& smoother) +MultiGridBase::level_mgstep(unsigned level, + const MGSmootherBase& pre_smooth, + const MGSmootherBase& post_smooth) { if (level == minlevel) { @@ -36,7 +38,7 @@ MultiGridBase::level_mgstep(unsigned level, MGSmoother& smoother) } // smoothing of the residual by modifying s -// smooth(level, d[level], s[level], n_pre_smooth); + pre_smooth.smooth(level, s[level], d[level]); // t = d-As level_residual(level, t, s[level], d[level]); @@ -44,12 +46,12 @@ MultiGridBase::level_mgstep(unsigned level, MGSmoother& smoother) // make t rhs of lower level transfer->restrict(level, t, d[level-1]); // do recursion - level_mgstep(level-1, smoother); + level_mgstep(level-1, pre_smooth, post_smooth); // do coarse grid correction transfer->prolongate(level, s[level], s[level-1]); // smoothing (modify s again) -// post_smooth(level, d[level], s[level], n_post_smooth); + post_smooth.smooth(level, s[level], d[level]); } @@ -223,4 +225,4 @@ void MGTransferPrebuilt::restrict (const unsigned int from_level, template void MGTransferPrebuilt::build_matrices (const MGDoFHandler &mg_dof); - +template MultiGrid; diff --git a/deal.II/deal.II/source/numerics/mg_smoother.cc b/deal.II/deal.II/source/numerics/mg_smoother.cc index bc6a227a85..98fe594fca 100644 --- a/deal.II/deal.II/source/numerics/mg_smoother.cc +++ b/deal.II/deal.II/source/numerics/mg_smoother.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -13,7 +14,9 @@ #if deal_II_dimension == 1 -MGSmoother::MGSmoother (const MGDoFHandler<1> &/*mg_dof*/) +MGSmoother::MGSmoother (const MGDoFHandler<1> &/*mg_dof*/, unsigned int steps) + : + steps(steps) { Assert (false, ExcNotImplemented()); }; @@ -24,7 +27,9 @@ MGSmoother::MGSmoother (const MGDoFHandler<1> &/*mg_dof*/) #if deal_II_dimension > 1 template -MGSmoother::MGSmoother (const MGDoFHandler &mg_dof) +MGSmoother::MGSmoother (const MGDoFHandler &mg_dof, unsigned int steps) + : + steps(steps) { const unsigned int n_levels = mg_dof.get_tria().n_levels(); @@ -83,12 +88,12 @@ MGSmoother::MGSmoother (const MGDoFHandler &mg_dof) #endif +////////////////////////////////////////////////////////////////////// - -MGSmoother::~MGSmoother () +MGSmootherBase::~MGSmootherBase () {}; - +////////////////////////////////////////////////////////////////////// void MGSmoother::set_zero_interior_boundary (const unsigned int level, @@ -102,22 +107,32 @@ MGSmoother::set_zero_interior_boundary (const unsigned int level, u(*p) = 0; }; +////////////////////////////////////////////////////////////////////// - +template +MGSmootherSOR::MGSmootherSOR(const MGDoFHandler &mg_dof, + const MGMatrix& matrix, + unsigned int steps) + : + MGSmoother(mg_dof, steps), + matrix(&matrix) +{} void -MGSmoother::post_smooth (const unsigned int level, - Vector &u) const +MGSmootherSOR::smooth (const unsigned int /*level*/, + Vector &/*u*/, + const Vector &/*rhs*/) const { - pre_smooth (level, u); -}; - - +} // explicit instantiations // don't do the following instantiation in 1d, since there is a specialized // function there #if deal_II_dimension > 1 -template MGSmoother::MGSmoother (const MGDoFHandler&); +template MGSmoother::MGSmoother (const MGDoFHandler&, unsigned int); #endif + +template MGSmootherSOR::MGSmootherSOR(const MGDoFHandler &mg_dof, + const MGMatrix& matrix, unsigned int steps); + diff --git a/deal.II/deal.II/source/numerics/multigrid.cc b/deal.II/deal.II/source/numerics/multigrid.cc index f17272409f..8578b44254 100644 --- a/deal.II/deal.II/source/numerics/multigrid.cc +++ b/deal.II/deal.II/source/numerics/multigrid.cc @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include @@ -15,19 +17,19 @@ MultiGridBase::~MultiGridBase () -MultiGridBase::MultiGridBase(MGTransferBase& transfer, - unsigned maxlevel, unsigned minlevel, - unsigned pre_smooth, unsigned post_smooth) +MultiGridBase::MultiGridBase(const MGTransferBase& transfer, + unsigned maxlevel, unsigned minlevel) : d(maxlevel-minlevel), s(maxlevel-minlevel), - maxlevel(maxlevel), minlevel(minlevel), transfer(&transfer), - n_pre_smooth(pre_smooth), n_post_smooth(post_smooth) + maxlevel(maxlevel), minlevel(minlevel) {} void -MultiGridBase::level_mgstep(unsigned level, MGSmoother& smoother) +MultiGridBase::level_mgstep(unsigned level, + const MGSmootherBase& pre_smooth, + const MGSmootherBase& post_smooth) { if (level == minlevel) { @@ -36,7 +38,7 @@ MultiGridBase::level_mgstep(unsigned level, MGSmoother& smoother) } // smoothing of the residual by modifying s -// smooth(level, d[level], s[level], n_pre_smooth); + pre_smooth.smooth(level, s[level], d[level]); // t = d-As level_residual(level, t, s[level], d[level]); @@ -44,12 +46,12 @@ MultiGridBase::level_mgstep(unsigned level, MGSmoother& smoother) // make t rhs of lower level transfer->restrict(level, t, d[level-1]); // do recursion - level_mgstep(level-1, smoother); + level_mgstep(level-1, pre_smooth, post_smooth); // do coarse grid correction transfer->prolongate(level, s[level], s[level-1]); // smoothing (modify s again) -// post_smooth(level, d[level], s[level], n_post_smooth); + post_smooth.smooth(level, s[level], d[level]); } @@ -223,4 +225,4 @@ void MGTransferPrebuilt::restrict (const unsigned int from_level, template void MGTransferPrebuilt::build_matrices (const MGDoFHandler &mg_dof); - +template MultiGrid; diff --git a/deal.II/doc/parser/dealparse.l b/deal.II/doc/parser/dealparse.l index eb9d17129e..24f07b2f3b 100644 --- a/deal.II/doc/parser/dealparse.l +++ b/deal.II/doc/parser/dealparse.l @@ -16,8 +16,10 @@ extern int yydebug; %x LINECOMMENT %x EXC_IGNORE %x INSTRING +%x INFUNCTION +%x BASEINIT -NAME [a-zA-Z][_a-zA-Z0-9]* +NAME [_a-zA-Z][_a-zA-Z0-9]* INT [+-]?[0-9]+ WHITE [ \t\n\f\v] CLASS (class)|(struct)|(union) @@ -49,9 +51,21 @@ DeclException[0-9] { return(DECLEXCEPTION); } . \n { yy_pop_state(); } + /* Ignore function bodies */ + +"{" { yy_push_state(INFUNCTION); } +"}" { yy_pop_state(); } +. +\n + + /* Ignore base initializers */ +"{" { yy_pop_state(); yy_push_state(INFUNCTION); } +. +\n + /* Ignore preprocessor commands */ -^#.*\n +^#.*(\\\n.*)*\n /* Ignore friend declarations so far */ @@ -69,6 +83,7 @@ template { return TEMPLATE; } enum { return ENUM; } friend { return FRIEND; } typedef { return TYPEDEF; } +namespace { return NAMESPACE; } typename {} {CLASS} { yylval = string(yytext); return CLASS; } @@ -92,5 +107,15 @@ typename {} cerr << "[" << yylval << "]"; return IDENTIFIER; } . { yylval = string(yytext); return yytext[0]; } +"..." { yylval = string(yytext); return THREEDOTS; } %% +void enterfunction() +{ + yy_push_state(INFUNCTION); +} + +void enterbaseinitializers() +{ + yy_push_state(BASEINIT); +} diff --git a/deal.II/doc/parser/dealparse.y b/deal.II/doc/parser/dealparse.y index 18e7fd0c33..c8d0bafd2d 100644 --- a/deal.II/doc/parser/dealparse.y +++ b/deal.II/doc/parser/dealparse.y @@ -12,7 +12,8 @@ stack class_stack; stack access_stack; int yylex(); -void yy_push_fargs(); +void enterfunction(); +void enterbaseinitializers(); void yyerror(const char* s) { @@ -20,6 +21,7 @@ void yyerror(const char* s) } %} +%token NAMESPACE %token CLASS %token TYPEDEF %token ACCESS @@ -42,6 +44,7 @@ void yyerror(const char* s) %token COMTEMP %token DECLEXCEPTION %token INLINE +%token THREEDOTS %token ENDOFDECL %% @@ -52,49 +55,56 @@ all: declaration_list declaration_list: declaration | declaration_list { cout << "@@@" << endl; } declaration + | NAMESPACE '{' declaration_list '}' ';' | declaration_list ';' ; declaration: class_declaration ';' + | function_declaration '{' { enterfunction(); } + | function_declaration ':' { enterbaseinitializers(); } | function_declaration ';' - | function_declaration '{' '}' ';' - | function_declaration '{' '}' | variable_declaration ';' | enum_declaration ';' | typedef_declaration ';' | template_declaration class_declaration ';' - { cout << setw(OUTW) << "Template-Description:" << $1 << endl; } + { cout << setw(OUTW) << "@Template-Description:" << $1 << endl; } | template_declaration function_declaration ';' - { cout << setw(OUTW) << "Template-Description:" << $1 << endl; } + { cout << setw(OUTW) << "@Template-Description:" << $1 << endl; } + | template_declaration function_declaration '{' { enterfunction(); + cout << setw(OUTW) << "@Template-Description:" << $1 << endl; } + | template_declaration function_declaration ':' { enterbaseinitializers(); + cout << setw(OUTW) << "@Template-Description:" << $1 << endl; } | deal_exception_declaration ';' + | ';' ; variable_declaration: vartype identifier - { cout << setw(OUTW) << "Variable-Declaration:" << $2 << endl - << setw(OUTW) << "Type:" << $1 << endl - << setw(OUTW) << "In-Class:" << class_stack.top() << endl - << setw(OUTW) << "Access:" << access_stack.top() << endl; } + { cout << setw(OUTW) << "@Variable-Declaration:" << $2 << endl + << setw(OUTW) << "@Type:" << $1 << endl + << setw(OUTW) << "@In-Class:" << class_stack.top() << endl + << setw(OUTW) << "@Access:" << access_stack.top() << endl; } | vartype identifier array_dimensions - { cout << setw(OUTW) << "Variable-Declaration:" << $2 << endl - << setw(OUTW) << "Type:" << $1 << endl - << setw(OUTW) << "In-Class:" << class_stack.top() << endl - << setw(OUTW) << "Access:" << access_stack.top() << endl - << setw(OUTW) << "Array-Dimension:" << $3 << endl; } + { cout << setw(OUTW) << "@Variable-Declaration:" << $2 << endl + << setw(OUTW) << "@Type:" << $1 << endl + << setw(OUTW) << "@In-Class:" << class_stack.top() << endl + << setw(OUTW) << "@Access:" << access_stack.top() << endl + << setw(OUTW) << "@Array-Dimension:" << $3 << endl; } | variable_declaration '=' expression +/* | enum_declaration identifier*/ ; typedef_declaration: TYPEDEF vartype identifier - { cout << setw(OUTW) << "Typedef:" << $3 << endl - << setw(OUTW) << "Type:" << $2 << endl - << setw(OUTW) << "Access:" << access_stack.top() << endl; } + { cout << setw(OUTW) << "@Typedef:" << $3 << endl + << setw(OUTW) << "@Type:" << $2 << endl + << setw(OUTW) << "@Access:" << access_stack.top() << endl; } | TYPEDEF vartype identifier array_dimensions - { cout << setw(OUTW) << "Typedef:" << $3 << endl - << setw(OUTW) << "Type:" << $2 << endl - << setw(OUTW) << "Access:" << access_stack.top() << endl - << setw(OUTW) << "Array-Dimension:" << $4 << endl; } + { cout << setw(OUTW) << "@Typedef:" << $3 << endl + << setw(OUTW) << "@Type:" << $2 << endl + << setw(OUTW) << "@Access:" << access_stack.top() << endl + << setw(OUTW) << "@Array-Dimension:" << $4 << endl; } ; array_dimensions: @@ -107,22 +117,22 @@ array_dimensions: function_declaration: function_name argument_declaration { - cout << setw(OUTW) << "Function-Definition:" << $1 << endl - << setw(OUTW) << "Function-Parameters:" << $2 << endl - << setw(OUTW) << "In-Class:" << class_stack.top() << endl - << setw(OUTW) << "Access:" << access_stack.top() << endl; + cout << setw(OUTW) << "@Function-Definition:" << $1 << endl + << setw(OUTW) << "@Function-Parameters:" << $2 << endl + << setw(OUTW) << "@In-Class:" << class_stack.top() << endl + << setw(OUTW) << "@Access:" << access_stack.top() << endl; } | function_name argument_declaration CONST { - cout << setw(OUTW) << "Function-Definition:" << $1 << endl - << setw(OUTW) << "Function-Parameters:" << $2 << endl - << setw(OUTW) << "Const:" << "const" << endl - << setw(OUTW) << "In-Class:" << class_stack.top() << endl - << setw(OUTW) << "Access:" << access_stack.top() << endl; + cout << setw(OUTW) << "@Function-Definition:" << $1 << endl + << setw(OUTW) << "@Function-Parameters:" << $2 << endl + << setw(OUTW) << "@Const:" << "const" << endl + << setw(OUTW) << "@In-Class:" << class_stack.top() << endl + << setw(OUTW) << "@Access:" << access_stack.top() << endl; } | vartype function_declaration { - cout << setw(OUTW) << "Return-Type:" << $1 << endl; + cout << setw(OUTW) << "@Return-Type:" << $1 << endl; } ; @@ -131,7 +141,7 @@ function_name: | '~' identifier { $$ = string("~") + $2; } | OPERATOR operator { $$ = string("operator") + $2; } | OPERATOR vartype { $$ = string("operator") + $2; } - + | identifier ':' ':' function_name { $$ = $1 + string("::") + $4; } ; operator: OP @@ -147,6 +157,7 @@ operator: OP argument_declaration: '(' ')' { $$ = string(""); } + | '(' THREEDOTS ')' { $$ = $2; } | '(' arguments ')' { $$ = $2; } ; @@ -193,8 +204,8 @@ class_declaration: class_head { class_stack.pop(); access_stack.pop(); - cout << "@@@" << endl << setw(OUTW) << "Class-Definition:" << $1 << endl - << setw(OUTW) << "In-Class:" << class_stack.top() << endl; + cout << "@@@" << endl << setw(OUTW) << "@Class-Definition:" << $1 << endl + << setw(OUTW) << "@In-Class:" << class_stack.top() << endl; } ; @@ -231,11 +242,11 @@ member_declaration: declaration | VIRTUAL declaration { - cout << setw(OUTW) << "Virtual:" << "virtual" << endl; + cout << setw(OUTW) << "@Virtual:" << "virtual" << endl; } | VIRTUAL function_declaration '=' INT { - cout << setw(OUTW) << "Virtual:" << "pure" << endl; + cout << setw(OUTW) << "@Virtual:" << "pure" << endl; } | ACCESS ':' { access_stack.top() = $1; } | friend_declaration @@ -250,7 +261,7 @@ vartype: identifier { $$ = $1; } | UNSIGNED IDENTIFIER { $$ = string("unsigned ") + $2; } | CONST vartype { $$ = string("const ") + $2; } -/* | vartype CONST { $$ = $1 + string(" const"); } */ + | vartype '*' CONST { $$ = $1 + string("* const"); } | vartype '&' { $$ = $1 + string("&"); } | vartype '*' { $$ = $1 + string("*"); } | STATIC vartype { $$ = string("static ") + $2; } @@ -276,6 +287,7 @@ expression: | expression OP expression { $$ = $1 + $2 + $3; } | expression INT { $$ = $1 + $2; } | identifier argument_declaration { $$ = $1 + $2; } + | '(' expression ')' { $$ = $1 + $2 + $3; } ; literal: @@ -300,10 +312,15 @@ template_arg: | CLASS IDENTIFIER { $$ = $1 + SPC + $2; } ; -template_declaration: +template_statement: TEMPLATE '<' arguments '>' { $$ = $3; } ; +template_declaration: + template_statement + | template_declaration template_statement { $$ = $1 + $2; } +; + deal_exception_declaration: DECLEXCEPTION '(' IDENTIFIER deal_exception_arglist ')' ; diff --git a/tests/deal.II/fe_tables.cc b/tests/deal.II/fe_tables.cc index 725e6743f9..03e1b8d536 100644 --- a/tests/deal.II/fe_tables.cc +++ b/tests/deal.II/fe_tables.cc @@ -36,7 +36,7 @@ print_fe_statistics(const FiniteElement& fe) DoFHandler dof(&tr); dof.distribute_dofs(fe); StraightBoundary boundary; - DoFHandler::active_cell_iterator cell = dof.begin_active(); +// DoFHandler::active_cell_iterator cell = dof.begin_active(); DoFHandler::active_face_iterator face = dof.begin_active_face(); vector > unit_points(fe.total_dofs); diff --git a/tests/deal.II/mg1.cc b/tests/deal.II/mg1.cc index 0497bec99b..8c2efd4f32 100644 --- a/tests/deal.II/mg1.cc +++ b/tests/deal.II/mg1.cc @@ -4,6 +4,7 @@ // deal_II_libraries=-ldeal_II_2d #include +#include class TransferTest : @@ -18,13 +19,27 @@ class TransferTest friend class MultiGridBase; }; +class SmoothTest + : + public MGSmootherBase +{ + public: + virtual void smooth (const unsigned int level, + Vector &u, + const Vector& rhs) const; +}; + + class MGTest : public MultiGridBase { + MGSmootherBase& smoother; + public: - MGTest(TransferTest& t) - : MultiGridBase(t, 9, 3, 2, 4) + MGTest(TransferTest& t, SmoothTest& s) + : MultiGridBase(t, 9, 3), + smoother(s) {} virtual void level_residual(unsigned level, @@ -32,20 +47,17 @@ class MGTest const Vector& src, const Vector& rhs); - virtual void smooth(unsigned level, - Vector& x, - const Vector& b, - unsigned steps); void doit() { - level_mgstep(9); + level_mgstep(9, smoother, smoother); } }; main() { TransferTest tr; - MGTest mg(tr); + SmoothTest s; + MGTest mg(tr, s); mg.doit(); } @@ -66,6 +78,14 @@ TransferTest::restrict(unsigned l, cout << "Restricting " << l << " to " << l-1 << endl; } +void +SmoothTest::smooth (const unsigned int level, + Vector &, + const Vector&) const +{ + cout << "Smoothing on" << level << endl; +} + void MGTest::level_residual(unsigned l, Vector&, @@ -74,12 +94,3 @@ MGTest::level_residual(unsigned l, { cout << "Residual on " << l << endl; } - -void -MGTest::smooth(unsigned l, - Vector&, - const Vector&, - unsigned steps) -{ - cout << "Smooth on " << l << " : " << steps << " steps" << endl; -}