From: hackbard Date: Wed, 11 Jul 2007 14:47:58 +0000 (+0000) Subject: average calc moved, more fscking virial testing X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=998262afd7a8593832a8cbb80f02c0eb42a493ff;p=physik%2Fposic.git average calc moved, more fscking virial testing --- diff --git a/moldyn.c b/moldyn.c index e0881de..992d112 100644 --- a/moldyn.c +++ b/moldyn.c @@ -810,12 +810,29 @@ double ideal_gas_law_pressure(t_moldyn *moldyn) { return p; } -double pressure_calc(t_moldyn *moldyn) { +double virial_sum(t_moldyn *moldyn) { int i; double v; t_virial *virial; + /* virial (sum over atom virials) */ + v=0.0; + for(i=0;icount;i++) { + virial=&(moldyn->atom[i].virial); + v+=(virial->xx+virial->yy+virial->zz); + } + moldyn->virial=v; + + /* global virial (absolute coordinates) */ + virial=&(moldyn->gvir); + moldyn->gv=virial->xx+virial->yy+virial->zz; + + return moldyn->virial; +} + +double pressure_calc(t_moldyn *moldyn) { + /* * PV = NkT + * with W = 1/3 sum_i f_i r_i (- skipped!) @@ -824,34 +841,15 @@ double pressure_calc(t_moldyn *moldyn) { * => P = (2 Ekin + virial) / (3V) */ - v=0.0; - for(i=0;icount;i++) { - virial=&(moldyn->atom[i].virial); - v+=(virial->xx+virial->yy+virial->zz); - } + /* assume up to date virial & up to date kinetic energy */ - /* virial sum and average virial */ - if(moldyn->total_steps>=moldyn->avg_skip) { - moldyn->virial_sum+=v; - moldyn->virial_avg=moldyn->virial_sum/ - (moldyn->total_steps+1-moldyn->avg_skip); - moldyn->p=2.0*moldyn->k_avg+moldyn->virial_avg; - moldyn->p/=(3.0*moldyn->volume); - moldyn->p_sum+=moldyn->p; - moldyn->p_avg=moldyn->p_sum/ - (moldyn->total_steps+1-moldyn->avg_skip); - } + /* pressure (atom virials) */ + moldyn->p=2.0*moldyn->ekin+moldyn->virial; + moldyn->p/=(3.0*moldyn->volume); - /* pressure from 'absolute coordinates' virial */ - virial=&(moldyn->virial); - v=virial->xx+virial->yy+virial->zz; - moldyn->gp=2.0*moldyn->ekin+v; + /* pressure (absolute coordinates) */ + moldyn->gp=2.0*moldyn->ekin+moldyn->gv; moldyn->gp/=(3.0*moldyn->volume); - if(moldyn->total_steps>=moldyn->avg_skip) { - moldyn->gp_sum+=moldyn->gp; - moldyn->gp_avg=moldyn->gp_sum/ - (moldyn->total_steps+1-moldyn->avg_skip); - } return moldyn->p; } @@ -861,31 +859,39 @@ int average_and_fluctuation_calc(t_moldyn *moldyn) { if(moldyn->total_stepsavg_skip) return 0; + int denom=moldyn->total_steps+1-moldyn->avg_skip; + /* assume up to date energies, temperature, pressure etc */ /* kinetic energy */ moldyn->k_sum+=moldyn->ekin; moldyn->k2_sum+=(moldyn->ekin*moldyn->ekin); - moldyn->k_avg=moldyn->k_sum/(moldyn->total_steps+1-moldyn->avg_skip); - moldyn->k2_avg=moldyn->k2_sum/(moldyn->total_steps+1-moldyn->avg_skip); + moldyn->k_avg=moldyn->k_sum/denom; + moldyn->k2_avg=moldyn->k2_sum/denom; moldyn->dk2_avg=moldyn->k2_avg-(moldyn->k_avg*moldyn->k_avg); /* potential energy */ moldyn->v_sum+=moldyn->energy; moldyn->v2_sum+=(moldyn->energy*moldyn->energy); - moldyn->v_avg=moldyn->v_sum/(moldyn->total_steps+1-moldyn->avg_skip); - moldyn->v2_avg=moldyn->v2_sum/(moldyn->total_steps+1-moldyn->avg_skip); + moldyn->v_avg=moldyn->v_sum/denom; + moldyn->v2_avg=moldyn->v2_sum/denom; moldyn->dv2_avg=moldyn->v2_avg-(moldyn->v_avg*moldyn->v_avg); /* temperature */ moldyn->t_sum+=moldyn->t; - moldyn->t_avg=moldyn->t_sum/(moldyn->total_steps+1-moldyn->avg_skip); + moldyn->t_avg=moldyn->t_sum/denom; /* 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; /* 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; return 0; } @@ -1402,6 +1408,7 @@ return 0; /* calculate kinetic energy, temperature and pressure */ e_kin_calc(moldyn); temperature_calc(moldyn); + virial_sum(moldyn); pressure_calc(moldyn); average_and_fluctuation_calc(moldyn); @@ -1467,14 +1474,12 @@ return 0; /* display progress */ if(!(i%10)) { - printf("\rsched: %d, steps: %d, T: %f, P: %f %f V: %f", - sched->count,i, - moldyn->t_avg, - //moldyn->p_avg/BAR, - moldyn->p/BAR, - moldyn->gp_avg/BAR, - moldyn->volume); - fflush(stdout); + printf("\rsched:%d, steps:%d, T:%3.1f/%3.1f P:%4.1f/%4.1f V:%6.1f", + sched->count,i, + moldyn->t,moldyn->t_avg, + moldyn->p_avg/BAR,moldyn->p/BAR, + moldyn->volume); + fflush(stdout); } /* increase absolute time */ @@ -1569,7 +1574,7 @@ int potential_force_calc(t_moldyn *moldyn) { moldyn->energy=0.0; /* reset global virial */ - memset(&(moldyn->virial),0,sizeof(t_virial)); + memset(&(moldyn->gvir),0,sizeof(t_virial)); /* reset force, site energy and virial of every atom */ for(i=0;ivirial.xx+=moldyn->atom[i].r.x*moldyn->atom[i].f.x; - moldyn->virial.yy+=moldyn->atom[i].r.y*moldyn->atom[i].f.y; - moldyn->virial.zz+=moldyn->atom[i].r.z*moldyn->atom[i].f.z; - moldyn->virial.xy+=moldyn->atom[i].r.y*moldyn->atom[i].f.x; - moldyn->virial.xz+=moldyn->atom[i].r.z*moldyn->atom[i].f.x; - moldyn->virial.yz+=moldyn->atom[i].r.z*moldyn->atom[i].f.y; + moldyn->gvir.xx+=moldyn->atom[i].r.x*moldyn->atom[i].f.x; + moldyn->gvir.yy+=moldyn->atom[i].r.y*moldyn->atom[i].f.y; + moldyn->gvir.zz+=moldyn->atom[i].r.z*moldyn->atom[i].f.z; + moldyn->gvir.xy+=moldyn->atom[i].r.y*moldyn->atom[i].f.x; + moldyn->gvir.xz+=moldyn->atom[i].r.z*moldyn->atom[i].f.x; + moldyn->gvir.yz+=moldyn->atom[i].r.z*moldyn->atom[i].f.y; } return 0; diff --git a/moldyn.h b/moldyn.h index 212db14..51ad482 100644 --- a/moldyn.h +++ b/moldyn.h @@ -109,18 +109,24 @@ typedef struct s_moldyn { double t_sum; /* sum over all t */ double t_avg; /* average value of t */ - t_virial virial; /* global virial (absolute coordinates) */ + t_virial gvir; /* global virial (absolute coordinates) */ + double gv; + double gv_sum; + double gv_avg; + double gp; /* pressure computed from global virial */ double gp_sum; /* sum over all gp */ double gp_avg; /* average value of gp */ - double virial_avg; /* average of virial */ + double virial; /* actual virial */ double virial_sum; /* sum over all calculated virials */ + double virial_avg; /* average of virial */ double p_ref; /* reference pressure */ double p; /* actual pressure (computed by virial) */ double p_sum; /* sum over all p */ double p_avg; /* average value of p */ + t_3dvec tp; /* thermodynamic pressure dU/dV */ double dv; /* dV for thermodynamic pressure calc */ @@ -416,6 +422,7 @@ double total_mass_calc(t_moldyn *moldyn); double temperature_calc(t_moldyn *moldyn); double get_temperature(t_moldyn *moldyn); int scale_velocity(t_moldyn *moldyn,u8 equi_init); +double virial_sum(t_moldyn *moldyn); double pressure_calc(t_moldyn *moldyn); int energy_fluctuation_calc(t_moldyn *moldyn); int get_heat_capacity(t_moldyn *moldyn); diff --git a/potentials/albe.c b/potentials/albe.c index 338fb03..c0a5fe4 100644 --- a/potentials/albe.c +++ b/potentials/albe.c @@ -380,13 +380,13 @@ int albe_mult_3bp_k2(t_moldyn *moldyn, /* cos_theta derivatives wrt i,j,k */ dijdik_inv=1.0/(d_ij*d_ik); - v3_scale(&dcosdrj,&dist_ik,dijdik_inv); + v3_scale(&dcosdrj,&dist_ik,dijdik_inv); // j v3_scale(&tmp,&dist_ij,-cos_theta/d_ij2); v3_add(&dcosdrj,&dcosdrj,&tmp); - v3_scale(&dcosdrk,&dist_ij,dijdik_inv); + v3_scale(&dcosdrk,&dist_ij,dijdik_inv); // k v3_scale(&tmp,&dist_ik,-cos_theta/d_ik2); v3_add(&dcosdrk,&dcosdrk,&tmp); - v3_add(&dcosdri,&dcosdrj,&dcosdrk); + v3_add(&dcosdri,&dcosdrj,&dcosdrk); // i v3_scale(&dcosdri,&dcosdri,-1.0); /* f_c_ik * dg, df_c_ik * g */ @@ -428,8 +428,8 @@ int albe_mult_3bp_k2(t_moldyn *moldyn, #endif /* virial */ - //v3_scale(&force,&force,-1.0); - //virial_calc(ai,&force,&dist_ij); + v3_scale(&force,&force,-1.0); + virial_calc(ai,&force,&dist_ij); /* derivative wrt k */ v3_scale(&force,&dist_ik,-1.0*dfcg); // dri rik = - drk rik @@ -449,7 +449,7 @@ int albe_mult_3bp_k2(t_moldyn *moldyn, #endif /* virial */ - //v3_scale(&force,&force,-1.0); + v3_scale(&force,&force,-1.0); virial_calc(ai,&force,&dist_ik); /* increase k counter */ diff --git a/sic.c b/sic.c index f8e6ce1..ba7de3d 100644 --- a/sic.c +++ b/sic.c @@ -289,7 +289,7 @@ int main(int argc,char **argv) { set_pressure(&md,BAR); /* set amount of steps to skip before average calc */ - set_mean_skip(&md,1000); + set_avg_skip(&md,1000); /* set p/t scaling */ //set_pt_scale(&md,0,0,T_SCALE_BERENDSEN,100.0);