started potential and force stuff
[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
57         printf("setting thermal fluctuations\n");
58         thermal_init(si,&random,count,t);
59
60         /* visualize */
61
62         visual_atoms(&vis,0.0,si,count);
63
64         /* check kinetic energy */
65
66         e=get_e_kin(si,count);
67         printf("kinetic energy: %f\n",e);
68         printf("3/2 N k T = %f\n",1.5*count*K_BOLTZMANN*t);
69
70         /* check total momentum */
71         p=get_total_p(si,count);
72         printf("total momentum: %f\n",v3_norm(&p));
73
74         /* check potential energy */
75         md.count=count;
76         md.atom=si;
77         md.potential=potential_lennard_jones;
78         md.pot_params=&lj;
79         md.force=NULL;
80         md.status=0;
81
82         lj.sigma6=3.0/16.0*LC_SI*LC_SI;
83         help=lj.sigma6*lj.sigma6;
84         lj.sigma6*=help;
85         lj.sigma12=lj.sigma6*lj.sigma6;
86         lj.epsilon=1;
87
88         u=get_e_pot(&md);
89
90         printf("potential energy: %f\n",u);
91         printf("total energy (1): %f\n",e+u);
92         printf("total energy (2): %f\n",get_total_energy(&md));
93
94         md.dim.x=a*LC_SI;
95         md.dim.y=b*LC_SI;
96         md.dim.z=c*LC_SI;
97
98         /*
99          * let's do the actual md algorithm now
100          *
101          * integration of newtons equations
102          */
103
104         /* close */
105
106         visual_tini(&vis);
107
108         rand_close(&random);
109         
110
111         //printf("starting velocity verlet: ");
112         //fflush(stdout);
113
114         //for(runs=0;runs<RUNS;runs++) {
115
116         /* 
117          * velocity verlet
118          *
119          * r(t+h) = r(t) + h * dr/dt|t + h^2/2m * F(t)
120          * dr/dt|(t+h) = dr/dt|t + h/2m * (F(t) + F(t+h))
121          *
122          */
123         //for(i=0;i<amount_si;i++) {
124 //              /* calculation of new positions r(t+h) */
125 //              si[i].x+=si[i].vx*tau;
126 //              si[i].y+=si[i].vy*tau;
127 //              si[i].z+=si[i].vz*tau;
128 //              si[i].x+=(tau2*si[i].fx/m2);
129 //              if(si[i].x>LX) si[i].x-=LEN_X;
130 //              else if(si[i].x<-LX) si[i].x+=LEN_X;
131 //              si[i].y+=(tau2*si[i].fy/m2);
132 //              if(si[i].y>LY) si[i].y-=LEN_Y;
133 //              else if(si[i].y<-LY) si[i].y+=LEN_Y;
134 //              si[i].z+=(tau2*si[i].fz/m2);
135 //              if(si[i].z>LZ) si[i].z-=LEN_Z;
136 //              else if(si[i].z<-LZ) si[i].z+=LEN_Z;
137 //              /* calculation of velocities v(t+h/2) */
138 //              si[i].vx+=(tau*si[i].fx/m2);
139 //              si[i].vy+=(tau*si[i].fy/m2);
140 //              si[i].vz+=(tau*si[i].fz/m2);
141 //              /* reset of forces */
142 //              si[i].fx=.0;
143 //              si[i].fy=.0;
144 //              si[i].fz=.0;
145 //      }
146 //      for(i=0;i<amount_si;i++) {
147 //              /* calculation of forces at new positions r(t+h) */
148 //              for(j=0;j<i;j++) {
149 //                      deltax=si[i].x-si[j].x;
150 //                      if(deltax>LX) deltax-=LEN_X;
151 //                      else if(-deltax>LX) deltax+=LEN_X;
152 //                      deltax2=deltax*deltax;
153 //                      deltay=si[i].y-si[j].y;
154 //                      if(deltay>LY) deltay-=LEN_Y;
155 //                      else if(-deltay>LY) deltay+=LEN_Y;
156 //                      deltay2=deltay*deltay;
157 //                      deltaz=si[i].z-si[j].z;
158 //                      if(deltaz>LZ) deltaz-=LEN_Z;
159 //                      else if(-deltaz>LZ) deltaz+=LEN_Z;
160 //                      deltaz2=deltaz*deltaz;
161 //                      distance=deltax2+deltay2+deltaz2;
162 //                      if(distance<=R2_CUTOFF) {
163 //                              tmp=1.0/distance; // 1/r^2
164 //                              lj1=tmp; // 1/r^2
165 //                              tmp*=tmp; // 1/r^4
166 //                              lj1*=tmp; // 1/r^6
167 //                              tmp*=tmp; // 1/r^8
168 //                              lj2=tmp; // 1/r^8
169 //                              lj1*=tmp; // 1/r^14
170 //                              lj1*=LJ_SIGMA_12;
171 //                              lj2*=LJ_SIGMA_06;
172 //                              lj=-2*lj1+lj2;
173 //                              si[i].fx-=lj*deltax;
174 //                              si[i].fy-=lj*deltay;
175 //                              si[i].fz-=lj*deltaz;
176 //                              si[j].fx+=lj*deltax;
177 //                              si[j].fy+=lj*deltay;
178 //                              si[j].fz+=lj*deltaz;
179 //                      }
180 //              }
181 //      }
182 //      for(i=0;i<amount_si;i++) {
183 //              /* calculation of new velocities v(t+h) */
184 //              si[i].vx+=(tau*si[i].fx/m2);
185 //              si[i].vy+=(tau*si[i].fy/m2);
186 //              si[i].vz+=(tau*si[i].fz/m2);
187 //      }
188 //
189 //      if(!(runs%150)) {
190 //
191 //      /* rasmol script & xyz file */
192 //      sprintf(xyz,"./saves/si-%.15f.xyz",time);
193 //      sprintf(ppm,"./video/si-%.15f.ppm",time);
194 //      fd1=open(xyz,O_WRONLY|O_CREAT|O_TRUNC);
195 //      if(fd1<0) {
196 //              perror("rasmol xyz file open");
197 //              return -1;
198 //      }
199 //      dprintf(fd2,"load xyz %s\n",xyz);
200 //      dprintf(fd2,"spacefill 200\n");
201 //      dprintf(fd2,"rotate x 11\n");
202 //      dprintf(fd2,"rotate y 13\n");
203 //      dprintf(fd2,"set ambient 20\n");
204 //      dprintf(fd2,"set specular on\n");
205 //      dprintf(fd2,"zoom 400\n");
206 //      dprintf(fd2,"write ppm %s\n",ppm);
207 //      dprintf(fd2,"zap\n");
208 //      dprintf(fd1,"%d\nsilicon\n",amount_si+9);
209 //      for(i=0;i<amount_si;i++)
210 //              dprintf(fd1,"Si %f %f %f %f\n",
211 //                      si[i].x,si[i].y,si[i].z,time);
212 //      dprintf(fd1,"H 0.0 0.0 0.0 %f\n",time);
213 //      dprintf(fd1,"He %f %f %f %f\n",LX,LY,LZ,time);
214 //      dprintf(fd1,"He %f %f %f %f\n",-LX,LY,LZ,time);
215 //      dprintf(fd1,"He %f %f %f %f\n",LX,-LY,LZ,time);
216 //      dprintf(fd1,"He %f %f %f %f\n",LX,LY,-LZ,time);
217 //      dprintf(fd1,"He %f %f %f %f\n",-LX,-LY,LZ,time);
218 //      dprintf(fd1,"He %f %f %f %f\n",-LX,LY,-LZ,time);
219 //      dprintf(fd1,"He %f %f %f %f\n",LX,-LY,-LZ,time);
220 //      dprintf(fd1,"He %f %f %f %f\n",-LX,-LY,-LZ,time);
221 //      close(fd1);
222 //
223 //      }
224 //
225 //      /* increase time */
226 //      time+=tau;
227 //      printf(".");
228 //      fflush(stdout);
229 //
230 //      }
231 //
232 //      printf(" done\n");
233 //      close(fd2);
234 //      free(si);
235 //
236
237         return 0;
238 }
239