more testing
[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         t_atom *si;
21         t_visual vis;
22         t_random random;
23
24         int a,b,c;
25         double e,u;
26         double help;
27         t_3dvec p;
28         int count;
29
30         t_lj_params lj;
31         t_ho_params ho;
32
33         /* parse arguments */
34         a=moldyn_parse_argv(&md,argc,argv);
35         if(a<0) return -1;
36
37         /* init */
38         moldyn_log_init(&md,&vis);
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         a=LEN_X;
48         b=LEN_Y;
49         c=LEN_Z;
50
51         /* set for 'bounding atoms' */
52         vis.dim.x=a*LC_SI;
53         vis.dim.y=b*LC_SI;
54         vis.dim.z=c*LC_SI;
55
56         /* init lattice
57         printf("placing silicon atoms ... ");
58         count=create_lattice(DIAMOND,SI,M_SI,LC_SI,a,b,c,&si);
59         printf("(%d) ok!\n",count); */
60         /* testing purpose */
61         count=2;
62         si=malloc(2*sizeof(t_atom));
63         si[0].r.x=0.35*sqrt(3.0)*LC_SI/2.0;
64         si[0].r.y=0;
65         si[0].r.z=0;
66         si[0].element=SI;
67         si[0].mass=M_SI;
68         si[1].r.x=-si[0].r.x;
69         si[1].r.y=0;
70         si[1].r.z=0;
71         si[1].element=SI;
72         si[1].mass=M_SI;
73         /* */
74
75         /* moldyn init (now si is a valid address) */
76         md.count=count;
77         md.atom=si;
78         md.potential=potential_lennard_jones;
79         md.force=force_lennard_jones;
80         //md.potential=potential_harmonic_oscillator;
81         //md.force=force_harmonic_oscillator;
82         md.cutoff=R_CUTOFF;
83         md.cutoff_square=(R_CUTOFF*R_CUTOFF);
84         md.pot_params=&lj;
85         //md.pot_params=&ho;
86         md.integrate=velocity_verlet;
87         //md.time_steps=RUNS;
88         //md.tau=TAU;
89         md.status=0;
90         md.visual=&vis;
91
92         printf("setting thermal fluctuations (T=%f K)\n",md.t);
93         //thermal_init(&md,&random,count);
94         for(a=0;a<count;a++) v3_zero(&(si[0].v));
95         //v3_zero(&(si[0].v));
96         //v3_zero(&(si[1].v));
97
98         /* check kinetic energy */
99
100         e=get_e_kin(si,count);
101         printf("kinetic energy: %.40f [J]\n",e);
102         printf("3/2 N k T = %.40f [J]\n",1.5*count*K_BOLTZMANN*md.t);
103
104         /* check total momentum */
105         p=get_total_p(si,count);
106         printf("total momentum: %.30f [Ns]\n",v3_norm(&p));
107
108         /* check potential energy */
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         ho.equilibrium_distance=0.25*sqrt(3.0)*LC_SI;
116         ho.spring_constant=LJ_EPSILON_SI;
117
118         u=get_e_pot(&md);
119
120         printf("potential energy: %.40f [J]\n",u);
121         printf("total energy (1): %.40f [J]\n",e+u);
122         printf("total energy (2): %.40f [J]\n",get_total_energy(&md));
123
124         md.dim.x=a*LC_SI;
125         md.dim.y=b*LC_SI;
126         md.dim.z=c*LC_SI;
127
128         printf("estimated accurate time step: %.30f [s]\n",
129                estimate_time_step(&md,3.0,md.t));
130
131
132         /*
133          * let's do the actual md algorithm now
134          *
135          * integration of newtons equations
136          */
137
138         moldyn_integrate(&md);
139
140         printf("total energy (after integration): %.40f [J]\n",
141                get_total_energy(&md));
142
143         /* close */
144
145         rand_close(&random);
146
147         moldyn_shutdown(&md);
148         
149         return 0;
150 }
151