// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, 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 "dihedral_fourier_omp.h" #include "atom.h" #include "comm.h" #include "force.h" #include "neighbor.h" #include #include "omp_compat.h" #include "suffix.h" using namespace LAMMPS_NS; #define TOLERANCE 0.05 /* ---------------------------------------------------------------------- */ DihedralFourierOMP::DihedralFourierOMP(class LAMMPS *lmp) : DihedralFourier(lmp), ThrOMP(lmp,THR_DIHEDRAL) { suffix_flag |= Suffix::OMP; } /* ---------------------------------------------------------------------- */ void DihedralFourierOMP::compute(int eflag, int vflag) { ev_init(eflag,vflag); const int nall = atom->nlocal + atom->nghost; const int nthreads = comm->nthreads; const int inum = neighbor->ndihedrallist; #if defined(_OPENMP) #pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(eflag,vflag) #endif { int ifrom, ito, tid; loop_setup_thr(ifrom, ito, tid, inum, nthreads); ThrData *thr = fix->get_thr(tid); thr->timer(Timer::START); ev_setup_thr(eflag, vflag, nall, eatom, vatom, cvatom, thr); if (inum > 0) { 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); } } thr->timer(Timer::BOND); reduce_thr(this, eflag, vflag, thr); } // end of omp parallel region } template void DihedralFourierOMP::eval(int nfrom, int nto, ThrData * const thr) { int i1,i2,i3,i4,i,j,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_,sx2,sy2,sz2; edihedral = 0.0; const auto * _noalias const x = (dbl3_t *) atom->x[0]; auto * _noalias const f = (dbl3_t *) thr->get_f()[0]; const int5_t * _noalias const dihedrallist = (int5_t *) neighbor->dihedrallist[0]; const int nlocal = atom->nlocal; for (n = nfrom; n < nto; n++) { i1 = dihedrallist[n].a; i2 = dihedrallist[n].b; i3 = dihedrallist[n].c; i4 = dihedrallist[n].d; type = dihedrallist[n].t; // 1st bond vb1x = x[i1].x - x[i2].x; vb1y = x[i1].y - x[i2].y; vb1z = x[i1].z - x[i2].z; // 2nd bond vb2x = x[i3].x - x[i2].x; vb2y = x[i3].y - x[i2].y; vb2z = x[i3].z - x[i2].z; vb2xm = -vb2x; vb2ym = -vb2y; vb2zm = -vb2z; // 3rd bond vb3x = x[i4].x - x[i3].x; vb3y = x[i4].y - x[i3].y; vb3z = x[i4].z - x[i3].z; 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)) problem(FLERR, i1, i2, i3, i4); if (c > 1.0) c = 1.0; if (c < -1.0) c = -1.0; // force and energy // p = sum(i=1,nterms) k_i*(1+cos(n_i*phi-d_i) // dp = dp / dphi edihedral = 0.0; df = 0.0; for (j=0; j