checkin before cafeteria visit ;)
[physik/posic.git] / posic.c
1 /*
2  * posic.c - precipitation process of silicon carbide in silicon
3  *
4  * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
5  *
6  */
7
8 #include <math.h>
9  
10 #include "moldyn.h"
11 #include "math/math.h"
12 #include "init/init.h"
13 #include "visual/visual.h"
14
15 #include "posic.h"
16
17 int main(int argc,char **argv) {
18
19         t_moldyn md;
20
21         t_atom *si;
22
23         t_visual vis;
24
25         t_random random;
26
27         int a,b,c;
28         double t,e,u;
29         double help;
30         t_3dvec p;
31         int count;
32
33         t_lj_params lj;
34
35         char fb[32]="saves/lj_test";
36
37         /* init */
38
39         rand_init(&random,NULL,1);
40         random.status|=RAND_STAT_VERBOSE;
41
42         /* testing random numbers */
43         //for(a=0;a<1000000;a++)
44         //      printf("%f %f\n",rand_get_gauss(&random),
45         //                       rand_get_gauss(&random));
46
47         visual_init(&vis,fb);
48
49         a=LEN_X;
50         b=LEN_Y;
51         c=LEN_Z;
52
53         /* set for 'bounding atoms' */
54         //vis.dim.x=a*LC_SI;
55         //vis.dim.y=b*LC_SI;
56         //vis.dim.z=c*LC_SI;
57
58         t=TEMPERATURE;
59
60         printf("placing silicon atoms ... ");
61         count=create_lattice(DIAMOND,SI,M_SI,LC_SI,a,b,c,&si);
62         printf("(%d) ok!\n",count);
63
64         /* testing purpose
65         count=2;
66         si=malloc(2*sizeof(t_atom));
67         si[0].r.x=0.16e-9;
68         si[0].r.y=0;
69         si[0].r.z=0;
70         si[0].element=SI;
71         si[0].mass=M_SI;
72         si[1].r.x=-0.16e-9;
73         si[1].r.y=0;
74         si[1].r.z=0;
75         si[1].element=SI;
76         si[1].mass=M_SI;
77         */
78
79         printf("setting thermal fluctuations\n");
80         thermal_init(si,&random,count,t);
81         //v3_zero(&(si[0].v));
82         //v3_zero(&(si[1].v));
83
84         /* check kinetic energy */
85
86         e=get_e_kin(si,count);
87         printf("kinetic energy: %.40f [J]\n",e);
88         printf("3/2 N k T = %.40f [J]\n",1.5*count*K_BOLTZMANN*t);
89
90         /* check total momentum */
91         p=get_total_p(si,count);
92         printf("total momentum: %.30f [Ns]\n",v3_norm(&p));
93
94         /* check potential energy */
95         md.count=count;
96         md.atom=si;
97         md.potential=potential_lennard_jones;
98         md.force=force_lennard_jones;
99         md.cutoff=R_CUTOFF;
100         md.cutoff_square=(R_CUTOFF*R_CUTOFF);
101         md.pot_params=&lj;
102         md.integrate=velocity_verlet;
103         md.time_steps=RUNS;
104         md.tau=TAU;
105         md.status=0;
106         md.visual=&vis;
107         md.write=WRITE_FILE;
108
109         lj.sigma6=LJ_SIGMA_SI*LJ_SIGMA_SI;
110         help=lj.sigma6*lj.sigma6;
111         lj.sigma6*=help;
112         lj.sigma12=lj.sigma6*lj.sigma6;
113         lj.epsilon=LJ_EPSILON_SI;
114
115         u=get_e_pot(&md);
116
117         printf("potential energy: %.40f [J]\n",u);
118         printf("total energy (1): %.40f [J]\n",e+u);
119         printf("total energy (2): %.40f [J]\n",get_total_energy(&md));
120
121         md.dim.x=a*LC_SI;
122         md.dim.y=b*LC_SI;
123         md.dim.z=c*LC_SI;
124
125         printf("estimated accurate time step: %.30f [s]\n",
126                estimate_time_step(&md,3.0,t));
127
128
129         /*
130          * let's do the actual md algorithm now
131          *
132          * integration of newtons equations
133          */
134
135         moldyn_integrate(&md);
136
137         printf("total energy (after integration): %.40f [J]\n",
138                get_total_energy(&md));
139
140         /* close */
141
142         visual_tini(&vis);
143
144         rand_close(&random);
145         
146         return 0;
147 }
148