started potentials
[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_atom *si;
18
19         t_visual vis;
20
21         t_random random;
22
23         int a,b,c;
24         double t,e;
25         t_3dvec p;
26         int count;
27
28         char fb[32]="saves/fcc_test";
29
30         /* init */
31
32         rand_init(&random,NULL,1);
33         random.status|=RAND_STAT_VERBOSE;
34
35         /* testing random numbers */
36         //for(a=0;a<1000000;a++)
37         //      printf("%f %f\n",rand_get_gauss(&random),
38         //                       rand_get_gauss(&random));
39
40         visual_init(&vis,fb);
41
42         a=LEN_X;
43         b=LEN_Y;
44         c=LEN_Z;
45
46         t=TEMPERATURE;
47
48         printf("placing silicon atoms ... ");
49         count=create_lattice(DIAMOND,Si,M_SI,LC_SI,a,b,c,&si);
50         printf("(%d) ok!\n",count);
51
52         printf("setting thermal fluctuations\n");
53         thermal_init(si,&random,count,t);
54
55         /* visualize */
56
57         visual_atoms(&vis,0.0,si,count);
58
59         /* check kinetic energy */
60
61         e=get_e_kin(si,count);
62         printf("kinetic energy: %f\n",e);
63         printf("3/2 N k T = %f\n",1.5*count*K_BOLTZMANN*t);
64
65         /* check total momentum */
66         p=get_total_p(si,count);
67         printf("total momentum: %f\n",v3_norm(&p));
68
69         /*
70          * let's do the actual md algorithm now
71          *
72          * integration of newtons equations
73          */
74
75         /* close */
76
77         visual_tini(&vis);
78
79         rand_close(&random);
80         
81
82         //printf("starting velocity verlet: ");
83         //fflush(stdout);
84
85         //for(runs=0;runs<RUNS;runs++) {
86
87         /* 
88          * velocity verlet
89          *
90          * r(t+h) = r(t) + h * dr/dt|t + h^2/2m * F(t)
91          * dr/dt|(t+h) = dr/dt|t + h/2m * (F(t) + F(t+h))
92          *
93          */
94         //for(i=0;i<amount_si;i++) {
95 //              /* calculation of new positions r(t+h) */
96 //              si[i].x+=si[i].vx*tau;
97 //              si[i].y+=si[i].vy*tau;
98 //              si[i].z+=si[i].vz*tau;
99 //              si[i].x+=(tau2*si[i].fx/m2);
100 //              if(si[i].x>LX) si[i].x-=LEN_X;
101 //              else if(si[i].x<-LX) si[i].x+=LEN_X;
102 //              si[i].y+=(tau2*si[i].fy/m2);
103 //              if(si[i].y>LY) si[i].y-=LEN_Y;
104 //              else if(si[i].y<-LY) si[i].y+=LEN_Y;
105 //              si[i].z+=(tau2*si[i].fz/m2);
106 //              if(si[i].z>LZ) si[i].z-=LEN_Z;
107 //              else if(si[i].z<-LZ) si[i].z+=LEN_Z;
108 //              /* calculation of velocities v(t+h/2) */
109 //              si[i].vx+=(tau*si[i].fx/m2);
110 //              si[i].vy+=(tau*si[i].fy/m2);
111 //              si[i].vz+=(tau*si[i].fz/m2);
112 //              /* reset of forces */
113 //              si[i].fx=.0;
114 //              si[i].fy=.0;
115 //              si[i].fz=.0;
116 //      }
117 //      for(i=0;i<amount_si;i++) {
118 //              /* calculation of forces at new positions r(t+h) */
119 //              for(j=0;j<i;j++) {
120 //                      deltax=si[i].x-si[j].x;
121 //                      if(deltax>LX) deltax-=LEN_X;
122 //                      else if(-deltax>LX) deltax+=LEN_X;
123 //                      deltax2=deltax*deltax;
124 //                      deltay=si[i].y-si[j].y;
125 //                      if(deltay>LY) deltay-=LEN_Y;
126 //                      else if(-deltay>LY) deltay+=LEN_Y;
127 //                      deltay2=deltay*deltay;
128 //                      deltaz=si[i].z-si[j].z;
129 //                      if(deltaz>LZ) deltaz-=LEN_Z;
130 //                      else if(-deltaz>LZ) deltaz+=LEN_Z;
131 //                      deltaz2=deltaz*deltaz;
132 //                      distance=deltax2+deltay2+deltaz2;
133 //                      if(distance<=R2_CUTOFF) {
134 //                              tmp=1.0/distance; // 1/r^2
135 //                              lj1=tmp; // 1/r^2
136 //                              tmp*=tmp; // 1/r^4
137 //                              lj1*=tmp; // 1/r^6
138 //                              tmp*=tmp; // 1/r^8
139 //                              lj2=tmp; // 1/r^8
140 //                              lj1*=tmp; // 1/r^14
141 //                              lj1*=LJ_SIGMA_12;
142 //                              lj2*=LJ_SIGMA_06;
143 //                              lj=-2*lj1+lj2;
144 //                              si[i].fx-=lj*deltax;
145 //                              si[i].fy-=lj*deltay;
146 //                              si[i].fz-=lj*deltaz;
147 //                              si[j].fx+=lj*deltax;
148 //                              si[j].fy+=lj*deltay;
149 //                              si[j].fz+=lj*deltaz;
150 //                      }
151 //              }
152 //      }
153 //      for(i=0;i<amount_si;i++) {
154 //              /* calculation of new velocities v(t+h) */
155 //              si[i].vx+=(tau*si[i].fx/m2);
156 //              si[i].vy+=(tau*si[i].fy/m2);
157 //              si[i].vz+=(tau*si[i].fz/m2);
158 //      }
159 //
160 //      if(!(runs%150)) {
161 //
162 //      /* rasmol script & xyz file */
163 //      sprintf(xyz,"./saves/si-%.15f.xyz",time);
164 //      sprintf(ppm,"./video/si-%.15f.ppm",time);
165 //      fd1=open(xyz,O_WRONLY|O_CREAT|O_TRUNC);
166 //      if(fd1<0) {
167 //              perror("rasmol xyz file open");
168 //              return -1;
169 //      }
170 //      dprintf(fd2,"load xyz %s\n",xyz);
171 //      dprintf(fd2,"spacefill 200\n");
172 //      dprintf(fd2,"rotate x 11\n");
173 //      dprintf(fd2,"rotate y 13\n");
174 //      dprintf(fd2,"set ambient 20\n");
175 //      dprintf(fd2,"set specular on\n");
176 //      dprintf(fd2,"zoom 400\n");
177 //      dprintf(fd2,"write ppm %s\n",ppm);
178 //      dprintf(fd2,"zap\n");
179 //      dprintf(fd1,"%d\nsilicon\n",amount_si+9);
180 //      for(i=0;i<amount_si;i++)
181 //              dprintf(fd1,"Si %f %f %f %f\n",
182 //                      si[i].x,si[i].y,si[i].z,time);
183 //      dprintf(fd1,"H 0.0 0.0 0.0 %f\n",time);
184 //      dprintf(fd1,"He %f %f %f %f\n",LX,LY,LZ,time);
185 //      dprintf(fd1,"He %f %f %f %f\n",-LX,LY,LZ,time);
186 //      dprintf(fd1,"He %f %f %f %f\n",LX,-LY,LZ,time);
187 //      dprintf(fd1,"He %f %f %f %f\n",LX,LY,-LZ,time);
188 //      dprintf(fd1,"He %f %f %f %f\n",-LX,-LY,LZ,time);
189 //      dprintf(fd1,"He %f %f %f %f\n",-LX,LY,-LZ,time);
190 //      dprintf(fd1,"He %f %f %f %f\n",LX,-LY,-LZ,time);
191 //      dprintf(fd1,"He %f %f %f %f\n",-LX,-LY,-LZ,time);
192 //      close(fd1);
193 //
194 //      }
195 //
196 //      /* increase time */
197 //      time+=tau;
198 //      printf(".");
199 //      fflush(stdout);
200 //
201 //      }
202 //
203 //      printf(" done\n");
204 //      close(fd2);
205 //      free(si);
206 //
207
208         return 0;
209 }
210