From 61993d16432314055cc263779095f550c7d7a1db Mon Sep 17 00:00:00 2001 From: Leidy Lorena Alzate Vargas - 373576 Date: Wed, 22 Nov 2023 14:36:59 -0700 Subject: [PATCH 01/46] MLIAP Unified fix for multi layer models CPU only --- src/ML-IAP/mliap_unified.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/ML-IAP/mliap_unified.cpp b/src/ML-IAP/mliap_unified.cpp index de1d0bcb7d..6dcdf94c2d 100644 --- a/src/ML-IAP/mliap_unified.cpp +++ b/src/ML-IAP/mliap_unified.cpp @@ -254,10 +254,8 @@ void LAMMPS_NS::update_pair_energy(MLIAPData *data, double *eij) double e = 0.5 * eij[ii]; // must not count any contribution where i is not a local atom - if (i < nlocal) { - data->eatoms[i] += e; - e_total += e; - } + data->eatoms[i] += e; + e_total += e; } data->energy = e_total; } @@ -278,16 +276,14 @@ void LAMMPS_NS::update_pair_forces(MLIAPData *data, double *fij) int j = data->jatoms[ii]; // must not count any contribution where i is not a local atom - if (i < nlocal) { - f[i][0] += fij[ii3]; - f[i][1] += fij[ii3 + 1]; - f[i][2] += fij[ii3 + 2]; - f[j][0] -= fij[ii3]; - f[j][1] -= fij[ii3 + 1]; - f[j][2] -= fij[ii3 + 2]; + f[i][0] += fij[ii3]; + f[i][1] += fij[ii3 + 1]; + f[i][2] += fij[ii3 + 2]; + f[j][0] -= fij[ii3]; + f[j][1] -= fij[ii3 + 1]; + f[j][2] -= fij[ii3 + 2]; - if (data->vflag) data->pairmliap->v_tally(i, j, &fij[ii3], data->rij[ii]); - } + if (data->vflag) data->pairmliap->v_tally(i, j, &fij[ii3], data->rij[ii]); } } From 469358cbf4951c51472777bcd51055de9aaf2ed7 Mon Sep 17 00:00:00 2001 From: Leidy Lorena Alzate Vargas - 373576 Date: Wed, 22 Nov 2023 14:38:13 -0700 Subject: [PATCH 02/46] UPDATE KOKKOS --- src/KOKKOS/mliap_unified_kokkos.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/KOKKOS/mliap_unified_kokkos.cpp b/src/KOKKOS/mliap_unified_kokkos.cpp index 4c38e4f1d6..4a8c14d723 100644 --- a/src/KOKKOS/mliap_unified_kokkos.cpp +++ b/src/KOKKOS/mliap_unified_kokkos.cpp @@ -315,7 +315,6 @@ void LAMMPS_NS::update_pair_forces(MLIAPDataKokkosDevice *data, double *fij) int i = pair_i[ii]; int j = j_atoms[ii]; // must not count any contribution where i is not a local atom - if (i < nlocal) { Kokkos::atomic_add(&f[i*3+0], fij[ii3+0]); Kokkos::atomic_add(&f[i*3+1], fij[ii3+1]); Kokkos::atomic_add(&f[i*3+2], fij[ii3+2]); @@ -352,7 +351,6 @@ void LAMMPS_NS::update_pair_forces(MLIAPDataKokkosDevice *data, double *fij) Kokkos::atomic_add(&d_vatom(j,3), 0.5*v[3]); Kokkos::atomic_add(&d_vatom(j,4), 0.5*v[4]); Kokkos::atomic_add(&d_vatom(j,5), 0.5*v[5]); - } } } }); @@ -383,10 +381,8 @@ void LAMMPS_NS::update_atom_energy(MLIAPDataKokkosDevice *data, double *ei) Kokkos::parallel_reduce(nlocal, KOKKOS_LAMBDA(int i, double &local_sum){ double e = ei[i]; // must not count any contribution where i is not a local atom - if (i < nlocal) { - d_eatoms[i] = e; - local_sum += e; - } + d_eatoms[i] = e; + local_sum += e; },*data->energy); } From 8e3b5bf32730d43373881a9a06364a975399522c Mon Sep 17 00:00:00 2001 From: Ben Nebgen Date: Fri, 5 Jan 2024 13:05:27 -0700 Subject: [PATCH 03/46] Fixed memory bug in ML-IAP unified with atom name definitions Added explict memory allocation for type string in ML-IAP unified. Corrected bug where atom types were not properly alligned with the potential. --- src/KOKKOS/mliap_unified_couple_kokkos.pyx | 18 ++++++++++++++---- src/ML-IAP/mliap_unified_couple.pyx | 20 ++++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/KOKKOS/mliap_unified_couple_kokkos.pyx b/src/KOKKOS/mliap_unified_couple_kokkos.pyx index 97d807ac33..385a770bb3 100644 --- a/src/KOKKOS/mliap_unified_couple_kokkos.pyx +++ b/src/KOKKOS/mliap_unified_couple_kokkos.pyx @@ -13,6 +13,7 @@ from libc.stdint cimport uintptr_t cimport cython from cpython.ref cimport PyObject from libc.stdlib cimport malloc, free +from libc.string cimport memcpy cdef extern from "lammps.h" namespace "LAMMPS_NS": @@ -451,15 +452,24 @@ cdef public object mliap_unified_connect_kokkos(char *fname, MLIAPDummyModel * m cdef int nelements = len(unified.element_types) cdef char **elements = malloc(nelements * sizeof(char*)) + cdef char * c_str + cdef char * s + cdef ssize_t slen if not elements: raise MemoryError("failed to allocate memory for element names") - cdef char *elem_name for i, elem in enumerate(unified.element_types): - elem_name_bytes = elem.encode('UTF-8') - elem_name = elem_name_bytes - elements[i] = &elem_name[0] + py_str = elem.encode('UTF-8') + s = py_str + slen = len(py_str) + c_str = malloc((slen+1)*sizeof(char)) + if not c_str: + raise MemoryError("failed to allocate memory for element names") + memcpy(c_str, s, slen) + c_str[slen] = 0 + elements[i] = c_str + unified_int.descriptor.set_elements(elements, nelements) unified_int.model.nelements = nelements diff --git a/src/ML-IAP/mliap_unified_couple.pyx b/src/ML-IAP/mliap_unified_couple.pyx index 3148b96b51..6c8331d0fa 100644 --- a/src/ML-IAP/mliap_unified_couple.pyx +++ b/src/ML-IAP/mliap_unified_couple.pyx @@ -8,6 +8,7 @@ import lammps.mliap cimport cython from cpython.ref cimport PyObject from libc.stdlib cimport malloc, free +from libc.string cimport memcpy cdef extern from "lammps.h" namespace "LAMMPS_NS": @@ -387,15 +388,26 @@ cdef public object mliap_unified_connect(char *fname, MLIAPDummyModel * model, cdef int nelements = len(unified.element_types) cdef char **elements = malloc(nelements * sizeof(char*)) + cdef char * c_str + cdef char * s + cdef ssize_t slen if not elements: raise MemoryError("failed to allocate memory for element names") - cdef char *elem_name for i, elem in enumerate(unified.element_types): - elem_name_bytes = elem.encode('UTF-8') - elem_name = elem_name_bytes - elements[i] = &elem_name[0] + py_str = elem.encode('UTF-8') + + s = py_str + slen = len(py_str) + c_str = malloc((slen+1)*sizeof(char)) + if not c_str: + raise MemoryError("failed to allocate memory for element names") + memcpy(c_str, s, slen) + c_str[slen] = 0 + + elements[i] = c_str + unified_int.descriptor.set_elements(elements, nelements) unified_int.model.nelements = nelements From ec291174092595119d72d70cdab01b810ec9ea6d Mon Sep 17 00:00:00 2001 From: vladgl Date: Fri, 6 Oct 2023 19:23:15 +0300 Subject: [PATCH 04/46] Add new fix wall/flow --- src/KOKKOS/Install.sh | 2 + src/KOKKOS/fix_wall_flow_kokkos.cpp | 295 ++++++++++++++++++++++++++++ src/KOKKOS/fix_wall_flow_kokkos.h | 129 ++++++++++++ src/fix_wall_flow.cpp | 248 +++++++++++++++++++++++ src/fix_wall_flow.h | 60 ++++++ 5 files changed, 734 insertions(+) create mode 100644 src/KOKKOS/fix_wall_flow_kokkos.cpp create mode 100644 src/KOKKOS/fix_wall_flow_kokkos.h create mode 100644 src/fix_wall_flow.cpp create mode 100644 src/fix_wall_flow.h diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index 462c0cbe57..75949c35d8 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -187,6 +187,8 @@ action fix_temp_rescale_kokkos.cpp action fix_temp_rescale_kokkos.h action fix_viscous_kokkos.cpp action fix_viscous_kokkos.h +action fix_wall_flow_kokkos.cpp fix_wall_flow.cpp +action fix_wall_flow_kokkos.h fix_wall_flow.h action fix_wall_gran_kokkos.cpp fix_wall_gran.cpp action fix_wall_gran_kokkos.h fix_wall_gran.h action fix_wall_gran_old.cpp fix_wall_gran.cpp diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp new file mode 100644 index 0000000000..501a1bbd3f --- /dev/null +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -0,0 +1,295 @@ +#include "fix_wall_flow_kokkos.h" +#include "atom_kokkos.h" +#include "memory_kokkos.h" +#include "math_const.h" +#include "atom_masks.h" +#include "force.h" + +#include +//#include "comm.h +// clang-format off + +using namespace LAMMPS_NS; + +template +FixWallFlowKokkos::FixWallFlowKokkos(LAMMPS *lmp, int narg, char **arg) : + FixWallFlow(lmp, narg, arg), rand_pool(rndseed + comm->me) +{ + kokkosable = 1; + exchange_comm_device = sort_device = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | RMASS_MASK | TYPE_MASK | MASK_MASK; + datamask_modify = V_MASK; + + memory->destroy(current_segment); + current_segment = nullptr; + grow_arrays(atomKK->nmax); + + d_walls = d_walls_t("FixWallFlowKokkos::walls", walls.size()); + auto h_walls = Kokkos::create_mirror_view(d_walls); + for (int i = 0; i < walls.size(); ++i) + { + h_walls(i) = walls[i]; + } + Kokkos::deep_copy(d_walls, h_walls); +} + +template +FixWallFlowKokkos::~FixWallFlowKokkos() +{ + if (copymode) return; + memoryKK->destroy_kokkos(k_current_segment, current_segment); +} + +template +void FixWallFlowKokkos::init() +{ + atomKK->sync(execution_space, datamask_read); + k_current_segment.template sync(); + d_x = atomKK->k_x.template view(); + + copymode = 1; + Kokkos::parallel_for(Kokkos::RangePolicy(0, atom->nlocal), *this); + copymode = 0; + + k_current_segment.template modify(); +} + +template +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWallFlowInit, + const int &i) const +{ + double pos = d_x(i, flowax); + d_current_segment(i) = compute_current_segment_kk(pos); +} + +template +void FixWallFlowKokkos::end_of_step() +{ + atomKK->sync(execution_space, datamask_read); + k_current_segment.template sync(); + + d_x = atomKK->k_x.template view(); + d_v = atomKK->k_v.template view(); + d_type = atomKK->k_type.template view(); + d_mask = atomKK->k_mask.template view(); + d_mass = atomKK->k_mass.template view(); + d_rmass = atomKK->k_rmass.template view(); + + copymode = 1; + if (d_rmass.data()) { + Kokkos::parallel_for( + Kokkos::RangePolicy>(0, atom->nlocal), *this); + } else { + Kokkos::parallel_for( + Kokkos::RangePolicy>(0, atom->nlocal), *this); + } + copymode = 0; + atomKK->modified(execution_space, datamask_modify); + k_current_segment.template modify(); +} + +template +template +KOKKOS_INLINE_FUNCTION +void FixWallFlowKokkos::operator()(TagFixWallFlowEndOfStep, + const int &atom_i) const +{ + if (d_mask[atom_i] & groupbit) + { + double pos = d_x(atom_i, flowax); + int prev_segment = d_current_segment(atom_i); + d_current_segment(atom_i) = compute_current_segment_kk(pos); + if (prev_segment != d_current_segment(atom_i)) + { + generate_velocity_kk(atom_i); + } + } +} + +template +template +KOKKOS_INLINE_FUNCTION +void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const +{ + const int newton_iteration_count = 10; + double mass = get_mass(MTag(), atom_i); + const double gamma = 1.0 / std::sqrt(2.0 * kT / mass); + double delta = gamma * flowvel; + + const double edd = std::exp(-delta * delta) / MathConst::MY_PIS + delta * std::erf(delta); + const double probability_threshold = 0.5 * (1. + delta / edd); + + double direction = 1.0; + + rand_type_t rand_gen = rand_pool.get_state(); + + if (/*random->uniform()*/ rand_gen.drand() > probability_threshold) { + delta = -delta; + direction = -direction; + } + + const double xi_0 = rand_gen.drand(); //random->uniform(); + const double F_inf = edd + delta; + const double xi = xi_0 * F_inf; + const double x_0 = (std::sqrt(delta * delta + 2) - delta) * 0.5; + double x = x_0; + for (int i = 0; i < newton_iteration_count; ++i) { + x -= (std::exp(x * x) * MathConst::MY_PIS * (xi - delta * std::erfc(x)) - 1.0) / (x + delta) * + 0.5; + } + + const double nu = x + delta; + const double v = nu / gamma; + + d_v(atom_i, flowax) = v * direction; + d_v(atom_i, (flowax + 1) % 3) = /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); + d_v(atom_i, (flowax + 2) % 3) = /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); + + rand_pool.free_state(rand_gen); +} + +template +KOKKOS_INLINE_FUNCTION +int FixWallFlowKokkos::compute_current_segment_kk(double pos) const +{ + int result = 0; + for (; result < d_walls.extent(0) - 1; ++result) { + if (pos >= d_walls[result] && pos < d_walls[result + 1]) { return result; } + } + return -1; // -1 is "out of box" region +} + + +template +void FixWallFlowKokkos::grow_arrays(int nmax) +{ + k_current_segment.template sync(); + memoryKK->grow_kokkos(k_current_segment, current_segment, nmax, "WallFlowKK::current_segment"); + k_current_segment.template modify(); + + d_current_segment = k_current_segment.template view(); + h_current_segment = k_current_segment.template view(); +} + +template +void FixWallFlowKokkos::copy_arrays(int i, int j, int) +{ + k_current_segment.template sync(); + h_current_segment(j) = h_current_segment(i); + k_current_segment.template modify(); +} + +/* ---------------------------------------------------------------------- + sort local atom-based arrays +------------------------------------------------------------------------- */ + +template +void FixWallFlowKokkos::sort_kokkos(Kokkos::BinSort &Sorter) +{ + // always sort on the device + + k_current_segment.sync_device(); + + Sorter.sort(LMPDeviceType(), k_current_segment.d_view); + + k_current_segment.modify_device(); +} + +template +int FixWallFlowKokkos::pack_exchange(int i, double *buf) +{ + k_current_segment.sync_host(); + buf[0] = static_cast(h_current_segment(i)); + return 1; +} + +template +KOKKOS_INLINE_FUNCTION +void FixWallFlowKokkos::operator()(TagFixWallFlowPackExchange, const int &mysend) const { + const int send_i = d_sendlist(mysend); + const int segment = d_current_segment(send_i); + d_buf(mysend) = static_cast(segment); + + const int copy_i = d_copylist(mysend); + if (copy_i > -1) { + d_current_segment(send_i) = d_current_segment(copy_i); + } +} + +template +int FixWallFlowKokkos::pack_exchange_kokkos( + const int &nsend, DAT::tdual_xfloat_2d &k_buf, + DAT::tdual_int_1d k_sendlist, + DAT::tdual_int_1d k_copylist, + ExecutionSpace space) +{ + k_current_segment.template sync(); + + k_buf.template sync(); + k_sendlist.template sync(); + k_copylist.template sync(); + + d_sendlist = k_sendlist.view(); + d_copylist = k_copylist.view(); + + d_buf = typename ArrayTypes::t_xfloat_1d_um( + k_buf.template view().data(), + k_buf.extent(0)*k_buf.extent(1)); + + copymode = 1; + + Kokkos::parallel_for(Kokkos::RangePolicy(0, nsend), *this); + + copymode = 0; + + k_buf.template modify(); + k_current_segment.template modify(); + + return nsend; +} + +template +int FixWallFlowKokkos::unpack_exchange(int i, double *buf) +{ + k_current_segment.sync_host(); + h_current_segment(i) = static_cast(buf[0]); + k_current_segment.modify_host(); + return 1; +} + +template +KOKKOS_INLINE_FUNCTION +void FixWallFlowKokkos::operator()(TagFixWallFlowUnpackExchange, const int &i) const +{ + int index = d_indices(i); + if (index > -1) { + d_current_segment(index) = static_cast(d_buf(i)); + } +} + +template +void FixWallFlowKokkos::unpack_exchange_kokkos( + DAT::tdual_xfloat_2d &k_buf, + DAT::tdual_int_1d &k_indices, int nrecv, + ExecutionSpace space) +{ + d_buf = typename ArrayTypes::t_xfloat_1d_um( + k_buf.template view().data(), + k_buf.extent(0)*k_buf.extent(1)); + d_indices = k_indices.view(); + + copymode = 1; + Kokkos::parallel_for(Kokkos::RangePolicy(0,nrecv),*this); + copymode = 0; + + k_current_segment.template modify(); +} + +namespace LAMMPS_NS { +template class FixWallFlowKokkos; +#ifdef LMP_KOKKOS_GPU +template class FixWallFlowKokkos; +#endif +} // namespace LAMMPS_NS diff --git a/src/KOKKOS/fix_wall_flow_kokkos.h b/src/KOKKOS/fix_wall_flow_kokkos.h new file mode 100644 index 0000000000..1faa8f4f32 --- /dev/null +++ b/src/KOKKOS/fix_wall_flow_kokkos.h @@ -0,0 +1,129 @@ +/* -*- 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. +------------------------------------------------------------------------- */ + +#ifdef FIX_CLASS +// clang-format off +FixStyle(wall/flow/kk,FixWallFlowKokkos); +FixStyle(wall/flow/kk/device,FixWallFlowKokkos); +FixStyle(wall/flow/kk/host,FixWallFlowKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_FIX_WALL_FLOW_KOKKOS_H +#define LMP_FIX_WALL_FLOW_KOKKOS_H + +#include "fix_wall_flow.h" +#include "kokkos_type.h" +#include "kokkos_base.h" +#include "Kokkos_Random.hpp" +#include "comm_kokkos.h" + +namespace LAMMPS_NS { + +struct TagFixWallFlowInit{}; +template +struct TagFixWallFlowEndOfStep{}; +struct TagFixWallFlowPackExchange{}; +struct TagFixWallFlowUnpackExchange{}; + +template +class FixWallFlowKokkos : public FixWallFlow, public KokkosBase { + public: + typedef DeviceType device_type; + typedef ArrayTypes AT; + struct MassTag{}; + struct RMassTag{}; + FixWallFlowKokkos(class LAMMPS *, int, char **); + ~FixWallFlowKokkos(); + + void init() override; + void end_of_step() override; + void grow_arrays(int) override; + void copy_arrays(int, int, int) override; + void sort_kokkos(Kokkos::BinSort &Sorter) override; + int pack_exchange(int, double *) override; + int unpack_exchange(int, double *) override; + + KOKKOS_INLINE_FUNCTION + void operator() (TagFixWallFlowInit, const int&) const; + + template + KOKKOS_INLINE_FUNCTION + void operator()(TagFixWallFlowEndOfStep, const int&) const; + + KOKKOS_INLINE_FUNCTION + void operator()(TagFixWallFlowPackExchange, const int&) const; + + KOKKOS_INLINE_FUNCTION + void operator()(TagFixWallFlowUnpackExchange, const int&) const; + + int pack_exchange_kokkos(const int &nsend,DAT::tdual_xfloat_2d &buf, + DAT::tdual_int_1d k_sendlist, + DAT::tdual_int_1d k_copylist, + ExecutionSpace space) override; + + void unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf, + DAT::tdual_int_1d &indices,int nrecv, + ExecutionSpace space) override; + protected: + typename AT::t_x_array d_x; + typename AT::t_v_array d_v; + typename AT::t_int_1d d_type; + typename AT::t_int_1d d_mask; + + typename AT::t_float_1d d_mass; + typename AT::t_float_1d d_rmass; + + typedef typename AT::t_xfloat_1d d_walls_t; + typedef Kokkos::Random_XorShift64_Pool rand_pool_t; + typedef typename rand_pool_t::generator_type rand_type_t; + + typename AT::tdual_int_1d k_current_segment; + typename AT::t_int_1d d_current_segment; + typename HAT::t_int_1d h_current_segment; + + typename AT::t_int_1d d_sendlist; + typename AT::t_xfloat_1d d_buf; + typename AT::t_int_1d d_copylist; + typename AT::t_int_1d d_indices; + + d_walls_t d_walls; + + rand_pool_t rand_pool; + + template + KOKKOS_INLINE_FUNCTION + void generate_velocity_kk(int atom_i) const; + + KOKKOS_INLINE_FUNCTION + int compute_current_segment_kk(double pos) const; + + KOKKOS_INLINE_FUNCTION + double get_mass(MassTag, int atom_i) const + { + return d_mass(d_type(atom_i)); + } + + KOKKOS_INLINE_FUNCTION + double get_mass(RMassTag, int atom_i) const + { + return d_rmass(atom_i); + } +}; + +} + +#endif +#endif + diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp new file mode 100644 index 0000000000..a6e3e38cbc --- /dev/null +++ b/src/fix_wall_flow.cpp @@ -0,0 +1,248 @@ +// 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. +------------------------------------------------------------------------- */ + +#include "fix_wall_flow.h" + +#include "atom.h" +#include "comm.h" +#include "domain.h" +#include "error.h" +#include "input.h" +#include "lattice.h" +#include "modify.h" +#include "update.h" +#include "variable.h" +#include "random_mars.h" +#include "memory.h" +#include "force.h" +#include "math_const.h" + +#include +#include +#include +#include +#include + +using namespace LAMMPS_NS; +using namespace FixConst; + +/* ---------------------------------------------------------------------- */ + +// fix name groupId wall/flow vel temp dim N coords... + +FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg), + flowax(FlowAxis::AX_X), + flowvel(0.0), + flowdir(0), + rndseed(0), + current_segment(nullptr) +{ + if (narg < 9) utils::missing_cmd_args(FLERR, "fix wall/flow", error); + + dynamic_group_allow = 1; + bool do_abort = false; + + int iarg = 3; + // parsing axis + if (strcmp(arg[iarg], "x") == 0) flowax = FlowAxis::AX_X; + else if (strcmp(arg[iarg],"y") == 0) flowax = FlowAxis::AX_Y; + else if (strcmp(arg[iarg],"z") == 0) flowax = FlowAxis::AX_Z; + else error->all(FLERR,"Illegal fix wall/flow argument: axis must by x or y or z, but {} specified", arg[iarg]); + + ++iarg; + // parsing velocity + flowvel = utils::numeric(FLERR,arg[iarg],do_abort,lmp); + if (flowvel == 0.0) error->all(FLERR,"Illegal fix wall/flow argument: velocity cannot be 0"); + if (flowvel > 0.0) flowdir = 1; + else flowdir = -1; + if(flowdir < 0) error->all(FLERR, "Negative direction is not supported yet"); + + ++iarg; + // parsing temperature + double flowtemp = utils::numeric(FLERR,arg[iarg],do_abort,lmp); + kT = lmp->force->boltz * flowtemp / force->mvv2e; + + ++iarg; + // parsing seed + rndseed = utils::inumeric(FLERR, arg[iarg],do_abort,lmp); + if(rndseed <= 0) error->all(FLERR, "Random seed must be positive!"); + + ++iarg; + // parsing wall count + int wallcount = utils::inumeric(FLERR,arg[iarg],do_abort,lmp); + if(wallcount <= 0) error->all(FLERR,"Illegal fix wall/flow argument: wall count must be positive"); + + ++iarg; + // parsing walls + if(narg - iarg != wallcount) error->all(FLERR, "Wrong fix wall/flow wall count {}," + " must be {}", + wallcount, narg - iarg); + walls.resize(wallcount + 2); + walls.front() = domain->boxlo[flowax]; + for (size_t w = 1; w <= wallcount; ++w, ++iarg) + { + walls[w] = utils::numeric(FLERR,arg[iarg],do_abort,lmp); + } + walls.back() = domain->boxhi[flowax]; + if (!std::is_sorted(walls.begin(), walls.end(), std::less_equal())) + { + error->all(FLERR, "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); + } + + memory->grow(current_segment, atom->nmax, "WallFlow::current_segment"); + atom->add_callback(Atom::GROW); + if (restart_peratom) atom->add_callback(Atom::RESTART); + + maxexchange = 1; + + random = new RanMars(lmp, rndseed + comm->me); + } + +/* ---------------------------------------------------------------------- */ + +FixWallFlow::~FixWallFlow() +{ + if (copymode) return; + atom->delete_callback(id, Atom::GROW); + if (restart_peratom) atom->delete_callback(id, Atom::RESTART); + memory->destroy(current_segment); + + delete random; +} + +/* ---------------------------------------------------------------------- */ + +int FixWallFlow::setmask() +{ + int mask = 0; + + mask |= END_OF_STEP; + + return mask; +} + +/* ---------------------------------------------------------------------- */ + +void FixWallFlow::init() +{ + int nrigid = 0; + for (int i = 0; i < modify->nfix; i++) + if (modify->fix[i]->rigid_flag) nrigid++; + + if (nrigid && comm->me == 0) + error->warning(FLERR,"FixWallFlow is not compatible with rigid bodies"); + + for (int i = 0; i < atom->nlocal; ++i) + { + double pos = atom->x[i][flowax]; + current_segment[i] = compute_current_segment(pos); + } +} + +/* ---------------------------------------------------------------------- */ + +void FixWallFlow::end_of_step() +{ + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; ++i) + { + if (mask[i] & groupbit) + { + double pos = x[i][flowax]; + int prev_segment = current_segment[i]; + current_segment[i] = compute_current_segment(pos); + + if (prev_segment != current_segment[i]) + { + generate_velocity(i); + } + } + } +} + +void FixWallFlow::generate_velocity(int atom_i) +{ + const int newton_iteration_count = 10; + double *vel = atom->v[atom_i]; + double mass = atom->mass[atom->type[atom_i]]; + const double gamma = 1.0 / std::sqrt(2.0 * kT / mass); + double delta = gamma * flowvel; + + const double edd = std::exp(-delta*delta) / MathConst::MY_PIS + delta * std::erf(delta); + const double probability_threshold = 0.5f * (1.f + delta / edd); + + double direction = 1.0; + + if (random->uniform() > probability_threshold) + { + delta = -delta; + direction = -direction; + } + + const double xi_0 = random->uniform(); + const double F_inf = edd + delta; + const double xi = xi_0 * F_inf; + const double x_0 = (std::sqrt(delta*delta + 2) - delta) * 0.5; + double x = x_0; + for (int i = 0; i < newton_iteration_count; ++i) + { + x -= (std::exp(x*x) * MathConst::MY_PIS * (xi - delta * std::erfc(x)) - 1.0) / (x + delta) * 0.5; + } + + const double nu = x + delta; + const double v = nu / gamma; + + vel[flowax] = v * direction; + vel[(flowax + 1) % 3] = random->gaussian() / (gamma * MathConst::MY_SQRT2); + vel[(flowax + 2) % 3] = random->gaussian() / (gamma * MathConst::MY_SQRT2); +} + +int FixWallFlow::compute_current_segment(double pos) const +{ + int result = 0; + for (; result < walls.size()-1; ++result) + { + if (pos >= walls[result] && pos < walls[result + 1]) + { + return result; + } + } + return -1; // -1 is "out of box" region +} + +void FixWallFlow::grow_arrays(int nmax) +{ + memory->grow(current_segment, nmax, "WallFlow::current_segment"); +} + +void FixWallFlow::copy_arrays(int i, int j, int) +{ + current_segment[j] = current_segment[i]; +} + +int FixWallFlow::pack_exchange(int i, double* buf) +{ + buf[0] = static_cast(current_segment[i]); + return 1; +} + +int FixWallFlow::unpack_exchange(int i, double* buf) +{ + current_segment[i] = static_cast(buf[0]); + return 1; +} diff --git a/src/fix_wall_flow.h b/src/fix_wall_flow.h new file mode 100644 index 0000000000..ec9e4a4601 --- /dev/null +++ b/src/fix_wall_flow.h @@ -0,0 +1,60 @@ +/* -*- 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. +------------------------------------------------------------------------- */ + +#ifdef FIX_CLASS +// clang-format off +FixStyle(wall/flow,FixWallFlow); +// clang-format on +#else + +#ifndef LMP_FIX_WALL_FLOW_H +#define LMP_FIX_WALL_FLOW_H + +#include "fix.h" +#include +namespace LAMMPS_NS { + +class FixWallFlow : public Fix { + public: + enum FlowAxis {AX_X = 0, AX_Y = 1, AX_Z = 2}; + + FixWallFlow(class LAMMPS *, int, char **); + ~FixWallFlow() override; + int setmask() override; + void init() override; + void end_of_step() override; + + void grow_arrays(int) override; + void copy_arrays(int, int, int) override; + + int pack_exchange(int, double *) override; + int unpack_exchange(int, double *) override; + + protected: + FlowAxis flowax; + double flowvel; + double kT; + std::vector walls; + + int flowdir; + int rndseed; + class RanMars *random; + int *current_segment; + int compute_current_segment(double pos) const; + void generate_velocity(int i); +}; + +} // namespace LAMMPS_NS + +#endif +#endif From b775085189d3b66d193cc4b8e96cb3599f9c5db0 Mon Sep 17 00:00:00 2001 From: vladgl Date: Mon, 9 Oct 2023 13:29:15 +0300 Subject: [PATCH 05/46] Add licensing info --- src/KOKKOS/fix_wall_flow_kokkos.cpp | 19 +++++++++++++++++++ src/fix_wall_flow.cpp | 8 ++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index 501a1bbd3f..46805f07d6 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -1,3 +1,22 @@ +// 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 authors: Vladislav Galigerov (HSE), + Daniil Pavlov (MIPT) +------------------------------------------------------------------------- */ + #include "fix_wall_flow_kokkos.h" #include "atom_kokkos.h" #include "memory_kokkos.h" diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index a6e3e38cbc..adaf7412cc 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -1,5 +1,5 @@ // clang-format off - /* ---------------------------------------------------------------------- +/* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories LAMMPS development team: developers@lammps.org @@ -12,8 +12,12 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "fix_wall_flow.h" +/* ---------------------------------------------------------------------- + Contributing authors: Vladislav Galigerov (HSE), + Daniil Pavlov (MIPT) +------------------------------------------------------------------------- */ +#include "fix_wall_flow.h" #include "atom.h" #include "comm.h" #include "domain.h" From 70cc1039fd304a2e1b64897e37ad4efbe14915d4 Mon Sep 17 00:00:00 2001 From: vladgl Date: Mon, 9 Oct 2023 17:30:57 +0300 Subject: [PATCH 06/46] Some cleaning --- src/KOKKOS/fix_wall_flow_kokkos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index 46805f07d6..b0efee0941 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -25,7 +25,7 @@ #include "force.h" #include -//#include "comm.h + // clang-format off using namespace LAMMPS_NS; From 19e45187f8d4bf7663ffb3f24591ce66f9153bdd Mon Sep 17 00:00:00 2001 From: vladgl Date: Mon, 9 Oct 2023 17:32:59 +0300 Subject: [PATCH 07/46] Add cite string --- src/fix_wall_flow.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index adaf7412cc..d6dbafd64c 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -19,6 +19,7 @@ #include "fix_wall_flow.h" #include "atom.h" +#include "citeme.h" #include "comm.h" #include "domain.h" #include "error.h" @@ -43,7 +44,16 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ -// fix name groupId wall/flow vel temp dim N coords... +static const char cite_fix_wall_flow_c[] = + "fix wall/flow command: doi:{tba}\n\n" + "@Article{Pavlov-etal-IJHPCA-2023,\n" + " author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod Nikolskiy and Vladimir Stegailov},\n" + " title = {GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence},\n" + " journal = {International Journal of High Performance Computing Applications},\n" + " year = 2023,\n" + " volume = {tba},\n" + " pages = {tba}\n” + "}\n\n"; FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), @@ -53,6 +63,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : rndseed(0), current_segment(nullptr) { + if (lmp->citeme) lmp->citeme->add(cite_fix_wall_flow_c); if (narg < 9) utils::missing_cmd_args(FLERR, "fix wall/flow", error); dynamic_group_allow = 1; From d7f7306b7d14ecb067b08c0fbf17aaf26ee83852 Mon Sep 17 00:00:00 2001 From: vladgl Date: Fri, 13 Oct 2023 14:26:05 +0300 Subject: [PATCH 08/46] Fix character --- src/fix_wall_flow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index d6dbafd64c..ff4d4078dd 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -52,7 +52,7 @@ static const char cite_fix_wall_flow_c[] = " journal = {International Journal of High Performance Computing Applications},\n" " year = 2023,\n" " volume = {tba},\n" - " pages = {tba}\n” + " pages = {tba}\n" "}\n\n"; FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : From 249f3b0af4149d90ea68d3a008ed3b3148e9b5c1 Mon Sep 17 00:00:00 2001 From: vladgl Date: Sat, 14 Oct 2023 13:10:08 +0300 Subject: [PATCH 09/46] Add units command --- src/fix_wall_flow.cpp | 44 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index ff4d4078dd..e5602b7af9 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -82,7 +82,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : if (flowvel == 0.0) error->all(FLERR,"Illegal fix wall/flow argument: velocity cannot be 0"); if (flowvel > 0.0) flowdir = 1; else flowdir = -1; - if(flowdir < 0) error->all(FLERR, "Negative direction is not supported yet"); + if(flowdir < 0) error->all(FLERR, "Illegal fix wall/flow argument: negative direction is not supported yet"); ++iarg; // parsing temperature @@ -92,29 +92,59 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : ++iarg; // parsing seed rndseed = utils::inumeric(FLERR, arg[iarg],do_abort,lmp); - if(rndseed <= 0) error->all(FLERR, "Random seed must be positive!"); + if(rndseed <= 0) error->all(FLERR, "Illegal fix wall/flow argument: random seed must be positive integer"); ++iarg; // parsing wall count int wallcount = utils::inumeric(FLERR,arg[iarg],do_abort,lmp); - if(wallcount <= 0) error->all(FLERR,"Illegal fix wall/flow argument: wall count must be positive"); + if(wallcount <= 0) error->all(FLERR,"Illegal fix wall/flow argument: wall count must be positive integer"); ++iarg; // parsing walls - if(narg - iarg != wallcount) error->all(FLERR, "Wrong fix wall/flow wall count {}," - " must be {}", - wallcount, narg - iarg); + if(narg - iarg != wallcount && narg - iarg != wallcount + 2) error->all(FLERR, "Wrong fix wall/flow wall count"); + auto getscale = [&]() -> double { + switch (flowax) + { + case FlowAxis::AX_X: + return domain->lattice->xlattice; + case FlowAxis::AX_Y: + return domain->lattice->ylattice; + case FlowAxis::AX_Z: + return domain->lattice->zlattice; + default: return 0.0; + } + return 0.0; + }; + double scale = getscale(); + + if (narg - iarg == wallcount + 2) + { + if(strcmp(arg[narg - 2], "units") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); + if (strcmp(arg[narg - 1], "box") == 0) scale = 1.0; + else if (strcmp(arg[narg - 1], "lattice") == 0) + { + scale = getscale(); + } + else error->all(FLERR, "Wrong fix wall/flow units command"); + } + walls.resize(wallcount + 2); walls.front() = domain->boxlo[flowax]; for (size_t w = 1; w <= wallcount; ++w, ++iarg) { - walls[w] = utils::numeric(FLERR,arg[iarg],do_abort,lmp); + walls[w] = utils::numeric(FLERR,arg[iarg],do_abort,lmp) * scale; } walls.back() = domain->boxhi[flowax]; if (!std::is_sorted(walls.begin(), walls.end(), std::less_equal())) { error->all(FLERR, "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); } + std::cout << "Walls:\n" + for (auto w : walls) + { + std::cout << w << " "; + } + std::cout << std::endl; memory->grow(current_segment, atom->nmax, "WallFlow::current_segment"); atom->add_callback(Atom::GROW); From 381330c3c25aa1e04819925e42ad8202b0615072 Mon Sep 17 00:00:00 2001 From: vladgl Date: Sat, 14 Oct 2023 13:11:06 +0300 Subject: [PATCH 10/46] Fix typo --- src/fix_wall_flow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index e5602b7af9..beaaa474eb 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -139,7 +139,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : { error->all(FLERR, "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); } - std::cout << "Walls:\n" + std::cout << "Walls:\n"; for (auto w : walls) { std::cout << w << " "; From c53847ad882f282ecf737040bedf3968682c656f Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Wed, 31 Jan 2024 15:35:04 +0300 Subject: [PATCH 11/46] Update citation --- src/fix_wall_flow.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index beaaa474eb..591f640279 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -45,14 +45,15 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ static const char cite_fix_wall_flow_c[] = - "fix wall/flow command: doi:{tba}\n\n" - "@Article{Pavlov-etal-IJHPCA-2023,\n" + "fix wall/flow command: doi:10.1177/10943420231213013\n\n" + "@Article{Pavlov-etal-IJHPCA-2024,\n" " author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod Nikolskiy and Vladimir Stegailov},\n" - " title = {GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence},\n" - " journal = {International Journal of High Performance Computing Applications},\n" - " year = 2023,\n" - " volume = {tba},\n" - " pages = {tba}\n" + " title = {GPU-based molecular dynamics of fluid flows: Reaching for turbulence},\n" + " journal = {The International Journal of High Performance Computing Applications},\n" + " year = 2024,\n" + " volume = 38,\n" + " number = 1,\n" + " pages = 34-49\n" "}\n\n"; FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : From 90105fd58a0a5e55ee43993c9b9c7415376ea5ca Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Sun, 4 Feb 2024 16:02:53 +0300 Subject: [PATCH 12/46] Add wall_flow documentation --- doc/src/Bibliography.rst | 3 + doc/src/Commands_fix.rst | 1 + doc/src/fix.rst | 1 + doc/src/fix_wall_flow.rst | 123 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 doc/src/fix_wall_flow.rst diff --git a/doc/src/Bibliography.rst b/doc/src/Bibliography.rst index 4ed8e73dfe..9778340c94 100644 --- a/doc/src/Bibliography.rst +++ b/doc/src/Bibliography.rst @@ -877,6 +877,9 @@ Bibliography **(PLUMED)** G.A. Tribello, M. Bonomi, D. Branduardi, C. Camilloni and G. Bussi, Comp. Phys. Comm 185, 604 (2014) +**(Pavlov)** +D Pavlov, V Galigerov, D Kolotinskii, V Nikolskiy, V Stegailov, International Journal of High Performance Computing Applications, 38, 34-49 (2024). + **(Paquay)** Paquay and Kusters, Biophys. J., 110, 6, (2016). preprint available at `arXiv:1411.3019 `_. diff --git a/doc/src/Commands_fix.rst b/doc/src/Commands_fix.rst index e89e302673..304f54f690 100644 --- a/doc/src/Commands_fix.rst +++ b/doc/src/Commands_fix.rst @@ -262,6 +262,7 @@ OPT. * :doc:`wall/body/polyhedron ` * :doc:`wall/colloid ` * :doc:`wall/ees ` + * :doc:`wall/flow (k) ` * :doc:`wall/gran (k) ` * :doc:`wall/gran/region ` * :doc:`wall/harmonic ` diff --git a/doc/src/fix.rst b/doc/src/fix.rst index 69a7212487..4ff7fd6bd6 100644 --- a/doc/src/fix.rst +++ b/doc/src/fix.rst @@ -427,6 +427,7 @@ accelerated styles exist. * :doc:`wall/body/polyhedron ` - time integration for body particles of style :doc:`rounded/polyhedron ` * :doc:`wall/colloid ` - Lennard-Jones wall interacting with finite-size particles * :doc:`wall/ees ` - wall for ellipsoidal particles +* :doc:`wall/flow ` - flow boundary conditions * :doc:`wall/gran ` - frictional wall(s) for granular simulations * :doc:`wall/gran/region ` - :doc:`fix wall/region ` equivalent for use with granular particles * :doc:`wall/harmonic ` - harmonic spring wall diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst new file mode 100644 index 0000000000..56a2510d08 --- /dev/null +++ b/doc/src/fix_wall_flow.rst @@ -0,0 +1,123 @@ +.. index:: fix wall/flow +.. index:: fix wall/flow/kk + +fix wall/flow command +===================== + +Accelerator Variants: *wall/flow/kk* + +Syntax +"""""" + +.. code-block:: LAMMPS + + fix ID group-ID wall/flow ax vf T seed N coords... + +* ID, group-ID are documented in :doc:`fix ` command +* wall/flow = style name of this fix command +* ax = flow axis (*x*, *y*, or *z* character) +* vf = *ax* component of generated flow velocity +* T = flow temperature (temperature units) +* seed = random seed for stochasticity (positive integer) +* N = number of walls (positive integer) +* coords = set of N wall coordinates (box units) along *ax* axis arranged in ascending order. Note that an additional implicit wall is introduced at the boundary of the simulation domain, so the resulting system always has N+1 walls. + +Examples +"""""""" + +.. code-block:: LAMMPS + + fix 1 g_flow wall/flow x ${VFLOW} ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} + fix 2 all wall/flow 0.4 0.2 3 1 400 + +Description +""""""""""" + +This fix implements flow boundary conditions (FBC) introduced in :ref:`(Pavlov) ` and :ref:`(Pavlov) `. +The goal is to generate a stationary flow with a shifted Maxwell velocity distribution: + +.. math:: + + f_z(v_z) \propto \exp{\left(-\frac{m (v_z-v_{\text{flow}})^2}{2 k T}\right)} + +This is achieved by reassigning the velocity of each particle that passes a wall. +Such reassigning represents an emission of a new particle into the system with +simultaneous removal of a particle with the same position. +The parallel velocity components parallel to the wall are re-assigned according +to the Maxwell velocity distribution. The perpendicular component is assigned +according to the following velocity distribution: + +.. math:: + + f_{\text{z generated}}(v_z) \propto v_z f_z(v_z) + +It can be shown that in an ideal-gas scenario this makes the velocity +distribution of particles between walls exactly as desired. + +Since in most cases simulated systems are not ideal gas, +the need for multiple walls might arise, as a single wall may not be +sufficient for maintaining a stationary flow without congestions +manifesting as areas with increased density located upstream from static obstacles. + +For the same reason, the actual temperature and velocity of the generated +flow may differ from ones requested. The degree of such discrepancy is determined +by how different from the ideal gas the simulated system is. Therefore, a calibration procedure is required for each system as described in :ref:`(Pavlov) `. + +The interactions between particles on different sides of a wall are not disabled or neglected and the +particle positions aren't affected by the velocity reassignment. +This removes the need to modify the force field to work correctly in cases when a particle is close +to a wall (for example, if particle positions were uniformly redistributed across the surface of the wall, +two particles could end up too close to each other, potentially causing the simulation to explode). +However due to this compromise, some collective phenomena such as areas with increased/decreased density +or collective movements are not fully removed when particles cross a wall. +This unwanted consequence can also be potentially mitigated by using more than one wall. + + +---------- + +Note that when high flow velocity is reached, a lost atoms error may +occur (see :doc:`error messages `). +If this message appears when using this fix, you can, for example, reduce the frequency of the +neighbor list rebuild via :doc:`neigh_modify ` command. + +Restart, fix_modify, output, run start/stop, minimize info +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +No information about this fix is written to :doc:`binary restart files `. + +None of the :doc:`fix_modify ` options are relevant to +this fix. + +No global or per-atom quantities are stored by this fix for access by +various :doc:`output commands `. + +No parameter of this fix can be used with the *start/stop* keywords of +the :doc:`run ` command. + +This fix is not invoked during :doc:`energy minimization `. + +Restrictions +"""""""""""" + +Flow boundary conditions should not be used with rigid bodies such as those +defined by a "fix rigid" command. + +Related commands +"""""""""""""""" + +:doc:`fix wall/reflect ` command + +Default +""""""" + +none + +---------- + +.. _fbc-Pavlov1: + +**(Pavlov)** Pavlov, Kolotinskii, Stegailov, “GPU-Based Molecular Dynamics of Turbulent Liquid Flows with OpenMM”, In: Proceedings of PPAM-2022, LNCS (Springer), vol. 13826, pp. 346–358 (2023) + +.. _fbc-Pavlov2: + +**(Pavlov)** Pavlov, Galigerov, Kolotinskii, Nikolskiy, Stegailov, "GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence”, Int. J. High Perf. Comp. Appl., (2024) \ No newline at end of file From 4ad5a9d3eb01a7ad2a3771d43c678b8c821e5e24 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Tue, 6 Feb 2024 21:00:37 +0300 Subject: [PATCH 13/46] Fix doc --- doc/src/fix_wall_flow.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index 56a2510d08..e0f5424658 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -11,7 +11,7 @@ Syntax .. code-block:: LAMMPS - fix ID group-ID wall/flow ax vf T seed N coords... + fix ID group-ID wall/flow ax vf T seed N coords ... keyword value * ID, group-ID are documented in :doc:`fix ` command * wall/flow = style name of this fix command @@ -22,6 +22,15 @@ Syntax * N = number of walls (positive integer) * coords = set of N wall coordinates (box units) along *ax* axis arranged in ascending order. Note that an additional implicit wall is introduced at the boundary of the simulation domain, so the resulting system always has N+1 walls. +* zero or more keyword/value pairs may be appended +* keyword = *units* + + .. parsed-literal:: + + *units* value = *lattice* or *box* + *lattice* = the wall positions are defined in lattice units + *box* = the wall positions are defined in simulation box units + Examples """""""" @@ -110,7 +119,7 @@ Related commands Default """"""" -none +The default for the units keyword is lattice. ---------- From 0f5436de99607f000a0b4c2291443baf2d5e1c46 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Tue, 6 Feb 2024 22:43:56 +0300 Subject: [PATCH 14/46] Fix spelling --- doc/src/fix_wall_flow.rst | 10 +++++----- doc/utils/sphinx-config/false_positives.txt | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index e0f5424658..f6f5a242ac 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -42,7 +42,7 @@ Examples Description """"""""""" -This fix implements flow boundary conditions (FBC) introduced in :ref:`(Pavlov) ` and :ref:`(Pavlov) `. +This fix implements flow boundary conditions (FBC) introduced in :ref:`(Pavlov1) ` and :ref:`(Pavlov2) `. The goal is to generate a stationary flow with a shifted Maxwell velocity distribution: .. math:: @@ -52,7 +52,7 @@ The goal is to generate a stationary flow with a shifted Maxwell velocity distri This is achieved by reassigning the velocity of each particle that passes a wall. Such reassigning represents an emission of a new particle into the system with simultaneous removal of a particle with the same position. -The parallel velocity components parallel to the wall are re-assigned according +The velocity components parallel to the wall are re-assigned according to the Maxwell velocity distribution. The perpendicular component is assigned according to the following velocity distribution: @@ -65,7 +65,7 @@ distribution of particles between walls exactly as desired. Since in most cases simulated systems are not ideal gas, the need for multiple walls might arise, as a single wall may not be -sufficient for maintaining a stationary flow without congestions +sufficient for maintaining a stationary flow without congestion manifesting as areas with increased density located upstream from static obstacles. For the same reason, the actual temperature and velocity of the generated @@ -125,8 +125,8 @@ The default for the units keyword is lattice. .. _fbc-Pavlov1: -**(Pavlov)** Pavlov, Kolotinskii, Stegailov, “GPU-Based Molecular Dynamics of Turbulent Liquid Flows with OpenMM”, In: Proceedings of PPAM-2022, LNCS (Springer), vol. 13826, pp. 346–358 (2023) +**(Pavlov1)** Pavlov, Kolotinskii, Stegailov, "GPU-Based Molecular Dynamics of Turbulent Liquid Flows with OpenMM", Proceedings of PPAM-2022, LNCS (Springer), vol. 13826, pp. 346-358 (2023) .. _fbc-Pavlov2: -**(Pavlov)** Pavlov, Galigerov, Kolotinskii, Nikolskiy, Stegailov, "GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence”, Int. J. High Perf. Comp. Appl., (2024) \ No newline at end of file +**(Pavlov2)** Pavlov, Galigerov, Kolotinskii, Nikolskiy, Stegailov, "GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence", Int. J. High Perf. Comp. Appl., (2024) \ No newline at end of file diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 4f5fe6fdaf..6106a1638c 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -1770,6 +1770,7 @@ Kolafa Kollman kolmogorov Kolmogorov +Kolotinskii Kondor konglt Koning @@ -2774,6 +2775,7 @@ PEigenDense Peng peptide peratom +Perf Pergamon pergrid peri @@ -3884,6 +3886,7 @@ Verlet versa Verstraelen ves +vf vflag vfrac vhi From a3a054cc152f08006f8b6bb8870869f4d4f5626c Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Tue, 6 Feb 2024 23:19:47 +0300 Subject: [PATCH 15/46] Another spell fix --- doc/src/fix_wall_flow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index f6f5a242ac..d89e0b6d89 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -73,7 +73,7 @@ flow may differ from ones requested. The degree of such discrepancy is determine by how different from the ideal gas the simulated system is. Therefore, a calibration procedure is required for each system as described in :ref:`(Pavlov) `. The interactions between particles on different sides of a wall are not disabled or neglected and the -particle positions aren't affected by the velocity reassignment. +particle positions are not affected by the velocity reassignment. This removes the need to modify the force field to work correctly in cases when a particle is close to a wall (for example, if particle positions were uniformly redistributed across the surface of the wall, two particles could end up too close to each other, potentially causing the simulation to explode). From 5bab14d31e9b2b8ec9622778de2ec78088b1125d Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Tue, 6 Feb 2024 23:23:11 +0300 Subject: [PATCH 16/46] Sync unpack_exchange_kokkos with develop --- src/KOKKOS/fix_wall_flow_kokkos.cpp | 1 + src/KOKKOS/fix_wall_flow_kokkos.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index b0efee0941..daf73e7ef2 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -292,6 +292,7 @@ template void FixWallFlowKokkos::unpack_exchange_kokkos( DAT::tdual_xfloat_2d &k_buf, DAT::tdual_int_1d &k_indices, int nrecv, + int /*nrecv1*/, int /*nextrarecv1*/, ExecutionSpace space) { d_buf = typename ArrayTypes::t_xfloat_1d_um( diff --git a/src/KOKKOS/fix_wall_flow_kokkos.h b/src/KOKKOS/fix_wall_flow_kokkos.h index 1faa8f4f32..10bfed962d 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.h +++ b/src/KOKKOS/fix_wall_flow_kokkos.h @@ -75,6 +75,7 @@ class FixWallFlowKokkos : public FixWallFlow, public KokkosBase { void unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf, DAT::tdual_int_1d &indices,int nrecv, + int /*nrecv1*/, int /*nextrarecv1*/, ExecutionSpace space) override; protected: typename AT::t_x_array d_x; From df7662162e29cbcb40e8eecb26736950535c50f8 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Wed, 7 Feb 2024 13:53:40 +0300 Subject: [PATCH 17/46] Add example --- examples/wall/in.wall.flow | 79 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 examples/wall/in.wall.flow diff --git a/examples/wall/in.wall.flow b/examples/wall/in.wall.flow new file mode 100644 index 0000000000..59d1b99eda --- /dev/null +++ b/examples/wall/in.wall.flow @@ -0,0 +1,79 @@ +variable nrun equal 10000 +variable dump_count equal 10 + +variable nwall equal 4 +variable w1 equal 67 +variable w2 equal 71 +variable w3 equal 75 +variable w4 equal 79 + +variable x_cylinder equal 20 +variable y_cylinder equal 17 +variable r_cylinder equal 4 + +variable MASS equal 1 +variable TEMP equal 0.4 +variable VFLOW equal 0.5 + +units lj +atom_style atomic + +lattice fcc 0.3 +region sim_box block 0 84 0 34 0 10 + +boundary p p p + +create_box 2 sim_box +region reg_cylinder cylinder z ${x_cylinder} ${y_cylinder} ${r_cylinder} EDGE EDGE + +create_atoms 1 box + +## setup obstacle ## +group g_obst region reg_cylinder +group g_flow subtract all g_obst +set group g_obst type 2 + +mass 1 ${MASS} +mass 2 ${MASS} + +velocity g_flow create ${TEMP} 4928459 rot yes dist gaussian +velocity g_obst set 0.0 0.0 0.0 + +pair_style lj/cut 1.122462 +pair_coeff 1 1 1.0 1.0 +pair_coeff 1 2 1.0 1.0 +pair_coeff 2 2 1.0 1.0 +pair_modify shift yes + +neighbor 0.3 bin +neigh_modify delay 0 every 20 check no + +fix 1 g_flow nve +fix 2 g_flow wall/flow x ${VFLOW} ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} + +variable dump_every equal ${nrun}/${dump_count} +variable thermo_every equal ${dump_every} +variable restart_every equal ${nrun}/10 + +##### uncomment for grid aggregation ##### +#variable gr_Nx equal 42 +#variable gr_Ny equal 17 +#variable gr_Nz equal 1 +#variable gr_Nevery equal ${dump_every} +#variable gr_Nrepeat equal 1 +#variable gr_Nfreq equal ${dump_every} +#fix 3 g_flow ave/grid ${gr_Nevery} ${gr_Nrepeat} ${gr_Nfreq} ${gr_Nx} ${gr_Ny} ${gr_Nz} vx vy vz density/mass norm all ave one +#compute ct_gridId g_flow property/grid ${gr_Nx} ${gr_Ny} ${gr_Nz} id +#dump dmp_grid g_flow grid ${dump_every} grid.lammpstrj c_ct_gridId:grid:data f_3:grid:data[*] +########################################## + +#dump dmp_coord all atom ${dump_every} dump.lammpstrj + +#compute ct_Temp g_flow temp/com +#thermo_style custom step temp epair emol etotal press c_ct_Temp + +#restart ${restart_every} flow.restart + +timestep 0.005 +thermo ${thermo_every} +run ${nrun} From e33590b2fc101813d0beef963daf31c0dd40a264 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Wed, 7 Feb 2024 16:03:32 +0300 Subject: [PATCH 18/46] Whitespace --- doc/src/fix_wall_flow.rst | 2 +- src/KOKKOS/fix_wall_flow_kokkos.cpp | 32 ++++++++++++++--------------- src/KOKKOS/fix_wall_flow_kokkos.h | 6 +++--- src/fix_wall_flow.cpp | 4 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index d89e0b6d89..3b8d7300e6 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -129,4 +129,4 @@ The default for the units keyword is lattice. .. _fbc-Pavlov2: -**(Pavlov2)** Pavlov, Galigerov, Kolotinskii, Nikolskiy, Stegailov, "GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence", Int. J. High Perf. Comp. Appl., (2024) \ No newline at end of file +**(Pavlov2)** Pavlov, Galigerov, Kolotinskii, Nikolskiy, Stegailov, "GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence", Int. J. High Perf. Comp. Appl., (2024) diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index daf73e7ef2..a143578fdc 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -48,7 +48,7 @@ FixWallFlowKokkos::FixWallFlowKokkos(LAMMPS *lmp, int narg, char **a d_walls = d_walls_t("FixWallFlowKokkos::walls", walls.size()); auto h_walls = Kokkos::create_mirror_view(d_walls); for (int i = 0; i < walls.size(); ++i) - { + { h_walls(i) = walls[i]; } Kokkos::deep_copy(d_walls, h_walls); @@ -61,7 +61,7 @@ FixWallFlowKokkos::~FixWallFlowKokkos() memoryKK->destroy_kokkos(k_current_segment, current_segment); } -template +template void FixWallFlowKokkos::init() { atomKK->sync(execution_space, datamask_read); @@ -83,10 +83,10 @@ KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWall d_current_segment(i) = compute_current_segment_kk(pos); } -template -void FixWallFlowKokkos::end_of_step() +template +void FixWallFlowKokkos::end_of_step() { - atomKK->sync(execution_space, datamask_read); + atomKK->sync(execution_space, datamask_read); k_current_segment.template sync(); d_x = atomKK->k_x.template view(); @@ -111,17 +111,17 @@ void FixWallFlowKokkos::end_of_step() template template -KOKKOS_INLINE_FUNCTION +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWallFlowEndOfStep, const int &atom_i) const { - if (d_mask[atom_i] & groupbit) - { + if (d_mask[atom_i] & groupbit) + { double pos = d_x(atom_i, flowax); int prev_segment = d_current_segment(atom_i); d_current_segment(atom_i) = compute_current_segment_kk(pos); - if (prev_segment != d_current_segment(atom_i)) - { + if (prev_segment != d_current_segment(atom_i)) + { generate_velocity_kk(atom_i); } } @@ -129,7 +129,7 @@ void FixWallFlowKokkos::operator()(TagFixWallFlowEndOfStep, template template -KOKKOS_INLINE_FUNCTION +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const { const int newton_iteration_count = 10; @@ -170,7 +170,7 @@ void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const } template -KOKKOS_INLINE_FUNCTION +KOKKOS_INLINE_FUNCTION int FixWallFlowKokkos::compute_current_segment_kk(double pos) const { int result = 0; @@ -181,8 +181,8 @@ int FixWallFlowKokkos::compute_current_segment_kk(double pos) const } -template -void FixWallFlowKokkos::grow_arrays(int nmax) +template +void FixWallFlowKokkos::grow_arrays(int nmax) { k_current_segment.template sync(); memoryKK->grow_kokkos(k_current_segment, current_segment, nmax, "WallFlowKK::current_segment"); @@ -193,7 +193,7 @@ void FixWallFlowKokkos::grow_arrays(int nmax) } template -void FixWallFlowKokkos::copy_arrays(int i, int j, int) +void FixWallFlowKokkos::copy_arrays(int i, int j, int) { k_current_segment.template sync(); h_current_segment(j) = h_current_segment(i); @@ -252,7 +252,7 @@ int FixWallFlowKokkos::pack_exchange_kokkos( d_sendlist = k_sendlist.view(); d_copylist = k_copylist.view(); - + d_buf = typename ArrayTypes::t_xfloat_1d_um( k_buf.template view().data(), k_buf.extent(0)*k_buf.extent(1)); diff --git a/src/KOKKOS/fix_wall_flow_kokkos.h b/src/KOKKOS/fix_wall_flow_kokkos.h index 10bfed962d..8de0eded0a 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.h +++ b/src/KOKKOS/fix_wall_flow_kokkos.h @@ -107,16 +107,16 @@ class FixWallFlowKokkos : public FixWallFlow, public KokkosBase { KOKKOS_INLINE_FUNCTION void generate_velocity_kk(int atom_i) const; - KOKKOS_INLINE_FUNCTION + KOKKOS_INLINE_FUNCTION int compute_current_segment_kk(double pos) const; - KOKKOS_INLINE_FUNCTION + KOKKOS_INLINE_FUNCTION double get_mass(MassTag, int atom_i) const { return d_mass(d_type(atom_i)); } - KOKKOS_INLINE_FUNCTION + KOKKOS_INLINE_FUNCTION double get_mass(RMassTag, int atom_i) const { return d_rmass(atom_i); diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index 591f640279..695b93aea8 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -99,7 +99,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : // parsing wall count int wallcount = utils::inumeric(FLERR,arg[iarg],do_abort,lmp); if(wallcount <= 0) error->all(FLERR,"Illegal fix wall/flow argument: wall count must be positive integer"); - + ++iarg; // parsing walls if(narg - iarg != wallcount && narg - iarg != wallcount + 2) error->all(FLERR, "Wrong fix wall/flow wall count"); @@ -173,7 +173,7 @@ FixWallFlow::~FixWallFlow() int FixWallFlow::setmask() { int mask = 0; - + mask |= END_OF_STEP; return mask; From 93fcf3cc754e4e77aba34ce839633a57ebe45146 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 7 Feb 2024 15:07:11 -0500 Subject: [PATCH 19/46] move fix to EXTRA-FIX package, update docs, add reference logs to example --- doc/src/fix_wall_flow.rst | 6 + examples/wall/in.wall.flow | 2 +- examples/wall/log.7Feb24.wall.flow.g++.1 | 182 +++++++++++++++++++++++ examples/wall/log.7Feb24.wall.flow.g++.4 | 182 +++++++++++++++++++++++ src/.gitignore | 2 + src/{ => EXTRA-FIX}/fix_wall_flow.cpp | 0 src/{ => EXTRA-FIX}/fix_wall_flow.h | 0 7 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 examples/wall/log.7Feb24.wall.flow.g++.1 create mode 100644 examples/wall/log.7Feb24.wall.flow.g++.4 rename src/{ => EXTRA-FIX}/fix_wall_flow.cpp (100%) rename src/{ => EXTRA-FIX}/fix_wall_flow.h (100%) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index 3b8d7300e6..464021ff52 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -42,6 +42,8 @@ Examples Description """"""""""" +.. versionadded:: TBD + This fix implements flow boundary conditions (FBC) introduced in :ref:`(Pavlov1) ` and :ref:`(Pavlov2) `. The goal is to generate a stationary flow with a shifted Maxwell velocity distribution: @@ -108,6 +110,10 @@ This fix is not invoked during :doc:`energy minimization `. Restrictions """""""""""" +Fix *wall_flow* is part of the EXTRA-FIX package. It is only enabled +if LAMMPS was built with that package. See the :doc:`Build package +` page for more info. + Flow boundary conditions should not be used with rigid bodies such as those defined by a "fix rigid" command. diff --git a/examples/wall/in.wall.flow b/examples/wall/in.wall.flow index 59d1b99eda..9dfe001a55 100644 --- a/examples/wall/in.wall.flow +++ b/examples/wall/in.wall.flow @@ -1,4 +1,4 @@ -variable nrun equal 10000 +variable nrun equal 1000 variable dump_count equal 10 variable nwall equal 4 diff --git a/examples/wall/log.7Feb24.wall.flow.g++.1 b/examples/wall/log.7Feb24.wall.flow.g++.1 new file mode 100644 index 0000000000..75e8b66fe1 --- /dev/null +++ b/examples/wall/log.7Feb24.wall.flow.g++.1 @@ -0,0 +1,182 @@ +LAMMPS (21 Nov 2023 - Development - patch_21Nov2023-758-ge33590b2fc-modified) + using 1 OpenMP thread(s) per MPI task +variable nrun equal 1000 +variable dump_count equal 10 + +variable nwall equal 4 +variable w1 equal 67 +variable w2 equal 71 +variable w3 equal 75 +variable w4 equal 79 + +variable x_cylinder equal 20 +variable y_cylinder equal 17 +variable r_cylinder equal 4 + +variable MASS equal 1 +variable TEMP equal 0.4 +variable VFLOW equal 0.5 + +units lj +atom_style atomic + +lattice fcc 0.3 +Lattice spacing in x,y,z = 2.3712622 2.3712622 2.3712622 +region sim_box block 0 84 0 34 0 10 + +boundary p p p + +create_box 2 sim_box +Created orthogonal box = (0 0 0) to (199.18603 80.622915 23.712622) + 1 by 1 by 1 MPI processor grid +region reg_cylinder cylinder z ${x_cylinder} ${y_cylinder} ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 ${y_cylinder} ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 17 ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 17 4 EDGE EDGE + +create_atoms 1 box +Created 114240 atoms + using lattice units in orthogonal box = (0 0 0) to (199.18603 80.622915 23.712622) + create_atoms CPU = 0.010 seconds + +## setup obstacle ## +group g_obst region reg_cylinder +1950 atoms in group g_obst +group g_flow subtract all g_obst +112290 atoms in group g_flow +set group g_obst type 2 +Setting atom values ... + 1950 settings made for type + +mass 1 ${MASS} +mass 1 1 +mass 2 ${MASS} +mass 2 1 + +velocity g_flow create ${TEMP} 4928459 rot yes dist gaussian +velocity g_flow create 0.4 4928459 rot yes dist gaussian +velocity g_obst set 0.0 0.0 0.0 + +pair_style lj/cut 1.122462 +pair_coeff 1 1 1.0 1.0 +pair_coeff 1 2 1.0 1.0 +pair_coeff 2 2 1.0 1.0 +pair_modify shift yes + +neighbor 0.3 bin +neigh_modify delay 0 every 20 check no + +fix 1 g_flow nve +fix 2 g_flow wall/flow x ${VFLOW} ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 75 ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 75 79 + +variable dump_every equal ${nrun}/${dump_count} +variable dump_every equal 1000/${dump_count} +variable dump_every equal 1000/10 +variable thermo_every equal ${dump_every} +variable thermo_every equal 100 +variable restart_every equal ${nrun}/10 +variable restart_every equal 1000/10 + +##### uncomment for grid aggregation ##### +#variable gr_Nx equal 42 +#variable gr_Ny equal 17 +#variable gr_Nz equal 1 +#variable gr_Nevery equal ${dump_every} +#variable gr_Nrepeat equal 1 +#variable gr_Nfreq equal ${dump_every} +#fix 3 g_flow ave/grid ${gr_Nevery} ${gr_Nrepeat} ${gr_Nfreq} ${gr_Nx} ${gr_Ny} ${gr_Nz} vx vy vz density/mass norm all ave one +#compute ct_gridId g_flow property/grid ${gr_Nx} ${gr_Ny} ${gr_Nz} id +#dump dmp_grid g_flow grid ${dump_every} grid.lammpstrj c_ct_gridId:grid:data f_3:grid:data[*] +########################################## + +#dump dmp_coord all atom ${dump_every} dump.lammpstrj + +#compute ct_Temp g_flow temp/com +#thermo_style custom step temp epair emol etotal press c_ct_Temp + +#restart ${restart_every} flow.restart + +timestep 0.005 +thermo ${thermo_every} +thermo 100 +run ${nrun} +run 1000 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- fix wall/flow command: doi:10.1177/10943420231213013 + +@Article{Pavlov-etal-IJHPCA-2024, + author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod Nikolskiy and Vladimir Stegailov}, + title = {GPU-based molecular dynamics of fluid flows: Reaching for turbulence}, + journal = {The International Journal of High Performance Computing Applications}, + year = 2024, + volume = 38, + number = 1, + pages = 34-49 +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Generated 0 of 1 mixed pair_coeff terms from geometric mixing rule +Neighbor list info ... + update: every = 20 steps, delay = 0 steps, check = no + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 1.422462 + ghost atom cutoff = 1.422462 + binsize = 0.711231, bins = 281 114 34 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair lj/cut, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 26.69 | 26.69 | 26.69 Mbytes + Step Temp E_pair E_mol TotEng Press + 0 0.39317221 0 0 0.58975315 0.11795063 + 100 0.3671684 0.045118445 0 0.59586622 0.27378331 + 200 0.3732041 0.036897471 0 0.59669873 0.24917809 + 300 0.37432305 0.036501844 0 0.5979815 0.24715194 + 400 0.37603886 0.035350565 0 0.59940392 0.24480762 + 500 0.37617142 0.036949771 0 0.60120196 0.24862985 + 600 0.37751983 0.036484268 0 0.60275905 0.24784635 + 700 0.37787831 0.037327783 0 0.60414029 0.25060427 + 800 0.37959242 0.036206184 0 0.60558983 0.2476903 + 900 0.38019033 0.036874395 0 0.6071549 0.24984211 + 1000 0.38070666 0.037068948 0 0.60812395 0.25041936 +Loop time of 5.61598 on 1 procs for 1000 steps with 114240 atoms + +Performance: 76923.319 tau/day, 178.063 timesteps/s, 20.342 Matom-step/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.6351 | 2.6351 | 2.6351 | 0.0 | 46.92 +Neigh | 1.2994 | 1.2994 | 1.2994 | 0.0 | 23.14 +Comm | 0.26576 | 0.26576 | 0.26576 | 0.0 | 4.73 +Output | 0.0030531 | 0.0030531 | 0.0030531 | 0.0 | 0.05 +Modify | 1.3019 | 1.3019 | 1.3019 | 0.0 | 23.18 +Other | | 0.1107 | | | 1.97 + +Nlocal: 114240 ave 114240 max 114240 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 20119 ave 20119 max 20119 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 164018 ave 164018 max 164018 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 164018 +Ave neighs/atom = 1.4357318 +Neighbor list builds = 50 +Dangerous builds not checked +Total wall time: 0:00:05 diff --git a/examples/wall/log.7Feb24.wall.flow.g++.4 b/examples/wall/log.7Feb24.wall.flow.g++.4 new file mode 100644 index 0000000000..1efe7bb28e --- /dev/null +++ b/examples/wall/log.7Feb24.wall.flow.g++.4 @@ -0,0 +1,182 @@ +LAMMPS (21 Nov 2023 - Development - patch_21Nov2023-758-ge33590b2fc-modified) + using 1 OpenMP thread(s) per MPI task +variable nrun equal 1000 +variable dump_count equal 10 + +variable nwall equal 4 +variable w1 equal 67 +variable w2 equal 71 +variable w3 equal 75 +variable w4 equal 79 + +variable x_cylinder equal 20 +variable y_cylinder equal 17 +variable r_cylinder equal 4 + +variable MASS equal 1 +variable TEMP equal 0.4 +variable VFLOW equal 0.5 + +units lj +atom_style atomic + +lattice fcc 0.3 +Lattice spacing in x,y,z = 2.3712622 2.3712622 2.3712622 +region sim_box block 0 84 0 34 0 10 + +boundary p p p + +create_box 2 sim_box +Created orthogonal box = (0 0 0) to (199.18603 80.622915 23.712622) + 4 by 1 by 1 MPI processor grid +region reg_cylinder cylinder z ${x_cylinder} ${y_cylinder} ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 ${y_cylinder} ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 17 ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 17 4 EDGE EDGE + +create_atoms 1 box +Created 114240 atoms + using lattice units in orthogonal box = (0 0 0) to (199.18603 80.622915 23.712622) + create_atoms CPU = 0.003 seconds + +## setup obstacle ## +group g_obst region reg_cylinder +1950 atoms in group g_obst +group g_flow subtract all g_obst +112290 atoms in group g_flow +set group g_obst type 2 +Setting atom values ... + 1950 settings made for type + +mass 1 ${MASS} +mass 1 1 +mass 2 ${MASS} +mass 2 1 + +velocity g_flow create ${TEMP} 4928459 rot yes dist gaussian +velocity g_flow create 0.4 4928459 rot yes dist gaussian +velocity g_obst set 0.0 0.0 0.0 + +pair_style lj/cut 1.122462 +pair_coeff 1 1 1.0 1.0 +pair_coeff 1 2 1.0 1.0 +pair_coeff 2 2 1.0 1.0 +pair_modify shift yes + +neighbor 0.3 bin +neigh_modify delay 0 every 20 check no + +fix 1 g_flow nve +fix 2 g_flow wall/flow x ${VFLOW} ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 75 ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 75 79 + +variable dump_every equal ${nrun}/${dump_count} +variable dump_every equal 1000/${dump_count} +variable dump_every equal 1000/10 +variable thermo_every equal ${dump_every} +variable thermo_every equal 100 +variable restart_every equal ${nrun}/10 +variable restart_every equal 1000/10 + +##### uncomment for grid aggregation ##### +#variable gr_Nx equal 42 +#variable gr_Ny equal 17 +#variable gr_Nz equal 1 +#variable gr_Nevery equal ${dump_every} +#variable gr_Nrepeat equal 1 +#variable gr_Nfreq equal ${dump_every} +#fix 3 g_flow ave/grid ${gr_Nevery} ${gr_Nrepeat} ${gr_Nfreq} ${gr_Nx} ${gr_Ny} ${gr_Nz} vx vy vz density/mass norm all ave one +#compute ct_gridId g_flow property/grid ${gr_Nx} ${gr_Ny} ${gr_Nz} id +#dump dmp_grid g_flow grid ${dump_every} grid.lammpstrj c_ct_gridId:grid:data f_3:grid:data[*] +########################################## + +#dump dmp_coord all atom ${dump_every} dump.lammpstrj + +#compute ct_Temp g_flow temp/com +#thermo_style custom step temp epair emol etotal press c_ct_Temp + +#restart ${restart_every} flow.restart + +timestep 0.005 +thermo ${thermo_every} +thermo 100 +run ${nrun} +run 1000 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- fix wall/flow command: doi:10.1177/10943420231213013 + +@Article{Pavlov-etal-IJHPCA-2024, + author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod Nikolskiy and Vladimir Stegailov}, + title = {GPU-based molecular dynamics of fluid flows: Reaching for turbulence}, + journal = {The International Journal of High Performance Computing Applications}, + year = 2024, + volume = 38, + number = 1, + pages = 34-49 +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Generated 0 of 1 mixed pair_coeff terms from geometric mixing rule +Neighbor list info ... + update: every = 20 steps, delay = 0 steps, check = no + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 1.422462 + ghost atom cutoff = 1.422462 + binsize = 0.711231, bins = 281 114 34 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair lj/cut, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 8.496 | 8.496 | 8.496 Mbytes + Step Temp E_pair E_mol TotEng Press + 0 0.39317221 0 0 0.58975315 0.11795063 + 100 0.36726398 0.045386014 0 0.59627716 0.27402111 + 200 0.37384538 0.036574547 0 0.5973377 0.24836729 + 300 0.37487455 0.036519645 0 0.59882654 0.24691726 + 400 0.37591417 0.036405755 0 0.60027207 0.24700641 + 500 0.37654714 0.037008829 0 0.60182459 0.24883444 + 600 0.3778008 0.03663706 0 0.6033333 0.24874392 + 700 0.37851338 0.036714175 0 0.60447928 0.24881829 + 800 0.37984876 0.036237049 0 0.6060052 0.24843003 + 900 0.38022763 0.036847615 0 0.60718407 0.24987198 + 1000 0.38084717 0.037139994 0 0.60840575 0.25070072 +Loop time of 2.20347 on 4 procs for 1000 steps with 114240 atoms + +Performance: 196054.093 tau/day, 453.829 timesteps/s, 51.845 Matom-step/s +95.6% 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.67927 | 0.70882 | 0.73473 | 2.4 | 32.17 +Neigh | 0.32928 | 0.34467 | 0.36084 | 2.0 | 15.64 +Comm | 0.3211 | 0.36609 | 0.40741 | 6.1 | 16.61 +Output | 0.0017748 | 0.0032465 | 0.0046508 | 2.1 | 0.15 +Modify | 0.71135 | 0.74424 | 0.76001 | 2.3 | 33.78 +Other | | 0.03641 | | | 1.65 + +Nlocal: 28560 ave 29169 max 27884 min +Histogram: 1 0 0 0 0 2 0 0 0 1 +Nghost: 6452.25 ave 6546 max 6368 min +Histogram: 1 0 0 0 2 0 0 0 0 1 +Neighs: 40893 ave 42032 max 39445 min +Histogram: 1 0 0 0 1 0 0 1 0 1 + +Total # of neighbors = 163572 +Ave neighs/atom = 1.4318277 +Neighbor list builds = 50 +Dangerous builds not checked +Total wall time: 0:00:02 diff --git a/src/.gitignore b/src/.gitignore index 1e4c5b9ddb..41f4e7b614 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1023,6 +1023,8 @@ /fix_wall_colloid.h /fix_wall_ees.cpp /fix_wall_ees.h +/fix_wall_flow.cpp +/fix_wall_flow.h /fix_wall_region_ees.cpp /fix_wall_region_ees.h /fix_wall_reflect_stochastic.cpp diff --git a/src/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp similarity index 100% rename from src/fix_wall_flow.cpp rename to src/EXTRA-FIX/fix_wall_flow.cpp diff --git a/src/fix_wall_flow.h b/src/EXTRA-FIX/fix_wall_flow.h similarity index 100% rename from src/fix_wall_flow.h rename to src/EXTRA-FIX/fix_wall_flow.h From 022cedeff0b3b4ed6653a35b8da763372d9ceee0 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 12:08:36 +0300 Subject: [PATCH 20/46] Remove debug output --- src/EXTRA-FIX/fix_wall_flow.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 695b93aea8..6b42c34731 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -34,10 +34,8 @@ #include "math_const.h" #include -#include #include #include -#include using namespace LAMMPS_NS; using namespace FixConst; @@ -140,12 +138,6 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : { error->all(FLERR, "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); } - std::cout << "Walls:\n"; - for (auto w : walls) - { - std::cout << w << " "; - } - std::cout << std::endl; memory->grow(current_segment, atom->nmax, "WallFlow::current_segment"); atom->add_callback(Atom::GROW); From 5839b67d278485b9c4c8cdda2a76132d8da4049b Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 12:26:40 +0300 Subject: [PATCH 21/46] Simplify the code and remove redundant include --- src/EXTRA-FIX/fix_wall_flow.cpp | 11 +++++------ src/EXTRA-FIX/fix_wall_flow.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 6b42c34731..0bd9f162a2 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -114,17 +114,16 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : } return 0.0; }; - double scale = getscale(); + double scale = 0.0; + if(flowax == FlowAxis::AX_X) scale = domain->lattice->xlattice; + else if(flowax == FlowAxis::AX_Y) scale = domain->lattice->ylattice; + else if(flowax == FlowAxis::AX_Z) scale = domain->lattice->zlattice; if (narg - iarg == wallcount + 2) { if(strcmp(arg[narg - 2], "units") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); if (strcmp(arg[narg - 1], "box") == 0) scale = 1.0; - else if (strcmp(arg[narg - 1], "lattice") == 0) - { - scale = getscale(); - } - else error->all(FLERR, "Wrong fix wall/flow units command"); + else if (strcmp(arg[narg - 1], "lattice") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); } walls.resize(wallcount + 2); diff --git a/src/EXTRA-FIX/fix_wall_flow.h b/src/EXTRA-FIX/fix_wall_flow.h index ec9e4a4601..f4a4a69b1c 100644 --- a/src/EXTRA-FIX/fix_wall_flow.h +++ b/src/EXTRA-FIX/fix_wall_flow.h @@ -21,7 +21,7 @@ FixStyle(wall/flow,FixWallFlow); #define LMP_FIX_WALL_FLOW_H #include "fix.h" -#include + namespace LAMMPS_NS { class FixWallFlow : public Fix { From cba3c91b510debb4bd0e79bb5ce31d3dc5828cb2 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 12:29:10 +0300 Subject: [PATCH 22/46] Remove lambda --- src/EXTRA-FIX/fix_wall_flow.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 0bd9f162a2..0357d14773 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -101,19 +101,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : ++iarg; // parsing walls if(narg - iarg != wallcount && narg - iarg != wallcount + 2) error->all(FLERR, "Wrong fix wall/flow wall count"); - auto getscale = [&]() -> double { - switch (flowax) - { - case FlowAxis::AX_X: - return domain->lattice->xlattice; - case FlowAxis::AX_Y: - return domain->lattice->ylattice; - case FlowAxis::AX_Z: - return domain->lattice->zlattice; - default: return 0.0; - } - return 0.0; - }; + double scale = 0.0; if(flowax == FlowAxis::AX_X) scale = domain->lattice->xlattice; else if(flowax == FlowAxis::AX_Y) scale = domain->lattice->ylattice; From 6aad6177b0d52f2d6a6ad02763ef09275b657783 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 12:31:19 +0300 Subject: [PATCH 23/46] Remove accessing internal data of the Modify class --- src/EXTRA-FIX/fix_wall_flow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 0357d14773..704a8d854d 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -163,8 +163,9 @@ int FixWallFlow::setmask() void FixWallFlow::init() { int nrigid = 0; - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) nrigid++; + + for (auto ifix : modify->get_fix_list()) + if (ifix->rigid_flag) nrigid++; if (nrigid && comm->me == 0) error->warning(FLERR,"FixWallFlow is not compatible with rigid bodies"); From be742253e2d1bbf040b4b6a4069a217ec7335caa Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 13:05:45 +0300 Subject: [PATCH 24/46] Fix bug with the masses of the atoms --- src/EXTRA-FIX/fix_wall_flow.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 704a8d854d..bbd5d39ce3 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -205,7 +205,13 @@ void FixWallFlow::generate_velocity(int atom_i) { const int newton_iteration_count = 10; double *vel = atom->v[atom_i]; - double mass = atom->mass[atom->type[atom_i]]; + + double *prmass = atom->rmass; + double *pmass = atom->mass; + double mass = 0.0; + if(prmass) mass = prmass[atom_i]; + else mass = pmass[atom->type[atom_i]]; + const double gamma = 1.0 / std::sqrt(2.0 * kT / mass); double delta = gamma * flowvel; From c7831b29c0fb8b1f43ba27f70b0621e606710f84 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 13:28:35 +0300 Subject: [PATCH 25/46] Fix formatting issues --- src/EXTRA-FIX/fix_wall_flow.cpp | 173 ++++++++++++++-------------- src/EXTRA-FIX/fix_wall_flow.h | 2 +- src/KOKKOS/fix_wall_flow_kokkos.cpp | 122 ++++++++------------ 3 files changed, 138 insertions(+), 159 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index bbd5d39ce3..bc2ddcd137 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -23,18 +22,18 @@ #include "comm.h" #include "domain.h" #include "error.h" +#include "force.h" #include "input.h" #include "lattice.h" +#include "math_const.h" +#include "memory.h" #include "modify.h" +#include "random_mars.h" #include "update.h" #include "variable.h" -#include "random_mars.h" -#include "memory.h" -#include "force.h" -#include "math_const.h" -#include #include +#include #include using namespace LAMMPS_NS; @@ -43,24 +42,21 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ static const char cite_fix_wall_flow_c[] = - "fix wall/flow command: doi:10.1177/10943420231213013\n\n" - "@Article{Pavlov-etal-IJHPCA-2024,\n" - " author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod Nikolskiy and Vladimir Stegailov},\n" - " title = {GPU-based molecular dynamics of fluid flows: Reaching for turbulence},\n" - " journal = {The International Journal of High Performance Computing Applications},\n" - " year = 2024,\n" - " volume = 38,\n" - " number = 1,\n" - " pages = 34-49\n" - "}\n\n"; + "fix wall/flow command: doi:10.1177/10943420231213013\n\n" + "@Article{Pavlov-etal-IJHPCA-2024,\n" + " author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod " + "Nikolskiy and Vladimir Stegailov},\n" + " title = {GPU-based molecular dynamics of fluid flows: Reaching for turbulence},\n" + " journal = {The International Journal of High Performance Computing Applications},\n" + " year = 2024,\n" + " volume = 38,\n" + " number = 1,\n" + " pages = 34-49\n" + "}\n\n"; FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), - flowax(FlowAxis::AX_X), - flowvel(0.0), - flowdir(0), - rndseed(0), - current_segment(nullptr) + Fix(lmp, narg, arg), flowax(FlowAxis::AX_X), flowvel(0.0), flowdir(0), rndseed(0), + current_segment(nullptr) { if (lmp->citeme) lmp->citeme->add(cite_fix_wall_flow_c); if (narg < 9) utils::missing_cmd_args(FLERR, "fix wall/flow", error); @@ -70,60 +66,74 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : int iarg = 3; // parsing axis - if (strcmp(arg[iarg], "x") == 0) flowax = FlowAxis::AX_X; - else if (strcmp(arg[iarg],"y") == 0) flowax = FlowAxis::AX_Y; - else if (strcmp(arg[iarg],"z") == 0) flowax = FlowAxis::AX_Z; - else error->all(FLERR,"Illegal fix wall/flow argument: axis must by x or y or z, but {} specified", arg[iarg]); + if (strcmp(arg[iarg], "x") == 0) + flowax = FlowAxis::AX_X; + else if (strcmp(arg[iarg], "y") == 0) + flowax = FlowAxis::AX_Y; + else if (strcmp(arg[iarg], "z") == 0) + flowax = FlowAxis::AX_Z; + else + error->all(FLERR, "Illegal fix wall/flow argument: axis must by x or y or z, but {} specified", + arg[iarg]); ++iarg; // parsing velocity - flowvel = utils::numeric(FLERR,arg[iarg],do_abort,lmp); - if (flowvel == 0.0) error->all(FLERR,"Illegal fix wall/flow argument: velocity cannot be 0"); - if (flowvel > 0.0) flowdir = 1; - else flowdir = -1; - if(flowdir < 0) error->all(FLERR, "Illegal fix wall/flow argument: negative direction is not supported yet"); + flowvel = utils::numeric(FLERR, arg[iarg], do_abort, lmp); + if (flowvel == 0.0) error->all(FLERR, "Illegal fix wall/flow argument: velocity cannot be 0"); + if (flowvel > 0.0) + flowdir = 1; + else + flowdir = -1; + if (flowdir < 0) + error->all(FLERR, "Illegal fix wall/flow argument: negative direction is not supported yet"); ++iarg; // parsing temperature - double flowtemp = utils::numeric(FLERR,arg[iarg],do_abort,lmp); + double flowtemp = utils::numeric(FLERR, arg[iarg], do_abort, lmp); kT = lmp->force->boltz * flowtemp / force->mvv2e; ++iarg; // parsing seed - rndseed = utils::inumeric(FLERR, arg[iarg],do_abort,lmp); - if(rndseed <= 0) error->all(FLERR, "Illegal fix wall/flow argument: random seed must be positive integer"); + rndseed = utils::inumeric(FLERR, arg[iarg], do_abort, lmp); + if (rndseed <= 0) + error->all(FLERR, "Illegal fix wall/flow argument: random seed must be positive integer"); ++iarg; // parsing wall count - int wallcount = utils::inumeric(FLERR,arg[iarg],do_abort,lmp); - if(wallcount <= 0) error->all(FLERR,"Illegal fix wall/flow argument: wall count must be positive integer"); + int wallcount = utils::inumeric(FLERR, arg[iarg], do_abort, lmp); + if (wallcount <= 0) + error->all(FLERR, "Illegal fix wall/flow argument: wall count must be positive integer"); ++iarg; // parsing walls - if(narg - iarg != wallcount && narg - iarg != wallcount + 2) error->all(FLERR, "Wrong fix wall/flow wall count"); + if (narg - iarg != wallcount && narg - iarg != wallcount + 2) + error->all(FLERR, "Wrong fix wall/flow wall count"); double scale = 0.0; - if(flowax == FlowAxis::AX_X) scale = domain->lattice->xlattice; - else if(flowax == FlowAxis::AX_Y) scale = domain->lattice->ylattice; - else if(flowax == FlowAxis::AX_Z) scale = domain->lattice->zlattice; + if (flowax == FlowAxis::AX_X) + scale = domain->lattice->xlattice; + else if (flowax == FlowAxis::AX_Y) + scale = domain->lattice->ylattice; + else if (flowax == FlowAxis::AX_Z) + scale = domain->lattice->zlattice; - if (narg - iarg == wallcount + 2) - { - if(strcmp(arg[narg - 2], "units") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); - if (strcmp(arg[narg - 1], "box") == 0) scale = 1.0; - else if (strcmp(arg[narg - 1], "lattice") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); + if (narg - iarg == wallcount + 2) { + if (strcmp(arg[narg - 2], "units") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); + if (strcmp(arg[narg - 1], "box") == 0) + scale = 1.0; + else if (strcmp(arg[narg - 1], "lattice") != 0) + error->all(FLERR, "Wrong fix wall/flow units command"); } walls.resize(wallcount + 2); walls.front() = domain->boxlo[flowax]; - for (size_t w = 1; w <= wallcount; ++w, ++iarg) - { - walls[w] = utils::numeric(FLERR,arg[iarg],do_abort,lmp) * scale; + for (size_t w = 1; w <= wallcount; ++w, ++iarg) { + walls[w] = utils::numeric(FLERR, arg[iarg], do_abort, lmp) * scale; } walls.back() = domain->boxhi[flowax]; - if (!std::is_sorted(walls.begin(), walls.end(), std::less_equal())) - { - error->all(FLERR, "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); + if (!std::is_sorted(walls.begin(), walls.end(), std::less_equal())) { + error->all(FLERR, + "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); } memory->grow(current_segment, atom->nmax, "WallFlow::current_segment"); @@ -133,7 +143,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : maxexchange = 1; random = new RanMars(lmp, rndseed + comm->me); - } +} /* ---------------------------------------------------------------------- */ @@ -168,10 +178,9 @@ void FixWallFlow::init() if (ifix->rigid_flag) nrigid++; if (nrigid && comm->me == 0) - error->warning(FLERR,"FixWallFlow is not compatible with rigid bodies"); + error->warning(FLERR, "FixWallFlow is not compatible with rigid bodies"); - for (int i = 0; i < atom->nlocal; ++i) - { + for (int i = 0; i < atom->nlocal; ++i) { double pos = atom->x[i][flowax]; current_segment[i] = compute_current_segment(pos); } @@ -185,18 +194,13 @@ void FixWallFlow::end_of_step() int *mask = atom->mask; int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; ++i) - { - if (mask[i] & groupbit) - { - double pos = x[i][flowax]; - int prev_segment = current_segment[i]; - current_segment[i] = compute_current_segment(pos); + for (int i = 0; i < nlocal; ++i) { + if (mask[i] & groupbit) { + double pos = x[i][flowax]; + int prev_segment = current_segment[i]; + current_segment[i] = compute_current_segment(pos); - if (prev_segment != current_segment[i]) - { - generate_velocity(i); - } + if (prev_segment != current_segment[i]) { generate_velocity(i); } } } } @@ -209,31 +213,32 @@ void FixWallFlow::generate_velocity(int atom_i) double *prmass = atom->rmass; double *pmass = atom->mass; double mass = 0.0; - if(prmass) mass = prmass[atom_i]; - else mass = pmass[atom->type[atom_i]]; + if (prmass) + mass = prmass[atom_i]; + else + mass = pmass[atom->type[atom_i]]; const double gamma = 1.0 / std::sqrt(2.0 * kT / mass); double delta = gamma * flowvel; - const double edd = std::exp(-delta*delta) / MathConst::MY_PIS + delta * std::erf(delta); + const double edd = std::exp(-delta * delta) / MathConst::MY_PIS + delta * std::erf(delta); const double probability_threshold = 0.5f * (1.f + delta / edd); double direction = 1.0; - if (random->uniform() > probability_threshold) - { - delta = -delta; - direction = -direction; + if (random->uniform() > probability_threshold) { + delta = -delta; + direction = -direction; } const double xi_0 = random->uniform(); const double F_inf = edd + delta; const double xi = xi_0 * F_inf; - const double x_0 = (std::sqrt(delta*delta + 2) - delta) * 0.5; + const double x_0 = (std::sqrt(delta * delta + 2) - delta) * 0.5; double x = x_0; - for (int i = 0; i < newton_iteration_count; ++i) - { - x -= (std::exp(x*x) * MathConst::MY_PIS * (xi - delta * std::erfc(x)) - 1.0) / (x + delta) * 0.5; + for (int i = 0; i < newton_iteration_count; ++i) { + x -= (std::exp(x * x) * MathConst::MY_PIS * (xi - delta * std::erfc(x)) - 1.0) / (x + delta) * + 0.5; } const double nu = x + delta; @@ -247,14 +252,10 @@ void FixWallFlow::generate_velocity(int atom_i) int FixWallFlow::compute_current_segment(double pos) const { int result = 0; - for (; result < walls.size()-1; ++result) - { - if (pos >= walls[result] && pos < walls[result + 1]) - { - return result; - } + for (; result < walls.size() - 1; ++result) { + if (pos >= walls[result] && pos < walls[result + 1]) { return result; } } - return -1; // -1 is "out of box" region + return -1; // -1 is "out of box" region } void FixWallFlow::grow_arrays(int nmax) @@ -267,13 +268,13 @@ void FixWallFlow::copy_arrays(int i, int j, int) current_segment[j] = current_segment[i]; } -int FixWallFlow::pack_exchange(int i, double* buf) +int FixWallFlow::pack_exchange(int i, double *buf) { buf[0] = static_cast(current_segment[i]); return 1; } -int FixWallFlow::unpack_exchange(int i, double* buf) +int FixWallFlow::unpack_exchange(int i, double *buf) { current_segment[i] = static_cast(buf[0]); return 1; diff --git a/src/EXTRA-FIX/fix_wall_flow.h b/src/EXTRA-FIX/fix_wall_flow.h index f4a4a69b1c..8e16a850b1 100644 --- a/src/EXTRA-FIX/fix_wall_flow.h +++ b/src/EXTRA-FIX/fix_wall_flow.h @@ -26,7 +26,7 @@ namespace LAMMPS_NS { class FixWallFlow : public Fix { public: - enum FlowAxis {AX_X = 0, AX_Y = 1, AX_Z = 2}; + enum FlowAxis { AX_X = 0, AX_Y = 1, AX_Z = 2 }; FixWallFlow(class LAMMPS *, int, char **); ~FixWallFlow() override; diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index a143578fdc..f9d11efe81 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -19,18 +18,16 @@ #include "fix_wall_flow_kokkos.h" #include "atom_kokkos.h" -#include "memory_kokkos.h" -#include "math_const.h" #include "atom_masks.h" #include "force.h" +#include "math_const.h" +#include "memory_kokkos.h" #include -// clang-format off - using namespace LAMMPS_NS; -template +template FixWallFlowKokkos::FixWallFlowKokkos(LAMMPS *lmp, int narg, char **arg) : FixWallFlow(lmp, narg, arg), rand_pool(rndseed + comm->me) { @@ -47,22 +44,17 @@ FixWallFlowKokkos::FixWallFlowKokkos(LAMMPS *lmp, int narg, char **a d_walls = d_walls_t("FixWallFlowKokkos::walls", walls.size()); auto h_walls = Kokkos::create_mirror_view(d_walls); - for (int i = 0; i < walls.size(); ++i) - { - h_walls(i) = walls[i]; - } + for (int i = 0; i < walls.size(); ++i) { h_walls(i) = walls[i]; } Kokkos::deep_copy(d_walls, h_walls); } -template -FixWallFlowKokkos::~FixWallFlowKokkos() +template FixWallFlowKokkos::~FixWallFlowKokkos() { if (copymode) return; memoryKK->destroy_kokkos(k_current_segment, current_segment); } -template -void FixWallFlowKokkos::init() +template void FixWallFlowKokkos::init() { atomKK->sync(execution_space, datamask_read); k_current_segment.template sync(); @@ -83,8 +75,7 @@ KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWall d_current_segment(i) = compute_current_segment_kk(pos); } -template -void FixWallFlowKokkos::end_of_step() +template void FixWallFlowKokkos::end_of_step() { atomKK->sync(execution_space, datamask_read); k_current_segment.template sync(); @@ -111,26 +102,20 @@ void FixWallFlowKokkos::end_of_step() template template -KOKKOS_INLINE_FUNCTION -void FixWallFlowKokkos::operator()(TagFixWallFlowEndOfStep, +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWallFlowEndOfStep, const int &atom_i) const { - if (d_mask[atom_i] & groupbit) - { + if (d_mask[atom_i] & groupbit) { double pos = d_x(atom_i, flowax); int prev_segment = d_current_segment(atom_i); d_current_segment(atom_i) = compute_current_segment_kk(pos); - if (prev_segment != d_current_segment(atom_i)) - { - generate_velocity_kk(atom_i); - } + if (prev_segment != d_current_segment(atom_i)) { generate_velocity_kk(atom_i); } } } -template -template -KOKKOS_INLINE_FUNCTION -void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const +template +template +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const { const int newton_iteration_count = 10; double mass = get_mass(MTag(), atom_i); @@ -163,15 +148,17 @@ void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const const double v = nu / gamma; d_v(atom_i, flowax) = v * direction; - d_v(atom_i, (flowax + 1) % 3) = /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); - d_v(atom_i, (flowax + 2) % 3) = /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); + d_v(atom_i, (flowax + 1) % 3) = + /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); + d_v(atom_i, (flowax + 2) % 3) = + /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); rand_pool.free_state(rand_gen); } template -KOKKOS_INLINE_FUNCTION -int FixWallFlowKokkos::compute_current_segment_kk(double pos) const +KOKKOS_INLINE_FUNCTION int +FixWallFlowKokkos::compute_current_segment_kk(double pos) const { int result = 0; for (; result < d_walls.extent(0) - 1; ++result) { @@ -180,9 +167,7 @@ int FixWallFlowKokkos::compute_current_segment_kk(double pos) const return -1; // -1 is "out of box" region } - -template -void FixWallFlowKokkos::grow_arrays(int nmax) +template void FixWallFlowKokkos::grow_arrays(int nmax) { k_current_segment.template sync(); memoryKK->grow_kokkos(k_current_segment, current_segment, nmax, "WallFlowKK::current_segment"); @@ -192,8 +177,7 @@ void FixWallFlowKokkos::grow_arrays(int nmax) h_current_segment = k_current_segment.template view(); } -template -void FixWallFlowKokkos::copy_arrays(int i, int j, int) +template void FixWallFlowKokkos::copy_arrays(int i, int j, int) { k_current_segment.template sync(); h_current_segment(j) = h_current_segment(i); @@ -204,7 +188,7 @@ void FixWallFlowKokkos::copy_arrays(int i, int j, int) sort local atom-based arrays ------------------------------------------------------------------------- */ -template +template void FixWallFlowKokkos::sort_kokkos(Kokkos::BinSort &Sorter) { // always sort on the device @@ -216,33 +200,31 @@ void FixWallFlowKokkos::sort_kokkos(Kokkos::BinSort -int FixWallFlowKokkos::pack_exchange(int i, double *buf) +template int FixWallFlowKokkos::pack_exchange(int i, double *buf) { k_current_segment.sync_host(); buf[0] = static_cast(h_current_segment(i)); return 1; } -template -KOKKOS_INLINE_FUNCTION -void FixWallFlowKokkos::operator()(TagFixWallFlowPackExchange, const int &mysend) const { +template +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWallFlowPackExchange, + const int &mysend) const +{ const int send_i = d_sendlist(mysend); const int segment = d_current_segment(send_i); d_buf(mysend) = static_cast(segment); const int copy_i = d_copylist(mysend); - if (copy_i > -1) { - d_current_segment(send_i) = d_current_segment(copy_i); - } + if (copy_i > -1) { d_current_segment(send_i) = d_current_segment(copy_i); } } template -int FixWallFlowKokkos::pack_exchange_kokkos( - const int &nsend, DAT::tdual_xfloat_2d &k_buf, - DAT::tdual_int_1d k_sendlist, - DAT::tdual_int_1d k_copylist, - ExecutionSpace space) +int FixWallFlowKokkos::pack_exchange_kokkos(const int &nsend, + DAT::tdual_xfloat_2d &k_buf, + DAT::tdual_int_1d k_sendlist, + DAT::tdual_int_1d k_copylist, + ExecutionSpace space) { k_current_segment.template sync(); @@ -253,13 +235,13 @@ int FixWallFlowKokkos::pack_exchange_kokkos( d_sendlist = k_sendlist.view(); d_copylist = k_copylist.view(); - d_buf = typename ArrayTypes::t_xfloat_1d_um( - k_buf.template view().data(), - k_buf.extent(0)*k_buf.extent(1)); + d_buf = typename ArrayTypes::t_xfloat_1d_um(k_buf.template view().data(), + k_buf.extent(0) * k_buf.extent(1)); copymode = 1; - Kokkos::parallel_for(Kokkos::RangePolicy(0, nsend), *this); + Kokkos::parallel_for(Kokkos::RangePolicy(0, nsend), + *this); copymode = 0; @@ -269,8 +251,7 @@ int FixWallFlowKokkos::pack_exchange_kokkos( return nsend; } -template -int FixWallFlowKokkos::unpack_exchange(int i, double *buf) +template int FixWallFlowKokkos::unpack_exchange(int i, double *buf) { k_current_segment.sync_host(); h_current_segment(i) = static_cast(buf[0]); @@ -278,30 +259,27 @@ int FixWallFlowKokkos::unpack_exchange(int i, double *buf) return 1; } -template -KOKKOS_INLINE_FUNCTION -void FixWallFlowKokkos::operator()(TagFixWallFlowUnpackExchange, const int &i) const +template +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWallFlowUnpackExchange, + const int &i) const { int index = d_indices(i); - if (index > -1) { - d_current_segment(index) = static_cast(d_buf(i)); - } + if (index > -1) { d_current_segment(index) = static_cast(d_buf(i)); } } template -void FixWallFlowKokkos::unpack_exchange_kokkos( - DAT::tdual_xfloat_2d &k_buf, - DAT::tdual_int_1d &k_indices, int nrecv, - int /*nrecv1*/, int /*nextrarecv1*/, - ExecutionSpace space) +void FixWallFlowKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf, + DAT::tdual_int_1d &k_indices, int nrecv, + int /*nrecv1*/, int /*nextrarecv1*/, + ExecutionSpace space) { - d_buf = typename ArrayTypes::t_xfloat_1d_um( - k_buf.template view().data(), - k_buf.extent(0)*k_buf.extent(1)); + d_buf = typename ArrayTypes::t_xfloat_1d_um(k_buf.template view().data(), + k_buf.extent(0) * k_buf.extent(1)); d_indices = k_indices.view(); copymode = 1; - Kokkos::parallel_for(Kokkos::RangePolicy(0,nrecv),*this); + Kokkos::parallel_for(Kokkos::RangePolicy(0, nrecv), + *this); copymode = 0; k_current_segment.template modify(); From fb1e6610edbdf63702d81a720f3c94eb41926f2f Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Mon, 19 Feb 2024 10:36:15 -0700 Subject: [PATCH 26/46] edits of doc page for clarity --- doc/src/fix_wall_flow.rst | 118 ++++++++++++++++++++------------ src/EXTRA-FIX/fix_wall_flow.cpp | 15 +++- src/EXTRA-FIX/fix_wall_flow.h | 1 + 3 files changed, 89 insertions(+), 45 deletions(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index 464021ff52..5fc9f5367c 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -11,24 +11,23 @@ Syntax .. code-block:: LAMMPS - fix ID group-ID wall/flow ax vf T seed N coords ... keyword value + fix ID group-ID wall/flow axis vflow T seed N coords ... keyword value * ID, group-ID are documented in :doc:`fix ` command * wall/flow = style name of this fix command -* ax = flow axis (*x*, *y*, or *z* character) -* vf = *ax* component of generated flow velocity +* axis = flow axis (*x*, *y*, or *z*) +* vflow = generated flow velocity in *axis* direction (velocity units) * T = flow temperature (temperature units) * seed = random seed for stochasticity (positive integer) -* N = number of walls (positive integer) -* coords = set of N wall coordinates (box units) along *ax* axis arranged in ascending order. Note that an additional implicit wall is introduced at the boundary of the simulation domain, so the resulting system always has N+1 walls. - +* N = number of walls +* coords = list of N wall positions along the *axis* direction in ascending order (distance units) * zero or more keyword/value pairs may be appended * keyword = *units* .. parsed-literal:: *units* value = *lattice* or *box* - *lattice* = the wall positions are defined in lattice units + *lattice* = wall positions are defined in lattice units *box* = the wall positions are defined in simulation box units Examples @@ -36,65 +35,96 @@ Examples .. code-block:: LAMMPS - fix 1 g_flow wall/flow x ${VFLOW} ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} - fix 2 all wall/flow 0.4 0.2 3 1 400 + fix 1 all wall/flow x 0.4 1.5 593894 4 2.0 4.0 6.0 8.0 Description """"""""""" .. versionadded:: TBD -This fix implements flow boundary conditions (FBC) introduced in :ref:`(Pavlov1) ` and :ref:`(Pavlov2) `. -The goal is to generate a stationary flow with a shifted Maxwell velocity distribution: +This fix implements flow boundary conditions (FBC) introduced in +:ref:`(Pavlov1) ` and :ref:`(Pavlov2) `. +The goal is to generate a stationary flow with a shifted Maxwell +velocity distribution: .. math:: - f_z(v_z) \propto \exp{\left(-\frac{m (v_z-v_{\text{flow}})^2}{2 k T}\right)} + f_a(v_a) \propto \exp{\left(-\frac{m (v_a-v_{\text{flow}})^2}{2 kB T}\right)} -This is achieved by reassigning the velocity of each particle that passes a wall. -Such reassigning represents an emission of a new particle into the system with -simultaneous removal of a particle with the same position. -The velocity components parallel to the wall are re-assigned according -to the Maxwell velocity distribution. The perpendicular component is assigned -according to the following velocity distribution: +where :math:`v_a` is the component of velocity along the specified +*axis* argument (a = x,y,z), :math:`v_{\text{flow}}` is the flow +velocity specified as the *vflow* argument, *T* is the specified flow +temperature, *m* is the particle mass, and *kB* is the Boltzmann +constant. + +This is achieved by defining a series of *N* transparent walls along +the flow *axis* direction. Each wall is at the specified position +listed in the *coords* argument. Note that an additional transparent +wall is defined by the code at the boundary of the (periodic) +simulation domain in the *axis* direction. So there are effectively +N+1 walls. + +Each time a particle in the specified group passes through one of the +transparent walls, its velocity is re-assigned. Particles not in the +group do not interact with the wall. + +Conceptually, the velocity re-assignment represents creation of a new +particle within the system with simultaneous removal of the particle +which passed through the wall. The velocity components in directions +parallel to the wall are re-assigned according to the standard Maxwell +velocity distribution for the specified temperature *T*. The velocity +component perpendicular to the wall is re-assigned according to the +shifted Maxwell distribution defined above: .. math:: - f_{\text{z generated}}(v_z) \propto v_z f_z(v_z) + f_{\text{a generated}}(v_a) \propto v_a f_a(v_a) -It can be shown that in an ideal-gas scenario this makes the velocity -distribution of particles between walls exactly as desired. +It can be shown that for an ideal-gas scenario this procedure makes +the velocity distribution of particles between walls exactly as +desired. -Since in most cases simulated systems are not ideal gas, -the need for multiple walls might arise, as a single wall may not be -sufficient for maintaining a stationary flow without congestion -manifesting as areas with increased density located upstream from static obstacles. +Since in most cases simulated systems are not an ideal gas, multiple +walls can be defined, since a single wall may not be sufficient for +maintaining a stationary flow without "congestion" which can manifest +itself as regions in the flow with increased particle density located +upstream from static obstacles. -For the same reason, the actual temperature and velocity of the generated -flow may differ from ones requested. The degree of such discrepancy is determined -by how different from the ideal gas the simulated system is. Therefore, a calibration procedure is required for each system as described in :ref:`(Pavlov) `. +For the same reason, the actual temperature and velocity of the +generated flow may differ from what is requested. The degree of +discrepancy is determined by how different from an ideal gas the +simulated system is. Therefore, a calibration procedure may be +required for such a system as described in :ref:`(Pavlov) +`. -The interactions between particles on different sides of a wall are not disabled or neglected and the -particle positions are not affected by the velocity reassignment. -This removes the need to modify the force field to work correctly in cases when a particle is close -to a wall (for example, if particle positions were uniformly redistributed across the surface of the wall, -two particles could end up too close to each other, potentially causing the simulation to explode). -However due to this compromise, some collective phenomena such as areas with increased/decreased density -or collective movements are not fully removed when particles cross a wall. -This unwanted consequence can also be potentially mitigated by using more than one wall. +Note that the interactions between particles on different sides of a +transparent wall are not disabled or neglected. Likewise particle +positions are not altered by the velocity reassignment. This removes +the need to modify the force field to work correctly in cases when a +particle is close to a wall. +For example, if particle positions were uniformly redistributed across +the surface of a wall, two particles could end up too close to each +other, potentially causing the simulation to explode. However due to +this compromise, some collective phenomena such as regions with +increased/decreased density or collective movements are not fully +removed when particles cross a wall. This unwanted consequence can +also be potentially mitigated by using more multiple walls. ----------- +.. note:: -Note that when high flow velocity is reached, a lost atoms error may -occur (see :doc:`error messages `). -If this message appears when using this fix, you can, for example, reduce the frequency of the -neighbor list rebuild via :doc:`neigh_modify ` command. + When the specified flow has a high velocity, a lost atoms error can + occur (see :doc:`error messages `). If this + happens, you should ensure the checks for neighbor list rebuilds, + set via the :doc:`neigh_modify ` command, are as + conservative as possible (every timestep if needed). Those are the + default settings. Restart, fix_modify, output, run start/stop, minimize info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" -No information about this fix is written to :doc:`binary restart files `. +No information about this fix is written to :doc:`binary restart files +`. None of the :doc:`fix_modify ` options are relevant to this fix. @@ -114,8 +144,8 @@ Fix *wall_flow* is part of the EXTRA-FIX package. It is only enabled if LAMMPS was built with that package. See the :doc:`Build package ` page for more info. -Flow boundary conditions should not be used with rigid bodies such as those -defined by a "fix rigid" command. +Flow boundary conditions should not be used with rigid bodies such as +those defined by a "fix rigid" command. Related commands """""""""""""""" diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index bc2ddcd137..afa0a4e4bd 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -200,11 +200,14 @@ void FixWallFlow::end_of_step() int prev_segment = current_segment[i]; current_segment[i] = compute_current_segment(pos); - if (prev_segment != current_segment[i]) { generate_velocity(i); } + if (prev_segment != current_segment[i]) + generate_velocity(i); } } } +/* ---------------------------------------------------------------------- */ + void FixWallFlow::generate_velocity(int atom_i) { const int newton_iteration_count = 10; @@ -249,6 +252,8 @@ void FixWallFlow::generate_velocity(int atom_i) vel[(flowax + 2) % 3] = random->gaussian() / (gamma * MathConst::MY_SQRT2); } +/* ---------------------------------------------------------------------- */ + int FixWallFlow::compute_current_segment(double pos) const { int result = 0; @@ -258,22 +263,30 @@ int FixWallFlow::compute_current_segment(double pos) const return -1; // -1 is "out of box" region } +/* ---------------------------------------------------------------------- */ + void FixWallFlow::grow_arrays(int nmax) { memory->grow(current_segment, nmax, "WallFlow::current_segment"); } +/* ---------------------------------------------------------------------- */ + void FixWallFlow::copy_arrays(int i, int j, int) { current_segment[j] = current_segment[i]; } +/* ---------------------------------------------------------------------- */ + int FixWallFlow::pack_exchange(int i, double *buf) { buf[0] = static_cast(current_segment[i]); return 1; } +/* ---------------------------------------------------------------------- */ + int FixWallFlow::unpack_exchange(int i, double *buf) { current_segment[i] = static_cast(buf[0]); diff --git a/src/EXTRA-FIX/fix_wall_flow.h b/src/EXTRA-FIX/fix_wall_flow.h index 8e16a850b1..0379c03783 100644 --- a/src/EXTRA-FIX/fix_wall_flow.h +++ b/src/EXTRA-FIX/fix_wall_flow.h @@ -50,6 +50,7 @@ class FixWallFlow : public Fix { int rndseed; class RanMars *random; int *current_segment; + int compute_current_segment(double pos) const; void generate_velocity(int i); }; From ec0535172c55c7bfac812ab5cab123bb5e11be90 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 19 Feb 2024 12:54:59 -0500 Subject: [PATCH 27/46] whitespace --- src/EXTRA-FIX/fix_wall_flow.cpp | 4 ++-- src/EXTRA-FIX/fix_wall_flow.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index afa0a4e4bd..586cfa7382 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -17,6 +17,7 @@ ------------------------------------------------------------------------- */ #include "fix_wall_flow.h" + #include "atom.h" #include "citeme.h" #include "comm.h" @@ -200,8 +201,7 @@ void FixWallFlow::end_of_step() int prev_segment = current_segment[i]; current_segment[i] = compute_current_segment(pos); - if (prev_segment != current_segment[i]) - generate_velocity(i); + if (prev_segment != current_segment[i]) generate_velocity(i); } } } diff --git a/src/EXTRA-FIX/fix_wall_flow.h b/src/EXTRA-FIX/fix_wall_flow.h index 0379c03783..6a662f3d94 100644 --- a/src/EXTRA-FIX/fix_wall_flow.h +++ b/src/EXTRA-FIX/fix_wall_flow.h @@ -50,7 +50,7 @@ class FixWallFlow : public Fix { int rndseed; class RanMars *random; int *current_segment; - + int compute_current_segment(double pos) const; void generate_velocity(int i); }; From e20ea968b930184bec9eb0d273caee48026f88fc Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Wed, 21 Feb 2024 20:49:19 +0300 Subject: [PATCH 28/46] Add some clarifications to the doc --- doc/src/fix_wall_flow.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index 5fc9f5367c..b40ba9697f 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -66,7 +66,10 @@ N+1 walls. Each time a particle in the specified group passes through one of the transparent walls, its velocity is re-assigned. Particles not in the -group do not interact with the wall. +group do not interact with the wall. This can be used, for example, to +add obstacles composed of atoms, or to simulate a solution of complex +molecules in a one-atom liquid (note that the fix has been tested for +one-atom systems only). Conceptually, the velocity re-assignment represents creation of a new particle within the system with simultaneous removal of the particle @@ -147,6 +150,10 @@ if LAMMPS was built with that package. See the :doc:`Build package Flow boundary conditions should not be used with rigid bodies such as those defined by a "fix rigid" command. +This fix can only be used with periodic boundary conditions along the +flow axis. The size of the box in this direction must not change. Also, +the fix is designed to work only in an orthogonal simulation box. + Related commands """""""""""""""" From 0f34c1ec6e49dbc34c398b142db88259b550f701 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Wed, 21 Feb 2024 21:16:21 +0300 Subject: [PATCH 29/46] Add check for triclinic and periodic boundary --- src/EXTRA-FIX/fix_wall_flow.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 586cfa7382..15b82b45b8 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -62,6 +62,9 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : if (lmp->citeme) lmp->citeme->add(cite_fix_wall_flow_c); if (narg < 9) utils::missing_cmd_args(FLERR, "fix wall/flow", error); + if (domain->triclinic != 0) + error->all(FLERR, "Fix wall/flow cannot be used with triclinic simulation box"); + dynamic_group_allow = 1; bool do_abort = false; @@ -77,6 +80,10 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR, "Illegal fix wall/flow argument: axis must by x or y or z, but {} specified", arg[iarg]); + if (domain->periodicity[flowax] != 1) + error->all(FLERR, + "Fix wall/flow cannot be used with a non-periodic boundary along the flow axis"); + ++iarg; // parsing velocity flowvel = utils::numeric(FLERR, arg[iarg], do_abort, lmp); @@ -137,6 +144,12 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); } + if (std::adjacent_find(walls.begin(), walls.end()) != walls.end()) { + error->all(FLERR, + "Wrong fix wall/flow wall coordinates: some walls have the same coordinates or lie " + "on the boundary"); + } + memory->grow(current_segment, atom->nmax, "WallFlow::current_segment"); atom->add_callback(Atom::GROW); if (restart_peratom) atom->add_callback(Atom::RESTART); From 6ac24c297a43124f0d0c5ddf97b3a37768bfb0b1 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Thu, 22 Feb 2024 11:47:53 +0300 Subject: [PATCH 30/46] Add check for varying box size --- src/EXTRA-FIX/fix_wall_flow.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 15b82b45b8..629d2ad452 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -187,12 +187,34 @@ int FixWallFlow::setmask() void FixWallFlow::init() { int nrigid = 0; - - for (auto ifix : modify->get_fix_list()) + int box_change_flowax = 0; + for (auto ifix : modify->get_fix_list()) { if (ifix->rigid_flag) nrigid++; + switch (flowax) { + case FlowAxis::AX_X: + if (ifix->box_change & Fix::BOX_CHANGE_X) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_XY) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_XZ) box_change_flowax++; + break; + case FlowAxis::AX_Y: + if (ifix->box_change & Fix::BOX_CHANGE_Y) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_YZ) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_XY) box_change_flowax++; + break; + case FlowAxis::AX_Z: + if (ifix->box_change & Fix::BOX_CHANGE_Z) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_YZ) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_XZ) box_change_flowax++; + break; + } + } if (nrigid && comm->me == 0) error->warning(FLERR, "FixWallFlow is not compatible with rigid bodies"); + if (box_change_flowax && comm->me == 0) + error->warning( + FLERR, + "FixWallFlow is not compatible with simulation box size changing along flow direction"); for (int i = 0; i < atom->nlocal; ++i) { double pos = atom->x[i][flowax]; From f1a5dd0479cecfa3ff8e84b2f3379b957224a905 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Thu, 22 Feb 2024 12:28:23 +0300 Subject: [PATCH 31/46] Change warnings to errors --- src/EXTRA-FIX/fix_wall_flow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 629d2ad452..49a8a2eb9b 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -210,9 +210,9 @@ void FixWallFlow::init() } if (nrigid && comm->me == 0) - error->warning(FLERR, "FixWallFlow is not compatible with rigid bodies"); + error->all(FLERR, "FixWallFlow is not compatible with rigid bodies"); if (box_change_flowax && comm->me == 0) - error->warning( + error->all( FLERR, "FixWallFlow is not compatible with simulation box size changing along flow direction"); From 86d306b50239d9619cb5f8179956e376b18659d6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 04:40:55 -0500 Subject: [PATCH 32/46] avoid excessive copies --- src/EXTRA-FIX/fix_wall_flow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 49a8a2eb9b..add0b51ca4 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -188,7 +188,7 @@ void FixWallFlow::init() { int nrigid = 0; int box_change_flowax = 0; - for (auto ifix : modify->get_fix_list()) { + for (const auto &ifix : modify->get_fix_list()) { if (ifix->rigid_flag) nrigid++; switch (flowax) { case FlowAxis::AX_X: From 6af4dac2e572e76a74a0acde88e1514e5242431c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 04:41:16 -0500 Subject: [PATCH 33/46] Error::all() must be called by all MPI ranks --- src/EXTRA-FIX/fix_wall_flow.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index add0b51ca4..b6634aa87c 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -209,12 +209,11 @@ void FixWallFlow::init() } } - if (nrigid && comm->me == 0) - error->all(FLERR, "FixWallFlow is not compatible with rigid bodies"); - if (box_change_flowax && comm->me == 0) + if (nrigid) error->all(FLERR, "Fix wall/flow is not compatible with rigid bodies"); + if (box_change_flowax) error->all( FLERR, - "FixWallFlow is not compatible with simulation box size changing along flow direction"); + "Fix wall/flow is not compatible with simulation box size changing along flow direction"); for (int i = 0; i < atom->nlocal; ++i) { double pos = atom->x[i][flowax]; From 5cadcbfd6849fdbd160d029e53fd6fb22a6bf4b7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 04:51:35 -0500 Subject: [PATCH 34/46] silence compiler warnings --- src/EXTRA-FIX/fix_wall_flow.cpp | 4 ++-- src/KOKKOS/fix_wall_flow_kokkos.cpp | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index b6634aa87c..f194a4076a 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -135,7 +135,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : walls.resize(wallcount + 2); walls.front() = domain->boxlo[flowax]; - for (size_t w = 1; w <= wallcount; ++w, ++iarg) { + for (int w = 1; w <= wallcount; ++w, ++iarg) { walls[w] = utils::numeric(FLERR, arg[iarg], do_abort, lmp) * scale; } walls.back() = domain->boxhi[flowax]; @@ -291,7 +291,7 @@ void FixWallFlow::generate_velocity(int atom_i) int FixWallFlow::compute_current_segment(double pos) const { int result = 0; - for (; result < walls.size() - 1; ++result) { + for (; result < (int)walls.size() - 1; ++result) { if (pos >= walls[result] && pos < walls[result + 1]) { return result; } } return -1; // -1 is "out of box" region diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index f9d11efe81..b6b3f7c096 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -23,8 +23,6 @@ #include "math_const.h" #include "memory_kokkos.h" -#include - using namespace LAMMPS_NS; template @@ -44,7 +42,7 @@ FixWallFlowKokkos::FixWallFlowKokkos(LAMMPS *lmp, int narg, char **a d_walls = d_walls_t("FixWallFlowKokkos::walls", walls.size()); auto h_walls = Kokkos::create_mirror_view(d_walls); - for (int i = 0; i < walls.size(); ++i) { h_walls(i) = walls[i]; } + for (int i = 0; i < (int) walls.size(); ++i) h_walls(i) = walls[i]; Kokkos::deep_copy(d_walls, h_walls); } @@ -161,7 +159,7 @@ KOKKOS_INLINE_FUNCTION int FixWallFlowKokkos::compute_current_segment_kk(double pos) const { int result = 0; - for (; result < d_walls.extent(0) - 1; ++result) { + for (; result < (int) d_walls.extent(0) - 1; ++result) { if (pos >= d_walls[result] && pos < d_walls[result + 1]) { return result; } } return -1; // -1 is "out of box" region @@ -224,7 +222,7 @@ int FixWallFlowKokkos::pack_exchange_kokkos(const int &nsend, DAT::tdual_xfloat_2d &k_buf, DAT::tdual_int_1d k_sendlist, DAT::tdual_int_1d k_copylist, - ExecutionSpace space) + ExecutionSpace /*space*/) { k_current_segment.template sync(); @@ -271,7 +269,7 @@ template void FixWallFlowKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf, DAT::tdual_int_1d &k_indices, int nrecv, int /*nrecv1*/, int /*nextrarecv1*/, - ExecutionSpace space) + ExecutionSpace /*space*/) { d_buf = typename ArrayTypes::t_xfloat_1d_um(k_buf.template view().data(), k_buf.extent(0) * k_buf.extent(1)); From 71e0d506e71ab7453ba328984b9b0c534d37266c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 04:56:27 -0500 Subject: [PATCH 35/46] spelling --- doc/utils/sphinx-config/false_positives.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 6106a1638c..2ec10d0e80 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -3888,6 +3888,7 @@ Verstraelen ves vf vflag +vflow vfrac vhi vibrational From d6d9a91126a39932564630be9935689dbdcffaa2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 09:13:21 -0500 Subject: [PATCH 36/46] add rebomos potential with examples and unit test --- doc/src/Commands_pair.rst | 1 + doc/src/pair_rebomos.rst | 109 ++ doc/src/pair_style.rst | 1 + examples/threebody/MoS.rebomos | 1 + examples/threebody/in.mos2-bulk | 35 + examples/threebody/in.mos2.rebomos | 31 + .../threebody/log.22Feb24.mos2-bulk.g++.1 | 86 ++ .../threebody/log.22Feb24.mos2-bulk.g++.4 | 86 ++ .../threebody/log.22Feb24.mos2.rebomos.g++.1 | 96 ++ .../threebody/log.22Feb24.mos2.rebomos.g++.4 | 96 ++ potentials/MoS.rebomos | 65 + potentials/README | 4 +- src/.gitignore | 2 + src/MANYBODY/pair_rebomos.cpp | 1161 +++++++++++++++++ src/MANYBODY/pair_rebomos.h | 219 ++++ .../tests/manybody-pair-rebomos.yaml | 126 ++ 16 files changed, 2118 insertions(+), 1 deletion(-) create mode 100644 doc/src/pair_rebomos.rst create mode 120000 examples/threebody/MoS.rebomos create mode 100644 examples/threebody/in.mos2-bulk create mode 100644 examples/threebody/in.mos2.rebomos create mode 100644 examples/threebody/log.22Feb24.mos2-bulk.g++.1 create mode 100644 examples/threebody/log.22Feb24.mos2-bulk.g++.4 create mode 100644 examples/threebody/log.22Feb24.mos2.rebomos.g++.1 create mode 100644 examples/threebody/log.22Feb24.mos2.rebomos.g++.4 create mode 100644 potentials/MoS.rebomos create mode 100644 src/MANYBODY/pair_rebomos.cpp create mode 100644 src/MANYBODY/pair_rebomos.h create mode 100644 unittest/force-styles/tests/manybody-pair-rebomos.yaml diff --git a/doc/src/Commands_pair.rst b/doc/src/Commands_pair.rst index 9f2bdbce79..95dd7429e8 100644 --- a/doc/src/Commands_pair.rst +++ b/doc/src/Commands_pair.rst @@ -256,6 +256,7 @@ OPT. * :doc:`rann ` * :doc:`reaxff (ko) ` * :doc:`rebo (io) ` + * :doc:`rebomos ` * :doc:`resquared (go) ` * :doc:`saip/metal (t) ` * :doc:`sdpd/taitwater/isothermal ` diff --git a/doc/src/pair_rebomos.rst b/doc/src/pair_rebomos.rst new file mode 100644 index 0000000000..56bf6488bb --- /dev/null +++ b/doc/src/pair_rebomos.rst @@ -0,0 +1,109 @@ +.. index:: pair_style rebomos + +pair_style rebomos command +========================= + +Syntax +"""""" + +.. code-block:: LAMMPS + + pair_style rebomos + +* rebomos = name of this pair style + +Examples +"""""""" + +.. code-block:: LAMMPS + + pair_style rebomos + pair_coeff * * ../potentials/MoS.rebomos Mo S + + +Description +""""""""""" + +The *rebomos* pair style computes + + +---------- + +Only a single pair_coeff command is used with the *rebomos* pair style +which specifies an REBOMoS potential file with parameters for Mo and S. +These are mapped to LAMMPS atom types by specifying N additional +arguments after the filename in the pair_coeff command, where N is the +number of LAMMPS atom types: + +* filename +* :math:`N` element names = mapping of REBOMoS elements to atom types + +See the :doc:`pair_coeff ` page for alternate ways +to specify the path for the potential file. + +As an example, if your LAMMPS simulation has three atom types and you want +the first two to be Mo, and the third to be S, you would use the following +pair_coeff command: + +.. code-block:: LAMMPS + + pair_coeff * * MoS.rebomos Mo Mo S + +The first 2 arguments must be \* \* so as to span all LAMMPS atom types. +The first two Mo arguments map LAMMPS atom types 1 and 2 to the Mo +element in the REBOMoS file. The final S argument maps LAMMPS atom type +3 to the S element in the REBOMoS file. If a mapping value is specified +as NULL, the mapping is not performed. This can be used when a +*rebomos* potential is used as part of the *hybrid* pair style. The +NULL values are placeholders for atom types that will be used with other +potentials. + +---------- + +Mixing, shift, table, tail correction, restart, rRESPA info +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +This pair style does not support the :doc:`pair_modify ` +mix, shift, table, and tail options. + +This pair style does not write their 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 styles 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. + +These pair potentials require the :doc:`newton ` setting to be +"on" for pair interactions. + +The MoS.rebomos potential file provided with LAMMPS (see the potentials +directory) is parameterized for metal :doc:`units `. You can use +the *rebomos* pair style with any LAMMPS units setting, but you would +need to create your own REBOMoS potential file with coefficients listed +in the appropriate units. + +The pair style provided here **only** supports potential files parameterized +for the elements molybdenum and sulfur (designated with "Mo" and "S" in the +*pair_coeff* command. Using potential files for other elements will trigger +an error. + +Related commands +"""""""""""""""" + +:doc:`pair_coeff `, :doc:`pair style rebo ` + +Default +""""""" + +none + +---------- diff --git a/doc/src/pair_style.rst b/doc/src/pair_style.rst index a2467bff2b..53bf269e1c 100644 --- a/doc/src/pair_style.rst +++ b/doc/src/pair_style.rst @@ -333,6 +333,7 @@ accelerated styles exist. * :doc:`rann ` - * :doc:`reaxff ` - ReaxFF potential * :doc:`rebo ` - second generation REBO potential of Brenner +* :doc:`rebomos ` - REBOMoS potential for MoS2 * :doc:`resquared ` - Everaers RE-Squared ellipsoidal potential * :doc:`saip/metal ` - interlayer potential for hetero-junctions formed with hexagonal 2D materials and metal surfaces * :doc:`sdpd/taitwater/isothermal ` - smoothed dissipative particle dynamics for water at isothermal conditions diff --git a/examples/threebody/MoS.rebomos b/examples/threebody/MoS.rebomos new file mode 120000 index 0000000000..6146c74c24 --- /dev/null +++ b/examples/threebody/MoS.rebomos @@ -0,0 +1 @@ +../../potentials/MoS.rebomos \ No newline at end of file diff --git a/examples/threebody/in.mos2-bulk b/examples/threebody/in.mos2-bulk new file mode 100644 index 0000000000..032e71fce8 --- /dev/null +++ b/examples/threebody/in.mos2-bulk @@ -0,0 +1,35 @@ +units metal + +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 & + a2 -1.5964590311 2.7651481541 0.0000000000 & + a3 0.0000000000 0.0000000000 13.9827680588 & + basis 0.0000000000 0.000000000 $(3.0/4.0) & + basis 0.0000000000 0.000000000 $(1.0/4.0) & + basis $(2.0/3.0) $(1.0/3.0) 0.862008989 & + basis $(1.0/3.0) $(2.0/3.0) 0.137990996 & + basis $(1.0/3.0) $(2.0/3.0) 0.362008989 & + basis $(2.0/3.0) $(1.0/3.0) 0.637991011 & + origin 0.1 0.1 0.1 + +region box prism 0 4 0 8 0 1 -2.0 0.0 0.0 +create_box 2 box +create_atoms 2 box & + basis 1 1 & + basis 2 1 & + basis 3 2 & + basis 4 2 & + basis 5 2 & + basis 6 2 + +mass 1 95.95 #Mo +mass 2 32.065 #S + +pair_style rebomos +pair_coeff * * MoS.rebomos Mo S + +thermo_style custom step temp press pe ke cellgamma vol +thermo 10 +#dump 1 all atom 10 MoS.lammpstrj +fix 1 all nve +run 20 + diff --git a/examples/threebody/in.mos2.rebomos b/examples/threebody/in.mos2.rebomos new file mode 100644 index 0000000000..ca91f67003 --- /dev/null +++ b/examples/threebody/in.mos2.rebomos @@ -0,0 +1,31 @@ +# monolayer MoS2 +units metal +boundary p p f +processors * * 1 +atom_modify map array + +atom_style atomic +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 rebomos +pair_coeff * * MoS.rebomos Mo S S +######################################################################### + +### Simulation settings #### +timestep 0.001 +velocity all create 300.0 12345 loop geom + +############################ + +# 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/threebody/log.22Feb24.mos2-bulk.g++.1 b/examples/threebody/log.22Feb24.mos2-bulk.g++.1 new file mode 100644 index 0000000000..7822ad40c5 --- /dev/null +++ b/examples/threebody/log.22Feb24.mos2-bulk.g++.1 @@ -0,0 +1,86 @@ +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +units metal + +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 $(3.0/4.0) basis 0.0000000000 0.000000000 $(1.0/4.0) basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 $(1.0/4.0) basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis 0.66666666666666662966 $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis 0.66666666666666662966 0.33333333333333331483 0.637991011 origin 0.1 0.1 0.1 +Lattice spacing in x,y,z = 4.7867748 2.7651482 13.982768 + +region box prism 0 4 0 8 0 1 -2.0 0.0 0.0 +create_box 2 box +Created triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9.5735495 0 0) + 1 by 1 by 1 MPI processor grid +create_atoms 2 box basis 1 1 basis 2 1 basis 3 2 basis 4 2 basis 5 2 basis 6 2 +Created 288 atoms + using lattice units in triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9.5735495 0 0) + create_atoms CPU = 0.000 seconds + +mass 1 95.95 #Mo +mass 2 32.065 #S + +pair_style rebomos +pair_coeff * * MoS.rebomos Mo S +Reading rebomos potential file MoS.rebomos with DATE: 2013-11-04 + +thermo_style custom step temp press pe ke cellgamma vol +thermo 10 +#dump 1 all atom 10 MoS.lammpstrj +fix 1 all nve +run 20 +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 20.1 + ghost atom cutoff = 20.1 + binsize = 10.05, bins = 3 3 2 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair rebomos, perpetual + attributes: full, newton on, ghost + pair build: full/bin/ghost + stencil: full/ghost/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 6.759 | 6.759 | 6.759 Mbytes + Step Temp Press PotEng KinEng CellGamma Volume + 0 0 28799.53 -2061.6112 0 113.40187 5922.4926 + 10 80.776057 13540.088 -2064.6132 2.9966028 113.40187 5922.4926 + 20 146.17503 -20669.371 -2067.0428 5.4227518 113.40187 5922.4926 +Loop time of 0.173901 on 1 procs for 20 steps with 288 atoms + +Performance: 9.937 ns/day, 2.415 hours/ns, 115.008 timesteps/s, 33.122 katom-step/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 | 0.17213 | 0.17213 | 0.17213 | 0.0 | 98.98 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.0013913 | 0.0013913 | 0.0013913 | 0.0 | 0.80 +Output | 5.0377e-05 | 5.0377e-05 | 5.0377e-05 | 0.0 | 0.03 +Modify | 6.9212e-05 | 6.9212e-05 | 6.9212e-05 | 0.0 | 0.04 +Other | | 0.000264 | | | 0.15 + +Nlocal: 288 ave 288 max 288 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 10002 ave 10002 max 10002 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 0 ave 0 max 0 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 477120 ave 477120 max 477120 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 477120 +Ave neighs/atom = 1656.6667 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 diff --git a/examples/threebody/log.22Feb24.mos2-bulk.g++.4 b/examples/threebody/log.22Feb24.mos2-bulk.g++.4 new file mode 100644 index 0000000000..c215d88294 --- /dev/null +++ b/examples/threebody/log.22Feb24.mos2-bulk.g++.4 @@ -0,0 +1,86 @@ +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +units metal + +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 $(3.0/4.0) basis 0.0000000000 0.000000000 $(1.0/4.0) basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 $(1.0/4.0) basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis 0.66666666666666662966 $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis 0.66666666666666662966 0.33333333333333331483 0.637991011 origin 0.1 0.1 0.1 +Lattice spacing in x,y,z = 4.7867748 2.7651482 13.982768 + +region box prism 0 4 0 8 0 1 -2.0 0.0 0.0 +create_box 2 box +Created triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9.5735495 0 0) + 2 by 2 by 1 MPI processor grid +create_atoms 2 box basis 1 1 basis 2 1 basis 3 2 basis 4 2 basis 5 2 basis 6 2 +Created 288 atoms + using lattice units in triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9.5735495 0 0) + create_atoms CPU = 0.001 seconds + +mass 1 95.95 #Mo +mass 2 32.065 #S + +pair_style rebomos +pair_coeff * * MoS.rebomos Mo S +Reading rebomos potential file MoS.rebomos with DATE: 2013-11-04 + +thermo_style custom step temp press pe ke cellgamma vol +thermo 10 +#dump 1 all atom 10 MoS.lammpstrj +fix 1 all nve +run 20 +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 20.1 + ghost atom cutoff = 20.1 + binsize = 10.05, bins = 3 3 2 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair rebomos, perpetual + attributes: full, newton on, ghost + pair build: full/bin/ghost + stencil: full/ghost/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 4.977 | 4.978 | 4.978 Mbytes + Step Temp Press PotEng KinEng CellGamma Volume + 0 0 28799.53 -2061.6112 0 113.40187 5922.4926 + 10 80.776057 13540.088 -2064.6132 2.9966028 113.40187 5922.4926 + 20 146.17503 -20669.371 -2067.0428 5.4227518 113.40187 5922.4926 +Loop time of 0.0644788 on 4 procs for 20 steps with 288 atoms + +Performance: 26.799 ns/day, 0.896 hours/ns, 310.179 timesteps/s, 89.332 katom-step/s +99.2% 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.057739 | 0.059918 | 0.06231 | 0.7 | 92.93 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.0018848 | 0.0042821 | 0.0064683 | 2.6 | 6.64 +Output | 3.7548e-05 | 4.1425e-05 | 5.1594e-05 | 0.0 | 0.06 +Modify | 3.4882e-05 | 3.5821e-05 | 3.6589e-05 | 0.0 | 0.06 +Other | | 0.0002014 | | | 0.31 + +Nlocal: 72 ave 72 max 72 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Nghost: 7113.5 ave 7114 max 7113 min +Histogram: 2 0 0 0 0 0 0 0 0 2 +Neighs: 0 ave 0 max 0 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +FullNghs: 119280 ave 119280 max 119280 min +Histogram: 4 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 477120 +Ave neighs/atom = 1656.6667 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 diff --git a/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 b/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 new file mode 100644 index 0000000000..e0a313647d --- /dev/null +++ b/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 @@ -0,0 +1,96 @@ +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +# monolayer MoS2 +units metal +boundary p p f +processors * * 1 +atom_modify map array + +atom_style atomic +read_data single_layer_MoS2.data +Reading data file ... + triclinic box = (0 0 -100) to (51.15232 44.299209 100) with tilt (25.57616 0 0) +WARNING: Triclinic box skew is large. LAMMPS will run inefficiently. (src/domain.cpp:219) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 768 atoms + read_data CPU = 0.003 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 rebomos +pair_coeff * * MoS.rebomos Mo S S +Reading rebomos potential file MoS.rebomos with DATE: 2013-11-04 +######################################################################### + +### Simulation settings #### +timestep 0.001 +velocity all create 300.0 12345 loop geom + +############################ + +# 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 = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 20.1 + ghost atom cutoff = 20.1 + binsize = 10.05, bins = 8 5 20 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair rebomos, perpetual + attributes: full, newton on, ghost + pair build: full/bin/ghost + stencil: full/ghost/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 5.273 | 5.273 | 5.273 Mbytes + Step TotEng PotEng KinEng Temp + 0 -5466.9785 -5496.7212 29.742759 300 + 500 -5466.964 -5482.6985 15.734505 158.7059 + 1000 -5466.9615 -5480.9492 13.98763 141.08607 + 1500 -5466.964 -5482.6912 15.727258 158.63281 + 2000 -5466.9657 -5483.3606 16.394878 165.36675 + 2500 -5466.9624 -5481.6253 14.662948 147.89765 + 3000 -5466.9642 -5482.7515 15.7873 159.23842 + 3500 -5466.9654 -5483.3789 16.413502 165.5546 + 4000 -5466.9628 -5481.848 14.885236 150.13977 + 4500 -5466.9648 -5483.5045 16.539775 166.82825 + 5000 -5466.9649 -5483.4932 16.528298 166.71249 +Loop time of 36.2406 on 1 procs for 5000 steps with 768 atoms + +Performance: 11.920 ns/day, 2.013 hours/ns, 137.967 timesteps/s, 105.959 katom-step/s +99.9% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 36.14 | 36.14 | 36.14 | 0.0 | 99.72 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.043166 | 0.043166 | 0.043166 | 0.0 | 0.12 +Output | 0.00021785 | 0.00021785 | 0.00021785 | 0.0 | 0.00 +Modify | 0.034547 | 0.034547 | 0.034547 | 0.0 | 0.10 +Other | | 0.02219 | | | 0.06 + +Nlocal: 768 ave 768 max 768 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 2054 ave 2054 max 2054 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 0 ave 0 max 0 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 330752 ave 330752 max 330752 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 330752 +Ave neighs/atom = 430.66667 +Neighbor list builds = 0 +Dangerous builds = 0 +Total wall time: 0:00:36 diff --git a/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 b/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 new file mode 100644 index 0000000000..7510c5a793 --- /dev/null +++ b/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 @@ -0,0 +1,96 @@ +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +# monolayer MoS2 +units metal +boundary p p f +processors * * 1 +atom_modify map array + +atom_style atomic +read_data single_layer_MoS2.data +Reading data file ... + triclinic box = (0 0 -100) to (51.15232 44.299209 100) with tilt (25.57616 0 0) +WARNING: Triclinic box skew is large. LAMMPS will run inefficiently. (src/domain.cpp:219) + 2 by 2 by 1 MPI processor grid + reading atoms ... + 768 atoms + read_data CPU = 0.002 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 rebomos +pair_coeff * * MoS.rebomos Mo S S +Reading rebomos potential file MoS.rebomos with DATE: 2013-11-04 +######################################################################### + +### Simulation settings #### +timestep 0.001 +velocity all create 300.0 12345 loop geom + +############################ + +# 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 = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 20.1 + ghost atom cutoff = 20.1 + binsize = 10.05, bins = 8 5 20 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair rebomos, perpetual + attributes: full, newton on, ghost + pair build: full/bin/ghost + stencil: full/ghost/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 4.464 | 4.464 | 4.464 Mbytes + Step TotEng PotEng KinEng Temp + 0 -5466.9785 -5496.7212 29.742759 300 + 500 -5466.964 -5482.6985 15.734505 158.7059 + 1000 -5466.9615 -5480.9492 13.98763 141.08607 + 1500 -5466.964 -5482.6912 15.727258 158.63281 + 2000 -5466.9657 -5483.3606 16.394878 165.36675 + 2500 -5466.9624 -5481.6253 14.662948 147.89765 + 3000 -5466.9642 -5482.7515 15.7873 159.23842 + 3500 -5466.9654 -5483.3789 16.413502 165.5546 + 4000 -5466.9628 -5481.848 14.885236 150.13977 + 4500 -5466.9648 -5483.5045 16.539775 166.82825 + 5000 -5466.9649 -5483.4932 16.528298 166.71249 +Loop time of 10.2878 on 4 procs for 5000 steps with 768 atoms + +Performance: 41.992 ns/day, 0.572 hours/ns, 486.014 timesteps/s, 373.259 katom-step/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 | 9.7925 | 9.9286 | 10.096 | 3.6 | 96.51 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.16754 | 0.33518 | 0.47096 | 19.5 | 3.26 +Output | 0.00016889 | 0.00018727 | 0.00023915 | 0.0 | 0.00 +Modify | 0.010131 | 0.010502 | 0.011106 | 0.4 | 0.10 +Other | | 0.01333 | | | 0.13 + +Nlocal: 192 ave 194 max 190 min +Histogram: 1 0 0 0 0 2 0 0 0 1 +Nghost: 1350 ave 1352 max 1348 min +Histogram: 1 0 0 0 0 2 0 0 0 1 +Neighs: 0 ave 0 max 0 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +FullNghs: 82688 ave 83548 max 81828 min +Histogram: 1 0 0 0 0 2 0 0 0 1 + +Total # of neighbors = 330752 +Ave neighs/atom = 430.66667 +Neighbor list builds = 0 +Dangerous builds = 0 +Total wall time: 0:00:10 diff --git a/potentials/MoS.rebomos b/potentials/MoS.rebomos new file mode 100644 index 0000000000..ea96981a1e --- /dev/null +++ b/potentials/MoS.rebomos @@ -0,0 +1,65 @@ +# DATE: 2013-11-04 UNITS: metal CONTRIBUTOR: J Stewart, K Dang, D Spearot (UArk) CITATION: Stewart J A and Spearot D E, Modelling Simul. Mater. Sci. Eng. 21. +# MoS-S REBO Brenner/Sinnot Potential as published in +# Liang T, Phillpot S R and Sinnott S B (2009) Phys. Rev. B79 245110, Erratum: Phys. Rev. B85 199903(E). + +3.50 rcmin_MM +2.75 rcmin_MS +2.30 rcmin_SS +3.80 rcmax_MM +3.05 rcmax_MS +3.00 rcmax_SS +3.419129390005910 Q_MM +1.505537839153790 Q_MS +0.254959104053671 Q_SS +1.07500712999340 alpha_MM +1.19267902218820 alpha_MS +1.10775022439715 alpha_SS +179.008013654688 A_MM +575.509677721866 A_MS +1228.43233679426 A_SS +706.247903589221 BIJc_MM1 +1344.46820036159 BIJc_MS1 +1498.64815404145 BIJc_SS1 +1.16100322369589 Beta_MM1 +1.26973752204290 Beta_MS1 +1.12673623610320 Beta_SS1 +0.1326842550663270 M_b0 +-0.007642788338017 M_b1 +0.0341395775059370 M_b2 +0.2523050971380870 M_b3 +0.1227287372225670 M_b4 +-0.361387798398897 M_b5 +-0.282577591351457 M_b6 +0.120194301035280 M_bg0 +0.045238287358190 M_bg1 +0.067922807244030 M_bg2 +-0.03672511378682 M_bg3 +0.107516477513860 M_bg4 +0.004964711984940 M_bg5 +-0.12997598358652 M_bg6 +0.006848761596750 S_b0 +-0.02389964401024 S_b1 +0.137457353311170 S_b2 +0.033016467497740 S_b3 +-0.31064291544850 S_b4 +-0.08550273135791 S_b5 +0.149252790306880 S_b6 +-0.2850852 S_bg0 +1.67102480 S_bg1 +-3.5678516 S_bg2 +3.45054990 S_bg3 +-1.2186289 S_bg4 +0.0 S_bg5 +0.0 S_bg6 +0.138040769883614 M_a0 +0.803625443023934 M_a1 +0.292412960851064 M_a2 +0.640588078946224 M_a3 +0.062978539843324 S_a0 +2.478617619878250 S_a1 +0.036666243238154 S_a2 +2.386431372486710 S_a3 +0.00058595 epsilon_MM +0.01386 epsilon_SS +4.200 sigma_MM +3.130 sigma_SS diff --git a/potentials/README b/potentials/README index c234f5f48b..2cb4a383c5 100644 --- a/potentials/README +++ b/potentials/README @@ -84,7 +84,7 @@ Au_u3 = Gold universal 3 The suffix of each file indicates the pair style it is used with: adp ADP angular dependent potential -airebo AI-REBO and REBO potentials +airebo AI-REBO potentials bop.table BOP potential, tabulated form cdeam concentration-dependent EAM comb COMB potential @@ -107,6 +107,8 @@ nb3b.harmonic nonbonded 3-body harmonic potential pod ML potential with proper orthogonal descriptors (POD) poly polymorphic 3-body potential reax ReaxFF potential (see README.reax for more info) +rebo REBO potentials +rebomos REBOMoS potential smtbq second moment tight binding QEq (SMTBQ) potential snap SNAP potential snapcoeff SNAP potential diff --git a/src/.gitignore b/src/.gitignore index 9e2c36bdd0..ba4c4c05b0 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1371,6 +1371,8 @@ /pair_reaxff.h /pair_rebo.cpp /pair_rebo.h +/pair_rebomos.cpp +/pair_rebomos.h /pair_resquared.cpp /pair_resquared.h /pair_saip_metal.cpp diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp new file mode 100644 index 0000000000..1211ad5c7e --- /dev/null +++ b/src/MANYBODY/pair_rebomos.cpp @@ -0,0 +1,1161 @@ +// 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + References: + + This code: + Stewart J A and Spearot D E (2013) Atomistic simulations of nanoindentation on the basal plane of crystalline molybdenum disulfide. Modelling Simul. Mater. Sci. Eng. 21. + + Based on: + Liang T, Phillpot S R and Sinnott S B (2009) Parameterization of a reactive many-body potential for Mo2S systems. Phys. Rev. B79 245110. + Liang T, Phillpot S R and Sinnott S B (2012) Erratum: Parameterization of a reactive many-body potential for Mo-S systems. (Phys. Rev. B79 245110 (2009)) Phys. Rev. B85 199903(E). + + LAMMPS file contributing authors: James Stewart, Khanh Dang and Douglas Spearot (University of Arkansas) +------------------------------------------------------------------------- */ + +// clang-format on + +#include "pair_rebomos.h" + +#include "atom.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "math_const.h" +#include "math_special.h" +#include "memory.h" +#include "my_page.h" +#include "neigh_list.h" +#include "neighbor.h" +#include "potential_file_reader.h" +#include "text_file_reader.h" + +#include +#include + +using namespace LAMMPS_NS; +using namespace MathConst; +using MathSpecial::cube; +using MathSpecial::powint; +using MathSpecial::square; + +#define MAXLINE 1024 +#define TOL 1.0e-9 +#define PGDELTA 1 + +/* ---------------------------------------------------------------------- */ + +PairREBOMoS::PairREBOMoS(LAMMPS *lmp) : Pair(lmp) +{ + single_enable = 0; + restartinfo = 0; + one_coeff = 1; + ghostneigh = 1; + manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; + + maxlocal = 0; + REBO_numneigh = nullptr; + REBO_firstneigh = nullptr; + ipage = nullptr; + pgsize = oneatom = 0; + nM = nS = nullptr; +} + +// clang-format off + +/* ---------------------------------------------------------------------- + Check if allocated, since class can be destructed when incomplete +------------------------------------------------------------------------- */ + +PairREBOMoS::~PairREBOMoS() +{ + memory->destroy(REBO_numneigh); + memory->sfree(REBO_firstneigh); + delete[] ipage; + memory->destroy(nM); + memory->destroy(nS); + + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); + memory->destroy(cutghost); + + memory->destroy(lj1); + memory->destroy(lj2); + memory->destroy(lj3); + memory->destroy(lj4); + } +} + +/* ---------------------------------------------------------------------- */ + +void PairREBOMoS::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); + + REBO_neigh(); + FREBO(eflag); + FLJ(eflag); + + if (vflag_fdotr) virial_fdotr_compute(); +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +void PairREBOMoS::allocate() +{ + allocated = 1; + int n = atom->ntypes; + + memory->create(setflag,n+1,n+1,"pair:setflag"); + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + setflag[i][j] = 0; + + memory->create(cutsq,n+1,n+1,"pair:cutsq"); + memory->create(cutghost,n+1,n+1,"pair:cutghost"); + + // only sized by M,S = 2 types + + memory->create(lj1,2,2,"pair:lj1"); + memory->create(lj2,2,2,"pair:lj2"); + memory->create(lj3,2,2,"pair:lj3"); + memory->create(lj4,2,2,"pair:lj4"); + + map = new int[n+1]; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +void PairREBOMoS::settings(int narg, char ** /* arg */) +{ + if (narg != 0) error->all(FLERR,"Illegal pair_style command"); +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +void PairREBOMoS::coeff(int narg, char **arg) +{ + if (!allocated) allocate(); + + if (narg != 3 + atom->ntypes) + error->all(FLERR,"Incorrect args for pair coefficients"); + + // insure I,J args are * * + + if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) + error->all(FLERR,"Incorrect args for pair coefficients"); + + // read args that map atom types to Mo and S + // map[i] = which element (0,1) the Ith atom type is, -1 if NULL + + for (int i = 3; i < narg; i++) { + if (strcmp(arg[i],"NULL") == 0) { + map[i-2] = -1; + continue; + } else if (strcmp(arg[i],"Mo") == 0) { + map[i-2] = 0; + } else if (strcmp(arg[i],"M") == 0) { // backward compatibility + map[i-2] = 0; + } else if (strcmp(arg[i],"S") == 0) { + map[i-2] = 1; + } else error->all(FLERR,"Incorrect args for pair coefficients"); + } + + // read potential file and initialize fitting splines + + read_file(arg[2]); + + // clear setflag since coeff() called once with I,J = * * + + int n = atom->ntypes; + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + setflag[i][j] = 0; + + // set setflag i,j for type pairs where both are mapped to elements + + int count = 0; + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + if (map[i] >= 0 && map[j] >= 0) { + setflag[i][j] = 1; + count++; + } + + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +void PairREBOMoS::init_style() +{ + if (atom->tag_enable == 0) + error->all(FLERR,"Pair style REBOMoS requires atom IDs"); + if (force->newton_pair == 0) + error->all(FLERR,"Pair style REBOMoS requires newton pair on"); + + // need a full neighbor list, including neighbors of ghosts + + neighbor->add_request(this,NeighConst::REQ_FULL|NeighConst::REQ_GHOST); + + // local REBO neighbor list + // create pages if first time or if neighbor pgsize/oneatom has changed + + int create = 0; + if (ipage == nullptr) create = 1; + if (pgsize != neighbor->pgsize) create = 1; + if (oneatom != neighbor->oneatom) create = 1; + + if (create) { + delete[] ipage; + pgsize = neighbor->pgsize; + oneatom = neighbor->oneatom; + + int nmypage= comm->nthreads; + ipage = new MyPage[nmypage]; + for (int i = 0; i < nmypage; i++) + ipage[i].init(oneatom,pgsize,PGDELTA); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +double PairREBOMoS::init_one(int i, int j) +{ + if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); + + // convert to Mo,S types + + int ii = map[i]; + int jj = map[j]; + + // use Mo-Mo values for these cutoffs since M atoms are biggest + + // cut3rebo = 3 REBO distances + + cut3rebo = 3.0 * rcmax[0][0]; + + // cutljrebosq = furthest distance from an owned atom a ghost atom can be + // to need its REBO neighs computed + // interaction = M-K-I-J-L-N with I = owned and J = ghost + // this insures N is in the REBO neigh list of L + // since I-J < rcLJmax and J-L < rmax + + double cutljrebo = rcLJmax[0][0] + rcmax[0][0]; + cutljrebosq = cutljrebo * cutljrebo; + + // cutmax = furthest distance from an owned atom + // at which another atom will feel force, i.e. the ghost cutoff + // for REBO term in potential: + // interaction = M-K-I-J-L-N with I = owned and J = ghost + // I to N is max distance = 3 REBO distances + // for LJ term in potential: + // short interaction = M-K-I-J-L-N with I = owned, J = ghost, I-J < rcLJmax + // rcLJmax + 2*rcmax, since I-J < rcLJmax and J-L,L-N = REBO distances + // long interaction = I-J with I = owned and J = ghost + // cutlj*sigma, since I-J < LJ cutoff + // cutghost = REBO cutoff used in REBO_neigh() for neighbors of ghosts + + double cutmax = MAX(cut3rebo,rcLJmax[0][0] + 2.0*rcmax[0][0]); + + cutghost[i][j] = rcmax[ii][jj]; + lj1[ii][jj] = 48.0 * epsilon[ii][jj] * powint(sigma[ii][jj],12); + lj2[ii][jj] = 24.0 * epsilon[ii][jj] * powint(sigma[ii][jj],6); + lj3[ii][jj] = 4.0 * epsilon[ii][jj] * powint(sigma[ii][jj],12); + lj4[ii][jj] = 4.0 * epsilon[ii][jj] * powint(sigma[ii][jj],6); + + cutghost[j][i] = cutghost[i][j]; + lj1[jj][ii] = lj1[ii][jj]; + lj2[jj][ii] = lj2[ii][jj]; + lj3[jj][ii] = lj3[ii][jj]; + lj4[jj][ii] = lj4[ii][jj]; + + return cutmax; +} + +/* ---------------------------------------------------------------------- + create REBO neighbor list from main neighbor list + REBO neighbor list stores neighbors of ghost atoms +------------------------------------------------------------------------- */ + +void PairREBOMoS::REBO_neigh() +{ + int i,j,ii,jj,n,allnum,jnum,itype,jtype; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq,dS; + int *ilist,*jlist,*numneigh,**firstneigh; + int *neighptr; + + double **x = atom->x; + int *type = atom->type; + + if (atom->nmax > maxlocal) { + maxlocal = atom->nmax; + memory->destroy(REBO_numneigh); + memory->sfree(REBO_firstneigh); + memory->destroy(nM); + memory->destroy(nS); + memory->create(REBO_numneigh,maxlocal,"REBOMoS:numneigh"); + REBO_firstneigh = (int **) memory->smalloc(maxlocal*sizeof(int *), + "REBOMoS:firstneigh"); + memory->create(nM,maxlocal,"REBOMoS:nM"); + memory->create(nS,maxlocal,"REBOMoS:nS"); + } + + allnum = list->inum + list->gnum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // store all REBO neighs of owned and ghost atoms + // scan full neighbor list of I + + ipage->reset(); + + for (ii = 0; ii < allnum; ii++) { + i = ilist[ii]; + + n = 0; + neighptr = ipage->vget(); + + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + itype = map[type[i]]; + nM[i] = nS[i] = 0.0; + jlist = firstneigh[i]; + jnum = numneigh[i]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + jtype = map[type[j]]; + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + + if (rsq < rcmaxsq[itype][jtype]) { + neighptr[n++] = j; + if (jtype == 0) + nM[i] += Sp(sqrt(rsq),rcmin[itype][jtype],rcmax[itype][jtype],dS); + else + nS[i] += Sp(sqrt(rsq),rcmin[itype][jtype],rcmax[itype][jtype],dS); + } + } + + REBO_firstneigh[i] = neighptr; + REBO_numneigh[i] = n; + ipage->vgot(n); + if (ipage->status()) + error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); + } +} + +/* ---------------------------------------------------------------------- + REBO forces and energy +------------------------------------------------------------------------- */ + +void PairREBOMoS::FREBO(int eflag) +{ + int i,j,k,ii,inum,itype,jtype; + tagint itag, jtag; + double delx,dely,delz,evdwl,fpair,xtmp,ytmp,ztmp; + double rsq,rij,wij; + double Qij,Aij,alphaij,VR,pre,dVRdi,VA,bij,dVAdi,dVA; + double dwij,del[3]; + int *ilist,*REBO_neighs; + + evdwl = 0.0; + + double **x = atom->x; + double **f = atom->f; + int *type = atom->type; + tagint *tag = atom->tag; + int nlocal = atom->nlocal; + int newton_pair = force->newton_pair; + + inum = list->inum; + ilist = list->ilist; + + // two-body interactions from REBO neighbor list, skip half of them + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + itag = tag[i]; + itype = map[type[i]]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + REBO_neighs = REBO_firstneigh[i]; + + for (k = 0; k < REBO_numneigh[i]; k++) { + j = REBO_neighs[k]; + 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][2] < ztmp) continue; + if (x[j][2] == ztmp && x[j][1] < ytmp) continue; + if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue; + } + + jtype = map[type[j]]; + + delx = x[i][0] - x[j][0]; + dely = x[i][1] - x[j][1]; + delz = x[i][2] - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + rij = sqrt(rsq); + wij = Sp(rij,rcmin[itype][jtype],rcmax[itype][jtype],dwij); + if (wij <= TOL) continue; + + Qij = Q[itype][jtype]; + Aij = A[itype][jtype]; + alphaij = alpha[itype][jtype]; + + VR = wij*(1.0+(Qij/rij)) * Aij*exp(-alphaij*rij); + pre = wij*Aij * exp(-alphaij*rij); + dVRdi = pre * ((-alphaij)-(Qij/rsq)-(Qij*alphaij/rij)); + dVRdi += VR/wij * dwij; + + VA = dVA = 0.0; + VA = -wij * BIJc[itype][jtype] * exp(-Beta[itype][jtype]*rij); + + dVA = -Beta[itype][jtype] * VA; + dVA += VA/wij * dwij; + + del[0] = delx; + del[1] = dely; + del[2] = delz; + bij = bondorder(i,j,del,rij,VA,f); + dVAdi = bij*dVA; + + fpair = -(dVRdi+dVAdi) / rij; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; + + if (eflag) evdwl = VR + bij*VA; + if (evflag) ev_tally(i,j,nlocal,newton_pair,evdwl,0.0,fpair,delx,dely,delz); + } + } +} + +/* ---------------------------------------------------------------------- + compute LJ forces and energy +------------------------------------------------------------------------- */ + +void PairREBOMoS::FLJ(int eflag) +{ + int i,j,ii,jj,inum,jnum,itype,jtype; + tagint itag,jtag; + double evdwl,fpair,xtmp,ytmp,ztmp; + double rij,delij[3],rijsq; + double VLJ,dVLJ; + double vdw,dvdw; + double r2inv,r6inv; + int *ilist,*jlist,*numneigh,**firstneigh; + double c2,c3,dr,drp,r6; + + // I-J interaction from full neighbor list + // skip 1/2 of interactions since only consider each pair once + + evdwl = 0.0; + + double **x = atom->x; + double **f = atom->f; + tagint *tag = atom->tag; + int *type = atom->type; + int nlocal = atom->nlocal; + int newton_pair = force->newton_pair; + + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // loop over neighbors of my atoms + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + itag = tag[i]; + itype = map[type[i]]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + 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][2] < ztmp) continue; + if (x[j][2] == ztmp && x[j][1] < ytmp) continue; + if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue; + } + jtype = map[type[j]]; + + delij[0] = xtmp - x[j][0]; + delij[1] = ytmp - x[j][1]; + delij[2] = ztmp - x[j][2]; + rijsq = delij[0]*delij[0] + delij[1]*delij[1] + delij[2]*delij[2]; + rij = sqrt(rijsq); + + // compute LJ forces and energy + + // Outside Rmax + if (rij > rcLJmax[itype][jtype] || rij < rcLJmin[itype][jtype]){ + VLJ = 0; + dVLJ = 0; + } + + // Inside Rmax and above 0.95*sigma + else if (rij <= rcLJmax[itype][jtype] && rij >= 0.95*sigma[itype][jtype]){ + r2inv = 1.0/rijsq; + r6inv = r2inv*r2inv*r2inv; + VLJ = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); + dVLJ = -r6inv*(lj1[itype][jtype]*r6inv - lj2[itype][jtype])/rij; + } + + // Below 0.95*sigma + else if (rij < 0.95*sigma[itype][jtype] && rij >= rcLJmin[itype][jtype]){ + dr = 0.95*sigma[itype][jtype] - rcLJmin[itype][jtype]; + r6 = powint((sigma[itype][jtype]/(0.95*sigma[itype][jtype])),6); + vdw = 4*epsilon[itype][jtype]*r6*(r6 - 1.0); + dvdw = (-4*epsilon[itype][jtype]/(0.95*sigma[itype][jtype]))*r6*(12.0*r6 - 6.0); + c2 = ((3.0/dr)*vdw - dvdw)/dr; + c3 = (vdw/(dr*dr) - c2)/dr; + + drp = rij - rcLJmin[itype][jtype]; + VLJ = drp*drp*(drp*c3 + c2); + dVLJ = drp*(3.0*drp*c3 + 2.0*c2); + } + + fpair = -dVLJ/rij; + f[i][0] += delij[0]*fpair; + f[i][1] += delij[1]*fpair; + f[i][2] += delij[2]*fpair; + f[j][0] -= delij[0]*fpair; + f[j][1] -= delij[1]*fpair; + f[j][2] -= delij[2]*fpair; + + if (eflag) evdwl = VLJ; + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delij[0],delij[1],delij[2]); + + } + } +} + +/* ---------------------------------------------------------------------- + Bij function + + The bond order term modified the attractive portion of the REBO + potential based on the number of atoms around a specific pair + and the bond angle between sets of three atoms. + + The functions G(cos(theta)) and P(N) are evaluated and their + derivatives are also computed for use in the force calculation. +------------------------------------------------------------------------- */ + +double PairREBOMoS::bondorder(int i, int j, double rij[3], double rijmag, double VA, double **f) +{ + int atomi,atomj,atomk,atoml; + int k,l; + int itype, jtype, ktype, ltype; + double rik[3], rjl[3], rji[3], rki[3],rlj[3], dwjl, bij; + double NijM,NijS,NjiM,NjiS,wik,dwik,wjl; + double rikmag,rjlmag,cosjik,cosijl,g,tmp2; + double Etmp,pij,tmp,dwij,dS; + double dgdc,pji; + double dcosjikdri[3],dcosijldri[3],dcosjikdrk[3]; + double dp; + double dcosjikdrj[3],dcosijldrj[3],dcosijldrl[3]; + double fi[3],fj[3],fk[3],fl[3]; + double PijS, PjiS; + int *REBO_neighs; + + double **x = atom->x; + int *type = atom->type; + + atomi = i; + atomj = j; + itype = map[type[i]]; + jtype = map[type[j]]; + Sp(rijmag,rcmin[itype][jtype],rcmax[itype][jtype],dwij); + NijM = nM[i]; + NijS = nS[i]; + NjiM = nM[j]; + NjiS = nS[j]; + bij = 0.0; + tmp = 0.0; + tmp2 = 0.0; + dgdc = 0.0; + Etmp = 0.0; + + REBO_neighs = REBO_firstneigh[i]; + for (k = 0; k < REBO_numneigh[i]; k++) { + atomk = REBO_neighs[k]; + if (atomk != atomj) { + ktype = map[type[atomk]]; + rik[0] = x[atomi][0]-x[atomk][0]; + rik[1] = x[atomi][1]-x[atomk][1]; + rik[2] = x[atomi][2]-x[atomk][2]; + rikmag = sqrt((rik[0]*rik[0])+(rik[1]*rik[1])+(rik[2]*rik[2])); + wik = Sp(rikmag,rcmin[itype][ktype],rcmax[itype][ktype],dS); + cosjik = ((rij[0]*rik[0])+(rij[1]*rik[1])+(rij[2]*rik[2])) / (rijmag*rikmag); + cosjik = MIN(cosjik,1.0); + cosjik = MAX(cosjik,-1.0); + + // evaluate g and derivative dg + + g = gSpline(cosjik,itype,dgdc); + Etmp = Etmp+(wik*g); + } + } + + dp = 0.0; + PijS = PijSpline(NijM,NijS,itype,dp); + pij = 1.0/sqrt(1.0+Etmp+PijS); + tmp = -0.5*cube(pij); + + // derivative calculations + + REBO_neighs = REBO_firstneigh[i]; + for (k = 0; k < REBO_numneigh[i]; k++) { + atomk = REBO_neighs[k]; + if (atomk != atomj) { + ktype = map[type[atomk]]; + rik[0] = x[atomi][0]-x[atomk][0]; + rik[1] = x[atomi][1]-x[atomk][1]; + rik[2] = x[atomi][2]-x[atomk][2]; + rikmag = sqrt((rik[0]*rik[0])+(rik[1]*rik[1])+(rik[2]*rik[2])); + wik = Sp(rikmag,rcmin[itype][ktype],rcmax[itype][ktype],dwik); + cosjik = (rij[0]*rik[0] + rij[1]*rik[1] + rij[2]*rik[2]) / (rijmag*rikmag); + cosjik = MIN(cosjik,1.0); + cosjik = MAX(cosjik,-1.0); + + dcosjikdri[0] = ((rij[0]+rik[0])/(rijmag*rikmag)) - + (cosjik*((rij[0]/(rijmag*rijmag))+(rik[0]/(rikmag*rikmag)))); + dcosjikdri[1] = ((rij[1]+rik[1])/(rijmag*rikmag)) - + (cosjik*((rij[1]/(rijmag*rijmag))+(rik[1]/(rikmag*rikmag)))); + dcosjikdri[2] = ((rij[2]+rik[2])/(rijmag*rikmag)) - + (cosjik*((rij[2]/(rijmag*rijmag))+(rik[2]/(rikmag*rikmag)))); + dcosjikdrk[0] = (-rij[0]/(rijmag*rikmag)) + + (cosjik*(rik[0]/(rikmag*rikmag))); + dcosjikdrk[1] = (-rij[1]/(rijmag*rikmag)) + + (cosjik*(rik[1]/(rikmag*rikmag))); + dcosjikdrk[2] = (-rij[2]/(rijmag*rikmag)) + + (cosjik*(rik[2]/(rikmag*rikmag))); + dcosjikdrj[0] = (-rik[0]/(rijmag*rikmag)) + + (cosjik*(rij[0]/(rijmag*rijmag))); + dcosjikdrj[1] = (-rik[1]/(rijmag*rikmag)) + + (cosjik*(rij[1]/(rijmag*rijmag))); + dcosjikdrj[2] = (-rik[2]/(rijmag*rikmag)) + + (cosjik*(rij[2]/(rijmag*rijmag))); + + g = gSpline(cosjik,itype,dgdc); + tmp2 = VA*0.5*(tmp*wik*dgdc); + fj[0] = -tmp2*dcosjikdrj[0]; + fj[1] = -tmp2*dcosjikdrj[1]; + fj[2] = -tmp2*dcosjikdrj[2]; + fi[0] = -tmp2*dcosjikdri[0]; + fi[1] = -tmp2*dcosjikdri[1]; + fi[2] = -tmp2*dcosjikdri[2]; + fk[0] = -tmp2*dcosjikdrk[0]; + fk[1] = -tmp2*dcosjikdrk[1]; + fk[2] = -tmp2*dcosjikdrk[2]; + + // coordination forces + + // dwik forces (from partial derivative) + + tmp2 = VA*0.5*(tmp*dwik*g)/rikmag; + fi[0] -= tmp2*rik[0]; + fi[1] -= tmp2*rik[1]; + fi[2] -= tmp2*rik[2]; + fk[0] += tmp2*rik[0]; + fk[1] += tmp2*rik[1]; + fk[2] += tmp2*rik[2]; + + // PIJ forces (from coordination P(N) term) + + tmp2 = VA*0.5*(tmp*dp*dwik)/rikmag; + fi[0] -= tmp2*rik[0]; + fi[1] -= tmp2*rik[1]; + fi[2] -= tmp2*rik[2]; + fk[0] += tmp2*rik[0]; + fk[1] += tmp2*rik[1]; + fk[2] += tmp2*rik[2]; + + // dgdN forces are removed + + f[atomi][0] += fi[0]; f[atomi][1] += fi[1]; f[atomi][2] += fi[2]; + f[atomj][0] += fj[0]; f[atomj][1] += fj[1]; f[atomj][2] += fj[2]; + f[atomk][0] += fk[0]; f[atomk][1] += fk[1]; f[atomk][2] += fk[2]; + + if (vflag_either) { + rji[0] = -rij[0]; rji[1] = -rij[1]; rji[2] = -rij[2]; + rki[0] = -rik[0]; rki[1] = -rik[1]; rki[2] = -rik[2]; + v_tally3(atomi,atomj,atomk,fj,fk,rji,rki); + } + } + } + + // PIJ force contribution additional term + tmp2 = -VA*0.5*(tmp*dp*dwij)/rijmag; + + f[atomi][0] += rij[0]*tmp2; + f[atomi][1] += rij[1]*tmp2; + f[atomi][2] += rij[2]*tmp2; + f[atomj][0] -= rij[0]*tmp2; + f[atomj][1] -= rij[1]*tmp2; + f[atomj][2] -= rij[2]*tmp2; + + if (vflag_either) v_tally2(atomi,atomj,tmp2,rij); + + tmp = 0.0; + tmp2 = 0.0; + Etmp = 0.0; + + REBO_neighs = REBO_firstneigh[j]; + for (l = 0; l < REBO_numneigh[j]; l++) { + atoml = REBO_neighs[l]; + if (atoml != atomi) { + ltype = map[type[atoml]]; + rjl[0] = x[atomj][0]-x[atoml][0]; + rjl[1] = x[atomj][1]-x[atoml][1]; + rjl[2] = x[atomj][2]-x[atoml][2]; + rjlmag = sqrt((rjl[0]*rjl[0])+(rjl[1]*rjl[1])+(rjl[2]*rjl[2])); + wjl = Sp(rjlmag,rcmin[jtype][ltype],rcmax[jtype][ltype],dS); + cosijl = -1.0*((rij[0]*rjl[0])+(rij[1]*rjl[1])+(rij[2]*rjl[2])) / (rijmag*rjlmag); + cosijl = MIN(cosijl,1.0); + cosijl = MAX(cosijl,-1.0); + + // evaluate g and derivative dg + + g = gSpline(cosijl,jtype,dgdc); + Etmp = Etmp+(wjl*g); + } + } + + dp = 0.0; + PjiS = PijSpline(NjiM,NjiS,jtype,dp); + pji = 1.0/sqrt(1.0+Etmp+PjiS); + tmp = -0.5*cube(pji); + + REBO_neighs = REBO_firstneigh[j]; + for (l = 0; l < REBO_numneigh[j]; l++) { + atoml = REBO_neighs[l]; + if (atoml != atomi) { + ltype = map[type[atoml]]; + rjl[0] = x[atomj][0]-x[atoml][0]; + rjl[1] = x[atomj][1]-x[atoml][1]; + rjl[2] = x[atomj][2]-x[atoml][2]; + rjlmag = sqrt((rjl[0]*rjl[0])+(rjl[1]*rjl[1])+(rjl[2]*rjl[2])); + wjl = Sp(rjlmag,rcmin[jtype][ltype],rcmax[jtype][ltype],dwjl); + cosijl = (-1.0*((rij[0]*rjl[0])+(rij[1]*rjl[1])+(rij[2]*rjl[2]))) / (rijmag*rjlmag); + cosijl = MIN(cosijl,1.0); + cosijl = MAX(cosijl,-1.0); + + dcosijldri[0] = (-rjl[0]/(rijmag*rjlmag)) - + (cosijl*rij[0]/(rijmag*rijmag)); + dcosijldri[1] = (-rjl[1]/(rijmag*rjlmag)) - + (cosijl*rij[1]/(rijmag*rijmag)); + dcosijldri[2] = (-rjl[2]/(rijmag*rjlmag)) - + (cosijl*rij[2]/(rijmag*rijmag)); + dcosijldrj[0] = ((-rij[0]+rjl[0])/(rijmag*rjlmag)) + + (cosijl*((rij[0]/square(rijmag))-(rjl[0]/(rjlmag*rjlmag)))); + dcosijldrj[1] = ((-rij[1]+rjl[1])/(rijmag*rjlmag)) + + (cosijl*((rij[1]/square(rijmag))-(rjl[1]/(rjlmag*rjlmag)))); + dcosijldrj[2] = ((-rij[2]+rjl[2])/(rijmag*rjlmag)) + + (cosijl*((rij[2]/square(rijmag))-(rjl[2]/(rjlmag*rjlmag)))); + dcosijldrl[0] = (rij[0]/(rijmag*rjlmag))+(cosijl*rjl[0]/(rjlmag*rjlmag)); + dcosijldrl[1] = (rij[1]/(rijmag*rjlmag))+(cosijl*rjl[1]/(rjlmag*rjlmag)); + dcosijldrl[2] = (rij[2]/(rijmag*rjlmag))+(cosijl*rjl[2]/(rjlmag*rjlmag)); + + // evaluate g and derivatives dg + + g = gSpline(cosijl,jtype,dgdc); + tmp2 = VA*0.5*(tmp*wjl*dgdc); + fi[0] = -tmp2*dcosijldri[0]; + fi[1] = -tmp2*dcosijldri[1]; + fi[2] = -tmp2*dcosijldri[2]; + fj[0] = -tmp2*dcosijldrj[0]; + fj[1] = -tmp2*dcosijldrj[1]; + fj[2] = -tmp2*dcosijldrj[2]; + fl[0] = -tmp2*dcosijldrl[0]; + fl[1] = -tmp2*dcosijldrl[1]; + fl[2] = -tmp2*dcosijldrl[2]; + + // coordination forces + + // dwik forces (from partial derivative) + + tmp2 = VA*0.5*(tmp*dwjl*g)/rjlmag; + fj[0] -= tmp2*rjl[0]; + fj[1] -= tmp2*rjl[1]; + fj[2] -= tmp2*rjl[2]; + fl[0] += tmp2*rjl[0]; + fl[1] += tmp2*rjl[1]; + fl[2] += tmp2*rjl[2]; + + // PIJ forces (coordination) + + tmp2 = VA*0.5*(tmp*dp*dwjl)/rjlmag; + fj[0] -= tmp2*rjl[0]; + fj[1] -= tmp2*rjl[1]; + fj[2] -= tmp2*rjl[2]; + fl[0] += tmp2*rjl[0]; + fl[1] += tmp2*rjl[1]; + fl[2] += tmp2*rjl[2]; + + // dgdN forces are removed + + f[atomi][0] += fi[0]; f[atomi][1] += fi[1]; f[atomi][2] += fi[2]; + f[atomj][0] += fj[0]; f[atomj][1] += fj[1]; f[atomj][2] += fj[2]; + f[atoml][0] += fl[0]; f[atoml][1] += fl[1]; f[atoml][2] += fl[2]; + + if (vflag_either) { + rlj[0] = -rjl[0]; rlj[1] = -rjl[1]; rlj[2] = -rjl[2]; + v_tally3(atomi,atomj,atoml,fi,fl,rij,rlj); + } + } + } + + // PIJ force contribution additional term + + tmp2 = -VA*0.5*(tmp*dp*dwij)/rijmag; + f[atomi][0] += rij[0]*tmp2; + f[atomi][1] += rij[1]*tmp2; + f[atomi][2] += rij[2]*tmp2; + f[atomj][0] -= rij[0]*tmp2; + f[atomj][1] -= rij[1]*tmp2; + f[atomj][2] -= rij[2]*tmp2; + + if (vflag_either) v_tally2(atomi,atomj,tmp2,rij); + + bij = (0.5*(pij+pji)); + return bij; +} + +/* ---------------------------------------------------------------------- + G calculation +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + read REBO potential file +------------------------------------------------------------------------- */ + +void PairREBOMoS::read_file(char *filename) +{ + // REBO Parameters (Mo-S REBO) + + double rcmin_MM,rcmin_MS,rcmin_SS,rcmax_MM,rcmax_MS,rcmax_SS; + double Q_MM,Q_MS,Q_SS,alpha_MM,alpha_MS,alpha_SS,A_MM,A_MS,A_SS; + double BIJc_MM1,BIJc_MS1,BIJc_SS1; + double Beta_MM1,Beta_MS1,Beta_SS1; + double M_bg0,M_bg1,M_bg2,M_bg3,M_bg4,M_bg5,M_bg6; + double S_bg0,S_bg1,S_bg2,S_bg3,S_bg4,S_bg5,S_bg6; + double M_b0,M_b1,M_b2,M_b3,M_b4,M_b5,M_b6; + double S_b0,S_b1,S_b2,S_b3,S_b4,S_b5,S_b6; + double M_a0,M_a1,M_a2,M_a3; + double S_a0,S_a1,S_a2,S_a3; + + // LJ Parameters (Mo-S REBO) + + double epsilon_MM,epsilon_SS; + double sigma_MM,sigma_SS; + + // read file on proc 0 + + if (comm->me == 0) { + PotentialFileReader reader(lmp, filename, "rebomos"); + + // read parameters + + std::vector params { + &rcmin_MM, + &rcmin_MS, + &rcmin_SS, + &rcmax_MM, + &rcmax_MS, + &rcmax_SS, + &Q_MM, + &Q_MS, + &Q_SS, + &alpha_MM, + &alpha_MS, + &alpha_SS, + &A_MM, + &A_MS, + &A_SS, + &BIJc_MM1, + &BIJc_MS1, + &BIJc_SS1, + &Beta_MM1, + &Beta_MS1, + &Beta_SS1, + &M_b0, + &M_b1, + &M_b2, + &M_b3, + &M_b4, + &M_b5, + &M_b6, + &M_bg0, + &M_bg1, + &M_bg2, + &M_bg3, + &M_bg4, + &M_bg5, + &M_bg6, + &S_b0, + &S_b1, + &S_b2, + &S_b3, + &S_b4, + &S_b5, + &S_b6, + &S_bg0, + &S_bg1, + &S_bg2, + &S_bg3, + &S_bg4, + &S_bg5, + &S_bg6, + &M_a0, + &M_a1, + &M_a2, + &M_a3, + &S_a0, + &S_a1, + &S_a2, + &S_a3, + + // LJ parameters + &epsilon_MM, + &epsilon_SS, + &sigma_MM, + &sigma_SS, + }; + + try { + for (auto ¶m : params) { + *param = reader.next_double(); + } + } catch (TokenizerException &e) { + error->one(FLERR, "reading rebomos potential file {}\nREASON: {}\n", filename, e.what()); + } catch (FileReaderException &fre) { + error->one(FLERR, "reading rebomos potential file {}\nREASON: {}\n", filename, fre.what()); + } + + // store read-in values in arrays + + // REBO + + rcmin[0][0] = rcmin_MM; + rcmin[0][1] = rcmin_MS; + rcmin[1][0] = rcmin[0][1]; + rcmin[1][1] = rcmin_SS; + + rcmax[0][0] = rcmax_MM; + rcmax[0][1] = rcmax_MS; + rcmax[1][0] = rcmax[0][1]; + rcmax[1][1] = rcmax_SS; + + rcmaxsq[0][0] = rcmax[0][0]*rcmax[0][0]; + rcmaxsq[1][0] = rcmax[1][0]*rcmax[1][0]; + rcmaxsq[0][1] = rcmax[0][1]*rcmax[0][1]; + rcmaxsq[1][1] = rcmax[1][1]*rcmax[1][1]; + + Q[0][0] = Q_MM; + Q[0][1] = Q_MS; + Q[1][0] = Q[0][1]; + Q[1][1] = Q_SS; + + alpha[0][0] = alpha_MM; + alpha[0][1] = alpha_MS; + alpha[1][0] = alpha[0][1]; + alpha[1][1] = alpha_SS; + + A[0][0] = A_MM; + A[0][1] = A_MS; + A[1][0] = A[0][1]; + A[1][1] = A_SS; + + BIJc[0][0] = BIJc_MM1; + BIJc[0][1] = BIJc_MS1; + BIJc[1][0] = BIJc_MS1; + BIJc[1][1] = BIJc_SS1; + + Beta[0][0] = Beta_MM1; + Beta[0][1] = Beta_MS1; + Beta[1][0] = Beta_MS1; + Beta[1][1] = Beta_SS1; + + b0[0] = M_b0; + b1[0] = M_b1; + b2[0] = M_b2; + b3[0] = M_b3; + b4[0] = M_b4; + b5[0] = M_b5; + b6[0] = M_b6; + + bg0[0] = M_bg0; + bg1[0] = M_bg1; + bg2[0] = M_bg2; + bg3[0] = M_bg3; + bg4[0] = M_bg4; + bg5[0] = M_bg5; + bg6[0] = M_bg6; + + b0[1] = S_b0; + b1[1] = S_b1; + b2[1] = S_b2; + b3[1] = S_b3; + b4[1] = S_b4; + b5[1] = S_b5; + b6[1] = S_b6; + + bg0[1] = S_bg0; + bg1[1] = S_bg1; + bg2[1] = S_bg2; + bg3[1] = S_bg3; + bg4[1] = S_bg4; + bg5[1] = S_bg5; + bg6[1] = S_bg6; + + a0[0] = M_a0; + a1[0] = M_a1; + a2[0] = M_a2; + a3[0] = M_a3; + + a0[1] = S_a0; + a1[1] = S_a1; + a2[1] = S_a2; + a3[1] = S_a3; + + // LJ + + sigma[0][0] = sigma_MM; + sigma[0][1] = (sigma_MM + sigma_SS)/2; + sigma[1][0] = sigma[0][1]; + sigma[1][1] = sigma_SS; + + epsilon[0][0] = epsilon_MM; + epsilon[0][1] = sqrt(epsilon_MM*epsilon_SS); + epsilon[1][0] = epsilon[0][1]; + epsilon[1][1] = epsilon_SS; + + rcLJmin[0][0] = rcmin_MM; + rcLJmin[0][1] = rcmin_MS; + rcLJmin[1][0] = rcmin[0][1]; + rcLJmin[1][1] = rcmin_SS; + + rcLJmax[0][0] = 2.5*sigma[0][0]; + rcLJmax[0][1] = 2.5*sigma[0][1]; + rcLJmax[1][0] = rcLJmax[0][1]; + rcLJmax[1][1] = 2.5*sigma[1][1]; + + rcLJmaxsq[0][0] = rcLJmax[0][0]*rcLJmax[0][0]; + rcLJmaxsq[1][0] = rcLJmax[1][0]*rcLJmax[1][0]; + rcLJmaxsq[0][1] = rcLJmax[0][1]*rcLJmax[0][1]; + rcLJmaxsq[1][1] = rcLJmax[1][1]*rcLJmax[1][1]; + + } + + // broadcast read-in and setup values + + MPI_Bcast(&rcmin[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&rcmax[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&rcmaxsq[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&rcmaxp[0][0],4,MPI_DOUBLE,0,world); + + MPI_Bcast(&Q[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&alpha[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&A[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&BIJc[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&Beta[0][0],4,MPI_DOUBLE,0,world); + + MPI_Bcast(&b0[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b1[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b2[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b3[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b4[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b5[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b6[0],2,MPI_DOUBLE,0,world); + + MPI_Bcast(&a0[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&a1[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&a2[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&a3[0],2,MPI_DOUBLE,0,world); + + MPI_Bcast(&bg0[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg1[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg2[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg3[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg4[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg5[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg6[0],2,MPI_DOUBLE,0,world); + + MPI_Bcast(&rcLJmin[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&rcLJmax[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&rcLJmaxsq[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&epsilon[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&sigma[0][0],4,MPI_DOUBLE,0,world); +} + +/* ---------------------------------------------------------------------- + memory usage of local atom-based arrays +------------------------------------------------------------------------- */ + +double PairREBOMoS::memory_usage() +{ + double bytes = 0.0; + bytes += (double)maxlocal * sizeof(int); + bytes += (double)maxlocal * sizeof(int *); + + for (int i = 0; i < comm->nthreads; i++) + bytes += ipage[i].size(); + + bytes += 3.0 * maxlocal * sizeof(double); + return bytes; +} diff --git a/src/MANYBODY/pair_rebomos.h b/src/MANYBODY/pair_rebomos.h new file mode 100644 index 0000000000..4a530de329 --- /dev/null +++ b/src/MANYBODY/pair_rebomos.h @@ -0,0 +1,219 @@ +/* -*- 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. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS +// clang-format off +PairStyle(rebomos,PairREBOMoS); +// clang-format on +#else + +#ifndef LMP_PAIR_REBOMOS_H +#define LMP_PAIR_REBOMOS_H + +#include "math_const.h" +#include "pair.h" +#include + +namespace LAMMPS_NS { + +class PairREBOMoS : public Pair { + public: + PairREBOMoS(class LAMMPS *); + ~PairREBOMoS() override; + void compute(int, int) override; + void settings(int, char **) override; + void coeff(int, char **) override; + void init_style() override; + double init_one(int, int) override; + double memory_usage() override; + + protected: + double cutljrebosq; // cut for when to compute + // REBO neighs of ghost atoms + + double **lj1, **lj2, **lj3, **lj4; // pre-computed LJ coeffs for M,S types + double cut3rebo; // maximum distance for 3rd REBO neigh + + int maxlocal; // size of numneigh, firstneigh arrays + int pgsize; // size of neighbor page + int oneatom; // max # of neighbors for one atom + MyPage *ipage; // neighbor list pages + int *REBO_numneigh; // # of pair neighbors for each atom + int **REBO_firstneigh; // ptr to 1st neighbor of each atom + + double *closestdistsq; // closest owned atom dist to each ghost + double *nM, *nS; // sum of weighting fns with REBO neighs + + double rcmin[2][2], rcmax[2][2], rcmaxsq[2][2], rcmaxp[2][2]; + double Q[2][2], alpha[2][2], A[2][2], BIJc[2][2], Beta[2][2]; + double b0[2], b1[2], b2[2], b3[2], b4[2], b5[2], b6[2]; + double bg0[2], bg1[2], bg2[2], bg3[2], bg4[2], bg5[2], bg6[2]; + double a0[2], a1[2], a2[2], a3[2]; + double rcLJmin[2][2], rcLJmax[2][2], rcLJmaxsq[2][2]; + double epsilon[2][2], sigma[2][2]; + + void REBO_neigh(); + void FREBO(int); + void FLJ(int); + + double bondorder(int, int, double *, double, double, double **); + + inline double gSpline(const double costh, const int typei, double &dgdc) const + { + const double b0i = b0[typei]; + const double b1i = b1[typei]; + const double b2i = b2[typei]; + const double b3i = b3[typei]; + const double b4i = b4[typei]; + const double b5i = b5[typei]; + const double b6i = b6[typei]; + double g = 0.0; + + if (costh >= -1.0 && costh < 0.5) { + g = b6i * costh; + double dg = 6.0 * b6i * costh; + g += b5i; + dg += 5.0 * b5i; + g *= costh; + dg *= costh; + g += b4i; + dg += 4.0 * b4i; + g *= costh; + dg *= costh; + g += b3i; + dg += 3.0 * b3i; + g *= costh; + dg *= costh; + g += b2i; + dg += 2.0 * b2i; + g *= costh; + dg *= costh; + g += b1i; + dg += b1i; + g *= costh; + g += b0i; + dgdc = dg; + + } else if (costh >= 0.5 && costh <= 1.0) { + double gcos = b6i * costh; + double dgcos = 6.0 * b6i * costh; + gcos += b5i; + dgcos += 5.0 * b5i; + gcos *= costh; + dgcos *= costh; + gcos += b4i; + dgcos += 4.0 * b4i; + gcos *= costh; + dgcos *= costh; + gcos += b3i; + dgcos += 3.0 * b3i; + gcos *= costh; + dgcos *= costh; + gcos += b2i; + dgcos += 2.0 * b2i; + gcos *= costh; + dgcos *= costh; + gcos += b1i; + dgcos += b1i; + gcos *= costh; + gcos += b0i; + + const double bg0i = bg0[typei]; + const double bg1i = bg1[typei]; + const double bg2i = bg2[typei]; + const double bg3i = bg3[typei]; + const double bg4i = bg4[typei]; + const double bg5i = bg5[typei]; + const double bg6i = bg6[typei]; + double gamma = bg6i * costh; + double dgamma = 6.0 * bg6i * costh; + gamma += bg5i; + dgamma += 5.0 * bg5i; + gamma *= costh; + dgamma *= costh; + gamma += bg4i; + dgamma += 4.0 * bg4i; + gamma *= costh; + dgamma *= costh; + gamma += bg3i; + dgamma += 3.0 * bg3i; + gamma *= costh; + dgamma *= costh; + gamma += bg2i; + dgamma += 2.0 * bg2i; + gamma *= costh; + dgamma *= costh; + gamma += bg1i; + dgamma += bg1i; + gamma *= costh; + gamma += bg0i; + + const double tmp = MathConst::MY_2PI * (costh - 0.5); + const double psi = 0.5 * (1 - cos(tmp)); + const double dpsi = MathConst::MY_PI * sin(tmp); + g = gcos + psi * (gamma - gcos); + dgdc = dgcos + dpsi * (gamma - gcos) + psi * (dgamma - dgcos); + } else { + dgdc = 0.0; + } + return g; + } + + /* ---------------------------------------------------------------------- + Pij calculation + ------------------------------------------------------------------------- */ + + inline double PijSpline(const double NM, const double NS, const int typei, double &dp) const + { + const double N = NM + NS; + + dp = -a0[typei] + a1[typei] * a2[typei] * exp(-a2[typei] * N); + return -a0[typei] * (N - 1) - a1[typei] * exp(-a2[typei] * N) + a3[typei]; + } + + void read_file(char *); + void allocate(); + + // ---------------------------------------------------------------------- + // S'(t) and S(t) cutoff functions + // added to header for inlining + // ---------------------------------------------------------------------- + + /* ---------------------------------------------------------------------- + cutoff function Sprime + return cutoff and dX = derivative + no side effects + ------------------------------------------------------------------------- */ + + inline double Sp(double Xij, double Xmin, double Xmax, double &dX) const + { + double cutoff; + + const double t = (Xij - Xmin) / (Xmax - Xmin); + if (t <= 0.0) { + cutoff = 1.0; + dX = 0.0; + } else if (t >= 1.0) { + cutoff = 0.0; + dX = 0.0; + } else { + cutoff = 0.5 * (1.0 + cos(t * MathConst::MY_PI)); + dX = (-0.5 * MathConst::MY_PI * sin(t * MathConst::MY_PI)) / (Xmax - Xmin); + } + return cutoff; + }; +}; +} // namespace LAMMPS_NS + +#endif +#endif diff --git a/unittest/force-styles/tests/manybody-pair-rebomos.yaml b/unittest/force-styles/tests/manybody-pair-rebomos.yaml new file mode 100644 index 0000000000..1d862720af --- /dev/null +++ b/unittest/force-styles/tests/manybody-pair-rebomos.yaml @@ -0,0 +1,126 @@ +--- +lammps_version: 7 Feb 2024 +tags: slow +date_generated: Thu Feb 22 09:08:59 2024 +epsilon: 1e-12 +skip_tests: +prerequisites: ! | + pair rebomos +pre_commands: ! | + variable newton_pair delete + if "$(is_active(package,gpu)) > 0.0" then "variable newton_pair index off" else "variable newton_pair index on" +post_commands: ! | + neigh_modify one 3000 +input_file: in.airebo +pair_style: rebomos +pair_coeff: ! | + * * MoS.rebomos Mo S +extract: ! "" +natoms: 48 +init_vdwl: 3158.017726833385 +init_coul: 0 +init_stress: ! |2- + 6.8398718310371441e+03 6.7325636075141883e+03 6.1154248388685965e+03 -3.2850057579078185e+02 -6.6397329123828470e+01 -3.4208234997867203e+02 +init_forces: ! |2 + 1 -3.7681565852737293e+00 2.4378308384489483e+02 -2.6969740060923279e+01 + 2 2.6266038011491645e+02 -2.0681295165426090e+02 -1.9964225279104706e+01 + 3 -2.5778010496370018e+02 -2.3678496612327552e+02 4.3829487525746238e+01 + 4 -1.0244959408607365e+01 -2.6794342328905179e+02 -2.6250177085935768e+01 + 5 2.2561151172717553e+02 2.0458598509633319e+02 -4.2183143539914880e+01 + 6 -2.4766208404861507e+02 1.8231884233051196e+02 1.2358374858464346e+01 + 7 -2.8974107341390795e+01 1.1031227139363692e+02 -1.2014739688866064e+02 + 8 2.1125868843851663e+02 -2.8863731327540540e+02 1.6869558243398984e+01 + 9 -3.1045083889038222e+02 -1.7569259168198960e+02 7.9653354234911163e+01 + 10 3.9886149586070935e+01 -1.0347554263069082e+02 1.5430519714983259e+02 + 11 1.8975960895859026e+02 1.4943835159807929e+02 -7.3224202319244824e+01 + 12 -2.1525843617159188e+02 2.2144411990369784e+02 -1.4893230739895195e+01 + 13 -4.5214798787473534e+00 1.1303681465405538e+02 -1.1385660017739841e+02 + 14 2.3203040375527121e+02 -3.4422786145586961e+01 1.8438743650405590e+02 + 15 -9.7170644212253990e+01 -2.9205504121924292e+02 1.9237141908302370e+01 + 16 -5.1044169101209107e+01 -1.4503490444304657e+02 1.5798442448724001e+02 + 17 2.8968061091312188e+02 8.7626477818666558e+01 -5.8802357863256212e+01 + 18 -1.7269858357220591e+02 8.9805161881631591e+01 -1.7847636055101773e+02 + 19 1.0760757939777642e+02 1.2642591396366257e+02 1.5914528700154095e+01 + 20 8.4608047558760049e+01 -2.4114295115066687e+02 -8.5792447633922421e+01 + 21 -8.8196263713344706e+01 -1.2718199182512282e+02 -7.0146571930858386e+01 + 22 -9.8957412653883708e+01 -1.4706747771082254e+02 -4.1887992372999022e+01 + 23 1.3739608451158423e+02 2.5576040689729510e+02 3.0309933932861746e+01 + 24 -1.7919184387909232e+02 1.4014151619269020e+02 1.6188399417577682e+02 + 25 -7.7347072523993347e+01 1.5555894832740958e+02 2.6182670200573220e+01 + 26 7.1360176064432650e+01 -2.9346871053231695e+02 -4.0766232856732509e+00 + 27 -2.6964124483003886e+01 9.8094028485618843e+00 2.4520760165936114e+01 + 28 1.2261226472559841e+02 -2.1507437048459283e+02 -3.0529457478077248e+01 + 29 2.2123474818204119e+01 2.8827028167050270e+02 1.0492685172067040e+02 + 30 -3.0573547162322302e+02 6.5880918489915032e+01 -1.1459287271946665e+02 + 31 6.0299759271951014e+00 1.7876996651274851e+02 -1.2964028093837922e+02 + 32 2.3752911820416773e+02 -1.2903240767402318e+02 1.2355068302179771e+02 + 33 -2.7462402312452838e+02 -5.3957296643601545e+01 9.5908146508348565e+01 + 34 -2.4514118579997412e+01 -1.0385194449627924e+02 1.4149428440602534e+02 + 35 1.2613298864651166e+02 6.2171771831118461e+00 -2.0642312645163636e+02 + 36 -6.9996802234927173e+01 2.9354514776980676e+02 -2.0963604805137543e+01 + 37 5.0241789394721707e+01 2.4495589528252060e+02 -1.1814425338523709e+01 + 38 2.2684897209808264e+02 -1.8673318434123004e+02 1.5220428086050066e+00 + 39 -2.5107271651763259e+02 -1.6443685417603410e+02 -3.8081572318769169e+01 + 40 -5.6754727284178912e+01 -2.5956532443118618e+02 -5.9343761520548126e+00 + 41 2.7426370608616236e+02 1.7742153146823480e+02 1.3451000229991498e+01 + 42 -2.2732796257204490e+02 2.5279459742055184e+02 -2.7020668313372529e+01 + 43 1.6217419052721431e+02 1.3946372126978235e+02 -2.0623397237537300e+00 + 44 3.0490806490775839e+01 2.1072542774667330e+01 8.2426559376766466e+00 + 45 -1.8440339212966003e+02 -2.5521581334939563e+02 2.6487508881411735e+01 + 46 -3.5020523296396959e+01 -2.5119105337038474e+02 8.0096253171487604e+00 + 47 3.2722641189388571e+02 9.7949745935413119e+01 -1.1898751818014821e+01 + 48 -1.3785292104885133e+02 3.2239007811982697e+02 2.4602884867061839e+01 +run_vdwl: 838.005031679853 +run_coul: 0 +run_stress: ! |2- + 2.0454406617512559e+03 2.1642975706136021e+03 3.2875013790709349e+03 2.4615001869678809e+02 9.3532964794023911e+01 -1.6795786485689854e+02 +run_forces: ! |2 + 1 -2.5386905249574866e+01 -9.9909927316940710e+01 1.9622022776949393e+00 + 2 -3.6801215363277215e+01 1.3354608905768052e+02 1.3651128931415545e+02 + 3 2.1845136723115344e+00 2.3527273580981478e+00 2.4005941692097457e+00 + 4 -3.7818914621624749e+01 3.2946537814811997e+01 4.3018847892043375e+01 + 5 9.6010433504280890e+00 4.3327442916171194e+01 -1.0513311611209312e+02 + 6 8.4308572792324540e+01 -2.3503352214725012e+01 5.0539884405443850e+01 + 7 -1.1497740491253731e+01 -6.4938790153209212e+01 3.8948855627091397e+01 + 8 -4.2897157525993697e+00 -3.3530261299383611e+01 9.5574489119024229e+00 + 9 4.8767710902858741e-01 -3.5176606358955858e+00 -1.4806227207057554e-01 + 10 -1.4766722110672411e+01 2.3818988804615220e+01 -5.3134339246512809e+01 + 11 -1.3935431402422819e+02 -1.5665571900752980e+02 -3.7627334252485582e+01 + 12 7.7074185304589484e+00 -1.2031768398608595e+01 1.8274050209872662e+01 + 13 2.3670515505343992e+01 -6.4282829210616583e+01 4.6336363412751325e+01 + 14 -2.5980738378663424e+00 8.4167979467127569e+00 -2.3849686761968631e+00 + 15 2.6909213334137871e+01 9.4711670949167956e+00 1.4728430099051328e+00 + 16 2.6072330920174934e+01 1.5861581881675242e+01 -5.1429144994723586e+01 + 17 -4.5656802478750279e+01 -1.0557685195759221e+02 -1.8486644164722456e+01 + 18 1.3345348571390588e+02 5.3791289185967734e+01 3.1330462313925089e+01 + 19 -3.4744179120880638e+01 -2.9727735009574776e+01 1.3758697899848009e+01 + 20 3.5805745710027459e+00 2.3635583506556830e+00 -9.8641913612550636e-01 + 21 -1.9112967021807076e+01 2.4093036642722907e+01 -1.8643238887150801e+01 + 22 -9.0201617792954476e+00 3.7160721932912736e+01 -5.0873237843214003e+00 + 23 -2.0559670924056718e+01 -1.3037172781831362e+01 -4.1555140102832148e+01 + 24 3.5016464856031341e+01 -1.2488249708112150e+02 -5.5132899737529639e+00 + 25 2.4856779395007460e+00 -6.7533673428345381e+01 -1.7153563726726016e+01 + 26 -8.6470517146734750e+01 -7.9057942497429794e+00 3.8434105758101332e+01 + 27 3.1062776626038996e+01 2.5568916700234454e+00 -2.3812255018358194e+01 + 28 -3.6128021960690276e+01 8.8535946500139033e+01 -3.1718315624050986e-01 + 29 -1.7473599694524488e+01 5.1605700760038529e+00 3.1477016370448561e+00 + 30 3.2722165297173231e+00 -5.9807188688706105e+00 3.0903475914489444e+01 + 31 -5.5852599877204412e-01 -3.7635607965114964e+01 5.5407547347738578e+01 + 32 -4.8419811021707950e+01 1.2083134296973620e+02 -1.4299477119499166e+01 + 33 2.5993167832212944e+01 5.4415694550334088e+01 -2.2817585641730194e+01 + 34 1.3632918027769463e+01 1.0165209000060044e+02 -6.0709294862836366e+01 + 35 -1.7896100047169217e+01 5.7265522876438499e+00 6.7274680861552483e+00 + 36 -1.8125137765726237e+01 2.7564787465936047e+00 -9.5278575701404478e+00 + 37 -3.5898678616111592e+00 -7.2362382910010311e+01 -9.3588358281326709e+00 + 38 -3.6726824963125949e+01 2.0008528283799198e+01 4.2387983046244827e+01 + 39 1.4756349734330427e+00 3.4387817449154888e+01 4.6004570693407864e+01 + 40 1.3004687263347805e+01 6.5948251357408196e+01 -9.3870897441198231e+00 + 41 -9.2360908880622592e+00 3.0113497063365648e+00 -1.1785409504259610e+01 + 42 -1.1795417170666214e+01 -1.1546754933247897e+01 -1.2188857610119777e+01 + 43 -6.5511968637617390e-01 -3.9133448932537512e+01 5.5788437875425423e-01 + 44 -4.2976958767216473e+01 1.8814792063050870e+01 -3.2742042602021932e+01 + 45 1.8589630046648591e+02 5.3367997582431663e+01 3.8324469380182308e+01 + 46 2.2463767362468872e+01 7.7485287617829670e+01 2.6113916756613811e+01 + 47 3.0703470673161828e+00 2.4966324680483410e+01 -5.0826014249556524e+00 + 48 7.6310071304830785e+01 -9.3082908173611301e+01 -1.1280958703044767e+02 +... From bed84841ad970da4fc2caefc03d7377fff4a7f61 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 09:57:42 -0500 Subject: [PATCH 37/46] update comment header to point to the LAMMPS developers email address --- src/MANYBODY/pair_rebomos.cpp | 2 +- src/MANYBODY/pair_rebomos.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp index 1211ad5c7e..3e46f86a20 100644 --- a/src/MANYBODY/pair_rebomos.cpp +++ b/src/MANYBODY/pair_rebomos.cpp @@ -2,7 +2,7 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov + 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 diff --git a/src/MANYBODY/pair_rebomos.h b/src/MANYBODY/pair_rebomos.h index 4a530de329..8df4c6b3c9 100644 --- a/src/MANYBODY/pair_rebomos.h +++ b/src/MANYBODY/pair_rebomos.h @@ -1,7 +1,7 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov + 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 From 36fa601fe08a9727f9dbc53bfe696bf10a53e8f3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 13:33:04 -0500 Subject: [PATCH 38/46] cutoff calculation inherited from but only required for AIREBO. up to 2x speedup --- src/MANYBODY/pair_rebomos.cpp | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp index 3e46f86a20..8ba1437aca 100644 --- a/src/MANYBODY/pair_rebomos.cpp +++ b/src/MANYBODY/pair_rebomos.cpp @@ -259,29 +259,8 @@ double PairREBOMoS::init_one(int i, int j) cut3rebo = 3.0 * rcmax[0][0]; - // cutljrebosq = furthest distance from an owned atom a ghost atom can be - // to need its REBO neighs computed - // interaction = M-K-I-J-L-N with I = owned and J = ghost - // this insures N is in the REBO neigh list of L - // since I-J < rcLJmax and J-L < rmax - - double cutljrebo = rcLJmax[0][0] + rcmax[0][0]; - cutljrebosq = cutljrebo * cutljrebo; - - // cutmax = furthest distance from an owned atom - // at which another atom will feel force, i.e. the ghost cutoff - // for REBO term in potential: - // interaction = M-K-I-J-L-N with I = owned and J = ghost - // I to N is max distance = 3 REBO distances - // for LJ term in potential: - // short interaction = M-K-I-J-L-N with I = owned, J = ghost, I-J < rcLJmax - // rcLJmax + 2*rcmax, since I-J < rcLJmax and J-L,L-N = REBO distances - // long interaction = I-J with I = owned and J = ghost - // cutlj*sigma, since I-J < LJ cutoff // cutghost = REBO cutoff used in REBO_neigh() for neighbors of ghosts - double cutmax = MAX(cut3rebo,rcLJmax[0][0] + 2.0*rcmax[0][0]); - cutghost[i][j] = rcmax[ii][jj]; lj1[ii][jj] = 48.0 * epsilon[ii][jj] * powint(sigma[ii][jj],12); lj2[ii][jj] = 24.0 * epsilon[ii][jj] * powint(sigma[ii][jj],6); @@ -294,7 +273,7 @@ double PairREBOMoS::init_one(int i, int j) lj3[jj][ii] = lj3[ii][jj]; lj4[jj][ii] = lj4[ii][jj]; - return cutmax; + return cut3rebo; } /* ---------------------------------------------------------------------- From 22d0b202c4d2c120e3e7937d226c7e7988f4c1ed Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 13:37:59 -0500 Subject: [PATCH 39/46] update example logs for change in cutoff setting --- .../threebody/log.22Feb24.mos2-bulk.g++.1 | 35 +++++++++--------- .../threebody/log.22Feb24.mos2-bulk.g++.4 | 37 +++++++++---------- .../threebody/log.22Feb24.mos2.rebomos.g++.1 | 37 +++++++++---------- .../threebody/log.22Feb24.mos2.rebomos.g++.4 | 37 +++++++++---------- 4 files changed, 71 insertions(+), 75 deletions(-) diff --git a/examples/threebody/log.22Feb24.mos2-bulk.g++.1 b/examples/threebody/log.22Feb24.mos2-bulk.g++.1 index 7822ad40c5..8218026f3d 100644 --- a/examples/threebody/log.22Feb24.mos2-bulk.g++.1 +++ b/examples/threebody/log.22Feb24.mos2-bulk.g++.1 @@ -1,5 +1,4 @@ -LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) -OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-73-g36fa601fe0) using 1 OpenMP thread(s) per MPI task units metal @@ -40,46 +39,46 @@ run 20 Neighbor list info ... update: every = 1 steps, delay = 0 steps, check = yes max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 20.1 - ghost atom cutoff = 20.1 - binsize = 10.05, bins = 3 3 2 + master list distance cutoff = 13.4 + ghost atom cutoff = 13.4 + binsize = 6.7, bins = 5 4 3 1 neighbor lists, perpetual/occasional/extra = 1 0 0 (1) pair rebomos, perpetual attributes: full, newton on, ghost pair build: full/bin/ghost stencil: full/ghost/bin/3d bin: standard -Per MPI rank memory allocation (min/avg/max) = 6.759 | 6.759 | 6.759 Mbytes +Per MPI rank memory allocation (min/avg/max) = 4.996 | 4.996 | 4.996 Mbytes Step Temp Press PotEng KinEng CellGamma Volume 0 0 28799.53 -2061.6112 0 113.40187 5922.4926 10 80.776057 13540.088 -2064.6132 2.9966028 113.40187 5922.4926 20 146.17503 -20669.371 -2067.0428 5.4227518 113.40187 5922.4926 -Loop time of 0.173901 on 1 procs for 20 steps with 288 atoms +Loop time of 0.058071 on 1 procs for 20 steps with 288 atoms -Performance: 9.937 ns/day, 2.415 hours/ns, 115.008 timesteps/s, 33.122 katom-step/s -99.7% CPU use with 1 MPI tasks x 1 OpenMP threads +Performance: 29.757 ns/day, 0.807 hours/ns, 344.406 timesteps/s, 99.189 katom-step/s +99.8% CPU use with 1 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total --------------------------------------------------------------- -Pair | 0.17213 | 0.17213 | 0.17213 | 0.0 | 98.98 +Pair | 0.057666 | 0.057666 | 0.057666 | 0.0 | 99.30 Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 0.0013913 | 0.0013913 | 0.0013913 | 0.0 | 0.80 -Output | 5.0377e-05 | 5.0377e-05 | 5.0377e-05 | 0.0 | 0.03 -Modify | 6.9212e-05 | 6.9212e-05 | 6.9212e-05 | 0.0 | 0.04 -Other | | 0.000264 | | | 0.15 +Comm | 0.00024654 | 0.00024654 | 0.00024654 | 0.0 | 0.42 +Output | 2.3975e-05 | 2.3975e-05 | 2.3975e-05 | 0.0 | 0.04 +Modify | 3.8394e-05 | 3.8394e-05 | 3.8394e-05 | 0.0 | 0.07 +Other | | 9.596e-05 | | | 0.17 Nlocal: 288 ave 288 max 288 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Nghost: 10002 ave 10002 max 10002 min +Nghost: 4285 ave 4285 max 4285 min Histogram: 1 0 0 0 0 0 0 0 0 0 Neighs: 0 ave 0 max 0 min Histogram: 1 0 0 0 0 0 0 0 0 0 -FullNghs: 477120 ave 477120 max 477120 min +FullNghs: 142848 ave 142848 max 142848 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Total # of neighbors = 477120 -Ave neighs/atom = 1656.6667 +Total # of neighbors = 142848 +Ave neighs/atom = 496 Neighbor list builds = 0 Dangerous builds = 0 diff --git a/examples/threebody/log.22Feb24.mos2-bulk.g++.4 b/examples/threebody/log.22Feb24.mos2-bulk.g++.4 index c215d88294..0b9cd3ed8a 100644 --- a/examples/threebody/log.22Feb24.mos2-bulk.g++.4 +++ b/examples/threebody/log.22Feb24.mos2-bulk.g++.4 @@ -1,5 +1,4 @@ -LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) -OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-73-g36fa601fe0) using 1 OpenMP thread(s) per MPI task units metal @@ -23,7 +22,7 @@ Created triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9 create_atoms 2 box basis 1 1 basis 2 1 basis 3 2 basis 4 2 basis 5 2 basis 6 2 Created 288 atoms using lattice units in triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9.5735495 0 0) - create_atoms CPU = 0.001 seconds + create_atoms CPU = 0.000 seconds mass 1 95.95 #Mo mass 2 32.065 #S @@ -40,46 +39,46 @@ run 20 Neighbor list info ... update: every = 1 steps, delay = 0 steps, check = yes max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 20.1 - ghost atom cutoff = 20.1 - binsize = 10.05, bins = 3 3 2 + master list distance cutoff = 13.4 + ghost atom cutoff = 13.4 + binsize = 6.7, bins = 5 4 3 1 neighbor lists, perpetual/occasional/extra = 1 0 0 (1) pair rebomos, perpetual attributes: full, newton on, ghost pair build: full/bin/ghost stencil: full/ghost/bin/3d bin: standard -Per MPI rank memory allocation (min/avg/max) = 4.977 | 4.978 | 4.978 Mbytes +Per MPI rank memory allocation (min/avg/max) = 4.15 | 4.151 | 4.151 Mbytes Step Temp Press PotEng KinEng CellGamma Volume 0 0 28799.53 -2061.6112 0 113.40187 5922.4926 10 80.776057 13540.088 -2064.6132 2.9966028 113.40187 5922.4926 20 146.17503 -20669.371 -2067.0428 5.4227518 113.40187 5922.4926 -Loop time of 0.0644788 on 4 procs for 20 steps with 288 atoms +Loop time of 0.0219485 on 4 procs for 20 steps with 288 atoms -Performance: 26.799 ns/day, 0.896 hours/ns, 310.179 timesteps/s, 89.332 katom-step/s -99.2% CPU use with 4 MPI tasks x 1 OpenMP threads +Performance: 78.730 ns/day, 0.305 hours/ns, 911.225 timesteps/s, 262.433 katom-step/s +96.3% 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.057739 | 0.059918 | 0.06231 | 0.7 | 92.93 +Pair | 0.018118 | 0.019372 | 0.020087 | 0.5 | 88.26 Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 0.0018848 | 0.0042821 | 0.0064683 | 2.6 | 6.64 -Output | 3.7548e-05 | 4.1425e-05 | 5.1594e-05 | 0.0 | 0.06 -Modify | 3.4882e-05 | 3.5821e-05 | 3.6589e-05 | 0.0 | 0.06 -Other | | 0.0002014 | | | 0.31 +Comm | 0.0015635 | 0.0023195 | 0.0035967 | 1.6 | 10.57 +Output | 2.5017e-05 | 4.6834e-05 | 0.00010543 | 0.0 | 0.21 +Modify | 1.3954e-05 | 1.423e-05 | 1.4594e-05 | 0.0 | 0.06 +Other | | 0.0001957 | | | 0.89 Nlocal: 72 ave 72 max 72 min Histogram: 4 0 0 0 0 0 0 0 0 0 -Nghost: 7113.5 ave 7114 max 7113 min +Nghost: 2771.5 ave 2775 max 2768 min Histogram: 2 0 0 0 0 0 0 0 0 2 Neighs: 0 ave 0 max 0 min Histogram: 4 0 0 0 0 0 0 0 0 0 -FullNghs: 119280 ave 119280 max 119280 min +FullNghs: 35712 ave 35712 max 35712 min Histogram: 4 0 0 0 0 0 0 0 0 0 -Total # of neighbors = 477120 -Ave neighs/atom = 1656.6667 +Total # of neighbors = 142848 +Ave neighs/atom = 496 Neighbor list builds = 0 Dangerous builds = 0 diff --git a/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 b/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 index e0a313647d..f7c5b3c74d 100644 --- a/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 +++ b/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 @@ -1,5 +1,4 @@ -LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) -OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-73-g36fa601fe0) using 1 OpenMP thread(s) per MPI task # monolayer MoS2 units metal @@ -15,7 +14,7 @@ WARNING: Triclinic box skew is large. LAMMPS will run inefficiently. (src/domain 1 by 1 by 1 MPI processor grid reading atoms ... 768 atoms - read_data CPU = 0.003 seconds + read_data CPU = 0.002 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 @@ -43,16 +42,16 @@ run 5000 Neighbor list info ... update: every = 1 steps, delay = 0 steps, check = yes max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 20.1 - ghost atom cutoff = 20.1 - binsize = 10.05, bins = 8 5 20 + master list distance cutoff = 13.4 + ghost atom cutoff = 13.4 + binsize = 6.7, bins = 12 7 30 1 neighbor lists, perpetual/occasional/extra = 1 0 0 (1) pair rebomos, perpetual attributes: full, newton on, ghost pair build: full/bin/ghost stencil: full/ghost/bin/3d bin: standard -Per MPI rank memory allocation (min/avg/max) = 5.273 | 5.273 | 5.273 Mbytes +Per MPI rank memory allocation (min/avg/max) = 4.473 | 4.473 | 4.473 Mbytes Step TotEng PotEng KinEng Temp 0 -5466.9785 -5496.7212 29.742759 300 500 -5466.964 -5482.6985 15.734505 158.7059 @@ -65,32 +64,32 @@ Per MPI rank memory allocation (min/avg/max) = 5.273 | 5.273 | 5.273 Mbytes 4000 -5466.9628 -5481.848 14.885236 150.13977 4500 -5466.9648 -5483.5045 16.539775 166.82825 5000 -5466.9649 -5483.4932 16.528298 166.71249 -Loop time of 36.2406 on 1 procs for 5000 steps with 768 atoms +Loop time of 19.1009 on 1 procs for 5000 steps with 768 atoms -Performance: 11.920 ns/day, 2.013 hours/ns, 137.967 timesteps/s, 105.959 katom-step/s +Performance: 22.617 ns/day, 1.061 hours/ns, 261.768 timesteps/s, 201.038 katom-step/s 99.9% CPU use with 1 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total --------------------------------------------------------------- -Pair | 36.14 | 36.14 | 36.14 | 0.0 | 99.72 +Pair | 19.042 | 19.042 | 19.042 | 0.0 | 99.69 Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 0.043166 | 0.043166 | 0.043166 | 0.0 | 0.12 -Output | 0.00021785 | 0.00021785 | 0.00021785 | 0.0 | 0.00 -Modify | 0.034547 | 0.034547 | 0.034547 | 0.0 | 0.10 -Other | | 0.02219 | | | 0.06 +Comm | 0.018451 | 0.018451 | 0.018451 | 0.0 | 0.10 +Output | 0.00015575 | 0.00015575 | 0.00015575 | 0.0 | 0.00 +Modify | 0.023931 | 0.023931 | 0.023931 | 0.0 | 0.13 +Other | | 0.01658 | | | 0.09 Nlocal: 768 ave 768 max 768 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Nghost: 2054 ave 2054 max 2054 min +Nghost: 1158 ave 1158 max 1158 min Histogram: 1 0 0 0 0 0 0 0 0 0 Neighs: 0 ave 0 max 0 min Histogram: 1 0 0 0 0 0 0 0 0 0 -FullNghs: 330752 ave 330752 max 330752 min +FullNghs: 141824 ave 141824 max 141824 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Total # of neighbors = 330752 -Ave neighs/atom = 430.66667 +Total # of neighbors = 141824 +Ave neighs/atom = 184.66667 Neighbor list builds = 0 Dangerous builds = 0 -Total wall time: 0:00:36 +Total wall time: 0:00:19 diff --git a/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 b/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 index 7510c5a793..dc1cfa84d4 100644 --- a/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 +++ b/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 @@ -1,5 +1,4 @@ -LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) -OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-73-g36fa601fe0) using 1 OpenMP thread(s) per MPI task # monolayer MoS2 units metal @@ -43,16 +42,16 @@ run 5000 Neighbor list info ... update: every = 1 steps, delay = 0 steps, check = yes max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 20.1 - ghost atom cutoff = 20.1 - binsize = 10.05, bins = 8 5 20 + master list distance cutoff = 13.4 + ghost atom cutoff = 13.4 + binsize = 6.7, bins = 12 7 30 1 neighbor lists, perpetual/occasional/extra = 1 0 0 (1) pair rebomos, perpetual attributes: full, newton on, ghost pair build: full/bin/ghost stencil: full/ghost/bin/3d bin: standard -Per MPI rank memory allocation (min/avg/max) = 4.464 | 4.464 | 4.464 Mbytes +Per MPI rank memory allocation (min/avg/max) = 4.045 | 4.045 | 4.045 Mbytes Step TotEng PotEng KinEng Temp 0 -5466.9785 -5496.7212 29.742759 300 500 -5466.964 -5482.6985 15.734505 158.7059 @@ -65,32 +64,32 @@ Per MPI rank memory allocation (min/avg/max) = 4.464 | 4.464 | 4.464 Mbytes 4000 -5466.9628 -5481.848 14.885236 150.13977 4500 -5466.9648 -5483.5045 16.539775 166.82825 5000 -5466.9649 -5483.4932 16.528298 166.71249 -Loop time of 10.2878 on 4 procs for 5000 steps with 768 atoms +Loop time of 5.69326 on 4 procs for 5000 steps with 768 atoms -Performance: 41.992 ns/day, 0.572 hours/ns, 486.014 timesteps/s, 373.259 katom-step/s -99.7% CPU use with 4 MPI tasks x 1 OpenMP threads +Performance: 75.879 ns/day, 0.316 hours/ns, 878.231 timesteps/s, 674.482 katom-step/s +98.6% CPU use with 4 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total --------------------------------------------------------------- -Pair | 9.7925 | 9.9286 | 10.096 | 3.6 | 96.51 +Pair | 5.2611 | 5.3666 | 5.4358 | 3.0 | 94.26 Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 0.16754 | 0.33518 | 0.47096 | 19.5 | 3.26 -Output | 0.00016889 | 0.00018727 | 0.00023915 | 0.0 | 0.00 -Modify | 0.010131 | 0.010502 | 0.011106 | 0.4 | 0.10 -Other | | 0.01333 | | | 0.13 +Comm | 0.23476 | 0.30106 | 0.40642 | 12.8 | 5.29 +Output | 0.00014996 | 0.0004478 | 0.0013353 | 0.0 | 0.01 +Modify | 0.0068861 | 0.0069917 | 0.0072247 | 0.2 | 0.12 +Other | | 0.01814 | | | 0.32 Nlocal: 192 ave 194 max 190 min Histogram: 1 0 0 0 0 2 0 0 0 1 -Nghost: 1350 ave 1352 max 1348 min +Nghost: 710 ave 712 max 708 min Histogram: 1 0 0 0 0 2 0 0 0 1 Neighs: 0 ave 0 max 0 min Histogram: 4 0 0 0 0 0 0 0 0 0 -FullNghs: 82688 ave 83548 max 81828 min +FullNghs: 35456 ave 35824 max 35088 min Histogram: 1 0 0 0 0 2 0 0 0 1 -Total # of neighbors = 330752 -Ave neighs/atom = 430.66667 +Total # of neighbors = 141824 +Ave neighs/atom = 184.66667 Neighbor list builds = 0 Dangerous builds = 0 -Total wall time: 0:00:10 +Total wall time: 0:00:05 From 3e512834c739f7edf9f2e8384b923ad8140876e7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 14:09:50 -0500 Subject: [PATCH 40/46] cosmetic --- src/MANYBODY/pair_rebomos.cpp | 7 ++----- src/MANYBODY/pair_rebomos.h | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp index 8ba1437aca..b40ff287cf 100644 --- a/src/MANYBODY/pair_rebomos.cpp +++ b/src/MANYBODY/pair_rebomos.cpp @@ -33,7 +33,6 @@ #include "comm.h" #include "error.h" #include "force.h" -#include "math_const.h" #include "math_special.h" #include "memory.h" #include "my_page.h" @@ -46,14 +45,12 @@ #include using namespace LAMMPS_NS; -using namespace MathConst; using MathSpecial::cube; using MathSpecial::powint; using MathSpecial::square; -#define MAXLINE 1024 -#define TOL 1.0e-9 -#define PGDELTA 1 +static constexpr double TOL = 1.0e-9; +static constexpr int PGDELTA = 1; /* ---------------------------------------------------------------------- */ diff --git a/src/MANYBODY/pair_rebomos.h b/src/MANYBODY/pair_rebomos.h index 8df4c6b3c9..4997c65b87 100644 --- a/src/MANYBODY/pair_rebomos.h +++ b/src/MANYBODY/pair_rebomos.h @@ -20,8 +20,9 @@ PairStyle(rebomos,PairREBOMoS); #ifndef LMP_PAIR_REBOMOS_H #define LMP_PAIR_REBOMOS_H -#include "math_const.h" #include "pair.h" +#include "math_const.h" + #include namespace LAMMPS_NS { From 49886caaf14f79918654f93e303c988a05066240 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 15:17:46 -0500 Subject: [PATCH 41/46] add OPENMP package version of pair style rebomos --- doc/src/Commands_pair.rst | 2 +- doc/src/pair_rebomos.rst | 21 +- doc/utils/sphinx-config/false_positives.txt | 2 + src/MANYBODY/pair_rebomos.cpp | 16 +- src/OPENMP/pair_rebomos_omp.cpp | 702 ++++++++++++++++++++ src/OPENMP/pair_rebomos_omp.h | 46 ++ 6 files changed, 775 insertions(+), 14 deletions(-) create mode 100644 src/OPENMP/pair_rebomos_omp.cpp create mode 100644 src/OPENMP/pair_rebomos_omp.h diff --git a/doc/src/Commands_pair.rst b/doc/src/Commands_pair.rst index 95dd7429e8..9bbe216dec 100644 --- a/doc/src/Commands_pair.rst +++ b/doc/src/Commands_pair.rst @@ -256,7 +256,7 @@ OPT. * :doc:`rann ` * :doc:`reaxff (ko) ` * :doc:`rebo (io) ` - * :doc:`rebomos ` + * :doc:`rebomos (o) ` * :doc:`resquared (go) ` * :doc:`saip/metal (t) ` * :doc:`sdpd/taitwater/isothermal ` diff --git a/doc/src/pair_rebomos.rst b/doc/src/pair_rebomos.rst index 56bf6488bb..9be400e363 100644 --- a/doc/src/pair_rebomos.rst +++ b/doc/src/pair_rebomos.rst @@ -1,7 +1,10 @@ .. index:: pair_style rebomos +.. index:: pair_style rebomos/omp pair_style rebomos command -========================= +========================== + +Accelerator Variants: *rebomos/omp* Syntax """""" @@ -24,7 +27,9 @@ Examples Description """"""""""" -The *rebomos* pair style computes +.. versionadded:: TBD + +The *rebomos* pair style computes ---------- @@ -60,6 +65,10 @@ potentials. ---------- +.. include:: accel_styles.rst + +---------- + Mixing, shift, table, tail correction, restart, rRESPA info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -107,3 +116,11 @@ Default none ---------- + +.. _Stewart: + +**(Steward)** Stewart, Spearot, Modelling Simul. Mater. Sci. Eng. 21,(2013) + +.. _Liang: + +**(Liang)** Liang, Phillpot, Sinnott Phys. Rev. B79 245110, (2009), Erratum: Phys. Rev. B85 199903(E), (2012) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 4f5fe6fdaf..3423b7859b 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -2266,6 +2266,7 @@ morris Morriss morse Morteza +MoS Mosayebi Moseler Moskalev @@ -3070,6 +3071,7 @@ reaxff ReaxFF REAXFF rebo +rebomos recurse recursing Ree diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp index b40ff287cf..d6cea004a7 100644 --- a/src/MANYBODY/pair_rebomos.cpp +++ b/src/MANYBODY/pair_rebomos.cpp @@ -372,7 +372,6 @@ void PairREBOMoS::FREBO(int eflag) int *type = atom->type; tagint *tag = atom->tag; int nlocal = atom->nlocal; - int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; @@ -442,7 +441,7 @@ void PairREBOMoS::FREBO(int eflag) f[j][2] -= delz*fpair; if (eflag) evdwl = VR + bij*VA; - if (evflag) ev_tally(i,j,nlocal,newton_pair,evdwl,0.0,fpair,delx,dely,delz); + if (evflag) ev_tally(i,j,nlocal,/*newton_pair*/1,evdwl,0.0,fpair,delx,dely,delz); } } } @@ -473,7 +472,6 @@ void PairREBOMoS::FLJ(int eflag) tagint *tag = atom->tag; int *type = atom->type; int nlocal = atom->nlocal; - int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; @@ -553,8 +551,7 @@ void PairREBOMoS::FLJ(int eflag) f[j][2] -= delij[2]*fpair; if (eflag) evdwl = VLJ; - if (evflag) ev_tally(i,j,nlocal,newton_pair, - evdwl,0.0,fpair,delij[0],delij[1],delij[2]); + if (evflag) ev_tally(i,j,nlocal,/*newton_pair*/1,evdwl,0.0,fpair,delij[0],delij[1],delij[2]); } } @@ -771,12 +768,9 @@ double PairREBOMoS::bondorder(int i, int j, double rij[3], double rijmag, double cosijl = MIN(cosijl,1.0); cosijl = MAX(cosijl,-1.0); - dcosijldri[0] = (-rjl[0]/(rijmag*rjlmag)) - - (cosijl*rij[0]/(rijmag*rijmag)); - dcosijldri[1] = (-rjl[1]/(rijmag*rjlmag)) - - (cosijl*rij[1]/(rijmag*rijmag)); - dcosijldri[2] = (-rjl[2]/(rijmag*rjlmag)) - - (cosijl*rij[2]/(rijmag*rijmag)); + dcosijldri[0] = (-rjl[0]/(rijmag*rjlmag)) - (cosijl*rij[0]/(rijmag*rijmag)); + dcosijldri[1] = (-rjl[1]/(rijmag*rjlmag)) - (cosijl*rij[1]/(rijmag*rijmag)); + dcosijldri[2] = (-rjl[2]/(rijmag*rjlmag)) - (cosijl*rij[2]/(rijmag*rijmag)); dcosijldrj[0] = ((-rij[0]+rjl[0])/(rijmag*rjlmag)) + (cosijl*((rij[0]/square(rijmag))-(rjl[0]/(rjlmag*rjlmag)))); dcosijldrj[1] = ((-rij[1]+rjl[1])/(rijmag*rjlmag)) + diff --git a/src/OPENMP/pair_rebomos_omp.cpp b/src/OPENMP/pair_rebomos_omp.cpp new file mode 100644 index 0000000000..5143fd0f63 --- /dev/null +++ b/src/OPENMP/pair_rebomos_omp.cpp @@ -0,0 +1,702 @@ +// 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + References: + + This code: + Stewart J A and Spearot D E (2013) Atomistic simulations of nanoindentation on the basal plane of crystalline molybdenum disulfide. Modelling Simul. Mater. Sci. Eng. 21. + + Based on: + Liang T, Phillpot S R and Sinnott S B (2009) Parameterization of a reactive many-body potential for Mo2S systems. Phys. Rev. B79 245110. + Liang T, Phillpot S R and Sinnott S B (2012) Erratum: Parameterization of a reactive many-body potential for Mo-S systems. (Phys. Rev. B79 245110 (2009)) Phys. Rev. B85 199903(E). + + LAMMPS file contributing authors: James Stewart, Khanh Dang and Douglas Spearot (University of Arkansas) +------------------------------------------------------------------------- */ + +// clang-format on + +#include "pair_rebomos_omp.h" + +#include "atom.h" +#include "comm.h" +#include "error.h" +#include "math_special.h" +#include "memory.h" +#include "my_page.h" +#include "neigh_list.h" + +#include "suffix.h" + +#include + +#include "omp_compat.h" +#if defined(_OPENMP) +#include +#endif + +using namespace LAMMPS_NS; +using namespace MathConst; +using MathSpecial::cube; +using MathSpecial::powint; +using MathSpecial::square; + +static constexpr double TOL = 1.0e-9; + +/* ---------------------------------------------------------------------- */ + +PairREBOMoSOMP::PairREBOMoSOMP(LAMMPS *lmp) : PairREBOMoS(lmp), ThrOMP(lmp, THR_PAIR) +{ + suffix_flag |= Suffix::OMP; + respa_enable = 0; +} + +// clang-format off + +/* ---------------------------------------------------------------------- */ + +void PairREBOMoSOMP::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); + + REBO_neigh_thr(); + + 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); + + FREBO_thr(ifrom,ito,eflag,thr); + FLJ_thr(ifrom,ito,eflag,thr); + + thr->timer(Timer::PAIR); + reduce_thr(this, eflag, vflag, thr); + } // end of omp parallel region +} + +/* ---------------------------------------------------------------------- + create REBO neighbor list from main neighbor list + REBO neighbor list stores neighbors of ghost atoms +------------------------------------------------------------------------- */ + +void PairREBOMoSOMP::REBO_neigh_thr() +{ + const int nthreads = comm->nthreads; + + if (atom->nmax > maxlocal) { + maxlocal = atom->nmax; + memory->destroy(REBO_numneigh); + memory->sfree(REBO_firstneigh); + memory->destroy(nM); + memory->destroy(nS); + memory->create(REBO_numneigh,maxlocal,"REBOMoS:numneigh"); + REBO_firstneigh = (int **) memory->smalloc(maxlocal*sizeof(int *), + "REBOMoS:firstneigh"); + memory->create(nM,maxlocal,"REBOMoS:nM"); + memory->create(nS,maxlocal,"REBOMoS:nS"); + } + +#if defined(_OPENMP) +#pragma omp parallel LMP_DEFAULT_NONE +#endif + { + int i,j,ii,jj,n,jnum,itype,jtype; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq,dS; + int *ilist,*jlist,*numneigh,**firstneigh; + int *neighptr; + + double **x = atom->x; + int *type = atom->type; + + const int allnum = list->inum + list->gnum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + +#if defined(_OPENMP) + const int tid = omp_get_thread_num(); +#else + const int tid = 0; +#endif + + const int iidelta = 1 + allnum/nthreads; + const int iifrom = tid*iidelta; + const int iito = ((iifrom+iidelta)>allnum) ? allnum : (iifrom+iidelta); + + // store all REBO neighs of owned and ghost atoms + // scan full neighbor list of I + + // each thread has its own page allocator + MyPage &ipg = ipage[tid]; + ipg.reset(); + + for (ii = iifrom; ii < iito; ii++) { + i = ilist[ii]; + + n = 0; + neighptr = ipg.vget(); + + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + itype = map[type[i]]; + nM[i] = nS[i] = 0.0; + jlist = firstneigh[i]; + jnum = numneigh[i]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + jtype = map[type[j]]; + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + + if (rsq < rcmaxsq[itype][jtype]) { + neighptr[n++] = j; + if (jtype == 0) + nM[i] += Sp(sqrt(rsq),rcmin[itype][jtype],rcmax[itype][jtype],dS); + else + nS[i] += Sp(sqrt(rsq),rcmin[itype][jtype],rcmax[itype][jtype],dS); + } + } + + REBO_firstneigh[i] = neighptr; + REBO_numneigh[i] = n; + ipg.vgot(n); + if (ipg.status()) + error->one(FLERR,"REBO list overflow, boost neigh_modify one"); + } + } +} + +/* ---------------------------------------------------------------------- + REBO forces and energy +------------------------------------------------------------------------- */ + +void PairREBOMoSOMP::FREBO_thr(int ifrom, int ito, int eflag, ThrData * const thr) +{ + int i,j,k,ii,itype,jtype; + tagint itag, jtag; + double delx,dely,delz,evdwl,fpair,xtmp,ytmp,ztmp; + double rsq,rij,wij; + double Qij,Aij,alphaij,VR,pre,dVRdi,VA,bij,dVAdi,dVA; + double dwij,del[3]; + int *ilist,*REBO_neighs; + + evdwl = 0.0; + + const double * const * const x = atom->x; + double * const * const f = thr->get_f(); + const int * const type = atom->type; + const tagint * const tag = atom->tag; + const int nlocal = atom->nlocal; + + ilist = list->ilist; + + // two-body interactions from REBO neighbor list, skip half of them + + for (ii = ifrom; ii < ito; ii++) { + i = ilist[ii]; + itag = tag[i]; + itype = map[type[i]]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + REBO_neighs = REBO_firstneigh[i]; + + for (k = 0; k < REBO_numneigh[i]; k++) { + j = REBO_neighs[k]; + 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][2] < ztmp) continue; + if (x[j][2] == ztmp && x[j][1] < ytmp) continue; + if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue; + } + + jtype = map[type[j]]; + + delx = x[i][0] - x[j][0]; + dely = x[i][1] - x[j][1]; + delz = x[i][2] - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + rij = sqrt(rsq); + wij = Sp(rij,rcmin[itype][jtype],rcmax[itype][jtype],dwij); + if (wij <= TOL) continue; + + Qij = Q[itype][jtype]; + Aij = A[itype][jtype]; + alphaij = alpha[itype][jtype]; + + VR = wij*(1.0+(Qij/rij)) * Aij*exp(-alphaij*rij); + pre = wij*Aij * exp(-alphaij*rij); + dVRdi = pre * ((-alphaij)-(Qij/rsq)-(Qij*alphaij/rij)); + dVRdi += VR/wij * dwij; + + VA = dVA = 0.0; + VA = -wij * BIJc[itype][jtype] * exp(-Beta[itype][jtype]*rij); + + dVA = -Beta[itype][jtype] * VA; + dVA += VA/wij * dwij; + + del[0] = delx; + del[1] = dely; + del[2] = delz; + bij = bondorder_thr(i,j,del,rij,VA,thr); + dVAdi = bij*dVA; + + fpair = -(dVRdi+dVAdi) / rij; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; + + if (eflag) evdwl = VR + bij*VA; + if (evflag) ev_tally_thr(this,i,j,nlocal,/* newton_pair */1,evdwl,0.0,fpair,delx,dely,delz,thr); + } + } +} + +/* ---------------------------------------------------------------------- + compute LJ forces and energy +------------------------------------------------------------------------- */ + +void PairREBOMoSOMP::FLJ_thr(int ifrom, int ito, int eflag, ThrData * const thr) +{ + int i,j,ii,jj,jnum,itype,jtype; + tagint itag,jtag; + double evdwl,fpair,xtmp,ytmp,ztmp; + double rij,delij[3],rijsq; + double VLJ,dVLJ; + double vdw,dvdw; + double r2inv,r6inv; + int *ilist,*jlist,*numneigh,**firstneigh; + double c2,c3,dr,drp,r6; + + // I-J interaction from full neighbor list + // skip 1/2 of interactions since only consider each pair once + + evdwl = 0.0; + + const double * const * const x = atom->x; + double * const * const f = thr->get_f(); + const tagint * const tag = atom->tag; + const int * const type = atom->type; + const int nlocal = atom->nlocal; + + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // loop over neighbors of my atoms + + for (ii = ifrom; ii < ito; ii++) { + i = ilist[ii]; + itag = tag[i]; + itype = map[type[i]]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + 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][2] < ztmp) continue; + if (x[j][2] == ztmp && x[j][1] < ytmp) continue; + if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue; + } + jtype = map[type[j]]; + + delij[0] = xtmp - x[j][0]; + delij[1] = ytmp - x[j][1]; + delij[2] = ztmp - x[j][2]; + rijsq = delij[0]*delij[0] + delij[1]*delij[1] + delij[2]*delij[2]; + rij = sqrt(rijsq); + + // compute LJ forces and energy + + // Outside Rmax + if (rij > rcLJmax[itype][jtype] || rij < rcLJmin[itype][jtype]){ + VLJ = 0; + dVLJ = 0; + } + + // Inside Rmax and above 0.95*sigma + else if (rij <= rcLJmax[itype][jtype] && rij >= 0.95*sigma[itype][jtype]){ + r2inv = 1.0/rijsq; + r6inv = r2inv*r2inv*r2inv; + VLJ = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); + dVLJ = -r6inv*(lj1[itype][jtype]*r6inv - lj2[itype][jtype])/rij; + } + + // Below 0.95*sigma + else if (rij < 0.95*sigma[itype][jtype] && rij >= rcLJmin[itype][jtype]){ + dr = 0.95*sigma[itype][jtype] - rcLJmin[itype][jtype]; + r6 = powint((sigma[itype][jtype]/(0.95*sigma[itype][jtype])),6); + vdw = 4*epsilon[itype][jtype]*r6*(r6 - 1.0); + dvdw = (-4*epsilon[itype][jtype]/(0.95*sigma[itype][jtype]))*r6*(12.0*r6 - 6.0); + c2 = ((3.0/dr)*vdw - dvdw)/dr; + c3 = (vdw/(dr*dr) - c2)/dr; + + drp = rij - rcLJmin[itype][jtype]; + VLJ = drp*drp*(drp*c3 + c2); + dVLJ = drp*(3.0*drp*c3 + 2.0*c2); + } + + fpair = -dVLJ/rij; + f[i][0] += delij[0]*fpair; + f[i][1] += delij[1]*fpair; + f[i][2] += delij[2]*fpair; + f[j][0] -= delij[0]*fpair; + f[j][1] -= delij[1]*fpair; + f[j][2] -= delij[2]*fpair; + + if (eflag) evdwl = VLJ; + if (evflag) ev_tally_thr(this,i,j,nlocal,/*newton_pair*/1,evdwl,0.0,fpair,delij[0],delij[1],delij[2],thr); + + } + } +} + +/* ---------------------------------------------------------------------- + Bij function + + The bond order term modified the attractive portion of the REBO + potential based on the number of atoms around a specific pair + and the bond angle between sets of three atoms. + + The functions G(cos(theta)) and P(N) are evaluated and their + derivatives are also computed for use in the force calculation. +------------------------------------------------------------------------- */ + +double PairREBOMoSOMP::bondorder_thr(int i, int j, double rij[3], double rijmag, double VA, ThrData *thr) +{ + int atomi,atomj,atomk,atoml; + int k,l; + int itype, jtype, ktype, ltype; + double rik[3], rjl[3], rji[3], rki[3],rlj[3], dwjl, bij; + double NijM,NijS,NjiM,NjiS,wik,dwik,wjl; + double rikmag,rjlmag,cosjik,cosijl,g,tmp2; + double Etmp,pij,tmp,dwij,dS; + double dgdc,pji; + double dcosjikdri[3],dcosijldri[3],dcosjikdrk[3]; + double dp; + double dcosjikdrj[3],dcosijldrj[3],dcosijldrl[3]; + double fi[3],fj[3],fk[3],fl[3]; + double PijS, PjiS; + int *REBO_neighs; + + const double * const * const x = atom->x; + double * const * const f = thr->get_f(); + const int * const type = atom->type; + + atomi = i; + atomj = j; + itype = map[type[i]]; + jtype = map[type[j]]; + Sp(rijmag,rcmin[itype][jtype],rcmax[itype][jtype],dwij); + NijM = nM[i]; + NijS = nS[i]; + NjiM = nM[j]; + NjiS = nS[j]; + bij = 0.0; + tmp = 0.0; + tmp2 = 0.0; + dgdc = 0.0; + Etmp = 0.0; + + REBO_neighs = REBO_firstneigh[i]; + for (k = 0; k < REBO_numneigh[i]; k++) { + atomk = REBO_neighs[k]; + if (atomk != atomj) { + ktype = map[type[atomk]]; + rik[0] = x[atomi][0]-x[atomk][0]; + rik[1] = x[atomi][1]-x[atomk][1]; + rik[2] = x[atomi][2]-x[atomk][2]; + rikmag = sqrt((rik[0]*rik[0])+(rik[1]*rik[1])+(rik[2]*rik[2])); + wik = Sp(rikmag,rcmin[itype][ktype],rcmax[itype][ktype],dS); + cosjik = ((rij[0]*rik[0])+(rij[1]*rik[1])+(rij[2]*rik[2])) / (rijmag*rikmag); + cosjik = MIN(cosjik,1.0); + cosjik = MAX(cosjik,-1.0); + + // evaluate g and derivative dg + + g = gSpline(cosjik,itype,dgdc); + Etmp = Etmp+(wik*g); + } + } + + dp = 0.0; + PijS = PijSpline(NijM,NijS,itype,dp); + pij = 1.0/sqrt(1.0+Etmp+PijS); + tmp = -0.5*cube(pij); + + // derivative calculations + + REBO_neighs = REBO_firstneigh[i]; + for (k = 0; k < REBO_numneigh[i]; k++) { + atomk = REBO_neighs[k]; + if (atomk != atomj) { + ktype = map[type[atomk]]; + rik[0] = x[atomi][0]-x[atomk][0]; + rik[1] = x[atomi][1]-x[atomk][1]; + rik[2] = x[atomi][2]-x[atomk][2]; + rikmag = sqrt((rik[0]*rik[0])+(rik[1]*rik[1])+(rik[2]*rik[2])); + wik = Sp(rikmag,rcmin[itype][ktype],rcmax[itype][ktype],dwik); + cosjik = (rij[0]*rik[0] + rij[1]*rik[1] + rij[2]*rik[2]) / (rijmag*rikmag); + cosjik = MIN(cosjik,1.0); + cosjik = MAX(cosjik,-1.0); + + dcosjikdri[0] = ((rij[0]+rik[0])/(rijmag*rikmag)) - + (cosjik*((rij[0]/(rijmag*rijmag))+(rik[0]/(rikmag*rikmag)))); + dcosjikdri[1] = ((rij[1]+rik[1])/(rijmag*rikmag)) - + (cosjik*((rij[1]/(rijmag*rijmag))+(rik[1]/(rikmag*rikmag)))); + dcosjikdri[2] = ((rij[2]+rik[2])/(rijmag*rikmag)) - + (cosjik*((rij[2]/(rijmag*rijmag))+(rik[2]/(rikmag*rikmag)))); + dcosjikdrk[0] = (-rij[0]/(rijmag*rikmag)) + + (cosjik*(rik[0]/(rikmag*rikmag))); + dcosjikdrk[1] = (-rij[1]/(rijmag*rikmag)) + + (cosjik*(rik[1]/(rikmag*rikmag))); + dcosjikdrk[2] = (-rij[2]/(rijmag*rikmag)) + + (cosjik*(rik[2]/(rikmag*rikmag))); + dcosjikdrj[0] = (-rik[0]/(rijmag*rikmag)) + + (cosjik*(rij[0]/(rijmag*rijmag))); + dcosjikdrj[1] = (-rik[1]/(rijmag*rikmag)) + + (cosjik*(rij[1]/(rijmag*rijmag))); + dcosjikdrj[2] = (-rik[2]/(rijmag*rikmag)) + + (cosjik*(rij[2]/(rijmag*rijmag))); + + g = gSpline(cosjik,itype,dgdc); + tmp2 = VA*0.5*(tmp*wik*dgdc); + fj[0] = -tmp2*dcosjikdrj[0]; + fj[1] = -tmp2*dcosjikdrj[1]; + fj[2] = -tmp2*dcosjikdrj[2]; + fi[0] = -tmp2*dcosjikdri[0]; + fi[1] = -tmp2*dcosjikdri[1]; + fi[2] = -tmp2*dcosjikdri[2]; + fk[0] = -tmp2*dcosjikdrk[0]; + fk[1] = -tmp2*dcosjikdrk[1]; + fk[2] = -tmp2*dcosjikdrk[2]; + + // coordination forces + + // dwik forces (from partial derivative) + + tmp2 = VA*0.5*(tmp*dwik*g)/rikmag; + fi[0] -= tmp2*rik[0]; + fi[1] -= tmp2*rik[1]; + fi[2] -= tmp2*rik[2]; + fk[0] += tmp2*rik[0]; + fk[1] += tmp2*rik[1]; + fk[2] += tmp2*rik[2]; + + // PIJ forces (from coordination P(N) term) + + tmp2 = VA*0.5*(tmp*dp*dwik)/rikmag; + fi[0] -= tmp2*rik[0]; + fi[1] -= tmp2*rik[1]; + fi[2] -= tmp2*rik[2]; + fk[0] += tmp2*rik[0]; + fk[1] += tmp2*rik[1]; + fk[2] += tmp2*rik[2]; + + // dgdN forces are removed + + f[atomi][0] += fi[0]; f[atomi][1] += fi[1]; f[atomi][2] += fi[2]; + f[atomj][0] += fj[0]; f[atomj][1] += fj[1]; f[atomj][2] += fj[2]; + f[atomk][0] += fk[0]; f[atomk][1] += fk[1]; f[atomk][2] += fk[2]; + + if (vflag_either) { + rji[0] = -rij[0]; rji[1] = -rij[1]; rji[2] = -rij[2]; + rki[0] = -rik[0]; rki[1] = -rik[1]; rki[2] = -rik[2]; + v_tally3_thr(this,atomi,atomj,atomk,fj,fk,rji,rki,thr); + } + } + } + + // PIJ force contribution additional term + tmp2 = -VA*0.5*(tmp*dp*dwij)/rijmag; + + f[atomi][0] += rij[0]*tmp2; + f[atomi][1] += rij[1]*tmp2; + f[atomi][2] += rij[2]*tmp2; + f[atomj][0] -= rij[0]*tmp2; + f[atomj][1] -= rij[1]*tmp2; + f[atomj][2] -= rij[2]*tmp2; + + if (vflag_either) v_tally2_thr(this,atomi,atomj,tmp2,rij,thr); + + tmp = 0.0; + tmp2 = 0.0; + Etmp = 0.0; + + REBO_neighs = REBO_firstneigh[j]; + for (l = 0; l < REBO_numneigh[j]; l++) { + atoml = REBO_neighs[l]; + if (atoml != atomi) { + ltype = map[type[atoml]]; + rjl[0] = x[atomj][0]-x[atoml][0]; + rjl[1] = x[atomj][1]-x[atoml][1]; + rjl[2] = x[atomj][2]-x[atoml][2]; + rjlmag = sqrt((rjl[0]*rjl[0])+(rjl[1]*rjl[1])+(rjl[2]*rjl[2])); + wjl = Sp(rjlmag,rcmin[jtype][ltype],rcmax[jtype][ltype],dS); + cosijl = -1.0*((rij[0]*rjl[0])+(rij[1]*rjl[1])+(rij[2]*rjl[2])) / (rijmag*rjlmag); + cosijl = MIN(cosijl,1.0); + cosijl = MAX(cosijl,-1.0); + + // evaluate g and derivative dg + + g = gSpline(cosijl,jtype,dgdc); + Etmp = Etmp+(wjl*g); + } + } + + dp = 0.0; + PjiS = PijSpline(NjiM,NjiS,jtype,dp); + pji = 1.0/sqrt(1.0+Etmp+PjiS); + tmp = -0.5*cube(pji); + + REBO_neighs = REBO_firstneigh[j]; + for (l = 0; l < REBO_numneigh[j]; l++) { + atoml = REBO_neighs[l]; + if (atoml != atomi) { + ltype = map[type[atoml]]; + rjl[0] = x[atomj][0]-x[atoml][0]; + rjl[1] = x[atomj][1]-x[atoml][1]; + rjl[2] = x[atomj][2]-x[atoml][2]; + rjlmag = sqrt((rjl[0]*rjl[0])+(rjl[1]*rjl[1])+(rjl[2]*rjl[2])); + wjl = Sp(rjlmag,rcmin[jtype][ltype],rcmax[jtype][ltype],dwjl); + cosijl = (-1.0*((rij[0]*rjl[0])+(rij[1]*rjl[1])+(rij[2]*rjl[2]))) / (rijmag*rjlmag); + cosijl = MIN(cosijl,1.0); + cosijl = MAX(cosijl,-1.0); + + dcosijldri[0] = (-rjl[0]/(rijmag*rjlmag)) - + (cosijl*rij[0]/(rijmag*rijmag)); + dcosijldri[1] = (-rjl[1]/(rijmag*rjlmag)) - + (cosijl*rij[1]/(rijmag*rijmag)); + dcosijldri[2] = (-rjl[2]/(rijmag*rjlmag)) - + (cosijl*rij[2]/(rijmag*rijmag)); + dcosijldrj[0] = ((-rij[0]+rjl[0])/(rijmag*rjlmag)) + + (cosijl*((rij[0]/square(rijmag))-(rjl[0]/(rjlmag*rjlmag)))); + dcosijldrj[1] = ((-rij[1]+rjl[1])/(rijmag*rjlmag)) + + (cosijl*((rij[1]/square(rijmag))-(rjl[1]/(rjlmag*rjlmag)))); + dcosijldrj[2] = ((-rij[2]+rjl[2])/(rijmag*rjlmag)) + + (cosijl*((rij[2]/square(rijmag))-(rjl[2]/(rjlmag*rjlmag)))); + dcosijldrl[0] = (rij[0]/(rijmag*rjlmag))+(cosijl*rjl[0]/(rjlmag*rjlmag)); + dcosijldrl[1] = (rij[1]/(rijmag*rjlmag))+(cosijl*rjl[1]/(rjlmag*rjlmag)); + dcosijldrl[2] = (rij[2]/(rijmag*rjlmag))+(cosijl*rjl[2]/(rjlmag*rjlmag)); + + // evaluate g and derivatives dg + + g = gSpline(cosijl,jtype,dgdc); + tmp2 = VA*0.5*(tmp*wjl*dgdc); + fi[0] = -tmp2*dcosijldri[0]; + fi[1] = -tmp2*dcosijldri[1]; + fi[2] = -tmp2*dcosijldri[2]; + fj[0] = -tmp2*dcosijldrj[0]; + fj[1] = -tmp2*dcosijldrj[1]; + fj[2] = -tmp2*dcosijldrj[2]; + fl[0] = -tmp2*dcosijldrl[0]; + fl[1] = -tmp2*dcosijldrl[1]; + fl[2] = -tmp2*dcosijldrl[2]; + + // coordination forces + + // dwik forces (from partial derivative) + + tmp2 = VA*0.5*(tmp*dwjl*g)/rjlmag; + fj[0] -= tmp2*rjl[0]; + fj[1] -= tmp2*rjl[1]; + fj[2] -= tmp2*rjl[2]; + fl[0] += tmp2*rjl[0]; + fl[1] += tmp2*rjl[1]; + fl[2] += tmp2*rjl[2]; + + // PIJ forces (coordination) + + tmp2 = VA*0.5*(tmp*dp*dwjl)/rjlmag; + fj[0] -= tmp2*rjl[0]; + fj[1] -= tmp2*rjl[1]; + fj[2] -= tmp2*rjl[2]; + fl[0] += tmp2*rjl[0]; + fl[1] += tmp2*rjl[1]; + fl[2] += tmp2*rjl[2]; + + // dgdN forces are removed + + f[atomi][0] += fi[0]; f[atomi][1] += fi[1]; f[atomi][2] += fi[2]; + f[atomj][0] += fj[0]; f[atomj][1] += fj[1]; f[atomj][2] += fj[2]; + f[atoml][0] += fl[0]; f[atoml][1] += fl[1]; f[atoml][2] += fl[2]; + + if (vflag_either) { + rlj[0] = -rjl[0]; rlj[1] = -rjl[1]; rlj[2] = -rjl[2]; + v_tally3_thr(this,atomi,atomj,atoml,fi,fl,rij,rlj,thr); + } + } + } + + // PIJ force contribution additional term + + tmp2 = -VA*0.5*(tmp*dp*dwij)/rijmag; + f[atomi][0] += rij[0]*tmp2; + f[atomi][1] += rij[1]*tmp2; + f[atomi][2] += rij[2]*tmp2; + f[atomj][0] -= rij[0]*tmp2; + f[atomj][1] -= rij[1]*tmp2; + f[atomj][2] -= rij[2]*tmp2; + + if (vflag_either) v_tally2_thr(this,atomi,atomj,tmp2,rij,thr); + + bij = (0.5*(pij+pji)); + return bij; +} + +/* ---------------------------------------------------------------------- + memory usage of local atom-based arrays +------------------------------------------------------------------------- */ + +double PairREBOMoSOMP::memory_usage() +{ + double bytes = memory_usage_thr(); + bytes += PairREBOMoS::memory_usage(); + + return bytes; +} diff --git a/src/OPENMP/pair_rebomos_omp.h b/src/OPENMP/pair_rebomos_omp.h new file mode 100644 index 0000000000..ea87f51950 --- /dev/null +++ b/src/OPENMP/pair_rebomos_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. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS +// clang-format off +PairStyle(rebomos/omp,PairREBOMoSOMP); +// clang-format on +#else + +#ifndef LMP_PAIR_REBOMOS_OMP_H +#define LMP_PAIR_REBOMOS_OMP_H + +#include "pair_rebomos.h" +#include "thr_omp.h" + +namespace LAMMPS_NS { + +class PairREBOMoSOMP : public PairREBOMoS, public ThrOMP { + public: + PairREBOMoSOMP(class LAMMPS *); + + void compute(int, int) override; + double memory_usage() override; + + protected: + void FREBO_thr(int ifrom, int ito, int eflag, ThrData *const thr); + void FLJ_thr(int ifrom, int ito, int eflag, ThrData *const thr); + + void REBO_neigh_thr(); + + double bondorder_thr(int, int, double *, double, double, ThrData *const thr); +}; +} // namespace LAMMPS_NS + +#endif +#endif From f864963ab94ba88828cc77ffd0ecd1902313b1e3 Mon Sep 17 00:00:00 2001 From: sakibmatin Date: Thu, 22 Feb 2024 22:03:29 -0700 Subject: [PATCH 42/46] removed old comments. --- src/KOKKOS/mliap_unified_kokkos.cpp | 2 +- src/ML-IAP/mliap_unified.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/KOKKOS/mliap_unified_kokkos.cpp b/src/KOKKOS/mliap_unified_kokkos.cpp index 4a8c14d723..68caf035e9 100644 --- a/src/KOKKOS/mliap_unified_kokkos.cpp +++ b/src/KOKKOS/mliap_unified_kokkos.cpp @@ -380,7 +380,7 @@ void LAMMPS_NS::update_atom_energy(MLIAPDataKokkosDevice *data, double *ei) Kokkos::parallel_reduce(nlocal, KOKKOS_LAMBDA(int i, double &local_sum){ double e = ei[i]; - // must not count any contribution where i is not a local atom + d_eatoms[i] = e; local_sum += e; },*data->energy); diff --git a/src/ML-IAP/mliap_unified.cpp b/src/ML-IAP/mliap_unified.cpp index 6dcdf94c2d..7697204e44 100644 --- a/src/ML-IAP/mliap_unified.cpp +++ b/src/ML-IAP/mliap_unified.cpp @@ -275,7 +275,6 @@ void LAMMPS_NS::update_pair_forces(MLIAPData *data, double *fij) int i = data->pair_i[ii]; int j = data->jatoms[ii]; - // must not count any contribution where i is not a local atom f[i][0] += fij[ii3]; f[i][1] += fij[ii3 + 1]; f[i][2] += fij[ii3 + 2]; From a3f2c5b8845695f1411dcb48a959edf49f8229ff Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 16:48:03 -0500 Subject: [PATCH 43/46] no longer need to boost neighbor one in rebomos unit test --- unittest/force-styles/tests/manybody-pair-rebomos.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unittest/force-styles/tests/manybody-pair-rebomos.yaml b/unittest/force-styles/tests/manybody-pair-rebomos.yaml index 1d862720af..74fbe2b001 100644 --- a/unittest/force-styles/tests/manybody-pair-rebomos.yaml +++ b/unittest/force-styles/tests/manybody-pair-rebomos.yaml @@ -9,8 +9,7 @@ prerequisites: ! | pre_commands: ! | variable newton_pair delete if "$(is_active(package,gpu)) > 0.0" then "variable newton_pair index off" else "variable newton_pair index on" -post_commands: ! | - neigh_modify one 3000 +post_commands: ! "" input_file: in.airebo pair_style: rebomos pair_coeff: ! | From 66701ef1e2d492dfa3619952e2704c9ff97f89f8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 17:29:31 -0500 Subject: [PATCH 44/46] complete rebomos docs --- doc/src/pair_rebomos.rst | 26 ++++++++++++++++++++- doc/utils/sphinx-config/false_positives.txt | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/src/pair_rebomos.rst b/doc/src/pair_rebomos.rst index 9be400e363..9466deb338 100644 --- a/doc/src/pair_rebomos.rst +++ b/doc/src/pair_rebomos.rst @@ -23,14 +23,34 @@ Examples pair_style rebomos pair_coeff * * ../potentials/MoS.rebomos Mo S +Example input scripts available: examples/threebody/ Description """"""""""" .. versionadded:: TBD -The *rebomos* pair style computes +The *rebomos* pair style computes the interactions between molybdenum +and sulfur atoms :ref:`(Stewart) ` utilizing an adaptive +interatomic reactive empirical bond order potential that is similar in +form to the AIREBO potential :ref:`(Stuart) `. The potential +is based on an earlier parameterizations for :math:`\text{MoS}_2` +developed by :ref:`(Liang) `. +The REBOMoS potential consists of two terms: + +.. math:: + + E & = \frac{1}{2} \sum_i \sum_{j \neq i} + \left[ E^{\text{REBO}}_{ij} + E^{\text{LJ}}_{ij} \right] \\ + +The :math:`E^{\text{REBO}}` term describes the covalently bonded +interactions between Mo and S atoms while the :math:`E^{\text{LJ}}` term +describes longer range dispersion forces between layers. A cubic spline +function is applied to smoothly switch between covalent bonding at short +distances to dispersion interactions at longer distances. This allows +the model to capture bond formation and breaking events which may occur +between adjacent MoS2 layers, edges, defects, and more. ---------- @@ -121,6 +141,10 @@ none **(Steward)** Stewart, Spearot, Modelling Simul. Mater. Sci. Eng. 21,(2013) +.. _Stuart2: + +**(Stuart)** Stuart, Tutein, Harrison, J Chem Phys, 112, 6472-6486. (2000). + .. _Liang: **(Liang)** Liang, Phillpot, Sinnott Phys. Rev. B79 245110, (2009), Erratum: Phys. Rev. B85 199903(E), (2012) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 3423b7859b..e46fb6ca97 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -3599,6 +3599,7 @@ tesselation tesselations Tetot tex +textrm tfac tfmc tfMC From b7153eebee475d25bd9851ff9fea7ae153c856fc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 19:04:14 -0500 Subject: [PATCH 45/46] simplify and check for triclinic again, since somebody may have used change_box --- src/EXTRA-FIX/fix_wall_flow.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index f194a4076a..1f3dcfca5b 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -186,6 +186,9 @@ int FixWallFlow::setmask() void FixWallFlow::init() { + if (domain->triclinic != 0) + error->all(FLERR, "Fix wall/flow cannot be used with triclinic simulation box"); + int nrigid = 0; int box_change_flowax = 0; for (const auto &ifix : modify->get_fix_list()) { @@ -193,18 +196,12 @@ void FixWallFlow::init() switch (flowax) { case FlowAxis::AX_X: if (ifix->box_change & Fix::BOX_CHANGE_X) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_XY) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_XZ) box_change_flowax++; break; case FlowAxis::AX_Y: if (ifix->box_change & Fix::BOX_CHANGE_Y) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_YZ) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_XY) box_change_flowax++; break; case FlowAxis::AX_Z: if (ifix->box_change & Fix::BOX_CHANGE_Z) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_YZ) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_XZ) box_change_flowax++; break; } } From 01d9f78e6900ce8dfb0db2105f15b9f6eb3097f1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 24 Feb 2024 14:34:40 -0500 Subject: [PATCH 46/46] correct citation --- doc/src/pair_rebomos.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/pair_rebomos.rst b/doc/src/pair_rebomos.rst index 9466deb338..9f4b8006c1 100644 --- a/doc/src/pair_rebomos.rst +++ b/doc/src/pair_rebomos.rst @@ -139,11 +139,11 @@ none .. _Stewart: -**(Steward)** Stewart, Spearot, Modelling Simul. Mater. Sci. Eng. 21,(2013) +**(Steward)** Stewart, Spearot, Modelling Simul. Mater. Sci. Eng. 21, 045003, (2013). .. _Stuart2: -**(Stuart)** Stuart, Tutein, Harrison, J Chem Phys, 112, 6472-6486. (2000). +**(Stuart)** Stuart, Tutein, Harrison, J Chem Phys, 112, 6472-6486, (2000). .. _Liang: