Ginkgo  Generated from pipelines/3136675824 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
nullspace.hpp
1 // SPDX-FileCopyrightText: 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_SOLVER_NULLSPACE_HPP_
6 #define GKO_PUBLIC_CORE_SOLVER_NULLSPACE_HPP_
7 
8 
9 #include <memory>
10 #include <vector>
11 
12 #include <ginkgo/core/base/array.hpp>
13 #include <ginkgo/core/base/dense_cache.hpp>
14 #include <ginkgo/core/base/lin_op.hpp>
15 #include <ginkgo/core/base/math.hpp>
16 #include <ginkgo/core/base/polymorphic_object.hpp>
17 #include <ginkgo/core/base/utils.hpp>
18 #include <ginkgo/core/matrix/dense.hpp>
19 
20 
21 namespace gko {
22 namespace solver {
23 
24 
58 template <typename ValueType = default_precision>
59 class Nullspace : public LinOp, public EnableCloneable<Nullspace<ValueType>> {
60  friend class EnableCloneable<Nullspace>;
61  GKO_ASSERT_SUPPORTED_VALUE_TYPE;
62 
63 public:
66 
67  using value_type = ValueType;
68  using absolute_type = remove_complex<ValueType>;
69 
84  static std::unique_ptr<Nullspace> create(
85  std::shared_ptr<const Executor> exec,
86  std::vector<std::shared_ptr<const AbstractMultiVector>> basis,
87  bool contains_constant = false);
88 
104  static std::unique_ptr<Nullspace> create_from_constant(
105  std::shared_ptr<const Executor> exec, dim<2> size = {});
106 
108  bool contains_constant() const noexcept;
109 
114  size_type get_dimension() const noexcept;
115 
121  std::shared_ptr<const AbstractMultiVector> get_basis() const noexcept;
122 
134 
135  Nullspace& operator=(const Nullspace& other);
136 
137  Nullspace& operator=(Nullspace&& other);
138 
139  Nullspace(const Nullspace& other);
140 
141  Nullspace(Nullspace&& other);
142 
143 protected:
144  explicit Nullspace(std::shared_ptr<const Executor> exec);
145 
146  Nullspace(std::shared_ptr<const Executor> exec, dim<2> size,
147  std::vector<std::shared_ptr<const AbstractMultiVector>> basis,
148  bool contains_constant);
149 
150  void apply_impl(const AbstractMultiVector* b,
151  AbstractMultiVector* x) const override;
152 
153  void apply_impl(const AbstractMultiVector* alpha,
154  const AbstractMultiVector* b,
155  const AbstractMultiVector* beta,
156  AbstractMultiVector* x) const override;
157 
158 private:
159  void setup_basis(
160  const std::vector<std::shared_ptr<const AbstractMultiVector>>& basis);
161 
162  // stores [mean(v); V^H v] in coefficients_
163  void compute_components(const AbstractMultiVector* v,
164  const AbstractMultiVector* basis,
165  bool has_constant) const;
166 
167  // result = v - mean - V C with the coefficients from compute_components;
168  // result may be v
169  void subtract_components(const AbstractMultiVector* v,
170  AbstractMultiVector* result,
171  const AbstractMultiVector* basis_local,
172  bool has_constant) const;
173 
174  void remove_components(AbstractMultiVector* v,
175  const AbstractMultiVector* basis_local,
176  bool has_constant) const;
177 
178  bool contains_constant_;
179  // orthonormal explicit basis (n x k), MultiVector or distributed::Vector
180  std::shared_ptr<const AbstractMultiVector> basis_;
181  // scratch: (1 + k) x nrhs coefficients (means, then V^H x)
182  gko::detail::DenseCache<ValueType> coefficients_;
183  gko::detail::DenseCache<ValueType> host_coefficients_;
184  mutable array<char> reduction_tmp_;
185 };
186 
187 
188 namespace detail {
189 
190 
205 template <typename ValueType>
206 std::shared_ptr<const Nullspace<ValueType>> prepare_nullspace(
207  std::shared_ptr<const LinOp> param, const char* name, const LinOp* op,
208  size_type size, std::shared_ptr<const Executor> exec);
209 
210 
211 } // namespace detail
212 } // namespace solver
213 } // namespace gko
214 
215 
216 #endif // GKO_PUBLIC_CORE_SOLVER_NULLSPACE_HPP_
gko::solver::Nullspace::create
static std::unique_ptr< Nullspace > create(std::shared_ptr< const Executor > exec, std::vector< std::shared_ptr< const AbstractMultiVector >> basis, bool contains_constant=false)
Creates a Nullspace from an explicit basis.
gko::log::profile_event_category::solver
Solver events.
gko::LinOp
Definition: lin_op.hpp:163
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:102
gko::solver::Nullspace
Nullspace represents the (right or left) nullspace of an operator and is the orthogonal projector on...
Definition: nullspace.hpp:59
gko::solver::Nullspace::project
void project(ptr_param< AbstractMultiVector > v) const
Applies the projector in place: , for each column of v independently.
gko::solver::Nullspace::create_from_constant
static std::unique_ptr< Nullspace > create_from_constant(std::shared_ptr< const Executor > exec, dim< 2 > size={})
Creates a Nullspace consisting only of the constant vector (e.g.
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::array< char >
gko::dim< 2 >
gko::solver::Nullspace::get_dimension
size_type get_dimension() const noexcept
gko::ptr_param
This class is used for function parameters in the place of raw pointers.
Definition: utils_helper.hpp:43
gko::solver::Nullspace::get_basis
std::shared_ptr< const AbstractMultiVector > get_basis() const noexcept
gko::solver::Nullspace::contains_constant
bool contains_constant() const noexcept
gko::EnableCloneable
This mixin is used to enable a default Cloneable::clone() implementation and similar for objects that...
Definition: polymorphic_object.hpp:372
gko::AbstractMultiVector
Abstract interface class for (multi-)vector types.
Definition: multivector.hpp:81
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:263