Ginkgo  Generated from pipelines/2837190956 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
multigrid_level.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_MULTIGRID_MULTIGRID_LEVEL_HPP_
6 #define GKO_PUBLIC_CORE_MULTIGRID_MULTIGRID_LEVEL_HPP_
7 
8 
9 #include <functional>
10 #include <memory>
11 
12 #include <ginkgo/core/base/abstract_factory.hpp>
13 #include <ginkgo/core/base/composition.hpp>
14 #include <ginkgo/core/base/exception_helpers.hpp>
15 #include <ginkgo/core/base/lin_op.hpp>
16 #include <ginkgo/core/base/utils.hpp>
17 
18 
19 namespace gko {
24 namespace multigrid {
25 
26 
38 public:
44  virtual std::shared_ptr<const LinOp> get_fine_op() const = 0;
45 
51  virtual std::shared_ptr<const LinOp> get_restrict_op() const = 0;
52 
58  virtual std::shared_ptr<const LinOp> get_coarse_op() const = 0;
59 
65  virtual std::shared_ptr<const LinOp> get_prolong_op() const = 0;
66 };
67 
68 
79 template <typename ValueType>
81  public UseComposition<ValueType> {
82 public:
83  using value_type = ValueType;
84 
85  std::shared_ptr<const LinOp> get_fine_op() const override
86  {
87  return fine_op_;
88  }
89 
90  std::shared_ptr<const LinOp> get_restrict_op() const override
91  {
92  return this->get_operator_at(2);
93  }
94 
95  std::shared_ptr<const LinOp> get_coarse_op() const override
96  {
97  return this->get_operator_at(1);
98  }
99 
100  std::shared_ptr<const LinOp> get_prolong_op() const override
101  {
102  return this->get_operator_at(0);
103  }
104 
105 protected:
114  void set_multigrid_level(std::shared_ptr<const LinOp> prolong_op,
115  std::shared_ptr<const LinOp> coarse_op,
116  std::shared_ptr<const LinOp> restrict_op)
117  {
118  gko::dim<2> mg_size{prolong_op->get_size()[0],
119  restrict_op->get_size()[1]};
120  GKO_ASSERT_EQUAL_DIMENSIONS(fine_op_->get_size(), mg_size);
121  // check mg_size is the same as fine_size
122  this->set_composition(prolong_op, coarse_op, restrict_op);
123  }
124 
131  void set_fine_op(std::shared_ptr<const LinOp> fine_op)
132  {
133  GKO_ASSERT_EQUAL_DIMENSIONS(fine_op_->get_size(), fine_op->get_size());
134  fine_op_ = fine_op;
135  }
136 
137  explicit EnableMultigridLevel() {}
138 
148  explicit EnableMultigridLevel(std::shared_ptr<const LinOp> fine_op)
149  : fine_op_(fine_op)
150  {}
151 
152 private:
153  std::shared_ptr<const LinOp> fine_op_;
154 };
155 
156 
157 } // namespace multigrid
158 } // namespace gko
159 
160 
161 #endif // GKO_PUBLIC_CORE_MULTIGRID_MULTIGRID_LEVEL_HPP_
gko::UseComposition
The UseComposition class can be used to store the composition information in LinOp.
Definition: composition.hpp:178
gko::multigrid::EnableMultigridLevel::get_fine_op
std::shared_ptr< const LinOp > get_fine_op() const override
Returns the operator on fine level.
Definition: multigrid_level.hpp:85
gko::multigrid::MultigridLevel::get_restrict_op
virtual std::shared_ptr< const LinOp > get_restrict_op() const =0
Returns the restrict operator.
gko::multigrid::EnableMultigridLevel::get_prolong_op
std::shared_ptr< const LinOp > get_prolong_op() const override
Returns the prolong operator.
Definition: multigrid_level.hpp:100
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::multigrid::MultigridLevel::get_prolong_op
virtual std::shared_ptr< const LinOp > get_prolong_op() const =0
Returns the prolong operator.
gko::multigrid::EnableMultigridLevel
The EnableMultigridLevel gives the default implementation of MultigridLevel with composition and prov...
Definition: multigrid_level.hpp:80
gko::dim< 2 >
gko::multigrid::EnableMultigridLevel::get_restrict_op
std::shared_ptr< const LinOp > get_restrict_op() const override
Returns the restrict operator.
Definition: multigrid_level.hpp:90
gko::multigrid::MultigridLevel
This class represents two levels in a multigrid hierarchy.
Definition: multigrid_level.hpp:37
gko::UseComposition::get_operator_at
std::shared_ptr< const LinOp > get_operator_at(size_type index) const
Returns the operator at index-th position of composition.
Definition: composition.hpp:203
gko::multigrid::EnableMultigridLevel::get_coarse_op
std::shared_ptr< const LinOp > get_coarse_op() const override
Returns the operator on coarse level.
Definition: multigrid_level.hpp:95
gko::multigrid::MultigridLevel::get_coarse_op
virtual std::shared_ptr< const LinOp > get_coarse_op() const =0
Returns the operator on coarse level.
gko::multigrid::MultigridLevel::get_fine_op
virtual std::shared_ptr< const LinOp > get_fine_op() const =0
Returns the operator on fine level.