程序运行结果没出数据,是不是因为没建接受数据的文件夹?
/*dA/dt-s*dA/dx=a*d2A/dx2+b*A-(c*|A|2-|A|4+d*|B|2)A
dB/dt-s*dB/dx=a*d2B/dx2+b*B-(c*|B|2-|B|4+d*|A|2)B
(subcritical)ai=bi=ci=di=ei=0
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.14159265 /*shokisettei*/
#define OMG 2.
#define NL 200000
#define NT 1000
#define NS 100
#define AR 1.0
#define AI 0.0
#define BR 1.0
#define BI 0.0
#define CR 1.0
#define CI 2.0
#define DR 1.0
#define DI 0.0
#define ER 1.0
#define EI 0.0
#define MR -0.06
#define MI 0.0
#define NR -0.06
#define NI 0.0
#define S 0.6
#define DEE 2.0
int M,s=200000;
double EPS;
double u0,v0,w0,z0;
double u[1000],v[1000],w[1000],z[1000];
double u2[1000],v2[1000],w2[1000],z2[1000];
double DX=2.0/10.0;
double DT=1.0/100.0;
double D2,D,K,DX2;
#define L 20
int i,l,m,n=0;
char fname[6][20];
FILE *f[6],*fp;
double keisan();
double kyoukai();
void shokijouken();
main (int argc,char*argv[]) /*input EPS finename*/
{
if((argc!=2)&&(argc!=3)){
fprintf(stderr,"usage:%sEPS[filename]/n",argv[0]);
exit(1);
}
EPS=atof(argv[1]);
M=(L*5)+1;
sprintf(fname[0],"g%2.2g1",EPS);
sprintf(fname[1],"g%2.2g2",EPS);
sprintf(fname[2],"f%2.2g1",EPS);
sprintf(fname[3],"f%2.2g2",EPS);
sprintf(fname[4],"f%2.2g",EPS);
sprintf(fname[5],"s%2.2g",EPS);
for(i=0;i<=4;i++){
if((f[i]=fopen(fname[i],"w"))==NULL){ /*file open*/
printf("Cannot open file %s¥n",fname[i]);
exit(1);
}
}
shokijouken(argc,argv[2]);
for(n=1;n<=NL;n++){/*keisann 翻译成汉语是计算*/
u2[0]=keisan(u0,u[0],u[1],v0,v[0],v[1],w[0],z[0],-1,-1);
v2[0]=keisan(v0,v[0],v[1],u0,u[0],u[1],z[0],w[0],1,-1);
w2[0]=keisan(w0,w[0],w[1],z0,z[0],z[1],u[0],v[0],-1,1);
z2[0]=keisan(z0,z[0],z[1],w0,w[0],w[1],v[0],u[0],1,1);
for (i=1;i<=M-1;i++){
u2[i]=keisan(u[i-1],u[i],u[i+1],v[i-1],v[i],v[i+1],w[i],z[i],-1,-1);
v2[i]=keisan(v[i-1],v[i],v[i+1],u[i-1],u[i],u[i+1],z[i],w[i],1,-1);
w2[i]=keisan(w[i-1],w[i],w[i+1],z[i-1],z[i],z[i+1],u[i],v[i],-1,1);
z2[i]=keisan(z[i-1],z[i],z[i+1],w[i-1],w[i],w[i+1],v[i],u[i],1,1);
}
for(i=0;i<=M-1;i++)
u[i]=u2[i];
v[i]=v2[i];
w[i]=w2[i];
z[i]=z2[i];
}
/*kyoukaijoukenn翻译成汉语是边界条件*/
u[0]=kyoukai(u[1],u0,v[1],v0,w[1],w0,z[1],z0,-1);
v[0]=kyoukai(v[1],v0,u[1],u0,z[1],z0,w[1],w0,1);
w[0]=kyoukai(w[1],w0,z[1],z0,u[1],u0,v[1],v0,1);
z[0]=kyoukai(z[1],z0,w[1],w0,v[1],v0,u[1],u0,-1);
u[M-1]=kyoukai(u[M],u[M-2],v[M],v[M-2],w[M],w[M-2],z[M],z[M-2],-1);
v[M-1]=kyoukai(v[M],v[M-2],u[M],u[M-2],z[M],z[M-2],w[M],w[M-2],1);
w[M-1]=kyoukai(w[M],w[M-2],z[M],z[M-2],u[M],u[M-2],v[M],v[M-2],1);
z[M-1]=kyoukai(z[M],z[M-2],w[M],w[M-2],v[M],v[M-2],u[M],u[M-2],-1);
if(n%NS==0){/*file ni kakikomi翻译成汉语是在这个文件里写进去*/
l=(M-1)/2;
fprintf(f[0],"%d%e/n",n,sqrt(u[l]*u[l]+v[l]*v[l]));
fprintf(f[1],"%d%e/n",n,sqrt(w[l]*w[l]+z[l]*z[l]));
}
if(n%NT==0)
m=(M-1)/100;
K=2*PI/sqrt(2);
for(i=0;i<=M-1;i+=m){
fprintf(f[2],"%f%d%e/n",i*DX,n,sqrt(u[i]*u[i]+v[i]*v[i]));
fprintf(f[3],"%f%d%e/n",i*DX,n,sqrt(w[i]*w[i]+z[i]*z[i]));
fprintf(f[4],"%f%d%e/n",i*DX,n,2*u[i]*cos(K*DX*i-OMG*DT*n)
-2*v[i]*sin(K*DX*i-OMG*DT*n)
+2*w[i]*cos(K*DX*i+OMG*DT*n)
+2*z[i]*sin(K*DX*i+OMG*DT*n));
{
fprintf(f[2],"/n");
fprintf(f[3],"/n");
fprintf(f[4],"/n");
}
}
for(i=0;i<=4;i++) fclose(f[i]);
shokijouken(argc,argv[2]);
for(n=1;n<=s;n++){/*keisann*/
u2[0]=keisan(u0,u[0],u[1],v0,v[0],v[1],w[0],z[0],-1,-1);
v2[0]=keisan(v0,v[0],v[1],u0,u[0],u[1],z[0],w[0],1,-1);
w2[0]=keisan(w0,w[0],w[1],z0,z[0],z[1],u[0],v[0],-1,1);
z2[0]=keisan(z0,z[0],z[1],w0,w[0],w[1],v[0],u[0],1,1);
for (i=1;i<=M-1;i++){
u2[i]=keisan(u[i-1],u[i],u[i+1],v[i-1],v[i],v[i+1],w[i],z[i],-1,-1);
v2[i]=keisan(v[i-1],v[i],v[i+1],u[i-1],u[i],u[i+1],z[i],w[i],1,-1);
w2[i]=keisan(w[i-1],w[i],w[i+1],z[i-1],z[i],z[i+1],u[i],v[i],-1,1);
z2[i]=keisan(z[i-1],z[i],z[i+1],w[i-1],w[i],w[i+1],v[i],u[i],1,1);
}
for(i=0;i<=M-1;i++){
u[i]=u2[i];
v[i]=v2[i];
w[i]=w2[i];
z[i]=z2[i];
}
/*kyoukaijoukenn边界条件*/
u[0]=kyoukai(u[1],u0,v[1],v0,w[1],w0,z[1],z0,-1);
v[0]=kyoukai(v[1],v0,u[1],u0,z[1],z0,w[1],w0,1);
w[0]=kyoukai(w[1],w0,z[1],z0,u[1],u0,v[1],v0,1);
z[0]=kyoukai(z[1],z0,w[1],w0,v[1],v0,u[1],u0,-1);
u[M-1]=kyoukai(u[M],u[M-2],v[M],v[M-2],w[M],w[M-2],z[M],z[M-2],-1);
v[M-1]=kyoukai(v[M],v[M-2],u[M],u[M-2],z[M],z[M-2],w[M],w[M-2],1);
w[M-1]=kyoukai(w[M],w[M-2],z[M],z[M-2],u[M],u[M-2],v[M],v[M-2],1);
z[M-1]=kyoukai(z[M],z[M-2],w[M],w[M-2],v[M],v[M-2],u[M],u[M-2],-1);
}
if((f[5]=fopen(fname[5],"wb"))==NULL){
printf("Cannot open file %s/n",fname[5]);
exit(1);
}
if((fwrite(&u0,sizeof(u0),1,f[5]))!=1){
fprintf(stderr,"fwrite error%s/n",fname[5]);
exit(1);
}
if(fwrite(u,sizeof(double),M+1,f[5])!=102){
fprintf(stderr,"fwrite error%s/n",fname[5]);
exit(1);
}
if((fwrite(&v0,sizeof(v0),1,f[5]))!=1){
fprintf(stderr,"fwrite error%s/n",fname[5]);
exit(1);
}
if((fwrite(v,sizeof(double),M+1,f[5]))!=102){
fprintf(stderr,"fwrite error%s/n",fname[5]);
exit(1);
}
if((fwrite(&w0,sizeof(w0),1,f[5]))!=1){
fprintf(stderr,"fwrite error%s/n",fname[5]);
exit(1);
}
if((fwrite(w,sizeof(w0),M+1,f[5]))!=102){
fprintf(stderr,"fwrite error%s/n",fname[5]);
exit(1);
}
if((fwrite(&z0,sizeof(z0),1,f[5]))!=1){
fprintf(stderr,"fwrite error%s/n",fname[5]);
exit(1);
}
if((fwrite(z,sizeof(double),M+1,f[5]))!=102){
fprintf(stderr,"fwrite error%s/n",fname[5]);
exit(1);
}
fclose(f[5]);
}
double u0;
void shokijouken(int argc,char*argv2)
{
double u0;
if (argc==2){
u0=1.e-10*(1/(0.5*sqrt(PI)))*exp(-(1/(0.5*0.5))*(DX*(-1-M/2))*(DX*(-1-M/2)));
v0=w0=z0=0;
for(i=0;i<=M;i++)
u[i]=1.e-10*(1/(0.5*sqrt(PI)))*exp(-(1/(0.5*0.5))*(DX*(i-M/2))*(DX*(i-M/2)));
v[i]=w[i]=z[i]=0;
}
else{/*argc==3*/
if((fp=fopen(argv2,"rb"))==NULL){
printf("Cannot open file %s/n",*argv2);
exit(1);
}
if((fread(&u0,sizeof(u0),1,fp))!=1){
fprintf(stderr,"fread error %s/n",argv2);
exit(1);
}
if((fread(u,sizeof(double),M+1,fp))!=102){
fprintf(stderr,"fread error %s/n",argv2);
exit(1);
}
if((fread(&v0,sizeof(v0),1,fp))!=1){
fprintf(stderr,"fread error %s/n",argv2);
exit(1);
}
if((fread(v,sizeof(double),M+1,fp))!=102){
fprintf(stderr,"fread error %s/n",argv2);
exit(1);
}
if((fread(&w0,sizeof(w0),1,fp))!=1){
fprintf(stderr,"fread error %s/n",argv2);
exit(1);
}
if((fread(w,sizeof(double),M+1,fp))!=102){
fprintf(stderr,"fread error %s/n",argv2);
exit(1);
}
if((fread(&z0,sizeof(z0),1,fp))!=1){
fprintf(stderr,"fread error %s/n",argv2);
exit(1);
}
if((fread(z,sizeof(double),M+1,fp))!=102){
fprintf(stderr,"fread error %s/n",argv2);
exit(1);
}
fclose(fp);
}
}
/*keisann计算*/
double keisan(double u_x,double u,double ux,double v_x,double v,double vx,double w,double z,int a, int b)
{
D2=DT/(DX*DX);
D=DT/(2*DX);
return u+D2*(AR*(ux-2*u+u_x)+a*AI*(vx-2*v+v_x))+DT*(EPS*(BR*u+a*BI*v)+(CR*u+a*CI*v)*(u*u+v*v)-DEE*(DR*u+a*DI*v)*(w*w+z*z)-(ER*u+a*EI*v)*(u*u+v*v)*(u*u+v*v))+b*D*S*(ux-u_x);
}
/*kyoukaijoukenn边界条件*/
double kyoukai(double u1,double u0,double v1,double v0,double w1,double w0,double z1,double z0,int a)
{
DX2=2*DX;
return (MR*(u1-u0)+a*MI*(v1-v0)+NR*(w1-w0)+a*NI*(z1-z0))/DX2;
system ("pause");
}