From 3b9f641f4202a7903b453385700ff7268ef7f0c9 Mon Sep 17 00:00:00 2001 From: Pratik Nayak Date: Tue, 5 Feb 2019 14:20:12 +0100 Subject: [PATCH] Add preconditioner support. --- include/deal.II/lac/ginkgo_solver.h | 13 +++++++++++++ source/lac/ginkgo_solver.cc | 13 +++++++++++++ tests/ginkgo/solver.cc | 7 +++++++ tests/ginkgo/solver.output | 1 + 4 files changed, 34 insertions(+) diff --git a/include/deal.II/lac/ginkgo_solver.h b/include/deal.II/lac/ginkgo_solver.h index 3ac50c9128..3b327511ed 100644 --- a/include/deal.II/lac/ginkgo_solver.h +++ b/include/deal.II/lac/ginkgo_solver.h @@ -225,6 +225,19 @@ namespace GinkgoWrappers std::shared_ptr 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 executor, + std::shared_ptr preconditioner, + const AdditionalData & data = AdditionalData()); protected: /** * Store a copy of the settings for this particular solver. diff --git a/source/lac/ginkgo_solver.cc b/source/lac/ginkgo_solver.cc index 8223fc6a4d..2aa25a55ee 100644 --- a/source/lac/ginkgo_solver.cc +++ b/source/lac/ginkgo_solver.cc @@ -288,6 +288,19 @@ namespace GinkgoWrappers cg::build().with_criteria(this->combined_factory).on(executor); } + template + SolverCG::SolverCG( + SolverControl & solver_control, + std::shared_ptr executor, + std::shared_ptr preconditioner, + const AdditionalData & data) + : SolverBase(solver_control, executor) + , additional_data(data) + { + using cg = gko::solver::Cg; + 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); \ diff --git a/tests/ginkgo/solver.cc b/tests/ginkgo/solver.cc index 560d9117c4..46deda45c8 100644 --- a/tests/ginkgo/solver.cc +++ b/tests/ginkgo/solver.cc @@ -57,11 +57,18 @@ main(int argc, char **argv) // gko::OmpExecutor::create()); // std::shared_ptr exec = gko::OmpExecutor::create(); std::shared_ptr exec = gko::ReferenceExecutor::create(); + std::shared_ptr 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); } } diff --git a/tests/ginkgo/solver.output b/tests/ginkgo/solver.output index 4ce62b0ef7..06d6d30d58 100644 --- a/tests/ginkgo/solver.output +++ b/tests/ginkgo/solver.output @@ -1,3 +1,4 @@ DEAL::Size 32 Unknowns 961 DEAL::Solver stopped within 35 - 39 iterations +DEAL::Solver stopped within 29 - 33 iterations -- 2.39.5