moldyn->vis.dim.z=z;
}
- moldyn->dv=0.000001*moldyn->volume;
-
printf("[moldyn] dimensions in A and A^3 respectively:\n");
printf(" x: %f\n",moldyn->dim.x);
printf(" y: %f\n",moldyn->dim.y);
printf(" z: %f\n",moldyn->dim.z);
printf(" volume: %f\n",moldyn->volume);
printf(" visualize simulation box: %s\n",visualize?"yes":"no");
- printf(" delta volume (pressure calc): %f\n",moldyn->dv);
return 0;
}
dprintf(moldyn->tfd,"# temperature log file\n");
printf("temperature (%d)\n",timer);
break;
+ case LOG_VOLUME:
+ moldyn->vwrite=timer;
+ snprintf(filename,127,"%s/volume",moldyn->vlsdir);
+ moldyn->vfd=open(filename,
+ O_WRONLY|O_CREAT|O_EXCL,
+ S_IRUSR|S_IWUSR);
+ if(moldyn->vfd<0) {
+ perror("[moldyn] volume log file\n");
+ return moldyn->vfd;
+ }
+ dprintf(moldyn->vfd,"# volume log file\n");
+ printf("volume (%d)\n",timer);
+ break;
case SAVE_STEP:
moldyn->swrite=timer;
printf("save file (%d)\n",timer);
break;
case VISUAL_STEP:
- moldyn->vwrite=timer;
+ moldyn->awrite=timer;
ret=visual_init(moldyn,moldyn->vlsdir);
if(ret<0) {
printf("[moldyn] visual init failure\n");
double virial_sum(t_moldyn *moldyn) {
int i;
- double v;
t_virial *virial;
/* virial (sum over atom virials) */
- v=0.0;
+ moldyn->virial=0.0;
+ moldyn->vir.xx=0.0;
+ moldyn->vir.yy=0.0;
+ moldyn->vir.zz=0.0;
+ moldyn->vir.xy=0.0;
+ moldyn->vir.xz=0.0;
+ moldyn->vir.yz=0.0;
for(i=0;i<moldyn->count;i++) {
virial=&(moldyn->atom[i].virial);
- v+=(virial->xx+virial->yy+virial->zz);
+ moldyn->virial+=(virial->xx+virial->yy+virial->zz);
+ moldyn->vir.xx+=virial->xx;
+ moldyn->vir.yy+=virial->yy;
+ moldyn->vir.zz+=virial->zz;
+ moldyn->vir.xy+=virial->xy;
+ moldyn->vir.xz+=virial->xz;
+ moldyn->vir.yz+=virial->yz;
}
- moldyn->virial=v;
/* global virial (absolute coordinates) */
virial=&(moldyn->gvir);
/* pressure */
moldyn->p_sum=0.0;
moldyn->gp_sum=0.0;
+ moldyn->tp_sum=0.0;
return 0;
}
moldyn->p_avg=moldyn->p_sum/denom;
moldyn->gp_sum+=moldyn->gp;
moldyn->gp_avg=moldyn->gp_sum/denom;
+ moldyn->tp_sum+=moldyn->tp;
+ moldyn->tp_avg=moldyn->tp_sum/denom;
return 0;
}
t_3dvec dim;
//t_3dvec *tp;
- double u_up,u_down,dv;
- double scale,p;
+ double h,dv;
+ double y0,y1;
+ double su,sd;
t_atom *store;
/*
*
*/
- scale=0.00001;
- dv=8*scale*scale*scale*moldyn->volume;
-
+ /* store atomic configuration + dimension */
store=malloc(moldyn->count*sizeof(t_atom));
if(store==NULL) {
printf("[moldyn] allocating store mem failed\n");
return -1;
}
-
- /* save unscaled potential energy + atom/dim configuration */
memcpy(store,moldyn->atom,moldyn->count*sizeof(t_atom));
dim=moldyn->dim;
+ /* x1, y1 */
+ sd=0.00001;
+ h=(1.0-sd)*(1.0-sd)*(1.0-sd);
+ su=pow(2.0-h,ONE_THIRD)-1.0;
+ dv=(1.0-h)*moldyn->volume;
+
/* scale up dimension and atom positions */
- scale_dim(moldyn,SCALE_UP,scale,TRUE,TRUE,TRUE);
- scale_atoms(moldyn,SCALE_UP,scale,TRUE,TRUE,TRUE);
+ scale_dim(moldyn,SCALE_UP,su,TRUE,TRUE,TRUE);
+ scale_atoms(moldyn,SCALE_UP,su,TRUE,TRUE,TRUE);
link_cell_shutdown(moldyn);
link_cell_init(moldyn,QUIET);
potential_force_calc(moldyn);
- u_up=moldyn->energy;
+ y1=moldyn->energy;
/* restore atomic configuration + dim */
memcpy(moldyn->atom,store,moldyn->count*sizeof(t_atom));
moldyn->dim=dim;
/* scale down dimension and atom positions */
- scale_dim(moldyn,SCALE_DOWN,scale,TRUE,TRUE,TRUE);
- scale_atoms(moldyn,SCALE_DOWN,scale,TRUE,TRUE,TRUE);
+ scale_dim(moldyn,SCALE_DOWN,sd,TRUE,TRUE,TRUE);
+ scale_atoms(moldyn,SCALE_DOWN,sd,TRUE,TRUE,TRUE);
link_cell_shutdown(moldyn);
link_cell_init(moldyn,QUIET);
potential_force_calc(moldyn);
- u_down=moldyn->energy;
+ y0=moldyn->energy;
/* calculate pressure */
- p=-(u_up-u_down)/dv;
-printf("-------> %.10f %.10f %f\n",u_up/EV/moldyn->count,u_down/EV/moldyn->count,p/BAR);
+ moldyn->tp=-(y1-y0)/(2.0*dv);
- /* restore atomic configuration + dim */
+ /* restore atomic configuration */
memcpy(moldyn->atom,store,moldyn->count*sizeof(t_atom));
moldyn->dim=dim;
-
- /* restore energy */
- potential_force_calc(moldyn);
-
link_cell_shutdown(moldyn);
link_cell_init(moldyn,QUIET);
+ //potential_force_calc(moldyn);
- return p;
+ /* free store buffer */
+ if(store)
+ free(store);
+
+ return moldyn->tp;
}
double get_pressure(t_moldyn *moldyn) {
/* scaling factor */
if(moldyn->pt_scale&P_SCALE_BERENDSEN) {
- scale=1.0-(moldyn->p_ref-moldyn->p)/moldyn->p_tc;
+ scale=1.0-(moldyn->p_ref-moldyn->p)*moldyn->p_tc;
scale=pow(scale,ONE_THIRD);
}
else {
scale=pow(moldyn->p/moldyn->p_ref,ONE_THIRD);
}
-moldyn->debug=scale;
/* scale the atoms and dimensions */
scale_atoms(moldyn,SCALE_DIRECT,scale,TRUE,TRUE,TRUE);
int moldyn_integrate(t_moldyn *moldyn) {
int i;
- unsigned int e,m,s,v,p,t;
+ unsigned int e,m,s,v,p,t,a;
t_3dvec momentum;
t_moldyn_schedule *sched;
t_atom *atom;
m=moldyn->mwrite;
s=moldyn->swrite;
v=moldyn->vwrite;
+ a=moldyn->awrite;
p=moldyn->pwrite;
t=moldyn->twrite;
temperature_calc(moldyn);
virial_sum(moldyn);
pressure_calc(moldyn);
+ //thermodynamic_pressure_calc(moldyn);
+
+ /* calculate fluctuations + averages */
average_and_fluctuation_calc(moldyn);
/* p/t scaling */
if(p) {
if(!(moldyn->total_steps%p)) {
dprintf(moldyn->pfd,
- "%f %f %f %f %f\n",moldyn->time,
+ "%f %f %f %f %f %f %f\n",moldyn->time,
moldyn->p/BAR,moldyn->p_avg/BAR,
- moldyn->gp/BAR,moldyn->gp_avg/BAR);
+ moldyn->gp/BAR,moldyn->gp_avg/BAR,
+ moldyn->tp/BAR,moldyn->tp_avg/BAR);
}
}
if(t) {
moldyn->time,moldyn->t,moldyn->t_avg);
}
}
+ if(v) {
+ if(!(moldyn->total_steps%v)) {
+ dprintf(moldyn->vfd,
+ "%f %f\n",moldyn->time,moldyn->volume);
+ }
+ }
if(s) {
if(!(moldyn->total_steps%s)) {
snprintf(dir,128,"%s/s-%07.f.save",
close(fd);
}
}
- if(v) {
- if(!(moldyn->total_steps%v)) {
+ if(a) {
+ if(!(moldyn->total_steps%a)) {
visual_atoms(moldyn);
}
}
/* get current time */
gettimeofday(&t2,NULL);
-printf("\rsched:%d, steps:%d/%d, T:%3.1f/%3.1f P:%4.1f/%4.1f V:%6.1f (%d)",
+printf("\rsched:%d, steps:%d/%d, T:%4.1f/%4.1f P:%4.1f/%4.1f V:%6.1f (%d)",
sched->count,i,moldyn->total_steps,
moldyn->t,moldyn->t_avg,
- moldyn->p_avg/BAR,moldyn->gp_avg/BAR,
+ moldyn->p/BAR,moldyn->p_avg/BAR,
moldyn->volume,
(int)(t2.tv_sec-t1.tv_sec));
double gp_sum; /* sum over all gp */
double gp_avg; /* average value of gp */
- double virial; /* actual virial */
+ t_virial vir; /* actual virial */
+ double virial;
double virial_sum; /* sum over all calculated virials */
double virial_avg; /* average of virial */
double p_sum; /* sum over all p */
double p_avg; /* average value of p */
- t_3dvec tp; /* thermodynamic pressure dU/dV */
- double dv; /* dV for thermodynamic pressure calc */
+ double tp; /* thermodynamic pressure dU/dV */
+ double tp_sum; /* sum over dU/dV pressure */
+ double tp_avg; /* average value of dU/dV pressure */
+ int tp_cnt; /* how often to do thermodynamic p calc */
/* pressure and temperature control (velocity/volume scaling) */
/* (t_tc in units of tau, p_tc in units of tau * isoth. compressib.) */
int pfd; /* fd for pressure log */
unsigned int twrite; /* how often to log temperature */
int tfd; /* fd for temperature log */
- unsigned int vwrite; /* how often to visualize atom information */
+ unsigned int vwrite; /* how often to log volume */
+ int vfd; /* fd for volume log */
+ unsigned int awrite; /* how often to visualize atom information */
unsigned int swrite; /* how often to create a save file */
int rfd; /* report file descriptor */
char rtitle[64]; /* report title */
#define KILOGRAM (1.0/AMU) /* amu */
#define NEWTON (METER*KILOGRAM/(SECOND*SECOND)) /* A amu / fs^2 */
#define PASCAL (NEWTON/(METER*METER)) /* N / A^2 */
+#define GPA (1e9*PASCAL) /* N / A^2 */
#define BAR ((1.0e5*PASCAL)) /* N / A^2 */
#define K_BOLTZMANN (1.380650524e-23*METER*NEWTON) /* NA/K */
#define K_B2 (K_BOLTZMANN*K_BOLTZMANN) /* (NA)^2/K^2 */
#define LOG_TOTAL_MOMENTUM 0x02
#define LOG_PRESSURE 0x04
#define LOG_TEMPERATURE 0x08
-#define SAVE_STEP 0x10
-#define VISUAL_STEP 0x20
-#define CREATE_REPORT 0x40
+#define LOG_VOLUME 0x10
+#define SAVE_STEP 0x20
+#define VISUAL_STEP 0x40
+#define CREATE_REPORT 0x80
#define TRUE 1
#define FALSE 0
// 001 dumbbell
r.x=(-0.5+0.25)*ALBE_LC_SI;
r.y=(-0.5+0.25)*ALBE_LC_SI;
- r.z=(-0.5+0.25+0.125)*ALBE_LC_SI;
- moldyn->atom[4372].r.z=(-0.5+0.25-0.125)*ALBE_LC_SI;
+ r.z=(-0.1)*ALBE_LC_SI;
+ moldyn->atom[4372].r.z=(-0.4)*ALBE_LC_SI;
#endif
#ifdef INS_USER
// 001 dumbbell
#endif
#ifdef INS_RAND
// random
+#ifdef INS_DYNAMIC_LEN
+ r.x=(rand_get_double(&(moldyn->random))-0.5)*\
+ moldyn->dim.x;
+ r.y=(rand_get_double(&(moldyn->random))-0.5)*\
+ moldyn->dim.y;
+ r.z=(rand_get_double(&(moldyn->random))-0.5)*\
+ moldyn->dim.z;
+#else
r.x=(rand_get_double(&(moldyn->random))-0.5)*INS_LENX;
r.y=(rand_get_double(&(moldyn->random))-0.5)*INS_LENY;
r.z=(rand_get_double(&(moldyn->random))-0.5)*INS_LENZ;
+#endif
#endif
// offset
r.x+=INS_OFFSET;
int steps;
double tau;
double dt;
+ double dp;
hp=hook_params;
md=moldyn;
/* switch on t scaling */
if(md->schedule.count==0)
- set_pt_scale(md,0,0,T_SCALE_BERENDSEN,T_SCALE_TAU);
+ set_pt_scale(md,P_SCALE_BERENDSEN,P_SCALE_TAU,
+ T_SCALE_BERENDSEN,T_SCALE_TAU);
/* my lousy state machine ! */
/* check temperature */
dt=md->t_avg-md->t_ref;
+ dp=md->p_avg-md->p_ref;
if(dt<0)
dt=-dt;
- if(dt>INS_DELTA_TC)
+ if(dp<0)
+ dp=-dp;
+ if((dt>INS_DELTA_TC)|(dp>INS_DELTA_PC))
goto addsched;
/* immediately go on if no job is to be done */
/* check temperature */
dt=md->t_avg-md->t_ref;
+ dp=md->p_avg-md->p_ref;
if(dt<0)
dt=-dt;
- if(dt>POST_DELTA_TC)
+ if(dp<0)
+ dp=-dp;
+ if((dt>POST_DELTA_TC)|(dp>POST_DELTA_PC))
goto addsched;
/* immediately return if no job is to be done */
0,LCNTX,LCNTY,LCNTZ,&r);
r.x+=0.25*ALBE_LC_SIC; r.y=r.x; r.z=r.x;
create_lattice(&md,FCC,ALBE_LC_SIC,C,M_C,
- ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
+ ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB|ATOM_ATTR_VB,
1,LCNTX,LCNTY,LCNTZ,&r);
#else
r.x=0.5*0.25*TM_LC_SIC; r.y=r.x; r.z=r.x;
/* set temperature & pressure */
set_temperature(&md,atof(argv[2])+273.0);
- set_pressure(&md,BAR);
+ set_pressure(&md,0.0);
/* set amount of steps to skip before average calc */
set_avg_skip(&md,AVG_SKIP);
/* set p/t scaling */
//set_pt_scale(&md,0,0,T_SCALE_BERENDSEN,100.0);
- //set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,
+ //set_pt_scale(&md,P_SCALE_BERENDSEN,0.01/(100*GPA),
// T_SCALE_BERENDSEN,100.0);
//set_pt_scale(&md,0,0,T_SCALE_DIRECT,1.0);
//set_pt_scale(&md,P_SCALE_BERENDSEN,0.001,0,0);
moldyn_set_log(&md,LOG_TOTAL_ENERGY,LOG_E);
moldyn_set_log(&md,LOG_TEMPERATURE,LOG_T);
moldyn_set_log(&md,LOG_PRESSURE,LOG_P);
- moldyn_set_log(&md,VISUAL_STEP,LOG_V);
+ moldyn_set_log(&md,LOG_VOLUME,LOG_V);
+ moldyn_set_log(&md,VISUAL_STEP,LOG_A);
moldyn_set_log(&md,SAVE_STEP,LOG_S);
moldyn_set_log(&md,CREATE_REPORT,0);