X-Git-Url: https://www.hackdaworld.org/gitweb/?a=blobdiff_plain;f=moldyn.c;h=80f4fa1b7f8cbff28fdb05b3a6e2c4f17c78faaa;hb=4bf9958c9ed62371b6d620c7ca167bd9993d2148;hp=ed831aed93ec4861c71a383033af863ef1378074;hpb=dece53fc37f9ebb52b33c9743333c213be2d6f26;p=physik%2Fposic.git diff --git a/moldyn.c b/moldyn.c index ed831ae..80f4fa1 100644 --- a/moldyn.c +++ b/moldyn.c @@ -72,7 +72,7 @@ int set_cutoff(t_moldyn *moldyn,double cutoff) { } int set_temperature(t_moldyn *moldyn,double t) { - + moldyn->t=t; return 0; @@ -331,6 +331,7 @@ int scale_velocity(t_moldyn *moldyn,u8 type) { int i; double e,scale; t_atom *atom; + int count; atom=moldyn->atom; @@ -339,13 +340,29 @@ int scale_velocity(t_moldyn *moldyn,u8 type) { */ e=0.0; - for(i=0;icount;i++) - e+=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v)); - scale=(1.5*moldyn->count*K_BOLTZMANN*moldyn->t)/e; + count=0; + for(i=0;icount;i++) { + if(atom[i].attr&ATOM_ATTR_HB) { + e+=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v)); + count+=1; + } + } + + /* temporary hack for e,t = 0 */ + if(e==0.0) { + if(moldyn->t!=0.0) + thermal_init(moldyn); + else + return 0; + } + + /* direct scaling */ + scale=(1.5*count*K_BOLTZMANN*moldyn->t)/e; if(type&VSCALE_INIT_EQUI) scale*=2.0; /* equipartition theorem */ scale=sqrt(scale); for(i=0;icount;i++) - v3_scale(&(atom[i].v),&(atom[i].v),scale); + if(atom[i].attr&ATOM_ATTR_HB) + v3_scale(&(atom[i].v),&(atom[i].v),scale); return 0; } @@ -497,7 +514,6 @@ int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell) { count2=27; a=nx*ny; - cell[0]=lc->subcell[i+j*nx+k*a]; for(ci=-1;ci<=1;ci++) { bx=0; @@ -636,7 +652,6 @@ int moldyn_integrate(t_moldyn *moldyn) { /* zero absolute time */ moldyn->time=0.0; - for(sched=0;schedschedule.content_count;sched++) { /* setting amount of runs and finite time step size */ @@ -760,15 +775,15 @@ int velocity_verlet(t_moldyn *moldyn) { int potential_force_calc(t_moldyn *moldyn) { int i,j,k,count; - t_atom *atom,*btom,*ktom; + t_atom *itom,*jtom,*ktom; t_linkcell *lc; - t_list neighbour[27]; - t_list *this,*thisk,*neighbourk; - u8 bc,bck; + t_list neighbour_i[27],neighbour_j[27]; + t_list *this,*that; + u8 bc_ij,bc_ijk; int countn,dnlc; count=moldyn->count; - atom=moldyn->atom; + itom=moldyn->atom; lc=&(moldyn->lc); /* reset energy */ @@ -777,87 +792,117 @@ int potential_force_calc(t_moldyn *moldyn) { for(i=0;ifunc1b(moldyn,&(atom[i])); + if(itom[i].attr&ATOM_ATTR_1BP) + moldyn->func1b(moldyn,&(itom[i])); /* 2 body pair potential/force */ - if(atom[i].attr&(ATOM_ATTR_2BP|ATOM_ATTR_3BP)) { + if(itom[i].attr&(ATOM_ATTR_2BP|ATOM_ATTR_3BP)) { link_cell_neighbour_index(moldyn, - (atom[i].r.x+moldyn->dim.x/2)/lc->x, - (atom[i].r.y+moldyn->dim.y/2)/lc->y, - (atom[i].r.z+moldyn->dim.z/2)/lc->z, - neighbour); + (itom[i].r.x+moldyn->dim.x/2)/lc->x, + (itom[i].r.y+moldyn->dim.y/2)/lc->y, + (itom[i].r.z+moldyn->dim.z/2)/lc->z, + neighbour_i); countn=lc->countn; dnlc=lc->dnlc; for(j=0;jstart==NULL) continue; - bc=(jcurrent->data; + jtom=this->current->data; - if(btom==&(atom[i])) + if(jtom==&(itom[i])) continue; - if((btom->attr&ATOM_ATTR_2BP)& - (atom[i].attr&ATOM_ATTR_2BP)) + if((jtom->attr&ATOM_ATTR_2BP)& + (itom[i].attr&ATOM_ATTR_2BP)) moldyn->func2b(moldyn, - &(atom[i]), - btom, - bc); + &(itom[i]), + jtom, + bc_ij); /* 3 body potential/force */ - if(!(atom[i].attr&ATOM_ATTR_3BP)|| - !(btom->attr&ATOM_ATTR_3BP)) + if(!(itom[i].attr&ATOM_ATTR_3BP)|| + !(jtom->attr&ATOM_ATTR_3BP)) continue; -printf("DEBUG: problem exists here ...\n"); link_cell_neighbour_index(moldyn, - (btom->r.x+moldyn->dim.x/2)/lc->x, - (btom->r.y+moldyn->dim.y/2)/lc->y, - (btom->r.z+moldyn->dim.z/2)/lc->z, - neighbourk); -printf("DEBUG: as you won't see that!\n"); + (jtom->r.x+moldyn->dim.x/2)/lc->x, + (jtom->r.y+moldyn->dim.y/2)/lc->y, + (jtom->r.z+moldyn->dim.z/2)/lc->z, + neighbour_j); + /* neighbours of j */ for(k=0;kcountn;k++) { - thisk=&(neighbourk[k]); - list_reset(thisk); + that=&(neighbour_j[k]); + list_reset(that); + + if(that->start==NULL) + continue; + + bc_ijk=(kdnlc)?0:1; + + do { + + ktom=that->current->data; + + if(!(ktom->attr&ATOM_ATTR_3BP)) + continue; + + if(ktom==jtom) + continue; + + if(ktom==&(itom[i])) + continue; + + moldyn->func3b(moldyn,&(itom[i]),jtom,ktom,bc_ijk); + + } while(list_next(that)!=\ + L_NO_NEXT_ELEMENT); + + } + + /* neighbours of i */ + for(k=0;kstart==NULL) + if(that->start==NULL) continue; - bck=(kdnlc)?0:1; + bc_ijk=(kcurrent->data; + ktom=that->current->data; if(!(ktom->attr&ATOM_ATTR_3BP)) continue; - if(ktom==btom) + if(ktom==jtom) continue; - if(ktom==&(atom[i])) + if(ktom==&(itom[i])) continue; - moldyn->func3b(moldyn,&(atom[i]),btom,ktom,bck); + moldyn->func3b(moldyn,&(itom[i]),jtom,ktom,bc_ijk); - } while(list_next(thisk)!=\ + } while(list_next(that)!=\ L_NO_NEXT_ELEMENT); }