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