#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define PI 3.1415926
#define FM 30.0
#define R 3
int main()
{
/************声明变量****************/
FILE *fp,*fp1;
int i, j,add=100, k,k1, Xn=300+add,Zn=300+add,Tn=1000,l;//add为向外扩充的网格。
int t,t0=60,p;
double dt=0.0005,dh=5.0,le,q1,temp,A;
double *w,**v,**u1,**u2,**u3,**u4,**u_1,**u_2,**u_3,**u_4;
/************动态数组开辟****************/
w=(double*)malloc(sizeof(double)*Tn);
u1=(double**)malloc(sizeof(double*)*Xn);
u2=(double**)malloc(sizeof(double*)*Xn);
u3=(double**)malloc(sizeof(double*)*Xn);
u4=(double**)malloc(sizeof(double*)*Xn);
v=(double**)malloc(sizeof(double*)*Xn);
u_1=(double**)malloc(sizeof(double*)*Xn);
u_2=(double**)malloc(sizeof(double*)*Xn);
u_3=(double**)malloc(sizeof(double*)*Xn);
u_4=(double**)malloc(sizeof(double*)*Xn);
for(i=0;i<Xn;i++)
{
u1[i] = (double*)malloc(sizeof(double)*Zn);
u2[i] = (double*)malloc(sizeof(double)*Zn);
u3[i] = (double*)malloc(sizeof(double)*Zn);
u4[i] = (double*)malloc(sizeof(double)*Tn);
u_1[i] = (double*)malloc(sizeof(double)*Zn);
u_2[i] = (double*)malloc(sizeof(double)*Zn);
u_3[i] = (double*)malloc(sizeof(double)*Zn);
u_4[i] = (double*)malloc(sizeof(double)*Tn);
v[i] = (double*)malloc(sizeof(double)*Zn);
}
printf("in put the time\n");
scanf("%d",&t);
/************子波和速度数组赋值****************/
for(k=0;k<Tn;k++)
w[k]=exp(-(2*PI*FM/R)*(2*PI*FM/R)*(k-t0)*dt*(k-t0)*dt)*cos(2*PI*FM*(k-t0)*dt);
for(i=0;i<Xn;i++)
for(j=0;j<Zn;j++)
v[i][j]=2000.0;
//*********观察多次波模型***
//for(i=0;i<Xn;i++)
// for(j=0;j<40;j++)
// v[i][j]=2000.0;
//for(i=0;i<Xn;i++)
// for(j=40;j<Zn;j++)
// v[i][j]=4000.0;
//*********三层分界模型****
for(i=0;i<Xn;i++)
for(j=100;j<Zn;j++)
v[i][j]=3000.0;
/*for(i=0;i<Xn;i++)
for(j=100;j<Zn;j++)
v[i][j]=3000.0;
//for(i=0;i<Xn;i++)
// for(j=200;j<Zn;j++)
// v[i][j]=3500.0;
//*********绕射波地层******
//for(i=0;i<Xn;i++)
// for(j=0;j<Zn;j++)
// v[i][j]=2000.0;
//for(i=148+add/2;i<152+add/2;i++)
// for(j=add/2+50;j<add/2+54;j++)
// v[i][j]=4000.0;
//*********盆地模型********
//for(i=0;i<Xn;i++)
//{
// le=-11.0/2250*(i-150)*(i-150)+160;
// for(j=ceil(le);j<Zn;j++)
// v[i][j]=3000;
//}
//***********断层**********
//for(i=0;i<Xn;i++)
// for(j=60+add/2;j<Zn;j++)
// v[i][j]=3000.0;
//for(i=120+add/2;i<Xn;i++)
// for(j=60+add/2;j<90+add/2;j++)
// v[i][j]=2000.0;
//for(i=120+add/2;i<150+add/2;i++)
//{
// temp=1*(i-add/2)-60;
// for(j=ceil(temp)+add/2;j<90+add/2;j++)
// v[i][j]=3000.0;
//}
/************波场计算****************/
for(i=0;i<Xn;i++)
{
for(j=0;j<Zn;j++)
{u1[i][j]= 0.0;
u3[i][j]= 0.0;
u2[i][j]= 0.0;
u_1[i][j]= 0.0;
u_3[i][j]= 0.0;
u_2[i][j]= 0.0;
u_4[i][j]=0.0;
}
for(j=0;j<Tn;j++)
u4[i][j]= 0.0;
}
A=dt/dh;
for(k=0;k<Tn;k++)
{
for(i=1;i<Xn-1;i++)
{
for(j=1;j<Zn-1;j++)
{
if(i==1+add/2&&j==1+add/2)//duancneg:20
p=1;
else
p=0;
u3[i][j]=(v[i][j]*dt/dh)*(v[i][j]*dt/dh)*(u2[i+1][j]+u2[i-1][j]+u2[i][j+1]+u2[i][j-1])+(2*dh*dh-4*v[i][j]*v[i][j]*dt*dt)/(dh*dh)*u2[i][j]-u1[i][j]+10*w[k]*p;
}
}
//地震记录
for(i=0;i<Xn-1;i++)
u4[i][k]=10*u3[i][1+add/2];//duancneg:25
for(i=0;i<Xn;i++)
{
for(j=0;j<Zn;j++)
{
u1[i][j]=u2[i][j];
u2[i][j]=u3[i][j];
}
}
if(k%2==0)
printf("T=%d\n",k);
if(t==k)
break;
}
//逆时延拓与正演.............................
for(i=0;i<Xn;i++)
{
for(j=0;j<Zn;j++)
{u1[i][j]= 0.0;
u3[i][j]= 0.0;
u2[i][j]= 0.0;
u_1[i][j]= 0.0;
u_3[i][j]= 0.0;
u_2[i][j]= 0.0;
u_4[i][j]=0.0;
}
}
for(k=0,k1=t;k1>=0;k1--,k++)
{
for(i=1;i<Xn-1;i++)
{
for(j=1;j<Zn-1;j++)
{
u_1[i][j]=(v[i][j]*dt/dh)*(v[i][j]*dt/dh)*(u_2[i+1][j]+u_2[i-1][j]+u_2[i][j+1]+u_2[i][j-1])+(2*dh*dh-4*v[i][j]*v[i][j]*dt*dt)/(dh*dh)*u_2[i][j]-u_3[i][j]+u4[i][k1];
if(i==1+add/2&&j==1+add/2)
p=1;
else
p=0;
u3[i][j]=(v[i][j]*dt/dh)*(v[i][j]*dt/dh)*(u2[i+1][j]+u2[i-1][j]+u2[i][j+1]+u2[i][j-1])+(2*dh*dh-4*v[i][j]*v[i][j]*dt*dt)/(dh*dh)*u2[i][j]-u1[i][j]+10*w[k]*p;
}
}
for(i=0;i<Xn;i++)
{
for(j=0;j<Zn;j++)
{
u_3[i][j]=u_2[i][j];
u_2[i][j]=u_1[i][j];
u1[i][j]=u2[i][j];
u2[i][j]=u3[i][j];
}
}
for(i=0;i<Xn;i++)
{
for(j=0;j<Zn;j++)
{
u_4[i][j]+=u3[i][j]*u_1[i][j];
}
}
}
/************写文件****************/
if((fp=fopen("wavefront.dat","w"))!=NULL)
{
fprintf(fp," %d\n",Xn-add);
fprintf(fp," %d\n",Zn-add);
for(i=add/2;i<Xn-add/2;i++)
for(j=add/2;j<Zn-add/2;j++)
{
fprintf(fp,"%f\n",u_4[i][j]);
}
fclose(fp);
}
if((fp1=fopen("record.dat","w"))!=NULL)
{
fprintf(fp1," %d\n",Xn-add);
fprintf(fp1," %d\n",Tn);
for(i=add/2;i<Xn-add/2;i++)
for(j=0;j<Tn;j++)
{
fprintf(fp1,"%f\n",u4[i][j]);
}
fclose(fp1);
}
free(w);
free(u1);
free(v);
free(u2);
free(u3);
free(u4);
free(u_1);
free(u_2);
free(u_3);
free(u_4);
return 0;
}
评论1