-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultigrid.hpp
61 lines (47 loc) · 1.46 KB
/
multigrid.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef __MULTIGRID_H_
#define __MULTIGRID_H_
#include <Eigen/Sparse>
#include <Eigen/Dense>
#include <vector>
#include "enums.hpp"
#include "solver.hpp"
using namespace Eigen;
class Level {
public:
Level(int level, int imax, int jmax, double dx, double dy, matrix<cell_type>& types);
Level(int level, int imax, int jmax, double dx, double dy, matrix<cell_type>& types_, MatrixXd& p, MatrixXd& rhs);
MatrixXd& x();
MatrixXd& b();
MatrixXd& e();
MatrixXd& res();
matrix<cell_type>& types();
private:
friend class Multigrid;
int level;
int imax;
int jmax;
double dx;
double dy;
matrix<cell_type>* _types;
MatrixXd* _x = nullptr;
MatrixXd* _b = nullptr;
MatrixXd* _e = nullptr;
MatrixXd* _res = nullptr;
};
class Multigrid: public Solver {
public:
Multigrid(Config& config, MatrixXd& p, MatrixXd& rhs, matrix<cell_type>& types);
void solve(int& it, double& res);
Level& levels(int l);
private:
MatrixXd _residual;
FullPivLU<MatrixXd>_solver;
MatrixXd _A;
std::vector<Level*> _levels;
void v_cycle(int level);
void smoothing(MatrixXd& x, MatrixXd& b, matrix<cell_type>& types, double dx, double dy, bool boundary);
void restriction_fullweight(MatrixXd& fine, MatrixXd& coarse);
void prolongate(MatrixXd& fine, MatrixXd& coarse);
void gaussSeidel(MatrixXd &P, MatrixXd &RS, matrix<cell_type>& _types, double dx, double dy);
};
#endif