Ginkgo Generated from branch based on master. Ginkgo version 1.7.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
multigrid_level.hpp
1/*******************************<GINKGO LICENSE>******************************
2Copyright (c) 2017-2023, the Ginkgo authors
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
91. Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11
122. Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the distribution.
15
163. Neither the name of the copyright holder nor the names of its
17contributors may be used to endorse or promote products derived from
18this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31******************************<GINKGO LICENSE>*******************************/
32
33#ifndef GKO_PUBLIC_CORE_MULTIGRID_MULTIGRID_LEVEL_HPP_
34#define GKO_PUBLIC_CORE_MULTIGRID_MULTIGRID_LEVEL_HPP_
35
36
37#include <functional>
38#include <memory>
39
40
41#include <ginkgo/core/base/abstract_factory.hpp>
42#include <ginkgo/core/base/composition.hpp>
43#include <ginkgo/core/base/exception_helpers.hpp>
44#include <ginkgo/core/base/lin_op.hpp>
45#include <ginkgo/core/base/utils.hpp>
46
47
48namespace gko {
54namespace multigrid {
55
56
68public:
74 virtual std::shared_ptr<const LinOp> get_fine_op() const = 0;
75
81 virtual std::shared_ptr<const LinOp> get_restrict_op() const = 0;
82
88 virtual std::shared_ptr<const LinOp> get_coarse_op() const = 0;
89
95 virtual std::shared_ptr<const LinOp> get_prolong_op() const = 0;
96};
97
98
109template <typename ValueType>
111 public UseComposition<ValueType> {
112public:
113 using value_type = ValueType;
114
115 std::shared_ptr<const LinOp> get_fine_op() const override
116 {
117 return fine_op_;
118 }
119
120 std::shared_ptr<const LinOp> get_restrict_op() const override
121 {
122 return this->get_operator_at(2);
123 }
124
125 std::shared_ptr<const LinOp> get_coarse_op() const override
126 {
127 return this->get_operator_at(1);
128 }
129
130 std::shared_ptr<const LinOp> get_prolong_op() const override
131 {
132 return this->get_operator_at(0);
133 }
134
135protected:
144 void set_multigrid_level(std::shared_ptr<const LinOp> prolong_op,
145 std::shared_ptr<const LinOp> coarse_op,
146 std::shared_ptr<const LinOp> restrict_op)
147 {
148 gko::dim<2> mg_size{prolong_op->get_size()[0],
149 restrict_op->get_size()[1]};
150 GKO_ASSERT_EQUAL_DIMENSIONS(fine_op_->get_size(), mg_size);
151 // check mg_size is the same as fine_size
152 this->set_composition(prolong_op, coarse_op, restrict_op);
153 }
154
161 void set_fine_op(std::shared_ptr<const LinOp> fine_op)
162 {
163 GKO_ASSERT_EQUAL_DIMENSIONS(fine_op_->get_size(), fine_op->get_size());
164 fine_op_ = fine_op;
165 }
166
167 explicit EnableMultigridLevel() {}
168
178 explicit EnableMultigridLevel(std::shared_ptr<const LinOp> fine_op)
179 : fine_op_(fine_op)
180 {}
181
182private:
183 std::shared_ptr<const LinOp> fine_op_;
184};
185
186
187} // namespace multigrid
188} // namespace gko
189
190
191#endif // GKO_PUBLIC_CORE_MULTIGRID_MULTIGRID_LEVEL_HPP_
The UseComposition class can be used to store the composition information in LinOp.
Definition composition.hpp:206
std::shared_ptr< const LinOp > get_operator_at(size_type index) const
Returns the operator at index-th position of composition.
Definition composition.hpp:231
The EnableMultigridLevel gives the default implementation of MultigridLevel with composition and prov...
Definition multigrid_level.hpp:111
std::shared_ptr< const LinOp > get_prolong_op() const override
Returns the prolong operator.
Definition multigrid_level.hpp:130
std::shared_ptr< const LinOp > get_restrict_op() const override
Returns the restrict operator.
Definition multigrid_level.hpp:120
std::shared_ptr< const LinOp > get_coarse_op() const override
Returns the operator on coarse level.
Definition multigrid_level.hpp:125
std::shared_ptr< const LinOp > get_fine_op() const override
Returns the operator on fine level.
Definition multigrid_level.hpp:115
This class represents two levels in a multigrid hierarchy.
Definition multigrid_level.hpp:67
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:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:55