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