From 4bf9958c9ed62371b6d620c7ca167bd9993d2148 Mon Sep 17 00:00:00 2001 From: hackbard Date: Thu, 30 Nov 2006 23:54:37 +0000 Subject: [PATCH] vel scaling issues, tersoff still segfaulting! --- moldyn.c | 27 ++++++++++++++++++++++----- sic.c | 14 ++++++-------- 2 files changed, 28 insertions(+), 13 deletions(-) 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; } diff --git a/sic.c b/sic.c index 82b3710..fa1cb66 100644 --- a/sic.c +++ b/sic.c @@ -15,7 +15,6 @@ #include "posic.h" int main(int argc,char **argv) { -printf("%d\n",sizeof(t_atom)); /* main moldyn structure */ t_moldyn md; @@ -86,7 +85,6 @@ printf("%d\n",sizeof(t_atom)); /* cutoff radius */ printf("[sic] setting cutoff radius\n"); set_cutoff(&md,TM_S_SI); - //set_cutoff(&md,1.0*LC_SI); /* set (initial) dimensions of simulation volume */ printf("[sic] setting dimensions\n"); @@ -99,8 +97,8 @@ printf("%d\n",sizeof(t_atom)); /* create the lattice / place atoms */ printf("[sic] creating atoms\n"); create_lattice(&md,DIAMOND,LC_SI,SI,M_SI, - ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP, - //ATOM_ATTR_2BP, + ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB, + //ATOM_ATTR_2BP|ATOM_ATTR_HB, 0,4,4,4); /* setting a nearest neighbour distance for the moldyn checks */ @@ -108,7 +106,7 @@ printf("%d\n",sizeof(t_atom)); /* set temperature */ printf("[sic] setting temperature\n"); - set_temperature(&md,10.0); + set_temperature(&md,273.0); /* initial thermal fluctuations of particles */ printf("[sic] thermal init\n"); @@ -116,12 +114,12 @@ printf("%d\n",sizeof(t_atom)); /* create the simulation schedule */ printf("[sic] adding schedule\n"); - moldyn_add_schedule(&md,1000,1.0e-15); + moldyn_add_schedule(&md,100,1.0e-15); /* activate logging */ printf("[sic] activate logging\n"); - moldyn_set_log(&md,LOG_TOTAL_ENERGY,"saves/test-energy",10); - moldyn_set_log(&md,VISUAL_STEP,"saves/test-visual",10); + moldyn_set_log(&md,LOG_TOTAL_ENERGY,"saves/test-energy",1); + moldyn_set_log(&md,VISUAL_STEP,"saves/test-visual",1); /* * let's do the actual md algorithm now -- 2.20.1