4 * this program tries helping to understand the amorphous depuration
5 * and recrystallization of SiCx while ion implanation. hopefully the program
6 * will simulate the stabilization of the selforganizing structure in the
10 * - J. K. N. Lindner. Habilationsschrift, Universitaet Augsburg.
11 * - Maik Haeberlen. Diplomarbeit, Universitaet Augsburg.
17 #include <sys/types.h>
21 /* important defines */
24 /* function prototypes */
28 /* global variables */
29 u32 *rand_buf,*rand_current;
30 char random_file[MAX_CHARS_RANDOM_FILE];
32 int random_fd; /* /dev/urandom file descriptor */
38 printf("-a <value> \t slope of nuclear energy loss (default %d)\n",DEFAULT_SLOPE_NEL);
39 printf("-c <value> \t nuclear enery loss at depths 0 (default %d)\n",DEFAULT_START_NEL);
40 printf("-x <value> \t # x cells (default %d)\n",DEFAULT_X_SEG);
41 printf("-y <value> \t # y cells (default %d)\n",DEFAULT_Y_SEG);
42 printf("-z <value> \t # z cells (default %d)\n",DEFAULT_Z_SEG);
43 printf("-s <value> \t # steps to calculate (default %d)\n",DEFAULT_STEPS);
44 puts("-X <value> \t display area intercept point x (default # x celss / 2)");
45 puts("-Y <value> \t display area intercept point y (default # y cells / 2)");
46 puts("-Z <value> \t display area intercept point z (default # z cells / 2)");
47 printf("-d <value> \t refresh every <value> loops (default %d)\n",DEFAULT_DISPLAY_REF_RATE);
48 printf("-r <value> \t pressure range from amorphous SiCx (default %d)\n",DEFAULT_A_P_RANGE);
49 printf("-f <value> \t faktor for pressure from amorphous SiCx (default %f)\n",DEFAULT_A_P_FAKTOR);
50 printf("-p <value> \t p0 for probability of cell getting amorph (default %f)\n",DEFAULT_A_P_P0);
51 printf("-C <value> \t C start concentration (default %d)\n",DEFAULT_C_DIST_START_CONC);
52 printf("-S <value> \t slope of linear C distribution (default %d)\n",DEFAULT_C_DIST_SLOPE);
53 puts("-R <file> \t read random datat from file (default not used)");
57 int make_amorph(cell *cell)
63 int make_cryst(cell *cell)
65 cell->status&=~AMORPH;
69 int distrib_c_conc(cell *cell_p,int c_c0,int c_slope,u32 c_conc,u32 x_max,u32 y_max,u32 z_max)
72 u32 area,c_area,total,count;
77 sum_c_z=c_c0*z_max+c_slope*gr;
82 c_area=(c_conc*(c_c0+(i+1)*c_slope))/sum_c_z;
85 if(!(cell_p+j+i*area)->status&AMORPH) count++;
89 if(!(cell_p+j+i*area)->status&AMORPH)
91 (cell_p+j+i*area)->conc=c_area/count;
100 if(!(cell_p+x+y*x_max+i*area)->status&AMORPH)
102 (cell_p+x+y*x_max+i*area)->conc+=1;
109 while(i<c_conc-total)
113 z=rand_get_lgp(c_slope,c_c0,z_max);
114 if(!(cell_p+x+y*x_max+z*area)->status&AMORPH)
116 (cell_p+x+y*x_max+z*area)->conc+=1;
123 /* look at cell ... */
124 int process_cell(cell *cell_p,u32 x,u32 y,u32 z,u32 x_max,u32 y_max,u32 z_max,int range,double faktor,double p0,u32 *c_conc)
130 this_cell=cell_p+x+y*x_max+z*x_max*y_max;
131 pressure=p0*URAND_2BYTE_MAX;
133 for(i=-range;i<=range;i++)
135 for(j=-range;j<=range;j++)
137 // z relaxation, no pressure in z direction
138 // for(k=-range;k<=range;k++)
140 if(!(i==0 && j==0)) // && k==0))
142 // if((cell_p+((x+x_max+i)%x_max)+((y+j+y_max)%y_max)*x_max+((z+k+z_max)%z_max)*x_max*y_max)->status&AMORPH) pressure+=faktor*URAND_2BYTE_MAX/(i*i+j*j+k*k);
143 if((cell_p+((x+x_max+i)%x_max)+((y+j+y_max)%y_max)*x_max+z*x_max*y_max)->status&AMORPH) pressure+=faktor*URAND_2BYTE_MAX/(i*i+j*j);
148 pressure*=this_cell->conc;
149 if(this_cell->status&AMORPH)
151 /* wrong probability! just test by now ...*/
152 if(rand_get(URAND_2BYTE_MAX)>pressure)
154 make_cryst(this_cell);
155 *c_conc=*c_conc+1+this_cell->conc;
159 if(rand_get(URAND_2BYTE_MAX)<=pressure)
161 make_amorph(this_cell);
162 *c_conc=*c_conc+1-this_cell->conc;
168 int main(int argc,char **argv)
170 u32 x_cell,y_cell,z_cell; /* amount of segments */
171 u32 x,y,z; /* cells */
172 int i; /* for counting */
173 int slope_nel,start_nel; /* nuclear energy loss: slope, constant */
174 int a_p_range; /* p. range of amorphous sic */
175 double a_p_faktor,a_p_p0; /* p0 and faktor of amorphous sic */
176 int c_dist_c0,c_dist_slope; /* c start concentration and linear slope of c distribution */
178 int steps; /* # steps */
180 struct __display display;
181 u32 display_x,display_y,display_z; /* intercept point of diplayed areas */
182 u32 display_refresh_rate; /* refresh rate for display */
183 int quit=0; /* continue/quit status */
185 printfd("debug: sizeof my u32 variable: %d\n",sizeof(u32));
186 printfd("debug: sizeof my cell struct: %d\n",sizeof(cell));
189 x_cell=DEFAULT_X_SEG;
190 y_cell=DEFAULT_Y_SEG;
191 z_cell=DEFAULT_Z_SEG;
192 slope_nel=DEFAULT_SLOPE_NEL;
193 start_nel=DEFAULT_START_NEL;
194 a_p_range=DEFAULT_A_P_RANGE;
195 a_p_faktor=DEFAULT_A_P_FAKTOR;
196 a_p_p0=DEFAULT_A_P_P0;
197 c_dist_c0=DEFAULT_C_DIST_START_CONC;
198 c_dist_slope=DEFAULT_C_DIST_SLOPE;
204 display_refresh_rate=DEFAULT_DISPLAY_REF_RATE;
205 strcpy(random_file,"");
207 /* parse command args */
219 slope_nel=atoi(argv[++i]);
222 start_nel=atoi(argv[++i]);
225 x_cell=atoi(argv[++i]);
228 y_cell=atoi(argv[++i]);
231 z_cell=atoi(argv[++i]);
234 steps=atoi(argv[++i]);
237 display_x=atoi(argv[++i]);
240 display_y=atoi(argv[++i]);
243 display_z=atoi(argv[++i]);
246 display_refresh_rate=atoi(argv[++i]);
249 a_p_range=atoi(argv[++i]);
252 a_p_faktor=atof(argv[++i]);
255 a_p_p0=atof(argv[++i]);
258 c_conc=atoi(argv[++i]);
261 c_dist_c0=atoi(argv[++i]);
264 c_dist_slope=atoi(argv[++i]);
267 strcpy(random_file,argv[++i]);
277 if(!strcmp(random_file,""))
279 if((random_fd=open("/dev/urandom",O_RDONLY))<0)
281 puts("cannot open /dev/urandom");
286 if((random_fd=open(random_file,O_RDONLY))<0)
288 puts("cannot open random file");
292 /* allocate random number buffer */
293 printf("malloc will free %d bytes now ...\n",RAND_BUF_SIZE);
294 if((rand_buf=(u32 *)malloc(RAND_BUF_SIZE))==NULL)
296 puts("failed allocating memory for random numbers");
299 rand_current=rand_buf+RAND_BUF_SIZE;
301 /* calculate gr one time! */
303 for(i=1;i<=z_cell;i++) gr+=i;
304 printfd("debug: gr = %d\n",gr);
307 printf("malloc will free %d bytes now ...\n",x_cell*y_cell*z_cell*sizeof(cell));
308 if((cell_p=(cell *)malloc(x_cell*y_cell*z_cell*sizeof(cell)))==NULL)
310 puts("failed allocating memory for cells");
313 memset(cell_p,0,x_cell*y_cell*z_cell*sizeof(cell));
316 printfd("debug: init display now ...\n");
317 display_init(x_cell,y_cell,z_cell,&display,cell_p,&argc,argv);
320 printfd("debug: starting main routine ...\n");
321 for(display.step=0;display.step<steps;display.step++)
325 z=rand_get_lgp(slope_nel,start_nel,z_cell);
328 distrib_c_conc(cell_p,c_dist_c0,c_dist_slope,c_conc,x_cell,y_cell,z_cell);
330 process_cell(cell_p,x,y,z,x_cell,y_cell,z_cell,a_p_range,a_p_faktor,a_p_p0,&c_conc);
333 if((display.step%display_refresh_rate)==0)
334 display_draw(&display,display_x,display_y,display_z);
336 printfd("debug: main routine finished!\n");
338 /* display again and listen for events */
339 display_draw(&display,display_x,display_y,display_z);
340 display_event_init(&display);
344 display_scan_event(&display,&display_x,&display_y,&display_z,&quit);
345 display_draw(&display,display_x,display_y,display_z);
348 display_release(&display);