Ginkgo Generated from branch based on main. Ginkgo version 1.10.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
multigrid_level.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 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
19namespace gko {
25namespace multigrid {
26
27
39public:
45 virtual std::shared_ptr<const LinOp> get_fine_op() const = 0;
46
52 virtual std::shared_ptr<const LinOp> get_restrict_op() const = 0;
53
59 virtual std::shared_ptr<const LinOp> get_coarse_op() const = 0;
60
66 virtual std::shared_ptr<const LinOp> get_prolong_op() const = 0;
67};
68
69
80template <typename ValueType>
81class EnableMultigridLevel : public MultigridLevel,
82 public UseComposition<ValueType> {
83public:
84 using value_type = ValueType;
85
86 std::shared_ptr<const LinOp> get_fine_op() const override
87 {
88 return fine_op_;
89 }
90
91 std::shared_ptr<const LinOp> get_restrict_op() const override
92 {
93 return this->get_operator_at(2);
94 }
95
96 std::shared_ptr<const LinOp> get_coarse_op() const override
97 {
98 return this->get_operator_at(1);
99 }
100
101 std::shared_ptr<const LinOp> get_prolong_op() const override
102 {
103 return this->get_operator_at(0);
104 }
105
106protected:
115 void set_multigrid_level(std::shared_ptr<const LinOp> prolong_op,
116 std::shared_ptr<const LinOp> coarse_op,
117 std::shared_ptr<const LinOp> restrict_op)
118 {
119 gko::dim<2> mg_size{prolong_op->get_size()[0],
120 restrict_op->get_size()[1]};
121 GKO_ASSERT_EQUAL_DIMENSIONS(fine_op_->get_size(), mg_size);
122 // check mg_size is the same as fine_size
123 this->set_composition(prolong_op, coarse_op, restrict_op);
124 }
125
132 void set_fine_op(std::shared_ptr<const LinOp> fine_op)
133 {
134 GKO_ASSERT_EQUAL_DIMENSIONS(fine_op_->get_size(), fine_op->get_size());
135 fine_op_ = fine_op;
136 }
137
138 explicit EnableMultigridLevel() {}
139
149 explicit EnableMultigridLevel(std::shared_ptr<const LinOp> fine_op)
150 : fine_op_(fine_op)
151 {}
152
153private:
154 std::shared_ptr<const LinOp> fine_op_;
155};
156
157
158} // namespace multigrid
159} // namespace gko
160
161
162#endif // GKO_PUBLIC_CORE_MULTIGRID_MULTIGRID_LEVEL_HPP_
The UseComposition class can be used to store the composition information in LinOp.
Definition composition.hpp:178
std::shared_ptr< const LinOp > get_operator_at(size_type index) const
Definition composition.hpp:203
std::shared_ptr< const LinOp > get_prolong_op() const override
Returns the prolong operator.
Definition multigrid_level.hpp:101
std::shared_ptr< const LinOp > get_restrict_op() const override
Returns the restrict operator.
Definition multigrid_level.hpp:91
std::shared_ptr< const LinOp > get_coarse_op() const override
Returns the operator on coarse level.
Definition multigrid_level.hpp:96
std::shared_ptr< const LinOp > get_fine_op() const override
Returns the operator on fine level.
Definition multigrid_level.hpp:86
This class represents two levels in a multigrid hierarchy.
Definition multigrid_level.hpp:38
virtual std::shared_ptr< const LinOp > get_prolong_op() const =0
Returns the prolong operator.
virtual std::shared_ptr< const LinOp > get_fine_op() const =0
Returns the operator on fine level.
virtual std::shared_ptr< const LinOp > get_restrict_op() const =0
Returns the restrict operator.
virtual std::shared_ptr< const LinOp > get_coarse_op() const =0
Returns the operator on coarse level.
The multigrid components namespace.
Definition matrix.hpp:36
The Ginkgo namespace.
Definition abstract_factory.hpp:20
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:26