4 * author: frank zirkelbach (frank.zirkelbach@physik.uni-augsburg.de)
6 * this program tries helping to understand the amorphous depuration
7 * and recrystallization of SiCx while ion implantation at temperatures
8 * below 400 degree celsius.
9 * hopefully the program will simulate the stabilization of the
10 * selforganizing lamella structure in the observed behaviour.
13 * - J. K. N. Lindner. Habilationsschrift, Universitaet Augsburg.
14 * - Maik Haeberlen. Diplomarbeit, Universitaet Augsburg.
16 * Copyright (C) 2004 Frank Zirkelbach
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #include <sys/types.h>
48 #define MAKE_AMORPH(N) *(N)|=AMORPH
49 #define MAKE_CRYST(N) *(N)&=~AMORPH
55 puts("-n \t\t no user interaction");
56 puts("-Z \t\t cryst -> amorph c diffusion in z direction");
57 puts("-i \t\t no cryst to cryst diffusion");
58 printf("-a <value> \t slope of nuclear energy loss (default %f)\n",A_EL);
59 printf("-b <value> \t nuclear energy loss offset (default %f)\n",B_EL);
60 printf("-x <value> \t # x cells (default %d)\n",X);
61 printf("-y <value> \t # y cells (default %d)\n",Y);
62 printf("-z <value> \t # z cells (default %d)\n",Z);
63 printf("-s <value> \t steps (default %d)\n",STEPS);
64 printf("-d <value> \t refresh display (default %d)\n",REFRESH);
65 printf("-r <value> \t amorphous influence range (default %d)\n",RANGE);
66 printf("-f <value> \t pressure = <value> * 1/distance^2 (default %f)\n",A_AP);
67 printf("-p <value> \t pressure offset (default %f)\n",B_AP);
68 printf("-F <value> \t proportionality constant between c conc and ability to get amorphous (default %f)\n",A_CP);
69 printf("-A <value> \t slope of linear c distribution (default %f)\n",A_CD);
70 printf("-B <value> \t linear c distribution offset (default %f)\n",B_CD);
71 printf("-D <value> \t diffusion rate from cryst to amorph cells (default %f)\n",DR_AC);
72 printf("-c <value> \t diffusion rate in cryst cells (default %f)\n",DR_CC);
73 printf("-e <value> \t do diffusion every <value> steps (default %d)\n",DIFF_RATE);
74 puts("-g <file> <step> continue simulation from file and step (step > 0)!");
75 printf("-W <value> \t write every <value> steps to save file (default %d)\n",RESAVE);
76 puts("-C <file> \t convert file to gnuplot format");
77 puts("-L <file> \t load from file");
78 puts("-S <file> \t save to file");
79 puts("-R <file> \t read from random file");
80 puts("-P <file> \t specify implantation profile file");
81 puts("-N <file> \t specify nuclear energy loss profile file");
82 printf("-H <value> \t collisions per ion in simulation window (default %d)\n",CPI);
87 int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,info *my_info)
95 thiz=d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
96 conc=d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
97 p=my_info->b_ap*URAND_MAX;
98 for(i=-(my_info->range);i<=my_info->range;i++)
100 for(j=-(my_info->range);j<=my_info->range;j++)
104 off=((x+d3_l->max_x+i)%d3_l->max_x)+((y+d3_l->max_y+j)%d3_l->max_x)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
105 if(*(d3_l->status+off)&AMORPH) p+=my_info->a_ap*(*(d3_l->extra+off))*URAND_MAX/(i*i+j*j);
109 p+=*conc*my_info->a_cp*URAND_MAX;
112 if(get_rand(URAND_MAX)<=p) MAKE_AMORPH(thiz);
115 /* assume 1-p probability */
116 if(get_rand(URAND_MAX)>p) MAKE_CRYST(thiz);
122 int distrib_c(d3_lattice *d3_l,info *my_info,int step,double c_ratio,u32 rj_m,u32 *rj_g)
129 /* put one c ion somewhere in the lattice */
130 if(my_info->cc<c_ratio*step)
132 x=get_rand(d3_l->max_x);
133 y=get_rand(d3_l->max_y);
134 // printf("nd: %d %d\n",x,y);
135 // z=get_rand_lgp(d3_l->max_z,my_info->a_cd,my_info->b_cd);
136 z=get_rand_reject(d3_l->max_z,rj_m,rj_g);
138 *(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)+=1;
142 if(step%my_info->diff_rate==0)
145 for(i=0;i<d3_l->max_x;i++)
147 for(j=0;j<d3_l->max_y;j++)
149 for(k=0;k<d3_l->max_z;k++)
151 offset=i+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
152 /* case amorph: amorph <- cryst diffusion */
153 if(*(d3_l->status+offset)&AMORPH)
159 off=((i+d3_l->max_x+c)%d3_l->max_x)+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
161 if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
164 *(d3_l->extra+offset)+=carry;
165 *(d3_l->extra+off)-=carry;
173 off=i+((j+c+d3_l->max_y)%d3_l->max_y)*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
175 if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
178 *(d3_l->extra+offset)+=carry;
179 *(d3_l->extra+off)-=carry;
187 off=i+j*d3_l->max_x+(k-1)*d3_l->max_x*d3_l->max_y;
189 if(!*(d3_l->status+off)&AMORPH) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
192 *(d3_l->extra+off)-=carry;
193 *(d3_l->extra+offset)+=carry;
198 off=i+j*d3_l->max_x+(k+1)*d3_l->max_x*d3_l->max_y;
200 if(!*(d3_l->status+off)&AMORPH) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
203 *(d3_l->extra+off)-=carry;
204 *(d3_l->extra+offset)+=carry;
209 /* case not amorph: cryst <-> cryst diffusion */
210 if(my_info->c_diff) {
211 /* if there is c diff, no diff in z-direction */
217 off=i+((j+c+d3_l->max_y)%d3_l->max_y)*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
219 if(!(*(d3_l->status+off)&AMORPH))
221 carry=(int)(my_info->dr_cc*(*(d3_l->extra+off)-*(d3_l->extra+offset))/2);
224 *(d3_l->extra+offset)+=carry;
225 *(d3_l->extra+off)-=carry;
234 off=((i+c+d3_l->max_x)%d3_l->max_x)+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
236 if(!(*(d3_l->status+off)&AMORPH))
238 carry=(int)(my_info->dr_cc*(*(d3_l->extra+off)-*(d3_l->extra+offset))/2);
241 *(d3_l->extra+offset)+=carry;
242 *(d3_l->extra+off)-=carry;
255 } /* if step modulo diff_rate == 0 */
260 int calc_pressure(d3_lattice *d3_l,int range)
266 for(x=0;x<d3_l->max_x;x++)
268 for(y=0;y<d3_l->max_y;y++)
270 for(z=0;z<d3_l->max_z;z++)
273 for(i=-range;i<=range;i++)
275 for(j=-range;j<=range;j++)
279 off=((x+d3_l->max_x+i)%d3_l->max_x)+((y+d3_l->max_y+j)%d3_l->max_x)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
280 if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
284 if(count>max) max=count;
289 for(x=0;x<d3_l->max_x;x++)
291 for(y=0;y<d3_l->max_y;y++)
293 for(z=0;z<d3_l->max_z;z++)
296 for(i=-range;i<=range;i++)
298 for(j=-range;j<=range;j++)
302 off=((x+d3_l->max_x+i)%d3_l->max_x)+((y+d3_l->max_y+j)%d3_l->max_x)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
303 if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
307 *(unsigned char *)(d3_l->v_ptr+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)=(unsigned char)(count*255/max);
315 int calc_max_extra(d3_lattice *d3_l)
320 for(x=0;x<d3_l->max_x;x++)
322 for(y=0;y<d3_l->max_y;y++)
324 for(z=0;z<d3_l->max_z;z++)
326 off=x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
327 if(*(d3_l->extra+off)>max) max=*(d3_l->extra+off);
335 int write_ac_distr(d3_lattice *d3_l,int ac_distr)
341 if(ac_distr==1) strcpy(file,"a.plot");
342 if(ac_distr==2) strcpy(file,"c.plot");
343 if(ac_distr==3) strcpy(file,"b.plot");
345 if((fd=open(file,O_WRONLY|O_CREAT))<0)
347 puts("cannot open plot file");
351 for(z=0;z<d3_l->max_z;z++)
353 for(x=0;x<d3_l->max_x;x++)
355 for(y=0;y<d3_l->max_y;y++)
357 offset=x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
359 if(*(d3_l->status+offset)&AMORPH) count+=*(d3_l->extra+offset);
361 if(!(*(d3_l->status+offset)&AMORPH)) count+=*(d3_l->extra+offset);
362 if(ac_distr==3) count+=*(d3_l->extra+offset);
365 dprintf(fd,"%d %d\n",z,count);
372 int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z)
374 int fd,i,j,size=0,foo=0,end=0;
375 int width=0,height=0;
376 char bmpfile[MAX_CHARS];
379 if(((window==4)||(window==5))&&(d3_l->max_z<FFT_HEIGHT) )
381 puts("error: z < FFT_HEIGHT!");
382 puts("not writing bmp file ...");
388 sprintf(bmpfile,"x-z_%d.bmp",y);
392 size=(foo+(4-foo%4))*d3_l->max_z;
397 size=(foo+(4-foo%4))*FFT_HEIGHT;
398 end=d3_l->max_z-FFT_HEIGHT;
405 sprintf(bmpfile,"y-z_%d.bmp",x);
409 size=(foo+(4-foo%4))*d3_l->max_z;
414 size=(foo+(4-foo%4))*FFT_HEIGHT;
415 end=d3_l->max_z-FFT_HEIGHT;
422 sprintf(bmpfile,"x-y_%d.bmp",z);
424 size=(foo+(4-foo%4))*d3_l->max_y;
429 if((fd=open(bmpfile,O_WRONLY|O_CREAT))<0)
431 puts("cannot open bmp file");
436 buf[0]='B'; /* std header start */
438 buf[2]=(size+0x36)&0xff; /* file size */
439 buf[3]=(size+0x36)>>8;
441 buf[10]=0x36; /* offset to data */
443 buf[14]=0x28; /* length of bmp info header */
445 buf[18]=width&0xff; /* width and height */
451 buf[26]=1; /* # planes -> 1 */
453 buf[28]=24; /* bits per pixel -> 2^24 (true color) */
455 memset(buf+30,0,4); /* compression -> none */
456 buf[34]=size&0xff; /* data size */
459 buf[38]=0x12; /* res: pixel/meter */
465 memset(buf+46,0,8); /* no colors, no important colors */
467 if(write(fd,buf,54)<54)
469 puts("failed writing bmp header");
474 for(j=0;j<d3_l->max_z-end;j++)
476 for(i=0;i<d3_l->max_x;i++)
478 if(*(d3_l->status+i+y*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y)&RED) memset(buf,0xff,3);
479 else memset(buf,0,3);
480 if(write(fd,buf,3)<3)
482 puts("failed writing rgb values to bmp file");
488 memset(buf,0,4-foo%4);
489 if(write(fd,buf,4-foo%4)<4-foo%4)
491 puts("failed writing 4 byte ending");
499 for(j=0;j<d3_l->max_z-end;j++)
501 for(i=0;i<d3_l->max_y;i++)
503 if(*(d3_l->status+x+i*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y)&RED) memset(buf,0xff,3);
504 else memset(buf,0,3);
505 if(write(fd,buf,3)<3)
507 puts("failed writing rgb values to bmp file");
513 memset(buf,0,4-foo%4);
514 if(write(fd,buf,4-foo%4)<4-foo%4)
516 puts("failed writing 4 byte ending");
524 for(j=0;j<d3_l->max_y;j++)
526 for(i=0;i<d3_l->max_x;i++)
528 if(*(d3_l->status+i+(d3_l->max_y-j-1)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&RED) memset(buf,0xff,3);
529 else memset(buf,0,3);
530 if(write(fd,buf,3)<3)
532 puts("failed writing rgb values to bmp file");
538 memset(buf,0,4-foo%4);
539 if(write(fd,buf,4-foo%4)<4-foo%4)
541 puts("failed writing 4 byte ending");
552 int save_to_file(char *sf,d3_lattice *d3_l,info *my_inf)
556 if((sf_fd=open(sf,O_WRONLY|O_CREAT))<0)
558 puts("cannot open save file");
561 if(write(sf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
563 puts("failed saving d3 lattice struct");
566 if(write(sf_fd,my_inf,sizeof(info))<sizeof(info))
568 puts("failed saving info struct");
571 c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
572 if(write(sf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
574 puts("failed saving status of d3 lattice sites");
577 if(write(sf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
579 puts("failed saving sites concentration");
587 int load_from_file(char *lf,d3_lattice *d3_l,info *my_inf)
591 if((lf_fd=open(lf,O_RDONLY))<0)
593 puts("cannot open load file");
596 if(read(lf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
598 puts("failed reading d3 lattice struct");
601 if(read(lf_fd,my_inf,sizeof(info))<sizeof(info))
603 puts("failed reading info struct");
606 c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
607 if((d3_l->status=(unsigned char*)malloc(c*sizeof(unsigned char)))==NULL)
609 puts("cannot allocate status buffer");
612 if((d3_l->extra=(int *)malloc(c*sizeof(int)))==NULL)
614 puts("cannot allocate concentration buffer");
617 if(read(lf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
619 puts("failed reading status of d3 lattice sites");
622 if(read(lf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
624 puts("failed reading sites concentration");
632 int convert_file(char *cf,d3_lattice *d3_l)
637 if((c_fd=open(cf,O_WRONLY|O_CREAT))<0)
639 puts("cannot open convert file");
642 dprintf(c_fd,"# created by nlsop (gnuplot format)\n");
643 for(x=0;x<d3_l->max_x;x++)
645 for(y=0;y<d3_l->max_y;y++)
647 for(z=0;z<d3_l->max_z;z++)
649 if(*(d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH) dprintf(c_fd,"%d %d %d\n",x,y,z);
658 int get_c_ratio(double *c_ratio,char *pfile,info *my_info,d3_lattice *d3_l)
663 unsigned char buf[32];
667 if((p_fd=open(pfile,O_RDONLY))<0)
669 puts("cannot open profile file");
686 a=atof(p)/10; /* nm */
689 if(a>my_info->b_cd*CELL_LENGTH && a<(my_info->b_cd+d3_l->max_z)*CELL_LENGTH) d+=b;
699 u32 get_reject_graph(info *my_info,d3_lattice *d3_l,char *file,u32 *graph) {
708 if((fd=open(file,O_RDONLY))<0)
710 puts("cannot open file to calculate rejection graph");
713 if((flag=(unsigned char *)malloc(d3_l->max_z))==NULL)
715 puts("cannot malloc flag memory for rejection graph");
718 memset(flag,0,d3_l->max_z);
719 memset(graph,0,d3_l->max_z*sizeof(u32));
726 k=read(fd,&buf[i],1);
727 if((buf[i]=='\n')||(k==0)) break;
732 a=atof(p)/10; /* nm */
735 if(a>d3_l->max_z*CELL_LENGTH) k=0;
738 graph[(int)(a/CELL_LENGTH)]=(int)(URAND_MAX*b);
739 flag[(int)(a/CELL_LENGTH)]=1;
743 /* do (linear) interpolation here! */
751 while(flag[i]==0&&i<d3_l->max_z) i++;
752 for(k=j+1;k<i;k++) graph[k]=(int)((k-j)*((int)graph[i]-(int)graph[j])/(i-j))+graph[j];
753 if(graph[i]>max) max=graph[i];
758 // printf("debug: (interpolated c profile)\n");
759 // for(i=0;i<d3_l->max_z;i++) printf("%d %d\n",i,graph[i]);
764 int main(int argc,char **argv)
766 u32 x,y,z,x_c,y_c,z_c;
767 int i,j,quit,escape,switchmode,nowait,bmp,ac_distr;
770 char s_file[MAX_CHARS];
771 char s_file_tmp[MAX_CHARS];
772 char l_file[MAX_CHARS];
773 char c_file[MAX_CHARS];
774 char p_file[MAX_CHARS];
775 char n_e_file[MAX_CHARS];
777 char r_file[MAX_CHARS];
779 char xyz_txt[MAX_TXT];
780 char status_txt[MAX_TXT];
781 char conc_txt[MAX_TXT];
782 char steps_txt[MAX_TXT];
783 char cc_txt[MAX_TXT];
786 char ap_txt[MAX_TXT];
787 char el_txt[MAX_TXT];
788 char cd_txt[MAX_TXT];
790 char cp_txt[MAX_TXT];
791 char zdiff_txt[MAX_TXT];
792 char diff_txt[MAX_TXT];
793 char dr_ac_txt[MAX_TXT];
794 char dr_cc_txt[MAX_TXT];
795 char dose_txt[MAX_TXT];
796 char mode_txt[MAX_TXT];
797 char *arg_v[MAX_ARGV];
829 my_info.diff_rate=DIFF_RATE;
839 strcpy(p_file,IMP_PROFILE);
840 strcpy(n_e_file,NEL_PROFILE);
860 my_info.a_el=atof(argv[++i]);
863 my_info.b_el=atof(argv[++i]);
866 d3_l.max_x=atoi(argv[++i]);
869 d3_l.max_y=atoi(argv[++i]);
872 d3_l.max_z=atoi(argv[++i]);
882 my_info.steps=atoi(argv[++i]);
885 refresh=atoi(argv[++i]);
888 my_info.range=atoi(argv[++i]);
891 my_info.a_ap=atof(argv[++i]);
894 my_info.b_ap=atof(argv[++i]);
897 my_info.a_cp=atof(argv[++i]);
900 my_info.a_cd=atof(argv[++i]);
903 my_info.b_cd=atof(argv[++i]);
906 resave=atoi(argv[++i]);
909 strcpy(l_file,argv[++i]);
910 if(i<argc-1) if(argv[i+1][0]!='-') strcpy(c_file,argv[++i]);
914 my_info.dr_ac=atof(argv[++i]);
917 my_info.dr_cc=atof(argv[++i]);
920 my_info.diff_rate=atoi(argv[++i]);
923 strcpy(l_file,argv[++i]);
926 strcpy(s_file,argv[++i]);
929 strcpy(r_file,argv[++i]);
932 strcpy(p_file,argv[++i]);
935 strcpy(n_e_file,argv[++i]);
938 strcpy(l_file,argv[++i]);
939 if(i<argc-1) if(argv[i+1][0]!='-') c_step=atoi(argv[++i]);
942 my_info.cpi=atoi(argv[++i]);
956 if(!strcmp(s_file,""))
958 puts("NODFB defined, run with -S option");
963 if(!strcmp(r_file,"")) rand_init(NULL);
964 else rand_init(r_file);
966 if(!strcmp(l_file,""))
968 i=d3_l.max_x*d3_l.max_y*d3_l.max_z;
970 d3_lattice_init(&argc,argv,&d3_l);
972 if((d3_l.status=(unsigned char *)malloc(i*sizeof(unsigned char)))==NULL)
974 puts("failed allocating status buffer");
977 memset(d3_l.status,0,i*sizeof(unsigned char));
978 if((d3_l.extra=(int *)malloc(i*sizeof(int)))==NULL)
980 puts("failed allocating concentration buffer");
983 memset(d3_l.extra,0,i*sizeof(int));
986 load_from_file(l_file,&d3_l,&my_info);
989 if(!strcmp(c_file,"")) sprintf(c_file,"%s_gnuplot",l_file);
990 printf("converting file %s to %s\n",l_file,c_file);
991 convert_file(c_file,&d3_l);
996 else d3_lattice_init(&argc,argv,&d3_l);
1001 d3_event_init(&d3_l);
1005 strcpy(a_txt,"args:");
1006 sprintf(s_txt,"steps: %d",my_info.steps);
1007 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));
1008 sprintf(r_txt,"pressure range: %d",my_info.range);
1009 sprintf(ap_txt,"a_ap: %f b_ap: %f",my_info.a_ap,my_info.b_ap);
1010 sprintf(el_txt,"a_el: %f b_el: %f",my_info.a_el,my_info.b_el);
1011 sprintf(cd_txt,"a_cd: %f b_cd: %f",my_info.a_cd,my_info.b_cd);
1012 sprintf(cp_txt,"a_cp: %f",my_info.a_cp);
1013 sprintf(dr_ac_txt,"a/c diffusion rate: %f",my_info.dr_ac);
1014 if(my_info.c_diff!=0) sprintf(dr_cc_txt,"c/c diffusion rate: %f",my_info.dr_cc);
1015 else sprintf(dr_cc_txt,"c/c diffusion rate: none");
1016 sprintf(zdiff_txt,"diffusion in z direction: %c",my_info.z_diff?'y':'n');
1017 sprintf(diff_txt,"diffusion every %d steps",my_info.diff_rate);
1018 strcpy(mode_txt,"view: a/c mode");
1021 arg_v[3]=status_txt;
1030 arg_v[12]=zdiff_txt;
1042 arg_v[24]=dr_ac_txt;
1043 arg_v[25]=dr_cc_txt;
1046 if((!strcmp(l_file,""))||(c_step))
1048 /* calculate ratio of c_simwindow / c_total */
1049 if(get_c_ratio(&c_ratio,p_file,&my_info,&d3_l)!=1)
1051 puts("failed calculating ratio");
1054 /* compute graphs for random number rejection method */
1055 if((c_profile=(u32 *)malloc(d3_l.max_z*sizeof(unsigned int)))==NULL)
1057 puts("failed allocating memory for carbon profile graph");
1060 if((n_e_loss=(u32 *)malloc(d3_l.max_z*sizeof(unsigned int)))==NULL)
1062 puts("failed allocating memory for nuclear energy loss graph");
1065 ip_max=get_reject_graph(&my_info,&d3_l,p_file,c_profile);
1066 ne_max=get_reject_graph(&my_info,&d3_l,n_e_file,n_e_loss);
1072 printf("%d\n",get_rand_reject(d3_l.max_z,ip_max,c_profile));
1075 printf("%d\n",get_rand_reject(d3_l.max_z,ne_max,n_e_loss));
1080 i=(c_step?c_step:0);
1081 while((i<my_info.steps) && (quit==0) && (escape==0))
1083 for(j=0;j<my_info.cpi;j++)
1085 x_c=get_rand(d3_l.max_x);
1086 y_c=get_rand(d3_l.max_y);
1087 // z_c=get_rand_lgp(d3_l.max_z,my_info.a_el,my_info.b_el);
1088 z_c=get_rand_reject(d3_l.max_z,ne_max,n_e_loss);
1089 process_cell(&d3_l,x_c,y_c,z_c,&my_info);
1091 distrib_c(&d3_l,&my_info,i,c_ratio,ip_max,c_profile);
1095 sprintf(xyz_txt,"x: %d y: %d z: %d",x+1,y+1,z+1);
1096 sprintf(status_txt,"status: %c",(*(d3_l.status+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y)&AMORPH)?'a':'c');
1097 sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
1098 sprintf(steps_txt,"step: %d",i);
1099 sprintf(cc_txt,"total c: %d",my_info.cc);
1100 d3_lattice_draw(&d3_l,x,y,z,25,arg_v,mode,0);
1103 if(i%resave==0 && strcmp(s_file,"") && resave!=0 && i!=0)
1105 sprintf(s_file_tmp,"%s_%d_of_%d",s_file,i,my_info.steps);
1106 save_to_file(s_file_tmp,&d3_l,&my_info);
1108 printf("saved %s\n",s_file_tmp);
1115 if(strcmp(s_file,""))
1117 printf("saved %s\n",s_file);
1118 save_to_file(s_file,&d3_l,&my_info);
1122 /* allocating buffer for pressure values */
1123 if((d3_l.v_ptr=malloc(d3_l.max_x*d3_l.max_y*d3_l.max_z*sizeof(unsigned char)))==NULL)
1125 puts("cannot allocate buffer for pressure values");
1129 calc_pressure(&d3_l,my_info.range);
1130 max_extra=calc_max_extra(&d3_l);
1132 while((quit==0) && (escape==0) && (nowait==0))
1135 if(switchmode==0) mode=0;
1136 if(switchmode==1) mode=1;
1137 if(switchmode==2) mode=2;
1139 sprintf(xyz_txt,"x: %d y: %d z: %d",x+1,y+1,z+1);
1140 sprintf(status_txt,"status: %c",(*(d3_l.status+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y)&AMORPH)?'a':'c');
1141 sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
1142 sprintf(steps_txt,"step: end");
1143 sprintf(cc_txt,"total c: %d",my_info.cc);
1144 if(switchmode==0) strcpy(mode_txt,"view: a/c mode");
1145 if(switchmode==1) strcpy(mode_txt,"view: c conc mode");
1146 if(switchmode==2) strcpy(mode_txt,"view: a pressure mode");
1147 d3_lattice_draw(&d3_l,x,y,z,25,arg_v,mode,max_extra);
1150 scan_event(&d3_l,&x,&y,&z,&quit,&escape,&switchmode,&bmp,&ac_distr);
1151 if(bmp) write_bmp(&d3_l,bmp,x,y,z);
1152 if(ac_distr) write_ac_distr(&d3_l,ac_distr);
1155 d3_lattice_release(&d3_l);