]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
PreconditionMG
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 5 May 1999 11:29:39 +0000 (11:29 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 5 May 1999 11:29:39 +0000 (11:29 +0000)
git-svn-id: https://svn.dealii.org/trunk@1271 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/multigrid/mg_base.h
deal.II/deal.II/source/multigrid/mg_base.cc
deal.II/lac/include/lac/mgbase.h
deal.II/lac/source/mgbase.cc

index c30ef1930c08153207aa5d1fb825471f3f17a6dd..2a45a3a82662f9f4958fa1c78aa0e32f27f8403b 100644 (file)
@@ -10,6 +10,7 @@
 #include <lac/vector.h>
 
 #include <vector>
+#include <base/smartpointer.h>
 
 #define FLOAT float
 
  * grid solution in a derived class.
  */
 class MGCoarseGridSolver
+  :
+  public Subscriptor
 {
   public:
+                                    /**
+                                     * Virtual destructor.
+                                     */
+    virtual ~MGCoarseGridSolver();
+    
                                     /**
                                      * Coarse grid solving method.
                                      * This is only the interface for
@@ -98,7 +106,9 @@ class MGSmootherIdentity
  *
  * @author Wolfgang Bangerth, Guido Kanschat, 1999
  */
-class MGTransferBase  :  public Subscriptor
+class MGTransferBase
+  :
+  public Subscriptor
 {
   public:
                                     /**
@@ -274,6 +284,8 @@ class MGCoarseGridLACIteration
  * @author Guido Kanschat, 1999
  * */
 class MGBase
+  :
+  public Subscriptor
 {
   private:
     MGBase(const MGBase&);
@@ -368,6 +380,59 @@ class MGBase
 };
 
 
+
+/**
+ * Multi-level preconditioner.
+ * Here, we collect all information needed for multi-level preconditioning
+ * and provide the standard interface for LAC iterative methods.
+ *
+ * The template parameter class #MG# is required to inherit #MGBase#.
+ * Furthermore, it needs functions #void copy_to_mg(const VECTOR&)#
+ * to store #src# in the right hand side of the multi-level method and
+ * #void copy_from_mg(VECTOR&)# to store the result of the v-cycle in #dst#.
+ * @author Guido Kanschat, 1999
+ */
+template<class MG, class VECTOR>
+class PreconditionMG
+{
+  public:
+                                    /**
+                                     * Constructor.
+                                     * Arguments are the multigrid object,
+                                     * pre-smoother, post-smoother and
+                                     * coarse grid solver.
+                                     */
+    PreconditionMG(MG& mg,
+                  const MGSmootherBase& pre,
+                  const MGSmootherBase& post,
+                  const MGCoarseGridSolver& coarse);
+                                    /**
+                                     * Preconditioning operator.
+                                     * This is the operator used by LAC
+                                     * iterative solvers.
+                                     */
+    void operator() (VECTOR& dst, const VECTOR& src) const;
+  private:
+                                    /**
+                                     * The mulrigrid object.
+                                     */
+    SmartPointer<MG> multigrid;
+                                    /**
+                                     * The pre-smoothing object.
+                                     */
+    SmartPointer<const MGSmootherBase> pre;
+                                    /**
+                                     * The post-smoothing object.
+                                     */
+    SmartPointer<const MGSmootherBase> post;
+                                    /**
+                                     * The coarse grid solver.
+                                     */
+    SmartPointer<const MGCoarseGridSolver> coarse;
+};
+
+
+
 template<class SOLVER, class MATRIX, class PRECOND>
 MGCoarseGridLACIteration<SOLVER, MATRIX, PRECOND>
 ::MGCoarseGridLACIteration(SOLVER& s, const MATRIX& m, const PRECOND& p)
@@ -437,5 +502,28 @@ MGMatrix<MATRIX>::operator[](unsigned int i) const
   return vector<MATRIX>::operator[](i-minlevel);
 }
 
+//////////////////////////////////////////////////////////////////////
+
+template<class MG, class VECTOR>
+PreconditionMG<MG, VECTOR>::PreconditionMG(MG& mg,
+                              const MGSmootherBase& pre,
+                              const MGSmootherBase& post,
+                              const MGCoarseGridSolver& coarse)
+               :
+               multigrid(&mg),
+               pre(&pre),
+               post(&post),
+               coarse(&coarse)
+{}
+
+template<class MG, class VECTOR>
+void
+PreconditionMG<MG, VECTOR>::operator() (VECTOR& dst, const VECTOR& src) const
+{
+  multigrid->copy_to_mg(src);
+  multigrid->vcycle(*pre, *post, *coarse);
+  multigrid->copy_from_mg(dst);
+}
+
 
 #endif
index 73a80470fb19336e436d37da737be686f8918290..b7e475a798afa5ad3edd5443342b43ddb55ee9df 100644 (file)
@@ -79,6 +79,12 @@ MGBase::level_mgstep(unsigned level,
 }
 
 
+//////////////////////////////////////////////////////////////////////
+
+MGCoarseGridSolver::~MGCoarseGridSolver()
+{}
+
+
 //////////////////////////////////////////////////////////////////////
 
 MGTransferBase::~MGTransferBase()
index 54c15ce614ae563eca818dd2b2a92836309f0852..4192a16bd61863cb0fa4ec2ca7fa6eef5a369365 100644 (file)
@@ -10,6 +10,7 @@
 #include <lac/vector.h>
 
 #include <vector>
+#include <base/smartpointer.h>
 
 #define FLOAT float
 
  * grid solution in a derived class.
  */
 class MGCoarseGridSolver
+  :
+  public Subscriptor
 {
   public:
+                                    /**
+                                     * Virtual destructor.
+                                     */
+    virtual ~MGCoarseGridSolver();
+    
                                     /**
                                      * Coarse grid solving method.
                                      * This is only the interface for
@@ -98,7 +106,9 @@ class MGSmootherIdentity
  *
  * @author Wolfgang Bangerth, Guido Kanschat, 1999
  */
-class MGTransferBase  :  public Subscriptor
+class MGTransferBase
+  :
+  public Subscriptor
 {
   public:
                                     /**
@@ -274,6 +284,8 @@ class MGCoarseGridLACIteration
  * @author Guido Kanschat, 1999
  * */
 class MGBase
+  :
+  public Subscriptor
 {
   private:
     MGBase(const MGBase&);
@@ -368,6 +380,59 @@ class MGBase
 };
 
 
+
+/**
+ * Multi-level preconditioner.
+ * Here, we collect all information needed for multi-level preconditioning
+ * and provide the standard interface for LAC iterative methods.
+ *
+ * The template parameter class #MG# is required to inherit #MGBase#.
+ * Furthermore, it needs functions #void copy_to_mg(const VECTOR&)#
+ * to store #src# in the right hand side of the multi-level method and
+ * #void copy_from_mg(VECTOR&)# to store the result of the v-cycle in #dst#.
+ * @author Guido Kanschat, 1999
+ */
+template<class MG, class VECTOR>
+class PreconditionMG
+{
+  public:
+                                    /**
+                                     * Constructor.
+                                     * Arguments are the multigrid object,
+                                     * pre-smoother, post-smoother and
+                                     * coarse grid solver.
+                                     */
+    PreconditionMG(MG& mg,
+                  const MGSmootherBase& pre,
+                  const MGSmootherBase& post,
+                  const MGCoarseGridSolver& coarse);
+                                    /**
+                                     * Preconditioning operator.
+                                     * This is the operator used by LAC
+                                     * iterative solvers.
+                                     */
+    void operator() (VECTOR& dst, const VECTOR& src) const;
+  private:
+                                    /**
+                                     * The mulrigrid object.
+                                     */
+    SmartPointer<MG> multigrid;
+                                    /**
+                                     * The pre-smoothing object.
+                                     */
+    SmartPointer<const MGSmootherBase> pre;
+                                    /**
+                                     * The post-smoothing object.
+                                     */
+    SmartPointer<const MGSmootherBase> post;
+                                    /**
+                                     * The coarse grid solver.
+                                     */
+    SmartPointer<const MGCoarseGridSolver> coarse;
+};
+
+
+
 template<class SOLVER, class MATRIX, class PRECOND>
 MGCoarseGridLACIteration<SOLVER, MATRIX, PRECOND>
 ::MGCoarseGridLACIteration(SOLVER& s, const MATRIX& m, const PRECOND& p)
@@ -437,5 +502,28 @@ MGMatrix<MATRIX>::operator[](unsigned int i) const
   return vector<MATRIX>::operator[](i-minlevel);
 }
 
+//////////////////////////////////////////////////////////////////////
+
+template<class MG, class VECTOR>
+PreconditionMG<MG, VECTOR>::PreconditionMG(MG& mg,
+                              const MGSmootherBase& pre,
+                              const MGSmootherBase& post,
+                              const MGCoarseGridSolver& coarse)
+               :
+               multigrid(&mg),
+               pre(&pre),
+               post(&post),
+               coarse(&coarse)
+{}
+
+template<class MG, class VECTOR>
+void
+PreconditionMG<MG, VECTOR>::operator() (VECTOR& dst, const VECTOR& src) const
+{
+  multigrid->copy_to_mg(src);
+  multigrid->vcycle(*pre, *post, *coarse);
+  multigrid->copy_from_mg(dst);
+}
+
 
 #endif
index 73a80470fb19336e436d37da737be686f8918290..b7e475a798afa5ad3edd5443342b43ddb55ee9df 100644 (file)
@@ -79,6 +79,12 @@ MGBase::level_mgstep(unsigned level,
 }
 
 
+//////////////////////////////////////////////////////////////////////
+
+MGCoarseGridSolver::~MGCoarseGridSolver()
+{}
+
+
 //////////////////////////////////////////////////////////////////////
 
 MGTransferBase::~MGTransferBase()

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.