From 41bd3437f671050c4a5c2dcb2bbf13bcec64a8c9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 05:53:46 -0400 Subject: [PATCH 01/37] Revert "make attempt_swap valgrind clean. now fails in pair->compute()." This reverts commit deef74289727f760e91921687ac5a5e63fa8ebfc. --- src/MC/fix_neighbor_swap.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 0fedfc460e..267313cd35 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -413,6 +413,10 @@ int FixNeighborSwap::attempt_swap() // pick a random atom i int i = pick_i_swap_atom(); + if (i < 0) return 0; + + // get global id and position of atom i + // get_global_i(i); // build nearest-neighbor list based on atom i @@ -541,9 +545,8 @@ int FixNeighborSwap::pick_i_swap_atom() i = local_swap_iatom_list[iwhichlocal]; MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); } else { - id_center = -1; + return -1; } - return i; } /* ---------------------------------------------------------------------- From 99e8085cda450d8d548e9b8a081788cbcf916870 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 05:53:56 -0400 Subject: [PATCH 02/37] Revert "make fix neighbor/swap valgrind clean" This reverts commit 6a2e7965386a17e5e5e4b3bdc18688078cf75417. --- src/MC/fix_neighbor_swap.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 267313cd35..b01e1e4d8b 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -413,7 +413,6 @@ int FixNeighborSwap::attempt_swap() // pick a random atom i int i = pick_i_swap_atom(); - if (i < 0) return 0; // get global id and position of atom i // get_global_i(i); @@ -545,8 +544,10 @@ int FixNeighborSwap::pick_i_swap_atom() i = local_swap_iatom_list[iwhichlocal]; MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); } else { - return -1; + MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); } + + return i; } /* ---------------------------------------------------------------------- From 61f9cb66e2f32df6662024c60c8c608dadb461e0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 05:54:02 -0400 Subject: [PATCH 03/37] Revert "remove dead code and redundant implementation." This reverts commit 3dadcab0476230e37e99636199ed8822a6f5b953. --- src/MC/fix_neighbor_swap.cpp | 53 ++++++++++++++++++++++++------------ src/MC/fix_neighbor_swap.h | 3 +- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index b01e1e4d8b..75aa0c2430 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -20,7 +20,6 @@ #include "angle.h" #include "atom.h" #include "bond.h" -#include "citeme.h" #include "comm.h" #include "compute.h" #include "compute_voronoi_atom.h" @@ -32,7 +31,6 @@ #include "group.h" #include "improper.h" #include "kspace.h" -#include "math_extra.h" #include "math_special.h" #include "memory.h" #include "modify.h" @@ -49,10 +47,9 @@ using namespace LAMMPS_NS; using namespace FixConst; -using MathExtra::distsq3; using MathSpecial::square; -static const char cite_fix_neighbor_swap[] = +static const char cite_fix_neighbor_swap_c[] = "fix neighbor/swap command: doi:10.1016/j.commatsci.2022.111929\n\n" "@Article{Tavenner2023111929,\n" " author = {Jacob P. Tavenner and Mikhail I. Mendelev and John W. Lawson},\n" @@ -62,7 +59,7 @@ static const char cite_fix_neighbor_swap[] = " year = {2023},\n" " volume = {218},\n" " pages = {111929}\n" - " url = {https://dx.doi.org/10.1016/j.commatsci.2022.111929}\n" + " url = {https://www.sciencedirect.com/science/article/pii/S0927025622006401}\n" "}\n\n"; /* ---------------------------------------------------------------------- */ @@ -90,8 +87,6 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : rates_flag = 0; nswaptypes = 0; - if (lmp->citeme) lmp->citeme->add(cite_fix_neighbor_swap); - // required args nevery = utils::inumeric(FLERR, arg[3], false, lmp); @@ -217,7 +212,8 @@ void FixNeighborSwap::options(int narg, char **arg) } } else if (strcmp(arg[iarg], "diff") == 0) { if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix neighbor/swap diff", error); - if (diff_flag) error->all(FLERR, iarg + ioffset, "Cannot use 'diff' keyword multiple times"); + if (diff_flag) + error->all(FLERR, iarg + ioffset, "Cannot use 'diff' keyword multiple times"); if (nswaptypes != 0) error->all(FLERR, iarg + ioffset, "Cannot use 'diff' and 'types' keywords together"); type_list[nswaptypes] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); @@ -404,6 +400,9 @@ void FixNeighborSwap::pre_exchange() int FixNeighborSwap::attempt_swap() { + // int nlocal = atom->nlocal; + tagint *id = atom->tag; + if (niswap == 0) return 0; // pre-swap energy @@ -424,7 +423,7 @@ int FixNeighborSwap::attempt_swap() // pick a neighbor atom j based on i neighbor list jtype_selected = -1; - int j = pick_j_swap_neighbor(); + int j = pick_j_swap_neighbor(i); int itype = type_list[0]; int jtype = jtype_selected; @@ -536,12 +535,14 @@ double FixNeighborSwap::energy_full() int FixNeighborSwap::pick_i_swap_atom() { tagint *id = atom->tag; + int id_center_local = -1; int i = -1; int iwhichglobal = static_cast(niswap * random_equal->uniform()); if ((iwhichglobal >= niswap_before) && (iwhichglobal < niswap_before + niswap_local)) { int iwhichlocal = iwhichglobal - niswap_before; i = local_swap_iatom_list[iwhichlocal]; + id_center_local = id[i]; MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); } else { MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); @@ -553,7 +554,7 @@ int FixNeighborSwap::pick_i_swap_atom() /* ---------------------------------------------------------------------- ------------------------------------------------------------------------- */ -int FixNeighborSwap::pick_j_swap_neighbor() +int FixNeighborSwap::pick_j_swap_neighbor(int i) { int j = -1; int jtype_selected_local = -1; @@ -585,6 +586,15 @@ int FixNeighborSwap::pick_j_swap_neighbor() /* ---------------------------------------------------------------------- ------------------------------------------------------------------------- */ +double FixNeighborSwap::get_distance(double *i, double *j) +{ + double r = sqrt(square((i[0] - j[0])) + square((i[1] - j[1])) + square((i[2] - j[2]))); + return r; +} + +/* ---------------------------------------------------------------------- +------------------------------------------------------------------------- */ + void FixNeighborSwap::build_i_neighbor_list(int i_center) { int nghost = atom->nghost; @@ -651,11 +661,13 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Get distance if own center atom double r = INFINITY; + if (i_center >= 0) { double r = get_distance(x[temp_j], x[i_center]); } // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { - double rtmp = sqrt(distsq3(x[temp_j], x[i])); - if ((id[i] == id_center) && (rtmp < r)) r = rtmp; + if ((id[i] == id_center) && (get_distance(x[temp_j], x[i]) < r)) { + r = get_distance(x[temp_j], x[i]); + } } if (rates_flag) { @@ -674,11 +686,13 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; + if (i_center >= 0) { double r = get_distance(x[temp_j], x[i_center]); } // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { - double rtmp = sqrt(distsq3(x[temp_j], x[i])); - if ((id[i] == id_center) && (rtmp < r)) r = rtmp; + if ((id[i] == id_center) && (get_distance(x[temp_j], x[i]) < r)) { + r = get_distance(x[temp_j], x[i]); + } } if (rates_flag) { @@ -703,11 +717,12 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; + if (i_center >= 0) { r = get_distance(x[temp_j], x[i_center]); } // Get local id of ghost center atoms for (int i = nlocal; i < nlocal + nghost; i++) { - double rtmp = sqrt(distsq3(x[temp_j], x[i])); - if ((id[i] == id_center) && (rtmp < r)) r = rtmp; + if ((id[i] == id_center) && (get_distance(x[temp_j], x[i]) < r)) + r = get_distance(x[temp_j], x[i]); } if (rates_flag) { @@ -727,11 +742,13 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; + if (i_center >= 0) { double r = get_distance(x[temp_j], x[i_center]); } // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { - double rtmp = sqrt(distsq3(x[temp_j], x[i])); - if ((id[i] == id_center) && (rtmp < r)) r = rtmp; + if ((id[i] == id_center) && (get_distance(x[temp_j], x[i]) < r)) { + r = get_distance(x[temp_j], x[i]); + } } if (rates_flag) { diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index f5d208f764..49ed78a4df 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -87,7 +87,8 @@ class FixNeighborSwap : public Fix { int attempt_swap(); double energy_full(); int pick_i_swap_atom(); - int pick_j_swap_neighbor(); + int pick_j_swap_neighbor(int); + double get_distance(double[3], double[3]); void build_i_neighbor_list(int); void update_iswap_atoms_list(); }; From 7bf5d5899f68cf2fc21bb2e812bfaac430d24f7b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 05:54:04 -0400 Subject: [PATCH 04/37] Revert "update error message" This reverts commit df3467a114bc374ac32580692b9593bd9f508c93. --- src/MC/fix_neighbor_swap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 75aa0c2430..fa013d8b10 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -213,7 +213,7 @@ void FixNeighborSwap::options(int narg, char **arg) } else if (strcmp(arg[iarg], "diff") == 0) { if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix neighbor/swap diff", error); if (diff_flag) - error->all(FLERR, iarg + ioffset, "Cannot use 'diff' keyword multiple times"); + error->all(FLERR, iarg + ioffset, "Cannot not use 'diff' keyword multiple times"); if (nswaptypes != 0) error->all(FLERR, iarg + ioffset, "Cannot use 'diff' and 'types' keywords together"); type_list[nswaptypes] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); From 9d37f28a867d6cc4f523221bb3b574f83c4ed619 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 05:54:10 -0400 Subject: [PATCH 05/37] Revert "Cleaned options reading index error" This reverts commit ef6cdbf00ecc12cec6ca2d4548cc2a448b9f7196. --- src/MC/fix_neighbor_swap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index fa013d8b10..f288d151df 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -122,7 +122,7 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : // read options from end of input line - options(narg - 9, &arg[9]); + options(narg - 8, &arg[8]); // random number generator, same for all procs @@ -180,7 +180,7 @@ void FixNeighborSwap::options(int narg, char **arg) { if (narg < 0) utils::missing_cmd_args(FLERR, "fix neighbor/swap", error); - int ioffset = 9; // first 9 arguments are fixed and handled in constructor + int ioffset = 8; // first 8 arguments are fixed and handled in constructor int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg], "region") == 0) { From 467cbbc188a52736af16fd2e0032bb731a36d4d0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 05:54:13 -0400 Subject: [PATCH 06/37] Revert "refactor fix neighbor/swap" This reverts commit 594953ed0bb31faae5038cb341a9890a33e8907b. --- src/MC/fix_neighbor_swap.cpp | 179 ++++++++++++++--------------------- src/MC/fix_neighbor_swap.h | 7 +- 2 files changed, 73 insertions(+), 113 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index f288d151df..d44181a981 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -40,14 +40,13 @@ #include "region.h" #include "update.h" +#include #include #include #include -#include using namespace LAMMPS_NS; using namespace FixConst; -using MathSpecial::square; static const char cite_fix_neighbor_swap_c[] = "fix neighbor/swap command: doi:10.1016/j.commatsci.2022.111929\n\n" @@ -65,11 +64,9 @@ static const char cite_fix_neighbor_swap_c[] = /* ---------------------------------------------------------------------- */ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), region(nullptr), idregion(nullptr), type_list(nullptr), rate_list(nullptr), - qtype(nullptr), sqrt_mass_ratio(nullptr), voro_neighbor_list(nullptr), - local_swap_iatom_list(nullptr), local_swap_neighbor_list(nullptr), - local_swap_type_list(nullptr), local_swap_probability(nullptr), random_equal(nullptr), - id_voro(nullptr), c_voro(nullptr), c_pe(nullptr) + Fix(lmp, narg, arg), region(nullptr), idregion(nullptr), type_list(nullptr), qtype(nullptr), + c_voro(nullptr), voro_neighbor_list(nullptr), sqrt_mass_ratio(nullptr), + local_swap_iatom_list(nullptr), random_equal(nullptr), c_pe(nullptr) { if (narg < 10) utils::missing_cmd_args(FLERR, "fix neighbor/swap", error); @@ -82,40 +79,30 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : restart_global = 1; time_depend = 1; - ke_flag = 1; - diff_flag = 0; - rates_flag = 0; - nswaptypes = 0; - // required args nevery = utils::inumeric(FLERR, arg[3], false, lmp); ncycles = utils::inumeric(FLERR, arg[4], false, lmp); seed = utils::inumeric(FLERR, arg[5], false, lmp); double temperature = utils::numeric(FLERR, arg[6], false, lmp); - double r_0 = utils::inumeric(FLERR, arg[7], false, lmp); - - if (nevery <= 0) - error->all(FLERR, 3, "Illegal fix neighbor/swap command nevery value: {}", nevery); - if (ncycles < 0) - error->all(FLERR, 4, "Illegal fix neighbor/swap command ncycles value: {}", ncycles); - if (seed <= 0) error->all(FLERR, 5, "Illegal fix neighbor/swap command seed value: {}", seed); - if (temperature <= 0.0) - error->all(FLERR, 6, "Illegal fix neighbor/swap command temperature value: {}", temperature); - if (r_0 <= 0.0) error->all(FLERR, 7, "Illegal fix neighbor/swap command R0 value: {}", r_0); + r_0 = utils::inumeric(FLERR, arg[7], false, lmp); // Voro compute check - id_voro = utils::strdup(arg[8]); - c_voro = modify->get_compute_by_id(id_voro); - if (!c_voro) error->all(FLERR, 8, "Could not find compute voronoi ID {}", id_voro); + int icompute = modify->find_compute(utils::strdup(arg[8])); + if (icompute < 0) error->all(FLERR, "Could not find neighbor compute ID"); + c_voro = modify->compute[icompute]; if (c_voro->local_flag == 0) - error->all(FLERR, 8, "Voronoi compute {} does not compute local info", id_voro); + error->all(FLERR, "Neighbor compute does not compute local info"); if (c_voro->size_local_cols != 3) - error->all(FLERR, 8, "Voronoi compute {} does not compute i, j, sizes as expected", id_voro); + error->all(FLERR, "Neighbor compute does not give i, j, size as expected"); + + if (nevery <= 0) error->all(FLERR, "Illegal fix neighbor/swap command nevery value"); + if (ncycles < 0) error->all(FLERR, "Illegal fix neighbor/swap command ncycles value"); + if (seed <= 0) error->all(FLERR, "Illegal fix neighbor/swap command seed value"); + if (temperature <= 0.0) error->all(FLERR, "Illegal fix neighbor/swap command temperature value"); beta = 1.0 / (force->boltz * temperature); - inv_r_0 = 1.0 / r_0; memory->create(type_list, atom->ntypes, "neighbor/swap:type_list"); memory->create(rate_list, atom->ntypes, "neighbor/swap:rate_list"); @@ -139,6 +126,11 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : nswap_successes = 0.0; atom_swap_nmax = 0; + voro_neighbor_list = nullptr; + local_swap_iatom_list = nullptr; + local_swap_neighbor_list = nullptr; + local_swap_probability = nullptr; + local_swap_type_list = nullptr; // set comm size needed by this Fix @@ -161,7 +153,6 @@ FixNeighborSwap::~FixNeighborSwap() memory->destroy(local_swap_probability); memory->destroy(local_swap_type_list); delete[] idregion; - delete[] id_voro; delete random_equal; } @@ -169,86 +160,62 @@ FixNeighborSwap::~FixNeighborSwap() parse optional parameters at end of input line ------------------------------------------------------------------------- */ -static const std::unordered_set known_keywords = {"region", "ke", "types", "diff", - "rates"}; -static bool is_keyword(const std::string &arg) -{ - return known_keywords.find(arg) != known_keywords.end(); -} - void FixNeighborSwap::options(int narg, char **arg) { - if (narg < 0) utils::missing_cmd_args(FLERR, "fix neighbor/swap", error); + if (narg < 0) error->all(FLERR, "Illegal fix neighbor/swap command\n"); + + ke_flag = 1; + diff_flag = 0; + rates_flag = 0; + nswaptypes = 0; - int ioffset = 8; // first 8 arguments are fixed and handled in constructor int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg], "region") == 0) { - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix neighbor/swap region", error); - delete[] idregion; + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix neighbor/swap command"); + region = domain->get_region_by_id(arg[iarg + 1]); + if (!region) error->all(FLERR, "Region ID for fix neighbor/swap does not exist"); idregion = utils::strdup(arg[iarg + 1]); - region = domain->get_region_by_id(idregion); - if (!region) - error->all(FLERR, iarg + 1 + ioffset, "Region ID {} for fix neighbor/swap does not exist", - idregion); iarg += 2; } else if (strcmp(arg[iarg], "ke") == 0) { - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix neighbor/swap ke", error); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix neighbor/swap command"); ke_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "types") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix neighbor/swap types", error); - if (diff_flag) - error->all(FLERR, iarg + ioffset, "Cannot use 'diff' and 'types' keywords together"); + if (iarg + 3 > narg) error->all(FLERR, "Illegal fix neighbor/swap command"); + if (diff_flag != 0) error->all(FLERR, "Illegal fix neighbor/swap command"); iarg++; nswaptypes = 0; while (iarg < narg) { - if (is_keyword(arg[iarg])) break; - if (nswaptypes >= atom->ntypes) - error->all(FLERR, iarg + ioffset, "Too many arguments to fix neighbor/swap types"); - type_list[nswaptypes] = utils::expand_type_int(FLERR, arg[iarg], Atom::ATOM, lmp); + if (isalpha(arg[iarg][0])) break; + if (nswaptypes >= atom->ntypes) error->all(FLERR, "Illegal fix neighbor/swap command"); + type_list[nswaptypes] = utils::numeric(FLERR, arg[iarg], false, lmp); nswaptypes++; iarg++; } } else if (strcmp(arg[iarg], "diff") == 0) { - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix neighbor/swap diff", error); - if (diff_flag) - error->all(FLERR, iarg + ioffset, "Cannot not use 'diff' keyword multiple times"); - if (nswaptypes != 0) - error->all(FLERR, iarg + ioffset, "Cannot use 'diff' and 'types' keywords together"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix neighbor/swap command"); + if (nswaptypes != 0) error->all(FLERR, "Illegal fix neighbor/swap command"); type_list[nswaptypes] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); diff_flag = 1; nswaptypes++; iarg += 2; } else if (strcmp(arg[iarg], "rates") == 0) { - if (iarg + atom->ntypes >= narg) - utils::missing_cmd_args(FLERR, "fix neighbor/swap rates", error); + if (iarg + atom->ntypes >= narg) error->all(FLERR, "Illegal fix neighbor/swap command"); iarg++; int i = 0; while (iarg < narg) { - if (is_keyword(arg[iarg])) break; - if (i >= atom->ntypes) error->all(FLERR, "Too many values for fix neighbor/swap rates"); + if (isalpha(arg[iarg][0])) break; + if (i >= atom->ntypes) error->all(FLERR, "Illegal fix neighbor/swap command"); rate_list[i] = utils::numeric(FLERR, arg[iarg], false, lmp); i++; iarg++; } rates_flag = 1; - if (i != atom->ntypes) - error->all(FLERR, "Fix neighbor/swap rates keyword must have exactly {} arguments", - atom->ntypes); - } else { - error->all(FLERR, "Unknown fix neighbor/swap keyword: {}", arg[iarg]); - } + if (i != atom->ntypes) error->all(FLERR, "Illegal fix neighbor/swap command"); + } else + error->all(FLERR, "Illegal fix neighbor/swap command"); } - - // checks - if (!nswaptypes && !diff_flag) - error->all(FLERR, Error::NOLASTLINE, - "Must specify at either 'types' or 'diff' keyword with fix neighbor/swap"); - - if (nswaptypes < 2 && !diff_flag) - error->all(FLERR, Error::NOLASTLINE, - "Must specify at least 2 atom types in fix neighbor/swap 'types' keyword"); } /* ---------------------------------------------------------------------- */ @@ -265,26 +232,23 @@ int FixNeighborSwap::setmask() void FixNeighborSwap::init() { c_pe = modify->get_compute_by_id("thermo_pe"); - if (!c_pe) error->all(FLERR, Error::NOLASTLINE, "Could not find 'thermo_pe' compute"); - c_voro = modify->get_compute_by_id(id_voro); - if (!c_voro) - error->all(FLERR, Error::NOLASTLINE, "Could not find compute voronoi ID {}", id_voro); + int *type = atom->type; + + if (nswaptypes < 2 && !diff_flag) + error->all(FLERR, "Must specify at least 2 types in fix neighbor/swap command"); // set index and check validity of region if (idregion) { region = domain->get_region_by_id(idregion); - if (!region) - error->all(FLERR, Error::NOLASTLINE, "Region {} for fix neighbor/swap does not exist", - idregion); + if (!region) error->all(FLERR, "Region {} for fix setforce does not exist", idregion); } for (int iswaptype = 0; iswaptype < nswaptypes; iswaptype++) if (type_list[iswaptype] <= 0 || type_list[iswaptype] > atom->ntypes) - error->all(FLERR, Error::NOLASTLINE, "Invalid atom type in fix neighbor/swap command"); + error->all(FLERR, "Invalid atom type in fix neighbor/swap command"); - int *type = atom->type; if (atom->q_flag) { double qmax, qmin; int firstall, first; @@ -294,27 +258,23 @@ void FixNeighborSwap::init() for (int i = 0; i < atom->nlocal; i++) { if (atom->mask[i] & groupbit) { if (type[i] == type_list[iswaptype]) { - if (first > 0) { + if (first) { qtype[iswaptype] = atom->q[i]; first = 0; } else if (qtype[iswaptype] != atom->q[i]) - first = -1; + error->one(FLERR, "All atoms of a swapped type must have the same charge."); } } } MPI_Allreduce(&first, &firstall, 1, MPI_INT, MPI_MIN, world); - if (firstall < 0) - error->all(FLERR, Error::NOLASTLINE, - "All atoms of a swapped type must have the same charge"); - if (firstall > 0) - error->all(FLERR, Error::NOLASTLINE, - "At least one atom of each swapped type must be present to define charges"); + if (firstall) + error->all(FLERR, + "At least one atom of each swapped type must be present to define charges."); if (first) qtype[iswaptype] = -DBL_MAX; MPI_Allreduce(&qtype[iswaptype], &qmax, 1, MPI_DOUBLE, MPI_MAX, world); if (first) qtype[iswaptype] = DBL_MAX; MPI_Allreduce(&qtype[iswaptype], &qmin, 1, MPI_DOUBLE, MPI_MIN, world); - if (qmax != qmin) - error->all(FLERR, Error::NOLASTLINE, "All atoms of a swapped type must have same charge."); + if (qmax != qmin) error->all(FLERR, "All atoms of a swapped type must have same charge."); } } @@ -348,9 +308,8 @@ void FixNeighborSwap::init() int flagall; MPI_Allreduce(&flag, &flagall, 1, MPI_INT, MPI_SUM, world); - if (flagall) - error->all(FLERR, Error::NOLASTLINE, - "Cannot use fix neighbor/swap on atoms in atom_modify first group"); + + if (flagall) error->all(FLERR, "Cannot do neighbor/swap on atoms in atom_modify first group"); } } @@ -576,7 +535,7 @@ int FixNeighborSwap::pick_j_swap_neighbor(int i) return j; } } - error->all(FLERR, Error::NOLASTLINE, "Did not select local neighbor swap atom"); + error->all(FLERR, "Did not select local neighbor swap atom"); } MPI_Allreduce(&jtype_selected_local, &jtype_selected, 1, MPI_INT, MPI_MAX, world); @@ -588,7 +547,8 @@ int FixNeighborSwap::pick_j_swap_neighbor(int i) double FixNeighborSwap::get_distance(double *i, double *j) { - double r = sqrt(square((i[0] - j[0])) + square((i[1] - j[1])) + square((i[2] - j[2]))); + double r = sqrt(MathSpecial::square((i[0] - j[0])) + MathSpecial::square((i[1] - j[1])) + + MathSpecial::square((i[2] - j[2]))); return r; } @@ -672,9 +632,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-square(r * inv_r_0)); + rate_list[type[temp_j] - 1] * exp(-MathSpecial::square(r / r_0)); } else { - local_swap_probability[njswap_local] = exp(-square(r * inv_r_0)); + local_swap_probability[njswap_local] = exp(-MathSpecial::square(r / r_0)); } local_probability += local_swap_probability[njswap_local]; local_swap_type_list[njswap_local] = type[temp_j]; @@ -697,9 +657,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-square(r * inv_r_0)); + rate_list[type[temp_j] - 1] * exp(-MathSpecial::square(r / r_0)); } else { - local_swap_probability[njswap_local] = exp(-square(r * inv_r_0)); + local_swap_probability[njswap_local] = exp(-MathSpecial::square(r / r_0)); } local_probability += local_swap_probability[njswap_local]; @@ -727,9 +687,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-square(r * inv_r_0)); + rate_list[type[temp_j] - 1] * exp(-MathSpecial::square(r / r_0)); } else { - local_swap_probability[njswap_local] = exp(-square(r * inv_r_0)); + local_swap_probability[njswap_local] = exp(-MathSpecial::square(r / r_0)); } local_probability += local_swap_probability[njswap_local]; @@ -753,9 +713,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-square(r * inv_r_0)); + rate_list[type[temp_j] - 1] * exp(-MathSpecial::square(r / r_0)); } else { - local_swap_probability[njswap_local] = exp(-square(r * inv_r_0)); + local_swap_probability[njswap_local] = exp(-MathSpecial::square(r / r_0)); } local_probability += local_swap_probability[njswap_local]; @@ -937,6 +897,5 @@ void FixNeighborSwap::restart(char *buf) bigint ntimestep_restart = (bigint) ubuf(list[n++]).i; if (ntimestep_restart != update->ntimestep) - error->all(FLERR, Error::NOLASTLINE, - "Must not reset timestep when restarting fix neighbor/swap"); + error->all(FLERR, "Must not reset timestep when restarting fix neighbor/swap"); } diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index 49ed78a4df..821eda1bdc 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -47,6 +47,7 @@ class FixNeighborSwap : public Fix { int niswap, njswap; // # of i,j swap atoms on all procs int niswap_local, njswap_local; // # of swap atoms on this proc int niswap_before, njswap_before; // # of swap atoms on procs < this proc + // int global_i_ID; // global id of selected i atom class Region *region; // swap region char *idregion; // swap region id @@ -65,7 +66,7 @@ class FixNeighborSwap : public Fix { bool unequal_cutoffs; int atom_swap_nmax; - double beta, inv_r_0; + double beta, r_0; double local_probability; // Total swap probability stored on this proc double global_probability; // Total swap probability across all proc double prev_probability; // Swap probability on proc < this proc @@ -80,8 +81,8 @@ class FixNeighborSwap : public Fix { class RanPark *random_equal; - char *id_voro; - class Compute *c_voro, *c_pe; + class Compute *c_voro; + class Compute *c_pe; void options(int, char **); int attempt_swap(); From 8abd42ed2fdf8bc0bab60937d6adb9f34805f811 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 06:02:03 -0400 Subject: [PATCH 07/37] complete embedded citation handling --- src/MC/fix_neighbor_swap.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index d44181a981..c22a4cc0cd 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -20,6 +20,7 @@ #include "angle.h" #include "atom.h" #include "bond.h" +#include "citeme.h" #include "comm.h" #include "compute.h" #include "compute_voronoi_atom.h" @@ -48,7 +49,7 @@ using namespace LAMMPS_NS; using namespace FixConst; -static const char cite_fix_neighbor_swap_c[] = +static const char cite_fix_neighbor_swap[] = "fix neighbor/swap command: doi:10.1016/j.commatsci.2022.111929\n\n" "@Article{Tavenner2023111929,\n" " author = {Jacob P. Tavenner and Mikhail I. Mendelev and John W. Lawson},\n" @@ -58,7 +59,7 @@ static const char cite_fix_neighbor_swap_c[] = " year = {2023},\n" " volume = {218},\n" " pages = {111929}\n" - " url = {https://www.sciencedirect.com/science/article/pii/S0927025622006401}\n" + " url = {https://dx.doi.org/10.1016/j.commatsci.2022.111929}\n" "}\n\n"; /* ---------------------------------------------------------------------- */ @@ -79,6 +80,8 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : restart_global = 1; time_depend = 1; + if (lmp->citeme) lmp->citeme->add(cite_fix_neighbor_swap); + // required args nevery = utils::inumeric(FLERR, arg[3], false, lmp); From 4b56fd4cd25cacb1078cf6794aeca0323a8851f7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 06:15:48 -0400 Subject: [PATCH 08/37] replace redundant get_distance() with sqrt(MathExtra::distsqr()) Also avoid repetitive computation of distance. --- src/MC/fix_neighbor_swap.cpp | 39 +++++++++++++----------------------- src/MC/fix_neighbor_swap.h | 3 +-- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index c22a4cc0cd..55e0cc70cb 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -32,6 +32,7 @@ #include "group.h" #include "improper.h" #include "kspace.h" +#include "math_extra.h" #include "math_special.h" #include "memory.h" #include "modify.h" @@ -48,6 +49,7 @@ using namespace LAMMPS_NS; using namespace FixConst; +using MathExtra::distsq3; static const char cite_fix_neighbor_swap[] = "fix neighbor/swap command: doi:10.1016/j.commatsci.2022.111929\n\n" @@ -548,16 +550,6 @@ int FixNeighborSwap::pick_j_swap_neighbor(int i) /* ---------------------------------------------------------------------- ------------------------------------------------------------------------- */ -double FixNeighborSwap::get_distance(double *i, double *j) -{ - double r = sqrt(MathSpecial::square((i[0] - j[0])) + MathSpecial::square((i[1] - j[1])) + - MathSpecial::square((i[2] - j[2]))); - return r; -} - -/* ---------------------------------------------------------------------- -------------------------------------------------------------------------- */ - void FixNeighborSwap::build_i_neighbor_list(int i_center) { int nghost = atom->nghost; @@ -624,13 +616,12 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Get distance if own center atom double r = INFINITY; - if (i_center >= 0) { double r = get_distance(x[temp_j], x[i_center]); } + if (i_center >= 0) { double r = sqrt(distsq3(x[temp_j], x[i_center])); } // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { - if ((id[i] == id_center) && (get_distance(x[temp_j], x[i]) < r)) { - r = get_distance(x[temp_j], x[i]); - } + double rtmp = sqrt(distsq3(x[temp_j], x[i])); + if ((id[i] == id_center) && (rtmp < r)) r = rtmp; } if (rates_flag) { @@ -649,13 +640,12 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; - if (i_center >= 0) { double r = get_distance(x[temp_j], x[i_center]); } + if (i_center >= 0) { double r = sqrt(distsq3(x[temp_j], x[i_center])); } // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { - if ((id[i] == id_center) && (get_distance(x[temp_j], x[i]) < r)) { - r = get_distance(x[temp_j], x[i]); - } + double rtmp = sqrt(distsq3(x[temp_j], x[i])); + if ((id[i] == id_center) && (rtmp < r)) r = rtmp; } if (rates_flag) { @@ -680,12 +670,12 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; - if (i_center >= 0) { r = get_distance(x[temp_j], x[i_center]); } + if (i_center >= 0) { r = sqrt(distsq3(x[temp_j], x[i_center])); } // Get local id of ghost center atoms for (int i = nlocal; i < nlocal + nghost; i++) { - if ((id[i] == id_center) && (get_distance(x[temp_j], x[i]) < r)) - r = get_distance(x[temp_j], x[i]); + double rtmp = sqrt(distsq3(x[temp_j], x[i])); + if ((id[i] == id_center) && (rtmp < r)) r = rtmp; } if (rates_flag) { @@ -705,13 +695,12 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; - if (i_center >= 0) { double r = get_distance(x[temp_j], x[i_center]); } + if (i_center >= 0) { double r = sqrt(distsq3(x[temp_j], x[i_center])); } // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { - if ((id[i] == id_center) && (get_distance(x[temp_j], x[i]) < r)) { - r = get_distance(x[temp_j], x[i]); - } + double rtmp = sqrt(distsq3(x[temp_j], x[i])); + if ((id[i] == id_center) && (rtmp < r)) r = rtmp; } if (rates_flag) { diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index 821eda1bdc..f01e4db195 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -47,7 +47,7 @@ class FixNeighborSwap : public Fix { int niswap, njswap; // # of i,j swap atoms on all procs int niswap_local, njswap_local; // # of swap atoms on this proc int niswap_before, njswap_before; // # of swap atoms on procs < this proc - // int global_i_ID; // global id of selected i atom + class Region *region; // swap region char *idregion; // swap region id @@ -89,7 +89,6 @@ class FixNeighborSwap : public Fix { double energy_full(); int pick_i_swap_atom(); int pick_j_swap_neighbor(int); - double get_distance(double[3], double[3]); void build_i_neighbor_list(int); void update_iswap_atoms_list(); }; From cf79cf8e72995d257990750b3334090455d19a84 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 06:18:29 -0400 Subject: [PATCH 09/37] simplify use of MathSpecial::square() --- src/MC/fix_neighbor_swap.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 55e0cc70cb..a42ec284a1 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -50,6 +50,7 @@ using namespace LAMMPS_NS; using namespace FixConst; using MathExtra::distsq3; +using MathSpecial::square; static const char cite_fix_neighbor_swap[] = "fix neighbor/swap command: doi:10.1016/j.commatsci.2022.111929\n\n" @@ -626,9 +627,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-MathSpecial::square(r / r_0)); + rate_list[type[temp_j] - 1] * exp(-square(r / r_0)); } else { - local_swap_probability[njswap_local] = exp(-MathSpecial::square(r / r_0)); + local_swap_probability[njswap_local] = exp(-square(r / r_0)); } local_probability += local_swap_probability[njswap_local]; local_swap_type_list[njswap_local] = type[temp_j]; @@ -650,9 +651,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-MathSpecial::square(r / r_0)); + rate_list[type[temp_j] - 1] * exp(-square(r / r_0)); } else { - local_swap_probability[njswap_local] = exp(-MathSpecial::square(r / r_0)); + local_swap_probability[njswap_local] = exp(-square(r / r_0)); } local_probability += local_swap_probability[njswap_local]; @@ -680,9 +681,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-MathSpecial::square(r / r_0)); + rate_list[type[temp_j] - 1] * exp(-square(r / r_0)); } else { - local_swap_probability[njswap_local] = exp(-MathSpecial::square(r / r_0)); + local_swap_probability[njswap_local] = exp(-square(r / r_0)); } local_probability += local_swap_probability[njswap_local]; @@ -705,9 +706,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-MathSpecial::square(r / r_0)); + rate_list[type[temp_j] - 1] * exp(-square(r / r_0)); } else { - local_swap_probability[njswap_local] = exp(-MathSpecial::square(r / r_0)); + local_swap_probability[njswap_local] = exp(-square(r / r_0)); } local_probability += local_swap_probability[njswap_local]; From 3f1944cace0e02ffd6a17d51410832ea2b90947c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 06:23:58 -0400 Subject: [PATCH 10/37] more accurate detection of known keywords --- src/MC/fix_neighbor_swap.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index a42ec284a1..be861e1afc 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -42,10 +42,10 @@ #include "region.h" #include "update.h" -#include #include #include #include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -162,6 +162,14 @@ FixNeighborSwap::~FixNeighborSwap() delete random_equal; } +// helper function: detect known keywords +static const std::unordered_set known_keywords = {"region", "ke", "types", "diff", + "rates"}; +static bool is_keyword(const std::string &arg) +{ + return known_keywords.find(arg) != known_keywords.end(); +} + /* ---------------------------------------------------------------------- parse optional parameters at end of input line ------------------------------------------------------------------------- */ @@ -193,7 +201,7 @@ void FixNeighborSwap::options(int narg, char **arg) iarg++; nswaptypes = 0; while (iarg < narg) { - if (isalpha(arg[iarg][0])) break; + if (is_keyword(arg[iarg])) break; if (nswaptypes >= atom->ntypes) error->all(FLERR, "Illegal fix neighbor/swap command"); type_list[nswaptypes] = utils::numeric(FLERR, arg[iarg], false, lmp); nswaptypes++; @@ -211,7 +219,7 @@ void FixNeighborSwap::options(int narg, char **arg) iarg++; int i = 0; while (iarg < narg) { - if (isalpha(arg[iarg][0])) break; + if (is_keyword(arg[iarg])) break; if (i >= atom->ntypes) error->all(FLERR, "Illegal fix neighbor/swap command"); rate_list[i] = utils::numeric(FLERR, arg[iarg], false, lmp); i++; From e31f864620ea1fa0b3515215bd2e95f0cc479e45 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 06:25:27 -0400 Subject: [PATCH 11/37] correct offset for parsing optional arguments --- src/MC/fix_neighbor_swap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index be861e1afc..379a7c4c0c 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -115,7 +115,7 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : // read options from end of input line - options(narg - 8, &arg[8]); + options(narg - 9, &arg[9]); // random number generator, same for all procs From 78e538c9fc4e1b0e7915d745286ca552b083429c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 06:32:50 -0400 Subject: [PATCH 12/37] store inv_r_0 instead of r_0 to replace division by faster multiplication --- src/MC/fix_neighbor_swap.cpp | 19 ++++++++++--------- src/MC/fix_neighbor_swap.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 379a7c4c0c..46c1e2734d 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -91,7 +91,7 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : ncycles = utils::inumeric(FLERR, arg[4], false, lmp); seed = utils::inumeric(FLERR, arg[5], false, lmp); double temperature = utils::numeric(FLERR, arg[6], false, lmp); - r_0 = utils::inumeric(FLERR, arg[7], false, lmp); + double r_0 = utils::inumeric(FLERR, arg[7], false, lmp); // Voro compute check @@ -109,6 +109,7 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : if (temperature <= 0.0) error->all(FLERR, "Illegal fix neighbor/swap command temperature value"); beta = 1.0 / (force->boltz * temperature); + inv_r_0 = 1.0 / r_0; memory->create(type_list, atom->ntypes, "neighbor/swap:type_list"); memory->create(rate_list, atom->ntypes, "neighbor/swap:rate_list"); @@ -635,9 +636,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-square(r / r_0)); + rate_list[type[temp_j] - 1] * exp(-square(r * inv_r_0)); } else { - local_swap_probability[njswap_local] = exp(-square(r / r_0)); + local_swap_probability[njswap_local] = exp(-square(r * inv_r_0)); } local_probability += local_swap_probability[njswap_local]; local_swap_type_list[njswap_local] = type[temp_j]; @@ -659,9 +660,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-square(r / r_0)); + rate_list[type[temp_j] - 1] * exp(-square(r * inv_r_0)); } else { - local_swap_probability[njswap_local] = exp(-square(r / r_0)); + local_swap_probability[njswap_local] = exp(-square(r * inv_r_0)); } local_probability += local_swap_probability[njswap_local]; @@ -689,9 +690,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-square(r / r_0)); + rate_list[type[temp_j] - 1] * exp(-square(r * inv_r_0)); } else { - local_swap_probability[njswap_local] = exp(-square(r / r_0)); + local_swap_probability[njswap_local] = exp(-square(r * inv_r_0)); } local_probability += local_swap_probability[njswap_local]; @@ -714,9 +715,9 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) if (rates_flag) { local_swap_probability[njswap_local] = - rate_list[type[temp_j] - 1] * exp(-square(r / r_0)); + rate_list[type[temp_j] - 1] * exp(-square(r * inv_r_0)); } else { - local_swap_probability[njswap_local] = exp(-square(r / r_0)); + local_swap_probability[njswap_local] = exp(-square(r * inv_r_0)); } local_probability += local_swap_probability[njswap_local]; diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index f01e4db195..1329f090a5 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -66,7 +66,7 @@ class FixNeighborSwap : public Fix { bool unequal_cutoffs; int atom_swap_nmax; - double beta, r_0; + double beta, inv_r_0; double local_probability; // Total swap probability stored on this proc double global_probability; // Total swap probability across all proc double prev_probability; // Swap probability on proc < this proc From 21d3f68939cc6c1f2166d75c94cd553fa3c6a5db Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 06:42:08 -0400 Subject: [PATCH 13/37] modernize looking up voronoi compute and check for it in init(), too --- src/MC/fix_neighbor_swap.cpp | 18 ++++++++++++------ src/MC/fix_neighbor_swap.h | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 46c1e2734d..15e142d4ac 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -69,7 +69,7 @@ static const char cite_fix_neighbor_swap[] = FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), region(nullptr), idregion(nullptr), type_list(nullptr), qtype(nullptr), - c_voro(nullptr), voro_neighbor_list(nullptr), sqrt_mass_ratio(nullptr), + id_voro(nullptr), c_voro(nullptr), voro_neighbor_list(nullptr), sqrt_mass_ratio(nullptr), local_swap_iatom_list(nullptr), random_equal(nullptr), c_pe(nullptr) { if (narg < 10) utils::missing_cmd_args(FLERR, "fix neighbor/swap", error); @@ -95,13 +95,13 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : // Voro compute check - int icompute = modify->find_compute(utils::strdup(arg[8])); - if (icompute < 0) error->all(FLERR, "Could not find neighbor compute ID"); - c_voro = modify->compute[icompute]; + id_voro = utils::strdup(arg[8]); + c_voro = modify->get_compute_by_id(id_voro); + if (!c_voro) error->all(FLERR, 8, "Could not find voronoi compute ID {}", id_voro); if (c_voro->local_flag == 0) - error->all(FLERR, "Neighbor compute does not compute local info"); + error->all(FLERR, 8, "Voronoi compute {} does not compute local info", id_voro); if (c_voro->size_local_cols != 3) - error->all(FLERR, "Neighbor compute does not give i, j, size as expected"); + error->all(FLERR, "Voronoi compute {} does not give i, j, size as expected", id_voro); if (nevery <= 0) error->all(FLERR, "Illegal fix neighbor/swap command nevery value"); if (ncycles < 0) error->all(FLERR, "Illegal fix neighbor/swap command ncycles value"); @@ -160,6 +160,7 @@ FixNeighborSwap::~FixNeighborSwap() memory->destroy(local_swap_probability); memory->destroy(local_swap_type_list); delete[] idregion; + delete[] id_voro; delete random_equal; } @@ -247,6 +248,11 @@ int FixNeighborSwap::setmask() void FixNeighborSwap::init() { c_pe = modify->get_compute_by_id("thermo_pe"); + if (!c_pe) error->all(FLERR, Error::NOLASTLINE, "Could not find 'thermo_pe' compute"); + + c_voro = modify->get_compute_by_id(id_voro); + if (!c_voro) + error->all(FLERR, Error::NOLASTLINE, "Could not find voronoi compute ID {}", id_voro); int *type = atom->type; diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index 1329f090a5..29e0c8d379 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -81,8 +81,8 @@ class FixNeighborSwap : public Fix { class RanPark *random_equal; - class Compute *c_voro; - class Compute *c_pe; + char *id_voro; + class Compute *c_voro, *c_pe; void options(int, char **); int attempt_swap(); From 74e8ed7a49e11b1ac65267ca0b17c494f2e029b4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 06:46:43 -0400 Subject: [PATCH 14/37] follow LAMMPS' conventions for initializing class members more closely --- src/MC/fix_neighbor_swap.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 15e142d4ac..1a40b7620d 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -68,9 +68,11 @@ static const char cite_fix_neighbor_swap[] = /* ---------------------------------------------------------------------- */ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), region(nullptr), idregion(nullptr), type_list(nullptr), qtype(nullptr), - id_voro(nullptr), c_voro(nullptr), voro_neighbor_list(nullptr), sqrt_mass_ratio(nullptr), - local_swap_iatom_list(nullptr), random_equal(nullptr), c_pe(nullptr) + Fix(lmp, narg, arg), region(nullptr), idregion(nullptr), type_list(nullptr), rate_list(nullptr), + qtype(nullptr), sqrt_mass_ratio(nullptr), voro_neighbor_list(nullptr), + local_swap_iatom_list(nullptr), local_swap_neighbor_list(nullptr), + local_swap_type_list(nullptr), local_swap_probability(nullptr), random_equal(nullptr), + id_voro(nullptr), c_voro(nullptr), c_pe(nullptr) { if (narg < 10) utils::missing_cmd_args(FLERR, "fix neighbor/swap", error); @@ -109,11 +111,18 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : if (temperature <= 0.0) error->all(FLERR, "Illegal fix neighbor/swap command temperature value"); beta = 1.0 / (force->boltz * temperature); - inv_r_0 = 1.0 / r_0; + inv_r_0 = 1.0 / r_0; memory->create(type_list, atom->ntypes, "neighbor/swap:type_list"); memory->create(rate_list, atom->ntypes, "neighbor/swap:rate_list"); + // defaults for options + + ke_flag = 1; + diff_flag = 0; + rates_flag = 0; + nswaptypes = 0; + // read options from end of input line options(narg - 9, &arg[9]); @@ -133,11 +142,6 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : nswap_successes = 0.0; atom_swap_nmax = 0; - voro_neighbor_list = nullptr; - local_swap_iatom_list = nullptr; - local_swap_neighbor_list = nullptr; - local_swap_probability = nullptr; - local_swap_type_list = nullptr; // set comm size needed by this Fix @@ -180,11 +184,6 @@ void FixNeighborSwap::options(int narg, char **arg) { if (narg < 0) error->all(FLERR, "Illegal fix neighbor/swap command\n"); - ke_flag = 1; - diff_flag = 0; - rates_flag = 0; - nswaptypes = 0; - int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg], "region") == 0) { From 964605f25ade71687fd3bd1d29b9d03745fb05a9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 06:50:28 -0400 Subject: [PATCH 15/37] remove commented out code --- src/MC/fix_neighbor_swap.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 1a40b7620d..c1c8b65555 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -253,8 +253,6 @@ void FixNeighborSwap::init() if (!c_voro) error->all(FLERR, Error::NOLASTLINE, "Could not find voronoi compute ID {}", id_voro); - int *type = atom->type; - if (nswaptypes < 2 && !diff_flag) error->all(FLERR, "Must specify at least 2 types in fix neighbor/swap command"); @@ -269,6 +267,7 @@ void FixNeighborSwap::init() if (type_list[iswaptype] <= 0 || type_list[iswaptype] > atom->ntypes) error->all(FLERR, "Invalid atom type in fix neighbor/swap command"); + int *type = atom->type; if (atom->q_flag) { double qmax, qmin; int firstall, first; @@ -379,9 +378,6 @@ void FixNeighborSwap::pre_exchange() int FixNeighborSwap::attempt_swap() { - // int nlocal = atom->nlocal; - tagint *id = atom->tag; - if (niswap == 0) return 0; // pre-swap energy @@ -392,9 +388,6 @@ int FixNeighborSwap::attempt_swap() int i = pick_i_swap_atom(); - // get global id and position of atom i - // get_global_i(i); - // build nearest-neighbor list based on atom i build_i_neighbor_list(i); From 654cd0fe004bf5901a4537733d1de2a6cf00171c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 22:52:40 -0400 Subject: [PATCH 16/37] improve argument parsing and error messages --- src/MC/fix_neighbor_swap.cpp | 116 +++++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 39 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index c1c8b65555..9bfb587b8c 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -90,10 +90,25 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : // required args nevery = utils::inumeric(FLERR, arg[3], false, lmp); + if (nevery <= 0) + error->all(FLERR, 3, "Illegal fix neighbor/swap command nevery value: {}", nevery); + ncycles = utils::inumeric(FLERR, arg[4], false, lmp); + if (ncycles < 0) + error->all(FLERR, 4, "Illegal fix neighbor/swap command ncycles value: {}", ncycles); + seed = utils::inumeric(FLERR, arg[5], false, lmp); + if (seed <= 0) error->all(FLERR, 5, "Illegal fix neighbor/swap command seed value: {}", seed); + double temperature = utils::numeric(FLERR, arg[6], false, lmp); + if (temperature <= 0.0) + error->all(FLERR, 6, "Illegal fix neighbor/swap command temperature value: {}", temperature); + double r_0 = utils::inumeric(FLERR, arg[7], false, lmp); + if (r_0 <= 0.0) error->all(FLERR, 7, "Illegal fix neighbor/swap command R0 value: {}", r_0); + + beta = 1.0 / (force->boltz * temperature); + inv_r_0 = 1.0 / r_0; // Voro compute check @@ -105,24 +120,16 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : if (c_voro->size_local_cols != 3) error->all(FLERR, "Voronoi compute {} does not give i, j, size as expected", id_voro); - if (nevery <= 0) error->all(FLERR, "Illegal fix neighbor/swap command nevery value"); - if (ncycles < 0) error->all(FLERR, "Illegal fix neighbor/swap command ncycles value"); - if (seed <= 0) error->all(FLERR, "Illegal fix neighbor/swap command seed value"); - if (temperature <= 0.0) error->all(FLERR, "Illegal fix neighbor/swap command temperature value"); - - beta = 1.0 / (force->boltz * temperature); - inv_r_0 = 1.0 / r_0; - - memory->create(type_list, atom->ntypes, "neighbor/swap:type_list"); - memory->create(rate_list, atom->ntypes, "neighbor/swap:rate_list"); - - // defaults for options + // defaults and allocations for options ke_flag = 1; diff_flag = 0; rates_flag = 0; nswaptypes = 0; + memory->create(type_list, atom->ntypes, "neighbor/swap:type_list"); + memory->create(rate_list, atom->ntypes, "neighbor/swap:rate_list"); + // read options from end of input line options(narg - 9, &arg[9]); @@ -140,7 +147,6 @@ FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : nswap_attempts = 0.0; nswap_successes = 0.0; - atom_swap_nmax = 0; // set comm size needed by this Fix @@ -182,55 +188,78 @@ static bool is_keyword(const std::string &arg) void FixNeighborSwap::options(int narg, char **arg) { - if (narg < 0) error->all(FLERR, "Illegal fix neighbor/swap command\n"); + // either "types" or "diff" option is required + if (narg < 0) utils::missing_cmd_args(FLERR, "fix neighbor/swap", error); + + int ntypes = atom->ntypes; + int ioffset = 9; // first 9 arguments are fixed and handled in constructor int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg], "region") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal fix neighbor/swap command"); - region = domain->get_region_by_id(arg[iarg + 1]); - if (!region) error->all(FLERR, "Region ID for fix neighbor/swap does not exist"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix neighbor/swap region", error); + delete[] idregion; idregion = utils::strdup(arg[iarg + 1]); + region = domain->get_region_by_id(idregion); + if (!region) + error->all(FLERR, iarg + 1 + ioffset, "Region ID {} for fix neighbor/swap does not exist", + idregion); iarg += 2; } else if (strcmp(arg[iarg], "ke") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal fix neighbor/swap command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix neighbor/swap ke", error); ke_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "types") == 0) { - if (iarg + 3 > narg) error->all(FLERR, "Illegal fix neighbor/swap command"); - if (diff_flag != 0) error->all(FLERR, "Illegal fix neighbor/swap command"); + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix neighbor/swap types", error); + if (diff_flag) + error->all(FLERR, iarg + ioffset, "Cannot use 'diff' and 'types' keywords together"); iarg++; nswaptypes = 0; while (iarg < narg) { if (is_keyword(arg[iarg])) break; - if (nswaptypes >= atom->ntypes) error->all(FLERR, "Illegal fix neighbor/swap command"); - type_list[nswaptypes] = utils::numeric(FLERR, arg[iarg], false, lmp); + if (nswaptypes >= ntypes) + error->all(FLERR, iarg + ioffset, "Too many arguments to fix neighbor/swap types"); + type_list[nswaptypes] = utils::expand_type_int(FLERR, arg[iarg], Atom::ATOM, lmp); nswaptypes++; iarg++; } } else if (strcmp(arg[iarg], "diff") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal fix neighbor/swap command"); - if (nswaptypes != 0) error->all(FLERR, "Illegal fix neighbor/swap command"); - type_list[nswaptypes] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + if (diff_flag) error->all(FLERR, iarg + ioffset, "Cannot use 'diff' keyword multiple times"); + if (nswaptypes != 0) + error->all(FLERR, iarg + ioffset, "Cannot use 'diff' and 'types' keywords together"); + type_list[nswaptypes] = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); diff_flag = 1; nswaptypes++; iarg += 2; } else if (strcmp(arg[iarg], "rates") == 0) { - if (iarg + atom->ntypes >= narg) error->all(FLERR, "Illegal fix neighbor/swap command"); + if (iarg + ntypes >= narg) utils::missing_cmd_args(FLERR, "fix neighbor/swap rates", error); iarg++; int i = 0; while (iarg < narg) { if (is_keyword(arg[iarg])) break; - if (i >= atom->ntypes) error->all(FLERR, "Illegal fix neighbor/swap command"); + if (i >= ntypes) + error->all(FLERR, iarg + ioffset, "Too many values (> {}) for fix neighbor/swap rates", + ntypes); rate_list[i] = utils::numeric(FLERR, arg[iarg], false, lmp); i++; iarg++; } rates_flag = 1; - if (i != atom->ntypes) error->all(FLERR, "Illegal fix neighbor/swap command"); + if (i != ntypes) + error->all(FLERR, "Fix neighbor/swap rates keyword must have exactly {} arguments", ntypes); } else - error->all(FLERR, "Illegal fix neighbor/swap command"); + error->all(FLERR, "Unknown fix neighbor/swap keyword: {}", arg[iarg]); } + + // checks + + if (!nswaptypes && !diff_flag) + error->all(FLERR, Error::NOLASTLINE, + "Must specify at either 'types' or 'diff' keyword with fix neighbor/swap"); + + if (nswaptypes < 2 && !diff_flag) + error->all(FLERR, Error::NOLASTLINE, + "Must specify at least 2 atom types in fix neighbor/swap 'types' keyword"); } /* ---------------------------------------------------------------------- */ @@ -260,7 +289,9 @@ void FixNeighborSwap::init() if (idregion) { region = domain->get_region_by_id(idregion); - if (!region) error->all(FLERR, "Region {} for fix setforce does not exist", idregion); + if (!region) + error->all(FLERR, Error::NOLASTLINE, "Region {} for fix neighbor/swap does not exist", + idregion); } for (int iswaptype = 0; iswaptype < nswaptypes; iswaptype++) @@ -277,23 +308,27 @@ void FixNeighborSwap::init() for (int i = 0; i < atom->nlocal; i++) { if (atom->mask[i] & groupbit) { if (type[i] == type_list[iswaptype]) { - if (first) { + if (first > 0) { qtype[iswaptype] = atom->q[i]; first = 0; } else if (qtype[iswaptype] != atom->q[i]) - error->one(FLERR, "All atoms of a swapped type must have the same charge."); + first = -1; } } } MPI_Allreduce(&first, &firstall, 1, MPI_INT, MPI_MIN, world); - if (firstall) - error->all(FLERR, - "At least one atom of each swapped type must be present to define charges."); + if (firstall < 0) + error->all(FLERR, Error::NOLASTLINE, + "All atoms of a swapped type must have the same charge"); + if (firstall > 0) + error->all(FLERR, Error::NOLASTLINE, + "At least one atom of each swapped type must be present to define charges"); if (first) qtype[iswaptype] = -DBL_MAX; MPI_Allreduce(&qtype[iswaptype], &qmax, 1, MPI_DOUBLE, MPI_MAX, world); if (first) qtype[iswaptype] = DBL_MAX; MPI_Allreduce(&qtype[iswaptype], &qmin, 1, MPI_DOUBLE, MPI_MIN, world); - if (qmax != qmin) error->all(FLERR, "All atoms of a swapped type must have same charge."); + if (qmax != qmin) + error->all(FLERR, Error::NOLASTLINE, "All atoms of a swapped type must have same charge."); } } @@ -328,7 +363,9 @@ void FixNeighborSwap::init() int flagall; MPI_Allreduce(&flag, &flagall, 1, MPI_INT, MPI_SUM, world); - if (flagall) error->all(FLERR, "Cannot do neighbor/swap on atoms in atom_modify first group"); + if (flagall) + error->all(FLERR, Error::NOLASTLINE, + "Cannot do neighbor/swap on atoms in atom_modify first group"); } } @@ -548,7 +585,7 @@ int FixNeighborSwap::pick_j_swap_neighbor(int i) return j; } } - error->all(FLERR, "Did not select local neighbor swap atom"); + error->all(FLERR, Error::NOLASTLINE, "Did not select local neighbor swap atom"); } MPI_Allreduce(&jtype_selected_local, &jtype_selected, 1, MPI_INT, MPI_MAX, world); @@ -897,5 +934,6 @@ void FixNeighborSwap::restart(char *buf) bigint ntimestep_restart = (bigint) ubuf(list[n++]).i; if (ntimestep_restart != update->ntimestep) - error->all(FLERR, "Must not reset timestep when restarting fix neighbor/swap"); + error->all(FLERR, Error::NOLASTLINE, + "Must not reset timestep when restarting fix neighbor/swap"); } From 1e7dc5126ed1a9fe15f3d4095832ff67d6560400 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Jun 2025 23:06:55 -0400 Subject: [PATCH 17/37] Flag code that needs improving with TODO comments --- src/MC/fix_neighbor_swap.cpp | 10 +++++++++- src/MC/fix_neighbor_swap.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 9bfb587b8c..d95ad12d68 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -544,6 +544,7 @@ double FixNeighborSwap::energy_full() int FixNeighborSwap::pick_i_swap_atom() { tagint *id = atom->tag; + // TODO: variable id_center_local is set but not used int id_center_local = -1; int i = -1; @@ -551,9 +552,12 @@ int FixNeighborSwap::pick_i_swap_atom() if ((iwhichglobal >= niswap_before) && (iwhichglobal < niswap_before + niswap_local)) { int iwhichlocal = iwhichglobal - niswap_before; i = local_swap_iatom_list[iwhichlocal]; + // TODO: this line has no effect id_center_local = id[i]; MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); } else { + // TODO: i == -1 and thus the following line causes a memory access violation + // and its result is bogus. i must be: 0 <= i < nlocal MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); } @@ -563,6 +567,7 @@ int FixNeighborSwap::pick_i_swap_atom() /* ---------------------------------------------------------------------- ------------------------------------------------------------------------- */ +// TODO: parameter i is never used int FixNeighborSwap::pick_j_swap_neighbor(int i) { int j = -1; @@ -661,7 +666,8 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Get distance if own center atom double r = INFINITY; - if (i_center >= 0) { double r = sqrt(distsq3(x[temp_j], x[i_center])); } + // TODO: this statement has no effect: local declaration of "r" shadows declaration above + if (i_center >= 0) { double r = sqrt(distsq3(x[temp_j], x[i_center])); }; // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { @@ -685,6 +691,7 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; + // TODO: this statement has no effect: local declaration of "r" shadows declaration if (i_center >= 0) { double r = sqrt(distsq3(x[temp_j], x[i_center])); } // Get local id of ghost center atom when ghost @@ -740,6 +747,7 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; + // TODO: this statement has no effect: local declaration of "r" shadows declaration above if (i_center >= 0) { double r = sqrt(distsq3(x[temp_j], x[i_center])); } // Get local id of ghost center atom when ghost diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index 29e0c8d379..75986e7312 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -88,6 +88,7 @@ class FixNeighborSwap : public Fix { int attempt_swap(); double energy_full(); int pick_i_swap_atom(); + // TODO: parameter not used int pick_j_swap_neighbor(int); void build_i_neighbor_list(int); void update_iswap_atoms_list(); From 22082854adb522b9b1f00c84fe45395a39bba323 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 13 Jun 2025 08:55:10 -0400 Subject: [PATCH 18/37] restore documentation files --- doc/src/Commands_fix.rst | 1 + doc/src/fix.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/src/Commands_fix.rst b/doc/src/Commands_fix.rst index 4bdb3c3bc8..700abe0c2b 100644 --- a/doc/src/Commands_fix.rst +++ b/doc/src/Commands_fix.rst @@ -113,6 +113,7 @@ OPT. * :doc:`mvv/tdpd ` * :doc:`neb ` * :doc:`neb/spin ` + * :doc:`neighbor/swap ` * :doc:`nonaffine/displacement ` * :doc:`nph (ko) ` * :doc:`nph/asphere (o) ` diff --git a/doc/src/fix.rst b/doc/src/fix.rst index 459bf895b7..bb0545e406 100644 --- a/doc/src/fix.rst +++ b/doc/src/fix.rst @@ -292,6 +292,7 @@ accelerated styles exist. * :doc:`mvv/tdpd ` - constant temperature DPD using the modified velocity-Verlet algorithm * :doc:`neb ` - nudged elastic band (NEB) spring forces * :doc:`neb/spin ` - nudged elastic band (NEB) spring forces for spins +* :doc:`neighbor/swap ` - kinetic Monte Carlo (kMC) atom swapping * :doc:`nonaffine/displacement ` - calculate nonaffine displacement of atoms * :doc:`nph ` - constant NPH time integration via Nose/Hoover * :doc:`nph/asphere ` - NPH for aspherical particles From 88f777226e171acfddbbde0fb62663f5642b46b7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 13 Jun 2025 08:57:37 -0400 Subject: [PATCH 19/37] restore example --- .../neighbor-swap/MoCoNiVFeAlCr_2nn.meam | 1 + .../neighbor-swap/in.KMC_pulse_center | 46 ++++++ .../PACKAGES/neighbor-swap/in.KMC_pulse_edge | 47 ++++++ .../PACKAGES/neighbor-swap/library_2nn.meam | 1 + .../log.22May22.KMC_pulse_center.g++.1 | 154 +++++++++++++++++ .../log.22May22.KMC_pulse_center.g++.4 | 154 +++++++++++++++++ .../log.22May22.KMC_pulse_edge.g++.1 | 155 ++++++++++++++++++ .../log.22May22.KMC_pulse_edge.g++.4 | 155 ++++++++++++++++++ 8 files changed, 713 insertions(+) create mode 120000 examples/PACKAGES/neighbor-swap/MoCoNiVFeAlCr_2nn.meam create mode 100644 examples/PACKAGES/neighbor-swap/in.KMC_pulse_center create mode 100644 examples/PACKAGES/neighbor-swap/in.KMC_pulse_edge create mode 120000 examples/PACKAGES/neighbor-swap/library_2nn.meam create mode 100644 examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.1 create mode 100644 examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.4 create mode 100644 examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.1 create mode 100644 examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.4 diff --git a/examples/PACKAGES/neighbor-swap/MoCoNiVFeAlCr_2nn.meam b/examples/PACKAGES/neighbor-swap/MoCoNiVFeAlCr_2nn.meam new file mode 120000 index 0000000000..160501aee4 --- /dev/null +++ b/examples/PACKAGES/neighbor-swap/MoCoNiVFeAlCr_2nn.meam @@ -0,0 +1 @@ +../../../potentials/MoCoNiVFeAlCr_2nn.meam \ No newline at end of file diff --git a/examples/PACKAGES/neighbor-swap/in.KMC_pulse_center b/examples/PACKAGES/neighbor-swap/in.KMC_pulse_center new file mode 100644 index 0000000000..29993fab29 --- /dev/null +++ b/examples/PACKAGES/neighbor-swap/in.KMC_pulse_center @@ -0,0 +1,46 @@ +# May 2025 +# Test script for MD-KMC accelerated diffusion testing in LAMMPS +# Created by Jacob Tavenner, Baylor University + +# Initiation ------------------------------------- +units metal +dimension 3 +boundary p p p +atom_style atomic + +# Atom Definition -------------------------------- +lattice fcc 3.762 +region whole block 0 1 0 1 0 1 +create_box 2 whole +create_atoms 1 region whole + +replicate 6 16 6 + +region puck block INF INF 7 9 INF INF +set region puck type 2 + +# Force Fields ----------------------------------- +pair_style meam +pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr + +# Settings --------------------------------------- +timestep 0.002 +thermo 100 + +# Computations ----------------------------------- +compute voroN all voronoi/atom neighbors yes + +run 0 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe + +# Execution -------------------------------------- + +velocity all create 2400 908124 loop geom +fix temp all npt temp 1000 1000 1000 aniso 0 0 1 +fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] +#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym + +run 1000 + +#write_data pulse_center.data diff --git a/examples/PACKAGES/neighbor-swap/in.KMC_pulse_edge b/examples/PACKAGES/neighbor-swap/in.KMC_pulse_edge new file mode 100644 index 0000000000..5bf51d2ed1 --- /dev/null +++ b/examples/PACKAGES/neighbor-swap/in.KMC_pulse_edge @@ -0,0 +1,47 @@ +# May 2025 +# Test script for MD-KMC accelerated diffusion testing in LAMMPS +# Created by Jacob Tavenner, Baylor University + +# Initiation ------------------------------------- +units metal +dimension 3 +boundary p p p +atom_style atomic + + +# Atom Definition -------------------------------- +lattice fcc 3.762 +region whole block 0 1 0 1 0 1 +create_box 2 whole +create_atoms 1 region whole + +replicate 6 16 6 + +region puck block INF INF INF 2 INF INF +set region puck type 2 + +# Force Fields ----------------------------------- +pair_style meam +pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr + +# Settings --------------------------------------- +timestep 0.002 +thermo 100 + +# Computations ----------------------------------- +compute voroN all voronoi/atom neighbors yes + +run 0 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe + +# Execution -------------------------------------- + +velocity all create 2400 908124 loop geom +fix temp all npt temp 1000 1000 1000 aniso 0 0 1 +fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] +#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym + +run 1000 + +#write_data pulse_end.data diff --git a/examples/PACKAGES/neighbor-swap/library_2nn.meam b/examples/PACKAGES/neighbor-swap/library_2nn.meam new file mode 120000 index 0000000000..278b81be6a --- /dev/null +++ b/examples/PACKAGES/neighbor-swap/library_2nn.meam @@ -0,0 +1 @@ +../../../potentials/library_2nn.meam \ No newline at end of file diff --git a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.1 b/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.1 new file mode 100644 index 0000000000..1f1bd00a71 --- /dev/null +++ b/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.1 @@ -0,0 +1,154 @@ +LAMMPS (2 Apr 2025 - Development - patch_2Apr2025-384-g88bc7dc720-modified) + using 1 OpenMP thread(s) per MPI task +# May 2025 +# Test script for MD-KMC accelerated diffusion testing in LAMMPS +# Created by Jacob Tavenner, Baylor University + +# Initiation ------------------------------------- +units metal +dimension 3 +boundary p p p +atom_style atomic + +# Atom Definition -------------------------------- +lattice fcc 3.762 +Lattice spacing in x,y,z = 3.762 3.762 3.762 +region whole block 0 1 0 1 0 1 +create_box 2 whole +Created orthogonal box = (0 0 0) to (3.762 3.762 3.762) + 1 by 1 by 1 MPI processor grid +create_atoms 1 region whole +Created 4 atoms + using lattice units in orthogonal box = (0 0 0) to (3.762 3.762 3.762) + create_atoms CPU = 0.000 seconds + +replicate 6 16 6 +Replication is creating a 6x16x6 = 576 times larger system... + orthogonal box = (0 0 0) to (22.572 60.192 22.572) + 1 by 1 by 1 MPI processor grid + 2304 atoms + replicate CPU = 0.000 seconds + +region puck block INF INF 7 9 INF INF +set region puck type 2 +Setting atom values ... + 360 settings made for type + +# Force Fields ----------------------------------- +pair_style meam +pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr +Reading MEAM library file library_2nn.meam with DATE: 2024-08-08 +Reading MEAM potential file MoCoNiVFeAlCr_2nn.meam with DATE: 2024-08-08 + +# Settings --------------------------------------- +timestep 0.002 +thermo 100 + +# Computations ----------------------------------- +compute voroN all voronoi/atom neighbors yes + +run 0 +WARNING: No fixes with time integration, atoms won't move +For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60) +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 6.8 + ghost atom cutoff = 6.8 + binsize = 3.4, bins = 7 18 7 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair meam, perpetual + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (2) pair meam, perpetual, half/full from (1) + attributes: half, newton on + pair build: halffull/newton + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 13.32 | 13.32 | 13.32 Mbytes + Step Temp E_pair E_mol TotEng Press + 0 0 -9674.3728 0 -9674.3728 -212400.94 +Loop time of 1.202e-06 on 1 procs for 0 steps with 2304 atoms + +0.0% 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 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 1.202e-06 | | |100.00 + +Nlocal: 2304 ave 2304 max 2304 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 4735 ave 4735 max 4735 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 99072 ave 99072 max 99072 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 198144 ave 198144 max 198144 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 198144 +Ave neighs/atom = 86 +Neighbor list builds = 0 +Dangerous builds = 0 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe + +# Execution -------------------------------------- + +velocity all create 2400 908124 +fix temp all npt temp 1000 1000 1000 aniso 0 0 1 +fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] +#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym + +run 1000 +Per MPI rank memory allocation (min/avg/max) = 13.32 | 13.32 | 13.32 Mbytes + Step Temp Press Pxx Pyy Pzz Lx Ly Lz Volume PotEng f_mc[1] f_mc[2] + 0 2400 -187517.52 -187403.07 -187750.14 -187399.35 22.572 60.192 22.572 30667.534 -9674.3728 0 0 + 100 1664.9956 14000 14280.682 15095.077 12624.241 21.635315 57.726568 21.64791 27036.778 -9592.8978 24 22 + 200 1560.0093 -5452.2434 -5749.5816 -2957.4228 -7649.7258 21.734212 58.085959 21.724853 27426.596 -9562.8822 48 45 + 300 1586.4553 2030.9253 2776.4677 775.50538 2540.803 21.678654 58.101753 21.654423 27275.215 -9571.1308 72 66 + 400 1603.6896 -223.16773 156.17673 -478.47929 -347.20061 21.701021 58.098904 21.657752 27306.213 -9576.4456 96 90 + 500 1618.236 -925.51874 -1640.9078 451.6228 -1587.2713 21.718334 58.042685 21.666081 27312.054 -9581.2045 120 110 + 600 1581.9995 290.10126 1359.1314 1407.5434 -1896.371 21.679813 58.086147 21.692118 27316.815 -9570.4803 144 132 + 700 1568.3261 1387.3472 938.81523 2159.3686 1063.8577 21.685928 58.075626 21.67273 27295.153 -9566.2914 168 155 + 800 1607.1531 46.792964 -453.90265 -1533.3908 2127.6723 21.685188 58.202356 21.628338 27297.753 -9577.7848 192 177 + 900 1573.4747 -84.225488 548.90935 -1356.7479 555.16208 21.69634 58.150052 21.651847 27316.908 -9567.7039 216 196 + 1000 1609.2136 1215.0833 764.08936 3301.0811 -419.92053 21.683731 58.000401 21.68726 27275.31 -9578.2843 240 219 +Loop time of 31.6263 on 1 procs for 1000 steps with 2304 atoms + +Performance: 5.464 ns/day, 4.393 hours/ns, 31.619 timesteps/s, 72.851 katom-step/s +99.2% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 28.487 | 28.487 | 28.487 | 0.0 | 90.07 +Neigh | 0.22789 | 0.22789 | 0.22789 | 0.0 | 0.72 +Comm | 0.010808 | 0.010808 | 0.010808 | 0.0 | 0.03 +Output | 0.00033526 | 0.00033526 | 0.00033526 | 0.0 | 0.00 +Modify | 2.8963 | 2.8963 | 2.8963 | 0.0 | 9.16 +Other | | 0.003905 | | | 0.01 + +Nlocal: 2304 ave 2304 max 2304 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 4750 ave 4750 max 4750 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 130023 ave 130023 max 130023 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 260046 ave 260046 max 260046 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 260046 +Ave neighs/atom = 112.86719 +Neighbor list builds = 65 +Dangerous builds = 0 + +#write_data pulse_center.data +Total wall time: 0:00:31 diff --git a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.4 b/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.4 new file mode 100644 index 0000000000..54c372d0f7 --- /dev/null +++ b/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.4 @@ -0,0 +1,154 @@ +LAMMPS (2 Apr 2025 - Development - patch_2Apr2025-384-g88bc7dc720-modified) + using 1 OpenMP thread(s) per MPI task +# May 2025 +# Test script for MD-KMC accelerated diffusion testing in LAMMPS +# Created by Jacob Tavenner, Baylor University + +# Initiation ------------------------------------- +units metal +dimension 3 +boundary p p p +atom_style atomic + +# Atom Definition -------------------------------- +lattice fcc 3.762 +Lattice spacing in x,y,z = 3.762 3.762 3.762 +region whole block 0 1 0 1 0 1 +create_box 2 whole +Created orthogonal box = (0 0 0) to (3.762 3.762 3.762) + 1 by 2 by 2 MPI processor grid +create_atoms 1 region whole +Created 4 atoms + using lattice units in orthogonal box = (0 0 0) to (3.762 3.762 3.762) + create_atoms CPU = 0.000 seconds + +replicate 6 16 6 +Replication is creating a 6x16x6 = 576 times larger system... + orthogonal box = (0 0 0) to (22.572 60.192 22.572) + 1 by 4 by 1 MPI processor grid + 2304 atoms + replicate CPU = 0.000 seconds + +region puck block INF INF 7 9 INF INF +set region puck type 2 +Setting atom values ... + 360 settings made for type + +# Force Fields ----------------------------------- +pair_style meam +pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr +Reading MEAM library file library_2nn.meam with DATE: 2024-08-08 +Reading MEAM potential file MoCoNiVFeAlCr_2nn.meam with DATE: 2024-08-08 + +# Settings --------------------------------------- +timestep 0.002 +thermo 100 + +# Computations ----------------------------------- +compute voroN all voronoi/atom neighbors yes + +run 0 +WARNING: No fixes with time integration, atoms won't move +For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60) +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 6.8 + ghost atom cutoff = 6.8 + binsize = 3.4, bins = 7 18 7 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair meam, perpetual + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (2) pair meam, perpetual, half/full from (1) + attributes: half, newton on + pair build: halffull/newton + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes + Step Temp E_pair E_mol TotEng Press + 0 0 -9674.3728 0 -9674.3728 -212400.94 +Loop time of 1.422e-06 on 4 procs for 0 steps with 2304 atoms + +35.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 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 1.422e-06 | | |100.00 + +Nlocal: 576 ave 576 max 576 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Nghost: 2131 ave 2131 max 2131 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Neighs: 24768 ave 24768 max 24768 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +FullNghs: 49536 ave 49536 max 49536 min +Histogram: 4 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 198144 +Ave neighs/atom = 86 +Neighbor list builds = 0 +Dangerous builds = 0 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe + +# Execution -------------------------------------- + +velocity all create 2400 908124 +fix temp all npt temp 1000 1000 1000 aniso 0 0 1 +fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] +#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym + +run 1000 +Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes + Step Temp Press Pxx Pyy Pzz Lx Ly Lz Volume PotEng f_mc[1] f_mc[2] + 0 2400 -187517.52 -187403.09 -187750.05 -187399.42 22.572 60.192 22.572 30667.534 -9674.3728 0 0 + 100 1668.8754 13300.763 12419.304 15568.772 11914.212 21.636248 57.724775 21.647685 27036.823 -9594.7526 24 23 + 200 1584.9699 -5686.0414 -4741.8496 -5914.7681 -6401.5064 21.729384 58.060532 21.730736 27415.923 -9571.0639 48 46 + 300 1582.0473 2806.2983 3413.4122 2716.0124 2289.4702 21.6679 58.033587 21.694744 27280.402 -9570.5549 72 69 + 400 1582.5825 845.29268 -849.61221 2123.5339 1261.9563 21.676298 58.14253 21.656418 27293.905 -9570.7948 96 93 + 500 1591.7285 -501.17955 1151.9743 -1719.3712 -936.14174 21.696367 58.157211 21.648308 27315.839 -9573.5089 120 116 + 600 1610.708 -821.74669 -1002.4957 291.88502 -1754.6294 21.730338 58.008213 21.661226 27304.8 -9579.5573 144 138 + 700 1598.5176 -590.00633 -1844.42 408.97706 -334.57602 21.712908 57.96131 21.698129 27307.281 -9575.8973 168 162 + 800 1584.3478 330.16711 666.88818 74.698331 248.91482 21.650908 58.045055 21.719838 27295.933 -9571.9268 192 186 + 900 1557.9946 1471.1207 2124.6512 1526.9937 761.71731 21.645578 58.156083 21.681637 27293.323 -9564.4385 216 207 + 1000 1582.5312 379.57005 -602.96446 2696.737 -955.06238 21.655418 58.231248 21.649581 27300.598 -9571.9879 240 227 +Loop time of 9.1632 on 4 procs for 1000 steps with 2304 atoms + +Performance: 18.858 ns/day, 1.273 hours/ns, 109.132 timesteps/s, 251.440 katom-step/s +98.5% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 7.867 | 7.9923 | 8.1311 | 4.3 | 87.22 +Neigh | 0.054997 | 0.057518 | 0.060145 | 1.0 | 0.63 +Comm | 0.017529 | 0.14801 | 0.27408 | 29.5 | 1.62 +Output | 0.00015963 | 0.00017216 | 0.00020869 | 0.0 | 0.00 +Modify | 0.95227 | 0.96325 | 0.9917 | 1.7 | 10.51 +Other | | 0.001983 | | | 0.02 + +Nlocal: 576 ave 609 max 540 min +Histogram: 2 0 0 0 0 0 0 0 0 2 +Nghost: 2161.5 ave 2173 max 2151 min +Histogram: 1 0 1 0 0 0 1 0 0 1 +Neighs: 32450.2 ave 35422 max 29271 min +Histogram: 2 0 0 0 0 0 0 0 0 2 +FullNghs: 64900.5 ave 70800 max 58684 min +Histogram: 2 0 0 0 0 0 0 0 0 2 + +Total # of neighbors = 259602 +Ave neighs/atom = 112.67448 +Neighbor list builds = 62 +Dangerous builds = 0 + +#write_data pulse_center.data +Total wall time: 0:00:09 diff --git a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.1 b/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.1 new file mode 100644 index 0000000000..c7ee0d41b5 --- /dev/null +++ b/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.1 @@ -0,0 +1,155 @@ +LAMMPS (2 Apr 2025 - Development - patch_2Apr2025-384-g88bc7dc720-modified) + using 1 OpenMP thread(s) per MPI task +# May 2025 +# Test script for MD-KMC accelerated diffusion testing in LAMMPS +# Created by Jacob Tavenner, Baylor University + +# Initiation ------------------------------------- +units metal +dimension 3 +boundary p p p +atom_style atomic + + +# Atom Definition -------------------------------- +lattice fcc 3.762 +Lattice spacing in x,y,z = 3.762 3.762 3.762 +region whole block 0 1 0 1 0 1 +create_box 2 whole +Created orthogonal box = (0 0 0) to (3.762 3.762 3.762) + 1 by 1 by 1 MPI processor grid +create_atoms 1 region whole +Created 4 atoms + using lattice units in orthogonal box = (0 0 0) to (3.762 3.762 3.762) + create_atoms CPU = 0.000 seconds + +replicate 6 16 6 +Replication is creating a 6x16x6 = 576 times larger system... + orthogonal box = (0 0 0) to (22.572 60.192 22.572) + 1 by 1 by 1 MPI processor grid + 2304 atoms + replicate CPU = 0.000 seconds + +region puck block INF INF INF 2 INF INF +set region puck type 2 +Setting atom values ... + 360 settings made for type + +# Force Fields ----------------------------------- +pair_style meam +pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr +Reading MEAM library file library_2nn.meam with DATE: 2024-08-08 +Reading MEAM potential file MoCoNiVFeAlCr_2nn.meam with DATE: 2024-08-08 + +# Settings --------------------------------------- +timestep 0.002 +thermo 100 + +# Computations ----------------------------------- +compute voroN all voronoi/atom neighbors yes + +run 0 +WARNING: No fixes with time integration, atoms won't move +For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60) +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 6.8 + ghost atom cutoff = 6.8 + binsize = 3.4, bins = 7 18 7 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair meam, perpetual + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (2) pair meam, perpetual, half/full from (1) + attributes: half, newton on + pair build: halffull/newton + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 13.32 | 13.32 | 13.32 Mbytes + Step Temp E_pair E_mol TotEng Press + 0 0 -9674.3728 0 -9674.3728 -212400.94 +Loop time of 1.232e-06 on 1 procs for 0 steps with 2304 atoms + +81.2% 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 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 1.232e-06 | | |100.00 + +Nlocal: 2304 ave 2304 max 2304 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 4735 ave 4735 max 4735 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 99072 ave 99072 max 99072 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 198144 ave 198144 max 198144 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 198144 +Ave neighs/atom = 86 +Neighbor list builds = 0 +Dangerous builds = 0 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe + +# Execution -------------------------------------- + +velocity all create 2400 908124 loop geom +fix temp all npt temp 1000 1000 1000 aniso 0 0 1 +fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] +#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym + +run 1000 +Per MPI rank memory allocation (min/avg/max) = 13.32 | 13.32 | 13.32 Mbytes + Step Temp Press Pxx Pyy Pzz Lx Ly Lz Volume PotEng f_mc[1] f_mc[2] + 0 2400 -187517.52 -187464.47 -188202.62 -186885.48 22.572 60.192 22.572 30667.534 -9674.3728 0 0 + 100 1665.6154 14281.316 14426.547 14555.867 13861.534 21.637238 57.719793 21.637281 27022.733 -9594.4303 24 24 + 200 1603.3309 -7325.7341 -8878.1524 -5333.0485 -7766.0015 21.710246 58.122827 21.725933 27415.106 -9577.4545 48 48 + 300 1603.2974 207.19165 1983.4565 -1841.9518 480.07024 21.678227 58.079126 21.674033 27288.745 -9577.6391 72 69 + 400 1600.1515 810.95054 1087.969 802.04946 542.83316 21.683731 58.045848 21.678505 27285.662 -9576.6508 96 92 + 500 1629.8313 -2808.1005 -3197.9357 310.89931 -5537.265 21.683924 58.090375 21.697076 27330.229 -9585.5435 120 113 + 600 1598.8232 -67.845623 -1573.0718 -1526.7607 2896.2957 21.70213 58.12191 21.653853 27313.504 -9576.4147 144 137 + 700 1607.2185 154.66718 -1777.2469 2566.4705 -325.22208 21.712408 57.971553 21.678708 27287.033 -9579.1772 168 158 + 800 1582.559 -891.23631 -632.46037 -636.88203 -1404.3665 21.671936 58.127004 21.678224 27308.594 -9571.6663 192 180 + 900 1586.7172 -617.17083 -2495.5378 -2302.8766 2946.9018 21.658489 58.181921 21.668968 27305.771 -9572.9641 216 204 + 1000 1607.563 -389.8113 810.4908 298.84287 -2278.7676 21.624573 58.076745 21.724272 27283.183 -9579.5034 240 227 +Loop time of 31.7733 on 1 procs for 1000 steps with 2304 atoms + +Performance: 5.439 ns/day, 4.413 hours/ns, 31.473 timesteps/s, 72.514 katom-step/s +99.2% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 28.604 | 28.604 | 28.604 | 0.0 | 90.02 +Neigh | 0.21293 | 0.21293 | 0.21293 | 0.0 | 0.67 +Comm | 0.010645 | 0.010645 | 0.010645 | 0.0 | 0.03 +Output | 0.00033194 | 0.00033194 | 0.00033194 | 0.0 | 0.00 +Modify | 2.9411 | 2.9411 | 2.9411 | 0.0 | 9.26 +Other | | 0.00448 | | | 0.01 + +Nlocal: 2304 ave 2304 max 2304 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 4748 ave 4748 max 4748 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 130301 ave 130301 max 130301 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 260602 ave 260602 max 260602 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 260602 +Ave neighs/atom = 113.10851 +Neighbor list builds = 62 +Dangerous builds = 0 + +#write_data pulse_end.data +Total wall time: 0:00:31 diff --git a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.4 b/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.4 new file mode 100644 index 0000000000..da7976d867 --- /dev/null +++ b/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.4 @@ -0,0 +1,155 @@ +LAMMPS (2 Apr 2025 - Development - patch_2Apr2025-384-g88bc7dc720-modified) + using 1 OpenMP thread(s) per MPI task +# May 2025 +# Test script for MD-KMC accelerated diffusion testing in LAMMPS +# Created by Jacob Tavenner, Baylor University + +# Initiation ------------------------------------- +units metal +dimension 3 +boundary p p p +atom_style atomic + + +# Atom Definition -------------------------------- +lattice fcc 3.762 +Lattice spacing in x,y,z = 3.762 3.762 3.762 +region whole block 0 1 0 1 0 1 +create_box 2 whole +Created orthogonal box = (0 0 0) to (3.762 3.762 3.762) + 1 by 2 by 2 MPI processor grid +create_atoms 1 region whole +Created 4 atoms + using lattice units in orthogonal box = (0 0 0) to (3.762 3.762 3.762) + create_atoms CPU = 0.000 seconds + +replicate 6 16 6 +Replication is creating a 6x16x6 = 576 times larger system... + orthogonal box = (0 0 0) to (22.572 60.192 22.572) + 1 by 4 by 1 MPI processor grid + 2304 atoms + replicate CPU = 0.000 seconds + +region puck block INF INF INF 2 INF INF +set region puck type 2 +Setting atom values ... + 360 settings made for type + +# Force Fields ----------------------------------- +pair_style meam +pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr +Reading MEAM library file library_2nn.meam with DATE: 2024-08-08 +Reading MEAM potential file MoCoNiVFeAlCr_2nn.meam with DATE: 2024-08-08 + +# Settings --------------------------------------- +timestep 0.002 +thermo 100 + +# Computations ----------------------------------- +compute voroN all voronoi/atom neighbors yes + +run 0 +WARNING: No fixes with time integration, atoms won't move +For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60) +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 6.8 + ghost atom cutoff = 6.8 + binsize = 3.4, bins = 7 18 7 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair meam, perpetual + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (2) pair meam, perpetual, half/full from (1) + attributes: half, newton on + pair build: halffull/newton + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes + Step Temp E_pair E_mol TotEng Press + 0 0 -9674.3728 0 -9674.3728 -212400.94 +Loop time of 1.53e-06 on 4 procs for 0 steps with 2304 atoms + +65.4% 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 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 1.53e-06 | | |100.00 + +Nlocal: 576 ave 576 max 576 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Nghost: 2131 ave 2131 max 2131 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Neighs: 24768 ave 24768 max 24768 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +FullNghs: 49536 ave 49536 max 49536 min +Histogram: 4 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 198144 +Ave neighs/atom = 86 +Neighbor list builds = 0 +Dangerous builds = 0 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe + +# Execution -------------------------------------- + +velocity all create 2400 908124 loop geom +fix temp all npt temp 1000 1000 1000 aniso 0 0 1 +fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] +#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym + +run 1000 +Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes + Step Temp Press Pxx Pyy Pzz Lx Ly Lz Volume PotEng f_mc[1] f_mc[2] + 0 2400 -187517.52 -187464.47 -188202.62 -186885.48 22.572 60.192 22.572 30667.534 -9674.3728 0 0 + 100 1665.569 14271.813 14638.855 14316.569 13860.016 21.63675 57.721065 21.637799 27023.366 -9594.291 24 24 + 200 1598.6479 -6990.8349 -8574.1986 -5033.6147 -7364.6916 21.708963 58.123129 21.724821 27412.223 -9575.7322 48 47 + 300 1604.388 456.43285 1926.408 -1214.1721 657.0626 21.673369 58.090421 21.671716 27285.018 -9577.698 72 70 + 400 1601.1591 1303.6721 703.88473 1137.6607 2069.471 21.684004 58.049595 21.671161 27278.522 -9576.4811 96 94 + 500 1623.6044 -2243.2478 -2084.532 320.87709 -4966.0885 21.686171 58.097101 21.695911 27334.758 -9583.1878 120 118 + 600 1587.2041 421.60034 190.88741 -328.76599 1402.6796 21.712439 58.086039 21.655927 27312.229 -9572.559 144 141 + 700 1591.2923 32.327829 -2893.2353 1839.7574 1150.4614 21.719102 57.999862 21.666164 27292.974 -9573.9009 168 165 + 800 1580.8587 -105.51079 654.26389 -160.04168 -810.75457 21.670225 58.109245 21.684683 27306.229 -9570.6482 192 186 + 900 1570.7648 1290.088 1252.3689 255.62548 2362.2695 21.68101 58.100507 21.658755 27283.051 -9567.9864 216 209 + 1000 1598.1483 -125.35291 -3626.5479 3404.789 -154.29983 21.720146 57.952942 21.686111 27297.313 -9576.2975 240 231 +Loop time of 9.17241 on 4 procs for 1000 steps with 2304 atoms + +Performance: 18.839 ns/day, 1.274 hours/ns, 109.023 timesteps/s, 251.188 katom-step/s +98.1% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 7.7477 | 8.0143 | 8.1344 | 5.5 | 87.37 +Neigh | 0.050543 | 0.056882 | 0.05986 | 1.6 | 0.62 +Comm | 0.069784 | 0.16898 | 0.40996 | 34.2 | 1.84 +Output | 0.00015612 | 0.0001707 | 0.00021249 | 0.0 | 0.00 +Modify | 0.90628 | 0.93003 | 0.96157 | 2.2 | 10.14 +Other | | 0.002053 | | | 0.02 + +Nlocal: 576 ave 614 max 505 min +Histogram: 1 0 0 0 0 0 1 0 0 2 +Nghost: 2165.75 ave 2204 max 2132 min +Histogram: 1 0 0 0 2 0 0 0 0 1 +Neighs: 32430.8 ave 35552 max 26564 min +Histogram: 1 0 0 0 0 0 1 0 0 2 +FullNghs: 64861.5 ave 71111 max 53164 min +Histogram: 1 0 0 0 0 0 1 0 0 2 + +Total # of neighbors = 259446 +Ave neighs/atom = 112.60677 +Neighbor list builds = 62 +Dangerous builds = 0 + +#write_data pulse_end.data +Total wall time: 0:00:09 From 4d6a085361b21bd8a7dd27d18f48461b6b4cfa42 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 13 Jun 2025 08:58:48 -0400 Subject: [PATCH 20/37] make include guard consistent with file name --- src/MC/fix_neighbor_swap.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index 75986e7312..f490af8b50 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -17,8 +17,8 @@ FixStyle(neighbor/swap,FixNeighborSwap); // clang-format on #else -#ifndef LMP_FIX_NEIGH_SWAP_H -#define LMP_FIX_NEIGH_SWAP_H +#ifndef LMP_FIX_NEIGHBOR_SWAP_H +#define LMP_FIX_NEIGHBOR_SWAP_H #include "fix.h" From 80b41eea9ddce942a7658beb8b6974615ac32826 Mon Sep 17 00:00:00 2001 From: Jacob Tavenner Date: Fri, 4 Jul 2025 15:39:22 -0600 Subject: [PATCH 21/37] Fixed cleanup TODO and tested functionality. MPI memory leak remains. --- src/MC/fix_neighbor_swap.cpp | 26 ++++++++++++-------------- src/MC/fix_neighbor_swap.h | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index d95ad12d68..a1608bd6f1 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -432,7 +432,7 @@ int FixNeighborSwap::attempt_swap() // pick a neighbor atom j based on i neighbor list jtype_selected = -1; - int j = pick_j_swap_neighbor(i); + int j = pick_j_swap_neighbor(); int itype = type_list[0]; int jtype = jtype_selected; @@ -544,19 +544,17 @@ double FixNeighborSwap::energy_full() int FixNeighborSwap::pick_i_swap_atom() { tagint *id = atom->tag; - // TODO: variable id_center_local is set but not used - int id_center_local = -1; + // TODO: variable id_center_local is set but not used - FIXED: Leftover from old selection method int i = -1; int iwhichglobal = static_cast(niswap * random_equal->uniform()); if ((iwhichglobal >= niswap_before) && (iwhichglobal < niswap_before + niswap_local)) { int iwhichlocal = iwhichglobal - niswap_before; i = local_swap_iatom_list[iwhichlocal]; - // TODO: this line has no effect - id_center_local = id[i]; + // TODO: this line has no effect - FIXED: Removed, leftover from old method MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); } else { - // TODO: i == -1 and thus the following line causes a memory access violation + // TODO: i == -1 and thus the following line causes a memory access violation - RETURN, need to sync with MPI_Allreduce above when i=-1 to send id_center to all procs. Find new/proper MPI call. // and its result is bogus. i must be: 0 <= i < nlocal MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); } @@ -567,8 +565,8 @@ int FixNeighborSwap::pick_i_swap_atom() /* ---------------------------------------------------------------------- ------------------------------------------------------------------------- */ -// TODO: parameter i is never used -int FixNeighborSwap::pick_j_swap_neighbor(int i) +// TODO: parameter i is never used - FIXED: Removed, new method already has neigbors selected +int FixNeighborSwap::pick_j_swap_neighbor() { int j = -1; int jtype_selected_local = -1; @@ -666,8 +664,8 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Get distance if own center atom double r = INFINITY; - // TODO: this statement has no effect: local declaration of "r" shadows declaration above - if (i_center >= 0) { double r = sqrt(distsq3(x[temp_j], x[i_center])); }; + // TODO: this statement has no effect: local declaration of "r" shadows declaration above - FIXED: Should be getting atom distances for all local atoms, have removed unecessary re-delcaration of type + if (i_center >= 0) { r = sqrt(distsq3(x[temp_j], x[i_center])); }; // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { @@ -691,8 +689,8 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; - // TODO: this statement has no effect: local declaration of "r" shadows declaration - if (i_center >= 0) { double r = sqrt(distsq3(x[temp_j], x[i_center])); } + // TODO: this statement has no effect: local declaration of "r" shadows declaration - FIXED: See above, same logic as above + if (i_center >= 0) { r = sqrt(distsq3(x[temp_j], x[i_center])); } // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { @@ -747,8 +745,8 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; - // TODO: this statement has no effect: local declaration of "r" shadows declaration above - if (i_center >= 0) { double r = sqrt(distsq3(x[temp_j], x[i_center])); } + // TODO: this statement has no effect: local declaration of "r" shadows declaration above - FIXED: Same logic as above + if (i_center >= 0) { r = sqrt(distsq3(x[temp_j], x[i_center])); } // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index f490af8b50..f72f676291 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -89,7 +89,7 @@ class FixNeighborSwap : public Fix { double energy_full(); int pick_i_swap_atom(); // TODO: parameter not used - int pick_j_swap_neighbor(int); + int pick_j_swap_neighbor(); void build_i_neighbor_list(int); void update_iswap_atoms_list(); }; From b11c549dbdde154dd751a94fc7122ac27061c627 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 Jul 2025 18:09:57 -0400 Subject: [PATCH 22/37] remove "fixed" comments, small stype updates --- src/MC/fix_neighbor_swap.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index a1608bd6f1..aab30e522e 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -544,14 +544,12 @@ double FixNeighborSwap::energy_full() int FixNeighborSwap::pick_i_swap_atom() { tagint *id = atom->tag; - // TODO: variable id_center_local is set but not used - FIXED: Leftover from old selection method int i = -1; int iwhichglobal = static_cast(niswap * random_equal->uniform()); if ((iwhichglobal >= niswap_before) && (iwhichglobal < niswap_before + niswap_local)) { int iwhichlocal = iwhichglobal - niswap_before; i = local_swap_iatom_list[iwhichlocal]; - // TODO: this line has no effect - FIXED: Removed, leftover from old method MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); } else { // TODO: i == -1 and thus the following line causes a memory access violation - RETURN, need to sync with MPI_Allreduce above when i=-1 to send id_center to all procs. Find new/proper MPI call. @@ -565,7 +563,6 @@ int FixNeighborSwap::pick_i_swap_atom() /* ---------------------------------------------------------------------- ------------------------------------------------------------------------- */ -// TODO: parameter i is never used - FIXED: Removed, new method already has neigbors selected int FixNeighborSwap::pick_j_swap_neighbor() { int j = -1; @@ -664,8 +661,7 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Get distance if own center atom double r = INFINITY; - // TODO: this statement has no effect: local declaration of "r" shadows declaration above - FIXED: Should be getting atom distances for all local atoms, have removed unecessary re-delcaration of type - if (i_center >= 0) { r = sqrt(distsq3(x[temp_j], x[i_center])); }; + if (i_center >= 0) = sqrt(distsq3(x[temp_j], x[i_center])); // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { @@ -689,8 +685,7 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; - // TODO: this statement has no effect: local declaration of "r" shadows declaration - FIXED: See above, same logic as above - if (i_center >= 0) { r = sqrt(distsq3(x[temp_j], x[i_center])); } + if (i_center >= 0) r = sqrt(distsq3(x[temp_j], x[i_center])); // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { @@ -745,8 +740,7 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Calculate distance from i to each j, adjust probability of selection // Get distance if own center atom double r = INFINITY; - // TODO: this statement has no effect: local declaration of "r" shadows declaration above - FIXED: Same logic as above - if (i_center >= 0) { r = sqrt(distsq3(x[temp_j], x[i_center])); } + if (i_center >= 0) r = sqrt(distsq3(x[temp_j], x[i_center])); // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { From a85906236c470f6d128b6d6a0b17ff4643a11043 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 Jul 2025 18:14:08 -0400 Subject: [PATCH 23/37] fix typo --- src/MC/fix_neighbor_swap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index aab30e522e..6b273f0e1c 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -661,7 +661,7 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Get distance if own center atom double r = INFINITY; - if (i_center >= 0) = sqrt(distsq3(x[temp_j], x[i_center])); + if (i_center >= 0) r = sqrt(distsq3(x[temp_j], x[i_center])); // Get local id of ghost center atom when ghost for (int i = nlocal; i < nlocal + nghost; i++) { From 57d4c472a058f2beae6271f4533577963d96bf31 Mon Sep 17 00:00:00 2001 From: Jacob Tavenner Date: Fri, 11 Jul 2025 02:39:57 -0600 Subject: [PATCH 24/37] Updated pick_i_swap_atom for MPI_Bcast to avoid memory access leak --- src/MC/fix_neighbor_swap.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 6b273f0e1c..7b6f1ff976 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -544,19 +544,25 @@ double FixNeighborSwap::energy_full() int FixNeighborSwap::pick_i_swap_atom() { tagint *id = atom->tag; - int i = -1; + int i, root_rank = -1; + int rank; + MPI_Comm_rank(world, &rank); int iwhichglobal = static_cast(niswap * random_equal->uniform()); if ((iwhichglobal >= niswap_before) && (iwhichglobal < niswap_before + niswap_local)) { + int iwhichlocal = iwhichglobal - niswap_before; + i = local_swap_iatom_list[iwhichlocal]; - MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); - } else { - // TODO: i == -1 and thus the following line causes a memory access violation - RETURN, need to sync with MPI_Allreduce above when i=-1 to send id_center to all procs. Find new/proper MPI call. - // and its result is bogus. i must be: 0 <= i < nlocal - MPI_Allreduce(&id[i], &id_center, 1, MPI_INT, MPI_MAX, world); + id_center = id[i]; + root_rank = rank; + } + MPI_Allreduce(MPI_IN_PLACE, &root_rank, 1, MPI_INT, MPI_MAX, world); + + MPI_Bcast(&id_center, 1, MPI_INT, root_rank, world); + return i; } From 192901f6d0f7095019ce4851158832a82da60e1e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Jul 2025 05:54:36 -0400 Subject: [PATCH 25/37] add sanity check to error out when the index picking fails. --- src/MC/fix_neighbor_swap.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 7b6f1ff976..e9b22f5f4e 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -438,7 +438,13 @@ int FixNeighborSwap::attempt_swap() int jtype = jtype_selected; // Accept swap if types are equal, no change to system - if (itype == jtype) { return 1; } + if (itype == jtype) return 1; + + // error out when pick_i_swap_atom() or pick_j_swap_neighbor() picked invalid indices + if (i >= atom->nlocal) + error->one(FLERR, Error::NOLASTLINE, "Invalid i index {} chosen for swap. nlocal = {}", i, atom->nlocal); + if (j >= (atom->nlocal + atom->nghost)) + error->one(FLERR, Error::NOLASTLINE, "Invalid j index {} chosen for swap. nall = {}", j, atom->nlocal+atom->nghost); // swap their properties if (i >= 0) { @@ -550,13 +556,12 @@ int FixNeighborSwap::pick_i_swap_atom() int iwhichglobal = static_cast(niswap * random_equal->uniform()); if ((iwhichglobal >= niswap_before) && (iwhichglobal < niswap_before + niswap_local)) { - + int iwhichlocal = iwhichglobal - niswap_before; - + i = local_swap_iatom_list[iwhichlocal]; id_center = id[i]; root_rank = rank; - } MPI_Allreduce(MPI_IN_PLACE, &root_rank, 1, MPI_INT, MPI_MAX, world); From efd051087391bf6a3f964532e3f90ef3ddbf83a4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Jul 2025 06:00:34 -0400 Subject: [PATCH 26/37] update example outputs --- .../log.11Jul25.KMC_pulse_center.g++.1 | 174 +++++++++++++++++ .../log.11Jul25.KMC_pulse_center.g++.4 | 174 +++++++++++++++++ ...g++.1 => log.11Jul25.KMC_pulse_edge.g++.1} | 82 ++++---- .../log.11Jul25.KMC_pulse_edge.g++.4 | 175 ++++++++++++++++++ .../log.22May22.KMC_pulse_center.g++.1 | 154 --------------- .../log.22May22.KMC_pulse_center.g++.4 | 154 --------------- .../log.22May22.KMC_pulse_edge.g++.4 | 155 ---------------- 7 files changed, 574 insertions(+), 494 deletions(-) create mode 100644 examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_center.g++.1 create mode 100644 examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_center.g++.4 rename examples/PACKAGES/neighbor-swap/{log.22May22.KMC_pulse_edge.g++.1 => log.11Jul25.KMC_pulse_edge.g++.1} (74%) create mode 100644 examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_edge.g++.4 delete mode 100644 examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.1 delete mode 100644 examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.4 delete mode 100644 examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.4 diff --git a/examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_center.g++.1 b/examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_center.g++.1 new file mode 100644 index 0000000000..e9825af8ee --- /dev/null +++ b/examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_center.g++.1 @@ -0,0 +1,174 @@ +LAMMPS (12 Jun 2025 - Development - patch_12Jun2025-605-g5eb61491f0-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. + using 1 OpenMP thread(s) per MPI task +# May 2025 +# Test script for MD-KMC accelerated diffusion testing in LAMMPS +# Created by Jacob Tavenner, Baylor University + +# Initiation ------------------------------------- +units metal +dimension 3 +boundary p p p +atom_style atomic + +# Atom Definition -------------------------------- +lattice fcc 3.762 +Lattice spacing in x,y,z = 3.762 3.762 3.762 +region whole block 0 1 0 1 0 1 +create_box 2 whole +Created orthogonal box = (0 0 0) to (3.762 3.762 3.762) + 1 by 1 by 1 MPI processor grid +create_atoms 1 region whole +Created 4 atoms + using lattice units in orthogonal box = (0 0 0) to (3.762 3.762 3.762) + create_atoms CPU = 0.000 seconds + +replicate 6 16 6 +Replication is creating a 6x16x6 = 576 times larger system... + orthogonal box = (0 0 0) to (22.572 60.192 22.572) + 1 by 1 by 1 MPI processor grid + 2304 atoms + replicate CPU = 0.000 seconds + +region puck block INF INF 7 9 INF INF +set region puck type 2 +Setting atom values ... + 360 settings made for type + +# Force Fields ----------------------------------- +pair_style meam +pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr +Reading MEAM library file library_2nn.meam with DATE: 2024-08-08 +Reading MEAM potential file MoCoNiVFeAlCr_2nn.meam with DATE: 2024-08-08 + +# Settings --------------------------------------- +timestep 0.002 +thermo 100 + +# Computations ----------------------------------- +compute voroN all voronoi/atom neighbors yes + +run 0 +WARNING: No fixes with time integration, atoms won't move +For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60) +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 6.8 + ghost atom cutoff = 6.8 + binsize = 3.4, bins = 7 18 7 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair meam, perpetual + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (2) pair meam, perpetual, half/full from (1) + attributes: half, newton on + pair build: halffull/newton + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 13.32 | 13.32 | 13.32 Mbytes + Step Temp E_pair E_mol TotEng Press + 0 0 -9674.3728 0 -9674.3728 -212400.94 +Loop time of 8.62e-07 on 1 procs for 0 steps with 2304 atoms + +0.0% 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 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 8.62e-07 | | |100.00 + +Nlocal: 2304 ave 2304 max 2304 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 4735 ave 4735 max 4735 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 99072 ave 99072 max 99072 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 198144 ave 198144 max 198144 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 198144 +Ave neighs/atom = 86 +Neighbor list builds = 0 +Dangerous builds = 0 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe + +# Execution -------------------------------------- + +velocity all create 2400 908124 loop geom +fix temp all npt temp 1000 1000 1000 aniso 0 0 1 +fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] +#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym + +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 neighbor/swap command: doi:10.1016/j.commatsci.2022.111929 + +@Article{Tavenner2023111929, + author = {Jacob P. Tavenner and Mikhail I. Mendelev and John W. Lawson}, + title = {Molecular dynamics based kinetic Monte Carlo simulation for accelerated diffusion}, + journal = {Computational Materials Science}, + year = {2023}, + volume = {218}, + pages = {111929} + url = {https://dx.doi.org/10.1016/j.commatsci.2022.111929} +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Per MPI rank memory allocation (min/avg/max) = 13.32 | 13.32 | 13.32 Mbytes + Step Temp Press Pxx Pyy Pzz Lx Ly Lz Volume PotEng f_mc[1] f_mc[2] + 0 2400 -187517.52 -187464.28 -188202.86 -186885.42 22.572 60.192 22.572 30667.534 -9674.3728 0 0 + 100 1687.1584 13681.454 14112.794 14026.902 12904.667 21.637683 57.728817 21.63703 27027.2 -9600.6424 24 23 + 200 1578.9879 -6074.2872 -7170.074 -4456.4001 -6596.3875 21.71812 58.13626 21.712735 27414.722 -9569.7632 48 44 + 300 1586.0502 1921.5002 2871.8396 1449.0001 1443.661 21.677891 58.13829 21.643595 27277.759 -9572.2349 72 67 + 400 1599.8151 459.13309 -890.62191 638.40686 1629.6143 21.662475 58.208733 21.64368 27291.495 -9576.3711 96 88 + 500 1622.7406 -980.83045 -358.66202 -2883.0275 299.19813 21.627475 58.244052 21.683194 27313.708 -9583.2244 120 110 + 600 1558.3072 661.01491 2134.4817 -1069.4315 917.99455 21.675158 58.08722 21.705367 27328.136 -9564.1953 144 132 + 700 1585.7908 2896.8915 2712.2516 5131.3298 847.09324 21.703761 57.89964 21.704281 27274.466 -9572.077 168 154 + 800 1593.7707 -754.08728 -529.51328 807.24585 -2539.9944 21.682927 58.129291 21.67599 27320.704 -9574.7174 192 175 + 900 1594.1026 -504.80889 147.79949 -1421.9393 -240.28691 21.678023 58.172814 21.655846 27309.572 -9574.7989 216 198 + 1000 1604.8161 1017.6914 707.59987 2068.9348 276.53957 21.696786 57.985179 21.676799 27271.408 -9578.0587 240 221 +Loop time of 30.6062 on 1 procs for 1000 steps with 2304 atoms + +Performance: 5.646 ns/day, 4.251 hours/ns, 32.673 timesteps/s, 75.279 katom-step/s +99.6% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 27.514 | 27.514 | 27.514 | 0.0 | 89.90 +Neigh | 0.22106 | 0.22106 | 0.22106 | 0.0 | 0.72 +Comm | 0.011786 | 0.011786 | 0.011786 | 0.0 | 0.04 +Output | 0.00030095 | 0.00030095 | 0.00030095 | 0.0 | 0.00 +Modify | 2.854 | 2.854 | 2.854 | 0.0 | 9.32 +Other | | 0.004794 | | | 0.02 + +Nlocal: 2304 ave 2304 max 2304 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 4744 ave 4744 max 4744 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 130039 ave 130039 max 130039 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 260078 ave 260078 max 260078 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 260078 +Ave neighs/atom = 112.88108 +Neighbor list builds = 62 +Dangerous builds = 0 + +#write_data pulse_center.data +Total wall time: 0:00:30 diff --git a/examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_center.g++.4 b/examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_center.g++.4 new file mode 100644 index 0000000000..feafbc166a --- /dev/null +++ b/examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_center.g++.4 @@ -0,0 +1,174 @@ +LAMMPS (12 Jun 2025 - Development - patch_12Jun2025-605-g5eb61491f0-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. + using 1 OpenMP thread(s) per MPI task +# May 2025 +# Test script for MD-KMC accelerated diffusion testing in LAMMPS +# Created by Jacob Tavenner, Baylor University + +# Initiation ------------------------------------- +units metal +dimension 3 +boundary p p p +atom_style atomic + +# Atom Definition -------------------------------- +lattice fcc 3.762 +Lattice spacing in x,y,z = 3.762 3.762 3.762 +region whole block 0 1 0 1 0 1 +create_box 2 whole +Created orthogonal box = (0 0 0) to (3.762 3.762 3.762) + 1 by 2 by 2 MPI processor grid +create_atoms 1 region whole +Created 4 atoms + using lattice units in orthogonal box = (0 0 0) to (3.762 3.762 3.762) + create_atoms CPU = 0.000 seconds + +replicate 6 16 6 +Replication is creating a 6x16x6 = 576 times larger system... + orthogonal box = (0 0 0) to (22.572 60.192 22.572) + 1 by 4 by 1 MPI processor grid + 2304 atoms + replicate CPU = 0.000 seconds + +region puck block INF INF 7 9 INF INF +set region puck type 2 +Setting atom values ... + 360 settings made for type + +# Force Fields ----------------------------------- +pair_style meam +pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr +Reading MEAM library file library_2nn.meam with DATE: 2024-08-08 +Reading MEAM potential file MoCoNiVFeAlCr_2nn.meam with DATE: 2024-08-08 + +# Settings --------------------------------------- +timestep 0.002 +thermo 100 + +# Computations ----------------------------------- +compute voroN all voronoi/atom neighbors yes + +run 0 +WARNING: No fixes with time integration, atoms won't move +For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60) +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 6.8 + ghost atom cutoff = 6.8 + binsize = 3.4, bins = 7 18 7 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair meam, perpetual + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (2) pair meam, perpetual, half/full from (1) + attributes: half, newton on + pair build: halffull/newton + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes + Step Temp E_pair E_mol TotEng Press + 0 0 -9674.3728 0 -9674.3728 -212400.94 +Loop time of 4.3735e-06 on 4 procs for 0 steps with 2304 atoms + +0.0% 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 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 4.374e-06 | | |100.00 + +Nlocal: 576 ave 576 max 576 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Nghost: 2131 ave 2131 max 2131 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Neighs: 24768 ave 24768 max 24768 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +FullNghs: 49536 ave 49536 max 49536 min +Histogram: 4 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 198144 +Ave neighs/atom = 86 +Neighbor list builds = 0 +Dangerous builds = 0 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe + +# Execution -------------------------------------- + +velocity all create 2400 908124 loop geom +fix temp all npt temp 1000 1000 1000 aniso 0 0 1 +fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] +#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym + +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 neighbor/swap command: doi:10.1016/j.commatsci.2022.111929 + +@Article{Tavenner2023111929, + author = {Jacob P. Tavenner and Mikhail I. Mendelev and John W. Lawson}, + title = {Molecular dynamics based kinetic Monte Carlo simulation for accelerated diffusion}, + journal = {Computational Materials Science}, + year = {2023}, + volume = {218}, + pages = {111929} + url = {https://dx.doi.org/10.1016/j.commatsci.2022.111929} +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes + Step Temp Press Pxx Pyy Pzz Lx Ly Lz Volume PotEng f_mc[1] f_mc[2] + 0 2400 -187517.52 -187464.28 -188202.86 -186885.42 22.572 60.192 22.572 30667.534 -9674.3728 0 0 + 100 1688.7809 13746.894 14218.282 14190.983 12831.417 21.636615 57.726346 21.637269 27025.008 -9601.4799 24 24 + 200 1585.0272 -6497.2882 -7280.7893 -5297.3951 -6913.6802 21.716781 58.142867 21.714094 27417.864 -9571.8204 48 45 + 300 1592.737 1747.6515 2738.4114 1924.1359 580.40727 21.676942 58.130592 21.647155 27277.439 -9574.5368 72 68 + 400 1594.154 852.39952 -369.56275 1867.5224 1059.2389 21.659314 58.220677 21.640495 27289.096 -9574.1977 96 89 + 500 1616.8485 -1466.6184 -1965.5854 -2117.4507 -316.81912 21.622512 58.328889 21.660903 27319.101 -9580.0369 120 112 + 600 1560.0956 1162.0193 2410.2796 -925.45844 2001.2369 21.637185 58.168753 21.700261 27312.124 -9564.0088 144 136 + 700 1583.4354 1031.9177 243.6789 5034.5413 -2182.467 21.682521 57.96166 21.718651 27295.022 -9570.2301 168 158 + 800 1618.7711 -2148.2603 -4066.0779 -863.23022 -1515.4726 21.694024 58.144275 21.659535 27320.975 -9581.5884 192 181 + 900 1598.9132 -764.84277 413.68636 -2395.8324 -312.3823 21.650745 58.249779 21.651506 27305.821 -9575.9563 216 204 + 1000 1603.2739 240.94022 606.79481 644.45464 -528.42878 21.661235 58.138319 21.674995 27296.357 -9577.7462 240 228 +Loop time of 8.90243 on 4 procs for 1000 steps with 2304 atoms + +Performance: 19.410 ns/day, 1.236 hours/ns, 112.329 timesteps/s, 258.806 katom-step/s +98.9% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 7.5993 | 7.7187 | 7.8278 | 3.8 | 86.70 +Neigh | 0.056181 | 0.059129 | 0.062043 | 1.1 | 0.66 +Comm | 0.052658 | 0.14746 | 0.25458 | 24.3 | 1.66 +Output | 0.00018588 | 0.00019825 | 0.00023195 | 0.0 | 0.00 +Modify | 0.95669 | 0.97388 | 0.99047 | 1.6 | 10.94 +Other | | 0.00311 | | | 0.03 + +Nlocal: 576 ave 619 max 531 min +Histogram: 1 0 1 0 0 0 0 0 1 1 +Nghost: 2159.25 ave 2181 max 2126 min +Histogram: 1 0 0 0 0 0 1 0 1 1 +Neighs: 32404.8 ave 36204 max 28467 min +Histogram: 1 0 1 0 0 0 0 0 1 1 +FullNghs: 64809.5 ave 72517 max 56929 min +Histogram: 1 1 0 0 0 0 0 0 1 1 + +Total # of neighbors = 259238 +Ave neighs/atom = 112.51649 +Neighbor list builds = 62 +Dangerous builds = 0 + +#write_data pulse_center.data +Total wall time: 0:00:08 diff --git a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.1 b/examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_edge.g++.1 similarity index 74% rename from examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.1 rename to examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_edge.g++.1 index c7ee0d41b5..7d2c5b37cb 100644 --- a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.1 +++ b/examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_edge.g++.1 @@ -1,24 +1,25 @@ -LAMMPS (2 Apr 2025 - Development - patch_2Apr2025-384-g88bc7dc720-modified) +LAMMPS (12 Jun 2025 - Development - patch_12Jun2025-605-g5eb61491f0-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. using 1 OpenMP thread(s) per MPI task # May 2025 # Test script for MD-KMC accelerated diffusion testing in LAMMPS # Created by Jacob Tavenner, Baylor University # Initiation ------------------------------------- -units metal -dimension 3 -boundary p p p -atom_style atomic +units metal +dimension 3 +boundary p p p +atom_style atomic # Atom Definition -------------------------------- -lattice fcc 3.762 +lattice fcc 3.762 Lattice spacing in x,y,z = 3.762 3.762 3.762 -region whole block 0 1 0 1 0 1 -create_box 2 whole +region whole block 0 1 0 1 0 1 +create_box 2 whole Created orthogonal box = (0 0 0) to (3.762 3.762 3.762) 1 by 1 by 1 MPI processor grid -create_atoms 1 region whole +create_atoms 1 region whole Created 4 atoms using lattice units in orthogonal box = (0 0 0) to (3.762 3.762 3.762) create_atoms CPU = 0.000 seconds @@ -36,19 +37,19 @@ Setting atom values ... 360 settings made for type # Force Fields ----------------------------------- -pair_style meam -pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr +pair_style meam +pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr Reading MEAM library file library_2nn.meam with DATE: 2024-08-08 Reading MEAM potential file MoCoNiVFeAlCr_2nn.meam with DATE: 2024-08-08 # Settings --------------------------------------- -timestep 0.002 -thermo 100 +timestep 0.002 +thermo 100 # Computations ----------------------------------- -compute voroN all voronoi/atom neighbors yes +compute voroN all voronoi/atom neighbors yes -run 0 +run 0 WARNING: No fixes with time integration, atoms won't move For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60) Neighbor list info ... @@ -71,9 +72,9 @@ Neighbor list info ... Per MPI rank memory allocation (min/avg/max) = 13.32 | 13.32 | 13.32 Mbytes Step Temp E_pair E_mol TotEng Press 0 0 -9674.3728 0 -9674.3728 -212400.94 -Loop time of 1.232e-06 on 1 procs for 0 steps with 2304 atoms +Loop time of 7.92e-07 on 1 procs for 0 steps with 2304 atoms -81.2% CPU use with 1 MPI tasks x 1 OpenMP threads +126.3% CPU use with 1 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total @@ -83,7 +84,7 @@ Neigh | 0 | 0 | 0 | 0.0 | 0.00 Comm | 0 | 0 | 0 | 0.0 | 0.00 Output | 0 | 0 | 0 | 0.0 | 0.00 Modify | 0 | 0 | 0 | 0.0 | 0.00 -Other | | 1.232e-06 | | |100.00 +Other | | 7.92e-07 | | |100.00 Nlocal: 2304 ave 2304 max 2304 min Histogram: 1 0 0 0 0 0 0 0 0 0 @@ -98,17 +99,36 @@ Total # of neighbors = 198144 Ave neighs/atom = 86 Neighbor list builds = 0 Dangerous builds = 0 -thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe # Execution -------------------------------------- velocity all create 2400 908124 loop geom fix temp all npt temp 1000 1000 1000 aniso 0 0 1 fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 -thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] -#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] +#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym 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 neighbor/swap command: doi:10.1016/j.commatsci.2022.111929 + +@Article{Tavenner2023111929, + author = {Jacob P. Tavenner and Mikhail I. Mendelev and John W. Lawson}, + title = {Molecular dynamics based kinetic Monte Carlo simulation for accelerated diffusion}, + journal = {Computational Materials Science}, + year = {2023}, + volume = {218}, + pages = {111929} + url = {https://dx.doi.org/10.1016/j.commatsci.2022.111929} +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + Per MPI rank memory allocation (min/avg/max) = 13.32 | 13.32 | 13.32 Mbytes Step Temp Press Pxx Pyy Pzz Lx Ly Lz Volume PotEng f_mc[1] f_mc[2] 0 2400 -187517.52 -187464.47 -188202.62 -186885.48 22.572 60.192 22.572 30667.534 -9674.3728 0 0 @@ -122,20 +142,20 @@ Per MPI rank memory allocation (min/avg/max) = 13.32 | 13.32 | 13.32 Mbytes 800 1582.559 -891.23631 -632.46037 -636.88203 -1404.3665 21.671936 58.127004 21.678224 27308.594 -9571.6663 192 180 900 1586.7172 -617.17083 -2495.5378 -2302.8766 2946.9018 21.658489 58.181921 21.668968 27305.771 -9572.9641 216 204 1000 1607.563 -389.8113 810.4908 298.84287 -2278.7676 21.624573 58.076745 21.724272 27283.183 -9579.5034 240 227 -Loop time of 31.7733 on 1 procs for 1000 steps with 2304 atoms +Loop time of 31.1311 on 1 procs for 1000 steps with 2304 atoms -Performance: 5.439 ns/day, 4.413 hours/ns, 31.473 timesteps/s, 72.514 katom-step/s -99.2% CPU use with 1 MPI tasks x 1 OpenMP threads +Performance: 5.551 ns/day, 4.324 hours/ns, 32.122 timesteps/s, 74.010 katom-step/s +99.6% CPU use with 1 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total --------------------------------------------------------------- -Pair | 28.604 | 28.604 | 28.604 | 0.0 | 90.02 -Neigh | 0.21293 | 0.21293 | 0.21293 | 0.0 | 0.67 -Comm | 0.010645 | 0.010645 | 0.010645 | 0.0 | 0.03 -Output | 0.00033194 | 0.00033194 | 0.00033194 | 0.0 | 0.00 -Modify | 2.9411 | 2.9411 | 2.9411 | 0.0 | 9.26 -Other | | 0.00448 | | | 0.01 +Pair | 27.859 | 27.859 | 27.859 | 0.0 | 89.49 +Neigh | 0.22271 | 0.22271 | 0.22271 | 0.0 | 0.72 +Comm | 0.012597 | 0.012597 | 0.012597 | 0.0 | 0.04 +Output | 0.00031219 | 0.00031219 | 0.00031219 | 0.0 | 0.00 +Modify | 3.0301 | 3.0301 | 3.0301 | 0.0 | 9.73 +Other | | 0.006178 | | | 0.02 Nlocal: 2304 ave 2304 max 2304 min Histogram: 1 0 0 0 0 0 0 0 0 0 @@ -151,5 +171,5 @@ Ave neighs/atom = 113.10851 Neighbor list builds = 62 Dangerous builds = 0 -#write_data pulse_end.data +#write_data pulse_end.data Total wall time: 0:00:31 diff --git a/examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_edge.g++.4 b/examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_edge.g++.4 new file mode 100644 index 0000000000..160918d63f --- /dev/null +++ b/examples/PACKAGES/neighbor-swap/log.11Jul25.KMC_pulse_edge.g++.4 @@ -0,0 +1,175 @@ +LAMMPS (12 Jun 2025 - Development - patch_12Jun2025-605-g5eb61491f0-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. + using 1 OpenMP thread(s) per MPI task +# May 2025 +# Test script for MD-KMC accelerated diffusion testing in LAMMPS +# Created by Jacob Tavenner, Baylor University + +# Initiation ------------------------------------- +units metal +dimension 3 +boundary p p p +atom_style atomic + + +# Atom Definition -------------------------------- +lattice fcc 3.762 +Lattice spacing in x,y,z = 3.762 3.762 3.762 +region whole block 0 1 0 1 0 1 +create_box 2 whole +Created orthogonal box = (0 0 0) to (3.762 3.762 3.762) + 1 by 2 by 2 MPI processor grid +create_atoms 1 region whole +Created 4 atoms + using lattice units in orthogonal box = (0 0 0) to (3.762 3.762 3.762) + create_atoms CPU = 0.001 seconds + +replicate 6 16 6 +Replication is creating a 6x16x6 = 576 times larger system... + orthogonal box = (0 0 0) to (22.572 60.192 22.572) + 1 by 4 by 1 MPI processor grid + 2304 atoms + replicate CPU = 0.000 seconds + +region puck block INF INF INF 2 INF INF +set region puck type 2 +Setting atom values ... + 360 settings made for type + +# Force Fields ----------------------------------- +pair_style meam +pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr +Reading MEAM library file library_2nn.meam with DATE: 2024-08-08 +Reading MEAM potential file MoCoNiVFeAlCr_2nn.meam with DATE: 2024-08-08 + +# Settings --------------------------------------- +timestep 0.002 +thermo 100 + +# Computations ----------------------------------- +compute voroN all voronoi/atom neighbors yes + +run 0 +WARNING: No fixes with time integration, atoms won't move +For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60) +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 6.8 + ghost atom cutoff = 6.8 + binsize = 3.4, bins = 7 18 7 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair meam, perpetual + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (2) pair meam, perpetual, half/full from (1) + attributes: half, newton on + pair build: halffull/newton + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes + Step Temp E_pair E_mol TotEng Press + 0 0 -9674.3728 0 -9674.3728 -212400.94 +Loop time of 1.84625e-06 on 4 procs for 0 steps with 2304 atoms + +135.4% 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 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 1.846e-06 | | |100.00 + +Nlocal: 576 ave 576 max 576 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Nghost: 2131 ave 2131 max 2131 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Neighs: 24768 ave 24768 max 24768 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +FullNghs: 49536 ave 49536 max 49536 min +Histogram: 4 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 198144 +Ave neighs/atom = 86 +Neighbor list builds = 0 +Dangerous builds = 0 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe + +# Execution -------------------------------------- + +velocity all create 2400 908124 loop geom +fix temp all npt temp 1000 1000 1000 aniso 0 0 1 +fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 +thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] +#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym + +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 neighbor/swap command: doi:10.1016/j.commatsci.2022.111929 + +@Article{Tavenner2023111929, + author = {Jacob P. Tavenner and Mikhail I. Mendelev and John W. Lawson}, + title = {Molecular dynamics based kinetic Monte Carlo simulation for accelerated diffusion}, + journal = {Computational Materials Science}, + year = {2023}, + volume = {218}, + pages = {111929} + url = {https://dx.doi.org/10.1016/j.commatsci.2022.111929} +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes + Step Temp Press Pxx Pyy Pzz Lx Ly Lz Volume PotEng f_mc[1] f_mc[2] + 0 2400 -187517.52 -187464.47 -188202.62 -186885.48 22.572 60.192 22.572 30667.534 -9674.3728 0 0 + 100 1662.8388 14433.559 14653.105 14684.034 13963.538 21.637114 57.721378 21.63721 27023.232 -9593.5557 24 23 + 200 1592.9276 -6765.4603 -8210.8697 -4995.7657 -7089.7454 21.709482 58.120737 21.726324 27413.648 -9573.9313 48 45 + 300 1619.7013 -391.64606 982.6812 -1910.4062 -247.21322 21.674555 58.073042 21.673346 27280.4 -9583.2581 72 69 + 400 1595.5295 1320.1347 726.16024 2142.0732 1092.1705 21.687154 58.033385 21.679884 27285.845 -9575.3049 96 92 + 500 1613.2865 -2150.2729 -2059.2665 -196.97204 -4194.58 21.675436 58.092453 21.698792 27322.668 -9581.7322 120 114 + 600 1587.7089 685.3534 113.39179 523.41016 1419.2583 21.69641 58.089816 21.665296 27305.65 -9572.879 144 135 + 700 1596.2078 232.23434 -985.47338 1818.9814 -136.80497 21.712357 57.974481 21.690493 27303.182 -9575.5985 168 157 + 800 1544.7314 1176.3622 -1011.314 3132.5302 1407.8703 21.681458 58.02289 21.705773 27306.315 -9560.7678 192 179 + 900 1579.6589 45.000317 -72.21997 -1479.7462 1686.9671 21.649984 58.218959 21.671494 27315.607 -9570.1227 216 198 + 1000 1609.6666 95.736886 -795.90474 641.09574 442.01966 21.651706 58.158209 21.667909 27284.76 -9579.3522 240 221 +Loop time of 9.05461 on 4 procs for 1000 steps with 2304 atoms + +Performance: 19.084 ns/day, 1.258 hours/ns, 110.441 timesteps/s, 254.456 katom-step/s +98.8% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 7.4742 | 7.7144 | 7.8285 | 5.1 | 85.20 +Neigh | 0.051898 | 0.058573 | 0.061819 | 1.6 | 0.65 +Comm | 0.063429 | 0.15788 | 0.37324 | 31.7 | 1.74 +Output | 0.00018368 | 0.00019631 | 0.00023307 | 0.0 | 0.00 +Modify | 1.098 | 1.1206 | 1.1519 | 1.9 | 12.38 +Other | | 0.002936 | | | 0.03 + +Nlocal: 576 ave 612 max 506 min +Histogram: 1 0 0 0 0 0 0 1 1 1 +Nghost: 2165.5 ave 2211 max 2128 min +Histogram: 1 1 0 0 0 0 1 0 0 1 +Neighs: 32568.8 ave 35314 max 26622 min +Histogram: 1 0 0 0 0 0 0 1 0 2 +FullNghs: 65137.5 ave 70664 max 53385 min +Histogram: 1 0 0 0 0 0 0 1 0 2 + +Total # of neighbors = 260550 +Ave neighs/atom = 113.08594 +Neighbor list builds = 62 +Dangerous builds = 0 + +#write_data pulse_end.data +Total wall time: 0:00:09 diff --git a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.1 b/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.1 deleted file mode 100644 index 1f1bd00a71..0000000000 --- a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.1 +++ /dev/null @@ -1,154 +0,0 @@ -LAMMPS (2 Apr 2025 - Development - patch_2Apr2025-384-g88bc7dc720-modified) - using 1 OpenMP thread(s) per MPI task -# May 2025 -# Test script for MD-KMC accelerated diffusion testing in LAMMPS -# Created by Jacob Tavenner, Baylor University - -# Initiation ------------------------------------- -units metal -dimension 3 -boundary p p p -atom_style atomic - -# Atom Definition -------------------------------- -lattice fcc 3.762 -Lattice spacing in x,y,z = 3.762 3.762 3.762 -region whole block 0 1 0 1 0 1 -create_box 2 whole -Created orthogonal box = (0 0 0) to (3.762 3.762 3.762) - 1 by 1 by 1 MPI processor grid -create_atoms 1 region whole -Created 4 atoms - using lattice units in orthogonal box = (0 0 0) to (3.762 3.762 3.762) - create_atoms CPU = 0.000 seconds - -replicate 6 16 6 -Replication is creating a 6x16x6 = 576 times larger system... - orthogonal box = (0 0 0) to (22.572 60.192 22.572) - 1 by 1 by 1 MPI processor grid - 2304 atoms - replicate CPU = 0.000 seconds - -region puck block INF INF 7 9 INF INF -set region puck type 2 -Setting atom values ... - 360 settings made for type - -# Force Fields ----------------------------------- -pair_style meam -pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr -Reading MEAM library file library_2nn.meam with DATE: 2024-08-08 -Reading MEAM potential file MoCoNiVFeAlCr_2nn.meam with DATE: 2024-08-08 - -# Settings --------------------------------------- -timestep 0.002 -thermo 100 - -# Computations ----------------------------------- -compute voroN all voronoi/atom neighbors yes - -run 0 -WARNING: No fixes with time integration, atoms won't move -For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60) -Neighbor list info ... - update: every = 1 steps, delay = 0 steps, check = yes - max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 6.8 - ghost atom cutoff = 6.8 - binsize = 3.4, bins = 7 18 7 - 2 neighbor lists, perpetual/occasional/extra = 2 0 0 - (1) pair meam, perpetual - attributes: full, newton on - pair build: full/bin/atomonly - stencil: full/bin/3d - bin: standard - (2) pair meam, perpetual, half/full from (1) - attributes: half, newton on - pair build: halffull/newton - stencil: none - bin: none -Per MPI rank memory allocation (min/avg/max) = 13.32 | 13.32 | 13.32 Mbytes - Step Temp E_pair E_mol TotEng Press - 0 0 -9674.3728 0 -9674.3728 -212400.94 -Loop time of 1.202e-06 on 1 procs for 0 steps with 2304 atoms - -0.0% 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 | 0 | 0 | 0.0 | 0.00 -Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 0 | 0 | 0 | 0.0 | 0.00 -Output | 0 | 0 | 0 | 0.0 | 0.00 -Modify | 0 | 0 | 0 | 0.0 | 0.00 -Other | | 1.202e-06 | | |100.00 - -Nlocal: 2304 ave 2304 max 2304 min -Histogram: 1 0 0 0 0 0 0 0 0 0 -Nghost: 4735 ave 4735 max 4735 min -Histogram: 1 0 0 0 0 0 0 0 0 0 -Neighs: 99072 ave 99072 max 99072 min -Histogram: 1 0 0 0 0 0 0 0 0 0 -FullNghs: 198144 ave 198144 max 198144 min -Histogram: 1 0 0 0 0 0 0 0 0 0 - -Total # of neighbors = 198144 -Ave neighs/atom = 86 -Neighbor list builds = 0 -Dangerous builds = 0 -thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe - -# Execution -------------------------------------- - -velocity all create 2400 908124 -fix temp all npt temp 1000 1000 1000 aniso 0 0 1 -fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 -thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] -#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym - -run 1000 -Per MPI rank memory allocation (min/avg/max) = 13.32 | 13.32 | 13.32 Mbytes - Step Temp Press Pxx Pyy Pzz Lx Ly Lz Volume PotEng f_mc[1] f_mc[2] - 0 2400 -187517.52 -187403.07 -187750.14 -187399.35 22.572 60.192 22.572 30667.534 -9674.3728 0 0 - 100 1664.9956 14000 14280.682 15095.077 12624.241 21.635315 57.726568 21.64791 27036.778 -9592.8978 24 22 - 200 1560.0093 -5452.2434 -5749.5816 -2957.4228 -7649.7258 21.734212 58.085959 21.724853 27426.596 -9562.8822 48 45 - 300 1586.4553 2030.9253 2776.4677 775.50538 2540.803 21.678654 58.101753 21.654423 27275.215 -9571.1308 72 66 - 400 1603.6896 -223.16773 156.17673 -478.47929 -347.20061 21.701021 58.098904 21.657752 27306.213 -9576.4456 96 90 - 500 1618.236 -925.51874 -1640.9078 451.6228 -1587.2713 21.718334 58.042685 21.666081 27312.054 -9581.2045 120 110 - 600 1581.9995 290.10126 1359.1314 1407.5434 -1896.371 21.679813 58.086147 21.692118 27316.815 -9570.4803 144 132 - 700 1568.3261 1387.3472 938.81523 2159.3686 1063.8577 21.685928 58.075626 21.67273 27295.153 -9566.2914 168 155 - 800 1607.1531 46.792964 -453.90265 -1533.3908 2127.6723 21.685188 58.202356 21.628338 27297.753 -9577.7848 192 177 - 900 1573.4747 -84.225488 548.90935 -1356.7479 555.16208 21.69634 58.150052 21.651847 27316.908 -9567.7039 216 196 - 1000 1609.2136 1215.0833 764.08936 3301.0811 -419.92053 21.683731 58.000401 21.68726 27275.31 -9578.2843 240 219 -Loop time of 31.6263 on 1 procs for 1000 steps with 2304 atoms - -Performance: 5.464 ns/day, 4.393 hours/ns, 31.619 timesteps/s, 72.851 katom-step/s -99.2% CPU use with 1 MPI tasks x 1 OpenMP threads - -MPI task timing breakdown: -Section | min time | avg time | max time |%varavg| %total ---------------------------------------------------------------- -Pair | 28.487 | 28.487 | 28.487 | 0.0 | 90.07 -Neigh | 0.22789 | 0.22789 | 0.22789 | 0.0 | 0.72 -Comm | 0.010808 | 0.010808 | 0.010808 | 0.0 | 0.03 -Output | 0.00033526 | 0.00033526 | 0.00033526 | 0.0 | 0.00 -Modify | 2.8963 | 2.8963 | 2.8963 | 0.0 | 9.16 -Other | | 0.003905 | | | 0.01 - -Nlocal: 2304 ave 2304 max 2304 min -Histogram: 1 0 0 0 0 0 0 0 0 0 -Nghost: 4750 ave 4750 max 4750 min -Histogram: 1 0 0 0 0 0 0 0 0 0 -Neighs: 130023 ave 130023 max 130023 min -Histogram: 1 0 0 0 0 0 0 0 0 0 -FullNghs: 260046 ave 260046 max 260046 min -Histogram: 1 0 0 0 0 0 0 0 0 0 - -Total # of neighbors = 260046 -Ave neighs/atom = 112.86719 -Neighbor list builds = 65 -Dangerous builds = 0 - -#write_data pulse_center.data -Total wall time: 0:00:31 diff --git a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.4 b/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.4 deleted file mode 100644 index 54c372d0f7..0000000000 --- a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_center.g++.4 +++ /dev/null @@ -1,154 +0,0 @@ -LAMMPS (2 Apr 2025 - Development - patch_2Apr2025-384-g88bc7dc720-modified) - using 1 OpenMP thread(s) per MPI task -# May 2025 -# Test script for MD-KMC accelerated diffusion testing in LAMMPS -# Created by Jacob Tavenner, Baylor University - -# Initiation ------------------------------------- -units metal -dimension 3 -boundary p p p -atom_style atomic - -# Atom Definition -------------------------------- -lattice fcc 3.762 -Lattice spacing in x,y,z = 3.762 3.762 3.762 -region whole block 0 1 0 1 0 1 -create_box 2 whole -Created orthogonal box = (0 0 0) to (3.762 3.762 3.762) - 1 by 2 by 2 MPI processor grid -create_atoms 1 region whole -Created 4 atoms - using lattice units in orthogonal box = (0 0 0) to (3.762 3.762 3.762) - create_atoms CPU = 0.000 seconds - -replicate 6 16 6 -Replication is creating a 6x16x6 = 576 times larger system... - orthogonal box = (0 0 0) to (22.572 60.192 22.572) - 1 by 4 by 1 MPI processor grid - 2304 atoms - replicate CPU = 0.000 seconds - -region puck block INF INF 7 9 INF INF -set region puck type 2 -Setting atom values ... - 360 settings made for type - -# Force Fields ----------------------------------- -pair_style meam -pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr -Reading MEAM library file library_2nn.meam with DATE: 2024-08-08 -Reading MEAM potential file MoCoNiVFeAlCr_2nn.meam with DATE: 2024-08-08 - -# Settings --------------------------------------- -timestep 0.002 -thermo 100 - -# Computations ----------------------------------- -compute voroN all voronoi/atom neighbors yes - -run 0 -WARNING: No fixes with time integration, atoms won't move -For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60) -Neighbor list info ... - update: every = 1 steps, delay = 0 steps, check = yes - max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 6.8 - ghost atom cutoff = 6.8 - binsize = 3.4, bins = 7 18 7 - 2 neighbor lists, perpetual/occasional/extra = 2 0 0 - (1) pair meam, perpetual - attributes: full, newton on - pair build: full/bin/atomonly - stencil: full/bin/3d - bin: standard - (2) pair meam, perpetual, half/full from (1) - attributes: half, newton on - pair build: halffull/newton - stencil: none - bin: none -Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes - Step Temp E_pair E_mol TotEng Press - 0 0 -9674.3728 0 -9674.3728 -212400.94 -Loop time of 1.422e-06 on 4 procs for 0 steps with 2304 atoms - -35.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 | 0 | 0 | 0.0 | 0.00 -Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 0 | 0 | 0 | 0.0 | 0.00 -Output | 0 | 0 | 0 | 0.0 | 0.00 -Modify | 0 | 0 | 0 | 0.0 | 0.00 -Other | | 1.422e-06 | | |100.00 - -Nlocal: 576 ave 576 max 576 min -Histogram: 4 0 0 0 0 0 0 0 0 0 -Nghost: 2131 ave 2131 max 2131 min -Histogram: 4 0 0 0 0 0 0 0 0 0 -Neighs: 24768 ave 24768 max 24768 min -Histogram: 4 0 0 0 0 0 0 0 0 0 -FullNghs: 49536 ave 49536 max 49536 min -Histogram: 4 0 0 0 0 0 0 0 0 0 - -Total # of neighbors = 198144 -Ave neighs/atom = 86 -Neighbor list builds = 0 -Dangerous builds = 0 -thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe - -# Execution -------------------------------------- - -velocity all create 2400 908124 -fix temp all npt temp 1000 1000 1000 aniso 0 0 1 -fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 -thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] -#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym - -run 1000 -Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes - Step Temp Press Pxx Pyy Pzz Lx Ly Lz Volume PotEng f_mc[1] f_mc[2] - 0 2400 -187517.52 -187403.09 -187750.05 -187399.42 22.572 60.192 22.572 30667.534 -9674.3728 0 0 - 100 1668.8754 13300.763 12419.304 15568.772 11914.212 21.636248 57.724775 21.647685 27036.823 -9594.7526 24 23 - 200 1584.9699 -5686.0414 -4741.8496 -5914.7681 -6401.5064 21.729384 58.060532 21.730736 27415.923 -9571.0639 48 46 - 300 1582.0473 2806.2983 3413.4122 2716.0124 2289.4702 21.6679 58.033587 21.694744 27280.402 -9570.5549 72 69 - 400 1582.5825 845.29268 -849.61221 2123.5339 1261.9563 21.676298 58.14253 21.656418 27293.905 -9570.7948 96 93 - 500 1591.7285 -501.17955 1151.9743 -1719.3712 -936.14174 21.696367 58.157211 21.648308 27315.839 -9573.5089 120 116 - 600 1610.708 -821.74669 -1002.4957 291.88502 -1754.6294 21.730338 58.008213 21.661226 27304.8 -9579.5573 144 138 - 700 1598.5176 -590.00633 -1844.42 408.97706 -334.57602 21.712908 57.96131 21.698129 27307.281 -9575.8973 168 162 - 800 1584.3478 330.16711 666.88818 74.698331 248.91482 21.650908 58.045055 21.719838 27295.933 -9571.9268 192 186 - 900 1557.9946 1471.1207 2124.6512 1526.9937 761.71731 21.645578 58.156083 21.681637 27293.323 -9564.4385 216 207 - 1000 1582.5312 379.57005 -602.96446 2696.737 -955.06238 21.655418 58.231248 21.649581 27300.598 -9571.9879 240 227 -Loop time of 9.1632 on 4 procs for 1000 steps with 2304 atoms - -Performance: 18.858 ns/day, 1.273 hours/ns, 109.132 timesteps/s, 251.440 katom-step/s -98.5% CPU use with 4 MPI tasks x 1 OpenMP threads - -MPI task timing breakdown: -Section | min time | avg time | max time |%varavg| %total ---------------------------------------------------------------- -Pair | 7.867 | 7.9923 | 8.1311 | 4.3 | 87.22 -Neigh | 0.054997 | 0.057518 | 0.060145 | 1.0 | 0.63 -Comm | 0.017529 | 0.14801 | 0.27408 | 29.5 | 1.62 -Output | 0.00015963 | 0.00017216 | 0.00020869 | 0.0 | 0.00 -Modify | 0.95227 | 0.96325 | 0.9917 | 1.7 | 10.51 -Other | | 0.001983 | | | 0.02 - -Nlocal: 576 ave 609 max 540 min -Histogram: 2 0 0 0 0 0 0 0 0 2 -Nghost: 2161.5 ave 2173 max 2151 min -Histogram: 1 0 1 0 0 0 1 0 0 1 -Neighs: 32450.2 ave 35422 max 29271 min -Histogram: 2 0 0 0 0 0 0 0 0 2 -FullNghs: 64900.5 ave 70800 max 58684 min -Histogram: 2 0 0 0 0 0 0 0 0 2 - -Total # of neighbors = 259602 -Ave neighs/atom = 112.67448 -Neighbor list builds = 62 -Dangerous builds = 0 - -#write_data pulse_center.data -Total wall time: 0:00:09 diff --git a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.4 b/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.4 deleted file mode 100644 index da7976d867..0000000000 --- a/examples/PACKAGES/neighbor-swap/log.22May22.KMC_pulse_edge.g++.4 +++ /dev/null @@ -1,155 +0,0 @@ -LAMMPS (2 Apr 2025 - Development - patch_2Apr2025-384-g88bc7dc720-modified) - using 1 OpenMP thread(s) per MPI task -# May 2025 -# Test script for MD-KMC accelerated diffusion testing in LAMMPS -# Created by Jacob Tavenner, Baylor University - -# Initiation ------------------------------------- -units metal -dimension 3 -boundary p p p -atom_style atomic - - -# Atom Definition -------------------------------- -lattice fcc 3.762 -Lattice spacing in x,y,z = 3.762 3.762 3.762 -region whole block 0 1 0 1 0 1 -create_box 2 whole -Created orthogonal box = (0 0 0) to (3.762 3.762 3.762) - 1 by 2 by 2 MPI processor grid -create_atoms 1 region whole -Created 4 atoms - using lattice units in orthogonal box = (0 0 0) to (3.762 3.762 3.762) - create_atoms CPU = 0.000 seconds - -replicate 6 16 6 -Replication is creating a 6x16x6 = 576 times larger system... - orthogonal box = (0 0 0) to (22.572 60.192 22.572) - 1 by 4 by 1 MPI processor grid - 2304 atoms - replicate CPU = 0.000 seconds - -region puck block INF INF INF 2 INF INF -set region puck type 2 -Setting atom values ... - 360 settings made for type - -# Force Fields ----------------------------------- -pair_style meam -pair_coeff * * library_2nn.meam Mo Co Ni V Fe Al Cr MoCoNiVFeAlCr_2nn.meam Ni Cr -Reading MEAM library file library_2nn.meam with DATE: 2024-08-08 -Reading MEAM potential file MoCoNiVFeAlCr_2nn.meam with DATE: 2024-08-08 - -# Settings --------------------------------------- -timestep 0.002 -thermo 100 - -# Computations ----------------------------------- -compute voroN all voronoi/atom neighbors yes - -run 0 -WARNING: No fixes with time integration, atoms won't move -For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60) -Neighbor list info ... - update: every = 1 steps, delay = 0 steps, check = yes - max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 6.8 - ghost atom cutoff = 6.8 - binsize = 3.4, bins = 7 18 7 - 2 neighbor lists, perpetual/occasional/extra = 2 0 0 - (1) pair meam, perpetual - attributes: full, newton on - pair build: full/bin/atomonly - stencil: full/bin/3d - bin: standard - (2) pair meam, perpetual, half/full from (1) - attributes: half, newton on - pair build: halffull/newton - stencil: none - bin: none -Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes - Step Temp E_pair E_mol TotEng Press - 0 0 -9674.3728 0 -9674.3728 -212400.94 -Loop time of 1.53e-06 on 4 procs for 0 steps with 2304 atoms - -65.4% 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 | 0 | 0 | 0.0 | 0.00 -Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 0 | 0 | 0 | 0.0 | 0.00 -Output | 0 | 0 | 0 | 0.0 | 0.00 -Modify | 0 | 0 | 0 | 0.0 | 0.00 -Other | | 1.53e-06 | | |100.00 - -Nlocal: 576 ave 576 max 576 min -Histogram: 4 0 0 0 0 0 0 0 0 0 -Nghost: 2131 ave 2131 max 2131 min -Histogram: 4 0 0 0 0 0 0 0 0 0 -Neighs: 24768 ave 24768 max 24768 min -Histogram: 4 0 0 0 0 0 0 0 0 0 -FullNghs: 49536 ave 49536 max 49536 min -Histogram: 4 0 0 0 0 0 0 0 0 0 - -Total # of neighbors = 198144 -Ave neighs/atom = 86 -Neighbor list builds = 0 -Dangerous builds = 0 -thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe - -# Execution -------------------------------------- - -velocity all create 2400 908124 loop geom -fix temp all npt temp 1000 1000 1000 aniso 0 0 1 -fix mc all neighbor/swap 50 12 1340723 1000 3 voroN diff 2 -thermo_style custom step temp press pxx pyy pzz lx ly lz vol pe f_mc[*] -#dump dump2 all custom 5000 dump.edge-3_Ni-Cr.* id type x y z c_eng c_csym - -run 1000 -Per MPI rank memory allocation (min/avg/max) = 9.636 | 9.636 | 9.636 Mbytes - Step Temp Press Pxx Pyy Pzz Lx Ly Lz Volume PotEng f_mc[1] f_mc[2] - 0 2400 -187517.52 -187464.47 -188202.62 -186885.48 22.572 60.192 22.572 30667.534 -9674.3728 0 0 - 100 1665.569 14271.813 14638.855 14316.569 13860.016 21.63675 57.721065 21.637799 27023.366 -9594.291 24 24 - 200 1598.6479 -6990.8349 -8574.1986 -5033.6147 -7364.6916 21.708963 58.123129 21.724821 27412.223 -9575.7322 48 47 - 300 1604.388 456.43285 1926.408 -1214.1721 657.0626 21.673369 58.090421 21.671716 27285.018 -9577.698 72 70 - 400 1601.1591 1303.6721 703.88473 1137.6607 2069.471 21.684004 58.049595 21.671161 27278.522 -9576.4811 96 94 - 500 1623.6044 -2243.2478 -2084.532 320.87709 -4966.0885 21.686171 58.097101 21.695911 27334.758 -9583.1878 120 118 - 600 1587.2041 421.60034 190.88741 -328.76599 1402.6796 21.712439 58.086039 21.655927 27312.229 -9572.559 144 141 - 700 1591.2923 32.327829 -2893.2353 1839.7574 1150.4614 21.719102 57.999862 21.666164 27292.974 -9573.9009 168 165 - 800 1580.8587 -105.51079 654.26389 -160.04168 -810.75457 21.670225 58.109245 21.684683 27306.229 -9570.6482 192 186 - 900 1570.7648 1290.088 1252.3689 255.62548 2362.2695 21.68101 58.100507 21.658755 27283.051 -9567.9864 216 209 - 1000 1598.1483 -125.35291 -3626.5479 3404.789 -154.29983 21.720146 57.952942 21.686111 27297.313 -9576.2975 240 231 -Loop time of 9.17241 on 4 procs for 1000 steps with 2304 atoms - -Performance: 18.839 ns/day, 1.274 hours/ns, 109.023 timesteps/s, 251.188 katom-step/s -98.1% CPU use with 4 MPI tasks x 1 OpenMP threads - -MPI task timing breakdown: -Section | min time | avg time | max time |%varavg| %total ---------------------------------------------------------------- -Pair | 7.7477 | 8.0143 | 8.1344 | 5.5 | 87.37 -Neigh | 0.050543 | 0.056882 | 0.05986 | 1.6 | 0.62 -Comm | 0.069784 | 0.16898 | 0.40996 | 34.2 | 1.84 -Output | 0.00015612 | 0.0001707 | 0.00021249 | 0.0 | 0.00 -Modify | 0.90628 | 0.93003 | 0.96157 | 2.2 | 10.14 -Other | | 0.002053 | | | 0.02 - -Nlocal: 576 ave 614 max 505 min -Histogram: 1 0 0 0 0 0 1 0 0 2 -Nghost: 2165.75 ave 2204 max 2132 min -Histogram: 1 0 0 0 2 0 0 0 0 1 -Neighs: 32430.8 ave 35552 max 26564 min -Histogram: 1 0 0 0 0 0 1 0 0 2 -FullNghs: 64861.5 ave 71111 max 53164 min -Histogram: 1 0 0 0 0 0 1 0 0 2 - -Total # of neighbors = 259446 -Ave neighs/atom = 112.60677 -Neighbor list builds = 62 -Dangerous builds = 0 - -#write_data pulse_end.data -Total wall time: 0:00:09 From bc3c85b6a4145b2ae55ea98b79aeaed6e26db7c8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Jul 2025 06:20:57 -0400 Subject: [PATCH 27/37] re-add fix neighbor/swap doc page --- doc/src/fix_neighbor_swap.rst | 264 ++++++++++++++++++++++++++++++++++ 1 file changed, 264 insertions(+) create mode 100644 doc/src/fix_neighbor_swap.rst diff --git a/doc/src/fix_neighbor_swap.rst b/doc/src/fix_neighbor_swap.rst new file mode 100644 index 0000000000..dffbc93217 --- /dev/null +++ b/doc/src/fix_neighbor_swap.rst @@ -0,0 +1,264 @@ +.. index:: fix neighbor/swap + +fix neighbor/swap command +========================= + +Syntax +"""""" + +.. code-block:: LAMMPS + + fix ID group-ID neighbor/swap N X seed T R0 voro-ID keyword values ... + +* ID, group-ID are documented in :doc:`fix ` command +* neighbor/swap = style name of this fix command +* N = invoke this fix every N steps +* X = number of swaps to attempt every N steps +* seed = random # seed (positive integer) +* T = scaling temperature of the MC swaps (temperature units) +* R0 = scaling swap probability of the MC swaps (distance units) +* voro-ID = valid voronoi compute id (compute voronoi/atom) +* one or more keyword/value pairs may be appended to args +* keywords *types* and *diff* are mutually exclusive, but one must be specified +* keyword = *types* or *diff* or *ke* or *region* or *rates* + + .. parsed-literal:: + + *types* values = two or more atom types (Integers in range [1,Ntypes] or type labels) + *diff* values = one atom type + *ke* value = *yes* or *no* + *yes* = kinetic energy is conserved after atom swaps + *no* = no conservation of kinetic energy after atom swaps + *region* value = region-ID + region-ID = ID of region to use as an exchange/move volume + *rates* values = V1 V2 . . . Vntypes values to conduct variable diffusion for different atom types (unitless) + +Examples +"""""""" + +.. code-block:: LAMMPS + + compute voroN all voronoi/atom neighbors yes + fix mc all neighbor/swap 10 160 15238 1000.0 3.0 voroN diff 2 + fix myFix all neighbor/swap 100 1 12345 298.0 3.0 voroN region my_swap_region types 5 6 + fix kmc all neighbor/swap 1 100 345 1.0 3.0 voroN diff 3 rates 3 1 6 + +Description +""""""""""" + +.. versionadded:: TBD + +This fix performs Monte-Carlo (MC) evaluations to enable kinetic +Monte Carlo (kMC)-type behavior during MD simulation by allowing +neighboring atoms to swap their positions. In contrast to the :doc:`fix +atom/swap ` command which swaps pairs of atoms anywhere +in the simulation domain, the restriction of the MC swapping to +neighbors enables a hybrid MD/kMC-like simulation. + +Neighboring atoms are defined by using a Voronoi tesselation performed +by the :doc:`compute voronoi/atom ` command. +Two atoms are neighbors if their Voronoi cells share a common face +(3d) or edge (2d). + +The selection of a swap neighbor is made using a distance-based +criterion for weighting the selection probability of each swap, in the +same manner as kMC selects a next event using relative probabilities. +The acceptance or rejection of each swap is determined via the +Metropolis criterion after evaluating the change in system energy due +to the swap. + +A detailed explanation of the original implementation of this +algorithm can be found in :ref:`(Tavenner 2023) ` +where it was used to simulated accelerated diffusion in an MD context. + +Simulating inherently kinetically-limited behaviors which rely on rare +events (such as atomic diffusion in a solid) is challenging for +traditional MD since its relatively short timescale will not naturally +sample many events. This fix addresses this challenge by allowing rare +neighbor hopping events to be sampled in a kMC-like fashion at a much +faster rate (set by the specified *N* and *X* parameters). This enables +the processes of atomic diffusion to be approximated during an MD +simulation, effectively decoupling the MD atomic vibrational timescale +and the atomic hopping (kMC event) timescale. + +The algorithm implemented by this fix is as follows: + + - The MD simulation is paused every *N* steps + - A Voronoi tesselation is performed for the current atom configuration. + - Then *X* atom swaps are attempted, one after the other. + - For each swap, an atom *I* is selected randomly from the list of + atom types specified by either the *types* or *diff* keywords. + - One of *I*'s Voronoi neighbors *J* is selected using the + distance-weighted probability for each neighbor detailed below. + - The *I,J* atom IDs are communicated to all processors so that a + global energy evaluation can be performed for the post-swap state + of the system. + - The swap is accepted or rejected based on the Metropolis criterion + using the energy change of the system and the specified temperature + *T*. + +Here are a few comments on the computational cost of the swapping +algorithm. + + 1. The cost of a global energy evaluation is similar to that of an MD + timestep. + + 2. Similar to other MC algorithms in LAMMPS, improved parallel + efficiency is achieved with a smaller number of atoms per + processor than would typically be used in an standard MD + simulation. This is because the per-energy evaluation cost + increases relative to the balance of MD/MC steps as indicated by + 1., but the communication cost remains relatively constant for a + given number of MD steps. + + 3. The MC portion of the simulation will run dramatically slower if + the pair style uses different cutoffs for different atom types (or + type pairs). This is because each atom swap then requires a + rebuild of the neighbor list to ensure the post-swap global energy + can be computed correctly. + +Limitations are imposed on selection of *I,J* atom pairs to avoid +swapping of atoms which are outside of a reasonable cutoff (e.g. due to +a Voronoi tesselation near free surfaces) though the use of a +distance-weighted probability scaling. + +---------- + +This section gives more details on other arguments and keywords. + +The random number generator (RNG) used by all the processors for MC +operations is initialized with the specified *seed*. + +The distance-based probability is weighted by the specified *R0* which +sets the radius :math:`r_0` in this formula + +.. math:: + + p_{ij} = e^{(\frac{r_{ij}}{r_0})^2} + +where :math:`p_{ij}` is the probability of selecting atom :math:`j` to +swap with atom :math:`i`. Typically, a value for *R0* around the +average nearest-neighbor spacing is appropriate. Since this is simply a +probability weighting, the swapping behavior is not very sensitive to +the exact value of *R0*. + +The required *voro-ID* value is the compute-ID of a +:doc:`compute voronoi/atom ` command like +this: + +.. code-block:: LAMMPS + + compute compute-ID group-ID voronoi/atom neighbors yes + +It must return per-atom list of valid neighbor IDs as in the +:doc:`compute voronoi/atom ` command. + +The keyword *types* takes two or more atom types as its values. Only +atoms *I* of the first atom type will be selected. Only atoms *J* of the +remaining atom types will be considered as potential swap partners. + +The keyword *diff* take a single atom type as its value. Only atoms +*I* of the that atom type will be selected. Atoms *J* of all +remaining atom types will be considered as potential swap partners. +This includes the atom type specified with the *diff* keyword to +account for self-diffusive hops between two atoms of the same type. + +Note that the *neighbors yes* option must be enabled for use with this +fix. The group-ID should include all the atoms which this fix will +potentially select. I.e. the group-ID used in the voronoi compute should +include the same atoms as that indicated by the *types* keyword. If the +*diff* keyword is used, the group-ID should include atoms of all types +in the simulation. + +The keyword *ke* takes *yes* (default) or *no* as its value. It two +atoms are swapped with different masses, then a value of *yes* will +rescale their respective velocities to conserve the kinetic energy of +the system. A value of *no* will perform no rescaling, so that +kinetic energy is not conserved. See the restriction on this keyword +below. + +The *region* keyword takes a *region-ID* as its value. If specified, +then only atoms *I* and *J* within the geometric region will be +considered as swap partners. See the :doc:`region ` command +for details. This means the group-ID for the :doc:`compute +voronoi/atom ` command also need only contain +atoms within the region. + +The keyword *rates* can modify the swap rate based on the type of atom +*J*. Ntype values must be specified, where Ntype = the number of atom +types in the system. Each value is used to scale the probability +weighting given by the equation above. In the third example command +above, a simulation has 3 atoms types. Atom *I*s of type 1 are +eligible for swapping. Swaps may occur with atom *J*s of all 3 types. +Assuming all *J* atoms are equidistant from an atom *I*, *J* atoms of +type 1 will be 3x more likely to be selected as a swap partner than +atoms of type 2. And *J* atoms of type 3 will be 6.5x more likely to +be selected than atoms of type 2. If the *rates* keyword is not used, +all atom types will be treated with the same probability during selection +of swap attempts. + + +Restart, fix_modify, output, run start/stop, minimize info +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +This fix writes the state of the fix to :doc:`binary restart files +`. This includes information about the random number generator +seed, the next timestep for MC exchanges, and the number of exchange +attempts and successes. See the :doc:`read_restart ` +command for info on how to re-specify a fix in an input script that +reads a restart file, so that the operation of the fix continues in an +uninterrupted fashion. + +None of the :doc:`fix_modify ` options are relevant to this +fix. + +This fix computes a global vector of length 2, which can be accessed +by various :doc:`output commands `. The vector values are +the following global cumulative quantities: + + #. swap attempts + #. swap accepts + +The vector values calculated by this fix are "intensive". + +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 +"""""""""""" + +This fix is part of the MC package. It is only enabled if LAMMPS was +built with that package. See the :doc:`Build package ` +doc page for more info. Also this fix requires that the :ref:`VORONOI +package ` is installed, otherwise the fix will not be +compiled. + +The :doc:`compute voronoi/atom ` command +referenced by the required voro-ID must return neighboring atoms as +illustrated in the examples above. + +If this fix is used with systems that do not have per-type masses +(e.g. atom style sphere), the *ke* keyword must be set to *off* since +the implemented algorithm will not be able to re-scale velocities +properly. + +Related commands +"""""""""""""""" + +:doc:`fix nvt `, :doc:`compute voronoi/atom ` +:doc:`delete_atoms `, :doc:`fix gcmc `, +:doc:`fix atom/swap `, :doc:`fix mol/swap `, +:doc:`fix sgcmc ` + +Default +""""""" + +The option defaults are *ke* = yes and *rates* = 1 for all atom types. + +---------- + +.. _TavennerMDkMC: + +**(Tavenner 2023)** J Tavenner, M Mendelev, J Lawson, Computational + Materials Science, 218, 111929 (2023). From 491f5d96b8c9a6d3cef824531726c89d0d7fcbfd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Jul 2025 06:33:46 -0400 Subject: [PATCH 28/37] id_center should be of type tagint --- src/MC/fix_neighbor_swap.cpp | 2 +- src/MC/fix_neighbor_swap.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index e9b22f5f4e..55e07c3082 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -566,7 +566,7 @@ int FixNeighborSwap::pick_i_swap_atom() MPI_Allreduce(MPI_IN_PLACE, &root_rank, 1, MPI_INT, MPI_MAX, world); - MPI_Bcast(&id_center, 1, MPI_INT, root_rank, world); + MPI_Bcast(&id_center, 1, MPI_LMP_TAGINT, root_rank, world); return i; } diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index f72f676291..77260a9ad4 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -53,7 +53,7 @@ class FixNeighborSwap : public Fix { int nswaptypes; int jtype_selected; - int id_center; + tagint id_center; double x_center; double y_center; double z_center; From 1ff281dd3ccd0efb54c922ad56d35a545092e1d2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Jul 2025 06:34:47 -0400 Subject: [PATCH 29/37] make sure i is initialized, use comm->me instead of calling MPI_Comm_rank() --- src/MC/fix_neighbor_swap.cpp | 9 ++++----- src/MC/fix_neighbor_swap.h | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 55e07c3082..88fc26bc57 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -550,18 +550,17 @@ double FixNeighborSwap::energy_full() int FixNeighborSwap::pick_i_swap_atom() { tagint *id = atom->tag; - int i, root_rank = -1; - int rank; - MPI_Comm_rank(world, &rank); + int i = -1; + int root_rank = -1; int iwhichglobal = static_cast(niswap * random_equal->uniform()); if ((iwhichglobal >= niswap_before) && (iwhichglobal < niswap_before + niswap_local)) { int iwhichlocal = iwhichglobal - niswap_before; - i = local_swap_iatom_list[iwhichlocal]; + int i = local_swap_iatom_list[iwhichlocal]; id_center = id[i]; - root_rank = rank; + root_rank = comm->me; } MPI_Allreduce(MPI_IN_PLACE, &root_rank, 1, MPI_INT, MPI_MAX, world); diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index 77260a9ad4..deb8e42229 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -88,7 +88,6 @@ class FixNeighborSwap : public Fix { int attempt_swap(); double energy_full(); int pick_i_swap_atom(); - // TODO: parameter not used int pick_j_swap_neighbor(); void build_i_neighbor_list(int); void update_iswap_atoms_list(); From 3efdf228500d3346df9cd24e97732367f7464c75 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Jul 2025 06:35:53 -0400 Subject: [PATCH 30/37] use memory->create() and memory->destroy() consistently memory->smalloc() and memory->sfree() are not type-safe --- src/MC/fix_neighbor_swap.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 88fc26bc57..82d1d07cd7 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -615,18 +615,15 @@ void FixNeighborSwap::build_i_neighbor_list(int i_center) // Allocate local_swap_neighbor_list size - memory->sfree(local_swap_neighbor_list); + memory->destroy(local_swap_neighbor_list); atom_swap_nmax = atom->nmax; - local_swap_neighbor_list = - (int *) memory->smalloc(atom_swap_nmax * sizeof(int), "MCSWAP:local_swap_neighbor_list"); + memory->create(local_swap_neighbor_list, atom_swap_nmax, "MCSWAP:local_swap_neighbor_list"); - memory->sfree(local_swap_probability); - local_swap_probability = (double *) memory->smalloc(atom_swap_nmax * sizeof(double), - "MCSWAP:local_swap_probability_list"); + memory->destroy(local_swap_probability); + memory->create(local_swap_probability, atom_swap_nmax, "MCSWAP:local_swap_probability_list"); - memory->sfree(local_swap_type_list); - local_swap_type_list = - (int *) memory->smalloc(atom_swap_nmax * sizeof(int), "MCSWAP:local_swap_type_list"); + memory->destroy(local_swap_type_list); + memory->create(local_swap_type_list, atom_swap_nmax, "MCSWAP:local_swap_type_list"); // Compute voronoi and access neighbor list @@ -796,10 +793,9 @@ void FixNeighborSwap::update_iswap_atoms_list() double **x = atom->x; if (atom->nmax > atom_swap_nmax) { - memory->sfree(local_swap_iatom_list); + memory->destroy(local_swap_iatom_list); atom_swap_nmax = atom->nmax; - local_swap_iatom_list = - (int *) memory->smalloc(atom_swap_nmax * sizeof(int), "MCSWAP:local_swap_iatom_list"); + memory->create(local_swap_iatom_list, atom_swap_nmax, "MCSWAP:local_swap_iatom_list"); } niswap_local = 0; From 1b3ebcc8579bff727035fe774877ebe2ad6d5bf4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Jul 2025 06:44:55 -0400 Subject: [PATCH 31/37] account for all large memory allocations --- src/MC/fix_neighbor_swap.cpp | 10 +++++++--- src/MC/fix_neighbor_swap.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 82d1d07cd7..0b1ea4db61 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -442,9 +442,11 @@ int FixNeighborSwap::attempt_swap() // error out when pick_i_swap_atom() or pick_j_swap_neighbor() picked invalid indices if (i >= atom->nlocal) - error->one(FLERR, Error::NOLASTLINE, "Invalid i index {} chosen for swap. nlocal = {}", i, atom->nlocal); + error->one(FLERR, Error::NOLASTLINE, "Invalid i index {} chosen for swap. nlocal = {}", i, + atom->nlocal); if (j >= (atom->nlocal + atom->nghost)) - error->one(FLERR, Error::NOLASTLINE, "Invalid j index {} chosen for swap. nall = {}", j, atom->nlocal+atom->nghost); + error->one(FLERR, Error::NOLASTLINE, "Invalid j index {} chosen for swap. nall = {}", j, + atom->nlocal + atom->nghost); // swap their properties if (i >= 0) { @@ -896,7 +898,9 @@ double FixNeighborSwap::compute_vector(int n) double FixNeighborSwap::memory_usage() { - double bytes = (double) atom_swap_nmax * sizeof(int); + double bytes = (double) atom_swap_nmax * sizeof(int) * 3; // local_swap_*list + bytes += (double) atom_swap_nmax * sizeof(double); // local_swap_probability_list + bytes += (double) nswaptypes * sizeof(double); // qtype return bytes; } diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index deb8e42229..e3911ab1fe 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -42,7 +42,7 @@ class FixNeighborSwap : public Fix { int nevery, seed; int ke_flag; // yes = conserve ke, no = do not conserve ke int diff_flag; // yes = simulate diffusion of central atom, no = swap only to certain types - int rates_flag; // yes = use modified type rates, no = swap rates are equivilent across types + int rates_flag; // yes = use modified type rates, no = swap rates are equivalent across types int ncycles; int niswap, njswap; // # of i,j swap atoms on all procs int niswap_local, njswap_local; // # of swap atoms on this proc From 6d335fb5a6e4ee757633398e2bb89489cd68168c Mon Sep 17 00:00:00 2001 From: Jacob Tavenner Date: Fri, 11 Jul 2025 10:26:36 -0600 Subject: [PATCH 32/37] Fixed assignment of local i in pick_i_swap_atom. i, j should both be owned not ghost atoms on swapping procs --- src/MC/fix_neighbor_swap.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 0b1ea4db61..ef2a798ec5 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -415,6 +415,7 @@ void FixNeighborSwap::pre_exchange() int FixNeighborSwap::attempt_swap() { + tagint *id = atom->tag; if (niswap == 0) return 0; // pre-swap energy @@ -444,9 +445,9 @@ int FixNeighborSwap::attempt_swap() if (i >= atom->nlocal) error->one(FLERR, Error::NOLASTLINE, "Invalid i index {} chosen for swap. nlocal = {}", i, atom->nlocal); - if (j >= (atom->nlocal + atom->nghost)) + if (j >= (atom->nlocal)) error->one(FLERR, Error::NOLASTLINE, "Invalid j index {} chosen for swap. nall = {}", j, - atom->nlocal + atom->nghost); + atom->nlocal); // swap their properties if (i >= 0) { @@ -502,7 +503,7 @@ int FixNeighborSwap::attempt_swap() // swap not accepted, return 0 // restore the swapped itype & jtype atoms // do not need to re-call comm->borders() and rebuild neighbor list - // since will be done on next cycle or in Verlet when this fix finishes + // since will be done on next cycle or in Verlet when this fix finishes if (i >= 0) { atom->type[i] = itype; @@ -560,7 +561,7 @@ int FixNeighborSwap::pick_i_swap_atom() int iwhichlocal = iwhichglobal - niswap_before; - int i = local_swap_iatom_list[iwhichlocal]; + i = local_swap_iatom_list[iwhichlocal]; id_center = id[i]; root_rank = comm->me; } From 29dc28c6150849c0453cb94db3e280d88952448a Mon Sep 17 00:00:00 2001 From: Jacob Tavenner Date: Fri, 11 Jul 2025 10:44:19 -0600 Subject: [PATCH 33/37] Handle per-atom masses --- src/MC/fix_neighbor_swap.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index ef2a798ec5..21ab87a45a 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -332,11 +332,17 @@ void FixNeighborSwap::init() } } - memory->create(sqrt_mass_ratio, atom->ntypes + 1, atom->ntypes + 1, - "neighbor/swap:sqrt_mass_ratio"); - for (int itype = 1; itype <= atom->ntypes; itype++) - for (int jtype = 1; jtype <= atom->ntypes; jtype++) - sqrt_mass_ratio[itype][jtype] = sqrt(atom->mass[itype] / atom->mass[jtype]); + if (ke_flag) { + if (atom->rmass) { + error->all(FLERR, Error::NOLASTLINE, "Per-atom masses are not curently supported while ke = yes."); + } else { + memory->create(sqrt_mass_ratio, atom->ntypes + 1, atom->ntypes + 1, + "neighbor/swap:sqrt_mass_ratio"); + for (int itype = 1; itype <= atom->ntypes; itype++) + for (int jtype = 1; jtype <= atom->ntypes; jtype++) + sqrt_mass_ratio[itype][jtype] = sqrt(atom->mass[itype] / atom->mass[jtype]); + } + } // check to see if itype and jtype cutoffs are the same // if not, reneighboring will be needed between swaps From 6152906deb361253267bf35e8fd25739348d29cb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Jul 2025 13:01:08 -0400 Subject: [PATCH 34/37] Revert "Handle per-atom masses" This reverts commit 29dc28c6150849c0453cb94db3e280d88952448a. --- src/MC/fix_neighbor_swap.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index 21ab87a45a..ef2a798ec5 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -332,17 +332,11 @@ void FixNeighborSwap::init() } } - if (ke_flag) { - if (atom->rmass) { - error->all(FLERR, Error::NOLASTLINE, "Per-atom masses are not curently supported while ke = yes."); - } else { - memory->create(sqrt_mass_ratio, atom->ntypes + 1, atom->ntypes + 1, - "neighbor/swap:sqrt_mass_ratio"); - for (int itype = 1; itype <= atom->ntypes; itype++) - for (int jtype = 1; jtype <= atom->ntypes; jtype++) - sqrt_mass_ratio[itype][jtype] = sqrt(atom->mass[itype] / atom->mass[jtype]); - } - } + memory->create(sqrt_mass_ratio, atom->ntypes + 1, atom->ntypes + 1, + "neighbor/swap:sqrt_mass_ratio"); + for (int itype = 1; itype <= atom->ntypes; itype++) + for (int jtype = 1; jtype <= atom->ntypes; jtype++) + sqrt_mass_ratio[itype][jtype] = sqrt(atom->mass[itype] / atom->mass[jtype]); // check to see if itype and jtype cutoffs are the same // if not, reneighboring will be needed between swaps From 363ad5438387547e7abe8b7fae8ad5d07a6dc716 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Jul 2025 18:45:53 -0400 Subject: [PATCH 35/37] make fix neighbor/swap compatible with per-atom masses --- src/MC/fix_neighbor_swap.cpp | 72 ++++++++++++++++++++++++++++++++---- src/MC/fix_neighbor_swap.h | 2 +- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/MC/fix_neighbor_swap.cpp b/src/MC/fix_neighbor_swap.cpp index ef2a798ec5..97ce359c27 100644 --- a/src/MC/fix_neighbor_swap.cpp +++ b/src/MC/fix_neighbor_swap.cpp @@ -69,7 +69,7 @@ static const char cite_fix_neighbor_swap[] = FixNeighborSwap::FixNeighborSwap(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), region(nullptr), idregion(nullptr), type_list(nullptr), rate_list(nullptr), - qtype(nullptr), sqrt_mass_ratio(nullptr), voro_neighbor_list(nullptr), + qtype(nullptr), mtype(nullptr), sqrt_mass_ratio(nullptr), voro_neighbor_list(nullptr), local_swap_iatom_list(nullptr), local_swap_neighbor_list(nullptr), local_swap_type_list(nullptr), local_swap_probability(nullptr), random_equal(nullptr), id_voro(nullptr), c_voro(nullptr), c_pe(nullptr) @@ -164,6 +164,7 @@ FixNeighborSwap::~FixNeighborSwap() memory->destroy(type_list); memory->destroy(rate_list); memory->destroy(qtype); + memory->destroy(mtype); memory->destroy(sqrt_mass_ratio); memory->destroy(local_swap_iatom_list); memory->destroy(local_swap_neighbor_list); @@ -329,14 +330,67 @@ void FixNeighborSwap::init() MPI_Allreduce(&qtype[iswaptype], &qmin, 1, MPI_DOUBLE, MPI_MIN, world); if (qmax != qmin) error->all(FLERR, Error::NOLASTLINE, "All atoms of a swapped type must have same charge."); + qtype[iswaptype] = qmax; } } - memory->create(sqrt_mass_ratio, atom->ntypes + 1, atom->ntypes + 1, - "neighbor/swap:sqrt_mass_ratio"); - for (int itype = 1; itype <= atom->ntypes; itype++) - for (int jtype = 1; jtype <= atom->ntypes; jtype++) - sqrt_mass_ratio[itype][jtype] = sqrt(atom->mass[itype] / atom->mass[jtype]); + // if we have per-atom masses, check that rmass is consistent with type, + // and set per-type mass to that value + if (ke_flag && (atom->rmass != nullptr)) { + double mmax, mmin; + int firstall, first; + memory->create(mtype, nswaptypes, "neighbor/swap:mtype"); + for (int iswaptype = 0; iswaptype < nswaptypes; iswaptype++) { + first = 1; + for (int i = 0; i < atom->nlocal; i++) { + if (atom->mask[i] & groupbit) { + if (type[i] == type_list[iswaptype]) { + if (first > 0) { + mtype[iswaptype] = atom->rmass[i]; + first = 0; + } else if (mtype[iswaptype] != atom->rmass[i]) + first = -1; + } + } + } + MPI_Allreduce(&first, &firstall, 1, MPI_INT, MPI_MIN, world); + if (firstall < 0) + error->all(FLERR, Error::NOLASTLINE, + "All atoms of a swapped type must have the same per-atom mass"); + if (firstall > 0) + error->all(FLERR, Error::NOLASTLINE, + "At least one atom of each swapped type must be present to define masses"); + if (first) mtype[iswaptype] = -DBL_MAX; + MPI_Allreduce(&mtype[iswaptype], &mmax, 1, MPI_DOUBLE, MPI_MAX, world); + if (first) mtype[iswaptype] = DBL_MAX; + MPI_Allreduce(&mtype[iswaptype], &mmin, 1, MPI_DOUBLE, MPI_MIN, world); + if (mmax != mmin) + error->all(FLERR, Error::NOLASTLINE, "All atoms of a swapped type must have same mass."); + mtype[iswaptype] = mmax; + } + } + + if (ke_flag) { + memory->create(sqrt_mass_ratio, atom->ntypes + 1, atom->ntypes + 1, + "neighbor/swap:sqrt_mass_ratio"); + if (atom->rmass != nullptr) { + for (int itype = 1; itype <= atom->ntypes; itype++) + for (int jtype = 1; jtype <= atom->ntypes; jtype++) sqrt_mass_ratio[itype][jtype] = 1.0; + for (int iswaptype = 0; iswaptype < nswaptypes; iswaptype++) { + int itype = type_list[iswaptype]; + for (int jswaptype = 0; jswaptype < nswaptypes; jswaptype++) { + int jtype = type_list[jswaptype]; + sqrt_mass_ratio[itype][jtype] = sqrt(mtype[iswaptype] / mtype[jswaptype]); + } + } + } else { + for (int itype = 1; itype <= atom->ntypes; itype++) { + for (int jtype = 1; jtype <= atom->ntypes; jtype++) { + sqrt_mass_ratio[itype][jtype] = sqrt(atom->mass[itype] / atom->mass[jtype]); + } + } + } + } // check to see if itype and jtype cutoffs are the same // if not, reneighboring will be needed between swaps @@ -453,10 +507,12 @@ int FixNeighborSwap::attempt_swap() if (i >= 0) { atom->type[i] = jtype; if (atom->q_flag) atom->q[i] = qtype[jtype_selected]; + if (atom->rmass_flag) atom->rmass[i] = mtype[jtype_selected]; } if (j >= 0) { atom->type[j] = itype; if (atom->q_flag) atom->q[j] = qtype[0]; + if (atom->rmass_flag) atom->rmass[j] = mtype[0]; } // if unequal_cutoffs, call comm->borders() and rebuild neighbor list @@ -480,7 +536,7 @@ int FixNeighborSwap::attempt_swap() double energy_after = energy_full(); // if swap accepted, return 1 - // if ke_flag, rescale atom velocities + // if ke_flag, rescale atom velocities first if (random_equal->uniform() < exp(beta * (energy_before - energy_after))) { update_iswap_atoms_list(); @@ -508,10 +564,12 @@ int FixNeighborSwap::attempt_swap() if (i >= 0) { atom->type[i] = itype; if (atom->q_flag) atom->q[i] = qtype[0]; + if (atom->rmass_flag) atom->rmass[i] = mtype[0]; } if (j >= 0) { atom->type[j] = jtype; if (atom->q_flag) atom->q[j] = qtype[jtype_selected]; + if (atom->rmass_flag) atom->rmass[j] = mtype[jtype_selected]; } return 0; diff --git a/src/MC/fix_neighbor_swap.h b/src/MC/fix_neighbor_swap.h index e3911ab1fe..e368d27759 100644 --- a/src/MC/fix_neighbor_swap.h +++ b/src/MC/fix_neighbor_swap.h @@ -70,7 +70,7 @@ class FixNeighborSwap : public Fix { double local_probability; // Total swap probability stored on this proc double global_probability; // Total swap probability across all proc double prev_probability; // Swap probability on proc < this proc - double *qtype; + double *qtype, *mtype; double energy_stored; double **sqrt_mass_ratio; double **voro_neighbor_list; From 411295439996fe61bf64ce2a9b3148948ce0aa28 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sun, 13 Jul 2025 21:33:37 +0200 Subject: [PATCH 36/37] Improve text and use consistent symbols for the local stress --- doc/src/compute_stress_mop.rst | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/doc/src/compute_stress_mop.rst b/doc/src/compute_stress_mop.rst index b4779b8bf3..8f1116301d 100644 --- a/doc/src/compute_stress_mop.rst +++ b/doc/src/compute_stress_mop.rst @@ -45,13 +45,13 @@ Examples Description """"""""""" -Compute *stress/mop* and compute *stress/mop/profile* define -computations that calculate components of the local stress tensor using -the method of planes :ref:`(Todd) `. Specifically in compute -*stress/mop* calculates 3 components are computed in directions *dir*,\ -*x*\ ; *dir*,\ *y*\ ; and *dir*,\ *z*\ ; where *dir* is the direction -normal to the plane, while in compute *stress/mop/profile* the profile -of the stress is computed. +Compute *stress/mop* and compute *stress/mop/profile* +calculate components of the local stress tensor using +the method of planes :ref:`(Todd) `. Specifically, compute +*stress/mop* calculates 3 components in directions :math:`ix`, +:math:`iy`, and :math:`iz` where :math:`i` is the direction +normal to the plane, while compute *stress/mop/profile* calculates the profile +of the local stress along the :math:`i` direction. Contrary to methods based on histograms of atomic stress (i.e., using :doc:`compute stress/atom `), the method of planes @@ -103,14 +103,15 @@ Output info Compute *stress/mop* calculates a global vector (indices starting at 1), with 3 values for each declared keyword (in the order the keywords have been declared). For each keyword, the stress tensor components are -ordered as follows: stress_dir,x, stress_dir,y, and stress_dir,z. +ordered as follows: :math:`P_{ix}`, :math:`P_{iy}`, and :math:`P_{iz}`, +where :math:`i` is the direction normal to the plane. Compute *stress/mop/profile* instead calculates a global array, with 1 column giving the position of the planes where the stress tensor was computed, and with 3 columns of values for each declared keyword (in the order the keywords have been declared). For each keyword, the profiles -of stress tensor components are ordered as follows: stress_dir,x; -stress_dir,y; and stress_dir,z. +of stress tensor components are ordered as follows: :math:`P_{ix}`, +:math:`P_{iy}`, and :math:`P_{iz}`. The values are in pressure :doc:`units `. @@ -128,13 +129,12 @@ package ` doc page on for more info. The method is implemented for orthogonal simulation boxes whose size does not change in time, and axis-aligned planes. - -The method only works with two-body pair interactions, because it -requires the class method ``Pair::single()`` to be implemented, which is -not possible for manybody potentials. In particular, compute -*stress/mop/profile* and *stress/mop* do not work with more than two-body -pair interactions, long range (kspace) interactions and -improper intramolecular interactions. + +Compute *stress/mop* and *stress/mop/profile* do not work with manybody +non-bonded interactions, long range (kspace) interactions and +improper intramolecular interactions. The reason is that the current +implementation requires the class method ``Pair::single()`` to be implemented, +which is not possible for manybody potentials. The impact of fixes that affect the stress (e.g. fix langevin) is also not included in the stress computed here. From 4ff44d2a2f94bc04ec8cb25784a2d8a700f3f2c7 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sun, 13 Jul 2025 21:38:39 +0200 Subject: [PATCH 37/37] remove whitespace --- doc/src/compute_stress_mop.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/compute_stress_mop.rst b/doc/src/compute_stress_mop.rst index 8f1116301d..01efe80af9 100644 --- a/doc/src/compute_stress_mop.rst +++ b/doc/src/compute_stress_mop.rst @@ -129,7 +129,7 @@ package ` doc page on for more info. The method is implemented for orthogonal simulation boxes whose size does not change in time, and axis-aligned planes. - + Compute *stress/mop* and *stress/mop/profile* do not work with manybody non-bonded interactions, long range (kspace) interactions and improper intramolecular interactions. The reason is that the current