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
32 /* test globals - get removed or included in my_info struct later */
40 puts("-n \t\t no user interaction");
41 puts("-Z \t\t cryst -> amorph c diffusion in z direction");
42 printf("-a <value> \t slope of nuclear energy loss (default %f)\n",A_EL);
43 printf("-b <value> \t nuclear energy loss offset (default %f)\n",B_EL);
44 printf("-x <value> \t # x cells (default %d)\n",X);
45 printf("-y <value> \t # y cells (default %d)\n",Y);
46 printf("-z <value> \t # z cells (default %d)\n",Z);
47 printf("-s <value> \t steps (default %d)\n",STEPS);
48 printf("-d <value> \t refresh display (default %d)\n",REFRESH);
49 printf("-r <value> \t amorphous influence range (default %d)\n",RANGE);
50 printf("-f <value> \t pressure = <value> * 1/distance^2 (default %f)\n",A_AP);
51 printf("-p <value> \t pressure offset (default %f)\n",B_AP);
52 printf("-F <value> \t proportionality constant between c conc and ability to get amorphous (default %f)\n",A_CP);
53 printf("-A <value> \t slope of linear c distribution (default %f)\n",A_CD);
54 printf("-B <value> \t linear c distribution offset (default %f)\n",B_CD);
55 printf("-D <value> \t diffusion rate from cryst to amorph cells (default %f)\n",DR_AC);
56 printf("-c <value> \t diffusion rate in cryst cells (default %f)\n",DR_CC);
57 printf("-e <value> \t do diffusion every <value> steps (default %d)\n",DIFF_RATE);
58 printf("-W <value> \t write every <value> steps to save file (default %d)\n",RESAVE);
59 puts("-C <file> \t convert file to gnuplot format");
60 puts("-L <file> \t load from file");
61 puts("-S <file> \t save to file");
62 puts("-R <file> \t read from random file");
63 puts("-P <file> \t specify implantatin profile file");
68 int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,info *my_info)
76 thiz=d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
77 conc=d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
78 p=my_info->b_ap*URAND_MAX;
79 for(i=-(my_info->range);i<=my_info->range;i++)
81 for(j=-(my_info->range);j<=my_info->range;j++)
85 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;
86 if(*(d3_l->status+off)&AMORPH) p+=my_info->a_ap*(*(d3_l->extra+off))*URAND_MAX/(i*i+j*j);
90 p+=*conc*my_info->a_cp*URAND_MAX;
93 if(get_rand(URAND_MAX)<=p)
100 /* assume 1-p probability */
101 if(get_rand(URAND_MAX)>p)
111 int distrib_c(d3_lattice *d3_l,info *my_info,int step,double c_ratio)
118 /* put one c ion somewhere in the lattice */
119 if(my_info->cc<c_ratio*step)
121 x=get_rand(d3_l->max_x);
122 y=get_rand(d3_l->max_y);
123 z=get_rand_lgp(d3_l->max_z,my_info->a_cd,my_info->b_cd);
124 *(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)+=1;
128 if(step%my_info->diff_rate==0)
131 for(i=0;i<d3_l->max_x;i++)
133 for(j=0;j<d3_l->max_y;j++)
135 for(k=0;k<d3_l->max_z;k++)
137 offset=i+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
138 /* case amorph - amorph <-> cryst diffusion */
139 if(*(d3_l->status+offset)&AMORPH)
145 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;
147 if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
150 *(d3_l->extra+offset)+=carry;
151 *(d3_l->extra+off)-=carry;
159 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;
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;
175 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;
177 if(!*(d3_l->status+off)&AMORPH) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
180 *(d3_l->extra+off)-=carry;
181 *(d3_l->extra+offset)+=carry;
187 /* case not amorph - cryst <-> cryst diffusion */
193 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;
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;
210 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;
212 if(!(*(d3_l->status+off)&AMORPH))
214 carry=(*(d3_l->extra+off)-*(d3_l->extra+offset))/2;
217 *(d3_l->extra+offset)+=carry;
218 *(d3_l->extra+off)-=carry;
228 } /* if step modulo diff_rate == 0 */
233 int calc_pressure(d3_lattice *d3_l,int range)
239 for(x=0;x<d3_l->max_x;x++)
241 for(y=0;y<d3_l->max_y;y++)
243 for(z=0;z<d3_l->max_z;z++)
246 for(i=-range;i<=range;i++)
248 for(j=-range;j<=range;j++)
252 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;
253 if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
257 *(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);
265 int save_to_file(char *sf,d3_lattice *d3_l,info *my_inf)
269 if((sf_fd=open(sf,O_WRONLY|O_CREAT))<0)
271 puts("cannot open save file");
274 if(write(sf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
276 puts("failed saving d3 lattice struct");
279 if(write(sf_fd,my_inf,sizeof(info))<sizeof(info))
281 puts("failed saving info struct");
284 c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
285 if(write(sf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
287 puts("failed saving status of d3 lattice sites");
290 if(write(sf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
292 puts("failed saving sites concentration");
300 int load_from_file(char *lf,d3_lattice *d3_l,info *my_inf)
304 if((lf_fd=open(lf,O_RDONLY))<0)
306 puts("cannot open load file");
309 if(read(lf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
311 puts("failed reading d3 lattice struct");
314 if(read(lf_fd,my_inf,sizeof(info))<sizeof(info))
316 puts("failed reading info struct");
319 c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
320 if((d3_l->status=(unsigned char*)malloc(c*sizeof(unsigned char)))==NULL)
322 puts("cannot allocate status buffer");
325 if((d3_l->extra=(int *)malloc(c*sizeof(int)))==NULL)
327 puts("cannot allocate concentration buffer");
330 if(read(lf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
332 puts("failed reading status of d3 lattice sites");
335 if(read(lf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
337 puts("failed reading sites concentration");
345 int convert_file(char *cf,d3_lattice *d3_l)
350 if((c_fd=open(cf,O_WRONLY|O_CREAT))<0)
352 puts("cannot open convert file");
355 dprintf(c_fd,"# created by nlsop (gnuplot format)\n");
356 for(x=0;x<d3_l->max_x;x++)
358 for(y=0;y<d3_l->max_y;y++)
360 for(z=0;z<d3_l->max_z;z++)
362 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);
371 int get_c_ratio(double *c_ratio,char *pfile,info *my_info,d3_lattice *d3_l)
376 unsigned char buf[32];
380 if((p_fd=open(pfile,O_RDONLY))<0)
382 puts("cannot open profile file");
399 a=atof(p)/10; /* nm */
402 if(a>my_info->b_cd*CELL_LENGTH && a<(my_info->b_cd+d3_l->max_z)*CELL_LENGTH) d+=b;
411 int main(int argc,char **argv)
413 u32 x,y,z,x_c,y_c,z_c;
414 int i,quit,escape,switchmode,nowait;
416 char s_file[MAX_CHARS];
417 char s_file_tmp[MAX_CHARS];
418 char l_file[MAX_CHARS];
419 char c_file[MAX_CHARS];
420 char p_file[MAX_CHARS];
422 char r_file[MAX_CHARS];
424 char xyz_txt[MAX_TXT];
425 char status_txt[MAX_TXT];
426 char conc_txt[MAX_TXT];
427 char steps_txt[MAX_TXT];
428 char cc_txt[MAX_TXT];
431 char ap_txt[MAX_TXT];
432 char el_txt[MAX_TXT];
433 char cd_txt[MAX_TXT];
435 char cp_txt[MAX_TXT];
436 char zdiff_txt[MAX_TXT];
437 char diff_txt[MAX_TXT];
438 char dr_ac_txt[MAX_TXT];
439 char dr_cc_txt[MAX_TXT];
440 char mode_txt[MAX_TXT];
441 char *arg_v[MAX_ARGV];
466 my_info.diff_rate=DIFF_RATE;
474 strcpy(p_file,IMP_PROFILE);
495 my_info.a_el=atof(argv[++i]);
498 my_info.b_el=atof(argv[++i]);
501 d3_l.max_x=atoi(argv[++i]);
504 d3_l.max_y=atoi(argv[++i]);
507 d3_l.max_z=atoi(argv[++i]);
513 my_info.steps=atoi(argv[++i]);
516 refresh=atoi(argv[++i]);
519 my_info.range=atoi(argv[++i]);
522 my_info.a_ap=atof(argv[++i]);
525 my_info.b_ap=atof(argv[++i]);
528 my_info.a_cp=atof(argv[++i]);
531 my_info.a_cd=atof(argv[++i]);
534 my_info.b_cd=atof(argv[++i]);
537 resave=atoi(argv[++i]);
540 strcpy(l_file,argv[++i]);
541 if(i<argc-1) if(argv[i+1][0]!='-') strcpy(c_file,argv[++i]);
545 my_info.dr_ac=atof(argv[++i]);
548 my_info.dr_cc=atof(argv[++i]);
551 my_info.diff_rate=atoi(argv[++i]);
554 strcpy(l_file,argv[++i]);
557 strcpy(s_file,argv[++i]);
560 strcpy(r_file,argv[++i]);
563 strcpy(p_file,argv[++i]);
577 if(!strcmp(s_file,""))
579 puts("NODFB defined, run with -S option");
584 if(!strcmp(r_file,"")) rand_init(NULL);
585 else rand_init(r_file);
587 if(!strcmp(l_file,""))
589 i=d3_l.max_x*d3_l.max_y*d3_l.max_z;
591 d3_lattice_init(&argc,argv,&d3_l);
593 if((d3_l.status=(unsigned char *)malloc(i*sizeof(unsigned char)))==NULL)
595 puts("failed allocating status buffer");
598 memset(d3_l.status,0,i*sizeof(unsigned char));
599 if((d3_l.extra=(int *)malloc(i*sizeof(int)))==NULL)
601 puts("failed allocating concentration buffer");
604 memset(d3_l.extra,0,i*sizeof(int));
607 load_from_file(l_file,&d3_l,&my_info);
610 if(!strcmp(c_file,"")) sprintf(c_file,"%s_gnuplot",l_file);
611 printf("converting file %s to %s\n",l_file,c_file);
612 convert_file(c_file,&d3_l);
617 else d3_lattice_init(&argc,argv,&d3_l);
622 d3_event_init(&d3_l);
626 strcpy(a_txt,"args:");
627 sprintf(s_txt,"steps: %d",my_info.steps);
628 sprintf(r_txt,"pressure range: %d",my_info.range);
629 sprintf(ap_txt,"a_ap: %.2f b_ap: %.3f",my_info.a_ap,my_info.b_ap);
630 sprintf(el_txt,"a_el: %.2f b_el: %.3f",my_info.a_el,my_info.b_el);
631 sprintf(cd_txt,"a_cd: %.2f b_cd: %.3f",my_info.a_cd,my_info.b_cd);
632 sprintf(cp_txt,"a_cp: %.4f",my_info.a_cp);
633 sprintf(dr_ac_txt,"a/c diffusion rate: %.4f",my_info.dr_ac);
634 sprintf(dr_cc_txt,"c/c diffusion rate: %.4f",my_info.dr_cc);
635 sprintf(zdiff_txt,"diffusion in z direction: %c",my_info.z_diff?'y':'n');
636 sprintf(diff_txt,"diffusion every %d steps",my_info.diff_rate);
637 strcpy(mode_txt,"view: a/c mode");
665 if(!strcmp(l_file,""))
667 if(get_c_ratio(&c_ratio,p_file,&my_info,&d3_l)!=1)
669 puts("failed calculating ratio");
673 while((i<my_info.steps) && (quit==0) && (escape==0))
675 x_c=get_rand(d3_l.max_x);
676 y_c=get_rand(d3_l.max_y);
677 z_c=get_rand_lgp(d3_l.max_z,my_info.a_el,my_info.b_el);
678 distrib_c(&d3_l,&my_info,i,c_ratio);
679 process_cell(&d3_l,x_c,y_c,z_c,&my_info);
683 sprintf(xyz_txt,"x: %d y: %d z: %d",x+1,y+1,z+1);
684 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');
685 sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
686 sprintf(steps_txt,"step: %d a_count: %d",i,amorph_count);
687 sprintf(cc_txt,"total c: %d c_count: %d",my_info.cc,cryst_count);
688 d3_lattice_draw(&d3_l,x,y,z,25,arg_v,mode);
691 if(i%resave==0 && strcmp(s_file,"") && resave!=0 && i!=0)
693 sprintf(s_file_tmp,"%s_%d_of_%d",s_file,i,my_info.steps);
694 save_to_file(s_file_tmp,&d3_l,&my_info);
696 printf("saved %s\n",s_file_tmp);
703 if(strcmp(s_file,""))
705 printf("saved %s\n",s_file);
706 save_to_file(s_file,&d3_l,&my_info);
710 /* allocating buffer for pressure values */
711 if((d3_l.v_ptr=malloc(d3_l.max_x*d3_l.max_y*d3_l.max_z*sizeof(unsigned char)))==NULL)
713 puts("cannot allocate buffer for pressure values");
717 calc_pressure(&d3_l,my_info.range);
719 while((quit==0) && (escape==0) && (nowait==0))
722 if(switchmode==0) mode=0;
723 if(switchmode==1) mode=1;
724 if(switchmode==2) mode=2;
726 sprintf(xyz_txt,"x: %d y: %d z: %d",x+1,y+1,z+1);
727 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');
728 sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
729 sprintf(steps_txt,"step: end! a_count: %d",amorph_count);
730 sprintf(cc_txt,"total c: %d c_count: %d",my_info.cc,cryst_count);
731 if(switchmode==0) strcpy(mode_txt,"view: a/c mode");
732 if(switchmode==1) strcpy(mode_txt,"view: c conc mode");
733 if(switchmode==2) strcpy(mode_txt,"view: a pressure mode");
734 d3_lattice_draw(&d3_l,x,y,z,25,arg_v,mode);
735 scan_event(&d3_l,&x,&y,&z,&quit,&escape,&switchmode);
738 d3_lattice_release(&d3_l);