]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
more multigrid
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 9 Apr 1999 15:23:18 +0000 (15:23 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 9 Apr 1999 15:23:18 +0000 (15:23 +0000)
git-svn-id: https://svn.dealii.org/trunk@1117 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/multigrid/multigrid.h
deal.II/deal.II/include/numerics/multigrid.h
deal.II/deal.II/source/multigrid/multigrid.cc
deal.II/deal.II/source/numerics/multigrid.cc

index 7d60d21d34d548d5e498e611d0b574d9bf73e5ee..81a59959b7297e45d5e713739eda79c5ef127137 100644 (file)
@@ -4,7 +4,7 @@
 #define __multigrid_H
 /*----------------------------   multigrid.h     ---------------------------*/
 
-#include <base/subscriptor.h>
+#include <base/smartpointer.h>
 #include <lac/forward-declarations.h>
 #include <basic/forward-declarations.h>
 #include <lac/sparsematrix.h>
@@ -12,7 +12,7 @@
 
 #include <vector>
 class MGTransferBase;
-
+class MGSmoother;
 
 
 /**
@@ -72,30 +72,19 @@ class MultiGridBase
                                      * Prolongation and restriction object.
                                      */
     SmartPointer<MGTransferBase> transfer;
-
-                                    /** 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.
+    
+  protected:
+                                    /**
+                                     * Number of pre-smoothing steps. Is used
+                                     * as a parameter to #pre_smooth#.
                                      */
-    void copy_to_mg(vector<Vector<float> >& dst, const Vector<double>& src);
-
+    unsigned n_pre_smooth;
+  
                                     /**
-                                     * Transfer from MGVector to
-                                     * Vector<double>.
-                                     *
-                                     * Copies data from active portions
-                                     * of an MGVector into the
-                                     * respective positions of a
-                                     * Vector<double>. All other entries of
-                                     * #src# are zero.
+                                     * Number of post-smoothing steps Is used
+                                     * as a parameter to #post_smooth#.
                                      */
-    void copy_from_mg(Vector<double>& dst, const vector<Vector<float> >& src);
-
+    unsigned n_post_smooth;
                                     /**
                                      * The actual v-cycle multigrid method.
                                      * This function is called on the
@@ -105,44 +94,7 @@ class MultiGridBase
                                      * #coarse_grid_solution# and
                                      * proceeds back up.
                                      */
-    void level_mgstep(unsigned level);
-  
-  protected:
-                                    /**
-                                     * Number of pre-smoothing steps.
-                                     */
-    unsigned n_pre_smooth;
-  
-                                    /**
-                                     * Number of post-smoothing steps
-                                     */
-    unsigned n_post_smooth;
-                                    /**
-                                     * The (pre-)smoothing algorithm.
-                                     * This function is required to
-                                     * perform #steps# iterations to
-                                     * smoothen the residual $Ax-b$.
-                                     *
-                                     * When overloading this function
-                                     * in derived classes, make sure
-                                     * that smoothing only applies to
-                                     * interior degrees of freedom of
-                                     * the actual level.
-                                     *
-                                     */
-    virtual void smooth(unsigned level,
-                       Vector<float>& x,
-                       const Vector<float>& b,
-                       unsigned steps) = 0;
-
-                                    /**
-                                     * The post-smoothing algorithm.
-                                     * Defaults to #smooth#.
-                                     */
-    virtual void post_smooth(unsigned level,
-                            Vector<float>& dst,
-                            const Vector<float>& src,
-                            unsigned steps);
+    void level_mgstep(unsigned level, MGSmoother& smoother);  
 
                                     /**
                                      * Apply residual operator on all
@@ -164,7 +116,7 @@ class MultiGridBase
                                      * standard implementation doing
                                      * #10 * (n_pre_smooth +
                                      * n_post_smooth)#
-                                     * smoothing steps.
+                                     * smoothing steps of #pre_smooth#.
                                      */
     virtual void coarse_grid_solution(unsigned l,
                                      Vector<float>& dst,
@@ -238,6 +190,68 @@ class MGTransferBase  :  public Subscriptor
                           const Vector<float> &src) const = 0;
 };
 
+/**
+ * Implementation of multigrid with matrices.
+ * While #MultiGridBase# was only an abstract framework for the v-cycle,
+ * here we have the implementation of the pure virtual functions defined there.
+ * Furthermore, level information is obtained from a triangulation object.
+ * 
+ * @author Wolfgang Bangerth, Guido Kanschat, 1999
+ */
+template<int dim, class Matrix>
+class MultiGrid
+{
+  public:
+    MultiGrid(const MGDoFHandler<dim>&);
+    
+                                    /** Transfer 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.
+                                     */
+    template<typename number>
+    void copy_to_mg(vector<Vector<float> >& dst,
+                   const Vector<number>& src) const;
+
+                                    /**
+                                     * Transfer from multi-grid vector to
+                                     * normal vector.
+                                     *
+                                     * Copies data from active portions
+                                     * of an MGVector into the
+                                     * respective positions of a
+                                     * Vector<double>. All other entries of
+                                     * #src# are zero.
+                                     */
+    template<typename number>
+    void copy_from_mg(Vector<number>& dst,
+                     const vector<Vector<float> >& src) const;
+  private:
+                                    /**
+                                     * Associated #MGDoFHandler#.
+                                     */
+    SmartPointer<MGDoFHandler<dim> > dofs;
+
+                                    /**
+                                     * Matrix structures for each level.
+                                     * These are generated by the constructor
+                                     * of #MultiGrid# and can be accessed
+                                     * later.
+                                     */
+    vector<SparseMatrixStruct> matrix_structures;
+
+                                    /**
+                                     * Matrices for each level.
+                                     * The matrices are prepared by
+                                     * the constructor of #MultiGrid# and can
+                                     * be accessed for assembling.
+                                     */
+    vector<SparseMatrix<float> > matrices;
+};
 
 
 /**
index 7d60d21d34d548d5e498e611d0b574d9bf73e5ee..81a59959b7297e45d5e713739eda79c5ef127137 100644 (file)
@@ -4,7 +4,7 @@
 #define __multigrid_H
 /*----------------------------   multigrid.h     ---------------------------*/
 
-#include <base/subscriptor.h>
+#include <base/smartpointer.h>
 #include <lac/forward-declarations.h>
 #include <basic/forward-declarations.h>
 #include <lac/sparsematrix.h>
@@ -12,7 +12,7 @@
 
 #include <vector>
 class MGTransferBase;
-
+class MGSmoother;
 
 
 /**
@@ -72,30 +72,19 @@ class MultiGridBase
                                      * Prolongation and restriction object.
                                      */
     SmartPointer<MGTransferBase> transfer;
-
-                                    /** 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.
+    
+  protected:
+                                    /**
+                                     * Number of pre-smoothing steps. Is used
+                                     * as a parameter to #pre_smooth#.
                                      */
-    void copy_to_mg(vector<Vector<float> >& dst, const Vector<double>& src);
-
+    unsigned n_pre_smooth;
+  
                                     /**
-                                     * Transfer from MGVector to
-                                     * Vector<double>.
-                                     *
-                                     * Copies data from active portions
-                                     * of an MGVector into the
-                                     * respective positions of a
-                                     * Vector<double>. All other entries of
-                                     * #src# are zero.
+                                     * Number of post-smoothing steps Is used
+                                     * as a parameter to #post_smooth#.
                                      */
-    void copy_from_mg(Vector<double>& dst, const vector<Vector<float> >& src);
-
+    unsigned n_post_smooth;
                                     /**
                                      * The actual v-cycle multigrid method.
                                      * This function is called on the
@@ -105,44 +94,7 @@ class MultiGridBase
                                      * #coarse_grid_solution# and
                                      * proceeds back up.
                                      */
-    void level_mgstep(unsigned level);
-  
-  protected:
-                                    /**
-                                     * Number of pre-smoothing steps.
-                                     */
-    unsigned n_pre_smooth;
-  
-                                    /**
-                                     * Number of post-smoothing steps
-                                     */
-    unsigned n_post_smooth;
-                                    /**
-                                     * The (pre-)smoothing algorithm.
-                                     * This function is required to
-                                     * perform #steps# iterations to
-                                     * smoothen the residual $Ax-b$.
-                                     *
-                                     * When overloading this function
-                                     * in derived classes, make sure
-                                     * that smoothing only applies to
-                                     * interior degrees of freedom of
-                                     * the actual level.
-                                     *
-                                     */
-    virtual void smooth(unsigned level,
-                       Vector<float>& x,
-                       const Vector<float>& b,
-                       unsigned steps) = 0;
-
-                                    /**
-                                     * The post-smoothing algorithm.
-                                     * Defaults to #smooth#.
-                                     */
-    virtual void post_smooth(unsigned level,
-                            Vector<float>& dst,
-                            const Vector<float>& src,
-                            unsigned steps);
+    void level_mgstep(unsigned level, MGSmoother& smoother);  
 
                                     /**
                                      * Apply residual operator on all
@@ -164,7 +116,7 @@ class MultiGridBase
                                      * standard implementation doing
                                      * #10 * (n_pre_smooth +
                                      * n_post_smooth)#
-                                     * smoothing steps.
+                                     * smoothing steps of #pre_smooth#.
                                      */
     virtual void coarse_grid_solution(unsigned l,
                                      Vector<float>& dst,
@@ -238,6 +190,68 @@ class MGTransferBase  :  public Subscriptor
                           const Vector<float> &src) const = 0;
 };
 
+/**
+ * Implementation of multigrid with matrices.
+ * While #MultiGridBase# was only an abstract framework for the v-cycle,
+ * here we have the implementation of the pure virtual functions defined there.
+ * Furthermore, level information is obtained from a triangulation object.
+ * 
+ * @author Wolfgang Bangerth, Guido Kanschat, 1999
+ */
+template<int dim, class Matrix>
+class MultiGrid
+{
+  public:
+    MultiGrid(const MGDoFHandler<dim>&);
+    
+                                    /** Transfer 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.
+                                     */
+    template<typename number>
+    void copy_to_mg(vector<Vector<float> >& dst,
+                   const Vector<number>& src) const;
+
+                                    /**
+                                     * Transfer from multi-grid vector to
+                                     * normal vector.
+                                     *
+                                     * Copies data from active portions
+                                     * of an MGVector into the
+                                     * respective positions of a
+                                     * Vector<double>. All other entries of
+                                     * #src# are zero.
+                                     */
+    template<typename number>
+    void copy_from_mg(Vector<number>& dst,
+                     const vector<Vector<float> >& src) const;
+  private:
+                                    /**
+                                     * Associated #MGDoFHandler#.
+                                     */
+    SmartPointer<MGDoFHandler<dim> > dofs;
+
+                                    /**
+                                     * Matrix structures for each level.
+                                     * These are generated by the constructor
+                                     * of #MultiGrid# and can be accessed
+                                     * later.
+                                     */
+    vector<SparseMatrixStruct> matrix_structures;
+
+                                    /**
+                                     * Matrices for each level.
+                                     * The matrices are prepared by
+                                     * the constructor of #MultiGrid# and can
+                                     * be accessed for assembling.
+                                     */
+    vector<SparseMatrix<float> > matrices;
+};
 
 
 /**
index 835d134a7a29456398147a4cb080b1e7e4c4dbd4..f17272409f31c893473d0950384381aafa06ab79 100644 (file)
@@ -19,14 +19,15 @@ MultiGridBase::MultiGridBase(MGTransferBase& transfer,
                             unsigned maxlevel, unsigned minlevel,
                             unsigned pre_smooth, unsigned post_smooth)
                :
+               d(maxlevel-minlevel),
+               s(maxlevel-minlevel),
                maxlevel(maxlevel), minlevel(minlevel),
                transfer(&transfer),
                n_pre_smooth(pre_smooth), n_post_smooth(post_smooth)
 {}
 
-
 void
-MultiGridBase::level_mgstep(unsigned level)
+MultiGridBase::level_mgstep(unsigned level, MGSmoother& smoother)
 {
   if (level == minlevel)
     {
@@ -35,7 +36,7 @@ MultiGridBase::level_mgstep(unsigned level)
     }
   
                                   // smoothing of the residual by modifying s
-  smooth(level, d[level], s[level], n_pre_smooth);
+//  smooth(level, d[level], s[level], n_pre_smooth);
 
                                   // t = d-As
   level_residual(level, t, s[level], d[level]);
@@ -43,31 +44,21 @@ MultiGridBase::level_mgstep(unsigned level)
                                   // make t rhs of lower level
   transfer->restrict(level, t, d[level-1]);
                                   // do recursion
-  level_mgstep(level-1);
+  level_mgstep(level-1, smoother);
                                   // 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(level, d[level], s[level], n_post_smooth);
 }
 
 
 void
-MultiGridBase::post_smooth(unsigned level,
-                          Vector<float>& dst, const Vector<float>& src,
-                          unsigned steps)
-{
-  smooth(level, dst, src, steps);
-}
-
-
-
-void
-MultiGridBase::coarse_grid_solution(unsigned level,
-                         Vector<float>& dst,
-                         const Vector<float>& src)
+MultiGridBase::coarse_grid_solution(unsigned /*level*/,
+                                   Vector<float>& /*dst*/,
+                                   const Vector<float>& /*src*/)
 {
-  smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth));
+//  smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth));
 }
 
 
index 835d134a7a29456398147a4cb080b1e7e4c4dbd4..f17272409f31c893473d0950384381aafa06ab79 100644 (file)
@@ -19,14 +19,15 @@ MultiGridBase::MultiGridBase(MGTransferBase& transfer,
                             unsigned maxlevel, unsigned minlevel,
                             unsigned pre_smooth, unsigned post_smooth)
                :
+               d(maxlevel-minlevel),
+               s(maxlevel-minlevel),
                maxlevel(maxlevel), minlevel(minlevel),
                transfer(&transfer),
                n_pre_smooth(pre_smooth), n_post_smooth(post_smooth)
 {}
 
-
 void
-MultiGridBase::level_mgstep(unsigned level)
+MultiGridBase::level_mgstep(unsigned level, MGSmoother& smoother)
 {
   if (level == minlevel)
     {
@@ -35,7 +36,7 @@ MultiGridBase::level_mgstep(unsigned level)
     }
   
                                   // smoothing of the residual by modifying s
-  smooth(level, d[level], s[level], n_pre_smooth);
+//  smooth(level, d[level], s[level], n_pre_smooth);
 
                                   // t = d-As
   level_residual(level, t, s[level], d[level]);
@@ -43,31 +44,21 @@ MultiGridBase::level_mgstep(unsigned level)
                                   // make t rhs of lower level
   transfer->restrict(level, t, d[level-1]);
                                   // do recursion
-  level_mgstep(level-1);
+  level_mgstep(level-1, smoother);
                                   // 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(level, d[level], s[level], n_post_smooth);
 }
 
 
 void
-MultiGridBase::post_smooth(unsigned level,
-                          Vector<float>& dst, const Vector<float>& src,
-                          unsigned steps)
-{
-  smooth(level, dst, src, steps);
-}
-
-
-
-void
-MultiGridBase::coarse_grid_solution(unsigned level,
-                         Vector<float>& dst,
-                         const Vector<float>& src)
+MultiGridBase::coarse_grid_solution(unsigned /*level*/,
+                                   Vector<float>& /*dst*/,
+                                   const Vector<float>& /*src*/)
 {
-  smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth));
+//  smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth));
 }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.