diff --git a/src/USER-MISC/dihedral_nharmonic.cpp b/src/USER-MISC/dihedral_nharmonic.cpp index 03f235b166..7b30f3d055 100644 --- a/src/USER-MISC/dihedral_nharmonic.cpp +++ b/src/USER-MISC/dihedral_nharmonic.cpp @@ -181,15 +181,14 @@ void DihedralNHarmonic::compute(int eflag, int vflag) // p = sum (i=1,n) a_i * c**(i-1) // pd = dp/dc - c_ = c; - p = this->a[type][0]; - pd = this->a[type][1]; - for (int i = 1; i < nterms[type]-1; i++) { - p += c_ * this->a[type][i]; - pd += c_ * static_cast(i+1) * this->a[type][i+1]; + c_ = 1.0; + p = a[type][0]; + pd = 0.0; + for (int i = 1; i < nterms[type]; i++) { + pd += c_ * i * a[type][i]; c_ *= c; + p += c_ * a[type][i]; } - p += c_ * this->a[type][nterms[type]-1]; if (eflag) edihedral = p; @@ -275,7 +274,7 @@ void DihedralNHarmonic::allocate() void DihedralNHarmonic::coeff(int narg, char **arg) { - if (narg < 4 ) error->all(FLERR,"Incorrect args for dihedral coefficients"); + if (narg < 3) error->all(FLERR,"Incorrect args for dihedral coefficients"); int n = utils::inumeric(FLERR,arg[1],false,lmp); if (narg != n + 2) diff --git a/src/USER-OMP/dihedral_nharmonic_omp.cpp b/src/USER-OMP/dihedral_nharmonic_omp.cpp index 89b3952d59..35899072a9 100644 --- a/src/USER-OMP/dihedral_nharmonic_omp.cpp +++ b/src/USER-OMP/dihedral_nharmonic_omp.cpp @@ -203,15 +203,15 @@ void DihedralNHarmonicOMP::eval(int nfrom, int nto, ThrData * const thr) // force & energy // p = sum (i=1,n) a_i * c**(i-1) // pd = dp/dc - c_ = c; + + c_ = 1.0; p = a[type][0]; - pd = a[type][1]; - for (int i = 1; i < nterms[type]-1; i++) { - p += c_ * a[type][i]; - pd += c_ * static_cast(i+1) * a[type][i+1]; + pd = 0.0; + for (int i = 1; i < nterms[type]; i++) { + pd += c_ * i * a[type][i]; c_ *= c; + p += c_ * a[type][i]; } - p += c_ * a[type][nterms[type]-1]; if (EFLAG) edihedral = p;