diff --git a/doc/src/Commands_bond.rst b/doc/src/Commands_bond.rst index a295d8e2c1..0c389df399 100644 --- a/doc/src/Commands_bond.rst +++ b/doc/src/Commands_bond.rst @@ -89,7 +89,7 @@ OPT. * :doc:`cosine/shift (o) ` * :doc:`cosine/shift/exp (o) ` * :doc:`cosine/squared (o) ` - * :doc:`cosine/squared/restricted ` + * :doc:`cosine/squared/restricted (o) ` * :doc:`cross ` * :doc:`dipole (o) ` * :doc:`fourier (o) ` diff --git a/doc/src/angle_cosine_squared_restricted.rst b/doc/src/angle_cosine_squared_restricted.rst index 63f323b806..5417a3b050 100644 --- a/doc/src/angle_cosine_squared_restricted.rst +++ b/doc/src/angle_cosine_squared_restricted.rst @@ -1,8 +1,11 @@ .. index:: angle_style cosine/squared/restricted +.. index:: angle_style cosine/squared/restricted/omp angle_style cosine/squared/restricted command ============================================= +Accelerator Variants: *cosine/squared/restricted/omp* + Syntax """""" @@ -46,6 +49,10 @@ internally. ---------- +.. include:: accel_styles.rst + +---------- + Restrictions """""""""""" diff --git a/src/EXTRA-MOLECULE/angle_cosine_squared_restricted.cpp b/src/EXTRA-MOLECULE/angle_cosine_squared_restricted.cpp index f3844ec3a0..2da31ef893 100644 --- a/src/EXTRA-MOLECULE/angle_cosine_squared_restricted.cpp +++ b/src/EXTRA-MOLECULE/angle_cosine_squared_restricted.cpp @@ -55,8 +55,7 @@ void AngleCosineSquaredRestricted::compute(int eflag, int vflag) 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; + double tk, rsq1, rsq2, r1, r2, c, a, a11, a12, a22; eangle = 0.0; ev_init(eflag, vflag); @@ -265,7 +264,8 @@ double AngleCosineSquaredRestricted::single(int type, int i1, int i2, int i3) /* ---------------------------------------------------------------------- */ -void AngleCosineSquaredRestricted::born_matrix(int type, int i1, int i2, int i3, double &du, double &du2) +void AngleCosineSquaredRestricted::born_matrix(int type, int i1, int i2, int i3, double &du, + double &du2) { double **x = atom->x; @@ -291,7 +291,7 @@ void AngleCosineSquaredRestricted::born_matrix(int type, int i1, int i2, int i3, du = 2 * k[type] * (c - c0) * (1.0 - c * c0) / (sq_sin * sq_sin); - double numerator = 2.0 * c0 * c * c * c - 3.0 * (c0 * c0 + 1) * c * c + 6 * c0 * c - c0 * c0 - 1 ; + double numerator = 2.0 * c0 * c * c * c - 3.0 * (c0 * c0 + 1) * c * c + 6 * c0 * c - c0 * c0 - 1; double denominator = sq_sin * sq_sin * sq_sin; du2 = 2 * k[type] * numerator / denominator; diff --git a/src/OPENMP/angle_cosine_squared_restricted_omp.cpp b/src/OPENMP/angle_cosine_squared_restricted_omp.cpp new file mode 100644 index 0000000000..80960653b4 --- /dev/null +++ b/src/OPENMP/angle_cosine_squared_restricted_omp.cpp @@ -0,0 +1,170 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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 "angle_cosine_squared_restricted_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; + +/* ---------------------------------------------------------------------- */ + +AngleCosineSquaredRestrictedOMP::AngleCosineSquaredRestrictedOMP(class LAMMPS *lmp) + : AngleCosineSquaredRestricted(lmp), ThrOMP(lmp,THR_ANGLE) +{ + suffix_flag |= Suffix::OMP; +} + +/* ---------------------------------------------------------------------- */ + +void AngleCosineSquaredRestrictedOMP::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->nanglelist; + +#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 AngleCosineSquaredRestrictedOMP::eval(int nfrom, int nto, ThrData * const thr) +{ + int i1,i2,i3,n,type; + double delx1,dely1,delz1,delx2,dely2,delz2; + double eangle,f1[3],f3[3]; + double tk,rsq1,rsq2,r1,r2,c,a,a11,a12,a22; + + const auto * _noalias const x = (dbl3_t *) atom->x[0]; + auto * _noalias const f = (dbl3_t *) thr->get_f()[0]; + const int4_t * _noalias const anglelist = (int4_t *) neighbor->anglelist[0]; + const int nlocal = atom->nlocal; + eangle = 0.0; + + for (n = nfrom; n < nto; n++) { + i1 = anglelist[n].a; + i2 = anglelist[n].b; + i3 = anglelist[n].c; + type = anglelist[n].t; + + // 1st bond + + delx1 = x[i1].x - x[i2].x; + dely1 = x[i1].y - x[i2].y; + delz1 = x[i1].z - x[i2].z; + + rsq1 = delx1*delx1 + dely1*dely1 + delz1*delz1; + r1 = sqrt(rsq1); + + // 2nd bond + + delx2 = x[i3].x - x[i2].x; + dely2 = x[i3].y - x[i2].y; + delz2 = x[i3].z - x[i2].z; + + rsq2 = delx2*delx2 + dely2*dely2 + delz2*delz2; + r2 = sqrt(rsq2); + + // angle (cos and sin) + + c = delx1*delx2 + dely1*dely2 + delz1*delz2; + c /= r1*r2; + + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + + // force & energy + + double sq_sin = 1.0 - c * c; + double c0 = cos(theta0[type]); + + tk = k[type] * (c - c0) * (1.0 - c * c0) / (sq_sin * sq_sin); + + if (EFLAG) eangle = k[type] * (c - c0) * (c - c0) / sq_sin; + + a = 2.0 * tk; + a11 = a*c / rsq1; + a12 = -a / (r1*r2); + a22 = a*c / rsq2; + + 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].x += f1[0]; + f[i1].y += f1[1]; + f[i1].z += f1[2]; + } + + if (NEWTON_BOND || i2 < nlocal) { + f[i2].x -= f1[0] + f3[0]; + f[i2].y -= f1[1] + f3[1]; + f[i2].z -= f1[2] + f3[2]; + } + + if (NEWTON_BOND || i3 < nlocal) { + f[i3].x += f3[0]; + f[i3].y += f3[1]; + f[i3].z += f3[2]; + } + + if (EVFLAG) ev_tally_thr(this,i1,i2,i3,nlocal,NEWTON_BOND,eangle,f1,f3, + delx1,dely1,delz1,delx2,dely2,delz2,thr); + } +} diff --git a/src/OPENMP/angle_cosine_squared_restricted_omp.h b/src/OPENMP/angle_cosine_squared_restricted_omp.h new file mode 100644 index 0000000000..b2ad545230 --- /dev/null +++ b/src/OPENMP/angle_cosine_squared_restricted_omp.h @@ -0,0 +1,46 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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) +------------------------------------------------------------------------- */ + +#ifdef ANGLE_CLASS +// clang-format off +AngleStyle(cosine/squared/restricted/omp,AngleCosineSquaredRestrictedOMP); +// clang-format on +#else + +#ifndef LMP_ANGLE_COSINE_SQUARED_RESTRICTED_OMP_H +#define LMP_ANGLE_COSINE_SQUARED_RESTRICTED_OMP_H + +#include "angle_cosine_squared_restricted.h" +#include "thr_omp.h" + +namespace LAMMPS_NS { + +class AngleCosineSquaredRestrictedOMP : public AngleCosineSquaredRestricted, public ThrOMP { + + public: + AngleCosineSquaredRestrictedOMP(class LAMMPS *lmp); + void compute(int, int) override; + + private: + template + void eval(int ifrom, int ito, ThrData *const thr); +}; + +} // namespace LAMMPS_NS + +#endif +#endif