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