X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fnlsop.git;a=blobdiff_plain;f=nlsop.c;h=030db9f110d83648ed29f714b6c1355c523339b4;hp=4eb641085d8f03b5d6b51d25ac01917dc12bf48a;hb=ac3628afff01679dfa9da69cf010764970e40be7;hpb=c2cf344605eb715f5b6524b1a05317ff319f7dd7 diff --git a/nlsop.c b/nlsop.c index 4eb6410..030db9f 100644 --- a/nlsop.c +++ b/nlsop.c @@ -56,15 +56,15 @@ int usage(void) return 1; } -int process_cell(3d_lattice *3d_l,u32 x,u32 y,u32 z,int r,double a,double b,int *t_c) +int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,int r,double a,double b,int *t_c) { unsigned char *thiz; int *conc; int i,j; double p; - thiz=3d_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; - conc=3d_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; + thiz=d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; + conc=d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; p=b*URAND_MAX; for(i=-r;i<=r;i++) { @@ -97,7 +97,7 @@ int process_cell(3d_lattice *3d_l,u32 x,u32 y,u32 z,int r,double a,double b,int return 1; } -int distrib_c(3d_lattice *3d_l,int t_c,double a,double b) +int distrib_c(d3_lattice *d3_l,int t_c,double a,double b) { int i,j,k,total,area,sum; int temp,left; @@ -135,7 +135,7 @@ int distrib_c(3d_lattice *3d_l,int t_c,double a,double b) } } } - left=(((i+1)*a+b)*t_c/sum)%area_h[i]; + left=(int)(((i+1)*a+b)*t_c/sum)%area_h[i]; while(left) { x=get_rand(d3_l->max_x); @@ -164,6 +164,76 @@ int distrib_c(3d_lattice *3d_l,int t_c,double a,double b) return 1; } +int save_to_file(char *sf,d3_lattice *d3_l) +{ + int sf_fd,c; + + if((sf_fd=open(sf,O_WRONLY|O_CREAT))<0) + { + puts("cannot open save file"); + return -1; + } + if(write(sf_fd,d3_l,sizeof(d3_lattice))max_x*d3_l->max_y*d3_l->max_z; + if(write(sf_fd,d3_l->status,c*sizeof(unsigned char))extra,c*sizeof(int))max_x*d3_l->max_y*d3_l->max_z; + if((d3_l->status=(unsigned char*)malloc(c*sizeof(unsigned char)))==NULL) + { + puts("cannot allocate status buffer"); + return -1; + } + if((d3_l->extra=(int *)malloc(c*sizeof(int)))==NULL) + { + puts("cannot allocate concentration buffer"); + return -1; + } + if(read(lf_fd,d3_l->status,c*sizeof(unsigned char))extra,c*sizeof(int))