-
Notifications
You must be signed in to change notification settings - Fork 9
/
Toa_gpu2DvtiFdRtmAdcigsLaplace.cu
1808 lines (1480 loc) · 55.5 KB
/
Toa_gpu2DvtiFdRtmAdcigsLaplace.cu
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*a*****************************************************
a* 2D Quasi Acoustic VTI Medium FD & RTM
b* P + sv wave and get rid of sv
c* GPU(CUDA) ,poynting adcigs, read shot
d*
e*******************************************************
f*
g* Ps: the Quasi Acoustic VTI function:
h*
i* du/dt=1/rho*dp/dx ,
j* dw/dt=1/rho*dq/dz ,
k* dp/dt=rho*vpx^2*du/dx+rho*vp*vpn*dw/dz ,
l* dq/dt=rho*vp*vpn*du/dx+rho*vp^2*dw/dz ,
m* vpx^2=vp^2*(1+2*epsilon);
n* vpn^2=vp^2*(1+2*delta);
o*
p*******************************************************
q* initial: 2017.02 Rong Tao
r* adcigs: 2017.04 Rong Tao
s* modify: 2018.02 Rong Tao
u* print: 2018.05 Rong Tao
v*
w*
x*
y*******************************************************
z*/
#include <stdio.h>
#include <malloc.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <cuda_runtime.h>
#define ANSI_CYAN "\x1b[36m"
#define ANSI_GREEN "\x1b[32m"
#define ANSI_RED "\x1b[31m"
#define ANSI_YELLOW "\x1b[33m"
#define ANSI_RESET "\x1b[0m"
/*print error message*/
void print_error(const char *message)
{
if(message)
printf(ANSI_RED " [Error] " ANSI_RESET "%s",message);
}
/*print warning message*/
void print_warning(const char *message)
{
if(message )
printf(ANSI_YELLOW " [Warning] "ANSI_RESET "%s",message);
}
/*printf info message*/
void print_info(const char *message)
{
if(message )
printf(ANSI_CYAN " [Info] "ANSI_RESET "%s", message);
}
/*print success message*/
void print_success(const char* message)
{
if(message )
printf(ANSI_GREEN " [Success] "ANSI_RESET "%s", message);
}
#ifdef pi
#pragma message("Already define pi !!!")
#else
#define pi 3.141592653
#endif
#define mm 4
#define Nbar 25
#define CHECK_gpu(call) { \
const cudaError_t error = call; \
char msg[1024]; \
if (error != cudaSuccess) { \
sprintf(msg, "Error in: %s:%d: ", __FILE__, __LINE__); \
print_error(msg); \
sprintf(msg, "code: %d, reason: %s\n", error, \
cudaGetErrorString(error)); \
print_error(msg); \
exit(1); \
} \
}
const char *note[] = {
"\n\033[1;31;44m 2D Quasi Acoustic VTI Medium FD & RTM (CUDA, ADCIGs) \033[m",
"\033[1;31;44m Author: Rong Tao @UPC \033[m",
" ",
" \033[1;31mQuasi Acoustic Function as follows:\033[m ",
" du/dt = dp/dx ",
" dw/dt = dq/dz ",
" dp/dt = vpx^2 * du/dx + vp*vpn * dw/dz ",
" dq/dt = vp*vpn * du/dx + vp^2 * dw/dz ",
" vpx^2 = vp^2 * (1+2*epsilon) ",
" vpn^2 = vp^2 * (1+2*delta) ",
" ",
" \033[1;31mRequired Parameters:\033[m ",
" kind =1 Finite difference forward modeling[FD] ",
" =2 Reverse Time Migration[RTM] ",
" For example: ",
" ./a.out kind=1 Finite difference forward modeling[FD] ",
" ./a.out kind=2 Reverse Time Migration[RTM] ",
" no space in 'kind=1' ",
" ",
" \033[1;31mInner Parameters:\033[m ",
" nx, dx Horizontal Space sampling point and interval ",
" nz, dz Vertical Space sampling point and interval ",
" nt, dt Time sampling point and interval ",
" favg Wavelet frequency ",
" pfac Wavelet Gain ",
" ns The number of shots ",
" fs First shot position[grid] ",
" ds Shots interval[grid] ",
" zs Shots vertical position[grid] ",
" nangle The number of ADCIGs's angle ",
" dangle The interval of ADCIGs's angle ",
" dAdcigs Output file, the interval cdp(nx) ",
" npml PML Border width[grid] ",
" ",
" \033[1;31mOptional Parameters:\033[m ",
" wtype kind of wavelet =1 ricker wavelet ",
" =2 derivative of gaussian ",
" =3 derivative of gaussian ",
" readShot =true, boolean, read obs shot ",
" =false, boolean, use accurate shot data ",
" writeSnap =true,false output snap into file or not ",
" ",
" \033[1;31mCOMMENTS\033[m ",
" Copyright (C) 2016-2018 ",
" \033[1;32mChina University of Petroleum (East China), QingDao, China\033[m ",
" Authors: \033[1;32mRong Tao \033[m ",
" Location: \033[1;32mYi Fu Building @UPC\033[m ",
" Team: \033[1;32mLEON-VEL\033[m ",
" ",
NULL
};
__device__ float d0;
__global__ void get_d0(float dx,
float dz,
int nnx,
int nnz,
int npml,
float *vp)
/* this (d0) function for pml bndr */
{
d0 = 10.0*vp[nnx*nnz/2]*log(100000.0)/(2.0*npml*((dx+dz)/2.0));
}
/*#define mm 4*/
__constant__ float c[mm]={1.196289,-0.0797526,0.009570313,-0.0006975447};
void mBar(float fBar)
/* show progress bar */
{
int i,j,k,m;
//for ( i=0;i< Nbar+6; i++ )
// printf("\b");
k = Nbar*fBar;
m = fBar*100;
printf("[");
for ( i=0;i<k;i++ )
printf("=");
for ( j=0;j<Nbar-k;j++ )
printf(" ");
printf("]%3d%%",m);
}
void check_gpu_error (const char *msg)
/* check GPU errors */
{
cudaError_t err = cudaGetLastError ();
char message[1024];
if (cudaSuccess != err) {
sprintf(message,"Cuda error: %s: %s\n", msg, cudaGetErrorString(err));
print_error(message);
exit(0);
}
print_success("Check gpu successfully.\n");
}
void laplace_filter(int adj,
int nz,
int nx,
float *in,
float *out)
/**
* linear operator
*
* Copyright@ Madagascar Mlaplac2
*/
{
int iz,ix,j;
for (j=0;j<nx*nz;j++)
out[j]=0.0;
for (ix=0; ix < nx; ix++) {
for (iz=0; iz < nz; iz++) {
j = iz+ix*nz;
if (iz > 0) {
if (adj) {
out[j-1] -= in[j];
out[j] += in[j];
} else {
out[j] += in[j] - in[j-1];
}
}
if (iz < nz-1) {
if (adj) {
out[j+1] -= in[j];
out[j] += in[j];
} else {
out[j] += in[j] - in[j+1];
}
}
if (ix > 0) {
if (adj) {
out[j-nz] -= in[j];
out[j] += in[j];
} else {
out[j] += in[j] - in[j-nz];
}
}
if (ix < nx-1) {
if (adj) {
out[j+nz] -= in[j];
out[j] += in[j];
} else {
out[j] += in[j] - in[j+nz];
}
}
}
}
}
__global__ void add_source( float pfac,
float xsn,
float zsn,
int nx,
int nz,
int nnx,
int nnz,
float dt,
float t,
float favg,
int wtype,
int npml,
int is,
int ds,
float *P,
float *Q)
/* generate ricker wavelet with time deley */
{
int ixs,izs;
float x_,xx_,tdelay,ts,source=0.0,fs;
tdelay = 1.0/favg;
ts = t-tdelay;
fs = xsn+(is-1)*ds;
if(wtype==1)//ricker wavelet
{
x_ = favg*ts;
xx_ = x_*x_;
source=(1-2*pi*pi*(xx_))*exp(-(pi*pi*xx_));
}else if(wtype==2){//derivative of gaussian
x_ = (-4)*favg*favg*pi*pi/log(0.1);
source = (-2)*pi*pi*ts*exp(-x_*ts*ts);
}else if(wtype==3){//derivative of gaussian
x_ = (-1)*favg*favg*pi*pi/log(0.1);
source = exp(-x_*ts*ts);
}
if(t <= 2*tdelay)
{
ixs = (int)( fs + 0.5) + npml - 1;
izs = (int)(zsn + 0.5) + npml - 1;
P[ixs*nnz+izs] += pfac * source;
Q[ixs*nnz+izs] += pfac * source;
}
}
__global__ void update_vel(int nx,
int nz,
int nnx,
int nnz,
int npml,
float dt,
float dx,
float dz,
float *u0,
float *w0,
float *u1,
float *w1,
float *P,
float *Q,
float *coffx1,
float *coffx2,
float *coffz1,
float *coffz2)
{
int id=threadIdx.x+blockDim.x*blockIdx.x;
int ix,iz,im;
float dtx,dtz,xx,zz;
ix = id/nnz;
iz = id%nnz;
dtx = dt/dx;
dtz = dt/dz;
if(id >= mm && id < nnx*nnz - mm) {
if(ix >= mm && ix<(nnx-mm) && iz >= mm && iz<(nnz-mm)) {
xx = 0.0;
zz = 0.0;
for(im = 0;im<mm;im++) {
xx += c[im] * (P[id+(im+1)*nnz] - P[id-im*nnz]);
zz += c[im] * (Q[id+im+1] - Q[id-im]);
}
u1[id] = coffx2[ix]*u0[id] - coffx1[ix]*dtx*xx;
w1[id] = coffz2[iz]*w0[id] - coffz1[iz]*dtz*zz;
}
}
}
__global__ void update_stress(int nx,
int nz,
int nnx,
int nnz,
float dt,
float dx,
float dz,
float *u1,
float *w1,
float *P,
float *Q,
float *vp,
int npml,
float *px1,
float *px0,
float *pz1,
float *pz0,
float *qx1,
float *qx0,
float *qz1,
float *qz0,
float *acoffx1,
float *acoffx2,
float *acoffz1,
float *acoffz2,
float *delta,
float *epsilon,
int fs,
int ds,
int zs,
int is,
bool SV)
{
int id=threadIdx.x+blockDim.x*blockIdx.x;
int im, ix, iz, rx, rz;
float dtx, dtz, xx, zz, ee, dd;
/* iso circle */
int R=18,r=7;
ix = id / nnz;
iz = id % nnz;
dtx = dt / dx;
dtz = dt / dz;
if(id >= mm && id<nnx*nnz-mm) {
/* iso circle begin */
rx = ix-(fs+(is-1)*ds+npml);
rz = iz-(zs+npml);
if(SV){
if((rx*rx+rz*rz) <= R*R){
if((rx*rx+rz*rz) <= r*r){
ee = 0.0;
dd = 0.0;
}else{
ee = 0.5*(1-cos(pi*((sqrtf(rx*rx+rz*rz)-r)*4.0/(R*3.0-1))))*epsilon[id];
dd = 0.5*(1-cos(pi*((sqrtf(rx*rx+rz*rz)-r)*4.0/(R*3.0-1))))*delta[id];
}//else
}else{
ee = epsilon[id];
dd = delta[id];
}
}else{
ee = epsilon[id];
dd = delta[id];
}
/* iso circle end */
if(ix>=mm && ix<(nnx-mm) && iz>=mm && iz<(nnz-mm)) {
xx=0.0;
zz=0.0;
for(im=0; im<mm; im++) {
xx += c[im]*(u1[id+im*nnz] - u1[id-(im+1)*nnz]);
zz += c[im]*(w1[id+im] - w1[id-im-1]);
}
px1[id] = acoffx2[ix]*px0[id] - acoffx1[ix]*vp[id]*vp[id]*(1+2*ee)*dtx*xx;
pz1[id] = acoffz2[iz]*pz0[id] - acoffz1[iz]*vp[id]*vp[id]*sqrtf(1+2*dd)*dtz*zz;
qx1[id] = acoffx2[ix]*qx0[id] - acoffx1[ix]*vp[id]*vp[id]*sqrtf(1+2*dd)*dtx*xx;
qz1[id] = acoffz2[iz]*qz0[id] - acoffz1[iz]*vp[id]*vp[id]*dtz*zz;
P[id] = px1[id] + pz1[id];
Q[id] = qx1[id] + qz1[id];
}
}
}
void pad_vv(int nx,
int nz,
int nnx,
int nnz,
int npml,
float *ee)
/**
* Expand the border
*/
{
int ix,iz,id;
for(id=0; id<nnx*nnz; id++) {
ix = id/nnz;
iz = id%nnz;
/* left */
if(ix<npml){
ee[id] = ee[npml*nnz+iz];
/* right */
}else if(ix>=nnx-npml){
ee[id] = ee[(nnx-npml-1)*nnz+iz];
}
}
for(id=0; id<nnx*nnz; id++) {
ix = id/nnz;
iz = id%nnz;
/* up */
if(iz < npml){
ee[id] = ee[ix*nnz+npml];
/* bottom */
}else if(iz >= nnz-npml){
ee[id] = ee[ix*nnz+nnz-npml-1];
}
}
}
__global__ void initial_coffe(float dt,
int nn,
float *coff1,
float *coff2,
float *acoff1,
float *acoff2,
int npml)
/**
* Calculate the PML coefficient
*
*/
{
int id=threadIdx.x+blockDim.x*blockIdx.x;
if(id < nn+2*npml) {
/* The front of the inner */
if(id<npml) {
coff1[id] = 1.0/(1.0+(dt*d0*pow((npml-0.5-id)/npml,2.0))/2.0);
coff2[id] = coff1[id]*(1.0-(dt*d0*pow((npml-0.5-id)/npml,2.0))/2.0);
acoff1[id] = 1.0/(1.0+(dt*d0*pow(((npml-id)*1.0)/npml,2.0))/2.0);
acoff2[id] = acoff1[id]*(1.0-(dt*d0*pow(((npml-id)*1.0)/npml,2.0))/2.0);
/* media inner */
}else if(id>=npml&&id<npml+nn){
coff1[id] = 1.0;
coff2[id] = 1.0;
acoff1[id] = 1.0;
acoff2[id] = 1.0;
/* The tail of the inner */
}else{
coff1[id] = 1.0/(1.0+(dt*d0*pow((0.5+id-nn-npml)/npml,2.0))/2.0);
coff2[id] = coff1[id]*(1.0-(dt*d0*pow((0.5+id-nn-npml)/npml,2.0))/2.0);
acoff1[id] = 1.0/(1.0+(dt*d0*pow(((id-nn-npml)*1.0)/npml,2.0))/2.0);
acoff2[id] = acoff1[id]*(1.0-(dt*d0*pow(((id-nn-npml)*1.0)/npml,2.0))/2.0);
}
}
}
__global__ void shot_record(int nnx,
int nnz,
int nx,
int nz,
int npml,
int it,
int nt,
float *P,
float *shot,
bool record)
/**
* Record or load Receiver wavefield
* (nx) >> (nx,nt)
* or
* (nx,nt) >> (nx)
*/
{
int id=threadIdx.x+blockDim.x*blockIdx.x;
if(id<nx) {
/* record the wavefield */
if(record){
shot[it+nt*id] = P[npml+nnz*(id+npml)];
/* load the receiver wavefield */
}else{
P[npml+nnz*(id+npml)] = shot[it+nt*id];
}
}
}
__global__ void wavefield_bndr(int nnx,
int nnz,
int nx,
int nz,
int npml,
int it,
int nt,
float *P,
float *Q,
float *P_bndr,
float *Q_bndr,
bool record)
/**
* Record or backword the boundary wave field
*
*/
{
int id=threadIdx.x+blockDim.x*blockIdx.x;
if(id<2*nx+2*nz) {
/* save boundary */
if(record) {
/* up */
if(id<nx){
P_bndr[it*(2*nx+2*nz)+id] = P[npml-1+nnz*(id+npml)];
Q_bndr[it*(2*nx+2*nz)+id] = Q[npml-1+nnz*(id+npml)];
/* bottom */
}else if(id>=nx&&id<(2*nx)){
P_bndr[it*(2*nx+2*nz)+id] = P[npml+nz+1+nnz*(id-nx+npml)];
Q_bndr[it*(2*nx+2*nz)+id] = Q[npml+nz+1+nnz*(id-nx+npml)];
/* left */
}else if(id>=(2*nx)&&id<(2*nx+nz)){
P_bndr[it*(2*nx+2*nz)+id] = P[id-2*nx+npml+nnz*(npml-1)];
Q_bndr[it*(2*nx+2*nz)+id] = Q[id-2*nx+npml+nnz*(npml-1)];
/* right */
}else if(id>=(2*nx+nz)){
P_bndr[it*(2*nx+2*nz)+id] = P[id-2*nx-nz+npml+nnz*(npml+nx+1)];
Q_bndr[it*(2*nx+2*nz)+id] = Q[id-2*nx-nz+npml+nnz*(npml+nx+1)];
}
/* backward porpagation boundary */
}else{
/* up */
if(id<nx){
P[npml-1+nnz*(id+npml)] = P_bndr[it*(2*nx+2*nz)+id];
Q[npml-1+nnz*(id+npml)] = Q_bndr[it*(2*nx+2*nz)+id];
/* bottom */
}else if(id>=nx&&id<(2*nx)){
P[npml+nz+1+nnz*(id-nx+npml)] = P_bndr[it*(2*nx+2*nz)+id];
Q[npml+nz+1+nnz*(id-nx+npml)] = Q_bndr[it*(2*nx+2*nz)+id];
/* left */
}else if(id>=(2*nx)&&id<(2*nx+nz)){
P[id-2*nx+npml+nnz*(npml-1)] = P_bndr[it*(2*nx+2*nz)+id];
Q[id-2*nx+npml+nnz*(npml-1)] = Q_bndr[it*(2*nx+2*nz)+id];
/* right */
}else if(id>=(2*nx+nz)){
P[id-2*nx-nz+npml+nnz*(npml+nx+1)] = P_bndr[it*(2*nx+2*nz)+id];
Q[id-2*nx-nz+npml+nnz*(npml+nx+1)] = Q_bndr[it*(2*nx+2*nz)+id];
}
}
}
}
__global__ void mute_directwave(int nx,
int nt,
float dt,
float favg,
float dx,
float dz,
int fs,
int ds,
int zs,
int is,
float *vp,
float *epsilon,
float *shot,
int tt)
/**
*mute direct waves
*/
{
int it = threadIdx.x+blockDim.x*blockIdx.x;
int mu_t, mu_nt;
float mu_x, mu_z, mu_t0;
int ix, id;
for(ix = 0; ix < nx; ix ++){
id = ix*nt + it;
mu_x = dx*abs(ix-fs-(is-1)*ds);
mu_z = dz*zs;
mu_t0 = sqrtf(pow(mu_x,2)+pow(mu_z,2))/(vp[1]*sqrtf(1+2*epsilon[1]));
mu_t = (int)(2.0/(dt*favg));
mu_nt = (int)(mu_t0/dt)+mu_t+tt;
if((it > (int)(mu_t0/dt)-tt) && (it<mu_nt))
shot[id] = 0.0;
}
}
__global__ void cal_illumination(int nnx,
int nnz,
int nz,
int npml,
float *illumination,
float *P,
float *Q)
/**
* illumination matrix
*/
{
int id = threadIdx.x+blockDim.x*blockIdx.x;
int ix = id/nz;
int iz = id%nz;
if(id < nnx*nnz) {
illumination[id] += P[iz+npml+nnz*(ix+npml)] * P[iz+npml+nnz*(ix+npml)]
+Q[iz+npml+nnz*(ix+npml)] * Q[iz+npml+nnz*(ix+npml)];
if(illumination[id] <= 0.0 )
illumination[id] = 1.0;
}
}
__global__ void cal_migration(int nnx,
int nnz,
int nz,
int npml,
float *migration,
float *s,
float *g)
/**
* RTM migration
*/
{
int id = threadIdx.x+blockDim.x*blockIdx.x;
int ix = id/nz;
int iz = id%nz;
if(id<nnx*nnz) {
migration[id] += s[iz+npml+nnz*(ix+npml)] * g[iz+npml+nnz*(ix+npml)];
}
}
__global__ void migration_illum(int nx,
int nz,
int npml,
float *migration,
float *illumination)
/**
* illuminate
*/
{
int id=threadIdx.x+blockDim.x*blockIdx.x;
if(id<nx*nz) {
migration[id] /= illumination[id];
}
}
__global__ void Poynting_Adcigs(int nnz,
int nx,
int nz,
int npml,
int nangle,
int dangle,
float *adcigs,
float *s_P,
float *s_Q,
float *s_u,
float *s_w,
float *g_P,
float *g_Q,
float *g_u,
float *g_w)
/**
* poynting vector extraction ADCIGs
* "Copyright(C) Madagascar:user/pyang/Mrtmadcig.c"
*/
{
int id = threadIdx.x+blockDim.x*blockIdx.x;
int ix = id/nz;
int iz = id%nz;
int ia = 0;
float Ssx = -s_P[iz+npml+nnz*(ix+npml)]*s_u[iz+npml+nnz*(ix+npml)];
float Ssz = -s_Q[iz+npml+nnz*(ix+npml)]*s_w[iz+npml+nnz*(ix+npml)];
float Sgx = g_P[iz+npml+nnz*(ix+npml)]*g_u[iz+npml+nnz*(ix+npml)];
float Sgz = g_Q[iz+npml+nnz*(ix+npml)]*g_w[iz+npml+nnz*(ix+npml)];
float b1 = Ssx*Ssx + Ssz*Ssz;
float b2 = Sgx*Sgx + Sgz*Sgz;
float a = (Ssx*Sgx + Ssz*Sgz)/(sqrtf(b1*b2)*(1 - 0.1));
if(id<nx*nz) {
if(a>=-1&&a<=1) {
a = 0.5*acosf(a)*180.0/pi;
ia = (int)(a/(dangle*1.0));
if(ia<nangle) {
adcigs[iz+nz*ia+nz*nangle*(id/nz)]
+= s_P[iz+npml+nnz*(ix+npml)]*g_P[iz+npml+nnz*(ix+npml)]
*cosf(ia*pi/180.0)*cosf(ia*pi/180.0)*cosf(ia*pi/180.0);
}
}
}
}
__global__ void adcigs_illum(int nx,
int nz,
int nangle,
int dangle,
float *adcigs,
float *illumination)
/**
* illuminate the adcigs
*/
{
int id = threadIdx.x+blockDim.x*blockIdx.x;
int ix = id/(nz*nangle);
int iz = id%nz;
if(id<nx*nz*nangle) {
adcigs[id] /= illumination[iz+nz*ix];
}
}
void stk_adcigs(int nx,
int nz,
int nangle,
float *adcigs,
float *migration)
/**
* Stack adcigs to migration
* Can suppress low-frequency random noise
*/
{
int ix,iz,ia,id,ido;
float stk;
float *temp;
temp=(float*)malloc(nz*nx*sizeof(float));
for (ix=0; ix<nx; ix++) {
for (iz=0; iz<nz; iz++) {
stk=0.0;
for (ia=0; ia<nangle; ia++) {
id = ix*nangle*nz+ia*nz+iz;
stk += adcigs[id];
}
ido = ix*nz+iz;
temp[ido] = stk;
}
}
laplace_filter(1,nz,nx,temp,migration);
print_success("Done with stack ADCIGs into Migration.\n");
}
void adcigs_smiled(int nx,
int nz,
int nangle,
int dAdcigs,
float *adcigs)
/**
* Draw thin adcigs
*/
{
int ix,iz,ia,id,ido;
float *temp;
temp = (float*)malloc(nz*nx/dAdcigs*nangle*sizeof(float));
for (ix=0; ix<nx; ix++) {
for (ia=0; ia<nangle; ia++) {
for (iz=0; iz<nz; iz++) {
id=ix*nangle*nz+ia*nz+iz;
if(ix%dAdcigs==0) {
ido = ix/dAdcigs*nangle*nz+ia*nz+iz;
temp[ido] = adcigs[id];
adcigs[ido] = temp[ido];
}
}
}
}
print_success("Done with smile ADCIGs.\n");
}
void readFile( char FNvelocity[],
char FNepsilon[],
char FNdelta[],
int nx,
int nz,
int nnx,
int nnz,
float dx,
float dz,
float favg,
float dt,
float *v,
float *e,
float *d,
int npml)
{
int i,j,id;
float vmax, vmin;
float emax, emin;
float dmax, dmin;
float H_min, dt_max, dxz_max, C, tmp;
char msg[1024];
FILE *fp1,*fp2,*fp3;
if((fp1=fopen(FNvelocity,"rb"))==NULL){
sprintf(msg, "error open <%s>!\n",FNvelocity);
print_error(msg);
exit(0);
}
if((fp2=fopen(FNepsilon,"rb"))==NULL){
sprintf(msg, "error open <%s>!\n",FNepsilon);
print_error(msg);
exit(0);
}
if((fp3=fopen(FNdelta,"rb"))==NULL){
sprintf(msg, "error open <%s>!\n",FNdelta);
print_error(msg);
exit(0);
}
vmin = emin = dmin = 999999.9;
vmax = emax = dmax = -999999.9;
for(i=npml;i<nx+npml;i++) {
for(j=npml;j<nz+npml;j++) {
id=i*nnz+j;
/* inch time 0.3 */
fread(&v[id],4L,1,fp1);//v[id] *= 0.3;
fread(&e[id],4L,1,fp2);
fread(&d[id],4L,1,fp3);
/* For Parameters Sensitivity Analysis */
//if(true) // true: active
// if(v[id]>3800)
{
//v[id] *= 0.3;
//e[id] *= 0.85;
//d[id] *= 0.85;
}
if(vmax<v[id]) vmax = v[id];
if(vmin>v[id]) vmin = v[id];
if(emax<e[id]) emax = e[id];
if(emin>e[id]) emin = e[id];
if(dmax<d[id]) dmax = d[id];
if(dmin>d[id]) dmin = d[id];
}
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
print_success("Load (v,e,d) successfully.\n");
sprintf(msg," Velocity Range (%.1f - %.1f)[m/s]\n",vmin,vmax);
print_info(msg);
sprintf(msg," Epsilon Range (%.4f - %.4f)\n",emin,emax);
print_info(msg);
sprintf(msg," Delta Range (%.4f - %.4f)\n",dmin,dmax);
print_info(msg);
/* boundary */
pad_vv(nx,nz,nnx,nnz,npml,e);
pad_vv(nx,nz,nnx,nnz,npml,d);
pad_vv(nx,nz,nnx,nnz,npml,v);
H_min=dx<dz?dx:dz;
dt_max = 0.5*H_min/vmin;
dxz_max = vmax/favg*0.2;
if ( dxz_max<dz || dxz_max<dx){
print_warning("You need have to redefine DX and DZ ! \n");
exit(0);
}
if ( dt_max<dt){
print_warning("You need have to redefine DT ! \n");
exit(0);
}
if ( favg >= vmin/( 5.0*(dx>dz?dx:dz) )
|| favg >= vmin/( 5.0*(dx>dz?dx:dz) ) ) {
print_warning("Non-dispersion relation not satisfied! \n");
exit(0);
}
/* following
* Copyright@ Madagascar */