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)
}
moldyn->count=count;
+ printf("[moldyn] created lattice with %d atoms\n",count);
while(count) {
moldyn->atom[count-1].element=element;
}
/* 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;
* - 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;
}
t_3dvec p;
t_moldyn_schedule *schedule;
t_atom *atom;
-
int fd;
char fb[128];
+ double ds;
schedule=&(moldyn->schedule);
atom=moldyn->atom;
/* 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;
moldyn->energy=0.0;
for(i=0;i<count;i++) {
-printf("BAR %d %d\n",i,count);
/* reset force */
v3_zero(&(atom[i].f));
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 */
#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 */
/*
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);
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);
/* 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");
//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");
/* 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