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;i<moldyn->count;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 + <W>
* with W = 1/3 sum_i f_i r_i (- skipped!)
* => P = (2 Ekin + virial) / (3V)
*/
- v=0.0;
- for(i=0;i<moldyn->count;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;
}
if(moldyn->total_steps<moldyn->avg_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;
}
/* calculate kinetic energy, temperature and pressure */
e_kin_calc(moldyn);
temperature_calc(moldyn);
+ virial_sum(moldyn);
pressure_calc(moldyn);
average_and_fluctuation_calc(moldyn);
/* 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 */
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;i<count;i++) {
/* calculate global virial */
for(i=0;i<count;i++) {
- moldyn->virial.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;
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 */
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);
/* 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 */
#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
#endif
/* virial */
- //v3_scale(&force,&force,-1.0);
+ v3_scale(&force,&force,-1.0);
virial_calc(ai,&force,&dist_ik);
/* increase k counter */