]> hackdaworld.org Git - physik/posic.git/commitdiff
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 1f62963c366ca66096639b9183e4944dc8f61258..07b4dc6fd061e120f2af3b749b7ca2ff7462e97c 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 81bfe199f8befd4fefff6f2b34517d373da70525..8f4e93c670f3f0c689835d12d628003cd4d6da84 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 029f7c756bd8f31871b4e7da5ae51f887db68031..ba3c1a30c8c2bd995a2ac2264d9a79984db01015 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 d72ac1623d9c655aa3d0a2efb27fdb46639bb231..1f9800c61b950dc66c2c127a617bb62438573fb2 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 69732781b2136c235e452960b60df8e8271ea5ba..6d1256fbf6513d40b0ce32146c60b3a7bc5d9ed9 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 1eb8e81d194ae7bf07ff351ad34777b17e16e119..a26e66830e1cfc2e10b17f3e275ae6c63f87d0da 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 6ad527a8ee4100bc58a5e91e4dce746cf7fea942..ce4ceaf97cbdd2fdf1873b2b84c35af92d1f67a7 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);