]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
mg:level_step
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Apr 1999 15:15:13 +0000 (15:15 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Apr 1999 15:15:13 +0000 (15:15 +0000)
git-svn-id: https://svn.dealii.org/trunk@1096 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 b7811b0fe78be0993e627b6909b9be5e55ea926a..4c00b24dc26e86c35b1513ca80b627c071a3e231 100644 (file)
@@ -5,8 +5,12 @@
 /*----------------------------   multigrid.h     ---------------------------*/
 
 #include <vector>
-#include <base/subscriptor.h>
+#include <base/smartpointer.h>
 #include <lac/forward-declarations.h>
+#include <lac/vector.h>
+
+class MGTransferBase;
+
 
 /**
  * Basic matrix class for multigrid preconditioning.
@@ -36,10 +40,20 @@ class MultiGridBase
     MultiGridBase(const MultiGridBase&);
     const MultiGridBase& operator=(const MultiGridBase&);
     
-                                    /** Auxiliary vectors.
+                                    /**
+                                     * Auxiliary vector.
                                      */
     vector<Vector<float> > d;
+
+                                    /**
+                                     * Auxiliary vector.
+                                     */
     vector<Vector<float> > s;
+
+                                    /**
+                                     * Auxiliary vector.
+                                     */
+    Vector<float> t;
     
                                     /**
                                      * Highest level of cells.
@@ -50,7 +64,12 @@ class MultiGridBase
                                      * Level for coarse grid solution.
                                      */
     unsigned minlevel;
-  
+
+                                    /**
+                                     * Prolongation and restriction object.
+                                     */
+    SmartPointer<MGTransferBase> transfer;
+
                                     /** Tranfer from dVector to
                                      * MGVector.
                                      *
@@ -111,7 +130,7 @@ class MultiGridBase
     virtual void smooth(unsigned level,
                        Vector<float>& x,
                        const Vector<float>& b,
-                       unsigned steps);
+                       unsigned steps) = 0;
 
                                     /**
                                      * The post-smoothing algorithm.
@@ -123,16 +142,26 @@ class MultiGridBase
                             unsigned steps);
 
                                     /**
-                                     * Apply operator on all
+                                     * Apply residual operator on all
                                      * cells of a level.
-                                     *
+                                     * This is implemented in a
+                                     * derived class.
                                      */
-    virtual void level_vmult(unsigned level,
+    virtual void level_residual(unsigned level,
                             Vector<float>& dst,
-                            const Vector<float>& src);
+                            const Vector<float>& src,
+                            const Vector<float>& rhs) = 0;
 
                                     /**
                                      * Solve exactly on coarsest grid.
+                                     * Usually, this function should
+                                     * be overloaded by a more
+                                     * sophisticated derived
+                                     * class. Still, there is a
+                                     * standard implementation doing
+                                     * #10 * (n_pre_smooth +
+                                     * n_post_smooth)#
+                                     * smoothing steps.
                                      */
     virtual void coarse_grid_solution(unsigned l,
                                      Vector<float>& dst,
@@ -146,7 +175,9 @@ class MultiGridBase
                                     /**
                                      * Constructor, subject to change.
                                      */
-    MultiGridBase();
+    MultiGridBase(MGTransferBase& transfer,
+                 unsigned maxlevel, unsigned minlevel,
+                 unsigned pre_smooth, unsigned post_smooth);
     virtual ~MultiGridBase();
     
 };
index b7811b0fe78be0993e627b6909b9be5e55ea926a..4c00b24dc26e86c35b1513ca80b627c071a3e231 100644 (file)
@@ -5,8 +5,12 @@
 /*----------------------------   multigrid.h     ---------------------------*/
 
 #include <vector>
-#include <base/subscriptor.h>
+#include <base/smartpointer.h>
 #include <lac/forward-declarations.h>
+#include <lac/vector.h>
+
+class MGTransferBase;
+
 
 /**
  * Basic matrix class for multigrid preconditioning.
@@ -36,10 +40,20 @@ class MultiGridBase
     MultiGridBase(const MultiGridBase&);
     const MultiGridBase& operator=(const MultiGridBase&);
     
-                                    /** Auxiliary vectors.
+                                    /**
+                                     * Auxiliary vector.
                                      */
     vector<Vector<float> > d;
+
+                                    /**
+                                     * Auxiliary vector.
+                                     */
     vector<Vector<float> > s;
+
+                                    /**
+                                     * Auxiliary vector.
+                                     */
+    Vector<float> t;
     
                                     /**
                                      * Highest level of cells.
@@ -50,7 +64,12 @@ class MultiGridBase
                                      * Level for coarse grid solution.
                                      */
     unsigned minlevel;
-  
+
+                                    /**
+                                     * Prolongation and restriction object.
+                                     */
+    SmartPointer<MGTransferBase> transfer;
+
                                     /** Tranfer from dVector to
                                      * MGVector.
                                      *
@@ -111,7 +130,7 @@ class MultiGridBase
     virtual void smooth(unsigned level,
                        Vector<float>& x,
                        const Vector<float>& b,
-                       unsigned steps);
+                       unsigned steps) = 0;
 
                                     /**
                                      * The post-smoothing algorithm.
@@ -123,16 +142,26 @@ class MultiGridBase
                             unsigned steps);
 
                                     /**
-                                     * Apply operator on all
+                                     * Apply residual operator on all
                                      * cells of a level.
-                                     *
+                                     * This is implemented in a
+                                     * derived class.
                                      */
-    virtual void level_vmult(unsigned level,
+    virtual void level_residual(unsigned level,
                             Vector<float>& dst,
-                            const Vector<float>& src);
+                            const Vector<float>& src,
+                            const Vector<float>& rhs) = 0;
 
                                     /**
                                      * Solve exactly on coarsest grid.
+                                     * Usually, this function should
+                                     * be overloaded by a more
+                                     * sophisticated derived
+                                     * class. Still, there is a
+                                     * standard implementation doing
+                                     * #10 * (n_pre_smooth +
+                                     * n_post_smooth)#
+                                     * smoothing steps.
                                      */
     virtual void coarse_grid_solution(unsigned l,
                                      Vector<float>& dst,
@@ -146,7 +175,9 @@ class MultiGridBase
                                     /**
                                      * Constructor, subject to change.
                                      */
-    MultiGridBase();
+    MultiGridBase(MGTransferBase& transfer,
+                 unsigned maxlevel, unsigned minlevel,
+                 unsigned pre_smooth, unsigned post_smooth);
     virtual ~MultiGridBase();
     
 };
index 55f840c6672fc4963b8389ec7eeb340a28daadda..c0fa498bf354b276db548886fe1cc2824dd0b0cd 100644 (file)
@@ -4,6 +4,15 @@
 #include <numerics/multigrid.h>
 #include <lac/vector.h>
 
+MultiGridBase::MultiGridBase(MGTransferBase& transfer,
+                            unsigned maxlevel, unsigned minlevel,
+                            unsigned pre_smooth, unsigned post_smooth)
+               :
+               maxlevel(maxlevel), minlevel(minlevel),
+               transfer(&transfer),
+               n_pre_smooth(pre_smooth), n_post_smooth(post_smooth)
+{}
+
 void
 MultiGridBase::level_mgstep(unsigned level)
 {
@@ -13,18 +22,39 @@ MultiGridBase::level_mgstep(unsigned level)
       return;
     }
   
+                                  // smoothing of the residual by modifying s
   smooth(level, d[level], s[level], n_pre_smooth);
 
+                                  // t = d-As
+  level_residual(level, t, s[level], d[level]);
+  
+                                  // make t rhs of lower level
+  transfer->restrict(level, t, d[level-1]);
+                                  // do recursion
+  level_mgstep(level-1);
+                                  // 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);
 }
 
 
-void MultiGridBase::post_smooth(unsigned level,
-                               Vector<float>& dst, const Vector<float>& src,
-                               unsigned steps)
+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)
+{
+  smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth));
+}
+
 // ab hier Wolfgang
 
index 55f840c6672fc4963b8389ec7eeb340a28daadda..c0fa498bf354b276db548886fe1cc2824dd0b0cd 100644 (file)
@@ -4,6 +4,15 @@
 #include <numerics/multigrid.h>
 #include <lac/vector.h>
 
+MultiGridBase::MultiGridBase(MGTransferBase& transfer,
+                            unsigned maxlevel, unsigned minlevel,
+                            unsigned pre_smooth, unsigned post_smooth)
+               :
+               maxlevel(maxlevel), minlevel(minlevel),
+               transfer(&transfer),
+               n_pre_smooth(pre_smooth), n_post_smooth(post_smooth)
+{}
+
 void
 MultiGridBase::level_mgstep(unsigned level)
 {
@@ -13,18 +22,39 @@ MultiGridBase::level_mgstep(unsigned level)
       return;
     }
   
+                                  // smoothing of the residual by modifying s
   smooth(level, d[level], s[level], n_pre_smooth);
 
+                                  // t = d-As
+  level_residual(level, t, s[level], d[level]);
+  
+                                  // make t rhs of lower level
+  transfer->restrict(level, t, d[level-1]);
+                                  // do recursion
+  level_mgstep(level-1);
+                                  // 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);
 }
 
 
-void MultiGridBase::post_smooth(unsigned level,
-                               Vector<float>& dst, const Vector<float>& src,
-                               unsigned steps)
+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)
+{
+  smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth));
+}
+
 // ab hier Wolfgang
 

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.