From b8728884fc900dd43f6c565dbe686d5eb5a68d06 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Mon, 10 Oct 2022 10:33:47 -0600 Subject: [PATCH 001/185] Drafting stress controls in fix deform --- src/fix_deform.cpp | 505 ++++++++++++++++++++++++++++++++++++--------- src/fix_deform.h | 21 +- 2 files changed, 430 insertions(+), 96 deletions(-) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index bc6e61a69e..40221df839 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -16,6 +16,11 @@ Contributing author: Pieter in 't Veld (SNL) ------------------------------------------------------------------------- */ +// Save previous state to restart file for derivatives +// define hrate_lo/hi for volume +// add modify command +// add pressure code + #include "fix_deform.h" #include "atom.h" @@ -39,8 +44,9 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{NONE=0,FINAL,DELTA,SCALE,VEL,ERATE,TRATE,VOLUME,WIGGLE,VARIABLE}; +enum{NONE=0,FINAL,DELTA,SCALE,VEL,ERATE,TRATE,VOLUME,WIGGLE,VARIABLE,PRESSURE,PISOTROPIC}; enum{ONE_FROM_ONE,ONE_FROM_TWO,TWO_FROM_ONE}; +enum{NOCOUPLE=0,XYZ,XY,YZ,XZ}; /* ---------------------------------------------------------------------- */ @@ -52,6 +58,8 @@ irregular(nullptr), set(nullptr) no_change_box = 1; restart_global = 1; pre_exchange_migrate = 1; + pcouple = NOCOUPLE; + dimension = domain->dimension; nevery = utils::inumeric(FLERR,arg[3],false,lmp); if (nevery <= 0) error->all(FLERR,"Illegal fix deform command"); @@ -132,7 +140,35 @@ irregular(nullptr), set(nullptr) set[index].hstr = utils::strdup(&arg[iarg+2][2]); set[index].hratestr = utils::strdup(&arg[iarg+3][2]); iarg += 4; - } else error->all(FLERR,"Illegal fix deform command"); + } else if (strcmp(arg[iarg+1],"pressure") == 0) { + if (iarg+4 > narg) error->all(FLERR, "Illegal fix deform command"); + set[index].style = PRESSURE; + if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { + set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); + } else { + if (iarg+ > narg) error->all(FLERR,"Illegal fix deform command"); + set[index].pstr = utils::strdup(&arg[iarg+2][2]); + set[index].pvar = 1; + } + set[index].pgain = utils::numeric(FLERR,arg[iarg+3],false,lmp); + if (set[index].pgain <= 0.0) + error->all(FLERR,"Illegal fix deform command"); + iarg += 4; + } else if (strcmp(arg[iarg+1],"pressure/isotropic") == 0) { + if (iarg+4 > narg) error->all(FLERR, "Illegal fix deform command"); + set[index].style = PISOTROPIC; + if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { + set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); + } else { + if (iarg+ > narg) error->all(FLERR,"Illegal fix deform command"); + set[index].pstr = utils::strdup(&arg[iarg+2][2]); + set[index].pvar = 1; + } + set[index].pgain = utils::numeric(FLERR,arg[iarg+3],false,lmp); + if (set[index].pgain <= 0.0) + error->all(FLERR,"Illegal fix deform command"); + iarg += 4; + } error->all(FLERR,"Illegal fix deform command"); } else if (strcmp(arg[iarg],"xy") == 0 || strcmp(arg[iarg],"xz") == 0 || @@ -190,8 +226,21 @@ irregular(nullptr), set(nullptr) set[index].hstr = utils::strdup(&arg[iarg+2][2]); set[index].hratestr = utils::strdup(&arg[iarg+3][2]); iarg += 4; + } else if (strcmp(arg[iarg+1],"pressure") == 0) { + if (iarg+4 > narg) error->all(FLERR, "Illegal fix deform command"); + set[index].style = PRESSURE; + if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { + set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); + } else { + if (iarg+ > narg) error->all(FLERR,"Illegal fix deform command"); + set[index].pstr = utils::strdup(&arg[iarg+2][2]); + set[index].pvar = 1; + } + set[index].pgain = utils::numeric(FLERR,arg[iarg+3],false,lmp); + if (set[index].pgain <= 0.0) + error->all(FLERR,"Illegal fix deform command"); + iarg += 4; } else error->all(FLERR,"Illegal fix deform command"); - } else break; } @@ -201,6 +250,63 @@ irregular(nullptr), set(nullptr) options(narg-iarg,&arg[iarg]); if (remapflag != Domain::X_REMAP) restart_pbc = 1; + // populate coupled pressure controls + + if (pcouple != NOCOUPLE) { + int coupled_indices[3] = {0}; + int j = -1; + double couple_gain, coupled_pressure; + char *couple_str; + + if (pcouple == XYZ || pcouple == XY || pcouple == XZ) + coupled_indices[0] = 1; + if (pcouple == XYZ || pcouple == XY || pcouple == YZ) + coupled_indices[1] = 1; + if (pcouple == XYZ || pcouple == XZ || pcouple == YZ) + coupled_indices[2] = 1; + + // Check coupled styles and find reference + for (int i = 0; i < 3; i++) { + if (coupled_indices[i]) { + set[i].coupled_flag = 1; + if (set[i].style != VOLUME && set[i].style != PRESSURE && set[i].style != NONE) + error->all(FLERR, "Cannot couple dimensions not controlled by pressure or volume in fix deform"); + if (set[i].style == PRESSURE || set[i].style == VOLUME) + j = i; + } + } + + if (j == -1) + error->all(FLERR, "Must specify pressure style for a coupled dimension in fix deform"); + + // Copy data to each coupled dimension + for (int i = 0; i < 3; i++) { + if (coupled_indices[i]) { + if (set[j].style != set[i].style && set[i].style != NONE) + error->all(FLERR, "Cannot couple dimensions with different control options"); + + if (set[j].style == PRESSURE && set[i].style == NONE) { + set[i].style = PRESSURE; + set[i].pgain = set[j].pgain; + if (set[j].pvar == 1) { + set[i].pstr = set[j].pstr; + set[i].pvar = 1; + } else { + set[i].ptarget = set[j].ptarget; + } + } else if (set[j].style == VOLUME && set[i].style == NONE) { + set[i].style = VOLUME; + set[i].saved = -1; + if (domain->dimension == 2) + error->all(FLERR, "Cannot couple pressure with constant volume in two dimensions"); + } + } else { + if (set[i].style == VOLUME && set[j].style == VOLUME) + error->all(FLERR, "Dimensions used to maintain constant volume must either be all be coupled or not coupled"); + } + } + } + // setup dimflags used by other classes to check for volume-change conflicts for (int i = 0; i < 6; i++) @@ -285,32 +391,31 @@ irregular(nullptr), set(nullptr) // for VOLUME, setup links to other dims // fixed, dynamic1, dynamic2 + volume_flag = 0; for (int i = 0; i < 3; i++) { if (set[i].style != VOLUME) continue; + volume_flag = 1; int other1 = (i+1) % 3; int other2 = (i+2) % 3; - if (set[other1].style == NONE) { + // Cannot use VOLUME option without at least one deformed dimension + if (set[other1].style == NONE || set[other1].style == VOLUME) if (set[other2].style == NONE || set[other2].style == VOLUME) error->all(FLERR,"Fix deform volume setting is invalid"); + + if (set[other1].style == NONE) { set[i].substyle = ONE_FROM_ONE; set[i].fixed = other1; set[i].dynamic1 = other2; } else if (set[other2].style == NONE) { - if (set[other1].style == NONE || set[other1].style == VOLUME) - error->all(FLERR,"Fix deform volume setting is invalid"); set[i].substyle = ONE_FROM_ONE; set[i].fixed = other2; set[i].dynamic1 = other1; } else if (set[other1].style == VOLUME) { - if (set[other2].style == NONE || set[other2].style == VOLUME) - error->all(FLERR,"Fix deform volume setting is invalid"); set[i].substyle = TWO_FROM_ONE; set[i].fixed = other1; set[i].dynamic1 = other2; } else if (set[other2].style == VOLUME) { - if (set[other1].style == NONE || set[other1].style == VOLUME) - error->all(FLERR,"Fix deform volume setting is invalid"); set[i].substyle = TWO_FROM_ONE; set[i].fixed = other2; set[i].dynamic1 = other1; @@ -321,12 +426,34 @@ irregular(nullptr), set(nullptr) } } + // set strain_flag + strain_flag = 0; + for (int i = 0; i < 6; i++) + if (set[i].style != NONE && set[i].style != VOLUME && + set[i].style != PRESSURE && set[i].style != PISOTROPIC) + strain_flag = 1; + // set varflag varflag = 0; for (int i = 0; i < 6; i++) if (set[i].style == VARIABLE) varflag = 1; + // set pressure_flag + + pressure_flag = 0; + for (int i = 0; i < 6; i++) { + if (set[i].style == PRESSURE || set[i].style == PISOTROPIC) pressure_flag = 1; + if (set[i].coupled_flag) pressure_flag = 1; + } + + // check conflict between constant volume/pressure + + if (volume_flag) + for (int i = 0; i < 6; i++) + if (set[i].style == PISOTROPIC) + error->all(FLERR, "Cannot use fix deform to assign constant volume and pressure"); + // set initial values at time fix deform is issued for (int i = 0; i < 3; i++) { @@ -350,6 +477,29 @@ irregular(nullptr), set(nullptr) else irregular = nullptr; TWOPI = 2.0*MY_PI; + + // Create pressure compute, if needed + + pflag = 0; + tflag = 0; + if (pressure_flag) { + // create a new compute temp style + // id = fix-ID + temp + // compute group = all since pressure is always global (group all) + // and thus its KE/temperature contribution should use group all + + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); + tflag = 1; + + // create a new compute pressure style + // id = fix-ID + press, compute group = all + // pass id_temp as 4th arg to pressure constructor + + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); + pflag = 1; + } } /* ---------------------------------------------------------------------- */ @@ -360,6 +510,7 @@ FixDeform::~FixDeform() for (int i = 0; i < 6; i++) { delete[] set[i].hstr; delete[] set[i].hratestr; + delete[] set[i].pstr; } } delete[] set; @@ -374,6 +525,13 @@ FixDeform::~FixDeform() h_rate[0] = h_rate[1] = h_rate[2] = h_rate[3] = h_rate[4] = h_rate[5] = 0.0; h_ratelo[0] = h_ratelo[1] = h_ratelo[2] = 0.0; + + // delete temperature and pressure if fix created them + + if (tflag) modify->delete_compute(id_temp); + if (pflag) modify->delete_compute(id_press); + delete [] id_temp; + delete [] id_press; } /* ---------------------------------------------------------------------- */ @@ -574,7 +732,7 @@ void FixDeform::init() // set domain->h_rate values for use by domain and other fixes/computes // initialize all rates to 0.0 - // cannot set here for TRATE,VOLUME,WIGGLE,VARIABLE since not constant + // cannot set here for TRATE,VOLUME,WIGGLE,VARIABLE,PRESSURE since not constant h_rate = domain->h_rate; h_ratelo = domain->h_ratelo; @@ -611,6 +769,31 @@ void FixDeform::init() for (auto ifix : modify->get_fix_list()) if (ifix->rigid_flag) rfix.push_back(ifix); + + // Find pressure/temp computes if needed + + if (pressure_flag) { + int icompute = modify->find_compute(id_temp); + if (icompute < 0) + error->all(FLERR,"Temperature ID for fix deform does not exist"); + temperature = modify->compute[icompute]; + + icompute = modify->find_compute(id_press); + if (icompute < 0) + error->all(FLERR,"Pressure ID for fix deform does not exist"); + pressure = modify->compute[icompute]; + } +} + +/* ---------------------------------------------------------------------- + compute T,P if needed before integrator starts +------------------------------------------------------------------------- */ + +void FixDeform::setup(int /*vflag*/) +{ + // trigger virial computation on next timestep + + if (pressure_flag) pressure->addstep(update->ntimestep+1); } /* ---------------------------------------------------------------------- @@ -660,95 +843,40 @@ void FixDeform::end_of_step() if (varflag) modify->clearstep_compute(); - // set new box size - // for NONE, target is current box size - // for TRATE, set target directly based on current time, also set h_rate - // for WIGGLE, set target directly based on current time, also set h_rate - // for VARIABLE, set target directly via variable eval, also set h_rate - // for others except VOLUME, target is linear value between start and stop + // set new box size for strain-based dims - for (i = 0; i < 3; i++) { - if (set[i].style == NONE) { - set[i].lo_target = domain->boxlo[i]; - set[i].hi_target = domain->boxhi[i]; - } else if (set[i].style == TRATE) { - double delt = (update->ntimestep - update->beginstep) * update->dt; - set[i].lo_target = 0.5*(set[i].lo_start+set[i].hi_start) - - 0.5*((set[i].hi_start-set[i].lo_start) * exp(set[i].rate*delt)); - set[i].hi_target = 0.5*(set[i].lo_start+set[i].hi_start) + - 0.5*((set[i].hi_start-set[i].lo_start) * exp(set[i].rate*delt)); - h_rate[i] = set[i].rate * domain->h[i]; - h_ratelo[i] = -0.5*h_rate[i]; - } else if (set[i].style == WIGGLE) { - double delt = (update->ntimestep - update->beginstep) * update->dt; - set[i].lo_target = set[i].lo_start - - 0.5*set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); - set[i].hi_target = set[i].hi_start + - 0.5*set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); - h_rate[i] = TWOPI/set[i].tperiod * set[i].amplitude * - cos(TWOPI*delt/set[i].tperiod); - h_ratelo[i] = -0.5*h_rate[i]; - } else if (set[i].style == VARIABLE) { - double del = input->variable->compute_equal(set[i].hvar); - set[i].lo_target = set[i].lo_start - 0.5*del; - set[i].hi_target = set[i].hi_start + 0.5*del; - h_rate[i] = input->variable->compute_equal(set[i].hratevar); - h_ratelo[i] = -0.5*h_rate[i]; - } else if (set[i].style != VOLUME) { - set[i].lo_target = set[i].lo_start + - delta*(set[i].lo_stop - set[i].lo_start); - set[i].hi_target = set[i].hi_start + - delta*(set[i].hi_stop - set[i].hi_start); + set_strain(); + + // set new box size for pressure-based dims + + if (pressure_flag) { + temperature->compute_vector(); + pressure->compute_vector(); + for (int i = 0; i < 3; i++) { + if (set[i].saved == -1) { + set[i].saved = 1; + set[i].rate = 0.0; + set[i].prior_pressure = pressure->vector[i]; + if (i == 0) set[i].box_length = domain->xprd; + else if (i == 1) set[i].box_length = domain->yprd; + else (i == 2) set[i].box_length = domain->zprd; + } } + set_pressure(); } // set new box size for VOLUME dims that are linked to other dims // NOTE: still need to set h_rate for these dims - for (i = 0; i < 3; i++) { - if (set[i].style != VOLUME) continue; + if (volume_flag) set_volume(); - if (set[i].substyle == ONE_FROM_ONE) { - set[i].lo_target = 0.5*(set[i].lo_start+set[i].hi_start) - - 0.5*(set[i].vol_start / - (set[set[i].dynamic1].hi_target - - set[set[i].dynamic1].lo_target) / - (set[set[i].fixed].hi_start-set[set[i].fixed].lo_start)); - set[i].hi_target = 0.5*(set[i].lo_start+set[i].hi_start) + - 0.5*(set[i].vol_start / - (set[set[i].dynamic1].hi_target - - set[set[i].dynamic1].lo_target) / - (set[set[i].fixed].hi_start-set[set[i].fixed].lo_start)); + // Save pressure/strain rate if required - } else if (set[i].substyle == ONE_FROM_TWO) { - set[i].lo_target = 0.5*(set[i].lo_start+set[i].hi_start) - - 0.5*(set[i].vol_start / - (set[set[i].dynamic1].hi_target - - set[set[i].dynamic1].lo_target) / - (set[set[i].dynamic2].hi_target - - set[set[i].dynamic2].lo_target)); - set[i].hi_target = 0.5*(set[i].lo_start+set[i].hi_start) + - 0.5*(set[i].vol_start / - (set[set[i].dynamic1].hi_target - - set[set[i].dynamic1].lo_target) / - (set[set[i].dynamic2].hi_target - - set[set[i].dynamic2].lo_target)); - - } else if (set[i].substyle == TWO_FROM_ONE) { - set[i].lo_target = 0.5*(set[i].lo_start+set[i].hi_start) - - 0.5*sqrt(set[i].vol_start / - (set[set[i].dynamic1].hi_target - - set[set[i].dynamic1].lo_target) / - (set[set[i].fixed].hi_start - - set[set[i].fixed].lo_start) * - (set[i].hi_start - set[i].lo_start)); - set[i].hi_target = 0.5*(set[i].lo_start+set[i].hi_start) + - 0.5*sqrt(set[i].vol_start / - (set[set[i].dynamic1].hi_target - - set[set[i].dynamic1].lo_target) / - (set[set[i].fixed].hi_start - - set[set[i].fixed].lo_start) * - (set[i].hi_start - set[i].lo_start)); + if (pressure_flag) { + double dt_inv = 1.0 / update->dt; + for (int i = 0; i < 3; i++) { + set[i].prior_pressure = pressure->vector[i]; + set[i].prior_rate = ((set[i].hi_target - set[i].lo_target) / set[i].box_length - 1.0) * dt_inv; } } @@ -882,7 +1010,7 @@ void FixDeform::end_of_step() if (mask[i] & groupbit) domain->x2lamda(x[i],x[i]); - for (auto &ifix : rfix) + for (auto ifix : rfix) ifix->deform(0); } @@ -921,13 +1049,134 @@ void FixDeform::end_of_step() if (mask[i] & groupbit) domain->lamda2x(x[i],x[i]); - for (auto &ifix : rfix) + for (auto ifix : rfix) ifix->deform(1); } // redo KSpace coeffs since box has changed if (kspace_flag) force->kspace->setup(); + + // trigger virial computation, if needed, on next timestep + + if (pressure_flag) { + pressure->addstep(update->ntimestep+1); + set[0].box_length = domain->xprd; + set[1].box_length = domain->yprd; + set[2].box_length = domain->zprd; + } +} + +/* ---------------------------------------------------------------------- + set box size for strain-based dimensions +------------------------------------------------------------------------- */ + +void FixDeform::set_strain() +{ + // for NONE, target is current box size + // for TRATE, set target directly based on current time, also set h_rate + // for WIGGLE, set target directly based on current time, also set h_rate + // for VARIABLE, set target directly via variable eval, also set h_rate + // for others except VOLUME, target is linear value between start and stop + + for (int i = 0; i < 3; i++) { + if (set[i].style == NONE) { + set[i].lo_target = domain->boxlo[i]; + set[i].hi_target = domain->boxhi[i]; + } else if (set[i].style == TRATE) { + double delt = (update->ntimestep - update->beginstep) * update->dt; + set[i].lo_target = 0.5*(set[i].lo_start+set[i].hi_start) - + 0.5*((set[i].hi_start-set[i].lo_start) * exp(set[i].rate*delt)); + set[i].hi_target = 0.5*(set[i].lo_start+set[i].hi_start) + + 0.5*((set[i].hi_start-set[i].lo_start) * exp(set[i].rate*delt)); + h_rate[i] = set[i].rate * domain->h[i]; + h_ratelo[i] = -0.5*h_rate[i]; + } else if (set[i].style == WIGGLE) { + double delt = (update->ntimestep - update->beginstep) * update->dt; + set[i].lo_target = set[i].lo_start - + 0.5*set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); + set[i].hi_target = set[i].hi_start + + 0.5*set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); + h_rate[i] = TWOPI/set[i].tperiod * set[i].amplitude * + cos(TWOPI*delt/set[i].tperiod); + h_ratelo[i] = -0.5*h_rate[i]; + } else if (set[i].style == VARIABLE) { + double del = input->variable->compute_equal(set[i].hvar); + set[i].lo_target = set[i].lo_start - 0.5*del; + set[i].hi_target = set[i].hi_start + 0.5*del; + h_rate[i] = input->variable->compute_equal(set[i].hratevar); + h_ratelo[i] = -0.5*h_rate[i]; + } else if (set[i].style != VOLUME) { + set[i].lo_target = set[i].lo_start + + delta*(set[i].lo_stop - set[i].lo_start); + set[i].hi_target = set[i].hi_start + + delta*(set[i].hi_stop - set[i].hi_start); + } + } +} + +/* ---------------------------------------------------------------------- + set box size for pressure-based dimensions +------------------------------------------------------------------------- */ + +void FixDeform::set_pressure() +{ + for (int i = 0; i < 3; i++) { + + + } + // must define hi+lo target + // + +} + +/* ---------------------------------------------------------------------- + set box size for VOLUME dimensions +------------------------------------------------------------------------- */ + +void FixDeform::set_volume() +{ + for (int i = 0; i < 3; i++) { + if (set[i].style != VOLUME) continue; + + double v0 = set[i].vol_start; + double center_start = 0.5 * (set[i].lo_start + set[i].hi_start); + double offset; + + if (set[i].substyle == ONE_FROM_ONE) { + offset = 0.5 * (v0 / + (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target) / + (set[set[i].fixed].hi_start-set[set[i].fixed].lo_start)); + } else if (set[i].substyle == ONE_FROM_TWO) { + offset = 0.5 * (v0 / + (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target) / + (set[set[i].dynamic2].hi_target - set[set[i].dynamic2].lo_target)) + } else if (set[i].substyle == TWO_FROM_ONE) { + if (!set[i].coupled_flag) { + offset = 0.5 * sqrt(v0 * (set[i].hi_start - set[i].lo_start) / + (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target) / + (set[set[i].fixed].hi_start - set[set[i].fixed].lo_start)) + } else { + double p1 = pressure->vector[i]; + double p2 = pressure->vector[set[i].fixed]; + double p1i = set[i].prior_pressure; + double p2i = set[set[i].fixed].prior_pressure; + double e1i = set[i].prior_rate; + double e2i = set[set[i].fixed].prior_rate; + double L3 = (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target); + double dt = update->dt; + + double e3 = (L3 / set[set[i].dynamic1].box_length - 1.0) / dt; + double e1 = -e3 * dt / (1 + e3 * dt) * (p2 - p2i) - e2i * (p1 - p2); + e1 /= (p2 - p2i + (p1 - p1i) / e1p * e2p); + double e2 = (1.0 - (1 + e3 * dt) * (1 + e1 * dt)); + e2 /= (1 + e3 * dt) * (1 + e1 * dt) * dt; + offset = 0.5 * set[i].box_length * (1.0 - e3 * dt); + } + } + set[i].lo_target = center_start - offset; + set[i].hi_target = center_start + offset; + } } /* ---------------------------------------------------------------------- @@ -937,7 +1186,7 @@ void FixDeform::end_of_step() void FixDeform::write_restart(FILE *fp) { if (comm->me == 0) { - int size = 6*sizeof(Set); + int size = 6 * sizeof(Set); fwrite(&size,sizeof(int),1,fp); fwrite(set,sizeof(Set),6,fp); } @@ -996,8 +1245,22 @@ void FixDeform::options(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal fix deform command"); flipflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; + } else if (strcmp(arg[iarg],"couple") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal fix fix deform command"); + if (strcmp(arg[iarg+1],"xyz") == 0) pcouple = XYZ; + else if (strcmp(arg[iarg+1],"xy") == 0) pcouple = XY; + else if (strcmp(arg[iarg+1],"yz") == 0) pcouple = YZ; + else if (strcmp(arg[iarg+1],"xz") == 0) pcouple = XZ; + else if (strcmp(arg[iarg+1],"none") == 0) pcouple = NOCOUPLE; + else error->all(FLERR,"Illegal fix fix deform command"); + iarg += 2; } else error->all(FLERR,"Illegal fix deform command"); } + + if (dimension == 2) + if (pcouple == XYZ || pcouple == XZ || pcouple == YZ) + error->all(FLERR, "Cannot couple Z dimension in fix deform in 2D"); } /* ---------------------------------------------------------------------- @@ -1010,3 +1273,57 @@ double FixDeform::memory_usage() if (irregular) bytes += irregular->memory_usage(); return bytes; } + + +/* ---------------------------------------------------------------------- */ + +int FixDeform::modify_param(int narg, char **arg) +{ + if (!pressure_flag) error->all(FLERR,"Cannot modify fix deform without a pressure control"); + if (strcmp(arg[0],"temp") == 0) { + if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); + if (tflag) { + modify->delete_compute(id_temp); + tflag = 0; + } + delete [] id_temp; + id_temp = utils::strdup(arg[1]); + + int icompute = modify->find_compute(arg[1]); + if (icompute < 0) error->all(FLERR,"Could not find fix_modify temperature ID"); + temperature = modify->compute[icompute]; + + if (temperature->tempflag == 0) + error->all(FLERR,"Fix_modify temperature ID does not compute temperature"); + if (temperature->igroup != 0 && comm->me == 0) + error->warning(FLERR,"Temperature for deform is not for group all"); + + // reset id_temp of pressure to new temperature ID + + icompute = modify->find_compute(id_press); + if (icompute < 0) + error->all(FLERR,"Pressure ID for fix deform does not exist"); + modify->compute[icompute]->reset_extra_compute_fix(id_temp); + + return 2; + + } else if (strcmp(arg[0],"press") == 0) { + if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); + if (pflag) { + modify->delete_compute(id_press); + pflag = 0; + } + delete [] id_press; + id_press = utils::strdup(arg[1]); + + int icompute = modify->find_compute(arg[1]); + if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); + pressure = modify->compute[icompute]; + + if (pressure->pressflag == 0) + error->all(FLERR,"Fix_modify pressure ID does not compute pressure"); + return 2; + } + + return 0; +} diff --git a/src/fix_deform.h b/src/fix_deform.h index 76f5fc9d4a..7297874258 100644 --- a/src/fix_deform.h +++ b/src/fix_deform.h @@ -33,23 +33,32 @@ class FixDeform : public Fix { ~FixDeform() override; int setmask() override; void init() override; + void setup(int) override; void pre_exchange() override; void end_of_step() override; void write_restart(FILE *) override; void restart(char *buf) override; double memory_usage() override; + int modify_param(int, char **) override; protected: - int triclinic, scaleflag, flipflag; + int dimension, triclinic, scaleflag, flipflag, pcouple; int flip, flipxy, flipxz, flipyz; double *h_rate, *h_ratelo; int varflag; // 1 if VARIABLE option is used, 0 if not + int strain_flag; // 1 if strain-based option is used, 0 if not + int volume_flag; // 1 if VOLUME option is used, 0 if not + int pressure_flag; // 1 if pressure tensor used, 0 if not int kspace_flag; // 1 if KSpace invoked, 0 if not std::vector rfix; // pointers to rigid fixes class Irregular *irregular; // for migrating atoms after box flips double TWOPI; + char *id_temp, *id_press; + class Compute *temperature, *pressure; + int tflag, pflag; + struct Set { int style, substyle; double flo, fhi, ftilt; @@ -61,13 +70,21 @@ class FixDeform : public Fix { double tilt_initial, tilt_start, tilt_stop, tilt_target, tilt_flip; double tilt_min, tilt_max; double vol_initial, vol_start; + double ptarget, pgain; + double prior_pressure, prior_rate; + double box_length; + int saved; int fixed, dynamic1, dynamic2; - char *hstr, *hratestr; + char *hstr, *hratestr, *pstr; int hvar, hratevar; + int pvar; + int coupled_flag; }; Set *set; void options(int, char **); + void set_volume(); + void couple(); }; } // namespace LAMMPS_NS From 66471c146537d8d1a32e00c8c7d9e68c4bc8ff07 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Tue, 11 Oct 2022 16:52:02 -0600 Subject: [PATCH 002/185] Adding pressure controls and fixing misc errors --- src/fix_deform.cpp | 375 ++++++++++++++++++++++++++++----------------- src/fix_deform.h | 4 +- 2 files changed, 235 insertions(+), 144 deletions(-) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 40221df839..766d7c22ae 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -17,14 +17,14 @@ ------------------------------------------------------------------------- */ // Save previous state to restart file for derivatives -// define hrate_lo/hi for volume -// add modify command -// add pressure code +// define hrate_lo/hi for volume/pressure +// add logic for hi_stop and flip flag #include "fix_deform.h" #include "atom.h" #include "comm.h" +#include "compute.h" #include "domain.h" #include "error.h" #include "force.h" @@ -84,36 +84,36 @@ irregular(nullptr), set(nullptr) else if (strcmp(arg[iarg],"y") == 0) index = 1; else if (strcmp(arg[iarg],"z") == 0) index = 2; - if (iarg+2 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); if (strcmp(arg[iarg+1],"final") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); set[index].style = FINAL; set[index].flo = utils::numeric(FLERR,arg[iarg+2],false,lmp); set[index].fhi = utils::numeric(FLERR,arg[iarg+3],false,lmp); iarg += 4; } else if (strcmp(arg[iarg+1],"delta") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); set[index].style = DELTA; set[index].dlo = utils::numeric(FLERR,arg[iarg+2],false,lmp); set[index].dhi = utils::numeric(FLERR,arg[iarg+3],false,lmp); iarg += 4; } else if (strcmp(arg[iarg+1],"scale") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform scale", error); set[index].style = SCALE; set[index].scale = utils::numeric(FLERR,arg[iarg+2],false,lmp); iarg += 3; } else if (strcmp(arg[iarg+1],"vel") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); set[index].style = VEL; set[index].vel = utils::numeric(FLERR,arg[iarg+2],false,lmp); iarg += 3; } else if (strcmp(arg[iarg+1],"erate") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); set[index].style = ERATE; set[index].rate = utils::numeric(FLERR,arg[iarg+2],false,lmp); iarg += 3; } else if (strcmp(arg[iarg+1],"trate") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); set[index].style = TRATE; set[index].rate = utils::numeric(FLERR,arg[iarg+2],false,lmp); iarg += 3; @@ -121,54 +121,52 @@ irregular(nullptr), set(nullptr) set[index].style = VOLUME; iarg += 2; } else if (strcmp(arg[iarg+1],"wiggle") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); set[index].style = WIGGLE; set[index].amplitude = utils::numeric(FLERR,arg[iarg+2],false,lmp); set[index].tperiod = utils::numeric(FLERR,arg[iarg+3],false,lmp); if (set[index].tperiod <= 0.0) - error->all(FLERR,"Illegal fix deform command"); + error->all(FLERR,"Illegal fix deform wiggle period, must be positive"); iarg += 4; } else if (strcmp(arg[iarg+1],"variable") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); set[index].style = VARIABLE; if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) - error->all(FLERR,"Illegal fix deform command"); + error->all(FLERR,"Illegal fix deform variable name {}", arg[iarg+2]); if (strstr(arg[iarg+3],"v_") != arg[iarg+3]) - error->all(FLERR,"Illegal fix deform command"); + error->all(FLERR,"Illegal fix deform variable name {}", arg[iarg+3]); delete[] set[index].hstr; delete[] set[index].hratestr; set[index].hstr = utils::strdup(&arg[iarg+2][2]); set[index].hratestr = utils::strdup(&arg[iarg+3][2]); iarg += 4; } else if (strcmp(arg[iarg+1],"pressure") == 0) { - if (iarg+4 > narg) error->all(FLERR, "Illegal fix deform command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform pressure", error); set[index].style = PRESSURE; if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); } else { - if (iarg+ > narg) error->all(FLERR,"Illegal fix deform command"); set[index].pstr = utils::strdup(&arg[iarg+2][2]); - set[index].pvar = 1; + set[index].pvar_flag = 1; } set[index].pgain = utils::numeric(FLERR,arg[iarg+3],false,lmp); if (set[index].pgain <= 0.0) - error->all(FLERR,"Illegal fix deform command"); + error->all(FLERR,"Illegal fix deform pressure gain, must be positive"); iarg += 4; } else if (strcmp(arg[iarg+1],"pressure/isotropic") == 0) { - if (iarg+4 > narg) error->all(FLERR, "Illegal fix deform command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform pressure/isotropic", error); set[index].style = PISOTROPIC; if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); } else { - if (iarg+ > narg) error->all(FLERR,"Illegal fix deform command"); set[index].pstr = utils::strdup(&arg[iarg+2][2]); - set[index].pvar = 1; + set[index].pvar_flag = 1; } set[index].pgain = utils::numeric(FLERR,arg[iarg+3],false,lmp); if (set[index].pgain <= 0.0) - error->all(FLERR,"Illegal fix deform command"); + error->all(FLERR,"Illegal fix deform pressure gain, must be positive"); iarg += 4; - } error->all(FLERR,"Illegal fix deform command"); + } else error->all(FLERR,"Illegal fix deform command argument: {}", arg[iarg+1]); } else if (strcmp(arg[iarg],"xy") == 0 || strcmp(arg[iarg],"xz") == 0 || @@ -180,67 +178,66 @@ irregular(nullptr), set(nullptr) else if (strcmp(arg[iarg],"xz") == 0) index = 4; else if (strcmp(arg[iarg],"yz") == 0) index = 3; - if (iarg+2 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); if (strcmp(arg[iarg+1],"final") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); set[index].style = FINAL; set[index].ftilt = utils::numeric(FLERR,arg[iarg+2],false,lmp); iarg += 3; } else if (strcmp(arg[iarg+1],"delta") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); set[index].style = DELTA; set[index].dtilt = utils::numeric(FLERR,arg[iarg+2],false,lmp); iarg += 3; } else if (strcmp(arg[iarg+1],"vel") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); set[index].style = VEL; set[index].vel = utils::numeric(FLERR,arg[iarg+2],false,lmp); iarg += 3; } else if (strcmp(arg[iarg+1],"erate") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); set[index].style = ERATE; set[index].rate = utils::numeric(FLERR,arg[iarg+2],false,lmp); iarg += 3; } else if (strcmp(arg[iarg+1],"trate") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); set[index].style = TRATE; set[index].rate = utils::numeric(FLERR,arg[iarg+2],false,lmp); iarg += 3; } else if (strcmp(arg[iarg+1],"wiggle") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); set[index].style = WIGGLE; set[index].amplitude = utils::numeric(FLERR,arg[iarg+2],false,lmp); set[index].tperiod = utils::numeric(FLERR,arg[iarg+3],false,lmp); if (set[index].tperiod <= 0.0) - error->all(FLERR,"Illegal fix deform command"); + error->all(FLERR,"Illegal fix deform wiggle period, must be positive"); iarg += 4; } else if (strcmp(arg[iarg+1],"variable") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); set[index].style = VARIABLE; if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) - error->all(FLERR,"Illegal fix deform command"); + error->all(FLERR,"Illegal fix deform variable name {}", arg[iarg+2]); if (strstr(arg[iarg+3],"v_") != arg[iarg+3]) - error->all(FLERR,"Illegal fix deform command"); + error->all(FLERR,"Illegal fix deform variable name {}", arg[iarg+3]); delete[] set[index].hstr; delete[] set[index].hratestr; set[index].hstr = utils::strdup(&arg[iarg+2][2]); set[index].hratestr = utils::strdup(&arg[iarg+3][2]); iarg += 4; } else if (strcmp(arg[iarg+1],"pressure") == 0) { - if (iarg+4 > narg) error->all(FLERR, "Illegal fix deform command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform pressure", error); set[index].style = PRESSURE; if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); } else { - if (iarg+ > narg) error->all(FLERR,"Illegal fix deform command"); set[index].pstr = utils::strdup(&arg[iarg+2][2]); - set[index].pvar = 1; + set[index].pvar_flag = 1; } set[index].pgain = utils::numeric(FLERR,arg[iarg+3],false,lmp); if (set[index].pgain <= 0.0) - error->all(FLERR,"Illegal fix deform command"); + error->all(FLERR,"Illegal fix deform pressure gain, must be positive"); iarg += 4; - } else error->all(FLERR,"Illegal fix deform command"); + } else error->all(FLERR,"Illegal fix deform command: {}", arg[iarg+1]); } else break; } @@ -270,7 +267,7 @@ irregular(nullptr), set(nullptr) if (coupled_indices[i]) { set[i].coupled_flag = 1; if (set[i].style != VOLUME && set[i].style != PRESSURE && set[i].style != NONE) - error->all(FLERR, "Cannot couple dimensions not controlled by pressure or volume in fix deform"); + error->all(FLERR, "Cannot couple dimensions unless they are controlled using the pressure or volume option in fix deform"); if (set[i].style == PRESSURE || set[i].style == VOLUME) j = i; } @@ -279,30 +276,45 @@ irregular(nullptr), set(nullptr) if (j == -1) error->all(FLERR, "Must specify pressure style for a coupled dimension in fix deform"); - // Copy data to each coupled dimension + // Copy or compare data for each coupled dimension for (int i = 0; i < 3; i++) { if (coupled_indices[i]) { - if (set[j].style != set[i].style && set[i].style != NONE) - error->all(FLERR, "Cannot couple dimensions with different control options"); - + // Copy coupling information if dimension style is undefined if (set[j].style == PRESSURE && set[i].style == NONE) { set[i].style = PRESSURE; set[i].pgain = set[j].pgain; - if (set[j].pvar == 1) { + if (set[j].pvar_flag) { set[i].pstr = set[j].pstr; - set[i].pvar = 1; + set[i].pvar_flag = 1; } else { set[i].ptarget = set[j].ptarget; } } else if (set[j].style == VOLUME && set[i].style == NONE) { set[i].style = VOLUME; - set[i].saved = -1; if (domain->dimension == 2) error->all(FLERR, "Cannot couple pressure with constant volume in two dimensions"); } + + // Check for incompatibilities in style + if (set[j].style != set[i].style && set[i].style != NONE) + error->all(FLERR, "Cannot couple dimensions with different control options"); + if (set[j].style != PRESSURE) continue; + + // If pressure controlled, check for incompatibilities in parameters + if (set[i].pgain != set[j].pgain) + error->all(FLERR, "Coupled dimensions must have identical gain parameters\n"); + + if (set[i].pvar_flag != set[j].pvar_flag) + error->all(FLERR, "Coupled dimensions must have the same target pressure\n"); + if (set[j].pvar_flag) + if (strcmp(set[i].pstr, set[j].pstr) != 0) + error->all(FLERR, "Coupled dimensions must have the same target pressure\n"); + if (set[i].ptarget != set[j].ptarget) + error->all(FLERR, "Coupled dimensions must have the same target pressure\n"); + } else { if (set[i].style == VOLUME && set[j].style == VOLUME) - error->all(FLERR, "Dimensions used to maintain constant volume must either be all be coupled or not coupled"); + error->all(FLERR, "Dimensions used to maintain constant volume must either all be coupled or uncoupled"); } } } @@ -427,6 +439,7 @@ irregular(nullptr), set(nullptr) } // set strain_flag + strain_flag = 0; for (int i = 0; i < 6; i++) if (set[i].style != NONE && set[i].style != VOLUME && @@ -569,14 +582,25 @@ void FixDeform::init() if (set[i].style != VARIABLE) continue; set[i].hvar = input->variable->find(set[i].hstr); if (set[i].hvar < 0) - error->all(FLERR,"Variable name for fix deform does not exist"); + error->all(FLERR,"Variable name {} for fix deform does not exist", set[i].hstr); if (!input->variable->equalstyle(set[i].hvar)) - error->all(FLERR,"Variable for fix deform is invalid style"); + error->all(FLERR,"Variable {} for fix deform is invalid style", set[i].hstr); set[i].hratevar = input->variable->find(set[i].hratestr); if (set[i].hratevar < 0) - error->all(FLERR,"Variable name for fix deform does not exist"); + error->all(FLERR,"Variable name {} for fix deform does not exist", set[i].hratestr); if (!input->variable->equalstyle(set[i].hratevar)) - error->all(FLERR,"Variable for fix deform is invalid style"); + error->all(FLERR,"Variable {} for fix deform is invalid style", set[i].hratestr); + } + + // check optional variables for PRESSURE or PISOTROPIC style + + for (int i = 0; i < 6; i++) { + if (!set[i].pvar_flag) continue; + set[i].pvar = input->variable->find(set[i].pstr); + if (set[i].pvar < 0) + error->all(FLERR,"Variable name {} for fix deform does not exist", set[i].pstr); + if (!input->variable->equalstyle(set[i].pvar)) + error->all(FLERR,"Variable {} for fix deform is invalid style", set[i].pstr); } // set start/stop values for box size and shape @@ -834,11 +858,6 @@ void FixDeform::pre_exchange() void FixDeform::end_of_step() { - int i; - - double delta = update->ntimestep - update->beginstep; - if (delta != 0.0) delta /= update->endstep - update->beginstep; - // wrap variable evaluations with clear/add if (varflag) modify->clearstep_compute(); @@ -853,13 +872,13 @@ void FixDeform::end_of_step() temperature->compute_vector(); pressure->compute_vector(); for (int i = 0; i < 3; i++) { - if (set[i].saved == -1) { + if (! set[i].saved) { set[i].saved = 1; - set[i].rate = 0.0; + set[i].prior_rate = 0.0; set[i].prior_pressure = pressure->vector[i]; if (i == 0) set[i].box_length = domain->xprd; else if (i == 1) set[i].box_length = domain->yprd; - else (i == 2) set[i].box_length = domain->zprd; + else set[i].box_length = domain->zprd; } } set_pressure(); @@ -880,61 +899,6 @@ void FixDeform::end_of_step() } } - // for triclinic, set new box shape - // for NONE, target is current tilt - // for TRATE, set target directly based on current time. also set h_rate - // for WIGGLE, set target directly based on current time. also set h_rate - // for VARIABLE, set target directly via variable eval. also set h_rate - // for other styles, target is linear value between start and stop values - - if (triclinic) { - double *h = domain->h; - - for (i = 3; i < 6; i++) { - if (set[i].style == NONE) { - if (i == 5) set[i].tilt_target = domain->xy; - else if (i == 4) set[i].tilt_target = domain->xz; - else if (i == 3) set[i].tilt_target = domain->yz; - } else if (set[i].style == TRATE) { - double delt = (update->ntimestep - update->beginstep) * update->dt; - set[i].tilt_target = set[i].tilt_start * exp(set[i].rate*delt); - h_rate[i] = set[i].rate * domain->h[i]; - } else if (set[i].style == WIGGLE) { - double delt = (update->ntimestep - update->beginstep) * update->dt; - set[i].tilt_target = set[i].tilt_start + - set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); - h_rate[i] = TWOPI/set[i].tperiod * set[i].amplitude * - cos(TWOPI*delt/set[i].tperiod); - } else if (set[i].style == VARIABLE) { - double delta_tilt = input->variable->compute_equal(set[i].hvar); - set[i].tilt_target = set[i].tilt_start + delta_tilt; - h_rate[i] = input->variable->compute_equal(set[i].hratevar); - } else { - set[i].tilt_target = set[i].tilt_start + - delta*(set[i].tilt_stop - set[i].tilt_start); - } - - // tilt_target can be large positive or large negative value - // add/subtract box lengths until tilt_target is closest to current value - - int idenom = 0; - if (i == 5) idenom = 0; - else if (i == 4) idenom = 0; - else if (i == 3) idenom = 1; - double denom = set[idenom].hi_target - set[idenom].lo_target; - - double current = h[i]/h[idenom]; - - while (set[i].tilt_target/denom - current > 0.0) - set[i].tilt_target -= denom; - while (set[i].tilt_target/denom - current < 0.0) - set[i].tilt_target += denom; - if (fabs(set[i].tilt_target/denom - 1.0 - current) < - fabs(set[i].tilt_target/denom - current)) - set[i].tilt_target -= denom; - } - } - if (varflag) modify->addstep_compute(update->ntimestep + nevery); // if any tilt ratios exceed 0.5, set flip = 1 and compute new tilt values @@ -1006,7 +970,7 @@ void FixDeform::end_of_step() int *mask = atom->mask; int nlocal = atom->nlocal; - for (i = 0; i < nlocal; i++) + for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) domain->x2lamda(x[i],x[i]); @@ -1045,7 +1009,7 @@ void FixDeform::end_of_step() int *mask = atom->mask; int nlocal = atom->nlocal; - for (i = 0; i < nlocal; i++) + for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) domain->lamda2x(x[i],x[i]); @@ -1079,6 +1043,9 @@ void FixDeform::set_strain() // for VARIABLE, set target directly via variable eval, also set h_rate // for others except VOLUME, target is linear value between start and stop + double delta = update->ntimestep - update->beginstep; + if (delta != 0.0) delta /= update->endstep - update->beginstep; + for (int i = 0; i < 3; i++) { if (set[i].style == NONE) { set[i].lo_target = domain->boxlo[i]; @@ -1113,6 +1080,62 @@ void FixDeform::set_strain() delta*(set[i].hi_stop - set[i].hi_start); } } + + + // for triclinic, set new box shape + // for NONE, target is current tilt + // for TRATE, set target directly based on current time. also set h_rate + // for WIGGLE, set target directly based on current time. also set h_rate + // for VARIABLE, set target directly via variable eval. also set h_rate + // for other styles, target is linear value between start and stop values + + if (triclinic) { + double *h = domain->h; + + for (int i = 3; i < 6; i++) { + if (set[i].style == NONE) { + if (i == 5) set[i].tilt_target = domain->xy; + else if (i == 4) set[i].tilt_target = domain->xz; + else if (i == 3) set[i].tilt_target = domain->yz; + } else if (set[i].style == TRATE) { + double delt = (update->ntimestep - update->beginstep) * update->dt; + set[i].tilt_target = set[i].tilt_start * exp(set[i].rate*delt); + h_rate[i] = set[i].rate * domain->h[i]; + } else if (set[i].style == WIGGLE) { + double delt = (update->ntimestep - update->beginstep) * update->dt; + set[i].tilt_target = set[i].tilt_start + + set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); + h_rate[i] = TWOPI/set[i].tperiod * set[i].amplitude * + cos(TWOPI*delt/set[i].tperiod); + } else if (set[i].style == VARIABLE) { + double delta_tilt = input->variable->compute_equal(set[i].hvar); + set[i].tilt_target = set[i].tilt_start + delta_tilt; + h_rate[i] = input->variable->compute_equal(set[i].hratevar); + } else { + set[i].tilt_target = set[i].tilt_start + + delta*(set[i].tilt_stop - set[i].tilt_start); + } + + // tilt_target can be large positive or large negative value + // add/subtract box lengths until tilt_target is closest to current value + + int idenom = 0; + if (i == 5) idenom = 0; + else if (i == 4) idenom = 0; + else if (i == 3) idenom = 1; + double denom = set[idenom].hi_target - set[idenom].lo_target; + + double current = h[i]/h[idenom]; + + while (set[i].tilt_target/denom - current > 0.0) + set[i].tilt_target -= denom; + while (set[i].tilt_target/denom - current < 0.0) + set[i].tilt_target += denom; + if (fabs(set[i].tilt_target/denom - 1.0 - current) < + fabs(set[i].tilt_target/denom - current)) + set[i].tilt_target -= denom; + } + } } /* ---------------------------------------------------------------------- @@ -1121,13 +1144,59 @@ void FixDeform::set_strain() void FixDeform::set_pressure() { - for (int i = 0; i < 3; i++) { + // If variable pressure, calculate current target + for (int i = 0; i < 6; i++) + if (set[i].style == PRESSURE) + if (set[i].pvar_flag) + set[i].ptarget = input->variable->compute_equal(set[i].pvar); + // Find current (possibly coupled/hydrostatic) pressure for X, Y, Z + double *tensor = pressure->vector; + double scalar = pressure->scalar; + double p_current[3]; + if (pcouple == XYZ) { + double ave = 1.0/3.0 * (tensor[0] + tensor[1] + tensor[2]); + p_current[0] = p_current[1] = p_current[2] = ave; + } else if (pcouple == XY) { + double ave = 0.5 * (tensor[0] + tensor[1]); + p_current[0] = p_current[1] = ave; + p_current[2] = tensor[2]; + } else if (pcouple == YZ) { + double ave = 0.5 * (tensor[1] + tensor[2]); + p_current[1] = p_current[2] = ave; + p_current[0] = tensor[0]; + } else if (pcouple == XZ) { + double ave = 0.5 * (tensor[0] + tensor[2]); + p_current[0] = p_current[2] = ave; + p_current[1] = tensor[1]; + } else { + if (set[0].style == PRESSURE) p_current[0] = tensor[0]; + else if (set[0].style == PISOTROPIC) p_current[0] = scalar; + + if (set[1].style == PRESSURE) p_current[1] = tensor[1]; + else if (set[1].style == PISOTROPIC) p_current[1] = scalar; + + if (set[2].style == PRESSURE) p_current[2] = tensor[2]; + else if (set[2].style == PISOTROPIC) p_current[2] = scalar; } - // must define hi+lo target - // + for (int i = 0; i < 3; i++) { + if (set[i].style != PRESSURE && set[i].style != PISOTROPIC) continue; + double dilation = 1.0 - update->dt * set[i].pgain * (set[i].ptarget - p_current[i]); + double center_start = 0.5 * (set[i].lo_start + set[i].hi_start); + double offset = 0.5 * set[i].box_length * dilation; + //printf("ptarget %g vs %g, dilation %g cs %g ofset %g box %g\n", set[i].ptarget, p_current[i], dilation, center_start, offset, set[i].box_length); + set[i].lo_target = center_start - offset; + set[i].hi_target = center_start + offset; + } + + for (int i = 3; i < 6; i++) { + double shift = update->dt * set[i].pgain * (set[i].ptarget - tensor[i]); + if (i == 3) set[i].tilt_target = domain->xy + shift * domain->xprd; + else if (i == 4) set[i].tilt_target = domain->xz + shift * domain->xprd; + else set[i].tilt_target = domain->yz + shift * domain->yprd; + } } /* ---------------------------------------------------------------------- @@ -1136,6 +1205,9 @@ void FixDeform::set_pressure() void FixDeform::set_volume() { + double e1, e2; + int linked_pressure = 0; + for (int i = 0; i < 3; i++) { if (set[i].style != VOLUME) continue; @@ -1150,28 +1222,46 @@ void FixDeform::set_volume() } else if (set[i].substyle == ONE_FROM_TWO) { offset = 0.5 * (v0 / (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target) / - (set[set[i].dynamic2].hi_target - set[set[i].dynamic2].lo_target)) + (set[set[i].dynamic2].hi_target - set[set[i].dynamic2].lo_target)); } else if (set[i].substyle == TWO_FROM_ONE) { if (!set[i].coupled_flag) { offset = 0.5 * sqrt(v0 * (set[i].hi_start - set[i].lo_start) / (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target) / - (set[set[i].fixed].hi_start - set[set[i].fixed].lo_start)) + (set[set[i].fixed].hi_start - set[set[i].fixed].lo_start)); } else { + double dt = update->dt; + double e1i = set[i].prior_rate; + double e2i = set[set[i].fixed].prior_rate; + double L3 = (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target); + double e3 = (L3 / set[set[i].dynamic1].box_length - 1.0) / dt; double p1 = pressure->vector[i]; double p2 = pressure->vector[set[i].fixed]; double p1i = set[i].prior_pressure; double p2i = set[set[i].fixed].prior_pressure; - double e1i = set[i].prior_rate; - double e2i = set[set[i].fixed].prior_rate; - double L3 = (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target); - double dt = update->dt; - double e3 = (L3 / set[set[i].dynamic1].box_length - 1.0) / dt; - double e1 = -e3 * dt / (1 + e3 * dt) * (p2 - p2i) - e2i * (p1 - p2); - e1 /= (p2 - p2i + (p1 - p1i) / e1p * e2p); - double e2 = (1.0 - (1 + e3 * dt) * (1 + e1 * dt)); - e2 /= (1 + e3 * dt) * (1 + e1 * dt) * dt; - offset = 0.5 * set[i].box_length * (1.0 - e3 * dt); + if (e3 == 0) { + e1 = 0.0; + e2 = 0.0; + offset = 0.5 * set[i].box_length; + } else if (e1i == 0 || e2i == 0 || (p2 == p2i && p1 == p1i)) { + // If no prior strain or no change in pressure (initial step) just scale offset by relative box lengths + offset = 0.5 * sqrt(v0 * set[i].box_length / L3 / set[set[i].fixed].box_length); + } else { + if (! linked_pressure) { + // Calculate first strain rate by expanding stress to linear order in strain to achieve p1(t+dt) = p2(t+dt) + e1 = -e3 / (1 + e3 * dt) * (p2 - p2i) - e2i * (p1 - p2); + e1 /= (p2 - p2i + (p1 - p1i) / e1i * e2i); + + // Calculate second strain rate to preserve volume + e2 = (1.0 - (1 + e3 * dt) * (1 + e1 * dt)); + e2 /= (1 + e3 * dt) * (1 + e1 * dt) * dt; + + offset = 0.5 * set[i].box_length * (1.0 + e1 * dt); + linked_pressure = 1; + } else { + offset = 0.5 * set[i].box_length * (1.0 + e2 * dt); + } + } } } set[i].lo_target = center_start - offset; @@ -1229,33 +1319,32 @@ void FixDeform::options(int narg, char **arg) int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg],"remap") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform remap", error); if (strcmp(arg[iarg+1],"x") == 0) remapflag = Domain::X_REMAP; else if (strcmp(arg[iarg+1],"v") == 0) remapflag = Domain::V_REMAP; else if (strcmp(arg[iarg+1],"none") == 0) remapflag = Domain::NO_REMAP; - else error->all(FLERR,"Illegal fix deform command"); + else error->all(FLERR,"Illegal fix deform remap command: {}", arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"units") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform units", error); if (strcmp(arg[iarg+1],"box") == 0) scaleflag = 0; else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = 1; - else error->all(FLERR,"Illegal fix deform command"); + else error->all(FLERR,"Illegal fix deform units command: {}", arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"flip") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix deform command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform flip", error); flipflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"couple") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal fix fix deform command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform couple", error); if (strcmp(arg[iarg+1],"xyz") == 0) pcouple = XYZ; else if (strcmp(arg[iarg+1],"xy") == 0) pcouple = XY; else if (strcmp(arg[iarg+1],"yz") == 0) pcouple = YZ; else if (strcmp(arg[iarg+1],"xz") == 0) pcouple = XZ; else if (strcmp(arg[iarg+1],"none") == 0) pcouple = NOCOUPLE; - else error->all(FLERR,"Illegal fix fix deform command"); + else error->all(FLERR,"Illegal fix fix deform couple command: {}", arg[iarg+1]); iarg += 2; - } else error->all(FLERR,"Illegal fix deform command"); + } else error->all(FLERR,"Illegal fix deform command: {}", arg[iarg]); } if (dimension == 2) @@ -1281,7 +1370,7 @@ int FixDeform::modify_param(int narg, char **arg) { if (!pressure_flag) error->all(FLERR,"Cannot modify fix deform without a pressure control"); if (strcmp(arg[0],"temp") == 0) { - if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); + if (narg < 2) utils::missing_cmd_args(FLERR, "fix_modify deform", error); if (tflag) { modify->delete_compute(id_temp); tflag = 0; diff --git a/src/fix_deform.h b/src/fix_deform.h index 7297874258..9ecb9a577d 100644 --- a/src/fix_deform.h +++ b/src/fix_deform.h @@ -77,12 +77,14 @@ class FixDeform : public Fix { int fixed, dynamic1, dynamic2; char *hstr, *hratestr, *pstr; int hvar, hratevar; - int pvar; + int pvar, pvar_flag; int coupled_flag; }; Set *set; void options(int, char **); + void set_strain(); + void set_pressure(); void set_volume(); void couple(); }; From 173e2382b3c3752439b601e7fa88f1a7523b50ce Mon Sep 17 00:00:00 2001 From: jtclemm Date: Sat, 22 Oct 2022 19:03:52 -0600 Subject: [PATCH 003/185] Adding documentation, various updates --- doc/src/fix_deform.rst | 169 ++++++++++++++- src/fix_deform.cpp | 482 ++++++++++++++++++++++------------------- src/fix_deform.h | 7 +- 3 files changed, 425 insertions(+), 233 deletions(-) diff --git a/doc/src/fix_deform.rst b/doc/src/fix_deform.rst index 805bd84382..d46f1204f5 100644 --- a/doc/src/fix_deform.rst +++ b/doc/src/fix_deform.rst @@ -34,6 +34,12 @@ Syntax effectively an engineering strain rate *erate* value = R R = engineering strain rate (1/time units) + *pressure* values = target gain + target = target pressure (pressure units) + gain = proportional gain constant (1/(time * pressure) or 1/time units) + *pressure/mean* values = target gain + target = target pressure (pressure units) + gain = proportional gain constant (1/(time * pressure) or 1/time units) *trate* value = R R = true strain rate (1/time units) *volume* value = none = adjust this dim to preserve volume of system @@ -54,6 +60,9 @@ Syntax effectively an engineering shear strain rate *erate* value = R R = engineering shear strain rate (1/time units) + *pressure* values = target gain + target = target pressure (pressure units) + gain = proportional gain constant (1/(time * pressure) or 1/time units) *trate* value = R R = true shear strain rate (1/time units) *wiggle* values = A Tp @@ -64,7 +73,7 @@ Syntax v_name2 = variable with name2 for change rate as function of time * zero or more keyword/value pairs may be appended -* keyword = *remap* or *flip* or *units* +* keyword = *remap* or *flip* or *units* or *couple* or *vol/balance/p* or *max/rate* or *normalize/pressure* .. parsed-literal:: @@ -77,6 +86,14 @@ Syntax *units* value = *lattice* or *box* lattice = distances are defined in lattice units box = distances are defined in simulation box units + *couple* value = *none* or *xyz* or *xy* or *yz* or *xz* + couple pressure values of various dimensions + *vol/balance/p* = *yes* or *no* + Modifies the behavior of the *volume* option to try and balance pressures + *max/rate* value = *rate* + rate = maximum strain rate for pressure control + *normalize/pressure* value = *yes* or *no* + determine whether pressure deviation is normalized by target pressure Examples """""""" @@ -87,6 +104,9 @@ Examples fix 1 all deform 1 x trate 0.1 y volume z volume fix 1 all deform 1 xy erate 0.001 remap v fix 1 all deform 10 y delta -0.5 0.5 xz vel 1.0 + fix 1 all deform 1 x pressure 2.0 0.1 normalize/pressure yes max/rate 0.001 + fix 1 all deform 1 x trate 0.1 y volume z volume vol/balance/p yes + fix 1 all deform 1 x trate 0.1 y pressure/mean 0.0 1.0 z pressure/mean 0.0 1.0 Description """"""""""" @@ -230,7 +250,11 @@ the product of x,z lengths constant. If "x scale 1.1 y volume z volume" is specified, then both the y,z box lengths will shrink as x increases to keep the volume constant (product of x,y,z lengths). In this case, the y,z box lengths shrink so as to keep their relative -aspect ratio constant. +aspect ratio constant. When maintaining a constant volume using two +separate dimensions, one can alternatively allow the two dimensions +to adjust their aspect ratio to attempt to maintain equivalent +pressures along the two dimensions. See the +:ref:`vol/balance/p ` option for more details. For solids or liquids, note that when one dimension of the box is expanded via fix deform (i.e. tensile strain), it may be physically @@ -292,6 +316,38 @@ For the *scale*, *vel*, *erate*, *trate*, *volume*, *wiggle*, and *variable* styles, the box length is expanded or compressed around its mid point. +The *pressure* style adjusts a dimensions's box length to control that +component of the pressure tensor. This option attempts to maintain a +specified target value using a linear controller where the box length L +evolves according to the equation + +.. parsed-literal:: + + \frac{d L(t)}{dt} = L(t) k (P_t - P) + +where :math:`k` is a proportional gain constant, :math:`P_t` is the target +pressure, and :math:`P` is the current pressure along that dimension. This +approach is similar to the method used to control the pressure by +:doc:`fix press/berendsen `. The target pressure +accepts either a constant numeric value or a LAMMPS :ref:`variable `. +Notably, this variable can be a function of time or other components of +the pressure tensor. By default, :math:`k` has units of 1/(time * pressure) +although this will change if the *normalize/pessure* option is set as +:ref:`discussed below `. There is no proven method +to choosing an appropriate value of :math:`k` as it will depend on the +specific details of a simulation and testing different values is +recommended. One can also apply a maximum limit to the magnitude of the +applied strain using the :ref:`max/rate ` option and couple +pressures in different dimensions using the :ref:`couple ` +option. + +The *pressure/mean* style is changes a dimension in order to maintain +a constant mean pressure defined as the trace of the pressure tensor. +This option is therefore very similar to the *presssure* style with +identical arguments except the current and target pressures refer to the +mean trace of the pressure tensor. The same options also apply except +for the :ref:`couple ` option. + ---------- For the *xy*, *xz*, and *yz* parameters, this is the meaning of their @@ -433,6 +489,27 @@ assume that the current timestep = 0. variable rate equal "2*PI*v_A/v_Tp * cos(2*PI * step*dt/v_Tp)" fix 2 all deform 1 xy variable v_displace v_rate remap v +The *pressure* style adjusts a tilt factor to control the corresponding +off-diagonal component of the pressure tensor. This option attempts to +maintain a specified target value using a linear controller where the +tilt factor T evolves according to the equation + +.. parsed-literal:: + + \frac{d T(t)}{dt} = L(t) k (P - P_t) + +where :math:`k` is a proportional gain constant, :math:`P_t` is the target +pressure, :math:`P` is the current pressure, and :math:`L` is the perpendicular +box length. The target pressure accepts either a constant numeric value or a +LAMMPS :ref:`variable `. Notably, this variable can be a function +of time or other components of the pressure tensor. By default, :math:`k` +has units of 1/(time * pressure) although this will change if the +*normalize/pessure* option is set as :ref:`discussed below `. +There is no proven method to choosing an appropriate value of :math:`k` as it +will depend on thespecific details of a simulation and testing different +values isrecommended. One can also apply a maximum limit to the magnitude +of the applied strain using the :ref:`max/rate ` option. + ---------- All of the tilt styles change the xy, xz, yz tilt factors during a @@ -561,6 +638,73 @@ does not affect the *variable* style. You should use the *xlat*, *ylat*, *zlat* keywords of the :doc:`thermo_style ` command if you want to include lattice spacings in a variable formula. +.. _deform_normalize: + +The *normalize/pressure* keyword changes how box dimensions evolve when +using the *pressure* or *pressure/mean* deformation options. If the +*deform/normalize* value is set to *yes*, then the deviation from the +target pressure is normalized by the absolute value of the target +pressure such that the proportional gain constant scales a percentage +error and has units of 1/time. If the target pressure is ever zero, this +will produce an error unless the *max/rate* keyword is defined, +described below, which will cap the divergence. + +.. _deform_max_rate: + +The *max/rate* keyword sets an upper threshold, *rate*, that limits the +maximum magnitude of the strain rate applied in any dimension. This keyword +only applies to the *pressure* and *pressure/mean* options. + +.. _deform_couple: + +The *couple* keyword allows two or three of the diagonal components of +the pressure tensor to be "coupled" together for the *pressure* option. +The value specified with the keyword determines which are coupled. For +example, *xz* means the *Pxx* and *Pzz* components of the stress tensor +are coupled. *Xyz* means all 3 diagonal components are coupled. Coupling +means two things: the instantaneous stress will be computed as an average +of the corresponding diagonal components, and the coupled box dimensions +will be changed together in lockstep, meaning coupled dimensions will be +dilated or contracted by the same percentage every timestep. The target +pressures and gain constants for any coupled dimensions must be identical. +*Couple xyz* can be used for a 2d simulation; the *z* dimension is simply +ignored. + +.. _deform_balance: + +The *vol/balance/p* keyword modifies the behavior of *volume* when two +dimensions are used to maintain a fixed volume. Instead of straining +the two dimensions in lockstep, the two dimensions are allowed to +separately dilate or contract in a manner to maintain a constant +volume while simultaneously trying to keep the pressure along each +dimension equal using a method described in :ref:`(Huang2014) `. + +---------- + +If any pressure controls are used, this fix computes a temperature and +pressure each timestep. To do this, the fix creates its own computes of +style "temp" and "pressure", as if these commands had been issued: + +.. code-block:: LAMMPS + + compute fix-ID_temp group-ID temp + compute fix-ID_press group-ID pressure fix-ID_temp + +See the :doc:`compute temp ` and :doc:`compute pressure ` commands for details. Note that the +IDs of the new computes are the fix-ID + underscore + "temp" or fix_ID ++ underscore + "press", and the group for the new computes is the same +as the fix group. + +Note that these are NOT the computes used by thermodynamic output (see +the :doc:`thermo_style ` command) with ID = *thermo_temp* +and *thermo_press*. This means you can change the attributes of this +fix's temperature or pressure via the +:doc:`compute_modify ` command or print this temperature +or pressure during thermodynamic output via the +:doc:`thermo_style custom ` command using the appropriate +compute-ID. It also means that changing attributes of *thermo_temp* or +*thermo_press* will have no effect on this fix. + ---------- .. include:: accel_styles.rst @@ -574,6 +718,15 @@ command. None of the :doc:`fix_modify ` options are relevant to this fix. No global or per-atom quantities are stored by this fix for access by various :doc:`output commands `. +If any pressure controls are used, the :doc:`fix_modify ` *temp* +and *press* options are supported by this fix. You can use them to assign a +:doc:`compute ` you have defined to this fix which will be used +in its temperature and pressure calculations. If you do this, note +that the kinetic energy derived from the compute temperature should be +consistent with the virial term computed using all atoms for the +pressure. LAMMPS will warn you if you choose to compute temperature +on a subset of atoms. + This fix can perform deformation over multiple runs, using the *start* and *stop* keywords of the :doc:`run ` command. See the :doc:`run ` command for details of how to do this. @@ -597,4 +750,14 @@ Related commands Default """"""" -The option defaults are remap = x, flip = yes, and units = lattice. +The option defaults are remap = x, flip = yes, units = lattice, and +normalize/pressure = no. + +---------- + +.. _Li2014b: + +**(Huang2014)** X. Huang, +"Exploring critical-state behavior using DEM", +Doctoral dissertation, Imperial College. +(2014). https://doi.org/10.25560/25316 diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 766d7c22ae..db3fad6a95 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -13,13 +13,9 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Pieter in 't Veld (SNL) + Contributing author: Pieter in 't Veld (SNL), Joel Clemmer (SNL) ------------------------------------------------------------------------- */ -// Save previous state to restart file for derivatives -// define hrate_lo/hi for volume/pressure -// add logic for hi_stop and flip flag - #include "fix_deform.h" #include "atom.h" @@ -44,7 +40,7 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{NONE=0,FINAL,DELTA,SCALE,VEL,ERATE,TRATE,VOLUME,WIGGLE,VARIABLE,PRESSURE,PISOTROPIC}; +enum{NONE=0,FINAL,DELTA,SCALE,VEL,ERATE,TRATE,VOLUME,WIGGLE,VARIABLE,PRESSURE,PMEAN}; enum{ONE_FROM_ONE,ONE_FROM_TWO,TWO_FROM_ONE}; enum{NOCOUPLE=0,XYZ,XY,YZ,XZ}; @@ -60,6 +56,9 @@ irregular(nullptr), set(nullptr) pre_exchange_migrate = 1; pcouple = NOCOUPLE; dimension = domain->dimension; + max_h_rate = 0.0; + vol_balance_flag = 0; + normalize_pressure_flag = 0; nevery = utils::inumeric(FLERR,arg[3],false,lmp); if (nevery <= 0) error->all(FLERR,"Illegal fix deform command"); @@ -153,9 +152,9 @@ irregular(nullptr), set(nullptr) if (set[index].pgain <= 0.0) error->all(FLERR,"Illegal fix deform pressure gain, must be positive"); iarg += 4; - } else if (strcmp(arg[iarg+1],"pressure/isotropic") == 0) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform pressure/isotropic", error); - set[index].style = PISOTROPIC; + } else if (strcmp(arg[iarg+1],"pressure/mean") == 0) { + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform pressure/mean", error); + set[index].style = PMEAN; if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); } else { @@ -266,21 +265,21 @@ irregular(nullptr), set(nullptr) for (int i = 0; i < 3; i++) { if (coupled_indices[i]) { set[i].coupled_flag = 1; - if (set[i].style != VOLUME && set[i].style != PRESSURE && set[i].style != NONE) - error->all(FLERR, "Cannot couple dimensions unless they are controlled using the pressure or volume option in fix deform"); - if (set[i].style == PRESSURE || set[i].style == VOLUME) + if (set[i].style != PRESSURE && set[i].style != NONE) + error->all(FLERR, "Cannot couple non-pressure-controlled dimensions"); + if (set[i].style == PRESSURE) j = i; } } if (j == -1) - error->all(FLERR, "Must specify pressure style for a coupled dimension in fix deform"); + error->all(FLERR, "Must specify deformation style for at least one coupled dimension"); // Copy or compare data for each coupled dimension for (int i = 0; i < 3; i++) { if (coupled_indices[i]) { // Copy coupling information if dimension style is undefined - if (set[j].style == PRESSURE && set[i].style == NONE) { + if (set[i].style == NONE) { set[i].style = PRESSURE; set[i].pgain = set[j].pgain; if (set[j].pvar_flag) { @@ -289,32 +288,21 @@ irregular(nullptr), set(nullptr) } else { set[i].ptarget = set[j].ptarget; } - } else if (set[j].style == VOLUME && set[i].style == NONE) { - set[i].style = VOLUME; - if (domain->dimension == 2) - error->all(FLERR, "Cannot couple pressure with constant volume in two dimensions"); + } else { + // Check for incompatibilities in style + if (set[j].style != set[i].style && set[i].style != NONE) + error->all(FLERR, "Cannot couple dimensions with different control options"); + if (set[j].style != PRESSURE) continue; + + // If pressure controlled, check for incompatibilities in parameters + if (set[i].pgain != set[j].pgain || set[i].pvar_flag != set[j].pvar_flag || + set[i].ptarget != set[j].ptarget) + error->all(FLERR, "Coupled dimensions must have identical gain parameters"); + + if (set[j].pvar_flag) + if (strcmp(set[i].pstr, set[j].pstr) != 0) + error->all(FLERR, "Coupled dimensions must have the same target pressure"); } - - // Check for incompatibilities in style - if (set[j].style != set[i].style && set[i].style != NONE) - error->all(FLERR, "Cannot couple dimensions with different control options"); - if (set[j].style != PRESSURE) continue; - - // If pressure controlled, check for incompatibilities in parameters - if (set[i].pgain != set[j].pgain) - error->all(FLERR, "Coupled dimensions must have identical gain parameters\n"); - - if (set[i].pvar_flag != set[j].pvar_flag) - error->all(FLERR, "Coupled dimensions must have the same target pressure\n"); - if (set[j].pvar_flag) - if (strcmp(set[i].pstr, set[j].pstr) != 0) - error->all(FLERR, "Coupled dimensions must have the same target pressure\n"); - if (set[i].ptarget != set[j].ptarget) - error->all(FLERR, "Coupled dimensions must have the same target pressure\n"); - - } else { - if (set[i].style == VOLUME && set[j].style == VOLUME) - error->all(FLERR, "Dimensions used to maintain constant volume must either all be coupled or uncoupled"); } } } @@ -335,27 +323,18 @@ irregular(nullptr), set(nullptr) // no tensile deformation on shrink-wrapped dims // b/c shrink wrap will change box-length - if (set[0].style && - (domain->boundary[0][0] >= 2 || domain->boundary[0][1] >= 2)) - error->all(FLERR,"Cannot use fix deform on a shrink-wrapped boundary"); - if (set[1].style && - (domain->boundary[1][0] >= 2 || domain->boundary[1][1] >= 2)) - error->all(FLERR,"Cannot use fix deform on a shrink-wrapped boundary"); - if (set[2].style && - (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) + for (int i = 0; i < 3; i++) + if (set[i].style && (domain->boundary[i][0] >= 2 || domain->boundary[i][1] >= 2)) error->all(FLERR,"Cannot use fix deform on a shrink-wrapped boundary"); // no tilt deformation on shrink-wrapped 2nd dim // b/c shrink wrap will change tilt factor in domain::reset_box() - if (set[3].style && - (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) + if (set[3].style && (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) error->all(FLERR,"Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); - if (set[4].style && - (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) + if (set[4].style && (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) error->all(FLERR,"Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); - if (set[5].style && - (domain->boundary[1][0] >= 2 || domain->boundary[1][1] >= 2)) + if (set[5].style && (domain->boundary[1][0] >= 2 || domain->boundary[1][1] >= 2)) error->all(FLERR,"Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); // apply scaling to FINAL,DELTA,VEL,WIGGLE since they have dist/vel units @@ -436,6 +415,9 @@ irregular(nullptr), set(nullptr) set[i].dynamic1 = other1; set[i].dynamic2 = other2; } + + if (vol_balance_flag && set[i].substyle != TWO_FROM_ONE) + error->all(FLERR, "Two dimensions must maintain constant volume to use the vol/balance/p option"); } // set strain_flag @@ -443,30 +425,41 @@ irregular(nullptr), set(nullptr) strain_flag = 0; for (int i = 0; i < 6; i++) if (set[i].style != NONE && set[i].style != VOLUME && - set[i].style != PRESSURE && set[i].style != PISOTROPIC) + set[i].style != PRESSURE && set[i].style != PMEAN) strain_flag = 1; // set varflag varflag = 0; - for (int i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) { if (set[i].style == VARIABLE) varflag = 1; + if (set[i].pvar_flag) varflag = 1; + } // set pressure_flag pressure_flag = 0; for (int i = 0; i < 6; i++) { - if (set[i].style == PRESSURE || set[i].style == PISOTROPIC) pressure_flag = 1; + if (set[i].style == PRESSURE || set[i].style == PMEAN) pressure_flag = 1; if (set[i].coupled_flag) pressure_flag = 1; } + if (vol_balance_flag) pressure_flag = 1; // check conflict between constant volume/pressure if (volume_flag) for (int i = 0; i < 6; i++) - if (set[i].style == PISOTROPIC) + if (set[i].style == PMEAN) error->all(FLERR, "Cannot use fix deform to assign constant volume and pressure"); + // check pressure used for max rate and normalize error flag + + if (!pressure_flag && max_h_rate != 0) + error->all(FLERR, "Can only assign a maximum strain rate using pressure-controlled dimensions"); + + if (!pressure_flag && normalize_pressure_flag) + error->all(FLERR, "Can only normalize error using pressure-controlled dimensions"); + // set initial values at time fix deform is issued for (int i = 0; i < 3; i++) { @@ -489,8 +482,6 @@ irregular(nullptr), set(nullptr) if (force_reneighbor) irregular = new Irregular(lmp); else irregular = nullptr; - TWOPI = 2.0*MY_PI; - // Create pressure compute, if needed pflag = 0; @@ -592,7 +583,7 @@ void FixDeform::init() error->all(FLERR,"Variable {} for fix deform is invalid style", set[i].hratestr); } - // check optional variables for PRESSURE or PISOTROPIC style + // check optional variables for PRESSURE or PMEAN style for (int i = 0; i < 6; i++) { if (!set[i].pvar_flag) continue; @@ -627,30 +618,26 @@ void FixDeform::init() set[i].lo_stop = set[i].lo_start + set[i].dlo; set[i].hi_stop = set[i].hi_start + set[i].dhi; } else if (set[i].style == SCALE) { - set[i].lo_stop = 0.5*(set[i].lo_start+set[i].hi_start) - - 0.5*set[i].scale*(set[i].hi_start-set[i].lo_start); - set[i].hi_stop = 0.5*(set[i].lo_start+set[i].hi_start) + - 0.5*set[i].scale*(set[i].hi_start-set[i].lo_start); + double shift = 0.5 * set[i].scale * (set[i].hi_start - set[i].lo_start); + set[i].lo_stop = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; + set[i].hi_stop = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; } else if (set[i].style == VEL) { - set[i].lo_stop = set[i].lo_start - 0.5*delt*set[i].vel; - set[i].hi_stop = set[i].hi_start + 0.5*delt*set[i].vel; + set[i].lo_stop = set[i].lo_start - 0.5 * delt * set[i].vel; + set[i].hi_stop = set[i].hi_start + 0.5 * delt * set[i].vel; } else if (set[i].style == ERATE) { - set[i].lo_stop = set[i].lo_start - - 0.5*delt*set[i].rate * (set[i].hi_start-set[i].lo_start); - set[i].hi_stop = set[i].hi_start + - 0.5*delt*set[i].rate * (set[i].hi_start-set[i].lo_start); + double shift = 0.5 * delt * set[i].rate * (set[i].hi_start - set[i].lo_start); + set[i].lo_stop = set[i].lo_start - shift; + set[i].hi_stop = set[i].hi_start + shift; if (set[i].hi_stop <= set[i].lo_stop) error->all(FLERR,"Final box dimension due to fix deform is < 0.0"); } else if (set[i].style == TRATE) { - set[i].lo_stop = 0.5*(set[i].lo_start+set[i].hi_start) - - 0.5*((set[i].hi_start-set[i].lo_start) * exp(set[i].rate*delt)); - set[i].hi_stop = 0.5*(set[i].lo_start+set[i].hi_start) + - 0.5*((set[i].hi_start-set[i].lo_start) * exp(set[i].rate*delt)); + double shift = 0.5 * ((set[i].hi_start - set[i].lo_start) * exp(set[i].rate * delt)); + set[i].lo_stop = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; + set[i].hi_stop = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; } else if (set[i].style == WIGGLE) { - set[i].lo_stop = set[i].lo_start - - 0.5*set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); - set[i].hi_stop = set[i].hi_start + - 0.5*set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); + double shift = 0.5 * set[i].amplitude * sin(MY_2PI * delt / set[i].tperiod); + set[i].lo_stop = set[i].lo_start - shift; + set[i].hi_stop = set[i].hi_start + shift; } } @@ -666,50 +653,46 @@ void FixDeform::init() } else if (set[i].style == DELTA) { set[i].tilt_stop = set[i].tilt_start + set[i].dtilt; } else if (set[i].style == VEL) { - set[i].tilt_stop = set[i].tilt_start + delt*set[i].vel; + set[i].tilt_stop = set[i].tilt_start + delt * set[i].vel; } else if (set[i].style == ERATE) { if (i == 3) set[i].tilt_stop = set[i].tilt_start + - delt*set[i].rate * (set[2].hi_start-set[2].lo_start); + delt * set[i].rate * (set[2].hi_start - set[2].lo_start); if (i == 4) set[i].tilt_stop = set[i].tilt_start + - delt*set[i].rate * (set[2].hi_start-set[2].lo_start); + delt * set[i].rate * (set[2].hi_start - set[2].lo_start); if (i == 5) set[i].tilt_stop = set[i].tilt_start + - delt*set[i].rate * (set[1].hi_start-set[1].lo_start); + delt * set[i].rate * (set[1].hi_start - set[1].lo_start); } else if (set[i].style == TRATE) { - set[i].tilt_stop = set[i].tilt_start * exp(set[i].rate*delt); + set[i].tilt_stop = set[i].tilt_start * exp(set[i].rate * delt); } else if (set[i].style == WIGGLE) { - set[i].tilt_stop = set[i].tilt_start + - set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); + double shift = set[i].amplitude * sin(MY_2PI * delt / set[i].tperiod); + set[i].tilt_stop = set[i].tilt_start + shift; // compute min/max for WIGGLE = extrema tilt factor will ever reach if (set[i].amplitude >= 0.0) { - if (delt < 0.25*set[i].tperiod) { + if (delt < 0.25 * set[i].tperiod) { set[i].tilt_min = set[i].tilt_start; - set[i].tilt_max = set[i].tilt_start + - set[i].amplitude*sin(TWOPI*delt/set[i].tperiod); - } else if (delt < 0.5*set[i].tperiod) { + set[i].tilt_max = set[i].tilt_start + shift; + } else if (delt < 0.5 * set[i].tperiod) { set[i].tilt_min = set[i].tilt_start; set[i].tilt_max = set[i].tilt_start + set[i].amplitude; - } else if (delt < 0.75*set[i].tperiod) { - set[i].tilt_min = set[i].tilt_start - - set[i].amplitude*sin(TWOPI*delt/set[i].tperiod); + } else if (delt < 0.75 * set[i].tperiod) { + set[i].tilt_min = set[i].tilt_start - shift; set[i].tilt_max = set[i].tilt_start + set[i].amplitude; } else { set[i].tilt_min = set[i].tilt_start - set[i].amplitude; set[i].tilt_max = set[i].tilt_start + set[i].amplitude; } } else { - if (delt < 0.25*set[i].tperiod) { - set[i].tilt_min = set[i].tilt_start - - set[i].amplitude*sin(TWOPI*delt/set[i].tperiod); + if (delt < 0.25 * set[i].tperiod) { + set[i].tilt_min = set[i].tilt_start - shift; set[i].tilt_max = set[i].tilt_start; - } else if (delt < 0.5*set[i].tperiod) { + } else if (delt < 0.5 * set[i].tperiod) { set[i].tilt_min = set[i].tilt_start - set[i].amplitude; set[i].tilt_max = set[i].tilt_start; - } else if (delt < 0.75*set[i].tperiod) { + } else if (delt < 0.75 * set[i].tperiod) { set[i].tilt_min = set[i].tilt_start - set[i].amplitude; - set[i].tilt_max = set[i].tilt_start + - set[i].amplitude*sin(TWOPI*delt/set[i].tperiod); + set[i].tilt_max = set[i].tilt_start + shift; } else { set[i].tilt_min = set[i].tilt_start - set[i].amplitude; set[i].tilt_max = set[i].tilt_start + set[i].amplitude; @@ -729,25 +712,25 @@ void FixDeform::init() // this is b/c the flips would induce continuous changes in xz // in order to keep the edge vectors of the flipped shape matrix // an integer combination of the edge vectors of the unflipped shape matrix - // VARIABLE for yz is error, since no way to calculate if box flip occurs + // VARIABLE or PRESSURE for yz is error, since no way to calculate if box flip occurs // WIGGLE lo/hi flip test is on min/max oscillation limit, not tilt_stop // only trigger actual errors if flipflag is set if (set[3].style && set[5].style) { int flag = 0; double lo,hi; - if (flipflag && set[3].style == VARIABLE) - error->all(FLERR,"Fix deform cannot use yz variable with xy"); + if (flipflag && (set[3].style == VARIABLE || set[3].style == PRESSURE)) + error->all(FLERR,"Fix deform cannot use yz variable or pressure with xy"); if (set[3].style == WIGGLE) { lo = set[3].tilt_min; hi = set[3].tilt_max; } else lo = hi = set[3].tilt_stop; if (flipflag) { - if (lo/(set[1].hi_start-set[1].lo_start) < -0.5 || - hi/(set[1].hi_start-set[1].lo_start) > 0.5) flag = 1; + if (lo / (set[1].hi_start - set[1].lo_start) < -0.5 || + hi / (set[1].hi_start - set[1].lo_start) > 0.5) flag = 1; if (set[1].style) { - if (lo/(set[1].hi_stop-set[1].lo_stop) < -0.5 || - hi/(set[1].hi_stop-set[1].lo_stop) > 0.5) flag = 1; + if (lo / (set[1].hi_stop - set[1].lo_stop) < -0.5 || + hi / (set[1].hi_stop - set[1].lo_stop) > 0.5) flag = 1; } if (flag) error->all(FLERR,"Fix deform is changing yz too much with xy"); @@ -798,13 +781,11 @@ void FixDeform::init() if (pressure_flag) { int icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Temperature ID for fix deform does not exist"); + if (icompute < 0) error->all(FLERR,"Temperature ID for fix deform does not exist"); temperature = modify->compute[icompute]; icompute = modify->find_compute(id_press); - if (icompute < 0) - error->all(FLERR,"Pressure ID for fix deform does not exist"); + if (icompute < 0) error->all(FLERR,"Pressure ID for fix deform does not exist"); pressure = modify->compute[icompute]; } } @@ -816,7 +797,6 @@ void FixDeform::init() void FixDeform::setup(int /*vflag*/) { // trigger virial computation on next timestep - if (pressure_flag) pressure->addstep(update->ntimestep+1); } @@ -872,13 +852,10 @@ void FixDeform::end_of_step() temperature->compute_vector(); pressure->compute_vector(); for (int i = 0; i < 3; i++) { - if (! set[i].saved) { + if (!set[i].saved) { set[i].saved = 1; set[i].prior_rate = 0.0; set[i].prior_pressure = pressure->vector[i]; - if (i == 0) set[i].box_length = domain->xprd; - else if (i == 1) set[i].box_length = domain->yprd; - else set[i].box_length = domain->zprd; } } set_pressure(); @@ -892,15 +869,39 @@ void FixDeform::end_of_step() // Save pressure/strain rate if required if (pressure_flag) { - double dt_inv = 1.0 / update->dt; for (int i = 0; i < 3; i++) { set[i].prior_pressure = pressure->vector[i]; - set[i].prior_rate = ((set[i].hi_target - set[i].lo_target) / set[i].box_length - 1.0) * dt_inv; + set[i].prior_rate = ((set[i].hi_target - set[i].lo_target) / + (domain->boxhi[i] - domain->boxlo[i]) - 1.0) / update->dt; } } if (varflag) modify->addstep_compute(update->ntimestep + nevery); + // tilt_target can be large positive or large negative value + // add/subtract box lengths until tilt_target is closest to current value + + if (triclinic) { + double *h = domain->h; + for (int i = 3; i < 6; i++) { + int idenom = 0; + if (i == 5) idenom = 0; + else if (i == 4) idenom = 0; + else if (i == 3) idenom = 1; + double denom = set[idenom].hi_target - set[idenom].lo_target; + + double current = h[i] / h[idenom]; + + while (set[i].tilt_target / denom - current > 0.0) + set[i].tilt_target -= denom; + while (set[i].tilt_target / denom - current < 0.0) + set[i].tilt_target += denom; + if (fabs(set[i].tilt_target / denom - 1.0 - current) < + fabs(set[i].tilt_target / denom - current)) + set[i].tilt_target -= denom; + } + } + // if any tilt ratios exceed 0.5, set flip = 1 and compute new tilt values // do not flip in x or y if non-periodic (can tilt but not flip) // this is b/c the box length would be changed (dramatically) by flip @@ -915,12 +916,12 @@ void FixDeform::end_of_step() double yprd = set[1].hi_target - set[1].lo_target; double xprdinv = 1.0 / xprd; double yprdinv = 1.0 / yprd; - if (set[3].tilt_target*yprdinv < -0.5 || - set[3].tilt_target*yprdinv > 0.5 || - set[4].tilt_target*xprdinv < -0.5 || - set[4].tilt_target*xprdinv > 0.5 || - set[5].tilt_target*xprdinv < -0.5 || - set[5].tilt_target*xprdinv > 0.5) { + if (set[3].tilt_target * yprdinv < -0.5 || + set[3].tilt_target * yprdinv > 0.5 || + set[4].tilt_target * xprdinv < -0.5 || + set[4].tilt_target * xprdinv > 0.5 || + set[5].tilt_target * xprdinv < -0.5 || + set[5].tilt_target * xprdinv > 0.5) { set[3].tilt_flip = set[3].tilt_target; set[4].tilt_flip = set[4].tilt_target; set[5].tilt_flip = set[5].tilt_target; @@ -928,30 +929,30 @@ void FixDeform::end_of_step() flipxy = flipxz = flipyz = 0; if (domain->yperiodic) { - if (set[3].tilt_flip*yprdinv < -0.5) { + if (set[3].tilt_flip * yprdinv < -0.5) { set[3].tilt_flip += yprd; set[4].tilt_flip += set[5].tilt_flip; flipyz = 1; - } else if (set[3].tilt_flip*yprdinv > 0.5) { + } else if (set[3].tilt_flip * yprdinv > 0.5) { set[3].tilt_flip -= yprd; set[4].tilt_flip -= set[5].tilt_flip; flipyz = -1; } } if (domain->xperiodic) { - if (set[4].tilt_flip*xprdinv < -0.5) { + if (set[4].tilt_flip * xprdinv < -0.5) { set[4].tilt_flip += xprd; flipxz = 1; } - if (set[4].tilt_flip*xprdinv > 0.5) { + if (set[4].tilt_flip * xprdinv > 0.5) { set[4].tilt_flip -= xprd; flipxz = -1; } - if (set[5].tilt_flip*xprdinv < -0.5) { + if (set[5].tilt_flip * xprdinv < -0.5) { set[5].tilt_flip += xprd; flipxy = 1; } - if (set[5].tilt_flip*xprdinv > 0.5) { + if (set[5].tilt_flip * xprdinv > 0.5) { set[5].tilt_flip -= xprd; flipxy = -1; } @@ -1023,12 +1024,8 @@ void FixDeform::end_of_step() // trigger virial computation, if needed, on next timestep - if (pressure_flag) { + if (pressure_flag) pressure->addstep(update->ntimestep+1); - set[0].box_length = domain->xprd; - set[1].box_length = domain->yprd; - set[2].box_length = domain->zprd; - } } /* ---------------------------------------------------------------------- @@ -1052,36 +1049,31 @@ void FixDeform::set_strain() set[i].hi_target = domain->boxhi[i]; } else if (set[i].style == TRATE) { double delt = (update->ntimestep - update->beginstep) * update->dt; - set[i].lo_target = 0.5*(set[i].lo_start+set[i].hi_start) - - 0.5*((set[i].hi_start-set[i].lo_start) * exp(set[i].rate*delt)); - set[i].hi_target = 0.5*(set[i].lo_start+set[i].hi_start) + - 0.5*((set[i].hi_start-set[i].lo_start) * exp(set[i].rate*delt)); + double shift = 0.5 * ((set[i].hi_start - set[i].lo_start) * exp(set[i].rate * delt)); + set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; + set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; h_rate[i] = set[i].rate * domain->h[i]; - h_ratelo[i] = -0.5*h_rate[i]; + h_ratelo[i] = -0.5 * h_rate[i]; } else if (set[i].style == WIGGLE) { double delt = (update->ntimestep - update->beginstep) * update->dt; - set[i].lo_target = set[i].lo_start - - 0.5*set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); - set[i].hi_target = set[i].hi_start + - 0.5*set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); - h_rate[i] = TWOPI/set[i].tperiod * set[i].amplitude * - cos(TWOPI*delt/set[i].tperiod); - h_ratelo[i] = -0.5*h_rate[i]; + double shift = 0.5 * set[i].amplitude * sin(MY_2PI * delt / set[i].tperiod); + set[i].lo_target = set[i].lo_start - shift; + set[i].hi_target = set[i].hi_start + shift; + h_rate[i] = MY_2PI / set[i].tperiod * set[i].amplitude * + cos(MY_2PI * delt / set[i].tperiod); + h_ratelo[i] = -0.5 * h_rate[i]; } else if (set[i].style == VARIABLE) { double del = input->variable->compute_equal(set[i].hvar); - set[i].lo_target = set[i].lo_start - 0.5*del; - set[i].hi_target = set[i].hi_start + 0.5*del; + set[i].lo_target = set[i].lo_start - 0.5 * del; + set[i].hi_target = set[i].hi_start + 0.5 * del; h_rate[i] = input->variable->compute_equal(set[i].hratevar); - h_ratelo[i] = -0.5*h_rate[i]; + h_ratelo[i] = -0.5 * h_rate[i]; } else if (set[i].style != VOLUME) { - set[i].lo_target = set[i].lo_start + - delta*(set[i].lo_stop - set[i].lo_start); - set[i].hi_target = set[i].hi_start + - delta*(set[i].hi_stop - set[i].hi_start); + set[i].lo_target = set[i].lo_start + delta * (set[i].lo_stop - set[i].lo_start); + set[i].hi_target = set[i].hi_start + delta * (set[i].hi_stop - set[i].hi_start); } } - // for triclinic, set new box shape // for NONE, target is current tilt // for TRATE, set target directly based on current time. also set h_rate @@ -1099,41 +1091,21 @@ void FixDeform::set_strain() else if (i == 3) set[i].tilt_target = domain->yz; } else if (set[i].style == TRATE) { double delt = (update->ntimestep - update->beginstep) * update->dt; - set[i].tilt_target = set[i].tilt_start * exp(set[i].rate*delt); + set[i].tilt_target = set[i].tilt_start * exp(set[i].rate * delt); h_rate[i] = set[i].rate * domain->h[i]; } else if (set[i].style == WIGGLE) { double delt = (update->ntimestep - update->beginstep) * update->dt; set[i].tilt_target = set[i].tilt_start + - set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); - h_rate[i] = TWOPI/set[i].tperiod * set[i].amplitude * - cos(TWOPI*delt/set[i].tperiod); + set[i].amplitude * sin(MY_2PI * delt / set[i].tperiod); + h_rate[i] = MY_2PI / set[i].tperiod * set[i].amplitude * + cos(MY_2PI * delt / set[i].tperiod); } else if (set[i].style == VARIABLE) { double delta_tilt = input->variable->compute_equal(set[i].hvar); set[i].tilt_target = set[i].tilt_start + delta_tilt; h_rate[i] = input->variable->compute_equal(set[i].hratevar); } else { - set[i].tilt_target = set[i].tilt_start + - delta*(set[i].tilt_stop - set[i].tilt_start); + set[i].tilt_target = set[i].tilt_start + delta * (set[i].tilt_stop - set[i].tilt_start); } - - // tilt_target can be large positive or large negative value - // add/subtract box lengths until tilt_target is closest to current value - - int idenom = 0; - if (i == 5) idenom = 0; - else if (i == 4) idenom = 0; - else if (i == 3) idenom = 1; - double denom = set[idenom].hi_target - set[idenom].lo_target; - - double current = h[i]/h[idenom]; - - while (set[i].tilt_target/denom - current > 0.0) - set[i].tilt_target -= denom; - while (set[i].tilt_target/denom - current < 0.0) - set[i].tilt_target += denom; - if (fabs(set[i].tilt_target/denom - 1.0 - current) < - fabs(set[i].tilt_target/denom - current)) - set[i].tilt_target -= denom; } } } @@ -1156,7 +1128,7 @@ void FixDeform::set_pressure() double p_current[3]; if (pcouple == XYZ) { - double ave = 1.0/3.0 * (tensor[0] + tensor[1] + tensor[2]); + double ave = THIRD * (tensor[0] + tensor[1] + tensor[2]); p_current[0] = p_current[1] = p_current[2] = ave; } else if (pcouple == XY) { double ave = 0.5 * (tensor[0] + tensor[1]); @@ -1172,30 +1144,68 @@ void FixDeform::set_pressure() p_current[1] = tensor[1]; } else { if (set[0].style == PRESSURE) p_current[0] = tensor[0]; - else if (set[0].style == PISOTROPIC) p_current[0] = scalar; + else if (set[0].style == PMEAN) p_current[0] = scalar; if (set[1].style == PRESSURE) p_current[1] = tensor[1]; - else if (set[1].style == PISOTROPIC) p_current[1] = scalar; + else if (set[1].style == PMEAN) p_current[1] = scalar; if (set[2].style == PRESSURE) p_current[2] = tensor[2]; - else if (set[2].style == PISOTROPIC) p_current[2] = scalar; + else if (set[2].style == PMEAN) p_current[2] = scalar; } for (int i = 0; i < 3; i++) { - if (set[i].style != PRESSURE && set[i].style != PISOTROPIC) continue; - double dilation = 1.0 - update->dt * set[i].pgain * (set[i].ptarget - p_current[i]); - double center_start = 0.5 * (set[i].lo_start + set[i].hi_start); - double offset = 0.5 * set[i].box_length * dilation; - //printf("ptarget %g vs %g, dilation %g cs %g ofset %g box %g\n", set[i].ptarget, p_current[i], dilation, center_start, offset, set[i].box_length); - set[i].lo_target = center_start - offset; - set[i].hi_target = center_start + offset; + if (set[i].style != PRESSURE && set[i].style != PMEAN) continue; + + h_rate[i] = set[i].pgain * (p_current[i] - set[i].ptarget); + if (normalize_pressure_flag) { + if (set[i].ptarget == 0) { + if (max_h_rate == 0) { + error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); + } else h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); + } else h_rate[i] /= fabs(set[i].ptarget); + } + + if (max_h_rate != 0) + if (fabs(set[i].ptarget) > max_h_rate) + h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); + + double offset = 0.5 * (domain->boxhi[i] - domain->boxlo[i]) * (1.0 + update->dt * h_rate[i]); + set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - offset; + set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + offset; } for (int i = 3; i < 6; i++) { - double shift = update->dt * set[i].pgain * (set[i].ptarget - tensor[i]); - if (i == 3) set[i].tilt_target = domain->xy + shift * domain->xprd; - else if (i == 4) set[i].tilt_target = domain->xz + shift * domain->xprd; - else set[i].tilt_target = domain->yz + shift * domain->yprd; + if (set[i].style != PRESSURE) continue; + + double L, tilt, pcurrent; + if (i == 3) { + L = domain->zprd; + tilt = domain->yz; + pcurrent = tensor[5]; + } else if (i == 4) { + L = domain->zprd; + tilt = domain->xz + update->dt; + pcurrent = tensor[4]; + } else { + L = domain->yprd; + tilt = domain->xy; + pcurrent = tensor[3]; + } + + h_rate[i] = L * set[i].pgain * (pcurrent - set[i].ptarget); + if (normalize_pressure_flag) { + if (set[i].ptarget == 0) { + if (max_h_rate == 0) { + error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); + } else h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); + } else h_rate[i] /= fabs(set[i].ptarget); + } + + if (max_h_rate != 0) + if (fabs(h_rate[i]) > max_h_rate) + h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); + + set[i].tilt_target = tilt + update->dt * h_rate[i]; } } @@ -1211,61 +1221,65 @@ void FixDeform::set_volume() for (int i = 0; i < 3; i++) { if (set[i].style != VOLUME) continue; + int dynamic1 = set[i].dynamic1; + int dynamic2 = set[i].dynamic2; + int fixed = set[i].fixed; double v0 = set[i].vol_start; - double center_start = 0.5 * (set[i].lo_start + set[i].hi_start); - double offset; + double shift; if (set[i].substyle == ONE_FROM_ONE) { - offset = 0.5 * (v0 / - (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target) / - (set[set[i].fixed].hi_start-set[set[i].fixed].lo_start)); + shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / + (set[fixed].hi_start-set[fixed].lo_start)); } else if (set[i].substyle == ONE_FROM_TWO) { - offset = 0.5 * (v0 / - (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target) / - (set[set[i].dynamic2].hi_target - set[set[i].dynamic2].lo_target)); + shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / + (set[dynamic2].hi_target - set[dynamic2].lo_target)); } else if (set[i].substyle == TWO_FROM_ONE) { - if (!set[i].coupled_flag) { - offset = 0.5 * sqrt(v0 * (set[i].hi_start - set[i].lo_start) / - (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target) / - (set[set[i].fixed].hi_start - set[set[i].fixed].lo_start)); + if (!vol_balance_flag) { + shift = 0.5 * sqrt(v0 * (set[i].hi_start - set[i].lo_start) / + (set[dynamic1].hi_target - set[dynamic1].lo_target) / + (set[fixed].hi_start - set[fixed].lo_start)); } else { double dt = update->dt; double e1i = set[i].prior_rate; - double e2i = set[set[i].fixed].prior_rate; - double L3 = (set[set[i].dynamic1].hi_target - set[set[i].dynamic1].lo_target); - double e3 = (L3 / set[set[i].dynamic1].box_length - 1.0) / dt; + double e2i = set[fixed].prior_rate; + double L1i = domain->boxhi[i] - domain->boxlo[i]; + double L2i = domain->boxhi[fixed] - domain->boxlo[fixed]; + double L3i = domain->boxhi[dynamic1] - domain->boxlo[dynamic1]; + double L3 = (set[dynamic1].hi_target - set[dynamic1].lo_target); + double e3 = (L3 / L3i - 1.0) / dt; double p1 = pressure->vector[i]; - double p2 = pressure->vector[set[i].fixed]; + double p2 = pressure->vector[fixed]; double p1i = set[i].prior_pressure; - double p2i = set[set[i].fixed].prior_pressure; + double p2i = set[fixed].prior_pressure; if (e3 == 0) { e1 = 0.0; e2 = 0.0; - offset = 0.5 * set[i].box_length; + shift = 0.5 * L1i; } else if (e1i == 0 || e2i == 0 || (p2 == p2i && p1 == p1i)) { - // If no prior strain or no change in pressure (initial step) just scale offset by relative box lengths - offset = 0.5 * sqrt(v0 * set[i].box_length / L3 / set[set[i].fixed].box_length); + // If no prior strain or no change in pressure (initial step) just scale shift by relative box lengths + shift = 0.5 * sqrt(v0 * L1i / L3 / L2i); } else { - if (! linked_pressure) { - // Calculate first strain rate by expanding stress to linear order in strain to achieve p1(t+dt) = p2(t+dt) - e1 = -e3 / (1 + e3 * dt) * (p2 - p2i) - e2i * (p1 - p2); - e1 /= (p2 - p2i + (p1 - p1i) / e1i * e2i); - + if (!linked_pressure) { + // Calculate first strain rate by expanding stress to linear order, p1(t+dt) = p2(t+dt) // Calculate second strain rate to preserve volume - e2 = (1.0 - (1 + e3 * dt) * (1 + e1 * dt)); - e2 /= (1 + e3 * dt) * (1 + e1 * dt) * dt; + e1 = -e3 / (1 + e3 * dt) * (p2 - p2i) - e2i * (p1 - p2) / (p2 - p2i + (p1 - p1i) / e1i * e2i); + e2 = (1.0 - (1 + e3 * dt) * (1 + e1 * dt)) / ((1 + e3 * dt) * (1 + e1 * dt) * dt); - offset = 0.5 * set[i].box_length * (1.0 + e1 * dt); + shift = 0.5 * L1i * (1.0 + e1 * dt); linked_pressure = 1; } else { - offset = 0.5 * set[i].box_length * (1.0 + e2 * dt); + // Already calculated value of e2 + shift = 0.5 * L1i * (1.0 + e2 * dt); } } } } - set[i].lo_target = center_start - offset; - set[i].hi_target = center_start + offset; + + h_rate[i] = (2.0 * shift / (domain->boxhi[i] - domain->boxlo[i]) - 1.0) / update->dt; + + set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; + set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; } } @@ -1296,6 +1310,9 @@ void FixDeform::restart(char *buf) set[i].hi_initial = set_restart[i].hi_initial; set[i].vol_initial = set_restart[i].vol_initial; set[i].tilt_initial = set_restart[i].tilt_initial; + set[i].saved = set_restart[i].saved; + set[i].prior_rate = set_restart[i].prior_rate; + set[i].prior_pressure = set_restart[i].prior_pressure; // check if style settings are consistent (should do the whole set?) if (set[i].style != set_restart[i].style) samestyle = 0; @@ -1344,6 +1361,20 @@ void FixDeform::options(int narg, char **arg) else if (strcmp(arg[iarg+1],"none") == 0) pcouple = NOCOUPLE; else error->all(FLERR,"Illegal fix fix deform couple command: {}", arg[iarg+1]); iarg += 2; + } else if (strcmp(arg[iarg],"max/rate") == 0) { + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform max/rate", error); + max_h_rate = utils::numeric(FLERR,arg[iarg+1],false,lmp); + if (max_h_rate <= 0.0) + error->all(FLERR,"Maximum strain rate must be a positive, non-zero value"); + iarg += 2; + } else if (strcmp(arg[iarg],"normalize/pressure") == 0) { + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform normalize/pressure", error); + normalize_pressure_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); + iarg += 2; + } else if (strcmp(arg[iarg],"vol/balance/p") == 0) { + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform vol/balance/p", error); + vol_balance_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); + iarg += 2; } else error->all(FLERR,"Illegal fix deform command: {}", arg[iarg]); } @@ -1363,7 +1394,6 @@ double FixDeform::memory_usage() return bytes; } - /* ---------------------------------------------------------------------- */ int FixDeform::modify_param(int narg, char **arg) diff --git a/src/fix_deform.h b/src/fix_deform.h index 9ecb9a577d..eda97f7c90 100644 --- a/src/fix_deform.h +++ b/src/fix_deform.h @@ -44,17 +44,17 @@ class FixDeform : public Fix { protected: int dimension, triclinic, scaleflag, flipflag, pcouple; int flip, flipxy, flipxz, flipyz; - double *h_rate, *h_ratelo; + double *h_rate, *h_ratelo, max_h_rate; int varflag; // 1 if VARIABLE option is used, 0 if not int strain_flag; // 1 if strain-based option is used, 0 if not int volume_flag; // 1 if VOLUME option is used, 0 if not int pressure_flag; // 1 if pressure tensor used, 0 if not int kspace_flag; // 1 if KSpace invoked, 0 if not + int normalize_pressure_flag; // 1 if normalize pressure deviation by target + int vol_balance_flag; // 1 if pressures balanced when maintaining const vol std::vector rfix; // pointers to rigid fixes class Irregular *irregular; // for migrating atoms after box flips - double TWOPI; - char *id_temp, *id_press; class Compute *temperature, *pressure; int tflag, pflag; @@ -72,7 +72,6 @@ class FixDeform : public Fix { double vol_initial, vol_start; double ptarget, pgain; double prior_pressure, prior_rate; - double box_length; int saved; int fixed, dynamic1, dynamic2; char *hstr, *hratestr, *pstr; From 63618d249056b6008d34486301d841fa7bc47ccf Mon Sep 17 00:00:00 2001 From: jtclemm Date: Mon, 24 Oct 2022 10:59:22 -0600 Subject: [PATCH 004/185] Adding scalar pressure compute --- src/fix_deform.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index db3fad6a95..29c286ed02 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -851,6 +851,7 @@ void FixDeform::end_of_step() if (pressure_flag) { temperature->compute_vector(); pressure->compute_vector(); + pressure->compute_scalar(); for (int i = 0; i < 3; i++) { if (!set[i].saved) { set[i].saved = 1; @@ -1157,6 +1158,7 @@ void FixDeform::set_pressure() if (set[i].style != PRESSURE && set[i].style != PMEAN) continue; h_rate[i] = set[i].pgain * (p_current[i] - set[i].ptarget); + if (normalize_pressure_flag) { if (set[i].ptarget == 0) { if (max_h_rate == 0) { From 7160594902f74dd8cb5d88e85a96c1930df67cd0 Mon Sep 17 00:00:00 2001 From: Ludwig Ahrens-Iwers Date: Tue, 31 Jan 2023 07:39:31 +0000 Subject: [PATCH 005/185] Warning for mobile electrode atoms --- src/ELECTRODE/electrode_math.h | 1 + src/ELECTRODE/fix_electrode_conp.cpp | 26 ++- unittest/force-styles/tests/in.conp | 1 + .../tests/kspace-ewald_conp_charge.yaml | 159 +++++++-------- .../tests/kspace-pppm_conp_charge.yaml | 185 +++++++++--------- 5 files changed, 200 insertions(+), 172 deletions(-) diff --git a/src/ELECTRODE/electrode_math.h b/src/ELECTRODE/electrode_math.h index 5992df2289..08689a5adc 100644 --- a/src/ELECTRODE/electrode_math.h +++ b/src/ELECTRODE/electrode_math.h @@ -18,6 +18,7 @@ #ifndef LMP_ELECTRODE_MATH_H #define LMP_ELECTRODE_MATH_H +#include "math.h" #include "math_const.h" namespace LAMMPS_NS { diff --git a/src/ELECTRODE/fix_electrode_conp.cpp b/src/ELECTRODE/fix_electrode_conp.cpp index dbb508a033..33632f9099 100644 --- a/src/ELECTRODE/fix_electrode_conp.cpp +++ b/src/ELECTRODE/fix_electrode_conp.cpp @@ -377,6 +377,30 @@ void FixElectrodeConp::init() if (strncmp(modify->fix[i]->style, "electrode", 9) == 0) count++; if (count > 1) error->all(FLERR, "More than one fix electrode"); + // make sure electrode atoms are not integrated if a matrix is used for electrode-electrode interaction + int const nlocal = atom->nlocal; + int *mask = atom->mask; + Fix **fix = modify->fix; + if (matrix_algo) { + std::vector integrate_ids = std::vector(); + for (int i = 0; i < modify->nfix; i++) { + if (fix[i]->time_integrate == 0) continue; + int electrode_mover = 0; + int fix_groupbit = fix[i]->groupbit; + for (int j = 0; j < nlocal; j++) + if ((mask[j] & fix_groupbit) && (mask[j] & groupbit)) electrode_mover = 1; + MPI_Allreduce(MPI_IN_PLACE, &electrode_mover, 1, MPI_INT, MPI_SUM, world); + if (electrode_mover && comm->me == 0) integrate_ids.push_back(fix[i]->id); + } + if (comm->me == 0) + for (char *fix_id : integrate_ids) + error->warning( + FLERR, + "Electrode atoms are integrated by fix {}, but fix electrode is using a matrix method. For " + "mobile electrodes use the conjugate gradient algorithm without matrix ('algo cg').", + fix_id); + } + // check for package intel if (etypes_neighlists) request_etypes_neighlists(); @@ -863,7 +887,7 @@ void FixElectrodeConp::update_charges() update_time += MPI_Wtime() - start; } -std::vector FixElectrodeConp::ele_ele_interaction(const std::vector& q_local) +std::vector FixElectrodeConp::ele_ele_interaction(const std::vector &q_local) { assert(q_local.size() == nlocalele); assert(algo == Algo::CG || algo == Algo::MATRIX_CG); diff --git a/unittest/force-styles/tests/in.conp b/unittest/force-styles/tests/in.conp index 92d2f63cd1..08673ec20b 100644 --- a/unittest/force-styles/tests/in.conp +++ b/unittest/force-styles/tests/in.conp @@ -22,3 +22,4 @@ angle_coeff * group bot type 1 group top type 2 +group ele type 1 2 diff --git a/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml b/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml index 73fb252226..9a09a933a4 100644 --- a/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml +++ b/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml @@ -1,7 +1,7 @@ --- -lammps_version: 23 Jun 2022 +lammps_version: 3 Nov 2022 tags: generated -date_generated: Wed Sep 21 13:52:53 2022 +date_generated: Fri Dec 16 10:49:39 2022 epsilon: 1e-12 skip_tests: gpu kokkos_omp omp prerequisites: ! | @@ -17,6 +17,7 @@ post_commands: ! | kspace_modify gewald 0.23118 kspace_modify slab ew2d fix fxcpm bot electrode/conp -1.0 1.805 couple top 1.0 symm on + fix fxforce ele setforce 0 0 0 input_file: in.conp pair_style: coul/long 15.0 pair_coeff: ! | @@ -40,85 +41,85 @@ init_forces: ! |2 10 -3.3526564930579039e-02 -2.3802275431282884e-03 -1.5617801011657175e+00 11 -5.1236396351794389e-02 -4.9531100598979201e-04 -1.5779995894034005e+00 12 -3.3740693032952060e-02 -1.0210406243572182e-03 -1.5630986537874150e+00 - 13 -1.1437102611353016e-03 -4.6454866413029015e-05 5.4282837980149448e-03 - 14 2.3914999373115431e-03 -1.6478680244651469e-04 2.9802178734319239e-02 - 15 3.9287193302652786e-05 -2.5715673267285659e-05 2.8944525105129479e-03 - 16 2.0458480716482328e-03 -1.2119161321908735e-04 3.3689550843809452e-02 - 17 -2.7146073277767471e-03 -8.2376243258224663e-04 2.6564130941474612e-02 - 18 1.3669692885198135e-03 -4.2357196145489820e-04 3.2396141113926739e-02 - 19 3.0143371860819995e-04 -8.6218593339583785e-04 2.6284521141350669e-02 - 20 1.1542435168435056e-03 -2.7252318260838826e-04 3.4237916528138110e-02 - 21 -1.2350056952573553e-03 4.8655691135364269e-04 5.9284283442393631e-03 - 22 2.3656743884722890e-03 9.6575340844312705e-04 2.9811074931784823e-02 - 23 4.6754986244969657e-05 3.0149464050350903e-04 3.4630785686112129e-03 - 24 2.0301227080749633e-03 6.3879578068684812e-04 3.3653437189053413e-02 - 25 -2.3656211013513076e-03 -8.0454594828768334e-04 2.8476980555362911e-02 - 26 1.1566723797447039e-03 -3.9614599888570504e-04 3.2873323713155905e-02 - 27 2.8784994028036400e-04 -8.3661697184444898e-04 2.8317655886021253e-02 - 28 9.3882364605486020e-04 -2.3327601777843495e-04 3.4334676606415648e-02 - 29 -4.7969977052124917e-04 -1.2933334305373028e-04 -1.2336987392568071e-02 - 30 6.4733118786851766e-05 -1.3190918849005797e-04 -1.2737933567178844e-02 - 31 2.4269094157913586e-04 -1.3093943526788584e-04 -1.2136133260085013e-02 - 32 1.7452552740941527e-04 -1.1792779046242341e-04 -1.4181538324619835e-02 - 33 -3.8366266481516803e-04 -7.1061854758754556e-05 -1.3699106365426135e-02 - 34 2.8849004082563746e-05 -5.7838605310673531e-05 -1.3764181266896890e-02 - 35 2.2648059665862587e-04 -7.2851385190891320e-05 -1.3537361892926607e-02 - 36 1.2929221129083645e-04 -4.2862960950045859e-05 -1.4926105930886896e-02 - 37 -4.7698025941707008e-04 2.9971529466656788e-04 -1.2393604822896313e-02 - 38 6.4231095731188766e-05 2.7548977518460050e-04 -1.2789498345723021e-02 - 39 2.4169204779864826e-04 3.0552093685810269e-04 -1.2193908285665961e-02 - 40 1.7324998349441456e-04 2.2898000918153004e-04 -1.4225267020837207e-02 - 41 -3.4345772150395188e-04 -9.8012060153887415e-05 -1.4482722052972283e-02 - 42 2.0345466940577010e-05 -8.5250083485342566e-05 -1.4497101004472062e-02 - 43 2.0917627239292995e-04 -1.0051271468149899e-04 -1.4335313646556430e-02 - 44 1.1456796622437295e-04 -6.7553675788598551e-05 -1.5543196158604005e-02 + 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 16 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 17 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 30 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 31 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 32 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 33 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 34 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 35 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 36 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 37 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 38 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 39 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 40 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 41 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 42 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 44 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_vdwl: 0 -run_coul: 6.662694629990089 +run_coul: 6.662694556930399 run_stress: ! |2- 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_forces: ! |2 - 1 2.4590612609445102e-04 1.9614041218568861e-03 3.0874291949281147e+00 - 2 -1.6646393233505193e-02 2.1136941574790400e-03 3.0751132981100078e+00 - 3 6.3535217476586373e-04 5.1012487117746350e-03 3.0897301317927290e+00 - 4 -1.6598677148313409e-02 6.0535154567108685e-03 3.0778495346381409e+00 - 5 4.2257888534896988e-02 -2.3028533365965051e-03 -1.5593100596807521e+00 - 6 5.5690508027606708e-02 -2.4104721624763235e-03 -1.5626897542440843e+00 - 7 4.2243973130370149e-02 -7.6153220413259775e-04 -1.5604618260035832e+00 - 8 5.5862703939049158e-02 -9.9825803703216718e-04 -1.5640031014325448e+00 - 9 -5.1059409954744304e-02 -2.3195553026588347e-03 -1.5701677851024036e+00 - 10 -3.3824298857146967e-02 -2.3375522139358631e-03 -1.5551647619109401e+00 - 11 -5.1334079184640377e-02 -5.0583705005136689e-04 -1.5712298444761112e+00 - 12 -3.4037363466305925e-02 -1.0275978089057873e-03 -1.5564691026885336e+00 - 13 -1.1767076011504501e-03 -4.7681963272732406e-05 5.6177800544716262e-03 - 14 2.3826294437743331e-03 -1.6349140124449633e-04 2.9836275824428962e-02 - 15 4.1635367214843796e-05 -2.7287283914685102e-05 3.0967012748694773e-03 - 16 2.0334138778396313e-03 -1.1986039772787527e-04 3.3679727731055195e-02 - 17 -2.7026084826568797e-03 -8.1815079485725360e-04 2.6574868248546435e-02 - 18 1.3603406762441243e-03 -4.1902595052936860e-04 3.2373613783594497e-02 - 19 2.9940467686436986e-04 -8.5646794759970863e-04 2.6296909514905095e-02 - 20 1.1469475577225402e-03 -2.6907093945665336e-04 3.4197589258157073e-02 - 21 -1.2662578686531134e-03 4.9770031968890231e-04 6.1141650873547037e-03 - 22 2.3568409810395020e-03 9.5671841592085381e-04 2.9844352492872490e-02 - 23 4.8965507374742117e-05 3.1616579858329929e-04 3.6613180489820005e-03 - 24 2.0177821554069170e-03 6.3083810187911310e-04 3.3643353017422439e-02 - 25 -2.3537455003017457e-03 -7.9846295760147956e-04 2.8468250829639500e-02 - 26 1.1507655048236000e-03 -3.9159985067612060e-04 3.2839870487003708e-02 - 27 2.8582562554448814e-04 -8.3038492818152999e-04 2.8309777443009273e-02 - 28 9.3274285761092680e-04 -2.2997823984283208e-04 3.4287630335266286e-02 - 29 -4.7502414048888327e-04 -1.2847214455389489e-04 -1.2453998829891042e-02 - 30 6.3675154563755000e-05 -1.3104204562344653e-04 -1.2848240218511071e-02 - 31 2.4068203429808906e-04 -1.3007692195448562e-04 -1.2254443488117142e-02 - 32 1.7286880375665112e-04 -1.1713944254614034e-04 -1.4279748536149278e-02 - 33 -3.7975304094097439e-04 -7.0481503989778179e-05 -1.3805675914786045e-02 - 34 2.8172580422574018e-05 -5.7414812953860394e-05 -1.3867744309035916e-02 - 35 2.2448042926710853e-04 -7.2258368796568220e-05 -1.3645037267085249e-02 - 36 1.2804302797390986e-04 -4.2547023166907131e-05 -1.5019384166440140e-02 - 37 -4.7231656130619122e-04 2.9759414220405656e-04 -1.2510308090752414e-02 - 38 6.3181133759042352e-05 2.7366531591578288e-04 -1.2899551129187765e-02 - 39 2.3968383978790597e-04 3.0338116638639894e-04 -1.2311919409216509e-02 - 40 1.7159804905743131e-04 2.2744508340904917e-04 -1.4323246783684936e-02 - 41 -3.3986046011853923e-04 -9.7274166717457145e-05 -1.4583591616566860e-02 - 42 1.9775995840422978e-05 -8.4675117269364898e-05 -1.4595729099929700e-02 - 43 2.0725822207231137e-04 -9.9764702521265135e-05 -1.4437236974797743e-02 - 44 1.1345006523014360e-04 -6.7103771021504086e-05 -1.5632251527466189e-02 + 1 2.4590683616589461e-04 1.9614031577863586e-03 3.0874292323214023e+00 + 2 -1.6646391056109371e-02 2.1136931488457949e-03 3.0751133344119812e+00 + 3 6.3535284261970041e-04 5.1012486499622143e-03 3.0897301693141319e+00 + 4 -1.6598674977089525e-02 6.0535154273403009e-03 3.0778495712965137e+00 + 5 4.2257890248609424e-02 -2.3028528771735519e-03 -1.5593100743454233e+00 + 6 5.5690508840794913e-02 -2.4104716736065191e-03 -1.5626897684026875e+00 + 7 4.2243974848895624e-02 -7.6153214117135259e-04 -1.5604618407191599e+00 + 8 5.5862704771247232e-02 -9.9825804058303641e-04 -1.5640031157582626e+00 + 9 -5.1059412079591339e-02 -2.3195548367148278e-03 -1.5701677996288432e+00 + 10 -3.3824301875619064e-02 -2.3375517362836449e-03 -1.5551647759943841e+00 + 11 -5.1334081278836839e-02 -5.0583707575588808e-04 -1.5712298590599834e+00 + 12 -3.4037366496628307e-02 -1.0275977984217531e-03 -1.5564691169384570e+00 + 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 16 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 17 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 30 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 31 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 32 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 33 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 34 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 35 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 36 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 37 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 38 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 39 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 40 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 41 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 42 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 44 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 ... diff --git a/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml b/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml index 84148fc816..9322cae321 100644 --- a/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml +++ b/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml @@ -1,7 +1,7 @@ --- -lammps_version: 23 Jun 2022 +lammps_version: 3 Nov 2022 tags: generated -date_generated: Wed Sep 21 13:52:39 2022 +date_generated: Fri Dec 16 10:53:11 2022 epsilon: 3e-12 skip_tests: gpu kokkos_omp omp prerequisites: ! | @@ -17,6 +17,7 @@ post_commands: ! | kspace_modify gewald 0.23118 kspace_modify slab 3.0 fix fxcpm bot electrode/conp -1.0 1.805 couple top 1.0 symm on + fix fxforce ele setforce 0 0 0 input_file: in.conp pair_style: coul/long 15.0 pair_coeff: ! | @@ -24,101 +25,101 @@ pair_coeff: ! | extract: ! "" natoms: 44 init_vdwl: 0 -init_coul: 2.2156402256727614 +init_coul: 2.2156402256727743 init_stress: ! |2- 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 init_forces: ! |2 - 1 2.0996096688279944e-04 1.9837586784580306e-03 3.1004822661058822e+00 - 2 -1.6783332510617883e-02 2.1368843599407611e-03 3.0880130470329230e+00 - 3 6.0300296042517466e-04 5.1688381279905342e-03 3.1028182137891114e+00 - 4 -1.6735061532950901e-02 6.1290626039690339e-03 3.0907879891042755e+00 - 5 4.2014131860757913e-02 -2.3478381081742388e-03 -1.5658874682481487e+00 - 6 5.5659823770659422e-02 -2.4566144388410410e-03 -1.5693278833316506e+00 - 7 4.1999624791768865e-02 -7.5066218795240259e-04 -1.5670569809441617e+00 - 8 5.5832732887661884e-02 -9.8883264742169940e-04 -1.5706605160409139e+00 - 9 -5.0976953599115804e-02 -2.3653810185280950e-03 -1.5768945194236066e+00 - 10 -3.3513771125456657e-02 -2.3824712764543426e-03 -1.5616806812004886e+00 - 11 -5.1253442064492741e-02 -4.9304425051529275e-04 -1.5779738349804424e+00 - 12 -3.3727836471637192e-02 -1.0188844490582761e-03 -1.5630041309277038e+00 - 13 -1.1453068449918257e-03 -4.7335833322794788e-05 5.4292779404649470e-03 - 14 2.3900993287279790e-03 -1.6878550058260119e-04 2.9808528147740175e-02 - 15 4.0078428215627730e-05 -2.6184607051201481e-05 2.8941780231019881e-03 - 16 2.0473353699190459e-03 -1.2552209515766962e-04 3.3684989110502959e-02 - 17 -2.7210216747431955e-03 -8.2349543008294359e-04 2.6567504438257068e-02 - 18 1.3656002828979516e-03 -4.2323438710338486e-04 3.2404938547366383e-02 - 19 3.0785575286292939e-04 -8.6186674263511191e-04 2.6288541663855129e-02 - 20 1.1555469330548321e-03 -2.7230960410720359e-04 3.4235148032534163e-02 - 21 -1.2368093613861506e-03 4.8760847861882366e-04 5.9296798954256557e-03 - 22 2.3643140421916085e-03 9.6975102599399746e-04 2.9817231402721564e-02 - 23 4.7705653522709085e-05 3.0203836842154655e-04 3.4631818106649337e-03 - 24 2.0316297431160258e-03 6.4335031755788927e-04 3.3648629802522749e-02 - 25 -2.3728144718995455e-03 -8.0497592536520339e-04 2.8474707915345274e-02 - 26 1.1555985481661916e-03 -3.9649433660109970e-04 3.2876098209196375e-02 - 27 2.9459292459149998e-04 -8.3700881746301306e-04 2.8316136079038545e-02 - 28 9.4027352090446912e-04 -2.3371025598546553e-04 3.4325153603153732e-02 - 29 -5.2133856931286127e-04 -1.4498587872629142e-04 -1.2345168780426297e-02 - 30 7.0344538924238829e-05 -1.4805754895657979e-04 -1.2765142487049358e-02 - 31 2.7857644686035687e-04 -1.4667349483298643e-04 -1.2140095836769501e-02 - 32 1.7479865631996218e-04 -1.3335074368636031e-04 -1.4152171307753206e-02 - 33 -4.2607366742485959e-04 -7.2661709209033136e-05 -1.3713642029394900e-02 - 34 3.4224570995904750e-05 -5.9352423088202727e-05 -1.3797063100154012e-02 - 35 2.6332638434852483e-04 -7.4573909050170201e-05 -1.3548481212572565e-02 - 36 1.2956589882656260e-04 -4.4469640559387641e-05 -1.4903750420442119e-02 - 37 -5.1855202137555164e-04 3.1768672664149645e-04 -1.2402413876588990e-02 - 38 6.9744637010106164e-05 2.9379923413403201e-04 -1.2817238930047764e-02 - 39 2.7753815671547851e-04 3.2364879063853462e-04 -1.2198687630220518e-02 - 40 1.7359211286247436e-04 2.4661766514410969e-04 -1.4196607980261094e-02 - 41 -3.8501793941197521e-04 -9.8818538537990245e-05 -1.4472863167957050e-02 - 42 2.5779944975443997e-05 -8.5975255466014692e-05 -1.4504933662725301e-02 - 43 2.4535595442148292e-04 -1.0127263490049206e-04 -1.4321758087878972e-02 - 44 1.1457678622968817e-04 -6.8200688092186871e-05 -1.5499407046729242e-02 + 1 2.0996096688278619e-04 1.9837586784579742e-03 3.1004822661058862e+00 + 2 -1.6783332510618001e-02 2.1368843599407208e-03 3.0880130470329266e+00 + 3 6.0300296042516458e-04 5.1688381279906756e-03 3.1028182137891149e+00 + 4 -1.6735061532951023e-02 6.1290626039691648e-03 3.0907879891042778e+00 + 5 4.2014131860757892e-02 -2.3478381081742106e-03 -1.5658874682481501e+00 + 6 5.5659823770659464e-02 -2.4566144388410275e-03 -1.5693278833316524e+00 + 7 4.1999624791768830e-02 -7.5066218795246862e-04 -1.5670569809441637e+00 + 8 5.5832732887661912e-02 -9.8883264742175101e-04 -1.5706605160409157e+00 + 9 -5.0976953599115776e-02 -2.3653810185280764e-03 -1.5768945194236081e+00 + 10 -3.3513771125456580e-02 -2.3824712764543249e-03 -1.5616806812004898e+00 + 11 -5.1253442064492706e-02 -4.9304425051534804e-04 -1.5779738349804435e+00 + 12 -3.3727836471637108e-02 -1.0188844490583379e-03 -1.5630041309277052e+00 + 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 16 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 17 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 30 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 31 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 32 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 33 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 34 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 35 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 36 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 37 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 38 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 39 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 40 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 41 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 42 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 44 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_vdwl: 0 -run_coul: 6.662844717848837 +run_coul: 6.662844644802018 run_stress: ! |2- 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_forces: ! |2 - 1 2.4838374656870440e-04 1.9503798034564181e-03 3.0873204052231675e+00 - 2 -1.6652792550963507e-02 2.1026197438206527e-03 3.0749612313228378e+00 - 3 6.3785681925848106e-04 5.1125747842690368e-03 3.0896293583134606e+00 - 4 -1.6605065971975488e-02 6.0649203428150876e-03 3.0777057441315305e+00 - 5 4.2242720963296274e-02 -2.3050719334346786e-03 -1.5592361839228894e+00 - 6 5.5714272244614366e-02 -2.4127241272198356e-03 -1.5626351053810128e+00 - 7 4.2228744507856318e-02 -7.5938680980830215e-04 -1.5603926173148708e+00 - 8 5.5886400463161408e-02 -9.9610508394880446e-04 -1.5639532943562677e+00 - 9 -5.1076260774663269e-02 -2.3218376339398856e-03 -1.5701372580807029e+00 - 10 -3.3811558405906099e-02 -2.3397301017438945e-03 -1.5550660295253020e+00 - 11 -5.1350900750795785e-02 -5.0363945411724615e-04 -1.5712039970018119e+00 - 12 -3.4024561045577786e-02 -1.0255079139096881e-03 -1.5563752017113657e+00 - 13 -1.1783355827329363e-03 -4.8584425213699084e-05 5.6187810005819084e-03 - 14 2.3812433011153062e-03 -1.6745821939573657e-04 2.9842604329757397e-02 - 15 4.2472634867315832e-05 -2.7784504406519571e-05 3.0964622176844602e-03 - 16 2.0348857368272344e-03 -1.2415016403438035e-04 3.3675205082768264e-02 - 17 -2.7089567432503573e-03 -8.1788662401764114e-04 2.6578231998707000e-02 - 18 1.3589859834844708e-03 -4.1869284075205220e-04 3.2382362625908642e-02 - 19 3.0575998684987288e-04 -8.5615261685325662e-04 2.6300918365183709e-02 - 20 1.1482382726252934e-03 -2.6885864047674810e-04 3.4194853807722227e-02 - 21 -1.2680891310638792e-03 4.9877122346546224e-04 6.1154164862940522e-03 - 22 2.3554944751877239e-03 9.6068685589809240e-04 2.9850487598267021e-02 - 23 4.9959016556344255e-05 3.1673714227676154e-04 3.6614479955528112e-03 - 24 2.0192733259603224e-03 6.3534849028298586e-04 3.3638585635455770e-02 - 25 -2.3608563352120440e-03 -7.9888874314704573e-04 2.8465994834953420e-02 - 26 1.1497012824588045e-03 -3.9194609517719160e-04 3.2842627585052867e-02 - 27 2.9249325092285189e-04 -8.3077344407106490e-04 2.8308269755484061e-02 - 28 9.3417705968603434e-04 -2.3040781495046246e-04 3.4278191255128133e-02 - 29 -5.1652528928022433e-04 -1.4404353042683099e-04 -1.2462150875064196e-02 - 30 6.9288940488795056e-05 -1.4710788156542239e-04 -1.2875332550432134e-02 - 31 2.7644608312646314e-04 -1.4573040212804145e-04 -1.2258366148270420e-02 - 32 1.7312052380602741e-04 -1.3246895843787418e-04 -1.4250473428514749e-02 - 33 -4.2201273060055557e-04 -7.2075937985441126e-05 -1.3820153961237609e-02 - 34 3.3549241776445280e-05 -5.8924381188893540e-05 -1.3900492261623465e-02 - 35 2.6119063773180797e-04 -7.3975274656908229e-05 -1.3656086631368676e-02 - 36 1.2829798186810219e-04 -4.4146305074977061e-05 -1.4997087695938056e-02 - 37 -5.1375024459660446e-04 3.1547360096919003e-04 -1.2519087424517190e-02 - 38 6.8697062203298403e-05 2.9188411177715840e-04 -1.2927175328444108e-02 - 39 2.7540798890579723e-04 3.2141722701930868e-04 -1.2316658300695350e-02 - 40 1.7191884579607650e-04 2.4497453169432579e-04 -1.4294679585099376e-02 - 41 -3.8125358429239129e-04 -9.8073404256391242e-05 -1.4573806404289218e-02 - 42 2.5208712883704254e-05 -8.5394829999053783e-05 -1.4603558816163261e-02 - 43 2.4329125095209453e-04 -1.0051714757303402e-04 -1.4423743772053488e-02 - 44 1.1343880007511943e-04 -6.7742613833467660e-05 -1.5588639087563531e-02 + 1 2.4838446863948484e-04 1.9503788466162767e-03 3.0873204426106526e+00 + 2 -1.6652790386576983e-02 2.1026187422225470e-03 3.0749612676149027e+00 + 3 6.3785749905503929e-04 5.1125747155211223e-03 3.0896293958296615e+00 + 4 -1.6605063813844967e-02 6.0649203065202420e-03 3.0777057807809554e+00 + 5 4.2242722672783783e-02 -2.3050714764837449e-03 -1.5592361985876177e+00 + 6 5.5714273062644280e-02 -2.4127236407636868e-03 -1.5626351195306318e+00 + 7 4.2228746222139874e-02 -7.5938674438442175e-04 -1.5603926320308752e+00 + 8 5.5886401300220823e-02 -9.9610508505007457e-04 -1.5639533086735800e+00 + 9 -5.1076262902731109e-02 -2.3218371704875071e-03 -1.5701372726008265e+00 + 10 -3.3811561421032664e-02 -2.3397296264742753e-03 -1.5550660436064545e+00 + 11 -5.1350902848165472e-02 -5.0363947736730796e-04 -1.5712040115797643e+00 + 12 -3.4024564072498598e-02 -1.0255079009805080e-03 -1.5563752159595892e+00 + 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 16 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 17 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 30 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 31 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 32 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 33 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 34 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 35 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 36 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 37 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 38 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 39 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 40 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 41 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 42 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 44 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 ... From 7d8866891a67878c001e292a21527bb750f7d964 Mon Sep 17 00:00:00 2001 From: Ludwig Ahrens Date: Wed, 1 Feb 2023 10:15:11 +0100 Subject: [PATCH 006/185] Call particle_map in compute of pppm/electrode --- src/ELECTRODE/pppm_electrode.cpp | 137 +++++++++++++++---------------- 1 file changed, 68 insertions(+), 69 deletions(-) diff --git a/src/ELECTRODE/pppm_electrode.cpp b/src/ELECTRODE/pppm_electrode.cpp index 7418a052e6..3bc1364c99 100644 --- a/src/ELECTRODE/pppm_electrode.cpp +++ b/src/ELECTRODE/pppm_electrode.cpp @@ -445,6 +445,7 @@ void PPPMElectrode::compute(int eflag, int vflag) start_compute(); + /* if (compute_vector_called && last_invert_source) { // electrolyte_density_brick is filled, so we can grab only electrode atoms. // Does not work for direct cg algorithm because electrode charges change after compute_vector. @@ -460,15 +461,17 @@ void PPPMElectrode::compute(int eflag, int vflag) density_brick[nz][ny][nx] += electrolyte_density_brick[nz][ny][nx]; } } else { - make_rho(); + */ + particle_map(); + make_rho(); - // all procs communicate density values from their ghost cells - // to fully sum contribution in their 3d bricks - // remap from 3d decomposition to FFT decomposition + // all procs communicate density values from their ghost cells + // to fully sum contribution in their 3d bricks + // remap from 3d decomposition to FFT decomposition - gc->reverse_comm(Grid3d::KSPACE, this, REVERSE_RHO, 1, sizeof(FFT_SCALAR), gc_buf1, gc_buf2, - MPI_FFT_SCALAR); - } + gc->reverse_comm(Grid3d::KSPACE, this, REVERSE_RHO, 1, sizeof(FFT_SCALAR), gc_buf1, gc_buf2, + MPI_FFT_SCALAR); + //} brick2fft(); @@ -591,6 +594,7 @@ void PPPMElectrode::compute_vector(double *vec, int sensor_grpbit, int source_gr // electrolyte density (without writing an additional function) FFT_SCALAR ***density_brick_real = density_brick; FFT_SCALAR *density_fft_real = density_fft; + particle_map(); make_rho_in_brick(source_grpbit, electrolyte_density_brick, invert_source); density_brick = electrolyte_density_brick; density_fft = electrolyte_density_fft; @@ -674,7 +678,8 @@ void PPPMElectrode::compute_matrix(bigint *imat, double **matrix, bool timer_fla // fft green's function k -> r (double) double *greens_real; memory->create(greens_real, nz_pppm * ny_pppm * nx_pppm, "pppm/electrode:greens_real"); - memset(greens_real, 0, (std::size_t)nz_pppm * (std::size_t)ny_pppm * (std::size_t)nx_pppm * sizeof(double)); + memset(greens_real, 0, + (std::size_t) nz_pppm * (std::size_t) ny_pppm * (std::size_t) nx_pppm * sizeof(double)); for (int i = 0, n = 0; i < nfft; i++) { work2[n++] = greensfn[i]; work2[n++] = ZEROF; @@ -867,7 +872,7 @@ void PPPMElectrode::two_step_multiplication(bigint *imat, double *greens_real, d double **gw; memory->create(gw, nmat, nxyz, "pppm/electrode:gw"); - memset(&(gw[0][0]), 0, (std::size_t)nmat * (std::size_t)nxyz * sizeof(double)); + memset(&(gw[0][0]), 0, (std::size_t) nmat * (std::size_t) nxyz * sizeof(double)); auto fmod = [](int x, int n) { // fast unsigned mod int r = abs(x); @@ -986,17 +991,18 @@ void PPPMElectrode::allocate() // returns local owned and ghost grid bounds // setup communication patterns and buffers - gc = new Grid3d(lmp,world,nx_pppm,ny_pppm,nz_pppm, - nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in, - nxlo_out,nxhi_out,nylo_out,nyhi_out,nzlo_out,nzhi_out); + gc = new Grid3d(lmp, world, nx_pppm, ny_pppm, nz_pppm, nxlo_in, nxhi_in, nylo_in, nyhi_in, + nzlo_in, nzhi_in, nxlo_out, nxhi_out, nylo_out, nyhi_out, nzlo_out, nzhi_out); - gc->setup_comm(ngc_buf1,ngc_buf2); + gc->setup_comm(ngc_buf1, ngc_buf2); - if (differentiation_flag) npergrid = 1; - else npergrid = 3; + if (differentiation_flag) + npergrid = 1; + else + npergrid = 3; - memory->create(gc_buf1,npergrid*ngc_buf1,"pppm:gc_buf1"); - memory->create(gc_buf2,npergrid*ngc_buf2,"pppm:gc_buf2"); + memory->create(gc_buf1, npergrid * ngc_buf1, "pppm:gc_buf1"); + memory->create(gc_buf2, npergrid * ngc_buf2, "pppm:gc_buf2"); // tally local grid sizes // ngrid = count of owned+ghost grid cells on this proc @@ -1005,67 +1011,63 @@ void PPPMElectrode::allocate() // nfft = FFT points in x-pencil FFT decomposition on this proc // nfft_both = greater of nfft and nfft_brick - ngrid = (nxhi_out-nxlo_out+1) * (nyhi_out-nylo_out+1) * - (nzhi_out-nzlo_out+1); + ngrid = (nxhi_out - nxlo_out + 1) * (nyhi_out - nylo_out + 1) * (nzhi_out - nzlo_out + 1); - nfft_brick = (nxhi_in-nxlo_in+1) * (nyhi_in-nylo_in+1) * - (nzhi_in-nzlo_in+1); + nfft_brick = (nxhi_in - nxlo_in + 1) * (nyhi_in - nylo_in + 1) * (nzhi_in - nzlo_in + 1); - nfft = (nxhi_fft-nxlo_fft+1) * (nyhi_fft-nylo_fft+1) * - (nzhi_fft-nzlo_fft+1); + nfft = (nxhi_fft - nxlo_fft + 1) * (nyhi_fft - nylo_fft + 1) * (nzhi_fft - nzlo_fft + 1); - nfft_both = MAX(nfft,nfft_brick); + nfft_both = MAX(nfft, nfft_brick); // allocate distributed grid data - memory->create3d_offset(density_brick,nzlo_out,nzhi_out,nylo_out,nyhi_out, - nxlo_out,nxhi_out,"pppm:density_brick"); + memory->create3d_offset(density_brick, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out, nxhi_out, + "pppm:density_brick"); - memory->create(density_fft,nfft_both,"pppm:density_fft"); - memory->create(greensfn,nfft_both,"pppm:greensfn"); - memory->create(work1,2*nfft_both,"pppm:work1"); - memory->create(work2,2*nfft_both,"pppm:work2"); - memory->create(vg,nfft_both,6,"pppm:vg"); + memory->create(density_fft, nfft_both, "pppm:density_fft"); + memory->create(greensfn, nfft_both, "pppm:greensfn"); + memory->create(work1, 2 * nfft_both, "pppm:work1"); + memory->create(work2, 2 * nfft_both, "pppm:work2"); + memory->create(vg, nfft_both, 6, "pppm:vg"); if (triclinic == 0) { - memory->create1d_offset(fkx,nxlo_fft,nxhi_fft,"pppm:fkx"); - memory->create1d_offset(fky,nylo_fft,nyhi_fft,"pppm:fky"); - memory->create1d_offset(fkz,nzlo_fft,nzhi_fft,"pppm:fkz"); + memory->create1d_offset(fkx, nxlo_fft, nxhi_fft, "pppm:fkx"); + memory->create1d_offset(fky, nylo_fft, nyhi_fft, "pppm:fky"); + memory->create1d_offset(fkz, nzlo_fft, nzhi_fft, "pppm:fkz"); } else { - memory->create(fkx,nfft_both,"pppm:fkx"); - memory->create(fky,nfft_both,"pppm:fky"); - memory->create(fkz,nfft_both,"pppm:fkz"); + memory->create(fkx, nfft_both, "pppm:fkx"); + memory->create(fky, nfft_both, "pppm:fky"); + memory->create(fkz, nfft_both, "pppm:fkz"); } if (differentiation_flag == 1) { - memory->create3d_offset(u_brick,nzlo_out,nzhi_out,nylo_out,nyhi_out, - nxlo_out,nxhi_out,"pppm:u_brick"); + memory->create3d_offset(u_brick, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out, nxhi_out, + "pppm:u_brick"); - memory->create(sf_precoeff1,nfft_both,"pppm:sf_precoeff1"); - memory->create(sf_precoeff2,nfft_both,"pppm:sf_precoeff2"); - memory->create(sf_precoeff3,nfft_both,"pppm:sf_precoeff3"); - memory->create(sf_precoeff4,nfft_both,"pppm:sf_precoeff4"); - memory->create(sf_precoeff5,nfft_both,"pppm:sf_precoeff5"); - memory->create(sf_precoeff6,nfft_both,"pppm:sf_precoeff6"); + memory->create(sf_precoeff1, nfft_both, "pppm:sf_precoeff1"); + memory->create(sf_precoeff2, nfft_both, "pppm:sf_precoeff2"); + memory->create(sf_precoeff3, nfft_both, "pppm:sf_precoeff3"); + memory->create(sf_precoeff4, nfft_both, "pppm:sf_precoeff4"); + memory->create(sf_precoeff5, nfft_both, "pppm:sf_precoeff5"); + memory->create(sf_precoeff6, nfft_both, "pppm:sf_precoeff6"); } else { - memory->create3d_offset(vdx_brick,nzlo_out,nzhi_out,nylo_out,nyhi_out, - nxlo_out,nxhi_out,"pppm:vdx_brick"); - memory->create3d_offset(vdy_brick,nzlo_out,nzhi_out,nylo_out,nyhi_out, - nxlo_out,nxhi_out,"pppm:vdy_brick"); - memory->create3d_offset(vdz_brick,nzlo_out,nzhi_out,nylo_out,nyhi_out, - nxlo_out,nxhi_out,"pppm:vdz_brick"); + memory->create3d_offset(vdx_brick, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out, nxhi_out, + "pppm:vdx_brick"); + memory->create3d_offset(vdy_brick, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out, nxhi_out, + "pppm:vdy_brick"); + memory->create3d_offset(vdz_brick, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out, nxhi_out, + "pppm:vdz_brick"); } // summation coeffs order_allocated = order; - if (!stagger_flag) memory->create(gf_b,order,"pppm:gf_b"); - memory->create2d_offset(rho1d,3,-order/2,order/2,"pppm:rho1d"); - memory->create2d_offset(drho1d,3,-order/2,order/2,"pppm:drho1d"); - memory->create2d_offset(rho_coeff,order,(1-order)/2,order/2,"pppm:rho_coeff"); - memory->create2d_offset(drho_coeff,order,(1-order)/2,order/2, - "pppm:drho_coeff"); + if (!stagger_flag) memory->create(gf_b, order, "pppm:gf_b"); + memory->create2d_offset(rho1d, 3, -order / 2, order / 2, "pppm:rho1d"); + memory->create2d_offset(drho1d, 3, -order / 2, order / 2, "pppm:drho1d"); + memory->create2d_offset(rho_coeff, order, (1 - order) / 2, order / 2, "pppm:rho_coeff"); + memory->create2d_offset(drho_coeff, order, (1 - order) / 2, order / 2, "pppm:drho_coeff"); // create 2 FFTs and a Remap // 1st FFT keeps data in FFT decomposition @@ -1074,20 +1076,17 @@ void PPPMElectrode::allocate() int tmp; - fft1 = new FFT3d(lmp,world,nx_pppm,ny_pppm,nz_pppm, - nxlo_fft,nxhi_fft,nylo_fft,nyhi_fft,nzlo_fft,nzhi_fft, - nxlo_fft,nxhi_fft,nylo_fft,nyhi_fft,nzlo_fft,nzhi_fft, - 0,0,&tmp,collective_flag); + fft1 = new FFT3d(lmp, world, nx_pppm, ny_pppm, nz_pppm, nxlo_fft, nxhi_fft, nylo_fft, nyhi_fft, + nzlo_fft, nzhi_fft, nxlo_fft, nxhi_fft, nylo_fft, nyhi_fft, nzlo_fft, nzhi_fft, + 0, 0, &tmp, collective_flag); - fft2 = new FFT3d(lmp,world,nx_pppm,ny_pppm,nz_pppm, - nxlo_fft,nxhi_fft,nylo_fft,nyhi_fft,nzlo_fft,nzhi_fft, - nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in, - 0,0,&tmp,collective_flag); + fft2 = new FFT3d(lmp, world, nx_pppm, ny_pppm, nz_pppm, nxlo_fft, nxhi_fft, nylo_fft, nyhi_fft, + nzlo_fft, nzhi_fft, nxlo_in, nxhi_in, nylo_in, nyhi_in, nzlo_in, nzhi_in, 0, 0, + &tmp, collective_flag); - remap = new Remap(lmp,world, - nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in, - nxlo_fft,nxhi_fft,nylo_fft,nyhi_fft,nzlo_fft,nzhi_fft, - 1,0,0,FFT_PRECISION,collective_flag); + remap = new Remap(lmp, world, nxlo_in, nxhi_in, nylo_in, nyhi_in, nzlo_in, nzhi_in, nxlo_fft, + nxhi_fft, nylo_fft, nyhi_fft, nzlo_fft, nzhi_fft, 1, 0, 0, FFT_PRECISION, + collective_flag); // ELECTRODE specific allocations From 59bdb136dcada2c62d7c8be7ea298eb3fa26ce00 Mon Sep 17 00:00:00 2001 From: Shern Tee Date: Wed, 31 May 2023 14:50:55 +0000 Subject: [PATCH 007/185] added qtotal keyword --- doc/src/fix_electrode.rst | 17 +++- .../PACKAGES/electrode/graph-il/in.nonneut | 31 +++++++ .../PACKAGES/electrode/graph-il/in.nonneut2 | 33 +++++++ src/ELECTRODE/fix_electrode_conp.cpp | 86 ++++++++++++++++--- src/ELECTRODE/fix_electrode_conp.h | 10 ++- src/ELECTRODE/fix_electrode_thermo.cpp | 5 +- 6 files changed, 168 insertions(+), 14 deletions(-) create mode 100644 examples/PACKAGES/electrode/graph-il/in.nonneut create mode 100644 examples/PACKAGES/electrode/graph-il/in.nonneut2 diff --git a/doc/src/fix_electrode.rst b/doc/src/fix_electrode.rst index 3d543f08d2..5685482a71 100644 --- a/doc/src/fix_electrode.rst +++ b/doc/src/fix_electrode.rst @@ -45,7 +45,7 @@ Syntax rng_v = integer used to initialize random number generator * zero or more keyword/value pairs may be appended -* keyword = *algo* or *symm* or *couple* or *etypes* or *ffield* or *write_mat* or *write_inv* or *read_mat* or *read_inv* +* keyword = *algo* or *symm* or *couple* or *etypes* or *ffield* or *write_mat* or *write_inv* or *read_mat* or *read_inv* or *qtotal* .. parsed-literal:: @@ -68,6 +68,8 @@ Syntax filename = file from which to read elastance matrix *read_inv* value = filename filename = file from which to read inverted matrix + *qtotal* value = number or *v_* equal-style variable + add overall potential so that all electrode charges add up to *qtotal* Examples """""""" @@ -249,6 +251,19 @@ be enabled if any electrode particle has the same type as any electrolyte particle (which would be unusual in a typical simulation) and the fix will issue an error in that case. +.. versionchanged:: qtotal + +The keyword *qtotal* causes *fix electrode/conp* and *fix electrode/thermo* +to add an overall potential to all electrodes so that the total charge on +the electrodes is a specified amount (which may be an equal-style variable). +For example, if a user wanted to simulate a solution of excess cations +such that the total electrolyte charge is +2, setting *qtotal -2* would cause +the total electrode charge to be -2, so that the simulation box remains overall +electroneutral. Since *fix electrode/conq* constrains the total charges of +individual electrodes, and since *symm on* constrains the total charge of all +electrodes to be zero, either option is incompatible with the *qtotal* keyword +(even if *qtotal* is set to zero). + Restart, fix_modify, output, run start/stop, minimize info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" diff --git a/examples/PACKAGES/electrode/graph-il/in.nonneut b/examples/PACKAGES/electrode/graph-il/in.nonneut new file mode 100644 index 0000000000..3027faf0cc --- /dev/null +++ b/examples/PACKAGES/electrode/graph-il/in.nonneut @@ -0,0 +1,31 @@ +# electrodes, overall non-neutral +# for graphene-ionic liquid supercapacitor + +boundary p p f # slab calculation +include settings.mod # styles, groups, computes and fixes +kspace_modify slab 3.0 + +# make an extra anion +variable qmodify index 1 +variable vdiff index 1 +# these values can be changed, e.g. ${LAMMPS_EXECUTABLE} -i in.nonneut -var qmodify 0.9 -var vdiff -2 +# fix electrode/* needs equal style variables: +variable qmodify_equal equal v_qmodify +variable vdiff_equal equal v_vdiff + +create_atoms 4 single 16.1 17.2 0 +set atom 3777 charge $(-v_qmodify) + +fix c top electrode/conp v_vdiff_equal 1.979 couple bot 0 etypes on qtotal v_qmodify_equal +# to test electrode/thermo: +# variable vbot equal 0 +# fix c top electrode/thermo v_vdiff_equal 1.979 couple bot v_vbot etypes on qtotal v_qmodify_equal temp 310 100 12309 # symm on + +variable dv equal f_c[1]-f_c[2] + +variable qelec equal c_qbot+c_qtop +compute qall all reduce sum v_q # total system charge + +thermo 50 +thermo_style custom step temp c_ctemp epair etotal c_qbot c_qtop f_c[1] f_c[2] v_dv v_qelec c_qall +run 500 diff --git a/examples/PACKAGES/electrode/graph-il/in.nonneut2 b/examples/PACKAGES/electrode/graph-il/in.nonneut2 new file mode 100644 index 0000000000..c73eee5db3 --- /dev/null +++ b/examples/PACKAGES/electrode/graph-il/in.nonneut2 @@ -0,0 +1,33 @@ +# electrodes, overall non-neutral +# for graphene-ionic liquid supercapacitor + +boundary p p f # slab calculation +include settings.mod # styles, groups, computes and fixes +kspace_modify slab 3.0 + +# make an extra anion +variable qmodify index 1 +variable vdiff index 1 +# these values can be changed, e.g. ${LAMMPS_EXECUTABLE} -i in.nonneut -var qmodify 0.9 -var vdiff -2 +create_atoms 4 single 16.1 17.2 0 +set atom 3777 charge $(-v_qmodify) + +fix c top electrode/conp v_vtop 1.979 couple bot v_vbot etypes on # symm on +# to test electrode/thermo: +#fix c top electrode/thermo v_vtop 1.979 couple bot v_vbot etypes on temp 310 100 12309 symm off +#but it looks like update_psi() is hardwired to impose electroneutrality + +variable csum equal f_c[1][2]+f_c[1][3]+f_c[2][2]+f_c[2][3] +variable cdiff equal 0.5*(f_c[1][2]-f_c[2][3]) +variable qdeficit equal v_qmodify-f_c[1][1]-f_c[2][1]-v_cdiff*v_vdiff +variable vphi equal v_qdeficit/v_csum +variable vtop equal v_vphi+0.5*v_vdiff +variable vbot equal v_vphi-0.5*v_vdiff +variable dv equal v_vtop-v_vbot + +variable qelec equal c_qbot+c_qtop +compute qall all reduce sum v_q # total system charge + +thermo 50 +thermo_style custom step temp c_ctemp epair etotal c_qbot c_qtop f_c[1] f_c[2] v_dv v_qelec c_qall +run 500 diff --git a/src/ELECTRODE/fix_electrode_conp.cpp b/src/ELECTRODE/fix_electrode_conp.cpp index 33632f9099..a7e6cbe922 100644 --- a/src/ELECTRODE/fix_electrode_conp.cpp +++ b/src/ELECTRODE/fix_electrode_conp.cpp @@ -103,20 +103,23 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : mult_time = 0; n_call = n_cg_step = 0; + qtotal = 0.; + qtotal_var_style = VarStyle::UNSET; + // read fix command fixname = std::string(arg[0]); groups = std::vector(1, igroup); group_bits = std::vector(1, groupbit); group_psi_var_names = std::vector(1); group_psi_var_styles = std::vector(1, VarStyle::CONST); - group_psi = std::vector(1); + group_psi_const = std::vector(1); etypes_neighlists = false; if (strstr(arg[3], "v_") == arg[3]) { std::string vname = arg[3]; group_psi_var_names[0] = vname.substr(2); group_psi_var_styles[0] = VarStyle::EQUAL; } else - group_psi[0] = utils::numeric(FLERR, arg[3], false, lmp); + group_psi_const[0] = utils::numeric(FLERR, arg[3], false, lmp); char *eta_str = arg[4]; eta = utils::numeric(FLERR, eta_str, false, lmp); int iarg = 5; @@ -132,12 +135,12 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : std::string vname = arg[iarg]; group_psi_var_names.push_back(vname.substr(2)); group_psi_var_styles.push_back(VarStyle::EQUAL); - group_psi.push_back(0.); + group_psi_const.push_back(0.); } else { std::string null; group_psi_var_names.push_back(null); group_psi_var_styles.push_back(VarStyle::CONST); - group_psi.push_back(utils::numeric(FLERR, arg[iarg], false, lmp)); + group_psi_const.push_back(utils::numeric(FLERR, arg[iarg], false, lmp)); } } else if ((strcmp(arg[iarg], "algo") == 0)) { if (!default_algo) error->one(FLERR, fmt::format("Algorithm can be set once, only")); @@ -195,6 +198,19 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : thermo_temp = force->boltz / force->qe2f * utils::numeric(FLERR, arg[++iarg], false, lmp); thermo_time = utils::numeric(FLERR, arg[++iarg], false, lmp); thermo_init = utils::inumeric(FLERR, arg[++iarg], false, lmp); + } else if ((strcmp(arg[iarg], "qtotal") == 0)) { + if (iarg + 2 > narg) error->all(FLERR, "Need one argument after qtotal keyword"); + if (strcmp(this->style, "electrode/conq") == 0) + error->all(FLERR, "qtotal keyword not available for electrode/conq"); + ++iarg; + if (strstr(arg[iarg], "v_") == arg[iarg]) { + std::string vname = arg[iarg]; + qtotal_var_name = vname.substr(2); + qtotal_var_style = VarStyle::EQUAL; + } else { + qtotal = utils::numeric(FLERR, arg[iarg], false, lmp); + qtotal_var_style = VarStyle::CONST; + } // toggle parameters } else if ((strcmp(arg[iarg], "etypes") == 0)) { etypes_neighlists = utils::logical(FLERR, arg[++iarg], false, lmp); @@ -208,6 +224,12 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : iarg++; } + if (qtotal_var_style != VarStyle::UNSET) { + if (symm) error->all(FLERR, "{} cannot use qtotal keyword with symm on", this->style); + } + + // computatonal potential + group_psi = std::vector(groups.size()); // union of all coupled groups std::string union_group = "conp_group"; std::string group_cmd = union_group + " union"; @@ -225,6 +247,7 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : if (need_elec_vector) elec_vector = new ElectrodeVector(lmp, igroup, igroup, eta, false); assert(groups.size() == group_bits.size()); assert(groups.size() == group_psi.size()); + assert(groups.size() == group_psi_const.size()); assert(groups.size() == group_psi_var_styles.size()); assert(groups.size() == group_psi_var_names.size()); assert(igroup == elyt_vector->igroup); @@ -396,7 +419,8 @@ void FixElectrodeConp::init() for (char *fix_id : integrate_ids) error->warning( FLERR, - "Electrode atoms are integrated by fix {}, but fix electrode is using a matrix method. For " + "Electrode atoms are integrated by fix {}, but fix electrode is using a matrix method. " + "For " "mobile electrodes use the conjugate gradient algorithm without matrix ('algo cg').", fix_id); } @@ -475,6 +499,7 @@ void FixElectrodeConp::setup_post_neighbor() // get equal-style variable ids: group_psi_var_ids = std::vector(num_of_groups, -1); for (int g = 0; g < num_of_groups; g++) { + assert(group_psi_var_styles[g] != VarStyle::UNSET); if (group_psi_var_styles[g] == VarStyle::CONST) continue; const char *var_name = group_psi_var_names[g].c_str(); int var_id = input->variable->find(var_name); @@ -485,6 +510,16 @@ void FixElectrodeConp::setup_post_neighbor() fmt::format("Variable '{}' for fix electrode is not equal-style", var_name)); group_psi_var_ids[g] = var_id; } + if (qtotal_var_style == VarStyle::EQUAL) { + const char *var_name = qtotal_var_name.c_str(); + int var_id = input->variable->find(var_name); + if (var_id < 0) + error->all(FLERR, fmt::format("Variable '{}' for fix electrode does not exist", var_name)); + if (!input->variable->equalstyle(var_id)) + error->all(FLERR, + fmt::format("Variable '{}' for fix electrode is not equal-style", var_name)); + qtotal_var_id = var_id; + } // pair and list setups: @@ -834,6 +869,8 @@ void FixElectrodeConp::update_charges() } MPI_Allreduce(MPI_IN_PLACE, &sb_charges.front(), num_of_groups, MPI_DOUBLE, MPI_SUM, world); update_psi(); // use for equal-style and conq + if (qtotal_var_style != VarStyle::UNSET) + update_psi_qtotal(); // use for qtotal; same for thermo for (int g = 0; g < num_of_groups; g++) for (int j = 0; j < nlocalele; j++) q_local[j] += sd_vectors[g][list_iele[j]] * group_psi[g]; MPI_Barrier(world); @@ -936,12 +973,22 @@ std::vector FixElectrodeConp::gather_ngroup(std::vector x_local) } /* ---------------------------------------------------------------------- - ensure total electrode charge is 0 if symm + ensure total electrode charge is 0 if symm and qtotal if qtotal is used ------------------------------------------------------------------------- */ std::vector FixElectrodeConp::constraint_correction(std::vector x) { - return constraint_projection(x); + if (symm || qtotal_var_style != VarStyle::UNSET) { + if (qtotal_var_style == VarStyle::EQUAL) qtotal = input->variable->compute_equal(qtotal_var_id); + double sum = 0.; + for (double xi : x) sum += xi; + MPI_Allreduce(MPI_IN_PLACE, &sum, 1, MPI_DOUBLE, MPI_SUM, world); + if (qtotal_var_style != VarStyle::UNSET) sum -= qtotal; + sum /= ngroup; + for (double &xi : x) xi -= sum; + return x; + } + return x; } /* ---------------------------------------------------------------------- @@ -950,7 +997,7 @@ std::vector FixElectrodeConp::constraint_correction(std::vector std::vector FixElectrodeConp::constraint_projection(std::vector x) { - if (symm) { + if (symm || qtotal_var_style != VarStyle::UNSET) { double sum = 0.; for (double xi : x) sum += xi; MPI_Allreduce(MPI_IN_PLACE, &sum, 1, MPI_DOUBLE, MPI_SUM, world); @@ -1008,13 +1055,28 @@ std::vector FixElectrodeConp::times_elastance(std::vector x) void FixElectrodeConp::update_psi() { for (int g = 0; g < num_of_groups; g++) { - if (group_psi_var_styles[g] == VarStyle::CONST) continue; - group_psi[g] = input->variable->compute_equal(group_psi_var_ids[g]); + if (group_psi_var_styles[g] == VarStyle::CONST) + group_psi[g] = group_psi_const[g]; + else + group_psi[g] = input->variable->compute_equal(group_psi_var_ids[g]); } } /* ---------------------------------------------------------------------- */ +void FixElectrodeConp::update_psi_qtotal() +{ + if (qtotal_var_style == VarStyle::EQUAL) qtotal = input->variable->compute_equal(qtotal_var_id); + double q_current = 0.; + for (int i = 0; i < num_of_groups; i++) { + q_current += sb_charges[i]; + for (int j = 0; j < num_of_groups; j++) q_current += macro_capacitance[i][j] * group_psi[j]; + } + double add_psi = (qtotal - q_current) / macro_capacitance_sum; + for (int i = 0; i < num_of_groups; i++) group_psi[i] += add_psi; +} +/* ---------------------------------------------------------------------- */ + void FixElectrodeConp::compute_macro_matrices() { assert(algo == Algo::MATRIX_INV); @@ -1070,6 +1132,10 @@ void FixElectrodeConp::compute_macro_matrices() } } } + + macro_capacitance_sum = 0.; + for (int i = 0; i < num_of_groups; i++) + for (int j = 0; j < num_of_groups; j++) macro_capacitance_sum += macro_capacitance[i][j]; } /* ---------------------------------------------------------------------- */ diff --git a/src/ELECTRODE/fix_electrode_conp.h b/src/ELECTRODE/fix_electrode_conp.h index 1289d96281..689a44053c 100644 --- a/src/ELECTRODE/fix_electrode_conp.h +++ b/src/ELECTRODE/fix_electrode_conp.h @@ -71,7 +71,7 @@ class FixElectrodeConp : public Fix { protected: enum class Algo { MATRIX_INV, MATRIX_CG, CG }; - enum class VarStyle { CONST, EQUAL }; + enum class VarStyle { CONST, EQUAL, UNSET }; virtual void update_psi(); virtual void pre_update(){}; virtual void recompute_potential(std::vector, std::vector){}; @@ -80,6 +80,7 @@ class FixElectrodeConp : public Fix { virtual void compute_macro_matrices(); std::vector ele_ele_interaction(const std::vector &); std::vector group_psi; + std::vector group_psi_const; // needed to undo qtotal psi updates std::vector group_bits; std::vector groups; int num_of_groups; @@ -101,6 +102,10 @@ class FixElectrodeConp : public Fix { std::string fixname; // used by electrode/ffield to set up internal efield bool intelflag; inline virtual void intel_pack_buffers() {} + double qtotal; + std::string qtotal_var_name; + int qtotal_var_id; + VarStyle qtotal_var_style; private: std::string output_file_inv, output_file_mat, output_file_vec; @@ -143,6 +148,9 @@ class FixElectrodeConp : public Fix { std::vector gather_ngroup(std::vector); std::vector gather_elevec_local(ElectrodeVector *); void set_charges(std::vector); + // qtotal + double macro_capacitance_sum; + void update_psi_qtotal(); // fix-specific electrode ID storage system: diff --git a/src/ELECTRODE/fix_electrode_thermo.cpp b/src/ELECTRODE/fix_electrode_thermo.cpp index 52c0a3ce4c..3883aa40a2 100644 --- a/src/ELECTRODE/fix_electrode_thermo.cpp +++ b/src/ELECTRODE/fix_electrode_thermo.cpp @@ -47,7 +47,8 @@ FixElectrodeThermo::FixElectrodeThermo(LAMMPS *lmp, int narg, char **arg) : if (thermo_time < SMALL) error->all(FLERR, "Keyword temp not set or zero in electrode/thermo"); thermo_random = new RanMars(lmp, thermo_init); - if (group_psi_var_styles[0] == VarStyle::CONST) delta_psi_0 = group_psi[1] - group_psi[0]; + if (group_psi_var_styles[0] == VarStyle::CONST) + delta_psi_0 = group_psi_const[1] - group_psi_const[0]; } /* ----------------------------------------------------------------------- */ @@ -102,7 +103,7 @@ void FixElectrodeThermo::update_psi() double const delta_psi = group_psi_old[1] - group_psi_old[0]; // target potential difference from input parameters - if (group_psi_var_styles[0] != VarStyle::CONST) { + if (group_psi_var_styles[0] == VarStyle::EQUAL) { delta_psi_0 = input->variable->compute_equal(group_psi_var_ids[1]) - input->variable->compute_equal(group_psi_var_ids[0]); } From 6de50fbd33a130e8a2ecac07a5bc31ac5467969d Mon Sep 17 00:00:00 2001 From: jtclemm Date: Wed, 14 Jun 2023 13:39:24 -0600 Subject: [PATCH 008/185] Adding iso options to fix deform --- doc/src/fix_deform.rst | 46 ++++++++++++--- src/fix_deform.cpp | 129 ++++++++++++++++++++++++++++++++++++----- src/fix_deform.h | 2 + 3 files changed, 155 insertions(+), 22 deletions(-) diff --git a/doc/src/fix_deform.rst b/doc/src/fix_deform.rst index d46f1204f5..7a17f14fed 100644 --- a/doc/src/fix_deform.rst +++ b/doc/src/fix_deform.rst @@ -20,7 +20,7 @@ Syntax .. parsed-literal:: - parameter = *x* or *y* or *z* or *xy* or *xz* or *yz* + parameter = *x* or *y* or *z* or *xy* or *xz* or *yz* or *iso* *x*, *y*, *z* args = style value(s) style = *final* or *delta* or *scale* or *vel* or *erate* or *trate* or *volume* or *wiggle* or *variable* *final* values = lo hi @@ -71,6 +71,12 @@ Syntax *variable* values = v_name1 v_name2 v_name1 = variable with name1 for tilt change as function of time v_name2 = variable with name2 for change rate as function of time + *iso* = style value + style = *volume* or *pressure* + *volume* value = none = isotropically adjust system to preserve volume of system + *pressure* values = target gain + target = target mean pressure (pressure units) + gain = proportional gain constant (1/(time * pressure) or 1/time units) * zero or more keyword/value pairs may be appended * keyword = *remap* or *flip* or *units* or *couple* or *vol/balance/p* or *max/rate* or *normalize/pressure* @@ -88,12 +94,10 @@ Syntax box = distances are defined in simulation box units *couple* value = *none* or *xyz* or *xy* or *yz* or *xz* couple pressure values of various dimensions - *vol/balance/p* = *yes* or *no* + *vol/balance/p* value = *yes* or *no* Modifies the behavior of the *volume* option to try and balance pressures *max/rate* value = *rate* rate = maximum strain rate for pressure control - *normalize/pressure* value = *yes* or *no* - determine whether pressure deviation is normalized by target pressure Examples """""""" @@ -107,6 +111,7 @@ Examples fix 1 all deform 1 x pressure 2.0 0.1 normalize/pressure yes max/rate 0.001 fix 1 all deform 1 x trate 0.1 y volume z volume vol/balance/p yes fix 1 all deform 1 x trate 0.1 y pressure/mean 0.0 1.0 z pressure/mean 0.0 1.0 + fix 1 all deform 1 x trate 0.1 y trate -0.1 overlay/pressure/mean 1.0 0.1 Description """"""""""" @@ -318,8 +323,8 @@ mid point. The *pressure* style adjusts a dimensions's box length to control that component of the pressure tensor. This option attempts to maintain a -specified target value using a linear controller where the box length L -evolves according to the equation +specified target value using a linear controller where the box length +:math:`L` evolves according to the equation .. parsed-literal:: @@ -343,7 +348,7 @@ option. The *pressure/mean* style is changes a dimension in order to maintain a constant mean pressure defined as the trace of the pressure tensor. -This option is therefore very similar to the *presssure* style with +This option is therefore very similar to the *pressure* style with identical arguments except the current and target pressures refer to the mean trace of the pressure tensor. The same options also apply except for the :ref:`couple ` option. @@ -512,6 +517,25 @@ of the applied strain using the :ref:`max/rate ` option. ---------- +The *iso* parameter provides an additonal control over the x, y, +and z box lengths. This parameter can only be used in combination with +the *x*, *y*, or *z* comamnds: *vel*, *erate*, *trate*, *pressure*, or +*wiggle*. Note that this parameter will change the overall strain rate in +the *x*, *y*, or *z* dimensions. This is the meaning of its styles and values. + +The *volume* style isotropically scales box lengths to maintain a constant +box volume in response to deformation from other parameters. + +The *pressure* style controls the box volume to maintain the mean pressure +of the system. This is accomplished by isotropically scaling all box +lengths :math:`L` by an additional factor of :math:`k (P_t - P_m)` where +:math:`k` is the proportional gain constant, :math:`P_t` is the target +pressure, and :math:`P_m` is the current mean pressure (the trace of the +pressure tensor). This style allows one to control the deviatoric strain +tensor while maintaining a fixed mean pressure. + +---------- + All of the tilt styles change the xy, xz, yz tilt factors during a simulation. In LAMMPS, tilt factors (xy,xz,yz) for triclinic boxes are normally bounded by half the distance of the parallel box length. @@ -652,8 +676,12 @@ described below, which will cap the divergence. .. _deform_max_rate: The *max/rate* keyword sets an upper threshold, *rate*, that limits the -maximum magnitude of the strain rate applied in any dimension. This keyword -only applies to the *pressure* and *pressure/mean* options. +maximum magnitude of the instantaneous strain rate applied in any dimension. +This keyword only applies to the *pressure* and *pressure/mean* options. If +a pressure-controlled rate is used for both *iso* and either *x*, *y*, or +*z*, then this threshold will apply separately to each individual controller +such that the cumulative strain rate on a box dimension may be up to twice +the value of *rate*. .. _deform_couple: diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 29c286ed02..e76b34f302 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -65,8 +65,8 @@ irregular(nullptr), set(nullptr) // set defaults - set = new Set[6]; - memset(set,0,6*sizeof(Set)); + set = new Set[7]; + memset(set,0,7*sizeof(Set)); // parse arguments @@ -237,6 +237,25 @@ irregular(nullptr), set(nullptr) error->all(FLERR,"Illegal fix deform pressure gain, must be positive"); iarg += 4; } else error->all(FLERR,"Illegal fix deform command: {}", arg[iarg+1]); + } else if (strcmp(arg[iarg],"iso") == 0) { + index = 6; + if (strcmp(arg[iarg+1],"volume") == 0) { + set[index].style = VOLUME; + iarg += 2; + } else if (strcmp(arg[iarg+1],"pressure") == 0) { + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform pressure", error); + set[index].style = PRESSURE; + if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { + set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); + } else { + set[index].pstr = utils::strdup(&arg[iarg+2][2]); + set[index].pvar_flag = 1; + } + set[index].pgain = utils::numeric(FLERR,arg[iarg+3],false,lmp); + if (set[index].pgain <= 0.0) + error->all(FLERR,"Illegal fix deform pressure gain, must be positive"); + iarg += 4; + } } else break; } @@ -313,6 +332,12 @@ irregular(nullptr), set(nullptr) if (set[i].style == NONE) dimflag[i] = 0; else dimflag[i] = 1; + if (set[6].style != NONE) { + dimflag[0] = 1; + dimflag[1] = 1; + dimflag[2] = 1; + } + if (dimflag[0]) box_change |= BOX_CHANGE_X; if (dimflag[1]) box_change |= BOX_CHANGE_Y; if (dimflag[2]) box_change |= BOX_CHANGE_Z; @@ -324,7 +349,7 @@ irregular(nullptr), set(nullptr) // b/c shrink wrap will change box-length for (int i = 0; i < 3; i++) - if (set[i].style && (domain->boundary[i][0] >= 2 || domain->boundary[i][1] >= 2)) + if ((set[i].style || set[6].style) && (domain->boundary[i][0] >= 2 || domain->boundary[i][1] >= 2)) error->all(FLERR,"Cannot use fix deform on a shrink-wrapped boundary"); // no tilt deformation on shrink-wrapped 2nd dim @@ -431,7 +456,7 @@ irregular(nullptr), set(nullptr) // set varflag varflag = 0; - for (int i = 0; i < 6; i++) { + for (int i = 0; i < 7; i++) { if (set[i].style == VARIABLE) varflag = 1; if (set[i].pvar_flag) varflag = 1; } @@ -439,7 +464,7 @@ irregular(nullptr), set(nullptr) // set pressure_flag pressure_flag = 0; - for (int i = 0; i < 6; i++) { + for (int i = 0; i < 7; i++) { if (set[i].style == PRESSURE || set[i].style == PMEAN) pressure_flag = 1; if (set[i].coupled_flag) pressure_flag = 1; } @@ -452,6 +477,14 @@ irregular(nullptr), set(nullptr) if (set[i].style == PMEAN) error->all(FLERR, "Cannot use fix deform to assign constant volume and pressure"); + // check conflicts between x,y,z styles and iso + + if (set[6].style) + for (int i = 0; i < 3; i++) { + if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == SCALE || set[i].style == PMEAN || set[i].style == VARIABLE) + error->all(FLERR, "Cannot use fix deform iso parameter with x, y, or z styles other than vel, erate, trate, pressure, and wiggle"); + } + // check pressure used for max rate and normalize error flag if (!pressure_flag && max_h_rate != 0) @@ -470,6 +503,7 @@ irregular(nullptr), set(nullptr) set[3].tilt_initial = domain->yz; set[4].tilt_initial = domain->xz; set[5].tilt_initial = domain->xy; + set[6].vol_initial = domain->xprd * domain->yprd * domain->zprd; // reneighboring only forced if flips can occur due to shape changes @@ -511,7 +545,7 @@ irregular(nullptr), set(nullptr) FixDeform::~FixDeform() { if (set) { - for (int i = 0; i < 6; i++) { + for (int i = 0; i < 7; i++) { delete[] set[i].hstr; delete[] set[i].hratestr; delete[] set[i].pstr; @@ -569,7 +603,7 @@ void FixDeform::init() // check variables for VARIABLE style - for (int i = 0; i < 6; i++) { + for (int i = 0; i < 7; i++) { if (set[i].style != VARIABLE) continue; set[i].hvar = input->variable->find(set[i].hstr); if (set[i].hvar < 0) @@ -585,7 +619,7 @@ void FixDeform::init() // check optional variables for PRESSURE or PMEAN style - for (int i = 0; i < 6; i++) { + for (int i = 0; i < 7; i++) { if (!set[i].pvar_flag) continue; set[i].pvar = input->variable->find(set[i].pstr); if (set[i].pvar < 0) @@ -701,6 +735,8 @@ void FixDeform::init() } } + set[6].vol_start = domain->xprd * domain->yprd * domain->zprd; + // if using tilt TRATE, then initial tilt must be non-zero for (int i = 3; i < 6; i++) @@ -740,6 +776,7 @@ void FixDeform::init() // set domain->h_rate values for use by domain and other fixes/computes // initialize all rates to 0.0 // cannot set here for TRATE,VOLUME,WIGGLE,VARIABLE,PRESSURE since not constant + // if iso style is used, these will also not be constant h_rate = domain->h_rate; h_ratelo = domain->h_ratelo; @@ -867,6 +904,10 @@ void FixDeform::end_of_step() if (volume_flag) set_volume(); + // apply any final isotropic scalings + + if (set[6].style) set_iso(); + // Save pressure/strain rate if required if (pressure_flag) { @@ -983,15 +1024,15 @@ void FixDeform::end_of_step() // reset global and local box to new size/shape // only if deform fix is controlling the dimension - if (set[0].style) { + if (set[0].style || set[6].style) { domain->boxlo[0] = set[0].lo_target; domain->boxhi[0] = set[0].hi_target; } - if (set[1].style) { + if (set[1].style || set[6].style) { domain->boxlo[1] = set[1].lo_target; domain->boxhi[1] = set[1].hi_target; } - if (set[2].style) { + if (set[2].style || set[6].style) { domain->boxlo[2] = set[2].lo_target; domain->boxhi[2] = set[2].hi_target; } @@ -1285,6 +1326,67 @@ void FixDeform::set_volume() } } +/* ---------------------------------------------------------------------- + apply isotropic controls +------------------------------------------------------------------------- */ + +void FixDeform::set_iso() +{ + int i; + double scale, shift; + double v_rate; + + if (set[6].style == VOLUME) { + double v0 = set[6].vol_start; + double v = 1.0; + for (i = 0; i < 3; i++) + v *= (set[i].hi_target - set[i].lo_target); + + scale = std::pow(v0 / v, THIRD); + for (i = 0; i < 3; i++) { + shift = 0.5 * (set[i].hi_target - set[i].lo_target) * scale; + set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; + set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; + + // Recalculate h_rate + h_rate[i] = (set[i].hi_target - set[i].lo_target) / (domain->boxhi[i] - domain->boxlo[i]) - 1.0; + h_rate[i] /= update->dt; + } + + } else if (set[6].style == PRESSURE) { + + // If variable pressure, calculate current target + if (set[6].pvar_flag) + set[6].ptarget = input->variable->compute_equal(set[6].pvar); + + v_rate = set[6].pgain * (pressure->scalar- set[6].ptarget); + + if (normalize_pressure_flag) { + if (set[6].ptarget == 0) { + if (max_h_rate == 0) { + error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); + } else v_rate = max_h_rate * v_rate / fabs(v_rate); + } else v_rate /= fabs(set[6].ptarget); + } + + if (max_h_rate != 0) + if (fabs(set[6].ptarget) > max_h_rate) + v_rate = max_h_rate * v_rate / fabs(v_rate); + + set[6].cumulative_strain += update->dt * v_rate; + scale = (1.0 + set[6].cumulative_strain); + for (i = 0; i < 3; i++) { + shift = 0.5 * (set[i].hi_target - set[i].lo_target) * scale; + set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; + set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; + + // Recalculate h_rate + h_rate[i] = (set[i].hi_target - set[i].lo_target) / (domain->boxhi[i] - domain->boxlo[i]) - 1.0; + h_rate[i] /= update->dt; + } + } +} + /* ---------------------------------------------------------------------- write Set data to restart file ------------------------------------------------------------------------- */ @@ -1294,7 +1396,7 @@ void FixDeform::write_restart(FILE *fp) if (comm->me == 0) { int size = 6 * sizeof(Set); fwrite(&size,sizeof(int),1,fp); - fwrite(set,sizeof(Set),6,fp); + fwrite(set,sizeof(Set),7,fp); } } @@ -1306,7 +1408,7 @@ void FixDeform::restart(char *buf) { int samestyle = 1; Set *set_restart = (Set *) buf; - for (int i=0; i<6; ++i) { + for (int i=0; i<7; ++i) { // restore data from initial state set[i].lo_initial = set_restart[i].lo_initial; set[i].hi_initial = set_restart[i].hi_initial; @@ -1315,6 +1417,7 @@ void FixDeform::restart(char *buf) set[i].saved = set_restart[i].saved; set[i].prior_rate = set_restart[i].prior_rate; set[i].prior_pressure = set_restart[i].prior_pressure; + set[i].cumulative_strain = set_restart[i].cumulative_strain; // check if style settings are consistent (should do the whole set?) if (set[i].style != set_restart[i].style) samestyle = 0; diff --git a/src/fix_deform.h b/src/fix_deform.h index eda97f7c90..e8a4766b12 100644 --- a/src/fix_deform.h +++ b/src/fix_deform.h @@ -72,6 +72,7 @@ class FixDeform : public Fix { double vol_initial, vol_start; double ptarget, pgain; double prior_pressure, prior_rate; + double cumulative_strain; int saved; int fixed, dynamic1, dynamic2; char *hstr, *hratestr, *pstr; @@ -85,6 +86,7 @@ class FixDeform : public Fix { void set_strain(); void set_pressure(); void set_volume(); + void set_iso(); void couple(); }; From f75eda4bf4f5d223eaf469a5f42d7b8377c0547b Mon Sep 17 00:00:00 2001 From: jtclemm Date: Wed, 14 Jun 2023 14:16:46 -0600 Subject: [PATCH 009/185] Updating size of set in restart --- src/fix_deform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index e76b34f302..34e73b4e10 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -1394,7 +1394,7 @@ void FixDeform::set_iso() void FixDeform::write_restart(FILE *fp) { if (comm->me == 0) { - int size = 6 * sizeof(Set); + int size = 7 * sizeof(Set); fwrite(&size,sizeof(int),1,fp); fwrite(set,sizeof(Set),7,fp); } From 60173c477d59c770e1bbac40e68111a01f28fd67 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Wed, 14 Jun 2023 15:14:19 -0600 Subject: [PATCH 010/185] Creating persistent h_rate variable --- src/fix_deform.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 34e73b4e10..b595901a05 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -47,7 +47,7 @@ enum{NOCOUPLE=0,XYZ,XY,YZ,XZ}; /* ---------------------------------------------------------------------- */ FixDeform::FixDeform(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), -irregular(nullptr), set(nullptr) +irregular(nullptr), set(nullptr), id_temp(nullptr), id_press(nullptr) { if (narg < 4) error->all(FLERR,"Illegal fix deform command"); @@ -538,6 +538,16 @@ irregular(nullptr), set(nullptr) modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pflag = 1; } + + // initialize all rates to 0.0 in constructor instead of init so values persist + // across run statements and ghosts have correct velocities until the destructor + h_rate = domain->h_rate; + h_ratelo = domain->h_ratelo; + + for (int i = 0; i < 3; i++) + h_rate[i] = h_ratelo[i] = 0.0; + for (int i = 3; i < 6; i++) + h_rate[i] = 0.0; } /* ---------------------------------------------------------------------- */ @@ -774,15 +784,10 @@ void FixDeform::init() } // set domain->h_rate values for use by domain and other fixes/computes - // initialize all rates to 0.0 // cannot set here for TRATE,VOLUME,WIGGLE,VARIABLE,PRESSURE since not constant // if iso style is used, these will also not be constant - h_rate = domain->h_rate; - h_ratelo = domain->h_ratelo; - for (int i = 0; i < 3; i++) { - h_rate[i] = h_ratelo[i] = 0.0; if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == SCALE || set[i].style == VEL || set[i].style == ERATE) { @@ -797,7 +802,6 @@ void FixDeform::init() } for (int i = 3; i < 6; i++) { - h_rate[i] = 0.0; if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == VEL || set[i].style == ERATE) { if (delt != 0.0) @@ -1394,8 +1398,10 @@ void FixDeform::set_iso() void FixDeform::write_restart(FILE *fp) { if (comm->me == 0) { - int size = 7 * sizeof(Set); + int size = 9 * sizeof(double) + 7 * sizeof(Set); fwrite(&size,sizeof(int),1,fp); + fwrite(h_rate,sizeof(double),6,fp); + fwrite(h_ratelo,sizeof(double),3,fp); fwrite(set,sizeof(Set),7,fp); } } @@ -1406,9 +1412,16 @@ void FixDeform::write_restart(FILE *fp) void FixDeform::restart(char *buf) { + int n = 0; + auto list = (double *) buf; + for (int i = 0; i < 6; i++) + h_rate[i] = list[n++]; + for (int i = 0; i < 3; i++) + h_ratelo[i] = list[n++]; + int samestyle = 1; - Set *set_restart = (Set *) buf; - for (int i=0; i<7; ++i) { + Set *set_restart = (Set *) &buf[n * sizeof(double)]; + for (int i = 0; i < 7; ++i) { // restore data from initial state set[i].lo_initial = set_restart[i].lo_initial; set[i].hi_initial = set_restart[i].hi_initial; From d6532d3550694d3f5ce4a1ae83ff4b57ce1598a6 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Fri, 23 Jun 2023 14:13:32 -0600 Subject: [PATCH 011/185] Adding h_ratelo calculation --- src/fix_deform.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index b595901a05..8da904100e 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -1114,7 +1114,8 @@ void FixDeform::set_strain() set[i].hi_target = set[i].hi_start + 0.5 * del; h_rate[i] = input->variable->compute_equal(set[i].hratevar); h_ratelo[i] = -0.5 * h_rate[i]; - } else if (set[i].style != VOLUME) { + } else if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == SCALE || + set[i].style == VEL || set[i].style == ERATE) { set[i].lo_target = set[i].lo_start + delta * (set[i].lo_stop - set[i].lo_start); set[i].hi_target = set[i].hi_start + delta * (set[i].hi_stop - set[i].hi_start); } @@ -1215,6 +1216,7 @@ void FixDeform::set_pressure() if (max_h_rate != 0) if (fabs(set[i].ptarget) > max_h_rate) h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); + h_ratelo[i] = -0.5 * h_rate[i]; double offset = 0.5 * (domain->boxhi[i] - domain->boxlo[i]) * (1.0 + update->dt * h_rate[i]); set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - offset; @@ -1324,6 +1326,7 @@ void FixDeform::set_volume() } h_rate[i] = (2.0 * shift / (domain->boxhi[i] - domain->boxlo[i]) - 1.0) / update->dt; + h_ratelo[i] = -0.5 * h_rate[i]; set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; @@ -1355,6 +1358,7 @@ void FixDeform::set_iso() // Recalculate h_rate h_rate[i] = (set[i].hi_target - set[i].lo_target) / (domain->boxhi[i] - domain->boxlo[i]) - 1.0; h_rate[i] /= update->dt; + h_ratelo[i] = -0.5 * h_rate[i]; } } else if (set[6].style == PRESSURE) { @@ -1387,6 +1391,7 @@ void FixDeform::set_iso() // Recalculate h_rate h_rate[i] = (set[i].hi_target - set[i].lo_target) / (domain->boxhi[i] - domain->boxlo[i]) - 1.0; h_rate[i] /= update->dt; + h_ratelo[i] = -0.5 * h_rate[i]; } } } From 2ef326273d703eeee71cbb894a451810ea3055db Mon Sep 17 00:00:00 2001 From: jtclemm Date: Sat, 15 Jul 2023 16:09:53 -0600 Subject: [PATCH 012/185] Fixing bug in max rate threshold --- src/fix_deform.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 8da904100e..ff6caf5a1d 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -1214,8 +1214,9 @@ void FixDeform::set_pressure() } if (max_h_rate != 0) - if (fabs(set[i].ptarget) > max_h_rate) + if (fabs(h_rate[i]) > max_h_rate) h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); + h_ratelo[i] = -0.5 * h_rate[i]; double offset = 0.5 * (domain->boxhi[i] - domain->boxlo[i]) * (1.0 + update->dt * h_rate[i]); @@ -1378,7 +1379,7 @@ void FixDeform::set_iso() } if (max_h_rate != 0) - if (fabs(set[6].ptarget) > max_h_rate) + if (fabs(v_rate) > max_h_rate) v_rate = max_h_rate * v_rate / fabs(v_rate); set[6].cumulative_strain += update->dt * v_rate; From ec65fc48adbe1d2edb40db35e1ae6f85f7b5f7fb Mon Sep 17 00:00:00 2001 From: jtclemm Date: Tue, 18 Jul 2023 09:25:22 -0600 Subject: [PATCH 013/185] Cleaning up files, fixing bug in berendsen --- doc/src/fix_deform.rst | 10 ++++++---- src/fix_deform.cpp | 35 +++++++++++++++++------------------ src/fix_press_berendsen.cpp | 2 +- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/doc/src/fix_deform.rst b/doc/src/fix_deform.rst index 7a17f14fed..a4d449850e 100644 --- a/doc/src/fix_deform.rst +++ b/doc/src/fix_deform.rst @@ -98,6 +98,8 @@ Syntax Modifies the behavior of the *volume* option to try and balance pressures *max/rate* value = *rate* rate = maximum strain rate for pressure control + *normalize/pressure* value = *yes* or *no* + Modifies pressure controls such that the deviation in pressure is normalized by the target pressure Examples """""""" @@ -111,7 +113,6 @@ Examples fix 1 all deform 1 x pressure 2.0 0.1 normalize/pressure yes max/rate 0.001 fix 1 all deform 1 x trate 0.1 y volume z volume vol/balance/p yes fix 1 all deform 1 x trate 0.1 y pressure/mean 0.0 1.0 z pressure/mean 0.0 1.0 - fix 1 all deform 1 x trate 0.1 y trate -0.1 overlay/pressure/mean 1.0 0.1 Description """"""""""" @@ -346,12 +347,13 @@ applied strain using the :ref:`max/rate ` option and couple pressures in different dimensions using the :ref:`couple ` option. -The *pressure/mean* style is changes a dimension in order to maintain +The *pressure/mean* style changes a dimension's box length to maintain a constant mean pressure defined as the trace of the pressure tensor. This option is therefore very similar to the *pressure* style with identical arguments except the current and target pressures refer to the -mean trace of the pressure tensor. The same options also apply except -for the :ref:`couple ` option. +mean trace of the pressure tensor. All options for the *pressure* style +also apply to the *pressure/mean* style except for the +:ref:`couple ` option. ---------- diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index ff6caf5a1d..79f9b3a5ba 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -24,6 +24,7 @@ #include "domain.h" #include "error.h" #include "force.h" +#include "group.h" #include "input.h" #include "irregular.h" #include "kspace.h" @@ -1522,31 +1523,31 @@ double FixDeform::memory_usage() int FixDeform::modify_param(int narg, char **arg) { - if (!pressure_flag) error->all(FLERR,"Cannot modify fix deform without a pressure control"); if (strcmp(arg[0],"temp") == 0) { - if (narg < 2) utils::missing_cmd_args(FLERR, "fix_modify deform", error); + if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); if (tflag) { modify->delete_compute(id_temp); tflag = 0; } - delete [] id_temp; + delete[] id_temp; id_temp = utils::strdup(arg[1]); - int icompute = modify->find_compute(arg[1]); - if (icompute < 0) error->all(FLERR,"Could not find fix_modify temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(arg[1]); + if (!temperature) + error->all(FLERR,"Could not find fix_modify temperature compute ID: ", arg[1]); if (temperature->tempflag == 0) - error->all(FLERR,"Fix_modify temperature ID does not compute temperature"); + error->all(FLERR,"Fix_modify temperature compute {} does not compute temperature", arg[1]); if (temperature->igroup != 0 && comm->me == 0) - error->warning(FLERR,"Temperature for deform is not for group all"); + error->warning(FLERR,"Temperature compute {} for fix {} is not for group all: {}", + arg[1], style, group->names[temperature->igroup]); // reset id_temp of pressure to new temperature ID - icompute = modify->find_compute(id_press); - if (icompute < 0) - error->all(FLERR,"Pressure ID for fix deform does not exist"); - modify->compute[icompute]->reset_extra_compute_fix(id_temp); + auto icompute = modify->get_compute_by_id(id_press); + if (!icompute) + error->all(FLERR,"Pressure compute ID {} for fix {} does not exist", id_press, style); + icompute->reset_extra_compute_fix(id_temp); return 2; @@ -1556,15 +1557,13 @@ int FixDeform::modify_param(int narg, char **arg) modify->delete_compute(id_press); pflag = 0; } - delete [] id_press; + delete[] id_press; id_press = utils::strdup(arg[1]); - int icompute = modify->find_compute(arg[1]); - if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); - pressure = modify->compute[icompute]; - + pressure = modify->get_compute_by_id(arg[1]); + if (!pressure) error->all(FLERR,"Could not find fix_modify pressure compute ID: {}", arg[1]); if (pressure->pressflag == 0) - error->all(FLERR,"Fix_modify pressure ID does not compute pressure"); + error->all(FLERR,"Fix_modify pressure compute {} does not compute pressure", arg[1]); return 2; } diff --git a/src/fix_press_berendsen.cpp b/src/fix_press_berendsen.cpp index 67802654ba..ee9a879616 100644 --- a/src/fix_press_berendsen.cpp +++ b/src/fix_press_berendsen.cpp @@ -491,7 +491,7 @@ int FixPressBerendsen::modify_param(int narg, char **arg) id_press = utils::strdup(arg[1]); pressure = modify->get_compute_by_id(arg[1]); - if (pressure) error->all(FLERR,"Could not find fix_modify pressure compute ID: {}", arg[1]); + if (!pressure) error->all(FLERR,"Could not find fix_modify pressure compute ID: {}", arg[1]); if (pressure->pressflag == 0) error->all(FLERR,"Fix_modify pressure compute {} does not compute pressure", arg[1]); return 2; From e5bcbd4213ceaad5297cea609a70b26c7c31ee90 Mon Sep 17 00:00:00 2001 From: Ludwig Ahrens Date: Wed, 2 Aug 2023 13:03:45 +0200 Subject: [PATCH 014/185] Bugfix electrode/conq after changes for qtotal --- src/ELECTRODE/fix_electrode_conq.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ELECTRODE/fix_electrode_conq.cpp b/src/ELECTRODE/fix_electrode_conq.cpp index 0d3d1d2aaf..a6baa1e122 100644 --- a/src/ELECTRODE/fix_electrode_conq.cpp +++ b/src/ELECTRODE/fix_electrode_conq.cpp @@ -30,7 +30,7 @@ FixElectrodeConq::FixElectrodeConq(LAMMPS *lmp, int narg, char **arg) : FixElectrodeConp(lmp, narg, arg) { // copy const-style values across because update_psi will change group_psi - group_q = group_psi; + group_q = group_psi_const; if (symm) { if (num_of_groups == 1) From 77a5fd16dd5309d1955aae573ed41d66bc0caede Mon Sep 17 00:00:00 2001 From: jtclemm Date: Tue, 19 Sep 2023 13:37:47 +0200 Subject: [PATCH 015/185] Fixing bug in link pressure --- src/fix_deform.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 79f9b3a5ba..139f1e0835 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -1302,6 +1302,7 @@ void FixDeform::set_volume() double p2 = pressure->vector[fixed]; double p1i = set[i].prior_pressure; double p2i = set[fixed].prior_pressure; + double denominator; if (e3 == 0) { e1 = 0.0; @@ -1314,7 +1315,12 @@ void FixDeform::set_volume() if (!linked_pressure) { // Calculate first strain rate by expanding stress to linear order, p1(t+dt) = p2(t+dt) // Calculate second strain rate to preserve volume - e1 = -e3 / (1 + e3 * dt) * (p2 - p2i) - e2i * (p1 - p2) / (p2 - p2i + (p1 - p1i) / e1i * e2i); + denominator = (p2 - p2i + (p1 - p1i) / e1i * e2i); + if (denominator != 0.0 && e1i != 0.0) { + e1 = (-e3 / (1 + e3 * dt) * (p2 - p2i) - e2i * (p1 - p2)) / denominator; + } else { + e1 = e2i; + } e2 = (1.0 - (1 + e3 * dt) * (1 + e1 * dt)) / ((1 + e3 * dt) * (1 + e1 * dt) * dt); shift = 0.5 * L1i * (1.0 + e1 * dt); From 5ff16da2725e641c3a4eae7db763dd8f0d2cf8fa Mon Sep 17 00:00:00 2001 From: jtclemm Date: Thu, 21 Sep 2023 12:17:47 +0200 Subject: [PATCH 016/185] Adding rate cap on vol link pressure --- src/fix_deform.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++--- src/fix_deform.h | 1 + 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 139f1e0835..3430c26061 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -1297,6 +1297,8 @@ void FixDeform::set_volume() double L2i = domain->boxhi[fixed] - domain->boxlo[fixed]; double L3i = domain->boxhi[dynamic1] - domain->boxlo[dynamic1]; double L3 = (set[dynamic1].hi_target - set[dynamic1].lo_target); + double Vi = L1i * L2i * L3i; + double V = L3 * L1i * L2i; double e3 = (L3 / L3i - 1.0) / dt; double p1 = pressure->vector[i]; double p2 = pressure->vector[fixed]; @@ -1315,13 +1317,22 @@ void FixDeform::set_volume() if (!linked_pressure) { // Calculate first strain rate by expanding stress to linear order, p1(t+dt) = p2(t+dt) // Calculate second strain rate to preserve volume - denominator = (p2 - p2i + (p1 - p1i) / e1i * e2i); + denominator = p2 - p2i + e2i * ((p1 - p1i) / e1i); if (denominator != 0.0 && e1i != 0.0) { - e1 = (-e3 / (1 + e3 * dt) * (p2 - p2i) - e2i * (p1 - p2)) / denominator; + e1 = (((p2 - p2i) * (Vi - V) / (V * dt)) - e2i * (p1 - p2)) / denominator; } else { e1 = e2i; } - e2 = (1.0 - (1 + e3 * dt) * (1 + e1 * dt)) / ((1 + e3 * dt) * (1 + e1 * dt) * dt); + e2 = (Vi - V * (1 + e1 * dt)) / (V * (1 + e1 * dt) * dt); + + // If strain rate exceeds limit in either dimension, cap it at the maximum compatible rate + if (max_h_rate != 0) + if (fabs(e1) > max_h_rate || fabs(e2) > max_h_rate) + if (fabs(e1) > fabs(e2)) + adjust_linked_rates(e1, e2, e3, Vi, V); + else + adjust_linked_rates(e2, e1, e3, Vi, V); + shift = 0.5 * L1i * (1.0 + e1 * dt); linked_pressure = 1; @@ -1341,6 +1352,37 @@ void FixDeform::set_volume() } } + +/* ---------------------------------------------------------------------- + Rescale volume preserving strain rates to enforce max rate +------------------------------------------------------------------------- */ + +void FixDeform::adjust_linked_rates(double &e_larger, double &e_smaller, double e3, double Vi, double V) +{ + double dt = update->dt; + double e_lim_positive = (Vi - V * (1 + max_h_rate * dt)) / (V * (1 + max_h_rate * dt) * dt); + double e_lim_negative = (Vi - V * (1 - max_h_rate * dt)) / (V * (1 - max_h_rate * dt) * dt); + if ((e_larger * e3) >= 0) { + if (e_larger > 0.0) { + // Same sign as primary strain rate, cap third dimension + e_smaller = -max_h_rate; + e_larger = e_lim_negative; + } else { + e_smaller = max_h_rate; + e_larger = e_lim_positive; + } + } else { + // Opposite sign, set to maxrate. + if (e_larger > 0.0) { + e_larger = max_h_rate; + e_smaller = e_lim_positive; + } else { + e_larger = -max_h_rate; + e_smaller = e_lim_negative; + } + } +} + /* ---------------------------------------------------------------------- apply isotropic controls ------------------------------------------------------------------------- */ diff --git a/src/fix_deform.h b/src/fix_deform.h index e8a4766b12..2f0b66aa71 100644 --- a/src/fix_deform.h +++ b/src/fix_deform.h @@ -88,6 +88,7 @@ class FixDeform : public Fix { void set_volume(); void set_iso(); void couple(); + void adjust_linked_rates(double&, double&, double, double, double); }; } // namespace LAMMPS_NS From 857cc5392385f1799b222af2996c6b684ee613da Mon Sep 17 00:00:00 2001 From: Ludwig Ahrens-Iwers Date: Wed, 4 Oct 2023 10:32:50 +0200 Subject: [PATCH 017/185] README file for the ELECTRODE package --- src/ELECTRODE/README | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/ELECTRODE/README diff --git a/src/ELECTRODE/README b/src/ELECTRODE/README new file mode 100644 index 0000000000..56894943a0 --- /dev/null +++ b/src/ELECTRODE/README @@ -0,0 +1,15 @@ +This package provides the "fix electrode/*" commands which can be used in a +LAMMPS input script. These fixes implement the constant potential method, which +minimizes the energy of electrodes as a function of atom charges at given +electric potentials or electrode charges. + +See the doc page for the fix electrode/conp command to get started. There are +example scripts for using this package in examples/PACKAGES/electrode. + +This package uses an external library in lib/electrode which must be compiled +before making LAMMPS. See the doc page on "Packages with extra build options" +for more information. + +The primary people who created this package are Ludwig Ahrens-Iwers, Shern Tee +(s.tee@griffith.edu.au) and Robert Meißner (robert.meissner@tuhh.de). Contact +them directly if you have questions. From a651697d2e8477927c04eaf1db5ba0a5ef4b6f5c Mon Sep 17 00:00:00 2001 From: Ludwig Ahrens-Iwers Date: Mon, 13 Nov 2023 14:41:13 +0100 Subject: [PATCH 018/185] Mix eta in Electrode package --- doc/src/fix_electrode.rst | 7 ++ examples/PACKAGES/electrode/madelung/data.eta | 34 +++++ .../PACKAGES/electrode/madelung/data.eta_mix | 34 +++++ examples/PACKAGES/electrode/madelung/eval.py | 4 +- examples/PACKAGES/electrode/madelung/in.eta | 17 +++ .../PACKAGES/electrode/madelung/in.eta_cg | 17 +++ .../PACKAGES/electrode/madelung/in.eta_mix | 17 +++ .../PACKAGES/electrode/madelung/plate_cap.py | 117 +++++++++--------- .../electrode/madelung/settings_eta.mod | 19 +++ examples/PACKAGES/electrode/madelung/test.sh | 16 ++- src/ELECTRODE/electrode_matrix.cpp | 20 ++- src/ELECTRODE/electrode_matrix.h | 3 + src/ELECTRODE/electrode_vector.cpp | 35 ++++-- src/ELECTRODE/electrode_vector.h | 3 + src/ELECTRODE/fix_electrode_conp.cpp | 36 +++++- src/ELECTRODE/fix_electrode_conp.h | 2 + 16 files changed, 303 insertions(+), 78 deletions(-) create mode 100644 examples/PACKAGES/electrode/madelung/data.eta create mode 100644 examples/PACKAGES/electrode/madelung/data.eta_mix create mode 100644 examples/PACKAGES/electrode/madelung/in.eta create mode 100644 examples/PACKAGES/electrode/madelung/in.eta_cg create mode 100644 examples/PACKAGES/electrode/madelung/in.eta_mix create mode 100644 examples/PACKAGES/electrode/madelung/settings_eta.mod diff --git a/doc/src/fix_electrode.rst b/doc/src/fix_electrode.rst index 5685482a71..d807da7fd2 100644 --- a/doc/src/fix_electrode.rst +++ b/doc/src/fix_electrode.rst @@ -70,6 +70,8 @@ Syntax filename = file from which to read inverted matrix *qtotal* value = number or *v_* equal-style variable add overall potential so that all electrode charges add up to *qtotal* + *eta* value = d_propname + d_propname = a custom double vector defined via fix property/atom Examples """""""" @@ -264,6 +266,11 @@ individual electrodes, and since *symm on* constrains the total charge of all electrodes to be zero, either option is incompatible with the *qtotal* keyword (even if *qtotal* is set to zero). +The keyword *eta* takes the name of a custom double vector defined via fix +property/atom. The values will be used instead of the standard eta value. The +property/atom fix must be for vector of double values and use the *ghost on* +option. + Restart, fix_modify, output, run start/stop, minimize info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" diff --git a/examples/PACKAGES/electrode/madelung/data.eta b/examples/PACKAGES/electrode/madelung/data.eta new file mode 100644 index 0000000000..b05700a4ab --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/data.eta @@ -0,0 +1,34 @@ +LAMMPS data file via write_data, version 24 Dec 2020, timestep = 0 + +4 atoms +3 atom types + +0 1 xlo xhi +0 1 ylo yhi +-10 10 zlo zhi + +Masses + +1 196.966553 +2 196.966553 +3 1.0 + +Pair Coeffs # lj/cut/coul/long + +1 0 0 +2 0 0 +3 0 0 + +Atoms # full + +1 1 1 0.00 0.00 0.00 -2.00 # bottom electrode +2 2 2 0.00 0.00 0.00 2.00 # top electrode +3 3 3 0.50 0.00 0.00 -1.00 # bottom electrolyte +4 3 3 -0.50 0.00 0.00 1.00 # top electrolyte + +ETA + +1 2.0 +2 2.0 +3 0 +4 0 diff --git a/examples/PACKAGES/electrode/madelung/data.eta_mix b/examples/PACKAGES/electrode/madelung/data.eta_mix new file mode 100644 index 0000000000..9322ebd662 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/data.eta_mix @@ -0,0 +1,34 @@ +LAMMPS data file via write_data, version 24 Dec 2020, timestep = 0 + +4 atoms +3 atom types + +0 1 xlo xhi +0 1 ylo yhi +-10 10 zlo zhi + +Masses + +1 196.966553 +2 196.966553 +3 1.0 + +Pair Coeffs # lj/cut/coul/long + +1 0 0 +2 0 0 +3 0 0 + +Atoms # full + +1 1 1 0.00 0.00 0.00 -2.00 # bottom electrode +2 2 2 0.00 0.00 0.00 2.00 # top electrode +3 3 3 0.50 0.00 0.00 -1.00 # bottom electrolyte +4 3 3 -0.50 0.00 0.00 1.00 # top electrolyte + +ETA + +1 0.5 +2 3.0 +3 0 +4 0 diff --git a/examples/PACKAGES/electrode/madelung/eval.py b/examples/PACKAGES/electrode/madelung/eval.py index 2f5a355d9b..feda0e384e 100644 --- a/examples/PACKAGES/electrode/madelung/eval.py +++ b/examples/PACKAGES/electrode/madelung/eval.py @@ -1,7 +1,7 @@ #!/usr/env/python3 -import sys import os.path as op +import sys def rel_error(out, ref): @@ -49,5 +49,5 @@ for label, ref, out in out_lines: error = rel_error(out, ref) lines.append(f"{label}: {out:.5f}, {error:.5f}\n") -with open("madelung.txt", 'a') as f: +with open("madelung.txt", "a") as f: f.writelines(lines) diff --git a/examples/PACKAGES/electrode/madelung/in.eta b/examples/PACKAGES/electrode/madelung/in.eta new file mode 100644 index 0000000000..d928f8fed0 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/in.eta @@ -0,0 +1,17 @@ +atom_style full +units real +boundary p p f + +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc +pair_style lj/cut/coul/long 12 + +fix feta all property/atom d_eta ghost yes +read_data data.eta fix feta NULL ETA + +include "settings_eta.mod" + +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta write_inv inv.csv write_vec vec.csv + +run 0 + diff --git a/examples/PACKAGES/electrode/madelung/in.eta_cg b/examples/PACKAGES/electrode/madelung/in.eta_cg new file mode 100644 index 0000000000..e04db318d5 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/in.eta_cg @@ -0,0 +1,17 @@ +atom_style full +units real +boundary p p f + +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc +pair_style lj/cut/coul/long 12 + +fix feta all property/atom d_eta ghost yes +read_data data.eta_mix fix feta NULL ETA + +include "settings_eta.mod" + +fix conp bot electrode/conp 0 2 couple top 1 symm on algo cg 1e-6 eta d_eta + +run 0 + diff --git a/examples/PACKAGES/electrode/madelung/in.eta_mix b/examples/PACKAGES/electrode/madelung/in.eta_mix new file mode 100644 index 0000000000..d4bcf71225 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/in.eta_mix @@ -0,0 +1,17 @@ +atom_style full +units real +boundary p p f + +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc +pair_style lj/cut/coul/long 12 + +fix feta all property/atom d_eta ghost on +read_data data.eta_mix fix feta NULL ETA + +include "settings_eta.mod" + +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta write_inv inv.csv write_vec vec.csv + +run 0 + diff --git a/examples/PACKAGES/electrode/madelung/plate_cap.py b/examples/PACKAGES/electrode/madelung/plate_cap.py index 62d52fe102..fcca166869 100755 --- a/examples/PACKAGES/electrode/madelung/plate_cap.py +++ b/examples/PACKAGES/electrode/madelung/plate_cap.py @@ -3,7 +3,6 @@ import numpy as np from scipy.special import erf -ETA = 2 SQRT2 = np.sqrt(2) COULOMB = 332.06371 # Coulomb constant in Lammps 'real' units QE2F = 23.060549 @@ -17,14 +16,14 @@ def lattice(length): return np.array(np.meshgrid(x, y)).T.reshape(-1, 2) -def a_element(r): +def a_element(r, eta): """Coulomb contribution of two Gaussians""" - return erf(ETA / SQRT2 * r) / r + return erf(eta * r) / r -def b_element(r, q): +def b_element(r, q, eta): """Coulomb contribution of a Gaussian with a point charge""" - return q * erf(ETA * r) / r + return q * erf(eta * r) / r a = 1 # nearest neighbor distance i.e. lattice constant / sqrt(2) @@ -36,59 +35,65 @@ v = np.array([-0.5, 0.5]) * (QE2F / COULOMB) # distances to images within electrode and to opposite electrode distances = a * np.linalg.norm(lattice(LENGTH), axis=1) -opposite_distances = np.sqrt(np.square(distances) + distance_plates ** 2) +opposite_distances = np.sqrt(np.square(distances) + distance_plates**2) -# self interaction and within original box -A_11 = np.sqrt(2 / np.pi) * ETA -A_12 = erf(ETA * distance_plates / SQRT2) / distance_plates +for name, eta_elec in [("", [2.0, 2.0]), ("_eta_mix", [0.5, 3.0])]: + eta_mix = np.prod(eta_elec) / np.sqrt(np.sum(np.square(eta_elec))) + # self interaction and within original box + A_11 = np.sqrt(2 / np.pi) * eta_elec[0] + A_22 = np.sqrt(2 / np.pi) * eta_elec[1] + A_12 = erf(eta_mix * distance_plates) / distance_plates -# interaction with periodic images -A_11 += 4 * np.sum(a_element(distances)) -A_12 += 4 * np.sum(a_element(opposite_distances)) -A = np.array([[A_11, A_12], [A_12, A_11]]) -inv = np.linalg.inv(A) -e = np.array([1, 1]) -inv -= np.matmul(inv, np.matmul(np.outer(e, e), inv)) / np.dot(e, np.dot(inv, e)) + # interaction with periodic images + A_11 += 4 * np.sum(a_element(distances, eta_elec[0] / SQRT2)) + A_22 += 4 * np.sum(a_element(distances, eta_elec[1] / SQRT2)) + A_12 += 4 * np.sum(a_element(opposite_distances, eta_mix)) + A = np.array([[A_11, A_12], [A_12, A_22]]) + inv = np.linalg.inv(A) + e = np.array([1, 1]) + inv -= np.matmul(inv, np.matmul(np.outer(e, e), inv)) / np.dot(e, np.dot(inv, e)) -# electrode-electrolyte interaction -b = [] -for x in x_elec: - bi = 0 - for y, q in zip(x_elyt, q_elyt): - d = abs(y - x) - bi += b_element(d, q) - image_distances = np.sqrt(np.square(distances) + d ** 2) - bi += 4 * np.sum(b_element(image_distances, q)) - b.append(bi) -b = np.array(b) + # electrode-electrolyte interaction + b = [] + for x, eta in zip(x_elec, eta_elec): + bi = 0 + for y, q in zip(x_elyt, q_elyt): + d = abs(y - x) + bi += b_element(d, q, eta) + image_distances = np.sqrt(np.square(distances) + d**2) + bi += 4 * np.sum(b_element(image_distances, q, eta)) + b.append(bi) + b = np.array(b) -# electrolyte-electrolyte energy -elyt_11 = 4 * np.sum(1 / distances) -distance_elyt = x_elyt[1] - x_elyt[0] -elyt_12 = 1 / distance_elyt + 4 * np.sum( - 1 / np.sqrt(np.square(distances) + distance_elyt ** 2) -) -elyt = np.array([[elyt_11, elyt_12], [elyt_12, elyt_11]]) -energy_elyt = 0.5 * np.dot(q_elyt, np.dot(elyt, q_elyt)) - -# electrode charges and energy -q = np.dot(inv, v - b) -energy = COULOMB * (0.5 * np.dot(q, np.dot(A, q)) + np.dot(b, q) + energy_elyt) - -print( - "length, energy / kcal/mol, q1 / e, q2 / e, inv11 / A, inv12 / A, b1 / e/A, b2 / e/A" -) -print( - ", ".join( - [ - str(LENGTH), - f"{energy:.8f}", - f"{q[0]:.10f}", - f"{q[1]:.10f}", - f"{inv[0, 0]:.10f}", - f"{inv[0, 1]:.10f}", - f"{b[0]:.8f}", - f"{b[1]:.8f}", - ] + # electrolyte-electrolyte energy + elyt_11 = 4 * np.sum(1 / distances) + distance_elyt = x_elyt[1] - x_elyt[0] + elyt_12 = 1 / distance_elyt + 4 * np.sum( + 1 / np.sqrt(np.square(distances) + distance_elyt**2) ) -) + elyt = np.array([[elyt_11, elyt_12], [elyt_12, elyt_11]]) + energy_elyt = 0.5 * np.dot(q_elyt, np.dot(elyt, q_elyt)) + + # electrode charges and energy + q = np.dot(inv, v - b) + energy = COULOMB * (0.5 * np.dot(q, np.dot(A, q)) + np.dot(b, q) + energy_elyt) + + with open(f"plate_cap{name}.csv", "w") as f: + f.write( + "length, energy / kcal/mol, q1 / e, q2 / e, inv11 / A, inv12 / A, b1 / e/A, b2 / e/A\n" + ) + f.write( + ", ".join( + [ + str(LENGTH), + f"{energy:.8f}", + f"{q[0]:.10f}", + f"{q[1]:.10f}", + f"{inv[0, 0]:.10f}", + f"{inv[0, 1]:.10f}", + f"{b[0]:.8f}", + f"{b[1]:.8f}", + ] + ) + + "\n" + ) diff --git a/examples/PACKAGES/electrode/madelung/settings_eta.mod b/examples/PACKAGES/electrode/madelung/settings_eta.mod new file mode 100644 index 0000000000..aee63bf2e9 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/settings_eta.mod @@ -0,0 +1,19 @@ + +# distribute electrode atoms among all processors: +if "$(extract_setting(world_size) % 2) == 0" then "processors * * 2" + +group bot type 1 +group top type 2 + +# get electrode charges +variable q atom q +compute qbot bot reduce sum v_q +compute qtop top reduce sum v_q + +compute compute_pe all pe +variable vpe equal c_compute_pe +variable charge equal c_qtop +fix fxprint all print 1 "${vpe}, ${charge}" file "out.csv" + +thermo_style custom step pe c_qbot c_qtop + diff --git a/examples/PACKAGES/electrode/madelung/test.sh b/examples/PACKAGES/electrode/madelung/test.sh index edac04f5b1..a558ee6711 100644 --- a/examples/PACKAGES/electrode/madelung/test.sh +++ b/examples/PACKAGES/electrode/madelung/test.sh @@ -7,17 +7,27 @@ if [ ! -f $lmpbin ]; then fi ref_out="plate_cap.csv" -if [ ! -f $ref_out ]; then +ref_mix_out="plate_cap_eta_mix.csv" +if [ ! -f $ref_out ] || [ ! -f $ref_mix_out ]; then echo "Generating reference data" - python3 plate_cap.py > $ref_out + python3 plate_cap.py fi echo "Running Lammps inputs" +# w/o eta mixing rm -rf madelung.txt && touch madelung.txt -for file in in.*; do +for file in in.eta in.ewald-ew3dc in.ewald-ew2d in.pppm-ew3dc in.cg; do printf "\n$file\n" >> madelung.txt rm -f out.csv inv.csv vec.csv $lmpbin -i $file &> /dev/null python3 eval.py $ref_out out.csv inv.csv vec.csv done + +# with eta mixing +for file in in.eta_mix in.eta_cg; do + printf "\n$file\n" >> madelung.txt + rm -f out.csv inv.csv vec.csv + $lmpbin -i $file &> /dev/null + python3 eval.py $ref_mix_out out.csv inv.csv vec.csv +done cat madelung.txt diff --git a/src/ELECTRODE/electrode_matrix.cpp b/src/ELECTRODE/electrode_matrix.cpp index 7be9119c62..d917fb1f97 100644 --- a/src/ELECTRODE/electrode_matrix.cpp +++ b/src/ELECTRODE/electrode_matrix.cpp @@ -43,6 +43,7 @@ ElectrodeMatrix::ElectrodeMatrix(LAMMPS *lmp, int electrode_group, double eta) : groupbit = group->bitmask[igroup]; ngroup = group->count(igroup); this->eta = eta; + etaflag = false; tfflag = false; } @@ -72,6 +73,14 @@ void ElectrodeMatrix::setup_tf(const std::map &tf_types) /* ---------------------------------------------------------------------- */ +void ElectrodeMatrix::setup_eta(int index) +{ + etaflag = true; + eta_index = index; +} + +/* ---------------------------------------------------------------------- */ + void ElectrodeMatrix::compute_array(double **array, bool timer_flag) { // setting all entries of coulomb matrix to zero @@ -115,8 +124,6 @@ void ElectrodeMatrix::pair_contribution(double **array) int nlocal = atom->nlocal; int newton_pair = force->newton_pair; - double const etaij = eta * eta / sqrt(2.0 * eta * eta); // see mw ewald theory eq. (29)-(30) - // neighbor list will be ready because called from post_neighbor inum = list->inum; ilist = list->ilist; @@ -135,6 +142,7 @@ void ElectrodeMatrix::pair_contribution(double **array) xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; + double const eta_i = etaflag ? atom->dvector[eta_index][i] : eta; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; @@ -152,6 +160,9 @@ void ElectrodeMatrix::pair_contribution(double **array) jtype = type[j]; if (rsq < cutsq[itype][jtype]) { + double const eta_j = etaflag ? atom->dvector[eta_index][j] : eta; + double const etaij = eta_i * eta_j / sqrt(eta_i * eta_i + eta_j * eta_j); + r = sqrt(rsq); rinv = 1.0 / r; aij = rinv; @@ -178,7 +189,10 @@ void ElectrodeMatrix::self_contribution(double **array) const double preta = MY_SQRT2 / MY_PIS; for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit) { array[mpos[i]][mpos[i]] += preta * eta - selfint; } + if (mask[i] & groupbit) { + double const eta_i = etaflag ? atom->dvector[eta_index][i] : eta; + array[mpos[i]][mpos[i]] += preta * eta_i - selfint; + } } /* ---------------------------------------------------------------------- */ diff --git a/src/ELECTRODE/electrode_matrix.h b/src/ELECTRODE/electrode_matrix.h index 8499cfdb34..1c64d8a4c4 100644 --- a/src/ELECTRODE/electrode_matrix.h +++ b/src/ELECTRODE/electrode_matrix.h @@ -30,6 +30,7 @@ class ElectrodeMatrix : protected Pointers { ElectrodeMatrix(class LAMMPS *, int, double); void setup(const std::unordered_map &, class Pair *, class NeighList *); void setup_tf(const std::map &); + void setup_eta(int); void compute_array(double **, bool); int igroup; @@ -39,6 +40,8 @@ class ElectrodeMatrix : protected Pointers { double **cutsq; double g_ewald, eta; bool tfflag; + bool etaflag; + int eta_index; std::map tf_types; std::unordered_map tag_to_iele; bool assigned; diff --git a/src/ELECTRODE/electrode_vector.cpp b/src/ELECTRODE/electrode_vector.cpp index 245ba57727..a2eaf784c5 100644 --- a/src/ELECTRODE/electrode_vector.cpp +++ b/src/ELECTRODE/electrode_vector.cpp @@ -29,6 +29,7 @@ #include "neigh_list.h" #include "pair.h" +#include #include #include @@ -47,6 +48,7 @@ ElectrodeVector::ElectrodeVector(LAMMPS *lmp, int sensor_group, int source_group source_grpbit = group->bitmask[source_group]; this->eta = eta; tfflag = false; + etaflag = false; kspace_time_total = 0; pair_time_total = 0; @@ -93,6 +95,14 @@ void ElectrodeVector::setup_tf(const std::map &tf_types) /* ---------------------------------------------------------------------- */ +void ElectrodeVector::setup_eta(int index) +{ + etaflag = true; + eta_index = index; +} + +/* ---------------------------------------------------------------------- */ + void ElectrodeVector::compute_vector(double *vector) { MPI_Barrier(world); @@ -121,7 +131,6 @@ void ElectrodeVector::compute_vector(double *vector) void ElectrodeVector::pair_contribution(double *vector) { - double const etaij = eta * MY_ISQRT2; double **x = atom->x; double *q = atom->q; int *type = atom->type; @@ -142,6 +151,7 @@ void ElectrodeVector::pair_contribution(double *vector) double const xtmp = x[i][0]; double const ytmp = x[i][1]; double const ztmp = x[i][2]; + double const eta_i = etaflag ? atom->dvector[eta_index][i] : eta; int itype = type[i]; int *jlist = firstneigh[i]; int jnum = numneigh[i]; @@ -158,18 +168,22 @@ void ElectrodeVector::pair_contribution(double *vector) double const rsq = delx * delx + dely * dely + delz * delz; int jtype = type[j]; if (rsq >= cutsq[itype][jtype]) continue; + double const eta_j = etaflag ? atom->dvector[eta_index][j] : eta; + double etaij; + if (i_in_sensor && j_in_sensor) + etaij = eta_i * eta_j / sqrt(eta_i * eta_i + eta_j * eta_j); + else if (i_in_sensor) + etaij = eta_i; + else { + assert(j_in_sensor); + etaij = eta_j; + } double const r = sqrt(rsq); double const rinv = 1.0 / r; double aij = rinv; aij *= ElectrodeMath::safe_erfc(g_ewald * r); - if (invert_source) - aij -= ElectrodeMath::safe_erfc(eta * r) * rinv; - else - aij -= ElectrodeMath::safe_erfc(etaij * r) * rinv; - if (i_in_sensor) { - vector[i] += aij * q[j]; - //} else if (j_in_sensor) { - } + aij -= ElectrodeMath::safe_erfc(etaij * r) * rinv; + if (i_in_sensor) { vector[i] += aij * q[j]; } if (j_in_sensor && (!invert_source || !i_in_sensor)) { vector[j] += aij * q[i]; } } } @@ -189,9 +203,10 @@ void ElectrodeVector::self_contribution(double *vector) for (int ii = 0; ii < inum; ii++) { int const i = ilist[ii]; + double const eta_i = etaflag ? atom->dvector[eta_index][i] : eta; bool const i_in_sensor = (mask[i] & groupbit); bool const i_in_source = !!(mask[i] & source_grpbit) != invert_source; - if (i_in_sensor && i_in_source) vector[i] += (preta * eta - selfint) * q[i]; + if (i_in_sensor && i_in_source) vector[i] += (preta * eta_i - selfint) * q[i]; } } diff --git a/src/ELECTRODE/electrode_vector.h b/src/ELECTRODE/electrode_vector.h index e7f637dd2d..a4f274a049 100644 --- a/src/ELECTRODE/electrode_vector.h +++ b/src/ELECTRODE/electrode_vector.h @@ -29,6 +29,7 @@ class ElectrodeVector : protected Pointers { ~ElectrodeVector() override; void setup(class Pair *, class NeighList *, bool); void setup_tf(const std::map &); + void setup_eta(int); void compute_vector(double *); int igroup, source_group; @@ -39,6 +40,8 @@ class ElectrodeVector : protected Pointers { double **cutsq; double g_ewald, eta; bool tfflag; + bool etaflag; + int eta_index; std::map tf_types; class Pair *pair; class NeighList *list; diff --git a/src/ELECTRODE/fix_electrode_conp.cpp b/src/ELECTRODE/fix_electrode_conp.cpp index 13866cd394..a87642182b 100644 --- a/src/ELECTRODE/fix_electrode_conp.cpp +++ b/src/ELECTRODE/fix_electrode_conp.cpp @@ -97,6 +97,7 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : top_group = 0; intelflag = false; tfflag = false; + etaflag = false; timer_flag = false; update_time = 0; @@ -211,6 +212,19 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : qtotal = utils::numeric(FLERR, arg[iarg], false, lmp); qtotal_var_style = VarStyle::CONST; } + } else if ((strcmp(arg[iarg], "eta") == 0)) { + if (iarg + 2 > narg) error->all(FLERR, "Need two arguments after eta command"); + etaflag = true; + int is_double, cols; + eta_index = atom->find_custom(arg[++iarg] + 2, is_double, cols); + if (eta_index == -1) + error->all(FLERR, "eta keyword requires name of previously defined property"); + if (!is_double) error->all(FLERR, "eta keyword requires double-valued property/atom vector"); + if (cols != 0) error->all(FLERR, "eta keyword requires property/atom vector not an array"); + if (!atom->nextra_border) + error->all(FLERR, + "There is no fix with ghost on, but the eta keyword requires a property/atom " + "fix with ghost on"); // toggle parameters } else if ((strcmp(arg[iarg], "etypes") == 0)) { etypes_neighlists = utils::logical(FLERR, arg[++iarg], false, lmp); @@ -520,8 +534,10 @@ void FixElectrodeConp::setup_post_neighbor() evscale = force->qe2f / force->qqrd2e; elyt_vector->setup(pair, vec_neighlist, timer_flag); + if (etaflag) elyt_vector->setup_eta(eta_index); if (need_elec_vector) { elec_vector->setup(pair, mat_neighlist, timer_flag); + if (etaflag) elec_vector->setup_eta(eta_index); if (tfflag) elec_vector->setup_tf(tf_types); } @@ -556,7 +572,8 @@ void FixElectrodeConp::setup_post_neighbor() if (etypes_neighlists) neighbor->build_one(mat_neighlist, 0); auto array_compute = std::unique_ptr(new ElectrodeMatrix(lmp, igroup, eta)); array_compute->setup(tag_to_iele, pair, mat_neighlist); - if (tfflag) { array_compute->setup_tf(tf_types); } + if (etaflag) array_compute->setup_eta(eta_index); + if (tfflag) array_compute->setup_tf(tf_types); array_compute->compute_array(elastance, timer_flag); } // write_mat before proceeding if (comm->me == 0 && write_mat) { @@ -1186,7 +1203,7 @@ double FixElectrodeConp::self_energy(int eflag) // corrections to energy due to self interaction double const qqrd2e = force->qqrd2e; int const nlocal = atom->nlocal; - double const pre = eta / sqrt(MY_2PI) * qqrd2e; + double const pre = 1. / sqrt(MY_2PI) * qqrd2e; int *mask = atom->mask; int *type = atom->type; double *q = atom->q; @@ -1194,7 +1211,8 @@ double FixElectrodeConp::self_energy(int eflag) for (int i = 0; i < nlocal; i++) { if (groupbit & mask[i]) { double const q2 = q[i] * q[i]; - double e = pre * q2; + double ieta = etaflag ? atom->dvector[eta_index][i] : eta; + double e = ieta * pre * q2; if (tfflag && (groupbit & mask[i])) e += 0.5 * qqrd2e * q2 * tf_types[type[i]]; energy += e; if (eflag) { @@ -1234,6 +1252,7 @@ double FixElectrodeConp::gausscorr(int eflag, bool fflag) double xtmp = x[i][0]; double ytmp = x[i][1]; double ztmp = x[i][2]; + double const eta_i = etaflag ? atom->dvector[eta_index][i] : eta; int itype = type[i]; int *jlist = firstneigh[i]; int jnum = numneigh[i]; @@ -1242,7 +1261,6 @@ double FixElectrodeConp::gausscorr(int eflag, bool fflag) int const j = jlist[jj] & NEIGHMASK; bool j_in_ele = groupbit & mask[j]; if (!(i_in_ele || j_in_ele)) continue; - double eta_ij = (i_in_ele && j_in_ele) ? eta / MY_SQRT2 : eta; double delx = xtmp - x[j][0]; double dely = ytmp - x[j][1]; @@ -1251,6 +1269,16 @@ double FixElectrodeConp::gausscorr(int eflag, bool fflag) int jtype = type[j]; if (rsq < force->pair->cutsq[itype][jtype]) { + double const eta_j = etaflag ? atom->dvector[eta_index][j] : eta; + double eta_ij; + if (i_in_ele && j_in_ele) + eta_ij = eta_i * eta_j / sqrt(eta_i * eta_i + eta_j * eta_j); + else if (i_in_ele) + eta_ij = eta_i; + else { + assert(j_in_ele); + eta_ij = eta_j; + } double r2inv = 1.0 / rsq; double r = sqrt(rsq); double erfc_etar = 0.; diff --git a/src/ELECTRODE/fix_electrode_conp.h b/src/ELECTRODE/fix_electrode_conp.h index 689a44053c..fa972c0acc 100644 --- a/src/ELECTRODE/fix_electrode_conp.h +++ b/src/ELECTRODE/fix_electrode_conp.h @@ -138,6 +138,8 @@ class FixElectrodeConp : public Fix { int get_top_group(); // used by ffield int top_group; // used by ffield bool tfflag; + int eta_index; // index of atom property for eta + bool etaflag; // eta specified as atom property bool timer_flag; std::map tf_types; // cg From 61993d16432314055cc263779095f550c7d7a1db Mon Sep 17 00:00:00 2001 From: Leidy Lorena Alzate Vargas - 373576 Date: Wed, 22 Nov 2023 14:36:59 -0700 Subject: [PATCH 019/185] MLIAP Unified fix for multi layer models CPU only --- src/ML-IAP/mliap_unified.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/ML-IAP/mliap_unified.cpp b/src/ML-IAP/mliap_unified.cpp index de1d0bcb7d..6dcdf94c2d 100644 --- a/src/ML-IAP/mliap_unified.cpp +++ b/src/ML-IAP/mliap_unified.cpp @@ -254,10 +254,8 @@ void LAMMPS_NS::update_pair_energy(MLIAPData *data, double *eij) double e = 0.5 * eij[ii]; // must not count any contribution where i is not a local atom - if (i < nlocal) { - data->eatoms[i] += e; - e_total += e; - } + data->eatoms[i] += e; + e_total += e; } data->energy = e_total; } @@ -278,16 +276,14 @@ void LAMMPS_NS::update_pair_forces(MLIAPData *data, double *fij) int j = data->jatoms[ii]; // must not count any contribution where i is not a local atom - if (i < nlocal) { - f[i][0] += fij[ii3]; - f[i][1] += fij[ii3 + 1]; - f[i][2] += fij[ii3 + 2]; - f[j][0] -= fij[ii3]; - f[j][1] -= fij[ii3 + 1]; - f[j][2] -= fij[ii3 + 2]; + f[i][0] += fij[ii3]; + f[i][1] += fij[ii3 + 1]; + f[i][2] += fij[ii3 + 2]; + f[j][0] -= fij[ii3]; + f[j][1] -= fij[ii3 + 1]; + f[j][2] -= fij[ii3 + 2]; - if (data->vflag) data->pairmliap->v_tally(i, j, &fij[ii3], data->rij[ii]); - } + if (data->vflag) data->pairmliap->v_tally(i, j, &fij[ii3], data->rij[ii]); } } From 469358cbf4951c51472777bcd51055de9aaf2ed7 Mon Sep 17 00:00:00 2001 From: Leidy Lorena Alzate Vargas - 373576 Date: Wed, 22 Nov 2023 14:38:13 -0700 Subject: [PATCH 020/185] UPDATE KOKKOS --- src/KOKKOS/mliap_unified_kokkos.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/KOKKOS/mliap_unified_kokkos.cpp b/src/KOKKOS/mliap_unified_kokkos.cpp index 4c38e4f1d6..4a8c14d723 100644 --- a/src/KOKKOS/mliap_unified_kokkos.cpp +++ b/src/KOKKOS/mliap_unified_kokkos.cpp @@ -315,7 +315,6 @@ void LAMMPS_NS::update_pair_forces(MLIAPDataKokkosDevice *data, double *fij) int i = pair_i[ii]; int j = j_atoms[ii]; // must not count any contribution where i is not a local atom - if (i < nlocal) { Kokkos::atomic_add(&f[i*3+0], fij[ii3+0]); Kokkos::atomic_add(&f[i*3+1], fij[ii3+1]); Kokkos::atomic_add(&f[i*3+2], fij[ii3+2]); @@ -352,7 +351,6 @@ void LAMMPS_NS::update_pair_forces(MLIAPDataKokkosDevice *data, double *fij) Kokkos::atomic_add(&d_vatom(j,3), 0.5*v[3]); Kokkos::atomic_add(&d_vatom(j,4), 0.5*v[4]); Kokkos::atomic_add(&d_vatom(j,5), 0.5*v[5]); - } } } }); @@ -383,10 +381,8 @@ void LAMMPS_NS::update_atom_energy(MLIAPDataKokkosDevice *data, double *ei) Kokkos::parallel_reduce(nlocal, KOKKOS_LAMBDA(int i, double &local_sum){ double e = ei[i]; // must not count any contribution where i is not a local atom - if (i < nlocal) { - d_eatoms[i] = e; - local_sum += e; - } + d_eatoms[i] = e; + local_sum += e; },*data->energy); } From 82868cd583c1dab43c541340f43161e4e9a4f1aa Mon Sep 17 00:00:00 2001 From: Ludwig Ahrens Date: Mon, 4 Dec 2023 13:59:07 +0100 Subject: [PATCH 021/185] Simplify Madelung examples with mixed eta --- examples/PACKAGES/electrode/madelung/data.eta | 34 ------------------- .../PACKAGES/electrode/madelung/data.eta_mix | 34 ------------------- examples/PACKAGES/electrode/madelung/in.eta | 13 +++---- .../PACKAGES/electrode/madelung/in.eta_cg | 15 ++++---- .../PACKAGES/electrode/madelung/in.eta_mix | 13 +++---- .../electrode/madelung/settings_eta.mod | 19 ----------- 6 files changed, 16 insertions(+), 112 deletions(-) delete mode 100644 examples/PACKAGES/electrode/madelung/data.eta delete mode 100644 examples/PACKAGES/electrode/madelung/data.eta_mix delete mode 100644 examples/PACKAGES/electrode/madelung/settings_eta.mod diff --git a/examples/PACKAGES/electrode/madelung/data.eta b/examples/PACKAGES/electrode/madelung/data.eta deleted file mode 100644 index b05700a4ab..0000000000 --- a/examples/PACKAGES/electrode/madelung/data.eta +++ /dev/null @@ -1,34 +0,0 @@ -LAMMPS data file via write_data, version 24 Dec 2020, timestep = 0 - -4 atoms -3 atom types - -0 1 xlo xhi -0 1 ylo yhi --10 10 zlo zhi - -Masses - -1 196.966553 -2 196.966553 -3 1.0 - -Pair Coeffs # lj/cut/coul/long - -1 0 0 -2 0 0 -3 0 0 - -Atoms # full - -1 1 1 0.00 0.00 0.00 -2.00 # bottom electrode -2 2 2 0.00 0.00 0.00 2.00 # top electrode -3 3 3 0.50 0.00 0.00 -1.00 # bottom electrolyte -4 3 3 -0.50 0.00 0.00 1.00 # top electrolyte - -ETA - -1 2.0 -2 2.0 -3 0 -4 0 diff --git a/examples/PACKAGES/electrode/madelung/data.eta_mix b/examples/PACKAGES/electrode/madelung/data.eta_mix deleted file mode 100644 index 9322ebd662..0000000000 --- a/examples/PACKAGES/electrode/madelung/data.eta_mix +++ /dev/null @@ -1,34 +0,0 @@ -LAMMPS data file via write_data, version 24 Dec 2020, timestep = 0 - -4 atoms -3 atom types - -0 1 xlo xhi -0 1 ylo yhi --10 10 zlo zhi - -Masses - -1 196.966553 -2 196.966553 -3 1.0 - -Pair Coeffs # lj/cut/coul/long - -1 0 0 -2 0 0 -3 0 0 - -Atoms # full - -1 1 1 0.00 0.00 0.00 -2.00 # bottom electrode -2 2 2 0.00 0.00 0.00 2.00 # top electrode -3 3 3 0.50 0.00 0.00 -1.00 # bottom electrolyte -4 3 3 -0.50 0.00 0.00 1.00 # top electrolyte - -ETA - -1 0.5 -2 3.0 -3 0 -4 0 diff --git a/examples/PACKAGES/electrode/madelung/in.eta b/examples/PACKAGES/electrode/madelung/in.eta index d928f8fed0..3a45bb1bf5 100644 --- a/examples/PACKAGES/electrode/madelung/in.eta +++ b/examples/PACKAGES/electrode/madelung/in.eta @@ -1,16 +1,13 @@ -atom_style full -units real boundary p p f - kspace_style ewald/electrode 1.0e-8 kspace_modify slab 8.0 # ew3dc -pair_style lj/cut/coul/long 12 -fix feta all property/atom d_eta ghost yes -read_data data.eta fix feta NULL ETA - -include "settings_eta.mod" +include "settings.mod" # styles, computes, groups and fixes +thermo_style custom step pe c_qbot c_qtop +fix feta all property/atom d_eta ghost on +set group bot d_eta 2.0 +set group top d_eta 2.0 fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta write_inv inv.csv write_vec vec.csv run 0 diff --git a/examples/PACKAGES/electrode/madelung/in.eta_cg b/examples/PACKAGES/electrode/madelung/in.eta_cg index e04db318d5..5ac8cddf17 100644 --- a/examples/PACKAGES/electrode/madelung/in.eta_cg +++ b/examples/PACKAGES/electrode/madelung/in.eta_cg @@ -1,17 +1,14 @@ -atom_style full -units real boundary p p f - kspace_style ewald/electrode 1.0e-8 kspace_modify slab 8.0 # ew3dc -pair_style lj/cut/coul/long 12 -fix feta all property/atom d_eta ghost yes -read_data data.eta_mix fix feta NULL ETA +include "settings.mod" # styles, computes, groups and fixes -include "settings_eta.mod" - -fix conp bot electrode/conp 0 2 couple top 1 symm on algo cg 1e-6 eta d_eta +thermo_style custom step pe c_qbot c_qtop +fix feta all property/atom d_eta ghost on +set group bot d_eta 0.5 +set group top d_eta 3.0 +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta algo cg 1e-6 run 0 diff --git a/examples/PACKAGES/electrode/madelung/in.eta_mix b/examples/PACKAGES/electrode/madelung/in.eta_mix index d4bcf71225..d00e008fa4 100644 --- a/examples/PACKAGES/electrode/madelung/in.eta_mix +++ b/examples/PACKAGES/electrode/madelung/in.eta_mix @@ -1,16 +1,13 @@ -atom_style full -units real boundary p p f - kspace_style ewald/electrode 1.0e-8 kspace_modify slab 8.0 # ew3dc -pair_style lj/cut/coul/long 12 +include "settings.mod" # styles, computes, groups and fixes + +thermo_style custom step pe c_qbot c_qtop fix feta all property/atom d_eta ghost on -read_data data.eta_mix fix feta NULL ETA - -include "settings_eta.mod" - +set group bot d_eta 0.5 +set group top d_eta 3.0 fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta write_inv inv.csv write_vec vec.csv run 0 diff --git a/examples/PACKAGES/electrode/madelung/settings_eta.mod b/examples/PACKAGES/electrode/madelung/settings_eta.mod deleted file mode 100644 index aee63bf2e9..0000000000 --- a/examples/PACKAGES/electrode/madelung/settings_eta.mod +++ /dev/null @@ -1,19 +0,0 @@ - -# distribute electrode atoms among all processors: -if "$(extract_setting(world_size) % 2) == 0" then "processors * * 2" - -group bot type 1 -group top type 2 - -# get electrode charges -variable q atom q -compute qbot bot reduce sum v_q -compute qtop top reduce sum v_q - -compute compute_pe all pe -variable vpe equal c_compute_pe -variable charge equal c_qtop -fix fxprint all print 1 "${vpe}, ${charge}" file "out.csv" - -thermo_style custom step pe c_qbot c_qtop - From e69a079545dcf9801f0099c268fb781567fe7b61 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Wed, 20 Dec 2023 10:50:54 -0700 Subject: [PATCH 022/185] Fixing invalid variable deform kokkos --- src/KOKKOS/fix_deform_kokkos.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/KOKKOS/fix_deform_kokkos.cpp b/src/KOKKOS/fix_deform_kokkos.cpp index 104ac41188..7a2b3e2481 100644 --- a/src/KOKKOS/fix_deform_kokkos.cpp +++ b/src/KOKKOS/fix_deform_kokkos.cpp @@ -120,11 +120,11 @@ void FixDeformKokkos::end_of_step() } else if (set[i].style == WIGGLE) { double delt = (update->ntimestep - update->beginstep) * update->dt; set[i].lo_target = set[i].lo_start - - 0.5*set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); + 0.5*set[i].amplitude * sin(MY_2PI*delt/set[i].tperiod); set[i].hi_target = set[i].hi_start + - 0.5*set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); - h_rate[i] = TWOPI/set[i].tperiod * set[i].amplitude * - cos(TWOPI*delt/set[i].tperiod); + 0.5*set[i].amplitude * sin(MY_2PI*delt/set[i].tperiod); + h_rate[i] = MY_2PI/set[i].tperiod * set[i].amplitude * + cos(MY_2PI*delt/set[i].tperiod); h_ratelo[i] = -0.5*h_rate[i]; } else if (set[i].style == VARIABLE) { double del = input->variable->compute_equal(set[i].hvar); @@ -212,9 +212,9 @@ void FixDeformKokkos::end_of_step() } else if (set[i].style == WIGGLE) { double delt = (update->ntimestep - update->beginstep) * update->dt; set[i].tilt_target = set[i].tilt_start + - set[i].amplitude * sin(TWOPI*delt/set[i].tperiod); - h_rate[i] = TWOPI/set[i].tperiod * set[i].amplitude * - cos(TWOPI*delt/set[i].tperiod); + set[i].amplitude * sin(MY_2PI*delt/set[i].tperiod); + h_rate[i] = MY_2PI/set[i].tperiod * set[i].amplitude * + cos(MY_2PI*delt/set[i].tperiod); } else if (set[i].style == VARIABLE) { double delta_tilt = input->variable->compute_equal(set[i].hvar); set[i].tilt_target = set[i].tilt_start + delta_tilt; From d61c379b0caa0b50b6fac0942c7bba191c4b4143 Mon Sep 17 00:00:00 2001 From: Ludwig Ahrens Date: Thu, 21 Dec 2023 14:28:54 +0100 Subject: [PATCH 023/185] Error formatting --- src/ELECTRODE/fix_electrode_conp.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ELECTRODE/fix_electrode_conp.cpp b/src/ELECTRODE/fix_electrode_conp.cpp index a87642182b..091840148d 100644 --- a/src/ELECTRODE/fix_electrode_conp.cpp +++ b/src/ELECTRODE/fix_electrode_conp.cpp @@ -522,11 +522,9 @@ void FixElectrodeConp::setup_post_neighbor() if (qtotal_var_style == VarStyle::EQUAL) { const char *var_name = qtotal_var_name.c_str(); int var_id = input->variable->find(var_name); - if (var_id < 0) - error->all(FLERR, fmt::format("Variable '{}' for fix electrode does not exist", var_name)); + if (var_id < 0) error->all(FLERR, "Variable '{}' for fix electrode does not exist", var_name); if (!input->variable->equalstyle(var_id)) - error->all(FLERR, - fmt::format("Variable '{}' for fix electrode is not equal-style", var_name)); + error->all(FLERR, "Variable '{}' for fix electrode is not equal-style", var_name); qtotal_var_id = var_id; } From 8e3b5bf32730d43373881a9a06364a975399522c Mon Sep 17 00:00:00 2001 From: Ben Nebgen Date: Fri, 5 Jan 2024 13:05:27 -0700 Subject: [PATCH 024/185] Fixed memory bug in ML-IAP unified with atom name definitions Added explict memory allocation for type string in ML-IAP unified. Corrected bug where atom types were not properly alligned with the potential. --- src/KOKKOS/mliap_unified_couple_kokkos.pyx | 18 ++++++++++++++---- src/ML-IAP/mliap_unified_couple.pyx | 20 ++++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/KOKKOS/mliap_unified_couple_kokkos.pyx b/src/KOKKOS/mliap_unified_couple_kokkos.pyx index 97d807ac33..385a770bb3 100644 --- a/src/KOKKOS/mliap_unified_couple_kokkos.pyx +++ b/src/KOKKOS/mliap_unified_couple_kokkos.pyx @@ -13,6 +13,7 @@ from libc.stdint cimport uintptr_t cimport cython from cpython.ref cimport PyObject from libc.stdlib cimport malloc, free +from libc.string cimport memcpy cdef extern from "lammps.h" namespace "LAMMPS_NS": @@ -451,15 +452,24 @@ cdef public object mliap_unified_connect_kokkos(char *fname, MLIAPDummyModel * m cdef int nelements = len(unified.element_types) cdef char **elements = malloc(nelements * sizeof(char*)) + cdef char * c_str + cdef char * s + cdef ssize_t slen if not elements: raise MemoryError("failed to allocate memory for element names") - cdef char *elem_name for i, elem in enumerate(unified.element_types): - elem_name_bytes = elem.encode('UTF-8') - elem_name = elem_name_bytes - elements[i] = &elem_name[0] + py_str = elem.encode('UTF-8') + s = py_str + slen = len(py_str) + c_str = malloc((slen+1)*sizeof(char)) + if not c_str: + raise MemoryError("failed to allocate memory for element names") + memcpy(c_str, s, slen) + c_str[slen] = 0 + elements[i] = c_str + unified_int.descriptor.set_elements(elements, nelements) unified_int.model.nelements = nelements diff --git a/src/ML-IAP/mliap_unified_couple.pyx b/src/ML-IAP/mliap_unified_couple.pyx index 3148b96b51..6c8331d0fa 100644 --- a/src/ML-IAP/mliap_unified_couple.pyx +++ b/src/ML-IAP/mliap_unified_couple.pyx @@ -8,6 +8,7 @@ import lammps.mliap cimport cython from cpython.ref cimport PyObject from libc.stdlib cimport malloc, free +from libc.string cimport memcpy cdef extern from "lammps.h" namespace "LAMMPS_NS": @@ -387,15 +388,26 @@ cdef public object mliap_unified_connect(char *fname, MLIAPDummyModel * model, cdef int nelements = len(unified.element_types) cdef char **elements = malloc(nelements * sizeof(char*)) + cdef char * c_str + cdef char * s + cdef ssize_t slen if not elements: raise MemoryError("failed to allocate memory for element names") - cdef char *elem_name for i, elem in enumerate(unified.element_types): - elem_name_bytes = elem.encode('UTF-8') - elem_name = elem_name_bytes - elements[i] = &elem_name[0] + py_str = elem.encode('UTF-8') + + s = py_str + slen = len(py_str) + c_str = malloc((slen+1)*sizeof(char)) + if not c_str: + raise MemoryError("failed to allocate memory for element names") + memcpy(c_str, s, slen) + c_str[slen] = 0 + + elements[i] = c_str + unified_int.descriptor.set_elements(elements, nelements) unified_int.model.nelements = nelements From 87b2662ee9351958b8a2af0c0ae27b41796ad33a Mon Sep 17 00:00:00 2001 From: jtclemm Date: Mon, 22 Jan 2024 21:21:20 -0700 Subject: [PATCH 025/185] Moving pressure options to subclass --- doc/src/fix_deform.rst | 201 +--- doc/src/fix_deform_pressure.rst | 793 ++++++++++++++++ src/.gitignore | 2 + src/EXTRA-FIX/fix_deform_pressure.cpp | 905 ++++++++++++++++++ src/EXTRA-FIX/fix_deform_pressure.h | 60 ++ src/fix_deform.cpp | 1223 +++++++------------------ src/fix_deform.h | 20 +- 7 files changed, 2082 insertions(+), 1122 deletions(-) create mode 100644 doc/src/fix_deform_pressure.rst create mode 100644 src/EXTRA-FIX/fix_deform_pressure.cpp create mode 100644 src/EXTRA-FIX/fix_deform_pressure.h diff --git a/doc/src/fix_deform.rst b/doc/src/fix_deform.rst index a4d449850e..924397c42a 100644 --- a/doc/src/fix_deform.rst +++ b/doc/src/fix_deform.rst @@ -20,7 +20,7 @@ Syntax .. parsed-literal:: - parameter = *x* or *y* or *z* or *xy* or *xz* or *yz* or *iso* + parameter = *x* or *y* or *z* or *xy* or *xz* or *yz* *x*, *y*, *z* args = style value(s) style = *final* or *delta* or *scale* or *vel* or *erate* or *trate* or *volume* or *wiggle* or *variable* *final* values = lo hi @@ -34,12 +34,6 @@ Syntax effectively an engineering strain rate *erate* value = R R = engineering strain rate (1/time units) - *pressure* values = target gain - target = target pressure (pressure units) - gain = proportional gain constant (1/(time * pressure) or 1/time units) - *pressure/mean* values = target gain - target = target pressure (pressure units) - gain = proportional gain constant (1/(time * pressure) or 1/time units) *trate* value = R R = true strain rate (1/time units) *volume* value = none = adjust this dim to preserve volume of system @@ -60,9 +54,6 @@ Syntax effectively an engineering shear strain rate *erate* value = R R = engineering shear strain rate (1/time units) - *pressure* values = target gain - target = target pressure (pressure units) - gain = proportional gain constant (1/(time * pressure) or 1/time units) *trate* value = R R = true shear strain rate (1/time units) *wiggle* values = A Tp @@ -71,15 +62,9 @@ Syntax *variable* values = v_name1 v_name2 v_name1 = variable with name1 for tilt change as function of time v_name2 = variable with name2 for change rate as function of time - *iso* = style value - style = *volume* or *pressure* - *volume* value = none = isotropically adjust system to preserve volume of system - *pressure* values = target gain - target = target mean pressure (pressure units) - gain = proportional gain constant (1/(time * pressure) or 1/time units) * zero or more keyword/value pairs may be appended -* keyword = *remap* or *flip* or *units* or *couple* or *vol/balance/p* or *max/rate* or *normalize/pressure* +* keyword = *remap* or *flip* or *units* .. parsed-literal:: @@ -92,14 +77,6 @@ Syntax *units* value = *lattice* or *box* lattice = distances are defined in lattice units box = distances are defined in simulation box units - *couple* value = *none* or *xyz* or *xy* or *yz* or *xz* - couple pressure values of various dimensions - *vol/balance/p* value = *yes* or *no* - Modifies the behavior of the *volume* option to try and balance pressures - *max/rate* value = *rate* - rate = maximum strain rate for pressure control - *normalize/pressure* value = *yes* or *no* - Modifies pressure controls such that the deviation in pressure is normalized by the target pressure Examples """""""" @@ -110,9 +87,6 @@ Examples fix 1 all deform 1 x trate 0.1 y volume z volume fix 1 all deform 1 xy erate 0.001 remap v fix 1 all deform 10 y delta -0.5 0.5 xz vel 1.0 - fix 1 all deform 1 x pressure 2.0 0.1 normalize/pressure yes max/rate 0.001 - fix 1 all deform 1 x trate 0.1 y volume z volume vol/balance/p yes - fix 1 all deform 1 x trate 0.1 y pressure/mean 0.0 1.0 z pressure/mean 0.0 1.0 Description """"""""""" @@ -256,11 +230,7 @@ the product of x,z lengths constant. If "x scale 1.1 y volume z volume" is specified, then both the y,z box lengths will shrink as x increases to keep the volume constant (product of x,y,z lengths). In this case, the y,z box lengths shrink so as to keep their relative -aspect ratio constant. When maintaining a constant volume using two -separate dimensions, one can alternatively allow the two dimensions -to adjust their aspect ratio to attempt to maintain equivalent -pressures along the two dimensions. See the -:ref:`vol/balance/p ` option for more details. +aspect ratio constant. For solids or liquids, note that when one dimension of the box is expanded via fix deform (i.e. tensile strain), it may be physically @@ -322,39 +292,6 @@ For the *scale*, *vel*, *erate*, *trate*, *volume*, *wiggle*, and *variable* styles, the box length is expanded or compressed around its mid point. -The *pressure* style adjusts a dimensions's box length to control that -component of the pressure tensor. This option attempts to maintain a -specified target value using a linear controller where the box length -:math:`L` evolves according to the equation - -.. parsed-literal:: - - \frac{d L(t)}{dt} = L(t) k (P_t - P) - -where :math:`k` is a proportional gain constant, :math:`P_t` is the target -pressure, and :math:`P` is the current pressure along that dimension. This -approach is similar to the method used to control the pressure by -:doc:`fix press/berendsen `. The target pressure -accepts either a constant numeric value or a LAMMPS :ref:`variable `. -Notably, this variable can be a function of time or other components of -the pressure tensor. By default, :math:`k` has units of 1/(time * pressure) -although this will change if the *normalize/pessure* option is set as -:ref:`discussed below `. There is no proven method -to choosing an appropriate value of :math:`k` as it will depend on the -specific details of a simulation and testing different values is -recommended. One can also apply a maximum limit to the magnitude of the -applied strain using the :ref:`max/rate ` option and couple -pressures in different dimensions using the :ref:`couple ` -option. - -The *pressure/mean* style changes a dimension's box length to maintain -a constant mean pressure defined as the trace of the pressure tensor. -This option is therefore very similar to the *pressure* style with -identical arguments except the current and target pressures refer to the -mean trace of the pressure tensor. All options for the *pressure* style -also apply to the *pressure/mean* style except for the -:ref:`couple ` option. - ---------- For the *xy*, *xz*, and *yz* parameters, this is the meaning of their @@ -496,46 +433,6 @@ assume that the current timestep = 0. variable rate equal "2*PI*v_A/v_Tp * cos(2*PI * step*dt/v_Tp)" fix 2 all deform 1 xy variable v_displace v_rate remap v -The *pressure* style adjusts a tilt factor to control the corresponding -off-diagonal component of the pressure tensor. This option attempts to -maintain a specified target value using a linear controller where the -tilt factor T evolves according to the equation - -.. parsed-literal:: - - \frac{d T(t)}{dt} = L(t) k (P - P_t) - -where :math:`k` is a proportional gain constant, :math:`P_t` is the target -pressure, :math:`P` is the current pressure, and :math:`L` is the perpendicular -box length. The target pressure accepts either a constant numeric value or a -LAMMPS :ref:`variable `. Notably, this variable can be a function -of time or other components of the pressure tensor. By default, :math:`k` -has units of 1/(time * pressure) although this will change if the -*normalize/pessure* option is set as :ref:`discussed below `. -There is no proven method to choosing an appropriate value of :math:`k` as it -will depend on thespecific details of a simulation and testing different -values isrecommended. One can also apply a maximum limit to the magnitude -of the applied strain using the :ref:`max/rate ` option. - ----------- - -The *iso* parameter provides an additonal control over the x, y, -and z box lengths. This parameter can only be used in combination with -the *x*, *y*, or *z* comamnds: *vel*, *erate*, *trate*, *pressure*, or -*wiggle*. Note that this parameter will change the overall strain rate in -the *x*, *y*, or *z* dimensions. This is the meaning of its styles and values. - -The *volume* style isotropically scales box lengths to maintain a constant -box volume in response to deformation from other parameters. - -The *pressure* style controls the box volume to maintain the mean pressure -of the system. This is accomplished by isotropically scaling all box -lengths :math:`L` by an additional factor of :math:`k (P_t - P_m)` where -:math:`k` is the proportional gain constant, :math:`P_t` is the target -pressure, and :math:`P_m` is the current mean pressure (the trace of the -pressure tensor). This style allows one to control the deviatoric strain -tensor while maintaining a fixed mean pressure. - ---------- All of the tilt styles change the xy, xz, yz tilt factors during a @@ -664,77 +561,6 @@ does not affect the *variable* style. You should use the *xlat*, *ylat*, *zlat* keywords of the :doc:`thermo_style ` command if you want to include lattice spacings in a variable formula. -.. _deform_normalize: - -The *normalize/pressure* keyword changes how box dimensions evolve when -using the *pressure* or *pressure/mean* deformation options. If the -*deform/normalize* value is set to *yes*, then the deviation from the -target pressure is normalized by the absolute value of the target -pressure such that the proportional gain constant scales a percentage -error and has units of 1/time. If the target pressure is ever zero, this -will produce an error unless the *max/rate* keyword is defined, -described below, which will cap the divergence. - -.. _deform_max_rate: - -The *max/rate* keyword sets an upper threshold, *rate*, that limits the -maximum magnitude of the instantaneous strain rate applied in any dimension. -This keyword only applies to the *pressure* and *pressure/mean* options. If -a pressure-controlled rate is used for both *iso* and either *x*, *y*, or -*z*, then this threshold will apply separately to each individual controller -such that the cumulative strain rate on a box dimension may be up to twice -the value of *rate*. - -.. _deform_couple: - -The *couple* keyword allows two or three of the diagonal components of -the pressure tensor to be "coupled" together for the *pressure* option. -The value specified with the keyword determines which are coupled. For -example, *xz* means the *Pxx* and *Pzz* components of the stress tensor -are coupled. *Xyz* means all 3 diagonal components are coupled. Coupling -means two things: the instantaneous stress will be computed as an average -of the corresponding diagonal components, and the coupled box dimensions -will be changed together in lockstep, meaning coupled dimensions will be -dilated or contracted by the same percentage every timestep. The target -pressures and gain constants for any coupled dimensions must be identical. -*Couple xyz* can be used for a 2d simulation; the *z* dimension is simply -ignored. - -.. _deform_balance: - -The *vol/balance/p* keyword modifies the behavior of *volume* when two -dimensions are used to maintain a fixed volume. Instead of straining -the two dimensions in lockstep, the two dimensions are allowed to -separately dilate or contract in a manner to maintain a constant -volume while simultaneously trying to keep the pressure along each -dimension equal using a method described in :ref:`(Huang2014) `. - ----------- - -If any pressure controls are used, this fix computes a temperature and -pressure each timestep. To do this, the fix creates its own computes of -style "temp" and "pressure", as if these commands had been issued: - -.. code-block:: LAMMPS - - compute fix-ID_temp group-ID temp - compute fix-ID_press group-ID pressure fix-ID_temp - -See the :doc:`compute temp ` and :doc:`compute pressure ` commands for details. Note that the -IDs of the new computes are the fix-ID + underscore + "temp" or fix_ID -+ underscore + "press", and the group for the new computes is the same -as the fix group. - -Note that these are NOT the computes used by thermodynamic output (see -the :doc:`thermo_style ` command) with ID = *thermo_temp* -and *thermo_press*. This means you can change the attributes of this -fix's temperature or pressure via the -:doc:`compute_modify ` command or print this temperature -or pressure during thermodynamic output via the -:doc:`thermo_style custom ` command using the appropriate -compute-ID. It also means that changing attributes of *thermo_temp* or -*thermo_press* will have no effect on this fix. - ---------- .. include:: accel_styles.rst @@ -748,15 +574,6 @@ command. None of the :doc:`fix_modify ` options are relevant to this fix. No global or per-atom quantities are stored by this fix for access by various :doc:`output commands `. -If any pressure controls are used, the :doc:`fix_modify ` *temp* -and *press* options are supported by this fix. You can use them to assign a -:doc:`compute ` you have defined to this fix which will be used -in its temperature and pressure calculations. If you do this, note -that the kinetic energy derived from the compute temperature should be -consistent with the virial term computed using all atoms for the -pressure. LAMMPS will warn you if you choose to compute temperature -on a subset of atoms. - This fix can perform deformation over multiple runs, using the *start* and *stop* keywords of the :doc:`run ` command. See the :doc:`run ` command for details of how to do this. @@ -780,14 +597,4 @@ Related commands Default """"""" -The option defaults are remap = x, flip = yes, units = lattice, and -normalize/pressure = no. - ----------- - -.. _Li2014b: - -**(Huang2014)** X. Huang, -"Exploring critical-state behavior using DEM", -Doctoral dissertation, Imperial College. -(2014). https://doi.org/10.25560/25316 +The option defaults are remap = x, flip = yes, units = lattice diff --git a/doc/src/fix_deform_pressure.rst b/doc/src/fix_deform_pressure.rst new file mode 100644 index 0000000000..d19e5fba7e --- /dev/null +++ b/doc/src/fix_deform_pressure.rst @@ -0,0 +1,793 @@ +.. index:: fix deform +.. index:: fix deform/kk + +fix deform command +================== + +Accelerator Variants: *deform/kk* + +Syntax +"""""" + +.. parsed-literal:: + + fix ID group-ID deform N parameter args ... keyword value ... + +* ID, group-ID are documented in :doc:`fix ` command +* deform = style name of this fix command +* N = perform box deformation every this many timesteps +* one or more parameter/arg pairs may be appended + + .. parsed-literal:: + + parameter = *x* or *y* or *z* or *xy* or *xz* or *yz* or *iso* + *x*, *y*, *z* args = style value(s) + style = *final* or *delta* or *scale* or *vel* or *erate* or *trate* or *volume* or *wiggle* or *variable* + *final* values = lo hi + lo hi = box boundaries at end of run (distance units) + *delta* values = dlo dhi + dlo dhi = change in box boundaries at end of run (distance units) + *scale* values = factor + factor = multiplicative factor for change in box length at end of run + *vel* value = V + V = change box length at this velocity (distance/time units), + effectively an engineering strain rate + *erate* value = R + R = engineering strain rate (1/time units) + *pressure* values = target gain + target = target pressure (pressure units) + gain = proportional gain constant (1/(time * pressure) or 1/time units) + *pressure/mean* values = target gain + target = target pressure (pressure units) + gain = proportional gain constant (1/(time * pressure) or 1/time units) + *trate* value = R + R = true strain rate (1/time units) + *volume* value = none = adjust this dim to preserve volume of system + *wiggle* values = A Tp + A = amplitude of oscillation (distance units) + Tp = period of oscillation (time units) + *variable* values = v_name1 v_name2 + v_name1 = variable with name1 for box length change as function of time + v_name2 = variable with name2 for change rate as function of time + *xy*, *xz*, *yz* args = style value + style = *final* or *delta* or *vel* or *erate* or *trate* or *wiggle* + *final* value = tilt + tilt = tilt factor at end of run (distance units) + *delta* value = dtilt + dtilt = change in tilt factor at end of run (distance units) + *vel* value = V + V = change tilt factor at this velocity (distance/time units), + effectively an engineering shear strain rate + *erate* value = R + R = engineering shear strain rate (1/time units) + *pressure* values = target gain + target = target pressure (pressure units) + gain = proportional gain constant (1/(time * pressure) or 1/time units) + *trate* value = R + R = true shear strain rate (1/time units) + *wiggle* values = A Tp + A = amplitude of oscillation (distance units) + Tp = period of oscillation (time units) + *variable* values = v_name1 v_name2 + v_name1 = variable with name1 for tilt change as function of time + v_name2 = variable with name2 for change rate as function of time + *iso* = style value + style = *volume* or *pressure* + *volume* value = none = isotropically adjust system to preserve volume of system + *pressure* values = target gain + target = target mean pressure (pressure units) + gain = proportional gain constant (1/(time * pressure) or 1/time units) + +* zero or more keyword/value pairs may be appended +* keyword = *remap* or *flip* or *units* or *couple* or *vol/balance/p* or *max/rate* or *normalize/pressure* + + .. parsed-literal:: + + *remap* value = *x* or *v* or *none* + x = remap coords of atoms in group into deforming box + v = remap velocities of atoms in group when they cross periodic boundaries + none = no remapping of x or v + *flip* value = *yes* or *no* + allow or disallow box flips when it becomes highly skewed + *units* value = *lattice* or *box* + lattice = distances are defined in lattice units + box = distances are defined in simulation box units + *couple* value = *none* or *xyz* or *xy* or *yz* or *xz* + couple pressure values of various dimensions + *vol/balance/p* value = *yes* or *no* + Modifies the behavior of the *volume* option to try and balance pressures + *max/rate* value = *rate* + rate = maximum strain rate for pressure control + *normalize/pressure* value = *yes* or *no* + Modifies pressure controls such that the deviation in pressure is normalized by the target pressure + +Examples +"""""""" + +.. code-block:: LAMMPS + + fix 1 all deform 1 x final 0.0 9.0 z final 0.0 5.0 units box + fix 1 all deform 1 x trate 0.1 y volume z volume + fix 1 all deform 1 xy erate 0.001 remap v + fix 1 all deform 10 y delta -0.5 0.5 xz vel 1.0 + fix 1 all deform 1 x pressure 2.0 0.1 normalize/pressure yes max/rate 0.001 + fix 1 all deform 1 x trate 0.1 y volume z volume vol/balance/p yes + fix 1 all deform 1 x trate 0.1 y pressure/mean 0.0 1.0 z pressure/mean 0.0 1.0 + +Description +""""""""""" + +Change the volume and/or shape of the simulation box during a dynamics +run. Orthogonal simulation boxes have 3 adjustable parameters +(x,y,z). Triclinic (non-orthogonal) simulation boxes have 6 +adjustable parameters (x,y,z,xy,xz,yz). Any or all of them can be +adjusted independently and simultaneously by this command. + +This fix can be used to perform non-equilibrium MD (NEMD) simulations +of a continuously strained system. See the :doc:`fix nvt/sllod ` and :doc:`compute temp/deform ` commands for more details. Note +that simulation of a continuously extended system (extensional flow) +can be modeled using the :ref:`UEF package ` and its :doc:`fix commands `. + +For the *x*, *y*, *z* parameters, the associated dimension cannot be +shrink-wrapped. For the *xy*, *yz*, *xz* parameters, the associated +second dimension cannot be shrink-wrapped. Dimensions not varied by this +command can be periodic or non-periodic. Dimensions corresponding to +unspecified parameters can also be controlled by a :doc:`fix npt ` or :doc:`fix nph ` command. + +The size and shape of the simulation box at the beginning of the +simulation run were either specified by the +:doc:`create_box ` or :doc:`read_data ` or +:doc:`read_restart ` command used to setup the simulation +initially if it is the first run, or they are the values from the end +of the previous run. The :doc:`create_box `, :doc:`read data `, and :doc:`read_restart ` commands +specify whether the simulation box is orthogonal or non-orthogonal +(triclinic) and explain the meaning of the xy,xz,yz tilt factors. If +fix deform changes the xy,xz,yz tilt factors, then the simulation box +must be triclinic, even if its initial tilt factors are 0.0. + +As described below, the desired simulation box size and shape at the +end of the run are determined by the parameters of the fix deform +command. Every Nth timestep during the run, the simulation box is +expanded, contracted, or tilted to ramped values between the initial +and final values. + +---------- + +For the *x*, *y*, and *z* parameters, this is the meaning of their +styles and values. + +The *final*, *delta*, *scale*, *vel*, and *erate* styles all change +the specified dimension of the box via "constant displacement" which +is effectively a "constant engineering strain rate". This means the +box dimension changes linearly with time from its initial to final +value. + +For style *final*, the final lo and hi box boundaries of a dimension +are specified. The values can be in lattice or box distance units. +See the discussion of the units keyword below. + +For style *delta*, plus or minus changes in the lo/hi box boundaries +of a dimension are specified. The values can be in lattice or box +distance units. See the discussion of the units keyword below. + +For style *scale*, a multiplicative factor to apply to the box length +of a dimension is specified. For example, if the initial box length +is 10, and the factor is 1.1, then the final box length will be 11. A +factor less than 1.0 means compression. + +For style *vel*, a velocity at which the box length changes is +specified in units of distance/time. This is effectively a "constant +engineering strain rate", where rate = V/L0 and L0 is the initial box +length. The distance can be in lattice or box distance units. See +the discussion of the units keyword below. For example, if the +initial box length is 100 Angstroms, and V is 10 Angstroms/ps, then +after 10 ps, the box length will have doubled. After 20 ps, it +will have tripled. + +The *erate* style changes a dimension of the box at a "constant +engineering strain rate". The units of the specified strain rate are +1/time. See the :doc:`units ` command for the time units +associated with different choices of simulation units, +e.g. picoseconds for "metal" units). Tensile strain is unitless and +is defined as delta/L0, where L0 is the original box length and delta +is the change relative to the original length. The box length L as a +function of time will change as + +.. parsed-literal:: + + L(t) = L0 (1 + erate\*dt) + +where dt is the elapsed time (in time units). Thus if *erate* R is +specified as 0.1 and time units are picoseconds, this means the box +length will increase by 10% of its original length every picosecond. +I.e. strain after 1 ps = 0.1, strain after 2 ps = 0.2, etc. R = +-0.01 means the box length will shrink by 1% of its original length +every picosecond. Note that for an "engineering" rate the change is +based on the original box length, so running with R = 1 for 10 +picoseconds expands the box length by a factor of 11 (strain of 10), +which is different that what the *trate* style would induce. + +The *trate* style changes a dimension of the box at a "constant true +strain rate". Note that this is not an "engineering strain rate", as +the other styles are. Rather, for a "true" rate, the rate of change +is constant, which means the box dimension changes non-linearly with +time from its initial to final value. The units of the specified +strain rate are 1/time. See the :doc:`units ` command for the +time units associated with different choices of simulation units, +e.g. picoseconds for "metal" units). Tensile strain is unitless and +is defined as delta/L0, where L0 is the original box length and delta +is the change relative to the original length. + +The box length L as a function of time will change as + +.. parsed-literal:: + + L(t) = L0 exp(trate\*dt) + +where dt is the elapsed time (in time units). Thus if *trate* R is +specified as ln(1.1) and time units are picoseconds, this means the +box length will increase by 10% of its current (not original) length +every picosecond. I.e. strain after 1 ps = 0.1, strain after 2 ps += 0.21, etc. R = ln(2) or ln(3) means the box length will double or +triple every picosecond. R = ln(0.99) means the box length will +shrink by 1% of its current length every picosecond. Note that for a +"true" rate the change is continuous and based on the current length, +so running with R = ln(2) for 10 picoseconds does not expand the box +length by a factor of 11 as it would with *erate*, but by a factor of +1024 since the box length will double every picosecond. + +Note that to change the volume (or cross-sectional area) of the +simulation box at a constant rate, you can change multiple dimensions +via *erate* or *trate*\ . E.g. to double the box volume in a picosecond +picosecond, you could set "x erate M", "y erate M", "z erate M", with +M = pow(2,1/3) - 1 = 0.26, since if each box dimension grows by 26%, +the box volume doubles. Or you could set "x trate M", "y trate M", "z +trate M", with M = ln(1.26) = 0.231, and the box volume would double +every picosecond. + +The *volume* style changes the specified dimension in such a way that +the box volume remains constant while other box dimensions are changed +explicitly via the styles discussed above. For example, "x scale 1.1 +y scale 1.1 z volume" will shrink the z box length as the x,y box +lengths increase, to keep the volume constant (product of x,y,z +lengths). If "x scale 1.1 z volume" is specified and parameter *y* is +unspecified, then the z box length will shrink as x increases to keep +the product of x,z lengths constant. If "x scale 1.1 y volume z +volume" is specified, then both the y,z box lengths will shrink as x +increases to keep the volume constant (product of x,y,z lengths). In +this case, the y,z box lengths shrink so as to keep their relative +aspect ratio constant. When maintaining a constant volume using two +separate dimensions, one can alternatively allow the two dimensions +to adjust their aspect ratio to attempt to maintain equivalent +pressures along the two dimensions. See the +:ref:`vol/balance/p ` option for more details. + +For solids or liquids, note that when one dimension of the box is +expanded via fix deform (i.e. tensile strain), it may be physically +undesirable to hold the other 2 box lengths constant (unspecified by +fix deform) since that implies a density change. Using the *volume* +style for those 2 dimensions to keep the box volume constant may make +more physical sense, but may also not be correct for materials and +potentials whose Poisson ratio is not 0.5. An alternative is to use +:doc:`fix npt aniso ` with zero applied pressure on those 2 +dimensions, so that they respond to the tensile strain dynamically. + +The *wiggle* style oscillates the specified box length dimension +sinusoidally with the specified amplitude and period. I.e. the box +length L as a function of time is given by + +.. parsed-literal:: + + L(t) = L0 + A sin(2\*pi t/Tp) + +where L0 is its initial length. If the amplitude A is a positive +number the box initially expands, then contracts, etc. If A is +negative then the box initially contracts, then expands, etc. The +amplitude can be in lattice or box distance units. See the discussion +of the units keyword below. + +The *variable* style changes the specified box length dimension by +evaluating a variable, which presumably is a function of time. The +variable with *name1* must be an :doc:`equal-style variable ` +and should calculate a change in box length in units of distance. +Note that this distance is in box units, not lattice units; see the +discussion of the *units* keyword below. The formula associated with +variable *name1* can reference the current timestep. Note that it +should return the "change" in box length, not the absolute box length. +This means it should evaluate to 0.0 when invoked on the initial +timestep of the run following the definition of fix deform. It should +evaluate to a value > 0.0 to dilate the box at future times, or a +value < 0.0 to compress the box. + +The variable *name2* must also be an :doc:`equal-style variable ` and should calculate the rate of box length +change, in units of distance/time, i.e. the time-derivative of the +*name1* variable. This quantity is used internally by LAMMPS to reset +atom velocities when they cross periodic boundaries. It is computed +internally for the other styles, but you must provide it when using an +arbitrary variable. + +Here is an example of using the *variable* style to perform the same +box deformation as the *wiggle* style formula listed above, where we +assume that the current timestep = 0. + +.. code-block:: LAMMPS + + variable A equal 5.0 + variable Tp equal 10.0 + variable displace equal "v_A * sin(2*PI * step*dt/v_Tp)" + variable rate equal "2*PI*v_A/v_Tp * cos(2*PI * step*dt/v_Tp)" + fix 2 all deform 1 x variable v_displace v_rate remap v + +For the *scale*, *vel*, *erate*, *trate*, *volume*, *wiggle*, and +*variable* styles, the box length is expanded or compressed around its +mid point. + +The *pressure* style adjusts a dimensions's box length to control that +component of the pressure tensor. This option attempts to maintain a +specified target value using a linear controller where the box length +:math:`L` evolves according to the equation + +.. parsed-literal:: + + \frac{d L(t)}{dt} = L(t) k (P_t - P) + +where :math:`k` is a proportional gain constant, :math:`P_t` is the target +pressure, and :math:`P` is the current pressure along that dimension. This +approach is similar to the method used to control the pressure by +:doc:`fix press/berendsen `. The target pressure +accepts either a constant numeric value or a LAMMPS :ref:`variable `. +Notably, this variable can be a function of time or other components of +the pressure tensor. By default, :math:`k` has units of 1/(time * pressure) +although this will change if the *normalize/pessure* option is set as +:ref:`discussed below `. There is no proven method +to choosing an appropriate value of :math:`k` as it will depend on the +specific details of a simulation and testing different values is +recommended. One can also apply a maximum limit to the magnitude of the +applied strain using the :ref:`max/rate ` option and couple +pressures in different dimensions using the :ref:`couple ` +option. + +The *pressure/mean* style changes a dimension's box length to maintain +a constant mean pressure defined as the trace of the pressure tensor. +This option is therefore very similar to the *pressure* style with +identical arguments except the current and target pressures refer to the +mean trace of the pressure tensor. All options for the *pressure* style +also apply to the *pressure/mean* style except for the +:ref:`couple ` option. + +---------- + +For the *xy*, *xz*, and *yz* parameters, this is the meaning of their +styles and values. Note that changing the tilt factors of a triclinic +box does not change its volume. + +The *final*, *delta*, *vel*, and *erate* styles all change the shear +strain at a "constant engineering shear strain rate". This means the +tilt factor changes linearly with time from its initial to final +value. + +For style *final*, the final tilt factor is specified. The value +can be in lattice or box distance units. See the discussion of the +units keyword below. + +For style *delta*, a plus or minus change in the tilt factor is +specified. The value can be in lattice or box distance units. See +the discussion of the units keyword below. + +For style *vel*, a velocity at which the tilt factor changes is +specified in units of distance/time. This is effectively an +"engineering shear strain rate", where rate = V/L0 and L0 is the +initial box length perpendicular to the direction of shear. The +distance can be in lattice or box distance units. See the discussion +of the units keyword below. For example, if the initial tilt factor +is 5 Angstroms, and the V is 10 Angstroms/ps, then after 1 ps, the +tilt factor will be 15 Angstroms. After 2 ps, it will be 25 +Angstroms. + +The *erate* style changes a tilt factor at a "constant engineering +shear strain rate". The units of the specified shear strain rate are +1/time. See the :doc:`units ` command for the time units +associated with different choices of simulation units, +e.g. picoseconds for "metal" units). Shear strain is unitless and is +defined as offset/length, where length is the box length perpendicular +to the shear direction (e.g. y box length for xy deformation) and +offset is the displacement distance in the shear direction (e.g. x +direction for xy deformation) from the unstrained orientation. + +The tilt factor T as a function of time will change as + +.. parsed-literal:: + + T(t) = T0 + L0\*erate\*dt + +where T0 is the initial tilt factor, L0 is the original length of the +box perpendicular to the shear direction (e.g. y box length for xy +deformation), and dt is the elapsed time (in time units). Thus if +*erate* R is specified as 0.1 and time units are picoseconds, this +means the shear strain will increase by 0.1 every picosecond. I.e. if +the xy shear strain was initially 0.0, then strain after 1 ps = 0.1, +strain after 2 ps = 0.2, etc. Thus the tilt factor would be 0.0 at +time 0, 0.1\*ybox at 1 ps, 0.2\*ybox at 2 ps, etc, where ybox is the +original y box length. R = 1 or 2 means the tilt factor will increase +by 1 or 2 every picosecond. R = -0.01 means a decrease in shear +strain by 0.01 every picosecond. + +The *trate* style changes a tilt factor at a "constant true shear +strain rate". Note that this is not an "engineering shear strain +rate", as the other styles are. Rather, for a "true" rate, the rate +of change is constant, which means the tilt factor changes +non-linearly with time from its initial to final value. The units of +the specified shear strain rate are 1/time. See the +:doc:`units ` command for the time units associated with +different choices of simulation units, e.g. picoseconds for "metal" +units). Shear strain is unitless and is defined as offset/length, +where length is the box length perpendicular to the shear direction +(e.g. y box length for xy deformation) and offset is the displacement +distance in the shear direction (e.g. x direction for xy deformation) +from the unstrained orientation. + +The tilt factor T as a function of time will change as + +.. parsed-literal:: + + T(t) = T0 exp(trate\*dt) + +where T0 is the initial tilt factor and dt is the elapsed time (in +time units). Thus if *trate* R is specified as ln(1.1) and time units +are picoseconds, this means the shear strain or tilt factor will +increase by 10% every picosecond. I.e. if the xy shear strain was +initially 0.1, then strain after 1 ps = 0.11, strain after 2 ps = +0.121, etc. R = ln(2) or ln(3) means the tilt factor will double or +triple every picosecond. R = ln(0.99) means the tilt factor will +shrink by 1% every picosecond. Note that the change is continuous, so +running with R = ln(2) for 10 picoseconds does not change the tilt +factor by a factor of 10, but by a factor of 1024 since it doubles +every picosecond. Note that the initial tilt factor must be non-zero +to use the *trate* option. + +Note that shear strain is defined as the tilt factor divided by the +perpendicular box length. The *erate* and *trate* styles control the +tilt factor, but assume the perpendicular box length remains constant. +If this is not the case (e.g. it changes due to another fix deform +parameter), then this effect on the shear strain is ignored. + +The *wiggle* style oscillates the specified tilt factor sinusoidally +with the specified amplitude and period. I.e. the tilt factor T as a +function of time is given by + +.. parsed-literal:: + + T(t) = T0 + A sin(2\*pi t/Tp) + +where T0 is its initial value. If the amplitude A is a positive +number the tilt factor initially becomes more positive, then more +negative, etc. If A is negative then the tilt factor initially +becomes more negative, then more positive, etc. The amplitude can be +in lattice or box distance units. See the discussion of the units +keyword below. + +The *variable* style changes the specified tilt factor by evaluating a +variable, which presumably is a function of time. The variable with +*name1* must be an :doc:`equal-style variable ` and should +calculate a change in tilt in units of distance. Note that this +distance is in box units, not lattice units; see the discussion of the +*units* keyword below. The formula associated with variable *name1* +can reference the current timestep. Note that it should return the +"change" in tilt factor, not the absolute tilt factor. This means it +should evaluate to 0.0 when invoked on the initial timestep of the run +following the definition of fix deform. + +The variable *name2* must also be an :doc:`equal-style variable ` and should calculate the rate of tilt change, +in units of distance/time, i.e. the time-derivative of the *name1* +variable. This quantity is used internally by LAMMPS to reset atom +velocities when they cross periodic boundaries. It is computed +internally for the other styles, but you must provide it when using an +arbitrary variable. + +Here is an example of using the *variable* style to perform the same +box deformation as the *wiggle* style formula listed above, where we +assume that the current timestep = 0. + +.. code-block:: LAMMPS + + variable A equal 5.0 + variable Tp equal 10.0 + variable displace equal "v_A * sin(2*PI * step*dt/v_Tp)" + variable rate equal "2*PI*v_A/v_Tp * cos(2*PI * step*dt/v_Tp)" + fix 2 all deform 1 xy variable v_displace v_rate remap v + +The *pressure* style adjusts a tilt factor to control the corresponding +off-diagonal component of the pressure tensor. This option attempts to +maintain a specified target value using a linear controller where the +tilt factor T evolves according to the equation + +.. parsed-literal:: + + \frac{d T(t)}{dt} = L(t) k (P - P_t) + +where :math:`k` is a proportional gain constant, :math:`P_t` is the target +pressure, :math:`P` is the current pressure, and :math:`L` is the perpendicular +box length. The target pressure accepts either a constant numeric value or a +LAMMPS :ref:`variable `. Notably, this variable can be a function +of time or other components of the pressure tensor. By default, :math:`k` +has units of 1/(time * pressure) although this will change if the +*normalize/pessure* option is set as :ref:`discussed below `. +There is no proven method to choosing an appropriate value of :math:`k` as it +will depend on thespecific details of a simulation and testing different +values is recommended. One can also apply a maximum limit to the magnitude +of the applied strain using the :ref:`max/rate ` option. + +---------- + +The *iso* parameter provides an additonal control over the x, y, +and z box lengths. This parameter can only be used in combination with +the *x*, *y*, or *z* comamnds: *vel*, *erate*, *trate*, *pressure*, or +*wiggle*. Note that this parameter will change the overall strain rate in +the *x*, *y*, or *z* dimensions. This is the meaning of its styles and values. + +The *volume* style isotropically scales box lengths to maintain a constant +box volume in response to deformation from other parameters. + +The *pressure* style controls the box volume to maintain the mean pressure +of the system. This is accomplished by isotropically scaling all box +lengths :math:`L` by an additional factor of :math:`k (P_t - P_m)` where +:math:`k` is the proportional gain constant, :math:`P_t` is the target +pressure, and :math:`P_m` is the current mean pressure (the trace of the +pressure tensor). This style allows one to control the deviatoric strain +tensor while maintaining a fixed mean pressure. + +---------- + +All of the tilt styles change the xy, xz, yz tilt factors during a +simulation. In LAMMPS, tilt factors (xy,xz,yz) for triclinic boxes +are normally bounded by half the distance of the parallel box length. +See the discussion of the *flip* keyword below, to allow this bound to +be exceeded, if desired. + +For example, if xlo = 2 and xhi = 12, then the x box length is 10 and +the xy tilt factor must be between -5 and 5. Similarly, both xz and +yz must be between -(xhi-xlo)/2 and +(yhi-ylo)/2. Note that this is +not a limitation, since if the maximum tilt factor is 5 (as in this +example), then configurations with tilt = ..., -15, -5, 5, 15, 25, +... are all equivalent. + +To obey this constraint and allow for large shear deformations to be +applied via the *xy*, *xz*, or *yz* parameters, the following +algorithm is used. If *prd* is the associated parallel box length (10 +in the example above), then if the tilt factor exceeds the accepted +range of -5 to 5 during the simulation, then the box is flipped to the +other limit (an equivalent box) and the simulation continues. Thus +for this example, if the initial xy tilt factor was 0.0 and "xy final +100.0" was specified, then during the simulation the xy tilt factor +would increase from 0.0 to 5.0, the box would be flipped so that the +tilt factor becomes -5.0, the tilt factor would increase from -5.0 to +5.0, the box would be flipped again, etc. The flip occurs 10 times +and the final tilt factor at the end of the simulation would be 0.0. +During each flip event, atoms are remapped into the new box in the +appropriate manner. + +The one exception to this rule is if the first dimension in the tilt +factor (x for xy) is non-periodic. In that case, the limits on the +tilt factor are not enforced, since flipping the box in that dimension +does not change the atom positions due to non-periodicity. In this +mode, if you tilt the system to extreme angles, the simulation will +simply become inefficient due to the highly skewed simulation box. + +---------- + +Each time the box size or shape is changed, the *remap* keyword +determines whether atom positions are remapped to the new box. If +*remap* is set to *x* (the default), atoms in the fix group are +remapped; otherwise they are not. Note that their velocities are not +changed, just their positions are altered. If *remap* is set to *v*, +then any atom in the fix group that crosses a periodic boundary will +have a delta added to its velocity equal to the difference in +velocities between the lo and hi boundaries. Note that this velocity +difference can include tilt components, e.g. a delta in the x velocity +when an atom crosses the y periodic boundary. If *remap* is set to +*none*, then neither of these remappings take place. + +Conceptually, setting *remap* to *x* forces the atoms to deform via an +affine transformation that exactly matches the box deformation. This +setting is typically appropriate for solids. Note that though the +atoms are effectively "moving" with the box over time, it is not due +to their having a velocity that tracks the box change, but only due to +the remapping. By contrast, setting *remap* to *v* is typically +appropriate for fluids, where you want the atoms to respond to the +change in box size/shape on their own and acquire a velocity that +matches the box change, so that their motion will naturally track the +box without explicit remapping of their coordinates. + +.. note:: + + When non-equilibrium MD (NEMD) simulations are performed using + this fix, the option "remap v" should normally be used. This is + because :doc:`fix nvt/sllod ` adjusts the atom positions + and velocities to induce a velocity profile that matches the changing + box size/shape. Thus atom coordinates should NOT be remapped by fix + deform, but velocities SHOULD be when atoms cross periodic boundaries, + since that is consistent with maintaining the velocity profile already + created by fix nvt/sllod. LAMMPS will warn you if the *remap* setting + is not consistent with fix nvt/sllod. + +.. note:: + + For non-equilibrium MD (NEMD) simulations using "remap v" it is + usually desirable that the fluid (or flowing material, e.g. granular + particles) stream with a velocity profile consistent with the + deforming box. As mentioned above, using a thermostat such as :doc:`fix nvt/sllod ` or :doc:`fix lavgevin ` + (with a bias provided by :doc:`compute temp/deform `), will typically accomplish + that. If you do not use a thermostat, then there is no driving force + pushing the atoms to flow in a manner consistent with the deforming + box. E.g. for a shearing system the box deformation velocity may vary + from 0 at the bottom to 10 at the top of the box. But the stream + velocity profile of the atoms may vary from -5 at the bottom to +5 at + the top. You can monitor these effects using the :doc:`fix ave/chunk `, :doc:`compute temp/deform `, and :doc:`compute temp/profile ` commands. One way to induce + atoms to stream consistent with the box deformation is to give them an + initial velocity profile, via the :doc:`velocity ramp ` + command, that matches the box deformation rate. This also typically + helps the system come to equilibrium more quickly, even if a + thermostat is used. + +.. note:: + + If a :doc:`fix rigid ` is defined for rigid bodies, and + *remap* is set to *x*, then the center-of-mass coordinates of rigid + bodies will be remapped to the changing simulation box. This will be + done regardless of whether atoms in the rigid bodies are in the fix + deform group or not. The velocity of the centers of mass are not + remapped even if *remap* is set to *v*, since :doc:`fix nvt/sllod ` does not currently do anything special + for rigid particles. If you wish to perform a NEMD simulation of + rigid particles, you can either thermostat them independently or + include a background fluid and thermostat the fluid via :doc:`fix nvt/sllod `. + +The *flip* keyword allows the tilt factors for a triclinic box to +exceed half the distance of the parallel box length, as discussed +above. If the *flip* value is set to *yes*, the bound is enforced by +flipping the box when it is exceeded. If the *flip* value is set to +*no*, the tilt will continue to change without flipping. Note that if +you apply large deformations, this means the box shape can tilt +dramatically LAMMPS will run less efficiently, due to the large volume +of communication needed to acquire ghost atoms around a processor's +irregular-shaped sub-domain. For extreme values of tilt, LAMMPS may +also lose atoms and generate an error. + +The *units* keyword determines the meaning of the distance units used +to define various arguments. A *box* value selects standard distance +units as defined by the :doc:`units ` command, e.g. Angstroms for +units = real or metal. A *lattice* value means the distance units are +in lattice spacings. The :doc:`lattice ` command must have +been previously used to define the lattice spacing. Note that the +units choice also affects the *vel* style parameters since it is +defined in terms of distance/time. Also note that the units keyword +does not affect the *variable* style. You should use the *xlat*, +*ylat*, *zlat* keywords of the :doc:`thermo_style ` +command if you want to include lattice spacings in a variable formula. + +.. _deform_normalize: + +The *normalize/pressure* keyword changes how box dimensions evolve when +using the *pressure* or *pressure/mean* deformation options. If the +*deform/normalize* value is set to *yes*, then the deviation from the +target pressure is normalized by the absolute value of the target +pressure such that the proportional gain constant scales a percentage +error and has units of 1/time. If the target pressure is ever zero, this +will produce an error unless the *max/rate* keyword is defined, +described below, which will cap the divergence. + +.. _deform_max_rate: + +The *max/rate* keyword sets an upper threshold, *rate*, that limits the +maximum magnitude of the instantaneous strain rate applied in any dimension. +This keyword only applies to the *pressure* and *pressure/mean* options. If +a pressure-controlled rate is used for both *iso* and either *x*, *y*, or +*z*, then this threshold will apply separately to each individual controller +such that the cumulative strain rate on a box dimension may be up to twice +the value of *rate*. + +.. _deform_couple: + +The *couple* keyword allows two or three of the diagonal components of +the pressure tensor to be "coupled" together for the *pressure* option. +The value specified with the keyword determines which are coupled. For +example, *xz* means the *Pxx* and *Pzz* components of the stress tensor +are coupled. *Xyz* means all 3 diagonal components are coupled. Coupling +means two things: the instantaneous stress will be computed as an average +of the corresponding diagonal components, and the coupled box dimensions +will be changed together in lockstep, meaning coupled dimensions will be +dilated or contracted by the same percentage every timestep. The target +pressures and gain constants for any coupled dimensions must be identical. +*Couple xyz* can be used for a 2d simulation; the *z* dimension is simply +ignored. + +.. _deform_balance: + +The *vol/balance/p* keyword modifies the behavior of *volume* when two +dimensions are used to maintain a fixed volume. Instead of straining +the two dimensions in lockstep, the two dimensions are allowed to +separately dilate or contract in a manner to maintain a constant +volume while simultaneously trying to keep the pressure along each +dimension equal using a method described in :ref:`(Huang2014) `. + +---------- + +If any pressure controls are used, this fix computes a temperature and +pressure each timestep. To do this, the fix creates its own computes of +style "temp" and "pressure", as if these commands had been issued: + +.. code-block:: LAMMPS + + compute fix-ID_temp group-ID temp + compute fix-ID_press group-ID pressure fix-ID_temp + +See the :doc:`compute temp ` and :doc:`compute pressure ` commands for details. Note that the +IDs of the new computes are the fix-ID + underscore + "temp" or fix_ID ++ underscore + "press", and the group for the new computes is the same +as the fix group. + +Note that these are NOT the computes used by thermodynamic output (see +the :doc:`thermo_style ` command) with ID = *thermo_temp* +and *thermo_press*. This means you can change the attributes of this +fix's temperature or pressure via the +:doc:`compute_modify ` command or print this temperature +or pressure during thermodynamic output via the +:doc:`thermo_style custom ` command using the appropriate +compute-ID. It also means that changing attributes of *thermo_temp* or +*thermo_press* will have no effect on this fix. + +---------- + +.. include:: accel_styles.rst + +Restart, fix_modify, output, run start/stop, minimize info +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +This fix will restore the initial box settings from :doc:`binary restart files `, which allows the fix to be properly continue +deformation, when using the start/stop options of the :doc:`run ` +command. None of the :doc:`fix_modify ` options are +relevant to this fix. No global or per-atom quantities are stored by +this fix for access by various :doc:`output commands `. + +If any pressure controls are used, the :doc:`fix_modify ` *temp* +and *press* options are supported by this fix. You can use them to assign a +:doc:`compute ` you have defined to this fix which will be used +in its temperature and pressure calculations. If you do this, note +that the kinetic energy derived from the compute temperature should be +consistent with the virial term computed using all atoms for the +pressure. LAMMPS will warn you if you choose to compute temperature +on a subset of atoms. + +This fix can perform deformation over multiple runs, using the *start* +and *stop* keywords of the :doc:`run ` command. See the +:doc:`run ` command for details of how to do this. + +This fix is not invoked during :doc:`energy minimization `. + +Restrictions +"""""""""""" + +You cannot apply x, y, or z deformations to a dimension that is +shrink-wrapped via the :doc:`boundary ` command. + +You cannot apply xy, yz, or xz deformations to a second dimension (y in +xy) that is shrink-wrapped via the :doc:`boundary ` command. + +Related commands +"""""""""""""""" + +:doc:`change_box ` + +Default +""""""" + +The option defaults are remap = x, flip = yes, units = lattice, and +normalize/pressure = no. + +---------- + +.. _Li2014b: + +**(Huang2014)** X. Huang, +"Exploring critical-state behavior using DEM", +Doctoral dissertation, Imperial College. +(2014). https://doi.org/10.25560/25316 diff --git a/src/.gitignore b/src/.gitignore index 0d3cb2ff4a..ab68aa1055 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -724,6 +724,8 @@ /fix_cmap.h /fix_damping_cundall.cpp /fix_damping_cundall.h +/fix_deform_pressure.cpp +/fix_deform_pressure.h /fix_dpd_energy.cpp /fix_dpd_energy.h /fix_electron_stopping.cpp diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp new file mode 100644 index 0000000000..666ca5f2af --- /dev/null +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -0,0 +1,905 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Joel Clemmer (SNL) +------------------------------------------------------------------------- */ + +#include "fix_deform_pressure.h" + +#include "atom.h" +#include "comm.h" +#include "compute.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "group.h" +#include "input.h" +#include "irregular.h" +#include "kspace.h" +#include "lattice.h" +#include "math_const.h" +#include "modify.h" +#include "update.h" +#include "variable.h" + +#include +#include + +using namespace LAMMPS_NS; +using namespace FixConst; +using namespace MathConst; + +enum{NONE=0,FINAL,DELTA,SCALE,VEL,ERATE,TRATE,VOLUME,WIGGLE,VARIABLE,PRESSURE,PMEAN}; +enum{ONE_FROM_ONE,ONE_FROM_TWO,TWO_FROM_ONE}; +enum{NOCOUPLE=0,XYZ,XY,YZ,XZ}; + +/* ---------------------------------------------------------------------- */ + +FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : FixDeform(lmp, narg, arg), +id_temp(nullptr), id_press(nullptr) +{ + // populate coupled pressure controls + + if (pcouple != NOCOUPLE) { + int coupled_indices[3] = {0}; + int j = -1; + double couple_gain, coupled_pressure; + char *couple_str; + + if (pcouple == XYZ || pcouple == XY || pcouple == XZ) + coupled_indices[0] = 1; + if (pcouple == XYZ || pcouple == XY || pcouple == YZ) + coupled_indices[1] = 1; + if (pcouple == XYZ || pcouple == XZ || pcouple == YZ) + coupled_indices[2] = 1; + + // Check coupled styles and find reference + for (int i = 0; i < 3; i++) { + if (coupled_indices[i]) { + set[i].coupled_flag = 1; + if (set[i].style != PRESSURE && set[i].style != NONE) + error->all(FLERR, "Cannot couple non-pressure-controlled dimensions"); + if (set[i].style == PRESSURE) + j = i; + } + } + + if (j == -1) + error->all(FLERR, "Must specify deformation style for at least one coupled dimension"); + + // Copy or compare data for each coupled dimension + for (int i = 0; i < 3; i++) { + if (coupled_indices[i]) { + // Copy coupling information if dimension style is undefined + if (set[i].style == NONE) { + set[i].style = PRESSURE; + dimflag[i] = 1; + set[i].pgain = set[j].pgain; + if (set[j].pvar_flag) { + set[i].pstr = set[j].pstr; + set[i].pvar_flag = 1; + } else { + set[i].ptarget = set[j].ptarget; + } + } else { + // Check for incompatibilities in style + if (set[j].style != set[i].style && set[i].style != NONE) + error->all(FLERR, "Cannot couple dimensions with different control options"); + if (set[j].style != PRESSURE) continue; + + // If pressure controlled, check for incompatibilities in parameters + if (set[i].pgain != set[j].pgain || set[i].pvar_flag != set[j].pvar_flag || + set[i].ptarget != set[j].ptarget) + error->all(FLERR, "Coupled dimensions must have identical gain parameters"); + + if (set[j].pvar_flag) + if (strcmp(set[i].pstr, set[j].pstr) != 0) + error->all(FLERR, "Coupled dimensions must have the same target pressure"); + } + } + } + } + + // repeat some checks in child class to catch changes to pcouple + + if (dimflag[0]) box_change |= BOX_CHANGE_X; + if (dimflag[1]) box_change |= BOX_CHANGE_Y; + if (dimflag[2]) box_change |= BOX_CHANGE_Z; + + // no tensile deformation on shrink-wrapped dims + // b/c shrink wrap will change box-length + + for (int i = 0; i < 3; i++) + if ((set[i].style || set[6].style) && (domain->boundary[i][0] >= 2 || domain->boundary[i][1] >= 2)) + error->all(FLERR, "Cannot use fix deform/pressure on a shrink-wrapped boundary"); + + // if vol/balance/p used, must have 2 free dimensions + + if (vol_balance_flag) { + for (int i = 0; i < 3; i++) { + if (set[i].style != VOLUME) continue; + if (set[i].substyle != TWO_FROM_ONE) + error->all(FLERR, "Two dimensions must maintain constant volume to use the vol/balance/p option"); + } + } + + // set strain_flag + + strain_flag = 0; + for (int i = 0; i < 6; i++) + if (set[i].style != NONE && set[i].style != VOLUME && + set[i].style != PRESSURE && set[i].style != PMEAN) + strain_flag = 1; + + // set pressure_flag + + pressure_flag = 0; + for (int i = 0; i < 7; i++) { + if (set[i].style == PRESSURE || set[i].style == PMEAN) pressure_flag = 1; + if (set[i].coupled_flag) pressure_flag = 1; + } + if (vol_balance_flag) pressure_flag = 1; + + // check conflict between constant volume/pressure + + volume_flag = 0; + for (int i = 0; i < 3; i++) + if (set[i].style == VOLUME) + volume_flag = 1; + + if (volume_flag) + for (int i = 0; i < 6; i++) + if (set[i].style == PMEAN) + error->all(FLERR, "Cannot use fix deform/pressure to assign constant volume and pressure"); + + // check conflicts between x,y,z styles and iso + + if (set[6].style) + for (int i = 0; i < 3; i++) + if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == SCALE || set[i].style == PMEAN || set[i].style == VARIABLE) + error->all(FLERR, "Cannot use fix deform/pressure iso parameter with x, y, or z styles other than vel, erate, trate, pressure, and wiggle"); + + // check pressure used for max rate and normalize error flag + + if (!pressure_flag && max_h_rate != 0) + error->all(FLERR, "Can only assign a maximum strain rate using pressure-controlled dimensions"); + + if (!pressure_flag && normalize_pressure_flag) + error->all(FLERR, "Can only normalize error using pressure-controlled dimensions"); + + // Create pressure compute, if needed + + pflag = 0; + tflag = 0; + if (pressure_flag) { + // create a new compute temp style + // id = fix-ID + temp + // compute group = all since pressure is always global (group all) + // and thus its KE/temperature contribution should use group all + + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); + tflag = 1; + + // create a new compute pressure style + // id = fix-ID + press, compute group = all + // pass id_temp as 4th arg to pressure constructor + + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); + pflag = 1; + } +} + +/* ---------------------------------------------------------------------- */ + +FixDeformPressure::~FixDeformPressure() +{ + // delete temperature and pressure if fix created them + + if (tflag) modify->delete_compute(id_temp); + if (pflag) modify->delete_compute(id_press); + delete [] id_temp; + delete [] id_press; +} + +/* ---------------------------------------------------------------------- */ + +void FixDeformPressure::init() +{ + FixDeform::init(); + + // check optional variables for PRESSURE or PMEAN style + + for (int i = 0; i < 7; i++) { + if (!set[i].pvar_flag) continue; + set[i].pvar = input->variable->find(set[i].pstr); + if (set[i].pvar < 0) + error->all(FLERR, "Variable name {} for fix deform/pressure does not exist", set[i].pstr); + if (!input->variable->equalstyle(set[i].pvar)) + error->all(FLERR, "Variable {} for fix deform/pressure is invalid style", set[i].pstr); + } + + // Find pressure/temp computes if needed + + if (pressure_flag) { + int icompute = modify->find_compute(id_temp); + if (icompute < 0) error->all(FLERR, "Temperature ID for fix deform/pressure does not exist"); + temperature = modify->compute[icompute]; + + icompute = modify->find_compute(id_press); + if (icompute < 0) error->all(FLERR, "Pressure ID for fix deform/pressure does not exist"); + pressure = modify->compute[icompute]; + } +} + +/* ---------------------------------------------------------------------- + compute T,P if needed before integrator starts +------------------------------------------------------------------------- */ + +void FixDeformPressure::setup(int /*vflag*/) +{ + // trigger virial computation on next timestep + if (pressure_flag) pressure->addstep(update->ntimestep+1); +} + +/* ---------------------------------------------------------------------- */ + +void FixDeformPressure::end_of_step() +{ + // wrap variable evaluations with clear/add + + if (varflag) modify->clearstep_compute(); + + // set new box size for strain-based dims + + if (strain_flag) FixDeform::set_strain(); + + // set new box size for pressure-based dims + + if (pressure_flag) { + temperature->compute_vector(); + pressure->compute_vector(); + pressure->compute_scalar(); + for (int i = 0; i < 3; i++) { + if (!set[i].saved) { + set[i].saved = 1; + set[i].prior_rate = 0.0; + set[i].prior_pressure = pressure->vector[i]; + } + } + set_pressure(); + } + + // set new box size for VOLUME dims that are linked to other dims + // NOTE: still need to set h_rate for these dims + + if (volume_flag) set_volume(); + + // apply any final isotropic scalings + + if (set[6].style) set_iso(); + + // Save pressure/strain rate if required + + if (pressure_flag) { + for (int i = 0; i < 3; i++) { + set[i].prior_pressure = pressure->vector[i]; + set[i].prior_rate = ((set[i].hi_target - set[i].lo_target) / + (domain->boxhi[i] - domain->boxlo[i]) - 1.0) / update->dt; + } + } + + if (varflag) modify->addstep_compute(update->ntimestep + nevery); + + + FixDeform::apply_deformation(); + + // trigger virial computation, if needed, on next timestep + + if (pressure_flag) + pressure->addstep(update->ntimestep+1); +} + +/* ---------------------------------------------------------------------- + set box size for pressure-based dimensions +------------------------------------------------------------------------- */ + +void FixDeformPressure::set_pressure() +{ + // If variable pressure, calculate current target + for (int i = 0; i < 6; i++) + if (set[i].style == PRESSURE) + if (set[i].pvar_flag) + set[i].ptarget = input->variable->compute_equal(set[i].pvar); + + // Find current (possibly coupled/hydrostatic) pressure for X, Y, Z + double *tensor = pressure->vector; + double scalar = pressure->scalar; + double p_current[3]; + + if (pcouple == XYZ) { + double ave = THIRD * (tensor[0] + tensor[1] + tensor[2]); + p_current[0] = p_current[1] = p_current[2] = ave; + } else if (pcouple == XY) { + double ave = 0.5 * (tensor[0] + tensor[1]); + p_current[0] = p_current[1] = ave; + p_current[2] = tensor[2]; + } else if (pcouple == YZ) { + double ave = 0.5 * (tensor[1] + tensor[2]); + p_current[1] = p_current[2] = ave; + p_current[0] = tensor[0]; + } else if (pcouple == XZ) { + double ave = 0.5 * (tensor[0] + tensor[2]); + p_current[0] = p_current[2] = ave; + p_current[1] = tensor[1]; + } else { + if (set[0].style == PRESSURE) p_current[0] = tensor[0]; + else if (set[0].style == PMEAN) p_current[0] = scalar; + + if (set[1].style == PRESSURE) p_current[1] = tensor[1]; + else if (set[1].style == PMEAN) p_current[1] = scalar; + + if (set[2].style == PRESSURE) p_current[2] = tensor[2]; + else if (set[2].style == PMEAN) p_current[2] = scalar; + } + + for (int i = 0; i < 3; i++) { + if (set[i].style != PRESSURE && set[i].style != PMEAN) continue; + + h_rate[i] = set[i].pgain * (p_current[i] - set[i].ptarget); + + if (normalize_pressure_flag) { + if (set[i].ptarget == 0) { + if (max_h_rate == 0) { + error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); + } else h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); + } else h_rate[i] /= fabs(set[i].ptarget); + } + + if (max_h_rate != 0) + if (fabs(h_rate[i]) > max_h_rate) + h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); + + h_ratelo[i] = -0.5 * h_rate[i]; + + double offset = 0.5 * (domain->boxhi[i] - domain->boxlo[i]) * (1.0 + update->dt * h_rate[i]); + set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - offset; + set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + offset; + } + + for (int i = 3; i < 6; i++) { + if (set[i].style != PRESSURE) continue; + + double L, tilt, pcurrent; + if (i == 3) { + L = domain->zprd; + tilt = domain->yz; + pcurrent = tensor[5]; + } else if (i == 4) { + L = domain->zprd; + tilt = domain->xz + update->dt; + pcurrent = tensor[4]; + } else { + L = domain->yprd; + tilt = domain->xy; + pcurrent = tensor[3]; + } + + h_rate[i] = L * set[i].pgain * (pcurrent - set[i].ptarget); + if (normalize_pressure_flag) { + if (set[i].ptarget == 0) { + if (max_h_rate == 0) { + error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); + } else h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); + } else h_rate[i] /= fabs(set[i].ptarget); + } + + if (max_h_rate != 0) + if (fabs(h_rate[i]) > max_h_rate) + h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); + + set[i].tilt_target = tilt + update->dt * h_rate[i]; + } +} + +/* ---------------------------------------------------------------------- + set box size for VOLUME dimensions +------------------------------------------------------------------------- */ + +void FixDeformPressure::set_volume() +{ + double e1, e2; + int linked_pressure = 0; + + for (int i = 0; i < 3; i++) { + if (set[i].style != VOLUME) continue; + + int dynamic1 = set[i].dynamic1; + int dynamic2 = set[i].dynamic2; + int fixed = set[i].fixed; + double v0 = set[i].vol_start; + double shift; + + if (set[i].substyle == ONE_FROM_ONE) { + shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / + (set[fixed].hi_start-set[fixed].lo_start)); + } else if (set[i].substyle == ONE_FROM_TWO) { + shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / + (set[dynamic2].hi_target - set[dynamic2].lo_target)); + } else if (set[i].substyle == TWO_FROM_ONE) { + if (!vol_balance_flag) { + shift = 0.5 * sqrt(v0 * (set[i].hi_start - set[i].lo_start) / + (set[dynamic1].hi_target - set[dynamic1].lo_target) / + (set[fixed].hi_start - set[fixed].lo_start)); + } else { + double dt = update->dt; + double e1i = set[i].prior_rate; + double e2i = set[fixed].prior_rate; + double L1i = domain->boxhi[i] - domain->boxlo[i]; + double L2i = domain->boxhi[fixed] - domain->boxlo[fixed]; + double L3i = domain->boxhi[dynamic1] - domain->boxlo[dynamic1]; + double L3 = (set[dynamic1].hi_target - set[dynamic1].lo_target); + double Vi = L1i * L2i * L3i; + double V = L3 * L1i * L2i; + double e3 = (L3 / L3i - 1.0) / dt; + double p1 = pressure->vector[i]; + double p2 = pressure->vector[fixed]; + double p1i = set[i].prior_pressure; + double p2i = set[fixed].prior_pressure; + double denominator; + + if (e3 == 0) { + e1 = 0.0; + e2 = 0.0; + shift = 0.5 * L1i; + } else if (e1i == 0 || e2i == 0 || (p2 == p2i && p1 == p1i)) { + // If no prior strain or no change in pressure (initial step) just scale shift by relative box lengths + shift = 0.5 * sqrt(v0 * L1i / L3 / L2i); + } else { + if (!linked_pressure) { + // Calculate first strain rate by expanding stress to linear order, p1(t+dt) = p2(t+dt) + // Calculate second strain rate to preserve volume + denominator = p2 - p2i + e2i * ((p1 - p1i) / e1i); + if (denominator != 0.0 && e1i != 0.0) { + e1 = (((p2 - p2i) * (Vi - V) / (V * dt)) - e2i * (p1 - p2)) / denominator; + } else { + e1 = e2i; + } + e2 = (Vi - V * (1 + e1 * dt)) / (V * (1 + e1 * dt) * dt); + + // If strain rate exceeds limit in either dimension, cap it at the maximum compatible rate + if (max_h_rate != 0) + if (fabs(e1) > max_h_rate || fabs(e2) > max_h_rate) + if (fabs(e1) > fabs(e2)) + adjust_linked_rates(e1, e2, e3, Vi, V); + else + adjust_linked_rates(e2, e1, e3, Vi, V); + + + shift = 0.5 * L1i * (1.0 + e1 * dt); + linked_pressure = 1; + } else { + // Already calculated value of e2 + shift = 0.5 * L1i * (1.0 + e2 * dt); + } + } + } + } + + h_rate[i] = (2.0 * shift / (domain->boxhi[i] - domain->boxlo[i]) - 1.0) / update->dt; + h_ratelo[i] = -0.5 * h_rate[i]; + + set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; + set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; + } +} + + +/* ---------------------------------------------------------------------- + Rescale volume preserving strain rates to enforce max rate +------------------------------------------------------------------------- */ + +void FixDeformPressure::adjust_linked_rates(double &e_larger, double &e_smaller, double e3, double Vi, double V) +{ + double dt = update->dt; + double e_lim_positive = (Vi - V * (1 + max_h_rate * dt)) / (V * (1 + max_h_rate * dt) * dt); + double e_lim_negative = (Vi - V * (1 - max_h_rate * dt)) / (V * (1 - max_h_rate * dt) * dt); + if ((e_larger * e3) >= 0) { + if (e_larger > 0.0) { + // Same sign as primary strain rate, cap third dimension + e_smaller = -max_h_rate; + e_larger = e_lim_negative; + } else { + e_smaller = max_h_rate; + e_larger = e_lim_positive; + } + } else { + // Opposite sign, set to maxrate. + if (e_larger > 0.0) { + e_larger = max_h_rate; + e_smaller = e_lim_positive; + } else { + e_larger = -max_h_rate; + e_smaller = e_lim_negative; + } + } +} + +/* ---------------------------------------------------------------------- + apply isotropic controls +------------------------------------------------------------------------- */ + +void FixDeformPressure::set_iso() +{ + int i; + double scale, shift; + double v_rate; + + if (set[6].style == VOLUME) { + double v0 = set[6].vol_start; + double v = 1.0; + for (i = 0; i < 3; i++) + v *= (set[i].hi_target - set[i].lo_target); + + scale = std::pow(v0 / v, THIRD); + for (i = 0; i < 3; i++) { + shift = 0.5 * (set[i].hi_target - set[i].lo_target) * scale; + set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; + set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; + + // Recalculate h_rate + h_rate[i] = (set[i].hi_target - set[i].lo_target) / (domain->boxhi[i] - domain->boxlo[i]) - 1.0; + h_rate[i] /= update->dt; + h_ratelo[i] = -0.5 * h_rate[i]; + } + + } else if (set[6].style == PRESSURE) { + + // If variable pressure, calculate current target + if (set[6].pvar_flag) + set[6].ptarget = input->variable->compute_equal(set[6].pvar); + + v_rate = set[6].pgain * (pressure->scalar- set[6].ptarget); + + if (normalize_pressure_flag) { + if (set[6].ptarget == 0) { + if (max_h_rate == 0) { + error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); + } else v_rate = max_h_rate * v_rate / fabs(v_rate); + } else v_rate /= fabs(set[6].ptarget); + } + + if (max_h_rate != 0) + if (fabs(v_rate) > max_h_rate) + v_rate = max_h_rate * v_rate / fabs(v_rate); + + set[6].cumulative_strain += update->dt * v_rate; + scale = (1.0 + set[6].cumulative_strain); + for (i = 0; i < 3; i++) { + shift = 0.5 * (set[i].hi_target - set[i].lo_target) * scale; + set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; + set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; + + // Recalculate h_rate + h_rate[i] = (set[i].hi_target - set[i].lo_target) / (domain->boxhi[i] - domain->boxlo[i]) - 1.0; + h_rate[i] /= update->dt; + h_ratelo[i] = -0.5 * h_rate[i]; + } + } +} + +/* ---------------------------------------------------------------------- */ + +void FixDeformPressure::options(int narg, char **arg) +{ + if (narg < 0) error->all(FLERR, "Illegal fix deform/pressure command"); + + remapflag = Domain::X_REMAP; + scaleflag = 1; + flipflag = 1; + + pcouple = NOCOUPLE; + dimension = domain->dimension; + max_h_rate = 0.0; + vol_balance_flag = 0; + normalize_pressure_flag = 0; + + int index; + int iarg = 4; + while (iarg < narg) { + if (strcmp(arg[iarg], "x") == 0 || + strcmp(arg[iarg], "y") == 0 || + strcmp(arg[iarg], "z") == 0) { + + if (strcmp(arg[iarg], "x") == 0) index = 0; + else if (strcmp(arg[iarg], "y") == 0) index = 1; + else if (strcmp(arg[iarg], "z") == 0) index = 2; + + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure", error); + if (strcmp(arg[iarg + 1], "final") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure final", error); + set[index].style = FINAL; + set[index].flo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].fhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "delta") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure delta", error); + set[index].style = DELTA; + set[index].dlo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].dhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "scale") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure scale", error); + set[index].style = SCALE; + set[index].scale = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "vel") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure vel", error); + set[index].style = VEL; + set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "erate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure erate", error); + set[index].style = ERATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "trate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure trate", error); + set[index].style = TRATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "volume") == 0) { + set[index].style = VOLUME; + iarg += 2; + } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure wiggle", error); + set[index].style = WIGGLE; + set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + if (set[index].tperiod <= 0.0) + error->all(FLERR, "Illegal fix deform/pressure wiggle period, must be positive"); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "variable") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure variable", error); + set[index].style = VARIABLE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) + error->all(FLERR, "Illegal fix deform/pressure variable name {}", arg[iarg + 2]); + if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) + error->all(FLERR, "Illegal fix deform/pressure variable name {}", arg[iarg + 3]); + delete[] set[index].hstr; + delete[] set[index].hratestr; + set[index].hstr = utils::strdup(&arg[iarg + 2][2]); + set[index].hratestr = utils::strdup(&arg[iarg + 3][2]); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "pressure") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure", error); + set[index].style = PRESSURE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { + set[index].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + } else { + set[index].pstr = utils::strdup(&arg[iarg + 2][2]); + set[index].pvar_flag = 1; + } + set[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + if (set[index].pgain <= 0.0) + error->all(FLERR, "Illegal fix deform/pressure pressure gain, must be positive"); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "pressure/mean") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure/mean", error); + set[index].style = PMEAN; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { + set[index].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + } else { + set[index].pstr = utils::strdup(&arg[iarg + 2][2]); + set[index].pvar_flag = 1; + } + set[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + if (set[index].pgain <= 0.0) + error->all(FLERR, "Illegal fix deform/pressure pressure gain, must be positive"); + iarg += 4; + } else error->all(FLERR, "Illegal fix deform/pressure command argument: {}", arg[iarg + 1]); + + } else if (strcmp(arg[iarg], "xy") == 0 || + strcmp(arg[iarg], "xz") == 0 || + strcmp(arg[iarg], "yz") == 0) { + + if (triclinic == 0) + error->all(FLERR, "fix deform/pressure tilt factors require triclinic box"); + if (strcmp(arg[iarg], "xy") == 0) index = 5; + else if (strcmp(arg[iarg], "xz") == 0) index = 4; + else if (strcmp(arg[iarg], "yz") == 0) index = 3; + + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure", error); + if (strcmp(arg[iarg + 1], "final") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure final", error); + set[index].style = FINAL; + set[index].ftilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "delta") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure delta", error); + set[index].style = DELTA; + set[index].dtilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "vel") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure vel", error); + set[index].style = VEL; + set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "erate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure erate", error); + set[index].style = ERATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "trate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure trate", error); + set[index].style = TRATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure wiggle", error); + set[index].style = WIGGLE; + set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + if (set[index].tperiod <= 0.0) + error->all(FLERR, "Illegal fix deform/pressure wiggle period, must be positive"); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "variable") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure variable", error); + set[index].style = VARIABLE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) + error->all(FLERR, "Illegal fix deform/pressure variable name {}", arg[iarg + 2]); + if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) + error->all(FLERR, "Illegal fix deform/pressure variable name {}", arg[iarg + 3]); + delete[] set[index].hstr; + delete[] set[index].hratestr; + set[index].hstr = utils::strdup(&arg[iarg + 2][2]); + set[index].hratestr = utils::strdup(&arg[iarg + 3][2]); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "pressure") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure", error); + set[index].style = PRESSURE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { + set[index].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + } else { + set[index].pstr = utils::strdup(&arg[iarg + 2][2]); + set[index].pvar_flag = 1; + } + set[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + if (set[index].pgain <= 0.0) + error->all(FLERR, "Illegal fix deform/pressure pressure gain, must be positive"); + iarg += 4; + } else error->all(FLERR, "Illegal fix deform/pressure command: {}", arg[iarg + 1]); + } else if (strcmp(arg[iarg], "iso") == 0) { + index = 6; + if (strcmp(arg[iarg + 1], "volume") == 0) { + set[index].style = VOLUME; + iarg += 2; + } else if (strcmp(arg[iarg + 1], "pressure") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure", error); + set[index].style = PRESSURE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { + set[index].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + } else { + set[index].pstr = utils::strdup(&arg[iarg + 2][2]); + set[index].pvar_flag = 1; + } + set[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + if (set[index].pgain <= 0.0) + error->all(FLERR, "Illegal fix deform/pressure pressure gain, must be positive"); + iarg += 4; + } + } else break; + } + + while (iarg < narg) { + if (strcmp(arg[iarg], "remap") == 0) { + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure remap", error); + if (strcmp(arg[iarg + 1], "x") == 0) remapflag = Domain::X_REMAP; + else if (strcmp(arg[iarg + 1], "v") == 0) remapflag = Domain::V_REMAP; + else if (strcmp(arg[iarg + 1], "none") == 0) remapflag = Domain::NO_REMAP; + else error->all(FLERR, "Illegal fix deform/pressure remap command: {}", arg[iarg + 1]); + iarg += 2; + } else if (strcmp(arg[iarg], "units") == 0) { + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure units", error); + if (strcmp(arg[iarg + 1], "box") == 0) scaleflag = 0; + else if (strcmp(arg[iarg + 1], "lattice") == 0) scaleflag = 1; + else error->all(FLERR, "Illegal fix deform/pressure units command: {}", arg[iarg + 1]); + iarg += 2; + } else if (strcmp(arg[iarg], "flip") == 0) { + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure flip", error); + flipflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); + iarg += 2; + } else if (strcmp(arg[iarg], "couple") == 0) { + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure couple", error); + if (strcmp(arg[iarg + 1], "xyz") == 0) pcouple = XYZ; + else if (strcmp(arg[iarg + 1], "xy") == 0) pcouple = XY; + else if (strcmp(arg[iarg + 1], "yz") == 0) pcouple = YZ; + else if (strcmp(arg[iarg + 1], "xz") == 0) pcouple = XZ; + else if (strcmp(arg[iarg + 1], "none") == 0) pcouple = NOCOUPLE; + else error->all(FLERR, "Illegal fix fix deform/pressure couple command: {}", arg[iarg + 1]); + iarg += 2; + } else if (strcmp(arg[iarg], "max/rate") == 0) { + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure max/rate", error); + max_h_rate = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + if (max_h_rate <= 0.0) + error->all(FLERR, "Maximum strain rate must be a positive, non-zero value"); + iarg += 2; + } else if (strcmp(arg[iarg], "normalize/pressure") == 0) { + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure normalize/pressure", error); + normalize_pressure_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp); + iarg += 2; + } else if (strcmp(arg[iarg], "vol/balance/p") == 0) { + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure vol/balance/p", error); + vol_balance_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp); + iarg += 2; + } else error->all(FLERR, "Illegal fix deform/pressure command: {}", arg[iarg]); + } + + if (dimension == 2) + if (pcouple == XYZ || pcouple == XZ || pcouple == YZ) + error->all(FLERR, "Cannot couple Z dimension in fix deform/pressure in 2D"); +} + +/* ---------------------------------------------------------------------- */ + +int FixDeformPressure::modify_param(int narg, char **arg) +{ + if (strcmp(arg[0], "temp") == 0) { + if (narg < 2) error->all(FLERR, "Illegal fix_modify command"); + if (tflag) { + modify->delete_compute(id_temp); + tflag = 0; + } + delete[] id_temp; + id_temp = utils::strdup(arg[1]); + + temperature = modify->get_compute_by_id(arg[1]); + if (!temperature) + error->all(FLERR, "Could not find fix_modify temperature compute ID: ", arg[1]); + + if (temperature->tempflag == 0) + error->all(FLERR, "Fix_modify temperature compute {} does not compute temperature", arg[1]); + if (temperature->igroup != 0 && comm->me == 0) + error->warning(FLERR, "Temperature compute {} for fix {} is not for group all: {}", + arg[1], style, group->names[temperature->igroup]); + + // reset id_temp of pressure to new temperature ID + + auto icompute = modify->get_compute_by_id(id_press); + if (!icompute) + error->all(FLERR, "Pressure compute ID {} for fix {} does not exist", id_press, style); + icompute->reset_extra_compute_fix(id_temp); + + return 2; + + } else if (strcmp(arg[0], "press") == 0) { + if (narg < 2) error->all(FLERR, "Illegal fix_modify command"); + if (pflag) { + modify->delete_compute(id_press); + pflag = 0; + } + delete[] id_press; + id_press = utils::strdup(arg[1]); + + pressure = modify->get_compute_by_id(arg[1]); + if (!pressure) error->all(FLERR, "Could not find fix_modify pressure compute ID: {}", arg[1]); + if (pressure->pressflag == 0) + error->all(FLERR, "Fix_modify pressure compute {} does not compute pressure", arg[1]); + return 2; + } + + return 0; +} diff --git a/src/EXTRA-FIX/fix_deform_pressure.h b/src/EXTRA-FIX/fix_deform_pressure.h new file mode 100644 index 0000000000..d3a05d949d --- /dev/null +++ b/src/EXTRA-FIX/fix_deform_pressure.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef FIX_CLASS +// clang-format off +FixStyle(deform/pressure,FixDeformPressure); +// clang-format on +#else + +#ifndef LMP_FIX_DEFORM_PRESSURE_H +#define LMP_FIX_DEFORM_PRESSURE_H + +#include "fix_deform.h" + +namespace LAMMPS_NS { + +class FixDeformPressure : public FixDeform { + public: + FixDeformPressure(class LAMMPS *, int, char **); + ~FixDeformPressure() override; + void init() override; + void setup(int) override; + void end_of_step() override; + int modify_param(int, char **) override; + + protected: + int pcouple, dimension; + double *h_rate, *h_ratelo, max_h_rate; + int strain_flag; // 1 if strain-based option is used, 0 if not + int pressure_flag; // 1 if pressure tensor used, 0 if not + int volume_flag; // 1 if VOLUME option is used, 0 if not + int normalize_pressure_flag; // 1 if normalize pressure deviation by target + int vol_balance_flag; // 1 if pressures balanced when maintaining const vol + + char *id_temp, *id_press; + class Compute *temperature, *pressure; + int tflag, pflag; + + void options(int, char **); + void set_pressure(); + void set_volume(); + void set_iso(); + void couple(); + void adjust_linked_rates(double&, double&, double, double, double); +}; + +} // namespace LAMMPS_NS + +#endif +#endif diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 3430c26061..0bd392367f 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -20,11 +20,9 @@ #include "atom.h" #include "comm.h" -#include "compute.h" #include "domain.h" #include "error.h" #include "force.h" -#include "group.h" #include "input.h" #include "irregular.h" #include "kspace.h" @@ -41,292 +39,37 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{NONE=0,FINAL,DELTA,SCALE,VEL,ERATE,TRATE,VOLUME,WIGGLE,VARIABLE,PRESSURE,PMEAN}; +enum{NONE=0,FINAL,DELTA,SCALE,VEL,ERATE,TRATE,VOLUME,WIGGLE,VARIABLE}; enum{ONE_FROM_ONE,ONE_FROM_TWO,TWO_FROM_ONE}; -enum{NOCOUPLE=0,XYZ,XY,YZ,XZ}; /* ---------------------------------------------------------------------- */ FixDeform::FixDeform(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), -irregular(nullptr), set(nullptr), id_temp(nullptr), id_press(nullptr) +irregular(nullptr), set(nullptr) { - if (narg < 4) error->all(FLERR,"Illegal fix deform command"); + if (narg < 4) error->all(FLERR, "Illegal fix deform command"); no_change_box = 1; restart_global = 1; pre_exchange_migrate = 1; - pcouple = NOCOUPLE; - dimension = domain->dimension; - max_h_rate = 0.0; - vol_balance_flag = 0; - normalize_pressure_flag = 0; - nevery = utils::inumeric(FLERR,arg[3],false,lmp); - if (nevery <= 0) error->all(FLERR,"Illegal fix deform command"); + nevery = utils::inumeric(FLERR, arg[3], false, lmp); + if (nevery <= 0) error->all(FLERR, "Illegal fix deform command"); // set defaults set = new Set[7]; - memset(set,0,7*sizeof(Set)); + memset(set, 0, 7 * sizeof(Set)); // parse arguments triclinic = domain->triclinic; + options(narg, arg); - int index; - int iarg = 4; - while (iarg < narg) { - if (strcmp(arg[iarg],"x") == 0 || - strcmp(arg[iarg],"y") == 0 || - strcmp(arg[iarg],"z") == 0) { - - if (strcmp(arg[iarg],"x") == 0) index = 0; - else if (strcmp(arg[iarg],"y") == 0) index = 1; - else if (strcmp(arg[iarg],"z") == 0) index = 2; - - if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); - if (strcmp(arg[iarg+1],"final") == 0) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); - set[index].style = FINAL; - set[index].flo = utils::numeric(FLERR,arg[iarg+2],false,lmp); - set[index].fhi = utils::numeric(FLERR,arg[iarg+3],false,lmp); - iarg += 4; - } else if (strcmp(arg[iarg+1],"delta") == 0) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); - set[index].style = DELTA; - set[index].dlo = utils::numeric(FLERR,arg[iarg+2],false,lmp); - set[index].dhi = utils::numeric(FLERR,arg[iarg+3],false,lmp); - iarg += 4; - } else if (strcmp(arg[iarg+1],"scale") == 0) { - if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform scale", error); - set[index].style = SCALE; - set[index].scale = utils::numeric(FLERR,arg[iarg+2],false,lmp); - iarg += 3; - } else if (strcmp(arg[iarg+1],"vel") == 0) { - if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); - set[index].style = VEL; - set[index].vel = utils::numeric(FLERR,arg[iarg+2],false,lmp); - iarg += 3; - } else if (strcmp(arg[iarg+1],"erate") == 0) { - if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); - set[index].style = ERATE; - set[index].rate = utils::numeric(FLERR,arg[iarg+2],false,lmp); - iarg += 3; - } else if (strcmp(arg[iarg+1],"trate") == 0) { - if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); - set[index].style = TRATE; - set[index].rate = utils::numeric(FLERR,arg[iarg+2],false,lmp); - iarg += 3; - } else if (strcmp(arg[iarg+1],"volume") == 0) { - set[index].style = VOLUME; - iarg += 2; - } else if (strcmp(arg[iarg+1],"wiggle") == 0) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); - set[index].style = WIGGLE; - set[index].amplitude = utils::numeric(FLERR,arg[iarg+2],false,lmp); - set[index].tperiod = utils::numeric(FLERR,arg[iarg+3],false,lmp); - if (set[index].tperiod <= 0.0) - error->all(FLERR,"Illegal fix deform wiggle period, must be positive"); - iarg += 4; - } else if (strcmp(arg[iarg+1],"variable") == 0) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); - set[index].style = VARIABLE; - if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) - error->all(FLERR,"Illegal fix deform variable name {}", arg[iarg+2]); - if (strstr(arg[iarg+3],"v_") != arg[iarg+3]) - error->all(FLERR,"Illegal fix deform variable name {}", arg[iarg+3]); - delete[] set[index].hstr; - delete[] set[index].hratestr; - set[index].hstr = utils::strdup(&arg[iarg+2][2]); - set[index].hratestr = utils::strdup(&arg[iarg+3][2]); - iarg += 4; - } else if (strcmp(arg[iarg+1],"pressure") == 0) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform pressure", error); - set[index].style = PRESSURE; - if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { - set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); - } else { - set[index].pstr = utils::strdup(&arg[iarg+2][2]); - set[index].pvar_flag = 1; - } - set[index].pgain = utils::numeric(FLERR,arg[iarg+3],false,lmp); - if (set[index].pgain <= 0.0) - error->all(FLERR,"Illegal fix deform pressure gain, must be positive"); - iarg += 4; - } else if (strcmp(arg[iarg+1],"pressure/mean") == 0) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform pressure/mean", error); - set[index].style = PMEAN; - if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { - set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); - } else { - set[index].pstr = utils::strdup(&arg[iarg+2][2]); - set[index].pvar_flag = 1; - } - set[index].pgain = utils::numeric(FLERR,arg[iarg+3],false,lmp); - if (set[index].pgain <= 0.0) - error->all(FLERR,"Illegal fix deform pressure gain, must be positive"); - iarg += 4; - } else error->all(FLERR,"Illegal fix deform command argument: {}", arg[iarg+1]); - - } else if (strcmp(arg[iarg],"xy") == 0 || - strcmp(arg[iarg],"xz") == 0 || - strcmp(arg[iarg],"yz") == 0) { - - if (triclinic == 0) - error->all(FLERR,"Fix deform tilt factors require triclinic box"); - if (strcmp(arg[iarg],"xy") == 0) index = 5; - else if (strcmp(arg[iarg],"xz") == 0) index = 4; - else if (strcmp(arg[iarg],"yz") == 0) index = 3; - - if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); - if (strcmp(arg[iarg+1],"final") == 0) { - if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); - set[index].style = FINAL; - set[index].ftilt = utils::numeric(FLERR,arg[iarg+2],false,lmp); - iarg += 3; - } else if (strcmp(arg[iarg+1],"delta") == 0) { - if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); - set[index].style = DELTA; - set[index].dtilt = utils::numeric(FLERR,arg[iarg+2],false,lmp); - iarg += 3; - } else if (strcmp(arg[iarg+1],"vel") == 0) { - if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); - set[index].style = VEL; - set[index].vel = utils::numeric(FLERR,arg[iarg+2],false,lmp); - iarg += 3; - } else if (strcmp(arg[iarg+1],"erate") == 0) { - if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); - set[index].style = ERATE; - set[index].rate = utils::numeric(FLERR,arg[iarg+2],false,lmp); - iarg += 3; - } else if (strcmp(arg[iarg+1],"trate") == 0) { - if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); - set[index].style = TRATE; - set[index].rate = utils::numeric(FLERR,arg[iarg+2],false,lmp); - iarg += 3; - } else if (strcmp(arg[iarg+1],"wiggle") == 0) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); - set[index].style = WIGGLE; - set[index].amplitude = utils::numeric(FLERR,arg[iarg+2],false,lmp); - set[index].tperiod = utils::numeric(FLERR,arg[iarg+3],false,lmp); - if (set[index].tperiod <= 0.0) - error->all(FLERR,"Illegal fix deform wiggle period, must be positive"); - iarg += 4; - } else if (strcmp(arg[iarg+1],"variable") == 0) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); - set[index].style = VARIABLE; - if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) - error->all(FLERR,"Illegal fix deform variable name {}", arg[iarg+2]); - if (strstr(arg[iarg+3],"v_") != arg[iarg+3]) - error->all(FLERR,"Illegal fix deform variable name {}", arg[iarg+3]); - delete[] set[index].hstr; - delete[] set[index].hratestr; - set[index].hstr = utils::strdup(&arg[iarg+2][2]); - set[index].hratestr = utils::strdup(&arg[iarg+3][2]); - iarg += 4; - } else if (strcmp(arg[iarg+1],"pressure") == 0) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform pressure", error); - set[index].style = PRESSURE; - if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { - set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); - } else { - set[index].pstr = utils::strdup(&arg[iarg+2][2]); - set[index].pvar_flag = 1; - } - set[index].pgain = utils::numeric(FLERR,arg[iarg+3],false,lmp); - if (set[index].pgain <= 0.0) - error->all(FLERR,"Illegal fix deform pressure gain, must be positive"); - iarg += 4; - } else error->all(FLERR,"Illegal fix deform command: {}", arg[iarg+1]); - } else if (strcmp(arg[iarg],"iso") == 0) { - index = 6; - if (strcmp(arg[iarg+1],"volume") == 0) { - set[index].style = VOLUME; - iarg += 2; - } else if (strcmp(arg[iarg+1],"pressure") == 0) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix deform pressure", error); - set[index].style = PRESSURE; - if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) { - set[index].ptarget = utils::numeric(FLERR,arg[iarg+2],false,lmp); - } else { - set[index].pstr = utils::strdup(&arg[iarg+2][2]); - set[index].pvar_flag = 1; - } - set[index].pgain = utils::numeric(FLERR,arg[iarg+3],false,lmp); - if (set[index].pgain <= 0.0) - error->all(FLERR,"Illegal fix deform pressure gain, must be positive"); - iarg += 4; - } - } else break; - } - - // read options from end of input line // no x remap effectively moves atoms within box, so set restart_pbc - options(narg-iarg,&arg[iarg]); if (remapflag != Domain::X_REMAP) restart_pbc = 1; - // populate coupled pressure controls - - if (pcouple != NOCOUPLE) { - int coupled_indices[3] = {0}; - int j = -1; - double couple_gain, coupled_pressure; - char *couple_str; - - if (pcouple == XYZ || pcouple == XY || pcouple == XZ) - coupled_indices[0] = 1; - if (pcouple == XYZ || pcouple == XY || pcouple == YZ) - coupled_indices[1] = 1; - if (pcouple == XYZ || pcouple == XZ || pcouple == YZ) - coupled_indices[2] = 1; - - // Check coupled styles and find reference - for (int i = 0; i < 3; i++) { - if (coupled_indices[i]) { - set[i].coupled_flag = 1; - if (set[i].style != PRESSURE && set[i].style != NONE) - error->all(FLERR, "Cannot couple non-pressure-controlled dimensions"); - if (set[i].style == PRESSURE) - j = i; - } - } - - if (j == -1) - error->all(FLERR, "Must specify deformation style for at least one coupled dimension"); - - // Copy or compare data for each coupled dimension - for (int i = 0; i < 3; i++) { - if (coupled_indices[i]) { - // Copy coupling information if dimension style is undefined - if (set[i].style == NONE) { - set[i].style = PRESSURE; - set[i].pgain = set[j].pgain; - if (set[j].pvar_flag) { - set[i].pstr = set[j].pstr; - set[i].pvar_flag = 1; - } else { - set[i].ptarget = set[j].ptarget; - } - } else { - // Check for incompatibilities in style - if (set[j].style != set[i].style && set[i].style != NONE) - error->all(FLERR, "Cannot couple dimensions with different control options"); - if (set[j].style != PRESSURE) continue; - - // If pressure controlled, check for incompatibilities in parameters - if (set[i].pgain != set[j].pgain || set[i].pvar_flag != set[j].pvar_flag || - set[i].ptarget != set[j].ptarget) - error->all(FLERR, "Coupled dimensions must have identical gain parameters"); - - if (set[j].pvar_flag) - if (strcmp(set[i].pstr, set[j].pstr) != 0) - error->all(FLERR, "Coupled dimensions must have the same target pressure"); - } - } - } - } - // setup dimflags used by other classes to check for volume-change conflicts for (int i = 0; i < 6; i++) @@ -351,17 +94,17 @@ irregular(nullptr), set(nullptr), id_temp(nullptr), id_press(nullptr) for (int i = 0; i < 3; i++) if ((set[i].style || set[6].style) && (domain->boundary[i][0] >= 2 || domain->boundary[i][1] >= 2)) - error->all(FLERR,"Cannot use fix deform on a shrink-wrapped boundary"); + error->all(FLERR, "Cannot use fix deform on a shrink-wrapped boundary"); // no tilt deformation on shrink-wrapped 2nd dim // b/c shrink wrap will change tilt factor in domain::reset_box() if (set[3].style && (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) - error->all(FLERR,"Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); if (set[4].style && (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) - error->all(FLERR,"Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); if (set[5].style && (domain->boundary[1][0] >= 2 || domain->boundary[1][1] >= 2)) - error->all(FLERR,"Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); // apply scaling to FINAL,DELTA,VEL,WIGGLE since they have dist/vel units @@ -408,17 +151,15 @@ irregular(nullptr), set(nullptr), id_temp(nullptr), id_press(nullptr) // for VOLUME, setup links to other dims // fixed, dynamic1, dynamic2 - volume_flag = 0; for (int i = 0; i < 3; i++) { if (set[i].style != VOLUME) continue; - volume_flag = 1; - int other1 = (i+1) % 3; - int other2 = (i+2) % 3; + int other1 = (i + 1) % 3; + int other2 = (i + 2) % 3; // Cannot use VOLUME option without at least one deformed dimension if (set[other1].style == NONE || set[other1].style == VOLUME) if (set[other2].style == NONE || set[other2].style == VOLUME) - error->all(FLERR,"Fix deform volume setting is invalid"); + error->all(FLERR, "Fix deform volume setting is invalid"); if (set[other1].style == NONE) { set[i].substyle = ONE_FROM_ONE; @@ -441,19 +182,8 @@ irregular(nullptr), set(nullptr), id_temp(nullptr), id_press(nullptr) set[i].dynamic1 = other1; set[i].dynamic2 = other2; } - - if (vol_balance_flag && set[i].substyle != TWO_FROM_ONE) - error->all(FLERR, "Two dimensions must maintain constant volume to use the vol/balance/p option"); } - // set strain_flag - - strain_flag = 0; - for (int i = 0; i < 6; i++) - if (set[i].style != NONE && set[i].style != VOLUME && - set[i].style != PRESSURE && set[i].style != PMEAN) - strain_flag = 1; - // set varflag varflag = 0; @@ -462,38 +192,6 @@ irregular(nullptr), set(nullptr), id_temp(nullptr), id_press(nullptr) if (set[i].pvar_flag) varflag = 1; } - // set pressure_flag - - pressure_flag = 0; - for (int i = 0; i < 7; i++) { - if (set[i].style == PRESSURE || set[i].style == PMEAN) pressure_flag = 1; - if (set[i].coupled_flag) pressure_flag = 1; - } - if (vol_balance_flag) pressure_flag = 1; - - // check conflict between constant volume/pressure - - if (volume_flag) - for (int i = 0; i < 6; i++) - if (set[i].style == PMEAN) - error->all(FLERR, "Cannot use fix deform to assign constant volume and pressure"); - - // check conflicts between x,y,z styles and iso - - if (set[6].style) - for (int i = 0; i < 3; i++) { - if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == SCALE || set[i].style == PMEAN || set[i].style == VARIABLE) - error->all(FLERR, "Cannot use fix deform iso parameter with x, y, or z styles other than vel, erate, trate, pressure, and wiggle"); - } - - // check pressure used for max rate and normalize error flag - - if (!pressure_flag && max_h_rate != 0) - error->all(FLERR, "Can only assign a maximum strain rate using pressure-controlled dimensions"); - - if (!pressure_flag && normalize_pressure_flag) - error->all(FLERR, "Can only normalize error using pressure-controlled dimensions"); - // set initial values at time fix deform is issued for (int i = 0; i < 3; i++) { @@ -517,29 +215,6 @@ irregular(nullptr), set(nullptr), id_temp(nullptr), id_press(nullptr) if (force_reneighbor) irregular = new Irregular(lmp); else irregular = nullptr; - // Create pressure compute, if needed - - pflag = 0; - tflag = 0; - if (pressure_flag) { - // create a new compute temp style - // id = fix-ID + temp - // compute group = all since pressure is always global (group all) - // and thus its KE/temperature contribution should use group all - - id_temp = utils::strdup(std::string(id) + "_temp"); - modify->add_compute(fmt::format("{} all temp",id_temp)); - tflag = 1; - - // create a new compute pressure style - // id = fix-ID + press, compute group = all - // pass id_temp as 4th arg to pressure constructor - - id_press = utils::strdup(std::string(id) + "_press"); - modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); - pflag = 1; - } - // initialize all rates to 0.0 in constructor instead of init so values persist // across run statements and ghosts have correct velocities until the destructor h_rate = domain->h_rate; @@ -574,13 +249,6 @@ FixDeform::~FixDeform() h_rate[0] = h_rate[1] = h_rate[2] = h_rate[3] = h_rate[4] = h_rate[5] = 0.0; h_ratelo[0] = h_ratelo[1] = h_ratelo[2] = 0.0; - - // delete temperature and pressure if fix created them - - if (tflag) modify->delete_compute(id_temp); - if (pflag) modify->delete_compute(id_press); - delete [] id_temp; - delete [] id_press; } /* ---------------------------------------------------------------------- */ @@ -601,7 +269,7 @@ void FixDeform::init() // domain, fix nvt/sllod, compute temp/deform only work on single h_rate if (modify->get_fix_by_style("deform").size() > 1) - error->all(FLERR,"More than one fix deform"); + error->all(FLERR, "More than one fix deform"); // Kspace setting @@ -618,25 +286,14 @@ void FixDeform::init() if (set[i].style != VARIABLE) continue; set[i].hvar = input->variable->find(set[i].hstr); if (set[i].hvar < 0) - error->all(FLERR,"Variable name {} for fix deform does not exist", set[i].hstr); + error->all(FLERR, "Variable name {} for fix deform does not exist", set[i].hstr); if (!input->variable->equalstyle(set[i].hvar)) - error->all(FLERR,"Variable {} for fix deform is invalid style", set[i].hstr); + error->all(FLERR, "Variable {} for fix deform is invalid style", set[i].hstr); set[i].hratevar = input->variable->find(set[i].hratestr); if (set[i].hratevar < 0) - error->all(FLERR,"Variable name {} for fix deform does not exist", set[i].hratestr); + error->all(FLERR, "Variable name {} for fix deform does not exist", set[i].hratestr); if (!input->variable->equalstyle(set[i].hratevar)) - error->all(FLERR,"Variable {} for fix deform is invalid style", set[i].hratestr); - } - - // check optional variables for PRESSURE or PMEAN style - - for (int i = 0; i < 7; i++) { - if (!set[i].pvar_flag) continue; - set[i].pvar = input->variable->find(set[i].pstr); - if (set[i].pvar < 0) - error->all(FLERR,"Variable name {} for fix deform does not exist", set[i].pstr); - if (!input->variable->equalstyle(set[i].pvar)) - error->all(FLERR,"Variable {} for fix deform is invalid style", set[i].pstr); + error->all(FLERR, "Variable {} for fix deform is invalid style", set[i].hratestr); } // set start/stop values for box size and shape @@ -674,7 +331,7 @@ void FixDeform::init() set[i].lo_stop = set[i].lo_start - shift; set[i].hi_stop = set[i].hi_start + shift; if (set[i].hi_stop <= set[i].lo_stop) - error->all(FLERR,"Final box dimension due to fix deform is < 0.0"); + error->all(FLERR, "Final box dimension due to fix deform is < 0.0"); } else if (set[i].style == TRATE) { double shift = 0.5 * ((set[i].hi_start - set[i].lo_start) * exp(set[i].rate * delt)); set[i].lo_stop = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; @@ -752,22 +409,22 @@ void FixDeform::init() for (int i = 3; i < 6; i++) if (set[i].style == TRATE && set[i].tilt_start == 0.0) - error->all(FLERR,"Cannot use fix deform trate on a box with zero tilt"); + error->all(FLERR, "Cannot use fix deform trate on a box with zero tilt"); // if yz changes and will cause box flip, then xy cannot be changing // yz = [3], xy = [5] // this is b/c the flips would induce continuous changes in xz // in order to keep the edge vectors of the flipped shape matrix // an integer combination of the edge vectors of the unflipped shape matrix - // VARIABLE or PRESSURE for yz is error, since no way to calculate if box flip occurs + // VARIABLE for yz is error, since no way to calculate if box flip occurs // WIGGLE lo/hi flip test is on min/max oscillation limit, not tilt_stop // only trigger actual errors if flipflag is set if (set[3].style && set[5].style) { int flag = 0; double lo,hi; - if (flipflag && (set[3].style == VARIABLE || set[3].style == PRESSURE)) - error->all(FLERR,"Fix deform cannot use yz variable or pressure with xy"); + if (flipflag && set[3].style == VARIABLE) + error->all(FLERR, "Fix deform cannot use yz variable with xy"); if (set[3].style == WIGGLE) { lo = set[3].tilt_min; hi = set[3].tilt_max; @@ -780,13 +437,12 @@ void FixDeform::init() hi / (set[1].hi_stop - set[1].lo_stop) > 0.5) flag = 1; } if (flag) - error->all(FLERR,"Fix deform is changing yz too much with xy"); + error->all(FLERR, "Fix deform is changing yz too much with xy"); } } // set domain->h_rate values for use by domain and other fixes/computes - // cannot set here for TRATE,VOLUME,WIGGLE,VARIABLE,PRESSURE since not constant - // if iso style is used, these will also not be constant + // cannot set here for TRATE,VOLUME,WIGGLE,VARIABLE since not constant for (int i = 0; i < 3; i++) { if (set[i].style == FINAL || set[i].style == DELTA || @@ -818,28 +474,6 @@ void FixDeform::init() for (auto ifix : modify->get_fix_list()) if (ifix->rigid_flag) rfix.push_back(ifix); - - // Find pressure/temp computes if needed - - if (pressure_flag) { - int icompute = modify->find_compute(id_temp); - if (icompute < 0) error->all(FLERR,"Temperature ID for fix deform does not exist"); - temperature = modify->compute[icompute]; - - icompute = modify->find_compute(id_press); - if (icompute < 0) error->all(FLERR,"Pressure ID for fix deform does not exist"); - pressure = modify->compute[icompute]; - } -} - -/* ---------------------------------------------------------------------- - compute T,P if needed before integrator starts -------------------------------------------------------------------------- */ - -void FixDeform::setup(int /*vflag*/) -{ - // trigger virial computation on next timestep - if (pressure_flag) pressure->addstep(update->ntimestep+1); } /* ---------------------------------------------------------------------- @@ -862,7 +496,7 @@ void FixDeform::pre_exchange() domain->set_global_box(); domain->set_local_box(); - domain->image_flip(flipxy,flipxz,flipyz); + domain->image_flip(flipxy, flipxz, flipyz); double **x = atom->x; imageint *image = atom->image; @@ -888,43 +522,146 @@ void FixDeform::end_of_step() set_strain(); - // set new box size for pressure-based dims - - if (pressure_flag) { - temperature->compute_vector(); - pressure->compute_vector(); - pressure->compute_scalar(); - for (int i = 0; i < 3; i++) { - if (!set[i].saved) { - set[i].saved = 1; - set[i].prior_rate = 0.0; - set[i].prior_pressure = pressure->vector[i]; - } - } - set_pressure(); - } - // set new box size for VOLUME dims that are linked to other dims // NOTE: still need to set h_rate for these dims - if (volume_flag) set_volume(); - - // apply any final isotropic scalings - - if (set[6].style) set_iso(); - - // Save pressure/strain rate if required - - if (pressure_flag) { - for (int i = 0; i < 3; i++) { - set[i].prior_pressure = pressure->vector[i]; - set[i].prior_rate = ((set[i].hi_target - set[i].lo_target) / - (domain->boxhi[i] - domain->boxlo[i]) - 1.0) / update->dt; - } - } + set_volume(); if (varflag) modify->addstep_compute(update->ntimestep + nevery); + apply_deformation(); + + // redo KSpace coeffs since box has changed + + if (kspace_flag) force->kspace->setup(); +} + +/* ---------------------------------------------------------------------- + set box size for strain-based dimensions +------------------------------------------------------------------------- */ + +void FixDeform::set_strain() +{ + // for NONE, target is current box size + // for TRATE, set target directly based on current time, also set h_rate + // for WIGGLE, set target directly based on current time, also set h_rate + // for VARIABLE, set target directly via variable eval, also set h_rate + // for others except VOLUME, target is linear value between start and stop + + double delta = update->ntimestep - update->beginstep; + if (delta != 0.0) delta /= update->endstep - update->beginstep; + + for (int i = 0; i < 3; i++) { + if (set[i].style == NONE) { + set[i].lo_target = domain->boxlo[i]; + set[i].hi_target = domain->boxhi[i]; + } else if (set[i].style == TRATE) { + double delt = (update->ntimestep - update->beginstep) * update->dt; + double shift = 0.5 * ((set[i].hi_start - set[i].lo_start) * exp(set[i].rate * delt)); + set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; + set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; + h_rate[i] = set[i].rate * domain->h[i]; + h_ratelo[i] = -0.5 * h_rate[i]; + } else if (set[i].style == WIGGLE) { + double delt = (update->ntimestep - update->beginstep) * update->dt; + double shift = 0.5 * set[i].amplitude * sin(MY_2PI * delt / set[i].tperiod); + set[i].lo_target = set[i].lo_start - shift; + set[i].hi_target = set[i].hi_start + shift; + h_rate[i] = MY_2PI / set[i].tperiod * set[i].amplitude * + cos(MY_2PI * delt / set[i].tperiod); + h_ratelo[i] = -0.5 * h_rate[i]; + } else if (set[i].style == VARIABLE) { + double del = input->variable->compute_equal(set[i].hvar); + set[i].lo_target = set[i].lo_start - 0.5 * del; + set[i].hi_target = set[i].hi_start + 0.5 * del; + h_rate[i] = input->variable->compute_equal(set[i].hratevar); + h_ratelo[i] = -0.5 * h_rate[i]; + } else if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == SCALE || + set[i].style == VEL || set[i].style == ERATE) { + set[i].lo_target = set[i].lo_start + delta * (set[i].lo_stop - set[i].lo_start); + set[i].hi_target = set[i].hi_start + delta * (set[i].hi_stop - set[i].hi_start); + } + } + + // for triclinic, set new box shape + // for NONE, target is current tilt + // for TRATE, set target directly based on current time. also set h_rate + // for WIGGLE, set target directly based on current time. also set h_rate + // for VARIABLE, set target directly via variable eval. also set h_rate + // for other styles, target is linear value between start and stop values + + if (triclinic) { + double *h = domain->h; + + for (int i = 3; i < 6; i++) { + if (set[i].style == NONE) { + if (i == 5) set[i].tilt_target = domain->xy; + else if (i == 4) set[i].tilt_target = domain->xz; + else if (i == 3) set[i].tilt_target = domain->yz; + } else if (set[i].style == TRATE) { + double delt = (update->ntimestep - update->beginstep) * update->dt; + set[i].tilt_target = set[i].tilt_start * exp(set[i].rate * delt); + h_rate[i] = set[i].rate * domain->h[i]; + } else if (set[i].style == WIGGLE) { + double delt = (update->ntimestep - update->beginstep) * update->dt; + set[i].tilt_target = set[i].tilt_start + + set[i].amplitude * sin(MY_2PI * delt / set[i].tperiod); + h_rate[i] = MY_2PI / set[i].tperiod * set[i].amplitude * + cos(MY_2PI * delt / set[i].tperiod); + } else if (set[i].style == VARIABLE) { + double delta_tilt = input->variable->compute_equal(set[i].hvar); + set[i].tilt_target = set[i].tilt_start + delta_tilt; + h_rate[i] = input->variable->compute_equal(set[i].hratevar); + } else { + set[i].tilt_target = set[i].tilt_start + delta * (set[i].tilt_stop - set[i].tilt_start); + } + } + } +} + +/* ---------------------------------------------------------------------- + set box size for VOLUME dimensions +------------------------------------------------------------------------- */ + +void FixDeform::set_volume() +{ + double e1, e2; + + for (int i = 0; i < 3; i++) { + if (set[i].style != VOLUME) continue; + + int dynamic1 = set[i].dynamic1; + int dynamic2 = set[i].dynamic2; + int fixed = set[i].fixed; + double v0 = set[i].vol_start; + double shift; + + if (set[i].substyle == ONE_FROM_ONE) { + shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / + (set[fixed].hi_start-set[fixed].lo_start)); + } else if (set[i].substyle == ONE_FROM_TWO) { + shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / + (set[dynamic2].hi_target - set[dynamic2].lo_target)); + } else if (set[i].substyle == TWO_FROM_ONE) { + shift = 0.5 * sqrt(v0 * (set[i].hi_start - set[i].lo_start) / + (set[dynamic1].hi_target - set[dynamic1].lo_target) / + (set[fixed].hi_start - set[fixed].lo_start)); + } + + h_rate[i] = (2.0 * shift / (domain->boxhi[i] - domain->boxlo[i]) - 1.0) / update->dt; + h_ratelo[i] = -0.5 * h_rate[i]; + + set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; + set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; + } +} + +/* ---------------------------------------------------------------------- + Apply calculated deformation +------------------------------------------------------------------------- */ + +void FixDeform::apply_deformation() +{ // tilt_target can be large positive or large negative value // add/subtract box lengths until tilt_target is closest to current value @@ -1020,7 +757,7 @@ void FixDeform::end_of_step() for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) - domain->x2lamda(x[i],x[i]); + domain->x2lamda(x[i], x[i]); for (auto ifix : rfix) ifix->deform(0); @@ -1059,391 +796,11 @@ void FixDeform::end_of_step() for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) - domain->lamda2x(x[i],x[i]); + domain->lamda2x(x[i], x[i]); for (auto ifix : rfix) ifix->deform(1); } - - // redo KSpace coeffs since box has changed - - if (kspace_flag) force->kspace->setup(); - - // trigger virial computation, if needed, on next timestep - - if (pressure_flag) - pressure->addstep(update->ntimestep+1); -} - -/* ---------------------------------------------------------------------- - set box size for strain-based dimensions -------------------------------------------------------------------------- */ - -void FixDeform::set_strain() -{ - // for NONE, target is current box size - // for TRATE, set target directly based on current time, also set h_rate - // for WIGGLE, set target directly based on current time, also set h_rate - // for VARIABLE, set target directly via variable eval, also set h_rate - // for others except VOLUME, target is linear value between start and stop - - double delta = update->ntimestep - update->beginstep; - if (delta != 0.0) delta /= update->endstep - update->beginstep; - - for (int i = 0; i < 3; i++) { - if (set[i].style == NONE) { - set[i].lo_target = domain->boxlo[i]; - set[i].hi_target = domain->boxhi[i]; - } else if (set[i].style == TRATE) { - double delt = (update->ntimestep - update->beginstep) * update->dt; - double shift = 0.5 * ((set[i].hi_start - set[i].lo_start) * exp(set[i].rate * delt)); - set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; - set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; - h_rate[i] = set[i].rate * domain->h[i]; - h_ratelo[i] = -0.5 * h_rate[i]; - } else if (set[i].style == WIGGLE) { - double delt = (update->ntimestep - update->beginstep) * update->dt; - double shift = 0.5 * set[i].amplitude * sin(MY_2PI * delt / set[i].tperiod); - set[i].lo_target = set[i].lo_start - shift; - set[i].hi_target = set[i].hi_start + shift; - h_rate[i] = MY_2PI / set[i].tperiod * set[i].amplitude * - cos(MY_2PI * delt / set[i].tperiod); - h_ratelo[i] = -0.5 * h_rate[i]; - } else if (set[i].style == VARIABLE) { - double del = input->variable->compute_equal(set[i].hvar); - set[i].lo_target = set[i].lo_start - 0.5 * del; - set[i].hi_target = set[i].hi_start + 0.5 * del; - h_rate[i] = input->variable->compute_equal(set[i].hratevar); - h_ratelo[i] = -0.5 * h_rate[i]; - } else if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == SCALE || - set[i].style == VEL || set[i].style == ERATE) { - set[i].lo_target = set[i].lo_start + delta * (set[i].lo_stop - set[i].lo_start); - set[i].hi_target = set[i].hi_start + delta * (set[i].hi_stop - set[i].hi_start); - } - } - - // for triclinic, set new box shape - // for NONE, target is current tilt - // for TRATE, set target directly based on current time. also set h_rate - // for WIGGLE, set target directly based on current time. also set h_rate - // for VARIABLE, set target directly via variable eval. also set h_rate - // for other styles, target is linear value between start and stop values - - if (triclinic) { - double *h = domain->h; - - for (int i = 3; i < 6; i++) { - if (set[i].style == NONE) { - if (i == 5) set[i].tilt_target = domain->xy; - else if (i == 4) set[i].tilt_target = domain->xz; - else if (i == 3) set[i].tilt_target = domain->yz; - } else if (set[i].style == TRATE) { - double delt = (update->ntimestep - update->beginstep) * update->dt; - set[i].tilt_target = set[i].tilt_start * exp(set[i].rate * delt); - h_rate[i] = set[i].rate * domain->h[i]; - } else if (set[i].style == WIGGLE) { - double delt = (update->ntimestep - update->beginstep) * update->dt; - set[i].tilt_target = set[i].tilt_start + - set[i].amplitude * sin(MY_2PI * delt / set[i].tperiod); - h_rate[i] = MY_2PI / set[i].tperiod * set[i].amplitude * - cos(MY_2PI * delt / set[i].tperiod); - } else if (set[i].style == VARIABLE) { - double delta_tilt = input->variable->compute_equal(set[i].hvar); - set[i].tilt_target = set[i].tilt_start + delta_tilt; - h_rate[i] = input->variable->compute_equal(set[i].hratevar); - } else { - set[i].tilt_target = set[i].tilt_start + delta * (set[i].tilt_stop - set[i].tilt_start); - } - } - } -} - -/* ---------------------------------------------------------------------- - set box size for pressure-based dimensions -------------------------------------------------------------------------- */ - -void FixDeform::set_pressure() -{ - // If variable pressure, calculate current target - for (int i = 0; i < 6; i++) - if (set[i].style == PRESSURE) - if (set[i].pvar_flag) - set[i].ptarget = input->variable->compute_equal(set[i].pvar); - - // Find current (possibly coupled/hydrostatic) pressure for X, Y, Z - double *tensor = pressure->vector; - double scalar = pressure->scalar; - double p_current[3]; - - if (pcouple == XYZ) { - double ave = THIRD * (tensor[0] + tensor[1] + tensor[2]); - p_current[0] = p_current[1] = p_current[2] = ave; - } else if (pcouple == XY) { - double ave = 0.5 * (tensor[0] + tensor[1]); - p_current[0] = p_current[1] = ave; - p_current[2] = tensor[2]; - } else if (pcouple == YZ) { - double ave = 0.5 * (tensor[1] + tensor[2]); - p_current[1] = p_current[2] = ave; - p_current[0] = tensor[0]; - } else if (pcouple == XZ) { - double ave = 0.5 * (tensor[0] + tensor[2]); - p_current[0] = p_current[2] = ave; - p_current[1] = tensor[1]; - } else { - if (set[0].style == PRESSURE) p_current[0] = tensor[0]; - else if (set[0].style == PMEAN) p_current[0] = scalar; - - if (set[1].style == PRESSURE) p_current[1] = tensor[1]; - else if (set[1].style == PMEAN) p_current[1] = scalar; - - if (set[2].style == PRESSURE) p_current[2] = tensor[2]; - else if (set[2].style == PMEAN) p_current[2] = scalar; - } - - for (int i = 0; i < 3; i++) { - if (set[i].style != PRESSURE && set[i].style != PMEAN) continue; - - h_rate[i] = set[i].pgain * (p_current[i] - set[i].ptarget); - - if (normalize_pressure_flag) { - if (set[i].ptarget == 0) { - if (max_h_rate == 0) { - error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); - } else h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); - } else h_rate[i] /= fabs(set[i].ptarget); - } - - if (max_h_rate != 0) - if (fabs(h_rate[i]) > max_h_rate) - h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); - - h_ratelo[i] = -0.5 * h_rate[i]; - - double offset = 0.5 * (domain->boxhi[i] - domain->boxlo[i]) * (1.0 + update->dt * h_rate[i]); - set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - offset; - set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + offset; - } - - for (int i = 3; i < 6; i++) { - if (set[i].style != PRESSURE) continue; - - double L, tilt, pcurrent; - if (i == 3) { - L = domain->zprd; - tilt = domain->yz; - pcurrent = tensor[5]; - } else if (i == 4) { - L = domain->zprd; - tilt = domain->xz + update->dt; - pcurrent = tensor[4]; - } else { - L = domain->yprd; - tilt = domain->xy; - pcurrent = tensor[3]; - } - - h_rate[i] = L * set[i].pgain * (pcurrent - set[i].ptarget); - if (normalize_pressure_flag) { - if (set[i].ptarget == 0) { - if (max_h_rate == 0) { - error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); - } else h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); - } else h_rate[i] /= fabs(set[i].ptarget); - } - - if (max_h_rate != 0) - if (fabs(h_rate[i]) > max_h_rate) - h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); - - set[i].tilt_target = tilt + update->dt * h_rate[i]; - } -} - -/* ---------------------------------------------------------------------- - set box size for VOLUME dimensions -------------------------------------------------------------------------- */ - -void FixDeform::set_volume() -{ - double e1, e2; - int linked_pressure = 0; - - for (int i = 0; i < 3; i++) { - if (set[i].style != VOLUME) continue; - - int dynamic1 = set[i].dynamic1; - int dynamic2 = set[i].dynamic2; - int fixed = set[i].fixed; - double v0 = set[i].vol_start; - double shift; - - if (set[i].substyle == ONE_FROM_ONE) { - shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / - (set[fixed].hi_start-set[fixed].lo_start)); - } else if (set[i].substyle == ONE_FROM_TWO) { - shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / - (set[dynamic2].hi_target - set[dynamic2].lo_target)); - } else if (set[i].substyle == TWO_FROM_ONE) { - if (!vol_balance_flag) { - shift = 0.5 * sqrt(v0 * (set[i].hi_start - set[i].lo_start) / - (set[dynamic1].hi_target - set[dynamic1].lo_target) / - (set[fixed].hi_start - set[fixed].lo_start)); - } else { - double dt = update->dt; - double e1i = set[i].prior_rate; - double e2i = set[fixed].prior_rate; - double L1i = domain->boxhi[i] - domain->boxlo[i]; - double L2i = domain->boxhi[fixed] - domain->boxlo[fixed]; - double L3i = domain->boxhi[dynamic1] - domain->boxlo[dynamic1]; - double L3 = (set[dynamic1].hi_target - set[dynamic1].lo_target); - double Vi = L1i * L2i * L3i; - double V = L3 * L1i * L2i; - double e3 = (L3 / L3i - 1.0) / dt; - double p1 = pressure->vector[i]; - double p2 = pressure->vector[fixed]; - double p1i = set[i].prior_pressure; - double p2i = set[fixed].prior_pressure; - double denominator; - - if (e3 == 0) { - e1 = 0.0; - e2 = 0.0; - shift = 0.5 * L1i; - } else if (e1i == 0 || e2i == 0 || (p2 == p2i && p1 == p1i)) { - // If no prior strain or no change in pressure (initial step) just scale shift by relative box lengths - shift = 0.5 * sqrt(v0 * L1i / L3 / L2i); - } else { - if (!linked_pressure) { - // Calculate first strain rate by expanding stress to linear order, p1(t+dt) = p2(t+dt) - // Calculate second strain rate to preserve volume - denominator = p2 - p2i + e2i * ((p1 - p1i) / e1i); - if (denominator != 0.0 && e1i != 0.0) { - e1 = (((p2 - p2i) * (Vi - V) / (V * dt)) - e2i * (p1 - p2)) / denominator; - } else { - e1 = e2i; - } - e2 = (Vi - V * (1 + e1 * dt)) / (V * (1 + e1 * dt) * dt); - - // If strain rate exceeds limit in either dimension, cap it at the maximum compatible rate - if (max_h_rate != 0) - if (fabs(e1) > max_h_rate || fabs(e2) > max_h_rate) - if (fabs(e1) > fabs(e2)) - adjust_linked_rates(e1, e2, e3, Vi, V); - else - adjust_linked_rates(e2, e1, e3, Vi, V); - - - shift = 0.5 * L1i * (1.0 + e1 * dt); - linked_pressure = 1; - } else { - // Already calculated value of e2 - shift = 0.5 * L1i * (1.0 + e2 * dt); - } - } - } - } - - h_rate[i] = (2.0 * shift / (domain->boxhi[i] - domain->boxlo[i]) - 1.0) / update->dt; - h_ratelo[i] = -0.5 * h_rate[i]; - - set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; - set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; - } -} - - -/* ---------------------------------------------------------------------- - Rescale volume preserving strain rates to enforce max rate -------------------------------------------------------------------------- */ - -void FixDeform::adjust_linked_rates(double &e_larger, double &e_smaller, double e3, double Vi, double V) -{ - double dt = update->dt; - double e_lim_positive = (Vi - V * (1 + max_h_rate * dt)) / (V * (1 + max_h_rate * dt) * dt); - double e_lim_negative = (Vi - V * (1 - max_h_rate * dt)) / (V * (1 - max_h_rate * dt) * dt); - if ((e_larger * e3) >= 0) { - if (e_larger > 0.0) { - // Same sign as primary strain rate, cap third dimension - e_smaller = -max_h_rate; - e_larger = e_lim_negative; - } else { - e_smaller = max_h_rate; - e_larger = e_lim_positive; - } - } else { - // Opposite sign, set to maxrate. - if (e_larger > 0.0) { - e_larger = max_h_rate; - e_smaller = e_lim_positive; - } else { - e_larger = -max_h_rate; - e_smaller = e_lim_negative; - } - } -} - -/* ---------------------------------------------------------------------- - apply isotropic controls -------------------------------------------------------------------------- */ - -void FixDeform::set_iso() -{ - int i; - double scale, shift; - double v_rate; - - if (set[6].style == VOLUME) { - double v0 = set[6].vol_start; - double v = 1.0; - for (i = 0; i < 3; i++) - v *= (set[i].hi_target - set[i].lo_target); - - scale = std::pow(v0 / v, THIRD); - for (i = 0; i < 3; i++) { - shift = 0.5 * (set[i].hi_target - set[i].lo_target) * scale; - set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; - set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; - - // Recalculate h_rate - h_rate[i] = (set[i].hi_target - set[i].lo_target) / (domain->boxhi[i] - domain->boxlo[i]) - 1.0; - h_rate[i] /= update->dt; - h_ratelo[i] = -0.5 * h_rate[i]; - } - - } else if (set[6].style == PRESSURE) { - - // If variable pressure, calculate current target - if (set[6].pvar_flag) - set[6].ptarget = input->variable->compute_equal(set[6].pvar); - - v_rate = set[6].pgain * (pressure->scalar- set[6].ptarget); - - if (normalize_pressure_flag) { - if (set[6].ptarget == 0) { - if (max_h_rate == 0) { - error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); - } else v_rate = max_h_rate * v_rate / fabs(v_rate); - } else v_rate /= fabs(set[6].ptarget); - } - - if (max_h_rate != 0) - if (fabs(v_rate) > max_h_rate) - v_rate = max_h_rate * v_rate / fabs(v_rate); - - set[6].cumulative_strain += update->dt * v_rate; - scale = (1.0 + set[6].cumulative_strain); - for (i = 0; i < 3; i++) { - shift = 0.5 * (set[i].hi_target - set[i].lo_target) * scale; - set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; - set[i].hi_target = 0.5 * (set[i].lo_start + set[i].hi_start) + shift; - - // Recalculate h_rate - h_rate[i] = (set[i].hi_target - set[i].lo_target) / (domain->boxhi[i] - domain->boxlo[i]) - 1.0; - h_rate[i] /= update->dt; - h_ratelo[i] = -0.5 * h_rate[i]; - } - } } /* ---------------------------------------------------------------------- @@ -1454,10 +811,10 @@ void FixDeform::write_restart(FILE *fp) { if (comm->me == 0) { int size = 9 * sizeof(double) + 7 * sizeof(Set); - fwrite(&size,sizeof(int),1,fp); - fwrite(h_rate,sizeof(double),6,fp); - fwrite(h_ratelo,sizeof(double),3,fp); - fwrite(set,sizeof(Set),7,fp); + fwrite(&size, sizeof(int), 1, fp); + fwrite(h_rate, sizeof(double), 6, fp); + fwrite(h_ratelo, sizeof(double), 3, fp); + fwrite(set, sizeof(Set), 7, fp); } } @@ -1493,67 +850,168 @@ void FixDeform::restart(char *buf) samestyle = 0; } if (!samestyle) - error->all(FLERR,"Fix deform settings not consistent with restart"); + error->all(FLERR, "Fix deform settings not consistent with restart"); } /* ---------------------------------------------------------------------- */ void FixDeform::options(int narg, char **arg) { - if (narg < 0) error->all(FLERR,"Illegal fix deform command"); + if (narg < 0) error->all(FLERR, "Illegal fix deform command"); remapflag = Domain::X_REMAP; scaleflag = 1; flipflag = 1; - int iarg = 0; + int index; + int iarg = 4; while (iarg < narg) { - if (strcmp(arg[iarg],"remap") == 0) { - if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform remap", error); - if (strcmp(arg[iarg+1],"x") == 0) remapflag = Domain::X_REMAP; - else if (strcmp(arg[iarg+1],"v") == 0) remapflag = Domain::V_REMAP; - else if (strcmp(arg[iarg+1],"none") == 0) remapflag = Domain::NO_REMAP; - else error->all(FLERR,"Illegal fix deform remap command: {}", arg[iarg+1]); - iarg += 2; - } else if (strcmp(arg[iarg],"units") == 0) { - if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform units", error); - if (strcmp(arg[iarg+1],"box") == 0) scaleflag = 0; - else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = 1; - else error->all(FLERR,"Illegal fix deform units command: {}", arg[iarg+1]); - iarg += 2; - } else if (strcmp(arg[iarg],"flip") == 0) { - if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform flip", error); - flipflag = utils::logical(FLERR,arg[iarg+1],false,lmp); - iarg += 2; - } else if (strcmp(arg[iarg],"couple") == 0) { - if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform couple", error); - if (strcmp(arg[iarg+1],"xyz") == 0) pcouple = XYZ; - else if (strcmp(arg[iarg+1],"xy") == 0) pcouple = XY; - else if (strcmp(arg[iarg+1],"yz") == 0) pcouple = YZ; - else if (strcmp(arg[iarg+1],"xz") == 0) pcouple = XZ; - else if (strcmp(arg[iarg+1],"none") == 0) pcouple = NOCOUPLE; - else error->all(FLERR,"Illegal fix fix deform couple command: {}", arg[iarg+1]); - iarg += 2; - } else if (strcmp(arg[iarg],"max/rate") == 0) { - if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform max/rate", error); - max_h_rate = utils::numeric(FLERR,arg[iarg+1],false,lmp); - if (max_h_rate <= 0.0) - error->all(FLERR,"Maximum strain rate must be a positive, non-zero value"); - iarg += 2; - } else if (strcmp(arg[iarg],"normalize/pressure") == 0) { - if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform normalize/pressure", error); - normalize_pressure_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); - iarg += 2; - } else if (strcmp(arg[iarg],"vol/balance/p") == 0) { - if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix deform vol/balance/p", error); - vol_balance_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); - iarg += 2; - } else error->all(FLERR,"Illegal fix deform command: {}", arg[iarg]); + if (strcmp(arg[iarg], "x") == 0 || + strcmp(arg[iarg], "y") == 0 || + strcmp(arg[iarg], "z") == 0) { + + if (strcmp(arg[iarg], "x") == 0) index = 0; + else if (strcmp(arg[iarg], "y") == 0) index = 1; + else if (strcmp(arg[iarg], "z") == 0) index = 2; + + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); + if (strcmp(arg[iarg + 1], "final") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); + set[index].style = FINAL; + set[index].flo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].fhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "delta") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); + set[index].style = DELTA; + set[index].dlo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].dhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "scale") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform scale", error); + set[index].style = SCALE; + set[index].scale = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "vel") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); + set[index].style = VEL; + set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "erate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); + set[index].style = ERATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "trate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); + set[index].style = TRATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "volume") == 0) { + set[index].style = VOLUME; + iarg += 2; + } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); + set[index].style = WIGGLE; + set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + if (set[index].tperiod <= 0.0) + error->all(FLERR, "Illegal fix deform wiggle period, must be positive"); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "variable") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); + set[index].style = VARIABLE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) + error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 2]); + if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) + error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 3]); + delete[] set[index].hstr; + delete[] set[index].hratestr; + set[index].hstr = utils::strdup(&arg[iarg + 2][2]); + set[index].hratestr = utils::strdup(&arg[iarg + 3][2]); + iarg += 4; + } else error->all(FLERR, "Illegal fix deform command argument: {}", arg[iarg + 1]); + + } else if (strcmp(arg[iarg], "xy") == 0 || + strcmp(arg[iarg], "xz") == 0 || + strcmp(arg[iarg], "yz") == 0) { + + if (triclinic == 0) + error->all(FLERR, "Fix deform tilt factors require triclinic box"); + if (strcmp(arg[iarg], "xy") == 0) index = 5; + else if (strcmp(arg[iarg], "xz") == 0) index = 4; + else if (strcmp(arg[iarg], "yz") == 0) index = 3; + + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); + if (strcmp(arg[iarg + 1], "final") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); + set[index].style = FINAL; + set[index].ftilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "delta") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); + set[index].style = DELTA; + set[index].dtilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "vel") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); + set[index].style = VEL; + set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "erate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); + set[index].style = ERATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "trate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); + set[index].style = TRATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); + set[index].style = WIGGLE; + set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + if (set[index].tperiod <= 0.0) + error->all(FLERR, "Illegal fix deform wiggle period, must be positive"); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "variable") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); + set[index].style = VARIABLE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) + error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 2]); + if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) + error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 3]); + delete[] set[index].hstr; + delete[] set[index].hratestr; + set[index].hstr = utils::strdup(&arg[iarg + 2][2]); + set[index].hratestr = utils::strdup(&arg[iarg + 3][2]); + iarg += 4; + } else error->all(FLERR, "Illegal fix deform command: {}", arg[iarg + 1]); + } else break; } - if (dimension == 2) - if (pcouple == XYZ || pcouple == XZ || pcouple == YZ) - error->all(FLERR, "Cannot couple Z dimension in fix deform in 2D"); + while (iarg < narg) { + if (strcmp(arg[iarg], "remap") == 0) { + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform remap", error); + if (strcmp(arg[iarg + 1], "x") == 0) remapflag = Domain::X_REMAP; + else if (strcmp(arg[iarg + 1], "v") == 0) remapflag = Domain::V_REMAP; + else if (strcmp(arg[iarg + 1], "none") == 0) remapflag = Domain::NO_REMAP; + else error->all(FLERR, "Illegal fix deform remap command: {}", arg[iarg + 1]); + iarg += 2; + } else if (strcmp(arg[iarg], "units") == 0) { + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform units", error); + if (strcmp(arg[iarg + 1], "box") == 0) scaleflag = 0; + else if (strcmp(arg[iarg + 1], "lattice") == 0) scaleflag = 1; + else error->all(FLERR, "Illegal fix deform units command: {}", arg[iarg + 1]); + iarg += 2; + } else if (strcmp(arg[iarg], "flip") == 0) { + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform flip", error); + flipflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); + iarg += 2; + } else error->all(FLERR, "Illegal fix deform command: {}", arg[iarg]); + } } /* ---------------------------------------------------------------------- @@ -1566,54 +1024,3 @@ double FixDeform::memory_usage() if (irregular) bytes += irregular->memory_usage(); return bytes; } - -/* ---------------------------------------------------------------------- */ - -int FixDeform::modify_param(int narg, char **arg) -{ - if (strcmp(arg[0],"temp") == 0) { - if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); - if (tflag) { - modify->delete_compute(id_temp); - tflag = 0; - } - delete[] id_temp; - id_temp = utils::strdup(arg[1]); - - temperature = modify->get_compute_by_id(arg[1]); - if (!temperature) - error->all(FLERR,"Could not find fix_modify temperature compute ID: ", arg[1]); - - if (temperature->tempflag == 0) - error->all(FLERR,"Fix_modify temperature compute {} does not compute temperature", arg[1]); - if (temperature->igroup != 0 && comm->me == 0) - error->warning(FLERR,"Temperature compute {} for fix {} is not for group all: {}", - arg[1], style, group->names[temperature->igroup]); - - // reset id_temp of pressure to new temperature ID - - auto icompute = modify->get_compute_by_id(id_press); - if (!icompute) - error->all(FLERR,"Pressure compute ID {} for fix {} does not exist", id_press, style); - icompute->reset_extra_compute_fix(id_temp); - - return 2; - - } else if (strcmp(arg[0],"press") == 0) { - if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); - if (pflag) { - modify->delete_compute(id_press); - pflag = 0; - } - delete[] id_press; - id_press = utils::strdup(arg[1]); - - pressure = modify->get_compute_by_id(arg[1]); - if (!pressure) error->all(FLERR,"Could not find fix_modify pressure compute ID: {}", arg[1]); - if (pressure->pressflag == 0) - error->all(FLERR,"Fix_modify pressure compute {} does not compute pressure", arg[1]); - return 2; - } - - return 0; -} diff --git a/src/fix_deform.h b/src/fix_deform.h index 2f0b66aa71..dc4af75d33 100644 --- a/src/fix_deform.h +++ b/src/fix_deform.h @@ -33,32 +33,21 @@ class FixDeform : public Fix { ~FixDeform() override; int setmask() override; void init() override; - void setup(int) override; void pre_exchange() override; void end_of_step() override; void write_restart(FILE *) override; void restart(char *buf) override; double memory_usage() override; - int modify_param(int, char **) override; protected: - int dimension, triclinic, scaleflag, flipflag, pcouple; + int triclinic, scaleflag, flipflag; int flip, flipxy, flipxz, flipyz; - double *h_rate, *h_ratelo, max_h_rate; + double *h_rate, *h_ratelo; int varflag; // 1 if VARIABLE option is used, 0 if not - int strain_flag; // 1 if strain-based option is used, 0 if not - int volume_flag; // 1 if VOLUME option is used, 0 if not - int pressure_flag; // 1 if pressure tensor used, 0 if not int kspace_flag; // 1 if KSpace invoked, 0 if not - int normalize_pressure_flag; // 1 if normalize pressure deviation by target - int vol_balance_flag; // 1 if pressures balanced when maintaining const vol std::vector rfix; // pointers to rigid fixes class Irregular *irregular; // for migrating atoms after box flips - char *id_temp, *id_press; - class Compute *temperature, *pressure; - int tflag, pflag; - struct Set { int style, substyle; double flo, fhi, ftilt; @@ -84,11 +73,8 @@ class FixDeform : public Fix { void options(int, char **); void set_strain(); - void set_pressure(); void set_volume(); - void set_iso(); - void couple(); - void adjust_linked_rates(double&, double&, double, double, double); + void apply_deformation(); }; } // namespace LAMMPS_NS From 7c7f07e28d199fc7ac3948d02bb27a85b65ac5ce Mon Sep 17 00:00:00 2001 From: jtclemm Date: Mon, 22 Jan 2024 22:13:29 -0700 Subject: [PATCH 026/185] Misc patches and missed changes --- doc/src/fix_deform.rst | 2 +- src/EXTRA-FIX/fix_deform_pressure.cpp | 2 +- src/EXTRA-FIX/fix_deform_pressure.h | 4 ++-- src/fix_deform.cpp | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/src/fix_deform.rst b/doc/src/fix_deform.rst index 84670b37a8..ee010f5645 100644 --- a/doc/src/fix_deform.rst +++ b/doc/src/fix_deform.rst @@ -597,4 +597,4 @@ Related commands Default """"""" -The option defaults are remap = x, flip = yes, units = lattice +The option defaults are remap = x, flip = yes, and units = lattice. diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index 666ca5f2af..c76550b40f 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -2,7 +2,7 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov + LAMMPS development team: developers@lammps.org Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains diff --git a/src/EXTRA-FIX/fix_deform_pressure.h b/src/EXTRA-FIX/fix_deform_pressure.h index d3a05d949d..7e4ad6e35a 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.h +++ b/src/EXTRA-FIX/fix_deform_pressure.h @@ -1,7 +1,7 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov + LAMMPS development team: developers@lammps.org Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains @@ -35,7 +35,7 @@ class FixDeformPressure : public FixDeform { protected: int pcouple, dimension; - double *h_rate, *h_ratelo, max_h_rate; + double max_h_rate; int strain_flag; // 1 if strain-based option is used, 0 if not int pressure_flag; // 1 if pressure tensor used, 0 if not int volume_flag; // 1 if VOLUME option is used, 0 if not diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index d78e28ef2f..cf45a12f5d 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -13,7 +13,7 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Pieter in 't Veld (SNL), Joel Clemmer (SNL) + Contributing author: Pieter in 't Veld (SNL) ------------------------------------------------------------------------- */ #include "fix_deform.h" @@ -759,7 +759,7 @@ void FixDeform::apply_deformation() if (mask[i] & groupbit) domain->x2lamda(x[i], x[i]); - for (auto ifix : rfix) + for (auto &ifix : rfix) ifix->deform(0); } @@ -798,7 +798,7 @@ void FixDeform::apply_deformation() if (mask[i] & groupbit) domain->lamda2x(x[i], x[i]); - for (auto ifix : rfix) + for (auto &ifix : rfix) ifix->deform(1); } } From 7f152de062c9e7f1bb356a4d2b846d748eb313bb Mon Sep 17 00:00:00 2001 From: jtclemm Date: Tue, 30 Jan 2024 15:29:02 -0700 Subject: [PATCH 027/185] Rewiring arg parsing and data ownership --- src/EXTRA-FIX/fix_deform_pressure.cpp | 589 +++++++++++++------------- src/EXTRA-FIX/fix_deform_pressure.h | 20 +- src/fix_deform.cpp | 367 ++++++++-------- src/fix_deform.h | 18 +- 4 files changed, 520 insertions(+), 474 deletions(-) diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index c76550b40f..7f3a627b66 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -50,9 +50,160 @@ enum{NOCOUPLE=0,XYZ,XY,YZ,XZ}; FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : FixDeform(lmp, narg, arg), id_temp(nullptr), id_press(nullptr) { + // set defaults + + set_extra = new SetExtra[7]; + memset(set_extra, 0, 7 * sizeof(SetExtra)); + memset(&set_box, 0, sizeof(Set)); + + // parse child-specific arguments + + int index; + int iarg = 4; + while (iarg < narg) { + if (strcmp(arg[iarg], "x") == 0 || + strcmp(arg[iarg], "y") == 0 || + strcmp(arg[iarg], "z") == 0) { + + if (strcmp(arg[iarg], "x") == 0) index = 0; + else if (strcmp(arg[iarg], "y") == 0) index = 1; + else if (strcmp(arg[iarg], "z") == 0) index = 2; + + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure", error); + if (strcmp(arg[iarg + 1], "pressure") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure", error); + set[index].style = PRESSURE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { + set_extra[index].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + } else { + set_extra[index].pstr = utils::strdup(&arg[iarg + 2][2]); + set_extra[index].pvar_flag = 1; + } + set_extra[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "pressure/mean") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure/mean", error); + set[index].style = PMEAN; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { + set_extra[index].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + } else { + set_extra[index].pstr = utils::strdup(&arg[iarg + 2][2]); + set_extra[index].pvar_flag = 1; + } + set_extra[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + iarg += 4; + } else error->all(FLERR, "Illegal fix deform/pressure command argument: {}", arg[iarg + 1]); + + } else if (strcmp(arg[iarg], "xy") == 0 || + strcmp(arg[iarg], "xz") == 0 || + strcmp(arg[iarg], "yz") == 0) { + + if (strcmp(arg[iarg], "xy") == 0) index = 5; + else if (strcmp(arg[iarg], "xz") == 0) index = 4; + else if (strcmp(arg[iarg], "yz") == 0) index = 3; + + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure", error); + if (strcmp(arg[iarg + 1], "pressure") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure", error); + set[index].style = PRESSURE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { + set_extra[index].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + } else { + set_extra[index].pstr = utils::strdup(&arg[iarg + 2][2]); + set_extra[index].pvar_flag = 1; + } + set_extra[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + iarg += 4; + } else error->all(FLERR, "Illegal fix deform/pressure command: {}", arg[iarg + 1]); + } else if (strcmp(arg[iarg], "box") == 0) { + if (strcmp(arg[iarg + 1], "volume") == 0) { + set_box.style = VOLUME; + iarg += 2; + } else if (strcmp(arg[iarg + 1], "pressure") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure", error); + set_box.style = PRESSURE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { + set_extra[6].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + } else { + set_extra[6].pstr = utils::strdup(&arg[iarg + 2][2]); + set_extra[6].pvar_flag = 1; + } + set_extra[6].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + iarg += 4; + } else error->all(FLERR, "Illegal fix deform/pressure command argument: {}", arg[iarg + 1]); + } else break; + } + + // read options from end of input line + + options(narg - iarg, &arg[iarg]); + + // repeat: check triclinic + + dimension = domain->dimension; + if (triclinic == 0 && (set[3].style || set[4].style || set[5].style)) + error->all(FLERR, "Fix deform tilt factors require triclinic box"); + + // repeat: setup dimflags used by other classes to check for volume-change conflicts + + for (int i = 0; i < 6; i++) + if (set[i].style == NONE) dimflag[i] = 0; + else dimflag[i] = 1; + + if (set_box.style != NONE) { + dimflag[0] = 1; + dimflag[1] = 1; + dimflag[2] = 1; + } + + if (dimflag[0]) box_change |= BOX_CHANGE_X; + if (dimflag[1]) box_change |= BOX_CHANGE_Y; + if (dimflag[2]) box_change |= BOX_CHANGE_Z; + if (dimflag[3]) box_change |= BOX_CHANGE_YZ; + if (dimflag[4]) box_change |= BOX_CHANGE_XZ; + if (dimflag[5]) box_change |= BOX_CHANGE_XY; + + // repeat: no tensile deformation on shrink-wrapped dims + // b/c shrink wrap will change box-length + + for (int i = 0; i < 3; i++) + if (set_box.style && (domain->boundary[i][0] >= 2 || domain->boundary[i][1] >= 2)) + error->all(FLERR, "Cannot use fix deform on a shrink-wrapped boundary"); + + // repeat: no tilt deformation on shrink-wrapped 2nd dim + // b/c shrink wrap will change tilt factor in domain::reset_box() + + if (set[3].style && (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) + error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + if (set[4].style && (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) + error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + if (set[5].style && (domain->boundary[1][0] >= 2 || domain->boundary[1][1] >= 2)) + error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + + // repeat: set varflag + + for (int i = 0; i < 7; i++) + if (set_extra[i].pvar_flag) varflag = 1; + + // repeat: reneighboring only forced if flips can occur due to shape changes + + if ((!force_reneighbor) && flipflag && (set[3].style || set[4].style || set[5].style)) { + force_reneighbor = 1; + irregular = new Irregular(lmp); + } + + // set initial values at time fix deform is issued + + set_box.vol_initial = domain->xprd * domain->yprd * domain->zprd; + // populate coupled pressure controls if (pcouple != NOCOUPLE) { + + if (dimension == 2) + if (pcouple == XYZ || pcouple == XZ || pcouple == YZ) + error->all(FLERR, "Cannot couple Z dimension in fix deform/pressure in 2D"); + int coupled_indices[3] = {0}; int j = -1; double couple_gain, coupled_pressure; @@ -68,7 +219,7 @@ id_temp(nullptr), id_press(nullptr) // Check coupled styles and find reference for (int i = 0; i < 3; i++) { if (coupled_indices[i]) { - set[i].coupled_flag = 1; + set_extra[i].coupled_flag = 1; if (set[i].style != PRESSURE && set[i].style != NONE) error->all(FLERR, "Cannot couple non-pressure-controlled dimensions"); if (set[i].style == PRESSURE) @@ -86,12 +237,12 @@ id_temp(nullptr), id_press(nullptr) if (set[i].style == NONE) { set[i].style = PRESSURE; dimflag[i] = 1; - set[i].pgain = set[j].pgain; - if (set[j].pvar_flag) { - set[i].pstr = set[j].pstr; - set[i].pvar_flag = 1; + set_extra[i].pgain = set_extra[j].pgain; + if (set_extra[j].pvar_flag) { + set_extra[i].pstr = set_extra[j].pstr; + set_extra[i].pvar_flag = 1; } else { - set[i].ptarget = set[j].ptarget; + set_extra[i].ptarget = set_extra[j].ptarget; } } else { // Check for incompatibilities in style @@ -100,31 +251,18 @@ id_temp(nullptr), id_press(nullptr) if (set[j].style != PRESSURE) continue; // If pressure controlled, check for incompatibilities in parameters - if (set[i].pgain != set[j].pgain || set[i].pvar_flag != set[j].pvar_flag || - set[i].ptarget != set[j].ptarget) + if (set_extra[i].pgain != set_extra[j].pgain || set_extra[i].pvar_flag != set_extra[j].pvar_flag || + set_extra[i].ptarget != set_extra[j].ptarget) error->all(FLERR, "Coupled dimensions must have identical gain parameters"); - if (set[j].pvar_flag) - if (strcmp(set[i].pstr, set[j].pstr) != 0) + if (set_extra[j].pvar_flag) + if (strcmp(set_extra[i].pstr, set_extra[j].pstr) != 0) error->all(FLERR, "Coupled dimensions must have the same target pressure"); } } } } - // repeat some checks in child class to catch changes to pcouple - - if (dimflag[0]) box_change |= BOX_CHANGE_X; - if (dimflag[1]) box_change |= BOX_CHANGE_Y; - if (dimflag[2]) box_change |= BOX_CHANGE_Z; - - // no tensile deformation on shrink-wrapped dims - // b/c shrink wrap will change box-length - - for (int i = 0; i < 3; i++) - if ((set[i].style || set[6].style) && (domain->boundary[i][0] >= 2 || domain->boundary[i][1] >= 2)) - error->all(FLERR, "Cannot use fix deform/pressure on a shrink-wrapped boundary"); - // if vol/balance/p used, must have 2 free dimensions if (vol_balance_flag) { @@ -146,10 +284,15 @@ id_temp(nullptr), id_press(nullptr) // set pressure_flag pressure_flag = 0; - for (int i = 0; i < 7; i++) { - if (set[i].style == PRESSURE || set[i].style == PMEAN) pressure_flag = 1; - if (set[i].coupled_flag) pressure_flag = 1; + for (int i = 0; i < 6; i++) { + if (set[i].style == PRESSURE || set[i].style == PMEAN) { + pressure_flag = 1; + if (set_extra[i].pgain <= 0.0) + error->all(FLERR, "Illegal fix deform/pressure gain constant, must be positive"); + } + if (set_extra[i].coupled_flag) pressure_flag = 1; } + if (set_box.style == PRESSURE) pressure_flag = 1; if (vol_balance_flag) pressure_flag = 1; // check conflict between constant volume/pressure @@ -164,12 +307,12 @@ id_temp(nullptr), id_press(nullptr) if (set[i].style == PMEAN) error->all(FLERR, "Cannot use fix deform/pressure to assign constant volume and pressure"); - // check conflicts between x,y,z styles and iso + // check conflicts between x,y,z styles and box - if (set[6].style) + if (set_box.style) for (int i = 0; i < 3; i++) if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == SCALE || set[i].style == PMEAN || set[i].style == VARIABLE) - error->all(FLERR, "Cannot use fix deform/pressure iso parameter with x, y, or z styles other than vel, erate, trate, pressure, and wiggle"); + error->all(FLERR, "Cannot use fix deform/pressure box parameter with x, y, or z styles other than vel, erate, trate, pressure, and wiggle"); // check pressure used for max rate and normalize error flag @@ -207,6 +350,14 @@ id_temp(nullptr), id_press(nullptr) FixDeformPressure::~FixDeformPressure() { + if (set_extra) + for (int i = 0; i < 7; i++) + delete[] set_extra[i].pstr; + delete[] set_extra; + + delete[] set_box.hstr; + delete[] set_box.hratestr; + // delete temperature and pressure if fix created them if (tflag) modify->delete_compute(id_temp); @@ -221,15 +372,17 @@ void FixDeformPressure::init() { FixDeform::init(); + set_box.vol_start = domain->xprd * domain->yprd * domain->zprd; + // check optional variables for PRESSURE or PMEAN style for (int i = 0; i < 7; i++) { - if (!set[i].pvar_flag) continue; - set[i].pvar = input->variable->find(set[i].pstr); - if (set[i].pvar < 0) - error->all(FLERR, "Variable name {} for fix deform/pressure does not exist", set[i].pstr); - if (!input->variable->equalstyle(set[i].pvar)) - error->all(FLERR, "Variable {} for fix deform/pressure is invalid style", set[i].pstr); + if (!set_extra[i].pvar_flag) continue; + set_extra[i].pvar = input->variable->find(set_extra[i].pstr); + if (set_extra[i].pvar < 0) + error->all(FLERR, "Variable name {} for fix deform/pressure does not exist", set_extra[i].pstr); + if (!input->variable->equalstyle(set_extra[i].pvar)) + error->all(FLERR, "Variable {} for fix deform/pressure is invalid style", set_extra[i].pstr); } // Find pressure/temp computes if needed @@ -265,7 +418,7 @@ void FixDeformPressure::end_of_step() // set new box size for strain-based dims - if (strain_flag) FixDeform::set_strain(); + if (strain_flag) FixDeform::apply_strain(); // set new box size for pressure-based dims @@ -274,30 +427,30 @@ void FixDeformPressure::end_of_step() pressure->compute_vector(); pressure->compute_scalar(); for (int i = 0; i < 3; i++) { - if (!set[i].saved) { - set[i].saved = 1; - set[i].prior_rate = 0.0; - set[i].prior_pressure = pressure->vector[i]; + if (!set_extra[i].saved) { + set_extra[i].saved = 1; + set_extra[i].prior_rate = 0.0; + set_extra[i].prior_pressure = pressure->vector[i]; } } - set_pressure(); + apply_pressure(); } // set new box size for VOLUME dims that are linked to other dims // NOTE: still need to set h_rate for these dims - if (volume_flag) set_volume(); + if (volume_flag) apply_volume(); - // apply any final isotropic scalings + // apply any final box scalings - if (set[6].style) set_iso(); + if (set_box.style) apply_box(); // Save pressure/strain rate if required if (pressure_flag) { for (int i = 0; i < 3; i++) { - set[i].prior_pressure = pressure->vector[i]; - set[i].prior_rate = ((set[i].hi_target - set[i].lo_target) / + set_extra[i].prior_pressure = pressure->vector[i]; + set_extra[i].prior_rate = ((set[i].hi_target - set[i].lo_target) / (domain->boxhi[i] - domain->boxlo[i]) - 1.0) / update->dt; } } @@ -305,7 +458,7 @@ void FixDeformPressure::end_of_step() if (varflag) modify->addstep_compute(update->ntimestep + nevery); - FixDeform::apply_deformation(); + FixDeform::update_domain(); // trigger virial computation, if needed, on next timestep @@ -314,16 +467,16 @@ void FixDeformPressure::end_of_step() } /* ---------------------------------------------------------------------- - set box size for pressure-based dimensions + apply pressure controls ------------------------------------------------------------------------- */ -void FixDeformPressure::set_pressure() +void FixDeformPressure::apply_pressure() { // If variable pressure, calculate current target for (int i = 0; i < 6; i++) if (set[i].style == PRESSURE) - if (set[i].pvar_flag) - set[i].ptarget = input->variable->compute_equal(set[i].pvar); + if (set_extra[i].pvar_flag) + set_extra[i].ptarget = input->variable->compute_equal(set_extra[i].pvar); // Find current (possibly coupled/hydrostatic) pressure for X, Y, Z double *tensor = pressure->vector; @@ -359,14 +512,14 @@ void FixDeformPressure::set_pressure() for (int i = 0; i < 3; i++) { if (set[i].style != PRESSURE && set[i].style != PMEAN) continue; - h_rate[i] = set[i].pgain * (p_current[i] - set[i].ptarget); + h_rate[i] = set_extra[i].pgain * (p_current[i] - set_extra[i].ptarget); if (normalize_pressure_flag) { - if (set[i].ptarget == 0) { + if (set_extra[i].ptarget == 0) { if (max_h_rate == 0) { error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); } else h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); - } else h_rate[i] /= fabs(set[i].ptarget); + } else h_rate[i] /= fabs(set_extra[i].ptarget); } if (max_h_rate != 0) @@ -398,13 +551,13 @@ void FixDeformPressure::set_pressure() pcurrent = tensor[3]; } - h_rate[i] = L * set[i].pgain * (pcurrent - set[i].ptarget); + h_rate[i] = L * set_extra[i].pgain * (pcurrent - set_extra[i].ptarget); if (normalize_pressure_flag) { - if (set[i].ptarget == 0) { + if (set_extra[i].ptarget == 0) { if (max_h_rate == 0) { error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); } else h_rate[i] = max_h_rate * h_rate[i] / fabs(h_rate[i]); - } else h_rate[i] /= fabs(set[i].ptarget); + } else h_rate[i] /= fabs(set_extra[i].ptarget); } if (max_h_rate != 0) @@ -416,10 +569,10 @@ void FixDeformPressure::set_pressure() } /* ---------------------------------------------------------------------- - set box size for VOLUME dimensions + apply volume controls ------------------------------------------------------------------------- */ -void FixDeformPressure::set_volume() +void FixDeformPressure::apply_volume() { double e1, e2; int linked_pressure = 0; @@ -446,8 +599,8 @@ void FixDeformPressure::set_volume() (set[fixed].hi_start - set[fixed].lo_start)); } else { double dt = update->dt; - double e1i = set[i].prior_rate; - double e2i = set[fixed].prior_rate; + double e1i = set_extra[i].prior_rate; + double e2i = set_extra[fixed].prior_rate; double L1i = domain->boxhi[i] - domain->boxlo[i]; double L2i = domain->boxhi[fixed] - domain->boxlo[fixed]; double L3i = domain->boxhi[dynamic1] - domain->boxlo[dynamic1]; @@ -457,8 +610,8 @@ void FixDeformPressure::set_volume() double e3 = (L3 / L3i - 1.0) / dt; double p1 = pressure->vector[i]; double p2 = pressure->vector[fixed]; - double p1i = set[i].prior_pressure; - double p2i = set[fixed].prior_pressure; + double p1i = set_extra[i].prior_pressure; + double p2i = set_extra[fixed].prior_pressure; double denominator; if (e3 == 0) { @@ -539,17 +692,17 @@ void FixDeformPressure::adjust_linked_rates(double &e_larger, double &e_smaller, } /* ---------------------------------------------------------------------- - apply isotropic controls + apply box controls ------------------------------------------------------------------------- */ -void FixDeformPressure::set_iso() +void FixDeformPressure::apply_box() { int i; double scale, shift; double v_rate; - if (set[6].style == VOLUME) { - double v0 = set[6].vol_start; + if (set_box.style == VOLUME) { + double v0 = set_box.vol_start; double v = 1.0; for (i = 0; i < 3; i++) v *= (set[i].hi_target - set[i].lo_target); @@ -566,28 +719,28 @@ void FixDeformPressure::set_iso() h_ratelo[i] = -0.5 * h_rate[i]; } - } else if (set[6].style == PRESSURE) { + } else if (set_box.style == PRESSURE) { // If variable pressure, calculate current target - if (set[6].pvar_flag) - set[6].ptarget = input->variable->compute_equal(set[6].pvar); + if (set_extra[6].pvar_flag) + set_extra[6].ptarget = input->variable->compute_equal(set_extra[6].pvar); - v_rate = set[6].pgain * (pressure->scalar- set[6].ptarget); + v_rate = set_extra[6].pgain * (pressure->scalar - set_extra[6].ptarget); if (normalize_pressure_flag) { - if (set[6].ptarget == 0) { + if (set_extra[6].ptarget == 0) { if (max_h_rate == 0) { error->all(FLERR, "Cannot normalize error for zero pressure without defining a max rate"); } else v_rate = max_h_rate * v_rate / fabs(v_rate); - } else v_rate /= fabs(set[6].ptarget); + } else v_rate /= fabs(set_extra[6].ptarget); } if (max_h_rate != 0) if (fabs(v_rate) > max_h_rate) v_rate = max_h_rate * v_rate / fabs(v_rate); - set[6].cumulative_strain += update->dt * v_rate; - scale = (1.0 + set[6].cumulative_strain); + set_extra[6].cumulative_strain += update->dt * v_rate; + scale = (1.0 + set_extra[6].cumulative_strain); for (i = 0; i < 3; i++) { shift = 0.5 * (set[i].hi_target - set[i].lo_target) * scale; set[i].lo_target = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; @@ -601,235 +754,95 @@ void FixDeformPressure::set_iso() } } +/* ---------------------------------------------------------------------- + write Set data to restart file +------------------------------------------------------------------------- */ + +void FixDeformPressure::write_restart(FILE *fp) +{ + if (comm->me == 0) { + int size = 9 * sizeof(double) + 7 * sizeof(Set) + 7 * sizeof(SetExtra); + fwrite(&size, sizeof(int), 1, fp); + fwrite(h_rate, sizeof(double), 6, fp); + fwrite(h_ratelo, sizeof(double), 3, fp); + fwrite(set, sizeof(Set), 6, fp); + fwrite(&set_box, sizeof(Set), 1, fp); + fwrite(set_extra, sizeof(SetExtra), 7, fp); + } +} + +/* ---------------------------------------------------------------------- + use selected state info from restart file to restart the Fix +------------------------------------------------------------------------- */ + +void FixDeformPressure::restart(char *buf) +{ + int n = 0; + auto list = (double *) buf; + for (int i = 0; i < 6; i++) + h_rate[i] = list[n++]; + for (int i = 0; i < 3; i++) + h_ratelo[i] = list[n++]; + + n = n * sizeof(double); + int samestyle = 1; + Set *set_restart = (Set *) &buf[n]; + for (int i = 0; i < 6; ++i) { + // restore data from initial state + set[i].lo_initial = set_restart[i].lo_initial; + set[i].hi_initial = set_restart[i].hi_initial; + set[i].vol_initial = set_restart[i].vol_initial; + set[i].tilt_initial = set_restart[i].tilt_initial; + // check if style settings are consistent (should do the whole set?) + if (set[i].style != set_restart[i].style) + samestyle = 0; + if (set[i].substyle != set_restart[i].substyle) + samestyle = 0; + } + n += 6 * sizeof(Set); + + // Only restore relevant box variables & check consistency + Set set_box_restart; + memcpy(&set_box_restart, (Set *) &buf[n], sizeof(Set)); + set_box.vol_initial = set_box_restart.vol_initial; + if (set_box.style != set_box_restart.style) + samestyle = 0; + + if (!samestyle) + error->all(FLERR, "Fix deform/pressure settings not consistent with restart"); + + n += sizeof(Set); + SetExtra *set_extra_restart = (SetExtra *) &buf[n]; + for (int i = 0; i < 7; ++i) { + set_extra[i].saved = set_extra_restart[i].saved; + set_extra[i].prior_rate = set_extra_restart[i].prior_rate; + set_extra[i].prior_pressure = set_extra_restart[i].prior_pressure; + set_extra[i].cumulative_strain = set_extra_restart[i].cumulative_strain; + } +} + + /* ---------------------------------------------------------------------- */ void FixDeformPressure::options(int narg, char **arg) { if (narg < 0) error->all(FLERR, "Illegal fix deform/pressure command"); - remapflag = Domain::X_REMAP; - scaleflag = 1; - flipflag = 1; - pcouple = NOCOUPLE; - dimension = domain->dimension; max_h_rate = 0.0; vol_balance_flag = 0; normalize_pressure_flag = 0; - int index; - int iarg = 4; + int iarg = 0; while (iarg < narg) { - if (strcmp(arg[iarg], "x") == 0 || - strcmp(arg[iarg], "y") == 0 || - strcmp(arg[iarg], "z") == 0) { - - if (strcmp(arg[iarg], "x") == 0) index = 0; - else if (strcmp(arg[iarg], "y") == 0) index = 1; - else if (strcmp(arg[iarg], "z") == 0) index = 2; - - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure", error); - if (strcmp(arg[iarg + 1], "final") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure final", error); - set[index].style = FINAL; - set[index].flo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - set[index].fhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "delta") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure delta", error); - set[index].style = DELTA; - set[index].dlo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - set[index].dhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "scale") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure scale", error); - set[index].style = SCALE; - set[index].scale = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "vel") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure vel", error); - set[index].style = VEL; - set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "erate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure erate", error); - set[index].style = ERATE; - set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "trate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure trate", error); - set[index].style = TRATE; - set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "volume") == 0) { - set[index].style = VOLUME; - iarg += 2; - } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure wiggle", error); - set[index].style = WIGGLE; - set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - if (set[index].tperiod <= 0.0) - error->all(FLERR, "Illegal fix deform/pressure wiggle period, must be positive"); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "variable") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure variable", error); - set[index].style = VARIABLE; - if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) - error->all(FLERR, "Illegal fix deform/pressure variable name {}", arg[iarg + 2]); - if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) - error->all(FLERR, "Illegal fix deform/pressure variable name {}", arg[iarg + 3]); - delete[] set[index].hstr; - delete[] set[index].hratestr; - set[index].hstr = utils::strdup(&arg[iarg + 2][2]); - set[index].hratestr = utils::strdup(&arg[iarg + 3][2]); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "pressure") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure", error); - set[index].style = PRESSURE; - if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { - set[index].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - } else { - set[index].pstr = utils::strdup(&arg[iarg + 2][2]); - set[index].pvar_flag = 1; - } - set[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - if (set[index].pgain <= 0.0) - error->all(FLERR, "Illegal fix deform/pressure pressure gain, must be positive"); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "pressure/mean") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure/mean", error); - set[index].style = PMEAN; - if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { - set[index].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - } else { - set[index].pstr = utils::strdup(&arg[iarg + 2][2]); - set[index].pvar_flag = 1; - } - set[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - if (set[index].pgain <= 0.0) - error->all(FLERR, "Illegal fix deform/pressure pressure gain, must be positive"); - iarg += 4; - } else error->all(FLERR, "Illegal fix deform/pressure command argument: {}", arg[iarg + 1]); - - } else if (strcmp(arg[iarg], "xy") == 0 || - strcmp(arg[iarg], "xz") == 0 || - strcmp(arg[iarg], "yz") == 0) { - - if (triclinic == 0) - error->all(FLERR, "fix deform/pressure tilt factors require triclinic box"); - if (strcmp(arg[iarg], "xy") == 0) index = 5; - else if (strcmp(arg[iarg], "xz") == 0) index = 4; - else if (strcmp(arg[iarg], "yz") == 0) index = 3; - - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure", error); - if (strcmp(arg[iarg + 1], "final") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure final", error); - set[index].style = FINAL; - set[index].ftilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "delta") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure delta", error); - set[index].style = DELTA; - set[index].dtilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "vel") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure vel", error); - set[index].style = VEL; - set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "erate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure erate", error); - set[index].style = ERATE; - set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "trate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure trate", error); - set[index].style = TRATE; - set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure wiggle", error); - set[index].style = WIGGLE; - set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - if (set[index].tperiod <= 0.0) - error->all(FLERR, "Illegal fix deform/pressure wiggle period, must be positive"); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "variable") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure variable", error); - set[index].style = VARIABLE; - if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) - error->all(FLERR, "Illegal fix deform/pressure variable name {}", arg[iarg + 2]); - if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) - error->all(FLERR, "Illegal fix deform/pressure variable name {}", arg[iarg + 3]); - delete[] set[index].hstr; - delete[] set[index].hratestr; - set[index].hstr = utils::strdup(&arg[iarg + 2][2]); - set[index].hratestr = utils::strdup(&arg[iarg + 3][2]); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "pressure") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure", error); - set[index].style = PRESSURE; - if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { - set[index].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - } else { - set[index].pstr = utils::strdup(&arg[iarg + 2][2]); - set[index].pvar_flag = 1; - } - set[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - if (set[index].pgain <= 0.0) - error->all(FLERR, "Illegal fix deform/pressure pressure gain, must be positive"); - iarg += 4; - } else error->all(FLERR, "Illegal fix deform/pressure command: {}", arg[iarg + 1]); - } else if (strcmp(arg[iarg], "iso") == 0) { - index = 6; - if (strcmp(arg[iarg + 1], "volume") == 0) { - set[index].style = VOLUME; - iarg += 2; - } else if (strcmp(arg[iarg + 1], "pressure") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure", error); - set[index].style = PRESSURE; - if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) { - set[index].ptarget = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - } else { - set[index].pstr = utils::strdup(&arg[iarg + 2][2]); - set[index].pvar_flag = 1; - } - set[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - if (set[index].pgain <= 0.0) - error->all(FLERR, "Illegal fix deform/pressure pressure gain, must be positive"); - iarg += 4; - } - } else break; - } - - while (iarg < narg) { - if (strcmp(arg[iarg], "remap") == 0) { - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure remap", error); - if (strcmp(arg[iarg + 1], "x") == 0) remapflag = Domain::X_REMAP; - else if (strcmp(arg[iarg + 1], "v") == 0) remapflag = Domain::V_REMAP; - else if (strcmp(arg[iarg + 1], "none") == 0) remapflag = Domain::NO_REMAP; - else error->all(FLERR, "Illegal fix deform/pressure remap command: {}", arg[iarg + 1]); - iarg += 2; - } else if (strcmp(arg[iarg], "units") == 0) { - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure units", error); - if (strcmp(arg[iarg + 1], "box") == 0) scaleflag = 0; - else if (strcmp(arg[iarg + 1], "lattice") == 0) scaleflag = 1; - else error->all(FLERR, "Illegal fix deform/pressure units command: {}", arg[iarg + 1]); - iarg += 2; - } else if (strcmp(arg[iarg], "flip") == 0) { - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure flip", error); - flipflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); - iarg += 2; - } else if (strcmp(arg[iarg], "couple") == 0) { + if (strcmp(arg[iarg], "couple") == 0) { if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure couple", error); if (strcmp(arg[iarg + 1], "xyz") == 0) pcouple = XYZ; else if (strcmp(arg[iarg + 1], "xy") == 0) pcouple = XY; else if (strcmp(arg[iarg + 1], "yz") == 0) pcouple = YZ; else if (strcmp(arg[iarg + 1], "xz") == 0) pcouple = XZ; else if (strcmp(arg[iarg + 1], "none") == 0) pcouple = NOCOUPLE; - else error->all(FLERR, "Illegal fix fix deform/pressure couple command: {}", arg[iarg + 1]); + else error->all(FLERR, "Illegal fix deform/pressure couple command: {}", arg[iarg + 1]); iarg += 2; } else if (strcmp(arg[iarg], "max/rate") == 0) { if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure max/rate", error); @@ -847,10 +860,6 @@ void FixDeformPressure::options(int narg, char **arg) iarg += 2; } else error->all(FLERR, "Illegal fix deform/pressure command: {}", arg[iarg]); } - - if (dimension == 2) - if (pcouple == XYZ || pcouple == XZ || pcouple == YZ) - error->all(FLERR, "Cannot couple Z dimension in fix deform/pressure in 2D"); } /* ---------------------------------------------------------------------- */ diff --git a/src/EXTRA-FIX/fix_deform_pressure.h b/src/EXTRA-FIX/fix_deform_pressure.h index 7e4ad6e35a..41b93f6e98 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.h +++ b/src/EXTRA-FIX/fix_deform_pressure.h @@ -31,6 +31,8 @@ class FixDeformPressure : public FixDeform { void init() override; void setup(int) override; void end_of_step() override; + void write_restart(FILE *) override; + void restart(char *buf) override; int modify_param(int, char **) override; protected: @@ -46,10 +48,22 @@ class FixDeformPressure : public FixDeform { class Compute *temperature, *pressure; int tflag, pflag; + struct SetExtra { + double ptarget, pgain; + double prior_pressure, prior_rate; + double cumulative_strain; + int saved; + char *pstr; + int pvar, pvar_flag; + int coupled_flag; + }; + SetExtra *set_extra; + Set set_box; + void options(int, char **); - void set_pressure(); - void set_volume(); - void set_iso(); + void apply_volume() override; + void apply_pressure(); + void apply_box(); void couple(); void adjust_linked_rates(double&, double&, double, double, double); }; diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index cf45a12f5d..ea68574bf2 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -34,6 +34,8 @@ #include #include +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -56,15 +58,174 @@ irregular(nullptr), set(nullptr) nevery = utils::inumeric(FLERR, arg[3], false, lmp); if (nevery <= 0) error->all(FLERR, "Illegal fix deform command"); + // arguments for child classes + + std::unordered_set child_parameters; + std::unordered_map child_styles; + int nskip; + if (utils::strmatch(style, "pressure$")) { + child_parameters.insert("box"); + child_styles.insert({{"pressure", 4}, {"pressure/mean", 4}, {"volume", 3}}); + } + // set defaults - set = new Set[7]; - memset(set, 0, 7 * sizeof(Set)); + set = new Set[6]; + memset(set, 0, 6 * sizeof(Set)); // parse arguments + int index; + int iarg = 4; + while (iarg < narg) { + if (strcmp(arg[iarg], "x") == 0 || + strcmp(arg[iarg], "y") == 0 || + strcmp(arg[iarg], "z") == 0) { + + if (strcmp(arg[iarg], "x") == 0) index = 0; + else if (strcmp(arg[iarg], "y") == 0) index = 1; + else if (strcmp(arg[iarg], "z") == 0) index = 2; + + if (strcmp(arg[iarg + 1], "final") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); + set[index].style = FINAL; + set[index].flo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].fhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "delta") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); + set[index].style = DELTA; + set[index].dlo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].dhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "scale") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform scale", error); + set[index].style = SCALE; + set[index].scale = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "vel") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); + set[index].style = VEL; + set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "erate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); + set[index].style = ERATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "trate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); + set[index].style = TRATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "volume") == 0) { + set[index].style = VOLUME; + iarg += 2; + } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); + set[index].style = WIGGLE; + set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + if (set[index].tperiod <= 0.0) + error->all(FLERR, "Illegal fix deform wiggle period, must be positive"); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "variable") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); + set[index].style = VARIABLE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) + error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 2]); + if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) + error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 3]); + delete[] set[index].hstr; + delete[] set[index].hratestr; + set[index].hstr = utils::strdup(&arg[iarg + 2][2]); + set[index].hratestr = utils::strdup(&arg[iarg + 3][2]); + iarg += 4; + } else if (child_styles.find(arg[iarg + 1]) != child_styles.end()) { + nskip = child_styles[arg[iarg + 1]]; + if (iarg + nskip > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg + 1]), error); + iarg += nskip; + } error->all(FLERR, "Illegal fix deform command argument: {}", arg[iarg + 1]); + + } else if (strcmp(arg[iarg], "xy") == 0 || + strcmp(arg[iarg], "xz") == 0 || + strcmp(arg[iarg], "yz") == 0) { + + if (strcmp(arg[iarg], "xy") == 0) index = 5; + else if (strcmp(arg[iarg], "xz") == 0) index = 4; + else if (strcmp(arg[iarg], "yz") == 0) index = 3; + + if (strcmp(arg[iarg + 1], "final") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); + set[index].style = FINAL; + set[index].ftilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "delta") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); + set[index].style = DELTA; + set[index].dtilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "vel") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); + set[index].style = VEL; + set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "erate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); + set[index].style = ERATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "trate") == 0) { + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); + set[index].style = TRATE; + set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + iarg += 3; + } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); + set[index].style = WIGGLE; + set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + if (set[index].tperiod <= 0.0) + error->all(FLERR, "Illegal fix deform wiggle period, must be positive"); + iarg += 4; + } else if (strcmp(arg[iarg + 1], "variable") == 0) { + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); + set[index].style = VARIABLE; + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) + error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 2]); + if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) + error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 3]); + delete[] set[index].hstr; + delete[] set[index].hratestr; + set[index].hstr = utils::strdup(&arg[iarg + 2][2]); + set[index].hratestr = utils::strdup(&arg[iarg + 3][2]); + iarg += 4; + } else if (child_styles.find(arg[iarg + 1]) != child_styles.end()) { + nskip = child_styles[arg[iarg + 1]]; + if (iarg + nskip > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg + 1]), error); + iarg += nskip; + } error->all(FLERR, "Illegal fix deform command argument: {}", arg[iarg + 1]); + } else if (child_parameters.find(arg[iarg]) != child_parameters.end()) { + if (child_styles.find(arg[iarg + 1]) != child_styles.end()) { + nskip = child_styles[arg[iarg + 1]]; + if (iarg + nskip > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg + 1]), error); + iarg += nskip; + } error->all(FLERR, "Illegal fix {} command argument: {}", style, arg[iarg + 1]); + } else break; + } + + // reparse all arguments for optional keywords + + options(narg - 4, &arg[4]); + + // check triclinic + triclinic = domain->triclinic; - options(narg, arg); + if (triclinic == 0 && (set[3].style || set[4].style || set[5].style)) + error->all(FLERR, "Fix deform tilt factors require triclinic box"); // no x remap effectively moves atoms within box, so set restart_pbc @@ -76,12 +237,6 @@ irregular(nullptr), set(nullptr) if (set[i].style == NONE) dimflag[i] = 0; else dimflag[i] = 1; - if (set[6].style != NONE) { - dimflag[0] = 1; - dimflag[1] = 1; - dimflag[2] = 1; - } - if (dimflag[0]) box_change |= BOX_CHANGE_X; if (dimflag[1]) box_change |= BOX_CHANGE_Y; if (dimflag[2]) box_change |= BOX_CHANGE_Z; @@ -93,7 +248,7 @@ irregular(nullptr), set(nullptr) // b/c shrink wrap will change box-length for (int i = 0; i < 3; i++) - if ((set[i].style || set[6].style) && (domain->boundary[i][0] >= 2 || domain->boundary[i][1] >= 2)) + if (set[i].style && (domain->boundary[i][0] >= 2 || domain->boundary[i][1] >= 2)) error->all(FLERR, "Cannot use fix deform on a shrink-wrapped boundary"); // no tilt deformation on shrink-wrapped 2nd dim @@ -113,7 +268,7 @@ irregular(nullptr), set(nullptr) if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == VEL || set[i].style == WIGGLE) flag = 1; - double xscale,yscale,zscale; + double xscale, yscale, zscale; if (flag && scaleflag) { xscale = domain->lattice->xlattice; yscale = domain->lattice->ylattice; @@ -187,10 +342,8 @@ irregular(nullptr), set(nullptr) // set varflag varflag = 0; - for (int i = 0; i < 7; i++) { + for (int i = 0; i < 6; i++) if (set[i].style == VARIABLE) varflag = 1; - if (set[i].pvar_flag) varflag = 1; - } // set initial values at time fix deform is issued @@ -202,7 +355,6 @@ irregular(nullptr), set(nullptr) set[3].tilt_initial = domain->yz; set[4].tilt_initial = domain->xz; set[5].tilt_initial = domain->xy; - set[6].vol_initial = domain->xprd * domain->yprd * domain->zprd; // reneighboring only forced if flips can occur due to shape changes @@ -231,10 +383,9 @@ irregular(nullptr), set(nullptr) FixDeform::~FixDeform() { if (set) { - for (int i = 0; i < 7; i++) { + for (int i = 0; i < 6; i++) { delete[] set[i].hstr; delete[] set[i].hratestr; - delete[] set[i].pstr; } } delete[] set; @@ -282,7 +433,7 @@ void FixDeform::init() // check variables for VARIABLE style - for (int i = 0; i < 7; i++) { + for (int i = 0; i < 6; i++) { if (set[i].style != VARIABLE) continue; set[i].hvar = input->variable->find(set[i].hstr); if (set[i].hvar < 0) @@ -403,8 +554,6 @@ void FixDeform::init() } } - set[6].vol_start = domain->xprd * domain->yprd * domain->zprd; - // if using tilt TRATE, then initial tilt must be non-zero for (int i = 3; i < 6; i++) @@ -520,16 +669,16 @@ void FixDeform::end_of_step() // set new box size for strain-based dims - set_strain(); + apply_strain(); // set new box size for VOLUME dims that are linked to other dims // NOTE: still need to set h_rate for these dims - set_volume(); + apply_volume(); if (varflag) modify->addstep_compute(update->ntimestep + nevery); - apply_deformation(); + update_domain(); // redo KSpace coeffs since box has changed @@ -537,10 +686,10 @@ void FixDeform::end_of_step() } /* ---------------------------------------------------------------------- - set box size for strain-based dimensions + apply strain controls ------------------------------------------------------------------------- */ -void FixDeform::set_strain() +void FixDeform::apply_strain() { // for NONE, target is current box size // for TRATE, set target directly based on current time, also set h_rate @@ -620,10 +769,10 @@ void FixDeform::set_strain() } /* ---------------------------------------------------------------------- - set box size for VOLUME dimensions + apply volume controls ------------------------------------------------------------------------- */ -void FixDeform::set_volume() +void FixDeform::apply_volume() { double e1, e2; @@ -657,10 +806,10 @@ void FixDeform::set_volume() } /* ---------------------------------------------------------------------- - Apply calculated deformation + Update box domain ------------------------------------------------------------------------- */ -void FixDeform::apply_deformation() +void FixDeform::update_domain() { // tilt_target can be large positive or large negative value // add/subtract box lengths until tilt_target is closest to current value @@ -766,22 +915,22 @@ void FixDeform::apply_deformation() // reset global and local box to new size/shape // only if deform fix is controlling the dimension - if (set[0].style || set[6].style) { + if (dimflag[0]) { domain->boxlo[0] = set[0].lo_target; domain->boxhi[0] = set[0].hi_target; } - if (set[1].style || set[6].style) { + if (dimflag[1]) { domain->boxlo[1] = set[1].lo_target; domain->boxhi[1] = set[1].hi_target; } - if (set[2].style || set[6].style) { + if (dimflag[2]) { domain->boxlo[2] = set[2].lo_target; domain->boxhi[2] = set[2].hi_target; } if (triclinic) { - if (set[3].style) domain->yz = set[3].tilt_target; - if (set[4].style) domain->xz = set[4].tilt_target; - if (set[5].style) domain->xy = set[5].tilt_target; + if (dimflag[3]) domain->yz = set[3].tilt_target; + if (dimflag[4]) domain->xz = set[4].tilt_target; + if (dimflag[5]) domain->xy = set[5].tilt_target; } domain->set_global_box(); @@ -810,11 +959,11 @@ void FixDeform::apply_deformation() void FixDeform::write_restart(FILE *fp) { if (comm->me == 0) { - int size = 9 * sizeof(double) + 7 * sizeof(Set); + int size = 9 * sizeof(double) + 6 * sizeof(Set); fwrite(&size, sizeof(int), 1, fp); fwrite(h_rate, sizeof(double), 6, fp); fwrite(h_ratelo, sizeof(double), 3, fp); - fwrite(set, sizeof(Set), 7, fp); + fwrite(set, sizeof(Set), 6, fp); } } @@ -833,16 +982,12 @@ void FixDeform::restart(char *buf) int samestyle = 1; Set *set_restart = (Set *) &buf[n * sizeof(double)]; - for (int i = 0; i < 7; ++i) { + for (int i = 0; i < 6; ++i) { // restore data from initial state set[i].lo_initial = set_restart[i].lo_initial; set[i].hi_initial = set_restart[i].hi_initial; set[i].vol_initial = set_restart[i].vol_initial; set[i].tilt_initial = set_restart[i].tilt_initial; - set[i].saved = set_restart[i].saved; - set[i].prior_rate = set_restart[i].prior_rate; - set[i].prior_pressure = set_restart[i].prior_pressure; - set[i].cumulative_strain = set_restart[i].cumulative_strain; // check if style settings are consistent (should do the whole set?) if (set[i].style != set_restart[i].style) samestyle = 0; @@ -863,135 +1008,14 @@ void FixDeform::options(int narg, char **arg) scaleflag = 1; flipflag = 1; - int index; - int iarg = 4; - while (iarg < narg) { - if (strcmp(arg[iarg], "x") == 0 || - strcmp(arg[iarg], "y") == 0 || - strcmp(arg[iarg], "z") == 0) { + // arguments for child classes - if (strcmp(arg[iarg], "x") == 0) index = 0; - else if (strcmp(arg[iarg], "y") == 0) index = 1; - else if (strcmp(arg[iarg], "z") == 0) index = 2; - - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); - if (strcmp(arg[iarg + 1], "final") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); - set[index].style = FINAL; - set[index].flo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - set[index].fhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "delta") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); - set[index].style = DELTA; - set[index].dlo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - set[index].dhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "scale") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform scale", error); - set[index].style = SCALE; - set[index].scale = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "vel") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); - set[index].style = VEL; - set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "erate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); - set[index].style = ERATE; - set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "trate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); - set[index].style = TRATE; - set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "volume") == 0) { - set[index].style = VOLUME; - iarg += 2; - } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); - set[index].style = WIGGLE; - set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - if (set[index].tperiod <= 0.0) - error->all(FLERR, "Illegal fix deform wiggle period, must be positive"); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "variable") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); - set[index].style = VARIABLE; - if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) - error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 2]); - if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) - error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 3]); - delete[] set[index].hstr; - delete[] set[index].hratestr; - set[index].hstr = utils::strdup(&arg[iarg + 2][2]); - set[index].hratestr = utils::strdup(&arg[iarg + 3][2]); - iarg += 4; - } else error->all(FLERR, "Illegal fix deform command argument: {}", arg[iarg + 1]); - - } else if (strcmp(arg[iarg], "xy") == 0 || - strcmp(arg[iarg], "xz") == 0 || - strcmp(arg[iarg], "yz") == 0) { - - if (triclinic == 0) - error->all(FLERR, "Fix deform tilt factors require triclinic box"); - if (strcmp(arg[iarg], "xy") == 0) index = 5; - else if (strcmp(arg[iarg], "xz") == 0) index = 4; - else if (strcmp(arg[iarg], "yz") == 0) index = 3; - - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); - if (strcmp(arg[iarg + 1], "final") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); - set[index].style = FINAL; - set[index].ftilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "delta") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); - set[index].style = DELTA; - set[index].dtilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "vel") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); - set[index].style = VEL; - set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "erate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); - set[index].style = ERATE; - set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "trate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); - set[index].style = TRATE; - set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - iarg += 3; - } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); - set[index].style = WIGGLE; - set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); - set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - if (set[index].tperiod <= 0.0) - error->all(FLERR, "Illegal fix deform wiggle period, must be positive"); - iarg += 4; - } else if (strcmp(arg[iarg + 1], "variable") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); - set[index].style = VARIABLE; - if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) - error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 2]); - if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) - error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 3]); - delete[] set[index].hstr; - delete[] set[index].hratestr; - set[index].hstr = utils::strdup(&arg[iarg + 2][2]); - set[index].hratestr = utils::strdup(&arg[iarg + 3][2]); - iarg += 4; - } else error->all(FLERR, "Illegal fix deform command: {}", arg[iarg + 1]); - } else break; - } + std::unordered_map child_options; + int nskip; + if (utils::strmatch(style, "pressure$")) + child_options.insert({{"couple", 2}, {"max/rate", 2}, {"normalize/pressure", 2}, {"vol/balance/p", 2}}); + int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg], "remap") == 0) { if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform remap", error); @@ -1010,6 +1034,11 @@ void FixDeform::options(int narg, char **arg) if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform flip", error); flipflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; + } else if (child_options.find(arg[iarg]) != child_options.end()) { + nskip = child_options[arg[iarg]]; + if (iarg + nskip > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg]), error); + iarg += nskip; } else error->all(FLERR, "Illegal fix deform command: {}", arg[iarg]); } } diff --git a/src/fix_deform.h b/src/fix_deform.h index 16a563cf4f..69f62fe558 100644 --- a/src/fix_deform.h +++ b/src/fix_deform.h @@ -35,8 +35,8 @@ class FixDeform : public Fix { void init() override; void pre_exchange() override; void end_of_step() override; - void write_restart(FILE *) override; - void restart(char *buf) override; + void virtual write_restart(FILE *) override; + void virtual restart(char *buf) override; double memory_usage() override; protected: @@ -59,22 +59,16 @@ class FixDeform : public Fix { double tilt_initial, tilt_start, tilt_stop, tilt_target, tilt_flip; double tilt_min, tilt_max; double vol_initial, vol_start; - double ptarget, pgain; - double prior_pressure, prior_rate; - double cumulative_strain; - int saved; int fixed, dynamic1, dynamic2; - char *hstr, *hratestr, *pstr; + char *hstr, *hratestr; int hvar, hratevar; - int pvar, pvar_flag; - int coupled_flag; }; Set *set; void options(int, char **); - void set_strain(); - void set_volume(); - void apply_deformation(); + void virtual apply_volume(); + void apply_strain(); + void update_domain(); }; } // namespace LAMMPS_NS From a835c5f3d98be243bd0e5b9f95b382da5f1c0229 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Tue, 30 Jan 2024 15:50:40 -0700 Subject: [PATCH 028/185] Restoring some error message locations, minor edits --- src/EXTRA-FIX/fix_deform_pressure.cpp | 6 ------ src/fix_deform.cpp | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index 7f3a627b66..7fb60e13fb 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -138,12 +138,6 @@ id_temp(nullptr), id_press(nullptr) options(narg - iarg, &arg[iarg]); - // repeat: check triclinic - - dimension = domain->dimension; - if (triclinic == 0 && (set[3].style || set[4].style || set[5].style)) - error->all(FLERR, "Fix deform tilt factors require triclinic box"); - // repeat: setup dimflags used by other classes to check for volume-change conflicts for (int i = 0; i < 6; i++) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index ea68574bf2..94b28a5cd3 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -75,6 +75,8 @@ irregular(nullptr), set(nullptr) // parse arguments + triclinic = domain->triclinic; + int index; int iarg = 4; while (iarg < narg) { @@ -86,6 +88,7 @@ irregular(nullptr), set(nullptr) else if (strcmp(arg[iarg], "y") == 0) index = 1; else if (strcmp(arg[iarg], "z") == 0) index = 2; + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); if (strcmp(arg[iarg + 1], "final") == 0) { if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); set[index].style = FINAL; @@ -152,10 +155,14 @@ irregular(nullptr), set(nullptr) strcmp(arg[iarg], "xz") == 0 || strcmp(arg[iarg], "yz") == 0) { + + if (triclinic == 0) + error->all(FLERR,"Fix deform tilt factors require triclinic box"); if (strcmp(arg[iarg], "xy") == 0) index = 5; else if (strcmp(arg[iarg], "xz") == 0) index = 4; else if (strcmp(arg[iarg], "yz") == 0) index = 3; + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); if (strcmp(arg[iarg + 1], "final") == 0) { if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); set[index].style = FINAL; @@ -217,15 +224,9 @@ irregular(nullptr), set(nullptr) } else break; } - // reparse all arguments for optional keywords + // read options from end of input line - options(narg - 4, &arg[4]); - - // check triclinic - - triclinic = domain->triclinic; - if (triclinic == 0 && (set[3].style || set[4].style || set[5].style)) - error->all(FLERR, "Fix deform tilt factors require triclinic box"); + options(narg - iarg, &arg[iarg]); // no x remap effectively moves atoms within box, so set restart_pbc @@ -787,7 +788,7 @@ void FixDeform::apply_volume() if (set[i].substyle == ONE_FROM_ONE) { shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / - (set[fixed].hi_start-set[fixed].lo_start)); + (set[fixed].hi_start - set[fixed].lo_start)); } else if (set[i].substyle == ONE_FROM_TWO) { shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / (set[dynamic2].hi_target - set[dynamic2].lo_target)); From 103dc9ef668153a9494593c5952278358a7c1669 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Jan 2024 19:21:48 -0500 Subject: [PATCH 029/185] fix missing "else" bug --- src/fix_deform.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 94b28a5cd3..8e9b489979 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -149,7 +149,7 @@ irregular(nullptr), set(nullptr) if (iarg + nskip > narg) utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg + 1]), error); iarg += nskip; - } error->all(FLERR, "Illegal fix deform command argument: {}", arg[iarg + 1]); + } else error->all(FLERR, "Illegal fix deform command argument: {}", arg[iarg + 1]); } else if (strcmp(arg[iarg], "xy") == 0 || strcmp(arg[iarg], "xz") == 0 || @@ -213,7 +213,7 @@ irregular(nullptr), set(nullptr) if (iarg + nskip > narg) utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg + 1]), error); iarg += nskip; - } error->all(FLERR, "Illegal fix deform command argument: {}", arg[iarg + 1]); + } else error->all(FLERR, "Illegal fix deform command argument: {}", arg[iarg + 1]); } else if (child_parameters.find(arg[iarg]) != child_parameters.end()) { if (child_styles.find(arg[iarg + 1]) != child_styles.end()) { nskip = child_styles[arg[iarg + 1]]; From 9d46408fa41c0122b77e9140d77e23ca05812161 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Jan 2024 19:23:40 -0500 Subject: [PATCH 030/185] delete unused variables --- src/fix_deform.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 8e9b489979..cf4a1242c0 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -741,8 +741,6 @@ void FixDeform::apply_strain() // for other styles, target is linear value between start and stop values if (triclinic) { - double *h = domain->h; - for (int i = 3; i < 6; i++) { if (set[i].style == NONE) { if (i == 5) set[i].tilt_target = domain->xy; @@ -775,8 +773,6 @@ void FixDeform::apply_strain() void FixDeform::apply_volume() { - double e1, e2; - for (int i = 0; i < 3; i++) { if (set[i].style != VOLUME) continue; From 840577114ee1255ce091d5b50e8cf10af66fce72 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Jan 2024 19:38:58 -0500 Subject: [PATCH 031/185] force enumerators to be consistent by moving them to base class declaration --- src/EXTRA-FIX/fix_deform_pressure.cpp | 4 +--- src/fix_deform.cpp | 3 --- src/fix_deform.h | 3 +++ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index 7fb60e13fb..a1eab08470 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -41,9 +41,7 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{NONE=0,FINAL,DELTA,SCALE,VEL,ERATE,TRATE,VOLUME,WIGGLE,VARIABLE,PRESSURE,PMEAN}; -enum{ONE_FROM_ONE,ONE_FROM_TWO,TWO_FROM_ONE}; -enum{NOCOUPLE=0,XYZ,XY,YZ,XZ}; +enum{ NOCOUPLE=0, XYZ, XY, YZ, XZ }; /* ---------------------------------------------------------------------- */ diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index cf4a1242c0..7f9ec14c5d 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -41,9 +41,6 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{NONE=0,FINAL,DELTA,SCALE,VEL,ERATE,TRATE,VOLUME,WIGGLE,VARIABLE}; -enum{ONE_FROM_ONE,ONE_FROM_TWO,TWO_FROM_ONE}; - /* ---------------------------------------------------------------------- */ FixDeform::FixDeform(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), diff --git a/src/fix_deform.h b/src/fix_deform.h index 69f62fe558..fa92b851e6 100644 --- a/src/fix_deform.h +++ b/src/fix_deform.h @@ -29,6 +29,9 @@ class FixDeform : public Fix { int remapflag; // whether x,v are remapped across PBC int dimflag[6]; // which dims are deformed + enum { NONE, FINAL, DELTA, SCALE, VEL, ERATE, TRATE, VOLUME, WIGGLE, VARIABLE, PRESSURE, PMEAN }; + enum { ONE_FROM_ONE, ONE_FROM_TWO, TWO_FROM_ONE }; + FixDeform(class LAMMPS *, int, char **); ~FixDeform() override; int setmask() override; From bff789aac9bcaa4e607d8f334c393814c2c8f62e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Jan 2024 20:03:26 -0500 Subject: [PATCH 032/185] silence compiler warnings and update format --- src/EXTRA-FIX/fix_deform_pressure.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index a1eab08470..9fb85843a2 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -41,12 +41,12 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{ NOCOUPLE=0, XYZ, XY, YZ, XZ }; +enum { NOCOUPLE = 0, XYZ, XY, YZ, XZ }; /* ---------------------------------------------------------------------- */ -FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : FixDeform(lmp, narg, arg), -id_temp(nullptr), id_press(nullptr) +FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : + FixDeform(lmp, narg, arg), id_temp(nullptr), id_press(nullptr) { // set defaults @@ -198,8 +198,6 @@ id_temp(nullptr), id_press(nullptr) int coupled_indices[3] = {0}; int j = -1; - double couple_gain, coupled_pressure; - char *couple_str; if (pcouple == XYZ || pcouple == XY || pcouple == XZ) coupled_indices[0] = 1; @@ -626,14 +624,14 @@ void FixDeformPressure::apply_volume() e2 = (Vi - V * (1 + e1 * dt)) / (V * (1 + e1 * dt) * dt); // If strain rate exceeds limit in either dimension, cap it at the maximum compatible rate - if (max_h_rate != 0) - if (fabs(e1) > max_h_rate || fabs(e2) > max_h_rate) + if (max_h_rate != 0) { + if ((fabs(e1) > max_h_rate) || (fabs(e2) > max_h_rate)) { if (fabs(e1) > fabs(e2)) adjust_linked_rates(e1, e2, e3, Vi, V); else adjust_linked_rates(e2, e1, e3, Vi, V); - - + } + } shift = 0.5 * L1i * (1.0 + e1 * dt); linked_pressure = 1; } else { From e649c0e0704b2f899238332639e49582cbbd82f5 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Jan 2024 20:04:07 -0500 Subject: [PATCH 033/185] consistent error messages for parent and child class --- src/EXTRA-FIX/fix_deform_pressure.cpp | 10 +-- src/fix_deform.cpp | 125 +++++++++++++------------- 2 files changed, 70 insertions(+), 65 deletions(-) diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index 9fb85843a2..91a0591cd2 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -160,17 +160,17 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : for (int i = 0; i < 3; i++) if (set_box.style && (domain->boundary[i][0] >= 2 || domain->boundary[i][1] >= 2)) - error->all(FLERR, "Cannot use fix deform on a shrink-wrapped boundary"); + error->all(FLERR, "Cannot use fix deform/pressure on a shrink-wrapped boundary"); // repeat: no tilt deformation on shrink-wrapped 2nd dim // b/c shrink wrap will change tilt factor in domain::reset_box() if (set[3].style && (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) - error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + error->all(FLERR, "Cannot use fix deform/pressure tilt on a shrink-wrapped 2nd dim"); if (set[4].style && (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) - error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + error->all(FLERR, "Cannot use fix deform/pressure tilt on a shrink-wrapped 2nd dim"); if (set[5].style && (domain->boundary[1][0] >= 2 || domain->boundary[1][1] >= 2)) - error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + error->all(FLERR, "Cannot use fix deform/pressure tilt on a shrink-wrapped 2nd dim"); // repeat: set varflag @@ -184,7 +184,7 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : irregular = new Irregular(lmp); } - // set initial values at time fix deform is issued + // set initial values at time fix deform/pressure is issued set_box.vol_initial = domain->xprd * domain->yprd * domain->zprd; diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 7f9ec14c5d..9c6bfb9d8b 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -46,21 +46,22 @@ using namespace MathConst; FixDeform::FixDeform(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), irregular(nullptr), set(nullptr) { - if (narg < 4) error->all(FLERR, "Illegal fix deform command"); + const std::string thiscmd = fmt::format("fix {}", style); + if (narg < 4) utils::missing_cmd_args(FLERR, thiscmd, error); no_change_box = 1; restart_global = 1; pre_exchange_migrate = 1; nevery = utils::inumeric(FLERR, arg[3], false, lmp); - if (nevery <= 0) error->all(FLERR, "Illegal fix deform command"); + if (nevery <= 0) error->all(FLERR, "Fix {} Nevery must be > 0", style); // arguments for child classes std::unordered_set child_parameters; std::unordered_map child_styles; int nskip; - if (utils::strmatch(style, "pressure$")) { + if (utils::strmatch(style, "^deform/pressure")) { child_parameters.insert("box"); child_styles.insert({{"pressure", 4}, {"pressure/mean", 4}, {"volume", 3}}); } @@ -76,45 +77,46 @@ irregular(nullptr), set(nullptr) int index; int iarg = 4; + while (iarg < narg) { - if (strcmp(arg[iarg], "x") == 0 || - strcmp(arg[iarg], "y") == 0 || - strcmp(arg[iarg], "z") == 0) { + if ((strcmp(arg[iarg], "x") == 0) + || (strcmp(arg[iarg], "y") == 0) + || (strcmp(arg[iarg], "z") == 0)) { if (strcmp(arg[iarg], "x") == 0) index = 0; else if (strcmp(arg[iarg], "y") == 0) index = 1; else if (strcmp(arg[iarg], "z") == 0) index = 2; - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, thiscmd, error); if (strcmp(arg[iarg + 1], "final") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, thiscmd + " final", error); set[index].style = FINAL; set[index].flo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); set[index].fhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; } else if (strcmp(arg[iarg + 1], "delta") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, thiscmd + " delta", error); set[index].style = DELTA; set[index].dlo = utils::numeric(FLERR, arg[iarg + 2], false, lmp); set[index].dhi = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; } else if (strcmp(arg[iarg + 1], "scale") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform scale", error); + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, thiscmd + " scale", error); set[index].style = SCALE; set[index].scale = utils::numeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; } else if (strcmp(arg[iarg + 1], "vel") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, thiscmd + " vel", error); set[index].style = VEL; set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; } else if (strcmp(arg[iarg + 1], "erate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, thiscmd + " erate", error); set[index].style = ERATE; set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; } else if (strcmp(arg[iarg + 1], "trate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, thiscmd + " trate", error); set[index].style = TRATE; set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; @@ -122,20 +124,20 @@ irregular(nullptr), set(nullptr) set[index].style = VOLUME; iarg += 2; } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, thiscmd + " wiggle", error); set[index].style = WIGGLE; set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); if (set[index].tperiod <= 0.0) - error->all(FLERR, "Illegal fix deform wiggle period, must be positive"); + error->all(FLERR, "Illegal fix {} wiggle period, must be positive", style); iarg += 4; } else if (strcmp(arg[iarg + 1], "variable") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, thiscmd + " variable", error); set[index].style = VARIABLE; if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) - error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 2]); + error->all(FLERR, "Illegal fix {} variable name {}", style, arg[iarg + 2]); if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) - error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 3]); + error->all(FLERR, "Illegal fix {} variable name {}", style, arg[iarg + 3]); delete[] set[index].hstr; delete[] set[index].hratestr; set[index].hstr = utils::strdup(&arg[iarg + 2][2]); @@ -146,60 +148,58 @@ irregular(nullptr), set(nullptr) if (iarg + nskip > narg) utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg + 1]), error); iarg += nskip; - } else error->all(FLERR, "Illegal fix deform command argument: {}", arg[iarg + 1]); + } else error->all(FLERR, "Illegal fix {} command argument: {}", style, arg[iarg + 1]); - } else if (strcmp(arg[iarg], "xy") == 0 || - strcmp(arg[iarg], "xz") == 0 || - strcmp(arg[iarg], "yz") == 0) { + } else if ((strcmp(arg[iarg], "xy") == 0) + || (strcmp(arg[iarg], "xz") == 0) + || (strcmp(arg[iarg], "yz") == 0)) { - - if (triclinic == 0) - error->all(FLERR,"Fix deform tilt factors require triclinic box"); + if (triclinic == 0) error->all(FLERR,"Fix {} tilt factors require triclinic box", style); if (strcmp(arg[iarg], "xy") == 0) index = 5; else if (strcmp(arg[iarg], "xz") == 0) index = 4; else if (strcmp(arg[iarg], "yz") == 0) index = 3; - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform", error); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, thiscmd, error); if (strcmp(arg[iarg + 1], "final") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform final", error); + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, thiscmd + " final", error); set[index].style = FINAL; set[index].ftilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; } else if (strcmp(arg[iarg + 1], "delta") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform delta", error); + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, thiscmd + " delta", error); set[index].style = DELTA; set[index].dtilt = utils::numeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; } else if (strcmp(arg[iarg + 1], "vel") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform vel", error); + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, thiscmd + " vel", error); set[index].style = VEL; set[index].vel = utils::numeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; } else if (strcmp(arg[iarg + 1], "erate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform erate", error); + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, thiscmd + " erate", error); set[index].style = ERATE; set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; } else if (strcmp(arg[iarg + 1], "trate") == 0) { - if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "fix deform trate", error); + if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, thiscmd + " trate", error); set[index].style = TRATE; set[index].rate = utils::numeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; } else if (strcmp(arg[iarg + 1], "wiggle") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform wiggle", error); + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, thiscmd + " wiggle", error); set[index].style = WIGGLE; set[index].amplitude = utils::numeric(FLERR, arg[iarg + 2], false, lmp); set[index].tperiod = utils::numeric(FLERR, arg[iarg + 3], false, lmp); if (set[index].tperiod <= 0.0) - error->all(FLERR, "Illegal fix deform wiggle period, must be positive"); + error->all(FLERR, "Illegal fix {} wiggle period, must be positive", style); iarg += 4; } else if (strcmp(arg[iarg + 1], "variable") == 0) { - if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform variable", error); + if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, thiscmd + " variable", error); set[index].style = VARIABLE; if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) - error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 2]); + error->all(FLERR, "Illegal fix {} variable name {}", style, arg[iarg + 2]); if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) - error->all(FLERR, "Illegal fix deform variable name {}", arg[iarg + 3]); + error->all(FLERR, "Illegal fix {} variable name {}", style, arg[iarg + 3]); delete[] set[index].hstr; delete[] set[index].hratestr; set[index].hstr = utils::strdup(&arg[iarg + 2][2]); @@ -210,7 +210,7 @@ irregular(nullptr), set(nullptr) if (iarg + nskip > narg) utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg + 1]), error); iarg += nskip; - } else error->all(FLERR, "Illegal fix deform command argument: {}", arg[iarg + 1]); + } else error->all(FLERR, "Illegal fix {} command argument: {}", style, arg[iarg + 1]); } else if (child_parameters.find(arg[iarg]) != child_parameters.end()) { if (child_styles.find(arg[iarg + 1]) != child_styles.end()) { nskip = child_styles[arg[iarg + 1]]; @@ -247,17 +247,17 @@ irregular(nullptr), set(nullptr) for (int i = 0; i < 3; i++) if (set[i].style && (domain->boundary[i][0] >= 2 || domain->boundary[i][1] >= 2)) - error->all(FLERR, "Cannot use fix deform on a shrink-wrapped boundary"); + error->all(FLERR, "Cannot use fix {} on a shrink-wrapped boundary", style); // no tilt deformation on shrink-wrapped 2nd dim // b/c shrink wrap will change tilt factor in domain::reset_box() if (set[3].style && (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) - error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + error->all(FLERR, "Cannot use fix {} tilt on a shrink-wrapped 2nd dim", style); if (set[4].style && (domain->boundary[2][0] >= 2 || domain->boundary[2][1] >= 2)) - error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + error->all(FLERR, "Cannot use fix {} tilt on a shrink-wrapped 2nd dim", style); if (set[5].style && (domain->boundary[1][0] >= 2 || domain->boundary[1][1] >= 2)) - error->all(FLERR, "Cannot use fix deform tilt on a shrink-wrapped 2nd dim"); + error->all(FLERR, "Cannot use fix {} tilt on a shrink-wrapped 2nd dim", style); // apply scaling to FINAL,DELTA,VEL,WIGGLE since they have dist/vel units @@ -312,7 +312,7 @@ irregular(nullptr), set(nullptr) // Cannot use VOLUME option without at least one deformed dimension if (set[other1].style == NONE || set[other1].style == VOLUME) if (set[other2].style == NONE || set[other2].style == VOLUME) - error->all(FLERR, "Fix deform volume setting is invalid"); + error->all(FLERR, "Fix {} volume setting is invalid", style); if (set[other1].style == NONE) { set[i].substyle = ONE_FROM_ONE; @@ -435,14 +435,14 @@ void FixDeform::init() if (set[i].style != VARIABLE) continue; set[i].hvar = input->variable->find(set[i].hstr); if (set[i].hvar < 0) - error->all(FLERR, "Variable name {} for fix deform does not exist", set[i].hstr); + error->all(FLERR, "Variable name {} for fix {} does not exist", set[i].hstr, style); if (!input->variable->equalstyle(set[i].hvar)) - error->all(FLERR, "Variable {} for fix deform is invalid style", set[i].hstr); + error->all(FLERR, "Variable {} for fix {} is invalid style", set[i].hstr, style); set[i].hratevar = input->variable->find(set[i].hratestr); if (set[i].hratevar < 0) - error->all(FLERR, "Variable name {} for fix deform does not exist", set[i].hratestr); + error->all(FLERR, "Variable name {} for fix {} does not exist", set[i].hratestr, style); if (!input->variable->equalstyle(set[i].hratevar)) - error->all(FLERR, "Variable {} for fix deform is invalid style", set[i].hratestr); + error->all(FLERR, "Variable {} for fix {} is invalid style", set[i].hratestr, style); } // set start/stop values for box size and shape @@ -480,7 +480,7 @@ void FixDeform::init() set[i].lo_stop = set[i].lo_start - shift; set[i].hi_stop = set[i].hi_start + shift; if (set[i].hi_stop <= set[i].lo_stop) - error->all(FLERR, "Final box dimension due to fix deform is < 0.0"); + error->all(FLERR, "Final box dimension due to fix {} is < 0.0", style); } else if (set[i].style == TRATE) { double shift = 0.5 * ((set[i].hi_start - set[i].lo_start) * exp(set[i].rate * delt)); set[i].lo_stop = 0.5 * (set[i].lo_start + set[i].hi_start) - shift; @@ -556,7 +556,7 @@ void FixDeform::init() for (int i = 3; i < 6; i++) if (set[i].style == TRATE && set[i].tilt_start == 0.0) - error->all(FLERR, "Cannot use fix deform trate on a box with zero tilt"); + error->all(FLERR, "Cannot use fix {} trate on a box with zero tilt", style); // if yz changes and will cause box flip, then xy cannot be changing // yz = [3], xy = [5] @@ -571,7 +571,7 @@ void FixDeform::init() int flag = 0; double lo,hi; if (flipflag && set[3].style == VARIABLE) - error->all(FLERR, "Fix deform cannot use yz variable with xy"); + error->all(FLERR, "Fix {} cannot use yz variable with xy", style); if (set[3].style == WIGGLE) { lo = set[3].tilt_min; hi = set[3].tilt_max; @@ -584,7 +584,7 @@ void FixDeform::init() hi / (set[1].hi_stop - set[1].lo_stop) > 0.5) flag = 1; } if (flag) - error->all(FLERR, "Fix deform is changing yz too much with xy"); + error->all(FLERR, "Fix {} is changing yz too much with xy", style); } } @@ -989,14 +989,15 @@ void FixDeform::restart(char *buf) samestyle = 0; } if (!samestyle) - error->all(FLERR, "Fix deform settings not consistent with restart"); + error->all(FLERR, "Fix {} settings not consistent with restart", style); } /* ---------------------------------------------------------------------- */ void FixDeform::options(int narg, char **arg) { - if (narg < 0) error->all(FLERR, "Illegal fix deform command"); + const std::string thiscmd = fmt::format("fix {}", style); + if (narg < 0) utils::missing_cmd_args(FLERR, thiscmd, error); remapflag = Domain::X_REMAP; scaleflag = 1; @@ -1006,26 +1007,30 @@ void FixDeform::options(int narg, char **arg) std::unordered_map child_options; int nskip; - if (utils::strmatch(style, "pressure$")) - child_options.insert({{"couple", 2}, {"max/rate", 2}, {"normalize/pressure", 2}, {"vol/balance/p", 2}}); + if (utils::strmatch(style, "^deform/pressure")) { + child_options.insert({{"couple", 2}, + {"max/rate", 2}, + {"normalize/pressure", 2}, + {"vol/balance/p", 2}}); + } int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg], "remap") == 0) { - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform remap", error); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, thiscmd + " remap", error); if (strcmp(arg[iarg + 1], "x") == 0) remapflag = Domain::X_REMAP; else if (strcmp(arg[iarg + 1], "v") == 0) remapflag = Domain::V_REMAP; else if (strcmp(arg[iarg + 1], "none") == 0) remapflag = Domain::NO_REMAP; - else error->all(FLERR, "Illegal fix deform remap command: {}", arg[iarg + 1]); + else error->all(FLERR, "Illegal fix {} remap command: {}", style, arg[iarg + 1]); iarg += 2; } else if (strcmp(arg[iarg], "units") == 0) { - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform units", error); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, thiscmd + " units", error); if (strcmp(arg[iarg + 1], "box") == 0) scaleflag = 0; else if (strcmp(arg[iarg + 1], "lattice") == 0) scaleflag = 1; - else error->all(FLERR, "Illegal fix deform units command: {}", arg[iarg + 1]); + else error->all(FLERR, "Illegal fix {} units command: {}", style, arg[iarg + 1]); iarg += 2; } else if (strcmp(arg[iarg], "flip") == 0) { - if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform flip", error); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, thiscmd + " flip", error); flipflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (child_options.find(arg[iarg]) != child_options.end()) { @@ -1033,7 +1038,7 @@ void FixDeform::options(int narg, char **arg) if (iarg + nskip > narg) utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg]), error); iarg += nskip; - } else error->all(FLERR, "Illegal fix deform command: {}", arg[iarg]); + } else error->all(FLERR, "Unknown fix {} keyword: {}", style, arg[iarg]); } } From 5b6c0c6b56859c337ba5652f1c5b3494289d6c81 Mon Sep 17 00:00:00 2001 From: Ludwig Ahrens Date: Wed, 31 Jan 2024 15:42:10 +0100 Subject: [PATCH 034/185] Check eta property for fix electrode uses ghost on --- src/ELECTRODE/fix_electrode_conp.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ELECTRODE/fix_electrode_conp.cpp b/src/ELECTRODE/fix_electrode_conp.cpp index b966188d07..247e639ae8 100644 --- a/src/ELECTRODE/fix_electrode_conp.cpp +++ b/src/ELECTRODE/fix_electrode_conp.cpp @@ -215,18 +215,16 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : } else if ((strcmp(arg[iarg], "eta") == 0)) { if (iarg + 2 > narg) error->all(FLERR, "Need two arguments after eta command"); etaflag = true; - int is_double, cols; - eta_index = atom->find_custom(arg[++iarg] + 2, is_double, cols); + int is_double, cols, ghost; + eta_index = atom->find_custom_ghost(arg[++iarg] + 2, is_double, cols, ghost); if (eta_index == -1) error->all(FLERR, "eta keyword requires name of previously defined property"); if (!is_double) error->all(FLERR, "eta keyword requires double-valued property/atom vector"); if (cols != 0) error->all(FLERR, "eta keyword requires property/atom vector not an array"); - if (!atom->nextra_border) - error->all(FLERR, - "There is no fix with ghost on, but the eta keyword requires a property/atom " - "fix with ghost on"); - // toggle parameters - } else if ((strcmp(arg[iarg], "etypes") == 0)) { + if (!ghost) error->all(FLERR, "eta keyword requires property/atom fix with ghost on"); + } + // toggle parameters + else if ((strcmp(arg[iarg], "etypes") == 0)) { etypes_neighlists = utils::logical(FLERR, arg[++iarg], false, lmp); } else if ((strncmp(arg[iarg], "symm", 4) == 0)) { symm = utils::logical(FLERR, arg[++iarg], false, lmp); From 1afb9e9dcb0fe6cff7ea2d226ea4020a179857b2 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Fri, 2 Feb 2024 17:10:35 -0700 Subject: [PATCH 035/185] Revamping arg parsing in child class, updates to doc pages --- src/EXTRA-FIX/fix_deform_pressure.cpp | 76 ++++++++++++++++++++------- src/EXTRA-FIX/fix_deform_pressure.h | 2 +- src/fix_deform.cpp | 65 +++++++++++++---------- src/fix_deform.h | 3 ++ 4 files changed, 99 insertions(+), 47 deletions(-) diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index 91a0591cd2..26dd85b78b 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -36,6 +36,7 @@ #include #include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -56,9 +57,10 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : // parse child-specific arguments - int index; - int iarg = 4; - while (iarg < narg) { + int index, iarg; + int i = 0; + while (i < leftover_iarg.size()) { + iarg = leftover_iarg[i]; if (strcmp(arg[iarg], "x") == 0 || strcmp(arg[iarg], "y") == 0 || strcmp(arg[iarg], "z") == 0) { @@ -78,7 +80,7 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : set_extra[index].pvar_flag = 1; } set_extra[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - iarg += 4; + i += 4; } else if (strcmp(arg[iarg + 1], "pressure/mean") == 0) { if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure/mean", error); set[index].style = PMEAN; @@ -89,7 +91,7 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : set_extra[index].pvar_flag = 1; } set_extra[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - iarg += 4; + i += 4; } else error->all(FLERR, "Illegal fix deform/pressure command argument: {}", arg[iarg + 1]); } else if (strcmp(arg[iarg], "xy") == 0 || @@ -111,12 +113,12 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : set_extra[index].pvar_flag = 1; } set_extra[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - iarg += 4; + i += 4; } else error->all(FLERR, "Illegal fix deform/pressure command: {}", arg[iarg + 1]); } else if (strcmp(arg[iarg], "box") == 0) { if (strcmp(arg[iarg + 1], "volume") == 0) { set_box.style = VOLUME; - iarg += 2; + i += 2; } else if (strcmp(arg[iarg + 1], "pressure") == 0) { if (iarg + 4 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure pressure", error); set_box.style = PRESSURE; @@ -127,14 +129,16 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : set_extra[6].pvar_flag = 1; } set_extra[6].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - iarg += 4; + i += 4; } else error->all(FLERR, "Illegal fix deform/pressure command argument: {}", arg[iarg + 1]); } else break; } // read options from end of input line + // shift arguments before reading - options(narg - iarg, &arg[iarg]); + iarg = iarg_options_start; + options(i, narg - iarg, &arg[iarg]); // repeat: setup dimflags used by other classes to check for volume-change conflicts @@ -172,6 +176,42 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : if (set[5].style && (domain->boundary[1][0] >= 2 || domain->boundary[1][1] >= 2)) error->all(FLERR, "Cannot use fix deform/pressure tilt on a shrink-wrapped 2nd dim"); + // for VOLUME, setup links to other dims + // fixed, dynamic1, dynamic2 + + for (int i = 0; i < 3; i++) { + if (set[i].style != VOLUME) continue; + int other1 = (i + 1) % 3; + int other2 = (i + 2) % 3; + + // Cannot use VOLUME option without at least one deformed dimension + if (set[other1].style == NONE || set[other1].style == VOLUME) + if (set[other2].style == NONE || set[other2].style == VOLUME) + error->all(FLERR, "Fix {} volume setting is invalid", style); + + if (set[other1].style == NONE) { + set[i].substyle = ONE_FROM_ONE; + set[i].fixed = other1; + set[i].dynamic1 = other2; + } else if (set[other2].style == NONE) { + set[i].substyle = ONE_FROM_ONE; + set[i].fixed = other2; + set[i].dynamic1 = other1; + } else if (set[other1].style == VOLUME) { + set[i].substyle = TWO_FROM_ONE; + set[i].fixed = other1; + set[i].dynamic1 = other2; + } else if (set[other2].style == VOLUME) { + set[i].substyle = TWO_FROM_ONE; + set[i].fixed = other2; + set[i].dynamic1 = other1; + } else { + set[i].substyle = ONE_FROM_TWO; + set[i].dynamic1 = other1; + set[i].dynamic2 = other2; + } + } + // repeat: set varflag for (int i = 0; i < 7; i++) @@ -221,6 +261,7 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR, "Must specify deformation style for at least one coupled dimension"); // Copy or compare data for each coupled dimension + for (int i = 0; i < 3; i++) { if (coupled_indices[i]) { // Copy coupling information if dimension style is undefined @@ -814,17 +855,16 @@ void FixDeformPressure::restart(char *buf) /* ---------------------------------------------------------------------- */ -void FixDeformPressure::options(int narg, char **arg) +void FixDeformPressure::options(int i, int narg, char **arg) { - if (narg < 0) error->all(FLERR, "Illegal fix deform/pressure command"); - pcouple = NOCOUPLE; max_h_rate = 0.0; vol_balance_flag = 0; normalize_pressure_flag = 0; - int iarg = 0; - while (iarg < narg) { + int iarg, nskip; + while (i < leftover_iarg.size()) { + iarg = leftover_iarg[i]; if (strcmp(arg[iarg], "couple") == 0) { if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure couple", error); if (strcmp(arg[iarg + 1], "xyz") == 0) pcouple = XYZ; @@ -833,21 +873,21 @@ void FixDeformPressure::options(int narg, char **arg) else if (strcmp(arg[iarg + 1], "xz") == 0) pcouple = XZ; else if (strcmp(arg[iarg + 1], "none") == 0) pcouple = NOCOUPLE; else error->all(FLERR, "Illegal fix deform/pressure couple command: {}", arg[iarg + 1]); - iarg += 2; + i += 2; } else if (strcmp(arg[iarg], "max/rate") == 0) { if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure max/rate", error); max_h_rate = utils::numeric(FLERR, arg[iarg + 1], false, lmp); if (max_h_rate <= 0.0) error->all(FLERR, "Maximum strain rate must be a positive, non-zero value"); - iarg += 2; + i += 2; } else if (strcmp(arg[iarg], "normalize/pressure") == 0) { if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure normalize/pressure", error); normalize_pressure_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp); - iarg += 2; + i += 2; } else if (strcmp(arg[iarg], "vol/balance/p") == 0) { if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure vol/balance/p", error); vol_balance_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp); - iarg += 2; + i += 2; } else error->all(FLERR, "Illegal fix deform/pressure command: {}", arg[iarg]); } } diff --git a/src/EXTRA-FIX/fix_deform_pressure.h b/src/EXTRA-FIX/fix_deform_pressure.h index 41b93f6e98..a52bb01c04 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.h +++ b/src/EXTRA-FIX/fix_deform_pressure.h @@ -60,7 +60,7 @@ class FixDeformPressure : public FixDeform { SetExtra *set_extra; Set set_box; - void options(int, char **); + void options(int, int, char **); void apply_volume() override; void apply_pressure(); void apply_box(); diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 9c6bfb9d8b..010250ed92 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -36,6 +36,7 @@ #include #include #include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -147,6 +148,7 @@ irregular(nullptr), set(nullptr) nskip = child_styles[arg[iarg + 1]]; if (iarg + nskip > narg) utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg + 1]), error); + for (int i = 0; i < nskip; i++) leftover_iarg.push_back(iarg + i); iarg += nskip; } else error->all(FLERR, "Illegal fix {} command argument: {}", style, arg[iarg + 1]); @@ -209,6 +211,7 @@ irregular(nullptr), set(nullptr) nskip = child_styles[arg[iarg + 1]]; if (iarg + nskip > narg) utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg + 1]), error); + for (int i = 0; i < nskip; i++) leftover_iarg.push_back(iarg + i); iarg += nskip; } else error->all(FLERR, "Illegal fix {} command argument: {}", style, arg[iarg + 1]); } else if (child_parameters.find(arg[iarg]) != child_parameters.end()) { @@ -216,6 +219,7 @@ irregular(nullptr), set(nullptr) nskip = child_styles[arg[iarg + 1]]; if (iarg + nskip > narg) utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg + 1]), error); + for (int i = 0; i < nskip; i++) leftover_iarg.push_back(iarg + i); iarg += nskip; } error->all(FLERR, "Illegal fix {} command argument: {}", style, arg[iarg + 1]); } else break; @@ -223,6 +227,7 @@ irregular(nullptr), set(nullptr) // read options from end of input line + iarg_options_start = iarg; options(narg - iarg, &arg[iarg]); // no x remap effectively moves atoms within box, so set restart_pbc @@ -303,37 +308,40 @@ irregular(nullptr), set(nullptr) // for VOLUME, setup links to other dims // fixed, dynamic1, dynamic2 + // only check for parent, otherwise child will check - for (int i = 0; i < 3; i++) { - if (set[i].style != VOLUME) continue; - int other1 = (i + 1) % 3; - int other2 = (i + 2) % 3; + if (strcmp(style, "deform") == 0) { + for (int i = 0; i < 3; i++) { + if (set[i].style != VOLUME) continue; + int other1 = (i + 1) % 3; + int other2 = (i + 2) % 3; - // Cannot use VOLUME option without at least one deformed dimension - if (set[other1].style == NONE || set[other1].style == VOLUME) - if (set[other2].style == NONE || set[other2].style == VOLUME) - error->all(FLERR, "Fix {} volume setting is invalid", style); + // Cannot use VOLUME option without at least one deformed dimension + if (set[other1].style == NONE || set[other1].style == VOLUME) + if (set[other2].style == NONE || set[other2].style == VOLUME) + error->all(FLERR, "Fix {} volume setting is invalid", style); - if (set[other1].style == NONE) { - set[i].substyle = ONE_FROM_ONE; - set[i].fixed = other1; - set[i].dynamic1 = other2; - } else if (set[other2].style == NONE) { - set[i].substyle = ONE_FROM_ONE; - set[i].fixed = other2; - set[i].dynamic1 = other1; - } else if (set[other1].style == VOLUME) { - set[i].substyle = TWO_FROM_ONE; - set[i].fixed = other1; - set[i].dynamic1 = other2; - } else if (set[other2].style == VOLUME) { - set[i].substyle = TWO_FROM_ONE; - set[i].fixed = other2; - set[i].dynamic1 = other1; - } else { - set[i].substyle = ONE_FROM_TWO; - set[i].dynamic1 = other1; - set[i].dynamic2 = other2; + if (set[other1].style == NONE) { + set[i].substyle = ONE_FROM_ONE; + set[i].fixed = other1; + set[i].dynamic1 = other2; + } else if (set[other2].style == NONE) { + set[i].substyle = ONE_FROM_ONE; + set[i].fixed = other2; + set[i].dynamic1 = other1; + } else if (set[other1].style == VOLUME) { + set[i].substyle = TWO_FROM_ONE; + set[i].fixed = other1; + set[i].dynamic1 = other2; + } else if (set[other2].style == VOLUME) { + set[i].substyle = TWO_FROM_ONE; + set[i].fixed = other2; + set[i].dynamic1 = other1; + } else { + set[i].substyle = ONE_FROM_TWO; + set[i].dynamic1 = other1; + set[i].dynamic2 = other2; + } } } @@ -1037,6 +1045,7 @@ void FixDeform::options(int narg, char **arg) nskip = child_options[arg[iarg]]; if (iarg + nskip > narg) utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg]), error); + for (int i = 0; i < nskip; i++) leftover_iarg.push_back(iarg + i); iarg += nskip; } else error->all(FLERR, "Unknown fix {} keyword: {}", style, arg[iarg]); } diff --git a/src/fix_deform.h b/src/fix_deform.h index fa92b851e6..b133729444 100644 --- a/src/fix_deform.h +++ b/src/fix_deform.h @@ -68,6 +68,9 @@ class FixDeform : public Fix { }; Set *set; + std::vector leftover_iarg; + int iarg_options_start; + void options(int, char **); void virtual apply_volume(); void apply_strain(); From ec291174092595119d72d70cdab01b810ec9ea6d Mon Sep 17 00:00:00 2001 From: vladgl Date: Fri, 6 Oct 2023 19:23:15 +0300 Subject: [PATCH 036/185] Add new fix wall/flow --- src/KOKKOS/Install.sh | 2 + src/KOKKOS/fix_wall_flow_kokkos.cpp | 295 ++++++++++++++++++++++++++++ src/KOKKOS/fix_wall_flow_kokkos.h | 129 ++++++++++++ src/fix_wall_flow.cpp | 248 +++++++++++++++++++++++ src/fix_wall_flow.h | 60 ++++++ 5 files changed, 734 insertions(+) create mode 100644 src/KOKKOS/fix_wall_flow_kokkos.cpp create mode 100644 src/KOKKOS/fix_wall_flow_kokkos.h create mode 100644 src/fix_wall_flow.cpp create mode 100644 src/fix_wall_flow.h diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index 462c0cbe57..75949c35d8 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -187,6 +187,8 @@ action fix_temp_rescale_kokkos.cpp action fix_temp_rescale_kokkos.h action fix_viscous_kokkos.cpp action fix_viscous_kokkos.h +action fix_wall_flow_kokkos.cpp fix_wall_flow.cpp +action fix_wall_flow_kokkos.h fix_wall_flow.h action fix_wall_gran_kokkos.cpp fix_wall_gran.cpp action fix_wall_gran_kokkos.h fix_wall_gran.h action fix_wall_gran_old.cpp fix_wall_gran.cpp diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp new file mode 100644 index 0000000000..501a1bbd3f --- /dev/null +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -0,0 +1,295 @@ +#include "fix_wall_flow_kokkos.h" +#include "atom_kokkos.h" +#include "memory_kokkos.h" +#include "math_const.h" +#include "atom_masks.h" +#include "force.h" + +#include +//#include "comm.h +// clang-format off + +using namespace LAMMPS_NS; + +template +FixWallFlowKokkos::FixWallFlowKokkos(LAMMPS *lmp, int narg, char **arg) : + FixWallFlow(lmp, narg, arg), rand_pool(rndseed + comm->me) +{ + kokkosable = 1; + exchange_comm_device = sort_device = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | RMASS_MASK | TYPE_MASK | MASK_MASK; + datamask_modify = V_MASK; + + memory->destroy(current_segment); + current_segment = nullptr; + grow_arrays(atomKK->nmax); + + d_walls = d_walls_t("FixWallFlowKokkos::walls", walls.size()); + auto h_walls = Kokkos::create_mirror_view(d_walls); + for (int i = 0; i < walls.size(); ++i) + { + h_walls(i) = walls[i]; + } + Kokkos::deep_copy(d_walls, h_walls); +} + +template +FixWallFlowKokkos::~FixWallFlowKokkos() +{ + if (copymode) return; + memoryKK->destroy_kokkos(k_current_segment, current_segment); +} + +template +void FixWallFlowKokkos::init() +{ + atomKK->sync(execution_space, datamask_read); + k_current_segment.template sync(); + d_x = atomKK->k_x.template view(); + + copymode = 1; + Kokkos::parallel_for(Kokkos::RangePolicy(0, atom->nlocal), *this); + copymode = 0; + + k_current_segment.template modify(); +} + +template +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWallFlowInit, + const int &i) const +{ + double pos = d_x(i, flowax); + d_current_segment(i) = compute_current_segment_kk(pos); +} + +template +void FixWallFlowKokkos::end_of_step() +{ + atomKK->sync(execution_space, datamask_read); + k_current_segment.template sync(); + + d_x = atomKK->k_x.template view(); + d_v = atomKK->k_v.template view(); + d_type = atomKK->k_type.template view(); + d_mask = atomKK->k_mask.template view(); + d_mass = atomKK->k_mass.template view(); + d_rmass = atomKK->k_rmass.template view(); + + copymode = 1; + if (d_rmass.data()) { + Kokkos::parallel_for( + Kokkos::RangePolicy>(0, atom->nlocal), *this); + } else { + Kokkos::parallel_for( + Kokkos::RangePolicy>(0, atom->nlocal), *this); + } + copymode = 0; + atomKK->modified(execution_space, datamask_modify); + k_current_segment.template modify(); +} + +template +template +KOKKOS_INLINE_FUNCTION +void FixWallFlowKokkos::operator()(TagFixWallFlowEndOfStep, + const int &atom_i) const +{ + if (d_mask[atom_i] & groupbit) + { + double pos = d_x(atom_i, flowax); + int prev_segment = d_current_segment(atom_i); + d_current_segment(atom_i) = compute_current_segment_kk(pos); + if (prev_segment != d_current_segment(atom_i)) + { + generate_velocity_kk(atom_i); + } + } +} + +template +template +KOKKOS_INLINE_FUNCTION +void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const +{ + const int newton_iteration_count = 10; + double mass = get_mass(MTag(), atom_i); + const double gamma = 1.0 / std::sqrt(2.0 * kT / mass); + double delta = gamma * flowvel; + + const double edd = std::exp(-delta * delta) / MathConst::MY_PIS + delta * std::erf(delta); + const double probability_threshold = 0.5 * (1. + delta / edd); + + double direction = 1.0; + + rand_type_t rand_gen = rand_pool.get_state(); + + if (/*random->uniform()*/ rand_gen.drand() > probability_threshold) { + delta = -delta; + direction = -direction; + } + + const double xi_0 = rand_gen.drand(); //random->uniform(); + const double F_inf = edd + delta; + const double xi = xi_0 * F_inf; + const double x_0 = (std::sqrt(delta * delta + 2) - delta) * 0.5; + double x = x_0; + for (int i = 0; i < newton_iteration_count; ++i) { + x -= (std::exp(x * x) * MathConst::MY_PIS * (xi - delta * std::erfc(x)) - 1.0) / (x + delta) * + 0.5; + } + + const double nu = x + delta; + const double v = nu / gamma; + + d_v(atom_i, flowax) = v * direction; + d_v(atom_i, (flowax + 1) % 3) = /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); + d_v(atom_i, (flowax + 2) % 3) = /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); + + rand_pool.free_state(rand_gen); +} + +template +KOKKOS_INLINE_FUNCTION +int FixWallFlowKokkos::compute_current_segment_kk(double pos) const +{ + int result = 0; + for (; result < d_walls.extent(0) - 1; ++result) { + if (pos >= d_walls[result] && pos < d_walls[result + 1]) { return result; } + } + return -1; // -1 is "out of box" region +} + + +template +void FixWallFlowKokkos::grow_arrays(int nmax) +{ + k_current_segment.template sync(); + memoryKK->grow_kokkos(k_current_segment, current_segment, nmax, "WallFlowKK::current_segment"); + k_current_segment.template modify(); + + d_current_segment = k_current_segment.template view(); + h_current_segment = k_current_segment.template view(); +} + +template +void FixWallFlowKokkos::copy_arrays(int i, int j, int) +{ + k_current_segment.template sync(); + h_current_segment(j) = h_current_segment(i); + k_current_segment.template modify(); +} + +/* ---------------------------------------------------------------------- + sort local atom-based arrays +------------------------------------------------------------------------- */ + +template +void FixWallFlowKokkos::sort_kokkos(Kokkos::BinSort &Sorter) +{ + // always sort on the device + + k_current_segment.sync_device(); + + Sorter.sort(LMPDeviceType(), k_current_segment.d_view); + + k_current_segment.modify_device(); +} + +template +int FixWallFlowKokkos::pack_exchange(int i, double *buf) +{ + k_current_segment.sync_host(); + buf[0] = static_cast(h_current_segment(i)); + return 1; +} + +template +KOKKOS_INLINE_FUNCTION +void FixWallFlowKokkos::operator()(TagFixWallFlowPackExchange, const int &mysend) const { + const int send_i = d_sendlist(mysend); + const int segment = d_current_segment(send_i); + d_buf(mysend) = static_cast(segment); + + const int copy_i = d_copylist(mysend); + if (copy_i > -1) { + d_current_segment(send_i) = d_current_segment(copy_i); + } +} + +template +int FixWallFlowKokkos::pack_exchange_kokkos( + const int &nsend, DAT::tdual_xfloat_2d &k_buf, + DAT::tdual_int_1d k_sendlist, + DAT::tdual_int_1d k_copylist, + ExecutionSpace space) +{ + k_current_segment.template sync(); + + k_buf.template sync(); + k_sendlist.template sync(); + k_copylist.template sync(); + + d_sendlist = k_sendlist.view(); + d_copylist = k_copylist.view(); + + d_buf = typename ArrayTypes::t_xfloat_1d_um( + k_buf.template view().data(), + k_buf.extent(0)*k_buf.extent(1)); + + copymode = 1; + + Kokkos::parallel_for(Kokkos::RangePolicy(0, nsend), *this); + + copymode = 0; + + k_buf.template modify(); + k_current_segment.template modify(); + + return nsend; +} + +template +int FixWallFlowKokkos::unpack_exchange(int i, double *buf) +{ + k_current_segment.sync_host(); + h_current_segment(i) = static_cast(buf[0]); + k_current_segment.modify_host(); + return 1; +} + +template +KOKKOS_INLINE_FUNCTION +void FixWallFlowKokkos::operator()(TagFixWallFlowUnpackExchange, const int &i) const +{ + int index = d_indices(i); + if (index > -1) { + d_current_segment(index) = static_cast(d_buf(i)); + } +} + +template +void FixWallFlowKokkos::unpack_exchange_kokkos( + DAT::tdual_xfloat_2d &k_buf, + DAT::tdual_int_1d &k_indices, int nrecv, + ExecutionSpace space) +{ + d_buf = typename ArrayTypes::t_xfloat_1d_um( + k_buf.template view().data(), + k_buf.extent(0)*k_buf.extent(1)); + d_indices = k_indices.view(); + + copymode = 1; + Kokkos::parallel_for(Kokkos::RangePolicy(0,nrecv),*this); + copymode = 0; + + k_current_segment.template modify(); +} + +namespace LAMMPS_NS { +template class FixWallFlowKokkos; +#ifdef LMP_KOKKOS_GPU +template class FixWallFlowKokkos; +#endif +} // namespace LAMMPS_NS diff --git a/src/KOKKOS/fix_wall_flow_kokkos.h b/src/KOKKOS/fix_wall_flow_kokkos.h new file mode 100644 index 0000000000..1faa8f4f32 --- /dev/null +++ b/src/KOKKOS/fix_wall_flow_kokkos.h @@ -0,0 +1,129 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef FIX_CLASS +// clang-format off +FixStyle(wall/flow/kk,FixWallFlowKokkos); +FixStyle(wall/flow/kk/device,FixWallFlowKokkos); +FixStyle(wall/flow/kk/host,FixWallFlowKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_FIX_WALL_FLOW_KOKKOS_H +#define LMP_FIX_WALL_FLOW_KOKKOS_H + +#include "fix_wall_flow.h" +#include "kokkos_type.h" +#include "kokkos_base.h" +#include "Kokkos_Random.hpp" +#include "comm_kokkos.h" + +namespace LAMMPS_NS { + +struct TagFixWallFlowInit{}; +template +struct TagFixWallFlowEndOfStep{}; +struct TagFixWallFlowPackExchange{}; +struct TagFixWallFlowUnpackExchange{}; + +template +class FixWallFlowKokkos : public FixWallFlow, public KokkosBase { + public: + typedef DeviceType device_type; + typedef ArrayTypes AT; + struct MassTag{}; + struct RMassTag{}; + FixWallFlowKokkos(class LAMMPS *, int, char **); + ~FixWallFlowKokkos(); + + void init() override; + void end_of_step() override; + void grow_arrays(int) override; + void copy_arrays(int, int, int) override; + void sort_kokkos(Kokkos::BinSort &Sorter) override; + int pack_exchange(int, double *) override; + int unpack_exchange(int, double *) override; + + KOKKOS_INLINE_FUNCTION + void operator() (TagFixWallFlowInit, const int&) const; + + template + KOKKOS_INLINE_FUNCTION + void operator()(TagFixWallFlowEndOfStep, const int&) const; + + KOKKOS_INLINE_FUNCTION + void operator()(TagFixWallFlowPackExchange, const int&) const; + + KOKKOS_INLINE_FUNCTION + void operator()(TagFixWallFlowUnpackExchange, const int&) const; + + int pack_exchange_kokkos(const int &nsend,DAT::tdual_xfloat_2d &buf, + DAT::tdual_int_1d k_sendlist, + DAT::tdual_int_1d k_copylist, + ExecutionSpace space) override; + + void unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf, + DAT::tdual_int_1d &indices,int nrecv, + ExecutionSpace space) override; + protected: + typename AT::t_x_array d_x; + typename AT::t_v_array d_v; + typename AT::t_int_1d d_type; + typename AT::t_int_1d d_mask; + + typename AT::t_float_1d d_mass; + typename AT::t_float_1d d_rmass; + + typedef typename AT::t_xfloat_1d d_walls_t; + typedef Kokkos::Random_XorShift64_Pool rand_pool_t; + typedef typename rand_pool_t::generator_type rand_type_t; + + typename AT::tdual_int_1d k_current_segment; + typename AT::t_int_1d d_current_segment; + typename HAT::t_int_1d h_current_segment; + + typename AT::t_int_1d d_sendlist; + typename AT::t_xfloat_1d d_buf; + typename AT::t_int_1d d_copylist; + typename AT::t_int_1d d_indices; + + d_walls_t d_walls; + + rand_pool_t rand_pool; + + template + KOKKOS_INLINE_FUNCTION + void generate_velocity_kk(int atom_i) const; + + KOKKOS_INLINE_FUNCTION + int compute_current_segment_kk(double pos) const; + + KOKKOS_INLINE_FUNCTION + double get_mass(MassTag, int atom_i) const + { + return d_mass(d_type(atom_i)); + } + + KOKKOS_INLINE_FUNCTION + double get_mass(RMassTag, int atom_i) const + { + return d_rmass(atom_i); + } +}; + +} + +#endif +#endif + diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp new file mode 100644 index 0000000000..a6e3e38cbc --- /dev/null +++ b/src/fix_wall_flow.cpp @@ -0,0 +1,248 @@ +// clang-format off + /* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "fix_wall_flow.h" + +#include "atom.h" +#include "comm.h" +#include "domain.h" +#include "error.h" +#include "input.h" +#include "lattice.h" +#include "modify.h" +#include "update.h" +#include "variable.h" +#include "random_mars.h" +#include "memory.h" +#include "force.h" +#include "math_const.h" + +#include +#include +#include +#include +#include + +using namespace LAMMPS_NS; +using namespace FixConst; + +/* ---------------------------------------------------------------------- */ + +// fix name groupId wall/flow vel temp dim N coords... + +FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg), + flowax(FlowAxis::AX_X), + flowvel(0.0), + flowdir(0), + rndseed(0), + current_segment(nullptr) +{ + if (narg < 9) utils::missing_cmd_args(FLERR, "fix wall/flow", error); + + dynamic_group_allow = 1; + bool do_abort = false; + + int iarg = 3; + // parsing axis + if (strcmp(arg[iarg], "x") == 0) flowax = FlowAxis::AX_X; + else if (strcmp(arg[iarg],"y") == 0) flowax = FlowAxis::AX_Y; + else if (strcmp(arg[iarg],"z") == 0) flowax = FlowAxis::AX_Z; + else error->all(FLERR,"Illegal fix wall/flow argument: axis must by x or y or z, but {} specified", arg[iarg]); + + ++iarg; + // parsing velocity + flowvel = utils::numeric(FLERR,arg[iarg],do_abort,lmp); + if (flowvel == 0.0) error->all(FLERR,"Illegal fix wall/flow argument: velocity cannot be 0"); + if (flowvel > 0.0) flowdir = 1; + else flowdir = -1; + if(flowdir < 0) error->all(FLERR, "Negative direction is not supported yet"); + + ++iarg; + // parsing temperature + double flowtemp = utils::numeric(FLERR,arg[iarg],do_abort,lmp); + kT = lmp->force->boltz * flowtemp / force->mvv2e; + + ++iarg; + // parsing seed + rndseed = utils::inumeric(FLERR, arg[iarg],do_abort,lmp); + if(rndseed <= 0) error->all(FLERR, "Random seed must be positive!"); + + ++iarg; + // parsing wall count + int wallcount = utils::inumeric(FLERR,arg[iarg],do_abort,lmp); + if(wallcount <= 0) error->all(FLERR,"Illegal fix wall/flow argument: wall count must be positive"); + + ++iarg; + // parsing walls + if(narg - iarg != wallcount) error->all(FLERR, "Wrong fix wall/flow wall count {}," + " must be {}", + wallcount, narg - iarg); + walls.resize(wallcount + 2); + walls.front() = domain->boxlo[flowax]; + for (size_t w = 1; w <= wallcount; ++w, ++iarg) + { + walls[w] = utils::numeric(FLERR,arg[iarg],do_abort,lmp); + } + walls.back() = domain->boxhi[flowax]; + if (!std::is_sorted(walls.begin(), walls.end(), std::less_equal())) + { + error->all(FLERR, "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); + } + + memory->grow(current_segment, atom->nmax, "WallFlow::current_segment"); + atom->add_callback(Atom::GROW); + if (restart_peratom) atom->add_callback(Atom::RESTART); + + maxexchange = 1; + + random = new RanMars(lmp, rndseed + comm->me); + } + +/* ---------------------------------------------------------------------- */ + +FixWallFlow::~FixWallFlow() +{ + if (copymode) return; + atom->delete_callback(id, Atom::GROW); + if (restart_peratom) atom->delete_callback(id, Atom::RESTART); + memory->destroy(current_segment); + + delete random; +} + +/* ---------------------------------------------------------------------- */ + +int FixWallFlow::setmask() +{ + int mask = 0; + + mask |= END_OF_STEP; + + return mask; +} + +/* ---------------------------------------------------------------------- */ + +void FixWallFlow::init() +{ + int nrigid = 0; + for (int i = 0; i < modify->nfix; i++) + if (modify->fix[i]->rigid_flag) nrigid++; + + if (nrigid && comm->me == 0) + error->warning(FLERR,"FixWallFlow is not compatible with rigid bodies"); + + for (int i = 0; i < atom->nlocal; ++i) + { + double pos = atom->x[i][flowax]; + current_segment[i] = compute_current_segment(pos); + } +} + +/* ---------------------------------------------------------------------- */ + +void FixWallFlow::end_of_step() +{ + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; ++i) + { + if (mask[i] & groupbit) + { + double pos = x[i][flowax]; + int prev_segment = current_segment[i]; + current_segment[i] = compute_current_segment(pos); + + if (prev_segment != current_segment[i]) + { + generate_velocity(i); + } + } + } +} + +void FixWallFlow::generate_velocity(int atom_i) +{ + const int newton_iteration_count = 10; + double *vel = atom->v[atom_i]; + double mass = atom->mass[atom->type[atom_i]]; + const double gamma = 1.0 / std::sqrt(2.0 * kT / mass); + double delta = gamma * flowvel; + + const double edd = std::exp(-delta*delta) / MathConst::MY_PIS + delta * std::erf(delta); + const double probability_threshold = 0.5f * (1.f + delta / edd); + + double direction = 1.0; + + if (random->uniform() > probability_threshold) + { + delta = -delta; + direction = -direction; + } + + const double xi_0 = random->uniform(); + const double F_inf = edd + delta; + const double xi = xi_0 * F_inf; + const double x_0 = (std::sqrt(delta*delta + 2) - delta) * 0.5; + double x = x_0; + for (int i = 0; i < newton_iteration_count; ++i) + { + x -= (std::exp(x*x) * MathConst::MY_PIS * (xi - delta * std::erfc(x)) - 1.0) / (x + delta) * 0.5; + } + + const double nu = x + delta; + const double v = nu / gamma; + + vel[flowax] = v * direction; + vel[(flowax + 1) % 3] = random->gaussian() / (gamma * MathConst::MY_SQRT2); + vel[(flowax + 2) % 3] = random->gaussian() / (gamma * MathConst::MY_SQRT2); +} + +int FixWallFlow::compute_current_segment(double pos) const +{ + int result = 0; + for (; result < walls.size()-1; ++result) + { + if (pos >= walls[result] && pos < walls[result + 1]) + { + return result; + } + } + return -1; // -1 is "out of box" region +} + +void FixWallFlow::grow_arrays(int nmax) +{ + memory->grow(current_segment, nmax, "WallFlow::current_segment"); +} + +void FixWallFlow::copy_arrays(int i, int j, int) +{ + current_segment[j] = current_segment[i]; +} + +int FixWallFlow::pack_exchange(int i, double* buf) +{ + buf[0] = static_cast(current_segment[i]); + return 1; +} + +int FixWallFlow::unpack_exchange(int i, double* buf) +{ + current_segment[i] = static_cast(buf[0]); + return 1; +} diff --git a/src/fix_wall_flow.h b/src/fix_wall_flow.h new file mode 100644 index 0000000000..ec9e4a4601 --- /dev/null +++ b/src/fix_wall_flow.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef FIX_CLASS +// clang-format off +FixStyle(wall/flow,FixWallFlow); +// clang-format on +#else + +#ifndef LMP_FIX_WALL_FLOW_H +#define LMP_FIX_WALL_FLOW_H + +#include "fix.h" +#include +namespace LAMMPS_NS { + +class FixWallFlow : public Fix { + public: + enum FlowAxis {AX_X = 0, AX_Y = 1, AX_Z = 2}; + + FixWallFlow(class LAMMPS *, int, char **); + ~FixWallFlow() override; + int setmask() override; + void init() override; + void end_of_step() override; + + void grow_arrays(int) override; + void copy_arrays(int, int, int) override; + + int pack_exchange(int, double *) override; + int unpack_exchange(int, double *) override; + + protected: + FlowAxis flowax; + double flowvel; + double kT; + std::vector walls; + + int flowdir; + int rndseed; + class RanMars *random; + int *current_segment; + int compute_current_segment(double pos) const; + void generate_velocity(int i); +}; + +} // namespace LAMMPS_NS + +#endif +#endif From b775085189d3b66d193cc4b8e96cb3599f9c5db0 Mon Sep 17 00:00:00 2001 From: vladgl Date: Mon, 9 Oct 2023 13:29:15 +0300 Subject: [PATCH 037/185] Add licensing info --- src/KOKKOS/fix_wall_flow_kokkos.cpp | 19 +++++++++++++++++++ src/fix_wall_flow.cpp | 8 ++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index 501a1bbd3f..46805f07d6 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -1,3 +1,22 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing authors: Vladislav Galigerov (HSE), + Daniil Pavlov (MIPT) +------------------------------------------------------------------------- */ + #include "fix_wall_flow_kokkos.h" #include "atom_kokkos.h" #include "memory_kokkos.h" diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index a6e3e38cbc..adaf7412cc 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -1,5 +1,5 @@ // clang-format off - /* ---------------------------------------------------------------------- +/* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories LAMMPS development team: developers@lammps.org @@ -12,8 +12,12 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "fix_wall_flow.h" +/* ---------------------------------------------------------------------- + Contributing authors: Vladislav Galigerov (HSE), + Daniil Pavlov (MIPT) +------------------------------------------------------------------------- */ +#include "fix_wall_flow.h" #include "atom.h" #include "comm.h" #include "domain.h" From 70cc1039fd304a2e1b64897e37ad4efbe14915d4 Mon Sep 17 00:00:00 2001 From: vladgl Date: Mon, 9 Oct 2023 17:30:57 +0300 Subject: [PATCH 038/185] Some cleaning --- src/KOKKOS/fix_wall_flow_kokkos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index 46805f07d6..b0efee0941 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -25,7 +25,7 @@ #include "force.h" #include -//#include "comm.h + // clang-format off using namespace LAMMPS_NS; From 19e45187f8d4bf7663ffb3f24591ce66f9153bdd Mon Sep 17 00:00:00 2001 From: vladgl Date: Mon, 9 Oct 2023 17:32:59 +0300 Subject: [PATCH 039/185] Add cite string --- src/fix_wall_flow.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index adaf7412cc..d6dbafd64c 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -19,6 +19,7 @@ #include "fix_wall_flow.h" #include "atom.h" +#include "citeme.h" #include "comm.h" #include "domain.h" #include "error.h" @@ -43,7 +44,16 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ -// fix name groupId wall/flow vel temp dim N coords... +static const char cite_fix_wall_flow_c[] = + "fix wall/flow command: doi:{tba}\n\n" + "@Article{Pavlov-etal-IJHPCA-2023,\n" + " author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod Nikolskiy and Vladimir Stegailov},\n" + " title = {GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence},\n" + " journal = {International Journal of High Performance Computing Applications},\n" + " year = 2023,\n" + " volume = {tba},\n" + " pages = {tba}\n” + "}\n\n"; FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), @@ -53,6 +63,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : rndseed(0), current_segment(nullptr) { + if (lmp->citeme) lmp->citeme->add(cite_fix_wall_flow_c); if (narg < 9) utils::missing_cmd_args(FLERR, "fix wall/flow", error); dynamic_group_allow = 1; From d7f7306b7d14ecb067b08c0fbf17aaf26ee83852 Mon Sep 17 00:00:00 2001 From: vladgl Date: Fri, 13 Oct 2023 14:26:05 +0300 Subject: [PATCH 040/185] Fix character --- src/fix_wall_flow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index d6dbafd64c..ff4d4078dd 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -52,7 +52,7 @@ static const char cite_fix_wall_flow_c[] = " journal = {International Journal of High Performance Computing Applications},\n" " year = 2023,\n" " volume = {tba},\n" - " pages = {tba}\n” + " pages = {tba}\n" "}\n\n"; FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : From 249f3b0af4149d90ea68d3a008ed3b3148e9b5c1 Mon Sep 17 00:00:00 2001 From: vladgl Date: Sat, 14 Oct 2023 13:10:08 +0300 Subject: [PATCH 041/185] Add units command --- src/fix_wall_flow.cpp | 44 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index ff4d4078dd..e5602b7af9 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -82,7 +82,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : if (flowvel == 0.0) error->all(FLERR,"Illegal fix wall/flow argument: velocity cannot be 0"); if (flowvel > 0.0) flowdir = 1; else flowdir = -1; - if(flowdir < 0) error->all(FLERR, "Negative direction is not supported yet"); + if(flowdir < 0) error->all(FLERR, "Illegal fix wall/flow argument: negative direction is not supported yet"); ++iarg; // parsing temperature @@ -92,29 +92,59 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : ++iarg; // parsing seed rndseed = utils::inumeric(FLERR, arg[iarg],do_abort,lmp); - if(rndseed <= 0) error->all(FLERR, "Random seed must be positive!"); + if(rndseed <= 0) error->all(FLERR, "Illegal fix wall/flow argument: random seed must be positive integer"); ++iarg; // parsing wall count int wallcount = utils::inumeric(FLERR,arg[iarg],do_abort,lmp); - if(wallcount <= 0) error->all(FLERR,"Illegal fix wall/flow argument: wall count must be positive"); + if(wallcount <= 0) error->all(FLERR,"Illegal fix wall/flow argument: wall count must be positive integer"); ++iarg; // parsing walls - if(narg - iarg != wallcount) error->all(FLERR, "Wrong fix wall/flow wall count {}," - " must be {}", - wallcount, narg - iarg); + if(narg - iarg != wallcount && narg - iarg != wallcount + 2) error->all(FLERR, "Wrong fix wall/flow wall count"); + auto getscale = [&]() -> double { + switch (flowax) + { + case FlowAxis::AX_X: + return domain->lattice->xlattice; + case FlowAxis::AX_Y: + return domain->lattice->ylattice; + case FlowAxis::AX_Z: + return domain->lattice->zlattice; + default: return 0.0; + } + return 0.0; + }; + double scale = getscale(); + + if (narg - iarg == wallcount + 2) + { + if(strcmp(arg[narg - 2], "units") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); + if (strcmp(arg[narg - 1], "box") == 0) scale = 1.0; + else if (strcmp(arg[narg - 1], "lattice") == 0) + { + scale = getscale(); + } + else error->all(FLERR, "Wrong fix wall/flow units command"); + } + walls.resize(wallcount + 2); walls.front() = domain->boxlo[flowax]; for (size_t w = 1; w <= wallcount; ++w, ++iarg) { - walls[w] = utils::numeric(FLERR,arg[iarg],do_abort,lmp); + walls[w] = utils::numeric(FLERR,arg[iarg],do_abort,lmp) * scale; } walls.back() = domain->boxhi[flowax]; if (!std::is_sorted(walls.begin(), walls.end(), std::less_equal())) { error->all(FLERR, "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); } + std::cout << "Walls:\n" + for (auto w : walls) + { + std::cout << w << " "; + } + std::cout << std::endl; memory->grow(current_segment, atom->nmax, "WallFlow::current_segment"); atom->add_callback(Atom::GROW); From 381330c3c25aa1e04819925e42ad8202b0615072 Mon Sep 17 00:00:00 2001 From: vladgl Date: Sat, 14 Oct 2023 13:11:06 +0300 Subject: [PATCH 042/185] Fix typo --- src/fix_wall_flow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index e5602b7af9..beaaa474eb 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -139,7 +139,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : { error->all(FLERR, "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); } - std::cout << "Walls:\n" + std::cout << "Walls:\n"; for (auto w : walls) { std::cout << w << " "; From c53847ad882f282ecf737040bedf3968682c656f Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Wed, 31 Jan 2024 15:35:04 +0300 Subject: [PATCH 043/185] Update citation --- src/fix_wall_flow.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index beaaa474eb..591f640279 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -45,14 +45,15 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ static const char cite_fix_wall_flow_c[] = - "fix wall/flow command: doi:{tba}\n\n" - "@Article{Pavlov-etal-IJHPCA-2023,\n" + "fix wall/flow command: doi:10.1177/10943420231213013\n\n" + "@Article{Pavlov-etal-IJHPCA-2024,\n" " author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod Nikolskiy and Vladimir Stegailov},\n" - " title = {GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence},\n" - " journal = {International Journal of High Performance Computing Applications},\n" - " year = 2023,\n" - " volume = {tba},\n" - " pages = {tba}\n" + " title = {GPU-based molecular dynamics of fluid flows: Reaching for turbulence},\n" + " journal = {The International Journal of High Performance Computing Applications},\n" + " year = 2024,\n" + " volume = 38,\n" + " number = 1,\n" + " pages = 34-49\n" "}\n\n"; FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : From 90105fd58a0a5e55ee43993c9b9c7415376ea5ca Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Sun, 4 Feb 2024 16:02:53 +0300 Subject: [PATCH 044/185] Add wall_flow documentation --- doc/src/Bibliography.rst | 3 + doc/src/Commands_fix.rst | 1 + doc/src/fix.rst | 1 + doc/src/fix_wall_flow.rst | 123 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 doc/src/fix_wall_flow.rst diff --git a/doc/src/Bibliography.rst b/doc/src/Bibliography.rst index 4ed8e73dfe..9778340c94 100644 --- a/doc/src/Bibliography.rst +++ b/doc/src/Bibliography.rst @@ -877,6 +877,9 @@ Bibliography **(PLUMED)** G.A. Tribello, M. Bonomi, D. Branduardi, C. Camilloni and G. Bussi, Comp. Phys. Comm 185, 604 (2014) +**(Pavlov)** +D Pavlov, V Galigerov, D Kolotinskii, V Nikolskiy, V Stegailov, International Journal of High Performance Computing Applications, 38, 34-49 (2024). + **(Paquay)** Paquay and Kusters, Biophys. J., 110, 6, (2016). preprint available at `arXiv:1411.3019 `_. diff --git a/doc/src/Commands_fix.rst b/doc/src/Commands_fix.rst index e89e302673..304f54f690 100644 --- a/doc/src/Commands_fix.rst +++ b/doc/src/Commands_fix.rst @@ -262,6 +262,7 @@ OPT. * :doc:`wall/body/polyhedron ` * :doc:`wall/colloid ` * :doc:`wall/ees ` + * :doc:`wall/flow (k) ` * :doc:`wall/gran (k) ` * :doc:`wall/gran/region ` * :doc:`wall/harmonic ` diff --git a/doc/src/fix.rst b/doc/src/fix.rst index 69a7212487..4ff7fd6bd6 100644 --- a/doc/src/fix.rst +++ b/doc/src/fix.rst @@ -427,6 +427,7 @@ accelerated styles exist. * :doc:`wall/body/polyhedron ` - time integration for body particles of style :doc:`rounded/polyhedron ` * :doc:`wall/colloid ` - Lennard-Jones wall interacting with finite-size particles * :doc:`wall/ees ` - wall for ellipsoidal particles +* :doc:`wall/flow ` - flow boundary conditions * :doc:`wall/gran ` - frictional wall(s) for granular simulations * :doc:`wall/gran/region ` - :doc:`fix wall/region ` equivalent for use with granular particles * :doc:`wall/harmonic ` - harmonic spring wall diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst new file mode 100644 index 0000000000..56a2510d08 --- /dev/null +++ b/doc/src/fix_wall_flow.rst @@ -0,0 +1,123 @@ +.. index:: fix wall/flow +.. index:: fix wall/flow/kk + +fix wall/flow command +===================== + +Accelerator Variants: *wall/flow/kk* + +Syntax +"""""" + +.. code-block:: LAMMPS + + fix ID group-ID wall/flow ax vf T seed N coords... + +* ID, group-ID are documented in :doc:`fix ` command +* wall/flow = style name of this fix command +* ax = flow axis (*x*, *y*, or *z* character) +* vf = *ax* component of generated flow velocity +* T = flow temperature (temperature units) +* seed = random seed for stochasticity (positive integer) +* N = number of walls (positive integer) +* coords = set of N wall coordinates (box units) along *ax* axis arranged in ascending order. Note that an additional implicit wall is introduced at the boundary of the simulation domain, so the resulting system always has N+1 walls. + +Examples +"""""""" + +.. code-block:: LAMMPS + + fix 1 g_flow wall/flow x ${VFLOW} ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} + fix 2 all wall/flow 0.4 0.2 3 1 400 + +Description +""""""""""" + +This fix implements flow boundary conditions (FBC) introduced in :ref:`(Pavlov) ` and :ref:`(Pavlov) `. +The goal is to generate a stationary flow with a shifted Maxwell velocity distribution: + +.. math:: + + f_z(v_z) \propto \exp{\left(-\frac{m (v_z-v_{\text{flow}})^2}{2 k T}\right)} + +This is achieved by reassigning the velocity of each particle that passes a wall. +Such reassigning represents an emission of a new particle into the system with +simultaneous removal of a particle with the same position. +The parallel velocity components parallel to the wall are re-assigned according +to the Maxwell velocity distribution. The perpendicular component is assigned +according to the following velocity distribution: + +.. math:: + + f_{\text{z generated}}(v_z) \propto v_z f_z(v_z) + +It can be shown that in an ideal-gas scenario this makes the velocity +distribution of particles between walls exactly as desired. + +Since in most cases simulated systems are not ideal gas, +the need for multiple walls might arise, as a single wall may not be +sufficient for maintaining a stationary flow without congestions +manifesting as areas with increased density located upstream from static obstacles. + +For the same reason, the actual temperature and velocity of the generated +flow may differ from ones requested. The degree of such discrepancy is determined +by how different from the ideal gas the simulated system is. Therefore, a calibration procedure is required for each system as described in :ref:`(Pavlov) `. + +The interactions between particles on different sides of a wall are not disabled or neglected and the +particle positions aren't affected by the velocity reassignment. +This removes the need to modify the force field to work correctly in cases when a particle is close +to a wall (for example, if particle positions were uniformly redistributed across the surface of the wall, +two particles could end up too close to each other, potentially causing the simulation to explode). +However due to this compromise, some collective phenomena such as areas with increased/decreased density +or collective movements are not fully removed when particles cross a wall. +This unwanted consequence can also be potentially mitigated by using more than one wall. + + +---------- + +Note that when high flow velocity is reached, a lost atoms error may +occur (see :doc:`error messages `). +If this message appears when using this fix, you can, for example, reduce the frequency of the +neighbor list rebuild via :doc:`neigh_modify ` command. + +Restart, fix_modify, output, run start/stop, minimize info +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +No information about this fix is written to :doc:`binary restart files `. + +None of the :doc:`fix_modify ` options are relevant to +this fix. + +No global or per-atom quantities are stored by this fix for access by +various :doc:`output commands `. + +No parameter of this fix can be used with the *start/stop* keywords of +the :doc:`run ` command. + +This fix is not invoked during :doc:`energy minimization `. + +Restrictions +"""""""""""" + +Flow boundary conditions should not be used with rigid bodies such as those +defined by a "fix rigid" command. + +Related commands +"""""""""""""""" + +:doc:`fix wall/reflect ` command + +Default +""""""" + +none + +---------- + +.. _fbc-Pavlov1: + +**(Pavlov)** Pavlov, Kolotinskii, Stegailov, “GPU-Based Molecular Dynamics of Turbulent Liquid Flows with OpenMM”, In: Proceedings of PPAM-2022, LNCS (Springer), vol. 13826, pp. 346–358 (2023) + +.. _fbc-Pavlov2: + +**(Pavlov)** Pavlov, Galigerov, Kolotinskii, Nikolskiy, Stegailov, "GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence”, Int. J. High Perf. Comp. Appl., (2024) \ No newline at end of file From 4ad5a9d3eb01a7ad2a3771d43c678b8c821e5e24 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Tue, 6 Feb 2024 21:00:37 +0300 Subject: [PATCH 045/185] Fix doc --- doc/src/fix_wall_flow.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index 56a2510d08..e0f5424658 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -11,7 +11,7 @@ Syntax .. code-block:: LAMMPS - fix ID group-ID wall/flow ax vf T seed N coords... + fix ID group-ID wall/flow ax vf T seed N coords ... keyword value * ID, group-ID are documented in :doc:`fix ` command * wall/flow = style name of this fix command @@ -22,6 +22,15 @@ Syntax * N = number of walls (positive integer) * coords = set of N wall coordinates (box units) along *ax* axis arranged in ascending order. Note that an additional implicit wall is introduced at the boundary of the simulation domain, so the resulting system always has N+1 walls. +* zero or more keyword/value pairs may be appended +* keyword = *units* + + .. parsed-literal:: + + *units* value = *lattice* or *box* + *lattice* = the wall positions are defined in lattice units + *box* = the wall positions are defined in simulation box units + Examples """""""" @@ -110,7 +119,7 @@ Related commands Default """"""" -none +The default for the units keyword is lattice. ---------- From 0f5436de99607f000a0b4c2291443baf2d5e1c46 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Tue, 6 Feb 2024 22:43:56 +0300 Subject: [PATCH 046/185] Fix spelling --- doc/src/fix_wall_flow.rst | 10 +++++----- doc/utils/sphinx-config/false_positives.txt | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index e0f5424658..f6f5a242ac 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -42,7 +42,7 @@ Examples Description """"""""""" -This fix implements flow boundary conditions (FBC) introduced in :ref:`(Pavlov) ` and :ref:`(Pavlov) `. +This fix implements flow boundary conditions (FBC) introduced in :ref:`(Pavlov1) ` and :ref:`(Pavlov2) `. The goal is to generate a stationary flow with a shifted Maxwell velocity distribution: .. math:: @@ -52,7 +52,7 @@ The goal is to generate a stationary flow with a shifted Maxwell velocity distri This is achieved by reassigning the velocity of each particle that passes a wall. Such reassigning represents an emission of a new particle into the system with simultaneous removal of a particle with the same position. -The parallel velocity components parallel to the wall are re-assigned according +The velocity components parallel to the wall are re-assigned according to the Maxwell velocity distribution. The perpendicular component is assigned according to the following velocity distribution: @@ -65,7 +65,7 @@ distribution of particles between walls exactly as desired. Since in most cases simulated systems are not ideal gas, the need for multiple walls might arise, as a single wall may not be -sufficient for maintaining a stationary flow without congestions +sufficient for maintaining a stationary flow without congestion manifesting as areas with increased density located upstream from static obstacles. For the same reason, the actual temperature and velocity of the generated @@ -125,8 +125,8 @@ The default for the units keyword is lattice. .. _fbc-Pavlov1: -**(Pavlov)** Pavlov, Kolotinskii, Stegailov, “GPU-Based Molecular Dynamics of Turbulent Liquid Flows with OpenMM”, In: Proceedings of PPAM-2022, LNCS (Springer), vol. 13826, pp. 346–358 (2023) +**(Pavlov1)** Pavlov, Kolotinskii, Stegailov, "GPU-Based Molecular Dynamics of Turbulent Liquid Flows with OpenMM", Proceedings of PPAM-2022, LNCS (Springer), vol. 13826, pp. 346-358 (2023) .. _fbc-Pavlov2: -**(Pavlov)** Pavlov, Galigerov, Kolotinskii, Nikolskiy, Stegailov, "GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence”, Int. J. High Perf. Comp. Appl., (2024) \ No newline at end of file +**(Pavlov2)** Pavlov, Galigerov, Kolotinskii, Nikolskiy, Stegailov, "GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence", Int. J. High Perf. Comp. Appl., (2024) \ No newline at end of file diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 4f5fe6fdaf..6106a1638c 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -1770,6 +1770,7 @@ Kolafa Kollman kolmogorov Kolmogorov +Kolotinskii Kondor konglt Koning @@ -2774,6 +2775,7 @@ PEigenDense Peng peptide peratom +Perf Pergamon pergrid peri @@ -3884,6 +3886,7 @@ Verlet versa Verstraelen ves +vf vflag vfrac vhi From a3a054cc152f08006f8b6bb8870869f4d4f5626c Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Tue, 6 Feb 2024 23:19:47 +0300 Subject: [PATCH 047/185] Another spell fix --- doc/src/fix_wall_flow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index f6f5a242ac..d89e0b6d89 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -73,7 +73,7 @@ flow may differ from ones requested. The degree of such discrepancy is determine by how different from the ideal gas the simulated system is. Therefore, a calibration procedure is required for each system as described in :ref:`(Pavlov) `. The interactions between particles on different sides of a wall are not disabled or neglected and the -particle positions aren't affected by the velocity reassignment. +particle positions are not affected by the velocity reassignment. This removes the need to modify the force field to work correctly in cases when a particle is close to a wall (for example, if particle positions were uniformly redistributed across the surface of the wall, two particles could end up too close to each other, potentially causing the simulation to explode). From 5bab14d31e9b2b8ec9622778de2ec78088b1125d Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Tue, 6 Feb 2024 23:23:11 +0300 Subject: [PATCH 048/185] Sync unpack_exchange_kokkos with develop --- src/KOKKOS/fix_wall_flow_kokkos.cpp | 1 + src/KOKKOS/fix_wall_flow_kokkos.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index b0efee0941..daf73e7ef2 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -292,6 +292,7 @@ template void FixWallFlowKokkos::unpack_exchange_kokkos( DAT::tdual_xfloat_2d &k_buf, DAT::tdual_int_1d &k_indices, int nrecv, + int /*nrecv1*/, int /*nextrarecv1*/, ExecutionSpace space) { d_buf = typename ArrayTypes::t_xfloat_1d_um( diff --git a/src/KOKKOS/fix_wall_flow_kokkos.h b/src/KOKKOS/fix_wall_flow_kokkos.h index 1faa8f4f32..10bfed962d 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.h +++ b/src/KOKKOS/fix_wall_flow_kokkos.h @@ -75,6 +75,7 @@ class FixWallFlowKokkos : public FixWallFlow, public KokkosBase { void unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf, DAT::tdual_int_1d &indices,int nrecv, + int /*nrecv1*/, int /*nextrarecv1*/, ExecutionSpace space) override; protected: typename AT::t_x_array d_x; From df7662162e29cbcb40e8eecb26736950535c50f8 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Wed, 7 Feb 2024 13:53:40 +0300 Subject: [PATCH 049/185] Add example --- examples/wall/in.wall.flow | 79 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 examples/wall/in.wall.flow diff --git a/examples/wall/in.wall.flow b/examples/wall/in.wall.flow new file mode 100644 index 0000000000..59d1b99eda --- /dev/null +++ b/examples/wall/in.wall.flow @@ -0,0 +1,79 @@ +variable nrun equal 10000 +variable dump_count equal 10 + +variable nwall equal 4 +variable w1 equal 67 +variable w2 equal 71 +variable w3 equal 75 +variable w4 equal 79 + +variable x_cylinder equal 20 +variable y_cylinder equal 17 +variable r_cylinder equal 4 + +variable MASS equal 1 +variable TEMP equal 0.4 +variable VFLOW equal 0.5 + +units lj +atom_style atomic + +lattice fcc 0.3 +region sim_box block 0 84 0 34 0 10 + +boundary p p p + +create_box 2 sim_box +region reg_cylinder cylinder z ${x_cylinder} ${y_cylinder} ${r_cylinder} EDGE EDGE + +create_atoms 1 box + +## setup obstacle ## +group g_obst region reg_cylinder +group g_flow subtract all g_obst +set group g_obst type 2 + +mass 1 ${MASS} +mass 2 ${MASS} + +velocity g_flow create ${TEMP} 4928459 rot yes dist gaussian +velocity g_obst set 0.0 0.0 0.0 + +pair_style lj/cut 1.122462 +pair_coeff 1 1 1.0 1.0 +pair_coeff 1 2 1.0 1.0 +pair_coeff 2 2 1.0 1.0 +pair_modify shift yes + +neighbor 0.3 bin +neigh_modify delay 0 every 20 check no + +fix 1 g_flow nve +fix 2 g_flow wall/flow x ${VFLOW} ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} + +variable dump_every equal ${nrun}/${dump_count} +variable thermo_every equal ${dump_every} +variable restart_every equal ${nrun}/10 + +##### uncomment for grid aggregation ##### +#variable gr_Nx equal 42 +#variable gr_Ny equal 17 +#variable gr_Nz equal 1 +#variable gr_Nevery equal ${dump_every} +#variable gr_Nrepeat equal 1 +#variable gr_Nfreq equal ${dump_every} +#fix 3 g_flow ave/grid ${gr_Nevery} ${gr_Nrepeat} ${gr_Nfreq} ${gr_Nx} ${gr_Ny} ${gr_Nz} vx vy vz density/mass norm all ave one +#compute ct_gridId g_flow property/grid ${gr_Nx} ${gr_Ny} ${gr_Nz} id +#dump dmp_grid g_flow grid ${dump_every} grid.lammpstrj c_ct_gridId:grid:data f_3:grid:data[*] +########################################## + +#dump dmp_coord all atom ${dump_every} dump.lammpstrj + +#compute ct_Temp g_flow temp/com +#thermo_style custom step temp epair emol etotal press c_ct_Temp + +#restart ${restart_every} flow.restart + +timestep 0.005 +thermo ${thermo_every} +run ${nrun} From e33590b2fc101813d0beef963daf31c0dd40a264 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Wed, 7 Feb 2024 16:03:32 +0300 Subject: [PATCH 050/185] Whitespace --- doc/src/fix_wall_flow.rst | 2 +- src/KOKKOS/fix_wall_flow_kokkos.cpp | 32 ++++++++++++++--------------- src/KOKKOS/fix_wall_flow_kokkos.h | 6 +++--- src/fix_wall_flow.cpp | 4 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index d89e0b6d89..3b8d7300e6 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -129,4 +129,4 @@ The default for the units keyword is lattice. .. _fbc-Pavlov2: -**(Pavlov2)** Pavlov, Galigerov, Kolotinskii, Nikolskiy, Stegailov, "GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence", Int. J. High Perf. Comp. Appl., (2024) \ No newline at end of file +**(Pavlov2)** Pavlov, Galigerov, Kolotinskii, Nikolskiy, Stegailov, "GPU-based Molecular Dynamics of Fluid Flows: Reaching for Turbulence", Int. J. High Perf. Comp. Appl., (2024) diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index daf73e7ef2..a143578fdc 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -48,7 +48,7 @@ FixWallFlowKokkos::FixWallFlowKokkos(LAMMPS *lmp, int narg, char **a d_walls = d_walls_t("FixWallFlowKokkos::walls", walls.size()); auto h_walls = Kokkos::create_mirror_view(d_walls); for (int i = 0; i < walls.size(); ++i) - { + { h_walls(i) = walls[i]; } Kokkos::deep_copy(d_walls, h_walls); @@ -61,7 +61,7 @@ FixWallFlowKokkos::~FixWallFlowKokkos() memoryKK->destroy_kokkos(k_current_segment, current_segment); } -template +template void FixWallFlowKokkos::init() { atomKK->sync(execution_space, datamask_read); @@ -83,10 +83,10 @@ KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWall d_current_segment(i) = compute_current_segment_kk(pos); } -template -void FixWallFlowKokkos::end_of_step() +template +void FixWallFlowKokkos::end_of_step() { - atomKK->sync(execution_space, datamask_read); + atomKK->sync(execution_space, datamask_read); k_current_segment.template sync(); d_x = atomKK->k_x.template view(); @@ -111,17 +111,17 @@ void FixWallFlowKokkos::end_of_step() template template -KOKKOS_INLINE_FUNCTION +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWallFlowEndOfStep, const int &atom_i) const { - if (d_mask[atom_i] & groupbit) - { + if (d_mask[atom_i] & groupbit) + { double pos = d_x(atom_i, flowax); int prev_segment = d_current_segment(atom_i); d_current_segment(atom_i) = compute_current_segment_kk(pos); - if (prev_segment != d_current_segment(atom_i)) - { + if (prev_segment != d_current_segment(atom_i)) + { generate_velocity_kk(atom_i); } } @@ -129,7 +129,7 @@ void FixWallFlowKokkos::operator()(TagFixWallFlowEndOfStep, template template -KOKKOS_INLINE_FUNCTION +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const { const int newton_iteration_count = 10; @@ -170,7 +170,7 @@ void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const } template -KOKKOS_INLINE_FUNCTION +KOKKOS_INLINE_FUNCTION int FixWallFlowKokkos::compute_current_segment_kk(double pos) const { int result = 0; @@ -181,8 +181,8 @@ int FixWallFlowKokkos::compute_current_segment_kk(double pos) const } -template -void FixWallFlowKokkos::grow_arrays(int nmax) +template +void FixWallFlowKokkos::grow_arrays(int nmax) { k_current_segment.template sync(); memoryKK->grow_kokkos(k_current_segment, current_segment, nmax, "WallFlowKK::current_segment"); @@ -193,7 +193,7 @@ void FixWallFlowKokkos::grow_arrays(int nmax) } template -void FixWallFlowKokkos::copy_arrays(int i, int j, int) +void FixWallFlowKokkos::copy_arrays(int i, int j, int) { k_current_segment.template sync(); h_current_segment(j) = h_current_segment(i); @@ -252,7 +252,7 @@ int FixWallFlowKokkos::pack_exchange_kokkos( d_sendlist = k_sendlist.view(); d_copylist = k_copylist.view(); - + d_buf = typename ArrayTypes::t_xfloat_1d_um( k_buf.template view().data(), k_buf.extent(0)*k_buf.extent(1)); diff --git a/src/KOKKOS/fix_wall_flow_kokkos.h b/src/KOKKOS/fix_wall_flow_kokkos.h index 10bfed962d..8de0eded0a 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.h +++ b/src/KOKKOS/fix_wall_flow_kokkos.h @@ -107,16 +107,16 @@ class FixWallFlowKokkos : public FixWallFlow, public KokkosBase { KOKKOS_INLINE_FUNCTION void generate_velocity_kk(int atom_i) const; - KOKKOS_INLINE_FUNCTION + KOKKOS_INLINE_FUNCTION int compute_current_segment_kk(double pos) const; - KOKKOS_INLINE_FUNCTION + KOKKOS_INLINE_FUNCTION double get_mass(MassTag, int atom_i) const { return d_mass(d_type(atom_i)); } - KOKKOS_INLINE_FUNCTION + KOKKOS_INLINE_FUNCTION double get_mass(RMassTag, int atom_i) const { return d_rmass(atom_i); diff --git a/src/fix_wall_flow.cpp b/src/fix_wall_flow.cpp index 591f640279..695b93aea8 100644 --- a/src/fix_wall_flow.cpp +++ b/src/fix_wall_flow.cpp @@ -99,7 +99,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : // parsing wall count int wallcount = utils::inumeric(FLERR,arg[iarg],do_abort,lmp); if(wallcount <= 0) error->all(FLERR,"Illegal fix wall/flow argument: wall count must be positive integer"); - + ++iarg; // parsing walls if(narg - iarg != wallcount && narg - iarg != wallcount + 2) error->all(FLERR, "Wrong fix wall/flow wall count"); @@ -173,7 +173,7 @@ FixWallFlow::~FixWallFlow() int FixWallFlow::setmask() { int mask = 0; - + mask |= END_OF_STEP; return mask; From 93fcf3cc754e4e77aba34ce839633a57ebe45146 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 7 Feb 2024 15:07:11 -0500 Subject: [PATCH 051/185] move fix to EXTRA-FIX package, update docs, add reference logs to example --- doc/src/fix_wall_flow.rst | 6 + examples/wall/in.wall.flow | 2 +- examples/wall/log.7Feb24.wall.flow.g++.1 | 182 +++++++++++++++++++++++ examples/wall/log.7Feb24.wall.flow.g++.4 | 182 +++++++++++++++++++++++ src/.gitignore | 2 + src/{ => EXTRA-FIX}/fix_wall_flow.cpp | 0 src/{ => EXTRA-FIX}/fix_wall_flow.h | 0 7 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 examples/wall/log.7Feb24.wall.flow.g++.1 create mode 100644 examples/wall/log.7Feb24.wall.flow.g++.4 rename src/{ => EXTRA-FIX}/fix_wall_flow.cpp (100%) rename src/{ => EXTRA-FIX}/fix_wall_flow.h (100%) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index 3b8d7300e6..464021ff52 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -42,6 +42,8 @@ Examples Description """"""""""" +.. versionadded:: TBD + This fix implements flow boundary conditions (FBC) introduced in :ref:`(Pavlov1) ` and :ref:`(Pavlov2) `. The goal is to generate a stationary flow with a shifted Maxwell velocity distribution: @@ -108,6 +110,10 @@ This fix is not invoked during :doc:`energy minimization `. Restrictions """""""""""" +Fix *wall_flow* is part of the EXTRA-FIX package. It is only enabled +if LAMMPS was built with that package. See the :doc:`Build package +` page for more info. + Flow boundary conditions should not be used with rigid bodies such as those defined by a "fix rigid" command. diff --git a/examples/wall/in.wall.flow b/examples/wall/in.wall.flow index 59d1b99eda..9dfe001a55 100644 --- a/examples/wall/in.wall.flow +++ b/examples/wall/in.wall.flow @@ -1,4 +1,4 @@ -variable nrun equal 10000 +variable nrun equal 1000 variable dump_count equal 10 variable nwall equal 4 diff --git a/examples/wall/log.7Feb24.wall.flow.g++.1 b/examples/wall/log.7Feb24.wall.flow.g++.1 new file mode 100644 index 0000000000..75e8b66fe1 --- /dev/null +++ b/examples/wall/log.7Feb24.wall.flow.g++.1 @@ -0,0 +1,182 @@ +LAMMPS (21 Nov 2023 - Development - patch_21Nov2023-758-ge33590b2fc-modified) + using 1 OpenMP thread(s) per MPI task +variable nrun equal 1000 +variable dump_count equal 10 + +variable nwall equal 4 +variable w1 equal 67 +variable w2 equal 71 +variable w3 equal 75 +variable w4 equal 79 + +variable x_cylinder equal 20 +variable y_cylinder equal 17 +variable r_cylinder equal 4 + +variable MASS equal 1 +variable TEMP equal 0.4 +variable VFLOW equal 0.5 + +units lj +atom_style atomic + +lattice fcc 0.3 +Lattice spacing in x,y,z = 2.3712622 2.3712622 2.3712622 +region sim_box block 0 84 0 34 0 10 + +boundary p p p + +create_box 2 sim_box +Created orthogonal box = (0 0 0) to (199.18603 80.622915 23.712622) + 1 by 1 by 1 MPI processor grid +region reg_cylinder cylinder z ${x_cylinder} ${y_cylinder} ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 ${y_cylinder} ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 17 ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 17 4 EDGE EDGE + +create_atoms 1 box +Created 114240 atoms + using lattice units in orthogonal box = (0 0 0) to (199.18603 80.622915 23.712622) + create_atoms CPU = 0.010 seconds + +## setup obstacle ## +group g_obst region reg_cylinder +1950 atoms in group g_obst +group g_flow subtract all g_obst +112290 atoms in group g_flow +set group g_obst type 2 +Setting atom values ... + 1950 settings made for type + +mass 1 ${MASS} +mass 1 1 +mass 2 ${MASS} +mass 2 1 + +velocity g_flow create ${TEMP} 4928459 rot yes dist gaussian +velocity g_flow create 0.4 4928459 rot yes dist gaussian +velocity g_obst set 0.0 0.0 0.0 + +pair_style lj/cut 1.122462 +pair_coeff 1 1 1.0 1.0 +pair_coeff 1 2 1.0 1.0 +pair_coeff 2 2 1.0 1.0 +pair_modify shift yes + +neighbor 0.3 bin +neigh_modify delay 0 every 20 check no + +fix 1 g_flow nve +fix 2 g_flow wall/flow x ${VFLOW} ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 75 ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 75 79 + +variable dump_every equal ${nrun}/${dump_count} +variable dump_every equal 1000/${dump_count} +variable dump_every equal 1000/10 +variable thermo_every equal ${dump_every} +variable thermo_every equal 100 +variable restart_every equal ${nrun}/10 +variable restart_every equal 1000/10 + +##### uncomment for grid aggregation ##### +#variable gr_Nx equal 42 +#variable gr_Ny equal 17 +#variable gr_Nz equal 1 +#variable gr_Nevery equal ${dump_every} +#variable gr_Nrepeat equal 1 +#variable gr_Nfreq equal ${dump_every} +#fix 3 g_flow ave/grid ${gr_Nevery} ${gr_Nrepeat} ${gr_Nfreq} ${gr_Nx} ${gr_Ny} ${gr_Nz} vx vy vz density/mass norm all ave one +#compute ct_gridId g_flow property/grid ${gr_Nx} ${gr_Ny} ${gr_Nz} id +#dump dmp_grid g_flow grid ${dump_every} grid.lammpstrj c_ct_gridId:grid:data f_3:grid:data[*] +########################################## + +#dump dmp_coord all atom ${dump_every} dump.lammpstrj + +#compute ct_Temp g_flow temp/com +#thermo_style custom step temp epair emol etotal press c_ct_Temp + +#restart ${restart_every} flow.restart + +timestep 0.005 +thermo ${thermo_every} +thermo 100 +run ${nrun} +run 1000 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- fix wall/flow command: doi:10.1177/10943420231213013 + +@Article{Pavlov-etal-IJHPCA-2024, + author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod Nikolskiy and Vladimir Stegailov}, + title = {GPU-based molecular dynamics of fluid flows: Reaching for turbulence}, + journal = {The International Journal of High Performance Computing Applications}, + year = 2024, + volume = 38, + number = 1, + pages = 34-49 +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Generated 0 of 1 mixed pair_coeff terms from geometric mixing rule +Neighbor list info ... + update: every = 20 steps, delay = 0 steps, check = no + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 1.422462 + ghost atom cutoff = 1.422462 + binsize = 0.711231, bins = 281 114 34 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair lj/cut, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 26.69 | 26.69 | 26.69 Mbytes + Step Temp E_pair E_mol TotEng Press + 0 0.39317221 0 0 0.58975315 0.11795063 + 100 0.3671684 0.045118445 0 0.59586622 0.27378331 + 200 0.3732041 0.036897471 0 0.59669873 0.24917809 + 300 0.37432305 0.036501844 0 0.5979815 0.24715194 + 400 0.37603886 0.035350565 0 0.59940392 0.24480762 + 500 0.37617142 0.036949771 0 0.60120196 0.24862985 + 600 0.37751983 0.036484268 0 0.60275905 0.24784635 + 700 0.37787831 0.037327783 0 0.60414029 0.25060427 + 800 0.37959242 0.036206184 0 0.60558983 0.2476903 + 900 0.38019033 0.036874395 0 0.6071549 0.24984211 + 1000 0.38070666 0.037068948 0 0.60812395 0.25041936 +Loop time of 5.61598 on 1 procs for 1000 steps with 114240 atoms + +Performance: 76923.319 tau/day, 178.063 timesteps/s, 20.342 Matom-step/s +99.7% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 2.6351 | 2.6351 | 2.6351 | 0.0 | 46.92 +Neigh | 1.2994 | 1.2994 | 1.2994 | 0.0 | 23.14 +Comm | 0.26576 | 0.26576 | 0.26576 | 0.0 | 4.73 +Output | 0.0030531 | 0.0030531 | 0.0030531 | 0.0 | 0.05 +Modify | 1.3019 | 1.3019 | 1.3019 | 0.0 | 23.18 +Other | | 0.1107 | | | 1.97 + +Nlocal: 114240 ave 114240 max 114240 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 20119 ave 20119 max 20119 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 164018 ave 164018 max 164018 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 164018 +Ave neighs/atom = 1.4357318 +Neighbor list builds = 50 +Dangerous builds not checked +Total wall time: 0:00:05 diff --git a/examples/wall/log.7Feb24.wall.flow.g++.4 b/examples/wall/log.7Feb24.wall.flow.g++.4 new file mode 100644 index 0000000000..1efe7bb28e --- /dev/null +++ b/examples/wall/log.7Feb24.wall.flow.g++.4 @@ -0,0 +1,182 @@ +LAMMPS (21 Nov 2023 - Development - patch_21Nov2023-758-ge33590b2fc-modified) + using 1 OpenMP thread(s) per MPI task +variable nrun equal 1000 +variable dump_count equal 10 + +variable nwall equal 4 +variable w1 equal 67 +variable w2 equal 71 +variable w3 equal 75 +variable w4 equal 79 + +variable x_cylinder equal 20 +variable y_cylinder equal 17 +variable r_cylinder equal 4 + +variable MASS equal 1 +variable TEMP equal 0.4 +variable VFLOW equal 0.5 + +units lj +atom_style atomic + +lattice fcc 0.3 +Lattice spacing in x,y,z = 2.3712622 2.3712622 2.3712622 +region sim_box block 0 84 0 34 0 10 + +boundary p p p + +create_box 2 sim_box +Created orthogonal box = (0 0 0) to (199.18603 80.622915 23.712622) + 4 by 1 by 1 MPI processor grid +region reg_cylinder cylinder z ${x_cylinder} ${y_cylinder} ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 ${y_cylinder} ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 17 ${r_cylinder} EDGE EDGE +region reg_cylinder cylinder z 20 17 4 EDGE EDGE + +create_atoms 1 box +Created 114240 atoms + using lattice units in orthogonal box = (0 0 0) to (199.18603 80.622915 23.712622) + create_atoms CPU = 0.003 seconds + +## setup obstacle ## +group g_obst region reg_cylinder +1950 atoms in group g_obst +group g_flow subtract all g_obst +112290 atoms in group g_flow +set group g_obst type 2 +Setting atom values ... + 1950 settings made for type + +mass 1 ${MASS} +mass 1 1 +mass 2 ${MASS} +mass 2 1 + +velocity g_flow create ${TEMP} 4928459 rot yes dist gaussian +velocity g_flow create 0.4 4928459 rot yes dist gaussian +velocity g_obst set 0.0 0.0 0.0 + +pair_style lj/cut 1.122462 +pair_coeff 1 1 1.0 1.0 +pair_coeff 1 2 1.0 1.0 +pair_coeff 2 2 1.0 1.0 +pair_modify shift yes + +neighbor 0.3 bin +neigh_modify delay 0 every 20 check no + +fix 1 g_flow nve +fix 2 g_flow wall/flow x ${VFLOW} ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 ${nwall} ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 ${w1} ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 ${w2} ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 ${w3} ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 75 ${w4} +fix 2 g_flow wall/flow x 0.5 0.4 123 4 67 71 75 79 + +variable dump_every equal ${nrun}/${dump_count} +variable dump_every equal 1000/${dump_count} +variable dump_every equal 1000/10 +variable thermo_every equal ${dump_every} +variable thermo_every equal 100 +variable restart_every equal ${nrun}/10 +variable restart_every equal 1000/10 + +##### uncomment for grid aggregation ##### +#variable gr_Nx equal 42 +#variable gr_Ny equal 17 +#variable gr_Nz equal 1 +#variable gr_Nevery equal ${dump_every} +#variable gr_Nrepeat equal 1 +#variable gr_Nfreq equal ${dump_every} +#fix 3 g_flow ave/grid ${gr_Nevery} ${gr_Nrepeat} ${gr_Nfreq} ${gr_Nx} ${gr_Ny} ${gr_Nz} vx vy vz density/mass norm all ave one +#compute ct_gridId g_flow property/grid ${gr_Nx} ${gr_Ny} ${gr_Nz} id +#dump dmp_grid g_flow grid ${dump_every} grid.lammpstrj c_ct_gridId:grid:data f_3:grid:data[*] +########################################## + +#dump dmp_coord all atom ${dump_every} dump.lammpstrj + +#compute ct_Temp g_flow temp/com +#thermo_style custom step temp epair emol etotal press c_ct_Temp + +#restart ${restart_every} flow.restart + +timestep 0.005 +thermo ${thermo_every} +thermo 100 +run ${nrun} +run 1000 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- fix wall/flow command: doi:10.1177/10943420231213013 + +@Article{Pavlov-etal-IJHPCA-2024, + author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod Nikolskiy and Vladimir Stegailov}, + title = {GPU-based molecular dynamics of fluid flows: Reaching for turbulence}, + journal = {The International Journal of High Performance Computing Applications}, + year = 2024, + volume = 38, + number = 1, + pages = 34-49 +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Generated 0 of 1 mixed pair_coeff terms from geometric mixing rule +Neighbor list info ... + update: every = 20 steps, delay = 0 steps, check = no + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 1.422462 + ghost atom cutoff = 1.422462 + binsize = 0.711231, bins = 281 114 34 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair lj/cut, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 8.496 | 8.496 | 8.496 Mbytes + Step Temp E_pair E_mol TotEng Press + 0 0.39317221 0 0 0.58975315 0.11795063 + 100 0.36726398 0.045386014 0 0.59627716 0.27402111 + 200 0.37384538 0.036574547 0 0.5973377 0.24836729 + 300 0.37487455 0.036519645 0 0.59882654 0.24691726 + 400 0.37591417 0.036405755 0 0.60027207 0.24700641 + 500 0.37654714 0.037008829 0 0.60182459 0.24883444 + 600 0.3778008 0.03663706 0 0.6033333 0.24874392 + 700 0.37851338 0.036714175 0 0.60447928 0.24881829 + 800 0.37984876 0.036237049 0 0.6060052 0.24843003 + 900 0.38022763 0.036847615 0 0.60718407 0.24987198 + 1000 0.38084717 0.037139994 0 0.60840575 0.25070072 +Loop time of 2.20347 on 4 procs for 1000 steps with 114240 atoms + +Performance: 196054.093 tau/day, 453.829 timesteps/s, 51.845 Matom-step/s +95.6% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0.67927 | 0.70882 | 0.73473 | 2.4 | 32.17 +Neigh | 0.32928 | 0.34467 | 0.36084 | 2.0 | 15.64 +Comm | 0.3211 | 0.36609 | 0.40741 | 6.1 | 16.61 +Output | 0.0017748 | 0.0032465 | 0.0046508 | 2.1 | 0.15 +Modify | 0.71135 | 0.74424 | 0.76001 | 2.3 | 33.78 +Other | | 0.03641 | | | 1.65 + +Nlocal: 28560 ave 29169 max 27884 min +Histogram: 1 0 0 0 0 2 0 0 0 1 +Nghost: 6452.25 ave 6546 max 6368 min +Histogram: 1 0 0 0 2 0 0 0 0 1 +Neighs: 40893 ave 42032 max 39445 min +Histogram: 1 0 0 0 1 0 0 1 0 1 + +Total # of neighbors = 163572 +Ave neighs/atom = 1.4318277 +Neighbor list builds = 50 +Dangerous builds not checked +Total wall time: 0:00:02 diff --git a/src/.gitignore b/src/.gitignore index 1e4c5b9ddb..41f4e7b614 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1023,6 +1023,8 @@ /fix_wall_colloid.h /fix_wall_ees.cpp /fix_wall_ees.h +/fix_wall_flow.cpp +/fix_wall_flow.h /fix_wall_region_ees.cpp /fix_wall_region_ees.h /fix_wall_reflect_stochastic.cpp diff --git a/src/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp similarity index 100% rename from src/fix_wall_flow.cpp rename to src/EXTRA-FIX/fix_wall_flow.cpp diff --git a/src/fix_wall_flow.h b/src/EXTRA-FIX/fix_wall_flow.h similarity index 100% rename from src/fix_wall_flow.h rename to src/EXTRA-FIX/fix_wall_flow.h From 3358fe36d1ae7c8723dd454d00e00ff3d200ca13 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Thu, 8 Feb 2024 21:27:58 -0700 Subject: [PATCH 052/185] Fixing bugs in child arg parsing --- src/fix_deform.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 010250ed92..4b774b79d3 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -64,7 +64,7 @@ irregular(nullptr), set(nullptr) int nskip; if (utils::strmatch(style, "^deform/pressure")) { child_parameters.insert("box"); - child_styles.insert({{"pressure", 4}, {"pressure/mean", 4}, {"volume", 3}}); + child_styles.insert({{"pressure", 4}, {"pressure/mean", 4}, {"volume", 2}}); } // set defaults @@ -221,7 +221,7 @@ irregular(nullptr), set(nullptr) utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg + 1]), error); for (int i = 0; i < nskip; i++) leftover_iarg.push_back(iarg + i); iarg += nskip; - } error->all(FLERR, "Illegal fix {} command argument: {}", style, arg[iarg + 1]); + } else error->all(FLERR, "Illegal fix {} command argument: {}", style, arg[iarg + 1]); } else break; } From 022cedeff0b3b4ed6653a35b8da763372d9ceee0 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 12:08:36 +0300 Subject: [PATCH 053/185] Remove debug output --- src/EXTRA-FIX/fix_wall_flow.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 695b93aea8..6b42c34731 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -34,10 +34,8 @@ #include "math_const.h" #include -#include #include #include -#include using namespace LAMMPS_NS; using namespace FixConst; @@ -140,12 +138,6 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : { error->all(FLERR, "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); } - std::cout << "Walls:\n"; - for (auto w : walls) - { - std::cout << w << " "; - } - std::cout << std::endl; memory->grow(current_segment, atom->nmax, "WallFlow::current_segment"); atom->add_callback(Atom::GROW); From 5839b67d278485b9c4c8cdda2a76132d8da4049b Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 12:26:40 +0300 Subject: [PATCH 054/185] Simplify the code and remove redundant include --- src/EXTRA-FIX/fix_wall_flow.cpp | 11 +++++------ src/EXTRA-FIX/fix_wall_flow.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 6b42c34731..0bd9f162a2 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -114,17 +114,16 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : } return 0.0; }; - double scale = getscale(); + double scale = 0.0; + if(flowax == FlowAxis::AX_X) scale = domain->lattice->xlattice; + else if(flowax == FlowAxis::AX_Y) scale = domain->lattice->ylattice; + else if(flowax == FlowAxis::AX_Z) scale = domain->lattice->zlattice; if (narg - iarg == wallcount + 2) { if(strcmp(arg[narg - 2], "units") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); if (strcmp(arg[narg - 1], "box") == 0) scale = 1.0; - else if (strcmp(arg[narg - 1], "lattice") == 0) - { - scale = getscale(); - } - else error->all(FLERR, "Wrong fix wall/flow units command"); + else if (strcmp(arg[narg - 1], "lattice") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); } walls.resize(wallcount + 2); diff --git a/src/EXTRA-FIX/fix_wall_flow.h b/src/EXTRA-FIX/fix_wall_flow.h index ec9e4a4601..f4a4a69b1c 100644 --- a/src/EXTRA-FIX/fix_wall_flow.h +++ b/src/EXTRA-FIX/fix_wall_flow.h @@ -21,7 +21,7 @@ FixStyle(wall/flow,FixWallFlow); #define LMP_FIX_WALL_FLOW_H #include "fix.h" -#include + namespace LAMMPS_NS { class FixWallFlow : public Fix { From cba3c91b510debb4bd0e79bb5ce31d3dc5828cb2 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 12:29:10 +0300 Subject: [PATCH 055/185] Remove lambda --- src/EXTRA-FIX/fix_wall_flow.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 0bd9f162a2..0357d14773 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -101,19 +101,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : ++iarg; // parsing walls if(narg - iarg != wallcount && narg - iarg != wallcount + 2) error->all(FLERR, "Wrong fix wall/flow wall count"); - auto getscale = [&]() -> double { - switch (flowax) - { - case FlowAxis::AX_X: - return domain->lattice->xlattice; - case FlowAxis::AX_Y: - return domain->lattice->ylattice; - case FlowAxis::AX_Z: - return domain->lattice->zlattice; - default: return 0.0; - } - return 0.0; - }; + double scale = 0.0; if(flowax == FlowAxis::AX_X) scale = domain->lattice->xlattice; else if(flowax == FlowAxis::AX_Y) scale = domain->lattice->ylattice; From 6aad6177b0d52f2d6a6ad02763ef09275b657783 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 12:31:19 +0300 Subject: [PATCH 056/185] Remove accessing internal data of the Modify class --- src/EXTRA-FIX/fix_wall_flow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 0357d14773..704a8d854d 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -163,8 +163,9 @@ int FixWallFlow::setmask() void FixWallFlow::init() { int nrigid = 0; - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) nrigid++; + + for (auto ifix : modify->get_fix_list()) + if (ifix->rigid_flag) nrigid++; if (nrigid && comm->me == 0) error->warning(FLERR,"FixWallFlow is not compatible with rigid bodies"); From be742253e2d1bbf040b4b6a4069a217ec7335caa Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 13:05:45 +0300 Subject: [PATCH 057/185] Fix bug with the masses of the atoms --- src/EXTRA-FIX/fix_wall_flow.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 704a8d854d..bbd5d39ce3 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -205,7 +205,13 @@ void FixWallFlow::generate_velocity(int atom_i) { const int newton_iteration_count = 10; double *vel = atom->v[atom_i]; - double mass = atom->mass[atom->type[atom_i]]; + + double *prmass = atom->rmass; + double *pmass = atom->mass; + double mass = 0.0; + if(prmass) mass = prmass[atom_i]; + else mass = pmass[atom->type[atom_i]]; + const double gamma = 1.0 / std::sqrt(2.0 * kT / mass); double delta = gamma * flowvel; From c7831b29c0fb8b1f43ba27f70b0621e606710f84 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Fri, 9 Feb 2024 13:28:35 +0300 Subject: [PATCH 058/185] Fix formatting issues --- src/EXTRA-FIX/fix_wall_flow.cpp | 173 ++++++++++++++-------------- src/EXTRA-FIX/fix_wall_flow.h | 2 +- src/KOKKOS/fix_wall_flow_kokkos.cpp | 122 ++++++++------------ 3 files changed, 138 insertions(+), 159 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index bbd5d39ce3..bc2ddcd137 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -23,18 +22,18 @@ #include "comm.h" #include "domain.h" #include "error.h" +#include "force.h" #include "input.h" #include "lattice.h" +#include "math_const.h" +#include "memory.h" #include "modify.h" +#include "random_mars.h" #include "update.h" #include "variable.h" -#include "random_mars.h" -#include "memory.h" -#include "force.h" -#include "math_const.h" -#include #include +#include #include using namespace LAMMPS_NS; @@ -43,24 +42,21 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ static const char cite_fix_wall_flow_c[] = - "fix wall/flow command: doi:10.1177/10943420231213013\n\n" - "@Article{Pavlov-etal-IJHPCA-2024,\n" - " author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod Nikolskiy and Vladimir Stegailov},\n" - " title = {GPU-based molecular dynamics of fluid flows: Reaching for turbulence},\n" - " journal = {The International Journal of High Performance Computing Applications},\n" - " year = 2024,\n" - " volume = 38,\n" - " number = 1,\n" - " pages = 34-49\n" - "}\n\n"; + "fix wall/flow command: doi:10.1177/10943420231213013\n\n" + "@Article{Pavlov-etal-IJHPCA-2024,\n" + " author = {Daniil Pavlov and Vladislav Galigerov and Daniil Kolotinskii and Vsevolod " + "Nikolskiy and Vladimir Stegailov},\n" + " title = {GPU-based molecular dynamics of fluid flows: Reaching for turbulence},\n" + " journal = {The International Journal of High Performance Computing Applications},\n" + " year = 2024,\n" + " volume = 38,\n" + " number = 1,\n" + " pages = 34-49\n" + "}\n\n"; FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), - flowax(FlowAxis::AX_X), - flowvel(0.0), - flowdir(0), - rndseed(0), - current_segment(nullptr) + Fix(lmp, narg, arg), flowax(FlowAxis::AX_X), flowvel(0.0), flowdir(0), rndseed(0), + current_segment(nullptr) { if (lmp->citeme) lmp->citeme->add(cite_fix_wall_flow_c); if (narg < 9) utils::missing_cmd_args(FLERR, "fix wall/flow", error); @@ -70,60 +66,74 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : int iarg = 3; // parsing axis - if (strcmp(arg[iarg], "x") == 0) flowax = FlowAxis::AX_X; - else if (strcmp(arg[iarg],"y") == 0) flowax = FlowAxis::AX_Y; - else if (strcmp(arg[iarg],"z") == 0) flowax = FlowAxis::AX_Z; - else error->all(FLERR,"Illegal fix wall/flow argument: axis must by x or y or z, but {} specified", arg[iarg]); + if (strcmp(arg[iarg], "x") == 0) + flowax = FlowAxis::AX_X; + else if (strcmp(arg[iarg], "y") == 0) + flowax = FlowAxis::AX_Y; + else if (strcmp(arg[iarg], "z") == 0) + flowax = FlowAxis::AX_Z; + else + error->all(FLERR, "Illegal fix wall/flow argument: axis must by x or y or z, but {} specified", + arg[iarg]); ++iarg; // parsing velocity - flowvel = utils::numeric(FLERR,arg[iarg],do_abort,lmp); - if (flowvel == 0.0) error->all(FLERR,"Illegal fix wall/flow argument: velocity cannot be 0"); - if (flowvel > 0.0) flowdir = 1; - else flowdir = -1; - if(flowdir < 0) error->all(FLERR, "Illegal fix wall/flow argument: negative direction is not supported yet"); + flowvel = utils::numeric(FLERR, arg[iarg], do_abort, lmp); + if (flowvel == 0.0) error->all(FLERR, "Illegal fix wall/flow argument: velocity cannot be 0"); + if (flowvel > 0.0) + flowdir = 1; + else + flowdir = -1; + if (flowdir < 0) + error->all(FLERR, "Illegal fix wall/flow argument: negative direction is not supported yet"); ++iarg; // parsing temperature - double flowtemp = utils::numeric(FLERR,arg[iarg],do_abort,lmp); + double flowtemp = utils::numeric(FLERR, arg[iarg], do_abort, lmp); kT = lmp->force->boltz * flowtemp / force->mvv2e; ++iarg; // parsing seed - rndseed = utils::inumeric(FLERR, arg[iarg],do_abort,lmp); - if(rndseed <= 0) error->all(FLERR, "Illegal fix wall/flow argument: random seed must be positive integer"); + rndseed = utils::inumeric(FLERR, arg[iarg], do_abort, lmp); + if (rndseed <= 0) + error->all(FLERR, "Illegal fix wall/flow argument: random seed must be positive integer"); ++iarg; // parsing wall count - int wallcount = utils::inumeric(FLERR,arg[iarg],do_abort,lmp); - if(wallcount <= 0) error->all(FLERR,"Illegal fix wall/flow argument: wall count must be positive integer"); + int wallcount = utils::inumeric(FLERR, arg[iarg], do_abort, lmp); + if (wallcount <= 0) + error->all(FLERR, "Illegal fix wall/flow argument: wall count must be positive integer"); ++iarg; // parsing walls - if(narg - iarg != wallcount && narg - iarg != wallcount + 2) error->all(FLERR, "Wrong fix wall/flow wall count"); + if (narg - iarg != wallcount && narg - iarg != wallcount + 2) + error->all(FLERR, "Wrong fix wall/flow wall count"); double scale = 0.0; - if(flowax == FlowAxis::AX_X) scale = domain->lattice->xlattice; - else if(flowax == FlowAxis::AX_Y) scale = domain->lattice->ylattice; - else if(flowax == FlowAxis::AX_Z) scale = domain->lattice->zlattice; + if (flowax == FlowAxis::AX_X) + scale = domain->lattice->xlattice; + else if (flowax == FlowAxis::AX_Y) + scale = domain->lattice->ylattice; + else if (flowax == FlowAxis::AX_Z) + scale = domain->lattice->zlattice; - if (narg - iarg == wallcount + 2) - { - if(strcmp(arg[narg - 2], "units") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); - if (strcmp(arg[narg - 1], "box") == 0) scale = 1.0; - else if (strcmp(arg[narg - 1], "lattice") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); + if (narg - iarg == wallcount + 2) { + if (strcmp(arg[narg - 2], "units") != 0) error->all(FLERR, "Wrong fix wall/flow units command"); + if (strcmp(arg[narg - 1], "box") == 0) + scale = 1.0; + else if (strcmp(arg[narg - 1], "lattice") != 0) + error->all(FLERR, "Wrong fix wall/flow units command"); } walls.resize(wallcount + 2); walls.front() = domain->boxlo[flowax]; - for (size_t w = 1; w <= wallcount; ++w, ++iarg) - { - walls[w] = utils::numeric(FLERR,arg[iarg],do_abort,lmp) * scale; + for (size_t w = 1; w <= wallcount; ++w, ++iarg) { + walls[w] = utils::numeric(FLERR, arg[iarg], do_abort, lmp) * scale; } walls.back() = domain->boxhi[flowax]; - if (!std::is_sorted(walls.begin(), walls.end(), std::less_equal())) - { - error->all(FLERR, "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); + if (!std::is_sorted(walls.begin(), walls.end(), std::less_equal())) { + error->all(FLERR, + "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); } memory->grow(current_segment, atom->nmax, "WallFlow::current_segment"); @@ -133,7 +143,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : maxexchange = 1; random = new RanMars(lmp, rndseed + comm->me); - } +} /* ---------------------------------------------------------------------- */ @@ -168,10 +178,9 @@ void FixWallFlow::init() if (ifix->rigid_flag) nrigid++; if (nrigid && comm->me == 0) - error->warning(FLERR,"FixWallFlow is not compatible with rigid bodies"); + error->warning(FLERR, "FixWallFlow is not compatible with rigid bodies"); - for (int i = 0; i < atom->nlocal; ++i) - { + for (int i = 0; i < atom->nlocal; ++i) { double pos = atom->x[i][flowax]; current_segment[i] = compute_current_segment(pos); } @@ -185,18 +194,13 @@ void FixWallFlow::end_of_step() int *mask = atom->mask; int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; ++i) - { - if (mask[i] & groupbit) - { - double pos = x[i][flowax]; - int prev_segment = current_segment[i]; - current_segment[i] = compute_current_segment(pos); + for (int i = 0; i < nlocal; ++i) { + if (mask[i] & groupbit) { + double pos = x[i][flowax]; + int prev_segment = current_segment[i]; + current_segment[i] = compute_current_segment(pos); - if (prev_segment != current_segment[i]) - { - generate_velocity(i); - } + if (prev_segment != current_segment[i]) { generate_velocity(i); } } } } @@ -209,31 +213,32 @@ void FixWallFlow::generate_velocity(int atom_i) double *prmass = atom->rmass; double *pmass = atom->mass; double mass = 0.0; - if(prmass) mass = prmass[atom_i]; - else mass = pmass[atom->type[atom_i]]; + if (prmass) + mass = prmass[atom_i]; + else + mass = pmass[atom->type[atom_i]]; const double gamma = 1.0 / std::sqrt(2.0 * kT / mass); double delta = gamma * flowvel; - const double edd = std::exp(-delta*delta) / MathConst::MY_PIS + delta * std::erf(delta); + const double edd = std::exp(-delta * delta) / MathConst::MY_PIS + delta * std::erf(delta); const double probability_threshold = 0.5f * (1.f + delta / edd); double direction = 1.0; - if (random->uniform() > probability_threshold) - { - delta = -delta; - direction = -direction; + if (random->uniform() > probability_threshold) { + delta = -delta; + direction = -direction; } const double xi_0 = random->uniform(); const double F_inf = edd + delta; const double xi = xi_0 * F_inf; - const double x_0 = (std::sqrt(delta*delta + 2) - delta) * 0.5; + const double x_0 = (std::sqrt(delta * delta + 2) - delta) * 0.5; double x = x_0; - for (int i = 0; i < newton_iteration_count; ++i) - { - x -= (std::exp(x*x) * MathConst::MY_PIS * (xi - delta * std::erfc(x)) - 1.0) / (x + delta) * 0.5; + for (int i = 0; i < newton_iteration_count; ++i) { + x -= (std::exp(x * x) * MathConst::MY_PIS * (xi - delta * std::erfc(x)) - 1.0) / (x + delta) * + 0.5; } const double nu = x + delta; @@ -247,14 +252,10 @@ void FixWallFlow::generate_velocity(int atom_i) int FixWallFlow::compute_current_segment(double pos) const { int result = 0; - for (; result < walls.size()-1; ++result) - { - if (pos >= walls[result] && pos < walls[result + 1]) - { - return result; - } + for (; result < walls.size() - 1; ++result) { + if (pos >= walls[result] && pos < walls[result + 1]) { return result; } } - return -1; // -1 is "out of box" region + return -1; // -1 is "out of box" region } void FixWallFlow::grow_arrays(int nmax) @@ -267,13 +268,13 @@ void FixWallFlow::copy_arrays(int i, int j, int) current_segment[j] = current_segment[i]; } -int FixWallFlow::pack_exchange(int i, double* buf) +int FixWallFlow::pack_exchange(int i, double *buf) { buf[0] = static_cast(current_segment[i]); return 1; } -int FixWallFlow::unpack_exchange(int i, double* buf) +int FixWallFlow::unpack_exchange(int i, double *buf) { current_segment[i] = static_cast(buf[0]); return 1; diff --git a/src/EXTRA-FIX/fix_wall_flow.h b/src/EXTRA-FIX/fix_wall_flow.h index f4a4a69b1c..8e16a850b1 100644 --- a/src/EXTRA-FIX/fix_wall_flow.h +++ b/src/EXTRA-FIX/fix_wall_flow.h @@ -26,7 +26,7 @@ namespace LAMMPS_NS { class FixWallFlow : public Fix { public: - enum FlowAxis {AX_X = 0, AX_Y = 1, AX_Z = 2}; + enum FlowAxis { AX_X = 0, AX_Y = 1, AX_Z = 2 }; FixWallFlow(class LAMMPS *, int, char **); ~FixWallFlow() override; diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index a143578fdc..f9d11efe81 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -19,18 +18,16 @@ #include "fix_wall_flow_kokkos.h" #include "atom_kokkos.h" -#include "memory_kokkos.h" -#include "math_const.h" #include "atom_masks.h" #include "force.h" +#include "math_const.h" +#include "memory_kokkos.h" #include -// clang-format off - using namespace LAMMPS_NS; -template +template FixWallFlowKokkos::FixWallFlowKokkos(LAMMPS *lmp, int narg, char **arg) : FixWallFlow(lmp, narg, arg), rand_pool(rndseed + comm->me) { @@ -47,22 +44,17 @@ FixWallFlowKokkos::FixWallFlowKokkos(LAMMPS *lmp, int narg, char **a d_walls = d_walls_t("FixWallFlowKokkos::walls", walls.size()); auto h_walls = Kokkos::create_mirror_view(d_walls); - for (int i = 0; i < walls.size(); ++i) - { - h_walls(i) = walls[i]; - } + for (int i = 0; i < walls.size(); ++i) { h_walls(i) = walls[i]; } Kokkos::deep_copy(d_walls, h_walls); } -template -FixWallFlowKokkos::~FixWallFlowKokkos() +template FixWallFlowKokkos::~FixWallFlowKokkos() { if (copymode) return; memoryKK->destroy_kokkos(k_current_segment, current_segment); } -template -void FixWallFlowKokkos::init() +template void FixWallFlowKokkos::init() { atomKK->sync(execution_space, datamask_read); k_current_segment.template sync(); @@ -83,8 +75,7 @@ KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWall d_current_segment(i) = compute_current_segment_kk(pos); } -template -void FixWallFlowKokkos::end_of_step() +template void FixWallFlowKokkos::end_of_step() { atomKK->sync(execution_space, datamask_read); k_current_segment.template sync(); @@ -111,26 +102,20 @@ void FixWallFlowKokkos::end_of_step() template template -KOKKOS_INLINE_FUNCTION -void FixWallFlowKokkos::operator()(TagFixWallFlowEndOfStep, +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWallFlowEndOfStep, const int &atom_i) const { - if (d_mask[atom_i] & groupbit) - { + if (d_mask[atom_i] & groupbit) { double pos = d_x(atom_i, flowax); int prev_segment = d_current_segment(atom_i); d_current_segment(atom_i) = compute_current_segment_kk(pos); - if (prev_segment != d_current_segment(atom_i)) - { - generate_velocity_kk(atom_i); - } + if (prev_segment != d_current_segment(atom_i)) { generate_velocity_kk(atom_i); } } } -template -template -KOKKOS_INLINE_FUNCTION -void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const +template +template +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const { const int newton_iteration_count = 10; double mass = get_mass(MTag(), atom_i); @@ -163,15 +148,17 @@ void FixWallFlowKokkos::generate_velocity_kk(int atom_i) const const double v = nu / gamma; d_v(atom_i, flowax) = v * direction; - d_v(atom_i, (flowax + 1) % 3) = /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); - d_v(atom_i, (flowax + 2) % 3) = /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); + d_v(atom_i, (flowax + 1) % 3) = + /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); + d_v(atom_i, (flowax + 2) % 3) = + /*random->gaussian()*/ rand_gen.normal() / (gamma * MathConst::MY_SQRT2); rand_pool.free_state(rand_gen); } template -KOKKOS_INLINE_FUNCTION -int FixWallFlowKokkos::compute_current_segment_kk(double pos) const +KOKKOS_INLINE_FUNCTION int +FixWallFlowKokkos::compute_current_segment_kk(double pos) const { int result = 0; for (; result < d_walls.extent(0) - 1; ++result) { @@ -180,9 +167,7 @@ int FixWallFlowKokkos::compute_current_segment_kk(double pos) const return -1; // -1 is "out of box" region } - -template -void FixWallFlowKokkos::grow_arrays(int nmax) +template void FixWallFlowKokkos::grow_arrays(int nmax) { k_current_segment.template sync(); memoryKK->grow_kokkos(k_current_segment, current_segment, nmax, "WallFlowKK::current_segment"); @@ -192,8 +177,7 @@ void FixWallFlowKokkos::grow_arrays(int nmax) h_current_segment = k_current_segment.template view(); } -template -void FixWallFlowKokkos::copy_arrays(int i, int j, int) +template void FixWallFlowKokkos::copy_arrays(int i, int j, int) { k_current_segment.template sync(); h_current_segment(j) = h_current_segment(i); @@ -204,7 +188,7 @@ void FixWallFlowKokkos::copy_arrays(int i, int j, int) sort local atom-based arrays ------------------------------------------------------------------------- */ -template +template void FixWallFlowKokkos::sort_kokkos(Kokkos::BinSort &Sorter) { // always sort on the device @@ -216,33 +200,31 @@ void FixWallFlowKokkos::sort_kokkos(Kokkos::BinSort -int FixWallFlowKokkos::pack_exchange(int i, double *buf) +template int FixWallFlowKokkos::pack_exchange(int i, double *buf) { k_current_segment.sync_host(); buf[0] = static_cast(h_current_segment(i)); return 1; } -template -KOKKOS_INLINE_FUNCTION -void FixWallFlowKokkos::operator()(TagFixWallFlowPackExchange, const int &mysend) const { +template +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWallFlowPackExchange, + const int &mysend) const +{ const int send_i = d_sendlist(mysend); const int segment = d_current_segment(send_i); d_buf(mysend) = static_cast(segment); const int copy_i = d_copylist(mysend); - if (copy_i > -1) { - d_current_segment(send_i) = d_current_segment(copy_i); - } + if (copy_i > -1) { d_current_segment(send_i) = d_current_segment(copy_i); } } template -int FixWallFlowKokkos::pack_exchange_kokkos( - const int &nsend, DAT::tdual_xfloat_2d &k_buf, - DAT::tdual_int_1d k_sendlist, - DAT::tdual_int_1d k_copylist, - ExecutionSpace space) +int FixWallFlowKokkos::pack_exchange_kokkos(const int &nsend, + DAT::tdual_xfloat_2d &k_buf, + DAT::tdual_int_1d k_sendlist, + DAT::tdual_int_1d k_copylist, + ExecutionSpace space) { k_current_segment.template sync(); @@ -253,13 +235,13 @@ int FixWallFlowKokkos::pack_exchange_kokkos( d_sendlist = k_sendlist.view(); d_copylist = k_copylist.view(); - d_buf = typename ArrayTypes::t_xfloat_1d_um( - k_buf.template view().data(), - k_buf.extent(0)*k_buf.extent(1)); + d_buf = typename ArrayTypes::t_xfloat_1d_um(k_buf.template view().data(), + k_buf.extent(0) * k_buf.extent(1)); copymode = 1; - Kokkos::parallel_for(Kokkos::RangePolicy(0, nsend), *this); + Kokkos::parallel_for(Kokkos::RangePolicy(0, nsend), + *this); copymode = 0; @@ -269,8 +251,7 @@ int FixWallFlowKokkos::pack_exchange_kokkos( return nsend; } -template -int FixWallFlowKokkos::unpack_exchange(int i, double *buf) +template int FixWallFlowKokkos::unpack_exchange(int i, double *buf) { k_current_segment.sync_host(); h_current_segment(i) = static_cast(buf[0]); @@ -278,30 +259,27 @@ int FixWallFlowKokkos::unpack_exchange(int i, double *buf) return 1; } -template -KOKKOS_INLINE_FUNCTION -void FixWallFlowKokkos::operator()(TagFixWallFlowUnpackExchange, const int &i) const +template +KOKKOS_INLINE_FUNCTION void FixWallFlowKokkos::operator()(TagFixWallFlowUnpackExchange, + const int &i) const { int index = d_indices(i); - if (index > -1) { - d_current_segment(index) = static_cast(d_buf(i)); - } + if (index > -1) { d_current_segment(index) = static_cast(d_buf(i)); } } template -void FixWallFlowKokkos::unpack_exchange_kokkos( - DAT::tdual_xfloat_2d &k_buf, - DAT::tdual_int_1d &k_indices, int nrecv, - int /*nrecv1*/, int /*nextrarecv1*/, - ExecutionSpace space) +void FixWallFlowKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf, + DAT::tdual_int_1d &k_indices, int nrecv, + int /*nrecv1*/, int /*nextrarecv1*/, + ExecutionSpace space) { - d_buf = typename ArrayTypes::t_xfloat_1d_um( - k_buf.template view().data(), - k_buf.extent(0)*k_buf.extent(1)); + d_buf = typename ArrayTypes::t_xfloat_1d_um(k_buf.template view().data(), + k_buf.extent(0) * k_buf.extent(1)); d_indices = k_indices.view(); copymode = 1; - Kokkos::parallel_for(Kokkos::RangePolicy(0,nrecv),*this); + Kokkos::parallel_for(Kokkos::RangePolicy(0, nrecv), + *this); copymode = 0; k_current_segment.template modify(); From 1edec590bbb303f8c7adade7205a1a515e6bee16 Mon Sep 17 00:00:00 2001 From: Ludwig Ahrens Date: Mon, 19 Feb 2024 15:01:51 +0100 Subject: [PATCH 059/185] Logs for eta mix example --- .../madelung/log.19Feb2024.eta.g++.1 | 138 +++++++++++++++++ .../madelung/log.19Feb2024.eta_cg.g++.1 | 139 ++++++++++++++++++ .../madelung/log.19Feb2024.eta_mix.g++.1 | 138 +++++++++++++++++ 3 files changed, 415 insertions(+) create mode 100644 examples/PACKAGES/electrode/madelung/log.19Feb2024.eta.g++.1 create mode 100644 examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_cg.g++.1 create mode 100644 examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_mix.g++.1 diff --git a/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta.g++.1 b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta.g++.1 new file mode 100644 index 0000000000..daf0563799 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta.g++.1 @@ -0,0 +1,138 @@ +LAMMPS (21 Nov 2023 - Development - patch_21Nov2023-668-g5b6c0c6b56) + using 1 OpenMP thread(s) per MPI task +boundary p p f +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc + +include "settings.mod" # styles, computes, groups and fixes +# set boundary in main script because ffield is periodic +units real +# distribute electrode atoms among all processors: +if "$(extract_setting(world_size) % 2) == 0" then "processors * * 2" + +atom_style full +pair_style lj/cut/coul/long 12 + +read_data "data.au-elyt" +Reading data file ... + orthogonal box = (0 0 -10) to (1 1 10) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 4 atoms +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0 0 0 + special bond factors coul: 0 0 0 + 0 = max # of 1-2 neighbors + 0 = max # of 1-3 neighbors + 0 = max # of 1-4 neighbors + 1 = max # of special neighbors + special bonds CPU = 0.000 seconds + read_data CPU = 0.003 seconds + +group bot type 1 +1 atoms in group bot +group top type 2 +1 atoms in group top + +# get electrode charges +variable q atom q +compute qbot bot reduce sum v_q +compute qtop top reduce sum v_q + +compute compute_pe all pe +variable vpe equal c_compute_pe +variable charge equal c_qtop +fix fxprint all print 1 "${vpe}, ${charge}" file "out.csv" + +thermo_style custom step pe c_qbot c_qtop +fix feta all property/atom d_eta ghost on +set group bot d_eta 2.0 +Setting atom values ... + 1 settings made for d_eta +set group top d_eta 2.0 +Setting atom values ... + 1 settings made for d_eta +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta write_inv inv.csv write_vec vec.csv +2 atoms in group conp_group + +run 0 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- fix electrode command: + +@article{Ahrens2022 +author = {Ahrens-Iwers, Ludwig J.V. and Janssen, Mahijs and Tee, Shern R. and Mei{\ss}ner, Robert H.}, +doi = {10.1063/5.0099239}, +title = {{ELECTRODE: An electrochemistry package for LAMMPS}}, +journal = {The Journal of Chemical Physics}, +year = {2022} +volume = {157}, +pages = {084801}, +} +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +WARNING: No fixes with time integration, atoms won't move (src/verlet.cpp:60) +Ewald/electrode initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:342) +WARNING: For better accuracy use 'pair_modify table 0' (src/kspace.cpp:365) + G vector (1/distance) = 0.32261103 + estimated absolute RMS force accuracy = 3.8272011e-06 + estimated relative force accuracy = 1.1525502e-08 + KSpace vectors: actual max1d max3d = 52 50 515150 + kxmax kymax kzmax = 1 1 50 +Generated 3 of 3 mixed pair_coeff terms from geometric mixing rule +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 14 + ghost atom cutoff = 14 + binsize = 7, bins = 1 1 3 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair lj/cut/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d + bin: standard + (2) fix electrode/conp, perpetual, copy from (1) + attributes: half, newton on + pair build: copy + stencil: none + bin: none +WARNING: Proc sub-domain size < neighbor skin, could lead to lost atoms (src/domain.cpp:965) +139.943964815502, 0.279214485147238 +Per MPI rank memory allocation (min/avg/max) = 144.2 | 144.2 | 144.2 Mbytes + Step PotEng c_qbot c_qtop + 0 139.94396 -0.27921449 0.27921449 +Loop time of 2.191e-06 on 1 procs for 0 steps with 4 atoms + +91.3% 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 +Bond | 0 | 0 | 0 | 0.0 | 0.00 +Kspace | 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 | | 2.191e-06 | | |100.00 + +Nlocal: 4 ave 4 max 4 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 3596 ave 3596 max 3596 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 4790 ave 4790 max 4790 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 4790 +Ave neighs/atom = 1197.5 +Ave special neighs/atom = 0 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 diff --git a/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_cg.g++.1 b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_cg.g++.1 new file mode 100644 index 0000000000..edb2e434e6 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_cg.g++.1 @@ -0,0 +1,139 @@ +LAMMPS (21 Nov 2023 - Development - patch_21Nov2023-668-g5b6c0c6b56) + using 1 OpenMP thread(s) per MPI task +boundary p p f +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc + +include "settings.mod" # styles, computes, groups and fixes +# set boundary in main script because ffield is periodic +units real +# distribute electrode atoms among all processors: +if "$(extract_setting(world_size) % 2) == 0" then "processors * * 2" + +atom_style full +pair_style lj/cut/coul/long 12 + +read_data "data.au-elyt" +Reading data file ... + orthogonal box = (0 0 -10) to (1 1 10) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 4 atoms +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0 0 0 + special bond factors coul: 0 0 0 + 0 = max # of 1-2 neighbors + 0 = max # of 1-3 neighbors + 0 = max # of 1-4 neighbors + 1 = max # of special neighbors + special bonds CPU = 0.000 seconds + read_data CPU = 0.003 seconds + +group bot type 1 +1 atoms in group bot +group top type 2 +1 atoms in group top + +# get electrode charges +variable q atom q +compute qbot bot reduce sum v_q +compute qtop top reduce sum v_q + +compute compute_pe all pe +variable vpe equal c_compute_pe +variable charge equal c_qtop +fix fxprint all print 1 "${vpe}, ${charge}" file "out.csv" + +thermo_style custom step pe c_qbot c_qtop +fix feta all property/atom d_eta ghost on +set group bot d_eta 0.5 +Setting atom values ... + 1 settings made for d_eta +set group top d_eta 3.0 +Setting atom values ... + 1 settings made for d_eta +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta algo cg 1e-6 +2 atoms in group conp_group + +run 0 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- fix electrode command: + +@article{Ahrens2022 +author = {Ahrens-Iwers, Ludwig J.V. and Janssen, Mahijs and Tee, Shern R. and Mei{\ss}ner, Robert H.}, +doi = {10.1063/5.0099239}, +title = {{ELECTRODE: An electrochemistry package for LAMMPS}}, +journal = {The Journal of Chemical Physics}, +year = {2022} +volume = {157}, +pages = {084801}, +} +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +WARNING: No fixes with time integration, atoms won't move (src/verlet.cpp:60) +Ewald/electrode initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:342) +WARNING: For better accuracy use 'pair_modify table 0' (src/kspace.cpp:365) + G vector (1/distance) = 0.32261103 + estimated absolute RMS force accuracy = 3.8272011e-06 + estimated relative force accuracy = 1.1525502e-08 + KSpace vectors: actual max1d max3d = 52 50 515150 + kxmax kymax kzmax = 1 1 50 +Generated 3 of 3 mixed pair_coeff terms from geometric mixing rule +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 14 + ghost atom cutoff = 14 + binsize = 7, bins = 1 1 3 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair lj/cut/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d + bin: standard + (2) fix electrode/conp, perpetual, copy from (1) + attributes: half, newton on + pair build: copy + stencil: none + bin: none +WARNING: Proc sub-domain size < neighbor skin, could lead to lost atoms (src/domain.cpp:965) +165.519373910316, 0.29521534552818 +Per MPI rank memory allocation (min/avg/max) = 144.2 | 144.2 | 144.2 Mbytes + Step PotEng c_qbot c_qtop + 0 165.51937 -0.29521535 0.29521535 +Loop time of 2.797e-06 on 1 procs for 0 steps with 4 atoms + +71.5% 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 +Bond | 0 | 0 | 0 | 0.0 | 0.00 +Kspace | 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 | | 2.797e-06 | | |100.00 + +Nlocal: 4 ave 4 max 4 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 3596 ave 3596 max 3596 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 4790 ave 4790 max 4790 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 4790 +Ave neighs/atom = 1197.5 +Ave special neighs/atom = 0 +Neighbor list builds = 0 +Dangerous builds = 0 + +Average conjugate gradient steps: 1 +Total wall time: 0:00:00 diff --git a/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_mix.g++.1 b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_mix.g++.1 new file mode 100644 index 0000000000..51eda0d870 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_mix.g++.1 @@ -0,0 +1,138 @@ +LAMMPS (21 Nov 2023 - Development - patch_21Nov2023-668-g5b6c0c6b56) + using 1 OpenMP thread(s) per MPI task +boundary p p f +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc + +include "settings.mod" # styles, computes, groups and fixes +# set boundary in main script because ffield is periodic +units real +# distribute electrode atoms among all processors: +if "$(extract_setting(world_size) % 2) == 0" then "processors * * 2" + +atom_style full +pair_style lj/cut/coul/long 12 + +read_data "data.au-elyt" +Reading data file ... + orthogonal box = (0 0 -10) to (1 1 10) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 4 atoms +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0 0 0 + special bond factors coul: 0 0 0 + 0 = max # of 1-2 neighbors + 0 = max # of 1-3 neighbors + 0 = max # of 1-4 neighbors + 1 = max # of special neighbors + special bonds CPU = 0.000 seconds + read_data CPU = 0.003 seconds + +group bot type 1 +1 atoms in group bot +group top type 2 +1 atoms in group top + +# get electrode charges +variable q atom q +compute qbot bot reduce sum v_q +compute qtop top reduce sum v_q + +compute compute_pe all pe +variable vpe equal c_compute_pe +variable charge equal c_qtop +fix fxprint all print 1 "${vpe}, ${charge}" file "out.csv" + +thermo_style custom step pe c_qbot c_qtop +fix feta all property/atom d_eta ghost on +set group bot d_eta 0.5 +Setting atom values ... + 1 settings made for d_eta +set group top d_eta 3.0 +Setting atom values ... + 1 settings made for d_eta +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta write_inv inv.csv write_vec vec.csv +2 atoms in group conp_group + +run 0 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- fix electrode command: + +@article{Ahrens2022 +author = {Ahrens-Iwers, Ludwig J.V. and Janssen, Mahijs and Tee, Shern R. and Mei{\ss}ner, Robert H.}, +doi = {10.1063/5.0099239}, +title = {{ELECTRODE: An electrochemistry package for LAMMPS}}, +journal = {The Journal of Chemical Physics}, +year = {2022} +volume = {157}, +pages = {084801}, +} +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +WARNING: No fixes with time integration, atoms won't move (src/verlet.cpp:60) +Ewald/electrode initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:342) +WARNING: For better accuracy use 'pair_modify table 0' (src/kspace.cpp:365) + G vector (1/distance) = 0.32261103 + estimated absolute RMS force accuracy = 3.8272011e-06 + estimated relative force accuracy = 1.1525502e-08 + KSpace vectors: actual max1d max3d = 52 50 515150 + kxmax kymax kzmax = 1 1 50 +Generated 3 of 3 mixed pair_coeff terms from geometric mixing rule +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 14 + ghost atom cutoff = 14 + binsize = 7, bins = 1 1 3 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair lj/cut/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d + bin: standard + (2) fix electrode/conp, perpetual, copy from (1) + attributes: half, newton on + pair build: copy + stencil: none + bin: none +WARNING: Proc sub-domain size < neighbor skin, could lead to lost atoms (src/domain.cpp:965) +165.519373910316, 0.295215345528172 +Per MPI rank memory allocation (min/avg/max) = 144.2 | 144.2 | 144.2 Mbytes + Step PotEng c_qbot c_qtop + 0 165.51937 -0.29521535 0.29521535 +Loop time of 2.18e-06 on 1 procs for 0 steps with 4 atoms + +91.7% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0 | 0 | 0 | 0.0 | 0.00 +Bond | 0 | 0 | 0 | 0.0 | 0.00 +Kspace | 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 | | 2.18e-06 | | |100.00 + +Nlocal: 4 ave 4 max 4 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 3596 ave 3596 max 3596 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 4790 ave 4790 max 4790 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 4790 +Ave neighs/atom = 1197.5 +Ave special neighs/atom = 0 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 From fb1e6610edbdf63702d81a720f3c94eb41926f2f Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Mon, 19 Feb 2024 10:36:15 -0700 Subject: [PATCH 060/185] edits of doc page for clarity --- doc/src/fix_wall_flow.rst | 118 ++++++++++++++++++++------------ src/EXTRA-FIX/fix_wall_flow.cpp | 15 +++- src/EXTRA-FIX/fix_wall_flow.h | 1 + 3 files changed, 89 insertions(+), 45 deletions(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index 464021ff52..5fc9f5367c 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -11,24 +11,23 @@ Syntax .. code-block:: LAMMPS - fix ID group-ID wall/flow ax vf T seed N coords ... keyword value + fix ID group-ID wall/flow axis vflow T seed N coords ... keyword value * ID, group-ID are documented in :doc:`fix ` command * wall/flow = style name of this fix command -* ax = flow axis (*x*, *y*, or *z* character) -* vf = *ax* component of generated flow velocity +* axis = flow axis (*x*, *y*, or *z*) +* vflow = generated flow velocity in *axis* direction (velocity units) * T = flow temperature (temperature units) * seed = random seed for stochasticity (positive integer) -* N = number of walls (positive integer) -* coords = set of N wall coordinates (box units) along *ax* axis arranged in ascending order. Note that an additional implicit wall is introduced at the boundary of the simulation domain, so the resulting system always has N+1 walls. - +* N = number of walls +* coords = list of N wall positions along the *axis* direction in ascending order (distance units) * zero or more keyword/value pairs may be appended * keyword = *units* .. parsed-literal:: *units* value = *lattice* or *box* - *lattice* = the wall positions are defined in lattice units + *lattice* = wall positions are defined in lattice units *box* = the wall positions are defined in simulation box units Examples @@ -36,65 +35,96 @@ Examples .. code-block:: LAMMPS - fix 1 g_flow wall/flow x ${VFLOW} ${TEMP} 123 ${nwall} ${w1} ${w2} ${w3} ${w4} - fix 2 all wall/flow 0.4 0.2 3 1 400 + fix 1 all wall/flow x 0.4 1.5 593894 4 2.0 4.0 6.0 8.0 Description """"""""""" .. versionadded:: TBD -This fix implements flow boundary conditions (FBC) introduced in :ref:`(Pavlov1) ` and :ref:`(Pavlov2) `. -The goal is to generate a stationary flow with a shifted Maxwell velocity distribution: +This fix implements flow boundary conditions (FBC) introduced in +:ref:`(Pavlov1) ` and :ref:`(Pavlov2) `. +The goal is to generate a stationary flow with a shifted Maxwell +velocity distribution: .. math:: - f_z(v_z) \propto \exp{\left(-\frac{m (v_z-v_{\text{flow}})^2}{2 k T}\right)} + f_a(v_a) \propto \exp{\left(-\frac{m (v_a-v_{\text{flow}})^2}{2 kB T}\right)} -This is achieved by reassigning the velocity of each particle that passes a wall. -Such reassigning represents an emission of a new particle into the system with -simultaneous removal of a particle with the same position. -The velocity components parallel to the wall are re-assigned according -to the Maxwell velocity distribution. The perpendicular component is assigned -according to the following velocity distribution: +where :math:`v_a` is the component of velocity along the specified +*axis* argument (a = x,y,z), :math:`v_{\text{flow}}` is the flow +velocity specified as the *vflow* argument, *T* is the specified flow +temperature, *m* is the particle mass, and *kB* is the Boltzmann +constant. + +This is achieved by defining a series of *N* transparent walls along +the flow *axis* direction. Each wall is at the specified position +listed in the *coords* argument. Note that an additional transparent +wall is defined by the code at the boundary of the (periodic) +simulation domain in the *axis* direction. So there are effectively +N+1 walls. + +Each time a particle in the specified group passes through one of the +transparent walls, its velocity is re-assigned. Particles not in the +group do not interact with the wall. + +Conceptually, the velocity re-assignment represents creation of a new +particle within the system with simultaneous removal of the particle +which passed through the wall. The velocity components in directions +parallel to the wall are re-assigned according to the standard Maxwell +velocity distribution for the specified temperature *T*. The velocity +component perpendicular to the wall is re-assigned according to the +shifted Maxwell distribution defined above: .. math:: - f_{\text{z generated}}(v_z) \propto v_z f_z(v_z) + f_{\text{a generated}}(v_a) \propto v_a f_a(v_a) -It can be shown that in an ideal-gas scenario this makes the velocity -distribution of particles between walls exactly as desired. +It can be shown that for an ideal-gas scenario this procedure makes +the velocity distribution of particles between walls exactly as +desired. -Since in most cases simulated systems are not ideal gas, -the need for multiple walls might arise, as a single wall may not be -sufficient for maintaining a stationary flow without congestion -manifesting as areas with increased density located upstream from static obstacles. +Since in most cases simulated systems are not an ideal gas, multiple +walls can be defined, since a single wall may not be sufficient for +maintaining a stationary flow without "congestion" which can manifest +itself as regions in the flow with increased particle density located +upstream from static obstacles. -For the same reason, the actual temperature and velocity of the generated -flow may differ from ones requested. The degree of such discrepancy is determined -by how different from the ideal gas the simulated system is. Therefore, a calibration procedure is required for each system as described in :ref:`(Pavlov) `. +For the same reason, the actual temperature and velocity of the +generated flow may differ from what is requested. The degree of +discrepancy is determined by how different from an ideal gas the +simulated system is. Therefore, a calibration procedure may be +required for such a system as described in :ref:`(Pavlov) +`. -The interactions between particles on different sides of a wall are not disabled or neglected and the -particle positions are not affected by the velocity reassignment. -This removes the need to modify the force field to work correctly in cases when a particle is close -to a wall (for example, if particle positions were uniformly redistributed across the surface of the wall, -two particles could end up too close to each other, potentially causing the simulation to explode). -However due to this compromise, some collective phenomena such as areas with increased/decreased density -or collective movements are not fully removed when particles cross a wall. -This unwanted consequence can also be potentially mitigated by using more than one wall. +Note that the interactions between particles on different sides of a +transparent wall are not disabled or neglected. Likewise particle +positions are not altered by the velocity reassignment. This removes +the need to modify the force field to work correctly in cases when a +particle is close to a wall. +For example, if particle positions were uniformly redistributed across +the surface of a wall, two particles could end up too close to each +other, potentially causing the simulation to explode. However due to +this compromise, some collective phenomena such as regions with +increased/decreased density or collective movements are not fully +removed when particles cross a wall. This unwanted consequence can +also be potentially mitigated by using more multiple walls. ----------- +.. note:: -Note that when high flow velocity is reached, a lost atoms error may -occur (see :doc:`error messages `). -If this message appears when using this fix, you can, for example, reduce the frequency of the -neighbor list rebuild via :doc:`neigh_modify ` command. + When the specified flow has a high velocity, a lost atoms error can + occur (see :doc:`error messages `). If this + happens, you should ensure the checks for neighbor list rebuilds, + set via the :doc:`neigh_modify ` command, are as + conservative as possible (every timestep if needed). Those are the + default settings. Restart, fix_modify, output, run start/stop, minimize info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" -No information about this fix is written to :doc:`binary restart files `. +No information about this fix is written to :doc:`binary restart files +`. None of the :doc:`fix_modify ` options are relevant to this fix. @@ -114,8 +144,8 @@ Fix *wall_flow* is part of the EXTRA-FIX package. It is only enabled if LAMMPS was built with that package. See the :doc:`Build package ` page for more info. -Flow boundary conditions should not be used with rigid bodies such as those -defined by a "fix rigid" command. +Flow boundary conditions should not be used with rigid bodies such as +those defined by a "fix rigid" command. Related commands """""""""""""""" diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index bc2ddcd137..afa0a4e4bd 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -200,11 +200,14 @@ void FixWallFlow::end_of_step() int prev_segment = current_segment[i]; current_segment[i] = compute_current_segment(pos); - if (prev_segment != current_segment[i]) { generate_velocity(i); } + if (prev_segment != current_segment[i]) + generate_velocity(i); } } } +/* ---------------------------------------------------------------------- */ + void FixWallFlow::generate_velocity(int atom_i) { const int newton_iteration_count = 10; @@ -249,6 +252,8 @@ void FixWallFlow::generate_velocity(int atom_i) vel[(flowax + 2) % 3] = random->gaussian() / (gamma * MathConst::MY_SQRT2); } +/* ---------------------------------------------------------------------- */ + int FixWallFlow::compute_current_segment(double pos) const { int result = 0; @@ -258,22 +263,30 @@ int FixWallFlow::compute_current_segment(double pos) const return -1; // -1 is "out of box" region } +/* ---------------------------------------------------------------------- */ + void FixWallFlow::grow_arrays(int nmax) { memory->grow(current_segment, nmax, "WallFlow::current_segment"); } +/* ---------------------------------------------------------------------- */ + void FixWallFlow::copy_arrays(int i, int j, int) { current_segment[j] = current_segment[i]; } +/* ---------------------------------------------------------------------- */ + int FixWallFlow::pack_exchange(int i, double *buf) { buf[0] = static_cast(current_segment[i]); return 1; } +/* ---------------------------------------------------------------------- */ + int FixWallFlow::unpack_exchange(int i, double *buf) { current_segment[i] = static_cast(buf[0]); diff --git a/src/EXTRA-FIX/fix_wall_flow.h b/src/EXTRA-FIX/fix_wall_flow.h index 8e16a850b1..0379c03783 100644 --- a/src/EXTRA-FIX/fix_wall_flow.h +++ b/src/EXTRA-FIX/fix_wall_flow.h @@ -50,6 +50,7 @@ class FixWallFlow : public Fix { int rndseed; class RanMars *random; int *current_segment; + int compute_current_segment(double pos) const; void generate_velocity(int i); }; From ec0535172c55c7bfac812ab5cab123bb5e11be90 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 19 Feb 2024 12:54:59 -0500 Subject: [PATCH 061/185] whitespace --- src/EXTRA-FIX/fix_wall_flow.cpp | 4 ++-- src/EXTRA-FIX/fix_wall_flow.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index afa0a4e4bd..586cfa7382 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -17,6 +17,7 @@ ------------------------------------------------------------------------- */ #include "fix_wall_flow.h" + #include "atom.h" #include "citeme.h" #include "comm.h" @@ -200,8 +201,7 @@ void FixWallFlow::end_of_step() int prev_segment = current_segment[i]; current_segment[i] = compute_current_segment(pos); - if (prev_segment != current_segment[i]) - generate_velocity(i); + if (prev_segment != current_segment[i]) generate_velocity(i); } } } diff --git a/src/EXTRA-FIX/fix_wall_flow.h b/src/EXTRA-FIX/fix_wall_flow.h index 0379c03783..6a662f3d94 100644 --- a/src/EXTRA-FIX/fix_wall_flow.h +++ b/src/EXTRA-FIX/fix_wall_flow.h @@ -50,7 +50,7 @@ class FixWallFlow : public Fix { int rndseed; class RanMars *random; int *current_segment; - + int compute_current_segment(double pos) const; void generate_velocity(int i); }; From d38b3ffd82c11a64bc6ee306250f1775d917853c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Feb 2024 05:11:40 -0500 Subject: [PATCH 062/185] remove dead code --- src/GPU/pair_lj_cut_dipole_cut_gpu.cpp | 9 +-------- src/GPU/pair_lj_sf_dipole_sf_gpu.cpp | 12 ++---------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/GPU/pair_lj_cut_dipole_cut_gpu.cpp b/src/GPU/pair_lj_cut_dipole_cut_gpu.cpp index b71e526bf2..1052e16c11 100644 --- a/src/GPU/pair_lj_cut_dipole_cut_gpu.cpp +++ b/src/GPU/pair_lj_cut_dipole_cut_gpu.cpp @@ -179,7 +179,7 @@ void PairLJCutDipoleCutGPU::cpu_compute(int start, int inum, int eflag, int vfla double qtmp, xtmp, ytmp, ztmp, delx, dely, delz, evdwl, ecoul, fx, fy, fz; double rsq, rinv, r2inv, r6inv, r3inv, r5inv, r7inv; double forcecoulx, forcecouly, forcecoulz, crossx, crossy, crossz; - double tixcoul, tiycoul, tizcoul, tjxcoul, tjycoul, tjzcoul; + double tixcoul, tiycoul, tizcoul; double fq, pdotp, pidotr, pjdotr, pre1, pre2, pre3, pre4; double forcelj, factor_coul, factor_lj; int *jlist; @@ -230,7 +230,6 @@ void PairLJCutDipoleCutGPU::cpu_compute(int start, int inum, int eflag, int vfla forcecoulx = forcecouly = forcecoulz = 0.0; tixcoul = tiycoul = tizcoul = 0.0; - tjxcoul = tjycoul = tjzcoul = 0.0; if (rsq < cut_coulsq[itype][jtype]) { @@ -268,9 +267,6 @@ void PairLJCutDipoleCutGPU::cpu_compute(int start, int inum, int eflag, int vfla tixcoul += crossx + pre2 * (mu[i][1] * delz - mu[i][2] * dely); tiycoul += crossy + pre2 * (mu[i][2] * delx - mu[i][0] * delz); tizcoul += crossz + pre2 * (mu[i][0] * dely - mu[i][1] * delx); - tjxcoul += -crossx + pre3 * (mu[j][1] * delz - mu[j][2] * dely); - tjycoul += -crossy + pre3 * (mu[j][2] * delx - mu[j][0] * delz); - tjzcoul += -crossz + pre3 * (mu[j][0] * dely - mu[j][1] * delx); } if (mu[i][3] > 0.0 && q[j] != 0.0) { @@ -298,9 +294,6 @@ void PairLJCutDipoleCutGPU::cpu_compute(int start, int inum, int eflag, int vfla forcecoulx += pre1 * delx - pre2 * mu[j][0]; forcecouly += pre1 * dely - pre2 * mu[j][1]; forcecoulz += pre1 * delz - pre2 * mu[j][2]; - tjxcoul += -pre2 * (mu[j][1] * delz - mu[j][2] * dely); - tjycoul += -pre2 * (mu[j][2] * delx - mu[j][0] * delz); - tjzcoul += -pre2 * (mu[j][0] * dely - mu[j][1] * delx); } } diff --git a/src/GPU/pair_lj_sf_dipole_sf_gpu.cpp b/src/GPU/pair_lj_sf_dipole_sf_gpu.cpp index 4d8fbb5139..57ba3ec353 100644 --- a/src/GPU/pair_lj_sf_dipole_sf_gpu.cpp +++ b/src/GPU/pair_lj_sf_dipole_sf_gpu.cpp @@ -178,8 +178,8 @@ void PairLJSFDipoleSFGPU::cpu_compute(int start, int inum, int eflag, int vflag, double qtmp, xtmp, ytmp, ztmp, delx, dely, delz, evdwl, ecoul, fx, fy, fz; double rsq, rinv, r2inv, r6inv, r3inv, r5inv; double forcecoulx, forcecouly, forcecoulz, crossx, crossy, crossz; - double tixcoul, tiycoul, tizcoul, tjxcoul, tjycoul, tjzcoul; - double fq, pdotp, pidotr, pjdotr, pre1, pre2, pre3, pre4; + double tixcoul, tiycoul, tizcoul; + double fq, pdotp, pidotr, pjdotr, pre1, pre2, pre4; double forcelj, factor_coul, factor_lj; double presf, afac, bfac, pqfac, qpfac, forceljcut, forceljsf; double aforcecoulx, aforcecouly, aforcecoulz; @@ -233,7 +233,6 @@ void PairLJSFDipoleSFGPU::cpu_compute(int start, int inum, int eflag, int vflag, forcecoulx = forcecouly = forcecoulz = 0.0; tixcoul = tiycoul = tizcoul = 0.0; - tjxcoul = tjycoul = tjzcoul = 0.0; if (rsq < cut_coulsq[itype][jtype]) { @@ -272,7 +271,6 @@ void PairLJSFDipoleSFGPU::cpu_compute(int start, int inum, int eflag, int vflag, forcecoulz += 3.0 * r5inv * (aforcecoulz + bforcecoulz); pre2 = 3.0 * bfac * r5inv * pjdotr; - pre3 = 3.0 * bfac * r5inv * pidotr; pre4 = -bfac * r3inv; crossx = pre4 * (mu[i][1] * mu[j][2] - mu[i][2] * mu[j][1]); @@ -282,9 +280,6 @@ void PairLJSFDipoleSFGPU::cpu_compute(int start, int inum, int eflag, int vflag, tixcoul += crossx + pre2 * (mu[i][1] * delz - mu[i][2] * dely); tiycoul += crossy + pre2 * (mu[i][2] * delx - mu[i][0] * delz); tizcoul += crossz + pre2 * (mu[i][0] * dely - mu[i][1] * delx); - tjxcoul += -crossx + pre3 * (mu[j][1] * delz - mu[j][2] * dely); - tjycoul += -crossy + pre3 * (mu[j][2] * delx - mu[j][0] * delz); - tjzcoul += -crossz + pre3 * (mu[j][0] * dely - mu[j][1] * delx); } if (mu[i][3] > 0.0 && q[j] != 0.0) { @@ -318,9 +313,6 @@ void PairLJSFDipoleSFGPU::cpu_compute(int start, int inum, int eflag, int vflag, forcecoulx += pre1 * delx - pre2 * mu[j][0]; forcecouly += pre1 * dely - pre2 * mu[j][1]; forcecoulz += pre1 * delz - pre2 * mu[j][2]; - tjxcoul += -pre2 * (mu[j][1] * delz - mu[j][2] * dely); - tjycoul += -pre2 * (mu[j][2] * delx - mu[j][0] * delz); - tjzcoul += -pre2 * (mu[j][0] * dely - mu[j][1] * delx); } } From 9cf4f688d9a15bba43c2d2cd82166d4d69dd7780 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Feb 2024 11:38:32 -0500 Subject: [PATCH 063/185] improve some explanations for KOKKOS package usage. --- doc/src/Speed_kokkos.rst | 64 ++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/doc/src/Speed_kokkos.rst b/doc/src/Speed_kokkos.rst index 1cae518f96..41ae4a4dfb 100644 --- a/doc/src/Speed_kokkos.rst +++ b/doc/src/Speed_kokkos.rst @@ -20,11 +20,28 @@ including Sikandar Mashayak (UIUC), Ray Shan (Sandia), and Dan Ibanez (Sandia). For more information on developing using Kokkos abstractions see the `Kokkos Wiki `_. -Kokkos currently provides support for 4 modes of execution (per MPI +.. note:: + + The Kokkos library is under active development and tracking the + availability of accelerator hardware, so is the KOKKOS package in + LAMMPS. This means that only a certain range of versions of the + Kokkos library are compatible with the KOKKOS package of a certain + range of LAMMPS versions. For that reason LAMMPS comes with a + bundled version of the Kokkos library that has been validated on + multiple platforms and may contain selected back-ported bug fixes + from upstream Kokkos versions. While it is possible to build LAMMPS + with an external version of Kokkos, it is untested and may result in + incorrect execution or crashes. + +Kokkos currently provides full support for 4 modes of execution (per MPI task). These are Serial (MPI-only for CPUs and Intel Phi), OpenMP -(threading for many-core CPUs and Intel Phi), CUDA (for NVIDIA -GPUs) and HIP (for AMD GPUs). You choose the mode at build time to -produce an executable compatible with a specific hardware. +(threading for many-core CPUs and Intel Phi), CUDA (for NVIDIA GPUs) and +HIP (for AMD GPUs). Additional modes (e.g. OpenMP target, Intel data +center GPUs) are under development. You choose the mode at build time +to produce an executable compatible with a specific hardware. + +The following compatibility notes have been last updated for LAMMPS +version 23 November 2023 and Kokkos version 4.2. .. admonition:: C++17 support :class: note @@ -54,22 +71,22 @@ produce an executable compatible with a specific hardware. :class: note Kokkos with CUDA currently implicitly assumes that the MPI library is - GPU-aware. This is not always the case, especially when using + GPU-aware. This is not always the case, especially when using pre-compiled MPI libraries provided by a Linux distribution. This is not a problem when using only a single GPU with a single MPI - rank. When running with multiple MPI ranks, you may see segmentation + rank. When running with multiple MPI ranks, you may see segmentation faults without GPU-aware MPI support. These can be avoided by adding the flags :doc:`-pk kokkos gpu/aware off ` to the LAMMPS command line or by using the command :doc:`package kokkos gpu/aware off ` in the input file. -.. admonition:: AMD GPU support +.. admonition:: Intel Data Center GPU support :class: note - To build with Kokkos the HIPCC compiler from the AMD ROCm software - version 3.5 or later is required. Supporting this Kokkos mode in - LAMMPS is still work in progress. Please contact the LAMMPS developers - if you run into problems. + Support for Kokkos with Intel Data Center GPU accelerators (formerly + known under the code name "Ponte Vecchio") in LAMMPS is still a work + in progress. Only a subset of the functionality works correctly. + Please contact the LAMMPS developers if you run into problems. Building LAMMPS with the KOKKOS package """"""""""""""""""""""""""""""""""""""" @@ -292,6 +309,10 @@ one or more nodes, each with two GPUs: settings. Experimenting with its options can provide a speed-up for specific calculations. For example: +.. code-block:: bash + + mpirun -np 2 lmp_kokkos_cuda_openmpi -k on g 2 -sf kk -pk kokkos newton on neigh half binsize 2.8 -in in.lj # Newton on, half neighbor list, set binsize = neighbor ghost cutoff + .. note:: The default binsize for :doc:`atom sorting ` on GPUs @@ -302,9 +323,15 @@ one or more nodes, each with two GPUs: frequent sorting than default (e.g. sorting every 100 time steps instead of 1000) may improve performance. -.. code-block:: bash +.. note:: - mpirun -np 2 lmp_kokkos_cuda_openmpi -k on g 2 -sf kk -pk kokkos newton on neigh half binsize 2.8 -in in.lj # Newton on, half neighbor list, set binsize = neighbor ghost cutoff + When running on GPUs with many MPI ranks (tens of thousands and + more), the creation of the atom map (required for molecular systems) + on the GPU can slow down significantly or run out of GPU memory and + thus slow down the whole calculation or cause a crash. You can use + the "-pk kokkos atom/map no" :doc:`command-line switch ` + of the :doc:`package kokkos atom/map no ` command to create + the atom map on the CPU instead. .. note:: @@ -416,15 +443,22 @@ Generally speaking, the following rules of thumb apply: performance of a KOKKOS style is a bit slower than the OPENMP package. * When running large number of atoms per GPU, KOKKOS is typically faster - than the GPU package when compiled for double precision. The benefit + than the GPU package when compiled for double precision. The benefit of using single or mixed precision with the GPU package depends significantly on the hardware in use and the simulated system and pair style. -* When running on Intel hardware, KOKKOS is not as fast as +* When running on Intel Phi hardware, KOKKOS is not as fast as the INTEL package, which is optimized for x86 hardware (not just from Intel) and compilation with the Intel compilers. The INTEL package also can increase the vector length of vector instructions by switching to single or mixed precision mode. +* The KOKKOS package by default assumes that you are using exactly one + MPI rank per GPU. When trying to use multiple MPI ranks per GPU it is + mandatory to enable `CUDA Multi-Process Service (MPS) + `_ to get good + performance. In this case it is better to not use all available + MPI ranks in order to avoid competing with the MPS daemon for + CPU resources. See the `Benchmark page `_ of the LAMMPS website for performance of the KOKKOS package on different From 4c0952dc70d3537e92e9a7e7c50a4befea61f094 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Tue, 20 Feb 2024 21:02:55 -0700 Subject: [PATCH 064/185] Doc file updates, reverting h_rate initialization --- doc/src/fix_deform.rst | 8 +- doc/src/fix_deform_pressure.rst | 659 ++++---------------------- src/EXTRA-FIX/fix_deform_pressure.cpp | 2 - src/fix_deform.cpp | 31 +- 4 files changed, 105 insertions(+), 595 deletions(-) diff --git a/doc/src/fix_deform.rst b/doc/src/fix_deform.rst index ee010f5645..c0ea50ae41 100644 --- a/doc/src/fix_deform.rst +++ b/doc/src/fix_deform.rst @@ -44,7 +44,7 @@ Syntax v_name1 = variable with name1 for box length change as function of time v_name2 = variable with name2 for change rate as function of time *xy*, *xz*, *yz* args = style value - style = *final* or *delta* or *vel* or *erate* or *trate* or *wiggle* + style = *final* or *delta* or *vel* or *erate* or *trate* or *wiggle* or *variable* *final* value = tilt tilt = tilt factor at end of run (distance units) *delta* value = dtilt @@ -95,7 +95,9 @@ Change the volume and/or shape of the simulation box during a dynamics run. Orthogonal simulation boxes have 3 adjustable parameters (x,y,z). Triclinic (non-orthogonal) simulation boxes have 6 adjustable parameters (x,y,z,xy,xz,yz). Any or all of them can be -adjusted independently and simultaneously by this command. +adjusted independently and simultaneously by this command. For +additional pressure-based controls, see +:doc:`fix deform/pressure `. This fix can be used to perform non-equilibrium MD (NEMD) simulations of a continuously strained system. See the :doc:`fix nvt/sllod ` and :doc:`compute temp/deform ` commands for more details. Note @@ -592,7 +594,7 @@ xy) that is shrink-wrapped via the :doc:`boundary ` command. Related commands """""""""""""""" -:doc:`change_box ` +:doc:`fix deform/pressure `, :doc:`change_box ` Default """"""" diff --git a/doc/src/fix_deform_pressure.rst b/doc/src/fix_deform_pressure.rst index d19e5fba7e..d45c10b351 100644 --- a/doc/src/fix_deform_pressure.rst +++ b/doc/src/fix_deform_pressure.rst @@ -1,10 +1,7 @@ -.. index:: fix deform -.. index:: fix deform/kk +.. index:: fix deform/pressure -fix deform command -================== - -Accelerator Variants: *deform/kk* +fix deform/pressure command +=========================== Syntax """""" @@ -20,58 +17,23 @@ Syntax .. parsed-literal:: - parameter = *x* or *y* or *z* or *xy* or *xz* or *yz* or *iso* + parameter = *x* or *y* or *z* or *xy* or *xz* or *yz* or *box* *x*, *y*, *z* args = style value(s) - style = *final* or *delta* or *scale* or *vel* or *erate* or *trate* or *volume* or *wiggle* or *variable* - *final* values = lo hi - lo hi = box boundaries at end of run (distance units) - *delta* values = dlo dhi - dlo dhi = change in box boundaries at end of run (distance units) - *scale* values = factor - factor = multiplicative factor for change in box length at end of run - *vel* value = V - V = change box length at this velocity (distance/time units), - effectively an engineering strain rate - *erate* value = R - R = engineering strain rate (1/time units) + style = *final* or *delta* or *scale* or *vel* or *erate* or *trate* or *volume* or *wiggle* or *variable* or *pressure* or *pressure/mean* *pressure* values = target gain target = target pressure (pressure units) gain = proportional gain constant (1/(time * pressure) or 1/time units) *pressure/mean* values = target gain target = target pressure (pressure units) gain = proportional gain constant (1/(time * pressure) or 1/time units) - *trate* value = R - R = true strain rate (1/time units) - *volume* value = none = adjust this dim to preserve volume of system - *wiggle* values = A Tp - A = amplitude of oscillation (distance units) - Tp = period of oscillation (time units) - *variable* values = v_name1 v_name2 - v_name1 = variable with name1 for box length change as function of time - v_name2 = variable with name2 for change rate as function of time + All other styles operate identically to those in :doc:`fix deform ` *xy*, *xz*, *yz* args = style value - style = *final* or *delta* or *vel* or *erate* or *trate* or *wiggle* - *final* value = tilt - tilt = tilt factor at end of run (distance units) - *delta* value = dtilt - dtilt = change in tilt factor at end of run (distance units) - *vel* value = V - V = change tilt factor at this velocity (distance/time units), - effectively an engineering shear strain rate - *erate* value = R - R = engineering shear strain rate (1/time units) + style = *final* or *delta* or *vel* or *erate* or *trate* or *wiggle* or *variable* or *pressure* *pressure* values = target gain target = target pressure (pressure units) gain = proportional gain constant (1/(time * pressure) or 1/time units) - *trate* value = R - R = true shear strain rate (1/time units) - *wiggle* values = A Tp - A = amplitude of oscillation (distance units) - Tp = period of oscillation (time units) - *variable* values = v_name1 v_name2 - v_name1 = variable with name1 for tilt change as function of time - v_name2 = variable with name2 for change rate as function of time - *iso* = style value + All other styles operate identically to those in :doc:`fix deform ` + *box* = style value style = *volume* or *pressure* *volume* value = none = isotropically adjust system to preserve volume of system *pressure* values = target gain @@ -83,15 +45,6 @@ Syntax .. parsed-literal:: - *remap* value = *x* or *v* or *none* - x = remap coords of atoms in group into deforming box - v = remap velocities of atoms in group when they cross periodic boundaries - none = no remapping of x or v - *flip* value = *yes* or *no* - allow or disallow box flips when it becomes highly skewed - *units* value = *lattice* or *box* - lattice = distances are defined in lattice units - box = distances are defined in simulation box units *couple* value = *none* or *xyz* or *xy* or *yz* or *xz* couple pressure values of various dimensions *vol/balance/p* value = *yes* or *no* @@ -100,232 +53,38 @@ Syntax rate = maximum strain rate for pressure control *normalize/pressure* value = *yes* or *no* Modifies pressure controls such that the deviation in pressure is normalized by the target pressure + All other options operate identically to those in :doc:`fix deform ` Examples """""""" .. code-block:: LAMMPS - fix 1 all deform 1 x final 0.0 9.0 z final 0.0 5.0 units box - fix 1 all deform 1 x trate 0.1 y volume z volume - fix 1 all deform 1 xy erate 0.001 remap v - fix 1 all deform 10 y delta -0.5 0.5 xz vel 1.0 - fix 1 all deform 1 x pressure 2.0 0.1 normalize/pressure yes max/rate 0.001 - fix 1 all deform 1 x trate 0.1 y volume z volume vol/balance/p yes - fix 1 all deform 1 x trate 0.1 y pressure/mean 0.0 1.0 z pressure/mean 0.0 1.0 + fix 1 all deform/pressure 1 x pressure 2.0 0.1 normalize/pressure yes max/rate 0.001 + fix 1 all deform/pressure 1 x trate 0.1 y volume z volume vol/balance/p yes + fix 1 all deform/pressure 1 x trate 0.1 y pressure/mean 0.0 1.0 z pressure/mean 0.0 1.0 Description """"""""""" -Change the volume and/or shape of the simulation box during a dynamics -run. Orthogonal simulation boxes have 3 adjustable parameters -(x,y,z). Triclinic (non-orthogonal) simulation boxes have 6 -adjustable parameters (x,y,z,xy,xz,yz). Any or all of them can be -adjusted independently and simultaneously by this command. - -This fix can be used to perform non-equilibrium MD (NEMD) simulations -of a continuously strained system. See the :doc:`fix nvt/sllod ` and :doc:`compute temp/deform ` commands for more details. Note -that simulation of a continuously extended system (extensional flow) -can be modeled using the :ref:`UEF package ` and its :doc:`fix commands `. - -For the *x*, *y*, *z* parameters, the associated dimension cannot be -shrink-wrapped. For the *xy*, *yz*, *xz* parameters, the associated -second dimension cannot be shrink-wrapped. Dimensions not varied by this -command can be periodic or non-periodic. Dimensions corresponding to -unspecified parameters can also be controlled by a :doc:`fix npt ` or :doc:`fix nph ` command. - -The size and shape of the simulation box at the beginning of the -simulation run were either specified by the -:doc:`create_box ` or :doc:`read_data ` or -:doc:`read_restart ` command used to setup the simulation -initially if it is the first run, or they are the values from the end -of the previous run. The :doc:`create_box `, :doc:`read data `, and :doc:`read_restart ` commands -specify whether the simulation box is orthogonal or non-orthogonal -(triclinic) and explain the meaning of the xy,xz,yz tilt factors. If -fix deform changes the xy,xz,yz tilt factors, then the simulation box -must be triclinic, even if its initial tilt factors are 0.0. - -As described below, the desired simulation box size and shape at the -end of the run are determined by the parameters of the fix deform -command. Every Nth timestep during the run, the simulation box is -expanded, contracted, or tilted to ramped values between the initial -and final values. +This fix is an extension of :doc:`fix deform `, inheriting +all of its features and adding new pressure-based controls to allow for +new deformation protocols. All details in :doc:`fix deform ` +apply to this fix unless otherwise noted. ---------- For the *x*, *y*, and *z* parameters, this is the meaning of their styles and values. -The *final*, *delta*, *scale*, *vel*, and *erate* styles all change -the specified dimension of the box via "constant displacement" which -is effectively a "constant engineering strain rate". This means the -box dimension changes linearly with time from its initial to final -value. +The *final*, *delta*, *scale*, *vel*, *erate*, *trate*, *volume*, +*wiggle*, and *variable* styles all behave identically to those in +:doc:`fix deform `. Additional styles are described below. -For style *final*, the final lo and hi box boundaries of a dimension -are specified. The values can be in lattice or box distance units. -See the discussion of the units keyword below. - -For style *delta*, plus or minus changes in the lo/hi box boundaries -of a dimension are specified. The values can be in lattice or box -distance units. See the discussion of the units keyword below. - -For style *scale*, a multiplicative factor to apply to the box length -of a dimension is specified. For example, if the initial box length -is 10, and the factor is 1.1, then the final box length will be 11. A -factor less than 1.0 means compression. - -For style *vel*, a velocity at which the box length changes is -specified in units of distance/time. This is effectively a "constant -engineering strain rate", where rate = V/L0 and L0 is the initial box -length. The distance can be in lattice or box distance units. See -the discussion of the units keyword below. For example, if the -initial box length is 100 Angstroms, and V is 10 Angstroms/ps, then -after 10 ps, the box length will have doubled. After 20 ps, it -will have tripled. - -The *erate* style changes a dimension of the box at a "constant -engineering strain rate". The units of the specified strain rate are -1/time. See the :doc:`units ` command for the time units -associated with different choices of simulation units, -e.g. picoseconds for "metal" units). Tensile strain is unitless and -is defined as delta/L0, where L0 is the original box length and delta -is the change relative to the original length. The box length L as a -function of time will change as - -.. parsed-literal:: - - L(t) = L0 (1 + erate\*dt) - -where dt is the elapsed time (in time units). Thus if *erate* R is -specified as 0.1 and time units are picoseconds, this means the box -length will increase by 10% of its original length every picosecond. -I.e. strain after 1 ps = 0.1, strain after 2 ps = 0.2, etc. R = --0.01 means the box length will shrink by 1% of its original length -every picosecond. Note that for an "engineering" rate the change is -based on the original box length, so running with R = 1 for 10 -picoseconds expands the box length by a factor of 11 (strain of 10), -which is different that what the *trate* style would induce. - -The *trate* style changes a dimension of the box at a "constant true -strain rate". Note that this is not an "engineering strain rate", as -the other styles are. Rather, for a "true" rate, the rate of change -is constant, which means the box dimension changes non-linearly with -time from its initial to final value. The units of the specified -strain rate are 1/time. See the :doc:`units ` command for the -time units associated with different choices of simulation units, -e.g. picoseconds for "metal" units). Tensile strain is unitless and -is defined as delta/L0, where L0 is the original box length and delta -is the change relative to the original length. - -The box length L as a function of time will change as - -.. parsed-literal:: - - L(t) = L0 exp(trate\*dt) - -where dt is the elapsed time (in time units). Thus if *trate* R is -specified as ln(1.1) and time units are picoseconds, this means the -box length will increase by 10% of its current (not original) length -every picosecond. I.e. strain after 1 ps = 0.1, strain after 2 ps -= 0.21, etc. R = ln(2) or ln(3) means the box length will double or -triple every picosecond. R = ln(0.99) means the box length will -shrink by 1% of its current length every picosecond. Note that for a -"true" rate the change is continuous and based on the current length, -so running with R = ln(2) for 10 picoseconds does not expand the box -length by a factor of 11 as it would with *erate*, but by a factor of -1024 since the box length will double every picosecond. - -Note that to change the volume (or cross-sectional area) of the -simulation box at a constant rate, you can change multiple dimensions -via *erate* or *trate*\ . E.g. to double the box volume in a picosecond -picosecond, you could set "x erate M", "y erate M", "z erate M", with -M = pow(2,1/3) - 1 = 0.26, since if each box dimension grows by 26%, -the box volume doubles. Or you could set "x trate M", "y trate M", "z -trate M", with M = ln(1.26) = 0.231, and the box volume would double -every picosecond. - -The *volume* style changes the specified dimension in such a way that -the box volume remains constant while other box dimensions are changed -explicitly via the styles discussed above. For example, "x scale 1.1 -y scale 1.1 z volume" will shrink the z box length as the x,y box -lengths increase, to keep the volume constant (product of x,y,z -lengths). If "x scale 1.1 z volume" is specified and parameter *y* is -unspecified, then the z box length will shrink as x increases to keep -the product of x,z lengths constant. If "x scale 1.1 y volume z -volume" is specified, then both the y,z box lengths will shrink as x -increases to keep the volume constant (product of x,y,z lengths). In -this case, the y,z box lengths shrink so as to keep their relative -aspect ratio constant. When maintaining a constant volume using two -separate dimensions, one can alternatively allow the two dimensions -to adjust their aspect ratio to attempt to maintain equivalent -pressures along the two dimensions. See the -:ref:`vol/balance/p ` option for more details. - -For solids or liquids, note that when one dimension of the box is -expanded via fix deform (i.e. tensile strain), it may be physically -undesirable to hold the other 2 box lengths constant (unspecified by -fix deform) since that implies a density change. Using the *volume* -style for those 2 dimensions to keep the box volume constant may make -more physical sense, but may also not be correct for materials and -potentials whose Poisson ratio is not 0.5. An alternative is to use -:doc:`fix npt aniso ` with zero applied pressure on those 2 -dimensions, so that they respond to the tensile strain dynamically. - -The *wiggle* style oscillates the specified box length dimension -sinusoidally with the specified amplitude and period. I.e. the box -length L as a function of time is given by - -.. parsed-literal:: - - L(t) = L0 + A sin(2\*pi t/Tp) - -where L0 is its initial length. If the amplitude A is a positive -number the box initially expands, then contracts, etc. If A is -negative then the box initially contracts, then expands, etc. The -amplitude can be in lattice or box distance units. See the discussion -of the units keyword below. - -The *variable* style changes the specified box length dimension by -evaluating a variable, which presumably is a function of time. The -variable with *name1* must be an :doc:`equal-style variable ` -and should calculate a change in box length in units of distance. -Note that this distance is in box units, not lattice units; see the -discussion of the *units* keyword below. The formula associated with -variable *name1* can reference the current timestep. Note that it -should return the "change" in box length, not the absolute box length. -This means it should evaluate to 0.0 when invoked on the initial -timestep of the run following the definition of fix deform. It should -evaluate to a value > 0.0 to dilate the box at future times, or a -value < 0.0 to compress the box. - -The variable *name2* must also be an :doc:`equal-style variable ` and should calculate the rate of box length -change, in units of distance/time, i.e. the time-derivative of the -*name1* variable. This quantity is used internally by LAMMPS to reset -atom velocities when they cross periodic boundaries. It is computed -internally for the other styles, but you must provide it when using an -arbitrary variable. - -Here is an example of using the *variable* style to perform the same -box deformation as the *wiggle* style formula listed above, where we -assume that the current timestep = 0. - -.. code-block:: LAMMPS - - variable A equal 5.0 - variable Tp equal 10.0 - variable displace equal "v_A * sin(2*PI * step*dt/v_Tp)" - variable rate equal "2*PI*v_A/v_Tp * cos(2*PI * step*dt/v_Tp)" - fix 2 all deform 1 x variable v_displace v_rate remap v - -For the *scale*, *vel*, *erate*, *trate*, *volume*, *wiggle*, and -*variable* styles, the box length is expanded or compressed around its -mid point. - -The *pressure* style adjusts a dimensions's box length to control that -component of the pressure tensor. This option attempts to maintain a -specified target value using a linear controller where the box length -:math:`L` evolves according to the equation +The *pressure* style adjusts a dimension's box length to control the +corresponding component of the pressure tensor. This option attempts to +maintain a specified target pressure using a linear controller where the +box length :math:`L` evolves according to the equation .. parsed-literal:: @@ -338,163 +97,43 @@ approach is similar to the method used to control the pressure by accepts either a constant numeric value or a LAMMPS :ref:`variable `. Notably, this variable can be a function of time or other components of the pressure tensor. By default, :math:`k` has units of 1/(time * pressure) -although this will change if the *normalize/pessure* option is set as +although this will change if the *normalize/pressure* option is set as :ref:`discussed below `. There is no proven method to choosing an appropriate value of :math:`k` as it will depend on the -specific details of a simulation and testing different values is -recommended. One can also apply a maximum limit to the magnitude of the -applied strain using the :ref:`max/rate ` option and couple -pressures in different dimensions using the :ref:`couple ` -option. +specific details of a simulation. Testing different values is recommended. + +By default, there is no limit on the resulting strain rate in any dimension. +A maximum limit can be applied using the :ref:`max/rate ` +option. Akin to :ref:`fix nh `, pressures in different dimensions +can be coupled using the :ref:`couple ` option. This means +the instantaneous pressure along coupled dimensions are averaged and the box +strains identically along the coupled dimensions. The *pressure/mean* style changes a dimension's box length to maintain a constant mean pressure defined as the trace of the pressure tensor. -This option is therefore very similar to the *pressure* style with -identical arguments except the current and target pressures refer to the +This option has identical arguments to the *pressure* style and a similar +functional equation, except the current and target pressures refer to the mean trace of the pressure tensor. All options for the *pressure* style also apply to the *pressure/mean* style except for the :ref:`couple ` option. +Note that while this style can be identical to coupled *pressure* styles, +it is generally not the same. For instance in 2D, a coupled *pressure* +style in the *x* and *y* dimensions would be equivalent to using the +*pressure/mean* style with identical settings in each dimension. However, +it would not be the same if settings (e.g. gain constants) were used in +the *x* and *y* dimensions or if the *pressure/mean* command was only applied +along one dimension. + ---------- For the *xy*, *xz*, and *yz* parameters, this is the meaning of their styles and values. Note that changing the tilt factors of a triclinic box does not change its volume. -The *final*, *delta*, *vel*, and *erate* styles all change the shear -strain at a "constant engineering shear strain rate". This means the -tilt factor changes linearly with time from its initial to final -value. - -For style *final*, the final tilt factor is specified. The value -can be in lattice or box distance units. See the discussion of the -units keyword below. - -For style *delta*, a plus or minus change in the tilt factor is -specified. The value can be in lattice or box distance units. See -the discussion of the units keyword below. - -For style *vel*, a velocity at which the tilt factor changes is -specified in units of distance/time. This is effectively an -"engineering shear strain rate", where rate = V/L0 and L0 is the -initial box length perpendicular to the direction of shear. The -distance can be in lattice or box distance units. See the discussion -of the units keyword below. For example, if the initial tilt factor -is 5 Angstroms, and the V is 10 Angstroms/ps, then after 1 ps, the -tilt factor will be 15 Angstroms. After 2 ps, it will be 25 -Angstroms. - -The *erate* style changes a tilt factor at a "constant engineering -shear strain rate". The units of the specified shear strain rate are -1/time. See the :doc:`units ` command for the time units -associated with different choices of simulation units, -e.g. picoseconds for "metal" units). Shear strain is unitless and is -defined as offset/length, where length is the box length perpendicular -to the shear direction (e.g. y box length for xy deformation) and -offset is the displacement distance in the shear direction (e.g. x -direction for xy deformation) from the unstrained orientation. - -The tilt factor T as a function of time will change as - -.. parsed-literal:: - - T(t) = T0 + L0\*erate\*dt - -where T0 is the initial tilt factor, L0 is the original length of the -box perpendicular to the shear direction (e.g. y box length for xy -deformation), and dt is the elapsed time (in time units). Thus if -*erate* R is specified as 0.1 and time units are picoseconds, this -means the shear strain will increase by 0.1 every picosecond. I.e. if -the xy shear strain was initially 0.0, then strain after 1 ps = 0.1, -strain after 2 ps = 0.2, etc. Thus the tilt factor would be 0.0 at -time 0, 0.1\*ybox at 1 ps, 0.2\*ybox at 2 ps, etc, where ybox is the -original y box length. R = 1 or 2 means the tilt factor will increase -by 1 or 2 every picosecond. R = -0.01 means a decrease in shear -strain by 0.01 every picosecond. - -The *trate* style changes a tilt factor at a "constant true shear -strain rate". Note that this is not an "engineering shear strain -rate", as the other styles are. Rather, for a "true" rate, the rate -of change is constant, which means the tilt factor changes -non-linearly with time from its initial to final value. The units of -the specified shear strain rate are 1/time. See the -:doc:`units ` command for the time units associated with -different choices of simulation units, e.g. picoseconds for "metal" -units). Shear strain is unitless and is defined as offset/length, -where length is the box length perpendicular to the shear direction -(e.g. y box length for xy deformation) and offset is the displacement -distance in the shear direction (e.g. x direction for xy deformation) -from the unstrained orientation. - -The tilt factor T as a function of time will change as - -.. parsed-literal:: - - T(t) = T0 exp(trate\*dt) - -where T0 is the initial tilt factor and dt is the elapsed time (in -time units). Thus if *trate* R is specified as ln(1.1) and time units -are picoseconds, this means the shear strain or tilt factor will -increase by 10% every picosecond. I.e. if the xy shear strain was -initially 0.1, then strain after 1 ps = 0.11, strain after 2 ps = -0.121, etc. R = ln(2) or ln(3) means the tilt factor will double or -triple every picosecond. R = ln(0.99) means the tilt factor will -shrink by 1% every picosecond. Note that the change is continuous, so -running with R = ln(2) for 10 picoseconds does not change the tilt -factor by a factor of 10, but by a factor of 1024 since it doubles -every picosecond. Note that the initial tilt factor must be non-zero -to use the *trate* option. - -Note that shear strain is defined as the tilt factor divided by the -perpendicular box length. The *erate* and *trate* styles control the -tilt factor, but assume the perpendicular box length remains constant. -If this is not the case (e.g. it changes due to another fix deform -parameter), then this effect on the shear strain is ignored. - -The *wiggle* style oscillates the specified tilt factor sinusoidally -with the specified amplitude and period. I.e. the tilt factor T as a -function of time is given by - -.. parsed-literal:: - - T(t) = T0 + A sin(2\*pi t/Tp) - -where T0 is its initial value. If the amplitude A is a positive -number the tilt factor initially becomes more positive, then more -negative, etc. If A is negative then the tilt factor initially -becomes more negative, then more positive, etc. The amplitude can be -in lattice or box distance units. See the discussion of the units -keyword below. - -The *variable* style changes the specified tilt factor by evaluating a -variable, which presumably is a function of time. The variable with -*name1* must be an :doc:`equal-style variable ` and should -calculate a change in tilt in units of distance. Note that this -distance is in box units, not lattice units; see the discussion of the -*units* keyword below. The formula associated with variable *name1* -can reference the current timestep. Note that it should return the -"change" in tilt factor, not the absolute tilt factor. This means it -should evaluate to 0.0 when invoked on the initial timestep of the run -following the definition of fix deform. - -The variable *name2* must also be an :doc:`equal-style variable ` and should calculate the rate of tilt change, -in units of distance/time, i.e. the time-derivative of the *name1* -variable. This quantity is used internally by LAMMPS to reset atom -velocities when they cross periodic boundaries. It is computed -internally for the other styles, but you must provide it when using an -arbitrary variable. - -Here is an example of using the *variable* style to perform the same -box deformation as the *wiggle* style formula listed above, where we -assume that the current timestep = 0. - -.. code-block:: LAMMPS - - variable A equal 5.0 - variable Tp equal 10.0 - variable displace equal "v_A * sin(2*PI * step*dt/v_Tp)" - variable rate equal "2*PI*v_A/v_Tp * cos(2*PI * step*dt/v_Tp)" - fix 2 all deform 1 xy variable v_displace v_rate remap v +The *final*, *delta*, *vel*, *erate*, *trate*, *wiggle*, and *variable* +styles all behave identically to those in :doc:`fix deform `. +Additional styles are described below. The *pressure* style adjusts a tilt factor to control the corresponding off-diagonal component of the pressure tensor. This option attempts to @@ -519,155 +158,42 @@ of the applied strain using the :ref:`max/rate ` option. ---------- -The *iso* parameter provides an additonal control over the x, y, -and z box lengths. This parameter can only be used in combination with -the *x*, *y*, or *z* comamnds: *vel*, *erate*, *trate*, *pressure*, or -*wiggle*. Note that this parameter will change the overall strain rate in -the *x*, *y*, or *z* dimensions. This is the meaning of its styles and values. +The *box* parameter provides an additonal control over the *x*, *y*, +and *z* box lengths by isotropically dilating or contracting the box to +either maintain a fixed mean pressure or volume. This isotropic scaling +is applied after the box is deformed by the above *x*, *y*, *z*, *xy*, +*xz*, and *yz* styles, acting as a second deformation step. This parameter +will change the overall strain rate in the *x*, *y*, or *z* dimensions. +This parameter can only be used in combination with the *x*, *y*, or *z* +commands: *vel*, *erate*, *trate*, *pressure*, or *wiggle*. This is the meaning +of its styles and values. The *volume* style isotropically scales box lengths to maintain a constant -box volume in response to deformation from other parameters. +box volume in response to deformation from other parameters. This style +may be useful in scenarios where one wants to apply a constant deviatoric +pressure using *pressure* styles in the *x*, *y*, and *z* dimensions ( +deforming the shape of the box), while maintaining a constant volume. -The *pressure* style controls the box volume to maintain the mean pressure -of the system. This is accomplished by isotropically scaling all box -lengths :math:`L` by an additional factor of :math:`k (P_t - P_m)` where -:math:`k` is the proportional gain constant, :math:`P_t` is the target -pressure, and :math:`P_m` is the current mean pressure (the trace of the -pressure tensor). This style allows one to control the deviatoric strain -tensor while maintaining a fixed mean pressure. +The *pressure* style isotropically scales box lengths in an attempt to +maintain a target mean pressure (the trace of the pressure tensor) of the +system. This is accomplished by isotropically scaling all box lengths +:math:`L` by an additional factor of :math:`k (P_t - P_m)` where :math:`k` +is the proportional gain constant, :math:`P_t` is the target pressure, and +:math:`P_m` is the current mean pressure. This style may be useful in +scenarios where one wants to apply a constant deviatoric strain rate +using various strain-based styles (e.g. *trate*) along the *x*, *y*, and *z* +dimensions (deforming the shape of the box), while maintaining a mean pressure. ---------- -All of the tilt styles change the xy, xz, yz tilt factors during a -simulation. In LAMMPS, tilt factors (xy,xz,yz) for triclinic boxes -are normally bounded by half the distance of the parallel box length. -See the discussion of the *flip* keyword below, to allow this bound to -be exceeded, if desired. - -For example, if xlo = 2 and xhi = 12, then the x box length is 10 and -the xy tilt factor must be between -5 and 5. Similarly, both xz and -yz must be between -(xhi-xlo)/2 and +(yhi-ylo)/2. Note that this is -not a limitation, since if the maximum tilt factor is 5 (as in this -example), then configurations with tilt = ..., -15, -5, 5, 15, 25, -... are all equivalent. - -To obey this constraint and allow for large shear deformations to be -applied via the *xy*, *xz*, or *yz* parameters, the following -algorithm is used. If *prd* is the associated parallel box length (10 -in the example above), then if the tilt factor exceeds the accepted -range of -5 to 5 during the simulation, then the box is flipped to the -other limit (an equivalent box) and the simulation continues. Thus -for this example, if the initial xy tilt factor was 0.0 and "xy final -100.0" was specified, then during the simulation the xy tilt factor -would increase from 0.0 to 5.0, the box would be flipped so that the -tilt factor becomes -5.0, the tilt factor would increase from -5.0 to -5.0, the box would be flipped again, etc. The flip occurs 10 times -and the final tilt factor at the end of the simulation would be 0.0. -During each flip event, atoms are remapped into the new box in the -appropriate manner. - -The one exception to this rule is if the first dimension in the tilt -factor (x for xy) is non-periodic. In that case, the limits on the -tilt factor are not enforced, since flipping the box in that dimension -does not change the atom positions due to non-periodicity. In this -mode, if you tilt the system to extreme angles, the simulation will -simply become inefficient due to the highly skewed simulation box. - ----------- - -Each time the box size or shape is changed, the *remap* keyword -determines whether atom positions are remapped to the new box. If -*remap* is set to *x* (the default), atoms in the fix group are -remapped; otherwise they are not. Note that their velocities are not -changed, just their positions are altered. If *remap* is set to *v*, -then any atom in the fix group that crosses a periodic boundary will -have a delta added to its velocity equal to the difference in -velocities between the lo and hi boundaries. Note that this velocity -difference can include tilt components, e.g. a delta in the x velocity -when an atom crosses the y periodic boundary. If *remap* is set to -*none*, then neither of these remappings take place. - -Conceptually, setting *remap* to *x* forces the atoms to deform via an -affine transformation that exactly matches the box deformation. This -setting is typically appropriate for solids. Note that though the -atoms are effectively "moving" with the box over time, it is not due -to their having a velocity that tracks the box change, but only due to -the remapping. By contrast, setting *remap* to *v* is typically -appropriate for fluids, where you want the atoms to respond to the -change in box size/shape on their own and acquire a velocity that -matches the box change, so that their motion will naturally track the -box without explicit remapping of their coordinates. - -.. note:: - - When non-equilibrium MD (NEMD) simulations are performed using - this fix, the option "remap v" should normally be used. This is - because :doc:`fix nvt/sllod ` adjusts the atom positions - and velocities to induce a velocity profile that matches the changing - box size/shape. Thus atom coordinates should NOT be remapped by fix - deform, but velocities SHOULD be when atoms cross periodic boundaries, - since that is consistent with maintaining the velocity profile already - created by fix nvt/sllod. LAMMPS will warn you if the *remap* setting - is not consistent with fix nvt/sllod. - -.. note:: - - For non-equilibrium MD (NEMD) simulations using "remap v" it is - usually desirable that the fluid (or flowing material, e.g. granular - particles) stream with a velocity profile consistent with the - deforming box. As mentioned above, using a thermostat such as :doc:`fix nvt/sllod ` or :doc:`fix lavgevin ` - (with a bias provided by :doc:`compute temp/deform `), will typically accomplish - that. If you do not use a thermostat, then there is no driving force - pushing the atoms to flow in a manner consistent with the deforming - box. E.g. for a shearing system the box deformation velocity may vary - from 0 at the bottom to 10 at the top of the box. But the stream - velocity profile of the atoms may vary from -5 at the bottom to +5 at - the top. You can monitor these effects using the :doc:`fix ave/chunk `, :doc:`compute temp/deform `, and :doc:`compute temp/profile ` commands. One way to induce - atoms to stream consistent with the box deformation is to give them an - initial velocity profile, via the :doc:`velocity ramp ` - command, that matches the box deformation rate. This also typically - helps the system come to equilibrium more quickly, even if a - thermostat is used. - -.. note:: - - If a :doc:`fix rigid ` is defined for rigid bodies, and - *remap* is set to *x*, then the center-of-mass coordinates of rigid - bodies will be remapped to the changing simulation box. This will be - done regardless of whether atoms in the rigid bodies are in the fix - deform group or not. The velocity of the centers of mass are not - remapped even if *remap* is set to *v*, since :doc:`fix nvt/sllod ` does not currently do anything special - for rigid particles. If you wish to perform a NEMD simulation of - rigid particles, you can either thermostat them independently or - include a background fluid and thermostat the fluid via :doc:`fix nvt/sllod `. - -The *flip* keyword allows the tilt factors for a triclinic box to -exceed half the distance of the parallel box length, as discussed -above. If the *flip* value is set to *yes*, the bound is enforced by -flipping the box when it is exceeded. If the *flip* value is set to -*no*, the tilt will continue to change without flipping. Note that if -you apply large deformations, this means the box shape can tilt -dramatically LAMMPS will run less efficiently, due to the large volume -of communication needed to acquire ghost atoms around a processor's -irregular-shaped sub-domain. For extreme values of tilt, LAMMPS may -also lose atoms and generate an error. - -The *units* keyword determines the meaning of the distance units used -to define various arguments. A *box* value selects standard distance -units as defined by the :doc:`units ` command, e.g. Angstroms for -units = real or metal. A *lattice* value means the distance units are -in lattice spacings. The :doc:`lattice ` command must have -been previously used to define the lattice spacing. Note that the -units choice also affects the *vel* style parameters since it is -defined in terms of distance/time. Also note that the units keyword -does not affect the *variable* style. You should use the *xlat*, -*ylat*, *zlat* keywords of the :doc:`thermo_style ` -command if you want to include lattice spacings in a variable formula. +The *flip*, *remap*, and *units* keywords all behave identically +to those in :doc:`fix deform `. Additional optional +keywords are described below. .. _deform_normalize: The *normalize/pressure* keyword changes how box dimensions evolve when -using the *pressure* or *pressure/mean* deformation options. If the +using the *pressure* or *pressure/mean* deformation styles. If the *deform/normalize* value is set to *yes*, then the deviation from the target pressure is normalized by the absolute value of the target pressure such that the proportional gain constant scales a percentage @@ -680,7 +206,7 @@ described below, which will cap the divergence. The *max/rate* keyword sets an upper threshold, *rate*, that limits the maximum magnitude of the instantaneous strain rate applied in any dimension. This keyword only applies to the *pressure* and *pressure/mean* options. If -a pressure-controlled rate is used for both *iso* and either *x*, *y*, or +a pressure-controlled rate is used for both *box* and either *x*, *y*, or *z*, then this threshold will apply separately to each individual controller such that the cumulative strain rate on a box dimension may be up to twice the value of *rate*. @@ -695,15 +221,17 @@ are coupled. *Xyz* means all 3 diagonal components are coupled. Coupling means two things: the instantaneous stress will be computed as an average of the corresponding diagonal components, and the coupled box dimensions will be changed together in lockstep, meaning coupled dimensions will be -dilated or contracted by the same percentage every timestep. The target -pressures and gain constants for any coupled dimensions must be identical. -*Couple xyz* can be used for a 2d simulation; the *z* dimension is simply -ignored. +dilated or contracted by the same percentage every timestep. If a *pressure* +style is defined for more than one coupled dimension, the target pressures +and gain constants must be identical. Alternatively, if a *pressure* +style is only defined for one of the coupled dimensions, its settings are +copied to other dimensions with undefined styles. *Couple xyz* can be used +for a 2d simulation; the *z* dimension is simply ignored. .. _deform_balance: -The *vol/balance/p* keyword modifies the behavior of *volume* when two -dimensions are used to maintain a fixed volume. Instead of straining +The *vol/balance/p* keyword modifies the behavior of the *volume* style when +applied to two of the *x*, *y*, and *z* dimensions. Instead of straining the two dimensions in lockstep, the two dimensions are allowed to separately dilate or contract in a manner to maintain a constant volume while simultaneously trying to keep the pressure along each @@ -735,27 +263,22 @@ or pressure during thermodynamic output via the compute-ID. It also means that changing attributes of *thermo_temp* or *thermo_press* will have no effect on this fix. ----------- - -.. include:: accel_styles.rst - Restart, fix_modify, output, run start/stop, minimize info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" This fix will restore the initial box settings from :doc:`binary restart files `, which allows the fix to be properly continue deformation, when using the start/stop options of the :doc:`run ` -command. None of the :doc:`fix_modify ` options are -relevant to this fix. No global or per-atom quantities are stored by -this fix for access by various :doc:`output commands `. +command. No global or per-atom quantities are stored by this fix for access +by various :doc:`output commands `. If any pressure controls are used, the :doc:`fix_modify ` *temp* -and *press* options are supported by this fix. You can use them to assign a -:doc:`compute ` you have defined to this fix which will be used -in its temperature and pressure calculations. If you do this, note -that the kinetic energy derived from the compute temperature should be -consistent with the virial term computed using all atoms for the -pressure. LAMMPS will warn you if you choose to compute temperature -on a subset of atoms. +and *press* options are supported by this fix, unklike in :doc:`fix deform `. +You can use them to assign a :doc:`compute ` you have defined to +this fix which will be used in its temperature and pressure calculations. +If you do this, note that the kinetic energy derived from the compute +temperature should be consistent with the virial term computed using all +atoms for the pressure. LAMMPS will warn you if you choose to compute +temperature on a subset of atoms. This fix can perform deformation over multiple runs, using the *start* and *stop* keywords of the :doc:`run ` command. See the @@ -775,7 +298,7 @@ xy) that is shrink-wrapped via the :doc:`boundary ` command. Related commands """""""""""""""" -:doc:`change_box ` +:doc:`fix deform `, :doc:`change_box ` Default """"""" diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index 26dd85b78b..5eafebc9de 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -794,8 +794,6 @@ void FixDeformPressure::write_restart(FILE *fp) if (comm->me == 0) { int size = 9 * sizeof(double) + 7 * sizeof(Set) + 7 * sizeof(SetExtra); fwrite(&size, sizeof(int), 1, fp); - fwrite(h_rate, sizeof(double), 6, fp); - fwrite(h_ratelo, sizeof(double), 3, fp); fwrite(set, sizeof(Set), 6, fp); fwrite(&set_box, sizeof(Set), 1, fp); fwrite(set_extra, sizeof(SetExtra), 7, fp); diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 4b774b79d3..6a585d8b26 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -372,16 +372,6 @@ irregular(nullptr), set(nullptr) if (force_reneighbor) irregular = new Irregular(lmp); else irregular = nullptr; - - // initialize all rates to 0.0 in constructor instead of init so values persist - // across run statements and ghosts have correct velocities until the destructor - h_rate = domain->h_rate; - h_ratelo = domain->h_ratelo; - - for (int i = 0; i < 3; i++) - h_rate[i] = h_ratelo[i] = 0.0; - for (int i = 3; i < 6; i++) - h_rate[i] = 0.0; } /* ---------------------------------------------------------------------- */ @@ -597,13 +587,18 @@ void FixDeform::init() } // set domain->h_rate values for use by domain and other fixes/computes + // initialize all rates to 0.0 // cannot set here for TRATE,VOLUME,WIGGLE,VARIABLE since not constant + h_rate = domain->h_rate; + h_ratelo = domain->h_ratelo; + for (int i = 0; i < 3; i++) { + h_rate[i] = h_ratelo[i] = 0.0; if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == SCALE || set[i].style == VEL || set[i].style == ERATE) { - double dlo_dt,dhi_dt; + double dlo_dt, dhi_dt; if (delt != 0.0) { dlo_dt = (set[i].lo_stop - set[i].lo_start) / delt; dhi_dt = (set[i].hi_stop - set[i].hi_start) / delt; @@ -614,6 +609,7 @@ void FixDeform::init() } for (int i = 3; i < 6; i++) { + h_rate[i] = 0.0; if (set[i].style == FINAL || set[i].style == DELTA || set[i].style == VEL || set[i].style == ERATE) { if (delt != 0.0) @@ -961,10 +957,8 @@ void FixDeform::update_domain() void FixDeform::write_restart(FILE *fp) { if (comm->me == 0) { - int size = 9 * sizeof(double) + 6 * sizeof(Set); + int size = 6 * sizeof(Set); fwrite(&size, sizeof(int), 1, fp); - fwrite(h_rate, sizeof(double), 6, fp); - fwrite(h_ratelo, sizeof(double), 3, fp); fwrite(set, sizeof(Set), 6, fp); } } @@ -975,15 +969,8 @@ void FixDeform::write_restart(FILE *fp) void FixDeform::restart(char *buf) { - int n = 0; - auto list = (double *) buf; - for (int i = 0; i < 6; i++) - h_rate[i] = list[n++]; - for (int i = 0; i < 3; i++) - h_ratelo[i] = list[n++]; - int samestyle = 1; - Set *set_restart = (Set *) &buf[n * sizeof(double)]; + Set *set_restart = (Set *) buf; for (int i = 0; i < 6; ++i) { // restore data from initial state set[i].lo_initial = set_restart[i].lo_initial; From 16b631858f99ba44eb945e97d5b236c054a9329e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 21 Feb 2024 10:02:01 -0500 Subject: [PATCH 065/185] fix typo --- cmake/presets/kokkos-cuda.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/presets/kokkos-cuda.cmake b/cmake/presets/kokkos-cuda.cmake index 3205387044..878ce0c566 100644 --- a/cmake/presets/kokkos-cuda.cmake +++ b/cmake/presets/kokkos-cuda.cmake @@ -10,7 +10,7 @@ get_filename_component(NVCC_WRAPPER_CMD ${CMAKE_CURRENT_SOURCE_DIR}/../lib/kokko set(CMAKE_CXX_COMPILER ${NVCC_WRAPPER_CMD} CACHE FILEPATH "" FORCE) # If KSPACE is also enabled, use CUFFT for FFTs -set(FFT_KOKKOS "CUFFT" CACHE STRING FORCE) +set(FFT_KOKKOS "CUFFT" CACHE STRING "" FORCE) # hide deprecation warnings temporarily for stable release set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE) From e143bbb4dd69f4e6aabd86374d5f6f7daf3e28b8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 21 Feb 2024 10:49:31 -0500 Subject: [PATCH 066/185] use a more "CMake" way to link to cuFFT with check in CMake config run --- cmake/Modules/Packages/KOKKOS.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/Packages/KOKKOS.cmake b/cmake/Modules/Packages/KOKKOS.cmake index ce55c83b08..fa2201c595 100644 --- a/cmake/Modules/Packages/KOKKOS.cmake +++ b/cmake/Modules/Packages/KOKKOS.cmake @@ -139,8 +139,9 @@ if(PKG_KSPACE) message(WARNING "Using KISS FFT with the CUDA backend of Kokkos may be sub-optimal.") target_compile_definitions(lammps PRIVATE -DFFT_KOKKOS_KISS) elseif(FFT_KOKKOS STREQUAL "CUFFT") + find_library(CUFFT_LIBRARY cufft) target_compile_definitions(lammps PRIVATE -DFFT_KOKKOS_CUFFT) - target_link_libraries(lammps PRIVATE cufft) + target_link_libraries(lammps PRIVATE ${CUFFT_LIBRARY}) endif() elseif(Kokkos_ENABLE_HIP) if(NOT ((FFT_KOKKOS STREQUAL "KISS") OR (FFT_KOKKOS STREQUAL "HIPFFT"))) From e20ea968b930184bec9eb0d273caee48026f88fc Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Wed, 21 Feb 2024 20:49:19 +0300 Subject: [PATCH 067/185] Add some clarifications to the doc --- doc/src/fix_wall_flow.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/src/fix_wall_flow.rst b/doc/src/fix_wall_flow.rst index 5fc9f5367c..b40ba9697f 100644 --- a/doc/src/fix_wall_flow.rst +++ b/doc/src/fix_wall_flow.rst @@ -66,7 +66,10 @@ N+1 walls. Each time a particle in the specified group passes through one of the transparent walls, its velocity is re-assigned. Particles not in the -group do not interact with the wall. +group do not interact with the wall. This can be used, for example, to +add obstacles composed of atoms, or to simulate a solution of complex +molecules in a one-atom liquid (note that the fix has been tested for +one-atom systems only). Conceptually, the velocity re-assignment represents creation of a new particle within the system with simultaneous removal of the particle @@ -147,6 +150,10 @@ if LAMMPS was built with that package. See the :doc:`Build package Flow boundary conditions should not be used with rigid bodies such as those defined by a "fix rigid" command. +This fix can only be used with periodic boundary conditions along the +flow axis. The size of the box in this direction must not change. Also, +the fix is designed to work only in an orthogonal simulation box. + Related commands """""""""""""""" From 0f34c1ec6e49dbc34c398b142db88259b550f701 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Wed, 21 Feb 2024 21:16:21 +0300 Subject: [PATCH 068/185] Add check for triclinic and periodic boundary --- src/EXTRA-FIX/fix_wall_flow.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 586cfa7382..15b82b45b8 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -62,6 +62,9 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : if (lmp->citeme) lmp->citeme->add(cite_fix_wall_flow_c); if (narg < 9) utils::missing_cmd_args(FLERR, "fix wall/flow", error); + if (domain->triclinic != 0) + error->all(FLERR, "Fix wall/flow cannot be used with triclinic simulation box"); + dynamic_group_allow = 1; bool do_abort = false; @@ -77,6 +80,10 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR, "Illegal fix wall/flow argument: axis must by x or y or z, but {} specified", arg[iarg]); + if (domain->periodicity[flowax] != 1) + error->all(FLERR, + "Fix wall/flow cannot be used with a non-periodic boundary along the flow axis"); + ++iarg; // parsing velocity flowvel = utils::numeric(FLERR, arg[iarg], do_abort, lmp); @@ -137,6 +144,12 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : "Wrong fix wall/flow wall ordering or some walls are outside simulation domain"); } + if (std::adjacent_find(walls.begin(), walls.end()) != walls.end()) { + error->all(FLERR, + "Wrong fix wall/flow wall coordinates: some walls have the same coordinates or lie " + "on the boundary"); + } + memory->grow(current_segment, atom->nmax, "WallFlow::current_segment"); atom->add_callback(Atom::GROW); if (restart_peratom) atom->add_callback(Atom::RESTART); From cd4c97f8d8f8a7a111d0ab7de17185446ef60f40 Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Wed, 21 Feb 2024 14:18:26 -0700 Subject: [PATCH 069/185] doc adjust and code comments --- doc/src/fix_deform.rst | 183 ++++++++++++++++---------- doc/src/fix_deform_pressure.rst | 147 +++++++++++---------- src/EXTRA-FIX/fix_deform_pressure.cpp | 6 +- src/fix_deform.cpp | 6 +- 4 files changed, 201 insertions(+), 141 deletions(-) diff --git a/doc/src/fix_deform.rst b/doc/src/fix_deform.rst index c0ea50ae41..e882c22bf6 100644 --- a/doc/src/fix_deform.rst +++ b/doc/src/fix_deform.rst @@ -4,6 +4,9 @@ fix deform command ================== +:doc:`fix deform/pressure ` command +================== + Accelerator Variants: *deform/kk* Syntax @@ -11,18 +14,18 @@ Syntax .. code-block:: LAMMPS - fix ID group-ID deform N parameter args ... keyword value ... + fix ID group-ID fixstyle N parameter style args ... keyword value ... * ID, group-ID are documented in :doc:`fix ` command -* deform = style name of this fix command +* fixstyle = *deform* or *deform/pressure* * N = perform box deformation every this many timesteps -* one or more parameter/arg pairs may be appended +* one or more parameter/style/args sequences of arguments may be appended .. parsed-literal:: parameter = *x* or *y* or *z* or *xy* or *xz* or *yz* *x*, *y*, *z* args = style value(s) - style = *final* or *delta* or *scale* or *vel* or *erate* or *trate* or *volume* or *wiggle* or *variable* + style = *final* or *delta* or *scale* or *vel* or *erate* or *trate* or *volume* or *wiggle* or *variable* or *pressure* or *pressure/mean* *final* values = lo hi lo hi = box boundaries at end of run (distance units) *delta* values = dlo dhi @@ -43,6 +46,13 @@ Syntax *variable* values = v_name1 v_name2 v_name1 = variable with name1 for box length change as function of time v_name2 = variable with name2 for change rate as function of time + *pressure* values = target gain (ONLY available in :doc:`fix deform/pressure ` command) + target = target pressure (pressure units) + gain = proportional gain constant (1/(time * pressure) or 1/time units) + *pressure/mean* values = target gain (ONLY available in :doc:`fix deform/pressure ` command) + target = target pressure (pressure units) + gain = proportional gain constant (1/(time * pressure) or 1/time units) + *xy*, *xz*, *yz* args = style value style = *final* or *delta* or *vel* or *erate* or *trate* or *wiggle* or *variable* *final* value = tilt @@ -62,9 +72,12 @@ Syntax *variable* values = v_name1 v_name2 v_name1 = variable with name1 for tilt change as function of time v_name2 = variable with name2 for change rate as function of time + *pressure* values = target gain (ONLY available in :doc:`fix deform/pressure ` command) + target = target pressure (pressure units) + gain = proportional gain constant (1/(time * pressure) or 1/time units) * zero or more keyword/value pairs may be appended -* keyword = *remap* or *flip* or *units* +* keyword = *remap* or *flip* or *units* or *couple* or *vol/balance/p* or *max/rate* or *normalize/pressure* .. parsed-literal:: @@ -77,6 +90,15 @@ Syntax *units* value = *lattice* or *box* lattice = distances are defined in lattice units box = distances are defined in simulation box units + *couple* value = *none* or *xyz* or *xy* or *yz* or *xz* (ONLY available in :doc:`fix deform/pressure ` command) + couple pressure values of various dimensions + *vol/balance/p* value = *yes* or *no* (ONLY available in :doc:`fix deform/pressure ` command) + Modifies the behavior of the *volume* option to try and balance pressures + *max/rate* value = *rate* (ONLY available in :doc:`fix deform/pressure ` command) + rate = maximum strain rate for pressure control + *normalize/pressure* value = *yes* or *no* (ONLY available in :doc:`fix deform/pressure ` command) + Modifies pressure controls such that the deviation in pressure is normalized by the target pressure + Examples """""""" @@ -88,6 +110,8 @@ Examples fix 1 all deform 1 xy erate 0.001 remap v fix 1 all deform 10 y delta -0.5 0.5 xz vel 1.0 + See examples for :doc:`fix deform/pressure ` on its doc page + Description """"""""""" @@ -95,31 +119,46 @@ Change the volume and/or shape of the simulation box during a dynamics run. Orthogonal simulation boxes have 3 adjustable parameters (x,y,z). Triclinic (non-orthogonal) simulation boxes have 6 adjustable parameters (x,y,z,xy,xz,yz). Any or all of them can be -adjusted independently and simultaneously by this command. For -additional pressure-based controls, see -:doc:`fix deform/pressure `. +adjusted independently and simultaneously. -This fix can be used to perform non-equilibrium MD (NEMD) simulations -of a continuously strained system. See the :doc:`fix nvt/sllod ` and :doc:`compute temp/deform ` commands for more details. Note -that simulation of a continuously extended system (extensional flow) -can be modeled using the :ref:`UEF package ` and its :doc:`fix commands `. +The fix deform command allows use of all the arguments listed above, +except those flagged as available ONLY for the :doc:`fix +deform/pressure ` command, which are +pressure-based controls. The fix deform/pressure command allows use +of all the arguments listed above. + +The rest of this doc page explains the options common to both +commands. The :doc:`fix deform/pressure ` doc +page explains the options available ONLY with the fix deform/pressure +command. Note that a simulation can define only a single deformation +command: fix deform or fix deform/pressure. + +Both these fixes can be used to perform non-equilibrium MD (NEMD) +simulations of a continuously strained system. See the :doc:`fix +nvt/sllod ` and :doc:`compute temp/deform +` commands for more details. Note that +simulation of a continuously extended system (extensional flow) can be +modeled using the :ref:`UEF package ` and its :doc:`fix +commands `. For the *x*, *y*, *z* parameters, the associated dimension cannot be shrink-wrapped. For the *xy*, *yz*, *xz* parameters, the associated -second dimension cannot be shrink-wrapped. Dimensions not varied by this -command can be periodic or non-periodic. Dimensions corresponding to -unspecified parameters can also be controlled by a :doc:`fix npt ` or :doc:`fix nph ` command. +second dimension cannot be shrink-wrapped. Dimensions not varied by +this command can be periodic or non-periodic. Dimensions +corresponding to unspecified parameters can also be controlled by a +:doc:`fix npt ` or :doc:`fix nph ` command. The size and shape of the simulation box at the beginning of the -simulation run were either specified by the -:doc:`create_box ` or :doc:`read_data ` or -:doc:`read_restart ` command used to setup the simulation -initially if it is the first run, or they are the values from the end -of the previous run. The :doc:`create_box `, :doc:`read data `, and :doc:`read_restart ` commands -specify whether the simulation box is orthogonal or non-orthogonal -(triclinic) and explain the meaning of the xy,xz,yz tilt factors. If -fix deform changes the xy,xz,yz tilt factors, then the simulation box -must be triclinic, even if its initial tilt factors are 0.0. +simulation run were either specified by the :doc:`create_box +` or :doc:`read_data ` or :doc:`read_restart +` command used to setup the simulation initially if it +is the first run, or they are the values from the end of the previous +run. The :doc:`create_box `, :doc:`read data +`, and :doc:`read_restart ` commands specify +whether the simulation box is orthogonal or non-orthogonal (triclinic) +and explain the meaning of the xy,xz,yz tilt factors. If fix deform +changes the xy,xz,yz tilt factors, then the simulation box must be +triclinic, even if its initial tilt factors are 0.0. As described below, the desired simulation box size and shape at the end of the run are determined by the parameters of the fix deform @@ -260,21 +299,22 @@ of the units keyword below. The *variable* style changes the specified box length dimension by evaluating a variable, which presumably is a function of time. The -variable with *name1* must be an :doc:`equal-style variable ` -and should calculate a change in box length in units of distance. -Note that this distance is in box units, not lattice units; see the -discussion of the *units* keyword below. The formula associated with -variable *name1* can reference the current timestep. Note that it -should return the "change" in box length, not the absolute box length. -This means it should evaluate to 0.0 when invoked on the initial -timestep of the run following the definition of fix deform. It should -evaluate to a value > 0.0 to dilate the box at future times, or a -value < 0.0 to compress the box. +variable with *name1* must be an :doc:`equal-style variable +` and should calculate a change in box length in units of +distance. Note that this distance is in box units, not lattice units; +see the discussion of the *units* keyword below. The formula +associated with variable *name1* can reference the current timestep. +Note that it should return the "change" in box length, not the +absolute box length. This means it should evaluate to 0.0 when +invoked on the initial timestep of the run following the definition of +fix deform. It should evaluate to a value > 0.0 to dilate the box at +future times, or a value < 0.0 to compress the box. -The variable *name2* must also be an :doc:`equal-style variable ` and should calculate the rate of box length -change, in units of distance/time, i.e. the time-derivative of the -*name1* variable. This quantity is used internally by LAMMPS to reset -atom velocities when they cross periodic boundaries. It is computed +The variable *name2* must also be an :doc:`equal-style variable +` and should calculate the rate of box length change, in +units of distance/time, i.e. the time-derivative of the *name1* +variable. This quantity is used internally by LAMMPS to reset atom +velocities when they cross periodic boundaries. It is computed internally for the other styles, but you must provide it when using an arbitrary variable. @@ -416,12 +456,13 @@ can reference the current timestep. Note that it should return the should evaluate to 0.0 when invoked on the initial timestep of the run following the definition of fix deform. -The variable *name2* must also be an :doc:`equal-style variable ` and should calculate the rate of tilt change, -in units of distance/time, i.e. the time-derivative of the *name1* -variable. This quantity is used internally by LAMMPS to reset atom -velocities when they cross periodic boundaries. It is computed -internally for the other styles, but you must provide it when using an -arbitrary variable. +The variable *name2* must also be an :doc:`equal-style variable +` and should calculate the rate of tilt change, in units of +distance/time, i.e. the time-derivative of the *name1* variable. This +quantity is used internally by LAMMPS to reset atom velocities when +they cross periodic boundaries. It is computed internally for the +other styles, but you must provide it when using an arbitrary +variable. Here is an example of using the *variable* style to perform the same box deformation as the *wiggle* style formula listed above, where we @@ -512,33 +553,40 @@ box without explicit remapping of their coordinates. .. note:: For non-equilibrium MD (NEMD) simulations using "remap v" it is - usually desirable that the fluid (or flowing material, e.g. granular - particles) stream with a velocity profile consistent with the - deforming box. As mentioned above, using a thermostat such as :doc:`fix nvt/sllod ` or :doc:`fix lavgevin ` - (with a bias provided by :doc:`compute temp/deform `), will typically accomplish - that. If you do not use a thermostat, then there is no driving force - pushing the atoms to flow in a manner consistent with the deforming - box. E.g. for a shearing system the box deformation velocity may vary + usually desirable that the fluid (or flowing material, + e.g. granular particles) stream with a velocity profile consistent + with the deforming box. As mentioned above, using a thermostat + such as :doc:`fix nvt/sllod ` or :doc:`fix lavgevin + ` (with a bias provided by :doc:`compute temp/deform + `), will typically accomplish that. If you do + not use a thermostat, then there is no driving force pushing the + atoms to flow in a manner consistent with the deforming box. + E.g. for a shearing system the box deformation velocity may vary from 0 at the bottom to 10 at the top of the box. But the stream - velocity profile of the atoms may vary from -5 at the bottom to +5 at - the top. You can monitor these effects using the :doc:`fix ave/chunk `, :doc:`compute temp/deform `, and :doc:`compute temp/profile ` commands. One way to induce - atoms to stream consistent with the box deformation is to give them an + velocity profile of the atoms may vary from -5 at the bottom to +5 + at the top. You can monitor these effects using the :doc:`fix + ave/chunk `, :doc:`compute temp/deform + `, and :doc:`compute temp/profile + ` commands. One way to induce atoms to + stream consistent with the box deformation is to give them an initial velocity profile, via the :doc:`velocity ramp ` - command, that matches the box deformation rate. This also typically - helps the system come to equilibrium more quickly, even if a - thermostat is used. + command, that matches the box deformation rate. This also + typically helps the system come to equilibrium more quickly, even + if a thermostat is used. .. note:: If a :doc:`fix rigid ` is defined for rigid bodies, and *remap* is set to *x*, then the center-of-mass coordinates of rigid - bodies will be remapped to the changing simulation box. This will be - done regardless of whether atoms in the rigid bodies are in the fix - deform group or not. The velocity of the centers of mass are not - remapped even if *remap* is set to *v*, since :doc:`fix nvt/sllod ` does not currently do anything special + bodies will be remapped to the changing simulation box. This will + be done regardless of whether atoms in the rigid bodies are in the + fix deform group or not. The velocity of the centers of mass are + not remapped even if *remap* is set to *v*, since :doc:`fix + nvt/sllod ` does not currently do anything special for rigid particles. If you wish to perform a NEMD simulation of rigid particles, you can either thermostat them independently or - include a background fluid and thermostat the fluid via :doc:`fix nvt/sllod `. + include a background fluid and thermostat the fluid via :doc:`fix + nvt/sllod `. The *flip* keyword allows the tilt factors for a triclinic box to exceed half the distance of the parallel box length, as discussed @@ -570,7 +618,8 @@ command if you want to include lattice spacings in a variable formula. Restart, fix_modify, output, run start/stop, minimize info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" -This fix will restore the initial box settings from :doc:`binary restart files `, which allows the fix to be properly continue +This fix will restore the initial box settings from :doc:`binary +restart files `, which allows the fix to be properly continue deformation, when using the start/stop options of the :doc:`run ` command. None of the :doc:`fix_modify ` options are relevant to this fix. No global or per-atom quantities are stored by @@ -588,13 +637,15 @@ Restrictions You cannot apply x, y, or z deformations to a dimension that is shrink-wrapped via the :doc:`boundary ` command. -You cannot apply xy, yz, or xz deformations to a second dimension (y in -xy) that is shrink-wrapped via the :doc:`boundary ` command. +You cannot apply xy, yz, or xz deformations to a second dimension (y +in xy) that is shrink-wrapped via the :doc:`boundary ` +command. Related commands """""""""""""""" -:doc:`fix deform/pressure `, :doc:`change_box ` +:doc:`fix deform/pressure `, :doc:`change_box + ` Default """"""" diff --git a/doc/src/fix_deform_pressure.rst b/doc/src/fix_deform_pressure.rst index d45c10b351..64bf210446 100644 --- a/doc/src/fix_deform_pressure.rst +++ b/doc/src/fix_deform_pressure.rst @@ -8,12 +8,12 @@ Syntax .. parsed-literal:: - fix ID group-ID deform N parameter args ... keyword value ... + fix ID group-ID deform/pressure N parameter style args ... keyword value ... * ID, group-ID are documented in :doc:`fix ` command -* deform = style name of this fix command +* deform/pressure = style name of this fix command * N = perform box deformation every this many timesteps -* one or more parameter/arg pairs may be appended +* one or more parameter/arg sequences may be appended .. parsed-literal:: @@ -26,13 +26,15 @@ Syntax *pressure/mean* values = target gain target = target pressure (pressure units) gain = proportional gain constant (1/(time * pressure) or 1/time units) - All other styles operate identically to those in :doc:`fix deform ` + NOTE: All other styles are documented by the :doc:`fix deform ` command + *xy*, *xz*, *yz* args = style value style = *final* or *delta* or *vel* or *erate* or *trate* or *wiggle* or *variable* or *pressure* *pressure* values = target gain target = target pressure (pressure units) gain = proportional gain constant (1/(time * pressure) or 1/time units) - All other styles operate identically to those in :doc:`fix deform ` + NOTE: All other styles are documented by the :doc:`fix deform ` command + *box* = style value style = *volume* or *pressure* *volume* value = none = isotropically adjust system to preserve volume of system @@ -53,7 +55,7 @@ Syntax rate = maximum strain rate for pressure control *normalize/pressure* value = *yes* or *no* Modifies pressure controls such that the deviation in pressure is normalized by the target pressure - All other options operate identically to those in :doc:`fix deform ` + NOTE: All other keywords are documented by the :doc:`fix deform ` command Examples """""""" @@ -67,19 +69,20 @@ Examples Description """"""""""" -This fix is an extension of :doc:`fix deform `, inheriting -all of its features and adding new pressure-based controls to allow for -new deformation protocols. All details in :doc:`fix deform ` -apply to this fix unless otherwise noted. +This fix is an extension of the :doc:`fix deform ` +command, which allows all of its options to be used as well as new +pressure-based controls implemented by this command. + +All arguments described on the :doc:`fix deform ` doc page +also apply to this fix unless otherwise noted below. The rest of this +doc page explains the arguments specific to this fix. Note that a +simulation can define only a single deformation command: fix deform or +fix deform/pressure. ---------- -For the *x*, *y*, and *z* parameters, this is the meaning of their -styles and values. - -The *final*, *delta*, *scale*, *vel*, *erate*, *trate*, *volume*, -*wiggle*, and *variable* styles all behave identically to those in -:doc:`fix deform `. Additional styles are described below. +For the *x*, *y*, and *z* parameters, this is the meaning of the +styles and values provided by this fix. The *pressure* style adjusts a dimension's box length to control the corresponding component of the pressure tensor. This option attempts to @@ -127,13 +130,9 @@ along one dimension. ---------- -For the *xy*, *xz*, and *yz* parameters, this is the meaning of their -styles and values. Note that changing the tilt factors of a triclinic -box does not change its volume. - -The *final*, *delta*, *vel*, *erate*, *trate*, *wiggle*, and *variable* -styles all behave identically to those in :doc:`fix deform `. -Additional styles are described below. +For the *xy*, *xz*, and *yz* parameters, this is the meaning of the +styles and values provided by this fix. Note that changing the +tilt factors of a triclinic box does not change its volume. The *pressure* style adjusts a tilt factor to control the corresponding off-diagonal component of the pressure tensor. This option attempts to @@ -144,29 +143,32 @@ tilt factor T evolves according to the equation \frac{d T(t)}{dt} = L(t) k (P - P_t) -where :math:`k` is a proportional gain constant, :math:`P_t` is the target -pressure, :math:`P` is the current pressure, and :math:`L` is the perpendicular -box length. The target pressure accepts either a constant numeric value or a -LAMMPS :ref:`variable `. Notably, this variable can be a function -of time or other components of the pressure tensor. By default, :math:`k` -has units of 1/(time * pressure) although this will change if the -*normalize/pessure* option is set as :ref:`discussed below `. -There is no proven method to choosing an appropriate value of :math:`k` as it -will depend on thespecific details of a simulation and testing different -values is recommended. One can also apply a maximum limit to the magnitude -of the applied strain using the :ref:`max/rate ` option. +where :math:`k` is a proportional gain constant, :math:`P_t` is the +target pressure, :math:`P` is the current pressure, and :math:`L` is +the perpendicular box length. The target pressure accepts either a +constant numeric value or a LAMMPS :ref:`variable +`. Notably, this variable can be a function of time or other +components of the pressure tensor. By default, :math:`k` has units of +1/(time * pressure) although this will change if the +*normalize/pessure* option is set as :ref:`discussed below +`. There is no proven method to choosing an +appropriate value of :math:`k` as it will depend on the specific +details of a simulation and testing different values is +recommended. One can also apply a maximum limit to the magnitude of +the applied strain using the :ref:`max/rate ` option. ---------- -The *box* parameter provides an additonal control over the *x*, *y*, -and *z* box lengths by isotropically dilating or contracting the box to -either maintain a fixed mean pressure or volume. This isotropic scaling -is applied after the box is deformed by the above *x*, *y*, *z*, *xy*, -*xz*, and *yz* styles, acting as a second deformation step. This parameter -will change the overall strain rate in the *x*, *y*, or *z* dimensions. -This parameter can only be used in combination with the *x*, *y*, or *z* -commands: *vel*, *erate*, *trate*, *pressure*, or *wiggle*. This is the meaning -of its styles and values. +The *box* parameter provides an additional control over the *x*, *y*, +and *z* box lengths by isotropically dilating or contracting the box +to either maintain a fixed mean pressure or volume. This isotropic +scaling is applied after the box is deformed by the above *x*, *y*, +*z*, *xy*, *xz*, and *yz* styles, acting as a second deformation +step. This parameter will change the overall strain rate in the *x*, +*y*, or *z* dimensions. This parameter can only be used in +combination with the *x*, *y*, or *z* commands: *vel*, *erate*, +*trate*, *pressure*, or *wiggle*. This is the meaning of its styles +and values. The *volume* style isotropically scales box lengths to maintain a constant box volume in response to deformation from other parameters. This style @@ -186,9 +188,7 @@ dimensions (deforming the shape of the box), while maintaining a mean pressure. ---------- -The *flip*, *remap*, and *units* keywords all behave identically -to those in :doc:`fix deform `. Additional optional -keywords are described below. +The optional keywords provided by this fix are described below. .. _deform_normalize: @@ -240,44 +240,47 @@ dimension equal using a method described in :ref:`(Huang2014) `. ---------- If any pressure controls are used, this fix computes a temperature and -pressure each timestep. To do this, the fix creates its own computes of -style "temp" and "pressure", as if these commands had been issued: +pressure each timestep. To do this, the fix creates its own computes +of style "temp" and "pressure", as if these commands had been issued: .. code-block:: LAMMPS compute fix-ID_temp group-ID temp compute fix-ID_press group-ID pressure fix-ID_temp -See the :doc:`compute temp ` and :doc:`compute pressure ` commands for details. Note that the -IDs of the new computes are the fix-ID + underscore + "temp" or fix_ID +See the :doc:`compute temp ` and :doc:`compute pressure +` commands for details. Note that the IDs of the +new computes are the fix-ID + underscore + "temp" or fix_ID + underscore + "press", and the group for the new computes is the same as the fix group. Note that these are NOT the computes used by thermodynamic output (see -the :doc:`thermo_style ` command) with ID = *thermo_temp* -and *thermo_press*. This means you can change the attributes of this -fix's temperature or pressure via the -:doc:`compute_modify ` command or print this temperature -or pressure during thermodynamic output via the -:doc:`thermo_style custom ` command using the appropriate -compute-ID. It also means that changing attributes of *thermo_temp* or -*thermo_press* will have no effect on this fix. +the :doc:`thermo_style ` command) with ID = +*thermo_temp* and *thermo_press*. This means you can change the +attributes of this fix's temperature or pressure via the +:doc:`compute_modify ` command or print this +temperature or pressure during thermodynamic output via the +:doc:`thermo_style custom ` command using the +appropriate compute-ID. It also means that changing attributes of +*thermo_temp* or *thermo_press* will have no effect on this fix. Restart, fix_modify, output, run start/stop, minimize info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" -This fix will restore the initial box settings from :doc:`binary restart files `, which allows the fix to be properly continue +This fix will restore the initial box settings from :doc:`binary +restart files `, which allows the fix to be properly continue deformation, when using the start/stop options of the :doc:`run ` -command. No global or per-atom quantities are stored by this fix for access -by various :doc:`output commands `. +command. No global or per-atom quantities are stored by this fix for +access by various :doc:`output commands `. -If any pressure controls are used, the :doc:`fix_modify ` *temp* -and *press* options are supported by this fix, unklike in :doc:`fix deform `. -You can use them to assign a :doc:`compute ` you have defined to -this fix which will be used in its temperature and pressure calculations. -If you do this, note that the kinetic energy derived from the compute -temperature should be consistent with the virial term computed using all -atoms for the pressure. LAMMPS will warn you if you choose to compute +If any pressure controls are used, the :doc:`fix_modify ` +*temp* and *press* options are supported by this fix, unlike in +:doc:`fix deform `. You can use them to assign a +:doc:`compute ` you have defined to this fix which will be +used in its temperature and pressure calculations. If you do this, +note that the kinetic energy derived from the compute temperature +should be consistent with the virial term computed using all atoms for +the pressure. LAMMPS will warn you if you choose to compute temperature on a subset of atoms. This fix can perform deformation over multiple runs, using the *start* @@ -292,8 +295,9 @@ Restrictions You cannot apply x, y, or z deformations to a dimension that is shrink-wrapped via the :doc:`boundary ` command. -You cannot apply xy, yz, or xz deformations to a second dimension (y in -xy) that is shrink-wrapped via the :doc:`boundary ` command. +You cannot apply xy, yz, or xz deformations to a second dimension (y +in xy) that is shrink-wrapped via the :doc:`boundary ` +command. Related commands """""""""""""""" @@ -303,8 +307,7 @@ Related commands Default """"""" -The option defaults are remap = x, flip = yes, units = lattice, and -normalize/pressure = no. +The option defaults are normalize/pressure = no. ---------- diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index 5eafebc9de..d8374bcc75 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -55,7 +55,7 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : memset(set_extra, 0, 7 * sizeof(SetExtra)); memset(&set_box, 0, sizeof(Set)); - // parse child-specific arguments + // parse only parameter/style arguments specific to this child class int index, iarg; int i = 0; @@ -115,6 +115,7 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : set_extra[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); i += 4; } else error->all(FLERR, "Illegal fix deform/pressure command: {}", arg[iarg + 1]); + } else if (strcmp(arg[iarg], "box") == 0) { if (strcmp(arg[iarg + 1], "volume") == 0) { set_box.style = VOLUME; @@ -850,7 +851,6 @@ void FixDeformPressure::restart(char *buf) } } - /* ---------------------------------------------------------------------- */ void FixDeformPressure::options(int i, int narg, char **arg) @@ -860,6 +860,8 @@ void FixDeformPressure::options(int i, int narg, char **arg) vol_balance_flag = 0; normalize_pressure_flag = 0; + // parse only options not handled by parent class + int iarg, nskip; while (i < leftover_iarg.size()) { iarg = leftover_iarg[i]; diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 6a585d8b26..9ee7259482 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -72,7 +72,8 @@ irregular(nullptr), set(nullptr) set = new Set[6]; memset(set, 0, 6 * sizeof(Set)); - // parse arguments + // parse all parameter/style arguments for this parent and also child classes + // for child classes, simply store them in leftover_iarg and skip over them triclinic = domain->triclinic; @@ -1009,6 +1010,9 @@ void FixDeform::options(int narg, char **arg) {"vol/balance/p", 2}}); } + // parse all optional arguments for this parent and also child classes + // for child classes, simply store them in leftover_iarg and skip over them + int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg], "remap") == 0) { From 11675587df2666d7309a39fcbdcd82428ae8090a Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Wed, 21 Feb 2024 14:28:53 -0700 Subject: [PATCH 070/185] tweak to underlining --- doc/src/fix_deform.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/fix_deform.rst b/doc/src/fix_deform.rst index e882c22bf6..7f81bcf68d 100644 --- a/doc/src/fix_deform.rst +++ b/doc/src/fix_deform.rst @@ -5,7 +5,7 @@ fix deform command ================== :doc:`fix deform/pressure ` command -================== +======================================================== Accelerator Variants: *deform/kk* @@ -110,7 +110,7 @@ Examples fix 1 all deform 1 xy erate 0.001 remap v fix 1 all deform 10 y delta -0.5 0.5 xz vel 1.0 - See examples for :doc:`fix deform/pressure ` on its doc page +See examples for :doc:`fix deform/pressure ` on its doc page Description """"""""""" From 06b69f2d401aecf17a26760e0480fa9141a74696 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 21 Feb 2024 17:35:28 -0500 Subject: [PATCH 071/185] whitespace --- doc/src/fix_deform.rst | 2 +- doc/src/fix_deform_pressure.rst | 6 ++++-- src/EXTRA-FIX/fix_deform_pressure.cpp | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/doc/src/fix_deform.rst b/doc/src/fix_deform.rst index 7f81bcf68d..6d415fd0a9 100644 --- a/doc/src/fix_deform.rst +++ b/doc/src/fix_deform.rst @@ -111,7 +111,7 @@ Examples fix 1 all deform 10 y delta -0.5 0.5 xz vel 1.0 See examples for :doc:`fix deform/pressure ` on its doc page - + Description """"""""""" diff --git a/doc/src/fix_deform_pressure.rst b/doc/src/fix_deform_pressure.rst index 64bf210446..15dcc9f7a4 100644 --- a/doc/src/fix_deform_pressure.rst +++ b/doc/src/fix_deform_pressure.rst @@ -27,14 +27,14 @@ Syntax target = target pressure (pressure units) gain = proportional gain constant (1/(time * pressure) or 1/time units) NOTE: All other styles are documented by the :doc:`fix deform ` command - + *xy*, *xz*, *yz* args = style value style = *final* or *delta* or *vel* or *erate* or *trate* or *wiggle* or *variable* or *pressure* *pressure* values = target gain target = target pressure (pressure units) gain = proportional gain constant (1/(time * pressure) or 1/time units) NOTE: All other styles are documented by the :doc:`fix deform ` command - + *box* = style value style = *volume* or *pressure* *volume* value = none = isotropically adjust system to preserve volume of system @@ -69,6 +69,8 @@ Examples Description """"""""""" +.. versionadded:: TBD + This fix is an extension of the :doc:`fix deform ` command, which allows all of its options to be used as well as new pressure-based controls implemented by this command. diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index d8374bcc75..7f15870ef1 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -115,7 +115,7 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : set_extra[index].pgain = utils::numeric(FLERR, arg[iarg + 3], false, lmp); i += 4; } else error->all(FLERR, "Illegal fix deform/pressure command: {}", arg[iarg + 1]); - + } else if (strcmp(arg[iarg], "box") == 0) { if (strcmp(arg[iarg + 1], "volume") == 0) { set_box.style = VOLUME; @@ -861,7 +861,7 @@ void FixDeformPressure::options(int i, int narg, char **arg) normalize_pressure_flag = 0; // parse only options not handled by parent class - + int iarg, nskip; while (i < leftover_iarg.size()) { iarg = leftover_iarg[i]; From 71385add8bfb7e79297f3ef1d511fde3924af541 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 21 Feb 2024 17:50:55 -0500 Subject: [PATCH 072/185] integrate into documentation system. correct links/references. --- doc/src/Commands_fix.rst | 1 + doc/src/fix.rst | 1 + doc/src/fix_deform.rst | 8 ++++---- doc/src/fix_deform_pressure.rst | 10 ++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/src/Commands_fix.rst b/doc/src/Commands_fix.rst index e89e302673..ea50e68cdd 100644 --- a/doc/src/Commands_fix.rst +++ b/doc/src/Commands_fix.rst @@ -61,6 +61,7 @@ OPT. * :doc:`controller ` * :doc:`damping/cundall ` * :doc:`deform (k) ` + * :doc:`deform/pressure ` * :doc:`deposit ` * :doc:`dpd/energy (k) ` * :doc:`drag ` diff --git a/doc/src/fix.rst b/doc/src/fix.rst index 69a7212487..d03cab4687 100644 --- a/doc/src/fix.rst +++ b/doc/src/fix.rst @@ -226,6 +226,7 @@ accelerated styles exist. * :doc:`controller ` - apply control loop feedback mechanism * :doc:`damping/cundall ` - Cundall non-viscous damping for granular simulations * :doc:`deform ` - change the simulation box size/shape +* :doc:`deform/pressure ` - change the simulation box size/shape with additional loading conditions * :doc:`deposit ` - add new atoms above a surface * :doc:`dpd/energy ` - constant energy dissipative particle dynamics * :doc:`drag ` - drag atoms towards a defined coordinate diff --git a/doc/src/fix_deform.rst b/doc/src/fix_deform.rst index 6d415fd0a9..9146b987c8 100644 --- a/doc/src/fix_deform.rst +++ b/doc/src/fix_deform.rst @@ -14,10 +14,10 @@ Syntax .. code-block:: LAMMPS - fix ID group-ID fixstyle N parameter style args ... keyword value ... + fix ID group-ID fix_style N parameter style args ... keyword value ... * ID, group-ID are documented in :doc:`fix ` command -* fixstyle = *deform* or *deform/pressure* +* fix_style = *deform* or *deform/pressure* * N = perform box deformation every this many timesteps * one or more parameter/style/args sequences of arguments may be appended @@ -644,8 +644,8 @@ command. Related commands """""""""""""""" -:doc:`fix deform/pressure `, :doc:`change_box - ` +:doc:`fix deform/pressure `, +:doc:`change_box ` Default """"""" diff --git a/doc/src/fix_deform_pressure.rst b/doc/src/fix_deform_pressure.rst index 15dcc9f7a4..f85ad37238 100644 --- a/doc/src/fix_deform_pressure.rst +++ b/doc/src/fix_deform_pressure.rst @@ -109,7 +109,7 @@ specific details of a simulation. Testing different values is recommended. By default, there is no limit on the resulting strain rate in any dimension. A maximum limit can be applied using the :ref:`max/rate ` -option. Akin to :ref:`fix nh `, pressures in different dimensions +option. Akin to :doc:`fix nh `, pressures in different dimensions can be coupled using the :ref:`couple ` option. This means the instantaneous pressure along coupled dimensions are averaged and the box strains identically along the coupled dimensions. @@ -313,9 +313,7 @@ The option defaults are normalize/pressure = no. ---------- -.. _Li2014b: +.. _Huang2014: -**(Huang2014)** X. Huang, -"Exploring critical-state behavior using DEM", -Doctoral dissertation, Imperial College. -(2014). https://doi.org/10.25560/25316 +**(Huang2014)** X. Huang, "Exploring critical-state behavior using DEM", +Doctoral dissertation, Imperial College. (2014). https://doi.org/10.25560/25316 From 14348a599cacff1174bc07ca144eb6eb79abb8b4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 21 Feb 2024 20:44:55 -0500 Subject: [PATCH 073/185] monte carlo insertions and pair style dsmc require per-type masses --- src/MC/fix_charge_regulation.cpp | 5 +++++ src/MC/fix_gcmc.cpp | 4 ++++ src/MC/fix_sgcmc.cpp | 15 +++++++++------ src/MC/fix_widom.cpp | 4 ++++ src/MC/pair_dsmc.cpp | 2 ++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/MC/fix_charge_regulation.cpp b/src/MC/fix_charge_regulation.cpp index 2fade2be79..1690e647dc 100644 --- a/src/MC/fix_charge_regulation.cpp +++ b/src/MC/fix_charge_regulation.cpp @@ -191,6 +191,11 @@ int FixChargeRegulation::setmask() { void FixChargeRegulation::init() { + if (!atom->mass) error->all(FLERR, "Fix charge/regulation requires per atom type masses"); + if (atom->rmass_flag && (comm->me == 0)) + error->warning(FLERR, "Fix charge/regulation will use per atom type masses for " + "velocity initialization"); + triclinic = domain->triclinic; int ipe = modify->find_compute("thermo_pe"); c_pe = modify->compute[ipe]; diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index b3d000e8b1..2d35528219 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -463,6 +463,10 @@ int FixGCMC::setmask() void FixGCMC::init() { + if (!atom->mass) error->all(FLERR, "Fix gcmc requires per atom type masses"); + if (atom->rmass_flag && (comm->me == 0)) + error->warning(FLERR, "Fix gcmc will use per atom type masses for velocity initialization"); + triclinic = domain->triclinic; // set index and check validity of region diff --git a/src/MC/fix_sgcmc.cpp b/src/MC/fix_sgcmc.cpp index a70f3240db..ae0e69d77e 100644 --- a/src/MC/fix_sgcmc.cpp +++ b/src/MC/fix_sgcmc.cpp @@ -235,11 +235,13 @@ int FixSemiGrandCanonicalMC::setmask() *********************************************************************/ void FixSemiGrandCanonicalMC::init() { - // Make sure the user has defined only one Monte-Carlo fix. - int count = 0; - for (int i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"sgcmc") == 0) count++; - if (count > 1) error->all(FLERR, "More than one fix sgcmc defined."); + if (!atom->mass) error->all(FLERR, "Fix sgcmc requires per atom type masses"); + if (atom->rmass_flag && (comm->me == 0)) + error->warning(FLERR, "Fix sgcmc will use per atom type masses for velocity initialization"); + + // Make sure the user has defined only one Semi-Grand Monte-Carlo fix. + if (modify->get_fix_by_style("sgcmc").size() > 1) + error->all(FLERR, "More than one fix sgcmc defined."); // Save a pointer to the EAM potential. pairEAM = dynamic_cast(force->pair); @@ -248,7 +250,8 @@ void FixSemiGrandCanonicalMC::init() utils::logmesg(lmp, " SGC - Using naive total energy calculation for MC -> SLOW!\n"); if (comm->nprocs > 1) - error->all(FLERR, "Can not run fix vcsgc with naive total energy calculation and more than one MPI process."); + error->all(FLERR, "Can not run fix sgcmc with naive total energy calculation " + "and more than one MPI process."); // Create a compute that will provide the total energy of the system. // This is needed by computeTotalEnergy(). diff --git a/src/MC/fix_widom.cpp b/src/MC/fix_widom.cpp index 2e48630f59..d0840c80b7 100644 --- a/src/MC/fix_widom.cpp +++ b/src/MC/fix_widom.cpp @@ -280,6 +280,10 @@ int FixWidom::setmask() void FixWidom::init() { + if (!atom->mass) error->all(FLERR, "Fix widom requires per atom type masses"); + if (atom->rmass_flag && (comm->me == 0)) + error->warning(FLERR, "Fix widom will use per atom type masses for velocity initialization"); + triclinic = domain->triclinic; // set index and check validity of region diff --git a/src/MC/pair_dsmc.cpp b/src/MC/pair_dsmc.cpp index 4773ac7653..1c152906b3 100644 --- a/src/MC/pair_dsmc.cpp +++ b/src/MC/pair_dsmc.cpp @@ -271,6 +271,8 @@ void PairDSMC::coeff(int narg, char **arg) void PairDSMC::init_style() { + if (!atom->mass) error->all(FLERR, "Pair style dsmc requires per atom type masses"); + ncellsx = ncellsy = ncellsz = 1; while (((domain->boxhi[0] - domain->boxlo[0])/ncellsx) > max_cell_size) ncellsx++; From 6ac24c297a43124f0d0c5ddf97b3a37768bfb0b1 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Thu, 22 Feb 2024 11:47:53 +0300 Subject: [PATCH 074/185] Add check for varying box size --- src/EXTRA-FIX/fix_wall_flow.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 15b82b45b8..629d2ad452 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -187,12 +187,34 @@ int FixWallFlow::setmask() void FixWallFlow::init() { int nrigid = 0; - - for (auto ifix : modify->get_fix_list()) + int box_change_flowax = 0; + for (auto ifix : modify->get_fix_list()) { if (ifix->rigid_flag) nrigid++; + switch (flowax) { + case FlowAxis::AX_X: + if (ifix->box_change & Fix::BOX_CHANGE_X) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_XY) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_XZ) box_change_flowax++; + break; + case FlowAxis::AX_Y: + if (ifix->box_change & Fix::BOX_CHANGE_Y) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_YZ) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_XY) box_change_flowax++; + break; + case FlowAxis::AX_Z: + if (ifix->box_change & Fix::BOX_CHANGE_Z) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_YZ) box_change_flowax++; + if (ifix->box_change & Fix::BOX_CHANGE_XZ) box_change_flowax++; + break; + } + } if (nrigid && comm->me == 0) error->warning(FLERR, "FixWallFlow is not compatible with rigid bodies"); + if (box_change_flowax && comm->me == 0) + error->warning( + FLERR, + "FixWallFlow is not compatible with simulation box size changing along flow direction"); for (int i = 0; i < atom->nlocal; ++i) { double pos = atom->x[i][flowax]; From f1a5dd0479cecfa3ff8e84b2f3379b957224a905 Mon Sep 17 00:00:00 2001 From: Vladislav Galigerov Date: Thu, 22 Feb 2024 12:28:23 +0300 Subject: [PATCH 075/185] Change warnings to errors --- src/EXTRA-FIX/fix_wall_flow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 629d2ad452..49a8a2eb9b 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -210,9 +210,9 @@ void FixWallFlow::init() } if (nrigid && comm->me == 0) - error->warning(FLERR, "FixWallFlow is not compatible with rigid bodies"); + error->all(FLERR, "FixWallFlow is not compatible with rigid bodies"); if (box_change_flowax && comm->me == 0) - error->warning( + error->all( FLERR, "FixWallFlow is not compatible with simulation box size changing along flow direction"); From a466d74f31c18be3c682b50b231ab36d56d48b84 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 04:34:22 -0500 Subject: [PATCH 076/185] document requirement of per-type masses --- doc/src/fix_charge_regulation.rst | 10 +++++----- doc/src/fix_gcmc.rst | 5 ++++- doc/src/fix_sgcmc.rst | 3 +++ doc/src/fix_widom.rst | 7 +++++-- doc/src/pair_dsmc.rst | 8 ++++++-- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/doc/src/fix_charge_regulation.rst b/doc/src/fix_charge_regulation.rst index bc2651a55b..091eeae417 100644 --- a/doc/src/fix_charge_regulation.rst +++ b/doc/src/fix_charge_regulation.rst @@ -253,11 +253,11 @@ built with that package. See the :doc:`Build package ` page for more info. The :doc:`atom_style `, used must contain the charge -property, for example, the style could be *charge* or *full*. Only -usable for 3D simulations. Atoms specified as free ions cannot be part -of rigid bodies or molecules and cannot have bonding interactions. The -scheme is limited to integer charges, any atoms with non-integer charges -will not be considered by the fix. +property and have per atom type masses, for example, the style could be +*charge* or *full*. Only usable for 3D simulations. Atoms specified as +free ions cannot be part of rigid bodies or molecules and cannot have +bonding interactions. The scheme is limited to integer charges, any +atoms with non-integer charges will not be considered by the fix. All interaction potentials used must be continuous, otherwise the MD integration and the particle exchange MC moves do not correspond to the diff --git a/doc/src/fix_gcmc.rst b/doc/src/fix_gcmc.rst index 13ae509684..a21e85d803 100644 --- a/doc/src/fix_gcmc.rst +++ b/doc/src/fix_gcmc.rst @@ -440,8 +440,11 @@ 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. +This fix style requires an :doc:`atom style ` with per atom +type masses. + Do not set "neigh_modify once yes" or else this fix will never be -called. Reneighboring is required. +called. Reneighboring is **required**. Only usable for 3D simulations. diff --git a/doc/src/fix_sgcmc.rst b/doc/src/fix_sgcmc.rst index 63cfaf22da..bcdbdf2736 100644 --- a/doc/src/fix_sgcmc.rst +++ b/doc/src/fix_sgcmc.rst @@ -155,6 +155,9 @@ This fix is part of the MC package. It is only enabled if LAMMPS was built with that package. See the :doc:`Build package ` page for more info. +This fix style requires an :doc:`atom style ` with per atom +type masses. + At present the fix provides optimized subroutines for EAM type potentials (see above) that calculate potential energy changes due to *local* atom type swaps very efficiently. Other potentials are diff --git a/doc/src/fix_widom.rst b/doc/src/fix_widom.rst index ff66095db5..43e081800f 100644 --- a/doc/src/fix_widom.rst +++ b/doc/src/fix_widom.rst @@ -195,8 +195,11 @@ doc page for more info. Do not set "neigh_modify once yes" or else this fix will never be called. Reneighboring is **required**. -Can be run in parallel, but aspects of the GCMC part will not scale well -in parallel. Only usable for 3D simulations. +This fix style requires an :doc:`atom style ` with per atom +type masses. + +Can be run in parallel, but some aspects of the insertion procedure +will not scale well in parallel. Only usable for 3D simulations. Related commands diff --git a/doc/src/pair_dsmc.rst b/doc/src/pair_dsmc.rst index edac1d7a65..09bb5d90af 100644 --- a/doc/src/pair_dsmc.rst +++ b/doc/src/pair_dsmc.rst @@ -138,8 +138,12 @@ This pair style can only be used via the *pair* keyword of the Restrictions """""""""""" -This style is part of the MC package. It is only enabled if LAMMPS -was built with that package. See the :doc:`Build package ` page for more info. +This pair style is part of the MC package. It is only enabled if LAMMPS +was built with that package. See the :doc:`Build package +` page for more info. + +This pair style requires an :doc:`atom style ` with per +atom type masses. Related commands """""""""""""""" From 86d306b50239d9619cb5f8179956e376b18659d6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 04:40:55 -0500 Subject: [PATCH 077/185] avoid excessive copies --- src/EXTRA-FIX/fix_wall_flow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 49a8a2eb9b..add0b51ca4 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -188,7 +188,7 @@ void FixWallFlow::init() { int nrigid = 0; int box_change_flowax = 0; - for (auto ifix : modify->get_fix_list()) { + for (const auto &ifix : modify->get_fix_list()) { if (ifix->rigid_flag) nrigid++; switch (flowax) { case FlowAxis::AX_X: From 6af4dac2e572e76a74a0acde88e1514e5242431c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 04:41:16 -0500 Subject: [PATCH 078/185] Error::all() must be called by all MPI ranks --- src/EXTRA-FIX/fix_wall_flow.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index add0b51ca4..b6634aa87c 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -209,12 +209,11 @@ void FixWallFlow::init() } } - if (nrigid && comm->me == 0) - error->all(FLERR, "FixWallFlow is not compatible with rigid bodies"); - if (box_change_flowax && comm->me == 0) + if (nrigid) error->all(FLERR, "Fix wall/flow is not compatible with rigid bodies"); + if (box_change_flowax) error->all( FLERR, - "FixWallFlow is not compatible with simulation box size changing along flow direction"); + "Fix wall/flow is not compatible with simulation box size changing along flow direction"); for (int i = 0; i < atom->nlocal; ++i) { double pos = atom->x[i][flowax]; From 5cadcbfd6849fdbd160d029e53fd6fb22a6bf4b7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 04:51:35 -0500 Subject: [PATCH 079/185] silence compiler warnings --- src/EXTRA-FIX/fix_wall_flow.cpp | 4 ++-- src/KOKKOS/fix_wall_flow_kokkos.cpp | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index b6634aa87c..f194a4076a 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -135,7 +135,7 @@ FixWallFlow::FixWallFlow(LAMMPS *lmp, int narg, char **arg) : walls.resize(wallcount + 2); walls.front() = domain->boxlo[flowax]; - for (size_t w = 1; w <= wallcount; ++w, ++iarg) { + for (int w = 1; w <= wallcount; ++w, ++iarg) { walls[w] = utils::numeric(FLERR, arg[iarg], do_abort, lmp) * scale; } walls.back() = domain->boxhi[flowax]; @@ -291,7 +291,7 @@ void FixWallFlow::generate_velocity(int atom_i) int FixWallFlow::compute_current_segment(double pos) const { int result = 0; - for (; result < walls.size() - 1; ++result) { + for (; result < (int)walls.size() - 1; ++result) { if (pos >= walls[result] && pos < walls[result + 1]) { return result; } } return -1; // -1 is "out of box" region diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index f9d11efe81..b6b3f7c096 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -23,8 +23,6 @@ #include "math_const.h" #include "memory_kokkos.h" -#include - using namespace LAMMPS_NS; template @@ -44,7 +42,7 @@ FixWallFlowKokkos::FixWallFlowKokkos(LAMMPS *lmp, int narg, char **a d_walls = d_walls_t("FixWallFlowKokkos::walls", walls.size()); auto h_walls = Kokkos::create_mirror_view(d_walls); - for (int i = 0; i < walls.size(); ++i) { h_walls(i) = walls[i]; } + for (int i = 0; i < (int) walls.size(); ++i) h_walls(i) = walls[i]; Kokkos::deep_copy(d_walls, h_walls); } @@ -161,7 +159,7 @@ KOKKOS_INLINE_FUNCTION int FixWallFlowKokkos::compute_current_segment_kk(double pos) const { int result = 0; - for (; result < d_walls.extent(0) - 1; ++result) { + for (; result < (int) d_walls.extent(0) - 1; ++result) { if (pos >= d_walls[result] && pos < d_walls[result + 1]) { return result; } } return -1; // -1 is "out of box" region @@ -224,7 +222,7 @@ int FixWallFlowKokkos::pack_exchange_kokkos(const int &nsend, DAT::tdual_xfloat_2d &k_buf, DAT::tdual_int_1d k_sendlist, DAT::tdual_int_1d k_copylist, - ExecutionSpace space) + ExecutionSpace /*space*/) { k_current_segment.template sync(); @@ -271,7 +269,7 @@ template void FixWallFlowKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf, DAT::tdual_int_1d &k_indices, int nrecv, int /*nrecv1*/, int /*nextrarecv1*/, - ExecutionSpace space) + ExecutionSpace /*space*/) { d_buf = typename ArrayTypes::t_xfloat_1d_um(k_buf.template view().data(), k_buf.extent(0) * k_buf.extent(1)); From 71e0d506e71ab7453ba328984b9b0c534d37266c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 04:56:27 -0500 Subject: [PATCH 080/185] spelling --- doc/utils/sphinx-config/false_positives.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 6106a1638c..2ec10d0e80 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -3888,6 +3888,7 @@ Verstraelen ves vf vflag +vflow vfrac vhi vibrational From 3ff2b1b43b507f5dfb407a5a1e18c4bd1974ee55 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 05:07:08 -0500 Subject: [PATCH 081/185] silence compiler warnings --- src/EXTRA-FIX/fix_deform_pressure.cpp | 8 ++++---- src/fix_deform.cpp | 11 ++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index 7f15870ef1..aebc6e120f 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -58,7 +58,7 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : // parse only parameter/style arguments specific to this child class int index, iarg; - int i = 0; + std::size_t i = 0; while (i < leftover_iarg.size()) { iarg = leftover_iarg[i]; if (strcmp(arg[iarg], "x") == 0 || @@ -616,7 +616,7 @@ void FixDeformPressure::apply_volume() int dynamic2 = set[i].dynamic2; int fixed = set[i].fixed; double v0 = set[i].vol_start; - double shift; + double shift = 0.0; if (set[i].substyle == ONE_FROM_ONE) { shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / @@ -862,8 +862,8 @@ void FixDeformPressure::options(int i, int narg, char **arg) // parse only options not handled by parent class - int iarg, nskip; - while (i < leftover_iarg.size()) { + int iarg; + while (i < (int) leftover_iarg.size()) { iarg = leftover_iarg[i]; if (strcmp(arg[iarg], "couple") == 0) { if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix deform/pressure couple", error); diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 9ee7259482..c19423d844 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -782,7 +782,7 @@ void FixDeform::apply_volume() int dynamic2 = set[i].dynamic2; int fixed = set[i].fixed; double v0 = set[i].vol_start; - double shift; + double shift = 0.0; if (set[i].substyle == ONE_FROM_ONE) { shift = 0.5 * (v0 / (set[dynamic1].hi_target - set[dynamic1].lo_target) / @@ -1002,11 +1002,8 @@ void FixDeform::options(int narg, char **arg) // arguments for child classes std::unordered_map child_options; - int nskip; if (utils::strmatch(style, "^deform/pressure")) { - child_options.insert({{"couple", 2}, - {"max/rate", 2}, - {"normalize/pressure", 2}, + child_options.insert({{"couple", 2}, {"max/rate", 2}, {"normalize/pressure", 2}, {"vol/balance/p", 2}}); } @@ -1033,10 +1030,10 @@ void FixDeform::options(int narg, char **arg) flipflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (child_options.find(arg[iarg]) != child_options.end()) { - nskip = child_options[arg[iarg]]; + auto nskip = child_options[arg[iarg]]; if (iarg + nskip > narg) utils::missing_cmd_args(FLERR, fmt::format("fix {} {}", style, arg[iarg]), error); - for (int i = 0; i < nskip; i++) leftover_iarg.push_back(iarg + i); + for (int i = 0; i < nskip; i++) leftover_iarg.push_back(iarg + i); iarg += nskip; } else error->all(FLERR, "Unknown fix {} keyword: {}", style, arg[iarg]); } From 325a7d99d6e640da365d31d7862bbf4aa5eab525 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 07:47:37 -0500 Subject: [PATCH 082/185] error out when cuFFT is not found --- cmake/Modules/Packages/KOKKOS.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/Modules/Packages/KOKKOS.cmake b/cmake/Modules/Packages/KOKKOS.cmake index fa2201c595..0cc13c9667 100644 --- a/cmake/Modules/Packages/KOKKOS.cmake +++ b/cmake/Modules/Packages/KOKKOS.cmake @@ -140,6 +140,9 @@ if(PKG_KSPACE) target_compile_definitions(lammps PRIVATE -DFFT_KOKKOS_KISS) elseif(FFT_KOKKOS STREQUAL "CUFFT") find_library(CUFFT_LIBRARY cufft) + if (CUFFT_LIBRARY STREQUAL "CUTFFT_LIBRARY-NOTFOUND") + message(FATAL_ERROR "Required cuFFT library not found. Check your environment or set CUFFT_LIBRARY to its location") + endif() target_compile_definitions(lammps PRIVATE -DFFT_KOKKOS_CUFFT) target_link_libraries(lammps PRIVATE ${CUFFT_LIBRARY}) endif() From d6d9a91126a39932564630be9935689dbdcffaa2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 09:13:21 -0500 Subject: [PATCH 083/185] add rebomos potential with examples and unit test --- doc/src/Commands_pair.rst | 1 + doc/src/pair_rebomos.rst | 109 ++ doc/src/pair_style.rst | 1 + examples/threebody/MoS.rebomos | 1 + examples/threebody/in.mos2-bulk | 35 + examples/threebody/in.mos2.rebomos | 31 + .../threebody/log.22Feb24.mos2-bulk.g++.1 | 86 ++ .../threebody/log.22Feb24.mos2-bulk.g++.4 | 86 ++ .../threebody/log.22Feb24.mos2.rebomos.g++.1 | 96 ++ .../threebody/log.22Feb24.mos2.rebomos.g++.4 | 96 ++ potentials/MoS.rebomos | 65 + potentials/README | 4 +- src/.gitignore | 2 + src/MANYBODY/pair_rebomos.cpp | 1161 +++++++++++++++++ src/MANYBODY/pair_rebomos.h | 219 ++++ .../tests/manybody-pair-rebomos.yaml | 126 ++ 16 files changed, 2118 insertions(+), 1 deletion(-) create mode 100644 doc/src/pair_rebomos.rst create mode 120000 examples/threebody/MoS.rebomos create mode 100644 examples/threebody/in.mos2-bulk create mode 100644 examples/threebody/in.mos2.rebomos create mode 100644 examples/threebody/log.22Feb24.mos2-bulk.g++.1 create mode 100644 examples/threebody/log.22Feb24.mos2-bulk.g++.4 create mode 100644 examples/threebody/log.22Feb24.mos2.rebomos.g++.1 create mode 100644 examples/threebody/log.22Feb24.mos2.rebomos.g++.4 create mode 100644 potentials/MoS.rebomos create mode 100644 src/MANYBODY/pair_rebomos.cpp create mode 100644 src/MANYBODY/pair_rebomos.h create mode 100644 unittest/force-styles/tests/manybody-pair-rebomos.yaml diff --git a/doc/src/Commands_pair.rst b/doc/src/Commands_pair.rst index 9f2bdbce79..95dd7429e8 100644 --- a/doc/src/Commands_pair.rst +++ b/doc/src/Commands_pair.rst @@ -256,6 +256,7 @@ OPT. * :doc:`rann ` * :doc:`reaxff (ko) ` * :doc:`rebo (io) ` + * :doc:`rebomos ` * :doc:`resquared (go) ` * :doc:`saip/metal (t) ` * :doc:`sdpd/taitwater/isothermal ` diff --git a/doc/src/pair_rebomos.rst b/doc/src/pair_rebomos.rst new file mode 100644 index 0000000000..56bf6488bb --- /dev/null +++ b/doc/src/pair_rebomos.rst @@ -0,0 +1,109 @@ +.. index:: pair_style rebomos + +pair_style rebomos command +========================= + +Syntax +"""""" + +.. code-block:: LAMMPS + + pair_style rebomos + +* rebomos = name of this pair style + +Examples +"""""""" + +.. code-block:: LAMMPS + + pair_style rebomos + pair_coeff * * ../potentials/MoS.rebomos Mo S + + +Description +""""""""""" + +The *rebomos* pair style computes + + +---------- + +Only a single pair_coeff command is used with the *rebomos* pair style +which specifies an REBOMoS potential file with parameters for Mo and S. +These are mapped to LAMMPS atom types by specifying N additional +arguments after the filename in the pair_coeff command, where N is the +number of LAMMPS atom types: + +* filename +* :math:`N` element names = mapping of REBOMoS elements to atom types + +See the :doc:`pair_coeff ` page for alternate ways +to specify the path for the potential file. + +As an example, if your LAMMPS simulation has three atom types and you want +the first two to be Mo, and the third to be S, you would use the following +pair_coeff command: + +.. code-block:: LAMMPS + + pair_coeff * * MoS.rebomos Mo Mo S + +The first 2 arguments must be \* \* so as to span all LAMMPS atom types. +The first two Mo arguments map LAMMPS atom types 1 and 2 to the Mo +element in the REBOMoS file. The final S argument maps LAMMPS atom type +3 to the S element in the REBOMoS file. If a mapping value is specified +as NULL, the mapping is not performed. This can be used when a +*rebomos* potential is used as part of the *hybrid* pair style. The +NULL values are placeholders for atom types that will be used with other +potentials. + +---------- + +Mixing, shift, table, tail correction, restart, rRESPA info +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +This pair style does not support the :doc:`pair_modify ` +mix, shift, table, and tail options. + +This pair style does not write their information to :doc:`binary restart +files `, since it is stored in potential files. Thus, you need +to re-specify the pair_style and pair_coeff commands in an input script +that reads a restart file. + +This pair styles can only be used via the *pair* keyword of the +:doc:`run_style respa ` command. It does not support the +*inner*, *middle*, *outer* keywords. + +Restrictions +"""""""""""" + +This pair style is part of the MANYBODY package. It is only enabled if +LAMMPS was built with that package. See the :doc:`Build package +` page for more info. + +These pair potentials require the :doc:`newton ` setting to be +"on" for pair interactions. + +The MoS.rebomos potential file provided with LAMMPS (see the potentials +directory) is parameterized for metal :doc:`units `. You can use +the *rebomos* pair style with any LAMMPS units setting, but you would +need to create your own REBOMoS potential file with coefficients listed +in the appropriate units. + +The pair style provided here **only** supports potential files parameterized +for the elements molybdenum and sulfur (designated with "Mo" and "S" in the +*pair_coeff* command. Using potential files for other elements will trigger +an error. + +Related commands +"""""""""""""""" + +:doc:`pair_coeff `, :doc:`pair style rebo ` + +Default +""""""" + +none + +---------- diff --git a/doc/src/pair_style.rst b/doc/src/pair_style.rst index a2467bff2b..53bf269e1c 100644 --- a/doc/src/pair_style.rst +++ b/doc/src/pair_style.rst @@ -333,6 +333,7 @@ accelerated styles exist. * :doc:`rann ` - * :doc:`reaxff ` - ReaxFF potential * :doc:`rebo ` - second generation REBO potential of Brenner +* :doc:`rebomos ` - REBOMoS potential for MoS2 * :doc:`resquared ` - Everaers RE-Squared ellipsoidal potential * :doc:`saip/metal ` - interlayer potential for hetero-junctions formed with hexagonal 2D materials and metal surfaces * :doc:`sdpd/taitwater/isothermal ` - smoothed dissipative particle dynamics for water at isothermal conditions diff --git a/examples/threebody/MoS.rebomos b/examples/threebody/MoS.rebomos new file mode 120000 index 0000000000..6146c74c24 --- /dev/null +++ b/examples/threebody/MoS.rebomos @@ -0,0 +1 @@ +../../potentials/MoS.rebomos \ No newline at end of file diff --git a/examples/threebody/in.mos2-bulk b/examples/threebody/in.mos2-bulk new file mode 100644 index 0000000000..032e71fce8 --- /dev/null +++ b/examples/threebody/in.mos2-bulk @@ -0,0 +1,35 @@ +units metal + +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 & + a2 -1.5964590311 2.7651481541 0.0000000000 & + a3 0.0000000000 0.0000000000 13.9827680588 & + basis 0.0000000000 0.000000000 $(3.0/4.0) & + basis 0.0000000000 0.000000000 $(1.0/4.0) & + basis $(2.0/3.0) $(1.0/3.0) 0.862008989 & + basis $(1.0/3.0) $(2.0/3.0) 0.137990996 & + basis $(1.0/3.0) $(2.0/3.0) 0.362008989 & + basis $(2.0/3.0) $(1.0/3.0) 0.637991011 & + origin 0.1 0.1 0.1 + +region box prism 0 4 0 8 0 1 -2.0 0.0 0.0 +create_box 2 box +create_atoms 2 box & + basis 1 1 & + basis 2 1 & + basis 3 2 & + basis 4 2 & + basis 5 2 & + basis 6 2 + +mass 1 95.95 #Mo +mass 2 32.065 #S + +pair_style rebomos +pair_coeff * * MoS.rebomos Mo S + +thermo_style custom step temp press pe ke cellgamma vol +thermo 10 +#dump 1 all atom 10 MoS.lammpstrj +fix 1 all nve +run 20 + diff --git a/examples/threebody/in.mos2.rebomos b/examples/threebody/in.mos2.rebomos new file mode 100644 index 0000000000..ca91f67003 --- /dev/null +++ b/examples/threebody/in.mos2.rebomos @@ -0,0 +1,31 @@ +# monolayer MoS2 +units metal +boundary p p f +processors * * 1 +atom_modify map array + +atom_style atomic +read_data single_layer_MoS2.data + +mass * 32.065 # mass of sulphur atom , uint: a.u.=1.66X10^(-27)kg +mass 1 95.94 # mass of molebdenum atom , uint: a.u.=1.66X10^(-27)kg + +########################## Define potentials ################################ +pair_style rebomos +pair_coeff * * MoS.rebomos Mo S S +######################################################################### + +### Simulation settings #### +timestep 0.001 +velocity all create 300.0 12345 loop geom + +############################ + +# Output +thermo 500 +thermo_style custom step etotal pe ke temp +thermo_modify lost warn + +###### Run molecular dynamics ###### +fix thermostat all nve +run 5000 diff --git a/examples/threebody/log.22Feb24.mos2-bulk.g++.1 b/examples/threebody/log.22Feb24.mos2-bulk.g++.1 new file mode 100644 index 0000000000..7822ad40c5 --- /dev/null +++ b/examples/threebody/log.22Feb24.mos2-bulk.g++.1 @@ -0,0 +1,86 @@ +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +units metal + +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 $(3.0/4.0) basis 0.0000000000 0.000000000 $(1.0/4.0) basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 $(1.0/4.0) basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis 0.66666666666666662966 $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis 0.66666666666666662966 0.33333333333333331483 0.637991011 origin 0.1 0.1 0.1 +Lattice spacing in x,y,z = 4.7867748 2.7651482 13.982768 + +region box prism 0 4 0 8 0 1 -2.0 0.0 0.0 +create_box 2 box +Created triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9.5735495 0 0) + 1 by 1 by 1 MPI processor grid +create_atoms 2 box basis 1 1 basis 2 1 basis 3 2 basis 4 2 basis 5 2 basis 6 2 +Created 288 atoms + using lattice units in triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9.5735495 0 0) + create_atoms CPU = 0.000 seconds + +mass 1 95.95 #Mo +mass 2 32.065 #S + +pair_style rebomos +pair_coeff * * MoS.rebomos Mo S +Reading rebomos potential file MoS.rebomos with DATE: 2013-11-04 + +thermo_style custom step temp press pe ke cellgamma vol +thermo 10 +#dump 1 all atom 10 MoS.lammpstrj +fix 1 all nve +run 20 +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 20.1 + ghost atom cutoff = 20.1 + binsize = 10.05, bins = 3 3 2 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair rebomos, perpetual + attributes: full, newton on, ghost + pair build: full/bin/ghost + stencil: full/ghost/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 6.759 | 6.759 | 6.759 Mbytes + Step Temp Press PotEng KinEng CellGamma Volume + 0 0 28799.53 -2061.6112 0 113.40187 5922.4926 + 10 80.776057 13540.088 -2064.6132 2.9966028 113.40187 5922.4926 + 20 146.17503 -20669.371 -2067.0428 5.4227518 113.40187 5922.4926 +Loop time of 0.173901 on 1 procs for 20 steps with 288 atoms + +Performance: 9.937 ns/day, 2.415 hours/ns, 115.008 timesteps/s, 33.122 katom-step/s +99.7% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0.17213 | 0.17213 | 0.17213 | 0.0 | 98.98 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.0013913 | 0.0013913 | 0.0013913 | 0.0 | 0.80 +Output | 5.0377e-05 | 5.0377e-05 | 5.0377e-05 | 0.0 | 0.03 +Modify | 6.9212e-05 | 6.9212e-05 | 6.9212e-05 | 0.0 | 0.04 +Other | | 0.000264 | | | 0.15 + +Nlocal: 288 ave 288 max 288 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 10002 ave 10002 max 10002 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 0 ave 0 max 0 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 477120 ave 477120 max 477120 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 477120 +Ave neighs/atom = 1656.6667 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 diff --git a/examples/threebody/log.22Feb24.mos2-bulk.g++.4 b/examples/threebody/log.22Feb24.mos2-bulk.g++.4 new file mode 100644 index 0000000000..c215d88294 --- /dev/null +++ b/examples/threebody/log.22Feb24.mos2-bulk.g++.4 @@ -0,0 +1,86 @@ +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +units metal + +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 $(3.0/4.0) basis 0.0000000000 0.000000000 $(1.0/4.0) basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 $(1.0/4.0) basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis $(2.0/3.0) $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 $(1.0/3.0) 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis $(1.0/3.0) $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 $(2.0/3.0) 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis $(1.0/3.0) $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 $(2.0/3.0) 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis $(2.0/3.0) $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis 0.66666666666666662966 $(1.0/3.0) 0.637991011 origin 0.1 0.1 0.1 +lattice custom 1.0 a1 3.1903157234 0.0000000000 0.0000000000 a2 -1.5964590311 2.7651481541 0.0000000000 a3 0.0000000000 0.0000000000 13.9827680588 basis 0.0000000000 0.000000000 0.75 basis 0.0000000000 0.000000000 0.25 basis 0.66666666666666662966 0.33333333333333331483 0.862008989 basis 0.33333333333333331483 0.66666666666666662966 0.137990996 basis 0.33333333333333331483 0.66666666666666662966 0.362008989 basis 0.66666666666666662966 0.33333333333333331483 0.637991011 origin 0.1 0.1 0.1 +Lattice spacing in x,y,z = 4.7867748 2.7651482 13.982768 + +region box prism 0 4 0 8 0 1 -2.0 0.0 0.0 +create_box 2 box +Created triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9.5735495 0 0) + 2 by 2 by 1 MPI processor grid +create_atoms 2 box basis 1 1 basis 2 1 basis 3 2 basis 4 2 basis 5 2 basis 6 2 +Created 288 atoms + using lattice units in triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9.5735495 0 0) + create_atoms CPU = 0.001 seconds + +mass 1 95.95 #Mo +mass 2 32.065 #S + +pair_style rebomos +pair_coeff * * MoS.rebomos Mo S +Reading rebomos potential file MoS.rebomos with DATE: 2013-11-04 + +thermo_style custom step temp press pe ke cellgamma vol +thermo 10 +#dump 1 all atom 10 MoS.lammpstrj +fix 1 all nve +run 20 +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 20.1 + ghost atom cutoff = 20.1 + binsize = 10.05, bins = 3 3 2 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair rebomos, perpetual + attributes: full, newton on, ghost + pair build: full/bin/ghost + stencil: full/ghost/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 4.977 | 4.978 | 4.978 Mbytes + Step Temp Press PotEng KinEng CellGamma Volume + 0 0 28799.53 -2061.6112 0 113.40187 5922.4926 + 10 80.776057 13540.088 -2064.6132 2.9966028 113.40187 5922.4926 + 20 146.17503 -20669.371 -2067.0428 5.4227518 113.40187 5922.4926 +Loop time of 0.0644788 on 4 procs for 20 steps with 288 atoms + +Performance: 26.799 ns/day, 0.896 hours/ns, 310.179 timesteps/s, 89.332 katom-step/s +99.2% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0.057739 | 0.059918 | 0.06231 | 0.7 | 92.93 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.0018848 | 0.0042821 | 0.0064683 | 2.6 | 6.64 +Output | 3.7548e-05 | 4.1425e-05 | 5.1594e-05 | 0.0 | 0.06 +Modify | 3.4882e-05 | 3.5821e-05 | 3.6589e-05 | 0.0 | 0.06 +Other | | 0.0002014 | | | 0.31 + +Nlocal: 72 ave 72 max 72 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Nghost: 7113.5 ave 7114 max 7113 min +Histogram: 2 0 0 0 0 0 0 0 0 2 +Neighs: 0 ave 0 max 0 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +FullNghs: 119280 ave 119280 max 119280 min +Histogram: 4 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 477120 +Ave neighs/atom = 1656.6667 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 diff --git a/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 b/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 new file mode 100644 index 0000000000..e0a313647d --- /dev/null +++ b/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 @@ -0,0 +1,96 @@ +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +# monolayer MoS2 +units metal +boundary p p f +processors * * 1 +atom_modify map array + +atom_style atomic +read_data single_layer_MoS2.data +Reading data file ... + triclinic box = (0 0 -100) to (51.15232 44.299209 100) with tilt (25.57616 0 0) +WARNING: Triclinic box skew is large. LAMMPS will run inefficiently. (src/domain.cpp:219) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 768 atoms + read_data CPU = 0.003 seconds + +mass * 32.065 # mass of sulphur atom , uint: a.u.=1.66X10^(-27)kg +mass 1 95.94 # mass of molebdenum atom , uint: a.u.=1.66X10^(-27)kg + +########################## Define potentials ################################ +pair_style rebomos +pair_coeff * * MoS.rebomos Mo S S +Reading rebomos potential file MoS.rebomos with DATE: 2013-11-04 +######################################################################### + +### Simulation settings #### +timestep 0.001 +velocity all create 300.0 12345 loop geom + +############################ + +# Output +thermo 500 +thermo_style custom step etotal pe ke temp +thermo_modify lost warn + +###### Run molecular dynamics ###### +fix thermostat all nve +run 5000 +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 20.1 + ghost atom cutoff = 20.1 + binsize = 10.05, bins = 8 5 20 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair rebomos, perpetual + attributes: full, newton on, ghost + pair build: full/bin/ghost + stencil: full/ghost/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 5.273 | 5.273 | 5.273 Mbytes + Step TotEng PotEng KinEng Temp + 0 -5466.9785 -5496.7212 29.742759 300 + 500 -5466.964 -5482.6985 15.734505 158.7059 + 1000 -5466.9615 -5480.9492 13.98763 141.08607 + 1500 -5466.964 -5482.6912 15.727258 158.63281 + 2000 -5466.9657 -5483.3606 16.394878 165.36675 + 2500 -5466.9624 -5481.6253 14.662948 147.89765 + 3000 -5466.9642 -5482.7515 15.7873 159.23842 + 3500 -5466.9654 -5483.3789 16.413502 165.5546 + 4000 -5466.9628 -5481.848 14.885236 150.13977 + 4500 -5466.9648 -5483.5045 16.539775 166.82825 + 5000 -5466.9649 -5483.4932 16.528298 166.71249 +Loop time of 36.2406 on 1 procs for 5000 steps with 768 atoms + +Performance: 11.920 ns/day, 2.013 hours/ns, 137.967 timesteps/s, 105.959 katom-step/s +99.9% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 36.14 | 36.14 | 36.14 | 0.0 | 99.72 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.043166 | 0.043166 | 0.043166 | 0.0 | 0.12 +Output | 0.00021785 | 0.00021785 | 0.00021785 | 0.0 | 0.00 +Modify | 0.034547 | 0.034547 | 0.034547 | 0.0 | 0.10 +Other | | 0.02219 | | | 0.06 + +Nlocal: 768 ave 768 max 768 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 2054 ave 2054 max 2054 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 0 ave 0 max 0 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 330752 ave 330752 max 330752 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 330752 +Ave neighs/atom = 430.66667 +Neighbor list builds = 0 +Dangerous builds = 0 +Total wall time: 0:00:36 diff --git a/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 b/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 new file mode 100644 index 0000000000..7510c5a793 --- /dev/null +++ b/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 @@ -0,0 +1,96 @@ +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +# monolayer MoS2 +units metal +boundary p p f +processors * * 1 +atom_modify map array + +atom_style atomic +read_data single_layer_MoS2.data +Reading data file ... + triclinic box = (0 0 -100) to (51.15232 44.299209 100) with tilt (25.57616 0 0) +WARNING: Triclinic box skew is large. LAMMPS will run inefficiently. (src/domain.cpp:219) + 2 by 2 by 1 MPI processor grid + reading atoms ... + 768 atoms + read_data CPU = 0.002 seconds + +mass * 32.065 # mass of sulphur atom , uint: a.u.=1.66X10^(-27)kg +mass 1 95.94 # mass of molebdenum atom , uint: a.u.=1.66X10^(-27)kg + +########################## Define potentials ################################ +pair_style rebomos +pair_coeff * * MoS.rebomos Mo S S +Reading rebomos potential file MoS.rebomos with DATE: 2013-11-04 +######################################################################### + +### Simulation settings #### +timestep 0.001 +velocity all create 300.0 12345 loop geom + +############################ + +# Output +thermo 500 +thermo_style custom step etotal pe ke temp +thermo_modify lost warn + +###### Run molecular dynamics ###### +fix thermostat all nve +run 5000 +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 20.1 + ghost atom cutoff = 20.1 + binsize = 10.05, bins = 8 5 20 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair rebomos, perpetual + attributes: full, newton on, ghost + pair build: full/bin/ghost + stencil: full/ghost/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 4.464 | 4.464 | 4.464 Mbytes + Step TotEng PotEng KinEng Temp + 0 -5466.9785 -5496.7212 29.742759 300 + 500 -5466.964 -5482.6985 15.734505 158.7059 + 1000 -5466.9615 -5480.9492 13.98763 141.08607 + 1500 -5466.964 -5482.6912 15.727258 158.63281 + 2000 -5466.9657 -5483.3606 16.394878 165.36675 + 2500 -5466.9624 -5481.6253 14.662948 147.89765 + 3000 -5466.9642 -5482.7515 15.7873 159.23842 + 3500 -5466.9654 -5483.3789 16.413502 165.5546 + 4000 -5466.9628 -5481.848 14.885236 150.13977 + 4500 -5466.9648 -5483.5045 16.539775 166.82825 + 5000 -5466.9649 -5483.4932 16.528298 166.71249 +Loop time of 10.2878 on 4 procs for 5000 steps with 768 atoms + +Performance: 41.992 ns/day, 0.572 hours/ns, 486.014 timesteps/s, 373.259 katom-step/s +99.7% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 9.7925 | 9.9286 | 10.096 | 3.6 | 96.51 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.16754 | 0.33518 | 0.47096 | 19.5 | 3.26 +Output | 0.00016889 | 0.00018727 | 0.00023915 | 0.0 | 0.00 +Modify | 0.010131 | 0.010502 | 0.011106 | 0.4 | 0.10 +Other | | 0.01333 | | | 0.13 + +Nlocal: 192 ave 194 max 190 min +Histogram: 1 0 0 0 0 2 0 0 0 1 +Nghost: 1350 ave 1352 max 1348 min +Histogram: 1 0 0 0 0 2 0 0 0 1 +Neighs: 0 ave 0 max 0 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +FullNghs: 82688 ave 83548 max 81828 min +Histogram: 1 0 0 0 0 2 0 0 0 1 + +Total # of neighbors = 330752 +Ave neighs/atom = 430.66667 +Neighbor list builds = 0 +Dangerous builds = 0 +Total wall time: 0:00:10 diff --git a/potentials/MoS.rebomos b/potentials/MoS.rebomos new file mode 100644 index 0000000000..ea96981a1e --- /dev/null +++ b/potentials/MoS.rebomos @@ -0,0 +1,65 @@ +# DATE: 2013-11-04 UNITS: metal CONTRIBUTOR: J Stewart, K Dang, D Spearot (UArk) CITATION: Stewart J A and Spearot D E, Modelling Simul. Mater. Sci. Eng. 21. +# MoS-S REBO Brenner/Sinnot Potential as published in +# Liang T, Phillpot S R and Sinnott S B (2009) Phys. Rev. B79 245110, Erratum: Phys. Rev. B85 199903(E). + +3.50 rcmin_MM +2.75 rcmin_MS +2.30 rcmin_SS +3.80 rcmax_MM +3.05 rcmax_MS +3.00 rcmax_SS +3.419129390005910 Q_MM +1.505537839153790 Q_MS +0.254959104053671 Q_SS +1.07500712999340 alpha_MM +1.19267902218820 alpha_MS +1.10775022439715 alpha_SS +179.008013654688 A_MM +575.509677721866 A_MS +1228.43233679426 A_SS +706.247903589221 BIJc_MM1 +1344.46820036159 BIJc_MS1 +1498.64815404145 BIJc_SS1 +1.16100322369589 Beta_MM1 +1.26973752204290 Beta_MS1 +1.12673623610320 Beta_SS1 +0.1326842550663270 M_b0 +-0.007642788338017 M_b1 +0.0341395775059370 M_b2 +0.2523050971380870 M_b3 +0.1227287372225670 M_b4 +-0.361387798398897 M_b5 +-0.282577591351457 M_b6 +0.120194301035280 M_bg0 +0.045238287358190 M_bg1 +0.067922807244030 M_bg2 +-0.03672511378682 M_bg3 +0.107516477513860 M_bg4 +0.004964711984940 M_bg5 +-0.12997598358652 M_bg6 +0.006848761596750 S_b0 +-0.02389964401024 S_b1 +0.137457353311170 S_b2 +0.033016467497740 S_b3 +-0.31064291544850 S_b4 +-0.08550273135791 S_b5 +0.149252790306880 S_b6 +-0.2850852 S_bg0 +1.67102480 S_bg1 +-3.5678516 S_bg2 +3.45054990 S_bg3 +-1.2186289 S_bg4 +0.0 S_bg5 +0.0 S_bg6 +0.138040769883614 M_a0 +0.803625443023934 M_a1 +0.292412960851064 M_a2 +0.640588078946224 M_a3 +0.062978539843324 S_a0 +2.478617619878250 S_a1 +0.036666243238154 S_a2 +2.386431372486710 S_a3 +0.00058595 epsilon_MM +0.01386 epsilon_SS +4.200 sigma_MM +3.130 sigma_SS diff --git a/potentials/README b/potentials/README index c234f5f48b..2cb4a383c5 100644 --- a/potentials/README +++ b/potentials/README @@ -84,7 +84,7 @@ Au_u3 = Gold universal 3 The suffix of each file indicates the pair style it is used with: adp ADP angular dependent potential -airebo AI-REBO and REBO potentials +airebo AI-REBO potentials bop.table BOP potential, tabulated form cdeam concentration-dependent EAM comb COMB potential @@ -107,6 +107,8 @@ nb3b.harmonic nonbonded 3-body harmonic potential pod ML potential with proper orthogonal descriptors (POD) poly polymorphic 3-body potential reax ReaxFF potential (see README.reax for more info) +rebo REBO potentials +rebomos REBOMoS potential smtbq second moment tight binding QEq (SMTBQ) potential snap SNAP potential snapcoeff SNAP potential diff --git a/src/.gitignore b/src/.gitignore index 9e2c36bdd0..ba4c4c05b0 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1371,6 +1371,8 @@ /pair_reaxff.h /pair_rebo.cpp /pair_rebo.h +/pair_rebomos.cpp +/pair_rebomos.h /pair_resquared.cpp /pair_resquared.h /pair_saip_metal.cpp diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp new file mode 100644 index 0000000000..1211ad5c7e --- /dev/null +++ b/src/MANYBODY/pair_rebomos.cpp @@ -0,0 +1,1161 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + References: + + This code: + Stewart J A and Spearot D E (2013) Atomistic simulations of nanoindentation on the basal plane of crystalline molybdenum disulfide. Modelling Simul. Mater. Sci. Eng. 21. + + Based on: + Liang T, Phillpot S R and Sinnott S B (2009) Parameterization of a reactive many-body potential for Mo2S systems. Phys. Rev. B79 245110. + Liang T, Phillpot S R and Sinnott S B (2012) Erratum: Parameterization of a reactive many-body potential for Mo-S systems. (Phys. Rev. B79 245110 (2009)) Phys. Rev. B85 199903(E). + + LAMMPS file contributing authors: James Stewart, Khanh Dang and Douglas Spearot (University of Arkansas) +------------------------------------------------------------------------- */ + +// clang-format on + +#include "pair_rebomos.h" + +#include "atom.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "math_const.h" +#include "math_special.h" +#include "memory.h" +#include "my_page.h" +#include "neigh_list.h" +#include "neighbor.h" +#include "potential_file_reader.h" +#include "text_file_reader.h" + +#include +#include + +using namespace LAMMPS_NS; +using namespace MathConst; +using MathSpecial::cube; +using MathSpecial::powint; +using MathSpecial::square; + +#define MAXLINE 1024 +#define TOL 1.0e-9 +#define PGDELTA 1 + +/* ---------------------------------------------------------------------- */ + +PairREBOMoS::PairREBOMoS(LAMMPS *lmp) : Pair(lmp) +{ + single_enable = 0; + restartinfo = 0; + one_coeff = 1; + ghostneigh = 1; + manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; + + maxlocal = 0; + REBO_numneigh = nullptr; + REBO_firstneigh = nullptr; + ipage = nullptr; + pgsize = oneatom = 0; + nM = nS = nullptr; +} + +// clang-format off + +/* ---------------------------------------------------------------------- + Check if allocated, since class can be destructed when incomplete +------------------------------------------------------------------------- */ + +PairREBOMoS::~PairREBOMoS() +{ + memory->destroy(REBO_numneigh); + memory->sfree(REBO_firstneigh); + delete[] ipage; + memory->destroy(nM); + memory->destroy(nS); + + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); + memory->destroy(cutghost); + + memory->destroy(lj1); + memory->destroy(lj2); + memory->destroy(lj3); + memory->destroy(lj4); + } +} + +/* ---------------------------------------------------------------------- */ + +void PairREBOMoS::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); + + REBO_neigh(); + FREBO(eflag); + FLJ(eflag); + + if (vflag_fdotr) virial_fdotr_compute(); +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +void PairREBOMoS::allocate() +{ + allocated = 1; + int n = atom->ntypes; + + memory->create(setflag,n+1,n+1,"pair:setflag"); + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + setflag[i][j] = 0; + + memory->create(cutsq,n+1,n+1,"pair:cutsq"); + memory->create(cutghost,n+1,n+1,"pair:cutghost"); + + // only sized by M,S = 2 types + + memory->create(lj1,2,2,"pair:lj1"); + memory->create(lj2,2,2,"pair:lj2"); + memory->create(lj3,2,2,"pair:lj3"); + memory->create(lj4,2,2,"pair:lj4"); + + map = new int[n+1]; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +void PairREBOMoS::settings(int narg, char ** /* arg */) +{ + if (narg != 0) error->all(FLERR,"Illegal pair_style command"); +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +void PairREBOMoS::coeff(int narg, char **arg) +{ + if (!allocated) allocate(); + + if (narg != 3 + atom->ntypes) + error->all(FLERR,"Incorrect args for pair coefficients"); + + // insure I,J args are * * + + if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) + error->all(FLERR,"Incorrect args for pair coefficients"); + + // read args that map atom types to Mo and S + // map[i] = which element (0,1) the Ith atom type is, -1 if NULL + + for (int i = 3; i < narg; i++) { + if (strcmp(arg[i],"NULL") == 0) { + map[i-2] = -1; + continue; + } else if (strcmp(arg[i],"Mo") == 0) { + map[i-2] = 0; + } else if (strcmp(arg[i],"M") == 0) { // backward compatibility + map[i-2] = 0; + } else if (strcmp(arg[i],"S") == 0) { + map[i-2] = 1; + } else error->all(FLERR,"Incorrect args for pair coefficients"); + } + + // read potential file and initialize fitting splines + + read_file(arg[2]); + + // clear setflag since coeff() called once with I,J = * * + + int n = atom->ntypes; + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + setflag[i][j] = 0; + + // set setflag i,j for type pairs where both are mapped to elements + + int count = 0; + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + if (map[i] >= 0 && map[j] >= 0) { + setflag[i][j] = 1; + count++; + } + + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +void PairREBOMoS::init_style() +{ + if (atom->tag_enable == 0) + error->all(FLERR,"Pair style REBOMoS requires atom IDs"); + if (force->newton_pair == 0) + error->all(FLERR,"Pair style REBOMoS requires newton pair on"); + + // need a full neighbor list, including neighbors of ghosts + + neighbor->add_request(this,NeighConst::REQ_FULL|NeighConst::REQ_GHOST); + + // local REBO neighbor list + // create pages if first time or if neighbor pgsize/oneatom has changed + + int create = 0; + if (ipage == nullptr) create = 1; + if (pgsize != neighbor->pgsize) create = 1; + if (oneatom != neighbor->oneatom) create = 1; + + if (create) { + delete[] ipage; + pgsize = neighbor->pgsize; + oneatom = neighbor->oneatom; + + int nmypage= comm->nthreads; + ipage = new MyPage[nmypage]; + for (int i = 0; i < nmypage; i++) + ipage[i].init(oneatom,pgsize,PGDELTA); + } +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +double PairREBOMoS::init_one(int i, int j) +{ + if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); + + // convert to Mo,S types + + int ii = map[i]; + int jj = map[j]; + + // use Mo-Mo values for these cutoffs since M atoms are biggest + + // cut3rebo = 3 REBO distances + + cut3rebo = 3.0 * rcmax[0][0]; + + // cutljrebosq = furthest distance from an owned atom a ghost atom can be + // to need its REBO neighs computed + // interaction = M-K-I-J-L-N with I = owned and J = ghost + // this insures N is in the REBO neigh list of L + // since I-J < rcLJmax and J-L < rmax + + double cutljrebo = rcLJmax[0][0] + rcmax[0][0]; + cutljrebosq = cutljrebo * cutljrebo; + + // cutmax = furthest distance from an owned atom + // at which another atom will feel force, i.e. the ghost cutoff + // for REBO term in potential: + // interaction = M-K-I-J-L-N with I = owned and J = ghost + // I to N is max distance = 3 REBO distances + // for LJ term in potential: + // short interaction = M-K-I-J-L-N with I = owned, J = ghost, I-J < rcLJmax + // rcLJmax + 2*rcmax, since I-J < rcLJmax and J-L,L-N = REBO distances + // long interaction = I-J with I = owned and J = ghost + // cutlj*sigma, since I-J < LJ cutoff + // cutghost = REBO cutoff used in REBO_neigh() for neighbors of ghosts + + double cutmax = MAX(cut3rebo,rcLJmax[0][0] + 2.0*rcmax[0][0]); + + cutghost[i][j] = rcmax[ii][jj]; + lj1[ii][jj] = 48.0 * epsilon[ii][jj] * powint(sigma[ii][jj],12); + lj2[ii][jj] = 24.0 * epsilon[ii][jj] * powint(sigma[ii][jj],6); + lj3[ii][jj] = 4.0 * epsilon[ii][jj] * powint(sigma[ii][jj],12); + lj4[ii][jj] = 4.0 * epsilon[ii][jj] * powint(sigma[ii][jj],6); + + cutghost[j][i] = cutghost[i][j]; + lj1[jj][ii] = lj1[ii][jj]; + lj2[jj][ii] = lj2[ii][jj]; + lj3[jj][ii] = lj3[ii][jj]; + lj4[jj][ii] = lj4[ii][jj]; + + return cutmax; +} + +/* ---------------------------------------------------------------------- + create REBO neighbor list from main neighbor list + REBO neighbor list stores neighbors of ghost atoms +------------------------------------------------------------------------- */ + +void PairREBOMoS::REBO_neigh() +{ + int i,j,ii,jj,n,allnum,jnum,itype,jtype; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq,dS; + int *ilist,*jlist,*numneigh,**firstneigh; + int *neighptr; + + double **x = atom->x; + int *type = atom->type; + + if (atom->nmax > maxlocal) { + maxlocal = atom->nmax; + memory->destroy(REBO_numneigh); + memory->sfree(REBO_firstneigh); + memory->destroy(nM); + memory->destroy(nS); + memory->create(REBO_numneigh,maxlocal,"REBOMoS:numneigh"); + REBO_firstneigh = (int **) memory->smalloc(maxlocal*sizeof(int *), + "REBOMoS:firstneigh"); + memory->create(nM,maxlocal,"REBOMoS:nM"); + memory->create(nS,maxlocal,"REBOMoS:nS"); + } + + allnum = list->inum + list->gnum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // store all REBO neighs of owned and ghost atoms + // scan full neighbor list of I + + ipage->reset(); + + for (ii = 0; ii < allnum; ii++) { + i = ilist[ii]; + + n = 0; + neighptr = ipage->vget(); + + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + itype = map[type[i]]; + nM[i] = nS[i] = 0.0; + jlist = firstneigh[i]; + jnum = numneigh[i]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + jtype = map[type[j]]; + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + + if (rsq < rcmaxsq[itype][jtype]) { + neighptr[n++] = j; + if (jtype == 0) + nM[i] += Sp(sqrt(rsq),rcmin[itype][jtype],rcmax[itype][jtype],dS); + else + nS[i] += Sp(sqrt(rsq),rcmin[itype][jtype],rcmax[itype][jtype],dS); + } + } + + REBO_firstneigh[i] = neighptr; + REBO_numneigh[i] = n; + ipage->vgot(n); + if (ipage->status()) + error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); + } +} + +/* ---------------------------------------------------------------------- + REBO forces and energy +------------------------------------------------------------------------- */ + +void PairREBOMoS::FREBO(int eflag) +{ + int i,j,k,ii,inum,itype,jtype; + tagint itag, jtag; + double delx,dely,delz,evdwl,fpair,xtmp,ytmp,ztmp; + double rsq,rij,wij; + double Qij,Aij,alphaij,VR,pre,dVRdi,VA,bij,dVAdi,dVA; + double dwij,del[3]; + int *ilist,*REBO_neighs; + + evdwl = 0.0; + + double **x = atom->x; + double **f = atom->f; + int *type = atom->type; + tagint *tag = atom->tag; + int nlocal = atom->nlocal; + int newton_pair = force->newton_pair; + + inum = list->inum; + ilist = list->ilist; + + // two-body interactions from REBO neighbor list, skip half of them + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + itag = tag[i]; + itype = map[type[i]]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + REBO_neighs = REBO_firstneigh[i]; + + for (k = 0; k < REBO_numneigh[i]; k++) { + j = REBO_neighs[k]; + jtag = tag[j]; + + if (itag > jtag) { + if ((itag+jtag) % 2 == 0) continue; + } else if (itag < jtag) { + if ((itag+jtag) % 2 == 1) continue; + } else { + if (x[j][2] < ztmp) continue; + if (x[j][2] == ztmp && x[j][1] < ytmp) continue; + if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue; + } + + jtype = map[type[j]]; + + delx = x[i][0] - x[j][0]; + dely = x[i][1] - x[j][1]; + delz = x[i][2] - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + rij = sqrt(rsq); + wij = Sp(rij,rcmin[itype][jtype],rcmax[itype][jtype],dwij); + if (wij <= TOL) continue; + + Qij = Q[itype][jtype]; + Aij = A[itype][jtype]; + alphaij = alpha[itype][jtype]; + + VR = wij*(1.0+(Qij/rij)) * Aij*exp(-alphaij*rij); + pre = wij*Aij * exp(-alphaij*rij); + dVRdi = pre * ((-alphaij)-(Qij/rsq)-(Qij*alphaij/rij)); + dVRdi += VR/wij * dwij; + + VA = dVA = 0.0; + VA = -wij * BIJc[itype][jtype] * exp(-Beta[itype][jtype]*rij); + + dVA = -Beta[itype][jtype] * VA; + dVA += VA/wij * dwij; + + del[0] = delx; + del[1] = dely; + del[2] = delz; + bij = bondorder(i,j,del,rij,VA,f); + dVAdi = bij*dVA; + + fpair = -(dVRdi+dVAdi) / rij; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; + + if (eflag) evdwl = VR + bij*VA; + if (evflag) ev_tally(i,j,nlocal,newton_pair,evdwl,0.0,fpair,delx,dely,delz); + } + } +} + +/* ---------------------------------------------------------------------- + compute LJ forces and energy +------------------------------------------------------------------------- */ + +void PairREBOMoS::FLJ(int eflag) +{ + int i,j,ii,jj,inum,jnum,itype,jtype; + tagint itag,jtag; + double evdwl,fpair,xtmp,ytmp,ztmp; + double rij,delij[3],rijsq; + double VLJ,dVLJ; + double vdw,dvdw; + double r2inv,r6inv; + int *ilist,*jlist,*numneigh,**firstneigh; + double c2,c3,dr,drp,r6; + + // I-J interaction from full neighbor list + // skip 1/2 of interactions since only consider each pair once + + evdwl = 0.0; + + double **x = atom->x; + double **f = atom->f; + tagint *tag = atom->tag; + int *type = atom->type; + int nlocal = atom->nlocal; + int newton_pair = force->newton_pair; + + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // loop over neighbors of my atoms + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + itag = tag[i]; + itype = map[type[i]]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + jtag = tag[j]; + + if (itag > jtag) { + if ((itag+jtag) % 2 == 0) continue; + } else if (itag < jtag) { + if ((itag+jtag) % 2 == 1) continue; + } else { + if (x[j][2] < ztmp) continue; + if (x[j][2] == ztmp && x[j][1] < ytmp) continue; + if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue; + } + jtype = map[type[j]]; + + delij[0] = xtmp - x[j][0]; + delij[1] = ytmp - x[j][1]; + delij[2] = ztmp - x[j][2]; + rijsq = delij[0]*delij[0] + delij[1]*delij[1] + delij[2]*delij[2]; + rij = sqrt(rijsq); + + // compute LJ forces and energy + + // Outside Rmax + if (rij > rcLJmax[itype][jtype] || rij < rcLJmin[itype][jtype]){ + VLJ = 0; + dVLJ = 0; + } + + // Inside Rmax and above 0.95*sigma + else if (rij <= rcLJmax[itype][jtype] && rij >= 0.95*sigma[itype][jtype]){ + r2inv = 1.0/rijsq; + r6inv = r2inv*r2inv*r2inv; + VLJ = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); + dVLJ = -r6inv*(lj1[itype][jtype]*r6inv - lj2[itype][jtype])/rij; + } + + // Below 0.95*sigma + else if (rij < 0.95*sigma[itype][jtype] && rij >= rcLJmin[itype][jtype]){ + dr = 0.95*sigma[itype][jtype] - rcLJmin[itype][jtype]; + r6 = powint((sigma[itype][jtype]/(0.95*sigma[itype][jtype])),6); + vdw = 4*epsilon[itype][jtype]*r6*(r6 - 1.0); + dvdw = (-4*epsilon[itype][jtype]/(0.95*sigma[itype][jtype]))*r6*(12.0*r6 - 6.0); + c2 = ((3.0/dr)*vdw - dvdw)/dr; + c3 = (vdw/(dr*dr) - c2)/dr; + + drp = rij - rcLJmin[itype][jtype]; + VLJ = drp*drp*(drp*c3 + c2); + dVLJ = drp*(3.0*drp*c3 + 2.0*c2); + } + + fpair = -dVLJ/rij; + f[i][0] += delij[0]*fpair; + f[i][1] += delij[1]*fpair; + f[i][2] += delij[2]*fpair; + f[j][0] -= delij[0]*fpair; + f[j][1] -= delij[1]*fpair; + f[j][2] -= delij[2]*fpair; + + if (eflag) evdwl = VLJ; + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delij[0],delij[1],delij[2]); + + } + } +} + +/* ---------------------------------------------------------------------- + Bij function + + The bond order term modified the attractive portion of the REBO + potential based on the number of atoms around a specific pair + and the bond angle between sets of three atoms. + + The functions G(cos(theta)) and P(N) are evaluated and their + derivatives are also computed for use in the force calculation. +------------------------------------------------------------------------- */ + +double PairREBOMoS::bondorder(int i, int j, double rij[3], double rijmag, double VA, double **f) +{ + int atomi,atomj,atomk,atoml; + int k,l; + int itype, jtype, ktype, ltype; + double rik[3], rjl[3], rji[3], rki[3],rlj[3], dwjl, bij; + double NijM,NijS,NjiM,NjiS,wik,dwik,wjl; + double rikmag,rjlmag,cosjik,cosijl,g,tmp2; + double Etmp,pij,tmp,dwij,dS; + double dgdc,pji; + double dcosjikdri[3],dcosijldri[3],dcosjikdrk[3]; + double dp; + double dcosjikdrj[3],dcosijldrj[3],dcosijldrl[3]; + double fi[3],fj[3],fk[3],fl[3]; + double PijS, PjiS; + int *REBO_neighs; + + double **x = atom->x; + int *type = atom->type; + + atomi = i; + atomj = j; + itype = map[type[i]]; + jtype = map[type[j]]; + Sp(rijmag,rcmin[itype][jtype],rcmax[itype][jtype],dwij); + NijM = nM[i]; + NijS = nS[i]; + NjiM = nM[j]; + NjiS = nS[j]; + bij = 0.0; + tmp = 0.0; + tmp2 = 0.0; + dgdc = 0.0; + Etmp = 0.0; + + REBO_neighs = REBO_firstneigh[i]; + for (k = 0; k < REBO_numneigh[i]; k++) { + atomk = REBO_neighs[k]; + if (atomk != atomj) { + ktype = map[type[atomk]]; + rik[0] = x[atomi][0]-x[atomk][0]; + rik[1] = x[atomi][1]-x[atomk][1]; + rik[2] = x[atomi][2]-x[atomk][2]; + rikmag = sqrt((rik[0]*rik[0])+(rik[1]*rik[1])+(rik[2]*rik[2])); + wik = Sp(rikmag,rcmin[itype][ktype],rcmax[itype][ktype],dS); + cosjik = ((rij[0]*rik[0])+(rij[1]*rik[1])+(rij[2]*rik[2])) / (rijmag*rikmag); + cosjik = MIN(cosjik,1.0); + cosjik = MAX(cosjik,-1.0); + + // evaluate g and derivative dg + + g = gSpline(cosjik,itype,dgdc); + Etmp = Etmp+(wik*g); + } + } + + dp = 0.0; + PijS = PijSpline(NijM,NijS,itype,dp); + pij = 1.0/sqrt(1.0+Etmp+PijS); + tmp = -0.5*cube(pij); + + // derivative calculations + + REBO_neighs = REBO_firstneigh[i]; + for (k = 0; k < REBO_numneigh[i]; k++) { + atomk = REBO_neighs[k]; + if (atomk != atomj) { + ktype = map[type[atomk]]; + rik[0] = x[atomi][0]-x[atomk][0]; + rik[1] = x[atomi][1]-x[atomk][1]; + rik[2] = x[atomi][2]-x[atomk][2]; + rikmag = sqrt((rik[0]*rik[0])+(rik[1]*rik[1])+(rik[2]*rik[2])); + wik = Sp(rikmag,rcmin[itype][ktype],rcmax[itype][ktype],dwik); + cosjik = (rij[0]*rik[0] + rij[1]*rik[1] + rij[2]*rik[2]) / (rijmag*rikmag); + cosjik = MIN(cosjik,1.0); + cosjik = MAX(cosjik,-1.0); + + dcosjikdri[0] = ((rij[0]+rik[0])/(rijmag*rikmag)) - + (cosjik*((rij[0]/(rijmag*rijmag))+(rik[0]/(rikmag*rikmag)))); + dcosjikdri[1] = ((rij[1]+rik[1])/(rijmag*rikmag)) - + (cosjik*((rij[1]/(rijmag*rijmag))+(rik[1]/(rikmag*rikmag)))); + dcosjikdri[2] = ((rij[2]+rik[2])/(rijmag*rikmag)) - + (cosjik*((rij[2]/(rijmag*rijmag))+(rik[2]/(rikmag*rikmag)))); + dcosjikdrk[0] = (-rij[0]/(rijmag*rikmag)) + + (cosjik*(rik[0]/(rikmag*rikmag))); + dcosjikdrk[1] = (-rij[1]/(rijmag*rikmag)) + + (cosjik*(rik[1]/(rikmag*rikmag))); + dcosjikdrk[2] = (-rij[2]/(rijmag*rikmag)) + + (cosjik*(rik[2]/(rikmag*rikmag))); + dcosjikdrj[0] = (-rik[0]/(rijmag*rikmag)) + + (cosjik*(rij[0]/(rijmag*rijmag))); + dcosjikdrj[1] = (-rik[1]/(rijmag*rikmag)) + + (cosjik*(rij[1]/(rijmag*rijmag))); + dcosjikdrj[2] = (-rik[2]/(rijmag*rikmag)) + + (cosjik*(rij[2]/(rijmag*rijmag))); + + g = gSpline(cosjik,itype,dgdc); + tmp2 = VA*0.5*(tmp*wik*dgdc); + fj[0] = -tmp2*dcosjikdrj[0]; + fj[1] = -tmp2*dcosjikdrj[1]; + fj[2] = -tmp2*dcosjikdrj[2]; + fi[0] = -tmp2*dcosjikdri[0]; + fi[1] = -tmp2*dcosjikdri[1]; + fi[2] = -tmp2*dcosjikdri[2]; + fk[0] = -tmp2*dcosjikdrk[0]; + fk[1] = -tmp2*dcosjikdrk[1]; + fk[2] = -tmp2*dcosjikdrk[2]; + + // coordination forces + + // dwik forces (from partial derivative) + + tmp2 = VA*0.5*(tmp*dwik*g)/rikmag; + fi[0] -= tmp2*rik[0]; + fi[1] -= tmp2*rik[1]; + fi[2] -= tmp2*rik[2]; + fk[0] += tmp2*rik[0]; + fk[1] += tmp2*rik[1]; + fk[2] += tmp2*rik[2]; + + // PIJ forces (from coordination P(N) term) + + tmp2 = VA*0.5*(tmp*dp*dwik)/rikmag; + fi[0] -= tmp2*rik[0]; + fi[1] -= tmp2*rik[1]; + fi[2] -= tmp2*rik[2]; + fk[0] += tmp2*rik[0]; + fk[1] += tmp2*rik[1]; + fk[2] += tmp2*rik[2]; + + // dgdN forces are removed + + f[atomi][0] += fi[0]; f[atomi][1] += fi[1]; f[atomi][2] += fi[2]; + f[atomj][0] += fj[0]; f[atomj][1] += fj[1]; f[atomj][2] += fj[2]; + f[atomk][0] += fk[0]; f[atomk][1] += fk[1]; f[atomk][2] += fk[2]; + + if (vflag_either) { + rji[0] = -rij[0]; rji[1] = -rij[1]; rji[2] = -rij[2]; + rki[0] = -rik[0]; rki[1] = -rik[1]; rki[2] = -rik[2]; + v_tally3(atomi,atomj,atomk,fj,fk,rji,rki); + } + } + } + + // PIJ force contribution additional term + tmp2 = -VA*0.5*(tmp*dp*dwij)/rijmag; + + f[atomi][0] += rij[0]*tmp2; + f[atomi][1] += rij[1]*tmp2; + f[atomi][2] += rij[2]*tmp2; + f[atomj][0] -= rij[0]*tmp2; + f[atomj][1] -= rij[1]*tmp2; + f[atomj][2] -= rij[2]*tmp2; + + if (vflag_either) v_tally2(atomi,atomj,tmp2,rij); + + tmp = 0.0; + tmp2 = 0.0; + Etmp = 0.0; + + REBO_neighs = REBO_firstneigh[j]; + for (l = 0; l < REBO_numneigh[j]; l++) { + atoml = REBO_neighs[l]; + if (atoml != atomi) { + ltype = map[type[atoml]]; + rjl[0] = x[atomj][0]-x[atoml][0]; + rjl[1] = x[atomj][1]-x[atoml][1]; + rjl[2] = x[atomj][2]-x[atoml][2]; + rjlmag = sqrt((rjl[0]*rjl[0])+(rjl[1]*rjl[1])+(rjl[2]*rjl[2])); + wjl = Sp(rjlmag,rcmin[jtype][ltype],rcmax[jtype][ltype],dS); + cosijl = -1.0*((rij[0]*rjl[0])+(rij[1]*rjl[1])+(rij[2]*rjl[2])) / (rijmag*rjlmag); + cosijl = MIN(cosijl,1.0); + cosijl = MAX(cosijl,-1.0); + + // evaluate g and derivative dg + + g = gSpline(cosijl,jtype,dgdc); + Etmp = Etmp+(wjl*g); + } + } + + dp = 0.0; + PjiS = PijSpline(NjiM,NjiS,jtype,dp); + pji = 1.0/sqrt(1.0+Etmp+PjiS); + tmp = -0.5*cube(pji); + + REBO_neighs = REBO_firstneigh[j]; + for (l = 0; l < REBO_numneigh[j]; l++) { + atoml = REBO_neighs[l]; + if (atoml != atomi) { + ltype = map[type[atoml]]; + rjl[0] = x[atomj][0]-x[atoml][0]; + rjl[1] = x[atomj][1]-x[atoml][1]; + rjl[2] = x[atomj][2]-x[atoml][2]; + rjlmag = sqrt((rjl[0]*rjl[0])+(rjl[1]*rjl[1])+(rjl[2]*rjl[2])); + wjl = Sp(rjlmag,rcmin[jtype][ltype],rcmax[jtype][ltype],dwjl); + cosijl = (-1.0*((rij[0]*rjl[0])+(rij[1]*rjl[1])+(rij[2]*rjl[2]))) / (rijmag*rjlmag); + cosijl = MIN(cosijl,1.0); + cosijl = MAX(cosijl,-1.0); + + dcosijldri[0] = (-rjl[0]/(rijmag*rjlmag)) - + (cosijl*rij[0]/(rijmag*rijmag)); + dcosijldri[1] = (-rjl[1]/(rijmag*rjlmag)) - + (cosijl*rij[1]/(rijmag*rijmag)); + dcosijldri[2] = (-rjl[2]/(rijmag*rjlmag)) - + (cosijl*rij[2]/(rijmag*rijmag)); + dcosijldrj[0] = ((-rij[0]+rjl[0])/(rijmag*rjlmag)) + + (cosijl*((rij[0]/square(rijmag))-(rjl[0]/(rjlmag*rjlmag)))); + dcosijldrj[1] = ((-rij[1]+rjl[1])/(rijmag*rjlmag)) + + (cosijl*((rij[1]/square(rijmag))-(rjl[1]/(rjlmag*rjlmag)))); + dcosijldrj[2] = ((-rij[2]+rjl[2])/(rijmag*rjlmag)) + + (cosijl*((rij[2]/square(rijmag))-(rjl[2]/(rjlmag*rjlmag)))); + dcosijldrl[0] = (rij[0]/(rijmag*rjlmag))+(cosijl*rjl[0]/(rjlmag*rjlmag)); + dcosijldrl[1] = (rij[1]/(rijmag*rjlmag))+(cosijl*rjl[1]/(rjlmag*rjlmag)); + dcosijldrl[2] = (rij[2]/(rijmag*rjlmag))+(cosijl*rjl[2]/(rjlmag*rjlmag)); + + // evaluate g and derivatives dg + + g = gSpline(cosijl,jtype,dgdc); + tmp2 = VA*0.5*(tmp*wjl*dgdc); + fi[0] = -tmp2*dcosijldri[0]; + fi[1] = -tmp2*dcosijldri[1]; + fi[2] = -tmp2*dcosijldri[2]; + fj[0] = -tmp2*dcosijldrj[0]; + fj[1] = -tmp2*dcosijldrj[1]; + fj[2] = -tmp2*dcosijldrj[2]; + fl[0] = -tmp2*dcosijldrl[0]; + fl[1] = -tmp2*dcosijldrl[1]; + fl[2] = -tmp2*dcosijldrl[2]; + + // coordination forces + + // dwik forces (from partial derivative) + + tmp2 = VA*0.5*(tmp*dwjl*g)/rjlmag; + fj[0] -= tmp2*rjl[0]; + fj[1] -= tmp2*rjl[1]; + fj[2] -= tmp2*rjl[2]; + fl[0] += tmp2*rjl[0]; + fl[1] += tmp2*rjl[1]; + fl[2] += tmp2*rjl[2]; + + // PIJ forces (coordination) + + tmp2 = VA*0.5*(tmp*dp*dwjl)/rjlmag; + fj[0] -= tmp2*rjl[0]; + fj[1] -= tmp2*rjl[1]; + fj[2] -= tmp2*rjl[2]; + fl[0] += tmp2*rjl[0]; + fl[1] += tmp2*rjl[1]; + fl[2] += tmp2*rjl[2]; + + // dgdN forces are removed + + f[atomi][0] += fi[0]; f[atomi][1] += fi[1]; f[atomi][2] += fi[2]; + f[atomj][0] += fj[0]; f[atomj][1] += fj[1]; f[atomj][2] += fj[2]; + f[atoml][0] += fl[0]; f[atoml][1] += fl[1]; f[atoml][2] += fl[2]; + + if (vflag_either) { + rlj[0] = -rjl[0]; rlj[1] = -rjl[1]; rlj[2] = -rjl[2]; + v_tally3(atomi,atomj,atoml,fi,fl,rij,rlj); + } + } + } + + // PIJ force contribution additional term + + tmp2 = -VA*0.5*(tmp*dp*dwij)/rijmag; + f[atomi][0] += rij[0]*tmp2; + f[atomi][1] += rij[1]*tmp2; + f[atomi][2] += rij[2]*tmp2; + f[atomj][0] -= rij[0]*tmp2; + f[atomj][1] -= rij[1]*tmp2; + f[atomj][2] -= rij[2]*tmp2; + + if (vflag_either) v_tally2(atomi,atomj,tmp2,rij); + + bij = (0.5*(pij+pji)); + return bij; +} + +/* ---------------------------------------------------------------------- + G calculation +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + read REBO potential file +------------------------------------------------------------------------- */ + +void PairREBOMoS::read_file(char *filename) +{ + // REBO Parameters (Mo-S REBO) + + double rcmin_MM,rcmin_MS,rcmin_SS,rcmax_MM,rcmax_MS,rcmax_SS; + double Q_MM,Q_MS,Q_SS,alpha_MM,alpha_MS,alpha_SS,A_MM,A_MS,A_SS; + double BIJc_MM1,BIJc_MS1,BIJc_SS1; + double Beta_MM1,Beta_MS1,Beta_SS1; + double M_bg0,M_bg1,M_bg2,M_bg3,M_bg4,M_bg5,M_bg6; + double S_bg0,S_bg1,S_bg2,S_bg3,S_bg4,S_bg5,S_bg6; + double M_b0,M_b1,M_b2,M_b3,M_b4,M_b5,M_b6; + double S_b0,S_b1,S_b2,S_b3,S_b4,S_b5,S_b6; + double M_a0,M_a1,M_a2,M_a3; + double S_a0,S_a1,S_a2,S_a3; + + // LJ Parameters (Mo-S REBO) + + double epsilon_MM,epsilon_SS; + double sigma_MM,sigma_SS; + + // read file on proc 0 + + if (comm->me == 0) { + PotentialFileReader reader(lmp, filename, "rebomos"); + + // read parameters + + std::vector params { + &rcmin_MM, + &rcmin_MS, + &rcmin_SS, + &rcmax_MM, + &rcmax_MS, + &rcmax_SS, + &Q_MM, + &Q_MS, + &Q_SS, + &alpha_MM, + &alpha_MS, + &alpha_SS, + &A_MM, + &A_MS, + &A_SS, + &BIJc_MM1, + &BIJc_MS1, + &BIJc_SS1, + &Beta_MM1, + &Beta_MS1, + &Beta_SS1, + &M_b0, + &M_b1, + &M_b2, + &M_b3, + &M_b4, + &M_b5, + &M_b6, + &M_bg0, + &M_bg1, + &M_bg2, + &M_bg3, + &M_bg4, + &M_bg5, + &M_bg6, + &S_b0, + &S_b1, + &S_b2, + &S_b3, + &S_b4, + &S_b5, + &S_b6, + &S_bg0, + &S_bg1, + &S_bg2, + &S_bg3, + &S_bg4, + &S_bg5, + &S_bg6, + &M_a0, + &M_a1, + &M_a2, + &M_a3, + &S_a0, + &S_a1, + &S_a2, + &S_a3, + + // LJ parameters + &epsilon_MM, + &epsilon_SS, + &sigma_MM, + &sigma_SS, + }; + + try { + for (auto ¶m : params) { + *param = reader.next_double(); + } + } catch (TokenizerException &e) { + error->one(FLERR, "reading rebomos potential file {}\nREASON: {}\n", filename, e.what()); + } catch (FileReaderException &fre) { + error->one(FLERR, "reading rebomos potential file {}\nREASON: {}\n", filename, fre.what()); + } + + // store read-in values in arrays + + // REBO + + rcmin[0][0] = rcmin_MM; + rcmin[0][1] = rcmin_MS; + rcmin[1][0] = rcmin[0][1]; + rcmin[1][1] = rcmin_SS; + + rcmax[0][0] = rcmax_MM; + rcmax[0][1] = rcmax_MS; + rcmax[1][0] = rcmax[0][1]; + rcmax[1][1] = rcmax_SS; + + rcmaxsq[0][0] = rcmax[0][0]*rcmax[0][0]; + rcmaxsq[1][0] = rcmax[1][0]*rcmax[1][0]; + rcmaxsq[0][1] = rcmax[0][1]*rcmax[0][1]; + rcmaxsq[1][1] = rcmax[1][1]*rcmax[1][1]; + + Q[0][0] = Q_MM; + Q[0][1] = Q_MS; + Q[1][0] = Q[0][1]; + Q[1][1] = Q_SS; + + alpha[0][0] = alpha_MM; + alpha[0][1] = alpha_MS; + alpha[1][0] = alpha[0][1]; + alpha[1][1] = alpha_SS; + + A[0][0] = A_MM; + A[0][1] = A_MS; + A[1][0] = A[0][1]; + A[1][1] = A_SS; + + BIJc[0][0] = BIJc_MM1; + BIJc[0][1] = BIJc_MS1; + BIJc[1][0] = BIJc_MS1; + BIJc[1][1] = BIJc_SS1; + + Beta[0][0] = Beta_MM1; + Beta[0][1] = Beta_MS1; + Beta[1][0] = Beta_MS1; + Beta[1][1] = Beta_SS1; + + b0[0] = M_b0; + b1[0] = M_b1; + b2[0] = M_b2; + b3[0] = M_b3; + b4[0] = M_b4; + b5[0] = M_b5; + b6[0] = M_b6; + + bg0[0] = M_bg0; + bg1[0] = M_bg1; + bg2[0] = M_bg2; + bg3[0] = M_bg3; + bg4[0] = M_bg4; + bg5[0] = M_bg5; + bg6[0] = M_bg6; + + b0[1] = S_b0; + b1[1] = S_b1; + b2[1] = S_b2; + b3[1] = S_b3; + b4[1] = S_b4; + b5[1] = S_b5; + b6[1] = S_b6; + + bg0[1] = S_bg0; + bg1[1] = S_bg1; + bg2[1] = S_bg2; + bg3[1] = S_bg3; + bg4[1] = S_bg4; + bg5[1] = S_bg5; + bg6[1] = S_bg6; + + a0[0] = M_a0; + a1[0] = M_a1; + a2[0] = M_a2; + a3[0] = M_a3; + + a0[1] = S_a0; + a1[1] = S_a1; + a2[1] = S_a2; + a3[1] = S_a3; + + // LJ + + sigma[0][0] = sigma_MM; + sigma[0][1] = (sigma_MM + sigma_SS)/2; + sigma[1][0] = sigma[0][1]; + sigma[1][1] = sigma_SS; + + epsilon[0][0] = epsilon_MM; + epsilon[0][1] = sqrt(epsilon_MM*epsilon_SS); + epsilon[1][0] = epsilon[0][1]; + epsilon[1][1] = epsilon_SS; + + rcLJmin[0][0] = rcmin_MM; + rcLJmin[0][1] = rcmin_MS; + rcLJmin[1][0] = rcmin[0][1]; + rcLJmin[1][1] = rcmin_SS; + + rcLJmax[0][0] = 2.5*sigma[0][0]; + rcLJmax[0][1] = 2.5*sigma[0][1]; + rcLJmax[1][0] = rcLJmax[0][1]; + rcLJmax[1][1] = 2.5*sigma[1][1]; + + rcLJmaxsq[0][0] = rcLJmax[0][0]*rcLJmax[0][0]; + rcLJmaxsq[1][0] = rcLJmax[1][0]*rcLJmax[1][0]; + rcLJmaxsq[0][1] = rcLJmax[0][1]*rcLJmax[0][1]; + rcLJmaxsq[1][1] = rcLJmax[1][1]*rcLJmax[1][1]; + + } + + // broadcast read-in and setup values + + MPI_Bcast(&rcmin[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&rcmax[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&rcmaxsq[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&rcmaxp[0][0],4,MPI_DOUBLE,0,world); + + MPI_Bcast(&Q[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&alpha[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&A[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&BIJc[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&Beta[0][0],4,MPI_DOUBLE,0,world); + + MPI_Bcast(&b0[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b1[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b2[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b3[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b4[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b5[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&b6[0],2,MPI_DOUBLE,0,world); + + MPI_Bcast(&a0[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&a1[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&a2[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&a3[0],2,MPI_DOUBLE,0,world); + + MPI_Bcast(&bg0[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg1[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg2[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg3[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg4[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg5[0],2,MPI_DOUBLE,0,world); + MPI_Bcast(&bg6[0],2,MPI_DOUBLE,0,world); + + MPI_Bcast(&rcLJmin[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&rcLJmax[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&rcLJmaxsq[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&epsilon[0][0],4,MPI_DOUBLE,0,world); + MPI_Bcast(&sigma[0][0],4,MPI_DOUBLE,0,world); +} + +/* ---------------------------------------------------------------------- + memory usage of local atom-based arrays +------------------------------------------------------------------------- */ + +double PairREBOMoS::memory_usage() +{ + double bytes = 0.0; + bytes += (double)maxlocal * sizeof(int); + bytes += (double)maxlocal * sizeof(int *); + + for (int i = 0; i < comm->nthreads; i++) + bytes += ipage[i].size(); + + bytes += 3.0 * maxlocal * sizeof(double); + return bytes; +} diff --git a/src/MANYBODY/pair_rebomos.h b/src/MANYBODY/pair_rebomos.h new file mode 100644 index 0000000000..4a530de329 --- /dev/null +++ b/src/MANYBODY/pair_rebomos.h @@ -0,0 +1,219 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS +// clang-format off +PairStyle(rebomos,PairREBOMoS); +// clang-format on +#else + +#ifndef LMP_PAIR_REBOMOS_H +#define LMP_PAIR_REBOMOS_H + +#include "math_const.h" +#include "pair.h" +#include + +namespace LAMMPS_NS { + +class PairREBOMoS : public Pair { + public: + PairREBOMoS(class LAMMPS *); + ~PairREBOMoS() override; + void compute(int, int) override; + void settings(int, char **) override; + void coeff(int, char **) override; + void init_style() override; + double init_one(int, int) override; + double memory_usage() override; + + protected: + double cutljrebosq; // cut for when to compute + // REBO neighs of ghost atoms + + double **lj1, **lj2, **lj3, **lj4; // pre-computed LJ coeffs for M,S types + double cut3rebo; // maximum distance for 3rd REBO neigh + + int maxlocal; // size of numneigh, firstneigh arrays + int pgsize; // size of neighbor page + int oneatom; // max # of neighbors for one atom + MyPage *ipage; // neighbor list pages + int *REBO_numneigh; // # of pair neighbors for each atom + int **REBO_firstneigh; // ptr to 1st neighbor of each atom + + double *closestdistsq; // closest owned atom dist to each ghost + double *nM, *nS; // sum of weighting fns with REBO neighs + + double rcmin[2][2], rcmax[2][2], rcmaxsq[2][2], rcmaxp[2][2]; + double Q[2][2], alpha[2][2], A[2][2], BIJc[2][2], Beta[2][2]; + double b0[2], b1[2], b2[2], b3[2], b4[2], b5[2], b6[2]; + double bg0[2], bg1[2], bg2[2], bg3[2], bg4[2], bg5[2], bg6[2]; + double a0[2], a1[2], a2[2], a3[2]; + double rcLJmin[2][2], rcLJmax[2][2], rcLJmaxsq[2][2]; + double epsilon[2][2], sigma[2][2]; + + void REBO_neigh(); + void FREBO(int); + void FLJ(int); + + double bondorder(int, int, double *, double, double, double **); + + inline double gSpline(const double costh, const int typei, double &dgdc) const + { + const double b0i = b0[typei]; + const double b1i = b1[typei]; + const double b2i = b2[typei]; + const double b3i = b3[typei]; + const double b4i = b4[typei]; + const double b5i = b5[typei]; + const double b6i = b6[typei]; + double g = 0.0; + + if (costh >= -1.0 && costh < 0.5) { + g = b6i * costh; + double dg = 6.0 * b6i * costh; + g += b5i; + dg += 5.0 * b5i; + g *= costh; + dg *= costh; + g += b4i; + dg += 4.0 * b4i; + g *= costh; + dg *= costh; + g += b3i; + dg += 3.0 * b3i; + g *= costh; + dg *= costh; + g += b2i; + dg += 2.0 * b2i; + g *= costh; + dg *= costh; + g += b1i; + dg += b1i; + g *= costh; + g += b0i; + dgdc = dg; + + } else if (costh >= 0.5 && costh <= 1.0) { + double gcos = b6i * costh; + double dgcos = 6.0 * b6i * costh; + gcos += b5i; + dgcos += 5.0 * b5i; + gcos *= costh; + dgcos *= costh; + gcos += b4i; + dgcos += 4.0 * b4i; + gcos *= costh; + dgcos *= costh; + gcos += b3i; + dgcos += 3.0 * b3i; + gcos *= costh; + dgcos *= costh; + gcos += b2i; + dgcos += 2.0 * b2i; + gcos *= costh; + dgcos *= costh; + gcos += b1i; + dgcos += b1i; + gcos *= costh; + gcos += b0i; + + const double bg0i = bg0[typei]; + const double bg1i = bg1[typei]; + const double bg2i = bg2[typei]; + const double bg3i = bg3[typei]; + const double bg4i = bg4[typei]; + const double bg5i = bg5[typei]; + const double bg6i = bg6[typei]; + double gamma = bg6i * costh; + double dgamma = 6.0 * bg6i * costh; + gamma += bg5i; + dgamma += 5.0 * bg5i; + gamma *= costh; + dgamma *= costh; + gamma += bg4i; + dgamma += 4.0 * bg4i; + gamma *= costh; + dgamma *= costh; + gamma += bg3i; + dgamma += 3.0 * bg3i; + gamma *= costh; + dgamma *= costh; + gamma += bg2i; + dgamma += 2.0 * bg2i; + gamma *= costh; + dgamma *= costh; + gamma += bg1i; + dgamma += bg1i; + gamma *= costh; + gamma += bg0i; + + const double tmp = MathConst::MY_2PI * (costh - 0.5); + const double psi = 0.5 * (1 - cos(tmp)); + const double dpsi = MathConst::MY_PI * sin(tmp); + g = gcos + psi * (gamma - gcos); + dgdc = dgcos + dpsi * (gamma - gcos) + psi * (dgamma - dgcos); + } else { + dgdc = 0.0; + } + return g; + } + + /* ---------------------------------------------------------------------- + Pij calculation + ------------------------------------------------------------------------- */ + + inline double PijSpline(const double NM, const double NS, const int typei, double &dp) const + { + const double N = NM + NS; + + dp = -a0[typei] + a1[typei] * a2[typei] * exp(-a2[typei] * N); + return -a0[typei] * (N - 1) - a1[typei] * exp(-a2[typei] * N) + a3[typei]; + } + + void read_file(char *); + void allocate(); + + // ---------------------------------------------------------------------- + // S'(t) and S(t) cutoff functions + // added to header for inlining + // ---------------------------------------------------------------------- + + /* ---------------------------------------------------------------------- + cutoff function Sprime + return cutoff and dX = derivative + no side effects + ------------------------------------------------------------------------- */ + + inline double Sp(double Xij, double Xmin, double Xmax, double &dX) const + { + double cutoff; + + const double t = (Xij - Xmin) / (Xmax - Xmin); + if (t <= 0.0) { + cutoff = 1.0; + dX = 0.0; + } else if (t >= 1.0) { + cutoff = 0.0; + dX = 0.0; + } else { + cutoff = 0.5 * (1.0 + cos(t * MathConst::MY_PI)); + dX = (-0.5 * MathConst::MY_PI * sin(t * MathConst::MY_PI)) / (Xmax - Xmin); + } + return cutoff; + }; +}; +} // namespace LAMMPS_NS + +#endif +#endif diff --git a/unittest/force-styles/tests/manybody-pair-rebomos.yaml b/unittest/force-styles/tests/manybody-pair-rebomos.yaml new file mode 100644 index 0000000000..1d862720af --- /dev/null +++ b/unittest/force-styles/tests/manybody-pair-rebomos.yaml @@ -0,0 +1,126 @@ +--- +lammps_version: 7 Feb 2024 +tags: slow +date_generated: Thu Feb 22 09:08:59 2024 +epsilon: 1e-12 +skip_tests: +prerequisites: ! | + pair rebomos +pre_commands: ! | + variable newton_pair delete + if "$(is_active(package,gpu)) > 0.0" then "variable newton_pair index off" else "variable newton_pair index on" +post_commands: ! | + neigh_modify one 3000 +input_file: in.airebo +pair_style: rebomos +pair_coeff: ! | + * * MoS.rebomos Mo S +extract: ! "" +natoms: 48 +init_vdwl: 3158.017726833385 +init_coul: 0 +init_stress: ! |2- + 6.8398718310371441e+03 6.7325636075141883e+03 6.1154248388685965e+03 -3.2850057579078185e+02 -6.6397329123828470e+01 -3.4208234997867203e+02 +init_forces: ! |2 + 1 -3.7681565852737293e+00 2.4378308384489483e+02 -2.6969740060923279e+01 + 2 2.6266038011491645e+02 -2.0681295165426090e+02 -1.9964225279104706e+01 + 3 -2.5778010496370018e+02 -2.3678496612327552e+02 4.3829487525746238e+01 + 4 -1.0244959408607365e+01 -2.6794342328905179e+02 -2.6250177085935768e+01 + 5 2.2561151172717553e+02 2.0458598509633319e+02 -4.2183143539914880e+01 + 6 -2.4766208404861507e+02 1.8231884233051196e+02 1.2358374858464346e+01 + 7 -2.8974107341390795e+01 1.1031227139363692e+02 -1.2014739688866064e+02 + 8 2.1125868843851663e+02 -2.8863731327540540e+02 1.6869558243398984e+01 + 9 -3.1045083889038222e+02 -1.7569259168198960e+02 7.9653354234911163e+01 + 10 3.9886149586070935e+01 -1.0347554263069082e+02 1.5430519714983259e+02 + 11 1.8975960895859026e+02 1.4943835159807929e+02 -7.3224202319244824e+01 + 12 -2.1525843617159188e+02 2.2144411990369784e+02 -1.4893230739895195e+01 + 13 -4.5214798787473534e+00 1.1303681465405538e+02 -1.1385660017739841e+02 + 14 2.3203040375527121e+02 -3.4422786145586961e+01 1.8438743650405590e+02 + 15 -9.7170644212253990e+01 -2.9205504121924292e+02 1.9237141908302370e+01 + 16 -5.1044169101209107e+01 -1.4503490444304657e+02 1.5798442448724001e+02 + 17 2.8968061091312188e+02 8.7626477818666558e+01 -5.8802357863256212e+01 + 18 -1.7269858357220591e+02 8.9805161881631591e+01 -1.7847636055101773e+02 + 19 1.0760757939777642e+02 1.2642591396366257e+02 1.5914528700154095e+01 + 20 8.4608047558760049e+01 -2.4114295115066687e+02 -8.5792447633922421e+01 + 21 -8.8196263713344706e+01 -1.2718199182512282e+02 -7.0146571930858386e+01 + 22 -9.8957412653883708e+01 -1.4706747771082254e+02 -4.1887992372999022e+01 + 23 1.3739608451158423e+02 2.5576040689729510e+02 3.0309933932861746e+01 + 24 -1.7919184387909232e+02 1.4014151619269020e+02 1.6188399417577682e+02 + 25 -7.7347072523993347e+01 1.5555894832740958e+02 2.6182670200573220e+01 + 26 7.1360176064432650e+01 -2.9346871053231695e+02 -4.0766232856732509e+00 + 27 -2.6964124483003886e+01 9.8094028485618843e+00 2.4520760165936114e+01 + 28 1.2261226472559841e+02 -2.1507437048459283e+02 -3.0529457478077248e+01 + 29 2.2123474818204119e+01 2.8827028167050270e+02 1.0492685172067040e+02 + 30 -3.0573547162322302e+02 6.5880918489915032e+01 -1.1459287271946665e+02 + 31 6.0299759271951014e+00 1.7876996651274851e+02 -1.2964028093837922e+02 + 32 2.3752911820416773e+02 -1.2903240767402318e+02 1.2355068302179771e+02 + 33 -2.7462402312452838e+02 -5.3957296643601545e+01 9.5908146508348565e+01 + 34 -2.4514118579997412e+01 -1.0385194449627924e+02 1.4149428440602534e+02 + 35 1.2613298864651166e+02 6.2171771831118461e+00 -2.0642312645163636e+02 + 36 -6.9996802234927173e+01 2.9354514776980676e+02 -2.0963604805137543e+01 + 37 5.0241789394721707e+01 2.4495589528252060e+02 -1.1814425338523709e+01 + 38 2.2684897209808264e+02 -1.8673318434123004e+02 1.5220428086050066e+00 + 39 -2.5107271651763259e+02 -1.6443685417603410e+02 -3.8081572318769169e+01 + 40 -5.6754727284178912e+01 -2.5956532443118618e+02 -5.9343761520548126e+00 + 41 2.7426370608616236e+02 1.7742153146823480e+02 1.3451000229991498e+01 + 42 -2.2732796257204490e+02 2.5279459742055184e+02 -2.7020668313372529e+01 + 43 1.6217419052721431e+02 1.3946372126978235e+02 -2.0623397237537300e+00 + 44 3.0490806490775839e+01 2.1072542774667330e+01 8.2426559376766466e+00 + 45 -1.8440339212966003e+02 -2.5521581334939563e+02 2.6487508881411735e+01 + 46 -3.5020523296396959e+01 -2.5119105337038474e+02 8.0096253171487604e+00 + 47 3.2722641189388571e+02 9.7949745935413119e+01 -1.1898751818014821e+01 + 48 -1.3785292104885133e+02 3.2239007811982697e+02 2.4602884867061839e+01 +run_vdwl: 838.005031679853 +run_coul: 0 +run_stress: ! |2- + 2.0454406617512559e+03 2.1642975706136021e+03 3.2875013790709349e+03 2.4615001869678809e+02 9.3532964794023911e+01 -1.6795786485689854e+02 +run_forces: ! |2 + 1 -2.5386905249574866e+01 -9.9909927316940710e+01 1.9622022776949393e+00 + 2 -3.6801215363277215e+01 1.3354608905768052e+02 1.3651128931415545e+02 + 3 2.1845136723115344e+00 2.3527273580981478e+00 2.4005941692097457e+00 + 4 -3.7818914621624749e+01 3.2946537814811997e+01 4.3018847892043375e+01 + 5 9.6010433504280890e+00 4.3327442916171194e+01 -1.0513311611209312e+02 + 6 8.4308572792324540e+01 -2.3503352214725012e+01 5.0539884405443850e+01 + 7 -1.1497740491253731e+01 -6.4938790153209212e+01 3.8948855627091397e+01 + 8 -4.2897157525993697e+00 -3.3530261299383611e+01 9.5574489119024229e+00 + 9 4.8767710902858741e-01 -3.5176606358955858e+00 -1.4806227207057554e-01 + 10 -1.4766722110672411e+01 2.3818988804615220e+01 -5.3134339246512809e+01 + 11 -1.3935431402422819e+02 -1.5665571900752980e+02 -3.7627334252485582e+01 + 12 7.7074185304589484e+00 -1.2031768398608595e+01 1.8274050209872662e+01 + 13 2.3670515505343992e+01 -6.4282829210616583e+01 4.6336363412751325e+01 + 14 -2.5980738378663424e+00 8.4167979467127569e+00 -2.3849686761968631e+00 + 15 2.6909213334137871e+01 9.4711670949167956e+00 1.4728430099051328e+00 + 16 2.6072330920174934e+01 1.5861581881675242e+01 -5.1429144994723586e+01 + 17 -4.5656802478750279e+01 -1.0557685195759221e+02 -1.8486644164722456e+01 + 18 1.3345348571390588e+02 5.3791289185967734e+01 3.1330462313925089e+01 + 19 -3.4744179120880638e+01 -2.9727735009574776e+01 1.3758697899848009e+01 + 20 3.5805745710027459e+00 2.3635583506556830e+00 -9.8641913612550636e-01 + 21 -1.9112967021807076e+01 2.4093036642722907e+01 -1.8643238887150801e+01 + 22 -9.0201617792954476e+00 3.7160721932912736e+01 -5.0873237843214003e+00 + 23 -2.0559670924056718e+01 -1.3037172781831362e+01 -4.1555140102832148e+01 + 24 3.5016464856031341e+01 -1.2488249708112150e+02 -5.5132899737529639e+00 + 25 2.4856779395007460e+00 -6.7533673428345381e+01 -1.7153563726726016e+01 + 26 -8.6470517146734750e+01 -7.9057942497429794e+00 3.8434105758101332e+01 + 27 3.1062776626038996e+01 2.5568916700234454e+00 -2.3812255018358194e+01 + 28 -3.6128021960690276e+01 8.8535946500139033e+01 -3.1718315624050986e-01 + 29 -1.7473599694524488e+01 5.1605700760038529e+00 3.1477016370448561e+00 + 30 3.2722165297173231e+00 -5.9807188688706105e+00 3.0903475914489444e+01 + 31 -5.5852599877204412e-01 -3.7635607965114964e+01 5.5407547347738578e+01 + 32 -4.8419811021707950e+01 1.2083134296973620e+02 -1.4299477119499166e+01 + 33 2.5993167832212944e+01 5.4415694550334088e+01 -2.2817585641730194e+01 + 34 1.3632918027769463e+01 1.0165209000060044e+02 -6.0709294862836366e+01 + 35 -1.7896100047169217e+01 5.7265522876438499e+00 6.7274680861552483e+00 + 36 -1.8125137765726237e+01 2.7564787465936047e+00 -9.5278575701404478e+00 + 37 -3.5898678616111592e+00 -7.2362382910010311e+01 -9.3588358281326709e+00 + 38 -3.6726824963125949e+01 2.0008528283799198e+01 4.2387983046244827e+01 + 39 1.4756349734330427e+00 3.4387817449154888e+01 4.6004570693407864e+01 + 40 1.3004687263347805e+01 6.5948251357408196e+01 -9.3870897441198231e+00 + 41 -9.2360908880622592e+00 3.0113497063365648e+00 -1.1785409504259610e+01 + 42 -1.1795417170666214e+01 -1.1546754933247897e+01 -1.2188857610119777e+01 + 43 -6.5511968637617390e-01 -3.9133448932537512e+01 5.5788437875425423e-01 + 44 -4.2976958767216473e+01 1.8814792063050870e+01 -3.2742042602021932e+01 + 45 1.8589630046648591e+02 5.3367997582431663e+01 3.8324469380182308e+01 + 46 2.2463767362468872e+01 7.7485287617829670e+01 2.6113916756613811e+01 + 47 3.0703470673161828e+00 2.4966324680483410e+01 -5.0826014249556524e+00 + 48 7.6310071304830785e+01 -9.3082908173611301e+01 -1.1280958703044767e+02 +... From 3a82e76607dfcaf25fe566aef2e11202fe0dbd0f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 09:15:18 -0500 Subject: [PATCH 084/185] small corrections --- doc/src/pair_airebo.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/src/pair_airebo.rst b/doc/src/pair_airebo.rst index 9a1e4e5518..ce574cc734 100644 --- a/doc/src/pair_airebo.rst +++ b/doc/src/pair_airebo.rst @@ -156,7 +156,7 @@ pair_coeff command: The first 2 arguments must be \* \* so as to span all LAMMPS atom types. The first three C arguments map LAMMPS atom types 1,2,3 to the C element in the AIREBO file. The final H argument maps LAMMPS atom -type 4 to the H element in the SW file. If a mapping value is +type 4 to the H element in the AIREBO file. If a mapping value is specified as NULL, the mapping is not performed. This can be used when a *airebo* potential is used as part of the *hybrid* pair style. The NULL values are placeholders for atom types that will be used with @@ -222,12 +222,12 @@ enabled if LAMMPS was built with that package. See the :doc:`Build package ` setting to be "on" for pair interactions. -The CH.airebo and CH.airebo-m potential files provided with LAMMPS -(see the potentials directory) are parameterized for metal :doc:`units `. -You can use the AIREBO, AIREBO-M or REBO potential with any LAMMPS units, -but you would need to create your own AIREBO or AIREBO-M potential file -with coefficients listed in the appropriate units, if your simulation -does not use "metal" units. +The CH.airebo and CH.airebo-m potential files provided with LAMMPS (see +the potentials directory) are parameterized for metal :doc:`units +`. You can use the pair styles with *any* LAMMPS units, but you +would need to create your own AIREBO or AIREBO-M potential file with +coefficients listed in the appropriate units, if your simulation does +not use "metal" units. The pair styles provided here **only** support potential files parameterized for the elements carbon and hydrogen (designated with "C" and "H" in the From bed84841ad970da4fc2caefc03d7377fff4a7f61 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 09:57:42 -0500 Subject: [PATCH 085/185] update comment header to point to the LAMMPS developers email address --- src/MANYBODY/pair_rebomos.cpp | 2 +- src/MANYBODY/pair_rebomos.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp index 1211ad5c7e..3e46f86a20 100644 --- a/src/MANYBODY/pair_rebomos.cpp +++ b/src/MANYBODY/pair_rebomos.cpp @@ -2,7 +2,7 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov + LAMMPS Development team: developers@lammps.org Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains diff --git a/src/MANYBODY/pair_rebomos.h b/src/MANYBODY/pair_rebomos.h index 4a530de329..8df4c6b3c9 100644 --- a/src/MANYBODY/pair_rebomos.h +++ b/src/MANYBODY/pair_rebomos.h @@ -1,7 +1,7 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov + LAMMPS Development team: developers@lammps.org Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains From 36fa601fe08a9727f9dbc53bfe696bf10a53e8f3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 13:33:04 -0500 Subject: [PATCH 086/185] cutoff calculation inherited from but only required for AIREBO. up to 2x speedup --- src/MANYBODY/pair_rebomos.cpp | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp index 3e46f86a20..8ba1437aca 100644 --- a/src/MANYBODY/pair_rebomos.cpp +++ b/src/MANYBODY/pair_rebomos.cpp @@ -259,29 +259,8 @@ double PairREBOMoS::init_one(int i, int j) cut3rebo = 3.0 * rcmax[0][0]; - // cutljrebosq = furthest distance from an owned atom a ghost atom can be - // to need its REBO neighs computed - // interaction = M-K-I-J-L-N with I = owned and J = ghost - // this insures N is in the REBO neigh list of L - // since I-J < rcLJmax and J-L < rmax - - double cutljrebo = rcLJmax[0][0] + rcmax[0][0]; - cutljrebosq = cutljrebo * cutljrebo; - - // cutmax = furthest distance from an owned atom - // at which another atom will feel force, i.e. the ghost cutoff - // for REBO term in potential: - // interaction = M-K-I-J-L-N with I = owned and J = ghost - // I to N is max distance = 3 REBO distances - // for LJ term in potential: - // short interaction = M-K-I-J-L-N with I = owned, J = ghost, I-J < rcLJmax - // rcLJmax + 2*rcmax, since I-J < rcLJmax and J-L,L-N = REBO distances - // long interaction = I-J with I = owned and J = ghost - // cutlj*sigma, since I-J < LJ cutoff // cutghost = REBO cutoff used in REBO_neigh() for neighbors of ghosts - double cutmax = MAX(cut3rebo,rcLJmax[0][0] + 2.0*rcmax[0][0]); - cutghost[i][j] = rcmax[ii][jj]; lj1[ii][jj] = 48.0 * epsilon[ii][jj] * powint(sigma[ii][jj],12); lj2[ii][jj] = 24.0 * epsilon[ii][jj] * powint(sigma[ii][jj],6); @@ -294,7 +273,7 @@ double PairREBOMoS::init_one(int i, int j) lj3[jj][ii] = lj3[ii][jj]; lj4[jj][ii] = lj4[ii][jj]; - return cutmax; + return cut3rebo; } /* ---------------------------------------------------------------------- From 22d0b202c4d2c120e3e7937d226c7e7988f4c1ed Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 13:37:59 -0500 Subject: [PATCH 087/185] update example logs for change in cutoff setting --- .../threebody/log.22Feb24.mos2-bulk.g++.1 | 35 +++++++++--------- .../threebody/log.22Feb24.mos2-bulk.g++.4 | 37 +++++++++---------- .../threebody/log.22Feb24.mos2.rebomos.g++.1 | 37 +++++++++---------- .../threebody/log.22Feb24.mos2.rebomos.g++.4 | 37 +++++++++---------- 4 files changed, 71 insertions(+), 75 deletions(-) diff --git a/examples/threebody/log.22Feb24.mos2-bulk.g++.1 b/examples/threebody/log.22Feb24.mos2-bulk.g++.1 index 7822ad40c5..8218026f3d 100644 --- a/examples/threebody/log.22Feb24.mos2-bulk.g++.1 +++ b/examples/threebody/log.22Feb24.mos2-bulk.g++.1 @@ -1,5 +1,4 @@ -LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) -OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-73-g36fa601fe0) using 1 OpenMP thread(s) per MPI task units metal @@ -40,46 +39,46 @@ run 20 Neighbor list info ... update: every = 1 steps, delay = 0 steps, check = yes max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 20.1 - ghost atom cutoff = 20.1 - binsize = 10.05, bins = 3 3 2 + master list distance cutoff = 13.4 + ghost atom cutoff = 13.4 + binsize = 6.7, bins = 5 4 3 1 neighbor lists, perpetual/occasional/extra = 1 0 0 (1) pair rebomos, perpetual attributes: full, newton on, ghost pair build: full/bin/ghost stencil: full/ghost/bin/3d bin: standard -Per MPI rank memory allocation (min/avg/max) = 6.759 | 6.759 | 6.759 Mbytes +Per MPI rank memory allocation (min/avg/max) = 4.996 | 4.996 | 4.996 Mbytes Step Temp Press PotEng KinEng CellGamma Volume 0 0 28799.53 -2061.6112 0 113.40187 5922.4926 10 80.776057 13540.088 -2064.6132 2.9966028 113.40187 5922.4926 20 146.17503 -20669.371 -2067.0428 5.4227518 113.40187 5922.4926 -Loop time of 0.173901 on 1 procs for 20 steps with 288 atoms +Loop time of 0.058071 on 1 procs for 20 steps with 288 atoms -Performance: 9.937 ns/day, 2.415 hours/ns, 115.008 timesteps/s, 33.122 katom-step/s -99.7% CPU use with 1 MPI tasks x 1 OpenMP threads +Performance: 29.757 ns/day, 0.807 hours/ns, 344.406 timesteps/s, 99.189 katom-step/s +99.8% CPU use with 1 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total --------------------------------------------------------------- -Pair | 0.17213 | 0.17213 | 0.17213 | 0.0 | 98.98 +Pair | 0.057666 | 0.057666 | 0.057666 | 0.0 | 99.30 Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 0.0013913 | 0.0013913 | 0.0013913 | 0.0 | 0.80 -Output | 5.0377e-05 | 5.0377e-05 | 5.0377e-05 | 0.0 | 0.03 -Modify | 6.9212e-05 | 6.9212e-05 | 6.9212e-05 | 0.0 | 0.04 -Other | | 0.000264 | | | 0.15 +Comm | 0.00024654 | 0.00024654 | 0.00024654 | 0.0 | 0.42 +Output | 2.3975e-05 | 2.3975e-05 | 2.3975e-05 | 0.0 | 0.04 +Modify | 3.8394e-05 | 3.8394e-05 | 3.8394e-05 | 0.0 | 0.07 +Other | | 9.596e-05 | | | 0.17 Nlocal: 288 ave 288 max 288 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Nghost: 10002 ave 10002 max 10002 min +Nghost: 4285 ave 4285 max 4285 min Histogram: 1 0 0 0 0 0 0 0 0 0 Neighs: 0 ave 0 max 0 min Histogram: 1 0 0 0 0 0 0 0 0 0 -FullNghs: 477120 ave 477120 max 477120 min +FullNghs: 142848 ave 142848 max 142848 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Total # of neighbors = 477120 -Ave neighs/atom = 1656.6667 +Total # of neighbors = 142848 +Ave neighs/atom = 496 Neighbor list builds = 0 Dangerous builds = 0 diff --git a/examples/threebody/log.22Feb24.mos2-bulk.g++.4 b/examples/threebody/log.22Feb24.mos2-bulk.g++.4 index c215d88294..0b9cd3ed8a 100644 --- a/examples/threebody/log.22Feb24.mos2-bulk.g++.4 +++ b/examples/threebody/log.22Feb24.mos2-bulk.g++.4 @@ -1,5 +1,4 @@ -LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) -OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-73-g36fa601fe0) using 1 OpenMP thread(s) per MPI task units metal @@ -23,7 +22,7 @@ Created triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9 create_atoms 2 box basis 1 1 basis 2 1 basis 3 2 basis 4 2 basis 5 2 basis 6 2 Created 288 atoms using lattice units in triclinic box = (0 0 0) to (19.147099 22.121185 13.982768) with tilt (-9.5735495 0 0) - create_atoms CPU = 0.001 seconds + create_atoms CPU = 0.000 seconds mass 1 95.95 #Mo mass 2 32.065 #S @@ -40,46 +39,46 @@ run 20 Neighbor list info ... update: every = 1 steps, delay = 0 steps, check = yes max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 20.1 - ghost atom cutoff = 20.1 - binsize = 10.05, bins = 3 3 2 + master list distance cutoff = 13.4 + ghost atom cutoff = 13.4 + binsize = 6.7, bins = 5 4 3 1 neighbor lists, perpetual/occasional/extra = 1 0 0 (1) pair rebomos, perpetual attributes: full, newton on, ghost pair build: full/bin/ghost stencil: full/ghost/bin/3d bin: standard -Per MPI rank memory allocation (min/avg/max) = 4.977 | 4.978 | 4.978 Mbytes +Per MPI rank memory allocation (min/avg/max) = 4.15 | 4.151 | 4.151 Mbytes Step Temp Press PotEng KinEng CellGamma Volume 0 0 28799.53 -2061.6112 0 113.40187 5922.4926 10 80.776057 13540.088 -2064.6132 2.9966028 113.40187 5922.4926 20 146.17503 -20669.371 -2067.0428 5.4227518 113.40187 5922.4926 -Loop time of 0.0644788 on 4 procs for 20 steps with 288 atoms +Loop time of 0.0219485 on 4 procs for 20 steps with 288 atoms -Performance: 26.799 ns/day, 0.896 hours/ns, 310.179 timesteps/s, 89.332 katom-step/s -99.2% CPU use with 4 MPI tasks x 1 OpenMP threads +Performance: 78.730 ns/day, 0.305 hours/ns, 911.225 timesteps/s, 262.433 katom-step/s +96.3% CPU use with 4 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total --------------------------------------------------------------- -Pair | 0.057739 | 0.059918 | 0.06231 | 0.7 | 92.93 +Pair | 0.018118 | 0.019372 | 0.020087 | 0.5 | 88.26 Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 0.0018848 | 0.0042821 | 0.0064683 | 2.6 | 6.64 -Output | 3.7548e-05 | 4.1425e-05 | 5.1594e-05 | 0.0 | 0.06 -Modify | 3.4882e-05 | 3.5821e-05 | 3.6589e-05 | 0.0 | 0.06 -Other | | 0.0002014 | | | 0.31 +Comm | 0.0015635 | 0.0023195 | 0.0035967 | 1.6 | 10.57 +Output | 2.5017e-05 | 4.6834e-05 | 0.00010543 | 0.0 | 0.21 +Modify | 1.3954e-05 | 1.423e-05 | 1.4594e-05 | 0.0 | 0.06 +Other | | 0.0001957 | | | 0.89 Nlocal: 72 ave 72 max 72 min Histogram: 4 0 0 0 0 0 0 0 0 0 -Nghost: 7113.5 ave 7114 max 7113 min +Nghost: 2771.5 ave 2775 max 2768 min Histogram: 2 0 0 0 0 0 0 0 0 2 Neighs: 0 ave 0 max 0 min Histogram: 4 0 0 0 0 0 0 0 0 0 -FullNghs: 119280 ave 119280 max 119280 min +FullNghs: 35712 ave 35712 max 35712 min Histogram: 4 0 0 0 0 0 0 0 0 0 -Total # of neighbors = 477120 -Ave neighs/atom = 1656.6667 +Total # of neighbors = 142848 +Ave neighs/atom = 496 Neighbor list builds = 0 Dangerous builds = 0 diff --git a/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 b/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 index e0a313647d..f7c5b3c74d 100644 --- a/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 +++ b/examples/threebody/log.22Feb24.mos2.rebomos.g++.1 @@ -1,5 +1,4 @@ -LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) -OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-73-g36fa601fe0) using 1 OpenMP thread(s) per MPI task # monolayer MoS2 units metal @@ -15,7 +14,7 @@ WARNING: Triclinic box skew is large. LAMMPS will run inefficiently. (src/domain 1 by 1 by 1 MPI processor grid reading atoms ... 768 atoms - read_data CPU = 0.003 seconds + read_data CPU = 0.002 seconds mass * 32.065 # mass of sulphur atom , uint: a.u.=1.66X10^(-27)kg mass 1 95.94 # mass of molebdenum atom , uint: a.u.=1.66X10^(-27)kg @@ -43,16 +42,16 @@ run 5000 Neighbor list info ... update: every = 1 steps, delay = 0 steps, check = yes max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 20.1 - ghost atom cutoff = 20.1 - binsize = 10.05, bins = 8 5 20 + master list distance cutoff = 13.4 + ghost atom cutoff = 13.4 + binsize = 6.7, bins = 12 7 30 1 neighbor lists, perpetual/occasional/extra = 1 0 0 (1) pair rebomos, perpetual attributes: full, newton on, ghost pair build: full/bin/ghost stencil: full/ghost/bin/3d bin: standard -Per MPI rank memory allocation (min/avg/max) = 5.273 | 5.273 | 5.273 Mbytes +Per MPI rank memory allocation (min/avg/max) = 4.473 | 4.473 | 4.473 Mbytes Step TotEng PotEng KinEng Temp 0 -5466.9785 -5496.7212 29.742759 300 500 -5466.964 -5482.6985 15.734505 158.7059 @@ -65,32 +64,32 @@ Per MPI rank memory allocation (min/avg/max) = 5.273 | 5.273 | 5.273 Mbytes 4000 -5466.9628 -5481.848 14.885236 150.13977 4500 -5466.9648 -5483.5045 16.539775 166.82825 5000 -5466.9649 -5483.4932 16.528298 166.71249 -Loop time of 36.2406 on 1 procs for 5000 steps with 768 atoms +Loop time of 19.1009 on 1 procs for 5000 steps with 768 atoms -Performance: 11.920 ns/day, 2.013 hours/ns, 137.967 timesteps/s, 105.959 katom-step/s +Performance: 22.617 ns/day, 1.061 hours/ns, 261.768 timesteps/s, 201.038 katom-step/s 99.9% CPU use with 1 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total --------------------------------------------------------------- -Pair | 36.14 | 36.14 | 36.14 | 0.0 | 99.72 +Pair | 19.042 | 19.042 | 19.042 | 0.0 | 99.69 Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 0.043166 | 0.043166 | 0.043166 | 0.0 | 0.12 -Output | 0.00021785 | 0.00021785 | 0.00021785 | 0.0 | 0.00 -Modify | 0.034547 | 0.034547 | 0.034547 | 0.0 | 0.10 -Other | | 0.02219 | | | 0.06 +Comm | 0.018451 | 0.018451 | 0.018451 | 0.0 | 0.10 +Output | 0.00015575 | 0.00015575 | 0.00015575 | 0.0 | 0.00 +Modify | 0.023931 | 0.023931 | 0.023931 | 0.0 | 0.13 +Other | | 0.01658 | | | 0.09 Nlocal: 768 ave 768 max 768 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Nghost: 2054 ave 2054 max 2054 min +Nghost: 1158 ave 1158 max 1158 min Histogram: 1 0 0 0 0 0 0 0 0 0 Neighs: 0 ave 0 max 0 min Histogram: 1 0 0 0 0 0 0 0 0 0 -FullNghs: 330752 ave 330752 max 330752 min +FullNghs: 141824 ave 141824 max 141824 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Total # of neighbors = 330752 -Ave neighs/atom = 430.66667 +Total # of neighbors = 141824 +Ave neighs/atom = 184.66667 Neighbor list builds = 0 Dangerous builds = 0 -Total wall time: 0:00:36 +Total wall time: 0:00:19 diff --git a/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 b/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 index 7510c5a793..dc1cfa84d4 100644 --- a/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 +++ b/examples/threebody/log.22Feb24.mos2.rebomos.g++.4 @@ -1,5 +1,4 @@ -LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-70-ge51a65696d-modified) -OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-73-g36fa601fe0) using 1 OpenMP thread(s) per MPI task # monolayer MoS2 units metal @@ -43,16 +42,16 @@ run 5000 Neighbor list info ... update: every = 1 steps, delay = 0 steps, check = yes max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 20.1 - ghost atom cutoff = 20.1 - binsize = 10.05, bins = 8 5 20 + master list distance cutoff = 13.4 + ghost atom cutoff = 13.4 + binsize = 6.7, bins = 12 7 30 1 neighbor lists, perpetual/occasional/extra = 1 0 0 (1) pair rebomos, perpetual attributes: full, newton on, ghost pair build: full/bin/ghost stencil: full/ghost/bin/3d bin: standard -Per MPI rank memory allocation (min/avg/max) = 4.464 | 4.464 | 4.464 Mbytes +Per MPI rank memory allocation (min/avg/max) = 4.045 | 4.045 | 4.045 Mbytes Step TotEng PotEng KinEng Temp 0 -5466.9785 -5496.7212 29.742759 300 500 -5466.964 -5482.6985 15.734505 158.7059 @@ -65,32 +64,32 @@ Per MPI rank memory allocation (min/avg/max) = 4.464 | 4.464 | 4.464 Mbytes 4000 -5466.9628 -5481.848 14.885236 150.13977 4500 -5466.9648 -5483.5045 16.539775 166.82825 5000 -5466.9649 -5483.4932 16.528298 166.71249 -Loop time of 10.2878 on 4 procs for 5000 steps with 768 atoms +Loop time of 5.69326 on 4 procs for 5000 steps with 768 atoms -Performance: 41.992 ns/day, 0.572 hours/ns, 486.014 timesteps/s, 373.259 katom-step/s -99.7% CPU use with 4 MPI tasks x 1 OpenMP threads +Performance: 75.879 ns/day, 0.316 hours/ns, 878.231 timesteps/s, 674.482 katom-step/s +98.6% CPU use with 4 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total --------------------------------------------------------------- -Pair | 9.7925 | 9.9286 | 10.096 | 3.6 | 96.51 +Pair | 5.2611 | 5.3666 | 5.4358 | 3.0 | 94.26 Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 0.16754 | 0.33518 | 0.47096 | 19.5 | 3.26 -Output | 0.00016889 | 0.00018727 | 0.00023915 | 0.0 | 0.00 -Modify | 0.010131 | 0.010502 | 0.011106 | 0.4 | 0.10 -Other | | 0.01333 | | | 0.13 +Comm | 0.23476 | 0.30106 | 0.40642 | 12.8 | 5.29 +Output | 0.00014996 | 0.0004478 | 0.0013353 | 0.0 | 0.01 +Modify | 0.0068861 | 0.0069917 | 0.0072247 | 0.2 | 0.12 +Other | | 0.01814 | | | 0.32 Nlocal: 192 ave 194 max 190 min Histogram: 1 0 0 0 0 2 0 0 0 1 -Nghost: 1350 ave 1352 max 1348 min +Nghost: 710 ave 712 max 708 min Histogram: 1 0 0 0 0 2 0 0 0 1 Neighs: 0 ave 0 max 0 min Histogram: 4 0 0 0 0 0 0 0 0 0 -FullNghs: 82688 ave 83548 max 81828 min +FullNghs: 35456 ave 35824 max 35088 min Histogram: 1 0 0 0 0 2 0 0 0 1 -Total # of neighbors = 330752 -Ave neighs/atom = 430.66667 +Total # of neighbors = 141824 +Ave neighs/atom = 184.66667 Neighbor list builds = 0 Dangerous builds = 0 -Total wall time: 0:00:10 +Total wall time: 0:00:05 From 3e512834c739f7edf9f2e8384b923ad8140876e7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 14:09:50 -0500 Subject: [PATCH 088/185] cosmetic --- src/MANYBODY/pair_rebomos.cpp | 7 ++----- src/MANYBODY/pair_rebomos.h | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp index 8ba1437aca..b40ff287cf 100644 --- a/src/MANYBODY/pair_rebomos.cpp +++ b/src/MANYBODY/pair_rebomos.cpp @@ -33,7 +33,6 @@ #include "comm.h" #include "error.h" #include "force.h" -#include "math_const.h" #include "math_special.h" #include "memory.h" #include "my_page.h" @@ -46,14 +45,12 @@ #include using namespace LAMMPS_NS; -using namespace MathConst; using MathSpecial::cube; using MathSpecial::powint; using MathSpecial::square; -#define MAXLINE 1024 -#define TOL 1.0e-9 -#define PGDELTA 1 +static constexpr double TOL = 1.0e-9; +static constexpr int PGDELTA = 1; /* ---------------------------------------------------------------------- */ diff --git a/src/MANYBODY/pair_rebomos.h b/src/MANYBODY/pair_rebomos.h index 8df4c6b3c9..4997c65b87 100644 --- a/src/MANYBODY/pair_rebomos.h +++ b/src/MANYBODY/pair_rebomos.h @@ -20,8 +20,9 @@ PairStyle(rebomos,PairREBOMoS); #ifndef LMP_PAIR_REBOMOS_H #define LMP_PAIR_REBOMOS_H -#include "math_const.h" #include "pair.h" +#include "math_const.h" + #include namespace LAMMPS_NS { From 49886caaf14f79918654f93e303c988a05066240 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 15:17:46 -0500 Subject: [PATCH 089/185] add OPENMP package version of pair style rebomos --- doc/src/Commands_pair.rst | 2 +- doc/src/pair_rebomos.rst | 21 +- doc/utils/sphinx-config/false_positives.txt | 2 + src/MANYBODY/pair_rebomos.cpp | 16 +- src/OPENMP/pair_rebomos_omp.cpp | 702 ++++++++++++++++++++ src/OPENMP/pair_rebomos_omp.h | 46 ++ 6 files changed, 775 insertions(+), 14 deletions(-) create mode 100644 src/OPENMP/pair_rebomos_omp.cpp create mode 100644 src/OPENMP/pair_rebomos_omp.h diff --git a/doc/src/Commands_pair.rst b/doc/src/Commands_pair.rst index 95dd7429e8..9bbe216dec 100644 --- a/doc/src/Commands_pair.rst +++ b/doc/src/Commands_pair.rst @@ -256,7 +256,7 @@ OPT. * :doc:`rann ` * :doc:`reaxff (ko) ` * :doc:`rebo (io) ` - * :doc:`rebomos ` + * :doc:`rebomos (o) ` * :doc:`resquared (go) ` * :doc:`saip/metal (t) ` * :doc:`sdpd/taitwater/isothermal ` diff --git a/doc/src/pair_rebomos.rst b/doc/src/pair_rebomos.rst index 56bf6488bb..9be400e363 100644 --- a/doc/src/pair_rebomos.rst +++ b/doc/src/pair_rebomos.rst @@ -1,7 +1,10 @@ .. index:: pair_style rebomos +.. index:: pair_style rebomos/omp pair_style rebomos command -========================= +========================== + +Accelerator Variants: *rebomos/omp* Syntax """""" @@ -24,7 +27,9 @@ Examples Description """"""""""" -The *rebomos* pair style computes +.. versionadded:: TBD + +The *rebomos* pair style computes ---------- @@ -60,6 +65,10 @@ potentials. ---------- +.. include:: accel_styles.rst + +---------- + Mixing, shift, table, tail correction, restart, rRESPA info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -107,3 +116,11 @@ Default none ---------- + +.. _Stewart: + +**(Steward)** Stewart, Spearot, Modelling Simul. Mater. Sci. Eng. 21,(2013) + +.. _Liang: + +**(Liang)** Liang, Phillpot, Sinnott Phys. Rev. B79 245110, (2009), Erratum: Phys. Rev. B85 199903(E), (2012) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 4f5fe6fdaf..3423b7859b 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -2266,6 +2266,7 @@ morris Morriss morse Morteza +MoS Mosayebi Moseler Moskalev @@ -3070,6 +3071,7 @@ reaxff ReaxFF REAXFF rebo +rebomos recurse recursing Ree diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp index b40ff287cf..d6cea004a7 100644 --- a/src/MANYBODY/pair_rebomos.cpp +++ b/src/MANYBODY/pair_rebomos.cpp @@ -372,7 +372,6 @@ void PairREBOMoS::FREBO(int eflag) int *type = atom->type; tagint *tag = atom->tag; int nlocal = atom->nlocal; - int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; @@ -442,7 +441,7 @@ void PairREBOMoS::FREBO(int eflag) f[j][2] -= delz*fpair; if (eflag) evdwl = VR + bij*VA; - if (evflag) ev_tally(i,j,nlocal,newton_pair,evdwl,0.0,fpair,delx,dely,delz); + if (evflag) ev_tally(i,j,nlocal,/*newton_pair*/1,evdwl,0.0,fpair,delx,dely,delz); } } } @@ -473,7 +472,6 @@ void PairREBOMoS::FLJ(int eflag) tagint *tag = atom->tag; int *type = atom->type; int nlocal = atom->nlocal; - int newton_pair = force->newton_pair; inum = list->inum; ilist = list->ilist; @@ -553,8 +551,7 @@ void PairREBOMoS::FLJ(int eflag) f[j][2] -= delij[2]*fpair; if (eflag) evdwl = VLJ; - if (evflag) ev_tally(i,j,nlocal,newton_pair, - evdwl,0.0,fpair,delij[0],delij[1],delij[2]); + if (evflag) ev_tally(i,j,nlocal,/*newton_pair*/1,evdwl,0.0,fpair,delij[0],delij[1],delij[2]); } } @@ -771,12 +768,9 @@ double PairREBOMoS::bondorder(int i, int j, double rij[3], double rijmag, double cosijl = MIN(cosijl,1.0); cosijl = MAX(cosijl,-1.0); - dcosijldri[0] = (-rjl[0]/(rijmag*rjlmag)) - - (cosijl*rij[0]/(rijmag*rijmag)); - dcosijldri[1] = (-rjl[1]/(rijmag*rjlmag)) - - (cosijl*rij[1]/(rijmag*rijmag)); - dcosijldri[2] = (-rjl[2]/(rijmag*rjlmag)) - - (cosijl*rij[2]/(rijmag*rijmag)); + dcosijldri[0] = (-rjl[0]/(rijmag*rjlmag)) - (cosijl*rij[0]/(rijmag*rijmag)); + dcosijldri[1] = (-rjl[1]/(rijmag*rjlmag)) - (cosijl*rij[1]/(rijmag*rijmag)); + dcosijldri[2] = (-rjl[2]/(rijmag*rjlmag)) - (cosijl*rij[2]/(rijmag*rijmag)); dcosijldrj[0] = ((-rij[0]+rjl[0])/(rijmag*rjlmag)) + (cosijl*((rij[0]/square(rijmag))-(rjl[0]/(rjlmag*rjlmag)))); dcosijldrj[1] = ((-rij[1]+rjl[1])/(rijmag*rjlmag)) + diff --git a/src/OPENMP/pair_rebomos_omp.cpp b/src/OPENMP/pair_rebomos_omp.cpp new file mode 100644 index 0000000000..5143fd0f63 --- /dev/null +++ b/src/OPENMP/pair_rebomos_omp.cpp @@ -0,0 +1,702 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS Development team: developers@lammps.org + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + References: + + This code: + Stewart J A and Spearot D E (2013) Atomistic simulations of nanoindentation on the basal plane of crystalline molybdenum disulfide. Modelling Simul. Mater. Sci. Eng. 21. + + Based on: + Liang T, Phillpot S R and Sinnott S B (2009) Parameterization of a reactive many-body potential for Mo2S systems. Phys. Rev. B79 245110. + Liang T, Phillpot S R and Sinnott S B (2012) Erratum: Parameterization of a reactive many-body potential for Mo-S systems. (Phys. Rev. B79 245110 (2009)) Phys. Rev. B85 199903(E). + + LAMMPS file contributing authors: James Stewart, Khanh Dang and Douglas Spearot (University of Arkansas) +------------------------------------------------------------------------- */ + +// clang-format on + +#include "pair_rebomos_omp.h" + +#include "atom.h" +#include "comm.h" +#include "error.h" +#include "math_special.h" +#include "memory.h" +#include "my_page.h" +#include "neigh_list.h" + +#include "suffix.h" + +#include + +#include "omp_compat.h" +#if defined(_OPENMP) +#include +#endif + +using namespace LAMMPS_NS; +using namespace MathConst; +using MathSpecial::cube; +using MathSpecial::powint; +using MathSpecial::square; + +static constexpr double TOL = 1.0e-9; + +/* ---------------------------------------------------------------------- */ + +PairREBOMoSOMP::PairREBOMoSOMP(LAMMPS *lmp) : PairREBOMoS(lmp), ThrOMP(lmp, THR_PAIR) +{ + suffix_flag |= Suffix::OMP; + respa_enable = 0; +} + +// clang-format off + +/* ---------------------------------------------------------------------- */ + +void PairREBOMoSOMP::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); + + REBO_neigh_thr(); + + const int nall = atom->nlocal + atom->nghost; + const int nthreads = comm->nthreads; + const int inum = list->inum; + +#if defined(_OPENMP) +#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(eflag,vflag) +#endif + { + int ifrom, ito, tid; + + loop_setup_thr(ifrom, ito, tid, inum, nthreads); + ThrData *thr = fix->get_thr(tid); + thr->timer(Timer::START); + ev_setup_thr(eflag, vflag, nall, eatom, vatom, nullptr, thr); + + FREBO_thr(ifrom,ito,eflag,thr); + FLJ_thr(ifrom,ito,eflag,thr); + + thr->timer(Timer::PAIR); + reduce_thr(this, eflag, vflag, thr); + } // end of omp parallel region +} + +/* ---------------------------------------------------------------------- + create REBO neighbor list from main neighbor list + REBO neighbor list stores neighbors of ghost atoms +------------------------------------------------------------------------- */ + +void PairREBOMoSOMP::REBO_neigh_thr() +{ + const int nthreads = comm->nthreads; + + if (atom->nmax > maxlocal) { + maxlocal = atom->nmax; + memory->destroy(REBO_numneigh); + memory->sfree(REBO_firstneigh); + memory->destroy(nM); + memory->destroy(nS); + memory->create(REBO_numneigh,maxlocal,"REBOMoS:numneigh"); + REBO_firstneigh = (int **) memory->smalloc(maxlocal*sizeof(int *), + "REBOMoS:firstneigh"); + memory->create(nM,maxlocal,"REBOMoS:nM"); + memory->create(nS,maxlocal,"REBOMoS:nS"); + } + +#if defined(_OPENMP) +#pragma omp parallel LMP_DEFAULT_NONE +#endif + { + int i,j,ii,jj,n,jnum,itype,jtype; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq,dS; + int *ilist,*jlist,*numneigh,**firstneigh; + int *neighptr; + + double **x = atom->x; + int *type = atom->type; + + const int allnum = list->inum + list->gnum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + +#if defined(_OPENMP) + const int tid = omp_get_thread_num(); +#else + const int tid = 0; +#endif + + const int iidelta = 1 + allnum/nthreads; + const int iifrom = tid*iidelta; + const int iito = ((iifrom+iidelta)>allnum) ? allnum : (iifrom+iidelta); + + // store all REBO neighs of owned and ghost atoms + // scan full neighbor list of I + + // each thread has its own page allocator + MyPage &ipg = ipage[tid]; + ipg.reset(); + + for (ii = iifrom; ii < iito; ii++) { + i = ilist[ii]; + + n = 0; + neighptr = ipg.vget(); + + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + itype = map[type[i]]; + nM[i] = nS[i] = 0.0; + jlist = firstneigh[i]; + jnum = numneigh[i]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + jtype = map[type[j]]; + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + + if (rsq < rcmaxsq[itype][jtype]) { + neighptr[n++] = j; + if (jtype == 0) + nM[i] += Sp(sqrt(rsq),rcmin[itype][jtype],rcmax[itype][jtype],dS); + else + nS[i] += Sp(sqrt(rsq),rcmin[itype][jtype],rcmax[itype][jtype],dS); + } + } + + REBO_firstneigh[i] = neighptr; + REBO_numneigh[i] = n; + ipg.vgot(n); + if (ipg.status()) + error->one(FLERR,"REBO list overflow, boost neigh_modify one"); + } + } +} + +/* ---------------------------------------------------------------------- + REBO forces and energy +------------------------------------------------------------------------- */ + +void PairREBOMoSOMP::FREBO_thr(int ifrom, int ito, int eflag, ThrData * const thr) +{ + int i,j,k,ii,itype,jtype; + tagint itag, jtag; + double delx,dely,delz,evdwl,fpair,xtmp,ytmp,ztmp; + double rsq,rij,wij; + double Qij,Aij,alphaij,VR,pre,dVRdi,VA,bij,dVAdi,dVA; + double dwij,del[3]; + int *ilist,*REBO_neighs; + + evdwl = 0.0; + + const double * const * const x = atom->x; + double * const * const f = thr->get_f(); + const int * const type = atom->type; + const tagint * const tag = atom->tag; + const int nlocal = atom->nlocal; + + ilist = list->ilist; + + // two-body interactions from REBO neighbor list, skip half of them + + for (ii = ifrom; ii < ito; ii++) { + i = ilist[ii]; + itag = tag[i]; + itype = map[type[i]]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + REBO_neighs = REBO_firstneigh[i]; + + for (k = 0; k < REBO_numneigh[i]; k++) { + j = REBO_neighs[k]; + jtag = tag[j]; + + if (itag > jtag) { + if ((itag+jtag) % 2 == 0) continue; + } else if (itag < jtag) { + if ((itag+jtag) % 2 == 1) continue; + } else { + if (x[j][2] < ztmp) continue; + if (x[j][2] == ztmp && x[j][1] < ytmp) continue; + if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue; + } + + jtype = map[type[j]]; + + delx = x[i][0] - x[j][0]; + dely = x[i][1] - x[j][1]; + delz = x[i][2] - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + rij = sqrt(rsq); + wij = Sp(rij,rcmin[itype][jtype],rcmax[itype][jtype],dwij); + if (wij <= TOL) continue; + + Qij = Q[itype][jtype]; + Aij = A[itype][jtype]; + alphaij = alpha[itype][jtype]; + + VR = wij*(1.0+(Qij/rij)) * Aij*exp(-alphaij*rij); + pre = wij*Aij * exp(-alphaij*rij); + dVRdi = pre * ((-alphaij)-(Qij/rsq)-(Qij*alphaij/rij)); + dVRdi += VR/wij * dwij; + + VA = dVA = 0.0; + VA = -wij * BIJc[itype][jtype] * exp(-Beta[itype][jtype]*rij); + + dVA = -Beta[itype][jtype] * VA; + dVA += VA/wij * dwij; + + del[0] = delx; + del[1] = dely; + del[2] = delz; + bij = bondorder_thr(i,j,del,rij,VA,thr); + dVAdi = bij*dVA; + + fpair = -(dVRdi+dVAdi) / rij; + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; + + if (eflag) evdwl = VR + bij*VA; + if (evflag) ev_tally_thr(this,i,j,nlocal,/* newton_pair */1,evdwl,0.0,fpair,delx,dely,delz,thr); + } + } +} + +/* ---------------------------------------------------------------------- + compute LJ forces and energy +------------------------------------------------------------------------- */ + +void PairREBOMoSOMP::FLJ_thr(int ifrom, int ito, int eflag, ThrData * const thr) +{ + int i,j,ii,jj,jnum,itype,jtype; + tagint itag,jtag; + double evdwl,fpair,xtmp,ytmp,ztmp; + double rij,delij[3],rijsq; + double VLJ,dVLJ; + double vdw,dvdw; + double r2inv,r6inv; + int *ilist,*jlist,*numneigh,**firstneigh; + double c2,c3,dr,drp,r6; + + // I-J interaction from full neighbor list + // skip 1/2 of interactions since only consider each pair once + + evdwl = 0.0; + + const double * const * const x = atom->x; + double * const * const f = thr->get_f(); + const tagint * const tag = atom->tag; + const int * const type = atom->type; + const int nlocal = atom->nlocal; + + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // loop over neighbors of my atoms + + for (ii = ifrom; ii < ito; ii++) { + i = ilist[ii]; + itag = tag[i]; + itype = map[type[i]]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + jtag = tag[j]; + + if (itag > jtag) { + if ((itag+jtag) % 2 == 0) continue; + } else if (itag < jtag) { + if ((itag+jtag) % 2 == 1) continue; + } else { + if (x[j][2] < ztmp) continue; + if (x[j][2] == ztmp && x[j][1] < ytmp) continue; + if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue; + } + jtype = map[type[j]]; + + delij[0] = xtmp - x[j][0]; + delij[1] = ytmp - x[j][1]; + delij[2] = ztmp - x[j][2]; + rijsq = delij[0]*delij[0] + delij[1]*delij[1] + delij[2]*delij[2]; + rij = sqrt(rijsq); + + // compute LJ forces and energy + + // Outside Rmax + if (rij > rcLJmax[itype][jtype] || rij < rcLJmin[itype][jtype]){ + VLJ = 0; + dVLJ = 0; + } + + // Inside Rmax and above 0.95*sigma + else if (rij <= rcLJmax[itype][jtype] && rij >= 0.95*sigma[itype][jtype]){ + r2inv = 1.0/rijsq; + r6inv = r2inv*r2inv*r2inv; + VLJ = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]); + dVLJ = -r6inv*(lj1[itype][jtype]*r6inv - lj2[itype][jtype])/rij; + } + + // Below 0.95*sigma + else if (rij < 0.95*sigma[itype][jtype] && rij >= rcLJmin[itype][jtype]){ + dr = 0.95*sigma[itype][jtype] - rcLJmin[itype][jtype]; + r6 = powint((sigma[itype][jtype]/(0.95*sigma[itype][jtype])),6); + vdw = 4*epsilon[itype][jtype]*r6*(r6 - 1.0); + dvdw = (-4*epsilon[itype][jtype]/(0.95*sigma[itype][jtype]))*r6*(12.0*r6 - 6.0); + c2 = ((3.0/dr)*vdw - dvdw)/dr; + c3 = (vdw/(dr*dr) - c2)/dr; + + drp = rij - rcLJmin[itype][jtype]; + VLJ = drp*drp*(drp*c3 + c2); + dVLJ = drp*(3.0*drp*c3 + 2.0*c2); + } + + fpair = -dVLJ/rij; + f[i][0] += delij[0]*fpair; + f[i][1] += delij[1]*fpair; + f[i][2] += delij[2]*fpair; + f[j][0] -= delij[0]*fpair; + f[j][1] -= delij[1]*fpair; + f[j][2] -= delij[2]*fpair; + + if (eflag) evdwl = VLJ; + if (evflag) ev_tally_thr(this,i,j,nlocal,/*newton_pair*/1,evdwl,0.0,fpair,delij[0],delij[1],delij[2],thr); + + } + } +} + +/* ---------------------------------------------------------------------- + Bij function + + The bond order term modified the attractive portion of the REBO + potential based on the number of atoms around a specific pair + and the bond angle between sets of three atoms. + + The functions G(cos(theta)) and P(N) are evaluated and their + derivatives are also computed for use in the force calculation. +------------------------------------------------------------------------- */ + +double PairREBOMoSOMP::bondorder_thr(int i, int j, double rij[3], double rijmag, double VA, ThrData *thr) +{ + int atomi,atomj,atomk,atoml; + int k,l; + int itype, jtype, ktype, ltype; + double rik[3], rjl[3], rji[3], rki[3],rlj[3], dwjl, bij; + double NijM,NijS,NjiM,NjiS,wik,dwik,wjl; + double rikmag,rjlmag,cosjik,cosijl,g,tmp2; + double Etmp,pij,tmp,dwij,dS; + double dgdc,pji; + double dcosjikdri[3],dcosijldri[3],dcosjikdrk[3]; + double dp; + double dcosjikdrj[3],dcosijldrj[3],dcosijldrl[3]; + double fi[3],fj[3],fk[3],fl[3]; + double PijS, PjiS; + int *REBO_neighs; + + const double * const * const x = atom->x; + double * const * const f = thr->get_f(); + const int * const type = atom->type; + + atomi = i; + atomj = j; + itype = map[type[i]]; + jtype = map[type[j]]; + Sp(rijmag,rcmin[itype][jtype],rcmax[itype][jtype],dwij); + NijM = nM[i]; + NijS = nS[i]; + NjiM = nM[j]; + NjiS = nS[j]; + bij = 0.0; + tmp = 0.0; + tmp2 = 0.0; + dgdc = 0.0; + Etmp = 0.0; + + REBO_neighs = REBO_firstneigh[i]; + for (k = 0; k < REBO_numneigh[i]; k++) { + atomk = REBO_neighs[k]; + if (atomk != atomj) { + ktype = map[type[atomk]]; + rik[0] = x[atomi][0]-x[atomk][0]; + rik[1] = x[atomi][1]-x[atomk][1]; + rik[2] = x[atomi][2]-x[atomk][2]; + rikmag = sqrt((rik[0]*rik[0])+(rik[1]*rik[1])+(rik[2]*rik[2])); + wik = Sp(rikmag,rcmin[itype][ktype],rcmax[itype][ktype],dS); + cosjik = ((rij[0]*rik[0])+(rij[1]*rik[1])+(rij[2]*rik[2])) / (rijmag*rikmag); + cosjik = MIN(cosjik,1.0); + cosjik = MAX(cosjik,-1.0); + + // evaluate g and derivative dg + + g = gSpline(cosjik,itype,dgdc); + Etmp = Etmp+(wik*g); + } + } + + dp = 0.0; + PijS = PijSpline(NijM,NijS,itype,dp); + pij = 1.0/sqrt(1.0+Etmp+PijS); + tmp = -0.5*cube(pij); + + // derivative calculations + + REBO_neighs = REBO_firstneigh[i]; + for (k = 0; k < REBO_numneigh[i]; k++) { + atomk = REBO_neighs[k]; + if (atomk != atomj) { + ktype = map[type[atomk]]; + rik[0] = x[atomi][0]-x[atomk][0]; + rik[1] = x[atomi][1]-x[atomk][1]; + rik[2] = x[atomi][2]-x[atomk][2]; + rikmag = sqrt((rik[0]*rik[0])+(rik[1]*rik[1])+(rik[2]*rik[2])); + wik = Sp(rikmag,rcmin[itype][ktype],rcmax[itype][ktype],dwik); + cosjik = (rij[0]*rik[0] + rij[1]*rik[1] + rij[2]*rik[2]) / (rijmag*rikmag); + cosjik = MIN(cosjik,1.0); + cosjik = MAX(cosjik,-1.0); + + dcosjikdri[0] = ((rij[0]+rik[0])/(rijmag*rikmag)) - + (cosjik*((rij[0]/(rijmag*rijmag))+(rik[0]/(rikmag*rikmag)))); + dcosjikdri[1] = ((rij[1]+rik[1])/(rijmag*rikmag)) - + (cosjik*((rij[1]/(rijmag*rijmag))+(rik[1]/(rikmag*rikmag)))); + dcosjikdri[2] = ((rij[2]+rik[2])/(rijmag*rikmag)) - + (cosjik*((rij[2]/(rijmag*rijmag))+(rik[2]/(rikmag*rikmag)))); + dcosjikdrk[0] = (-rij[0]/(rijmag*rikmag)) + + (cosjik*(rik[0]/(rikmag*rikmag))); + dcosjikdrk[1] = (-rij[1]/(rijmag*rikmag)) + + (cosjik*(rik[1]/(rikmag*rikmag))); + dcosjikdrk[2] = (-rij[2]/(rijmag*rikmag)) + + (cosjik*(rik[2]/(rikmag*rikmag))); + dcosjikdrj[0] = (-rik[0]/(rijmag*rikmag)) + + (cosjik*(rij[0]/(rijmag*rijmag))); + dcosjikdrj[1] = (-rik[1]/(rijmag*rikmag)) + + (cosjik*(rij[1]/(rijmag*rijmag))); + dcosjikdrj[2] = (-rik[2]/(rijmag*rikmag)) + + (cosjik*(rij[2]/(rijmag*rijmag))); + + g = gSpline(cosjik,itype,dgdc); + tmp2 = VA*0.5*(tmp*wik*dgdc); + fj[0] = -tmp2*dcosjikdrj[0]; + fj[1] = -tmp2*dcosjikdrj[1]; + fj[2] = -tmp2*dcosjikdrj[2]; + fi[0] = -tmp2*dcosjikdri[0]; + fi[1] = -tmp2*dcosjikdri[1]; + fi[2] = -tmp2*dcosjikdri[2]; + fk[0] = -tmp2*dcosjikdrk[0]; + fk[1] = -tmp2*dcosjikdrk[1]; + fk[2] = -tmp2*dcosjikdrk[2]; + + // coordination forces + + // dwik forces (from partial derivative) + + tmp2 = VA*0.5*(tmp*dwik*g)/rikmag; + fi[0] -= tmp2*rik[0]; + fi[1] -= tmp2*rik[1]; + fi[2] -= tmp2*rik[2]; + fk[0] += tmp2*rik[0]; + fk[1] += tmp2*rik[1]; + fk[2] += tmp2*rik[2]; + + // PIJ forces (from coordination P(N) term) + + tmp2 = VA*0.5*(tmp*dp*dwik)/rikmag; + fi[0] -= tmp2*rik[0]; + fi[1] -= tmp2*rik[1]; + fi[2] -= tmp2*rik[2]; + fk[0] += tmp2*rik[0]; + fk[1] += tmp2*rik[1]; + fk[2] += tmp2*rik[2]; + + // dgdN forces are removed + + f[atomi][0] += fi[0]; f[atomi][1] += fi[1]; f[atomi][2] += fi[2]; + f[atomj][0] += fj[0]; f[atomj][1] += fj[1]; f[atomj][2] += fj[2]; + f[atomk][0] += fk[0]; f[atomk][1] += fk[1]; f[atomk][2] += fk[2]; + + if (vflag_either) { + rji[0] = -rij[0]; rji[1] = -rij[1]; rji[2] = -rij[2]; + rki[0] = -rik[0]; rki[1] = -rik[1]; rki[2] = -rik[2]; + v_tally3_thr(this,atomi,atomj,atomk,fj,fk,rji,rki,thr); + } + } + } + + // PIJ force contribution additional term + tmp2 = -VA*0.5*(tmp*dp*dwij)/rijmag; + + f[atomi][0] += rij[0]*tmp2; + f[atomi][1] += rij[1]*tmp2; + f[atomi][2] += rij[2]*tmp2; + f[atomj][0] -= rij[0]*tmp2; + f[atomj][1] -= rij[1]*tmp2; + f[atomj][2] -= rij[2]*tmp2; + + if (vflag_either) v_tally2_thr(this,atomi,atomj,tmp2,rij,thr); + + tmp = 0.0; + tmp2 = 0.0; + Etmp = 0.0; + + REBO_neighs = REBO_firstneigh[j]; + for (l = 0; l < REBO_numneigh[j]; l++) { + atoml = REBO_neighs[l]; + if (atoml != atomi) { + ltype = map[type[atoml]]; + rjl[0] = x[atomj][0]-x[atoml][0]; + rjl[1] = x[atomj][1]-x[atoml][1]; + rjl[2] = x[atomj][2]-x[atoml][2]; + rjlmag = sqrt((rjl[0]*rjl[0])+(rjl[1]*rjl[1])+(rjl[2]*rjl[2])); + wjl = Sp(rjlmag,rcmin[jtype][ltype],rcmax[jtype][ltype],dS); + cosijl = -1.0*((rij[0]*rjl[0])+(rij[1]*rjl[1])+(rij[2]*rjl[2])) / (rijmag*rjlmag); + cosijl = MIN(cosijl,1.0); + cosijl = MAX(cosijl,-1.0); + + // evaluate g and derivative dg + + g = gSpline(cosijl,jtype,dgdc); + Etmp = Etmp+(wjl*g); + } + } + + dp = 0.0; + PjiS = PijSpline(NjiM,NjiS,jtype,dp); + pji = 1.0/sqrt(1.0+Etmp+PjiS); + tmp = -0.5*cube(pji); + + REBO_neighs = REBO_firstneigh[j]; + for (l = 0; l < REBO_numneigh[j]; l++) { + atoml = REBO_neighs[l]; + if (atoml != atomi) { + ltype = map[type[atoml]]; + rjl[0] = x[atomj][0]-x[atoml][0]; + rjl[1] = x[atomj][1]-x[atoml][1]; + rjl[2] = x[atomj][2]-x[atoml][2]; + rjlmag = sqrt((rjl[0]*rjl[0])+(rjl[1]*rjl[1])+(rjl[2]*rjl[2])); + wjl = Sp(rjlmag,rcmin[jtype][ltype],rcmax[jtype][ltype],dwjl); + cosijl = (-1.0*((rij[0]*rjl[0])+(rij[1]*rjl[1])+(rij[2]*rjl[2]))) / (rijmag*rjlmag); + cosijl = MIN(cosijl,1.0); + cosijl = MAX(cosijl,-1.0); + + dcosijldri[0] = (-rjl[0]/(rijmag*rjlmag)) - + (cosijl*rij[0]/(rijmag*rijmag)); + dcosijldri[1] = (-rjl[1]/(rijmag*rjlmag)) - + (cosijl*rij[1]/(rijmag*rijmag)); + dcosijldri[2] = (-rjl[2]/(rijmag*rjlmag)) - + (cosijl*rij[2]/(rijmag*rijmag)); + dcosijldrj[0] = ((-rij[0]+rjl[0])/(rijmag*rjlmag)) + + (cosijl*((rij[0]/square(rijmag))-(rjl[0]/(rjlmag*rjlmag)))); + dcosijldrj[1] = ((-rij[1]+rjl[1])/(rijmag*rjlmag)) + + (cosijl*((rij[1]/square(rijmag))-(rjl[1]/(rjlmag*rjlmag)))); + dcosijldrj[2] = ((-rij[2]+rjl[2])/(rijmag*rjlmag)) + + (cosijl*((rij[2]/square(rijmag))-(rjl[2]/(rjlmag*rjlmag)))); + dcosijldrl[0] = (rij[0]/(rijmag*rjlmag))+(cosijl*rjl[0]/(rjlmag*rjlmag)); + dcosijldrl[1] = (rij[1]/(rijmag*rjlmag))+(cosijl*rjl[1]/(rjlmag*rjlmag)); + dcosijldrl[2] = (rij[2]/(rijmag*rjlmag))+(cosijl*rjl[2]/(rjlmag*rjlmag)); + + // evaluate g and derivatives dg + + g = gSpline(cosijl,jtype,dgdc); + tmp2 = VA*0.5*(tmp*wjl*dgdc); + fi[0] = -tmp2*dcosijldri[0]; + fi[1] = -tmp2*dcosijldri[1]; + fi[2] = -tmp2*dcosijldri[2]; + fj[0] = -tmp2*dcosijldrj[0]; + fj[1] = -tmp2*dcosijldrj[1]; + fj[2] = -tmp2*dcosijldrj[2]; + fl[0] = -tmp2*dcosijldrl[0]; + fl[1] = -tmp2*dcosijldrl[1]; + fl[2] = -tmp2*dcosijldrl[2]; + + // coordination forces + + // dwik forces (from partial derivative) + + tmp2 = VA*0.5*(tmp*dwjl*g)/rjlmag; + fj[0] -= tmp2*rjl[0]; + fj[1] -= tmp2*rjl[1]; + fj[2] -= tmp2*rjl[2]; + fl[0] += tmp2*rjl[0]; + fl[1] += tmp2*rjl[1]; + fl[2] += tmp2*rjl[2]; + + // PIJ forces (coordination) + + tmp2 = VA*0.5*(tmp*dp*dwjl)/rjlmag; + fj[0] -= tmp2*rjl[0]; + fj[1] -= tmp2*rjl[1]; + fj[2] -= tmp2*rjl[2]; + fl[0] += tmp2*rjl[0]; + fl[1] += tmp2*rjl[1]; + fl[2] += tmp2*rjl[2]; + + // dgdN forces are removed + + f[atomi][0] += fi[0]; f[atomi][1] += fi[1]; f[atomi][2] += fi[2]; + f[atomj][0] += fj[0]; f[atomj][1] += fj[1]; f[atomj][2] += fj[2]; + f[atoml][0] += fl[0]; f[atoml][1] += fl[1]; f[atoml][2] += fl[2]; + + if (vflag_either) { + rlj[0] = -rjl[0]; rlj[1] = -rjl[1]; rlj[2] = -rjl[2]; + v_tally3_thr(this,atomi,atomj,atoml,fi,fl,rij,rlj,thr); + } + } + } + + // PIJ force contribution additional term + + tmp2 = -VA*0.5*(tmp*dp*dwij)/rijmag; + f[atomi][0] += rij[0]*tmp2; + f[atomi][1] += rij[1]*tmp2; + f[atomi][2] += rij[2]*tmp2; + f[atomj][0] -= rij[0]*tmp2; + f[atomj][1] -= rij[1]*tmp2; + f[atomj][2] -= rij[2]*tmp2; + + if (vflag_either) v_tally2_thr(this,atomi,atomj,tmp2,rij,thr); + + bij = (0.5*(pij+pji)); + return bij; +} + +/* ---------------------------------------------------------------------- + memory usage of local atom-based arrays +------------------------------------------------------------------------- */ + +double PairREBOMoSOMP::memory_usage() +{ + double bytes = memory_usage_thr(); + bytes += PairREBOMoS::memory_usage(); + + return bytes; +} diff --git a/src/OPENMP/pair_rebomos_omp.h b/src/OPENMP/pair_rebomos_omp.h new file mode 100644 index 0000000000..ea87f51950 --- /dev/null +++ b/src/OPENMP/pair_rebomos_omp.h @@ -0,0 +1,46 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS Development team: developers@lammps.org + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS +// clang-format off +PairStyle(rebomos/omp,PairREBOMoSOMP); +// clang-format on +#else + +#ifndef LMP_PAIR_REBOMOS_OMP_H +#define LMP_PAIR_REBOMOS_OMP_H + +#include "pair_rebomos.h" +#include "thr_omp.h" + +namespace LAMMPS_NS { + +class PairREBOMoSOMP : public PairREBOMoS, public ThrOMP { + public: + PairREBOMoSOMP(class LAMMPS *); + + void compute(int, int) override; + double memory_usage() override; + + protected: + void FREBO_thr(int ifrom, int ito, int eflag, ThrData *const thr); + void FLJ_thr(int ifrom, int ito, int eflag, ThrData *const thr); + + void REBO_neigh_thr(); + + double bondorder_thr(int, int, double *, double, double, ThrData *const thr); +}; +} // namespace LAMMPS_NS + +#endif +#endif From b016eaa1cf3178a79b37b6c81bda1fa3d420d087 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 22 Feb 2024 15:20:51 -0500 Subject: [PATCH 090/185] cosmetic --- src/OPENMP/pair_airebo_omp.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/OPENMP/pair_airebo_omp.cpp b/src/OPENMP/pair_airebo_omp.cpp index 9f992aefda..6736b10f8f 100644 --- a/src/OPENMP/pair_airebo_omp.cpp +++ b/src/OPENMP/pair_airebo_omp.cpp @@ -38,8 +38,7 @@ static constexpr double TOL = 1.0e-9; /* ---------------------------------------------------------------------- */ -PairAIREBOOMP::PairAIREBOOMP(LAMMPS *lmp) : - PairAIREBO(lmp), ThrOMP(lmp, THR_PAIR) +PairAIREBOOMP::PairAIREBOOMP(LAMMPS *lmp) : PairAIREBO(lmp), ThrOMP(lmp, THR_PAIR) { suffix_flag |= Suffix::OMP; respa_enable = 0; @@ -1121,12 +1120,9 @@ double PairAIREBOOMP::bondorder_thr(int i, int j, double rij[3], double rijmag, cosjik = MIN(cosjik,1.0); cosjik = MAX(cosjik,-1.0); - dcosjikdri[0] = ((rij[0]+rik[0])*invrijkm) - - (cosjik*((rij[0]*invrijm2)+(rik[0]*invrikm2))); - dcosjikdri[1] = ((rij[1]+rik[1])*invrijkm) - - (cosjik*((rij[1]*invrijm2)+(rik[1]*invrikm2))); - dcosjikdri[2] = ((rij[2]+rik[2])*invrijkm) - - (cosjik*((rij[2]*invrijm2)+(rik[2]*invrikm2))); + dcosjikdri[0] = ((rij[0]+rik[0])*invrijkm) - (cosjik*((rij[0]*invrijm2)+(rik[0]*invrikm2))); + dcosjikdri[1] = ((rij[1]+rik[1])*invrijkm) - (cosjik*((rij[1]*invrijm2)+(rik[1]*invrikm2))); + dcosjikdri[2] = ((rij[2]+rik[2])*invrijkm) - (cosjik*((rij[2]*invrijm2)+(rik[2]*invrikm2))); dcosjikdrk[0] = (-rij[0]*invrijkm) + (cosjik*(rik[0]*invrikm2)); dcosjikdrk[1] = (-rij[1]*invrijkm) + (cosjik*(rik[1]*invrikm2)); dcosjikdrk[2] = (-rij[2]*invrijkm) + (cosjik*(rik[2]*invrikm2)); From f864963ab94ba88828cc77ffd0ecd1902313b1e3 Mon Sep 17 00:00:00 2001 From: sakibmatin Date: Thu, 22 Feb 2024 22:03:29 -0700 Subject: [PATCH 091/185] removed old comments. --- src/KOKKOS/mliap_unified_kokkos.cpp | 2 +- src/ML-IAP/mliap_unified.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/KOKKOS/mliap_unified_kokkos.cpp b/src/KOKKOS/mliap_unified_kokkos.cpp index 4a8c14d723..68caf035e9 100644 --- a/src/KOKKOS/mliap_unified_kokkos.cpp +++ b/src/KOKKOS/mliap_unified_kokkos.cpp @@ -380,7 +380,7 @@ void LAMMPS_NS::update_atom_energy(MLIAPDataKokkosDevice *data, double *ei) Kokkos::parallel_reduce(nlocal, KOKKOS_LAMBDA(int i, double &local_sum){ double e = ei[i]; - // must not count any contribution where i is not a local atom + d_eatoms[i] = e; local_sum += e; },*data->energy); diff --git a/src/ML-IAP/mliap_unified.cpp b/src/ML-IAP/mliap_unified.cpp index 6dcdf94c2d..7697204e44 100644 --- a/src/ML-IAP/mliap_unified.cpp +++ b/src/ML-IAP/mliap_unified.cpp @@ -275,7 +275,6 @@ void LAMMPS_NS::update_pair_forces(MLIAPData *data, double *fij) int i = data->pair_i[ii]; int j = data->jatoms[ii]; - // must not count any contribution where i is not a local atom f[i][0] += fij[ii3]; f[i][1] += fij[ii3 + 1]; f[i][2] += fij[ii3 + 2]; From fef2150bfba2c421c20d3afe9e633d932ed42920 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Fri, 23 Feb 2024 13:29:18 -0700 Subject: [PATCH 092/185] Fixing rare precision error in Tsuji damping --- src/GRANULAR/gran_sub_mod_damping.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GRANULAR/gran_sub_mod_damping.cpp b/src/GRANULAR/gran_sub_mod_damping.cpp index 7d6a02b8f0..c635d90265 100644 --- a/src/GRANULAR/gran_sub_mod_damping.cpp +++ b/src/GRANULAR/gran_sub_mod_damping.cpp @@ -130,6 +130,8 @@ void GranSubModDampingTsuji::init() double GranSubModDampingTsuji::calculate_forces() { - damp_prefactor = damp * sqrt(gm->meff * gm->Fnormal / gm->delta); + // in case argument < 0 due to precision issues + double sqrt1 = MAX(0, gm->meff * gm->Fnormal / gm->delta); + damp_prefactor = damp * sqrt(sqrt1); return -damp_prefactor * gm->vnnr; } From 3e089496b33f3e0d59d69a91dfbbce0b96695e1c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 15:52:54 -0500 Subject: [PATCH 093/185] modernize and address issues flagged by static code analysis --- src/EXTRA-FIX/fix_deform_pressure.cpp | 25 +++++++++++++------------ src/EXTRA-FIX/fix_deform_pressure.h | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index aebc6e120f..34741fef14 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -47,7 +47,8 @@ enum { NOCOUPLE = 0, XYZ, XY, YZ, XZ }; /* ---------------------------------------------------------------------- */ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : - FixDeform(lmp, narg, arg), id_temp(nullptr), id_press(nullptr) + FixDeform(lmp, narg, arg), id_temp(nullptr), id_press(nullptr), temperature(nullptr), + pressure(nullptr) { // set defaults @@ -233,7 +234,7 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : if (pcouple != NOCOUPLE) { - if (dimension == 2) + if (domain->dimension == 2) if (pcouple == XYZ || pcouple == XZ || pcouple == YZ) error->all(FLERR, "Cannot couple Z dimension in fix deform/pressure in 2D"); @@ -365,7 +366,7 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id) + "_temp"); - modify->add_compute(fmt::format("{} all temp",id_temp)); + temperature = modify->add_compute(fmt::format("{} all temp", id_temp)); tflag = 1; // create a new compute pressure style @@ -373,7 +374,7 @@ FixDeformPressure::FixDeformPressure(LAMMPS *lmp, int narg, char **arg) : // pass id_temp as 4th arg to pressure constructor id_press = utils::strdup(std::string(id) + "_press"); - modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); + pressure = modify->add_compute(fmt::format("{} all pressure {}", id_press, id_temp)); pflag = 1; } } @@ -420,13 +421,13 @@ void FixDeformPressure::init() // Find pressure/temp computes if needed if (pressure_flag) { - int icompute = modify->find_compute(id_temp); - if (icompute < 0) error->all(FLERR, "Temperature ID for fix deform/pressure does not exist"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR, "Temperature ID {} for fix deform/pressure does not exist", id_temp); - icompute = modify->find_compute(id_press); - if (icompute < 0) error->all(FLERR, "Pressure ID for fix deform/pressure does not exist"); - pressure = modify->compute[icompute]; + pressure = modify->get_compute_by_id(id_press); + if (!pressure) + error->all(FLERR, "Pressure ID {} for fix deform/pressure does not exist", id_press); } } @@ -513,7 +514,7 @@ void FixDeformPressure::apply_pressure() // Find current (possibly coupled/hydrostatic) pressure for X, Y, Z double *tensor = pressure->vector; double scalar = pressure->scalar; - double p_current[3]; + double p_current[3] = {0.0, 0.0, 0.0}; if (pcouple == XYZ) { double ave = THIRD * (tensor[0] + tensor[1] + tensor[2]); @@ -730,7 +731,7 @@ void FixDeformPressure::adjust_linked_rates(double &e_larger, double &e_smaller, void FixDeformPressure::apply_box() { int i; - double scale, shift; + double scale, shift = 0.0; double v_rate; if (set_box.style == VOLUME) { diff --git a/src/EXTRA-FIX/fix_deform_pressure.h b/src/EXTRA-FIX/fix_deform_pressure.h index a52bb01c04..5a0d844bad 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.h +++ b/src/EXTRA-FIX/fix_deform_pressure.h @@ -36,7 +36,7 @@ class FixDeformPressure : public FixDeform { int modify_param(int, char **) override; protected: - int pcouple, dimension; + int pcouple; double max_h_rate; int strain_flag; // 1 if strain-based option is used, 0 if not int pressure_flag; // 1 if pressure tensor used, 0 if not From c36650fc8895f3cd8ff9929dd2f411fc53f44c1a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 15:55:44 -0500 Subject: [PATCH 094/185] auto-assign @jtclemm when fix deform/pressure is edited --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1b4cae3aaa..284d56f1ca 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -65,6 +65,7 @@ src/MANYBODY/pair_nb3b_screened.* @flodesani src/REPLICA/*_grem.* @dstelter92 src/EXTRA-COMPUTE/compute_stress_mop*.* @RomainVermorel src/EXTRA-COMPUTE/compute_born_matrix.* @Bibobu @athomps +src/EXTRA-FIX/fix_deform_pressure.* @jtclemm src/MISC/*_tracker.* @jtclemm src/MC/fix_gcmc.* @athomps src/MC/fix_sgcmc.* @athomps From 5de685368459ad3f3e125dff5881ca6ba4a3e429 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 16:05:30 -0500 Subject: [PATCH 095/185] fix typo --- cmake/Modules/Packages/KOKKOS.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/Packages/KOKKOS.cmake b/cmake/Modules/Packages/KOKKOS.cmake index 0cc13c9667..e1da77c6d0 100644 --- a/cmake/Modules/Packages/KOKKOS.cmake +++ b/cmake/Modules/Packages/KOKKOS.cmake @@ -140,7 +140,7 @@ if(PKG_KSPACE) target_compile_definitions(lammps PRIVATE -DFFT_KOKKOS_KISS) elseif(FFT_KOKKOS STREQUAL "CUFFT") find_library(CUFFT_LIBRARY cufft) - if (CUFFT_LIBRARY STREQUAL "CUTFFT_LIBRARY-NOTFOUND") + if (CUFFT_LIBRARY STREQUAL "CUFFT_LIBRARY-NOTFOUND") message(FATAL_ERROR "Required cuFFT library not found. Check your environment or set CUFFT_LIBRARY to its location") endif() target_compile_definitions(lammps PRIVATE -DFFT_KOKKOS_CUFFT) From dd4cd240df40d820fb4746de114e280413bd6d9b Mon Sep 17 00:00:00 2001 From: jtclemm Date: Fri, 23 Feb 2024 14:31:40 -0700 Subject: [PATCH 096/185] Moving temp/heat keywords out of dump to compute prop/atom --- doc/src/Howto_granular.rst | 5 ++++ doc/src/compute_property_atom.rst | 5 +++- doc/src/dump.rst | 3 -- doc/src/fix_property_atom.rst | 17 +++++++---- examples/granular/in.pour.heat | 3 +- src/BPM/bond_bpm.cpp | 2 -- src/compute_property_atom.cpp | 38 +++++++++++++++++++++++ src/compute_property_atom.h | 2 ++ src/dump_custom.cpp | 50 +------------------------------ src/dump_custom.h | 2 -- 10 files changed, 64 insertions(+), 63 deletions(-) diff --git a/doc/src/Howto_granular.rst b/doc/src/Howto_granular.rst index c22cab66bc..b0c801be11 100644 --- a/doc/src/Howto_granular.rst +++ b/doc/src/Howto_granular.rst @@ -45,10 +45,15 @@ atoms, and should be used for granular system instead of the fix style To model heat conduction, one must add the temperature and heatflow atom variables with: + * :doc:`fix property/atom ` + a temperature integration fix + * :doc:`fix heat/flow ` + and a heat conduction option defined in both + * :doc:`pair_style granular ` * :doc:`fix wall/gran ` diff --git a/doc/src/compute_property_atom.rst b/doc/src/compute_property_atom.rst index b03d6eb74e..4484c3b697 100644 --- a/doc/src/compute_property_atom.rst +++ b/doc/src/compute_property_atom.rst @@ -23,8 +23,9 @@ Syntax spx, spy, spz, sp, fmx, fmy, fmz, nbonds, radius, diameter, omegax, omegay, omegaz, + temperature, heatflow, angmomx, angmomy, angmomz, - shapex,shapey, shapez, + shapex, shapey, shapez, quatw, quati, quatj, quatk, tqx, tqy, tqz, end1x, end1y, end1z, end2x, end2y, end2z, corner1x, corner1y, corner1z, @@ -56,6 +57,8 @@ Syntax *nbonds* = number of bonds assigned to an atom *radius,diameter* = radius,diameter of spherical particle *omegax,omegay,omegaz* = angular velocity of spherical particle + *temperature* = internal temperature of spherical particle + *heatflow* = internal heat flow of spherical particle *angmomx,angmomy,angmomz* = angular momentum of aspherical particle *shapex,shapey,shapez* = 3 diameters of aspherical particle *quatw,quati,quatj,quatk* = quaternion components for aspherical or body particles diff --git a/doc/src/dump.rst b/doc/src/dump.rst index 2d1598e493..82faba6c81 100644 --- a/doc/src/dump.rst +++ b/doc/src/dump.rst @@ -104,7 +104,6 @@ Syntax q, mux, muy, muz, mu, radius, diameter, omegax, omegay, omegaz, angmomx, angmomy, angmomz, tqx, tqy, tqz, - heatflow, temperature, c_ID, c_ID[I], f_ID, f_ID[I], v_name, i_name, d_name, i2_name[I], d2_name[I] @@ -131,8 +130,6 @@ Syntax omegax,omegay,omegaz = angular velocity of spherical particle angmomx,angmomy,angmomz = angular momentum of aspherical particle tqx,tqy,tqz = torque on finite-size particles - heatflow = rate of heat flow into particle - temperature = temperature of particle c_ID = per-atom vector calculated by a compute with ID c_ID[I] = Ith column of per-atom array calculated by a compute with ID, I can include wildcard (see below) f_ID = per-atom vector calculated by a fix with ID diff --git a/doc/src/fix_property_atom.rst b/doc/src/fix_property_atom.rst index b177fe9a96..d20358b7a7 100644 --- a/doc/src/fix_property_atom.rst +++ b/doc/src/fix_property_atom.rst @@ -22,6 +22,8 @@ Syntax *mol* = molecule IDs *q* = charge *rmass* = per-atom mass + *temperature* = internal temperature of atom + *heatflow* = internal heat flow of atom i_name = new integer vector referenced by name d_name = new floating-point vector referenced by name i2_name = new integer array referenced by name @@ -59,14 +61,18 @@ these properties for each atom in the system when a data file is read. This fix augments the set of per-atom properties with new custom ones. This can be useful in several scenarios. -If the atom style does not define molecule IDs, per-atom charge, or -per-atom mass, they can be added using the *mol*\ , *q* or *rmass* +If the atom style does not define molecule IDs, per-atom charge, +per-atom mass, internal temperature, or internal heat flow, they can +be added using the *mol*\ , *q*, *rmass*, *temperature*, or *heatflow* keywords. This could be useful to define "molecules" to use as rigid bodies with the :doc:`fix rigid ` command, or to carry around an extra flag with atoms (stored as a molecule ID) that can be used by various commands like :doc:`compute chunk/atom ` to group atoms without having to use the group command (which is limited to a total of 32 groups including *all*\ ). +For finite-size particles, an internal temperature and heat flow can +be used to model heat conduction as in the +:doc:`GRANULAR package `. Another application is to use the *rmass* flag in order to have per-atom masses instead of per-type masses. This could be used to @@ -85,9 +91,10 @@ properties that are not needed such as bond lists, which incurs some overhead when there are no bonds. In the future, we may add additional existing per-atom properties to -fix property/atom, similar to *mol*\ , *q* or *rmass*\ , which -"turn-on" specific properties defined by some atom styles, so they can -be easily used by atom styles that do not define them. +fix property/atom, similar to *mol*\ , *q*, *rmass*\ , *temperature*\ , +or *heatflow* which "turn-on" specific properties defined by some atom +styles, so they can be easily used by atom styles that do not define +them. More generally, the *i_name* and *d_name* options allow one or more new custom per-atom vectors to be defined. Likewise the *i2_name* and diff --git a/examples/granular/in.pour.heat b/examples/granular/in.pour.heat index 907e56dc39..cc6b03f7d0 100644 --- a/examples/granular/in.pour.heat +++ b/examples/granular/in.pour.heat @@ -73,7 +73,8 @@ thermo 100 timestep 0.001 -#dump 1 all custom 1000 ${name}.dump id type radius mass x y z temperature heatflow +compute 1 all property/atom temperature heatflow +#dump 1 all custom 1000 ${name}.dump id type radius mass x y z c_1[*] run 100000 diff --git a/src/BPM/bond_bpm.cpp b/src/BPM/bond_bpm.cpp index b484df7fab..f1482d4203 100644 --- a/src/BPM/bond_bpm.cpp +++ b/src/BPM/bond_bpm.cpp @@ -357,7 +357,6 @@ void BondBPM::process_broken(int i, int j) if (i < nlocal) { for (m = 0; m < num_bond[i]; m++) { if (bond_atom[i][m] == tag[j]) { - bond_type[i][m] = 0; n = num_bond[i]; bond_type[i][m] = bond_type[i][n - 1]; bond_atom[i][m] = bond_atom[i][n - 1]; @@ -372,7 +371,6 @@ void BondBPM::process_broken(int i, int j) if (j < nlocal) { for (m = 0; m < num_bond[j]; m++) { if (bond_atom[j][m] == tag[i]) { - bond_type[j][m] = 0; n = num_bond[j]; bond_type[j][m] = bond_type[j][n - 1]; bond_atom[j][m] = bond_atom[j][n - 1]; diff --git a/src/compute_property_atom.cpp b/src/compute_property_atom.cpp index c3c101b995..b95b7267dc 100644 --- a/src/compute_property_atom.cpp +++ b/src/compute_property_atom.cpp @@ -205,6 +205,14 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : if (!atom->omega_flag) error->all(FLERR,"Compute property/atom {} is not available", arg[iarg]); pack_choice[i] = &ComputePropertyAtom::pack_omegaz; + } else if (strcmp(arg[iarg],"temperature") == 0) { + if (!atom->temperature_flag) + error->all(FLERR,"Compute property/atom {} is not available", arg[iarg]); + pack_choice[i] = &ComputePropertyAtom::pack_temperature; + } else if (strcmp(arg[iarg],"heatflow") == 0) { + if (!atom->heatflow_flag) + error->all(FLERR,"Compute property/atom {} is not available", arg[iarg]); + pack_choice[i] = &ComputePropertyAtom::pack_heatflow; } else if (strcmp(arg[iarg],"angmomx") == 0) { if (!atom->angmom_flag) error->all(FLERR,"Compute property/atom {} is not available", arg[iarg]); @@ -1213,6 +1221,36 @@ void ComputePropertyAtom::pack_omegaz(int n) /* ---------------------------------------------------------------------- */ +void ComputePropertyAtom::pack_temperature(int n) +{ + double *temperature = atom->temperature; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = temperature[i]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void ComputePropertyAtom::pack_heatflow(int n) +{ + double *heatflow = atom->heatflow; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = heatflow[i]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + void ComputePropertyAtom::pack_angmomx(int n) { double **angmom = atom->angmom; diff --git a/src/compute_property_atom.h b/src/compute_property_atom.h index 034b2901c2..d4f4db564f 100644 --- a/src/compute_property_atom.h +++ b/src/compute_property_atom.h @@ -95,6 +95,8 @@ class ComputePropertyAtom : public Compute { void pack_omegax(int); void pack_omegay(int); void pack_omegaz(int); + void pack_temperature(int); + void pack_heatflow(int); void pack_angmomx(int); void pack_angmomy(int); void pack_angmomz(int); diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index ed70c7413d..e9935b774f 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -41,7 +41,7 @@ enum{ID,MOL,PROC,PROCP1,TYPE,ELEMENT,MASS, XSU,YSU,ZSU,XSUTRI,YSUTRI,ZSUTRI, IX,IY,IZ, VX,VY,VZ,FX,FY,FZ, - Q,MUX,MUY,MUZ,MU,RADIUS,DIAMETER,HEATFLOW,TEMPERATURE, + Q,MUX,MUY,MUZ,MU,RADIUS,DIAMETER, OMEGAX,OMEGAY,OMEGAZ,ANGMOMX,ANGMOMY,ANGMOMZ, TQX,TQY,TQZ, COMPUTE,FIX,VARIABLE,IVEC,DVEC,IARRAY,DARRAY}; @@ -929,18 +929,6 @@ int DumpCustom::count() for (i = 0; i < nlocal; i++) dchoose[i] = 2.0*radius[i]; ptr = dchoose; nstride = 1; - } else if (thresh_array[ithresh] == HEATFLOW) { - if (!atom->heatflow_flag) - error->all(FLERR, - "Threshold for an atom property that isn't allocated"); - ptr = atom->heatflow; - nstride = 1; - } else if (thresh_array[ithresh] == TEMPERATURE) { - if (!atom->temperature_flag) - error->all(FLERR, - "Threshold for an atom property that isn't allocated"); - ptr = atom->temperature; - nstride = 1; } else if (thresh_array[ithresh] == OMEGAX) { if (!atom->omega_flag) error->all(FLERR, @@ -1395,16 +1383,6 @@ int DumpCustom::parse_fields(int narg, char **arg) error->all(FLERR,"Dumping an atom property that isn't allocated"); pack_choice[iarg] = &DumpCustom::pack_diameter; vtype[iarg] = Dump::DOUBLE; - } else if (strcmp(arg[iarg],"heatflow") == 0) { - if (!atom->heatflow_flag) - error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[iarg] = &DumpCustom::pack_heatflow; - vtype[iarg] = Dump::DOUBLE; - } else if (strcmp(arg[iarg],"temperature") == 0) { - if (!atom->temperature_flag) - error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[iarg] = &DumpCustom::pack_temperature; - vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"omegax") == 0) { if (!atom->omega_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); @@ -1875,8 +1853,6 @@ int DumpCustom::modify_param(int narg, char **arg) else if (strcmp(arg[1],"radius") == 0) thresh_array[nthresh] = RADIUS; else if (strcmp(arg[1],"diameter") == 0) thresh_array[nthresh] = DIAMETER; - else if (strcmp(arg[1],"heatflow") == 0) thresh_array[nthresh] = HEATFLOW; - else if (strcmp(arg[1],"temperature") == 0) thresh_array[nthresh] = TEMPERATURE; else if (strcmp(arg[1],"omegax") == 0) thresh_array[nthresh] = OMEGAX; else if (strcmp(arg[1],"omegay") == 0) thresh_array[nthresh] = OMEGAY; else if (strcmp(arg[1],"omegaz") == 0) thresh_array[nthresh] = OMEGAZ; @@ -2791,30 +2767,6 @@ void DumpCustom::pack_diameter(int n) /* ---------------------------------------------------------------------- */ -void DumpCustom::pack_heatflow(int n) -{ - double *heatflow = atom->heatflow; - - for (int i = 0; i < nchoose; i++) { - buf[n] = heatflow[clist[i]]; - n += size_one; - } -} - -/* ---------------------------------------------------------------------- */ - -void DumpCustom::pack_temperature(int n) -{ - double *temperature = atom->temperature; - - for (int i = 0; i < nchoose; i++) { - buf[n] = temperature[clist[i]]; - n += size_one; - } -} - -/* ---------------------------------------------------------------------- */ - void DumpCustom::pack_omegax(int n) { double **omega = atom->omega; diff --git a/src/dump_custom.h b/src/dump_custom.h index 2b04944ec3..b600bd60b8 100644 --- a/src/dump_custom.h +++ b/src/dump_custom.h @@ -188,8 +188,6 @@ class DumpCustom : public Dump { void pack_mu(int); void pack_radius(int); void pack_diameter(int); - void pack_heatflow(int); - void pack_temperature(int); void pack_omegax(int); void pack_omegay(int); From 74abb18e691e57df0a1ea631632b76da69052784 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 16:44:15 -0500 Subject: [PATCH 097/185] improve error messages for pair style airebo and variants --- src/MANYBODY/pair_airebo.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/MANYBODY/pair_airebo.cpp b/src/MANYBODY/pair_airebo.cpp index 13d2b97433..41c8faf752 100644 --- a/src/MANYBODY/pair_airebo.cpp +++ b/src/MANYBODY/pair_airebo.cpp @@ -44,6 +44,8 @@ using namespace MathSpecial; static constexpr double TOL = 1.0e-9; static constexpr int PGDELTA = 1; +static const char *style[3] = {"airebo", "rebo", "airebo/morse"}; + /* ---------------------------------------------------------------------- */ PairAIREBO::PairAIREBO(LAMMPS *lmp) @@ -150,7 +152,7 @@ void PairAIREBO::allocate() void PairAIREBO::settings(int narg, char **arg) { if (narg != 1 && narg != 3 && narg != 4) - error->all(FLERR,"Illegal pair_style command"); + error->all(FLERR,"Illegal pair_style {} command", style[variant]); cutlj = utils::numeric(FLERR,arg[0],false,lmp); @@ -175,12 +177,7 @@ void PairAIREBO::coeff(int narg, char **arg) if (!allocated) allocate(); if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // ensure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); + error->all(FLERR,"Incorrect number of args for pair coefficient."); // read args that map atom types to C and H // map[i] = which element (0,1) the Ith atom type is, -1 if "NULL" @@ -193,7 +190,7 @@ void PairAIREBO::coeff(int narg, char **arg) map[i-2] = 0; } else if (strcmp(arg[i],"H") == 0) { map[i-2] = 1; - } else error->all(FLERR,"Incorrect args for pair coefficients"); + } else error->all(FLERR,"Element {} not supported by pair style {}", arg[i], style[variant]); } // read potential file and initialize fitting splines @@ -228,13 +225,13 @@ void PairAIREBO::coeff(int narg, char **arg) void PairAIREBO::init_style() { if (atom->tag_enable == 0) - error->all(FLERR,"Pair style AIREBO requires atom IDs"); + error->all(FLERR,"Pair style {} requires atom IDs", style[variant]); if (force->newton_pair == 0) - error->all(FLERR,"Pair style AIREBO requires newton pair on"); + error->all(FLERR,"Pair style {} requires newton pair on", style[variant]); // need a full neighbor list, including neighbors of ghosts - neighbor->add_request(this,NeighConst::REQ_FULL|NeighConst::REQ_GHOST); + neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_GHOST); // local REBO neighbor list // create pages if first time or if neighbor pgsize/oneatom has changed From 6ea1bcf9d96dc4e7a2575857277c58e5ce8e6587 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Fri, 23 Feb 2024 14:45:21 -0700 Subject: [PATCH 098/185] Clarifying trace notation in fabric --- src/GRANULAR/compute_fabric.cpp | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/GRANULAR/compute_fabric.cpp b/src/GRANULAR/compute_fabric.cpp index adaf242c92..04afc95280 100644 --- a/src/GRANULAR/compute_fabric.cpp +++ b/src/GRANULAR/compute_fabric.cpp @@ -184,7 +184,7 @@ void ComputeFabric::compute_vector() double nx, ny, nz; double ncinv, denom, fn, ft, prefactor; double br_tensor[6], ft_tensor[6], fn_tensor[6]; - double trace_phi, trace_D, trace_Xfn, trace_Xft; + double trace_third_phi, trace_third_D, trace_third_Xfn, trace_third_Xft; double phi_ij[6] = {0.0}; double Ac_ij[6] = {0.0}; double D_ij[6] = {0.0}; @@ -295,11 +295,11 @@ void ComputeFabric::compute_vector() MPI_Allreduce(phi_ij, temp_dbl, 6, MPI_DOUBLE, MPI_SUM, world); for (i = 0; i < 6; i++) phi_ij[i] = temp_dbl[i] * ncinv; - trace_phi = (1.0 / 3.0) * (phi_ij[0] + phi_ij[1] + phi_ij[2]); + trace_third_phi = (1.0 / 3.0) * (phi_ij[0] + phi_ij[1] + phi_ij[2]); - Ac_ij[0] = (15.0 / 2.0) * (phi_ij[0] - trace_phi); - Ac_ij[1] = (15.0 / 2.0) * (phi_ij[1] - trace_phi); - Ac_ij[2] = (15.0 / 2.0) * (phi_ij[2] - trace_phi); + Ac_ij[0] = (15.0 / 2.0) * (phi_ij[0] - trace_third_phi); + Ac_ij[1] = (15.0 / 2.0) * (phi_ij[1] - trace_third_phi); + Ac_ij[2] = (15.0 / 2.0) * (phi_ij[2] - trace_third_phi); Ac_ij[3] = (15.0 / 2.0) * (phi_ij[3]); Ac_ij[4] = (15.0 / 2.0) * (phi_ij[4]); Ac_ij[5] = (15.0 / 2.0) * (phi_ij[5]); @@ -419,14 +419,14 @@ void ComputeFabric::compute_vector() MPI_Allreduce(D_ij, temp_dbl, 6, MPI_DOUBLE, MPI_SUM, world); for (i = 0; i < 6; i++) D_ij[i] = temp_dbl[i]; - trace_D = (1.0 / 3.0) * (D_ij[0] + D_ij[1] + D_ij[2]); + trace_third_D = (1.0 / 3.0) * (D_ij[0] + D_ij[1] + D_ij[2]); - br_tensor[0] = (15.0 / (6.0 * trace_D)) * (D_ij[0] - trace_D); - br_tensor[1] = (15.0 / (6.0 * trace_D)) * (D_ij[1] - trace_D); - br_tensor[2] = (15.0 / (6.0 * trace_D)) * (D_ij[2] - trace_D); - br_tensor[3] = (15.0 / (6.0 * trace_D)) * (D_ij[3]); - br_tensor[4] = (15.0 / (6.0 * trace_D)) * (D_ij[4]); - br_tensor[5] = (15.0 / (6.0 * trace_D)) * (D_ij[5]); + br_tensor[0] = (15.0 / (6.0 * trace_third_D)) * (D_ij[0] - trace_third_D); + br_tensor[1] = (15.0 / (6.0 * trace_third_D)) * (D_ij[1] - trace_third_D); + br_tensor[2] = (15.0 / (6.0 * trace_third_D)) * (D_ij[2] - trace_third_D); + br_tensor[3] = (15.0 / (6.0 * trace_third_D)) * (D_ij[3]); + br_tensor[4] = (15.0 / (6.0 * trace_third_D)) * (D_ij[4]); + br_tensor[5] = (15.0 / (6.0 * trace_third_D)) * (D_ij[5]); for (i = 0; i < ntensors; i++) { if (tensor_style[i] == BR) { @@ -439,17 +439,17 @@ void ComputeFabric::compute_vector() MPI_Allreduce(Xfn_ij, temp_dbl, 6, MPI_DOUBLE, MPI_SUM, world); for (i = 0; i < 6; i++) Xfn_ij[i] = temp_dbl[i]; - trace_Xfn = (1.0 / 3.0) * (Xfn_ij[0] + Xfn_ij[1] + Xfn_ij[2]); + trace_third_Xfn = (1.0 / 3.0) * (Xfn_ij[0] + Xfn_ij[1] + Xfn_ij[2]); } if (fn_flag) { - fn_tensor[0] = (15.0 / (6.0 * trace_Xfn)) * (Xfn_ij[0] - trace_Xfn); - fn_tensor[1] = (15.0 / (6.0 * trace_Xfn)) * (Xfn_ij[1] - trace_Xfn); - fn_tensor[2] = (15.0 / (6.0 * trace_Xfn)) * (Xfn_ij[2] - trace_Xfn); - fn_tensor[3] = (15.0 / (6.0 * trace_Xfn)) * (Xfn_ij[3]); - fn_tensor[4] = (15.0 / (6.0 * trace_Xfn)) * (Xfn_ij[4]); - fn_tensor[5] = (15.0 / (6.0 * trace_Xfn)) * (Xfn_ij[5]); + fn_tensor[0] = (15.0 / (6.0 * trace_third_Xfn)) * (Xfn_ij[0] - trace_third_Xfn); + fn_tensor[1] = (15.0 / (6.0 * trace_third_Xfn)) * (Xfn_ij[1] - trace_third_Xfn); + fn_tensor[2] = (15.0 / (6.0 * trace_third_Xfn)) * (Xfn_ij[2] - trace_third_Xfn); + fn_tensor[3] = (15.0 / (6.0 * trace_third_Xfn)) * (Xfn_ij[3]); + fn_tensor[4] = (15.0 / (6.0 * trace_third_Xfn)) * (Xfn_ij[4]); + fn_tensor[5] = (15.0 / (6.0 * trace_third_Xfn)) * (Xfn_ij[5]); for (i = 0; i < ntensors; i++) { if (tensor_style[i] == FN) { @@ -462,14 +462,14 @@ void ComputeFabric::compute_vector() MPI_Allreduce(Xft_ij, temp_dbl, 6, MPI_DOUBLE, MPI_SUM, world); for (i = 0; i < 6; i++) Xft_ij[i] = temp_dbl[i]; - trace_Xft = (1.0 / 3.0) * (Xft_ij[0] + Xft_ij[1] + Xft_ij[2]); + trace_third_Xft = (1.0 / 3.0) * (Xft_ij[0] + Xft_ij[1] + Xft_ij[2]); - ft_tensor[0] = (15.0 / (9.0 * trace_Xfn)) * (Xft_ij[0] - trace_Xft); - ft_tensor[1] = (15.0 / (9.0 * trace_Xfn)) * (Xft_ij[1] - trace_Xft); - ft_tensor[2] = (15.0 / (9.0 * trace_Xfn)) * (Xft_ij[2] - trace_Xft); - ft_tensor[3] = (15.0 / (9.0 * trace_Xfn)) * (Xft_ij[3]); - ft_tensor[4] = (15.0 / (9.0 * trace_Xfn)) * (Xft_ij[4]); - ft_tensor[5] = (15.0 / (9.0 * trace_Xfn)) * (Xft_ij[5]); + ft_tensor[0] = (15.0 / (9.0 * trace_third_Xfn)) * (Xft_ij[0] - trace_third_Xft); + ft_tensor[1] = (15.0 / (9.0 * trace_third_Xfn)) * (Xft_ij[1] - trace_third_Xft); + ft_tensor[2] = (15.0 / (9.0 * trace_third_Xfn)) * (Xft_ij[2] - trace_third_Xft); + ft_tensor[3] = (15.0 / (9.0 * trace_third_Xfn)) * (Xft_ij[3]); + ft_tensor[4] = (15.0 / (9.0 * trace_third_Xfn)) * (Xft_ij[4]); + ft_tensor[5] = (15.0 / (9.0 * trace_third_Xfn)) * (Xft_ij[5]); for (i = 0; i < ntensors; i++) { if (tensor_style[i] == FT) { From a3f2c5b8845695f1411dcb48a959edf49f8229ff Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 16:48:03 -0500 Subject: [PATCH 099/185] no longer need to boost neighbor one in rebomos unit test --- unittest/force-styles/tests/manybody-pair-rebomos.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unittest/force-styles/tests/manybody-pair-rebomos.yaml b/unittest/force-styles/tests/manybody-pair-rebomos.yaml index 1d862720af..74fbe2b001 100644 --- a/unittest/force-styles/tests/manybody-pair-rebomos.yaml +++ b/unittest/force-styles/tests/manybody-pair-rebomos.yaml @@ -9,8 +9,7 @@ prerequisites: ! | pre_commands: ! | variable newton_pair delete if "$(is_active(package,gpu)) > 0.0" then "variable newton_pair index off" else "variable newton_pair index on" -post_commands: ! | - neigh_modify one 3000 +post_commands: ! "" input_file: in.airebo pair_style: rebomos pair_coeff: ! | From dda2bc7ac7c36df76e6289d3747459fc84c86d0a Mon Sep 17 00:00:00 2001 From: jtclemm Date: Fri, 23 Feb 2024 14:50:28 -0700 Subject: [PATCH 100/185] Mirroring changes in doc --- doc/src/compute_fabric.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/src/compute_fabric.rst b/doc/src/compute_fabric.rst index b38ffafa48..87fabe2374 100644 --- a/doc/src/compute_fabric.rst +++ b/doc/src/compute_fabric.rst @@ -64,7 +64,7 @@ tangential force tensor. The contact tensor is calculated as .. math:: - C_{ab} = \frac{15}{2} (\phi_{ab} - \mathrm{Tr}(\phi) \delta_{ab}) + C_{ab} = \frac{15}{2} (\phi_{ab} - \frac{1}{3} \mathrm{Tr}(\phi) \delta_{ab}) where :math:`a` and :math:`b` are the :math:`x`, :math:`y`, :math:`z` directions, :math:`\delta_{ab}` is the Kronecker delta function, and @@ -83,7 +83,7 @@ The branch tensor is calculated as .. math:: - B_{ab} = \frac{15}{6 \mathrm{Tr}(D)} (D_{ab} - \mathrm{Tr}(D) \delta_{ab}) + B_{ab} = \frac{15}{2\, \mathrm{Tr}(D)} (D_{ab} - \frac{1}{3} \mathrm{Tr}(D) \delta_{ab}) where the tensor :math:`D` is defined as @@ -101,7 +101,7 @@ The normal force fabric tensor is calculated as .. math:: - F^n_{ab} = \frac{15}{6\, \mathrm{Tr}(N)} (N_{ab} - \mathrm{Tr}(N) \delta_{ab}) + F^n_{ab} = \frac{15}{2\, \mathrm{Tr}(N)} (N_{ab} - \frac{1}{3} \mathrm{Tr}(N) \delta_{ab}) where the tensor :math:`N` is defined as @@ -119,7 +119,7 @@ as .. math:: - F^t_{ab} = \frac{15}{9\, \mathrm{Tr}(N)} (T_{ab} - \mathrm{Tr}(T) \delta_{ab}) + F^t_{ab} = \frac{15}{3\, \mathrm{Tr}(N)} (T_{ab} - \frac{1}{3} \mathrm{Tr}(T) \delta_{ab}) where the tensor :math:`T` is defined as From c401dc31d666fad7a749cc327037e7d0a0be76d3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 17:05:20 -0500 Subject: [PATCH 101/185] bump maxelt to 8 (for folks simulating high-entropy alloys) and make it uppercase --- src/MEAM/meam.h | 44 +++++++++++++++++----------------- src/MEAM/meam_impl.cpp | 4 ++-- src/MEAM/meam_setup_done.cpp | 2 +- src/MEAM/meam_setup_global.cpp | 2 +- src/MEAM/pair_meam.cpp | 5 ++-- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/MEAM/meam.h b/src/MEAM/meam.h index 5a131bdc34..7aca094912 100644 --- a/src/MEAM/meam.h +++ b/src/MEAM/meam.h @@ -17,7 +17,7 @@ #include #include -constexpr int maxelt = 5; +constexpr int MAXELT = 8; namespace LAMMPS_NS { class Memory; @@ -88,30 +88,30 @@ class MEAM { // stheta_meam = sin(theta/2) in radian used in line, zigzag, and trimer reference structures // ctheta_meam = cos(theta/2) in radian used in line, zigzag, and trimer reference structures - double Ec_meam[maxelt][maxelt], re_meam[maxelt][maxelt]; - double A_meam[maxelt], alpha_meam[maxelt][maxelt], rho0_meam[maxelt]; - double delta_meam[maxelt][maxelt]; - double beta0_meam[maxelt], beta1_meam[maxelt]; - double beta2_meam[maxelt], beta3_meam[maxelt]; - double t0_meam[maxelt], t1_meam[maxelt]; - double t2_meam[maxelt], t3_meam[maxelt]; - double rho_ref_meam[maxelt]; - int ibar_meam[maxelt], ielt_meam[maxelt]; - lattice_t lattce_meam[maxelt][maxelt]; - int nn2_meam[maxelt][maxelt]; - int zbl_meam[maxelt][maxelt]; - int eltind[maxelt][maxelt]; + double Ec_meam[MAXELT][MAXELT], re_meam[MAXELT][MAXELT]; + double A_meam[MAXELT], alpha_meam[MAXELT][MAXELT], rho0_meam[MAXELT]; + double delta_meam[MAXELT][MAXELT]; + double beta0_meam[MAXELT], beta1_meam[MAXELT]; + double beta2_meam[MAXELT], beta3_meam[MAXELT]; + double t0_meam[MAXELT], t1_meam[MAXELT]; + double t2_meam[MAXELT], t3_meam[MAXELT]; + double rho_ref_meam[MAXELT]; + int ibar_meam[MAXELT], ielt_meam[MAXELT]; + lattice_t lattce_meam[MAXELT][MAXELT]; + int nn2_meam[MAXELT][MAXELT]; + int zbl_meam[MAXELT][MAXELT]; + int eltind[MAXELT][MAXELT]; int neltypes; double **phir; double **phirar, **phirar1, **phirar2, **phirar3, **phirar4, **phirar5, **phirar6; - double attrac_meam[maxelt][maxelt], repuls_meam[maxelt][maxelt]; + double attrac_meam[MAXELT][MAXELT], repuls_meam[MAXELT][MAXELT]; - double Cmin_meam[maxelt][maxelt][maxelt]; - double Cmax_meam[maxelt][maxelt][maxelt]; - double rc_meam, delr_meam, ebound_meam[maxelt][maxelt]; + double Cmin_meam[MAXELT][MAXELT][MAXELT]; + double Cmax_meam[MAXELT][MAXELT][MAXELT]; + double rc_meam, delr_meam, ebound_meam[MAXELT][MAXELT]; int augt1, ialloy, mix_ref_t, erose_form; int emb_lin_neg, bkgd_dyn; double gsmooth_factor; @@ -124,8 +124,8 @@ class MEAM { // MS-MEAM parameters - double t1m_meam[maxelt], t2m_meam[maxelt], t3m_meam[maxelt]; - double beta1m_meam[maxelt], beta2m_meam[maxelt], beta3m_meam[maxelt]; + double t1m_meam[MAXELT], t2m_meam[MAXELT], t3m_meam[MAXELT]; + double beta1m_meam[MAXELT], beta2m_meam[MAXELT], beta3m_meam[MAXELT]; //int msmeamflag; // made public for pair style settings public: @@ -142,8 +142,8 @@ class MEAM { double *scrfcn, *dscrfcn, *fcpair; //angle for trimer, zigzag, line reference structures - double stheta_meam[maxelt][maxelt]; - double ctheta_meam[maxelt][maxelt]; + double stheta_meam[MAXELT][MAXELT]; + double ctheta_meam[MAXELT][MAXELT]; protected: // meam_funcs.cpp diff --git a/src/MEAM/meam_impl.cpp b/src/MEAM/meam_impl.cpp index 473b491b01..41248c192b 100644 --- a/src/MEAM/meam_impl.cpp +++ b/src/MEAM/meam_impl.cpp @@ -42,12 +42,12 @@ MEAM::MEAM(Memory *mem) : memory(mem) copymode = 0; neltypes = 0; - for (int i = 0; i < maxelt; i++) { + for (int i = 0; i < MAXELT; i++) { A_meam[i] = rho0_meam[i] = beta0_meam[i] = beta1_meam[i] = beta2_meam[i] = beta3_meam[i] = t0_meam[i] = t1_meam[i] = t2_meam[i] = t3_meam[i] = rho_ref_meam[i] = ibar_meam[i] = ielt_meam[i] = t1m_meam[i] = t2m_meam[i] = t3m_meam[i] = beta1m_meam[i] = beta2m_meam[i] = beta3m_meam[i] = 0.0; - for (int j = 0; j < maxelt; j++) { + for (int j = 0; j < MAXELT; j++) { lattce_meam[i][j] = FCC; Ec_meam[i][j] = re_meam[i][j] = alpha_meam[i][j] = delta_meam[i][j] = ebound_meam[i][j] = attrac_meam[i][j] = repuls_meam[i][j] = 0.0; diff --git a/src/MEAM/meam_setup_done.cpp b/src/MEAM/meam_setup_done.cpp index 4adfd68f19..ce756051e4 100644 --- a/src/MEAM/meam_setup_done.cpp +++ b/src/MEAM/meam_setup_done.cpp @@ -33,7 +33,7 @@ void MEAM::meam_setup_done(double* cutmax) *cutmax = cutforce; // Augment t1 term - for (int i = 0; i < maxelt; i++) + for (int i = 0; i < MAXELT; i++) t1_meam[i] = t1_meam[i] + augt1 * 3.0 / 5.0 * t3_meam[i]; // Compute off-diagonal alloy parameters diff --git a/src/MEAM/meam_setup_global.cpp b/src/MEAM/meam_setup_global.cpp index 299fc4da61..4afffb4b02 100644 --- a/src/MEAM/meam_setup_global.cpp +++ b/src/MEAM/meam_setup_global.cpp @@ -38,7 +38,7 @@ void MEAM::meam_setup_global(int nelt, lattice_t *lat, int *ielement, double * / double *b2m, double *b3m, double *t1m, double *t2m, double *t3m) { int i; - double tmplat[maxelt]; + double tmplat[MAXELT]; neltypes = nelt; diff --git a/src/MEAM/pair_meam.cpp b/src/MEAM/pair_meam.cpp index c8932d9a31..6159c452b0 100644 --- a/src/MEAM/pair_meam.cpp +++ b/src/MEAM/pair_meam.cpp @@ -241,11 +241,10 @@ void PairMEAM::coeff(int narg, char **arg) nlibelements = paridx - 3; if (nlibelements < 1) error->all(FLERR, "Incorrect args for pair coefficients"); - if (nlibelements > maxelt) + if (nlibelements > MAXELT) error->all(FLERR, "Too many elements extracted from MEAM library (current limit: {}). " - "Increase 'maxelt' in meam.h and recompile.", - maxelt); + "Increase 'MAXELT' in meam.h and recompile.", MAXELT); for (int i = 0; i < nlibelements; i++) { if (std::any_of(libelements.begin(), libelements.end(), [&](const std::string &elem) { From 66701ef1e2d492dfa3619952e2704c9ff97f89f8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 17:29:31 -0500 Subject: [PATCH 102/185] complete rebomos docs --- doc/src/pair_rebomos.rst | 26 ++++++++++++++++++++- doc/utils/sphinx-config/false_positives.txt | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/src/pair_rebomos.rst b/doc/src/pair_rebomos.rst index 9be400e363..9466deb338 100644 --- a/doc/src/pair_rebomos.rst +++ b/doc/src/pair_rebomos.rst @@ -23,14 +23,34 @@ Examples pair_style rebomos pair_coeff * * ../potentials/MoS.rebomos Mo S +Example input scripts available: examples/threebody/ Description """"""""""" .. versionadded:: TBD -The *rebomos* pair style computes +The *rebomos* pair style computes the interactions between molybdenum +and sulfur atoms :ref:`(Stewart) ` utilizing an adaptive +interatomic reactive empirical bond order potential that is similar in +form to the AIREBO potential :ref:`(Stuart) `. The potential +is based on an earlier parameterizations for :math:`\text{MoS}_2` +developed by :ref:`(Liang) `. +The REBOMoS potential consists of two terms: + +.. math:: + + E & = \frac{1}{2} \sum_i \sum_{j \neq i} + \left[ E^{\text{REBO}}_{ij} + E^{\text{LJ}}_{ij} \right] \\ + +The :math:`E^{\text{REBO}}` term describes the covalently bonded +interactions between Mo and S atoms while the :math:`E^{\text{LJ}}` term +describes longer range dispersion forces between layers. A cubic spline +function is applied to smoothly switch between covalent bonding at short +distances to dispersion interactions at longer distances. This allows +the model to capture bond formation and breaking events which may occur +between adjacent MoS2 layers, edges, defects, and more. ---------- @@ -121,6 +141,10 @@ none **(Steward)** Stewart, Spearot, Modelling Simul. Mater. Sci. Eng. 21,(2013) +.. _Stuart2: + +**(Stuart)** Stuart, Tutein, Harrison, J Chem Phys, 112, 6472-6486. (2000). + .. _Liang: **(Liang)** Liang, Phillpot, Sinnott Phys. Rev. B79 245110, (2009), Erratum: Phys. Rev. B85 199903(E), (2012) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 3423b7859b..e46fb6ca97 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -3599,6 +3599,7 @@ tesselation tesselations Tetot tex +textrm tfac tfmc tfMC From b7153eebee475d25bd9851ff9fea7ae153c856fc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 19:04:14 -0500 Subject: [PATCH 103/185] simplify and check for triclinic again, since somebody may have used change_box --- src/EXTRA-FIX/fix_wall_flow.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index f194a4076a..1f3dcfca5b 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -186,6 +186,9 @@ int FixWallFlow::setmask() void FixWallFlow::init() { + if (domain->triclinic != 0) + error->all(FLERR, "Fix wall/flow cannot be used with triclinic simulation box"); + int nrigid = 0; int box_change_flowax = 0; for (const auto &ifix : modify->get_fix_list()) { @@ -193,18 +196,12 @@ void FixWallFlow::init() switch (flowax) { case FlowAxis::AX_X: if (ifix->box_change & Fix::BOX_CHANGE_X) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_XY) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_XZ) box_change_flowax++; break; case FlowAxis::AX_Y: if (ifix->box_change & Fix::BOX_CHANGE_Y) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_YZ) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_XY) box_change_flowax++; break; case FlowAxis::AX_Z: if (ifix->box_change & Fix::BOX_CHANGE_Z) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_YZ) box_change_flowax++; - if (ifix->box_change & Fix::BOX_CHANGE_XZ) box_change_flowax++; break; } } From 04bccd0a9f74ea62f90308b89c66351b0e775295 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 19:08:46 -0500 Subject: [PATCH 104/185] whitespace --- examples/airebo/in.airebo-0-0 | 26 +++++++++++++------------- examples/airebo/in.rebo2 | 26 +++++++++++++------------- src/fix_ave_chunk.cpp | 3 +-- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/examples/airebo/in.airebo-0-0 b/examples/airebo/in.airebo-0-0 index 077da68912..0e71644127 100644 --- a/examples/airebo/in.airebo-0-0 +++ b/examples/airebo/in.airebo-0-0 @@ -1,22 +1,22 @@ # AIREBO polyethelene benchmark -units metal -atom_style atomic +units metal +atom_style atomic -read_data data.airebo +read_data data.airebo -replicate 17 16 2 +replicate 17 16 2 -neighbor 0.5 bin -neigh_modify delay 5 every 1 +neighbor 0.5 bin +neigh_modify delay 5 every 1 -pair_style airebo 3.0 0 0 -pair_coeff * * CH.airebo C H +pair_style airebo 3.0 0 0 +pair_coeff * * CH.airebo C H -velocity all create 300.0 761341 +velocity all create 300.0 761341 -fix 1 all nve -timestep 0.0005 +fix 1 all nve +timestep 0.0005 -thermo 10 -run 100 +thermo 10 +run 100 diff --git a/examples/airebo/in.rebo2 b/examples/airebo/in.rebo2 index e06cf462ca..319a60bd50 100644 --- a/examples/airebo/in.rebo2 +++ b/examples/airebo/in.rebo2 @@ -1,22 +1,22 @@ # REBO polyethelene benchmark -units metal -atom_style atomic +units metal +atom_style atomic -read_data data.airebo +read_data data.airebo -replicate 17 16 2 +replicate 17 16 2 -neighbor 0.5 bin -neigh_modify delay 5 every 1 +neighbor 0.5 bin +neigh_modify delay 5 every 1 -pair_style rebo -pair_coeff * * CH.rebo C H +pair_style rebo +pair_coeff * * CH.rebo C H -velocity all create 300.0 761341 +velocity all create 300.0 761341 -fix 1 all nve -timestep 0.0005 +fix 1 all nve +timestep 0.0005 -thermo 10 -run 100 +thermo 10 +run 100 diff --git a/src/fix_ave_chunk.cpp b/src/fix_ave_chunk.cpp index 8ed518efc2..a0d25cf2c7 100644 --- a/src/fix_ave_chunk.cpp +++ b/src/fix_ave_chunk.cpp @@ -301,8 +301,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : if (fp && comm->me == 0) { clearerr(fp); if (title1) fprintf(fp,"%s\n",title1); - else fprintf(fp,"# Chunk-averaged data for fix %s and group %s\n", - id, group); + else fprintf(fp,"# Chunk-averaged data for fix %s and group %s\n", id, group); if (title2) fprintf(fp,"%s\n",title2); else fprintf(fp,"# Timestep Number-of-chunks Total-count\n"); if (title3) fprintf(fp,"%s\n",title3); From 9c7ec8bb6c57dc8499272174b94d6b8fb0270c30 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Feb 2024 21:55:09 -0500 Subject: [PATCH 105/185] must update docs for code changes --- doc/src/pair_meam.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/pair_meam.rst b/doc/src/pair_meam.rst index 57c40aa6ee..bafa9fb3c9 100644 --- a/doc/src/pair_meam.rst +++ b/doc/src/pair_meam.rst @@ -427,8 +427,8 @@ package. They are only enabled if LAMMPS was built with that package. See the :doc:`Build package ` page for more info. The maximum number of elements, that can be read from the MEAM library -file, is determined at compile time. The default is 5. If you need -support for more elements, you have to change the the constant 'maxelt' +file, is determined at compile time. The default is 8. If you need +support for more elements, you have to change the the constant 'MAXELT' at the beginning of the file ``src/MEAM/meam.h`` and update/recompile LAMMPS. There is no limit on the number of atoms types. From d39158ca08b1549902f740405df960cfe166dd13 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 24 Feb 2024 03:38:48 -0500 Subject: [PATCH 106/185] modernize --- src/ASPHERE/compute_temp_asphere.cpp | 51 +++++++++++++--------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/src/ASPHERE/compute_temp_asphere.cpp b/src/ASPHERE/compute_temp_asphere.cpp index 7d5d6adce5..d99d9f30c8 100644 --- a/src/ASPHERE/compute_temp_asphere.cpp +++ b/src/ASPHERE/compute_temp_asphere.cpp @@ -18,30 +18,29 @@ #include "compute_temp_asphere.h" -#include -#include "math_extra.h" #include "atom.h" #include "atom_vec_ellipsoid.h" -#include "update.h" -#include "force.h" #include "domain.h" -#include "modify.h" -#include "group.h" #include "error.h" +#include "force.h" +#include "group.h" +#include "math_extra.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; -enum{ROTATE,ALL}; - -static constexpr double INERTIA = 0.2; // moment of inertia prefactor for ellipsoid +enum { ROTATE, ALL }; +static constexpr double INERTIA = 0.2; // moment of inertia prefactor for ellipsoid /* ---------------------------------------------------------------------- */ ComputeTempAsphere::ComputeTempAsphere(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - id_bias(nullptr), tbias(nullptr), avec(nullptr) + Compute(lmp, narg, arg), id_bias(nullptr), tbias(nullptr), avec(nullptr) { - if (narg < 3) error->all(FLERR,"Illegal compute temp/asphere command"); + if (narg < 3) utils::missing_cmd_args(FLERR, "compute temp/asphere", error); scalar_flag = vector_flag = 1; size_vector = 6; @@ -56,19 +55,17 @@ ComputeTempAsphere::ComputeTempAsphere(LAMMPS *lmp, int narg, char **arg) : int iarg = 3; while (iarg < narg) { if (strcmp(arg[iarg],"bias") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute temp/asphere command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "compute temp/asphere bias", error); tempbias = 1; id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"dof") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute temp/asphere command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "compute temp/asphere dof", error); if (strcmp(arg[iarg+1],"rotate") == 0) mode = ROTATE; else if (strcmp(arg[iarg+1],"all") == 0) mode = ALL; - else error->all(FLERR,"Illegal compute temp/asphere command"); + else error->all(FLERR,"Unknown compute temp/asphere dof keyword {}", arg[iarg+1]); iarg += 2; - } else error->all(FLERR,"Illegal compute temp/asphere command"); + } else error->all(FLERR,"Unknown compute temp/asphere keyword {}", arg[iarg]); } // when computing only the rotational temperature, @@ -84,8 +81,8 @@ ComputeTempAsphere::ComputeTempAsphere(LAMMPS *lmp, int narg, char **arg) : ComputeTempAsphere::~ComputeTempAsphere() { - delete [] id_bias; - delete [] vector; + delete[] id_bias; + delete[] vector; } /* ---------------------------------------------------------------------- */ @@ -107,17 +104,17 @@ void ComputeTempAsphere::init() for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) if (ellipsoid[i] < 0) - error->one(FLERR,"Compute temp/asphere requires extended particles"); + error->one(FLERR,"Compute temp/asphere requires all extended particles"); if (tempbias) { - int i = modify->find_compute(id_bias); - if (i < 0) - error->all(FLERR,"Could not find compute ID for temperature bias"); - tbias = modify->compute[i]; + tbias = modify->get_compute_by_id(id_bias); + if (!tbias) + error->all(FLERR,"Could not find compute ID {} for temperature bias", id_bias); + if (tbias->tempflag == 0) - error->all(FLERR,"Bias compute does not calculate temperature"); + error->all(FLERR,"Bias compute {} does not calculate temperature", id_bias); if (tbias->tempbias == 0) - error->all(FLERR,"Bias compute does not calculate a velocity bias"); + error->all(FLERR,"Bias compute {} does not calculate a velocity bias", id_bias); if (tbias->igroup != igroup) error->all(FLERR,"Bias compute group does not match compute group"); if (strcmp(tbias->style,"temp/region") == 0) tempbias = 2; From c869783e72ff094fdda00c9fe002474ef7d492f1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 24 Feb 2024 09:21:20 -0500 Subject: [PATCH 107/185] warn about building LAMMPS with shared lib support for plugins --- cmake/CMakeLists.txt | 3 +++ doc/src/Packages_details.rst | 2 ++ 2 files changed, 5 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ad7f9da35e..05c9ff6e8c 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -693,6 +693,9 @@ endforeach() if(PKG_PLUGIN) target_compile_definitions(lammps PRIVATE -DLMP_PLUGIN) + if(NOT BUILD_SHARED_LIBS) + message(WARNING "Using plugins benefits from compiling LAMMPS with -DBUILD_SHARED_LIBS=yes") + endif() endif() # link with -ldl or equivalent for plugin loading; except on Windows diff --git a/doc/src/Packages_details.rst b/doc/src/Packages_details.rst index a3d65d9d65..ea1336cb0f 100644 --- a/doc/src/Packages_details.rst +++ b/doc/src/Packages_details.rst @@ -2260,6 +2260,8 @@ will search the directory (or directories) listed in this path for files with names that end in ``plugin.so`` (e.g. ``helloplugin.so``) and will try to load the contained plugins automatically at start-up. +It is preferred to build LAMMPS in shared library mode when using this package. + **Authors:** Axel Kohlmeyer (Temple U) .. versionadded:: 8Apr2021 From 01d9f78e6900ce8dfb0db2105f15b9f6eb3097f1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 24 Feb 2024 14:34:40 -0500 Subject: [PATCH 108/185] correct citation --- doc/src/pair_rebomos.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/pair_rebomos.rst b/doc/src/pair_rebomos.rst index 9466deb338..9f4b8006c1 100644 --- a/doc/src/pair_rebomos.rst +++ b/doc/src/pair_rebomos.rst @@ -139,11 +139,11 @@ none .. _Stewart: -**(Steward)** Stewart, Spearot, Modelling Simul. Mater. Sci. Eng. 21,(2013) +**(Steward)** Stewart, Spearot, Modelling Simul. Mater. Sci. Eng. 21, 045003, (2013). .. _Stuart2: -**(Stuart)** Stuart, Tutein, Harrison, J Chem Phys, 112, 6472-6486. (2000). +**(Stuart)** Stuart, Tutein, Harrison, J Chem Phys, 112, 6472-6486, (2000). .. _Liang: From 98b3d19c4036372420517fd6cea5d1f676082cad Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 24 Feb 2024 17:01:53 -0500 Subject: [PATCH 109/185] link with static liblammps.a when available to avoid dynamic linker error when loading plugins --- examples/plugins/LAMMPSInterfaceCXX.cmake | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/plugins/LAMMPSInterfaceCXX.cmake b/examples/plugins/LAMMPSInterfaceCXX.cmake index 7eef5bd6e4..0146aaf240 100644 --- a/examples/plugins/LAMMPSInterfaceCXX.cmake +++ b/examples/plugins/LAMMPSInterfaceCXX.cmake @@ -23,11 +23,21 @@ function(validate_option name values) endfunction(validate_option) ################################################################################# -# LAMMPS C++ interface. We only need the header related parts. +# LAMMPS C++ interface. We only need the header related parts for shared linkage +# but the library .a file for real static or quasi-static linkage (of LAMMPS). add_library(lammps INTERFACE) target_include_directories(lammps INTERFACE ${LAMMPS_HEADER_DIR}) if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING) target_link_libraries(lammps INTERFACE ${CMAKE_BINARY_DIR}/../liblammps.dll.a) +else() + # make a best guess where the static lammps library could be + if(EXISTS ${CMAKE_BINARY_DIR}/../liblammps.a) + target_link_libraries(lammps INTERFACE ${CMAKE_BINARY_DIR}/../liblammps.a) + elseif(EXISTS ${LAMMPS_SOURCE_DIR}/liblammps.a) + target_link_libraries(lammps INTERFACE ${LAMMPS_SOURCE_DIR}/liblammps.a) + elseif(EXISTS ${LAMMPS_SOURCE_DIR}/../build/liblammps.a) + target_link_libraries(lammps INTERFACE ${LAMMPS_SOURCE_DIR}/../build/liblammps.a) + endif() endif() ################################################################################ # MPI configuration From aaba7369678b38cb9c25daf31b09b593b839e70d Mon Sep 17 00:00:00 2001 From: "Aidan P. Thompson" Date: Sat, 24 Feb 2024 14:14:52 -0700 Subject: [PATCH 110/185] Fixed error in forces that only affects non-zero t1m MS-MEAM models --- src/KOKKOS/meam_force_kokkos.h | 2 ++ src/MEAM/meam_force.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/KOKKOS/meam_force_kokkos.h b/src/KOKKOS/meam_force_kokkos.h index fec923f5b2..2f0c51dddb 100644 --- a/src/KOKKOS/meam_force_kokkos.h +++ b/src/KOKKOS/meam_force_kokkos.h @@ -601,6 +601,8 @@ KOKKOS_INLINE_FUNCTION void MEAMKokkos::operator()(TagMEAMForce Date: Sat, 24 Feb 2024 17:29:25 -0500 Subject: [PATCH 111/185] synchronize LAMMPS C++ interface CMake modules --- cmake/Modules/LAMMPSInterfacePlugin.cmake | 9 +++++++++ examples/plugins/LAMMPSInterfaceCXX.cmake | 7 +++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/LAMMPSInterfacePlugin.cmake b/cmake/Modules/LAMMPSInterfacePlugin.cmake index 151e0a04f7..23792a0cb2 100644 --- a/cmake/Modules/LAMMPSInterfacePlugin.cmake +++ b/cmake/Modules/LAMMPSInterfacePlugin.cmake @@ -105,6 +105,15 @@ add_library(lammps INTERFACE) target_include_directories(lammps INTERFACE ${LAMMPS_SOURCE_DIR}) if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING) target_link_libraries(lammps INTERFACE ${CMAKE_BINARY_DIR}/../liblammps.dll.a) +else() + # make a best guess where the static lammps library could be + if(EXISTS ${CMAKE_BINARY_DIR}/../liblammps.a) + target_link_libraries(lammps INTERFACE ${CMAKE_BINARY_DIR}/../liblammps.a) + elseif(EXISTS ${LAMMPS_HEADER_DIR}/liblammps.a) + target_link_libraries(lammps INTERFACE ${LAMMPS_HEADER_DIR}/liblammps.a) + elseif(EXISTS ${LAMMPS_HEADER_DIR}/../build/liblammps.a) + target_link_libraries(lammps INTERFACE ${LAMMPS_HEADER_DIR}/../build/liblammps.a) + endif() endif() ################################################################################ diff --git a/examples/plugins/LAMMPSInterfaceCXX.cmake b/examples/plugins/LAMMPSInterfaceCXX.cmake index 0146aaf240..9cec639cbc 100644 --- a/examples/plugins/LAMMPSInterfaceCXX.cmake +++ b/examples/plugins/LAMMPSInterfaceCXX.cmake @@ -39,6 +39,7 @@ else() target_link_libraries(lammps INTERFACE ${LAMMPS_SOURCE_DIR}/../build/liblammps.a) endif() endif() + ################################################################################ # MPI configuration if(NOT CMAKE_CROSSCOMPILING) @@ -92,13 +93,9 @@ if(BUILD_MPI) # Download and configure custom MPICH files for Windows message(STATUS "Downloading and configuring MPICH-1.4.1 for Windows") set(MPICH2_WIN64_DEVEL_URL "${LAMMPS_THIRDPARTY_URL}/mpich2-win64-devel.tar.gz" CACHE STRING "URL for MPICH2 (win64) tarball") - set(MPICH2_WIN32_DEVEL_URL "${LAMMPS_THIRDPARTY_URL}/mpich2-win32-devel.tar.gz" CACHE STRING "URL for MPICH2 (win32) tarball") set(MPICH2_WIN64_DEVEL_MD5 "4939fdb59d13182fd5dd65211e469f14" CACHE STRING "MD5 checksum of MPICH2 (win64) tarball") - set(MPICH2_WIN32_DEVEL_MD5 "a61d153500dce44e21b755ee7257e031" CACHE STRING "MD5 checksum of MPICH2 (win32) tarball") mark_as_advanced(MPICH2_WIN64_DEVEL_URL) - mark_as_advanced(MPICH2_WIN32_DEVEL_URL) mark_as_advanced(MPICH2_WIN64_DEVEL_MD5) - mark_as_advanced(MPICH2_WIN32_DEVEL_MD5) include(ExternalProject) if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") @@ -141,6 +138,8 @@ else() target_include_directories(lammps INTERFACE "${LAMMPS_SOURCE_DIR}/STUBS") endif() +################ +# integer size selection set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)") set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall) set_property(CACHE LAMMPS_SIZES PROPERTY STRINGS ${LAMMPS_SIZES_VALUES}) From b8c8b4d19bbcfcc92a5a3bf5aa02fb4b3c732bd7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 25 Feb 2024 21:11:31 -0500 Subject: [PATCH 112/185] use -rdynamic for re-exporting symbols when using plugins --- cmake/CMakeLists.txt | 4 ++++ cmake/Modules/LAMMPSInterfacePlugin.cmake | 9 --------- examples/plugins/LAMMPSInterfaceCXX.cmake | 9 --------- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 05c9ff6e8c..a48d606227 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -222,6 +222,10 @@ endif() add_executable(lmp ${MAIN_SOURCES}) target_link_libraries(lmp PRIVATE lammps) set_target_properties(lmp PROPERTIES OUTPUT_NAME ${LAMMPS_BINARY}) +# re-export all symbols for plugins +if(PKG_PLUGIN) + set_target_properties(lmp PROPERTIES LINK_FLAGS "-rdynamic") +endif() install(TARGETS lmp EXPORT LAMMPS_Targets DESTINATION ${CMAKE_INSTALL_BINDIR}) option(CMAKE_VERBOSE_MAKEFILE "Generate verbose Makefiles" OFF) diff --git a/cmake/Modules/LAMMPSInterfacePlugin.cmake b/cmake/Modules/LAMMPSInterfacePlugin.cmake index 23792a0cb2..151e0a04f7 100644 --- a/cmake/Modules/LAMMPSInterfacePlugin.cmake +++ b/cmake/Modules/LAMMPSInterfacePlugin.cmake @@ -105,15 +105,6 @@ add_library(lammps INTERFACE) target_include_directories(lammps INTERFACE ${LAMMPS_SOURCE_DIR}) if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING) target_link_libraries(lammps INTERFACE ${CMAKE_BINARY_DIR}/../liblammps.dll.a) -else() - # make a best guess where the static lammps library could be - if(EXISTS ${CMAKE_BINARY_DIR}/../liblammps.a) - target_link_libraries(lammps INTERFACE ${CMAKE_BINARY_DIR}/../liblammps.a) - elseif(EXISTS ${LAMMPS_HEADER_DIR}/liblammps.a) - target_link_libraries(lammps INTERFACE ${LAMMPS_HEADER_DIR}/liblammps.a) - elseif(EXISTS ${LAMMPS_HEADER_DIR}/../build/liblammps.a) - target_link_libraries(lammps INTERFACE ${LAMMPS_HEADER_DIR}/../build/liblammps.a) - endif() endif() ################################################################################ diff --git a/examples/plugins/LAMMPSInterfaceCXX.cmake b/examples/plugins/LAMMPSInterfaceCXX.cmake index 9cec639cbc..d1f8faec22 100644 --- a/examples/plugins/LAMMPSInterfaceCXX.cmake +++ b/examples/plugins/LAMMPSInterfaceCXX.cmake @@ -29,15 +29,6 @@ add_library(lammps INTERFACE) target_include_directories(lammps INTERFACE ${LAMMPS_HEADER_DIR}) if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING) target_link_libraries(lammps INTERFACE ${CMAKE_BINARY_DIR}/../liblammps.dll.a) -else() - # make a best guess where the static lammps library could be - if(EXISTS ${CMAKE_BINARY_DIR}/../liblammps.a) - target_link_libraries(lammps INTERFACE ${CMAKE_BINARY_DIR}/../liblammps.a) - elseif(EXISTS ${LAMMPS_SOURCE_DIR}/liblammps.a) - target_link_libraries(lammps INTERFACE ${LAMMPS_SOURCE_DIR}/liblammps.a) - elseif(EXISTS ${LAMMPS_SOURCE_DIR}/../build/liblammps.a) - target_link_libraries(lammps INTERFACE ${LAMMPS_SOURCE_DIR}/../build/liblammps.a) - endif() endif() ################################################################################ From 86ea5271d6127bc403a6ea97fcadd5b5a661de70 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 25 Feb 2024 21:19:13 -0500 Subject: [PATCH 113/185] portability --- cmake/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index a48d606227..2cfde45ab2 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -223,7 +223,7 @@ add_executable(lmp ${MAIN_SOURCES}) target_link_libraries(lmp PRIVATE lammps) set_target_properties(lmp PROPERTIES OUTPUT_NAME ${LAMMPS_BINARY}) # re-export all symbols for plugins -if(PKG_PLUGIN) +if(PKG_PLUGIN AND (NOT ((CMAKE_SYSTEM_NAME STREQUAL "Windows")))) set_target_properties(lmp PROPERTIES LINK_FLAGS "-rdynamic") endif() install(TARGETS lmp EXPORT LAMMPS_Targets DESTINATION ${CMAKE_INSTALL_BINDIR}) From 725156753ad72da6f5c707a6093d5933ab4d3630 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 25 Feb 2024 21:51:34 -0500 Subject: [PATCH 114/185] remove superfluous warning --- cmake/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 2cfde45ab2..508ea49f5e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -697,9 +697,6 @@ endforeach() if(PKG_PLUGIN) target_compile_definitions(lammps PRIVATE -DLMP_PLUGIN) - if(NOT BUILD_SHARED_LIBS) - message(WARNING "Using plugins benefits from compiling LAMMPS with -DBUILD_SHARED_LIBS=yes") - endif() endif() # link with -ldl or equivalent for plugin loading; except on Windows From b22ce0f4be697d5f765837d2170bb2265b5a3421 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 25 Feb 2024 21:58:35 -0500 Subject: [PATCH 115/185] use platform neutral CMake property to export symbols --- cmake/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 508ea49f5e..f87c92396f 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -224,7 +224,7 @@ target_link_libraries(lmp PRIVATE lammps) set_target_properties(lmp PROPERTIES OUTPUT_NAME ${LAMMPS_BINARY}) # re-export all symbols for plugins if(PKG_PLUGIN AND (NOT ((CMAKE_SYSTEM_NAME STREQUAL "Windows")))) - set_target_properties(lmp PROPERTIES LINK_FLAGS "-rdynamic") + set_target_properties(lmp PROPERTIES ENABLE_EXPORTS TRUE) endif() install(TARGETS lmp EXPORT LAMMPS_Targets DESTINATION ${CMAKE_INSTALL_BINDIR}) From 5aae41a08c7c10003aeee346ddeaf435aaa323e6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Feb 2024 06:50:36 -0500 Subject: [PATCH 116/185] remove obsolete comment --- doc/src/Packages_details.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/src/Packages_details.rst b/doc/src/Packages_details.rst index ea1336cb0f..a3d65d9d65 100644 --- a/doc/src/Packages_details.rst +++ b/doc/src/Packages_details.rst @@ -2260,8 +2260,6 @@ will search the directory (or directories) listed in this path for files with names that end in ``plugin.so`` (e.g. ``helloplugin.so``) and will try to load the contained plugins automatically at start-up. -It is preferred to build LAMMPS in shared library mode when using this package. - **Authors:** Axel Kohlmeyer (Temple U) .. versionadded:: 8Apr2021 From 2bc5a042144ea0a74d6755b964985aeb4c520360 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Feb 2024 07:54:25 -0500 Subject: [PATCH 117/185] fix conversion bug when input is in radians --- src/DIFFRACTION/compute_xrd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DIFFRACTION/compute_xrd.cpp b/src/DIFFRACTION/compute_xrd.cpp index 426248b31e..2ee23c489c 100644 --- a/src/DIFFRACTION/compute_xrd.cpp +++ b/src/DIFFRACTION/compute_xrd.cpp @@ -261,7 +261,7 @@ void ComputeXRD::init() double ang = 0.0; double convf = 360 / MY_PI; - if (radflag ==1) convf = 1; + if (radflag == 1) convf = 2; int n = 0; for (int m = 0; m < mmax; m++) { From f532a513da243cf40fd22c0c03a3b8f665365bde Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Feb 2024 07:58:53 -0500 Subject: [PATCH 118/185] only import used constant --- src/DIFFRACTION/compute_xrd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DIFFRACTION/compute_xrd.cpp b/src/DIFFRACTION/compute_xrd.cpp index 2ee23c489c..11e0bb9a9f 100644 --- a/src/DIFFRACTION/compute_xrd.cpp +++ b/src/DIFFRACTION/compute_xrd.cpp @@ -35,7 +35,7 @@ #include "omp_compat.h" using namespace LAMMPS_NS; -using namespace MathConst; +using MathConst::MY_PI; static const char cite_compute_xrd_c[] = "compute xrd command: doi:10.1088/0965-0393/21/5/055020\n\n" From 73ae3200d0093948840b67b2b2fd03935375b7d3 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Mon, 26 Feb 2024 12:09:19 -0700 Subject: [PATCH 119/185] incorporating feedback --- doc/src/compute_fabric.rst | 2 +- src/GRANULAR/gran_sub_mod_damping.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/src/compute_fabric.rst b/doc/src/compute_fabric.rst index 87fabe2374..77586e617a 100644 --- a/doc/src/compute_fabric.rst +++ b/doc/src/compute_fabric.rst @@ -119,7 +119,7 @@ as .. math:: - F^t_{ab} = \frac{15}{3\, \mathrm{Tr}(N)} (T_{ab} - \frac{1}{3} \mathrm{Tr}(T) \delta_{ab}) + F^t_{ab} = \frac{5}{\mathrm{Tr}(N)} (T_{ab} - \frac{1}{3} \mathrm{Tr}(T) \delta_{ab}) where the tensor :math:`T` is defined as diff --git a/src/GRANULAR/gran_sub_mod_damping.cpp b/src/GRANULAR/gran_sub_mod_damping.cpp index c635d90265..1ac0ce9030 100644 --- a/src/GRANULAR/gran_sub_mod_damping.cpp +++ b/src/GRANULAR/gran_sub_mod_damping.cpp @@ -130,8 +130,12 @@ void GranSubModDampingTsuji::init() double GranSubModDampingTsuji::calculate_forces() { - // in case argument < 0 due to precision issues - double sqrt1 = MAX(0, gm->meff * gm->Fnormal / gm->delta); + // in case argument <= 0 due to precision issues + double sqrt1; + if (gm->delta > 0.0) + sqrt1 = MAX(0.0, gm->meff * gm->Fnormal / gm->delta); + else + sqrt1 = 0.0; damp_prefactor = damp * sqrt(sqrt1); return -damp_prefactor * gm->vnnr; } From 719b7a96f10b4115414d6e235a67fcb459fd9522 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Feb 2024 16:45:01 -0500 Subject: [PATCH 120/185] silence compiler warnings --- src/DIPOLE/pair_lj_long_dipole_long.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DIPOLE/pair_lj_long_dipole_long.cpp b/src/DIPOLE/pair_lj_long_dipole_long.cpp index 6f46d9d024..2e1a9c4db0 100644 --- a/src/DIPOLE/pair_lj_long_dipole_long.cpp +++ b/src/DIPOLE/pair_lj_long_dipole_long.cpp @@ -401,7 +401,7 @@ void PairLJLongDipoleLong::compute(int eflag, int vflag) ev_init(eflag,vflag); double **x = atom->x, *x0 = x[0]; - double **mu = atom->mu, *mu0 = mu[0], *imu, *jmu; + double **mu = atom->mu, *mu0 = mu[0]; double **tq = atom->torque, *tq0 = tq[0], *tqi; double **f = atom->f, *f0 = f[0], *fi = f0, fx, fy, fz; double *q = atom->q, qi = 0, qj; @@ -435,7 +435,7 @@ void PairLJLongDipoleLong::compute(int eflag, int vflag) lj1i = lj1[typei]; lj2i = lj2[typei]; lj3i = lj3[typei]; lj4i = lj4[typei]; cutsqi = cutsq[typei]; cut_ljsqi = cut_ljsq[typei]; memcpy(xi, x0+(i+(i<<1)), 3*sizeof(double)); - memcpy(mui, imu = mu0+(i<<2), 3*sizeof(double)); + memcpy(mui, mu0+(i<<2), 3*sizeof(double)); jneighn = (jneigh = list->firstneigh[i])+list->numneigh[i]; @@ -453,7 +453,7 @@ void PairLJLongDipoleLong::compute(int eflag, int vflag) r2inv = 1.0/rsq; if (order3 && (rsq < cut_coulsq)) { // dipole - memcpy(muj, jmu = mu0+(j<<2), 3*sizeof(double)); + memcpy(muj, mu0+(j<<2), 3*sizeof(double)); { // series real space double r = sqrt(rsq); double x = g_ewald*r; From bd9f6993e3725462c8361bbff2dcf927a4144edc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Feb 2024 17:14:44 -0500 Subject: [PATCH 121/185] whitespace --- src/KOKKOS/mliap_unified_kokkos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KOKKOS/mliap_unified_kokkos.cpp b/src/KOKKOS/mliap_unified_kokkos.cpp index 68caf035e9..e85f836254 100644 --- a/src/KOKKOS/mliap_unified_kokkos.cpp +++ b/src/KOKKOS/mliap_unified_kokkos.cpp @@ -380,7 +380,7 @@ void LAMMPS_NS::update_atom_energy(MLIAPDataKokkosDevice *data, double *ei) Kokkos::parallel_reduce(nlocal, KOKKOS_LAMBDA(int i, double &local_sum){ double e = ei[i]; - + d_eatoms[i] = e; local_sum += e; },*data->energy); From 82762937a86ae82fe01dba0fbe0554664310f02f Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Mon, 26 Feb 2024 15:37:22 -0700 Subject: [PATCH 122/185] Add better Kokkos support for comm_style tiled --- src/KOKKOS/atom_vec_angle_kokkos.cpp | 310 +-------------- src/KOKKOS/atom_vec_angle_kokkos.h | 13 +- src/KOKKOS/atom_vec_atomic_kokkos.cpp | 20 +- src/KOKKOS/atom_vec_atomic_kokkos.h | 4 +- src/KOKKOS/atom_vec_bond_kokkos.cpp | 22 +- src/KOKKOS/atom_vec_bond_kokkos.h | 4 +- src/KOKKOS/atom_vec_charge_kokkos.cpp | 30 +- src/KOKKOS/atom_vec_charge_kokkos.h | 4 +- src/KOKKOS/atom_vec_dipole_kokkos.cpp | 29 +- src/KOKKOS/atom_vec_dipole_kokkos.h | 4 +- src/KOKKOS/atom_vec_dpd_kokkos.cpp | 84 ++-- src/KOKKOS/atom_vec_dpd_kokkos.h | 11 +- src/KOKKOS/atom_vec_full_kokkos.cpp | 22 +- src/KOKKOS/atom_vec_full_kokkos.h | 4 +- src/KOKKOS/atom_vec_hybrid_kokkos.cpp | 13 +- src/KOKKOS/atom_vec_hybrid_kokkos.h | 11 +- src/KOKKOS/atom_vec_kokkos.cpp | 205 +++++----- src/KOKKOS/atom_vec_kokkos.h | 28 +- src/KOKKOS/atom_vec_molecular_kokkos.cpp | 303 +-------------- src/KOKKOS/atom_vec_molecular_kokkos.h | 13 +- src/KOKKOS/atom_vec_sphere_kokkos.cpp | 176 ++++----- src/KOKKOS/atom_vec_sphere_kokkos.h | 18 +- src/KOKKOS/atom_vec_spin_kokkos.cpp | 30 +- src/KOKKOS/atom_vec_spin_kokkos.h | 4 +- src/KOKKOS/comm_kokkos.cpp | 171 ++++++-- src/KOKKOS/comm_kokkos.h | 24 +- src/KOKKOS/comm_tiled_kokkos.cpp | 476 ++++++++++++++++++++++- src/KOKKOS/comm_tiled_kokkos.h | 61 ++- src/KOKKOS/fix_acks2_reaxff_kokkos.cpp | 2 +- src/KOKKOS/fix_acks2_reaxff_kokkos.h | 3 +- src/KOKKOS/fix_qeq_reaxff_kokkos.cpp | 7 +- src/KOKKOS/fix_qeq_reaxff_kokkos.h | 6 +- src/KOKKOS/fix_rx_kokkos.cpp | 13 +- src/KOKKOS/fix_shake_kokkos.cpp | 9 +- src/KOKKOS/fix_shake_kokkos.h | 6 +- src/KOKKOS/fix_wall_lj93_kokkos.cpp | 12 +- src/KOKKOS/fix_wall_lj93_kokkos.h | 1 - src/KOKKOS/kokkos_base.h | 12 +- src/KOKKOS/kokkos_type.h | 15 + src/KOKKOS/memory_kokkos.h | 250 ++++++------ src/KOKKOS/pair_adp_kokkos.cpp | 7 +- src/KOKKOS/pair_adp_kokkos.h | 5 +- src/KOKKOS/pair_eam_alloy_kokkos.cpp | 7 +- src/KOKKOS/pair_eam_alloy_kokkos.h | 5 +- src/KOKKOS/pair_eam_fs_kokkos.cpp | 7 +- src/KOKKOS/pair_eam_fs_kokkos.h | 5 +- src/KOKKOS/pair_eam_kokkos.cpp | 7 +- src/KOKKOS/pair_eam_kokkos.h | 5 +- src/KOKKOS/pair_meam_kokkos.cpp | 10 +- src/KOKKOS/pair_meam_kokkos.h | 10 +- src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp | 5 +- src/KOKKOS/pair_multi_lucy_rx_kokkos.h | 5 +- 52 files changed, 1209 insertions(+), 1299 deletions(-) diff --git a/src/KOKKOS/atom_vec_angle_kokkos.cpp b/src/KOKKOS/atom_vec_angle_kokkos.cpp index 418c2d629d..dc8641a6b6 100644 --- a/src/KOKKOS/atom_vec_angle_kokkos.cpp +++ b/src/KOKKOS/atom_vec_angle_kokkos.cpp @@ -186,302 +186,13 @@ void AtomVecAngleKokkos::sort_kokkos(Kokkos::BinSort &Sorter /* ---------------------------------------------------------------------- */ -template -struct AtomVecAngleKokkos_PackComm { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array_randomread _x; - typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; - X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; - X_FLOAT _pbc[6]; - - AtomVecAngleKokkos_PackComm( - const typename DAT::tdual_x_array &x, - const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, - const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, - const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_list(list.view()),_iswap(iswap), - _xprd(xprd),_yprd(yprd),_zprd(zprd), - _xy(xy),_xz(xz),_yz(yz) { - const size_t maxsend = (buf.view().extent(0) - *buf.view().extent(1))/3; - const size_t elements = 3; - buffer_view(_buf,buf,maxsend,elements); - _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; - _pbc[3] = pbc[3]; _pbc[4] = pbc[4]; _pbc[5] = pbc[5]; - }; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - const int j = _list(_iswap,i); - if (PBC_FLAG == 0) { - _buf(i,0) = _x(j,0); - _buf(i,1) = _x(j,1); - _buf(i,2) = _x(j,2); - } else { - if (TRICLINIC == 0) { - _buf(i,0) = _x(j,0) + _pbc[0]*_xprd; - _buf(i,1) = _x(j,1) + _pbc[1]*_yprd; - _buf(i,2) = _x(j,2) + _pbc[2]*_zprd; - } else { - _buf(i,0) = _x(j,0) + _pbc[0]*_xprd + _pbc[5]*_xy + _pbc[4]*_xz; - _buf(i,1) = _x(j,1) + _pbc[1]*_yprd + _pbc[3]*_yz; - _buf(i,2) = _x(j,2) + _pbc[2]*_zprd; - } - } - } -}; - -/* ---------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::pack_comm_kokkos(const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, - const DAT::tdual_xfloat_2d &buf, - const int &pbc_flag, - const int* const pbc) -{ - // Check whether to always run forward communication on the host - // Choose correct forward PackComm kernel - - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } else { - atomKK->sync(Device,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } - - return n*size_forward; -} - -/* ---------------------------------------------------------------------- */ - -template -struct AtomVecAngleKokkos_PackCommSelf { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array_randomread _x; - typename ArrayTypes::t_x_array _xw; - int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; - X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; - X_FLOAT _pbc[6]; - - AtomVecAngleKokkos_PackCommSelf( - const typename DAT::tdual_x_array &x, - const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap, - const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, - const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_xw(x.view()),_nfirst(nfirst),_list(list.view()),_iswap(iswap), - _xprd(xprd),_yprd(yprd),_zprd(zprd), - _xy(xy),_xz(xz),_yz(yz) { - _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; - _pbc[3] = pbc[3]; _pbc[4] = pbc[4]; _pbc[5] = pbc[5]; - }; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - const int j = _list(_iswap,i); - if (PBC_FLAG == 0) { - _xw(i+_nfirst,0) = _x(j,0); - _xw(i+_nfirst,1) = _x(j,1); - _xw(i+_nfirst,2) = _x(j,2); - } else { - if (TRICLINIC == 0) { - _xw(i+_nfirst,0) = _x(j,0) + _pbc[0]*_xprd; - _xw(i+_nfirst,1) = _x(j,1) + _pbc[1]*_yprd; - _xw(i+_nfirst,2) = _x(j,2) + _pbc[2]*_zprd; - } else { - _xw(i+_nfirst,0) = _x(j,0) + _pbc[0]*_xprd + _pbc[5]*_xy + _pbc[4]*_xz; - _xw(i+_nfirst,1) = _x(j,1) + _pbc[1]*_yprd + _pbc[3]*_yz; - _xw(i+_nfirst,2) = _x(j,2) + _pbc[2]*_zprd; - } - } - - } -}; - -/* ---------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, - const int nfirst, const int &pbc_flag, - const int* const pbc) { - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } else { - atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } - return n*3; -} - -/* ---------------------------------------------------------------------- */ - -template -struct AtomVecAngleKokkos_UnpackComm { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array _x; - typename ArrayTypes::t_xfloat_2d_const _buf; - int _first; - - AtomVecAngleKokkos_UnpackComm( - const typename DAT::tdual_x_array &x, - const typename DAT::tdual_xfloat_2d &buf, - const int& first):_x(x.view()),_buf(buf.view()), - _first(first) {}; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - _x(i+_first,0) = _buf(i,0); - _x(i+_first,1) = _buf(i,1); - _x(i+_first,2) = _buf(i,2); - } -}; - -/* ---------------------------------------------------------------------- */ - -void AtomVecAngleKokkos::unpack_comm_kokkos(const int &n, const int &first, - const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); - struct AtomVecAngleKokkos_UnpackComm f(atomKK->k_x,buf,first); - Kokkos::parallel_for(n,f); - } else { - atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); - struct AtomVecAngleKokkos_UnpackComm f(atomKK->k_x,buf,first); - Kokkos::parallel_for(n,f); - } -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecAngleKokkos_PackBorder { typedef DeviceType device_type; typedef ArrayTypes AT; typename AT::t_xfloat_2d _buf; - const typename AT::t_int_2d_const _list; - const int _iswap; + const typename AT::t_int_1d_const _list; const typename AT::t_x_array_randomread _x; const typename AT::t_tagint_1d _tag; const typename AT::t_int_1d _type; @@ -491,21 +202,20 @@ struct AtomVecAngleKokkos_PackBorder { AtomVecAngleKokkos_PackBorder( const typename AT::t_xfloat_2d &buf, - const typename AT::t_int_2d_const &list, - const int & iswap, + const typename AT::t_int_1d_const &list, const typename AT::t_x_array &x, const typename AT::t_tagint_1d &tag, const typename AT::t_int_1d &type, const typename AT::t_int_1d &mask, const typename AT::t_tagint_1d &molecule, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_molecule(molecule), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -528,8 +238,8 @@ struct AtomVecAngleKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecAngleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecAngleKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -547,12 +257,12 @@ int AtomVecAngleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecAngleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecAngleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -561,12 +271,12 @@ int AtomVecAngleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecAngleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecAngleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_angle_kokkos.h b/src/KOKKOS/atom_vec_angle_kokkos.h index 44f1d824b2..157e8b45cc 100644 --- a/src/KOKKOS/atom_vec_angle_kokkos.h +++ b/src/KOKKOS/atom_vec_angle_kokkos.h @@ -35,17 +35,8 @@ class AtomVecAngleKokkos : public AtomVecKokkos, public AtomVecAngle { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, - const DAT::tdual_xfloat_2d &buf, - const int &pbc_flag, const int pbc[]) override; - void unpack_comm_kokkos(const int &n, const int &nfirst, - const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, - const int &pbc_flag, const int pbc[]) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_atomic_kokkos.cpp b/src/KOKKOS/atom_vec_atomic_kokkos.cpp index 973ad2f7f2..48d2bf4b92 100644 --- a/src/KOKKOS/atom_vec_atomic_kokkos.cpp +++ b/src/KOKKOS/atom_vec_atomic_kokkos.cpp @@ -125,8 +125,7 @@ struct AtomVecAtomicKokkos_PackBorder { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -135,20 +134,19 @@ struct AtomVecAtomicKokkos_PackBorder { AtomVecAtomicKokkos_PackBorder( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int &iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, const typename ArrayTypes::t_int_1d &mask, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -169,7 +167,7 @@ struct AtomVecAtomicKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecAtomicKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecAtomicKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -187,12 +185,12 @@ int AtomVecAtomicKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,dx,dy,dz); + h_x,h_tag,h_type,h_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,dx,dy,dz); + d_x,d_tag,d_type,d_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -201,12 +199,12 @@ int AtomVecAtomicKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,dx,dy,dz); + h_x,h_tag,h_type,h_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,dx,dy,dz); + d_x,d_tag,d_type,d_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_atomic_kokkos.h b/src/KOKKOS/atom_vec_atomic_kokkos.h index 07631dda98..457b5b61a9 100644 --- a/src/KOKKOS/atom_vec_atomic_kokkos.h +++ b/src/KOKKOS/atom_vec_atomic_kokkos.h @@ -36,8 +36,8 @@ class AtomVecAtomicKokkos : public AtomVecKokkos, public AtomVecAtomic { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_bond_kokkos.cpp b/src/KOKKOS/atom_vec_bond_kokkos.cpp index a4fd9ca1b5..da7f7fb383 100644 --- a/src/KOKKOS/atom_vec_bond_kokkos.cpp +++ b/src/KOKKOS/atom_vec_bond_kokkos.cpp @@ -158,8 +158,7 @@ struct AtomVecBondKokkos_PackBorder { typedef ArrayTypes AT; typename AT::t_xfloat_2d _buf; - const typename AT::t_int_2d_const _list; - const int _iswap; + const typename AT::t_int_1d_const _list; const typename AT::t_x_array_randomread _x; const typename AT::t_tagint_1d _tag; const typename AT::t_int_1d _type; @@ -169,21 +168,20 @@ struct AtomVecBondKokkos_PackBorder { AtomVecBondKokkos_PackBorder( const typename AT::t_xfloat_2d &buf, - const typename AT::t_int_2d_const &list, - const int & iswap, + const typename AT::t_int_1d_const &list, const typename AT::t_x_array &x, const typename AT::t_tagint_1d &tag, const typename AT::t_int_1d &type, const typename AT::t_int_1d &mask, const typename AT::t_tagint_1d &molecule, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_molecule(molecule), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -206,8 +204,8 @@ struct AtomVecBondKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecBondKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecBondKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -225,12 +223,12 @@ int AtomVecBondKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecBondKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecBondKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -239,12 +237,12 @@ int AtomVecBondKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecBondKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecBondKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_bond_kokkos.h b/src/KOKKOS/atom_vec_bond_kokkos.h index 5ed59432de..cad1ea86d7 100644 --- a/src/KOKKOS/atom_vec_bond_kokkos.h +++ b/src/KOKKOS/atom_vec_bond_kokkos.h @@ -35,8 +35,8 @@ class AtomVecBondKokkos : public AtomVecKokkos, public AtomVecBond { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_charge_kokkos.cpp b/src/KOKKOS/atom_vec_charge_kokkos.cpp index 4fa814f1ac..588564de6a 100644 --- a/src/KOKKOS/atom_vec_charge_kokkos.cpp +++ b/src/KOKKOS/atom_vec_charge_kokkos.cpp @@ -134,19 +134,17 @@ struct AtomVecChargeKokkos_PackComm { typename AT::t_x_array_randomread _x; typename AT::t_xfloat_2d_um _buf; - typename AT::t_int_2d_const _list; - const int _iswap; + typename AT::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; AtomVecChargeKokkos_PackComm( const typename DAT::tdual_x_array &x, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_list(list.view()),_iswap(iswap), + _x(x.view()),_list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t maxsend = (buf.view().extent(0)*buf.view().extent(1))/3; @@ -158,7 +156,7 @@ struct AtomVecChargeKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -185,8 +183,7 @@ struct AtomVecChargeKokkos_PackBorder { typedef ArrayTypes AT; typename AT::t_xfloat_2d _buf; - const typename AT::t_int_2d_const _list; - const int _iswap; + const typename AT::t_int_1d_const _list; const typename AT::t_x_array_randomread _x; const typename AT::t_tagint_1d _tag; const typename AT::t_int_1d _type; @@ -196,21 +193,20 @@ struct AtomVecChargeKokkos_PackBorder { AtomVecChargeKokkos_PackBorder( const typename AT::t_xfloat_2d &buf, - const typename AT::t_int_2d_const &list, - const int & iswap, + const typename AT::t_int_1d_const &list, const typename AT::t_x_array &x, const typename AT::t_tagint_1d &tag, const typename AT::t_int_1d &type, const typename AT::t_int_1d &mask, const typename AT::t_float_1d &q, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_q(q), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -233,7 +229,7 @@ struct AtomVecChargeKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecChargeKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecChargeKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -251,12 +247,12 @@ int AtomVecChargeKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecChargeKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecChargeKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -265,12 +261,12 @@ int AtomVecChargeKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecChargeKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecChargeKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_charge_kokkos.h b/src/KOKKOS/atom_vec_charge_kokkos.h index 397a5ee4c0..1d1c68735e 100644 --- a/src/KOKKOS/atom_vec_charge_kokkos.h +++ b/src/KOKKOS/atom_vec_charge_kokkos.h @@ -36,8 +36,8 @@ class AtomVecChargeKokkos : public AtomVecKokkos, public AtomVecCharge { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_dipole_kokkos.cpp b/src/KOKKOS/atom_vec_dipole_kokkos.cpp index ecc0f3b497..28ecb24672 100644 --- a/src/KOKKOS/atom_vec_dipole_kokkos.cpp +++ b/src/KOKKOS/atom_vec_dipole_kokkos.cpp @@ -136,8 +136,7 @@ struct AtomVecDipoleKokkos_PackComm { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_mu_array_randomread _mu; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -145,13 +144,12 @@ struct AtomVecDipoleKokkos_PackComm { const typename DAT::tdual_x_array &x, const typename DAT::tdual_float_1d_4 &mu, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()), _mu(mu.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t elements = 7; // size_forward @@ -163,7 +161,7 @@ struct AtomVecDipoleKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -201,8 +199,7 @@ struct AtomVecDipoleKokkos_PackBorder { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -213,8 +210,7 @@ struct AtomVecDipoleKokkos_PackBorder { AtomVecDipoleKokkos_PackBorder( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int & iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, @@ -222,13 +218,12 @@ struct AtomVecDipoleKokkos_PackBorder { const typename ArrayTypes::t_float_1d &q, const typename ArrayTypes::t_mu_array_randomread &mu, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), _x(x),_tag(tag),_type(type),_mask(mask),_q(q),_mu(mu), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -259,7 +254,7 @@ struct AtomVecDipoleKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecDipoleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecDipoleKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -277,12 +272,12 @@ int AtomVecDipoleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecDipoleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,h_mu,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,h_mu,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecDipoleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,d_mu,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,d_mu,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -291,12 +286,12 @@ int AtomVecDipoleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecDipoleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,h_mu,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,h_mu,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecDipoleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,d_mu,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,d_mu,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_dipole_kokkos.h b/src/KOKKOS/atom_vec_dipole_kokkos.h index 97ec92c6c6..46e102936a 100644 --- a/src/KOKKOS/atom_vec_dipole_kokkos.h +++ b/src/KOKKOS/atom_vec_dipole_kokkos.h @@ -36,8 +36,8 @@ class AtomVecDipoleKokkos : public AtomVecKokkos, public AtomVecDipole { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_dpd_kokkos.cpp b/src/KOKKOS/atom_vec_dpd_kokkos.cpp index 70aedcc931..6152fa60fb 100644 --- a/src/KOKKOS/atom_vec_dpd_kokkos.cpp +++ b/src/KOKKOS/atom_vec_dpd_kokkos.cpp @@ -20,6 +20,7 @@ #include "domain.h" #include "error.h" #include "fix.h" +#include "kokkos.h" #include "memory_kokkos.h" #include "modify.h" @@ -168,8 +169,7 @@ struct AtomVecDPDKokkos_PackComm { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_efloat_1d _dpdTheta,_uCond,_uMech,_uChem; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -180,8 +180,7 @@ struct AtomVecDPDKokkos_PackComm { const typename DAT::tdual_efloat_1d &uMech, const typename DAT::tdual_efloat_1d &uChem, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()), @@ -189,7 +188,7 @@ struct AtomVecDPDKokkos_PackComm { _uCond(uCond.view()), _uMech(uMech.view()), _uChem(uChem.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t maxsend = (buf.view().extent(0)*buf.view().extent(1))/3; @@ -201,7 +200,7 @@ struct AtomVecDPDKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -227,8 +226,7 @@ struct AtomVecDPDKokkos_PackComm { /* ---------------------------------------------------------------------- */ int AtomVecDPDKokkos::pack_comm_kokkos(const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int* const pbc) @@ -236,20 +234,20 @@ int AtomVecDPDKokkos::pack_comm_kokkos(const int &n, // Check whether to always run forward communication on the host // Choose correct forward PackComm kernel - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); if (pbc_flag) { if (domain->triclinic) { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -258,14 +256,14 @@ int AtomVecDPDKokkos::pack_comm_kokkos(const int &n, if (domain->triclinic) { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -277,14 +275,14 @@ int AtomVecDPDKokkos::pack_comm_kokkos(const int &n, if (domain->triclinic) { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -293,14 +291,14 @@ int AtomVecDPDKokkos::pack_comm_kokkos(const int &n, if (domain->triclinic) { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -321,8 +319,7 @@ struct AtomVecDPDKokkos_PackCommSelf { typename ArrayTypes::t_x_array _xw; typename ArrayTypes::t_efloat_1d _dpdTheta,_uCond,_uMech,_uChem; int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -333,8 +330,7 @@ struct AtomVecDPDKokkos_PackCommSelf { const typename DAT::tdual_efloat_1d &uMech, const typename DAT::tdual_efloat_1d &uChem, const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()),_xw(x.view()), @@ -342,7 +338,7 @@ struct AtomVecDPDKokkos_PackCommSelf { _uCond(uCond.view()), _uMech(uMech.view()), _uChem(uChem.view()), - _nfirst(nfirst),_list(list.view()),_iswap(iswap), + _nfirst(nfirst),_list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; @@ -351,7 +347,7 @@ struct AtomVecDPDKokkos_PackCommSelf { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _xw(i+_nfirst,0) = _x(j,0); _xw(i+_nfirst,1) = _x(j,1); @@ -376,23 +372,23 @@ struct AtomVecDPDKokkos_PackCommSelf { /* ---------------------------------------------------------------------- */ -int AtomVecDPDKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list, const int & iswap, +int AtomVecDPDKokkos::pack_comm_self(const int &n, const DAT::tdual_int_1d &list, const int nfirst, const int &pbc_flag, const int* const pbc) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); atomKK->modified(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); if (pbc_flag) { if (domain->triclinic) { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -401,14 +397,14 @@ int AtomVecDPDKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list if (domain->triclinic) { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -421,14 +417,14 @@ int AtomVecDPDKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list if (domain->triclinic) { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -437,14 +433,14 @@ int AtomVecDPDKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list if (domain->triclinic) { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -496,7 +492,7 @@ struct AtomVecDPDKokkos_UnpackComm { void AtomVecDPDKokkos::unpack_comm_kokkos(const int &n, const int &first, const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); atomKK->modified(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); struct AtomVecDPDKokkos_UnpackComm f(atomKK->k_x, @@ -520,8 +516,7 @@ struct AtomVecDPDKokkos_PackBorder { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -531,8 +526,7 @@ struct AtomVecDPDKokkos_PackBorder { AtomVecDPDKokkos_PackBorder( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int & iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, @@ -544,7 +538,7 @@ struct AtomVecDPDKokkos_PackBorder { const typename ArrayTypes::t_efloat_1d &uCG, const typename ArrayTypes::t_efloat_1d &uCGnew, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask), _dpdTheta(dpdTheta), _uCond(uCond), @@ -556,7 +550,7 @@ struct AtomVecDPDKokkos_PackBorder { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -580,7 +574,7 @@ struct AtomVecDPDKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecDPDKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecDPDKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -600,14 +594,14 @@ int AtomVecDPDKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DA if (space==Host) { AtomVecDPDKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_dpdTheta,h_uCond,h_uMech,h_uChem,h_uCG,h_uCGnew, dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecDPDKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_dpdTheta,d_uCond,d_uMech,d_uChem,d_uCG,d_uCGnew, dx,dy,dz); Kokkos::parallel_for(n,f); @@ -618,14 +612,14 @@ int AtomVecDPDKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DA if (space==Host) { AtomVecDPDKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_dpdTheta,h_uCond,h_uMech,h_uChem,h_uCG,h_uCGnew, dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecDPDKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_dpdTheta,d_uCond,d_uMech,d_uChem,d_uCG,d_uCGnew, dx,dy,dz); Kokkos::parallel_for(n,f); diff --git a/src/KOKKOS/atom_vec_dpd_kokkos.h b/src/KOKKOS/atom_vec_dpd_kokkos.h index a76d7f908a..185422cfcf 100644 --- a/src/KOKKOS/atom_vec_dpd_kokkos.h +++ b/src/KOKKOS/atom_vec_dpd_kokkos.h @@ -36,17 +36,16 @@ class AtomVecDPDKokkos : public AtomVecKokkos, public AtomVecDPD { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, + int pack_comm_kokkos(const int &n, const DAT::tdual_int_1d &k_sendlist, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]) override; void unpack_comm_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, + int pack_comm_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst, const int &pbc_flag, const int pbc[]) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_full_kokkos.cpp b/src/KOKKOS/atom_vec_full_kokkos.cpp index 732078a627..82404d4001 100644 --- a/src/KOKKOS/atom_vec_full_kokkos.cpp +++ b/src/KOKKOS/atom_vec_full_kokkos.cpp @@ -275,8 +275,7 @@ struct AtomVecFullKokkos_PackBorder { typedef ArrayTypes AT; typename AT::t_xfloat_2d _buf; - const typename AT::t_int_2d_const _list; - const int _iswap; + const typename AT::t_int_1d_const _list; const typename AT::t_x_array_randomread _x; const typename AT::t_tagint_1d _tag; const typename AT::t_int_1d _type; @@ -287,8 +286,7 @@ struct AtomVecFullKokkos_PackBorder { AtomVecFullKokkos_PackBorder( const typename AT::t_xfloat_2d &buf, - const typename AT::t_int_2d_const &list, - const int & iswap, + const typename AT::t_int_1d_const &list, const typename AT::t_x_array &x, const typename AT::t_tagint_1d &tag, const typename AT::t_int_1d &type, @@ -296,13 +294,13 @@ struct AtomVecFullKokkos_PackBorder { const typename AT::t_float_1d &q, const typename AT::t_tagint_1d &molecule, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_q(q),_molecule(molecule), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -327,8 +325,8 @@ struct AtomVecFullKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecFullKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecFullKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -346,12 +344,12 @@ int AtomVecFullKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecFullKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecFullKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -360,12 +358,12 @@ int AtomVecFullKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecFullKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecFullKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_full_kokkos.h b/src/KOKKOS/atom_vec_full_kokkos.h index 4937ef4152..9eea48ef95 100644 --- a/src/KOKKOS/atom_vec_full_kokkos.h +++ b/src/KOKKOS/atom_vec_full_kokkos.h @@ -35,8 +35,8 @@ class AtomVecFullKokkos : public AtomVecKokkos, public AtomVecFull { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp index 08bcaaef74..b1fc0c8688 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp @@ -63,8 +63,7 @@ void AtomVecHybridKokkos::sort_kokkos(Kokkos::BinSort &Sorte /* ---------------------------------------------------------------------- */ -int AtomVecHybridKokkos::pack_comm_kokkos(const int &/*n*/, const DAT::tdual_int_2d &/*k_sendlist*/, - const int & /*iswap*/, +int AtomVecHybridKokkos::pack_comm_kokkos(const int &/*n*/, const DAT::tdual_int_1d &/*k_sendlist*/, const DAT::tdual_xfloat_2d &/*buf*/, const int &/*pbc_flag*/, const int /*pbc*/[]) { @@ -78,16 +77,16 @@ void AtomVecHybridKokkos::unpack_comm_kokkos(const int &/*n*/, const int &/*nfir error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); } -int AtomVecHybridKokkos::pack_comm_self(const int &/*n*/, const DAT::tdual_int_2d &/*list*/, - const int & /*iswap*/, const int /*nfirst*/, - const int &/*pbc_flag*/, const int /*pbc*/[]) +int AtomVecHybridKokkos::pack_comm_self(const int &/*n*/, const DAT::tdual_int_1d &/*list*/, + const int /*nfirst*/, + const int &/*pbc_flag*/, const int pbc[]) { error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); return 0; } -int AtomVecHybridKokkos::pack_border_kokkos(int /*n*/, DAT::tdual_int_2d /*k_sendlist*/, - DAT::tdual_xfloat_2d /*buf*/,int /*iswap*/, +int AtomVecHybridKokkos::pack_border_kokkos(int /*n*/, DAT::tdual_int_1d /*k_sendlist*/, + DAT::tdual_xfloat_2d /*buf*/, int /*pbc_flag*/, int * /*pbc*/, ExecutionSpace /*space*/) { error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.h b/src/KOKKOS/atom_vec_hybrid_kokkos.h index 6f81c93673..19210549f5 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.h +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.h @@ -36,17 +36,16 @@ class AtomVecHybridKokkos : public AtomVecKokkos, public AtomVecHybrid { void grow(int) override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, + int pack_comm_kokkos(const int &n, const DAT::tdual_int_1d &k_sendlist, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]) override; void unpack_comm_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, + int pack_comm_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst, const int &pbc_flag, const int pbc[]) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_kokkos.cpp b/src/KOKKOS/atom_vec_kokkos.cpp index 93393e9e09..31fc63db6a 100644 --- a/src/KOKKOS/atom_vec_kokkos.cpp +++ b/src/KOKKOS/atom_vec_kokkos.cpp @@ -19,6 +19,7 @@ #include "comm_kokkos.h" #include "error.h" #include "domain.h" +#include "kokkos.h" using namespace LAMMPS_NS; @@ -57,19 +58,17 @@ struct AtomVecKokkos_PackComm { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; AtomVecKokkos_PackComm( const typename DAT::tdual_x_array &x, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_list(list.view()),_iswap(iswap), + _x(x.view()),_list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t maxsend = (buf.view().extent(0)*buf.view().extent(1))/3; @@ -81,7 +80,7 @@ struct AtomVecKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -103,8 +102,7 @@ struct AtomVecKokkos_PackComm { /* ---------------------------------------------------------------------- */ int AtomVecKokkos::pack_comm_kokkos(const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int* const pbc) @@ -112,28 +110,28 @@ int AtomVecKokkos::pack_comm_kokkos(const int &n, // Check whether to always run forward communication on the host // Choose correct forward PackComm kernel - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK); if (pbc_flag) { if (domain->triclinic) { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } } else { if (domain->triclinic) { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -143,24 +141,24 @@ int AtomVecKokkos::pack_comm_kokkos(const int &n, atomKK->sync(Device,X_MASK); if (pbc_flag) { if (domain->triclinic) { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } } else { if (domain->triclinic) { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -168,7 +166,7 @@ int AtomVecKokkos::pack_comm_kokkos(const int &n, } } - return n*size_forward; + return n*size_forward; } /* ---------------------------------------------------------------------- */ @@ -180,19 +178,17 @@ struct AtomVecKokkos_PackCommSelf { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_x_array _xw; int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; AtomVecKokkos_PackCommSelf( const typename DAT::tdual_x_array &x, const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_xw(x.view()),_nfirst(nfirst),_list(list.view()),_iswap(iswap), + _x(x.view()),_xw(x.view()),_nfirst(nfirst),_list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; @@ -201,7 +197,7 @@ struct AtomVecKokkos_PackCommSelf { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _xw(i+_nfirst,0) = _x(j,0); _xw(i+_nfirst,1) = _x(j,1); @@ -223,66 +219,67 @@ struct AtomVecKokkos_PackCommSelf { /* ---------------------------------------------------------------------- */ -int AtomVecKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list, const int & iswap, +int AtomVecKokkos::pack_comm_self(const int &n, const DAT::tdual_int_1d &list, const int nfirst, const int &pbc_flag, const int* const pbc) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); if (pbc_flag) { if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } } else { if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } } + atomKK->modified(Host,X_MASK); } else { atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); if (pbc_flag) { if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } } else { if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } } + atomKK->modified(Device,X_MASK); } - return n*3; + + return n*3; } @@ -361,35 +358,36 @@ struct AtomVecKokkos_PackCommSelfFused { int AtomVecKokkos::pack_comm_self_fused(const int &n, const DAT::tdual_int_2d &list, const DAT::tdual_int_1d &sendnum_scan, const DAT::tdual_int_1d &firstrecv, const DAT::tdual_int_1d &pbc_flag, const DAT::tdual_int_2d &pbc, const DAT::tdual_int_1d &g2l) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, + struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, + struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } + atomKK->modified(Host,X_MASK); } else { atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, + struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, + struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } + atomKK->modified(Device,X_MASK); } + return n*3; } @@ -421,20 +419,19 @@ struct AtomVecKokkos_UnpackComm { void AtomVecKokkos::unpack_comm_kokkos(const int &n, const int &first, const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); struct AtomVecKokkos_UnpackComm f(atomKK->k_x,buf,first); Kokkos::parallel_for(n,f); + atomKK->modified(Host,X_MASK); } else { atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); struct AtomVecKokkos_UnpackComm f(atomKK->k_x,buf,first); Kokkos::parallel_for(n,f); + atomKK->modified(Device,X_MASK); } } - /* ---------------------------------------------------------------------- */ template @@ -445,8 +442,7 @@ struct AtomVecKokkos_PackCommVel { typename ArrayTypes::t_int_1d _mask; typename ArrayTypes::t_v_array _v; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; X_FLOAT _h_rate[6]; @@ -457,8 +453,7 @@ struct AtomVecKokkos_PackCommVel { const typename DAT::tdual_int_1d &mask, const typename DAT::tdual_v_array &v, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int &iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc, const double * const h_rate, @@ -466,7 +461,7 @@ struct AtomVecKokkos_PackCommVel { _x(x.view()), _mask(mask.view()), _v(v.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz), _deform_vremap(deform_vremap) @@ -482,7 +477,7 @@ struct AtomVecKokkos_PackCommVel { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -524,13 +519,12 @@ struct AtomVecKokkos_PackCommVel { int AtomVecKokkos::pack_comm_vel_kokkos( const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int* const pbc) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|V_MASK); if (pbc_flag) { if (deform_vremap) { @@ -538,7 +532,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -546,7 +540,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -556,7 +550,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -564,7 +558,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -575,7 +569,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -583,7 +577,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -597,7 +591,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -605,7 +599,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -615,7 +609,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -623,7 +617,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -634,7 +628,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -642,13 +636,14 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); } } } + return n*6; } @@ -692,16 +687,16 @@ struct AtomVecKokkos_UnpackCommVel { void AtomVecKokkos::unpack_comm_vel_kokkos(const int &n, const int &first, const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|V_MASK); - atomKK->modified(Host,X_MASK|V_MASK); struct AtomVecKokkos_UnpackCommVel f(atomKK->k_x,atomKK->k_v,buf,first); Kokkos::parallel_for(n,f); + atomKK->modified(Host,X_MASK|V_MASK); } else { atomKK->sync(Device,X_MASK|V_MASK); - atomKK->modified(Device,X_MASK|V_MASK); struct AtomVecKokkos_UnpackCommVel f(atomKK->k_x,atomKK->k_v,buf,first); Kokkos::parallel_for(n,f); + atomKK->modified(Device,X_MASK|V_MASK); } } @@ -733,7 +728,7 @@ struct AtomVecKokkos_PackReverse { int AtomVecKokkos::pack_reverse_kokkos(const int &n, const int &first, const DAT::tdual_ffloat_2d &buf) { - if (commKK->reverse_comm_on_host) { + if (lmp->kokkos->reverse_comm_on_host) { atomKK->sync(Host,F_MASK); struct AtomVecKokkos_PackReverse f(atomKK->k_f,buf,first); Kokkos::parallel_for(n,f); @@ -755,20 +750,18 @@ struct AtomVecKokkos_UnPackReverseSelf { typename ArrayTypes::t_f_array_randomread _f; typename ArrayTypes::t_f_array _fw; int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; AtomVecKokkos_UnPackReverseSelf( const typename DAT::tdual_f_array &f, const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap): - _f(f.view()),_fw(f.view()),_nfirst(nfirst),_list(list.view()),_iswap(iswap) { + const typename DAT::tdual_int_1d &list): + _f(f.view()),_fw(f.view()),_nfirst(nfirst),_list(list.view()) { }; KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); _fw(j,0) += _f(i+_nfirst,0); _fw(j,1) += _f(i+_nfirst,1); _fw(j,2) += _f(i+_nfirst,2); @@ -777,19 +770,20 @@ struct AtomVecKokkos_UnPackReverseSelf { /* ---------------------------------------------------------------------- */ -int AtomVecKokkos::unpack_reverse_self(const int &n, const DAT::tdual_int_2d &list, const int & iswap, - const int nfirst) { - if (commKK->reverse_comm_on_host) { +int AtomVecKokkos::pack_reverse_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst) { + if (lmp->kokkos->reverse_comm_on_host) { atomKK->sync(Host,F_MASK); - struct AtomVecKokkos_UnPackReverseSelf f(atomKK->k_f,nfirst,list,iswap); + struct AtomVecKokkos_UnPackReverseSelf f(atomKK->k_f,nfirst,list); Kokkos::parallel_for(n,f); atomKK->modified(Host,F_MASK); } else { atomKK->sync(Device,F_MASK); - struct AtomVecKokkos_UnPackReverseSelf f(atomKK->k_f,nfirst,list,iswap); + struct AtomVecKokkos_UnPackReverseSelf f(atomKK->k_f,nfirst,list); Kokkos::parallel_for(n,f); atomKK->modified(Device,F_MASK); } + return n*3; } @@ -801,15 +795,13 @@ struct AtomVecKokkos_UnPackReverse { typename ArrayTypes::t_f_array _f; typename ArrayTypes::t_ffloat_2d_const _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; AtomVecKokkos_UnPackReverse( const typename DAT::tdual_f_array &f, const typename DAT::tdual_ffloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap): - _f(f.view()),_list(list.view()),_iswap(iswap) { + const typename DAT::tdual_int_1d &list): + _f(f.view()),_list(list.view()) { const size_t maxsend = (buf.view().extent(0)*buf.view().extent(1))/3; const size_t elements = 3; buffer_view(_buf,buf,maxsend,elements); @@ -817,7 +809,7 @@ struct AtomVecKokkos_UnPackReverse { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); _f(j,0) += _buf(i,0); _f(j,1) += _buf(i,1); _f(j,2) += _buf(i,2); @@ -827,19 +819,18 @@ struct AtomVecKokkos_UnPackReverse { /* ---------------------------------------------------------------------- */ void AtomVecKokkos::unpack_reverse_kokkos(const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_ffloat_2d &buf) { // Check whether to always run reverse communication on the host // Choose correct reverse UnPackReverse kernel - if (commKK->reverse_comm_on_host) { - struct AtomVecKokkos_UnPackReverse f(atomKK->k_f,buf,list,iswap); + if (lmp->kokkos->reverse_comm_on_host) { + struct AtomVecKokkos_UnPackReverse f(atomKK->k_f,buf,list); Kokkos::parallel_for(n,f); atomKK->modified(Host,F_MASK); } else { - struct AtomVecKokkos_UnPackReverse f(atomKK->k_f,buf,list,iswap); + struct AtomVecKokkos_UnPackReverse f(atomKK->k_f,buf,list); Kokkos::parallel_for(n,f); atomKK->modified(Device,F_MASK); } diff --git a/src/KOKKOS/atom_vec_kokkos.h b/src/KOKKOS/atom_vec_kokkos.h index c10ff5b40a..635113d500 100644 --- a/src/KOKKOS/atom_vec_kokkos.h +++ b/src/KOKKOS/atom_vec_kokkos.h @@ -50,8 +50,8 @@ class AtomVecKokkos : virtual public AtomVec { virtual void sync_overlapping_device(ExecutionSpace space, unsigned int mask) = 0; virtual int - pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, + pack_comm_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst, const int &pbc_flag, const int pbc[]); virtual int @@ -63,8 +63,8 @@ class AtomVecKokkos : virtual public AtomVec { const DAT::tdual_int_1d &g2l); virtual int - pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const DAT::tdual_xfloat_2d &buf, + pack_comm_kokkos(const int &n, const DAT::tdual_int_1d &list, + const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]); virtual void @@ -72,8 +72,8 @@ class AtomVecKokkos : virtual public AtomVec { const DAT::tdual_xfloat_2d &buf); virtual int - pack_comm_vel_kokkos(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const DAT::tdual_xfloat_2d &buf, + pack_comm_vel_kokkos(const int &n, const DAT::tdual_int_1d &list, + const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]); virtual void @@ -81,20 +81,20 @@ class AtomVecKokkos : virtual public AtomVec { const DAT::tdual_xfloat_2d &buf); virtual int - unpack_reverse_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst); + pack_reverse_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst); virtual int pack_reverse_kokkos(const int &n, const int &nfirst, const DAT::tdual_ffloat_2d &buf); virtual void - unpack_reverse_kokkos(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const DAT::tdual_ffloat_2d &buf); + unpack_reverse_kokkos(const int &n, const DAT::tdual_int_1d &list, + const DAT::tdual_ffloat_2d &buf); virtual int - pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) = 0; virtual void @@ -103,8 +103,8 @@ class AtomVecKokkos : virtual public AtomVec { ExecutionSpace space) = 0; virtual int - pack_border_vel_kokkos(int /*n*/, DAT::tdual_int_2d /*k_sendlist*/, - DAT::tdual_xfloat_2d /*buf*/,int /*iswap*/, + pack_border_vel_kokkos(int /*n*/, DAT::tdual_int_1d /*k_sendlist*/, + DAT::tdual_xfloat_2d /*buf*/, int /*pbc_flag*/, int * /*pbc*/, ExecutionSpace /*space*/) { return 0; } virtual void diff --git a/src/KOKKOS/atom_vec_molecular_kokkos.cpp b/src/KOKKOS/atom_vec_molecular_kokkos.cpp index ec98ff9239..68369e2fad 100644 --- a/src/KOKKOS/atom_vec_molecular_kokkos.cpp +++ b/src/KOKKOS/atom_vec_molecular_kokkos.cpp @@ -260,295 +260,13 @@ void AtomVecMolecularKokkos::sort_kokkos(Kokkos::BinSort &So /* ---------------------------------------------------------------------- */ -template -struct AtomVecMolecularKokkos_PackComm { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array_randomread _x; - typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; - X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; - X_FLOAT _pbc[6]; - - AtomVecMolecularKokkos_PackComm( - const typename DAT::tdual_x_array &x, - const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, - const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, - const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_list(list.view()),_iswap(iswap), - _xprd(xprd),_yprd(yprd),_zprd(zprd), - _xy(xy),_xz(xz),_yz(yz) { - const size_t maxsend = (buf.view().extent(0) - *buf.view().extent(1))/3; - const size_t elements = 3; - buffer_view(_buf,buf,maxsend,elements); - _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; - _pbc[3] = pbc[3]; _pbc[4] = pbc[4]; _pbc[5] = pbc[5]; - }; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - const int j = _list(_iswap,i); - if (PBC_FLAG == 0) { - _buf(i,0) = _x(j,0); - _buf(i,1) = _x(j,1); - _buf(i,2) = _x(j,2); - } else { - if (TRICLINIC == 0) { - _buf(i,0) = _x(j,0) + _pbc[0]*_xprd; - _buf(i,1) = _x(j,1) + _pbc[1]*_yprd; - _buf(i,2) = _x(j,2) + _pbc[2]*_zprd; - } else { - _buf(i,0) = _x(j,0) + _pbc[0]*_xprd + _pbc[5]*_xy + _pbc[4]*_xz; - _buf(i,1) = _x(j,1) + _pbc[1]*_yprd + _pbc[3]*_yz; - _buf(i,2) = _x(j,2) + _pbc[2]*_zprd; - } - } - } -}; - -/* ---------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::pack_comm_kokkos(const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, - const DAT::tdual_xfloat_2d &buf, - const int &pbc_flag, - const int* const pbc) -{ - // Check whether to always run forward communication on the host - // Choose correct forward PackComm kernel - - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } else { - atomKK->sync(Device,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } - - return n*size_forward; -} - -/* ---------------------------------------------------------------------- */ - -template -struct AtomVecMolecularKokkos_PackCommSelf { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array_randomread _x; - typename ArrayTypes::t_x_array _xw; - int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; - X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; - X_FLOAT _pbc[6]; - - AtomVecMolecularKokkos_PackCommSelf( - const typename DAT::tdual_x_array &x, - const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap, - const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, - const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_xw(x.view()),_nfirst(nfirst), - _list(list.view()),_iswap(iswap), - _xprd(xprd),_yprd(yprd),_zprd(zprd), - _xy(xy),_xz(xz),_yz(yz) { - _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; - _pbc[3] = pbc[3]; _pbc[4] = pbc[4]; _pbc[5] = pbc[5]; - }; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - const int j = _list(_iswap,i); - if (PBC_FLAG == 0) { - _xw(i+_nfirst,0) = _x(j,0); - _xw(i+_nfirst,1) = _x(j,1); - _xw(i+_nfirst,2) = _x(j,2); - } else { - if (TRICLINIC == 0) { - _xw(i+_nfirst,0) = _x(j,0) + _pbc[0]*_xprd; - _xw(i+_nfirst,1) = _x(j,1) + _pbc[1]*_yprd; - _xw(i+_nfirst,2) = _x(j,2) + _pbc[2]*_zprd; - } else { - _xw(i+_nfirst,0) = _x(j,0) + _pbc[0]*_xprd + _pbc[5]*_xy + _pbc[4]*_xz; - _xw(i+_nfirst,1) = _x(j,1) + _pbc[1]*_yprd + _pbc[3]*_yz; - _xw(i+_nfirst,2) = _x(j,2) + _pbc[2]*_zprd; - } - } - - } -}; - -/* ---------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, - const int nfirst, const int &pbc_flag, - const int* const pbc) { - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } else { - atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } - return n*3; -} - -/* ---------------------------------------------------------------------- */ - -template -struct AtomVecMolecularKokkos_UnpackComm { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array _x; - typename ArrayTypes::t_xfloat_2d_const _buf; - int _first; - - AtomVecMolecularKokkos_UnpackComm( - const typename DAT::tdual_x_array &x, - const typename DAT::tdual_xfloat_2d &buf, - const int& first):_x(x.view()),_buf(buf.view()), - _first(first) {}; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - _x(i+_first,0) = _buf(i,0); - _x(i+_first,1) = _buf(i,1); - _x(i+_first,2) = _buf(i,2); - } -}; - -/* ---------------------------------------------------------------------- */ - -void AtomVecMolecularKokkos::unpack_comm_kokkos(const int &n, const int &first, - const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); - struct AtomVecMolecularKokkos_UnpackComm f(atomKK->k_x,buf,first); - Kokkos::parallel_for(n,f); - } else { - atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); - struct AtomVecMolecularKokkos_UnpackComm f(atomKK->k_x,buf,first); - Kokkos::parallel_for(n,f); - } -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecMolecularKokkos_PackBorder { typedef DeviceType device_type; typedef ArrayTypes AT; typename AT::t_xfloat_2d _buf; - const typename AT::t_int_2d_const _list; - const int _iswap; + const typename AT::t_int_1d_const _list; const typename AT::t_x_array_randomread _x; const typename AT::t_tagint_1d _tag; const typename AT::t_int_1d _type; @@ -558,21 +276,20 @@ struct AtomVecMolecularKokkos_PackBorder { AtomVecMolecularKokkos_PackBorder( const typename AT::t_xfloat_2d &buf, - const typename AT::t_int_2d_const &list, - const int & iswap, + const typename AT::t_int_1d_const &list, const typename AT::t_x_array &x, const typename AT::t_tagint_1d &tag, const typename AT::t_int_1d &type, const typename AT::t_int_1d &mask, const typename AT::t_tagint_1d &molecule, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_molecule(molecule), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -595,8 +312,8 @@ struct AtomVecMolecularKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecMolecularKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecMolecularKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -614,12 +331,12 @@ int AtomVecMolecularKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendli if (space==Host) { AtomVecMolecularKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecMolecularKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -628,12 +345,12 @@ int AtomVecMolecularKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendli if (space==Host) { AtomVecMolecularKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecMolecularKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_molecular_kokkos.h b/src/KOKKOS/atom_vec_molecular_kokkos.h index eb976e9073..a92784fbd9 100644 --- a/src/KOKKOS/atom_vec_molecular_kokkos.h +++ b/src/KOKKOS/atom_vec_molecular_kokkos.h @@ -35,17 +35,8 @@ class AtomVecMolecularKokkos : public AtomVecKokkos, public AtomVecMolecular { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, - const DAT::tdual_xfloat_2d &buf, - const int &pbc_flag, const int pbc[]) override; - void unpack_comm_kokkos(const int &n, const int &nfirst, - const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, - const int &pbc_flag, const int pbc[]) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_sphere_kokkos.cpp b/src/KOKKOS/atom_vec_sphere_kokkos.cpp index 3dfb5143cd..de62988c67 100644 --- a/src/KOKKOS/atom_vec_sphere_kokkos.cpp +++ b/src/KOKKOS/atom_vec_sphere_kokkos.cpp @@ -20,6 +20,7 @@ #include "domain.h" #include "error.h" #include "fix.h" +#include "kokkos.h" #include "math_const.h" #include "memory.h" #include "memory_kokkos.h" @@ -152,8 +153,7 @@ struct AtomVecSphereKokkos_PackComm { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_float_1d _radius,_rmass; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -162,14 +162,13 @@ struct AtomVecSphereKokkos_PackComm { const typename DAT::tdual_float_1d &radius, const typename DAT::tdual_float_1d &rmass, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()), _radius(radius.view()), _rmass(rmass.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t elements = 5; @@ -181,7 +180,7 @@ struct AtomVecSphereKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -206,25 +205,24 @@ struct AtomVecSphereKokkos_PackComm { int AtomVecSphereKokkos::pack_comm_kokkos( const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int* const pbc) { // Fallback to AtomVecKokkos if radvary == 0 if (radvary == 0) - return AtomVecKokkos::pack_comm_kokkos(n,list,iswap,buf,pbc_flag,pbc); + return AtomVecKokkos::pack_comm_kokkos(n,list,buf,pbc_flag,pbc); // Check whether to always run forward communication on the host // Choose correct forward PackComm kernel - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|RADIUS_MASK|RMASS_MASK); if (pbc_flag) { if (domain->triclinic) { struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -232,7 +230,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -242,7 +240,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -250,7 +248,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -263,7 +261,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -271,7 +269,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -281,7 +279,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -289,7 +287,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -310,8 +308,7 @@ struct AtomVecSphereKokkos_PackCommVel { typename ArrayTypes::t_float_1d _radius,_rmass; typename ArrayTypes::t_v_array _v, _omega; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; X_FLOAT _h_rate[6]; @@ -325,8 +322,7 @@ struct AtomVecSphereKokkos_PackCommVel { const typename DAT::tdual_v_array &v, const typename DAT::tdual_v_array &omega, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int &iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc, const double * const h_rate, @@ -337,7 +333,7 @@ struct AtomVecSphereKokkos_PackCommVel { _rmass(rmass.view()), _v(v.view()), _omega(omega.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz), _deform_vremap(deform_vremap) @@ -353,7 +349,7 @@ struct AtomVecSphereKokkos_PackCommVel { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -398,13 +394,12 @@ struct AtomVecSphereKokkos_PackCommVel { int AtomVecSphereKokkos::pack_comm_vel_kokkos( const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int* const pbc) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|RADIUS_MASK|RMASS_MASK|V_MASK|OMEGA_MASK); if (pbc_flag) { if (deform_vremap) { @@ -414,7 +409,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -423,7 +418,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -434,7 +429,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -443,7 +438,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -456,7 +451,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -465,7 +460,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -476,7 +471,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -485,7 +480,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -499,7 +494,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -508,7 +503,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -519,7 +514,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -528,7 +523,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -545,7 +540,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -554,7 +549,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -565,7 +560,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -574,7 +569,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -587,7 +582,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -596,7 +591,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -607,7 +602,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -616,7 +611,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -630,7 +625,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -639,7 +634,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -650,7 +645,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -659,7 +654,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -680,8 +675,7 @@ struct AtomVecSphereKokkos_PackCommSelf { typename ArrayTypes::t_x_array _xw; typename ArrayTypes::t_float_1d _radius,_rmass; int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -690,14 +684,13 @@ struct AtomVecSphereKokkos_PackCommSelf { const typename DAT::tdual_float_1d &radius, const typename DAT::tdual_float_1d &rmass, const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()),_xw(x.view()), _radius(radius.view()), _rmass(rmass.view()), - _nfirst(nfirst),_list(list.view()),_iswap(iswap), + _nfirst(nfirst),_list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; @@ -706,7 +699,7 @@ struct AtomVecSphereKokkos_PackCommSelf { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _xw(i+_nfirst,0) = _x(j,0); _xw(i+_nfirst,1) = _x(j,1); @@ -730,12 +723,12 @@ struct AtomVecSphereKokkos_PackCommSelf { /* ---------------------------------------------------------------------- */ int AtomVecSphereKokkos::pack_comm_self( - const int &n, const DAT::tdual_int_2d &list, const int &iswap, + const int &n, const DAT::tdual_int_1d &list, const int nfirst, const int &pbc_flag, const int* const pbc) { // Fallback to AtomVecKokkos if radvary == 0 if (radvary == 0) - return AtomVecKokkos::pack_comm_self(n,list,iswap,nfirst,pbc_flag,pbc); - if (commKK->forward_comm_on_host) { + return AtomVecKokkos::pack_comm_self(n,list,nfirst,pbc_flag,pbc); + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|RADIUS_MASK|RMASS_MASK); atomKK->modified(Host,X_MASK|RADIUS_MASK|RMASS_MASK); if (pbc_flag) { @@ -743,7 +736,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -751,7 +744,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -761,7 +754,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -769,7 +762,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -783,7 +776,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -791,7 +784,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -801,7 +794,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -809,7 +802,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -866,7 +859,7 @@ void AtomVecSphereKokkos::unpack_comm_kokkos( AtomVecKokkos::unpack_comm_kokkos(n,first,buf); return; } - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->modified(Host,X_MASK|RADIUS_MASK|RMASS_MASK); struct AtomVecSphereKokkos_UnpackComm f( atomKK->k_x, @@ -938,7 +931,7 @@ struct AtomVecSphereKokkos_UnpackCommVel { void AtomVecSphereKokkos::unpack_comm_vel_kokkos( const int &n, const int &first, const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->modified(Host,X_MASK|RADIUS_MASK|RMASS_MASK|V_MASK|OMEGA_MASK); if (radvary == 0) { struct AtomVecSphereKokkos_UnpackCommVel f( @@ -982,8 +975,7 @@ struct AtomVecSphereKokkos_PackBorder { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d_um _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -993,8 +985,7 @@ struct AtomVecSphereKokkos_PackBorder { AtomVecSphereKokkos_PackBorder( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int &iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, @@ -1002,7 +993,6 @@ struct AtomVecSphereKokkos_PackBorder { const typename ArrayTypes::t_float_1d &radius, const typename ArrayTypes::t_float_1d &rmass, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _list(list),_iswap(iswap), _x(x),_tag(tag),_type(type),_mask(mask), _radius(radius), _rmass(rmass), @@ -1015,7 +1005,7 @@ struct AtomVecSphereKokkos_PackBorder { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -1036,7 +1026,7 @@ struct AtomVecSphereKokkos_PackBorder { /* ---------------------------------------------------------------------- */ int AtomVecSphereKokkos::pack_border_kokkos( - int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, + int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -1057,14 +1047,14 @@ int AtomVecSphereKokkos::pack_border_kokkos( if (space==Host) { AtomVecSphereKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_radius,h_rmass, dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecSphereKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_radius,d_rmass, dx,dy,dz); Kokkos::parallel_for(n,f); @@ -1074,14 +1064,14 @@ int AtomVecSphereKokkos::pack_border_kokkos( if (space==Host) { AtomVecSphereKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_radius,h_rmass, dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecSphereKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_radius,d_rmass, dx,dy,dz); Kokkos::parallel_for(n,f); @@ -1097,8 +1087,7 @@ struct AtomVecSphereKokkos_PackBorderVel { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d_um _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -1110,8 +1099,7 @@ struct AtomVecSphereKokkos_PackBorderVel { AtomVecSphereKokkos_PackBorderVel( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int &iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, @@ -1123,7 +1111,7 @@ struct AtomVecSphereKokkos_PackBorderVel { const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz, const X_FLOAT &dvx, const X_FLOAT &dvy, const X_FLOAT &dvz, const int &deform_groupbit): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask), _radius(radius), _rmass(rmass), @@ -1139,7 +1127,7 @@ struct AtomVecSphereKokkos_PackBorderVel { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -1175,7 +1163,7 @@ struct AtomVecSphereKokkos_PackBorderVel { /* ---------------------------------------------------------------------- */ int AtomVecSphereKokkos::pack_border_vel_kokkos( - int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, + int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx=0,dy=0,dz=0; @@ -1198,7 +1186,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( if (space==Host) { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_radius,h_rmass, h_v, h_omega, dx,dy,dz,dvx,dvy,dvz, @@ -1207,7 +1195,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( } else { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_radius,d_rmass, d_v, d_omega, dx,dy,dz,dvx,dvy,dvz, @@ -1222,7 +1210,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( if (space==Host) { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_radius,h_rmass, h_v, h_omega, dx,dy,dz,dvx,dvy,dvz, @@ -1231,7 +1219,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( } else { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_radius,d_rmass, d_v, d_omega, dx,dy,dz,dvx,dvy,dvz, @@ -1243,7 +1231,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( if (space==Host) { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_radius,h_rmass, h_v, h_omega, dx,dy,dz,dvx,dvy,dvz, @@ -1252,7 +1240,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( } else { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_radius,d_rmass, d_v, d_omega, dx,dy,dz,dvx,dvy,dvz, diff --git a/src/KOKKOS/atom_vec_sphere_kokkos.h b/src/KOKKOS/atom_vec_sphere_kokkos.h index 34529320d9..b28da45c6a 100644 --- a/src/KOKKOS/atom_vec_sphere_kokkos.h +++ b/src/KOKKOS/atom_vec_sphere_kokkos.h @@ -37,29 +37,27 @@ class AtomVecSphereKokkos : public AtomVecKokkos, public AtomVecSphere { void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, + int pack_comm_kokkos(const int &n, const DAT::tdual_int_1d &k_sendlist, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]) override; void unpack_comm_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_vel_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, + int pack_comm_vel_kokkos(const int &n, const DAT::tdual_int_1d &k_sendlist, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]) override; void unpack_comm_vel_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, + int pack_comm_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst, const int &pbc_flag, const int pbc[]) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, ExecutionSpace space) override; - int pack_border_vel_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_vel_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_vel_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_spin_kokkos.cpp b/src/KOKKOS/atom_vec_spin_kokkos.cpp index c6ee7c1d3b..87f5cd46c6 100644 --- a/src/KOKKOS/atom_vec_spin_kokkos.cpp +++ b/src/KOKKOS/atom_vec_spin_kokkos.cpp @@ -157,8 +157,7 @@ struct AtomVecSpinKokkos_PackComm { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_sp_array_randomread _sp; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -166,12 +165,11 @@ struct AtomVecSpinKokkos_PackComm { const typename DAT::tdual_x_array &x, const typename DAT::tdual_float_1d_4 &sp, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()),_sp(sp.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t maxsend = (buf.view().extent(0)*buf.view().extent(1))/3; @@ -183,7 +181,7 @@ struct AtomVecSpinKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -221,8 +219,7 @@ struct AtomVecSpinKokkos_PackBorder { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -232,21 +229,20 @@ struct AtomVecSpinKokkos_PackBorder { AtomVecSpinKokkos_PackBorder( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int & iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, const typename ArrayTypes::t_int_1d &mask, const typename ArrayTypes::t_sp_array &sp, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_sp(sp), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -275,7 +271,7 @@ struct AtomVecSpinKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecSpinKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecSpinKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -293,12 +289,12 @@ int AtomVecSpinKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, D if(space==Host) { AtomVecSpinKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_sp,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_sp,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecSpinKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_sp,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_sp,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -307,12 +303,12 @@ int AtomVecSpinKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, D if(space==Host) { AtomVecSpinKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_sp,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_sp,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecSpinKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_sp,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_sp,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_spin_kokkos.h b/src/KOKKOS/atom_vec_spin_kokkos.h index f0145e4db7..6f968dcd25 100644 --- a/src/KOKKOS/atom_vec_spin_kokkos.h +++ b/src/KOKKOS/atom_vec_spin_kokkos.h @@ -36,8 +36,8 @@ class AtomVecSpinKokkos : public AtomVecKokkos, public AtomVecSpin { void grow_pointers() override; void force_clear(int, size_t) override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/comm_kokkos.cpp b/src/KOKKOS/comm_kokkos.cpp index 6bb2d7e4d0..2425857d61 100644 --- a/src/KOKKOS/comm_kokkos.cpp +++ b/src/KOKKOS/comm_kokkos.cpp @@ -142,11 +142,15 @@ void CommKokkos::init() if (force->newton == 0) check_reverse = 0; if (force->pair) check_reverse += force->pair->comm_reverse_off; - if (!comm_f_only) // not all Kokkos atom_vec styles have reverse pack/unpack routines yet + if (!comm_f_only) {// not all Kokkos atom_vec styles have reverse pack/unpack routines yet reverse_comm_classic = true; + lmp->kokkos->reverse_comm_classic = 1; + } - if (ghost_velocity && atomKK->avecKK->no_comm_vel_flag) // not all Kokkos atom_vec styles have comm vel pack/unpack routines yet + if (ghost_velocity && atomKK->avecKK->no_comm_vel_flag) { // not all Kokkos atom_vec styles have comm vel pack/unpack routines yet forward_comm_classic = true; + lmp->kokkos->forward_comm_classic = 1; + } } /* ---------------------------------------------------------------------- @@ -157,8 +161,8 @@ void CommKokkos::init() void CommKokkos::forward_comm(int dummy) { if (!forward_comm_classic) { - if (forward_comm_on_host) forward_comm_device(dummy); - else forward_comm_device(dummy); + if (forward_comm_on_host) forward_comm_device(); + else forward_comm_device(); return; } @@ -181,7 +185,7 @@ void CommKokkos::forward_comm(int dummy) /* ---------------------------------------------------------------------- */ template -void CommKokkos::forward_comm_device(int) +void CommKokkos::forward_comm_device() { int n; MPI_Request request; @@ -192,7 +196,6 @@ void CommKokkos::forward_comm_device(int) // if comm_x_only set, exchange or copy directly to x, don't unpack k_sendlist.sync(); - atomKK->sync(ExecutionSpaceFromDevice::space,X_MASK); if (comm->nprocs == 1 && !ghost_velocity) { k_swap.sync(); @@ -211,26 +214,26 @@ void CommKokkos::forward_comm_device(int) MPI_Irecv(buf,size_forward_recv[iswap],MPI_DOUBLE, recvproc[iswap],0,world,&request); } - n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap],k_sendlist, - iswap,k_buf_send,pbc_flag[iswap],pbc[iswap]); + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap],k_sendlist_iswap, + k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); if (n) { MPI_Send(k_buf_send.view().data(), n,MPI_DOUBLE,sendproc[iswap],0,world); } - if (size_forward_recv[iswap]) { + if (size_forward_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE); - atomKK->modified(ExecutionSpaceFromDevice:: - space,X_MASK); - } + } else if (ghost_velocity) { if (size_forward_recv[iswap]) { MPI_Irecv(k_buf_recv.view().data(), size_forward_recv[iswap],MPI_DOUBLE, recvproc[iswap],0,world,&request); } - n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist,iswap, + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist_iswap, k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); if (n) { @@ -245,7 +248,8 @@ void CommKokkos::forward_comm_device(int) MPI_Irecv(k_buf_recv.view().data(), size_forward_recv[iswap],MPI_DOUBLE, recvproc[iswap],0,world,&request); - n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap],k_sendlist,iswap, + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap],k_sendlist_iswap, k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); if (n) @@ -257,12 +261,15 @@ void CommKokkos::forward_comm_device(int) } } else { if (!ghost_velocity) { - if (sendnum[iswap]) - n = atomKK->avecKK->pack_comm_self(sendnum[iswap],k_sendlist,iswap, + if (sendnum[iswap]) { + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_self(sendnum[iswap],k_sendlist_iswap, firstrecv[iswap],pbc_flag[iswap],pbc[iswap]); - DeviceType().fence(); + DeviceType().fence(); + } } else { - n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist,iswap, + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist_iswap, k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); atomKK->avecKK->unpack_comm_vel_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_send); @@ -299,10 +306,10 @@ void CommKokkos::reverse_comm() atomKK->modified(Host,F_MASK); else atomKK->modified(Host,ALL_MASK); - - //atomKK->sync(Device,ALL_MASK); // is this needed? } +/* ---------------------------------------------------------------------- */ + template void CommKokkos::reverse_comm_device() { @@ -315,7 +322,6 @@ void CommKokkos::reverse_comm_device() // if comm_f_only set, exchange or copy directly from f, don't pack k_sendlist.sync(); - atomKK->sync(ExecutionSpaceFromDevice::space,F_MASK); for (int iswap = nswap-1; iswap >= 0; iswap--) { if (sendproc[iswap] != me) { @@ -330,11 +336,9 @@ void CommKokkos::reverse_comm_device() MPI_Send(buf,size_reverse_send[iswap],MPI_DOUBLE, recvproc[iswap],0,world); } - if (size_reverse_recv[iswap]) { + if (size_reverse_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE); - atomKK->modified(ExecutionSpaceFromDevice:: - space,F_MASK); - } + } else { if (size_reverse_recv[iswap]) MPI_Irecv(k_buf_recv.view().data(), @@ -347,18 +351,28 @@ void CommKokkos::reverse_comm_device() MPI_DOUBLE,recvproc[iswap],0,world); if (size_reverse_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE); } - atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap],k_sendlist,iswap, + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap],k_sendlist_iswap, k_buf_recv); DeviceType().fence(); } else { - if (sendnum[iswap]) - n = atomKK->avecKK->unpack_reverse_self(sendnum[iswap],k_sendlist,iswap, + if (sendnum[iswap]) { + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_reverse_self(sendnum[iswap],k_sendlist_iswap, firstrecv[iswap]); + } } } } -/* ---------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + forward communication invoked by a Fix + size/nsize used only to set recv buffer limit + size = 0 (default) -> use comm_forward from Fix + size > 0 -> Fix passes max size per atom + the latter is only useful if Fix does several comm modes, + some are smaller than max stored in its comm_forward +------------------------------------------------------------------------- */ void CommKokkos::forward_comm(Fix *fix, int size) { @@ -371,6 +385,8 @@ void CommKokkos::forward_comm(Fix *fix, int size) } } +/* ---------------------------------------------------------------------- */ + template void CommKokkos::forward_comm_device(Fix *fix, int size) { @@ -393,8 +409,9 @@ void CommKokkos::forward_comm_device(Fix *fix, int size) // pack buffer - n = fixKKBase->pack_forward_comm_kokkos(sendnum[iswap],k_sendlist, - iswap,k_buf_send_fix,pbc_flag[iswap],pbc[iswap]); + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = fixKKBase->pack_forward_comm_kokkos(sendnum[iswap],k_sendlist_iswap, + k_buf_send_fix,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); // exchange with another proc @@ -435,7 +452,14 @@ void CommKokkos::forward_comm_device(Fix *fix, int size) } } -/* ---------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + reverse communication invoked by a Fix + size/nsize used only to set recv buffer limit + size = 0 (default) -> use comm_forward from Fix + size > 0 -> Fix passes max size per atom + the latter is only useful if Fix does several comm modes, + some are smaller than max stored in its comm_forward +------------------------------------------------------------------------- */ void CommKokkos::reverse_comm(Fix *fix, int size) { @@ -443,18 +467,66 @@ void CommKokkos::reverse_comm(Fix *fix, int size) CommBrick::reverse_comm(fix, size); } + +/* ---------------------------------------------------------------------- + reverse communication invoked by a Fix with variable size data + query fix for pack size to ensure buf_send is big enough + handshake sizes before each Irecv/Send to ensure buf_recv is big enough +------------------------------------------------------------------------- */ + +void CommKokkos::reverse_comm_variable(Fix *fix) +{ + k_sendlist.sync(); + CommBrick::reverse_comm_variable(fix); +} + +/* ---------------------------------------------------------------------- + forward communication invoked by a Compute + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + void CommKokkos::forward_comm(Compute *compute) { k_sendlist.sync(); CommBrick::forward_comm(compute); } +/* ---------------------------------------------------------------------- + forward communication invoked by a Bond + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + +void CommKokkos::forward_comm(Bond *bond) +{ + CommBrick::forward_comm(bond); +} + +/* ---------------------------------------------------------------------- + reverse communication invoked by a Bond + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + +void CommKokkos::reverse_comm(Bond *bond) +{ + CommBrick::reverse_comm(bond); +} + +/* ---------------------------------------------------------------------- + reverse communication invoked by a Compute + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + void CommKokkos::reverse_comm(Compute *compute) { k_sendlist.sync(); CommBrick::reverse_comm(compute); } +/* ---------------------------------------------------------------------- + forward communication invoked by a Dump + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + void CommKokkos::forward_comm(Pair *pair) { if (pair->execution_space == Host || forward_pair_comm_classic) { @@ -466,6 +538,8 @@ void CommKokkos::forward_comm(Pair *pair) } } +/* ---------------------------------------------------------------------- */ + template void CommKokkos::forward_comm_device(Pair *pair) { @@ -488,8 +562,9 @@ void CommKokkos::forward_comm_device(Pair *pair) // pack buffer - n = pairKKBase->pack_forward_comm_kokkos(sendnum[iswap],k_sendlist, - iswap,k_buf_send_pair,pbc_flag[iswap],pbc[iswap]); + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = pairKKBase->pack_forward_comm_kokkos(sendnum[iswap],k_sendlist_iswap, + k_buf_send_pair,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); // exchange with another proc @@ -530,18 +605,24 @@ void CommKokkos::forward_comm_device(Pair *pair) } } +/* ---------------------------------------------------------------------- */ + void CommKokkos::grow_buf_pair(int n) { max_buf_pair = n * BUFFACTOR; k_buf_send_pair.resize(max_buf_pair); k_buf_recv_pair.resize(max_buf_pair); } +/* ---------------------------------------------------------------------- */ + void CommKokkos::grow_buf_fix(int n) { max_buf_fix = n * BUFFACTOR; k_buf_send_fix.resize(max_buf_fix); k_buf_recv_fix.resize(max_buf_fix); } +/* ---------------------------------------------------------------------- */ + void CommKokkos::reverse_comm(Pair *pair) { if (pair->execution_space == Host || !pair->reverse_comm_device || reverse_pair_comm_classic) { @@ -553,6 +634,8 @@ void CommKokkos::reverse_comm(Pair *pair) } } +/* ---------------------------------------------------------------------- */ + template void CommKokkos::reverse_comm_device(Pair *pair) { @@ -610,18 +693,23 @@ void CommKokkos::reverse_comm_device(Pair *pair) // unpack buffer - pairKKBase->unpack_reverse_comm_kokkos(sendnum[iswap],k_sendlist, - iswap,k_buf_tmp); + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + pairKKBase->unpack_reverse_comm_kokkos(sendnum[iswap],k_sendlist_iswap, + k_buf_tmp); DeviceType().fence(); } } +/* ---------------------------------------------------------------------- */ + void CommKokkos::forward_comm(Dump *dump) { k_sendlist.sync(); CommBrick::forward_comm(dump); } +/* ---------------------------------------------------------------------- */ + void CommKokkos::reverse_comm(Dump *dump) { k_sendlist.sync(); @@ -668,6 +756,7 @@ void CommKokkos::exchange() } } exchange_comm_classic = true; + lmp->kokkos->exchange_comm_classic = 1; } } } @@ -980,6 +1069,7 @@ void CommKokkos::borders() "switching to classic exchange/border communication"); } exchange_comm_classic = true; + lmp->kokkos->exchange_comm_classic = 1; } } @@ -1202,14 +1292,15 @@ void CommKokkos::borders_device() { if (nsend*size_border > maxsend) grow_send_kokkos(nsend*size_border,0); if (ghost_velocity) { + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); n = atomKK->avecKK-> - pack_border_vel_kokkos(nsend,k_sendlist,k_buf_send,iswap, + pack_border_vel_kokkos(nsend,k_sendlist_iswap,k_buf_send, pbc_flag[iswap],pbc[iswap],exec_space); DeviceType().fence(); - } - else { + } else { + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); n = atomKK->avecKK-> - pack_border_kokkos(nsend,k_sendlist,k_buf_send,iswap, + pack_border_kokkos(nsend,k_sendlist_iswap,k_buf_send, pbc_flag[iswap],pbc[iswap],exec_space); DeviceType().fence(); } diff --git a/src/KOKKOS/comm_kokkos.h b/src/KOKKOS/comm_kokkos.h index e06810b939..4fb4dfbe29 100644 --- a/src/KOKKOS/comm_kokkos.h +++ b/src/KOKKOS/comm_kokkos.h @@ -45,18 +45,21 @@ class CommKokkos : public CommBrick { void exchange() override; // move atoms to new procs void borders() override; // setup list of atoms to comm - void forward_comm(class Pair *) override; // forward comm from a Pair - void reverse_comm(class Pair *) override; // reverse comm from a Pair - void forward_comm(class Fix *, int size=0) override; // forward comm from a Fix - void reverse_comm(class Fix *, int size=0) override; // reverse comm from a Fix - void forward_comm(class Compute *) override; // forward from a Compute - void reverse_comm(class Compute *) override; // reverse from a Compute - void forward_comm(class Dump *) override; // forward comm from a Dump - void reverse_comm(class Dump *) override; // reverse comm from a Dump + void forward_comm(class Pair *) override; // forward comm from a Pair + void reverse_comm(class Pair *) override; // reverse comm from a Pair + void forward_comm(class Bond *) override; // forward comm from a Bond + void reverse_comm(class Bond *) override; // reverse comm from a Bond + void forward_comm(class Fix *, int size = 0) override; // forward comm from a Fix + void reverse_comm(class Fix *, int size = 0) override; // reverse comm from a Fix + void reverse_comm_variable(class Fix *) override; // variable size reverse comm from a Fix + void forward_comm(class Compute *) override; // forward from a Compute + void reverse_comm(class Compute *) override; // reverse from a Compute + void forward_comm(class Dump *) override; // forward comm from a Dump + void reverse_comm(class Dump *) override; // reverse comm from a Dump void forward_comm_array(int, double **) override; // forward comm of array - template void forward_comm_device(int dummy); + template void forward_comm_device(); template void reverse_comm_device(); template void forward_comm_device(Pair *pair); template void reverse_comm_device(Pair *pair); @@ -95,7 +98,6 @@ class CommKokkos : public CommBrick { void copy_swap_info(); }; -} +} // namespace LAMMPS_NS #endif - diff --git a/src/KOKKOS/comm_tiled_kokkos.cpp b/src/KOKKOS/comm_tiled_kokkos.cpp index 5b35527b7e..86268301ad 100644 --- a/src/KOKKOS/comm_tiled_kokkos.cpp +++ b/src/KOKKOS/comm_tiled_kokkos.cpp @@ -16,13 +16,28 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "atom_vec.h" +#include "atom_vec_kokkos.h" +#include "compute.h" +#include "dump.h" +#include "fix.h" +#include "force.h" +#include "kokkos.h" +#include "memory_kokkos.h" +#include "modify.h" +#include "output.h" using namespace LAMMPS_NS; +static constexpr double BUFFACTOR = 1.5; +static constexpr int BUFMIN = 1024; +static constexpr int BUFEXTRA = 1000; + /* ---------------------------------------------------------------------- */ -CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) {} +CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) +{ + sendlist = nullptr; +} /* ---------------------------------------------------------------------- */ //IMPORTANT: we *MUST* pass "*oldcomm" to the Comm initializer here, as @@ -31,10 +46,69 @@ CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) {} // The call to Comm::copy_arrays() then converts the shallow copy // into a deep copy of the class with the new layout. -CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp, Comm *oldcomm) : CommTiled(_lmp,oldcomm) {} +CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp, Comm *oldcomm) : CommTiled(_lmp,oldcomm) +{ + sendlist = nullptr; +} /* ---------------------------------------------------------------------- */ +CommTiledKokkos::~CommTiledKokkos() +{ + memoryKK->destroy_kokkos(k_sendlist,sendlist); + sendlist = nullptr; + buf_send = nullptr; + buf_recv = nullptr; +} + +/* ---------------------------------------------------------------------- */ + +void CommTiledKokkos::init() +{ + atomKK = (AtomKokkos *) atom; + exchange_comm_classic = lmp->kokkos->exchange_comm_classic; + forward_comm_classic = lmp->kokkos->forward_comm_classic; + forward_pair_comm_classic = lmp->kokkos->forward_pair_comm_classic; + reverse_pair_comm_classic = lmp->kokkos->reverse_pair_comm_classic; + forward_fix_comm_classic = lmp->kokkos->forward_fix_comm_classic; + reverse_comm_classic = lmp->kokkos->reverse_comm_classic; + exchange_comm_on_host = lmp->kokkos->exchange_comm_on_host; + forward_comm_on_host = lmp->kokkos->forward_comm_on_host; + reverse_comm_on_host = lmp->kokkos->reverse_comm_on_host; + + CommTiled::init(); + + int check_forward = 0; + int check_reverse = 0; + if (force->pair && (force->pair->execution_space == Host)) + check_forward += force->pair->comm_forward; + if (force->pair && (force->pair->execution_space == Host)) + check_reverse += force->pair->comm_reverse; + + for (const auto &fix : modify->get_fix_list()) { + check_forward += fix->comm_forward; + check_reverse += fix->comm_reverse; + } + + for (const auto &compute : modify->get_compute_list()) { + check_forward += compute->comm_forward; + check_reverse += compute->comm_reverse; + } + + for (const auto &dump : output->get_dump_list()) { + check_forward += dump->comm_forward; + check_reverse += dump->comm_reverse; + } + + if (force->newton == 0) check_reverse = 0; + if (force->pair) check_reverse += force->pair->comm_reverse_off; + + if (!comm_f_only) { // not all Kokkos atom_vec styles have reverse pack/unpack routines yet + reverse_comm_classic = true; + lmp->kokkos->reverse_comm_classic = 1; + } +} + /* ---------------------------------------------------------------------- forward communication of atom coords every timestep other per-atom attributes may also be sent via pack/unpack routines @@ -42,6 +116,14 @@ CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp, Comm *oldcomm) : CommTiled(_lmp,o void CommTiledKokkos::forward_comm(int dummy) { + if (!forward_comm_classic) { + if (forward_comm_on_host) forward_comm_device(); + else forward_comm_device(); + return; + } + + k_sendlist.sync(); + if (comm_x_only) { atomKK->sync(Host,X_MASK); atomKK->modified(Host,X_MASK); @@ -56,6 +138,127 @@ void CommTiledKokkos::forward_comm(int dummy) CommTiled::forward_comm(dummy); } +/* ---------------------------------------------------------------------- */ + +template +void CommTiledKokkos::forward_comm_device() +{ + int i,irecv,n,nsend,nrecv; + double *buf; + + // exchange data with another set of procs in each swap + // post recvs from all procs except self + // send data to all procs except self + // copy data to self if sendself is set + // wait on all procs except self and unpack received data + // if comm_x_only set, exchange or copy directly to x, don't unpack + + k_sendlist.sync(); + + for (int iswap = 0; iswap < nswap; iswap++) { + nsend = nsendproc[iswap] - sendself[iswap]; + nrecv = nrecvproc[iswap] - sendself[iswap]; + + if (comm_x_only) { + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + buf = atomKK->k_x.view().data() + + firstrecv[iswap][i]*atomKK->k_x.view().extent(1); + MPI_Irecv(buf,size_forward_recv[iswap][i], + MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]); + } + } + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,i,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap][i],k_sendlist_small, + k_buf_send,pbc_flag[iswap][i],pbc[iswap][i]); + DeviceType().fence(); + MPI_Send(k_buf_send.view().data(),n,MPI_DOUBLE,sendproc[iswap][i],0,world); + } + } + if (sendself[iswap]) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,nsend,Kokkos::ALL); + atomKK->avecKK->pack_comm_self(sendnum[iswap][nsend],k_sendlist_small, + firstrecv[iswap][nrecv],pbc_flag[iswap][nsend],pbc[iswap][nsend]); + DeviceType().fence(); + } + if (recvother[iswap]) MPI_Waitall(nrecv,requests,MPI_STATUS_IGNORE); + + } else if (ghost_velocity) { + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + buf = k_buf_recv.view().data() + + forward_recv_offset[iswap][i]*k_buf_recv.view().extent(1); + MPI_Irecv(buf, + size_forward_recv[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]); + } + } + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,i,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap][i],k_sendlist_small, + k_buf_send,pbc_flag[iswap][i],pbc[iswap][i]); + DeviceType().fence(); + MPI_Send(k_buf_send.view().data(),n, + MPI_DOUBLE,sendproc[iswap][i],0,world); + } + } + if (sendself[iswap]) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,nsend,Kokkos::ALL); + atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap][nsend],k_sendlist_small, + k_buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]); + DeviceType().fence(); + atomKK->avecKK->unpack_comm_vel_kokkos(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],k_buf_send); + DeviceType().fence(); + } + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(forward_recv_offset[iswap][irecv],(int)k_buf_recv.extent(1)),Kokkos::ALL); + atomKK->avecKK->unpack_comm_vel_kokkos(recvnum[iswap][irecv],firstrecv[iswap][irecv], + k_buf_recv_offset); + DeviceType().fence(); + } + } + + } else { + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + buf = k_buf_recv.view().data() + + forward_recv_offset[iswap][i]*k_buf_recv.view().extent(1); + MPI_Irecv(buf, + size_forward_recv[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]); + } + } + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,i,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap][i],k_sendlist_small, + k_buf_send,pbc_flag[iswap][i],pbc[iswap][i]); + DeviceType().fence(); + MPI_Send(k_buf_send.view().data(),n,MPI_DOUBLE,sendproc[iswap][i],0,world); + } + } + if (sendself[iswap]) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,nsend,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap][nsend],k_sendlist_small, + k_buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]); + DeviceType().fence(); + } + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(forward_recv_offset[iswap][irecv],(int)k_buf_recv.extent(1)),Kokkos::ALL); + atomKK->avecKK->unpack_comm_kokkos(recvnum[iswap][irecv],firstrecv[iswap][irecv], + k_buf_recv_offset); + DeviceType().fence(); + } + } + } + } +} + /* ---------------------------------------------------------------------- reverse communication of forces on atoms every timestep other per-atom attributes may also be sent via pack/unpack routines @@ -63,16 +266,118 @@ void CommTiledKokkos::forward_comm(int dummy) void CommTiledKokkos::reverse_comm() { + if (!reverse_comm_classic) { + if (reverse_comm_on_host) reverse_comm_device(); + else reverse_comm_device(); + return; + } + + k_sendlist.sync(); + if (comm_f_only) atomKK->sync(Host,F_MASK); else atomKK->sync(Host,ALL_MASK); + CommTiled::reverse_comm(); + if (comm_f_only) atomKK->modified(Host,F_MASK); else atomKK->modified(Host,ALL_MASK); - atomKK->sync(Device,ALL_MASK); +} + +/* ---------------------------------------------------------------------- */ + +template +void CommTiledKokkos::reverse_comm_device() +{ + int i,irecv,n,nsend,nrecv; + MPI_Request request; + double *buf; + + // exchange data with another set of procs in each swap + // post recvs from all procs except self + // send data to all procs except self + // copy data to self if sendself is set + // wait on all procs except self and unpack received data + // if comm_f_only set, exchange or copy directly from f, don't pack + + k_sendlist.sync(); + + for (int iswap = nswap-1; iswap >= 0; iswap--) { + nsend = nsendproc[iswap] - sendself[iswap]; + nrecv = nrecvproc[iswap] - sendself[iswap]; + + if (comm_f_only) { + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + buf = k_buf_recv.view().data() + + reverse_recv_offset[iswap][i]*k_buf_recv.view().extent(1); + MPI_Irecv(buf, + size_reverse_recv[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world,&requests[i]); + } + } + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + buf = atomKK->k_f.view().data() + + firstrecv[iswap][i]*atomKK->k_f.view().extent(1); + MPI_Send(buf,size_reverse_send[iswap][i], + MPI_DOUBLE,recvproc[iswap][i],0,world); + } + } + if (sendself[iswap]) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,nsend,Kokkos::ALL); + atomKK->avecKK->pack_reverse_self(sendnum[iswap][nsend],k_sendlist_small, + firstrecv[iswap][nrecv]); + DeviceType().fence(); + } + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE); + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,irecv,Kokkos::ALL); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(reverse_recv_offset[iswap][irecv],(int)k_buf_recv.extent(1)),Kokkos::ALL); + atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap][irecv],k_sendlist_small, + k_buf_recv_offset); + DeviceType().fence(); + } + } + + } else { + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + buf = k_buf_recv.view().data() + + reverse_recv_offset[iswap][i]*k_buf_recv.view().extent(1); + MPI_Irecv(buf, + size_reverse_recv[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world,&requests[i]); + } + } + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + n = atomKK->avecKK->pack_reverse_kokkos(recvnum[iswap][i],firstrecv[iswap][i],k_buf_send); + DeviceType().fence(); + MPI_Send(k_buf_send.view().data(),n,MPI_DOUBLE,recvproc[iswap][i],0,world); + } + } + if (sendself[iswap]) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,nsend,Kokkos::ALL); + atomKK->avecKK->pack_reverse_kokkos(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],k_buf_send); + DeviceType().fence(); + atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap][nsend],k_sendlist_small,k_buf_send); + DeviceType().fence(); + } + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE); + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,irecv,Kokkos::ALL); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(reverse_recv_offset[iswap][irecv],(int)k_buf_recv.extent(1)),Kokkos::ALL); + atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap][irecv],k_sendlist_small, + k_buf_recv_offset); + DeviceType().fence(); + } + } + } + } } /* ---------------------------------------------------------------------- @@ -108,6 +413,7 @@ void CommTiledKokkos::borders() atomKK->sync(Host,ALL_MASK); CommTiled::borders(); atomKK->modified(Host,ALL_MASK); + k_sendlist.modify_host(); } /* ---------------------------------------------------------------------- @@ -130,6 +436,26 @@ void CommTiledKokkos::reverse_comm(Pair *pair) CommTiled::reverse_comm(pair); } +/* ---------------------------------------------------------------------- + forward communication invoked by a Bond + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + +void CommTiledKokkos::forward_comm(Bond *bond) +{ + CommTiled::forward_comm(bond); +} + +/* ---------------------------------------------------------------------- + reverse communication invoked by a Bond + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + +void CommTiledKokkos::reverse_comm(Bond *bond) +{ + CommTiled::reverse_comm(bond); +} + /* ---------------------------------------------------------------------- forward communication invoked by a Fix size/nsize used only to set recv buffer limit @@ -218,3 +544,145 @@ void CommTiledKokkos::forward_comm_array(int nsize, double **array) { CommTiled::forward_comm_array(nsize,array); } + +/* ---------------------------------------------------------------------- + realloc the size of the send buffer as needed with BUFFACTOR and bufextra + if flag = 1, realloc + if flag = 0, don't need to realloc with copy, just free/malloc +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_send(int n, int flag) +{ + grow_send_kokkos(n,flag,Host); +} + +/* ---------------------------------------------------------------------- + free/malloc the size of the recv buffer as needed with BUFFACTOR +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_recv(int n, int flag) +{ + grow_recv_kokkos(n,flag,Host); +} + +/* ---------------------------------------------------------------------- + realloc the size of the send buffer as needed with BUFFACTOR & BUFEXTRA + if flag = 1, realloc + if flag = 0, don't need to realloc with copy, just free/malloc +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_send_kokkos(int n, int flag, ExecutionSpace space) +{ + + maxsend = static_cast (BUFFACTOR * n); + int maxsend_border = (maxsend+BUFEXTRA)/atomKK->avecKK->size_border; + if (flag) { + if (space == Device) + k_buf_send.modify(); + else + k_buf_send.modify(); + + if (ghost_velocity) + k_buf_send.resize(maxsend_border, + atomKK->avecKK->size_border + atomKK->avecKK->size_velocity); + else + k_buf_send.resize(maxsend_border,atomKK->avecKK->size_border); + buf_send = k_buf_send.view().data(); + } else { + if (ghost_velocity) + MemoryKokkos::realloc_kokkos(k_buf_send,"comm:k_buf_send",maxsend_border, + atomKK->avecKK->size_border + atomKK->avecKK->size_velocity); + else + MemoryKokkos::realloc_kokkos(k_buf_send,"comm:k_buf_send",maxsend_border, + atomKK->avecKK->size_border); + buf_send = k_buf_send.view().data(); + } +} + +/* ---------------------------------------------------------------------- + free/malloc the size of the recv buffer as needed with BUFFACTOR +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_recv_kokkos(int n, int flag, ExecutionSpace /*space*/) +{ + if (flag) maxrecv = n; + else maxrecv = static_cast (BUFFACTOR * n); + + int maxrecv_border = (maxrecv+BUFEXTRA)/atomKK->avecKK->size_border; + + MemoryKokkos::realloc_kokkos(k_buf_recv,"comm:k_buf_recv",maxrecv_border, + atomKK->avecKK->size_border); + buf_recv = k_buf_recv.view().data(); +} + +/* ---------------------------------------------------------------------- + realloc the size of the iswap sendlist as needed with BUFFACTOR +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_list(int iswap, int iwhich, int n) +{ + int size = static_cast (BUFFACTOR * n); + + if (exchange_comm_classic) { // force realloc on Host + k_sendlist.sync(); + k_sendlist.modify(); + } + + int nsend = k_sendlist.extent(1); + + if (size > k_sendlist.extent(2)) { + memoryKK->grow_kokkos(k_sendlist,sendlist,maxswap,maxsend,size,"comm:sendlist"); + + for (int i = 0; i < maxswap; i++) + maxsendlist[iswap][iwhich] = size; + } +} + +/* ---------------------------------------------------------------------- + grow info for swap I, to allow for N procs to communicate with + ditto for complementary recv for swap I+1 or I-1, as invoked by caller +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_swap_send(int i, int n, int nold) +{ + delete [] sendproc[i]; + sendproc[i] = new int[n]; + delete [] sendnum[i]; + sendnum[i] = new int[n]; + + delete [] size_reverse_recv[i]; + size_reverse_recv[i] = new int[n]; + delete [] reverse_recv_offset[i]; + reverse_recv_offset[i] = new int[n]; + + delete [] pbc_flag[i]; + pbc_flag[i] = new int[n]; + memory->destroy(pbc[i]); + memory->create(pbc[i],n,6,"comm:pbc_flag"); + memory->destroy(sendbox[i]); + memory->create(sendbox[i],n,6,"comm:sendbox"); + grow_swap_send_multi(i,n); + memory->destroy(sendbox_multiold[i]); + memory->create(sendbox_multiold[i],n,atom->ntypes+1,6,"comm:sendbox_multiold"); + + delete [] maxsendlist[i]; + maxsendlist[i] = new int[n]; + + for (int j = 0; j < n; j++) + maxsendlist[i][j] = BUFMIN; + + if (sendlist && !k_sendlist.d_view.data()) { + for (int ii = 0; ii < maxswap; ii++) { + if (sendlist[ii]) { + for (int jj = 0; jj < nprocmax[ii]; jj++) + memory->destroy(sendlist[ii][jj]); + delete [] sendlist[ii]; + } + } + delete [] sendlist; + } else { + memoryKK->destroy_kokkos(k_sendlist,sendlist); + } + + memoryKK->create_kokkos(k_sendlist,sendlist,maxswap,n,BUFMIN,"comm:sendlist"); +} diff --git a/src/KOKKOS/comm_tiled_kokkos.h b/src/KOKKOS/comm_tiled_kokkos.h index c80436b454..eba453b49e 100644 --- a/src/KOKKOS/comm_tiled_kokkos.h +++ b/src/KOKKOS/comm_tiled_kokkos.h @@ -25,28 +25,59 @@ class CommTiledKokkos : public CommTiled { CommTiledKokkos(class LAMMPS *); CommTiledKokkos(class LAMMPS *, class Comm *); + ~CommTiledKokkos() override; + + bool exchange_comm_classic; + bool forward_comm_classic; + bool forward_pair_comm_classic; + bool reverse_pair_comm_classic; + bool forward_fix_comm_classic; + bool reverse_comm_classic; + bool exchange_comm_on_host; + bool forward_comm_on_host; + bool reverse_comm_on_host; + using CommTiled::forward_comm; using CommTiled::reverse_comm; + + void init() override; void forward_comm(int dummy = 0) override; // forward comm of atom coords void reverse_comm() override; // reverse comm of forces void exchange() override; // move atoms to new procs void borders() override; // setup list of atoms to comm - void forward_comm(class Pair *) override; // forward comm from a Pair - void reverse_comm(class Pair *) override; // reverse comm from a Pair - void forward_comm(class Fix *, int size=0) override; - // forward comm from a Fix - void reverse_comm(class Fix *, int size=0) override; - // reverse comm from a Fix - void reverse_comm_variable(class Fix *) override; - // variable size reverse comm from a Fix - void forward_comm(class Compute *) override; // forward from a Compute - void reverse_comm(class Compute *) override; // reverse from a Compute - void forward_comm(class Dump *) override; // forward comm from a Dump - void reverse_comm(class Dump *) override; // reverse comm from a Dump + void forward_comm(class Pair *) override; // forward comm from a Pair + void reverse_comm(class Pair *) override; // reverse comm from a Pair + void forward_comm(class Bond *) override; // forward comm from a Bond + void reverse_comm(class Bond *) override; // reverse comm from a Bond + void forward_comm(class Fix *, int size = 0) override; // forward comm from a Fix + void reverse_comm(class Fix *, int size = 0) override; // reverse comm from a Fix + void reverse_comm_variable(class Fix *) override; // variable size reverse comm from a Fix + void forward_comm(class Compute *) override; // forward from a Compute + void reverse_comm(class Compute *) override; // reverse from a Compute + void forward_comm(class Dump *) override; // forward comm from a Dump + void reverse_comm(class Dump *) override; // reverse comm from a Dump void forward_comm_array(int, double **) override; // forward comm of array -}; -} -#endif + template void forward_comm_device(); + template void reverse_comm_device(); + + protected: + + DAT::tdual_int_3d k_sendlist; + //DAT::tdual_int_scalar k_total_send; + DAT::tdual_xfloat_2d k_buf_send,k_buf_recv; + //DAT::tdual_int_scalar k_count; + + void grow_send(int, int) override; + void grow_recv(int, int flag = 0) override; + void grow_send_kokkos(int, int, ExecutionSpace space = Host); + void grow_recv_kokkos(int, int, ExecutionSpace space = Host); + void grow_list(int, int, int) override; + void grow_swap_send(int, int, int); // grow swap arrays for send and recv +}; + +} // namespace LAMMPS_NS + +#endif diff --git a/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp b/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp index 617660d5ef..dabab9405b 100644 --- a/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp +++ b/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp @@ -536,7 +536,7 @@ void FixACKS2ReaxFFKokkos::deallocate_array() { memoryKK->destroy_kokkos(k_s,s); memoryKK->destroy_kokkos(k_chi_field,chi_field); - memoryKK->destroy_kokkos(X_diag); + memoryKK->destroy_kokkos(k_X_diag,X_diag); memoryKK->destroy_kokkos(k_d,d); memoryKK->destroy_kokkos(k_q_hat,q_hat); memoryKK->destroy_kokkos(k_y,y); diff --git a/src/KOKKOS/fix_acks2_reaxff_kokkos.h b/src/KOKKOS/fix_acks2_reaxff_kokkos.h index c27719c364..cb16b4cd24 100644 --- a/src/KOKKOS/fix_acks2_reaxff_kokkos.h +++ b/src/KOKKOS/fix_acks2_reaxff_kokkos.h @@ -246,9 +246,8 @@ class FixACKS2ReaxFFKokkos : public FixACKS2ReaxFF, public KokkosBase { int count, isuccess; double alpha, beta, omega, cutsq; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; void grow_arrays(int) override; diff --git a/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp b/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp index ba25d79ad5..225ec2a211 100644 --- a/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp +++ b/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp @@ -1117,12 +1117,11 @@ void FixQEqReaxFFKokkos::operator()(TagQEqCalculateQ, const int &ii) /* ---------------------------------------------------------------------- */ template -int FixQEqReaxFFKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &k_buf, +int FixQEqReaxFFKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &k_buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; d_buf = k_buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); if (pack_flag == 3) return n; @@ -1134,7 +1133,7 @@ int FixQEqReaxFFKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_i template KOKKOS_INLINE_FUNCTION void FixQEqReaxFFKokkos::operator()(TagQEqPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); if (pack_flag == 1) { if (!(converged & 1)) diff --git a/src/KOKKOS/fix_qeq_reaxff_kokkos.h b/src/KOKKOS/fix_qeq_reaxff_kokkos.h index 6aa345fba6..92026b209d 100644 --- a/src/KOKKOS/fix_qeq_reaxff_kokkos.h +++ b/src/KOKKOS/fix_qeq_reaxff_kokkos.h @@ -154,7 +154,7 @@ class FixQEqReaxFFKokkos : public FixQEqReaxFF, public KokkosBase { F_FLOAT chi, eta, gamma; }; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -255,9 +255,9 @@ class FixQEqReaxFFKokkos : public FixQEqReaxFF, public KokkosBase { DupScatterView dup_o; NonDupScatterView ndup_o; - int iswap,nsend; + int nsend; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d d_buf; typename AT::t_int_1d d_copylist; typename AT::t_int_1d d_indices; diff --git a/src/KOKKOS/fix_rx_kokkos.cpp b/src/KOKKOS/fix_rx_kokkos.cpp index 0ba56c611e..7c67cc8b96 100644 --- a/src/KOKKOS/fix_rx_kokkos.cpp +++ b/src/KOKKOS/fix_rx_kokkos.cpp @@ -85,9 +85,6 @@ FixRxKokkos::~FixRxKokkos() memoryKK->destroy_kokkos(k_dpdThetaLocal, dpdThetaLocal); memoryKK->destroy_kokkos(k_sumWeights, sumWeights); - memoryKK->destroy_kokkos(d_scratchSpace); - - memoryKK->destroy_kokkos(k_cutsq); } /* ---------------------------------------------------------------------- */ @@ -1463,8 +1460,8 @@ void FixRxKokkos::solve_reactions(const int /*vflag*/, const bool is this->scratchSpaceSize = (8*nspecies + 2*nreactions); if (nlocal*scratchSpaceSize > d_scratchSpace.extent(0)) { - memoryKK->destroy_kokkos (d_scratchSpace); - memoryKK->create_kokkos (d_scratchSpace, nlocal*scratchSpaceSize, "FixRxKokkos::d_scratchSpace"); + d_scratchSpace = typename AT::t_double_1d(); + d_scratchSpace = typename AT::t_double_1d("FixRxKokkos::d_scratchSpace", nlocal*scratchSpaceSize); } if (setRatesToZero) @@ -1822,8 +1819,8 @@ void FixRxKokkos::computeLocalTemperature() const int ntypes = atom->ntypes; if (ntypes+1 > (int) k_cutsq.extent(0)) { - memoryKK->destroy_kokkos (k_cutsq); - memoryKK->create_kokkos (k_cutsq, ntypes+1, ntypes+1, "FixRxKokkos::k_cutsq"); + k_cutsq = typename AT::tdual_ffloat_2d(); + k_cutsq = typename AT::tdual_ffloat_2d("FixRxKokkos::k_cutsq", ntypes+1, ntypes+1); d_cutsq = k_cutsq.template view(); } @@ -1843,7 +1840,7 @@ void FixRxKokkos::computeLocalTemperature() if (sumWeightsCt > (int)k_sumWeights.template view().extent(0)) { memoryKK->destroy_kokkos(k_sumWeights, sumWeights); - memoryKK->create_kokkos (k_sumWeights, sumWeightsCt, "FixRxKokkos::sumWeights"); + memoryKK->create_kokkos(k_sumWeights, sumWeights, sumWeightsCt, "FixRxKokkos::sumWeights"); d_sumWeights = k_sumWeights.template view(); h_sumWeights = k_sumWeights.h_view; } diff --git a/src/KOKKOS/fix_shake_kokkos.cpp b/src/KOKKOS/fix_shake_kokkos.cpp index 791738e5a4..28f0098410 100644 --- a/src/KOKKOS/fix_shake_kokkos.cpp +++ b/src/KOKKOS/fix_shake_kokkos.cpp @@ -1808,12 +1808,11 @@ int FixShakeKokkos::unpack_exchange(int nlocal, double *buf) /* ---------------------------------------------------------------------- */ template -int FixShakeKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &k_buf, - int pbc_flag, int* pbc) +int FixShakeKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &k_buf, + int pbc_flag, int* pbc) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; d_buf = k_buf.view(); if (domain->triclinic == 0) { @@ -1837,7 +1836,7 @@ template template KOKKOS_INLINE_FUNCTION void FixShakeKokkos::operator()(TagFixShakePackForwardComm, const int &i) const { - const int j = d_sendlist(iswap, i); + const int j = d_sendlist(i); if (PBC_FLAG == 0) { d_buf[3*i] = d_xshake(j,0); diff --git a/src/KOKKOS/fix_shake_kokkos.h b/src/KOKKOS/fix_shake_kokkos.h index 19f3a2343d..31a6c340be 100644 --- a/src/KOKKOS/fix_shake_kokkos.h +++ b/src/KOKKOS/fix_shake_kokkos.h @@ -66,7 +66,7 @@ class FixShakeKokkos : public FixShake, public KokkosBase { int pack_exchange(int, double *) override; int unpack_exchange(int, double *) override; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -211,9 +211,9 @@ class FixShakeKokkos : public FixShake, public KokkosBase { KOKKOS_INLINE_FUNCTION void v_tally(EV_FLOAT&, int, int *, double, double *) const; - int iswap,first,nsend; + int first,nsend; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um d_buf; typename AT::t_int_1d d_exchange_sendlist; diff --git a/src/KOKKOS/fix_wall_lj93_kokkos.cpp b/src/KOKKOS/fix_wall_lj93_kokkos.cpp index dff47f1c30..b98c4354f6 100644 --- a/src/KOKKOS/fix_wall_lj93_kokkos.cpp +++ b/src/KOKKOS/fix_wall_lj93_kokkos.cpp @@ -51,8 +51,6 @@ void FixWallLJ93Kokkos::wall_particle(int m_in, int which, double co x = atomKK->k_x.view(); f = atomKK->k_f.view(); mask = atomKK->k_mask.view(); - DAT::tdual_int_scalar k_oneflag = DAT::tdual_int_scalar("fix:oneflag"); - d_oneflag = k_oneflag.view(); int nlocal = atom->nlocal; @@ -66,10 +64,6 @@ void FixWallLJ93Kokkos::wall_particle(int m_in, int which, double co copymode = 0; atomKK->modified(execution_space, F_MASK); - - k_oneflag.template modify(); - k_oneflag.template sync(); - if (k_oneflag.h_view()) error->one(FLERR,"Particle on or inside fix wall surface"); } template @@ -80,10 +74,8 @@ void FixWallLJ93Kokkos::wall_particle_item(int i, value_type ewall) if (side < 0) delta = x(i,dim) - coord; else delta = coord - x(i,dim); if (delta >= cutoff[m]) return; - if (delta <= 0.0) { - d_oneflag() = 1; - return; - } + if (delta <= 0.0) + Kokkos::abort("Particle on or inside fix wall surface"); double rinv = 1.0/delta; double r2inv = rinv*rinv; double r4inv = r2inv*r2inv; diff --git a/src/KOKKOS/fix_wall_lj93_kokkos.h b/src/KOKKOS/fix_wall_lj93_kokkos.h index 2bc78f3781..720e586f5d 100644 --- a/src/KOKKOS/fix_wall_lj93_kokkos.h +++ b/src/KOKKOS/fix_wall_lj93_kokkos.h @@ -50,7 +50,6 @@ class FixWallLJ93Kokkos : public FixWallLJ93 { typename AT::t_x_array x; typename AT::t_f_array f; typename AT::t_int_1d mask; - typename AT::t_int_scalar d_oneflag; }; template diff --git a/src/KOKKOS/kokkos_base.h b/src/KOKKOS/kokkos_base.h index 24fcc47579..22ed1687a9 100644 --- a/src/KOKKOS/kokkos_base.h +++ b/src/KOKKOS/kokkos_base.h @@ -26,18 +26,18 @@ class KokkosBase { KokkosBase() {} // Pair - virtual int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, - int, DAT::tdual_xfloat_1d &, + virtual int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, + DAT::tdual_xfloat_1d &, int, int *) {return 0;}; virtual void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d &) {} virtual int pack_reverse_comm_kokkos(int, int, DAT::tdual_xfloat_1d &) {return 0;}; - virtual void unpack_reverse_comm_kokkos(int, DAT::tdual_int_2d, - int, DAT::tdual_xfloat_1d &) {} + virtual void unpack_reverse_comm_kokkos(int, DAT::tdual_int_1d, + DAT::tdual_xfloat_1d &) {} // Fix - virtual int pack_forward_comm_fix_kokkos(int, DAT::tdual_int_2d, - int, DAT::tdual_xfloat_1d &, + virtual int pack_forward_comm_fix_kokkos(int, DAT::tdual_int_1d, + DAT::tdual_xfloat_1d &, int, int *) {return 0;}; virtual void unpack_forward_comm_fix_kokkos(int, int, DAT::tdual_xfloat_1d &) {} diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index 1009e43196..cc4e00819f 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -689,6 +689,14 @@ typedef tdual_int_2d_dl::t_dev_um t_int_2d_um_dl; typedef tdual_int_2d_dl::t_dev_const_um t_int_2d_const_um_dl; typedef tdual_int_2d_dl::t_dev_const_randomread t_int_2d_randomread_dl; +typedef Kokkos:: + DualView tdual_int_3d; +typedef tdual_int_3d::t_dev t_int_3d; +typedef tdual_int_3d::t_dev_const t_int_3d_const; +typedef tdual_int_3d::t_dev_um t_int_3d_um; +typedef tdual_int_3d::t_dev_const_um t_int_3d_const_um; +typedef tdual_int_3d::t_dev_const_randomread t_int_3d_randomread; + typedef Kokkos:: DualView tdual_tagint_1d; @@ -1006,6 +1014,13 @@ typedef tdual_int_2d_dl::t_host_um t_int_2d_um_dl; typedef tdual_int_2d_dl::t_host_const_um t_int_2d_const_um_dl; typedef tdual_int_2d_dl::t_host_const_randomread t_int_2d_randomread_dl; +typedef Kokkos::DualView tdual_int_3d; +typedef tdual_int_3d::t_host t_int_3d; +typedef tdual_int_3d::t_host_const t_int_3d_const; +typedef tdual_int_3d::t_host_um t_int_3d_um; +typedef tdual_int_3d::t_host_const_um t_int_3d_const_um; +typedef tdual_int_3d::t_host_const_randomread t_int_3d_randomread; + typedef Kokkos::DualView tdual_tagint_1d; typedef tdual_tagint_1d::t_host t_tagint_1d; typedef tdual_tagint_1d::t_host_const t_tagint_1d_const; diff --git a/src/KOKKOS/memory_kokkos.h b/src/KOKKOS/memory_kokkos.h index 9d894a344a..0cf5b0d51a 100644 --- a/src/KOKKOS/memory_kokkos.h +++ b/src/KOKKOS/memory_kokkos.h @@ -65,8 +65,7 @@ template } /* ---------------------------------------------------------------------- - grow or shrink 1st dim of a 1d array - last dim must stay the same + grow or shrink a 1d array ------------------------------------------------------------------------- */ template @@ -80,6 +79,10 @@ TYPE grow_kokkos(TYPE &data, typename TYPE::value_type *&array, return data; } +/* ---------------------------------------------------------------------- + destroy a 1d array +------------------------------------------------------------------------- */ + template void destroy_kokkos(TYPE data, typename TYPE::value_type* &array) { @@ -92,71 +95,6 @@ void destroy_kokkos(TYPE data, typename TYPE::value_type* &array) create a 2d array ------------------------------------------------------------------------- */ -template -TYPE destroy_kokkos(TYPE &data) -{ - /*if (data.data()!=nullptr) - free(data.data());*/ - data = TYPE(); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name),n1); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, int n2, const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*n2*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name),n1,n2); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, int n2, int n3 ,const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*n2*n3*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name),n1,n2,n3); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4 ,const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*n2*n3*n4*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name),n1,n2,n3,n4); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4, int n5 ,const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*n2*n3*n4*n5*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name),n1,n2,n3,n4,n5); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4, int n5 , int n6 ,const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*n2*n3*n4*n5*n6*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name) ,n1,n2,n3,n4,n5,n6); - return data; -} - - - template TYPE create_kokkos(TYPE &data, HTYPE &h_data, int n1, int n2, const char *name) @@ -202,27 +140,94 @@ template return data; } -template - TYPE create_kokkos(TYPE &data, HTYPE &h_data, int n1, int n2, int n3, - const char *name) +template +TYPE create_kokkos(TYPE &data, typename TYPE::value_type **&array, + int n1, const char *name) { - data = TYPE(std::string(name),n1,n2,n3); - h_data = Kokkos::create_mirror_view(data); + data = TYPE(std::string(name),n1); + bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; + array = (typename TYPE::value_type **) smalloc(nbytes,name); + + for (int i = 0; i < n1; i++) + if (data.h_view.extent(1) == 0) + array[i] = nullptr; + else + array[i] = &data.h_view(i,0); + + return data; +} + +/* ---------------------------------------------------------------------- + grow or shrink a 2d array +------------------------------------------------------------------------- */ + +template +TYPE grow_kokkos(TYPE &data, typename TYPE::value_type **&array, + int n1, int n2, const char *name) +{ + if (array == nullptr) return create_kokkos(data,array,n1,n2,name); + data.resize(n1,n2); + bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; + array = (typename TYPE::value_type**) srealloc(array,nbytes,name); + + for (int i = 0; i < n1; i++) + if (n2 == 0) + array[i] = nullptr; + else + array[i] = &data.h_view(i,0); + return data; } +template +TYPE grow_kokkos(TYPE &data, typename TYPE::value_type **&array, + int n1, const char *name) +{ + if (array == nullptr) return create_kokkos(data,array,n1,name); + + data.resize(n1); + + bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; + array = (typename TYPE::value_type **) srealloc(array,nbytes,name); + + for (int i = 0; i < n1; i++) + if (data.h_view.extent(1) == 0) + array[i] = nullptr; + else + array[i] = &data.h_view(i,0); + + return data; +} + +/* ---------------------------------------------------------------------- + destroy a 2d array +------------------------------------------------------------------------- */ + +template +void destroy_kokkos(TYPE data, typename TYPE::value_type** &array) +{ + if (array == nullptr) return; + data = TYPE(); + sfree(array); + array = nullptr; +} + +/* ---------------------------------------------------------------------- + create a 3d array +------------------------------------------------------------------------- */ + template TYPE create_kokkos(TYPE &data, typename TYPE::value_type ***&array, int n1, int n2, int n3, const char *name) -{ - data = TYPE(std::string(name),n1,n2); +{ + data = TYPE(std::string(name),n1,n2,n3); bigint nbytes = ((bigint) sizeof(typename TYPE::value_type **)) * n1; array = (typename TYPE::value_type ***) smalloc(nbytes,name); - + for (int i = 0; i < n1; i++) { if (n2 == 0) { array[i] = nullptr; - } else { + } else { nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n2; array[i] = (typename TYPE::value_type **) smalloc(nbytes,name); for (int j = 0; j < n2; j++) { @@ -263,79 +268,46 @@ template return data; } +template + TYPE create_kokkos(TYPE &data, HTYPE &h_data, int n1, int n2, int n3, + const char *name) +{ + data = TYPE(std::string(name),n1,n2,n3); + h_data = Kokkos::create_mirror_view(data); + return data; +} + + /* ---------------------------------------------------------------------- - grow or shrink 1st dim of a 2d array - last dim must stay the same + grow or shrink a 3d array ------------------------------------------------------------------------- */ template -TYPE grow_kokkos(TYPE &data, typename TYPE::value_type **&array, - int n1, int n2, const char *name) +TYPE grow_kokkos(TYPE &data, typename TYPE::value_type ***&array, + int n1, int n2, int n3, const char *name) { - if (array == nullptr) return create_kokkos(data,array,n1,n2,name); - data.resize(n1,n2); - bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; - array = (typename TYPE::value_type**) srealloc(array,nbytes,name); + if (array == nullptr) return create_kokkos(data,array,n1,n2,n3,name); + data.resize(n1,n2,n3); + bigint nbytes = ((bigint) sizeof(typename TYPE::value_type **)) * n1; + array = (typename TYPE::value_type ***) smalloc(nbytes,name); - for (int i = 0; i < n1; i++) - if (n2 == 0) + for (int i = 0; i < n1; i++) { + if (n2 == 0) { array[i] = nullptr; - else - array[i] = &data.h_view(i,0); - + } else { + nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n2; + array[i] = (typename TYPE::value_type **) smalloc(nbytes,name); + for (int j = 0; j < n2; j++) { + if (n3 == 0) + array[i][j] = nullptr; + else + array[i][j] = &data.h_view(i,j,0); + } + } + } return data; } -template -TYPE create_kokkos(TYPE &data, typename TYPE::value_type **&array, - int n1, const char *name) -{ - data = TYPE(std::string(name),n1); - bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; - array = (typename TYPE::value_type **) smalloc(nbytes,name); - - for (int i = 0; i < n1; i++) - if (data.h_view.extent(1) == 0) - array[i] = nullptr; - else - array[i] = &data.h_view(i,0); - - return data; -} - -template -TYPE grow_kokkos(TYPE &data, typename TYPE::value_type **&array, - int n1, const char *name) -{ - if (array == nullptr) return create_kokkos(data,array,n1,name); - - data.resize(n1); - - bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; - array = (typename TYPE::value_type **) srealloc(array,nbytes,name); - - for (int i = 0; i < n1; i++) - if (data.h_view.extent(1) == 0) - array[i] = nullptr; - else - array[i] = &data.h_view(i,0); - - return data; -} - -/* ---------------------------------------------------------------------- - destroy a 2d array -------------------------------------------------------------------------- */ - -template -void destroy_kokkos(TYPE data, typename TYPE::value_type** &array) -{ - if (array == nullptr) return; - data = TYPE(); - sfree(array); - array = nullptr; -} - /* ---------------------------------------------------------------------- destroy a 3d array ------------------------------------------------------------------------- */ diff --git a/src/KOKKOS/pair_adp_kokkos.cpp b/src/KOKKOS/pair_adp_kokkos.cpp index d02edc43ab..1297d62651 100644 --- a/src/KOKKOS/pair_adp_kokkos.cpp +++ b/src/KOKKOS/pair_adp_kokkos.cpp @@ -472,12 +472,11 @@ void PairADPKokkos::interpolate(int n, double delta, double *f, t_ho /* ---------------------------------------------------------------------- */ template -int PairADPKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &buf, +int PairADPKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n*10; @@ -486,7 +485,7 @@ int PairADPKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d template KOKKOS_INLINE_FUNCTION void PairADPKokkos::operator()(TagPairADPPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); v_buf[10 * i] = d_fp(j); v_buf[10 * i + 1] = d_mu(j, 0); v_buf[10 * i + 2] = d_mu(j, 1); diff --git a/src/KOKKOS/pair_adp_kokkos.h b/src/KOKKOS/pair_adp_kokkos.h index 5714bdb699..41328a567e 100644 --- a/src/KOKKOS/pair_adp_kokkos.h +++ b/src/KOKKOS/pair_adp_kokkos.h @@ -108,7 +108,7 @@ class PairADPKokkos : public PairADP, public KokkosBase const F_FLOAT &epair, const F_FLOAT &fx, const F_FLOAT &fy, const F_FLOAT &fz, const F_FLOAT &delx, const F_FLOAT &dely, const F_FLOAT &delz) const; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -185,9 +185,8 @@ class PairADPKokkos : public PairADP, public KokkosBase typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; int neighflag,newton_pair; diff --git a/src/KOKKOS/pair_eam_alloy_kokkos.cpp b/src/KOKKOS/pair_eam_alloy_kokkos.cpp index 93ed9fc620..b02faced1e 100644 --- a/src/KOKKOS/pair_eam_alloy_kokkos.cpp +++ b/src/KOKKOS/pair_eam_alloy_kokkos.cpp @@ -449,12 +449,11 @@ void PairEAMAlloyKokkos::interpolate(int n, double delta, double *f, /* ---------------------------------------------------------------------- */ template -int PairEAMAlloyKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &buf, +int PairEAMAlloyKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n; @@ -463,7 +462,7 @@ int PairEAMAlloyKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_i template KOKKOS_INLINE_FUNCTION void PairEAMAlloyKokkos::operator()(TagPairEAMAlloyPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); v_buf[i] = d_fp[j]; } diff --git a/src/KOKKOS/pair_eam_alloy_kokkos.h b/src/KOKKOS/pair_eam_alloy_kokkos.h index 2eb40189ac..572dc1aca8 100644 --- a/src/KOKKOS/pair_eam_alloy_kokkos.h +++ b/src/KOKKOS/pair_eam_alloy_kokkos.h @@ -122,7 +122,7 @@ class PairEAMAlloyKokkos : public PairEAM, public KokkosBase { const F_FLOAT &epair, const F_FLOAT &fpair, const F_FLOAT &delx, const F_FLOAT &dely, const F_FLOAT &delz) const; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -190,9 +190,8 @@ class PairEAMAlloyKokkos : public PairEAM, public KokkosBase { typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; int neighflag,newton_pair; diff --git a/src/KOKKOS/pair_eam_fs_kokkos.cpp b/src/KOKKOS/pair_eam_fs_kokkos.cpp index 5dee601302..4da146e68e 100644 --- a/src/KOKKOS/pair_eam_fs_kokkos.cpp +++ b/src/KOKKOS/pair_eam_fs_kokkos.cpp @@ -449,12 +449,11 @@ void PairEAMFSKokkos::interpolate(int n, double delta, double *f, t_ /* ---------------------------------------------------------------------- */ template -int PairEAMFSKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &buf, +int PairEAMFSKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n; @@ -463,7 +462,7 @@ int PairEAMFSKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_ template KOKKOS_INLINE_FUNCTION void PairEAMFSKokkos::operator()(TagPairEAMFSPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); v_buf[i] = d_fp[j]; } diff --git a/src/KOKKOS/pair_eam_fs_kokkos.h b/src/KOKKOS/pair_eam_fs_kokkos.h index bd03ab0015..8e4ee7851e 100644 --- a/src/KOKKOS/pair_eam_fs_kokkos.h +++ b/src/KOKKOS/pair_eam_fs_kokkos.h @@ -122,7 +122,7 @@ class PairEAMFSKokkos : public PairEAM, public KokkosBase { const F_FLOAT &epair, const F_FLOAT &fpair, const F_FLOAT &delx, const F_FLOAT &dely, const F_FLOAT &delz) const; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -190,9 +190,8 @@ class PairEAMFSKokkos : public PairEAM, public KokkosBase { typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; int neighflag,newton_pair; diff --git a/src/KOKKOS/pair_eam_kokkos.cpp b/src/KOKKOS/pair_eam_kokkos.cpp index 32f4afe225..54ffa84f2d 100644 --- a/src/KOKKOS/pair_eam_kokkos.cpp +++ b/src/KOKKOS/pair_eam_kokkos.cpp @@ -444,12 +444,11 @@ void PairEAMKokkos::interpolate(int n, double delta, double *f, t_ho /* ---------------------------------------------------------------------- */ template -int PairEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &buf, +int PairEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n; @@ -458,7 +457,7 @@ int PairEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d template KOKKOS_INLINE_FUNCTION void PairEAMKokkos::operator()(TagPairEAMPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); v_buf[i] = d_fp[j]; } diff --git a/src/KOKKOS/pair_eam_kokkos.h b/src/KOKKOS/pair_eam_kokkos.h index 9d066d40a0..950db43fb2 100644 --- a/src/KOKKOS/pair_eam_kokkos.h +++ b/src/KOKKOS/pair_eam_kokkos.h @@ -120,7 +120,7 @@ class PairEAMKokkos : public PairEAM, public KokkosBase { const F_FLOAT &epair, const F_FLOAT &fpair, const F_FLOAT &delx, const F_FLOAT &dely, const F_FLOAT &delz) const; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -186,9 +186,8 @@ class PairEAMKokkos : public PairEAM, public KokkosBase { typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; int neighflag,newton_pair; diff --git a/src/KOKKOS/pair_meam_kokkos.cpp b/src/KOKKOS/pair_meam_kokkos.cpp index 4361a387ba..9082c410e0 100644 --- a/src/KOKKOS/pair_meam_kokkos.cpp +++ b/src/KOKKOS/pair_meam_kokkos.cpp @@ -338,11 +338,10 @@ void PairMEAMKokkos::init_style() /* ---------------------------------------------------------------------- */ template -int PairMEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, int iswap_in, DAT::tdual_xfloat_1d &buf, +int PairMEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n*comm_forward; @@ -353,7 +352,7 @@ int PairMEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2 template KOKKOS_INLINE_FUNCTION void PairMEAMKokkos::operator()(TagPairMEAMPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); int m = i*comm_forward; v_buf[m++] = d_rho0[j]; v_buf[m++] = d_rho1[j]; @@ -782,10 +781,9 @@ int PairMEAMKokkos::pack_reverse_comm(int n, int first, double *buf) /* ---------------------------------------------------------------------- */ template -void PairMEAMKokkos::unpack_reverse_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, int iswap_in, DAT::tdual_xfloat_1d &buf) +void PairMEAMKokkos::unpack_reverse_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_1d &buf) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); } @@ -795,7 +793,7 @@ void PairMEAMKokkos::unpack_reverse_comm_kokkos(int n, DAT::tdual_in template KOKKOS_INLINE_FUNCTION void PairMEAMKokkos::operator()(TagPairMEAMUnpackReverseComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); //int m = i*30; int m = i*comm_reverse; diff --git a/src/KOKKOS/pair_meam_kokkos.h b/src/KOKKOS/pair_meam_kokkos.h index 0d0d7667f3..66b5700a72 100644 --- a/src/KOKKOS/pair_meam_kokkos.h +++ b/src/KOKKOS/pair_meam_kokkos.h @@ -76,15 +76,15 @@ class PairMEAMKokkos : public PairMEAM, public KokkosBase { KOKKOS_INLINE_FUNCTION void operator()(TagPairMEAMOffsets, const int, int&) const; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; int pack_forward_comm(int, int *, double *, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; void unpack_forward_comm(int, int, double *) override; int pack_reverse_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_reverse_comm(int, int, double *) override; - void unpack_reverse_comm_kokkos(int, DAT::tdual_int_2d, - int, DAT::tdual_xfloat_1d&) override; + void unpack_reverse_comm_kokkos(int, DAT::tdual_int_1d, + DAT::tdual_xfloat_1d&) override; void unpack_reverse_comm(int, int *, double *) override; protected: @@ -108,10 +108,10 @@ class PairMEAMKokkos : public PairMEAM, public KokkosBase { typename AT::t_neighbors_2d d_neighbors_half; typename AT::t_int_1d d_numneigh_full; typename AT::t_neighbors_2d d_neighbors_full; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; - int iswap,first; + int first; int neighflag,nlocal,nall,eflag,vflag; typename ArrayTypes::t_ffloat_1d d_rho, d_rho0, d_rho1, d_rho2, d_rho3, d_frhop; diff --git a/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp b/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp index 41fcac126d..2a20c9e013 100644 --- a/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp +++ b/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp @@ -646,12 +646,11 @@ void PairMultiLucyRXKokkos::getMixingWeights(int id, double &mixWtSi /* ---------------------------------------------------------------------- */ template -int PairMultiLucyRXKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, int iswap_in, DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) +int PairMultiLucyRXKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { atomKK->sync(execution_space,DPDRHO_MASK); d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n; @@ -660,7 +659,7 @@ int PairMultiLucyRXKokkos::pack_forward_comm_kokkos(int n, DAT::tdua template KOKKOS_INLINE_FUNCTION void PairMultiLucyRXKokkos::operator()(TagPairMultiLucyRXPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); v_buf[i] = rho[j]; } diff --git a/src/KOKKOS/pair_multi_lucy_rx_kokkos.h b/src/KOKKOS/pair_multi_lucy_rx_kokkos.h index c335ed526f..753012e0c7 100644 --- a/src/KOKKOS/pair_multi_lucy_rx_kokkos.h +++ b/src/KOKKOS/pair_multi_lucy_rx_kokkos.h @@ -61,7 +61,7 @@ class PairMultiLucyRXKokkos : public PairMultiLucyRX, public KokkosBase { void compute_style(int, int); void init_style() override; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -181,9 +181,8 @@ class PairMultiLucyRXKokkos : public PairMultiLucyRX, public KokkosBase { typename AT::tdual_ffloat_2d k_cutsq; typename AT::t_ffloat_2d d_cutsq; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; friend void pair_virial_fdotr_compute(PairMultiLucyRXKokkos*); From 214ea5209ee23a09ec5e909f86ade984648746a1 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Mon, 26 Feb 2024 16:34:42 -0700 Subject: [PATCH 123/185] Missed changes --- src/comm_tiled.cpp | 26 ++++++++++++++++++-------- src/comm_tiled.h | 12 ++++++------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 65cbfad0b5..0c12fc268b 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -54,7 +54,7 @@ CommTiled::CommTiled(LAMMPS *lmp) : Comm(lmp) rcbinfo = nullptr; cutghostmulti = nullptr; cutghostmultiold = nullptr; - init_buffers(); + init_buffers_flag = 1; } /* ---------------------------------------------------------------------- */ @@ -69,7 +69,7 @@ CommTiled::CommTiled(LAMMPS * /*lmp*/, Comm *oldcomm) : Comm(*oldcomm) style = Comm::TILED; layout = oldcomm->layout; Comm::copy_arrays(oldcomm); - init_buffers(); + init_buffers_flag = 1; } /* ---------------------------------------------------------------------- */ @@ -94,7 +94,7 @@ void CommTiled::init_buffers() buf_send = buf_recv = nullptr; maxsend = maxrecv = BUFMIN; grow_send(maxsend,2); - memory->create(buf_recv,maxrecv,"comm:buf_recv"); + grow_recv(maxrecv,1); maxoverlap = 0; overlap = nullptr; @@ -113,6 +113,11 @@ void CommTiled::init_buffers() void CommTiled::init() { + if (init_buffers_flag) { + init_buffers(); + init_buffers_flag = 0; + } + Comm::init(); // cannot set nswap in init_buffers() b/c @@ -2236,12 +2241,15 @@ void CommTiled::grow_send(int n, int flag) } /* ---------------------------------------------------------------------- - free/malloc the size of the recv buffer as needed with BUFFACTOR + free/malloc the size of the recv buffer as needed + flag = 0, realloc with BUFFACTOR + flag = 1, free/malloc w/out BUFFACTOR ------------------------------------------------------------------------- */ -void CommTiled::grow_recv(int n) +void CommTiled::grow_recv(int n, int flag) { - maxrecv = static_cast (BUFFACTOR * n); + if (flag) maxrecv = n; + else maxrecv = static_cast (BUFFACTOR * n); memory->destroy(buf_recv); memory->create(buf_recv,maxrecv,"comm:buf_recv"); } @@ -2428,8 +2436,10 @@ void CommTiled::deallocate_swap(int n) delete [] maxsendlist[i]; - for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); - delete [] sendlist[i]; + if (sendlist && sendlist[i]) { + for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); + delete [] sendlist[i]; + } } delete [] sendproc; diff --git a/src/comm_tiled.h b/src/comm_tiled.h index c9434e6164..095e7bf5aa 100644 --- a/src/comm_tiled.h +++ b/src/comm_tiled.h @@ -51,7 +51,7 @@ class CommTiled : public Comm { double memory_usage() override; - private: + protected: int nswap; // # of swaps to perform = 2*dim int maxswap; // largest nswap can be = 6 @@ -117,7 +117,7 @@ class CommTiled : public Comm { double *sublo, *subhi; int dimension; - // NOTE: init_buffers is called from a constructor and must not be made virtual + int init_buffers_flag; void init_buffers(); // box drop and other functions @@ -145,11 +145,11 @@ class CommTiled : public Comm { int point_drop_tiled_recurse(double *, int, int); int closer_subbox_edge(int, double *); - void grow_send(int, int); // reallocate send buffer - void grow_recv(int); // free/allocate recv buffer - void grow_list(int, int, int); // reallocate sendlist for one swap/proc + virtual void grow_send(int, int); // reallocate send buffer + virtual void grow_recv(int, int flag = 0); // free/allocate recv buffer + virtual void grow_list(int, int, int); // reallocate sendlist for one swap/proc void allocate_swap(int); // allocate swap arrays - void grow_swap_send(int, int, int); // grow swap arrays for send and recv + virtual void grow_swap_send(int, int, int); // grow swap arrays for send and recv void grow_swap_send_multi(int, int); // grow multi swap arrays for send and recv void grow_swap_recv(int, int); void deallocate_swap(int); // deallocate swap arrays From 07731d81122c4fc0f6ec03cf9f9b4bedea5a8b29 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Mon, 26 Feb 2024 16:34:49 -0700 Subject: [PATCH 124/185] Whitespace --- src/KOKKOS/memory_kokkos.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/KOKKOS/memory_kokkos.h b/src/KOKKOS/memory_kokkos.h index 0cf5b0d51a..3a8272d5ae 100644 --- a/src/KOKKOS/memory_kokkos.h +++ b/src/KOKKOS/memory_kokkos.h @@ -219,15 +219,15 @@ void destroy_kokkos(TYPE data, typename TYPE::value_type** &array) template TYPE create_kokkos(TYPE &data, typename TYPE::value_type ***&array, int n1, int n2, int n3, const char *name) -{ +{ data = TYPE(std::string(name),n1,n2,n3); bigint nbytes = ((bigint) sizeof(typename TYPE::value_type **)) * n1; array = (typename TYPE::value_type ***) smalloc(nbytes,name); - + for (int i = 0; i < n1; i++) { if (n2 == 0) { array[i] = nullptr; - } else { + } else { nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n2; array[i] = (typename TYPE::value_type **) smalloc(nbytes,name); for (int j = 0; j < n2; j++) { From 14066e018ffcfdb65c928d3460a4e6d2220745fc Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Mon, 26 Feb 2024 17:15:04 -0700 Subject: [PATCH 125/185] Fix indexing issue --- src/KOKKOS/comm_tiled_kokkos.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/KOKKOS/comm_tiled_kokkos.cpp b/src/KOKKOS/comm_tiled_kokkos.cpp index 86268301ad..bd65bcf221 100644 --- a/src/KOKKOS/comm_tiled_kokkos.cpp +++ b/src/KOKKOS/comm_tiled_kokkos.cpp @@ -215,7 +215,7 @@ void CommTiledKokkos::forward_comm_device() if (recvother[iswap]) { for (i = 0; i < nrecv; i++) { MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE); - auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(forward_recv_offset[iswap][irecv],(int)k_buf_recv.extent(1)),Kokkos::ALL); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(forward_recv_offset[iswap][irecv],(int)k_buf_recv.extent(0)),Kokkos::ALL); atomKK->avecKK->unpack_comm_vel_kokkos(recvnum[iswap][irecv],firstrecv[iswap][irecv], k_buf_recv_offset); DeviceType().fence(); @@ -249,7 +249,7 @@ void CommTiledKokkos::forward_comm_device() if (recvother[iswap]) { for (i = 0; i < nrecv; i++) { MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE); - auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(forward_recv_offset[iswap][irecv],(int)k_buf_recv.extent(1)),Kokkos::ALL); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(forward_recv_offset[iswap][irecv],(int)k_buf_recv.extent(0)),Kokkos::ALL); atomKK->avecKK->unpack_comm_kokkos(recvnum[iswap][irecv],firstrecv[iswap][irecv], k_buf_recv_offset); DeviceType().fence(); @@ -336,7 +336,7 @@ void CommTiledKokkos::reverse_comm_device() for (i = 0; i < nsend; i++) { MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE); auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,irecv,Kokkos::ALL); - auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(reverse_recv_offset[iswap][irecv],(int)k_buf_recv.extent(1)),Kokkos::ALL); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(reverse_recv_offset[iswap][irecv],(int)k_buf_recv.extent(0)),Kokkos::ALL); atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap][irecv],k_sendlist_small, k_buf_recv_offset); DeviceType().fence(); @@ -370,7 +370,7 @@ void CommTiledKokkos::reverse_comm_device() for (i = 0; i < nsend; i++) { MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE); auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,irecv,Kokkos::ALL); - auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(reverse_recv_offset[iswap][irecv],(int)k_buf_recv.extent(1)),Kokkos::ALL); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(reverse_recv_offset[iswap][irecv],(int)k_buf_recv.extent(0)),Kokkos::ALL); atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap][irecv],k_sendlist_small, k_buf_recv_offset); DeviceType().fence(); From 53219b299bd35109a3cf270df022618f917cb790 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Mon, 26 Feb 2024 17:16:28 -0700 Subject: [PATCH 126/185] Unused var --- src/KOKKOS/atom_vec_kokkos.cpp | 1 - src/KOKKOS/atom_vec_kokkos.h | 1 - src/KOKKOS/fix_langevin_kokkos.h | 2 -- 3 files changed, 4 deletions(-) diff --git a/src/KOKKOS/atom_vec_kokkos.cpp b/src/KOKKOS/atom_vec_kokkos.cpp index 31fc63db6a..bdcf2b0803 100644 --- a/src/KOKKOS/atom_vec_kokkos.cpp +++ b/src/KOKKOS/atom_vec_kokkos.cpp @@ -38,7 +38,6 @@ AtomVecKokkos::AtomVecKokkos(LAMMPS *lmp) : AtomVec(lmp) k_count = DAT::tdual_int_1d("atom:k_count",1); atomKK = (AtomKokkos *) atom; - commKK = (CommKokkos *) comm; } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/atom_vec_kokkos.h b/src/KOKKOS/atom_vec_kokkos.h index 635113d500..646d9a4840 100644 --- a/src/KOKKOS/atom_vec_kokkos.h +++ b/src/KOKKOS/atom_vec_kokkos.h @@ -133,7 +133,6 @@ class AtomVecKokkos : virtual public AtomVec { HAT::t_v_array h_v; HAT::t_f_array h_f; - class CommKokkos *commKK; size_t buffer_size; void* buffer; diff --git a/src/KOKKOS/fix_langevin_kokkos.h b/src/KOKKOS/fix_langevin_kokkos.h index 4fc22a1df1..24e587f61b 100644 --- a/src/KOKKOS/fix_langevin_kokkos.h +++ b/src/KOKKOS/fix_langevin_kokkos.h @@ -103,8 +103,6 @@ namespace LAMMPS_NS { void end_of_step_rmass_item(int) const; private: - class CommKokkos *commKK; - typename ArrayTypes::t_float_1d rmass; typename ArrayTypes::t_float_1d mass; typename ArrayTypes::tdual_double_2d k_franprev; From 1baa6cc166234f67013875776cbdec13784ed149 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 27 Feb 2024 10:28:32 -0500 Subject: [PATCH 127/185] remove dead code from fix bocs --- src/BOCS/fix_bocs.cpp | 40 +++++++--------------------------------- src/BOCS/fix_bocs.h | 4 +--- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/src/BOCS/fix_bocs.cpp b/src/BOCS/fix_bocs.cpp index 33f4f072e7..409ec8507b 100644 --- a/src/BOCS/fix_bocs.cpp +++ b/src/BOCS/fix_bocs.cpp @@ -64,15 +64,15 @@ enum { ISO, ANISO, TRICLINIC }; /* ---------------------------------------------------------------------- NVT,NPH,NPT integrators for improved Nose-Hoover equations of motion ---------------------------------------------------------------------- */ -// clang-format off FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), id_dilate(nullptr), irregular(nullptr), id_temp(nullptr), - id_press(nullptr), eta(nullptr), eta_dot(nullptr), eta_dotdot(nullptr), eta_mass(nullptr), - etap(nullptr), etap_dot(nullptr), etap_dotdot(nullptr), etap_mass(nullptr) + Fix(lmp, narg, arg), irregular(nullptr), id_temp(nullptr), id_press(nullptr), eta(nullptr), + eta_dot(nullptr), eta_dotdot(nullptr), eta_mass(nullptr), etap(nullptr), etap_dot(nullptr), + etap_dotdot(nullptr), etap_mass(nullptr) { if (lmp->citeme) lmp->citeme->add(cite_user_bocs_package); + // clang-format off if (narg < 4) utils::missing_cmd_args(FLERR,"fix bocs",error); restart_global = 1; @@ -89,8 +89,6 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : pcouple = NONE; drag = 0.0; - allremap = 1; - id_dilate = nullptr; mtchain = mpchain = 3; nc_tchain = nc_pchain = 1; mtk_flag = 1; @@ -288,7 +286,6 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : if (p_flag[4]) box_change |= BOX_CHANGE_XZ; if (p_flag[5]) box_change |= BOX_CHANGE_XY; no_change_box = 1; - if (allremap == 0) restart_pbc = 1; pstyle = ISO; // MRD this is the only one that can happen @@ -407,7 +404,6 @@ FixBocs::~FixBocs() { if (copymode) return; - delete[] id_dilate; delete irregular; // delete temperature and pressure if fix created them @@ -458,14 +454,6 @@ int FixBocs::setmask() void FixBocs::init() { - // recheck that dilate group has not been deleted - if (allremap == 0) { - int idilate = group->find(id_dilate); - if (idilate == -1) - error->all(FLERR,"Fix bocs dilate group ID does not exist"); - dilate_group_bit = group->bitmask[idilate]; - } - // ensure no conflict with fix deform if (pstat_flag) { @@ -1125,19 +1113,15 @@ void FixBocs::couple() } /* ---------------------------------------------------------------------- - change box size - remap all atoms or dilate group atoms depending on allremap flag + change box size, remap all atoms if rigid bodies exist, scale rigid body centers-of-mass ------------------------------------------------------------------------- */ void FixBocs::remap() { - int i; double oldlo,oldhi; double expfac; - double **x = atom->x; - int *mask = atom->mask; int nlocal = atom->nlocal; double *h = domain->h; @@ -1147,12 +1131,7 @@ void FixBocs::remap() // convert pertinent atoms and rigid bodies to lamda coords - if (allremap) domain->x2lamda(nlocal); - else { - for (i = 0; i < nlocal; i++) - if (mask[i] & dilate_group_bit) - domain->x2lamda(x[i],x[i]); - } + domain->x2lamda(nlocal); for (auto &ifix : rfix) ifix->deform(0); @@ -1292,12 +1271,7 @@ void FixBocs::remap() // convert pertinent atoms and rigid bodies back to box coords - if (allremap) domain->lamda2x(nlocal); - else { - for (i = 0; i < nlocal; i++) - if (mask[i] & dilate_group_bit) - domain->lamda2x(x[i],x[i]); - } + domain->lamda2x(nlocal); for (auto &ifix : rfix) ifix->deform(1); } diff --git a/src/BOCS/fix_bocs.h b/src/BOCS/fix_bocs.h index af221fedb3..7f752a03f3 100644 --- a/src/BOCS/fix_bocs.h +++ b/src/BOCS/fix_bocs.h @@ -65,7 +65,7 @@ class FixBocs : public Fix { int tstat_flag; // 1 if control T int pstat_flag; // 1 if control P - int pstyle, pcouple, allremap; + int pstyle, pcouple; int p_flag[6]; // 1 if control P on this dim, 0 if not double p_start[6], p_stop[6]; double p_freq[6], p_target[6]; @@ -75,9 +75,7 @@ class FixBocs : public Fix { double drag, tdrag_factor; // drag factor on particle thermostat double pdrag_factor; // drag factor on barostat int kspace_flag; // 1 if KSpace invoked, 0 if not - int dilate_group_bit; // mask for dilation group std::vector rfix; // list of rigid fixes - char *id_dilate; // group name to dilate class Irregular *irregular; // for migrating atoms after box flips // MRD NJD From e1a3ed6602da994d258dadf38231c72658815f4c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 27 Feb 2024 10:31:43 -0500 Subject: [PATCH 128/185] modernize and coding style/formatting improvements --- src/BOCS/compute_pressure_bocs.cpp | 36 +++++++++++++--------------- src/BOCS/fix_bocs.cpp | 38 +++++++++++++----------------- 2 files changed, 33 insertions(+), 41 deletions(-) diff --git a/src/BOCS/compute_pressure_bocs.cpp b/src/BOCS/compute_pressure_bocs.cpp index a8bc9596cc..16d6c91a1f 100644 --- a/src/BOCS/compute_pressure_bocs.cpp +++ b/src/BOCS/compute_pressure_bocs.cpp @@ -42,7 +42,7 @@ ComputePressureBocs::ComputePressureBocs(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), vptr(nullptr), id_temp(nullptr) { - if (narg < 4) error->all(FLERR,"Illegal compute pressure/bocs command"); + if (narg < 4) utils::missing_cmd_args(FLERR,"compute pressure/bocs", error); if (igroup) error->all(FLERR,"Compute pressure/bocs must use group all"); scalar_flag = vector_flag = 1; @@ -62,12 +62,12 @@ ComputePressureBocs::ComputePressureBocs(LAMMPS *lmp, int narg, char **arg) : else { id_temp = utils::strdup(arg[3]); - int icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Could not find compute pressure/bocs temperature ID"); - if (modify->compute[icompute]->tempflag == 0) - error->all(FLERR,"Compute pressure/bocs temperature ID does not " - "compute temperature"); + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR,"Could not find compute pressure/bocs temperature compute {}", id_temp); + if (temperature->tempflag == 0) + error->all(FLERR,"Compute pressure/bocs temperature compute {} does not compute " + "temperature", id_temp); } // process optional args @@ -137,10 +137,9 @@ void ComputePressureBocs::init() // fixes could have changed or compute_modify could have changed it if (keflag) { - int icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Could not find compute pressure/bocs temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR,"Could not find compute pressure/bocs temperature compute {}", id_temp); } // detect contributions to virial @@ -158,10 +157,8 @@ void ComputePressureBocs::init() if (improperflag && force->improper) nvirial++; } if (fixflag) { - Fix **fix = modify->fix; - int nfix = modify->nfix; - for (int i = 0; i < nfix; i++) - if (fix[i]->thermo_virial) nvirial++; + for (const auto &ifix : modify->get_fix_list()) + if (ifix->thermo_virial) nvirial++; } if (nvirial) { @@ -174,10 +171,11 @@ void ComputePressureBocs::init() vptr[nvirial++] = force->dihedral->virial; if (improperflag && force->improper) vptr[nvirial++] = force->improper->virial; - if (fixflag) - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->virial_global_flag && modify->fix[i]->thermo_virial) - vptr[nvirial++] = modify->fix[i]->virial; + if (fixflag) { + for (const auto &ifix : modify->get_fix_list()) + if (ifix->virial_global_flag && ifix->thermo_virial) + vptr[nvirial++] = ifix->virial; + } } // flag Kspace contribution separately, since not summed across procs diff --git a/src/BOCS/fix_bocs.cpp b/src/BOCS/fix_bocs.cpp index 409ec8507b..d6beb889ff 100644 --- a/src/BOCS/fix_bocs.cpp +++ b/src/BOCS/fix_bocs.cpp @@ -145,15 +145,14 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"temp") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix bocs command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR,"fix bocs temp", error); tstat_flag = 1; t_start = utils::numeric(FLERR,arg[iarg+1],false,lmp); t_target = t_start; t_stop = utils::numeric(FLERR,arg[iarg+2],false,lmp); t_period = utils::numeric(FLERR,arg[iarg+3],false,lmp); if (t_start <= 0.0 || t_stop <= 0.0) - error->all(FLERR, - "Target temperature for fix bocs cannot be 0.0"); + error->all(FLERR, "Target temperature for fix bocs cannot be 0.0"); iarg += 4; } else if (strcmp(arg[iarg],"iso") == 0) { error->all(FLERR,"Illegal fix bocs command. Pressure fix must be " @@ -164,12 +163,9 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : "followed by: P_0 P_f P_coupl"); p_match_flag = 1; pcouple = XYZ; - p_start[0] = p_start[1] = p_start[2] = - utils::numeric(FLERR,arg[iarg+1],false,lmp); - p_stop[0] = p_stop[1] = p_stop[2] = - utils::numeric(FLERR,arg[iarg+2],false,lmp); - p_period[0] = p_period[1] = p_period[2] = - utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_start[0] = p_start[1] = p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + p_stop[0] = p_stop[1] = p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + p_period[0] = p_period[1] = p_period[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); p_flag[0] = p_flag[1] = p_flag[2] = 1; p_flag[3] = p_flag[4] = p_flag[5] = 0; // MRD @@ -383,7 +379,7 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(fmt::format("{} all temp",id_temp)); + temperature = modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style @@ -391,7 +387,7 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : // pass id_temp as 4th arg to pressure constructor id_press = utils::strdup(std::string(id)+"_press"); - modify->add_compute(fmt::format("{} all PRESSURE/BOCS {}",id_press,id_temp)); + pressure = modify->add_compute(fmt::format("{} all PRESSURE/BOCS {}",id_press,id_temp)); pcomputeflag = 1; /*~ MRD End of stuff copied from fix_npt.cpp~*/ @@ -1435,24 +1431,22 @@ int FixBocs::modify_param(int narg, char **arg) delete[] id_temp; id_temp = utils::strdup(arg[1]); - int icompute = modify->find_compute(arg[1]); - if (icompute < 0) - error->all(FLERR,"Could not find fix_modify temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR,"Could not find fix_modify temperature compute {}", id_temp); if (temperature->tempflag == 0) - error->all(FLERR, - "Fix_modify temperature ID does not compute temperature"); + error->all(FLERR, "Fix_modify temperature compute {} does not compute temperature", id_temp); if (temperature->igroup != 0 && comm->me == 0) - error->warning(FLERR,"Temperature for fix modify is not for group all"); + error->warning(FLERR,"Temperature compute {} for fix modify is not for group all", id_temp); // reset id_temp of pressure to new temperature ID if (pstat_flag) { - icompute = modify->find_compute(id_press); - if (icompute < 0) - error->all(FLERR,"Pressure ID for fix modify does not exist"); - modify->compute[icompute]->reset_extra_compute_fix(id_temp); + pressure = modify->get_compute_by_id(id_press); + if (!pressure) + error->all(FLERR,"Pressure ID {} for fix modify does not exist", id_press); + pressure->reset_extra_compute_fix(id_temp); } return 2; From f1ed2f20a1f001bd5d75718d6f04b488b4a548d3 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 27 Feb 2024 09:31:39 -0700 Subject: [PATCH 129/185] Add back in legacy functions needed for mliap --- src/KOKKOS/memory_kokkos.h | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/KOKKOS/memory_kokkos.h b/src/KOKKOS/memory_kokkos.h index 3a8272d5ae..0d9b10ed2f 100644 --- a/src/KOKKOS/memory_kokkos.h +++ b/src/KOKKOS/memory_kokkos.h @@ -346,6 +346,65 @@ static double memory_usage(TYPE &data) return data.span() * sizeof(typename TYPE::value_type); } +/* ---------------------------------------------------------------------- + legacy functions +------------------------------------------------------------------------- */ + +template +TYPE destroy_kokkos(TYPE &data) +{ + data = TYPE(); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name),n1); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, int n2, const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name),n1,n2); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, int n2, int n3 ,const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name),n1,n2,n3); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4 ,const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name),n1,n2,n3,n4); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4, int n5 ,const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name),n1,n2,n3,n4,n5); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4, int n5 , int n6 ,const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name) ,n1,n2,n3,n4,n5,n6); + return data; +} + }; } From 369aae91d38339572ceeadd38fbe06d1340b56ec Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 27 Feb 2024 09:31:53 -0700 Subject: [PATCH 130/185] Remove unnecessary destroys --- src/KOKKOS/mliap_data_kokkos.cpp | 2 - src/KOKKOS/mliap_descriptor_kokkos.h | 3 -- src/KOKKOS/mliap_model_kokkos.h | 2 - src/KOKKOS/mliap_so3_kokkos.cpp | 72 ---------------------------- 4 files changed, 79 deletions(-) diff --git a/src/KOKKOS/mliap_data_kokkos.cpp b/src/KOKKOS/mliap_data_kokkos.cpp index dc8fe7dd83..14d0dae14f 100644 --- a/src/KOKKOS/mliap_data_kokkos.cpp +++ b/src/KOKKOS/mliap_data_kokkos.cpp @@ -59,7 +59,6 @@ MLIAPDataKokkos::~MLIAPDataKokkos() { memoryKK->destroy_kokkos(k_pair_i,pair_i); memoryKK->destroy_kokkos(k_jelems,jelems); memoryKK->destroy_kokkos(k_elems,elems); - memoryKK->destroy_kokkos(k_ij); memoryKK->destroy_kokkos(k_rij,rij); memoryKK->destroy_kokkos(k_graddesc,graddesc); } @@ -213,7 +212,6 @@ void MLIAPDataKokkos::grow_neigharrays() { memoryKK->create_kokkos(k_iatoms, iatoms, natomneigh_max, "mliap_data:iatoms"); memoryKK->destroy_kokkos(k_ielems,ielems); memoryKK->create_kokkos(k_ielems, ielems, natomneigh_max, "mliap_data:ielems"); - memoryKK->destroy_kokkos(k_ij); memoryKK->create_kokkos(k_ij, natomneigh_max, "mliap_data:ij"); memoryKK->destroy_kokkos(k_numneighs,numneighs); memoryKK->create_kokkos(k_numneighs, numneighs, natomneigh_max, "mliap_data:numneighs"); diff --git a/src/KOKKOS/mliap_descriptor_kokkos.h b/src/KOKKOS/mliap_descriptor_kokkos.h index 075f0e9fed..d4ab72ff96 100644 --- a/src/KOKKOS/mliap_descriptor_kokkos.h +++ b/src/KOKKOS/mliap_descriptor_kokkos.h @@ -29,13 +29,11 @@ template class MLIAPDescriptorKokkos : virtual protected Poin MLIAPDescriptorKokkos(LAMMPS *lmp, MLIAPDescriptor *descriptor_in) : Pointers(lmp), descriptor(descriptor_in) { - memoryKK->destroy_kokkos(k_wjelem); } void init_data() { int num_elems = descriptor->nelements; - memoryKK->destroy_kokkos(k_wjelem); memoryKK->create_kokkos(k_wjelem, num_elems, "MLIAPDescriptorKokkos::k_wjelem"); for (int i = 0; i < num_elems; ++i) k_wjelem.h_view(i) = descriptor->wjelem[i]; k_wjelem.modify(); @@ -44,7 +42,6 @@ template class MLIAPDescriptorKokkos : virtual protected Poin virtual ~MLIAPDescriptorKokkos() { - memoryKK->destroy_kokkos(k_wjelem); } MLIAPDescriptor *descriptor; diff --git a/src/KOKKOS/mliap_model_kokkos.h b/src/KOKKOS/mliap_model_kokkos.h index 72077f5988..4840798cc1 100644 --- a/src/KOKKOS/mliap_model_kokkos.h +++ b/src/KOKKOS/mliap_model_kokkos.h @@ -29,14 +29,12 @@ template class MLIAPModelKokkos : protected Pointers { MLIAPModelKokkos(LAMMPS *lmp, MLIAPModel *model_in) : Pointers(lmp), model(model_in) {} virtual ~MLIAPModelKokkos() { - memoryKK->destroy_kokkos(k_coeffelem); model->coeffelem = nullptr; } void set_k_coeffelem() { double **tmp = nullptr; - memoryKK->destroy_kokkos(k_coeffelem); memoryKK->create_kokkos(k_coeffelem, tmp, model->nelements, model->nparams, "MLIAPModelKokkos::coeffelem"); for (int i = 0; i < model->nelements; ++i) diff --git a/src/KOKKOS/mliap_so3_kokkos.cpp b/src/KOKKOS/mliap_so3_kokkos.cpp index 3f6370a6fc..0fe3cd2350 100644 --- a/src/KOKKOS/mliap_so3_kokkos.cpp +++ b/src/KOKKOS/mliap_so3_kokkos.cpp @@ -60,44 +60,6 @@ MLIAP_SO3Kokkos::MLIAP_SO3Kokkos(LAMMPS *lmp, double vrcut, int vlma template MLIAP_SO3Kokkos::~MLIAP_SO3Kokkos() { - memoryKK->destroy_kokkos(m_ellpl1); - memoryKK->destroy_kokkos(m_ellm1); - memoryKK->destroy_kokkos(m_pfac); - memoryKK->destroy_kokkos(m_Ylms); - memoryKK->destroy_kokkos(m_dfac0); - memoryKK->destroy_kokkos(m_dfac1); - memoryKK->destroy_kokkos(m_dfac2); - memoryKK->destroy_kokkos(m_dfac3); - memoryKK->destroy_kokkos(m_dfac4); - memoryKK->destroy_kokkos(m_dfac5); - memoryKK->destroy_kokkos(m_w); - memoryKK->destroy_kokkos(m_g_array); - - memoryKK->destroy_kokkos(m_rootpq); - memoryKK->destroy_kokkos(m_idxu_block); - memoryKK->destroy_kokkos(m_idxylm); - - memoryKK->destroy_kokkos(m_rip_array); - memoryKK->destroy_kokkos(m_rip_darray); - - memoryKK->destroy_kokkos(m_sbes_array); - memoryKK->destroy_kokkos(m_sbes_darray); - - memoryKK->destroy_kokkos(m_plist_r); - - memoryKK->destroy_kokkos(m_ulist_r); - memoryKK->destroy_kokkos(m_ulist_i); - - memoryKK->destroy_kokkos(m_dYlm_r); - memoryKK->destroy_kokkos(m_dYlm_i); - - memoryKK->destroy_kokkos(k_dplist_r); - - memoryKK->destroy_kokkos(m_dclist); - - memoryKK->destroy_kokkos(m_clisttot_r); - memoryKK->destroy_kokkos(m_clisttot_i); - t_numneighs = int_1d(); t_jelems = int_1d(); t_wjelem = float_1d(); @@ -121,9 +83,7 @@ void MLIAP_SO3Kokkos::init() int totali; totali = m_lmax + 1; - memoryKK->destroy_kokkos(m_ellpl1); memoryKK->create_kokkos(m_ellpl1, totali, "MLIAP_SO3Kokkos:m_ellpl1"); - memoryKK->destroy_kokkos(m_ellm1); memoryKK->create_kokkos(m_ellm1, totali, "MLIAP_SO3Kokkos:m_ellm1"); alloc_init = 2.0 * totali * sizeof(double); using range=Kokkos::RangePolicy; @@ -139,9 +99,7 @@ void MLIAP_SO3Kokkos::init() m_pfac_l1 = m_lmax + 2; m_pfac_l2 = (m_lmax + 2) * (m_lmax + 2) + 1; totali = m_pfac_l1 * m_pfac_l2; - memoryKK->destroy_kokkos(m_pfac); memoryKK->create_kokkos(m_pfac, totali, "MLIAP_SO3Kokkos:m_pfac"); - memoryKK->destroy_kokkos(m_Ylms); memoryKK->create_kokkos(m_Ylms, totali, "MLIAP_SO3Kokkos:m_Ylms"); alloc_init += 2 * totali * sizeof(double); @@ -161,17 +119,11 @@ void MLIAP_SO3Kokkos::init() m_dfac_l1 = m_lmax + 1; m_dfac_l2 = m_numYlms + 1; totali = m_dfac_l1 * m_dfac_l2; - memoryKK->destroy_kokkos(m_dfac0); memoryKK->create_kokkos(m_dfac0, totali, "MLIAP_SO3Kokkos:m_dfac0"); - memoryKK->destroy_kokkos(m_dfac1); memoryKK->create_kokkos(m_dfac1, totali, "MLIAP_SO3Kokkos:m_dfac1"); - memoryKK->destroy_kokkos(m_dfac2); memoryKK->create_kokkos(m_dfac2, totali, "MLIAP_SO3Kokkos:m_dfac2"); - memoryKK->destroy_kokkos(m_dfac3); memoryKK->create_kokkos(m_dfac3, totali, "MLIAP_SO3Kokkos:m_dfac3"); - memoryKK->destroy_kokkos(m_dfac4); memoryKK->create_kokkos(m_dfac4, totali, "MLIAP_SO3Kokkos:m_dfac4"); - memoryKK->destroy_kokkos(m_dfac5); memoryKK->create_kokkos(m_dfac5, totali, "MLIAP_SO3Kokkos:m_dfac5"); alloc_init += 6.0 * totali * sizeof(double); @@ -197,12 +149,10 @@ void MLIAP_SO3Kokkos::init() }); totali = m_nmax * m_nmax; - memoryKK->destroy_kokkos(m_w); memoryKK->create_kokkos(m_w, totali, "MLIAP_SO3Kokkos:w"); alloc_init += totali * sizeof(double); totali = m_nmax * m_Nmax; - memoryKK->destroy_kokkos(m_g_array); memoryKK->create_kokkos(m_g_array, totali, "MLIAP_SO3Kokkos:g_array"); alloc_init += totali * sizeof(double); @@ -218,7 +168,6 @@ void MLIAP_SO3Kokkos::init() twolmax = 2 * (m_lmax + 1); int m_ldim = twolmax + 1; totali = m_ldim * m_ldim; - memoryKK->destroy_kokkos(m_rootpq); memoryKK->create_kokkos(m_rootpq, totali, "MLIAP_SO3Kokkos:rootpq"); alloc_init += totali * sizeof(double); @@ -229,12 +178,10 @@ void MLIAP_SO3Kokkos::init() rootpq[p * ldim + q] = sqrt(static_cast(p) / q); }); - memoryKK->destroy_kokkos(m_idxu_block); memoryKK->create_kokkos(m_idxu_block, m_ldim, "MLIAP_SO3Kokkos:idxu_bloc"); alloc_init += totali * sizeof(double); totali = square(m_lmax + 2); - memoryKK->destroy_kokkos(m_idxylm); memoryKK->create_kokkos(m_idxylm, totali, "MLIAP_SO3Kokkos:idxylm"); alloc_init += totali * sizeof(double); @@ -278,7 +225,6 @@ void MLIAP_SO3Kokkos::init_arrays(int nlocal, int ncoefs) int totali = nlocal * ncoefs; if ( nlocal > (int)m_plist_r.extent(0)) { - memoryKK->destroy_kokkos(m_plist_r); memoryKK->create_kokkos(m_plist_r, nlocal, ncoefs, "MLIAP_SO3Kokkos:m_plist_r"); alloc_arrays = totali * sizeof(double); } @@ -286,26 +232,19 @@ void MLIAP_SO3Kokkos::init_arrays(int nlocal, int ncoefs) int num_of_temp = std::min(nlocal, m_chunk_size); if ((int)m_ulist_r.extent(0) < num_of_temp ) { totali = m_idxu_count; - memoryKK->destroy_kokkos(m_ulist_r); memoryKK->create_kokkos(m_ulist_r, num_of_temp, totali, "MLIAP_SO3Kokkos:m_ulist_r"); - memoryKK->destroy_kokkos(m_ulist_i); memoryKK->create_kokkos(m_ulist_i, num_of_temp, totali, "MLIAP_SO3Kokkos:m_ulist_i"); alloc_arrays += 2.0 * totali * num_of_temp * sizeof(double); totali = m_numYlms * 3; - memoryKK->destroy_kokkos(m_dYlm_r); memoryKK->create_kokkos(m_dYlm_r, num_of_temp, m_numYlms, 3, "MLIAP_SO3Kokkos:m_dYlm_r"); - memoryKK->destroy_kokkos(m_dYlm_i); memoryKK->create_kokkos(m_dYlm_i, num_of_temp, m_numYlms, 3, "MLIAP_SO3Kokkos:m_dYlm_i"); alloc_arrays += 2.0 * m_numYlms * 3 * num_of_temp * sizeof(double); - memoryKK->destroy_kokkos(m_dclist); memoryKK->create_kokkos(m_dclist, num_of_temp, m_nmax, m_numYlms, 3, "MLIAP_SO3Kokkos:k_dclist_r"); alloc_arrays += m_nmax * m_numYlms * 3 * num_of_temp* sizeof(double); - memoryKK->destroy_kokkos(m_clisttot_r); memoryKK->create_kokkos(m_clisttot_r, num_of_temp, m_nmax, m_numYlms, "MLIAP_SO3Kokkos:m_clisttot_r"); - memoryKK->destroy_kokkos(m_clisttot_i); memoryKK->create_kokkos(m_clisttot_i, num_of_temp, m_nmax, m_numYlms, "MLIAP_SO3Kokkos:m_clisttot_i"); alloc_arrays += 2.0 * m_nmax * m_numYlms * num_of_temp * sizeof(double); m_init_arrays = 1; @@ -850,21 +789,15 @@ void MLIAP_SO3Kokkos::spectrum_dxdr(int nlocal, DAT::tdual_int_1d nu bigint totali; if ( nlocal > (int)m_clisttot_r.extent(0)){ - memoryKK->destroy_kokkos(m_clisttot_r); memoryKK->create_kokkos(m_clisttot_r, nlocal, m_nmax, m_numYlms, "MLIAP_SO3Kokkos:m_clisttot_r"); - memoryKK->destroy_kokkos(m_clisttot_i); memoryKK->create_kokkos(m_clisttot_i, nlocal, m_nmax, m_numYlms, "MLIAP_SO3Kokkos:m_clisttot_i"); int num_of_temp = std::min(nlocal, m_chunk_size); int delta=num_of_temp-m_ulist_r.extent(0); if (delta > 0){ - memoryKK->destroy_kokkos(m_ulist_r); memoryKK->create_kokkos(m_ulist_r, num_of_temp, m_idxu_count, "MLIAP_SO3Kokkos:m_ulist_r"); - memoryKK->destroy_kokkos(m_ulist_i); memoryKK->create_kokkos(m_ulist_i, num_of_temp, m_idxu_count, "MLIAP_SO3Kokkos:m_ulist_i"); alloc_arrays += 2.0 * m_idxu_count * delta * sizeof(double); - memoryKK->destroy_kokkos(m_dYlm_r); memoryKK->create_kokkos(m_dYlm_r, num_of_temp, m_numYlms, 3, "MLIAP_SO3Kokkos:m_dYlm_r"); - memoryKK->destroy_kokkos(m_dYlm_i); memoryKK->create_kokkos(m_dYlm_i, num_of_temp, m_numYlms, 3, "MLIAP_SO3Kokkos:m_dYlm_i"); alloc_arrays += 2.0 * m_numYlms * 3 * delta * sizeof(double); } @@ -872,18 +805,13 @@ void MLIAP_SO3Kokkos::spectrum_dxdr(int nlocal, DAT::tdual_int_1d nu totali = totaln * m_Nmax * (m_lmax + 1); if ( totali > (int)m_sbes_array.extent(0)) { - memoryKK->destroy_kokkos(m_sbes_array); memoryKK->create_kokkos(m_sbes_array, totali, "MLIAP_SO3Kokkos:m_sbes_array"); - memoryKK->destroy_kokkos(m_sbes_darray); memoryKK->create_kokkos(m_sbes_darray, totali, "MLIAP_SO3Kokkos:m_sbes_darray"); totali = totaln * m_nmax * (m_lmax + 1); - memoryKK->destroy_kokkos(m_rip_array); memoryKK->create_kokkos(m_rip_array, totali, "MLIAP_SO3Kokkos:m_rip_array"); - memoryKK->destroy_kokkos(m_rip_darray); memoryKK->create_kokkos(m_rip_darray, totali, "MLIAP_SO3Kokkos:m_rip_darray"); - memoryKK->destroy_kokkos(k_dplist_r); memoryKK->create_kokkos(k_dplist_r, (int)totaln, ncoefs, 3, "MLIAP_SO3Kokkos:m_dplist_r"); } From 69727587836c1e064a63071d3513ae0b4794214a Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 27 Feb 2024 09:38:22 -0700 Subject: [PATCH 131/185] whitespace --- src/KOKKOS/memory_kokkos.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KOKKOS/memory_kokkos.h b/src/KOKKOS/memory_kokkos.h index 0d9b10ed2f..0c7555875e 100644 --- a/src/KOKKOS/memory_kokkos.h +++ b/src/KOKKOS/memory_kokkos.h @@ -347,7 +347,7 @@ static double memory_usage(TYPE &data) } /* ---------------------------------------------------------------------- - legacy functions + legacy functions ------------------------------------------------------------------------- */ template From 86b7560740f2b03262458e0025eb6c5c42d6282e Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 27 Feb 2024 14:13:27 -0700 Subject: [PATCH 132/185] Init pointers, etc. --- src/KOKKOS/comm_tiled_kokkos.cpp | 3 +- src/comm_tiled.cpp | 74 ++++++++++++++++++++++---------- src/comm_tiled.h | 3 +- 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/KOKKOS/comm_tiled_kokkos.cpp b/src/KOKKOS/comm_tiled_kokkos.cpp index bd65bcf221..60e7f7d9a8 100644 --- a/src/KOKKOS/comm_tiled_kokkos.cpp +++ b/src/KOKKOS/comm_tiled_kokkos.cpp @@ -36,7 +36,6 @@ static constexpr int BUFEXTRA = 1000; CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) { - sendlist = nullptr; } /* ---------------------------------------------------------------------- */ @@ -48,7 +47,6 @@ CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp, Comm *oldcomm) : CommTiled(_lmp,oldcomm) { - sendlist = nullptr; } /* ---------------------------------------------------------------------- */ @@ -59,6 +57,7 @@ CommTiledKokkos::~CommTiledKokkos() sendlist = nullptr; buf_send = nullptr; buf_recv = nullptr; + maxswap = 0; } /* ---------------------------------------------------------------------- */ diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 0c12fc268b..59ab993655 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -47,14 +47,9 @@ CommTiled::CommTiled(LAMMPS *lmp) : Comm(lmp) { style = Comm::TILED; layout = Comm::LAYOUT_UNIFORM; - pbc_flag = nullptr; - buf_send = nullptr; - buf_recv = nullptr; - overlap = nullptr; - rcbinfo = nullptr; - cutghostmulti = nullptr; - cutghostmultiold = nullptr; - init_buffers_flag = 1; + init_pointers(); + init_buffers_flag = 0; + maxswap = 0; } /* ---------------------------------------------------------------------- */ @@ -69,7 +64,9 @@ CommTiled::CommTiled(LAMMPS * /*lmp*/, Comm *oldcomm) : Comm(*oldcomm) style = Comm::TILED; layout = oldcomm->layout; Comm::copy_arrays(oldcomm); - init_buffers_flag = 1; + init_pointers(); + init_buffers_flag = 0; + maxswap = 0; } /* ---------------------------------------------------------------------- */ @@ -85,24 +82,59 @@ CommTiled::~CommTiled() memory->destroy(cutghostmultiold); } +/* ---------------------------------------------------------------------- + initialize comm pointers to nullptr +------------------------------------------------------------------------- */ + +void CommTiled::init_pointers() +{ + buf_send = buf_recv = nullptr; + overlap = nullptr; + rcbinfo = nullptr; + cutghostmulti = nullptr; + cutghostmultiold = nullptr; + + nsendproc = nullptr; + nrecvproc = nullptr; + sendother = nullptr; + recvother = nullptr; + sendself = nullptr; + sendproc = nullptr; + recvproc = nullptr; + sendnum = nullptr; + recvnum = nullptr; + size_forward_recv = nullptr; + firstrecv = nullptr; + size_reverse_send = nullptr; + size_reverse_recv = nullptr; + forward_recv_offset = nullptr; + reverse_recv_offset = nullptr; + pbc_flag = nullptr; + pbc = nullptr; + sendbox = nullptr; + sendbox_multi = nullptr; + sendbox_multiold = nullptr; + maxsendlist = nullptr; + sendlist = nullptr; + requests = nullptr; + nprocmax = nullptr; + nexchproc = nullptr; + nexchprocmax = nullptr; + exchproc = nullptr; + exchnum = nullptr; +} + /* ---------------------------------------------------------------------- initialize comm buffers and other data structs local to CommTiled ------------------------------------------------------------------------- */ void CommTiled::init_buffers() { - buf_send = buf_recv = nullptr; maxsend = maxrecv = BUFMIN; grow_send(maxsend,2); grow_recv(maxrecv,1); maxoverlap = 0; - overlap = nullptr; - rcbinfo = nullptr; - cutghostmulti = nullptr; - cutghostmultiold = nullptr; - sendbox_multi = nullptr; - sendbox_multiold = nullptr; // Note this may skip growing multi arrays, will call again in init() maxswap = 6; @@ -113,9 +145,9 @@ void CommTiled::init_buffers() void CommTiled::init() { - if (init_buffers_flag) { + if (!init_buffers_flag) { init_buffers(); - init_buffers_flag = 0; + init_buffers_flag = 1; } Comm::init(); @@ -2436,10 +2468,8 @@ void CommTiled::deallocate_swap(int n) delete [] maxsendlist[i]; - if (sendlist && sendlist[i]) { - for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); - delete [] sendlist[i]; - } + for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); + delete [] sendlist[i]; } delete [] sendproc; diff --git a/src/comm_tiled.h b/src/comm_tiled.h index 095e7bf5aa..857cddf033 100644 --- a/src/comm_tiled.h +++ b/src/comm_tiled.h @@ -117,8 +117,9 @@ class CommTiled : public Comm { double *sublo, *subhi; int dimension; - int init_buffers_flag; + void init_pointers(); void init_buffers(); + int init_buffers_flag; // box drop and other functions From 4dbfa5483b57465262a98b312475cee25b433cd9 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 27 Feb 2024 14:50:20 -0700 Subject: [PATCH 133/185] Fix memory leak --- src/KOKKOS/comm_tiled_kokkos.cpp | 3 ++- src/comm_tiled.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/KOKKOS/comm_tiled_kokkos.cpp b/src/KOKKOS/comm_tiled_kokkos.cpp index 60e7f7d9a8..bd65bcf221 100644 --- a/src/KOKKOS/comm_tiled_kokkos.cpp +++ b/src/KOKKOS/comm_tiled_kokkos.cpp @@ -36,6 +36,7 @@ static constexpr int BUFEXTRA = 1000; CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) { + sendlist = nullptr; } /* ---------------------------------------------------------------------- */ @@ -47,6 +48,7 @@ CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp, Comm *oldcomm) : CommTiled(_lmp,oldcomm) { + sendlist = nullptr; } /* ---------------------------------------------------------------------- */ @@ -57,7 +59,6 @@ CommTiledKokkos::~CommTiledKokkos() sendlist = nullptr; buf_send = nullptr; buf_recv = nullptr; - maxswap = 0; } /* ---------------------------------------------------------------------- */ diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 59ab993655..b864e0523d 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -2468,8 +2468,10 @@ void CommTiled::deallocate_swap(int n) delete [] maxsendlist[i]; - for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); - delete [] sendlist[i]; + if (sendlist && sendlist[i]) { + for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); + delete [] sendlist[i]; + } } delete [] sendproc; From eb9b1e163d72a2e65290512428ac776a33580faa Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 27 Feb 2024 10:31:43 -0500 Subject: [PATCH 134/185] modernize and coding style/formatting improvements --- src/BOCS/compute_pressure_bocs.cpp | 36 ++++++++++---------- src/BOCS/fix_bocs.cpp | 38 +++++++++------------ src/BODY/compute_temp_body.cpp | 54 ++++++++++++++---------------- src/DRUDE/compute_temp_drude.cpp | 25 ++++++-------- src/DRUDE/fix_drude.cpp | 5 +-- 5 files changed, 70 insertions(+), 88 deletions(-) diff --git a/src/BOCS/compute_pressure_bocs.cpp b/src/BOCS/compute_pressure_bocs.cpp index a8bc9596cc..16d6c91a1f 100644 --- a/src/BOCS/compute_pressure_bocs.cpp +++ b/src/BOCS/compute_pressure_bocs.cpp @@ -42,7 +42,7 @@ ComputePressureBocs::ComputePressureBocs(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), vptr(nullptr), id_temp(nullptr) { - if (narg < 4) error->all(FLERR,"Illegal compute pressure/bocs command"); + if (narg < 4) utils::missing_cmd_args(FLERR,"compute pressure/bocs", error); if (igroup) error->all(FLERR,"Compute pressure/bocs must use group all"); scalar_flag = vector_flag = 1; @@ -62,12 +62,12 @@ ComputePressureBocs::ComputePressureBocs(LAMMPS *lmp, int narg, char **arg) : else { id_temp = utils::strdup(arg[3]); - int icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Could not find compute pressure/bocs temperature ID"); - if (modify->compute[icompute]->tempflag == 0) - error->all(FLERR,"Compute pressure/bocs temperature ID does not " - "compute temperature"); + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR,"Could not find compute pressure/bocs temperature compute {}", id_temp); + if (temperature->tempflag == 0) + error->all(FLERR,"Compute pressure/bocs temperature compute {} does not compute " + "temperature", id_temp); } // process optional args @@ -137,10 +137,9 @@ void ComputePressureBocs::init() // fixes could have changed or compute_modify could have changed it if (keflag) { - int icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Could not find compute pressure/bocs temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR,"Could not find compute pressure/bocs temperature compute {}", id_temp); } // detect contributions to virial @@ -158,10 +157,8 @@ void ComputePressureBocs::init() if (improperflag && force->improper) nvirial++; } if (fixflag) { - Fix **fix = modify->fix; - int nfix = modify->nfix; - for (int i = 0; i < nfix; i++) - if (fix[i]->thermo_virial) nvirial++; + for (const auto &ifix : modify->get_fix_list()) + if (ifix->thermo_virial) nvirial++; } if (nvirial) { @@ -174,10 +171,11 @@ void ComputePressureBocs::init() vptr[nvirial++] = force->dihedral->virial; if (improperflag && force->improper) vptr[nvirial++] = force->improper->virial; - if (fixflag) - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->virial_global_flag && modify->fix[i]->thermo_virial) - vptr[nvirial++] = modify->fix[i]->virial; + if (fixflag) { + for (const auto &ifix : modify->get_fix_list()) + if (ifix->virial_global_flag && ifix->thermo_virial) + vptr[nvirial++] = ifix->virial; + } } // flag Kspace contribution separately, since not summed across procs diff --git a/src/BOCS/fix_bocs.cpp b/src/BOCS/fix_bocs.cpp index 409ec8507b..d6beb889ff 100644 --- a/src/BOCS/fix_bocs.cpp +++ b/src/BOCS/fix_bocs.cpp @@ -145,15 +145,14 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"temp") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix bocs command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR,"fix bocs temp", error); tstat_flag = 1; t_start = utils::numeric(FLERR,arg[iarg+1],false,lmp); t_target = t_start; t_stop = utils::numeric(FLERR,arg[iarg+2],false,lmp); t_period = utils::numeric(FLERR,arg[iarg+3],false,lmp); if (t_start <= 0.0 || t_stop <= 0.0) - error->all(FLERR, - "Target temperature for fix bocs cannot be 0.0"); + error->all(FLERR, "Target temperature for fix bocs cannot be 0.0"); iarg += 4; } else if (strcmp(arg[iarg],"iso") == 0) { error->all(FLERR,"Illegal fix bocs command. Pressure fix must be " @@ -164,12 +163,9 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : "followed by: P_0 P_f P_coupl"); p_match_flag = 1; pcouple = XYZ; - p_start[0] = p_start[1] = p_start[2] = - utils::numeric(FLERR,arg[iarg+1],false,lmp); - p_stop[0] = p_stop[1] = p_stop[2] = - utils::numeric(FLERR,arg[iarg+2],false,lmp); - p_period[0] = p_period[1] = p_period[2] = - utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_start[0] = p_start[1] = p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + p_stop[0] = p_stop[1] = p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + p_period[0] = p_period[1] = p_period[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); p_flag[0] = p_flag[1] = p_flag[2] = 1; p_flag[3] = p_flag[4] = p_flag[5] = 0; // MRD @@ -383,7 +379,7 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(fmt::format("{} all temp",id_temp)); + temperature = modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style @@ -391,7 +387,7 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : // pass id_temp as 4th arg to pressure constructor id_press = utils::strdup(std::string(id)+"_press"); - modify->add_compute(fmt::format("{} all PRESSURE/BOCS {}",id_press,id_temp)); + pressure = modify->add_compute(fmt::format("{} all PRESSURE/BOCS {}",id_press,id_temp)); pcomputeflag = 1; /*~ MRD End of stuff copied from fix_npt.cpp~*/ @@ -1435,24 +1431,22 @@ int FixBocs::modify_param(int narg, char **arg) delete[] id_temp; id_temp = utils::strdup(arg[1]); - int icompute = modify->find_compute(arg[1]); - if (icompute < 0) - error->all(FLERR,"Could not find fix_modify temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR,"Could not find fix_modify temperature compute {}", id_temp); if (temperature->tempflag == 0) - error->all(FLERR, - "Fix_modify temperature ID does not compute temperature"); + error->all(FLERR, "Fix_modify temperature compute {} does not compute temperature", id_temp); if (temperature->igroup != 0 && comm->me == 0) - error->warning(FLERR,"Temperature for fix modify is not for group all"); + error->warning(FLERR,"Temperature compute {} for fix modify is not for group all", id_temp); // reset id_temp of pressure to new temperature ID if (pstat_flag) { - icompute = modify->find_compute(id_press); - if (icompute < 0) - error->all(FLERR,"Pressure ID for fix modify does not exist"); - modify->compute[icompute]->reset_extra_compute_fix(id_temp); + pressure = modify->get_compute_by_id(id_press); + if (!pressure) + error->all(FLERR,"Pressure ID {} for fix modify does not exist", id_press); + pressure->reset_extra_compute_fix(id_temp); } return 2; diff --git a/src/BODY/compute_temp_body.cpp b/src/BODY/compute_temp_body.cpp index 319c2ff986..39b2518600 100644 --- a/src/BODY/compute_temp_body.cpp +++ b/src/BODY/compute_temp_body.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -19,27 +18,28 @@ #include "compute_temp_body.h" -#include -#include "math_extra.h" #include "atom.h" #include "atom_vec_body.h" -#include "update.h" -#include "force.h" #include "domain.h" -#include "modify.h" -#include "group.h" #include "error.h" +#include "force.h" +#include "group.h" +#include "math_extra.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; -enum{ROTATE,ALL}; +enum { ROTATE, ALL }; /* ---------------------------------------------------------------------- */ ComputeTempBody::ComputeTempBody(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), id_bias(nullptr), tbias(nullptr), avec(nullptr) + Compute(lmp, narg, arg), id_bias(nullptr), tbias(nullptr), avec(nullptr) { - if (narg < 3) error->all(FLERR,"Illegal compute temp/body command"); + if (narg < 3) utils::missing_cmd_args(FLERR, "compute temp/body", error); scalar_flag = vector_flag = 1; size_vector = 6; @@ -48,25 +48,24 @@ ComputeTempBody::ComputeTempBody(LAMMPS *lmp, int narg, char **arg) : tempflag = 1; tempbias = 0; - id_bias = nullptr; mode = ALL; + // clang-format off + int iarg = 3; while (iarg < narg) { if (strcmp(arg[iarg],"bias") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute temp/body command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "compute temp/body bias", error); tempbias = 1; id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"dof") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute temp/body command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "compute temp/body dof", error); if (strcmp(arg[iarg+1],"rotate") == 0) mode = ROTATE; else if (strcmp(arg[iarg+1],"all") == 0) mode = ALL; - else error->all(FLERR,"Illegal compute temp/body command"); + else error->all(FLERR,"Unknown compute temp/body dof keyword {}", arg[iarg+1]); iarg += 2; - } else error->all(FLERR,"Illegal compute temp/body command"); + } else error->all(FLERR,"Unknown compute temp/body keyword {}", arg[iarg]); } vector = new double[size_vector]; @@ -77,8 +76,8 @@ ComputeTempBody::ComputeTempBody(LAMMPS *lmp, int narg, char **arg) : ComputeTempBody::~ComputeTempBody() { - delete [] id_bias; - delete [] vector; + delete[] id_bias; + delete[] vector; } /* ---------------------------------------------------------------------- */ @@ -88,8 +87,7 @@ void ComputeTempBody::init() // error check avec = dynamic_cast(atom->style_match("body")); - if (!avec) - error->all(FLERR,"Compute temp/body requires atom style body"); + if (!avec) error->all(FLERR,"Compute temp/body requires atom style body"); // check that all particles are finite-size, no point particles allowed @@ -99,18 +97,16 @@ void ComputeTempBody::init() for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) - if (body[i] < 0) - error->one(FLERR,"Compute temp/body requires bodies"); + if (body[i] < 0) error->one(FLERR,"Compute temp/body requires bodies"); if (tempbias) { - int i = modify->find_compute(id_bias); - if (i < 0) - error->all(FLERR,"Could not find compute ID for temperature bias"); - tbias = modify->compute[i]; + tbias = modify->get_compute_by_id(id_bias); + if (!tbias) + error->all(FLERR,"Could not find compute {} for temperature bias", id_bias); if (tbias->tempflag == 0) - error->all(FLERR,"Bias compute does not calculate temperature"); + error->all(FLERR,"Bias compute {} does not calculate temperature", id_bias); if (tbias->tempbias == 0) - error->all(FLERR,"Bias compute does not calculate a velocity bias"); + error->all(FLERR,"Bias compute {} does not calculate a velocity bias", id_bias); if (tbias->igroup != igroup) error->all(FLERR,"Bias compute group does not match compute group"); if (strcmp(tbias->style,"temp/region") == 0) tempbias = 2; diff --git a/src/DRUDE/compute_temp_drude.cpp b/src/DRUDE/compute_temp_drude.cpp index b309346934..535808580e 100644 --- a/src/DRUDE/compute_temp_drude.cpp +++ b/src/DRUDE/compute_temp_drude.cpp @@ -54,20 +54,19 @@ ComputeTempDrude::ComputeTempDrude(LAMMPS *lmp, int narg, char **arg) : ComputeTempDrude::~ComputeTempDrude() { - delete [] vector; - delete [] extlist; - delete [] id_temp; + delete[] vector; + delete[] extlist; + delete[] id_temp; } /* ---------------------------------------------------------------------- */ void ComputeTempDrude::init() { - int ifix; - for (ifix = 0; ifix < modify->nfix; ifix++) - if (strcmp(modify->fix[ifix]->style,"drude") == 0) break; - if (ifix == modify->nfix) error->all(FLERR, "compute temp/drude requires fix drude"); - fix_drude = dynamic_cast(modify->fix[ifix]); + // Fix drude already checks that there is only one fix drude instance + auto &fixes = modify->get_fix_by_style("drude"); + if (fixes.size() == 0) error->all(FLERR, "compute temp/drude requires fix drude"); + fix_drude = dynamic_cast(fixes[0]); if (!comm->ghost_velocity) error->all(FLERR,"compute temp/drude requires ghost velocities. Use comm_modify vel yes"); @@ -118,14 +117,12 @@ int ComputeTempDrude::modify_param(int narg, char **arg) delete [] id_temp; id_temp = utils::strdup(arg[1]); - int icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Could not find fix_modify temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR,"Could not find fix_modify temperature compute {}", id_temp); if (temperature->tempflag == 0) - error->all(FLERR, - "Fix_modify temperature ID does not compute temperature"); + error->all(FLERR, "Fix_modify temperature compute {} does not compute temperature", id_temp); if (temperature->igroup != igroup && comm->me == 0) error->warning(FLERR,"Group for fix_modify temp != fix group"); return 2; diff --git a/src/DRUDE/fix_drude.cpp b/src/DRUDE/fix_drude.cpp index 56a5cd42f6..4270c2f402 100644 --- a/src/DRUDE/fix_drude.cpp +++ b/src/DRUDE/fix_drude.cpp @@ -83,10 +83,7 @@ FixDrude::~FixDrude() void FixDrude::init() { - int count = 0; - for (int i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"drude") == 0) count++; - if (count > 1) error->all(FLERR,"More than one fix drude"); + if (modify->get_fix_by_style("drude").size() > 1) error->all(FLERR,"More than one fix drude"); if (!rebuildflag) rebuild_special(); } From 73e42481f715a6af893b2fd3e46a3a4a7bc46e8f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 27 Feb 2024 20:55:52 -0500 Subject: [PATCH 135/185] modernize and consolidate ML compute styles --- src/ML-IAP/compute_mliap.cpp | 31 ++++++------------ src/ML-PACE/compute_pace.cpp | 53 +++++++++++++----------------- src/ML-PACE/compute_pace.h | 2 ++ src/ML-SNAP/compute_snap.cpp | 62 +++++++++++++----------------------- src/ML-SNAP/compute_snap.h | 3 +- 5 files changed, 60 insertions(+), 91 deletions(-) diff --git a/src/ML-IAP/compute_mliap.cpp b/src/ML-IAP/compute_mliap.cpp index 4fa88abad1..38e0912344 100644 --- a/src/ML-IAP/compute_mliap.cpp +++ b/src/ML-IAP/compute_mliap.cpp @@ -19,10 +19,10 @@ #include "compute_mliap.h" #include "mliap_data.h" -#include "mliap_model_linear.h" -#include "mliap_model_quadratic.h" #include "mliap_descriptor_snap.h" #include "mliap_descriptor_so3.h" +#include "mliap_model_linear.h" +#include "mliap_model_quadratic.h" #ifdef MLIAP_PYTHON #include "mliap_model_python.h" #endif @@ -41,17 +41,17 @@ using namespace LAMMPS_NS; -enum{SCALAR,VECTOR,ARRAY}; +enum { SCALAR, VECTOR, ARRAY }; ComputeMLIAP::ComputeMLIAP(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), mliaparray(nullptr), - mliaparrayall(nullptr), map(nullptr) + Compute(lmp, narg, arg), mliaparray(nullptr), mliaparrayall(nullptr), list(nullptr), + map(nullptr), model(nullptr), descriptor(nullptr), data(nullptr), c_pe(nullptr), + c_virial(nullptr) { array_flag = 1; extarray = 0; - if (narg < 4) - error->all(FLERR,"Illegal compute mliap command"); + if (narg < 4) utils::missing_cmd_args(FLERR, "compute mliap", error); // default values @@ -130,7 +130,6 @@ ComputeMLIAP::ComputeMLIAP(LAMMPS *lmp, int narg, char **arg) : ComputeMLIAP::~ComputeMLIAP() { - modify->delete_compute(id_virial); memory->destroy(mliaparray); @@ -180,23 +179,13 @@ void ComputeMLIAP::init() // find compute for reference energy - std::string id_pe = std::string("thermo_pe"); - int ipe = modify->find_compute(id_pe); - if (ipe == -1) - error->all(FLERR,"compute thermo_pe does not exist."); - c_pe = modify->compute[ipe]; + c_pe = modify->get_compute_by_id("thermo_pe"); + if (!c_pe) error->all(FLERR,"Compute thermo_pe does not exist."); // add compute for reference virial tensor id_virial = id + std::string("_press"); - std::string pcmd = id_virial + " all pressure NULL virial"; - modify->add_compute(pcmd); - - int ivirial = modify->find_compute(id_virial); - if (ivirial == -1) - error->all(FLERR,"compute mliap_press does not exist."); - c_virial = modify->compute[ivirial]; - + c_virial = modify->add_compute(id_virial + " all pressure NULL virial"); } diff --git a/src/ML-PACE/compute_pace.cpp b/src/ML-PACE/compute_pace.cpp index b96432cfe3..a9a31bdbf0 100644 --- a/src/ML-PACE/compute_pace.cpp +++ b/src/ML-PACE/compute_pace.cpp @@ -11,24 +11,26 @@ ------------------------------------------------------------------------- */ #include "compute_pace.h" -#include "ace-evaluator/ace_evaluator.h" -#include "ace-evaluator/ace_c_basis.h" + #include "ace-evaluator/ace_abstract_basis.h" +#include "ace-evaluator/ace_c_basis.h" +#include "ace-evaluator/ace_evaluator.h" #include "ace-evaluator/ace_types.h" -#include -#include #include "atom.h" -#include "update.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "modify.h" -#include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" -#include "force.h" +#include "neighbor.h" #include "pair.h" -#include "comm.h" -#include "memory.h" -#include "error.h" +#include "update.h" + +#include +#include namespace LAMMPS_NS { struct ACECimpl { @@ -41,14 +43,15 @@ struct ACECimpl { ACECTildeBasisSet *basis_set; ACECTildeEvaluator *ace; }; -} +} // namespace LAMMPS_NS using namespace LAMMPS_NS; enum { SCALAR, VECTOR, ARRAY }; ComputePACE::ComputePACE(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), pace(nullptr), paceall(nullptr), - pace_peratom(nullptr), map(nullptr), cg(nullptr), c_pe(nullptr), c_virial(nullptr) + Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), pace(nullptr), paceall(nullptr), + pace_peratom(nullptr), map(nullptr), cg(nullptr), c_pe(nullptr), c_virial(nullptr), + acecimpl(nullptr) { array_flag = 1; extarray = 0; @@ -111,6 +114,8 @@ ComputePACE::ComputePACE(LAMMPS *lmp, int narg, char **arg) : ComputePACE::~ComputePACE() { + modify->delete_compute(id_virial); + delete acecimpl; memory->destroy(pace); memory->destroy(paceall); @@ -132,10 +137,7 @@ void ComputePACE::init() // need an occasional full neighbor list neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL); - int count = 0; - for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style,"pace") == 0) count++; - if (count > 1 && comm->me == 0) + if (modify->get_compute_by_style("pace").size() > 1 && comm->me == 0) error->warning(FLERR,"More than one compute pace"); // allocate memory for global array @@ -145,22 +147,13 @@ void ComputePACE::init() // find compute for reference energy - std::string id_pe = std::string("thermo_pe"); - int ipe = modify->find_compute(id_pe); - if (ipe == -1) - error->all(FLERR,"compute thermo_pe does not exist."); - c_pe = modify->compute[ipe]; + c_pe = modify->get_compute_by_id("thermo_pe"); + if (!c_pe) error->all(FLERR,"Compute thermo_pe does not exist."); // add compute for reference virial tensor - std::string id_virial = std::string("pace_press"); - std::string pcmd = id_virial + " all pressure NULL virial"; - modify->add_compute(pcmd); - - int ivirial = modify->find_compute(id_virial); - if (ivirial == -1) - error->all(FLERR,"compute pace_press does not exist."); - c_virial = modify->compute[ivirial]; + id_virial = id + std::string("_press"); + c_virial = modify->add_compute(id_virial + " all pressure NULL virial"); } /* ---------------------------------------------------------------------- */ diff --git a/src/ML-PACE/compute_pace.h b/src/ML-PACE/compute_pace.h index 496c8a16d3..3fa59405ea 100644 --- a/src/ML-PACE/compute_pace.h +++ b/src/ML-PACE/compute_pace.h @@ -45,8 +45,10 @@ class ComputePACE : public Compute { int bikflag, bik_rows, dgradflag, dgrad_rows; double *cg; double cutmax; + Compute *c_pe; Compute *c_virial; + std::string id_virial; void dbdotr_compute(); struct ACECimpl *acecimpl; diff --git a/src/ML-SNAP/compute_snap.cpp b/src/ML-SNAP/compute_snap.cpp index 3141791f6c..99a9a96361 100644 --- a/src/ML-SNAP/compute_snap.cpp +++ b/src/ML-SNAP/compute_snap.cpp @@ -30,14 +30,13 @@ using namespace LAMMPS_NS; -enum{SCALAR,VECTOR,ARRAY}; +enum { SCALAR, VECTOR, ARRAY }; ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), snap(nullptr), - snapall(nullptr), snap_peratom(nullptr), radelem(nullptr), wjelem(nullptr), - sinnerelem(nullptr), dinnerelem(nullptr), snaptr(nullptr) + Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), snap(nullptr), snapall(nullptr), + snap_peratom(nullptr), radelem(nullptr), wjelem(nullptr), map(nullptr), sinnerelem(nullptr), + dinnerelem(nullptr), snaptr(nullptr), c_pe(nullptr), c_virial(nullptr) { - array_flag = 1; extarray = 0; @@ -172,22 +171,18 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all( - FLERR, - "Illegal compute {} command: switchinnerflag = 1, missing sinner/dinner keyword", - style); + error->all(FLERR, "Illegal compute {} command: switchinnerflag = 1, " + "missing sinner/dinner keyword", style); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all( - FLERR, - "Illegal compute {} command: switchinnerflag = 0, unexpected sinner/dinner keyword", - style); + error->all(FLERR, "Illegal compute {} command: switchinnerflag = 0, " + "unexpected sinner/dinner keyword", style); if (dgradflag && !bikflag) - error->all(FLERR,"Illegal compute snap command: dgradflag=1 requires bikflag=1"); + error->all(FLERR, "Illegal compute snap command: dgradflag=1 requires bikflag=1"); if (dgradflag && quadraticflag) - error->all(FLERR,"Illegal compute snap command: dgradflag=1 not implemented for quadratic SNAP"); + error->all(FLERR, "Illegal compute snap command: dgradflag=1 not implemented for quadratic SNAP"); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); @@ -210,7 +205,8 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : if (dgradflag) { size_array_rows = bik_rows + 3*natoms*natoms + 1; size_array_cols = nvalues + 3; - error->warning(FLERR,"dgradflag=1 creates a N^2 array, beware of large systems."); + if (comm->me == 0) + error->warning(FLERR, "dgradflag=1 creates a N^2 array, beware of large systems."); } else size_array_cols = nvalues*atom->ntypes + 1; lastcol = size_array_cols-1; @@ -249,7 +245,8 @@ void ComputeSnap::init() error->all(FLERR,"Compute snap requires a pair style be defined"); if (cutmax > force->pair->cutforce) - error->all(FLERR,"Compute snap cutoff is longer than pairwise cutoff"); + error->all(FLERR,"Compute snap cutoff {} is longer than pairwise cutoff {}", + cutmax, force->pair->cutforce); // need an occasional full neighbor list @@ -261,31 +258,19 @@ void ComputeSnap::init() // allocate memory for global array - memory->create(snap,size_array_rows,size_array_cols, - "snap:snap"); - memory->create(snapall,size_array_rows,size_array_cols, - "snap:snapall"); + memory->create(snap,size_array_rows,size_array_cols, "snap:snap"); + memory->create(snapall,size_array_rows,size_array_cols, "snap:snapall"); array = snapall; - // find compute for reference energy + // find compute for global reference potential energy - std::string id_pe = std::string("thermo_pe"); - int ipe = modify->find_compute(id_pe); - if (ipe == -1) - error->all(FLERR,"compute thermo_pe does not exist."); - c_pe = modify->compute[ipe]; + c_pe = modify->get_compute_by_id("thermo_pe"); + if (!c_pe) error->all(FLERR,"compute thermo_pe does not exist."); - // add compute for reference virial tensor - - std::string id_virial = std::string("snap_press"); - std::string pcmd = id_virial + " all pressure NULL virial"; - modify->add_compute(pcmd); - - int ivirial = modify->find_compute(id_virial); - if (ivirial == -1) - error->all(FLERR,"compute snap_press does not exist."); - c_virial = modify->compute[ivirial]; + // add compute for global reference virial tensor + id_virial = id + std::string("_press"); + c_virial = modify->add_compute(id_virial + " all pressure NULL virial"); } @@ -309,8 +294,7 @@ void ComputeSnap::compute_array() if (atom->nmax > nmax) { memory->destroy(snap_peratom); nmax = atom->nmax; - memory->create(snap_peratom,nmax,size_peratom, - "snap:snap_peratom"); + memory->create(snap_peratom,nmax,size_peratom, "snap:snap_peratom"); } // clear global array diff --git a/src/ML-SNAP/compute_snap.h b/src/ML-SNAP/compute_snap.h index 2b8b972bbc..fe0b35d9e3 100644 --- a/src/ML-SNAP/compute_snap.h +++ b/src/ML-SNAP/compute_snap.h @@ -28,6 +28,7 @@ class ComputeSnap : public Compute { public: ComputeSnap(class LAMMPS *, int, char **); ~ComputeSnap() override; + void init() override; void init_list(int, class NeighList *) override; void compute_array() override; @@ -56,10 +57,10 @@ class ComputeSnap : public Compute { Compute *c_pe; Compute *c_virial; + std::string id_virial; void dbdotr_compute(); }; - } // namespace LAMMPS_NS #endif From 5967865af985da9c0faf4840a5b443c71d87d7d3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 27 Feb 2024 22:42:13 -0500 Subject: [PATCH 136/185] remove unused class member --- src/ML-PACE/compute_pace.cpp | 3 +-- src/ML-PACE/compute_pace.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ML-PACE/compute_pace.cpp b/src/ML-PACE/compute_pace.cpp index a9a31bdbf0..c2a0f9a9e6 100644 --- a/src/ML-PACE/compute_pace.cpp +++ b/src/ML-PACE/compute_pace.cpp @@ -50,8 +50,7 @@ using namespace LAMMPS_NS; enum { SCALAR, VECTOR, ARRAY }; ComputePACE::ComputePACE(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), pace(nullptr), paceall(nullptr), - pace_peratom(nullptr), map(nullptr), cg(nullptr), c_pe(nullptr), c_virial(nullptr), - acecimpl(nullptr) + pace_peratom(nullptr), map(nullptr), c_pe(nullptr), c_virial(nullptr), acecimpl(nullptr) { array_flag = 1; extarray = 0; diff --git a/src/ML-PACE/compute_pace.h b/src/ML-PACE/compute_pace.h index 3fa59405ea..23243b0066 100644 --- a/src/ML-PACE/compute_pace.h +++ b/src/ML-PACE/compute_pace.h @@ -43,7 +43,6 @@ class ComputePACE : public Compute { double **pace_peratom; int *map; // map types to [0,nelements) int bikflag, bik_rows, dgradflag, dgrad_rows; - double *cg; double cutmax; Compute *c_pe; From 1359c52f302aba77a79a8afb43f74ba7c55f03ba Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 27 Feb 2024 23:42:24 -0500 Subject: [PATCH 137/185] include-what-you-use updates --- src/angle_write.cpp | 1 - src/atom_vec_sphere.cpp | 2 -- src/compute_aggregate_atom.cpp | 1 - src/compute_cluster_atom.cpp | 1 - src/compute_cna_atom.cpp | 1 - src/compute_count_type.cpp | 4 ++-- src/compute_dipole_chunk.h | 3 --- src/compute_erotate_sphere_atom.cpp | 35 ++++++++++++++--------------- src/compute_ke_atom.cpp | 2 +- src/dihedral_write.cpp | 1 - src/dump_grid.cpp | 1 - src/fix_deform.cpp | 1 - src/fix_enforce2d.cpp | 1 - src/fix_pair.cpp | 2 ++ src/fix_press_langevin.cpp | 1 - src/fix_vector.cpp | 2 ++ src/fix_wall_lj126.cpp | 2 -- src/fix_wall_lj93.cpp | 2 -- src/grid2d.cpp | 2 ++ src/grid3d.cpp | 2 ++ src/integrate.h | 2 +- src/lammps.cpp | 1 - src/min.h | 4 ++-- src/npair_bin.cpp | 2 ++ 24 files changed, 33 insertions(+), 43 deletions(-) diff --git a/src/angle_write.cpp b/src/angle_write.cpp index 0a0c457000..48420ae7be 100644 --- a/src/angle_write.cpp +++ b/src/angle_write.cpp @@ -25,7 +25,6 @@ #include "error.h" #include "force.h" #include "input.h" -#include "lammps.h" #include "math_const.h" #include "update.h" diff --git a/src/atom_vec_sphere.cpp b/src/atom_vec_sphere.cpp index 3e8c2fd2a3..3c7be5d3ee 100644 --- a/src/atom_vec_sphere.cpp +++ b/src/atom_vec_sphere.cpp @@ -19,8 +19,6 @@ #include "math_const.h" #include "modify.h" -#include - using namespace LAMMPS_NS; using namespace MathConst; diff --git a/src/compute_aggregate_atom.cpp b/src/compute_aggregate_atom.cpp index 5a489092b7..8c6f7165a2 100644 --- a/src/compute_aggregate_atom.cpp +++ b/src/compute_aggregate_atom.cpp @@ -31,7 +31,6 @@ #include "update.h" #include -#include using namespace LAMMPS_NS; diff --git a/src/compute_cluster_atom.cpp b/src/compute_cluster_atom.cpp index ba0f263747..0021d32e2c 100644 --- a/src/compute_cluster_atom.cpp +++ b/src/compute_cluster_atom.cpp @@ -25,7 +25,6 @@ #include "update.h" #include -#include using namespace LAMMPS_NS; diff --git a/src/compute_cna_atom.cpp b/src/compute_cna_atom.cpp index a09a671c07..b92dca8f86 100644 --- a/src/compute_cna_atom.cpp +++ b/src/compute_cna_atom.cpp @@ -29,7 +29,6 @@ #include "update.h" #include -#include using namespace LAMMPS_NS; diff --git a/src/compute_count_type.cpp b/src/compute_count_type.cpp index 3d4815f9ff..d430b23e11 100644 --- a/src/compute_count_type.cpp +++ b/src/compute_count_type.cpp @@ -14,12 +14,12 @@ #include "compute_count_type.h" #include "atom.h" -#include "domain.h" #include "error.h" #include "force.h" -#include "group.h" #include "update.h" +#include + using namespace LAMMPS_NS; enum { ATOM, BOND, ANGLE, DIHEDRAL, IMPROPER }; diff --git a/src/compute_dipole_chunk.h b/src/compute_dipole_chunk.h index 603e6a4353..3ed875283f 100644 --- a/src/compute_dipole_chunk.h +++ b/src/compute_dipole_chunk.h @@ -23,7 +23,6 @@ ComputeStyle(dipole/chunk,ComputeDipoleChunk); #include "compute_chunk.h" namespace LAMMPS_NS { -class Fix; class ComputeDipoleChunk : public ComputeChunk { public: @@ -43,8 +42,6 @@ class ComputeDipoleChunk : public ComputeChunk { void allocate() override; }; - } // namespace LAMMPS_NS - #endif #endif diff --git a/src/compute_erotate_sphere_atom.cpp b/src/compute_erotate_sphere_atom.cpp index b1aca68614..fa1ce8a180 100644 --- a/src/compute_erotate_sphere_atom.cpp +++ b/src/compute_erotate_sphere_atom.cpp @@ -12,28 +12,25 @@ ------------------------------------------------------------------------- */ #include "compute_erotate_sphere_atom.h" -#include + #include "atom.h" -#include "update.h" -#include "modify.h" #include "comm.h" +#include "error.h" #include "force.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "update.h" using namespace LAMMPS_NS; -static constexpr double INERTIA = 0.4; // moment of inertia prefactor for sphere +static constexpr double INERTIA = 0.4; // moment of inertia prefactor for sphere /* ---------------------------------------------------------------------- */ -ComputeErotateSphereAtom:: -ComputeErotateSphereAtom(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - erot(nullptr) +ComputeErotateSphereAtom::ComputeErotateSphereAtom(LAMMPS *lmp, int narg, char **arg) : + Compute(lmp, narg, arg), erot(nullptr) { - if (narg != 3) - error->all(FLERR,"Illegal compute erotate/sphere//atom command"); + if (narg != 3) error->all(FLERR, "Illegal compute erotate/sphere//atom command"); peratom_flag = 1; size_peratom_cols = 0; @@ -41,9 +38,9 @@ ComputeErotateSphereAtom(LAMMPS *lmp, int narg, char **arg) : // error check if (!atom->omega_flag) - error->all(FLERR,"Compute erotate/sphere/atom requires atom attribute omega"); + error->all(FLERR, "Compute erotate/sphere/atom requires atom attribute omega"); if (!atom->radius_flag) - error->all(FLERR,"Compute erotate/sphere/atom requires atom attribute radius"); + error->all(FLERR, "Compute erotate/sphere/atom requires atom attribute radius"); nmax = 0; } @@ -76,7 +73,7 @@ void ComputeErotateSphereAtom::compute_peratom() if (atom->nmax > nmax) { memory->destroy(erot); nmax = atom->nmax; - memory->create(erot,nmax,"erotate/sphere/atom:erot"); + memory->create(erot, nmax, "erotate/sphere/atom:erot"); vector_atom = erot; } @@ -91,10 +88,12 @@ void ComputeErotateSphereAtom::compute_peratom() for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { - erot[i] = (omega[i][0]*omega[i][0] + omega[i][1]*omega[i][1] + - omega[i][2]*omega[i][2]) * radius[i]*radius[i]*rmass[i]; + erot[i] = + (omega[i][0] * omega[i][0] + omega[i][1] * omega[i][1] + omega[i][2] * omega[i][2]) * + radius[i] * radius[i] * rmass[i]; erot[i] *= pfactor; - } else erot[i] = 0.0; + } else + erot[i] = 0.0; } } @@ -104,6 +103,6 @@ void ComputeErotateSphereAtom::compute_peratom() double ComputeErotateSphereAtom::memory_usage() { - double bytes = (double)nmax * sizeof(double); + double bytes = (double) nmax * sizeof(double); return bytes; } diff --git a/src/compute_ke_atom.cpp b/src/compute_ke_atom.cpp index 9a329232b3..e8ab1b8b25 100644 --- a/src/compute_ke_atom.cpp +++ b/src/compute_ke_atom.cpp @@ -12,6 +12,7 @@ ------------------------------------------------------------------------- */ #include "compute_ke_atom.h" + #include "atom.h" #include "comm.h" #include "error.h" @@ -19,7 +20,6 @@ #include "memory.h" #include "modify.h" #include "update.h" -#include using namespace LAMMPS_NS; diff --git a/src/dihedral_write.cpp b/src/dihedral_write.cpp index 375373523b..dd1ca1de6a 100644 --- a/src/dihedral_write.cpp +++ b/src/dihedral_write.cpp @@ -25,7 +25,6 @@ #include "error.h" #include "force.h" #include "input.h" -#include "lammps.h" #include "math_const.h" #include "update.h" diff --git a/src/dump_grid.cpp b/src/dump_grid.cpp index 4c89b05739..ac42a85b01 100644 --- a/src/dump_grid.cpp +++ b/src/dump_grid.cpp @@ -23,7 +23,6 @@ #include "grid3d.h" #include "memory.h" #include "modify.h" -#include "region.h" #include "update.h" #include diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index c19423d844..bb27faeaa8 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -36,7 +36,6 @@ #include #include #include -#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/fix_enforce2d.cpp b/src/fix_enforce2d.cpp index c13e2147a3..048f8de543 100644 --- a/src/fix_enforce2d.cpp +++ b/src/fix_enforce2d.cpp @@ -17,7 +17,6 @@ #include "atom.h" #include "domain.h" #include "error.h" -#include "modify.h" #include "respa.h" #include "update.h" diff --git a/src/fix_pair.cpp b/src/fix_pair.cpp index 66212684a8..93a88a60c9 100644 --- a/src/fix_pair.cpp +++ b/src/fix_pair.cpp @@ -23,6 +23,8 @@ #include "update.h" #include "fmt/format.h" +#include + using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/fix_press_langevin.cpp b/src/fix_press_langevin.cpp index d8d2a3b04a..8116d66c0a 100644 --- a/src/fix_press_langevin.cpp +++ b/src/fix_press_langevin.cpp @@ -24,7 +24,6 @@ #include "error.h" #include "fix_deform.h" #include "force.h" -#include "group.h" #include "irregular.h" #include "kspace.h" #include "modify.h" diff --git a/src/fix_vector.cpp b/src/fix_vector.cpp index e18b53f615..7c75f93a3a 100644 --- a/src/fix_vector.cpp +++ b/src/fix_vector.cpp @@ -22,6 +22,8 @@ #include "update.h" #include "variable.h" +#include + using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/fix_wall_lj126.cpp b/src/fix_wall_lj126.cpp index f0f7750edb..d526390153 100644 --- a/src/fix_wall_lj126.cpp +++ b/src/fix_wall_lj126.cpp @@ -17,8 +17,6 @@ #include "error.h" #include "math_special.h" -#include - using namespace LAMMPS_NS; using MathSpecial::powint; diff --git a/src/fix_wall_lj93.cpp b/src/fix_wall_lj93.cpp index c0c5e86ce3..dda0298be1 100644 --- a/src/fix_wall_lj93.cpp +++ b/src/fix_wall_lj93.cpp @@ -17,8 +17,6 @@ #include "error.h" #include "math_special.h" -#include - using namespace LAMMPS_NS; using MathSpecial::powint; diff --git a/src/grid2d.cpp b/src/grid2d.cpp index ea6e8e4123..e1265839f9 100644 --- a/src/grid2d.cpp +++ b/src/grid2d.cpp @@ -23,6 +23,8 @@ #include "memory.h" #include "pair.h" +#include + using namespace LAMMPS_NS; static constexpr int DELTA = 16; diff --git a/src/grid3d.cpp b/src/grid3d.cpp index 4ce1978660..f11e5d0513 100644 --- a/src/grid3d.cpp +++ b/src/grid3d.cpp @@ -24,6 +24,8 @@ #include "math_extra.h" #include "memory.h" +#include + using namespace LAMMPS_NS; static constexpr int DELTA = 16; diff --git a/src/integrate.h b/src/integrate.h index e622f6328d..d078f4a997 100644 --- a/src/integrate.h +++ b/src/integrate.h @@ -15,9 +15,9 @@ #define LMP_INTEGRATE_H #include "pointers.h" -#include "compute.h" namespace LAMMPS_NS { +class Compute; class Integrate : protected Pointers { public: diff --git a/src/lammps.cpp b/src/lammps.cpp index 3329cb8d7b..b3659fdf50 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -66,7 +66,6 @@ #include "lmpinstalledpkgs.h" #include "lmpgitversion.h" -#include "lmpfftsettings.h" #if defined(LAMMPS_UPDATE) #define UPDATE_STRING " - " LAMMPS_UPDATE diff --git a/src/min.h b/src/min.h index b94d937fa5..a395a98bbc 100644 --- a/src/min.h +++ b/src/min.h @@ -15,9 +15,9 @@ #define LMP_MIN_H #include "pointers.h" // IWYU pragma: export -#include "compute.h" namespace LAMMPS_NS { +class Compute; class Min : protected Pointers { public: @@ -116,7 +116,7 @@ class Min : protected Pointers { int narray; // # of arrays stored by fix_minimize class FixMinimize *fix_minimize; // fix that stores auxiliary data - class Compute *pe_compute; // compute for potential energy + Compute *pe_compute; // compute for potential energy double ecurrent; // current potential energy bigint ndoftotal; // total dof for entire problem diff --git a/src/npair_bin.cpp b/src/npair_bin.cpp index d3d3415bc0..2c6fbbb49b 100644 --- a/src/npair_bin.cpp +++ b/src/npair_bin.cpp @@ -23,6 +23,8 @@ #include "neigh_list.h" #include "neighbor.h" +#include + using namespace LAMMPS_NS; using namespace NeighConst; From 0ce25755cd29d419b97233f754c5183b5a1d87bb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 28 Feb 2024 15:37:13 -0500 Subject: [PATCH 138/185] second round of include-what-you-use updates --- src/AMOEBA/amoeba_convolution.cpp | 3 - src/AMOEBA/pair_amoeba.h | 20 +++--- src/ATC/fix_atc.cpp | 8 ++- src/AWPMD/atom_vec_wavepacket.cpp | 2 + src/BPM/atom_vec_bpm_sphere.cpp | 3 - src/BPM/fix_update_special_bonds.cpp | 1 - src/CG-DNA/pair_oxdna_stk.cpp | 1 + src/CG-DNA/pair_oxrna2_stk.cpp | 1 + src/COLVARS/colvarproxy_lammps.cpp | 6 +- src/COLVARS/fix_colvars.cpp | 2 - src/DIELECTRIC/pppm_dielectric.cpp | 1 - src/DIELECTRIC/pppm_disp_dielectric.cpp | 2 + src/DPD-REACT/npair_half_bin_newton_ssa.cpp | 1 + src/DRUDE/fix_drude.cpp | 1 - src/DRUDE/fix_drude_transform.cpp | 1 - src/ELECTRODE/fix_electrode_conp.cpp | 1 + src/ELECTRODE/fix_electrode_conp.h | 1 - src/ELECTRODE/pppm_electrode.cpp | 1 + .../compute_composition_atom.cpp | 1 - .../compute_dipole_tip4p_chunk.cpp | 1 - .../compute_dipole_tip4p_chunk.h | 1 - src/EXTRA-COMPUTE/compute_rattlers_atom.cpp | 1 - src/EXTRA-COMPUTE/compute_slcsa_atom.cpp | 3 - src/EXTRA-FIX/fix_deform_pressure.cpp | 5 -- src/EXTRA-FIX/fix_efield_tip4p.cpp | 4 +- src/EXTRA-FIX/fix_nonaffine_displacement.cpp | 1 + src/EXTRA-FIX/fix_tmd.cpp | 1 + src/EXTRA-FIX/fix_wall_flow.cpp | 4 +- src/EXTRA-PAIR/pair_born_gauss.cpp | 2 - src/EXTRA-PAIR/pair_lj_cut_sphere.cpp | 3 - src/EXTRA-PAIR/pair_lj_expand_sphere.cpp | 2 - src/GRANULAR/fix_heat_flow.cpp | 4 +- src/GRANULAR/fix_wall_gran.cpp | 1 + src/GRANULAR/fix_wall_gran.h | 1 - src/GRANULAR/fix_wall_gran_region.cpp | 2 - src/GRANULAR/gran_sub_mod.cpp | 3 +- src/GRANULAR/gran_sub_mod.h | 62 +++++++++---------- src/GRANULAR/gran_sub_mod_damping.cpp | 2 + src/GRANULAR/gran_sub_mod_normal.cpp | 2 + src/GRANULAR/gran_sub_mod_rolling.cpp | 2 + src/GRANULAR/gran_sub_mod_tangential.cpp | 2 + src/GRANULAR/gran_sub_mod_twisting.cpp | 2 + src/GRANULAR/granular_model.cpp | 1 + src/GRANULAR/pair_granular.h | 1 - src/INTERLAYER/pair_aip_water_2dm.cpp | 3 - src/INTERLAYER/pair_ilp_tmd.h | 2 +- src/KOKKOS/atom_kokkos.cpp | 2 +- src/KOKKOS/atom_map_kokkos.cpp | 5 -- src/KOKKOS/atom_vec_atomic_kokkos.cpp | 1 - src/KOKKOS/atom_vec_bond_kokkos.cpp | 1 - src/KOKKOS/atom_vec_charge_kokkos.cpp | 1 - src/KOKKOS/atom_vec_dipole_kokkos.cpp | 1 - src/KOKKOS/atom_vec_full_kokkos.cpp | 1 - src/KOKKOS/atom_vec_hybrid_kokkos.cpp | 7 --- src/KOKKOS/atom_vec_kokkos.cpp | 1 - src/KOKKOS/atom_vec_sphere_kokkos.cpp | 3 - src/KOKKOS/atom_vec_spin_kokkos.cpp | 1 - src/KOKKOS/compute_ave_sphere_atom_kokkos.cpp | 7 --- .../compute_composition_atom_kokkos.cpp | 10 --- src/KOKKOS/compute_coord_atom_kokkos.cpp | 2 - src/KOKKOS/compute_erotate_sphere_kokkos.cpp | 2 - .../compute_orientorder_atom_kokkos.cpp | 3 - src/KOKKOS/compute_reaxff_atom_kokkos.cpp | 4 -- src/KOKKOS/compute_temp_deform_kokkos.cpp | 1 - src/KOKKOS/compute_temp_kokkos.cpp | 2 - src/KOKKOS/dynamical_matrix_kokkos.cpp | 9 --- src/KOKKOS/fix_acks2_reaxff_kokkos.cpp | 2 - src/KOKKOS/fix_deform_kokkos.cpp | 2 - src/KOKKOS/fix_dt_reset_kokkos.cpp | 6 +- src/KOKKOS/fix_efield_kokkos.cpp | 2 - src/KOKKOS/fix_gravity_kokkos.cpp | 1 - src/KOKKOS/fix_langevin_kokkos.h | 1 - src/KOKKOS/fix_minimize_kokkos.cpp | 2 + src/KOKKOS/fix_momentum_kokkos.cpp | 3 - src/KOKKOS/fix_neigh_history_kokkos.cpp | 1 - src/KOKKOS/fix_nh_kokkos.cpp | 4 -- src/KOKKOS/fix_nve_kokkos.cpp | 2 - src/KOKKOS/fix_nve_sphere_kokkos.cpp | 3 +- src/KOKKOS/fix_nvt_kokkos.cpp | 2 - src/KOKKOS/fix_nvt_sllod_kokkos.cpp | 8 +-- src/KOKKOS/fix_property_atom_kokkos.cpp | 1 - src/KOKKOS/fix_qeq_reaxff_kokkos.cpp | 2 - src/KOKKOS/fix_reaxff_species_kokkos.cpp | 8 +-- src/KOKKOS/fix_rx_kokkos.cpp | 3 +- src/KOKKOS/fix_setforce_kokkos.cpp | 3 - src/KOKKOS/fix_shake_kokkos.cpp | 9 --- src/KOKKOS/fix_shardlow_kokkos.cpp | 1 - src/KOKKOS/fix_spring_self_kokkos.cpp | 7 --- src/KOKKOS/fix_temp_berendsen_kokkos.cpp | 3 - src/KOKKOS/fix_temp_rescale_kokkos.cpp | 3 - src/KOKKOS/fix_viscous_kokkos.cpp | 4 -- src/KOKKOS/fix_wall_flow_kokkos.cpp | 4 +- src/KOKKOS/fix_wall_flow_kokkos.h | 1 - src/KOKKOS/fix_wall_gran_kokkos.cpp | 1 - src/KOKKOS/fix_wall_lj93_kokkos.cpp | 2 +- src/KOKKOS/fix_wall_reflect_kokkos.cpp | 2 - src/KOKKOS/min_cg_kokkos.cpp | 11 ++-- src/KOKKOS/mliap_data_kokkos.cpp | 2 - src/KOKKOS/mliap_descriptor_so3_kokkos.cpp | 4 -- src/KOKKOS/mliap_model_linear_kokkos.cpp | 1 - src/KOKKOS/mliap_so3_kokkos.cpp | 1 - src/KOKKOS/nbin_ssa_kokkos.cpp | 5 +- src/KOKKOS/neigh_bond_kokkos.cpp | 1 + src/KOKKOS/neigh_bond_kokkos.h | 2 - src/KOKKOS/neighbor_kokkos.cpp | 3 - src/KOKKOS/npair_skip_kokkos.cpp | 1 - src/KOKKOS/pair_buck_coul_cut_kokkos.cpp | 2 - src/KOKKOS/pair_buck_kokkos.cpp | 2 - src/KOKKOS/pair_coul_cut_kokkos.cpp | 1 - src/KOKKOS/pair_coul_debye_kokkos.cpp | 4 -- src/KOKKOS/pair_coul_dsf_kokkos.cpp | 1 - src/KOKKOS/pair_coul_wolf_kokkos.cpp | 1 - src/KOKKOS/pair_hybrid_kokkos.cpp | 6 +- src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp | 2 - src/KOKKOS/pair_lj_cut_kokkos.cpp | 3 - src/KOKKOS/third_order_kokkos.cpp | 9 --- src/KOKKOS/verlet_kokkos.cpp | 1 - src/KSPACE/pppm.cpp | 2 - src/KSPACE/pppm_cg.cpp | 1 - src/LEPTON/angle_lepton.cpp | 2 + src/LEPTON/bond_lepton.cpp | 2 + src/LEPTON/dihedral_lepton.cpp | 1 + src/LEPTON/fix_wall_lepton.cpp | 2 + src/LEPTON/lepton_utils.cpp | 1 - src/LEPTON/pair_lepton.cpp | 4 +- src/LEPTON/pair_lepton_coul.cpp | 4 +- src/LEPTON/pair_lepton_sphere.cpp | 4 +- src/MACHDYN/fix_smd_wall_surface.cpp | 1 + src/MANYBODY/pair_meam_spline.cpp | 1 + src/MANYBODY/pair_meam_sw_spline.cpp | 1 + src/MANYBODY/pair_sw_angle_table.cpp | 1 - src/MC/fix_charge_regulation.cpp | 1 + src/MC/fix_gcmc.cpp | 1 + src/MC/fix_widom.cpp | 1 + src/MDI/fix_mdi_engine.cpp | 1 - src/MDI/fix_mdi_qm.cpp | 2 + src/MDI/fix_mdi_qmmm.cpp | 4 ++ src/MDI/mdi_engine.cpp | 2 - src/MDI/mdi_plugin.cpp | 2 - src/MEAM/pair_meam_ms.cpp | 1 + src/MESONT/angle_mesocnt.cpp | 1 + src/MESONT/bond_mesocnt.cpp | 1 - src/MESONT/pair_mesocnt.cpp | 4 +- src/ML-IAP/compute_mliap.cpp | 1 + src/ML-PACE/compute_pace.cpp | 5 -- src/ML-PACE/pair_pace_extrapolation.cpp | 5 +- src/ML-PACE/pair_pace_extrapolation.h | 1 - src/ML-SNAP/compute_sna_atom.cpp | 1 + src/MOLECULE/bond_gromos.cpp | 1 + src/MOLECULE/pair_tip4p_cut.cpp | 1 + src/MOLFILE/molfile_interface.cpp | 1 - src/OPENMP/angle_lepton_omp.cpp | 3 + src/OPENMP/bond_lepton_omp.cpp | 2 + src/OPENMP/dihedral_lepton_omp.cpp | 2 + src/OPENMP/fix_nh_omp.cpp | 1 - src/OPENMP/fix_rigid_nh_omp.cpp | 1 - src/OPENMP/npair_bin_omp.cpp | 2 + src/OPENMP/npair_multi_old_omp.cpp | 2 + src/OPENMP/npair_multi_omp.cpp | 2 + src/OPENMP/npair_nsq_omp.cpp | 2 + src/OPENMP/npair_respa_bin_omp.cpp | 2 + src/OPENMP/npair_respa_nsq_omp.cpp | 2 + src/OPENMP/pair_lepton_coul_omp.cpp | 2 + src/OPENMP/pair_lepton_omp.cpp | 4 +- src/OPENMP/pair_lepton_sphere_omp.cpp | 2 + src/OPENMP/pair_lj_expand_sphere_omp.cpp | 2 + src/OPENMP/pair_rebomos_omp.cpp | 1 - src/POEMS/fix_poems.cpp | 2 +- src/PTM/compute_ptm_atom.cpp | 1 - src/PTM/ptm_convex_hull_incremental.h | 1 - src/PYTHON/python_impl.cpp | 1 - src/QEQ/fix_qeq.cpp | 2 - src/REAXFF/compute_reaxff_atom.cpp | 2 +- src/REAXFF/fix_acks2_reaxff.cpp | 1 + src/REAXFF/reaxff_ffield.cpp | 1 - src/REPLICA/fix_alchemy.cpp | 1 - src/REPLICA/fix_pimd_langevin.cpp | 1 - src/REPLICA/temper.cpp | 1 - src/REPLICA/temper_npt.cpp | 1 - src/SMTBQ/pair_smatb.cpp | 1 + src/SMTBQ/pair_smatb_single.cpp | 1 + src/SMTBQ/pair_smtbq.cpp | 1 + src/SPIN/neb_spin.cpp | 1 + src/npair_halffull.cpp | 2 + src/npair_multi.cpp | 2 + src/npair_multi_old.cpp | 2 + src/npair_nsq.cpp | 2 + src/npair_respa_bin.cpp | 2 + src/npair_respa_nsq.cpp | 2 + src/replicate.cpp | 1 + src/rerun.cpp | 1 + src/reset_atoms_image.cpp | 1 - src/utils.cpp | 1 + 193 files changed, 189 insertions(+), 337 deletions(-) diff --git a/src/AMOEBA/amoeba_convolution.cpp b/src/AMOEBA/amoeba_convolution.cpp index 3bdfdc9b74..44b7248815 100644 --- a/src/AMOEBA/amoeba_convolution.cpp +++ b/src/AMOEBA/amoeba_convolution.cpp @@ -15,16 +15,13 @@ #include "amoeba_convolution.h" #include "comm.h" -#include "domain.h" #include "fft3d_wrap.h" #include "grid3d.h" -#include "math_extra.h" #include "memory.h" #include "neighbor.h" #include "remap_wrap.h" #include "timer.h" -#include #include using namespace LAMMPS_NS; diff --git a/src/AMOEBA/pair_amoeba.h b/src/AMOEBA/pair_amoeba.h index 648fc86126..fd694a8037 100644 --- a/src/AMOEBA/pair_amoeba.h +++ b/src/AMOEBA/pair_amoeba.h @@ -20,7 +20,7 @@ PairStyle(amoeba,PairAmoeba); #ifndef LMP_PAIR_AMOEBA_H #define LMP_PAIR_AMOEBA_H -#include "lmpfftsettings.h" +#include "lmpfftsettings.h" // IWYU pragma: export #include "pair.h" namespace LAMMPS_NS { @@ -330,10 +330,10 @@ class PairAmoeba : public Pair { double *qfac; // convoulution pre-factors double *gridfft1; // copy of p_kspace FFT grid - double **cmp,**fmp; // Cartesian and fractional multipoles - double **cphi,**fphi; + double **cmp, **fmp; // Cartesian and fractional multipoles + double **cphi, **fphi; - double *_moduli_array; // buffers for moduli + double *_moduli_array; // buffers for moduli double *_moduli_bsarray; int _nfft_max; @@ -345,11 +345,11 @@ class PairAmoeba : public Pair { double ctf[10][10]; // indices NOT flipped vs Fortran double ftc[10][10]; // indices NOT flipped vs Fortran - class AmoebaConvolution *m_kspace; // multipole KSpace - class AmoebaConvolution *p_kspace; // polar KSpace + class AmoebaConvolution *m_kspace; // multipole KSpace + class AmoebaConvolution *p_kspace; // polar KSpace class AmoebaConvolution *pc_kspace; - class AmoebaConvolution *d_kspace; // dispersion KSpace - class AmoebaConvolution *i_kspace; // induce KSpace + class AmoebaConvolution *d_kspace; // dispersion KSpace + class AmoebaConvolution *i_kspace; // induce KSpace class AmoebaConvolution *ic_kspace; // FFT grid size factors @@ -362,8 +362,8 @@ class PairAmoeba : public Pair { void hal(); virtual void repulsion(); - void damprep(double, double, double, double, double, double, double, double, - int, double, double, double *); + void damprep(double, double, double, double, double, double, double, double, int, double, double, + double *); void dispersion(); virtual void dispersion_real(); diff --git a/src/ATC/fix_atc.cpp b/src/ATC/fix_atc.cpp index 436ffc9555..b1276d6788 100644 --- a/src/ATC/fix_atc.cpp +++ b/src/ATC/fix_atc.cpp @@ -20,15 +20,17 @@ #include "group.h" #include "neighbor.h" +#include "ATC_Error.h" #include "ATC_Method.h" -#include "ATC_TransferKernel.h" -#include "ATC_TransferPartitionOfUnity.h" #include "ATC_CouplingEnergy.h" #include "ATC_CouplingMomentum.h" #include "ATC_CouplingMass.h" #include "ATC_CouplingMomentumEnergy.h" +#include "ATC_TransferKernel.h" +#include "ATC_TransferPartitionOfUnity.h" +#include "ATC_TypeDefs.h" +#include "ExtrinsicModel.h" #include "LammpsInterface.h" - #include using namespace LAMMPS_NS; diff --git a/src/AWPMD/atom_vec_wavepacket.cpp b/src/AWPMD/atom_vec_wavepacket.cpp index ff0d660fb6..65b8214369 100644 --- a/src/AWPMD/atom_vec_wavepacket.cpp +++ b/src/AWPMD/atom_vec_wavepacket.cpp @@ -19,6 +19,8 @@ #include "atom.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/BPM/atom_vec_bpm_sphere.cpp b/src/BPM/atom_vec_bpm_sphere.cpp index 37a36f4a59..4332d517b4 100644 --- a/src/BPM/atom_vec_bpm_sphere.cpp +++ b/src/BPM/atom_vec_bpm_sphere.cpp @@ -14,14 +14,11 @@ #include "atom_vec_bpm_sphere.h" #include "atom.h" -#include "comm.h" #include "error.h" #include "fix.h" #include "math_const.h" #include "modify.h" -#include - using namespace LAMMPS_NS; using MathConst::MY_PI; diff --git a/src/BPM/fix_update_special_bonds.cpp b/src/BPM/fix_update_special_bonds.cpp index 04f5d94e7e..cdc72ee987 100644 --- a/src/BPM/fix_update_special_bonds.cpp +++ b/src/BPM/fix_update_special_bonds.cpp @@ -21,7 +21,6 @@ #include "modify.h" #include "neigh_list.h" #include "neighbor.h" -#include "pair.h" #include diff --git a/src/CG-DNA/pair_oxdna_stk.cpp b/src/CG-DNA/pair_oxdna_stk.cpp index 99ddf9c96a..1ef779dbd9 100644 --- a/src/CG-DNA/pair_oxdna_stk.cpp +++ b/src/CG-DNA/pair_oxdna_stk.cpp @@ -25,6 +25,7 @@ #include "memory.h" #include "mf_oxdna.h" #include "neighbor.h" +#include "neigh_list.h" #include #include diff --git a/src/CG-DNA/pair_oxrna2_stk.cpp b/src/CG-DNA/pair_oxrna2_stk.cpp index f6e12fffe1..f56aa572e8 100644 --- a/src/CG-DNA/pair_oxrna2_stk.cpp +++ b/src/CG-DNA/pair_oxrna2_stk.cpp @@ -26,6 +26,7 @@ #include "memory.h" #include "mf_oxdna.h" #include "neighbor.h" +#include "neigh_list.h" #include #include diff --git a/src/COLVARS/colvarproxy_lammps.cpp b/src/COLVARS/colvarproxy_lammps.cpp index 06a2a23ec0..1c5d84d62a 100644 --- a/src/COLVARS/colvarproxy_lammps.cpp +++ b/src/COLVARS/colvarproxy_lammps.cpp @@ -19,11 +19,7 @@ #include "colvarmodule.h" #include "colvarproxy.h" -#include -#include -#include -#include -#include +#include #define HASH_FAIL -1 diff --git a/src/COLVARS/fix_colvars.cpp b/src/COLVARS/fix_colvars.cpp index baf0209c61..0b496ee71b 100644 --- a/src/COLVARS/fix_colvars.cpp +++ b/src/COLVARS/fix_colvars.cpp @@ -40,8 +40,6 @@ #include #include -#include -#include #include "colvarproxy_lammps.h" #include "colvarmodule.h" diff --git a/src/DIELECTRIC/pppm_dielectric.cpp b/src/DIELECTRIC/pppm_dielectric.cpp index 49fa8ed128..e02cc33162 100644 --- a/src/DIELECTRIC/pppm_dielectric.cpp +++ b/src/DIELECTRIC/pppm_dielectric.cpp @@ -23,7 +23,6 @@ #include "comm.h" #include "domain.h" #include "error.h" -#include "fft3d_wrap.h" #include "force.h" #include "grid3d.h" #include "math_const.h" diff --git a/src/DIELECTRIC/pppm_disp_dielectric.cpp b/src/DIELECTRIC/pppm_disp_dielectric.cpp index c6108646be..e5149ae427 100644 --- a/src/DIELECTRIC/pppm_disp_dielectric.cpp +++ b/src/DIELECTRIC/pppm_disp_dielectric.cpp @@ -25,10 +25,12 @@ #include "error.h" #include "force.h" #include "grid3d.h" +#include "lmpfftsettings.h" #include "math_const.h" #include "memory.h" #include +#include using namespace LAMMPS_NS; using namespace MathConst; diff --git a/src/DPD-REACT/npair_half_bin_newton_ssa.cpp b/src/DPD-REACT/npair_half_bin_newton_ssa.cpp index ce405da3ac..7393e54f78 100644 --- a/src/DPD-REACT/npair_half_bin_newton_ssa.cpp +++ b/src/DPD-REACT/npair_half_bin_newton_ssa.cpp @@ -18,6 +18,7 @@ ------------------------------------------------------------------------- */ #include "npair_half_bin_newton_ssa.h" + #include "nstencil_ssa.h" #include "nbin_ssa.h" #include "neigh_list.h" diff --git a/src/DRUDE/fix_drude.cpp b/src/DRUDE/fix_drude.cpp index 4270c2f402..6aaa4f1a74 100644 --- a/src/DRUDE/fix_drude.cpp +++ b/src/DRUDE/fix_drude.cpp @@ -22,7 +22,6 @@ #include "modify.h" #include "molecule.h" -#include #include #include diff --git a/src/DRUDE/fix_drude_transform.cpp b/src/DRUDE/fix_drude_transform.cpp index 4a85b8ae4c..88877ef70d 100644 --- a/src/DRUDE/fix_drude_transform.cpp +++ b/src/DRUDE/fix_drude_transform.cpp @@ -24,7 +24,6 @@ #include "modify.h" #include -#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/ELECTRODE/fix_electrode_conp.cpp b/src/ELECTRODE/fix_electrode_conp.cpp index 9e2599ca8a..e8b11c330b 100644 --- a/src/ELECTRODE/fix_electrode_conp.cpp +++ b/src/ELECTRODE/fix_electrode_conp.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include using namespace LAMMPS_NS; diff --git a/src/ELECTRODE/fix_electrode_conp.h b/src/ELECTRODE/fix_electrode_conp.h index 1289d96281..46da1eec35 100644 --- a/src/ELECTRODE/fix_electrode_conp.h +++ b/src/ELECTRODE/fix_electrode_conp.h @@ -29,7 +29,6 @@ FixStyle(electrode/conp, FixElectrodeConp); #include "fix.h" #include -#include #include namespace LAMMPS_NS { diff --git a/src/ELECTRODE/pppm_electrode.cpp b/src/ELECTRODE/pppm_electrode.cpp index 39e7c66ce5..98a76a7cca 100644 --- a/src/ELECTRODE/pppm_electrode.cpp +++ b/src/ELECTRODE/pppm_electrode.cpp @@ -20,6 +20,7 @@ #include "angle.h" #include "atom.h" #include "bond.h" +#include "boundary_correction.h" #include "citeme.h" #include "comm.h" #include "domain.h" diff --git a/src/EXTRA-COMPUTE/compute_composition_atom.cpp b/src/EXTRA-COMPUTE/compute_composition_atom.cpp index 48aaa68dea..47483f760b 100644 --- a/src/EXTRA-COMPUTE/compute_composition_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_composition_atom.cpp @@ -19,7 +19,6 @@ #include "atom.h" #include "comm.h" -#include "domain.h" #include "error.h" #include "force.h" #include "math_const.h" diff --git a/src/EXTRA-COMPUTE/compute_dipole_tip4p_chunk.cpp b/src/EXTRA-COMPUTE/compute_dipole_tip4p_chunk.cpp index 571f1d562d..466bc0e882 100644 --- a/src/EXTRA-COMPUTE/compute_dipole_tip4p_chunk.cpp +++ b/src/EXTRA-COMPUTE/compute_dipole_tip4p_chunk.cpp @@ -16,7 +16,6 @@ #include "angle.h" #include "atom.h" #include "bond.h" -#include "comm.h" #include "compute_chunk_atom.h" #include "domain.h" #include "error.h" diff --git a/src/EXTRA-COMPUTE/compute_dipole_tip4p_chunk.h b/src/EXTRA-COMPUTE/compute_dipole_tip4p_chunk.h index b3354c9ab9..126f9962aa 100644 --- a/src/EXTRA-COMPUTE/compute_dipole_tip4p_chunk.h +++ b/src/EXTRA-COMPUTE/compute_dipole_tip4p_chunk.h @@ -23,7 +23,6 @@ ComputeStyle(dipole/tip4p/chunk,ComputeDipoleTIP4PChunk); #include "compute_chunk.h" namespace LAMMPS_NS { -class Fix; class ComputeDipoleTIP4PChunk : public ComputeChunk { public: diff --git a/src/EXTRA-COMPUTE/compute_rattlers_atom.cpp b/src/EXTRA-COMPUTE/compute_rattlers_atom.cpp index 9dacf14171..5f707d8433 100644 --- a/src/EXTRA-COMPUTE/compute_rattlers_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_rattlers_atom.cpp @@ -29,7 +29,6 @@ #include "pair.h" #include "update.h" -#include #include using namespace LAMMPS_NS; diff --git a/src/EXTRA-COMPUTE/compute_slcsa_atom.cpp b/src/EXTRA-COMPUTE/compute_slcsa_atom.cpp index 6c272938b6..e0b34b8ff1 100644 --- a/src/EXTRA-COMPUTE/compute_slcsa_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_slcsa_atom.cpp @@ -22,12 +22,9 @@ #include "citeme.h" #include "comm.h" #include "error.h" -#include "force.h" #include "memory.h" #include "modify.h" #include "neigh_list.h" -#include "neighbor.h" -#include "pair.h" #include "potential_file_reader.h" #include "update.h" diff --git a/src/EXTRA-FIX/fix_deform_pressure.cpp b/src/EXTRA-FIX/fix_deform_pressure.cpp index 34741fef14..ffa3f11d92 100644 --- a/src/EXTRA-FIX/fix_deform_pressure.cpp +++ b/src/EXTRA-FIX/fix_deform_pressure.cpp @@ -18,17 +18,13 @@ #include "fix_deform_pressure.h" -#include "atom.h" #include "comm.h" #include "compute.h" #include "domain.h" #include "error.h" -#include "force.h" #include "group.h" #include "input.h" #include "irregular.h" -#include "kspace.h" -#include "lattice.h" #include "math_const.h" #include "modify.h" #include "update.h" @@ -36,7 +32,6 @@ #include #include -#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/EXTRA-FIX/fix_efield_tip4p.cpp b/src/EXTRA-FIX/fix_efield_tip4p.cpp index 47b1d9e27a..a83939a620 100644 --- a/src/EXTRA-FIX/fix_efield_tip4p.cpp +++ b/src/EXTRA-FIX/fix_efield_tip4p.cpp @@ -16,7 +16,6 @@ #include "angle.h" #include "atom.h" #include "bond.h" -#include "comm.h" #include "domain.h" #include "error.h" #include "force.h" @@ -25,11 +24,10 @@ #include "modify.h" #include "pair.h" #include "region.h" -#include "respa.h" #include "update.h" #include "variable.h" -#include +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/EXTRA-FIX/fix_nonaffine_displacement.cpp b/src/EXTRA-FIX/fix_nonaffine_displacement.cpp index a426a8fb55..06702c408b 100644 --- a/src/EXTRA-FIX/fix_nonaffine_displacement.cpp +++ b/src/EXTRA-FIX/fix_nonaffine_displacement.cpp @@ -35,6 +35,7 @@ #include "pair.h" #include "update.h" +#include #include using namespace LAMMPS_NS; diff --git a/src/EXTRA-FIX/fix_tmd.cpp b/src/EXTRA-FIX/fix_tmd.cpp index 401ed41573..242efcf41c 100644 --- a/src/EXTRA-FIX/fix_tmd.cpp +++ b/src/EXTRA-FIX/fix_tmd.cpp @@ -32,6 +32,7 @@ #include #include +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/EXTRA-FIX/fix_wall_flow.cpp b/src/EXTRA-FIX/fix_wall_flow.cpp index 1f3dcfca5b..35997b5b63 100644 --- a/src/EXTRA-FIX/fix_wall_flow.cpp +++ b/src/EXTRA-FIX/fix_wall_flow.cpp @@ -24,16 +24,14 @@ #include "domain.h" #include "error.h" #include "force.h" -#include "input.h" #include "lattice.h" #include "math_const.h" #include "memory.h" #include "modify.h" #include "random_mars.h" -#include "update.h" -#include "variable.h" #include +#include #include #include diff --git a/src/EXTRA-PAIR/pair_born_gauss.cpp b/src/EXTRA-PAIR/pair_born_gauss.cpp index f60cc4dc6f..4b1390889d 100644 --- a/src/EXTRA-PAIR/pair_born_gauss.cpp +++ b/src/EXTRA-PAIR/pair_born_gauss.cpp @@ -18,10 +18,8 @@ #include "atom.h" #include "comm.h" #include "error.h" -#include "fix.h" #include "force.h" #include "memory.h" -#include "modify.h" #include "neigh_list.h" #include diff --git a/src/EXTRA-PAIR/pair_lj_cut_sphere.cpp b/src/EXTRA-PAIR/pair_lj_cut_sphere.cpp index 3f16a96666..852b2eea1d 100644 --- a/src/EXTRA-PAIR/pair_lj_cut_sphere.cpp +++ b/src/EXTRA-PAIR/pair_lj_cut_sphere.cpp @@ -20,10 +20,7 @@ #include "math_special.h" #include "memory.h" #include "neigh_list.h" -#include "neighbor.h" -#include "update.h" -#include #include using namespace LAMMPS_NS; diff --git a/src/EXTRA-PAIR/pair_lj_expand_sphere.cpp b/src/EXTRA-PAIR/pair_lj_expand_sphere.cpp index 089a9deea7..c275a9f9ee 100644 --- a/src/EXTRA-PAIR/pair_lj_expand_sphere.cpp +++ b/src/EXTRA-PAIR/pair_lj_expand_sphere.cpp @@ -20,8 +20,6 @@ #include "math_special.h" #include "memory.h" #include "neigh_list.h" -#include "neighbor.h" -#include "update.h" #include #include diff --git a/src/GRANULAR/fix_heat_flow.cpp b/src/GRANULAR/fix_heat_flow.cpp index d0d7a73ce6..b7643c2c24 100644 --- a/src/GRANULAR/fix_heat_flow.cpp +++ b/src/GRANULAR/fix_heat_flow.cpp @@ -16,12 +16,12 @@ #include "atom.h" #include "comm.h" #include "error.h" -#include "force.h" #include "memory.h" #include "modify.h" -#include "respa.h" #include "update.h" +#include + using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/GRANULAR/fix_wall_gran.cpp b/src/GRANULAR/fix_wall_gran.cpp index 5930280053..b8b06add2e 100644 --- a/src/GRANULAR/fix_wall_gran.cpp +++ b/src/GRANULAR/fix_wall_gran.cpp @@ -34,6 +34,7 @@ #include "update.h" #include "variable.h" +#include #include using namespace LAMMPS_NS; diff --git a/src/GRANULAR/fix_wall_gran.h b/src/GRANULAR/fix_wall_gran.h index 45e4e43844..cd1e8778c3 100644 --- a/src/GRANULAR/fix_wall_gran.h +++ b/src/GRANULAR/fix_wall_gran.h @@ -20,7 +20,6 @@ FixStyle(wall/gran,FixWallGran); #ifndef LMP_FIX_WALL_GRAN_H #define LMP_FIX_WALL_GRAN_H -#include "granular_model.h" #include "fix.h" namespace LAMMPS_NS { diff --git a/src/GRANULAR/fix_wall_gran_region.cpp b/src/GRANULAR/fix_wall_gran_region.cpp index 1c2fd4bcc0..b90620f3aa 100644 --- a/src/GRANULAR/fix_wall_gran_region.cpp +++ b/src/GRANULAR/fix_wall_gran_region.cpp @@ -30,8 +30,6 @@ #include "update.h" #include "variable.h" -#include - using namespace LAMMPS_NS; using namespace Granular_NS; using namespace MathExtra; diff --git a/src/GRANULAR/gran_sub_mod.cpp b/src/GRANULAR/gran_sub_mod.cpp index bf945523dd..bac9c9edfe 100644 --- a/src/GRANULAR/gran_sub_mod.cpp +++ b/src/GRANULAR/gran_sub_mod.cpp @@ -21,7 +21,8 @@ ----------------------------------------------------------------------- */ #include "gran_sub_mod.h" -#include "error.h" + +#include using namespace LAMMPS_NS; using namespace Granular_NS; diff --git a/src/GRANULAR/gran_sub_mod.h b/src/GRANULAR/gran_sub_mod.h index 2524565332..88e77eb77b 100644 --- a/src/GRANULAR/gran_sub_mod.h +++ b/src/GRANULAR/gran_sub_mod.h @@ -14,50 +14,50 @@ #ifndef LMP_GRAN_SUB_MOD_H #define LMP_GRAN_SUB_MOD_H -#include "granular_model.h" #include "pointers.h" // IWYU pragma: export namespace LAMMPS_NS { namespace Granular_NS { + class GranularModel; -class GranSubMod : protected Pointers { - public: - GranSubMod(class GranularModel *, class LAMMPS *); - ~GranSubMod() override; + class GranSubMod : protected Pointers { + public: + GranSubMod(class GranularModel *, class LAMMPS *); + ~GranSubMod() override; - int num_coeffs; - double *coeffs; - void read_restart(); - virtual void mix_coeffs(double*, double*); - virtual void coeffs_to_local() {}; - virtual void init() {}; // called after all sub models + coeffs defined + int num_coeffs; + double *coeffs; + void read_restart(); + virtual void mix_coeffs(double *, double *); + virtual void coeffs_to_local(){}; + virtual void init(){}; // called after all sub models + coeffs defined - void allocate_coeffs(); - std::string name; + void allocate_coeffs(); + std::string name; - int size_history; - int nondefault_history_transfer; - double *transfer_history_factor; + int size_history; + int nondefault_history_transfer; + double *transfer_history_factor; - int history_index; - int beyond_contact; // If the sub model contact extends beyond overlap - int allow_cohesion; // If the sub model works with a cohesive normal force - int contact_radius_flag; // If the sub model requires contact radius + int history_index; + int beyond_contact; // If the sub model contact extends beyond overlap + int allow_cohesion; // If the sub model works with a cohesive normal force + int contact_radius_flag; // If the sub model requires contact radius - GranularModel *gm; + GranularModel *gm; - protected: - int allocated; + protected: + int allocated; - double mix_stiffnessE(double, double, double, double); - double mix_stiffnessG(double, double, double, double); - double mix_stiffnessE_wall(double, double); - double mix_stiffnessG_wall(double, double); - double mix_geom(double, double); - double mix_mean(double, double); -}; + double mix_stiffnessE(double, double, double, double); + double mix_stiffnessG(double, double, double, double); + double mix_stiffnessE_wall(double, double); + double mix_stiffnessG_wall(double, double); + double mix_geom(double, double); + double mix_mean(double, double); + }; -} // namespace GranularModel +} // namespace Granular_NS } // namespace LAMMPS_NS #endif /* GRAN_SUB_MOD_H */ diff --git a/src/GRANULAR/gran_sub_mod_damping.cpp b/src/GRANULAR/gran_sub_mod_damping.cpp index 1ac0ce9030..4386ed71fc 100644 --- a/src/GRANULAR/gran_sub_mod_damping.cpp +++ b/src/GRANULAR/gran_sub_mod_damping.cpp @@ -17,6 +17,8 @@ #include "granular_model.h" #include "math_special.h" +#include + using namespace LAMMPS_NS; using namespace Granular_NS; diff --git a/src/GRANULAR/gran_sub_mod_normal.cpp b/src/GRANULAR/gran_sub_mod_normal.cpp index ffc18b8c32..f4294bbc35 100644 --- a/src/GRANULAR/gran_sub_mod_normal.cpp +++ b/src/GRANULAR/gran_sub_mod_normal.cpp @@ -16,6 +16,8 @@ #include "granular_model.h" #include "math_const.h" +#include + using namespace LAMMPS_NS; using namespace Granular_NS; diff --git a/src/GRANULAR/gran_sub_mod_rolling.cpp b/src/GRANULAR/gran_sub_mod_rolling.cpp index 554aa7ab63..4b10bd2358 100644 --- a/src/GRANULAR/gran_sub_mod_rolling.cpp +++ b/src/GRANULAR/gran_sub_mod_rolling.cpp @@ -18,6 +18,8 @@ #include "granular_model.h" #include "math_extra.h" +#include + using namespace LAMMPS_NS; using namespace Granular_NS; using namespace MathExtra; diff --git a/src/GRANULAR/gran_sub_mod_tangential.cpp b/src/GRANULAR/gran_sub_mod_tangential.cpp index c74233701b..f8f39a38f9 100644 --- a/src/GRANULAR/gran_sub_mod_tangential.cpp +++ b/src/GRANULAR/gran_sub_mod_tangential.cpp @@ -19,6 +19,8 @@ #include "granular_model.h" #include "math_extra.h" +#include + using namespace LAMMPS_NS; using namespace Granular_NS; using namespace MathExtra; diff --git a/src/GRANULAR/gran_sub_mod_twisting.cpp b/src/GRANULAR/gran_sub_mod_twisting.cpp index 48af89c9e7..95c62ad342 100644 --- a/src/GRANULAR/gran_sub_mod_twisting.cpp +++ b/src/GRANULAR/gran_sub_mod_twisting.cpp @@ -19,6 +19,8 @@ #include "granular_model.h" #include "math_const.h" +#include + using namespace LAMMPS_NS; using namespace Granular_NS; diff --git a/src/GRANULAR/granular_model.cpp b/src/GRANULAR/granular_model.cpp index c1ad692fb3..6de147b34a 100644 --- a/src/GRANULAR/granular_model.cpp +++ b/src/GRANULAR/granular_model.cpp @@ -31,6 +31,7 @@ #include "style_gran_sub_mod.h" // IWYU pragma: keep #include +#include using namespace LAMMPS_NS; using namespace Granular_NS; diff --git a/src/GRANULAR/pair_granular.h b/src/GRANULAR/pair_granular.h index 956717d598..46c5570543 100644 --- a/src/GRANULAR/pair_granular.h +++ b/src/GRANULAR/pair_granular.h @@ -21,7 +21,6 @@ PairStyle(granular,PairGranular); #define LMP_PAIR_GRANULAR_H #include "pair.h" -#include namespace LAMMPS_NS { diff --git a/src/INTERLAYER/pair_aip_water_2dm.cpp b/src/INTERLAYER/pair_aip_water_2dm.cpp index ea3812504d..2c6b222d45 100644 --- a/src/INTERLAYER/pair_aip_water_2dm.cpp +++ b/src/INTERLAYER/pair_aip_water_2dm.cpp @@ -24,9 +24,6 @@ #include "error.h" #include "force.h" -#include -#include - using namespace LAMMPS_NS; static const char cite_aip_water[] = diff --git a/src/INTERLAYER/pair_ilp_tmd.h b/src/INTERLAYER/pair_ilp_tmd.h index 8381c2e830..7e7edbb01b 100644 --- a/src/INTERLAYER/pair_ilp_tmd.h +++ b/src/INTERLAYER/pair_ilp_tmd.h @@ -20,7 +20,7 @@ PairStyle(ilp/tmd,PairILPTMD); #ifndef LMP_PAIR_ILP_TMD_H #define LMP_PAIR_ILP_TMD_H -#include "pair_ilp_graphene_hbn.h" +#include "pair_ilp_graphene_hbn.h" // IWYU pragma: export namespace LAMMPS_NS { diff --git a/src/KOKKOS/atom_kokkos.cpp b/src/KOKKOS/atom_kokkos.cpp index af1816c1d3..b1a066f165 100644 --- a/src/KOKKOS/atom_kokkos.cpp +++ b/src/KOKKOS/atom_kokkos.cpp @@ -16,7 +16,7 @@ #include "atom_masks.h" #include "atom_vec.h" #include "atom_vec_kokkos.h" -#include "comm_kokkos.h" +#include "comm.h" #include "domain.h" #include "error.h" #include "kokkos.h" diff --git a/src/KOKKOS/atom_map_kokkos.cpp b/src/KOKKOS/atom_map_kokkos.cpp index 3f86afe788..8203e1e6a2 100644 --- a/src/KOKKOS/atom_map_kokkos.cpp +++ b/src/KOKKOS/atom_map_kokkos.cpp @@ -16,13 +16,8 @@ #include "atom_masks.h" #include "comm.h" #include "error.h" -#include "fix.h" #include "kokkos.h" #include "memory_kokkos.h" -#include "modify.h" -#include "neighbor_kokkos.h" - -#include using namespace LAMMPS_NS; diff --git a/src/KOKKOS/atom_vec_atomic_kokkos.cpp b/src/KOKKOS/atom_vec_atomic_kokkos.cpp index 973ad2f7f2..a69ff85c54 100644 --- a/src/KOKKOS/atom_vec_atomic_kokkos.cpp +++ b/src/KOKKOS/atom_vec_atomic_kokkos.cpp @@ -16,7 +16,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "comm_kokkos.h" #include "domain.h" #include "error.h" #include "fix.h" diff --git a/src/KOKKOS/atom_vec_bond_kokkos.cpp b/src/KOKKOS/atom_vec_bond_kokkos.cpp index a4fd9ca1b5..3684d30acf 100644 --- a/src/KOKKOS/atom_vec_bond_kokkos.cpp +++ b/src/KOKKOS/atom_vec_bond_kokkos.cpp @@ -16,7 +16,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "comm_kokkos.h" #include "domain.h" #include "error.h" #include "fix.h" diff --git a/src/KOKKOS/atom_vec_charge_kokkos.cpp b/src/KOKKOS/atom_vec_charge_kokkos.cpp index 4fa814f1ac..a479e4f216 100644 --- a/src/KOKKOS/atom_vec_charge_kokkos.cpp +++ b/src/KOKKOS/atom_vec_charge_kokkos.cpp @@ -16,7 +16,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "comm_kokkos.h" #include "domain.h" #include "error.h" #include "fix.h" diff --git a/src/KOKKOS/atom_vec_dipole_kokkos.cpp b/src/KOKKOS/atom_vec_dipole_kokkos.cpp index ecc0f3b497..6af575ad37 100644 --- a/src/KOKKOS/atom_vec_dipole_kokkos.cpp +++ b/src/KOKKOS/atom_vec_dipole_kokkos.cpp @@ -16,7 +16,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "comm_kokkos.h" #include "domain.h" #include "error.h" #include "fix.h" diff --git a/src/KOKKOS/atom_vec_full_kokkos.cpp b/src/KOKKOS/atom_vec_full_kokkos.cpp index 732078a627..282414ab9b 100644 --- a/src/KOKKOS/atom_vec_full_kokkos.cpp +++ b/src/KOKKOS/atom_vec_full_kokkos.cpp @@ -16,7 +16,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "comm_kokkos.h" #include "domain.h" #include "error.h" #include "fix.h" diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp index 08bcaaef74..70b852a312 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp @@ -15,14 +15,7 @@ #include "atom_vec_hybrid_kokkos.h" #include "atom_kokkos.h" -#include "atom_masks.h" -#include "domain.h" #include "error.h" -#include "fix.h" -#include "memory_kokkos.h" -#include "modify.h" - -#include using namespace LAMMPS_NS; diff --git a/src/KOKKOS/atom_vec_kokkos.cpp b/src/KOKKOS/atom_vec_kokkos.cpp index 93393e9e09..42a32dd71d 100644 --- a/src/KOKKOS/atom_vec_kokkos.cpp +++ b/src/KOKKOS/atom_vec_kokkos.cpp @@ -17,7 +17,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" #include "comm_kokkos.h" -#include "error.h" #include "domain.h" using namespace LAMMPS_NS; diff --git a/src/KOKKOS/atom_vec_sphere_kokkos.cpp b/src/KOKKOS/atom_vec_sphere_kokkos.cpp index 3dfb5143cd..a9dcf72ff3 100644 --- a/src/KOKKOS/atom_vec_sphere_kokkos.cpp +++ b/src/KOKKOS/atom_vec_sphere_kokkos.cpp @@ -21,12 +21,9 @@ #include "error.h" #include "fix.h" #include "math_const.h" -#include "memory.h" #include "memory_kokkos.h" #include "modify.h" -#include - using namespace LAMMPS_NS; using namespace MathConst; diff --git a/src/KOKKOS/atom_vec_spin_kokkos.cpp b/src/KOKKOS/atom_vec_spin_kokkos.cpp index c6ee7c1d3b..1f52b56269 100644 --- a/src/KOKKOS/atom_vec_spin_kokkos.cpp +++ b/src/KOKKOS/atom_vec_spin_kokkos.cpp @@ -26,7 +26,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "comm_kokkos.h" #include "domain.h" #include "error.h" #include "fix.h" diff --git a/src/KOKKOS/compute_ave_sphere_atom_kokkos.cpp b/src/KOKKOS/compute_ave_sphere_atom_kokkos.cpp index 87fe3621e4..57f1f2bb18 100644 --- a/src/KOKKOS/compute_ave_sphere_atom_kokkos.cpp +++ b/src/KOKKOS/compute_ave_sphere_atom_kokkos.cpp @@ -21,19 +21,12 @@ #include "atom_masks.h" #include "comm.h" #include "domain.h" -#include "error.h" #include "force.h" #include "memory_kokkos.h" -#include "modify.h" -#include "neigh_list.h" #include "neigh_request.h" #include "neighbor_kokkos.h" -#include "pair.h" #include "update.h" -#include -#include - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/compute_composition_atom_kokkos.cpp b/src/KOKKOS/compute_composition_atom_kokkos.cpp index 2b0e663011..47056951e7 100644 --- a/src/KOKKOS/compute_composition_atom_kokkos.cpp +++ b/src/KOKKOS/compute_composition_atom_kokkos.cpp @@ -19,21 +19,11 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "comm.h" -#include "domain.h" -#include "error.h" -#include "force.h" #include "memory_kokkos.h" -#include "modify.h" -#include "neigh_list.h" #include "neigh_request.h" #include "neighbor_kokkos.h" -#include "pair.h" #include "update.h" -#include -#include - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/compute_coord_atom_kokkos.cpp b/src/KOKKOS/compute_coord_atom_kokkos.cpp index 089a94f498..2d56a53abe 100644 --- a/src/KOKKOS/compute_coord_atom_kokkos.cpp +++ b/src/KOKKOS/compute_coord_atom_kokkos.cpp @@ -20,8 +20,6 @@ #include "compute_orientorder_atom_kokkos.h" #include "error.h" #include "memory_kokkos.h" -#include "modify.h" -#include "neigh_list.h" #include "neigh_request.h" #include "neighbor_kokkos.h" #include "update.h" diff --git a/src/KOKKOS/compute_erotate_sphere_kokkos.cpp b/src/KOKKOS/compute_erotate_sphere_kokkos.cpp index 9fc477b3a0..d18aa3d27a 100644 --- a/src/KOKKOS/compute_erotate_sphere_kokkos.cpp +++ b/src/KOKKOS/compute_erotate_sphere_kokkos.cpp @@ -16,8 +16,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "error.h" -#include "force.h" #include "update.h" using namespace LAMMPS_NS; diff --git a/src/KOKKOS/compute_orientorder_atom_kokkos.cpp b/src/KOKKOS/compute_orientorder_atom_kokkos.cpp index 35699cb5c1..447f15b830 100644 --- a/src/KOKKOS/compute_orientorder_atom_kokkos.cpp +++ b/src/KOKKOS/compute_orientorder_atom_kokkos.cpp @@ -24,14 +24,11 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "kokkos.h" #include "math_const.h" #include "math_special.h" #include "memory_kokkos.h" -#include "neigh_list.h" #include "neigh_request.h" #include "neighbor_kokkos.h" -#include "pair.h" #include "update.h" #include diff --git a/src/KOKKOS/compute_reaxff_atom_kokkos.cpp b/src/KOKKOS/compute_reaxff_atom_kokkos.cpp index 2b5cbff13d..0683e63752 100644 --- a/src/KOKKOS/compute_reaxff_atom_kokkos.cpp +++ b/src/KOKKOS/compute_reaxff_atom_kokkos.cpp @@ -18,16 +18,12 @@ #include "compute_reaxff_atom_kokkos.h" #include "atom.h" -#include "molecule.h" #include "update.h" -#include "force.h" -#include "memory.h" #include "error.h" #include "neigh_list.h" #include "memory_kokkos.h" #include "pair_reaxff_kokkos.h" -#include "reaxff_api.h" using namespace LAMMPS_NS; using namespace ReaxFF; diff --git a/src/KOKKOS/compute_temp_deform_kokkos.cpp b/src/KOKKOS/compute_temp_deform_kokkos.cpp index 55db344d6a..03aba5b10d 100644 --- a/src/KOKKOS/compute_temp_deform_kokkos.cpp +++ b/src/KOKKOS/compute_temp_deform_kokkos.cpp @@ -24,7 +24,6 @@ #include "domain_kokkos.h" #include "error.h" #include "force.h" -#include "memory_kokkos.h" #include "update.h" using namespace LAMMPS_NS; diff --git a/src/KOKKOS/compute_temp_kokkos.cpp b/src/KOKKOS/compute_temp_kokkos.cpp index ebdd6971e0..78a35440c8 100644 --- a/src/KOKKOS/compute_temp_kokkos.cpp +++ b/src/KOKKOS/compute_temp_kokkos.cpp @@ -21,8 +21,6 @@ #include "force.h" #include "update.h" -#include - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/dynamical_matrix_kokkos.cpp b/src/KOKKOS/dynamical_matrix_kokkos.cpp index ec2cc17ef2..e4c454c7f2 100644 --- a/src/KOKKOS/dynamical_matrix_kokkos.cpp +++ b/src/KOKKOS/dynamical_matrix_kokkos.cpp @@ -23,27 +23,18 @@ #include "atom_masks.h" #include "bond.h" #include "comm.h" -#include "compute.h" #include "dihedral.h" #include "domain.h" -#include "error.h" -#include "finish.h" #include "force.h" -#include "group.h" #include "improper.h" #include "kokkos.h" #include "kspace.h" -#include "memory.h" #include "modify.h" #include "neighbor.h" #include "pair.h" #include "timer.h" #include "update.h" -#include -#include -#include - using namespace LAMMPS_NS; enum{REGULAR,ESKM}; diff --git a/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp b/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp index 617660d5ef..cc3df5d78d 100644 --- a/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp +++ b/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp @@ -24,13 +24,11 @@ #include "comm.h" #include "error.h" #include "force.h" -#include "integrate.h" #include "kokkos.h" #include "memory_kokkos.h" #include "neigh_list_kokkos.h" #include "neigh_request.h" #include "neighbor.h" -#include "pair_reaxff_kokkos.h" #include "update.h" #include diff --git a/src/KOKKOS/fix_deform_kokkos.cpp b/src/KOKKOS/fix_deform_kokkos.cpp index 97c78bb1a5..90c4380da9 100644 --- a/src/KOKKOS/fix_deform_kokkos.cpp +++ b/src/KOKKOS/fix_deform_kokkos.cpp @@ -21,7 +21,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" #include "domain_kokkos.h" -#include "error.h" #include "force.h" #include "input.h" #include "irregular.h" @@ -32,7 +31,6 @@ #include "variable.h" #include -#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_dt_reset_kokkos.cpp b/src/KOKKOS/fix_dt_reset_kokkos.cpp index 83cdc5f26f..df354f19c8 100644 --- a/src/KOKKOS/fix_dt_reset_kokkos.cpp +++ b/src/KOKKOS/fix_dt_reset_kokkos.cpp @@ -18,15 +18,13 @@ #include "atom_masks.h" #include "error.h" #include "force.h" -#include "input.h" -#include "integrate.h" -#include "kokkos_base.h" -#include "memory_kokkos.h" #include "modify.h" #include "output.h" #include "pair.h" #include "update.h" +#include + using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_efield_kokkos.cpp b/src/KOKKOS/fix_efield_kokkos.cpp index ffe1c34e97..4009773982 100644 --- a/src/KOKKOS/fix_efield_kokkos.cpp +++ b/src/KOKKOS/fix_efield_kokkos.cpp @@ -30,8 +30,6 @@ #include "atom_masks.h" #include "kokkos_base.h" -#include - using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_gravity_kokkos.cpp b/src/KOKKOS/fix_gravity_kokkos.cpp index 42a16eda78..01fcc0780c 100644 --- a/src/KOKKOS/fix_gravity_kokkos.cpp +++ b/src/KOKKOS/fix_gravity_kokkos.cpp @@ -16,7 +16,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "atom_vec.h" #include "input.h" #include "modify.h" #include "update.h" diff --git a/src/KOKKOS/fix_langevin_kokkos.h b/src/KOKKOS/fix_langevin_kokkos.h index 4fc22a1df1..05c5612313 100644 --- a/src/KOKKOS/fix_langevin_kokkos.h +++ b/src/KOKKOS/fix_langevin_kokkos.h @@ -27,7 +27,6 @@ FixStyle(langevin/kk/host,FixLangevinKokkos); #include "kokkos_type.h" #include "kokkos_base.h" #include "Kokkos_Random.hpp" -#include "comm_kokkos.h" namespace LAMMPS_NS { diff --git a/src/KOKKOS/fix_minimize_kokkos.cpp b/src/KOKKOS/fix_minimize_kokkos.cpp index e2106b3d03..585c357992 100644 --- a/src/KOKKOS/fix_minimize_kokkos.cpp +++ b/src/KOKKOS/fix_minimize_kokkos.cpp @@ -19,6 +19,8 @@ #include "domain.h" #include "memory_kokkos.h" +#include + using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_momentum_kokkos.cpp b/src/KOKKOS/fix_momentum_kokkos.cpp index b9220a417f..fa959cd582 100644 --- a/src/KOKKOS/fix_momentum_kokkos.cpp +++ b/src/KOKKOS/fix_momentum_kokkos.cpp @@ -18,11 +18,8 @@ #include "atom_masks.h" #include "domain_kokkos.h" #include "group.h" -#include "error.h" #include "kokkos_few.h" -#include - using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_neigh_history_kokkos.cpp b/src/KOKKOS/fix_neigh_history_kokkos.cpp index 49fe3f1177..d3df48354e 100644 --- a/src/KOKKOS/fix_neigh_history_kokkos.cpp +++ b/src/KOKKOS/fix_neigh_history_kokkos.cpp @@ -17,7 +17,6 @@ #include "atom_kokkos.h" #include "error.h" #include "memory_kokkos.h" -#include "modify.h" #include "neigh_list_kokkos.h" #include "pair_kokkos.h" #include "atom_vec_kokkos.h" diff --git a/src/KOKKOS/fix_nh_kokkos.cpp b/src/KOKKOS/fix_nh_kokkos.cpp index d038093317..1b87b3c775 100644 --- a/src/KOKKOS/fix_nh_kokkos.cpp +++ b/src/KOKKOS/fix_nh_kokkos.cpp @@ -18,18 +18,14 @@ #include "fix_nh_kokkos.h" -#include "atom.h" #include "atom_kokkos.h" #include "atom_masks.h" -#include "comm.h" #include "compute.h" #include "domain_kokkos.h" #include "error.h" -#include "fix_deform.h" #include "force.h" #include "irregular.h" #include "kspace.h" -#include "memory_kokkos.h" #include "neighbor.h" #include "update.h" diff --git a/src/KOKKOS/fix_nve_kokkos.cpp b/src/KOKKOS/fix_nve_kokkos.cpp index 59cc90c088..11b5184310 100644 --- a/src/KOKKOS/fix_nve_kokkos.cpp +++ b/src/KOKKOS/fix_nve_kokkos.cpp @@ -17,8 +17,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include - using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_nve_sphere_kokkos.cpp b/src/KOKKOS/fix_nve_sphere_kokkos.cpp index 38f6a40792..aed45c938c 100644 --- a/src/KOKKOS/fix_nve_sphere_kokkos.cpp +++ b/src/KOKKOS/fix_nve_sphere_kokkos.cpp @@ -15,7 +15,8 @@ #include "fix_nve_sphere_kokkos.h" #include "atom_masks.h" #include "atom_kokkos.h" -#include "error.h" + +#include using namespace LAMMPS_NS; diff --git a/src/KOKKOS/fix_nvt_kokkos.cpp b/src/KOKKOS/fix_nvt_kokkos.cpp index 16328c5e3a..7a8badd569 100644 --- a/src/KOKKOS/fix_nvt_kokkos.cpp +++ b/src/KOKKOS/fix_nvt_kokkos.cpp @@ -18,8 +18,6 @@ #include "group.h" #include "modify.h" -#include - using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_nvt_sllod_kokkos.cpp b/src/KOKKOS/fix_nvt_sllod_kokkos.cpp index 948e3b88f6..ddcc0c728c 100644 --- a/src/KOKKOS/fix_nvt_sllod_kokkos.cpp +++ b/src/KOKKOS/fix_nvt_sllod_kokkos.cpp @@ -18,21 +18,19 @@ #include "fix_nvt_sllod_kokkos.h" -#include "atom.h" -#include "atom.h" #include "atom_kokkos.h" #include "atom_masks.h" #include "compute.h" #include "domain.h" #include "error.h" -#include "fix.h" -#include "fix_deform_kokkos.h" +#include "fix_deform.h" #include "group.h" #include "kokkos_few.h" #include "math_extra.h" -#include "memory_kokkos.h" #include "modify.h" +#include + using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_property_atom_kokkos.cpp b/src/KOKKOS/fix_property_atom_kokkos.cpp index dcd943cac6..10cea48e90 100644 --- a/src/KOKKOS/fix_property_atom_kokkos.cpp +++ b/src/KOKKOS/fix_property_atom_kokkos.cpp @@ -16,7 +16,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "error.h" #include "memory_kokkos.h" #include diff --git a/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp b/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp index ba25d79ad5..f5b805844f 100644 --- a/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp +++ b/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp @@ -27,10 +27,8 @@ #include "fix_qeq_reaxff_kokkos.h" -#include "atom.h" #include "atom_kokkos.h" #include "atom_masks.h" -#include "atom_vec_kokkos.h" #include "comm.h" #include "error.h" #include "force.h" diff --git a/src/KOKKOS/fix_reaxff_species_kokkos.cpp b/src/KOKKOS/fix_reaxff_species_kokkos.cpp index 960ba07a86..7d742a8fa4 100644 --- a/src/KOKKOS/fix_reaxff_species_kokkos.cpp +++ b/src/KOKKOS/fix_reaxff_species_kokkos.cpp @@ -23,13 +23,11 @@ #include "comm.h" #include "error.h" #include "force.h" -#include "input.h" -#include "memory_kokkos.h" -#include "neigh_list.h" -#include "neigh_request.h" +#include "kokkos_type.h" +#include "neigh_list_kokkos.h" #include "fix_ave_atom.h" -#include "pair_reaxff_kokkos.h" +#include "pair_reaxff.h" #include "reaxff_defs.h" using namespace LAMMPS_NS; diff --git a/src/KOKKOS/fix_rx_kokkos.cpp b/src/KOKKOS/fix_rx_kokkos.cpp index 0ba56c611e..e07fbe119d 100644 --- a/src/KOKKOS/fix_rx_kokkos.cpp +++ b/src/KOKKOS/fix_rx_kokkos.cpp @@ -25,13 +25,12 @@ #include "math_special_kokkos.h" #include "memory_kokkos.h" #include "modify.h" -#include "neigh_list_kokkos.h" #include "neigh_request.h" #include "neighbor.h" #include "update.h" #include // DBL_EPSILON -#include +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_setforce_kokkos.cpp b/src/KOKKOS/fix_setforce_kokkos.cpp index 9f193bc6e4..e8f376643f 100644 --- a/src/KOKKOS/fix_setforce_kokkos.cpp +++ b/src/KOKKOS/fix_setforce_kokkos.cpp @@ -17,7 +17,6 @@ #include "atom_kokkos.h" #include "update.h" #include "modify.h" -#include "domain.h" #include "region.h" #include "input.h" #include "variable.h" @@ -26,8 +25,6 @@ #include "atom_masks.h" #include "kokkos_base.h" -#include - using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_shake_kokkos.cpp b/src/KOKKOS/fix_shake_kokkos.cpp index 791738e5a4..a4c66f6069 100644 --- a/src/KOKKOS/fix_shake_kokkos.cpp +++ b/src/KOKKOS/fix_shake_kokkos.cpp @@ -14,20 +14,12 @@ #include "fix_shake_kokkos.h" -#include "fix_rattle.h" #include "atom_kokkos.h" -#include "atom_vec.h" -#include "molecule.h" #include "update.h" -#include "respa.h" -#include "modify.h" #include "domain.h" #include "force.h" -#include "bond.h" -#include "angle.h" #include "comm.h" #include "group.h" -#include "fix_respa.h" #include "math_const.h" #include "memory_kokkos.h" #include "error.h" @@ -35,7 +27,6 @@ #include "atom_masks.h" #include -#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_shardlow_kokkos.cpp b/src/KOKKOS/fix_shardlow_kokkos.cpp index 4cbadc4803..a64adbcc38 100644 --- a/src/KOKKOS/fix_shardlow_kokkos.cpp +++ b/src/KOKKOS/fix_shardlow_kokkos.cpp @@ -43,7 +43,6 @@ #include "domain.h" #include "error.h" #include "force.h" -#include "memory_kokkos.h" #include "neigh_list_kokkos.h" #include "neigh_request.h" #include "neighbor.h" diff --git a/src/KOKKOS/fix_spring_self_kokkos.cpp b/src/KOKKOS/fix_spring_self_kokkos.cpp index 6571db37ed..9ba796b1ab 100644 --- a/src/KOKKOS/fix_spring_self_kokkos.cpp +++ b/src/KOKKOS/fix_spring_self_kokkos.cpp @@ -20,17 +20,10 @@ #include "atom_kokkos.h" #include "update.h" -#include "modify.h" #include "domain_kokkos.h" -#include "region.h" -#include "input.h" -#include "variable.h" #include "memory_kokkos.h" #include "error.h" #include "atom_masks.h" -#include "kokkos_base.h" - -#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_temp_berendsen_kokkos.cpp b/src/KOKKOS/fix_temp_berendsen_kokkos.cpp index b986b3189a..8aaf586194 100644 --- a/src/KOKKOS/fix_temp_berendsen_kokkos.cpp +++ b/src/KOKKOS/fix_temp_berendsen_kokkos.cpp @@ -15,11 +15,9 @@ #include "fix_temp_berendsen_kokkos.h" #include "atom_kokkos.h" -#include "comm.h" #include "compute.h" #include "error.h" #include "force.h" -#include "group.h" #include "input.h" #include "modify.h" #include "update.h" @@ -27,7 +25,6 @@ #include "atom_masks.h" #include -#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_temp_rescale_kokkos.cpp b/src/KOKKOS/fix_temp_rescale_kokkos.cpp index 3a1c6ddd26..5c295634e7 100644 --- a/src/KOKKOS/fix_temp_rescale_kokkos.cpp +++ b/src/KOKKOS/fix_temp_rescale_kokkos.cpp @@ -15,11 +15,9 @@ #include "fix_temp_rescale_kokkos.h" #include "atom_kokkos.h" -#include "comm.h" #include "compute.h" #include "error.h" #include "force.h" -#include "group.h" #include "input.h" #include "modify.h" #include "update.h" @@ -27,7 +25,6 @@ #include "atom_masks.h" #include -#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_viscous_kokkos.cpp b/src/KOKKOS/fix_viscous_kokkos.cpp index 80ddff2fce..86a5a35910 100644 --- a/src/KOKKOS/fix_viscous_kokkos.cpp +++ b/src/KOKKOS/fix_viscous_kokkos.cpp @@ -16,12 +16,8 @@ #include "atom_kokkos.h" #include "update.h" -#include "modify.h" -#include "input.h" -#include "memory_kokkos.h" #include "error.h" #include "atom_masks.h" -#include "kokkos_base.h" using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/KOKKOS/fix_wall_flow_kokkos.cpp b/src/KOKKOS/fix_wall_flow_kokkos.cpp index b6b3f7c096..e86cad54b4 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.cpp +++ b/src/KOKKOS/fix_wall_flow_kokkos.cpp @@ -19,10 +19,12 @@ #include "fix_wall_flow_kokkos.h" #include "atom_kokkos.h" #include "atom_masks.h" -#include "force.h" +#include "comm.h" #include "math_const.h" #include "memory_kokkos.h" +#include + using namespace LAMMPS_NS; template diff --git a/src/KOKKOS/fix_wall_flow_kokkos.h b/src/KOKKOS/fix_wall_flow_kokkos.h index 8de0eded0a..3535c74eb7 100644 --- a/src/KOKKOS/fix_wall_flow_kokkos.h +++ b/src/KOKKOS/fix_wall_flow_kokkos.h @@ -27,7 +27,6 @@ FixStyle(wall/flow/kk/host,FixWallFlowKokkos); #include "kokkos_type.h" #include "kokkos_base.h" #include "Kokkos_Random.hpp" -#include "comm_kokkos.h" namespace LAMMPS_NS { diff --git a/src/KOKKOS/fix_wall_gran_kokkos.cpp b/src/KOKKOS/fix_wall_gran_kokkos.cpp index 25e405c798..3ff97084fe 100644 --- a/src/KOKKOS/fix_wall_gran_kokkos.cpp +++ b/src/KOKKOS/fix_wall_gran_kokkos.cpp @@ -15,7 +15,6 @@ #include "atom_kokkos.h" #include "error.h" #include "memory_kokkos.h" -#include "atom_vec_kokkos.h" #include "atom_masks.h" #include "update.h" diff --git a/src/KOKKOS/fix_wall_lj93_kokkos.cpp b/src/KOKKOS/fix_wall_lj93_kokkos.cpp index dff47f1c30..6890a16c18 100644 --- a/src/KOKKOS/fix_wall_lj93_kokkos.cpp +++ b/src/KOKKOS/fix_wall_lj93_kokkos.cpp @@ -13,7 +13,7 @@ ------------------------------------------------------------------------- */ #include "fix_wall_lj93_kokkos.h" -#include + #include "atom_kokkos.h" #include "error.h" #include "atom_masks.h" diff --git a/src/KOKKOS/fix_wall_reflect_kokkos.cpp b/src/KOKKOS/fix_wall_reflect_kokkos.cpp index a8a01c1926..731ce11f10 100644 --- a/src/KOKKOS/fix_wall_reflect_kokkos.cpp +++ b/src/KOKKOS/fix_wall_reflect_kokkos.cpp @@ -21,8 +21,6 @@ #include "update.h" #include "variable.h" -#include - using namespace LAMMPS_NS; enum{XLO=0,XHI=1,YLO=2,YHI=3,ZLO=4,ZHI=5}; diff --git a/src/KOKKOS/min_cg_kokkos.cpp b/src/KOKKOS/min_cg_kokkos.cpp index 2ac869e4ea..17cce19a70 100644 --- a/src/KOKKOS/min_cg_kokkos.cpp +++ b/src/KOKKOS/min_cg_kokkos.cpp @@ -13,15 +13,16 @@ ------------------------------------------------------------------------- */ #include "min_cg_kokkos.h" -#include -#include -#include "update.h" -#include "output.h" -#include "timer.h" + #include "atom_kokkos.h" #include "atom_masks.h" #include "error.h" #include "fix_minimize_kokkos.h" +#include "output.h" +#include "timer.h" +#include "update.h" + +#include using namespace LAMMPS_NS; diff --git a/src/KOKKOS/mliap_data_kokkos.cpp b/src/KOKKOS/mliap_data_kokkos.cpp index dc8fe7dd83..8ff266c820 100644 --- a/src/KOKKOS/mliap_data_kokkos.cpp +++ b/src/KOKKOS/mliap_data_kokkos.cpp @@ -22,8 +22,6 @@ #include "kokkos_type.h" #include "pair_mliap_kokkos.h" #include "atom_masks.h" -#include "mliap_descriptor.h" -#include "lammps.h" #include "kokkos.h" /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/mliap_descriptor_so3_kokkos.cpp b/src/KOKKOS/mliap_descriptor_so3_kokkos.cpp index 7e30ab8cc7..1cf368e952 100644 --- a/src/KOKKOS/mliap_descriptor_so3_kokkos.cpp +++ b/src/KOKKOS/mliap_descriptor_so3_kokkos.cpp @@ -21,13 +21,9 @@ #include "atom_kokkos.h" #include "comm.h" #include "error.h" -#include "memory.h" #include "mliap_data_kokkos.h" #include "mliap_so3_kokkos.h" #include "pair_mliap.h" -#include "tokenizer.h" - -#include using namespace LAMMPS_NS; diff --git a/src/KOKKOS/mliap_model_linear_kokkos.cpp b/src/KOKKOS/mliap_model_linear_kokkos.cpp index b294dad294..f4fef82023 100644 --- a/src/KOKKOS/mliap_model_linear_kokkos.cpp +++ b/src/KOKKOS/mliap_model_linear_kokkos.cpp @@ -19,7 +19,6 @@ #include "mliap_model_linear_kokkos.h" #include "mliap_data_kokkos.h" -#include "error.h" using namespace LAMMPS_NS; diff --git a/src/KOKKOS/mliap_so3_kokkos.cpp b/src/KOKKOS/mliap_so3_kokkos.cpp index 3f6370a6fc..83f8deb3ee 100644 --- a/src/KOKKOS/mliap_so3_kokkos.cpp +++ b/src/KOKKOS/mliap_so3_kokkos.cpp @@ -21,7 +21,6 @@ #include "error.h" #include "math_const.h" #include "math_special_kokkos.h" -#include "memory.h" #include "memory_kokkos.h" #include "mliap_so3_math.h" diff --git a/src/KOKKOS/nbin_ssa_kokkos.cpp b/src/KOKKOS/nbin_ssa_kokkos.cpp index 6e7390d3c6..63c2fe22c1 100644 --- a/src/KOKKOS/nbin_ssa_kokkos.cpp +++ b/src/KOKKOS/nbin_ssa_kokkos.cpp @@ -18,13 +18,12 @@ ------------------------------------------------------------------------- */ #include "nbin_ssa_kokkos.h" -#include "neighbor.h" + #include "atom_kokkos.h" #include "domain.h" #include "update.h" #include "atom_masks.h" - -// #include "memory_kokkos.h" +#include "kokkos_type.h" using namespace LAMMPS_NS; diff --git a/src/KOKKOS/neigh_bond_kokkos.cpp b/src/KOKKOS/neigh_bond_kokkos.cpp index 85ca6c916e..9e1c8c273b 100644 --- a/src/KOKKOS/neigh_bond_kokkos.cpp +++ b/src/KOKKOS/neigh_bond_kokkos.cpp @@ -27,6 +27,7 @@ #include "force.h" #include "memory_kokkos.h" #include "modify.h" +#include "neighbor.h" #include "output.h" #include "thermo.h" #include "update.h" diff --git a/src/KOKKOS/neigh_bond_kokkos.h b/src/KOKKOS/neigh_bond_kokkos.h index 480726c602..f60903f73e 100644 --- a/src/KOKKOS/neigh_bond_kokkos.h +++ b/src/KOKKOS/neigh_bond_kokkos.h @@ -15,9 +15,7 @@ #ifndef LMP_NEIGH_BOND_KOKKOS_H #define LMP_NEIGH_BOND_KOKKOS_H -#include "neighbor.h" #include "kokkos_type.h" -#include "domain_kokkos.h" #include "pointers.h" #include diff --git a/src/KOKKOS/neighbor_kokkos.cpp b/src/KOKKOS/neighbor_kokkos.cpp index efb1247560..67af5b2b28 100644 --- a/src/KOKKOS/neighbor_kokkos.cpp +++ b/src/KOKKOS/neighbor_kokkos.cpp @@ -18,16 +18,13 @@ #include "atom_kokkos.h" #include "atom_masks.h" #include "bond.h" -#include "comm.h" #include "dihedral.h" #include "error.h" -#include "fix.h" #include "force.h" #include "improper.h" #include "kokkos.h" #include "memory_kokkos.h" #include "neigh_request.h" -#include "pair.h" #include "style_nbin.h" #include "style_npair.h" #include "style_nstencil.h" diff --git a/src/KOKKOS/npair_skip_kokkos.cpp b/src/KOKKOS/npair_skip_kokkos.cpp index 15c0487010..91a2cfa17e 100644 --- a/src/KOKKOS/npair_skip_kokkos.cpp +++ b/src/KOKKOS/npair_skip_kokkos.cpp @@ -16,7 +16,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "atom_vec.h" #include "neigh_list_kokkos.h" using namespace LAMMPS_NS; diff --git a/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp b/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp index a859b232be..ebe49b59a0 100644 --- a/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp +++ b/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp @@ -25,14 +25,12 @@ #include "kokkos.h" #include "math_const.h" #include "memory_kokkos.h" -#include "neigh_list.h" #include "neigh_request.h" #include "neighbor.h" #include "respa.h" #include "update.h" #include -#include using namespace LAMMPS_NS; using namespace MathConst; diff --git a/src/KOKKOS/pair_buck_kokkos.cpp b/src/KOKKOS/pair_buck_kokkos.cpp index b549fcd329..88b0445dc8 100644 --- a/src/KOKKOS/pair_buck_kokkos.cpp +++ b/src/KOKKOS/pair_buck_kokkos.cpp @@ -24,14 +24,12 @@ #include "force.h" #include "kokkos.h" #include "memory_kokkos.h" -#include "neigh_list.h" #include "neigh_request.h" #include "neighbor.h" #include "respa.h" #include "update.h" #include -#include using namespace LAMMPS_NS; diff --git a/src/KOKKOS/pair_coul_cut_kokkos.cpp b/src/KOKKOS/pair_coul_cut_kokkos.cpp index 283a4b2b69..1796bd93fd 100644 --- a/src/KOKKOS/pair_coul_cut_kokkos.cpp +++ b/src/KOKKOS/pair_coul_cut_kokkos.cpp @@ -20,7 +20,6 @@ #include "force.h" #include "kokkos.h" #include "memory_kokkos.h" -#include "neigh_list.h" #include "neigh_request.h" #include "neighbor.h" diff --git a/src/KOKKOS/pair_coul_debye_kokkos.cpp b/src/KOKKOS/pair_coul_debye_kokkos.cpp index 4c0e610e89..eb61716640 100644 --- a/src/KOKKOS/pair_coul_debye_kokkos.cpp +++ b/src/KOKKOS/pair_coul_debye_kokkos.cpp @@ -24,14 +24,10 @@ #include "force.h" #include "kokkos.h" #include "memory_kokkos.h" -#include "neigh_list.h" #include "neigh_request.h" #include "neighbor.h" -#include "respa.h" -#include "update.h" #include -#include using namespace LAMMPS_NS; diff --git a/src/KOKKOS/pair_coul_dsf_kokkos.cpp b/src/KOKKOS/pair_coul_dsf_kokkos.cpp index 5184c42096..9e0db27f36 100644 --- a/src/KOKKOS/pair_coul_dsf_kokkos.cpp +++ b/src/KOKKOS/pair_coul_dsf_kokkos.cpp @@ -20,7 +20,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "error.h" #include "ewald_const.h" #include "force.h" #include "kokkos.h" diff --git a/src/KOKKOS/pair_coul_wolf_kokkos.cpp b/src/KOKKOS/pair_coul_wolf_kokkos.cpp index 2ccf7a5a15..af5067db16 100644 --- a/src/KOKKOS/pair_coul_wolf_kokkos.cpp +++ b/src/KOKKOS/pair_coul_wolf_kokkos.cpp @@ -20,7 +20,6 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "error.h" #include "force.h" #include "kokkos.h" #include "math_const.h" diff --git a/src/KOKKOS/pair_hybrid_kokkos.cpp b/src/KOKKOS/pair_hybrid_kokkos.cpp index eabce17a1c..84d43bcec8 100644 --- a/src/KOKKOS/pair_hybrid_kokkos.cpp +++ b/src/KOKKOS/pair_hybrid_kokkos.cpp @@ -14,14 +14,10 @@ ------------------------------------------------------------------------- */ #include "pair_hybrid_kokkos.h" -#include + #include "atom_kokkos.h" #include "force.h" -#include "pair.h" -#include "neighbor.h" -#include "neigh_request.h" #include "update.h" -#include "memory_kokkos.h" #include "respa.h" #include "atom_masks.h" #include "kokkos.h" diff --git a/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp b/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp index 7c61c684e4..626f05106c 100644 --- a/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp @@ -20,14 +20,12 @@ #include "force.h" #include "kokkos.h" #include "memory_kokkos.h" -#include "neigh_list.h" #include "neigh_request.h" #include "neighbor.h" #include "respa.h" #include "update.h" #include -#include using namespace LAMMPS_NS; diff --git a/src/KOKKOS/pair_lj_cut_kokkos.cpp b/src/KOKKOS/pair_lj_cut_kokkos.cpp index 9a1ced9da3..566d74088c 100644 --- a/src/KOKKOS/pair_lj_cut_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_kokkos.cpp @@ -20,14 +20,11 @@ #include "force.h" #include "kokkos.h" #include "memory_kokkos.h" -#include "neigh_list.h" #include "neigh_request.h" #include "neighbor.h" #include "respa.h" #include "update.h" -#include - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/third_order_kokkos.cpp b/src/KOKKOS/third_order_kokkos.cpp index 04c467777f..569a94a773 100644 --- a/src/KOKKOS/third_order_kokkos.cpp +++ b/src/KOKKOS/third_order_kokkos.cpp @@ -23,27 +23,18 @@ #include "atom_masks.h" #include "bond.h" #include "comm.h" -#include "compute.h" #include "dihedral.h" #include "domain.h" -#include "error.h" -#include "finish.h" #include "force.h" -#include "group.h" #include "improper.h" #include "kokkos.h" #include "kspace.h" -#include "memory.h" #include "modify.h" #include "neighbor.h" #include "pair.h" #include "timer.h" #include "update.h" -#include -#include -#include - using namespace LAMMPS_NS; enum{REGULAR,ESKM}; diff --git a/src/KOKKOS/verlet_kokkos.cpp b/src/KOKKOS/verlet_kokkos.cpp index 7570f1d8fa..858df5df6c 100644 --- a/src/KOKKOS/verlet_kokkos.cpp +++ b/src/KOKKOS/verlet_kokkos.cpp @@ -29,7 +29,6 @@ #include "update.h" #include "modify_kokkos.h" #include "timer.h" -#include "memory_kokkos.h" #include "kokkos.h" using namespace LAMMPS_NS; diff --git a/src/KSPACE/pppm.cpp b/src/KSPACE/pppm.cpp index 2616282973..4fe5075f44 100644 --- a/src/KSPACE/pppm.cpp +++ b/src/KSPACE/pppm.cpp @@ -24,14 +24,12 @@ #include "angle.h" #include "atom.h" #include "bond.h" -#include "comm.h" #include "domain.h" #include "error.h" #include "fft3d_wrap.h" #include "force.h" #include "grid3d.h" #include "math_const.h" -#include "math_extra.h" #include "math_special.h" #include "memory.h" #include "neighbor.h" diff --git a/src/KSPACE/pppm_cg.cpp b/src/KSPACE/pppm_cg.cpp index e5ae0b05c8..cebf9e0000 100644 --- a/src/KSPACE/pppm_cg.cpp +++ b/src/KSPACE/pppm_cg.cpp @@ -26,7 +26,6 @@ #include "math_const.h" #include "memory.h" #include "neighbor.h" -#include "remap.h" #include #include diff --git a/src/LEPTON/angle_lepton.cpp b/src/LEPTON/angle_lepton.cpp index 9fe565f8ee..6efded950f 100644 --- a/src/LEPTON/angle_lepton.cpp +++ b/src/LEPTON/angle_lepton.cpp @@ -27,6 +27,8 @@ #include "neighbor.h" #include +#include +#include #include "Lepton.h" #include "lepton_utils.h" diff --git a/src/LEPTON/bond_lepton.cpp b/src/LEPTON/bond_lepton.cpp index 8679d0ed62..63c66011a1 100644 --- a/src/LEPTON/bond_lepton.cpp +++ b/src/LEPTON/bond_lepton.cpp @@ -25,6 +25,8 @@ #include "neighbor.h" #include +#include +#include #include "Lepton.h" #include "lepton_utils.h" diff --git a/src/LEPTON/dihedral_lepton.cpp b/src/LEPTON/dihedral_lepton.cpp index 069ff13d74..16975a8f52 100644 --- a/src/LEPTON/dihedral_lepton.cpp +++ b/src/LEPTON/dihedral_lepton.cpp @@ -29,6 +29,7 @@ #include "neighbor.h" #include +#include #include "Lepton.h" #include "lepton_utils.h" diff --git a/src/LEPTON/fix_wall_lepton.cpp b/src/LEPTON/fix_wall_lepton.cpp index 7530188c00..320efb090e 100644 --- a/src/LEPTON/fix_wall_lepton.cpp +++ b/src/LEPTON/fix_wall_lepton.cpp @@ -19,6 +19,8 @@ #include "Lepton.h" #include "lepton_utils.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/LEPTON/lepton_utils.cpp b/src/LEPTON/lepton_utils.cpp index 89e69beddd..c4e527d7d7 100644 --- a/src/LEPTON/lepton_utils.cpp +++ b/src/LEPTON/lepton_utils.cpp @@ -17,7 +17,6 @@ #include "lepton_utils.h" -#include "error.h" #include "input.h" #include "lammps.h" #include "pair_zbl_const.h" diff --git a/src/LEPTON/pair_lepton.cpp b/src/LEPTON/pair_lepton.cpp index adc07cbfa8..90003e9091 100644 --- a/src/LEPTON/pair_lepton.cpp +++ b/src/LEPTON/pair_lepton.cpp @@ -23,12 +23,12 @@ #include "force.h" #include "memory.h" #include "neigh_list.h" -#include "update.h" #include "Lepton.h" #include "lepton_utils.h" -#include + #include +#include #include using namespace LAMMPS_NS; diff --git a/src/LEPTON/pair_lepton_coul.cpp b/src/LEPTON/pair_lepton_coul.cpp index f7d2042874..bb6b8ed55f 100644 --- a/src/LEPTON/pair_lepton_coul.cpp +++ b/src/LEPTON/pair_lepton_coul.cpp @@ -21,16 +21,16 @@ #include "comm.h" #include "error.h" #include "force.h" -#include "memory.h" #include "neigh_list.h" #include "neighbor.h" -#include "update.h" #include "Lepton.h" #include "lepton_utils.h" #include #include +#include +#include using namespace LAMMPS_NS; diff --git a/src/LEPTON/pair_lepton_sphere.cpp b/src/LEPTON/pair_lepton_sphere.cpp index 72d0e85d0b..63b082774f 100644 --- a/src/LEPTON/pair_lepton_sphere.cpp +++ b/src/LEPTON/pair_lepton_sphere.cpp @@ -21,15 +21,15 @@ #include "comm.h" #include "error.h" #include "force.h" -#include "memory.h" #include "neigh_list.h" #include "neighbor.h" -#include "update.h" #include "Lepton.h" #include "lepton_utils.h" + #include #include +#include using namespace LAMMPS_NS; diff --git a/src/MACHDYN/fix_smd_wall_surface.cpp b/src/MACHDYN/fix_smd_wall_surface.cpp index f8a8ef970c..25e76e1dab 100644 --- a/src/MACHDYN/fix_smd_wall_surface.cpp +++ b/src/MACHDYN/fix_smd_wall_surface.cpp @@ -26,6 +26,7 @@ #include "text_file_reader.h" #include +#include #include using namespace LAMMPS_NS; diff --git a/src/MANYBODY/pair_meam_spline.cpp b/src/MANYBODY/pair_meam_spline.cpp index e888e2274c..e3d17f6fae 100644 --- a/src/MANYBODY/pair_meam_spline.cpp +++ b/src/MANYBODY/pair_meam_spline.cpp @@ -46,6 +46,7 @@ #include #include +#include using namespace LAMMPS_NS; diff --git a/src/MANYBODY/pair_meam_sw_spline.cpp b/src/MANYBODY/pair_meam_sw_spline.cpp index 5b5713dc4c..a19e1cc0fa 100644 --- a/src/MANYBODY/pair_meam_sw_spline.cpp +++ b/src/MANYBODY/pair_meam_sw_spline.cpp @@ -33,6 +33,7 @@ #include #include +#include using namespace LAMMPS_NS; diff --git a/src/MANYBODY/pair_sw_angle_table.cpp b/src/MANYBODY/pair_sw_angle_table.cpp index 8e605caebd..12592f4af6 100644 --- a/src/MANYBODY/pair_sw_angle_table.cpp +++ b/src/MANYBODY/pair_sw_angle_table.cpp @@ -26,7 +26,6 @@ #include "math_const.h" #include "memory.h" #include "neigh_list.h" -#include "neighbor.h" #include "table_file_reader.h" #include "potential_file_reader.h" diff --git a/src/MC/fix_charge_regulation.cpp b/src/MC/fix_charge_regulation.cpp index 1690e647dc..4358513095 100644 --- a/src/MC/fix_charge_regulation.cpp +++ b/src/MC/fix_charge_regulation.cpp @@ -46,6 +46,7 @@ #include #include +#include #include using namespace LAMMPS_NS; diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index 2d35528219..bd7e46b3d1 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -45,6 +45,7 @@ #include #include +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/MC/fix_widom.cpp b/src/MC/fix_widom.cpp index d0840c80b7..9871dc8f60 100644 --- a/src/MC/fix_widom.cpp +++ b/src/MC/fix_widom.cpp @@ -45,6 +45,7 @@ #include #include +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/MDI/fix_mdi_engine.cpp b/src/MDI/fix_mdi_engine.cpp index 0494d08b2d..fe896d906f 100644 --- a/src/MDI/fix_mdi_engine.cpp +++ b/src/MDI/fix_mdi_engine.cpp @@ -19,7 +19,6 @@ #include "fix_mdi_engine.h" #include "error.h" -#include "update.h" #include "mdi_engine.h" diff --git a/src/MDI/fix_mdi_qm.cpp b/src/MDI/fix_mdi_qm.cpp index 86dc87fd35..46071c5c90 100644 --- a/src/MDI/fix_mdi_qm.cpp +++ b/src/MDI/fix_mdi_qm.cpp @@ -22,6 +22,8 @@ #include "modify.h" #include "update.h" +#include + using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/MDI/fix_mdi_qmmm.cpp b/src/MDI/fix_mdi_qmmm.cpp index c6df52333d..d45290811f 100644 --- a/src/MDI/fix_mdi_qmmm.cpp +++ b/src/MDI/fix_mdi_qmmm.cpp @@ -12,6 +12,7 @@ ------------------------------------------------------------------------- */ #include "fix_mdi_qmmm.h" + #include "atom.h" #include "comm.h" #include "domain.h" @@ -25,6 +26,9 @@ #include "pair.h" #include "update.h" +#include +#include + using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/MDI/mdi_engine.cpp b/src/MDI/mdi_engine.cpp index 9c58de7560..6d7c604fa6 100644 --- a/src/MDI/mdi_engine.cpp +++ b/src/MDI/mdi_engine.cpp @@ -25,12 +25,10 @@ #include "error.h" #include "fix_mdi_engine.h" #include "force.h" -#include "group.h" #include "input.h" #include "integrate.h" #include "irregular.h" #include "library.h" -#include "library_mdi.h" #include "memory.h" #include "min.h" #include "modify.h" diff --git a/src/MDI/mdi_plugin.cpp b/src/MDI/mdi_plugin.cpp index 92b78b6afb..6294292229 100644 --- a/src/MDI/mdi_plugin.cpp +++ b/src/MDI/mdi_plugin.cpp @@ -21,9 +21,7 @@ #include "error.h" #include "input.h" #include "memory.h" -#include "modify.h" -#include #include #include diff --git a/src/MEAM/pair_meam_ms.cpp b/src/MEAM/pair_meam_ms.cpp index 982a54f546..e5cb960b59 100644 --- a/src/MEAM/pair_meam_ms.cpp +++ b/src/MEAM/pair_meam_ms.cpp @@ -12,6 +12,7 @@ ------------------------------------------------------------------------- */ #include "pair_meam_ms.h" + #include "meam.h" using namespace LAMMPS_NS; diff --git a/src/MESONT/angle_mesocnt.cpp b/src/MESONT/angle_mesocnt.cpp index 06ec135e3c..c6dae4b0fb 100644 --- a/src/MESONT/angle_mesocnt.cpp +++ b/src/MESONT/angle_mesocnt.cpp @@ -30,6 +30,7 @@ #include "update.h" #include +#include using namespace LAMMPS_NS; using MathConst::DEG2RAD; diff --git a/src/MESONT/bond_mesocnt.cpp b/src/MESONT/bond_mesocnt.cpp index 1623c4b1fc..5f468bd720 100644 --- a/src/MESONT/bond_mesocnt.cpp +++ b/src/MESONT/bond_mesocnt.cpp @@ -24,7 +24,6 @@ #include "force.h" #include "math_const.h" #include "memory.h" -#include "neighbor.h" #include "update.h" #include diff --git a/src/MESONT/pair_mesocnt.cpp b/src/MESONT/pair_mesocnt.cpp index 133170f883..21b04268c4 100644 --- a/src/MESONT/pair_mesocnt.cpp +++ b/src/MESONT/pair_mesocnt.cpp @@ -34,9 +34,9 @@ #include #include #include -#include +#include +#include #include -#include using namespace LAMMPS_NS; using namespace MathExtra; diff --git a/src/ML-IAP/compute_mliap.cpp b/src/ML-IAP/compute_mliap.cpp index 38e0912344..0ee35ea080 100644 --- a/src/ML-IAP/compute_mliap.cpp +++ b/src/ML-IAP/compute_mliap.cpp @@ -34,6 +34,7 @@ #include "memory.h" #include "modify.h" #include "neighbor.h" +#include "neigh_list.h" #include "pair.h" #include "update.h" diff --git a/src/ML-PACE/compute_pace.cpp b/src/ML-PACE/compute_pace.cpp index c2a0f9a9e6..fee9a0fa0e 100644 --- a/src/ML-PACE/compute_pace.cpp +++ b/src/ML-PACE/compute_pace.cpp @@ -12,7 +12,6 @@ #include "compute_pace.h" -#include "ace-evaluator/ace_abstract_basis.h" #include "ace-evaluator/ace_c_basis.h" #include "ace-evaluator/ace_evaluator.h" #include "ace-evaluator/ace_types.h" @@ -24,14 +23,10 @@ #include "memory.h" #include "modify.h" #include "neigh_list.h" -#include "neigh_request.h" #include "neighbor.h" #include "pair.h" #include "update.h" -#include -#include - namespace LAMMPS_NS { struct ACECimpl { ACECimpl() : basis_set(nullptr), ace(nullptr) {} diff --git a/src/ML-PACE/pair_pace_extrapolation.cpp b/src/ML-PACE/pair_pace_extrapolation.cpp index d9b8d3588a..ec42d232af 100644 --- a/src/ML-PACE/pair_pace_extrapolation.cpp +++ b/src/ML-PACE/pair_pace_extrapolation.cpp @@ -29,15 +29,12 @@ Copyright 2022 Yury Lysogorskiy^1, Anton Bochkarev^1, Matous Mrovec^1, Ralf Drau #include "force.h" #include "math_const.h" #include "memory.h" -#include "modify.h" #include "neigh_list.h" -#include "neigh_request.h" #include "neighbor.h" #include "update.h" -#include -#include #include +#include #include "ace/ace_b_basis.h" #include "ace/ace_b_evaluator.h" diff --git a/src/ML-PACE/pair_pace_extrapolation.h b/src/ML-PACE/pair_pace_extrapolation.h index 2dcec04d4b..440d999029 100644 --- a/src/ML-PACE/pair_pace_extrapolation.h +++ b/src/ML-PACE/pair_pace_extrapolation.h @@ -28,7 +28,6 @@ PairStyle(pace/extrapolation,PairPACEExtrapolation) #define LMP_PAIR_PACE_AL_H #include "pair.h" -#include namespace LAMMPS_NS { diff --git a/src/ML-SNAP/compute_sna_atom.cpp b/src/ML-SNAP/compute_sna_atom.cpp index b1b4a46482..c3582f200c 100644 --- a/src/ML-SNAP/compute_sna_atom.cpp +++ b/src/ML-SNAP/compute_sna_atom.cpp @@ -26,6 +26,7 @@ #include "memory.h" #include "error.h" +#include #include using namespace LAMMPS_NS; diff --git a/src/MOLECULE/bond_gromos.cpp b/src/MOLECULE/bond_gromos.cpp index badb808007..1917f18686 100644 --- a/src/MOLECULE/bond_gromos.cpp +++ b/src/MOLECULE/bond_gromos.cpp @@ -24,6 +24,7 @@ #include "memory.h" #include "neighbor.h" +#include #include using namespace LAMMPS_NS; diff --git a/src/MOLECULE/pair_tip4p_cut.cpp b/src/MOLECULE/pair_tip4p_cut.cpp index 6d27c1a164..73a5651e6b 100644 --- a/src/MOLECULE/pair_tip4p_cut.cpp +++ b/src/MOLECULE/pair_tip4p_cut.cpp @@ -30,6 +30,7 @@ #include "neighbor.h" #include +#include using namespace LAMMPS_NS; diff --git a/src/MOLFILE/molfile_interface.cpp b/src/MOLFILE/molfile_interface.cpp index 8f5ac8545e..84aa63cefc 100644 --- a/src/MOLFILE/molfile_interface.cpp +++ b/src/MOLFILE/molfile_interface.cpp @@ -26,7 +26,6 @@ #include #include -#include #if vmdplugin_ABIVERSION < 16 #error "unsupported VMD molfile plugin ABI version" diff --git a/src/OPENMP/angle_lepton_omp.cpp b/src/OPENMP/angle_lepton_omp.cpp index f57cf916a2..918fb57871 100644 --- a/src/OPENMP/angle_lepton_omp.cpp +++ b/src/OPENMP/angle_lepton_omp.cpp @@ -16,13 +16,16 @@ ------------------------------------------------------------------------- */ #include "angle_lepton_omp.h" + #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" #include "neighbor.h" #include "suffix.h" #include +#include #include "Lepton.h" #include "lepton_utils.h" diff --git a/src/OPENMP/bond_lepton_omp.cpp b/src/OPENMP/bond_lepton_omp.cpp index d9982b08f8..995e2fac09 100644 --- a/src/OPENMP/bond_lepton_omp.cpp +++ b/src/OPENMP/bond_lepton_omp.cpp @@ -18,11 +18,13 @@ #include "bond_lepton_omp.h" #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" #include "neighbor.h" #include "suffix.h" #include +#include #include "Lepton.h" #include "lepton_utils.h" diff --git a/src/OPENMP/dihedral_lepton_omp.cpp b/src/OPENMP/dihedral_lepton_omp.cpp index 37748ce9d5..206749fcfa 100644 --- a/src/OPENMP/dihedral_lepton_omp.cpp +++ b/src/OPENMP/dihedral_lepton_omp.cpp @@ -18,12 +18,14 @@ #include "dihedral_lepton_omp.h" #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" #include "math_extra.h" #include "neighbor.h" #include "suffix.h" #include +#include #include "Lepton.h" #include "lepton_utils.h" diff --git a/src/OPENMP/fix_nh_omp.cpp b/src/OPENMP/fix_nh_omp.cpp index d3565c4994..7ef69af0fe 100644 --- a/src/OPENMP/fix_nh_omp.cpp +++ b/src/OPENMP/fix_nh_omp.cpp @@ -22,7 +22,6 @@ #include "compute.h" #include "domain.h" #include "error.h" -#include "modify.h" #include diff --git a/src/OPENMP/fix_rigid_nh_omp.cpp b/src/OPENMP/fix_rigid_nh_omp.cpp index 19e5d4f240..f5e4a1f49d 100644 --- a/src/OPENMP/fix_rigid_nh_omp.cpp +++ b/src/OPENMP/fix_rigid_nh_omp.cpp @@ -30,7 +30,6 @@ #include "kspace.h" #include "math_const.h" #include "math_extra.h" -#include "modify.h" #include "rigid_const.h" #include "update.h" diff --git a/src/OPENMP/npair_bin_omp.cpp b/src/OPENMP/npair_bin_omp.cpp index 5b2189dec2..7922d76612 100644 --- a/src/OPENMP/npair_bin_omp.cpp +++ b/src/OPENMP/npair_bin_omp.cpp @@ -25,6 +25,8 @@ #include "my_page.h" #include "neigh_list.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/OPENMP/npair_multi_old_omp.cpp b/src/OPENMP/npair_multi_old_omp.cpp index d45f2d1f5f..fa790e177a 100644 --- a/src/OPENMP/npair_multi_old_omp.cpp +++ b/src/OPENMP/npair_multi_old_omp.cpp @@ -24,6 +24,8 @@ #include "my_page.h" #include "neigh_list.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/OPENMP/npair_multi_omp.cpp b/src/OPENMP/npair_multi_omp.cpp index 3f8604572c..cbc21ebc29 100644 --- a/src/OPENMP/npair_multi_omp.cpp +++ b/src/OPENMP/npair_multi_omp.cpp @@ -26,6 +26,8 @@ #include "neigh_list.h" #include "neighbor.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/OPENMP/npair_nsq_omp.cpp b/src/OPENMP/npair_nsq_omp.cpp index c482fc8f2d..5d6aa518b0 100644 --- a/src/OPENMP/npair_nsq_omp.cpp +++ b/src/OPENMP/npair_nsq_omp.cpp @@ -27,6 +27,8 @@ #include "neigh_list.h" #include "neighbor.h" +#include + using namespace LAMMPS_NS; using namespace NeighConst; diff --git a/src/OPENMP/npair_respa_bin_omp.cpp b/src/OPENMP/npair_respa_bin_omp.cpp index c958167ba0..a069affb06 100644 --- a/src/OPENMP/npair_respa_bin_omp.cpp +++ b/src/OPENMP/npair_respa_bin_omp.cpp @@ -25,6 +25,8 @@ #include "my_page.h" #include "neigh_list.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/OPENMP/npair_respa_nsq_omp.cpp b/src/OPENMP/npair_respa_nsq_omp.cpp index 6815b21544..deba473678 100644 --- a/src/OPENMP/npair_respa_nsq_omp.cpp +++ b/src/OPENMP/npair_respa_nsq_omp.cpp @@ -26,6 +26,8 @@ #include "my_page.h" #include "neigh_list.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/OPENMP/pair_lepton_coul_omp.cpp b/src/OPENMP/pair_lepton_coul_omp.cpp index 532c16d797..ae737ef1cb 100644 --- a/src/OPENMP/pair_lepton_coul_omp.cpp +++ b/src/OPENMP/pair_lepton_coul_omp.cpp @@ -16,6 +16,7 @@ #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" #include "neigh_list.h" #include "suffix.h" @@ -26,6 +27,7 @@ #include #include +#include using namespace LAMMPS_NS; diff --git a/src/OPENMP/pair_lepton_omp.cpp b/src/OPENMP/pair_lepton_omp.cpp index 58692e52d6..3b07a7b757 100644 --- a/src/OPENMP/pair_lepton_omp.cpp +++ b/src/OPENMP/pair_lepton_omp.cpp @@ -16,6 +16,7 @@ #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" #include "neigh_list.h" #include "suffix.h" @@ -23,8 +24,9 @@ #include "Lepton.h" #include "lepton_utils.h" #include "omp_compat.h" -#include + #include +#include using namespace LAMMPS_NS; diff --git a/src/OPENMP/pair_lepton_sphere_omp.cpp b/src/OPENMP/pair_lepton_sphere_omp.cpp index 79afe27717..6de9714f3e 100644 --- a/src/OPENMP/pair_lepton_sphere_omp.cpp +++ b/src/OPENMP/pair_lepton_sphere_omp.cpp @@ -16,6 +16,7 @@ #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" #include "neigh_list.h" #include "suffix.h" @@ -26,6 +27,7 @@ #include #include +#include using namespace LAMMPS_NS; diff --git a/src/OPENMP/pair_lj_expand_sphere_omp.cpp b/src/OPENMP/pair_lj_expand_sphere_omp.cpp index c19d3e7a7f..40f878cdc2 100644 --- a/src/OPENMP/pair_lj_expand_sphere_omp.cpp +++ b/src/OPENMP/pair_lj_expand_sphere_omp.cpp @@ -21,6 +21,8 @@ #include "neigh_list.h" #include "suffix.h" +#include + #include "omp_compat.h" using namespace LAMMPS_NS; using MathSpecial::powint; diff --git a/src/OPENMP/pair_rebomos_omp.cpp b/src/OPENMP/pair_rebomos_omp.cpp index 5143fd0f63..06b979d41a 100644 --- a/src/OPENMP/pair_rebomos_omp.cpp +++ b/src/OPENMP/pair_rebomos_omp.cpp @@ -47,7 +47,6 @@ #endif using namespace LAMMPS_NS; -using namespace MathConst; using MathSpecial::cube; using MathSpecial::powint; using MathSpecial::square; diff --git a/src/POEMS/fix_poems.cpp b/src/POEMS/fix_poems.cpp index a2720a3f64..eb9c790422 100644 --- a/src/POEMS/fix_poems.cpp +++ b/src/POEMS/fix_poems.cpp @@ -36,7 +36,7 @@ #include #include -#include +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/PTM/compute_ptm_atom.cpp b/src/PTM/compute_ptm_atom.cpp index e66bc1a17d..4d6cd4bc01 100644 --- a/src/PTM/compute_ptm_atom.cpp +++ b/src/PTM/compute_ptm_atom.cpp @@ -28,7 +28,6 @@ under #include "memory.h" #include "modify.h" #include "neigh_list.h" -#include "neigh_request.h" #include "neighbor.h" #include "update.h" diff --git a/src/PTM/ptm_convex_hull_incremental.h b/src/PTM/ptm_convex_hull_incremental.h index 796c787937..81fc92d829 100644 --- a/src/PTM/ptm_convex_hull_incremental.h +++ b/src/PTM/ptm_convex_hull_incremental.h @@ -11,7 +11,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #define PTM_CONVEX_HULL_INCREMENTAL_H #include "ptm_constants.h" -#include #include namespace ptm { diff --git a/src/PYTHON/python_impl.cpp b/src/PYTHON/python_impl.cpp index 0db468d701..87a57187bf 100644 --- a/src/PYTHON/python_impl.cpp +++ b/src/PYTHON/python_impl.cpp @@ -17,7 +17,6 @@ #include "python_impl.h" -#include "comm.h" #include "error.h" #include "input.h" #include "memory.h" diff --git a/src/QEQ/fix_qeq.cpp b/src/QEQ/fix_qeq.cpp index 22632cf786..411bdfb60b 100644 --- a/src/QEQ/fix_qeq.cpp +++ b/src/QEQ/fix_qeq.cpp @@ -27,9 +27,7 @@ #include "memory.h" #include "modify.h" #include "neigh_list.h" -#include "pair.h" #include "respa.h" -#include "suffix.h" #include "text_file_reader.h" #include "update.h" diff --git a/src/REAXFF/compute_reaxff_atom.cpp b/src/REAXFF/compute_reaxff_atom.cpp index 212d117ac7..0371f75120 100644 --- a/src/REAXFF/compute_reaxff_atom.cpp +++ b/src/REAXFF/compute_reaxff_atom.cpp @@ -17,8 +17,8 @@ ------------------------------------------------------------------------- */ #include "compute_reaxff_atom.h" + #include "atom.h" -#include "molecule.h" #include "update.h" #include "force.h" #include "memory.h" diff --git a/src/REAXFF/fix_acks2_reaxff.cpp b/src/REAXFF/fix_acks2_reaxff.cpp index 68de1c8ed1..4fd86605fa 100644 --- a/src/REAXFF/fix_acks2_reaxff.cpp +++ b/src/REAXFF/fix_acks2_reaxff.cpp @@ -33,6 +33,7 @@ #include #include +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/REAXFF/reaxff_ffield.cpp b/src/REAXFF/reaxff_ffield.cpp index 6ca8dc6256..b941d7d0f0 100644 --- a/src/REAXFF/reaxff_ffield.cpp +++ b/src/REAXFF/reaxff_ffield.cpp @@ -30,7 +30,6 @@ #include "error.h" #include "memory.h" #include "text_file_reader.h" -#include "tokenizer.h" #include "utils.h" #include diff --git a/src/REPLICA/fix_alchemy.cpp b/src/REPLICA/fix_alchemy.cpp index 2fe4417161..b14c6bc22d 100644 --- a/src/REPLICA/fix_alchemy.cpp +++ b/src/REPLICA/fix_alchemy.cpp @@ -21,7 +21,6 @@ #include "input.h" #include "memory.h" #include "modify.h" -#include "respa.h" #include "universe.h" #include "update.h" #include "variable.h" diff --git a/src/REPLICA/fix_pimd_langevin.cpp b/src/REPLICA/fix_pimd_langevin.cpp index 01cfa66ebd..c6886fbed7 100644 --- a/src/REPLICA/fix_pimd_langevin.cpp +++ b/src/REPLICA/fix_pimd_langevin.cpp @@ -41,7 +41,6 @@ #include "random_mars.h" #include "universe.h" #include "update.h" -#include "utils.h" #include #include diff --git a/src/REPLICA/temper.cpp b/src/REPLICA/temper.cpp index adbdb4d742..77bc45e6e3 100644 --- a/src/REPLICA/temper.cpp +++ b/src/REPLICA/temper.cpp @@ -33,7 +33,6 @@ #include "update.h" #include -#include using namespace LAMMPS_NS; diff --git a/src/REPLICA/temper_npt.cpp b/src/REPLICA/temper_npt.cpp index d814bf6725..aa72047fe7 100644 --- a/src/REPLICA/temper_npt.cpp +++ b/src/REPLICA/temper_npt.cpp @@ -35,7 +35,6 @@ #include "update.h" #include -#include using namespace LAMMPS_NS; diff --git a/src/SMTBQ/pair_smatb.cpp b/src/SMTBQ/pair_smatb.cpp index 85446b7a62..ab6aee557e 100644 --- a/src/SMTBQ/pair_smatb.cpp +++ b/src/SMTBQ/pair_smatb.cpp @@ -26,6 +26,7 @@ #include "neighbor.h" #include +#include using namespace LAMMPS_NS; diff --git a/src/SMTBQ/pair_smatb_single.cpp b/src/SMTBQ/pair_smatb_single.cpp index 756941b2b7..4506a1093c 100644 --- a/src/SMTBQ/pair_smatb_single.cpp +++ b/src/SMTBQ/pair_smatb_single.cpp @@ -26,6 +26,7 @@ #include "neighbor.h" #include +#include using namespace LAMMPS_NS; diff --git a/src/SMTBQ/pair_smtbq.cpp b/src/SMTBQ/pair_smtbq.cpp index 4e4a6109fa..3696a3ab6c 100644 --- a/src/SMTBQ/pair_smtbq.cpp +++ b/src/SMTBQ/pair_smtbq.cpp @@ -60,6 +60,7 @@ #include #include +#include #include #include diff --git a/src/SPIN/neb_spin.cpp b/src/SPIN/neb_spin.cpp index ac54f069a9..fb8b7d8353 100644 --- a/src/SPIN/neb_spin.cpp +++ b/src/SPIN/neb_spin.cpp @@ -44,6 +44,7 @@ #include #include +#include using namespace LAMMPS_NS; diff --git a/src/npair_halffull.cpp b/src/npair_halffull.cpp index b3d8d4f50e..aa560b5731 100644 --- a/src/npair_halffull.cpp +++ b/src/npair_halffull.cpp @@ -19,6 +19,8 @@ #include "my_page.h" #include "neigh_list.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/npair_multi.cpp b/src/npair_multi.cpp index b5f813c0a8..44c68a9195 100644 --- a/src/npair_multi.cpp +++ b/src/npair_multi.cpp @@ -24,6 +24,8 @@ #include "neighbor.h" #include "neigh_list.h" +#include + using namespace LAMMPS_NS; using namespace NeighConst; diff --git a/src/npair_multi_old.cpp b/src/npair_multi_old.cpp index a4ca1e7361..3d983bd7fd 100644 --- a/src/npair_multi_old.cpp +++ b/src/npair_multi_old.cpp @@ -23,6 +23,8 @@ #include "my_page.h" #include "neigh_list.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/npair_nsq.cpp b/src/npair_nsq.cpp index c2f43d9cb0..9f469de480 100644 --- a/src/npair_nsq.cpp +++ b/src/npair_nsq.cpp @@ -24,6 +24,8 @@ #include "neigh_list.h" #include "neighbor.h" +#include + using namespace LAMMPS_NS; using namespace NeighConst; diff --git a/src/npair_respa_bin.cpp b/src/npair_respa_bin.cpp index f2fb9f7486..5347f4d3a0 100644 --- a/src/npair_respa_bin.cpp +++ b/src/npair_respa_bin.cpp @@ -23,6 +23,8 @@ #include "my_page.h" #include "neigh_list.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/npair_respa_nsq.cpp b/src/npair_respa_nsq.cpp index 9ca166a491..065c9eb6d6 100644 --- a/src/npair_respa_nsq.cpp +++ b/src/npair_respa_nsq.cpp @@ -24,6 +24,8 @@ #include "my_page.h" #include "neigh_list.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ diff --git a/src/replicate.cpp b/src/replicate.cpp index b27304a2a0..710361e55c 100644 --- a/src/replicate.cpp +++ b/src/replicate.cpp @@ -21,6 +21,7 @@ #include "domain.h" #include "error.h" #include "memory.h" +#include "molecule.h" #include "special.h" #include "label_map.h" diff --git a/src/rerun.cpp b/src/rerun.cpp index 74a8956994..96491bab36 100644 --- a/src/rerun.cpp +++ b/src/rerun.cpp @@ -26,6 +26,7 @@ #include "update.h" #include "variable.h" +#include #include using namespace LAMMPS_NS; diff --git a/src/reset_atoms_image.cpp b/src/reset_atoms_image.cpp index 84df5bf746..63030c632b 100644 --- a/src/reset_atoms_image.cpp +++ b/src/reset_atoms_image.cpp @@ -22,7 +22,6 @@ #include "group.h" #include "input.h" #include "modify.h" -#include "update.h" #include "variable.h" #include diff --git a/src/utils.cpp b/src/utils.cpp index bde6dffca5..8aa33e14e6 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -33,6 +33,7 @@ #include #include #include +#include /*! \file utils.cpp */ From 81a684f57292143f294164a9cf273e3ab27eca58 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 28 Feb 2024 15:59:31 -0500 Subject: [PATCH 139/185] assign ownership for compute reaxff/atom and reaxff/atom/kk --- .github/CODEOWNERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 284d56f1ca..47233250a3 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -69,6 +69,8 @@ src/EXTRA-FIX/fix_deform_pressure.* @jtclemm src/MISC/*_tracker.* @jtclemm src/MC/fix_gcmc.* @athomps src/MC/fix_sgcmc.* @athomps +src/REAXFF/compute_reaxff_atom.* @rbberger +src/KOKKOS/compute_reaxff_atom_kokkos.* @rbberger src/REPLICA/fix_pimd_langevin.* @Yi-FanLi # core LAMMPS classes From 37c0795691f29503f5e4661c8842a5ddd3fc9cbe Mon Sep 17 00:00:00 2001 From: "Aidan P. Thompson" Date: Wed, 28 Feb 2024 14:51:17 -0700 Subject: [PATCH 140/185] Fixed additional errors with multicomponent systems, making msmeamflag independent of ialloy --- src/MEAM/meam_force.cpp | 144 ++++++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 66 deletions(-) diff --git a/src/MEAM/meam_force.cpp b/src/MEAM/meam_force.cpp index 4ee3cd4f83..1a2d947e6c 100644 --- a/src/MEAM/meam_force.cpp +++ b/src/MEAM/meam_force.cpp @@ -526,81 +526,93 @@ void MEAM::meam_force(int i, int eflag_global, int eflag_atom, int vflag_global, drho3ds1 = a3 * rhoa3j * arg1i3 - a3a * rhoa3j * arg3i3; drho3ds2 = a3 * rhoa3i * arg1j3 - a3a * rhoa3i * arg3j3; - if (msmeamflag) { - drho1mds1 = a1 * rhoa1mj * arg1i1m; - drho1mds2 = a1 * rhoa1mi * arg1j1m; - drho2mds1 = a2 * rhoa2mj * arg1i2m - 2.0 / 3.0 * arho2mb[i] * rhoa2mj; - drho2mds2 = a2 * rhoa2mi * arg1j2m - 2.0 / 3.0 * arho2mb[j] * rhoa2mi; - drho3mds1 = a3 * rhoa3mj * arg1i3m - a3a * rhoa3mj * arg3i3m; - drho3mds2 = a3 * rhoa3mi * arg1j3m - a3a * rhoa3mi * arg3j3m; - drho1mds1 *= -1; - drho1mds2 *= -1; - drho3mds1 *= -1; - drho3mds2 *= -1; - } else { - drho1mds1 = 0.0; - drho1mds2 = 0.0; - drho2mds1 = 0.0; - drho2mds2 = 0.0; - drho3mds1 = 0.0; - drho3mds2 = 0.0; - } + if (msmeamflag) { - if (ialloy == 1) { + drho1mds1 = a1 * rhoa1mj * arg1i1m; + drho1mds2 = a1 * rhoa1mi * arg1j1m; + drho2mds1 = a2 * rhoa2mj * arg1i2m - 2.0 / 3.0 * arho2mb[i] * rhoa2mj; + drho2mds2 = a2 * rhoa2mi * arg1j2m - 2.0 / 3.0 * arho2mb[j] * rhoa2mi; + drho3mds1 = a3 * rhoa3mj * arg1i3m - a3a * rhoa3mj * arg3i3m; + drho3mds2 = a3 * rhoa3mi * arg1j3m - a3a * rhoa3mi * arg3j3m; + drho1mds1 *= -1; + drho1mds2 *= -1; + drho3mds1 *= -1; + drho3mds2 *= -1; - a1i = fdiv_zero(rhoa0j, tsq_ave[i][0]); - a1j = fdiv_zero(rhoa0i, tsq_ave[j][0]); - a2i = fdiv_zero(rhoa0j, tsq_ave[i][1]); - a2j = fdiv_zero(rhoa0i, tsq_ave[j][1]); - a3i = fdiv_zero(rhoa0j, tsq_ave[i][2]); - a3j = fdiv_zero(rhoa0i, tsq_ave[j][2]); + t1i = 1.0; + t2i = 1.0; + t3i = 1.0; + t1j = 1.0; + t2j = 1.0; + t3j = 1.0; + dt1dr1 = 0.0; + dt1dr2 = 0.0; + dt2dr1 = 0.0; + dt2dr2 = 0.0; + dt3dr1 = 0.0; + dt3dr2 = 0.0; - dt1ds1 = a1i * (t1mj - t1i * MathSpecial::square(t1mj)); - dt1ds2 = a1j * (t1mi - t1j * MathSpecial::square(t1mi)); - dt2ds1 = a2i * (t2mj - t2i * MathSpecial::square(t2mj)); - dt2ds2 = a2j * (t2mi - t2j * MathSpecial::square(t2mi)); - dt3ds1 = a3i * (t3mj - t3i * MathSpecial::square(t3mj)); - dt3ds2 = a3j * (t3mi - t3j * MathSpecial::square(t3mi)); + // these formulae are simplifed by substituting t=1, dt=0 from above - } else if (ialloy == 2) { + drhods1 = dgamma1[i] * drho0ds1 + + dgamma2[i] * ((drho1ds1 - drho1mds1) + + (drho2ds1 - drho2mds1) + + (drho3ds1 - drho3mds1)); + drhods2 = dgamma1[j] * drho0ds2 + + dgamma2[j] * ((drho1ds2 - drho1mds2) + + (drho2ds2 - drho2mds2) + + (drho3ds2 - drho3mds2)); + } else { - dt1ds1 = 0.0; - dt1ds2 = 0.0; - dt2ds1 = 0.0; - dt2ds2 = 0.0; - dt3ds1 = 0.0; - dt3ds2 = 0.0; + drho1mds1 = 0.0; + drho1mds2 = 0.0; + drho2mds1 = 0.0; + drho2mds2 = 0.0; + drho3mds1 = 0.0; + drho3mds2 = 0.0; - } else { + if (ialloy == 1) { - ai = 0.0; - if (!iszero(rho0[i])) - ai = rhoa0j / rho0[i]; - aj = 0.0; - if (!iszero(rho0[j])) - aj = rhoa0i / rho0[j]; + a1i = fdiv_zero(rhoa0j, tsq_ave[i][0]); + a1j = fdiv_zero(rhoa0i, tsq_ave[j][0]); + a2i = fdiv_zero(rhoa0j, tsq_ave[i][1]); + a2j = fdiv_zero(rhoa0i, tsq_ave[j][1]); + a3i = fdiv_zero(rhoa0j, tsq_ave[i][2]); + a3j = fdiv_zero(rhoa0i, tsq_ave[j][2]); - dt1ds1 = ai * (t1mj - t1i); - dt1ds2 = aj * (t1mi - t1j); - dt2ds1 = ai * (t2mj - t2i); - dt2ds2 = aj * (t2mi - t2j); - dt3ds1 = ai * (t3mj - t3i); - dt3ds2 = aj * (t3mi - t3j); - } + dt1ds1 = a1i * (t1mj - t1i * MathSpecial::square(t1mj)); + dt1ds2 = a1j * (t1mi - t1j * MathSpecial::square(t1mi)); + dt2ds1 = a2i * (t2mj - t2i * MathSpecial::square(t2mj)); + dt2ds2 = a2j * (t2mi - t2j * MathSpecial::square(t2mi)); + dt3ds1 = a3i * (t3mj - t3i * MathSpecial::square(t3mj)); + dt3ds2 = a3j * (t3mi - t3j * MathSpecial::square(t3mi)); + + } else if (ialloy == 2) { + + dt1ds1 = 0.0; + dt1ds2 = 0.0; + dt2ds1 = 0.0; + dt2ds2 = 0.0; + dt3ds1 = 0.0; + dt3ds2 = 0.0; + + } else { + + ai = 0.0; + if (!iszero(rho0[i])) + ai = rhoa0j / rho0[i]; + aj = 0.0; + if (!iszero(rho0[j])) + aj = rhoa0i / rho0[j]; + + dt1ds1 = ai * (t1mj - t1i); + dt1ds2 = aj * (t1mi - t1j); + dt2ds1 = ai * (t2mj - t2i); + dt2ds2 = aj * (t2mi - t2j); + dt3ds1 = ai * (t3mj - t3i); + dt3ds2 = aj * (t3mi - t3j); + } - if (msmeamflag) { - drhods1 = dgamma1[i] * drho0ds1 + - dgamma2[i] * (dt1ds1 * rho1[i] + t1i * (drho1ds1 - drho1mds1) + - dt2ds1 * rho2[i] + t2i * (drho2ds1 - drho2mds1) + - dt3ds1 * rho3[i] + t3i * (drho3ds1 - drho3mds1)) - - dgamma3[i] * (shpi[0] * dt1ds1 + shpi[1] * dt2ds1 + shpi[2] * dt3ds1); - drhods2 = dgamma1[j] * drho0ds2 + - dgamma2[j] * (dt1ds2 * rho1[j] + t1j * (drho1ds2 - drho1mds2) + - dt2ds2 * rho2[j] + t2j * (drho2ds2 - drho2mds2) + - dt3ds2 * rho3[j] + t3j * (drho3ds2 - drho3mds2)) - - dgamma3[j] * (shpj[0] * dt1ds2 + shpj[1] * dt2ds2 + shpj[2] * dt3ds2); - } - else { drhods1 = dgamma1[i] * drho0ds1 + dgamma2[i] * (dt1ds1 * rho1[i] + t1i * drho1ds1 + dt2ds1 * rho2[i] + t2i * drho2ds1 + dt3ds1 * rho3[i] + t3i * drho3ds1) - From 0d37dddc9e626dbd13de0a8e8eefe0ea4df5ad30 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 28 Feb 2024 17:19:31 -0500 Subject: [PATCH 141/185] restore correct formatting to meam_force.cpp and port changes to KOKKOS --- src/KOKKOS/meam_force_kokkos.h | 101 +++++++------ src/MEAM/meam_force.cpp | 140 +++++++++--------- .../tests/atomic-pair-meam_ms.yaml | 138 ++++++++--------- 3 files changed, 191 insertions(+), 188 deletions(-) diff --git a/src/KOKKOS/meam_force_kokkos.h b/src/KOKKOS/meam_force_kokkos.h index 2f0c51dddb..6be5ff0016 100644 --- a/src/KOKKOS/meam_force_kokkos.h +++ b/src/KOKKOS/meam_force_kokkos.h @@ -605,6 +605,27 @@ KOKKOS_INLINE_FUNCTION void MEAMKokkos::operator()(TagMEAMForce::operator()(TagMEAMForce Date: Wed, 28 Feb 2024 17:40:17 -0500 Subject: [PATCH 142/185] third and final round of include-what-you-use updates --- src/BOCS/fix_bocs.cpp | 1 - src/DIELECTRIC/fix_polarize_bem_gmres.cpp | 1 - src/GRANULAR/pair_granular.cpp | 1 - src/KOKKOS/neighbor_kokkos.cpp | 1 + src/MDI/mdi_command.h | 2 +- src/MESONT/pair_mesocnt_viscous.cpp | 1 - src/compute_heat_flux.cpp | 7 +++---- src/fix_pair.cpp | 1 - src/imbalance_neigh.cpp | 2 -- src/replicate.cpp | 1 - 10 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/BOCS/fix_bocs.cpp b/src/BOCS/fix_bocs.cpp index d6beb889ff..25471d04a4 100644 --- a/src/BOCS/fix_bocs.cpp +++ b/src/BOCS/fix_bocs.cpp @@ -25,7 +25,6 @@ #include "error.h" #include "fix_deform.h" #include "force.h" -#include "group.h" #include "irregular.h" #include "kspace.h" #include "memory.h" diff --git a/src/DIELECTRIC/fix_polarize_bem_gmres.cpp b/src/DIELECTRIC/fix_polarize_bem_gmres.cpp index 40f7d0c853..67d79d57f0 100644 --- a/src/DIELECTRIC/fix_polarize_bem_gmres.cpp +++ b/src/DIELECTRIC/fix_polarize_bem_gmres.cpp @@ -41,7 +41,6 @@ #include "comm.h" #include "error.h" #include "force.h" -#include "group.h" #include "kspace.h" #include "math_const.h" #include "memory.h" diff --git a/src/GRANULAR/pair_granular.cpp b/src/GRANULAR/pair_granular.cpp index 119feb1c38..d5179a19b7 100644 --- a/src/GRANULAR/pair_granular.cpp +++ b/src/GRANULAR/pair_granular.cpp @@ -37,7 +37,6 @@ #include "update.h" #include -#include using namespace LAMMPS_NS; using namespace Granular_NS; diff --git a/src/KOKKOS/neighbor_kokkos.cpp b/src/KOKKOS/neighbor_kokkos.cpp index 67af5b2b28..214b2e86d9 100644 --- a/src/KOKKOS/neighbor_kokkos.cpp +++ b/src/KOKKOS/neighbor_kokkos.cpp @@ -18,6 +18,7 @@ #include "atom_kokkos.h" #include "atom_masks.h" #include "bond.h" +#include "domain.h" #include "dihedral.h" #include "error.h" #include "force.h" diff --git a/src/MDI/mdi_command.h b/src/MDI/mdi_command.h index 88e1901ab1..0bdfe81279 100644 --- a/src/MDI/mdi_command.h +++ b/src/MDI/mdi_command.h @@ -21,7 +21,7 @@ CommandStyle(mdi,MDICommand); #define LMP_MDI_COMMAND_H #include "command.h" -#include "mdi.h" +#include namespace LAMMPS_NS { diff --git a/src/MESONT/pair_mesocnt_viscous.cpp b/src/MESONT/pair_mesocnt_viscous.cpp index 9beabe0d2f..f7ad7b0aa6 100644 --- a/src/MESONT/pair_mesocnt_viscous.cpp +++ b/src/MESONT/pair_mesocnt_viscous.cpp @@ -25,7 +25,6 @@ #include "math_const.h" #include "math_extra.h" #include "memory.h" -#include "neigh_list.h" #include "neighbor.h" #include "update.h" diff --git a/src/compute_heat_flux.cpp b/src/compute_heat_flux.cpp index 62b2c8b63b..64cc8e69f3 100644 --- a/src/compute_heat_flux.cpp +++ b/src/compute_heat_flux.cpp @@ -19,12 +19,11 @@ #include "compute_heat_flux.h" -#include #include "atom.h" -#include "update.h" -#include "modify.h" -#include "force.h" #include "error.h" +#include "force.h" +#include "modify.h" +#include "update.h" using namespace LAMMPS_NS; diff --git a/src/fix_pair.cpp b/src/fix_pair.cpp index 93a88a60c9..da56b01f9e 100644 --- a/src/fix_pair.cpp +++ b/src/fix_pair.cpp @@ -21,7 +21,6 @@ #include "memory.h" #include "pair.h" #include "update.h" -#include "fmt/format.h" #include diff --git a/src/imbalance_neigh.cpp b/src/imbalance_neigh.cpp index 8d4a17976b..f6b2be2cad 100644 --- a/src/imbalance_neigh.cpp +++ b/src/imbalance_neigh.cpp @@ -14,10 +14,8 @@ #include "imbalance_neigh.h" #include "accelerator_kokkos.h" -#include "atom.h" #include "comm.h" #include "error.h" -#include "neighbor.h" using namespace LAMMPS_NS; diff --git a/src/replicate.cpp b/src/replicate.cpp index 710361e55c..b27304a2a0 100644 --- a/src/replicate.cpp +++ b/src/replicate.cpp @@ -21,7 +21,6 @@ #include "domain.h" #include "error.h" #include "memory.h" -#include "molecule.h" #include "special.h" #include "label_map.h" From a261a6c34cb7f79cf0eba476cb46c45f00bdb3a2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 28 Feb 2024 17:45:41 -0500 Subject: [PATCH 143/185] whitespace fixes --- src/KOKKOS/meam_force_kokkos.h | 2 +- src/MEAM/meam_force.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/KOKKOS/meam_force_kokkos.h b/src/KOKKOS/meam_force_kokkos.h index 6be5ff0016..a546ab54d4 100644 --- a/src/KOKKOS/meam_force_kokkos.h +++ b/src/KOKKOS/meam_force_kokkos.h @@ -673,7 +673,7 @@ KOKKOS_INLINE_FUNCTION void MEAMKokkos::operator()(TagMEAMForce Date: Wed, 28 Feb 2024 16:02:52 -0700 Subject: [PATCH 144/185] Fix compiler warning --- src/KOKKOS/comm_tiled_kokkos.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KOKKOS/comm_tiled_kokkos.h b/src/KOKKOS/comm_tiled_kokkos.h index eba453b49e..9033714796 100644 --- a/src/KOKKOS/comm_tiled_kokkos.h +++ b/src/KOKKOS/comm_tiled_kokkos.h @@ -75,7 +75,7 @@ class CommTiledKokkos : public CommTiled { void grow_send_kokkos(int, int, ExecutionSpace space = Host); void grow_recv_kokkos(int, int, ExecutionSpace space = Host); void grow_list(int, int, int) override; - void grow_swap_send(int, int, int); // grow swap arrays for send and recv + void grow_swap_send(int, int, int) override; // grow swap arrays for send and recv }; } // namespace LAMMPS_NS From 4f0d30b8d64f16c9d146ea4bd9b9d5546a902491 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Thu, 29 Feb 2024 11:01:18 -0700 Subject: [PATCH 145/185] Fix data transfer issue --- src/KOKKOS/comm_tiled_kokkos.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/KOKKOS/comm_tiled_kokkos.cpp b/src/KOKKOS/comm_tiled_kokkos.cpp index bd65bcf221..30dfd11fc6 100644 --- a/src/KOKKOS/comm_tiled_kokkos.cpp +++ b/src/KOKKOS/comm_tiled_kokkos.cpp @@ -293,7 +293,6 @@ template void CommTiledKokkos::reverse_comm_device() { int i,irecv,n,nsend,nrecv; - MPI_Request request; double *buf; // exchange data with another set of procs in each swap @@ -623,10 +622,8 @@ void CommTiledKokkos::grow_list(int iswap, int iwhich, int n) { int size = static_cast (BUFFACTOR * n); - if (exchange_comm_classic) { // force realloc on Host - k_sendlist.sync(); - k_sendlist.modify(); - } + k_sendlist.sync(); + k_sendlist.modify(); int nsend = k_sendlist.extent(1); From efcee365c1550083d788aad03a5203f99645a77e Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Thu, 29 Feb 2024 14:06:04 -0700 Subject: [PATCH 146/185] Fix issue --- src/KOKKOS/atom_vec_dipole_kokkos.cpp | 1 + src/KOKKOS/atom_vec_sphere_kokkos.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/KOKKOS/atom_vec_dipole_kokkos.cpp b/src/KOKKOS/atom_vec_dipole_kokkos.cpp index 28ecb24672..2d205f4cf0 100644 --- a/src/KOKKOS/atom_vec_dipole_kokkos.cpp +++ b/src/KOKKOS/atom_vec_dipole_kokkos.cpp @@ -218,6 +218,7 @@ struct AtomVecDipoleKokkos_PackBorder { const typename ArrayTypes::t_float_1d &q, const typename ArrayTypes::t_mu_array_randomread &mu, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_q(q),_mu(mu), _dx(dx),_dy(dy),_dz(dz) {} diff --git a/src/KOKKOS/atom_vec_sphere_kokkos.cpp b/src/KOKKOS/atom_vec_sphere_kokkos.cpp index de62988c67..6d12a4d97a 100644 --- a/src/KOKKOS/atom_vec_sphere_kokkos.cpp +++ b/src/KOKKOS/atom_vec_sphere_kokkos.cpp @@ -993,6 +993,7 @@ struct AtomVecSphereKokkos_PackBorder { const typename ArrayTypes::t_float_1d &radius, const typename ArrayTypes::t_float_1d &rmass, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask), _radius(radius), _rmass(rmass), From f5b1813f14c00e4af9ac5f8d0d0500b51cc55e76 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 29 Feb 2024 18:38:31 -0500 Subject: [PATCH 147/185] silence compiler warnings --- src/KOKKOS/comm_tiled_kokkos.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/KOKKOS/comm_tiled_kokkos.cpp b/src/KOKKOS/comm_tiled_kokkos.cpp index 30dfd11fc6..2e4ca30bed 100644 --- a/src/KOKKOS/comm_tiled_kokkos.cpp +++ b/src/KOKKOS/comm_tiled_kokkos.cpp @@ -625,9 +625,7 @@ void CommTiledKokkos::grow_list(int iswap, int iwhich, int n) k_sendlist.sync(); k_sendlist.modify(); - int nsend = k_sendlist.extent(1); - - if (size > k_sendlist.extent(2)) { + if (size > (int)k_sendlist.extent(2)) { memoryKK->grow_kokkos(k_sendlist,sendlist,maxswap,maxsend,size,"comm:sendlist"); for (int i = 0; i < maxswap; i++) @@ -640,7 +638,7 @@ void CommTiledKokkos::grow_list(int iswap, int iwhich, int n) ditto for complementary recv for swap I+1 or I-1, as invoked by caller ------------------------------------------------------------------------- */ -void CommTiledKokkos::grow_swap_send(int i, int n, int nold) +void CommTiledKokkos::grow_swap_send(int i, int n, int /*nold*/) { delete [] sendproc[i]; sendproc[i] = new int[n]; From b15956c13cf983e42d44a02759801c10c1dd3e8e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 29 Feb 2024 22:26:40 -0500 Subject: [PATCH 148/185] remove unused class members --- src/MANYBODY/pair_rebomos.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/MANYBODY/pair_rebomos.h b/src/MANYBODY/pair_rebomos.h index 4997c65b87..33c967a760 100644 --- a/src/MANYBODY/pair_rebomos.h +++ b/src/MANYBODY/pair_rebomos.h @@ -20,8 +20,8 @@ PairStyle(rebomos,PairREBOMoS); #ifndef LMP_PAIR_REBOMOS_H #define LMP_PAIR_REBOMOS_H -#include "pair.h" #include "math_const.h" +#include "pair.h" #include @@ -39,9 +39,6 @@ class PairREBOMoS : public Pair { double memory_usage() override; protected: - double cutljrebosq; // cut for when to compute - // REBO neighs of ghost atoms - double **lj1, **lj2, **lj3, **lj4; // pre-computed LJ coeffs for M,S types double cut3rebo; // maximum distance for 3rd REBO neigh @@ -52,7 +49,6 @@ class PairREBOMoS : public Pair { int *REBO_numneigh; // # of pair neighbors for each atom int **REBO_firstneigh; // ptr to 1st neighbor of each atom - double *closestdistsq; // closest owned atom dist to each ghost double *nM, *nS; // sum of weighting fns with REBO neighs double rcmin[2][2], rcmax[2][2], rcmaxsq[2][2], rcmaxp[2][2]; From 259bcfba1f73a91a3ce656d740730cd32e32df2a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 29 Feb 2024 22:45:32 -0500 Subject: [PATCH 149/185] remove one more unused class member --- src/MANYBODY/pair_rebomos.cpp | 7 ------- src/MANYBODY/pair_rebomos.h | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp index d6cea004a7..a84469f212 100644 --- a/src/MANYBODY/pair_rebomos.cpp +++ b/src/MANYBODY/pair_rebomos.cpp @@ -1064,12 +1064,6 @@ void PairREBOMoS::read_file(char *filename) rcLJmax[0][1] = 2.5*sigma[0][1]; rcLJmax[1][0] = rcLJmax[0][1]; rcLJmax[1][1] = 2.5*sigma[1][1]; - - rcLJmaxsq[0][0] = rcLJmax[0][0]*rcLJmax[0][0]; - rcLJmaxsq[1][0] = rcLJmax[1][0]*rcLJmax[1][0]; - rcLJmaxsq[0][1] = rcLJmax[0][1]*rcLJmax[0][1]; - rcLJmaxsq[1][1] = rcLJmax[1][1]*rcLJmax[1][1]; - } // broadcast read-in and setup values @@ -1108,7 +1102,6 @@ void PairREBOMoS::read_file(char *filename) MPI_Bcast(&rcLJmin[0][0],4,MPI_DOUBLE,0,world); MPI_Bcast(&rcLJmax[0][0],4,MPI_DOUBLE,0,world); - MPI_Bcast(&rcLJmaxsq[0][0],4,MPI_DOUBLE,0,world); MPI_Bcast(&epsilon[0][0],4,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[0][0],4,MPI_DOUBLE,0,world); } diff --git a/src/MANYBODY/pair_rebomos.h b/src/MANYBODY/pair_rebomos.h index 33c967a760..856a52ca81 100644 --- a/src/MANYBODY/pair_rebomos.h +++ b/src/MANYBODY/pair_rebomos.h @@ -56,7 +56,7 @@ class PairREBOMoS : public Pair { double b0[2], b1[2], b2[2], b3[2], b4[2], b5[2], b6[2]; double bg0[2], bg1[2], bg2[2], bg3[2], bg4[2], bg5[2], bg6[2]; double a0[2], a1[2], a2[2], a3[2]; - double rcLJmin[2][2], rcLJmax[2][2], rcLJmaxsq[2][2]; + double rcLJmin[2][2], rcLJmax[2][2]; double epsilon[2][2], sigma[2][2]; void REBO_neigh(); From 7064e1e2b6f143fc2473f5dda9b898463e4b2472 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 1 Mar 2024 07:33:48 -0500 Subject: [PATCH 150/185] make searches for drude fix more specific to avoid false positives --- src/DRUDE/compute_temp_drude.cpp | 2 +- src/DRUDE/fix_drude.cpp | 2 +- src/DRUDE/fix_drude_transform.cpp | 2 +- src/DRUDE/fix_tgnh_drude.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DRUDE/compute_temp_drude.cpp b/src/DRUDE/compute_temp_drude.cpp index 535808580e..0bf276924a 100644 --- a/src/DRUDE/compute_temp_drude.cpp +++ b/src/DRUDE/compute_temp_drude.cpp @@ -64,7 +64,7 @@ ComputeTempDrude::~ComputeTempDrude() void ComputeTempDrude::init() { // Fix drude already checks that there is only one fix drude instance - auto &fixes = modify->get_fix_by_style("drude"); + auto &fixes = modify->get_fix_by_style("^drude$"); if (fixes.size() == 0) error->all(FLERR, "compute temp/drude requires fix drude"); fix_drude = dynamic_cast(fixes[0]); diff --git a/src/DRUDE/fix_drude.cpp b/src/DRUDE/fix_drude.cpp index 6aaa4f1a74..6c0c84861a 100644 --- a/src/DRUDE/fix_drude.cpp +++ b/src/DRUDE/fix_drude.cpp @@ -82,7 +82,7 @@ FixDrude::~FixDrude() void FixDrude::init() { - if (modify->get_fix_by_style("drude").size() > 1) error->all(FLERR,"More than one fix drude"); + if (modify->get_fix_by_style("^drude$").size() > 1) error->all(FLERR,"More than one fix drude"); if (!rebuildflag) rebuild_special(); } diff --git a/src/DRUDE/fix_drude_transform.cpp b/src/DRUDE/fix_drude_transform.cpp index 88877ef70d..ad92740116 100644 --- a/src/DRUDE/fix_drude_transform.cpp +++ b/src/DRUDE/fix_drude_transform.cpp @@ -53,7 +53,7 @@ void FixDrudeTransform::init() std::string substyle = "direct"; if (inverse) substyle = "inverse"; - auto fixes = modify->get_fix_by_style("^drude"); + auto fixes = modify->get_fix_by_style("^drude$"); if (fixes.size() > 0) fix_drude = dynamic_cast(fixes[0]); if (!fix_drude) error->all(FLERR, "fix drude/transform/{} requires fix drude", substyle); diff --git a/src/DRUDE/fix_tgnh_drude.cpp b/src/DRUDE/fix_tgnh_drude.cpp index c067bf7adf..e15e865ce8 100644 --- a/src/DRUDE/fix_tgnh_drude.cpp +++ b/src/DRUDE/fix_tgnh_drude.cpp @@ -516,7 +516,7 @@ FixTGNHDrude::FixTGNHDrude(LAMMPS *lmp, int narg, char **arg) : // find fix drude - auto fdrude = modify->get_fix_by_style("^drude"); + auto fdrude = modify->get_fix_by_style("^drude$"); if (fdrude.size() < 1) error->all(FLERR, "Fix {} requires fix drude", style); fix_drude = dynamic_cast(fdrude[0]); if (!fix_drude) error->all(FLERR, "Fix {} requires fix drude", style); From 93942f201309c5c917795698c24c6c8ff38db32e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 1 Mar 2024 18:32:16 -0500 Subject: [PATCH 151/185] Added override for ialloy default with MS-MEAM # Conflicts: # doc/src/pair_meam.rst --- src/MEAM/meam_setup_global.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/MEAM/meam_setup_global.cpp b/src/MEAM/meam_setup_global.cpp index 4afffb4b02..1487a53b2e 100644 --- a/src/MEAM/meam_setup_global.cpp +++ b/src/MEAM/meam_setup_global.cpp @@ -123,4 +123,7 @@ void MEAM::meam_setup_global(int nelt, lattice_t *lat, int *ielement, double * / // for trimer, zigzag, line refernece structure, sungkwang setall2d(stheta_meam, 1.0); // stheta = sin(theta/2*pi/180) where theta is 180, so 1.0 setall2d(ctheta_meam, 0.0); // stheta = cos(theta/2*pi/180) where theta is 180, so 0 + + if (msmeamflag) ialloy = 1; + } From 2c9dfa3ea73c2020d8ceb3138f62e202372a2a4b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 1 Mar 2024 18:53:32 -0500 Subject: [PATCH 152/185] update MS-MEAM examples --- examples/meam/msmeam/HGa.meam | 30 ----- examples/meam/msmeam/HGa.msmeam | 1 + examples/meam/msmeam/data.msmeam.bu | 25 ---- examples/meam/msmeam/in.msmeam | 8 +- examples/meam/msmeam/library.msmeam | 14 -- .../meam/msmeam/log.1Mar2024.msmeam.g++.1 | 126 ++++++++++++++++++ .../meam/msmeam/log.1Mar2024.msmeam.g++.4 | 126 ++++++++++++++++++ examples/meam/msmeam/log.msmeam.bu | 107 --------------- examples/meam/msmeam/msmeam.dump.bu | 24 ---- examples/meam/msmeam/potential.mod | 2 +- potentials/HGa.msmeam | 34 ++--- 11 files changed, 274 insertions(+), 223 deletions(-) delete mode 100644 examples/meam/msmeam/HGa.meam create mode 120000 examples/meam/msmeam/HGa.msmeam delete mode 100644 examples/meam/msmeam/data.msmeam.bu delete mode 100644 examples/meam/msmeam/library.msmeam create mode 100644 examples/meam/msmeam/log.1Mar2024.msmeam.g++.1 create mode 100644 examples/meam/msmeam/log.1Mar2024.msmeam.g++.4 delete mode 100644 examples/meam/msmeam/log.msmeam.bu delete mode 100644 examples/meam/msmeam/msmeam.dump.bu diff --git a/examples/meam/msmeam/HGa.meam b/examples/meam/msmeam/HGa.meam deleted file mode 100644 index 9f01501c16..0000000000 --- a/examples/meam/msmeam/HGa.meam +++ /dev/null @@ -1,30 +0,0 @@ -bkgd_dyn = 1 -emb_lin_neg = 1 -augt1=0 -ialloy=1 -rc = 5.9 -#H -attrac(1,1)=0.460 -repuls(1,1)=0.460 -Cmin(1,1,1)=1.3 # PuMS -Cmax(1,1,1)= 2.80 -nn2(1,1)=1 -#Ga -rho0(2) = 0.6 -attrac(2,2)=0.097 -repuls(2,2)=0.097 -nn2(2,2)=1 -#HGa -attrac(1,2)=0.300 -repuls(1,2)=0.300 -lattce(1,2)=l12 -re(1,2)=3.19 -delta(1,2)=-0.48 -alpha(1,2)=6.6 -Cmin(1,1,2)=2.0 -Cmin(2,1,2)= 2.0 -Cmin(1,2,1)=2.0 -Cmin(2,2,1) = 1.4 -Cmin(1,2,2) = 1.4 -Cmin(1,1,2) = 1.4 -nn2(1,2)=1 diff --git a/examples/meam/msmeam/HGa.msmeam b/examples/meam/msmeam/HGa.msmeam new file mode 120000 index 0000000000..5629006d1d --- /dev/null +++ b/examples/meam/msmeam/HGa.msmeam @@ -0,0 +1 @@ +../../../potentials/HGa.msmeam \ No newline at end of file diff --git a/examples/meam/msmeam/data.msmeam.bu b/examples/meam/msmeam/data.msmeam.bu deleted file mode 100644 index 576a3c50de..0000000000 --- a/examples/meam/msmeam/data.msmeam.bu +++ /dev/null @@ -1,25 +0,0 @@ -LAMMPS data file via write_data, version 16 Feb 2016, timestep = 1 - -3 atoms -2 atom types - --4.0000000000000000e+00 4.0000000000000000e+00 xlo xhi --4.0000000000000000e+00 4.0000000000000000e+00 ylo yhi --4.0000000000000000e+00 4.0000000000000000e+00 zlo zhi - -Masses - -1 1.0079 -2 69.723 - -Atoms # atomic - -1 1 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0 0 0 -2 2 2.2000000000000002e+00 0.0000000000000000e+00 0.0000000000000000e+00 0 0 0 -3 2 2.9999999999999999e-01 2.2999999999999998e+00 0.0000000000000000e+00 0 0 0 - -Velocities - -1 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 -2 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 -3 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 diff --git a/examples/meam/msmeam/in.msmeam b/examples/meam/msmeam/in.msmeam index 82ffb89a13..e8d13f8682 100644 --- a/examples/meam/msmeam/in.msmeam +++ b/examples/meam/msmeam/in.msmeam @@ -1,5 +1,3 @@ -echo both -log log.msmeam # Test of MEAM potential for HGa # ------------------------ INITIALIZATION ---------------------------- @@ -21,11 +19,11 @@ create_atoms 1 single 0 0 0 units box create_atoms 2 single 2.2 0 0 units box create_atoms 2 single 0.3 2.3 0 units box # ---------- Define Settings --------------------- -variable teng equal "c_eatoms" +variable teng equal "c_eatoms" compute pot_energy all pe/atom compute stress all stress/atom NULL dump 1 all custom 1 dump.msmeam id x y z fx fy fz c_pot_energy c_stress[1] c_stress[2] c_stress[3] c_stress[4] c_stress[5] c_stress[6] -run 1 -write_data data.msmeam +run 1 +#write_data data.msmeam print "All done!" diff --git a/examples/meam/msmeam/library.msmeam b/examples/meam/msmeam/library.msmeam deleted file mode 100644 index 9937eaee08..0000000000 --- a/examples/meam/msmeam/library.msmeam +++ /dev/null @@ -1,14 +0,0 @@ -# DATE: 2018-09-22 UNITS: metal CONTRIBUTOR: Steve Valone, smv@lanl.gov CITATION: Baskes, PRB 1992; smv, sr, mib, JNM 2010 -# ms-meam data format May 2010 -# elt lat z ielement atwt -# alpha b0 b1 b2 b3 b1m b2m b3m alat esub asub -# - t0 t1 t2 t3 t1m t2m t3m rozero ibar -# NOTE: leading character cannot be a space - -'H' 'dim' 1.0 1 1.0079 -2.960 2.960 3.0 1.0 1.0 1.0 3.0 1.0 0.741 2.235 2.50 -1.0 0.44721 0.0 0.00 0.0 0.31623 0 6.70 0 - -'Ga4' 'fcc' 12.0 31 69.723 -4.42 4.80 3.10 6.00 0.00 0.0 0.0 0.5 4.247 2.897 0.97 -1.0 1.649 1.435 0.00 0.0 0.0 2.0 0.70 0 diff --git a/examples/meam/msmeam/log.1Mar2024.msmeam.g++.1 b/examples/meam/msmeam/log.1Mar2024.msmeam.g++.1 new file mode 100644 index 0000000000..70fbbdd89c --- /dev/null +++ b/examples/meam/msmeam/log.1Mar2024.msmeam.g++.1 @@ -0,0 +1,126 @@ +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-182-g93942f2013-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +# Test of MEAM potential for HGa + +# ------------------------ INITIALIZATION ---------------------------- +units metal +dimension 3 +boundary p p p +atom_style atomic +variable latparam equal 4.646 +variable ncell equal 3 + +# ----------------------- ATOM DEFINITION ---------------------------- +region box block -4 4 -4 4 -4 4 +create_box 2 box +Created orthogonal box = (-4 -4 -4) to (4 4 4) + 1 by 1 by 1 MPI processor grid + +# + +include potential.mod +# NOTE: This script can be modified for different pair styles +# See in.elastic for more info. + +variable Pu string H +print "potential chosen ${Pu}" +potential chosen H +# Choose potential +pair_style meam/ms +print "we just executed" +we just executed + +pair_coeff * * library.msmeam ${Pu} Ga4 HGa.msmeam ${Pu} Ga4 +pair_coeff * * library.msmeam H Ga4 HGa.msmeam ${Pu} Ga4 +pair_coeff * * library.msmeam H Ga4 HGa.msmeam H Ga4 +Reading MEAM library file library.msmeam with DATE: 2018-09-22 +# Setup neighbor style +neighbor 1.0 bin +neigh_modify once no every 1 delay 0 check yes + +# Setup minimization style +variable dmax equal 1.0e-2 +min_style cg +min_modify dmax ${dmax} line quadratic +min_modify dmax 0.01 line quadratic +compute eng all pe/atom +compute eatoms all reduce sum c_eng + +# Setup output +thermo 100 +thermo_style custom step temp etotal press pxx pyy pzz pxy pxz pyz lx ly lz vol c_eatoms +thermo_modify norm yes +create_atoms 1 single 0 0 0 units box +Created 1 atoms + using box units in orthogonal box = (-4 -4 -4) to (4 4 4) + create_atoms CPU = 0.000 seconds +create_atoms 2 single 2.2 0 0 units box +Created 1 atoms + using box units in orthogonal box = (-4 -4 -4) to (4 4 4) + create_atoms CPU = 0.000 seconds +create_atoms 2 single 0.3 2.3 0 units box +Created 1 atoms + using box units in orthogonal box = (-4 -4 -4) to (4 4 4) + create_atoms CPU = 0.000 seconds +# ---------- Define Settings --------------------- +variable teng equal "c_eatoms" +compute pot_energy all pe/atom +compute stress all stress/atom NULL +# dump 1 all custom 1 dump.msmeam id x y z fx fy fz c_pot_energy c_stress[1] c_stress[2] c_stress[3] c_stress[4] c_stress[5] c_stress[6] +run 1 +WARNING: No fixes with time integration, atoms won't move (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.9 + ghost atom cutoff = 6.9 + binsize = 3.45, bins = 3 3 3 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair meam/ms, perpetual + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (2) pair meam/ms, 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) = 8.587 | 8.587 | 8.587 Mbytes + Step Temp TotEng Press Pxx Pyy Pzz Pxy Pxz Pyz Lx Ly Lz Volume c_eatoms + 0 0 15.433079 491354.7 838670.96 635393.15 0 80195.797 0 0 8 8 8 512 15.433079 + 1 0 15.433079 491354.7 838670.96 635393.15 0 80195.797 0 0 8 8 8 512 15.433079 +Loop time of 4.4446e-05 on 1 procs for 1 steps with 3 atoms + +Performance: 1943.932 ns/day, 0.012 hours/ns, 22499.213 timesteps/s, 67.498 katom-step/s +31.5% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 2.9908e-05 | 2.9908e-05 | 2.9908e-05 | 0.0 | 67.29 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 1.033e-06 | 1.033e-06 | 1.033e-06 | 0.0 | 2.32 +Output | 9.347e-06 | 9.347e-06 | 9.347e-06 | 0.0 | 21.03 +Modify | 2.02e-07 | 2.02e-07 | 2.02e-07 | 0.0 | 0.45 +Other | | 3.956e-06 | | | 8.90 + +Nlocal: 3 ave 3 max 3 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 78 ave 78 max 78 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 7 ave 7 max 7 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 14 ave 14 max 14 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 14 +Ave neighs/atom = 4.6666667 +Neighbor list builds = 0 +Dangerous builds = 0 +#write_data data.msmeam + +print "All done!" +All done! +Total wall time: 0:00:00 diff --git a/examples/meam/msmeam/log.1Mar2024.msmeam.g++.4 b/examples/meam/msmeam/log.1Mar2024.msmeam.g++.4 new file mode 100644 index 0000000000..6951a64945 --- /dev/null +++ b/examples/meam/msmeam/log.1Mar2024.msmeam.g++.4 @@ -0,0 +1,126 @@ +LAMMPS (7 Feb 2024 - Development - patch_7Feb2024_update1-182-g93942f2013-modified) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98) + using 1 OpenMP thread(s) per MPI task +# Test of MEAM potential for HGa + +# ------------------------ INITIALIZATION ---------------------------- +units metal +dimension 3 +boundary p p p +atom_style atomic +variable latparam equal 4.646 +variable ncell equal 3 + +# ----------------------- ATOM DEFINITION ---------------------------- +region box block -4 4 -4 4 -4 4 +create_box 2 box +Created orthogonal box = (-4 -4 -4) to (4 4 4) + 1 by 2 by 2 MPI processor grid + +# + +include potential.mod +# NOTE: This script can be modified for different pair styles +# See in.elastic for more info. + +variable Pu string H +print "potential chosen ${Pu}" +potential chosen H +# Choose potential +pair_style meam/ms +print "we just executed" +we just executed + +pair_coeff * * library.msmeam ${Pu} Ga4 HGa.msmeam ${Pu} Ga4 +pair_coeff * * library.msmeam H Ga4 HGa.msmeam ${Pu} Ga4 +pair_coeff * * library.msmeam H Ga4 HGa.msmeam H Ga4 +Reading MEAM library file library.msmeam with DATE: 2018-09-22 +# Setup neighbor style +neighbor 1.0 bin +neigh_modify once no every 1 delay 0 check yes + +# Setup minimization style +variable dmax equal 1.0e-2 +min_style cg +min_modify dmax ${dmax} line quadratic +min_modify dmax 0.01 line quadratic +compute eng all pe/atom +compute eatoms all reduce sum c_eng + +# Setup output +thermo 100 +thermo_style custom step temp etotal press pxx pyy pzz pxy pxz pyz lx ly lz vol c_eatoms +thermo_modify norm yes +create_atoms 1 single 0 0 0 units box +Created 1 atoms + using box units in orthogonal box = (-4 -4 -4) to (4 4 4) + create_atoms CPU = 0.000 seconds +create_atoms 2 single 2.2 0 0 units box +Created 1 atoms + using box units in orthogonal box = (-4 -4 -4) to (4 4 4) + create_atoms CPU = 0.000 seconds +create_atoms 2 single 0.3 2.3 0 units box +Created 1 atoms + using box units in orthogonal box = (-4 -4 -4) to (4 4 4) + create_atoms CPU = 0.000 seconds +# ---------- Define Settings --------------------- +variable teng equal "c_eatoms" +compute pot_energy all pe/atom +compute stress all stress/atom NULL +# dump 1 all custom 1 dump.msmeam id x y z fx fy fz c_pot_energy c_stress[1] c_stress[2] c_stress[3] c_stress[4] c_stress[5] c_stress[6] +run 1 +WARNING: No fixes with time integration, atoms won't move (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.9 + ghost atom cutoff = 6.9 + binsize = 3.45, bins = 3 3 3 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair meam/ms, perpetual + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (2) pair meam/ms, 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) = 7.965 | 8.123 | 8.594 Mbytes + Step Temp TotEng Press Pxx Pyy Pzz Pxy Pxz Pyz Lx Ly Lz Volume c_eatoms + 0 0 15.433079 491354.7 838670.96 635393.15 0 80195.797 0 0 8 8 8 512 15.433079 + 1 0 15.433079 491354.7 838670.96 635393.15 0 80195.797 0 0 8 8 8 512 15.433079 +Loop time of 8.70645e-05 on 4 procs for 1 steps with 3 atoms + +Performance: 992.368 ns/day, 0.024 hours/ns, 11485.738 timesteps/s, 34.457 katom-step/s +29.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 | 4.3957e-05 | 4.67e-05 | 5.1056e-05 | 0.0 | 53.64 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 1.105e-05 | 1.3822e-05 | 1.7033e-05 | 0.0 | 15.88 +Output | 1.5765e-05 | 1.9045e-05 | 2.5216e-05 | 0.0 | 21.87 +Modify | 2.58e-07 | 3.465e-07 | 3.81e-07 | 0.0 | 0.40 +Other | | 7.151e-06 | | | 8.21 + +Nlocal: 0.75 ave 3 max 0 min +Histogram: 3 0 0 0 0 0 0 0 0 1 +Nghost: 38.25 ave 42 max 36 min +Histogram: 2 0 0 0 0 1 0 0 0 1 +Neighs: 1.75 ave 7 max 0 min +Histogram: 3 0 0 0 0 0 0 0 0 1 +FullNghs: 3.5 ave 14 max 0 min +Histogram: 3 0 0 0 0 0 0 0 0 1 + +Total # of neighbors = 14 +Ave neighs/atom = 4.6666667 +Neighbor list builds = 0 +Dangerous builds = 0 +#write_data data.msmeam + +print "All done!" +All done! +Total wall time: 0:00:00 diff --git a/examples/meam/msmeam/log.msmeam.bu b/examples/meam/msmeam/log.msmeam.bu deleted file mode 100644 index 8eac453c1e..0000000000 --- a/examples/meam/msmeam/log.msmeam.bu +++ /dev/null @@ -1,107 +0,0 @@ -# Test of MEAM potential for HGa - -# ------------------------ INITIALIZATION ---------------------------- -units metal -dimension 3 -boundary p p p -atom_style atomic -variable latparam equal 4.646 -variable ncell equal 3 - -# ----------------------- ATOM DEFINITION ---------------------------- -region box block -4 4 -4 4 -4 4 -create_box 2 box -Created orthogonal box = (-4 -4 -4) to (4 4 4) - 1 by 1 by 1 MPI processor grid - -# - -include potential.mod -# NOTE: This script can be modified for different pair styles -# See in.elastic for more info. - -variable Pu string H -print "potential chosen ${Pu}" -potential chosen H -# Choose potential -pair_style MSmeam -print "we just executed" -we just executed - -pair_coeff * * library.MSmeam ${Pu} Ga4 HGaMS.meam ${Pu} Ga4 -pair_coeff * * library.MSmeam H Ga4 HGaMS.meam ${Pu} Ga4 -pair_coeff * * library.MSmeam H Ga4 HGaMS.meam H Ga4 -Reading potential file library.MSmeam with DATE: 2018-09-22 -# Setup neighbor style -neighbor 1.0 nsq -neigh_modify once no every 1 delay 0 check yes - -# Setup minimization style -variable dmax equal 1.0e-2 -min_style cg -min_modify dmax ${dmax} line quadratic -min_modify dmax 0.01 line quadratic -compute eng all pe/atom -compute eatoms all reduce sum c_eng - -# Setup output -thermo 100 -thermo_style custom step temp etotal press pxx pyy pzz pxy pxz pyz lx ly lz vol c_eatoms -thermo_modify norm yes -create_atoms 1 single 0 0 0 units box -Created 1 atoms -create_atoms 2 single 2.2 0 0 units box -Created 1 atoms -create_atoms 2 single 0.3 2.3 0 units box -Created 1 atoms -# ---------- Define Settings --------------------- -variable teng equal "c_eatoms" -compute pot_energy all pe/atom -compute stress all stress/atom NULL -dump 1 all custom 1 dump.msmeam id x y z fx fy fz c_pot_energy c_stress[1] c_stress[2] c_stress[3] c_stress[4] c_stress[5] c_stress[6] -run 1 -WARNING: No fixes defined, atoms won't move (../verlet.cpp:55) -Neighbor list info ... - 2 neighbor list requests - update every 1 steps, delay 0 steps, check yes - max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 6.9 - ghost atom cutoff = 6.9 -Memory usage per processor = 12.9295 Mbytes -Step Temp TotEng Press Pxx Pyy Pzz Pxy Pxz Pyz Lx Ly Lz Volume eatoms - 0 0 15.433079 491354.68 838670.91 635393.13 0 80195.793 0 0 8 8 8 512 15.433079 - 1 0 15.433079 491354.68 838670.91 635393.13 0 80195.793 0 0 8 8 8 512 15.433079 -Loop time of 0.000172138 on 1 procs for 1 steps with 3 atoms - -Performance: 501.922 ns/day, 0.048 hours/ns, 5809.285 timesteps/s -81.3% CPU use with 1 MPI tasks x no OpenMP threads - -MPI task timing breakdown: -Section | min time | avg time | max time |%varavg| %total ---------------------------------------------------------------- -Pair | 6.6996e-05 | 6.6996e-05 | 6.6996e-05 | 0.0 | 38.92 -Neigh | 0 | 0 | 0 | 0.0 | 0.00 -Comm | 1.9073e-06 | 1.9073e-06 | 1.9073e-06 | 0.0 | 1.11 -Output | 9.7036e-05 | 9.7036e-05 | 9.7036e-05 | 0.0 | 56.37 -Modify | 0 | 0 | 0 | 0.0 | 0.00 -Other | | 6.199e-06 | | | 3.60 - -Nlocal: 3 ave 3 max 3 min -Histogram: 1 0 0 0 0 0 0 0 0 0 -Nghost: 78 ave 78 max 78 min -Histogram: 1 0 0 0 0 0 0 0 0 0 -Neighs: 7 ave 7 max 7 min -Histogram: 1 0 0 0 0 0 0 0 0 0 -FullNghs: 14 ave 14 max 14 min -Histogram: 1 0 0 0 0 0 0 0 0 0 - -Total # of neighbors = 14 -Ave neighs/atom = 4.66667 -Neighbor list builds = 0 -Dangerous builds = 0 -write_data data.msmeam - -print "All done!" -All done! -Total wall time: 0:00:00 - diff --git a/examples/meam/msmeam/msmeam.dump.bu b/examples/meam/msmeam/msmeam.dump.bu deleted file mode 100644 index 039f630073..0000000000 --- a/examples/meam/msmeam/msmeam.dump.bu +++ /dev/null @@ -1,24 +0,0 @@ -ITEM: TIMESTEP -0 -ITEM: NUMBER OF ATOMS -3 -ITEM: BOX BOUNDS pp pp pp --4 4 --4 4 --4 4 -ITEM: ATOMS id x y z fx fy fz c_pot_energy c_stress[1] c_stress[2] c_stress[3] c_stress[4] c_stress[5] c_stress[6] -1 0 0 0 -131.925 -88.3005 0 22.9153 -2.147e+08 -1.62661e+08 -0 -2.05301e+07 -0 -0 -2 2.2 0 0 120.809 -0.482171 0 14.7692 -2.12028e+08 -0 -0 403352 -0 -0 -3 0.3 2.3 0 11.1159 88.7827 0 8.61478 -2.67145e+06 -1.62661e+08 -0 -2.09335e+07 -0 -0 -ITEM: TIMESTEP -1 -ITEM: NUMBER OF ATOMS -3 -ITEM: BOX BOUNDS pp pp pp --4 4 --4 4 --4 4 -ITEM: ATOMS id x y z fx fy fz c_pot_energy c_stress[1] c_stress[2] c_stress[3] c_stress[4] c_stress[5] c_stress[6] -1 0 0 0 -131.925 -88.3005 0 22.9153 -2.147e+08 -1.62661e+08 -0 -2.05301e+07 -0 -0 -2 2.2 0 0 120.809 -0.482171 0 14.7692 -2.12028e+08 -0 -0 403352 -0 -0 -3 0.3 2.3 0 11.1159 88.7827 0 8.61478 -2.67145e+06 -1.62661e+08 -0 -2.09335e+07 -0 -0 diff --git a/examples/meam/msmeam/potential.mod b/examples/meam/msmeam/potential.mod index 760cc93503..117736743b 100644 --- a/examples/meam/msmeam/potential.mod +++ b/examples/meam/msmeam/potential.mod @@ -7,7 +7,7 @@ print "potential chosen ${Pu}" pair_style meam/ms print "we just executed" -pair_coeff * * library.msmeam ${Pu} Ga4 HGa.meam ${Pu} Ga4 +pair_coeff * * library.msmeam ${Pu} Ga4 HGa.msmeam ${Pu} Ga4 # Setup neighbor style neighbor 1.0 bin neigh_modify once no every 1 delay 0 check yes diff --git a/potentials/HGa.msmeam b/potentials/HGa.msmeam index 9f01501c16..1f84d0f8a5 100644 --- a/potentials/HGa.msmeam +++ b/potentials/HGa.msmeam @@ -1,29 +1,29 @@ bkgd_dyn = 1 emb_lin_neg = 1 -augt1=0 -ialloy=1 -rc = 5.9 +augt1=0 +ialloy=1 +rc = 5.9 #H -attrac(1,1)=0.460 -repuls(1,1)=0.460 +attrac(1,1)=0.460 +repuls(1,1)=0.460 Cmin(1,1,1)=1.3 # PuMS -Cmax(1,1,1)= 2.80 +Cmax(1,1,1)= 2.80 nn2(1,1)=1 #Ga rho0(2) = 0.6 -attrac(2,2)=0.097 -repuls(2,2)=0.097 +attrac(2,2)=0.097 +repuls(2,2)=0.097 nn2(2,2)=1 #HGa -attrac(1,2)=0.300 -repuls(1,2)=0.300 -lattce(1,2)=l12 -re(1,2)=3.19 -delta(1,2)=-0.48 -alpha(1,2)=6.6 -Cmin(1,1,2)=2.0 -Cmin(2,1,2)= 2.0 -Cmin(1,2,1)=2.0 +attrac(1,2)=0.300 +repuls(1,2)=0.300 +lattce(1,2)=l12 +re(1,2)=3.19 +delta(1,2)=-0.48 +alpha(1,2)=6.6 +Cmin(1,1,2)=2.0 +Cmin(2,1,2)= 2.0 +Cmin(1,2,1)=2.0 Cmin(2,2,1) = 1.4 Cmin(1,2,2) = 1.4 Cmin(1,1,2) = 1.4 From 00b0c439edc8e06ca9f143c11843804a11ad0a9e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 1 Mar 2024 18:54:43 -0500 Subject: [PATCH 153/185] improve error messages --- src/MEAM/pair_meam.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/MEAM/pair_meam.cpp b/src/MEAM/pair_meam.cpp index 6159c452b0..d9d2b53885 100644 --- a/src/MEAM/pair_meam.cpp +++ b/src/MEAM/pair_meam.cpp @@ -206,7 +206,12 @@ void PairMEAM::coeff(int narg, char **arg) // check for presence of first meam file std::string lib_file = utils::get_potential_file_path(arg[2]); - if (lib_file.empty()) error->all(FLERR, "Cannot open MEAM library file {}", lib_file); + if (lib_file.empty()) { + if (msmeamflag) + error->all(FLERR, "Cannot open MS-MEAM library file {}", lib_file); + else + error->all(FLERR, "Cannot open MEAM library file {}", lib_file); + } // find meam parameter file in arguments: // first word that is a file or "NULL" after the MEAM library file @@ -226,7 +231,12 @@ void PairMEAM::coeff(int narg, char **arg) break; } } - if (paridx < 0) error->all(FLERR, "No MEAM parameter file in pair coefficients"); + if (paridx < 0) { + if (msmeamflag) + error->all(FLERR, "No MS-MEAM parameter file in pair coefficients"); + else + error->all(FLERR, "No MEAM parameter file in pair coefficients"); + } if ((narg - paridx - 1) != atom->ntypes) error->all(FLERR, "Incorrect args for pair style {} coefficients", myname); From 133ec34bf576d38d4342e08a323fbaffdbaf6183 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 1 Mar 2024 19:01:48 -0500 Subject: [PATCH 154/185] update --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 47233250a3..ed37fa80b9 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -37,7 +37,7 @@ src/MESONT/* @iafoss src/ML-HDNNP/* @singraber src/ML-IAP/* @athomps src/ML-PACE/* @yury-lysogorskiy -src/ML-POD/* @exapde @rohskopf +src/ML-POD/* @exapde src/MOFFF/* @hheenen src/MOLFILE/* @akohlmey src/NETCDF/* @pastewka From 45e8ee1c087db0cc53415af8f20904bde36d66bf Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 2 Mar 2024 15:53:21 -0500 Subject: [PATCH 155/185] disallow using custom cutoff with multi cutoff neighbor lists --- src/compute_rdf.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compute_rdf.cpp b/src/compute_rdf.cpp index 17fe450fe5..f31c3c5743 100644 --- a/src/compute_rdf.cpp +++ b/src/compute_rdf.cpp @@ -68,6 +68,8 @@ ComputeRDF::ComputeRDF(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"cutoff") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal compute rdf command"); + if ((neighbor->style == Neighbor::MULTI) || (neighbor->style == Neighbor::MULTI_OLD)) + error->all(FLERR, "Compute rdf with custom cutoff requires neighbor style 'bin' or 'nsq'"); cutoff_user = utils::numeric(FLERR,arg[iarg+1],false,lmp); if (cutoff_user <= 0.0) cutflag = 0; else cutflag = 1; From ccdf55151dce30b5b9262adc1d542ccd3b2e147e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 2 Mar 2024 15:53:33 -0500 Subject: [PATCH 156/185] modernize --- src/compute_rdf.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/compute_rdf.cpp b/src/compute_rdf.cpp index f31c3c5743..abc72ff202 100644 --- a/src/compute_rdf.cpp +++ b/src/compute_rdf.cpp @@ -46,7 +46,7 @@ ComputeRDF::ComputeRDF(LAMMPS *lmp, int narg, char **arg) : hist(nullptr), histall(nullptr), typecount(nullptr), icount(nullptr), jcount(nullptr), duplicates(nullptr) { - if (narg < 4) error->all(FLERR,"Illegal compute rdf command"); + if (narg < 4) utils::missing_cmd_args(FLERR,"compute rdf", error); array_flag = 1; extarray = 0; @@ -67,14 +67,14 @@ ComputeRDF::ComputeRDF(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"cutoff") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal compute rdf command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR,"compute rdf cutoff", error); if ((neighbor->style == Neighbor::MULTI) || (neighbor->style == Neighbor::MULTI_OLD)) error->all(FLERR, "Compute rdf with custom cutoff requires neighbor style 'bin' or 'nsq'"); cutoff_user = utils::numeric(FLERR,arg[iarg+1],false,lmp); if (cutoff_user <= 0.0) cutflag = 0; else cutflag = 1; iarg += 2; - } else error->all(FLERR,"Illegal compute rdf command"); + } else error->all(FLERR,"Unknown compute rdf keyword {}", arg[iarg]); } // pairwise args @@ -141,17 +141,17 @@ ComputeRDF::~ComputeRDF() { memory->destroy(rdfpair); memory->destroy(nrdfpair); - delete [] ilo; - delete [] ihi; - delete [] jlo; - delete [] jhi; + delete[] ilo; + delete[] ihi; + delete[] jlo; + delete[] jhi; memory->destroy(hist); memory->destroy(histall); memory->destroy(array); - delete [] typecount; - delete [] icount; - delete [] jcount; - delete [] duplicates; + delete[] typecount; + delete[] icount; + delete[] jcount; + delete[] duplicates; } /* ---------------------------------------------------------------------- */ @@ -160,8 +160,7 @@ void ComputeRDF::init() { if (!force->pair && !cutflag) - error->all(FLERR,"Compute rdf requires a pair style be defined " - "or cutoff specified"); + error->all(FLERR,"Compute rdf requires a pair style or an explicit cutoff"); if (cutflag) { double skin = neighbor->skin; @@ -256,7 +255,7 @@ void ComputeRDF::init_norm() for (i = 0; i < npairs; i++) jcount[i] = scratch[i]; MPI_Allreduce(duplicates,scratch,npairs,MPI_INT,MPI_SUM,world); for (i = 0; i < npairs; i++) duplicates[i] = scratch[i]; - delete [] scratch; + delete[] scratch; } /* ---------------------------------------------------------------------- */ From e51e2733cb995e7c6822b4e1763c8ed22f7b96a6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 3 Mar 2024 07:47:14 -0500 Subject: [PATCH 157/185] add note for porting code containing the removed Atoms::count_words() functions --- doc/src/Developer_updating.rst | 47 ++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/doc/src/Developer_updating.rst b/doc/src/Developer_updating.rst index cd61eaa5a1..83491ac095 100644 --- a/doc/src/Developer_updating.rst +++ b/doc/src/Developer_updating.rst @@ -18,6 +18,7 @@ Available topics in mostly chronological order are: - `Setting flags in the constructor`_ - `Rename of pack/unpack_comm() to pack/unpack_forward_comm()`_ - `Use ev_init() to initialize variables derived from eflag and vflag`_ +- `Use utils::count_words() functions instead of atom->count_words()`_ - `Use utils::numeric() functions instead of force->numeric()`_ - `Use utils::open_potential() function to open potential files`_ - `Use symbolic Atom and AtomVec constants instead of numerical values`_ @@ -130,6 +131,41 @@ Not applying this change will not cause a compilation error, but can lead to inconsistent behavior and incorrect tallying of energy or virial. +Use utils::count_words() functions instead of atom->count_words() +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. versionchanged:: 2Jun2020 + +The "count_words()" functions for parsing text have been moved from the +Atom class to the :doc:`utils namespace `. The +"count_words()" function in "utils" uses the Tokenizer class internally +to split a line into words and count them, thus it will not modify the +argument string as the function in the Atoms class did and thus had a +variant using a copy buffer. Unlike the old version, the new version +does not remove comments. For that you can use the +:cpp:func:`utils::trim_comment() function +` as shown in the example below. + +Old: + +.. code-block:: c++ + + nwords = atom->count_words(line); + int nwords = atom->count_words(buf); + +New: + +.. code-block:: c++ + + nwords = utils::count_words(line); + int nwords = utils::count_words(utils::trim_comment(buf)); + +.. seealso:: + + :cpp:func:`utils::count_words() `, + :cpp:func:`utils::trim_comments() ` + + Use utils::numeric() functions instead of force->numeric() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -137,11 +173,12 @@ Use utils::numeric() functions instead of force->numeric() The "numeric()" conversion functions (including "inumeric()", "bnumeric()", and "tnumeric()") have been moved from the Force class to -the utils namespace. Also they take an additional argument that selects -whether the ``Error::all()`` or ``Error::one()`` function should be -called in case of an error. The former should be used when *all* MPI -processes call the conversion function and the latter *must* be used -when they are called from only one or a subset of the MPI processes. +the :doc:`utils namespace `. Also they take an +additional argument that selects whether the ``Error::all()`` or +``Error::one()`` function should be called in case of an error. The +former should be used when *all* MPI processes call the conversion +function and the latter *must* be used when they are called from only +one or a subset of the MPI processes. Old: From 4a993483fc3c2fdcfb84c4ce7f98d3383b88c30a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 3 Mar 2024 11:25:01 -0500 Subject: [PATCH 158/185] remove dead code --- src/MEAM/meam_force.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/MEAM/meam_force.cpp b/src/MEAM/meam_force.cpp index 1ee8b5e468..6fc3fd762f 100644 --- a/src/MEAM/meam_force.cpp +++ b/src/MEAM/meam_force.cpp @@ -65,11 +65,11 @@ void MEAM::meam_force(int i, int eflag_global, int eflag_atom, int vflag_global, double rhoa2mj,drhoa2mj,rhoa2mi,drhoa2mi; double rhoa3mj, drhoa3mj, rhoa3mi, drhoa3mi; double arg1i1m, arg1j1m, arg1i2m, arg1j2m, arg1i3m, arg1j3m, arg3i3m, arg3j3m; - double drho1mdr1, drho1mdr2, drho1mds1, drho1mds2; + double drho1mdr1, drho1mdr2; double drho1mdrm1[3], drho1mdrm2[3]; - double drho2mdr1, drho2mdr2, drho2mds1, drho2mds2; + double drho2mdr1, drho2mdr2; double drho2mdrm1[3], drho2mdrm2[3]; - double drho3mdr1, drho3mdr2, drho3mds1, drho3mds2; + double drho3mdr1, drho3mdr2; double drho3mdrm1[3], drho3mdrm2[3]; third = 1.0 / 3.0; @@ -528,16 +528,12 @@ void MEAM::meam_force(int i, int eflag_global, int eflag_atom, int vflag_global, if (msmeamflag) { - drho1mds1 = a1 * rhoa1mj * arg1i1m; - drho1mds2 = a1 * rhoa1mi * arg1j1m; - drho2mds1 = a2 * rhoa2mj * arg1i2m - 2.0 / 3.0 * arho2mb[i] * rhoa2mj; - drho2mds2 = a2 * rhoa2mi * arg1j2m - 2.0 / 3.0 * arho2mb[j] * rhoa2mi; - drho3mds1 = a3 * rhoa3mj * arg1i3m - a3a * rhoa3mj * arg3i3m; - drho3mds2 = a3 * rhoa3mi * arg1j3m - a3a * rhoa3mi * arg3j3m; - drho1mds1 *= -1; - drho1mds2 *= -1; - drho3mds1 *= -1; - drho3mds2 *= -1; + const double drho1mds1 = -a1 * rhoa1mj * arg1i1m; + const double drho1mds2 = -a1 * rhoa1mi * arg1j1m; + const double drho2mds1 = a2 * rhoa2mj * arg1i2m - 2.0 / 3.0 * arho2mb[i] * rhoa2mj; + const double drho2mds2 = a2 * rhoa2mi * arg1j2m - 2.0 / 3.0 * arho2mb[j] * rhoa2mi; + const double drho3mds1 = -a3 * rhoa3mj * arg1i3m + a3a * rhoa3mj * arg3i3m; + const double drho3mds2 = -a3 * rhoa3mi * arg1j3m + a3a * rhoa3mi * arg3j3m; t1i = 1.0; t2i = 1.0; @@ -560,13 +556,6 @@ void MEAM::meam_force(int i, int eflag_global, int eflag_atom, int vflag_global, * ((drho1ds2 - drho1mds2) + (drho2ds2 - drho2mds2) + (drho3ds2 - drho3mds2)); } else { - drho1mds1 = 0.0; - drho1mds2 = 0.0; - drho2mds1 = 0.0; - drho2mds2 = 0.0; - drho3mds1 = 0.0; - drho3mds2 = 0.0; - if (ialloy == 1) { a1i = fdiv_zero(rhoa0j, tsq_ave[i][0]); From a776d8425f780df830c4766581e029c8906deeaf Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 3 Mar 2024 11:28:49 -0500 Subject: [PATCH 159/185] initialize pointers to null --- src/MANYBODY/pair_rebomos.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/MANYBODY/pair_rebomos.cpp b/src/MANYBODY/pair_rebomos.cpp index a84469f212..0941ca0a3a 100644 --- a/src/MANYBODY/pair_rebomos.cpp +++ b/src/MANYBODY/pair_rebomos.cpp @@ -54,7 +54,9 @@ static constexpr int PGDELTA = 1; /* ---------------------------------------------------------------------- */ -PairREBOMoS::PairREBOMoS(LAMMPS *lmp) : Pair(lmp) +PairREBOMoS::PairREBOMoS(LAMMPS *lmp) : + Pair(lmp), lj1(nullptr), lj2(nullptr), lj3(nullptr), lj4(nullptr), ipage(nullptr), + REBO_numneigh(nullptr), REBO_firstneigh(nullptr), nM(nullptr), nS(nullptr) { single_enable = 0; restartinfo = 0; @@ -63,12 +65,9 @@ PairREBOMoS::PairREBOMoS(LAMMPS *lmp) : Pair(lmp) manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; + cut3rebo = 0.0; maxlocal = 0; - REBO_numneigh = nullptr; - REBO_firstneigh = nullptr; - ipage = nullptr; pgsize = oneatom = 0; - nM = nS = nullptr; } // clang-format off From 2809428fe20cbfd08d9e108fa88c72b27ef76c31 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 3 Mar 2024 12:27:39 -0500 Subject: [PATCH 160/185] make computes rdf and adf error out multi cutoff neighbor lists if needed --- doc/src/compute_adf.rst | 19 +++++- doc/src/compute_rdf.rst | 37 ++++++---- examples/rdf-adf/in.spce | 24 +++---- src/EXTRA-COMPUTE/compute_adf.cpp | 110 ++++++++++++++---------------- src/EXTRA-COMPUTE/compute_adf.h | 1 - src/compute_rdf.cpp | 8 ++- 6 files changed, 108 insertions(+), 91 deletions(-) diff --git a/doc/src/compute_adf.rst b/doc/src/compute_adf.rst index fc1ad1ae0a..a43a10207c 100644 --- a/doc/src/compute_adf.rst +++ b/doc/src/compute_adf.rst @@ -204,8 +204,23 @@ angles per atom satisfying the ADF criteria. Restrictions """""""""""" -This compute is part of the EXTRA-COMPUTE package. It is only enabled if -LAMMPS was built with that package. See the :doc:`Build package ` page for more info. +This compute is part of the EXTRA-COMPUTE package. It is only enabled +if LAMMPS was built with that package. See the :doc:`Build package +` page for more info. + +By default, the ADF is not computed for distances longer than the +largest force cutoff, since the neighbor list creation will only contain +pairs up to that distance (plus neighbor list skin). If you use outer +cutoffs larger than that, you must use :doc:`neighbor style 'bin' or +'nsq' `. + +If you want an ADF for a larger outer cutoff, you can also use the +:doc:`rerun ` command to post-process a dump file, use :doc:`pair +style zero ` and set the force cutoff to be larger in the +rerun script. Note that in the rerun context, the force cutoff is +arbitrary and with pair style zero you are not computing any forces, and +since you are not running dynamics you are not changing the model that +generated the trajectory. The ADF is not computed for neighbors outside the force cutoff, since processors (in parallel) don't know about atom coordinates for diff --git a/doc/src/compute_rdf.rst b/doc/src/compute_rdf.rst index ed73800f82..85e758016e 100644 --- a/doc/src/compute_rdf.rst +++ b/doc/src/compute_rdf.rst @@ -176,22 +176,29 @@ also numbers :math:`\ge 0.0`. Restrictions """""""""""" -The RDF is not computed for distances longer than the force cutoff, -since processors (in parallel) do not know about atom coordinates for -atoms further away than that distance. If you want an RDF for larger -distances, you can use the :doc:`rerun ` command to post-process -a dump file and set the cutoff for the potential to be longer in the +By default, the RDF is not computed for distances longer than the +largest force cutoff, since the neighbor list creation will only contain +pairs up to that distance (plus neighbor list skin). This distance can +be increased using the *cutoff* keyword but this keyword is only valid +with :doc:`neighbor styles 'bin' and 'nsq' `. + +If you want an RDF for larger distances, you can also use the +:doc:`rerun ` command to post-process a dump file, use :doc:`pair +style zero ` and set the force cutoff to be longer in the rerun script. Note that in the rerun context, the force cutoff is -arbitrary, since you are not running dynamics and thus are not changing -your model. The definition of :math:`g(r)` used by LAMMPS is only appropriate -for characterizing atoms that are uniformly distributed throughout the -simulation cell. In such cases, the coordination number is still -correct and meaningful. As an example, if a large simulation cell -contains only one atom of type *itypeN* and one of *jtypeN*, then :math:`g(r)` -will register an arbitrarily large spike at whatever distance they -happen to be at, and zero everywhere else. -The function :math:`\text{coord}(r)` will show a step -change from zero to one at the location of the spike in :math:`g(r)`. +arbitrary and with pair style zero you are not computing any forces, and +you are not running dynamics you are not changing the model that +generated the trajectory. + +The definition of :math:`g(r)` used by LAMMPS is only appropriate for +characterizing atoms that are uniformly distributed throughout the +simulation cell. In such cases, the coordination number is still correct +and meaningful. As an example, if a large simulation cell contains only +one atom of type *itypeN* and one of *jtypeN*, then :math:`g(r)` will +register an arbitrarily large spike at whatever distance they happen to +be at, and zero everywhere else. The function :math:`\text{coord}(r)` +will show a step change from zero to one at the location of the spike in +:math:`g(r)`. .. note:: diff --git a/examples/rdf-adf/in.spce b/examples/rdf-adf/in.spce index 9a9d99fd42..6627924adc 100644 --- a/examples/rdf-adf/in.spce +++ b/examples/rdf-adf/in.spce @@ -1,22 +1,22 @@ # Liquid water RDFs and ADFs (~12 O-O-O/atom, ~1 O-H...O/atom) -units real -atom_style full +units real +atom_style full -read_data data.spce +read_data data.spce pair_style lj/cut/coul/long 12.0 12.0 pair_coeff * * 0.0 1.0 pair_coeff 1 1 0.15535 3.166 -kspace_style pppm 1.0e-6 +kspace_style pppm 1.0e-6 -bond_style harmonic -angle_style harmonic -dihedral_style none -improper_style none +bond_style harmonic +angle_style harmonic +dihedral_style none +improper_style none -bond_coeff 1 1000.00 1.000 -angle_coeff 1 100.0 109.47 +bond_coeff 1 1000.00 1.000 +angle_coeff 1 100.0 109.47 # need to set bond/angle inclusion to > 0.0 # so that intramolecular pairs are included in neighbor lists (required for second ADF) @@ -26,8 +26,8 @@ neighbor 2.0 bin timestep 2.0 neigh_modify every 1 delay 2 check yes -fix 1 all shake 0.0001 20 0 b 1 a 1 -fix 2 all nvt temp 300.0 300.0 100.0 +fix 1 all shake 0.0001 20 0 b 1 a 1 +fix 2 all nvt temp 300.0 300.0 100.0 velocity all create 300.0 6244325 diff --git a/src/EXTRA-COMPUTE/compute_adf.cpp b/src/EXTRA-COMPUTE/compute_adf.cpp index 35ff8bfd33..20b1749fa9 100644 --- a/src/EXTRA-COMPUTE/compute_adf.cpp +++ b/src/EXTRA-COMPUTE/compute_adf.cpp @@ -34,32 +34,27 @@ #include using namespace LAMMPS_NS; -using namespace MathConst; +using MathConst::MY_PI; +using MathConst::RAD2DEG; -enum{DEGREE, RADIAN, COSINE}; +enum { DEGREE, RADIAN, COSINE }; /* ---------------------------------------------------------------------- compute angular distribution functions for I, J, K atoms ---------------------------------------------------------------------- */ ComputeADF::ComputeADF(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - ilo(nullptr), ihi(nullptr), jlo(nullptr), jhi(nullptr), klo(nullptr), khi(nullptr), - hist(nullptr), histall(nullptr), - rcutinnerj(nullptr), rcutinnerk(nullptr), - rcutouterj(nullptr), rcutouterk(nullptr), - list(nullptr), - iatomcount(nullptr), iatomcountall(nullptr), iatomflag(nullptr), - maxjatom(nullptr), maxkatom(nullptr), - numjatom(nullptr), numkatom(nullptr), - neighjatom(nullptr),neighkatom(nullptr), - jatomflag(nullptr), katomflag(nullptr), - maxjkatom(nullptr), numjkatom(nullptr), - neighjkatom(nullptr), bothjkatom(nullptr), delrjkatom(nullptr) + Compute(lmp, narg, arg), ilo(nullptr), ihi(nullptr), jlo(nullptr), jhi(nullptr), klo(nullptr), + khi(nullptr), hist(nullptr), histall(nullptr), rcutinnerj(nullptr), rcutinnerk(nullptr), + rcutouterj(nullptr), rcutouterk(nullptr), list(nullptr), iatomcount(nullptr), + iatomcountall(nullptr), iatomflag(nullptr), maxjatom(nullptr), maxkatom(nullptr), + numjatom(nullptr), numkatom(nullptr), neighjatom(nullptr), neighkatom(nullptr), + jatomflag(nullptr), katomflag(nullptr), maxjkatom(nullptr), numjkatom(nullptr), + neighjkatom(nullptr), bothjkatom(nullptr), delrjkatom(nullptr) { int nargsperadf = 7; - if (narg < 4 ) error->all(FLERR,"Illegal compute adf command"); + if (narg < 4) utils::missing_cmd_args(FLERR, "compute adf", error); array_flag = 1; extarray = 0; @@ -89,17 +84,16 @@ ComputeADF::ComputeADF(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[iarg+1],"degree") == 0) ordinate_style = DEGREE; else if (strcmp(arg[iarg+1],"radian") == 0) ordinate_style = RADIAN; else if (strcmp(arg[iarg+1],"cosine") == 0) ordinate_style = COSINE; - else error->all(FLERR,"Illegal compute adf command"); + else error->all(FLERR,"Unknown compute adf ordinate flag {}",arg[iarg+1]); iarg += 2; - } else error->all(FLERR,"Illegal compute adf command"); + } else error->all(FLERR,"Unknown compute adf keyword {}", arg[iarg]); } // triplewise args if (!nargtriple) ntriples = 1; else { - if (nargtriple % nargsperadf) - error->all(FLERR,"Illegal compute adf command"); + if (nargtriple % nargsperadf) error->all(FLERR,"Illegal compute adf command"); ntriples = nargtriple/nargsperadf; } @@ -107,12 +101,9 @@ ComputeADF::ComputeADF(LAMMPS *lmp, int narg, char **arg) : size_array_cols = 1 + 2*ntriples; int ntypes = atom->ntypes; - memory->create(iatomflag,ntriples,ntypes+1, - "adf:iatomflag"); - memory->create(jatomflag,ntriples,ntypes+1, - "adf:jatomflag"); - memory->create(katomflag,ntriples,ntypes+1, - "adf:katomflag"); + memory->create(iatomflag,ntriples,ntypes+1,"adf:iatomflag"); + memory->create(jatomflag,ntriples,ntypes+1,"adf:jatomflag"); + memory->create(katomflag,ntriples,ntypes+1,"adf:katomflag"); ilo = new int[ntriples]; ihi = new int[ntriples]; @@ -134,14 +125,14 @@ ComputeADF::ComputeADF(LAMMPS *lmp, int narg, char **arg) : klo[0] = 1; khi[0] = ntypes; } else { cutflag = 1; + if ((neighbor->style == Neighbor::MULTI) || (neighbor->style == Neighbor::MULTI_OLD)) + error->all(FLERR, "Compute adf with custom cutoffs requires neighbor style 'bin' or 'nsq'"); iarg = 4; for (int m = 0; m < ntriples; m++) { utils::bounds(FLERR,arg[iarg],1,atom->ntypes,ilo[m],ihi[m],error); utils::bounds(FLERR,arg[iarg+1],1,atom->ntypes,jlo[m],jhi[m],error); utils::bounds(FLERR,arg[iarg+2],1,atom->ntypes,klo[m],khi[m],error); - if (ilo[m] > ihi[m] || - jlo[m] > jhi[m] || - klo[m] > khi[m]) + if ((ilo[m] > ihi[m]) || (jlo[m] > jhi[m]) || (klo[m] > khi[m])) error->all(FLERR,"Illegal compute adf command"); rcutinnerj[m] = utils::numeric(FLERR,arg[iarg+3],false,lmp); rcutouterj[m] = utils::numeric(FLERR,arg[iarg+4],false,lmp); @@ -221,8 +212,6 @@ ComputeADF::ComputeADF(LAMMPS *lmp, int narg, char **arg) : memory->create(bothjkatom[m],maxjkatom[m],"adf:bothjkatom"); memory->create(delrjkatom[m],maxjkatom[m],4,"adf:delrjkatom"); } - - rad2deg = 180.0 / MY_PI; } /* ---------------------------------------------------------------------- */ @@ -230,47 +219,47 @@ ComputeADF::ComputeADF(LAMMPS *lmp, int narg, char **arg) : ComputeADF::~ComputeADF() { memory->destroy(iatomflag); - delete [] ilo; - delete [] ihi; - delete [] jlo; - delete [] jhi; - delete [] klo; - delete [] khi; - delete [] iatomcount; - delete [] iatomcountall; + delete[] ilo; + delete[] ihi; + delete[] jlo; + delete[] jhi; + delete[] klo; + delete[] khi; + delete[] iatomcount; + delete[] iatomcountall; memory->destroy(hist); memory->destroy(histall); memory->destroy(array); memory->destroy(jatomflag); - delete [] rcutinnerj; - delete [] rcutouterj; - delete [] maxjatom; - delete [] numjatom; + delete[] rcutinnerj; + delete[] rcutouterj; + delete[] maxjatom; + delete[] numjatom; for (int m = 0; m < ntriples; m++) memory->destroy(neighjatom[m]); - delete [] neighjatom; + delete[] neighjatom; memory->destroy(katomflag); - delete [] rcutinnerk; - delete [] rcutouterk; - delete [] maxkatom; - delete [] numkatom; + delete[] rcutinnerk; + delete[] rcutouterk; + delete[] maxkatom; + delete[] numkatom; for (int m = 0; m < ntriples; m++) memory->destroy(neighkatom[m]); - delete [] neighkatom; + delete[] neighkatom; - delete [] maxjkatom; - delete [] numjkatom; + delete[] maxjkatom; + delete[] numjkatom; for (int m = 0; m < ntriples; m++) memory->destroy(neighjkatom[m]); - delete [] neighjkatom; + delete[] neighjkatom; for (int m = 0; m < ntriples; m++) memory->destroy(bothjkatom[m]); - delete [] bothjkatom; + delete[] bothjkatom; for (int m = 0; m < ntriples; m++) memory->destroy(delrjkatom[m]); - delete [] delrjkatom; + delete[] delrjkatom; } /* ---------------------------------------------------------------------- */ @@ -282,8 +271,7 @@ void ComputeADF::init() if (!cutflag) { if (!force->pair) - error->all(FLERR,"Compute adf requires a pair style be defined " - "or an outer cutoff specified"); + error->all(FLERR,"Compute adf requires a pair style be defined or an outer cutoff specified"); rcutinnerj[0] = 0.0; rcutinnerk[0] = 0.0; rcutouterj[0] = force->pair->cutforce; @@ -298,7 +286,7 @@ void ComputeADF::init() // specify mycutneigh if force cutoff too small or non-existent - if (!(force->pair) || maxouter > force->pair->cutforce) { + if (!(force->pair) || (maxouter > force->pair->cutforce)) { double skin = neighbor->skin; mycutneigh = maxouter + skin; if (mycutneigh > comm->cutghostuser) @@ -310,7 +298,7 @@ void ComputeADF::init() int x0; if (ordinate_style == DEGREE) { - deltax = MY_PI / nbin * rad2deg; + deltax = MY_PI / nbin * RAD2DEG; deltaxinv = nbin / MY_PI; x0 = 0.0; @@ -337,7 +325,11 @@ void ComputeADF::init() // than maxouter apart, just like a normal neighbor list does auto req = neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL); - if (mycutneigh > 0.0) req->set_cutoff(mycutneigh); + if (mycutneigh > 0.0) { + if ((neighbor->style == Neighbor::MULTI) || (neighbor->style == Neighbor::MULTI_OLD)) + error->all(FLERR, "Compute adf with custom cutoffs requires neighbor style 'bin' or 'nsq'"); + req->set_cutoff(mycutneigh); + } } /* ---------------------------------------------------------------------- */ diff --git a/src/EXTRA-COMPUTE/compute_adf.h b/src/EXTRA-COMPUTE/compute_adf.h index 5f30995aa2..f1f95d325e 100644 --- a/src/EXTRA-COMPUTE/compute_adf.h +++ b/src/EXTRA-COMPUTE/compute_adf.h @@ -59,7 +59,6 @@ class ComputeADF : public Compute { int **bothjkatom; // 1 if atom is in both jatom and katom lists double ***delrjkatom; // list of 4-vectors: delx, dely, delx, and 1/r - double rad2deg; // conversion factor from radians to degrees int ordinate_style; // DEGREE, RADIAN, or COSINE int cutflag; // 1 if at least one outer cutoff specified }; diff --git a/src/compute_rdf.cpp b/src/compute_rdf.cpp index abc72ff202..89f3c91017 100644 --- a/src/compute_rdf.cpp +++ b/src/compute_rdf.cpp @@ -96,7 +96,7 @@ ComputeRDF::ComputeRDF(LAMMPS *lmp, int narg, char **arg) : jlo = new int[npairs]; jhi = new int[npairs]; - if (nargpair == 0) { + if (!nargpair) { ilo[0] = 1; ihi[0] = ntypes; jlo[0] = 1; jhi[0] = ntypes; } else { @@ -206,7 +206,11 @@ void ComputeRDF::init() // than cutoff_user apart, just like a normal neighbor list does auto req = neighbor->add_request(this, NeighConst::REQ_OCCASIONAL); - if (cutflag) req->set_cutoff(mycutneigh); + if (cutflag) { + if ((neighbor->style == Neighbor::MULTI) || (neighbor->style == Neighbor::MULTI_OLD)) + error->all(FLERR, "Compute rdf with custom cutoff requires neighbor style 'bin' or 'nsq'"); + req->set_cutoff(mycutneigh); + } } /* ---------------------------------------------------------------------- */ From 372260ec77ad4f75d873dde5da32a8ee7059102c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 3 Mar 2024 12:46:20 -0500 Subject: [PATCH 161/185] error out in compute ave/sphere/atom and efield/wolf/atom with multi-cutoff neighborlists --- doc/src/compute_ave_sphere_atom.rst | 2 ++ doc/src/compute_efield_wolf_atom.rst | 2 ++ src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp | 5 ++++- src/EXTRA-COMPUTE/compute_efield_wolf_atom.cpp | 6 +++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/src/compute_ave_sphere_atom.rst b/doc/src/compute_ave_sphere_atom.rst index ecb67ae7b5..4640b8534a 100644 --- a/doc/src/compute_ave_sphere_atom.rst +++ b/doc/src/compute_ave_sphere_atom.rst @@ -102,6 +102,8 @@ This compute is part of the EXTRA-COMPUTE package. It is only enabled if LAMMPS was built with that package. See the :doc:`Build package ` page for more info. +This compute requires :doc:`neighbor styles 'bin' or 'nsq' `. + Related commands """""""""""""""" diff --git a/doc/src/compute_efield_wolf_atom.rst b/doc/src/compute_efield_wolf_atom.rst index 1a709dc9f2..93bfa55151 100644 --- a/doc/src/compute_efield_wolf_atom.rst +++ b/doc/src/compute_efield_wolf_atom.rst @@ -106,6 +106,8 @@ Restrictions This compute is part of the EXTRA-COMPUTE package. It is only enabled if LAMMPS was built with that package. +This compute requires :doc:`neighbor styles 'bin' or 'nsq' `. + Related commands """""""""""""""" diff --git a/src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp b/src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp index 89011e7177..b3b920fef3 100644 --- a/src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp @@ -33,7 +33,7 @@ #include using namespace LAMMPS_NS; -using namespace MathConst; +using MathConst::MY_PI; /* ---------------------------------------------------------------------- */ @@ -108,6 +108,9 @@ void ComputeAveSphereAtom::init() else volume = MY_PI * cutsq; + if ((neighbor->style == Neighbor::MULTI) || (neighbor->style == Neighbor::MULTI_OLD)) + error->all(FLERR, "Compute ave/sphere/atom requires neighbor style 'bin' or 'nsq'"); + // need an occasional full neighbor list auto req = neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL); diff --git a/src/EXTRA-COMPUTE/compute_efield_wolf_atom.cpp b/src/EXTRA-COMPUTE/compute_efield_wolf_atom.cpp index ba5a16d52b..ceb16de2ec 100644 --- a/src/EXTRA-COMPUTE/compute_efield_wolf_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_efield_wolf_atom.cpp @@ -92,7 +92,11 @@ void ComputeEfieldWolfAtom::init() if (atom->mu_flag && (comm->me == 0)) error->warning(FLERR, "Compute efield/wolf/atom does not support per-atom dipoles"); - // need an occasional full neighbor list + if ((neighbor->style == Neighbor::MULTI) || (neighbor->style == Neighbor::MULTI_OLD)) + error->all(FLERR, "Compute efield/wolf/atom requires neighbor style 'bin' or 'nsq'"); + + // request an occasional full neighbor list + auto req = neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL); if (cutoff_flag) req->set_cutoff(cutoff); From 60e5124ac2fc72eb57ab9b349b970a882fe3557a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 3 Mar 2024 12:51:48 -0500 Subject: [PATCH 162/185] compute composition/atom doesn't seem to be compatible with multi neighbor lists --- doc/src/compute_composition_atom.rst | 2 ++ src/EXTRA-COMPUTE/compute_composition_atom.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/src/compute_composition_atom.rst b/doc/src/compute_composition_atom.rst index e973eaa234..c3e6fb7c60 100644 --- a/doc/src/compute_composition_atom.rst +++ b/doc/src/compute_composition_atom.rst @@ -107,6 +107,8 @@ This compute is part of the EXTRA-COMPUTE package. It is only enabled if LAMMPS was built with that package. See the :doc:`Build package ` page for more info. +This compute requires :doc:`neighbor styles 'bin' or 'nsq' `. + Related commands """""""""""""""" diff --git a/src/EXTRA-COMPUTE/compute_composition_atom.cpp b/src/EXTRA-COMPUTE/compute_composition_atom.cpp index 47483f760b..976718057f 100644 --- a/src/EXTRA-COMPUTE/compute_composition_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_composition_atom.cpp @@ -94,7 +94,6 @@ void ComputeCompositionAtom::init() "use comm_modify cutoff command"); } - int cutflag = 1; if (force->pair) { if (cutoff == 0.0) { cutoff = force->pair->cutforce; } if (cutoff <= force->pair->cutforce + skin) cutflag = 0; @@ -102,10 +101,13 @@ void ComputeCompositionAtom::init() cutsq = cutoff * cutoff; + if ((neighbor->style == Neighbor::MULTI) || (neighbor->style == Neighbor::MULTI_OLD)) + error->all(FLERR, "Compute composition/atom requires neighbor style 'bin' or 'nsq'"); + // need an occasional full neighbor list auto req = neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL); - if (cutflag) req->set_cutoff(cutoff); + req->set_cutoff(cutoff); } /* ---------------------------------------------------------------------- */ From 9628ad6cafc5a73d24eb9431184860cb34b1d990 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 3 Mar 2024 12:59:17 -0500 Subject: [PATCH 163/185] recover compilation --- src/EXTRA-COMPUTE/compute_composition_atom.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/EXTRA-COMPUTE/compute_composition_atom.cpp b/src/EXTRA-COMPUTE/compute_composition_atom.cpp index 976718057f..d36cb96028 100644 --- a/src/EXTRA-COMPUTE/compute_composition_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_composition_atom.cpp @@ -94,6 +94,7 @@ void ComputeCompositionAtom::init() "use comm_modify cutoff command"); } + int cutflag = 1; if (force->pair) { if (cutoff == 0.0) { cutoff = force->pair->cutforce; } if (cutoff <= force->pair->cutforce + skin) cutflag = 0; @@ -107,7 +108,7 @@ void ComputeCompositionAtom::init() // need an occasional full neighbor list auto req = neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL); - req->set_cutoff(cutoff); + if (cutflag) req->set_cutoff(cutoff); } /* ---------------------------------------------------------------------- */ From d33519e88209094085208b2a068c6562cd5be079 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 3 Mar 2024 16:47:44 -0500 Subject: [PATCH 164/185] correct and clarify --- doc/src/fix_ttm.rst | 28 ++++++++++++++-------------- src/EXTRA-FIX/fix_ttm_mod.cpp | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/doc/src/fix_ttm.rst b/doc/src/fix_ttm.rst index ccf7f16554..5a7f864686 100644 --- a/doc/src/fix_ttm.rst +++ b/doc/src/fix_ttm.rst @@ -96,11 +96,11 @@ each processor, which is acceptable when the overall grid is reasonably small. For larger grids you should use fix *ttm/grid* instead. Fix *ttm/mod* adds options to account for external heat sources (e.g. at -a surface) and for specifying parameters that allow the electronic -heat capacity to depend strongly on electronic temperature. It is -more expensive computationally than fix *ttm* because it treats the -thermal diffusion equation as non-linear. More details on fix *ttm/mod* -are given below. +a surface) and for specifying parameters that allow the electronic heat +capacity to depend strongly on electronic temperature. It is more +expensive computationally than fix *ttm* because it treats the thermal +diffusion equation as non-linear. More details on fix *ttm/mod* are +given below. Heat transfer between the electronic and atomic subsystems is carried out via an inhomogeneous Langevin thermostat. Only atoms in the fix @@ -303,15 +303,15 @@ The current fix ttm/mod implementation allows TTM simulations with a vacuum. The vacuum region is defined as the grid cells with zero electronic temperature. The numerical scheme does not allow energy exchange with such cells. Since the material can expand to previously -unoccupied region in some simulations, the vacuum border can be -allowed to move. It is controlled by the *surface_movement* parameter -in the *init_file*. If it is set to 1, then "vacuum" cells can be -changed to "electron-filled" cells with the temperature *T_e_min* if -atoms move into them (currently only implemented for the case of -1-dimensional motion of flat surface normal to the X axis). The -initial borders of vacuum can be set in the *init_file* via *lsurface* -and *rsurface* parameters. In this case, electronic pressure gradient -is calculated as +unoccupied region in some simulations, the vacuum border can be allowed +to move. It is controlled by the *surface_movement* parameter in the +*init_file*. If it is set to 1, then "vacuum" cells can be changed to +"electron-filled" cells with the temperature *T_e_min* if atoms move +into them (currently only implemented for the case of 1-dimensional +motion of a flat surface normal to the X axis). The initial locations of +the interfaces of the electron density to the vacuum can be set in the +*init_file* via *lsurface* and *rsurface* parameters. In this case, +electronic pressure gradient is calculated as .. math:: diff --git a/src/EXTRA-FIX/fix_ttm_mod.cpp b/src/EXTRA-FIX/fix_ttm_mod.cpp index 79af414f0a..335acdd853 100644 --- a/src/EXTRA-FIX/fix_ttm_mod.cpp +++ b/src/EXTRA-FIX/fix_ttm_mod.cpp @@ -486,12 +486,12 @@ void FixTTMMod::read_parameters(const std::string &filename) reader.next_line(); intensity = reader.next_values(1).next_double(); - // coordinate of 1st surface in x-direction (in box units) - constant + // coordinate of 1st surface in x-direction (electron grid units) - constant reader.next_line(); surface_l = reader.next_values(1).next_int(); - // coordinate of 2nd surface in x-direction (in box units) - constant + // coordinate of 2nd surface in x-direction (electron grid units) - constant reader.next_line(); surface_r = reader.next_values(1).next_int(); From e19ad38c14d217e2bf7df223f6ee277353af0ded Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 3 Mar 2024 18:36:15 -0500 Subject: [PATCH 165/185] fix missing thread initialization exposed by LAMMPS-GUI --- src/OPENMP/fix_omp.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OPENMP/fix_omp.cpp b/src/OPENMP/fix_omp.cpp index 3a249bad82..0bd36e26e8 100644 --- a/src/OPENMP/fix_omp.cpp +++ b/src/OPENMP/fix_omp.cpp @@ -167,6 +167,10 @@ void FixOMP::init() // adjust number of data objects when the number of OpenMP // threads has been changed somehow const int nthreads = comm->nthreads; +#if defined(_OPENMP) + // make certain threads are initialized correctly. avoids segfaults with LAMMPS-GUI + if (nthreads != omp_get_max_threads()) omp_set_num_threads(nthreads); +#endif if (_nthr != nthreads) { if (comm->me == 0) utils::logmesg(lmp,"Re-init OPENMP for {} OpenMP thread(s)\n", nthreads); From 3c8bb5a1be2987e4c0568a8f3b229a1472964511 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 3 Mar 2024 18:39:28 -0500 Subject: [PATCH 166/185] programming style update --- src/OPENMP/fix_omp.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/OPENMP/fix_omp.cpp b/src/OPENMP/fix_omp.cpp index 0bd36e26e8..f7828f43ee 100644 --- a/src/OPENMP/fix_omp.cpp +++ b/src/OPENMP/fix_omp.cpp @@ -161,8 +161,7 @@ void FixOMP::init() { // OPENMP package cannot be used with atom_style template if (atom->molecular == Atom::TEMPLATE) - error->all(FLERR,"OPENMP package does not (yet) work with " - "atom_style template"); + error->all(FLERR,"OPENMP package does not (yet) work with atom_style template"); // adjust number of data objects when the number of OpenMP // threads has been changed somehow @@ -216,7 +215,7 @@ void FixOMP::init() // kspace_split < 0 : master partition, does not do kspace // kspace_split > 0 : slave partition, only does kspace - if (strstr(update->integrate_style,"verlet/split") != nullptr) { + if (utils::strmatch(update->integrate_style, "^verlet/split")) { if (universe->iworld == 0) kspace_split = -1; else kspace_split = 1; } else { From 6e91123910d54354c5f2f23c5a58b402bf4b917c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 3 Mar 2024 23:58:33 -0500 Subject: [PATCH 167/185] try a different workaround for "fix not computed at compatible time" with write_dump --- src/write_dump.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/write_dump.cpp b/src/write_dump.cpp index 89dd48e0ba..0418d7c424 100644 --- a/src/write_dump.cpp +++ b/src/write_dump.cpp @@ -45,11 +45,15 @@ void WriteDump::command(int narg, char **arg) // create the Dump instance // create dump command line with extra required args + // work around "fix not computed at compatible times" errors. + + const int dumpfreq = MAX(1, update->nsteps); + auto dumpargs = new char *[modindex + 2]; - dumpargs[0] = (char *) "WRITE_DUMP"; // dump id - dumpargs[1] = arg[0]; // group - dumpargs[2] = arg[1]; // dump style - dumpargs[3] = utils::strdup(std::to_string(MAX(update->ntimestep, 1))); // dump frequency + dumpargs[0] = (char *) "WRITE_DUMP"; // dump id + dumpargs[1] = arg[0]; // group + dumpargs[2] = arg[1]; // dump style + dumpargs[3] = utils::strdup(std::to_string(dumpfreq)); // dump frequency for (int i = 2; i < modindex; ++i) dumpargs[i + 2] = arg[i]; From 8e6ce1d0b969dc0390f7e9d6408e4d57491b185a Mon Sep 17 00:00:00 2001 From: Ludwig Ahrens Date: Mon, 4 Mar 2024 08:52:05 +0100 Subject: [PATCH 168/185] Remove nonneut examples --- doc/src/fix_electrode.rst | 2 +- .../PACKAGES/electrode/graph-il/in.nonneut | 31 ----------------- .../PACKAGES/electrode/graph-il/in.nonneut2 | 33 ------------------- 3 files changed, 1 insertion(+), 65 deletions(-) delete mode 100644 examples/PACKAGES/electrode/graph-il/in.nonneut delete mode 100644 examples/PACKAGES/electrode/graph-il/in.nonneut2 diff --git a/doc/src/fix_electrode.rst b/doc/src/fix_electrode.rst index d807da7fd2..3759ff23ca 100644 --- a/doc/src/fix_electrode.rst +++ b/doc/src/fix_electrode.rst @@ -45,7 +45,7 @@ Syntax rng_v = integer used to initialize random number generator * zero or more keyword/value pairs may be appended -* keyword = *algo* or *symm* or *couple* or *etypes* or *ffield* or *write_mat* or *write_inv* or *read_mat* or *read_inv* or *qtotal* +* keyword = *algo* or *symm* or *couple* or *etypes* or *ffield* or *write_mat* or *write_inv* or *read_mat* or *read_inv* or *qtotal* or *eta* .. parsed-literal:: diff --git a/examples/PACKAGES/electrode/graph-il/in.nonneut b/examples/PACKAGES/electrode/graph-il/in.nonneut deleted file mode 100644 index 3027faf0cc..0000000000 --- a/examples/PACKAGES/electrode/graph-il/in.nonneut +++ /dev/null @@ -1,31 +0,0 @@ -# electrodes, overall non-neutral -# for graphene-ionic liquid supercapacitor - -boundary p p f # slab calculation -include settings.mod # styles, groups, computes and fixes -kspace_modify slab 3.0 - -# make an extra anion -variable qmodify index 1 -variable vdiff index 1 -# these values can be changed, e.g. ${LAMMPS_EXECUTABLE} -i in.nonneut -var qmodify 0.9 -var vdiff -2 -# fix electrode/* needs equal style variables: -variable qmodify_equal equal v_qmodify -variable vdiff_equal equal v_vdiff - -create_atoms 4 single 16.1 17.2 0 -set atom 3777 charge $(-v_qmodify) - -fix c top electrode/conp v_vdiff_equal 1.979 couple bot 0 etypes on qtotal v_qmodify_equal -# to test electrode/thermo: -# variable vbot equal 0 -# fix c top electrode/thermo v_vdiff_equal 1.979 couple bot v_vbot etypes on qtotal v_qmodify_equal temp 310 100 12309 # symm on - -variable dv equal f_c[1]-f_c[2] - -variable qelec equal c_qbot+c_qtop -compute qall all reduce sum v_q # total system charge - -thermo 50 -thermo_style custom step temp c_ctemp epair etotal c_qbot c_qtop f_c[1] f_c[2] v_dv v_qelec c_qall -run 500 diff --git a/examples/PACKAGES/electrode/graph-il/in.nonneut2 b/examples/PACKAGES/electrode/graph-il/in.nonneut2 deleted file mode 100644 index c73eee5db3..0000000000 --- a/examples/PACKAGES/electrode/graph-il/in.nonneut2 +++ /dev/null @@ -1,33 +0,0 @@ -# electrodes, overall non-neutral -# for graphene-ionic liquid supercapacitor - -boundary p p f # slab calculation -include settings.mod # styles, groups, computes and fixes -kspace_modify slab 3.0 - -# make an extra anion -variable qmodify index 1 -variable vdiff index 1 -# these values can be changed, e.g. ${LAMMPS_EXECUTABLE} -i in.nonneut -var qmodify 0.9 -var vdiff -2 -create_atoms 4 single 16.1 17.2 0 -set atom 3777 charge $(-v_qmodify) - -fix c top electrode/conp v_vtop 1.979 couple bot v_vbot etypes on # symm on -# to test electrode/thermo: -#fix c top electrode/thermo v_vtop 1.979 couple bot v_vbot etypes on temp 310 100 12309 symm off -#but it looks like update_psi() is hardwired to impose electroneutrality - -variable csum equal f_c[1][2]+f_c[1][3]+f_c[2][2]+f_c[2][3] -variable cdiff equal 0.5*(f_c[1][2]-f_c[2][3]) -variable qdeficit equal v_qmodify-f_c[1][1]-f_c[2][1]-v_cdiff*v_vdiff -variable vphi equal v_qdeficit/v_csum -variable vtop equal v_vphi+0.5*v_vdiff -variable vbot equal v_vphi-0.5*v_vdiff -variable dv equal v_vtop-v_vbot - -variable qelec equal c_qbot+c_qtop -compute qall all reduce sum v_q # total system charge - -thermo 50 -thermo_style custom step temp c_ctemp epair etotal c_qbot c_qtop f_c[1] f_c[2] v_dv v_qelec c_qall -run 500 From 6a1f1f7dbccabe0d6397fecee79c977159e28fac Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 4 Mar 2024 09:25:07 -0500 Subject: [PATCH 169/185] add missing symlink --- examples/meam/msmeam/library.msmeam | 1 + 1 file changed, 1 insertion(+) create mode 120000 examples/meam/msmeam/library.msmeam diff --git a/examples/meam/msmeam/library.msmeam b/examples/meam/msmeam/library.msmeam new file mode 120000 index 0000000000..2226ef99da --- /dev/null +++ b/examples/meam/msmeam/library.msmeam @@ -0,0 +1 @@ +../../../potentials/library.msmeam \ No newline at end of file From 0a32cd6c7f68c1a3eb916f5ba0bfe02eb142e1c1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 4 Mar 2024 09:45:54 -0500 Subject: [PATCH 170/185] avoid redundant constant definition --- src/ELECTRODE/electrode_math.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/ELECTRODE/electrode_math.h b/src/ELECTRODE/electrode_math.h index 08689a5adc..0c13076c70 100644 --- a/src/ELECTRODE/electrode_math.h +++ b/src/ELECTRODE/electrode_math.h @@ -18,18 +18,14 @@ #ifndef LMP_ELECTRODE_MATH_H #define LMP_ELECTRODE_MATH_H +#include "ewald_const.h" #include "math.h" #include "math_const.h" namespace LAMMPS_NS { +using namespace EwaldConst; namespace ElectrodeMath { - static constexpr double EWALD_P = 0.3275911; - static constexpr double A1 = 0.254829592; - static constexpr double A2 = -0.284496736; - static constexpr double A3 = 1.421413741; - static constexpr double A4 = -1.453152027; - static constexpr double A5 = 1.061405429; static constexpr double ERFCMAX = 5.8; // erfc(ERFCMAX) < machine epsilon(double) static double safe_erfc(double x) From 393fd164db2debe4bb34df2142bf01163a051b91 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 4 Mar 2024 09:46:14 -0500 Subject: [PATCH 171/185] small conding style updates --- src/ELECTRODE/electrode_math.h | 11 ++++++----- src/ELECTRODE/electrode_vector.cpp | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ELECTRODE/electrode_math.h b/src/ELECTRODE/electrode_math.h index 0c13076c70..4a3cb7bac4 100644 --- a/src/ELECTRODE/electrode_math.h +++ b/src/ELECTRODE/electrode_math.h @@ -19,9 +19,10 @@ #define LMP_ELECTRODE_MATH_H #include "ewald_const.h" -#include "math.h" #include "math_const.h" +#include + namespace LAMMPS_NS { using namespace EwaldConst; @@ -30,7 +31,7 @@ namespace ElectrodeMath { static double safe_erfc(double x) { - if (x > ERFCMAX) return 0.; + if (x > ERFCMAX) return 0.0; double expm2 = exp(-x * x); double t = 1.0 / (1.0 + EWALD_P * x); return t * (A1 + t * (A2 + t * (A3 + t * (A4 + t * A5)))) * expm2; @@ -39,14 +40,14 @@ namespace ElectrodeMath { static double safe_derfcr(double x, double &erfc) { if (x > ERFCMAX) { - erfc = 0.; - return 0.; + erfc = 0.0; + return 0.0; } double x2 = x * x; double expm2 = exp(-x2); double t = 1.0 / (1.0 + EWALD_P * x); erfc = t * (A1 + t * (A2 + t * (A3 + t * (A4 + t * A5)))) * expm2; - return -erfc - 2 * expm2 * x / MathConst::MY_PIS; + return -erfc - 2.0 * expm2 * x / MathConst::MY_PIS; } } // namespace ElectrodeMath diff --git a/src/ELECTRODE/electrode_vector.cpp b/src/ELECTRODE/electrode_vector.cpp index 10125f6325..fc2cca5e46 100644 --- a/src/ELECTRODE/electrode_vector.cpp +++ b/src/ELECTRODE/electrode_vector.cpp @@ -170,11 +170,11 @@ void ElectrodeVector::pair_contribution(double *vector) if (rsq >= cutsq[itype][jtype]) continue; double const eta_j = etaflag ? atom->dvector[eta_index][j] : eta; double etaij; - if (i_in_sensor && j_in_sensor) + if (i_in_sensor && j_in_sensor) { etaij = eta_i * eta_j / sqrt(eta_i * eta_i + eta_j * eta_j); - else if (i_in_sensor) + } else if (i_in_sensor) { etaij = eta_i; - else { + } else { assert(j_in_sensor); etaij = eta_j; } From c7b622699dc2615a665d9a4aef2fe2ac9119f6d1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 4 Mar 2024 09:46:34 -0500 Subject: [PATCH 172/185] regenerate test reference data --- .../tests/kspace-ewald_conp_charge.yaml | 55 +++++++++--------- .../tests/kspace-pppm_conp_charge.yaml | 57 +++++++++---------- 2 files changed, 55 insertions(+), 57 deletions(-) diff --git a/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml b/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml index 9a09a933a4..9bc190a766 100644 --- a/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml +++ b/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml @@ -1,7 +1,6 @@ --- -lammps_version: 3 Nov 2022 -tags: generated -date_generated: Fri Dec 16 10:49:39 2022 +lammps_version: 7 Feb 2024 +date_generated: Mon Mar 4 09:44:30 2024 epsilon: 1e-12 skip_tests: gpu kokkos_omp omp prerequisites: ! | @@ -29,18 +28,18 @@ init_coul: 2.215589572896434 init_stress: ! |2- 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 init_forces: ! |2 - 1 2.0780648532795694e-04 1.9949672015209204e-03 3.1005914149473996e+00 - 2 -1.6777235182686288e-02 2.1481432256290419e-03 3.0881659196467988e+00 - 3 6.0082164895554737e-04 5.1573260226633801e-03 3.1029192412328555e+00 - 4 -1.6728974802490675e-02 6.1174723156886242e-03 3.0909324782862346e+00 - 5 4.2029366155132378e-02 -2.3455526736195693e-03 -1.5659617577954634e+00 - 6 5.5635790919204904e-02 -2.4542947062522369e-03 -1.5693827709331334e+00 - 7 4.2014920784252008e-02 -7.5287470219125008e-04 -1.5671265392163820e+00 - 8 5.5808767852333470e-02 -9.9105389808573120e-04 -1.5707104957299389e+00 - 9 -5.0959878750421551e-02 -2.3630298689785601e-03 -1.5769250181497101e+00 - 10 -3.3526564930579039e-02 -2.3802275431282884e-03 -1.5617801011657175e+00 - 11 -5.1236396351794389e-02 -4.9531100598979201e-04 -1.5779995894034005e+00 - 12 -3.3740693032952060e-02 -1.0210406243572182e-03 -1.5630986537874150e+00 + 1 2.0780648532797705e-04 1.9949672015210172e-03 3.1005914149473988e+00 + 2 -1.6777235182686239e-02 2.1481432256291962e-03 3.0881659196467979e+00 + 3 6.0082164895566240e-04 5.1573260226632518e-03 3.1029192412328550e+00 + 4 -1.6728974802490665e-02 6.1174723156885227e-03 3.0909324782862333e+00 + 5 4.2029366155132364e-02 -2.3455526736195940e-03 -1.5659617577954636e+00 + 6 5.5635790919204904e-02 -2.4542947062522933e-03 -1.5693827709331336e+00 + 7 4.2014920784251980e-02 -7.5287470219118655e-04 -1.5671265392163822e+00 + 8 5.5808767852333491e-02 -9.9105389808568046e-04 -1.5707104957299391e+00 + 9 -5.0959878750421538e-02 -2.3630298689785965e-03 -1.5769250181497101e+00 + 10 -3.3526564930579081e-02 -2.3802275431283552e-03 -1.5617801011657175e+00 + 11 -5.1236396351794437e-02 -4.9531100598972577e-04 -1.5779995894034005e+00 + 12 -3.3740693032952088e-02 -1.0210406243571744e-03 -1.5630986537874152e+00 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 @@ -74,22 +73,22 @@ init_forces: ! |2 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 44 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_vdwl: 0 -run_coul: 6.662694556930399 +run_coul: 6.662694556930397 run_stress: ! |2- 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_forces: ! |2 - 1 2.4590683616589461e-04 1.9614031577863586e-03 3.0874292323214023e+00 - 2 -1.6646391056109371e-02 2.1136931488457949e-03 3.0751133344119812e+00 - 3 6.3535284261970041e-04 5.1012486499622143e-03 3.0897301693141319e+00 - 4 -1.6598674977089525e-02 6.0535154273403009e-03 3.0778495712965137e+00 - 5 4.2257890248609424e-02 -2.3028528771735519e-03 -1.5593100743454233e+00 - 6 5.5690508840794913e-02 -2.4104716736065191e-03 -1.5626897684026875e+00 - 7 4.2243974848895624e-02 -7.6153214117135259e-04 -1.5604618407191599e+00 - 8 5.5862704771247232e-02 -9.9825804058303641e-04 -1.5640031157582626e+00 - 9 -5.1059412079591339e-02 -2.3195548367148278e-03 -1.5701677996288432e+00 - 10 -3.3824301875619064e-02 -2.3375517362836449e-03 -1.5551647759943841e+00 - 11 -5.1334081278836839e-02 -5.0583707575588808e-04 -1.5712298590599834e+00 - 12 -3.4037366496628307e-02 -1.0275977984217531e-03 -1.5564691169384570e+00 + 1 2.4590683616588566e-04 1.9614031577864796e-03 3.0874292323214036e+00 + 2 -1.6646391056109287e-02 2.1136931488459688e-03 3.0751133344119794e+00 + 3 6.3535284261976926e-04 5.1012486499620825e-03 3.0897301693141319e+00 + 4 -1.6598674977089559e-02 6.0535154273402107e-03 3.0778495712965124e+00 + 5 4.2257890248609438e-02 -2.3028528771736243e-03 -1.5593100743454236e+00 + 6 5.5690508840794850e-02 -2.4104716736066006e-03 -1.5626897684026868e+00 + 7 4.2243974848895645e-02 -7.6153214117129057e-04 -1.5604618407191602e+00 + 8 5.5862704771247280e-02 -9.9825804058299890e-04 -1.5640031157582626e+00 + 9 -5.1059412079591346e-02 -2.3195548367148894e-03 -1.5701677996288432e+00 + 10 -3.3824301875619085e-02 -2.3375517362837230e-03 -1.5551647759943836e+00 + 11 -5.1334081278836916e-02 -5.0583707575582921e-04 -1.5712298590599834e+00 + 12 -3.4037366496628307e-02 -1.0275977984217173e-03 -1.5564691169384559e+00 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 diff --git a/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml b/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml index 9322cae321..38161ee044 100644 --- a/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml +++ b/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml @@ -1,7 +1,6 @@ --- -lammps_version: 3 Nov 2022 -tags: generated -date_generated: Fri Dec 16 10:53:11 2022 +lammps_version: 7 Feb 2024 +date_generated: Mon Mar 4 09:44:31 2024 epsilon: 3e-12 skip_tests: gpu kokkos_omp omp prerequisites: ! | @@ -25,22 +24,22 @@ pair_coeff: ! | extract: ! "" natoms: 44 init_vdwl: 0 -init_coul: 2.2156402256727743 +init_coul: 2.215640225672775 init_stress: ! |2- 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 init_forces: ! |2 - 1 2.0996096688278619e-04 1.9837586784579742e-03 3.1004822661058862e+00 - 2 -1.6783332510618001e-02 2.1368843599407208e-03 3.0880130470329266e+00 - 3 6.0300296042516458e-04 5.1688381279906756e-03 3.1028182137891149e+00 - 4 -1.6735061532951023e-02 6.1290626039691648e-03 3.0907879891042778e+00 - 5 4.2014131860757892e-02 -2.3478381081742106e-03 -1.5658874682481501e+00 - 6 5.5659823770659464e-02 -2.4566144388410275e-03 -1.5693278833316524e+00 - 7 4.1999624791768830e-02 -7.5066218795246862e-04 -1.5670569809441637e+00 - 8 5.5832732887661912e-02 -9.8883264742175101e-04 -1.5706605160409157e+00 - 9 -5.0976953599115776e-02 -2.3653810185280764e-03 -1.5768945194236081e+00 - 10 -3.3513771125456580e-02 -2.3824712764543249e-03 -1.5616806812004898e+00 - 11 -5.1253442064492706e-02 -4.9304425051534804e-04 -1.5779738349804435e+00 - 12 -3.3727836471637108e-02 -1.0188844490583379e-03 -1.5630041309277052e+00 + 1 2.0996096688288336e-04 1.9837586784579777e-03 3.1004822661058866e+00 + 2 -1.6783332510618088e-02 2.1368843599407052e-03 3.0880130470329270e+00 + 3 6.0300296042527755e-04 5.1688381279906869e-03 3.1028182137891140e+00 + 4 -1.6735061532951116e-02 6.1290626039692056e-03 3.0907879891042778e+00 + 5 4.2014131860757857e-02 -2.3478381081742123e-03 -1.5658874682481501e+00 + 6 5.5659823770659547e-02 -2.4566144388410201e-03 -1.5693278833316524e+00 + 7 4.1999624791768810e-02 -7.5066218795247393e-04 -1.5670569809441637e+00 + 8 5.5832732887661961e-02 -9.8883264742177161e-04 -1.5706605160409157e+00 + 9 -5.0976953599115846e-02 -2.3653810185280759e-03 -1.5768945194236084e+00 + 10 -3.3513771125456573e-02 -2.3824712764543218e-03 -1.5616806812004898e+00 + 11 -5.1253442064492769e-02 -4.9304425051536007e-04 -1.5779738349804435e+00 + 12 -3.3727836471637081e-02 -1.0188844490583557e-03 -1.5630041309277052e+00 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 @@ -74,22 +73,22 @@ init_forces: ! |2 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 44 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_vdwl: 0 -run_coul: 6.662844644802018 +run_coul: 6.662844644802024 run_stress: ! |2- 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_forces: ! |2 - 1 2.4838446863948484e-04 1.9503788466162767e-03 3.0873204426106526e+00 - 2 -1.6652790386576983e-02 2.1026187422225470e-03 3.0749612676149027e+00 - 3 6.3785749905503929e-04 5.1125747155211223e-03 3.0896293958296615e+00 - 4 -1.6605063813844967e-02 6.0649203065202420e-03 3.0777057807809554e+00 - 5 4.2242722672783783e-02 -2.3050714764837449e-03 -1.5592361985876177e+00 - 6 5.5714273062644280e-02 -2.4127236407636868e-03 -1.5626351195306318e+00 - 7 4.2228746222139874e-02 -7.5938674438442175e-04 -1.5603926320308752e+00 - 8 5.5886401300220823e-02 -9.9610508505007457e-04 -1.5639533086735800e+00 - 9 -5.1076262902731109e-02 -2.3218371704875071e-03 -1.5701372726008265e+00 - 10 -3.3811561421032664e-02 -2.3397296264742753e-03 -1.5550660436064545e+00 - 11 -5.1350902848165472e-02 -5.0363947736730796e-04 -1.5712040115797643e+00 - 12 -3.4024564072498598e-02 -1.0255079009805080e-03 -1.5563752159595892e+00 + 1 2.4838446863956616e-04 1.9503788466163226e-03 3.0873204426106526e+00 + 2 -1.6652790386577014e-02 2.1026187422225435e-03 3.0749612676149027e+00 + 3 6.3785749905510489e-04 5.1125747155211397e-03 3.0896293958296610e+00 + 4 -1.6605063813845172e-02 6.0649203065202620e-03 3.0777057807809554e+00 + 5 4.2242722672783749e-02 -2.3050714764837649e-03 -1.5592361985876177e+00 + 6 5.5714273062644336e-02 -2.4127236407636803e-03 -1.5626351195306318e+00 + 7 4.2228746222139832e-02 -7.5938674438442760e-04 -1.5603926320308752e+00 + 8 5.5886401300220948e-02 -9.9610508505008281e-04 -1.5639533086735800e+00 + 9 -5.1076262902731158e-02 -2.3218371704875301e-03 -1.5701372726008263e+00 + 10 -3.3811561421032657e-02 -2.3397296264742822e-03 -1.5550660436064543e+00 + 11 -5.1350902848165500e-02 -5.0363947736732217e-04 -1.5712040115797643e+00 + 12 -3.4024564072498521e-02 -1.0255079009805182e-03 -1.5563752159595889e+00 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 From 5177b50fda5a84694840549842b2a9c93cefeab6 Mon Sep 17 00:00:00 2001 From: Joel Thomas Clemmer Date: Mon, 4 Mar 2024 09:23:09 -0700 Subject: [PATCH 173/185] Updating multi+narg errors for fix nonaffine --- src/EXTRA-FIX/fix_nonaffine_displacement.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/EXTRA-FIX/fix_nonaffine_displacement.cpp b/src/EXTRA-FIX/fix_nonaffine_displacement.cpp index 06702c408b..4749f3d171 100644 --- a/src/EXTRA-FIX/fix_nonaffine_displacement.cpp +++ b/src/EXTRA-FIX/fix_nonaffine_displacement.cpp @@ -67,7 +67,7 @@ static const char cite_nonaffine_d2min[] = FixNonaffineDisplacement::FixNonaffineDisplacement(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), id_fix(nullptr), X(nullptr), Y(nullptr), F(nullptr), norm(nullptr) { - if (narg < 4) error->all(FLERR,"Illegal fix nonaffine/displacement command"); + if (narg < 4) utils::missing_cmd_args(FLERR,"fix nonaffine/displacement", error); nevery = utils::inumeric(FLERR, arg[3], false, lmp); if (nevery <= 0) error->all(FLERR,"Illegal nevery value {} in fix nonaffine/displacement", nevery); @@ -79,14 +79,16 @@ FixNonaffineDisplacement::FixNonaffineDisplacement(LAMMPS *lmp, int narg, char * nevery = 1; iarg += 1; } else if (strcmp(arg[iarg], "d2min") == 0) { - if (iarg + 1 > narg) error->all(FLERR,"Illegal fix nonaffine/displacement command"); + if (iarg + 1 > narg) utils::missing_cmd_args(FLERR,"fix nonaffine/displacement d2min", error); nad_style = D2MIN; if (strcmp(arg[iarg + 1], "type") == 0) { cut_style = TYPE; } else if (strcmp(arg[iarg + 1], "radius") == 0) { cut_style = RADIUS; } else if (strcmp(arg[iarg + 1], "custom") == 0) { - if (iarg + 2 > narg) error->all(FLERR,"Illegal fix nonaffine/displacement command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR,"fix nonaffine/displacement custom", error); + if ((neighbor->style == Neighbor::MULTI) || (neighbor->style == Neighbor::MULTI_OLD)) + error->all(FLERR, "Fix nonaffine/displacement with custom cutoff requires neighbor style 'bin' or 'nsq'"); cut_style = CUSTOM; cutoff_custom = utils::numeric(FLERR, arg[iarg + 2], false, lmp); cutsq_custom = cutoff_custom * cutoff_custom; @@ -97,7 +99,7 @@ FixNonaffineDisplacement::FixNonaffineDisplacement(LAMMPS *lmp, int narg, char * iarg += 2; } else error->all(FLERR,"Illegal nonaffine displacement style {} in fix nonaffine/displacement", arg[iarg]); - if (iarg + 2 > narg) error->all(FLERR,"Illegal fix nonaffine/displacement command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR,"fix nonaffine/displacement", error); if (strcmp(arg[iarg], "fixed") == 0) { reference_style = FIXED; reference_timestep = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); @@ -207,6 +209,9 @@ void FixNonaffineDisplacement::init() } else { auto req = neighbor->add_request(this, NeighConst::REQ_OCCASIONAL); if (cut_style == CUSTOM) { + if ((neighbor->style == Neighbor::MULTI) || (neighbor->style == Neighbor::MULTI_OLD)) + error->all(FLERR, "Fix nonaffine/displacement with custom cutoff requires neighbor style 'bin' or 'nsq'"); + double skin = neighbor->skin; mycutneigh = cutoff_custom + skin; From a4a171a55ee39ca2546484bca04389527afe4019 Mon Sep 17 00:00:00 2001 From: Joel Thomas Clemmer Date: Mon, 4 Mar 2024 11:14:29 -0700 Subject: [PATCH 174/185] Clarifying ambiguous variables --- src/EXTRA-FIX/fix_nonaffine_displacement.cpp | 38 ++++++++++++-------- src/EXTRA-FIX/fix_nonaffine_displacement.h | 2 +- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/EXTRA-FIX/fix_nonaffine_displacement.cpp b/src/EXTRA-FIX/fix_nonaffine_displacement.cpp index 4749f3d171..c91f37b961 100644 --- a/src/EXTRA-FIX/fix_nonaffine_displacement.cpp +++ b/src/EXTRA-FIX/fix_nonaffine_displacement.cpp @@ -65,7 +65,7 @@ static const char cite_nonaffine_d2min[] = /* ---------------------------------------------------------------------- */ FixNonaffineDisplacement::FixNonaffineDisplacement(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), id_fix(nullptr), X(nullptr), Y(nullptr), F(nullptr), norm(nullptr) + Fix(lmp, narg, arg), id_fix(nullptr), X(nullptr), Y(nullptr), F(nullptr), norm(nullptr), D2min(nullptr) { if (narg < 4) utils::missing_cmd_args(FLERR,"fix nonaffine/displacement", error); @@ -153,6 +153,7 @@ FixNonaffineDisplacement::~FixNonaffineDisplacement() memory->destroy(Y); memory->destroy(F); memory->destroy(norm); + memory->destroy(D2min); memory->destroy(array_atom); } } @@ -178,8 +179,7 @@ void FixNonaffineDisplacement::post_constructor() id_fix = utils::strdup(id + std::string("_FIX_PA")); fix = dynamic_cast(modify->add_fix(fmt::format("{} {} STORE/ATOM 3 0 {} 1", id_fix, group->names[igroup], ghost_status))); - if (nad_style == INTEGRATED) - array_atom = fix->astore; + array_atom = fix->astore; if (nad_style == D2MIN) grow_arrays(atom->nmax); @@ -297,14 +297,17 @@ void FixNonaffineDisplacement::integrate_velocity() int *mask = atom->mask; int nlocal = atom->nlocal; + double **x_nonaffine = fix->astore; for (int m = 0; m < 3; m++) { for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { - array_atom[i][m] += dtv * v[i][m]; + x_nonaffine[i][m] += dtv * v[i][m]; } } } + + array_atom = x_nonaffine; } /* ---------------------------------------------------------------------- */ @@ -312,6 +315,7 @@ void FixNonaffineDisplacement::integrate_velocity() void FixNonaffineDisplacement::save_reference_state() { double **x = atom->x; + double **x0 = fix->astore; int *mask = atom->mask; int nlocal = atom->nlocal; @@ -320,13 +324,13 @@ void FixNonaffineDisplacement::save_reference_state() if (nad_style == D2MIN) { for (int m = 0; m < 3; m++) { for (int i = 0; i < nall; i++) { - if (mask[i] & groupbit) array_atom[i][m] = x[i][m]; + if (mask[i] & groupbit) x0[i][m] = x[i][m]; } } } else { for (int m = 0; m < 3; m++) { for (int i = 0; i < nall; i++) { - if (mask[i] & groupbit) array_atom[i][m] = 0.0; + if (mask[i] & groupbit) x0[i][m] = 0.0; } } } @@ -364,7 +368,7 @@ void FixNonaffineDisplacement::calculate_D2Min() int *ilist, *jlist, *numneigh, **firstneigh; double **x = atom->x; - double **x0 = array_atom; + double **x0 = fix->astore; double *radius = atom->radius; int *type = atom->type; int *mask = atom->mask; @@ -389,7 +393,7 @@ void FixNonaffineDisplacement::calculate_D2Min() } } norm[i] = 0; - array_atom[i][0] = 0; + D2min[i] = 0; } // First loop through neighbors @@ -530,7 +534,7 @@ void FixNonaffineDisplacement::calculate_D2Min() } sub3(r, temp, temp); - array_atom[i][0] += lensq3(temp); + D2min[i] += lensq3(temp); norm[i] += 1; if (newton_pair || j < nlocal) { @@ -541,7 +545,7 @@ void FixNonaffineDisplacement::calculate_D2Min() } sub3(r, temp, temp); - array_atom[j][0] += lensq3(temp); + D2min[j] += lensq3(temp); norm[j] += 1; } } @@ -554,10 +558,9 @@ void FixNonaffineDisplacement::calculate_D2Min() if (!(mask[i] & groupbit)) continue; if (norm[i] != 0) - array_atom[i][0] /= norm[i]; + D2min[i] /= norm[i]; else - array_atom[i][0] = 0.0; - array_atom[i][0] = sqrt(array_atom[i][0]); + D2min[i] = 0.0; for (j = 0; j < 3; j++) for (k = 0; k < 3; k++) @@ -577,6 +580,7 @@ void FixNonaffineDisplacement::calculate_D2Min() edev = sqrt(0.5 * j2); + array_atom[i][0] = sqrt(D2min[i]); array_atom[i][1] = evol; array_atom[i][2] = edev; } @@ -599,7 +603,7 @@ int FixNonaffineDisplacement::pack_reverse_comm(int n, int first, double *buf) } } } else { - buf[m++] = array_atom[i][0]; + buf[m++] = D2min[i]; buf[m++] = ubuf(norm[i]).d; } } @@ -623,7 +627,7 @@ void FixNonaffineDisplacement::unpack_reverse_comm(int n, int *list, double *buf } } } else { - array_atom[j][0] += buf[m++]; + D2min[j] += buf[m++]; norm[j] += (int) ubuf(buf[m++]).i; } } @@ -732,9 +736,13 @@ void FixNonaffineDisplacement::grow_arrays(int nmax_new) memory->destroy(X); memory->destroy(Y); memory->destroy(F); + memory->destroy(D2min); memory->destroy(norm); + memory->destroy(array_atom); memory->create(X, nmax, 3, 3, "fix_nonaffine_displacement:X"); memory->create(Y, nmax, 3, 3, "fix_nonaffine_displacement:Y"); memory->create(F, nmax, 3, 3, "fix_nonaffine_displacement:F"); + memory->create(D2min, nmax, "fix_nonaffine_displacement:D2min"); memory->create(norm, nmax, "fix_nonaffine_displacement:norm"); + memory->create(array_atom, nmax, "fix_nonaffine_displacement:array_atom"); } diff --git a/src/EXTRA-FIX/fix_nonaffine_displacement.h b/src/EXTRA-FIX/fix_nonaffine_displacement.h index 3341ab1834..79dbdabf49 100644 --- a/src/EXTRA-FIX/fix_nonaffine_displacement.h +++ b/src/EXTRA-FIX/fix_nonaffine_displacement.h @@ -52,7 +52,7 @@ class FixNonaffineDisplacement : public Fix { double cutoff_custom, cutsq_custom, mycutneigh; double xprd0, yprd0, zprd0, xprd0_half, yprd0_half, zprd0_half, xy0, xz0, yz0; - double ***X, ***Y, ***F; + double *D2min, ***X, ***Y, ***F; int *norm; class NeighList *list; // half neighbor list From 1949953c0cd8812170d6224afa6e53f040e99229 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Mon, 4 Mar 2024 21:01:23 -0700 Subject: [PATCH 175/185] Clarifying more variables, enabling offset option with integration style --- doc/src/fix_nonaffine_displacement.rst | 4 +- src/EXTRA-FIX/fix_nonaffine_displacement.cpp | 50 ++++++++++---------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/doc/src/fix_nonaffine_displacement.rst b/doc/src/fix_nonaffine_displacement.rst index c6dfbc2e49..0a271ebc32 100644 --- a/doc/src/fix_nonaffine_displacement.rst +++ b/doc/src/fix_nonaffine_displacement.rst @@ -86,8 +86,8 @@ Both of these methods require defining a reference state. With the *fixed* refer style, the user picks a specific timestep *nstep* at which particle positions are saved. If peratom data is accessed from this compute prior to this timestep, it will simply be zeroed. The *update* reference style implies the reference state will be updated every -*nstep* timesteps. The *offset* reference only applies to the *d2min* metric and will -update the reference state *nstep* timesteps before a multiple of *nevery* timesteps. +*nstep* timesteps. The *offset* reference will update the reference state *nstep* +timesteps before a multiple of *nevery* timesteps. ---------- diff --git a/src/EXTRA-FIX/fix_nonaffine_displacement.cpp b/src/EXTRA-FIX/fix_nonaffine_displacement.cpp index c91f37b961..ee14822e98 100644 --- a/src/EXTRA-FIX/fix_nonaffine_displacement.cpp +++ b/src/EXTRA-FIX/fix_nonaffine_displacement.cpp @@ -76,7 +76,6 @@ FixNonaffineDisplacement::FixNonaffineDisplacement(LAMMPS *lmp, int narg, char * int iarg = 4; if (strcmp(arg[iarg], "integrated") == 0) { nad_style = INTEGRATED; - nevery = 1; iarg += 1; } else if (strcmp(arg[iarg], "d2min") == 0) { if (iarg + 1 > narg) utils::missing_cmd_args(FLERR,"fix nonaffine/displacement d2min", error); @@ -108,7 +107,7 @@ FixNonaffineDisplacement::FixNonaffineDisplacement(LAMMPS *lmp, int narg, char * } else if (strcmp(arg[iarg], "update") == 0) { reference_style = UPDATE; update_timestep = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); - if (update_timestep < 0) + if (update_timestep <= 0) error->all(FLERR, "Illegal update timestep {} in fix nonaffine/displacement", arg[iarg + 1]); } else if (strcmp(arg[iarg], "offset") == 0) { reference_style = OFFSET; @@ -121,9 +120,6 @@ FixNonaffineDisplacement::FixNonaffineDisplacement(LAMMPS *lmp, int narg, char * if (cut_style == RADIUS && (!atom->radius_flag)) error->all(FLERR, "Fix nonaffine/displacement radius style requires atom attribute radius"); - if (nad_style == INTEGRATED && reference_style == OFFSET) - error->all(FLERR, "Fix nonaffine/displacement cannot use the integrated style with an offset reference state"); - peratom_flag = 1; peratom_freq = nevery; nmax = -1; @@ -154,8 +150,9 @@ FixNonaffineDisplacement::~FixNonaffineDisplacement() memory->destroy(F); memory->destroy(norm); memory->destroy(D2min); - memory->destroy(array_atom); } + + memory->destroy(array_atom); } /* ---------------------------------------------------------------------- */ @@ -179,11 +176,7 @@ void FixNonaffineDisplacement::post_constructor() id_fix = utils::strdup(id + std::string("_FIX_PA")); fix = dynamic_cast(modify->add_fix(fmt::format("{} {} STORE/ATOM 3 0 {} 1", id_fix, group->names[igroup], ghost_status))); - array_atom = fix->astore; - - if (nad_style == D2MIN) - grow_arrays(atom->nmax); - + grow_arrays(atom->nmax); for (int i = 0; i < atom->nlocal; i++) for (int j = 0; j < 3; j++) array_atom[i][j] = 0.0; } @@ -251,6 +244,15 @@ void FixNonaffineDisplacement::post_force(int /*vflag*/) if (reference_saved && (!update->setupflag)) { if (nad_style == INTEGRATED) { integrate_velocity(); + if ((update->ntimestep % nevery) == 0) { + if (atom->nmax > nmax) + grow_arrays(atom->nmax); + + double **x_nonaffine = fix->astore; + for (int i = 0; i < atom->nlocal; i++) + for (int m = 0; m < 3; m++) + array_atom[i][m] = x_nonaffine[i][m]; + } } else { if ((update->ntimestep % nevery) == 0) calculate_D2Min(); } @@ -306,8 +308,6 @@ void FixNonaffineDisplacement::integrate_velocity() } } } - - array_atom = x_nonaffine; } /* ---------------------------------------------------------------------- */ @@ -733,16 +733,18 @@ void FixNonaffineDisplacement::minimum_image0(double *delta) void FixNonaffineDisplacement::grow_arrays(int nmax_new) { nmax = nmax_new; - memory->destroy(X); - memory->destroy(Y); - memory->destroy(F); - memory->destroy(D2min); - memory->destroy(norm); memory->destroy(array_atom); - memory->create(X, nmax, 3, 3, "fix_nonaffine_displacement:X"); - memory->create(Y, nmax, 3, 3, "fix_nonaffine_displacement:Y"); - memory->create(F, nmax, 3, 3, "fix_nonaffine_displacement:F"); - memory->create(D2min, nmax, "fix_nonaffine_displacement:D2min"); - memory->create(norm, nmax, "fix_nonaffine_displacement:norm"); - memory->create(array_atom, nmax, "fix_nonaffine_displacement:array_atom"); + memory->create(array_atom, nmax, 3, "fix_nonaffine_displacement:array_atom"); + if (nad_style == D2MIN) { + memory->destroy(X); + memory->destroy(Y); + memory->destroy(F); + memory->destroy(D2min); + memory->destroy(norm); + memory->create(X, nmax, 3, 3, "fix_nonaffine_displacement:X"); + memory->create(Y, nmax, 3, 3, "fix_nonaffine_displacement:Y"); + memory->create(F, nmax, 3, 3, "fix_nonaffine_displacement:F"); + memory->create(D2min, nmax, "fix_nonaffine_displacement:D2min"); + memory->create(norm, nmax, "fix_nonaffine_displacement:norm"); + } } From ad55bb4b8f6d4abe23ff4c6a7d4d7b145bab460d Mon Sep 17 00:00:00 2001 From: Ludwig Ahrens Date: Tue, 5 Mar 2024 09:57:09 +0100 Subject: [PATCH 176/185] Mention CMake in electrode README --- src/ELECTRODE/README | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ELECTRODE/README b/src/ELECTRODE/README index 56894943a0..72a95b7fe9 100644 --- a/src/ELECTRODE/README +++ b/src/ELECTRODE/README @@ -7,8 +7,10 @@ See the doc page for the fix electrode/conp command to get started. There are example scripts for using this package in examples/PACKAGES/electrode. This package uses an external library in lib/electrode which must be compiled -before making LAMMPS. See the doc page on "Packages with extra build options" -for more information. +before making LAMMPS. For a CMake build, the location of the LAPACK library +should be linked automatically. Alternatively, the "USE_INTERNAL_LINALG" option +can be used to enable the bundled library. See the doc page on "Packages with +extra build options" for more information. The primary people who created this package are Ludwig Ahrens-Iwers, Shern Tee (s.tee@griffith.edu.au) and Robert Meißner (robert.meissner@tuhh.de). Contact From e0c0b2fe7e683b6600a46e3dc5cb7874361fe70f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 5 Mar 2024 15:28:21 -0500 Subject: [PATCH 177/185] fix cmake syntax error --- cmake/presets/kokkos-hip.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/presets/kokkos-hip.cmake b/cmake/presets/kokkos-hip.cmake index ffc259a225..38bf27092f 100644 --- a/cmake/presets/kokkos-hip.cmake +++ b/cmake/presets/kokkos-hip.cmake @@ -13,7 +13,7 @@ set(CMAKE_CXX_COMPILER hipcc CACHE STRING "" FORCE) set(CMAKE_TUNE_FLAGS "-munsafe-fp-atomics" CACHE STRING "" FORCE) # If KSPACE is also enabled, use CUFFT for FFTs -set(FFT_KOKKOS "HIPFFT" CACHE STRING FORCE) +set(FFT_KOKKOS "HIPFFT" CACHE STRING "" FORCE) # hide deprecation warnings temporarily for stable release set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE) From 0dc6e156c131e8207a064d5bfac9e6f7eb438599 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 5 Mar 2024 18:24:38 -0500 Subject: [PATCH 178/185] add balance styles shift/report and rcb/report for reporting imbalances only --- doc/src/fix_balance.rst | 13 ++++++++++--- src/fix_balance.cpp | 26 +++++++++++++++++++++----- src/fix_balance.h | 1 + 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/doc/src/fix_balance.rst b/doc/src/fix_balance.rst index 0672a05470..83be726ba7 100644 --- a/doc/src/fix_balance.rst +++ b/doc/src/fix_balance.rst @@ -14,15 +14,15 @@ Syntax * balance = style name of this fix command * Nfreq = perform dynamic load balancing every this many steps * thresh = imbalance threshold that must be exceeded to perform a re-balance -* style = *shift* or *rcb* +* style = *shift* *shift/report* or *rcb* or *rcb/report* .. parsed-literal:: - shift args = dimstr Niter stopthresh + *shift* or *shift/report* args = dimstr Niter stopthresh dimstr = sequence of letters containing *x* or *y* or *z*, each not more than once Niter = # of times to iterate within each dimension of dimstr sequence stopthresh = stop balancing when this imbalance threshold is reached - *rcb* args = none + *rcb* or *rcb/report* args = none * zero or more keyword/arg pairs may be appended * keyword = *weight* or *out* @@ -70,6 +70,13 @@ re-balancing is performed periodically during the simulation. To perform "static" balancing, before or between runs, see the :doc:`balance ` command. +.. versionadded:: TBD + +The *shift/report* and *rcb/report* styles only compute the +load imbalance but do not attempt any re-balancing. This way +the load imbalance information can be used otherwise, for +instance for stopping a run with :doc:`fix halt `. + Load-balancing is typically most useful if the particles in the simulation box have a spatially-varying density distribution or where the computational cost varies significantly between different diff --git a/src/fix_balance.cpp b/src/fix_balance.cpp index 23a56c0a9d..76b71aafa9 100644 --- a/src/fix_balance.cpp +++ b/src/fix_balance.cpp @@ -61,9 +61,18 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) : if (nevery < 0) error->all(FLERR,"Illegal fix balance command"); thresh = utils::numeric(FLERR,arg[4],false,lmp); - if (strcmp(arg[5],"shift") == 0) lbstyle = SHIFT; - else if (strcmp(arg[5],"rcb") == 0) lbstyle = BISECTION; - else error->all(FLERR,"Illegal fix balance command"); + reportonly = 0; + if (strcmp(arg[5],"shift") == 0) { + lbstyle = SHIFT; + } else if (strcmp(arg[5],"shift/report") == 0) { + lbstyle = SHIFT; + reportonly = 1; + } else if (strcmp(arg[5],"rcb") == 0) { + lbstyle = BISECTION; + } else if (strcmp(arg[5],"rcb/report") == 0) { + lbstyle = BISECTION; + reportonly = 1; + } else error->all(FLERR,"Unknown fix balance style {}", arg[5]); int iarg = 5; if (lbstyle == SHIFT) { @@ -75,7 +84,6 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) : stopthresh = utils::numeric(FLERR,arg[iarg+3],false,lmp); if (stopthresh < 1.0) error->all(FLERR,"Illegal fix balance command"); iarg += 4; - } else if (lbstyle == BISECTION) { iarg++; } @@ -175,7 +183,7 @@ void FixBalance::setup(int /*vflag*/) void FixBalance::setup_pre_exchange() { // do not allow rebalancing twice on same timestep - // even if wanted to, can mess up elapsed time in ImbalanceTime + // even if you wanted to, it can mess up elapsed time in ImbalanceTime if (update->ntimestep == lastbalance) return; lastbalance = update->ntimestep; @@ -195,6 +203,7 @@ void FixBalance::setup_pre_exchange() balance->set_weights(); imbnow = balance->imbalance_factor(maxloadperproc); + if (imbnow > thresh) rebalance(); // next timestep to rebalance @@ -263,6 +272,13 @@ void FixBalance::pre_neighbor() void FixBalance::rebalance() { + // return immediately if only reporting of the imbalance is requested + + if (reportonly) { + imbprev = imbfinal = imbnow; + return; + } + imbprev = imbnow; // invoke balancer and reset comm->uniform flag diff --git a/src/fix_balance.h b/src/fix_balance.h index 964357a634..a319710ac6 100644 --- a/src/fix_balance.h +++ b/src/fix_balance.h @@ -45,6 +45,7 @@ class FixBalance : public Fix { std::string bstr; int wtflag; // 1 for weighted balancing int sortflag; // 1 for sorting comm messages + int reportonly; // 1 if skipping rebalancing and only computing imbalance double imbnow; // current imbalance factor double imbprev; // imbalance factor before last rebalancing From 7e8b24389149ced94053a5ac32623c26e46781e9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 5 Mar 2024 18:26:41 -0500 Subject: [PATCH 179/185] make use of ..versionadded/..versionchanged consistent with the rest of LAMMPS --- doc/src/fix_electrode.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/src/fix_electrode.rst b/doc/src/fix_electrode.rst index 3759ff23ca..8a7a44454d 100644 --- a/doc/src/fix_electrode.rst +++ b/doc/src/fix_electrode.rst @@ -253,7 +253,7 @@ be enabled if any electrode particle has the same type as any electrolyte particle (which would be unusual in a typical simulation) and the fix will issue an error in that case. -.. versionchanged:: qtotal +.. versionadded:: TBD The keyword *qtotal* causes *fix electrode/conp* and *fix electrode/thermo* to add an overall potential to all electrodes so that the total charge on @@ -266,6 +266,8 @@ individual electrodes, and since *symm on* constrains the total charge of all electrodes to be zero, either option is incompatible with the *qtotal* keyword (even if *qtotal* is set to zero). +.. versionadded:: TBD + The keyword *eta* takes the name of a custom double vector defined via fix property/atom. The values will be used instead of the standard eta value. The property/atom fix must be for vector of double values and use the *ghost on* From 20d95cd17feb8d494f92dbf1e5602491b0f1d7eb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 5 Mar 2024 18:30:07 -0500 Subject: [PATCH 180/185] whitespace --- src/fix_balance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_balance.cpp b/src/fix_balance.cpp index 76b71aafa9..ae1d00db8f 100644 --- a/src/fix_balance.cpp +++ b/src/fix_balance.cpp @@ -278,7 +278,7 @@ void FixBalance::rebalance() imbprev = imbfinal = imbnow; return; } - + imbprev = imbnow; // invoke balancer and reset comm->uniform flag From ea526998932aa949bad96b1e5fac5e8151bd703d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 5 Mar 2024 19:00:50 -0500 Subject: [PATCH 181/185] collapse the two /report styles into a single "report" style --- doc/src/fix_balance.rst | 16 ++++++++-------- src/fix_balance.cpp | 34 +++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/doc/src/fix_balance.rst b/doc/src/fix_balance.rst index 83be726ba7..0a0ea64c6a 100644 --- a/doc/src/fix_balance.rst +++ b/doc/src/fix_balance.rst @@ -14,15 +14,15 @@ Syntax * balance = style name of this fix command * Nfreq = perform dynamic load balancing every this many steps * thresh = imbalance threshold that must be exceeded to perform a re-balance -* style = *shift* *shift/report* or *rcb* or *rcb/report* - +* style = *shift* or *rcb* or *report* .. parsed-literal:: - *shift* or *shift/report* args = dimstr Niter stopthresh + *shift* args = dimstr Niter stopthresh dimstr = sequence of letters containing *x* or *y* or *z*, each not more than once Niter = # of times to iterate within each dimension of dimstr sequence stopthresh = stop balancing when this imbalance threshold is reached - *rcb* or *rcb/report* args = none + *rcb* args = none + *report* args = none * zero or more keyword/arg pairs may be appended * keyword = *weight* or *out* @@ -72,10 +72,10 @@ perform "static" balancing, before or between runs, see the .. versionadded:: TBD -The *shift/report* and *rcb/report* styles only compute the -load imbalance but do not attempt any re-balancing. This way -the load imbalance information can be used otherwise, for -instance for stopping a run with :doc:`fix halt `. +The *report* balance style only computes the load imbalance but +does not attempt any re-balancing. This way the load imbalance +information can be used otherwise, for instance for stopping a +run with :doc:`fix halt `. Load-balancing is typically most useful if the particles in the simulation box have a spatially-varying density distribution or diff --git a/src/fix_balance.cpp b/src/fix_balance.cpp index ae1d00db8f..2a32e96106 100644 --- a/src/fix_balance.cpp +++ b/src/fix_balance.cpp @@ -64,26 +64,34 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) : reportonly = 0; if (strcmp(arg[5],"shift") == 0) { lbstyle = SHIFT; - } else if (strcmp(arg[5],"shift/report") == 0) { - lbstyle = SHIFT; - reportonly = 1; } else if (strcmp(arg[5],"rcb") == 0) { lbstyle = BISECTION; - } else if (strcmp(arg[5],"rcb/report") == 0) { - lbstyle = BISECTION; + } else if (strcmp(arg[5],"report") == 0) { + lbstyle = SHIFT; reportonly = 1; } else error->all(FLERR,"Unknown fix balance style {}", arg[5]); int iarg = 5; if (lbstyle == SHIFT) { - if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix balance shift", error); - bstr = arg[iarg+1]; - if (bstr.size() > Balance::BSTR_SIZE) error->all(FLERR,"Illegal fix balance shift command"); - nitermax = utils::inumeric(FLERR,arg[iarg+2],false,lmp); - if (nitermax <= 0) error->all(FLERR,"Illegal fix balance command"); - stopthresh = utils::numeric(FLERR,arg[iarg+3],false,lmp); - if (stopthresh < 1.0) error->all(FLERR,"Illegal fix balance command"); - iarg += 4; + if (reportonly) { + if (dimension == 2) + bstr = "xy"; + else + bstr = "xyz"; + nitermax = 5; + stopthresh = 1.1; + iarg++; + } else { + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "fix balance shift", error); + bstr = arg[iarg+1]; + if (bstr.size() > Balance::BSTR_SIZE) error->all(FLERR,"Illegal fix balance shift command"); + nitermax = utils::inumeric(FLERR,arg[iarg+2],false,lmp); + if (nitermax <= 0) error->all(FLERR,"Illegal fix balance command"); + stopthresh = utils::numeric(FLERR,arg[iarg+3],false,lmp); + if (stopthresh < 1.0) error->all(FLERR,"Illegal fix balance command"); + iarg += 4; + } + } else if (lbstyle == BISECTION) { iarg++; } From c984d5c94a88acf0b839393b096b65e21202a04d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 6 Mar 2024 11:13:50 -0500 Subject: [PATCH 182/185] improved revision of write_dump output frequency setting for 64-bit timesteps --- src/write_dump.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/write_dump.cpp b/src/write_dump.cpp index 0418d7c424..8cd7dec88e 100644 --- a/src/write_dump.cpp +++ b/src/write_dump.cpp @@ -47,7 +47,8 @@ void WriteDump::command(int narg, char **arg) // work around "fix not computed at compatible times" errors. - const int dumpfreq = MAX(1, update->nsteps); + int dumpfreq = MAX(1, update->nsteps); + dumpfreq += update->ntimestep % dumpfreq; auto dumpargs = new char *[modindex + 2]; dumpargs[0] = (char *) "WRITE_DUMP"; // dump id From 6cc9a4c7b74913fb7673cf276a9d3f63daaf96df Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Wed, 6 Mar 2024 14:58:06 -0700 Subject: [PATCH 183/185] Update Kokkos library in LAMMPS to v4.2.1 --- lib/kokkos/CHANGELOG.md | 25 +++++++++++++++++-- lib/kokkos/CMakeLists.txt | 11 +------- lib/kokkos/Makefile.kokkos | 11 ++++++-- .../unit_tests/TestStdAlgorithmsCommon.hpp | 5 ++-- .../TestStdAlgorithmsTeamCopyIf.cpp | 2 +- .../TestStdAlgorithmsTeamIsPartitioned.cpp | 2 +- .../TestStdAlgorithmsTeamPartitionCopy.cpp | 2 +- .../TestStdAlgorithmsTeamPartitionPoint.cpp | 2 +- .../TestStdAlgorithmsTeamRemoveCopyIf.cpp | 2 +- .../TestStdAlgorithmsTeamRemoveIf.cpp | 2 +- .../TestStdAlgorithmsTeamReplaceCopyIf.cpp | 2 +- .../TestStdAlgorithmsTeamReplaceIf.cpp | 2 +- lib/kokkos/cmake/KokkosCore_config.h.in | 1 + lib/kokkos/cmake/kokkos_arch.cmake | 6 ++--- .../src/Cuda/Kokkos_Cuda_Parallel_MDRange.hpp | 5 ++++ .../src/Cuda/Kokkos_Cuda_Parallel_Range.hpp | 6 +++++ .../src/Cuda/Kokkos_Cuda_Parallel_Team.hpp | 5 ++++ .../core/src/HIP/Kokkos_HIP_Graph_Impl.hpp | 20 +++++++-------- .../core/src/HIP/Kokkos_HIP_Instance.hpp | 3 ++- lib/kokkos/core/src/Kokkos_HostSpace.hpp | 19 +++++++++----- lib/kokkos/core/src/Kokkos_Printf.hpp | 2 +- .../src/OpenMP/Kokkos_OpenMP_Instance.cpp | 2 -- .../src/OpenMP/Kokkos_OpenMP_Instance.hpp | 2 ++ lib/kokkos/core/src/Serial/Kokkos_Serial.cpp | 2 -- lib/kokkos/core/src/Serial/Kokkos_Serial.hpp | 1 + .../core/src/Threads/Kokkos_ThreadsExec.cpp | 2 -- .../unit_test/TestMathematicalFunctions.hpp | 25 +++++++++++++------ .../core/unit_test/TestNumericTraits.hpp | 4 +-- lib/kokkos/generate_makefile.bash | 1 + lib/kokkos/master_history.txt | 1 + lib/kokkos/simd/src/Kokkos_SIMD_Scalar.hpp | 8 +++--- .../include/TestSIMD_GeneratorCtors.hpp | 2 ++ 32 files changed, 121 insertions(+), 64 deletions(-) diff --git a/lib/kokkos/CHANGELOG.md b/lib/kokkos/CHANGELOG.md index c6115f4b3d..40e3c95f24 100644 --- a/lib/kokkos/CHANGELOG.md +++ b/lib/kokkos/CHANGELOG.md @@ -1,5 +1,26 @@ # CHANGELOG +## [4.2.01](https://github.com/kokkos/kokkos/tree/4.2.01) (2023-12-07) +[Full Changelog](https://github.com/kokkos/kokkos/compare/4.2.00...4.2.01) + +### Backend and Architecture Enhancements: + +#### CUDA: +- Add warp sync for `parallel_reduce` to avoid race condition [\#6630](https://github.com/kokkos/kokkos/pull/6630), [\#6746](https://github.com/kokkos/kokkos/pull/6746) + +#### HIP: +- Fix Graph "multiple definition of" linking error (missing `inline` specifier) [\#6624](https://github.com/kokkos/kokkos/pull/6624) +- Add support for gfx940 (AMD Instinct MI300 GPU) [\#6671](https://github.com/kokkos/kokkos/pull/6671) + +### Build System +- CMake: Don't let Kokkos set `CMAKE_CXX_FLAGS` for Trilinos builds [\#6742](https://github.com/kokkos/kokkos/pull/6742) + +### Bug Fixes +- Remove deprecation warning for `AllocationMechanism` for GCC <11.0 [\#6653](https://github.com/kokkos/kokkos/pull/6653) +- Fix bug early tools finalize with non-default host execution instances [\#6635](https://github.com/kokkos/kokkos/pull/6635) +- Fix various issues for MSVC CUDA builds [\#6659](https://github.com/kokkos/kokkos/pull/6659) +- Fix "extra `;`" warning with `-pedantic` flag in `` [\#6510](https://github.com/kokkos/kokkos/pull/6510) + ## [4.2.00](https://github.com/kokkos/kokkos/tree/4.2.00) (2023-11-06) [Full Changelog](https://github.com/kokkos/kokkos/compare/4.1.00...4.2.00) @@ -43,7 +64,7 @@ #### SYCL: - Enforce external `sycl::queues` to be in-order [\#6246](https://github.com/kokkos/kokkos/pull/6246) -- Improve reduction performance: [\#6272](https://github.com/kokkos/kokkos/pull/6272) [\#6271](https://github.com/kokkos/kokkos/pull/6271) [\#6270](https://github.com/kokkos/kokkos/pull/6270) [\#6264](https://github.com/kokkos/kokkos/pull/6264) +- Improve reduction performance: [\#6272](https://github.com/kokkos/kokkos/pull/6272) [\#6271](https://github.com/kokkos/kokkos/pull/6271) [\#6270](https://github.com/kokkos/kokkos/pull/6270) [\#6264](https://github.com/kokkos/kokkos/pull/6264) - Allow using the SYCL execution space on AMD GPUs [\#6321](https://github.com/kokkos/kokkos/pull/6321) - Allow sorting via native oneDPL to support Views with stride=1 [\#6322](https://github.com/kokkos/kokkos/pull/6322) - Make in-order queues the default via macro [\#6189](https://github.com/kokkos/kokkos/pull/6189) @@ -64,7 +85,7 @@ - Add converting assignment to `DualView`: [\#6474](https://github.com/kokkos/kokkos/pull/6474) -### Build System Changes +### Build System Changes - Export `Kokkos_CXX_COMPILER_VERSION` [\#6282](https://github.com/kokkos/kokkos/pull/6282) - Disable default oneDPL support in Trilinos [\#6342](https://github.com/kokkos/kokkos/pull/6342) diff --git a/lib/kokkos/CMakeLists.txt b/lib/kokkos/CMakeLists.txt index f6bd81058e..4a4e7a5501 100644 --- a/lib/kokkos/CMakeLists.txt +++ b/lib/kokkos/CMakeLists.txt @@ -151,7 +151,7 @@ ENDIF() set(Kokkos_VERSION_MAJOR 4) set(Kokkos_VERSION_MINOR 2) -set(Kokkos_VERSION_PATCH 0) +set(Kokkos_VERSION_PATCH 1) set(Kokkos_VERSION "${Kokkos_VERSION_MAJOR}.${Kokkos_VERSION_MINOR}.${Kokkos_VERSION_PATCH}") message(STATUS "Kokkos version: ${Kokkos_VERSION}") math(EXPR KOKKOS_VERSION "${Kokkos_VERSION_MAJOR} * 10000 + ${Kokkos_VERSION_MINOR} * 100 + ${Kokkos_VERSION_PATCH}") @@ -252,7 +252,6 @@ ENDIF() # subpackages ## This restores the old behavior of ProjectCompilerPostConfig.cmake -# It sets the CMAKE_CXX_FLAGS globally to those used by Kokkos # We must do this before KOKKOS_PACKAGE_DECL IF (KOKKOS_HAS_TRILINOS) # Overwrite the old flags at the top-level @@ -280,21 +279,13 @@ IF (KOKKOS_HAS_TRILINOS) SET(KOKKOSCORE_XCOMPILER_OPTIONS "${KOKKOSCORE_XCOMPILER_OPTIONS} -Xcompiler ${XCOMP_FLAG}") LIST(APPEND KOKKOS_ALL_COMPILE_OPTIONS -Xcompiler ${XCOMP_FLAG}) ENDFOREACH() - SET(KOKKOSCORE_CXX_FLAGS "${KOKKOSCORE_COMPILE_OPTIONS} ${KOKKOSCORE_XCOMPILER_OPTIONS}") IF (KOKKOS_ENABLE_CUDA) STRING(REPLACE ";" " " KOKKOSCORE_CUDA_OPTIONS "${KOKKOS_CUDA_OPTIONS}") FOREACH(CUDAFE_FLAG ${KOKKOS_CUDAFE_OPTIONS}) SET(KOKKOSCORE_CUDAFE_OPTIONS "${KOKKOSCORE_CUDAFE_OPTIONS} -Xcudafe ${CUDAFE_FLAG}") LIST(APPEND KOKKOS_ALL_COMPILE_OPTIONS -Xcudafe ${CUDAFE_FLAG}) ENDFOREACH() - SET(KOKKOSCORE_CXX_FLAGS "${KOKKOSCORE_CXX_FLAGS} ${KOKKOSCORE_CUDA_OPTIONS} ${KOKKOSCORE_CUDAFE_OPTIONS}") ENDIF() - # Both parent scope and this package - # In ProjectCompilerPostConfig.cmake, we capture the "global" flags Trilinos wants in - # TRILINOS_TOPLEVEL_CXX_FLAGS - SET(CMAKE_CXX_FLAGS "${TRILINOS_TOPLEVEL_CXX_FLAGS} ${KOKKOSCORE_CXX_FLAGS}" PARENT_SCOPE) - SET(CMAKE_CXX_FLAGS "${TRILINOS_TOPLEVEL_CXX_FLAGS} ${KOKKOSCORE_CXX_FLAGS}") - #CMAKE_CXX_FLAGS will get added to Kokkos and Kokkos dependencies automatically here #These flags get set up in KOKKOS_PACKAGE_DECL, which means they #must be configured before KOKKOS_PACKAGE_DECL SET(KOKKOS_ALL_COMPILE_OPTIONS diff --git a/lib/kokkos/Makefile.kokkos b/lib/kokkos/Makefile.kokkos index c970f72755..393422d73c 100644 --- a/lib/kokkos/Makefile.kokkos +++ b/lib/kokkos/Makefile.kokkos @@ -12,7 +12,7 @@ endif KOKKOS_VERSION_MAJOR = 4 KOKKOS_VERSION_MINOR = 2 -KOKKOS_VERSION_PATCH = 0 +KOKKOS_VERSION_PATCH = 1 KOKKOS_VERSION = $(shell echo $(KOKKOS_VERSION_MAJOR)*10000+$(KOKKOS_VERSION_MINOR)*100+$(KOKKOS_VERSION_PATCH) | bc) # Options: Cuda,HIP,SYCL,OpenMPTarget,OpenMP,Threads,Serial @@ -23,7 +23,7 @@ KOKKOS_DEVICES ?= "OpenMP" # NVIDIA: Kepler,Kepler30,Kepler32,Kepler35,Kepler37,Maxwell,Maxwell50,Maxwell52,Maxwell53,Pascal60,Pascal61,Volta70,Volta72,Turing75,Ampere80,Ampere86,Ada89,Hopper90 # ARM: ARMv80,ARMv81,ARMv8-ThunderX,ARMv8-TX2,A64FX # IBM: BGQ,Power7,Power8,Power9 -# AMD-GPUS: GFX906,GFX908,GFX90A,GFX942,GFX1030,GFX1100 +# AMD-GPUS: GFX906,GFX908,GFX90A,GFX940,GFX942,GFX1030,GFX1100 # AMD-CPUS: AMDAVX,Zen,Zen2,Zen3 # Intel-GPUs: Gen9,Gen11,Gen12LP,DG1,XeHP,PVC KOKKOS_ARCH ?= "" @@ -416,6 +416,8 @@ endif KOKKOS_INTERNAL_USE_ARCH_AMD_GFX906 := $(or $(call kokkos_has_string,$(KOKKOS_ARCH),VEGA906),$(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX906)) KOKKOS_INTERNAL_USE_ARCH_AMD_GFX908 := $(or $(call kokkos_has_string,$(KOKKOS_ARCH),VEGA908),$(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX908)) KOKKOS_INTERNAL_USE_ARCH_AMD_GFX90A := $(or $(call kokkos_has_string,$(KOKKOS_ARCH),VEGA90A),$(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX90A)) +KOKKOS_INTERNAL_USE_ARCH_AMD_GFX940 := $(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX940) +KOKKOS_INTERNAL_USE_ARCH_AMD_GFX942 := $(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX942) KOKKOS_INTERNAL_USE_ARCH_AMD_GFX1030 := $(or $(call kokkos_has_string,$(KOKKOS_ARCH),NAVI1030),$(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX1030)) KOKKOS_INTERNAL_USE_ARCH_AMD_GFX1100 := $(or $(call kokkos_has_string,$(KOKKOS_ARCH),NAVI1100),$(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX1100)) @@ -1113,6 +1115,11 @@ ifeq ($(KOKKOS_INTERNAL_USE_ARCH_AMD_GFX90A), 1) tmp := $(call kokkos_append_header,"$H""define KOKKOS_ARCH_AMD_GPU") KOKKOS_INTERNAL_HIP_ARCH_FLAG := --offload-arch=gfx90a endif +ifeq ($(KOKKOS_INTERNAL_USE_ARCH_AMD_GFX940), 1) + tmp := $(call kokkos_append_header,"$H""define KOKKOS_ARCH_AMD_GFX940") + tmp := $(call kokkos_append_header,"$H""define KOKKOS_ARCH_AMD_GPU") + KOKKOS_INTERNAL_HIP_ARCH_FLAG := --offload-arch=gfx940 +endif ifeq ($(KOKKOS_INTERNAL_USE_ARCH_AMD_GFX942), 1) tmp := $(call kokkos_append_header,"$H""define KOKKOS_ARCH_AMD_GFX942") tmp := $(call kokkos_append_header,"$H""define KOKKOS_ARCH_AMD_GPU") diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCommon.hpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCommon.hpp index b962218b5f..3eb963faf2 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCommon.hpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCommon.hpp @@ -198,8 +198,9 @@ auto create_deep_copyable_compatible_view_with_same_extent(ViewType view) { // this is needed for intel to avoid // error #1011: missing return statement at end of non-void function -#if defined KOKKOS_COMPILER_INTEL || \ - (defined(KOKKOS_COMPILER_NVCC) && KOKKOS_COMPILER_NVCC >= 1130) +#if defined KOKKOS_COMPILER_INTEL || \ + (defined(KOKKOS_COMPILER_NVCC) && KOKKOS_COMPILER_NVCC >= 1130 && \ + !defined(KOKKOS_COMPILER_MSVC)) __builtin_unreachable(); #endif } diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamCopyIf.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamCopyIf.cpp index b32a9be3a1..b5aa27c7c3 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamCopyIf.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamCopyIf.cpp @@ -139,7 +139,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { auto intraTeamSentinelView_h = create_host_space_copy(intraTeamSentinelView); Kokkos::View stdDestView("stdDestView", numTeams, numCols); - GreaterThanValueFunctor predicate(threshold); + GreaterThanValueFunctor predicate(threshold); for (std::size_t i = 0; i < sourceView.extent(0); ++i) { auto rowFrom = Kokkos::subview(sourceViewBeforeOp_h, i, Kokkos::ALL()); auto rowDest = Kokkos::subview(stdDestView, i, Kokkos::ALL()); diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamIsPartitioned.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamIsPartitioned.cpp index 1928f95588..21da333e75 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamIsPartitioned.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamIsPartitioned.cpp @@ -191,7 +191,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId, // ----------------------------------------------- auto returnView_h = create_host_space_copy(returnView); auto intraTeamSentinelView_h = create_host_space_copy(intraTeamSentinelView); - GreaterThanValueFunctor predicate(threshold); + GreaterThanValueFunctor predicate(threshold); for (std::size_t i = 0; i < dataView_dc_h.extent(0); ++i) { auto myRow = Kokkos::subview(dataView_dc_h, i, Kokkos::ALL()); diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamPartitionCopy.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamPartitionCopy.cpp index c0bbdfa390..78ab6bf1f8 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamPartitionCopy.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamPartitionCopy.cpp @@ -240,7 +240,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId, "stdDestTrueView", numTeams, numCols); Kokkos::View stdDestFalseView( "stdDestFalseView", numTeams, numCols); - GreaterThanValueFunctor predicate(threshold); + GreaterThanValueFunctor predicate(threshold); for (std::size_t i = 0; i < sourceView_dc_h.extent(0); ++i) { auto myRowSource = Kokkos::subview(sourceView_dc_h, i, Kokkos::ALL()); diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamPartitionPoint.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamPartitionPoint.cpp index 954d461246..370e91cc1f 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamPartitionPoint.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamPartitionPoint.cpp @@ -197,7 +197,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId, auto distancesView_h = create_host_space_copy(distancesView); auto dataViewAfterOp_h = create_host_space_copy(dataView); auto intraTeamSentinelView_h = create_host_space_copy(intraTeamSentinelView); - GreaterThanValueFunctor predicate(threshold); + GreaterThanValueFunctor predicate(threshold); for (std::size_t i = 0; i < dataView_dc_h.extent(0); ++i) { auto myRow = Kokkos::subview(dataView_dc_h, i, Kokkos::ALL()); diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamRemoveCopyIf.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamRemoveCopyIf.cpp index 2082fa9728..ce18eb4d31 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamRemoveCopyIf.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamRemoveCopyIf.cpp @@ -138,7 +138,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { auto intraTeamSentinelView_h = create_host_space_copy(intraTeamSentinelView); Kokkos::View stdDestView("stdDestView", numTeams, numCols); - GreaterThanValueFunctor predicate(threshold); + GreaterThanValueFunctor predicate(threshold); for (std::size_t i = 0; i < destViewAfterOp_h.extent(0); ++i) { auto rowFrom = Kokkos::subview(cloneOfSourceViewBeforeOp_h, i, Kokkos::ALL()); diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamRemoveIf.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamRemoveIf.cpp index 3315f281da..3dd7cb764c 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamRemoveIf.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamRemoveIf.cpp @@ -127,7 +127,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { // ----------------------------------------------- // check against std // ----------------------------------------------- - GreaterThanValueFunctor predicate(threshold); + GreaterThanValueFunctor predicate(threshold); auto dataViewAfterOp_h = create_host_space_copy(dataView); auto distancesView_h = create_host_space_copy(distancesView); auto intraTeamSentinelView_h = create_host_space_copy(intraTeamSentinelView); diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReplaceCopyIf.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReplaceCopyIf.cpp index ae43a2a426..d0217aed7a 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReplaceCopyIf.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReplaceCopyIf.cpp @@ -145,7 +145,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { auto intraTeamSentinelView_h = create_host_space_copy(intraTeamSentinelView); Kokkos::View stdDestView("stdDestView", numTeams, numCols); - GreaterThanValueFunctor predicate(threshold); + GreaterThanValueFunctor predicate(threshold); for (std::size_t i = 0; i < sourceView.extent(0); ++i) { auto rowFrom = Kokkos::subview(cloneOfSourceViewBeforeOp_h, i, Kokkos::ALL()); diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReplaceIf.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReplaceIf.cpp index 1d5d9578f9..d79b53d355 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReplaceIf.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReplaceIf.cpp @@ -103,7 +103,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { stdDataView(i, j) = cloneOfDataViewBeforeOp_h(i, j); } } - GreaterThanValueFunctor predicate(threshold); + GreaterThanValueFunctor predicate(threshold); for (std::size_t i = 0; i < dataView.extent(0); ++i) { auto thisRow = Kokkos::subview(stdDataView, i, Kokkos::ALL()); std::replace_if(KE::begin(thisRow), KE::end(thisRow), predicate, newVal); diff --git a/lib/kokkos/cmake/KokkosCore_config.h.in b/lib/kokkos/cmake/KokkosCore_config.h.in index bec59ebd03..9930d2abf0 100644 --- a/lib/kokkos/cmake/KokkosCore_config.h.in +++ b/lib/kokkos/cmake/KokkosCore_config.h.in @@ -114,6 +114,7 @@ #cmakedefine KOKKOS_ARCH_AMD_GFX906 #cmakedefine KOKKOS_ARCH_AMD_GFX908 #cmakedefine KOKKOS_ARCH_AMD_GFX90A +#cmakedefine KOKKOS_ARCH_AMD_GFX940 #cmakedefine KOKKOS_ARCH_AMD_GFX942 #cmakedefine KOKKOS_ARCH_AMD_GFX1030 #cmakedefine KOKKOS_ARCH_AMD_GFX1100 diff --git a/lib/kokkos/cmake/kokkos_arch.cmake b/lib/kokkos/cmake/kokkos_arch.cmake index bccf674d76..30764bde86 100644 --- a/lib/kokkos/cmake/kokkos_arch.cmake +++ b/lib/kokkos/cmake/kokkos_arch.cmake @@ -94,9 +94,9 @@ IF(Kokkos_ENABLE_HIP OR Kokkos_ENABLE_OPENMPTARGET OR Kokkos_ENABLE_OPENACC OR K ENDIF() # AMD archs ordered in decreasing priority of autodetection -LIST(APPEND SUPPORTED_AMD_GPUS MI300) -LIST(APPEND SUPPORTED_AMD_ARCHS AMD_GFX942) -LIST(APPEND CORRESPONDING_AMD_FLAGS gfx942) +LIST(APPEND SUPPORTED_AMD_GPUS MI300 MI300) +LIST(APPEND SUPPORTED_AMD_ARCHS AMD_GFX942 AMD_GFX940) +LIST(APPEND CORRESPONDING_AMD_FLAGS gfx942 gfx940) LIST(APPEND SUPPORTED_AMD_GPUS MI200 MI200 MI100 MI100) LIST(APPEND SUPPORTED_AMD_ARCHS VEGA90A AMD_GFX90A VEGA908 AMD_GFX908) LIST(APPEND CORRESPONDING_AMD_FLAGS gfx90a gfx90a gfx908 gfx908) diff --git a/lib/kokkos/core/src/Cuda/Kokkos_Cuda_Parallel_MDRange.hpp b/lib/kokkos/core/src/Cuda/Kokkos_Cuda_Parallel_MDRange.hpp index 8aae27d091..49d6c112e3 100644 --- a/lib/kokkos/core/src/Cuda/Kokkos_Cuda_Parallel_MDRange.hpp +++ b/lib/kokkos/core/src/Cuda/Kokkos_Cuda_Parallel_MDRange.hpp @@ -309,6 +309,11 @@ class ParallelReduce, if (CudaTraits::WarpSize < word_count.value) { __syncthreads(); + } else if (word_count.value > 1) { + // Inside cuda_single_inter_block_reduce_scan() above, shared[i] below + // might have been updated by a single thread within a warp without + // synchronization afterwards. Synchronize threads within warp to avoid + // potential racecondition. + __syncwarp(0xffffffff); } for (unsigned i = threadIdx.y; i < word_count.value; i += blockDim.y) { diff --git a/lib/kokkos/core/src/Cuda/Kokkos_Cuda_Parallel_Team.hpp b/lib/kokkos/core/src/Cuda/Kokkos_Cuda_Parallel_Team.hpp index 498e57f94a..b4679b4e0d 100644 --- a/lib/kokkos/core/src/Cuda/Kokkos_Cuda_Parallel_Team.hpp +++ b/lib/kokkos/core/src/Cuda/Kokkos_Cuda_Parallel_Team.hpp @@ -742,6 +742,11 @@ class ParallelReduce { hipGraphExec_t m_graph_exec = nullptr; }; -GraphImpl::~GraphImpl() { +inline GraphImpl::~GraphImpl() { m_execution_space.fence("Kokkos::GraphImpl::~GraphImpl: Graph Destruction"); KOKKOS_EXPECTS(m_graph); if (m_graph_exec) { @@ -92,12 +92,12 @@ GraphImpl::~GraphImpl() { KOKKOS_IMPL_HIP_SAFE_CALL(hipGraphDestroy(m_graph)); } -GraphImpl::GraphImpl(Kokkos::HIP instance) +inline GraphImpl::GraphImpl(Kokkos::HIP instance) : m_execution_space(std::move(instance)) { KOKKOS_IMPL_HIP_SAFE_CALL(hipGraphCreate(&m_graph, 0)); } -void GraphImpl::add_node( +inline void GraphImpl::add_node( std::shared_ptr const& arg_node_ptr) { // All of the predecessors are just added as normal, so all we need to // do here is add an empty node @@ -110,7 +110,7 @@ void GraphImpl::add_node( // Requires NodeImplPtr is a shared_ptr to specialization of GraphNodeImpl // Also requires that the kernel has the graph node tag in it's policy template -void GraphImpl::add_node( +inline void GraphImpl::add_node( std::shared_ptr const& arg_node_ptr) { static_assert(NodeImpl::kernel_type::Policy::is_graph_kernel::value); KOKKOS_EXPECTS(arg_node_ptr); @@ -129,8 +129,8 @@ void GraphImpl::add_node( // already been added to this graph and NodeImpl is a specialization of // GraphNodeImpl that has already been added to this graph. template -void GraphImpl::add_predecessor(NodeImplPtr arg_node_ptr, - PredecessorRef arg_pred_ref) { +inline void GraphImpl::add_predecessor( + NodeImplPtr arg_node_ptr, PredecessorRef arg_pred_ref) { KOKKOS_EXPECTS(arg_node_ptr); auto pred_ptr = GraphAccess::get_node_ptr(arg_pred_ref); KOKKOS_EXPECTS(pred_ptr); @@ -145,7 +145,7 @@ void GraphImpl::add_predecessor(NodeImplPtr arg_node_ptr, hipGraphAddDependencies(m_graph, &pred_node, &node, 1)); } -void GraphImpl::submit() { +inline void GraphImpl::submit() { if (!m_graph_exec) { instantiate_graph(); } @@ -153,12 +153,12 @@ void GraphImpl::submit() { hipGraphLaunch(m_graph_exec, m_execution_space.hip_stream())); } -Kokkos::HIP const& GraphImpl::get_execution_space() const +inline Kokkos::HIP const& GraphImpl::get_execution_space() const noexcept { return m_execution_space; } -auto GraphImpl::create_root_node_ptr() { +inline auto GraphImpl::create_root_node_ptr() { KOKKOS_EXPECTS(m_graph); KOKKOS_EXPECTS(!m_graph_exec); auto rv = std::make_shared(get_execution_space(), @@ -172,7 +172,7 @@ auto GraphImpl::create_root_node_ptr() { } template -auto GraphImpl::create_aggregate_ptr(PredecessorRefs&&...) { +inline auto GraphImpl::create_aggregate_ptr(PredecessorRefs&&...) { // The attachment to predecessors, which is all we really need, happens // in the generic layer, which calls through to add_predecessor for // each predecessor ref, so all we need to do here is create the (trivial) diff --git a/lib/kokkos/core/src/HIP/Kokkos_HIP_Instance.hpp b/lib/kokkos/core/src/HIP/Kokkos_HIP_Instance.hpp index ef140ec46c..63ad66686b 100644 --- a/lib/kokkos/core/src/HIP/Kokkos_HIP_Instance.hpp +++ b/lib/kokkos/core/src/HIP/Kokkos_HIP_Instance.hpp @@ -30,7 +30,8 @@ namespace Impl { struct HIPTraits { #if defined(KOKKOS_ARCH_AMD_GFX906) || defined(KOKKOS_ARCH_AMD_GFX908) || \ - defined(KOKKOS_ARCH_AMD_GFX90A) || defined(KOKKOS_ARCH_AMD_GFX942) + defined(KOKKOS_ARCH_AMD_GFX90A) || defined(KOKKOS_ARCH_AMD_GFX940) || \ + defined(KOKKOS_ARCH_AMD_GFX942) static constexpr int WarpSize = 64; static constexpr int WarpIndexMask = 0x003f; /* hexadecimal for 63 */ static constexpr int WarpIndexShift = 6; /* WarpSize == 1 << WarpShift*/ diff --git a/lib/kokkos/core/src/Kokkos_HostSpace.hpp b/lib/kokkos/core/src/Kokkos_HostSpace.hpp index 90d1404063..252aabd949 100644 --- a/lib/kokkos/core/src/Kokkos_HostSpace.hpp +++ b/lib/kokkos/core/src/Kokkos_HostSpace.hpp @@ -75,12 +75,19 @@ class HostSpace { /**\brief Non-default memory space instance to choose allocation mechansim, * if available */ - enum KOKKOS_DEPRECATED AllocationMechanism { - STD_MALLOC, - POSIX_MEMALIGN, - POSIX_MMAP, - INTEL_MM_ALLOC - }; +#if defined(KOKKOS_COMPILER_GNU) && KOKKOS_COMPILER_GNU < 1100 + // We see deprecation warnings even when not using the deprecated + // HostSpace constructor below when using gcc before release 11. + enum +#else + enum KOKKOS_DEPRECATED +#endif + AllocationMechanism { + STD_MALLOC, + POSIX_MEMALIGN, + POSIX_MMAP, + INTEL_MM_ALLOC + }; KOKKOS_DEPRECATED explicit HostSpace(const AllocationMechanism&); diff --git a/lib/kokkos/core/src/Kokkos_Printf.hpp b/lib/kokkos/core/src/Kokkos_Printf.hpp index af20221a5a..39f95825c3 100644 --- a/lib/kokkos/core/src/Kokkos_Printf.hpp +++ b/lib/kokkos/core/src/Kokkos_Printf.hpp @@ -31,7 +31,7 @@ namespace Kokkos { // backends. The GPU backends always return 1 and NVHPC only compiles if we // don't ask for the return value. template -KOKKOS_FORCEINLINE_FUNCTION void printf(const char* format, Args... args) { +KOKKOS_FUNCTION void printf(const char* format, Args... args) { #ifdef KOKKOS_ENABLE_SYCL // Some compilers warn if "args" is empty and format is not a string literal if constexpr (sizeof...(Args) == 0) diff --git a/lib/kokkos/core/src/OpenMP/Kokkos_OpenMP_Instance.cpp b/lib/kokkos/core/src/OpenMP/Kokkos_OpenMP_Instance.cpp index 44f0fbc180..12bf3b71f7 100644 --- a/lib/kokkos/core/src/OpenMP/Kokkos_OpenMP_Instance.cpp +++ b/lib/kokkos/core/src/OpenMP/Kokkos_OpenMP_Instance.cpp @@ -359,8 +359,6 @@ void OpenMPInternal::finalize() { } m_initialized = false; - - Kokkos::Profiling::finalize(); } void OpenMPInternal::print_configuration(std::ostream &s) const { diff --git a/lib/kokkos/core/src/OpenMP/Kokkos_OpenMP_Instance.hpp b/lib/kokkos/core/src/OpenMP/Kokkos_OpenMP_Instance.hpp index 4586406e16..03f5fff395 100644 --- a/lib/kokkos/core/src/OpenMP/Kokkos_OpenMP_Instance.hpp +++ b/lib/kokkos/core/src/OpenMP/Kokkos_OpenMP_Instance.hpp @@ -219,6 +219,8 @@ KOKKOS_DEPRECATED void OpenMP::partition_master(F const& f, int num_partitions, Exec::validate_partition_impl(prev_instance->m_pool_size, num_partitions, partition_size); + OpenMP::memory_space space; + #pragma omp parallel num_threads(num_partitions) { Exec thread_local_instance(partition_size); diff --git a/lib/kokkos/core/src/Serial/Kokkos_Serial.cpp b/lib/kokkos/core/src/Serial/Kokkos_Serial.cpp index e81e834939..071ecdbc4f 100644 --- a/lib/kokkos/core/src/Serial/Kokkos_Serial.cpp +++ b/lib/kokkos/core/src/Serial/Kokkos_Serial.cpp @@ -58,8 +58,6 @@ void SerialInternal::finalize() { m_thread_team_data.scratch_assign(nullptr, 0, 0, 0, 0, 0); } - Kokkos::Profiling::finalize(); - m_is_initialized = false; } diff --git a/lib/kokkos/core/src/Serial/Kokkos_Serial.hpp b/lib/kokkos/core/src/Serial/Kokkos_Serial.hpp index db1567610b..67119cac16 100644 --- a/lib/kokkos/core/src/Serial/Kokkos_Serial.hpp +++ b/lib/kokkos/core/src/Serial/Kokkos_Serial.hpp @@ -30,6 +30,7 @@ static_assert(false, #include #include +#include #include #include #include diff --git a/lib/kokkos/core/src/Threads/Kokkos_ThreadsExec.cpp b/lib/kokkos/core/src/Threads/Kokkos_ThreadsExec.cpp index c754091e87..801a1ac82e 100644 --- a/lib/kokkos/core/src/Threads/Kokkos_ThreadsExec.cpp +++ b/lib/kokkos/core/src/Threads/Kokkos_ThreadsExec.cpp @@ -815,8 +815,6 @@ void ThreadsExec::finalize() { s_threads_process.m_pool_size = 1; s_threads_process.m_pool_fan_size = 0; s_threads_process.m_pool_state = ThreadsExec::Inactive; - - Kokkos::Profiling::finalize(); } //---------------------------------------------------------------------------- diff --git a/lib/kokkos/core/unit_test/TestMathematicalFunctions.hpp b/lib/kokkos/core/unit_test/TestMathematicalFunctions.hpp index d32ef4ca23..424ba05a90 100644 --- a/lib/kokkos/core/unit_test/TestMathematicalFunctions.hpp +++ b/lib/kokkos/core/unit_test/TestMathematicalFunctions.hpp @@ -30,8 +30,9 @@ #define MATHEMATICAL_FUNCTIONS_HAVE_LONG_DOUBLE_OVERLOADS #endif -#if defined KOKKOS_COMPILER_INTEL || \ - (defined(KOKKOS_COMPILER_NVCC) && KOKKOS_COMPILER_NVCC >= 1130) +#if defined KOKKOS_COMPILER_INTEL || \ + (defined(KOKKOS_COMPILER_NVCC) && KOKKOS_COMPILER_NVCC >= 1130 && \ + !defined(KOKKOS_COMPILER_MSVC)) #define MATHEMATICAL_FUNCTIONS_TEST_UNREACHABLE __builtin_unreachable(); #else #define MATHEMATICAL_FUNCTIONS_TEST_UNREACHABLE @@ -394,10 +395,12 @@ DEFINE_UNARY_FUNCTION_EVAL(log2, 2); DEFINE_UNARY_FUNCTION_EVAL(log1p, 2); #endif -#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_1 +#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_2 DEFINE_UNARY_FUNCTION_EVAL(sqrt, 2); DEFINE_UNARY_FUNCTION_EVAL(cbrt, 2); +#endif +#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_1 DEFINE_UNARY_FUNCTION_EVAL(sin, 2); DEFINE_UNARY_FUNCTION_EVAL(cos, 2); DEFINE_UNARY_FUNCTION_EVAL(tan, 2); @@ -483,11 +486,9 @@ DEFINE_UNARY_FUNCTION_EVAL(logb, 2); }; \ constexpr char math_function_name::name[] -#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_1 +#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_2 DEFINE_BINARY_FUNCTION_EVAL(pow, 2); DEFINE_BINARY_FUNCTION_EVAL(hypot, 2); -#endif -#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_2 DEFINE_BINARY_FUNCTION_EVAL(nextafter, 1); DEFINE_BINARY_FUNCTION_EVAL(copysign, 1); #endif @@ -519,7 +520,7 @@ DEFINE_BINARY_FUNCTION_EVAL(copysign, 1); }; \ constexpr char math_function_name::name[] -#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_1 +#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_2 DEFINE_TERNARY_FUNCTION_EVAL(hypot, 2); DEFINE_TERNARY_FUNCTION_EVAL(fma, 2); #endif @@ -787,7 +788,9 @@ TEST(TEST_CATEGORY, mathematical_functions_trigonometric_functions) { // TODO atan2 } +#endif +#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_2 TEST(TEST_CATEGORY, mathematical_functions_power_functions) { TEST_MATH_FUNCTION(sqrt)({0, 1, 2, 3, 5, 7, 11}); TEST_MATH_FUNCTION(sqrt)({0l, 1l, 2l, 3l, 5l, 7l, 11l}); @@ -1568,6 +1571,7 @@ TEST(TEST_CATEGORY, mathematical_functions_ieee_remainder_function) { // TODO: TestFpClassify, see https://github.com/kokkos/kokkos/issues/6279 +#ifndef KOKKOS_MATHEMATICAL_FUNCTIONS_SKIP_2 template struct TestIsFinite { TestIsFinite() { run(); } @@ -1591,6 +1595,7 @@ struct TestIsFinite { ++e; Kokkos::printf("failed isfinite(float)\n"); } +#if !(defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOS_COMPILER_MSVC)) if (!isfinite(static_cast(2.f)) #ifndef KOKKOS_COMPILER_NVHPC // FIXME_NVHPC 23.7 || isfinite(quiet_NaN::value) || @@ -1611,6 +1616,7 @@ struct TestIsFinite { ++e; Kokkos::printf("failed isfinite(KE::bhalf_t)\n"); } +#endif if (!isfinite(3.) #ifndef KOKKOS_COMPILER_NVHPC // FIXME_NVHPC 23.7 || isfinite(quiet_NaN::value) || @@ -1670,6 +1676,7 @@ struct TestIsInf { ++e; Kokkos::printf("failed isinf(float)\n"); } +#if !(defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOS_COMPILER_MSVC)) if (isinf(static_cast(2.f)) #ifndef KOKKOS_COMPILER_NVHPC // FIXME_NVHPC 23.7 || isinf(quiet_NaN::value) || @@ -1690,6 +1697,7 @@ struct TestIsInf { ++e; Kokkos::printf("failed isinf(KE::bhalf_t)\n"); } +#endif if (isinf(3.) #ifndef KOKKOS_COMPILER_NVHPC // FIXME_NVHPC 23.7 || isinf(quiet_NaN::value) || @@ -1748,6 +1756,7 @@ struct TestIsNaN { ++e; Kokkos::printf("failed isnan(float)\n"); } +#if !(defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOS_COMPILER_MSVC)) if (isnan(static_cast(2.f)) #ifndef KOKKOS_COMPILER_NVHPC // FIXME_NVHPC 23.7 || !isnan(quiet_NaN::value) || @@ -1777,6 +1786,7 @@ struct TestIsNaN { ++e; Kokkos::printf("failed isnan(double)\n"); } +#endif #ifdef MATHEMATICAL_FUNCTIONS_HAVE_LONG_DOUBLE_OVERLOADS if (isnan(4.l) || !isnan(quiet_NaN::value) || !isnan(signaling_NaN::value) || @@ -1803,6 +1813,7 @@ struct TestIsNaN { TEST(TEST_CATEGORY, mathematical_functions_isnan) { TestIsNaN(); } +#endif // TODO: TestSignBit, see https://github.com/kokkos/kokkos/issues/6279 #endif diff --git a/lib/kokkos/core/unit_test/TestNumericTraits.hpp b/lib/kokkos/core/unit_test/TestNumericTraits.hpp index 2b5531f29a..ec1c1e0ca0 100644 --- a/lib/kokkos/core/unit_test/TestNumericTraits.hpp +++ b/lib/kokkos/core/unit_test/TestNumericTraits.hpp @@ -110,8 +110,8 @@ struct TestNumericTraits { KOKKOS_FUNCTION void operator()(Epsilon, int, int& e) const { using Kokkos::Experimental::epsilon; - auto const eps = epsilon::value; - auto const one = T(1); + T const eps = epsilon::value; + T const one = 1; // Avoid higher precision intermediate representation compare() = one + eps; e += (int)!(compare() != one); diff --git a/lib/kokkos/generate_makefile.bash b/lib/kokkos/generate_makefile.bash index 1b216d9fe3..301a1fceb5 100755 --- a/lib/kokkos/generate_makefile.bash +++ b/lib/kokkos/generate_makefile.bash @@ -160,6 +160,7 @@ display_help_text() { echo " AMD_GFX906 = AMD GPU MI50/MI60 GFX906" echo " AMD_GFX908 = AMD GPU MI100 GFX908" echo " AMD_GFX90A = AMD GPU MI200 GFX90A" + echo " AMD_GFX940 = AMD GPU MI300 GFX940" echo " AMD_GFX942 = AMD GPU MI300 GFX942" echo " AMD_GFX1030 = AMD GPU V620/W6800 GFX1030" echo " AMD_GFX1100 = AMD GPU RX 7900 XT(X) GFX1100" diff --git a/lib/kokkos/master_history.txt b/lib/kokkos/master_history.txt index fd0020b8d5..a43b5276a8 100644 --- a/lib/kokkos/master_history.txt +++ b/lib/kokkos/master_history.txt @@ -34,3 +34,4 @@ tag: 4.0.00 date: 02:23:2023 master: 5ad60966 release: 52ea2953 tag: 4.0.01 date: 04:26:2023 master: aa1f48f3 release: 5893754f tag: 4.1.00 date: 06:20:2023 master: 62d2b6c8 release: adde1e6a tag: 4.2.00 date: 11:09:2023 master: 1a3ea28f release: abe01c88 +tag: 4.2.01 date: 01:30:2024 master: 71a9bcae release: 221e5f7a diff --git a/lib/kokkos/simd/src/Kokkos_SIMD_Scalar.hpp b/lib/kokkos/simd/src/Kokkos_SIMD_Scalar.hpp index af7cb1e2c6..7443f5596b 100644 --- a/lib/kokkos/simd/src/Kokkos_SIMD_Scalar.hpp +++ b/lib/kokkos/simd/src/Kokkos_SIMD_Scalar.hpp @@ -224,7 +224,7 @@ template using data_type = std::conditional_t, T, double>; return Experimental::simd( Kokkos::floor(static_cast(a[0]))); -}; +} template [[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION auto ceil( @@ -232,7 +232,7 @@ template using data_type = std::conditional_t, T, double>; return Experimental::simd( Kokkos::ceil(static_cast(a[0]))); -}; +} template [[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION auto round( @@ -240,7 +240,7 @@ template using data_type = std::conditional_t, T, double>; return Experimental::simd( Experimental::round_half_to_nearest_even(static_cast(a[0]))); -}; +} template [[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION auto trunc( @@ -248,7 +248,7 @@ template using data_type = std::conditional_t, T, double>; return Experimental::simd( Kokkos::trunc(static_cast(a[0]))); -}; +} template [[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION diff --git a/lib/kokkos/simd/unit_tests/include/TestSIMD_GeneratorCtors.hpp b/lib/kokkos/simd/unit_tests/include/TestSIMD_GeneratorCtors.hpp index 4feff3a89d..4af08c266b 100644 --- a/lib/kokkos/simd/unit_tests/include/TestSIMD_GeneratorCtors.hpp +++ b/lib/kokkos/simd/unit_tests/include/TestSIMD_GeneratorCtors.hpp @@ -42,6 +42,7 @@ inline void host_check_gen_ctor() { simd_type blend; blend.copy_from(expected, Kokkos::Experimental::element_aligned_tag()); +#if !(defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOS_COMPILER_MSVC)) if constexpr (std::is_same_v) { simd_type basic(KOKKOS_LAMBDA(std::size_t i) { return init[i]; }); host_check_equality(basic, rhs, lanes); @@ -63,6 +64,7 @@ inline void host_check_gen_ctor() { host_check_equality(blend, result, lanes); } +#endif } template From 6dcfcc1a830d4e9a416b6cf3b1dce6a5281318c6 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Wed, 6 Mar 2024 17:57:10 -0700 Subject: [PATCH 184/185] Update CMake --- cmake/Modules/Packages/KOKKOS.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/Modules/Packages/KOKKOS.cmake b/cmake/Modules/Packages/KOKKOS.cmake index e1da77c6d0..9324ea95c4 100644 --- a/cmake/Modules/Packages/KOKKOS.cmake +++ b/cmake/Modules/Packages/KOKKOS.cmake @@ -45,8 +45,8 @@ if(DOWNLOAD_KOKKOS) list(APPEND KOKKOS_LIB_BUILD_ARGS "-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}") list(APPEND KOKKOS_LIB_BUILD_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") include(ExternalProject) - set(KOKKOS_URL "https://github.com/kokkos/kokkos/archive/4.2.00.tar.gz" CACHE STRING "URL for KOKKOS tarball") - set(KOKKOS_MD5 "731647b61a4233f568d583702e9cd6d1" CACHE STRING "MD5 checksum of KOKKOS tarball") + set(KOKKOS_URL "https://github.com/kokkos/kokkos/archive/4.2.01.tar.gz" CACHE STRING "URL for KOKKOS tarball") + set(KOKKOS_MD5 "16b9b09ae947d434dfb58fc5c87c2b76" CACHE STRING "MD5 checksum of KOKKOS tarball") mark_as_advanced(KOKKOS_URL) mark_as_advanced(KOKKOS_MD5) GetFallbackURL(KOKKOS_URL KOKKOS_FALLBACK) @@ -71,7 +71,7 @@ if(DOWNLOAD_KOKKOS) add_dependencies(LAMMPS::KOKKOSCORE kokkos_build) add_dependencies(LAMMPS::KOKKOSCONTAINERS kokkos_build) elseif(EXTERNAL_KOKKOS) - find_package(Kokkos 4.2.00 REQUIRED CONFIG) + find_package(Kokkos 4.2.01 REQUIRED CONFIG) target_link_libraries(lammps PRIVATE Kokkos::kokkos) else() set(LAMMPS_LIB_KOKKOS_SRC_DIR ${LAMMPS_LIB_SOURCE_DIR}/kokkos) From 8ab2544f5b3b3113d36cf208d3cc166c3385b1e5 Mon Sep 17 00:00:00 2001 From: "W. Michael Brown" Date: Thu, 7 Mar 2024 07:07:16 -0800 Subject: [PATCH 185/185] Add option to specify # of numa domains for processors grid numa style, simplify numa mapping with more agressive optimization to reduce comm between numa domains. --- doc/src/processors.rst | 34 ++++++++++++++++------- src/comm.cpp | 9 ++++++- src/comm.h | 1 + src/procmap.cpp | 61 ++++++++++++++++-------------------------- src/procmap.h | 2 +- 5 files changed, 57 insertions(+), 50 deletions(-) diff --git a/doc/src/processors.rst b/doc/src/processors.rst index 921bbcc667..a11febb1c2 100644 --- a/doc/src/processors.rst +++ b/doc/src/processors.rst @@ -25,6 +25,8 @@ Syntax *numa* params = none *custom* params = infile infile = file containing grid layout + *numa_nodes* arg = Nn + Nn = number of numa domains per node *map* arg = *cart* or *cart/reorder* or *xyz* or *xzy* or *yxz* or *yzx* or *zxy* or *zyx* cart = use MPI_Cart() methods to map processors to 3d grid with reorder = 0 cart/reorder = use MPI_Cart() methods to map processors to 3d grid with reorder = 1 @@ -159,24 +161,28 @@ surface-to-volume ratio of each processor's subdomain. The *numa* style operates similar to the *twolevel* keyword except that it auto-detects which cores are running on which nodes. -Currently, it does this in only 2 levels, but it may be extended in -the future to account for socket topology and other non-uniform memory -access (NUMA) costs. It also uses a different algorithm than the -*twolevel* keyword for doing the two-level factorization of the -simulation box into a 3d processor grid to minimize off-node -communication, and it does its own MPI-based mapping of nodes and +It will also subdivide the cores into numa domains. Currently, the +number of numa domains is not autodetected and must be specified using +the *numa_nodes* keyword; otherwise, the default value is used. The +*numa* style uses a different algorithm than the *twolevel* keyword for +doing the two-level factorization of the simulation box into a 3d +processor grid to minimize off-node communication and communication +across numa domains. It does its own MPI-based mapping of nodes and cores to the regular 3d grid. Thus it may produce a different layout of the processors than the *twolevel* options. The *numa* style will give an error if the number of MPI processes is not divisible by the number of cores used per node, or any of the Px -or Py of Pz values is greater than 1. +or Py or Pz values is greater than 1. .. note:: Unlike the *twolevel* style, the *numa* style does not require - any particular ordering of MPI ranks i norder to work correctly. This + any particular ordering of MPI ranks in order to work correctly. This is because it auto-detects which processes are running on which nodes. + However, it assumes that the lowest ranks are in the first numa + domain, and so forth. MPI rank orderings that do not preserve this + property might result in more intranode communication between CPUs. The *custom* style uses the file *infile* to define both the 3d factorization and the mapping of processors to the grid. @@ -207,6 +213,14 @@ any order, but no processor ID should appear more than once. ---------- +The *numa_nodes* keyword is used to specifiy the number of numa domains +per node. It is currently only used by the *numa* style for two-level +factorization to reduce the amount of MPI communications between CPUs. +A good setting for this will typically be equal to the number of CPU +sockets per node. + +---------- + The *map* keyword affects how the P processor IDs (from 0 to P-1) are mapped to the 3d grid of processors. It is only used by the *onelevel* and *twolevel* grid settings. @@ -356,5 +370,5 @@ Related commands Default """"""" -The option defaults are Px Py Pz = \* \* \*, grid = onelevel, and map = -cart. +The option defaults are Px Py Pz = \* \* \*, grid = onelevel, map = +cart, and numa_nodes = 2. diff --git a/src/comm.cpp b/src/comm.cpp index 1293dd3d6d..02999fd541 100644 --- a/src/comm.cpp +++ b/src/comm.cpp @@ -420,6 +420,7 @@ void Comm::set_processors(int narg, char **arg) error->all(FLERR,"Specified processors != physical processors"); int iarg = 3; + numa_nodes = 2; while (iarg < narg) { if (strcmp(arg[iarg],"grid") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal processors command"); @@ -514,6 +515,12 @@ void Comm::set_processors(int narg, char **arg) outfile = utils::strdup(arg[iarg+1]); iarg += 2; + } else if (strcmp(arg[iarg],"numa_nodes") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal processors command"); + numa_nodes = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + if (numa_nodes < 1) numa_nodes = 2; + iarg += 2; + } else error->all(FLERR,"Illegal processors command"); } @@ -565,7 +572,7 @@ void Comm::set_proc_grid(int outflag) otherflag,other_style,other_procgrid,other_coregrid); } else if (gridflag == NUMA) { - pmap->numa_grid(nprocs,user_procgrid,procgrid,coregrid); + pmap->numa_grid(numa_nodes,nprocs,user_procgrid,procgrid,coregrid); } else if (gridflag == CUSTOM) { pmap->custom_grid(customfile,nprocs,user_procgrid,procgrid); diff --git a/src/comm.h b/src/comm.h index 5d803c1afa..fde4c3b81f 100644 --- a/src/comm.h +++ b/src/comm.h @@ -146,6 +146,7 @@ class Comm : protected Pointers { char xyz[4]; // xyz mapping of procs to 3d grid char *customfile; // file with custom proc map char *outfile; // proc grid/map output file + int numa_nodes; // Number of numa domains per socket for 3d grid int otherflag; // 1 if this partition dependent on another int other_style; // style of dependency diff --git a/src/procmap.cpp b/src/procmap.cpp index 71e1cf5a6b..b520354f53 100644 --- a/src/procmap.cpp +++ b/src/procmap.cpp @@ -150,13 +150,9 @@ void ProcMap::twolevel_grid(int nprocs, int *user_procgrid, int *procgrid, auto-detects NUMA sockets within a multi-core node ------------------------------------------------------------------------- */ -void ProcMap::numa_grid(int nprocs, int *user_procgrid, int *procgrid, - int *numagrid) +void ProcMap::numa_grid(int numa_nodes, int nprocs, int *user_procgrid, + int *procgrid, int *numagrid) { - // hardwire this for now - - int numa_nodes = 1; - // get names of all nodes int name_length; @@ -181,6 +177,7 @@ void ProcMap::numa_grid(int nprocs, int *user_procgrid, int *procgrid, } procs_per_node = name_map.begin()->second; procs_per_numa = procs_per_node / numa_nodes; + if (procs_per_numa < 1) procs_per_numa = 1; delete [] node_names; @@ -192,6 +189,24 @@ void ProcMap::numa_grid(int nprocs, int *user_procgrid, int *procgrid, user_procgrid[2] > 1) error->all(FLERR,"Could not create numa grid of processors"); + // factorization for the grid of NUMA nodes + + int node_count = nprocs / procs_per_numa; + + int **nodefactors; + int nodepossible = factor(node_count,nullptr); + memory->create(nodefactors,nodepossible,3,"procmap:nodefactors"); + nodepossible = factor(node_count,nodefactors); + + if (domain->dimension == 2) + nodepossible = cull_2d(nodepossible,nodefactors,3); + nodepossible = cull_user(nodepossible,nodefactors,3,user_procgrid); + + if (nodepossible == 0) + error->all(FLERR,"Could not create numa grid of processors"); + + best_factors(nodepossible,nodefactors,nodegrid,1,1,1); + // user settings for the factorization per numa node // currently not user settable // if user specifies 1 for a proc grid dimension, @@ -204,6 +219,7 @@ void ProcMap::numa_grid(int nprocs, int *user_procgrid, int *procgrid, if (user_procgrid[1] == 1) user_numagrid[1] = 1; if (user_procgrid[2] == 1) user_numagrid[2] = 1; + // perform NUMA node factorization using subdomain sizes // initial factorization within NUMA node int **numafactors; @@ -218,38 +234,6 @@ void ProcMap::numa_grid(int nprocs, int *user_procgrid, int *procgrid, if (numapossible == 0) error->all(FLERR,"Could not create numa grid of processors"); - best_factors(numapossible,numafactors,numagrid,1,1,1); - - // user_nodegrid = implied user constraints on nodes - - int user_nodegrid[3]; - user_nodegrid[0] = user_procgrid[0] / numagrid[0]; - user_nodegrid[1] = user_procgrid[1] / numagrid[1]; - user_nodegrid[2] = user_procgrid[2] / numagrid[2]; - - // factorization for the grid of NUMA nodes - - int node_count = nprocs / procs_per_numa; - - int **nodefactors; - int nodepossible = factor(node_count,nullptr); - memory->create(nodefactors,nodepossible,3,"procmap:nodefactors"); - nodepossible = factor(node_count,nodefactors); - - if (domain->dimension == 2) - nodepossible = cull_2d(nodepossible,nodefactors,3); - nodepossible = cull_user(nodepossible,nodefactors,3,user_nodegrid); - - if (nodepossible == 0) - error->all(FLERR,"Could not create numa grid of processors"); - - best_factors(nodepossible,nodefactors,nodegrid, - numagrid[0],numagrid[1],numagrid[2]); - - // repeat NUMA node factorization using subdomain sizes - // refines the factorization if the user specified the node layout - // NOTE: this will not re-enforce user-procgrid constraint will it? - best_factors(numapossible,numafactors,numagrid, nodegrid[0],nodegrid[1],nodegrid[2]); @@ -270,6 +254,7 @@ void ProcMap::numa_grid(int nprocs, int *user_procgrid, int *procgrid, procgrid[0] = nodegrid[0] * numagrid[0]; procgrid[1] = nodegrid[1] * numagrid[1]; procgrid[2] = nodegrid[2] * numagrid[2]; + } /* ---------------------------------------------------------------------- diff --git a/src/procmap.h b/src/procmap.h index 06867837c6..2731aec984 100644 --- a/src/procmap.h +++ b/src/procmap.h @@ -24,7 +24,7 @@ class ProcMap : protected Pointers { void onelevel_grid(int, int *, int *, int, int, int *, int *); void twolevel_grid(int, int *, int *, int, int *, int *, int, int, int *, int *); - void numa_grid(int, int *, int *, int *); + void numa_grid(int, int, int *, int *, int *); void custom_grid(char *, int, int *, int *); void cart_map(int, int *, int *, int[3][2], int ***); void cart_map(int, int *, int, int *, int *, int[3][2], int ***);