📄 rayt2dan.c
字号:
/* Check if the point is in the previous circle */ if (r2 > (xc-xo)*(xc-xo)+(zc-zo)*(zc-zo) && it != NRS-1) continue; exo = fxo+(nxo-1)*dxo; ezo = fzo+(nzo-1)*dzo; /* Check if the point is out of output range */ if (xo<fxo || xo>exo || zo<fzo || zo>ezo) continue; xc = xo; zc = zo; px = ss[it]/vd1; pz = cc[it]/vd1; /* set parameters of the first auxilliary ray */ x1 = ray->rs[it].x; z1 = ray->rs[it].z; c1 = ray->rs[it].c; s1 = ray->rs[it].s; v1 = ray->rs[it].v; /* Compute the second derivatives of traveltimes */ /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ /* compute Xij and Yij */ X[0][0] = (x1-xc)/0.0017; X[1][0] = (z1-zc)/0.0017; Y[0][0] = ((s1/v1)-px)/0.0017; Y[1][0] = ((c1/v1)-pz)/0.0017; X[0][1] = (xx[it+1]-xx[it])/dt; X[1][1] = (zz[it+1]-zz[it])/dt; Y[0][1] = ((ss[it+1]/vv[it+1])-(ss[it]/vv[it]))/dt; Y[1][1] = ((cc[it+1]/vv[it+1])-(cc[it]/vv[it]))/dt; /* compute Nij */ Det = X[0][0]*X[1][1]-X[0][1]*X[1][0]; N[0][0] = (Y[0][0]*X[1][1]-Y[0][1]*X[1][0])/Det; N[0][1] = (-Y[0][0]*X[0][1]+Y[0][1]*X[0][0])/Det; N[1][0] = (Y[1][0]*X[1][1]-Y[1][1]*X[1][0])/Det; N[1][1] = (-Y[1][0]*X[0][1]+Y[1][1]*X[0][0])/Det; /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ /* determine the radius of extrapolation */ tc = it*dt; terr = tc*fac; norm2 = sqrt(N[0][0]*N[0][0]+N[1][1]*N[1][1]+2*N[0][1]*N[0][1]); r2 = terr/norm2; r1 = sqrt(r2); /* Make sure that the coordinates are regular */ if (r1*curv > 0.1) r1 = 0.1/curv; /* Ensure that the radius is not large */ if (r1 > 0.1*sd) r1 = 0.1*sd; r2 = r1*r1; nxf = ((xc-r1-fxo)/dxo)+0.9; if (nxf < 0) nxf=0; nxe = ((xc+r1-fxo)/dxo)+0.1; if (nxe >= nxo) nxe = nxo-1; for(ixo=nxf; ixo<=nxe; ++ixo) { xoc = fxo-xc+ixo*dxo; r2x = r2-xoc*xoc; if(r2x<0) continue; r1x = sqrt(r2x); t1x = tc+xoc*px; t2x = xoc*xoc*N[0][0]; t2xz= 2*xoc*N[0][1]; nzf = (zc-r1x-fzo)/dzo+0.9; if (nzf < 0) nzf = 0; nze = (zc+r1x-fzo)/dzo+0.1; if (nze>=nzo) nze = nzo-1; for(izo=nzf;izo<=nze;++izo) { if (sd<s[nzo*ixo+izo]) { zoc = fzo-zc+izo*dzo; t1 = t1x+zoc*pz; t2 = t2x+zoc*(zoc*N[1][1]+t2xz); s[nzo*ixo+izo] = sd; t[nzo*ixo+izo] = t1+0.5*t2; } } } } /* free ray */ freeRay(ray); } fwrite(t,sizeof(float),nxo*nzo,tfp); } /* free workspace */ free2float(delta); free2float(epsilon); /* free workspace */ free2float(VP0); free2float(VS0); free2float(a1111); free2float(a3333); free2float(a1133); free2float(a1313); free2float(a1113); free2float(a3313); return 0;}/****************************************************************** Functions for Ray tracing * *****************************************************************/Ray *makeRay (int SV, float x0, float z0, float a0, int nt, float dt, float ft, float **a1111xz, float **a3333xz, float **a1133xz, float **a1313xz, float **a1113xz, float **a3313xz, int nx, float dx, float fx, int nz, float dz, float fz, float amax, float amin)/*****************************************************************************Trace a ray for uniformly sampled v(x,z).******************************************************************************Input:x0 x coordinate of takeoff pointz0 z coordinate of takeoff pointa0 takeoff angle (radians)nt number of time samplesdt time sampling intervalft first time samplenx number of x samplesdx x sampling intervalfx first x samplenz number of z samplesdz z sampling intervalfz first z sampleamax maximum emergence angleamin minimum emergence anglea1111 array[nx][nz] of uniformly sampled density normalized elastic coef.a3333 array[nx][nz] of uniformly sampled density normalized elastic coef.a1133 array[nx][nz] of uniformly sampled density normalized elastic coef.a1313 array[nx][nz] of uniformly sampled density normalized elastic coef.a1113 array[nx][nz] of uniformly sampled density normalized elastic coef.a3313 array[nx][nz] of uniformly sampled density normalized elastic coef.******************************************************************************Returned: pointer to ray parameters sampled at discrete ray steps******************************************************************************Notes:The ray ends when it runs out of time (after nt steps) or with the first step that is out of the (x,z) bounds of the velocity function v(x,z).*****************************************************************************Technical Reference:Cerveny, V., 1972, Seismic rays and ray intensities in inhomogeneous anisotropic media: Geophys. J. R. Astr. Soc., 29, 1--13.***************************************************************************** Credits: CWP: Tariq Alkhalifah*****************************************************************************/{ int it,kmah; float t,x,z,c,s,p1,q1,p2,q2,px,pz,px2,pz2,pxz, lx,lz,cc,ss, a1111,da1111dx,da1111dz,dda1111dxdx,dda1111dxdz,dda1111dzdz, a3333,da3333dx,da3333dz,dda3333dxdx,dda3333dxdz,dda3333dzdz, a1133,da1133dx,da1133dz,dda1133dxdx,dda1133dxdz,dda1133dzdz, a1313,da1313dx,da1313dz,dda1313dxdx,dda1313dxdz,dda1313dzdz, a1113,da1113dx,da1113dz,dda1113dxdx,dda1113dxdz,dda1113dzdz, a3313,da3313dx,da3313dz,dda3313dxdx,dda3313dxdz,dda3313dzdz, da1111dn,dda1111dndn,da3333dn,dda3333dndn,da1133dn,dda1133dndn, da1313dn,dda1313dndn,da1113dn,dda1113dndn,da3313dn,dda3313dndn, gamm11,gamm13,gamm33,vp2,vp,ovp,sqr; Ray *ray; RayStep *rs; void *a11112; void *a33332; void *a11332; void *a13132; void *a11132; void *a33132; /*Convert degrees to radians*/ a0=a0*3.1415/180; amax=amax*3.1415/180; amin=amin*3.1415/180; /* allocate and initialize velocities interpolator */ a11112 = vel2Alloc(nx,dx,fx,nz,dz,fz,a1111xz); a33332 = vel2Alloc(nx,dx,fx,nz,dz,fz,a3333xz); a11332 = vel2Alloc(nx,dx,fx,nz,dz,fz,a1133xz); a13132 = vel2Alloc(nx,dx,fx,nz,dz,fz,a1313xz); a11132 = vel2Alloc(nx,dx,fx,nz,dz,fz,a1113xz); a33132 = vel2Alloc(nx,dx,fx,nz,dz,fz,a3313xz); /* last x and z in velocity model */ lx = fx+(nx-1)*dx; lz = fz+(nz-1)*dz; /* ensure takeoff point is within model */ if (x0<fx || x0>lx || z0<fz || z0>lz ) return NULL; /* allocate space for ray and raysteps */ ray = (Ray*)alloc1(1,sizeof(Ray)); rs = (RayStep*)alloc1(nt,sizeof(RayStep)); /* cosine and sine of takeoff angle */ c = cos(a0); s = sin(a0); cc = c*c; ss = s*s; /* velocities and derivatives at takeoff point */ vel2Interp(a11112,x0,z0,&a1111,&da1111dx,&da1111dz,&dda1111dxdx, &dda1111dxdz,&dda1111dzdz); da1111dn = da1111dx*c-da1111dz*s; dda1111dndn = dda1111dxdx*cc-2.0*dda1111dxdz*s*c+dda1111dzdz*ss; vel2Interp(a33332,x0,z0,&a3333,&da3333dx,&da3333dz,&dda3333dxdx, &dda3333dxdz,&dda3333dzdz); da3333dn = da3333dx*c-da3333dz*s; dda3333dndn = dda3333dxdx*cc-2.0*dda3333dxdz*s*c+dda3333dzdz*ss; vel2Interp(a11332,x0,z0,&a1133,&da1133dx,&da1133dz,&dda1133dxdx, &dda1133dxdz,&dda1133dzdz); da1133dn = da1133dx*c-da1133dz*s; dda1133dndn = dda1133dxdx*cc-2.0*dda1133dxdz*s*c+dda1133dzdz*ss; vel2Interp(a13132,x0,z0,&a1313,&da1313dx,&da1313dz,&dda1313dxdx, &dda1313dxdz,&dda1313dzdz); da1313dn = da1313dx*c-da1313dz*s; dda1313dndn = dda1313dxdx*cc-2.0*dda1313dxdz*s*c+dda1313dzdz*ss; vel2Interp(a11132,x0,z0,&a1113,&da1113dx,&da1113dz,&dda1113dxdx, &dda1113dxdz,&dda1113dzdz); da1113dn = da1113dx*c-da1113dz*s; dda1113dndn = dda1113dxdx*cc-2.0*dda1113dxdz*s*c+dda1113dzdz*ss; vel2Interp(a33132,x0,z0,&a3313,&da3313dx,&da3313dz,&dda3313dxdx, &dda3313dxdz,&dda3313dzdz); da3313dn = da3313dx*c-da3313dz*s; dda3313dndn = dda3313dxdx*cc-2.0*dda3313dxdz*s*c+dda3313dzdz*ss; /*computing the phase velocity for a0 angle */ gamm11 = a1111*ss+ a1313*cc +2*a1113*s*c; gamm33 = a3333*cc + a1313*ss+2*a3313*s*c; gamm13 = (a1133+a1313)*s*c+ a1113*ss+ a3313*cc; sqr = sqrt((gamm11+gamm33)*(gamm11+gamm33)- 4*(gamm11*gamm33-gamm13*gamm13)); if(SV) vp2 = gamm11+gamm33-sqr; else vp2 = gamm11+gamm33+sqr; vp = sqrt(vp2*.5); ovp = 1/vp; px = s*ovp; pz = c*ovp; /* first ray step */ rs[0].t = t = ft; rs[0].x = x = x0; rs[0].z = z = z0; rs[0].q1 = q1 = 1.0; rs[0].p1 = p1 = 0.0; rs[0].q2 = q2 = 0.0; rs[0].p2 = p2 = 1.0; rs[0].kmah = kmah = 0; rs[0].c = c; rs[0].s = s; rs[0].v = vp; rs[0].dvdx = .5*da3333dx*vp/a3333; rs[0].dvdz = .5*da3333dz*vp/a3333; /* loop over time steps */ for (it=1; it<nt; ++it) { /* variables used for Runge-Kutta integration */ float h=dt,hhalf=dt/2.0,hsixth=dt/6.0, q2old,xt,zt,p1t,q1t,p2t,q2t, dx,dz,dp1,dq1,dp2,dq2, dxt,dzt,dp1t,dq1t,dp2t,dq2t, dxm,dzm,dp1m,dq1m,dp2m,dq2m, gamma11,gamma33,gamma13,g11,g13,g33,den, sxfactor,szfactor,snfact,dpx,dpz,pxt,pzt,dpxt, dpzt,dpxm,dpzm,dxdn,dzdn,snfactor, dxx,dzz,dcdp1,dcdp3,dcdp13,ddcdnn,ddcdqq, ddcdpn,dgamma11dpx,dgamma11dpz,dgamma33dpx, dgamma33dpz,dgamma13dpx,dgamma13dpz,dg11dpx, dg11dpz,dg33dpx,dg33dpz,dg13dpx,dg13dpz,ddxdpx, ddzdpz,ddxdpz,dgamma11dn,dgamma33dn,dgamma13dn, dg11dn,dg33dn,dg13dn,dsnfactordn,ddxdn,ddzdn; /* if ray is out of bounds, break */ if (x<fx || x>lx || z<fz || z>lz || c>(cos(amin)+0.01) || c<(cos(amax))-0.01) break; /* remember old q2 */ q2old = q2; /* step 1 of 4th-order Runge-Kutta */ px2 = px*px; pz2 = pz*pz; pxz = px*pz; /*anisotropy parameters*/ gamma11 = a1111*px2+ a1313*pz2 +2*a1113*pxz; gamma33 = a3333*pz2 + a1313*px2+2*a3313*pxz; gamma13 = (a1133+a1313)*pxz+ a1113*px2+ a3313*pz2; den = 1/(gamma11+gamma33-2); g11 = (gamma33-1)*den; g33 = (gamma11-1)*den; g13 = -gamma13*den; sxfactor = da1111dx*px2*g11+da3333dx*pz2*g33+ 2*(da1133dx+da1313dx)*pxz*g13+da1313dx*(px2*g33+pz2*g11)+ 2*da3313dx*(pz2*g13+pxz*g33)+2*da1113dx*(pxz*g11+px2*g13); szfactor = da1111dz*px2*g11+da3333dz*pz2*g33+ 2*(da1133dz+da1313dz)*pxz*g13+da1313dz*(px2*g33+pz2*g11)+ 2*da3313dz*(pz2*g13+pxz*g33)+2*da1113dz*(pxz*g11+px2*g13); snfact = sxfactor*c-szfactor*s; /*computing ray velocities and derivatives*/ dx = (a1111*px*g11+(a1133+a1313)*pz*g13+a3313*pz*g33 +a1113*(pz*g11+2*px*g13)+a1313*g33*px); dz = (a3333*pz*g33+(a1133+a1313)*px*g13+a1113*px*g11 +a3313*(px*g33+2*pz*g13)+a1313*g11*pz); dgamma11dpx = 2*a1111*px+2*a1113*pz; dgamma11dpz = 2*a1313*pz+2*a1113*px; dgamma33dpx = 2*a1313*px+2*a3313*pz; dgamma33dpz = 2*a3333*pz+2*a3313*px; dgamma13dpx= (a1133+a1313)*pz+2*a1113*px; dgamma13dpz= (a1133+a1313)*px+2*a3313*pz; dgamma11dn = da1111dn*px2+ da1313dn*pz2 +2*da1113dn*pxz; dgamma33dn = da3333dn*pz2 + da1313dn*px2+2*da3313dn*pxz; dgamma13dn = (da1133dn+da1313dn)*pxz+ da1113dn*px2+ da3313dn*pz2; dg11dpx = -(gamma33-1)*(dgamma11dpx+dgamma33dpx-4*dx)*den*den+ (dgamma33dpx-2*dx)*den; dg11dpz = -(gamma33-1)*(dgamma11dpz+dgamma33dpz-4*dz)*den*den+ (dgamma33dpz-2*dz)*den; dg33dpx = -(gamma11-1)*(dgamma11dpx+dgamma33dpx-4*dx)*den*den+ (dgamma11dpx-2*dx)*den; dg33dpz = -(gamma11-1)*(dgamma11dpz+dgamma33dpz-4*dz)*den*den+ (dgamma11dpz-2*dz)*den; dg13dpx = gamma13*(dgamma11dpx+dgamma33dpx-4*dx)*den*den- dgamma13dpx*den; dg13dpz = gamma13*(dgamma11dpz+dgamma33dpz-4*dz)*den*den- dgamma13dpz*den; dg11dn = -(gamma33-1)*(dgamma11dn+dgamma33dn-2*snfact)*den*den+ (dgamma33dn-snfact)*den; dg33dn = -(gamma11-1)*(dgamma11dn+dgamma33dn-2*snfact)*den*den+ (dgamma11dn-snfact)*den; dg13dn = gamma13*(dgamma11dn+dgamma33dn-2*snfact)*den*den- dgamma13dn*den; ddxdpx= a1111*px*dg11dpx+(a1133+a1313)*pz*dg13dpx+ a3313*pz*dg33dpx+a1113*(pz*dg11dpx+2*px*dg13dpx) +a1313*dg33dpx*px; ddzdpz= a3333*pz*dg33dpz+(a1133+a1313)*px*dg13dpz+ a1113*px*dg11dpz+a3313*(px*dg33dpz+2*pz*dg13dpz)+ a1313*dg11dpz*pz; ddxdpz= a1111*px*dg11dpz+(a1133+a1313)*pz*dg13dpz+ a3313*pz*dg33dpz+a1113*(pz*dg11dpz+2*px*dg13dpz)+ a1313*dg33dpz*px; dsnfactordn = da1111dn*px2*dg11dn+da3333dn*pz2*dg33dn+ 2*(da1133dn+da1313dn)*pxz*dg13dn+da1313dn*(px2*dg33dn+pz2*dg11dn)+ 2*da3313dn*(pz2*dg13dn+pxz*dg33dn)+2*da1113dn*(pxz*dg11dn+px2*dg13dn); ddxdn = (a1111*px*dg11dn+(a1133+a1313)*pz*dg13dn+a3313*pz*dg33dn +a1113*(pz*dg11dn+2*px*dg13dn)+a1313*dg33dn*px); ddzdn = (a3333*pz*dg33dn+(a1133+a1313)*px*dg13dn+a1113*px*dg11dn +a3313*(px*dg33dn+2*pz*dg13dn)+a1313*dg11dn*pz); /*evaluating change in slowness and amplitude along ray*/ dpx = -0.5*sxfactor; dpz = -0.5*szfactor; dcdp1 = a1111*g11+a1313*g33+2*a1113*g13+ddxdpx-dx*dx; dcdp3 = a3333*g33+a1313*g11+2*a3313*g13+ddzdpz-dz*dz; dcdp13 = a1133*g13+a1313*g13+a1113*g11+a3313*g33+ddxdpz-dx*dz; ddcdqq = dcdp1*cc-2.0*dcdp13*s*c+dcdp3*ss; dxdn = (da1111dn*px*g11+(da1133dn+da1313dn)*pz*g13+da3313dn*pz*g33 +da1113dn*(pz*g11+2*px*g13)+da1313dn*g33*px); dzdn = (da3333dn*pz*g33+(da1133dn+da1313dn)*px*g13+da1113dn*px*g11 +da3313dn*(px*g33+2*pz*g13)+da1313dn*g11*pz); ddcdpn = dxdn*c-dzdn*s-.5*dx*sxfactor*cc+ .5*(dx*szfactor+dz*sxfactor)*s*c-.5*dz*szfactor*ss +ddxdn*c-ddzdn*s; snfactor = dda1111dndn*px2*g11+dda3333dndn*pz2*g33+ 2*(dda1133dndn+dda1313dndn)*pxz*g13+ dda1313dndn*(px2*g33+pz2*g11)+ 2*dda3313dndn*(pz2*g13+pxz*g33)+ 2*dda1113dndn*(pxz*g11+px2*g13); ddcdnn = 0.5*snfactor-.25*sxfactor*sxfactor*cc+ .5*sxfactor*szfactor*s*c-.25*szfactor*szfactor*ss +.5*dsnfactordn; dp1 = -ddcdnn*q1-ddcdpn*p1; dq1 = ddcdqq*p1+ddcdpn*q1; dp2 = -ddcdnn*q2-ddcdpn*p2; dq2 = ddcdqq*p2+ddcdpn*q2; xt = x+hhalf*dx; zt = z+hhalf*dz; pxt = px+hhalf*dpx; pzt = pz+hhalf*dpz; p1t = p1+hhalf*dp1; q1t = q1+hhalf*dq1; p2t = p2+hhalf*dp2; q2t = q2+hhalf*dq2; vp = 1/sqrt(pxt*pxt+pzt*pzt); s = pxt*vp; c = pzt*vp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -