-
Notifications
You must be signed in to change notification settings - Fork 1
/
EFIT2D-VISCO.cl
376 lines (248 loc) · 11.6 KB
/
EFIT2D-VISCO.cl
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/** Source Input Kernel
*/
__kernel void Source_EFIT2D( __global float *Txx,__global float *Tyy, __global const int *XL, __global const int *YL, const float source){
uint i = get_global_id(0);
Txx[ind(XL[i],YL[i])] -= source;
Tyy[ind(XL[i],YL[i])] -= source;
}
/** Receiver Kernel
*/
__kernel void Receiver_EFIT2D( __global float *Txx, __global float *receiver, const int t,
__global const int *XXL, __global const int *YYL){
__private float _tmp = 0.0f;
for (int i=0; i<get_global_size(0); ++i)
{
_tmp += Txx[ind(XXL[i],YYL[i])];
}
receiver[t] = _tmp/(float)get_global_size(0);
}
/** Velocity Kernel (Global Memory) for Viscoelastic Case
*/
__kernel void Velocity_EFIT2D_Voigt( __global float *Txx, __global float *Txy, __global float *Tyy,
__global float *vx, __global float *vy,
__global float *dvx, __global float *dvy,
__global const float *BX, __global const float *BY,
__global const float *ABS){
int j = get_global_id(0);
int i = get_global_id(1);
if (i < MRI-1 && j>0){
dvx[ind(i,j)] = (BX[ind(i,j)]*ddx)*( Txx[ind(i+1,j)] - Txx[ind(i,j)] + Txy[ind(i,j)] - Txy[ind(i,j-1)] );
vx[ind(i,j)] += dt*dvx[ind(i,j)];
}
if (i > 0 && j< NRI-1){
dvy[ind(i,j)] = (BY[ind(i,j)]*ddx)*( Txy[ind(i,j)] - Txy[ind(i-1,j)] + Tyy[ind(i,j+1)] - Tyy[ind(i,j)] );
vy[ind(i,j)] += dt*dvy[ind(i,j)];
}
barrier(CLK_GLOBAL_MEM_FENCE);
// Apply absorbing boundary conditions
vx[ind(i,j)] *= ABS[ind(i,j)];
vy[ind(i,j)] *= ABS[ind(i,j)];
}
/** Stress Kernel (Global Memory) for Viscoelastic Case
*/
__kernel void Stress_EFIT2D_Voigt(__global float *Txx, __global float *Txy, __global float *Tyy,
__global float *vx, __global float *vy,
__global float *dvx, __global float *dvy,
__global const float *C11, __global const float *C12, __global const float *C44,
__global const float *ETA_VS, __global const float *ETA_S, __global const float *ETA_SS,
__global const float *ABS) {
int j = get_global_id(0);
int i = get_global_id(1);
if (i>0 && j>0 ){
Txx[ind(i,j)] += ( ( C11[ind(i,j)]* dtx )*(vx[ind(i,j)] - vx[ind(i-1,j)]) +
( C12[ind(i,j)]* dtx )*(vy[ind(i,j)] - vy[ind(i,j-1)]) +
( (ETA_VS[ind(i,j)])*dtx) * (dvx[ind(i,j)] - dvx[ind(i-1,j)]) +
( (ETA_S [ind(i,j)])*dtx) * (dvy[ind(i,j)] - dvy[ind(i,j-1)]) );
Tyy[ind(i,j)] += ( ( C12[ind(i,j)]* dtx )*(vx[ind(i,j)] - vx[ind(i-1,j)]) +
( C11[ind(i,j)]* dtx )*(vy[ind(i,j)] - vy[ind(i,j-1)]) +
( (ETA_VS[ind(i,j)])*dtx) *(dvy[ind(i,j)] - dvy[ind(i,j-1)]) +
( (ETA_S [ind(i,j)])*dtx) * (dvx[ind(i,j)] - dvx[ind(i-1,j)]) );
}
if (i<MRI-1 && j<NRI-1){
Txy[ind(i,j)] += ( ( C44[ind(i,j)] * dtx )*(vx[ind(i,j+1)] - vx[ind(i,j)] + vy[ind(i+1,j)] - vy[ind(i,j)]) +
( ETA_SS[ind(i,j)] * dtx )*(dvx[ind(i,j+1)] - dvx[ind(i,j)] + dvy[ind(i+1,j)] - dvy[ind(i,j)] ) );
}
barrier(CLK_GLOBAL_MEM_FENCE);
Txx[ind(i,j)] *= ABS[ind(i,j)];
Tyy[ind(i,j)] *= ABS[ind(i,j)];
Txy[ind(i,j)] *= ABS[ind(i,j)];
}
/** Velocity Kernel (Local Memory) for Viscoelastic Case
*/
__kernel void Velocity_Local_Voigt(__global float *Txx, __global float *Txy, __global float *Tyy,
__global float *vx, __global float *vy, __global float *dvx, __global float *dvy,
__global const float *BX, __global const float *BY, __global const float *ABS){
__local float local_Txx[DimLocalX+Stencil][DimLocalY+Stencil];
__local float local_Txy[DimLocalX+Stencil][DimLocalY+Stencil];
__local float local_Tyy[DimLocalX+Stencil][DimLocalY+Stencil];
uint halo = Stencil/2;
uint j = get_group_id(0) * get_local_size(0) + get_local_id(0);
uint i = get_group_id(1) * get_local_size(1) + get_local_id(1);
uint iBlock = get_local_id(1)+halo;
uint jBlock = get_local_id(0)+halo;
uint iField = i + halo;
uint jField = j + halo;
float D_Txx = 0.0f;
float Dx_Txy = 0.0f;
float Dy_Txy = 0.0f;
float D_Tyy = 0.0f;
float tabs, tdvx, tdvy, tvx, tvy;
if (i < MRI - Stencil && j < NRI - Stencil ){
barrier(CLK_LOCAL_MEM_FENCE);
// fill left halo of local memory
if (get_local_id(0) < halo )
{
local_Txx[iBlock][jBlock-halo] = Txx[iField*NRI + jField - halo];
local_Tyy[iBlock][jBlock-halo] = Tyy[iField*NRI + jField - halo];
local_Txy[iBlock][jBlock-halo] = Txy[iField*NRI + jField - halo];
}
// fill right halo of local memory
if (get_local_id(0) > DimLocalY - halo -1 )
{
local_Txx[iBlock][jBlock+halo] = Txx[iField*NRI + jField + halo];
local_Tyy[iBlock][jBlock+halo] = Tyy[iField*NRI + jField + halo];
local_Txy[iBlock][jBlock+halo] = Txy[iField*NRI + jField + halo];
}
// fill bottom halo of local memory
if (get_local_id(1) < halo )
{
local_Txx[iBlock-halo][jBlock] = Txx[(iField-halo)*NRI + jField];
local_Tyy[iBlock-halo][jBlock] = Tyy[(iField-halo)*NRI + jField];
local_Txy[iBlock-halo][jBlock] = Txy[(iField-halo)*NRI + jField];
}
// fill top halo of local memory
if (get_local_id(1) > DimLocalX - halo -1 )
{
local_Txx[iBlock+halo][jBlock] = Txx[(iField+halo)*NRI + jField];
local_Tyy[iBlock+halo][jBlock] = Tyy[(iField+halo)*NRI + jField];
local_Txy[iBlock+halo][jBlock] = Txy[(iField+halo)*NRI + jField];
}
local_Txx[iBlock][jBlock] = Txx[iField*NRI + jField];
local_Tyy[iBlock][jBlock] = Tyy[iField*NRI + jField];
local_Txy[iBlock][jBlock] = Txy[iField*NRI + jField];
barrier(CLK_LOCAL_MEM_FENCE);
D_Txx = 0.0f;
Dx_Txy = 0.0f;
Dy_Txy = 0.0f;
D_Tyy = 0.0f;
if (j!=0){
Dy_Txy = local_Txy[iBlock][jBlock] - local_Txy[iBlock][jBlock-1];
}
if (i!=0){
Dx_Txy = local_Txy[iBlock][jBlock] - local_Txy[iBlock-1][jBlock];
}
D_Txx = local_Txx[iBlock+1][jBlock] - local_Txx[iBlock][jBlock];
D_Tyy = local_Tyy[iBlock][jBlock+1] - local_Tyy[iBlock][jBlock];
tvx = vx[iField*NRI + jField];
tvy = vy[iField*NRI + jField];
tdvx = (BX[iField*NRI+jField]*(ddx))*( D_Txx + Dy_Txy);
tvx += tdvx*dt;
tdvy = (BY[iField*NRI+jField]*(ddx))*( Dx_Txy + D_Tyy);
tvy += tdvy*dt;
tabs = ABS[iField*NRI + jField];
dvx[iField*NRI + jField] = tdvx;
dvy[iField*NRI + jField] = tdvy;
vx[iField*NRI + jField] = tvx*tabs;
vy[iField*NRI + jField] = tvy*tabs;
}
}
/** Stress Kernel (Local Memory) for Viscoelastic Case
*/
__kernel void Stress_Local_Voigt(__global float *Txx, __global float *Txy, __global float *Tyy,
__global float *vx, __global float *vy, __global float *dvx, __global float *dvy,
__global const float *C11, __global const float *C12, __global const float *C44,
__global const float *ETA_VS, __global const float *ETA_S, __global const float *ETA_SS,
__global const float *ABS){
__local float local_vx[DimLocalX+Stencil][DimLocalY+Stencil];
__local float local_vy[DimLocalX+Stencil][DimLocalY+Stencil];
__local float local_dvx[DimLocalX+Stencil][DimLocalY+Stencil];
__local float local_dvy[DimLocalX+Stencil][DimLocalY+Stencil];
uint halo = Stencil/2;
uint j = get_group_id(0) * get_local_size(0) + get_local_id(0);
uint i = get_group_id(1) * get_local_size(1) + get_local_id(1);
uint iBlock = get_local_id(1)+halo;
uint jBlock = get_local_id(0)+halo;
uint iField = i + halo;
uint jField = j + halo;
float D_vx = 0.0f;
float D_vy = 0.0f;
float Dy_vx = 0.0f;
float Dx_vy = 0.0f;
float D_dvx = 0.0f;
float D_dvy = 0.0f;
float Dy_dvx = 0.0f;
float Dx_dvy = 0.0f;
float tabs,tTxx, tTyy, tTxy;
if (i < MRI - Stencil && j < NRI - Stencil ){
barrier(CLK_LOCAL_MEM_FENCE);
// fill left halo of local memory
if (get_local_id(0) < halo )
{
local_vx[iBlock][jBlock-halo] = vx[iField*NRI + jField - halo];
local_vy[iBlock][jBlock-halo] = vy[iField*NRI + jField - halo];
local_dvx[iBlock][jBlock-halo] = dvx[iField*NRI + jField - halo];
local_dvy[iBlock][jBlock-halo] = dvy[iField*NRI + jField - halo];
}
// fill right halo of local memory
if (get_local_id(0) > DimLocalY - halo -1 )
{
local_vx[iBlock][jBlock+halo] = vx[iField*NRI + jField + halo];
local_vy[iBlock][jBlock+halo] = vy[iField*NRI + jField + halo];
local_dvx[iBlock][jBlock+halo] = dvx[iField*NRI + jField + halo];
local_dvy[iBlock][jBlock+halo] = dvy[iField*NRI + jField + halo];
}
// fill bottom halo of local memory
if (get_local_id(1) < halo )
{
local_vx[iBlock-halo][jBlock] = vx[(iField-halo)*NRI + jField];
local_vy[iBlock-halo][jBlock] = vy[(iField-halo)*NRI + jField];
local_dvx[iBlock-halo][jBlock] = dvx[(iField-halo)*NRI + jField];
local_dvy[iBlock-halo][jBlock] = dvy[(iField-halo)*NRI + jField];
}
// fill top halo of local memory
if (get_local_id(1) > DimLocalX - halo -1 )
{
local_vx[iBlock+halo][jBlock] = vx[(iField+halo)*NRI + jField];
local_vy[iBlock+halo][jBlock] = vy[(iField+halo)*NRI + jField];
local_dvx[iBlock+halo][jBlock] = dvx[(iField+halo)*NRI + jField];
local_dvy[iBlock+halo][jBlock] = dvy[(iField+halo)*NRI + jField];
}
local_vx[iBlock][jBlock] = vx[iField*NRI + jField];
local_vy[iBlock][jBlock] = vy[iField*NRI + jField];
local_dvx[iBlock][jBlock] = dvx[iField*NRI + jField];
local_dvy[iBlock][jBlock] = dvy[iField*NRI + jField];
barrier(CLK_LOCAL_MEM_FENCE);
D_vx = 0.0f;
D_vy = 0.0f;
Dy_vx = 0.0f;
Dx_vy = 0.0f;
if (i!= 0){
D_vx = local_vx[iBlock][jBlock]- local_vx[iBlock-1][jBlock];
D_dvx = local_dvx[iBlock][jBlock]- local_dvx[iBlock-1][jBlock];
}
if (j!=0){
D_vy = local_vy[iBlock][jBlock] - local_vy[iBlock][jBlock-1];
D_dvy = local_dvy[iBlock][jBlock]- local_dvy[iBlock][jBlock-1];
}
Dy_vx = local_vx[iBlock][jBlock+1] - local_vx[iBlock][jBlock];
Dx_vy = local_vy[iBlock+1][jBlock] - local_vy[iBlock][jBlock];
Dy_dvx = local_dvx[iBlock][jBlock+1] - local_dvx[iBlock][jBlock];
Dx_dvy = local_dvy[iBlock+1][jBlock] - local_dvy[iBlock][jBlock];
tTxx = Txx[iField*NRI + jField];
tTyy = Tyy[iField*NRI + jField];
tTxy = Txy[iField*NRI + jField];
tTxx += ( (C11[iField*NRI+jField]*dtx)*D_vx +
( C12[iField*NRI+jField]*dtx)*D_vy +
((ETA_VS[iField*NRI + jField])*dtx)*D_dvx +
((ETA_S[iField*NRI + jField])*dtx)*D_dvy );
tTyy += ( (C12[iField*NRI+jField]*dtx)*D_vx +
( C11[iField*NRI+jField]*dtx)*D_vy +
((ETA_VS[iField*NRI + jField])*dtx)*D_dvy +
((ETA_S[iField*NRI + jField])*dtx)*D_dvx );
tTxy += ( C44[iField*NRI+jField]*dtx)*( Dx_vy + Dy_vx ) + (ETA_SS[iField*NRI + jField]*dtx)*( Dx_dvy + Dy_dvx );
tabs = ABS[iField*NRI + jField];
Txx[iField*NRI + jField] = tTxx * tabs;
Tyy[iField*NRI + jField] = tTyy * tabs;
Txy[iField*NRI + jField] = tTxy * tabs;
}
}