2 * moldyn.c - molecular dynamics library main file
4 * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
13 #include "math/math.h"
14 #include "init/init.h"
17 int create_lattice(unsigned char type,int element,double mass,double lc,
18 int a,int b,int c,t_atom **atom) {
26 if(type==FCC) count*=4;
27 if(type==DIAMOND) count*=8;
29 *atom=malloc(count*sizeof(t_atom));
31 perror("malloc (atoms)");
39 ret=fcc_init(a,b,c,lc,*atom,&origin);
42 ret=diamond_init(a,b,c,lc,*atom,&origin);
45 printf("unknown lattice type (%02x)\n",type);
51 printf("ok, there is something wrong ...\n");
52 printf("calculated -> %d atoms\n",count);
53 printf("created -> %d atoms\n",ret);
58 (*atom)[count-1].element=element;
59 (*atom)[count-1].mass=mass;
66 int thermal_init(t_atom *atom,int count,double t) {
69 * - gaussian distribution of velocities
70 * - velocity scaling (E = 3/2 N k T), E: kinetic energy
78 for(i=0;i<count;i++) {
82 e+=0.5*atom[count].mass*v*v;
86 e+=0.5*atom[count].mass*v*v;
90 e+=0.5*atom[count].mass*v*v;
93 c=sqrt((2.0*e)/(3.0*count*K_BOLTZMANN));
96 v3_scale(&(atom[count].v),&(atom[count].v),(1.0/c));