X-Git-Url: https://www.hackdaworld.org/gitweb/?a=blobdiff_plain;f=moldyn.c;h=80f4fa1b7f8cbff28fdb05b3a6e2c4f17c78faaa;hb=4bf9958c9ed62371b6d620c7ca167bd9993d2148;hp=26f298fbb58f2488f048d04dd4fbaad550e9563e;hpb=a33fe7f5d4d7e09b5b52f5f4dadd462cf868ec2f;p=physik%2Fposic.git diff --git a/moldyn.c b/moldyn.c index 26f298f..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; }