vel scaling fixed/changed
authorhackbard <hackbard>
Thu, 30 Nov 2006 10:46:08 +0000 (10:46 +0000)
committerhackbard <hackbard>
Thu, 30 Nov 2006 10:46:08 +0000 (10:46 +0000)
moldyn.c
moldyn.h
sic.c

index de7bbbf..d52fcd3 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -93,6 +93,13 @@ int set_dim(t_moldyn *moldyn,double x,double y,double z,u8 visualize) {
        return 0;
 }
 
+int set_nn_dist(t_moldyn *moldyn,double dist) {
+
+       moldyn->nnd=dist;
+
+       return 0;
+}
+
 int set_pbc(t_moldyn *moldyn,u8 x,u8 y,u8 z) {
 
        if(x)
@@ -221,6 +228,7 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
        }
 
        moldyn->count=count;
+       printf("[moldyn] created lattice with %d atoms\n",count);
 
        while(count) {
                moldyn->atom[count-1].element=element;
@@ -311,15 +319,15 @@ int thermal_init(t_moldyn *moldyn) {
        }
 
        /* velocity scaling */
-       scale_velocity(moldyn);
+       scale_velocity(moldyn,VSCALE_INIT_EQUI);
 
        return 0;
 }
 
-int scale_velocity(t_moldyn *moldyn) {
+int scale_velocity(t_moldyn *moldyn,u8 type) {
 
        int i;
-       double e,c;
+       double e,scale;
        t_atom *atom;
 
        atom=moldyn->atom;
@@ -328,17 +336,14 @@ int scale_velocity(t_moldyn *moldyn) {
         * - velocity scaling (E = 3/2 N k T), E: kinetic energy
         */
 
-       if(moldyn->t==0.0) {
-               printf("[moldyn] no velocity scaling for T = 0 K\n");
-               return -1;
-       }
-
        e=0.0;
        for(i=0;i<moldyn->count;i++)
                e+=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v));
-       c=sqrt((2.0*e)/(3.0*moldyn->count*K_BOLTZMANN*moldyn->t));
+       scale=(1.5*moldyn->count*K_BOLTZMANN*moldyn->t)/e;
+       if(type&VSCALE_INIT_EQUI) scale*=2.0; /* equipartition theorem */
+       scale=sqrt(scale);
        for(i=0;i<moldyn->count;i++)
-               v3_scale(&(atom[i].v),&(atom[i].v),(1.0/c));
+               v3_scale(&(atom[i].v),&(atom[i].v),scale);
 
        return 0;
 }
@@ -594,9 +599,9 @@ int moldyn_integrate(t_moldyn *moldyn) {
        t_3dvec p;
        t_moldyn_schedule *schedule;
        t_atom *atom;
-
        int fd;
        char fb[128];
+       double ds;
 
        schedule=&(moldyn->schedule);
        atom=moldyn->atom;
@@ -617,6 +622,17 @@ int moldyn_integrate(t_moldyn *moldyn) {
        /* calculate initial forces */
        potential_force_calc(moldyn);
 
+       /* do some checks before we actually start calculating bullshit */
+       if(moldyn->cutoff>0.5*moldyn->dim.x)
+               printf("[moldyn] warning: cutoff > 0.5 x dim.x\n");
+       if(moldyn->cutoff>0.5*moldyn->dim.y)
+               printf("[moldyn] warning: cutoff > 0.5 x dim.y\n");
+       if(moldyn->cutoff>0.5*moldyn->dim.z)
+               printf("[moldyn] warning: cutoff > 0.5 x dim.z\n");
+       ds=0.5*atom[0].f.x*moldyn->tau_square/atom[0].mass;
+       if(ds>0.05*moldyn->nnd)
+               printf("[moldyn] warning: forces too high / tau too small!\n");
+
        /* zero absolute time */
        moldyn->time=0.0;
 
@@ -758,7 +774,6 @@ int potential_force_calc(t_moldyn *moldyn) {
        moldyn->energy=0.0;
 
        for(i=0;i<count;i++) {
-printf("BAR %d %d\n",i,count);
        
                /* reset force */
                v3_zero(&(atom[i].f));
index a2855a7..63dd14f 100644 (file)
--- a/moldyn.h
+++ b/moldyn.h
@@ -81,8 +81,9 @@ typedef struct s_moldyn {
 
        double cutoff;          /* cutoff radius */
        double cutoff_square;   /* square of the cutoff radius */
+       double nnd;             /* nearest neighbour distance (optional) */
 
-       t_linkcell lc;          /* linked cell method */
+       t_linkcell lc;          /* linked cell list interface */
 
        double t;               /* temperature */
 
@@ -122,9 +123,12 @@ typedef struct s_moldyn {
 #define MOLDYN_STAT_PBY                        0x10    /* y */
 #define MOLDYN_STAT_PBZ                        0x20    /* and z direction */
 
-#define MOLDYN_1BP                     0x00
-#define MOLDYN_2BP                     0x01
-#define MOLDYN_3BP                     0x02
+#define MOLDYN_1BP                     0x00    /* care about single */
+#define MOLDYN_2BP                     0x01    /* 2 body */
+#define MOLDYN_3BP                     0x02    /* and 3 body particle pots */
+
+#define VSCALE_INIT_EQUI               0x00    /* initial, eq positions */
+#define VSCALE_BERENDSEN               0x01    /* berendsen control */
 
 
 /*
@@ -281,6 +285,7 @@ int set_int_alg(t_moldyn *moldyn,u8 algo);
 int set_cutoff(t_moldyn *moldyn,double cutoff);
 int set_temperature(t_moldyn *moldyn,double t);
 int set_dim(t_moldyn *moldyn,double x,double y,double z,u8 visualize);
+int set_nn_dist(t_moldyn *moldyn,double dist);
 int set_pbc(t_moldyn *moldyn,u8 x,u8 y,u8 z);
 int set_potential1b(t_moldyn *moldyn,pf_func1b func,void *params);
 int set_potential2b(t_moldyn *moldyn,pf_func2b func,void *params);
@@ -296,7 +301,7 @@ int add_atom(t_moldyn *moldyn,int element,double mass,u8 bnum,u8 attr,
 int destroy_atoms(t_moldyn *moldyn);
 
 int thermal_init(t_moldyn *moldyn);
-int scale_velocity(t_moldyn *moldyn);
+int scale_velocity(t_moldyn *moldyn,u8 type);
 
 double get_e_kin(t_moldyn *moldyn);
 double get_e_pot(t_moldyn *moldyn);
diff --git a/sic.c b/sic.c
index 649d1e9..7c40a7e 100644 (file)
--- a/sic.c
+++ b/sic.c
@@ -61,11 +61,11 @@ int main(int argc,char **argv) {
 
        /* cutoff radius */
        printf("[sic] setting cutoff radius\n");
-       set_cutoff(&md,5*LC_SI);
+       set_cutoff(&md,1*LC_SI);
 
        /* set (initial) dimensions of simulation volume */
        printf("[sic] setting dimensions\n");
-       set_dim(&md,10*LC_SI,10*LC_SI,10*LC_SI,TRUE);
+       set_dim(&md,4*LC_SI,4*LC_SI,4*LC_SI,TRUE);
 
        /* set periodic boundary conditions in all directions */
        printf("[sic] setting periodic boundary conditions\n");
@@ -80,11 +80,14 @@ int main(int argc,char **argv) {
        //add_atom(&md,SI,M_SI,0,ATOM_ATTR_2BP,&r,&v);
        //r.x=-r.x;
        //add_atom(&md,SI,M_SI,0,ATOM_ATTR_2BP,&r,&v);
-       create_lattice(&md,DIAMOND,LC_SI,SI,M_SI,ATOM_ATTR_2BP,0,10,10,10);
+       create_lattice(&md,DIAMOND,LC_SI,SI,M_SI,ATOM_ATTR_2BP,0,4,4,4);
+
+       /* setting a nearest neighbour distance for the moldyn checks */
+       set_nn_dist(&md,sqrt(3.0)*LC_SI/4.0); /* diamond ! */
 
        /* set temperature */
        printf("[sic] setting temperature\n");
-       set_temperature(&md,0.0);
+       set_temperature(&md,273.0);
        
        /* initial thermal fluctuations of particles */
        printf("[sic] thermal init\n");
@@ -92,12 +95,12 @@ int main(int argc,char **argv) {
 
        /* create the simulation schedule */
        printf("[sic] adding schedule\n");
-       moldyn_add_schedule(&md,100,1.0e-15);
+       moldyn_add_schedule(&md,10000,1.0e-15);
 
        /* activate logging */
        printf("[sic] activate logging\n");
-       moldyn_set_log(&md,LOG_TOTAL_ENERGY,"saves/test-energy",1);
-       moldyn_set_log(&md,VISUAL_STEP,"saves/test-visual",1);
+       moldyn_set_log(&md,LOG_TOTAL_ENERGY,"saves/test-energy",100);
+       moldyn_set_log(&md,VISUAL_STEP,"saves/test-visual",100);
 
        /*
         * let's do the actual md algorithm now