33#ifndef GKO_PUBLIC_CORE_SOLVER_IR_HPP_
34#define GKO_PUBLIC_CORE_SOLVER_IR_HPP_
40#include <ginkgo/core/base/exception_helpers.hpp>
41#include <ginkgo/core/base/lin_op.hpp>
42#include <ginkgo/core/base/types.hpp>
43#include <ginkgo/core/matrix/dense.hpp>
44#include <ginkgo/core/matrix/identity.hpp>
45#include <ginkgo/core/solver/solver_base.hpp>
46#include <ginkgo/core/stop/combined.hpp>
47#include <ginkgo/core/stop/criterion.hpp>
48#include <ginkgo/core/stop/iteration.hpp>
107template <
typename ValueType = default_precision>
118 using value_type = ValueType;
132 return this->get_default_initial_guess() ==
141 std::shared_ptr<const LinOp>
get_solver()
const {
return solver_; }
187 std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
214 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
216 template <
typename VectorType>
221 LinOp* x)
const override;
223 void apply_with_initial_guess_impl(
const LinOp* b,
LinOp* x,
226 void apply_with_initial_guess_impl(
const LinOp* alpha,
const LinOp* b,
230 void set_relaxation_factor(
233 explicit Ir(std::shared_ptr<const Executor> exec)
238 std::shared_ptr<const LinOp> system_matrix)
244 parameters_{factory->get_parameters()}
248 }
else if (parameters_.
solver) {
250 parameters_.
solver->generate(
this->get_system_matrix()));
252 this->
set_solver(matrix::Identity<ValueType>::create(
261 std::shared_ptr<const LinOp> solver_{};
262 std::shared_ptr<const matrix::Dense<ValueType>> relaxation_factor_{};
266template <
typename ValueType = default_precision>
270template <
typename ValueType>
274 static int num_vectors(
const Solver&);
276 static int num_arrays(
const Solver&);
278 static std::vector<std::string> op_names(
const Solver&);
280 static std::vector<std::string> array_names(
const Solver&);
282 static std::vector<int> scalars(
const Solver&);
284 static std::vector<int> vectors(
const Solver&);
287 constexpr static int residual = 0;
289 constexpr static int inner_solution = 1;
291 constexpr static int one = 2;
293 constexpr static int minus_one = 3;
296 constexpr static int stop = 0;
310template <
typename ValueType>
314 auto exec = factory->get_executor();
316 .with_solver(factory)
317 .with_relaxation_factor(relaxation_factor)
318 .with_criteria(gko::stop::Iteration::build().with_max_iters(
iteration))
334template <
typename ValueType>
338 auto exec = solver->get_executor();
340 .with_generated_solver(solver)
341 .with_relaxation_factor(relaxation_factor)
342 .with_criteria(gko::stop::Iteration::build().with_max_iters(
iteration))
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:908
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:691
Definition lin_op.hpp:146
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition polymorphic_object.hpp:263
Linear operators which support transposition should implement the Transposable interface.
Definition lin_op.hpp:462
Dense is a matrix format which explicitly stores all values of the matrix.
Definition dense.hpp:136
EnableApplyWithInitialGuess providing default operation for ApplyWithInitialGuess with correct valida...
Definition solver_base.hpp:190
A LinOp deriving from this CRTP class stores a stopping criterion factory and allows applying with a ...
Definition solver_base.hpp:732
A LinOp deriving from this CRTP class stores a system matrix.
Definition solver_base.hpp:570
Iterative refinement (IR) is an iterative method that uses another coarse method to approximate the e...
Definition ir.hpp:112
Ir(const Ir &)
Copy-constructs an IR solver.
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
Ir & operator=(Ir &&)
Move-assigns an IR solver.
Ir(Ir &&)
Move-constructs an IR solver.
void set_solver(std::shared_ptr< const LinOp > new_solver)
Sets the solver operator used as the inner solver.
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
std::shared_ptr< const LinOp > get_solver() const
Returns the solver operator used as the inner solver.
Definition ir.hpp:141
bool apply_uses_initial_guess() const override
Return true as iterative solvers use the data in x as an initial guess.
Definition ir.hpp:130
Ir & operator=(const Ir &)
Copy-assigns an IR solver.
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition abstract_factory.hpp:473
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Defines a build method for the factory, simplifying its construction by removing the repetitive typin...
Definition abstract_factory.hpp:422
#define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name)
This macro will generate a default implementation of a LinOpFactory for the LinOp subclass it is defi...
Definition lin_op.hpp:1046
std::shared_ptr< const CriterionFactory > combine(FactoryContainer &&factories)
Combines multiple criterion factories into a single combined criterion factory.
Definition combined.hpp:138
initial_guess_mode
Give a initial guess mode about the input of the apply method.
Definition solver_base.hpp:62
@ provided
the input is provided
auto build_smoother(std::shared_ptr< const LinOpFactory > factory, size_type iteration=1, ValueType relaxation_factor=0.9)
build_smoother gives a shortcut to build a smoother by IR(Richardson) with limited stop criterion(ite...
Definition ir.hpp:311
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
initial_guess_mode default_initial_guess
Default initial guess mode.
Definition ir.hpp:208
std::shared_ptr< const LinOpFactory > solver
Inner solver factory.
Definition ir.hpp:188
std::shared_ptr< const LinOp > generated_solver
Already generated solver.
Definition ir.hpp:195
ValueType relaxation_factor
Relaxation factor for Richardson iteration.
Definition ir.hpp:201
Definition solver_base.hpp:858
Traits class providing information on the type and location of workspace vectors inside a solver.
Definition solver_base.hpp:267