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