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