forked from lijiext/lammps
263 lines
7.0 KiB
C++
263 lines
7.0 KiB
C++
/* ----------------------------------------------------------------------
|
|
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
|
http://lammps.sandia.gov, Sandia National Laboratories
|
|
Steve Plimpton, sjplimp@sandia.gov
|
|
|
|
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
|
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
|
certain rights in this software. This software is distributed under
|
|
the GNU General Public License.
|
|
|
|
See the README file in the top-level LAMMPS directory.
|
|
------------------------------------------------------------------------- */
|
|
|
|
/* ----------------------------------------------------------------------
|
|
Contributing author: Axel Kohlmeyer (Temple U)
|
|
------------------------------------------------------------------------- */
|
|
|
|
#include "math.h"
|
|
#include "dihedral_cosine_shift_exp_omp.h"
|
|
#include "atom.h"
|
|
#include "comm.h"
|
|
#include "neighbor.h"
|
|
#include "domain.h"
|
|
#include "force.h"
|
|
#include "update.h"
|
|
#include "error.h"
|
|
|
|
#include "suffix.h"
|
|
using namespace LAMMPS_NS;
|
|
|
|
#define TOLERANCE 0.05
|
|
#define SMALL 0.001
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
DihedralCosineShiftExpOMP::DihedralCosineShiftExpOMP(class LAMMPS *lmp)
|
|
: DihedralCosineShiftExp(lmp), ThrOMP(lmp,THR_DIHEDRAL)
|
|
{
|
|
suffix_flag |= Suffix::OMP;
|
|
}
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
void DihedralCosineShiftExpOMP::compute(int eflag, int vflag)
|
|
{
|
|
|
|
if (eflag || vflag) {
|
|
ev_setup(eflag,vflag);
|
|
} else evflag = 0;
|
|
|
|
const int nall = atom->nlocal + atom->nghost;
|
|
const int nthreads = comm->nthreads;
|
|
const int inum = neighbor->ndihedrallist;
|
|
|
|
#if defined(_OPENMP)
|
|
#pragma omp parallel default(none) shared(eflag,vflag)
|
|
#endif
|
|
{
|
|
int ifrom, ito, tid;
|
|
|
|
loop_setup_thr(ifrom, ito, tid, inum, nthreads);
|
|
ThrData *thr = fix->get_thr(tid);
|
|
ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr);
|
|
|
|
if (evflag) {
|
|
if (eflag) {
|
|
if (force->newton_bond) eval<1,1,1>(ifrom, ito, thr);
|
|
else eval<1,1,0>(ifrom, ito, thr);
|
|
} else {
|
|
if (force->newton_bond) eval<1,0,1>(ifrom, ito, thr);
|
|
else eval<1,0,0>(ifrom, ito, thr);
|
|
}
|
|
} else {
|
|
if (force->newton_bond) eval<0,0,1>(ifrom, ito, thr);
|
|
else eval<0,0,0>(ifrom, ito, thr);
|
|
}
|
|
|
|
reduce_thr(this, eflag, vflag, thr);
|
|
} // end of omp parallel region
|
|
}
|
|
|
|
template <int EVFLAG, int EFLAG, int NEWTON_BOND>
|
|
void DihedralCosineShiftExpOMP::eval(int nfrom, int nto, ThrData * const thr)
|
|
{
|
|
|
|
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 ax,ay,az,bx,by,bz,rasq,rbsq,rgsq,rg,rginv,ra2inv,rb2inv,rabinv;
|
|
double df,fg,hg,fga,hgb,gaa,gbb;
|
|
double dtfx,dtfy,dtfz,dtgx,dtgy,dtgz,dthx,dthy,dthz;
|
|
double c,s,sx2,sy2,sz2;
|
|
double cccpsss,cssmscc,exp2;
|
|
|
|
edihedral = 0.0;
|
|
|
|
const double * const * const x = atom->x;
|
|
double * const * const f = thr->get_f();
|
|
const int * const * const dihedrallist = neighbor->dihedrallist;
|
|
const int nlocal = atom->nlocal;
|
|
|
|
for (n = nfrom; n < nto; n++) {
|
|
i1 = dihedrallist[n][0];
|
|
i2 = dihedrallist[n][1];
|
|
i3 = dihedrallist[n][2];
|
|
i4 = dihedrallist[n][3];
|
|
type = dihedrallist[n][4];
|
|
|
|
// 1st bond
|
|
|
|
vb1x = x[i1][0] - x[i2][0];
|
|
vb1y = x[i1][1] - x[i2][1];
|
|
vb1z = x[i1][2] - x[i2][2];
|
|
|
|
// 2nd bond
|
|
|
|
vb2x = x[i3][0] - x[i2][0];
|
|
vb2y = x[i3][1] - x[i2][1];
|
|
vb2z = x[i3][2] - x[i2][2];
|
|
|
|
vb2xm = -vb2x;
|
|
vb2ym = -vb2y;
|
|
vb2zm = -vb2z;
|
|
|
|
// 3rd bond
|
|
|
|
vb3x = x[i4][0] - x[i3][0];
|
|
vb3y = x[i4][1] - x[i3][1];
|
|
vb3z = x[i4][2] - x[i3][2];
|
|
|
|
// c,s calculation
|
|
|
|
ax = vb1y*vb2zm - vb1z*vb2ym;
|
|
ay = vb1z*vb2xm - vb1x*vb2zm;
|
|
az = vb1x*vb2ym - vb1y*vb2xm;
|
|
bx = vb3y*vb2zm - vb3z*vb2ym;
|
|
by = vb3z*vb2xm - vb3x*vb2zm;
|
|
bz = vb3x*vb2ym - vb3y*vb2xm;
|
|
|
|
rasq = ax*ax + ay*ay + az*az;
|
|
rbsq = bx*bx + by*by + bz*bz;
|
|
rgsq = vb2xm*vb2xm + vb2ym*vb2ym + vb2zm*vb2zm;
|
|
rg = sqrt(rgsq);
|
|
|
|
rginv = ra2inv = rb2inv = 0.0;
|
|
if (rg > 0) rginv = 1.0/rg;
|
|
if (rasq > 0) ra2inv = 1.0/rasq;
|
|
if (rbsq > 0) rb2inv = 1.0/rbsq;
|
|
rabinv = sqrt(ra2inv*rb2inv);
|
|
|
|
c = (ax*bx + ay*by + az*bz)*rabinv;
|
|
s = rg*rabinv*(ax*vb3x + ay*vb3y + az*vb3z);
|
|
|
|
// error check
|
|
|
|
if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) {
|
|
int me = comm->me;
|
|
|
|
if (screen) {
|
|
char str[128];
|
|
sprintf(str,"Dihedral problem: %d/%d " BIGINT_FORMAT " %d %d %d %d",
|
|
me,thr->get_tid(),update->ntimestep,
|
|
atom->tag[i1],atom->tag[i2],atom->tag[i3],atom->tag[i4]);
|
|
error->warning(FLERR,str,0);
|
|
fprintf(screen," 1st atom: %d %g %g %g\n",
|
|
me,x[i1][0],x[i1][1],x[i1][2]);
|
|
fprintf(screen," 2nd atom: %d %g %g %g\n",
|
|
me,x[i2][0],x[i2][1],x[i2][2]);
|
|
fprintf(screen," 3rd atom: %d %g %g %g\n",
|
|
me,x[i3][0],x[i3][1],x[i3][2]);
|
|
fprintf(screen," 4th atom: %d %g %g %g\n",
|
|
me,x[i4][0],x[i4][1],x[i4][2]);
|
|
}
|
|
}
|
|
|
|
if (c > 1.0) c = 1.0;
|
|
if (c < -1.0) c = -1.0;
|
|
|
|
double aa=a[type];
|
|
double uumin=umin[type];
|
|
|
|
cccpsss = c*cost[type]+s*sint[type];
|
|
cssmscc = c*sint[type]-s*cost[type];
|
|
|
|
if (doExpansion[type]) {
|
|
// |a|<0.001 so use expansions relative precision <1e-5
|
|
if (EFLAG) edihedral = -0.125*(1+cccpsss)*(4+aa*(cccpsss-1))*uumin;
|
|
df=0.5*uumin*( cssmscc + 0.5*aa*cccpsss);
|
|
} else {
|
|
exp2=exp(0.5*aa*(1+cccpsss));
|
|
if (EFLAG) edihedral = opt1[type]*(1-exp2);
|
|
df= 0.5*opt1[type]*aa* ( exp2*cssmscc );
|
|
}
|
|
|
|
fg = vb1x*vb2xm + vb1y*vb2ym + vb1z*vb2zm;
|
|
hg = vb3x*vb2xm + vb3y*vb2ym + vb3z*vb2zm;
|
|
fga = fg*ra2inv*rginv;
|
|
hgb = hg*rb2inv*rginv;
|
|
gaa = -ra2inv*rg;
|
|
gbb = rb2inv*rg;
|
|
|
|
dtfx = gaa*ax;
|
|
dtfy = gaa*ay;
|
|
dtfz = gaa*az;
|
|
dtgx = fga*ax - hgb*bx;
|
|
dtgy = fga*ay - hgb*by;
|
|
dtgz = fga*az - hgb*bz;
|
|
dthx = gbb*bx;
|
|
dthy = gbb*by;
|
|
dthz = gbb*bz;
|
|
|
|
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] += f1[0];
|
|
f[i1][1] += f1[1];
|
|
f[i1][2] += f1[2];
|
|
}
|
|
|
|
if (NEWTON_BOND || i2 < nlocal) {
|
|
f[i2][0] += f2[0];
|
|
f[i2][1] += f2[1];
|
|
f[i2][2] += f2[2];
|
|
}
|
|
|
|
if (NEWTON_BOND || i3 < nlocal) {
|
|
f[i3][0] += f3[0];
|
|
f[i3][1] += f3[1];
|
|
f[i3][2] += f3[2];
|
|
}
|
|
|
|
if (NEWTON_BOND || i4 < nlocal) {
|
|
f[i4][0] += f4[0];
|
|
f[i4][1] += f4[1];
|
|
f[i4][2] += f4[2];
|
|
}
|
|
|
|
if (EVFLAG)
|
|
ev_tally_thr(this,i1,i2,i3,i4,nlocal,NEWTON_BOND,edihedral,f1,f3,f4,
|
|
vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z,thr);
|
|
}
|
|
}
|