testing
[physik/posic.git] / posic.c
1 /*
2  * posic.c - precipitation process of silicon carbide in silicon
3  *
4  * author: Frank Zirkelbach <hackbard@hackdaworld.org>
5  *
6  */
7  
8 #include "moldyn.h"
9 #include "math/math.h"
10 #include "init/init.h"
11 #include "visual/visual.h"
12
13 #include "posic.h"
14
15 int main(int argc,char **argv) {
16
17         t_moldyn md;
18
19         t_atom *si;
20
21         t_visual vis;
22
23         t_random random;
24
25         int a,b,c;
26         double t,e,u;
27         double help;
28         t_3dvec p;
29         int count;
30
31         t_lj_params lj;
32
33         char fb[32]="saves/fcc_test";
34
35         /* init */
36
37         rand_init(&random,NULL,1);
38         random.status|=RAND_STAT_VERBOSE;
39
40         /* testing random numbers */
41         //for(a=0;a<1000000;a++)
42         //      printf("%f %f\n",rand_get_gauss(&random),
43         //                       rand_get_gauss(&random));
44
45         visual_init(&vis,fb);
46
47         a=LEN_X;
48         b=LEN_Y;
49         c=LEN_Z;
50
51         t=TEMPERATURE;
52
53         printf("placing silicon atoms ... ");
54         //count=create_lattice(DIAMOND,Si,M_SI,LC_SI,a,b,c,&si);
55         //printf("(%d) ok!\n",count);
56         count=2;
57         si=malloc(2*sizeof(t_atom));
58         si[0].r.x=2.0;
59         si[0].r.y=0;
60         si[0].r.z=0;
61         si[0].element=Si;
62         si[0].mass=14.0;
63         si[1].r.x=-2.0;
64         si[1].r.y=0;
65         si[1].r.z=0;
66         si[1].element=Si;
67         si[1].mass=14.0;
68
69         printf("setting thermal fluctuations\n");
70         //thermal_init(si,&random,count,t);
71         v3_zero(&(si[0].v));
72         v3_zero(&(si[1].v));
73
74         /* check kinetic energy */
75
76         e=get_e_kin(si,count);
77         printf("kinetic energy: %f\n",e);
78         printf("3/2 N k T = %f\n",1.5*count*K_BOLTZMANN*t);
79
80         /* check total momentum */
81         p=get_total_p(si,count);
82         printf("total momentum: %f\n",v3_norm(&p));
83
84         /* check potential energy */
85         md.count=count;
86         md.atom=si;
87         md.potential=potential_lennard_jones;
88         md.force=force_lennard_jones;
89         //md.cutoff_square=((LC_SI/4.0)*(LC_SI/4.0));
90         md.cutoff_square=36.0;
91         md.pot_params=&lj;
92         md.integrate=velocity_verlet;
93         md.time_steps=RUNS;
94         md.tau=TAU;
95         md.status=0;
96         md.visual=&vis;
97
98         lj.sigma6=3.0/16.0*LC_SI*LC_SI;
99         help=lj.sigma6*lj.sigma6;
100         lj.sigma6*=help;
101         lj.sigma12=lj.sigma6*lj.sigma6;
102         lj.epsilon=10000;
103
104         u=get_e_pot(&md);
105
106         printf("potential energy: %f\n",u);
107         printf("total energy (1): %f\n",e+u);
108         printf("total energy (2): %f\n",get_total_energy(&md));
109
110         md.dim.x=a*LC_SI;
111         md.dim.y=b*LC_SI;
112         md.dim.z=c*LC_SI;
113
114         /*
115          * let's do the actual md algorithm now
116          *
117          * integration of newtons equations
118          */
119
120         /* visualize */
121         //visual_atoms(&vis,0.0,si,count);
122         
123
124         moldyn_integrate(&md);
125
126         printf("total energy (after integration): %f\n",get_total_energy(&md));
127
128         /* close */
129
130         visual_tini(&vis);
131
132         rand_close(&random);
133         
134
135         //printf("starting velocity verlet: ");
136         //fflush(stdout);
137
138         //for(runs=0;runs<RUNS;runs++) {
139
140         /* 
141          * velocity verlet
142          *
143          * r(t+h) = r(t) + h * dr/dt|t + h^2/2m * F(t)
144          * dr/dt|(t+h) = dr/dt|t + h/2m * (F(t) + F(t+h))
145          *
146          */
147         //for(i=0;i<amount_si;i++) {
148 //              /* calculation of new positions r(t+h) */
149 //              si[i].x+=si[i].vx*tau;
150 //              si[i].y+=si[i].vy*tau;
151 //              si[i].z+=si[i].vz*tau;
152 //              si[i].x+=(tau2*si[i].fx/m2);
153 //              if(si[i].x>LX) si[i].x-=LEN_X;
154 //              else if(si[i].x<-LX) si[i].x+=LEN_X;
155 //              si[i].y+=(tau2*si[i].fy/m2);
156 //              if(si[i].y>LY) si[i].y-=LEN_Y;
157 //              else if(si[i].y<-LY) si[i].y+=LEN_Y;
158 //              si[i].z+=(tau2*si[i].fz/m2);
159 //              if(si[i].z>LZ) si[i].z-=LEN_Z;
160 //              else if(si[i].z<-LZ) si[i].z+=LEN_Z;
161 //              /* calculation of velocities v(t+h/2) */
162 //              si[i].vx+=(tau*si[i].fx/m2);
163 //              si[i].vy+=(tau*si[i].fy/m2);
164 //              si[i].vz+=(tau*si[i].fz/m2);
165 //              /* reset of forces */
166 //              si[i].fx=.0;
167 //              si[i].fy=.0;
168 //              si[i].fz=.0;
169 //      }
170 //      for(i=0;i<amount_si;i++) {
171 //              /* calculation of forces at new positions r(t+h) */
172 //              for(j=0;j<i;j++) {
173 //                      deltax=si[i].x-si[j].x;
174 //                      if(deltax>LX) deltax-=LEN_X;
175 //                      else if(-deltax>LX) deltax+=LEN_X;
176 //                      deltax2=deltax*deltax;
177 //                      deltay=si[i].y-si[j].y;
178 //                      if(deltay>LY) deltay-=LEN_Y;
179 //                      else if(-deltay>LY) deltay+=LEN_Y;
180 //                      deltay2=deltay*deltay;
181 //                      deltaz=si[i].z-si[j].z;
182 //                      if(deltaz>LZ) deltaz-=LEN_Z;
183 //                      else if(-deltaz>LZ) deltaz+=LEN_Z;
184 //                      deltaz2=deltaz*deltaz;
185 //                      distance=deltax2+deltay2+deltaz2;
186 //                      if(distance<=R2_CUTOFF) {
187 //                              tmp=1.0/distance; // 1/r^2
188 //                              lj1=tmp; // 1/r^2
189 //                              tmp*=tmp; // 1/r^4
190 //                              lj1*=tmp; // 1/r^6
191 //                              tmp*=tmp; // 1/r^8
192 //                              lj2=tmp; // 1/r^8
193 //                              lj1*=tmp; // 1/r^14
194 //                              lj1*=LJ_SIGMA_12;
195 //                              lj2*=LJ_SIGMA_06;
196 //                              lj=-2*lj1+lj2;
197 //                              si[i].fx-=lj*deltax;
198 //                              si[i].fy-=lj*deltay;
199 //                              si[i].fz-=lj*deltaz;
200 //                              si[j].fx+=lj*deltax;
201 //                              si[j].fy+=lj*deltay;
202 //                              si[j].fz+=lj*deltaz;
203 //                      }
204 //              }
205 //      }
206 //      for(i=0;i<amount_si;i++) {
207 //              /* calculation of new velocities v(t+h) */
208 //              si[i].vx+=(tau*si[i].fx/m2);
209 //              si[i].vy+=(tau*si[i].fy/m2);
210 //              si[i].vz+=(tau*si[i].fz/m2);
211 //      }
212 //
213 //      if(!(runs%150)) {
214 //
215 //      /* rasmol script & xyz file */
216 //      sprintf(xyz,"./saves/si-%.15f.xyz",time);
217 //      sprintf(ppm,"./video/si-%.15f.ppm",time);
218 //      fd1=open(xyz,O_WRONLY|O_CREAT|O_TRUNC);
219 //      if(fd1<0) {
220 //              perror("rasmol xyz file open");
221 //              return -1;
222 //      }
223 //      dprintf(fd2,"load xyz %s\n",xyz);
224 //      dprintf(fd2,"spacefill 200\n");
225 //      dprintf(fd2,"rotate x 11\n");
226 //      dprintf(fd2,"rotate y 13\n");
227 //      dprintf(fd2,"set ambient 20\n");
228 //      dprintf(fd2,"set specular on\n");
229 //      dprintf(fd2,"zoom 400\n");
230 //      dprintf(fd2,"write ppm %s\n",ppm);
231 //      dprintf(fd2,"zap\n");
232 //      dprintf(fd1,"%d\nsilicon\n",amount_si+9);
233 //      for(i=0;i<amount_si;i++)
234 //              dprintf(fd1,"Si %f %f %f %f\n",
235 //                      si[i].x,si[i].y,si[i].z,time);
236 //      dprintf(fd1,"H 0.0 0.0 0.0 %f\n",time);
237 //      dprintf(fd1,"He %f %f %f %f\n",LX,LY,LZ,time);
238 //      dprintf(fd1,"He %f %f %f %f\n",-LX,LY,LZ,time);
239 //      dprintf(fd1,"He %f %f %f %f\n",LX,-LY,LZ,time);
240 //      dprintf(fd1,"He %f %f %f %f\n",LX,LY,-LZ,time);
241 //      dprintf(fd1,"He %f %f %f %f\n",-LX,-LY,LZ,time);
242 //      dprintf(fd1,"He %f %f %f %f\n",-LX,LY,-LZ,time);
243 //      dprintf(fd1,"He %f %f %f %f\n",LX,-LY,-LZ,time);
244 //      dprintf(fd1,"He %f %f %f %f\n",-LX,-LY,-LZ,time);
245 //      close(fd1);
246 //
247 //      }
248 //
249 //      /* increase time */
250 //      time+=tau;
251 //      printf(".");
252 //      fflush(stdout);
253 //
254 //      }
255 //
256 //      printf(" done\n");
257 //      close(fd2);
258 //      free(si);
259 //
260
261         return 0;
262 }
263