Ginkgo  Generated from pipelines/2662685947 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
sor.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_PRECONDITIONER_SOR_HPP_
6 #define GKO_PUBLIC_CORE_PRECONDITIONER_SOR_HPP_
7 
8 
9 #include <vector>
10 
11 #include <ginkgo/core/base/abstract_factory.hpp>
12 #include <ginkgo/core/base/composition.hpp>
13 #include <ginkgo/core/base/lin_op.hpp>
14 #include <ginkgo/core/base/polymorphic_object.hpp>
15 #include <ginkgo/core/config/config.hpp>
16 
17 
18 namespace gko {
19 namespace preconditioner {
20 
21 
50 template <typename ValueType = default_precision, typename IndexType = int32>
51 class Sor : public LinOpFactory {
52  GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
53 
54 public:
55  struct parameters_type;
57 
58  using value_type = ValueType;
59  using index_type = IndexType;
61 
63  : public enable_parameters_type<parameters_type, Sor> {
64  // skip sorting of input matrix
65  bool GKO_FACTORY_PARAMETER_SCALAR(skip_sorting, false);
66 
67  // determines if SOR or SSOR should be used
68  bool GKO_FACTORY_PARAMETER_SCALAR(symmetric, false);
69 
70  // has to be between 0.0 and 2.0
72  relaxation_factor, remove_complex<value_type>(1.2));
73 
74  // factory for the lower triangular factor solver, defaults to LowerTrs
75  std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
76  l_solver);
77 
78  // factory for the upper triangular factor solver, unused if symmetric
79  // is false, defaults to UpperTrs
80  std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
81  u_solver);
82  };
83 
89  const parameters_type& get_parameters() { return parameters_; }
90 
94  const parameters_type& get_parameters() const { return parameters_; }
95 
103  std::unique_ptr<composition_type> generate(
104  std::shared_ptr<const LinOp> system_matrix) const;
105 
107  static parameters_type build() { return {}; }
108 
109  static parameters_type parse(
110  const config::pnode& config, const config::registry& context,
111  const config::type_descriptor& td_for_child =
112  config::make_type_descriptor<ValueType, IndexType>());
113 
114 protected:
115  explicit Sor(std::shared_ptr<const Executor> exec,
116  const parameters_type& params = {})
117  : LinOpFactory(exec), parameters_(params)
118  {
119  GKO_ASSERT(parameters_.relaxation_factor > 0.0 &&
120  parameters_.relaxation_factor < 2.0);
121  }
122 
123  std::unique_ptr<LinOp> generate_impl(
124  std::shared_ptr<const LinOp> system_matrix) const override;
125 
126 private:
127  parameters_type parameters_;
128 };
129 } // namespace preconditioner
130 } // namespace gko
131 
132 
133 #endif // GKO_PUBLIC_CORE_PRECONDITIONER_SOR_HPP_
gko::config::pnode
pnode describes a tree of properties.
Definition: property_tree.hpp:28
gko::preconditioner::Sor::generate
std::unique_ptr< composition_type > generate(std::shared_ptr< const LinOp > system_matrix) const
GKO_FACTORY_PARAMETER_SCALAR
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition: abstract_factory.hpp:437
gko::preconditioner::Sor::get_parameters
const parameters_type & get_parameters()
Returns the parameters used to construct the factory.
Definition: sor.hpp:89
gko::config::type_descriptor
This class describes the value and index types to be used when building a Ginkgo type from a configur...
Definition: type_descriptor.hpp:39
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::preconditioner::Sor
This class generates the (S)SOR preconditioner.
Definition: sor.hpp:51
gko::Composition
The Composition class can be used to compose linear operators op1, op2, ..., opn and obtain the opera...
Definition: composition.hpp:39
gko::preconditioner::Sor::get_parameters
const parameters_type & get_parameters() const
Returns the parameters used to construct the factory.
Definition: sor.hpp:94
gko::preconditioner::Sor::parameters_type
Definition: sor.hpp:62
gko::config::registry
This class stores additional context for creating Ginkgo objects from configuration files.
Definition: registry.hpp:167
gko::LinOpFactory
A LinOpFactory represents a higher order mapping which transforms one linear operator into another.
Definition: lin_op.hpp:343
gko::preconditioner::Sor::build
static parameters_type build()
Creates a new parameter_type to set up the factory.
Definition: sor.hpp:107
gko::enable_parameters_type
The enable_parameters_type mixin is used to create a base implementation of the factory parameters st...
Definition: abstract_factory.hpp:203
gko::remove_complex
typename detail::remove_complex_s< T >::type remove_complex
Obtain the type which removed the complex of complex/scalar type or the template parameter of class b...
Definition: math.hpp:264