ginkgo/core/solver/idr.hpp Source File

ginkgo/core/solver/idr.hpp Source File#

Reference API: ginkgo/core/solver/idr.hpp Source File
Reference API
idr.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_SOLVER_IDR_HPP_
6#define GKO_PUBLIC_CORE_SOLVER_IDR_HPP_
7
8
9#include <random>
10#include <typeinfo>
11#include <vector>
12
13#include <ginkgo/core/base/array.hpp>
14#include <ginkgo/core/base/exception_helpers.hpp>
15#include <ginkgo/core/base/lin_op.hpp>
16#include <ginkgo/core/base/math.hpp>
17#include <ginkgo/core/base/types.hpp>
18#include <ginkgo/core/config/config.hpp>
19#include <ginkgo/core/config/registry.hpp>
20#include <ginkgo/core/log/logger.hpp>
21#include <ginkgo/core/matrix/dense.hpp>
22#include <ginkgo/core/matrix/identity.hpp>
23#include <ginkgo/core/solver/solver_base.hpp>
24#include <ginkgo/core/stop/combined.hpp>
25#include <ginkgo/core/stop/criterion.hpp>
26
27
28namespace gko {
34namespace solver {
35
36
53template <typename ValueType = default_precision>
54class Idr
55 : public EnableLinOp<Idr<ValueType>>,
56 public EnablePreconditionedIterativeSolver<ValueType, Idr<ValueType>>,
57 public Transposable {
58 friend class EnableLinOp<Idr>;
59 friend class EnablePolymorphicObject<Idr, LinOp>;
60
61public:
62 using value_type = ValueType;
64
65 std::unique_ptr<LinOp> transpose() const override;
66
67 std::unique_ptr<LinOp> conj_transpose() const override;
68
74 bool apply_uses_initial_guess() const override { return true; }
75
80 size_type get_subspace_dim() const { return parameters_.subspace_dim; }
81
86 void set_subspace_dim(const size_type other)
87 {
88 parameters_.subspace_dim = other;
89 }
90
96 remove_complex<ValueType> get_kappa() const { return parameters_.kappa; }
97
104 {
105 parameters_.kappa = other;
106 }
107
113 bool get_deterministic() const { return parameters_.deterministic; }
114
120 void set_deterministic(const bool other)
121 {
122 parameters_.deterministic = other;
123 }
124
130 bool get_complex_subspace() const { return parameters_.complex_subspace; }
131
138 GKO_DEPRECATED("Use set_complex_subspace instead")
139 void set_complex_subpsace(const bool other)
140 {
141 this->set_complex_subspace(other);
142 }
143
149 void set_complex_subspace(const bool other)
150 {
151 parameters_.complex_subspace = other;
152 }
153
154 class Factory;
155
195
209 static parameters_type parse(const config::pnode& config,
210 const config::registry& context,
211 const config::type_descriptor& td_for_child =
212 config::make_type_descriptor<ValueType>());
213
214protected:
215 void apply_impl(const LinOp* b, LinOp* x) const override;
216
217 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
218 LinOp* x) const override;
219
220 template <typename VectorType>
221 void iterate(const VectorType* dense_b, VectorType* dense_x) const;
222
223 explicit Idr(std::shared_ptr<const Executor> exec)
224 : EnableLinOp<Idr>(std::move(exec))
225 {}
226
227 explicit Idr(const Factory* factory,
228 std::shared_ptr<const LinOp> system_matrix)
229 : EnableLinOp<Idr>(factory->get_executor(),
230 gko::transpose(system_matrix->get_size())),
231 EnablePreconditionedIterativeSolver<ValueType, Idr<ValueType>>{
232 std::move(system_matrix), factory->get_parameters()},
233 parameters_{factory->get_parameters()}
234 {}
235};
236
237
238template <typename ValueType>
239struct workspace_traits<Idr<ValueType>> {
240 using Solver = Idr<ValueType>;
241 // number of vectors used by this workspace
242 static int num_vectors(const Solver&);
243 // number of arrays used by this workspace
244 static int num_arrays(const Solver&);
245 // array containing the num_vectors names for the workspace vectors
246 static std::vector<std::string> op_names(const Solver&);
247 // array containing the num_arrays names for the workspace vectors
248 static std::vector<std::string> array_names(const Solver&);
249 // array containing all varying scalar vectors (independent of problem size)
250 static std::vector<int> scalars(const Solver&);
251 // array containing all varying vectors (dependent on problem size)
252 static std::vector<int> vectors(const Solver&);
253
254 // residual vector
255 constexpr static int residual = 0;
256 // v vector
257 constexpr static int v = 1;
258 // t vector
259 constexpr static int t = 2;
260 // helper vector
261 constexpr static int helper = 3;
262 // m multivector
263 constexpr static int m = 4;
264 // g multivector
265 constexpr static int g = 5;
266 // u multivector
267 constexpr static int u = 6;
268 // subspace multivector
269 constexpr static int subspace = 7;
270 // f "multiscalar"
271 constexpr static int f = 8;
272 // c "multiscalar"
273 constexpr static int c = 9;
274 // omega scalar
275 constexpr static int omega = 10;
276 // residual norm scalar
277 constexpr static int residual_norm = 11;
278 // T^H*T scalar
279 constexpr static int tht = 12;
280 // alpha "multiscalar"
281 constexpr static int alpha = 13;
282 // constant 1.0 scalar
283 constexpr static int one = 14;
284 // constant -1.0 scalar
285 constexpr static int minus_one = 15;
286 // constant -1.0 scalar
287 constexpr static int subspace_minus_one = 16;
288
289 // stopping status array
290 constexpr static int stop = 0;
291 // reduction tmp array
292 constexpr static int tmp = 1;
293};
294
295
296} // namespace solver
297} // namespace gko
298
299
300#endif // GKO_PUBLIC_CORE_SOLVER_IDR_HPP_
Definition lin_op.hpp:878
Definition polymorphic_object.hpp:668
Definition lin_op.hpp:117
std::shared_ptr< const Executor > get_executor() const noexcept
Definition polymorphic_object.hpp:243
Definition lin_op.hpp:433
Definition property_tree.hpp:28
Definition registry.hpp:167
Definition type_descriptor.hpp:39
Definition idr.hpp:193
Definition idr.hpp:57
void set_kappa(const remove_complex< ValueType > other)
Definition idr.hpp:103
void set_complex_subpsace(const bool other)
Definition idr.hpp:139
void set_subspace_dim(const size_type other)
Definition idr.hpp:86
void set_deterministic(const bool other)
Definition idr.hpp:120
bool apply_uses_initial_guess() const override
Definition idr.hpp:74
std::unique_ptr< LinOp > conj_transpose() const override
void set_complex_subspace(const bool other)
Definition idr.hpp:149
bool get_complex_subspace() const
Definition idr.hpp:130
size_type get_subspace_dim() const
Definition idr.hpp:80
static parameters_type parse(const config::pnode &config, const config::registry &context, const config::type_descriptor &td_for_child=config::make_type_descriptor< ValueType >())
bool get_deterministic() const
Definition idr.hpp:113
std::unique_ptr< LinOp > transpose() const override
remove_complex< ValueType > get_kappa() const
Definition idr.hpp:96
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Definition abstract_factory.hpp:445
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Definition abstract_factory.hpp:394
#define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name)
Definition lin_op.hpp:1016
The Ginkgo namespace.
Definition abstract_factory.hpp:20
constexpr T one()
Definition math.hpp:630
std::size_t size_type
Definition types.hpp:89
typename detail::remove_complex_s< T >::type remove_complex
Definition math.hpp:260
STL namespace.
Definition idr.hpp:158
bool complex_subspace
Definition idr.hpp:191
remove_complex< ValueType > kappa
Definition idr.hpp:171
bool deterministic
Definition idr.hpp:182
size_type subspace_dim
Definition idr.hpp:163
Definition solver_base.hpp:238