]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add preconditioner support.
authorPratik Nayak <pratik.nayak4@gmail.com>
Tue, 5 Feb 2019 13:20:12 +0000 (14:20 +0100)
committerPratik Nayak <pratik.nayak4@gmail.com>
Thu, 25 Apr 2019 08:57:00 +0000 (10:57 +0200)
include/deal.II/lac/ginkgo_solver.h
source/lac/ginkgo_solver.cc
tests/ginkgo/solver.cc
tests/ginkgo/solver.output

index 3ac50c912836f2eb51e2194bab0373a7bbd5232c..3b327511ed8615a14ff016b1ba0b48ab918a3c4c 100644 (file)
@@ -225,6 +225,19 @@ namespace GinkgoWrappers
              std::shared_ptr<gko::Executor> executor,
              const AdditionalData &         data = AdditionalData());
 
+  /**
+   * Constructor.
+   *
+   * @p solver_control The solver control object is then used to set the
+   * parameters and setup the CG solver from the CG factory which solves the
+   * linear system.
+   *
+   * @p executor The execution paradigm for the CG solver.
+   */
+  SolverCG(SolverControl &                solver_control,
+           std::shared_ptr<gko::Executor> executor,
+           std::shared_ptr<gko::LinOpFactory> preconditioner,
+           const AdditionalData &         data = AdditionalData());
   protected:
     /**
      * Store a copy of the settings for this particular solver.
index 8223fc6a4d385588f59ffe509993b6e117258f9a..2aa25a55ee8a42a88433e6f87e29177df2fd69e9 100644 (file)
@@ -288,6 +288,19 @@ namespace GinkgoWrappers
       cg::build().with_criteria(this->combined_factory).on(executor);
   }
 
+  template <typename ValueType, typename IndexType>
+  SolverCG<ValueType, IndexType>::SolverCG(
+                                           SolverControl &                solver_control,
+                                           std::shared_ptr<gko::Executor> executor,
+                                           std::shared_ptr<gko::LinOpFactory> preconditioner,
+                                           const AdditionalData &         data)
+    : SolverBase<ValueType, IndexType>(solver_control, executor)
+    , additional_data(data)
+  {
+    using cg = gko::solver::Cg<ValueType>;
+    this->solver_gen =
+      cg::build().with_criteria(this->combined_factory).with_preconditioner(preconditioner).on(executor);
+  }
   // Explicit instantiations in GinkgoWrappers
 #  define DEALII_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
     template _macro(float, int32_t);                               \
index 560d9117c41101f085e7c57ee517045f07932e22..46deda45c81454926dc2c5fdb9d96094937e6ef3 100644 (file)
@@ -57,11 +57,18 @@ main(int argc, char **argv)
     //                                                               gko::OmpExecutor::create());
     // std::shared_ptr<gko::Executor> exec = gko::OmpExecutor::create();
     std::shared_ptr<gko::Executor> exec = gko::ReferenceExecutor::create();
+    std::shared_ptr<gko::LinOpFactory> jacobi = gko::preconditioner::Jacobi<>::build().on(exec);
     GinkgoWrappers::SolverCG<>     solver(control, exec);
+    GinkgoWrappers::SolverCG<>     solver_with_jacobi_precond(control, exec, jacobi);
 
     check_solver_within_range(solver.solve(A, u, f),
                               control.last_step(),
                               35,
                               39);
+    u = 0.;
+    check_solver_within_range(solver_with_jacobi_precond.solve(A, u, f),
+                              control.last_step(),
+                              29,
+                              33);
   }
 }
index 4ce62b0ef7c1c06192d2403fda2dc450cb545784..06d6d30d58f04690b80438e6441671368534df5c 100644 (file)
@@ -1,3 +1,4 @@
 
 DEAL::Size 32 Unknowns 961
 DEAL::Solver stopped within 35 - 39 iterations
+DEAL::Solver stopped within 29 - 33 iterations

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.