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