📄 velpertan.c
字号:
ss = s*s; cc = c*c; vel2Interp(a11112,xt,zt,&a1111,&da1111dx,&da1111dz,&dda1111dxdx, &dda1111dxdz,&dda1111dzdz); da1111dn = da1111dx*c-da1111dz*s; dda1111dndn = dda1111dxdx*cc-2.0*dda1111dxdz*s*c+dda1111dzdz*ss; vel2Interp(a33332,xt,zt,&a3333,&da3333dx,&da3333dz,&dda3333dxdx, &dda3333dxdz,&dda3333dzdz); da3333dn = da3333dx*c-da3333dz*s; dda3333dndn = dda3333dxdx*cc-2.0*dda3333dxdz*s*c+dda3333dzdz*ss; vel2Interp(a11332,xt,zt,&a1133,&da1133dx,&da1133dz,&dda1133dxdx, &dda1133dxdz,&dda1133dzdz); da1133dn = da1133dx*c-da1133dz*s; dda1133dndn = dda1133dxdx*cc-2.0*dda1133dxdz*s*c+dda1133dzdz*ss; vel2Interp(a13132,xt,zt,&a1313,&da1313dx,&da1313dz,&dda1313dxdx, &dda1313dxdz,&dda1313dzdz); da1313dn = da1313dx*c-da1313dz*s; dda1313dndn = dda1313dxdx*cc-2.0*dda1313dxdz*s*c+dda1313dzdz*ss; vel2Interp(a11132,xt,zt,&a1113,&da1113dx,&da1113dz,&dda1113dxdx, &dda1113dxdz,&dda1113dzdz); da1113dn = da1113dx*c-da1113dz*s; dda1113dndn = dda1113dxdx*cc-2.0*dda1113dxdz*s*c+dda1113dzdz*ss; vel2Interp(a33132,xt,zt,&a3313,&da3313dx,&da3313dz,&dda3313dxdx, &dda3313dxdz,&dda3313dzdz); da3313dn = da3313dx*c-da3313dz*s; dda3313dndn = dda3313dxdx*cc-2.0*dda3313dxdz*s*c+dda3313dzdz*ss; /* step 4 of 4th-order Runge-Kutta */ px2 = pxt*pxt; pz2 = pzt*pzt; pxz = pxt*pzt; /*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*/ dxt = (a1111*pxt*g11+(a1133+a1313)*pzt*g13+a3313*pzt*g33 +a1113*(pzt*g11+2*pxt*g13)+a1313*g33*pxt); dzt = (a3333*pzt*g33+(a1133+a1313)*pxt*g13+a1113*pxt*g11 +a3313*(pxt*g33+2*pzt*g13)+a1313*g11*pzt); dpxt = -0.5*sxfactor; dpzt = -0.5*szfactor; dgamma11dpx = 2*a1111*pxt+2*a1113*pzt; dgamma11dpz = 2*a1313*pzt+2*a1113*pxt; dgamma33dpx = 2*a1313*pxt+2*a3313*pzt; dgamma33dpz = 2*a3333*pzt+2*a3313*pxt; dgamma13dpx= (a1133+a1313)*pzt+2*a1113*pxt; dgamma13dpz= (a1133+a1313)*pxt+2*a3313*pzt; 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*dxt)*den*den+ (dgamma33dpx-2*dxt)*den; dg11dpz = -(gamma33-1)*(dgamma11dpz+dgamma33dpz-4*dzt)*den*den+ (dgamma33dpz-2*dzt)*den; dg33dpx = -(gamma11-1)*(dgamma11dpx+dgamma33dpx-4*dxt)*den*den+ (dgamma11dpx-2*dxt)*den; dg33dpz = -(gamma11-1)*(dgamma11dpz+dgamma33dpz-4*dzt)*den*den+ (dgamma11dpz-2*dzt)*den; dg13dpx = gamma13*(dgamma11dpx+dgamma33dpx-4*dxt)*den*den- dgamma13dpx*den; dg13dpz = gamma13*(dgamma11dpz+dgamma33dpz-4*dzt)*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*pxt*dg11dpx+(a1133+a1313)*pzt*dg13dpx+ a3313*pzt*dg33dpx+a1113*(pzt*dg11dpx+2*pxt*dg13dpx) +a1313*dg33dpx*pxt; ddzdpz= a3333*pzt*dg33dpz+(a1133+a1313)*pxt*dg13dpz+ a1113*pxt*dg11dpz+a3313*(pxt*dg33dpz+2*pzt*dg13dpz)+ a1313*dg11dpz*pzt; ddxdpz= a1111*pxt*dg11dpz+(a1133+a1313)*pzt*dg13dpz+ a3313*pzt*dg33dpz+a1113*(pzt*dg11dpz+2*pxt*dg13dpz)+ a1313*dg33dpz*pxt; 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*pxt*dg11dn+(a1133+a1313)*pzt*dg13dn+a3313*pzt*dg33dn +a1113*(pzt*dg11dn+2*pxt*dg13dn)+a1313*dg33dn*pxt); ddzdn = (a3333*pzt*dg33dn+(a1133+a1313)*pxt*dg13dn+a1113*pxt*dg11dn +a3313*(pxt*dg33dn+2*pzt*dg13dn)+a1313*dg11dn*pzt); dcdp1 = a1111*g11+a1313*g33+2*a1113*g13+ddxdpx-dxt*dxt; dcdp3 = a3333*g33+a1313*g11+2*a3313*g13+ddzdpz-dzt*dzt; dcdp13 = a1133*g13+a1313*g13+a1113*g11+a3313*g33+ddxdpz-dxt*dzt; ddcdqq = dcdp1*cc-2.0*dcdp13*s*c+dcdp3*ss; dxdn = (da1111dn*pxt*g11+(da1133dn+da1313dn)*pzt*g13+ da3313dn*pzt*g33+da1113dn*(pzt*g11+2*pxt*g13)+ da1313dn*g33*pxt); dzdn = (da3333dn*pzt*g33+(da1133dn+da1313dn)*pxt*g13+ da1113dn*pxt*g11+da3313dn*(pxt*g33+2*pzt*g13)+ da1313dn*g11*pzt); ddcdpn = dxdn*c-dzdn*s-.5*dxt*sxfactor*cc+ .5*(dxt*szfactor+dzt*sxfactor)*s*c-.5*dzt*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; dp1t = -ddcdnn*q1t-ddcdpn*p1t; dq1t = ddcdqq*p1t+ddcdpn*q1t; dp2t = -ddcdnn*q2t-ddcdpn*p2t; dq2t = ddcdqq*p2t+ddcdpn*q2t; dxx = hsixth*(dx+dxt+2.0*dxm); dzz = hsixth*(dz+dzt+2.0*dzm); x += dxx; z += dzz; px += hsixth*(dpx+dpxt+2.0*dpxm); pz += hsixth*(dpz+dpzt+2.0*dpzm); p1 += hsixth*(dp1+dp1t+2.0*dp1m); q1 += hsixth*(dq1+dq1t+2.0*dq1m); p2 += hsixth*(dp2+dp2t+2.0*dp2m); q2 += hsixth*(dq2+dq2t+2.0*dq2m); vp = 1/sqrt(px*px+pz*pz); s = px*vp; c = pz*vp; ss = s*s; cc = c*c; vel2Interp(a11112,x,z,&a1111,&da1111dx,&da1111dz,&dda1111dxdx, &dda1111dxdz,&dda1111dzdz); da1111dn = da1111dx*c-da1111dz*s; dda1111dndn = dda1111dxdx*cc-2.0*dda1111dxdz*s*c+dda1111dzdz*ss; vel2Interp(a33332,x,z,&a3333,&da3333dx,&da3333dz,&dda3333dxdx, &dda3333dxdz,&dda3333dzdz); da3333dn = da3333dx*c-da3333dz*s; dda3333dndn = dda3333dxdx*cc-2.0*dda3333dxdz*s*c+dda3333dzdz*ss; vel2Interp(a11332,x,z,&a1133,&da1133dx,&da1133dz,&dda1133dxdx, &dda1133dxdz,&dda1133dzdz); da1133dn = da1133dx*c-da1133dz*s; dda1133dndn = dda1133dxdx*cc-2.0*dda1133dxdz*s*c+dda1133dzdz*ss; vel2Interp(a13132,x,z,&a1313,&da1313dx,&da1313dz,&dda1313dxdx, &dda1313dxdz,&dda1313dzdz); da1313dn = da1313dx*c-da1313dz*s; dda1313dndn = dda1313dxdx*cc-2.0*dda1313dxdz*s*c+dda1313dzdz*ss; vel2Interp(a11132,x,z,&a1113,&da1113dx,&da1113dz,&dda1113dxdx, &dda1113dxdz,&dda1113dzdz); da1113dn = da1113dx*c-da1113dz*s; dda1113dndn = dda1113dxdx*cc-2.0*dda1113dxdz*s*c+dda1113dzdz*ss; vel2Interp(a33132,x,z,&a3313,&da3313dx,&da3313dz,&dda3313dxdx, &dda3313dxdz,&dda3313dzdz); da3313dn = da3313dx*c-da3313dz*s; dda3313dndn = dda3313dxdx*cc-2.0*dda3313dxdz*s*c+dda3313dzdz*ss; /* update time */ t += dt; /* update kmah index */ if ((q2<=0.0 && q2old>0.0) || (q2>=0.0 && q2old<0.0)) kmah++; /* save ray parameters */ rs[it].t = t; rs[it].x = x; rs[it].z = z; rs[it].c = c; rs[it].s = s; rs[it].q1 = q1; rs[it].p1 = p1; rs[it].q2 = q2; rs[it].p2 = p2; rs[it].kmah = kmah; rs[it].v = vp; rs[it].dvdx = .5*da3333dx*vp/a3333; rs[it].dvdz = .5*da3333dz*vp/a3333; /*printf("%d %f %f %f %f %f %f %f \n",it,t,x,z,fx,fz,lx,lz);*/ /*printf("%f %f \n",z,x);*/ } /* free velocity interpolator */ vel2Free(a11112); vel2Free(a33332); vel2Free(a11332); vel2Free(a13132); vel2Free(a11132); vel2Free(a33132); /* return ray */ ray->nrs = it; ray->rs = rs; ray->nc = 0; ray->c = NULL; return ray;}void freeRay (Ray *ray)/*****************************************************************************Free a ray.******************************************************************************Input:ray ray to be freed*****************************************************************************/{ if (ray->c!=NULL) free1((void*)ray->c); free1((void*)ray->rs); free1((void*)ray);}/*****************************************************************************Functions to support interpolation of velocity and its derivatives.******************************************************************************Functions:vel2Alloc allocate and initialize an interpolator for v(x,z)vel2Interp interpolate v(x,z) and its derivatives******************************************************************************Notes:Interpolation is performed by piecewise cubic Hermite polynomials,so that velocity and first derivatives are continuous. Therefore,velocity v, first derivatives dv/dx and dv/dz, and the mixedderivative ddv/dxdz are continuous. However, second derivativesddv/dxdx and ddv/dzdz are discontinuous.*****************************************************************************Technical Reference: Hale, D., 1992, Migration by the Kirchhoff, slant stack, and Gaussian beam methods: Colorado School of Mines.***************************************************************************** Credits: CWP: Dave Hale*****************************************************************************//* number of pre-computed, tabulated interpolators */#define NTABLE 101/* length of each interpolator in table (4 for piecewise cubic) */#define LTABLE 4/* table of pre-computed interpolators, for 0th, 1st, and 2nd derivatives */static float tbl[3][NTABLE][LTABLE];/* constants */static int ix=1-LTABLE/2-LTABLE,iz=1-LTABLE/2-LTABLE;static float ltable=LTABLE,ntblm1=NTABLE-1;/* indices for 0th, 1st, and 2nd derivatives */static int kx[6]={0,1,0,2,1,0};static int kz[6]={0,0,1,0,1,2};/* function to build interpolator tables; sets tabled=1 when built */static void buildTables (void);static int tabled=0;/* interpolator for velocity function v(x,z) of two variables */typedef struct Vel2Struct { int nx; /* number of x samples */ int nz; /* number of z samples */ int nxm; /* number of x samples minus LTABLE */ int nzm; /* number of x samples minus LTABLE */ float xs,xb,zs,zb,sx[3],sz[3],**vu;} Vel2;void* vel2Alloc (int nx, float dx, float fx, int nz, float dz, float fz, float **v)/*****************************************************************************Allocate and initialize an interpolator for v(x,z) and its derivatives.******************************************************************************Input:nx number of x samplesdx x sampling intervalfx first x samplenz number of z samplesdz z sampling intervalfz first z samplev array[nx][nz] of uniformly sampled v(x,z)*****************************************************************************Returned: pointer to interpolator*****************************************************************************/{ Vel2 *vel2; /* allocate space */ vel2 = (Vel2*)alloc1(1,sizeof(Vel2)); /* set state variables used for interpolation */ vel2->nx = nx; vel2->nxm = nx-LTABLE; vel2->xs = 1.0/dx; vel2->xb = ltable-fx*vel2->xs; vel2->sx[0] = 1.0; vel2->sx[1] = vel2->xs; vel2->sx[2] = vel2->xs*vel2->xs; vel2->nz = nz; vel2->nzm = nz-LTABLE; vel2->zs = 1.0/dz; vel2->zb = ltable-fz*vel2->zs; vel2->sz[0] = 1.0; vel2->sz[1] = vel2->zs; vel2->sz[2] = vel2->zs*vel2->zs; vel2->vu = v; /* if necessary, build interpolator coefficient tables */ if (!tabled) buildTables(); return vel2;}void vel2Free (void *vel2)/*****************************************************************************Free an interpolator for v(x,z) and its derivatives.******************************************************************************Input:vel2 pointer to interpolator as returned by vel2Alloc()*****************************************************************************/{ free1(vel2);}void vel2Interp (void *vel2, float x, float z, float *v, float *vx, float *vz, float *vxx, float *vxz, float *vzz)/*****************************************************************************Interpolation of a velocity function v(x,z) and its derivatives.******************************************************************************Input:vel2 pointer to interpolator as returned by vel2A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -