-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmultigridsolver3D.h
96 lines (74 loc) · 2.54 KB
/
multigridsolver3D.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MULTIGRIDSOLVER1_H
#define MULTIGRIDSOLVER1_H
#include "buffer.h"
class BorderHandler3D
{
public:
enum CellType { CellInner,CellOuter,CellDirichlet,CellNeumann };
virtual void setarg(int arg,cl::Kernel & ker,int dimx,int dimy,int dimz) = 0;
virtual CellType cellType(int x,int y,int z,int dimx,int dimy,int dimz) const = 0;
private:
};
class MultigridSolver3D
{
public:
MultigridSolver3D(const char * filename,BorderHandler3D & handl);
Buffer3D iterate(Buffer3D & in,
const Buffer3D & func,
real omega = 2.0/3.0,
int a1 = 4,
int a2 = 4,
int v = 1);
Buffer3D mg(Buffer3D & in,
const Buffer3D & func,
real omega = 2.0/3.0,
int a1 = 4,
int a2 = 4,
int v = 1,
int iters = 3) {
for (int i=0;i < iters;++i)
iterate(in,func,omega,a1,a2,v);
return in;
}
Buffer3D fmg(const Buffer3D & func,
real omega = 2.0/3.0,
int a1 = 4,
int a2 = 4,
int v = 1,
int iters = 3);
void wait() { m_queue.finish();}
cl::CommandQueue & queue() {return m_queue;}
void smoother_iterate(Buffer3D& res, const Buffer3D& func, real omega, int a1);
void compute_residuals(Buffer3D& res,const Buffer3D & input, const Buffer3D& func);
void restrict(Buffer3D& res,const Buffer3D & input);
void correct_residual(Buffer3D & res,const Buffer3D & input,Buffer3D & residual);
void prolongate(Buffer3D & res,const Buffer3D & input);
void zero_mem(Buffer3D & res);
void zero_out(Buffer3D & res);
private:
cl::Program m_theProgram;
cl::Kernel m_iterationKernel;
cl::Kernel m_residualKernel;
cl::Kernel m_reductionKernel;
cl::Kernel m_residualCorrectKernel;
cl::Kernel m_prolongationKernel;
cl::Kernel m_zeroOutKernel;
cl::Buffer m_emptyBuf;
cl::CommandQueue m_queue;
BorderHandler3D & m_Handl;
};
#endif // MULTIGRIDSOLVER1_H