/*------------------------------------------------------------*/ fdm2d fdutil_init(bool verb_, bool free_, sf_axis az_, sf_axis ax_, int nb_, int ompchunk_) /*< init fdm utilities >*/ { fdm2d fdm; fdm = (fdm2d) sf_alloc(1,sizeof(*fdm)); fdm->free=free_; fdm->verb=verb_; fdm->nb=nb_; fdm->nz=sf_n(az_); fdm->nx=sf_n(ax_); fdm->dz=sf_d(az_); fdm->dx=sf_d(ax_); fdm->oz=sf_o(az_); fdm->ox=sf_o(ax_); fdm->nzpad=sf_n(az_)+2*fdm->nb; fdm->nxpad=sf_n(ax_)+2*fdm->nb; fdm->ozpad=sf_o(az_)-fdm->nb*fdm->dz; fdm->oxpad=sf_o(ax_)-fdm->nb*fdm->dx; fdm->ompchunk=ompchunk_; return fdm; }
/*------------------------------------------------------------*/ void applyGaussian(float *****img, sf_axis ac, sf_axis aht,sf_axis ahx,sf_axis ahy,sf_axis ahz, float gst,float gsx,float gsy,float gsz) { int ic,iht,ihx,ihy,ihz; float gt, gx, gy, gz; int nht,nhx,nhy,nhz; nht=(sf_n(aht)-1)/2; nhx=(sf_n(ahx)-1)/2; nhy=(sf_n(ahy)-1)/2; nhz=(sf_n(ahz)-1)/2; for(ic=0;ic<sf_n(ac);ic++) { for (iht=0;iht<sf_n(aht);iht++){gt=(iht-nht)*sf_d(aht); gt*=gt; for (ihy=0;ihy<sf_n(ahy);ihy++){gy=(ihy-nhy)*sf_d(ahy); gy*=gy; for (ihx=0;ihx<sf_n(ahx);ihx++){gx=(ihx-nhx)*sf_d(ahx); gx*=gx; for(ihz=0;ihz<sf_n(ahz);ihz++){gz=(ihz-nhz)*sf_d(ahz); gz*=gz; img[ic][iht][ihy][ihx][ihz]*=exp(-gt*gst-gx*gsx-gy*gsy-gz*gsz); } } } } } }
/*------------------------------------------------------------*/ fdm2d fdutil_init(bool verb_, bool free_, sf_axis a1_, sf_axis a2_, int nb_, int ompchunk_) /*< init fdm utilities >*/ { fdm2d fdm; fdm = (fdm2d) sf_alloc(1,sizeof(*fdm)); fdm->free=free_; fdm->verb=verb_; fdm->nb=nb_; fdm->n1=sf_n(a1_); fdm->n2=sf_n(a2_); fdm->d1=sf_d(a1_); fdm->d2=sf_d(a2_); fdm->o1=sf_o(a1_); fdm->o2=sf_o(a2_); fdm->n1pad=sf_n(a1_)+2*fdm->nb; fdm->n2pad=sf_n(a2_)+2*fdm->nb; fdm->o1pad=sf_o(a1_)-fdm->nb*fdm->d1; fdm->o2pad=sf_o(a2_)-fdm->nb*fdm->d2; fdm->ompchunk=ompchunk_; return fdm; }
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; }
void wavmod_init(HVel pvel, float dt, int nt0, int st0, int jt0, int jtm0, int *pg0, int ng0, bool vb) /*< initialize >*/ { int i1, n1, n2, n3; double dt2; float d1, d2, d3; vel = pvel; verb = vb; nt = nt0; st = st0; jt = jt0; jtm= jtm0; pg = pg0; ng = ng0; n1 = sf_n(vel->z); n2=1; n3=1; d1 = sf_d(vel->z); d2=0.0; d3=0.0; if(vel->nd >= 2) { n2 = sf_n(vel->x); d2 = sf_d(vel->x); } if(vel->nd >= 3) { n3 = sf_n(vel->y); d3 = sf_d(vel->y); } nxyz = n1*n2*n3; owv = sf_floatalloc(nxyz); wav = sf_floatalloc(nxyz); nwv = sf_floatalloc(nxyz); ud = sf_floatalloc(nxyz); ntj = (nt-st+1)/jt; data = sf_floatalloc2(ntj, ng); fd3_init(d1, d2, d3); dt2 = dt*dt; for(i1=0; i1<nxyz; i1++) vel->p[i1] = dt2*vel->p[i1]*vel->p[i1]; }
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[]) { 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) { 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[]) { 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); }
/* 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[]) { 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[]) { 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[]) { /*------------------------------------------------------------*/ /* Execution control, I/O files and geometry */ /*------------------------------------------------------------*/ bool verb,fsrf,snap,back,esou; /* execution flags */ int jsnap,ntsnap,jdata; /* jump along axes */ int shft; /* time shift for wavefield matching in RTM */ /* I/O files */ sf_file Fwav=NULL; /* wavelet */ sf_file Fdat=NULL; /* data */ sf_file Fsou=NULL; /* sources */ sf_file Frec=NULL; /* receivers */ sf_file Fccc=NULL; /* velocity */ sf_file Frkp=NULL; /* app. rank */ sf_file Fltp=NULL; /* left mat */ sf_file Frtp=NULL; /* right mat */ sf_file Fwfp=NULL; /* wavefield */ sf_file Frks=NULL; /* app. rank */ sf_file Flts=NULL; /* left mat */ sf_file Frts=NULL; /* right mat */ sf_file Fwfs=NULL; /* wavefield */ /* cube axes */ sf_axis at,ax,ay,az; /* time, x, y, z */ sf_axis asx,asy,arx,ary,ac; /* sou, rec-x, rec-y, component */ /* dimension, index and interval */ int nt,nz,nx,ny,ns,nr,nc,nb; int it,iz,ix,iy; float dt,dz,dx,dy; int nxyz, nk; /* FDM and KSP structure */ //!!!JS fdm3d fdm=NULL; dft3d dft=NULL; clr3d clr_p=NULL, clr_s=NULL; /* I/O arrays for sou & rec */ sf_complex***ww=NULL; /* wavelet */ pt3d *ss=NULL; /* sources */ pt3d *rr=NULL; /* receivers */ sf_complex **dd=NULL; /* data */ /*------------------------------------------------------------*/ /* displacement: uo = U @ t; up = U @ t+1 */ /*------------------------------------------------------------*/ sf_complex ***uox, ***uoy, ***uoz, **uo; sf_complex ***uox_p, ***uoy_p, ***uoz_p, **uo_p; sf_complex ***uox_s, ***uoy_s, ***uoz_s, **uo_s; /*sf_complex ***upx, ***upy, ***upz, **up;*/ /*------------------------------------------------------------*/ /* lowrank decomposition arrays */ /*------------------------------------------------------------*/ int ntmp, *n2s_p, *n2s_s; sf_complex **lt_p, **rt_p, **lt_s, **rt_s; /*------------------------------------------------------------*/ /* linear interpolation weights/indices */ /*------------------------------------------------------------*/ lint3d cs,cr; /* for injecting source and extracting data */ /* Gaussian bell */ int nbell; /*------------------------------------------------------------*/ /* wavefield cut params */ /*------------------------------------------------------------*/ sf_axis acz=NULL,acx=NULL,acy=NULL; int nqz,nqx,nqy; float oqz,oqx,oqy; float dqz,dqx,dqy; sf_complex***uc=NULL; /* tmp array for output wavefield snaps */ /*------------------------------------------------------------*/ /* init RSF */ /*------------------------------------------------------------*/ sf_init(argc,argv); /*------------------------------------------------------------*/ /* OMP parameters */ /*------------------------------------------------------------*/ #ifdef _OPENMP omp_init(); #endif /*------------------------------------------------------------*/ /* read execution flags */ /*------------------------------------------------------------*/ 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("back",&back)) back=false; /* backward extrapolation flag (for rtm) */ if(! sf_getbool("esou",&esou)) esou=false; /* explosive force source */ /*------------------------------------------------------------*/ /* I/O files */ /*------------------------------------------------------------*/ Fwav = sf_input ("in" ); /* wavelet */ Fdat = sf_output("out"); /* data */ Fsou = sf_input ("sou"); /* sources */ Frec = sf_input ("rec"); /* receivers */ Fccc = sf_input ("ccc"); /* stiffness */ Frkp = sf_input ("rkp"); /* app. rank */ Fltp = sf_input ("ltp"); /* left mat */ Frtp = sf_input ("rtp"); /* right mat */ Fwfp = sf_output("wfp"); /* wavefield */ Frks = sf_input ("rks"); /* app. rank */ Flts = sf_input ("lts"); /* left mat */ Frts = sf_input ("rts"); /* right mat */ Fwfs = sf_output("wfs"); /* wavefield */ /*------------------------------------------------------------*/ /* axes */ /*------------------------------------------------------------*/ at = sf_iaxa(Fwav,4); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ az = sf_iaxa(Fccc,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */ ax = sf_iaxa(Fccc,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* space x */ ay = sf_iaxa(Fccc,3); sf_setlabel(ay,"y"); if(verb) sf_raxa(ay); /* space y */ asx = sf_iaxa(Fsou,2); sf_setlabel(asx,"sx"); if(verb) sf_raxa(asx); /* sources x */ asy = sf_iaxa(Fsou,3); sf_setlabel(asy,"sy"); if(verb) sf_raxa(asy); /* sources y */ arx = sf_iaxa(Frec,2); sf_setlabel(arx,"rx"); if(verb) sf_raxa(arx); /* receivers x */ ary = sf_iaxa(Frec,3); sf_setlabel(ary,"ry"); if(verb) sf_raxa(ary); /* receivers y */ 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(asx)*sf_n(asy); nr = sf_n(arx)*sf_n(ary); /*------------------------------------------------------------*/ /* other execution parameters */ /*------------------------------------------------------------*/ if(! sf_getint("nbell",&nbell)) nbell=NOP; /* bell size */ if(verb) sf_warning("nbell=%d",nbell); if(! sf_getint("jdata",&jdata)) jdata=1; if(snap) { /* save wavefield every *jsnap* time steps */ if(! sf_getint("jsnap",&jsnap)) jsnap=nt; } if(back) { shft = (nt-1)%jsnap; sf_warning("For backward extrapolation, make sure nbell(%d)=0",nbell); } else shft = 0; /*------------------------------------------------------------*/ /* expand domain for FD operators and ABC */ /*------------------------------------------------------------*/ if( !sf_getint("nb",&nb)) nb=NOP; fdm=fdutil3d_init(verb,fsrf,az,ax,ay,nb,1); if(nbell) fdbell3d_init(nbell); 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); /*------------------------------------------------------------*/ /* 3D vector components */ /*------------------------------------------------------------*/ nc=3; ac=sf_maxa(nc,0,1); /* output 3 cartesian components */ /*------------------------------------------------------------*/ /* setup output data header */ /*------------------------------------------------------------*/ sf_settype(Fdat,SF_COMPLEX); sf_oaxa(Fdat,arx,1); sf_oaxa(Fdat,ary,2); sf_oaxa(Fdat,ac,3); sf_setn(at,nt/jdata); sf_setd(at,dt*jdata); sf_oaxa(Fdat,at,4); /* setup output wavefield header */ if(snap) { if(!sf_getint ("nqz",&nqz)) nqz=sf_n(az); if(!sf_getint ("nqx",&nqx)) nqx=sf_n(ax); if(!sf_getint ("nqy",&nqy)) nqy=sf_n(ay); if(!sf_getfloat("oqz",&oqz)) oqz=sf_o(az); if(!sf_getfloat("oqx",&oqx)) oqx=sf_o(ax); if(!sf_getfloat("oqy",&oqy)) oqy=sf_o(ay); dqz=sf_d(az); dqx=sf_d(ax); dqy=sf_d(ay); acz = sf_maxa(nqz,oqz,dqz); sf_raxa(acz); acx = sf_maxa(nqx,oqx,dqx); sf_raxa(acx); acy = sf_maxa(nqy,oqy,dqy); sf_raxa(acy); uc=sf_complexalloc3(sf_n(acz),sf_n(acx),sf_n(acy)); ntsnap=0; /* ntsnap = it/jsnap+1; */ 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_settype(Fwfp,SF_COMPLEX); sf_oaxa(Fwfp,acz,1); sf_oaxa(Fwfp,acx,2); sf_oaxa(Fwfp,acy,3); sf_oaxa(Fwfp,ac, 4); sf_oaxa(Fwfp,at, 5); sf_settype(Fwfs,SF_COMPLEX); sf_oaxa(Fwfs,acz,1); sf_oaxa(Fwfs,acx,2); sf_oaxa(Fwfs,acy,3); sf_oaxa(Fwfs,ac, 4); sf_oaxa(Fwfs,at, 5); } /*------------------------------------------------------------*/ /* source and data array */ /*------------------------------------------------------------*/ ww=sf_complexalloc3(ns,nc,nt); /* Fast axis: n_sou > n_comp > n_time */ sf_complexread(ww[0][0],nt*nc*ns,Fwav); dd=sf_complexalloc2(nr,nc); /*------------------------------------------------------------*/ /* setup source/receiver coordinates */ /*------------------------------------------------------------*/ ss = (pt3d*) sf_alloc(ns,sizeof(*ss)); rr = (pt3d*) sf_alloc(nr,sizeof(*rr)); pt3dread1(Fsou,ss,ns,3); /* read (x,y,z) coordinates */ pt3dread1(Frec,rr,nr,3); /* read (x,y,z) coordinates */ /* calculate 3d linear interpolation coef for sou & rec */ cs = lint3d_make(ns,ss,fdm); cr = lint3d_make(nr,rr,fdm); /*------------------------------------------------------------*/ /* allocate and initialize wavefield arrays */ /*------------------------------------------------------------*/ /* z-component */ uoz=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uoz_p=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uoz_s=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); /*upz=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);*/ /* x-component */ uox=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uox_p=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uox_s=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); /*upx=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);*/ /* y-component */ uoy=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uoy_p=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uoy_s=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); /*upy=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);*/ /* wavefield vector */ uo = (sf_complex**) sf_alloc(3,sizeof(sf_complex*)); uo[0] = uox[0][0]; uo[1] = uoy[0][0]; uo[2] = uoz[0][0]; uo_p = (sf_complex**) sf_alloc(3,sizeof(sf_complex*)); uo_p[0] = uox_p[0][0]; uo_p[1] = uoy_p[0][0]; uo_p[2] = uoz_p[0][0]; uo_s = (sf_complex**) sf_alloc(3,sizeof(sf_complex*)); uo_s[0] = uox_s[0][0]; uo_s[1] = uoy_s[0][0]; uo_s[2] = uoz_s[0][0]; /*up = (sf_complex**) sf_alloc(3,sizeof(sf_complex*));*/ /*up[0] = upx[0][0]; up[1] = upy[0][0]; up[2] = upz[0][0];*/ /* initialize fft and lrk */ dft = dft3d_init(1,false,false,fdm); nxyz= fdm->nypad*fdm->nxpad*fdm->nzpad; nk = dft->nky *dft->nkx *dft->nkz; /*------------------------------------------------------------*/ /* allocation I/O arrays */ /*------------------------------------------------------------*/ n2s_p = sf_intalloc(9); sf_intread(n2s_p,9,Frkp); clr_p = clr3d_make2(n2s_p,fdm); n2s_s = sf_intalloc(9); sf_intread(n2s_s,9,Frks); clr_s = clr3d_make2(n2s_s,fdm); if (clr_p->n2_max > clr_s->n2_max) clr3d_init(fdm,dft,clr_p); else clr3d_init(fdm,dft,clr_s); /* check the dimension */ if (!sf_histint(Fltp,"n1",&ntmp) || ntmp != nxyz) sf_error("Need n1=%d in left",nxyz); if (!sf_histint(Fltp,"n2",&ntmp) || ntmp != clr_p->n2_sum) sf_error("Need n2=%d in left",clr_p->n2_sum); if (!sf_histint(Frtp,"n1",&ntmp) || ntmp != nk) sf_error("Need n1=%d in right",nk); if (!sf_histint(Frtp,"n2",&ntmp) || ntmp != clr_p->n2_sum) sf_error("Need n2=%d in right",clr_p->n2_sum); lt_p = sf_complexalloc2(nxyz,clr_p->n2_sum); rt_p = sf_complexalloc2(nk ,clr_p->n2_sum); sf_complexread(lt_p[0],nxyz*clr_p->n2_sum,Fltp); sf_complexread(rt_p[0],nk *clr_p->n2_sum,Frtp); if (!sf_histint(Flts,"n1",&ntmp) || ntmp != nxyz) sf_error("Need n1=%d in left",nxyz); if (!sf_histint(Flts,"n2",&ntmp) || ntmp != clr_s->n2_sum) sf_error("Need n2=%d in left",clr_s->n2_sum); if (!sf_histint(Frts,"n1",&ntmp) || ntmp != nk) sf_error("Need n1=%d in right",nk); if (!sf_histint(Frts,"n2",&ntmp) || ntmp != clr_s->n2_sum) sf_error("Need n2=%d in right",clr_s->n2_sum); lt_s = sf_complexalloc2(nxyz,clr_s->n2_sum); rt_s = sf_complexalloc2(nk ,clr_s->n2_sum); sf_complexread(lt_s[0],nxyz*clr_s->n2_sum,Flts); sf_complexread(rt_s[0],nk *clr_s->n2_sum,Frts); /* initialize to zero */ #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,1) \ private(iy,ix,iz) \ shared(fdm,uoz,uox,uoy,uoz_p,uox_p,uoy_p,uoz_s,uox_s,uoy_s) #endif for (iy=0; iy<fdm->nypad; iy++) { for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { uoz [iy][ix][iz]=sf_cmplx(0.,0.); uox [iy][ix][iz]=sf_cmplx(0.,0.); uoy [iy][ix][iz]=sf_cmplx(0.,0.); uoz_p[iy][ix][iz]=sf_cmplx(0.,0.); uox_p[iy][ix][iz]=sf_cmplx(0.,0.); uoy_p[iy][ix][iz]=sf_cmplx(0.,0.); uoz_s[iy][ix][iz]=sf_cmplx(0.,0.); uox_s[iy][ix][iz]=sf_cmplx(0.,0.); uoy_s[iy][ix][iz]=sf_cmplx(0.,0.); /*upz[iy][ix][iz]=sf_cmplx(0.,0.); upx[iy][ix][iz]=sf_cmplx(0.,0.); upy[iy][ix][iz]=sf_cmplx(0.,0.);*/ } } } /*------------------------------------------------------------*/ /*------------------------ MAIN LOOP -------------------------*/ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) sf_warning("it=%d/%d;",it,nt); /*fprintf(stderr,"\b\b\b\b\b%d",it);*/ /*------------------------------------------------------------*/ /* apply lowrank matrix to wavefield vector */ /*------------------------------------------------------------*/ clr3d_apply(uo_p, uo, lt_p, rt_p, fdm, dft, clr_p); clr3d_apply(uo_s, uo, lt_s, rt_s, fdm, dft, clr_s); /*------------------------------------------------------------*/ /* combine P and S wave modes */ /*------------------------------------------------------------*/ #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,1) \ private(iy,ix,iz) \ shared(fdm,uoz,uox,uoy,uoz_p,uox_p,uoy_p,uoz_s,uox_s,uoy_s) #endif for (iy=0; iy<fdm->nypad; iy++) { for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { uoz[iy][ix][iz] = uoz_p[iy][ix][iz] + uoz_s[iy][ix][iz]; uox[iy][ix][iz] = uox_p[iy][ix][iz] + uox_s[iy][ix][iz]; uoy[iy][ix][iz] = uoy_p[iy][ix][iz] + uoy_s[iy][ix][iz]; /*upz[iy][ix][iz]=sf_cmplx(0.,0.); upx[iy][ix][iz]=sf_cmplx(0.,0.); upy[iy][ix][iz]=sf_cmplx(0.,0.);*/ } } } /*------------------------------------------------------------*/ /* free surface */ /*------------------------------------------------------------*/ if(fsrf) { /* need to do something here */ } /*------------------------------------------------------------*/ /* inject displacement source */ /*------------------------------------------------------------*/ if(esou) { /* exploding force source */ lint3d_expl_complex(uoz,uox,uoy,ww[it],cs); } else { if(nbell) { lint3d_bell_complex(uoz,ww[it][0],cs); lint3d_bell_complex(uox,ww[it][1],cs); lint3d_bell_complex(uoy,ww[it][2],cs); } else { lint3d_inject_complex(uoz,ww[it][0],cs); lint3d_inject_complex(uox,ww[it][1],cs); lint3d_inject_complex(uoy,ww[it][2],cs); } } /*------------------------------------------------------------*/ /* cut wavefield and save */ /*------------------------------------------------------------*/ if(snap && (it-shft)%jsnap==0) { /* P wave */ cut3d_complex(uoz_p,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfp); cut3d_complex(uox_p,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfp); cut3d_complex(uoy_p,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfp); /* S wave */ cut3d_complex(uoz_s,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfs); cut3d_complex(uox_s,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfs); cut3d_complex(uoy_s,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfs); } lint3d_extract_complex(uoz,dd[0],cr); lint3d_extract_complex(uox,dd[1],cr); lint3d_extract_complex(uoy,dd[2],cr); if(it%jdata==0) sf_complexwrite(dd[0],nr*nc,Fdat); } if(verb) sf_warning("."); if(verb) fprintf(stderr,"\n"); /*------------------------------------------------------------*/ /* deallocate arrays */ free(dft); dft3d_finalize(); free(clr_p); free(clr_s); clr3d_finalize(); free(**ww); free(*ww); free(ww); free(ss); free(rr); free(*dd); free(dd); free(n2s_p); free(n2s_s); free(*lt_p); free(lt_p); free(*rt_p); free(rt_p); free(*lt_s); free(lt_s); free(*rt_s); free(rt_s); free(**uoz ); free(*uoz ); free(uoz) ; free(**uoz_p); free(*uoz_p); free(uoz_p); free(**uoz_s); free(*uoz_s); free(uoz_s); /*free(**upz); free(*upz); free(upz);*/ free(uo); free(uo_p); free(uo_s); /*free(up);*/ if (snap) { free(**uc); free(*uc); free(uc); } /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char* argv[]) { bool verb; sf_axis az,ah,ahx,ahy,ahz; int iz, ihx,ihy,ihz; int nz, nhx,nhy,nhz; float hx, hy, hz; float oh,dh,ohx,dhx,ohy,dhy,ohz,dhz; sf_bands spl; sf_file Fd; /* data = vector offset (hx,hy,hz)-z */ sf_file Fm; /* model = absolute offset h -z */ int nw; /* spline order */ int nd,id; /* data size (nd=nhx*nhy*nhz) */ int nh; /* model size (nm=nh) */ float *dat=NULL; float *mod=NULL; float *map=NULL; float *mwt=NULL; float *dwt=NULL; int i; /* int im;*/ /*------------------------------------------------------------*/ sf_init(argc,argv); if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getint( "nw",&nw)) nw=4; /* spline order */ Fd = sf_input ("in"); ahx = sf_iaxa(Fd,1); sf_setlabel(ahx,"hx"); if(verb) sf_raxa(ahx); ahy = sf_iaxa(Fd,2); sf_setlabel(ahy,"hy"); if(verb) sf_raxa(ahy); ahz = sf_iaxa(Fd,3); sf_setlabel(ahz,"hz"); if(verb) sf_raxa(ahz); az = sf_iaxa(Fd,4); sf_setlabel(az,"z"); if(verb) sf_raxa(az); nhx = sf_n(ahx); ohx = sf_o(ahx); dhx = sf_d(ahx); nhy = sf_n(ahy); ohy = sf_o(ahy); dhy = sf_d(ahy); nhz = sf_n(ahz); ohz = sf_o(ahz); dhz = sf_d(ahz); nz = sf_n(az); if(!sf_getint ("nh",&nh)) nh=nhx + ohx/dhx; if(!sf_getfloat("oh",&oh)) oh=0; if(!sf_getfloat("dh",&dh)) dh=dhx; ah = sf_maxa(nh,oh,dh); sf_setlabel(ah,"h"); if(verb) sf_raxa(ah); Fm = sf_output("out"); sf_oaxa(Fm,ah,1); sf_oaxa(Fm,az,2); sf_putint(Fm,"n3",1); sf_putint(Fm,"n4",1); /*------------------------------------------------------------*/ nd = nhx*nhy*nhz; /* data size */ map = sf_floatalloc(nd); /* mapping */ mod = sf_floatalloc(nh); /* model vector */ dat = sf_floatalloc(nd); /* data vector */ mwt = sf_floatalloc(nh); /* model weight */ dwt = sf_floatalloc(nd); /* data weight */ spl = sf_spline_init(nw,nd); for(ihz=0;ihz<nhz;ihz++) { hz = ohz + ihz * dhz; hz*=hz; for(ihy=0;ihy<nhy;ihy++) { hy = ohy + ihy * dhy; hy*=hy; for(ihx=0;ihx<nhx;ihx++) { hx = ohx + ihx * dhx; hx*=hx; i = ihz * nhx*nhy + ihy * nhx + ihx; map[i] = sqrtf(hx+hy+hz); } } } sf_int1_init( map, oh, dh, nh, sf_spline_int, nw, nd, 0.0); for(id=0;id<nd;id++) { dwt[id]=1; } sf_banded_solve(spl,dwt); for(iz=0;iz<nz;iz++) { sf_warning("iz=%d of %d",iz+1,nz); sf_floatread(dat,nd,Fd); sf_banded_solve(spl,dat); sf_int1_lop( true, /* adj */ false, /* add */ nh, /* n model */ nd, /* n data */ mod, dat); sf_floatwrite(mod,nh,Fm); } /*------------------------------------------------------------*/ sf_int1_close(); free(map); free(mod); free(dat); free(mwt); free(dwt); exit(0); }
int main (int argc, char* argv[]) { /* ----------------------------------------------------------------------------------*/ // Variable declaration // ------------------------ // logical variables bool source, verb; // axes sf_axis awx,awz,awt; /* wavefield axes */ sf_axis atau; /* eic axes: time-lag and extended images */ sf_axis ar; /* coordinate file */ int nr,nx,nz,nt; // integer int i1, i2,i3,it, itau,itaux; /* integer var for loops */ int ix,iz; /*integers for extracting windowed wavefield */ float tmin, tmax,taumin,taumax,t,tau,tbmin,tbmax; float *uaux; // arrays float ***uo; /* wavefield array */ float *tgathers; /* time lag gathers */ float **adjsrc; /* adjoint source [nt] */ // coordinate arrays pt2d *rr=NULL; /* extended images coordinates */ /* ----------------------*/ /* I/O files */ sf_file Feic=NULL; sf_file Fxcr=NULL; sf_file Fadj=NULL; sf_file Fwfl=NULL; /* ----------------------*/ // End of variables declaration /* ----------------------------------------------------------------------------------*/ /* ----------------------*/ // init RSF argument parsing sf_init (argc,argv); // end of init RSF argument parsing /* ------- I/O declaration ---------------*/ Fwfl = sf_input("in"); /* Wavefield used for the adjoint computation, for adj */ /* source side pass the receiver wavefield, for receiver */ /* side pass the source wavefield */ Feic = sf_input("eic"); /* Penalized extended image (apply P(\tau) twice) */ Fxcr = sf_input("coord"); /* coordinates of every extended image, in 2d */ /* should be organized in (x1,z1),(x2,z2),...,(xn,zn) */ Fadj = sf_output("out"); /* adjoint source to be injected on each coordinate */ /* --------------------------------------- */ //Get parameters from command line: if (! sf_getbool("source",&source)) source=true; /* Source side [default] or receiver side adjoint? */ if (! sf_getbool("verb",&verb)) verb=true; /* verbosity flag, mainly debug printout */ /* at this time */ if(verb) sf_warning("===================================================="); if(verb) sf_warning("====== Calculating adjoint source ======="); if(source) { if(verb) sf_warning("====== source side joint source ======="); } else { if(verb) sf_warning("====== receiver side joint source ======="); } if(verb) sf_warning("===================================================="); // ------------------------------------------------- // Some file type checking if (SF_FLOAT != sf_gettype(Fwfl)) sf_error("Need float input for wavefield"); if (SF_FLOAT != sf_gettype(Feic)) sf_error("Need float input for eic"); if (SF_FLOAT != sf_gettype(Fxcr)) sf_error("Need float input for coordinates"); // ------------------------------------------------- // -------------------------------------------------------------------------------------- // Axes geometry loading and writing // -------------------------------------------------------------------------------------- // From wavefield awz = sf_iaxa(Fwfl,1); awx = sf_iaxa(Fwfl,2); awt = sf_iaxa(Fwfl,3); // From coordinates ar = sf_iaxa(Fxcr,2); // From extended images atau = sf_iaxa(Feic,1); taumin = SF_MIN(sf_o(atau),(sf_n(atau)-1)*sf_d(atau)+sf_o(atau)); taumax = SF_MAX(sf_o(atau),(sf_n(atau)-1)*sf_d(atau)+sf_o(atau)); // To adjoint source sf_oaxa(Fadj,awt,1); sf_oaxa(Fadj,ar,2); sf_putint(Fadj,"n3",1); nr=sf_n(ar); /*-------------------------------------------------------------------------------------*/ /* setup source/receiver coordinates */ /*-------------------------------------------------------------------------------------*/ rr = pt2dalloc1(nr); pt2dread1(Fxcr,rr,nr,2); if(verb) sf_warning("===================================================="); if(verb) sf_warning("reading %d extended image coordinates points",nr); if(verb) sf_warning("===================================================="); if(verb) sf_warning("allocating and reading wavefield"); if(verb) sf_warning("z axis: n1=%-10d o1=%-10.3f d1=%-10.3f",sf_n(awz),sf_o(awz),sf_d(awz)); if(verb) sf_warning("x axis: n2=%-10d o2=%-10.3f d2=%-10.3f",sf_n(awx),sf_o(awx),sf_d(awx)); if(verb) sf_warning("t axis: n3=%-10d o3=%-10.3f d3=%-10.3f",sf_n(awt),sf_o(awt),sf_d(awt)); if(verb) sf_warning("===================================================="); // allocate wavefield space uo = sf_floatalloc3(sf_n(awz),sf_n(awx),sf_n(awt)); if(uo==NULL) sf_error("not enough memory to read wavefield"); uaux = sf_floatalloc(1); nz=sf_n(awz); nx=sf_n(awx); nt=sf_n(awt); // read wavefield for (i3=0 ; i3<nt; i3++) { ; for (i2=0 ; i2<nx; i2++) { ; for (i1=0 ; i1<nz; i1++) { sf_floatread(uaux,1,Fwfl); uo[i3][i2][i1]=uaux[0]; } } } //------------------------------------------------------------------------------------- // reading extended images //------------------------------------------------------------------------------------- if(verb) sf_warning("reading %d extended images points",nr); if(verb) sf_warning("====================================================="); if(verb) sf_warning(""); tgathers = sf_floatalloc(sf_n(atau)); adjsrc = sf_floatalloc2(sf_n(awt),1); if(source) { for (i1=0; i1<sf_n(ar); i1++) { sf_floatread(tgathers,sf_n(atau),Feic); ix= 0.5+(rr[i1].x - sf_o(awx))/sf_d(awx); iz= 0.5+(rr[i1].z - sf_o(awz))/sf_d(awz); if (verb) if(verb) fprintf(stderr,"\b\b\b\b\b%d",i1+1); for (it=0; it<sf_n(awt); it++) { adjsrc[0][it]=0.0; // get the limits of tau such that we avoid // segmentation fault on the wavefield uo: // 0 < t-2*tau < tmax //Lower tau bound t=it*sf_d(awt)+sf_o(awt); tmin = SF_MIN(t+2*taumax,t+2*taumin); tmin = SF_MAX(tmin,0); //Upper tau bound tmax = SF_MAX(t+2*taumax,t+2*taumin); tmax = SF_MIN(tmax,sf_o(awt)+sf_d(awt)*(sf_n(awt)-1) ); tbmin =SF_MIN( -(t - tmax)*0.5,-(t - tmin)*0.5); tbmax =SF_MAX( -(t - tmax)*0.5,-(t - tmin)*0.5); for (itau = 1.5 + (tbmin - sf_o(atau))/sf_d(atau) ; itau< (tbmax - sf_o(atau))/sf_d(atau) ; itau++) { tau=itau*sf_d(atau)+sf_o(atau) ; itaux = 0.5 + ((t + 2*tau)-sf_o(awt))/sf_d(awt); adjsrc[0][it] += tgathers[itau]*uo[itaux][ix][iz]; } } sf_floatwrite(adjsrc[0],nt,Fadj); } } else { for (i1=0; i1<sf_n(ar); i1++) { sf_floatread(tgathers,sf_n(atau),Feic); ix= 0.5+(rr[i1].x - sf_o(awx))/sf_d(awx); iz= 0.5+(rr[i1].z - sf_o(awz))/sf_d(awz); if (verb) if(verb) fprintf(stderr,"\b\b\b\b\b%d",i1+1); //if (verb) if(verb) fprintf(stderr,"\b\b\b\b\b%03d/%03d",i1+1,sf_n(ar)); for (it=0; it<sf_n(awt); it++) { adjsrc[0][it]=0.0; // get the limits of tau such that we avoid // segmentation fault on the wavefield uo: // 0 < t-2*tau < tmax //Lower tau bound t=it*sf_d(awt)+sf_o(awt); tmin = SF_MIN(t-2*taumax,t-2*taumin); tmin = SF_MAX(tmin,0); //Upper tau bound tmax = SF_MAX(t-2*taumax,t-2*taumin); tmax = SF_MIN(tmax,sf_o(awt)+sf_d(awt)*(sf_n(awt)-1) ); tbmin =SF_MIN( (t - tmax)*0.5,(t - tmin)*0.5); tbmax =SF_MAX( (t - tmax)*0.5,(t - tmin)*0.5); for (itau = 1.5 + (tbmin - sf_o(atau))/sf_d(atau) ; itau< (tbmax - sf_o(atau))/sf_d(atau) ; itau++) { tau=itau*sf_d(atau)+sf_o(atau) ; itaux = 0.5 + ((t - 2*tau)-sf_o(awt))/sf_d(awt); adjsrc[0][it] += tgathers[itau]*uo[itaux][ix][iz]; } } sf_floatwrite(adjsrc[0],nt,Fadj); } } if (verb) if(verb) fprintf(stderr,"\n"); free(**uo); free(*uo); free(uo); free(*adjsrc); free(adjsrc); free(tgathers); exit(0); }
int main( int argc , char* argv[] ) { sf_init( argc , argv ); sf_file FI1, FI2, FI3, FO1; sf_axis aa; int dim, num_dim[SF_MAX_DIM], NTRACE, NT, nw, nwave, wsft, itrace, idim; float dt, **ref, **Q, *wave, **gather, **TVM; if(!sf_getint( "wsft" , &wsft )) sf_error( "MISSING wave_shift PARAMETER!!\n" ); /* The wave shift should be set up! */ FI1 = sf_input( "ref" ); FI2 = sf_input( "Q" ); FI3 = sf_input( "wave" ); FO1 = sf_output( "gather" ); NTRACE = sf_leftsize( FI1 , 1 ); dim = sf_filedims( FI1 , num_dim ); /* define the LEFTSIZE bigger than the first * dimension, so we can treat the data as two * dimensional-data, */ NT = sf_n( sf_iaxa( FI1 , 1 ) ); dt = sf_d( sf_iaxa( FI1 , 1 ) ); nw = sf_n( sf_iaxa( FI3 , 1 ) ); /* extract the information about the first * dimension, which is needed by the function * of calculating the attenuated wavelet */ nwave = lh_powerof2( nw ); /* compute the suitable length for the FFT */ ref = alloc2float( NT , NTRACE ); Q = alloc2float( NT , NTRACE ); gather = alloc2float( NT , NTRACE ); wave = alloc1float( nwave ); TVM = alloc2float( NT , NT ); zero2float( ref , NT , NTRACE ); zero2float( Q , NT , NTRACE ); zero2float( gather, NT , NTRACE ); zero1float( wave , nwave ); /* alloc and setup */ sf_floatread( &ref[0][0] , NT*NTRACE , FI1 ); sf_floatread( &Q[0][0] , NT*NTRACE , FI2 ); sf_floatread( &wave[0] , nw , FI3 ); for( itrace=0 ; itrace<NTRACE ; itrace++ ) { zero2float( TVM , NT , NT ); lh_time_variant_matrix( wave , wsft , nwave , dt , &Q[itrace][0], NT , TVM ); lh_matrix_mu_vector( TVM , &ref[itrace][0] , &gather[itrace][0], NT , NT ); } /* float **spec_real, **spec_imag, **spec_amp; int nwave1 = lh_powerof2( NT ); spec_real = alloc2float( nwave1 , NT ); spec_imag = alloc2float( nwave1 , NT ); spec_amp = alloc2float( 200 , NT ); zero2float( spec_real , nwave1 , NT ); zero2float( spec_imag , nwave1 , NT ); zero2float( spec_amp , 200 , NT ); int i,j; for( i=0 ; i<NT ; i++ ) { for( j=0 ; j<NT ; j++ ) spec_real[i][j] = TVM[j][i]; lh_fft( &spec_real[i][0] , &spec_imag[i][0], nwave1 , 1 ); for( j=0 ; j<200 ; j++ ) spec_amp[i][j] = sqrt( spec_real[i][j]*spec_real[i][j]+spec_imag[i][j]*spec_imag[i][j] ); } lh_write_2d_float_bin_row( spec_amp , NT , 200 , "spec_amp_qwave.bin" ); */ for( idim=1 ; idim<=dim ; idim++ ) { aa = sf_iaxa( FI1 , idim ); sf_oaxa( FO1 , aa , idim ); } sf_floatwrite( &gather[0][0] , NT*NTRACE , FO1 ); exit( 0 ); }
int main (int argc, char *argv[]) { bool verb; bool rays; sf_axis az,ax; /* Cartesian coordinates */ sf_axis at,ag; /* Ray coordinates */ int it,ig; int nz,nx,nt,ng; float dt,dg,ot,og; float xsou,zsou; /* source coordinates */ sf_file Fv=NULL; /* velocity file */ sf_file Fw=NULL; /* wavefronfs file */ float **vv=NULL; /* velocity */ pt2d *wm=NULL; /* wavefront it-1 */ pt2d *wo=NULL; /* wavefront it */ pt2d *wp=NULL; /* wavefront it+1 */ pt2d Ro; /* point on wft it-1 */ pt2d Pm,Po,Pp; /* points on wft it */ pt2d Qo; /* point on wft it+1 */ /*------------------------------------------------------------*/ sf_init(argc,argv); if(! sf_getbool("verb",&verb)) verb=false; if(! sf_getbool("rays",&rays)) rays=false; /* velocity file */ Fv = sf_input ("in"); az = sf_iaxa(Fv,1); sf_setlabel(az,"z"); nz=sf_n(az); if(verb) sf_raxa(az); ax = sf_iaxa(Fv,2); sf_setlabel(ax,"x"); nx=sf_n(ax); if(verb) sf_raxa(ax); vv=sf_floatalloc2(nz,nx); sf_floatread(vv[0],nz*nx,Fv); /* source location */ if(! sf_getfloat("xsou",&xsou)) xsou=sf_o(ax) + nx*sf_d(ax)/2; if(! sf_getfloat("zsou",&zsou)) zsou=sf_o(az) + nz*sf_d(az)/2; if(verb) fprintf(stderr,"xsou=%f zsou=%f\n",xsou,zsou); /* time axis */ if(! sf_getint ("nt",&nt)) nt=100; if(! sf_getfloat("ot",&ot)) ot=0; if(! sf_getfloat("dt",&dt)) dt=0.001; at = sf_maxa(nt,ot,dt); sf_setlabel(at,"t"); /* shooting angle axis */ if(! sf_getint ("ng",&ng)) ng= 360; if(! sf_getfloat("og",&og)) og=-180; if(! sf_getfloat("dg",&dg)) dg= 1; ag = sf_maxa(ng,og,dg); sf_setlabel(ag,"g"); /*------------------------------------------------------------*/ /* wavefronts file (g,t) */ Fw = sf_output("out"); sf_oaxa(Fw,ag,1); if(verb) sf_raxa(ag); sf_oaxa(Fw,at,2); if(verb) sf_raxa(at); /* set the output to complex */ sf_putint(Fw,"esize",8); sf_settype(Fw,SF_COMPLEX); /*------------------------------------------------------------*/ /* allocate wavefronts */ wm = pt2dalloc1(ng); wo = pt2dalloc1(ng); wp = pt2dalloc1(ng); /* initialize wavefronts */ for( ig=0; ig<ng; ig++) { wm[ig].x=wo[ig].x=wp[ig].x=0; wm[ig].z=wo[ig].z=wp[ig].z=0; wm[ig].v=wo[ig].v=wp[ig].v=0; } /*------------------------------------------------------------*/ /* init HWT */ hwt2d_init(vv,az,ax,at,ag); /*------------------------------------------------------------*/ /* construct it=0 wavefront */ it=0; for( ig=0; ig<ng; ig++) { wm[ig].x=xsou; wm[ig].z=zsou; wm[ig].v=hwt2d_getv(wm[ig]); } pt2dwrite1(Fw,wm,ng,2); /* write wavefront it=0 */ /*------------------------------------------------------------*/ /* construct it=1 wavefront */ it=1; for( ig=0; ig<ng; ig++) { double d,g; d = dt * hwt2d_getv(wm[ig]); g = (og+ig*dg) * SF_PI/180; wo[ig].x=xsou + d*sin(g); wo[ig].z=zsou + d*cos(g); wo[ig].v=hwt2d_getv(wo[ig]); } pt2dwrite1(Fw,wo,ng,2); /* write wavefront it=1 */ /*------------------------------------------------------------*/ /* LOOP over time */ for (it=2; it<nt; it++) { if(verb) fprintf(stderr,"it=%d\n",it); if(ng>3 && !rays) { /* boundaries */ ig=0; wp[ig] = hwt2d_raytr(wm[ig],wo[ig]); ig=ng-1; wp[ig] = hwt2d_raytr(wm[ig],wo[ig]); for (ig=1; ig<ng-1; ig++) { Pm = wo[ig-1]; Po = wo[ig ]; Qo = wm[ig]; Pp = wo[ig+1]; if(hwt2d_cusp(Qo,Pm,Po,Pp)) { Ro = hwt2d_raytr(Qo, Po ); } else { Ro = hwt2d_wfttr(Qo,Pm,Po,Pp); } wp[ig] = Ro; } } else { for (ig=0; ig<ng; ig++) { Po = wo[ig]; Qo = wm[ig]; Ro = hwt2d_raytr(Qo,Po); wp[ig] = Ro; } } /* write wavefront it */ pt2dwrite1(Fw,wp,ng,2); /* step in time */ for( ig=0; ig<ng; ig++) { wm[ig] = wo[ig]; wo[ig] = wp[ig]; } } /* end it */ /*------------------------------------------------------------*/ 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[]) { 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[]) { 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); }
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 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[]) { 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[]) { 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[]) { /* 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[]) { 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) { /* 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) { 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[]) { 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); }