]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
multigrid compiles now... sorry!
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 22 Jan 1999 15:31:36 +0000 (15:31 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 22 Jan 1999 15:31:36 +0000 (15:31 +0000)
git-svn-id: https://svn.dealii.org/trunk@741 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 d3951e87d91e8afb2ce3e3373064e14dab8aed59..6a6524451730299c07f90538b363a0625e44a236 100644 (file)
@@ -4,6 +4,36 @@
 #define __multigrid_H
 /*----------------------------   multigrid.h     ---------------------------*/
 
+class dVector;
+
+/**
+ * Vector with data for each level.
+ */
+class MGVector
+{
+  MGVector(const MGVector&);
+public:
+                                  /**
+                                   * Constructor using the number of
+                                   * levels.
+                                   */
+  MGVector(unsigned l);
+                                  /**
+                                   * Access to data on a specific
+                                   level.
+                                  */
+  dVector& operator[](unsigned l);
+
+                                  /**
+                                   * Access to data on a specific
+                                   level.
+                                  */
+  const dVector& operator[](unsigned l) const;
+  
+};
+
+
+
 /**
  * Basic matrix class for multigrid preconditioning.
  *
  * classes...
  *
  */
-class MGMatrix
+class MultiGrid
 {
-  MGMatrix(const MGMatrix&);
-  operator=(const MGMatrix&);
+  MultiGrid(const MultiGrid&);
+  const MultiGrid& operator=(const MultiGrid&);
+
+                                  /** Auxiliary vectors.
+                                   */
+  mutable MGVector d,s;
+
+                                  /**
+                                   * Highest level of cells.
+                                   */
+  unsigned maxlevel;
+
+                                  /**
+                                   * Level for coarse grid solution.
+                                   */
+  unsigned minlevel;
+  
+                                  /** 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.
+                                   */
+  void copy_to_mg(MGVector& dst, const dVector& src) const;
+
+                                  /**
+                                   * Transfer from MGVector to
+                                   * dVector.
+                                   *
+                                   * Copies data from active portions
+                                   * of an MGVector into the
+                                   * respective positions of a
+                                   * dVector.
+                                   */
+  void copy_from_mg(dVector& dst, const MGVector& src) const;
+
+                                  /**
+                                   * The actual v-cycle multigrid method.
+                                   * This function is called on the
+                                   * highest level and recursively
+                                   * invokes itself down to the
+                                   * coarsest. There, it calls
+                                   * #coarse_grid_solution# and
+                                   * proceeds back up.
+                                   */
+  void level_mgstep(unsigned level) const;
+  
+protected:
+                                  /**
+                                   * Number of pre-smoothing steps.
+                                   */
+  unsigned n_presmooth;
+  
+                                  /**
+                                   * Number of post-smoothing steps
+                                   */
+  unsigned n_postsmooth;
+                                  /**
+                                   * The (pre-)smoothing algorithm.
+                                   */
+  virtual void smooth(unsigned level,
+                     dVector& dst,
+                     const dVector& src) const;
+
+                                  /**
+                                   * The post-smoothing algorithm.
+                                   * Defaults to #smooth#.
+                                   */
+  virtual void post_smooth(unsigned level,
+                     dVector& dst,
+                     const dVector& src) const;
+
+                                  /**
+                                   * Apply operator on non-refined
+                                   * cells.
+                                   */
+  virtual void level_active_vmult(unsigned level,
+                                 dVector& dst,
+                                 const dVector& src) const;
+
+                                  /**
+                                   * Solve exactly on coarsest grid.
+                                   */
+  virtual void coarse_grid_solution(unsigned l,
+                                   dVector& dst,
+                                   const dVector& src) const;
+  
+
+  
+
+  
 public:
+                                  /**
+                                   * Constructor, subject to change.
+                                   */
+  MultiGrid();
+
                                   /** Matrix-vector multiplication.
                                    *
                                    * The global, non-multigrid
index d3951e87d91e8afb2ce3e3373064e14dab8aed59..6a6524451730299c07f90538b363a0625e44a236 100644 (file)
@@ -4,6 +4,36 @@
 #define __multigrid_H
 /*----------------------------   multigrid.h     ---------------------------*/
 
+class dVector;
+
+/**
+ * Vector with data for each level.
+ */
+class MGVector
+{
+  MGVector(const MGVector&);
+public:
+                                  /**
+                                   * Constructor using the number of
+                                   * levels.
+                                   */
+  MGVector(unsigned l);
+                                  /**
+                                   * Access to data on a specific
+                                   level.
+                                  */
+  dVector& operator[](unsigned l);
+
+                                  /**
+                                   * Access to data on a specific
+                                   level.
+                                  */
+  const dVector& operator[](unsigned l) const;
+  
+};
+
+
+
 /**
  * Basic matrix class for multigrid preconditioning.
  *
  * classes...
  *
  */
-class MGMatrix
+class MultiGrid
 {
-  MGMatrix(const MGMatrix&);
-  operator=(const MGMatrix&);
+  MultiGrid(const MultiGrid&);
+  const MultiGrid& operator=(const MultiGrid&);
+
+                                  /** Auxiliary vectors.
+                                   */
+  mutable MGVector d,s;
+
+                                  /**
+                                   * Highest level of cells.
+                                   */
+  unsigned maxlevel;
+
+                                  /**
+                                   * Level for coarse grid solution.
+                                   */
+  unsigned minlevel;
+  
+                                  /** 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.
+                                   */
+  void copy_to_mg(MGVector& dst, const dVector& src) const;
+
+                                  /**
+                                   * Transfer from MGVector to
+                                   * dVector.
+                                   *
+                                   * Copies data from active portions
+                                   * of an MGVector into the
+                                   * respective positions of a
+                                   * dVector.
+                                   */
+  void copy_from_mg(dVector& dst, const MGVector& src) const;
+
+                                  /**
+                                   * The actual v-cycle multigrid method.
+                                   * This function is called on the
+                                   * highest level and recursively
+                                   * invokes itself down to the
+                                   * coarsest. There, it calls
+                                   * #coarse_grid_solution# and
+                                   * proceeds back up.
+                                   */
+  void level_mgstep(unsigned level) const;
+  
+protected:
+                                  /**
+                                   * Number of pre-smoothing steps.
+                                   */
+  unsigned n_presmooth;
+  
+                                  /**
+                                   * Number of post-smoothing steps
+                                   */
+  unsigned n_postsmooth;
+                                  /**
+                                   * The (pre-)smoothing algorithm.
+                                   */
+  virtual void smooth(unsigned level,
+                     dVector& dst,
+                     const dVector& src) const;
+
+                                  /**
+                                   * The post-smoothing algorithm.
+                                   * Defaults to #smooth#.
+                                   */
+  virtual void post_smooth(unsigned level,
+                     dVector& dst,
+                     const dVector& src) const;
+
+                                  /**
+                                   * Apply operator on non-refined
+                                   * cells.
+                                   */
+  virtual void level_active_vmult(unsigned level,
+                                 dVector& dst,
+                                 const dVector& src) const;
+
+                                  /**
+                                   * Solve exactly on coarsest grid.
+                                   */
+  virtual void coarse_grid_solution(unsigned l,
+                                   dVector& dst,
+                                   const dVector& src) const;
+  
+
+  
+
+  
 public:
+                                  /**
+                                   * Constructor, subject to change.
+                                   */
+  MultiGrid();
+
                                   /** Matrix-vector multiplication.
                                    *
                                    * The global, non-multigrid
index 08646d86be753404cedec9c58674c173dc2bcede..1a58b75b5c38ba4608397f8092e8a34a085d16a4 100644 (file)
@@ -2,37 +2,43 @@
 // Copyright Guido Kanschat, Universitaet Heidelberg, 1999
 
 #include <numerics/multigrid.h>
+#include <lac/dvector.h>
 
 void
-MGMatrix::vmult(dVector& dst, const dVector& src) const
+MultiGrid::vmult(dVector& dst, const dVector& src) const
 {
   dst = 0.;
   
   copy_to_mg(s,src);
   
-  for (int l=0;l<maxlevel;++l)
+  for (unsigned l=0;l<maxlevel;++l)
   {
-    level_active_vmult(l,d,s);
+    level_active_vmult(l,d[l],s[l]);
   }
   copy_from_mg(dst,d);
 }
 
 
 void
-MGMatrix::precondition(dVector& dst, const dVector& src) const
+MultiGrid::precondition(dVector& dst, const dVector& src) const
 {
   copy_to_mg(s,src);
-  d = 0.;
-  
-    
+  copy_to_mg(d,dst);
+  level_mgstep(maxlevel);
 }
 
 void
-MGMatrix::level_mgstep(int level)
+MultiGrid::level_mgstep(unsigned level) const
 {
-  for (int i=0; i< n_presmooth; ++i)
+  if (level == minlevel)
+  {
+    coarse_grid_solution(level, d[level], s[level]);
+    return;
+  }
+  
+  for (unsigned i=0; i< n_presmooth; ++i)
   {
-    smooth(level, d, s);
+    smooth(level, d[level], s[level]);
   }
 }
 
index 08646d86be753404cedec9c58674c173dc2bcede..1a58b75b5c38ba4608397f8092e8a34a085d16a4 100644 (file)
@@ -2,37 +2,43 @@
 // Copyright Guido Kanschat, Universitaet Heidelberg, 1999
 
 #include <numerics/multigrid.h>
+#include <lac/dvector.h>
 
 void
-MGMatrix::vmult(dVector& dst, const dVector& src) const
+MultiGrid::vmult(dVector& dst, const dVector& src) const
 {
   dst = 0.;
   
   copy_to_mg(s,src);
   
-  for (int l=0;l<maxlevel;++l)
+  for (unsigned l=0;l<maxlevel;++l)
   {
-    level_active_vmult(l,d,s);
+    level_active_vmult(l,d[l],s[l]);
   }
   copy_from_mg(dst,d);
 }
 
 
 void
-MGMatrix::precondition(dVector& dst, const dVector& src) const
+MultiGrid::precondition(dVector& dst, const dVector& src) const
 {
   copy_to_mg(s,src);
-  d = 0.;
-  
-    
+  copy_to_mg(d,dst);
+  level_mgstep(maxlevel);
 }
 
 void
-MGMatrix::level_mgstep(int level)
+MultiGrid::level_mgstep(unsigned level) const
 {
-  for (int i=0; i< n_presmooth; ++i)
+  if (level == minlevel)
+  {
+    coarse_grid_solution(level, d[level], s[level]);
+    return;
+  }
+  
+  for (unsigned i=0; i< n_presmooth; ++i)
   {
-    smooth(level, d, s);
+    smooth(level, d[level], s[level]);
   }
 }
 

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.