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