dprintf(moldyn->efd,"# total momentum log file\n");
printf("total momentum (%d)\n",timer);
break;
+ case LOG_PRESSURE:
+ moldyn->pwrite=timer;
+ snprintf(filename,127,"%s/pressure",moldyn->vlsdir);
+ moldyn->pfd=open(filename,
+ O_WRONLY|O_CREAT|O_EXCL,
+ S_IRUSR|S_IWUSR);
+ if(moldyn->pfd<0) {
+ perror("[moldyn] pressure log file\n");
+ return moldyn->pfd;
+ }
+ dprintf(moldyn->pfd,"# pressure log file\n");
+ printf("pressure (%d)\n",timer);
+ break;
+ case LOG_TEMPERATURE:
+ moldyn->twrite=timer;
+ snprintf(filename,127,"%s/temperature",moldyn->vlsdir);
+ moldyn->tfd=open(filename,
+ O_WRONLY|O_CREAT|O_EXCL,
+ S_IRUSR|S_IWUSR);
+ if(moldyn->tfd<0) {
+ perror("[moldyn] temperature log file\n");
+ return moldyn->tfd;
+ }
+ dprintf(moldyn->tfd,"# temperature log file\n");
+ printf("temperature (%d)\n",timer);
+ break;
case SAVE_STEP:
moldyn->swrite=timer;
printf("save file (%d)\n",timer);
perror("[moldyn] report fd open");
return moldyn->rfd;
}
- snprintf(filename,127,"%s/plot.scr",moldyn->vlsdir);
- moldyn->pfd=open(filename,
- O_WRONLY|O_CREAT|O_EXCL,
- S_IRUSR|S_IWUSR);
- if(moldyn->pfd<0) {
- perror("[moldyn] plot fd open");
- return moldyn->pfd;
+ if(moldyn->efd) {
+ snprintf(filename,127,"%s/e_plot.scr",
+ moldyn->vlsdir);
+ moldyn->epfd=open(filename,
+ O_WRONLY|O_CREAT|O_EXCL,
+ S_IRUSR|S_IWUSR);
+ if(moldyn->epfd<0) {
+ perror("[moldyn] energy plot fd open");
+ return moldyn->epfd;
+ }
+ dprintf(moldyn->epfd,e_plot_script);
+ close(moldyn->epfd);
+ }
+ if(moldyn->pfd) {
+ snprintf(filename,127,"%s/pressure_plot.scr",
+ moldyn->vlsdir);
+ moldyn->ppfd=open(filename,
+ O_WRONLY|O_CREAT|O_EXCL,
+ S_IRUSR|S_IWUSR);
+ if(moldyn->ppfd<0) {
+ perror("[moldyn] p plot fd open");
+ return moldyn->ppfd;
+ }
+ dprintf(moldyn->ppfd,pressure_plot_script);
+ close(moldyn->ppfd);
+ }
+ if(moldyn->tfd) {
+ snprintf(filename,127,"%s/temperature_plot.scr",
+ moldyn->vlsdir);
+ moldyn->tpfd=open(filename,
+ O_WRONLY|O_CREAT|O_EXCL,
+ S_IRUSR|S_IWUSR);
+ if(moldyn->tpfd<0) {
+ perror("[moldyn] t plot fd open");
+ return moldyn->tpfd;
+ }
+ dprintf(moldyn->tpfd,temperature_plot_script);
+ close(moldyn->tpfd);
}
dprintf(moldyn->rfd,report_start,
moldyn->rauthor,moldyn->rtitle);
- dprintf(moldyn->pfd,plot_script);
- close(moldyn->pfd);
break;
default:
printf("unknown log type: %02x\n",type);
char sc[256];
printf("[moldyn] log shutdown\n");
- if(moldyn->efd) close(moldyn->efd);
+ if(moldyn->efd) {
+ close(moldyn->efd);
+ if(moldyn->rfd) {
+ dprintf(moldyn->rfd,report_energy);
+ snprintf(sc,255,"cd %s && gnuplot e_plot.scr",
+ moldyn->vlsdir);
+ system(sc);
+ }
+ }
if(moldyn->mfd) close(moldyn->mfd);
+ if(moldyn->pfd) {
+ close(moldyn->pfd);
+ if(moldyn->rfd)
+ dprintf(moldyn->rfd,report_pressure);
+ snprintf(sc,255,"cd %s && gnuplot pressure_plot.scr",
+ moldyn->vlsdir);
+ system(sc);
+ }
+ if(moldyn->tfd) {
+ close(moldyn->tfd);
+ if(moldyn->rfd)
+ dprintf(moldyn->rfd,report_temperature);
+ snprintf(sc,255,"cd %s && gnuplot temperature_plot.scr",
+ moldyn->vlsdir);
+ system(sc);
+ }
if(moldyn->rfd) {
dprintf(moldyn->rfd,report_end);
close(moldyn->rfd);
- snprintf(sc,255,"cd %s && gnuplot plot.scr",moldyn->vlsdir);
- system(sc);
snprintf(sc,255,"cd %s && pdflatex report",moldyn->vlsdir);
system(sc);
snprintf(sc,255,"cd %s && pdflatex report",moldyn->vlsdir);
t_virial *virial;
/*
- * P = 1/(3V) sum_i ( p_i^2 / 2m + f_i r_i )
- *
- * virial = f_i r_i
+ * PV = NkT + <W>
+ * W = 1/3 sum_i f_i r_i
+ * virial = sum_i f_i r_i
+ *
+ * => P = (2 Ekin + virial) / (3V)
*/
v=0.0;
t_3dvec dim,*tp;
double u,p;
- double scale;
+ double scale,dv;
t_atom *store;
+ /*
+ * dU = - p dV
+ *
+ * => p = - dU/dV
+ *
+ * dV: dx,y,z = 0.001 x,y,z
+ */
+
+ scale=1.00001;
+printf("\n\nP-DEBUG:\n");
+
tp=&(moldyn->tp);
store=malloc(moldyn->count*sizeof(t_atom));
if(store==NULL) {
dim=moldyn->dim;
/* derivative with respect to x direction */
- scale=1.0+moldyn->dv/(moldyn->dim.y*moldyn->dim.z);
scale_dim(moldyn,scale,TRUE,0,0);
scale_atoms(moldyn,scale,TRUE,0,0);
+ dv=0.00001*moldyn->dim.x*moldyn->dim.y*moldyn->dim.z;
link_cell_shutdown(moldyn);
link_cell_init(moldyn,QUIET);
potential_force_calc(moldyn);
- tp->x=(moldyn->energy-u)/moldyn->dv;
+ tp->x=(moldyn->energy-u)/dv;
p=tp->x*tp->x;
+printf("e: %f eV de: %f eV dV: %f A^3\n",moldyn->energy/moldyn->count/EV,(moldyn->energy-u)/moldyn->count/EV,dv);
/* restore atomic configuration + dim */
memcpy(moldyn->atom,store,moldyn->count*sizeof(t_atom));
moldyn->dim=dim;
/* derivative with respect to y direction */
- scale=1.0+moldyn->dv/(moldyn->dim.x*moldyn->dim.z);
scale_dim(moldyn,scale,0,TRUE,0);
scale_atoms(moldyn,scale,0,TRUE,0);
+ dv=0.00001*moldyn->dim.y*moldyn->dim.x*moldyn->dim.z;
link_cell_shutdown(moldyn);
link_cell_init(moldyn,QUIET);
potential_force_calc(moldyn);
- tp->y=(moldyn->energy-u)/moldyn->dv;
+ tp->y=(moldyn->energy-u)/dv;
p+=tp->y*tp->y;
/* restore atomic configuration + dim */
moldyn->dim=dim;
/* derivative with respect to z direction */
- scale=1.0+moldyn->dv/(moldyn->dim.x*moldyn->dim.y);
scale_dim(moldyn,scale,0,0,TRUE);
scale_atoms(moldyn,scale,0,0,TRUE);
+ dv=0.00001*moldyn->dim.z*moldyn->dim.x*moldyn->dim.y;
link_cell_shutdown(moldyn);
link_cell_init(moldyn,QUIET);
potential_force_calc(moldyn);
- tp->z=(moldyn->energy-u)/moldyn->dv;
+ tp->z=(moldyn->energy-u)/dv;
p+=tp->z*tp->z;
/* restore atomic configuration + dim */
memcpy(moldyn->atom,store,moldyn->count*sizeof(t_atom));
moldyn->dim=dim;
- printf("dU/dV komp addiert = %f %f %f\n",tp->x,tp->y,tp->z);
-
- scale=1.0+pow(moldyn->dv/moldyn->volume,ONE_THIRD);
-
-printf("debug: %f %f\n",moldyn->atom[0].r.x,moldyn->dim.x);
- scale_dim(moldyn,scale,1,1,1);
- scale_atoms(moldyn,scale,1,1,1);
- link_cell_shutdown(moldyn);
- link_cell_init(moldyn,QUIET);
- potential_force_calc(moldyn);
-printf("debug: %f %f\n",moldyn->atom[0].r.x,moldyn->dim.x);
-
- printf("dU/dV einfach = %f\n",((moldyn->energy-u)/moldyn->dv)/ATM);
-
- /* restore atomic configuration + dim */
- memcpy(moldyn->atom,store,moldyn->count*sizeof(t_atom));
- moldyn->dim=dim;
-
/* restore energy */
moldyn->energy=u;
int moldyn_integrate(t_moldyn *moldyn) {
int i;
- unsigned int e,m,s,v;
- t_3dvec p;
+ unsigned int e,m,s,v,p,t;
+ t_3dvec momentum;
t_moldyn_schedule *sched;
t_atom *atom;
int fd;
char dir[128];
double ds;
double energy_scale;
+ //double tp;
sched=&(moldyn->schedule);
atom=moldyn->atom;
m=moldyn->mwrite;
s=moldyn->swrite;
v=moldyn->vwrite;
+ p=moldyn->pwrite;
+ t=moldyn->twrite;
/* sqaure of some variables */
moldyn->tau_square=moldyn->tau*moldyn->tau;
update_e_kin(moldyn);
temperature_calc(moldyn);
pressure_calc(moldyn);
- //thermodynamic_pressure_calc(moldyn);
+ //tp=thermodynamic_pressure_calc(moldyn);
/* p/t scaling */
if(moldyn->pt_scale&(T_SCALE_BERENDSEN|T_SCALE_DIRECT))
}
if(m) {
if(!(i%m)) {
- p=get_total_p(moldyn);
+ momentum=get_total_p(moldyn);
dprintf(moldyn->mfd,
- "%f %f\n",moldyn->time,v3_norm(&p));
+ "%f %f %f %f %f\n",moldyn->time,
+ momentum.x,momentum.y,momentum.z,
+ v3_norm(&momentum));
+ }
+ }
+ if(p) {
+ if(!(i%p)) {
+ dprintf(moldyn->pfd,
+ "%f %f\n",moldyn->time,moldyn->p/ATM);
+ }
+ }
+ if(t) {
+ if(!(i%t)) {
+ dprintf(moldyn->tfd,
+ "%f %f\n",moldyn->time,moldyn->t);
}
}
if(s) {
if(!(i%v)) {
visual_atoms(&(moldyn->vis),moldyn->time,
moldyn->atom,moldyn->count);
- printf("\rsched: %d, steps: %d, T: %f, P: %f V: %f",
- sched->count,i,
- moldyn->t,moldyn->p/ATM,moldyn->volume);
- fflush(stdout);
}
}
+ /* display progress */
+ if(!(i%10)) {
+ printf("\rsched: %d, steps: %d, T: %f, P: %f V: %f",
+ sched->count,i,
+ moldyn->t,moldyn->p/ATM,moldyn->volume);
+ fflush(stdout);
+ }
+
/* increase absolute time */
moldyn->time+=moldyn->tau;
v3_add(&(ai->f),&(ai->f),&force);
/* virial */
- ai->virial.xx-=force.x*dist_ij.x;
- ai->virial.yy-=force.y*dist_ij.y;
- ai->virial.zz-=force.z*dist_ij.z;
- ai->virial.xy-=force.x*dist_ij.y;
- ai->virial.xz-=force.x*dist_ij.z;
- ai->virial.yz-=force.y*dist_ij.z;
+ virial_calc(ai,&force,&dist_ij);
+ //ai->virial.xx-=force.x*dist_ij.x;
+ //ai->virial.yy-=force.y*dist_ij.y;
+ //ai->virial.zz-=force.z*dist_ij.z;
+ //ai->virial.xy-=force.x*dist_ij.y;
+ //ai->virial.xz-=force.x*dist_ij.z;
+ //ai->virial.yz-=force.y*dist_ij.z;
#ifdef DEBUG
if(ai==&(moldyn->atom[0])) {
v3_add(&(ai->f),&(ai->f),&force);
/* virial */
- ai->virial.xx-=force.x*dist_ij->x;
- ai->virial.yy-=force.y*dist_ij->y;
- ai->virial.zz-=force.z*dist_ij->z;
- ai->virial.xy-=force.x*dist_ij->y;
- ai->virial.xz-=force.x*dist_ij->z;
- ai->virial.yz-=force.y*dist_ij->z;
+ virial_calc(ai,&force,dist_ij);
+ //ai->virial.xx-=force.x*dist_ij->x;
+ //ai->virial.yy-=force.y*dist_ij->y;
+ //ai->virial.zz-=force.z*dist_ij->z;
+ //ai->virial.xy-=force.x*dist_ij->y;
+ //ai->virial.xz-=force.x*dist_ij->z;
+ //ai->virial.yz-=force.y*dist_ij->z;
#ifdef DEBUG
if(ai==&(moldyn->atom[0])) {
/* virial - plus sign, as dist_ij = - dist_ji - (really??) */
// TEST ... with a minus instead
- ai->virial.xx-=force.x*dist_ij->x;
- ai->virial.yy-=force.y*dist_ij->y;
- ai->virial.zz-=force.z*dist_ij->z;
- ai->virial.xy-=force.x*dist_ij->y;
- ai->virial.xz-=force.x*dist_ij->z;
- ai->virial.yz-=force.y*dist_ij->z;
+ virial_calc(ai,&force,dist_ij);
+ //ai->virial.xx-=force.x*dist_ij->x;
+ //ai->virial.yy-=force.y*dist_ij->y;
+ //ai->virial.zz-=force.z*dist_ij->z;
+ //ai->virial.xy-=force.x*dist_ij->y;
+ //ai->virial.xz-=force.x*dist_ij->z;
+ //ai->virial.yz-=force.y*dist_ij->z;
#ifdef DEBUG
if(ai==&(moldyn->atom[0])) {
#include "potentials/lennard_jones.h"
#include "potentials/tersoff.h"
+#define INJECT 20
+#define NR_ATOMS 20
+
int hook(void *moldyn,void *hook_params) {
t_moldyn *md;
+ t_3dvec r,v,dist;
+ double d;
+ unsigned char run;
+ int i,j;
+ t_atom *atom;
md=moldyn;
- /* switch to direct scaling in first hook */
- if(md->schedule.count==0)
+ printf("\nschedule hook: ");
+
+ if(!(md->schedule.count%2)) {
+ /* add carbon at random place, and enable t scaling */
+ for(j=0;j<NR_ATOMS;j++) {
+ run=1;
+ while(run) {
+ r.x=rand_get_double(&(md->random))*md->dim.x;
+ r.y=rand_get_double(&(md->random))*md->dim.y;
+ r.z=rand_get_double(&(md->random))*md->dim.z;
+ for(i=0;i<md->count;i++) {
+ atom=&(md->atom[i]);
+ v3_sub(&dist,&(atom->r),&r);
+ d=v3_absolute_square(&dist);
+ if(d>TM_R_C)
+ run=0;
+ }
+ }
+ v.x=0; v.y=0; v.z=0;
+ add_atom(md,C,M_C,1,
+ ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
+ &r,&v);
+ }
+ printf("adding atoms & enable t scaling\n");
set_pt_scale(md,0,0,T_SCALE_BERENDSEN,100.0);
- /* switch off temp scaling in second hook */
- if(md->schedule.count==1)
+ }
+ else {
+ /* disable t scaling */
+ printf("disabling t scaling\n");
set_pt_scale(md,0,0,0,0);
-
- //set_temperature(md,md->t_ref-100.0);
+ }
return 0;
}
t_ho_params ho;
t_tersoff_mult_params tp;
+ /* atom injection counter */
+ int inject;
+
/* testing location & velocity vector */
t_3dvec r,v;
memset(&r,0,sizeof(t_3dvec));
thermal_init(&md,TRUE);
/* create the simulation schedule */
- moldyn_add_schedule(&md,10001,1.0);
- //moldyn_add_schedule(&md,501,1.0);
- //moldyn_add_schedule(&md,501,1.0);
+ /* initial configuration */
+ moldyn_add_schedule(&md,500,1.0);
+ /* adding atoms */
+ for(inject=0;inject<INJECT;inject++) {
+ /* injecting atom and run with enabled t scaling */
+ moldyn_add_schedule(&md,400,1.0);
+ /* continue running with disabled t scaling */
+ moldyn_add_schedule(&md,100,1.0);
+ }
/* schedule hook function */
- //moldyn_set_schedule_hook(&md,&hook,NULL);
+ moldyn_set_schedule_hook(&md,&hook,NULL);
/* activate logging */
moldyn_set_log_dir(&md,argv[1]);
moldyn_set_report(&md,"Frank Zirkelbach","Test 1");
- moldyn_set_log(&md,LOG_TOTAL_ENERGY,1);
+ moldyn_set_log(&md,LOG_TOTAL_ENERGY,10);
+ moldyn_set_log(&md,LOG_TEMPERATURE,10);
+ moldyn_set_log(&md,LOG_PRESSURE,10);
moldyn_set_log(&md,VISUAL_STEP,100);
+ moldyn_set_log(&md,SAVE_STEP,100);
moldyn_set_log(&md,CREATE_REPORT,0);
/*