From 8fb52958cee33f248f72b308bf8056ac40b0ab04 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 30 Nov 2007 21:54:30 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@1193 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/ASPHERE/pair_gayberne.cpp | 34 +- src/ASPHERE/pair_resquared.cpp | 39 +- src/CLASS2/angle_class2.cpp | 99 ++--- src/CLASS2/bond_class2.cpp | 60 +-- src/CLASS2/bond_class2.h | 2 +- src/CLASS2/dihedral_class2.cpp | 251 +++++------ src/CLASS2/improper_class2.cpp | 101 ++--- src/CLASS2/pair_lj_class2.cpp | 44 +- src/CLASS2/pair_lj_class2_coul_cut.cpp | 56 ++- src/CLASS2/pair_lj_class2_coul_long.cpp | 56 ++- src/COLLOID/pair_colloid.cpp | 60 ++- src/COLLOID/pair_lubricate.cpp | 53 +-- src/DIPOLE/pair_dipole_cut.cpp | 62 ++- src/DPD/pair_dpd.cpp | 51 ++- src/GRANULAR/pair_gran_hertzian.cpp | 30 +- src/GRANULAR/pair_gran_history.cpp | 32 +- src/GRANULAR/pair_gran_no_history.cpp | 32 +- src/KSPACE/pair_buck_coul_long.cpp | 56 ++- src/KSPACE/pair_coul_long.cpp | 50 +-- src/KSPACE/pair_lj_charmm_coul_long.cpp | 173 ++++---- src/KSPACE/pair_lj_cut_coul_long.cpp | 165 ++++---- src/KSPACE/pair_lj_cut_coul_long_tip4p.cpp | 73 ++-- src/MANYBODY/pair_airebo.cpp | 391 ++++++++++-------- src/MANYBODY/pair_airebo.h | 7 +- src/MANYBODY/pair_eam.cpp | 67 ++- src/MANYBODY/pair_eam.h | 2 - src/MANYBODY/pair_sw.cpp | 36 +- src/MANYBODY/pair_tersoff.cpp | 60 +-- src/MOLECULE/angle.cpp | 183 ++++++++ src/MOLECULE/angle_charmm.cpp | 89 ++-- src/MOLECULE/angle_cosine.cpp | 69 ++-- src/MOLECULE/angle_cosine_squared.cpp | 72 ++-- src/MOLECULE/angle_harmonic.cpp | 72 ++-- src/MOLECULE/angle_hybrid.cpp | 34 +- src/MOLECULE/bond.cpp | 164 +++++++- src/MOLECULE/bond_fene.cpp | 70 +--- src/MOLECULE/bond_fene.h | 2 +- src/MOLECULE/bond_fene_expand.cpp | 72 +--- src/MOLECULE/bond_fene_expand.h | 2 +- src/MOLECULE/bond_harmonic.cpp | 58 +-- src/MOLECULE/bond_harmonic.h | 2 +- src/MOLECULE/bond_hybrid.cpp | 42 +- src/MOLECULE/bond_morse.cpp | 58 +-- src/MOLECULE/bond_morse.h | 2 +- src/MOLECULE/bond_nonlinear.cpp | 56 +-- src/MOLECULE/bond_nonlinear.h | 2 +- src/MOLECULE/bond_quartic.cpp | 111 +++-- src/MOLECULE/bond_quartic.h | 2 +- src/MOLECULE/dihedral.cpp | 207 +++++++++- src/MOLECULE/dihedral_charmm.cpp | 141 +++---- src/MOLECULE/dihedral_harmonic.cpp | 94 ++--- src/MOLECULE/dihedral_helix.cpp | 102 +++-- src/MOLECULE/dihedral_hybrid.cpp | 37 +- src/MOLECULE/dihedral_multi_harmonic.cpp | 102 +++-- src/MOLECULE/dihedral_opls.cpp | 102 +++-- src/MOLECULE/improper.cpp | 205 +++++++++ src/MOLECULE/improper_cvff.cpp | 103 +++-- src/MOLECULE/improper_harmonic.cpp | 144 +++---- src/MOLECULE/improper_hybrid.cpp | 34 +- src/MOLECULE/pair_lj_charmm_coul_charmm.cpp | 59 ++- .../pair_lj_charmm_coul_charmm_implicit.cpp | 59 ++- src/OPT/pair_eam_opt.cpp | 37 +- src/OPT/pair_eam_opt.h | 52 +-- src/OPT/pair_lj_charmm_coul_long_opt.cpp | 37 +- src/OPT/pair_lj_charmm_coul_long_opt.h | 106 ++--- src/OPT/pair_lj_cut_opt.cpp | 37 +- src/OPT/pair_lj_cut_opt.h | 90 ++-- src/OPT/pair_morse_opt.cpp | 37 +- src/OPT/pair_morse_opt.h | 96 ++--- src/USER-ACKLAND/compute_ackland_atom.cpp | 6 +- src/USER-EWALDN/pair_buck_coul.cpp | 191 ++++----- src/USER-EWALDN/pair_lj_coul.cpp | 189 ++++----- src/angle.h | 22 +- src/bond.h | 21 +- src/bond_hybrid.h | 2 +- src/compute.cpp | 1 + src/compute.h | 2 + src/compute_attribute_atom.cpp | 62 ++- src/compute_centro_atom.cpp | 1 - src/compute_coord_atom.cpp | 1 - src/compute_pe.cpp | 8 +- src/compute_pressure.cpp | 120 ++++-- src/compute_pressure.h | 3 +- src/compute_stress_atom.cpp | 355 +++++----------- src/compute_stress_atom.h | 8 +- src/compute_sum.cpp | 2 + src/dihedral.h | 25 +- src/fix_ave_atom.cpp | 58 ++- src/fix_ave_spatial.cpp | 26 +- src/fix_shake.cpp | 2 + src/improper.h | 23 +- src/integrate.cpp | 93 ++++- src/integrate.h | 10 +- src/min.cpp | 90 ++++ src/min.h | 15 +- src/min_cg.cpp | 49 +-- src/min_cg.h | 13 +- src/neigh_gran.cpp | 4 - src/neigh_half_bin.cpp | 1 - src/neigh_half_nsq.cpp | 4 - src/neighbor.cpp | 3 +- src/output.cpp | 9 + src/pair.cpp | 375 ++++++++++++++++- src/pair.h | 30 +- src/pair_buck.cpp | 46 +-- src/pair_buck_coul_cut.cpp | 56 ++- src/pair_coul_cut.cpp | 45 +- src/pair_hybrid.cpp | 76 ++-- src/pair_hybrid.h | 1 - src/pair_lj_cut.cpp | 137 +++--- src/pair_lj_cut_coul_cut.cpp | 55 ++- src/pair_lj_cut_coul_debye.cpp | 55 ++- src/pair_lj_expand.cpp | 44 +- src/pair_lj_smooth.cpp | 50 +-- src/pair_morse.cpp | 44 +- src/pair_soft.cpp | 52 +-- src/pair_table.cpp | 54 ++- src/pair_yukawa.cpp | 44 +- src/respa.cpp | 21 +- src/style.h | 6 +- src/style_granular.h | 2 - src/thermo.cpp | 10 +- src/verlet.cpp | 27 +- src/verlet.h | 4 +- 124 files changed, 4220 insertions(+), 3618 deletions(-) diff --git a/src/ASPHERE/pair_gayberne.cpp b/src/ASPHERE/pair_gayberne.cpp index 3bd54302f5..460e0bf007 100755 --- a/src/ASPHERE/pair_gayberne.cpp +++ b/src/ASPHERE/pair_gayberne.cpp @@ -74,15 +74,16 @@ PairGayBerne::~PairGayBerne() void PairGayBerne::compute(int eflag, int vflag) { - int i,j,ii,jj,m,inum,jnum,itype,jtype; - double one_eng,rsq,r2inv,r6inv,forcelj; + int i,j,ii,jj,inum,jnum,itype,jtype; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fx,fy,fz; + double one_eng,rsq,r2inv,r6inv,forcelj,factor_lj; double fforce[3],ttor[3],rtor[3],r12[3]; double a1[3][3],b1[3][3],g1[3][3],a2[3][3],b2[3][3],g2[3][3],temp[3][3]; int *ilist,*jlist,*numneigh,**firstneigh; - double factor_lj; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; @@ -90,7 +91,7 @@ void PairGayBerne::compute(int eflag, int vflag) double **tor = atom->torque; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -188,25 +189,16 @@ void PairGayBerne::compute(int eflag, int vflag) tor[j][2] += rtor[2]; } - if (eflag) { - if (newton_pair || j < nlocal) eng_vdwl += factor_lj*one_eng; - else eng_vdwl += 0.5*factor_lj*one_eng; - } + if (eflag) evdwl = factor_lj*one_eng; - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) - for (m = 0; m < 6; m++) fforce[m] *= 0.5; - virial[0] -= r12[0]*fforce[0]; - virial[1] -= r12[1]*fforce[1]; - virial[2] -= r12[2]*fforce[2]; - virial[3] -= r12[0]*fforce[1]; - virial[4] -= r12[0]*fforce[2]; - virial[5] -= r12[1]*fforce[2]; - } + if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair, + evdwl,0.0,fforce[0],fforce[1],fforce[2], + -r12[0],-r12[1],-r12[2]); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/ASPHERE/pair_resquared.cpp b/src/ASPHERE/pair_resquared.cpp index be511ba3c2..10e072f702 100755 --- a/src/ASPHERE/pair_resquared.cpp +++ b/src/ASPHERE/pair_resquared.cpp @@ -80,23 +80,23 @@ PairRESquared::~PairRESquared() void PairRESquared::compute(int eflag, int vflag) { - int i,j,ii,jj,m,inum,jnum,itype,jtype; - double one_eng,rsq,r2inv,r6inv,forcelj; + int i,j,ii,jj,inum,jnum,itype,jtype; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fx,fy,fz; + double one_eng,rsq,r2inv,r6inv,forcelj,factor_lj; double fforce[3],ttor[3],rtor[3],r12[3]; int *ilist,*jlist,*numneigh,**firstneigh; - double factor_lj; RE2Vars wi,wj; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; - double **quat = atom->quat; double **tor = atom->torque; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -155,7 +155,7 @@ void PairRESquared::compute(int eflag, int vflag) case SPHERE_ELLIPSE: precompute_i(j,wj); - if (newton_pair || j= nlocal) - for (m = 0; m < 6; m++) fforce[m] *= 0.5; - virial[0] -= r12[0]*fforce[0]; - virial[1] -= r12[1]*fforce[1]; - virial[2] -= r12[2]*fforce[2]; - virial[3] -= r12[0]*fforce[1]; - virial[4] -= r12[0]*fforce[2]; - virial[5] -= r12[1]*fforce[2]; - } + if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair, + evdwl,0.0,fforce[0],fforce[1],fforce[2], + -r12[0],-r12[1],-r12[2]); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/CLASS2/angle_class2.cpp b/src/CLASS2/angle_class2.cpp index e98ab6eb02..7a926f7856 100644 --- a/src/CLASS2/angle_class2.cpp +++ b/src/CLASS2/angle_class2.cpp @@ -64,15 +64,17 @@ AngleClass2::~AngleClass2() void AngleClass2::compute(int eflag, int vflag) { - int i1,i2,i3,n,type,factor; - double delx1,dely1,delz1,delx2,dely2,delz2,rfactor; + int i1,i2,i3,n,type; + double delx1,dely1,delz1,delx2,dely2,delz2; + double eangle,f1[3],f3[3]; double dtheta,dtheta2,dtheta3,dtheta4,de_angle; double dr1,dr2,tk1,tk2,aa1,aa2,aa11,aa12,aa21,aa22; - double rsq1,rsq2,r1,r2,c,s,a,a11,a12,a22,b1,b2,vx1,vx2,vy1,vy2,vz1,vz2; + double rsq1,rsq2,r1,r2,c,s,a,a11,a12,a22,b1,b2; double vx11,vx12,vy11,vy12,vz11,vz12,vx21,vx22,vy21,vy22,vz21,vz22; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + eangle = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -82,21 +84,11 @@ void AngleClass2::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nanglelist; n++) { - i1 = anglelist[n][0]; i2 = anglelist[n][1]; i3 = anglelist[n][2]; type = anglelist[n][3]; - if (newton_bond) factor = 3; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - } - rfactor = factor/3.0; - // 1st bond delx1 = x[i1][0] - x[i2][0]; @@ -139,22 +131,20 @@ void AngleClass2::compute(int eflag, int vflag) de_angle = 2.0*k2[type]*dtheta + 3.0*k3[type]*dtheta2 + 4.0*k4[type]*dtheta3; - a = de_angle*s; - + a = -de_angle*s; a11 = a*c / rsq1; a12 = -a / (r1*r2); a22 = a*c / rsq2; - vx1 = a11*delx1 + a12*delx2; - vy1 = a11*dely1 + a12*dely2; - vz1 = a11*delz1 + a12*delz2; + f1[0] = a11*delx1 + a12*delx2; + f1[1] = a11*dely1 + a12*dely2; + f1[2] = a11*delz1 + a12*delz2; - vx2 = a22*delx2 + a12*delx1; - vy2 = a22*dely2 + a12*dely1; - vz2 = a22*delz2 + a12*delz1; + f3[0] = a22*delx2 + a12*delx1; + f3[1] = a22*dely2 + a12*dely1; + f3[2] = a22*delz2 + a12*delz1; - if (eflag) energy += rfactor * - (k2[type]*dtheta2 + k3[type]*dtheta3 + k4[type]*dtheta4); + if (eflag) eangle = k2[type]*dtheta2 + k3[type]*dtheta3 + k4[type]*dtheta4; // force & energy for bond-bond term @@ -163,15 +153,15 @@ void AngleClass2::compute(int eflag, int vflag) tk1 = bb_k[type] * dr1; tk2 = bb_k[type] * dr2; - vx1 += delx1*tk2/r1; - vy1 += dely1*tk2/r1; - vz1 += delz1*tk2/r1; + f1[0] -= delx1*tk2/r1; + f1[2] -= dely1*tk2/r1; + f1[2] -= delz1*tk2/r1; - vx2 += delx2*tk1/r2; - vy2 += dely2*tk1/r2; - vz2 += delz2*tk1/r2; + f3[0] -= delx2*tk1/r2; + f3[1] -= dely2*tk1/r2; + f3[2] -= delz2*tk1/r2; - if (eflag) energy += rfactor * bb_k[type]*dr1*dr2; + if (eflag) eangle += bb_k[type]*dr1*dr2; // force & energy for bond-angle term @@ -203,47 +193,38 @@ void AngleClass2::compute(int eflag, int vflag) b1 = ba_k1[type] * dtheta / r1; b2 = ba_k2[type] * dtheta / r2; - vx1 += vx11 + b1*delx1 + vx12; - vy1 += vy11 + b1*dely1 + vy12; - vz1 += vz11 + b1*delz1 + vz12; + f1[0] -= vx11 + b1*delx1 + vx12; + f1[2] -= vy11 + b1*dely1 + vy12; + f1[2] -= vz11 + b1*delz1 + vz12; - vx2 += vx21 + b2*delx2 + vx22; - vy2 += vy21 + b2*dely2 + vy22; - vz2 += vz21 + b2*delz2 + vz22; + f3[0] -= vx21 + b2*delx2 + vx22; + f3[1] -= vy21 + b2*dely2 + vy22; + f3[2] -= vz21 + b2*delz2 + vz22; - if (eflag) energy += rfactor * - ((ba_k1[type]*dr1*dtheta) + (ba_k2[type]*dr2*dtheta)); + if (eflag) eangle += ba_k1[type]*dr1*dtheta + ba_k2[type]*dr2*dtheta; // apply force to each of 3 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= vx1; - f[i1][1] -= vy1; - f[i1][2] -= vz1; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += vx1 + vx2; - f[i2][1] += vy1 + vy2; - f[i2][2] += vz1 + vz2; + f[i2][0] -= f1[0] + f3[0]; + f[i2][1] -= f1[1] + f3[1]; + f[i2][2] -= f1[2] + f3[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] -= vx2; - f[i3][1] -= vy2; - f[i3][2] -= vz2; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } - // virial contribution - - if (vflag) { - virial[0] -= rfactor * (delx1*vx1 + delx2*vx2); - virial[1] -= rfactor * (dely1*vy1 + dely2*vy2); - virial[2] -= rfactor * (delz1*vz1 + delz2*vz2); - virial[3] -= rfactor * (delx1*vy1 + delx2*vy2); - virial[4] -= rfactor * (delx1*vz1 + delx2*vz2); - virial[5] -= rfactor * (dely1*vz1 + dely2*vz2); - } + if (evflag) ev_tally(i1,i2,i3,nlocal,newton_bond,eangle,f1,f3, + delx1,dely1,delz1,delx2,dely2,delz2); } } diff --git a/src/CLASS2/bond_class2.cpp b/src/CLASS2/bond_class2.cpp index 00de3c7944..da744a2539 100644 --- a/src/CLASS2/bond_class2.cpp +++ b/src/CLASS2/bond_class2.cpp @@ -49,11 +49,13 @@ BondClass2::~BondClass2() void BondClass2::compute(int eflag, int vflag) { - int i1,i2,n,type,factor; - double delx,dely,delz,rsq,r,dr,dr2,dr3,dr4,de_bond,fforce,rfactor; + int i1,i2,n,type; + double delx,dely,delz,ebond,fbond; + double rsq,r,dr,dr2,dr3,dr4,de_bond; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + ebond = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -63,19 +65,10 @@ void BondClass2::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nbondlist; n++) { - i1 = bondlist[n][0]; i2 = bondlist[n][1]; type = bondlist[n][2]; - if (newton_bond) factor = 2; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - } - rfactor = 0.5 * factor; - delx = x[i1][0] - x[i2][0]; dely = x[i1][1] - x[i2][1]; delz = x[i1][2] - x[i2][2]; @@ -91,36 +84,26 @@ void BondClass2::compute(int eflag, int vflag) // force & energy de_bond = 2.0*k2[type]*dr + 3.0*k3[type]*dr2 + 4.0*k4[type]*dr3; - if (r > 0.0) fforce = -de_bond/r; - else fforce = 0.0; + if (r > 0.0) fbond = -de_bond/r; + else fbond = 0.0; - if (eflag) - energy += rfactor * (k2[type]*dr2 + k3[type]*dr3 + k4[type]*dr4); + if (eflag) ebond = k2[type]*dr2 + k3[type]*dr3 + k4[type]*dr4; // apply force to each of 2 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] += delx*fforce; - f[i1][1] += dely*fforce; - f[i1][2] += delz*fforce; + f[i1][0] += delx*fbond; + f[i1][1] += dely*fbond; + f[i1][2] += delz*fbond; } if (newton_bond || i2 < nlocal) { - f[i2][0] -= delx*fforce; - f[i2][1] -= dely*fforce; - f[i2][2] -= delz*fforce; + f[i2][0] -= delx*fbond; + f[i2][1] -= dely*fbond; + f[i2][2] -= delz*fbond; } - // virial contribution - - if (vflag) { - virial[0] += rfactor*delx*delx*fforce; - virial[1] += rfactor*dely*dely*fforce; - virial[2] += rfactor*delz*delz*fforce; - virial[3] += rfactor*delx*dely*fforce; - virial[4] += rfactor*delx*delz*fforce; - virial[5] += rfactor*dely*delz*fforce; - } + if (evflag) ev_tally(i1,i2,nlocal,newton_bond,ebond,fbond,delx,dely,delz); } } @@ -215,19 +198,12 @@ void BondClass2::read_restart(FILE *fp) /* ---------------------------------------------------------------------- */ -void BondClass2::single(int type, double rsq, int i, int j, - int eflag, double &fforce, double &eng) +void BondClass2::single(int type, double rsq, int i, int j, double &eng) { double r = sqrt(rsq); double dr = r - r0[type]; double dr2 = dr*dr; double dr3 = dr2*dr; double dr4 = dr3*dr; - - // force & energy - - double de_bond = 2.0*k2[type]*dr + 3.0*k3[type]*dr2 + 4.0*k4[type]*dr3; - if (r > 0.0) fforce = -de_bond/r; - else fforce = 0.0; - if (eflag) eng = k2[type]*dr2 + k3[type]*dr3 + k4[type]*dr4; + eng = k2[type]*dr2 + k3[type]*dr3 + k4[type]*dr4; } diff --git a/src/CLASS2/bond_class2.h b/src/CLASS2/bond_class2.h index eff507b660..07b066431b 100644 --- a/src/CLASS2/bond_class2.h +++ b/src/CLASS2/bond_class2.h @@ -28,7 +28,7 @@ class BondClass2 : public Bond { double equilibrium_distance(int); void write_restart(FILE *); void read_restart(FILE *); - void single(int, double, int, int, int, double &, double &); + void single(int, double, int, int, double &); private: double *r0,*k2,*k3,*k4; diff --git a/src/CLASS2/dihedral_class2.cpp b/src/CLASS2/dihedral_class2.cpp index 26716de1ef..f1fa159e2c 100644 --- a/src/CLASS2/dihedral_class2.cpp +++ b/src/CLASS2/dihedral_class2.cpp @@ -101,23 +101,23 @@ DihedralClass2::~DihedralClass2() void DihedralClass2::compute(int eflag, int vflag) { - int i1,i2,i3,i4,i,j,k,n,type,factor; - double rfactor; - double delx1,dely1,delz1,dely2,delz2,delx2m,dely2m,delz2m; - double delx2,dely3,delz3,r1mag2,r1,r2mag2,r2,r3mag2,r3; + int i1,i2,i3,i4,i,j,k,n,type; + double vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z,vb2xm,vb2ym,vb2zm; + double edihedral; + double r1mag2,r1,r2mag2,r2,r3mag2,r3; double sb1,rb1,sb2,rb2,sb3,rb3,c0,r12c1; double r12c2,costh12,costh13,costh23,sc1,sc2,s1,s2,c; double cosphi,phi,sinphi,a11,a22,a33,a12,a13,a23,sx1,sx2; double sx12,sy1,sy2,sy12,sz1,sz2,sz12,dphi1,dphi2,dphi3; double de_dihedral,t1,t2,t3,t4,cos2phi,cos3phi,bt1,bt2; double bt3,sumbte,db,sumbtf,at1,at2,at3,da,da1,da2,r1_0; - double r3_0,dr1,dr2,tk1,tk2,vx1,vx2,vx3,vy1,vy2,vy3,vz1; - double vz2,vz3,delx3,s12,sin2; + double r3_0,dr1,dr2,tk1,tk2,s12,sin2; double dcosphidr[4][3],dphidr[4][3],dbonddr[3][4][3],dthetadr[2][4][3]; double fabcd[4][3]; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + edihedral = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -127,76 +127,63 @@ void DihedralClass2::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < ndihedrallist; n++) { - i1 = dihedrallist[n][0]; i2 = dihedrallist[n][1]; i3 = dihedrallist[n][2]; i4 = dihedrallist[n][3]; type = dihedrallist[n][4]; - if (newton_bond) factor = 4; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - if (i4 < nlocal) factor++; - } - rfactor = 0.25 * factor; - // 1st bond - delx1 = x[i1][0] - x[i2][0]; - dely1 = x[i1][1] - x[i2][1]; - delz1 = x[i1][2] - x[i2][2]; - domain->minimum_image(delx1,dely1,delz1); + vb1x = x[i1][0] - x[i2][0]; + vb1y = x[i1][1] - x[i2][1]; + vb1z = x[i1][2] - x[i2][2]; + domain->minimum_image(vb1x,vb1y,vb1z); // 2nd bond - delx2 = x[i3][0] - x[i2][0]; - dely2 = x[i3][1] - x[i2][1]; - delz2 = x[i3][2] - x[i2][2]; - domain->minimum_image(delx2,dely2,delz2); + vb2x = x[i3][0] - x[i2][0]; + vb2y = x[i3][1] - x[i2][1]; + vb2z = x[i3][2] - x[i2][2]; + domain->minimum_image(vb2x,vb2y,vb2z); - delx2m = -delx2; - dely2m = -dely2; - delz2m = -delz2; - domain->minimum_image(delx2m,dely2m,delz2m); + vb2xm = -vb2x; + vb2ym = -vb2y; + vb2zm = -vb2z; + domain->minimum_image(vb2xm,vb2ym,vb2zm); // 3rd bond - delx3 = x[i4][0] - x[i3][0]; - dely3 = x[i4][1] - x[i3][1]; - delz3 = x[i4][2] - x[i3][2]; - domain->minimum_image(delx3,dely3,delz3); + vb3x = x[i4][0] - x[i3][0]; + vb3y = x[i4][1] - x[i3][1]; + vb3z = x[i4][2] - x[i3][2]; + domain->minimum_image(vb3x,vb3y,vb3z); // distances - r1mag2 = delx1*delx1 + dely1*dely1 + delz1*delz1; + r1mag2 = vb1x*vb1x + vb1y*vb1y + vb1z*vb1z; r1 = sqrt(r1mag2); - r2mag2 = delx2*delx2 + dely2*dely2 + delz2*delz2; + r2mag2 = vb2x*vb2x + vb2y*vb2y + vb2z*vb2z; r2 = sqrt(r2mag2); - r3mag2 = delx3*delx3 + dely3*dely3 + delz3*delz3; + r3mag2 = vb3x*vb3x + vb3y*vb3y + vb3z*vb3z; r3 = sqrt(r3mag2); sb1 = 1.0/r1mag2; rb1 = 1.0/r1; - sb2 = 1.0/r2mag2; rb2 = 1.0/r2; - sb3 = 1.0/r3mag2; rb3 = 1.0/r3; - c0 = (delx1*delx3 + dely1*dely3 + delz1*delz3) * rb1*rb3; + c0 = (vb1x*vb3x + vb1y*vb3y + vb1z*vb3z) * rb1*rb3; // angles r12c1 = rb1*rb2; r12c2 = rb2*rb3; - costh12 = (delx1*delx2 + dely1*dely2 + delz1*delz2) * r12c1; + costh12 = (vb1x*vb2x + vb1y*vb2y + vb1z*vb2z) * r12c1; costh13 = c0; - costh23 = (delx2m*delx3 + dely2m*dely3 + delz2m*delz3) * r12c2; + costh23 = (vb2xm*vb3x + vb2ym*vb3y + vb2zm*vb3z) * r12c2; // cos and sin of 2 angles and final c @@ -250,15 +237,15 @@ void DihedralClass2::compute(int eflag, int vflag) a13 = rb1*rb3*s12; a23 = r12c2 * (-costh23*c*s2 - costh12*s12); - sx1 = a11*delx1 + a12*delx2 + a13*delx3; - sx2 = a12*delx1 + a22*delx2 + a23*delx3; - sx12 = a13*delx1 + a23*delx2 + a33*delx3; - sy1 = a11*dely1 + a12*dely2 + a13*dely3; - sy2 = a12*dely1 + a22*dely2 + a23*dely3; - sy12 = a13*dely1 + a23*dely2 + a33*dely3; - sz1 = a11*delz1 + a12*delz2 + a13*delz3; - sz2 = a12*delz1 + a22*delz2 + a23*delz3; - sz12 = a13*delz1 + a23*delz2 + a33*delz3; + sx1 = a11*vb1x + a12*vb2x + a13*vb3x; + sx2 = a12*vb1x + a22*vb2x + a23*vb3x; + sx12 = a13*vb1x + a23*vb2x + a33*vb3x; + sy1 = a11*vb1y + a12*vb2y + a13*vb3y; + sy2 = a12*vb1y + a22*vb2y + a23*vb3y; + sy12 = a13*vb1y + a23*vb2y + a33*vb3y; + sz1 = a11*vb1z + a12*vb2z + a13*vb3z; + sz2 = a12*vb1z + a22*vb2z + a23*vb3z; + sz12 = a13*vb1z + a23*vb2z + a33*vb3z; // set up d(cos(phi))/d(r) and dphi/dr arrays @@ -285,10 +272,10 @@ void DihedralClass2::compute(int eflag, int vflag) dphi2 = 2.0*phi - phi2[type]; dphi3 = 3.0*phi - phi3[type]; - if (eflag) energy += rfactor * (k1[type]*(1.0 - cos(dphi1)) + - k2[type]*(1.0 - cos(dphi2)) + - k3[type]*(1.0 - cos(dphi3))); - + if (eflag) edihedral = k1[type]*(1.0 - cos(dphi1)) + + k2[type]*(1.0 - cos(dphi2)) + + k3[type]*(1.0 - cos(dphi3)); + de_dihedral = k1[type]*sin(dphi1) + 2.0*k2[type]*sin(dphi2) + 3.0*k3[type]*sin(dphi3); @@ -308,30 +295,30 @@ void DihedralClass2::compute(int eflag, int vflag) // bond1 - dbonddr[0][0][0] = delx1 / r1; - dbonddr[0][0][1] = dely1 / r1; - dbonddr[0][0][2] = delz1 / r1; - dbonddr[0][1][0] = -delx1 / r1; - dbonddr[0][1][1] = -dely1 / r1; - dbonddr[0][1][2] = -delz1 / r1; + dbonddr[0][0][0] = vb1x / r1; + dbonddr[0][0][1] = vb1y / r1; + dbonddr[0][0][2] = vb1z / r1; + dbonddr[0][1][0] = -vb1x / r1; + dbonddr[0][1][1] = -vb1y / r1; + dbonddr[0][1][2] = -vb1z / r1; // bond2 - dbonddr[1][1][0] = delx2 / r2; - dbonddr[1][1][1] = dely2 / r2; - dbonddr[1][1][2] = delz2 / r2; - dbonddr[1][2][0] = -delx2 / r2; - dbonddr[1][2][1] = -dely2 / r2; - dbonddr[1][2][2] = -delz2 / r2; + dbonddr[1][1][0] = vb2x / r2; + dbonddr[1][1][1] = vb2y / r2; + dbonddr[1][1][2] = vb2z / r2; + dbonddr[1][2][0] = -vb2x / r2; + dbonddr[1][2][1] = -vb2y / r2; + dbonddr[1][2][2] = -vb2z / r2; // bond3 - dbonddr[2][2][0] = delx3 / r3; - dbonddr[2][2][1] = dely3 / r3; - dbonddr[2][2][2] = delz3 / r3; - dbonddr[2][3][0] = -delx3 / r3; - dbonddr[2][3][1] = -dely3 / r3; - dbonddr[2][3][2] = -delz3 / r3; + dbonddr[2][2][0] = vb3x / r3; + dbonddr[2][2][1] = vb3y / r3; + dbonddr[2][2][2] = vb3z / r3; + dbonddr[2][3][0] = -vb3x / r3; + dbonddr[2][3][1] = -vb3y / r3; + dbonddr[2][3][2] = -vb3z / r3; // set up d(theta)/d(r) array // dthetadr(i,j,k) = angle i, atom j, coordinate k @@ -348,37 +335,37 @@ void DihedralClass2::compute(int eflag, int vflag) // angle12 - dthetadr[0][0][0] = sc1 * ((t1 * delx1) - (delx2 * r12c1)); - dthetadr[0][0][1] = sc1 * ((t1 * dely1) - (dely2 * r12c1)); - dthetadr[0][0][2] = sc1 * ((t1 * delz1) - (delz2 * r12c1)); + dthetadr[0][0][0] = sc1 * ((t1 * vb1x) - (vb2x * r12c1)); + dthetadr[0][0][1] = sc1 * ((t1 * vb1y) - (vb2y * r12c1)); + dthetadr[0][0][2] = sc1 * ((t1 * vb1z) - (vb2z * r12c1)); - dthetadr[0][1][0] = sc1 * ((-t1 * delx1) + (delx2 * r12c1) + - (-t3 * delx2) + (delx1 * r12c1)); - dthetadr[0][1][1] = sc1 * ((-t1 * dely1) + (dely2 * r12c1) + - (-t3 * dely2) + (dely1 * r12c1)); - dthetadr[0][1][2] = sc1 * ((-t1 * delz1) + (delz2 * r12c1) + - (-t3 * delz2) + (delz1 * r12c1)); + dthetadr[0][1][0] = sc1 * ((-t1 * vb1x) + (vb2x * r12c1) + + (-t3 * vb2x) + (vb1x * r12c1)); + dthetadr[0][1][1] = sc1 * ((-t1 * vb1y) + (vb2y * r12c1) + + (-t3 * vb2y) + (vb1y * r12c1)); + dthetadr[0][1][2] = sc1 * ((-t1 * vb1z) + (vb2z * r12c1) + + (-t3 * vb2z) + (vb1z * r12c1)); - dthetadr[0][2][0] = sc1 * ((t3 * delx2) - (delx1 * r12c1)); - dthetadr[0][2][1] = sc1 * ((t3 * dely2) - (dely1 * r12c1)); - dthetadr[0][2][2] = sc1 * ((t3 * delz2) - (delz1 * r12c1)); + dthetadr[0][2][0] = sc1 * ((t3 * vb2x) - (vb1x * r12c1)); + dthetadr[0][2][1] = sc1 * ((t3 * vb2y) - (vb1y * r12c1)); + dthetadr[0][2][2] = sc1 * ((t3 * vb2z) - (vb1z * r12c1)); // angle23 - dthetadr[1][1][0] = sc2 * ((t2 * delx2) + (delx3 * r12c2)); - dthetadr[1][1][1] = sc2 * ((t2 * dely2) + (dely3 * r12c2)); - dthetadr[1][1][2] = sc2 * ((t2 * delz2) + (delz3 * r12c2)); + dthetadr[1][1][0] = sc2 * ((t2 * vb2x) + (vb3x * r12c2)); + dthetadr[1][1][1] = sc2 * ((t2 * vb2y) + (vb3y * r12c2)); + dthetadr[1][1][2] = sc2 * ((t2 * vb2z) + (vb3z * r12c2)); - dthetadr[1][2][0] = sc2 * ((-t2 * delx2) - (delx3 * r12c2) + - (t4 * delx3) + (delx2 * r12c2)); - dthetadr[1][2][1] = sc2 * ((-t2 * dely2) - (dely3 * r12c2) + - (t4 * dely3) + (dely2 * r12c2)); - dthetadr[1][2][2] = sc2 * ((-t2 * delz2) - (delz3 * r12c2) + - (t4 * delz3) + (delz2 * r12c2)); + dthetadr[1][2][0] = sc2 * ((-t2 * vb2x) - (vb3x * r12c2) + + (t4 * vb3x) + (vb2x * r12c2)); + dthetadr[1][2][1] = sc2 * ((-t2 * vb2y) - (vb3y * r12c2) + + (t4 * vb3y) + (vb2y * r12c2)); + dthetadr[1][2][2] = sc2 * ((-t2 * vb2z) - (vb3z * r12c2) + + (t4 * vb3z) + (vb2z * r12c2)); - dthetadr[1][3][0] = -sc2 * ((t4 * delx3) + (delx2 * r12c2)); - dthetadr[1][3][1] = -sc2 * ((t4 * dely3) + (dely2 * r12c2)); - dthetadr[1][3][2] = -sc2 * ((t4 * delz3) + (delz2 * r12c2)); + dthetadr[1][3][0] = -sc2 * ((t4 * vb3x) + (vb2x * r12c2)); + dthetadr[1][3][1] = -sc2 * ((t4 * vb3y) + (vb2y * r12c2)); + dthetadr[1][3][2] = -sc2 * ((t4 * vb3z) + (vb2z * r12c2)); // mid-bond/torsion coupling // energy on bond2 (middle bond) @@ -391,7 +378,7 @@ void DihedralClass2::compute(int eflag, int vflag) bt3 = mbt_f3[type] * cos3phi; sumbte = bt1 + bt2 + bt3; db = r2 - mbt_r0[type]; - if (eflag) energy += rfactor * db * sumbte; + if (eflag) edihedral += db * sumbte; // force on bond2 @@ -413,7 +400,7 @@ void DihedralClass2::compute(int eflag, int vflag) sumbte = bt1 + bt2 + bt3; db = r1 - ebt_r0_1[type]; - if (eflag) energy += rfactor * db * (bt1+bt2+bt3); + if (eflag) edihedral += db * (bt1+bt2+bt3); // force on bond1 @@ -435,7 +422,7 @@ void DihedralClass2::compute(int eflag, int vflag) sumbte = bt1 + bt2 + bt3; db = r3 - ebt_r0_2[type]; - if (eflag) energy += rfactor * db * (bt1+bt2+bt3); + if (eflag) edihedral += db * (bt1+bt2+bt3); // force on bond3 @@ -457,7 +444,7 @@ void DihedralClass2::compute(int eflag, int vflag) sumbte = at1 + at2 + at3; da = acos(costh12) - at_theta0_1[type]; - if (eflag) energy += rfactor * da * (at1+at2+at3); + if (eflag) edihedral += da * (at1+at2+at3); // force on angle1 @@ -478,7 +465,7 @@ void DihedralClass2::compute(int eflag, int vflag) sumbte = at1 + at2 + at3; da = acos(costh23) - at_theta0_2[type]; - if (eflag) energy += rfactor *da * (at1+at2+at3); + if (eflag) edihedral += da * (at1+at2+at3); // force on angle2 @@ -496,11 +483,7 @@ void DihedralClass2::compute(int eflag, int vflag) da1 = acos(costh12) - aat_theta0_1[type]; da2 = acos(costh23) - aat_theta0_2[type]; - // energy - - if (eflag) energy += rfactor * aat_k[type]*da1*da2*cosphi; - - // force + if (eflag) edihedral += aat_k[type]*da1*da2*cosphi; for (i = 0; i < 4; i++) for (j = 0; j < 3; j++) @@ -519,23 +502,23 @@ void DihedralClass2::compute(int eflag, int vflag) tk1 = -bb13t_k[type] * dr1 / r3; tk2 = -bb13t_k[type] * dr2 / r1; - if (eflag) energy += rfactor * bb13t_k[type]*dr1*dr2; + if (eflag) edihedral += bb13t_k[type]*dr1*dr2; - fabcd[0][0] += tk2 * delx1; - fabcd[0][1] += tk2 * dely1; - fabcd[0][2] += tk2 * delz1; + fabcd[0][0] += tk2 * vb1x; + fabcd[0][1] += tk2 * vb1y; + fabcd[0][2] += tk2 * vb1z; - fabcd[1][0] -= tk2 * delx1; - fabcd[1][1] -= tk2 * dely1; - fabcd[1][2] -= tk2 * delz1; + fabcd[1][0] -= tk2 * vb1x; + fabcd[1][1] -= tk2 * vb1y; + fabcd[1][2] -= tk2 * vb1z; - fabcd[2][0] -= tk1 * delx3; - fabcd[2][1] -= tk1 * dely3; - fabcd[2][2] -= tk1 * delz3; + fabcd[2][0] -= tk1 * vb3x; + fabcd[2][1] -= tk1 * vb3y; + fabcd[2][2] -= tk1 * vb3z; - fabcd[3][0] += tk1 * delx3; - fabcd[3][1] += tk1 * dely3; - fabcd[3][2] += tk1 * delz3; + fabcd[3][0] += tk1 * vb3x; + fabcd[3][1] += tk1 * vb3y; + fabcd[3][2] += tk1 * vb3z; } // apply force to each of 4 atoms @@ -564,28 +547,10 @@ void DihedralClass2::compute(int eflag, int vflag) f[i4][2] += fabcd[3][2]; } - // virial contribution - - if (vflag) { - vx1 = fabcd[0][0]; - vx2 = fabcd[2][0] + fabcd[3][0]; - vx3 = fabcd[3][0]; - - vy1 = fabcd[0][1]; - vy2 = fabcd[2][1] + fabcd[3][1]; - vy3 = fabcd[3][1]; - - vz1 = fabcd[0][2]; - vz2 = fabcd[2][2] + fabcd[3][2]; - vz3 = fabcd[3][2]; - - virial[0] += rfactor * (delx1*vx1 + delx2*vx2 + delx3*vx3); - virial[1] += rfactor * (dely1*vy1 + dely2*vy2 + dely3*vy3); - virial[2] += rfactor * (delz1*vz1 + delz2*vz2 + delz3*vz3); - virial[3] += rfactor * (delx1*vy1 + delx2*vy2 + delx3*vy3); - virial[4] += rfactor * (delx1*vz1 + delx2*vz2 + delx3*vz3); - virial[5] += rfactor * (dely1*vz1 + dely2*vz2 + dely3*vz3); - } + if (evflag) + ev_tally(i1,i2,i3,i4,nlocal,newton_bond,edihedral, + fabcd[i1],fabcd[i3],fabcd[i4], + vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); } } diff --git a/src/CLASS2/improper_class2.cpp b/src/CLASS2/improper_class2.cpp index 48ab7b95c3..ab0215970d 100644 --- a/src/CLASS2/improper_class2.cpp +++ b/src/CLASS2/improper_class2.cpp @@ -63,8 +63,9 @@ ImproperClass2::~ImproperClass2() void ImproperClass2::compute(int eflag, int vflag) { - int i1,i2,i3,i4,i,j,k,n,type,factor; - double rfactor; + int i1,i2,i3,i4,i,j,k,n,type; + double vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z; + double eimproper,f1[3],f2[3],f3[3],f4[3]; double delr[3][3],rmag[3],rinvmag[3],rmag2[3]; double theta[3],costheta[3],sintheta[3]; double cossqtheta[3],sinsqtheta[3],invstheta[3]; @@ -75,7 +76,7 @@ void ImproperClass2::compute(int eflag, int vflag) double drCBxrDB[3],rCBxdrDB[3],drDBxrAB[3],rDBxdrAB[3]; double drABxrCB[3],rABxdrCB[3]; double dot1,dot2,dd[3]; - double fdot[3][4][3],f2[3][4][3],invs3r[3],inv3r; + double fdot[3][4][3],ftmp,invs3r[3],inv3r; double t,tt1,tt3,sc1; double dotCBDBAB,dotDBABCB,dotABCBDB; double chi,deltachi,d2chi,cossin2; @@ -84,8 +85,9 @@ void ImproperClass2::compute(int eflag, int vflag) double schiABCD,chiABCD,schiCBDA,chiCBDA,schiDBAC,chiDBAC; double fabcd[4][3]; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + eimproper = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; for (i = 0; i < 3; i++) for (j = 0; j < 4; j++) @@ -104,7 +106,6 @@ void ImproperClass2::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nimproperlist; n++) { - i1 = improperlist[n][0]; i2 = improperlist[n][1]; i3 = improperlist[n][2]; @@ -113,16 +114,6 @@ void ImproperClass2::compute(int eflag, int vflag) if (k0[type] == 0.0) continue; - if (newton_bond) factor = 4; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - if (i4 < nlocal) factor++; - } - rfactor = 0.25 * factor; - // difference vectors delr[0][0] = x[i1][0] - x[i2][0]; @@ -222,7 +213,7 @@ void ImproperClass2::compute(int eflag, int vflag) // energy - if (eflag) energy += rfactor * k0[type] * d2chi; + if (eflag) eimproper = k0[type]*d2chi; // forces // define d(delr) @@ -443,15 +434,15 @@ void ImproperClass2::compute(int eflag, int vflag) for (i = 0; i < 4; i++) for (j = 0; j < 3; j++) { - f2[0][i][j] = (fdot[0][i][j] * invs3r[0]) + + ftmp = (fdot[0][i][j] * invs3r[0]) + (dinvs3r[0][i][j] * dotCBDBAB); - dchi[0][i][j] = f2[0][i][j] / cos(chiABCD); - f2[1][i][j] = (fdot[1][i][j] * invs3r[1]) + + dchi[0][i][j] = ftmp / cos(chiABCD); + ftmp = (fdot[1][i][j] * invs3r[1]) + (dinvs3r[1][i][j] * dotDBABCB); - dchi[1][i][j] = f2[1][i][j] / cos(chiCBDA); - f2[2][i][j] = (fdot[2][i][j] * invs3r[2]) + + dchi[1][i][j] = ftmp / cos(chiCBDA); + ftmp = (fdot[2][i][j] * invs3r[2]) + (dinvs3r[2][i][j] * dotABCBDB); - dchi[2][i][j] = f2[2][i][j] / cos(chiDBAC); + dchi[2][i][j] = ftmp / cos(chiDBAC); dtotalchi[i][j] = (dchi[0][i][j]+dchi[1][i][j]+dchi[2][i][j]) / 3.0; } @@ -485,22 +476,13 @@ void ImproperClass2::compute(int eflag, int vflag) f[i4][2] += fabcd[3][2]; } - // virial contribution - - if (vflag) { - virial[0] += rfactor * (delr[0][0]*fabcd[0][0] + - delr[1][0]*fabcd[2][0] + delr[2][0]*fabcd[3][0]); - virial[1] += rfactor * (delr[0][1]*fabcd[0][1] + - delr[1][1]*fabcd[2][1] + delr[2][1]*fabcd[3][1]); - virial[2] += rfactor * (delr[0][2]*fabcd[0][2] + - delr[1][2]*fabcd[2][2] + delr[2][2]*fabcd[3][2]); - virial[3] += rfactor * (delr[0][0]*fabcd[0][1] + - delr[1][0]*fabcd[2][1] + delr[2][0]*fabcd[3][1]); - virial[4] += rfactor * (delr[0][0]*fabcd[0][2] + - delr[1][0]*fabcd[2][2] + delr[2][0]*fabcd[3][2]); - virial[5] += rfactor * (delr[0][1]*fabcd[0][2] + - delr[1][1]*fabcd[2][2] + delr[2][1]*fabcd[3][2]); - } + if (evflag) + ev_tally(i1,i2,i3,i4,nlocal,newton_bond,eimproper, + fabcd[i1],fabcd[i3],fabcd[i4], + delr[0][0],delr[0][1],delr[0][2], + delr[1][0],delr[1][1],delr[1][2], + delr[2][0]-delr[1][0],delr[2][1]-delr[1][1], + delr[2][2]-delr[1][2]); } // compute angle-angle interactions @@ -655,8 +637,8 @@ void ImproperClass2::read_restart(FILE *fp) void ImproperClass2::angleangle(int eflag, int vflag) { - int i1,i2,i3,i4,i,j,k,n,type,factor; - double rfactor; + int i1,i2,i3,i4,i,j,k,n,type; + double eimproper; double delxAB,delyAB,delzAB,rABmag2,rAB; double delxBC,delyBC,delzBC,rBCmag2,rBC; double delxBD,delyBD,delzBD,rBDmag2,rBD; @@ -673,23 +655,12 @@ void ImproperClass2::angleangle(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nimproperlist; n++) { - i1 = improperlist[n][0]; i2 = improperlist[n][1]; i3 = improperlist[n][2]; i4 = improperlist[n][3]; type = improperlist[n][4]; - if (newton_bond) factor = 4; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - if (i4 < nlocal) factor++; - } - rfactor = 0.25 * factor; - // difference vectors delxAB = x[i1][0] - x[i2][0]; @@ -739,9 +710,9 @@ void ImproperClass2::angleangle(int eflag, int vflag) // energy - if (eflag) energy += rfactor * ((aa_k2[type] * dthABC * dthABD) + - (aa_k1[type] * dthABC * dthCBD) + - (aa_k3[type] * dthABD * dthCBD)); + if (eflag) eimproper = aa_k2[type] * dthABC * dthABD + + aa_k1[type] * dthABC * dthCBD + + aa_k3[type] * dthABD * dthCBD; // d(theta)/d(r) array // angle i, atom j, coordinate k @@ -849,22 +820,10 @@ void ImproperClass2::angleangle(int eflag, int vflag) f[i4][2] += fabcd[3][2]; } - // virial contribution - - if (vflag) { - virial[0] += rfactor * (delxAB*fabcd[0][0] + - delxBC*fabcd[2][0] + delxBD*fabcd[3][0]); - virial[1] += rfactor * (delyAB*fabcd[0][1] + - delyBC*fabcd[2][1] + delyBD*fabcd[3][1]); - virial[2] += rfactor * (delzAB*fabcd[0][2] + - delzBC*fabcd[2][2] + delzBD*fabcd[3][2]); - virial[3] += rfactor * (delxAB*fabcd[0][1] + - delxBC*fabcd[2][1] + delxBD*fabcd[3][1]); - virial[4] += rfactor * (delxAB*fabcd[0][2] + - delxBC*fabcd[2][2] + delxBD*fabcd[3][2]); - virial[5] += rfactor * (delyAB*fabcd[0][2] + - delyBC*fabcd[2][2] + delyBD*fabcd[3][2]); - } + if (evflag) + ev_tally(i1,i2,i3,i4,nlocal,newton_bond,eimproper, + fabcd[i1],fabcd[i3],fabcd[i4], + delxAB,delyAB,delzAB,delxBC,delyBC,delzBC,delxBD,delyBD,delzBD); } } diff --git a/src/CLASS2/pair_lj_class2.cpp b/src/CLASS2/pair_lj_class2.cpp index 260eb24b46..bcce534b77 100644 --- a/src/CLASS2/pair_lj_class2.cpp +++ b/src/CLASS2/pair_lj_class2.cpp @@ -55,18 +55,19 @@ PairLJClass2::~PairLJClass2() void PairLJClass2::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,rinv,r2inv,r3inv,r6inv,forcelj,fforce,factor_lj,philj; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,rinv,r2inv,r3inv,r6inv,forcelj,factor_lj; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -107,37 +108,30 @@ void PairLJClass2::compute(int eflag, int vflag) r3inv = r2inv*rinv; r6inv = r3inv*r3inv; forcelj = r6inv * (lj1[itype][jtype]*r3inv - lj2[itype][jtype]); - fforce = factor_lj*forcelj*r2inv; + fpair = factor_lj*forcelj*r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - philj = r6inv*(lj3[itype][jtype]*r3inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r3inv-lj4[itype][jtype]) - offset[itype][jtype]; - if (newton_pair || j < nlocal) eng_vdwl += factor_lj*philj; - else eng_vdwl += 0.5*factor_lj*philj; + evdwl *= factor_lj; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/CLASS2/pair_lj_class2_coul_cut.cpp b/src/CLASS2/pair_lj_class2_coul_cut.cpp index 9ed1149629..24705e26c0 100644 --- a/src/CLASS2/pair_lj_class2_coul_cut.cpp +++ b/src/CLASS2/pair_lj_class2_coul_cut.cpp @@ -59,20 +59,21 @@ PairLJClass2CoulCut::~PairLJClass2CoulCut() void PairLJClass2CoulCut::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,rinv,r2inv,r3inv,r6inv,forcecoul,forcelj,fforce; - double factor_coul,factor_lj,factor,phicoul,philj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double rsq,rinv,r2inv,r3inv,r6inv,forcecoul,forcelj; + double factor_coul,factor_lj; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -125,44 +126,35 @@ void PairLJClass2CoulCut::compute(int eflag, int vflag) forcelj = r6inv * (lj1[itype][jtype]*r3inv - lj2[itype][jtype]); } else forcelj = 0.0; - fforce = (factor_coul*forcecoul + factor_lj*forcelj) * r2inv; + fpair = (factor_coul*forcecoul + factor_lj*forcelj) * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; - if (rsq < cut_coulsq[itype][jtype]) { - phicoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); - eng_coul += factor*factor_coul*phicoul; - } + if (rsq < cut_coulsq[itype][jtype]) + ecoul = factor_coul * qqrd2e * qtmp*q[j]*sqrt(r2inv); + else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { - philj = r6inv*(lj3[itype][jtype]*r3inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r3inv-lj4[itype][jtype]) - offset[itype][jtype]; - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/CLASS2/pair_lj_class2_coul_long.cpp b/src/CLASS2/pair_lj_class2_coul_long.cpp index 8f17f68727..02a669c4e7 100644 --- a/src/CLASS2/pair_lj_class2_coul_long.cpp +++ b/src/CLASS2/pair_lj_class2_coul_long.cpp @@ -67,21 +67,22 @@ PairLJClass2CoulLong::~PairLJClass2CoulLong() void PairLJClass2CoulLong::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r,rinv,r2inv,r3inv,r6inv,forcecoul,forcelj,fforce; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double rsq,r,rinv,r2inv,r3inv,r6inv,forcecoul,forcelj; double grij,expm2,prefactor,t,erfc; - double factor_coul,factor_lj,factor,phicoul,philj; + double factor_coul,factor_lj; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -141,45 +142,36 @@ void PairLJClass2CoulLong::compute(int eflag, int vflag) forcelj = r6inv * (lj1[itype][jtype]*r3inv - lj2[itype][jtype]); } else forcelj = 0.0; - fforce = (forcecoul + factor_lj*forcelj) * r2inv; + fpair = (forcecoul + factor_lj*forcelj) * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; if (rsq < cut_coulsq) { - phicoul = prefactor*erfc; - if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; - eng_coul += factor*phicoul; - } + ecoul = prefactor*erfc; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; + } else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { - philj = r6inv*(lj3[itype][jtype]*r3inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r3inv-lj4[itype][jtype]) - offset[itype][jtype]; - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/COLLOID/pair_colloid.cpp b/src/COLLOID/pair_colloid.cpp index 832e6b9764..70e2fb45ec 100644 --- a/src/COLLOID/pair_colloid.cpp +++ b/src/COLLOID/pair_colloid.cpp @@ -69,20 +69,21 @@ PairColloid::~PairColloid() void PairColloid::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r,fforce,forcelj,factor_lj,phi; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,r,forcelj,factor_lj; double r2inv,r6inv,c1,c2,fR,dUR,dUA; double K[9],h[4],g[4]; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -124,8 +125,8 @@ void PairColloid::compute(int eflag, int vflag) r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); - fforce = factor_lj*forcelj*r2inv; - if (eflag) phi = r6inv*(r6inv*lj3[itype][jtype]-lj4[itype][jtype]) - + fpair = factor_lj*forcelj*r2inv; + if (eflag) evdwl = r6inv*(r6inv*lj3[itype][jtype]-lj4[itype][jtype]) - offset[itype][jtype]; break; @@ -139,11 +140,11 @@ void PairColloid::compute(int eflag, int vflag) K[3] *= K[3]*K[3]; K[6] = K[3]*K[3]; fR = sigma3[itype][jtype]*a12[itype][jtype]*c2*K[1]/K[3]; - fforce = 4.0/15.0*sqrt(rsq)*fR*factor_lj * + fpair = 4.0/15.0*sqrt(rsq)*fR*factor_lj * (2.0*(K[1]+K[2]) * (K[1]*(5.0*K[1]+22.0*K[2])+5.0*K[4]) * sigma6[itype][jtype]/K[6]-5.0) / K[0]; if (eflag) - phi = 2.0/9.0*fR * + evdwl = 2.0/9.0*fR * (1.0-(K[1]*(K[1]*(K[1]/3.0+3.0*K[2])+4.2*K[4])+K[2]*K[4]) * sigma6[itype][jtype]/K[6]) - offset[itype][jtype]; break; @@ -175,43 +176,34 @@ void PairColloid::compute(int eflag, int vflag) g[3] *= -42.0*K[0]/K[6]+6.0*K[2]+K[6]; fR = a12[itype][jtype]*sigma6[itype][jtype]/r/37800.0; - phi = fR * (h[0]-h[1]-h[2]+h[3]); - dUR = phi/r + 5.0*fR*(g[0]+g[1]-g[2]-g[3]); + evdwl = fR * (h[0]-h[1]-h[2]+h[3]); + dUR = evdwl/r + 5.0*fR*(g[0]+g[1]-g[2]-g[3]); dUA = -a12[itype][jtype]/3.0*r*((2.0*K[0]*K[7]+1.0)*K[7] + (2.0*K[0]*K[8]-1.0)*K[8]); - fforce = factor_lj * (dUR+dUA)/r; + fpair = factor_lj * (dUR+dUA)/r; if (eflag) - phi += a12[itype][jtype]/6.0*(2.0*K[0]*(K[7]+K[8])-log(K[8]/K[7])) - - offset[itype][jtype]; + evdwl += a12[itype][jtype]/6.0 * + (2.0*K[0]*(K[7]+K[8])-log(K[8]/K[7])) - offset[itype][jtype]; break; } - if (eflag) { - if (newton_pair || j < nlocal) eng_vdwl += factor_lj*phi; - else eng_vdwl += 0.5*factor_lj*phi; - } + if (eflag) evdwl *= factor_lj; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/COLLOID/pair_lubricate.cpp b/src/COLLOID/pair_lubricate.cpp index d0a9c9e113..b2323d2c93 100644 --- a/src/COLLOID/pair_lubricate.cpp +++ b/src/COLLOID/pair_lubricate.cpp @@ -61,8 +61,8 @@ PairLubricate::~PairLubricate() void PairLubricate::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r,h_sep,radi,fforce,f1,f2,f3; + double xtmp,ytmp,ztmp,delx,dely,delz,fpair,fx,fy,fz; + double rsq,r,h_sep,radi; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3; double vt1,vt2,vt3,w1,w2,w3,v_shear1,v_shear2,v_shear3; double omega_t_1,omega_t_2,omega_t_3; @@ -71,11 +71,10 @@ void PairLubricate::compute(int eflag, int vflag) double P_dot_wrel_1,P_dot_wrel_2,P_dot_wrel_3; double a_squeeze,a_shear,a_pump,a_twist; int *ilist,*jlist,*numneigh,**firstneigh; - double PI = 4.0*atan(1.0); - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **v = atom->v; @@ -212,11 +211,11 @@ void PairLubricate::compute(int eflag, int vflag) (h_sep/2.0/radi) * log(2.0/(2.0*h_sep)); if (h_sep >= cut_inner[itype][jtype]) { - f1 = -a_squeeze*vn1 - a_shear*(2.0/r)*(2.0/r)*vt1 + + fx = -a_squeeze*vn1 - a_shear*(2.0/r)*(2.0/r)*vt1 + (2.0/r)*a_shear*n_cross_omega_t_1; - f2 = -a_squeeze*vn2 - a_shear*(2.0/r)*(2.0/r)*vt2 + + fy = -a_squeeze*vn2 - a_shear*(2.0/r)*(2.0/r)*vt2 + (2.0/r)*a_shear*n_cross_omega_t_2; - f3 = -a_squeeze*vn3 - a_shear*(2.0/r)*(2.0/r)*vt3 + + fz = -a_squeeze*vn3 - a_shear*(2.0/r)*(2.0/r)*vt3 + (2.0/r)*a_shear*n_cross_omega_t_3; torque[i][0] += -(2.0/r)*a_shear*v_shear1 - a_shear*omega_t_1 - @@ -227,20 +226,20 @@ void PairLubricate::compute(int eflag, int vflag) a_pump*P_dot_wrel_3 - a_twist*wn3; } else { - fforce = -vnnr*(3.0*PI*mu*radi/2.0)*radi/4.0/cut_inner[itype][jtype]; - f1 = fforce*delx/r; - f2 = fforce*dely/r; - f3 = fforce*delz/r; + fpair = -vnnr*(3.0*PI*mu*radi/2.0)*radi/4.0/cut_inner[itype][jtype]; + fx = fpair*delx/r; + fy = fpair*dely/r; + fz = fpair*delz/r; } - f[i][0] += f1; - f[i][1] += f2; - f[i][2] += f3; + f[i][0] += fx; + f[i][1] += fy; + f[i][2] += fz; if (newton_pair || j < nlocal) { - f[j][0] -= f1; - f[j][1] -= f2; - f[j][2] -= f3; + f[j][0] -= fx; + f[j][1] -= fy; + f[j][2] -= fz; if (h_sep >= cut_inner[itype][jtype]) { torque[j][0] += -(2.0/r)*a_shear*v_shear1 - a_shear*omega_t_1 + @@ -252,23 +251,13 @@ void PairLubricate::compute(int eflag, int vflag) } } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) { - f1 *= 0.5; - f2 *= 0.5; - f3 *= 0.5; - } - virial[0] += delx*f1; - virial[1] += dely*f2; - virial[2] += delz*f3; - virial[3] += delx*f2; - virial[4] += delx*f3; - virial[5] += dely*f3; - } + if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair, + 0.0,0.0,fx,fy,fz,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/DIPOLE/pair_dipole_cut.cpp b/src/DIPOLE/pair_dipole_cut.cpp index e7e0777a78..98d02f3f99 100644 --- a/src/DIPOLE/pair_dipole_cut.cpp +++ b/src/DIPOLE/pair_dipole_cut.cpp @@ -61,18 +61,17 @@ PairDipoleCut::~PairDipoleCut() void PairDipoleCut::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fx,fy,fz; double rsq,rinv,r2inv,r6inv,r3inv,r5inv,r7inv; - double forcecoulx,forcecouly,forcecoulz,fforce,crossx,crossy,crossz; + double forcecoulx,forcecouly,forcecoulz,crossx,crossy,crossz; double tixcoul,tiycoul,tizcoul,tjxcoul,tjycoul,tjzcoul; - double fq,fx,fy,fz; - double pdotp,pidotr,pjdotr,pre1,pre2,pre3,pre4; + double fq,pdotp,pidotr,pjdotr,pre1,pre2,pre3,pre4; double forcelj,factor_coul,factor_lj; - double factor,phicoul,philj; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; @@ -82,7 +81,7 @@ void PairDipoleCut::compute(int eflag, int vflag) int *type = atom->type; double *dipole = atom->dipole; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -209,15 +208,15 @@ void PairDipoleCut::compute(int eflag, int vflag) if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); - fforce = factor_lj * forcelj*r2inv; - } else fforce = 0.0; + forcelj *= factor_lj * r2inv; + } else forcelj = 0.0; // total force fq = factor_coul*qqrd2e; - fx = fq*forcecoulx + delx*fforce; - fy = fq*forcecouly + dely*fforce; - fz = fq*forcecoulz + delz*fforce; + fx = fq*forcecoulx + delx*forcelj; + fy = fq*forcecouly + dely*forcelj; + fz = fq*forcecoulz + delz*forcelj; // force & torque accumulation @@ -238,42 +237,31 @@ void PairDipoleCut::compute(int eflag, int vflag) } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; - if (rsq < cut_coulsq[itype][jtype]) { - phicoul = qtmp*q[j]*rinv; + ecoul = qtmp*q[j]*rinv; if (dipole[itype] > 0.0 && dipole[jtype] > 0.0) - phicoul += r3inv*pdotp - 3.0*r5inv*pidotr*pjdotr; + ecoul += r3inv*pdotp - 3.0*r5inv*pidotr*pjdotr; if (dipole[itype] > 0.0 && q[j] != 0.0) - phicoul += -q[j]*r3inv*pidotr; + ecoul += -q[j]*r3inv*pidotr; if (dipole[jtype] > 0.0 && qtmp != 0.0) - phicoul += qtmp*r3inv*pjdotr; - eng_coul += factor*factor_coul*qqrd2e*phicoul; - } + ecoul += qtmp*r3inv*pjdotr; + ecoul *= factor_coul*qqrd2e; + } else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) { - fx *= 0.5; fy *= 0.5; fz *= 0.5; - } - virial[0] += delx*fx; - virial[1] += dely*fy; - virial[2] += delz*fz; - virial[3] += delx*fy; - virial[4] += delx*fz; - virial[5] += dely*fz; - } + if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair, + evdwl,ecoul,fx,fy,fz,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/DPD/pair_dpd.cpp b/src/DPD/pair_dpd.cpp index 7bea9574cc..5a0dba23e1 100644 --- a/src/DPD/pair_dpd.cpp +++ b/src/DPD/pair_dpd.cpp @@ -65,19 +65,21 @@ PairDPD::~PairDPD() void PairDPD::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz,vxtmp,vytmp,vztmp,delvx,delvy,delvz; - double rsq,r,rinv,dot,wd,randnum,fforce,factor_dpd,phi; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double vxtmp,vytmp,vztmp,delvx,delvy,delvz; + double rsq,r,rinv,dot,wd,randnum,factor_dpd; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **v = atom->v; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; double dtinvsqrt = 1.0/sqrt(update->dt); @@ -131,39 +133,32 @@ void PairDPD::compute(int eflag, int vflag) // drag force = -gamma * wd^2 * (delx dot delv) / r // random force = sigma * wd * rnd * dtinvsqrt; - fforce = a0[itype][jtype]*wd; - fforce -= gamma[itype][jtype]*wd*wd*dot*rinv; - fforce += sigma[itype][jtype]*wd*randnum*dtinvsqrt; - fforce *= factor_dpd*rinv; + fpair = a0[itype][jtype]*wd; + fpair -= gamma[itype][jtype]*wd*wd*dot*rinv; + fpair += sigma[itype][jtype]*wd*randnum*dtinvsqrt; + fpair *= factor_dpd*rinv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - phi = a0[itype][jtype] * r * (1.0 - 0.5*r/cut[itype][jtype]); - if (newton_pair || j < nlocal) eng_vdwl += factor_dpd*phi; - else eng_vdwl += 0.5*factor_dpd*phi; + evdwl = a0[itype][jtype] * r * (1.0 - 0.5*r/cut[itype][jtype]); + evdwl *= factor_dpd; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/GRANULAR/pair_gran_hertzian.cpp b/src/GRANULAR/pair_gran_hertzian.cpp index 07db4dd930..06e755d574 100644 --- a/src/GRANULAR/pair_gran_hertzian.cpp +++ b/src/GRANULAR/pair_gran_hertzian.cpp @@ -40,21 +40,24 @@ PairGranHertzian::PairGranHertzian(LAMMPS *lmp) : PairGranHistory(lmp) void PairGranHertzian::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum; - double xtmp,ytmp,ztmp,delx,dely,delz; + double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz; double radi,radj,radsum,rsq,r,rinv; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3; double wr1,wr2,wr3; double vtr1,vtr2,vtr3,vrel; - double xmeff,damp,ccel,ccelx,ccely,ccelz,tor1,tor2,tor3; + double xmeff,damp,ccel,tor1,tor2,tor3; double fn,fs,fs1,fs2,fs3; double shrmag,rsht,rhertz; int *ilist,*jlist,*numneigh,**firstneigh; int *touch,**firsttouch; double *shear,*allshear,**firstshear; - double **f = atom->f; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + double **x = atom->x; double **v = atom->v; + double **f = atom->f; double **omega = atom->omega; double **torque = atom->torque; double *radius = atom->radius; @@ -209,12 +212,12 @@ void PairGranHertzian::compute(int eflag, int vflag) // forces & torques - ccelx = delx*ccel + fs1; - ccely = dely*ccel + fs2; - ccelz = delz*ccel + fs3; - f[i][0] += ccelx; - f[i][1] += ccely; - f[i][2] += ccelz; + fx = delx*ccel + fs1; + fy = dely*ccel + fs2; + fz = delz*ccel + fs3; + f[i][0] += fx; + f[i][1] += fy; + f[i][2] += fz; rinv = 1/r; tor1 = rinv * (dely*fs3 - delz*fs2); @@ -225,13 +228,16 @@ void PairGranHertzian::compute(int eflag, int vflag) torque[i][2] -= radi*tor3; if (newton_pair || j < nlocal) { - f[j][0] -= ccelx; - f[j][1] -= ccely; - f[j][2] -= ccelz; + f[j][0] -= fx; + f[j][1] -= fy; + f[j][2] -= fz; torque[j][0] -= radj*tor1; torque[j][1] -= radj*tor2; torque[j][2] -= radj*tor3; } + + if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair, + 0.0,0.0,fx,fy,fz,delx,dely,delz); } } } diff --git a/src/GRANULAR/pair_gran_history.cpp b/src/GRANULAR/pair_gran_history.cpp index 3497467f79..e769c1ac60 100644 --- a/src/GRANULAR/pair_gran_history.cpp +++ b/src/GRANULAR/pair_gran_history.cpp @@ -45,8 +45,6 @@ using namespace LAMMPS_NS; PairGranHistory::PairGranHistory(LAMMPS *lmp) : Pair(lmp) { single_enable = 0; - - for (int i = 0; i < 6; i++) virial[i] = 0.0; history = 1; fix_history = NULL; } @@ -68,21 +66,24 @@ PairGranHistory::~PairGranHistory() void PairGranHistory::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum; - double xtmp,ytmp,ztmp,delx,dely,delz; + double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz; double radi,radj,radsum,rsq,r,rinv; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3; double wr1,wr2,wr3; double vtr1,vtr2,vtr3,vrel; - double xmeff,damp,ccel,ccelx,ccely,ccelz,tor1,tor2,tor3; + double xmeff,damp,ccel,tor1,tor2,tor3; double fn,fs,fs1,fs2,fs3; double shrmag,rsht; int *ilist,*jlist,*numneigh,**firstneigh; int *touch,**firsttouch; double *shear,*allshear,**firstshear; - double **f = atom->f; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + double **x = atom->x; double **v = atom->v; + double **f = atom->f; double **omega = atom->omega; double **torque = atom->torque; double *radius = atom->radius; @@ -235,12 +236,12 @@ void PairGranHistory::compute(int eflag, int vflag) // forces & torques - ccelx = delx*ccel + fs1; - ccely = dely*ccel + fs2; - ccelz = delz*ccel + fs3; - f[i][0] += ccelx; - f[i][1] += ccely; - f[i][2] += ccelz; + fx = delx*ccel + fs1; + fy = dely*ccel + fs2; + fz = delz*ccel + fs3; + f[i][0] += fx; + f[i][1] += fy; + f[i][2] += fz; rinv = 1/r; tor1 = rinv * (dely*fs3 - delz*fs2); @@ -251,13 +252,16 @@ void PairGranHistory::compute(int eflag, int vflag) torque[i][2] -= radi*tor3; if (newton_pair || j < nlocal) { - f[j][0] -= ccelx; - f[j][1] -= ccely; - f[j][2] -= ccelz; + f[j][0] -= fx; + f[j][1] -= fy; + f[j][2] -= fz; torque[j][0] -= radj*tor1; torque[j][1] -= radj*tor2; torque[j][2] -= radj*tor3; } + + if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair, + 0.0,0.0,fx,fy,fz,delx,dely,delz); } } } diff --git a/src/GRANULAR/pair_gran_no_history.cpp b/src/GRANULAR/pair_gran_no_history.cpp index e1dd1831b5..54fb62a594 100644 --- a/src/GRANULAR/pair_gran_no_history.cpp +++ b/src/GRANULAR/pair_gran_no_history.cpp @@ -40,18 +40,21 @@ PairGranNoHistory::PairGranNoHistory(LAMMPS *lmp) : PairGranHistory(lmp) void PairGranNoHistory::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum; - double xtmp,ytmp,ztmp,delx,dely,delz; + double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz; double radi,radj,radsum,rsq,r,rinv; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3; double wr1,wr2,wr3; double vtr1,vtr2,vtr3,vrel; - double xmeff,damp,ccel,ccelx,ccely,ccelz,tor1,tor2,tor3; + double xmeff,damp,ccel,tor1,tor2,tor3; double fn,fs,ft,fs1,fs2,fs3; int *ilist,*jlist,*numneigh,**firstneigh; - double **f = atom->f; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + double **x = atom->x; double **v = atom->v; + double **f = atom->f; double **omega = atom->omega; double **torque = atom->torque; double *radius = atom->radius; @@ -154,12 +157,12 @@ void PairGranNoHistory::compute(int eflag, int vflag) // forces & torques - ccelx = delx*ccel + fs1; - ccely = dely*ccel + fs2; - ccelz = delz*ccel + fs3; - f[i][0] += ccelx; - f[i][1] += ccely; - f[i][2] += ccelz; + fx = delx*ccel + fs1; + fy = dely*ccel + fs2; + fz = delz*ccel + fs3; + f[i][0] += fx; + f[i][1] += fy; + f[i][2] += fz; rinv = 1/r; tor1 = rinv * (dely*fs3 - delz*fs2); @@ -170,14 +173,19 @@ void PairGranNoHistory::compute(int eflag, int vflag) torque[i][2] -= radi*tor3; if (newton_pair || j < nlocal) { - f[j][0] -= ccelx; - f[j][1] -= ccely; - f[j][2] -= ccelz; + f[j][0] -= fx; + f[j][1] -= fy; + f[j][2] -= fz; torque[j][0] -= radj*tor1; torque[j][1] -= radj*tor2; torque[j][2] -= radj*tor3; } + + if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair, + 0.0,0.0,fx,fy,fz,delx,dely,delz); } } } + + if (vflag_fdotr) virial_compute(); } diff --git a/src/KSPACE/pair_buck_coul_long.cpp b/src/KSPACE/pair_buck_coul_long.cpp index f7fe6aeb72..e76a853921 100644 --- a/src/KSPACE/pair_buck_coul_long.cpp +++ b/src/KSPACE/pair_buck_coul_long.cpp @@ -67,21 +67,22 @@ PairBuckCoulLong::~PairBuckCoulLong() void PairBuckCoulLong::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcecoul,forcebuck,fforce,factor_coul,factor_lj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double rsq,r2inv,r6inv,forcecoul,forcebuck,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; - double factor,phicoul,phibuck,r,rexp; + double r,rexp; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -141,45 +142,36 @@ void PairBuckCoulLong::compute(int eflag, int vflag) forcebuck = buck1[itype][jtype]*r*rexp - buck2[itype][jtype]*r6inv; } else forcebuck = 0.0; - fforce = (forcecoul + factor_lj*forcebuck) * r2inv; + fpair = (forcecoul + factor_lj*forcebuck) * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; if (rsq < cut_coulsq) { - phicoul = prefactor*erfc; - if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; - eng_coul += factor*phicoul; - } + ecoul = prefactor*erfc; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; + } else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { - phibuck = a[itype][jtype]*rexp - c[itype][jtype]*r6inv - + evdwl = a[itype][jtype]*rexp - c[itype][jtype]*r6inv - offset[itype][jtype]; - eng_vdwl += factor*factor_lj*phibuck; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/KSPACE/pair_coul_long.cpp b/src/KSPACE/pair_coul_long.cpp index 69dc38247c..f49d34ab8a 100644 --- a/src/KSPACE/pair_coul_long.cpp +++ b/src/KSPACE/pair_coul_long.cpp @@ -68,22 +68,23 @@ PairCoulLong::~PairCoulLong() void PairCoulLong::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itable; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fraction,table; - double r,r2inv,forcecoul,fforce,factor_coul; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double fraction,table; + double r,r2inv,forcecoul,factor_coul; double grij,expm2,prefactor,t,erfc; - double phicoul; int *ilist,*jlist,*numneigh,**firstneigh; float rsq; int *int_rsq = (int *) &rsq; - eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; @@ -142,43 +143,36 @@ void PairCoulLong::compute(int eflag, int vflag) } } - fforce = forcecoul * r2inv; + fpair = forcecoul * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { if (!ncoultablebits || rsq <= tabinnersq) - phicoul = prefactor*erfc; + ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; - phicoul = qtmp*q[j] * table; + ecoul = qtmp*q[j] * table; } - if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; - if (newton_pair || j < nlocal) eng_coul += phicoul; - else eng_coul += 0.5*phicoul; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + 0.0,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } + /* ---------------------------------------------------------------------- allocate all arrays ------------------------------------------------------------------------- */ diff --git a/src/KSPACE/pair_lj_charmm_coul_long.cpp b/src/KSPACE/pair_lj_charmm_coul_long.cpp index d7429cd209..f874fc93d4 100644 --- a/src/KSPACE/pair_lj_charmm_coul_long.cpp +++ b/src/KSPACE/pair_lj_charmm_coul_long.cpp @@ -84,23 +84,25 @@ PairLJCharmmCoulLong::~PairLJCharmmCoulLong() void PairLJCharmmCoulLong::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fraction,table; - double r,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double fraction,table; + double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; - double factor,phicoul,philj,switch1,switch2; + double philj,switch1,switch2; int *ilist,*jlist,*numneigh,**firstneigh; float rsq; int *int_rsq = (int *) &rsq; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -179,54 +181,46 @@ void PairLJCharmmCoulLong::compute(int eflag, int vflag) } } else forcelj = 0.0; - fforce = (forcecoul + factor_lj*forcelj) * r2inv; + fpair = (forcecoul + factor_lj*forcelj) * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) - phicoul = prefactor*erfc; + ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; - phicoul = qtmp*q[j] * table; + ecoul = qtmp*q[j] * table; } - if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; - eng_coul += factor*phicoul; - } + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; + } else ecoul = 0.0; + if (rsq < cut_ljsq) { - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; - philj *= switch1; + evdwl *= switch1; } - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- */ @@ -234,8 +228,8 @@ void PairLJCharmmCoulLong::compute(int eflag, int vflag) void PairLJCharmmCoulLong::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; + double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; @@ -244,7 +238,7 @@ void PairLJCharmmCoulLong::compute_inner() double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -298,20 +292,20 @@ void PairLJCharmmCoulLong::compute_inner() jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); - fforce = (forcecoul + factor_lj*forcelj) * r2inv; + fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; - fforce *= 1.0 + rsw*rsw*(2.0*rsw-3.0); + fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } } } @@ -323,8 +317,8 @@ void PairLJCharmmCoulLong::compute_inner() void PairLJCharmmCoulLong::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; + double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double philj,switch1,switch2; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; @@ -334,7 +328,7 @@ void PairLJCharmmCoulLong::compute_middle() double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -402,23 +396,23 @@ void PairLJCharmmCoulLong::compute_middle() forcelj = forcelj*switch1 + philj*switch2; } - fforce = (forcecoul + factor_lj*forcelj) * r2inv; + fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; - fforce *= rsw*rsw*(3.0 - 2.0*rsw); + fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; - fforce *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); + fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } } } @@ -430,24 +424,26 @@ void PairLJCharmmCoulLong::compute_middle() void PairLJCharmmCoulLong::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fraction,table; - double r,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double fraction,table; + double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; - double factor,phicoul,philj,switch1,switch2; + double philj,switch1,switch2; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; float rsq; int *int_rsq = (int *) &rsq; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -548,46 +544,44 @@ void PairLJCharmmCoulLong::compute_outer(int eflag, int vflag) forcelj *= rsw*rsw*(3.0 - 2.0*rsw); } } else forcelj = 0.0; + + fpair = (forcecoul + forcelj) * r2inv; - fforce = (forcecoul + forcelj) * r2inv; - - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { - phicoul = prefactor*erfc; - if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; + ecoul = prefactor*erfc; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else { table = etable[itable] + fraction*detable[itable]; - phicoul = qtmp*q[j] * table; + ecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; - phicoul -= (1.0-factor_coul)*prefactor; + ecoul -= (1.0-factor_coul)*prefactor; } } - eng_coul += factor*phicoul; - } + } else ecoul = 0.0; + if (rsq < cut_ljsq) { r6inv = r2inv*r2inv*r2inv; - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; - philj *= switch1; + evdwl *= switch1; } - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } if (vflag) { @@ -629,16 +623,11 @@ void PairLJCharmmCoulLong::compute_outer(int eflag, int vflag) } } - fforce = (forcecoul + factor_lj*forcelj) * r2inv; - - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; + fpair = (forcecoul + factor_lj*forcelj) * r2inv; } + + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } diff --git a/src/KSPACE/pair_lj_cut_coul_long.cpp b/src/KSPACE/pair_lj_cut_coul_long.cpp index 67413b11a4..1ea3127c4c 100644 --- a/src/KSPACE/pair_lj_cut_coul_long.cpp +++ b/src/KSPACE/pair_lj_cut_coul_long.cpp @@ -80,23 +80,24 @@ PairLJCutCoulLong::~PairLJCutCoulLong() void PairLJCutCoulLong::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fraction,table; - double r,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double fraction,table; + double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; - double factor,phicoul,philj; int *ilist,*jlist,*numneigh,**firstneigh; float rsq; int *int_rsq = (int *) &rsq; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -167,50 +168,42 @@ void PairLJCutCoulLong::compute(int eflag, int vflag) forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; - fforce = (forcecoul + factor_lj*forcelj) * r2inv; + fpair = (forcecoul + factor_lj*forcelj) * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) - phicoul = prefactor*erfc; + ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; - phicoul = qtmp*q[j] * table; + ecoul = qtmp*q[j] * table; } - if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; - eng_coul += factor*phicoul; - } + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; + } else ecoul = 0.0; + if (rsq < cut_ljsq[itype][jtype]) { - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- */ @@ -218,8 +211,8 @@ void PairLJCutCoulLong::compute(int eflag, int vflag) void PairLJCutCoulLong::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; + double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; @@ -228,7 +221,7 @@ void PairLJCutCoulLong::compute_inner() double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -284,19 +277,19 @@ void PairLJCutCoulLong::compute_inner() forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; - fforce = (forcecoul + factor_lj*forcelj) * r2inv; + fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; - fforce *= 1.0 + rsw*rsw*(2.0*rsw-3.0); + fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } } } @@ -308,8 +301,8 @@ void PairLJCutCoulLong::compute_inner() void PairLJCutCoulLong::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair; + double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; @@ -318,7 +311,7 @@ void PairLJCutCoulLong::compute_middle() double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -379,23 +372,23 @@ void PairLJCutCoulLong::compute_middle() forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; - fforce = (forcecoul + factor_lj*forcelj) * r2inv; + fpair = (forcecoul + factor_lj*forcelj) * r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; - fforce *= rsw*rsw*(3.0 - 2.0*rsw); + fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; - fforce *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); + fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } } } @@ -407,24 +400,25 @@ void PairLJCutCoulLong::compute_middle() void PairLJCutCoulLong::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fraction,table; - double r,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double fraction,table; + double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; - double factor,phicoul,philj; double rsw; int *ilist,*jlist,*numneigh,**firstneigh; float rsq; int *int_rsq = (int *) &rsq; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -517,41 +511,39 @@ void PairLJCutCoulLong::compute_outer(int eflag, int vflag) } } else forcelj = 0.0; - fforce = (forcecoul + forcelj) * r2inv; + fpair = (forcecoul + forcelj) * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) { - phicoul = prefactor*erfc; - if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; + ecoul = prefactor*erfc; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } else { table = etable[itable] + fraction*detable[itable]; - phicoul = qtmp*q[j] * table; + ecoul = qtmp*q[j] * table; if (factor_coul < 1.0) { table = ptable[itable] + fraction*dptable[itable]; prefactor = qtmp*q[j] * table; - phicoul -= (1.0-factor_coul)*prefactor; + ecoul -= (1.0-factor_coul)*prefactor; } } - eng_coul += factor*phicoul; - } + } else ecoul = 0.0; + if (rsq < cut_ljsq[itype][jtype]) { r6inv = r2inv*r2inv*r2inv; - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } if (vflag) { @@ -576,16 +568,11 @@ void PairLJCutCoulLong::compute_outer(int eflag, int vflag) } else if (rsq <= cut_in_on_sq) forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); - fforce = (forcecoul + factor_lj*forcelj) * r2inv; - - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; + fpair = (forcecoul + factor_lj*forcelj) * r2inv; } + + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } diff --git a/src/KSPACE/pair_lj_cut_coul_long_tip4p.cpp b/src/KSPACE/pair_lj_cut_coul_long_tip4p.cpp index aa01e1c118..b9c853e9f7 100644 --- a/src/KSPACE/pair_lj_cut_coul_long_tip4p.cpp +++ b/src/KSPACE/pair_lj_cut_coul_long_tip4p.cpp @@ -71,7 +71,8 @@ PairLJCutCoulLongTIP4P::~PairLJCutCoulLongTIP4P() void PairLJCutCoulLongTIP4P::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fraction,table; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double fraction,table; double delx1,dely1,delz1,delx2,dely2,delz2,delx3,dely3,delz3; double r,r2inv,r6inv,forcecoul,forcelj,cforce,negforce; double factor_coul,factor_lj; @@ -85,35 +86,43 @@ void PairLJCutCoulLongTIP4P::compute(int eflag, int vflag) float rsq; int *int_rsq = (int *) &rsq; - // grow temporary force array if necessary + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; - if (atom->nmax > nmax) { - memory->destroy_2d_double_array(ftmp); - nmax = atom->nmax; - ftmp = memory->create_2d_double_array(nmax,3,"pair:ftmp"); - } + // error check (for now) - int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; - - eng_vdwl = eng_coul = 0.0; - if (vflag) { - for (i = 0; i < 6; i++) virial[i] = virialtmp[i] = 0.0; - for (i = 0; i < nall; ++i) { - ftmp[i][0] = 0.0; - ftmp[i][1] = 0.0; - ftmp[i][2] = 0.0; - } - } + if (eflag_atom || vflag_atom) + error->all("Pair style lj/cut/coul/long/tip4p does not yet support peratom energy/virial"); double **f = atom->f; double **x = atom->x; double *q = atom->q; int *type = atom->type; + int nlocal = atom->nlocal; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; + int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; + // grow and zero temporary force array if necessary + + if (vflag && atom->nmax > nmax) { + memory->destroy_2d_double_array(ftmp); + nmax = atom->nmax; + ftmp = memory->create_2d_double_array(nmax,3,"pair:ftmp"); + } + + if (vflag) { + for (i = 0; i < 6; i++) virialtmp[i] = 0.0; + for (i = 0; i < nall; i++) { + ftmp[i][0] = 0.0; + ftmp[i][1] = 0.0; + ftmp[i][2] = 0.0; + } + } + inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; @@ -168,11 +177,11 @@ void PairLJCutCoulLongTIP4P::compute(int eflag, int vflag) f[j][2] -= delz*forcelj; if (eflag) { - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; - eng_vdwl += factor_lj*philj; + evdwl *= factor_lj*philj; } - } + } else evdwl = 0.0; // adjust rsq for off-site O charge(s) @@ -380,23 +389,25 @@ void PairLJCutCoulLongTIP4P::compute(int eflag, int vflag) virialtmp[5] += 0.5 * (delz1 * fO[1] + (delz2 + delz3) * fH[1]); } } - + if (eflag) { if (!ncoultablebits || rsq <= tabinnersq) - phicoul = prefactor*erfc; + ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; - phicoul = qtmp*q[j] * table; + ecoul = qtmp*q[j] * table; } - if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; - eng_coul += phicoul; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } - } + } else ecoul = 0.0; + + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) { + if (vflag_fdotr) { virial_compute(); for (int i = 0; i < 6; i++) virial[i] += virialtmp[i]; for (int i = 0; i < nall; i++) { @@ -622,6 +633,8 @@ void *PairLJCutCoulLongTIP4P::extract(char *str) double PairLJCutCoulLongTIP4P::memory_usage() { - double bytes = 3 * nmax * sizeof(double); + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); + bytes += 3 * nmax * sizeof(double); return bytes; } diff --git a/src/MANYBODY/pair_airebo.cpp b/src/MANYBODY/pair_airebo.cpp index c4a7f903af..e70ffbc234 100644 --- a/src/MANYBODY/pair_airebo.cpp +++ b/src/MANYBODY/pair_airebo.cpp @@ -87,17 +87,20 @@ PairAIREBO::~PairAIREBO() void PairAIREBO::compute(int eflag, int vflag) { - eng_vdwl = 0.0; - if (vflag) for (int i = 0; i < 6; i++) virial[i] = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + // error check (for now) + + if (eflag_atom || vflag_atom) + error->all("Pair style airebo does not yet support peratom energy/virial"); - double **f = atom->f; - REBO_neigh(); - FREBO(eflag,f); - if (ljflag) FLJ(eflag,f); - if (torflag) TORSION(eflag,f); + FREBO(eflag,vflag); + if (ljflag) FLJ(eflag,vflag); + if (torflag) TORSION(eflag,vflag); - if (vflag == 2) virial_compute(); + if (vflag_fdotr == 2) virial_compute(); } /* ---------------------------------------------------------------------- @@ -448,24 +451,30 @@ void PairAIREBO::REBO_neigh() REBO forces and energy ------------------------------------------------------------------------- */ -void PairAIREBO::FREBO(int eflag, double **f) +void PairAIREBO::FREBO(int eflag, int vflag) { int i,j,k,m,itype,jtype; - double delx,dely,delz,rsq,rij,wij; + double delx,dely,delz,evdwl,fpair; + double rsq,rij,wij; double Qij,Aij,alphaij,VR,pre,dVRdi,VA,term,bij,dVAdi,dVA; - double dwij,fforce,del[3]; + double dwij,del[3]; int *REBO_neighs; + evdwl = 0.0; + double **x = atom->x; + double **f = atom->f; int *type = atom->type; int *tag = atom->tag; int nlocal = atom->nlocal; + int newton_pair = force->newton_pair; // two-body interactions from REBO neighbor list, skip half of them for (i = 0; i < nlocal; i++) { itype = map[type[i]]; REBO_neighs = REBO_firstneigh[i]; + for (k = 0; k < REBO_numneigh[i]; k++) { j = REBO_neighs[k]; if (tag[i] > tag[j]) continue; @@ -501,14 +510,17 @@ void PairAIREBO::FREBO(int eflag, double **f) bij = bondorder(i,j,del,rij,VA,f); dVAdi = bij*dVA; - fforce = (dVRdi+dVAdi) / rij; - f[i][0] -= delx*fforce; - f[i][1] -= dely*fforce; - f[i][2] -= delz*fforce; - f[j][0] += delx*fforce; - f[j][1] += dely*fforce; - f[j][2] += delz*fforce; - if (eflag) eng_vdwl += VR + bij*VA; + fpair = -(dVRdi+dVAdi) / rij; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; + + if (eflag) evdwl = VR + bij*VA; + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } @@ -518,29 +530,35 @@ void PairAIREBO::FREBO(int eflag, double **f) find 3- and 4-step paths between atoms I,J via REBO neighbor lists ------------------------------------------------------------------------- */ -void PairAIREBO::FLJ(int eflag, double **f) +void PairAIREBO::FLJ(int eflag, int vflag) { int i,j,k,m,ii,jj,kk,mm,inum,jnum,itype,jtype,ktype,mtype; int atomi,atomj,atomk,atomm; int testpath,npath,done; + double evdwl,fpair; double rsq,best,wik,wkm,cij,rij,dwij,dwik,dwkj,dwkm,dwmj; double delij[3],rijsq,delik[3],rik,delkj[3]; - double rkj,wkj,dC,VLJ,dVLJ,fforce,VA,Str,dStr,Stb; + double rkj,wkj,dC,VLJ,dVLJ,VA,Str,dStr,Stb; double delkm[3],rkm,delmj[3],rmj,wmj,r2inv,r6inv,scale,delscale[3]; int *ilist,*jlist,*numneigh,**firstneigh; int *REBO_neighs_i,*REBO_neighs_k; double delikS[3],delkjS[3],delkmS[3],delmjS[3]; double rikS,rkjS,rkmS,rmjS,wikS,dwikS; double wkjS,dwkjS,wkmS,dwkmS,wmjS,dwmjS; + double fpair1,fpair2,fpair3; // I-J interaction from full neighbor list // skip 1/2 of interactions since only consider each pair once + evdwl = 0.0; + double **x = atom->x; + double **f = atom->f; int *tag = atom->tag; int *type = atom->type; int nlocal = atom->nlocal; - + int newton_pair = force->newton_pair; + inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; @@ -723,65 +741,75 @@ void PairAIREBO::FLJ(int eflag, double **f) delscale[2] = scale * delij[2]; Stb = bondorderLJ(i,j,delscale,rcmin[itype][jtype],VA,delij,rij,f); } else Stb = 0.0; - VA = VA*Stb + (1.0-Str)*cij*VLJ; - fforce = (dStr * (Stb*cij*VLJ - cij*VLJ) + + + fpair = -(dStr * (Stb*cij*VLJ - cij*VLJ) + dVLJ * (Str*Stb*cij + cij - Str*cij)) / rij; - f[i][0] -= delij[0]*fforce; - f[i][1] -= delij[1]*fforce; - f[i][2] -= delij[2]*fforce; - f[j][0] += delij[0]*fforce; - f[j][1] += delij[1]*fforce; - f[j][2] += delij[2]*fforce; + f[i][0] += delij[0]*fpair; + f[i][1] += delij[1]*fpair; + f[i][2] += delij[2]*fpair; + f[j][0] -= delij[0]*fpair; + f[j][1] -= delij[1]*fpair; + f[j][2] -= delij[2]*fpair; - if (eflag) eng_vdwl += VA; + if (eflag) evdwl = VA*Stb + (1.0-Str)*cij*VLJ; + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delij[0],delij[1],delij[2]); + if (cij < 1.0) { - dC = -1.0*((Str*Stb*VLJ) + ((1.0-Str)*VLJ)); + dC = Str*Stb*VLJ + (1.0-Str)*VLJ; if (npath == 2) { - fforce = dC*dwij / rij; - f[atomi][0] -= delij[0]*fforce; - f[atomi][1] -= delij[1]*fforce; - f[atomi][2] -= delij[2]*fforce; - f[atomj][0] += delij[0]*fforce; - f[atomj][1] += delij[1]*fforce; - f[atomj][2] += delij[2]*fforce; + fpair = dC*dwij / rij; + f[atomi][0] += delij[0]*fpair; + f[atomi][1] += delij[1]*fpair; + f[atomi][2] += delij[2]*fpair; + f[atomj][0] -= delij[0]*fpair; + f[atomj][1] -= delij[1]*fpair; + f[atomj][2] -= delij[2]*fpair; + if (vflag_atom) ev_tally(atomi,atomj,nlocal,newton_pair, + 0.0,0.0,fpair,delij[0],delij[1],delij[2]); } else if (npath == 3) { - fforce = dC*dwikS*wkjS / rikS; - f[atomi][0] -= delikS[0]*fforce; - f[atomi][1] -= delikS[1]*fforce; - f[atomi][2] -= delikS[2]*fforce; - f[atomk][0] += delikS[0]*fforce; - f[atomk][1] += delikS[1]*fforce; - f[atomk][2] += delikS[2]*fforce; - fforce = dC*wikS*dwkjS / rkjS; - f[atomk][0] -= delkjS[0]*fforce; - f[atomk][1] -= delkjS[1]*fforce; - f[atomk][2] -= delkjS[2]*fforce; - f[atomj][0] += delkjS[0]*fforce; - f[atomj][1] += delkjS[1]*fforce; - f[atomj][2] += delkjS[2]*fforce; + fpair1 = dC*dwikS*wkjS / rikS; + f[atomi][0] += delikS[0]*fpair1; + f[atomi][1] += delikS[1]*fpair1; + f[atomi][2] += delikS[2]*fpair1; + f[atomk][0] -= delikS[0]*fpair1; + f[atomk][1] -= delikS[1]*fpair1; + f[atomk][2] -= delikS[2]*fpair1; + fpair2 = dC*wikS*dwkjS / rkjS; + f[atomk][0] += delkjS[0]*fpair2; + f[atomk][1] += delkjS[1]*fpair2; + f[atomk][2] += delkjS[2]*fpair2; + f[atomj][0] -= delkjS[0]*fpair2; + f[atomj][1] -= delkjS[1]*fpair2; + f[atomj][2] -= delkjS[2]*fpair2; + if (vflag_atom) + v_tally3(atomi,atomj,atomk,fpair1,fpair2,delikS,delkjS); } else { - fforce = dC*dwikS*wkmS*wmjS / rikS; - f[atomi][0] -= delikS[0]*fforce; - f[atomi][1] -= delikS[1]*fforce; - f[atomi][2] -= delikS[2]*fforce; - f[atomk][0] += delikS[0]*fforce; - f[atomk][1] += delikS[1]*fforce; - f[atomk][2] += delikS[2]*fforce; - fforce = dC*wikS*dwkmS*wmjS / rkmS; - f[atomk][0] -= delkmS[0]*fforce; - f[atomk][1] -= delkmS[1]*fforce; - f[atomk][2] -= delkmS[2]*fforce; - f[atomm][0] += delkmS[0]*fforce; - f[atomm][1] += delkmS[1]*fforce; - f[atomm][2] += delkmS[2]*fforce; - fforce = dC*wikS*wkmS*dwmjS / rmjS; - f[atomm][0] -= delmjS[0]*fforce; - f[atomm][1] -= delmjS[1]*fforce; - f[atomm][2] -= delmjS[2]*fforce; - f[atomj][0] += delmjS[0]*fforce; - f[atomj][1] += delmjS[1]*fforce; - f[atomj][2] += delmjS[2]*fforce; + fpair1 = dC*dwikS*wkmS*wmjS / rikS; + f[atomi][0] += delikS[0]*fpair1; + f[atomi][1] += delikS[1]*fpair1; + f[atomi][2] += delikS[2]*fpair1; + f[atomk][0] -= delikS[0]*fpair1; + f[atomk][1] -= delikS[1]*fpair1; + f[atomk][2] -= delikS[2]*fpair1; + fpair2 = dC*wikS*dwkmS*wmjS / rkmS; + f[atomk][0] += delkmS[0]*fpair2; + f[atomk][1] += delkmS[1]*fpair2; + f[atomk][2] += delkmS[2]*fpair2; + f[atomm][0] -= delkmS[0]*fpair2; + f[atomm][1] -= delkmS[1]*fpair2; + f[atomm][2] -= delkmS[2]*fpair2; + fpair3 = dC*wikS*wkmS*dwmjS / rmjS; + f[atomm][0] += delmjS[0]*fpair3; + f[atomm][1] += delmjS[1]*fpair3; + f[atomm][2] += delmjS[2]*fpair3; + f[atomj][0] -= delmjS[0]*fpair3; + f[atomj][1] -= delmjS[1]*fpair3; + f[atomj][2] -= delmjS[2]*fpair3; + if (vflag_atom) + v_tally4(atomi,atomj,atomk,atomm, + fpair1,fpair2,fpair3,delikS,delkmS,delmjS); } } } @@ -792,10 +820,10 @@ void PairAIREBO::FLJ(int eflag, double **f) Torsional forces and energy ------------------------------------------------------------------------- */ -void PairAIREBO::TORSION(int eflag, double **f) +void PairAIREBO::TORSION(int eflag, int vflag) { int i,j,k,l; - + double evdwl,fpair; double cos321; double w21,dw21,cos234,w34,dw34; double cross321[3],cross321mag,cross234[3],cross234mag; @@ -811,11 +839,15 @@ void PairAIREBO::TORSION(int eflag, double **f) double dxidij,dxidik,dxidjk,dxjdji,dxjdjl,dxjdil; double ddndij,ddndik,ddndjk,ddndjl,ddndil,dcwddn,dcwdn,dvpdcw,Ftmp[3]; double del32[3],rsq,r32,del23[3],del21[3],r21; - double deljk[3],del34[3],delil[3],fforce,r23,r34; + double deljk[3],del34[3],delil[3],r23,r34; + double fi[3],fj[3],fk[3],fl[3]; int itype,jtype,ktype,ltype,kk,ll,jj; int *REBO_neighs_i,*REBO_neighs_j; + evdwl = 0.0; + double **x = atom->x; + double **f = atom->f; int *type = atom->type; int *tag = atom->tag; int nlocal = atom->nlocal; @@ -923,7 +955,8 @@ void PairAIREBO::TORSION(int eflag, double **f) ekijl = epsilonT[ktype][ltype]; Ec = 256.0*ekijl/405.0; Vtors = (Ec*(pow(cw2,5.0)))-(ekijl/10.0); - if (eflag) eng_vdwl += Vtors*w21*w23*w34*(1.0-tspjik)*(1.0-tspijl); + + if (eflag) evdwl = Vtors*w21*w23*w34*(1.0-tspjik)*(1.0-tspijl); dndij[0] = (cross234[1]*del21[2])-(cross234[2]*del21[1]); dndij[1] = (cross234[2]*del21[0])-(cross234[0]*del21[2]); @@ -977,134 +1010,143 @@ void PairAIREBO::TORSION(int eflag, double **f) dcwdn = 1.0/cwnom; dvpdcw = (-1.0)*Ec*(-.5)*5.0*pow(cw2,4.0) * w23*w21*w34*(1.0-tspjik)*(1.0-tspijl); - + Ftmp[0] = dvpdcw*((dcwdn*dndij[0])+(dcwddn*ddndij*del23[0]/r23)); Ftmp[1] = dvpdcw*((dcwdn*dndij[1])+(dcwddn*ddndij*del23[1]/r23)); Ftmp[2] = dvpdcw*((dcwdn*dndij[2])+(dcwddn*ddndij*del23[2]/r23)); - f[i][0] += Ftmp[0]; - f[i][1] += Ftmp[1]; - f[i][2] += Ftmp[2]; - f[j][0] -= Ftmp[0]; - f[j][1] -= Ftmp[1]; - f[j][2] -= Ftmp[2]; + fi[0] = Ftmp[0]; + fi[1] = Ftmp[1]; + fi[2] = Ftmp[2]; + fj[0] = -Ftmp[0]; + fj[1] = -Ftmp[1]; + fj[2] = -Ftmp[2]; Ftmp[0] = dvpdcw*((dcwdn*dndik[0])+(dcwddn*ddndik*del21[0]/r21)); Ftmp[1] = dvpdcw*((dcwdn*dndik[1])+(dcwddn*ddndik*del21[1]/r21)); Ftmp[2] = dvpdcw*((dcwdn*dndik[2])+(dcwddn*ddndik*del21[2]/r21)); - f[i][0] += Ftmp[0]; - f[i][1] += Ftmp[1]; - f[i][2] += Ftmp[2]; - f[k][0] -= Ftmp[0]; - f[k][1] -= Ftmp[1]; - f[k][2] -= Ftmp[2]; + fi[0] += Ftmp[0]; + fi[1] += Ftmp[1]; + fi[2] += Ftmp[2]; + fk[0] = -Ftmp[0]; + fk[1] = -Ftmp[1]; + fk[2] = -Ftmp[2]; Ftmp[0] = (dvpdcw*dcwddn*ddndjk*deljk[0])/rjk; Ftmp[1] = (dvpdcw*dcwddn*ddndjk*deljk[1])/rjk; Ftmp[2] = (dvpdcw*dcwddn*ddndjk*deljk[2])/rjk; - f[j][0] += Ftmp[0]; - f[j][1] += Ftmp[1]; - f[j][2] += Ftmp[2]; - f[k][0] -= Ftmp[0]; - f[k][1] -= Ftmp[1]; - f[k][2] -= Ftmp[2]; + fj[0] += Ftmp[0]; + fj[1] += Ftmp[1]; + fj[2] += Ftmp[2]; + fk[0] -= Ftmp[0]; + fk[1] -= Ftmp[1]; + fk[2] -= Ftmp[2]; Ftmp[0] = dvpdcw*((dcwdn*dndjl[0])+(dcwddn*ddndjl*del34[0]/r34)); Ftmp[1] = dvpdcw*((dcwdn*dndjl[1])+(dcwddn*ddndjl*del34[1]/r34)); Ftmp[2] = dvpdcw*((dcwdn*dndjl[2])+(dcwddn*ddndjl*del34[2]/r34)); - f[j][0] += Ftmp[0]; - f[j][1] += Ftmp[1]; - f[j][2] += Ftmp[2]; - f[l][0] -= Ftmp[0]; - f[l][1] -= Ftmp[1]; - f[l][2] -= Ftmp[2]; + fj[0] += Ftmp[0]; + fj[1] += Ftmp[1]; + fj[2] += Ftmp[2]; + fl[0] = -Ftmp[0]; + fl[1] = -Ftmp[1]; + fl[2] = -Ftmp[2]; Ftmp[0] = (dvpdcw*dcwddn*ddndil*delil[0])/ril; Ftmp[1] = (dvpdcw*dcwddn*ddndil*delil[1])/ril; Ftmp[2] = (dvpdcw*dcwddn*ddndil*delil[2])/ril; - f[i][0] += Ftmp[0]; - f[i][1] += Ftmp[1]; - f[i][2] += Ftmp[2]; - f[l][0] -= Ftmp[0]; - f[l][1] -= Ftmp[1]; - f[l][2] -= Ftmp[2]; + fi[0] += Ftmp[0]; + fi[1] += Ftmp[1]; + fi[2] += Ftmp[2]; + fl[0] -= Ftmp[0]; + fl[1] -= Ftmp[1]; + fl[2] -= Ftmp[2]; // coordination forces - fforce = Vtors*dw21*w23*w34*(1.0-tspjik)*(1.0-tspijl) / r21; - f[i][0] -= del21[0]*fforce; - f[i][1] -= del21[1]*fforce; - f[i][2] -= del21[2]*fforce; - f[k][0] += del21[0]*fforce; - f[k][1] += del21[1]*fforce; - f[k][2] += del21[2]*fforce; + fpair = Vtors*dw21*w23*w34*(1.0-tspjik)*(1.0-tspijl) / r21; + fi[0] -= del21[0]*fpair; + fi[1] -= del21[1]*fpair; + fi[2] -= del21[2]*fpair; + fk[0] += del21[0]*fpair; + fk[1] += del21[1]*fpair; + fk[2] += del21[2]*fpair; - fforce = Vtors*w21*dw23*w34*(1.0-tspjik)*(1.0-tspijl) / r23; - f[i][0] -= del23[0]*fforce; - f[i][1] -= del23[1]*fforce; - f[i][2] -= del23[2]*fforce; - f[j][0] += del23[0]*fforce; - f[j][1] += del23[1]*fforce; - f[j][2] += del23[2]*fforce; + fpair = Vtors*w21*dw23*w34*(1.0-tspjik)*(1.0-tspijl) / r23; + fi[0] -= del23[0]*fpair; + fi[1] -= del23[1]*fpair; + fi[2] -= del23[2]*fpair; + fj[0] += del23[0]*fpair; + fj[1] += del23[1]*fpair; + fj[2] += del23[2]*fpair; - fforce = Vtors*w21*w23*dw34*(1.0-tspjik)*(1.0-tspijl) / r34; - f[j][0] -= del34[0]*fforce; - f[j][1] -= del34[1]*fforce; - f[j][2] -= del34[2]*fforce; - f[l][0] += del34[0]*fforce; - f[l][1] += del34[1]*fforce; - f[l][2] += del34[2]*fforce; + fpair = Vtors*w21*w23*dw34*(1.0-tspjik)*(1.0-tspijl) / r34; + fj[0] -= del34[0]*fpair; + fj[1] -= del34[1]*fpair; + fj[2] -= del34[2]*fpair; + fl[0] += del34[0]*fpair; + fl[1] += del34[1]*fpair; + fl[2] += del34[2]*fpair; // additional cut off function forces fcpc = -Vtors*w21*w23*w34*dtsjik*(1.0-tspijl); - fforce = fcpc*dcidij/rij; - f[i][0] += fforce*del23[0]; - f[i][1] += fforce*del23[1]; - f[i][2] += fforce*del23[2]; - f[j][0] -= fforce*del23[0]; - f[j][1] -= fforce*del23[1]; - f[j][2] -= fforce*del23[2]; + fpair = fcpc*dcidij/rij; + fi[0] += fpair*del23[0]; + fi[1] += fpair*del23[1]; + fi[2] += fpair*del23[2]; + fj[0] -= fpair*del23[0]; + fj[1] -= fpair*del23[1]; + fj[2] -= fpair*del23[2]; - fforce = fcpc*dcidik/rik; - f[i][0] += fforce*del21[0]; - f[i][1] += fforce*del21[1]; - f[i][2] += fforce*del21[2]; - f[k][0] -= fforce*del21[0]; - f[k][1] -= fforce*del21[1]; - f[k][2] -= fforce*del21[2]; + fpair = fcpc*dcidik/rik; + fi[0] += fpair*del21[0]; + fi[1] += fpair*del21[1]; + fi[2] += fpair*del21[2]; + fk[0] -= fpair*del21[0]; + fk[1] -= fpair*del21[1]; + fk[2] -= fpair*del21[2]; - fforce = fcpc*dcidjk/rjk; - f[j][0] += fforce*deljk[0]; - f[j][1] += fforce*deljk[1]; - f[j][2] += fforce*deljk[2]; - f[k][0] -= fforce*deljk[0]; - f[k][1] -= fforce*deljk[1]; - f[k][2] -= fforce*deljk[2]; + fpair = fcpc*dcidjk/rjk; + fj[0] += fpair*deljk[0]; + fj[1] += fpair*deljk[1]; + fj[2] += fpair*deljk[2]; + fk[0] -= fpair*deljk[0]; + fk[1] -= fpair*deljk[1]; + fk[2] -= fpair*deljk[2]; fcpc = -Vtors*w21*w23*w34*(1.0-tspjik)*dtsijl; - fforce = fcpc*dcjdji/rij; - f[i][0] += fforce*del23[0]; - f[i][1] += fforce*del23[1]; - f[i][2] += fforce*del23[2]; - f[j][0] -= fforce*del23[0]; - f[j][1] -= fforce*del23[1]; - f[j][2] -= fforce*del23[2]; + fpair = fcpc*dcjdji/rij; + fi[0] += fpair*del23[0]; + fi[1] += fpair*del23[1]; + fi[2] += fpair*del23[2]; + fj[0] -= fpair*del23[0]; + fj[1] -= fpair*del23[1]; + fj[2] -= fpair*del23[2]; - fforce = fcpc*dcjdjl/rjl; - f[j][0] += fforce*del34[0]; - f[j][1] += fforce*del34[1]; - f[j][2] += fforce*del34[2]; - f[l][0] -= fforce*del34[0]; - f[l][1] -= fforce*del34[1]; - f[l][2] -= fforce*del34[2]; + fpair = fcpc*dcjdjl/rjl; + fj[0] += fpair*del34[0]; + fj[1] += fpair*del34[1]; + fj[2] += fpair*del34[2]; + fl[0] -= fpair*del34[0]; + fl[1] -= fpair*del34[1]; + fl[2] -= fpair*del34[2]; - fforce = fcpc*dcjdil/ril; - f[i][0] += fforce*delil[0]; - f[i][1] += fforce*delil[1]; - f[i][2] += fforce*delil[2]; - f[l][0] -= fforce*delil[0]; - f[l][1] -= fforce*delil[1]; - f[l][2] -= fforce*delil[2]; + fpair = fcpc*dcjdil/ril; + fi[0] += fpair*delil[0]; + fi[1] += fpair*delil[1]; + fi[2] += fpair*delil[2]; + fl[0] -= fpair*delil[0]; + fl[1] -= fpair*delil[1]; + fl[2] -= fpair*delil[2]; + + // sum per-atom forces into atom force array + + f[i][0] += fi[0]; f[i][1] += fi[1]; f[i][2] += fi[2]; + f[j][0] += fj[0]; f[j][1] += fj[1]; f[j][2] += fj[2]; + f[k][0] += fk[0]; f[k][1] += fk[1]; f[k][2] += fk[2]; + f[l][0] += fl[0]; f[l][1] += fl[1]; f[l][2] += fl[2]; + + //if (evflag) ev_tally4(i,j,k,l,fi,fj,fk,fl); } } } @@ -2030,8 +2072,8 @@ double PairAIREBO::bondorderLJ(int i, int j, double rij[3], double rijmag, tmp3pij = tmp3; tmp = 0.0; tmp2 = 0.0; - tmp3 = 0.0; - Etmp=0.0; + tmp3 = 0.0; + Etmp = 0.0; REBO_neighs = REBO_firstneigh[j]; for (l = 0; l < REBO_numneigh[j]; l++) { @@ -3979,4 +4021,3 @@ void PairAIREBO::spline_init() Tf[2][2][1] = -0.035140; for (i = 2; i < 10; i++) Tf[2][2][i] = -0.0040480; } - diff --git a/src/MANYBODY/pair_airebo.h b/src/MANYBODY/pair_airebo.h index c3a7accc48..c8e2774443 100644 --- a/src/MANYBODY/pair_airebo.h +++ b/src/MANYBODY/pair_airebo.h @@ -82,9 +82,9 @@ class PairAIREBO : public Pair { double Tf[5][5][10],Tdfdx[5][5][10],Tdfdy[5][5][10],Tdfdz[5][5][10]; void REBO_neigh(); - void FREBO(int, double **); - void FLJ(int, double **); - void TORSION(int, double **); + void FREBO(int, int); + void FLJ(int, int); + void TORSION(int, int); double bondorder(int, int, double *, double, double, double **); double bondorderLJ(int, int, double *, double, double, @@ -114,4 +114,3 @@ class PairAIREBO : public Pair { } #endif - diff --git a/src/MANYBODY/pair_eam.cpp b/src/MANYBODY/pair_eam.cpp index 0d421e89cd..5c48c9f982 100644 --- a/src/MANYBODY/pair_eam.cpp +++ b/src/MANYBODY/pair_eam.cpp @@ -125,11 +125,15 @@ PairEAM::~PairEAM() void PairEAM::compute(int eflag, int vflag) { int i,j,ii,jj,m,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r,p,fforce,rhoip,rhojp,z2,z2p,recip,phi,phip,psip; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,r,p,rhoip,rhojp,z2,z2p,recip,phip,psip,phi; double *coeff; int *ilist,*jlist,*numneigh,**firstneigh; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + // grow energy array if necessary if (atom->nmax > nmax) { @@ -140,9 +144,6 @@ void PairEAM::compute(int eflag, int vflag) fp = (double *) memory->smalloc(nmax*sizeof(double),"pair:fp"); } - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; - double **x = atom->x; double **f = atom->f; int *type = atom->type; @@ -214,7 +215,11 @@ void PairEAM::compute(int eflag, int vflag) p = MIN(p,1.0); coeff = frho_spline[type2frho[type[i]]][m]; fp[i] = (coeff[0]*p + coeff[1])*p + coeff[2]; - if (eflag) eng_vdwl += ((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6]; + if (eflag) { + phi = ((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6]; + if (eflag_global) eng_vdwl += phi; + if (eflag_atom) eatom[i] += phi; + } } // communicate derivative of embedding function @@ -273,35 +278,26 @@ void PairEAM::compute(int eflag, int vflag) phi = z2*recip; phip = z2p*recip - phi*recip; psip = fp[i]*rhojp + fp[j]*rhoip + phip; - fforce = -psip*recip; + fpair = -psip*recip; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } - if (eflag) { - if (newton_pair || j < nlocal) eng_vdwl += phi; - else eng_vdwl += 0.5*phi; - } + if (eflag) evdwl = phi; - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- @@ -805,19 +801,6 @@ void PairEAM::single(int i, int j, int itype, int jtype, /* ---------------------------------------------------------------------- */ -void PairEAM::single_embed(int i, int itype, double &phi) -{ - double p = rho[i]*rdrho + 1.0; - int m = static_cast (p); - m = MAX(1,MIN(m,nrho-1)); - p -= m; - - double *coeff = frho_spline[type2frho[itype]][m]; - phi = ((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6]; -} - -/* ---------------------------------------------------------------------- */ - int PairEAM::pack_comm(int n, int *list, double *buf, int pbc_flag, int *pbc) { int i,j,m; @@ -872,7 +855,9 @@ void PairEAM::unpack_reverse_comm(int n, int *list, double *buf) double PairEAM::memory_usage() { - double bytes = 2 * nmax * sizeof(double); + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); + bytes += 2 * nmax * sizeof(double); return bytes; } diff --git a/src/MANYBODY/pair_eam.h b/src/MANYBODY/pair_eam.h index 5a939b35c6..3d88bfd86d 100644 --- a/src/MANYBODY/pair_eam.h +++ b/src/MANYBODY/pair_eam.h @@ -29,8 +29,6 @@ class PairEAM : public Pair { double init_one(int, int); void single(int, int, int, int, double, double, double, int, One &); - void single_embed(int, int, double &); - int pack_comm(int, int *, double *, int, int *); void unpack_comm(int, int, double *); int pack_reverse_comm(int, int, double *); diff --git a/src/MANYBODY/pair_sw.cpp b/src/MANYBODY/pair_sw.cpp index 0c6a5bb468..eb08ca5191 100755 --- a/src/MANYBODY/pair_sw.cpp +++ b/src/MANYBODY/pair_sw.cpp @@ -75,19 +75,21 @@ PairSW::~PairSW() void PairSW::compute(int eflag, int vflag) { int i,j,k,ii,jj,kk,inum,jnum,jnumm1,itag,jtag,itype,jtype,ktype,iparam; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,rsq1,rsq2,eng,fforce; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,rsq1,rsq2; double delr1[3],delr2[3],fj[3],fk[3]; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *tag = atom->tag; int *type = atom->type; int nlocal = atom->nlocal; + int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; @@ -134,15 +136,17 @@ void PairSW::compute(int eflag, int vflag) iparam = elem2param[itype][jtype][jtype]; if (rsq > params[iparam].cutsq) continue; - twobody(¶ms[iparam],rsq,fforce,eflag,eng); + twobody(¶ms[iparam],rsq,fpair,eflag,evdwl); - if (eflag) eng_vdwl += eng; - f[i][0] += fforce*delx; - f[i][1] += fforce*dely; - f[i][2] += fforce*delz; - f[j][0] -= fforce*delx; - f[j][1] -= fforce*dely; - f[j][2] -= fforce*delz; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; + + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } // three-body interactions @@ -172,9 +176,8 @@ void PairSW::compute(int eflag, int vflag) rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; if (rsq2 > params[iparam].cutsq) continue; - threebody(¶ms[iparam],rsq1,rsq2,delr1,delr2,fj,fk,eflag,eng); + threebody(¶ms[iparam],rsq1,rsq2,delr1,delr2,fj,fk,eflag,evdwl); - if (eflag) eng_vdwl += eng; f[i][0] -= fj[0] + fk[0]; f[i][1] -= fj[1] + fk[1]; f[i][2] -= fj[2] + fk[2]; @@ -184,10 +187,13 @@ void PairSW::compute(int eflag, int vflag) f[k][0] += fk[0]; f[k][1] += fk[1]; f[k][2] += fk[2]; + + if (evflag) ev_tally3(i,j,k,evdwl,0.0,fj,fk,delr1,delr2); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- */ diff --git a/src/MANYBODY/pair_tersoff.cpp b/src/MANYBODY/pair_tersoff.cpp index 768087ddaa..c9219a0730 100755 --- a/src/MANYBODY/pair_tersoff.cpp +++ b/src/MANYBODY/pair_tersoff.cpp @@ -77,20 +77,22 @@ void PairTersoff::compute(int eflag, int vflag) { int i,j,k,ii,jj,kk,inum,jnum; int itag,jtag,itype,jtype,ktype,iparam_ij,iparam_ijk; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,rsq1,rsq2,eng,fforce; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,rsq1,rsq2; double delr1[3],delr2[3],fi[3],fj[3],fk[3]; double zeta_ij,prefactor; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *tag = atom->tag; int *type = atom->type; int nlocal = atom->nlocal; + int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; @@ -129,23 +131,25 @@ void PairTersoff::compute(int eflag, int vflag) jtype = map[type[j]]; - delx = x[j][0] - xtmp; - dely = x[j][1] - ytmp; - delz = x[j][2] - ztmp; + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; iparam_ij = elem2param[itype][jtype][jtype]; if (rsq > params[iparam_ij].cutsq) continue; - repulsive(¶ms[iparam_ij],rsq,fforce,eflag,eng); + repulsive(¶ms[iparam_ij],rsq,fpair,eflag,evdwl); - if (eflag) eng_vdwl += eng; - f[i][0] += fforce*delx; - f[i][1] += fforce*dely; - f[i][2] += fforce*delz; - f[j][0] -= fforce*delx; - f[j][1] -= fforce*dely; - f[j][2] -= fforce*delz; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; + + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } // three-body interactions @@ -183,15 +187,17 @@ void PairTersoff::compute(int eflag, int vflag) // pairwise force due to zeta - force_zeta(¶ms[iparam_ij],rsq1,zeta_ij,fforce,prefactor,eflag,eng); + force_zeta(¶ms[iparam_ij],rsq1,zeta_ij,fpair,prefactor,eflag,evdwl); - if (eflag) eng_vdwl += eng; - f[i][0] += fforce*delr1[0]; - f[i][1] += fforce*delr1[1]; - f[i][2] += fforce*delr1[2]; - f[j][0] -= fforce*delr1[0]; - f[j][1] -= fforce*delr1[1]; - f[j][2] -= fforce*delr1[2]; + f[i][0] += delr1[0]*fpair; + f[i][1] += delr1[1]*fpair; + f[i][2] += delr1[2]*fpair; + f[j][0] -= delr1[0]*fpair; + f[j][1] -= delr1[1]*fpair; + f[j][2] -= delr1[2]*fpair; + + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,-fpair,-delr1[0],-delr1[1],-delr1[2]); // attractive term via loop over k @@ -219,10 +225,13 @@ void PairTersoff::compute(int eflag, int vflag) f[k][0] += fk[0]; f[k][1] += fk[1]; f[k][2] += fk[2]; + + if (evflag) ev_tally3(i,j,k,evdwl,0.0,fj,fk,delr1,delr2); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- */ @@ -543,8 +552,7 @@ void PairTersoff::repulsive(Param *param, double rsq, double &fforce, tmp_fc = ters_fc(r,param); tmp_fc_d = ters_fc_d(r,param); tmp_exp = exp(-param->lam1 * r); - fforce = param->biga * tmp_exp * (tmp_fc_d - tmp_fc*param->lam1) / r; - + fforce = -param->biga * tmp_exp * (tmp_fc_d - tmp_fc*param->lam1) / r; if (eflag) eng = tmp_fc * param->biga * tmp_exp; } diff --git a/src/MOLECULE/angle.cpp b/src/MOLECULE/angle.cpp index f42c92d12f..df8a80e22f 100644 --- a/src/MOLECULE/angle.cpp +++ b/src/MOLECULE/angle.cpp @@ -14,6 +14,8 @@ #include "math.h" #include "angle.h" #include "atom.h" +#include "force.h" +#include "memory.h" #include "error.h" using namespace LAMMPS_NS; @@ -22,8 +24,23 @@ using namespace LAMMPS_NS; Angle::Angle(LAMMPS *lmp) : Pointers(lmp) { + energy = 0.0; + allocated = 0; PI = 4.0*atan(1.0); + THIRD = 1.0/3.0; + + maxeatom = maxvatom = 0; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +Angle::~Angle() +{ + memory->sfree(eatom); + memory->destroy_2d_double_array(vatom); } /* ---------------------------------------------------------------------- @@ -37,3 +54,169 @@ void Angle::init() if (setflag[i] == 0) error->all("All angle coeffs are not set"); } +/* ---------------------------------------------------------------------- + setup for energy, virial computation + see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) +------------------------------------------------------------------------- */ + +void Angle::ev_setup(int eflag, int vflag) +{ + int i,n; + + evflag = 1; + + eflag_either = eflag; + eflag_global = eflag % 2; + eflag_atom = eflag / 2; + + vflag_either = vflag; + vflag_global = vflag % 4; + vflag_atom = vflag / 4; + + // reallocate per-atom arrays if necessary + + if (eflag_atom && atom->nmax > maxeatom) { + maxeatom = atom->nmax; + memory->sfree(eatom); + eatom = (double *) memory->smalloc(maxeatom*sizeof(double),"bond:eatom"); + } + if (vflag_atom && atom->nmax > maxvatom) { + maxvatom = atom->nmax; + memory->destroy_2d_double_array(vatom); + vatom = memory->create_2d_double_array(maxvatom,6,"bond:vatom"); + } + + // zero accumulators + + if (eflag_global) energy = 0.0; + if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0; + if (eflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + for (i = 0; i < n; i++) eatom[i] = 0.0; + } + if (vflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + for (i = 0; i < n; i++) { + vatom[i][0] = 0.0; + vatom[i][1] = 0.0; + vatom[i][2] = 0.0; + vatom[i][3] = 0.0; + vatom[i][4] = 0.0; + vatom[i][5] = 0.0; + } + } +} + +/* ---------------------------------------------------------------------- + tally energy and virial into global and per-atom accumulators + virial = r1F1 + r2F2 + r3F3 = (r1-r2) F1 + (r3-r2) F3 = del1*f1 + del2*f3 +------------------------------------------------------------------------- */ + +void Angle::ev_tally(int i, int j, int k, int nlocal, int newton_bond, + double eangle, double *f1, double *f3, + double delx1, double dely1, double delz1, + double delx2, double dely2, double delz2) +{ + double eanglethird,v[6]; + + if (eflag_either) { + if (eflag_global) { + if (newton_bond) energy += eangle; + else { + eanglethird = THIRD*eangle; + if (i < nlocal) energy += eanglethird; + if (j < nlocal) energy += eanglethird; + if (k < nlocal) energy += eanglethird; + } + } + if (eflag_atom) { + eanglethird = THIRD*eangle; + if (newton_bond || i < nlocal) eatom[i] += eanglethird; + if (newton_bond || j < nlocal) eatom[j] += eanglethird; + if (newton_bond || k < nlocal) eatom[k] += eanglethird; + } + } + + if (vflag_either) { + v[0] = delx1*f1[0] + delx2*f3[0]; + v[1] = dely1*f1[1] + dely2*f3[1]; + v[2] = delz1*f1[2] + delz2*f3[2]; + v[3] = delx1*f1[1] + delx2*f3[1]; + v[4] = delx1*f1[2] + delx2*f3[2]; + v[5] = dely1*f1[2] + dely2*f3[2]; + + if (vflag_global) { + if (newton_bond) { + virial[0] += v[0]; + virial[1] += v[1]; + virial[2] += v[2]; + virial[3] += v[3]; + virial[4] += v[4]; + virial[5] += v[5]; + } else { + if (i < nlocal) { + virial[0] += THIRD*v[0]; + virial[1] += THIRD*v[1]; + virial[2] += THIRD*v[2]; + virial[3] += THIRD*v[3]; + virial[4] += THIRD*v[4]; + virial[5] += THIRD*v[5]; + } + if (j < nlocal) { + virial[0] += THIRD*v[0]; + virial[1] += THIRD*v[1]; + virial[2] += THIRD*v[2]; + virial[3] += THIRD*v[3]; + virial[4] += THIRD*v[4]; + virial[5] += THIRD*v[5]; + } + if (k < nlocal) { + virial[0] += THIRD*v[0]; + virial[1] += THIRD*v[1]; + virial[2] += THIRD*v[2]; + virial[3] += THIRD*v[3]; + virial[4] += THIRD*v[4]; + virial[5] += THIRD*v[5]; + } + } + } + + if (vflag_atom) { + if (newton_bond || i < nlocal) { + vatom[i][0] += THIRD*v[0]; + vatom[i][1] += THIRD*v[1]; + vatom[i][2] += THIRD*v[2]; + vatom[i][3] += THIRD*v[3]; + vatom[i][4] += THIRD*v[4]; + vatom[i][5] += THIRD*v[5]; + } + if (newton_bond || j < nlocal) { + vatom[j][0] += THIRD*v[0]; + vatom[j][1] += THIRD*v[1]; + vatom[j][2] += THIRD*v[2]; + vatom[j][3] += THIRD*v[3]; + vatom[j][4] += THIRD*v[4]; + vatom[j][5] += THIRD*v[5]; + } + if (newton_bond || k < nlocal) { + vatom[k][0] += THIRD*v[0]; + vatom[k][1] += THIRD*v[1]; + vatom[k][2] += THIRD*v[2]; + vatom[k][3] += THIRD*v[3]; + vatom[k][4] += THIRD*v[4]; + vatom[k][5] += THIRD*v[5]; + } + } + } +} + +/* ---------------------------------------------------------------------- */ + +double Angle::memory_usage() +{ + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); + return bytes; +} diff --git a/src/MOLECULE/angle_charmm.cpp b/src/MOLECULE/angle_charmm.cpp index 87aac8c897..42602a8f41 100644 --- a/src/MOLECULE/angle_charmm.cpp +++ b/src/MOLECULE/angle_charmm.cpp @@ -51,13 +51,16 @@ AngleCharmm::~AngleCharmm() void AngleCharmm::compute(int eflag, int vflag) { - int i1,i2,i3,n,type,factor; - double delx1,dely1,delz1,delx2,dely2,delz2,rfactor,dtheta,tk; - double rsq1,rsq2,r1,r2,c,s,a,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; + int i1,i2,i3,n,type; + double delx1,dely1,delz1,delx2,dely2,delz2; + double eangle,f1[3],f3[3]; + double dtheta,tk; + double rsq1,rsq2,r1,r2,c,s,a,a11,a12,a22; double delxUB,delyUB,delzUB,rsqUB,rUB,dr,rk,forceUB; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + eangle = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -67,21 +70,11 @@ void AngleCharmm::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nanglelist; n++) { - i1 = anglelist[n][0]; i2 = anglelist[n][1]; i3 = anglelist[n][2]; type = anglelist[n][3]; - if (newton_bond) factor = 3; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - } - rfactor = factor/3.0; - // 1st bond delx1 = x[i1][0] - x[i2][0]; @@ -112,6 +105,16 @@ void AngleCharmm::compute(int eflag, int vflag) rsqUB = delxUB*delxUB + delyUB*delyUB + delzUB*delzUB; rUB = sqrt(rsqUB); + // Urey-Bradley force & energy + + dr = rUB - r_ub[type]; + rk = k_ub[type] * dr; + + if (rUB > 0.0) forceUB = -2.0*rk/rUB; + else forceUB = 0.0; + + if (eflag) eangle = rk*dr; + // angle (cos and sin) c = delx1*delx2 + dely1*dely2 + delz1*delz2; @@ -129,61 +132,43 @@ void AngleCharmm::compute(int eflag, int vflag) dtheta = acos(c) - theta0[type]; tk = k[type] * dtheta; - if (eflag) energy += rfactor * tk*dtheta; + if (eflag) eangle += tk*dtheta; - a = 2.0 * tk * s; - + a = -2.0 * tk * s; a11 = a*c / rsq1; a12 = -a / (r1*r2); a22 = a*c / rsq2; - - vx1 = a11*delx1 + a12*delx2; - vx2 = a22*delx2 + a12*delx1; - vy1 = a11*dely1 + a12*dely2; - vy2 = a22*dely2 + a12*dely1; - vz1 = a11*delz1 + a12*delz2; - vz2 = a22*delz2 + a12*delz1; - // Urey-Bradley force & energy + f1[0] = a11*delx1 + a12*delx2 - delxUB*forceUB; + f1[1] = a11*dely1 + a12*dely2 - delyUB*forceUB; + f1[2] = a11*delz1 + a12*delz2 - delzUB*forceUB; - dr = rUB - r_ub[type]; - rk = k_ub[type] * dr; - - if (rUB > 0.0) forceUB = -2.0*rk/rUB; - else forceUB = 0.0; - - if (eflag) energy += rfactor * rk*dr; + f3[0] = a22*delx2 + a12*delx1 + delxUB*forceUB; + f3[1] = a22*dely2 + a12*dely1 + delyUB*forceUB; + f3[2] = a22*delz2 + a12*delz1 + delzUB*forceUB; // apply force to each of 3 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= vx1 + delxUB*forceUB; - f[i1][1] -= vy1 + delyUB*forceUB; - f[i1][2] -= vz1 + delzUB*forceUB; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += vx1 + vx2; - f[i2][1] += vy1 + vy2; - f[i2][2] += vz1 + vz2; + f[i2][0] -= f1[0] + f3[0]; + f[i2][1] -= f1[1] + f3[1]; + f[i2][2] -= f1[2] + f3[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] -= vx2 - delxUB*forceUB; - f[i3][1] -= vy2 - delyUB*forceUB; - f[i3][2] -= vz2 - delzUB*forceUB; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } - // virial contribution - - if (vflag) { - virial[0] -= rfactor * (delx1*vx1 + delx2*vx2 - delxUB*delxUB*forceUB); - virial[1] -= rfactor * (dely1*vy1 + dely2*vy2 - delyUB*delyUB*forceUB); - virial[2] -= rfactor * (delz1*vz1 + delz2*vz2 - delzUB*delzUB*forceUB); - virial[3] -= rfactor * (delx1*vy1 + delx2*vy2 - delxUB*delyUB*forceUB); - virial[4] -= rfactor * (delx1*vz1 + delx2*vz2 - delxUB*delzUB*forceUB); - virial[5] -= rfactor * (dely1*vz1 + dely2*vz2 - delyUB*delzUB*forceUB); - } + if (evflag) ev_tally(i1,i2,i3,nlocal,newton_bond,eangle,f1,f3, + delx1,dely1,delz1,delx2,dely2,delz2); } } diff --git a/src/MOLECULE/angle_cosine.cpp b/src/MOLECULE/angle_cosine.cpp index f8ce82f083..38f4e0d654 100644 --- a/src/MOLECULE/angle_cosine.cpp +++ b/src/MOLECULE/angle_cosine.cpp @@ -44,12 +44,14 @@ AngleCosine::~AngleCosine() void AngleCosine::compute(int eflag, int vflag) { - int i1,i2,i3,n,type,factor; - double delx1,dely1,delz1,delx2,dely2,delz2,rfactor; - double rsq1,rsq2,r1,r2,c,a,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; + int i1,i2,i3,n,type; + double delx1,dely1,delz1,delx2,dely2,delz2; + double eangle,f1[3],f3[3]; + double rsq1,rsq2,r1,r2,c,a,a11,a12,a22; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + eangle = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -59,21 +61,11 @@ void AngleCosine::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nanglelist; n++) { - i1 = anglelist[n][0]; i2 = anglelist[n][1]; i3 = anglelist[n][2]; type = anglelist[n][3]; - if (newton_bond) factor = 3; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - } - rfactor = factor/3.0; - // 1st bond delx1 = x[i1][0] - x[i2][0]; @@ -103,51 +95,42 @@ void AngleCosine::compute(int eflag, int vflag) // force & energy - if (eflag) energy += rfactor * k[type]*(1.0+c); + if (eflag) eangle = k[type]*(1.0+c); - a = -k[type]; - + a = k[type]; a11 = a*c / rsq1; a12 = -a / (r1*r2); a22 = a*c / rsq2; - vx1 = a11*delx1 + a12*delx2; - vx2 = a22*delx2 + a12*delx1; - vy1 = a11*dely1 + a12*dely2; - vy2 = a22*dely2 + a12*dely1; - vz1 = a11*delz1 + a12*delz2; - vz2 = a22*delz2 + a12*delz1; + f1[0] = a11*delx1 + a12*delx2; + f1[1] = a11*dely1 + a12*dely2; + f1[2] = a11*delz1 + a12*delz2; + f3[0] = a22*delx2 + a12*delx1; + f3[1] = a22*dely2 + a12*dely1; + f3[2] = a22*delz2 + a12*delz1; // apply force to each of 3 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= vx1; - f[i1][1] -= vy1; - f[i1][2] -= vz1; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += vx1 + vx2; - f[i2][1] += vy1 + vy2; - f[i2][2] += vz1 + vz2; + f[i2][0] -= f1[0] + f3[0]; + f[i2][1] -= f1[1] + f3[1]; + f[i2][2] -= f1[2] + f3[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] -= vx2; - f[i3][1] -= vy2; - f[i3][2] -= vz2; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } - // virial contribution - - if (vflag) { - virial[0] -= rfactor * (delx1*vx1 + delx2*vx2); - virial[1] -= rfactor * (dely1*vy1 + dely2*vy2); - virial[2] -= rfactor * (delz1*vz1 + delz2*vz2); - virial[3] -= rfactor * (delx1*vy1 + delx2*vy2); - virial[4] -= rfactor * (delx1*vz1 + delx2*vz2); - virial[5] -= rfactor * (dely1*vz1 + dely2*vz2); - } + if (evflag) ev_tally(i1,i2,i3,nlocal,newton_bond,eangle,f1,f3, + delx1,dely1,delz1,delx2,dely2,delz2); } } diff --git a/src/MOLECULE/angle_cosine_squared.cpp b/src/MOLECULE/angle_cosine_squared.cpp index 512547e72e..d31e973c90 100644 --- a/src/MOLECULE/angle_cosine_squared.cpp +++ b/src/MOLECULE/angle_cosine_squared.cpp @@ -49,12 +49,15 @@ AngleCosineSquared::~AngleCosineSquared() void AngleCosineSquared::compute(int eflag, int vflag) { - int i1,i2,i3,n,type,factor; - double delx1,dely1,delz1,delx2,dely2,delz2,rfactor,dcostheta,tk; - double rsq1,rsq2,r1,r2,c,a,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; + int i1,i2,i3,n,type; + double delx1,dely1,delz1,delx2,dely2,delz2; + double eangle,f1[3],f3[3]; + double dcostheta,tk; + double rsq1,rsq2,r1,r2,c,a,a11,a12,a22; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + eangle = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -64,21 +67,11 @@ void AngleCosineSquared::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nanglelist; n++) { - i1 = anglelist[n][0]; i2 = anglelist[n][1]; i3 = anglelist[n][2]; type = anglelist[n][3]; - if (newton_bond) factor = 3; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - } - rfactor = factor/3.0; - // 1st bond delx1 = x[i1][0] - x[i2][0]; @@ -112,51 +105,42 @@ void AngleCosineSquared::compute(int eflag, int vflag) dcostheta = c - cos(theta0[type]); tk = k[type] * dcostheta; - if (eflag) energy += rfactor * tk*dcostheta; + if (eflag) eangle = tk*dcostheta; - a = -2.0 * tk; - + a = 2.0 * tk; a11 = a*c / rsq1; a12 = -a / (r1*r2); a22 = a*c / rsq2; - - vx1 = a11*delx1 + a12*delx2; - vx2 = a22*delx2 + a12*delx1; - vy1 = a11*dely1 + a12*dely2; - vy2 = a22*dely2 + a12*dely1; - vz1 = a11*delz1 + a12*delz2; - vz2 = a22*delz2 + a12*delz1; + + f1[0] = a11*delx1 + a12*delx2; + f1[1] = a11*dely1 + a12*dely2; + f1[2] = a11*delz1 + a12*delz2; + f3[0] = a22*delx2 + a12*delx1; + f3[1] = a22*dely2 + a12*dely1; + f3[2] = a22*delz2 + a12*delz1; // apply force to each of 3 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= vx1; - f[i1][1] -= vy1; - f[i1][2] -= vz1; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += vx1 + vx2; - f[i2][1] += vy1 + vy2; - f[i2][2] += vz1 + vz2; + f[i2][0] -= f1[0] + f3[0]; + f[i2][1] -= f1[1] + f3[1]; + f[i2][2] -= f1[2] + f3[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] -= vx2; - f[i3][1] -= vy2; - f[i3][2] -= vz2; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } - // virial contribution - - if (vflag) { - virial[0] -= rfactor * (delx1*vx1 + delx2*vx2); - virial[1] -= rfactor * (dely1*vy1 + dely2*vy2); - virial[2] -= rfactor * (delz1*vz1 + delz2*vz2); - virial[3] -= rfactor * (delx1*vy1 + delx2*vy2); - virial[4] -= rfactor * (delx1*vz1 + delx2*vz2); - virial[5] -= rfactor * (dely1*vz1 + dely2*vz2); - } + if (evflag) ev_tally(i1,i2,i3,nlocal,newton_bond,eangle,f1,f3, + delx1,dely1,delz1,delx2,dely2,delz2); } } diff --git a/src/MOLECULE/angle_harmonic.cpp b/src/MOLECULE/angle_harmonic.cpp index ba5d0821a8..86a438a933 100644 --- a/src/MOLECULE/angle_harmonic.cpp +++ b/src/MOLECULE/angle_harmonic.cpp @@ -45,12 +45,15 @@ AngleHarmonic::~AngleHarmonic() void AngleHarmonic::compute(int eflag, int vflag) { - int i1,i2,i3,n,type,factor; - double delx1,dely1,delz1,delx2,dely2,delz2,rfactor,dtheta,tk; - double rsq1,rsq2,r1,r2,c,s,a,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; + int i1,i2,i3,n,type; + double delx1,dely1,delz1,delx2,dely2,delz2; + double eangle,f1[3],f3[3]; + double dtheta,tk; + double rsq1,rsq2,r1,r2,c,s,a,a11,a12,a22; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + eangle = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -60,21 +63,11 @@ void AngleHarmonic::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nanglelist; n++) { - i1 = anglelist[n][0]; i2 = anglelist[n][1]; i3 = anglelist[n][2]; type = anglelist[n][3]; - if (newton_bond) factor = 3; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - } - rfactor = factor/3.0; - // 1st bond delx1 = x[i1][0] - x[i2][0]; @@ -112,51 +105,42 @@ void AngleHarmonic::compute(int eflag, int vflag) dtheta = acos(c) - theta0[type]; tk = k[type] * dtheta; - if (eflag) energy += rfactor * tk*dtheta; + if (eflag) eangle = tk*dtheta; - a = 2.0 * tk * s; - + a = -2.0 * tk * s; a11 = a*c / rsq1; a12 = -a / (r1*r2); a22 = a*c / rsq2; - - vx1 = a11*delx1 + a12*delx2; - vx2 = a22*delx2 + a12*delx1; - vy1 = a11*dely1 + a12*dely2; - vy2 = a22*dely2 + a12*dely1; - vz1 = a11*delz1 + a12*delz2; - vz2 = a22*delz2 + a12*delz1; + + f1[0] = a11*delx1 + a12*delx2; + f1[1] = a11*dely1 + a12*dely2; + f1[2] = a11*delz1 + a12*delz2; + f3[0] = a22*delx2 + a12*delx1; + f3[1] = a22*dely2 + a12*dely1; + f3[2] = a22*delz2 + a12*delz1; // apply force to each of 3 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= vx1; - f[i1][1] -= vy1; - f[i1][2] -= vz1; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += vx1 + vx2; - f[i2][1] += vy1 + vy2; - f[i2][2] += vz1 + vz2; + f[i2][0] -= f1[0] + f3[0]; + f[i2][1] -= f1[1] + f3[1]; + f[i2][2] -= f1[2] + f3[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] -= vx2; - f[i3][1] -= vy2; - f[i3][2] -= vz2; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } - // virial contribution - - if (vflag) { - virial[0] -= rfactor * (delx1*vx1 + delx2*vx2); - virial[1] -= rfactor * (dely1*vy1 + dely2*vy2); - virial[2] -= rfactor * (delz1*vz1 + delz2*vz2); - virial[3] -= rfactor * (delx1*vy1 + delx2*vy2); - virial[4] -= rfactor * (delx1*vz1 + delx2*vz2); - virial[5] -= rfactor * (dely1*vz1 + dely2*vz2); - } + if (evflag) ev_tally(i1,i2,i3,nlocal,newton_bond,eangle,f1,f3, + delx1,dely1,delz1,delx2,dely2,delz2); } } diff --git a/src/MOLECULE/angle_hybrid.cpp b/src/MOLECULE/angle_hybrid.cpp index ff59db91df..307e1355be 100644 --- a/src/MOLECULE/angle_hybrid.cpp +++ b/src/MOLECULE/angle_hybrid.cpp @@ -59,7 +59,7 @@ AngleHybrid::~AngleHybrid() void AngleHybrid::compute(int eflag, int vflag) { - int i,m,n; + int i,j,m,n; // save ptrs to original anglelist @@ -96,19 +96,36 @@ void AngleHybrid::compute(int eflag, int vflag) } // call each sub-style's compute function - // must set neighbor->anglelist to sub-style anglelist before call - // accumulate sub-style energy,virial in hybrid's energy,virial + // set neighbor->anglelist to sub-style anglelist before call + // accumulate sub-style global/peratom energy/virial in hybrid - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; for (m = 0; m < nstyles; m++) { if (styles[m] == NULL) continue; neighbor->nanglelist = nanglelist[m]; neighbor->anglelist = anglelist[m]; + styles[m]->compute(eflag,vflag); - if (eflag) energy += styles[m]->energy; - if (vflag) for (n = 0; n < 6; n++) virial[n] += styles[m]->virial[n]; + + if (eflag_global) energy += styles[m]->energy; + if (vflag_global) + for (n = 0; n < 6; n++) virial[n] += styles[m]->virial[n]; + if (eflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + double *eatom_substyle = styles[m]->eatom; + for (i = 0; i < n; i++) eatom[i] += eatom_substyle[i]; + } + if (vflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + double **vatom_substyle = styles[m]->vatom; + for (i = 0; i < n; i++) + for (j = 0; j < 6; j++) + vatom[i][j] += vatom_substyle[i][j]; + } } // restore ptrs to original anglelist @@ -253,7 +270,8 @@ double AngleHybrid::single(int type, int i1, int i2, int i3) double AngleHybrid::memory_usage() { - double bytes = 0.0; + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); for (int m = 0; m < nstyles; m++) bytes += maxangle[m]*4 * sizeof(int); for (int m = 0; m < nstyles; m++) if (styles[m]) bytes += styles[m]->memory_usage(); diff --git a/src/MOLECULE/bond.cpp b/src/MOLECULE/bond.cpp index 45f2444092..6551297f46 100644 --- a/src/MOLECULE/bond.cpp +++ b/src/MOLECULE/bond.cpp @@ -14,6 +14,8 @@ #include "string.h" #include "bond.h" #include "atom.h" +#include "force.h" +#include "memory.h" #include "error.h" using namespace LAMMPS_NS; @@ -25,8 +27,21 @@ using namespace LAMMPS_NS; Bond::Bond(LAMMPS *lmp) : Pointers(lmp) { + energy = 0.0; + allocated = 0; - eng_vdwl = 0.0; + + maxeatom = maxvatom = 0; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +Bond::~Bond() +{ + memory->sfree(eatom); + memory->destroy_2d_double_array(vatom); } /* ---------------------------------------------------------------------- @@ -40,3 +55,150 @@ void Bond::init() if (setflag[i] == 0) error->all("All bond coeffs are not set"); init_style(); } + +/* ---------------------------------------------------------------------- + setup for energy, virial computation + see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) +------------------------------------------------------------------------- */ + +void Bond::ev_setup(int eflag, int vflag) +{ + int i,n; + + evflag = 1; + + eflag_either = eflag; + eflag_global = eflag % 2; + eflag_atom = eflag / 2; + + vflag_either = vflag; + vflag_global = vflag % 4; + vflag_atom = vflag / 4; + + // reallocate per-atom arrays if necessary + + if (eflag_atom && atom->nmax > maxeatom) { + maxeatom = atom->nmax; + memory->sfree(eatom); + eatom = (double *) memory->smalloc(maxeatom*sizeof(double),"bond:eatom"); + } + if (vflag_atom && atom->nmax > maxvatom) { + maxvatom = atom->nmax; + memory->destroy_2d_double_array(vatom); + vatom = memory->create_2d_double_array(maxvatom,6,"bond:vatom"); + } + + // zero accumulators + + if (eflag_global) energy = 0.0; + if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0; + if (eflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + for (i = 0; i < n; i++) eatom[i] = 0.0; + } + if (vflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + for (i = 0; i < n; i++) { + vatom[i][0] = 0.0; + vatom[i][1] = 0.0; + vatom[i][2] = 0.0; + vatom[i][3] = 0.0; + vatom[i][4] = 0.0; + vatom[i][5] = 0.0; + } + } +} + +/* ---------------------------------------------------------------------- + tally energy and virial into global and per-atom accumulators +------------------------------------------------------------------------- */ + +void Bond::ev_tally(int i, int j, int nlocal, int newton_bond, + double ebond, double fbond, + double delx, double dely, double delz) +{ + double ebondhalf,v[6]; + + if (eflag_either) { + if (eflag_global) { + if (newton_bond) energy += ebond; + else { + ebondhalf = 0.5*ebond; + if (i < nlocal) energy += ebondhalf; + if (j < nlocal) energy += ebondhalf; + } + } + if (eflag_atom) { + ebondhalf = 0.5*ebond; + if (newton_bond || i < nlocal) eatom[i] += ebondhalf; + if (newton_bond || j < nlocal) eatom[j] += ebondhalf; + } + } + + if (vflag_either) { + v[0] = delx*delx*fbond; + v[1] = dely*dely*fbond; + v[2] = delz*delz*fbond; + v[3] = delx*dely*fbond; + v[4] = delx*delz*fbond; + v[5] = dely*delz*fbond; + + if (vflag_global) { + if (newton_bond) { + virial[0] += v[0]; + virial[1] += v[1]; + virial[2] += v[2]; + virial[3] += v[3]; + virial[4] += v[4]; + virial[5] += v[5]; + } else { + if (i < nlocal) { + virial[0] += 0.5*v[0]; + virial[1] += 0.5*v[1]; + virial[2] += 0.5*v[2]; + virial[3] += 0.5*v[3]; + virial[4] += 0.5*v[4]; + virial[5] += 0.5*v[5]; + } + if (j < nlocal) { + virial[0] += 0.5*v[0]; + virial[1] += 0.5*v[1]; + virial[2] += 0.5*v[2]; + virial[3] += 0.5*v[3]; + virial[4] += 0.5*v[4]; + virial[5] += 0.5*v[5]; + } + } + } + + if (vflag_atom) { + if (newton_bond || i < nlocal) { + vatom[i][0] += 0.5*v[0]; + vatom[i][1] += 0.5*v[1]; + vatom[i][2] += 0.5*v[2]; + vatom[i][3] += 0.5*v[3]; + vatom[i][4] += 0.5*v[4]; + vatom[i][5] += 0.5*v[5]; + } + if (newton_bond || j < nlocal) { + vatom[j][0] += 0.5*v[0]; + vatom[j][1] += 0.5*v[1]; + vatom[j][2] += 0.5*v[2]; + vatom[j][3] += 0.5*v[3]; + vatom[j][4] += 0.5*v[4]; + vatom[j][5] += 0.5*v[5]; + } + } + } +} + +/* ---------------------------------------------------------------------- */ + +double Bond::memory_usage() +{ + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); + return bytes; +} diff --git a/src/MOLECULE/bond_fene.cpp b/src/MOLECULE/bond_fene.cpp index a1d7cd9769..9bf82538c1 100644 --- a/src/MOLECULE/bond_fene.cpp +++ b/src/MOLECULE/bond_fene.cpp @@ -49,11 +49,13 @@ BondFENE::~BondFENE() void BondFENE::compute(int eflag, int vflag) { - int i1,i2,n,type,factor; - double delx,dely,delz,rsq,r0sq,rlogarg,fforce,sr2,sr6,rfactor; + int i1,i2,n,type; + double delx,dely,delz,ebond,fbond; + double rsq,r0sq,rlogarg,sr2,sr6; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + ebond = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -63,19 +65,10 @@ void BondFENE::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nbondlist; n++) { - i1 = bondlist[n][0]; i2 = bondlist[n][1]; type = bondlist[n][2]; - if (newton_bond) factor = 2; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - } - rfactor = 0.5*factor; - delx = x[i1][0] - x[i2][0]; dely = x[i1][1] - x[i2][1]; delz = x[i1][2] - x[i2][2]; @@ -100,48 +93,39 @@ void BondFENE::compute(int eflag, int vflag) rlogarg = 0.1; } - fforce = -k[type]/rlogarg; + fbond = -k[type]/rlogarg; // force from LJ term if (rsq < TWO_1_3*sigma[type]*sigma[type]) { sr2 = sigma[type]*sigma[type]/rsq; sr6 = sr2*sr2*sr2; - fforce += 48.0*epsilon[type]*sr6*(sr6-0.5)/rsq; + fbond += 48.0*epsilon[type]*sr6*(sr6-0.5)/rsq; } // energy if (eflag) { - energy -= 0.5*rfactor * k[type]*r0sq*log(rlogarg); + ebond = -0.5 * k[type]*r0sq*log(rlogarg); if (rsq < TWO_1_3*sigma[type]*sigma[type]) - energy += rfactor * (4.0*epsilon[type]*sr6*(sr6-1.0) + epsilon[type]); + ebond += 4.0*epsilon[type]*sr6*(sr6-1.0) + epsilon[type]; } // apply force to each of 2 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] += delx*fforce; - f[i1][1] += dely*fforce; - f[i1][2] += delz*fforce; + f[i1][0] += delx*fbond; + f[i1][1] += dely*fbond; + f[i1][2] += delz*fbond; } if (newton_bond || i2 < nlocal) { - f[i2][0] -= delx*fforce; - f[i2][1] -= dely*fforce; - f[i2][2] -= delz*fforce; + f[i2][0] -= delx*fbond; + f[i2][1] -= dely*fbond; + f[i2][2] -= delz*fbond; } - // virial contribution - - if (vflag) { - virial[0] += rfactor * delx*delx*fforce; - virial[1] += rfactor * dely*dely*fforce; - virial[2] += rfactor * delz*delz*fforce; - virial[3] += rfactor * delx*dely*fforce; - virial[4] += rfactor * delx*delz*fforce; - virial[5] += rfactor * dely*delz*fforce; - } + if (evflag) ev_tally(i1,i2,nlocal,newton_bond,ebond,fbond,delx,dely,delz); } } @@ -233,8 +217,7 @@ void BondFENE::read_restart(FILE *fp) /* ---------------------------------------------------------------------- */ -void BondFENE::single(int type, double rsq, int i, int j, - int eflag, double &fforce, double &eng) +void BondFENE::single(int type, double rsq, int i, int j, double &eng) { double r0sq = r0[type] * r0[type]; double rlogarg = 1.0 - rsq/r0sq; @@ -251,22 +234,11 @@ void BondFENE::single(int type, double rsq, int i, int j, rlogarg = 0.1; } - fforce = -k[type]/rlogarg; - - // force from LJ term - - double sr2,sr6; + eng = -0.5 * k[type]*r0sq*log(rlogarg); if (rsq < TWO_1_3*sigma[type]*sigma[type]) { + double sr2,sr6; sr2 = sigma[type]*sigma[type]/rsq; sr6 = sr2*sr2*sr2; - fforce += 48.0*epsilon[type]*sr6*(sr6-0.5)/rsq; - } - - // energy - - if (eflag) { - eng = -0.5 * k[type]*r0sq*log(rlogarg); - if (rsq < TWO_1_3*sigma[type]*sigma[type]) - eng += 4.0*epsilon[type]*sr6*(sr6-1.0) + epsilon[type]; + eng += 4.0*epsilon[type]*sr6*(sr6-1.0) + epsilon[type]; } } diff --git a/src/MOLECULE/bond_fene.h b/src/MOLECULE/bond_fene.h index 96cfe78bcf..68d234ac0e 100644 --- a/src/MOLECULE/bond_fene.h +++ b/src/MOLECULE/bond_fene.h @@ -28,7 +28,7 @@ class BondFENE : public Bond { double equilibrium_distance(int); void write_restart(FILE *); void read_restart(FILE *); - void single(int, double, int, int, int, double &, double &); + void single(int, double, int, int, double &); private: double TWO_1_3; diff --git a/src/MOLECULE/bond_fene_expand.cpp b/src/MOLECULE/bond_fene_expand.cpp index 405494b659..4ddef18ab1 100644 --- a/src/MOLECULE/bond_fene_expand.cpp +++ b/src/MOLECULE/bond_fene_expand.cpp @@ -50,12 +50,14 @@ BondFENEExpand::~BondFENEExpand() void BondFENEExpand::compute(int eflag, int vflag) { - int i1,i2,n,type,factor; - double delx,dely,delz,rsq,r0sq,rlogarg,fforce,sr2,sr6,rfactor; + int i1,i2,n,type; + double delx,dely,delz,ebond,fbond; + double rsq,r0sq,rlogarg,sr2,sr6; double r,rshift,rshiftsq; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + ebond = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -65,19 +67,10 @@ void BondFENEExpand::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nbondlist; n++) { - i1 = bondlist[n][0]; i2 = bondlist[n][1]; type = bondlist[n][2]; - if (newton_bond) factor = 2; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - } - rfactor = 0.5*factor; - delx = x[i1][0] - x[i2][0]; dely = x[i1][1] - x[i2][1]; delz = x[i1][2] - x[i2][2]; @@ -105,50 +98,39 @@ void BondFENEExpand::compute(int eflag, int vflag) rlogarg = 0.1; } - fforce = -k[type]*rshift/rlogarg/r; + fbond = -k[type]*rshift/rlogarg/r; // force from LJ term if (rshiftsq < TWO_1_3*sigma[type]*sigma[type]) { sr2 = sigma[type]*sigma[type]/rshiftsq; sr6 = sr2*sr2*sr2; - fforce += 48.0*epsilon[type]*sr6*(sr6-0.5)/rshift/r; + fbond += 48.0*epsilon[type]*sr6*(sr6-0.5)/rshift/r; } // energy if (eflag) { - energy -= 0.5*rfactor * k[type]*r0sq*log(rlogarg); + ebond = -0.5 * k[type]*r0sq*log(rlogarg); if (rshiftsq < TWO_1_3*sigma[type]*sigma[type]) - energy += 0.5*factor * - (4.0*epsilon[type]*sr6*(sr6-1.0) + epsilon[type]); + ebond += 4.0*epsilon[type]*sr6*(sr6-1.0) + epsilon[type]; } - // apply force to each of 2 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] += delx*fforce; - f[i1][1] += dely*fforce; - f[i1][2] += delz*fforce; + f[i1][0] += delx*fbond; + f[i1][1] += dely*fbond; + f[i1][2] += delz*fbond; } if (newton_bond || i2 < nlocal) { - f[i2][0] -= delx*fforce; - f[i2][1] -= dely*fforce; - f[i2][2] -= delz*fforce; + f[i2][0] -= delx*fbond; + f[i2][1] -= dely*fbond; + f[i2][2] -= delz*fbond; } - // virial contribution - - if (vflag) { - virial[0] += rfactor * delx*delx*fforce; - virial[1] += rfactor * dely*dely*fforce; - virial[2] += rfactor * delz*delz*fforce; - virial[3] += rfactor * delx*dely*fforce; - virial[4] += rfactor * delx*delz*fforce; - virial[5] += rfactor * dely*delz*fforce; - } + if (evflag) ev_tally(i1,i2,nlocal,newton_bond,ebond,fbond,delx,dely,delz); } } @@ -246,8 +228,7 @@ void BondFENEExpand::read_restart(FILE *fp) /* ---------------------------------------------------------------------- */ -void BondFENEExpand::single(int type, double rsq, int i, int j, - int eflag, double &fforce, double &eng) +void BondFENEExpand::single(int type, double rsq, int i, int j, double &eng) { double r = sqrt(rsq); double rshift = r - shift[type]; @@ -267,22 +248,11 @@ void BondFENEExpand::single(int type, double rsq, int i, int j, rlogarg = 0.1; } - fforce = -k[type]*rshift/rlogarg/r; - - // force from LJ term - - double sr2,sr6; + eng = -0.5 * k[type]*r0sq*log(rlogarg); if (rshiftsq < TWO_1_3*sigma[type]*sigma[type]) { + double sr2,sr6; sr2 = sigma[type]*sigma[type]/rshiftsq; sr6 = sr2*sr2*sr2; - fforce += 48.0*epsilon[type]*sr6*(sr6-0.5)/rshift/r; - } - - // energy - - if (eflag) { - eng = -0.5 * k[type]*r0sq*log(rlogarg); - if (rshiftsq < TWO_1_3*sigma[type]*sigma[type]) - eng += 4.0*epsilon[type]*sr6*(sr6-1.0) + epsilon[type]; + eng += 4.0*epsilon[type]*sr6*(sr6-1.0) + epsilon[type]; } } diff --git a/src/MOLECULE/bond_fene_expand.h b/src/MOLECULE/bond_fene_expand.h index 050cade586..6cf62e5d29 100644 --- a/src/MOLECULE/bond_fene_expand.h +++ b/src/MOLECULE/bond_fene_expand.h @@ -28,7 +28,7 @@ class BondFENEExpand : public Bond { double equilibrium_distance(int); void write_restart(FILE *); void read_restart(FILE *); - void single(int, double, int, int, int, double &, double &); + void single(int, double, int, int, double &); private: double TWO_1_3; diff --git a/src/MOLECULE/bond_harmonic.cpp b/src/MOLECULE/bond_harmonic.cpp index 16cad7d577..ade063db4b 100644 --- a/src/MOLECULE/bond_harmonic.cpp +++ b/src/MOLECULE/bond_harmonic.cpp @@ -43,11 +43,13 @@ BondHarmonic::~BondHarmonic() void BondHarmonic::compute(int eflag, int vflag) { - int i1,i2,n,type,factor; - double delx,dely,delz,rsq,r,dr,rk,fforce,rfactor; + int i1,i2,n,type; + double delx,dely,delz,ebond,fbond; + double rsq,r,dr,rk; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + ebond = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -57,19 +59,10 @@ void BondHarmonic::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nbondlist; n++) { - i1 = bondlist[n][0]; i2 = bondlist[n][1]; type = bondlist[n][2]; - if (newton_bond) factor = 2; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - } - rfactor = 0.5 * factor; - delx = x[i1][0] - x[i2][0]; dely = x[i1][1] - x[i2][1]; delz = x[i1][2] - x[i2][2]; @@ -82,35 +75,26 @@ void BondHarmonic::compute(int eflag, int vflag) // force & energy - if (r > 0.0) fforce = -2.0*rk/r; - else fforce = 0.0; + if (r > 0.0) fbond = -2.0*rk/r; + else fbond = 0.0; - if (eflag) energy += rfactor * rk*dr; + if (eflag) ebond = rk*dr; // apply force to each of 2 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] += delx*fforce; - f[i1][1] += dely*fforce; - f[i1][2] += delz*fforce; + f[i1][0] += delx*fbond; + f[i1][1] += dely*fbond; + f[i1][2] += delz*fbond; } if (newton_bond || i2 < nlocal) { - f[i2][0] -= delx*fforce; - f[i2][1] -= dely*fforce; - f[i2][2] -= delz*fforce; + f[i2][0] -= delx*fbond; + f[i2][1] -= dely*fbond; + f[i2][2] -= delz*fbond; } - // virial contribution - - if (vflag) { - virial[0] += rfactor*delx*delx*fforce; - virial[1] += rfactor*dely*dely*fforce; - virial[2] += rfactor*delz*delz*fforce; - virial[3] += rfactor*delx*dely*fforce; - virial[4] += rfactor*delx*delz*fforce; - virial[5] += rfactor*dely*delz*fforce; - } + if (evflag) ev_tally(i1,i2,nlocal,newton_bond,ebond,fbond,delx,dely,delz); } } @@ -193,16 +177,10 @@ void BondHarmonic::read_restart(FILE *fp) /* ---------------------------------------------------------------------- */ -void BondHarmonic::single(int type, double rsq, int i, int j, - int eflag, double &fforce, double &eng) +void BondHarmonic::single(int type, double rsq, int i, int j, double &eng) { double r = sqrt(rsq); double dr = r - r0[type]; double rk = k[type] * dr; - - // force & energy - - if (r > 0.0) fforce = -2.0*rk/r; - else fforce = 0.0; - if (eflag) eng = rk*dr; + eng = rk*dr; } diff --git a/src/MOLECULE/bond_harmonic.h b/src/MOLECULE/bond_harmonic.h index 5f282848a2..361493cfc7 100644 --- a/src/MOLECULE/bond_harmonic.h +++ b/src/MOLECULE/bond_harmonic.h @@ -28,7 +28,7 @@ class BondHarmonic : public Bond { double equilibrium_distance(int); void write_restart(FILE *); void read_restart(FILE *); - void single(int, double, int, int, int, double &, double &); + void single(int, double, int, int, double &); private: double *k,*r0; diff --git a/src/MOLECULE/bond_hybrid.cpp b/src/MOLECULE/bond_hybrid.cpp index cd34dc8c16..da3de7f21a 100644 --- a/src/MOLECULE/bond_hybrid.cpp +++ b/src/MOLECULE/bond_hybrid.cpp @@ -59,7 +59,7 @@ BondHybrid::~BondHybrid() void BondHybrid::compute(int eflag, int vflag) { - int i,m,n; + int i,j,m,n; // save ptrs to original bondlist @@ -95,23 +95,36 @@ void BondHybrid::compute(int eflag, int vflag) } // call each sub-style's compute function - // must set neighbor->bondlist to sub-style bondlist before call - // accumulate sub-style energy,virial in hybrid's energy,virial + // set neighbor->bondlist to sub-style bondlist before call + // accumulate sub-style global/peratom energy/virial in hybrid - energy = 0.0; - eng_vdwl = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; for (m = 0; m < nstyles; m++) { if (styles[m] == NULL) continue; neighbor->nbondlist = nbondlist[m]; neighbor->bondlist = bondlist[m]; + styles[m]->compute(eflag,vflag); - if (eflag) { - energy += styles[m]->energy; - eng_vdwl += styles[m]->eng_vdwl; + + if (eflag_global) energy += styles[m]->energy; + if (vflag_global) + for (n = 0; n < 6; n++) virial[n] += styles[m]->virial[n]; + if (eflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + double *eatom_substyle = styles[m]->eatom; + for (i = 0; i < n; i++) eatom[i] += eatom_substyle[i]; + } + if (vflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + double **vatom_substyle = styles[m]->vatom; + for (i = 0; i < n; i++) + for (j = 0; j < 6; j++) + vatom[i][j] += vatom_substyle[i][j]; } - if (vflag) for (n = 0; n < 6; n++) virial[n] += styles[m]->virial[n]; } // restore ptrs to original bondlist @@ -250,11 +263,9 @@ void BondHybrid::read_restart(FILE *fp) /* ---------------------------------------------------------------------- */ -void BondHybrid::single(int type, double rsq, int i, int j, - int eflag, double &fforce, double &eng) +void BondHybrid::single(int type, double rsq, int i, int j, double &eng) { - if (styles[map[type]]) - styles[map[type]]->single(type,rsq,i,j,eflag,fforce,eng); + if (styles[map[type]]) styles[map[type]]->single(type,rsq,i,j,eng); } /* ---------------------------------------------------------------------- @@ -263,7 +274,8 @@ void BondHybrid::single(int type, double rsq, int i, int j, double BondHybrid::memory_usage() { - double bytes = 0.0; + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); for (int m = 0; m < nstyles; m++) bytes += maxbond[m]*3 * sizeof(int); for (int m = 0; m < nstyles; m++) if (styles[m]) bytes += styles[m]->memory_usage(); diff --git a/src/MOLECULE/bond_morse.cpp b/src/MOLECULE/bond_morse.cpp index 44e161023c..c491962e00 100644 --- a/src/MOLECULE/bond_morse.cpp +++ b/src/MOLECULE/bond_morse.cpp @@ -48,11 +48,13 @@ BondMorse::~BondMorse() void BondMorse::compute(int eflag, int vflag) { - int i1,i2,n,type,factor; - double delx,dely,delz,rsq,r,dr,fforce,rfactor,ralpha; + int i1,i2,n,type; + double delx,dely,delz,ebond,fbond; + double rsq,r,dr,ralpha; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + ebond = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -62,19 +64,10 @@ void BondMorse::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nbondlist; n++) { - i1 = bondlist[n][0]; i2 = bondlist[n][1]; type = bondlist[n][2]; - if (newton_bond) factor = 2; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - } - rfactor = 0.5 * factor; - delx = x[i1][0] - x[i2][0]; dely = x[i1][1] - x[i2][1]; delz = x[i1][2] - x[i2][2]; @@ -87,35 +80,26 @@ void BondMorse::compute(int eflag, int vflag) // force & energy - if (r > 0.0) fforce = -2.0*d0[type]*alpha[type]*(1-ralpha)*ralpha/r; - else fforce = 0.0; + if (r > 0.0) fbond = -2.0*d0[type]*alpha[type]*(1-ralpha)*ralpha/r; + else fbond = 0.0; - if (eflag) energy += rfactor * d0[type]*(1-ralpha)*(1-ralpha); + if (eflag) ebond = d0[type]*(1-ralpha)*(1-ralpha); // apply force to each of 2 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] += delx*fforce; - f[i1][1] += dely*fforce; - f[i1][2] += delz*fforce; + f[i1][0] += delx*fbond; + f[i1][1] += dely*fbond; + f[i1][2] += delz*fbond; } if (newton_bond || i2 < nlocal) { - f[i2][0] -= delx*fforce; - f[i2][1] -= dely*fforce; - f[i2][2] -= delz*fforce; + f[i2][0] -= delx*fbond; + f[i2][1] -= dely*fbond; + f[i2][2] -= delz*fbond; } - // virial contribution - - if (vflag) { - virial[0] += rfactor*delx*delx*fforce; - virial[1] += rfactor*dely*dely*fforce; - virial[2] += rfactor*delz*delz*fforce; - virial[3] += rfactor*delx*dely*fforce; - virial[4] += rfactor*delx*delz*fforce; - virial[5] += rfactor*dely*delz*fforce; - } + if (evflag) ev_tally(i1,i2,nlocal,newton_bond,ebond,fbond,delx,dely,delz); } } @@ -203,16 +187,10 @@ void BondMorse::read_restart(FILE *fp) /* ---------------------------------------------------------------------- */ -void BondMorse::single(int type, double rsq, int i, int j, - int eflag, double &fforce, double &eng) +void BondMorse::single(int type, double rsq, int i, int j, double &eng) { double r = sqrt(rsq); double dr = r - r0[type]; double ralpha = exp(-alpha[type]*dr); - - // force & energy - - if (r > 0.0) fforce = -2.0*d0[type]*alpha[type]*(1-ralpha)*ralpha/r; - else fforce = 0.0; - if (eflag) eng = d0[type]*(1-ralpha)*(1-ralpha); + eng = d0[type]*(1-ralpha)*(1-ralpha); } diff --git a/src/MOLECULE/bond_morse.h b/src/MOLECULE/bond_morse.h index 790c93e234..3d5625c3b8 100644 --- a/src/MOLECULE/bond_morse.h +++ b/src/MOLECULE/bond_morse.h @@ -28,7 +28,7 @@ class BondMorse : public Bond { double equilibrium_distance(int); void write_restart(FILE *); void read_restart(FILE *); - void single(int, double, int, int, int, double &, double &); + void single(int, double, int, int, double &); private: double *d0,*alpha,*r0; diff --git a/src/MOLECULE/bond_nonlinear.cpp b/src/MOLECULE/bond_nonlinear.cpp index ef873b85c8..2979ba0b28 100644 --- a/src/MOLECULE/bond_nonlinear.cpp +++ b/src/MOLECULE/bond_nonlinear.cpp @@ -44,11 +44,13 @@ BondNonlinear::~BondNonlinear() void BondNonlinear::compute(int eflag, int vflag) { - int i1,i2,n,type,factor; - double delx,dely,delz,rsq,r,dr,drsq,lamdasq,denom,denomsq,fforce,rfactor; + int i1,i2,n,type; + double delx,dely,delz,ebond,fbond; + double rsq,r,dr,drsq,lamdasq,denom,denomsq; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + ebond = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -58,19 +60,10 @@ void BondNonlinear::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nbondlist; n++) { - i1 = bondlist[n][0]; i2 = bondlist[n][1]; type = bondlist[n][2]; - if (newton_bond) factor = 2; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - } - rfactor = 0.5 * factor; - delx = x[i1][0] - x[i2][0]; dely = x[i1][1] - x[i2][1]; delz = x[i1][2] - x[i2][2]; @@ -86,33 +79,24 @@ void BondNonlinear::compute(int eflag, int vflag) // force & energy - fforce = -epsilon[type]/r * 2.0*dr*lamdasq/denomsq; - if (eflag) energy += rfactor * epsilon[type] * drsq / denom; + fbond = -epsilon[type]/r * 2.0*dr*lamdasq/denomsq; + if (eflag) ebond = epsilon[type] * drsq / denom; // apply force to each of 2 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] += delx*fforce; - f[i1][1] += dely*fforce; - f[i1][2] += delz*fforce; + f[i1][0] += delx*fbond; + f[i1][1] += dely*fbond; + f[i1][2] += delz*fbond; } if (newton_bond || i2 < nlocal) { - f[i2][0] -= delx*fforce; - f[i2][1] -= dely*fforce; - f[i2][2] -= delz*fforce; + f[i2][0] -= delx*fbond; + f[i2][1] -= dely*fbond; + f[i2][2] -= delz*fbond; } - // virial contribution - - if (vflag) { - virial[0] += rfactor*delx*delx*fforce; - virial[1] += rfactor*dely*dely*fforce; - virial[2] += rfactor*delz*delz*fforce; - virial[3] += rfactor*delx*dely*fforce; - virial[4] += rfactor*delx*delz*fforce; - virial[5] += rfactor*dely*delz*fforce; - } + if (evflag) ev_tally(i1,i2,nlocal,newton_bond,ebond,fbond,delx,dely,delz); } } @@ -198,18 +182,12 @@ void BondNonlinear::read_restart(FILE *fp) /* ---------------------------------------------------------------------- */ -void BondNonlinear::single(int type, double rsq, int i, int j, - int eflag, double &fforce, double &eng) +void BondNonlinear::single(int type, double rsq, int i, int j, double &eng) { double r = sqrt(rsq); double dr = r - r0[type]; double drsq = dr*dr; double lamdasq = lamda[type]*lamda[type]; double denom = lamdasq - drsq; - double denomsq = denom*denom; - - // force & energy - - fforce = -epsilon[type]/r * 2.0*dr*lamdasq/denomsq; - if (eflag) eng = epsilon[type] * drsq / denom; + eng = epsilon[type] * drsq / denom; } diff --git a/src/MOLECULE/bond_nonlinear.h b/src/MOLECULE/bond_nonlinear.h index eb618b7e52..9238d1ae3f 100644 --- a/src/MOLECULE/bond_nonlinear.h +++ b/src/MOLECULE/bond_nonlinear.h @@ -28,7 +28,7 @@ class BondNonlinear : public Bond { double equilibrium_distance(int); void write_restart(FILE *); void read_restart(FILE *); - void single(int, double, int, int, int, double &, double &); + void single(int, double, int, int, double &); private: double *epsilon,*r0,*lamda; diff --git a/src/MOLECULE/bond_quartic.cpp b/src/MOLECULE/bond_quartic.cpp index 92ebb87f47..e1072baf42 100755 --- a/src/MOLECULE/bond_quartic.cpp +++ b/src/MOLECULE/bond_quartic.cpp @@ -55,13 +55,19 @@ BondQuartic::~BondQuartic() void BondQuartic::compute(int eflag, int vflag) { - int i1,i2,n,m,type,factor,itype,jtype; - double delx,dely,delz,r,rsq,dr,r2,ra,rb,fforce,sr2,sr6,rfactor; + int i1,i2,n,m,type,itype,jtype; + double delx,dely,delz,ebond,fbond,evdwl,fpair; + double r,rsq,dr,r2,ra,rb,sr2,sr6; Pair::One one; - energy = 0.0; - eng_vdwl = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + ebond = evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; + + // insure pair->ev_tally() will use bond virial contribution + + if (vflag_global == 2) + force->pair->vflag_either = force->pair->vflag_global = 1; double **cutsq = force->pair->cutsq; double **x = atom->x; @@ -81,14 +87,6 @@ void BondQuartic::compute(int eflag, int vflag) i2 = bondlist[n][1]; type = bondlist[n][2]; - if (newton_bond) factor = 2; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - } - rfactor = 0.5*factor; - delx = x[i1][0] - x[i2][0]; dely = x[i1][1] - x[i2][1]; delz = x[i1][2] - x[i2][2]; @@ -114,18 +112,6 @@ void BondQuartic::compute(int eflag, int vflag) continue; } - // subtract out pairwise contribution from 2 atoms via pair->single() - // required since special_bond = 1,1,1 - - itype = atom->type[i1]; - jtype = atom->type[i2]; - - if (rsq < cutsq[itype][jtype]) { - force->pair->single(i1,i2,itype,jtype,rsq,1.0,1.0,eflag,one); - fforce = -one.fforce; - if (eflag) eng_vdwl -= one.eng_vdwl + one.eng_coul; - } else fforce = 0.0; - // quartic bond // 1st portion is from quartic term // 2nd portion is from LJ term cut at 2^(1/6) with eps = sigma = 1.0 @@ -135,42 +121,60 @@ void BondQuartic::compute(int eflag, int vflag) r2 = dr*dr; ra = dr - b1[type]; rb = dr - b2[type]; - fforce += -k[type]/r * (r2*(ra+rb) + 2.0*dr*ra*rb); + fbond = -k[type]/r * (r2*(ra+rb) + 2.0*dr*ra*rb); if (rsq < TWO_1_3) { sr2 = 1.0/rsq; sr6 = sr2*sr2*sr2; - fforce += 48.0*sr6*(sr6-0.5)/rsq; + fbond += 48.0*sr6*(sr6-0.5)/rsq; } if (eflag) { - energy += rfactor*(k[type]*r2*ra*rb + u0[type]); - if (rsq < TWO_1_3) energy += rfactor * (4.0*sr6*(sr6-1.0) + 1.0); + ebond = k[type]*r2*ra*rb + u0[type]; + if (rsq < TWO_1_3) ebond += 4.0*sr6*(sr6-1.0) + 1.0; } // apply force to each of 2 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] += delx*fforce; - f[i1][1] += dely*fforce; - f[i1][2] += delz*fforce; + f[i1][0] += delx*fbond; + f[i1][1] += dely*fbond; + f[i1][2] += delz*fbond; } if (newton_bond || i2 < nlocal) { - f[i2][0] -= delx*fforce; - f[i2][1] -= dely*fforce; - f[i2][2] -= delz*fforce; + f[i2][0] -= delx*fbond; + f[i2][1] -= dely*fbond; + f[i2][2] -= delz*fbond; } - // virial contribution + if (evflag) ev_tally(i1,i2,nlocal,newton_bond,ebond,fbond,delx,dely,delz); - if (vflag) { - virial[0] += rfactor * delx*delx*fforce; - virial[1] += rfactor * dely*dely*fforce; - virial[2] += rfactor * delz*delz*fforce; - virial[3] += rfactor * delx*dely*fforce; - virial[4] += rfactor * delx*delz*fforce; - virial[5] += rfactor * dely*delz*fforce; + // subtract out pairwise contribution from 2 atoms via pair->single() + // required since special_bond = 1,1,1 + // tally energy/virial in pair, using newton_bond as newton flag + + itype = atom->type[i1]; + jtype = atom->type[i2]; + + if (rsq < cutsq[itype][jtype]) { + force->pair->single(i1,i2,itype,jtype,rsq,1.0,1.0,eflag,one); + fpair = -one.fforce; + if (eflag) evdwl = -(one.eng_vdwl + one.eng_coul); + + if (newton_bond || i1 < nlocal) { + f[i1][0] += delx*fpair; + f[i1][1] += dely*fpair; + f[i1][2] += delz*fpair; + } + if (newton_bond || i2 < nlocal) { + f[i2][0] -= delx*fpair; + f[i2][1] -= dely*fpair; + f[i2][2] -= delz*fpair; + } + + if (evflag) force->pair->ev_tally(i1,i2,nlocal,newton_bond, + evdwl,0.0,fpair,delx,dely,delz); } } } @@ -295,12 +299,11 @@ void BondQuartic::read_restart(FILE *fp) /* ---------------------------------------------------------------------- */ -void BondQuartic::single(int type, double rsq, int i, int j, - int eflag, double &fforce, double &eng) +void BondQuartic::single(int type, double rsq, int i, int j, double &eng) { double r,dr,r2,ra,rb,sr2,sr6; - fforce = eng = 0.0; + eng = 0.0; if (type <= 0) return; // subtract out pairwise contribution from 2 atoms via pair->single() @@ -311,9 +314,8 @@ void BondQuartic::single(int type, double rsq, int i, int j, if (rsq < force->pair->cutsq[itype][jtype]) { Pair::One one; - force->pair->single(i,j,itype,jtype,rsq,1.0,1.0,eflag,one); - fforce = -one.fforce; - if (eflag) eng = -one.eng_coul - one.eng_vdwl; + force->pair->single(i,j,itype,jtype,rsq,1.0,1.0,1,one); + eng = -one.eng_coul - one.eng_vdwl; } // quartic bond @@ -325,16 +327,11 @@ void BondQuartic::single(int type, double rsq, int i, int j, r2 = dr*dr; ra = dr - b1[type]; rb = dr - b2[type]; - fforce += -k[type]/r * (r2*(ra+rb) + 2.0*dr*ra*rb); - + + eng += k[type]*r2*ra*rb + u0[type]; if (rsq < TWO_1_3) { sr2 = 1.0/rsq; sr6 = sr2*sr2*sr2; - fforce += 48.0*sr6*(sr6-0.5)/rsq; - } - - if (eflag) { - eng += k[type]*r2*ra*rb + u0[type]; - if (rsq < TWO_1_3) eng += 4.0*sr6*(sr6-1.0) + 1.0; + eng += 4.0*sr6*(sr6-1.0) + 1.0; } } diff --git a/src/MOLECULE/bond_quartic.h b/src/MOLECULE/bond_quartic.h index b33bcca744..5fae223787 100644 --- a/src/MOLECULE/bond_quartic.h +++ b/src/MOLECULE/bond_quartic.h @@ -29,7 +29,7 @@ class BondQuartic : public Bond { double equilibrium_distance(int); void write_restart(FILE *); void read_restart(FILE *); - void single(int, double, int, int, int, double &, double &); + void single(int, double, int, int, double &); private: double TWO_1_3; diff --git a/src/MOLECULE/dihedral.cpp b/src/MOLECULE/dihedral.cpp index d523aa2754..8f8c700e08 100644 --- a/src/MOLECULE/dihedral.cpp +++ b/src/MOLECULE/dihedral.cpp @@ -14,6 +14,10 @@ #include "math.h" #include "dihedral.h" #include "atom.h" +#include "atom.h" +#include "force.h" +#include "pair.h" +#include "memory.h" #include "error.h" using namespace LAMMPS_NS; @@ -25,9 +29,22 @@ using namespace LAMMPS_NS; Dihedral::Dihedral(LAMMPS *lmp) : Pointers(lmp) { + energy = 0.0; + allocated = 0; - eng_vdwl = eng_coul = 0.0; PI = 4.0*atan(1.0); + + maxeatom = maxvatom = 0; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +Dihedral::~Dihedral() +{ + memory->sfree(eatom); + memory->destroy_2d_double_array(vatom); } /* ---------------------------------------------------------------------- @@ -42,3 +59,191 @@ void Dihedral::init() init_style(); } +/* ---------------------------------------------------------------------- + setup for energy, virial computation + see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) +------------------------------------------------------------------------- */ + +void Dihedral::ev_setup(int eflag, int vflag) +{ + int i,n; + + evflag = 1; + + eflag_either = eflag; + eflag_global = eflag % 2; + eflag_atom = eflag / 2; + + vflag_either = vflag; + vflag_global = vflag % 4; + vflag_atom = vflag / 4; + + // reallocate per-atom arrays if necessary + + if (eflag_atom && atom->nmax > maxeatom) { + maxeatom = atom->nmax; + memory->sfree(eatom); + eatom = (double *) memory->smalloc(maxeatom*sizeof(double),"bond:eatom"); + } + if (vflag_atom && atom->nmax > maxvatom) { + maxvatom = atom->nmax; + memory->destroy_2d_double_array(vatom); + vatom = memory->create_2d_double_array(maxvatom,6,"bond:vatom"); + } + + // zero accumulators + + if (eflag_global) energy = 0.0; + if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0; + if (eflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + for (i = 0; i < n; i++) eatom[i] = 0.0; + } + if (vflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + for (i = 0; i < n; i++) { + vatom[i][0] = 0.0; + vatom[i][1] = 0.0; + vatom[i][2] = 0.0; + vatom[i][3] = 0.0; + vatom[i][4] = 0.0; + vatom[i][5] = 0.0; + } + } +} + +/* ---------------------------------------------------------------------- + tally energy and virial into global and per-atom accumulators + virial = r1F1 + r2F2 + r3F3 + r4F4 = (r1-r2) F1 + (r3-r2) F3 + (r4-r2) F4 + = (r1-r2) F1 + (r3-r2) F3 + (r4-r3 + r3-r2) F4 + = vb1*f1 + vb2*f3 + (vb3+vb2)*f4 +------------------------------------------------------------------------- */ + +void Dihedral::ev_tally(int i1, int i2, int i3, int i4, + int nlocal, int newton_bond, + double edihedral, double *f1, double *f3, double *f4, + double vb1x, double vb1y, double vb1z, + double vb2x, double vb2y, double vb2z, + double vb3x, double vb3y, double vb3z) +{ + double edihedralquarter,v[6]; + + if (eflag_either) { + if (eflag_global) { + if (newton_bond) energy += edihedral; + else { + edihedralquarter = 0.25*edihedral; + if (i1 < nlocal) energy += edihedralquarter; + if (i2 < nlocal) energy += edihedralquarter; + if (i3 < nlocal) energy += edihedralquarter; + if (i4 < nlocal) energy += edihedralquarter; + } + } + if (eflag_atom) { + edihedralquarter = 0.25*edihedral; + if (newton_bond || i1 < nlocal) eatom[i1] += edihedralquarter; + if (newton_bond || i2 < nlocal) eatom[i2] += edihedralquarter; + if (newton_bond || i3 < nlocal) eatom[i3] += edihedralquarter; + if (newton_bond || i4 < nlocal) eatom[i4] += edihedralquarter; + } + } + + if (vflag_either) { + v[0] = vb1x*f1[0] + vb2x*f3[0] + (vb3x+vb2x)*f4[0]; + v[1] = vb1y*f1[1] + vb2y*f3[1] + (vb3y+vb2y)*f4[1]; + v[2] = vb1z*f1[2] + vb2z*f3[2] + (vb3z+vb2z)*f4[2]; + v[3] = vb1x*f1[1] + vb2x*f3[1] + (vb3x+vb2x)*f4[1]; + v[4] = vb1x*f1[2] + vb2x*f3[2] + (vb3x+vb2x)*f4[2]; + v[5] = vb1y*f1[2] + vb2y*f3[2] + (vb3y+vb2y)*f4[2]; + + if (vflag_global) { + if (newton_bond) { + virial[0] += v[0]; + virial[1] += v[1]; + virial[2] += v[2]; + virial[3] += v[3]; + virial[4] += v[4]; + virial[5] += v[5]; + } else { + if (i1 < nlocal) { + virial[0] += 0.25*v[0]; + virial[1] += 0.25*v[1]; + virial[2] += 0.25*v[2]; + virial[3] += 0.25*v[3]; + virial[4] += 0.25*v[4]; + virial[5] += 0.25*v[5]; + } + if (i2 < nlocal) { + virial[0] += 0.25*v[0]; + virial[1] += 0.25*v[1]; + virial[2] += 0.25*v[2]; + virial[3] += 0.25*v[3]; + virial[4] += 0.25*v[4]; + virial[5] += 0.25*v[5]; + } + if (i3 < nlocal) { + virial[0] += 0.25*v[0]; + virial[1] += 0.25*v[1]; + virial[2] += 0.25*v[2]; + virial[3] += 0.25*v[3]; + virial[4] += 0.25*v[4]; + virial[5] += 0.25*v[5]; + } + if (i4 < nlocal) { + virial[0] += 0.25*v[0]; + virial[1] += 0.25*v[1]; + virial[2] += 0.25*v[2]; + virial[3] += 0.25*v[3]; + virial[4] += 0.25*v[4]; + virial[5] += 0.25*v[5]; + } + } + } + + if (vflag_atom) { + if (newton_bond || i1 < nlocal) { + vatom[i1][0] += 0.25*v[0]; + vatom[i1][1] += 0.25*v[1]; + vatom[i1][2] += 0.25*v[2]; + vatom[i1][3] += 0.25*v[3]; + vatom[i1][4] += 0.25*v[4]; + vatom[i1][5] += 0.25*v[5]; + } + if (newton_bond || i2 < nlocal) { + vatom[i2][0] += 0.25*v[0]; + vatom[i2][1] += 0.25*v[1]; + vatom[i2][2] += 0.25*v[2]; + vatom[i2][3] += 0.25*v[3]; + vatom[i2][4] += 0.25*v[4]; + vatom[i2][5] += 0.25*v[5]; + } + if (newton_bond || i3 < nlocal) { + vatom[i3][0] += 0.25*v[0]; + vatom[i3][1] += 0.25*v[1]; + vatom[i3][2] += 0.25*v[2]; + vatom[i3][3] += 0.25*v[3]; + vatom[i3][4] += 0.25*v[4]; + vatom[i3][5] += 0.25*v[5]; + } + if (newton_bond || i4 < nlocal) { + vatom[i4][0] += 0.25*v[0]; + vatom[i4][1] += 0.25*v[1]; + vatom[i4][2] += 0.25*v[2]; + vatom[i4][3] += 0.25*v[3]; + vatom[i4][4] += 0.25*v[4]; + vatom[i4][5] += 0.25*v[5]; + } + } + } +} + +/* ---------------------------------------------------------------------- */ + +double Dihedral::memory_usage() +{ + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); + return bytes; +} diff --git a/src/MOLECULE/dihedral_charmm.cpp b/src/MOLECULE/dihedral_charmm.cpp index b17f1fa2d1..339456ccb7 100644 --- a/src/MOLECULE/dihedral_charmm.cpp +++ b/src/MOLECULE/dihedral_charmm.cpp @@ -57,21 +57,25 @@ DihedralCharmm::~DihedralCharmm() void DihedralCharmm::compute(int eflag, int vflag) { - int i,m,n,i1,i2,i3,i4,type,factor; - double rfactor; - double vb1x,vb1y,vb1z,vb2x,vb2y; - double vb2z,vb2xm,vb2ym,vb2zm,vb3x,vb3y,vb3z; + int i1,i2,i3,i4,i,m,n,type; + double vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z,vb2xm,vb2ym,vb2zm; + double edihedral,f1[3],f2[3],f3[3],f4[3]; double ax,ay,az,bx,by,bz,rasq,rbsq,rgsq,rg,rginv,ra2inv,rb2inv,rabinv; double df,df1,ddf1,fg,hg,fga,hgb,gaa,gbb; double dtfx,dtfy,dtfz,dtgx,dtgy,dtgz,dthx,dthy,dthz; - double c,s,p,sx1,sx2,sx12,sy1,sy2,sy12,sz1,sz2,sz12; + double c,s,p,sx2,sy2,sz2; int itype,jtype; double delx,dely,delz,rsq,r2inv,r6inv; - double fforce,forcecoul,forcelj,phicoul,philj; + double forcecoul,forcelj,fpair,ecoul,evdwl; - energy = 0.0; - eng_coul = eng_vdwl = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + edihedral = evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; + + // insure pair->ev_tally() will use 1-4 virial contribution + + if (vflag_global == 2) + force->pair->vflag_either = force->pair->vflag_global = 1; double **x = atom->x; double **f = atom->f; @@ -84,23 +88,12 @@ void DihedralCharmm::compute(int eflag, int vflag) double qqrd2e = force->qqrd2e; for (n = 0; n < ndihedrallist; n++) { - i1 = dihedrallist[n][0]; i2 = dihedrallist[n][1]; i3 = dihedrallist[n][2]; i4 = dihedrallist[n][3]; type = dihedrallist[n][4]; - if (newton_bond) factor = 4; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - if (i4 < nlocal) factor++; - } - rfactor = 0.25 * factor; - // 1st bond vb1x = x[i1][0] - x[i2][0]; @@ -191,7 +184,7 @@ void DihedralCharmm::compute(int eflag, int vflag) df1 = 0.0; } - if (eflag) energy += rfactor * k[type] * p; + if (eflag) edihedral = k[type] * p; fg = vb1x*vb2xm + vb1y*vb2ym + vb1z*vb2zm; hg = vb3x*vb2xm + vb3y*vb2ym + vb3z*vb2zm; @@ -210,60 +203,62 @@ void DihedralCharmm::compute(int eflag, int vflag) dthy = gbb*by; dthz = gbb*bz; - df = k[type] * df1; - - sx1 = df*dtfx; - sy1 = df*dtfy; - sz1 = df*dtfz; - sx2 = -df*dtgx; - sy2 = -df*dtgy; - sz2 = -df*dtgz; - sx12 = df*dthx; - sy12 = df*dthy; - sz12 = df*dthz; - + df = -k[type] * df1; + + sx2 = df*dtgx; + sy2 = df*dtgy; + sz2 = df*dtgz; + + f1[0] = df*dtfx; + f1[1] = df*dtfy; + f1[2] = df*dtfz; + + f2[0] = sx2 - f1[0]; + f2[1] = sy2 - f1[1]; + f2[2] = sz2 - f1[2]; + + f4[0] = df*dthx; + f4[1] = df*dthy; + f4[2] = df*dthz; + + f3[0] = -sx2 - f4[0]; + f3[1] = -sy2 - f4[1]; + f3[2] = -sz2 - f4[2]; + // apply force to each of 4 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= sx1; - f[i1][1] -= sy1; - f[i1][2] -= sz1; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += sx2 + sx1; - f[i2][1] += sy2 + sy1; - f[i2][2] += sz2 + sz1; + f[i2][0] += f2[0]; + f[i2][1] += f2[1]; + f[i2][2] += f2[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] += sx12 - sx2; - f[i3][1] += sy12 - sy2; - f[i3][2] += sz12 - sz2; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } if (newton_bond || i4 < nlocal) { - f[i4][0] -= sx12; - f[i4][1] -= sy12; - f[i4][2] -= sz12; + f[i4][0] += f4[0]; + f[i4][1] += f4[1]; + f[i4][2] += f4[2]; } - // virial contribution - - if (vflag) { - virial[0] -= rfactor * (vb1x*sx1 + vb2x*sx2 + vb3x*sx12); - virial[1] -= rfactor * (vb1y*sy1 + vb2y*sy2 + vb3y*sy12); - virial[2] -= rfactor * (vb1z*sz1 + vb2z*sz2 + vb3z*sz12); - virial[3] -= rfactor * (vb1x*sy1 + vb2x*sy2 + vb3x*sy12); - virial[4] -= rfactor * (vb1x*sz1 + vb2x*sz2 + vb3x*sz12); - virial[5] -= rfactor * (vb1y*sz1 + vb2y*sz2 + vb3y*sz12); - } + if (evflag) + ev_tally(i1,i2,i3,i4,nlocal,newton_bond,edihedral,f1,f3,f4, + vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); // 1-4 LJ and Coulomb interactions - // force, energy, and virial + // tally energy/virial in pair, using newton_bond as newton flag if (weight[type] > 0.0) { - itype = atomtype[i1]; jtype = atomtype[i4]; @@ -278,35 +273,27 @@ void DihedralCharmm::compute(int eflag, int vflag) if (implicit) forcecoul = qqrd2e * q[i1]*q[i4]*r2inv; else forcecoul = qqrd2e * q[i1]*q[i4]*sqrt(r2inv); forcelj = r6inv * (lj14_1[itype][jtype]*r6inv - lj14_2[itype][jtype]); - fforce = weight[type] * (forcelj+forcecoul)*r2inv; + fpair = weight[type] * (forcelj+forcecoul)*r2inv; if (eflag) { - phicoul = weight[type] * rfactor * forcecoul; - philj = r6inv * (lj14_3[itype][jtype]*r6inv - lj14_4[itype][jtype]); - philj = weight[type] * rfactor * philj; - eng_coul += phicoul; - eng_vdwl += philj; + ecoul = weight[type] * forcecoul; + evdwl = r6inv * (lj14_3[itype][jtype]*r6inv - lj14_4[itype][jtype]); + evdwl *= weight[type]; } if (newton_bond || i1 < nlocal) { - f[i1][0] += delx*fforce; - f[i1][1] += dely*fforce; - f[i1][2] += delz*fforce; + f[i1][0] += delx*fpair; + f[i1][1] += dely*fpair; + f[i1][2] += delz*fpair; } if (newton_bond || i4 < nlocal) { - f[i4][0] -= delx*fforce; - f[i4][1] -= dely*fforce; - f[i4][2] -= delz*fforce; + f[i4][0] -= delx*fpair; + f[i4][1] -= dely*fpair; + f[i4][2] -= delz*fpair; } - if (vflag) { - virial[0] += rfactor * delx*delx*fforce; - virial[1] += rfactor * dely*dely*fforce; - virial[2] += rfactor * delz*delz*fforce; - virial[3] += rfactor * delx*dely*fforce; - virial[4] += rfactor * delx*delz*fforce; - virial[5] += rfactor * dely*delz*fforce; - } + if (evflag) force->pair->ev_tally(i1,i4,nlocal,newton_bond, + evdwl,ecoul,fpair,delx,dely,delz); } } } diff --git a/src/MOLECULE/dihedral_harmonic.cpp b/src/MOLECULE/dihedral_harmonic.cpp index 4b7fe113b8..bcb43a1331 100644 --- a/src/MOLECULE/dihedral_harmonic.cpp +++ b/src/MOLECULE/dihedral_harmonic.cpp @@ -55,17 +55,17 @@ DihedralHarmonic::~DihedralHarmonic() void DihedralHarmonic::compute(int eflag, int vflag) { - int i,m,n,i1,i2,i3,i4,type,factor; - double rfactor; - double vb1x,vb1y,vb1z,vb2x,vb2y; - double vb2z,vb2xm,vb2ym,vb2zm,vb3x,vb3y,vb3z; + int i1,i2,i3,i4,i,m,n,type; + double vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z,vb2xm,vb2ym,vb2zm; + double edihedral,f1[3],f2[3],f3[3],f4[3]; double ax,ay,az,bx,by,bz,rasq,rbsq,rgsq,rg,rginv,ra2inv,rb2inv,rabinv; double df,df1,ddf1,fg,hg,fga,hgb,gaa,gbb; double dtfx,dtfy,dtfz,dtgx,dtgy,dtgz,dthx,dthy,dthz; - double c,s,p,sx1,sx2,sx12,sy1,sy2,sy12,sz1,sz2,sz12; + double c,s,p,sx2,sy2,sz2; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + edihedral = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -75,23 +75,12 @@ void DihedralHarmonic::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < ndihedrallist; n++) { - i1 = dihedrallist[n][0]; i2 = dihedrallist[n][1]; i3 = dihedrallist[n][2]; i4 = dihedrallist[n][3]; type = dihedrallist[n][4]; - if (newton_bond) factor = 4; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - if (i4 < nlocal) factor++; - } - rfactor = 0.25 * factor; - // 1st bond vb1x = x[i1][0] - x[i2][0]; @@ -184,7 +173,7 @@ void DihedralHarmonic::compute(int eflag, int vflag) df1 = 0.0; } - if (eflag) energy += rfactor * k[type] * p; + if (eflag) edihedral = k[type] * p; fg = vb1x*vb2xm + vb1y*vb2ym + vb1z*vb2zm; hg = vb3x*vb2xm + vb3y*vb2ym + vb3z*vb2zm; @@ -203,54 +192,57 @@ void DihedralHarmonic::compute(int eflag, int vflag) dthy = gbb*by; dthz = gbb*bz; - df = k[type] * df1; + df = -k[type] * df1; - sx1 = df*dtfx; - sy1 = df*dtfy; - sz1 = df*dtfz; - sx2 = -df*dtgx; - sy2 = -df*dtgy; - sz2 = -df*dtgz; - sx12 = df*dthx; - sy12 = df*dthy; - sz12 = df*dthz; + sx2 = df*dtgx; + sy2 = df*dtgy; + sz2 = df*dtgz; + + f1[0] = df*dtfx; + f1[1] = df*dtfy; + f1[2] = df*dtfz; + + f2[0] = sx2 - f1[0]; + f2[1] = sy2 - f1[1]; + f2[2] = sz2 - f1[2]; + + f4[0] = df*dthx; + f4[1] = df*dthy; + f4[2] = df*dthz; + + f3[0] = -sx2 - f4[0]; + f3[1] = -sy2 - f4[1]; + f3[2] = -sz2 - f4[2]; // apply force to each of 4 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= sx1; - f[i1][1] -= sy1; - f[i1][2] -= sz1; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += sx2 + sx1; - f[i2][1] += sy2 + sy1; - f[i2][2] += sz2 + sz1; + f[i2][0] += f2[0]; + f[i2][1] += f2[1]; + f[i2][2] += f2[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] += sx12 - sx2; - f[i3][1] += sy12 - sy2; - f[i3][2] += sz12 - sz2; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } if (newton_bond || i4 < nlocal) { - f[i4][0] -= sx12; - f[i4][1] -= sy12; - f[i4][2] -= sz12; + f[i4][0] += f4[0]; + f[i4][1] += f4[1]; + f[i4][2] += f4[2]; } - // virial contribution - - if (vflag) { - virial[0] -= rfactor * (vb1x*sx1 + vb2x*sx2 + vb3x*sx12); - virial[1] -= rfactor * (vb1y*sy1 + vb2y*sy2 + vb3y*sy12); - virial[2] -= rfactor * (vb1z*sz1 + vb2z*sz2 + vb3z*sz12); - virial[3] -= rfactor * (vb1x*sy1 + vb2x*sy2 + vb3x*sy12); - virial[4] -= rfactor * (vb1x*sz1 + vb2x*sz2 + vb3x*sz12); - virial[5] -= rfactor * (vb1y*sz1 + vb2y*sz2 + vb3y*sz12); - } + if (evflag) + ev_tally(i1,i2,i3,i4,nlocal,newton_bond,edihedral,f1,f3,f4, + vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); } } diff --git a/src/MOLECULE/dihedral_helix.cpp b/src/MOLECULE/dihedral_helix.cpp index a7e069e88c..f3adbb0f6a 100644 --- a/src/MOLECULE/dihedral_helix.cpp +++ b/src/MOLECULE/dihedral_helix.cpp @@ -58,18 +58,18 @@ DihedralHelix::~DihedralHelix() void DihedralHelix::compute(int eflag, int vflag) { - int n,i1,i2,i3,i4,type,factor; - double rfactor; - double vb1x,vb1y,vb1z,vb2x,vb2y; - double vb2z,vb2xm,vb2ym,vb2zm,vb3x,vb3y,vb3z,sb1; - double sb2,sb3,rb1,rb3,c0,b1mag2,b1mag,b2mag2; + int i1,i2,i3,i4,n,type; + double vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z,vb2xm,vb2ym,vb2zm; + double edihedral,f1[3],f2[3],f3[3],f4[3]; + double sb1,sb2,sb3,rb1,rb3,c0,b1mag2,b1mag,b2mag2; double b2mag,b3mag2,b3mag,ctmp,r12c1,c1mag,r12c2; double c2mag,sc1,sc2,s1,s12,c,p,pd,a,a11,a22; - double a33,a12,a13,a23,sx1,sx2,sx12,sy1,sy2,sy12; - double sz1,sz2,sz12,s2,cx,cy,cz,cmag,dx,phi,si,siinv,sin2; + double a33,a12,a13,a23,sx2,sy2,sz2; + double s2,cx,cy,cz,cmag,dx,phi,si,siinv,sin2; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + edihedral = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -79,23 +79,12 @@ void DihedralHelix::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < ndihedrallist; n++) { - i1 = dihedrallist[n][0]; i2 = dihedrallist[n][1]; i3 = dihedrallist[n][2]; i4 = dihedrallist[n][3]; type = dihedrallist[n][4]; - if (newton_bond) factor = 4; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - if (i4 < nlocal) factor++; - } - rfactor = 0.25 * factor; - // 1st bond vb1x = x[i1][0] - x[i2][0]; @@ -207,64 +196,67 @@ void DihedralHelix::compute(int eflag, int vflag) pd = -aphi[type] + 3.0*bphi[type]*sin(3.0*phi)*siinv + cphi[type]*sin(phi + 0.25*PI)*siinv; - if (eflag) energy += rfactor * p; + if (eflag) edihedral = p; a = pd; c = c * a; s12 = s12 * a; - a11 = -c*sb1*s1; - a22 = sb2 * (2.0*c0*s12 - c*(s1+s2)); - a33 = -c*sb3*s2; - a12 = r12c1 * (c1mag*c*s1 + c2mag*s12); - a13 = rb1*rb3*s12; - a23 = r12c2 * (-c2mag*c*s2 - c1mag*s12); + a11 = c*sb1*s1; + a22 = -sb2 * (2.0*c0*s12 - c*(s1+s2)); + a33 = c*sb3*s2; + a12 = -r12c1 * (c1mag*c*s1 + c2mag*s12); + a13 = -rb1*rb3*s12; + a23 = r12c2 * (c2mag*c*s2 + c1mag*s12); - sx1 = a11*vb1x + a12*vb2x + a13*vb3x; sx2 = a12*vb1x + a22*vb2x + a23*vb3x; - sx12 = a13*vb1x + a23*vb2x + a33*vb3x; - sy1 = a11*vb1y + a12*vb2y + a13*vb3y; sy2 = a12*vb1y + a22*vb2y + a23*vb3y; - sy12 = a13*vb1y + a23*vb2y + a33*vb3y; - sz1 = a11*vb1z + a12*vb2z + a13*vb3z; sz2 = a12*vb1z + a22*vb2z + a23*vb3z; - sz12 = a13*vb1z + a23*vb2z + a33*vb3z; + + f1[0] = a11*vb1x + a12*vb2x + a13*vb3x; + f1[1] = a11*vb1y + a12*vb2y + a13*vb3y; + f1[2] = a11*vb1z + a12*vb2z + a13*vb3z; + + f2[0] = -sx2 - f1[0]; + f2[1] = -sy2 - f1[1]; + f2[2] = -sz2 - f1[2]; + + f4[0] = a13*vb1x + a23*vb2x + a33*vb3x; + f4[1] = a13*vb1y + a23*vb2y + a33*vb3y; + f4[2] = a13*vb1z + a23*vb2z + a33*vb3z; + + f3[0] = sx2 - f4[0]; + f3[1] = sy2 - f4[1]; + f3[2] = sz2 - f4[2]; // apply force to each of 4 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= sx1; - f[i1][1] -= sy1; - f[i1][2] -= sz1; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += sx2 + sx1; - f[i2][1] += sy2 + sy1; - f[i2][2] += sz2 + sz1; + f[i2][0] += f2[0]; + f[i2][1] += f2[1]; + f[i2][2] += f2[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] += sx12 - sx2; - f[i3][1] += sy12 - sy2; - f[i3][2] += sz12 - sz2; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } if (newton_bond || i4 < nlocal) { - f[i4][0] -= sx12; - f[i4][1] -= sy12; - f[i4][2] -= sz12; + f[i4][0] += f4[0]; + f[i4][1] += f4[1]; + f[i4][2] += f4[2]; } - // virial contribution - - if (vflag) { - virial[0] -= rfactor * (vb1x*sx1 + vb2x*sx2 + vb3x*sx12); - virial[1] -= rfactor * (vb1y*sy1 + vb2y*sy2 + vb3y*sy12); - virial[2] -= rfactor * (vb1z*sz1 + vb2z*sz2 + vb3z*sz12); - virial[3] -= rfactor * (vb1x*sy1 + vb2x*sy2 + vb3x*sy12); - virial[4] -= rfactor * (vb1x*sz1 + vb2x*sz2 + vb3x*sz12); - virial[5] -= rfactor * (vb1y*sz1 + vb2y*sz2 + vb3y*sz12); - } + if (evflag) + ev_tally(i1,i2,i3,i4,nlocal,newton_bond,edihedral,f1,f3,f4, + vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); } } diff --git a/src/MOLECULE/dihedral_hybrid.cpp b/src/MOLECULE/dihedral_hybrid.cpp index cd566f4cb7..770bd49a60 100644 --- a/src/MOLECULE/dihedral_hybrid.cpp +++ b/src/MOLECULE/dihedral_hybrid.cpp @@ -59,7 +59,7 @@ DihedralHybrid::~DihedralHybrid() void DihedralHybrid::compute(int eflag, int vflag) { - int i,m,n; + int i,j,m,n; // save ptrs to original dihedrallist @@ -98,24 +98,36 @@ void DihedralHybrid::compute(int eflag, int vflag) } // call each sub-style's compute function - // must set neighbor->dihedrallist to sub-style dihedrallist before call - // accumulate sub-style energy,virial in hybrid's energy,virial + // set neighbor->dihedrallist to sub-style dihedrallist before call + // accumulate sub-style global/peratom energy/virial in hybrid - energy = 0.0; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; for (m = 0; m < nstyles; m++) { if (styles[m] == NULL) continue; neighbor->ndihedrallist = ndihedrallist[m]; neighbor->dihedrallist = dihedrallist[m]; + styles[m]->compute(eflag,vflag); - if (eflag) { - energy += styles[m]->energy; - eng_vdwl += styles[m]->eng_vdwl; - eng_coul += styles[m]->eng_coul; + + if (eflag_global) energy += styles[m]->energy; + if (vflag_global) + for (n = 0; n < 6; n++) virial[n] += styles[m]->virial[n]; + if (eflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + double *eatom_substyle = styles[m]->eatom; + for (i = 0; i < n; i++) eatom[i] += eatom_substyle[i]; + } + if (vflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + double **vatom_substyle = styles[m]->vatom; + for (i = 0; i < n; i++) + for (j = 0; j < 6; j++) + vatom[i][j] += vatom_substyle[i][j]; } - if (vflag) for (n = 0; n < 6; n++) virial[n] += styles[m]->virial[n]; } // restore ptrs to original dihedrallist @@ -250,7 +262,8 @@ void DihedralHybrid::read_restart(FILE *fp) double DihedralHybrid::memory_usage() { - double bytes = 0.0; + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); for (int m = 0; m < nstyles; m++) bytes += maxdihedral[m]*5 * sizeof(int); for (int m = 0; m < nstyles; m++) if (styles[m]) bytes += styles[m]->memory_usage(); diff --git a/src/MOLECULE/dihedral_multi_harmonic.cpp b/src/MOLECULE/dihedral_multi_harmonic.cpp index 01e16ec425..f1124adf61 100644 --- a/src/MOLECULE/dihedral_multi_harmonic.cpp +++ b/src/MOLECULE/dihedral_multi_harmonic.cpp @@ -57,18 +57,18 @@ DihedralMultiHarmonic::~DihedralMultiHarmonic() void DihedralMultiHarmonic::compute(int eflag, int vflag) { - int n,i1,i2,i3,i4,type,factor; - double rfactor; - double vb1x,vb1y,vb1z,vb2x,vb2y; - double vb2z,vb2xm,vb2ym,vb2zm,vb3x,vb3y,vb3z,sb1; - double sb2,sb3,rb1,rb3,c0,b1mag2,b1mag,b2mag2; + int i1,i2,i3,i4,n,type; + double vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z,vb2xm,vb2ym,vb2zm; + double edihedral,f1[3],f2[3],f3[3],f4[3]; + double sb1,sb2,sb3,rb1,rb3,c0,b1mag2,b1mag,b2mag2; double b2mag,b3mag2,b3mag,ctmp,r12c1,c1mag,r12c2; double c2mag,sc1,sc2,s1,s12,c,p,pd,a,a11,a22; - double a33,a12,a13,a23,sx1,sx2,sx12,sy1,sy2,sy12; - double sz1,sz2,sz12,s2,sin2; + double a33,a12,a13,a23,sx2,sy2,sz2; + double s2,sin2; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + edihedral = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -78,23 +78,12 @@ void DihedralMultiHarmonic::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < ndihedrallist; n++) { - i1 = dihedrallist[n][0]; i2 = dihedrallist[n][1]; i3 = dihedrallist[n][2]; i4 = dihedrallist[n][3]; type = dihedrallist[n][4]; - if (newton_bond) factor = 4; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - if (i4 < nlocal) factor++; - } - rfactor = 0.25 * factor; - // 1st bond vb1x = x[i1][0] - x[i2][0]; @@ -194,64 +183,67 @@ void DihedralMultiHarmonic::compute(int eflag, int vflag) p = a1[type] + c*(a2[type] + c*(a3[type] + c*(a4[type] + c*a5[type]))); pd = a2[type] + c*(2.0*a3[type] + c*(3.0*a4[type] + c*4.0*a5[type])); - if (eflag) energy += rfactor * p; + if (eflag) edihedral = p; a = pd; c = c * a; s12 = s12 * a; - a11 = (-c*sb1*s1); - a22 = sb2*(2.0*c0*s12 - c*(s1+s2)); - a33 = (-c*sb3*s2); - a12 = r12c1*(c1mag*c*s1 + c2mag*s12); - a13 = rb1*rb3*s12; - a23 = r12c2*(-c2mag*c*s2 - c1mag*s12); + a11 = c*sb1*s1; + a22 = -sb2 * (2.0*c0*s12 - c*(s1+s2)); + a33 = c*sb3*s2; + a12 = -r12c1*(c1mag*c*s1 + c2mag*s12); + a13 = -rb1*rb3*s12; + a23 = r12c2*(c2mag*c*s2 + c1mag*s12); - sx1 = a11*vb1x + a12*vb2x + a13*vb3x; sx2 = a12*vb1x + a22*vb2x + a23*vb3x; - sx12 = a13*vb1x + a23*vb2x + a33*vb3x; - sy1 = a11*vb1y + a12*vb2y + a13*vb3y; sy2 = a12*vb1y + a22*vb2y + a23*vb3y; - sy12 = a13*vb1y + a23*vb2y + a33*vb3y; - sz1 = a11*vb1z + a12*vb2z + a13*vb3z; sz2 = a12*vb1z + a22*vb2z + a23*vb3z; - sz12 = a13*vb1z + a23*vb2z + a33*vb3z; + + f1[0] = a11*vb1x + a12*vb2x + a13*vb3x; + f1[1] = a11*vb1y + a12*vb2y + a13*vb3y; + f1[2] = a11*vb1z + a12*vb2z + a13*vb3z; + + f2[0] = -sx2 - f1[0]; + f2[1] = -sy2 - f1[1]; + f2[2] = -sz2 - f1[2]; + + f4[0] = a13*vb1x + a23*vb2x + a33*vb3x; + f4[1] = a13*vb1y + a23*vb2y + a33*vb3y; + f4[2] = a13*vb1z + a23*vb2z + a33*vb3z; + + f3[0] = sx2 - f4[0]; + f3[1] = sy2 - f4[1]; + f3[2] = sz2 - f4[2]; // apply force to each of 4 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= sx1; - f[i1][1] -= sy1; - f[i1][2] -= sz1; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += sx2 + sx1; - f[i2][1] += sy2 + sy1; - f[i2][2] += sz2 + sz1; + f[i2][0] += f2[0]; + f[i2][1] += f2[1]; + f[i2][2] += f2[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] += sx12 - sx2; - f[i3][1] += sy12 - sy2; - f[i3][2] += sz12 - sz2; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } if (newton_bond || i4 < nlocal) { - f[i4][0] -= sx12; - f[i4][1] -= sy12; - f[i4][2] -= sz12; + f[i4][0] += f4[0]; + f[i4][1] += f4[1]; + f[i4][2] += f4[2]; } - // virial contribution - - if (vflag) { - virial[0] -= rfactor * (vb1x*sx1 + vb2x*sx2 + vb3x*sx12); - virial[1] -= rfactor * (vb1y*sy1 + vb2y*sy2 + vb3y*sy12); - virial[2] -= rfactor * (vb1z*sz1 + vb2z*sz2 + vb3z*sz12); - virial[3] -= rfactor * (vb1x*sy1 + vb2x*sy2 + vb3x*sy12); - virial[4] -= rfactor * (vb1x*sz1 + vb2x*sz2 + vb3x*sz12); - virial[5] -= rfactor * (vb1y*sz1 + vb2y*sz2 + vb3y*sz12); - } + if (evflag) + ev_tally(i1,i2,i3,i4,nlocal,newton_bond,edihedral,f1,f3,f4, + vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); } } diff --git a/src/MOLECULE/dihedral_opls.cpp b/src/MOLECULE/dihedral_opls.cpp index 07d41a30c3..41b0515240 100644 --- a/src/MOLECULE/dihedral_opls.cpp +++ b/src/MOLECULE/dihedral_opls.cpp @@ -57,18 +57,18 @@ DihedralOPLS::~DihedralOPLS() void DihedralOPLS::compute(int eflag, int vflag) { - int n,i1,i2,i3,i4,type,factor; - double rfactor; - double vb1x,vb1y,vb1z,vb2x,vb2y; - double vb2z,vb2xm,vb2ym,vb2zm,vb3x,vb3y,vb3z,sb1; - double sb2,sb3,rb1,rb3,c0,b1mag2,b1mag,b2mag2; + int i1,i2,i3,i4,n,type; + double vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z,vb2xm,vb2ym,vb2zm; + double edihedral,f1[3],f2[3],f3[3],f4[3]; + double sb1,sb2,sb3,rb1,rb3,c0,b1mag2,b1mag,b2mag2; double b2mag,b3mag2,b3mag,ctmp,r12c1,c1mag,r12c2; double c2mag,sc1,sc2,s1,s12,c,p,pd,a,a11,a22; - double a33,a12,a13,a23,sx1,sx2,sx12,sy1,sy2,sy12; - double sz1,sz2,sz12,s2,cx,cy,cz,cmag,dx,phi,si,siinv,sin2; + double a33,a12,a13,a23,sx2,sy2,sz2; + double s2,cx,cy,cz,cmag,dx,phi,si,siinv,sin2; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + edihedral = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -78,23 +78,12 @@ void DihedralOPLS::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < ndihedrallist; n++) { - i1 = dihedrallist[n][0]; i2 = dihedrallist[n][1]; i3 = dihedrallist[n][2]; i4 = dihedrallist[n][3]; type = dihedrallist[n][4]; - if (newton_bond) factor = 4; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - if (i4 < nlocal) factor++; - } - rfactor = 0.25 * factor; - // 1st bond vb1x = x[i1][0] - x[i2][0]; @@ -208,64 +197,67 @@ void DihedralOPLS::compute(int eflag, int vflag) pd = k1[type] - 2.0*k2[type]*sin(2.0*phi)*siinv + 3.0*k3[type]*sin(3.0*phi)*siinv - 4.0*k4[type]*sin(4.0*phi)*siinv; - if (eflag) energy += rfactor * p; + if (eflag) edihedral = p; a = pd; c = c * a; s12 = s12 * a; - a11 = -c*sb1*s1; - a22 = sb2 * (2.0*c0*s12 - c*(s1+s2)); - a33 = -c*sb3*s2; - a12 = r12c1 * (c1mag*c*s1 + c2mag*s12); - a13 = rb1*rb3*s12; - a23 = r12c2 * (-c2mag*c*s2 - c1mag*s12); + a11 = c*sb1*s1; + a22 = -sb2 * (2.0*c0*s12 - c*(s1+s2)); + a33 = c*sb3*s2; + a12 = -r12c1 * (c1mag*c*s1 + c2mag*s12); + a13 = -rb1*rb3*s12; + a23 = r12c2 * (c2mag*c*s2 + c1mag*s12); - sx1 = a11*vb1x + a12*vb2x + a13*vb3x; sx2 = a12*vb1x + a22*vb2x + a23*vb3x; - sx12 = a13*vb1x + a23*vb2x + a33*vb3x; - sy1 = a11*vb1y + a12*vb2y + a13*vb3y; sy2 = a12*vb1y + a22*vb2y + a23*vb3y; - sy12 = a13*vb1y + a23*vb2y + a33*vb3y; - sz1 = a11*vb1z + a12*vb2z + a13*vb3z; sz2 = a12*vb1z + a22*vb2z + a23*vb3z; - sz12 = a13*vb1z + a23*vb2z + a33*vb3z; + + f1[0] = a11*vb1x + a12*vb2x + a13*vb3x; + f1[1] = a11*vb1y + a12*vb2y + a13*vb3y; + f1[2] = a11*vb1z + a12*vb2z + a13*vb3z; + + f2[0] = -sx2 - f1[0]; + f2[1] = -sy2 - f1[1]; + f2[2] = -sz2 - f1[2]; + + f4[0] = a13*vb1x + a23*vb2x + a33*vb3x; + f4[1] = a13*vb1y + a23*vb2y + a33*vb3y; + f4[2] = a13*vb1z + a23*vb2z + a33*vb3z; + + f3[0] = sx2 - f4[0]; + f3[1] = sy2 - f4[1]; + f3[2] = sz2 - f4[2]; // apply force to each of 4 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= sx1; - f[i1][1] -= sy1; - f[i1][2] -= sz1; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += sx2 + sx1; - f[i2][1] += sy2 + sy1; - f[i2][2] += sz2 + sz1; + f[i2][0] += f2[0]; + f[i2][1] += f2[1]; + f[i2][2] += f2[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] += sx12 - sx2; - f[i3][1] += sy12 - sy2; - f[i3][2] += sz12 - sz2; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } if (newton_bond || i4 < nlocal) { - f[i4][0] -= sx12; - f[i4][1] -= sy12; - f[i4][2] -= sz12; + f[i4][0] += f4[0]; + f[i4][1] += f4[1]; + f[i4][2] += f4[2]; } - // virial contribution - - if (vflag) { - virial[0] -= rfactor * (vb1x*sx1 + vb2x*sx2 + vb3x*sx12); - virial[1] -= rfactor * (vb1y*sy1 + vb2y*sy2 + vb3y*sy12); - virial[2] -= rfactor * (vb1z*sz1 + vb2z*sz2 + vb3z*sz12); - virial[3] -= rfactor * (vb1x*sy1 + vb2x*sy2 + vb3x*sy12); - virial[4] -= rfactor * (vb1x*sz1 + vb2x*sz2 + vb3x*sz12); - virial[5] -= rfactor * (vb1y*sz1 + vb2y*sz2 + vb3y*sz12); - } + if (evflag) + ev_tally(i1,i2,i3,i4,nlocal,newton_bond,edihedral,f1,f3,f4, + vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); } } diff --git a/src/MOLECULE/improper.cpp b/src/MOLECULE/improper.cpp index 49639d2ea6..8697d9f722 100644 --- a/src/MOLECULE/improper.cpp +++ b/src/MOLECULE/improper.cpp @@ -14,6 +14,8 @@ #include "math.h" #include "improper.h" #include "atom.h" +#include "force.h" +#include "memory.h" #include "error.h" using namespace LAMMPS_NS; @@ -22,8 +24,22 @@ using namespace LAMMPS_NS; Improper::Improper(LAMMPS *lmp) : Pointers(lmp) { + energy = 0.0; + allocated = 0; PI = 4.0*atan(1.0); + + maxeatom = maxvatom = 0; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +Improper::~Improper() +{ + memory->sfree(eatom); + memory->destroy_2d_double_array(vatom); } /* ---------------------------------------------------------------------- @@ -36,3 +52,192 @@ void Improper::init() for (int i = 1; i <= atom->nimpropertypes; i++) if (setflag[i] == 0) error->all("All improper coeffs are not set"); } + +/* ---------------------------------------------------------------------- + setup for energy, virial computation + see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) +------------------------------------------------------------------------- */ + +void Improper::ev_setup(int eflag, int vflag) +{ + int i,n; + + evflag = 1; + + eflag_either = eflag; + eflag_global = eflag % 2; + eflag_atom = eflag / 2; + + vflag_either = vflag; + vflag_global = vflag % 4; + vflag_atom = vflag / 4; + + // reallocate per-atom arrays if necessary + + if (eflag_atom && atom->nmax > maxeatom) { + maxeatom = atom->nmax; + memory->sfree(eatom); + eatom = (double *) memory->smalloc(maxeatom*sizeof(double),"bond:eatom"); + } + if (vflag_atom && atom->nmax > maxvatom) { + maxvatom = atom->nmax; + memory->destroy_2d_double_array(vatom); + vatom = memory->create_2d_double_array(maxvatom,6,"bond:vatom"); + } + + // zero accumulators + + if (eflag_global) energy = 0.0; + if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0; + if (eflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + for (i = 0; i < n; i++) eatom[i] = 0.0; + } + if (vflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + for (i = 0; i < n; i++) { + vatom[i][0] = 0.0; + vatom[i][1] = 0.0; + vatom[i][2] = 0.0; + vatom[i][3] = 0.0; + vatom[i][4] = 0.0; + vatom[i][5] = 0.0; + } + } +} + +/* ---------------------------------------------------------------------- + tally energy and virial into global and per-atom accumulators + virial = r1F1 + r2F2 + r3F3 + r4F4 = (r1-r2) F1 + (r3-r2) F3 + (r4-r2) F4 + = (r1-r2) F1 + (r3-r2) F3 + (r4-r3 + r3-r2) F4 + = vb1*f1 + vb2*f3 + (vb3+vb2)*f4 +------------------------------------------------------------------------- */ + +void Improper::ev_tally(int i1, int i2, int i3, int i4, + int nlocal, int newton_bond, + double eimproper, double *f1, double *f3, double *f4, + double vb1x, double vb1y, double vb1z, + double vb2x, double vb2y, double vb2z, + double vb3x, double vb3y, double vb3z) +{ + double eimproperquarter,v[6]; + + if (eflag_either) { + if (eflag_global) { + if (newton_bond) energy += eimproper; + else { + eimproperquarter = 0.25*eimproper; + if (i1 < nlocal) energy += eimproperquarter; + if (i2 < nlocal) energy += eimproperquarter; + if (i3 < nlocal) energy += eimproperquarter; + if (i4 < nlocal) energy += eimproperquarter; + } + } + if (eflag_atom) { + eimproperquarter = 0.25*eimproper; + if (newton_bond || i1 < nlocal) eatom[i1] += eimproperquarter; + if (newton_bond || i2 < nlocal) eatom[i2] += eimproperquarter; + if (newton_bond || i3 < nlocal) eatom[i3] += eimproperquarter; + if (newton_bond || i4 < nlocal) eatom[i4] += eimproperquarter; + } + } + + if (vflag_either) { + v[0] = vb1x*f1[0] + vb2x*f3[0] + (vb3x+vb2x)*f4[0]; + v[1] = vb1y*f1[1] + vb2y*f3[1] + (vb3y+vb2y)*f4[1]; + v[2] = vb1z*f1[2] + vb2z*f3[2] + (vb3z+vb2z)*f4[2]; + v[3] = vb1x*f1[1] + vb2x*f3[1] + (vb3x+vb2x)*f4[1]; + v[4] = vb1x*f1[2] + vb2x*f3[2] + (vb3x+vb2x)*f4[2]; + v[5] = vb1y*f1[2] + vb2y*f3[2] + (vb3y+vb2y)*f4[2]; + + if (vflag_global) { + if (newton_bond) { + virial[0] += v[0]; + virial[1] += v[1]; + virial[2] += v[2]; + virial[3] += v[3]; + virial[4] += v[4]; + virial[5] += v[5]; + } else { + if (i1 < nlocal) { + virial[0] += 0.25*v[0]; + virial[1] += 0.25*v[1]; + virial[2] += 0.25*v[2]; + virial[3] += 0.25*v[3]; + virial[4] += 0.25*v[4]; + virial[5] += 0.25*v[5]; + } + if (i2 < nlocal) { + virial[0] += 0.25*v[0]; + virial[1] += 0.25*v[1]; + virial[2] += 0.25*v[2]; + virial[3] += 0.25*v[3]; + virial[4] += 0.25*v[4]; + virial[5] += 0.25*v[5]; + } + if (i3 < nlocal) { + virial[0] += 0.25*v[0]; + virial[1] += 0.25*v[1]; + virial[2] += 0.25*v[2]; + virial[3] += 0.25*v[3]; + virial[4] += 0.25*v[4]; + virial[5] += 0.25*v[5]; + } + if (i4 < nlocal) { + virial[0] += 0.25*v[0]; + virial[1] += 0.25*v[1]; + virial[2] += 0.25*v[2]; + virial[3] += 0.25*v[3]; + virial[4] += 0.25*v[4]; + virial[5] += 0.25*v[5]; + } + } + } + + if (vflag_atom) { + if (newton_bond || i1 < nlocal) { + vatom[i1][0] += 0.25*v[0]; + vatom[i1][1] += 0.25*v[1]; + vatom[i1][2] += 0.25*v[2]; + vatom[i1][3] += 0.25*v[3]; + vatom[i1][4] += 0.25*v[4]; + vatom[i1][5] += 0.25*v[5]; + } + if (newton_bond || i2 < nlocal) { + vatom[i2][0] += 0.25*v[0]; + vatom[i2][1] += 0.25*v[1]; + vatom[i2][2] += 0.25*v[2]; + vatom[i2][3] += 0.25*v[3]; + vatom[i2][4] += 0.25*v[4]; + vatom[i2][5] += 0.25*v[5]; + } + if (newton_bond || i3 < nlocal) { + vatom[i3][0] += 0.25*v[0]; + vatom[i3][1] += 0.25*v[1]; + vatom[i3][2] += 0.25*v[2]; + vatom[i3][3] += 0.25*v[3]; + vatom[i3][4] += 0.25*v[4]; + vatom[i3][5] += 0.25*v[5]; + } + if (newton_bond || i4 < nlocal) { + vatom[i4][0] += 0.25*v[0]; + vatom[i4][1] += 0.25*v[1]; + vatom[i4][2] += 0.25*v[2]; + vatom[i4][3] += 0.25*v[3]; + vatom[i4][4] += 0.25*v[4]; + vatom[i4][5] += 0.25*v[5]; + } + } + } +} + +/* ---------------------------------------------------------------------- */ + +double Improper::memory_usage() +{ + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); + return bytes; +} diff --git a/src/MOLECULE/improper_cvff.cpp b/src/MOLECULE/improper_cvff.cpp index e4a0fb4674..6328bc8ab4 100644 --- a/src/MOLECULE/improper_cvff.cpp +++ b/src/MOLECULE/improper_cvff.cpp @@ -49,18 +49,17 @@ ImproperCvff::~ImproperCvff() void ImproperCvff::compute(int eflag, int vflag) { - int m,n,i1,i2,i3,i4,type,factor; - double rfactor; - double vb1x,vb1y,vb1z,vb2x,vb2y; - double vb2z,vb2xm,vb2ym,vb2zm,vb3x,vb3y,vb3z,sb1; - double sb2,sb3,rb1,rb3,c0,b1mag2,b1mag,b2mag2; + int i1,i2,i3,i4,m,n,type; + double vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z,vb2xm,vb2ym,vb2zm; + double eimproper,f1[3],f2[3],f3[3],f4[3]; + double sb1,sb2,sb3,rb1,rb3,c0,b1mag2,b1mag,b2mag2; double b2mag,b3mag2,b3mag,ctmp,r12c1,c1mag,r12c2; - double c2mag,sc1,sc2,s1,s12,c,p,pd,rc2,a,a11,a22; - double a33,a12,a13,a23,sx1,sx2,sx12,sy1,sy2,sy12; - double sz1,sz2,sz12,s2; + double c2mag,sc1,sc2,s1,s2,s12,c,p,pd,rc2,a,a11,a22; + double a33,a12,a13,a23,sx2,sy2,sz2; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + eimproper = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -70,23 +69,12 @@ void ImproperCvff::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nimproperlist; n++) { - i1 = improperlist[n][0]; i2 = improperlist[n][1]; i3 = improperlist[n][2]; i4 = improperlist[n][3]; type = improperlist[n][4]; - if (newton_bond) factor = 4; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - if (i4 < nlocal) factor++; - } - rfactor = 0.25 * factor; - // 1st bond vb1x = x[i1][0] - x[i2][0]; @@ -218,64 +206,67 @@ void ImproperCvff::compute(int eflag, int vflag) pd = -pd; } - if (eflag) energy += rfactor * k[type] * p; + if (eflag) eimproper = k[type]*p; a = 2.0 * k[type] * pd; c = c * a; s12 = s12 * a; - a11 = (-c*sb1*s1); - a22 = sb2*(2.0*c0*s12 - c*(s1+s2)); - a33 = (-c*sb3*s2); - a12 = r12c1*(c1mag*c*s1 + c2mag*s12); - a13 = rb1*rb3*s12; - a23 = r12c2*(-c2mag*c*s2 - c1mag*s12); + a11 = c*sb1*s1; + a22 = -sb2*(2.0*c0*s12 - c*(s1+s2)); + a33 = c*sb3*s2; + a12 = -r12c1*(c1mag*c*s1 + c2mag*s12); + a13 = -rb1*rb3*s12; + a23 = r12c2*(c2mag*c*s2 + c1mag*s12); - sx1 = a11*vb1x + a12*vb2x + a13*vb3x; sx2 = a12*vb1x + a22*vb2x + a23*vb3x; - sx12 = a13*vb1x + a23*vb2x + a33*vb3x; - sy1 = a11*vb1y + a12*vb2y + a13*vb3y; sy2 = a12*vb1y + a22*vb2y + a23*vb3y; - sy12 = a13*vb1y + a23*vb2y + a33*vb3y; - sz1 = a11*vb1z + a12*vb2z + a13*vb3z; sz2 = a12*vb1z + a22*vb2z + a23*vb3z; - sz12 = a13*vb1z + a23*vb2z + a33*vb3z; + + f1[0] = a11*vb1x + a12*vb2x + a13*vb3x; + f1[1] = a11*vb1y + a12*vb2y + a13*vb3y; + f1[2] = a11*vb1z + a12*vb2z + a13*vb3z; + + f2[0] = -sx2 - f1[0]; + f2[1] = -sy2 - f1[1]; + f2[2] = -sz2 - f1[2]; + + f4[0] = a13*vb1x + a23*vb2x + a33*vb3x; + f4[1] = a13*vb1y + a23*vb2y + a33*vb3y; + f4[2] = a13*vb1z + a23*vb2z + a33*vb3z; + + f3[0] = sx2 - f4[0]; + f3[1] = sy2 - f4[1]; + f3[2] = sz2 - f4[2]; // apply force to each of 4 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= sx1; - f[i1][1] -= sy1; - f[i1][2] -= sz1; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += sx2 + sx1; - f[i2][1] += sy2 + sy1; - f[i2][2] += sz2 + sz1; + f[i2][0] += f2[0]; + f[i2][1] += f2[1]; + f[i2][2] += f2[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] += sx12 - sx2; - f[i3][1] += sy12 - sy2; - f[i3][2] += sz12 - sz2; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } if (newton_bond || i4 < nlocal) { - f[i4][0] -= sx12; - f[i4][1] -= sy12; - f[i4][2] -= sz12; + f[i4][0] += f4[0]; + f[i4][1] += f4[1]; + f[i4][2] += f4[2]; } - // virial contribution - - if (vflag) { - virial[0] -= rfactor * (vb1x*sx1 + vb2x*sx2 + vb3x*sx12); - virial[1] -= rfactor * (vb1y*sy1 + vb2y*sy2 + vb3y*sy12); - virial[2] -= rfactor * (vb1z*sz1 + vb2z*sz2 + vb3z*sz12); - virial[3] -= rfactor * (vb1x*sy1 + vb2x*sy2 + vb3x*sy12); - virial[4] -= rfactor * (vb1x*sz1 + vb2x*sz2 + vb3x*sz12); - virial[5] -= rfactor * (vb1y*sz1 + vb2y*sz2 + vb3y*sz12); - } + if (evflag) + ev_tally(i1,i2,i3,i4,nlocal,newton_bond,eimproper,f1,f3,f4, + vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); } } diff --git a/src/MOLECULE/improper_harmonic.cpp b/src/MOLECULE/improper_harmonic.cpp index 037f65010c..de49668f7d 100644 --- a/src/MOLECULE/improper_harmonic.cpp +++ b/src/MOLECULE/improper_harmonic.cpp @@ -48,15 +48,16 @@ ImproperHarmonic::~ImproperHarmonic() void ImproperHarmonic::compute(int eflag, int vflag) { - int n,i1,i2,i3,i4,type,factor; - double rfactor; - double v1x,v1y,v1z,v2x,v2y,v2z,v3x; - double v3y,v3z,ss1,ss2,ss3,r1,r2,r3,c0,c1,c2,s1,s2; - double s12,c,s,domega,a,a11,a22,a33,a12,a13,a23,sx1; - double sx2,sx12,sy1,sy2,sy12,sz1,sz2,sz12; + int i1,i2,i3,i4,n,type; + double vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z; + double eimproper,f1[3],f2[3],f3[3],f4[3]; + double ss1,ss2,ss3,r1,r2,r3,c0,c1,c2,s1,s2; + double s12,c,s,domega,a,a11,a22,a33,a12,a13,a23; + double sx2,sy2,sz2; - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + eimproper = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; @@ -66,43 +67,32 @@ void ImproperHarmonic::compute(int eflag, int vflag) int newton_bond = force->newton_bond; for (n = 0; n < nimproperlist; n++) { - i1 = improperlist[n][0]; i2 = improperlist[n][1]; i3 = improperlist[n][2]; i4 = improperlist[n][3]; type = improperlist[n][4]; - if (newton_bond) factor = 4; - else { - factor = 0; - if (i1 < nlocal) factor++; - if (i2 < nlocal) factor++; - if (i3 < nlocal) factor++; - if (i4 < nlocal) factor++; - } - rfactor = 0.25 * factor; - // geometry of 4-body - v1x = x[i2][0] - x[i1][0]; - v1y = x[i2][1] - x[i1][1]; - v1z = x[i2][2] - x[i1][2]; - domain->minimum_image(v1x,v1y,v1z); + vb1x = x[i1][0] - x[i2][0]; + vb1y = x[i1][1] - x[i2][1]; + vb1z = x[i1][2] - x[i2][2]; + domain->minimum_image(vb1x,vb1y,vb1z); - v2x = x[i3][0] - x[i2][0]; - v2y = x[i3][1] - x[i2][1]; - v2z = x[i3][2] - x[i2][2]; - domain->minimum_image(v2x,v2y,v2z); + vb2x = x[i3][0] - x[i2][0]; + vb2y = x[i3][1] - x[i2][1]; + vb2z = x[i3][2] - x[i2][2]; + domain->minimum_image(vb2x,vb2y,vb2z); - v3x = x[i4][0] - x[i3][0]; - v3y = x[i4][1] - x[i3][1]; - v3z = x[i4][2] - x[i3][2]; - domain->minimum_image(v3x,v3y,v3z); + vb3x = x[i4][0] - x[i3][0]; + vb3y = x[i4][1] - x[i3][1]; + vb3z = x[i4][2] - x[i3][2]; + domain->minimum_image(vb3x,vb3y,vb3z); - ss1 = 1.0 / (v1x*v1x + v1y*v1y + v1z*v1z); - ss2 = 1.0 / (v2x*v2x + v2y*v2y + v2z*v2z); - ss3 = 1.0 / (v3x*v3x + v3y*v3y + v3z*v3z); + ss1 = 1.0 / (vb1x*vb1x + vb1y*vb1y + vb1z*vb1z); + ss2 = 1.0 / (vb2x*vb2x + vb2y*vb2y + vb2z*vb2z); + ss3 = 1.0 / (vb3x*vb3x + vb3y*vb3y + vb3z*vb3z); r1 = sqrt(ss1); r2 = sqrt(ss2); @@ -110,9 +100,9 @@ void ImproperHarmonic::compute(int eflag, int vflag) // sin and cos of angle - c0 = -(v1x * v3x + v1y * v3y + v1z * v3z) * r1 * r3; - c1 = -(v1x * v2x + v1y * v2y + v1z * v2z) * r1 * r2; - c2 = -(v3x * v2x + v3y * v2y + v3z * v2z) * r3 * r2; + c0 = (vb1x * vb3x + vb1y * vb3y + vb1z * vb3z) * r1 * r3; + c1 = (vb1x * vb2x + vb1y * vb2y + vb1z * vb2z) * r1 * r2; + c2 = -(vb3x * vb2x + vb3y * vb2y + vb3z * vb2z) * r3 * r2; s1 = 1.0 - c1*c1; if (s1 < SMALL) s1 = SMALL; @@ -156,65 +146,67 @@ void ImproperHarmonic::compute(int eflag, int vflag) domega = acos(c) - chi[type]; a = k[type] * domega; - if (eflag) energy += rfactor * a * domega; + if (eflag) eimproper = a*domega; a = -a * 2.0/s; c = c * a; - s12 = s12 * a; - a11 = (-c * ss1 * s1); - a22 = ss2 * (2.0 * c0 * s12 - c * (s1 + s2)); - a33 = (-c * ss3 * s2); - a12 = r1 * r2 * (c1 * c * s1 + c2 * s12); - a13 = r1 * r3 * s12; - a23 = r2 * r3 * (-c2 * c * s2 - c1 * s12); + a11 = c*ss1*s1; + a22 = -ss2 * (2.0*c0*s12 - c*(s1+s2)); + a33 = c*ss3*s2; + a12 = -r1*r2*(c1*c*s1 + c2*s12); + a13 = -r1*r3*s12; + a23 = r2*r3*(c2*c*s2 + c1*s12); - sx1 = a12*v2x + a13*v3x - a11*v1x; - sx2 = a22*v2x + a23*v3x - a12*v1x; - sx12 = a23*v2x + a33*v3x - a13*v1x; - sy1 = a12*v2y + a13*v3y - a11*v1y; - sy2 = a22*v2y + a23*v3y - a12*v1y; - sy12 = a23*v2y + a33*v3y - a13*v1y; - sz1 = a12*v2z + a13*v3z - a11*v1z; - sz2 = a22*v2z + a23*v3z - a12*v1z; - sz12 = a23*v2z + a33*v3z - a13*v1z; + sx2 = a22*vb2x + a23*vb3x + a12*vb1x; + sy2 = a22*vb2y + a23*vb3y + a12*vb1y; + sz2 = a22*vb2z + a23*vb3z + a12*vb1z; + + f1[0] = a12*vb2x + a13*vb3x + a11*vb1x; + f1[1] = a12*vb2y + a13*vb3y + a11*vb1y; + f1[2] = a12*vb2z + a13*vb3z + a11*vb1z; + + f2[0] = -sx2 - f1[0]; + f2[1] = -sy2 - f1[1]; + f2[2] = -sz2 - f1[2]; + + f4[0] = a23*vb2x + a33*vb3x + a13*vb1x; + f4[1] = a23*vb2y + a33*vb3y + a13*vb1y; + f4[2] = a23*vb2z + a33*vb3z + a13*vb1z; + + f3[0] = sx2 - f4[0]; + f3[1] = sy2 - f4[1]; + f3[2] = sz2 - f4[2]; // apply force to each of 4 atoms if (newton_bond || i1 < nlocal) { - f[i1][0] -= sx1; - f[i1][1] -= sy1; - f[i1][2] -= sz1; + f[i1][0] += f1[0]; + f[i1][1] += f1[1]; + f[i1][2] += f1[2]; } if (newton_bond || i2 < nlocal) { - f[i2][0] += sx2 + sx1; - f[i2][1] += sy2 + sy1; - f[i2][2] += sz2 + sz1; + f[i2][0] += f2[0]; + f[i2][1] += f2[1]; + f[i2][2] += f2[2]; } if (newton_bond || i3 < nlocal) { - f[i3][0] += sx12 - sx2; - f[i3][1] += sy12 - sy2; - f[i3][2] += sz12 - sz2; + f[i3][0] += f3[0]; + f[i3][1] += f3[1]; + f[i3][2] += f3[2]; } if (newton_bond || i4 < nlocal) { - f[i4][0] -= sx12; - f[i4][1] -= sy12; - f[i4][2] -= sz12; + f[i4][0] += f4[0]; + f[i4][1] += f4[1]; + f[i4][2] += f4[2]; } - // virial contribution - - if (vflag) { - virial[0] += rfactor * (v1x*sx1 - v2x*sx2 - v3x*sx12); - virial[1] += rfactor * (v1y*sy1 - v2y*sy2 - v3y*sy12); - virial[2] += rfactor * (v1z*sz1 - v2z*sz2 - v3z*sz12); - virial[3] += rfactor * (v1x*sy1 - v2x*sy2 - v3x*sy12); - virial[4] += rfactor * (v1x*sz1 - v2x*sz2 - v3x*sz12); - virial[5] += rfactor * (v1y*sz1 - v2y*sz2 - v3y*sz12); - } + if (evflag) + ev_tally(i1,i2,i3,i4,nlocal,newton_bond,eimproper,f1,f3,f4, + vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); } } diff --git a/src/MOLECULE/improper_hybrid.cpp b/src/MOLECULE/improper_hybrid.cpp index d93a054928..c8cf757b38 100644 --- a/src/MOLECULE/improper_hybrid.cpp +++ b/src/MOLECULE/improper_hybrid.cpp @@ -59,7 +59,7 @@ ImproperHybrid::~ImproperHybrid() void ImproperHybrid::compute(int eflag, int vflag) { - int i,m,n; + int i,j,m,n; // save ptrs to original improperlist @@ -98,19 +98,36 @@ void ImproperHybrid::compute(int eflag, int vflag) } // call each sub-style's compute function - // must set neighbor->improperlist to sub-style improperlist before call - // accumulate sub-style energy,virial in hybrid's energy,virial + // set neighbor->improperlist to sub-style improperlist before call + // accumulate sub-style global/peratom energy/virial in hybrid - energy = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; for (m = 0; m < nstyles; m++) { if (styles[m] == NULL) continue; neighbor->nimproperlist = nimproperlist[m]; neighbor->improperlist = improperlist[m]; + styles[m]->compute(eflag,vflag); - if (eflag) energy += styles[m]->energy; - if (vflag) for (n = 0; n < 6; n++) virial[n] += styles[m]->virial[n]; + + if (eflag_global) energy += styles[m]->energy; + if (vflag_global) + for (n = 0; n < 6; n++) virial[n] += styles[m]->virial[n]; + if (eflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + double *eatom_substyle = styles[m]->eatom; + for (i = 0; i < n; i++) eatom[i] += eatom_substyle[i]; + } + if (vflag_atom) { + n = atom->nlocal; + if (force->newton_bond) n += atom->nghost; + double **vatom_substyle = styles[m]->vatom; + for (i = 0; i < n; i++) + for (j = 0; j < 6; j++) + vatom[i][j] += vatom_substyle[i][j]; + } } // restore ptrs to original improperlist @@ -237,7 +254,8 @@ void ImproperHybrid::read_restart(FILE *fp) double ImproperHybrid::memory_usage() { - double bytes = 0.0; + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); for (int m = 0; m < nstyles; m++) bytes += maximproper[m]*5 * sizeof(int); for (int m = 0; m < nstyles; m++) if (styles[m]) bytes += styles[m]->memory_usage(); diff --git a/src/MOLECULE/pair_lj_charmm_coul_charmm.cpp b/src/MOLECULE/pair_lj_charmm_coul_charmm.cpp index 4b045def93..b1f9dff6c2 100644 --- a/src/MOLECULE/pair_lj_charmm_coul_charmm.cpp +++ b/src/MOLECULE/pair_lj_charmm_coul_charmm.cpp @@ -68,20 +68,21 @@ PairLJCharmmCoulCharmm::~PairLJCharmmCoulCharmm() void PairLJCharmmCoulCharmm::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; - double factor,phicoul,philj,switch1,switch2; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; + double philj,switch1,switch2; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -147,54 +148,46 @@ void PairLJCharmmCoulCharmm::compute(int eflag, int vflag) } } else forcelj = 0.0; - fforce = (factor_coul*forcecoul + factor_lj*forcelj) * r2inv; + fpair = (factor_coul*forcecoul + factor_lj*forcelj) * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; if (rsq < cut_coulsq) { - phicoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); + ecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); if (rsq > cut_coul_innersq) { switch1 = (cut_coulsq-rsq) * (cut_coulsq-rsq) * (cut_coulsq + 2.0*rsq - 3.0*cut_coul_innersq) / denom_coul; - phicoul *= switch1; + ecoul *= switch1; } - eng_coul += factor*factor_coul*phicoul; - } + ecoul *= factor_coul; + } else ecoul = 0.0; if (rsq < cut_ljsq) { - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; - philj *= switch1; + evdwl *= switch1; } - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/MOLECULE/pair_lj_charmm_coul_charmm_implicit.cpp b/src/MOLECULE/pair_lj_charmm_coul_charmm_implicit.cpp index 05ba90ab6a..71dc72f087 100644 --- a/src/MOLECULE/pair_lj_charmm_coul_charmm_implicit.cpp +++ b/src/MOLECULE/pair_lj_charmm_coul_charmm_implicit.cpp @@ -33,20 +33,21 @@ PairLJCharmmCoulCharmmImplicit::PairLJCharmmCoulCharmmImplicit(LAMMPS *lmp) : void PairLJCharmmCoulCharmmImplicit::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; - double factor,phicoul,philj,switch1,switch2; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; + double philj,switch1,switch2; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -112,54 +113,46 @@ void PairLJCharmmCoulCharmmImplicit::compute(int eflag, int vflag) } } else forcelj = 0.0; - fforce = (factor_coul*forcecoul + factor_lj*forcelj) * r2inv; + fpair = (factor_coul*forcecoul + factor_lj*forcelj) * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; if (rsq < cut_coulsq) { - phicoul = qqrd2e * qtmp*q[j]*r2inv; + ecoul = qqrd2e * qtmp*q[j]*r2inv; if (rsq > cut_coul_innersq) { switch1 = (cut_coulsq-rsq) * (cut_coulsq-rsq) * (cut_coulsq + 2.0*rsq - 3.0*cut_coul_innersq) / denom_coul; - phicoul *= switch1; + ecoul *= switch1; } - eng_coul += factor*factor_coul*phicoul; - } + ecoul *= factor_coul; + } else ecoul = 0.0; if (rsq < cut_ljsq) { - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (cut_ljsq + 2.0*rsq - 3.0*cut_lj_innersq) / denom_lj; - philj *= switch1; + evdwl *= switch1; } - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- */ diff --git a/src/OPT/pair_eam_opt.cpp b/src/OPT/pair_eam_opt.cpp index 52388ce1f6..873fed0ca3 100644 --- a/src/OPT/pair_eam_opt.cpp +++ b/src/OPT/pair_eam_opt.cpp @@ -31,34 +31,19 @@ PairEAMOpt::PairEAMOpt(LAMMPS *lmp) : PairEAM(lmp) {} void PairEAMOpt::compute(int eflag, int vflag) { - if (eflag) { - if (force->newton_pair) { - switch (vflag) { - case 0: return eval<1,0,1>(); - case 1: return eval<1,1,1>(); - case 2: return eval<1,2,1>(); - } + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + if (evflag) { + if (eflag) { + if (force->newton_pair) return eval<1,1,1>(); + else return eval<1,1,0>(); } else { - switch (vflag) { - case 0: return eval<1,0,0>(); - case 1: return eval<1,1,0>(); - case 2: return eval<1,2,0>(); - } + if (force->newton_pair) return eval<1,0,1>(); + else return eval<1,0,0>(); } - } else { - if (force->newton_pair) { - switch (vflag) { - case 0: return eval<0,0,1>(); - case 1: return eval<0,1,1>(); - case 2: return eval<0,2,1>(); - } - } else { - switch (vflag) { - case 0: return eval<0,0,0>(); - case 1: return eval<0,1,0>(); - case 2: return eval<0,2,0>(); - } - } + if (force->newton_pair) return eval<0,0,1>(); + else return eval<0,0,0>(); } } diff --git a/src/OPT/pair_eam_opt.h b/src/OPT/pair_eam_opt.h index f21d6d8e48..b98c18de03 100644 --- a/src/OPT/pair_eam_opt.h +++ b/src/OPT/pair_eam_opt.h @@ -45,10 +45,10 @@ class PairEAMOpt : virtual public PairEAM { void compute(int, int); private: - template < int EFLAG, int VFLAG, int NEWTON_PAIR > void eval(); + template < int EVFLAG, int EFLAG, int NEWTON_PAIR > void eval(); }; -template < int EFLAG, int VFLAG, int NEWTON_PAIR > +template < int EVFLAG, int EFLAG, int NEWTON_PAIR > void PairEAMOpt::eval() { typedef struct { double x,y,z; } vec3_t; @@ -71,8 +71,9 @@ void PairEAMOpt::eval() } fast_gamma_t; int i,j,ii,jj,inum,jnum,itype,jtype; + double evdwl = 0.0; double* __restrict__ coeff; - + // grow energy array if necessary if (atom->nmax > nmax) { @@ -83,9 +84,6 @@ void PairEAMOpt::eval() fp = (double *) memory->smalloc(nmax*sizeof(double),"pair:fp"); } - eng_vdwl = 0.0; - if (VFLAG) for (i = 0; i < 6; i++) virial[i] = 0.0; - double** __restrict__ x = atom->x; double** __restrict__ f = atom->f; int* __restrict__ type = atom->type; @@ -179,7 +177,6 @@ void PairEAMOpt::eval() double rsq = delx*delx + dely*dely + delz*delz; if (rsq < tmp_cutforcesq) { - jtype = type[j] - 1; double p = sqrt(rsq)*tmp_rdr; @@ -197,9 +194,7 @@ void PairEAMOpt::eval() if (NEWTON_PAIR || j < nlocal) { rho[j] += a.rhor3i+a.rhor2i+a.rhor1i+a.rhor0i; } - } - } } rho[i] = tmprho; @@ -220,7 +215,11 @@ void PairEAMOpt::eval() ++m; coeff = frho_spline[type2frho[type[i]]][m]; fp[i] = (coeff[0]*p + coeff[1])*p + coeff[2]; - if (EFLAG) eng_vdwl += ((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6]; + if (EFLAG) { + double phi = ((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6]; + if (eflag_global) eng_vdwl += phi; + if (eflag_atom) eatom[i] += phi; + } } // communicate derivative of embedding function @@ -291,33 +290,24 @@ void PairEAMOpt::eval() double phi = z2*recip; double phip = z2p*recip - phi*recip; double psip = fp[i]*rhojp + fp[j]*rhoip + phip; - double fforce = -psip*recip; + double fpair = -psip*recip; - tmpfx += delx*fforce; - tmpfy += dely*fforce; - tmpfz += delz*fforce; + tmpfx += delx*fpair; + tmpfy += dely*fpair; + tmpfz += delz*fpair; if (NEWTON_PAIR || j < nlocal) { - ff[j].x -= delx*fforce; - ff[j].y -= dely*fforce; - ff[j].z -= delz*fforce; + ff[j].x -= delx*fpair; + ff[j].y -= dely*fpair; + ff[j].z -= delz*fpair; } - if (EFLAG) { - if (NEWTON_PAIR || j < nlocal) eng_vdwl += phi; - else eng_vdwl += 0.5*phi; - } + if (EFLAG) evdwl = phi; - if (VFLAG == 1) { - if (NEWTON_PAIR == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (EVFLAG) ev_tally(i,j,nlocal,NEWTON_PAIR, + evdwl,0.0,fpair,delx,dely,delz); } } + ff[i].x += tmpfx; ff[i].y += tmpfy; ff[i].z += tmpfz; @@ -326,7 +316,7 @@ void PairEAMOpt::eval() free(fast_alpha); fast_alpha = 0; free(fast_gamma); fast_gamma = 0; - if (VFLAG == 2) virial_compute(); + if (vflag_fdotr) virial_compute(); } } diff --git a/src/OPT/pair_lj_charmm_coul_long_opt.cpp b/src/OPT/pair_lj_charmm_coul_long_opt.cpp index cf7d6f26a3..173c201d12 100644 --- a/src/OPT/pair_lj_charmm_coul_long_opt.cpp +++ b/src/OPT/pair_lj_charmm_coul_long_opt.cpp @@ -31,34 +31,19 @@ PairLJCharmmCoulLongOpt::PairLJCharmmCoulLongOpt(LAMMPS *lmp) : void PairLJCharmmCoulLongOpt::compute(int eflag, int vflag) { - if (eflag) { - if (force->newton_pair) { - switch (vflag) { - case 0: return eval<1,0,1>(); - case 1: return eval<1,1,1>(); - case 2: return eval<1,2,1>(); - } + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + if (evflag) { + if (eflag) { + if (force->newton_pair) return eval<1,1,1>(); + else return eval<1,1,0>(); } else { - switch (vflag) { - case 0: return eval<1,0,0>(); - case 1: return eval<1,1,0>(); - case 2: return eval<1,2,0>(); - } + if (force->newton_pair) return eval<1,0,1>(); + else return eval<1,0,0>(); } - } else { - if (force->newton_pair) { - switch (vflag) { - case 0: return eval<0,0,1>(); - case 1: return eval<0,1,1>(); - case 2: return eval<0,2,1>(); - } - } else { - switch (vflag) { - case 0: return eval<0,0,0>(); - case 1: return eval<0,1,0>(); - case 2: return eval<0,2,0>(); - } - } + if (force->newton_pair) return eval<0,0,1>(); + else return eval<0,0,0>(); } } diff --git a/src/OPT/pair_lj_charmm_coul_long_opt.h b/src/OPT/pair_lj_charmm_coul_long_opt.h index 08c432a995..1b9f408060 100644 --- a/src/OPT/pair_lj_charmm_coul_long_opt.h +++ b/src/OPT/pair_lj_charmm_coul_long_opt.h @@ -47,10 +47,10 @@ class PairLJCharmmCoulLongOpt : public PairLJCharmmCoulLong { void compute(int, int); private: - template < int EFLAG, int VFLAG, int NEWTON_PAIR > void eval(); + template < int EVFLAG, int EFLAG, int NEWTON_PAIR > void eval(); }; -template < int EFLAG, int VFLAG, int NEWTON_PAIR > +template < int EVFLAG, int EFLAG, int NEWTON_PAIR > void PairLJCharmmCoulLongOpt::eval() { typedef struct { double x,y,z; } vec3_t; @@ -64,13 +64,13 @@ void PairLJCharmmCoulLongOpt::eval() double fraction,table; double r,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; double grij,expm2,prefactor,t,erfc; - double factor,phicoul,philj,switch1,switch2; + double philj,switch1,switch2; float rsq; int *int_rsq = (int *) &rsq; - eng_vdwl = eng_coul = 0.0; - if (VFLAG) for (i = 0; i < 6; i++) virial[i] = 0.0; + double evdwl = 0.0; + double ecoul = 0.0; double** __restrict__ x = atom->x; double** __restrict__ f = atom->f; @@ -174,51 +174,42 @@ void PairLJCharmmCoulLongOpt::eval() } } - fforce = (forcecoul + forcelj) * r2inv; + double fpair = (forcecoul + forcelj) * r2inv; - tmpfx += delx*fforce; - tmpfy += dely*fforce; - tmpfz += delz*fforce; + tmpfx += delx*fpair; + tmpfy += dely*fpair; + tmpfz += delz*fpair; if (NEWTON_PAIR || j < nlocal) { - ff[j].x -= delx*fforce; - ff[j].y -= dely*fforce; - ff[j].z -= delz*fforce; + ff[j].x -= delx*fpair; + ff[j].y -= dely*fpair; + ff[j].z -= delz*fpair; } if (EFLAG) { - if (NEWTON_PAIR || j < nlocal) factor = 1.0; - else factor = 0.5; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) - phicoul = prefactor*erfc; + ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; - phicoul = tmp_coef3 * table; + ecoul = tmp_coef3 * table; } - eng_coul += factor*phicoul; - } + } else ecoul = 0.0; + if (rsq < cut_ljsq) { fast_alpha_t& a = tabsixi[jtype]; - philj = r6inv*(a.lj3*r6inv-a.lj4); + evdwl = r6inv*(a.lj3*r6inv-a.lj4); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (tmp_coef2 + 2.0*rsq) * tmp_coef1; - philj *= switch1; + evdwl *= switch1; } - eng_vdwl += factor*philj; - } - } - - if (VFLAG == 1) { - if (NEWTON_PAIR == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; + } else evdwl = 0.0; } + + if (EVFLAG) ev_tally(i,j,nlocal,NEWTON_PAIR, + evdwl,ecoul,fpair,delx,dely,delz); } + } else { factor_coul = special_coul[j/nall]; factor_lj = special_lj[j/nall]; @@ -276,61 +267,54 @@ void PairLJCharmmCoulLongOpt::eval() } } - fforce = (forcecoul + factor_lj*forcelj) * r2inv; + double fpair = (forcecoul + factor_lj*forcelj) * r2inv; - tmpfx += delx*fforce; - tmpfy += dely*fforce; - tmpfz += delz*fforce; + tmpfx += delx*fpair; + tmpfy += dely*fpair; + tmpfz += delz*fpair; if (NEWTON_PAIR || j < nlocal) { - ff[j].x -= delx*fforce; - ff[j].y -= dely*fforce; - ff[j].z -= delz*fforce; + ff[j].x -= delx*fpair; + ff[j].y -= dely*fpair; + ff[j].z -= delz*fpair; } if (EFLAG) { - if (NEWTON_PAIR || j < nlocal) factor = 1.0; - else factor = 0.5; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) - phicoul = prefactor*erfc; + ecoul = prefactor*erfc; else { table = etable[itable] + fraction*detable[itable]; - phicoul = tmp_coef3 * table; + ecoul = tmp_coef3 * table; } - if (factor_coul < 1.0) - phicoul -= (1.0-factor_coul)*prefactor; - eng_coul += factor*phicoul; - } + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; + } else ecoul = 0.0; + if (rsq < cut_ljsq) { fast_alpha_t& a = tabsixi[jtype]; - philj = r6inv*(a.lj3*r6inv-a.lj4); + evdwl = r6inv*(a.lj3*r6inv-a.lj4); if (rsq > cut_lj_innersq) { switch1 = (cut_ljsq-rsq) * (cut_ljsq-rsq) * (tmp_coef2 + 2.0*rsq) * tmp_coef1; - philj *= switch1; + evdwl *= switch1; } - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (VFLAG == 1) { - if (NEWTON_PAIR == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (EVFLAG) ev_tally(i,j,nlocal,NEWTON_PAIR, + evdwl,ecoul,fpair,delx,dely,delz); } } } + ff[i].x += tmpfx; ff[i].y += tmpfy; ff[i].z += tmpfz; } - if (VFLAG == 2) virial_compute(); + free(fast_alpha); fast_alpha = 0; + + if (vflag_fdotr) virial_compute(); } } diff --git a/src/OPT/pair_lj_cut_opt.cpp b/src/OPT/pair_lj_cut_opt.cpp index db81bab5bc..d939727a59 100644 --- a/src/OPT/pair_lj_cut_opt.cpp +++ b/src/OPT/pair_lj_cut_opt.cpp @@ -30,34 +30,19 @@ PairLJCutOpt::PairLJCutOpt(LAMMPS *lmp) : PairLJCut(lmp) {} void PairLJCutOpt::compute(int eflag, int vflag) { - if (eflag) { - if (force->newton_pair) { - switch (vflag) { - case 0: return eval<1,0,1>(); - case 1: return eval<1,1,1>(); - case 2: return eval<1,2,1>(); - } + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + if (evflag) { + if (eflag) { + if (force->newton_pair) return eval<1,1,1>(); + else return eval<1,1,0>(); } else { - switch (vflag) { - case 0: return eval<1,0,0>(); - case 1: return eval<1,1,0>(); - case 2: return eval<1,2,0>(); - } + if (force->newton_pair) return eval<1,0,1>(); + else return eval<1,0,0>(); } - } else { - if (force->newton_pair) { - switch (vflag) { - case 0: return eval<0,0,1>(); - case 1: return eval<0,1,1>(); - case 2: return eval<0,2,1>(); - } - } else { - switch (vflag) { - case 0: return eval<0,0,0>(); - case 1: return eval<0,1,0>(); - case 2: return eval<0,2,0>(); - } - } + if (force->newton_pair) return eval<0,0,1>(); + else return eval<0,0,0>(); } } diff --git a/src/OPT/pair_lj_cut_opt.h b/src/OPT/pair_lj_cut_opt.h index 89d97d9059..6a9e9c514c 100644 --- a/src/OPT/pair_lj_cut_opt.h +++ b/src/OPT/pair_lj_cut_opt.h @@ -35,10 +35,10 @@ class PairLJCutOpt : public PairLJCut { void compute(int, int); private: - template < int EFLAG, int VFLAG, int NEWTON_PAIR > void eval(); + template < int EVFLAG, int EFLAG, int NEWTON_PAIR > void eval(); }; -template < int EFLAG, int VFLAG, int NEWTON_PAIR > +template < int EVFLAG, int EFLAG, int NEWTON_PAIR > void PairLJCutOpt::eval() { typedef struct { double x,y,z; } vec3_t; @@ -49,9 +49,7 @@ void PairLJCutOpt::eval() } fast_alpha_t; int i,j,ii,jj,inum,jnum,itype,jtype; - - eng_vdwl = 0.0; - if (VFLAG) for (i = 0; i < 6; i++) virial[i] = 0.0; + double evdwl = 0.0; double** __restrict__ x = atom->x; double** __restrict__ f = atom->f; @@ -119,37 +117,28 @@ void PairLJCutOpt::eval() double r2inv = 1.0/rsq; double r6inv = r2inv*r2inv*r2inv; double forcelj = r6inv * (a.lj1*r6inv - a.lj2); - if (EFLAG) { - double philj = r6inv*(a.lj3*r6inv-a.lj4) - a.offset; - if (NEWTON_PAIR || j < nlocal) eng_vdwl += philj; - else eng_vdwl += 0.5*philj; - } - double fforce = forcelj*r2inv; + double fpair = forcelj*r2inv; - tmpfx += delx*fforce; - tmpfy += dely*fforce; - tmpfz += delz*fforce; + tmpfx += delx*fpair; + tmpfy += dely*fpair; + tmpfz += delz*fpair; if (NEWTON_PAIR || j < nlocal) { - ff[j].x -= delx*fforce; - ff[j].y -= dely*fforce; - ff[j].z -= delz*fforce; - } - - if (VFLAG == 1) { - if (NEWTON_PAIR == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; + ff[j].x -= delx*fpair; + ff[j].y -= dely*fpair; + ff[j].z -= delz*fpair; } + + if (EFLAG) evdwl = r6inv*(a.lj3*r6inv-a.lj4) - a.offset; + + if (EVFLAG) + ev_tally(i,j,nlocal,NEWTON_PAIR, + evdwl,0.0,fpair,delx,dely,delz); } } else { - factor_lj = special_lj[j/nall]; j = j % nall; + double delx = xtmp - xx[j].x; double dely = ytmp - xx[j].y; double delz = ztmp - xx[j].z; @@ -160,49 +149,40 @@ void PairLJCutOpt::eval() fast_alpha_t& a = tabsixi[jtype]; if (rsq < a.cutsq) { - double r2inv = 1.0/rsq; double r6inv = r2inv*r2inv*r2inv; - fast_alpha_t& a = tabsixi[jtype]; double forcelj = r6inv * (a.lj1*r6inv - a.lj2); - if (EFLAG) { - double philj = r6inv*(a.lj3*r6inv-a.lj4) - a.offset; - if (NEWTON_PAIR || j < nlocal) eng_vdwl += factor_lj*philj; - else eng_vdwl += 0.5*factor_lj*philj; - } + double fpair = factor_lj*forcelj*r2inv; - double fforce = factor_lj*forcelj*r2inv; - - tmpfx += delx*fforce; - tmpfy += dely*fforce; - tmpfz += delz*fforce; + tmpfx += delx*fpair; + tmpfy += dely*fpair; + tmpfz += delz*fpair; if (NEWTON_PAIR || j < nlocal) { - ff[j].x -= delx*fforce; - ff[j].y -= dely*fforce; - ff[j].z -= delz*fforce; + ff[j].x -= delx*fpair; + ff[j].y -= dely*fpair; + ff[j].z -= delz*fpair; + } + + if (EFLAG) { + evdwl = r6inv*(a.lj3*r6inv-a.lj4) - a.offset; + evdwl *= factor_lj; } - if (VFLAG == 1) { - if (NEWTON_PAIR == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (EVFLAG) ev_tally(i,j,nlocal,NEWTON_PAIR, + evdwl,0.0,fpair,delx,dely,delz); } } } + ff[i].x += tmpfx; ff[i].y += tmpfy; ff[i].z += tmpfz; } - - if (VFLAG == 2) virial_compute(); - + free(fast_alpha); fast_alpha = 0; + + if (vflag_fdotr) virial_compute(); } } diff --git a/src/OPT/pair_morse_opt.cpp b/src/OPT/pair_morse_opt.cpp index 6f6cb3281a..1cf96d85b4 100644 --- a/src/OPT/pair_morse_opt.cpp +++ b/src/OPT/pair_morse_opt.cpp @@ -30,34 +30,19 @@ PairMorseOpt::PairMorseOpt(LAMMPS *lmp) : PairMorse(lmp) {} void PairMorseOpt::compute(int eflag, int vflag) { - if (eflag) { - if (force->newton_pair) { - switch (vflag) { - case 0: return eval<1,0,1>(); - case 1: return eval<1,1,1>(); - case 2: return eval<1,2,1>(); - } + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + if (evflag) { + if (eflag) { + if (force->newton_pair) return eval<1,1,1>(); + else return eval<1,1,0>(); } else { - switch (vflag) { - case 0: return eval<1,0,0>(); - case 1: return eval<1,1,0>(); - case 2: return eval<1,2,0>(); - } + if (force->newton_pair) return eval<1,0,1>(); + else return eval<1,0,0>(); } - } else { - if (force->newton_pair) { - switch (vflag) { - case 0: return eval<0,0,1>(); - case 1: return eval<0,1,1>(); - case 2: return eval<0,2,1>(); - } - } else { - switch (vflag) { - case 0: return eval<0,0,0>(); - case 1: return eval<0,1,0>(); - case 2: return eval<0,2,0>(); - } - } + if (force->newton_pair) return eval<0,0,1>(); + else return eval<0,0,0>(); } } diff --git a/src/OPT/pair_morse_opt.h b/src/OPT/pair_morse_opt.h index b975375227..dc5b2b9fc4 100644 --- a/src/OPT/pair_morse_opt.h +++ b/src/OPT/pair_morse_opt.h @@ -36,10 +36,10 @@ class PairMorseOpt : public PairMorse { void compute(int, int); private: - template < int EFLAG, int VFLAG, int NEWTON_PAIR > void eval(); + template < int EVFLAG, int EFLAG, int NEWTON_PAIR > void eval(); }; -template < int EFLAG, int VFLAG, int NEWTON_PAIR > +template < int EVFLAG, int EFLAG, int NEWTON_PAIR > void PairMorseOpt::eval() { typedef struct { double x,y,z; } vec3_t; @@ -50,9 +50,7 @@ void PairMorseOpt::eval() } fast_alpha_t; int i,j,ii,jj,inum,jnum,itype,jtype; - - eng_vdwl = 0.0; - if (VFLAG) for (i = 0; i < 6; i++) virial[i] = 0.0; + double evdwl = 0.0; double** __restrict__ x = atom->x; double** __restrict__ f = atom->f; @@ -119,35 +117,23 @@ void PairMorseOpt::eval() double r = sqrt(rsq); double dr = r - a.r0; double dexp = exp(-a.alpha * dr); - double fforce = a.morse1 * (dexp*dexp - dexp) / r; - if (EFLAG) { - double phi = a.d0 * (dexp*dexp - 2.0*dexp) - a.offset; - if (NEWTON_PAIR || j < nlocal) { - eng_vdwl += phi; - } else { - eng_vdwl += 0.5*phi; - } - } - - tmpfx += delx*fforce; - tmpfy += dely*fforce; - tmpfz += delz*fforce; + double fpair = a.morse1 * (dexp*dexp - dexp) / r; + + tmpfx += delx*fpair; + tmpfy += dely*fpair; + tmpfz += delz*fpair; if (NEWTON_PAIR || j < nlocal) { - ff[j].x -= delx*fforce; - ff[j].y -= dely*fforce; - ff[j].z -= delz*fforce; - } - - if (VFLAG == 1) { - if (NEWTON_PAIR == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; + ff[j].x -= delx*fpair; + ff[j].y -= dely*fpair; + ff[j].z -= delz*fpair; } + + if (EFLAG) evdwl = a.d0 * (dexp*dexp - 2.0*dexp) - a.offset; + + if (EVFLAG) ev_tally(i,j,nlocal,NEWTON_PAIR, + evdwl,0.0,fpair,delx,dely,delz); } + } else { factor_lj = special_lj[j/nall]; j = j % nall; @@ -164,46 +150,36 @@ void PairMorseOpt::eval() double r = sqrt(rsq); double dr = r - a.r0; double dexp = exp(-a.alpha * dr); - double fforce = factor_lj * a.morse1 * (dexp*dexp - dexp) / r; - if (EFLAG) { - double phi = a.d0 * (dexp*dexp - 2.0*dexp) - a.offset; - if (NEWTON_PAIR || j < nlocal) { - eng_vdwl += factor_lj*phi; - } else { - eng_vdwl += 0.5*factor_lj*phi; - } - } - - tmpfx += delx*fforce; - tmpfy += dely*fforce; - tmpfz += delz*fforce; + double fpair = factor_lj * a.morse1 * (dexp*dexp - dexp) / r; + + tmpfx += delx*fpair; + tmpfy += dely*fpair; + tmpfz += delz*fpair; if (NEWTON_PAIR || j < nlocal) { - ff[j].x -= delx*fforce; - ff[j].y -= dely*fforce; - ff[j].z -= delz*fforce; + ff[j].x -= delx*fpair; + ff[j].y -= dely*fpair; + ff[j].z -= delz*fpair; + } + + if (EFLAG) { + evdwl = a.d0 * (dexp*dexp - 2.0*dexp) - a.offset; + evdwl *= factor_lj; } - if (VFLAG == 1) { - if (NEWTON_PAIR == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (EVFLAG) ev_tally(i,j,nlocal,NEWTON_PAIR, + evdwl,0.0,fpair,delx,dely,delz); } } } + ff[i].x += tmpfx; ff[i].y += tmpfy; ff[i].z += tmpfz; } - - if (VFLAG == 2) virial_compute(); - + free(fast_alpha); fast_alpha = 0; - + + if (vflag_fdotr) virial_compute(); } } diff --git a/src/USER-ACKLAND/compute_ackland_atom.cpp b/src/USER-ACKLAND/compute_ackland_atom.cpp index 536631f314..17d4c6c35c 100644 --- a/src/USER-ACKLAND/compute_ackland_atom.cpp +++ b/src/USER-ACKLAND/compute_ackland_atom.cpp @@ -96,9 +96,8 @@ void ComputeAcklandAtom::init_list(int id, NeighList *ptr) void ComputeAcklandAtom::compute_peratom() { int i,j,ii,jj,k,n,inum,jnum; - double xtmp,ytmp,ztmp,delx,dely,delz,rsq,value; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *ilist,*jlist,*numneigh,**firstneigh; - double pairs[66]; int chi[8]; // grow structure array if necessary @@ -125,7 +124,6 @@ void ComputeAcklandAtom::compute_peratom() double **x = atom->x; int *mask = atom->mask; - int nlocal = atom->nlocal; int nall = atom->nlocal + atom->nghost; double cutsq = force->pair->cutforce * force->pair->cutforce; @@ -270,7 +268,7 @@ void ComputeAcklandAtom::compute_peratom() else structure[i] = HCP; - } // end loop over all particles + } else structure[i] = 0.0; } } diff --git a/src/USER-EWALDN/pair_buck_coul.cpp b/src/USER-EWALDN/pair_buck_coul.cpp index 666a3a6d04..4396ecf832 100644 --- a/src/USER-EWALDN/pair_buck_coul.cpp +++ b/src/USER-EWALDN/pair_buck_coul.cpp @@ -442,12 +442,17 @@ void PairBuckCoul::read_restart_settings(FILE *fp) void PairBuckCoul::compute(int eflag, int vflag) { + double evdwl,ecoul,fpair; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + double **x = atom->x, *x0 = x[0]; double **f = atom->f, *f0 = f[0], *fi = f0; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -457,13 +462,10 @@ void PairBuckCoul::compute(int eflag, int vflag) int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; double qi, qri, *cutsqi, *cut_bucksqi, *buck1i, *buck2i, *buckai, *buckci, *rhoinvi, *offseti; - double r, rsq, r2inv, force_coul, force_buck, fforce, factor; + double r, rsq, r2inv, force_coul, force_buck; double g2 = g_ewald*g_ewald, g6 = g2*g2*g2, g8 = g6*g2; vector xi, d; - eng_vdwl = eng_coul = 0.0; // reset energy&virial - if (vflag) memset(virial, 0, sizeof(shape)); - ineighn = (ineigh = list->ilist)+list->inum; for (; ineightype; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *x0 = atom->x[0], *f0 = atom->f[0], *fi = f0, *q = atom->q; double *special_coul = force->special_coul; double *special_lj = force->special_lj; @@ -619,7 +605,7 @@ void PairBuckCoul::compute_inner() int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; int i, j, order1 = (ewald_order|(ewald_off^-1))&(1<<1); - double qri, *cut_bucksqi, *buck1i, *buck2i, *rhoinvi, *offseti; + double qri, *cut_bucksqi, *buck1i, *buck2i, *rhoinvi; vector xi, d; ineighn = (ineigh = listinner->ilist)+listinner->inum; @@ -628,7 +614,6 @@ void PairBuckCoul::compute_inner() i = *ineigh; fi = f0+3*i; qri = qqrd2e*q[i]; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); - offseti = offset[typei = type[i]]; cut_bucksqi = cut_bucksq[typei]; buck1i = buck1[typei]; buck2i = buck2[typei]; rhoinvi = rhoinv[typei]; jneighn = (jneigh = listinner->firstneigh[i])+listinner->numneigh[i]; @@ -659,23 +644,23 @@ void PairBuckCoul::compute_inner() } else force_buck = 0.0; - fforce = (force_coul + force_buck) * r2inv; + fpair = (force_coul + force_buck) * r2inv; if (rsq > cut_out_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; - fforce *= 1.0 + rsw*rsw*(2.0*rsw-3.0); + fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; - fi[0] += f = d[0]*fforce; fj[0] -= f; - fi[1] += f = d[1]*fforce; fj[1] -= f; - fi[2] += f = d[2]*fforce; fj[2] -= f; + fi[0] += f = d[0]*fpair; fj[0] -= f; + fi[1] += f = d[1]*fpair; fj[1] -= f; + fi[2] += f = d[2]*fpair; fj[2] -= f; } else { - fi[0] += d[0]*fforce; - fi[1] += d[1]*fforce; - fi[2] += d[2]*fforce; + fi[0] += d[0]*fpair; + fi[1] += d[1]*fpair; + fi[2] += d[2]*fpair; } } } @@ -685,11 +670,11 @@ void PairBuckCoul::compute_inner() void PairBuckCoul::compute_middle() { - double r, rsq, r2inv, force_coul, force_buck, fforce; + double r, rsq, r2inv, force_coul, force_buck, fpair; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *x0 = atom->x[0], *f0 = atom->f[0], *fi = f0, *q = atom->q; double *special_coul = force->special_coul; double *special_lj = force->special_lj; @@ -710,7 +695,7 @@ void PairBuckCoul::compute_middle() int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; int i, j, order1 = (ewald_order|(ewald_off^-1))&(1<<1); - double qri, *cut_bucksqi, *buck1i, *buck2i, *rhoinvi, *offseti; + double qri, *cut_bucksqi, *buck1i, *buck2i, *rhoinvi; vector xi, d; ineighn = (ineigh = listmiddle->ilist)+listmiddle->inum; @@ -719,7 +704,6 @@ void PairBuckCoul::compute_middle() i = *ineigh; fi = f0+3*i; qri = qqrd2e*q[i]; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); - offseti = offset[typei = type[i]]; cut_bucksqi = cut_bucksq[typei]; buck1i = buck1[typei]; buck2i = buck2[typei]; rhoinvi = rhoinv[typei]; jneighn = (jneigh = listmiddle->firstneigh[i])+listmiddle->numneigh[i]; @@ -751,27 +735,27 @@ void PairBuckCoul::compute_middle() } else force_buck = 0.0; - fforce = (force_coul + force_buck) * r2inv; + fpair = (force_coul + force_buck) * r2inv; if (rsq < cut_in_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; - fforce *= rsw*rsw*(3.0 - 2.0*rsw); + fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; - fforce *= 1.0 + rsw*rsw*(2.0*rsw-3.0); + fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; - fi[0] += f = d[0]*fforce; fj[0] -= f; - fi[1] += f = d[1]*fforce; fj[1] -= f; - fi[2] += f = d[2]*fforce; fj[2] -= f; + fi[0] += f = d[0]*fpair; fj[0] -= f; + fi[1] += f = d[1]*fpair; fj[1] -= f; + fi[2] += f = d[2]*fpair; fj[2] -= f; } else { - fi[0] += d[0]*fforce; - fi[1] += d[1]*fforce; - fi[2] += d[2]*fforce; + fi[0] += d[0]*fpair; + fi[1] += d[1]*fpair; + fi[2] += d[2]*fpair; } } } @@ -781,12 +765,17 @@ void PairBuckCoul::compute_middle() void PairBuckCoul::compute_outer(int eflag, int vflag) { + double evdwl,ecoul,fpair; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; + double **x = atom->x, *x0 = x[0]; double **f = atom->f, *f0 = f[0], *fi = f0; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -796,7 +785,7 @@ void PairBuckCoul::compute_outer(int eflag, int vflag) int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni, respa_flag; double qi, qri, *cutsqi, *cut_bucksqi, *buck1i, *buck2i, *buckai, *buckci, *rhoinvi, *offseti; - double r, rsq, r2inv, force_coul, force_buck, fforce, factor; + double r, rsq, r2inv, force_coul, force_buck; double g2 = g_ewald*g_ewald, g6 = g2*g2*g2, g8 = g6*g2; double respa_buck, respa_coul, frespa; vector xi, d; @@ -808,9 +797,6 @@ void PairBuckCoul::compute_outer(int eflag, int vflag) double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; - eng_vdwl = eng_coul = 0.0; // reset energy&virial - if (vflag) memset(virial, 0, sizeof(shape)); - ineighn = (ineigh = listouter->ilist)+listouter->inum; for (; ineighcut_in_off_sq)&&(rsqx, *x0 = x[0]; double **f = atom->f, *f0 = f[0], *fi = f0; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -460,12 +465,10 @@ void PairLJCoul::compute(int eflag, int vflag) int i, j, order1 = ewald_order&(1<<1), order6 = ewald_order&(1<<6); int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; double qi, qri, *cutsqi, *cut_ljsqi, *lj1i, *lj2i, *lj3i, *lj4i, *offseti; - double rsq, r2inv, force_coul, force_lj, fforce, factor; + double rsq, r2inv, force_coul, force_lj; double g2 = g_ewald*g_ewald, g6 = g2*g2*g2, g8 = g6*g2; vector xi, d; - eng_vdwl = eng_coul = 0.0; // reset energy&virial - if (vflag) memset(virial, 0, sizeof(shape)); ineighn = (ineigh = list->ilist)+list->inum; for (; ineigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; - factor = newton_pair || jtype; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *x0 = atom->x[0], *f0 = atom->f[0], *fi = f0, *q = atom->q; double *special_coul = force->special_coul; double *special_lj = force->special_lj; @@ -618,7 +605,7 @@ void PairLJCoul::compute_inner() int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; int i, j, order1 = (ewald_order|(ewald_off^-1))&(1<<1); - double qri, *cut_ljsqi, *lj1i, *lj2i, *offseti; + double qri, *cut_ljsqi, *lj1i, *lj2i; vector xi, d; ineighn = (ineigh = list->ilist)+list->inum; @@ -627,7 +614,6 @@ void PairLJCoul::compute_inner() i = *ineigh; fi = f0+3*i; qri = qqrd2e*q[i]; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); - offseti = offset[typei = type[i]]; cut_ljsqi = cut_ljsq[typei]; lj1i = lj1[typei]; lj2i = lj2[typei]; jneighn = (jneigh = list->firstneigh[i])+list->numneigh[i]; @@ -656,23 +642,23 @@ void PairLJCoul::compute_inner() } else force_lj = 0.0; - fforce = (force_coul + force_lj) * r2inv; + fpair = (force_coul + force_lj) * r2inv; if (rsq > cut_out_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; - fforce *= 1.0 + rsw*rsw*(2.0*rsw-3.0); + fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; - fi[0] += f = d[0]*fforce; fj[0] -= f; - fi[1] += f = d[1]*fforce; fj[1] -= f; - fi[2] += f = d[2]*fforce; fj[2] -= f; + fi[0] += f = d[0]*fpair; fj[0] -= f; + fi[1] += f = d[1]*fpair; fj[1] -= f; + fi[2] += f = d[2]*fpair; fj[2] -= f; } else { - fi[0] += d[0]*fforce; - fi[1] += d[1]*fforce; - fi[2] += d[2]*fforce; + fi[0] += d[0]*fpair; + fi[1] += d[1]*fpair; + fi[2] += d[2]*fpair; } } } @@ -682,11 +668,11 @@ void PairLJCoul::compute_inner() void PairLJCoul::compute_middle() { - double rsq, r2inv, force_coul, force_lj, fforce; + double rsq, r2inv, force_coul, force_lj, fpair; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *x0 = atom->x[0], *f0 = atom->f[0], *fi = f0, *q = atom->q; double *special_coul = force->special_coul; double *special_lj = force->special_lj; @@ -707,7 +693,7 @@ void PairLJCoul::compute_middle() int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni; int i, j, order1 = (ewald_order|(ewald_off^-1))&(1<<1); - double qri, *cut_ljsqi, *lj1i, *lj2i, *offseti; + double qri, *cut_ljsqi, *lj1i, *lj2i; vector xi, d; ineighn = (ineigh = list->ilist)+list->inum; @@ -716,7 +702,6 @@ void PairLJCoul::compute_middle() i = *ineigh; fi = f0+3*i; qri = qqrd2e*q[i]; memcpy(xi, x0+(i+(i<<1)), sizeof(vector)); - offseti = offset[typei = type[i]]; cut_ljsqi = cut_ljsq[typei]; lj1i = lj1[typei]; lj2i = lj2[typei]; jneighn = (jneigh = list->firstneigh[i])+list->numneigh[i]; @@ -746,27 +731,27 @@ void PairLJCoul::compute_middle() } else force_lj = 0.0; - fforce = (force_coul + force_lj) * r2inv; + fpair = (force_coul + force_lj) * r2inv; if (rsq < cut_in_on_sq) { // switching register double rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; - fforce *= rsw*rsw*(3.0 - 2.0*rsw); + fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { register double rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; - fforce *= 1.0 + rsw*rsw*(2.0*rsw-3.0); + fpair *= 1.0 + rsw*rsw*(2.0*rsw-3.0); } if (newton_pair || j < nlocal) { // force update register double *fj = f0+(j+(j<<1)), f; - fi[0] += f = d[0]*fforce; fj[0] -= f; - fi[1] += f = d[1]*fforce; fj[1] -= f; - fi[2] += f = d[2]*fforce; fj[2] -= f; + fi[0] += f = d[0]*fpair; fj[0] -= f; + fi[1] += f = d[1]*fpair; fj[1] -= f; + fi[2] += f = d[2]*fpair; fj[2] -= f; } else { - fi[0] += d[0]*fforce; - fi[1] += d[1]*fforce; - fi[2] += d[2]*fforce; + fi[0] += d[0]*fpair; + fi[1] += d[1]*fpair; + fi[2] += d[2]*fpair; } } } @@ -776,12 +761,17 @@ void PairLJCoul::compute_middle() void PairLJCoul::compute_outer(int eflag, int vflag) { + double evdwl,ecoul,fpair; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; + double **x = atom->x, *x0 = x[0]; double **f = atom->f, *f0 = f[0], *fi = f0; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -790,7 +780,7 @@ void PairLJCoul::compute_outer(int eflag, int vflag) int i, j, order1 = ewald_order&(1<<1), order6 = ewald_order&(1<<6); int *ineigh, *ineighn, *jneigh, *jneighn, typei, typej, ni, respa_flag; double qi, qri, *cutsqi, *cut_ljsqi, *lj1i, *lj2i, *lj3i, *lj4i, *offseti; - double rsq, r2inv, force_coul, force_lj, fforce, factor; + double rsq, r2inv, force_coul, force_lj; double g2 = g_ewald*g_ewald, g6 = g2*g2*g2, g8 = g6*g2; double respa_lj, respa_coul, frespa; vector xi, d; @@ -802,9 +792,6 @@ void PairLJCoul::compute_outer(int eflag, int vflag) double cut_in_off_sq = cut_in_off*cut_in_off; double cut_in_on_sq = cut_in_on*cut_in_on; - eng_vdwl = eng_coul = 0.0; // reset energy&virial - if (vflag) memset(virial, 0, sizeof(shape)); - ineighn = (ineigh = list->ilist)+list->inum; for (; ineigh= cutsqi[typej = type[j]]) continue; r2inv = 1.0/rsq; - factor = newton_pair || jcut_in_off_sq)&&(rsqall("Illegal compute attribute/atom command"); nmax = 0; @@ -69,10 +65,8 @@ ComputeAttributeAtom::ComputeAttributeAtom(LAMMPS *lmp, int narg, char **arg) : ComputeAttributeAtom::~ComputeAttributeAtom() { - if (allocate) { - memory->sfree(s_attribute); - memory->destroy_2d_double_array(v_attribute); - } + memory->sfree(s_attribute); + memory->destroy_2d_double_array(v_attribute); } /* ---------------------------------------------------------------------- */ @@ -81,19 +75,21 @@ void ComputeAttributeAtom::compute_peratom() { // grow attribute array if necessary - if (allocate && atom->nlocal > nmax) { + if (atom->nlocal > nmax) { if (size_peratom == 0) { memory->sfree(s_attribute); nmax = atom->nmax; s_attribute = (double *) memory->smalloc(nmax*sizeof(double), "compute/attribute/atom:s_attribute"); + scalar_atom = s_attribute; } else { memory->destroy_2d_double_array(v_attribute); nmax = atom->nmax; v_attribute = memory->create_2d_double_array(nmax,size_peratom, "compute/attribute/atom:v_attribute"); + vector_atom = v_attribute; } } @@ -166,14 +162,40 @@ void ComputeAttributeAtom::compute_peratom() if (mask[i] & groupbit) s_attribute[i] = f[i][2]; else s_attribute[i] = 0.0; - } else if (which == XYZ) v_attribute = x; - else if (which == V) v_attribute = v; - else if (which == F) v_attribute = f; - - // set appropriate compute ptr to local array - - if (size_peratom == 0) scalar_atom = s_attribute; - else vector_atom = v_attribute; + } else if (which == XYZ) { + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + v_attribute[i][0] = x[i][0]; + v_attribute[i][1] = x[i][1]; + v_attribute[i][2] = x[i][2]; + } else { + v_attribute[i][0] = 0.0; + v_attribute[i][1] = 0.0; + v_attribute[i][2] = 0.0; + } + } else if (which == V) { + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + v_attribute[i][0] = v[i][0]; + v_attribute[i][1] = v[i][1]; + v_attribute[i][2] = v[i][2]; + } else { + v_attribute[i][0] = 0.0; + v_attribute[i][1] = 0.0; + v_attribute[i][2] = 0.0; + } + } else if (which == F) { + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + v_attribute[i][0] = f[i][0]; + v_attribute[i][1] = f[i][1]; + v_attribute[i][2] = f[i][2]; + } else { + v_attribute[i][0] = 0.0; + v_attribute[i][1] = 0.0; + v_attribute[i][2] = 0.0; + } + } } /* ---------------------------------------------------------------------- @@ -183,9 +205,7 @@ void ComputeAttributeAtom::compute_peratom() double ComputeAttributeAtom::memory_usage() { double bytes = 0.0; - if (allocate) { - if (size_peratom == 0) bytes = nmax * sizeof(double); - else bytes = size_peratom * nmax * sizeof(double); - } + if (size_peratom == 0) bytes = nmax * sizeof(double); + else bytes = size_peratom * nmax * sizeof(double); return bytes; } diff --git a/src/compute_centro_atom.cpp b/src/compute_centro_atom.cpp index 768c2e4662..1d5e605057 100644 --- a/src/compute_centro_atom.cpp +++ b/src/compute_centro_atom.cpp @@ -113,7 +113,6 @@ void ComputeCentroAtom::compute_peratom() double **x = atom->x; int *mask = atom->mask; - int nlocal = atom->nlocal; int nall = atom->nlocal + atom->nghost; double cutsq = force->pair->cutforce * force->pair->cutforce; diff --git a/src/compute_coord_atom.cpp b/src/compute_coord_atom.cpp index b7fd2dea97..025703471b 100644 --- a/src/compute_coord_atom.cpp +++ b/src/compute_coord_atom.cpp @@ -112,7 +112,6 @@ void ComputeCoordAtom::compute_peratom() double **x = atom->x; int *mask = atom->mask; - int nlocal = atom->nlocal; int nall = atom->nlocal + atom->nghost; double cutsq = cutoff*cutoff; diff --git a/src/compute_pe.cpp b/src/compute_pe.cpp index d929ec72c3..e3f5bbba38 100644 --- a/src/compute_pe.cpp +++ b/src/compute_pe.cpp @@ -74,12 +74,8 @@ double ComputePE::compute_scalar() invoked = 1; double one = 0.0; - if (pairflag) { - if (force->pair) one += force->pair->eng_vdwl + force->pair->eng_coul; - if (force->bond) one += force->bond->eng_vdwl; - if (force->dihedral) - one += force->dihedral->eng_vdwl + force->dihedral->eng_coul; - } + if (pairflag && force->pair) + one += force->pair->eng_vdwl + force->pair->eng_coul; if (atom->molecular) { if (bondflag && force->bond) one += force->bond->energy; diff --git a/src/compute_pressure.cpp b/src/compute_pressure.cpp index 2e9a741ede..1b27f85fd9 100644 --- a/src/compute_pressure.cpp +++ b/src/compute_pressure.cpp @@ -35,9 +35,15 @@ using namespace LAMMPS_NS; ComputePressure::ComputePressure(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg) { - if (narg != 4) error->all("Illegal compute pressure command"); + if (narg < 4) error->all("Illegal compute pressure command"); if (igroup) error->all("Compute pressure must use group all"); + scalar_flag = vector_flag = 1; + size_vector = 6; + extensive = 0; + pressflag = 1; + timeflag = 1; + // store temperature ID used by pressure computation // insure it is valid for temperature computation @@ -53,13 +59,32 @@ ComputePressure::ComputePressure(LAMMPS *lmp, int narg, char **arg) : if (modify->compute[icompute]->tempflag == 0) error->all("Compute pressure temp ID does not compute temperature"); - // settings + // process optional args - scalar_flag = vector_flag = 1; - size_vector = 6; - extensive = 0; - pressflag = 1; - timeflag = 1; + if (narg == 4) { + keflag = 1; + pairflag = 1; + bondflag = angleflag = dihedralflag = improperflag = 1; + fixflag = kspaceflag = 1; + } else { + keflag = 0; + pairflag = 0; + bondflag = angleflag = dihedralflag = improperflag = 0; + fixflag = kspaceflag = 0; + int iarg = 4; + while (iarg < narg) { + if (strcmp(arg[iarg],"ke") == 0) keflag = 1; + else if (strcmp(arg[iarg],"pair") == 0) pairflag = 1; + else if (strcmp(arg[iarg],"bond") == 0) bondflag = 1; + else if (strcmp(arg[iarg],"angle") == 0) angleflag = 1; + else if (strcmp(arg[iarg],"dihedral") == 0) dihedralflag = 1; + else if (strcmp(arg[iarg],"improper") == 0) improperflag = 1; + else if (strcmp(arg[iarg],"fix") == 0) fixflag = 1; + else if (strcmp(arg[iarg],"kspace") == 0) kspaceflag = 1; + else error->all("Illegal compute stress/atom command"); + iarg++; + } + } vector = new double[6]; nvirial = 0; @@ -95,34 +120,35 @@ void ComputePressure::init() nvirial = 0; vptr = NULL; - if (force->pair) nvirial++; - if (atom->molecular && force->bond) nvirial++; - if (atom->molecular && force->angle) nvirial++; - if (atom->molecular && force->dihedral) nvirial++; - if (atom->molecular && force->improper) nvirial++; - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->virial_flag) nvirial++; + if (pairflag && force->pair) nvirial++; + if (bondflag && atom->molecular && force->bond) nvirial++; + if (angleflag && atom->molecular && force->angle) nvirial++; + if (dihedralflag && atom->molecular && force->dihedral) nvirial++; + if (improperflag && atom->molecular && force->improper) nvirial++; + if (fixflag) + for (int i = 0; i < modify->nfix; i++) + if (modify->fix[i]->virial_flag) nvirial++; if (nvirial) { vptr = new double*[nvirial]; nvirial = 0; - if (force->pair) vptr[nvirial++] = force->pair->virial; - if (force->bond) vptr[nvirial++] = force->bond->virial; - if (force->angle) vptr[nvirial++] = force->angle->virial; - if (force->dihedral) vptr[nvirial++] = force->dihedral->virial; - if (force->improper) vptr[nvirial++] = force->improper->virial; - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->virial_flag) - vptr[nvirial++] = modify->fix[i]->virial; + if (pairflag && force->pair) vptr[nvirial++] = force->pair->virial; + if (bondflag && force->bond) vptr[nvirial++] = force->bond->virial; + if (angleflag && force->angle) vptr[nvirial++] = force->angle->virial; + if (dihedralflag && force->dihedral) + vptr[nvirial++] = force->dihedral->virial; + if (improperflag && force->improper) + vptr[nvirial++] = force->improper->virial; + if (fixflag) + for (int i = 0; i < modify->nfix; i++) + if (modify->fix[i]->virial_flag) + vptr[nvirial++] = modify->fix[i]->virial; } // flag Kspace contribution separately, since not summed across procs - kspaceflag = 0; - if (force->kspace) { - kspaceflag = 1; - kspace_virial = force->kspace->virial; - } + if (kspaceflag && force->kspace) kspace_virial = force->kspace->virial; + else kspace_virial = NULL; } /* ---------------------------------------------------------------------- @@ -135,13 +161,19 @@ double ComputePressure::compute_scalar() if (dimension == 3) { inv_volume = 1.0 / (domain->xprd * domain->yprd * domain->zprd); virial_compute(3,3); - scalar = (temperature->dof * boltz * temperature->scalar + - virial[0] + virial[1] + virial[2]) / 3.0 * inv_volume * nktv2p; + if (keflag) + scalar = (temperature->dof * boltz * temperature->scalar + + virial[0] + virial[1] + virial[2]) / 3.0 * inv_volume * nktv2p; + else + scalar = (virial[0] + virial[1] + virial[2]) / 3.0 * inv_volume * nktv2p; } else { inv_volume = 1.0 / (domain->xprd * domain->yprd); virial_compute(2,2); - scalar = (temperature->dof * boltz * temperature->scalar + - virial[0] + virial[1]) / 2.0 * inv_volume * nktv2p; + if (keflag) + scalar = (temperature->dof * boltz * temperature->scalar + + virial[0] + virial[1]) / 2.0 * inv_volume * nktv2p; + else + scalar = (virial[0] + virial[1]) / 2.0 * inv_volume * nktv2p; } return scalar; @@ -157,16 +189,26 @@ void ComputePressure::compute_vector() if (dimension == 3) { inv_volume = 1.0 / (domain->xprd * domain->yprd * domain->zprd); virial_compute(6,3); - double *ke_tensor = temperature->vector; - for (int i = 0; i < 6; i++) - vector[i] = (ke_tensor[i] + virial[i]) * inv_volume * nktv2p; + if (keflag) { + double *ke_tensor = temperature->vector; + for (int i = 0; i < 6; i++) + vector[i] = (ke_tensor[i] + virial[i]) * inv_volume * nktv2p; + } else + for (int i = 0; i < 6; i++) + vector[i] = virial[i] * inv_volume * nktv2p; } else { inv_volume = 1.0 / (domain->xprd * domain->yprd); virial_compute(4,2); - double *ke_tensor = temperature->vector; - vector[0] = (ke_tensor[0] + virial[0]) * inv_volume * nktv2p; - vector[1] = (ke_tensor[1] + virial[1]) * inv_volume * nktv2p; - vector[3] = (ke_tensor[3] + virial[3]) * inv_volume * nktv2p; + if (keflag) { + double *ke_tensor = temperature->vector; + vector[0] = (ke_tensor[0] + virial[0]) * inv_volume * nktv2p; + vector[1] = (ke_tensor[1] + virial[1]) * inv_volume * nktv2p; + vector[3] = (ke_tensor[3] + virial[3]) * inv_volume * nktv2p; + } else { + vector[0] = virial[0] * inv_volume * nktv2p; + vector[1] = virial[1] * inv_volume * nktv2p; + vector[3] = virial[3] * inv_volume * nktv2p; + } } } @@ -193,7 +235,7 @@ void ComputePressure::virial_compute(int n, int ndiag) // KSpace virial contribution is already summed across procs - if (force->kspace) + if (kspace_virial) for (i = 0; i < n; i++) virial[i] += kspace_virial[i]; // LJ long-range tail correction diff --git a/src/compute_pressure.h b/src/compute_pressure.h index 7b00c4b432..adf6ec226a 100644 --- a/src/compute_pressure.h +++ b/src/compute_pressure.h @@ -30,10 +30,11 @@ class ComputePressure : public Compute { double boltz,nktv2p,inv_volume; int nvirial,dimension; double **vptr; - int kspaceflag; double *kspace_virial; Compute *temperature; double virial[6]; + int keflag,pairflag,bondflag,angleflag,dihedralflag,improperflag; + int fixflag,kspaceflag; void virial_compute(int, int); }; diff --git a/src/compute_stress_atom.cpp b/src/compute_stress_atom.cpp index 3fd55b5a44..b737607c55 100644 --- a/src/compute_stress_atom.cpp +++ b/src/compute_stress_atom.cpp @@ -11,60 +11,54 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +#include "stdlib.h" #include "string.h" #include "compute_stress_atom.h" #include "atom.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "neigh_request.h" -#include "modify.h" #include "comm.h" -#include "update.h" #include "force.h" -#include "bond.h" #include "pair.h" -#include "domain.h" +#include "bond.h" +#include "angle.h" +#include "dihedral.h" +#include "improper.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) > (b) ? (a) : (b)) - /* ---------------------------------------------------------------------- */ -ComputeStressAtom::ComputeStressAtom(LAMMPS *lmp, int narg, char **arg) : +ComputeStressAtom::ComputeStressAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg) { if (narg < 3) error->all("Illegal compute stress/atom command"); peratom_flag = 1; size_peratom = 6; + pressatomflag = 1; + timeflag = 1; comm_reverse = 6; - // process args - - kerequest = pairrequest = bondrequest = 1; - - int iarg = 3; - while (iarg < narg) { - if (strcmp(arg[iarg],"ke") == 0) { - if (iarg+2 > narg) error->all("Illegal compute ebond/atom command"); - if (strcmp(arg[iarg+1],"yes") == 0) kerequest = 1; - else if (strcmp(arg[iarg+1],"no") == 0) kerequest = 0; - iarg += 2; - } else if (strcmp(arg[iarg],"pair") == 0) { - if (iarg+2 > narg) error->all("Illegal compute ebond/atom command"); - if (strcmp(arg[iarg+1],"yes") == 0) pairrequest = 1; - else if (strcmp(arg[iarg+1],"no") == 0) pairrequest = 0; - iarg += 2; - } else if (strcmp(arg[iarg],"bond") == 0) { - if (iarg+2 > narg) error->all("Illegal compute ebond/atom command"); - if (strcmp(arg[iarg+1],"yes") == 0) bondrequest = 1; - else if (strcmp(arg[iarg+1],"no") == 0) bondrequest = 0; - iarg += 2; - } else error->all("Illegal compute ebond/atom command"); + if (narg == 3) { + keflag = 1; + pairflag = 1; + bondflag = angleflag = dihedralflag = improperflag = 1; + } else { + keflag = 0; + pairflag = 0; + bondflag = angleflag = dihedralflag = improperflag = 0; + int iarg = 3; + while (iarg < narg) { + if (strcmp(arg[iarg],"ke") == 0) keflag = 1; + else if (strcmp(arg[iarg],"pair") == 0) pairflag = 1; + else if (strcmp(arg[iarg],"bond") == 0) bondflag = 1; + else if (strcmp(arg[iarg],"angle") == 0) angleflag = 1; + else if (strcmp(arg[iarg],"dihedral") == 0) dihedralflag = 1; + else if (strcmp(arg[iarg],"improper") == 0) improperflag = 1; + else error->all("Illegal compute stress/atom command"); + iarg++; + } } nmax = 0; @@ -80,50 +74,13 @@ ComputeStressAtom::~ComputeStressAtom() /* ---------------------------------------------------------------------- */ -void ComputeStressAtom::init() -{ - if (pairrequest) { - if (force->pair == NULL || force->pair->single_enable == 0) - error->all("Pair style does not support computing per-atom stress"); - pairflag = 1; - - // need an occasional half neighbor list - - int irequest = neighbor->request((void *) this); - neighbor->requests[irequest]->pair = 0; - neighbor->requests[irequest]->compute = 1; - neighbor->requests[irequest]->occasional = 1; - - } else pairflag = 0; - - if (bondrequest && force->bond) bondflag = 1; - else bondflag = 0; - - int count = 0; - for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style,"stress/atom") == 0) count++; - if (count > 1 && comm->me == 0) - error->warning("More than one compute stress/atom"); -} - -/* ---------------------------------------------------------------------- */ - -void ComputeStressAtom::init_list(int id, NeighList *ptr) -{ - list = ptr; -} - -/* ---------------------------------------------------------------------- */ - void ComputeStressAtom::compute_peratom() { - int i,j,ii,jj,n,i1,i2,inum,jnum,itype,jtype,iflag,jflag; - double xtmp,ytmp,ztmp,delx,dely,delz,rsq,eng; - double factor_coul,factor_lj,fforce,rmass; - int *ilist,*jlist,*numneigh,**firstneigh; - Pair::One one; + int i,j; - // grow stress array if necessary + invoked = 1; + + // grow local stress array if necessary if (atom->nmax > nmax) { memory->destroy_2d_double_array(stress); @@ -133,199 +90,115 @@ void ComputeStressAtom::compute_peratom() vector_atom = stress; } - // clear stress array - // n includes ghosts only if newton flag is set + // npair includes ghosts if either newton flag is set + // b/c some bonds/dihedrals call pair::ev_tally with pairwise info + // nbond includes ghosts if newton_bond is set + // ntotal includes ghosts if either newton flag is set int nlocal = atom->nlocal; + int npair = nlocal; + int nbond = nlocal; + int ntotal = nlocal; + if (force->newton) npair += atom->nghost; + if (force->newton_bond) nbond += atom->nghost; + if (force->newton) ntotal += atom->nghost; - if (force->newton) n = nlocal + atom->nghost; - else n = nlocal; + // clear local stress array - for (i = 0; i < n; i++) { - stress[i][0] = 0.0; - stress[i][1] = 0.0; - stress[i][2] = 0.0; - stress[i][3] = 0.0; - stress[i][4] = 0.0; - stress[i][5] = 0.0; + for (i = 0; i < ntotal; i++) + for (j = 0; j < 6; j++) + stress[i][j] = 0.0; + + // add in per-atom contributions from each force + + if (pairflag && force->pair) { + double **vatom = force->pair->vatom; + for (i = 0; i < npair; i++) + for (j = 0; j < 6; j++) + stress[i][j] += vatom[i][j]; } - // compute pairwise stress for atoms via pair->single() - // if neither atom is in compute group, skip that pair - // only add stress to atoms in group - - if (pairflag) { - - // invoke half neighbor list (will copy or build if necessary) - - neighbor->build_one(list->index); - - inum = list->inum; - ilist = list->ilist; - numneigh = list->numneigh; - firstneigh = list->firstneigh; - - double *special_coul = force->special_coul; - double *special_lj = force->special_lj; - double **cutsq = force->pair->cutsq; - int newton_pair = force->newton_pair; - - double **x = atom->x; - int *mask = atom->mask; - int *type = atom->type; - int nall = nlocal + atom->nghost; - - for (ii = 0; ii < inum; ii++) { - i = ilist[ii]; - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - itype = type[i]; - iflag = mask[i] & groupbit; - jlist = firstneigh[i]; - jnum = numneigh[i]; - - for (jj = 0; jj < jnum; jj++) { - j = jlist[jj]; - jflag = mask[j] & groupbit; - if (iflag == 0 && jflag == 0) continue; - - if (j < nall) factor_coul = factor_lj = 1.0; - else { - factor_coul = special_coul[j/nall]; - factor_lj = special_lj[j/nall]; - j %= nall; - } - - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - rsq = delx*delx + dely*dely + delz*delz; - jtype = type[j]; - - if (rsq < cutsq[itype][jtype]) { - force->pair->single(i,j,itype,jtype,rsq,factor_coul,factor_lj,0,one); - fforce = one.fforce; - - if (iflag) { - stress[i][0] -= delx*delx*fforce; - stress[i][1] -= dely*dely*fforce; - stress[i][2] -= delz*delz*fforce; - stress[i][3] -= delx*dely*fforce; - stress[i][4] -= delx*delz*fforce; - stress[i][5] -= dely*delz*fforce; - } - if (jflag && (newton_pair || j < nlocal)) { - stress[j][0] -= delx*delx*fforce; - stress[j][1] -= dely*dely*fforce; - stress[j][2] -= delz*delz*fforce; - stress[j][3] -= delx*dely*fforce; - stress[j][4] -= delx*delz*fforce; - stress[j][5] -= dely*delz*fforce; - } - } - } - } - + if (bondflag && force->bond) { + double **vatom = force->bond->vatom; + for (i = 0; i < nbond; i++) + for (j = 0; j < 6; j++) + stress[i][j] += vatom[i][j]; } - // compute bond stress for atoms via bond->single() - // if neither atom is in compute group, skip that bond - // only add stress to atoms in group - - if (bondflag) { - double **x = atom->x; - int *mask = atom->mask; - int **bondlist = neighbor->bondlist; - int nbondlist = neighbor->nbondlist; - int newton_bond = force->newton_bond; - int type; - - for (n = 0; n < nbondlist; n++) { - i1 = bondlist[n][0]; - i2 = bondlist[n][1]; - type = bondlist[n][2]; - iflag = mask[i1] & groupbit; - jflag = mask[i2] & groupbit; - if (iflag == 0 && jflag == 0) continue; - - delx = x[i1][0] - x[i2][0]; - dely = x[i1][1] - x[i2][1]; - delz = x[i1][2] - x[i2][2]; - domain->minimum_image(delx,dely,delz); - - rsq = delx*delx + dely*dely + delz*delz; - force->bond->single(type,rsq,i1,i2,0,fforce,eng); - - if (iflag) { - stress[i1][0] -= delx*delx*fforce; - stress[i1][1] -= dely*dely*fforce; - stress[i1][2] -= delz*delz*fforce; - stress[i1][3] -= delx*dely*fforce; - stress[i1][4] -= delx*delz*fforce; - stress[i1][5] -= dely*delz*fforce; - } - - if (jflag && (newton_bond || i2 < nlocal)) { - stress[i2][0] -= delx*delx*fforce; - stress[i2][1] -= dely*dely*fforce; - stress[i2][2] -= delz*delz*fforce; - stress[i2][3] -= delx*dely*fforce; - stress[i2][4] -= delx*delz*fforce; - stress[i2][5] -= dely*delz*fforce; - } - } + if (angleflag && force->angle) { + double **vatom = force->angle->vatom; + for (i = 0; i < nbond; i++) + for (j = 0; j < 6; j++) + stress[i][j] += vatom[i][j]; } - // communicate stress between neighbor procs + if (dihedralflag && force->dihedral) { + double **vatom = force->dihedral->vatom; + for (i = 0; i < nbond; i++) + for (j = 0; j < 6; j++) + stress[i][j] += vatom[i][j]; + } + + if (improperflag && force->improper) { + double **vatom = force->improper->vatom; + for (i = 0; i < nbond; i++) + for (j = 0; j < 6; j++) + stress[i][j] += vatom[i][j]; + } + + // communicate ghost energy between neighbor procs if (force->newton) comm->reverse_comm_compute(this); - // remove double counting + // zero virial of atoms not in group + // only do this after comm since ghost contributions must be included - for (i = 0; i < nlocal; i++) { - stress[i][0] *= 0.5; - stress[i][1] *= 0.5; - stress[i][2] *= 0.5; - stress[i][3] *= 0.5; - stress[i][4] *= 0.5; - stress[i][5] *= 0.5; - } + int *mask = atom->mask; + + for (i = 0; i < nlocal; i++) + if (!(mask[i] & groupbit)) { + stress[i][0] = 0.0; + stress[i][1] = 0.0; + stress[i][2] = 0.0; + stress[i][3] = 0.0; + stress[i][4] = 0.0; + stress[i][5] = 0.0; + } // include kinetic energy term for each atom in group // mvv2e converts mv^2 to energy - if (kerequest) { + if (keflag) { double **v = atom->v; double *mass = atom->mass; - int *mask = atom->mask; int *type = atom->type; double mvv2e = force->mvv2e; - - for (i = 0; i < nlocal; i++) { + double rmass; + + for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { rmass = mvv2e * mass[type[i]]; - stress[i][0] -= rmass*v[i][0]*v[i][0]; - stress[i][1] -= rmass*v[i][1]*v[i][1]; - stress[i][2] -= rmass*v[i][2]*v[i][2]; - stress[i][3] -= rmass*v[i][0]*v[i][1]; - stress[i][4] -= rmass*v[i][0]*v[i][2]; - stress[i][5] -= rmass*v[i][1]*v[i][2]; + stress[i][0] += rmass*v[i][0]*v[i][0]; + stress[i][1] += rmass*v[i][1]*v[i][1]; + stress[i][2] += rmass*v[i][2]*v[i][2]; + stress[i][3] += rmass*v[i][0]*v[i][1]; + stress[i][4] += rmass*v[i][0]*v[i][2]; + stress[i][5] += rmass*v[i][1]*v[i][2]; } + } + + // convert to pressure units (actually stress/volume = -pressure) + + double nktv2p = -force->nktv2p; + for (i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + stress[i][0] *= nktv2p; + stress[i][1] *= nktv2p; + stress[i][2] *= nktv2p; + stress[i][3] *= nktv2p; + stress[i][4] *= nktv2p; + stress[i][5] *= nktv2p; } - } - - // convert to pressure units (actually stress/volume = pressure) - - double nktv2p = force->nktv2p; - for (i = 0; i < nlocal; i++) { - stress[i][0] *= nktv2p; - stress[i][1] *= nktv2p; - stress[i][2] *= nktv2p; - stress[i][3] *= nktv2p; - stress[i][4] *= nktv2p; - stress[i][5] *= nktv2p; - } } /* ---------------------------------------------------------------------- */ diff --git a/src/compute_stress_atom.h b/src/compute_stress_atom.h index 7976cb47c5..d1cff5530b 100644 --- a/src/compute_stress_atom.h +++ b/src/compute_stress_atom.h @@ -19,22 +19,18 @@ namespace LAMMPS_NS { class ComputeStressAtom : public Compute { - public: ComputeStressAtom(class LAMMPS *, int, char **); ~ComputeStressAtom(); - void init(); - void init_list(int, class NeighList *); + void init() {} void compute_peratom(); int pack_reverse_comm(int, int, double *); void unpack_reverse_comm(int, int *, double *); double memory_usage(); private: - int pairrequest,bondrequest,kerequest; - int pairflag,bondflag; + int keflag,pairflag,bondflag,angleflag,dihedralflag,improperflag; int nmax; - class NeighList *list; double **stress; }; diff --git a/src/compute_sum.cpp b/src/compute_sum.cpp index 0ef29340dc..bc86c70c7b 100644 --- a/src/compute_sum.cpp +++ b/src/compute_sum.cpp @@ -114,6 +114,7 @@ double ComputeSum::compute_scalar() compute[icompute]->compute_peratom(); // compute scalar quantity by summing over atom scalars + // only include atoms in group int *mask = atom->mask; int nlocal = atom->nlocal; @@ -145,6 +146,7 @@ void ComputeSum::compute_vector() compute[icompute]->compute_peratom(); // compute vector quantity by summing over atom vectors + // only include atoms in group int *mask = atom->mask; int nlocal = atom->nlocal; diff --git a/src/dihedral.h b/src/dihedral.h index e0ce136f2d..c852c6d9cd 100644 --- a/src/dihedral.h +++ b/src/dihedral.h @@ -23,22 +23,33 @@ class Dihedral : protected Pointers { public: int allocated; int *setflag; - double energy; - double eng_vdwl,eng_coul; - double virial[6]; - double PI; + double energy; // accumulated energy + double virial[6]; // accumlated virial + double *eatom,**vatom; // accumulated per-atom energy/virial Dihedral(class LAMMPS *); - virtual ~Dihedral() {} + virtual ~Dihedral(); virtual void init(); virtual void init_style() {} - virtual void compute(int, int) = 0; virtual void settings(int, char **) {} virtual void coeff(int, int, char **) = 0; virtual void write_restart(FILE *) = 0; virtual void read_restart(FILE *) = 0; - virtual double memory_usage() {return 0.0;} + virtual double memory_usage(); + + protected: + double PI; + + int evflag; + int eflag_either,eflag_global,eflag_atom; + int vflag_either,vflag_global,vflag_atom; + int maxeatom,maxvatom; + + void ev_setup(int, int); + void ev_tally(int, int, int, int, int, int, double, + double *, double *, double *, double, double, double, + double, double, double, double, double, double); }; } diff --git a/src/fix_ave_atom.cpp b/src/fix_ave_atom.cpp index 186c1b5085..019d5f7534 100644 --- a/src/fix_ave_atom.cpp +++ b/src/fix_ave_atom.cpp @@ -78,12 +78,23 @@ FixAveAtom::FixAveAtom(LAMMPS *lmp, int narg, char **arg) : vector[i][m] = 0.0; // nvalid = next step on which end_of_step does something + // can be this timestep if multiple of peratom_freq and nrepeat = 1 + // else backup from next multiple of peratom_freq irepeat = 0; nvalid = (update->ntimestep/peratom_freq)*peratom_freq + peratom_freq; - nvalid -= (nrepeat-1)*nevery; - if (nvalid <= update->ntimestep) - error->all("Fix ave/atom cannot be started on this timestep"); + if (nvalid-peratom_freq == update->ntimestep && nrepeat == 1) + nvalid = update->ntimestep; + else + nvalid -= (nrepeat-1)*nevery; + if (nvalid < update->ntimestep) nvalid += peratom_freq; + + // must set timestep for all computes that store invocation times + // since don't know a priori which are invoked by this fix + // once in end_of_step() can just set timestep for ones actually invoked + + for (int i = 0; i < modify->ncompute; i++) + if (modify->compute[i]->timeflag) modify->compute[i]->add_step(nvalid); } /* ---------------------------------------------------------------------- */ @@ -156,6 +167,7 @@ void FixAveAtom::end_of_step() // accumulate results of compute to local copy + modify->clearstep_compute(); for (i = 0; i < ncompute; i++) compute[i]->compute_peratom(); int *mask = atom->mask; @@ -172,26 +184,30 @@ void FixAveAtom::end_of_step() vector[i][m] += compute_vector[i][m]; } + // done if irepeat < nrepeat + // else reset irepeat and nvalid + irepeat++; - nvalid += nevery; - - // divide by nrepeat if final step - // reset irepeat and nvalid - - if (irepeat == nrepeat) { - double repeat = nrepeat; - - if (size_peratom == 0) - for (i = 0; i < nlocal; i++) - scalar[i] /= repeat; - else - for (i = 0; i < nlocal; i++) - for (m = 0; m < size_peratom; m++) - vector[i][m] /= repeat; - - irepeat = 0; - nvalid = update->ntimestep+peratom_freq - (nrepeat-1)*nevery; + if (irepeat < nrepeat) { + nvalid += nevery; + modify->addstep_compute(nvalid); + return; } + + irepeat = 0; + nvalid = update->ntimestep+peratom_freq - (nrepeat-1)*nevery; + modify->addstep_compute(nvalid); + + // average the final result for the Nfreq timestep + + double repeat = nrepeat; + if (size_peratom == 0) + for (i = 0; i < nlocal; i++) + scalar[i] /= repeat; + else + for (i = 0; i < nlocal; i++) + for (m = 0; m < size_peratom; m++) + vector[i][m] /= repeat; } /* ---------------------------------------------------------------------- diff --git a/src/fix_ave_spatial.cpp b/src/fix_ave_spatial.cpp index 67ce1981f6..564960349d 100644 --- a/src/fix_ave_spatial.cpp +++ b/src/fix_ave_spatial.cpp @@ -238,6 +238,14 @@ FixAveSpatial::FixAveSpatial(LAMMPS *lmp, int narg, char **arg) : else nvalid -= (nrepeat-1)*nevery; if (nvalid < update->ntimestep) nvalid += nfreq; + + // must set timestep for all computes that store invocation times + // since don't know a priori which are invoked by this fix + // once in end_of_step() can just set timestep for ones actually invoked + + if (which == COMPUTE) + for (int i = 0; i < modify->ncompute; i++) + if (modify->compute[i]->timeflag) modify->compute[i]->add_step(nvalid); } /* ---------------------------------------------------------------------- */ @@ -492,6 +500,7 @@ void FixAveSpatial::end_of_step() // COMPUTE adds its scalar or vector quantity to values } else if (which == COMPUTE) { + modify->clearstep_compute(); for (i = 0; i < ncompute; i++) compute[i]->compute_peratom(); double *scalar = compute[ncompute-1]->scalar_atom; double **vector = compute[ncompute-1]->vector_atom; @@ -558,10 +567,18 @@ void FixAveSpatial::end_of_step() } // done if irepeat < nrepeat + // else reset irepeat and nvalid irepeat++; - nvalid += nevery; - if (irepeat < nrepeat) return; + if (irepeat < nrepeat) { + nvalid += nevery; + if (which == COMPUTE) modify->addstep_compute(nvalid); + return; + } + + irepeat = 0; + nvalid = update->ntimestep+nfreq - (nrepeat-1)*nevery; + if (which == COMPUTE) modify->addstep_compute(nvalid); // time average across samples // if density, also normalize by volume @@ -593,11 +610,6 @@ void FixAveSpatial::end_of_step() values_sum[m][0] *= count_sum[m] / layer_volume; } - // reset irepeat and nvalid - - irepeat = 0; - nvalid = update->ntimestep+nfreq - (nrepeat-1)*nevery; - // if ave = ONE, only single Nfreq timestep value is needed // if ave = RUNNING, combine with all previous Nfreq timestep values // if ave = WINDOW, comine with nwindow most recent Nfreq timestep values diff --git a/src/fix_shake.cpp b/src/fix_shake.cpp index d3e2a1eae9..d598dc8db8 100644 --- a/src/fix_shake.cpp +++ b/src/fix_shake.cpp @@ -321,6 +321,8 @@ void FixShake::init() for (i = 1; i <= atom->nangletypes; i++) { if (angle_flag[i] == 0) continue; + if (force->angle == NULL) + error->all("Angle potential must be defined for SHAKE"); // scan all atoms for a SHAKE angle cluster // extract bond types for the 2 bonds in the cluster diff --git a/src/improper.h b/src/improper.h index 292e45d552..6039e2ec65 100644 --- a/src/improper.h +++ b/src/improper.h @@ -23,19 +23,32 @@ class Improper : protected Pointers { public: int allocated; int *setflag; - double energy; - double virial[6]; - double PI; + double energy; // accumulated energies + double virial[6]; // accumlated virial + double *eatom,**vatom; // accumulated per-atom energy/virial Improper(class LAMMPS *); - virtual ~Improper() {} + virtual ~Improper(); virtual void init(); virtual void compute(int, int) = 0; virtual void settings(int, char **) {} virtual void coeff(int, int, char **) = 0; virtual void write_restart(FILE *) = 0; virtual void read_restart(FILE *) = 0; - virtual double memory_usage() {return 0.0;} + virtual double memory_usage(); + + protected: + double PI; + + int evflag; + int eflag_either,eflag_global,eflag_atom; + int vflag_either,vflag_global,vflag_atom; + int maxeatom,maxvatom; + + void ev_setup(int, int); + void ev_tally(int, int, int, int, int, int, double, + double *, double *, double *, double, double, double, + double, double, double, double, double, double); }; } diff --git a/src/integrate.cpp b/src/integrate.cpp index c219fe7372..e2b62c0e84 100644 --- a/src/integrate.cpp +++ b/src/integrate.cpp @@ -13,6 +13,7 @@ #include "stdlib.h" #include "integrate.h" +#include "modify.h" #include "compute.h" using namespace LAMMPS_NS; @@ -21,33 +22,99 @@ using namespace LAMMPS_NS; Integrate::Integrate(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) { - elist = vlist = NULL; + elist_global = elist_atom = NULL; + vlist_global = vlist_atom = NULL; } /* ---------------------------------------------------------------------- */ Integrate::~Integrate() { - delete [] elist; - delete [] vlist; + delete [] elist_global; + delete [] elist_atom; + delete [] vlist_global; + delete [] vlist_atom; } /* ---------------------------------------------------------------------- - set eflag if a pe compute is called this timestep - set vflag if a pressure compute is called this timestep + setup lists of computes for global and per-atom PE and pressure +------------------------------------------------------------------------- */ + +void Integrate::ev_setup() +{ + delete [] elist_global; + delete [] elist_atom; + delete [] vlist_global; + delete [] vlist_atom; + elist_global = elist_atom = NULL; + vlist_global = vlist_atom = NULL; + + nelist_global = nelist_atom = 0; + nvlist_global = nvlist_atom = 0; + for (int i = 0; i < modify->ncompute; i++) { + if (modify->compute[i]->peflag) nelist_global++; + if (modify->compute[i]->peatomflag) nelist_atom++; + if (modify->compute[i]->pressflag) nvlist_global++; + if (modify->compute[i]->pressatomflag) nvlist_atom++; + } + + if (nelist_global) elist_global = new Compute*[nelist_global]; + if (nelist_atom) elist_atom = new Compute*[nelist_atom]; + if (nvlist_global) vlist_global = new Compute*[nvlist_global]; + if (nvlist_atom) vlist_atom = new Compute*[nvlist_atom]; + + nelist_global = nelist_atom = 0; + nvlist_global = nvlist_atom = 0; + for (int i = 0; i < modify->ncompute; i++) { + if (modify->compute[i]->peflag) + elist_global[nelist_global++] = modify->compute[i]; + if (modify->compute[i]->peatomflag) + elist_atom[nelist_atom++] = modify->compute[i]; + if (modify->compute[i]->pressflag) + vlist_global[nvlist_global++] = modify->compute[i]; + if (modify->compute[i]->pressatomflag) + vlist_atom[nvlist_atom++] = modify->compute[i]; + } +} + +/* ---------------------------------------------------------------------- + set eflag,vflag for current iteration with ntimestep + eflag = 0 = no energy computation + eflag = 1 = global energy only + eflag = 2 = per-atom energy only + eflag = 3 = both global and per-atom energy + vflag = 0 = no virial computation (pressure) + vflag = 1 = global virial with pair portion via sum of pairwise interactions + vflag = 2 = global virial with pair portion via F dot r including ghosts + vflag = 4 = per-atom virial only + vflag = 5 or 6 = both global and per-atom virial ------------------------------------------------------------------------- */ void Integrate::ev_set(int ntimestep) { int i; - eflag = 0; - for (i = 0; i < nelist; i++) - if (elist[i]->match_step(ntimestep)) break; - if (i < nelist) eflag = 1; + int eflag_global = 0; + for (i = 0; i < nelist_global; i++) + if (elist_global[i]->match_step(ntimestep)) break; + if (i < nelist_global) eflag_global = 1; - vflag = 0; - for (i = 0; i < nvlist; i++) - if (vlist[i]->match_step(ntimestep)) break; - if (i < nvlist) vflag = virial_style; + int eflag_atom = 0; + for (i = 0; i < nelist_atom; i++) + if (elist_atom[i]->match_step(ntimestep)) break; + if (i < nelist_atom) eflag_atom = 2; + + eflag = eflag_global + eflag_atom; + + int vflag_global = 0; + for (i = 0; i < nvlist_global; i++) + if (vlist_global[i]->match_step(ntimestep)) break; + if (i < nvlist_global) vflag_global = virial_style; + + int vflag_atom = 0; + for (i = 0; i < nvlist_atom; i++) + if (vlist_atom[i]->match_step(ntimestep)) break; + if (i < nvlist_atom) vflag_atom = 4; + + vflag = vflag_global + vflag_atom; } diff --git a/src/integrate.h b/src/integrate.h index a40ed203a6..8eb89bff52 100644 --- a/src/integrate.h +++ b/src/integrate.h @@ -33,10 +33,14 @@ class Integrate : protected Pointers { int eflag,vflag; // flags for energy/virial computation int virial_style; // compute virial explicitly or implicitly - int nelist,nvlist; // # of PE,virial coputes for eflag,vflag - class Compute **elist; // list of Computes to check - class Compute **vlist; + int nelist_global,nelist_atom; // # of PE,virial computes to check + int nvlist_global,nvlist_atom; + class Compute **elist_global; // list of PE,virial Computes + class Compute **elist_atom; + class Compute **vlist_global; + class Compute **vlist_atom; + void ev_setup(); void ev_set(int); }; diff --git a/src/min.cpp b/src/min.cpp index de282eefd7..017d82bc7b 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -14,6 +14,8 @@ #include "stdlib.h" #include "string.h" #include "min.h" +#include "modify.h" +#include "compute.h" #include "error.h" using namespace LAMMPS_NS; @@ -29,6 +31,18 @@ Min::Min(LAMMPS *lmp) : Pointers(lmp) dmin = 1.0e-5; dmax = 0.1; lineiter = 10; + + elist_atom = NULL; + vlist_global = vlist_atom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +Min::~Min() +{ + delete [] elist_atom; + delete [] vlist_global; + delete [] vlist_atom; } /* ---------------------------------------------------------------------- */ @@ -60,3 +74,79 @@ void Min::modify_params(int narg, char **arg) } else error->all("Illegal min_modify command"); } } + +/* ---------------------------------------------------------------------- + setup lists of computes for global and per-atom PE and pressure +------------------------------------------------------------------------- */ + +void Min::ev_setup() +{ + delete [] elist_atom; + delete [] vlist_global; + delete [] vlist_atom; + elist_atom = NULL; + vlist_global = vlist_atom = NULL; + + nelist_atom = 0; + nvlist_global = nvlist_atom = 0; + for (int i = 0; i < modify->ncompute; i++) { + if (modify->compute[i]->peatomflag) nelist_atom++; + if (modify->compute[i]->pressflag) nvlist_global++; + if (modify->compute[i]->pressatomflag) nvlist_atom++; + } + + if (nelist_atom) elist_atom = new Compute*[nelist_atom]; + if (nvlist_global) vlist_global = new Compute*[nvlist_global]; + if (nvlist_atom) vlist_atom = new Compute*[nvlist_atom]; + + nelist_atom = 0; + nvlist_global = nvlist_atom = 0; + for (int i = 0; i < modify->ncompute; i++) { + if (modify->compute[i]->peatomflag) + elist_atom[nelist_atom++] = modify->compute[i]; + if (modify->compute[i]->pressflag) + vlist_global[nvlist_global++] = modify->compute[i]; + if (modify->compute[i]->pressatomflag) + vlist_atom[nvlist_atom++] = modify->compute[i]; + } +} + +/* ---------------------------------------------------------------------- + set eflag,vflag for current iteration with ntimestep + always set eflag_global = 1, since need energy every iteration + eflag = 0 = no energy computation + eflag = 1 = global energy only + eflag = 2 = per-atom energy only + eflag = 3 = both global and per-atom energy + vflag = 0 = no virial computation (pressure) + vflag = 1 = global virial with pair portion via sum of pairwise interactions + vflag = 2 = global virial with pair portion via F dot r including ghosts + vflag = 4 = per-atom virial only + vflag = 5 or 6 = both global and per-atom virial +------------------------------------------------------------------------- */ + +void Min::ev_set(int ntimestep) +{ + int i; + + int eflag_global = 1; + + int eflag_atom = 0; + for (i = 0; i < nelist_atom; i++) + if (elist_atom[i]->match_step(ntimestep)) break; + if (i < nelist_atom) eflag_atom = 2; + + eflag = eflag_global + eflag_atom; + + int vflag_global = 0; + for (i = 0; i < nvlist_global; i++) + if (vlist_global[i]->match_step(ntimestep)) break; + if (i < nvlist_global) vflag_global = virial_style; + + int vflag_atom = 0; + for (i = 0; i < nvlist_atom; i++) + if (vlist_atom[i]->match_step(ntimestep)) break; + if (i < nvlist_atom) vflag_atom = 4; + + vflag = vflag_global + vflag_atom; +} diff --git a/src/min.h b/src/min.h index 2e3ae61f87..f16a99619f 100644 --- a/src/min.h +++ b/src/min.h @@ -27,12 +27,25 @@ class Min : protected Pointers { int linestyle,lineiter; Min(class LAMMPS *); - virtual ~Min() {} + virtual ~Min(); virtual void init() = 0; virtual void run() = 0; virtual double memory_usage() {return 0.0;} void modify_params(int, char **); + + protected: + int eflag,vflag; // flags for energy/virial computation + int virial_style; // compute virial explicitly or implicitly + + int nelist_atom; // # of PE,virial computes to check + int nvlist_global,nvlist_atom; + class Compute **elist_atom; // list of PE,virial Computes + class Compute **vlist_global; + class Compute **vlist_atom; + + void ev_setup(); + void ev_set(int); }; } diff --git a/src/min_cg.cpp b/src/min_cg.cpp index 17c25f2ff3..88737c6554 100644 --- a/src/min_cg.cpp +++ b/src/min_cg.cpp @@ -57,17 +57,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -MinCG::MinCG(LAMMPS *lmp) : Min(lmp) -{ - vlist = NULL; -} - -/* ---------------------------------------------------------------------- */ - -MinCG::~MinCG() -{ - delete [] vlist; -} +MinCG::MinCG(LAMMPS *lmp) : Min(lmp) {} /* ---------------------------------------------------------------------- */ @@ -96,20 +86,9 @@ void MinCG::init() if (force->newton_pair) virial_style = 2; else virial_style = 1; - // vlist = list of computes for pressure + // setup lists of computes for global and per-atom PE and pressure - delete [] vlist; - vlist = NULL; - - nvlist = 0; - for (int i = 0; i < modify->ncompute; i++) - if (modify->compute[i]->pressflag) nvlist++; - - if (nvlist) vlist = new Compute*[nvlist]; - - nvlist = 0; - for (int i = 0; i < modify->ncompute; i++) - if (modify->compute[i]->pressflag) vlist[nvlist++] = modify->compute[i]; + ev_setup(); // set flags for what arrays to clear in force_clear() // need to clear torques if array exists @@ -256,7 +235,7 @@ void MinCG::setup() // compute all forces ev_set(update->ntimestep); - force_clear(vflag); + force_clear(); if (force->pair) force->pair->compute(eflag,vflag); @@ -409,7 +388,7 @@ void MinCG::eng_force(int *pndof, double **px, double **ph, double *peng) } ev_set(update->ntimestep); - force_clear(vflag); + force_clear(); timer->stamp(); @@ -454,28 +433,12 @@ void MinCG::eng_force(int *pndof, double **px, double **ph, double *peng) *peng = ecurrent; } -/* ---------------------------------------------------------------------- - eflag is always set, since minimizer needs potential energy - set vflag if a pressure compute is called this timestep -------------------------------------------------------------------------- */ - -void MinCG::ev_set(int ntimestep) -{ - int i; - - eflag = 1; - vflag = 0; - for (i = 0; i < nvlist; i++) - if (vlist[i]->match_step(ntimestep)) break; - if (i < nvlist) vflag = virial_style; -} - /* ---------------------------------------------------------------------- clear force on own & ghost atoms setup and clear other arrays as needed ------------------------------------------------------------------------- */ -void MinCG::force_clear(int vflag) +void MinCG::force_clear() { int i; diff --git a/src/min_cg.h b/src/min_cg.h index 1240a90ca4..586f13362b 100644 --- a/src/min_cg.h +++ b/src/min_cg.h @@ -21,24 +21,16 @@ namespace LAMMPS_NS { class MinCG : public Min { public: MinCG(class LAMMPS *); - virtual ~MinCG(); + virtual ~MinCG() {} void init(); void run(); virtual void iterate(int); protected: - int eflag,vflag; // flags for energy/virial computation - int virial_style; // compute virial explicitly or implicitly int pairflag,torqueflag; int neigh_every,neigh_delay,neigh_dist_check; // copies of reneigh criteria int triclinic; // 0 if domain is orthog, 1 if triclinic - int nvlist; // # of PE,virial coputes for eflag,vflag - class Compute **vlist; // list of Computes to check - - int maxpair; // copies of Update quantities - double **f_pair; - class FixMinimize *fix_minimize; // fix that stores gradient vecs class Compute *pe_compute; // compute for potential energy double ecurrent; // current potential energy @@ -59,8 +51,7 @@ class MinCG : public Min { void setup(); void setup_vectors(); void eng_force(int *, double **, double **, double *); - void ev_set(int); - void force_clear(int); + void force_clear(); }; } diff --git a/src/neigh_gran.cpp b/src/neigh_gran.cpp index 17c35fdb66..915caa8e49 100644 --- a/src/neigh_gran.cpp +++ b/src/neigh_gran.cpp @@ -56,8 +56,6 @@ void Neighbor::granular_nsq_no_newton(NeighList *list) int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; int **pages = list->pages; - int nstencil = list->nstencil; - int *stencil = list->stencil; FixShearHistory *fix_history = list->fix_history; if (fix_history) { @@ -190,8 +188,6 @@ void Neighbor::granular_nsq_newton(NeighList *list) int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; int **pages = list->pages; - int nstencil = list->nstencil; - int *stencil = list->stencil; int inum = 0; int npage = 0; diff --git a/src/neigh_half_bin.cpp b/src/neigh_half_bin.cpp index 495cb7f43c..c0e5ac7214 100644 --- a/src/neigh_half_bin.cpp +++ b/src/neigh_half_bin.cpp @@ -142,7 +142,6 @@ void Neighbor::half_bin_newton(NeighList *list) int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; int **pages = list->pages; - int skip = list->skip; int nstencil = list->nstencil; int *stencil = list->stencil; diff --git a/src/neigh_half_nsq.cpp b/src/neigh_half_nsq.cpp index f3f75698f8..ea7ae68e02 100644 --- a/src/neigh_half_nsq.cpp +++ b/src/neigh_half_nsq.cpp @@ -42,8 +42,6 @@ void Neighbor::half_nsq_no_newton(NeighList *list) int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; int **pages = list->pages; - int nstencil = list->nstencil; - int *stencil = list->stencil; int inum = 0; int npage = 0; @@ -121,8 +119,6 @@ void Neighbor::half_nsq_newton(NeighList *list) int *numneigh = list->numneigh; int **firstneigh = list->firstneigh; int **pages = list->pages; - int nstencil = list->nstencil; - int *stencil = list->stencil; int inum = 0; int npage = 0; diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 1f2f809151..4ab1c80b7b 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -1386,10 +1386,9 @@ int Neighbor::find_special(int i, int j) void Neighbor::bin_atoms() { - int i,ibin,nlocal,nall; + int i,ibin,nall; double **x; - nlocal = atom->nlocal; nall = atom->nlocal + atom->nghost; x = atom->x; diff --git a/src/output.cpp b/src/output.cpp index 76bf086d21..61b349cfac 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -23,6 +23,7 @@ #include "domain.h" #include "thermo.h" #include "modify.h" +#include "compute.h" #include "force.h" #include "dump.h" #include "write_restart.h" @@ -137,11 +138,15 @@ void Output::setup(int flag) for (int idump = 0; idump < ndump; idump++) { if (ntimestep % dump_every[idump] == 0 && last_dump[idump] != ntimestep) { + if (strcmp(dump[idump]->style,"custom") == 0) + modify->clearstep_compute(); dump[idump]->write(); last_dump[idump] = ntimestep; } next_dump[idump] = (ntimestep/dump_every[idump])*dump_every[idump] + dump_every[idump]; + if (strcmp(dump[idump]->style,"custom") == 0) + modify->addstep_compute(next_dump[idump]); if (idump) next_dump_any = MYMIN(next_dump_any,next_dump[idump]); else next_dump_any = next_dump[0]; } @@ -196,9 +201,13 @@ void Output::write(int ntimestep) if (next_dump_any == ntimestep) { for (int idump = 0; idump < ndump; idump++) { if (next_dump[idump] == ntimestep && last_dump[idump] != ntimestep) { + if (strcmp(dump[idump]->style,"custom") == 0) + modify->clearstep_compute(); dump[idump]->write(); last_dump[idump] = ntimestep; next_dump[idump] += dump_every[idump]; + if (strcmp(dump[idump]->style,"custom") == 0) + modify->addstep_compute(next_dump[idump]); } if (idump) next_dump_any = MYMIN(next_dump_any,next_dump[idump]); else next_dump_any = next_dump[0]; diff --git a/src/pair.cpp b/src/pair.cpp index c37f6cb66c..fb22f64f00 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -31,6 +31,7 @@ #include "comm.h" #include "force.h" #include "update.h" +#include "memory.h" #include "error.h" using namespace LAMMPS_NS; @@ -45,6 +46,8 @@ enum{R,RSQ,BMP}; Pair::Pair(LAMMPS *lmp) : Pointers(lmp) { + THIRD = 1.0/3.0; + eng_vdwl = eng_coul = 0.0; comm_forward = comm_reverse = 0; @@ -63,6 +66,18 @@ Pair::Pair(LAMMPS *lmp) : Pointers(lmp) tabinner = sqrt(2.0); allocated = 0; + + maxeatom = maxvatom = 0; + eatom = NULL; + vatom = NULL; +} + +/* ---------------------------------------------------------------------- */ + +Pair::~Pair() +{ + memory->sfree(eatom); + memory->destroy_2d_double_array(vatom); } /* ---------------------------------------------------------------------- @@ -214,7 +229,356 @@ double Pair::mix_distance(double sig1, double sig2) } /* ---------------------------------------------------------------------- - compute pair virial via own/ghost forces + setup for energy, virial computation + see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) +------------------------------------------------------------------------- */ + +void Pair::ev_setup(int eflag, int vflag) +{ + int i,n; + + evflag = 1; + + eflag_either = eflag; + eflag_global = eflag % 2; + eflag_atom = eflag / 2; + + vflag_either = vflag; + vflag_global = vflag % 4; + vflag_atom = vflag / 4; + + // reallocate per-atom arrays if necessary + + if (eflag_atom && atom->nmax > maxeatom) { + maxeatom = atom->nmax; + memory->sfree(eatom); + eatom = (double *) memory->smalloc(maxeatom*sizeof(double),"pair:eatom"); + } + if (vflag_atom && atom->nmax > maxvatom) { + maxvatom = atom->nmax; + memory->destroy_2d_double_array(vatom); + vatom = memory->create_2d_double_array(maxvatom,6,"pair:vatom"); + } + + // zero accumulators + // use force->newton instead of newton_pair + // b/c some bonds/dihedrals call pair::ev_tally with pairwise info + + if (eflag_global) eng_vdwl = eng_coul = 0.0; + if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0; + if (eflag_atom) { + n = atom->nlocal; + if (force->newton) n += atom->nghost; + for (i = 0; i < n; i++) eatom[i] = 0.0; + } + if (vflag_atom) { + n = atom->nlocal; + if (force->newton) n += atom->nghost; + for (i = 0; i < n; i++) { + vatom[i][0] = 0.0; + vatom[i][1] = 0.0; + vatom[i][2] = 0.0; + vatom[i][3] = 0.0; + vatom[i][4] = 0.0; + vatom[i][5] = 0.0; + } + } + + // if vflag_global = 2 + // compute global virial via (F dot r) instead of via pairwise summation + // unset other flags as appropriate + + if (vflag_global == 2) { + vflag_fdotr = 1; + vflag_global = 0; + if (vflag_atom == 0) vflag_either = 0; + if (vflag_either == 0 && eflag_either == 0) evflag = 0; + } else vflag_fdotr = 0; +} + +/* ---------------------------------------------------------------------- + tally eng_vdwl and virial into global and per-atom accumulators + need i < nlocal test since called by bond_quartic and dihedral_charmm +------------------------------------------------------------------------- */ + +void Pair::ev_tally(int i, int j, int nlocal, int newton_pair, + double evdwl, double ecoul, double fpair, + double delx, double dely, double delz) +{ + double evdwlhalf,ecoulhalf,epairhalf,v[6]; + + if (eflag_either) { + if (eflag_global) { + if (newton_pair) { + eng_vdwl += evdwl; + eng_coul += ecoul; + } else { + evdwlhalf = 0.5*evdwl; + ecoulhalf = 0.5*ecoul; + if (i < nlocal) { + eng_vdwl += evdwlhalf; + eng_coul += ecoulhalf; + } + if (j < nlocal) { + eng_vdwl += evdwlhalf; + eng_coul += ecoulhalf; + } + } + } + if (eflag_atom) { + epairhalf = 0.5 * (evdwl + ecoul); + if (newton_pair || i < nlocal) eatom[i] += epairhalf; + if (newton_pair || j < nlocal) eatom[j] += epairhalf; + } + } + + if (vflag_either) { + v[0] = delx*delx*fpair; + v[1] = dely*dely*fpair; + v[2] = delz*delz*fpair; + v[3] = delx*dely*fpair; + v[4] = delx*delz*fpair; + v[5] = dely*delz*fpair; + + if (vflag_global) { + if (newton_pair) { + virial[0] += v[0]; + virial[1] += v[1]; + virial[2] += v[2]; + virial[3] += v[3]; + virial[4] += v[4]; + virial[5] += v[5]; + } else { + if (i < nlocal) { + virial[0] += 0.5*v[0]; + virial[1] += 0.5*v[1]; + virial[2] += 0.5*v[2]; + virial[3] += 0.5*v[3]; + virial[4] += 0.5*v[4]; + virial[5] += 0.5*v[5]; + } + if (j < nlocal) { + virial[0] += 0.5*v[0]; + virial[1] += 0.5*v[1]; + virial[2] += 0.5*v[2]; + virial[3] += 0.5*v[3]; + virial[4] += 0.5*v[4]; + virial[5] += 0.5*v[5]; + } + } + } + + if (vflag_atom) { + if (newton_pair || i < nlocal) { + vatom[i][0] += 0.5*v[0]; + vatom[i][1] += 0.5*v[1]; + vatom[i][2] += 0.5*v[2]; + vatom[i][3] += 0.5*v[3]; + vatom[i][4] += 0.5*v[4]; + vatom[i][5] += 0.5*v[5]; + } + if (newton_pair || j < nlocal) { + vatom[j][0] += 0.5*v[0]; + vatom[j][1] += 0.5*v[1]; + vatom[j][2] += 0.5*v[2]; + vatom[j][3] += 0.5*v[3]; + vatom[j][4] += 0.5*v[4]; + vatom[j][5] += 0.5*v[5]; + } + } + } +} + +/* ---------------------------------------------------------------------- + tally eng_vdwl and virial into global and per-atom accumulators + for virial, have delx,dely,delz and fx,fy,fz +------------------------------------------------------------------------- */ + +void Pair::ev_tally_xyz(int i, int j, int nlocal, int newton_pair, + double evdwl, double ecoul, + double fx, double fy, double fz, + double delx, double dely, double delz) +{ + double evdwlhalf,ecoulhalf,epairhalf,v[6]; + + if (eflag_either) { + if (eflag_global) { + if (newton_pair) { + eng_vdwl += evdwl; + eng_coul += ecoul; + } else { + evdwlhalf = 0.5*evdwl; + ecoulhalf = 0.5*ecoul; + if (i < nlocal) { + eng_vdwl += evdwlhalf; + eng_coul += ecoulhalf; + } + if (j < nlocal) { + eng_vdwl += evdwlhalf; + eng_coul += ecoulhalf; + } + } + } + if (eflag_atom) { + epairhalf = 0.5 * (evdwl + ecoul); + if (newton_pair || i < nlocal) eatom[i] += epairhalf; + if (newton_pair || j < nlocal) eatom[j] += epairhalf; + } + } + + if (vflag_either) { + v[0] = delx*fx; + v[1] = dely*fy; + v[2] = delz*fz; + v[3] = delx*fy; + v[4] = delx*fz; + v[5] = dely*fz; + + if (vflag_global) { + if (newton_pair) { + virial[0] += v[0]; + virial[1] += v[1]; + virial[2] += v[2]; + virial[3] += v[3]; + virial[4] += v[4]; + virial[5] += v[5]; + } else { + if (i < nlocal) { + virial[0] += 0.5*v[0]; + virial[1] += 0.5*v[1]; + virial[2] += 0.5*v[2]; + virial[3] += 0.5*v[3]; + virial[4] += 0.5*v[4]; + virial[5] += 0.5*v[5]; + } + if (j < nlocal) { + virial[0] += 0.5*v[0]; + virial[1] += 0.5*v[1]; + virial[2] += 0.5*v[2]; + virial[3] += 0.5*v[3]; + virial[4] += 0.5*v[4]; + virial[5] += 0.5*v[5]; + } + } + } + + if (vflag_atom) { + if (newton_pair || i < nlocal) { + vatom[i][0] += 0.5*v[0]; + vatom[i][1] += 0.5*v[1]; + vatom[i][2] += 0.5*v[2]; + vatom[i][3] += 0.5*v[3]; + vatom[i][4] += 0.5*v[4]; + vatom[i][5] += 0.5*v[5]; + } + if (newton_pair || j < nlocal) { + vatom[j][0] += 0.5*v[0]; + vatom[j][1] += 0.5*v[1]; + vatom[j][2] += 0.5*v[2]; + vatom[j][3] += 0.5*v[3]; + vatom[j][4] += 0.5*v[4]; + vatom[j][5] += 0.5*v[5]; + } + } + } +} + +/* ---------------------------------------------------------------------- + tally eng_vdwl and virial into global and per-atom accumulators + called by SW and Tersoff potentials, newton_pair is always on + virial = riFi + rjFj + rkFk = (rj-ri) Fj + (rk-ri) Fk = drij*fj + drik*fk + ------------------------------------------------------------------------- */ + +void Pair::ev_tally3(int i, int j, int k, double evdwl, double ecoul, + double *fj, double *fk, double *drij, double *drik) +{ + double epairthird,v[6]; + + if (eflag_either) { + if (eflag_global) { + eng_vdwl += evdwl; + eng_coul += ecoul; + } + if (eflag_atom) { + epairthird = THIRD * (evdwl + ecoul); + eatom[i] += epairthird; + eatom[j] += epairthird; + eatom[k] += epairthird; + } + } + + if (vflag_atom) { + v[0] = THIRD * (drij[0]*fj[0] + drik[0]*fk[0]); + v[1] = THIRD * (drij[1]*fj[1] + drik[1]*fk[1]); + v[2] = THIRD * (drij[2]*fj[2] + drik[2]*fk[2]); + v[3] = THIRD * (drij[0]*fj[1] + drik[0]*fk[1]); + v[4] = THIRD * (drij[0]*fj[2] + drik[0]*fk[2]); + v[5] = THIRD * (drij[1]*fj[2] + drik[1]*fk[2]); + + vatom[i][0] += v[0]; vatom[i][1] += v[1]; vatom[i][2] += v[2]; + vatom[i][3] += v[3]; vatom[i][4] += v[4]; vatom[i][5] += v[5]; + vatom[j][0] += v[0]; vatom[j][1] += v[1]; vatom[j][2] += v[2]; + vatom[j][3] += v[3]; vatom[j][4] += v[4]; vatom[j][5] += v[5]; + vatom[k][0] += v[0]; vatom[k][1] += v[1]; vatom[k][2] += v[2]; + vatom[k][3] += v[3]; vatom[k][4] += v[4]; vatom[k][5] += v[5]; + } +} + +/* ---------------------------------------------------------------------- + tally virial into per-atom accumulators + called by airebo potential, newton_pair is always on +------------------------------------------------------------------------- */ + +void Pair::v_tally3(int i, int j, int k, + double f1, double f2, double *drik, double *drkj) +{ + double v[6]; + + v[0] = 0.0; + v[1] = 0.0; + v[2] = 0.0; + v[3] = 0.0; + v[4] = 0.0; + v[5] = 0.0; + + vatom[i][0] += v[0]; vatom[i][1] += v[1]; vatom[i][2] += v[2]; + vatom[i][3] += v[3]; vatom[i][4] += v[4]; vatom[i][5] += v[5]; + vatom[j][0] += v[0]; vatom[j][1] += v[1]; vatom[j][2] += v[2]; + vatom[j][3] += v[3]; vatom[j][4] += v[4]; vatom[j][5] += v[5]; + vatom[k][0] += v[0]; vatom[k][1] += v[1]; vatom[k][2] += v[2]; + vatom[k][3] += v[3]; vatom[k][4] += v[4]; vatom[k][5] += v[5]; +} + +/* ---------------------------------------------------------------------- + tally virial into per-atom accumulators + called by airebo potential, newton_pair is always on +------------------------------------------------------------------------- */ + +void Pair::v_tally4(int i, int j, int k, int m, + double f1, double f2, double f3, + double *drik, double *drkm, double *drmj) +{ + double v[6]; + + v[0] = 0.0; + v[1] = 0.0; + v[2] = 0.0; + v[3] = 0.0; + v[4] = 0.0; + v[5] = 0.0; + + vatom[i][0] += v[0]; vatom[i][1] += v[1]; vatom[i][2] += v[2]; + vatom[i][3] += v[3]; vatom[i][4] += v[4]; vatom[i][5] += v[5]; + vatom[j][0] += v[0]; vatom[j][1] += v[1]; vatom[j][2] += v[2]; + vatom[j][3] += v[3]; vatom[j][4] += v[4]; vatom[j][5] += v[5]; + vatom[k][0] += v[0]; vatom[k][1] += v[1]; vatom[k][2] += v[2]; + vatom[k][3] += v[3]; vatom[k][4] += v[4]; vatom[k][5] += v[5]; + vatom[m][0] += v[0]; vatom[m][1] += v[1]; vatom[m][2] += v[2]; + vatom[m][3] += v[3]; vatom[m][4] += v[4]; vatom[m][5] += v[5]; +} + +/* ---------------------------------------------------------------------- + compute global pair virial via summing F dot r over own & ghost atoms at this point, only pairwise forces have been accumulated in atom->f ------------------------------------------------------------------------- */ @@ -421,3 +785,12 @@ void Pair::init_bitmap(double inner, double outer, int ntablebits, rsq = inner*inner; masklo = *int_rsq & ~(nmask); } + +/* ---------------------------------------------------------------------- */ + +double Pair::memory_usage() +{ + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); + return bytes; +} diff --git a/src/pair.h b/src/pair.h index 1c4735fbb3..28ff5ec3be 100644 --- a/src/pair.h +++ b/src/pair.h @@ -19,9 +19,13 @@ namespace LAMMPS_NS { class Pair : protected Pointers { + friend class BondQuartic; + friend class DihedralCharmm; + public: double eng_vdwl,eng_coul; // accumulated energies double virial[6]; // accumulated virial + double *eatom,**vatom; // accumulated per-atom energy/virial double cutforce; // max cutoff for all atom pairs double **cutsq; // max cutoff sq for each atom pair @@ -52,14 +56,13 @@ class Pair : protected Pointers { }; Pair(class LAMMPS *); - virtual ~Pair() {} + virtual ~Pair(); // top-level Pair methods void init(); double mix_energy(double, double, double, double); double mix_distance(double, double); - void virial_compute(); void write_file(int, char **); void init_bitmap(double, double, int, int &, int &, int &, int &); virtual void modify_params(int, char **); @@ -90,12 +93,11 @@ class Pair : protected Pointers { virtual void unpack_comm(int, int, double *) {} virtual int pack_reverse_comm(int, int, double *) {return 0;} virtual void unpack_reverse_comm(int, int *, double *) {} - virtual double memory_usage() {return 0.0;} + virtual double memory_usage(); // specific child-class methods for certain Pair styles virtual void *extract(char *) {return NULL;} - virtual void single_embed(int, int, double &) {} virtual void swap_eam(double *, double **) {} virtual void reset_dt() {} @@ -106,6 +108,26 @@ class Pair : protected Pointers { int offset_flag,mix_flag; // flags for offset and mixing int ncoultablebits; // size of Coulomb table double tabinner; // inner cutoff for Coulomb table + + double THIRD; + + int evflag; // energy,virial settings + int eflag_either,eflag_global,eflag_atom; + int vflag_either,vflag_global,vflag_atom; + int vflag_fdotr; + int maxeatom,maxvatom; + + void ev_setup(int, int); + void ev_tally(int, int, int, int, double, double, double, + double, double, double); + void ev_tally_xyz(int, int, int, int, double, double, + double, double, double, double, double, double); + void ev_tally3(int, int, int, double, double, + double *, double *, double *, double *); + void v_tally3(int, int, int, double, double, double *, double *); + void v_tally4(int, int, int, int, double, double, double, + double *, double *, double *); + void virial_compute(); }; } diff --git a/src/pair_buck.cpp b/src/pair_buck.cpp index 67d919177b..a00fe69e7d 100644 --- a/src/pair_buck.cpp +++ b/src/pair_buck.cpp @@ -55,19 +55,20 @@ PairBuck::~PairBuck() void PairBuck::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcebuck,fforce,factor_lj; - double phibuck,r,rexp; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,r2inv,r6inv,forcebuck,factor_lj; + double r,rexp; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -108,37 +109,30 @@ void PairBuck::compute(int eflag, int vflag) r = sqrt(rsq); rexp = exp(-r*rhoinv[itype][jtype]); forcebuck = buck1[itype][jtype]*r*rexp - buck2[itype][jtype]*r6inv; - fforce = factor_lj*forcebuck*r2inv; + fpair = factor_lj*forcebuck*r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - phibuck = a[itype][jtype]*rexp - c[itype][jtype]*r6inv - + evdwl = a[itype][jtype]*rexp - c[itype][jtype]*r6inv - offset[itype][jtype]; - if (newton_pair || j < nlocal) eng_vdwl += factor_lj*phibuck; - else eng_vdwl += 0.5*factor_lj*phibuck; + evdwl *= factor_lj; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/pair_buck_coul_cut.cpp b/src/pair_buck_coul_cut.cpp index 955b98c7cd..bd83e30390 100644 --- a/src/pair_buck_coul_cut.cpp +++ b/src/pair_buck_coul_cut.cpp @@ -63,20 +63,21 @@ PairBuckCoulCut::~PairBuckCoulCut() void PairBuckCoulCut::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcecoul,forcebuck,fforce,factor_coul,factor_lj; - double factor,phicoul,phibuck,r,rexp; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double rsq,r2inv,r6inv,forcecoul,forcebuck,factor_coul,factor_lj; + double r,rexp; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -129,44 +130,35 @@ void PairBuckCoulCut::compute(int eflag, int vflag) forcebuck = buck1[itype][jtype]*r*rexp - buck2[itype][jtype]*r6inv; } else forcebuck = 0.0; - fforce = (factor_coul*forcecoul + factor_lj*forcebuck) * r2inv; + fpair = (factor_coul*forcecoul + factor_lj*forcebuck) * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; - if (rsq < cut_coulsq[itype][jtype]) { - phicoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); - eng_coul += factor*factor_coul*phicoul; - } + if (rsq < cut_coulsq[itype][jtype]) + ecoul = factor_coul * qqrd2e * qtmp*q[j]*sqrt(r2inv); + else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { - phibuck = a[itype][jtype]*rexp - c[itype][jtype]*r6inv - + evdwl = a[itype][jtype]*rexp - c[itype][jtype]*r6inv - offset[itype][jtype]; - eng_vdwl += factor*factor_lj*phibuck; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/pair_coul_cut.cpp b/src/pair_coul_cut.cpp index ba5f6a44ef..6296a47512 100644 --- a/src/pair_coul_cut.cpp +++ b/src/pair_coul_cut.cpp @@ -50,19 +50,20 @@ PairCoulCut::~PairCoulCut() void PairCoulCut::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,rinv,forcecoul,fforce,factor_coul,phicoul; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,ecoul,fpair; + double rsq,r2inv,rinv,forcecoul,factor_coul; int *ilist,*jlist,*numneigh,**firstneigh; - eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; int newton_pair = force->newton_pair; double qqrd2e = force->qqrd2e; @@ -103,36 +104,26 @@ void PairCoulCut::compute(int eflag, int vflag) r2inv = 1.0/rsq; rinv = sqrt(r2inv); forcecoul = qqrd2e * qtmp*q[j]*rinv; - fforce = factor_coul*forcecoul * r2inv; + fpair = factor_coul*forcecoul * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } - if (eflag) { - phicoul = qqrd2e * qtmp*q[j]*rinv; - if (newton_pair || j < nlocal) eng_coul += factor_coul*phicoul; - else eng_coul += 0.5*factor_coul*phicoul; - } + if (eflag) ecoul = factor_coul * qqrd2e * qtmp*q[j]*rinv; - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + 0.0,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/pair_hybrid.cpp b/src/pair_hybrid.cpp index e0f83607c5..a565551fe6 100644 --- a/src/pair_hybrid.cpp +++ b/src/pair_hybrid.cpp @@ -58,7 +58,7 @@ PairHybrid::~PairHybrid() /* ---------------------------------------------------------------------- call each sub-style's compute function - accumulate sub-style energy/virial in hybrid's energy/virial + accumulate sub-style global/peratom energy/virial in hybrid for vflag = 1: each sub-style computes own virial[6] sum sub-style virial[6] to hybrid's virial[6] @@ -70,21 +70,47 @@ PairHybrid::~PairHybrid() void PairHybrid::compute(int eflag, int vflag) { - int m,n; + int i,j,m,n; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (n = 0; n < 6; n++) virial[n] = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; + + // don't allow substyle to invoke virial_compute() + // if vflag has that setting, change vflag passed to substyle + // preserve vflag_atom option in what is passed to substyle + + int vflag_substyle; + int vflag_global_substyle = vflag % 4; + if (vflag_global_substyle == 2) { + vflag_substyle = vflag/4 * 4; + } else vflag_substyle = vflag; for (m = 0; m < nstyles; m++) { - styles[m]->compute(eflag,vflag % 2); - if (eflag) { + styles[m]->compute(eflag,vflag_substyle); + + if (eflag_global) { eng_vdwl += styles[m]->eng_vdwl; eng_coul += styles[m]->eng_coul; } - if (vflag == 1) for (n = 0; n < 6; n++) virial[n] += styles[m]->virial[n]; + if (vflag_global) + for (n = 0; n < 6; n++) virial[n] += styles[m]->virial[n]; + if (eflag_atom) { + n = atom->nlocal; + if (force->newton_pair) n += atom->nghost; + double *eatom_substyle = styles[m]->eatom; + for (i = 0; i < n; i++) eatom[i] += eatom_substyle[i]; + } + if (vflag_atom) { + n = atom->nlocal; + if (force->newton_pair) n += atom->nghost; + double **vatom_substyle = styles[m]->vatom; + for (i = 0; i < n; i++) + for (j = 0; j < 6; j++) + vatom[i][j] += vatom_substyle[i][j]; + } } - if (vflag == 2) virial_compute(); + if (vflag_fdotr == 2) virial_compute(); } /* ---------------------------------------------------------------------- */ @@ -531,39 +557,20 @@ void PairHybrid::single(int i, int j, int itype, int jtype, error->one("Invoked pair single on pair style none"); double fforce = 0.0; - double eng_vdwl = 0.0; - double eng_coul = 0.0; + double evdwl = 0.0; + double ecoul = 0.0; for (int m = 0; m < nmap[itype][jtype]; m++) { styles[map[itype][jtype][m]]-> single(i,j,itype,jtype,rsq,factor_coul,factor_lj,eflag,one); fforce += one.fforce; - eng_vdwl += one.eng_vdwl; - eng_coul += one.eng_coul; + evdwl += one.eng_vdwl; + ecoul += one.eng_coul; } one.fforce = fforce; - one.eng_vdwl = eng_vdwl; - one.eng_coul = eng_coul; -} - -/* ---------------------------------------------------------------------- - call sub-style to compute single embedding interaction - since overlay could have multiple sub-styles, sum results explicitly -------------------------------------------------------------------------- */ - -void PairHybrid::single_embed(int i, int itype, double &phi) -{ - if (nmap[itype][itype] == 0) - error->one("Invoked pair single on pair style none"); - - phi = 0.0; - double phi_single; - - for (int m = 0; m < nmap[itype][itype]; m++) { - styles[map[itype][itype][m]]->single_embed(i,itype,phi_single); - phi += phi_single; - } + one.eng_vdwl = evdwl; + one.eng_coul = ecoul; } /* ---------------------------------------------------------------------- @@ -584,7 +591,8 @@ void PairHybrid::modify_params(int narg, char **arg) double PairHybrid::memory_usage() { - double bytes = 0.0; + double bytes = maxeatom * sizeof(double); + bytes += maxvatom*6 * sizeof(double); for (int m = 0; m < nstyles; m++) bytes += styles[m]->memory_usage(); return bytes; } diff --git a/src/pair_hybrid.h b/src/pair_hybrid.h index 0ba7f0bc57..df80b4ba9a 100644 --- a/src/pair_hybrid.h +++ b/src/pair_hybrid.h @@ -35,7 +35,6 @@ class PairHybrid : public Pair { void write_restart(FILE *); void read_restart(FILE *); void single(int, int, int, int, double, double, double, int, One &); - void single_embed(int, int, double &); void modify_params(int narg, char **arg); double memory_usage(); diff --git a/src/pair_lj_cut.cpp b/src/pair_lj_cut.cpp index af2743af5c..ebd3c1a586 100644 --- a/src/pair_lj_cut.cpp +++ b/src/pair_lj_cut.cpp @@ -68,18 +68,19 @@ PairLJCut::~PairLJCut() void PairLJCut::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcelj,fforce,factor_lj,philj; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,r2inv,r6inv,forcelj,factor_lj; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -118,37 +119,30 @@ void PairLJCut::compute(int eflag, int vflag) r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); - fforce = factor_lj*forcelj*r2inv; + fpair = factor_lj*forcelj*r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; - if (newton_pair || j < nlocal) eng_vdwl += factor_lj*philj; - else eng_vdwl += 0.5*factor_lj*philj; + evdwl *= factor_lj; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- */ @@ -156,15 +150,15 @@ void PairLJCut::compute(int eflag, int vflag) void PairLJCut::compute_inner() { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcelj,fforce,factor_lj,rsw; + double xtmp,ytmp,ztmp,delx,dely,delz,fpair; + double rsq,r2inv,r6inv,forcelj,factor_lj,rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -210,19 +204,19 @@ void PairLJCut::compute_inner() r6inv = r2inv*r2inv*r2inv; jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); - fforce = factor_lj*forcelj*r2inv; + fpair = factor_lj*forcelj*r2inv; if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; - fforce *= 1.0 - rsw*rsw*(3.0 - 2.0*rsw); + fpair *= 1.0 - rsw*rsw*(3.0 - 2.0*rsw); } - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } } } @@ -234,15 +228,15 @@ void PairLJCut::compute_inner() void PairLJCut::compute_middle() { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcelj,fforce,factor_lj,rsw; + double xtmp,ytmp,ztmp,delx,dely,delz,fpair; + double rsq,r2inv,r6inv,forcelj,factor_lj,rsw; int *ilist,*jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -293,23 +287,23 @@ void PairLJCut::compute_middle() r6inv = r2inv*r2inv*r2inv; jtype = type[j]; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); - fforce = factor_lj*forcelj*r2inv; + fpair = factor_lj*forcelj*r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; - fforce *= rsw*rsw*(3.0 - 2.0*rsw); + fpair *= rsw*rsw*(3.0 - 2.0*rsw); } if (rsq > cut_out_on_sq) { rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff; - fforce *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); + fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0); } - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } } } @@ -321,18 +315,19 @@ void PairLJCut::compute_middle() void PairLJCut::compute_outer(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcelj,fforce,factor_lj,philj,rsw; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,r2inv,r6inv,forcelj,factor_lj,rsw; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -379,29 +374,28 @@ void PairLJCut::compute_outer(int eflag, int vflag) r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); - fforce = factor_lj*forcelj*r2inv; + fpair = factor_lj*forcelj*r2inv; if (rsq < cut_in_on_sq) { rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff; - fforce *= rsw*rsw*(3.0 - 2.0*rsw); + fpair *= rsw*rsw*(3.0 - 2.0*rsw); } - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } } if (eflag) { r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; - if (newton_pair || j < nlocal) eng_vdwl += factor_lj*philj; - else eng_vdwl += 0.5*factor_lj*philj; + evdwl *= factor_lj; } if (vflag) { @@ -409,18 +403,13 @@ void PairLJCut::compute_outer(int eflag, int vflag) r2inv = 1.0/rsq; r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); - fforce = factor_lj*forcelj*r2inv; + fpair = factor_lj*forcelj*r2inv; } else if (rsq < cut_in_on_sq) - fforce = factor_lj*forcelj*r2inv; - - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; + fpair = factor_lj*forcelj*r2inv; } + + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } diff --git a/src/pair_lj_cut_coul_cut.cpp b/src/pair_lj_cut_coul_cut.cpp index 5c0d08a4db..ea718d029c 100644 --- a/src/pair_lj_cut_coul_cut.cpp +++ b/src/pair_lj_cut_coul_cut.cpp @@ -60,20 +60,20 @@ PairLJCutCoulCut::~PairLJCutCoulCut() void PairLJCutCoulCut::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; - double factor,phicoul,philj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -124,44 +124,35 @@ void PairLJCutCoulCut::compute(int eflag, int vflag) forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; - fforce = (factor_coul*forcecoul + factor_lj*forcelj) * r2inv; + fpair = (factor_coul*forcecoul + factor_lj*forcelj) * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; - if (rsq < cut_coulsq[itype][jtype]) { - phicoul = qqrd2e * qtmp*q[j]*sqrt(r2inv); - eng_coul += factor*factor_coul*phicoul; - } + if (rsq < cut_coulsq[itype][jtype]) + ecoul = factor_coul * qqrd2e * qtmp*q[j]*sqrt(r2inv); + else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/pair_lj_cut_coul_debye.cpp b/src/pair_lj_cut_coul_debye.cpp index f4c28e6dba..2b41c480f1 100644 --- a/src/pair_lj_cut_coul_debye.cpp +++ b/src/pair_lj_cut_coul_debye.cpp @@ -31,21 +31,21 @@ PairLJCutCoulDebye::PairLJCutCoulDebye(LAMMPS *lmp) : PairLJCutCoulCut(lmp) {} void PairLJCutCoulDebye::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double qtmp,xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcecoul,forcelj,fforce,factor_coul,factor_lj; - double factor,phicoul,philj; + double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj; double r,rinv,screening; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; double *q = atom->q; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -99,44 +99,35 @@ void PairLJCutCoulDebye::compute(int eflag, int vflag) forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); } else forcelj = 0.0; - fforce = (factor_coul*forcecoul + factor_lj*forcelj) * r2inv; + fpair = (factor_coul*forcecoul + factor_lj*forcelj) * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - if (newton_pair || j < nlocal) factor = 1.0; - else factor = 0.5; - if (rsq < cut_coulsq[itype][jtype]) { - phicoul = qqrd2e * qtmp*q[j] * rinv * screening; - eng_coul += factor*factor_coul*phicoul; - } + if (rsq < cut_coulsq[itype][jtype]) + ecoul = factor_coul * qqrd2e * qtmp*q[j] * rinv * screening; + else ecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; - eng_vdwl += factor*factor_lj*philj; - } + evdwl *= factor_lj; + } else evdwl = 0.0; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/pair_lj_expand.cpp b/src/pair_lj_expand.cpp index f43d8d62bf..ce14a27574 100644 --- a/src/pair_lj_expand.cpp +++ b/src/pair_lj_expand.cpp @@ -56,19 +56,20 @@ PairLJExpand::~PairLJExpand() void PairLJExpand::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,forcelj,fforce,factor_lj,philj; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,r2inv,r6inv,forcelj,factor_lj; double r,rshift,rshiftsq; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -110,37 +111,30 @@ void PairLJExpand::compute(int eflag, int vflag) r2inv = 1.0/rshiftsq; r6inv = r2inv*r2inv*r2inv; forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]); - fforce = factor_lj*forcelj/rshift/r; + fpair = factor_lj*forcelj/rshift/r; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - + evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; - if (newton_pair || j < nlocal) eng_vdwl += factor_lj*philj; - else eng_vdwl += 0.5*factor_lj*philj; + evdwl *= factor_lj; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/pair_lj_smooth.cpp b/src/pair_lj_smooth.cpp index 5a70395d24..cc6c75798b 100644 --- a/src/pair_lj_smooth.cpp +++ b/src/pair_lj_smooth.cpp @@ -66,19 +66,20 @@ PairLJSmooth::~PairLJSmooth() void PairLJSmooth::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r6inv,r,forcelj,fforce,factor_lj,philj; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,r2inv,r6inv,r,forcelj,factor_lj; double t,tsq,fskin; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; - + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -127,42 +128,35 @@ void PairLJSmooth::compute(int eflag, int vflag) forcelj = fskin*r; } - fforce = factor_lj*forcelj*r2inv; + fpair = factor_lj*forcelj*r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { if (rsq < cut_inner_sq[itype][jtype]) - philj = r6inv * (lj3[itype][jtype]*r6inv - + evdwl = r6inv * (lj3[itype][jtype]*r6inv - lj4[itype][jtype]) - offset[itype][jtype]; else - philj = ljsw0[itype][jtype] - ljsw1[itype][jtype]*t - + evdwl = ljsw0[itype][jtype] - ljsw1[itype][jtype]*t - ljsw2[itype][jtype]*tsq/2.0 - ljsw3[itype][jtype]*tsq*t/3.0 - ljsw4[itype][jtype]*tsq*tsq/4.0 - offset[itype][jtype]; - if (newton_pair || j < nlocal) eng_vdwl += factor_lj*philj; - else eng_vdwl += 0.5*factor_lj*philj; - } - - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; + evdwl *= factor_lj; } + + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/pair_morse.cpp b/src/pair_morse.cpp index 66cc36ec01..3da5c26d32 100644 --- a/src/pair_morse.cpp +++ b/src/pair_morse.cpp @@ -53,18 +53,19 @@ PairMorse::~PairMorse() void PairMorse::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r,dr,dexp,fforce,factor_lj,phi; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,r,dr,dexp,factor_lj; int *ilist,*jlist,*numneigh,**firstneigh; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -103,37 +104,30 @@ void PairMorse::compute(int eflag, int vflag) r = sqrt(rsq); dr = r - r0[itype][jtype]; dexp = exp(-alpha[itype][jtype] * dr); - fforce = factor_lj * morse1[itype][jtype] * (dexp*dexp - dexp) / r; + fpair = factor_lj * morse1[itype][jtype] * (dexp*dexp - dexp) / r; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - phi = d0[itype][jtype] * (dexp*dexp - 2.0*dexp) - + evdwl = d0[itype][jtype] * (dexp*dexp - 2.0*dexp) - offset[itype][jtype]; - if (newton_pair || j < nlocal) eng_vdwl += factor_lj*phi; - else eng_vdwl += 0.5*factor_lj*phi; + evdwl *= factor_lj; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/pair_soft.cpp b/src/pair_soft.cpp index afd46c6dfd..d9e2bf69af 100644 --- a/src/pair_soft.cpp +++ b/src/pair_soft.cpp @@ -55,10 +55,14 @@ PairSoft::~PairSoft() void PairSoft::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double r,rsq,arg,fforce,factor_lj,philj; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double r,rsq,arg,factor_lj; int *ilist,*jlist,*numneigh,**firstneigh; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + // set current prefactor // for minimization, set to prestop // for dynamics, ramp from prestart to prestop @@ -74,14 +78,11 @@ void PairSoft::compute(int eflag, int vflag) prefactor[i][j] = prestart[i][j] + delta * (prestop[i][j] - prestart[i][j]); - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; - double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -119,38 +120,29 @@ void PairSoft::compute(int eflag, int vflag) if (rsq < cutsq[itype][jtype]) { r = sqrt(rsq); arg = PI*r/cut[itype][jtype]; - if (r == 0.0) fforce = 0.0; - else fforce = factor_lj * prefactor[itype][jtype] * - sin(arg) * PI/cut[itype][jtype]/r; + if (r > 0.0) fpair = factor_lj * prefactor[itype][jtype] * + sin(arg) * PI/cut[itype][jtype]/r; + else fpair = 0.0; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } - if (eflag) { - philj = prefactor[itype][jtype] * (1.0+cos(arg)); - if (newton_pair || j < nlocal) eng_vdwl += factor_lj*philj; - else eng_vdwl += 0.5*factor_lj*philj; - } + if (eflag) + evdwl = factor_lj * prefactor[itype][jtype] * (1.0+cos(arg)); - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/pair_table.cpp b/src/pair_table.cpp index f0f1a13515..0ba6e359ff 100644 --- a/src/pair_table.cpp +++ b/src/pair_table.cpp @@ -70,21 +70,22 @@ PairTable::~PairTable() void PairTable::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype,itable; - double xtmp,ytmp,ztmp,delx,dely,delz,rsq; - double fforce,factor_lj,phi,fraction,value,a,b; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,factor_lj,fraction,value,a,b; int *ilist,*jlist,*numneigh,**firstneigh; Table *tb; float rsq_single; int *int_rsq = (int *) &rsq_single; - eng_vdwl = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + evdwl = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_lj = force->special_lj; int newton_pair = force->newton_pair; @@ -128,14 +129,14 @@ void PairTable::compute(int eflag, int vflag) itable = static_cast ((rsq - tb->innersq) * tb->invdelta); if (itable >= nm1) error->one("Pair distance > table outer cutoff"); - fforce = factor_lj * tb->f[itable]; + fpair = factor_lj * tb->f[itable]; } else if (tabstyle == LINEAR) { itable = static_cast ((rsq - tb->innersq) * tb->invdelta); if (itable >= nm1) error->one("Pair distance > table outer cutoff"); fraction = (rsq - tb->rsq[itable]) * tb->invdelta; value = tb->f[itable] + fraction*tb->df[itable]; - fforce = factor_lj * value; + fpair = factor_lj * value; } else if (tabstyle == SPLINE) { itable = static_cast ((rsq - tb->innersq) * tb->invdelta); if (itable >= nm1) @@ -145,51 +146,44 @@ void PairTable::compute(int eflag, int vflag) value = a * tb->f[itable] + b * tb->f[itable+1] + ((a*a*a-a)*tb->f2[itable] + (b*b*b-b)*tb->f2[itable+1]) * tb->deltasq6; - fforce = factor_lj * value; + fpair = factor_lj * value; } else { rsq_single = rsq; itable = *int_rsq & tb->nmask; itable >>= tb->nshiftbits; fraction = (rsq_single - tb->rsq[itable]) * tb->drsq[itable]; value = tb->f[itable] + fraction*tb->df[itable]; - fforce = factor_lj * value; + fpair = factor_lj * value; } - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { if (tabstyle == LOOKUP) - phi = tb->e[itable]; + evdwl = tb->e[itable]; else if (tabstyle == LINEAR || tabstyle == BITMAP) - phi = tb->e[itable] + fraction*tb->de[itable]; + evdwl = tb->e[itable] + fraction*tb->de[itable]; else - phi = a * tb->e[itable] + b * tb->e[itable+1] + + evdwl = a * tb->e[itable] + b * tb->e[itable+1] + ((a*a*a-a)*tb->e2[itable] + (b*b*b-b)*tb->e2[itable+1]) * tb->deltasq6; - if (newton_pair || j < nlocal) eng_vdwl += factor_lj*phi; - else eng_vdwl += 0.5*factor_lj*phi; + evdwl *= factor_lj; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/pair_yukawa.cpp b/src/pair_yukawa.cpp index 472575eb0a..200df3c47f 100644 --- a/src/pair_yukawa.cpp +++ b/src/pair_yukawa.cpp @@ -49,18 +49,19 @@ PairYukawa::~PairYukawa() void PairYukawa::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double rsq,r2inv,r,rinv,screening,forceyukawa,fforce,factor_coul,phi; + double xtmp,ytmp,ztmp,delx,dely,delz,ecoul,fpair; + double rsq,r2inv,r,rinv,screening,forceyukawa,factor_coul; int *ilist,*jlist,*numneigh,**firstneigh; - eng_coul = 0.0; - if (vflag) for (i = 0; i < 6; i++) virial[i] = 0.0; + ecoul = 0.0; + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; double **x = atom->x; double **f = atom->f; int *type = atom->type; int nlocal = atom->nlocal; - int nall = atom->nlocal + atom->nghost; + int nall = nlocal + atom->nghost; double *special_coul = force->special_coul; int newton_pair = force->newton_pair; @@ -102,36 +103,29 @@ void PairYukawa::compute(int eflag, int vflag) screening = exp(-kappa*r); forceyukawa = a[itype][jtype] * screening * (kappa + rinv); - fforce = factor_coul*forceyukawa * r2inv; + fpair = factor_coul*forceyukawa * r2inv; - f[i][0] += delx*fforce; - f[i][1] += dely*fforce; - f[i][2] += delz*fforce; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; if (newton_pair || j < nlocal) { - f[j][0] -= delx*fforce; - f[j][1] -= dely*fforce; - f[j][2] -= delz*fforce; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; } if (eflag) { - phi = a[itype][jtype] * screening * rinv - offset[itype][jtype]; - if (newton_pair || j < nlocal) eng_coul += factor_coul*phi; - else eng_coul += 0.5*factor_coul*phi; + ecoul = a[itype][jtype] * screening * rinv - offset[itype][jtype]; + ecoul *= factor_coul; } - if (vflag == 1) { - if (newton_pair == 0 && j >= nlocal) fforce *= 0.5; - virial[0] += delx*delx*fforce; - virial[1] += dely*dely*fforce; - virial[2] += delz*delz*fforce; - virial[3] += delx*dely*fforce; - virial[4] += delx*delz*fforce; - virial[5] += dely*delz*fforce; - } + if (evflag) ev_tally(i,j,nlocal,newton_pair, + 0.0,ecoul,fpair,delx,dely,delz); } } } - if (vflag == 2) virial_compute(); + + if (vflag_fdotr) virial_compute(); } /* ---------------------------------------------------------------------- diff --git a/src/respa.cpp b/src/respa.cpp index caae026ad0..e201d22a23 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -273,26 +273,9 @@ void Respa::init() virial_style = 1; - // elist,vlist = list of computes for PE and pressure + // setup lists of computes for global and per-atom PE and pressure - delete [] elist; - delete [] vlist; - elist = vlist = NULL; - - nelist = nvlist = 0; - for (int i = 0; i < modify->ncompute; i++) { - if (modify->compute[i]->peflag) nelist++; - if (modify->compute[i]->pressflag) nvlist++; - } - - if (nelist) elist = new Compute*[nelist]; - if (nvlist) vlist = new Compute*[nvlist]; - - nelist = nvlist = 0; - for (int i = 0; i < modify->ncompute; i++) { - if (modify->compute[i]->peflag) elist[nelist++] = modify->compute[i]; - if (modify->compute[i]->pressflag) vlist[nvlist++] = modify->compute[i]; - } + ev_setup(); // step[] = timestep for each level diff --git a/src/style.h b/src/style.h index 2294e78d92..5d03f7a4b7 100644 --- a/src/style.h +++ b/src/style.h @@ -79,10 +79,9 @@ CommandStyle(write_restart,WriteRestart) #include "compute_attribute_atom.h" #include "compute_centro_atom.h" #include "compute_coord_atom.h" -#include "compute_ebond_atom.h" -#include "compute_epair_atom.h" #include "compute_ke_atom.h" #include "compute_pe.h" +#include "compute_pe_atom.h" #include "compute_pressure.h" #include "compute_rotate_dipole.h" #include "compute_rotate_gran.h" @@ -102,10 +101,9 @@ CommandStyle(write_restart,WriteRestart) ComputeStyle(attribute/atom,ComputeAttributeAtom) ComputeStyle(centro/atom,ComputeCentroAtom) ComputeStyle(coord/atom,ComputeCoordAtom) -ComputeStyle(ebond/atom,ComputeEbondAtom) -ComputeStyle(epair/atom,ComputeEpairAtom) ComputeStyle(ke/atom,ComputeKEAtom) ComputeStyle(pe,ComputePE) +ComputeStyle(pe/atom,ComputePEAtom) ComputeStyle(pressure,ComputePressure) ComputeStyle(rotate/dipole,ComputeRotateDipole) ComputeStyle(rotate/gran,ComputeRotateGran) diff --git a/src/style_granular.h b/src/style_granular.h index 7b0f4b6a71..5e89edb020 100644 --- a/src/style_granular.h +++ b/src/style_granular.h @@ -21,7 +21,6 @@ AtomStyle(granular,AtomVecGranular) #ifdef FixInclude #include "fix_freeze.h" -#include "fix_gran_diag.h" #include "fix_nve_gran.h" #include "fix_pour.h" #include "fix_shear_history.h" @@ -30,7 +29,6 @@ AtomStyle(granular,AtomVecGranular) #ifdef FixClass FixStyle(freeze,FixFreeze) -FixStyle(gran/diag,FixGranDiag) FixStyle(nve/gran,FixNVEGran) FixStyle(pour,FixPour) FixStyle(SHEAR_HISTORY,FixShearHistory) diff --git a/src/thermo.cpp b/src/thermo.cpp index 0a37fa1edb..6209ddf490 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -276,7 +276,6 @@ void Thermo::header() void Thermo::compute(int flag) { int i; - double tmp; firststep = flag; @@ -291,7 +290,7 @@ void Thermo::compute(int flag) // call compute_scalar() if which = 0, else compute_vector() for (i = 0; i < ncompute; i++) { - if (compute_which[i] % 2 == 0) tmp = computes[i]->compute_scalar(); + if (compute_which[i] % 2 == 0) double tmp = computes[i]->compute_scalar(); if (compute_which[i] > 0) computes[i]->compute_vector(); } @@ -1155,9 +1154,6 @@ void Thermo::compute_evdwl() { double tmp = 0.0; if (force->pair) tmp += force->pair->eng_vdwl; - if (force->bond) tmp += force->bond->eng_vdwl; - if (force->dihedral) tmp += force->dihedral->eng_vdwl; - MPI_Allreduce(&tmp,&dvalue,1,MPI_DOUBLE,MPI_SUM,world); if (force->pair && force->pair->tail_flag) { @@ -1174,7 +1170,6 @@ void Thermo::compute_ecoul() { double tmp = 0.0; if (force->pair) tmp += force->pair->eng_coul; - if (force->dihedral) tmp += force->dihedral->eng_coul; MPI_Allreduce(&tmp,&dvalue,1,MPI_DOUBLE,MPI_SUM,world); if (normflag) dvalue /= natoms; } @@ -1185,9 +1180,6 @@ void Thermo::compute_epair() { double tmp = 0.0; if (force->pair) tmp += force->pair->eng_vdwl + force->pair->eng_coul; - if (force->bond) tmp += force->bond->eng_vdwl; - if (force->dihedral) - tmp += force->dihedral->eng_vdwl + force->dihedral->eng_coul; MPI_Allreduce(&tmp,&dvalue,1,MPI_DOUBLE,MPI_SUM,world); if (force->kspace) dvalue += force->kspace->energy; diff --git a/src/verlet.cpp b/src/verlet.cpp index 664340659d..4a3872fc0e 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -58,26 +58,9 @@ void Verlet::init() if (force->newton_pair) virial_style = 2; else virial_style = 1; - // elist,vlist = list of computes for PE and pressure + // setup lists of computes for global and per-atom PE and pressure - delete [] elist; - delete [] vlist; - elist = vlist = NULL; - - nelist = nvlist = 0; - for (int i = 0; i < modify->ncompute; i++) { - if (modify->compute[i]->peflag) nelist++; - if (modify->compute[i]->pressflag) nvlist++; - } - - if (nelist) elist = new Compute*[nelist]; - if (nvlist) vlist = new Compute*[nvlist]; - - nelist = nvlist = 0; - for (int i = 0; i < modify->ncompute; i++) { - if (modify->compute[i]->peflag) elist[nelist++] = modify->compute[i]; - if (modify->compute[i]->pressflag) vlist[nvlist++] = modify->compute[i]; - } + ev_setup(); // set flags for what arrays to clear in force_clear() // need to clear torques if array exists @@ -116,7 +99,7 @@ void Verlet::setup() // compute all forces ev_set(update->ntimestep); - force_clear(vflag); + force_clear(); if (force->pair) force->pair->compute(eflag,vflag); @@ -184,7 +167,7 @@ void Verlet::iterate(int n) // force computations ev_set(ntimestep); - force_clear(vflag); + force_clear(); timer->stamp(); @@ -234,7 +217,7 @@ void Verlet::iterate(int n) setup and clear other arrays as needed ------------------------------------------------------------------------- */ -void Verlet::force_clear(int vflag) +void Verlet::force_clear() { int i; diff --git a/src/verlet.h b/src/verlet.h index e46995329c..41b94dcb08 100644 --- a/src/verlet.h +++ b/src/verlet.h @@ -28,9 +28,9 @@ class Verlet : public Integrate { private: int triclinic; // 0 if domain is orthog, 1 if triclinic - int torqueflag; // arrays to zero out every step + int torqueflag; // zero out array every step - void force_clear(int); + void force_clear(); }; }