简单明了“炮并行”、“MPI”、“C语言”、“VTI介质”、“RTM”、“中间激发两边接收”、“全孔径接收”、“照明”、“拉普拉斯滤波”、“角度域共成像点道集”、“Poynting矢量”;
在此做个备份!
直接上代码吧!头文件请到SeismicUnix中找。
//#############################################################a
//##s
//##s 2D Acoustic VTI Medium RTM & Pick Up ADCIG
//##s
//##s----------------------------------------------------------
//##s PML , P&SV , VTI , Acoustic , RTM , -SV , Adcig,
//##s Migration , Both sides receive , SU or dat(v,e,d) ,
//##s Adcig( poynting , s-r , offset-domain ),
//##s
//##s----------------------------------------------------------
//##s Rong Tao
//##s 2016
//############################################################a
#include
#include
#include
#include
#include "mpi.h"
#include "/home/Toa/hc/alloc.c"
#include "/home/Toa/hc/alloc.h"
#include "/home/Toa/hc/complex.c"
#include "/home/Toa/hc/complex.h"
#include "/home/Toa/hc/bhdr.h"
#include "/home/Toa/hc/hdr.h"
#include "/home/Toa/hc/fft.h"
#include "/home/Toa/hc/fft.c"
#include "/home/Toa/hc/mute_direct.h"
#include "/home/Toa/hc/cjbsegy.h"
/********* SEG-Y header *********/
typedef cjbsegy segy;
/********** SU & SEG-Y **********/
#define SU_NKEYS 80 /* Number of key header words */
#define HDRBYTES 240 /* Bytes in the trace header */
#define EBCBYTES 3200 /* Bytes in the card image EBCDIC block */
#define BNYBYTES 400 /* Bytes in the binary coded block */
#define SEGY_HDRBYTES 240 /* Bytes in the tape trace header */
#define SEGY_NKEYS 71 /* Number of mandated header fields */
#define BHED_NKEYS 27 /* Number of mandated binary fields */
#define pi 3.1415926535898
/********* SEG-Y header *********/
Y_3200 y3200;
bhed head_400;
cjbsegy tr, vtr;
/********* SEG-Y header *********/
/********** SU function *********/
void swap_short_2(short *tni2);
void swap_u_short_2(unsigned short *tni2);
void swap_int_4(int *tni4);
void swap_u_int_4(unsigned int *tni4);
void swap_long_4(long *tni4);
void swap_u_long_4(unsigned long *tni4);
void swap_float_4(float *tnf4);
void swap_double_8(double *tndd8);
void swaphval(segy *tr, int index);
/********* SU function *********/
/* MAIN */
main(int argc,char *argv[])
{
/*************************************** function ********************************************/
void model_vti_get_boundry(int nx,int nz,int vnx,int vnz,int nt,int npd,float dx,float dz,
float vdx,float vdz,float favg,float tmax,float dt,float dtout,float pfac,
float **vp,float **epsilu,float **deta,float **rho,
int ns_sxd,int ds_sxd,int fs_sxd,int zs_sxd,int is,
float **p_cal_x,float **p_cal_z,
float **p_top_x,float **p_bottom_x,float **p_left_x,float **p_right_x,
float **p_top_z,float **p_bottom_z,float **p_left_z,float **p_right_z,int _Circle_,
int mm,int wtype,int hsx,int myid,float *mu_v,int flag_snap,int seismic);
void mute_directwave(int flag_mu,int nx,int nt,float dt,float favg,
float dx,float dz,int fs_sxd,int ds_sxd,int zs_sxd,int is,
float mu_v,float **p_cal,int tt);
void RTM_corr_adcig(int nx,int nz,int vnx,int vnz,int nt,int npd,float dx,float dz,
float vdx,float vdz,float favg,float tmax,float dt,float dtout,
float pfac,float **vp,float **epsilu,float **deta,float **rho,char FN5[],
int ns_sxd,int ds_sxd,int fs_sxd,int ds_initial,int fs_initial,int zs_sxd,int is,int flag_cdp,
float **p_top_x,float **p_bottom_x,float **p_left_x,float **p_right_x,////////////////////////////////
float **p_top_z,float **p_bottom_z,float **p_left_z,float **p_right_z,float **p_obs_x,float **p_obs_z,
int mm,int wtype,int hsx,int myid,float **mig_is,float **mig_ns0,
float ***adcig_is,float ***adcig_ns0,float ***Ixhz_is,float ***Ixhz_ns0,int nh,
int flag_snap,int seismic,int flag_adcig);
void smooth1float(float *v,int r,int n);
void smooth2float(int nx,int rx,int nz,int rz,float **v);
void pad_vv(int nx,int nz,int npd,float **ee);
void read_v_e_d_r(char FN1[],char FN2[],char FN3[],int nx,int nz,float **vv,float **epsilu,float **deta,
float **rho0,int npd,int seismic);
/*************************** parameter statement ***********************/
int i,j,k,l,m,ih,is,nx,nz,nt,vnx,vnz,i_start,i_end,mm,wtype,hsx,ia,nxs,flag_cdp,flag_adcig,nh;
int ns_sxd,ds_sxd,fs_sxd,zs_sxd,fs,ds,npd;
float dx,dz,vdx,vdz,tmax,dt,dtout,pfac,favg;
int myid,numprocs,_Circle_,flag_mu,flag_snap,seismic,nangle,dangle,fangle;
float mu_v;
/***************** wave float **************/
float **p_cal_x,**p_cal_z,**p_top_x,**p_bottom_x,**p_left_x,**p_right_x;
float **p_top_z,**p_bottom_z,**p_left_z,**p_right_z;
/***************** image float *************/
float **mig_is,**mig_ns,**mig_ns0,***adcig_is,***adcig_ns,***adcig_ns0,**adcig2d;
float ***Ixhz_ns0,***Ixhz_ns,***Ixhz_is;
float **vp,**rho,**deta,**epsilu;
float **vps,**rhos,**detas,**epsilus;
//a###########################################################################
//#### input the parameter and confirm ####
//a###########################################################################
/************************ dat document **********************/
/* Input velocity */char FN1[250]={"vel_1801_862.dat"};
/* Input epsilu */char FN2[250]={"eps_1801_862.dat"};
/* Input deta */char FN3[250]={"del_1801_862.dat"};
/* Cal data */char FN4[250]={"shot_cal.dat"};
/* Obs data */char FN5[250]={"shot_obs.dat"};
/* Migration */char FN6[250]={"mig_ns.dat"};
/* IS tempor migration */char FN7[250]={"mig_is_tempor.dat"};
/* Adcig initial */char FN8[250]={"adcig.dat"};
/* Adcig smooth */char FN9[250]={"adcig_smooth.dat"};
/* Migration adcig stack */char FN10[250]={"mig_stack_adcig.dat"};
/* Half offset I(x,h,z) */char FN11[250]={"Image_x_h_z.dat"};
/*************************** type ***************************/
/* Wavelet type (1-3) */ wtype=1;
/* 1-mute , 0->don't mute */ flag_mu=1;
/* 1-snap , 0->nosnap */ flag_snap=0;
/* 1.dat, 2.su (v,e,d) */ seismic=1;
/*************************** cdp ****************************/
/* Activate "nxs"(=1) */ flag_cdp=1; /* 1-activate ;0-invaliable */
/* CDP of each shot */ nxs=501; /* Must be odd number */
/*************************** cdp ****************************/
/* choice adcig type */ flag_adcig=1; /* 1-poynting */
/* 2-source-receivers domain */
/* 3-half-offset-domain */
/*************************** wave ***************************/
hsx=1;mm=4;npd=20;_Circle_=15;
/******************** observation system ********************/
favg=20; pfac=1000.0;
nx=1801; dx=10.0;
nz=862; dz=5.0;
tmax=6.5;
dt=0.5;//ms
nt=11001;
ns_sxd=250;
fs_sxd=255;
ds_sxd=5;
zs_sxd=1;
nangle=90;
fangle=0;
dangle=1;
/*************************v****************************/
vdz=dz;vdx=dx;vnx=nx;vnz=nz;dtout=dt;
/************************FILE**************************/
FILE *fp4,*fp6,*fp7,*fp8,*fp9,*fp10,*fp11;
fp4=fopen(FN4,"wb"); /* Cal data */
fp6=fopen(FN6,"wb"); /* Migration */
fp7=fopen(FN7,"wb"); /* IS tempor migration */
fp8=fopen(FN8,"wb"); /* Adcig initial */
fp9=fopen(FN9,"wb"); /* Adcig smooth */
fp10=fopen(FN10,"wb"); /* Migration adcig stack */
if(flag_adcig==3)
fp11=fopen(FN11,"wb"); /* Image half-offset */
/************************** read_file ******************************/
vp = alloc2float(nz+2*npd,nx+2*npd); zero2float(vp,nz+2*npd,nx+2*npd);
rho = alloc2float(nz+2*npd,nx+2*npd); zero2float(rho,nz+2*npd,nx+2*npd);
epsilu = alloc2float(nz+2*npd,nx+2*npd); zero2float(epsilu,nz+2*npd,nx+2*npd);
deta = alloc2float(nz+2*npd,nx+2*npd); zero2float(deta,nz+2*npd,nx+2*npd);
read_v_e_d_r(FN1,FN2,FN3,vnx,vnz,vp,epsilu,deta,rho,npd,seismic);
pad_vv(nx,nz,npd,vp);
pad_vv(nx,nz,npd,rho);
pad_vv(nx,nz,npd,epsilu);
pad_vv(nx,nz,npd,deta);
/** determine NXS and nh **/
if(flag_cdp==1){
nxs=nxs;
nh=nxs/2+1;
}else{
nxs=nx;
nh=0;
}
vps = alloc2float(nz+2*npd,nxs+2*npd); zero2float(vps,nz+2*npd,nxs+2*npd);
rhos = alloc2float(nz+2*npd,nxs+2*npd); zero2float(rhos,nz+2*npd,nxs+2*npd);
epsilus = alloc2float(nz+2*npd,nxs+2*npd); zero2float(epsilus,nz+2*npd,nxs+2*npd);
detas = alloc2float(nz+2*npd,nxs+2*npd); zero2float(detas,nz+2*npd,nxs+2*npd);
/********************* alloc ***********************/
p_cal_x=alloc2float(nt,nxs);
p_cal_z=alloc2float(nt,nxs);
p_top_x=alloc2float(nt,nxs); p_bottom_x=alloc2float(nt,nxs);
p_top_z=alloc2float(nt,nxs); p_bottom_z=alloc2float(nt,nxs);
p_left_x=alloc2float(nt,nz); p_right_x=alloc2float(nt,nz);
p_left_z=alloc2float(nt,nz); p_right_z=alloc2float(nt,nz);
/********************* image alloc *************************/
mig_is=alloc2float(nz,nxs); zero2float(mig_is,nz,nxs);
adcig_is=alloc3float(nz,nxs,90); zero3float(adcig_is,nz,nxs,90);
/* half-offset domain image alloc */
if(flag_adcig==3)
{ Ixhz_is=alloc3float(nz,nh,nxs); zero3float(Ixhz_is,nz,nh,nxs); }
mig_ns=alloc2float(nz,nx); zero2float(mig_ns,nz,nx);
mig_ns0=alloc2float(nz,nx); zero2float(mig_ns0,nz,nx);
adcig_ns=alloc3float(nz,nx,90); zero3float(adcig_ns,nz,nx,90);
adcig_ns0=alloc3float(nz,nx,90); zero3float(adcig_ns0,nz,nx,90);
/* half-offset domain image alloc */
if(flag_adcig==3)
{ Ixhz_ns=alloc3float(nz,nh,nx); zero3float(Ixhz_ns,nz,nh,nx);
Ixhz_ns0=alloc3float(nz,nh,nx); zero3float(Ixhz_ns0,nz,nh,nx);}
adcig2d=alloc2float(nz,90); zero2float(adcig2d,nz,90);
/*******************MPI************************/
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
/*******************MPI***********************/
MPI_Barrier(MPI_COMM_WORLD);
if(myid==0)
{
printf("--------------------------------------------------------\n");
printf(" ####################################################\n");
printf(" ### Please confirm the parameter ! ###\n");
printf(" ####################################################\n");
printf(" ### ###\n");
printf(" ### mm=%d, wtype=%d, hsx=%d, flag_mu=%d\n",mm,wtype,hsx,flag_mu);
printf(" ###\n");
printf(" ### nx=vnx=%3d, dx=vdx=%.1f\n",nx,dx);
printf(" ### nz=vnz=%3d, dz=vdz=%.1f\n",nz,dz);
printf(" ###\n");
printf(" ### npd=%3d, favg=%.1f, pfac=%.1f\n",npd,favg,pfac);
printf(" ### tmax=%.2f(s), dt=%.2f(ms), nt=%d\n",tmax,dt,nt);
printf(" ###\n");
printf(" ### ns=%3d\n",ns_sxd);
printf(" ### fs=%3d\n",fs_sxd);
printf(" ### ds=%3d\n",ds_sxd);
printf(" ### zs=%3d\n",zs_sxd);
printf(" ###\n");
printf(" ### _Circle_=%3d\n",_Circle_);
printf(" ###\n");
printf(" ### numprocs= %2d\n",numprocs);
printf(" ### ###\n");
printf(" ####################################################\n");
//system("pause");
}if( ( flag_cdp==1 ) && ( nxnx ) ) ){
if(myid==0)
{
printf("\n\n\n");
printf(" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf(" $$$ Receivers location out of model boundary ! $$$\n");
printf(" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");printf("\n\n\n");
}
exit(0);
}
/************************IS Loop start**************************/
/************************IS Loop start**************************/
for(is=1+myid;is<=ns_sxd;is+=numprocs)
{
if(myid==0)
{
printf("--------------------------------------------------------\n");
printf("--------------------------------------------------------\n");
printf("--- IS========%d \n",is);
printf("--- The forward is start ! \n");
}
zero2float(p_cal_x,nt,nxs); zero2float(p_cal_z,nt,nxs);
zero2float(p_top_x,nt,nxs); zero2float(p_bottom_x,nt,nxs);
zero2float(p_top_z,nt,nxs); zero2float(p_bottom_z,nt,nxs);
zero2float(p_left_x,nt,nz); zero2float(p_right_x,nt,nz);
zero2float(p_left_z,nt,nz); zero2float(p_right_z,nt,nz);
/* determine IS vp,rho,deta,epsilu */
if(flag_cdp==1){
k=fs_sxd+(is-1)*ds_sxd;
for(i=k-nxs/2+npd;i<=k+nxs/2+npd;i++)
for(j=npd;jp_obs */
mm,wtype,hsx,myid,mig_is,mig_ns0,adcig_is,adcig_ns0,Ixhz_is,Ixhz_ns0,nh,
flag_snap,seismic,flag_adcig);
/**************** output tempor migration **************/
fseek(fp7,(is-1)*nxs*nz*4L,0);
for(i=0;i=0;it--)
{
if(it%100==0&&myid==0)printf("--- RTM is===%d it===%d\n",is,it);
/************************ construction waveform start *************************/
for(i=0;i=-1&&a1<=1)
{
a2=0.5*acosf(a1)*180/pi;
ia=(int)(a2/1.0);
if(ia==90)ia-=1;
}
/*############ source-receivers adcig ############*///imageing is very bad, pass this method.
}else if(flag_adcig==2){
sx=-s_txx0[i][j]*s_u0[i][j];
sz=-s_tzz0[i][j]*s_w0[i][j];
gx= g_txx0[i][j]*g_u0[i][j];
gz= g_tzz0[i][j]*g_w0[i][j];
b1=sqrtf(sx*sx+sz*sz);
b2=sqrtf(gx*gx+gz*gz);
sz=sx/b1;
gz=gx/b2;
ia=0;
if(sz>=-1&&sz<=1&&gz>=-1&&gz<=1)
{
a2=0.5*( asinf(sz) + asinf(gz) )*180/pi;
ia=(int)(a2/1.0);
if(ia<0)ia=-1*ia;
if(ia==90)ia-=1;
}
}
/*############ half-offset domain adcig ############*///this method is very compelicated, pass this method.
else if(flag_adcig==3){
if(flag_cdp==1){/* both sides */
for(ih=-nh/2;ih0 && (i+ih-npd)>0 && (i-ih-npd)0 loop end
/************************* is stack to ns **************************/
for(i=npd;inx){
printf("###########################\n");
printf("#Shot location(%f) >> nx(%d)\n",fs,nx);
printf("###########################\n");
exit(0);
}
if(t<=2*tdelay)
{
source=get_wavelet(ts,favg,wtype);
ixs = (int)(fs+0.5)+npd-1;
izs = (int)(zsn+0.5)+npd-1;
for(j=izs-3;j<=izs+3;j++)
{
for(i=ixs-3;i<=ixs+3;i++)
{
x=i-ixs;z=j-izs;
s[i][j]=pfac*source*exp(-z*z-x*x);
}
}
}
}
/**********************************func**************************************/
float get_wavelet(float ts,float favg,int wtype)
{
float x,xx,source;
source=0.0;
if(wtype==1)//ricker wavelet
{
x=favg*ts;
xx=x*x;
source=(1-2*pi*pi*(xx))*exp(-(pi*pi*xx));
}
else if(wtype==2)//derivative of gaussian
{
x=(-4)*favg*favg*pi*pi/log(0.1);
source=(-2)*pi*pi*ts*exp(-x*ts*ts);
}
else if(wtype==3)//derivative of gaussian
{
x=(-1)*favg*favg*pi*pi/log(0.1);
source=exp(-x*ts*ts);
}
return (source);
}
/**************************************func******************************************/
void update_vel(int nx,int nz,int npd,int mm,float dt,float dx,float dz,
float **u0,float **w0,float **txx0,float **tzz0,
float **u1,float **w1,float **txx1,float **tzz1,
float **rho,float c[],float *coffx1,float *coffx2,float *coffz1,float *coffz2)
{
int ii,i,j,im;
float dtxx,dtxz,dtx,dtz,xx,zz;
dtx=dt/dx;
dtz=dt/dz;
for(j=mm;j<=(2*npd+nz-mm-1);j++)
{
for(i=mm;i<=(2*npd+nx-mm-1);i++)
{
xx=0.0;
zz=0.0;
for(im=0;imvp[i][j]) vpmin=vp[i][j];
}
}
d0=3.0*vpmax*log(100000.0)/(2.0*npd*dx);
if(dx error!\n",FN1);
if((fp2=fopen(FN2,"rb"))==NULL)printf("Open <%s> error!\n",FN2);
if((fp3=fopen(FN3,"rb"))==NULL)printf("Open <%s> error!\n",FN3);
rewind(fp1);
rewind(fp2);
rewind(fp3);
for(i=npd;i>8)&0xff) | ((*tni2&0xff)<<8));
}
void swap_u_short_2(unsigned short *tni2)
/**************************************************************************
swap_u_short_2 swap an unsigned short integer
***************************************************************************/
{
*tni2=(((*tni2>>8)&0xff) | ((*tni2&0xff)<<8));
}
void swap_int_4(int *tni4)
/**************************************************************************
swap_int_4 swap a 4 byte integer
***************************************************************************/
{
*tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |
((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));
}
void swap_u_int_4(unsigned int *tni4)
/**************************************************************************
swap_u_int_4 swap an unsigned integer
***************************************************************************/
{
*tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |
((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));
}
void swap_long_4(long *tni4)
/**************************************************************************
swap_long_4 swap a long integer
***************************************************************************/
{
*tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |
((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));
}
void swap_u_long_4(unsigned long *tni4)
/**************************************************************************
swap_u_long_4 swap an unsigned long integer
***************************************************************************/
{
*tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |
((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));
}
void swap_float_4(float *tnf4)
/**************************************************************************
swap_float_4 swap a float
***************************************************************************/
{
int *tni4=(int *)tnf4;
*tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |
((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));
}
void swap_double_8(double *tndd8)
/**************************************************************************
swap_double_8 swap a double
***************************************************************************/
{
char *tnd8=(char *)tndd8;
char tnc;
tnc= *tnd8;
*tnd8= *(tnd8+7);
*(tnd8+7)=tnc;
tnc= *(tnd8+1);
*(tnd8+1)= *(tnd8+6);
*(tnd8+6)=tnc;
tnc= *(tnd8+2);
*(tnd8+2)= *(tnd8+5);
*(tnd8+5)=tnc;
tnc= *(tnd8+3);
*(tnd8+3)= *(tnd8+4);
*(tnd8+4)=tnc;
}
/*************** SU header conversion ****************/
void swaphval(segy *tr, int index)
{
register char *tp= (char *) tr;
switch(*(hdr[index].type)) {
case 'h': swap_short_2((short*)(tp + hdr[index].offs));
break;
case 'u': swap_u_short_2((unsigned short*)(tp + hdr[index].offs));
break;
case 'i': swap_int_4((int*)(tp + hdr[index].offs));
break;
case 'p': swap_u_int_4((unsigned int*)(tp + hdr[index].offs));
break;
case 'l': swap_long_4((long*)(tp + hdr[index].offs));
break;
case 'v': swap_u_long_4((unsigned long*)(tp + hdr[index].offs));
break;
case 'f': swap_float_4((float*)(tp + hdr[index].offs));
break;
case 'd': swap_double_8((double*)(tp + hdr[index].offs));
break;
default: err("%s: %s: unsupported data type", __FILE__, __LINE__);
break;
}
}
仅供参考、学习。