suanPan
Loading...
Searching...
No Matches
Jacobi.hpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* Copyright (C) 2017-2024 Theodore Chang
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
******************************************************************************/
29
#ifndef JACOBI_HPP
30
#define JACOBI_HPP
31
32
#include "
Preconditioner.hpp
"
33
34
template
<sp_d data_t>
class
Jacobi
final :
public
Preconditioner
<data_t> {
35
const
Col<data_t> diag_reciprocal;
36
37
public
:
38
template
<
typename
Container>
explicit
Jacobi
(
const
Container& in_mat)
39
:
Preconditioner
<data_t>()
40
, diag_reciprocal(1. / Col<data_t>(in_mat.diag())) {}
41
42
[[nodiscard]] Col<data_t>
apply
(
const
Col<data_t>&)
override
;
43
};
44
45
template
<sp_d data_t> Col<data_t>
Jacobi<data_t>::apply
(
const
Col<data_t>& in) {
46
Col<data_t> out = in;
47
48
for
(
auto
I = 0llu; I < in.n_elem; I += diag_reciprocal.n_elem) out.subvec(I, arma::size(diag_reciprocal)) %= diag_reciprocal;
49
50
return
out;
51
}
52
53
#endif
54
Preconditioner.hpp
Jacobi
A Jacobi class.
Definition
Jacobi.hpp:34
Jacobi::Jacobi
Jacobi(const Container &in_mat)
Definition
Jacobi.hpp:38
Preconditioner
A Preconditioner class.
Definition
Preconditioner.hpp:34
Jacobi::apply
Col< data_t > apply(const Col< data_t > &) override
Definition
Jacobi.hpp:45
Domain
MetaMat
Jacobi.hpp
Generated by
1.10.0