case STAGE_SET_TIMESTEP:
psize=sizeof(t_set_timestep_params);
break;
+ case STAGE_FILL:
+ psize=sizeof(t_fill_params);
+ break;
+ case STAGE_THERMAL_INIT:
+ psize=0;
+ break;
default:
printf("%s unknown stage type: %02x\n",ME,type);
return -1;
t_chsattr_params csp;
t_set_temp_params stp;
t_set_timestep_params stsp;
+ t_fill_params fp;
/* open config file */
fd=open(mdrun->cfile,O_RDONLY);
memset(&csp,0,sizeof(t_chsattr_params));
memset(&stp,0,sizeof(t_set_temp_params));
memset(&stsp,0,sizeof(t_set_timestep_params));
+ memset(&fp,0,sizeof(t_fill_params));
// get command + args
wcnt=0;
mdrun->m2=pse_mass[mdrun->element2];
}
else if(!strncmp(word[0],"fill",6)) {
- // only lc mode by now
- mdrun->lx=atoi(word[2]);
- mdrun->ly=atoi(word[3]);
- mdrun->lz=atoi(word[4]);
- mdrun->lc=atof(word[5]);
- if(wcnt==8) {
- mdrun->fill_element=atoi(word[6]);
- mdrun->fill_brand=atoi(word[7]);
+ fp.lx=atoi(word[2]);
+ fp.ly=atoi(word[3]);
+ fp.lz=atoi(word[4]);
+ fp.lc=atof(word[5]);
+ mdrun->lc=fp.lc;
+ if(!strncmp(word[1],"lc",2)) {
+ if(wcnt==8) {
+ fp.fill_element=atoi(word[6]);
+ fp.fill_brand=atoi(word[7]);
+ }
+ else {
+ fp.fill_element=mdrun->element1;
+ fp.fill_brand=0;
+ }
}
else {
- mdrun->fill_element=mdrun->element1;
- mdrun->fill_brand=0;
+ switch(word[6][0]) {
+ case 'i':
+ if(word[6][1]=='r')
+ fp.p_type=PART_INSIDE_R;
+ else
+ fp.p_type=PART_INSIDE_D;
+ break;
+ case 'o':
+ if(word[6][1]=='r')
+ fp.p_type=PART_OUTSIDE_R;
+ else
+ fp.p_type=PART_OUTSIDE_D;
+ break;
+ default:
+ break;
+ }
+ }
+ if((fp.p_type==PART_INSIDE_R)||
+ (fp.p_type==PART_OUTSIDE_R)) {
+ fp.p_vals.r=atof(word[7]);
+ fp.p_vals.p.x=atof(word[8]);
+ fp.p_vals.p.y=atof(word[9]);
+ fp.p_vals.p.z=atof(word[10]);
}
+ if((fp.p_type==PART_INSIDE_D)||
+ (fp.p_type==PART_OUTSIDE_D)) {
+ fp.p_vals.p.x=atof(word[7]);
+ fp.p_vals.p.y=atof(word[8]);
+ fp.p_vals.p.z=atof(word[9]);
+ fp.p_vals.d.x=atof(word[10]);
+ fp.p_vals.d.y=atof(word[11]);
+ fp.p_vals.d.z=atof(word[12]);
+ }
+ fp.lattice=mdrun->lattice;
+ add_stage(mdrun,STAGE_FILL,&fp);
+ }
+ else if(!strncmp(word[0],"thermal_init",12)) {
+ add_stage(mdrun,STAGE_THERMAL_INIT,NULL);
}
else if(!strncmp(word[0],"aattr",5)) {
// for aatrib line we need a special stage
t_list *sl;
int steps;
u8 change_stage;
+ t_3dvec o;
t_insert_atoms_params *iap;
t_insert_mixed_atoms_params *imp;
t_anneal_params *ap;
t_set_temp_params *stp;
t_set_timestep_params *stsp;
+ t_fill_params *fp;
moldyn=ptr1;
mdrun=ptr2;
mdrun->timestep=stsp->tau;
change_stage=TRUE;
break;
+ case STAGE_FILL:
+ stage_print(" -> fill lattice\n\n");
+ fp=stage->params;
+ if(fp->lattice!=ZINCBLENDE) {
+ create_lattice(moldyn,
+ fp->lattice,fp->lc,
+ mdrun->element1,
+ mdrun->m1,
+ DEFAULT_ATOM_ATTR,0,
+ fp->lx,fp->ly,fp->lz,
+ NULL,fp->p_type,
+ &(fp->p_vals));
+ }
+ else {
+ o.x=0.5*0.25*fp->lc;
+ o.y=o.x;
+ o.z=o.x;
+ create_lattice(moldyn,
+ FCC,fp->lc,
+ mdrun->element1,
+ mdrun->m1,
+ DEFAULT_ATOM_ATTR,0,
+ fp->lx,fp->ly,fp->lz,
+ &o,fp->p_type,
+ &(fp->p_vals));
+ o.x+=0.25*fp->lc;
+ o.y=o.x;
+ o.z=o.x;
+ create_lattice(moldyn,
+ FCC,fp->lc,
+ mdrun->element2,
+ mdrun->m2,
+ DEFAULT_ATOM_ATTR,1,
+ fp->lx,fp->ly,fp->lz,
+ &o,fp->p_type,
+ &(fp->p_vals));
+ }
+ moldyn_bc_check(moldyn);
+ change_stage=TRUE;
+ break;
+ case STAGE_THERMAL_INIT:
+ stage_print(" -> thermal init\n\n");
+ thermal_init(moldyn,TRUE);
+ change_stage=TRUE;
+ break;
default:
printf("%s unknwon stage type\n",ME);
break;
t_mdrun mdrun;
t_moldyn moldyn;
- t_3dvec o;
+ //t_3dvec o;
/* clear structs */
memset(&mdrun,0,sizeof(t_mdrun));
/* initial lattice and dimensions */
set_dim(&moldyn,mdrun.dim.x,mdrun.dim.y,mdrun.dim.z,mdrun.vis);
set_pbc(&moldyn,mdrun.pbcx,mdrun.pbcy,mdrun.pbcz);
+ /* replaced by fill stage !!
switch(mdrun.lattice) {
case FCC:
create_lattice(&moldyn,FCC,mdrun.lc,mdrun.fill_element,
return -1;
}
moldyn_bc_check(&moldyn);
+ replaced by fill stage !! */
/* temperature and pressure */
set_temperature(&moldyn,mdrun.temperature);
set_pressure(&moldyn,mdrun.pressure);
+ /* replaced thermal_init stage
thermal_init(&moldyn,TRUE);
+ */
addsched:
/* first schedule */
/* debug */
if(ret!=new) {
- printf("[moldyn] creating lattice failed\n");
+ printf("[moldyn] creating %s lattice (lc=%f) incomplete\n",
+ name,lc);
+ printf(" (ignore in case of partial lattice creation)\n");
printf(" amount of atoms\n");
printf(" - expected: %d\n",new);
printf(" - created: %d\n",ret);
- return -1;
}
- moldyn->count+=new;
- printf("[moldyn] created %s lattice with %d atoms\n",name,new);
+ moldyn->count+=ret;
+ if(ret==new)
+ printf("[moldyn] created %s lattice with %d atoms\n",name,ret);
- for(ret=0;ret<new;ret++) {
- atom[ret].element=element;
- atom[ret].mass=mass;
- atom[ret].attr=attr;
- atom[ret].brand=brand;
- atom[ret].tag=count+ret;
- check_per_bound(moldyn,&(atom[ret].r));
- atom[ret].r_0=atom[ret].r;
+ for(new=0;new<ret;new++) {
+ atom[new].element=element;
+ atom[new].mass=mass;
+ atom[new].attr=attr;
+ atom[new].brand=brand;
+ atom[new].tag=count+new;
+ check_per_bound(moldyn,&(atom[new].r));
+ atom[new].r_0=atom[new].r;
#ifdef PTHREADS
- pthread_mutex_init(&(mutex[ret]),NULL);
+ pthread_mutex_init(&(mutex[new]),NULL);
#endif
}
+ /* fix allocation */
+ ptr=realloc(moldyn->atom,moldyn->count*sizeof(t_atom));
+ if(!ptr) {
+ perror("[moldyn] realloc (create lattice - alloc fix)");
+ return -1;
+ }
+ moldyn->atom=ptr;
+
+#ifdef LOWMEM_LISTS
+ ptr=realloc(moldyn->lc.subcell->list,moldyn->count*sizeof(int));
+ if(!ptr) {
+ perror("[moldyn] list realloc (create lattice)");
+ return -1;
+ }
+ moldyn->lc.subcell->list=ptr;
+#endif
+
/* update total system mass */
total_mass_calc(moldyn);
int i,j,k;
t_3dvec o;
t_3dvec dist;
+ t_3dvec p;
+
+ p.x=0; p.y=0; p.z=0;
count=0;
if(origin)
/* shift partition values */
if(p_type) {
- p_vals->p.x+=(a*lc)/2.0;
- p_vals->p.y+=(b*lc)/2.0;
- p_vals->p.z+=(c*lc)/2.0;
+ p.x=p_vals->p.x+(a*lc)/2.0;
+ p.y=p_vals->p.y+(b*lc)/2.0;
+ p.z=p_vals->p.z+(c*lc)/2.0;
}
r.x=o.x;
for(k=0;k<c;k++) {
switch(p_type) {
case PART_INSIDE_R:
- v3_sub(&dist,&r,&(p_vals->p));
+ v3_sub(&dist,&r,&p);
if(v3_absolute_square(&dist)<(p_vals->r*p_vals->r)) {
v3_copy(&(atom[count].r),&r);
count+=1;
}
break;
case PART_OUTSIDE_R:
- v3_sub(&dist,&r,&(p_vals->p));
+ v3_sub(&dist,&r,&p);
if(v3_absolute_square(&dist)>=(p_vals->r*p_vals->r)) {
v3_copy(&(atom[count].r),&r);
count+=1;
+ }
+ break;
+ case PART_INSIDE_D:
+ v3_sub(&dist,&r,&p);
+ if((fabs(dist.x)<p_vals->d.x)&&
+ (fabs(dist.y)<p_vals->d.y)&&
+ (fabs(dist.z)<p_vals->d.z)) {
+ v3_copy(&(atom[count].r),&r);
+ count+=1;
+ }
+ break;
+ case PART_OUTSIDE_D:
+ v3_sub(&dist,&r,&p);
+ if((fabs(dist.x)>=p_vals->d.x)||
+ (fabs(dist.y)>=p_vals->d.y)||
+ (fabs(dist.z)>=p_vals->d.z)) {
+ v3_copy(&(atom[count].r),&r);
+ count+=1;
}
break;
default:
t_3dvec o,r,n;
t_3dvec basis[3];
t_3dvec dist;
+ t_3dvec p;
+
+ p.x=0; p.y=0; p.z=0;
count=0;
if(origin)
/* shift partition values */
if(p_type) {
- p_vals->p.x+=(a*lc)/2.0;
- p_vals->p.y+=(b*lc)/2.0;
- p_vals->p.z+=(c*lc)/2.0;
+ p.x=p_vals->p.x+(a*lc)/2.0;
+ p.y=p_vals->p.y+(b*lc)/2.0;
+ p.z=p_vals->p.z+(c*lc)/2.0;
}
/* fill up the room */
/* first atom */
switch(p_type) {
case PART_INSIDE_R:
- v3_sub(&dist,&r,&(p_vals->p));
+ v3_sub(&dist,&r,&p);
if(v3_absolute_square(&dist)<(p_vals->r*p_vals->r)) {
v3_copy(&(atom[count].r),&r);
count+=1;
}
break;
case PART_OUTSIDE_R:
- v3_sub(&dist,&r,&(p_vals->p));
+ v3_sub(&dist,&r,&p);
if(v3_absolute_square(&dist)>=(p_vals->r*p_vals->r)) {
v3_copy(&(atom[count].r),&r);
count+=1;
+ }
+ break;
+ case PART_INSIDE_D:
+ v3_sub(&dist,&r,&p);
+ if((fabs(dist.x)<p_vals->d.x)&&
+ (fabs(dist.y)<p_vals->d.y)&&
+ (fabs(dist.z)<p_vals->d.z)) {
+ v3_copy(&(atom[count].r),&r);
+ count+=1;
+ }
+ break;
+ case PART_OUTSIDE_D:
+ v3_sub(&dist,&r,&p);
+ if((fabs(dist.x)>=p_vals->d.x)||
+ (fabs(dist.y)>=p_vals->d.y)||
+ (fabs(dist.z)>=p_vals->d.z)) {
+ v3_copy(&(atom[count].r),&r);
+ count+=1;
}
break;
default:
v3_add(&n,&r,&basis[l]);
switch(p_type) {
case PART_INSIDE_R:
- v3_sub(&dist,&n,&(p_vals->p));
+ v3_sub(&dist,&n,&p);
if(v3_absolute_square(&dist)<(p_vals->r*p_vals->r)) {
- v3_copy(&(atom[count].r),&r);
+ v3_copy(&(atom[count].r),&n);
count+=1;
}
break;
case PART_OUTSIDE_R:
- v3_sub(&dist,&n,&(p_vals->p));
+ v3_sub(&dist,&n,&p);
if(v3_absolute_square(&dist)>=(p_vals->r*p_vals->r)) {
- v3_copy(&(atom[count].r),&r);
+ v3_copy(&(atom[count].r),&n);
count+=1;
}
break;
+ case PART_INSIDE_D:
+ v3_sub(&dist,&n,&p);
+ if((fabs(dist.x)<p_vals->d.x)&&
+ (fabs(dist.y)<p_vals->d.y)&&
+ (fabs(dist.z)<p_vals->d.z)) {
+ v3_copy(&(atom[count].r),&n);
+ count+=1;
+ }
+ break;
+ case PART_OUTSIDE_D:
+ v3_sub(&dist,&n,&p);
+ if((fabs(dist.x)>=p_vals->d.x)||
+ (fabs(dist.y)>=p_vals->d.y)||
+ (fabs(dist.z)>=p_vals->d.z)) {
+ v3_copy(&(atom[count].r),&n);
+ count+=1;
+ }
+ break;
default:
v3_copy(&(atom[count].r),&n);
count+=1;
/* assume up to date kinetic energy, which is 3/2 N k_B T */
- moldyn->t=(2.0*moldyn->ekin)/(3.0*K_BOLTZMANN*moldyn->count);
+ if(moldyn->count)
+ moldyn->t=(2.0*moldyn->ekin)/(3.0*K_BOLTZMANN*moldyn->count);
+ else moldyn->t=0.0;
return moldyn->t;
}
}
/* global virial (absolute coordinates) */
- virial=&(moldyn->gvir);
- moldyn->gv=virial->xx+virial->yy+virial->zz;
+ //virial=&(moldyn->gvir);
+ //moldyn->gv=virial->xx+virial->yy+virial->zz;
return moldyn->virial;
}
moldyn->p=2.0*moldyn->ekin+moldyn->virial;
moldyn->p/=(3.0*moldyn->volume);
+ moldyn->px=2.0*moldyn->ekinx+moldyn->vir.xx;
+ moldyn->px/=moldyn->volume;
+ moldyn->py=2.0*moldyn->ekiny+moldyn->vir.yy;
+ moldyn->py/=moldyn->volume;
+ moldyn->pz=2.0*moldyn->ekinz+moldyn->vir.zz;
+ moldyn->pz/=moldyn->volume;
+
/* pressure (absolute coordinates) */
- moldyn->gp=2.0*moldyn->ekin+moldyn->gv;
- moldyn->gp/=(3.0*moldyn->volume);
+ //moldyn->gp=2.0*moldyn->ekin+moldyn->gv;
+ //moldyn->gp/=(3.0*moldyn->volume);
return moldyn->p;
}
/* virial */
moldyn->virial_sum=0.0;
- moldyn->gv_sum=0.0;
+ //moldyn->gv_sum=0.0;
/* pressure */
moldyn->p_sum=0.0;
- moldyn->gp_sum=0.0;
+ //moldyn->gp_sum=0.0;
moldyn->tp_sum=0.0;
return 0;
/* virial */
moldyn->virial_sum+=moldyn->virial;
moldyn->virial_avg=moldyn->virial_sum/denom;
- moldyn->gv_sum+=moldyn->gv;
- moldyn->gv_avg=moldyn->gv_sum/denom;
+ //moldyn->gv_sum+=moldyn->gv;
+ //moldyn->gv_avg=moldyn->gv_sum/denom;
/* pressure */
moldyn->p_sum+=moldyn->p;
moldyn->p_avg=moldyn->p_sum/denom;
- moldyn->gp_sum+=moldyn->gp;
- moldyn->gp_avg=moldyn->gp_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;
}
+int scale_atoms_ind(t_moldyn *moldyn,double x,double y,double z) {
+
+ int i;
+ t_3dvec *r;
+
+ for(i=0;i<moldyn->count;i++) {
+ r=&(moldyn->atom[i].r);
+ r->x*=x;
+ r->y*=y;
+ r->z*=z;
+ }
+
+ return 0;
+}
+
+int scale_dim_ind(t_moldyn *moldyn,double x,double y,double z) {
+
+ t_3dvec *dim;
+
+ dim=&(moldyn->dim);
+
+ dim->x*=x;
+ dim->y*=y;
+ dim->z*=z;
+
+ return 0;
+}
+
int scale_volume(t_moldyn *moldyn) {
t_3dvec *dim,*vdim;
- double scale;
+ //double scale;
t_linkcell *lc;
+ double sx,sy,sz;
vdim=&(moldyn->vis.dim);
dim=&(moldyn->dim);
lc=&(moldyn->lc);
/* scaling factor */
+ /*
if(moldyn->pt_scale&P_SCALE_BERENDSEN) {
scale=1.0-(moldyn->p_ref-moldyn->p)*moldyn->p_tc*moldyn->tau;
scale=pow(scale,ONE_THIRD);
else {
scale=pow(moldyn->p/moldyn->p_ref,ONE_THIRD);
}
+ */
+
+ sx=1.0-(moldyn->p_ref-moldyn->px)*moldyn->p_tc*moldyn->tau;
+ sy=1.0-(moldyn->p_ref-moldyn->py)*moldyn->p_tc*moldyn->tau;
+ sz=1.0-(moldyn->p_ref-moldyn->pz)*moldyn->p_tc*moldyn->tau;
+ sx=pow(sx,ONE_THIRD);
+ sy=pow(sy,ONE_THIRD);
+ sz=pow(sz,ONE_THIRD);
/* scale the atoms and dimensions */
- scale_atoms(moldyn,SCALE_DIRECT,scale,TRUE,TRUE,TRUE);
- scale_dim(moldyn,SCALE_DIRECT,scale,TRUE,TRUE,TRUE);
+ //scale_atoms(moldyn,SCALE_DIRECT,scale,TRUE,TRUE,TRUE);
+ //scale_dim(moldyn,SCALE_DIRECT,scale,TRUE,TRUE,TRUE);
+ scale_atoms_ind(moldyn,sx,sy,sz);
+ scale_dim_ind(moldyn,sx,sy,sz);
/* visualize dimensions */
if(vdim->x!=0) {
link_cell_shutdown(moldyn);
link_cell_init(moldyn,QUIET);
} else {
- lc->x*=scale;
- lc->y*=scale;
- lc->z*=scale;
+ //lc->x*=scale;
+ //lc->y*=scale;
+ //lc->z*=scale;
+ lc->x*=sx;
+ lc->y*=sx;
+ lc->z*=sy;
}
return 0;
atom=moldyn->atom;
moldyn->ekin=0.0;
+ moldyn->ekinx=0.0;
+ moldyn->ekiny=0.0;
+ moldyn->ekinz=0.0;
for(i=0;i<moldyn->count;i++) {
atom[i].ekin=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v));
moldyn->ekin+=atom[i].ekin;
+ moldyn->ekinx+=0.5*atom[i].mass*atom[i].v.x*atom[i].v.x;
+ moldyn->ekiny+=0.5*atom[i].mass*atom[i].v.y*atom[i].v.y;
+ moldyn->ekinz+=0.5*atom[i].mass*atom[i].v.z*atom[i].v.z;
}
return moldyn->ekin;
dprintf(moldyn->pfd,
"%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->p/BAR,moldyn->p_avg/BAR,
moldyn->tp/BAR,moldyn->tp_avg/BAR);
}
}
if(v) {
if(!(moldyn->total_steps%v)) {
dprintf(moldyn->vfd,
- "%f %f\n",moldyn->time,moldyn->volume);
+ "%f %f %f %f %f\n",moldyn->time,
+ moldyn->volume,
+ moldyn->dim.x,
+ moldyn->dim.y,
+ moldyn->dim.z);
}
}
if(s) {
size-=cnt;
}
+#ifdef PTHREADS
+ amutex=malloc(moldyn->count*sizeof(pthread_mutex_t));
+ if(amutex==NULL) {
+ perror("[moldyn] load save file (mutexes)");
+ return -1;
+ }
+ for(cnt=0;cnt<moldyn->count;cnt++)
+ pthread_mutex_init(&(amutex[cnt]),NULL);
+#endif
+
// hooks etc ...
return 0;