improved log/report subsystem, playing around w/ pressure, sic hook
[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/tersoff.h"
17
18 #define INJECT          20
19 #define NR_ATOMS        20      
20
21 int hook(void *moldyn,void *hook_params) {
22
23         t_moldyn *md;
24         t_3dvec r,v,dist;
25         double d;
26         unsigned char run;
27         int i,j;
28         t_atom *atom;
29
30         md=moldyn;
31
32         printf("\nschedule hook: ");
33
34         if(!(md->schedule.count%2)) {
35                 /* add carbon at random place, and enable t scaling */
36                 for(j=0;j<NR_ATOMS;j++) {
37                 run=1;
38                 while(run) {
39                         r.x=rand_get_double(&(md->random))*md->dim.x;
40                         r.y=rand_get_double(&(md->random))*md->dim.y;
41                         r.z=rand_get_double(&(md->random))*md->dim.z;
42                         for(i=0;i<md->count;i++) {
43                                 atom=&(md->atom[i]);
44                                 v3_sub(&dist,&(atom->r),&r);
45                                 d=v3_absolute_square(&dist);
46                                 if(d>TM_R_C)
47                                         run=0;
48                         }
49                 }
50                 v.x=0; v.y=0; v.z=0;
51                 add_atom(md,C,M_C,1,
52                          ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
53                          &r,&v);
54                 }
55                 printf("adding atoms & enable t scaling\n");
56                 set_pt_scale(md,0,0,T_SCALE_BERENDSEN,100.0);
57         }
58         else {
59                 /* disable t scaling */
60                 printf("disabling t scaling\n");
61                 set_pt_scale(md,0,0,0,0);
62         }
63
64         return 0;
65 }
66
67 int main(int argc,char **argv) {
68
69         /* check argv */
70         if(argc!=3) {
71                 printf("[sic] usage: %s <logdir> <temperatur>\n",argv[0]);
72                 return -1;
73         }
74
75         /* main moldyn structure */
76         t_moldyn md;
77
78         /* potential parameters */
79         t_lj_params lj;
80         t_ho_params ho;
81         t_tersoff_mult_params tp;
82
83         /* atom injection counter */
84         int inject;
85
86         /* testing location & velocity vector */
87         t_3dvec r,v;
88         memset(&r,0,sizeof(t_3dvec));
89         memset(&v,0,sizeof(t_3dvec));
90
91         /* initialize moldyn */
92         moldyn_init(&md,argc,argv);
93
94         /* choose integration algorithm */
95         set_int_alg(&md,MOLDYN_INTEGRATE_VERLET);
96
97         /* choose potential */
98         set_potential1b(&md,tersoff_mult_1bp);
99         set_potential2b(&md,tersoff_mult_2bp);
100         set_potential2b_post(&md,tersoff_mult_post_2bp);
101         set_potential3b(&md,tersoff_mult_3bp);
102         //set_potential2b(&md,lennard_jones);
103         //set_potential2b(&md,harmonic_oscillator);
104         set_potential_params(&md,&tp);
105         //set_potential_params(&md,&lj);
106         //set_potential_params(&md,&ho);
107
108         /* cutoff radius */
109         set_cutoff(&md,TM_S_SI);
110         //set_cutoff(&md,LC_SI*sqrt(3.0));
111         //set_cutoff(&md,2.0*LC_SI);
112
113         /*
114          * potential parameters
115          */
116
117         /* lennard jones */
118         lj.sigma6=LJ_SIGMA_SI*LJ_SIGMA_SI*LJ_SIGMA_SI;
119         lj.sigma6*=lj.sigma6;
120         lj.sigma12=lj.sigma6*lj.sigma6;
121         lj.epsilon4=4.0*LJ_EPSILON_SI;
122         lj.uc=lj.epsilon4*(lj.sigma12/pow(md.cutoff,12.0)-lj.sigma6/pow(md.cutoff,6));
123
124         /* harmonic oscillator */
125         ho.equilibrium_distance=0.25*sqrt(3.0)*LC_SI;
126         //ho.equilibrium_distance=LC_SI;
127         ho.spring_constant=LJ_EPSILON_SI;
128
129         /*
130          * tersoff mult potential parameters for SiC
131          */
132         tp.S[0]=TM_S_SI;
133         tp.R[0]=TM_R_SI;
134         tp.A[0]=TM_A_SI;
135         tp.B[0]=TM_B_SI;
136         tp.lambda[0]=TM_LAMBDA_SI;
137         tp.mu[0]=TM_MU_SI;
138         tp.beta[0]=TM_BETA_SI;
139         tp.n[0]=TM_N_SI;
140         tp.c[0]=TM_C_SI;
141         tp.d[0]=TM_D_SI;
142         tp.h[0]=TM_H_SI;
143
144         tp.S[1]=TM_S_C;
145         tp.R[1]=TM_R_C;
146         tp.A[1]=TM_A_C;
147         tp.B[1]=TM_B_C;
148         tp.lambda[1]=TM_LAMBDA_C;
149         tp.mu[1]=TM_MU_C;
150         tp.beta[1]=TM_BETA_C;
151         tp.n[1]=TM_N_C;
152         tp.c[1]=TM_C_C;
153         tp.d[1]=TM_D_C;
154         tp.h[1]=TM_H_C;
155
156         tp.chi=TM_CHI_SIC;
157
158         tersoff_mult_complete_params(&tp);
159
160         /* set (initial) dimensions of simulation volume */
161         set_dim(&md,6*LC_SI,6*LC_SI,6*LC_SI,TRUE);
162
163         /* set periodic boundary conditions in all directions */
164         set_pbc(&md,TRUE,TRUE,TRUE);
165
166         /* create the lattice / place atoms */
167         //create_lattice(&md,CUBIC,LC_SI,SI,M_SI,
168         //create_lattice(&md,FCC,LC_SI,SI,M_SI,
169         create_lattice(&md,DIAMOND,LC_SI,SI,M_SI,
170                        ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
171         //               ATOM_ATTR_2BP|ATOM_ATTR_HB,
172                        0,6,6,6);
173         moldyn_bc_check(&md);
174
175         /* testing configuration */
176         //r.x=0.27*sqrt(3.0)*LC_SI/2.0; v.x=0;
177         //r.x=(TM_S_SI+TM_R_SI)/4.0;    v.x=0;
178         //r.y=0;                v.y=0;
179         //r.z=0;                v.z=0;
180         //add_atom(&md,SI,M_SI,0,
181         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
182         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
183         //           &r,&v);
184         //r.x=-r.x;     v.x=-v.x;
185         //r.y=0;                v.y=0;
186         //r.z=0;                v.z=0;
187         //add_atom(&md,SI,M_SI,0,
188         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
189         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
190         //           &r,&v);
191         //r.x=0;                v.x=0;
192         //r.y=0;        v.y=0;
193         //r.z=sin(M_PI*60.0/180.0)*(TM_S_SI+TM_R_SI)/4.0;       v.z=0;
194         //add_atom(&md,SI,M_SI,0,
195         //           ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
196         //           ATOM_ATTR_2BP|ATOM_ATTR_HB,
197         //           &r,&v);
198
199         /* set temperature & pressure */
200         set_temperature(&md,atof(argv[2])+273.0);
201         set_pressure(&md,ATM);
202
203         /* set p/t scaling */
204         //set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,
205         //                 T_SCALE_BERENDSEN,100.0);
206         //set_pt_scale(&md,0,0,T_SCALE_DIRECT,1.0);
207         //set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,0,0);
208         
209         /* initial thermal fluctuations of particles (in equilibrium) */
210         thermal_init(&md,TRUE);
211
212         /* create the simulation schedule */
213         /* initial configuration */
214         moldyn_add_schedule(&md,500,1.0);
215         /* adding atoms */
216         for(inject=0;inject<INJECT;inject++) {
217                 /* injecting atom and run with enabled t scaling */
218                 moldyn_add_schedule(&md,400,1.0);
219                 /* continue running with disabled t scaling */
220                 moldyn_add_schedule(&md,100,1.0);
221         }
222
223         /* schedule hook function */
224         moldyn_set_schedule_hook(&md,&hook,NULL);
225
226         /* activate logging */
227         moldyn_set_log_dir(&md,argv[1]);
228         moldyn_set_report(&md,"Frank Zirkelbach","Test 1");
229         moldyn_set_log(&md,LOG_TOTAL_ENERGY,10);
230         moldyn_set_log(&md,LOG_TEMPERATURE,10);
231         moldyn_set_log(&md,LOG_PRESSURE,10);
232         moldyn_set_log(&md,VISUAL_STEP,100);
233         moldyn_set_log(&md,SAVE_STEP,100);
234         moldyn_set_log(&md,CREATE_REPORT,0);
235
236         /*
237          * let's do the actual md algorithm now
238          *
239          * integration of newtons equations
240          */
241         moldyn_integrate(&md);
242
243         /* close */
244         moldyn_shutdown(&md);
245         
246         return 0;
247 }
248