Ginkgo Generated from branch based on master. Ginkgo version 1.8.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
13#include <ginkgo/core/base/abstract_factory.hpp>
14#include <ginkgo/core/base/composition.hpp>
15#include <ginkgo/core/base/exception_helpers.hpp>
16#include <ginkgo/core/base/lin_op.hpp>
17#include <ginkgo/core/base/utils.hpp>
18
19
20namespace gko {
26namespace multigrid {
27
28
40public:
46 virtual std::shared_ptr<const LinOp> get_fine_op() const = 0;
47
53 virtual std::shared_ptr<const LinOp> get_restrict_op() const = 0;
54
60 virtual std::shared_ptr<const LinOp> get_coarse_op() const = 0;
61
67 virtual std::shared_ptr<const LinOp> get_prolong_op() const = 0;
68};
69
70
81template <typename ValueType>
83 public UseComposition<ValueType> {
84public:
85 using value_type = ValueType;
86
87 std::shared_ptr<const LinOp> get_fine_op() const override
88 {
89 return fine_op_;
90 }
91
92 std::shared_ptr<const LinOp> get_restrict_op() const override
93 {
94 return this->get_operator_at(2);
95 }
96
97 std::shared_ptr<const LinOp> get_coarse_op() const override
98 {
99 return this->get_operator_at(1);
100 }
101
102 std::shared_ptr<const LinOp> get_prolong_op() const override
103 {
104 return this->get_operator_at(0);
105 }
106
107protected:
116 void set_multigrid_level(std::shared_ptr<const LinOp> prolong_op,
117 std::shared_ptr<const LinOp> coarse_op,
118 std::shared_ptr<const LinOp> restrict_op)
119 {
120 gko::dim<2> mg_size{prolong_op->get_size()[0],
121 restrict_op->get_size()[1]};
122 GKO_ASSERT_EQUAL_DIMENSIONS(fine_op_->get_size(), mg_size);
123 // check mg_size is the same as fine_size
124 this->set_composition(prolong_op, coarse_op, restrict_op);
125 }
126
133 void set_fine_op(std::shared_ptr<const LinOp> fine_op)
134 {
135 GKO_ASSERT_EQUAL_DIMENSIONS(fine_op_->get_size(), fine_op->get_size());
136 fine_op_ = fine_op;
137 }
138
139 explicit EnableMultigridLevel() {}
140
150 explicit EnableMultigridLevel(std::shared_ptr<const LinOp> fine_op)
151 : fine_op_(fine_op)
152 {}
153
154private:
155 std::shared_ptr<const LinOp> fine_op_;
156};
157
158
159} // namespace multigrid
160} // namespace gko
161
162
163#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
The EnableMultigridLevel gives the default implementation of MultigridLevel with composition and prov...
Definition multigrid_level.hpp:83
std::shared_ptr< const LinOp > get_prolong_op() const override
Returns the prolong operator.
Definition multigrid_level.hpp:102
std::shared_ptr< const LinOp > get_restrict_op() const override
Returns the restrict operator.
Definition multigrid_level.hpp:92
std::shared_ptr< const LinOp > get_coarse_op() const override
Returns the operator on coarse level.
Definition multigrid_level.hpp:97
std::shared_ptr< const LinOp > get_fine_op() const override
Returns the operator on fine level.
Definition multigrid_level.hpp:87
This class represents two levels in a multigrid hierarchy.
Definition multigrid_level.hpp:39
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 Ginkgo namespace.
Definition abstract_factory.hpp:20
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:27