X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=nlsop.c;h=58f19f7bff7180801f1848e6a30e48ea061245f9;hb=9a424ed8a83609409d67b28890475f81581f501e;hp=9b9f8039e2a790556b7896037b1eb1a1e58b212a;hpb=c37428b4496d4854ee7bd43b45be36238625c965;p=physik%2Fnlsop.git diff --git a/nlsop.c b/nlsop.c index 9b9f803..58f19f7 100644 --- a/nlsop.c +++ b/nlsop.c @@ -130,7 +130,9 @@ int distrib_c(d3_lattice *d3_l,info *my_info,int step,double c_ratio) { x=get_rand(d3_l->max_x); y=get_rand(d3_l->max_y); + // printf("nd: %d %d\n",x,y); z=get_rand_lgp(d3_l->max_z,my_info->a_cd,my_info->b_cd); + // printf("ld: %d\n",z); *(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)+=1; (my_info->cc)++; } @@ -328,6 +330,43 @@ int calc_max_extra(d3_lattice *d3_l) return max; } +int write_ac_distr(d3_lattice *d3_l,int ac_distr) +{ + int fd,x,y,z; + int count=0,offset; + char file[16]; + + if(ac_distr==1) strcpy(file,"a.plot"); + if(ac_distr==2) strcpy(file,"c.plot"); + if(ac_distr==3) strcpy(file,"b.plot"); + + if((fd=open(file,O_WRONLY|O_CREAT))<0) + { + puts("cannot open plot file"); + return -1; + } + + for(z=0;zmax_z;z++) + { + for(x=0;xmax_x;x++) + { + for(y=0;ymax_y;y++) + { + offset=x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; + if(ac_distr==1) + if(*(d3_l->status+offset)&AMORPH) count+=*(d3_l->extra+offset); + if(ac_distr==2) + if(!(*(d3_l->status+offset)&AMORPH)) count+=*(d3_l->extra+offset); + if(ac_distr==3) count+=*(d3_l->extra+offset); + } + } + dprintf(fd,"%d %d\n",z,count); + } + close(fd); + + return 1; +} + int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z) { int fd,i,j,size=0,foo=0,end=0; @@ -655,10 +694,68 @@ int get_c_ratio(double *c_ratio,char *pfile,info *my_info,d3_lattice *d3_l) return 1; } +int get_reject_graph(info *my_info,d3_lattice *d3_l,char *file,u32 *graph) { + double a,b; + int i,j,k; + int fd; + char buf[32],*p; + unsigned char *flag; + + if((fd=open(file,O_RDONLY))<0) + { + puts("cannot open file to calculate rejection graph"); + return -1; + } + if((flag=(unsigned char *)malloc(d3_l->max_z))==NULL) + { + puts("cannot malloc flag memory for rejection graph"); + return -1; + } + memset(flag,0,d3_l->max_z); + memset(graph,0,d3_l->max_z*sizeof(u32)); + /* get fixpoints */ + k=1; + while(k) + { + for(i=0;i<32;i++) + { + k=read(fd,&buf[i],1); + if((buf[i]=='\n')||(k==0)) 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) k=0; + else + { + graph[(int)(a/CELL_LENGTH)]=(int)(URAND_MAX*b); + flag[(int)(a/CELL_LENGTH)]=1; + } + } + } + /* do (linear) interpolation here! */ + i=0; + while(imax_z) + { + a=0; + + // WEITER HIER !! + + } + + printf("%s graph:\n",file); + for(i=0;imax_z;i++) printf("%02d | %d\n",i,graph[i]); + + return 1; +} + int main(int argc,char **argv) { u32 x,y,z,x_c,y_c,z_c; - int i,j,quit,escape,switchmode,nowait,bmp; + int i,j,quit,escape,switchmode,nowait,bmp,ac_distr; int refresh,resave; int c_step; char s_file[MAX_CHARS]; @@ -696,6 +793,8 @@ int main(int argc,char **argv) #ifdef USE_DFB_API int max_extra; #endif + u32 *c_profile; + u32 *n_e_loss; d3_l.max_x=X; d3_l.max_y=Y; @@ -890,10 +989,10 @@ int main(int argc,char **argv) sprintf(s_txt,"steps: %d",my_info.steps); sprintf(dose_txt,"dose: %.2fe+17 C/cm²",my_info.steps*1.0/(d3_l.max_x*d3_l.max_y*CELL_LENGTH*CELL_LENGTH*1000)); sprintf(r_txt,"pressure range: %d",my_info.range); - sprintf(ap_txt,"a_ap: %.3f b_ap: %.3f",my_info.a_ap,my_info.b_ap); + sprintf(ap_txt,"a_ap: %.4f b_ap: %.3f",my_info.a_ap,my_info.b_ap); sprintf(el_txt,"a_el: %.3f b_el: %.3f",my_info.a_el,my_info.b_el); sprintf(cd_txt,"a_cd: %.3f b_cd: %.3f",my_info.a_cd,my_info.b_cd); - sprintf(cp_txt,"a_cp: %.4f",my_info.a_cp); + sprintf(cp_txt,"a_cp: %.5f",my_info.a_cp); sprintf(dr_ac_txt,"a/c diffusion rate: %.4f",my_info.dr_ac); if(my_info.c_diff!=0) sprintf(dr_cc_txt,"c/c diffusion rate: %.4f",my_info.dr_cc); else sprintf(dr_cc_txt,"c/c diffusion rate: none"); @@ -929,11 +1028,32 @@ int main(int argc,char **argv) if((!strcmp(l_file,""))||(c_step)) { + /* calculate ratio of c_simwindow / c_total */ if(get_c_ratio(&c_ratio,p_file,&my_info,&d3_l)!=1) { puts("failed calculating ratio"); return -1; } + /* compute graphs for random number rejection method */ + if((c_profile=(u32 *)malloc(d3_l.max_z*sizeof(unsigned int)))==NULL) + { + puts("failed allocating memory for carbon profile graph"); + return -1; + } + if((n_e_loss=(u32 *)malloc(d3_l.max_z*sizeof(unsigned int)))==NULL) + { + puts("failed allocating memory for nuclear energy loss graph"); + return -1; + } + if(get_reject_graph(&my_info,&d3_l,p_file,c_profile)!=1) + { + puts("failed to get reject graph"); + return -1; + } + + /* break here for testing ... */ + return 23; + i=(c_step?c_step:0); while((i