diff --git a/doc/src/pair_sw.rst b/doc/src/pair_sw.rst index 7d795e0430..b8f7597d1c 100644 --- a/doc/src/pair_sw.rst +++ b/doc/src/pair_sw.rst @@ -3,26 +3,22 @@ .. index:: pair_style sw/intel .. index:: pair_style sw/kk .. index:: pair_style sw/omp +.. index:: pair_style sw/mod +.. index:: pair_style sw/mod/omp pair_style sw command ===================== -Accelerator Variants: *sw/gpu*, *sw/intel*, *sw/kk*, *sw/omp* +Accelerator Variants: *sw/gpu*, *sw/intel*, *sw/kk*, *sw/omp*, *sw/mod/omp* Syntax """""" .. code-block:: LAMMPS - pair_style style keywords values + pair_style style -* style = *sw* or *sw/gpu* or *sw/omp* -* keyword = *modify* - - .. parsed-literal:: - - *modify* value = flag - flag = 0/1 to turn off/on the modification +* style = *sw* or *sw/mod* Examples """""""" @@ -33,8 +29,8 @@ Examples pair_coeff * * si.sw Si pair_coeff * * GaN.sw Ga N Ga - pair_style sw modify 1 - pair_coeff * * tmd.sw Mo S S + pair_style sw/mod + pair_coeff * * tmd.sw.mod Mo S S Description """"""""""" @@ -168,7 +164,7 @@ used for anything and can be set to 0.0 if desired. This is also true for the parameters in :math:`\phi_3` that are taken from the ij and ik pairs (:math:`\sigma`, *a*, :math:`\gamma`) -The *modify* keyword computes the energy E of a system of atoms, whose +The *sw/mod* style computes the energy E of a system of atoms, whose formula is the same as the Stillinger-Weber potential. The only modification is in the three-body term, where :math:`\delta = \cos \theta_{ijk} - \cos \theta_{0ijk}` is modified with the following function: @@ -183,7 +179,7 @@ is modified with the following function: \end{array} \right. \\ -The *modify* keyword is designed for simulations of materials when +The *sw/mod* style is designed for simulations of materials when distinguishing three-body angles are necessary, such as borophene and transition metal dichalcogenide, which cannot be described by the original code for the Stillinger-Weber potential. Validation, @@ -192,28 +188,14 @@ benchmark tests, and applications of the *modify* keyword can be found in ---------- -Styles with a *gpu*, *intel*, *kk*, *omp*, or *opt* suffix are -functionally the same as the corresponding style without the suffix. -They have been optimized to run faster, depending on your available -hardware, as discussed on the :doc:`Speed packages ` doc -page. The accelerated styles take the same arguments and should -produce the same results, except for round-off and precision issues. +.. include:: accel_styles.rst -These accelerated styles are part of the GPU, INTEL, KOKKOS, -OPENMP and OPT packages, respectively. They are only enabled if -LAMMPS was built with those packages. See the :doc:`Build package ` page for more info. +.. note:: -You can specify the accelerated styles explicitly in your input script -by including their suffix, or you can use the :doc:`-suffix command-line switch ` when you invoke LAMMPS, or you can use the -:doc:`suffix ` command in your input script. - -When using the INTEL package with this style, there is an -additional 5 to 10 percent performance improvement when the -Stillinger-Weber parameters p and q are set to 4 and 0 respectively. -These parameters are common for modeling silicon and water. - -See the :doc:`Speed packages ` page for more -instructions on how to use the accelerated styles effectively. + When using the INTEL package with this style, there is an additional + 5 to 10 percent performance improvement when the Stillinger-Weber + parameters p and q are set to 4 and 0 respectively. These + parameters are common for modeling silicon and water. ---------- diff --git a/doc/src/pair_sw_mod.rst b/doc/src/pair_sw_mod.rst deleted file mode 100644 index e2163a8ea4..0000000000 --- a/doc/src/pair_sw_mod.rst +++ /dev/null @@ -1,103 +0,0 @@ -.. index:: pair_style sw/mod - -pair_style sw/mod command -===================== - -Syntax -"""""" - -.. code-block:: LAMMPS - - pair_style sw/mod - -Examples -"""""""" - -.. code-block:: LAMMPS - - pair_style sw/mod - pair_coeff * * tmd.sw.mod Mo S S - -Description -""""""""""" - -The *sw/mod* style computes the energy E of a system of atoms, whose -formula is the same as the Stillinger-Weber potential :doc:`pair_style sw `. -The only modification is in the three-body term, where -:math:`\delta = \cos \theta_{ijk} - \cos \theta_{0ijk}` -is modified with the following function: - -.. math:: - - g_C(\delta) & = \left\{ \begin{array} {r@{\quad:\quad}l} - 1 & \delta < \delta_1 \\ - \frac{1}{2} + \frac{1}{2} \cos \left( \pi \frac{\delta-\delta_1}{\delta_2 - \delta_1} \right) & - \delta_1 < \delta < \delta_2 \\ - 0 & \delta > \delta_2 - \end{array} \right. \\ - - -This potential is designed for simulations of materials when -distinguishing three-body angles are necessary, such as borophene -and transition metal dichalcogenide, which cannot be described -by the original code for the Stillinger-Weber potential. Validation, -benchmark tests, and applications of the *modify* keyword can be found in -:ref:`(Jiang_1) ` and :ref:`(Jiang_2) `. - ----------- - -Mixing, shift, table, tail correction, restart, rRESPA info -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -For atom type pairs I,J and I != J, where types I and J correspond to -two different element types, mixing is performed by LAMMPS as -described above from values in the potential file. - -This pair style does not support the :doc:`pair_modify ` -shift, table, and tail options. - -This pair style does not write its information to :doc:`binary restart files `, since it is stored in potential files. Thus, you -need to re-specify the pair_style and pair_coeff commands in an input -script that reads a restart file. - -This pair style can only be used via the *pair* keyword of the -:doc:`run_style respa ` command. It does not support the -*inner*, *middle*, *outer* keywords. - ----------- - -Restrictions -"""""""""""" - -This pair style is part of the MANYBODY package. It is only enabled -if LAMMPS was built with that package. See the :doc:`Build package ` page for more info. - -This pair style requires the :doc:`newton ` setting to be "on" -for pair interactions. - -The Stillinger-Weber potential files provided with LAMMPS (see the -potentials directory) are parameterized for metal :doc:`units `. -You can use the SW potential with any LAMMPS units, but you would need -to create your own SW potential file with coefficients listed in the -appropriate units if your simulation does not use "metal" units. - -Related commands -"""""""""""""""" -:doc:`pair_coeff ` - -:doc:`pair_style sw ` - -Default -""""""" - -none - ----------- - -.. _Jiang1: - -**(Jiang_1)** J.-W. Jiang, Nanotechnology 26, 315706 (2015). - -.. _Jiang2: - -**(Jiang_2)** J.-W. Jiang, Acta Mech. Solida. Sin 32, 17 (2019). diff --git a/examples/sw/in.mos2 b/examples/sw/in.mos2.sw.mod similarity index 100% rename from examples/sw/in.mos2 rename to examples/sw/in.mos2.sw.mod diff --git a/examples/sw/in.mos2.sw.mod.omp b/examples/sw/in.mos2.sw.mod.omp new file mode 100644 index 0000000000..c7636117f9 --- /dev/null +++ b/examples/sw/in.mos2.sw.mod.omp @@ -0,0 +1,30 @@ +# monolayer MoS2 +units metal +boundary p p f +processors * * 1 + +atom_style full +read_data single_layer_MoS2.data + +mass * 32.065 # mass of sulphur atom , uint: a.u.=1.66X10^(-27)kg +mass 1 95.94 # mass of molebdenum atom , uint: a.u.=1.66X10^(-27)kg + +########################## Define potentials ################################ +pair_style sw/mod/omp +pair_coeff * * tmd.sw.mod Mo S S +######################################################################### + +### Simulation settings #### +timestep 0.001 +velocity all create 300.0 12345 + +############################ + +# Output +thermo 500 +thermo_style custom step etotal pe ke temp +thermo_modify lost warn + +###### Run molecular dynamics ###### +fix thermostat all nve +run 5000 diff --git a/examples/sw/log.27Oct21.mos2_sw_mod.g++.4 b/examples/sw/log.27Oct21.mos2_sw_mod.g++.4 new file mode 100644 index 0000000000..ee9895bfc5 --- /dev/null +++ b/examples/sw/log.27Oct21.mos2_sw_mod.g++.4 @@ -0,0 +1,104 @@ +LAMMPS (27 Oct 2021) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (../comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +# monolayer MoS2 +units metal +boundary p p f +processors * * 1 + +atom_style full +read_data single_layer_MoS2.data +Reading data file ... + triclinic box = (0.0000000 0.0000000 -100.00000) to (51.152320 44.299209 100.00000) with tilt (25.576160 0.0000000 0.0000000) + 2 by 2 by 1 MPI processor grid + reading atoms ... + 768 atoms +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0 0 0 + special bond factors coul: 0 0 0 + 0 = max # of 1-2 neighbors + 0 = max # of 1-3 neighbors + 0 = max # of 1-4 neighbors + 1 = max # of special neighbors + special bonds CPU = 0.000 seconds + read_data CPU = 0.005 seconds + +mass * 32.065 # mass of sulphur atom , uint: a.u.=1.66X10^(-27)kg +mass 1 95.94 # mass of molebdenum atom , uint: a.u.=1.66X10^(-27)kg + +########################## Define potentials ################################ +pair_style sw/mod +pair_coeff * * tmd.sw.mod Mo S S +Reading sw potential file tmd.sw.mod with DATE: 2018-03-26 +######################################################################### + +### Simulation settings #### +timestep 0.001 +velocity all create 300.0 12345 + +############################ + +# Output +thermo 500 +thermo_style custom step etotal pe ke temp +thermo_modify lost warn + +###### Run molecular dynamics ###### +fix thermostat all nve +run 5000 +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 5.158796 + ghost atom cutoff = 5.158796 + binsize = 2.579398, bins = 30 18 78 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair sw/mod, perpetual + attributes: full, newton on + pair build: full/bin + stencil: full/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 6.360 | 6.360 | 6.360 Mbytes +Step TotEng PotEng KinEng Temp + 0 -899.28605 -929.02881 29.742759 300 + 500 -899.28626 -922.45519 23.168929 233.69313 + 1000 -899.29247 -925.86547 26.573002 268.02828 + 1500 -899.27957 -916.95478 17.675214 178.28084 + 2000 -899.28171 -918.38728 19.105573 192.70814 + 2500 -899.28732 -922.50423 23.21691 234.17709 + 3000 -899.28195 -918.74112 19.459174 196.27473 + 3500 -899.27944 -918.03105 18.751604 189.13784 + 4000 -899.28397 -920.50737 21.223397 214.06955 + 4500 -899.28386 -919.79154 20.507685 206.85053 + 5000 -899.28077 -918.78947 19.508698 196.77425 +Loop time of 0.741432 on 4 procs for 5000 steps with 768 atoms + +Performance: 582.656 ns/day, 0.041 hours/ns, 6743.708 timesteps/s +99.8% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0.64552 | 0.65764 | 0.66951 | 1.4 | 88.70 +Bond | 0.00027894 | 0.00029732 | 0.00031402 | 0.0 | 0.04 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.054789 | 0.066165 | 0.078466 | 4.3 | 8.92 +Output | 0.00010959 | 0.00011859 | 0.00013564 | 0.0 | 0.02 +Modify | 0.0083096 | 0.0085094 | 0.0087577 | 0.2 | 1.15 +Other | | 0.008697 | | | 1.17 + +Nlocal: 192.000 ave 194 max 190 min +Histogram: 1 0 0 0 0 2 0 0 0 1 +Nghost: 194.000 ave 196 max 192 min +Histogram: 1 0 0 0 0 2 0 0 0 1 +Neighs: 0.00000 ave 0 max 0 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +FullNghs: 5120.00 ave 5170 max 5070 min +Histogram: 1 0 0 0 0 2 0 0 0 1 + +Total # of neighbors = 20480 +Ave neighs/atom = 26.666667 +Ave special neighs/atom = 0.0000000 +Neighbor list builds = 0 +Dangerous builds = 0 +Total wall time: 0:00:00 diff --git a/examples/sw/log.27Oct21.mos2_sw_mod_omp.g++.1 b/examples/sw/log.27Oct21.mos2_sw_mod_omp.g++.1 new file mode 100644 index 0000000000..f2fbe18b35 --- /dev/null +++ b/examples/sw/log.27Oct21.mos2_sw_mod_omp.g++.1 @@ -0,0 +1,107 @@ +LAMMPS (27 Oct 2021) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (../comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +package omp 0 +using multi-threaded neighbor list subroutines +# monolayer MoS2 +units metal +boundary p p f +processors * * 1 + +atom_style full +read_data single_layer_MoS2.data +Reading data file ... + triclinic box = (0.0000000 0.0000000 -100.00000) to (51.152320 44.299209 100.00000) with tilt (25.576160 0.0000000 0.0000000) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 768 atoms +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0 0 0 + special bond factors coul: 0 0 0 + 0 = max # of 1-2 neighbors + 0 = max # of 1-3 neighbors + 0 = max # of 1-4 neighbors + 1 = max # of special neighbors + special bonds CPU = 0.001 seconds + read_data CPU = 0.005 seconds + +mass * 32.065 # mass of sulphur atom , uint: a.u.=1.66X10^(-27)kg +mass 1 95.94 # mass of molebdenum atom , uint: a.u.=1.66X10^(-27)kg + +########################## Define potentials ################################ +pair_style sw/mod/omp +pair_coeff * * tmd.sw.mod Mo S S +Reading sw potential file tmd.sw.mod with DATE: 2018-03-26 +######################################################################### + +### Simulation settings #### +timestep 0.001 +velocity all create 300.0 12345 + +############################ + +# Output +thermo 500 +thermo_style custom step etotal pe ke temp +thermo_modify lost warn + +###### Run molecular dynamics ###### +fix thermostat all nve +run 5000 +Last active /omp style is pair_style sw/mod/omp +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 5.158796 + ghost atom cutoff = 5.158796 + binsize = 2.579398, bins = 30 18 78 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair sw/mod/omp, perpetual + attributes: full, newton on, omp + pair build: full/bin/omp + stencil: full/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 6.539 | 6.539 | 6.539 Mbytes +Step TotEng PotEng KinEng Temp + 0 -899.28605 -929.02881 29.742759 300 + 500 -899.28626 -922.45519 23.168929 233.69313 + 1000 -899.29247 -925.86547 26.573002 268.02828 + 1500 -899.27957 -916.95478 17.675214 178.28084 + 2000 -899.28171 -918.38728 19.105573 192.70814 + 2500 -899.28732 -922.50423 23.21691 234.17709 + 3000 -899.28195 -918.74112 19.459174 196.27473 + 3500 -899.27944 -918.03105 18.751604 189.13784 + 4000 -899.28397 -920.50737 21.223397 214.06955 + 4500 -899.28386 -919.79154 20.507685 206.85053 + 5000 -899.28077 -918.78947 19.508698 196.77425 +Loop time of 2.43893 on 1 procs for 5000 steps with 768 atoms + +Performance: 177.127 ns/day, 0.135 hours/ns, 2050.080 timesteps/s +99.7% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 2.3796 | 2.3796 | 2.3796 | 0.0 | 97.57 +Bond | 0.00021636 | 0.00021636 | 0.00021636 | 0.0 | 0.01 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.0090182 | 0.0090182 | 0.0090182 | 0.0 | 0.37 +Output | 0.00020341 | 0.00020341 | 0.00020341 | 0.0 | 0.01 +Modify | 0.040174 | 0.040174 | 0.040174 | 0.0 | 1.65 +Other | | 0.009731 | | | 0.40 + +Nlocal: 768.000 ave 768 max 768 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 354.000 ave 354 max 354 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 0.00000 ave 0 max 0 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 20480.0 ave 20480 max 20480 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 20480 +Ave neighs/atom = 26.666667 +Ave special neighs/atom = 0.0000000 +Neighbor list builds = 0 +Dangerous builds = 0 +Total wall time: 0:00:02 diff --git a/examples/sw/log.27Oct21.mos2_sw_mod_omp.g++.4 b/examples/sw/log.27Oct21.mos2_sw_mod_omp.g++.4 new file mode 100644 index 0000000000..375bb0a367 --- /dev/null +++ b/examples/sw/log.27Oct21.mos2_sw_mod_omp.g++.4 @@ -0,0 +1,107 @@ +LAMMPS (27 Oct 2021) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (../comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +package omp 0 +using multi-threaded neighbor list subroutines +# monolayer MoS2 +units metal +boundary p p f +processors * * 1 + +atom_style full +read_data single_layer_MoS2.data +Reading data file ... + triclinic box = (0.0000000 0.0000000 -100.00000) to (51.152320 44.299209 100.00000) with tilt (25.576160 0.0000000 0.0000000) + 2 by 2 by 1 MPI processor grid + reading atoms ... + 768 atoms +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0 0 0 + special bond factors coul: 0 0 0 + 0 = max # of 1-2 neighbors + 0 = max # of 1-3 neighbors + 0 = max # of 1-4 neighbors + 1 = max # of special neighbors + special bonds CPU = 0.000 seconds + read_data CPU = 0.005 seconds + +mass * 32.065 # mass of sulphur atom , uint: a.u.=1.66X10^(-27)kg +mass 1 95.94 # mass of molebdenum atom , uint: a.u.=1.66X10^(-27)kg + +########################## Define potentials ################################ +pair_style sw/mod/omp +pair_coeff * * tmd.sw.mod Mo S S +Reading sw potential file tmd.sw.mod with DATE: 2018-03-26 +######################################################################### + +### Simulation settings #### +timestep 0.001 +velocity all create 300.0 12345 + +############################ + +# Output +thermo 500 +thermo_style custom step etotal pe ke temp +thermo_modify lost warn + +###### Run molecular dynamics ###### +fix thermostat all nve +run 5000 +Last active /omp style is pair_style sw/mod/omp +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 5.158796 + ghost atom cutoff = 5.158796 + binsize = 2.579398, bins = 30 18 78 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair sw/mod/omp, perpetual + attributes: full, newton on, omp + pair build: full/bin/omp + stencil: full/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 6.361 | 6.361 | 6.361 Mbytes +Step TotEng PotEng KinEng Temp + 0 -899.28605 -929.02881 29.742759 300 + 500 -899.28626 -922.45519 23.168929 233.69313 + 1000 -899.29247 -925.86547 26.573002 268.02828 + 1500 -899.27957 -916.95478 17.675214 178.28084 + 2000 -899.28171 -918.38728 19.105573 192.70814 + 2500 -899.28732 -922.50423 23.21691 234.17709 + 3000 -899.28195 -918.74112 19.459174 196.27473 + 3500 -899.27944 -918.03105 18.751604 189.13784 + 4000 -899.28397 -920.50737 21.223397 214.06955 + 4500 -899.28386 -919.79154 20.507685 206.85053 + 5000 -899.28077 -918.78947 19.508698 196.77425 +Loop time of 0.703794 on 4 procs for 5000 steps with 768 atoms + +Performance: 613.816 ns/day, 0.039 hours/ns, 7104.353 timesteps/s +99.7% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0.60288 | 0.60616 | 0.60938 | 0.3 | 86.13 +Bond | 0.00018681 | 0.00019351 | 0.00020187 | 0.0 | 0.03 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.070503 | 0.07298 | 0.077342 | 1.0 | 10.37 +Output | 0.00011523 | 0.00012677 | 0.00014986 | 0.0 | 0.02 +Modify | 0.014053 | 0.014315 | 0.014556 | 0.1 | 2.03 +Other | | 0.01002 | | | 1.42 + +Nlocal: 192.000 ave 194 max 190 min +Histogram: 1 0 0 0 0 2 0 0 0 1 +Nghost: 194.000 ave 196 max 192 min +Histogram: 1 0 0 0 0 2 0 0 0 1 +Neighs: 0.00000 ave 0 max 0 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +FullNghs: 5120.00 ave 5170 max 5070 min +Histogram: 1 0 0 0 0 2 0 0 0 1 + +Total # of neighbors = 20480 +Ave neighs/atom = 26.666667 +Ave special neighs/atom = 0.0000000 +Neighbor list builds = 0 +Dangerous builds = 0 +Total wall time: 0:00:00 diff --git a/src/MANYBODY/pair_sw.cpp b/src/MANYBODY/pair_sw.cpp index 46fd472af5..75ece1dc71 100644 --- a/src/MANYBODY/pair_sw.cpp +++ b/src/MANYBODY/pair_sw.cpp @@ -38,7 +38,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -PairSW::PairSW(LAMMPS *lmp) : Pair(lmp), variant(SW) +PairSW::PairSW(LAMMPS *lmp) : Pair(lmp) { single_enable = 0; restartinfo = 0; @@ -292,21 +292,7 @@ void PairSW::read_file(char *file) // open file on proc 0 if (comm->me == 0) { - std::string potential_name; - switch (variant) { - case SW: - potential_name = "sw"; - break; - - case SW_MOD: - potential_name = "sw/mod"; - break; - - default: - error->one(FLERR,"Unknown SW style variant {}",variant); - } - - PotentialFileReader reader(lmp, file, potential_name, unit_convert_flag); + PotentialFileReader reader(lmp, file, "sw", unit_convert_flag); char * line; // transparently convert units for supported conversions diff --git a/src/MANYBODY/pair_sw.h b/src/MANYBODY/pair_sw.h index 5b2b787e0d..4aec682989 100644 --- a/src/MANYBODY/pair_sw.h +++ b/src/MANYBODY/pair_sw.h @@ -36,8 +36,6 @@ class PairSW : public Pair { static constexpr int NPARAMS_PER_LINE = 14; - enum { SW, SW_MOD }; // for telling class variants apart in shared code - struct Param { double epsilon, sigma; double littlea, lambda, gamma, costheta; @@ -51,7 +49,6 @@ class PairSW : public Pair { }; protected: - int variant; double cutmax; // max cutoff for all elements Param *params; // parameter set for an I-J-K interaction int maxshort; // size of short neighbor list array diff --git a/src/MANYBODY/pair_sw_mod.cpp b/src/MANYBODY/pair_sw_mod.cpp index 0792c8d9b2..a564530d14 100644 --- a/src/MANYBODY/pair_sw_mod.cpp +++ b/src/MANYBODY/pair_sw_mod.cpp @@ -13,7 +13,7 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing authors: Jin-Wu Jiang (SHU) and Wengen Ouyang (WHU) + Contributing authors: Jin-Wu Jiang (Shanghai U) and Wengen Ouyang (Wuhan U) ------------------------------------------------------------------------- */ #include "pair_sw_mod.h" @@ -28,9 +28,7 @@ using namespace MathConst; /* ---------------------------------------------------------------------- */ -PairSWMOD::PairSWMOD(LAMMPS *lmp) : PairSW(lmp) { - variant = SW_MOD; -} +PairSWMOD::PairSWMOD(LAMMPS *lmp) : PairSW(lmp) {} /* ---------------------------------------------------------------------- */ diff --git a/src/MANYBODY/pair_sw_mod_omp.cpp b/src/MANYBODY/pair_sw_mod_omp.cpp new file mode 100644 index 0000000000..b0a2d2c871 --- /dev/null +++ b/src/MANYBODY/pair_sw_mod_omp.cpp @@ -0,0 +1,220 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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) + and Wengen Ouyang (Wuhan U) +------------------------------------------------------------------------- */ + +#include "pair_sw_mod_omp.h" + +#include "atom.h" +#include "comm.h" +#include "memory.h" +#include "neigh_list.h" +#include "suffix.h" + +#include "omp_compat.h" +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +PairSWMODOMP::PairSWMODOMP(LAMMPS *lmp) : + PairSWMOD(lmp), ThrOMP(lmp, THR_PAIR) +{ + suffix_flag |= Suffix::OMP; + respa_enable = 0; +} + +/* ---------------------------------------------------------------------- */ + +void PairSWMODOMP::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); + + const int nall = atom->nlocal + atom->nghost; + const int nthreads = comm->nthreads; + const int inum = list->inum; + +#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, nullptr, thr); + + if (evflag) { + if (eflag) { + eval<1,1>(ifrom, ito, thr); + } else { + eval<1,0>(ifrom, ito, thr); + } + } else eval<0,0>(ifrom, ito, thr); + + thr->timer(Timer::PAIR); + reduce_thr(this, eflag, vflag, thr); + } // end of omp parallel region +} + +template +void PairSWMODOMP::eval(int iifrom, int iito, ThrData * const thr) +{ + int i,j,k,ii,jj,kk,jnum,jnumm1,maxshort_thr; + tagint itag,jtag; + int itype,jtype,ktype,ijparam,ikparam,ijkparam; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,rsq1,rsq2; + double delr1[3],delr2[3],fj[3],fk[3]; + int *ilist,*jlist,*numneigh,**firstneigh,*neighshort_thr; + + evdwl = 0.0; + + const dbl3_t * _noalias const x = (dbl3_t *) atom->x[0]; + dbl3_t * _noalias const f = (dbl3_t *) thr->get_f()[0]; + const tagint * _noalias const tag = atom->tag; + const int * _noalias const type = atom->type; + const int nlocal = atom->nlocal; + + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + maxshort_thr = maxshort; + memory->create(neighshort_thr,maxshort_thr,"pair_thr:neighshort_thr"); + + double fxtmp,fytmp,fztmp; + + // loop over full neighbor list of my atoms + + for (ii = iifrom; ii < iito; ++ii) { + + i = ilist[ii]; + itag = tag[i]; + itype = map[type[i]]; + xtmp = x[i].x; + ytmp = x[i].y; + ztmp = x[i].z; + fxtmp = fytmp = fztmp = 0.0; + + // two-body interactions, skip half of them + + jlist = firstneigh[i]; + jnum = numneigh[i]; + int numshort = 0; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + + delx = xtmp - x[j].x; + dely = ytmp - x[j].y; + delz = ztmp - x[j].z; + rsq = delx*delx + dely*dely + delz*delz; + + jtype = map[type[j]]; + ijparam = elem3param[itype][jtype][jtype]; + if (rsq >= params[ijparam].cutsq) { + continue; + } else { + neighshort_thr[numshort++] = j; + if (numshort >= maxshort_thr) { + maxshort_thr += maxshort_thr/2; + memory->grow(neighshort_thr,maxshort_thr,"pair:neighshort_thr"); + } + } + + jtag = tag[j]; + if (itag > jtag) { + if ((itag+jtag) % 2 == 0) continue; + } else if (itag < jtag) { + if ((itag+jtag) % 2 == 1) continue; + } else { + if (x[j].z < ztmp) continue; + if (x[j].z == ztmp && x[j].y < ytmp) continue; + if (x[j].z == ztmp && x[j].y == ytmp && x[j].x < xtmp) continue; + } + + twobody(¶ms[ijparam],rsq,fpair,EFLAG,evdwl); + + fxtmp += delx*fpair; + fytmp += dely*fpair; + fztmp += delz*fpair; + f[j].x -= delx*fpair; + f[j].y -= dely*fpair; + f[j].z -= delz*fpair; + + if (EVFLAG) ev_tally_thr(this,i,j,nlocal,/* newton_pair */ 1, + evdwl,0.0,fpair,delx,dely,delz,thr); + } + + jnumm1 = numshort - 1; + + for (jj = 0; jj < jnumm1; jj++) { + j = neighshort_thr[jj]; + jtype = map[type[j]]; + ijparam = elem3param[itype][jtype][jtype]; + delr1[0] = x[j].x - xtmp; + delr1[1] = x[j].y - ytmp; + delr1[2] = x[j].z - ztmp; + rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; + + double fjxtmp,fjytmp,fjztmp; + fjxtmp = fjytmp = fjztmp = 0.0; + + for (kk = jj+1; kk < numshort; kk++) { + k = neighshort_thr[kk]; + ktype = map[type[k]]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; + + delr2[0] = x[k].x - xtmp; + delr2[1] = x[k].y - ytmp; + delr2[2] = x[k].z - ztmp; + rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; + + threebody(¶ms[ijparam],¶ms[ikparam],¶ms[ijkparam], + rsq1,rsq2,delr1,delr2,fj,fk,EFLAG,evdwl); + + fxtmp -= fj[0] + fk[0]; + fytmp -= fj[1] + fk[1]; + fztmp -= fj[2] + fk[2]; + fjxtmp += fj[0]; + fjytmp += fj[1]; + fjztmp += fj[2]; + f[k].x += fk[0]; + f[k].y += fk[1]; + f[k].z += fk[2]; + + if (EVFLAG) ev_tally3_thr(this,i,j,k,evdwl,0.0,fj,fk,delr1,delr2,thr); + } + f[j].x += fjxtmp; + f[j].y += fjytmp; + f[j].z += fjztmp; + } + f[i].x += fxtmp; + f[i].y += fytmp; + f[i].z += fztmp; + } + memory->destroy(neighshort_thr); +} + +/* ---------------------------------------------------------------------- */ + +double PairSWMODOMP::memory_usage() +{ + double bytes = memory_usage_thr(); + bytes += PairSWMOD::memory_usage(); + + return bytes; +} diff --git a/src/MANYBODY/pair_sw_mod_omp.h b/src/MANYBODY/pair_sw_mod_omp.h new file mode 100644 index 0000000000..20c433c292 --- /dev/null +++ b/src/MANYBODY/pair_sw_mod_omp.h @@ -0,0 +1,47 @@ +/* -*- c++ -*- ---------------------------------------------------------- + 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) +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS +// clang-format off +PairStyle(sw/mod/omp,PairSWMODOMP); +// clang-format on +#else + +#ifndef LMP_PAIR_SW_MOD_OMP_H +#define LMP_PAIR_SW_MOD_OMP_H + +#include "pair_sw_mod.h" +#include "thr_omp.h" + +namespace LAMMPS_NS { + +class PairSWMODOMP : public PairSWMOD, public ThrOMP { + + public: + PairSWMODOMP(class LAMMPS *); + + virtual void compute(int, int); + virtual double memory_usage(); + + private: + template void eval(int ifrom, int ito, ThrData *const thr); +}; + +} // namespace LAMMPS_NS + +#endif +#endif