4 * this program tries helping to understand the amorphous depuration
5 * and recrystallization of SiCx while ion implantation at temperatures
6 * below 400 degree celsius.
7 * hopefully the program will simulate the stabilization of the
8 * selforganizing lamella structure in the observed behaviour.
11 * - J. K. N. Lindner. Habilationsschrift, Universitaet Augsburg.
12 * - Maik Haeberlen. Diplomarbeit, Universitaet Augsburg.
19 #include <sys/types.h>
29 #define MAKE_AMORPH(N) *(N)|=AMORPH
30 #define MAKE_CRYST(N) *(N)&=~AMORPH
36 puts("-n \t\t no user interaction");
37 puts("-Z \t\t cryst -> amorph c diffusion in z direction");
38 printf("-a <value> \t slope of nuclear energy loss (default %f)\n",A_EL);
39 printf("-b <value> \t nuclear energy loss offset (default %f)\n",B_EL);
40 printf("-x <value> \t # x cells (default %d)\n",X);
41 printf("-y <value> \t # y cells (default %d)\n",Y);
42 printf("-z <value> \t # z cells (default %d)\n",Z);
43 printf("-s <value> \t steps (default %d)\n",STEPS);
44 printf("-d <value> \t refresh display (default %d)\n",REFRESH);
45 printf("-r <value> \t amorphous influence range (default %d)\n",RANGE);
46 printf("-f <value> \t pressure = <value> * 1/distance^2 (default %f)\n",A_AP);
47 printf("-p <value> \t pressure offset (default %f)\n",B_AP);
48 printf("-F <value> \t proportionality constant between c conc and ability to get amorphous (default %f)\n",A_CP);
49 printf("-A <value> \t slope of linear c distribution (default %f)\n",A_CD);
50 printf("-B <value> \t linear c distribution offset (default %f)\n",B_CD);
51 printf("-D <value> \t diffusion rate from cryst to amorph cells (default %f)\n",DR_AC);
52 printf("-c <value> \t diffusion rate in cryst cells (default %f)\n",DR_CC);
53 printf("-e <value> \t do diffusion every <value> steps (default %d)\n",DIFF_RATE);
54 printf("-W <value> \t write every <value> steps to save file (default %d)\n",RESAVE);
55 puts("-C <file> \t convert file to gnuplot format");
56 puts("-L <file> \t load from file");
57 puts("-S <file> \t save to file");
58 puts("-R <file> \t read from random file");
59 puts("-P <file> \t specify implantatin profile file");
64 int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,info *my_info)
72 thiz=d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
73 conc=d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
74 p=my_info->b_ap*URAND_MAX;
75 for(i=-(my_info->range);i<=my_info->range;i++)
77 for(j=-(my_info->range);j<=my_info->range;j++)
81 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;
82 if(*(d3_l->status+off)&AMORPH) p+=my_info->a_ap*(*(d3_l->extra+off))*URAND_MAX/(i*i+j*j);
86 p+=*conc*my_info->a_cp*URAND_MAX;
89 if(get_rand(URAND_MAX)<=p) MAKE_AMORPH(thiz);
92 /* assume 1-p probability */
93 if(get_rand(URAND_MAX)>p) MAKE_CRYST(thiz);
101 int distrib_c(d3_lattice *d3_l,info *my_info)
108 /* put one c ion somewhere in the lattice */
109 x=get_rand(d3_l->max_x);
110 y=get_rand(d3_l->max_y);
111 z=get_rand_lgp(d3_l->max_z,my_info->a_cd,my_info->b_cd);
112 *(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)+=1;
114 for(i=0;i<d3_l->max_x;i++)
116 for(j=0;j<d3_l->max_y;j++)
118 for(k=0;k<d3_l->max_z;k++)
120 offset=i+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
121 /* case amorph - amorph <-> cryst diffusion */
122 if(*(d3_l->status+offset)&AMORPH)
128 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;
130 if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
133 *(d3_l->extra+offset)+=carry;
134 *(d3_l->extra+off)-=carry;
142 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;
144 if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
147 *(d3_l->extra+offset)+=carry;
148 *(d3_l->extra+off)-=carry;
158 off=i+j*d3_l->max_x+((k+c+d3_l->max_z)%d3_l->max_z)*d3_l->max_x*d3_l->max_y;
160 if(!*(d3_l->status+off)&AMORPH) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
163 *(d3_l->extra+off)-=carry;
164 *(d3_l->extra+offset)+=carry;
170 /* case not amorph - cryst <-> cryst diffusion */
176 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;
178 if(!(*(d3_l->status+off)&AMORPH))
180 carry=(*(d3_l->extra+off)-*(d3_l->extra+offset))/2;
183 *(d3_l->extra+offset)+=carry;
184 *(d3_l->extra+off)-=carry;
193 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;
195 if(!(*(d3_l->status+off)&AMORPH))
197 carry=(*(d3_l->extra+off)-*(d3_l->extra+offset))/2;
200 *(d3_l->extra+offset)+=carry;
201 *(d3_l->extra+off)-=carry;
214 int calc_pressure(d3_lattice *d3_l,int range)
220 for(x=0;x<d3_l->max_x;x++)
222 for(y=0;y<d3_l->max_y;y++)
224 for(z=0;z<d3_l->max_z;z++)
227 for(i=-range;i<=range;i++)
229 for(j=-range;j<=range;j++)
233 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;
234 if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
238 *(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_VPTR);
246 int save_to_file(char *sf,d3_lattice *d3_l,info *my_inf)
250 if((sf_fd=open(sf,O_WRONLY|O_CREAT))<0)
252 puts("cannot open save file");
255 if(write(sf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
257 puts("failed saving d3 lattice struct");
260 if(write(sf_fd,my_inf,sizeof(info))<sizeof(info))
262 puts("failed saving info struct");
265 c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
266 if(write(sf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
268 puts("failed saving status of d3 lattice sites");
271 if(write(sf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
273 puts("failed saving sites concentration");
281 int load_from_file(char *lf,d3_lattice *d3_l,info *my_inf)
285 if((lf_fd=open(lf,O_RDONLY))<0)
287 puts("cannot open load file");
290 if(read(lf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
292 puts("failed reading d3 lattice struct");
295 if(read(lf_fd,my_inf,sizeof(info))<sizeof(info))
297 puts("failed reading info struct");
300 c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
301 if((d3_l->status=(unsigned char*)malloc(c*sizeof(unsigned char)))==NULL)
303 puts("cannot allocate status buffer");
306 if((d3_l->extra=(int *)malloc(c*sizeof(int)))==NULL)
308 puts("cannot allocate concentration buffer");
311 if(read(lf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
313 puts("failed reading status of d3 lattice sites");
316 if(read(lf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
318 puts("failed reading sites concentration");
326 int convert_file(char *cf,d3_lattice *d3_l)
331 if((c_fd=open(cf,O_WRONLY|O_CREAT))<0)
333 puts("cannot open convert file");
336 dprintf(c_fd,"# created by nlsop (gnuplot format)\n");
337 for(x=0;x<d3_l->max_x;x++)
339 for(y=0;y<d3_l->max_y;y++)
341 for(z=0;z<d3_l->max_z;z++)
343 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);
352 int main(int argc,char **argv)
354 u32 x,y,z,x_c,y_c,z_c;
355 int i,quit,escape,switchmode,nowait;
357 char s_file[MAX_CHARS];
358 char s_file_tmp[MAX_CHARS];
359 char l_file[MAX_CHARS];
360 char c_file[MAX_CHARS];
361 char p_file[MAX_CHARS];
363 char r_file[MAX_CHARS];
365 char xyz_txt[MAX_TXT];
366 char status_txt[MAX_TXT];
367 char conc_txt[MAX_TXT];
368 char steps_txt[MAX_TXT];
369 char cc_txt[MAX_TXT];
372 char ap_txt[MAX_TXT];
373 char el_txt[MAX_TXT];
374 char cd_txt[MAX_TXT];
376 char cp_txt[MAX_TXT];
377 char zdiff_txt[MAX_TXT];
378 char diff_txt[MAX_TXT];
379 char dr_ac_txt[MAX_TXT];
380 char dr_cc_txt[MAX_TXT];
381 char mode_txt[MAX_TXT];
382 char *arg_v[MAX_ARGV];
406 my_info.diff_rate=DIFF_RATE;
414 strcpy(p_file,IMP_PROFILE);
432 my_info.a_el=atof(argv[++i]);
435 my_info.b_el=atof(argv[++i]);
438 d3_l.max_x=atoi(argv[++i]);
441 d3_l.max_y=atoi(argv[++i]);
444 d3_l.max_z=atoi(argv[++i]);
450 my_info.steps=atoi(argv[++i]);
453 refresh=atoi(argv[++i]);
456 my_info.range=atoi(argv[++i]);
459 my_info.a_ap=atof(argv[++i]);
462 my_info.b_ap=atof(argv[++i]);
465 my_info.a_cp=atof(argv[++i]);
468 my_info.a_cd=atof(argv[++i]);
471 my_info.b_cd=atof(argv[++i]);
474 resave=atoi(argv[++i]);
477 strcpy(l_file,argv[++i]);
478 if(i<argc-1) if(argv[i+1][0]!='-') strcpy(c_file,argv[++i]);
482 my_info.dr_ac=atof(argv[++i]);
485 my_info.dr_cc=atof(argv[++i]);
488 my_info.diff_rate=atoi(argv[++i]);
491 strcpy(l_file,argv[++i]);
494 strcpy(s_file,argv[++i]);
497 strcpy(r_file,argv[++i]);
500 strcpy(p_file,argv[++i]);
514 if(!strcmp(s_file,""))
516 puts("NODFB defined, run with -S option");
521 if(!strcmp(r_file,"")) rand_init(NULL);
522 else rand_init(r_file);
524 if(!strcmp(l_file,""))
526 i=d3_l.max_x*d3_l.max_y*d3_l.max_z;
528 d3_lattice_init(&argc,argv,&d3_l);
530 if((d3_l.status=(unsigned char *)malloc(i*sizeof(unsigned char)))==NULL)
532 puts("failed allocating status buffer");
535 memset(d3_l.status,0,i*sizeof(unsigned char));
536 if((d3_l.extra=(int *)malloc(i*sizeof(int)))==NULL)
538 puts("failed allocating concentration buffer");
541 memset(d3_l.extra,0,i*sizeof(int));
544 load_from_file(l_file,&d3_l,&my_info);
547 if(!strcmp(c_file,"")) sprintf(c_file,"%s_gnuplot",l_file);
548 printf("converting file %s to %s\n",l_file,c_file);
549 convert_file(c_file,&d3_l);
554 else d3_lattice_init(&argc,argv,&d3_l);
559 d3_event_init(&d3_l);
563 strcpy(a_txt,"args:");
564 sprintf(s_txt,"steps: %d",my_info.steps);
565 sprintf(r_txt,"pressure range: %d",my_info.range);
566 sprintf(ap_txt,"a_ap: %.2f b_ap: %.3f",my_info.a_ap,my_info.b_ap);
567 sprintf(el_txt,"a_el: %.2f b_el: %.3f",my_info.a_el,my_info.b_el);
568 sprintf(cd_txt,"a_cd: %.2f b_cd: %.3f",my_info.a_cd,my_info.b_cd);
569 sprintf(cp_txt,"a_cp: %.4f",my_info.a_cp);
570 sprintf(dr_ac_txt,"a/c diffusion rate: %.4f",my_info.dr_ac);
571 sprintf(dr_cc_txt,"c/c diffusion rate: %.4f",my_info.dr_cc);
572 sprintf(zdiff_txt,"diffusion in z direction: %c",my_info.z_diff?'y':'n');
573 sprintf(diff_txt,"diffusion every %d steps",my_info.diff_rate);
574 strcpy(mode_txt,"view: a/c mode");
601 if(!strcmp(l_file,""))
604 while((i<my_info.steps) && (quit==0) && (escape==0))
606 x_c=get_rand(d3_l.max_x);
607 y_c=get_rand(d3_l.max_y);
608 z_c=get_rand_lgp(d3_l.max_z,my_info.a_el,my_info.b_el);
609 if(i%my_info.diff_rate==0) distrib_c(&d3_l,&my_info);
610 process_cell(&d3_l,x_c,y_c,z_c,&my_info);
614 sprintf(xyz_txt,"x: %d y: %d z: %d",x+1,y+1,z+1);
615 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');
616 sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
617 sprintf(steps_txt,"step: %d",i);
618 sprintf(cc_txt,"total c: %d",my_info.cc);
619 d3_lattice_draw(&d3_l,x,y,z,24,arg_v,mode);
622 if(i%resave==0 && strcmp(s_file,"") && resave!=0 && i!=0)
624 sprintf(s_file_tmp,"%s_%d_of_%d",s_file,i,my_info.steps);
625 save_to_file(s_file_tmp,&d3_l,&my_info);
627 printf("saved %s\n",s_file_tmp);
634 if(strcmp(s_file,""))
636 printf("saved %s\n",s_file);
637 save_to_file(s_file,&d3_l,&my_info);
641 /* allocating buffer for pressure values */
642 if((d3_l.v_ptr=malloc(d3_l.max_x*d3_l.max_y*d3_l.max_z*sizeof(unsigned char)))==NULL)
644 puts("cannot allocate buffer for pressure values");
648 calc_pressure(&d3_l,my_info.range);
650 while((quit==0) && (escape==0) && (nowait==0))
653 if(switchmode==0) mode=0;
654 if(switchmode==1) mode=1;
655 if(switchmode==2) mode=2;
657 sprintf(xyz_txt,"x: %d y: %d z: %d",x+1,y+1,z+1);
658 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');
659 sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
660 strcpy(steps_txt,"step: end!");
661 sprintf(cc_txt,"total c: %d",my_info.cc);
662 if(switchmode==0) strcpy(mode_txt,"view: a/c mode");
663 if(switchmode==1) strcpy(mode_txt,"view: c conc mode");
664 if(switchmode==2) strcpy(mode_txt,"view: a pressure mode");
665 d3_lattice_draw(&d3_l,x,y,z,24,arg_v,mode);
666 scan_event(&d3_l,&x,&y,&z,&quit,&escape,&switchmode);
669 d3_lattice_release(&d3_l);