]> www.hackdaworld.org Git - physik/posic.git/blob - sic.c
pair corr calc atom data offset correction
[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
12 /* potential */
13 #include "potentials/harmonic_oscillator.h"
14 #include "potentials/lennard_jones.h"
15 #include "potentials/albe.h"
16 #ifdef TERSOFF_ORIG
17 #include "potentials/tersoff_orig.h"
18 #else
19 #include "potentials/tersoff.h"
20 #endif
21
22 typedef struct s_hp {
23         int prerun_count;       /* prerun count */
24         int insert_count;       /* insert count */
25         int postrun_count;      /* post run count */
26         unsigned char state;    /* current state */
27         int argc;               /* arg count */
28         char **argv;            /* args */
29 } t_hp;
30
31 #define STATE_PRERUN    0x00
32 #define STATE_INSERT    0x01
33 #define STATE_POSTRUN   0x02
34
35 /* include the config file */
36 #include "config.h"
37
38 int insert_atoms(t_moldyn *moldyn) {
39
40         int i,j;
41         u8 run;
42         t_3dvec r,v,dist;
43         double d,dmin;
44
45         t_atom *atom;
46
47         atom=moldyn->atom;
48
49         v.x=0; v.y=0; v.z=0;
50
51         for(j=0;j<INS_ATOMS;j++) {
52                 run=1;
53                 while(run) {
54                         // tetrahedral
55                         /*
56                         r.x=0.0;
57                         r.y=0.0;
58                         r.z=0.0;
59                         */
60                         // hexagonal
61                         /*
62                         r.x=-1.0/8.0*ALBE_LC_SI;
63                         r.y=-1.0/8.0*ALBE_LC_SI;
64                         r.z=1.0/8.0*ALBE_LC_SI;
65                         */
66                         // 110 dumbbell
67                         /*
68                         r.x=(-0.5+0.25+0.125)*ALBE_LC_SI;
69                         r.y=(-0.5+0.25+0.125)*ALBE_LC_SI;
70                         r.z=(-0.5+0.25)*ALBE_LC_SI;
71                         md->atom[4372].r.x=(-0.5+0.125+0.125)*ALBE_LC_SI;
72                         md->atom[4372].r.y=(-0.5+0.125+0.125)*ALBE_LC_SI;
73                         */
74                         // random
75                         //
76                         r.x=(rand_get_double(&(moldyn->random))-0.5)*INS_LENX;
77                         r.y=(rand_get_double(&(moldyn->random))-0.5)*INS_LENY;
78                         r.z=(rand_get_double(&(moldyn->random))-0.5)*INS_LENZ;
79                         //
80                         // offset
81                         r.x+=INS_OFFSET;
82                         r.y+=INS_OFFSET;
83                         r.z+=INS_OFFSET;
84                         /* assume valid coordinates */
85                         run=0;
86                         dmin=10000000000.0;             // for sure too high!
87                         for(i=0;i<moldyn->count;i++) {
88                                 atom=&(moldyn->atom[i]);
89                                 v3_sub(&dist,&(atom->r),&r);
90                                 check_per_bound(moldyn,&dist);
91                                 d=v3_absolute_square(&dist);
92                                 /* reject coordinates */
93                                 if(d<INS_R_C) {
94                                         //printf("atom %d - %f\n",i,d);
95                                         run=1;
96                                         break;
97                                 }
98                                 if(d<dmin)
99                                         dmin=d;
100                         }
101                 }
102                 add_atom(moldyn,INS_TYPE,INS_MASS,INS_BRAND,
103                          ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|\
104                          //ATOM_ATTR_HB|ATOM_ATTR_VB,
105                          ATOM_ATTR_HB,
106                          &r,&v);
107                 printf(" %02d: atom %d | %f %f %f | %f\n",
108                        j,moldyn->count-1,r.x,r.y,r.z,dmin);
109         }
110
111         return 0;
112 }
113
114 int sic_hook(void *moldyn,void *hook_params) {
115
116         t_hp *hp;
117         t_moldyn *md;
118         int steps;
119         double tau;
120         double dt;
121
122         hp=hook_params;
123         md=moldyn;
124
125         tau=1.0;
126         steps=0;
127
128         /* switch on t scaling */
129         if(md->schedule.count==0)
130                 set_pt_scale(md,0,0,T_SCALE_BERENDSEN,100.0);
131
132         /* my lousy state machine ! */
133
134         /* switch to insert state immediately */
135         if(hp->state==STATE_PRERUN)
136                 hp->state=STATE_INSERT;
137
138         /* act according to state */
139         switch(hp->state) {
140                 case STATE_INSERT:
141                         /* assigne values */
142                         steps=INS_RELAX;
143                         tau=INS_TAU;
144                         /* check temperature */
145                         dt=md->t_avg-md->t_ref;
146                         if(dt<0)
147                                 dt=-dt;
148                         if(dt>INS_DELTA_TC)
149                                 break;
150                         /* insert atoms */
151                         hp->insert_count+=1;
152                         printf("   ### insert atoms (%d/%d) ###\n",
153                                hp->insert_count*INS_ATOMS,INS_RUNS*INS_ATOMS);
154                         insert_atoms(md);
155                         /* change state after last insertion */
156                         if(hp->insert_count==INS_RUNS)
157                                 hp->state=STATE_POSTRUN;
158                         break;
159                 case STATE_POSTRUN:
160                         /* assigne values */
161                         steps=POST_RELAX;
162                         tau=POST_TAU;
163                         /* check temperature */
164                         dt=md->t_avg-md->t_ref;
165                         if(dt<0)
166                                 dt=-dt;
167                         if(dt>INS_DELTA_TC)
168                                 break;
169                         /* decrease temperature */
170                         hp->postrun_count+=1;
171                         printf(" ### postrun (%d/%d) ###\n",
172                                hp->postrun_count,POST_RUNS);
173                         set_temperature(md,md->t_ref-POST_DT);
174                         if(hp->postrun_count==POST_RUNS)
175                                 return 0;
176                         break;
177                 default:
178                         printf("[hook] FATAL (default case!?!)\n");
179                         break;
180         }
181
182         /* reset the average counters */
183         average_reset(md);
184
185         /* add schedule */
186         moldyn_add_schedule(md,steps,tau);
187
188         return 0;
189 }
190
191 int main(int argc,char **argv) {
192
193         /* main moldyn structure */
194         t_moldyn md;
195
196         /* hook parameter structure */
197         t_hp hookparam;
198
199         /* potential parameters */
200         t_tersoff_mult_params tp;
201         t_albe_mult_params ap;
202
203         /* testing location & velocity vector */
204         t_3dvec r,v;
205         memset(&r,0,sizeof(t_3dvec));
206         memset(&v,0,sizeof(t_3dvec));
207
208         /* initialize moldyn */
209         moldyn_init(&md,argc,argv);
210
211         /* choose integration algorithm */
212         set_int_alg(&md,MOLDYN_INTEGRATE_VERLET);
213
214         /* choose potential */
215 #ifdef ALBE
216         set_potential3b_j1(&md,albe_mult_3bp_j1);
217         set_potential3b_k1(&md,albe_mult_3bp_k1);
218         set_potential3b_j2(&md,albe_mult_3bp_j2);
219         set_potential3b_k2(&md,albe_mult_3bp_k2);
220 #else
221         set_potential1b(&md,tersoff_mult_1bp);
222         set_potential3b_j1(&md,tersoff_mult_3bp_j1);
223         set_potential3b_k1(&md,tersoff_mult_3bp_k1);
224         set_potential3b_j2(&md,tersoff_mult_3bp_j2);
225         set_potential3b_k2(&md,tersoff_mult_3bp_k2);
226 #endif
227
228 #ifdef ALBE
229         set_potential_params(&md,&ap);
230 #else
231         set_potential_params(&md,&tp);
232 #endif
233
234         /* cutoff radius & bondlen */
235 #ifdef ALBE
236         set_cutoff(&md,ALBE_S_SI);
237         set_bondlen(&md,ALBE_S_SI,ALBE_S_C,ALBE_S_SIC);
238         //set_cutoff(&md,ALBE_S_C);
239 #else
240         set_cutoff(&md,TM_S_SI);
241         set_bondlen(&md,TM_S_SI,TM_S_C,-1.0);
242         //set_cutoff(&md,TM_S_C);
243 #endif
244
245         /*
246          * potential parameters
247          */
248
249         /*
250          * tersoff mult potential parameters for SiC
251          */
252         tp.S[0]=TM_S_SI;
253         tp.R[0]=TM_R_SI;
254         tp.A[0]=TM_A_SI;
255         tp.B[0]=TM_B_SI;
256         tp.lambda[0]=TM_LAMBDA_SI;
257         tp.mu[0]=TM_MU_SI;
258         tp.beta[0]=TM_BETA_SI;
259         tp.n[0]=TM_N_SI;
260         tp.c[0]=TM_C_SI;
261         tp.d[0]=TM_D_SI;
262         tp.h[0]=TM_H_SI;
263
264         tp.S[1]=TM_S_C;
265         tp.R[1]=TM_R_C;
266         tp.A[1]=TM_A_C;
267         tp.B[1]=TM_B_C;
268         tp.lambda[1]=TM_LAMBDA_C;
269         tp.mu[1]=TM_MU_C;
270         tp.beta[1]=TM_BETA_C;
271         tp.n[1]=TM_N_C;
272         tp.c[1]=TM_C_C;
273         tp.d[1]=TM_D_C;
274         tp.h[1]=TM_H_C;
275
276         tp.chi=TM_CHI_SIC;
277
278         tersoff_mult_complete_params(&tp);
279
280         /*
281          * albe mult potential parameters for SiC
282          */
283         ap.S[0]=ALBE_S_SI;
284         ap.R[0]=ALBE_R_SI;
285         ap.A[0]=ALBE_A_SI;
286         ap.B[0]=ALBE_B_SI;
287         ap.r0[0]=ALBE_R0_SI;
288         ap.lambda[0]=ALBE_LAMBDA_SI;
289         ap.mu[0]=ALBE_MU_SI;
290         ap.gamma[0]=ALBE_GAMMA_SI;
291         ap.c[0]=ALBE_C_SI;
292         ap.d[0]=ALBE_D_SI;
293         ap.h[0]=ALBE_H_SI;
294
295         ap.S[1]=ALBE_S_C;
296         ap.R[1]=ALBE_R_C;
297         ap.A[1]=ALBE_A_C;
298         ap.B[1]=ALBE_B_C;
299         ap.r0[1]=ALBE_R0_C;
300         ap.lambda[1]=ALBE_LAMBDA_C;
301         ap.mu[1]=ALBE_MU_C;
302         ap.gamma[1]=ALBE_GAMMA_C;
303         ap.c[1]=ALBE_C_C;
304         ap.d[1]=ALBE_D_C;
305         ap.h[1]=ALBE_H_C;
306
307         ap.Smixed=ALBE_S_SIC;
308         ap.Rmixed=ALBE_R_SIC;
309         ap.Amixed=ALBE_A_SIC;
310         ap.Bmixed=ALBE_B_SIC;
311         ap.r0_mixed=ALBE_R0_SIC;
312         ap.lambda_m=ALBE_LAMBDA_SIC;
313         ap.mu_m=ALBE_MU_SIC;
314         ap.gamma_m=ALBE_GAMMA_SIC;
315         ap.c_mixed=ALBE_C_SIC;
316         ap.d_mixed=ALBE_D_SIC;
317         ap.h_mixed=ALBE_H_SIC;
318
319         albe_mult_complete_params(&ap);
320
321         /* set (initial) dimensions of simulation volume */
322 #ifdef ALBE
323         set_dim(&md,LCNTX*ALBE_LC_SI,LCNTY*ALBE_LC_SI,LCNTZ*ALBE_LC_SI,TRUE);
324         //set_dim(&md,LCNTX*ALBE_LC_C,LCNTY*ALBE_LC_C,LCNTZ*ALBE_LC_C,TRUE);
325         //set_dim(&md,LCNTX*ALBE_LC_SIC,LCNTY*ALBE_LC_SIC,LCNTZ*ALBE_LC_SIC,TRUE);
326 #else
327         set_dim(&md,LCNTX*LC_SI,LCNTY*LC_SI,LCNTZ*LC_SI,TRUE);
328         //set_dim(&md,LCNTX*LC_C,LCNTY*LC_C,LCNTZ*LC_C,TRUE);
329         //set_dim(&md,LCNTX*TM_LC_SIC,LCNTY*TM_LC_SIC,LCNTZ*TM_LC_SIC,TRUE);
330 #endif
331
332         /* set periodic boundary conditions in all directions */
333         set_pbc(&md,TRUE,TRUE,TRUE);
334
335         /* create the lattice / place atoms */
336         //
337 #ifdef ALBE
338         create_lattice(&md,DIAMOND,ALBE_LC_SI,SI,M_SI,
339         //create_lattice(&md,DIAMOND,ALBE_LC_C,C,M_C,
340 #else
341         create_lattice(&md,DIAMOND,LC_SI,SI,M_SI,
342 #endif
343                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
344         //               ATOM_ATTR_2BP|ATOM_ATTR_HB,
345                        0,LCNTX,LCNTY,LCNTZ,NULL);
346         //               1,LCNTX,LCNTY,LCNTZ,NULL);
347
348         /* create zinkblende structure */
349         /*
350 #ifdef ALBE
351         r.x=0.5*0.25*ALBE_LC_SIC; r.y=r.x; r.z=r.x;
352         create_lattice(&md,FCC,ALBE_LC_SIC,SI,M_SI,
353                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
354                        0,LCNTX,LCNTY,LCNTZ,&r);
355         r.x+=0.25*ALBE_LC_SIC; r.y=r.x; r.z=r.x;
356         create_lattice(&md,FCC,ALBE_LC_SIC,C,M_C,
357                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
358                        1,LCNTX,LCNTY,LCNTZ,&r);
359 #else
360         r.x=0.5*0.25*TM_LC_SIC; r.y=r.x; r.z=r.x;
361         create_lattice(&md,FCC,TM_LC_SIC,SI,M_SI,
362                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
363                        0,LCNTX,LCNTY,LCNTZ,&r);
364         r.x+=0.25*TM_LC_SIC; r.y=r.x; r.z=r.x;
365         create_lattice(&md,FCC,TM_LC_SIC,C,M_C,
366                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
367                        1,LCNTX,LCNTY,LCNTZ,&r);
368 #endif
369         */
370
371         /* check for right atom placing */
372         moldyn_bc_check(&md);
373
374         /* testing configuration */
375         //r.x=0.27*sqrt(3.0)*LC_SI/2.0; v.x=0;
376         //r.x=(TM_S_SI+TM_R_SI)/4.0;    v.x=0;
377         //r.y=0;                v.y=0;
378         //r.z=0;                v.z=0;
379         //add_atom(&md,SI,M_SI,0,
380         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
381         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
382         //           &r,&v);
383         //r.x=-r.x;     v.x=-v.x;
384         //r.y=0;                v.y=0;
385         //r.z=0;                v.z=0;
386         //add_atom(&md,SI,M_SI,0,
387         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
388         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
389         //           &r,&v);
390         //r.z=0.27*sqrt(3.0)*LC_SI/2.0; v.z=0;
391         //r.x=(TM_S_SI+TM_R_SI)/4.0;    v.x=0;
392         //r.y=0;                v.y=0;
393         //r.x=0;                v.x=0;
394         //add_atom(&md,SI,M_SI,0,
395         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
396         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
397         //           &r,&v);
398         //r.z=-r.z;     v.z=-v.z;
399         //r.y=0;                v.y=0;
400         //r.x=0;                v.x=0;
401         //add_atom(&md,SI,M_SI,0,
402         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
403         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
404         //           &r,&v);
405
406         /* set temperature & pressure */
407         set_temperature(&md,atof(argv[2])+273.0);
408         set_pressure(&md,BAR);
409
410         /* set amount of steps to skip before average calc */
411         set_avg_skip(&md,AVG_SKIP);
412
413         /* set p/t scaling */
414         //set_pt_scale(&md,0,0,T_SCALE_BERENDSEN,100.0);
415         //set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,
416         //                 T_SCALE_BERENDSEN,100.0);
417         //set_pt_scale(&md,0,0,T_SCALE_DIRECT,1.0);
418         //set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,0,0);
419         
420         /* initial thermal fluctuations of particles (in equilibrium) */
421         thermal_init(&md,TRUE);
422
423         /* create the simulation schedule */
424         moldyn_add_schedule(&md,PRERUN,PRE_TAU);
425
426         /* schedule hook function */
427         memset(&hookparam,0,sizeof(t_hp));
428         hookparam.argc=argc;
429         hookparam.argv=argv;
430         moldyn_set_schedule_hook(&md,&sic_hook,&hookparam);
431         //moldyn_set_schedule_hook(&md,&hook_del_atom,&hookparam);
432         //moldyn_add_schedule(&md,POSTRUN,1.0);
433
434         /* activate logging */
435         moldyn_set_log_dir(&md,argv[1]);
436         moldyn_set_report(&md,"Frank Zirkelbach",R_TITLE);
437         moldyn_set_log(&md,LOG_TOTAL_ENERGY,LOG_E);
438         moldyn_set_log(&md,LOG_TEMPERATURE,LOG_T);
439         moldyn_set_log(&md,LOG_PRESSURE,LOG_P);
440         moldyn_set_log(&md,VISUAL_STEP,LOG_V);
441         moldyn_set_log(&md,SAVE_STEP,LOG_S);
442         moldyn_set_log(&md,CREATE_REPORT,0);
443
444         /* next neighbour distance for critical checking */
445         set_nn_dist(&md,0.25*ALBE_LC_SI*sqrt(3.0));
446
447         /*
448          * let's do the actual md algorithm now
449          *
450          * integration of newtons equations
451          */
452         moldyn_integrate(&md);
453 #ifdef dEBUG
454 return 0;
455 #endif
456
457         /*
458          * post processing the data
459          */
460
461         /* close */
462         moldyn_shutdown(&md);
463         
464         return 0;
465 }
466