]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add solvers and improve existing ones.
authorturcksin <turcksin@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 5 Jun 2014 23:22:42 +0000 (23:22 +0000)
committerturcksin <turcksin@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 5 Jun 2014 23:22:42 +0000 (23:22 +0000)
git-svn-id: https://svn.dealii.org/branches/branch_paralution@33024 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/paralution_solver.h
deal.II/source/lac/paralution_solver.cc

index 03ff4a06b2a5cb14818799292173fba6306f8509..ca3ba6df2a482bbe2cb6ab24753abeb8b0975b17 100644 (file)
@@ -78,6 +78,68 @@ namespace ParalutionWrappers
 
 
 
+  /**
+   * An implementation of the solver interface using the Paralution Richardson solver
+   * (paralution::fixed_point_iteration).
+   *
+   * @ingroup ParalutionWrappers
+   * @author Bruno Turcksin, 2014
+   */
+  class SolverRichardson : public SolverBase
+  {
+  public:
+    /**
+     * Standardized data struct to pipe additional data to the solver.
+     */
+    struct AdditionalData
+    {
+      /**
+       * Constructor. By default, set the verbosity of the solver to zero and
+       * the relaxation parameter to one.
+       */
+      AdditionalData (const unsigned int verbose = 0,
+                      const double relaxation_parameter = 1.);
+
+      /**
+       * Verbosity of the solver: 0 =  no output, 1 = print information at the
+       * start and at the end, 3 = print residual at each iteration.
+       */
+      unsigned int verbose;
+
+      /**
+       * Relaxation parameter.
+       */
+      double relaxation_parameter;
+    };
+
+    /**
+     * Constructor. AdditionalData is a structure that contains additional
+     * flags for tuning this particular solver.
+     */
+    SolverRichardson (SolverControl        &cn,
+                      const AdditionalData &data = AdditionalData());
+
+    /**
+     * Solve the linear system <tt>Ax=b</tt> using the CG solver of
+     * Paralution. If the flag @p move_to_accelerator is set to true, the
+     * solver is built on the accelerator.
+     */
+    template <typename Number>
+    void solve (const SparseMatrix<Number>     &A,
+                Vector<Number>                 &x,
+                const Vector<Number>           &b,
+                const PreconditionBase<Number> &preconditioner,
+                bool                            move_to_accelerator=false);
+
+  private:
+    /**
+     * store a copy of the flags for this solver.
+     */
+    const AdditionalData additional_data;
+  };
+
+
+
   /**
    * An implementation of the solver interface using the Paralution CG solver.
    *
@@ -88,9 +150,33 @@ namespace ParalutionWrappers
   {
   public:
     /**
-     * Constructor.
+     * Standardized data struct to pipe additional data to the solver.
+     */
+    struct AdditionalData
+    {
+      /**
+       * Constructor. By default, set the verbosity of the solver to zero.
+       */
+      AdditionalData (const unsigned int verbose = 0);
+
+      /**
+       * Verbosity of the solver: 0 =  no output, 1 = print information at the
+       * start and at the end, 3 = print residual at each iteration.
+       */
+      unsigned int verbose;
+
+      /**
+       * Relaxation parameter.
+       */
+      double relaxation_parameter;
+    };
+
+    /**
+     * Constructor. AdditionalData is a structure that contains additional
+     * flags for tuning this particular solver.
      */
-    SolverCG (SolverControl &cn);
+    SolverCG (SolverControl        &cn,
+              const AdditionalData &data = AdditionalData());
 
     /**
      * Solve the linear system <tt>Ax=b</tt> using the CG solver of
@@ -103,6 +189,131 @@ namespace ParalutionWrappers
                 const Vector<Number>           &b,
                 const PreconditionBase<Number> &preconditioner,
                 bool                            move_to_accelerator=false);
+
+  private:
+    /**
+     * store a copy of the flags for this solver.
+     */
+    const AdditionalData additional_data;
+  };
+
+
+
+  /**
+   * An implementation of the solver interface using the Paralution CR solver.
+   *
+   * @ingroup ParalutionWrappers
+   * @author Bruno Turcksin, 2014
+   */
+  class SolverCR : public SolverBase
+  {
+  public:
+    /**
+     * Standardized data struct to pipe additional data to the solver.
+     */
+    struct AdditionalData
+    {
+      /**
+       * Constructor. By default, set the verbosity of the solver to zero.
+       */
+      AdditionalData (const unsigned int verbose = 0);
+
+      /**
+       * Verbosity of the solver: 0 =  no output, 1 = print information at the
+       * start and at the end, 3 = print residual at each iteration.
+       */
+      unsigned int verbose;
+    };
+
+    /**
+     * Constructor. AdditionalData is a structure that contains additional
+     * flags for tuning this particular solver.
+     */
+    SolverCR (SolverControl        &cn,
+              const AdditionalData &data = AdditionalData());
+
+    /**
+     * Solve the linear system <tt>Ax=b</tt> using the CR solver of
+     * Paralution. If the flag @p move_to_accelerator is set to true, the
+     * solver is built on the accelerator.
+     */
+    template <typename Number>
+    void solve (const SparseMatrix<Number>     &A,
+                Vector<Number>                 &x,
+                const Vector<Number>           &b,
+                const PreconditionBase<Number> &preconditioner,
+                bool                            move_to_accelerator=false);
+
+  private:
+    /**
+     * store a copy of the flags for this solver.
+     */
+    const AdditionalData additional_data;
+  };
+
+
+
+  /**
+   * An implementation of the solver interface using the Paralution DPCG solver.
+   * DPCG stands for Deflated Preconditioned Conjugate Gradient. It is a
+   * two-level preconditioned CG algorithm to iteratively solve and
+   * ill-conditioned linear system. Deflation tries to remove the bad
+   * eigenvalues from the spectrum of the preconditioned system.
+   *
+   * @ingroup ParalutionWrappers
+   * @author Bruno Turcksin, 2014
+   */
+  class SolverDPCG : public SolverBase
+  {
+  public:
+    /**
+     * Standardized data struct to pipe additional data to the solver.
+     */
+    struct AdditionalData
+    {
+      /**
+       * Constructor. By default, set the verbosity of the solver to zero and
+       * set the number of deflated vectors to two.
+       */
+      AdditionalData (const unsigned int verbose = 0,
+                      const unsigned int n_deflated_vectors = 2);
+
+      /**
+       * Verbosity of the solver: 0 =  no output, 1 = print information at the
+       * start and at the end, 3 = print residual at each iteration.
+       */
+      unsigned int verbose;
+
+      /**
+       * Number of deflated vectors.
+       */
+      unsigned int n_deflated_vectors;
+    };
+
+    /**
+     * Constructor. AdditionalData is a structure that contains additional
+     * flags for tuning this particular solver.
+     */
+    SolverDPCG (SolverControl        &cn,
+                const AdditionalData &data = AdditionalData());
+
+    /**
+     * Solve the linear system <tt>Ax=b</tt> using the DPCG solver of
+     * Paralution. If the flag @p move_to_accelerator is set to true, the
+     * solver is built on the accelerator.
+     */
+    template <typename Number>
+    void solve (const SparseMatrix<Number>     &A,
+                Vector<Number>                 &x,
+                const Vector<Number>           &b,
+                const PreconditionBase<Number> &preconditioner,
+                bool                            move_to_accelerator=false);
+
+  private:
+    /**
+     * store a copy of the flags for this solver.
+     */
+    const AdditionalData additional_data;
   };
 
 
@@ -110,14 +321,36 @@ namespace ParalutionWrappers
   /**
    * An implementation of the solver interface using the Paralution BiCGStab
    * solver.
+   *
+   * @ingroup ParalutionWrappers
+   * @author Bruno Turcksin, 2013
    */
   class SolverBicgstab : public SolverBase
   {
   public:
     /**
-     * Constructor.
+     * Standardized data struct to pipe additional data to the solver.
+     */
+    struct AdditionalData
+    {
+      /**
+       * Constructor. By default, set the verbosity of the solver to zero.
+       */
+      AdditionalData (const unsigned int verbose = 0);
+
+      /**
+       * Verbosity of the solver: 0 =  no output, 1 = print information at the
+       * start and at the end, 3 = print residual at each iteration.
+       */
+      unsigned int verbose;
+    };
+
+    /**
+     * Constructor. AdditionalData is a structure that contains additional
+     * flags for tuning this particular solver.
      */
-    SolverBicgstab (SolverControl &cn);
+    SolverBicgstab (SolverControl &cn,
+                    const AdditionalData &data = AdditionalData());
 
     /**
      * Solve the linear system <tt>Ax=b</tt> using the BiCGStab solver of
@@ -130,6 +363,12 @@ namespace ParalutionWrappers
                 const Vector<Number>           &b,
                 const PreconditionBase<Number> &preconditioner,
                 bool                            move_to_accelerator=false);
+
+  private:
+    /**
+     * store a copy of the flags for this solver.
+     */
+    const AdditionalData additional_data;
   };
 
 
@@ -137,6 +376,9 @@ namespace ParalutionWrappers
   /**
    * An implementation of the solver interface using the Paralution GMRES
    * solver.
+   *
+   * @ingroup ParalutionWrappers
+   * @author Bruno Turcksin, 2013
    */
   class SolverGMRES : public SolverBase
   {
@@ -147,10 +389,18 @@ namespace ParalutionWrappers
     struct AdditionalData
     {
       /**
-       * Constructor. By default, set the size of the Krylov space to 30,
-       * i.e. do a restart every 30 iterations.
+       * Constructor. By default, set the verbosity of the solver to zero and
+       * set the size of the Krylov space to 30, i.e. do a restart every 30
+       * iterations.
+       */
+      AdditionalData (const unsigned int verbose = 0,
+                      const unsigned int restart_parameter = 30);
+
+      /**
+       * Verbosity of the solver: 0 =  no output, 1 = print information at the
+       * start and at the end, 3 = print residual at each iteration.
        */
-      AdditionalData (const unsigned int restart_parameter = 30);
+      unsigned int verbose;
 
       /**
        * Size of the Krylov space.
@@ -160,9 +410,9 @@ namespace ParalutionWrappers
 
     /**
      * Constructor. AdditionalData is a structure that contains additional
-     * flags for tuning this particulat solver.
+     * flags for tuning this particular solver.
      */
-    SolverGMRES (SolverControl &cn,
+    SolverGMRES (SolverControl        &cn,
                  const AdditionalData &data = AdditionalData());
 
     /**
@@ -179,7 +429,70 @@ namespace ParalutionWrappers
 
   private:
     /**
-     * Store a copy of the flags for this solver.
+     * store a copy of the flags for this solver.
+     */
+    const AdditionalData additional_data;
+  };
+
+
+
+  /**
+   * An implementation of the solver interface using the Paralution GMRES
+   * solver.
+   *
+   * @ingroup ParalutionWrappers
+   * @author Bruno Turcksin, 2014
+   */
+  class SolverFGMRES : public SolverBase
+  {
+  public:
+    /**
+     * Standardized data struct to pipe additional data to the solver.
+     */
+    struct AdditionalData
+    {
+      /**
+       * Constructor. By default, set the verbosity of the solver to zero and
+       * set the size of the Krylov space to 30, i.e. do a restart every 30
+       * iterations.
+       */
+      AdditionalData (const unsigned int verbose = 0,
+                      const unsigned int restart_parameter = 30);
+
+      /**
+       * Verbosity of the solver: 0 =  no output, 1 = print information at the
+       * start and at the end, 3 = print residual at each iteration.
+       */
+      unsigned int verbose;
+
+      /**
+       * Size of the Krylov space.
+       */
+      unsigned int restart_parameter;
+    };
+
+    /**
+     * Constructor. AdditionalData is a structure that contains additional
+     * flags for tuning this particular solver.
+     */
+    SolverFGMRES (SolverControl        &cn,
+                  const AdditionalData &data = AdditionalData());
+
+    /**
+     * Solve the linear system <tt>Ax=b</tt> using the GMRES solver of
+     * Paralution. If the flag @p move_to_accelerator is set to true, the
+     * solver is built on the accelerator.
+     */
+    template <typename Number>
+    void solve (const SparseMatrix<Number>     &A,
+                Vector<Number>                 &x,
+                const Vector<Number>           &b,
+                const PreconditionBase<Number> &preconditioner,
+                bool                            move_to_accelerator=false);
+
+  private:
+    /**
+     * store a copy of the flags for this solver.
      */
     const AdditionalData additional_data;
   };
index 623a6f17d33483ed16c03d70b67145de83ccbbdb..22c5278ebc46164de5d2e69c45e12801efd85349 100644 (file)
@@ -34,6 +34,8 @@ namespace ParalutionWrappers
     return solver_control;
   }
 
+
+
   template <typename Number>
   void SolverBase::execute_solve(std_cxx1x::shared_ptr<paralution::IterativeLinearSolver<paralution::
                                  LocalMatrix<Number>,paralution::LocalVector<Number>,Number> > solver,
@@ -64,11 +66,61 @@ namespace ParalutionWrappers
 
 
 
-  /* ---------------------- SolverCG ------------------------ */
+  /* --------------------- SolverRichardson----------------- */
+
+  SolverRichardson::AdditionalData::AdditionalData(const unsigned int verbose,
+                                                   const double relaxation_parameter)
+    :
+    verbose(verbose),
+    relaxation_parameter(relaxation_parameter)
+  {}
+
+
+
+  SolverRichardson::SolverRichardson (SolverControl        &cn,
+                                      const AdditionalData &data)
+    :
+    SolverBase (cn),
+    additional_data (data)
+  {}
+
+
+
+  template <typename Number>
+  void SolverRichardson::solve(const SparseMatrix<Number>     &A,
+                               Vector<Number>                 &x,
+                               const Vector<Number>           &b,
+                               const PreconditionBase<Number> &preconditioner,
+                               bool                            move_to_accelerator)
+  {
+    std_cxx1x::shared_ptr<paralution::FixedPoint<paralution::LocalMatrix<Number>,
+              paralution::LocalVector<Number>,Number> > solver(new  paralution::
+                                                               FixedPoint<paralution::LocalMatrix<Number>, paralution::LocalVector<Number>,Number>);
+
+    // Set the verbosity of the solver.
+    solver->Verbose(additional_data.verbose);
+
+    // Set the relaxation parameter.
+    solver->SetRelaxation(additional_data.relaxation_parameter);
+
+    this->execute_solve<Number>(solver,A,x,b,preconditioner,move_to_accelerator);
+  }
+
+
+
+  /* ---------------------- SolverCG ------------------------- */
 
-  SolverCG::SolverCG (SolverControl &cn)
+  SolverCG::AdditionalData::AdditionalData(const unsigned int verbose)
     :
-    SolverBase (cn)
+    verbose(verbose)
+  {}
+
+
+
+  SolverCG::SolverCG (SolverControl &cn, const AdditionalData &data)
+    :
+    SolverBase (cn),
+    additional_data (data)
   {}
 
 
@@ -84,6 +136,86 @@ namespace ParalutionWrappers
               paralution::LocalVector<Number>,Number> > solver(new  paralution::
                                                                CG<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,Number>);
 
+    // Set the verbosity of the solver.
+    solver->Verbose(additional_data.verbose);
+
+    this->execute_solve<Number>(solver,A,x,b,preconditioner,move_to_accelerator);
+  }
+
+
+
+  /* ---------------------- SolverCR ------------------------- */
+
+  SolverCR::AdditionalData::AdditionalData(const unsigned int verbose)
+    :
+    verbose(verbose)
+  {}
+
+
+
+  SolverCR::SolverCR (SolverControl &cn, const AdditionalData &data)
+    :
+    SolverBase (cn),
+    additional_data (data)
+  {}
+
+
+
+  template <typename Number>
+  void SolverCR::solve(const SparseMatrix<Number>     &A,
+                       Vector<Number>                 &x,
+                       const Vector<Number>           &b,
+                       const PreconditionBase<Number> &preconditioner,
+                       bool                            move_to_accelerator)
+  {
+    std_cxx1x::shared_ptr<paralution::CR<paralution::LocalMatrix<Number>,
+              paralution::LocalVector<Number>,Number> > solver(new  paralution::
+                                                               CR<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,Number>);
+
+    // Set the verbosity of the solver.
+    solver->Verbose(additional_data.verbose);
+
+    this->execute_solve<Number>(solver,A,x,b,preconditioner,move_to_accelerator);
+  }
+
+
+
+  /* ---------------------- SolverDPCG ----------------------- */
+
+  SolverDPCG::AdditionalData::AdditionalData(const unsigned int verbose,
+                                             const const unsigned int n_deflated_vectors)
+    :
+    verbose (verbose),
+    n_deflated_vectors(n_deflated_vectors)
+  {}
+
+
+
+  SolverDPCG::SolverDPCG (SolverControl &cn, const AdditionalData &data)
+    :
+    SolverBase (cn),
+    additional_data (data)
+  {}
+
+
+
+  template <typename Number>
+  void SolverDPCG::solve(const SparseMatrix<Number>     &A,
+                         Vector<Number>                 &x,
+                         const Vector<Number>           &b,
+                         const PreconditionBase<Number> &preconditioner,
+                         bool                            move_to_accelerator)
+  {
+    std_cxx1x::shared_ptr<paralution::DPCG<paralution::LocalMatrix<Number>,
+              paralution::LocalVector<Number>,Number> > solver(new  paralution::
+                                                               DPCG<paralution::LocalMatrix<Number>, paralution::LocalVector<Number>,Number>);
+
+    // Set the verbosity of the solver.
+    solver->Verbose(additional_data.verbose);
+
+    // Set the number of deflated vectors.
+    solver->SetNVectors(additional_data.n_deflated_vectors);
+
     this->execute_solve<Number>(solver,A,x,b,preconditioner,move_to_accelerator);
   }
 
@@ -91,9 +223,17 @@ namespace ParalutionWrappers
 
   /* -------------------- SolverBicgstab --------------------- */
 
-  SolverBicgstab::SolverBicgstab (SolverControl &cn)
+  SolverBicgstab::AdditionalData::AdditionalData(const unsigned int verbose)
     :
-    SolverBase (cn)
+    verbose(verbose)
+  {}
+
+
+
+  SolverBicgstab::SolverBicgstab (SolverControl &cn, const AdditionalData &data)
+    :
+    SolverBase (cn),
+    additional_data (data)
   {}
 
 
@@ -109,6 +249,9 @@ namespace ParalutionWrappers
               paralution::LocalVector<Number>,Number> > solver(new  paralution::
                                                                BiCGStab<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,Number>);
 
+    // Set the verbosity of the solver.
+    solver->Verbose(additional_data.verbose);
+
     this->execute_solve<Number>(solver,A,x,b,preconditioner,move_to_accelerator);
   }
 
@@ -116,14 +259,15 @@ namespace ParalutionWrappers
 
   /* --------------------- SolverGMRES ----------------------- */
 
-  SolverGMRES::AdditionalData::AdditionalData(const unsigned int restart_parameter)
+  SolverGMRES::AdditionalData::AdditionalData(const unsigned int verbose,
+                                              const unsigned int restart_parameter)
     :
+    verbose(verbose),
     restart_parameter(restart_parameter)
   {}
 
 
 
-
   SolverGMRES::SolverGMRES (SolverControl        &cn,
                             const AdditionalData &data)
     :
@@ -144,6 +288,51 @@ namespace ParalutionWrappers
               paralution::LocalVector<Number>,Number> > solver(new  paralution::
                                                                GMRES<paralution::LocalMatrix<Number>, paralution::LocalVector<Number>,Number>);
 
+    // Set the verbosity of the solver.
+    solver->Verbose(additional_data.verbose);
+
+    // Set the restart parameter.
+    solver->SetBasisSize(additional_data.restart_parameter);
+
+    this->execute_solve<Number>(solver,A,x,b,preconditioner,move_to_accelerator);
+  }
+
+
+
+  /* --------------------- SolverFGMRES ---------------------- */
+
+  SolverFGMRES::AdditionalData::AdditionalData(const unsigned int verbose,
+                                               const unsigned int restart_parameter)
+    :
+    verbose(verbose),
+    restart_parameter(restart_parameter)
+  {}
+
+
+
+  SolverFGMRES::SolverFGMRES (SolverControl        &cn,
+                              const AdditionalData &data)
+    :
+    SolverBase (cn),
+    additional_data (data)
+  {}
+
+
+
+  template <typename Number>
+  void SolverFGMRES::solve(const SparseMatrix<Number>     &A,
+                           Vector<Number>                 &x,
+                           const Vector<Number>           &b,
+                           const PreconditionBase<Number> &preconditioner,
+                           bool                            move_to_accelerator)
+  {
+    std_cxx1x::shared_ptr<paralution::FGMRES<paralution::LocalMatrix<Number>,
+              paralution::LocalVector<Number>,Number> > solver(new  paralution::
+                                                               FGMRES<paralution::LocalMatrix<Number>, paralution::LocalVector<Number>,Number>);
+
+    // Set the verbosity of the solver.
+    solver->Verbose(additional_data.verbose);
+
     // Set the restart parameter.
     solver->SetBasisSize(additional_data.restart_parameter);
 
@@ -168,6 +357,30 @@ namespace ParalutionWrappers
                                         const PreconditionBase<double> &preconditioner,
                                         bool                            move_to_accelerator);
 
+  template void SolverCR::solve<float>(const SparseMatrix<float>     &A,
+                                       Vector<float>                 &x,
+                                       const Vector<float>           &b,
+                                       const PreconditionBase<float> &preconditioner,
+                                       bool                           move_to_accelerator);
+
+  template void SolverCR::solve<double>(const SparseMatrix<double>     &A,
+                                        Vector<double>                 &x,
+                                        const Vector<double>           &b,
+                                        const PreconditionBase<double> &preconditioner,
+                                        bool                            move_to_accelerator);
+
+  template void SolverDPCG::solve<float>(const SparseMatrix<float>     &A,
+                                         Vector<float>                 &x,
+                                         const Vector<float>           &b,
+                                         const PreconditionBase<float> &preconditioner,
+                                         bool                           move_to_accelerator);
+
+  template void SolverDPCG::solve<double>(const SparseMatrix<double>     &A,
+                                          Vector<double>                 &x,
+                                          const Vector<double>           &b,
+                                          const PreconditionBase<double> &preconditioner,
+                                          bool                            move_to_accelerator);
+
   template void SolverBicgstab::solve<float>(const SparseMatrix<float>     &A,
                                              Vector<float>                 &x,
                                              const Vector<float>           &b,
@@ -191,6 +404,18 @@ namespace ParalutionWrappers
                                            const Vector<double>           &b,
                                            const PreconditionBase<double> &preconditioner,
                                            bool                            move_to_accelerator);
+
+  template void SolverFGMRES::solve<float>(const SparseMatrix<float>     &A,
+                                           Vector<float>                 &x,
+                                           const Vector<float>           &b,
+                                           const PreconditionBase<float> &preconditioner,
+                                           bool                           move_to_accelerator);
+
+  template void SolverFGMRES::solve<double>(const SparseMatrix<double>     &A,
+                                            Vector<double>                 &x,
+                                            const Vector<double>           &b,
+                                            const PreconditionBase<double> &preconditioner,
+                                            bool                            move_to_accelerator);
 }
 
 DEAL_II_NAMESPACE_CLOSE

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.