more mods
[physik/posic.git] / moldyn.c
index ba3c1a3..e96cdd4 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -42,8 +42,8 @@ int create_lattice(unsigned char type,int element,double mass,double lc,
                        ret=diamond_init(a,b,c,lc,*atom,&origin);
                        break;
                default:
-                       ret=-1;
                        printf("unknown lattice type (%02x)\n",type);
+                       return -1;
        }
 
        /* debug */
@@ -51,6 +51,7 @@ int create_lattice(unsigned char type,int element,double mass,double lc,
                printf("ok, there is something wrong ...\n");
                printf("calculated -> %d atoms\n",count);
                printf("created -> %d atoms\n",ret);
+               return -1;
        }
 
        while(count) {
@@ -62,3 +63,38 @@ int create_lattice(unsigned char type,int element,double mass,double lc,
        return ret;
 }
 
+int thermal_init(t_atom *atom,int count,double t) {
+
+       /*
+        * - gaussian distribution of velocities
+        * - velocity scaling (E = 3/2 N k T), E: kinetic energy
+        */
+
+       int i;
+       double e,c,v;
+
+       e=.0;
+
+       for(i=0;i<count;i++) {
+               /* x direction */
+               v=gauss_rand();
+               atom[count].v.x=v;
+               e+=0.5*atom[count].mass*v*v;
+               /* y direction */
+               v=gauss_rand();
+               atom[count].v.y=v;
+               e+=0.5*atom[count].mass*v*v;
+               /* z direction */
+               v=gauss_rand();
+               atom[count].v.z=v;
+               e+=0.5*atom[count].mass*v*v;
+       }
+
+       c=sqrt((2.0*e)/(3.0*count*K_BOLTZMANN));
+
+       for(i=0;i<count;i++)
+               v3_scale(&(atom[count].v),&(atom[count].v),(1.0/c));
+
+       return 0;
+}
+