]> www.hackdaworld.org Git - physik/posic.git/blob - sic.c
added pair correlation calc code
[physik/posic.git] / sic.c
1 /*
2  * sic.c - investigation of the sic precipitation process of silicon carbide
3  *
4  * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
5  *
6  */
7
8 #include <math.h>
9  
10 #include "moldyn.h"
11
12 /* potential */
13 #include "potentials/harmonic_oscillator.h"
14 #include "potentials/lennard_jones.h"
15 #include "potentials/albe.h"
16
17 #ifdef TERSOFF_ORIG
18 #include "potentials/tersoff_orig.h"
19 #else
20 #include "potentials/tersoff.h"
21 #endif
22
23 //#define INJECT                800
24 #define INJECT          1
25 #define NR_ATOMS        1
26 #define R_C             1.5
27 #define T_C             5.0
28 //#define INJ_LENX      (1*ALBE_LC_SIC)
29 //#define INJ_LENY      (1*ALBE_LC_SIC)
30 //#define INJ_LENZ      (1*ALBE_LC_SIC)
31 #define INJ_LENX        (1*ALBE_LC_SI)
32 #define INJ_LENY        (1*ALBE_LC_SI)
33 #define INJ_LENZ        (1*ALBE_LC_SI)
34 #define INJ_TYPE_SILICON
35 //#define INJ_TYPE_CARBON
36 #define INJ_OFFSET      (ALBE_LC_SI/8.0)
37 #define RELAX_S         20
38
39 #define LCNTX           9
40 #define LCNTY           9
41 #define LCNTZ           9
42 #define PRERUN          40
43 #define POSTRUN         3000
44
45 #define R_TITLE         "Silicon self-interstitial"
46 #define LOG_E           10
47 #define LOG_T           10
48 #define LOG_P           10
49 #define LOG_S           100
50 #define LOG_V           20
51
52 typedef struct s_hp {
53         int a_count;    /* atom count */
54         u8 quit;        /* quit mark */
55         int argc;       /* arg count */
56         char **argv;    /* args */
57 } t_hp;
58
59 int hook_del_atom(void *moldyn,void *hook_params) {
60
61         t_moldyn *md;
62         t_hp *hp;
63
64         md=moldyn;
65         hp=hook_params;
66
67         set_pt_scale(md,0,0,T_SCALE_BERENDSEN,100.0);
68         del_atom(md,2);
69
70         return 0;
71 }
72
73 int hook_add_atom(void *moldyn,void *hook_params) {
74
75         t_moldyn *md;
76         t_3dvec r,v,dist;
77         double d;
78         unsigned char run;
79         int i,j;
80         t_atom *atom;
81         t_hp *hp;
82
83         md=moldyn;
84         hp=hook_params;
85
86         /* quit */
87         if(hp->quit)
88                 return 0;
89
90         /* switch on t scaling */
91         if(md->schedule.count==0)
92                 set_pt_scale(md,0,0,T_SCALE_BERENDSEN,100.0);
93
94         /* last schedule add if there is enough carbon inside */
95         if(hp->a_count==(INJECT*NR_ATOMS)) {
96                 hp->quit=1;
97                 moldyn_add_schedule(md,POSTRUN,1.0);
98                 return 0;
99         }
100
101         /* more relaxing time for too high temperatures */
102         if(md->t-md->t_ref>T_C) {
103                 moldyn_add_schedule(md,RELAX_S,1.0);
104                 return 0;
105         }
106
107         /* inject carbon atoms */
108         printf("injecting another %d atoms ... (-> %d / %d)\n",
109                NR_ATOMS,hp->a_count+NR_ATOMS,INJECT*NR_ATOMS);
110         for(j=0;j<NR_ATOMS;j++) {
111                 run=1;
112                 while(run) {
113                         // tetrahedral
114                         /*
115                         r.x=0.0;
116                         r.y=0.0;
117                         r.z=0.0;
118                         */
119                         // hexagonal
120                         //
121                         r.x=-1.0/8.0*ALBE_LC_SI;
122                         r.y=-1.0/8.0*ALBE_LC_SI;
123                         r.z=1.0/8.0*ALBE_LC_SI;
124                         //
125                         // 110 dumbbell
126                         /*
127                         r.x=(-0.5+0.25+0.125)*ALBE_LC_SI;
128                         r.y=(-0.5+0.25+0.125)*ALBE_LC_SI;
129                         r.z=(-0.5+0.25)*ALBE_LC_SI;
130                         md->atom[4372].r.x=(-0.5+0.125+0.125)*ALBE_LC_SI;
131                         md->atom[4372].r.y=(-0.5+0.125+0.125)*ALBE_LC_SI;
132                         */
133                         // random
134                         /*
135                         r.x=(rand_get_double(&(md->random))-0.5)*INJ_LENX;
136                         r.y=(rand_get_double(&(md->random))-0.5)*INJ_LENY;
137                         r.z=(rand_get_double(&(md->random))-0.5)*INJ_LENZ;
138                         */
139                         // offset
140                         r.x+=INJ_OFFSET;
141                         r.y+=INJ_OFFSET;
142                         r.z+=INJ_OFFSET;
143                         /* assume valid coordinates */
144                         run=0;
145                         for(i=0;i<md->count;i++) {
146                                 atom=&(md->atom[i]);
147                                 v3_sub(&dist,&(atom->r),&r);
148                                 d=v3_absolute_square(&dist);
149                                 /* reject coordinates */
150                                 if(d<R_C) {
151                                         //printf("atom %d - %f\n",i,d);
152                                         run=1;
153                                         break;
154                                 }
155                         }
156                 }
157                 v.x=0; v.y=0; v.z=0;
158 #ifdef INJ_TYPE_CARBON
159                 add_atom(md,C,M_C,1,
160 #else
161                 add_atom(md,SI,M_SI,0,
162 #endif
163                          ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB|ATOM_ATTR_VB,
164                          &r,&v);
165         }
166         hp->a_count+=NR_ATOMS;
167
168         /* add schedule for simulating injected atoms ;) */
169         moldyn_add_schedule(md,RELAX_S,1.0);
170
171         return 0;
172 }
173
174 int main(int argc,char **argv) {
175
176         /* check argv */
177         //if(argc!=3) {
178         //      printf("[sic] usage: %s <logdir> <temperatur>\n",argv[0]);
179         //      return -1;
180         //}
181
182         /* main moldyn structure */
183         t_moldyn md;
184
185         /* hook parameter structure */
186         t_hp hookparam;
187
188         /* potential parameters */
189         t_tersoff_mult_params tp;
190         t_albe_mult_params ap;
191
192         /* testing location & velocity vector */
193         t_3dvec r,v;
194         memset(&r,0,sizeof(t_3dvec));
195         memset(&v,0,sizeof(t_3dvec));
196
197         /* initialize moldyn */
198         moldyn_init(&md,argc,argv);
199
200         /* choose integration algorithm */
201         set_int_alg(&md,MOLDYN_INTEGRATE_VERLET);
202
203         /* choose potential */
204 #ifdef ALBE
205         set_potential3b_j1(&md,albe_mult_3bp_j1);
206         set_potential3b_k1(&md,albe_mult_3bp_k1);
207         set_potential3b_j2(&md,albe_mult_3bp_j2);
208         set_potential3b_k2(&md,albe_mult_3bp_k2);
209 #else
210         set_potential1b(&md,tersoff_mult_1bp);
211         set_potential3b_j1(&md,tersoff_mult_3bp_j1);
212         set_potential3b_k1(&md,tersoff_mult_3bp_k1);
213         set_potential3b_j2(&md,tersoff_mult_3bp_j2);
214         set_potential3b_k2(&md,tersoff_mult_3bp_k2);
215 #endif
216
217 #ifdef ALBE
218         set_potential_params(&md,&ap);
219 #else
220         set_potential_params(&md,&tp);
221 #endif
222
223         /* cutoff radius & bondlen */
224 #ifdef ALBE
225         set_cutoff(&md,ALBE_S_SI);
226         set_bondlen(&md,ALBE_S_SI,ALBE_S_C,ALBE_S_SIC);
227         //set_cutoff(&md,ALBE_S_C);
228 #else
229         set_cutoff(&md,TM_S_SI);
230         set_bondlen(&md,TM_S_SI,TM_S_C,-1.0);
231         //set_cutoff(&md,TM_S_C);
232 #endif
233
234         /*
235          * potential parameters
236          */
237
238         /*
239          * tersoff mult potential parameters for SiC
240          */
241         tp.S[0]=TM_S_SI;
242         tp.R[0]=TM_R_SI;
243         tp.A[0]=TM_A_SI;
244         tp.B[0]=TM_B_SI;
245         tp.lambda[0]=TM_LAMBDA_SI;
246         tp.mu[0]=TM_MU_SI;
247         tp.beta[0]=TM_BETA_SI;
248         tp.n[0]=TM_N_SI;
249         tp.c[0]=TM_C_SI;
250         tp.d[0]=TM_D_SI;
251         tp.h[0]=TM_H_SI;
252
253         tp.S[1]=TM_S_C;
254         tp.R[1]=TM_R_C;
255         tp.A[1]=TM_A_C;
256         tp.B[1]=TM_B_C;
257         tp.lambda[1]=TM_LAMBDA_C;
258         tp.mu[1]=TM_MU_C;
259         tp.beta[1]=TM_BETA_C;
260         tp.n[1]=TM_N_C;
261         tp.c[1]=TM_C_C;
262         tp.d[1]=TM_D_C;
263         tp.h[1]=TM_H_C;
264
265         tp.chi=TM_CHI_SIC;
266
267         tersoff_mult_complete_params(&tp);
268
269         /*
270          * albe mult potential parameters for SiC
271          */
272         ap.S[0]=ALBE_S_SI;
273         ap.R[0]=ALBE_R_SI;
274         ap.A[0]=ALBE_A_SI;
275         ap.B[0]=ALBE_B_SI;
276         ap.r0[0]=ALBE_R0_SI;
277         ap.lambda[0]=ALBE_LAMBDA_SI;
278         ap.mu[0]=ALBE_MU_SI;
279         ap.gamma[0]=ALBE_GAMMA_SI;
280         ap.c[0]=ALBE_C_SI;
281         ap.d[0]=ALBE_D_SI;
282         ap.h[0]=ALBE_H_SI;
283
284         ap.S[1]=ALBE_S_C;
285         ap.R[1]=ALBE_R_C;
286         ap.A[1]=ALBE_A_C;
287         ap.B[1]=ALBE_B_C;
288         ap.r0[1]=ALBE_R0_C;
289         ap.lambda[1]=ALBE_LAMBDA_C;
290         ap.mu[1]=ALBE_MU_C;
291         ap.gamma[1]=ALBE_GAMMA_C;
292         ap.c[1]=ALBE_C_C;
293         ap.d[1]=ALBE_D_C;
294         ap.h[1]=ALBE_H_C;
295
296         ap.Smixed=ALBE_S_SIC;
297         ap.Rmixed=ALBE_R_SIC;
298         ap.Amixed=ALBE_A_SIC;
299         ap.Bmixed=ALBE_B_SIC;
300         ap.r0_mixed=ALBE_R0_SIC;
301         ap.lambda_m=ALBE_LAMBDA_SIC;
302         ap.mu_m=ALBE_MU_SIC;
303         ap.gamma_m=ALBE_GAMMA_SIC;
304         ap.c_mixed=ALBE_C_SIC;
305         ap.d_mixed=ALBE_D_SIC;
306         ap.h_mixed=ALBE_H_SIC;
307
308         albe_mult_complete_params(&ap);
309
310         /* set (initial) dimensions of simulation volume */
311 #ifdef ALBE
312         set_dim(&md,LCNTX*ALBE_LC_SI,LCNTY*ALBE_LC_SI,LCNTZ*ALBE_LC_SI,TRUE);
313         //set_dim(&md,LCNTX*ALBE_LC_C,LCNTY*ALBE_LC_C,LCNTZ*ALBE_LC_C,TRUE);
314         //set_dim(&md,LCNTX*ALBE_LC_SIC,LCNTY*ALBE_LC_SIC,LCNTZ*ALBE_LC_SIC,TRUE);
315 #else
316         set_dim(&md,LCNTX*LC_SI,LCNTY*LC_SI,LCNTZ*LC_SI,TRUE);
317         //set_dim(&md,LCNTX*LC_C,LCNTY*LC_C,LCNTZ*LC_C,TRUE);
318         //set_dim(&md,LCNTX*TM_LC_SIC,LCNTY*TM_LC_SIC,LCNTZ*TM_LC_SIC,TRUE);
319 #endif
320
321         /* set periodic boundary conditions in all directions */
322         set_pbc(&md,TRUE,TRUE,TRUE);
323
324         /* create the lattice / place atoms */
325         //
326 #ifdef ALBE
327         create_lattice(&md,DIAMOND,ALBE_LC_SI,SI,M_SI,
328         //create_lattice(&md,DIAMOND,ALBE_LC_C,C,M_C,
329 #else
330         create_lattice(&md,DIAMOND,LC_SI,SI,M_SI,
331 #endif
332                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
333         //               ATOM_ATTR_2BP|ATOM_ATTR_HB,
334                        0,LCNTX,LCNTY,LCNTZ,NULL);
335         //               1,LCNTX,LCNTY,LCNTZ,NULL);
336         //
337
338         /* create zinkblende structure */
339         /*
340 #ifdef ALBE
341         r.x=0.5*0.25*ALBE_LC_SIC; r.y=r.x; r.z=r.x;
342         create_lattice(&md,FCC,ALBE_LC_SIC,SI,M_SI,
343                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
344                        0,LCNTX,LCNTY,LCNTZ,&r);
345         r.x+=0.25*ALBE_LC_SIC; r.y=r.x; r.z=r.x;
346         create_lattice(&md,FCC,ALBE_LC_SIC,C,M_C,
347                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
348                        1,LCNTX,LCNTY,LCNTZ,&r);
349 #else
350         r.x=0.5*0.25*TM_LC_SIC; r.y=r.x; r.z=r.x;
351         create_lattice(&md,FCC,TM_LC_SIC,SI,M_SI,
352                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
353                        0,LCNTX,LCNTY,LCNTZ,&r);
354         r.x+=0.25*TM_LC_SIC; r.y=r.x; r.z=r.x;
355         create_lattice(&md,FCC,TM_LC_SIC,C,M_C,
356                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
357                        1,LCNTX,LCNTY,LCNTZ,&r);
358 #endif
359         */
360
361         /* check for right atom placing */
362         moldyn_bc_check(&md);
363
364         /* testing configuration */
365         //r.x=0.27*sqrt(3.0)*LC_SI/2.0; v.x=0;
366         //r.x=(TM_S_SI+TM_R_SI)/4.0;    v.x=0;
367         //r.y=0;                v.y=0;
368         //r.z=0;                v.z=0;
369         //add_atom(&md,SI,M_SI,0,
370         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
371         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
372         //           &r,&v);
373         //r.x=-r.x;     v.x=-v.x;
374         //r.y=0;                v.y=0;
375         //r.z=0;                v.z=0;
376         //add_atom(&md,SI,M_SI,0,
377         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
378         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
379         //           &r,&v);
380         //r.z=0.27*sqrt(3.0)*LC_SI/2.0; v.z=0;
381         //r.x=(TM_S_SI+TM_R_SI)/4.0;    v.x=0;
382         //r.y=0;                v.y=0;
383         //r.x=0;                v.x=0;
384         //add_atom(&md,SI,M_SI,0,
385         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
386         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
387         //           &r,&v);
388         //r.z=-r.z;     v.z=-v.z;
389         //r.y=0;                v.y=0;
390         //r.x=0;                v.x=0;
391         //add_atom(&md,SI,M_SI,0,
392         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
393         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
394         //           &r,&v);
395
396         /* set temperature & pressure */
397         set_temperature(&md,atof(argv[2])+273.0);
398         set_pressure(&md,BAR);
399
400         /* set amount of steps to skip before average calc */
401         set_avg_skip(&md,(8.0/10.0*PRERUN));
402
403         /* set p/t scaling */
404         //set_pt_scale(&md,0,0,T_SCALE_BERENDSEN,100.0);
405         //set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,
406         //                 T_SCALE_BERENDSEN,100.0);
407         //set_pt_scale(&md,0,0,T_SCALE_DIRECT,1.0);
408         //set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,0,0);
409         
410         /* initial thermal fluctuations of particles (in equilibrium) */
411         thermal_init(&md,TRUE);
412
413         /* create the simulation schedule */
414         moldyn_add_schedule(&md,PRERUN,1.0);
415
416         /* schedule hook function */
417         memset(&hookparam,0,sizeof(t_hp));
418         hookparam.argc=argc;
419         hookparam.argv=argv;
420         moldyn_set_schedule_hook(&md,&hook_add_atom,&hookparam);
421         //moldyn_set_schedule_hook(&md,&hook_del_atom,&hookparam);
422         //moldyn_add_schedule(&md,POSTRUN,1.0);
423
424         /* activate logging */
425         moldyn_set_log_dir(&md,argv[1]);
426         moldyn_set_report(&md,"Frank Zirkelbach",R_TITLE);
427         moldyn_set_log(&md,LOG_TOTAL_ENERGY,LOG_E);
428         moldyn_set_log(&md,LOG_TEMPERATURE,LOG_T);
429         moldyn_set_log(&md,LOG_PRESSURE,LOG_P);
430         moldyn_set_log(&md,VISUAL_STEP,LOG_V);
431         moldyn_set_log(&md,SAVE_STEP,LOG_S);
432         moldyn_set_log(&md,CREATE_REPORT,0);
433
434         /*
435          * let's do the actual md algorithm now
436          *
437          * integration of newtons equations
438          */
439         moldyn_integrate(&md);
440 #ifdef dEBUG
441 return 0;
442 #endif
443
444         /*
445          * post processing the data
446          */
447
448         /* close */
449         moldyn_shutdown(&md);
450         
451         return 0;
452 }
453