more interstitial testing, added bond visualization
[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          10
43 #define POSTRUN         4000
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                         r.x=1.0/8.0*ALBE_LC_SI;
114                         r.y=-1.0/8.0*ALBE_LC_SI;
115                         r.z=-1.0/8.0*ALBE_LC_SI;
116                         //r.x=(rand_get_double(&(md->random))-0.5)*INJ_LENX;
117                         r.x+=INJ_OFFSET;
118                         //r.y=(rand_get_double(&(md->random))-0.5)*INJ_LENY;
119                         r.y+=INJ_OFFSET;
120                         //r.z=(rand_get_double(&(md->random))-0.5)*INJ_LENZ;
121                         r.z+=INJ_OFFSET;
122                         /* assume valid coordinates */
123                         run=0;
124                         for(i=0;i<md->count;i++) {
125                                 atom=&(md->atom[i]);
126                                 v3_sub(&dist,&(atom->r),&r);
127                                 d=v3_absolute_square(&dist);
128                                 /* reject coordinates */
129                                 if(d<R_C) {
130                                         run=1;
131                                         break;
132                                 }
133                         }
134                 }
135                 v.x=0; v.y=0; v.z=0;
136 #ifdef INJ_TYPE_CARBON
137                 add_atom(md,C,M_C,1,
138 #else
139                 add_atom(md,SI,M_SI,0,
140 #endif
141                          ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB|ATOM_ATTR_VB,
142                          &r,&v);
143         }
144         hp->a_count+=NR_ATOMS;
145
146         /* add schedule for simulating injected atoms ;) */
147         moldyn_add_schedule(md,RELAX_S,1.0);
148
149         return 0;
150 }
151
152 int main(int argc,char **argv) {
153
154         /* check argv */
155         //if(argc!=3) {
156         //      printf("[sic] usage: %s <logdir> <temperatur>\n",argv[0]);
157         //      return -1;
158         //}
159
160         /* main moldyn structure */
161         t_moldyn md;
162
163         /* hook parameter structure */
164         t_hp hookparam;
165
166         /* potential parameters */
167         t_tersoff_mult_params tp;
168         t_albe_mult_params ap;
169
170         /* testing location & velocity vector */
171         t_3dvec r,v;
172         memset(&r,0,sizeof(t_3dvec));
173         memset(&v,0,sizeof(t_3dvec));
174
175         /* initialize moldyn */
176         moldyn_init(&md,argc,argv);
177
178         /* choose integration algorithm */
179         set_int_alg(&md,MOLDYN_INTEGRATE_VERLET);
180
181         /* choose potential */
182 #ifdef ALBE
183         set_potential3b_j1(&md,albe_mult_3bp_j1);
184         set_potential3b_k1(&md,albe_mult_3bp_k1);
185         set_potential3b_j2(&md,albe_mult_3bp_j2);
186         set_potential3b_k2(&md,albe_mult_3bp_k2);
187 #else
188         set_potential1b(&md,tersoff_mult_1bp);
189         set_potential3b_j1(&md,tersoff_mult_3bp_j1);
190         set_potential3b_k1(&md,tersoff_mult_3bp_k1);
191         set_potential3b_j2(&md,tersoff_mult_3bp_j2);
192         set_potential3b_k2(&md,tersoff_mult_3bp_k2);
193 #endif
194
195 #ifdef ALBE
196         set_potential_params(&md,&ap);
197 #else
198         set_potential_params(&md,&tp);
199 #endif
200
201         /* cutoff radius & bondlen */
202 #ifdef ALBE
203         set_cutoff(&md,ALBE_S_SI);
204         set_bondlen(&md,ALBE_S_SI,ALBE_S_C,ALBE_S_SIC);
205         //set_cutoff(&md,ALBE_S_C);
206 #else
207         set_cutoff(&md,TM_S_SI);
208         set_bondlen(&md,TM_S_SI,TM_S_C,-1.0);
209         //set_cutoff(&md,TM_S_C);
210 #endif
211
212         /*
213          * potential parameters
214          */
215
216         /*
217          * tersoff mult potential parameters for SiC
218          */
219         tp.S[0]=TM_S_SI;
220         tp.R[0]=TM_R_SI;
221         tp.A[0]=TM_A_SI;
222         tp.B[0]=TM_B_SI;
223         tp.lambda[0]=TM_LAMBDA_SI;
224         tp.mu[0]=TM_MU_SI;
225         tp.beta[0]=TM_BETA_SI;
226         tp.n[0]=TM_N_SI;
227         tp.c[0]=TM_C_SI;
228         tp.d[0]=TM_D_SI;
229         tp.h[0]=TM_H_SI;
230
231         tp.S[1]=TM_S_C;
232         tp.R[1]=TM_R_C;
233         tp.A[1]=TM_A_C;
234         tp.B[1]=TM_B_C;
235         tp.lambda[1]=TM_LAMBDA_C;
236         tp.mu[1]=TM_MU_C;
237         tp.beta[1]=TM_BETA_C;
238         tp.n[1]=TM_N_C;
239         tp.c[1]=TM_C_C;
240         tp.d[1]=TM_D_C;
241         tp.h[1]=TM_H_C;
242
243         tp.chi=TM_CHI_SIC;
244
245         tersoff_mult_complete_params(&tp);
246
247         /*
248          * albe mult potential parameters for SiC
249          */
250         ap.S[0]=ALBE_S_SI;
251         ap.R[0]=ALBE_R_SI;
252         ap.A[0]=ALBE_A_SI;
253         ap.B[0]=ALBE_B_SI;
254         ap.r0[0]=ALBE_R0_SI;
255         ap.lambda[0]=ALBE_LAMBDA_SI;
256         ap.mu[0]=ALBE_MU_SI;
257         ap.gamma[0]=ALBE_GAMMA_SI;
258         ap.c[0]=ALBE_C_SI;
259         ap.d[0]=ALBE_D_SI;
260         ap.h[0]=ALBE_H_SI;
261
262         ap.S[1]=ALBE_S_C;
263         ap.R[1]=ALBE_R_C;
264         ap.A[1]=ALBE_A_C;
265         ap.B[1]=ALBE_B_C;
266         ap.r0[1]=ALBE_R0_C;
267         ap.lambda[1]=ALBE_LAMBDA_C;
268         ap.mu[1]=ALBE_MU_C;
269         ap.gamma[1]=ALBE_GAMMA_C;
270         ap.c[1]=ALBE_C_C;
271         ap.d[1]=ALBE_D_C;
272         ap.h[1]=ALBE_H_C;
273
274         ap.Smixed=ALBE_S_SIC;
275         ap.Rmixed=ALBE_R_SIC;
276         ap.Amixed=ALBE_A_SIC;
277         ap.Bmixed=ALBE_B_SIC;
278         ap.r0_mixed=ALBE_R0_SIC;
279         ap.lambda_m=ALBE_LAMBDA_SIC;
280         ap.mu_m=ALBE_MU_SIC;
281         ap.gamma_m=ALBE_GAMMA_SIC;
282         ap.c_mixed=ALBE_C_SIC;
283         ap.d_mixed=ALBE_D_SIC;
284         ap.h_mixed=ALBE_H_SIC;
285
286         albe_mult_complete_params(&ap);
287
288         /* set (initial) dimensions of simulation volume */
289 #ifdef ALBE
290         set_dim(&md,LCNTX*ALBE_LC_SI,LCNTY*ALBE_LC_SI,LCNTZ*ALBE_LC_SI,TRUE);
291         //set_dim(&md,LCNTX*ALBE_LC_C,LCNTY*ALBE_LC_C,LCNTZ*ALBE_LC_C,TRUE);
292         //set_dim(&md,LCNTX*ALBE_LC_SIC,LCNTY*ALBE_LC_SIC,LCNTZ*ALBE_LC_SIC,TRUE);
293 #else
294         set_dim(&md,LCNTX*LC_SI,LCNTY*LC_SI,LCNTZ*LC_SI,TRUE);
295         //set_dim(&md,LCNTX*LC_C,LCNTY*LC_C,LCNTZ*LC_C,TRUE);
296         //set_dim(&md,LCNTX*TM_LC_SIC,LCNTY*TM_LC_SIC,LCNTZ*TM_LC_SIC,TRUE);
297 #endif
298
299         /* set periodic boundary conditions in all directions */
300         set_pbc(&md,TRUE,TRUE,TRUE);
301
302         /* create the lattice / place atoms */
303 #ifdef ALBE
304         create_lattice(&md,DIAMOND,ALBE_LC_SI,SI,M_SI,
305         //create_lattice(&md,DIAMOND,ALBE_LC_C,C,M_C,
306 #else
307         create_lattice(&md,DIAMOND,LC_SI,SI,M_SI,
308 #endif
309                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
310         //               ATOM_ATTR_2BP|ATOM_ATTR_HB,
311                        0,LCNTX,LCNTY,LCNTZ,NULL);
312         //               1,LCNTX,LCNTY,LCNTZ,NULL);
313
314         /* create zinkblende structure */
315         /*
316 #ifdef ALBE
317         r.x=0.5*0.25*ALBE_LC_SIC; r.y=r.x; r.z=r.x;
318         create_lattice(&md,FCC,ALBE_LC_SIC,SI,M_SI,
319                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
320                        0,LCNTX,LCNTY,LCNTZ,&r);
321         r.x+=0.25*ALBE_LC_SIC; r.y=r.x; r.z=r.x;
322         create_lattice(&md,FCC,ALBE_LC_SIC,C,M_C,
323                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
324                        1,LCNTX,LCNTY,LCNTZ,&r);
325 #else
326         r.x=0.5*0.25*TM_LC_SIC; r.y=r.x; r.z=r.x;
327         create_lattice(&md,FCC,TM_LC_SIC,SI,M_SI,
328                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
329                        0,LCNTX,LCNTY,LCNTZ,&r);
330         r.x+=0.25*TM_LC_SIC; r.y=r.x; r.z=r.x;
331         create_lattice(&md,FCC,TM_LC_SIC,C,M_C,
332                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
333                        1,LCNTX,LCNTY,LCNTZ,&r);
334 #endif
335         */
336
337         /* check for right atom placing */
338         moldyn_bc_check(&md);
339
340         /* testing configuration */
341         //r.x=0.27*sqrt(3.0)*LC_SI/2.0; v.x=0;
342         //r.x=(TM_S_SI+TM_R_SI)/4.0;    v.x=0;
343         //r.y=0;                v.y=0;
344         //r.z=0;                v.z=0;
345         //add_atom(&md,SI,M_SI,0,
346         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
347         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
348         //           &r,&v);
349         //r.x=-r.x;     v.x=-v.x;
350         //r.y=0;                v.y=0;
351         //r.z=0;                v.z=0;
352         //add_atom(&md,SI,M_SI,0,
353         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
354         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
355         //           &r,&v);
356         //r.z=0.27*sqrt(3.0)*LC_SI/2.0; v.z=0;
357         //r.x=(TM_S_SI+TM_R_SI)/4.0;    v.x=0;
358         //r.y=0;                v.y=0;
359         //r.x=0;                v.x=0;
360         //add_atom(&md,SI,M_SI,0,
361         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
362         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
363         //           &r,&v);
364         //r.z=-r.z;     v.z=-v.z;
365         //r.y=0;                v.y=0;
366         //r.x=0;                v.x=0;
367         //add_atom(&md,SI,M_SI,0,
368         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
369         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
370         //           &r,&v);
371
372         /* set temperature & pressure */
373         set_temperature(&md,atof(argv[2])+273.0);
374         set_pressure(&md,BAR);
375
376         /* set amount of steps to skip before average calc */
377         set_avg_skip(&md,(8.0/10.0*PRERUN));
378
379         /* set p/t scaling */
380         //set_pt_scale(&md,0,0,T_SCALE_BERENDSEN,100.0);
381         //set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,
382         //                 T_SCALE_BERENDSEN,100.0);
383         //set_pt_scale(&md,0,0,T_SCALE_DIRECT,1.0);
384         //set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,0,0);
385         
386         /* initial thermal fluctuations of particles (in equilibrium) */
387         thermal_init(&md,TRUE);
388
389         /* create the simulation schedule */
390         moldyn_add_schedule(&md,PRERUN,1.0);
391
392         /* schedule hook function */
393         memset(&hookparam,0,sizeof(t_hp));
394         hookparam.argc=argc;
395         hookparam.argv=argv;
396         moldyn_set_schedule_hook(&md,&hook_add_atom,&hookparam);
397         //moldyn_set_schedule_hook(&md,&hook_del_atom,&hookparam);
398         //moldyn_add_schedule(&md,POSTRUN,1.0);
399
400         /* activate logging */
401         moldyn_set_log_dir(&md,argv[1]);
402         moldyn_set_report(&md,"Frank Zirkelbach",R_TITLE);
403         moldyn_set_log(&md,LOG_TOTAL_ENERGY,LOG_E);
404         moldyn_set_log(&md,LOG_TEMPERATURE,LOG_T);
405         moldyn_set_log(&md,LOG_PRESSURE,LOG_P);
406         moldyn_set_log(&md,VISUAL_STEP,LOG_V);
407         moldyn_set_log(&md,SAVE_STEP,LOG_S);
408         moldyn_set_log(&md,CREATE_REPORT,0);
409
410         /*
411          * let's do the actual md algorithm now
412          *
413          * integration of newtons equations
414          */
415         moldyn_integrate(&md);
416 #ifdef dEBUG
417 return 0;
418 #endif
419
420         /*
421          * post processing the data
422          */
423
424         /* close */
425         moldyn_shutdown(&md);
426         
427         return 0;
428 }
429