Ginkgo  Generated from pipelines/2969282958 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
nullspace_projection.hpp
1 // SPDX-FileCopyrightText: 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_PRECONDITIONER_NULLSPACE_PROJECTION_HPP_
6 #define GKO_PUBLIC_CORE_PRECONDITIONER_NULLSPACE_PROJECTION_HPP_
7 
8 
9 #include <memory>
10 
11 #include <ginkgo/core/base/abstract_factory.hpp>
12 #include <ginkgo/core/base/lin_op.hpp>
13 #include <ginkgo/core/base/polymorphic_object.hpp>
14 #include <ginkgo/core/config/property_tree.hpp>
15 #include <ginkgo/core/config/registry.hpp>
16 #include <ginkgo/core/config/type_descriptor.hpp>
17 #include <ginkgo/core/solver/nullspace.hpp>
18 
19 
20 namespace gko {
21 namespace preconditioner {
22 
23 
49 template <typename ValueType = default_precision>
51  : public LinOp,
52  public EnableCloneable<NullspaceProjection<ValueType>>,
53  public Transposable {
55  GKO_ASSERT_SUPPORTED_VALUE_TYPE;
56 
57 public:
60 
61  using value_type = ValueType;
62 
64  std::shared_ptr<const LinOp> get_preconditioner() const;
65 
70  std::shared_ptr<const solver::Nullspace<ValueType>> get_nullspace() const;
71 
76  std::shared_ptr<const solver::Nullspace<ValueType>> get_left_nullspace()
77  const;
78 
79  std::unique_ptr<LinOp> transpose() const override;
80 
81  std::unique_ptr<LinOp> conj_transpose() const override;
82 
83  NullspaceProjection& operator=(const NullspaceProjection& other);
84 
85  NullspaceProjection& operator=(NullspaceProjection&& other);
86 
88 
90 
92  {
96  std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
97  preconditioner);
98 
103  std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(
104  generated_preconditioner, nullptr);
105 
110  std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(nullspace,
111  nullptr);
112 
119  std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(
120  left_nullspace, nullptr);
121  };
124 
138  static parameters_type parse(const config::pnode& config,
139  const config::registry& context,
140  const config::type_descriptor& td_for_child =
141  config::make_type_descriptor<ValueType>());
142 
143 protected:
144  explicit NullspaceProjection(std::shared_ptr<const Executor> exec);
145 
146  NullspaceProjection(const Factory* factory,
147  std::shared_ptr<const LinOp> system_matrix);
148 
150  std::shared_ptr<const Executor> exec, dim<2> size,
151  std::shared_ptr<const LinOp> preconditioner,
152  std::shared_ptr<const solver::Nullspace<ValueType>> nullspace,
153  std::shared_ptr<const solver::Nullspace<ValueType>> left_nullspace);
154 
155  void apply_impl(const LinOp* b, LinOp* x) const override;
156 
157  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
158  LinOp* x) const override;
159 
160 private:
161  // a vector of the same kind as the input, which is not copied along with
162  // the object
163  struct vector_cache {
164  vector_cache() = default;
165  vector_cache(const vector_cache&) {}
166  vector_cache(vector_cache&&) noexcept {}
167  vector_cache& operator=(const vector_cache&) { return *this; }
168  vector_cache& operator=(vector_cache&&) noexcept { return *this; }
169 
170  mutable std::unique_ptr<LinOp> vec;
171  };
172 
173  std::shared_ptr<const LinOp> preconditioner_;
174  std::shared_ptr<const solver::Nullspace<ValueType>> nullspace_;
175  std::shared_ptr<const solver::Nullspace<ValueType>> left_nullspace_;
176  vector_cache projected_input_;
177  vector_cache result_;
178 };
179 
180 
181 } // namespace preconditioner
182 } // namespace gko
183 
184 
185 #endif // GKO_PUBLIC_CORE_PRECONDITIONER_NULLSPACE_PROJECTION_HPP_
gko::config::pnode
pnode describes a tree of properties.
Definition: property_tree.hpp:28
gko::LinOp
Definition: lin_op.hpp:117
gko::preconditioner::NullspaceProjection::get_left_nullspace
std::shared_ptr< const solver::Nullspace< ValueType > > get_left_nullspace() const
gko::Transposable
Linear operators which support transposition should implement the Transposable interface.
Definition: lin_op.hpp:492
gko::preconditioner::NullspaceProjection::Factory
Definition: nullspace_projection.hpp:122
gko::solver::Nullspace
Nullspace represents the (right or left) nullspace of an operator and is the orthogonal projector on...
Definition: nullspace.hpp:59
gko::preconditioner::NullspaceProjection::transpose
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
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:469
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:19
gko::preconditioner::NullspaceProjection::conj_transpose
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
gko::dim< 2 >
GKO_ENABLE_LIN_OP_FACTORY
#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:1094
gko::preconditioner::NullspaceProjection::get_nullspace
std::shared_ptr< const solver::Nullspace< ValueType > > get_nullspace() const
gko::preconditioner::NullspaceProjection::parse
static parameters_type parse(const config::pnode &config, const config::registry &context, const config::type_descriptor &td_for_child=config::make_type_descriptor< ValueType >())
Create the parameters from the property_tree.
gko::preconditioner::NullspaceProjection::get_preconditioner
std::shared_ptr< const LinOp > get_preconditioner() const
gko::EnableCloneable
This mixin is used to enable a default Cloneable::clone() implementation and similar for objects that...
Definition: polymorphic_object.hpp:376
gko::preconditioner::NullspaceProjection
NullspaceProjection wraps a preconditioner with projections onto the complement of a nullspace,...
Definition: nullspace_projection.hpp:50
gko::config::registry
This class stores additional context for creating Ginkgo objects from configuration files.
Definition: registry.hpp:167
GKO_ENABLE_BUILD_METHOD
#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:418
GKO_CREATE_FACTORY_PARAMETERS
#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name)
This Macro will generate a new type containing the parameters for the factory _factory_name.
Definition: abstract_factory.hpp:304