RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
gmres_base.h
1//
2// Created by RainSure on 2024/2/13.
3//
4
5#ifndef RSMESH_GMRES_BASE_H
6#define RSMESH_GMRES_BASE_H
7
8#include "Eigen/Core"
9#include "linear_operator.h"
10#include "types.h"
11#include <vector>
12
13namespace rsmesh::krylov {
14 class gmres_base {
15 public:
16 static bool print_progress;
17
18 virtual ~gmres_base() = default;
19
20 gmres_base(const gmres_base &) = delete;
21
22 gmres_base(gmres_base &&) = delete;
23
24 gmres_base &operator=(const gmres_base &) = delete;
25
26 gmres_base &operator=(gmres_base &&) = delete;
27
28 [[nodiscard]] double absolute_residual() const;
29
30 [[nodiscard]] bool converged() const;
31
32 virtual void iterate_process() = 0;
33
34 [[nodiscard]] index_t iteration_count() const;
35
36 [[nodiscard]] index_t max_iterations() const;
37
38 [[nodiscard]] double relative_residual() const;
39
40 virtual void set_left_preconditioner(const linear_operator &left_preconditioner);
41
42 void set_initial_solution(const valuesd &x0);
43
44 virtual void set_right_preconditioner(const linear_operator &right_preconditioner);
45
46 virtual void setup();
47
48 virtual valuesd solution_vector() const;
49
50 // tolerance: Tolerance of the relative residual (stopping criterion).
51 void solve(double tolerance);
52
53 protected:
54 gmres_base(const linear_operator &op, const valuesd &rhs, index_t max_iter);
55
56 virtual void add_preconditioned_krylov_basis(const valuesd & /*z*/) {}
57
58 [[nodiscard]] valuesd left_preconditioned(const valuesd &x) const;
59
60 [[nodiscard]] valuesd right_preconditioned(const valuesd &x) const;
61
62 const linear_operator &op_;
63
64 // Dimension.
65 const index_t m_;
66
67 // Maximum # of iteration.
68 const index_t max_iter_;
69
70 // Initial solution.
71 valuesd x0_;
72
73 // Left preconditioner.
74 const linear_operator *left_pc_{};
75
76 // Right preconditioner.
77 const linear_operator *right_pc_{};
78
79 // Current # of iteration.
80 index_t iter_{};
81
82 // Constant (right-hand side) vector.
83 const valuesd rhs_;
84
85 // L2 norm of rhs.
86 double rhs_norm_;
87
88 // Orthonormal basis vectors for the Krylov subspace.
89 std::vector<valuesd> vs_;
90
91 // Upper triangular matrix of QR decomposition.
92 Eigen::MatrixXd r_;
93
94 // Cosines for the Givens rotations.
95 valuesd c_;
96
97 // Sines for the Givens rotations.
98 valuesd s_;
99
100 // Sequence of residuals.
101 valuesd g_;
102
103 bool converged_{};
104 };
105} // namespace rsmesh::krylov
106
107#endif //RSMESH_GMRES_BASE_H