Fix invalid result when dihedral quadratic angle is > pi or < -pi

This commit is contained in:
Julien Devemy
2020-12-01 09:21:12 +01:00
parent 5ea9d97024
commit 5a00d3c157
2 changed files with 6 additions and 0 deletions

View File

@ -195,6 +195,8 @@ void DihedralQuadratic::compute(int eflag, int vflag)
siinv = 1.0/si; siinv = 1.0/si;
double dphi = phi-phi0[type]; double dphi = phi-phi0[type];
if (dphi > MY_PI) dphi -= 2*MY_PI;
else if (dphi < -MY_PI) dphi += 2*MY_PI;
p = k[type]*dphi; p = k[type]*dphi;
pd = - 2.0 * p * siinv; pd = - 2.0 * p * siinv;
p = p * dphi; p = p * dphi;

View File

@ -23,11 +23,13 @@
#include "neighbor.h" #include "neighbor.h"
#include "force.h" #include "force.h"
#include "update.h" #include "update.h"
#include "math_const.h"
#include "error.h" #include "error.h"
#include "suffix.h" #include "suffix.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace MathConst;
#define TOLERANCE 0.05 #define TOLERANCE 0.05
#define SMALL 0.001 #define SMALL 0.001
@ -218,6 +220,8 @@ void DihedralQuadraticOMP::eval(int nfrom, int nto, ThrData * const thr)
siinv = 1.0/si; siinv = 1.0/si;
double dphi = phi-phi0[type]; double dphi = phi-phi0[type];
if (dphi > MY_PI) dphi -= 2*MY_PI;
else if (dphi < -MY_PI) dphi += 2*MY_PI;
p = k[type]*dphi; p = k[type]*dphi;
pd = - 2.0 * p * siinv; pd = - 2.0 * p * siinv;
p = p * dphi; p = p * dphi;