albe force calc bug fixed, sic mods, mean virial
[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        4
26
27 int hook(void *moldyn,void *hook_params) {
28
29         t_moldyn *md;
30         t_3dvec r,v,dist;
31         double d;
32         unsigned char run;
33         int i,j;
34         t_atom *atom;
35
36         md=moldyn;
37
38         printf("\nschedule hook: ");
39
40         if(!(md->schedule.count%2)) {
41                 /* add carbon at random place, and enable t scaling */
42                 for(j=0;j<NR_ATOMS;j++) {
43                 run=1;
44                 while(run) {
45                         r.x=rand_get_double(&(md->random))*md->dim.x;
46                         r.y=rand_get_double(&(md->random))*md->dim.y;
47                         r.z=rand_get_double(&(md->random))*md->dim.z;
48                         for(i=0;i<md->count;i++) {
49                                 atom=&(md->atom[i]);
50                                 v3_sub(&dist,&(atom->r),&r);
51                                 d=v3_absolute_square(&dist);
52                                 if(d>TM_R_C)
53                                         run=0;
54                         }
55                 }
56                 v.x=0; v.y=0; v.z=0;
57                 add_atom(md,C,M_C,1,
58                          ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
59                          &r,&v);
60                 }
61                 printf("adding atoms & enable t scaling\n");
62                 set_pt_scale(md,0,0,T_SCALE_BERENDSEN,100.0);
63         }
64         else {
65                 /* disable t scaling */
66                 printf("disabling t scaling\n");
67                 set_pt_scale(md,0,0,0,0);
68         }
69
70         return 0;
71 }
72
73 int main(int argc,char **argv) {
74
75         /* check argv */
76         if(argc!=3) {
77                 printf("[sic] usage: %s <logdir> <temperatur>\n",argv[0]);
78                 return -1;
79         }
80
81         /* main moldyn structure */
82         t_moldyn md;
83
84         /* potential parameters */
85         t_tersoff_mult_params tp;
86         t_albe_mult_params ap;
87
88         /* atom injection counter */
89         int inject;
90
91         /* testing location & velocity vector */
92         t_3dvec r,v;
93         memset(&r,0,sizeof(t_3dvec));
94         memset(&v,0,sizeof(t_3dvec));
95
96         /* initialize moldyn */
97         moldyn_init(&md,argc,argv);
98
99         /* choose integration algorithm */
100         set_int_alg(&md,MOLDYN_INTEGRATE_VERLET);
101
102         /* choose potential */
103 #ifdef ALBE
104         set_potential3b_j1(&md,albe_mult_3bp_j1);
105         set_potential3b_k1(&md,albe_mult_3bp_k1);
106         set_potential3b_j2(&md,albe_mult_3bp_j2);
107         set_potential3b_k2(&md,albe_mult_3bp_k2);
108 #else
109         set_potential1b(&md,tersoff_mult_1bp);
110         set_potential3b_j1(&md,tersoff_mult_3bp_j1);
111         set_potential3b_k1(&md,tersoff_mult_3bp_k1);
112         set_potential3b_j2(&md,tersoff_mult_3bp_j2);
113         set_potential3b_k2(&md,tersoff_mult_3bp_k2);
114 #endif
115
116 #ifdef ALBE
117         set_potential_params(&md,&ap);
118 #else
119         set_potential_params(&md,&tp);
120 #endif
121
122         /* cutoff radius */
123 #ifdef ALBE
124         set_cutoff(&md,ALBE_S_SI);
125 #else
126         set_cutoff(&md,TM_S_SI);
127 #endif
128
129         /*
130          * potential parameters
131          */
132
133         /*
134          * tersoff mult potential parameters for SiC
135          */
136         tp.S[0]=TM_S_SI;
137         tp.R[0]=TM_R_SI;
138         tp.A[0]=TM_A_SI;
139         tp.B[0]=TM_B_SI;
140         tp.lambda[0]=TM_LAMBDA_SI;
141         tp.mu[0]=TM_MU_SI;
142         tp.beta[0]=TM_BETA_SI;
143         tp.n[0]=TM_N_SI;
144         tp.c[0]=TM_C_SI;
145         tp.d[0]=TM_D_SI;
146         tp.h[0]=TM_H_SI;
147
148         tp.S[1]=TM_S_C;
149         tp.R[1]=TM_R_C;
150         tp.A[1]=TM_A_C;
151         tp.B[1]=TM_B_C;
152         tp.lambda[1]=TM_LAMBDA_C;
153         tp.mu[1]=TM_MU_C;
154         tp.beta[1]=TM_BETA_C;
155         tp.n[1]=TM_N_C;
156         tp.c[1]=TM_C_C;
157         tp.d[1]=TM_D_C;
158         tp.h[1]=TM_H_C;
159
160         tp.chi=TM_CHI_SIC;
161
162         tersoff_mult_complete_params(&tp);
163
164         /*
165          * albe mult potential parameters for SiC
166          */
167         ap.S[0]=ALBE_S_SI;
168         ap.R[0]=ALBE_R_SI;
169         ap.A[0]=ALBE_A_SI;
170         ap.B[0]=ALBE_B_SI;
171         ap.r0[0]=ALBE_R0_SI;
172         ap.lambda[0]=ALBE_LAMBDA_SI;
173         ap.mu[0]=ALBE_MU_SI;
174         ap.gamma[0]=ALBE_GAMMA_SI;
175         ap.c[0]=ALBE_C_SI;
176         ap.d[0]=ALBE_D_SI;
177         ap.h[0]=ALBE_H_SI;
178
179         ap.S[1]=ALBE_S_C;
180         ap.R[1]=ALBE_R_C;
181         ap.A[1]=ALBE_A_C;
182         ap.B[1]=ALBE_B_C;
183         ap.r0[1]=ALBE_R0_C;
184         ap.lambda[1]=ALBE_LAMBDA_C;
185         ap.mu[1]=ALBE_MU_C;
186         ap.gamma[1]=ALBE_GAMMA_C;
187         ap.c[1]=ALBE_C_C;
188         ap.d[1]=ALBE_D_C;
189         ap.h[1]=ALBE_H_C;
190
191         ap.Smixed=ALBE_S_SIC;
192         ap.Rmixed=ALBE_R_SIC;
193         ap.Amixed=ALBE_A_SIC;
194         ap.Bmixed=ALBE_B_SIC;
195         ap.r0_mixed=ALBE_R0_SIC;
196         ap.lambda_m=ALBE_LAMBDA_SIC;
197         ap.mu_m=ALBE_MU_SIC;
198         ap.gamma_m=ALBE_GAMMA_SIC;
199         ap.c_mixed=ALBE_C_SIC;
200         ap.d_mixed=ALBE_D_SIC;
201         ap.h_mixed=ALBE_H_SIC;
202
203         albe_mult_complete_params(&ap);
204
205         /* set (initial) dimensions of simulation volume */
206         //set_dim(&md,6*LC_SI_ALBE,6*LC_SI_ALBE,6*LC_SI_ALBE,TRUE);
207         //set_dim(&md,6*LC_SI,6*LC_SI,6*LC_SI,TRUE);
208         //set_dim(&md,6*LC_C_ALBE,6*LC_C_ALBE,6*LC_C_ALBE,TRUE);
209         //set_dim(&md,6*LC_C,6*LC_C,6*LC_C,TRUE);
210         set_dim(&md,6*LC_SIC_ALBE,6*LC_SIC_ALBE,6*LC_SIC_ALBE,TRUE);
211
212         /* set periodic boundary conditions in all directions */
213         set_pbc(&md,TRUE,TRUE,TRUE);
214
215         /* create the lattice / place atoms */
216         //create_lattice(&md,DIAMOND,LC_SI,SI,M_SI,
217         //create_lattice(&md,DIAMOND,LC_C_ALBE,C,M_C,
218         //create_lattice(&md,DIAMOND,LC_SI_ALBE,SI,M_SI,
219         //               ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
220         //               ATOM_ATTR_2BP|ATOM_ATTR_HB,
221         //               0,6,6,6,NULL);
222         //               1,6,6,6,NULL);
223
224         /* create centered zinc blende lattice */
225         /**/
226         r.x=0.5*0.25*LC_SIC_ALBE; r.y=r.x; r.z=r.x;
227         create_lattice(&md,FCC,LC_SIC_ALBE,SI,M_SI,
228                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
229                        0,6,6,6,&r);
230         r.x+=0.25*LC_SIC_ALBE; r.y=r.x; r.z=r.x;
231         create_lattice(&md,FCC,LC_SIC_ALBE,C,M_C,
232                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
233                        1,6,6,6,&r);
234         /**/
235
236         moldyn_bc_check(&md);
237
238         /* testing configuration */
239         //r.x=0.27*sqrt(3.0)*LC_SI/2.0; v.x=0;
240         //r.x=(TM_S_SI+TM_R_SI)/4.0;    v.x=0;
241         //r.y=0;                v.y=0;
242         //r.z=0;                v.z=0;
243         //add_atom(&md,SI,M_SI,0,
244         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
245         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
246         //           &r,&v);
247         //r.x=-r.x;     v.x=-v.x;
248         //r.y=0;                v.y=0;
249         //r.z=0;                v.z=0;
250         //add_atom(&md,SI,M_SI,0,
251         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
252         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
253         //           &r,&v);
254         //r.z=0.27*sqrt(3.0)*LC_SI/2.0; v.z=0;
255         //r.x=(TM_S_SI+TM_R_SI)/4.0;    v.x=0;
256         //r.y=0;                v.y=0;
257         //r.x=0;                v.x=0;
258         //add_atom(&md,SI,M_SI,0,
259         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
260         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
261         //           &r,&v);
262         //r.z=-r.z;     v.z=-v.z;
263         //r.y=0;                v.y=0;
264         //r.x=0;                v.x=0;
265         //add_atom(&md,SI,M_SI,0,
266         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
267         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
268         //           &r,&v);
269
270         /* set temperature & pressure */
271         set_temperature(&md,atof(argv[2])+273.0);
272         set_pressure(&md,BAR);
273
274         /* set p/t scaling */
275         //set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,
276         //                 T_SCALE_BERENDSEN,100.0);
277         //set_pt_scale(&md,0,0,T_SCALE_DIRECT,1.0);
278         //set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,0,0);
279         
280         /* initial thermal fluctuations of particles (in equilibrium) */
281         thermal_init(&md,TRUE);
282
283         /* create the simulation schedule */
284         /* initial configuration */
285         moldyn_add_schedule(&md,10000,1.0);
286         /* adding atoms */
287         //for(inject=0;inject<INJECT;inject++) {
288         //      /* injecting atom and run with enabled t scaling */
289         //      moldyn_add_schedule(&md,900,1.0);
290         //      /* continue running with disabled t scaling */
291         //      moldyn_add_schedule(&md,1100,1.0);
292         //}
293
294         /* schedule hook function */
295         moldyn_set_schedule_hook(&md,&hook,NULL);
296
297         /* activate logging */
298         moldyn_set_log_dir(&md,argv[1]);
299         moldyn_set_report(&md,"Frank Zirkelbach","Test 1");
300         moldyn_set_log(&md,LOG_TOTAL_ENERGY,1);
301         moldyn_set_log(&md,LOG_TEMPERATURE,1);
302         moldyn_set_log(&md,LOG_PRESSURE,1);
303         moldyn_set_log(&md,VISUAL_STEP,100);
304         moldyn_set_log(&md,SAVE_STEP,100);
305         moldyn_set_log(&md,CREATE_REPORT,0);
306
307         /*
308          * let's do the actual md algorithm now
309          *
310          * integration of newtons equations
311          */
312         moldyn_integrate(&md);
313 #ifdef DEBUG
314 return 0;
315 #endif
316
317         /* close */
318         moldyn_shutdown(&md);
319         
320         return 0;
321 }
322