X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fnlsop.git;a=blobdiff_plain;f=nlsop_client.c;h=beeda9f8daedf4982e5d31c7a841392b8c77d5d8;hp=5a25f4e6319a32de49c6177309100667d82bfed5;hb=HEAD;hpb=90046359b354455255f3b4aaf69de7e987d33e9b diff --git a/nlsop_client.c b/nlsop_client.c index 5a25f4e..beeda9f 100644 --- a/nlsop_client.c +++ b/nlsop_client.c @@ -59,11 +59,15 @@ char p_file[MAX_CHARS]; char n_e_file[MAX_CHARS]; char r_file[MAX_CHARS]; +char s_file[MAX_CHARS]; +int start_fd; t_net *gnet; d3_lattice *gd3_l; info *gmy_info; int *gi; unsigned char dc; +unsigned char shut_down; +double c_ratio; int get_data_and_calc(t_event *event,void *allineed); int nop(t_event *event,void *allineed); @@ -71,7 +75,7 @@ int nop(t_event *event,void *allineed); int usage(char *prog) { puts("usage:"); - printf("%s -i ip -p port -r/P/n random/profile/neloss file\n",prog); + printf("%s -i ip -p port -r/P/n/s random/profile/neloss/start file\n",prog); return 1; } @@ -101,6 +105,47 @@ int sputter(d3_lattice *d3_l) return 1; } +int get_c_ratio(double *c_ratio,char *pfile,info *my_info,d3_lattice *d3_l) +{ + double all,a,b,d; + int i,k; + int p_fd; + unsigned char buf[32]; + char *p; + unsigned char c; + + if((p_fd=open(pfile,O_RDONLY))<0) + { + puts("cannot open profile file"); + return -1; + } + k=1; + d=0; + all=0; + while(k) + { + for(i=0;i<32;i++) + { + k=read(p_fd,&c,1); + buf[i]=c; + if(c=='\n') break; + } + if(k) + { + p=strtok(buf," "); + a=atof(p)/10; /* nm */ + p=strtok(NULL," "); + b=atof(p); + if(a<=d3_l->max_z*CELL_LENGTH) d+=b; + all+=b; + } + } + *c_ratio=d/all; + close(p_fd); + + return 1; +} + int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,info *my_info,u32 nel_z) { unsigned char *thiz; @@ -111,7 +156,8 @@ int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,info *my_info,u32 nel_z) 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=my_info->b*nel_z; + //p=my_info->b*nel_z; // energieuebertrag prop zu nukl. bk + p=my_info->b*URAND_MAX; // konstanter energieuebertrag for(i=-(my_info->range);i<=my_info->range;i++) { for(j=-(my_info->range);j<=my_info->range;j++) @@ -124,24 +170,28 @@ int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,info *my_info,u32 nel_z) } } p+=*conc*my_info->c*URAND_MAX; - if(!(*thiz&AMORPH)) - { - if(get_rand(URAND_MAX)<=p) MAKE_AMORPH(thiz); - } else - { - /* assume 1-p probability */ - /* also look for neighbours ! */ - q=(URAND_MAX-p)>0?URAND_MAX-p:0; - j=0; - j+=(*(d3_l->status+((x+d3_l->max_x+1)%d3_l->max_x)+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; - j+=(*(d3_l->status+((x+d3_l->max_x-1)%d3_l->max_x)+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; - j+=(*(d3_l->status+x+((y+1+d3_l->max_y)%d3_l->max_y)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; - j+=(*(d3_l->status+x+((y-1+d3_l->max_y)%d3_l->max_y)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; - j+=(*(d3_l->status+x+y*d3_l->max_x+((z+1+d3_l->max_z)%d3_l->max_z)*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; - j+=(*(d3_l->status+x+y*d3_l->max_x+((z-1+d3_l->max_z)%d3_l->max_z)*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; - - p+=((q/6)*j); - if(get_rand(URAND_MAX)>p) MAKE_CRYST(thiz); + if(p>=URAND_MAX) MAKE_AMORPH(thiz); + else { + if(!(*thiz&AMORPH)) { + if(get_rand(URAND_MAX)<=p) MAKE_AMORPH(thiz); + } + else { + /* assume 1-p probability */ + /* also look for neighbours ! */ + q=(URAND_MAX-p)>0?URAND_MAX-p:0; + j=0; + j+=(*(d3_l->status+((x+d3_l->max_x+1)%d3_l->max_x)+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + j+=(*(d3_l->status+((x+d3_l->max_x-1)%d3_l->max_x)+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + j+=(*(d3_l->status+x+((y+1+d3_l->max_y)%d3_l->max_y)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + j+=(*(d3_l->status+x+((y-1+d3_l->max_y)%d3_l->max_y)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + j+=(*(d3_l->status+x+y*d3_l->max_x+((z+1+d3_l->max_z)%d3_l->max_z)*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + j+=(*(d3_l->status+x+y*d3_l->max_x+((z-1+d3_l->max_z)%d3_l->max_z)*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + + p+=((q/6)*j); + if(p<=URAND_MAX) { + if(get_rand(URAND_MAX)>p) MAKE_CRYST(thiz); + } + } } return 1; @@ -155,11 +205,13 @@ int distrib_c(d3_lattice *d3_l,info *my_info,int step,u32 rj_m,u32 *rj_g) int carry; /* put one c ion somewhere in the lattice */ - x=get_rand(d3_l->max_x); - y=get_rand(d3_l->max_y); - z=get_rand_reject(d3_l->max_z,rj_m,rj_g); - *(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)+=1; - (my_info->cc)++; + if(c_ratio*step<=my_info->cc) { + x=get_rand(d3_l->max_x); + y=get_rand(d3_l->max_y); + z=get_rand_reject(d3_l->max_z,rj_m,rj_g); + *(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)+=1; + (my_info->cc)++; + } if(step%my_info->diff_rate==0) { @@ -305,6 +357,7 @@ u32 get_reject_graph(info *my_info,d3_lattice *d3_l,char *file,u32 *graph) { void send_data(int signum) { int c; + unsigned char ack=DATA_OK; c=gd3_l->max_x*gd3_l->max_y*gd3_l->max_z; @@ -314,6 +367,9 @@ void send_data(int signum) { network_send_chan(gnet,0,gd3_l->status,c*sizeof(unsigned char)); network_send_chan(gnet,0,(unsigned char *)gd3_l->extra,c*sizeof(int)); network_send_chan(gnet,0,(unsigned char *)gi,sizeof(int)); + network_send_chan(gnet,0,&ack,sizeof(unsigned char)); + + if(dc==DC_QUIT) shut_down=1; } @@ -338,6 +394,8 @@ int main(int argc,char **argv) strcpy(p_file,IMP_PROFILE); strcpy(n_e_file,NEL_PROFILE); strcpy(r_file,""); + strcpy(s_file,""); + start_fd=0; port=1025; /* parse/check argv */ @@ -362,6 +420,9 @@ int main(int argc,char **argv) case 'p': port=atoi(argv[++i]); break; + case 's': + strcpy(s_file,argv[++i]); + break; default: usage(argv[0]); return -1; @@ -373,6 +434,13 @@ int main(int argc,char **argv) return -1; } + /* try a file to start from */ + if(strcmp(s_file,"")) { + start_fd=open(s_file,O_RDONLY); + if(start_fd>0) printf("using %s as a starting file ...\n",s_file); + else printf("errors opening %s!\n",s_file); + } + /* event init */ event_init(&event,1); event_set_timeout(&event,0,0); @@ -395,6 +463,9 @@ int main(int argc,char **argv) printf("idle, waiting for jobs ...\n"); event_start(&event,NULL,get_data_and_calc,nop); + network_shutdown(&net); + if(start_fd>0) close(start_fd); + return 1; } @@ -416,6 +487,7 @@ int get_data_and_calc(t_event *event,void *allineed) { u32 x_c,y_c,z_c; int i,j; int c_step; + unsigned char do_sputter; unsigned char data; t_net *net; @@ -423,12 +495,15 @@ int get_data_and_calc(t_event *event,void *allineed) { c_step=0; ne_max=0; ip_max=0; + do_sputter=1; + c_ratio=0; net=gnet; gd3_l=&d3_l; gmy_info=&my_info; gi=&i; dc=0; + shut_down=0; printf("got a new job ...\n"); @@ -463,6 +538,36 @@ int get_data_and_calc(t_event *event,void *allineed) { sizeof(int)); network_send(net->connection[0].fd,&data,sizeof(unsigned char)); } + if(c_step==0) { + printf("important: clear status/conc data!\n"); + memset(d3_l.status,0,j*sizeof(unsigned char)); + memset(d3_l.extra,0,j*sizeof(int)); + } + /* check for file to start from ... */ + if(start_fd>0) { + printf("starting from a save file!\n"); + unsigned char *nullbuf; + nullbuf=(unsigned char *)malloc(sizeof(d3_lattice)); + if(read(start_fd,nullbuf,sizeof(d3_lattice))!=sizeof(d3_lattice)) { + printf("read failed (start file d3l)\n"); + return -1; + } + free(nullbuf); + nullbuf=(unsigned char *)malloc(sizeof(info)); + if(read(start_fd,nullbuf,sizeof(info))!=sizeof(info)) { + printf("read failed (start file info)\n"); + return -1; + } + free(nullbuf); + if(read(start_fd,d3_l.status,j*sizeof(unsigned char))!=j*sizeof(unsigned char)) { + printf("read failed (start file status)\n"); + return -1; + } + if(read(start_fd,d3_l.extra,j*sizeof(int))!=j*sizeof(int)) { + printf("read failed (start file extra)\n"); + return -1; + } + } } else { printf("unknown instruction, restarting ...\n"); @@ -507,7 +612,7 @@ int get_data_and_calc(t_event *event,void *allineed) { /* this should be obsolete - z is high enough - we check now! */ if(c_profile[d3_l.max_z-1]!=0) { printf("max_z (%d) too small - sputtering not possible\n",d3_l.max_z); - return -1; + do_sputter=0; } /* sputtering really possible ?*/ @@ -515,6 +620,12 @@ int get_data_and_calc(t_event *event,void *allineed) { printf("warning: max_z (%d) too small, there may be amorphous volumes\n", d3_l.max_z); + /* maybe we need a ratio! */ + if(!do_sputter) { + get_c_ratio(&c_ratio,p_file,&my_info,&d3_l); + printf("calculated c ratio: %f\n",c_ratio); + } + /* * start of simulation */ @@ -524,11 +635,8 @@ int get_data_and_calc(t_event *event,void *allineed) { for(j=0;j