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