-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmultigrid.h
240 lines (168 loc) · 5.89 KB
/
multigrid.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//----------------------------------------------------------------------------------||
//------------------- multigrid.h -------------------||
//----------------------------------------------------------------------------------||
// ||
// __ ___ _ _ ____ ____ ___ ____ ||
// \ \ / / \ | \ | | _ \ | _ \_ _/ ___| ||
// \ \ /\ / / _ \ | \| | | | |_____| |_) | | | ||
// \ V V / ___ \| |\ | |_| |_____| __/| | |___ ||
// \_/\_/_/ \_\_| \_|____/ |_| |___\____| ||
// ||
//----------------------------------------------------------------------------------||
//-- (W)akefield (A)cceleration a(n)d (D)LA - (P)article (i)n (C)ell Simulation --||
//----------------------------------------------------------------------------------||
//---Author----------- : Tianhong Wang --------------------||
//---Starting--------- : Feb-07-2019 --------------------||
//---Email------------ : [email protected] --------------------||
//---Group------------ : Dr. Gennady Shvets' Group --------------------||
//---Copyright-------- : (C) 2019 by Tianhong Wang --------------------||
//----------------------------------------------------------------------------------||
//----------------------------------------------------------------------------------||
#ifndef H_MULTI
#define H_MULTI
#include<vector>
#include<utility>
class MG_Cell
{
friend class MultiGrid;
friend class Commute;
private:
// value at this cell
union
{
WDOUBLE M_value[1];
WDOUBLE field;
};
WDOUBLE source; //1
WDOUBLE Residu; //2
WDOUBLE savefield; //3
WDOUBLE Chi; //4
union
{
dcomplex C_value[1];
dcomplex C_field;
};
dcomplex C_source; //1
dcomplex C_Residu; //2
dcomplex C_savefield; //3
dcomplex C_Chi; //4
//point to the four cells we need to restrict from
MG_Cell *p_Res_cc;
MG_Cell *p_Res_xm;
MG_Cell *p_Res_xp;
MG_Cell *p_Res_ym;
MG_Cell *p_Res_yp;
MG_Cell *p_Res_mm;
MG_Cell *p_Res_mp;
MG_Cell *p_Res_pm;
MG_Cell *p_Res_pp;
//point to the four cells we need to prolongate from
MG_Cell *p_Pro_xm;
MG_Cell *p_Pro_xp;
MG_Cell *p_Pro_ym;
MG_Cell *p_Pro_yp;
int Protype; // four types of prolongation from 0 to 3;
int Grandidx_X;
int Grandidx_Y;
WDOUBLE dx;
WDOUBLE dy;
public:
MG_Cell();
~MG_Cell()
{;};// do not release any pointer, this class persists to the end of simulation anyway
};
class MultiGrid :public NList {
friend class Mesh;
private:
Domain *p_domain() {return Domain::p_Domain;}; // pointer to domain class.
static const int Layer_buf = 20; //Layer Number Buffer
int LayerGridX[Layer_buf];
int LayerGridY[Layer_buf];
int Layer_Sum[Layer_buf];
int MeshAmplif[Layer_buf+10];
int BLayerGrid[Layer_buf];
int BLayer_Sum[Layer_buf];
int MPI_Layer; //MPI Level layers idx starts from one !!!!!!!
int SER_Layer; //Single rank layers
int u1;
int u2;
int RelaxType;
int BottomType;
WDOUBLE dxdy;
int GridXY;
WDOUBLE EpsLim;
WDOUBLE omega;
int BottomCells; //total cells at the bottom layer without the bound cells.
int Worker;
int *Bottomdisp;
int *BottomSend;
int *recebottomX;
int *recebottomY;
int Rank;
int Xpa, Ypa;
MG_Cell* p_MGCell;
MG_Cell* p_MGBCell;
Mesh *p_Meshs;
public:
inline int GetMG_N(int i, int j, int layer)
{
return Layer_Sum[layer]+(LayerGridX[layer]+2)*j+i;
};
inline MG_Cell& GetMGCell(int i, int j, int layer)
{
return p_MGCell[GetMG_N(i,j,layer)];
};
inline int GetMGB_N(int i, int j, int layer)
{
return BLayer_Sum[layer]+(BLayerGrid[layer]+2)*j+i;
};
inline MG_Cell& GetMGBCell(int i, int j, int layer)
{
return p_MGBCell[GetMGB_N(i,j,layer)];
};
inline int GetLayerGridX(int layer)
{
return LayerGridX[layer];
};
inline int GetLayerGridY(int layer)
{
return LayerGridY[layer];
};
//======== WDOUBLE Type ==========================================
void Exchange(int what, int layer);
void Restriction(int send, int rece, int tolayer, int where);
void RestrictionB(int send, int rece, int tolayer, int where);
void Prolongation(int send, int rece, int tolayer, int where);
void SetZero(int what, int layer, int where);
void Relaxation(int field, int layer, int where);
void Residual(int field, int layer, int where);
void SendtoBottom(int what);
void BottomSendBack(int what);
void AddCorrection(int layer, int where);
void MG_BottomLayer(int field);
int MG_V_cycle(int field, WDOUBLE k0, int k);
void Put_Source(int field, WDOUBLE k0, int k);
void Put_Fields(int field, int k);
WDOUBLE FindError(WDOUBLE &maxall);
//======== Complex Type ==========================================
void RestrictionC(int send, int rece, int tolayer, int where);
void RestrictionBC(int send, int rece, int tolayer, int where);
void ProlongationC(int send, int rece, int tolayer, int where);
void SendtoBottomC(int what);
void BottomSendBackC(int what);
void MG_BottomLayerC(int field);
void RelaxationC(int field, int layer, int where);
void ResidualC(int field, int layer, int where);
void SetZeroC(int what, int layer, int where);
void ExchangeC(int what, int layer);
void AddCorrectionC(int layer, int where);
WDOUBLE FindErrorC(WDOUBLE &maxall);
void Put_SourceC(int field, int k, int NF);
void Put_FieldsC(int field, int k, int NF);
int MG_V_cycleC(int field, int k, int NF);
//====== debug ======================
void DebugWrite(int layer, int what, char *name, int where);
MultiGrid(int rank, int XGridN, int YGridN, FILE *f);
~MultiGrid();
};
#endif