init testing
authorhackbard <hackbard>
Mon, 27 Mar 2006 08:55:17 +0000 (08:55 +0000)
committerhackbard <hackbard>
Mon, 27 Mar 2006 08:55:17 +0000 (08:55 +0000)
init/init.c
init/init.h
moldyn.c
moldyn.h
posic.c
posic.h
visual/visual.c

index 1f62963..07b4dc6 100644 (file)
@@ -9,13 +9,18 @@
 #include "../moldyn.h"
 
 /* fcc lattice init */
-int fcc_init(t_3dvec *dim,double lc,t_atom *atom,t_3dvec *origin) {
+int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) {
 
        int count;
        int i,j;
        t_3dvec o,r,n;
        t_3dvec basis[3];
        double help[3];
+       double x,y,z;
+
+       x=a*lc;
+       y=b*lc;
+       z=c*lc;
 
        if(origin) v3_copy(&o,origin);
        else v3_zero(&o);
@@ -34,14 +39,16 @@ int fcc_init(t_3dvec *dim,double lc,t_atom *atom,t_3dvec *origin) {
        count=0;
        
        /* fill up the room */
-       while(r.x<dim->x) {
-               while(r.y<dim->y) {
-                       while(r.z<dim->z) {
+       while(r.x<x) {
+               r.y=.0;
+               while(r.y<y) {
+                       r.z=.0;
+                       while(r.z<z) {
                                v3_copy(&(atom[count].r),&r);
                                count+=1;
                                for(i=0;i<3;i++) {
                                        v3_add(&n,&r,&basis[i]);
-                                       if((n.x<dim->x+o.x)&&(n.y<dim->y+o.y)&&(n.z<dim->z+o.z)) {
+                                       if((n.x<x+o.x)&&(n.y<y+o.y)&&(n.z<z+o.z)) {
                                                v3_copy(&(atom[count].r),&n);
                                                count+=1;
                                        }
@@ -54,9 +61,9 @@ int fcc_init(t_3dvec *dim,double lc,t_atom *atom,t_3dvec *origin) {
        }
 
        /* coordinate transformation */
-       help[0]=dim->x/2.0;
-       help[1]=dim->y/2.0;
-       help[2]=dim->z/2.0;
+       help[0]=x/2.0;
+       help[1]=y/2.0;
+       help[2]=z/2.0;
        v3_set(&n,help);
        for(i=0;i<count;i++)
                v3_sub(&(atom[i].r),&(atom[i].r),&n);
@@ -64,12 +71,12 @@ int fcc_init(t_3dvec *dim,double lc,t_atom *atom,t_3dvec *origin) {
        return count;
 }
 
-int diamond_init(t_3dvec *dim,double lc,t_atom *atom,t_3dvec *origin) {
+int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) {
 
        int count;
        t_3dvec o;
 
-       count=fcc_init(dim,lc,atom,origin);
+       count=fcc_init(a,b,c,lc,atom,origin);
 
        o.x=0.25*lc;
        o.y=0.25*lc;
@@ -77,8 +84,7 @@ int diamond_init(t_3dvec *dim,double lc,t_atom *atom,t_3dvec *origin) {
 
        if(origin) v3_add(&o,&o,origin);
 
-       count+=fcc_init(dim,lc,&atom[count],&o);
-
+       count+=fcc_init(a,b,c,lc,&atom[count],&o);
 
        return count;
 }
index 81bfe19..8f4e93c 100644 (file)
@@ -14,7 +14,7 @@
 
 /* function prototypes */
 
-int fcc_init(t_3dvec *dim,double lc,t_atom *atom,t_3dvec *origin);
-int diamond_init(t_3dvec *dim,double lc,t_atom *atom,t_3dvec *origin);
+int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin);
+int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin);
 
 #endif
index 029f7c7..ba3c1a3 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
 
 
 int create_lattice(unsigned char type,int element,double mass,double lc,
-                   t_3dvec *dim,t_atom **atom) {
+                   int a,int b,int c,t_atom **atom) {
 
        int count;
        int ret;
        t_3dvec origin;
 
-       count=((dim->x/lc)*(dim->y/lc)*(dim->z/lc));
+       count=a*b*c;
 
        if(type==FCC) count*=4;
        if(type==DIAMOND) count*=8;
@@ -36,10 +36,10 @@ int create_lattice(unsigned char type,int element,double mass,double lc,
 
        switch(type) {
                case FCC:
-                       ret=fcc_init(dim,lc,*atom,&origin);
+                       ret=fcc_init(a,b,c,lc,*atom,&origin);
                        break;
                case DIAMOND:
-                       ret=diamond_init(dim,lc,*atom,&origin);
+                       ret=diamond_init(a,b,c,lc,*atom,&origin);
                        break;
                default:
                        ret=-1;
index d72ac16..1f9800c 100644 (file)
--- a/moldyn.h
+++ b/moldyn.h
@@ -36,6 +36,6 @@ typedef struct s_atom {
 /* function prototypes */
 
 int create_lattice(unsigned char type,int element,double mass,double lc,
-                   t_3dvec *dim,t_atom **atom);
+                   int a,int b,int c,t_atom **atom);
 
 #endif
diff --git a/posic.c b/posic.c
index 6973278..6d1256f 100644 (file)
--- a/posic.c
+++ b/posic.c
@@ -15,7 +15,7 @@
 int main(int argc,char **argv) {
 
        t_atom *si;
-       t_3dvec dim;
+       int a,b,c;
 
        char fb[32]="saves/fcc_test";
 
@@ -23,15 +23,15 @@ int main(int argc,char **argv) {
 
        int count;
 
-       dim.x=LEN_X;
-       dim.y=LEN_Y;
-       dim.z=LEN_Z;
+       a=LEN_X;
+       b=LEN_Y;
+       c=LEN_Z;
        
        visual_init(&vis,fb);
 
        /* init */
        printf("placing silicon atoms\n");
-       count=create_lattice(FCC,Si,M_SI,LC_SI,&dim,&si);
+       count=create_lattice(FCC,Si,M_SI,LC_SI,a,b,c,&si);
 
        visual_atoms(&vis,0.0,si,count);
 
diff --git a/posic.h b/posic.h
index 1eb8e81..a26e668 100644 (file)
--- a/posic.h
+++ b/posic.h
 #ifndef POSIC_H
 #define POSIC_H
 
-#define LEN_X 50
-#define LX (1.0*LEN_X/2)
-#define LEN_Y 50
-#define LY (1.0*LEN_Y/2)
-#define LEN_Z 50
-#define LZ (1.0*LEN_Z/2)
-
 #define RUNS 15000
 #define TAU 0.001
 
-#define R_CUTOFF 20
-#define R2_CUTOFF (R_CUTOFF*R_CUTOFF)
-
 #define SI_M 1
 #define SI_LC 5.43105
 #define LJ_SIGMA SI_LC
 #define LJ_SIGMA_06 (LJ_SIGMA_02*LJ_SIGMA_02*LJ_SIGMA_02)
 #define LJ_SIGMA_12 (LJ_SIGMA_06*LJ_SIGMA_06)
 
+#define LEN_X 2
+#define LEN_Y 2
+#define LEN_Z 2
+
+#define R_CUTOFF 20
+#define R2_CUTOFF (R_CUTOFF*R_CUTOFF)
+
 #define AMOUNT_SI ((LEN_X/SI_LC)*(LEN_Y/SI_LC)*(LEN_Z/SI_LC)*2)
 
 #endif
index 6ad527a..ce4ceaf 100644 (file)
@@ -25,7 +25,7 @@ int visual_init(t_visual *v,char *filebase) {
        memset(file,0,128+8);
        sprintf(file,"%s.scr",v->fb);
 
-       v->fd=open(file,O_WRONLY);
+       v->fd=open(file,O_WRONLY|O_CREAT|O_TRUNC);
        if(v->fd<0) {
                perror("open visual fd");
                return -1;
@@ -69,7 +69,7 @@ int visual_atoms(t_visual *v,double time,t_atom *atom,int n) {
        };
 
        sprintf(file,"%s-%.15f.xyz",v->fb,time);
-       fd=open(file,O_WRONLY);
+       fd=open(file,O_WRONLY|O_CREAT|O_TRUNC);
        if(fd<0) {
                perror("open visual save file fd");
                return -1;
@@ -87,8 +87,8 @@ int visual_atoms(t_visual *v,double time,t_atom *atom,int n) {
        dprintf(v->fd,"zap\n");
 
        /* write the actual data file */
-       dprintf(fd,"Atoms at time %.15f\n",time);
        dprintf(fd,"%d\n",n);
+       dprintf(fd,"atoms at time %.15f\n",time);
        for(i=0;i<n;i++)
                dprintf(fd,"%s %f %f %f\n",pse[atom[i].element],
                                           atom[i].r.x,atom[i].r.y,atom[i].r.z);