int main (int argc, char *argv[]) { int m, k, l, seed; sf_file bshuffle,ashuffle; sf_axis ax,at,ap,av; int nx,nt,np,nv,iteration,*a1, *a2; float ***bsh, ***bsh2; sf_init(argc,argv); bshuffle=sf_input("in"); ashuffle=sf_output("out"); if (!sf_getint("iteration",&iteration)) iteration=1; if (!sf_getint("seed",&seed)) seed=2012; at=sf_iaxa( bshuffle,1); nt=sf_n(at); ax=sf_iaxa( bshuffle,3); nx=sf_n(ax); ap=sf_iaxa( bshuffle,2); np=sf_n(ap); av=sf_iaxa( bshuffle,4); nv=sf_n(av); bsh=sf_floatalloc3(nt,np,nx); bsh2=sf_floatalloc3(nt,np,nx); a1=sf_intalloc(np); a2=sf_intalloc(np); sf_warning("ntpx=%d",nt*np*nx); srand(seed); for (m=0; m<np; m++) { a1[m]=rand(); } bubble(a1, a2, np); for (k=0; k<nv; k++) { sf_floatread(bsh[0][0],nt*np*nx,bshuffle); for(l=0; l<nx; l++) { for (m=0; m<np; m++) { memcpy(bsh2[l][m], bsh[l][a2[m]], nt*sizeof(float)); } } sf_floatwrite(bsh2[0][0],nt*np*nx,ashuffle); } free(bsh[0][0]); free(bsh[0]); free(bsh); free(bsh2[0][0]); free(bsh2[0]); free(bsh2); free(a1); free(a2); exit (0); }
int main(int argc, char* argv[]) { sf_init(argc,argv); sf_file Fin,Fout; long long int n1,n2,n3; float d1,o1,d2,o2; Fin=sf_input ("in" ); sf_axis a1,a2,a3; a1 = sf_iaxa(Fin,1); n1 = sf_n(a1); d1=sf_d(a1);o1=sf_o(a1); a2=sf_iaxa(Fin,2);n2=sf_n(a2);d2=sf_d(a2);o2=sf_o(a2); fprintf(stderr,"%lld %lld %f %f %f %f\n",n1,n2,d1,d2,o1,o2); int maxoffset; if (!sf_getint("maxoffset",&maxoffset)) maxoffset=100000000; Fout=sf_output("out"); sf_putint(Fout,"n2",15); float temp[15]; int i,j; int ntrace=0; for(i=0;i<n2;i++) for(j=0;j<n2;j++) { if((abs(j-i)%2==0)&&(fabs(j-i)*d2)<=maxoffset) { ntrace++; } } sf_putint(Fout,"n1",ntrace); ntrace=0; for(i=0;i<n2;i++) for(j=0;j<n2;j++) { if((abs(j-i)%2==0)&&(fabs(j-i)*d2)<=maxoffset) { float s=o2+i*d2; float r=o2+j*d2; float h=(r-s)/2.0; float x=(s+r)/2; temp[0]=i; temp[1]=s; temp[2]=r; temp[3]=0; temp[4]=0; temp[5]=x; temp[6]=h; temp[14]=ntrace; ntrace++; fprintf(stderr,"temp[0]=%f %f %f %f %f ntrace=%f\n",temp[0],s,r,h,x,temp[14]); sf_floatwrite(temp,15,Fout); } } sf_close(); return 0; }
int main(int argc, char* argv[]) { bool verb; sf_file Fu,Fw; /* I/O files */ sf_axis a1,a2,a3; /* cube axes */ float ***uu=NULL, ***ww=NULL; int *ii,ik; int nh1,nh2,nh3; int nb1,nb2,nb3; int ih1,ih2,ih3; int ib1,ib2,ib3; int n3; int i3; int j1, j2, j3; int k1, k2, k3; int ompchunk; int lo1,hi1; int lo2,hi2; int lo3,hi3; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getint("ompchunk",&ompchunk)) ompchunk=1; /* OpenMP data chunk size */ if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ Fu = sf_input ("in" ); /* input field */ Fw = sf_output("out"); /* wigner distribution */ /* read axes */ a1=sf_iaxa(Fu,1); sf_setlabel(a1,"a1"); if(verb) sf_raxa(a1); a2=sf_iaxa(Fu,2); sf_setlabel(a2,"a2"); if(verb) sf_raxa(a2); a3=sf_iaxa(Fu,3); sf_setlabel(a3,"a3"); if(verb) sf_raxa(a3); n3 = sf_n(a3); if(! sf_getint("nh1",&nh1)) nh1=0; if(! sf_getint("nh2",&nh2)) nh2=0; if(! sf_getint("nh3",&nh3)) nh3=0; if(n3<=1) nh3=0; if(verb) sf_warning("nh1=%d nh2=%d nh3=%d",2*nh1+1,2*nh2+1,2*nh3+1); nb1 = sf_n(a1); nb2 = sf_n(a2); nb3=2*nh3+1; uu=sf_floatalloc3(nb1,nb2,nb3); ww=sf_floatalloc3(nb1,nb2,nb3); ii = sf_intalloc(nb3); for(ib3=0;ib3<nb3;ib3++) { ii[ib3]=ib3; } /*------------------------------------------------------------*/ /* low end on axis 3 */ /*------------------------------------------------------------*/ for( ib3=0; ib3<nb3; ib3++) { for( ib2=0; ib2<nb2; ib2++) { for( ib1=0; ib1<nb1; ib1++) { ww[ib3][ib2][ib1] = 0.; } } } sf_floatread(uu[0][0],nb1*nb2*nb3,Fu); for( ih3=-nh3; ih3<nh3+1; ih3++) { lo3=SF_ABS(ih3); hi3=nb3-lo3; for( ih2=-nh2; ih2<nh2+1; ih2++) { lo2=SF_ABS(ih2); hi2=nb2-lo2; for(ih1=-nh1; ih1<nh1+1; ih1++) { lo1=SF_ABS(ih1); hi1=nb1-lo1; for( ib3=lo3; ib3<nh3+1;ib3++) { j3=ii[ib3-ih3]; k3=ii[ib3+ih3]; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) \ private(ib1,ib2,j2,j1,k2,k1) \ shared(ib3,j3,k3,ih2,ih1,lo2,hi2,lo1,hi1,uu,ww) #endif for( ib2=lo2; ib2<hi2; ib2++) { j2=ib2-ih2; k2=ib2+ih2; for(ib1=lo1; ib1<hi1; ib1++) { j1=ib1-ih1; k1=ib1+ih1; ww[ib3][ib2][ib1] += uu[j3][j2][j1] * uu[k3][k2][k1]; } /* nb1 */ } /* nb2 */ } /* nb3 */ } /* nh1 */ } /* nh2 */ } /* nh3 */ for(ih3=0;ih3<nh3+1;ih3++) { sf_floatwrite(ww[ih3][0],nb1*nb2,Fw); } /*------------------------------------------------------------*/ /* loop on axis 3 */ /*------------------------------------------------------------*/ if(verb) fprintf(stderr," n3\n"); if(verb) fprintf(stderr,"%5d\n",n3-1); for(i3=nh3+1;i3<n3-nh3;i3++) { if(verb) fprintf(stderr,"%5d",i3); /* zero WDF */ ib3=nh3; for( ib2=0; ib2<nb2; ib2++) { for( ib1=0; ib1<nb1; ib1++) { ww[ib3][ib2][ib1] = 0.; } } /* circulate index to slices */ ik = ii[0]; for(ib3=0;ib3<nb3-1;ib3++) { ii[ib3]=ii[ib3+1]; } ii[nb3-1]=ik; /* read new slice */ sf_floatread(uu[ ii[nb3-1] ][0],nb1*nb2,Fu); for( ih3=-nh3; ih3<nh3+1; ih3++) { for( ih2=-nh2; ih2<nh2+1; ih2++) { lo2=SF_ABS(ih2); hi2=nb2-lo2; for(ih1=-nh1; ih1<nh1+1; ih1++) { lo1=SF_ABS(ih1); hi1=nb1-lo1; ib3=nh3; j3=ii[ib3-ih3]; k3=ii[ib3+ih3]; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) \ private(ib1,ib2,j2,j1,k2,k1) \ shared(ib3,j3,k3,ih2,ih1,lo2,hi2,lo1,hi1,uu,ww) #endif for( ib2=lo2; ib2<hi2; ib2++) { j2=ib2-ih2; k2=ib2+ih2; for(ib1=lo1; ib1<hi1; ib1++) { j1=ib1-ih1; k1=ib1+ih1; ww[ib3][ib2][ib1] += uu[j3][j2][j1] * uu[k3][k2][k1]; } /* nb1 */ } /* nb2 */ } /* nh1 */ } /* nh2 */ } /* nh3 */ sf_floatwrite(ww[nh3][0],nb1*nb2,Fw); if(verb) fprintf(stderr,"\b\b\b\b\b"); } /*------------------------------------------------------------*/ /* high-end on axis 3*/ /*------------------------------------------------------------*/ for( ih3=-nh3; ih3<nh3+1; ih3++) { lo3=SF_ABS(ih3); hi3=nb3-lo3; for( ih2=-nh2; ih2<nh2+1; ih2++) { lo2=SF_ABS(ih2); hi2=nb2-lo2; for(ih1=-nh1; ih1<nh1+1; ih1++) { lo1=SF_ABS(ih1); hi1=nb1-lo1; for( ib3=nh3+1; ib3<hi3; ib3++) { j3=ii[ib3-ih3]; k3=ii[ib3+ih3]; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) \ private(ib1,ib2,j2,j1,k2,k1) \ shared(ib3,j3,k3,ih2,ih1,lo2,hi2,lo1,hi1,uu,ww) #endif for( ib2=lo2; ib2<hi2; ib2++) { j2=ib2-ih2; k2=ib2+ih2; for(ib1=lo1; ib1<hi1; ib1++) { j1=ib1-ih1; k1=ib1+ih1; ww[ib3][ib2][ib1] += uu[j3][j2][j1] * uu[k3][k2][k1]; } /* nb1 */ } /* nb2 */ } /* nb3 */ } /* nh1 */ } /* nh2 */ } /* nh3 */ for(ih3=nh3+1;ih3<2*nh3+1;ih3++) { sf_floatwrite(ww[ih3][0],nb1*nb2,Fw); } /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char** argv) { bool verb, fsrf, snap, expl, dabc, cden, adj; bool optfd, hybrid, sinc; int jsnap, jdata; /* I/O files */ sf_file file_wav=NULL; /* wavelet */ sf_file file_vel=NULL; /* velocity */ sf_file file_den=NULL; /* density */ sf_file file_wfl=NULL; /* wavefield */ sf_file file_dat=NULL; /* data */ sf_file file_src=NULL; /* sources */ sf_file file_rec=NULL; /* receivers */ /* cube axes */ sf_axis at = NULL, az = NULL, ax = NULL, ay = NULL; sf_axis as = NULL, ar = NULL; int nbd; /* ABC boundary size */ int fdorder; /* finite difference spatial accuracy order */ int nzpad,nxpad,nypad; /* boundary padded model size */ int ix,iy,it,is,nx,ny,nz,nt,ns,nr; float dx,dy,dz,dt,dt2; float* damp=NULL; /* damping profile for hybrid bc */ float* ws; /* wavelet */ float*** vel=NULL; /* velocity */ float*** rho=NULL; /* density */ float*** u0=NULL; /* wavefield array u@t-1 (u@t+1) */ float*** u1=NULL; /* wavefield array u@t */ float* u_dat=NULL; /* output data */ float*** ptr_tmp=NULL; pt3d* src3d=NULL; /* source position */ pt3d* rec3d=NULL; /*receiver position*/ scoef3d cssinc = NULL, crsinc = NULL; lint3d cslint = NULL, crlint = NULL; /* FDM structure */ fdm3d fdm = NULL; abcone3d abc = NULL; sponge spo = NULL; int nbell; float* fdcoef_d2; float* fdcoef_d1; sf_axis acz = NULL, acx = NULL, acy = NULL; int nqz, nqx, nqy; float oqz, oqx, oqy, dqz, dqx, dqy; float** oslice = NULL; /* output 3D wavefield slice-by-slice */ float*** tmp_array; double wall_clock_time_s, wall_clock_time_e; const int SECOND_DERIV = 2; const int FIRST_DERIV = 1; int nop; #if defined _OPENMP && _DEBUG double tic; double toc; #endif /* init RSF */ sf_init(argc,argv); #ifdef _OPENMP omp_init(); wall_clock_time_s = omp_get_wtime(); #else wall_clock_time_s = (double) clock() / CLOCKS_PER_SEC; #endif if (!sf_getbool("verb",&verb)) verb=false; /* Verbosity flag */ if (!sf_getbool("snap",&snap)) snap=false; /* Wavefield snapshots flag */ if (!sf_getbool("expl",&expl)) expl=false; /* Multiple sources, one wvlt*/ if (!sf_getbool("dabc",&dabc)) dabc=false; /* Absorbing BC */ if (!sf_getbool("cden",&cden)) cden=false; /* Constant density */ if (!sf_getbool("adj",&adj)) adj=false; /* adjoint flag */ if (!sf_getbool("free",&fsrf) && !sf_getbool("fsrf",&fsrf)) fsrf=false; /* Free surface flag */ if (!sf_getint("nbell",&nbell)) nbell=5; /* gaussian for source injection */ if (!sf_getbool("optfd",&optfd)) optfd=false; /* optimized FD coefficients flag */ if (!sf_getint("fdorder",&fdorder)) fdorder=4; /* spatial FD order */ if (!sf_getbool("hybridbc",&hybrid)) hybrid=false; /* hybrid Absorbing BC */ if (!sf_getbool("sinc",&sinc)) sinc=false; /* sinc source injection */ /* Initialize variables */ file_wav = sf_input("in"); /* wavelet */ file_vel = sf_input("vel"); /* velocity */ file_src = sf_input("sou"); /* sources */ file_rec = sf_input("rec"); /* receivers */ file_dat = sf_output("out"); /* data */ if (snap) file_wfl = sf_output("wfl"); /* wavefield */ if (!cden) { if (sf_getstring("cden")) { file_den = sf_input ("den"); /* density */ } else { cden = true; if (verb) sf_warning("No density file provided, running with constant density"); } } at = sf_iaxa(file_wav,2); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ az = sf_iaxa(file_vel,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */ ax = sf_iaxa(file_vel,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* space */ ay = sf_iaxa(file_vel,3); sf_setlabel(ay,"y"); if(verb) sf_raxa(ay); /* space */ as = sf_iaxa(file_src,2); sf_setlabel(as,"s"); if(verb) sf_raxa(as); /* sources */ ar = sf_iaxa(file_rec,2); sf_setlabel(ar,"r"); if(verb) sf_raxa(ar); /* receivers */ nt = sf_n(at); dt = sf_d(at); nz = sf_n(az); dz = sf_d(az); nx = sf_n(ax); dx = sf_d(ax); ny = sf_n(ay); dy = sf_d(ay); ns = sf_n(as); nr = sf_n(ar); /* other execution parameters */ if (snap) { if (!sf_getint("jsnap",&jsnap)) jsnap=nt; /* # of t steps at which to save wavefield */ } if (!sf_getint("jdata",&jdata)) jdata=1; /* # of t steps at which to save receiver data */ /* setup output data header */ sf_oaxa(file_dat,ar,1); sf_setn(at,(nt-1)/jdata+1); sf_setd(at,dt*jdata); sf_oaxa(file_dat,at,2); /* wavefield cut params */ /* setup output wavefield header */ if (snap) { if (!sf_getint ("nqz",&nqz)) nqz=sf_n(az); /* Saved wfld window nz */ if (!sf_getint ("nqx",&nqx)) nqx=sf_n(ax); /* Saved wfld window nx */ if (!sf_getint ("nqy",&nqy)) nqy=sf_n(ay); /* Saved wfld window ny */ if (!sf_getfloat("oqz",&oqz)) oqz=sf_o(az); /* Saved wfld window oz */ if (!sf_getfloat("oqx",&oqx)) oqx=sf_o(ax); /* Saved wfld window ox */ if (!sf_getfloat("oqy",&oqy)) oqy=sf_o(ay); /* Saved wfld window oy */ if (!sf_getfloat("dqz",&dqz)) dqz=sf_d(az); /* Saved wfld window dz */ if (!sf_getfloat("dqx",&dqx)) dqx=sf_d(ax); /* Saved wfld window dx */ if (!sf_getfloat("dqy",&dqy)) dqy=sf_d(ay); /* Saved wfld window dy */ acz = sf_maxa(nqz,oqz,dqz); if (verb) sf_raxa(acz); acx = sf_maxa(nqx,oqx,dqx); if (verb) sf_raxa(acx); acy = sf_maxa(nqy,oqy,dqy); if (verb) sf_raxa(acy); /* check if the imaging window fits in the wavefield domain */ sf_setn(at,(nt-1)/jsnap+1); sf_setd(at,dt*jsnap); if (verb) sf_raxa(at); sf_oaxa(file_wfl,acz,1); sf_oaxa(file_wfl,acx,2); sf_oaxa(file_wfl,acy,3); sf_oaxa(file_wfl,at,4); } /* 2-2N finite difference coefficient */ nop = fdorder/2; /* fd half-length stencil */ if (!sf_getint("nb",&nbd) || nbd<nop) nbd=nop; if (dabc && hybrid && nbd<=nop) nbd = 2*nop; /* expand domain for FD operators and ABC */ fdm = fdutil3d_init(verb,fsrf,az,ax,ay,nbd,1); sf_setn(az,fdm->nzpad); sf_seto(az,fdm->ozpad); if (verb) sf_raxa(az); sf_setn(ax,fdm->nxpad); sf_seto(ax,fdm->oxpad); if (verb) sf_raxa(ax); sf_setn(ay,fdm->nypad); sf_seto(ay,fdm->oypad); if (verb) sf_raxa(ay); /* Precompute coefficients */ dt2 = dt*dt; nzpad = nz+2*nbd; nxpad = nx+2*nbd; nypad = ny+2*nbd; fdcoef_d2 = compute_fdcoef(nop,dz,dx,dy,optfd,SECOND_DERIV); fdcoef_d1 = compute_fdcoef(nop,dz,dx,dy,optfd,FIRST_DERIV); /* Allocate memories */ if (expl) ws = sf_floatalloc(1); else ws = sf_floatalloc(ns); vel = sf_floatalloc3(nzpad,nxpad,nypad); if (!cden) rho = sf_floatalloc3(nzpad,nxpad,nypad); u_dat = sf_floatalloc(nr); src3d = pt3dalloc1(ns); rec3d = pt3dalloc1(nr); if (snap) oslice = sf_floatalloc2(sf_n(acz),sf_n(acx)); /* source and receiver position */ pt3dread1(file_src,src3d,ns,3); /* read format: (x,y,z) */ if (sinc) cssinc = sinc3d_make(ns,src3d,fdm); else cslint = lint3d_make(ns,src3d,fdm); pt3dread1(file_rec,rec3d,nr,3); /* read format: (x,y,z) */ if (sinc) crsinc = sinc3d_make(nr,rec3d,fdm); else crlint = lint3d_make(nr,rec3d,fdm); if (!sinc) fdbell3d_init(nbell); /* temperary array */ tmp_array = sf_floatalloc3(nz,nx,ny); /* read velocity and pad */ sf_floatread(tmp_array[0][0],nz*nx*ny,file_vel); expand3d(tmp_array,vel,fdm); /* read density and pad */ if (!cden) { sf_floatread(tmp_array[0][0],nz*nx*ny,file_den); expand3d(tmp_array,rho,fdm); } free(**tmp_array); free(*tmp_array); free(tmp_array); /* A1 one-way ABC implicit scheme coefficients */ if (dabc) { abc = abcone3d_make(nbd,dt,vel,fsrf,fdm); if (hybrid) damp = damp_make(nbd-nop); /* compute damping profiles for hybrid bc */ else spo = sponge_make(fdm->nb); } /* allocate memory for wavefield variables */ u0 = sf_floatalloc3(nzpad,nxpad,nypad); u1 = sf_floatalloc3(nzpad,nxpad,nypad); /* initialize variables */ memset(u0[0][0],0,sizeof(float)*nzpad*nxpad*nypad); memset(u1[0][0],0,sizeof(float)*nzpad*nxpad*nypad); memset(u_dat,0,sizeof(float)*nr); /* v = (v*dt)^2 */ for (ix=0;ix<nzpad*nxpad*nypad;ix++) *(vel[0][0]+ix) *= *(vel[0][0]+ix)*dt2; if (fsrf && !hybrid) { for (iy=0; iy<nypad; iy++) for (ix=0; ix<nxpad; ix++) memset(vel[iy][ix],0,sizeof(float)*fdm->nb); } for (it=0; it<nt; it++) { if (verb) sf_warning("it=%d;",it+1); #if defined _OPENMP && _DEBUG tic=omp_get_wtime(); #endif step_forward(u0,u1,vel,rho,fdcoef_d2,fdcoef_d1,nop,nzpad,nxpad,nypad); if (adj) { /* backward inject source wavelet */ if (expl) { sf_seek(file_wav,(off_t)(nt-it-1)*sizeof(float),SEEK_SET); sf_floatread(ws,1,file_wav); ws[0] *= dt2; if (sinc) sinc3d_inject1(u0,ws[0],cssinc); else lint3d_inject1(u0,ws[0],cslint); } else { sf_seek(file_wav,(off_t)(nt-it-1)*ns*sizeof(float),SEEK_SET); sf_floatread(ws,ns,file_wav); for (is=0; is<ns; is++) ws[is] *= dt2; if (sinc) sinc3d_inject(u0,ws,cssinc); else lint3d_inject(u0,ws,cslint); } } else { /* forward inject source wavelet */ if (expl) { sf_floatread(ws,1,file_wav); ws[0] *= dt2; if (sinc) sinc3d_inject1(u0,ws[0],cssinc); else lint3d_inject1(u0,ws[0],cslint); } else { sf_floatread(ws,ns,file_wav); for (is=0; is<ns; is++) ws[is] *= dt2; if (sinc) sinc3d_inject(u0,ws,cssinc); else lint3d_inject(u0,ws,cslint); } } /* apply abc */ if (dabc) { if (hybrid) apply_abc(u0,u1,nz,nx,ny,nbd,abc,nop,damp); else { abcone3d_apply(u0,u1,nop,abc,fdm); sponge3d_apply(u0,spo,fdm); sponge3d_apply(u1,spo,fdm); } } /* loop over pointers */ ptr_tmp = u0; u0 = u1; u1 = ptr_tmp; /* extract snapshot */ if (snap && it%jsnap==0) { int fy = (floor)((sf_o(acy)-fdm->oypad)/fdm->dy); int jy = floor(sf_d(acy)/fdm->dy); float **ptr_slice; for (iy=0; iy<sf_n(acy); iy++) { ptr_slice = u0[fy+iy*jy]; cut3d_slice(ptr_slice,oslice,fdm,acz,acx); sf_floatwrite(oslice[0],sf_n(acz)*sf_n(acx),file_wfl); } } /* extract receiver data */ if (sinc) sinc3d_extract(u0,u_dat,crsinc); else lint3d_extract(u0,u_dat,crlint); sf_floatwrite(u_dat,nr,file_dat); #if defined _OPENMP && _DEBUG toc=omp_get_wtime(); fprintf(stderr,"%5.2gs",(float)(toc-tic)); #endif } #ifdef _OPENMP wall_clock_time_e = omp_get_wtime(); #else wall_clock_time_e = (double) clock() / CLOCKS_PER_SEC; #endif if (verb) fprintf(stderr,"\nElapsed time: %lf s\n",wall_clock_time_e-wall_clock_time_s); free(**u0); free(*u0); free(u0); free(**u1); free(*u1); free(u1); free(**vel); free(*vel); free(vel); free(u_dat); free(ws); free(fdcoef_d2); free(fdcoef_d1); if (snap) { free(*oslice); free(oslice); } if(!cden) { free(**rho); free(*rho); free(rho); } if (hybrid) free(damp); free(src3d); free(rec3d); return 0; }
int main(int argc, char* argv[]) { bool verb; /* verbosity flag */ float clip; /* threshold (clip value) */ sf_file Fc; /* cube file */ sf_file Fl; /* list file */ extern int fseeko(FILE *stream, off_t offset, int whence); sf_axis ax,ay,az; sf_axis aa; int ix,iy,iz; int nx,ny,nz,nj,na; int nk=0,jk; float **cube; float dx,dy,dz; float x0,y0,z0; FILE* tfile; char* tname; float t2[3],t3[4]; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getbool("verb",&verb)) verb=false; if(! sf_getfloat("clip",&clip)) clip=0; Fc = sf_input ( "in"); /* input cube */ Fl = sf_output("out"); /* output list */ /* read axes*/ az=sf_iaxa(Fc,1); sf_setlabel(az,"z"); ax=sf_iaxa(Fc,2); sf_setlabel(ax,"x"); ay=sf_iaxa(Fc,3); sf_setlabel(ay,"y"); nz=sf_n(az); z0=sf_o(az); dz=sf_d(az); nx=sf_n(ax); x0=sf_o(ax); dx=sf_d(ax); ny=sf_n(ay); y0=sf_o(ay); dy=sf_d(ay); na=0; if(ny>1) { if(verb) sf_warning("initiating 3D points"); nj=4; } else { if(verb) sf_warning("initiating 2D points"); nj=3; } /*------------------------------------------------------------*/ cube = sf_floatalloc2(nz,nx); tfile = sf_tempfile(&(tname), "w+b"); for (iy=0; iy<ny; iy++) { /* if(verb) sf_warning("iy=%d",iy);*/ sf_floatread(cube[0],nz*nx,Fc); nk=0; for (ix=0; ix<nx; ix++) { for (iz=0; iz<nz; iz++) { if( fabs(cube[ix][iz]) > clip) { nk++; } } } if(ny>1) { jk=0; for (ix=0; ix<nx; ix++) { for (iz=0; iz<nz; iz++) { if( fabs(cube[ix][iz]) > clip) { t3[0] = x0 + ix * dx; t3[1] = y0 + iy * dy; t3[2] = z0 + iz * dz; t3[3] = cube[ix][iz]; fseeko(tfile,jk*4*sizeof(float),SEEK_SET); fwrite( t3, sizeof(float),4,tfile); jk++; } } } } else { jk=0; for (ix=0; ix<nx; ix++) { for (iz=0; iz<nz; iz++) { if( fabs(cube[ix][iz]) > clip) { t2[0] = x0 + ix * dx; t2[1] = z0 + iz * dz; t2[2] = cube[ix][iz]; fseeko(tfile,jk*3*sizeof(float),SEEK_SET); fwrite( t2, sizeof(float),3,tfile); jk++; } } } } /* else ny=1 */ na += nk; } /* iy */ /* output axes */ aa = sf_maxa(nj,0,1); sf_oaxa(Fl,aa,1); if(verb) sf_raxa(aa); free(aa); aa = sf_maxa(na,0,1); sf_oaxa(Fl,aa,2); if(verb) sf_raxa(aa); free(aa); if( ny>1) { for( jk=0; jk<nk; jk++) { fseeko(tfile,jk*4*sizeof(float),SEEK_SET); fread( t3, sizeof(float),4,tfile); /* if(verb) sf_warning("%d, %g %g %g %g",jk,t3[0],t3[1],t3[2],t3[3]);*/ sf_floatwrite(t3,4,Fl); } } else { for( jk=0; jk<nk; jk++) { fseeko(tfile,jk*3*sizeof(float),SEEK_SET); fread( t2, sizeof(float),3,tfile); /* if(verb) sf_warning("%d, %g %g %g",jk,t2[0],t2[1],t2[2]);*/ sf_floatwrite(t2,3,Fl); } } free(cube); unlink(tname); exit (0); }
int main(int argc, char* argv[]) { bool verb,correct; int nt,nz,nx,m2,nk,nzx,nz2,nx2,n2,pad1; int snap, wfnt; float dt, wfdt; char *mode; sf_complex **ini, **cc, **dd; sf_file Fi,Fo,Fs,Fa,Fb; /* I/O files */ sf_axis az,ax,at; /* cube axes */ sf_complex **lt, **rt,***wvfld,*alpha,*beta; sf_file left, right; sf_init(argc,argv); if(!sf_getbool("verb",&verb)) verb=true; /* verbosity */ if(!sf_getint("nt",&nt)) sf_error("Need nt!"); if(!sf_getfloat("dt",&dt)) sf_error("Need dt!"); if(!sf_getint("snap",&snap)) snap=0; /* interval for snapshots */ if(!sf_getbool("correct",&correct)) correct=false; /*jingwei's correction*/ mode=sf_getstring("mode"); /* default mode is pspi */ if (mode[0]=='p') {sf_warning(">>>>> Using PSPI+PSPI! <<<<< \n");} else if (mode[0]=='n') {sf_warning(">>>>> Using NSPS+NSPS! <<<<< \n");} else if (mode[0]=='m') {sf_warning(">>>>> Using NSPS+PSPI! <<<<< \n");} else if (mode[0]=='x') {sf_warning(">>>>> Using PSPI+NSPS! <<<<< \n");} else sf_error("Specify mode!"); /* setup I/O files */ Fi = sf_input ("in" ); Fo = sf_output("out"); sf_settype(Fo,SF_COMPLEX); /* Read/Write axes */ az = sf_iaxa(Fi,1); nz = sf_n(az); ax = sf_iaxa(Fi,2); nx = sf_n(ax); at = sf_iaxa(Fi,3); sf_oaxa(Fo,az,1); sf_oaxa(Fo,ax,2); if (snap > 0) { Fs = sf_output("snaps"); /* (optional) snapshot file */ wfnt = (int)(nt-1)/snap + 1; wfdt = dt*snap; sf_oaxa(Fs,az,1); sf_oaxa(Fs,ax,2); sf_setn(at,wfnt); sf_setd(at,wfdt); sf_oaxa(Fs,at,3); sf_settype(Fs,SF_COMPLEX); } else Fs=NULL; if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ nz2 = kiss_fft_next_fast_size(nz*pad1); nx2 = kiss_fft_next_fast_size(nx); nk = nz2*nx2; /*wavenumber*/ nzx = nz*nx; /* propagator matrices */ left = sf_input("left"); right = sf_input("right"); if (!sf_histint(left,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in left",nzx); if (!sf_histint(left,"n2",&m2)) sf_error("Need n2= in left"); if (!sf_histint(right,"n1",&n2) || n2 != m2) sf_error("Need n1=%d in right",m2); if (!sf_histint(right,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in right",nk); lt = sf_complexalloc2(nzx,m2); rt = sf_complexalloc2(m2,nk); sf_complexread(lt[0],nzx*m2,left); sf_complexread(rt[0],m2*nk,right); sf_fileclose(left); sf_fileclose(right); ini=sf_complexalloc2(nz,nx); cc=sf_complexalloc2(nz,nx); dd=sf_complexalloc2(nz,nx); sf_complexread(ini[0],nzx,Fi); sf_fileclose(Fi); if (snap>0) wvfld = sf_complexalloc3(nz,nx,wfnt); else wvfld = NULL; if (correct) { Fa = sf_input("alpha"); Fb = sf_input("beta"); if (!sf_histint(Fa,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in alpha",nzx); if (!sf_histint(Fb,"n1",&n2) || n2 != nk) sf_error("Need n1=%d in beta",nk); alpha = sf_complexalloc(nzx); beta = sf_complexalloc(nk); sf_complexread(alpha,nzx,Fa); sf_complexread(beta,nk,Fb); sf_fileclose(Fa); sf_fileclose(Fb); } else { Fa = NULL; Fb = NULL; alpha = NULL; beta = NULL; } /* wave propagation*/ propnewc(ini, lt, rt, nz, nx, nt, m2, nk, mode, 1, snap, cc, wvfld, verb,correct,alpha,beta); /* output result */ sf_complexwrite(cc[0], nzx, Fo); if (snap>0) sf_complexwrite(wvfld[0][0], nzx*wfnt, Fs); exit (0); }
int main(int argc, char* argv[]) { int ix, iz, jx, jz,ixx,izz,ixf,izf,i,j,im, jm,nx,nz,nxf,nzf,nxpad,nzpad,it,ii,jj; float kxmax,kzmax; float f0, t, t0, dx, dz, dxf, dzf,dt, dkx, dkz, dt2; int mm, nvx, nvz, ns; int hnkx, hnkz, nkx, nkz, nxz, nkxz; int hnkx1, hnkz1, nkx1, nkz1; int isx, isz, isxm, iszm; /*source location */ int itaper; /* tapering or not for spectrum of oprtator*/ int nstep; /* every nstep in spatial grids to calculate filters sparsely*/ float *coeff_1dx, *coeff_1dz, *coeff_2dx, *coeff_2dz; /* finite-difference coefficient */ float **apx, **apz, **apxx, **apzz; /* polarization operator of P-wave for a location */ float **apxs, **apzs, **apxxs, **apzzs; /* polarization operator of SV-wave for a location */ float ****ex, ****ez; /* operator for whole model for P-wave*/ float ****exs, ****ezs; /* operator for whole model for SV-wave*/ float **exx, **ezz; /* operator for constant model for P-wave*/ float **exxs, **ezzs; /* operator for constant model for SV-wave*/ float **vp0, **vs0, **epsi, **del, **theta; /* velocity model */ float **p1, **p2, **p3, **q1, **q2, **q3, **p3c, **q3c, **sum; /* wavefield array */ float *kx, *kz, *kkx, *kkz, *kx2, *kz2, **taper; clock_t t1, t2, t3, t4; float timespent; float A, fx, fz; int isep=1; int ihomo=1; char *tapertype; double vp2, vs2, ep2, de2, the; sf_init(argc,argv); sf_file Fo1, Fo2, Fo3, Fo4, Fo5, Fo6, Fo7, Fo8, Fo9, Fo10, Fo11, Fo12; t1=clock(); /* wavelet parameter for source definition */ f0=30.0; t0=0.04; A=1.0; /* time samping paramter */ if (!sf_getint("ns",&ns)) ns=301; if (!sf_getfloat("dt",&dt)) dt=0.001; if (!sf_getint("isep",&isep)) isep=0; /* if isep=1, separate wave-modes */ if (!sf_getint("ihomo",&ihomo)) ihomo=0; /* if ihomo=1, homogeneous medium */ if (NULL== (tapertype=sf_getstring("tapertype"))) tapertype="D"; /* taper type*/ if (!sf_getint("nstep",&nstep)) nstep=1; /* grid step to calculate operators: 1<=nstep<=5 */ sf_warning("isep=%d",isep); sf_warning("ihomo=%d",ihomo); sf_warning("tapertype=%s",tapertype); sf_warning("nstep=%d",nstep); sf_warning("ns=%d dt=%f",ns,dt); sf_warning("read velocity model parameters"); /* setup I/O files */ sf_file Fvp0, Fvs0, Feps, Fdel, Fthe; Fvp0 = sf_input ("in"); /* vp0 using standard input */ Fvs0 = sf_input ("vs0"); /* vs0 */ Feps = sf_input ("epsi"); /* epsi */ Fdel = sf_input ("del"); /* delta */ Fthe = sf_input ("the"); /* theta */ /* Read/Write axes */ sf_axis az, ax; az = sf_iaxa(Fvp0,1); nvz = sf_n(az); dz = sf_d(az)*1000.0; ax = sf_iaxa(Fvp0,2); nvx = sf_n(ax); dx = sf_d(ax)*1000.0; fx=sf_o(ax)*1000.0; fz=sf_o(az)*1000.0; /* source definition */ isx=nvx/2; isz=nvz/2; //isz=nvz*2/5; /* wave modeling space */ nx=nvx; nz=nvz; nxpad=nx+2*m; nzpad=nz+2*m; sf_warning("fx=%f fz=%f dx=%f dz=%f",fx,fz,dx,dz); sf_warning("nx=%d nz=%d nxpad=%d nzpad=%d", nx,nz,nxpad,nzpad); vp0=sf_floatalloc2(nz,nx); vs0=sf_floatalloc2(nz,nx); epsi=sf_floatalloc2(nz,nx); del=sf_floatalloc2(nz,nx); theta=sf_floatalloc2(nz,nx); nxz=nx*nz; mm=2*m+1; dt2=dt*dt; isxm=isx+m; /* source's x location */ iszm=isz+m; /* source's z-location */ /* read velocity model */ sf_floatread(vp0[0],nxz,Fvp0); sf_floatread(vs0[0],nxz,Fvs0); sf_floatread(epsi[0],nxz,Feps); sf_floatread(del[0],nxz,Fdel); sf_floatread(theta[0],nxz,Fthe); for(i=0;i<nx;i++) for(j=0;j<nz;j++) theta[i][j] *= PI/180.0; t2=clock(); Fo1 = sf_output("out"); /* Elastic-wave x-component */ Fo2 = sf_output("Elasticz"); /* Elastic-wave z-component */ /* setup I/O files */ puthead3(Fo1, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz/1000.0, fx/1000.0, 0.0); puthead3(Fo2, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz/1000.0, fx/1000.0, 0.0); /***************************************************************************** * Calculating polarization operator for wave-mode separation * ***************************************************************************/ if(isep==1) { sf_warning("=================================================="); sf_warning("== Calculating Polarization Operator =="); sf_warning("=================================================="); /* calculate spatial steps for operater in sparsely sampling grid point */ dxf=dx*nstep; dzf=dz*nstep; nxf=nx/nstep+1; nzf=nz/nstep+1; /* operators length for calculation */ hnkx=400.0/dx; hnkz=400.0/dz; nkx=2*hnkx+1; /* operator length in kx-direction */ nkz=2*hnkz+1; /* operator length in kz-direction */ /* truncated spatial operators length for filtering*/ hnkx1=200.0/dx; hnkz1=200.0/dz; nkx1=2*hnkx1+1; nkz1=2*hnkz1+1; sf_warning("nx=%d nz=%d nxf=%d nzf=%d", nx,nz,nxf,nzf); sf_warning("dx=%f dz=%f dxf=%f dzf=%f", dx,dz,dxf,dzf); sf_warning("hnkx=%d hnkz=%d nkx=%d nkz=%d", hnkx, hnkz, nkx, nkz); sf_warning("hnkx1=%d hnkz1=%d nkx1=%d nkz1=%d", hnkx1, hnkz1, nkx1, nkz1); dkx=2*PI/dx/nkx; dkz=2*PI/dz/nkz; kxmax=PI/dx; kzmax=PI/dz; kx=sf_floatalloc(nkx); kz=sf_floatalloc(nkx); kkx=sf_floatalloc(nkx); kkz=sf_floatalloc(nkx); kx2=sf_floatalloc(nkx); kz2=sf_floatalloc(nkx); taper=sf_floatalloc2(nkz, nkx); // define axis samples and taper in wavenumber domain kxkztaper(kx, kz, kkx, kkz, kx2, kz2, taper, nkx, nkz, hnkx, hnkz, dkx, dkz, kxmax, kzmax, tapertype); nkxz=nkx*nkz; /* truncation of spatial filter */ if(ihomo==1) { exx=sf_floatalloc2(nkz1, nkx1); ezz=sf_floatalloc2(nkz1, nkx1); exxs=sf_floatalloc2(nkz1, nkx1); ezzs=sf_floatalloc2(nkz1, nkx1); }else{ ex=sf_floatalloc4(nkz1, nkx1, nz, nx); ez=sf_floatalloc4(nkz1, nkx1, nz, nx); exs=sf_floatalloc4(nkz1, nkx1, nz, nx); ezs=sf_floatalloc4(nkz1, nkx1, nz, nx); } /***************************************************************************** * Calculating polarization operator for wave-mode separation * ***************************************************************************/ apx=sf_floatalloc2(nkz, nkx); apz=sf_floatalloc2(nkz, nkx); apxs=sf_floatalloc2(nkz, nkx); apzs=sf_floatalloc2(nkz, nkx); apxx=sf_floatalloc2(nkz, nkx); apzz=sf_floatalloc2(nkz, nkx); apxxs=sf_floatalloc2(nkz, nkx); apzzs=sf_floatalloc2(nkz, nkx); /* setup I/O files for wavenumber-domain operators */ Fo3 = sf_output("apx"); /* P-wave's polarization x-comp */ Fo4 = sf_output("apz"); /* P-wave's polarization z-comp */ Fo5 = sf_output("apxs"); /* SV-wave's polarization x-comp */ Fo6 = sf_output("apzs"); /* SV-wave's polarization z-comp */ puthead1(Fo3, nkz, nkx, dkz, -kzmax, dkx, -kxmax); puthead1(Fo4, nkz, nkx, dkz, -kzmax, dkx, -kxmax); puthead1(Fo5, nkz, nkx, dkz, -kzmax, dkx, -kxmax); puthead1(Fo6, nkz, nkx, dkz, -kzmax, dkx, -kxmax); /* setup I/O files for space-domain operators */ Fo7 = sf_output("apxx"); /* P-wave's polarization x-comp in (x,z) domain */ Fo8 = sf_output("apzz"); /* P-wave's polarization z-comp in (x,z) domain */ Fo9 = sf_output("apxxs"); /* SV-wave's polarization x-comp in (x,z) domain */ Fo10 = sf_output("apzzs"); /* SV-wave's polarization z-comp in (x,z) domain */ puthead2(Fo7, nkz, nkx, dz/1000.0, 0.0, dx/1000.0, 0.0); puthead2(Fo8, nkz, nkx, dz/1000.0, 0.0, dx/1000.0, 0.0); puthead2(Fo9, nkz, nkx, dz/1000.0, 0.0, dx/1000.0, 0.0); puthead2(Fo10, nkz, nkx, dz/1000.0, 0.0, dx/1000.0, 0.0); /*************calculate projection deviation grid-point by grid-point **********/ for(ix=0,ixf=0;ix<nx;ix+=nstep,ixf++) { for(iz=0,izf=0;iz<nz;iz+=nstep,izf++) { vp2=vp0[ix][iz]*vp0[ix][iz]; vs2=vs0[ix][iz]*vs0[ix][iz]; ep2=1.0+2*epsi[ix][iz]; de2=1.0+2*del[ix][iz]; the=theta[ix][iz]; if(ixf%10==0&&izf%100==0) sf_warning("Operator: nxf=%d ixf=%d izf=%d vp2=%f vs2=%f",nxf, ixf,izf,vp2,vs2); /*************calculate projection operrate with tapering **********/ zero2float(apx, nkz, nkx); zero2float(apz, nkz, nkx); zero2float(apxs, nkz, nkx); zero2float(apzs, nkz, nkx); /* polvtipsv: P- and SV-wave polarization operators in VTI media */ itaper=1; polttipsv(apx,apz,apxs,apzs,kx,kz,kkx,kkz,taper,hnkx,hnkz,dkx,dkz, vp2,vs2,ep2,de2,the,itaper); ikxkz2xz(apx, apxx, hnkx, hnkz, nkx, nkz); ikxkz2xz(apz, apzz, hnkx, hnkz, nkx, nkz); ikxkz2xz(apxs, apxxs, hnkx, hnkz, nkx, nkz); ikxkz2xz(apzs, apzzs, hnkx, hnkz, nkx, nkz); // truncation and saving of operator in space-domain if(ihomo==1) { for(jx=-hnkx1,ixx=hnkx-hnkx1;jx<=hnkx1;jx++,ixx++) for(jz=-hnkz1,izz=hnkz-hnkz1;jz<=hnkz1;jz++,izz++) { exx[jx+hnkx1][jz+hnkz1]=apxx[ixx][izz]; ezz[jx+hnkx1][jz+hnkz1]=apzz[ixx][izz]; exxs[jx+hnkx1][jz+hnkz1]=apxxs[ixx][izz]; ezzs[jx+hnkx1][jz+hnkz1]=apzzs[ixx][izz]; } }else{ for(jx=-hnkx1,ixx=hnkx-hnkx1;jx<=hnkx1;jx++,ixx++) for(jz=-hnkz1,izz=hnkz-hnkz1;jz<=hnkz1;jz++,izz++) { ex[ixf][izf][jx+hnkx1][jz+hnkz1]=apxx[ixx][izz]; ez[ixf][izf][jx+hnkx1][jz+hnkz1]=apzz[ixx][izz]; exs[ixf][izf][jx+hnkx1][jz+hnkz1]=apxxs[ixx][izz]; ezs[ixf][izf][jx+hnkx1][jz+hnkz1]=apzzs[ixx][izz]; } } if((ixf==nxf/2&&izf==nzf/2&&ihomo==0)||ihomo==1) { //write-disk operators in kx-kz domain sf_floatwrite(apx[0], nkxz, Fo3); sf_floatwrite(apz[0], nkxz, Fo4); sf_floatwrite(apxs[0], nkxz, Fo5); sf_floatwrite(apzs[0], nkxz, Fo6); //write-disk operators in x-z domain sf_floatwrite(apxx[0], nkxz, Fo7); sf_floatwrite(apzz[0], nkxz, Fo8); sf_floatwrite(apxxs[0], nkxz, Fo9); sf_floatwrite(apzzs[0], nkxz, Fo10); } if(ihomo==1) goto loop; }// iz loop }//ix loop loop:; free(kx); free(kz); free(kx2); free(kz2); free(kkx); free(kkz); free(*taper); free(*apx); free(*apz); free(*apxs); free(*apzs); free(*apxx); free(*apzz); free(*apxxs); free(*apzzs); }// isep loop /****************End of Calculating Projection Deviation Operator****************/ t3=clock(); timespent=(float)(t3-t2)/CLOCKS_PER_SEC; sf_warning("Computation time (operators): %f (second)",timespent); /****************begin to calculate wavefield****************/ /****************begin to calculate wavefield****************/ sf_warning("=================================================="); sf_warning("== Propagation Using Elastic Wave Eq. =="); sf_warning("=================================================="); coeff_2dx=sf_floatalloc(mm); coeff_2dz=sf_floatalloc(mm); coeff_1dx=sf_floatalloc(mm); coeff_1dz=sf_floatalloc(mm); coeff2d(coeff_2dx,dx); coeff2d(coeff_2dz,dz); p1=sf_floatalloc2(nzpad, nxpad); p2=sf_floatalloc2(nzpad, nxpad); p3=sf_floatalloc2(nzpad, nxpad); q1=sf_floatalloc2(nzpad, nxpad); q2=sf_floatalloc2(nzpad, nxpad); q3=sf_floatalloc2(nzpad, nxpad); zero2float(p1, nzpad, nxpad); zero2float(p2, nzpad, nxpad); zero2float(p3, nzpad, nxpad); zero2float(q1, nzpad, nxpad); zero2float(q2, nzpad, nxpad); zero2float(q3, nzpad, nxpad); coeff1dmix(coeff_1dx,dx); coeff1dmix(coeff_1dz,dz); if(isep==1) { Fo11 = sf_output("ElasticSepP"); /* scalar wavefield using P-wave's polarization projection oprtator*/ Fo12 = sf_output("ElasticSepSV"); /* scalar wavefield using SV-wave's polarization projection oprtator*/ puthead3(Fo11, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz/1000.0, fx/1000.0, 0.0); puthead3(Fo12, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz/1000.0, fx/1000.0, 0.0); p3c=sf_floatalloc2(nz,nx); q3c=sf_floatalloc2(nz,nx); sum=sf_floatalloc2(nz,nx); } for(it=0;it<ns;it++) { t=it*dt; // 2D exploding force source (e.g., Wu's PhD for(i=-1;i<=1;i++) for(j=-1;j<=1;j++) { if(fabs(i)+fabs(j)==2) { p2[isxm+i][iszm+j]+=i*Ricker(t, f0, t0, A); q2[isxm+i][iszm+j]+=j*Ricker(t, f0, t0, A); } } // 2D equil-energy force source (e.g., Wu's PhD) /* for(i=-1;i<=1;i++) for(j=-1;j<=1;j++) { if(fabs(i)+fabs(j)==2) { if(i==-1&&j==1) q2[isxm+i][iszm+j]+=sqrt(2.0)*Ricker(t, f0, t0, A); if(i==-1&&j==-1) p2[isxm+i][iszm+j]+=-sqrt(2.0)*Ricker(t, f0, t0, A); if(i==1&&j==1) p2[isxm+i][iszm+j]+=sqrt(2.0)*Ricker(t, f0, t0, A); if(i==1&&j==-1) q2[isxm+i][iszm+j]+=-sqrt(2.0)*Ricker(t, f0, t0, A); } } */ /* fwpvtielastic: forward-propagating using original elastic equation of displacement in VTI media*/ fwpttielastic(dt2, p1, p2, p3, q1, q2, q3, coeff_2dx, coeff_2dz, coeff_1dx, coeff_1dz, dx, dz, nx, nz, nxpad, nzpad, vp0, vs0, epsi, del, theta); /******* output wavefields: component and divergence *******/ if(it==ns-1) { for(i=0;i<nx;i++) { im=i+m; for(j=0;j<nz;j++) { jm=j+m; sf_floatwrite(&p3[im][jm],1,Fo1); sf_floatwrite(&q3[im][jm],1,Fo2); } }/* i loop*/ if(isep==1) { ////////////////////////////////////////////////////////////////////////////////////////// /* applying P-wave polarization projection operator in spatial domain */ zero2float(p3c,nz,nx); zero2float(q3c,nz,nx); zero2float(sum, nz, nx); if(ihomo==1) filter2dsepglobal(p3, q3, p3c, q3c, exx, ezz, nx, nz, hnkx1, hnkz1); else filter2dsep(p3, q3, p3c, q3c, ex, ez, nx, nz, nstep, hnkx1, hnkz1); for(i=0;i<nx;i++) for(j=0;j<nz;j++) sum[i][j]=p3c[i][j]+q3c[i][j]; sf_floatwrite(sum[0],nx*nz, Fo11); ////////////////////////////////////////////////////////////////////////////////////////// /* applying SV-wave polarization projection operator in spatial domain */ zero2float(p3c,nz,nx); zero2float(q3c,nz,nx); zero2float(sum, nz, nx); if(ihomo==1) filter2dsepglobal(p3, q3, p3c, q3c, exxs, ezzs, nx, nz, hnkx1, hnkz1); else filter2dsep(p3, q3, p3c, q3c, exs, ezs, nx, nz, nstep, hnkx1, hnkz1); for(i=0;i<nx;i++) for(j=0;j<nz;j++) sum[i][j]=p3c[i][j]+q3c[i][j]; sf_floatwrite(sum[0],nx*nz, Fo12); }// isep==1 }/* (it+1)%ntstep==0 */ /**************************************/ for(i=0,ii=m;i<nx;i++,ii++) for(j=0,jj=m;j<nz;j++,jj++) { p1[ii][jj]=p2[ii][jj]; p2[ii][jj]=p3[ii][jj]; q1[ii][jj]=q2[ii][jj]; q2[ii][jj]=q3[ii][jj]; } if(it%100==0) sf_warning("Elastic: it= %d",it); }/* it loop */ t4=clock(); timespent=(float)(t4-t3)/CLOCKS_PER_SEC; sf_warning("Computation time (propagation + separation): %f (second)",timespent); if(isep==1) { free(*p3c); free(*q3c); free(*sum); if(ihomo==1) { free(*exx); free(*ezz); free(*exxs); free(*ezzs); }else{ free(***ex); free(***ez); free(***exs); free(***ezs); } } free(*p1); free(*p2); free(*p3); free(*q1); free(*q2); free(*q3); free(*vp0); free(*vs0); free(*epsi); free(*del); free(*theta); exit(0); }
int main(int argc, char* argv[]) { int i,j,im,jm,nx,nz,nxpad,nzpad,it,ii,jj; float f0, t, t0, dx, dz,dt, dt2; int mm, nvx, nvz, ns; int isx, isz, isxm, iszm; /*source location */ float *coeff_1dx, *coeff_1dz, *coeff_2dx, *coeff_2dz; /* finite-difference coefficient */ float **vp0, **vs0, **epsi, **del, **theta; /* velocity model */ float **p1, **p2, **p3, **q1, **q2, **q3; /* wavefield array */ float A, fx, fz; clock_t t1, t2, t3; sf_init(argc,argv); sf_file Fo1, Fo2; float timespent; t1 = clock(); /* wavelet parameter for source definition */ f0=30.0; t0=0.04; A=1.0; /* time samping paramter */ if (!sf_getint("ns",&ns)) ns=301; if (!sf_getfloat("dt",&dt)) dt=0.001; sf_warning("ns=%d dt=%f",ns,dt); sf_warning("read velocity model parameters"); /* setup I/O files */ sf_file Fvp0, Fvs0, Feps, Fdel, Fthe; Fvp0 = sf_input ("in"); /* vp0 using standard input */ Fvs0 = sf_input ("vs0"); /* vs0 */ Feps = sf_input ("epsi"); /* epsi */ Fdel = sf_input ("del"); /* delta */ Fthe = sf_input ("the"); /* theta */ /* Read/Write axes */ sf_axis az, ax; az = sf_iaxa(Fvp0,1); nvz = sf_n(az); dz = sf_d(az)*1000.0; ax = sf_iaxa(Fvp0,2); nvx = sf_n(ax); dx = sf_d(ax)*1000.0; fx=sf_o(ax)*1000.0; fz=sf_o(az)*1000.0; /* source definition */ isx=nvx/2; isz=nvz/2; //isz=nvz*2/5; /* wave modeling space */ nx=nvx; nz=nvz; nxpad=nx+2*_m; nzpad=nz+2*_m; sf_warning("fx=%f fz=%f dx=%f dz=%f",fx,fz,dx,dz); sf_warning("nx=%d nz=%d nxpad=%d nzpad=%d", nx,nz,nxpad,nzpad); vp0=sf_floatalloc2(nz,nx); vs0=sf_floatalloc2(nz,nx); epsi=sf_floatalloc2(nz,nx); del=sf_floatalloc2(nz,nx); theta=sf_floatalloc2(nz,nx); int nxz=nx*nz; mm=2*_m+1; dt2=dt*dt; isxm=isx+_m; /* source's x location */ iszm=isz+_m; /* source's z-location */ /* read velocity model */ sf_floatread(vp0[0],nxz,Fvp0); sf_floatread(vs0[0],nxz,Fvs0); sf_floatread(epsi[0],nxz,Feps); sf_floatread(del[0],nxz,Fdel); sf_floatread(theta[0],nxz,Fthe); for(i=0;i<nx;i++) for(j=0;j<nz;j++) theta[i][j] *= SF_PI/180.0; Fo1 = sf_output("out"); /* Elastic-wave x-component */ Fo2 = sf_output("Elasticz"); /* Elastic-wave z-component */ /* setup I/O files */ puthead3(Fo1, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz/1000.0, fx/1000.0, 0.0); puthead3(Fo2, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz/1000.0, fx/1000.0, 0.0); /****************begin to calculate wavefield****************/ /****************begin to calculate wavefield****************/ sf_warning("=================================================="); sf_warning("== Porpagation Using Elastic Wave Eq. =="); sf_warning("=================================================="); coeff_2dx=sf_floatalloc(mm); coeff_2dz=sf_floatalloc(mm); coeff_1dx=sf_floatalloc(mm); coeff_1dz=sf_floatalloc(mm); coeff2d(coeff_2dx,dx); coeff2d(coeff_2dz,dz); p1=sf_floatalloc2(nzpad, nxpad); p2=sf_floatalloc2(nzpad, nxpad); p3=sf_floatalloc2(nzpad, nxpad); q1=sf_floatalloc2(nzpad, nxpad); q2=sf_floatalloc2(nzpad, nxpad); q3=sf_floatalloc2(nzpad, nxpad); zero2float(p1, nzpad, nxpad); zero2float(p2, nzpad, nxpad); zero2float(p3, nzpad, nxpad); zero2float(q1, nzpad, nxpad); zero2float(q2, nzpad, nxpad); zero2float(q3, nzpad, nxpad); coeff1dmix(coeff_1dx,dx); coeff1dmix(coeff_1dz,dz); t2 = clock(); for(it=0;it<ns;it++) { t=it*dt; // 2D exploding force source (e.g., Wu's PhD for(i=-1;i<=1;i++) for(j=-1;j<=1;j++) { if(fabs(i)+fabs(j)==2) { p2[isxm+i][iszm+j]+=sqrt(2.0)*i*Ricker(t, f0, t0, A); q2[isxm+i][iszm+j]+=sqrt(2.0)*j*Ricker(t, f0, t0, A); } } // 2D equil-energy force source (e.g., Wu's PhD) /* for(i=-1;i<=1;i++) for(j=-1;j<=1;j++) { if(fabs(i)+fabs(j)==2) { if(i==-1&&j==1) q2[isxm+i][iszm+j]+=sqrt(2.0)*Ricker(t, f0, t0, A); if(i==-1&&j==-1) p2[isxm+i][iszm+j]+=-sqrt(2.0)*Ricker(t, f0, t0, A); if(i==1&&j==1) p2[isxm+i][iszm+j]+=sqrt(2.0)*Ricker(t, f0, t0, A); if(i==1&&j==-1) q2[isxm+i][iszm+j]+=-sqrt(2.0)*Ricker(t, f0, t0, A); } } */ /* fwpvtielastic: forward-propagating using original elastic equation of displacement in VTI media*/ fwpttielastic(dt2, p1, p2, p3, q1, q2, q3, coeff_2dx, coeff_2dz, coeff_1dx, coeff_1dz, dx, dz, nx, nz, nxpad, nzpad, vp0, vs0, epsi, del, theta); /******* output wavefields: component and divergence *******/ if(it==ns-1) { for(i=0;i<nx;i++) { im=i+_m; for(j=0;j<nz;j++) { jm=j+_m; sf_floatwrite(&p3[im][jm],1,Fo1); sf_floatwrite(&q3[im][jm],1,Fo2); } }/* i loop*/ }/* (it+1)%ntstep==0 */ /**************************************/ for(i=0,ii=_m;i<nx;i++,ii++) for(j=0,jj=_m;j<nz;j++,jj++) { p1[ii][jj]=p2[ii][jj]; p2[ii][jj]=p3[ii][jj]; q1[ii][jj]=q2[ii][jj]; q2[ii][jj]=q3[ii][jj]; } if(it%100==0) sf_warning("Elastic: it= %d",it); }/* it loop */ t3=clock(); timespent=(float)(t3-t2)/CLOCKS_PER_SEC; sf_warning("CPU time for wavefield extrapolation.: %f(second)",timespent); timespent=(float)(t3-t1)/(ns*CLOCKS_PER_SEC); sf_warning("All CPU time: %f(second)",timespent); free(*p1); free(*p2); free(*p3); free(*q1); free(*q2); free(*q3); free(*vp0); free(*vs0); free(*epsi); free(*del); free(*theta); exit(0); }
int main (int argc, char* argv[]) { bool top; fint1 sft; int ext; float a,n,f,da,a0,t0,dt,s; int fint,na,nx,nz,nt; sf_axis ax,az,at,aa; int ix,iz,it,ia; float **stk=NULL, **ang=NULL, *tmp=NULL, *vel=NULL; sf_file Fstk=NULL, Fang=NULL, velocity=NULL; sf_init (argc,argv); /*------------------------------------------------------------*/ Fstk = sf_input("in"); Fang = sf_output("out"); if (SF_FLOAT != sf_gettype(Fstk)) sf_error("Need float input"); az=sf_iaxa(Fstk,1); nz=sf_n(az); at=sf_iaxa(Fstk,2); nt=sf_n(at); t0=sf_o(at); dt=sf_d(at); ax=sf_iaxa(Fstk,3); nx=sf_n(ax); if (!sf_getint ("na",&na)) na=nt; /* number of angles*/ if (!sf_getfloat("da",&da)) da=90/(nt-1); /* angle sampling */ if (!sf_getfloat("a0",&a0)) a0=0.; /* angle origin */ aa = sf_maxa(na,a0,da); sf_oaxa(Fang,aa,2); if (!sf_getint("extend",&ext)) ext=4; /* tmp extension */ /*------------------------------------------------------------*/ if (!sf_getbool("top",&top)) top=false; /* velocity scaling option */ if (top) { velocity = sf_input("velocity"); vel = sf_floatalloc(nz); } else { velocity = NULL; vel = NULL; } stk = sf_floatalloc2(nz,nt); ang = sf_floatalloc2(nz,na); tmp = sf_floatalloc(nt); sft = fint1_init(ext,nt, 0); for (ix = 0; ix < nx; ix++) { sf_floatread(stk[0],nz*nt,Fstk); if (top) sf_floatread(vel,nz,velocity); /*------------------------------------------------------------*/ for (iz = 0; iz < nz; iz++) { for (it = 0; it < nt; it++) { tmp[it] = stk[it][iz]; } fint1_set(sft,tmp); for (ia=0; ia < na; ia++) { a = a0+ia*da; /* ang or p */ if (top) { s = a*vel[iz]; if (s >= 1.) { n = t0 - 10.*dt; } else { n = s/sqrtf(1.0-s*s); } } else { n = 1.0/(sinf(a/180.0*SF_PI)); /* 1/sin : no angle close to 0 */ } f = (n - t0) / dt; fint = f; if (fint >= 0 && fint < nt) { ang[ia][iz] = fint1_apply(sft,fint,f-fint,false); } else { ang[ia][iz] = 0.; } } } /*------------------------------------------------------------*/ sf_floatwrite(ang[0],nz*na,Fang); } exit (0); }
int main (int argc, char ** argv) { /* RSF variables */ bool verb; float *dat=NULL, **datf=NULL, **image=NULL, **tr=NULL, **ts=NULL, **trs=NULL; float **px=NULL, **pz=NULL; sf_file Fin=NULL, Fout=NULL, Ftt=NULL; sf_axis a1,a2,a1t,a2t,a3t,ax,az; int nf,ntaper,i1,i2,i2t,itt; float fmax,df,theta,dtheta,tg,tgtap,tmin,xs,xr,eps; aalias aa; fslice tabtt=NULL; int n1,n2,n1t,n2t,n3t,nx,nz; float o1,d1,o2,d2,o1t,d1t,o2t,d2t,o3t,d3t,ox,oz,dx,dz; sf_init(argc,argv); Fin = sf_input ("in" ); Fout = sf_output ("out" ); Ftt = sf_input ("ttfile" ); /* axes */ a1 = sf_iaxa(Fin,1); /* data */ a2 = sf_iaxa(Fin,2); /* data */ a1t = sf_iaxa(Ftt,1); /* traveltime */ a2t = sf_iaxa(Ftt,2); /* traveltime */ a3t = sf_iaxa(Ftt,3); /* traveltime */ o1 = sf_o(a1); n1 = sf_n(a1); d1 = sf_d(a1); o2 = sf_o(a2); n2 = sf_n(a2); d2 = sf_d(a2); o1t = sf_o(a1t); n1t = sf_n(a1t); d1t = sf_d(a1t); o2t = sf_o(a2t); n2t = sf_n(a2t); d2t = sf_d(a2t); o3t = sf_o(a3t); n3t = sf_n(a3t); d3t = sf_d(a3t); /* migration parameters */ if(! sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ if(! sf_getfloat("theta",&theta)) theta = 30.; /* maximum dip */ if(! sf_getfloat("dtheta",&dtheta)) dtheta = theta/3; /* taper zone */ if(dtheta>theta) dtheta=theta; if(! sf_getfloat("df",&df)) df = 5.; /* anti-aliasing sampling */ if(!sf_getfloat("fmax",&fmax)) fmax=.5/d1; if(fmax>(.5/d1)) fmax=.5/d1; if (!sf_getint("ntaper",&ntaper)) ntaper=11; if(!sf_getfloat("tmin",&tmin)) tmin=3*d1; if(!sf_getfloat("xs",&xs)) sf_error("missing xs parameter\n"); /* image parameters */ if (!sf_getint("nx",&nx)) nx=n2t; if(!sf_getfloat("ox",&ox)) ox=o2t; if(!sf_getfloat("dx",&dx)) dx=d2t; if (!sf_getint("nz",&nz)) nz=n1t; if(!sf_getfloat("oz",&oz)) oz=o1t; if(!sf_getfloat("dz",&dz)) dz=d1t; /* checking dimensions */ if((dx!=d2t)||(dz!=d1t)) sf_error("sampling interval have to be the same in:\n" " image and traveltime file\n"); if(ox<o2t) ox=o2t; if(oz<o1t) oz=o1t; if((ox+(nx-1)*dx)>(o2t+(n2t-1)*d2t)) nx=floor(((o2t+(n2t-1)*d2t)-ox)/dx)+1; if((oz+(nz-1)*dz)>(o1t+(n1t-1)*d1t)) nz=floor(((o1t+(n1t-1)*d1t)-oz)/dz)+1; /* output axis */ ax = sf_maxa(nx,ox,dx); if(verb) sf_raxa(ax); az = sf_maxa(nz,oz,dz); if(verb) sf_raxa(az); sf_oaxa(Fout,az,1); sf_oaxa(Fout,ax,2); /* anti-aliasing */ /* df = fmax; */ nf = initAalias(-1,verb,fmax,df,n1,d1,&aa); /* fprintf(stderr,"forcing nf=%d df=%f\n",nf,df); */ /* aperture angle */ tg = tan(SF_PI*theta/180); tgtap = tan(SF_PI*(theta-dtheta)/180); if(verb) sf_warning("tgmax=%f tgtap=%f",tg,tgtap); /* allocating */ dat = sf_floatalloc(n1); image = sf_floatalloc2(nz,nx); datf = sf_floatalloc2 (n1,nf); ts = sf_floatalloc2(n1t,n2t); tr = sf_floatalloc2(n1t,n2t); trs = sf_floatalloc2(n1t,n2t); px = sf_floatalloc2(n1t,n2t); pz = sf_floatalloc2(n1t,n2t); if(verb) sf_warning("initializing traveltime loading"); /* initializing traveltime maps */ tabtt = fslice_init(n1t*n2t,n3t,sizeof(float)); fslice_load(Ftt,tabtt,SF_FLOAT); if(verb) sf_warning("traveltime loading has finished"); /* reading the source-slice from traveltime table */ eps = .01*d2; itt = floor((xs+eps-o3t)/d3t); fslice_get(tabtt,itt,ts[0]); if(verb) sf_warning("traveltime table from source was read"); for(i2=0;i2<n2;i2++) { sf_floatread(dat,n1,Fin); xr = o2+i2*d2; if((xr>=o3t)&&(xr<(o3t+n3t*d3t))) { for (i1=n1-ntaper;i1<n1;i1++) dat[i1]=(n1-i1-1)*dat[i1]/ntaper; loadBank(aa,dat,datf); /* reading the receiver-slice of traveltime table */ /* itt = floor((o2-o2t)/d2)+i2; */ itt = floor((xr+eps-o3t)/d3t); fslice_get(tabtt,itt,tr[0]); for(i2t=0;i2t<n2t;i2t++) for(i1=0;i1<n1t;i1++) trs[i2t][i1]=ts[i2t][i1]+tr[i2t][i1]; derive_1(n1t,n2t,d1t,trs,pz); derive_2(n1t,n2t,d2t,trs,px); spreadSR(nf,fmax,df,tg,tgtap, n1,o1,d1, nx,ox,dx, nz,oz,dz, o1t,o2t, px,pz,tr,ts,datf,image); if(verb) fprintf(stderr,"+"); }else{ if(verb) fprintf(stderr,".");} } sf_floatwrite(image[0],n1*n2,Fout); fprintf( stderr," \n finished processing \n"); exit(0); }
int main(int argc, char* argv[]) { /* Laplacian coefficients */ float c0=-30./12.,c1=+16./12.,c2=- 1./12.; bool verb,free, ifoneway, ifsponge; /* verbose flag */ sf_file Fw=NULL,Fv=NULL,Fr=NULL,Fo=NULL; /* I/O files */ sf_axis at,az,ax; /* cube axes */ int it,iz,ix,nb; /* index variables */ int nt,nz,nx; float dt,dz,dx,idx,idz,dt2; float *ww,**vv,**rr; /* I/O arrays*/ float **um,**uo,**up,**ud;/* tmp arrays */ #ifdef _OPENMP /* Testing for OpenMP */ double start_time, end_time; #endif sf_init(argc,argv); /* OMP parameters */ #ifdef _OPENMP omp_init(); #endif if(! sf_getbool("verb",&verb)) verb=0; if(! sf_getbool("free",&free)) free=false; if(! sf_getbool("ifoneway",&ifoneway)) ifoneway=true; if(! sf_getbool("ifsponge",&ifsponge)) ifsponge=true; if(! sf_getint("nb",&nb)) nb=5; /* setup I/O files */ Fw = sf_input ("in" ); Fo = sf_output("out"); Fv = sf_input ("vel"); Fr = sf_input ("ref"); /* Read/Write axes */ at = sf_iaxa(Fw,1); nt = sf_n(at); dt = sf_d(at); az = sf_iaxa(Fv,1); nz = sf_n(az); dz = sf_d(az); ax = sf_iaxa(Fv,2); nx = sf_n(ax); dx = sf_d(ax); sf_oaxa(Fo,az,1); sf_oaxa(Fo,ax,2); sf_oaxa(Fo,at,3); dt2 = dt*dt; idz = 1/(dz*dz); idx = 1/(dx*dx); /* read wavelet, velocity & reflectivity */ ww=sf_floatalloc(nt); sf_floatread(ww ,nt ,Fw); vv=sf_floatalloc2(nz,nx); sf_floatread(vv[0],nz*nx,Fv); rr=sf_floatalloc2(nz,nx); sf_floatread(rr[0],nz*nx,Fr); /* allocate temporary arrays */ um=sf_floatalloc2(nz,nx); uo=sf_floatalloc2(nz,nx); up=sf_floatalloc2(nz,nx); ud=sf_floatalloc2(nz,nx); for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { um[ix][iz]=0; uo[ix][iz]=0; up[ix][iz]=0; ud[ix][iz]=0; } } /* MAIN LOOP */ if(verb) fprintf(stderr,"\n"); /* Starting timer */ #ifdef _OPENMP start_time = omp_get_wtime(); #endif for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); /* 4th order laplacian */ if(ifoneway) { #ifdef _OPENMP #pragma omp parallel for default(none) \ private(ix,iz) \ shared(ud,nb,uo,c0,c1,c2,nx,nz,idx,idz) #endif for (iz=nb; iz<nz-nb; iz++) { for (ix=nb; ix<nx-nb; ix++) { ud[ix][iz] = c0* uo[ix ][iz ] * (idx+idz) + c1*(uo[ix-1][iz ] + uo[ix+1][iz ])*idx + c2*(uo[ix-2][iz ] + uo[ix+2][iz ])*idx + c1*(uo[ix ][iz-1] + uo[ix ][iz+1])*idz + c2*(uo[ix ][iz-2] + uo[ix ][iz+2])*idz; } } }else { #ifdef _OPENMP #pragma omp parallel for default(none) \ private(ix,iz) \ shared(ud,uo,c0,c1,c2,nx,nz,idx,idz) #endif for (iz=2; iz<nz-2; iz++) { for (ix=2; ix<nx-2; ix++) { ud[ix][iz] = c0* uo[ix ][iz ] * (idx+idz) + c1*(uo[ix-1][iz ] + uo[ix+1][iz ])*idx + c2*(uo[ix-2][iz ] + uo[ix+2][iz ])*idx + c1*(uo[ix ][iz-1] + uo[ix ][iz+1])*idz + c2*(uo[ix ][iz-2] + uo[ix ][iz+2])*idz; } } } /* inject wavelet */ #ifdef _OPENMP #pragma omp parallel for default(none) \ private(ix,iz) \ shared(nx,nz,ww,rr,ud,it) #endif for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { ud[ix][iz] -= ww[it] * rr[ix][iz]; } } /* scale by velocity */ #ifdef _OPENMP #pragma omp parallel for default(none) \ private(ix,iz) \ shared(ud,vv,nx,nz) #endif for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { ud[ix][iz] *= vv[ix][iz]*vv[ix][iz]; } } /* time step */ #ifdef _OPENMP #pragma omp parallel for default(none) \ private(ix,iz) \ shared(up,uo,um,ud,nx,nz,dt2) #endif for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { up[ix][iz] = 2*uo[ix][iz] - um[ix][iz] + ud[ix][iz] * dt2; um[ix][iz] = uo[ix][iz]; uo[ix][iz] = up[ix][iz]; } } /* one-way abc apply */ if(ifoneway) {oneway_abc(uo,um,vv,nx,nz,nb,dx,dz,dt,free);} if(ifsponge) {sponge_abc(um,nx,nz,nb); sponge_abc(uo,nx,nz,nb);} /* write wavefield to output */ sf_floatwrite(uo[0],nz*nx,Fo); } /* Ending timer */ #ifdef _OPENMP end_time = omp_get_wtime(); sf_warning("Elapsed time is %f.",end_time-start_time); #endif if(verb) fprintf(stderr,"\n"); sf_close(); exit (0); }
int main(int argc, char* argv[]) { clock_t tstart,tend; double duration; /*flag*/ bool verb; bool wantwf; bool wantrecord; /*I/O*/ sf_file Ffvel, Ffden, Fbvel, Fbden; sf_file Fsrc,/*wave field*/ Frcd/*record*/; sf_file Ftmpwf, Ftmpbwf; sf_file Fimg1, Fimg2; sf_file FGx, FGz, Fsxx, Fsxz, Fszx, Fszz; sf_axis at, ax, az; /*grid index variables*/ int nx, nz, nxz, nt, wfnt; int ix, iz, it; int nxb, nzb; float dt, dx, dz, wfdt; float ox, oz; /*source/geophone location*/ float slx, slz; int spx, spz; float gdep; int gp; int ginter, gn; /*SG LFD coefficient*/ int lenx, lenz; int marg; /*Modle*/ float **fvel, **fden, **fc11; float **bvel, **bden, **bc11; float ***wavefld, **record; float **img1, **img2; int snpint; /*source*/ bool srcdecay; int srcrange; float srctrunc; /*pml boundary*/ int pmlout, pmld0, decaybegin; bool decay, freesurface; /*memoray*/ //float memneed; int tmpint; //float tmpfloat; tstart = clock(); sf_init(argc, argv); if (!sf_getbool("verb", &verb)) verb=false; /*verbosity*/ if (!sf_getbool("wantwf", &wantwf)) wantwf=false; /*output forward and backward wavefield*/ if (!sf_getbool("wantrecord", &wantrecord)) wantrecord=true; /*if n, using record data generated by this program */ /*Set I/O file*/ Fsrc = sf_input("in"); /*source wavelet*/ Ffvel = sf_input("fvel"); /*forward velocity*/ Ffden = sf_input("fden"); /*forward density*/ Fbvel = sf_input("bvel"); /*backward velocity*/ Fbden = sf_input("bden"); /*backward velocity*/ if (wantrecord) { Frcd = sf_input("rec"); /*record*/ } else { Frcd = sf_output("rec"); /*record*/ } Fimg1 = sf_output("out"); /*Imaging*/ Fimg2 = sf_output("img2"); /*Imaging*/ if (wantwf) { Ftmpwf = sf_output("tmpwf");/*wavefield snap*/ Ftmpbwf = sf_output("tmpbwf"); } FGx = sf_input("Gx"); FGz = sf_input("Gz"); Fsxx = sf_input("sxx"); Fsxz = sf_input("sxz"); Fszx = sf_input("szx"); Fszz = sf_input("szz"); if (SF_FLOAT != sf_gettype(Ffvel)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(Ffden)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(Fbvel)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(Fbden)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(Fsrc)) sf_error("Need float input"); /*--- parameters of source ---*/ srcpar srcp; srcp = createsrc(); at = sf_iaxa(Fsrc, 1); nt = sf_n(at); dt = sf_d(at); if (!sf_getbool("srcdecay", &srcdecay)) srcdecay=SRCDECAY; /*source decay*/ if (!sf_getint("srcrange", &srcrange)) srcrange=SRCRANGE; /*source decay range*/ if (!sf_getfloat("srctrunc", &srctrunc)) srctrunc=SRCTRUNC; /*trunc source after srctrunc time (s)*/ srcp->nt = nt; srcp->dt = dt; srcp->decay = srcdecay; srcp->range=srcrange; srcp->trunc=srctrunc; loadsrc(srcp, Fsrc); /*--- parameters of SG LFD Coefficient ---*/ ax = sf_iaxa(Ffvel, 2); nxb = sf_n(ax); dx = sf_d(ax); ox = sf_o(ax); az = sf_iaxa(Ffvel, 1); nzb = sf_n(az); dz = sf_d(az); oz = sf_o(az); if (!sf_histint(FGx, "n1", &nxz)) sf_error("No n1= in input"); if (nxz != nxb*nzb) sf_error (" Need nxz = nxb*nzb"); if (!sf_histint(FGx,"n2", &lenx)) sf_error("No n2= in input"); if (!sf_histint(FGz,"n2", &lenz)) sf_error("No n2= in input"); initsglfdcoe(nxb, nzb, lenx, lenz); loadcoe(nzb, nxb, FGx, FGz); loadschm(Fsxx, Fsxz, Fszx, Fszz); marg = getmarg(); /* pml parameters */ pmlpar pmlp; pmlp = creatpmlpar(); if (!sf_getint("pmlsize", &pmlout)) pmlout=PMLOUT; /* size of PML layer */ if (!sf_getint("pmld0", &pmld0)) pmld0=PMLD0; /* PML parameter */ if (!sf_getbool("decay",&decay)) decay=DECAY_FLAG; /* Flag of decay boundary condtion: 1 = use ; 0 = not use */ if (!sf_getint("decaybegin",&decaybegin)) decaybegin=DECAY_BEGIN; /* Begin time of using decay boundary condition */ if (!sf_getbool("freesurface", &freesurface)) freesurface=false; /*free surface*/ nx = nxb - 2*pmlout - 2*marg; nz = nzb - 2*pmlout - 2*marg; pmlp->pmlout = pmlout; pmlp->pmld0 = pmld0; pmlp->decay = decay; pmlp->decaybegin = decaybegin; pmlp->freesurface = freesurface; /*Geometry parameters*/ geopar geop; geop = creategeo(); /*source loaction parameters*/ slx = -1.0; spx = -1; slz = -1.0; spz = -1; gdep = -1.0; gp = 0; if (!sf_getfloat("slx", &slx)) ; /*source location x */ if (!sf_getint("spx", &spx)); /*source location x (index)*/ if((slx<0 && spx <0) || (slx>=0 && spx >=0 )) sf_error("Need src location"); if (slx >= 0 ) spx = (int)((slx-ox)/dx+0.5); if (!sf_getfloat("slz", &slz)) ; /* source location z */ if (!sf_getint("spz", &spz)) ; /*source location z (index)*/ if((slz<0 && spz <0) || (slz>=0 && spz >=0 )) sf_error("Need src location"); if (slz >= 0 ) spz = (int)((slz-ox)/dz+0.5); if (!sf_getfloat("gdep", &gdep)) ; /* recorder depth on grid*/ if (!sf_getint("gp", &gp)) ; /* recorder depth on index*/ if ( gdep>=oz) { gp = (int)((gdep-oz)/dz+0.5);} if (gp < 0.0) sf_error("gdep need to be >=oz"); /*source and receiver location*/ if (!sf_getint("ginter", &ginter)) ginter = 1; /*geophone interval*/ gn = (nx-1)/ginter+1; /*ceil*/ if (!sf_getint("snapinter", &snpint)) snpint=10; /* snap interval */ /*check record data*/ if (wantrecord){ sf_histint(Frcd,"n1", &tmpint); if (tmpint != nt ) sf_error("Error parameter n1 in record!"); sf_histint(Frcd,"n2", &tmpint); if (tmpint != gn ) sf_error("Error parameter n2 in record!"); } geop->nx = nx; geop->nz = nz; geop->nxb = nxb; geop->nzb = nzb; geop->dx = dx; geop->dz = dz; geop->ox = ox; geop->oz = oz; geop->snpint = snpint; geop->spx = spx; geop->spz = spz; geop->gp = gp; geop->gn = gn; geop->ginter = ginter; /* wavefield and record */ wfnt = (int)(nt-1)/snpint+1; wfdt = dt*snpint; record = sf_floatalloc2(nt, gn); wavefld = sf_floatalloc3(nz, nx, wfnt); /* read model */ fvel = sf_floatalloc2(nzb, nxb); fden = sf_floatalloc2(nzb, nxb); fc11 = sf_floatalloc2(nzb, nxb); /*image*/ img1 = sf_floatalloc2(nz, nx); img2 = sf_floatalloc2(nz, nx); sf_floatread(fvel[0], nxz, Ffvel); sf_floatread(fden[0], nxz, Ffden); for (ix = 0; ix < nxb; ix++) { for ( iz= 0; iz < nzb; iz++) { fc11[ix][iz] = fden[ix][iz]*fvel[ix][iz]*fvel[ix][iz]; if(fc11[ix][iz] == 0.0) sf_warning("c11=0: ix=%d iz%d", ix, iz); } } bvel = sf_floatalloc2(nzb, nxb); bden = sf_floatalloc2(nzb, nxb); bc11 = sf_floatalloc2(nzb, nxb); sf_floatread(bvel[0], nxz, Fbvel); sf_floatread(bden[0], nxz, Fbden); for (ix = 0; ix < nxb; ix++) { for ( iz= 0; iz < nzb; iz++) { bc11[ix][iz] = bden[ix][iz]*bvel[ix][iz]*bvel[ix][iz]; if(bc11[ix][iz] == 0.0) sf_warning("c11=0: ix=%d iz%d", ix, iz); } } if (verb) { sf_warning("============================"); sf_warning("nx=%d nz=%d nt=%d", geop->nx, geop->nz, srcp->nt); sf_warning("dx=%f dz=%f dt=%f", geop->dx, geop->dz, srcp->dt); sf_warning("lenx=%d lenz=%d marg=%d pmlout=%d", lenx, lenz, marg, pmlout); sf_warning("srcdecay=%d srcrange=%d",srcp->decay,srcp->range); sf_warning("spx=%d spz=%d gp=%d snpint=%d", spx, spz, gp, snpint); sf_warning("wfdt=%f wfnt=%d ", wfdt, wfnt); sf_warning("============================"); } /* write record */ sf_setn(ax, gn); sf_setn(az, nz); if(!wantrecord) { sf_oaxa(Frcd, at, 1); sf_oaxa(Frcd, ax, 2); } /*wavefiel and image*/ sf_setn(ax,nx); if (wantwf) { /*write temp wavefield */ sf_setn(ax, nx); sf_setn(at, wfnt); sf_setd(at, wfdt); sf_oaxa(Ftmpwf, az, 1); sf_oaxa(Ftmpwf, ax, 2); sf_oaxa(Ftmpwf, at, 3); /*write temp wavefield */ sf_oaxa(Ftmpbwf, az, 1); sf_oaxa(Ftmpbwf, ax, 2); sf_oaxa(Ftmpbwf, at, 3); } /*write image*/ sf_oaxa(Fimg1, az, 1); sf_oaxa(Fimg1, ax, 2); sf_oaxa(Fimg2, az, 1); sf_oaxa(Fimg2, ax, 2); sglfdfor2(wavefld, record, verb, fden, fc11, geop, srcp, pmlp); if(wantrecord) { sf_floatread(record[0], gn*nt, Frcd); } sglfdback2(img1, img2, wavefld, record, verb, wantwf, bden, bc11, geop, srcp, pmlp, Ftmpbwf); if (!wantrecord) { for (ix=0; ix<gn; ix++) sf_floatwrite(record[ix], nt, Frcd); } if (wantwf) { for (it=0; it<wfnt; it++) for ( ix=0; ix<nx; ix++) sf_floatwrite(wavefld[it][ix], nz, Ftmpwf); } for (ix=0; ix<nx; ix++) sf_floatwrite(img1[ix], nz, Fimg1); for (ix=0; ix<nx; ix++) sf_floatwrite(img2[ix], nz, Fimg2); freertm(); tend = clock(); duration=(double)(tend-tstart)/CLOCKS_PER_SEC; sf_warning(">> The CPU time of sfsglfd2 is: %f seconds << ", duration); exit(0); }
int main(int argc, char* argv[]) { bool verb; int it,iz,im,ik,ix,i,j; /* index variables */ int nt,nz,nx, m2, nk, nzx, nz2, nx2, nzx2, n2, pad1; sf_complex c; float *rr; /* I/O arrays*/ sf_complex *ww, *cwave, *cwavem; sf_complex **wave, *curr; float *rcurr; sf_file Fw,Fr,Fo; /* I/O files */ sf_axis at,az,ax; /* cube axes */ sf_complex **lt, **rt; sf_file left, right; sf_init(argc,argv); if(!sf_getbool("verb",&verb)) verb=false; /* verbosity */ /* setup I/O files */ Fw = sf_input ("in" ); Fo = sf_output("out"); Fr = sf_input ("ref"); if (SF_COMPLEX != sf_gettype(Fw)) sf_error("Need complex input"); if (SF_FLOAT != sf_gettype(Fr)) sf_error("Need float ref"); sf_settype(Fo,SF_FLOAT); /* Read/Write axes */ at = sf_iaxa(Fw,1); nt = sf_n(at); az = sf_iaxa(Fr,1); nz = sf_n(az); ax = sf_iaxa(Fr,2); nx = sf_n(ax); sf_oaxa(Fo,az,1); sf_oaxa(Fo,ax,2); sf_oaxa(Fo,at,3); if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ nk = cfft2_init(pad1,nz,nx,&nz2,&nx2); nzx = nz*nx; nzx2 = nz2*nx2; /* propagator matrices */ left = sf_input("left"); right = sf_input("right"); if (!sf_histint(left,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in left",nzx); if (!sf_histint(left,"n2",&m2)) sf_error("Need n2= in left"); if (!sf_histint(right,"n1",&n2) || n2 != m2) sf_error("Need n1=%d in right",m2); if (!sf_histint(right,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in right",nk); // if (!sf_histint(Fw,"n1",&nxx)) sf_error("No n1= in input"); lt = sf_complexalloc2(nzx,m2); rt = sf_complexalloc2(m2,nk); sf_complexread(lt[0],nzx*m2,left); sf_complexread(rt[0],m2*nk,right); // sf_fileclose(left); // sf_fileclose(right); /* read wavelet & reflectivity */ ww=sf_complexalloc(nt); sf_complexread(ww,nt ,Fw); rr=sf_floatalloc(nzx); sf_floatread(rr,nzx,Fr); curr = sf_complexalloc(nzx2); rcurr = sf_floatalloc(nzx2); cwave = sf_complexalloc(nk); cwavem = sf_complexalloc(nk); wave = sf_complexalloc2(nzx2,m2); for (iz=0; iz < nzx2; iz++) { curr[iz] = sf_cmplx(0.,0.); rcurr[iz]= 0.; } /* MAIN LOOP */ for (it=0; it<nt; it++) { if(verb) sf_warning("it=%d;",it); /* matrix multiplication */ cfft2(curr,cwave); for (im = 0; im < m2; im++) { for (ik = 0; ik < nk; ik++) { #ifdef SF_HAS_COMPLEX_H cwavem[ik] = cwave[ik]*rt[ik][im]; #else cwavem[ik] = sf_cmul(cwave[ik],rt[ik][im]); //complex multiplies complex #endif // sf_warning("realcwave=%g, imagcwave=%g", crealf(cwavem[ik]),cimagf(cwavem[ik])); } icfft2(wave[im],cwavem); } for (ix = 0; ix < nx; ix++) { for (iz=0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ #ifdef SF_HAS_COMPLEX_H c = ww[it] * rr[i]; // source term #else c = sf_crmul(ww[it], rr[i]); // source term #endif for (im = 0; im < m2; im++) { #ifdef SF_HAS_COMPLEX_H c += lt[im][i]*wave[im][j]; #else c = sf_cadd(c,sf_cmul(lt[im][i], wave[im][j])); #endif } curr[j] = c; rcurr[j] = crealf(c); // rcurr[j] = cimagf(c); } /* write wavefield to output */ sf_floatwrite(rcurr+ix*nz2,nz,Fo); } } if(verb) sf_warning("."); exit (0); }
int main(int argc, char* argv[]) { /*survey parameters*/ int nx, nz; float dx, dz; int n_srcs; int *spx, *spz; int gpz, gpx, gpl; int gpz_v, gpx_v, gpl_v; int snap; /*fft related*/ bool cmplx; int pad1; /*absorbing boundary*/ bool abc; int nbt, nbb, nbl, nbr; float ct,cb,cl,cr; /*source parameters*/ int src; /*source type*/ int nt,ntsnap; float dt,*f0,*t0,*A; /*misc*/ bool verb, ps, mig; float vref; pspar par; int nx1, nz1; /*domain of interest*/ int it; float *vel,**dat,**dat_v,**wvfld,*img; /*velocity profile*/ sf_file Fi,Fo,Fd,Fd_v,snaps; /* I/O files */ sf_axis az,ax; /* cube axes */ sf_init(argc,argv); if (!sf_getint("snap",&snap)) snap=0; /* interval for snapshots */ if (!sf_getbool("cmplx",&cmplx)) cmplx=true; /* use complex fft */ if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ if(!sf_getbool("abc",&abc)) abc=false; /* absorbing flag */ if (abc) { if(!sf_getint("nbt",&nbt)) sf_error("Need nbt!"); if(!sf_getint("nbb",&nbb)) nbb = nbt; if(!sf_getint("nbl",&nbl)) nbl = nbt; if(!sf_getint("nbr",&nbr)) nbr = nbt; if(!sf_getfloat("ct",&ct)) sf_error("Need ct!"); if(!sf_getfloat("cb",&cb)) cb = ct; if(!sf_getfloat("cl",&cl)) cl = ct; if(!sf_getfloat("cr",&cr)) cr = ct; } else { nbt = 0; nbb = 0; nbl = 0; nbr = 0; ct = 0; cb = 0; cl = 0; cr = 0; } if (!sf_getbool("verb",&verb)) verb=false; /* verbosity */ if (!sf_getbool("ps",&ps)) ps=false; /* use pseudo-spectral */ if (ps) sf_warning("Using pseudo-spectral..."); else sf_warning("Using pseudo-analytical..."); if (!sf_getbool("mig",&mig)) mig=false; /* use pseudo-spectral */ if (mig) sf_warning("Time-reversal propagation"); else sf_warning("Forward modeling"); if (!sf_getfloat("vref",&vref)) vref=1500; /* reference velocity (default using water) */ /* setup I/O files */ Fi = sf_input ("in"); Fo = sf_output("out"); if (mig) { gpl = -1; gpl_v = -1; if (NULL==sf_getstring("dat") && NULL==sf_getstring("dat_v")) sf_error("Need Data!"); if (NULL!=sf_getstring("dat")) { Fd = sf_input("dat"); sf_histint(Fd,"n1",&nt); sf_histfloat(Fd,"d1",&dt); sf_histint(Fd,"n2",&gpl); } else Fd = NULL; if (NULL!=sf_getstring("dat_v")) { Fd_v = sf_input("dat_v"); sf_histint(Fd_v,"n1",&nt); sf_histfloat(Fd_v,"d1",&dt); sf_histint(Fd_v,"n2",&gpl_v); } else Fd_v = NULL; src = -1; n_srcs = -1; spx = NULL; spz = NULL; f0 = NULL; t0 = NULL; A = NULL; } else { Fd = NULL; if (!sf_getint("nt",&nt)) sf_error("Need nt!"); if (!sf_getfloat("dt",&dt)) sf_error("Need dt!"); if (!sf_getint("gpl",&gpl)) gpl = -1; /* geophone length */ if (!sf_getint("gpl_v",&gpl_v)) gpl_v = -1; /* geophone height */ if (!sf_getint("src",&src)) src=0; /* source type */ if (!sf_getint("n_srcs",&n_srcs)) n_srcs=1; /* source type */ spx = sf_intalloc(n_srcs); spz = sf_intalloc(n_srcs); f0 = sf_floatalloc(n_srcs); t0 = sf_floatalloc(n_srcs); A = sf_floatalloc(n_srcs); if (!sf_getints("spx",spx,n_srcs)) sf_error("Need spx!"); /* shot position x */ if (!sf_getints("spz",spz,n_srcs)) sf_error("Need spz!"); /* shot position z */ if (!sf_getfloats("f0",f0,n_srcs)) sf_error("Need f0! (e.g. 30Hz)"); /* wavelet peak freq */ if (!sf_getfloats("t0",t0,n_srcs)) sf_error("Need t0! (e.g. 0.04s)"); /* wavelet time lag */ if (!sf_getfloats("A",A,n_srcs)) sf_error("Need A! (e.g. 1)"); /* wavelet amplitude */ } if (!sf_getint("gpx",&gpx)) gpx = -1; /* geophone position x */ if (!sf_getint("gpz",&gpz)) gpz = -1; /* geophone position z */ if (!sf_getint("gpx_v",&gpx_v)) gpx_v = -1; /* geophone position x */ if (!sf_getint("gpz_v",&gpz_v)) gpz_v = -1; /* geophone position z */ if (SF_FLOAT != sf_gettype(Fi)) sf_error("Need float input"); /* Read/Write axes */ az = sf_iaxa(Fi,1); nz = sf_n(az); dz = sf_d(az); ax = sf_iaxa(Fi,2); nx = sf_n(ax); dx = sf_d(ax); nz1 = nz-nbt-nbb; nx1 = nx-nbl-nbr; if (gpx==-1) gpx = nbl; if (gpz==-1) gpz = nbt; if (gpl==-1) gpl = nx1; if (gpx_v==-1) gpx_v = nbl; if (gpz_v==-1) gpz_v = nbt; if (gpl_v==-1) gpl_v = nz1; ntsnap=0; if (snap) for (it=0;it<nt;it++) if (it%snap==0) ntsnap++; if (mig) { /*output final wavefield*/ sf_setn(az,nz1); sf_setn(ax,nx1); sf_oaxa(Fo,az,1); sf_oaxa(Fo,ax,2); sf_settype(Fo,SF_FLOAT); } else { /*output data*/ sf_setn(ax,gpl); /*output horizontal data is mandatory*/ sf_putint(Fo,"n1",nt); sf_putfloat(Fo,"d1",dt); sf_putfloat(Fo,"o1",0.); sf_putstring(Fo,"label1","Time"); sf_putstring(Fo,"unit1","s"); sf_oaxa(Fo,ax,2); sf_settype(Fo,SF_FLOAT); /*output vertical data is optional*/ if (NULL!=sf_getstring("dat_v")) { Fd_v = sf_output("dat_v"); sf_setn(az,gpl_v); sf_putint(Fd_v,"n1",nt); sf_putfloat(Fd_v,"d1",dt); sf_putfloat(Fd_v,"o1",0.); sf_putstring(Fd_v,"label1","Time"); sf_putstring(Fd_v,"unit1","s"); sf_oaxa(Fd_v,az,2); sf_settype(Fd_v,SF_FLOAT); } else Fd_v = NULL; } if (snap > 0) { snaps = sf_output("snaps"); /* (optional) snapshot file */ sf_setn(az,nz1); sf_setn(ax,nx1); sf_oaxa(snaps,az,1); sf_oaxa(snaps,ax,2); sf_putint(snaps,"n3",ntsnap); sf_putfloat(snaps,"d3",dt*snap); sf_putfloat(snaps,"o3",0.); sf_putstring(snaps,"label3","Time"); sf_putstring(snaps,"unit3","s"); } else snaps = NULL; par = (pspar) sf_alloc(1,sizeof(*par)); vel = sf_floatalloc(nz*nx); if (mig && NULL==Fd) dat = NULL; else dat = sf_floatalloc2(nt,gpl); if (NULL!=Fd_v) dat_v = sf_floatalloc2(nt,gpl_v); else dat_v = NULL; if (mig) img = sf_floatalloc(nz1*nx1); else img = NULL; if (snap>0) wvfld = sf_floatalloc2(nx1*nz1,ntsnap); else wvfld = NULL; sf_floatread(vel,nz*nx,Fi); if (mig) { if (NULL!=Fd) sf_floatread(dat[0],gpl*nt,Fd); if (NULL!=Fd_v) sf_floatread(dat_v[0],gpl_v*nt,Fd_v); } /*passing the parameters*/ par->nx = nx; par->nz = nz; par->dx = dx; par->dz = dz; par->n_srcs= n_srcs; par->spx = spx; par->spz = spz; par->gpz = gpz; par->gpx = gpx; par->gpl = gpl; par->gpz_v = gpz_v; par->gpx_v = gpx_v; par->gpl_v = gpl_v; par->snap = snap; par->cmplx = cmplx; par->pad1 = pad1; par->abc = abc; par->nbt = nbt; par->nbb = nbb; par->nbl = nbl; par->nbr = nbr; par->ct = ct; par->cb = cb; par->cl = cl; par->cr = cr; par->src = src; par->nt = nt; par->dt = dt; par->f0 = f0; par->t0 = t0; par->A = A; par->verb = verb; par->ps = ps; par->vref = vref; /*do the work*/ psp(wvfld, dat, dat_v, img, vel, par, mig); if (mig) { sf_floatwrite(img,nz1*nx1,Fo); } else { sf_floatwrite(dat[0],gpl*nt,Fo); if (NULL!=Fd_v) sf_floatwrite(dat_v[0],gpl_v*nt,Fd_v); } if (snap>0) sf_floatwrite(wvfld[0],nz1*nx1*ntsnap,snaps); exit (0); }
int main (int argc, char *argv[]) { int adj; /* forward or adjoint */ int eic; /* EIC or CIC */ bool verb; /* verbosity */ float eps; /* dip filter constant */ int nrmax; /* number of reference velocities */ float dtmax; /* time error */ int pmx,pmy; /* padding in the k domain */ int tmx,tmy; /* boundary taper size */ int nhx, nhy, nhz, nht, nc; int nhx2,nhy2,nhz2,nht2; float dht, oht; sf_axis amx,amy,az; sf_axis alx,aly; sf_axis aw,ae,ac,aa; sf_axis ahx,ahy,ahz,aht; /* I/O files */ sf_file Bws=NULL; /* background wavefield file Bws */ sf_file Bwr=NULL; /* background wavefield file Bwr */ sf_file Bs=NULL; /* background slowness file Bs */ sf_file Ps=NULL; /* slowness perturbation file Ps */ sf_file Pi=NULL; /* image perturbation file Pi */ sf_file Fc=NULL; /* CIP coordinates */ sf_file Pws=NULL; /* perturbed wavefield file Pws */ sf_file Pwr=NULL; /* perturbed wavefield file Pwr */ sf_file Pti=NULL; int ompnth=1; wexcub3d cub; /* wavefield hypercube */ wexcip3d cip; /* CIP gathers */ wextap3d tap; /* tapering */ wexssr3d ssr; /* SSR operator */ wexlsr3d lsr; /* LSR operator */ wexslo3d slo; /* slowness */ wexmvaop3d mva; float dsmax; /*------------------------------------------------------------*/ sf_init(argc,argv); /* OMP parameters */ #ifdef _OPENMP ompnth=omp_init(); #endif if (!sf_getbool( "verb",&verb )) verb = true; /* verbosity flag */ if (!sf_getint( "adj",&adj )) sf_error("Specify adjoint!"); /* y=ADJ Back-projection; n=FWD Forward Scattering */ if (!sf_getint( "feic",&eic )) sf_error("Specify EIC!"); /* extended I.C. flag */ if (!sf_getfloat( "eps",&eps )) eps = 0.01; /* stability parameter */ if (!sf_getint( "nrmax",&nrmax)) nrmax = 1; /* max number of refs */ if (!sf_getfloat("dtmax",&dtmax)) dtmax = 0.004; /* max time error */ if (!sf_getint( "pmx",&pmx )) pmx = 0; /* padding on x */ if (!sf_getint( "pmy",&pmy )) pmy = 0; /* padding on y */ if (!sf_getint( "tmx",&tmx )) tmx = 0; /* taper on x */ if (!sf_getint( "tmy",&tmy )) tmy = 0; /* taper on y */ ae = sf_maxa(1,0,1); nhx=nhy=nhz=nht=nc=nhx2=nhy2=nhz2=nht2=0; oht = dht = 0.0; /*------------------------------------------------------------*/ /* slowness */ Bs = sf_input("slo"); alx = sf_iaxa(Bs,1); sf_setlabel(alx,"lx"); aly = sf_iaxa(Bs,2); sf_setlabel(aly,"ly"); az = sf_iaxa(Bs,3); sf_setlabel(az, "z"); /*------------------------------------------------------------*/ /* input file */ if(adj) Pi = sf_input("in"); else Ps = sf_input("in"); /*------------------------------------------------------------*/ /* wavefield */ Bws = sf_input("swfl"); Bwr = sf_input("rwfl"); amx = sf_iaxa(Bws,1); sf_setlabel(amx,"mx"); amy = sf_iaxa(Bws,2); sf_setlabel(amy,"my"); aw = sf_iaxa(Bws,4); sf_setlabel(aw ,"w" ); Pws = sf_tmpfile(NULL); sf_settype(Pws,SF_COMPLEX); Pwr = sf_tmpfile(NULL); sf_settype(Pwr,SF_COMPLEX); /*------------------------------------------------------------*/ cub = wex_cube(verb, amx,amy,az, alx,aly, aw, ae, eps, ompnth); dsmax = dtmax/cub->az.d; /*------------------------------------------------------------*/ /* init structures */ tap = wextap_init(cub->amx.n, cub->amy.n, 1, SF_MIN(tmx,cub->amx.n-1), /* tmx */ SF_MIN(tmy,cub->amy.n-1), /* tmy */ 0, true,true,false); slo = wexslo_init(cub,Bs,nrmax,dsmax); ssr = wexssr_init(cub,slo,pmx,pmy,tmx,tmy,dsmax); lsr = wexlsr_init(cub,pmx,pmy,dsmax); /*------------------------------------------------------------*/ Pti = sf_tmpfile(NULL); sf_settype(Pti,SF_COMPLEX); /*------------------------------------------------------------*/ /* WEMVA */ if(adj) { sf_warning("adjoint operator..."); if(eic){ ahx = sf_iaxa(Pi,1); sf_setlabel(ahx,"hx"); ahy = sf_iaxa(Pi,2); sf_setlabel(ahy,"hy"); ahz = sf_iaxa(Pi,3); sf_setlabel(ahz,"hz"); aht = sf_iaxa(Pi,4); sf_setlabel(aht,"ht"); dht = sf_d(aht); oht = sf_o(aht); nhx2 = sf_n(ahx); nhx = (nhx2-1)/2; nhy2 = sf_n(ahy); nhy = (nhy2-1)/2; nhz2 = sf_n(ahz); nhz = (nhz2-1)/2; nht2 = sf_n(aht); nht = (nht2-1)/2; /* CIP coordinates */ Fc = sf_input ("cc" ); ac = sf_iaxa(Fc,2); sf_setlabel(ac,"cc"); sf_setunit(ac,""); nc = sf_n(ac); } cip = wexcip_init(cub,nhx,nhy,nhz,nht,nhx2,nhy2,nhz2,nht2,nc,dht,oht,Fc,eic); mva = wexmva_init(cub,cip); Ps = sf_output("out"); sf_settype(Ps,SF_COMPLEX); sf_oaxa(Ps,amx,1); sf_oaxa(Ps,amy,2); sf_oaxa(Ps,az, 3); if(eic){ sf_oaxa(Ps,ae, 4); sf_oaxa(Ps,ae, 5);} /* Adjoint I.C. operator, dI -> dW */ wexcip_adj(cub,cip,Bwr,Pws,Pi,eic,1,1); /* Ws dR */ wexcip_adj(cub,cip,Bws,Pwr,Pi,eic,0,0); /* Wr dR */ sf_filefresh(Pws); sf_filefresh(Pwr); /* Adjoint WEMVA operator, dW -> dS */ wexmva(mva,adj,cub,ssr,lsr,tap,slo,Bws,Bwr,Pws,Pwr,Ps); } else { /* set up the I/O of output CIP gathers */ Pi = sf_output("out"); sf_settype(Pi,SF_COMPLEX); if(eic){ /* CIP coordinates */ Fc = sf_input ("cc" ); ac = sf_iaxa(Fc,2); sf_setlabel(ac,"cc"); sf_setunit(ac,""); nc = sf_n(ac); if(! sf_getint("nhx",&nhx)) nhx=0; /* number of lags on the x axis */ if(! sf_getint("nhy",&nhy)) nhy=0; /* number of lags on the y axis */ if(! sf_getint("nhz",&nhz)) nhz=0; /* number of lags on the z axis */ if(! sf_getint("nht",&nht)) nht=0; /* number of lags on the t axis */ if(! sf_getfloat("dht",&dht)) sf_error("need dht"); oht = -nht*dht; nhx2=2*nhx+1; nhy2=2*nhy+1; nhz2=2*nhz+1; nht2=2*nht+1; aa=sf_maxa(nhx2,-nhx*cub->amx.d,cub->amx.d); sf_setlabel(aa,"hx"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Pi,aa,1); aa=sf_maxa(nhy2,-nhy*cub->amy.d,cub->amy.d); sf_setlabel(aa,"hy"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Pi,aa,2); aa=sf_maxa(nhz2,-nhz*cub->az.d,cub->az.d); sf_setlabel(aa,"hz"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Pi,aa,3); aa=sf_maxa(nht2,-nht*dht,dht); sf_setlabel(aa,"ht"); sf_setunit(aa,"s"); if(verb) sf_raxa(aa); sf_oaxa(Pi,aa,4); sf_oaxa(Pi,ac,5); } else{ sf_oaxa(Pi,amx,1); sf_oaxa(Pi,amy,2); sf_oaxa(Pi,az, 3); } cip = wexcip_init(cub,nhx,nhy,nhz,nht,nhx2,nhy2,nhz2,nht2,nc,dht,oht,Fc,eic); mva = wexmva_init(cub,cip); /* WEMVA operator, dS -> dW */ wexmva(mva,adj,cub,ssr,lsr,tap,slo,Bws,Bwr,Pws,Pwr,Ps); sf_filefresh(Pws); sf_filefresh(Pwr); /* I.C. operator, dW -> dI */ wexcip_for(cub,cip,Bws,Pwr,Pti,eic,0,0); /* CONJ( Ws) dWr */ sf_seek(Pti,(off_t)0,SEEK_SET); wexcip_for(cub,cip,Pws,Bwr,Pti,eic,0,1); /* CONJ(dWs) Wr */ sf_filefresh(Pti); sf_filecopy(Pi,Pti,SF_COMPLEX); } /*------------------------------------------------------------*/ /* close structures */ wexslo_close(slo); wexssr_close(cub,ssr); wextap2D_close(tap); wexmva_close(mva); wexcip_close(cip,eic); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* close files */ if (Ps!=NULL) sf_fileclose(Ps); if (Fc!=NULL) sf_fileclose(Fc); if (Pi!=NULL) sf_fileclose(Pi); if (Bws!=NULL) sf_fileclose(Bws); if (Bwr!=NULL) sf_fileclose(Bwr); if (Pws!=NULL) sf_tmpfileclose(Pws); if (Pwr!=NULL) sf_tmpfileclose(Pwr); if (Pti!=NULL) sf_tmpfileclose(Pti); /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char* argv[]) { sf_file in=NULL, out=NULL; int n1_traces; int n1_headers; char* header_format=NULL; sf_datatype typehead; /* kls do I need to add this? sf_datatype typein; */ float* fheader=NULL; float* intrace=NULL; int dim; off_t n_in[SF_MAX_DIM]; int iaxis; int dim_output; int *indx_of_keys; bool label_argparmread,n_argparmread,o_argparmread,d_argparmread; char parameter[13]; char* label[SF_MAX_DIM]; off_t n_output[SF_MAX_DIM]; off_t n_outheaders[SF_MAX_DIM]; float o_output[SF_MAX_DIM]; float d_output[SF_MAX_DIM]; sf_axis output_axa_array[SF_MAX_DIM]; sf_file output=NULL, outheaders=NULL; char* output_filename=NULL; char* outheaders_filename=NULL; sf_init (argc,argv); /*****************************/ /* initialize verbose switch */ /*****************************/ /* verbose flag controls ammount of print */ /*( verbose=1 0 terse, 1 informative, 2 chatty, 3 debug ) */ /* fprintf(stderr,"read verbose switch. getint reads command line.\n"); */ if(!sf_getint("verbose",&verbose))verbose=1; /* \n flag to control amount of print 0 terse, 1 informative, 2 chatty, 3 debug */ fprintf(stderr,"verbose=%d\n",verbose); /******************************************/ /* input and output data are stdin/stdout */ /******************************************/ if(verbose>0)fprintf(stderr,"read infile name\n"); in = sf_input ("in"); if(verbose>0) fprintf(stderr,"read outfile name (probably default to stdout\n"); out = sf_output ("out"); if (!sf_histint(in,"n1_traces",&n1_traces)) sf_error("input data not define n1_traces"); if (!sf_histint(in,"n1_headers",&n1_headers)) sf_error("input data does not define n1_headers"); header_format=sf_histstring(in,"header_format"); if(strcmp (header_format,"native_int")==0) typehead=SF_INT; else typehead=SF_FLOAT; fprintf(stderr,"allocate headers. n1_headers=%d\n",n1_headers); fheader = sf_floatalloc(n1_headers); fprintf(stderr,"allocate intrace. n1_traces=%d\n",n1_traces); intrace= sf_floatalloc(n1_traces); /* maybe I should add some validation that n1== n1_traces+n1_headers+2 and the record length read in the second word is consistent with n1. */ /* put the history from the input file to the output */ sf_fileflush(out,in); /********************************************************************/ /* set up the output and outheaders files for the traces and headers */ /********************************************************************/ output_filename=sf_getstring("output"); /* \n output trace filename. Required parameter with no default. */ if(NULL==output_filename) sf_error("output is a required parameter"); output=sf_output(output_filename); outheaders_filename=sf_getstring("outheaders"); /* \n Output trace header file name. Default is the input data file name, with the final .rsf changed to _hdr.rsf. */ if(outheaders_filename==NULL){ /* compute headers_filename from output_filename by replacing the final .rsf with _hdr.rsf */ if(!(0==strcmp(output_filename+strlen(output_filename)-4,".rsf"))){ fprintf(stderr,"parameter output, the name of the output file,\n"); fprintf(stderr,"does not end with .rsf, so header filename cannot\n"); fprintf(stderr,"be computed by replacing the final .rsf with\n"); fprintf(stderr,"_hdr.rsf.\n"); sf_error("default for outheaders parameter cannot be computed."); } outheaders_filename=malloc(strlen(output_filename)+60); strcpy(outheaders_filename,output_filename); strcpy(outheaders_filename+strlen(output_filename)-4,"_hdr.rsf\0"); if(verbose>1) fprintf(stderr,"parameter outheader defaulted. Computed to be #%s#\n", outheaders_filename); } if(verbose>1)fprintf(stderr,"parameter outheader input or computed #%s#\n", outheaders_filename); outheaders=sf_output(outheaders_filename); /* get each of the axis information: label2, n2, o2, d2, label3, n3, o3, d3, etc label1, n1, o1, d1 is always defaulted from input */ sf_putint (output ,"n1" ,n1_traces ); sf_putint (outheaders,"n1" ,n1_headers); sf_putfloat (outheaders,"d1" ,1 ); sf_putfloat (outheaders,"o1" ,0 ); sf_putstring(outheaders,"label1","none" ); sf_putstring(outheaders,"unit1" ,"none" ); dim_output=1; for (iaxis=1; iaxis<SF_MAX_DIM; iaxis++){ label_argparmread=n_argparmread=o_argparmread=d_argparmread=false; sprintf(parameter,"label%d",iaxis+1); fprintf(stderr,"try to read %s\n",parameter); if ((label[iaxis]=sf_getstring(parameter))) { /*(label#=(2,...) name of each of the axes. label1 is not changed from input. Each label must be a header key like cdp, cdpt, or ep. The trace header values are used to define the output trace location in the output file. )*/ fprintf(stderr,"got %s=%s\n",parameter,label[iaxis]); sf_putstring(output ,parameter,label[iaxis]); sf_putstring(outheaders,parameter,label[iaxis]); label_argparmread=true; } sprintf(parameter,"n%d",iaxis+1); fprintf(stderr,"try to read %s\n",parameter); if (sf_getlargeint (parameter,&n_output[iaxis])) { /*( n#=(2,...) number of locations in the #-th dimension )*/ fprintf(stderr,"got %s=%lld\n",parameter,(long long) n_output[iaxis]); sf_putint(output ,parameter,n_output[iaxis]); sf_putint(outheaders,parameter,n_output[iaxis]); n_argparmread=true; } sprintf(parameter,"o%d",iaxis+1); if (sf_getfloat(parameter,&o_output[iaxis])) { /*( o#=(2,...) origin of the #-th dimension )*/ sf_putfloat(output ,parameter,o_output[iaxis]); sf_putfloat(outheaders,parameter,o_output[iaxis]); o_argparmread=true; } sprintf(parameter,"d%d",iaxis+1); if (sf_getfloat(parameter,&d_output[iaxis])) { /*( d#=(2,...) delta in the #-th dimension )*/ sf_putfloat(output ,parameter,d_output[iaxis]); sf_putfloat(outheaders,parameter,d_output[iaxis]); d_argparmread=true; } if(!label_argparmread && !n_argparmread && ! o_argparmread && !d_argparmread){ /* none of the parameter were read you read all the parameters in the previous iteration compute the output dimension and exit the loop */ dim_output=iaxis; break; } if(label_argparmread && n_argparmread && o_argparmread && d_argparmread){ /* all the parameters for thisi axis were read. loop for next iaxis */ if(verbose>0){ fprintf(stderr,"label, n, i, and d read for iaxis%d\n",iaxis+1); } } else { sf_warning("working on iaxis=%d. Program expects to read\n",iaxis+1); sf_warning("label%d, n%d, i%d, and d%d from command line.\n", iaxis+1,iaxis+1,iaxis+1,iaxis+1); if(!label_argparmread) sf_error("unable to read label%d\n",iaxis+1); if(!n_argparmread ) sf_error("unable to read n%d \n",iaxis+1); if(!o_argparmread ) sf_error("unable to read o%d \n",iaxis+1); if(!d_argparmread ) sf_error("unable to read d$d \n",iaxis+1); } } /* if the input file is higher dimention than the output, then the size of all the higher dimensions must be set to 1. */ /* kls use sf_axis to get structure for each axis with n, o, d, l, and u this can be used to compute the index for sf_seek */ dim = sf_largefiledims(in,n_in); for (iaxis=dim_output; iaxis<dim; iaxis++){ sprintf(parameter,"n%d",iaxis+1); sf_putint(output,parameter,1); sf_putint(outheaders,parameter,1); } /* for a test zero n_output and dim_output and see it you can read the history file */ sf_largefiledims(output,n_output); sf_largefiledims(outheaders,n_outheaders); if(verbose>1){ for (iaxis=0; iaxis<SF_MAX_DIM; iaxis++){ fprintf(stderr,"from sf_largefiledims(output.. n%d=%lld outheaders=%lld\n", iaxis+1,(long long) n_output[iaxis],(long long) n_outheaders[iaxis]); } } /* the list header keys (including any extras) and get the index into the header vector */ segy_init(n1_headers,in); indx_of_keys=sf_intalloc(dim_output); for (iaxis=1; iaxis<dim_output; iaxis++){ /* kls need to check each of these key names are in the segy header and make error message for invalid keys. Of does segykey do this? NO, just segmentation fault. */ if(verbose>0)fprintf(stderr,"get index of key for %s\n",label[iaxis]); indx_of_keys[iaxis]=segykey(label[iaxis]); } sf_fileflush(output,in); sf_putint(outheaders,"n1",n1_headers); if(0==strcmp("native_int",sf_histstring(in,"header_format"))){ sf_settype(outheaders,SF_INT); } else { sf_settype(outheaders,SF_FLOAT); } sf_fileflush(outheaders,in); fprintf(stderr,"start trace loop\n"); /* kls maybe this should be in function sf_tahwritemapped_init */ { off_t file_offset; off_t i_output[SF_MAX_DIM]; float temp_float=0.0; for(iaxis=0; iaxis<SF_MAX_DIM; iaxis++){ i_output[iaxis]=n_output[iaxis]-1; } file_offset=sf_large_cart2line(dim_output,n_output,i_output)*sizeof(float); sf_seek(output,file_offset,SEEK_SET); sf_floatwrite(&temp_float,1,output); i_output[0]=n_outheaders[0]-1; file_offset=sf_large_cart2line(dim_output,n_outheaders,i_output)* sizeof(float); sf_seek(outheaders,file_offset,SEEK_SET); sf_floatwrite(&temp_float,1,outheaders); } for (iaxis=0; iaxis<SF_MAX_DIM; iaxis++){ /* sf_axis temp; */ output_axa_array[iaxis]=sf_iaxa(output,iaxis+1); if(verbose>2){ /* temp=output_axa_array[iaxis]; */ fprintf(stderr,"axis=%d sf_n(output_axa_array[iaxis])=%d\n", iaxis+1,sf_n(output_axa_array[iaxis])); } /* kls why does this fail? fprintf(stderr,"temp->n=%d\n",temp->n); */ } /***************************/ /* start trace loop */ /***************************/ fprintf(stderr,"start trace loop\n"); while (0==get_tah(intrace, fheader, n1_traces, n1_headers, in)){ if(verbose>1){ for(iaxis=2; iaxis<dim_output; iaxis++){ fprintf(stderr,"label[%d]=%s", iaxis,label[iaxis]); if(typehead == SF_INT)fprintf(stderr,"%d", ((int*)fheader)[indx_of_keys[iaxis]]); else fprintf(stderr,"%f", fheader[indx_of_keys[iaxis]]); } fprintf(stderr,"\n"); } tahwritemapped(verbose,intrace, fheader, n1_traces, n1_headers, output, outheaders, typehead, output_axa_array, indx_of_keys, dim_output, n_output,n_outheaders); /**********************************************/ /* write trace and headers to the output pipe */ /**********************************************/ put_tah(intrace, fheader, n1_traces, n1_headers, out); } exit(0); }
/* main function */ int main(int argc, char* argv[]) { /*geopar variables*/ int nx, nz; int nxb, nzb; float dx, dz, ox, oz; int spz, gpz, gpl; /*source/geophone location*/ int snpint; int top, bot, lft, rht; /*abc boundary*/ int nt; float dt; float trunc; bool verb; /* verbosity flag */ bool illum; /* source illumination flag*/ int m2, m2b, pad1; sf_complex **ltf, **rtf; sf_complex **ltb, **rtb; sf_complex *ww; float *rr; /*extras*/ bool roll; /* survey strategy */ int rectz,rectx,repeat; /*refl smoothing parameters*/ int sht0,shtbgn,shtend,shtnum,shtnum0,shtint; /*mpi*/ int cpuid, numprocs; /*misc*/ int mode; int nzx, nx2, nz2, n2, nk; int ix, iz, it, is; int wfnt; float wfdt; int niter; /*Data/Image*/ sf_complex ***record, **imginv; /*tmp*/ int tmpint; /*I/O*/ sf_file Fvel; sf_file left, right, leftb, rightb; sf_file Fsrc, Frcd/*source and record*/; sf_file Fimg; sf_file Fstart; /*axis*/ sf_axis at, ax, az; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &cpuid); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); sf_init(argc, argv); if(cpuid==0) sf_warning("numprocs=%d",numprocs); if (!sf_getbool("verb", &verb)) verb=false; /*verbosity*/ if (!sf_getint("niter",&niter)) niter=1; if (!sf_getint("mode", &mode)) mode = 0; if (!sf_getbool("illum", &illum)) illum=false; /*if n, no source illumination applied */ if (!sf_getbool("roll", &roll)) roll=false; /*if n, receiver is independent of source location and gpl=nx*/ /* source/receiver info */ if (!sf_getint("shtbgn", &shtbgn)) sf_error("Need shot starting location on grid!"); if (!sf_getint("sht0", &sht0)) sht0=shtbgn; /*actual shot origin on grid*/ if (!sf_getint("shtend", &shtend)) sf_error("Need shot ending location on grid!"); if (!sf_getint("shtint", &shtint)) sf_error("Need shot interval on grid!"); shtnum = (int)((shtend-shtbgn)/shtint) + 1; shtnum0 = shtnum; if (shtnum%numprocs!=0) { shtnum += numprocs-shtnum%numprocs; if (verb) sf_warning("Total shot number is not divisible by total number of nodes! shunum padded from %d to %d.",shtnum0,shtnum); } if (!sf_getint("spz", &spz)) sf_error("Need source depth!"); if (!sf_getint("gpz", &gpz)) sf_error("Need receiver depth!"); if (roll) if (!sf_getint("gpl", &gpl)) sf_error("Need receiver length"); if (!sf_getint("snapinter", &snpint)) snpint=1; /* snap interval */ /*--- parameters of source ---*/ if (!sf_getfloat("srctrunc", &trunc)) trunc=0.4; if (!sf_getint("rectz", &rectz)) rectz=1; if (!sf_getint("rectx", &rectx)) rectx=1; if (!sf_getint("repeat", &repeat)) repeat=0; /* abc parameters */ if (!sf_getint("top", &top)) top=40; if (!sf_getint("bot", &bot)) bot=40; if (!sf_getint("lft", &lft)) lft=40; if (!sf_getint("rht", &rht)) rht=40; /*Set I/O file*/ Frcd = sf_input("--input"); /*record from elsewhere*/ Fsrc = sf_input("src"); /*source wavelet*/ Fimg = sf_output("--output"); left = sf_input("left"); right = sf_input("right"); leftb = sf_input("leftb"); rightb = sf_input("rightb"); Fvel = sf_input("vel"); /*velocity - just for model dimension*/ /*--- Axes parameters ---*/ at = sf_iaxa(Fsrc, 1); nt = sf_n(at); dt = sf_d(at); az = sf_iaxa(Fvel, 1); nzb = sf_n(az); dz = sf_d(az); oz = sf_o(az); ax = sf_iaxa(Fvel, 2); nxb = sf_n(ax); dx = sf_d(ax); ox = sf_o(ax); nzx = nzb*nxb; nz = nzb - top - bot; nx = nxb - lft - rht; if (!roll) gpl = nx; /* global survey setting */ /* wavefield axis */ wfnt = (int)(nt-1)/snpint+1; wfdt = dt*snpint; /* propagator matrices */ if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ nz2 = kiss_fft_next_fast_size(nzb*pad1); nx2 = kiss_fft_next_fast_size(nxb); nk = nz2*nx2; /*wavenumber*/ if (!sf_histint(left,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in left",nzx); if (!sf_histint(left,"n2",&m2)) sf_error("Need n2= in left"); if (!sf_histint(right,"n1",&n2) || n2 != m2) sf_error("Need n1=%d in right",m2); if (!sf_histint(right,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in right",nk); if (!sf_histint(leftb,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in left",nzx); if (!sf_histint(leftb,"n2",&m2b)) sf_error("Need n2= in left"); if (!sf_histint(rightb,"n1",&n2) || n2 != m2b) sf_error("Need n1=%d in right",m2b); if (!sf_histint(rightb,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in right",nk); /*check record data*/ sf_histint(Frcd,"n1", &tmpint); if (tmpint != nt ) sf_error("Error parameter n1 in record!"); sf_histint(Frcd,"n2", &tmpint); if (tmpint != gpl ) sf_error("Error parameter n2 in record!"); sf_histint(Frcd,"n3", &tmpint); if (tmpint != shtnum0 ) sf_error("Error parameter n3 in record!"); /*check starting model for cg*/ if (NULL!=sf_getstring("start")) Fstart = sf_input("start"); else Fstart = NULL; /*allocate memory*/ ww=sf_complexalloc(nt); rr=sf_floatalloc(nzx); ltf = sf_complexalloc2(nzx,m2); rtf = sf_complexalloc2(m2,nk); ltb = sf_complexalloc2(nzx,m2b); rtb = sf_complexalloc2(m2b,nk); geop = (geopar) sf_alloc(1, sizeof(*geop)); record = sf_complexalloc3(nt, gpl, shtnum); imginv = sf_complexalloc2(nz,nx); /*read from files*/ sf_complexread(ww,nt,Fsrc); sf_complexread(ltf[0],nzx*m2,left); sf_complexread(rtf[0],m2*nk,right); sf_complexread(ltb[0],nzx*m2b,leftb); sf_complexread(rtb[0],m2b*nk,rightb); /*read data*/ sf_complexread(record[0][0], shtnum0*gpl*nt, Frcd); if (shtnum0%numprocs!=0) { #ifdef _OPENMP #pragma omp parallel for private(is,ix,it) #endif for (is=shtnum0; is<shtnum; is++) for (ix=0; ix<gpl; ix++) for (it=0; it<nt; it++) record[is][ix][it] = sf_cmplx(0.,0.); } /*read starting model*/ if (NULL != Fstart) { sf_complexread(imginv[0],nx*nz,Fstart); } else { /*transform the dimension to 1d*/ #ifdef _OPENMP #pragma omp parallel for private(iz) #endif for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { imginv[ix][iz] = sf_cmplx(0.,0.); } } } /* output RSF files */ if (cpuid==0) { sf_setn(az, nz); sf_setn(ax, nx); sf_oaxa(Fimg, az, 1); sf_oaxa(Fimg, ax, 2); sf_settype(Fimg,SF_COMPLEX); } /*close RSF files*/ sf_fileclose(Fvel); sf_fileclose(Fsrc); sf_fileclose(left); sf_fileclose(right); sf_fileclose(leftb); sf_fileclose(rightb); /*load geopar elements*/ geop->nx = nx; geop->nz = nz; geop->nxb = nxb; geop->nzb = nzb; geop->dx = dx; geop->dz = dz; geop->ox = ox; geop->oz = oz; geop->snpint = snpint; geop->spz = spz; geop->gpz = gpz; geop->gpl = gpl; geop->top = top; geop->bot = bot; geop->lft = lft; geop->rht = rht; geop->nt = nt; geop->dt = dt; geop->trunc = trunc; /*geop->adj = adj; */ geop->verb = verb; geop->illum = illum; geop->m2 = m2; geop->m2b = m2b; geop->pad1 = pad1; /*pointers*/ geop->ltf = ltf; geop->rtf = rtf; geop->ltb = ltb; geop->rtb = rtb; geop->ww = ww; geop->rr = rr; /*extra*/ geop->roll = roll; geop->rectz=rectz; geop->rectx=rectx; geop->repeat=repeat; geop->sht0=sht0; geop->shtbgn=shtbgn; geop->shtend=shtend; geop->shtnum=shtnum; geop->shtnum0=shtnum0; geop->shtint=shtint; geop->cpuid=cpuid; geop->numprocs=numprocs; /*switch*/ geop->mode=mode; sf_csolver(psrtm_lop,sf_ccgstep,nz*nx,nt*gpl*shtnum,imginv[0],record[0][0],niter,"verb",true,"end"); //psrtm_lop(true,false,nz*nx,nt*gpl*shtnum,imginv[0],record[0][0]); if (cpuid==0) sf_complexwrite(imginv[0], nz*nx, Fimg); /*free memory*/ free(geop); free(ww); free(rr); free(*ltf); free(ltf); free(*rtf); free(rtf); free(*ltb); free(ltb); free(*rtb); free(rtb); free(*imginv); free(imginv); free(**record); free(*record); free(record); MPI_Finalize(); exit(0); }
int main(int argc, char* argv[]) { int nx, nz, na, nb, i, j; float fx, fz, dx, dz, da, db; sf_init(argc,argv); sf_file Fo1, Fo2, Fo3, Fo4, Fo5, Fo6; Fo1 = sf_input("in"); // wavefront1 Fo2 = sf_input("wave2"); // wavefront2 Fo3 = sf_output("out"); // wavetrans1 Fo4 = sf_output("wavetrans2"); // wavetrans2 Fo5 = sf_output("amp1"); // amplitue1 Fo6 = sf_output("amp2"); // amplitue2 float **snap1, **snap2; float **sn1, **sn2; float *amp1, *amp2; float amax, amax1, amax2; /* Read/Write axes */ sf_axis az, ax; az = sf_iaxa(Fo1,1); nz = sf_n(az); dz = sf_d(az)*1000; ax = sf_iaxa(Fo1,2); nx = sf_n(ax); dx = sf_d(ax)*1000; fx=sf_o(ax); fz=sf_o(az); sf_warning("nx= %d nz= %d",nx,nz); sf_warning("dx= %f dz= %f",dx,dz); na = 720; da = 180.0/na; nb = nx*2; db = dx/2.0; sf_warning("da= %f db= %f",da,db); sf_putint(Fo3,"n1",nb); sf_putint(Fo3,"n2",na); sf_putfloat(Fo3,"d1",db); sf_putfloat(Fo3,"o1",0.0f); sf_putfloat(Fo3,"d2",da); sf_putfloat(Fo3,"o2",-90.0f); sf_putint(Fo4,"n1",nb); sf_putint(Fo4,"n2",na); sf_putfloat(Fo4,"d1",db); sf_putfloat(Fo4,"o1",0.0f); sf_putfloat(Fo4,"d2",da); sf_putfloat(Fo4,"o2",-90.0f); sf_putint(Fo5,"n2",1); sf_putint(Fo5,"n1",na); sf_putfloat(Fo5,"d1",da); sf_putfloat(Fo5,"o1",-90.0f); sf_putstring(Fo5,"label1","Phase angle"); sf_putstring(Fo5,"unit1","Degree"); sf_putint(Fo6,"n2",1); sf_putint(Fo6,"n1",na); sf_putfloat(Fo6,"d1",da); sf_putfloat(Fo6,"o1",-90.0f); sf_putstring(Fo6,"label1","Phase angle"); sf_putstring(Fo6,"unit1","Degree"); snap1=sf_floatalloc2(nz, nx); snap2=sf_floatalloc2(nz, nx); sn1=sf_floatalloc2(nb, na); sn2=sf_floatalloc2(nb, na); amp1=sf_floatalloc(na); amp2=sf_floatalloc(na); for(i=0;i<nx;i++){ sf_floatread(snap1[i], nz, Fo1); sf_floatread(snap2[i], nz, Fo2); } for(i=0;i<na;i++){ amp1[i]=0.0; amp2[i]=0.0; for(j=0;j<nb;j++){ sn1[i][j]=0.0; sn2[i][j]=0.0; } } for(i=0;i<na;i++){ float a=i*da; a *= SF_PI/180.0; for(j=0;j<nb;j++){ float b=j*db; float x=(nx-1)*dx*0.5-b*cos(a); float z=(nz-1)*dz*0.5+b*sin(a); int ix, iz; ix=x/dx; iz=z/dz; if(ix>=0&&ix<nx&&iz>=nz/2&&iz<nz){ //sf_warning("i=%d a=%f j=%d b=%f x=%f z=%f ix=%d iz=%d",i,a,j,b,x,z,ix,iz); sn1[i][j]=snap1[ix][iz]; sn2[i][j]=snap2[ix][iz]; } } sf_floatwrite(sn1[i], nb, Fo3); sf_floatwrite(sn2[i], nb, Fo4); } for(i=0;i<na;i++){ amax=0.0; for(j=0;j<nb;j++) if(fabs(sn1[i][j])>amax) amax=fabs(sn1[i][j]); amp1[i]=amax; amax=0.0; for(j=0;j<nb;j++) if(fabs(sn2[i][j])>amax) amax=fabs(sn2[i][j]); amp2[i]=amax; } amax1=0.0; amax2=0.0; for(i=na/2-2;i<na/2+2;i++){ if(amp1[i]>amax1) amax1=amp1[i]; if(amp2[i]>amax2) amax2=amp2[i]; } for(i=0;i<na;i++){ amp1[i] /= amax1; amp2[i] /= amax2; } sf_floatwrite(amp1, na, Fo5); sf_floatwrite(amp2, na, Fo6); free(*snap1); free(*snap2); free(*sn1); free(*sn2); free(amp1); free(amp2); }
int main(int argc, char* argv[]) { int ompnth=1; sf_file in, out; /* Input and output files */ sf_axis az,ax,a3; int nz,nx,n3; int box1,box2,klo1,khi1,klo2,khi2,kmid2,kmid1; int ix,iz,i3; float *sumG,***d,***dat,***neg,***dN; float neg1,AmpNorm,h,h1; double scalea, logs; /*---------------------------------------------------------*/ /* Initialize RSF */ sf_init(argc,argv); /* standard input */ in = sf_input("in"); /* standard output */ out = sf_output("out"); #ifdef _OPENMP ompnth = omp_init(); #endif /* parameters from input file*/ az=sf_iaxa(in,1); sf_setlabel(az,"z"); nz = sf_n(az); ax=sf_iaxa(in,2); sf_setlabel(ax,"x"); nx = sf_n(ax); a3=sf_iaxa(in,3); sf_setlabel(a3,"y"); n3 = sf_n(a3); /* parameter from the command line (i.e. box1=50 box2=50 ) */ if (!sf_getint("box1",&box1)) sf_error("Need box1="); if (!sf_getint("box2",&box2)) sf_error("Need box2="); /* allocate floating point array */ dat = sf_floatalloc3 (nz,nx,n3); /* initialise the size of the searching box*/ int s1= nz-(box1); int s2= nx-(box2); int bm1=box1/2; int bm2=box2/2; /*initialise the mid-point of each box) */ sumG =sf_floatalloc (n3); d =sf_floatalloc3 (nz,nx,n3); dN =sf_floatalloc3 (nz,nx,n3); neg =sf_floatalloc3 (nz,nx,n3); sf_floatread(dat[0][0],nz*nx*n3,in); // Global Sum for (i3=0 ; i3<n3; ++i3){ sumG[i3]=0; for (ix=0; ix<nx; ++ix){ for (iz=0; iz<nz; ++iz){ d[i3][ix][iz] = dat[i3][ix][iz] * dat[i3][ix][iz]; //make all amplitudes positive sumG[i3] += d[i3][ix][iz]; } } } /* #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(klo2,klo1,kmid2,kmid1,khi1,khi2,neg1,AmpNorm,scalea,logs,h1,h) #endif */ //initialise the box for negentropy for (i3=0 ; i3<n3 ; ++i3 ){ klo2=0;klo1=0; for (klo2=0; klo2<(s2); ++klo2){ for (klo1=0; klo1<(s1); ++klo1){ //intialise parameters neg1=0.0;scalea=0.0;logs=0.0; AmpNorm=0.0;h=0,h1=0; //Set upper limit of searching box and midpoints khi2=klo2+box2; khi1=klo1+box1; kmid2=klo2+bm2; kmid1=klo1+bm1; //Sum values in each box for (ix=klo2; ix<khi2; ++ix){ for (iz=klo1; iz<khi1; ++iz){ AmpNorm =(d[i3][ix][iz])/(sumG[i3]); dN[i3][ix][iz]=AmpNorm; //ai //Gaussian operator h =(((iz -kmid1) * (iz -kmid1)) + \ ((ix -kmid2) * (ix -kmid2))) / (2*box1*box2*1.41); h1=(((box1*0.5 ) * (box1*0.5 )) + \ ((box2*0.5 ) * (box2*0.5 )))/ (2*box1*box2*1.41); h =exp(-4*h ); h1=exp(-4*h1); if (h1>= h) scalea=0; else scalea = box1 * box2 * AmpNorm * (h-h1); //qi if (AmpNorm==0) logs= 0; else logs= scalea*scalea; /* logs can be different functions: else {logs=log(scalea);} logs=log(scalea); */ neg1 += (scalea*logs); } } neg[i3][kmid2][kmid1] = neg1/(box1*box2); } } } sf_floatwrite(neg[0][0] ,nz*nx*n3 ,out); //write negentropy exit(0); }
int main(int argc, char* argv[]) { bool verb; bool adj; bool anis; sf_file Fcip=NULL; /* lag-domain CIPs */ sf_file Fang=NULL; /* angle-domain CIPs */ sf_file Fvel=NULL; /* velocity @ CIPs */ sf_file Fnor=NULL; /* normals @ CIPs */ sf_file Ftlt=NULL; /* tilt @ CIPs */ sf_file Fani=NULL; /* anisotropy @ CIPs */ sf_axis ahx,ahy,ahz,aht,ac,ath,aph,aps,aj; int ihx,ihy,ihz,iht,ic,ith,iph; /* angle parameters */ int nth,nph,nps,nhx,nhy,nhz,nht; float oth,oph,ops,ohx,ohy,ohz,oht; float dth,dph,dps,dhx,dhy,dhz,dht; float phi; float tht; float psi; float v_s,v_r; float cosum,codif,sitovel; /* arrays 1 2 3 4 */ float ****cip; /* nhx-nhy-nhz-nht */ float **ang; /* nph-nth */ float *vep; /* nc */ float *ves; /* nc */ float *eps=NULL; /* nc */ float *dlt=NULL; /* nc */ vc3d vv; /* azimuth reference vector */ vc3d *nn; /* normal vectors */ vc3d *tt=NULL; /* tilt vectors */ vc3d *aa; /* in-plane reference vector */ vc3d qq; vc3d jk; /* temp vector */ float hx,hy,hz; float tau; /* time lag */ int jht; /* tau axis index */ float fht; /* tau axis weight */ float ssn; /* slant-stack normalization */ float *ttipar; /*-----------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); #ifdef _OPENMP omp_init(); /* OMP parameters */ #endif if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("anis",&anis)) anis=false; /* anisotropy flag */ if(! sf_getbool("adj", &adj)) adj=true; /* adj flag */ /* * ADJ: cip to ang * FOR: ang to cip */ sf_warning("verb=%d",verb); sf_warning("anis=%d",anis); /* select anisotropy model */ if(anis) sf_warning("ANI model"); else sf_warning("ISO model"); if(adj) { Fcip=sf_input ( "in"); /* CIP file */ Fang=sf_output("out"); /* ANG file */ } else { Fcip=sf_output("out"); /* CIP file */ Fang=sf_input ("in"); /* ANG file */ } Fvel=sf_input ("vel"); /* velocity file */ Fnor=sf_input ("nor"); /* normal vectors */ if(anis) { Ftlt=sf_input ("tlt"); /* tilt vectors */ Fani=sf_input ("ani"); /* anisotropy */ } aj = sf_maxa(1,0,1); if(adj) { /* input axes */ ahx = sf_iaxa(Fcip,1); sf_setlabel(ahx,"hx"); ahy = sf_iaxa(Fcip,2); sf_setlabel(ahy,"hy"); ahz = sf_iaxa(Fcip,3); sf_setlabel(ahz,"hz"); aht = sf_iaxa(Fcip,4); sf_setlabel(aht,"ht"); /* CIP axis */ ac = sf_iaxa(Fcip,5); sf_setlabel(ac ,"c "); /* reflection angle */ if(! sf_getint ("nth",&nth)) nth=90; if(! sf_getfloat("oth",&oth)) oth=0; if(! sf_getfloat("dth",&dth)) dth=1.; ath = sf_maxa(nth,oth,dth); sf_setlabel(ath,"th"); sf_setunit (ath,"deg"); /* azimuth angle */ if(! sf_getint ("nph",&nph)) nph=360; if(! sf_getfloat("oph",&oph)) oph=-180; if(! sf_getfloat("dph",&dph)) dph=1.; aph = sf_maxa(nph,oph,dph); sf_setlabel(aph,"ph"); sf_setunit (aph,"deg"); /* output axes */ sf_oaxa(Fang,ath,1); sf_oaxa(Fang,aph,2); sf_oaxa(Fang,ac ,3); sf_oaxa(Fang,aj ,4); sf_oaxa(Fang,aj ,5); } else { /* lag in x */ if(! sf_getint ("nhx",&nhx)) nhx=1; if(! sf_getfloat("ohx",&ohx)) ohx=0; if(! sf_getfloat("dhx",&dhx)) dhx=1.; ahx = sf_maxa(nhx,ohx,dhx); sf_setlabel(ahx,"hx"); sf_setunit (ahx,""); /* lag in y */ if(! sf_getint ("nhy",&nhy)) nhy=1; if(! sf_getfloat("ohy",&ohy)) ohy=0; if(! sf_getfloat("dhy",&dhy)) dhy=1.; ahy = sf_maxa(nhy,ohy,dhy); sf_setlabel(ahy,"hy"); sf_setunit (ahy,""); /* lag in z */ nhz=1; ohz=0.; dhz=1.; ahz = sf_maxa(nhz,ohz,dhz); sf_setlabel(ahz,"hz"); sf_setunit (ahz,""); /* lag in t */ if(! sf_getint ("nht",&nht)) nht=1; if(! sf_getfloat("oht",&oht)) oht=0.; if(! sf_getfloat("dht",&dht)) dht=1.; aht = sf_maxa(nht,oht,dht); sf_setlabel(aht,"ht"); sf_setunit (aht,""); /* reflection angle */ ath = sf_iaxa(Fang,1); sf_setlabel(ath,"th"); /* azimuth angle */ aph = sf_iaxa(Fang,2); sf_setlabel(aph,"ph"); /* CIP axis */ ac = sf_iaxa(Fang,3); sf_setlabel(ac ,"c "); /* output axes */ sf_oaxa(Fcip,ahx,1); sf_oaxa(Fcip,ahy,2); sf_oaxa(Fcip,ahz,3); sf_oaxa(Fcip,aht,4); sf_oaxa(Fcip,ac ,5); } if (verb){ sf_raxa(ahx); sf_raxa(ahy); sf_raxa(ahz); sf_raxa(aht); sf_raxa(ac); sf_raxa(ath); sf_raxa(aph); } if(anis) { /* deviation angle */ if(! sf_getint ("nps",&nps)) nps=251; if(! sf_getfloat("ops",&ops)) ops=-25; if(! sf_getfloat("dps",&dps)) dps=0.2; aps = sf_maxa(nps,ops,dps); sf_setlabel(aps,"ps"); sf_setunit (aps,"deg"); if(verb) sf_raxa(aps); } else { aps = NULL; } /*------------------------------------------------------------*/ /* allocate arrays */ cip = sf_floatalloc4 (sf_n(ahx),sf_n(ahy),sf_n(ahz),sf_n(aht)); ang = sf_floatalloc2 (sf_n(ath),sf_n(aph)); /* read velocity */ vep = sf_floatalloc (sf_n(ac)); sf_floatread(vep,sf_n(ac),Fvel); ves = sf_floatalloc (sf_n(ac)); sf_floatread(ves,sf_n(ac),Fvel); /*------------------------------------------------------------*/ /* read normals */ nn = (vc3d*) sf_alloc(sf_n(ac),sizeof(*nn)); /* normals */ vc3dread1(Fnor,nn,sf_n(ac)); if(anis) { /* read anisotropy */ eps = sf_floatalloc (sf_n(ac)); sf_floatread(eps,sf_n(ac),Fani); dlt = sf_floatalloc (sf_n(ac)); sf_floatread(dlt,sf_n(ac),Fani); /* read tilts */ tt = (vc3d*) sf_alloc(sf_n(ac),sizeof(*tt)); vc3dread1(Ftlt,tt,sf_n(ac)); } /*------------------------------------------------------------*/ /* in-plane azimuth reference */ vv.dx=1; vv.dy=0; vv.dz=0; aa = (vc3d*) sf_alloc(sf_n(ac),sizeof(*aa)); for(ic=0;ic<sf_n(ac);ic++) { jk =vcp3d(&nn[ic],&vv); aa[ic]=vcp3d(&jk,&nn[ic]); } /*------------------------------------------------------------*/ ssn = 1./sqrt(sf_n(ahx)*sf_n(ahy)*sf_n(ahz)); /*------------------------------------------------------------*/ /* loop over CIPs */ /* if(verb) fprintf(stderr,"ic\n");*/ for(ic=0;ic<sf_n(ac);ic++) { /* if(verb) fprintf(stderr,"\b\b\b\b\b%d",ic);*/ if(adj) { /* read CIP */ sf_floatread(cip[0][0][0],sf_n(ahx)*sf_n(ahy)*sf_n(ahz)*sf_n(aht),Fcip); /* init ANG */ for (iph=0;iph<sf_n(aph);iph++) { for(ith=0;ith<sf_n(ath);ith++) { ang[iph][ith]=0; } } } else { /* init CIP */ for (iht=0;iht<sf_n(aht);iht++) { for (ihz=0;ihz<sf_n(ahz);ihz++) { for (ihy=0;ihy<sf_n(ahy);ihy++) { for(ihx=0;ihx<sf_n(ahx);ihx++) { cip[iht][ihz][ihy][ihx]=0; } } } } /* read ANG */ sf_floatread(ang[0],sf_n(ath)*sf_n(aph),Fang); } /* phi loop */ nph = sf_n(aph); #ifdef _OPENMP #pragma omp parallel for schedule(static) \ private(iph,phi,jk,qq, \ ith,tht, \ ihy,ihx,hy,hx,hz, \ tau,jht,fht,cosum,codif,v_s,v_r,psi,sitovel) \ shared( nph,aph,ath,aps,ahy,ahx,aht,cip,ang,vep,ves,eps,dlt) #endif for(iph=0;iph<nph;iph++) { phi=(180+sf_o(aph)+iph*sf_d(aph))/180.*SF_PI; /* use '180' to reverse illumination direction: */ /* at a CIP, look toward the source */ /* reflection azimuth vector */ jk = rot3d(nn,aa,phi); qq = nor3d(&jk); /* theta loop */ for(ith=0;ith<sf_n(ath);ith++) { tht=(sf_o(ath)+ith*sf_d(ath))/180.*SF_PI; if(anis) { ttipar = psitti(nn,&qq,tt,aa, tht,phi,aps, vep[ic],ves[ic],eps[ic],dlt[ic]); psi = ttipar[0]; v_s = ttipar[1]; v_r = ttipar[2]; psi *= SF_PI/180.; cosum = cosf(tht+psi); codif = cosf(tht-psi); sitovel = sinf(2*tht)/(v_s*cosum + v_r*codif); } else { sitovel = sinf(tht)/vep[ic]; } /* lag loops */ if(adj) { for (ihy=0;ihy<sf_n(ahy);ihy++) { hy=sf_o(ahy)+ihy*sf_d(ahy); for(ihx=0;ihx<sf_n(ahx);ihx++) { hx=sf_o(ahx)+ihx*sf_d(ahx); hz = -(hx*(nn[ic].dx)+hy*(nn[ic].dy))/(nn[ic].dz); tau = -((qq.dx)*hx+(qq.dy)*hy+(qq.dz)*hz)*sitovel; jht=0.5+(tau-sf_o(aht))/sf_d(aht); if(jht>=0 && jht<sf_n(aht)-1) { fht= (tau-sf_o(aht))/sf_d(aht)-jht; ang[iph][ith] += (1-fht)*ssn*cip[jht ][0][ihy][ihx] + fht *ssn*cip[jht+1][0][ihy][ihx]; } } /* hx */ } /* hy */ } else { for (ihy=0;ihy<sf_n(ahy);ihy++) { hy=sf_o(ahy)+ihy*sf_d(ahy); for(ihx=0;ihx<sf_n(ahx);ihx++) { hx=sf_o(ahx)+ihx*sf_d(ahx); hz = -(hx*(nn[ic].dx)+hy*(nn[ic].dx))/(nn[ic].dz); tau = -((qq.dx)*hx+(qq.dy)*hy+(qq.dz)*hz)*sitovel; jht=0.5+(tau-sf_o(aht))/sf_d(aht); if(jht>=0 && jht<sf_n(aht)-1) { fht= (tau-sf_o(aht))/sf_d(aht)-jht; cip[jht ][0][ihy][ihx] += (1-fht)*ssn*ang[iph][ith]; cip[jht+1][0][ihy][ihx] += fht *ssn*ang[iph][ith]; } } /* hx */ } /* hy */ } } /* th */ } /* ph */ if(adj) { /* write ANG */ sf_floatwrite(ang[0],sf_n(ath)*sf_n(aph),Fang); } else { /* write CIP */ sf_floatwrite(cip[0][0][0],sf_n(ahx)*sf_n(ahy)*sf_n(ahz)*sf_n(aht),Fcip); } } if(verb) fprintf(stderr,"\n"); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"free memory..."); free(***cip);free(**cip);free(*cip);free(cip); ; free(*ang);free(ang); ; free(vep); ; free (nn); ; free (aa); if(anis) { free(ves); free(eps); free(dlt); free(tt); } if(verb) fprintf(stderr,"OK\n"); /*------------------------------------------------------------*/ exit(0); }
int main(int argc, char* argv[]) { clock_t tstart, tend; double duration; /*Flag*/ bool verb, cmplx; /*I/O*/ sf_file Fsrc,Fo,Frec; /* I/O files */ sf_file left, right; /*left/right matrix*/ sf_file Fvel, Fden, Ffft; /*Model*/ sf_axis at,az,ax; /* cube axes */ /* I/O arrays*/ float *src; /*point source, distributed source*/ float **lt, **rt; float **vel, **den, **c11; /* Grid index variables */ int it,iz,im,ik,ix,i,j; int nt,nz,nx, m2, nk, nkx, nkz, nzx, nz2, nx2, nzx2, n1, n2, pad1; float cx, cz; float kx, kz, dkx, dkz, kx0, kz0; float dx, dz, dt, d1, d2; float ox, oz; sf_complex *cwavex, *cwavez, *cwavemx, *cwavemz; float **record; float **wavex, **wavez; float *curtxx, *pretxx; float *curvx, *prevx, *curvz, *prevz; /*source*/ spara sp={0}; int srcrange; float srctrunc; bool srcdecay; float slx, slz; int spx, spz; /*options*/ float gdep; int gp; tstart = clock(); sf_init(argc,argv); if(!sf_getbool("verb",&verb)) verb=false; /* verbosity */ Fvel = sf_input("vel"); Fden = sf_input("den"); /* setup I/O files */ Fsrc = sf_input ("in" ); Fo = sf_output("out"); Frec = sf_output("rec"); /*record*/ /* Read/Write axes */ at = sf_iaxa(Fsrc,1); nt = sf_n(at); dt = sf_d(at); ax = sf_iaxa(Fvel,2); nx = sf_n(ax); dx = sf_d(ax); ox=sf_o(ax); az = sf_iaxa(Fvel,1); nz = sf_n(az); dz = sf_d(az); oz=sf_o(az); sf_oaxa(Fo,az,1); sf_oaxa(Fo,ax,2); sf_oaxa(Fo,at,3); /*set for record*/ sf_oaxa(Frec, at, 1); sf_oaxa(Frec, ax, 2); if (!sf_getbool("cmplx",&cmplx)) cmplx=false; /* use complex FFT */ if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ nk = fft2_init(cmplx,pad1,nz,nx,&nz2,&nx2); nzx = nz*nx; nzx2 = nz2*nx2; /* propagator matrices */ left = sf_input("left"); right = sf_input("right"); if (!sf_histint(left,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in left",nzx); if (!sf_histint(left,"n2",&m2)) sf_error("Need n2= in left"); if (!sf_histint(right,"n1",&n2) || n2 != m2) sf_error("Need n1=%d in right",m2); if (!sf_histint(right,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in right",nk); lt = sf_floatalloc2(nzx,m2); rt = sf_floatalloc2(m2,nk); sf_floatread(lt[0],nzx*m2,left); sf_floatread(rt[0],m2*nk,right); /*model veloctiy & density*/ if (!sf_histint(Fvel,"n1", &n1) || n1 != nz) sf_error("Need n1=%d in vel", nz); if (!sf_histfloat(Fvel,"d1", &d1) || d1 != dz) sf_error("Need d1=%d in vel", dz); if (!sf_histint(Fvel,"n2", &n2) || n2 != nx) sf_error("Need n2=%d in vel", nx); if (!sf_histfloat(Fvel,"d2", &d2) || d2 != dx) sf_error("Need d2=%d in vel", dx); if (!sf_histint(Fden,"n1", &n1) || n1 != nz) sf_error("Need n1=%d in den", nz); if (!sf_histfloat(Fden,"d1", &d1) || d1 != dz) sf_error("Need d1=%d in den", dz); if (!sf_histint(Fden,"n2", &n2) || n2 != nx) sf_error("Need n2=%d in den", nx); if (!sf_histfloat(Fden,"d2", &d2) || d2 != dx) sf_error("Need d2=%d in den", dx); vel = sf_floatalloc2(nz, nx); den = sf_floatalloc2(nz, nx); c11 = sf_floatalloc2(nz, nx); sf_floatread(vel[0], nzx, Fvel); sf_floatread(den[0], nzx, Fden); for (ix = 0; ix < nx; ix++) { for (iz = 0; iz < nz; iz++) { c11[ix][iz] = den[ix][iz]*vel[ix][iz]*vel[ix][iz]; } } /*parameters of fft*/ Ffft = sf_input("fft"); if (!sf_histint(Ffft,"n1", &nkz)) sf_error("Need n1 in fft"); if (!sf_histint(Ffft,"n2", &nkx)) sf_error("Need n2 in fft"); if ( nkx*nkz != nk ) sf_error("Need nk=nkx*nkz, nk=%d, nkx=%d, nkz=%d", nk, nkx, nkz); if (!sf_histfloat(Ffft,"d1", &dkz)) sf_error("Need d1 in fft"); if (!sf_histfloat(Ffft,"d2", &dkx)) sf_error("Need d2 in fft"); if (!sf_histfloat(Ffft,"o1", &kz0)) sf_error("Need o1 in fft"); if (!sf_histfloat(Ffft,"o2", &kx0)) sf_error("Need o2 in fft"); /*parameters of geometry*/ if (!sf_getfloat("gdep", &gdep)) gdep = 0.0; /*depth of geophone (meter)*/ if (gdep <0.0) sf_error("gdep need to be >=0.0"); /*source and receiver location*/ if (!sf_getfloat("slx", &slx)) slx=-1.0; /*source location x */ if (!sf_getint("spx", &spx)) spx = -1; /*source location x (index)*/ if((slx<0 && spx <0) || (slx>=0 && spx >=0 )) sf_error("Need src location"); if (slx >= 0 ) spx = (int)((slx-ox)/dx+0.5); if (!sf_getfloat("slz", &slz)) slz = -1.0; /* source location z */ if (!sf_getint("spz", &spz)) spz=-1; /*source location z (index)*/ if((slz<0 && spz <0) || (slz>=0 && spz >=0 )) sf_error("Need src location"); if (slz >= 0 ) spz = (int)((slz-ox)/dz+0.5); if (!sf_getfloat("gdep", &gdep)) gdep = -1.0; /* recorder depth on grid*/ if (!sf_getint("gp", &gp)) gp=0; /* recorder depth on index*/ if ( gdep>=oz) { gp = (int)((gdep-oz)/dz+0.5);} if (gp < 0.0) sf_error("gdep need to be >=oz"); /*source and receiver location*/ if (!sf_getbool("srcdecay", &srcdecay)) srcdecay=false; /*source decay*/ if (!sf_getint("srcrange", &srcrange)) srcrange=10; /*source decay range*/ if (!sf_getfloat("srctrunc", &srctrunc)) srctrunc=100; /*trunc source after srctrunc time (s)*/ /* read wavelet & reflectivity */ src = sf_floatalloc(nt); sf_floatread(src,nt,Fsrc); curtxx = sf_floatalloc(nzx2); curvx = sf_floatalloc(nzx2); curvz = sf_floatalloc(nzx2); pretxx = sf_floatalloc(nzx); prevx = sf_floatalloc(nzx); prevz = sf_floatalloc(nzx); cwavex = sf_complexalloc(nk); cwavez = sf_complexalloc(nk); cwavemx = sf_complexalloc(nk); cwavemz = sf_complexalloc(nk); wavex = sf_floatalloc2(nzx2,m2); wavez = sf_floatalloc2(nzx2,m2); record = sf_floatalloc2(nt,nx); ifft2_allocate(cwavemx); ifft2_allocate(cwavemz); for (iz=0; iz < nzx; iz++) { pretxx[iz]=0.; prevx[iz] =0.; prevz[iz] =0.; } for (iz=0; iz < nzx2; iz++) { curtxx[iz]=0.; curvx[iz]=0.; curvz[iz]=0.; } /* Check parameters*/ if(verb) { sf_warning("======================================"); #ifdef SF_HAS_FFTW sf_warning("FFTW is defined"); #endif #ifdef SF_HAS_COMPLEX_H sf_warning("Complex is defined"); #endif sf_warning("nx=%d nz=%d nzx=%d dx=%f dz=%f", nx, nz, nzx, dx, dz); sf_warning("nkx=%d nkz=%d dkx=%f dkz=%f nk=%d", nkx, nkz, dkx, dkz, nk); sf_warning("nx2=%d nz2=%d nzx2=%d", nx2, nz2, nzx2); sf_warning("======================================"); } /*set source*/ sp.trunc=srctrunc; sp.srange=srcrange; sp.alpha=0.5; sp.decay=srcdecay?1:0; /* MAIN LOOP */ for (it=0; it<nt; it++) { if(verb) sf_warning("it=%d/%d;",it,nt-1); /*vx, vz--- matrix multiplication */ fft2(curtxx,cwavex); /* P^(k,t) */ for (im = 0; im < m2; im++) { for (ik = 0; ik < nk; ik++) { kx = kx0+dkx*(ik/nkz); kz = kz0+dkz*(ik%nkz); #ifdef SF_HAS_COMPLEX_H cwavemz[ik] = cwavex[ik]*rt[ik][im]; cwavemx[ik] = fplus(kx,dx)*cwavemz[ik]; cwavemz[ik] = fplus(kz,dz)*cwavemz[ik]; #else cwavemz[ik] = sf_crmul(cwavex[ik],rt[ik][im]); cwavemx[ik] = sf_cmul(fplus(kx,dx), cwavemz[ik]); cwavemz[ik] = sf_cmul(fplus(kz,dz), cwavemz[ik]); #endif } ifft2(wavex[im], cwavemx); /* dp/dx */ ifft2(wavez[im], cwavemz); /* dp/dz */ } for (ix = 0; ix < nx; ix++) { for (iz = 0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ cx = 0.0; cz = 0.0; for (im=0; im<m2; im++) { cx += lt[im][i]*wavex[im][j]; cz += lt[im][i]*wavez[im][j]; } curvx[j] = -1*dt/den[ix][iz]*cx + prevx[i]; /*vx(t+dt/2) = -dt/rho*dp/dx(t) + vx(t-dt/2) */ prevx[i] = curvx[j]; curvz[j] = -1*dt/den[ix][iz]*cz + prevz[i]; prevz[i] = curvz[j]; } } /*txx--- matrix multiplication */ fft2(curvx, cwavex); fft2(curvz, cwavez); for (im = 0; im < m2; im++) { for (ik = 0; ik < nk; ik++ ) { kx = kx0 + dkx*(ik/nkz); kz = kz0 + dkz*(ik%nkz); #ifdef SF_HAS_COMPLEX_H cwavemz[ik] = cwavez[ik]*rt[ik][im]; cwavemx[ik] = cwavex[ik]*rt[ik][im]; cwavemx[ik] = fminu(kx,dx)*cwavemx[ik]; cwavemz[ik] = fminu(kz,dz)*cwavemz[ik]; #else cwavemz[ik] = sf_crmul(cwavez[ik],rt[ik][im]); cwavemx[ik] = sf_crmul(cwavex[ik],rt[ik][im]); cwavemx[ik] = sf_cmul(fplus(kx,dx), cwavemx[ik]); cwavemz[ik] = sf_cmul(fplus(kz,dz), cwavemz[ik]); #endif } ifft2(wavex[im], cwavemx); /* dux/dx */ ifft2(wavez[im], cwavemz); /* duz/dz */ } for (ix = 0; ix < nx; ix++) { for (iz = 0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ cx = 0.0; cz = 0.0; for (im=0; im<m2; im++) { cx += lt[im][i]*wavex[im][j]; cz += lt[im][i]*wavez[im][j]; } curtxx[j] = -1*dt*c11[ix][iz]*(cx+cz) + pretxx[i]; } } if ((it*dt)<=sp.trunc ) { curtxx[spz+spx*nz2] += src[it]*dt; } for (ix = 0; ix < nx; ix++) { /* write wavefield to output */ sf_floatwrite(pretxx+ix*nz,nz,Fo); } /*record*/ for (ix = 0; ix < nx; ix++){ record[ix][it] = pretxx[ix*nz+gp]; } for (ix = 0; ix < nx; ix++) { for (iz = 0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ pretxx[i] = curtxx[j]; } } }/*End of MAIN LOOP*/ if(verb) sf_warning("."); for ( ix = 0; ix < nx; ix++) { sf_floatwrite(record[ix], nt, Frec); } tend = clock(); duration=(double)(tend-tstart)/CLOCKS_PER_SEC; sf_warning(">> The CPU time of sfsglr is: %f seconds << ", duration); exit (0); }
int main(int argc, char* argv[]) { bool verb,fsrf,snap,expl; int jsnap,ntsnap; int jdata; /* I/O files */ sf_file Fwav=NULL; /* wavelet */ sf_file Fsou=NULL; /* sources */ sf_file Frec=NULL; /* receivers */ sf_file Fvel=NULL; /* velocity */ sf_file Fref=NULL; /* reflectivity */ sf_file Fden=NULL; /* density */ sf_file Fdat=NULL; /* data (background) */ sf_file Fwfl=NULL; /* wavefield (background) */ sf_file Flid=NULL; /* data (scattered) */ sf_file Fliw=NULL; /* wavefield (scattered) */ /* I/O arrays */ float *ww=NULL; /* wavelet */ pt2d *ss=NULL; /* sources */ pt2d *rr=NULL; /* receivers */ float **vpin=NULL; /* velocity */ float **roin=NULL; /* density */ float **rfin=NULL; /* reflectivity */ float **vp=NULL; /* velocity in expanded domain */ float **ro=NULL; /* density in expanded domain */ float **ro1=NULL; /* normalized 1st derivative of density on axis 1 */ float **ro2=NULL; /* normalized 1st derivative of density on axis 2 */ float **rf=NULL; /* reflectivity in expanded domain */ float *bdd=NULL; /* data (background) */ float *sdd=NULL; /* data (scattered) */ float **vt=NULL; /* temporary vp*vp * dt*dt */ float **bum,**buo,**bup,**bua,**but; /* wavefield: um = U @ t-1; uo = U @ t; up = U @ t+1 */ float **sum,**suo,**sup,**sua,**sut; /* wavefield: um = U @ t-1; uo = U @ t; up = U @ t+1 */ /* cube axes */ sf_axis at,a1,a2,as,ar; int nt,n1,n2,ns,nr,nb; int it,i1,i2; float dt,d1,d2,id1,id2,dt2; /* linear interpolation weights/indices */ lint2d cs,cr; fdm2d fdm; abcone2d abc; /* abc */ sponge spo; /* FD operator size */ float co,ca2,cb2,ca1,cb1; int ompchunk; #ifdef _OPENMP int ompnth,ompath; #endif sf_axis ac1=NULL,ac2=NULL; int nqz,nqx; float oqz,oqx; float dqz,dqx; float **uc=NULL; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getint("ompchunk",&ompchunk)) ompchunk=1; /* OpenMP data chunk size */ #ifdef _OPENMP if(! sf_getint("ompnth", &ompnth)) ompnth=0; /* OpenMP available threads */ #pragma omp parallel ompath=omp_get_num_threads(); if(ompnth<1) ompnth=ompath; omp_set_num_threads(ompnth); sf_warning("using %d threads of a total of %d",ompnth,ompath); #endif if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("snap",&snap)) snap=false; /* wavefield snapshots flag */ if(! sf_getbool("free",&fsrf)) fsrf=false; /* free surface flag */ if(! sf_getbool("expl",&expl)) expl=false; /* "exploding reflector" */ Fwav = sf_input ("in" ); /* wavelet */ Fsou = sf_input ("sou"); /* sources */ Frec = sf_input ("rec"); /* receivers */ Fvel = sf_input ("vel"); /* velocity */ Fden = sf_input ("den"); /* density */ Fref = sf_input ("ref"); /* reflectivity */ Fwfl = sf_output("wfl"); /* wavefield */ Fdat = sf_output("out"); /* data */ Fliw = sf_output("liw"); /* wavefield (scattered) */ Flid = sf_output("lid"); /* data (scattered) */ /* axes */ at = sf_iaxa(Fwav,2); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ as = sf_iaxa(Fsou,2); sf_setlabel(as,"s"); if(verb) sf_raxa(as); /* sources */ ar = sf_iaxa(Frec,2); sf_setlabel(ar,"r"); if(verb) sf_raxa(ar); /* receivers */ a1 = sf_iaxa(Fvel,1); sf_setlabel(a1,"z"); if(verb) sf_raxa(a1); /* depth */ a2 = sf_iaxa(Fvel,2); sf_setlabel(a2,"x"); if(verb) sf_raxa(a2); /* space */ nt = sf_n(at); dt = sf_d(at); ns = sf_n(as); nr = sf_n(ar); n1 = sf_n(a1); d1 = sf_d(a1); n2 = sf_n(a2); d2 = sf_d(a2); if(! sf_getint("jdata",&jdata)) jdata=1; if(snap) { /* save wavefield every *jsnap* time steps */ if(! sf_getint("jsnap",&jsnap)) jsnap=nt; } /*------------------------------------------------------------*/ /* setup output data header */ sf_oaxa(Fdat,ar,1); sf_oaxa(Flid,ar,1); sf_setn(at,nt/jdata); sf_setd(at,dt*jdata); sf_oaxa(Fdat,at,2); sf_oaxa(Flid,at,2); /* setup output wavefield header */ if(snap) { if(!sf_getint ("nqz",&nqz)) nqz=sf_n(a1); if(!sf_getint ("nqx",&nqx)) nqx=sf_n(a2); if(!sf_getfloat("oqz",&oqz)) oqz=sf_o(a1); if(!sf_getfloat("oqx",&oqx)) oqx=sf_o(a2); dqz=sf_d(a1); dqx=sf_d(a2); ac1 = sf_maxa(nqz,oqz,dqz); ac2 = sf_maxa(nqx,oqx,dqx); /* check if the imaging window fits in the wavefield domain */ uc=sf_floatalloc2(sf_n(ac1),sf_n(ac2)); ntsnap=0; for(it=0; it<nt; it++) { if(it%jsnap==0) ntsnap++; } sf_setn(at, ntsnap); sf_setd(at,dt*jsnap); if(verb) sf_raxa(at); /* sf_setn(at,nt/jsnap); sf_setd(at,dt*jsnap); */ sf_oaxa(Fwfl,ac1,1); sf_oaxa(Fwfl,ac2,2); sf_oaxa(Fwfl,at, 3); sf_oaxa(Fliw,ac1,1); sf_oaxa(Fliw,ac2,2); sf_oaxa(Fliw,at, 3); } /*------------------------------------------------------------*/ /* expand domain for FD operators and ABC */ if( !sf_getint("nb",&nb) || nb<NOP) nb=NOP; fdm=fdutil_init(verb,fsrf,a1,a2,nb,ompchunk); sf_setn(a1,fdm->nzpad); sf_seto(a1,fdm->ozpad); if(verb) sf_raxa(a1); sf_setn(a2,fdm->nxpad); sf_seto(a2,fdm->oxpad); if(verb) sf_raxa(a2); /*------------------------------------------------------------*/ if(expl) ww = sf_floatalloc( 1); else ww = sf_floatalloc(ns); bdd =sf_floatalloc(nr); sdd =sf_floatalloc(nr); /*------------------------------------------------------------*/ /* setup source/receiver coordinates */ ss = (pt2d*) sf_alloc(ns,sizeof(*ss)); rr = (pt2d*) sf_alloc(nr,sizeof(*rr)); pt2dread1(Fsou,ss,ns,2); /* read (x,z) coordinates */ pt2dread1(Frec,rr,nr,2); /* read (x,z) coordinates */ cs = lint2d_make(ns,ss,fdm); cr = lint2d_make(nr,rr,fdm); /*------------------------------------------------------------*/ /* setup FD coefficients */ dt2 = dt*dt; id1 = 1/d1; id2 = 1/d2; co = C0 * (id2*id2+id1*id1); ca2= CA * id2*id2; cb2= CB * id2*id2; ca1= CA * id1*id1; cb1= CB * id1*id1; /*------------------------------------------------------------*/ /* input density */ roin=sf_floatalloc2(n1, n2 ); ro =sf_floatalloc2(fdm->nzpad,fdm->nxpad); ro1 =sf_floatalloc2(fdm->nzpad,fdm->nxpad); ro2 =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(roin[0],n1*n2,Fden); expand(roin,ro,fdm); /* normalized density derivatives */ for (i2=NOP; i2<fdm->nxpad-NOP; i2++) { for(i1=NOP; i1<fdm->nzpad-NOP; i1++) { ro1[i2][i1] = D1(ro,i2,i1,id1) / ro[i2][i1]; ro2[i2][i1] = D2(ro,i2,i1,id2) / ro[i2][i1]; } } free(*roin); free(roin); /*------------------------------------------------------------*/ /* input velocity */ vpin=sf_floatalloc2(n1, n2 ); vp =sf_floatalloc2(fdm->nzpad,fdm->nxpad); vt =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(vpin[0],n1*n2,Fvel); expand(vpin,vp,fdm); free(*vpin); free(vpin); /*------------------------------------------------------------*/ /* input reflectivity */ rfin=sf_floatalloc2(n1, n2 ); rf =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(rfin[0],n1*n2,Fref); expand(rfin,rf,fdm); free(*rfin); free(rfin); for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nzpad; i1++) { vt[i2][i1] = vp[i2][i1] * vp[i2][i1] * dt2; } } /* free surface */ if(fsrf) { for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nb; i1++) { vt[i2][i1]=0; } } } /*------------------------------------------------------------*/ /* allocate wavefield arrays */ bum=sf_floatalloc2(fdm->nzpad,fdm->nxpad); buo=sf_floatalloc2(fdm->nzpad,fdm->nxpad); bup=sf_floatalloc2(fdm->nzpad,fdm->nxpad); bua=sf_floatalloc2(fdm->nzpad,fdm->nxpad); sum=sf_floatalloc2(fdm->nzpad,fdm->nxpad); suo=sf_floatalloc2(fdm->nzpad,fdm->nxpad); sup=sf_floatalloc2(fdm->nzpad,fdm->nxpad); sua=sf_floatalloc2(fdm->nzpad,fdm->nxpad); for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nzpad; i1++) { bum[i2][i1]=0; buo[i2][i1]=0; bup[i2][i1]=0; bua[i2][i1]=0; sum[i2][i1]=0; suo[i2][i1]=0; sup[i2][i1]=0; sua[i2][i1]=0; } } /*------------------------------------------------------------*/ /* one-way abc setup */ abc = abcone2d_make(NOP,dt,vp,fsrf,fdm); /* sponge abc setup */ spo = sponge_make(fdm->nb); /*------------------------------------------------------------*/ /* * MAIN LOOP */ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,fdm->ompchunk) private(i2,i1) shared(fdm,bua,buo,sua,suo,co,ca2,ca1,cb2,cb1,id2,id1) #endif for (i2=NOP; i2<fdm->nxpad-NOP; i2++) { for(i1=NOP; i1<fdm->nzpad-NOP; i1++) { /* 4th order Laplacian operator */ bua[i2][i1] = co * buo[i2 ][i1 ] + ca2*(buo[i2-1][i1 ] + buo[i2+1][i1 ]) + cb2*(buo[i2-2][i1 ] + buo[i2+2][i1 ]) + ca1*(buo[i2 ][i1-1] + buo[i2 ][i1+1]) + cb1*(buo[i2 ][i1-2] + buo[i2 ][i1+2]); sua[i2][i1] = co * suo[i2 ][i1 ] + ca2*(suo[i2-1][i1 ] + suo[i2+1][i1 ]) + cb2*(suo[i2-2][i1 ] + suo[i2+2][i1 ]) + ca1*(suo[i2 ][i1-1] + suo[i2 ][i1+1]) + cb1*(suo[i2 ][i1-2] + suo[i2 ][i1+2]); /* density term */ bua[i2][i1] -= ( D1(buo,i2,i1,id1) * ro1[i2][i1] + D2(buo,i2,i1,id2) * ro2[i2][i1] ); sua[i2][i1] -= ( D1(suo,i2,i1,id1) * ro1[i2][i1] + D2(suo,i2,i1,id2) * ro2[i2][i1] ); } } /* inject acceleration source */ if(expl) { sf_floatread(ww, 1,Fwav); lint2d_inject1(bua,ww[0],cs); } else { sf_floatread(ww,ns,Fwav); lint2d_inject(bua,ww,cs); } /* single scattering */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(i2,i1) shared(fdm,buo,sua,rf) #endif for (i2=0; i2<fdm->nxpad; i2++) { for (i1=0; i1<fdm->nzpad; i1++) { sua[i2][i1] -= bua[i2][i1] * 2*rf[i2][i1]; } } /* step forward in time */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,fdm->ompchunk) private(i2,i1) shared(fdm,bua,buo,bum,bup,sua,suo,sum,sup,vt,dt2) #endif for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nzpad; i1++) { bup[i2][i1] = 2*buo[i2][i1] - bum[i2][i1] + bua[i2][i1] * vt[i2][i1]; sup[i2][i1] = 2*suo[i2][i1] - sum[i2][i1] + sua[i2][i1] * vt[i2][i1]; } } /* circulate wavefield arrays */ but=bum; bum=buo; buo=bup; bup=but; sut=sum; sum=suo; suo=sup; sup=sut; /* one-way abc apply*/ abcone2d_apply(buo,bum,NOP,abc,fdm); sponge2d_apply(bum, spo,fdm); sponge2d_apply(buo, spo,fdm); abcone2d_apply(suo,sum,NOP,abc,fdm); sponge2d_apply(sum, spo,fdm); sponge2d_apply(suo, spo,fdm); /* extract data at receivers */ lint2d_extract(buo,bdd,cr); lint2d_extract(suo,sdd,cr); if( it%jdata==0) { sf_floatwrite(bdd,nr,Fdat); sf_floatwrite(sdd,nr,Flid); } /* extract wavefield in the "box" */ if(snap && it%jsnap==0) { cut2d(buo,uc,fdm,ac1,ac2); sf_floatwrite(uc[0],sf_n(ac1)*sf_n(ac2),Fwfl); cut2d(suo,uc,fdm,ac1,ac2); sf_floatwrite(uc[0],sf_n(ac1)*sf_n(ac2),Fliw); } } if(verb) fprintf(stderr,"\n"); exit (0); }
int main (int argc, char *argv[]) { bool verb; /* verbosity */ bool incore; /* in core execution */ float eps; /* dip filter constant */ int nrmax; /* number of reference velocities */ float dtmax; /* time error */ int pmx,pmy; /* padding in the k domain */ int tmx,tmy; /* boundary taper size */ bool cw; /* converted waves flag */ sf_axis az,ax,ay,aw,alx,aly; int n,nz,nw; sf_file Fs_s=NULL,Fs_r=NULL; /* slowness file S (nlx,nly,nz) */ sf_file Fw_s=NULL,Fw_r=NULL; /* wavefield file D or U ( nx, ny,nw) */ sf_file Fr=NULL; /* reflectivity */ fslice wfl_s=NULL,wfl_r=NULL,refl=NULL; fslice slo_s=NULL,slo_r=NULL; /*------------------------------------------------------------*/ sf_init(argc,argv); /* converted waves flag */ if (NULL != sf_getstring("sls")) { cw=true; } else { cw=false; } if (!sf_getbool("verb", &verb)) verb = true; /* verbosity flag */ if (!sf_getbool("incore",&incore))incore = false; /* in core execution */ if (!sf_getfloat("eps", &eps )) eps = 0.01; /* stability parameter */ if (!sf_getint( "nrmax",&nrmax)) nrmax = 1; /* maximum number of refs */ if (!sf_getfloat("dtmax",&dtmax)) dtmax = 0.004; /* time error */ if (!sf_getint( "pmx", &pmx )) pmx = 0; /* padding on x */ if (!sf_getint( "pmy", &pmy )) pmy = 0; /* padding on y */ if (!sf_getint( "tmx", &tmx )) tmx = 0; /* taper on x */ if (!sf_getint( "tmy", &tmy )) tmy = 0; /* taper on y */ /*------------------------------------------------------------*/ /* SLOWNESS */ ; Fs_s = sf_input("slo"); if(cw) Fs_r = sf_input("sls"); alx = sf_iaxa(Fs_s,1); sf_setlabel(alx,"lx"); aly = sf_iaxa(Fs_s,2); sf_setlabel(aly,"ly"); az = sf_iaxa(Fs_s,3); sf_setlabel(az , "z"); /* test here if slo and sls have similar sizes */ n = sf_n(alx)*sf_n(aly); nz = sf_n(az); ; slo_s = fslice_init(n,nz,sizeof(float)); if(cw) slo_r = fslice_init(n,nz,sizeof(float)); ; fslice_load(Fs_s,slo_s,SF_FLOAT); if(cw) fslice_load(Fs_r,slo_r,SF_FLOAT); /*------------------------------------------------------------*/ /* WAVEFIELD/IMAGE */ Fw_s = sf_input ( "in"); Fw_r = sf_output("out"); sf_settype(Fw_r,SF_COMPLEX); Fr = sf_input ("ref"); if (SF_COMPLEX !=sf_gettype(Fw_s)) sf_error("Need complex source wavefield"); ax = sf_iaxa(Fw_s,1); sf_setlabel(ax,"x"); sf_oaxa(Fw_r,ax,1); ay = sf_iaxa(Fw_s,2); sf_setlabel(ay,"y"); sf_oaxa(Fw_r,ay,2); aw = sf_iaxa(Fw_s,3); sf_setlabel(aw,"w"); sf_oaxa(Fw_r,aw,3); n = sf_n(ax)*sf_n(ay); nw = sf_n(aw); /* slice management (temp files) */ wfl_s = fslice_init(n,nw,sizeof(sf_complex)); wfl_r = fslice_init(n,nw,sizeof(sf_complex)); refl = fslice_init(n,nz,sizeof(float)); fslice_load(Fw_s,wfl_s,SF_COMPLEX); fslice_load(Fr, refl, SF_FLOAT); /*------------------------------------------------------------*/ /* MODELING */ srmod_init (verb,incore,eps,dtmax, az,aw,ax,ay,alx,aly, tmx,tmy,pmx,pmy); if(cw) { srmod_cw_init (dtmax,nrmax,slo_s,slo_r); srmod_cw (wfl_s,wfl_r,refl); srmod_cw_close(); } else { srmod_pw_init (dtmax,nrmax,slo_s); srmod_pw (wfl_s,wfl_r,refl); srmod_pw_close(); } srmod_close(); /*------------------------------------------------------------*/ /* slice management (temp files) */ fslice_dump(Fw_r,wfl_r,SF_COMPLEX); ; fslice_close(slo_s); if(cw) fslice_close(slo_r); ; fslice_close(wfl_s); ; fslice_close(wfl_r); ; fslice_close(refl); exit (0); }
int main(int argc, char * argv[]) { sf_file inA, outC, inB; int an1, an2, bn1, bn2; int im, in, ik, m, n, k, nth; sf_complex **a, **b, **c; sf_axis aax1, aax2, bax1, bax2, cax1, cax2; /* init RSF */ sf_init (argc, argv); inA = sf_input("in"); inB = sf_input("B"); outC= sf_output("out"); if(SF_COMPLEX != sf_gettype(inA)) sf_error("Need complex input!"); if(SF_COMPLEX != sf_gettype(inB)) sf_error("Need complex input!"); if(!sf_histint(inA, "n1", &an1)) sf_error("No n1 in input"); if(!sf_histint(inB, "n1", &bn1)) sf_error("No n1 in input"); if(!sf_histint(inA, "n2", &an2)) an2 = 1; if(!sf_histint(inB, "n2", &bn2)) bn2 = 1; if(sf_leftsize(inA,2)>1) sf_error("Input should be a matrix!"); if(sf_leftsize(inB,2)>1) sf_error("Input should be a matrix!"); if(an2 != bn1) sf_error("Input do not match!"); aax1 = sf_iaxa(inA, 1); aax2 = sf_iaxa(inA, 2); bax1 = sf_iaxa(inB, 1); bax2 = sf_iaxa(inB, 2); cax1 = aax1; cax2 = bax2; a = sf_complexalloc2(an1, an2); b = sf_complexalloc2(bn1, bn2); sf_complexread(a[0], an1*an2, inA); sf_complexread(b[0], bn1*bn2, inB); m = an1; n = an2; k = bn2; #ifdef _OPENMP #pragma omp parallel { nth = omp_get_num_threads(); /* omp_set_num_threads(nth); */ } sf_warning(">>>> Using %d threads <<<<<", nth); #endif c = sf_complexalloc2(m,k); #ifdef _OPENMP #pragma omp parallel for private(im,ik) shared(c,a,b,an1,an2,bn2) #endif for(im=0; im< an1; im++) { for (ik=0; ik<bn2; ik++ ) { c[ik][im]=sf_cmplx(0.0,0.0); for (in=0; in<an2; in++) { #ifdef SF_HAS_COMPLEX_H c[ik][im]+=a[in][im]*b[ik][in]; #else c[ik][im]+=sf_cmul(a[in][im],b[ik][in]); #endif } } } sf_oaxa(outC, cax1, 1); sf_oaxa(outC, cax2, 2); sf_complexwrite(c[0], m*k, outC); exit(0); }
int main(int argc, char* argv[]) { bool verb; /* verbosity flag */ bool abc; /* absorbing boundary conditions flag */ bool free; /* free surface flag*/ bool snap; /* wavefield snapshots flag */ int jsnap;/* save wavefield every *jsnap* time steps */ /* cube axes */ sf_axis at,az,ax,as,ar,bt; int it,iz,ix,is,ir, iop; int nt,nz,nx,ns,nr,nz2,nx2; float z0,x0,dt,dx,dz, idx,idz,dt2; /* Laplacian */ int nop=2; /* Laplacian operator size */ float c0, c1, c2; /* Laplacian operator coefficients */ float co,c1x,c2x,c1z,c2z; int nbz,nbx; /* boundary size */ float tz, tx; /* sponge boundary decay coefficients */ float dp; float ws; /* injected data */ /* linear interpolation */ float *fzs,*fxs, *fzr,*fxr; int *jzs,*jxs, *jzr,*jxr; float *ws00,*ws01,*ws10,*ws11; float *wr00,*wr01,*wr10,*wr11; /* boundary */ float *bzl,*bzh,*bxl,*bxh; /* I/O files */ sf_file Fw,Fs,Fr; float *ww; /* wavelet */ pt2d *ss, *rr; /* source/receiver locations */ float **tt; /* taper */ /* background */ sf_file Bv,Bd,Bu; /* velocity, data, wavefield */ float **bvv,**bvo; /* velocity */ float *bdd; /* data */ float **bum,**buo,**bup,**bud; /* wavefields */ /* perturbation */ sf_file Pv,Pd,Pu; float **pvv,**pvo; float *pdd; float **pum,**puo,**pup,**pud; int ompchunk; /* OpenMP data chunk size */ /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getint("ompchunk",&ompchunk)) ompchunk=1; if(! sf_getbool("verb",&verb)) verb=false; if(! sf_getbool( "abc",&abc )) abc=false; if(! sf_getbool("snap",&snap)) snap=false; if(! sf_getbool("free",&free)) free=false; Fw = sf_input ("in" ); /* wavelet */ Fs = sf_input ("sou"); /* sources */ Fr = sf_input ("rec"); /* receivers */ Bv = sf_input ("vel"); /* velocity */ Bu = sf_output("wfl"); /* wavefield */ Bd = sf_output("out"); /* data */ Pv = sf_input ("ref"); /* velocity */ Pu = sf_output("liw"); /* linearized wavefield */ Pd = sf_output("lid"); /* linearized data */ /* read axes*/ at=sf_iaxa(Fw,1); sf_setlabel(at,"t"); nt=sf_n(at); dt=sf_d(at); if(verb) sf_raxa(at); /* time */ as=sf_iaxa(Fs,2); sf_setlabel(as,"s"); ns=sf_n(as); if(verb) sf_raxa(as); /* sources */ ar=sf_iaxa(Fr,2); sf_setlabel(ar,"r"); nr=sf_n(ar); if(verb) sf_raxa(ar); /* receivers */ az=sf_iaxa(Bv,1); sf_setlabel(az,"z"); nz=sf_n(az); dz=sf_d(az); if(verb) sf_raxa(az); /* depth */ ax=sf_iaxa(Bv,2); sf_setlabel(ax,"x"); nx=sf_n(ax); dx=sf_d(ax); if(verb) sf_raxa(ax); /* space */ /* configure wavefield snapshots */ if(snap) { if(! sf_getint("jsnap",&jsnap)) jsnap=nt; } /*------------------------------------------------------------*/ /* expand domain for absorbing boundary conditions */ if(abc) { if(! sf_getint("nbz",&nbz)) nbz=nop; if(nbz<nop) nbz=nop; if(! sf_getint("nbx",&nbx)) nbx=nop; if(nbx<nop) nbx=nop; if(! sf_getfloat("tz",&tz)) tz=0.025; if(! sf_getfloat("tx",&tx)) tx=0.025; } else { nbz=nop; nbx=nop; } /* expanded domain ( az+2 nz, ax+2 nx ) */ nz2=nz+2*nbz; z0=sf_o(az)-nbz*dz; nx2=nx+2*nbx; x0=sf_o(ax)-nbx*dx; sf_setn(az,nz2); sf_seto(az,z0); if(verb) sf_raxa(az); sf_setn(ax,nx2); sf_seto(ax,x0); if(verb) sf_raxa(ax); /*------------------------------------------------------------*/ /* setup output wavefield header */ if(snap) { bt = sf_maxa(nt/jsnap,sf_o(at),dt*jsnap); sf_setlabel(bt,"t"); sf_oaxa(Bu,az,1); sf_oaxa(Bu,ax,2); sf_oaxa(Bu,bt,3); sf_oaxa(Pu,az,1); sf_oaxa(Pu,ax,2); sf_oaxa(Pu,bt,3); } /* setup output data header */ sf_oaxa(Bd,ar,1); sf_oaxa(Bd,at,2); sf_oaxa(Pd,ar,1); sf_oaxa(Pd,at,2); dt2 = dt*dt; idz = 1/(dz*dz); idx = 1/(dx*dx); /* Laplacian coefficients */ c0=-30./12.; c1=+16./12.; c2=- 1./12.; co = c0 * (idx+idz); c1x= c1 * idx; c2x= c2 * idx; c1z= c1 * idz; c2z= c2 * idz; /*------------------------------------------------------------*/ /* allocate arrays */ ww=sf_floatalloc (nt); sf_floatread(ww ,nt ,Fw); bvv=sf_floatalloc2(nz,nx); sf_floatread(bvv[0],nz*nx,Bv); pvv=sf_floatalloc2(nz,nx); sf_floatread(pvv[0],nz*nx,Pv); /* allocate source/receiver point arrays */ ss = (pt2d*) sf_alloc(ns,sizeof(*ss)); rr = (pt2d*) sf_alloc(nr,sizeof(*rr)); pt2dread1(Fs,ss,ns,3); /* read 3 elements (x,z,v) */ pt2dread1(Fr,rr,nr,2); /* read 2 elements (x,z) */ bdd=sf_floatalloc(nr); pdd=sf_floatalloc(nr); jzs=sf_intalloc(ns); fzs=sf_floatalloc(ns); jzr=sf_intalloc(nr); fzr=sf_floatalloc(nr); jxs=sf_intalloc(ns); fxs=sf_floatalloc(ns); jxr=sf_intalloc(nr); fxr=sf_floatalloc(nr); ws00 = sf_floatalloc(ns); wr00 = sf_floatalloc(nr); ws01 = sf_floatalloc(ns); wr01 = sf_floatalloc(nr); ws10 = sf_floatalloc(ns); wr10 = sf_floatalloc(nr); ws11 = sf_floatalloc(ns); wr11 = sf_floatalloc(nr); /*------------------------------------------------------------*/ for (is=0;is<ns;is++) { if(ss[is].z >= z0 && ss[is].z < z0 + (nz2-1)*dz && ss[is].x >= x0 && ss[is].x < x0 + (nx2-1)*dx) { jzs[is] = (int)( (ss[is].z-z0)/dz); fzs[is] = (ss[is].z-z0)/dz - jzs[is]; jxs[is] = (int)( (ss[is].x-x0)/dx); fxs[is] = (ss[is].x-x0)/dx - jxs[is]; } else { jzs[is] = 0; jxs[is] = 0; fzs[is] = 1; fxs[is] = 0; ss[is].v= 0; } ws00[is] = (1-fzs[is])*(1-fxs[is]); ws01[is] = ( fzs[is])*(1-fxs[is]); ws10[is] = (1-fzs[is])*( fxs[is]); ws11[is] = ( fzs[is])*( fxs[is]); } for (ir=0;ir<nr;ir++) { if(rr[ir].z >= z0 && rr[ir].z < z0 + (nz2-1)*dz && rr[ir].x >= x0 && rr[ir].x < x0 + (nx2-1)*dx) { jzr[ir] = (int)( (rr[ir].z-z0)/dz); fzr[ir] = (rr[ir].z-z0)/dz - jzr[ir]; jxr[ir] = (int)( (rr[ir].x-x0)/dx); fxr[ir] = (rr[ir].x-x0)/dx - jxr[ir]; rr[ir].v=1; } else { jzr[ir] = 0; fzr[ir] = 1; rr[ir].v= 0; } wr00[ir] = (1-fzr[ir])*(1-fxr[ir]); wr01[ir] = ( fzr[ir])*(1-fxr[ir]); wr10[ir] = (1-fzr[ir])*( fxr[ir]); wr11[ir] = ( fzr[ir])*( fxr[ir]); } /*------------------------------------------------------------*/ /* allocate temporary arrays */ bum=sf_floatalloc2(nz2,nx2); buo=sf_floatalloc2(nz2,nx2); bup=sf_floatalloc2(nz2,nx2); bud=sf_floatalloc2(nz2,nx2); pum=sf_floatalloc2(nz2,nx2); puo=sf_floatalloc2(nz2,nx2); pup=sf_floatalloc2(nz2,nx2); pud=sf_floatalloc2(nz2,nx2); tt=sf_floatalloc2(nz2,nx2); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(iz,ix) shared(nx2,nz2,bum,buo,bup,bud,pum,puo,pup,pud,tt) #endif for (iz=0; iz<nz2; iz++) { for (ix=0; ix<nx2; ix++) { bum[ix][iz]=pum[ix][iz]=0; buo[ix][iz]=puo[ix][iz]=0; bup[ix][iz]=pup[ix][iz]=0; bud[ix][iz]=pud[ix][iz]=0; tt[ix][iz]=1; } } /*------------------------------------------------------------*/ /* velocity in the expanded domain (vo=vv^2)*/ bvo=sf_floatalloc2(nz2,nx2); pvo=sf_floatalloc2(nz2,nx2); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(iz,ix) shared(nz,nx,bvv,pvv,bvo,pvo) #endif for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { bvo[nbx+ix][nbz+iz] = bvv[ix][iz] * bvv[ix][iz]; pvo[nbx+ix][nbz+iz] = pvv[ix][iz]; } } /* fill boundaries */ for (iz=0; iz<nbz; iz++) { for (ix=0; ix<nx2; ix++) { bvo[ix][ iz ] = bvo[ix][ nbz ]; bvo[ix][nz2-iz-1] = bvo[ix][nz2-nbz-1]; pvo[ix][ iz ] = pvo[ix][ nbz ]; pvo[ix][nz2-iz-1] = pvo[ix][nz2-nbz-1]; } } for (iz=0; iz<nz2; iz++) { for (ix=0; ix<nbx; ix++) { bvo[ ix ][iz] = bvo[ nbx ][iz]; bvo[nx2-ix-1][iz] = bvo[nx2-nbx-1][iz]; pvo[ ix ][iz] = pvo[ nbx ][iz]; pvo[nx2-ix-1][iz] = pvo[nx2-nbx-1][iz]; } } /*------------------------------------------------------------*/ /* free surface */ if(abc && free) { for (iz=0; iz<nbz; iz++) { for (ix=0; ix<nx2; ix++) { bvo[ix][iz]=0; pvo[ix][iz]=0; } } } /*------------------------------------------------------------*/ /* sponge ABC setup */ if(abc) { for (iz=0; iz<nbz; iz++) { for (ix=0; ix<nx2; ix++) { tt[ix][ iz ] = exp( - (tz*(nbz-iz))*(tz*(nbz-iz)) ); tt[ix][nz2-iz-1] = tt[ix][iz]; } } for (iz=0; iz<nz2; iz++) { for (ix=0; ix<nbx; ix++) { tt[ ix ][iz] = exp( - (tx*(nbx-ix))*(tx*(nbx-ix)) ); tt[nx2-ix-1][iz] = tt[ix][iz]; } } } /* one-way ABC setup */ bzl=sf_floatalloc(nx2); bzh=sf_floatalloc(nx2); bxl=sf_floatalloc(nz2); bxh=sf_floatalloc(nz2); for (ix=0;ix<nx2;ix++) { dp = bvo[ix][ nop ] *dt/dz; bzl[ix] = (1-dp)/(1+dp); dp = bvo[ix][nz2-nop-1] *dt/dz; bzh[ix] = (1-dp)/(1+dp); } for (iz=0;iz<nz2;iz++) { dp = bvo[ nop ][iz] *dt/dx; bxl[iz] = (1-dp)/(1+dp); dp = bvo[nx2-nop-1][iz] *dt/dx; bxh[iz] = (1-dp)/(1+dp); } /*------------------------------------------------------------*/ /* * MAIN LOOP */ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); /* 4th order Laplacian operator */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(iz,ix) shared(nop,nx2,nz2,bud,buo,pud,puo,co,c1x,c1z,c2x,c2z,idx,idz) #endif for (ix=nop; ix<nx2-nop; ix++) { for (iz=nop; iz<nz2-nop; iz++) { bud[ix][iz] = co * buo[ix ][iz ] + c1x*(buo[ix-1][iz ] + buo[ix+1][iz ]) + c2x*(buo[ix-2][iz ] + buo[ix+2][iz ]) + c1z*(buo[ix ][iz-1] + buo[ix ][iz+1]) + c2z*(buo[ix ][iz-2] + buo[ix ][iz+2]); pud[ix][iz] = co * puo[ix ][iz ] + c1x*(puo[ix-1][iz ] + puo[ix+1][iz ]) + c2x*(puo[ix-2][iz ] + puo[ix+2][iz ]) + c1z*(puo[ix ][iz-1] + puo[ix ][iz+1]) + c2z*(puo[ix ][iz-2] + puo[ix ][iz+2]); } } /* inject source */ for (is=0;is<ns;is++) { ws = ww[it] * ss[is].v; bud[ jxs[is] ][ jzs[is] ] -= ws * ws00[is]; bud[ jxs[is] ][ jzs[is]+1] -= ws * ws01[is]; bud[ jxs[is]+1][ jzs[is] ] -= ws * ws10[is]; bud[ jxs[is]+1][ jzs[is]+1] -= ws * ws11[is]; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,pud,bud,pvo) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { pud[ix][iz] -= bud[ix][iz] * 2*pvo[ix][iz]; } } /* velocity scale */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,bud,pud,bvo) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { bud[ix][iz] *= bvo[ix][iz]; pud[ix][iz] *= bvo[ix][iz]; } } /* time step */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,bud,buo,bum,bup,pud,puo,pum,pup,dt2) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { bup[ix][iz] = 2*buo[ix][iz] - bum[ix][iz] + bud[ix][iz] * dt2; bum[ix][iz] = buo[ix][iz]; buo[ix][iz] = bup[ix][iz]; pup[ix][iz] = 2*puo[ix][iz] - pum[ix][iz] + pud[ix][iz] * dt2; pum[ix][iz] = puo[ix][iz]; puo[ix][iz] = pup[ix][iz]; } } /* one-way ABC apply */ if(abc) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz,iop) shared(nx2,nz2,nop,buo,bum,puo,pum,bzl,bzh) #endif for(ix=0;ix<nx2;ix++) { for(iop=0;iop<nop;iop++) { iz = nop-iop; buo [ix][iz ] = bum[ix][iz+1] +(bum[ix][iz ] - buo[ix][iz+1]) * bzl[ix]; puo [ix][iz ] = pum[ix][iz+1] +(pum[ix][iz ] - puo[ix][iz+1]) * bzl[ix]; iz = nz2-nop+iop-1; buo [ix][iz ] = bum[ix][iz-1] +(bum[ix][iz ] - buo[ix][iz-1]) * bzh[ix]; puo [ix][iz ] = pum[ix][iz-1] +(pum[ix][iz ] - puo[ix][iz-1]) * bzh[ix]; } } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,1) private(ix,iz,iop) shared(nx2,nz2,nop,buo,bum,puo,pum,bzl,bzh) #endif for(iop=0;iop<nop;iop++) { for(iz=0;iz<nz2;iz++) { ix = nop-iop; buo [ix ][iz] = bum[ix+1][iz] +(bum[ix ][iz] - buo[ix+1][iz]) * bxl[iz]; puo [ix ][iz] = pum[ix+1][iz] +(pum[ix ][iz] - puo[ix+1][iz]) * bxl[iz]; ix = nx2-nop+iop-1; buo [ix ][iz] = bum[ix-1][iz] +(bum[ix ][iz] - buo[ix-1][iz]) * bxh[iz]; puo [ix ][iz] = pum[ix-1][iz] +(pum[ix ][iz] - puo[ix-1][iz]) * bxh[iz]; } } } /* sponge ABC apply */ if(abc) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,buo,bum,bud,puo,pum,pud,tt) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { buo[ix][iz] *= tt[ix][iz]; bum[ix][iz] *= tt[ix][iz]; bud[ix][iz] *= tt[ix][iz]; puo[ix][iz] *= tt[ix][iz]; pum[ix][iz] *= tt[ix][iz]; bud[ix][iz] *= tt[ix][iz]; } } } /* write wavefield */ if(snap && it%jsnap==0) { sf_floatwrite(buo[0],nz2*nx2,Bu); sf_floatwrite(puo[0],nz2*nx2,Pu); } /* write data */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,1) private(ir) shared(bdd,pdd,rr,buo,puo,jzr,wr00,wr01,wr10,wr11) #endif for (ir=0;ir<nr;ir++) { bdd[ir] = buo[ jxr[ir] ][ jzr[ir] ] * wr00[ir] + buo[ jxr[ir] ][ jzr[ir]+1] * wr01[ir] + buo[ jxr[ir]+1][ jzr[ir] ] * wr10[ir] + buo[ jxr[ir]+1][ jzr[ir]+1] * wr11[ir]; bdd[ir] *= rr[ir].v; pdd[ir] = puo[ jxr[ir] ][ jzr[ir] ] * wr00[ir] + puo[ jxr[ir] ][ jzr[ir]+1] * wr01[ir] + puo[ jxr[ir]+1][ jzr[ir] ] * wr10[ir] + puo[ jxr[ir]+1][ jzr[ir]+1] * wr11[ir]; pdd[ir] *= rr[ir].v; } /* write data */ sf_floatwrite(bdd,nr,Bd); sf_floatwrite(pdd,nr,Pd); } if(verb) fprintf(stderr,"\n"); exit (0); }
int main(int argc, char* argv[]) { bool verb; int nx,nz,nc,ic,iz,ix; int ind=0; float tmp; float dx,dz,ox,oz; pt2d *cc=NULL; float **eps=NULL,**del,***out=NULL; float x,y,lambda0,lambda1,lambda2,twoA; float lm00,lm01,lm02,lm10,lm11,lm12,lm20,lm21,lm22; float *a=NULL,*b=NULL,**llm=NULL; sf_axis ax,az,ac; sf_file Fin=NULL,Fdel=NULL, Fc=NULL,Fout=NULL; /* init RSF */ sf_init(argc,argv); if(! sf_getbool("verb",&verb)) verb=false; Fin = sf_input ("in" ); Fdel= sf_input ("del" ); Fout = sf_output ("out" ); Fc = sf_input ("cc" ); /* sample locations */ /* input axes */ az = sf_iaxa(Fin,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); ax = sf_iaxa(Fin,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); nz = sf_n(az); dz = sf_d(az); oz = sf_o(az); nx = sf_n(ax); dx = sf_d(ax); ox = sf_o(ax); eps = sf_floatalloc2(nz,nx); del = sf_floatalloc2(nz,nx); sf_floatread(eps[0],nz*nx,Fin); sf_floatread(del[0],nz*nx,Fdel); /* CIP coordinates */ ac = sf_iaxa(Fc,2); sf_setlabel(ac,"cc"); sf_setunit(ac,""); if(verb) sf_raxa(ac); nc = sf_n(ac); cc= (pt2d*) sf_alloc(nc,sizeof(*cc)); pt2dread1(Fc,cc,nc,2); /* read coordinates */ /* nc=3*/ /* output files*/ out = sf_floatalloc3(nz,nx,nc); sf_oaxa(Fout,az,1); sf_oaxa(Fout,ax,2); sf_oaxa(Fout,ac,3); nc=3; a = sf_floatalloc(nc); b = sf_floatalloc(nc); llm = sf_floatalloc2(2,nc); /*find sample indexes*/ for(ic=0; ic<nc; ic++) { b[ic]=cc[ic].z; /*delta*/ a[ic]=cc[ic].x; /*epsilon*/ sf_warning("x%d=%f,z%d=%f: epsilon=%f delta=%f",ic,cc[ic].x,ic,cc[ic].z,a[ic],b[ic]); } /* a[0]=0.0; b[0]=0.0;*/ /* a[2]=0.65; b[2]=0.0; */ /* a[1]=0.0; b[1]=0.35;*/ /*matrix*/ twoA=(a[0]-a[2])*(b[1]-b[2])-(a[1]-a[2])*(b[0]-b[2]); /* if(twoA<0) { */ /* tmp=a[1];a[1]=a[2];a[2]=tmp; */ /* tmp=b[1];b[1]=b[2];b[2]=tmp; */ /* } */ sf_warning("a=%f %f %f",a[0],a[1],a[2]); sf_warning("b=%f %f %f",b[0],b[1],b[2]); twoA=(a[0]-a[2])*(b[1]-b[2])-(a[1]-a[2])*(b[0]-b[2]); llm[0][0]=a[1]*b[2]-a[2]*b[1]; llm[0][1]=b[1]-b[2]; llm[0][2]=a[2]-a[1]; llm[1][0]=a[2]*b[0]-a[0]*b[2]; llm[1][1]=b[2]-b[0]; llm[1][2]=a[0]-a[2]; llm[2][0]=a[0]*b[1]-a[1]*b[0]; llm[2][1]=b[0]-b[1]; llm[2][2]=a[1]-a[0]; sf_warning(""); sf_warning("%f %f %f",llm[0][0], llm[0][1], llm[0][2]); sf_warning("%f %f %f",llm[1][0], llm[1][1], llm[1][2]); sf_warning("%f %f %f",llm[2][0], llm[2][1], llm[2][2]); sf_warning("area=%f",twoA); lm00=a[1]*b[2]-a[2]*b[1]; lm01=b[1]-b[2]; lm02=a[2]-a[1]; lm10=a[2]*b[0]-a[0]*b[2]; lm11=b[2]-b[0]; lm12=a[0]-a[2]; lm20=a[0]*b[1]-a[1]*b[0]; lm21=b[0]-b[1]; lm22=a[1]-a[0]; sf_warning(""); sf_warning("%f %f %f",lm00, lm01, lm02); sf_warning("%f %f %f",lm10, lm11, lm12); sf_warning("%f %f %f",lm20, lm21, lm22); /* find shape functions */ for (ic=0; ic<nc; ic++) { for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { out[ic][ix][iz]=0.; } } } if(twoA!=0){ for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { x=eps[ix][iz]; y=del[ix][iz]; lambda0=lm00 + lm01*x + lm02*y; lambda1=lm10 + lm11*x + lm12*y; lambda2=lm20 + lm21*x + lm22*y; out[0][ix][iz]=lambda0/twoA; out[1][ix][iz]=lambda1/twoA; out[2][ix][iz]=lambda2/twoA; } } } sf_floatwrite(out[0][0],nz*nx*nc,Fout); }
int main(int argc, char* argv[]) { bool verb,isreversed; sf_file Fs,Fr,Fi; /* I/O files */ sf_axis az,ax,at,aa; /* cube axes */ int iz,ix,it; int nz,nx,nt; off_t iseek; float **us=NULL,**ur=NULL,**ii=NULL; float scale; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); /* OMP parameters */ #ifdef _OPENMP omp_init(); #endif if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("isreversed",&isreversed)) isreversed=false; /* received wavefield */ Fs = sf_input ("in" ); Fr = sf_input ("ur" ); Fi = sf_output("out"); /*------------------------------------------------------------*/ /* read axes */ az=sf_iaxa(Fs,1); nz = sf_n(az); ax=sf_iaxa(Fs,2); nx = sf_n(ax); at=sf_iaxa(Fs,3); nt = sf_n(at); aa=sf_maxa(1,0,1); sf_setlabel(aa,""); sf_setunit (aa,""); if(verb) { sf_raxa(az); sf_raxa(ax); sf_raxa(at); } /* write axes */ sf_oaxa(Fi,az,1); sf_oaxa(Fi,ax,2); sf_oaxa(Fi,aa,3); /*------------------------------------------------------------*/ /* allocate work arrays */ ii = sf_floatalloc2(nz,nx); us = sf_floatalloc2(nz,nx); ur = sf_floatalloc2(nz,nx); for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz]=0.; } } /*------------------------------------------------------------*/ if(isreversed) { /* receiver wavefield is reversed */ if(verb) fprintf(stderr,"nt\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b%04d",it); sf_floatread(us[0],nz*nx,Fs); sf_floatread(ur[0],nz*nx,Fr); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(ix,iz) \ shared (ii,us,ur,nx,nz) #endif for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz] += us[ix][iz]*ur[ix][iz]; } } } /* it */ if(verb) fprintf(stderr,"\n"); } else { /* receiver wavefield is NOT reversed */ if(verb) fprintf(stderr,"nt\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",(nt-it-1)); sf_floatread(us[0],nz*nx,Fs); iseek=(off_t)(nt-1-it)*nz*nx*sizeof(float); sf_seek(Fr,iseek,SEEK_SET); sf_floatread(ur[0],nz*nx,Fr); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(ix,iz) \ shared (ii,us,ur,nx,nz) #endif for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz] += us[ix][iz]*ur[ix][iz]; } } } /* it */ if(verb) fprintf(stderr,"\n"); } /* end "is reversed" */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* scale image */ scale = 1./nt; for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz] *=scale; } } /*------------------------------------------------------------*/ /* write image */ sf_floatwrite(ii[0],nx*nz,Fi); /*------------------------------------------------------------*/ /* deallocate arrays */ free(*ii); free(ii); free(*us); free(us); free(*ur); free(ur); /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char* argv[]) { clock_t tstart,tend; double duration; /*flag*/ bool verb, adj; /* migration(adjoint) flag */ bool wantwf; bool wantrecord; /* actually means "need record" */ /*I/O*/ sf_file Fvel; sf_file left, right, leftb, rightb; sf_file Fsrc, Frcd/*source and record*/; sf_file Ftmpwf, Ftmpbwf; sf_file Fimg; sf_axis at, ax, az; /*grid index variables*/ int nx, nz, nt, wfnt; int nzx, nx2, nz2, n2, m2, pad1, nk; int ix, it; int nxb, nzb; float dt, dx, dz, wfdt; float ox, oz; /*source/geophone location*/ float slx, slz; int spx, spz; float gdep; int gpz,gpx,gpl; /*geophone depth/x-crd/length*/ /*Model*/ sf_complex **lt, **rt; sf_complex **ltb, **rtb; /*Data*/ sf_complex ***wavefld, ***wavefld2; sf_complex **record, **img; float **sill; int snpint; /*source*/ sf_complex *ww; float *rr; int rectz,rectx,repeat; /*smoothing parameters*/ float trunc; /*abc boundary*/ int top,bot,lft,rht; /*memoray*/ int tmpint; tstart = clock(); sf_init(argc, argv); if (!sf_getbool("verb", &verb)) verb=false; /*verbosity*/ if (!sf_getbool("adj", &adj)) adj=true; /*migration*/ if (!sf_getbool("wantwf", &wantwf)) wantwf=false; /*output forward and backward wavefield*/ if (!sf_getbool("wantrecord", &wantrecord)) wantrecord=true; /*if n, using record data generated by this program */ /*Set I/O file*/ if (adj) { /* migration */ if (wantrecord) { Frcd = sf_input("in"); /*record from elsewhere*/ Fsrc = sf_input("src"); /*source wavelet*/ } else { Frcd = sf_output("rec"); /*record produced by forward modeling*/ Fsrc = sf_input("in"); /*source wavelet*/ } Fimg = sf_output("out"); } else { /* modeling */ Fimg = sf_input("in"); Frcd = sf_output("out"); Fsrc = sf_input("src"); /*source wavelet*/ } Fvel = sf_input("vel"); /*velocity - just for model dimension*/ if (wantwf) { Ftmpwf = sf_output("tmpwf");/*wavefield snap*/ Ftmpbwf = sf_output("tmpbwf"); } /*--- Axes parameters ---*/ at = sf_iaxa(Fsrc, 1); nt = sf_n(at); dt = sf_d(at); az = sf_iaxa(Fvel, 1); nzb = sf_n(az); dz = sf_d(az); oz = sf_o(az); ax = sf_iaxa(Fvel, 2); nxb = sf_n(ax); dx = sf_d(ax); ox = sf_o(ax); nzx = nzb*nxb; /*--- parameters of source ---*/ if (!sf_getfloat("srctrunc", &trunc)) trunc=0.4; if (!sf_getint("rectz", &rectz)) rectz=1; if (!sf_getint("rectx", &rectx)) rectx=1; if (!sf_getint("repeat", &repeat)) repeat=0; ww=sf_complexalloc(nt); rr=sf_floatalloc(nzx); /* propagator matrices */ left = sf_input("left"); right = sf_input("right"); leftb = sf_input("leftb"); rightb = sf_input("rightb"); if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ nz2 = kiss_fft_next_fast_size(nzb*pad1); nx2 = kiss_fft_next_fast_size(nxb); nk = nz2*nx2; /*wavenumber*/ if (!sf_histint(left,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in left",nzx); if (!sf_histint(left,"n2",&m2)) sf_error("Need n2= in left"); if (!sf_histint(right,"n1",&n2) || n2 != m2) sf_error("Need n1=%d in right",m2); if (!sf_histint(right,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in right",nk); lt = sf_complexalloc2(nzx,m2); rt = sf_complexalloc2(m2,nk); sf_complexread(lt[0],nzx*m2,left); sf_complexread(rt[0],m2*nk,right); ltb = sf_complexalloc2(nzx,m2); rtb = sf_complexalloc2(m2,nk); sf_complexread(ltb[0],nzx*m2,leftb); sf_complexread(rtb[0],m2*nk,rightb); sf_fileclose(left); sf_fileclose(right); sf_fileclose(leftb); sf_fileclose(rightb); /* abc parameters */ if (!sf_getint("top", &top)) top=40; if (!sf_getint("bot", &bot)) bot=40; if (!sf_getint("lft", &lft)) lft=40; if (!sf_getint("rht", &rht)) rht=40; /* Width of abc layer */ nz = nzb - top - bot; nx = nxb - lft - rht; /*Geometry parameters*/ geopar geop; geop = creategeo(); /*source loaction parameters*/ if (!sf_getfloat("slx", &slx)) slx=-1.0; /*source location x */ if (!sf_getint("spx", &spx)) spx=-1; /*source location x (index)*/ if((slx<0 && spx <0) || (slx>=0 && spx >=0 )) sf_error("Need src location"); if (slx >= 0 ) spx = (int)((slx-ox)/dx+0.5); if (!sf_getfloat("slz", &slz)) slz=-1.0; /* source location z */ if (!sf_getint("spz", &spz)) spz=-1; /*source location z (index)*/ if((slz<0 && spz <0) || (slz>=0 && spz >=0 )) sf_error("Need src location"); if (slz >= 0 ) spz = (int)((slz-ox)/dz+0.5); if (!sf_getfloat("gdep", &gdep)) gdep=-1.0; /* recorder depth on grid*/ if (!sf_getint("gpz", &gpz)) gpz=0; /* recorder depth on index*/ if (!sf_getint("gpx", &gpx)) sf_error("Need receiver starting location"); /* recorder starting location on index*/ if (!sf_getint("gpl", &gpl)) sf_error("Need receiver length"); /* recorder length on index*/ if ( gdep>=oz) { gpz = (int)((gdep-oz)/dz+0.5);} if (gpz < 0.0) sf_error("gdep need to be >=oz"); /*source and receiver location*/ if (!sf_getint("snapinter", &snpint)) snpint=10; /* snap interval */ /*load source wavelet and reflectivity map*/ ww=sf_complexalloc(nt); sf_complexread(ww,nt,Fsrc); sf_fileclose(Fsrc); reflgen(nzb, nxb, spz+top, spx+lft, rectz, rectx, repeat, rr); /*check record data*/ if (adj && wantrecord){ sf_histint(Frcd,"n1", &tmpint); if (tmpint != nt ) sf_error("Error parameter n1 in record!"); sf_histint(Frcd,"n2", &tmpint); if (tmpint != gpl ) sf_error("Error parameter n2 in record!"); } geop->nx = nx; geop->nz = nz; geop->nxb = nxb; geop->nzb = nzb; geop->dx = dx; geop->dz = dz; geop->ox = ox; geop->oz = oz; geop->snpint = snpint; geop->spx = spx; geop->spz = spz; geop->gpz = gpz; geop->gpx = gpx; geop->gpl = gpl; geop->top = top; geop->bot = bot; geop->lft = lft; geop->rht = rht; geop->nt = nt; geop->dt = dt; geop->trunc = trunc; /* wavefield and record */ wfnt = (int)(nt-1)/snpint+1; wfdt = dt*snpint; record = sf_complexalloc2(nt, gpl); wavefld = sf_complexalloc3(nz, nx, wfnt); sill = sf_floatalloc2(nz, nx); if (wantwf) wavefld2= sf_complexalloc3(nz, nx, wfnt); else wavefld2=NULL; /*image*/ img = sf_complexalloc2(nz, nx); if (verb) { sf_warning("============================"); sf_warning("nx=%d nz=%d nt=%d", geop->nx, geop->nz, geop->nt); sf_warning("nxb=%d nzb=%d ", geop->nxb, geop->nzb); sf_warning("dx=%f dz=%f dt=%f", geop->dx, geop->dz, geop->dt); sf_warning("top=%d bot=%d lft=%d rht=%d", geop->top, geop->bot, geop->lft, geop->rht); sf_warning("rectz=%d rectx=%d repeat=%d srctrunc=%f",rectz,rectx,repeat,geop->trunc); sf_warning("spx=%d spz=%d gpz=%d gpx=%d gpl=%d snpint=%d", spx, spz, gpz, gpx, gpl, snpint); sf_warning("wfdt=%f wfnt=%d ", wfdt, wfnt); sf_warning("============================"); } /* write record */ sf_setn(ax, gpl); sf_setn(az, nz); if (adj) { /* migration */ if(!wantrecord) { sf_oaxa(Frcd, at, 1); sf_oaxa(Frcd, ax, 2); sf_settype(Frcd,SF_COMPLEX); } sf_setn(ax, nx); /*write image*/ sf_oaxa(Fimg, az, 1); sf_oaxa(Fimg, ax, 2); sf_settype(Fimg,SF_COMPLEX); } else { /* modeling */ sf_oaxa(Frcd, at, 1); sf_oaxa(Frcd, ax, 2); sf_settype(Frcd,SF_COMPLEX); } if (wantwf) { sf_setn(ax, nx); /*write temp wavefield */ sf_setn(at, wfnt); sf_setd(at, wfdt); sf_oaxa(Ftmpwf, az, 1); sf_oaxa(Ftmpwf, ax, 2); sf_oaxa(Ftmpwf, at, 3); sf_settype(Ftmpwf,SF_COMPLEX); /*write temp wavefield */ sf_oaxa(Ftmpbwf, az, 1); sf_oaxa(Ftmpbwf, ax, 2); sf_oaxa(Ftmpbwf, at, 3); sf_settype(Ftmpbwf,SF_COMPLEX); } if (!adj) sf_complexread(img[0],nx*nz,Fimg); lrosfor2(wavefld, sill, record, verb, lt, rt, m2, geop, ww, rr, pad1); if(adj && wantrecord) sf_complexread(record[0], gpl*nt, Frcd); lrosback2(img, wavefld, sill, record, adj, verb, wantwf, ltb, rtb, m2, geop, pad1, wavefld2); if (!wantrecord || !adj) { for (ix=0; ix<gpl; ix++) { sf_complexwrite(record[ix], nt, Frcd); } } if (adj) { for (ix=0; ix<nx; ix++) sf_complexwrite(img[ix], nz, Fimg); } if (wantwf) { for (it=0; it<wfnt; it++) for ( ix=0; ix<nx; ix++) { sf_complexwrite(wavefld[it][ix], nz, Ftmpwf); sf_complexwrite(wavefld2[it][ix],nz, Ftmpbwf); } } tend = clock(); duration=(double)(tend-tstart)/CLOCKS_PER_SEC; sf_warning(">> The CPU time of single shot migration is: %f seconds << ", duration); exit(0); }
int main(int argc,char **argv) { int isx,isy,isz,bd; int i,j,k,im,jm,it; int nth, rank; float t; float fx,fy,fz,dt2; float ***c11, ***c22, ***c33, ***c12, ***c13, ***c23, ***c44, ***c55, ***c66; float ***phaix, ***phaiy, ***phaiz; sf_init(argc,argv); sf_file Fo1, Fo2, Fo3; float f0=40; // main frequency of the wavelet(usually 30Hz) float t0=0.04; // time delay of the wavelet(if f0=30Hz, t0=0.04s)*/ float A=1.0; // the amplitude of wavelet clock_t t1, t2, t3; float timespent; t1=clock(); /* time samping paramter */ if (!sf_getint("nt",&nt)) nt=301; if (!sf_getfloat("dt",&dt)) dt=0.001; if (!sf_getint("bd",&bd)) bd=20; sf_warning("nt=%d dt=%f",nt,dt); /* setup I/O files */ sf_file Fc11, Fc22, Fc33, Fc12, Fc13, Fc23, Fc44, Fc55, Fc66; sf_file Fphiz, Fphiy, Fphix; Fc11 = sf_input ("c11"); /* c11 using standard input */ Fc22 = sf_input ("c22"); /* c22 */ Fc33 = sf_input ("c33"); /* c33 */ Fc12 = sf_input ("c12"); /* c12 */ Fc13 = sf_input ("c13"); /* c13 */ Fc23 = sf_input ("c23"); /* c23 */ Fc44 = sf_input ("c44"); /* c44 */ Fc55 = sf_input ("c55"); /* c55 */ Fc66 = sf_input ("c66"); /* c66 */ Fphix = sf_input ("phix"); /* phix x ccw*/ Fphiy = sf_input ("phiy"); /* phiy y ccw*/ Fphiz = sf_input ("phiz"); /* phiz z ccw */ /* Read/Write axes */ sf_axis az, ax, ay; az = sf_iaxa(Fc11,1); nz = sf_n(az); dz = sf_d(az)*1000.0; ax = sf_iaxa(Fc11,2); nx = sf_n(ax); dx = sf_d(ax)*1000.0; ay = sf_iaxa(Fc11,3); ny = sf_n(ay); dy = sf_d(ay)*1000.0; fy=sf_o(ay)*1000.0; fx=sf_o(ax)*1000.0; fz=sf_o(az)*1000.0; int nxpad, nypad, nzpad; nxpad=nx+2*bd; nypad=ny+2*bd; nzpad=nz+2*bd; sf_warning("nxpad=%d nypad=%d nzpad=%d ",nxpad,nypad,nzpad); sf_warning("dx=%f dy=%f dz=%f ",dx,dy,dz); c11=sf_floatalloc3(nzpad,nxpad,nypad); c22=sf_floatalloc3(nzpad,nxpad,nypad); c33=sf_floatalloc3(nzpad,nxpad,nypad); c12=sf_floatalloc3(nzpad,nxpad,nypad); c13=sf_floatalloc3(nzpad,nxpad,nypad); c23=sf_floatalloc3(nzpad,nxpad,nypad); c44=sf_floatalloc3(nzpad,nxpad,nypad); c55=sf_floatalloc3(nzpad,nxpad,nypad); c66=sf_floatalloc3(nzpad,nxpad,nypad); phaix=sf_floatalloc3(nzpad,nxpad,nypad); phaiy=sf_floatalloc3(nzpad,nxpad,nypad); phaiz=sf_floatalloc3(nzpad,nxpad,nypad); /* read velocity model */ for(i=bd;i<nypad-bd;i++) for(j=bd;j<nxpad-bd;j++){ sf_floatread(&c11[i][j][bd],nz,Fc11); sf_floatread(&c22[i][j][bd],nz,Fc22); sf_floatread(&c33[i][j][bd],nz,Fc33); sf_floatread(&c12[i][j][bd],nz,Fc12); sf_floatread(&c13[i][j][bd],nz,Fc13); sf_floatread(&c23[i][j][bd],nz,Fc23); sf_floatread(&c44[i][j][bd],nz,Fc44); sf_floatread(&c55[i][j][bd],nz,Fc55); sf_floatread(&c66[i][j][bd],nz,Fc66); sf_floatread(&phaix[i][j][bd],nz,Fphix); sf_floatread(&phaiy[i][j][bd],nz,Fphiy); sf_floatread(&phaiz[i][j][bd],nz,Fphiz); } vmodelboundary3d(c11, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c22, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c33, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c12, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c13, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c23, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c44, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c55, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c66, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(phaix, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(phaiy, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(phaiz, nx, ny, nz, nxpad, nypad, nzpad, bd); for(i=0;i<nypad;i++) for(j=0;j<nxpad;j++) for(k=0;k<nzpad;k++){ phaix[i][j][k] *= SF_PI/180.0; phaiy[i][j][k] *= SF_PI/180.0; phaiz[i][j][k] *= SF_PI/180.0; } sf_warning("Read velocity model parameters ok !"); int mm=2*_m+1; int mmix=2*_mix+1; sf_warning("m=%d mix=%d",_m,_mix); float *coeff_2dx,*coeff_2dy,*coeff_2dz,*coeff_1dx,*coeff_1dy,*coeff_1dz; coeff_2dy=sf_floatalloc(mm); coeff_2dx=sf_floatalloc(mm); coeff_2dz=sf_floatalloc(mm); coeff_1dy=sf_floatalloc(mmix); coeff_1dx=sf_floatalloc(mmix); coeff_1dz=sf_floatalloc(mmix); coeff2d(coeff_2dx,dx); coeff2d(coeff_2dy,dy); coeff2d(coeff_2dz,dz); coeff1dmix(coeff_1dx, dx); coeff1dmix(coeff_1dy, dy); coeff1dmix(coeff_1dz, dz); float*** p1=sf_floatalloc3(nzpad,nxpad,nypad); float*** p2=sf_floatalloc3(nzpad,nxpad,nypad); float*** p3=sf_floatalloc3(nzpad,nxpad,nypad); zero3float(p1,nzpad,nxpad,nypad); zero3float(p2,nzpad,nxpad,nypad); zero3float(p3,nzpad,nxpad,nypad); float*** q1=sf_floatalloc3(nzpad,nxpad,nypad); float*** q2=sf_floatalloc3(nzpad,nxpad,nypad); float*** q3=sf_floatalloc3(nzpad,nxpad,nypad); zero3float(q1,nzpad,nxpad,nypad); zero3float(q2,nzpad,nxpad,nypad); zero3float(q3,nzpad,nxpad,nypad); float*** r1=sf_floatalloc3(nzpad,nxpad,nypad); float*** r2=sf_floatalloc3(nzpad,nxpad,nypad); float*** r3=sf_floatalloc3(nzpad,nxpad,nypad); zero3float(r1,nzpad,nxpad,nypad); zero3float(r2,nzpad,nxpad,nypad); zero3float(r3,nzpad,nxpad,nypad); t2=clock(); /* setup I/O files */ Fo1 = sf_output("out"); /* original elasticwave iLine x-component */ Fo2 = sf_output("Elasticy"); /* original elasticwave iLine y-component */ Fo3 = sf_output("Elasticz"); /* original elasticwave xLine z-component */ puthead3x(Fo1, nz, nx, ny, dz/1000.0, dx/1000.0, dy/1000.0, 0.0, 0.0, 0.0); puthead3x(Fo2, nz, nx, ny, dz/1000.0, dx/1000.0, dy/1000.0, 0.0, 0.0, 0.0); puthead3x(Fo3, nz, nx, ny, dz/1000.0, dx/1000.0, dy/1000.0, 0.0, 0.0, 0.0); /* source definition */ isy=nypad/2; isx=nxpad/2; isz=nzpad/2; dt2=dt*dt; #ifdef _OPENMP #pragma omp parallel { nth = omp_get_num_threads(); rank = omp_get_thread_num(); sf_warning("Using %d threads, this is %dth thread",nth, rank); } #endif float*** px_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** pz_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** qx_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** qz_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** rx_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** rz_tmp=sf_floatalloc3(nzpad,nxpad,nypad); /*********the kernel calculation ************/ for(it=0;it<nt;it++) { t=it*dt; /* source Type 0: oriented 45 degree to vertical and 45 degree azimuth: Yan & Sava (2012) */ p2[isy][isx][isz]+=Ricker(t, f0, t0, A); // x-component q2[isy][isx][isz]+=Ricker(t, f0, t0, A); // y-component r2[isy][isx][isz]+=Ricker(t, f0, t0, A); // z-component // 3D exploding force source (e.g., Wu's PhD /* for(k=-1;k<=1;k++)*/ /* for(i=-1;i<=1;i++)*/ /* for(j=-1;j<=1;j++)*/ /* {*/ /* if(fabs(i)+fabs(j)+fabs(k)==3)*/ /* {*/ /* p2[isy+k][isx+i][isz+j]+=i*Ricker(t, f0, t0, A); // x-component*/ /* q2[isy+k][isx+i][isz+j]+=k*Ricker(t, f0, t0, A); // y-component*/ /* r2[isy+k][isx+i][isz+j]+=j*Ricker(t, f0, t0, A); // z-component*/ /* }*/ /* }*/ fwportelastic3d(dt2,p1,p2,p3,q1,q2,q3,r1,r2,r3, px_tmp,pz_tmp, qx_tmp,qz_tmp, rx_tmp,rz_tmp, coeff_2dx,coeff_2dy,coeff_2dz, coeff_1dx,coeff_1dy,coeff_1dz, dx,dy,dz,nxpad,nypad,nzpad, c11,c22,c33,c12,c13,c23,c44,c55,c66,phaix,phaiy,phaiz); if(it==nt-1) // output snapshot { // output iLine for(i=0;i<ny;i++) { im=i+bd; for(j=0;j<nx;j++) { jm=j+bd; sf_floatwrite(&p3[im][jm][bd],nz,Fo1); sf_floatwrite(&q3[im][jm][bd],nz,Fo2); sf_floatwrite(&r3[im][jm][bd],nz,Fo3); } } } for(i=0;i<nypad;i++) for(j=0;j<nxpad;j++) for(k=0;k<nzpad;k++) { p1[i][j][k]=p2[i][j][k]; p2[i][j][k]=p3[i][j][k]; q1[i][j][k]=q2[i][j][k]; q2[i][j][k]=q3[i][j][k]; r1[i][j][k]=r2[i][j][k]; r2[i][j][k]=r3[i][j][k]; } sf_warning("forward propagation... it= %d t=%f",it,t); } printf("ok3\n"); t3=clock(); timespent=(float)(t3-t2)/CLOCKS_PER_SEC; sf_warning("CPU time for 3D ORT elastic modeling: %f(second)",timespent); free(**p1); free(**p2); free(**p3); free(**q1); free(**q2); free(**q3); free(**r1); free(**r2); free(**r3); free(**px_tmp); free(**qx_tmp); free(**rx_tmp); free(**pz_tmp); free(**qz_tmp); free(**rz_tmp); free(**c11); free(**c33); free(**c13); free(**c55); free(**c66); free(**phaiz); free(**phaiy); free(**phaix); return 0; }
int main(int argc, char *argv[]) { clock_t tstart, tend; double duration; int numprocs, rank; float *sendbuf, *recvbuf; MPI_Comm Comm=MPI_COMM_WORLD; bool verb, wantrecord, wantwf, onlyrecord; sf_file Ffvel, Ffden, Fbvel, Fbden; sf_file Fsrc, Frcd, Fimg1, Fimg2; sf_file FGx, FGz, Fsxx, Fsxz, Fszx, Fszz; sf_file Ftmpfwf, Ftmpbwf; sf_axis at, ax, az, atau; int shtbgn, shtinv, shtnmb, shtpad, shtnmb0; int snapturn, tmpint; float **fvel, **bvel; float ***fwf, ***record, **localrec; float ***img1, **img2, ***mig1, **mig2; float *tmpsxx, *tmpsxz, *tmpszx, *tmpszz; sf_init(argc, argv); MPI_Init(&argc, &argv); MPI_Comm_size(Comm, &numprocs); MPI_Comm_rank(Comm, &rank); tstart=clock(); if(rank==0) sf_warning("numprocs=%d", numprocs); if(!sf_getbool("verb", &verb)) verb=true; if(!sf_getbool("wantrecord", &wantrecord)) wantrecord=false; if(!sf_getbool("wantwf", &wantwf)) wantwf=false; if(!sf_getbool("onlyrecord", &onlyrecord)) onlyrecord=false; Fsrc=sf_input("-input"); Fimg1=sf_output("-output"); Fimg2=sf_output("img2"); Ffvel=sf_input("fvel"); Ffden=sf_input("fden"); Fbvel=sf_input("bvel"); Fbden=sf_input("bden"); if(wantrecord) Frcd=sf_input("record"); else Frcd=sf_output("record"); if(wantwf){ Ftmpfwf=sf_output("tmpfwf"); Ftmpbwf=sf_output("tmpbwf"); } FGx=sf_input("Gx"); FGz=sf_input("Gz"); Fsxx=sf_input("sxx"); Fsxz=sf_input("sxz"); Fszx=sf_input("szx"); Fszz=sf_input("szz"); at=sf_iaxa(Fsrc, 1); nt=sf_n(at); dt=sf_d(at); if(!sf_getbool("srcdecay", &srcdecay)) srcdecay=true; if(!sf_getint("srcrange", &srcrange)) srcrange=3; if(!sf_getfloat("srctrunc", &srctrunc)) srctrunc=0.2; if(!sf_getfloat("srcalpha", &srcalpha)) srcalpha=0.5; wavelet=sf_floatalloc(nt); sf_floatread(wavelet, nt, Fsrc); if(!sf_getint("pmlsize", &pmlsize)) pmlsize=30; if(!sf_getint("nfd", &nfd)) sf_error("Need half of the FD order!"); if(!sf_getfloat("pmld0", &pmld0)) pmld0=200; if(!sf_getint("shtnmb", &shtnmb)) sf_error("Need shot number!"); if(!sf_getint("shtinv", &shtinv)) sf_error("Need shot interval!"); if(!sf_getint("shtbgn", &shtbgn)) shtbgn=0; shtpad=numprocs-shtnmb%numprocs; shtnmb0=shtnmb+shtpad; az=sf_iaxa(Ffvel, 1); nzb=sf_n(az); ax=sf_iaxa(Ffvel, 2); nxb=sf_n(ax); nxzb=nxb*nzb; nz=nzb-2*nfd-2*pmlsize; nx=nxb-2*nfd-2*pmlsize; if(!sf_getint("snapturn", &snapturn)) snapturn=1; if(!sf_getint("ginv", &ginv)) ginv=1; if(!sf_getint("wfinv", &wfinv)) wfinv=1; if(!sf_getint("spz", &spz)) spz=6; if(!sf_getint("gp", &gp)) gp=0; ng=(nx-1)/ginv+1; wfnt=(nt-1)/wfinv+1; wfdt=dt*wfinv; if(!sf_getint("ntau", &ntau)) ntau=1; if(!sf_getfloat("dtau", &dtau)) dtau=wfdt; if(!sf_getfloat("tau0", &tau0)) tau0=0; atau=sf_iaxa(Fsrc, 1); sf_setn(atau, ntau); sf_setd(atau, dtau); sf_seto(atau, tau0); if(!sf_histint(FGx, "n1", &nxz)) sf_error("No n1= in FGx!"); if(nxz != nxzb) sf_error("Dimension error!"); if(!sf_histint(FGx, "n2", &lenx)) sf_error("No n2= in FGx!"); if(!sf_histint(FGz, "n2", &lenz)) sf_error("No n2= in FGz!"); Gx=sf_floatalloc3(nzb, nxb, lenx); Gz=sf_floatalloc3(nzb, nxb, lenz); sxx=sf_intalloc(lenx); sxz=sf_intalloc(lenx); szx=sf_intalloc(lenz); szz=sf_intalloc(lenz); tmpsxx=sf_floatalloc(lenx); tmpsxz=sf_floatalloc(lenx); tmpszx=sf_floatalloc(lenz); tmpszz=sf_floatalloc(lenz); sf_floatread(Gx[0][0], nxzb*lenx, FGx); sf_floatread(Gz[0][0], nxzb*lenz, FGz); sf_floatread(tmpsxx, lenx, Fsxx); sf_floatread(tmpsxz, lenx, Fsxz); sf_floatread(tmpszx, lenz, Fszx); sf_floatread(tmpszz, lenz, Fszz); for (ix=0; ix<lenx; ix++){ sxx[ix]=(int)tmpsxx[ix]; sxz[ix]=(int)tmpsxz[ix]; } for (iz=0; iz<lenz; iz++){ szx[iz]=(int)tmpszx[iz]; szz[iz]=(int)tmpszz[iz]; } fvel=sf_floatalloc2(nzb, nxb); fden=sf_floatalloc2(nzb, nxb); fc11=sf_floatalloc2(nzb, nxb); bvel=sf_floatalloc2(nzb, nxb); bden=sf_floatalloc2(nzb, nxb); bc11=sf_floatalloc2(nzb, nxb); sf_floatread(fvel[0], nxzb, Ffvel); sf_floatread(fden[0], nxzb, Ffden); sf_floatread(bvel[0], nxzb, Fbvel); sf_floatread(bden[0], nxzb, Fbden); for (ix=0; ix<nxb; ix++){ for (iz=0; iz<nzb; iz++){ fc11[ix][iz]=fden[ix][iz]*fvel[ix][iz]*fvel[ix][iz]; bc11[ix][iz]=bden[ix][iz]*bvel[ix][iz]*bvel[ix][iz]; } } if(wantrecord){ /* check record data */ sf_histint(Frcd, "n1", &tmpint); if(tmpint != nt) sf_error("Not matched dimensions!"); sf_histint(Frcd, "n2", &tmpint); if(tmpint != ng) sf_error("Not matched dimensions!"); sf_histint(Frcd, "n3", &tmpint); if(tmpint != shtnmb) sf_error("Not matched dimensions!"); } if(rank==0){ record=sf_floatalloc3(nt, ng, shtnmb0); if(wantrecord){ sf_floatread(record[0][0], nt*ng*shtnmb, Frcd); for(is=shtnmb; is<shtnmb0; is++) for(ix=0; ix<ng; ix++) for(it=0; it<nt; it++) record[is][ix][it]=0.0; } } img1=sf_floatalloc3(nz, nx, ntau); mig1=sf_floatalloc3(nz, nx, ntau); img2=sf_floatalloc2(nz, nx); mig2=sf_floatalloc2(nz, nx); zero3(img1, nz, nx, ntau); zero2(img2, nz, nx); sf_setn(az, nz); sf_setn(ax, ng); if(!wantrecord){ sf_oaxa(Frcd, at, 1); sf_oaxa(Frcd, ax, 2); sf_putint(Frcd, "n3", shtnmb); sf_putint(Frcd, "d3", shtinv); sf_putint(Frcd, "o3", shtbgn); } sf_setn(ax, nx); if(wantwf){ sf_setn(at, wfnt); sf_setd(at, wfdt); sf_oaxa(Ftmpfwf, az, 1); sf_oaxa(Ftmpfwf, ax, 2); sf_oaxa(Ftmpfwf, at, 3); sf_oaxa(Ftmpbwf, az, 1); sf_oaxa(Ftmpbwf, ax, 2); sf_oaxa(Ftmpbwf, at, 3); } sf_oaxa(Fimg1, az, 1); sf_oaxa(Fimg1, ax, 2); sf_oaxa(Fimg1, atau, 3); sf_oaxa(Fimg2, az, 1); sf_oaxa(Fimg2, ax, 2); fwf=sf_floatalloc3(nz, nx, wfnt); localrec=sf_floatalloc2(nt, ng); if(verb){ sf_warning("=================================="); sf_warning("nx=%d nz=%d nt=%d", nx, nz, nt); sf_warning("wfnt=%d wfdt=%f wfinv=%d dt=%f", wfnt, wfdt, wfinv, dt); sf_warning("nxb=%d nzb=%d pmlsize=%d nfd=%d", nxb, nzb, pmlsize, nfd); sf_warning("ntau=%d dtau=%f tau0=%f", ntau, dtau, tau0); sf_warning("shtnmb=%d shtbgn=%d shtinv=%d", shtnmb, shtbgn, shtinv); sf_warning("lenx=%d lenz=%d spz=%d gp=%d", lenx, lenz, spz, gp); sf_warning("=================================="); } init(); for(iturn=0; iturn*numprocs<shtnmb; iturn++){ is=iturn*numprocs+rank; if(is<shtnmb){ sf_warning("ishot/nshot: %d/%d", is+1, shtnmb); spx=is*shtinv+shtbgn; sglfdfor2(fwf, localrec, verb); } if(wantrecord){ recvbuf=localrec[0]; if(rank==0) sendbuf=record[iturn*numprocs][0]; else sendbuf=NULL; MPI_Scatter(sendbuf, ng*nt, MPI_FLOAT, recvbuf, ng*nt, MPI_FLOAT, 0, Comm); }else{ sendbuf=localrec[0]; if(rank==0) recvbuf=record[iturn*numprocs][0]; else recvbuf=NULL; MPI_Gather(sendbuf, ng*nt, MPI_FLOAT, recvbuf, ng*nt, MPI_FLOAT, 0, Comm); } if(wantwf && rank==0 && iturn==snapturn-1) wantwf=true; else wantwf=false; if(wantwf) sf_floatwrite(fwf[0][0], wfnt*nx*nz, Ftmpfwf); if(!onlyrecord && is<shtnmb){ sglfdback2(mig1, mig2, fwf, localrec, verb, wantwf, Ftmpbwf); for(itau=0; itau<ntau; itau++){ for(ix=0; ix<nx; ix++){ for(iz=0; iz<nz; iz++){ img1[itau][ix][iz]+=mig1[itau][ix][iz]; } } } for(ix=0; ix<nx; ix++){ for(iz=0; iz<nz; iz++){ img2[ix][iz]+=mig2[ix][iz]; } } } MPI_Barrier(Comm); } //end of iturn if(!onlyrecord){ if(rank==0){ sendbuf=(float *)MPI_IN_PLACE; recvbuf=img1[0][0]; }else{ sendbuf=img1[0][0]; recvbuf=NULL; } MPI_Reduce(sendbuf, recvbuf, ntau*nx*nz, MPI_FLOAT, MPI_SUM, 0, Comm); if(rank==0){ sendbuf=MPI_IN_PLACE; recvbuf=img2[0]; }else{ sendbuf=img2[0]; recvbuf=NULL; } MPI_Reduce(sendbuf, recvbuf, nx*nz, MPI_FLOAT, MPI_SUM, 0, Comm); } if(rank==0){ if(!wantrecord){ sf_floatwrite(record[0][0], shtnmb*ng*nt, Frcd); } sf_floatwrite(img1[0][0], ntau*nx*nz, Fimg1); sf_floatwrite(img2[0], nx*nz, Fimg2); } tend=clock(); duration=(double)(tend-tstart)/CLOCKS_PER_SEC; sf_warning(">>The CPU time of sfmpilfdrtm2 is: %f seconds<<", duration); MPI_Finalize(); exit(0); }