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