From a4b3eea189ea2c0b9122dbd968a1d39d8c5d8bbd Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 2 Nov 2023 14:39:24 -0500 Subject: [PATCH 01/43] brownian/kk almost correct on cpu --- src/USER-SUMAN/pair_brownian.cpp | 772 +++++++++++++++++++++++ src/USER-SUMAN/pair_brownian.h | 64 ++ src/USER-SUMAN/pair_brownian_kokkos.cpp | 727 +++++++++++++++++++++ src/USER-SUMAN/pair_brownian_kokkos.h | 165 +++++ src/USER-SUMAN/pair_lubricate_Simple.cpp | 398 ++++++++++++ src/USER-SUMAN/pair_lubricate_Simple.h | 70 ++ 6 files changed, 2196 insertions(+) create mode 100644 src/USER-SUMAN/pair_brownian.cpp create mode 100644 src/USER-SUMAN/pair_brownian.h create mode 100644 src/USER-SUMAN/pair_brownian_kokkos.cpp create mode 100644 src/USER-SUMAN/pair_brownian_kokkos.h create mode 100644 src/USER-SUMAN/pair_lubricate_Simple.cpp create mode 100644 src/USER-SUMAN/pair_lubricate_Simple.h diff --git a/src/USER-SUMAN/pair_brownian.cpp b/src/USER-SUMAN/pair_brownian.cpp new file mode 100644 index 0000000000..8c99522abb --- /dev/null +++ b/src/USER-SUMAN/pair_brownian.cpp @@ -0,0 +1,772 @@ +/* ---------------------------------------------------------------------- + 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: Amit Kumar and Michael Bybee (UIUC) +------------------------------------------------------------------------- */ + +#include "pair_brownian.h" + +#include "atom.h" +#include "comm.h" +#include "domain.h" +#include "error.h" +#include "fix.h" +#include "fix_wall.h" +#include "force.h" +#include "input.h" +#include "math_const.h" +#include "math_special.h" +#include "memory.h" +#include "modify.h" +#include "neigh_list.h" +#include "neighbor.h" +#include "random_mars.h" +#include "update.h" +#include "variable.h" + +#include +#include + +using namespace LAMMPS_NS; +using namespace MathConst; +using namespace MathSpecial; + +// same as fix_wall.cpp + +enum { EDGE, CONSTANT, VARIABLE }; + +#define _NO_RANDOM + +/* ---------------------------------------------------------------------- */ + +PairBrownian::PairBrownian(LAMMPS *lmp) : Pair(lmp) +{ + single_enable = 0; + random = nullptr; +} + +/* ---------------------------------------------------------------------- */ + +PairBrownian::~PairBrownian() +{ + if(copymode) return; + + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); + + memory->destroy(cut); + memory->destroy(cut_inner); + } + delete random; +} + +/* ---------------------------------------------------------------------- */ + +void PairBrownian::compute(int eflag, int vflag) +{ + printf("Warning:: PairBrownian::compute() Random numbers all set to 0.5\n"); + + int i, j, ii, jj, inum, jnum, itype, jtype; + double xtmp, ytmp, ztmp, delx, dely, delz, fx, fy, fz, tx, ty, tz; + double rsq, r, h_sep, radi; + int *ilist, *jlist, *numneigh, **firstneigh; + + ev_init(eflag, vflag); + + double **x = atom->x; + double **f = atom->f; + double **torque = atom->torque; + double *radius = atom->radius; + int *type = atom->type; + int nlocal = atom->nlocal; + int newton_pair = force->newton_pair; + + double vxmu2f = force->vxmu2f; + double randr; + double prethermostat; + double xl[3], a_sq, a_sh, a_pu, Fbmag; + double p1[3], p2[3], p3[3]; + + // This section of code adjusts R0/RT0/RS0 if necessary due to changes + // in the volume fraction as a result of fix deform or moving walls + + printf("PairBrownian::compute() flagVF= %i flagdeform= %i flagwall= %i flaglog= %i\n",flagVF,flagdeform,flagwall,flaglog); + + double dims[3], wallcoord; + if (flagVF) // Flag for volume fraction corrections + if (flagdeform || flagwall == 2) { // Possible changes in volume fraction + if (flagdeform && !flagwall) + for (j = 0; j < 3; j++) dims[j] = domain->prd[j]; + else if (flagwall == 2 || (flagdeform && flagwall == 1)) { + double wallhi[3], walllo[3]; + for (int j = 0; j < 3; j++) { + wallhi[j] = domain->prd[j]; + walllo[j] = 0; + } + for (int m = 0; m < wallfix->nwall; m++) { + int dim = wallfix->wallwhich[m] / 2; + int side = wallfix->wallwhich[m] % 2; + if (wallfix->xstyle[m] == VARIABLE) { + wallcoord = input->variable->compute_equal(wallfix->xindex[m]); + } else + wallcoord = wallfix->coord0[m]; + if (side == 0) + walllo[dim] = wallcoord; + else + wallhi[dim] = wallcoord; + } + for (int j = 0; j < 3; j++) dims[j] = wallhi[j] - walllo[j]; + } + double vol_T = dims[0] * dims[1] * dims[2]; + double vol_f = vol_P / vol_T; + if (flaglog == 0) { + R0 = 6 * MY_PI * mu * rad * (1.0 + 2.16 * vol_f); + RT0 = 8 * MY_PI * mu * cube(rad); + //RS0 = 20.0/3.0*MY_PI*mu*pow(rad,3)*(1.0 + 3.33*vol_f + 2.80*vol_f*vol_f); + } else { + R0 = 6 * MY_PI * mu * rad * (1.0 + 2.725 * vol_f - 6.583 * vol_f * vol_f); + RT0 = 8 * MY_PI * mu * cube(rad) * (1.0 + 0.749 * vol_f - 2.469 * vol_f * vol_f); + //RS0 = 20.0/3.0*MY_PI*mu*pow(rad,3)*(1.0 + 3.64*vol_f - 6.95*vol_f*vol_f); + } + } + + // scale factor for Brownian moments + + prethermostat = sqrt(24.0 * force->boltz * t_target / update->dt); + prethermostat *= sqrt(force->vxmu2f / force->ftm2v / force->mvv2e); + + printf("PairBrownian::compute() prethermostat= %f R0= %f RT0= %f\n",prethermostat, R0, RT0); + + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + printf(" -- starting ij-loop() newton_pair= %i vflag_atom= %i flagfld= %i vflag_global= %i\n", + newton_pair, vflag_atom, flagfld, vflag_global); + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + itype = type[i]; + radi = radius[i]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + +#if 1 + // FLD contribution to force and torque due to isotropic terms + + if(ii == 0) printf("ii= %i i= %i f(before)= %f %f %f df= %f\n",ii,i,f[i][0],f[i][1],f[i][2],prethermostat * sqrt(R0) * 0.5); +#ifdef _NO_RANDOM + if (flagfld) { + f[i][0] += prethermostat * sqrt(R0) * 0.5; + f[i][1] += prethermostat * sqrt(R0) * 0.5; + f[i][2] += prethermostat * sqrt(R0) * 0.5; + if (flaglog) { + torque[i][0] += prethermostat * sqrt(RT0) * 0.5; + torque[i][1] += prethermostat * sqrt(RT0) * 0.5; + torque[i][2] += prethermostat * sqrt(RT0) * 0.5; + } + } +#else + if (flagfld) { + f[i][0] += prethermostat * sqrt(R0) * (random->uniform() - 0.5); + f[i][1] += prethermostat * sqrt(R0) * (random->uniform() - 0.5); + f[i][2] += prethermostat * sqrt(R0) * (random->uniform() - 0.5); + if (flaglog) { + torque[i][0] += prethermostat * sqrt(RT0) * (random->uniform() - 0.5); + torque[i][1] += prethermostat * sqrt(RT0) * (random->uniform() - 0.5); + torque[i][2] += prethermostat * sqrt(RT0) * (random->uniform() - 0.5); + } + } +#endif + +#endif + + if (!flagHI) continue; + +#if 1 + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx * delx + dely * dely + delz * delz; + jtype = type[j]; + + if (rsq < cutsq[itype][jtype]) { + r = sqrt(rsq); + + // scalar resistances a_sq and a_sh + + h_sep = r - 2.0 * radi; + + // if less than minimum gap, use minimum gap instead + + if (r < cut_inner[itype][jtype]) h_sep = cut_inner[itype][jtype] - 2.0 * radi; + + // scale h_sep by radi + + h_sep = h_sep / radi; + + // scalar resistances + + if (flaglog) { + a_sq = 6.0 * MY_PI * mu * radi * (1.0 / 4.0 / h_sep + 9.0 / 40.0 * log(1.0 / h_sep)); + a_sh = 6.0 * MY_PI * mu * radi * (1.0 / 6.0 * log(1.0 / h_sep)); + a_pu = 8.0 * MY_PI * mu * cube(radi) * (3.0 / 160.0 * log(1.0 / h_sep)); + } else + a_sq = 6.0 * MY_PI * mu * radi * (1.0 / 4.0 / h_sep); + + // generate the Pairwise Brownian Force: a_sq + + Fbmag = prethermostat * sqrt(a_sq); + + // generate a random number + +#ifdef _NO_RANDOM + randr = 0.5; +#else + randr = random->uniform() - 0.5; +#endif + + // contribution due to Brownian motion + + fx = Fbmag * randr * delx / r; + fy = Fbmag * randr * dely / r; + fz = Fbmag * randr * delz / r; + + // add terms due to a_sh + +#if 1 + if (flaglog) { + + // generate two orthogonal vectors to the line of centers + + p1[0] = delx / r; + p1[1] = dely / r; + p1[2] = delz / r; + set_3_orthogonal_vectors(p1, p2, p3); + + // magnitude + + Fbmag = prethermostat * sqrt(a_sh); + + // force in each of the two directions + +#ifdef _NO_RANDOM + randr = 0.5; +#else + randr = random->uniform() - 0.5; +#endif + fx += Fbmag * randr * p2[0]; + fy += Fbmag * randr * p2[1]; + fz += Fbmag * randr * p2[2]; + +#ifndef _NO_RANDOM + randr = random->uniform() - 0.5; +#endif + fx += Fbmag * randr * p3[0]; + fy += Fbmag * randr * p3[1]; + fz += Fbmag * randr * p3[2]; + } +#endif + // scale forces to appropriate units + + fx = vxmu2f * fx; + fy = vxmu2f * fy; + fz = vxmu2f * fz; + + // sum to total force + + f[i][0] -= fx; + f[i][1] -= fy; + f[i][2] -= fz; + + if (newton_pair || j < nlocal) { + //randr = random->uniform()-0.5; + //fx = Fbmag*randr*delx/r; + //fy = Fbmag*randr*dely/r; + //fz = Fbmag*randr*delz/r; + + f[j][0] += fx; + f[j][1] += fy; + f[j][2] += fz; + } + + // torque due to the Brownian Force + + if (flaglog) { + + // location of the point of closest approach on I from its center + + xl[0] = -delx / r * radi; + xl[1] = -dely / r * radi; + xl[2] = -delz / r * radi; + + // torque = xl_cross_F + + tx = xl[1] * fz - xl[2] * fy; + ty = xl[2] * fx - xl[0] * fz; + tz = xl[0] * fy - xl[1] * fx; + + // torque is same on both particles + + torque[i][0] -= tx; + torque[i][1] -= ty; + torque[i][2] -= tz; + + if (newton_pair || j < nlocal) { + torque[j][0] -= tx; + torque[j][1] -= ty; + torque[j][2] -= tz; + } + + // torque due to a_pu + + Fbmag = prethermostat * sqrt(a_pu); + + // force in each direction + +#ifdef _NO_RANDOM + randr = 0.5; +#else + randr = random->uniform() - 0.5; +#endif + tx = Fbmag * randr * p2[0]; + ty = Fbmag * randr * p2[1]; + tz = Fbmag * randr * p2[2]; + +#ifndef _NO_RANDOM + randr = random->uniform() - 0.5; +#endif + tx += Fbmag * randr * p3[0]; + ty += Fbmag * randr * p3[1]; + tz += Fbmag * randr * p3[2]; + + // torque has opposite sign on two particles + + torque[i][0] -= tx; + torque[i][1] -= ty; + torque[i][2] -= tz; + + if (newton_pair || j < nlocal) { + torque[j][0] += tx; + torque[j][1] += ty; + torque[j][2] += tz; + } + } + + if (evflag) + ev_tally_xyz(i, j, nlocal, newton_pair, 0.0, 0.0, -fx, -fy, -fz, delx, dely, delz); + } + } +#endif + } + + printf("ii= %i i= %i f(after)= %f %f %f\n",0,ilist[0],f[ilist[0]][0],f[ilist[0]][1],f[ilist[0]][2]); + printf("i= %i vatom= %f %f %f %f %f %f\n",0,vatom[0][0],vatom[0][1],vatom[0][2],vatom[0][3],vatom[0][4],vatom[0][5]); + + if (vflag_fdotr) virial_fdotr_compute(); +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +void PairBrownian::allocate() +{ + allocated = 1; + int np1 = atom->ntypes + 1; + + memory->create(setflag, np1, np1, "pair:setflag"); + for (int i = 1; i < np1; i++) + for (int j = i; j < np1; j++) setflag[i][j] = 0; + + memory->create(cutsq, np1, np1, "pair:cutsq"); + + memory->create(cut, np1, np1, "pair:cut"); + memory->create(cut_inner, np1, np1, "pair:cut_inner"); +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +void PairBrownian::settings(int narg, char **arg) +{ + if (narg != 7 && narg != 9) error->all(FLERR, "Illegal pair_style command"); + + mu = utils::numeric(FLERR, arg[0], false, lmp); + flaglog = utils::inumeric(FLERR, arg[1], false, lmp); + flagfld = utils::inumeric(FLERR, arg[2], false, lmp); + cut_inner_global = utils::numeric(FLERR, arg[3], false, lmp); + cut_global = utils::numeric(FLERR, arg[4], false, lmp); + t_target = utils::numeric(FLERR, arg[5], false, lmp); + seed = utils::inumeric(FLERR, arg[6], false, lmp); + + flagHI = flagVF = 1; + if (narg == 9) { + flagHI = utils::inumeric(FLERR, arg[7], false, lmp); + flagVF = utils::inumeric(FLERR, arg[8], false, lmp); + } + + if (flaglog == 1 && flagHI == 0) { + error->warning(FLERR, + "Cannot include log terms without 1/r terms; " + "setting flagHI to 1"); + flagHI = 1; + } + + // initialize Marsaglia RNG with processor-unique seed + + delete random; + random = new RanMars(lmp, seed + comm->me); + + // reset cutoffs that have been explicitly set + + if (allocated) { + for (int i = 1; i <= atom->ntypes; i++) + for (int j = i; j <= atom->ntypes; j++) + if (setflag[i][j]) { + cut_inner[i][j] = cut_inner_global; + cut[i][j] = cut_global; + } + } +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +void PairBrownian::coeff(int narg, char **arg) +{ + if (narg != 2 && narg != 4) error->all(FLERR, "Incorrect args for pair coefficients"); + + if (!allocated) allocate(); + + int ilo, ihi, jlo, jhi; + utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error); + utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error); + + double cut_inner_one = cut_inner_global; + double cut_one = cut_global; + + if (narg == 4) { + cut_inner_one = utils::numeric(FLERR, arg[2], false, lmp); + cut_one = utils::numeric(FLERR, arg[3], false, lmp); + } + + int count = 0; + for (int i = ilo; i <= ihi; i++) + for (int j = MAX(jlo, i); j <= jhi; j++) { + cut_inner[i][j] = cut_inner_one; + cut[i][j] = cut_one; + setflag[i][j] = 1; + count++; + } + + if (count == 0) error->all(FLERR, "Incorrect args for pair coefficients"); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +void PairBrownian::init_style() +{ + printf("Inside PairBrownian::init_style()\n"); + + if (!atom->sphere_flag) error->all(FLERR, "Pair brownian requires atom style sphere"); + + // if newton off, forces between atoms ij will be double computed + // using different random numbers + + if (force->newton_pair == 0 && comm->me == 0) + error->warning(FLERR, "Pair brownian needs newton pair on for momentum conservation"); + + neighbor->add_request(this); + + // ensure all particles are finite-size + // for pair hybrid, should limit test to types using the pair style + + double *radius = atom->radius; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) + if (radius[i] == 0.0) error->one(FLERR, "Pair brownian requires extended particles"); + + // require monodisperse system with same radii for all types + + double radtype; + for (int i = 1; i <= atom->ntypes; i++) { + if (!atom->radius_consistency(i, radtype)) + error->all(FLERR, "Pair brownian requires monodisperse particles"); + if (i > 1 && radtype != rad) error->all(FLERR, "Pair brownian requires monodisperse particles"); + rad = radtype; + } + + // set the isotropic constants that depend on the volume fraction + // vol_T = total volume + // check for fix deform, if exists it must use "remap v" + // If box will change volume, set appropriate flag so that volume + // and v.f. corrections are re-calculated at every step. + // + // If available volume is different from box volume + // due to walls, set volume appropriately; if walls will + // move, set appropriate flag so that volume and v.f. corrections + // are re-calculated at every step. + + flagdeform = flagwall = 0; + for (int i = 0; i < modify->nfix; i++) { + printf(" i= %i fix->style= %s\n",i,modify->fix[i]->style); + if (strcmp(modify->fix[i]->style, "deform") == 0) flagdeform = 1; + else if (strcmp(modify->fix[i]->style, "deform/kk") == 0) flagdeform = 1; // cleaner way to do this?? what about flagwall? + else if (strstr(modify->fix[i]->style, "wall") != nullptr) { + if (flagwall) error->all(FLERR, "Cannot use multiple fix wall commands with pair brownian"); + flagwall = 1; // Walls exist + wallfix = dynamic_cast(modify->fix[i]); + if (wallfix->xflag) flagwall = 2; // Moving walls exist + } + } + + // set the isotropic constants depending on the volume fraction + // vol_T = total volumeshearing = flagdeform = flagwall = 0; + + double vol_T, wallcoord; + if (!flagwall) + vol_T = domain->xprd * domain->yprd * domain->zprd; + else { + double wallhi[3], walllo[3]; + for (int j = 0; j < 3; j++) { + wallhi[j] = domain->prd[j]; + walllo[j] = 0; + } + for (int m = 0; m < wallfix->nwall; m++) { + int dim = wallfix->wallwhich[m] / 2; + int side = wallfix->wallwhich[m] % 2; + if (wallfix->xstyle[m] == VARIABLE) { + wallfix->xindex[m] = input->variable->find(wallfix->xstr[m]); + // Since fix->wall->init happens after pair->init_style + wallcoord = input->variable->compute_equal(wallfix->xindex[m]); + } + + else + wallcoord = wallfix->coord0[m]; + + if (side == 0) + walllo[dim] = wallcoord; + else + wallhi[dim] = wallcoord; + } + vol_T = (wallhi[0] - walllo[0]) * (wallhi[1] - walllo[1]) * (wallhi[2] - walllo[2]); + } + + // vol_P = volume of particles, assuming mono-dispersity + // vol_f = volume fraction + + vol_P = atom->natoms * (4.0 / 3.0) * MY_PI * cube(rad); + + double vol_f = vol_P / vol_T; + + // set isotropic constants + if (!flagVF) vol_f = 0; + + if (flaglog == 0) { + R0 = 6 * MY_PI * mu * rad * (1.0 + 2.16 * vol_f); + RT0 = 8 * MY_PI * mu * cube(rad); // not actually needed + } else { + R0 = 6 * MY_PI * mu * rad * (1.0 + 2.725 * vol_f - 6.583 * vol_f * vol_f); + RT0 = 8 * MY_PI * mu * cube(rad) * (1.0 + 0.749 * vol_f - 2.469 * vol_f * vol_f); + } + + printf("PairBrownian::init_style() flagdeform= %i flagwall= %i flaglog= %i R0= %f RT0= %f\n",flagdeform,flagwall,flaglog,R0,RT0); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +double PairBrownian::init_one(int i, int j) +{ + if (setflag[i][j] == 0) { + cut_inner[i][j] = mix_distance(cut_inner[i][i], cut_inner[j][j]); + cut[i][j] = mix_distance(cut[i][i], cut[j][j]); + } + + cut_inner[j][i] = cut_inner[i][j]; + + return cut[i][j]; +} + +/* ---------------------------------------------------------------------- + proc 0 writes to restart file +------------------------------------------------------------------------- */ + +void PairBrownian::write_restart(FILE *fp) +{ + write_restart_settings(fp); + + int i, j; + for (i = 1; i <= atom->ntypes; i++) + for (j = i; j <= atom->ntypes; j++) { + fwrite(&setflag[i][j], sizeof(int), 1, fp); + if (setflag[i][j]) { + fwrite(&cut_inner[i][j], sizeof(double), 1, fp); + fwrite(&cut[i][j], sizeof(double), 1, fp); + } + } +} + +/* ---------------------------------------------------------------------- + proc 0 reads from restart file, bcasts +------------------------------------------------------------------------- */ + +void PairBrownian::read_restart(FILE *fp) +{ + read_restart_settings(fp); + allocate(); + + int i, j; + int me = comm->me; + for (i = 1; i <= atom->ntypes; i++) + for (j = i; j <= atom->ntypes; j++) { + if (me == 0) utils::sfread(FLERR, &setflag[i][j], sizeof(int), 1, fp, nullptr, error); + MPI_Bcast(&setflag[i][j], 1, MPI_INT, 0, world); + if (setflag[i][j]) { + if (me == 0) { + utils::sfread(FLERR, &cut_inner[i][j], sizeof(double), 1, fp, nullptr, error); + utils::sfread(FLERR, &cut[i][j], sizeof(double), 1, fp, nullptr, error); + } + MPI_Bcast(&cut_inner[i][j], 1, MPI_DOUBLE, 0, world); + MPI_Bcast(&cut[i][j], 1, MPI_DOUBLE, 0, world); + } + } +} + +/* ---------------------------------------------------------------------- + proc 0 writes to restart file +------------------------------------------------------------------------- */ + +void PairBrownian::write_restart_settings(FILE *fp) +{ + fwrite(&mu, sizeof(double), 1, fp); + fwrite(&flaglog, sizeof(int), 1, fp); + fwrite(&flagfld, sizeof(int), 1, fp); + fwrite(&cut_inner_global, sizeof(double), 1, fp); + fwrite(&cut_global, sizeof(double), 1, fp); + fwrite(&t_target, sizeof(double), 1, fp); + fwrite(&seed, sizeof(int), 1, fp); + fwrite(&offset_flag, sizeof(int), 1, fp); + fwrite(&mix_flag, sizeof(int), 1, fp); + fwrite(&flagHI, sizeof(int), 1, fp); + fwrite(&flagVF, sizeof(int), 1, fp); +} + +/* ---------------------------------------------------------------------- + proc 0 reads from restart file, bcasts +------------------------------------------------------------------------- */ + +void PairBrownian::read_restart_settings(FILE *fp) +{ + int me = comm->me; + if (me == 0) { + utils::sfread(FLERR, &mu, sizeof(double), 1, fp, nullptr, error); + utils::sfread(FLERR, &flaglog, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &flagfld, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &cut_inner_global, sizeof(double), 1, fp, nullptr, error); + utils::sfread(FLERR, &cut_global, sizeof(double), 1, fp, nullptr, error); + utils::sfread(FLERR, &t_target, sizeof(double), 1, fp, nullptr, error); + utils::sfread(FLERR, &seed, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &offset_flag, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &mix_flag, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &flagHI, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &flagVF, sizeof(int), 1, fp, nullptr, error); + } + MPI_Bcast(&mu, 1, MPI_DOUBLE, 0, world); + MPI_Bcast(&flaglog, 1, MPI_INT, 0, world); + MPI_Bcast(&flagfld, 1, MPI_INT, 0, world); + MPI_Bcast(&cut_inner_global, 1, MPI_DOUBLE, 0, world); + MPI_Bcast(&cut_global, 1, MPI_DOUBLE, 0, world); + MPI_Bcast(&t_target, 1, MPI_DOUBLE, 0, world); + MPI_Bcast(&seed, 1, MPI_INT, 0, world); + MPI_Bcast(&offset_flag, 1, MPI_INT, 0, world); + MPI_Bcast(&mix_flag, 1, MPI_INT, 0, world); + MPI_Bcast(&flagHI, 1, MPI_INT, 0, world); + MPI_Bcast(&flagVF, 1, MPI_INT, 0, world); + + // additional setup based on restart parameters + + delete random; + random = new RanMars(lmp, seed + comm->me); +} + +/* ----------------------------------------------------------------------*/ + +void PairBrownian::set_3_orthogonal_vectors(double p1[3], double p2[3], double p3[3]) +{ + double norm; + int ix, iy, iz; + + // find the index of maximum magnitude and store it in iz + + if (fabs(p1[0]) > fabs(p1[1])) { + iz = 0; + ix = 1; + iy = 2; + } else { + iz = 1; + ix = 2; + iy = 0; + } + + if (iz == 0) { + if (fabs(p1[0]) < fabs(p1[2])) { + iz = 2; + ix = 0; + iy = 1; + } + } else { + if (fabs(p1[1]) < fabs(p1[2])) { + iz = 2; + ix = 0; + iy = 1; + } + } + + // set p2 arbitrarily such that it's orthogonal to p1 + + p2[ix] = 1.0; + p2[iy] = 1.0; + p2[iz] = -(p1[ix] * p2[ix] + p1[iy] * p2[iy]) / p1[iz]; + + // normalize p2 + + norm = sqrt(p2[0] * p2[0] + p2[1] * p2[1] + p2[2] * p2[2]); + + p2[0] = p2[0] / norm; + p2[1] = p2[1] / norm; + p2[2] = p2[2] / norm; + + // Set p3 by taking the cross product p3=p2xp1 + + p3[0] = p1[1] * p2[2] - p1[2] * p2[1]; + p3[1] = p1[2] * p2[0] - p1[0] * p2[2]; + p3[2] = p1[0] * p2[1] - p1[1] * p2[0]; +} diff --git a/src/USER-SUMAN/pair_brownian.h b/src/USER-SUMAN/pair_brownian.h new file mode 100644 index 0000000000..8087328fce --- /dev/null +++ b/src/USER-SUMAN/pair_brownian.h @@ -0,0 +1,64 @@ +/* -*- 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(brownian,PairBrownian); +// clang-format on +#else + +#ifndef LMP_PAIR_BROWNIAN_H +#define LMP_PAIR_BROWNIAN_H + +#include "pair.h" + +namespace LAMMPS_NS { + +class PairBrownian : public Pair { + public: + PairBrownian(class LAMMPS *); + ~PairBrownian() override; + void compute(int, int) override; + void settings(int, char **) override; + void coeff(int, char **) override; + double init_one(int, int) override; + void init_style() override; + void write_restart(FILE *) override; + void read_restart(FILE *) override; + void write_restart_settings(FILE *) override; + void read_restart_settings(FILE *) override; + + protected: + double cut_inner_global, cut_global; + double t_target, mu; + int flaglog, flagfld; + int flagHI, flagVF; + int flagdeform, flagwall; + double vol_P; + double rad; + class FixWall *wallfix; + + int seed; + double **cut_inner, **cut; + double R0, RT0; + + class RanMars *random; + + void set_3_orthogonal_vectors(double *, double *, double *); + virtual void allocate(); +}; + +} // namespace LAMMPS_NS + +#endif +#endif diff --git a/src/USER-SUMAN/pair_brownian_kokkos.cpp b/src/USER-SUMAN/pair_brownian_kokkos.cpp new file mode 100644 index 0000000000..1aeb80bf21 --- /dev/null +++ b/src/USER-SUMAN/pair_brownian_kokkos.cpp @@ -0,0 +1,727 @@ +// 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 "pair_brownian_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "error.h" +#include "fix.h" +#include "fix_wall.h" +#include "force.h" +#include "input.h" +#include "kokkos.h" +#include "math_const.h" +#include "math_special_kokkos.h" +#include "memory_kokkos.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" +#include "variable.h" + +#include + +using namespace LAMMPS_NS; +using namespace MathConst; +using namespace MathSpecialKokkos; + +// same as fix_wall.cpp + +enum { EDGE, CONSTANT, VARIABLE }; + +#define _NO_RANDOM + +/* ---------------------------------------------------------------------- */ + +template +PairBrownianKokkos::PairBrownianKokkos(LAMMPS *lmp) : PairBrownian(lmp), + rand_pool(seed + comm->me) +{ + respa_enable = 0; + + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TORQUE_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK | RADIUS_MASK; + datamask_modify = F_MASK | TORQUE_MASK | ENERGY_MASK | VIRIAL_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +PairBrownianKokkos::~PairBrownianKokkos() +{ + if (copymode) return; + + if (allocated) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->destroy_kokkos(k_vatom,vatom); + // eatom = nullptr; + // vatom = nullptr; + + memoryKK->destroy_kokkos(k_cut_inner,cut_inner); + memoryKK->destroy_kokkos(k_cutsq,cutsq); + } +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairBrownianKokkos::init_style() +{ + PairBrownian::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // adjust neighbor list request for KOKKOS + + neighflag = lmp->kokkos->neighflag; + auto request = neighbor->find_request(this); + request->set_kokkos_host(std::is_same_v && + !std::is_same_v); + request->set_kokkos_device(std::is_same_v); + //if (neighflag == FULL) request->enable_full(); + if (neighflag == FULL) + error->all(FLERR,"Must use half neighbor list with brownian/kk"); + + printf("PairBrownianKokkos::init_style() flagdeform= %i flagwall= %i flaglog= %i R0= %f RT0= %f\n",flagdeform,flagwall,flaglog,R0,RT0); +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +template +void PairBrownianKokkos::coeff(int narg, char **arg) +{ + PairBrownian::coeff(narg,arg); +} +/* ---------------------------------------------------------------------- */ + +template +void PairBrownianKokkos::compute(int eflag_in, int vflag_in) +{ + printf("Inside compute()\n"); + + copymode = 1; + + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL) no_virial_fdotr_compute = 1; + + ev_init(eflag,vflag,0); + + // This section of code adjusts R0/RT0/RS0 if necessary due to changes + // in the volume fraction as a result of fix deform or moving walls + + printf("PairBrownianKokkos::compute() flagVF= %i flagdeform= %i flagwall= %i flaglog= %i\n",flagVF,flagdeform,flagwall,flaglog); + + double dims[3], wallcoord; + if (flagVF) // Flag for volume fraction corrections + if (flagdeform || flagwall == 2) { // Possible changes in volume fraction + if (flagdeform && !flagwall) + for (int j = 0; j < 3; j++) dims[j] = domain->prd[j]; + else if (flagwall == 2 || (flagdeform && flagwall == 1)) { + double wallhi[3], walllo[3]; + for (int j = 0; j < 3; j++) { + wallhi[j] = domain->prd[j]; + walllo[j] = 0; + } + for (int m = 0; m < wallfix->nwall; m++) { + int dim = wallfix->wallwhich[m] / 2; + int side = wallfix->wallwhich[m] % 2; + if (wallfix->xstyle[m] == VARIABLE) { + wallcoord = input->variable->compute_equal(wallfix->xindex[m]); + } else + wallcoord = wallfix->coord0[m]; + if (side == 0) + walllo[dim] = wallcoord; + else + wallhi[dim] = wallcoord; + } + for (int j = 0; j < 3; j++) dims[j] = wallhi[j] - walllo[j]; + } + double vol_T = dims[0] * dims[1] * dims[2]; + double vol_f = vol_P / vol_T; + if (flaglog == 0) { + R0 = 6 * MY_PI * mu * rad * (1.0 + 2.16 * vol_f); + RT0 = 8 * MY_PI * mu * cube(rad); + //RS0 = 20.0/3.0*MY_PI*mu*pow(rad,3)*(1.0 + 3.33*vol_f + 2.80*vol_f*vol_f); + } else { + R0 = 6 * MY_PI * mu * rad * (1.0 + 2.725 * vol_f - 6.583 * vol_f * vol_f); + RT0 = 8 * MY_PI * mu * cube(rad) * (1.0 + 0.749 * vol_f - 2.469 * vol_f * vol_f); + //RS0 = 20.0/3.0*MY_PI*mu*pow(rad,3)*(1.0 + 3.64*vol_f - 6.95*vol_f*vol_f); + } + } + + // scale factor for Brownian moments + + prethermostat = sqrt(24.0 * force->boltz * t_target / update->dt); + prethermostat *= sqrt(force->vxmu2f / force->ftm2v / force->mvv2e); + + printf("PairBrownianKokkos::compute() prethermostat= %f R0= %f RT0= %f\n",prethermostat, R0, RT0); + + // reallocate per-atom arrays if necessary + + if (eflag_atom) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); + d_eatom = k_eatom.view(); + } + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK | TORQUE_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + torque = atomKK->k_torque.view(); + type = atomKK->k_type.view(); + radius = atomKK->k_radius.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + newton_pair = force->newton_pair; + vxmu2f = force->vxmu2f; + + // loop over neighbors of my atoms + + int inum = list->inum; + NeighListKokkos* k_list = static_cast*>(list); + d_numneigh = k_list->d_numneigh; + d_neighbors = k_list->d_neighbors; + d_ilist = k_list->d_ilist; + + EV_FLOAT ev; + + printf(" -- starting parallel_for() neighflag= %i HALF= %i newton_pair= %i vflag_atom= %i flagfld= %i vflag_global= %i\n", + neighflag, HALF, force->newton_pair, vflag_atom, flagfld, vflag_global); + if (neighflag == HALF) { + if (force->newton_pair) { + if (vflag_atom) { + if (flagfld) { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } else { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } + } else if (vflag_global) { + if (flagfld) { + Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); + } else { + Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); + } + } else { + if (flagfld) { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } else { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } + } + } else { + if (vflag_atom) { + if (flagfld) { + printf("Step 0\n"); + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } else { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } + } else if (vflag_global) { + if (flagfld) { + printf(" -- Step N\n"); + Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); + } else { + Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); + } + } else { + if (flagfld) { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } else { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } + } + } + } else { // HALFTHREAD + if (force->newton_pair) { + if (vflag_atom) { + if (flagfld) { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } else { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } + } else if (vflag_global) { + if (flagfld) { + Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); + } else { + Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); + } + } else { + if (flagfld) { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } else { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } + } + } else { + if (vflag_atom) { + if (flagfld) { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } else { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } + } else if (vflag_global) { + if (flagfld) { + Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); + } else { + Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); + } + } else { + if (flagfld) { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } else { + Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); + } + } + } + } + printf(" -- finished\n"); + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.template sync(); + } + + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.template sync(); + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + printf("i= %i vatom= %f %f %f %f %f %f\n",0,vatom[0][0],vatom[0][1],vatom[0][2],vatom[0][3],vatom[0][4],vatom[0][5]); + + copymode = 0; + + printf("Leaving compute()\n"); +} + +template +template +KOKKOS_INLINE_FUNCTION +void PairBrownianKokkos::operator()(TagPairBrownianCompute, const int ii, EV_FLOAT &ev) const { + + // printf("Inside TagPairBrownianCompute<>() ii= %i\n",ii); + + // The f and torque arrays are atomic for Half/Thread neighbor style + Kokkos::View::value,Kokkos::MemoryTraits::value> > a_f = f; + Kokkos::View::value,Kokkos::MemoryTraits::value> > a_torque = torque; + + rand_type rand_gen = rand_pool.get_state(); + + const int i = d_ilist[ii]; + const X_FLOAT xtmp = x(i,0); + const X_FLOAT ytmp = x(i,1); + const X_FLOAT ztmp = x(i,2); + const int itype = type[i]; + const LMP_FLOAT radi = radius[i]; + const int jnum = d_numneigh[i]; + + LMP_FLOAT a_sq, a_sh, a_pu; + LMP_FLOAT xl[3], p1[3], p2[3], p3[3]; + + F_FLOAT fx_i = 0.0; + F_FLOAT fy_i = 0.0; + F_FLOAT fz_i = 0.0; + + F_FLOAT torquex_i = 0.0; + F_FLOAT torquey_i = 0.0; + F_FLOAT torquez_i = 0.0; + +#if 1 +#ifdef _NO_RANDOM + if (FLAGFLD) { + fx_i = prethermostat * sqrt(R0) * 0.5; + fy_i = prethermostat * sqrt(R0) * 0.5; + fz_i = prethermostat * sqrt(R0) * 0.5; + if (flaglog) { + torquex_i = prethermostat * sqrt(RT0) * 0.5; + torquey_i = prethermostat * sqrt(RT0) * 0.5; + torquez_i = prethermostat * sqrt(RT0) * 0.5; + } + } +#else + if (FLAGFLD) { + fx_i = prethermostat * sqrt(R0) * (rand_gen.drand() - 0.5); + fy_i = prethermostat * sqrt(R0) * (rand_gen.drand() - 0.5); + fz_i = prethermostat * sqrt(R0) * (rand_gen.drand() - 0.5); + if (flaglog) { + torquex_i = prethermostat * sqrt(RT0) * (rand_gen.drand() - 0.5); + torquey_i = prethermostat * sqrt(RT0) * (rand_gen.drand() - 0.5); + torquez_i = prethermostat * sqrt(RT0) * (rand_gen.drand() - 0.5); + } + } +#endif +#endif + +#if 1 + if (flagHI) { + + for (int jj = 0; jj < jnum; jj++) { + int j = d_neighbors(i,jj); + j &= NEIGHMASK; + + const X_FLOAT delx = xtmp - x(j,0); + const X_FLOAT dely = ytmp - x(j,1); + const X_FLOAT delz = ztmp - x(j,2); + const X_FLOAT rsq = delx*delx + dely*dely + delz*delz; + const int jtype = type[j]; + + if(rsq < d_cutsq(itype,jtype)) { + + const LMP_FLOAT r = sqrt(rsq); + + // scalar resistances a_sq and a_sh + + LMP_FLOAT h_sep = r - 2.0 * radi; + + // if less than minimum gap, use minimum gap instead + + if (r < d_cut_inner(itype,jtype)) h_sep = d_cut_inner(itype,jtype) - 2.0 * radi; + + // scale h_sep by radi + + h_sep = h_sep / radi; + + if (flaglog) { + a_sq = 6.0 * MY_PI * mu * radi * (1.0 / 4.0 / h_sep + 9.0 / 40.0 * log(1.0 / h_sep)); + a_sh = 6.0 * MY_PI * mu * radi * (1.0 / 6.0 * log(1.0 / h_sep)); + a_pu = 8.0 * MY_PI * mu * cube(radi) * (3.0 / 160.0 * log(1.0 / h_sep)); + } else + a_sq = 6.0 * MY_PI * mu * radi * (1.0 / 4.0 / h_sep); + + // generate the Pairwise Brownian Force: a_sq + + LMP_FLOAT Fbmag = prethermostat * sqrt(a_sq); + + // generate a random number + +#ifdef _NO_RANDOM + LMP_FLOAT randr = 0.5; +#else + LMP_FLOAT randr = rand_gen.drand() - 0.5; +#endif + + // contribution due to Brownian motion + + F_FLOAT fx = Fbmag * randr * delx / r; + F_FLOAT fy = Fbmag * randr * dely / r; + F_FLOAT fz = Fbmag * randr * delz / r; + + // add terms due to a_sh +#if 1 + if (flaglog) { + + // generate two orthogonal vectors to the line of centers + + p1[0] = delx / r; + p1[1] = dely / r; + p1[2] = delz / r; + set_3_orthogonal_vectors(p1, p2, p3); + + // magnitude + + Fbmag = prethermostat * sqrt(a_sh); + + // force in each of the two directions + +#ifdef _NO_RANDOM + randr = 0.5; +#else + randr = rand_gen.drand() - 0.5; +#endif + fx += Fbmag * randr * p2[0]; + fy += Fbmag * randr * p2[1]; + fz += Fbmag * randr * p2[2]; + +#ifndef _NO_RANDOM + randr = rand_gen.drand() - 0.5; +#endif + fx += Fbmag * randr * p3[0]; + fy += Fbmag * randr * p3[1]; + fz += Fbmag * randr * p3[2]; + } +#endif + // scale forces to appropriate units + + fx = vxmu2f * fx; + fy = vxmu2f * fy; + fz = vxmu2f * fz; + + // sum to total force + + fx_i -= fx; + fy_i -= fy; + fz_i -= fz; + + if (NEWTON_PAIR || j < nlocal) { + a_f(j,0) += fx; + a_f(j,1) += fy; + a_f(j,2) += fz; + } + + // torque due to the Brownian Force + + if (flaglog) { + + // location of the point of closest approach on I from its center + + xl[0] = -delx / r * radi; + xl[1] = -dely / r * radi; + xl[2] = -delz / r * radi; + + // torque = xl_cross_F + + F_FLOAT tx = xl[1] * fz - xl[2] * fy; + F_FLOAT ty = xl[2] * fx - xl[0] * fz; + F_FLOAT tz = xl[0] * fy - xl[1] * fx; + + // torque is same on both particles + + torquex_i -= tx; + torquey_i -= ty; + torquez_i -= tz; + + if (NEWTON_PAIR || j < nlocal) { + a_torque(j,0) -= tx; + a_torque(j,1) -= ty; + a_torque(j,2) -= tz; + } + + // torque due to a_pu + + Fbmag = prethermostat * sqrt(a_pu); + + // force in each direction + +#ifdef _NO_RANDOM + randr = 0.5; +#else + randr = rand_gen.drand() - 0.5; +#endif + tx = Fbmag * randr * p2[0]; + ty = Fbmag * randr * p2[1]; + tz = Fbmag * randr * p2[2]; + +#ifndef _NO_RANDOM + randr = rand_gen.drand() - 0.5; +#endif + tx += Fbmag * randr * p3[0]; + ty += Fbmag * randr * p3[1]; + tz += Fbmag * randr * p3[2]; + + // torque has opposite sign on two particles + + torquex_i -= tx; + torquey_i -= ty; + torquez_i -= tz; + + if (NEWTON_PAIR || j < nlocal) { + a_torque(j,0) += tx; + a_torque(j,1) += ty; + a_torque(j,2) += tz; + } + } + + if (EVFLAG == 2) + ev_tally_xyz_atom(ev, i, j, -fx, -fy, -fz, delx, dely, delz); + if (EVFLAG == 1) + ev_tally_xyz(ev, i, j, -fx, -fy, -fz, delx, dely, delz); + } + } + + } // if(flagHI) +#endif + + rand_pool.free_state(rand_gen); + + if(ii == 0) printf("ii= %i i= %i f(before)= %f %f %f df= %f %f %f\n",ii,i,a_f(i,0),a_f(i,1),a_f(i,2),fx_i,fy_i,fz_i); + + a_f(i,0) += fx_i; + a_f(i,1) += fy_i; + a_f(i,2) += fz_i; + a_torque(i,0) += torquex_i; + a_torque(i,1) += torquey_i; + a_torque(i,2) += torquez_i; + + if(ii == 0) printf("ii= %i i= %i f(after)= %f %f %f\n",ii,i,a_f(i,0),a_f(i,1),a_f(i,2)); + + // printf(" -- leaving %i\n",ii); +} + +template +template +KOKKOS_INLINE_FUNCTION +void PairBrownianKokkos::operator()(TagPairBrownianCompute, const int ii) const { + EV_FLOAT ev; + this->template operator()(TagPairBrownianCompute(), ii, ev); +} + +template +template +KOKKOS_INLINE_FUNCTION +void PairBrownianKokkos::ev_tally_xyz(EV_FLOAT &ev, int i, int j, + F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, + X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const +{ + F_FLOAT v[6]; + + v[0] = delx*fx; + v[1] = dely*fy; + v[2] = delz*fz; + v[3] = delx*fy; + v[4] = delx*fz; + v[5] = dely*fz; + + if (NEWTON_PAIR) { + ev.v[0] += v[0]; + ev.v[1] += v[1]; + ev.v[2] += v[2]; + ev.v[3] += v[3]; + ev.v[4] += v[4]; + ev.v[5] += v[5]; + } else { + if (i < nlocal) { + ev.v[0] += 0.5*v[0]; + ev.v[1] += 0.5*v[1]; + ev.v[2] += 0.5*v[2]; + ev.v[3] += 0.5*v[3]; + ev.v[4] += 0.5*v[4]; + ev.v[5] += 0.5*v[5]; + } + if (j < nlocal) { + ev.v[0] += 0.5*v[0]; + ev.v[1] += 0.5*v[1]; + ev.v[2] += 0.5*v[2]; + ev.v[3] += 0.5*v[3]; + ev.v[4] += 0.5*v[4]; + ev.v[5] += 0.5*v[5]; + } + } +} + +template +template +KOKKOS_INLINE_FUNCTION +void PairBrownianKokkos::ev_tally_xyz_atom(EV_FLOAT & /*ev*/, int i, int j, + F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, + X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const +{ + Kokkos::View::value,Kokkos::MemoryTraits::value> > v_vatom = k_vatom.view(); + + F_FLOAT v[6]; + + v[0] = delx*fx; + v[1] = dely*fy; + v[2] = delz*fz; + v[3] = delx*fy; + v[4] = delx*fz; + v[5] = dely*fz; + + if (NEWTON_PAIR || i < nlocal) { + v_vatom(i,0) += 0.5*v[0]; + v_vatom(i,1) += 0.5*v[1]; + v_vatom(i,2) += 0.5*v[2]; + v_vatom(i,3) += 0.5*v[3]; + v_vatom(i,4) += 0.5*v[4]; + v_vatom(i,5) += 0.5*v[5]; + } + if (NEWTON_PAIR || j < nlocal) { + v_vatom(j,0) += 0.5*v[0]; + v_vatom(j,1) += 0.5*v[1]; + v_vatom(j,2) += 0.5*v[2]; + v_vatom(j,3) += 0.5*v[3]; + v_vatom(j,4) += 0.5*v[4]; + v_vatom(j,5) += 0.5*v[5]; + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairBrownianKokkos::allocate() +{ + PairBrownian::allocate(); + + int n = atom->ntypes; + memory->destroy(cutsq); + // memory->destroy(cut); + memory->destroy(cut_inner); + + memoryKK->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + + // memoryKK->create_kokkos(k_cut,cut,n+1,n+1,"pair:cut"); + memoryKK->create_kokkos(k_cut_inner,cut_inner,n+1,n+1,"pair:cut_inner"); + // d_cut = k_cut.template view(); + d_cut_inner = k_cut_inner.template view(); +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairBrownianKokkos::settings(int narg, char **arg) +{ + if (narg != 7 && narg != 9) error->all(FLERR, "Illegal pair_style command"); + + PairBrownian::settings(narg,arg); +} + +namespace LAMMPS_NS { +template class PairBrownianKokkos; +#ifdef LMP_KOKKOS_GPU +template class PairBrownianKokkos; +#endif +} + diff --git a/src/USER-SUMAN/pair_brownian_kokkos.h b/src/USER-SUMAN/pair_brownian_kokkos.h new file mode 100644 index 0000000000..ae7632f40f --- /dev/null +++ b/src/USER-SUMAN/pair_brownian_kokkos.h @@ -0,0 +1,165 @@ +/* -*- 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(brownian/kk,PairBrownianKokkos); +PairStyle(brownian/kk/device,PairBrownianKokkos); +PairStyle(brownian/kk/host,PairBrownianKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_PAIR_BROWNIAN_KOKKOS_H +#define LMP_PAIR_BROWNIAN_KOKKOS_H + +#include "pair_brownian.h" +#include "pair_kokkos.h" +#include "kokkos_type.h" +#include "kokkos_base.h" +#include "Kokkos_Random.hpp" +#include "comm_kokkos.h" + +namespace LAMMPS_NS { + +template +struct TagPairBrownianCompute {}; + +template +class PairBrownianKokkos : public PairBrownian, public KokkosBase { + public: + typedef DeviceType device_type; + typedef ArrayTypes AT; + typedef EV_FLOAT value_type; + + PairBrownianKokkos(class LAMMPS *); + ~PairBrownianKokkos() override; + void compute(int, int) override; + void coeff(int, char **) override; + void settings(int, char **) override; + void init_style() override; + + template + KOKKOS_INLINE_FUNCTION + void operator()(TagPairBrownianCompute, const int, EV_FLOAT &ev) const; + template + KOKKOS_INLINE_FUNCTION + void operator()(TagPairBrownianCompute, const int) const; + + template + KOKKOS_INLINE_FUNCTION + void ev_tally_xyz(EV_FLOAT &ev, int i, int j, + F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, + X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const; + template + KOKKOS_INLINE_FUNCTION + void ev_tally_xyz_atom(EV_FLOAT &ev, int i, int j, + F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, + X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const; + + protected: + typename AT::t_x_array_randomread x; + typename AT::t_x_array c_x; + typename AT::t_f_array f; + typename AT::t_f_array torque; + typename AT::t_int_1d_randomread type; + typename AT::t_float_1d_randomread radius; + + DAT::tdual_efloat_1d k_eatom; + DAT::tdual_virial_array k_vatom; + typename AT::t_efloat_1d d_eatom; + typename AT::t_virial_array d_vatom; + + typename AT::t_neighbors_2d d_neighbors; + typename AT::t_int_1d_randomread d_ilist; + typename AT::t_int_1d_randomread d_numneigh; + + int newton_pair; + double special_lj[4]; + + typename AT::tdual_ffloat_2d k_cutsq; + typename AT::t_ffloat_2d d_cutsq; + typename AT::tdual_ffloat_2d k_cut_inner; + typename AT::t_ffloat_2d d_cut_inner; + + int neighflag; + int nlocal,nall,eflag,vflag; + LMP_FLOAT vxmu2f; + + LMP_FLOAT prethermostat; + + void allocate() override; + + KOKKOS_INLINE_FUNCTION + void set_3_orthogonal_vectors(const double p1[3], double * const p2, double * const p3) const { + double norm; + int ix, iy, iz; + + // find the index of maximum magnitude and store it in iz + + if (fabs(p1[0]) > fabs(p1[1])) { + iz = 0; + ix = 1; + iy = 2; + } else { + iz = 1; + ix = 2; + iy = 0; + } + + if (iz == 0) { + if (fabs(p1[0]) < fabs(p1[2])) { + iz = 2; + ix = 0; + iy = 1; + } + } else { + if (fabs(p1[1]) < fabs(p1[2])) { + iz = 2; + ix = 0; + iy = 1; + } + } + + // set p2 arbitrarily such that it's orthogonal to p1 + + p2[ix] = 1.0; + p2[iy] = 1.0; + p2[iz] = -(p1[ix] * p2[ix] + p1[iy] * p2[iy]) / p1[iz]; + + // normalize p2 + + norm = sqrt(p2[0] * p2[0] + p2[1] * p2[1] + p2[2] * p2[2]); + + p2[0] = p2[0] / norm; + p2[1] = p2[1] / norm; + p2[2] = p2[2] / norm; + + // Set p3 by taking the cross product p3=p2xp1 + + p3[0] = p1[1] * p2[2] - p1[2] * p2[1]; + p3[1] = p1[2] * p2[0] - p1[0] * p2[2]; + p3[2] = p1[0] * p2[1] - p1[1] * p2[0]; + }; + + friend void pair_virial_fdotr_compute(PairBrownianKokkos*); + + Kokkos::Random_XorShift64_Pool rand_pool; + typedef typename Kokkos::Random_XorShift64_Pool::generator_type rand_type; +}; + +} + +#endif +#endif + diff --git a/src/USER-SUMAN/pair_lubricate_Simple.cpp b/src/USER-SUMAN/pair_lubricate_Simple.cpp new file mode 100644 index 0000000000..8eb7887bf2 --- /dev/null +++ b/src/USER-SUMAN/pair_lubricate_Simple.cpp @@ -0,0 +1,398 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator +http://lammps.sandia.gov, 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 authors: Randy Schunk (SNL) + Amit Kumar and Michael Bybee (UIUC) + Dave Heine (Corning), polydispersity + ------------------------------------------------------------------------- */ +/* Modified by Ranga on 27/05/2017 from the GRM formulation + given by Kim and Karilla, Microhydrodynamics */ + +#include +#include +#include +#include +#include "pair_lubricate_Simple.h" +#include "atom.h" +#include "atom_vec.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#if 0 +#include "neigh_request.h" +#endif +#include "domain.h" +#include "modify.h" +#include "fix.h" +#include "fix_deform.h" +#include "memory.h" +#include "random_mars.h" +#include "fix_wall.h" +#include "input.h" +#include "variable.h" +#include "math_const.h" +#include "error.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +// same as fix_deform.cpp + +enum{NO_REMAP,X_REMAP,V_REMAP}; + + +// same as fix_wall.cpp + +enum{EDGE,CONSTANT,VARIABLE}; + +/* ---------------------------------------------------------------------- */ + +PairLubricateSimple::PairLubricateSimple(LAMMPS *lmp) : PairLubricate(lmp) +{ + no_virial_fdotr_compute = 1; +} + +/* ---------------------------------------------------------------------- */ + +void PairLubricateSimple::compute(int eflag, int vflag) +{ + int i,j,ii,jj,inum,jnum,itype,jtype; + double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz,tx,ty,tz; + double rsq,r,h_sep,beta0,beta1,radi,radj; + double vr1,vr2,vr3,vnnr,vn1,vn2,vn3; + double vt1,vt2,vt3; + int *ilist,*jlist,*numneigh,**firstneigh; + double lamda[3],vstream[3]; + + double vxmu2f = force->vxmu2f; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + double **x = atom->x; + double **v = atom->v; + double **f = atom->f; + double **omega = atom->omega; + double **torque = atom->torque; + double *radius = atom->radius; + 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; + + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + itype = type[i]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + radi = radius[i]; + + // Drag contribution to force and torque due to isotropic terms + // Drag contribution to stress from isotropic RS0 + + if (flagfld) { + + domain->x2lamda(x[i],lamda); + double *h_rate = domain->h_rate; + double *h_ratelo = domain->h_ratelo; + vstream[0] = h_rate[0]*lamda[0] + h_rate[5]*lamda[1] + + h_rate[4]*lamda[2] + h_ratelo[0]; + vstream[1] = h_rate[1]*lamda[1] + h_rate[3]*lamda[2] + h_ratelo[1]; + vstream[2] = h_rate[2]*lamda[2] + h_ratelo[2]; + + + R0 = 6.0*MY_PI*mu; + RT0 = 8.0*MY_PI*mu; + RS0 = 20.0/3.0*MY_PI*mu; + + f[i][0] += vxmu2f*R0*radi*(vstream[0]-v[i][0]); + f[i][1] += vxmu2f*R0*radi*(vstream[1]-v[i][1]); + f[i][2] += vxmu2f*R0*radi*(vstream[2]-v[i][2]); + + const double radi3 = radi*radi*radi; + + torque[i][0] -= vxmu2f*RT0*radi3*(omega[i][0]+0.5*h_rate[3]/domain->zprd); + torque[i][1] -= vxmu2f*RT0*radi3*(omega[i][1]-0.5*h_rate[4]/domain->zprd); + torque[i][2] -= vxmu2f*RT0*radi3*(omega[i][2]+0.5*h_rate[5]/domain->yprd); + // Ef = (grad(vstream) + (grad(vstream))^T) / 2 + // set Ef from h_rate in strain units + if(shearing){ + Ef[0][0] = h_rate[0]/domain->xprd; + Ef[1][1] = h_rate[1]/domain->yprd; + Ef[2][2] = h_rate[2]/domain->zprd; + Ef[0][1] = Ef[1][0] = 0.5 * h_rate[5]/domain->yprd; + Ef[0][2] = Ef[2][0] = 0.5 * h_rate[4]/domain->zprd; + Ef[1][2] = Ef[2][1] = 0.5 * h_rate[3]/domain->zprd; + + + if (vflag_either) { + double vRS0 = -vxmu2f * RS0*radi3; + v_tally_tensor(i,i,nlocal,newton_pair, + vRS0*Ef[0][0],vRS0*Ef[1][1],vRS0*Ef[2][2], + vRS0*Ef[0][1],vRS0*Ef[0][2],vRS0*Ef[1][2]); + } + } + + } + + if (!flagHI)continue; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + jtype = type[j]; + radj = atom->radius[j]; + double radsum = radi+radj; //Sum of two particle's radii + + if (rsq < cutsq[itype][jtype] and rsq < (1.45*1.45*radsum*radsum) ) { + r = sqrt(rsq); + + + // scalar resistances XA and YA + + h_sep = r - radsum; + + // if less than the minimum gap use the minimum gap instead + + if (r < cut_inner[itype][jtype]*radsum) //Scaled inner cutoff by particle radii + h_sep = cut_inner[itype][jtype]*radsum - radsum; + + double hinv,lhinv,XA11=0.0,YA11=0.0,YB11=0.0,YC12=0.0,ws[3],wd[3],nx,ny,nz; + ws[0] = (omega[i][0]+omega[j][0])/2.0; + ws[1] = (omega[i][1]+omega[j][1])/2.0; + ws[2] = (omega[i][2]+omega[j][2])/2.0; + + wd[0] = (omega[i][0]-omega[j][0])/2.0; + wd[1] = (omega[i][1]-omega[j][1])/2.0; + wd[2] = (omega[i][2]-omega[j][2])/2.0; + + nx=-delx/r;ny=-dely/r;nz=-delz/r; + + + hinv=(radi+radj)/(2.0*h_sep); + lhinv=log(hinv); + + if(lhinv < 0) error->all(FLERR,"Using pair lubricate with cutoff problem: log(1/h) is negative"); + + beta0=radj/radi; + beta1=1.0+beta0; + + double b0p2,b1p2,b1p3,mupradi; + b0p2=beta0*beta0; + b1p2=beta1*beta1; + b1p3=beta1*b1p2; + mupradi=mu*MY_PI*radi; + + // scalar resistances + if (flaglog) { + XA11=6.0*mupradi*( hinv*2.0*b0p2 + lhinv*beta0*(1.0+ 7.0*beta0+ b0p2 )/5.0 )/b1p3; + YA11=1.6*mupradi*lhinv*beta0*(2.0+beta0+2.0*b0p2)/b1p3; + YB11=-0.8*mupradi*radi*lhinv*beta0*(4.0+beta0)/b1p2; + YC12=0.8*mupradi*radi*radi*lhinv*b0p2/beta1*(1.0-4.0/beta0); //YC12*(1-4/beta0) + } + else XA11=12.0*mupradi*hinv*b0p2/b1p3; + + + + /* + if (flaglog) { + XA11=6.0*MY_PI*mu*radi*( hinv*2.0*pow(beta0,2.0) + lhinv*beta0*(1.0+ 7.0*beta0+ beta0*beta0)/5.0 )/pow(beta1,3.0); + YA11=1.6*MY_PI*mu*radi*lhinv*beta0*(2.0+beta0+2.0*beta0*beta0)/pow(beta1,3.0); + YB11=-0.8*MY_PI*mu*radi*radi*lhinv*beta0*(4.0+beta0)/(beta1*beta1); + YC12=0.8*MY_PI*mu*pow(radi,3.0)*lhinv*beta0*beta0/beta1*(1.0-4.0/beta0); //YC12*(1-4/beta0) + } + else XA11=12*MY_PI*mu*radi*hinv*pow(beta0,2.0)/pow(beta1,3.0); + */ + // Relative velocity components U^2-U^1 + vr1 = v[j][0] - v[i][0]; + vr2 = v[j][1] - v[i][1]; + vr3 = v[j][2] - v[i][2]; + + // normal component (vr.n)n + + vnnr = vr1*nx + vr2*ny + vr3*nz; + vn1 = vnnr*nx; + vn2 = vnnr*ny; + vn3 = vnnr*nz; + + // tangential component vr - (vr.n)n + + vt1 = vr1 - vn1; + vt2 = vr2 - vn2; + vt3 = vr3 - vn3; + + // force due to squeeze type motion + //f=XA11 nn dot vr + fx = XA11*vn1; + fy = XA11*vn2; + fz = XA11*vn3; + + + // force due to all shear kind of motions + + if (flaglog) { + double ybfac=(1.0-beta0*(1.0+4.0*beta0)/(4.0+beta0))*YB11; + //f+=YA11*vt1-(r1+r2)*YA11*ws cross n + ybfac* wd cross n + fx = fx + YA11*(vt1-(radi+radj)*(ws[1]*nz-ws[2]*ny))+ybfac*(wd[1]*nz-wd[2]*ny); + fy = fy + YA11*(vt2-(radi+radj)*(ws[2]*nx-ws[0]*nz))+ybfac*(wd[2]*nx-wd[0]*nz); + fz = fz + YA11*(vt3-(radi+radj)*(ws[0]*ny-ws[1]*nx))+ybfac*(wd[0]*ny-wd[1]*nx); + } + + // scale forces for appropriate units + + fx *= vxmu2f; + fy *= vxmu2f; + fz *= vxmu2f; + + // add to total force + + f[i][0] += fx; + f[i][1] += fy; + f[i][2] += fz; + + // torque due to this force + + if (flaglog) { + double wsdotn,wddotn; + wsdotn=ws[0]*nx+ws[1]*ny+ws[2]*nz; + wddotn=wd[0]*nx+wd[1]*ny+wd[2]*nz; + + //squeeze+shear+pump contributions to torque + //YB11*(vr cross n + (r1+r2)* tang(ws)) +YC12*(1-4/beta)*tang(wd) + tx = YB11*(vr2*nz -vr3*ny + (radi+radj)*(ws[0]-wsdotn*nx)) + YC12*(wd[0]-wddotn*nx); + ty = YB11*(vr3*nx -vr1*nz + (radi+radj)*(ws[1]-wsdotn*ny)) + YC12*(wd[1]-wddotn*ny); + tz = YB11*(vr1*ny -vr2*nx + (radi+radj)*(ws[2]-wsdotn*nz)) + YC12*(wd[2]-wddotn*nz); + + torque[i][0] += vxmu2f*tx; + torque[i][1] += vxmu2f*ty; + torque[i][2] += vxmu2f*tz; + } + + // set j = nlocal so that only I gets tallied + + if (evflag) ev_tally_xyz(i,nlocal,nlocal,0,0.0,0.0,fx,fy,fz,delx,dely,delz); + // + //Add up stresslet for particle i + //v_tally_tensor(i,nlocal,nlocal,newton_pair,fx*delx,fy*dely,fz*delz, + //0.5*(fx*dely+fy*delx),0.5*(fx*delz+fz*delx),0.5*(fy*delz+fz*dely)); + + } + } + } + +} + +/* ---------------------------------------------------------------------- + init specific to this pair style + ------------------------------------------------------------------------- */ + +void PairLubricateSimple::init_style() +{ + if (force->newton_pair == 1) + error->all(FLERR,"Pair lubricate/poly requires newton pair off"); + if (comm->ghost_velocity == 0) + error->all(FLERR, + "Pair lubricate/poly requires ghost atoms store velocity"); + if (!atom->sphere_flag) + error->all(FLERR,"Pair lubricate/poly requires atom style sphere"); + + // ensure all particles are finite-size + // for pair hybrid, should limit test to types using the pair style + + double *radius = atom->radius; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) + if (radius[i] == 0.0) + error->one(FLERR,"Pair lubricate/poly requires extended particles"); + +#if 1 + neighbor->add_request(this, NeighConst::REQ_FULL); +#else + int irequest = neighbor->request(this,instance_me); + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full = 1; +#endif + + // set the isotropic constants that depend on the volume fraction + // vol_T = total volume + + // check for fix deform, if exists it must use "remap v" + // If box will change volume, set appropriate flag so that volume + // and v.f. corrections are re-calculated at every step. + + // Ranga: Volume fraction correction unnecessary for our purposes + // if available volume is different from box volume + // due to walls, set volume appropriately; if walls will + // move, set appropriate flag so that volume and v.f. corrections + // are re-calculated at every step. + + shearing = flagdeform = flagwall = 0; + for (int i = 0; i < modify->nfix; i++){ + if (strcmp(modify->fix[i]->style,"deform") == 0) { + shearing = flagdeform = 1; + if (((FixDeform *) modify->fix[i])->remapflag != V_REMAP) + error->all(FLERR,"Using pair lubricate with inconsistent " + "fix deform remap option"); + } + if (strstr(modify->fix[i]->style,"wall") != NULL) { + if (flagwall) + error->all(FLERR, + "Cannot use multiple fix wall commands with " + "pair lubricate/poly"); + flagwall = 1; // Walls exist + wallfix = (FixWall *) modify->fix[i]; + if (wallfix->xflag) flagwall = 2; // Moving walls exist + } + + if (strstr(modify->fix[i]->style,"wall") != NULL){ + flagwall = 1; // Walls exist + if (((FixWall *) modify->fix[i])->xflag ) { + flagwall = 2; // Moving walls exist + wallfix = (FixWall *) modify->fix[i]; + } + } + } + + // check for fix deform, if exists it must use "remap v" + + shearing = 0; + for (int i = 0; i < modify->nfix; i++) + if (strcmp(modify->fix[i]->style,"deform") == 0) { + shearing = 1; + if (((FixDeform *) modify->fix[i])->remapflag != V_REMAP) + error->all(FLERR,"Using pair lubricate/poly with inconsistent " + "fix deform remap option"); + } + + // set Ef = 0 since used whether shearing or not + + Ef[0][0] = Ef[0][1] = Ef[0][2] = 0.0; + Ef[1][0] = Ef[1][1] = Ef[1][2] = 0.0; + Ef[2][0] = Ef[2][1] = Ef[2][2] = 0.0; +} diff --git a/src/USER-SUMAN/pair_lubricate_Simple.h b/src/USER-SUMAN/pair_lubricate_Simple.h new file mode 100644 index 0000000000..e6fd9fa231 --- /dev/null +++ b/src/USER-SUMAN/pair_lubricate_Simple.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, 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 + +PairStyle(lubricate/Simple,PairLubricateSimple) + +#else + +#ifndef LMP_PAIR_LUBRICATE_SIMPLE_H +#define LMP_PAIR_LUBRICATE_SIMPLE_H + +#include "pair_lubricate.h" + +namespace LAMMPS_NS { + +class PairLubricateSimple : public PairLubricate { + public: + PairLubricateSimple(class LAMMPS *); + ~PairLubricateSimple() {} + void compute(int, int); + void init_style(); +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Pair lubricate/poly requires newton pair off + +Self-explanatory. + +E: Pair lubricate/poly requires ghost atoms store velocity + +Use the comm_modify vel yes command to enable this. + +E: Pair lubricate/poly requires atom style sphere + +Self-explanatory. + +E: Pair lubricate/poly requires extended particles + +One of the particles has radius 0.0. + +E: Using pair lubricate with inconsistent fix deform remap option + +Must use remap v option with fix deform with this pair style. + +E: Cannot use multiple fix wall commands with pair lubricate/poly + +Self-explanatory. + +E: Using pair lubricate/poly with inconsistent fix deform remap option + +If fix deform is used, the remap v option is required. + +*/ From 8ddceeb7afc16969254cfff8c1b9834f29ac0ce6 Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 2 Nov 2023 15:11:44 -0500 Subject: [PATCH 02/43] fix instantiation of compute; now correct pressure on step zero and support for FULL --- src/USER-SUMAN/pair_brownian_kokkos.cpp | 278 ++++++++++-------------- src/USER-SUMAN/pair_brownian_kokkos.h | 18 +- 2 files changed, 124 insertions(+), 172 deletions(-) diff --git a/src/USER-SUMAN/pair_brownian_kokkos.cpp b/src/USER-SUMAN/pair_brownian_kokkos.cpp index 1aeb80bf21..78ffa0a9e2 100644 --- a/src/USER-SUMAN/pair_brownian_kokkos.cpp +++ b/src/USER-SUMAN/pair_brownian_kokkos.cpp @@ -103,9 +103,7 @@ void PairBrownianKokkos::init_style() request->set_kokkos_host(std::is_same_v && !std::is_same_v); request->set_kokkos_device(std::is_same_v); - //if (neighflag == FULL) request->enable_full(); - if (neighflag == FULL) - error->all(FLERR,"Must use half neighbor list with brownian/kk"); + if (neighflag == FULL) request->enable_full(); printf("PairBrownianKokkos::init_style() flagdeform= %i flagwall= %i flaglog= %i R0= %f RT0= %f\n",flagdeform,flagwall,flaglog,R0,RT0); } @@ -224,92 +222,54 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) EV_FLOAT ev; - printf(" -- starting parallel_for() neighflag= %i HALF= %i newton_pair= %i vflag_atom= %i flagfld= %i vflag_global= %i\n", - neighflag, HALF, force->newton_pair, vflag_atom, flagfld, vflag_global); - if (neighflag == HALF) { - if (force->newton_pair) { - if (vflag_atom) { - if (flagfld) { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } - } else if (vflag_global) { - if (flagfld) { - Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); - } else { - Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); - } - } else { - if (flagfld) { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } + printf(" -- starting parallel_for() neighflag= %i HALF= %i newton_pair= %i vflag_either= %i vflag_atom= %i flagfld= %i vflag_global= %i\n", + neighflag, HALF, newton_pair, vflag_either, vflag_atom, flagfld, vflag_global); + if (flagfld) { // FLAGFLD == 1 + if (vflag_either) { // VFLAG == 1 + if (neighflag == HALF) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + } else if (neighflag == HALFTHREAD) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + } else if (neighflag == FULL) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); } - } else { - if (vflag_atom) { - if (flagfld) { - printf("Step 0\n"); - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } - } else if (vflag_global) { - if (flagfld) { - printf(" -- Step N\n"); - Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); - } else { - Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); - } - } else { - if (flagfld) { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } + } else { // VFLAG==0 + if (neighflag == HALF) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + } else if (neighflag == HALFTHREAD) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + } else if (neighflag == FULL) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); } } - } else { // HALFTHREAD - if (force->newton_pair) { - if (vflag_atom) { - if (flagfld) { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } - } else if (vflag_global) { - if (flagfld) { - Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); - } else { - Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); - } - } else { - if (flagfld) { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } + } else { // FLAGFLD == 0 + if (evflag) { // VFLAG== 1 + if (neighflag == HALF) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + } else if (neighflag == HALFTHREAD) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + } else if (neighflag == FULL) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); } - } else { - if (vflag_atom) { - if (flagfld) { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } - } else if (vflag_global) { - if (flagfld) { - Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); - } else { - Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); - } - } else { - if (flagfld) { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } + } else { // VFLAG == 0 + if (neighflag == HALF) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + } else if (neighflag == HALFTHREAD) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + } else if (neighflag == FULL) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); } } } @@ -344,9 +304,9 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) } template -template +template KOKKOS_INLINE_FUNCTION -void PairBrownianKokkos::operator()(TagPairBrownianCompute, const int ii, EV_FLOAT &ev) const { +void PairBrownianKokkos::operator()(TagPairBrownianCompute, const int ii, EV_FLOAT &ev) const { // printf("Inside TagPairBrownianCompute<>() ii= %i\n",ii); @@ -570,10 +530,8 @@ void PairBrownianKokkos::operator()(TagPairBrownianCompute(ev, i, j, -fx, -fy, -fz, delx, dely, delz); - if (EVFLAG == 1) - ev_tally_xyz(ev, i, j, -fx, -fy, -fz, delx, dely, delz); + if (VFLAG) + ev_tally_xyz(ev, i, j, -fx, -fy, -fz, delx, dely, delz); } } @@ -597,89 +555,87 @@ void PairBrownianKokkos::operator()(TagPairBrownianCompute -template +template KOKKOS_INLINE_FUNCTION -void PairBrownianKokkos::operator()(TagPairBrownianCompute, const int ii) const { +void PairBrownianKokkos::operator()(TagPairBrownianCompute, const int ii) const { EV_FLOAT ev; - this->template operator()(TagPairBrownianCompute(), ii, ev); + this->template operator()(TagPairBrownianCompute(), ii, ev); } -template -template -KOKKOS_INLINE_FUNCTION -void PairBrownianKokkos::ev_tally_xyz(EV_FLOAT &ev, int i, int j, - F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, - X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const -{ - F_FLOAT v[6]; - v[0] = delx*fx; - v[1] = dely*fy; - v[2] = delz*fz; - v[3] = delx*fy; - v[4] = delx*fz; - v[5] = dely*fz; - - if (NEWTON_PAIR) { - ev.v[0] += v[0]; - ev.v[1] += v[1]; - ev.v[2] += v[2]; - ev.v[3] += v[3]; - ev.v[4] += v[4]; - ev.v[5] += v[5]; - } else { - if (i < nlocal) { - ev.v[0] += 0.5*v[0]; - ev.v[1] += 0.5*v[1]; - ev.v[2] += 0.5*v[2]; - ev.v[3] += 0.5*v[3]; - ev.v[4] += 0.5*v[4]; - ev.v[5] += 0.5*v[5]; - } - if (j < nlocal) { - ev.v[0] += 0.5*v[0]; - ev.v[1] += 0.5*v[1]; - ev.v[2] += 0.5*v[2]; - ev.v[3] += 0.5*v[3]; - ev.v[4] += 0.5*v[4]; - ev.v[5] += 0.5*v[5]; - } - } -} +/* ---------------------------------------------------------------------- */ template template KOKKOS_INLINE_FUNCTION -void PairBrownianKokkos::ev_tally_xyz_atom(EV_FLOAT & /*ev*/, int i, int j, - F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, - X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const +void PairBrownianKokkos::ev_tally_xyz(EV_FLOAT & ev, int i, int j, + F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, + X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const { Kokkos::View::value,Kokkos::MemoryTraits::value> > v_vatom = k_vatom.view(); - F_FLOAT v[6]; - - v[0] = delx*fx; - v[1] = dely*fy; - v[2] = delz*fz; - v[3] = delx*fy; - v[4] = delx*fz; - v[5] = dely*fz; - - if (NEWTON_PAIR || i < nlocal) { - v_vatom(i,0) += 0.5*v[0]; - v_vatom(i,1) += 0.5*v[1]; - v_vatom(i,2) += 0.5*v[2]; - v_vatom(i,3) += 0.5*v[3]; - v_vatom(i,4) += 0.5*v[4]; - v_vatom(i,5) += 0.5*v[5]; + const F_FLOAT v0 = delx*fx; + const F_FLOAT v1 = dely*fy; + const F_FLOAT v2 = delz*fz; + const F_FLOAT v3 = delx*fy; + const F_FLOAT v4 = delx*fz; + const F_FLOAT v5 = dely*fz; + + if (vflag_global) { + if (NEIGHFLAG != FULL) { + if (NEWTON_PAIR) { // neigh half, newton on + ev.v[0] += v0; + ev.v[1] += v1; + ev.v[2] += v2; + ev.v[3] += v3; + ev.v[4] += v4; + ev.v[5] += v5; + } else { // neigh half, newton off + if (i < nlocal) { + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } + if (j < nlocal) { + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } + } + } else { //neigh full + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } } - if (NEWTON_PAIR || j < nlocal) { - v_vatom(j,0) += 0.5*v[0]; - v_vatom(j,1) += 0.5*v[1]; - v_vatom(j,2) += 0.5*v[2]; - v_vatom(j,3) += 0.5*v[3]; - v_vatom(j,4) += 0.5*v[4]; - v_vatom(j,5) += 0.5*v[5]; + + if (vflag_atom) { + + if (NEIGHFLAG == FULL || NEWTON_PAIR || i < nlocal) { + v_vatom(i,0) += 0.5*v0; + v_vatom(i,1) += 0.5*v1; + v_vatom(i,2) += 0.5*v2; + v_vatom(i,3) += 0.5*v3; + v_vatom(i,4) += 0.5*v4; + v_vatom(i,5) += 0.5*v5; + } + if (NEIGHFLAG != FULL && (NEWTON_PAIR || j < nlocal)) { + v_vatom(j,0) += 0.5*v0; + v_vatom(j,1) += 0.5*v1; + v_vatom(j,2) += 0.5*v2; + v_vatom(j,3) += 0.5*v3; + v_vatom(j,4) += 0.5*v4; + v_vatom(j,5) += 0.5*v5; + } } } diff --git a/src/USER-SUMAN/pair_brownian_kokkos.h b/src/USER-SUMAN/pair_brownian_kokkos.h index ae7632f40f..277b11b053 100644 --- a/src/USER-SUMAN/pair_brownian_kokkos.h +++ b/src/USER-SUMAN/pair_brownian_kokkos.h @@ -32,12 +32,13 @@ PairStyle(brownian/kk/host,PairBrownianKokkos); namespace LAMMPS_NS { -template +template struct TagPairBrownianCompute {}; template class PairBrownianKokkos : public PairBrownian, public KokkosBase { public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; typedef DeviceType device_type; typedef ArrayTypes AT; typedef EV_FLOAT value_type; @@ -49,23 +50,18 @@ class PairBrownianKokkos : public PairBrownian, public KokkosBase { void settings(int, char **) override; void init_style() override; - template + template KOKKOS_INLINE_FUNCTION - void operator()(TagPairBrownianCompute, const int, EV_FLOAT &ev) const; - template + void operator()(TagPairBrownianCompute, const int, EV_FLOAT &ev) const; + template KOKKOS_INLINE_FUNCTION - void operator()(TagPairBrownianCompute, const int) const; + void operator()(TagPairBrownianCompute, const int) const; - template + template KOKKOS_INLINE_FUNCTION void ev_tally_xyz(EV_FLOAT &ev, int i, int j, F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const; - template - KOKKOS_INLINE_FUNCTION - void ev_tally_xyz_atom(EV_FLOAT &ev, int i, int j, - F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, - X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const; protected: typename AT::t_x_array_randomread x; From e9f7b62f041480f5cba5b17643a5b825315b3734 Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 2 Nov 2023 15:26:56 -0500 Subject: [PATCH 03/43] fix FULL (as much as it can since not conservative) --- src/USER-SUMAN/pair_brownian_kokkos.cpp | 22 ++++------------------ src/USER-SUMAN/pair_brownian_kokkos.h | 2 -- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/USER-SUMAN/pair_brownian_kokkos.cpp b/src/USER-SUMAN/pair_brownian_kokkos.cpp index 78ffa0a9e2..117a5f4f97 100644 --- a/src/USER-SUMAN/pair_brownian_kokkos.cpp +++ b/src/USER-SUMAN/pair_brownian_kokkos.cpp @@ -67,11 +67,7 @@ PairBrownianKokkos::~PairBrownianKokkos() if (copymode) return; if (allocated) { - memoryKK->destroy_kokkos(k_eatom,eatom); memoryKK->destroy_kokkos(k_vatom,vatom); - // eatom = nullptr; - // vatom = nullptr; - memoryKK->destroy_kokkos(k_cut_inner,cut_inner); memoryKK->destroy_kokkos(k_cutsq,cutsq); } @@ -185,11 +181,6 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) // reallocate per-atom arrays if necessary - if (eflag_atom) { - memoryKK->destroy_kokkos(k_eatom,eatom); - memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); - d_eatom = k_eatom.view(); - } if (vflag_atom) { memoryKK->destroy_kokkos(k_vatom,vatom); memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); @@ -275,11 +266,6 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) } printf(" -- finished\n"); - if (eflag_atom) { - k_eatom.template modify(); - k_eatom.template sync(); - } - if (vflag_global) { virial[0] += ev.v[0]; virial[1] += ev.v[1]; @@ -288,7 +274,7 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) virial[4] += ev.v[4]; virial[5] += ev.v[5]; } - + if (vflag_atom) { k_vatom.template modify(); k_vatom.template sync(); @@ -461,7 +447,7 @@ void PairBrownianKokkos::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute Date: Thu, 2 Nov 2023 15:54:40 -0500 Subject: [PATCH 04/43] add PairBrownianKokkos::init_one() --- src/USER-SUMAN/pair_brownian.h | 2 +- src/USER-SUMAN/pair_brownian_kokkos.cpp | 26 ++++++++++++++++++++----- src/USER-SUMAN/pair_brownian_kokkos.h | 1 + 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/USER-SUMAN/pair_brownian.h b/src/USER-SUMAN/pair_brownian.h index 8087328fce..0bb4e2188b 100644 --- a/src/USER-SUMAN/pair_brownian.h +++ b/src/USER-SUMAN/pair_brownian.h @@ -31,7 +31,7 @@ class PairBrownian : public Pair { void compute(int, int) override; void settings(int, char **) override; void coeff(int, char **) override; - double init_one(int, int) override; + virtual double init_one(int, int) override; void init_style() override; void write_restart(FILE *) override; void read_restart(FILE *) override; diff --git a/src/USER-SUMAN/pair_brownian_kokkos.cpp b/src/USER-SUMAN/pair_brownian_kokkos.cpp index 117a5f4f97..4aea3610bd 100644 --- a/src/USER-SUMAN/pair_brownian_kokkos.cpp +++ b/src/USER-SUMAN/pair_brownian_kokkos.cpp @@ -104,6 +104,25 @@ void PairBrownianKokkos::init_style() printf("PairBrownianKokkos::init_style() flagdeform= %i flagwall= %i flaglog= %i R0= %f RT0= %f\n",flagdeform,flagwall,flaglog,R0,RT0); } +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairBrownianKokkos::init_one(int i, int j) +{ + double cutone = PairBrownian::init_one(i,j); + double cutinnerm = cut_inner[i][j]; + + k_cutsq.h_view(i,j) = k_cutsq.h_view(j,i) = cutone*cutone; + k_cutsq.template modify(); + + k_cut_inner.h_view(i,j) = k_cut_inner.h_view(j,i) = cutinnerm; + k_cut_inner.template modify(); + + return cutone; +} + /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ @@ -635,16 +654,13 @@ void PairBrownianKokkos::allocate() PairBrownian::allocate(); int n = atom->ntypes; - memory->destroy(cutsq); - // memory->destroy(cut); - memory->destroy(cut_inner); + memory->destroy(cutsq); memoryKK->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); d_cutsq = k_cutsq.template view(); - // memoryKK->create_kokkos(k_cut,cut,n+1,n+1,"pair:cut"); + memory->destroy(cut_inner); memoryKK->create_kokkos(k_cut_inner,cut_inner,n+1,n+1,"pair:cut_inner"); - // d_cut = k_cut.template view(); d_cut_inner = k_cut_inner.template view(); } diff --git a/src/USER-SUMAN/pair_brownian_kokkos.h b/src/USER-SUMAN/pair_brownian_kokkos.h index 8cb9299c67..06b443fcc4 100644 --- a/src/USER-SUMAN/pair_brownian_kokkos.h +++ b/src/USER-SUMAN/pair_brownian_kokkos.h @@ -49,6 +49,7 @@ class PairBrownianKokkos : public PairBrownian, public KokkosBase { void coeff(int, char **) override; void settings(int, char **) override; void init_style() override; + double init_one(int, int) override; template KOKKOS_INLINE_FUNCTION From 1be59745fb075b4bdebbd0a3c919b2b37602a041 Mon Sep 17 00:00:00 2001 From: cjknight Date: Wed, 29 Nov 2023 04:24:56 +0000 Subject: [PATCH 05/43] correct forces and per-atom virials, but thermo still off --- src/USER-SUMAN/pair_brownian_kokkos.cpp | 79 +++++++++++++------------ 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/src/USER-SUMAN/pair_brownian_kokkos.cpp b/src/USER-SUMAN/pair_brownian_kokkos.cpp index 4aea3610bd..c039defbe7 100644 --- a/src/USER-SUMAN/pair_brownian_kokkos.cpp +++ b/src/USER-SUMAN/pair_brownian_kokkos.cpp @@ -55,8 +55,8 @@ PairBrownianKokkos::PairBrownianKokkos(LAMMPS *lmp) : PairBrownian(l kokkosable = 1; atomKK = (AtomKokkos *) atom; execution_space = ExecutionSpaceFromDevice::space; - datamask_read = X_MASK | F_MASK | TORQUE_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK | RADIUS_MASK; - datamask_modify = F_MASK | TORQUE_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_read = X_MASK | F_MASK | TORQUE_MASK | TYPE_MASK | VIRIAL_MASK | RADIUS_MASK; + datamask_modify = F_MASK | TORQUE_MASK | VIRIAL_MASK; } /* ---------------------------------------------------------------------- */ @@ -104,34 +104,6 @@ void PairBrownianKokkos::init_style() printf("PairBrownianKokkos::init_style() flagdeform= %i flagwall= %i flaglog= %i R0= %f RT0= %f\n",flagdeform,flagwall,flaglog,R0,RT0); } -/* ---------------------------------------------------------------------- - init for one type pair i,j and corresponding j,i -------------------------------------------------------------------------- */ - -template -double PairBrownianKokkos::init_one(int i, int j) -{ - double cutone = PairBrownian::init_one(i,j); - double cutinnerm = cut_inner[i][j]; - - k_cutsq.h_view(i,j) = k_cutsq.h_view(j,i) = cutone*cutone; - k_cutsq.template modify(); - - k_cut_inner.h_view(i,j) = k_cut_inner.h_view(j,i) = cutinnerm; - k_cut_inner.template modify(); - - return cutone; -} - -/* ---------------------------------------------------------------------- - set coeffs for one or more type pairs -------------------------------------------------------------------------- */ - -template -void PairBrownianKokkos::coeff(int narg, char **arg) -{ - PairBrownian::coeff(narg,arg); -} /* ---------------------------------------------------------------------- */ template @@ -139,8 +111,6 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) { printf("Inside compute()\n"); - copymode = 1; - eflag = eflag_in; vflag = vflag_in; @@ -208,6 +178,7 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) atomKK->sync(execution_space,datamask_read); k_cutsq.template sync(); + k_cut_inner.template sync(); if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); else atomKK->modified(execution_space,F_MASK | TORQUE_MASK); @@ -230,10 +201,14 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) d_neighbors = k_list->d_neighbors; d_ilist = k_list->d_ilist; + copymode = 1; + EV_FLOAT ev; - printf(" -- starting parallel_for() neighflag= %i HALF= %i newton_pair= %i vflag_either= %i vflag_atom= %i flagfld= %i vflag_global= %i\n", - neighflag, HALF, newton_pair, vflag_either, vflag_atom, flagfld, vflag_global); + printf(" -- starting parallel_for() neighflag= %i HALF= %i HALFTHREAD= %i newton_pair= %i vflag_either= %i vflag_atom= %i flagfld= %i vflag_global= %i\n", + neighflag, HALF, HALFTHREAD, newton_pair, vflag_either, vflag_atom, flagfld, vflag_global); + +#if 1 if (flagfld) { // FLAGFLD == 1 if (vflag_either) { // VFLAG == 1 if (neighflag == HALF) { @@ -283,6 +258,7 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) } } } +#endif printf(" -- finished\n"); if (vflag_global) { @@ -293,15 +269,15 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) virial[4] += ev.v[4]; virial[5] += ev.v[5]; } - + if (vflag_atom) { k_vatom.template modify(); k_vatom.template sync(); } if (vflag_fdotr) pair_virial_fdotr_compute(this); - - printf("i= %i vatom= %f %f %f %f %f %f\n",0,vatom[0][0],vatom[0][1],vatom[0][2],vatom[0][3],vatom[0][4],vatom[0][5]); + + printf("i= %i vflag_fdotr= %i vatom= %f %f %f %f %f %f\n",vflag_fdotr,0,vatom[0][0],vatom[0][1],vatom[0][2],vatom[0][3],vatom[0][4],vatom[0][5]); copymode = 0; @@ -676,6 +652,35 @@ void PairBrownianKokkos::settings(int narg, char **arg) PairBrownian::settings(narg,arg); } +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairBrownianKokkos::init_one(int i, int j) +{ + double cutone = PairBrownian::init_one(i,j); + double cutinnerm = cut_inner[i][j]; + + k_cutsq.h_view(i,j) = k_cutsq.h_view(j,i) = cutone*cutone; + k_cutsq.template modify(); + + k_cut_inner.h_view(i,j) = k_cut_inner.h_view(j,i) = cutinnerm; + k_cut_inner.template modify(); + + return cutone; +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +template +void PairBrownianKokkos::coeff(int narg, char **arg) +{ + PairBrownian::coeff(narg,arg); +} + namespace LAMMPS_NS { template class PairBrownianKokkos; #ifdef LMP_KOKKOS_GPU From 9749c0658adcf65f469a77f7a480aa096d576906 Mon Sep 17 00:00:00 2001 From: cjknight Date: Wed, 29 Nov 2023 22:41:23 -0600 Subject: [PATCH 06/43] need to update velocities on host for non-kokkos computes --- src/KOKKOS/compute_temp_deform_kokkos.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/KOKKOS/compute_temp_deform_kokkos.cpp b/src/KOKKOS/compute_temp_deform_kokkos.cpp index 03aba5b10d..328cf783e0 100644 --- a/src/KOKKOS/compute_temp_deform_kokkos.cpp +++ b/src/KOKKOS/compute_temp_deform_kokkos.cpp @@ -214,6 +214,9 @@ void ComputeTempDeformKokkos::remove_bias_all() copymode = 0; domainKK->lamda2x(nlocal); + + atomKK->k_v.template modify(); + atomKK->k_v.template sync(); } template @@ -242,6 +245,9 @@ void ComputeTempDeformKokkos::restore_bias_all() copymode = 1; Kokkos::parallel_for(Kokkos::RangePolicy(0,nlocal),*this); copymode = 0; + + atomKK->k_v.template modify(); + atomKK->k_v.template sync(); } template From 83c9d47f5e3d0990db9bc7e521c778c2bc6c1512 Mon Sep 17 00:00:00 2001 From: cjknight Date: Wed, 29 Nov 2023 23:06:17 -0600 Subject: [PATCH 07/43] correct forces + virial --- src/USER-SUMAN/pair_brownian.cpp | 30 ++++--------------- src/USER-SUMAN/pair_brownian_kokkos.cpp | 40 +++++-------------------- 2 files changed, 12 insertions(+), 58 deletions(-) diff --git a/src/USER-SUMAN/pair_brownian.cpp b/src/USER-SUMAN/pair_brownian.cpp index 8c99522abb..783bea6690 100644 --- a/src/USER-SUMAN/pair_brownian.cpp +++ b/src/USER-SUMAN/pair_brownian.cpp @@ -46,7 +46,7 @@ using namespace MathSpecial; enum { EDGE, CONSTANT, VARIABLE }; -#define _NO_RANDOM +//#define _NO_RANDOM /* ---------------------------------------------------------------------- */ @@ -76,7 +76,9 @@ PairBrownian::~PairBrownian() void PairBrownian::compute(int eflag, int vflag) { +#ifdef _NO_RANDOM printf("Warning:: PairBrownian::compute() Random numbers all set to 0.5\n"); +#endif int i, j, ii, jj, inum, jnum, itype, jtype; double xtmp, ytmp, ztmp, delx, dely, delz, fx, fy, fz, tx, ty, tz; @@ -101,8 +103,6 @@ void PairBrownian::compute(int eflag, int vflag) // This section of code adjusts R0/RT0/RS0 if necessary due to changes // in the volume fraction as a result of fix deform or moving walls - - printf("PairBrownian::compute() flagVF= %i flagdeform= %i flagwall= %i flaglog= %i\n",flagVF,flagdeform,flagwall,flaglog); double dims[3], wallcoord; if (flagVF) // Flag for volume fraction corrections @@ -146,16 +146,11 @@ void PairBrownian::compute(int eflag, int vflag) prethermostat = sqrt(24.0 * force->boltz * t_target / update->dt); prethermostat *= sqrt(force->vxmu2f / force->ftm2v / force->mvv2e); - - printf("PairBrownian::compute() prethermostat= %f R0= %f RT0= %f\n",prethermostat, R0, RT0); inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; - - printf(" -- starting ij-loop() newton_pair= %i vflag_atom= %i flagfld= %i vflag_global= %i\n", - newton_pair, vflag_atom, flagfld, vflag_global); for (ii = 0; ii < inum; ii++) { i = ilist[ii]; @@ -167,10 +162,8 @@ void PairBrownian::compute(int eflag, int vflag) jlist = firstneigh[i]; jnum = numneigh[i]; -#if 1 // FLD contribution to force and torque due to isotropic terms - if(ii == 0) printf("ii= %i i= %i f(before)= %f %f %f df= %f\n",ii,i,f[i][0],f[i][1],f[i][2],prethermostat * sqrt(R0) * 0.5); #ifdef _NO_RANDOM if (flagfld) { f[i][0] += prethermostat * sqrt(R0) * 0.5; @@ -193,13 +186,10 @@ void PairBrownian::compute(int eflag, int vflag) torque[i][2] += prethermostat * sqrt(RT0) * (random->uniform() - 0.5); } } -#endif - #endif if (!flagHI) continue; -#if 1 for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; j &= NEIGHMASK; @@ -254,7 +244,6 @@ void PairBrownian::compute(int eflag, int vflag) // add terms due to a_sh -#if 1 if (flaglog) { // generate two orthogonal vectors to the line of centers @@ -286,7 +275,7 @@ void PairBrownian::compute(int eflag, int vflag) fy += Fbmag * randr * p3[1]; fz += Fbmag * randr * p3[2]; } -#endif + // scale forces to appropriate units fx = vxmu2f * fx; @@ -377,11 +366,7 @@ void PairBrownian::compute(int eflag, int vflag) ev_tally_xyz(i, j, nlocal, newton_pair, 0.0, 0.0, -fx, -fy, -fz, delx, dely, delz); } } -#endif } - - printf("ii= %i i= %i f(after)= %f %f %f\n",0,ilist[0],f[ilist[0]][0],f[ilist[0]][1],f[ilist[0]][2]); - printf("i= %i vatom= %f %f %f %f %f %f\n",0,vatom[0][0],vatom[0][1],vatom[0][2],vatom[0][3],vatom[0][4],vatom[0][5]); if (vflag_fdotr) virial_fdotr_compute(); } @@ -490,9 +475,7 @@ void PairBrownian::coeff(int narg, char **arg) ------------------------------------------------------------------------- */ void PairBrownian::init_style() -{ - printf("Inside PairBrownian::init_style()\n"); - +{ if (!atom->sphere_flag) error->all(FLERR, "Pair brownian requires atom style sphere"); // if newton off, forces between atoms ij will be double computed @@ -535,7 +518,6 @@ void PairBrownian::init_style() flagdeform = flagwall = 0; for (int i = 0; i < modify->nfix; i++) { - printf(" i= %i fix->style= %s\n",i,modify->fix[i]->style); if (strcmp(modify->fix[i]->style, "deform") == 0) flagdeform = 1; else if (strcmp(modify->fix[i]->style, "deform/kk") == 0) flagdeform = 1; // cleaner way to do this?? what about flagwall? else if (strstr(modify->fix[i]->style, "wall") != nullptr) { @@ -595,8 +577,6 @@ void PairBrownian::init_style() R0 = 6 * MY_PI * mu * rad * (1.0 + 2.725 * vol_f - 6.583 * vol_f * vol_f); RT0 = 8 * MY_PI * mu * cube(rad) * (1.0 + 0.749 * vol_f - 2.469 * vol_f * vol_f); } - - printf("PairBrownian::init_style() flagdeform= %i flagwall= %i flaglog= %i R0= %f RT0= %f\n",flagdeform,flagwall,flaglog,R0,RT0); } /* ---------------------------------------------------------------------- diff --git a/src/USER-SUMAN/pair_brownian_kokkos.cpp b/src/USER-SUMAN/pair_brownian_kokkos.cpp index c039defbe7..2450d53b37 100644 --- a/src/USER-SUMAN/pair_brownian_kokkos.cpp +++ b/src/USER-SUMAN/pair_brownian_kokkos.cpp @@ -42,7 +42,7 @@ using namespace MathSpecialKokkos; enum { EDGE, CONSTANT, VARIABLE }; -#define _NO_RANDOM +//#define _NO_RANDOM /* ---------------------------------------------------------------------- */ @@ -100,8 +100,6 @@ void PairBrownianKokkos::init_style() !std::is_same_v); request->set_kokkos_device(std::is_same_v); if (neighflag == FULL) request->enable_full(); - - printf("PairBrownianKokkos::init_style() flagdeform= %i flagwall= %i flaglog= %i R0= %f RT0= %f\n",flagdeform,flagwall,flaglog,R0,RT0); } /* ---------------------------------------------------------------------- */ @@ -109,7 +107,9 @@ void PairBrownianKokkos::init_style() template void PairBrownianKokkos::compute(int eflag_in, int vflag_in) { - printf("Inside compute()\n"); +#ifdef _NO_RANDOM + printf("Warning:: PairBrownian::compute() Random numbers all set to 0.5\n"); +#endif eflag = eflag_in; vflag = vflag_in; @@ -120,8 +120,6 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) // This section of code adjusts R0/RT0/RS0 if necessary due to changes // in the volume fraction as a result of fix deform or moving walls - - printf("PairBrownianKokkos::compute() flagVF= %i flagdeform= %i flagwall= %i flaglog= %i\n",flagVF,flagdeform,flagwall,flaglog); double dims[3], wallcoord; if (flagVF) // Flag for volume fraction corrections @@ -166,8 +164,6 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) prethermostat = sqrt(24.0 * force->boltz * t_target / update->dt); prethermostat *= sqrt(force->vxmu2f / force->ftm2v / force->mvv2e); - printf("PairBrownianKokkos::compute() prethermostat= %f R0= %f RT0= %f\n",prethermostat, R0, RT0); - // reallocate per-atom arrays if necessary if (vflag_atom) { @@ -205,10 +201,6 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) EV_FLOAT ev; - printf(" -- starting parallel_for() neighflag= %i HALF= %i HALFTHREAD= %i newton_pair= %i vflag_either= %i vflag_atom= %i flagfld= %i vflag_global= %i\n", - neighflag, HALF, HALFTHREAD, newton_pair, vflag_either, vflag_atom, flagfld, vflag_global); - -#if 1 if (flagfld) { // FLAGFLD == 1 if (vflag_either) { // VFLAG == 1 if (neighflag == HALF) { @@ -258,8 +250,6 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) } } } -#endif - printf(" -- finished\n"); if (vflag_global) { virial[0] += ev.v[0]; @@ -277,19 +267,13 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) if (vflag_fdotr) pair_virial_fdotr_compute(this); - printf("i= %i vflag_fdotr= %i vatom= %f %f %f %f %f %f\n",vflag_fdotr,0,vatom[0][0],vatom[0][1],vatom[0][2],vatom[0][3],vatom[0][4],vatom[0][5]); - copymode = 0; - - printf("Leaving compute()\n"); } template template KOKKOS_INLINE_FUNCTION void PairBrownianKokkos::operator()(TagPairBrownianCompute, const int ii, EV_FLOAT &ev) const { - - // printf("Inside TagPairBrownianCompute<>() ii= %i\n",ii); // The f and torque arrays are atomic for Half/Thread neighbor style Kokkos::View::value,Kokkos::MemoryTraits::value> > a_f = f; @@ -316,7 +300,6 @@ void PairBrownianKokkos::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute(ev, i, j, -fx, -fy, -fz, delx, dely, delz); + ev_tally_xyz(ev, i, j, -fx, -fy, -fz, delx, dely, delz); } } } // if(flagHI) -#endif rand_pool.free_state(rand_gen); - - if(ii == 0) printf("ii= %i i= %i f(before)= %f %f %f df= %f %f %f\n",ii,i,a_f(i,0),a_f(i,1),a_f(i,2),fx_i,fy_i,fz_i); a_f(i,0) += fx_i; a_f(i,1) += fy_i; @@ -529,10 +507,6 @@ void PairBrownianKokkos::operator()(TagPairBrownianCompute From ed18f3014aa99a3072597a0b6bbe713059fbc426 Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 30 Nov 2023 16:12:15 -0600 Subject: [PATCH 08/43] fix virial when both global and per-atom requested --- src/KOKKOS/pair_gran_hooke_history_kokkos.cpp | 184 +++++++----------- src/KOKKOS/pair_gran_hooke_history_kokkos.h | 17 +- 2 files changed, 79 insertions(+), 122 deletions(-) diff --git a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp index 35d779f36f..dc8679c10d 100644 --- a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp +++ b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp @@ -163,18 +163,12 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) d_firstshear = fix_historyKK->k_firstvalue.template view(); Kokkos::deep_copy(d_firsttouch,0); - + EV_FLOAT ev; if (neighflag == HALF) { if (force->newton_pair) { - if (vflag_atom) { - if (shearupdate) { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } - } else if (vflag_global) { + if (vflag_either) { // VFLAG == 1 if (shearupdate) { Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); } else { @@ -188,13 +182,7 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) } } } else { - if (vflag_atom) { - if (shearupdate) { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } - } else if (vflag_global) { + if (vflag_either) { if (shearupdate) { Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); } else { @@ -210,13 +198,7 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) } } else { // HALFTHREAD if (force->newton_pair) { - if (vflag_atom) { - if (shearupdate) { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } - } else if (vflag_global) { + if (vflag_either) { // VFLAG == 0 if (shearupdate) { Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); } else { @@ -230,13 +212,7 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) } } } else { - if (vflag_atom) { - if (shearupdate) { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } else { - Kokkos::parallel_for(Kokkos::RangePolicy>(0,inum),*this); - } - } else if (vflag_global) { + if (vflag_global) { if (shearupdate) { Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); } else { @@ -251,7 +227,7 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) } } } - + if (eflag_atom) { k_eatom.template modify(); k_eatom.template sync(); @@ -265,7 +241,7 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) virial[4] += ev.v[4]; virial[5] += ev.v[5]; } - + if (vflag_atom) { k_vatom.template modify(); k_vatom.template sync(); @@ -277,9 +253,9 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) } template -template +template KOKKOS_INLINE_FUNCTION -void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryCompute, const int ii, EV_FLOAT &ev) const { +void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryCompute, const int ii, EV_FLOAT &ev) const { // The f and torque arrays are atomic for Half/Thread neighbor style Kokkos::View::value,Kokkos::MemoryTraits::value> > a_f = f; @@ -324,7 +300,7 @@ void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryC const LMP_FLOAT jmass = rmass[j]; const LMP_FLOAT jrad = radius[j]; const LMP_FLOAT radsum = irad + jrad; - + // check for touching neighbors if (rsq >= radsum * radsum) { @@ -446,7 +422,7 @@ void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryC fx_i += fx; fy_i += fy; fz_i += fz; - + F_FLOAT tor1 = rinv * (dely*fs3 - delz*fs2); F_FLOAT tor2 = rinv * (delz*fs1 - delx*fs3); F_FLOAT tor3 = rinv * (delx*fs2 - dely*fs1); @@ -466,10 +442,8 @@ void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryC a_torque(j,2) -= jrad*tor3; } - if (EVFLAG == 2) - ev_tally_xyz_atom(ev, i, j, fx_i, fy_i, fz_i, delx, dely, delz); - if (EVFLAG == 1) - ev_tally_xyz(ev, i, j, fx_i, fy_i, fz_i, delx, dely, delz); + if (VFLAG) + ev_tally_xyz(ev, i, j, fx_i, fy_i, fz_i, delx, dely, delz); } a_f(i,0) += fx_i; @@ -481,90 +455,78 @@ void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryC } template -template +template KOKKOS_INLINE_FUNCTION -void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryCompute, const int ii) const { +void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryCompute, const int ii) const { EV_FLOAT ev; - this->template operator()(TagPairGranHookeHistoryCompute(), ii, ev); -} - -template -template -KOKKOS_INLINE_FUNCTION -void PairGranHookeHistoryKokkos::ev_tally_xyz(EV_FLOAT &ev, int i, int j, - F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, - X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const -{ - F_FLOAT v[6]; - - v[0] = delx*fx; - v[1] = dely*fy; - v[2] = delz*fz; - v[3] = delx*fy; - v[4] = delx*fz; - v[5] = dely*fz; - - if (NEWTON_PAIR) { - ev.v[0] += v[0]; - ev.v[1] += v[1]; - ev.v[2] += v[2]; - ev.v[3] += v[3]; - ev.v[4] += v[4]; - ev.v[5] += v[5]; - } else { - if (i < nlocal) { - ev.v[0] += 0.5*v[0]; - ev.v[1] += 0.5*v[1]; - ev.v[2] += 0.5*v[2]; - ev.v[3] += 0.5*v[3]; - ev.v[4] += 0.5*v[4]; - ev.v[5] += 0.5*v[5]; - } - if (j < nlocal) { - ev.v[0] += 0.5*v[0]; - ev.v[1] += 0.5*v[1]; - ev.v[2] += 0.5*v[2]; - ev.v[3] += 0.5*v[3]; - ev.v[4] += 0.5*v[4]; - ev.v[5] += 0.5*v[5]; - } - } + this->template operator()(TagPairGranHookeHistoryCompute(), ii, ev); } template template KOKKOS_INLINE_FUNCTION -void PairGranHookeHistoryKokkos::ev_tally_xyz_atom(EV_FLOAT & /*ev*/, int i, int j, - F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, - X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const +void PairGranHookeHistoryKokkos::ev_tally_xyz(EV_FLOAT &ev, int i, int j, + F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, + X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const { Kokkos::View::value,Kokkos::MemoryTraits::value> > v_vatom = k_vatom.view(); - F_FLOAT v[6]; - - v[0] = delx*fx; - v[1] = dely*fy; - v[2] = delz*fz; - v[3] = delx*fy; - v[4] = delx*fz; - v[5] = dely*fz; - - if (NEWTON_PAIR || i < nlocal) { - v_vatom(i,0) += 0.5*v[0]; - v_vatom(i,1) += 0.5*v[1]; - v_vatom(i,2) += 0.5*v[2]; - v_vatom(i,3) += 0.5*v[3]; - v_vatom(i,4) += 0.5*v[4]; - v_vatom(i,5) += 0.5*v[5]; + const F_FLOAT v0 = delx*fx; + const F_FLOAT v1 = dely*fy; + const F_FLOAT v2 = delz*fz; + const F_FLOAT v3 = delx*fy; + const F_FLOAT v4 = delx*fz; + const F_FLOAT v5 = dely*fz; + + if (vflag_global) { + if (NEWTON_PAIR) { // neigh half, newton on + ev.v[0] += v0; + ev.v[1] += v1; + ev.v[2] += v2; + ev.v[3] += v3; + ev.v[4] += v4; + ev.v[5] += v5; + } else { // neigh half, newton off + if (i < nlocal) { + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } + if (j < nlocal) { + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } + } } - if (NEWTON_PAIR || j < nlocal) { - v_vatom(j,0) += 0.5*v[0]; - v_vatom(j,1) += 0.5*v[1]; - v_vatom(j,2) += 0.5*v[2]; - v_vatom(j,3) += 0.5*v[3]; - v_vatom(j,4) += 0.5*v[4]; - v_vatom(j,5) += 0.5*v[5]; + + if (vflag_atom) { + + if (NEWTON_PAIR || i < nlocal) { + v_vatom(i,0) += 0.5*v0; + v_vatom(i,1) += 0.5*v1; + v_vatom(i,2) += 0.5*v2; + v_vatom(i,3) += 0.5*v3; + v_vatom(i,4) += 0.5*v4; + v_vatom(i,5) += 0.5*v5; + } + if (NEWTON_PAIR || j < nlocal) { + v_vatom(j,0) += 0.5*v0; + v_vatom(j,1) += 0.5*v1; + v_vatom(j,2) += 0.5*v2; + v_vatom(j,3) += 0.5*v3; + v_vatom(j,4) += 0.5*v4; + v_vatom(j,5) += 0.5*v5; + } + } + } namespace LAMMPS_NS { diff --git a/src/KOKKOS/pair_gran_hooke_history_kokkos.h b/src/KOKKOS/pair_gran_hooke_history_kokkos.h index 4f98b00f2a..d2bd1d96d5 100644 --- a/src/KOKKOS/pair_gran_hooke_history_kokkos.h +++ b/src/KOKKOS/pair_gran_hooke_history_kokkos.h @@ -32,7 +32,7 @@ namespace LAMMPS_NS { template class FixNeighHistoryKokkos; -template +template struct TagPairGranHookeHistoryCompute {}; template @@ -47,23 +47,18 @@ class PairGranHookeHistoryKokkos : public PairGranHookeHistory { void compute(int, int) override; void init_style() override; - template + template KOKKOS_INLINE_FUNCTION - void operator()(TagPairGranHookeHistoryCompute, const int, EV_FLOAT &ev) const; - template + void operator()(TagPairGranHookeHistoryCompute, const int, EV_FLOAT &ev) const; + template KOKKOS_INLINE_FUNCTION - void operator()(TagPairGranHookeHistoryCompute, const int) const; + void operator()(TagPairGranHookeHistoryCompute, const int) const; - template + template KOKKOS_INLINE_FUNCTION void ev_tally_xyz(EV_FLOAT &ev, int i, int j, F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const; - template - KOKKOS_INLINE_FUNCTION - void ev_tally_xyz_atom(EV_FLOAT &ev, int i, int j, - F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, - X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const; protected: typename AT::t_x_array_randomread x; From 26f52f755288fc07b70853d436be4436c9d307c5 Mon Sep 17 00:00:00 2001 From: cjknight Date: Fri, 12 Jan 2024 12:54:17 -0600 Subject: [PATCH 09/43] enable base classes to support Kokkos style --- src/COLLOID/pair_lubricate.cpp | 2 ++ src/COLLOID/pair_lubricate.h | 2 +- src/USER-SUMAN/pair_lubricate_Simple.cpp | 26 ++++++++++++++++-------- src/USER-SUMAN/pair_lubricate_Simple.h | 3 ++- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/COLLOID/pair_lubricate.cpp b/src/COLLOID/pair_lubricate.cpp index 99a544cd7f..55a1a10317 100644 --- a/src/COLLOID/pair_lubricate.cpp +++ b/src/COLLOID/pair_lubricate.cpp @@ -56,6 +56,8 @@ PairLubricate::PairLubricate(LAMMPS *lmp) : Pair(lmp) PairLubricate::~PairLubricate() { + if (copymode) return; + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/COLLOID/pair_lubricate.h b/src/COLLOID/pair_lubricate.h index 8097eb76dd..6956293dbc 100644 --- a/src/COLLOID/pair_lubricate.h +++ b/src/COLLOID/pair_lubricate.h @@ -56,7 +56,7 @@ class PairLubricate : public Pair { double R0, RT0, RS0; double **cut_inner, **cut; - void allocate(); + virtual void allocate(); }; } // namespace LAMMPS_NS diff --git a/src/USER-SUMAN/pair_lubricate_Simple.cpp b/src/USER-SUMAN/pair_lubricate_Simple.cpp index 8eb7887bf2..187dddcdf7 100644 --- a/src/USER-SUMAN/pair_lubricate_Simple.cpp +++ b/src/USER-SUMAN/pair_lubricate_Simple.cpp @@ -30,9 +30,6 @@ See the README file in the top-level LAMMPS directory. #include "force.h" #include "neighbor.h" #include "neigh_list.h" -#if 0 -#include "neigh_request.h" -#endif #include "domain.h" #include "modify.h" #include "fix.h" @@ -66,6 +63,13 @@ PairLubricateSimple::PairLubricateSimple(LAMMPS *lmp) : PairLubricate(lmp) /* ---------------------------------------------------------------------- */ +PairLubricateSimple::~PairLubricateSimple() +{ + if (copymode) return; +} + +/* ---------------------------------------------------------------------- */ + void PairLubricateSimple::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; @@ -331,13 +335,7 @@ void PairLubricateSimple::init_style() if (radius[i] == 0.0) error->one(FLERR,"Pair lubricate/poly requires extended particles"); -#if 1 neighbor->add_request(this, NeighConst::REQ_FULL); -#else - int irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->half = 0; - neighbor->requests[irequest]->full = 1; -#endif // set the isotropic constants that depend on the volume fraction // vol_T = total volume @@ -396,3 +394,13 @@ void PairLubricateSimple::init_style() Ef[1][0] = Ef[1][1] = Ef[1][2] = 0.0; Ef[2][0] = Ef[2][1] = Ef[2][2] = 0.0; } + +/* ---------------------------------------------------------------------- + allocate all arrays; overiding here so Kokkos can overide + ------------------------------------------------------------------------- */ + +void PairLubricateSimple::allocate() +{ + printf("Inside PairLubricateSimple::allocate()\n"); + PairLubricate::allocate(); +} diff --git a/src/USER-SUMAN/pair_lubricate_Simple.h b/src/USER-SUMAN/pair_lubricate_Simple.h index e6fd9fa231..46f7019b92 100644 --- a/src/USER-SUMAN/pair_lubricate_Simple.h +++ b/src/USER-SUMAN/pair_lubricate_Simple.h @@ -27,9 +27,10 @@ namespace LAMMPS_NS { class PairLubricateSimple : public PairLubricate { public: PairLubricateSimple(class LAMMPS *); - ~PairLubricateSimple() {} + ~PairLubricateSimple() override; void compute(int, int); void init_style(); + void allocate() override; }; } From 8002f985dad8193b618866e68ac3f9f12f5d2743 Mon Sep 17 00:00:00 2001 From: cjknight Date: Wed, 24 Jan 2024 09:19:00 -0600 Subject: [PATCH 10/43] enable half neighlist + kk support; correct except for neighbor list difference... --- src/USER-SUMAN/pair_lubricate_Simple.cpp | 639 ++++++++------- .../pair_lubricate_Simple_kokkos.cpp | 770 ++++++++++++++++++ src/USER-SUMAN/pair_lubricate_Simple_kokkos.h | 129 +++ 3 files changed, 1227 insertions(+), 311 deletions(-) create mode 100644 src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp create mode 100644 src/USER-SUMAN/pair_lubricate_Simple_kokkos.h diff --git a/src/USER-SUMAN/pair_lubricate_Simple.cpp b/src/USER-SUMAN/pair_lubricate_Simple.cpp index 187dddcdf7..68b5126048 100644 --- a/src/USER-SUMAN/pair_lubricate_Simple.cpp +++ b/src/USER-SUMAN/pair_lubricate_Simple.cpp @@ -58,7 +58,7 @@ enum{EDGE,CONSTANT,VARIABLE}; PairLubricateSimple::PairLubricateSimple(LAMMPS *lmp) : PairLubricate(lmp) { - no_virial_fdotr_compute = 1; + no_virial_fdotr_compute = 1; } /* ---------------------------------------------------------------------- */ @@ -72,243 +72,258 @@ PairLubricateSimple::~PairLubricateSimple() void PairLubricateSimple::compute(int eflag, int vflag) { - int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz,tx,ty,tz; - double rsq,r,h_sep,beta0,beta1,radi,radj; - double vr1,vr2,vr3,vnnr,vn1,vn2,vn3; - double vt1,vt2,vt3; - int *ilist,*jlist,*numneigh,**firstneigh; - double lamda[3],vstream[3]; + int i,j,ii,jj,inum,jnum,itype,jtype; + double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz,tx,ty,tz; + double rsq,r,h_sep,beta0,beta1,radi,radj; + double vr1,vr2,vr3,vnnr,vn1,vn2,vn3; + double vt1,vt2,vt3; + int *ilist,*jlist,*numneigh,**firstneigh; + double lamda[3],vstream[3]; + + double vxmu2f = force->vxmu2f; + + if (eflag || vflag) ev_setup(eflag,vflag); + else evflag = vflag_fdotr = 0; + + double **x = atom->x; + double **v = atom->v; + double **f = atom->f; + double **omega = atom->omega; + double **torque = atom->torque; + double *radius = atom->radius; + 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; + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + itype = type[i]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + radi = radius[i]; + + // Drag contribution to force and torque due to isotropic terms + // Drag contribution to stress from isotropic RS0 + + if (flagfld) { - double vxmu2f = force->vxmu2f; - - if (eflag || vflag) ev_setup(eflag,vflag); - else evflag = vflag_fdotr = 0; - - double **x = atom->x; - double **v = atom->v; - double **f = atom->f; - double **omega = atom->omega; - double **torque = atom->torque; - double *radius = atom->radius; - 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; - - - for (ii = 0; ii < inum; ii++) { - i = ilist[ii]; - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - itype = type[i]; - jlist = firstneigh[i]; - jnum = numneigh[i]; - radi = radius[i]; - - // Drag contribution to force and torque due to isotropic terms - // Drag contribution to stress from isotropic RS0 - - if (flagfld) { - - domain->x2lamda(x[i],lamda); - double *h_rate = domain->h_rate; - double *h_ratelo = domain->h_ratelo; - vstream[0] = h_rate[0]*lamda[0] + h_rate[5]*lamda[1] + - h_rate[4]*lamda[2] + h_ratelo[0]; - vstream[1] = h_rate[1]*lamda[1] + h_rate[3]*lamda[2] + h_ratelo[1]; - vstream[2] = h_rate[2]*lamda[2] + h_ratelo[2]; - - - R0 = 6.0*MY_PI*mu; - RT0 = 8.0*MY_PI*mu; - RS0 = 20.0/3.0*MY_PI*mu; - - f[i][0] += vxmu2f*R0*radi*(vstream[0]-v[i][0]); - f[i][1] += vxmu2f*R0*radi*(vstream[1]-v[i][1]); - f[i][2] += vxmu2f*R0*radi*(vstream[2]-v[i][2]); - - const double radi3 = radi*radi*radi; - - torque[i][0] -= vxmu2f*RT0*radi3*(omega[i][0]+0.5*h_rate[3]/domain->zprd); - torque[i][1] -= vxmu2f*RT0*radi3*(omega[i][1]-0.5*h_rate[4]/domain->zprd); - torque[i][2] -= vxmu2f*RT0*radi3*(omega[i][2]+0.5*h_rate[5]/domain->yprd); - // Ef = (grad(vstream) + (grad(vstream))^T) / 2 - // set Ef from h_rate in strain units - if(shearing){ - Ef[0][0] = h_rate[0]/domain->xprd; - Ef[1][1] = h_rate[1]/domain->yprd; - Ef[2][2] = h_rate[2]/domain->zprd; - Ef[0][1] = Ef[1][0] = 0.5 * h_rate[5]/domain->yprd; - Ef[0][2] = Ef[2][0] = 0.5 * h_rate[4]/domain->zprd; - Ef[1][2] = Ef[2][1] = 0.5 * h_rate[3]/domain->zprd; - - - if (vflag_either) { - double vRS0 = -vxmu2f * RS0*radi3; - v_tally_tensor(i,i,nlocal,newton_pair, - vRS0*Ef[0][0],vRS0*Ef[1][1],vRS0*Ef[2][2], - vRS0*Ef[0][1],vRS0*Ef[0][2],vRS0*Ef[1][2]); - } - } - - } - - if (!flagHI)continue; - - for (jj = 0; jj < jnum; jj++) { - j = jlist[jj]; - j &= NEIGHMASK; - - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - rsq = delx*delx + dely*dely + delz*delz; - jtype = type[j]; - radj = atom->radius[j]; - double radsum = radi+radj; //Sum of two particle's radii - - if (rsq < cutsq[itype][jtype] and rsq < (1.45*1.45*radsum*radsum) ) { - r = sqrt(rsq); - - - // scalar resistances XA and YA - - h_sep = r - radsum; - - // if less than the minimum gap use the minimum gap instead - - if (r < cut_inner[itype][jtype]*radsum) //Scaled inner cutoff by particle radii - h_sep = cut_inner[itype][jtype]*radsum - radsum; - - double hinv,lhinv,XA11=0.0,YA11=0.0,YB11=0.0,YC12=0.0,ws[3],wd[3],nx,ny,nz; - ws[0] = (omega[i][0]+omega[j][0])/2.0; - ws[1] = (omega[i][1]+omega[j][1])/2.0; - ws[2] = (omega[i][2]+omega[j][2])/2.0; - - wd[0] = (omega[i][0]-omega[j][0])/2.0; - wd[1] = (omega[i][1]-omega[j][1])/2.0; - wd[2] = (omega[i][2]-omega[j][2])/2.0; - - nx=-delx/r;ny=-dely/r;nz=-delz/r; - - - hinv=(radi+radj)/(2.0*h_sep); - lhinv=log(hinv); - - if(lhinv < 0) error->all(FLERR,"Using pair lubricate with cutoff problem: log(1/h) is negative"); - - beta0=radj/radi; - beta1=1.0+beta0; - - double b0p2,b1p2,b1p3,mupradi; - b0p2=beta0*beta0; - b1p2=beta1*beta1; - b1p3=beta1*b1p2; - mupradi=mu*MY_PI*radi; - - // scalar resistances - if (flaglog) { - XA11=6.0*mupradi*( hinv*2.0*b0p2 + lhinv*beta0*(1.0+ 7.0*beta0+ b0p2 )/5.0 )/b1p3; - YA11=1.6*mupradi*lhinv*beta0*(2.0+beta0+2.0*b0p2)/b1p3; - YB11=-0.8*mupradi*radi*lhinv*beta0*(4.0+beta0)/b1p2; - YC12=0.8*mupradi*radi*radi*lhinv*b0p2/beta1*(1.0-4.0/beta0); //YC12*(1-4/beta0) - } - else XA11=12.0*mupradi*hinv*b0p2/b1p3; - - - - /* - if (flaglog) { - XA11=6.0*MY_PI*mu*radi*( hinv*2.0*pow(beta0,2.0) + lhinv*beta0*(1.0+ 7.0*beta0+ beta0*beta0)/5.0 )/pow(beta1,3.0); - YA11=1.6*MY_PI*mu*radi*lhinv*beta0*(2.0+beta0+2.0*beta0*beta0)/pow(beta1,3.0); - YB11=-0.8*MY_PI*mu*radi*radi*lhinv*beta0*(4.0+beta0)/(beta1*beta1); - YC12=0.8*MY_PI*mu*pow(radi,3.0)*lhinv*beta0*beta0/beta1*(1.0-4.0/beta0); //YC12*(1-4/beta0) - } - else XA11=12*MY_PI*mu*radi*hinv*pow(beta0,2.0)/pow(beta1,3.0); - */ - // Relative velocity components U^2-U^1 - vr1 = v[j][0] - v[i][0]; - vr2 = v[j][1] - v[i][1]; - vr3 = v[j][2] - v[i][2]; - - // normal component (vr.n)n - - vnnr = vr1*nx + vr2*ny + vr3*nz; - vn1 = vnnr*nx; - vn2 = vnnr*ny; - vn3 = vnnr*nz; - - // tangential component vr - (vr.n)n - - vt1 = vr1 - vn1; - vt2 = vr2 - vn2; - vt3 = vr3 - vn3; - - // force due to squeeze type motion - //f=XA11 nn dot vr - fx = XA11*vn1; - fy = XA11*vn2; - fz = XA11*vn3; - - - // force due to all shear kind of motions - - if (flaglog) { - double ybfac=(1.0-beta0*(1.0+4.0*beta0)/(4.0+beta0))*YB11; - //f+=YA11*vt1-(r1+r2)*YA11*ws cross n + ybfac* wd cross n - fx = fx + YA11*(vt1-(radi+radj)*(ws[1]*nz-ws[2]*ny))+ybfac*(wd[1]*nz-wd[2]*ny); - fy = fy + YA11*(vt2-(radi+radj)*(ws[2]*nx-ws[0]*nz))+ybfac*(wd[2]*nx-wd[0]*nz); - fz = fz + YA11*(vt3-(radi+radj)*(ws[0]*ny-ws[1]*nx))+ybfac*(wd[0]*ny-wd[1]*nx); - } - - // scale forces for appropriate units - - fx *= vxmu2f; - fy *= vxmu2f; - fz *= vxmu2f; - - // add to total force - - f[i][0] += fx; - f[i][1] += fy; - f[i][2] += fz; - - // torque due to this force - - if (flaglog) { - double wsdotn,wddotn; - wsdotn=ws[0]*nx+ws[1]*ny+ws[2]*nz; - wddotn=wd[0]*nx+wd[1]*ny+wd[2]*nz; - - //squeeze+shear+pump contributions to torque - //YB11*(vr cross n + (r1+r2)* tang(ws)) +YC12*(1-4/beta)*tang(wd) - tx = YB11*(vr2*nz -vr3*ny + (radi+radj)*(ws[0]-wsdotn*nx)) + YC12*(wd[0]-wddotn*nx); - ty = YB11*(vr3*nx -vr1*nz + (radi+radj)*(ws[1]-wsdotn*ny)) + YC12*(wd[1]-wddotn*ny); - tz = YB11*(vr1*ny -vr2*nx + (radi+radj)*(ws[2]-wsdotn*nz)) + YC12*(wd[2]-wddotn*nz); - - torque[i][0] += vxmu2f*tx; - torque[i][1] += vxmu2f*ty; - torque[i][2] += vxmu2f*tz; - } - - // set j = nlocal so that only I gets tallied - - if (evflag) ev_tally_xyz(i,nlocal,nlocal,0,0.0,0.0,fx,fy,fz,delx,dely,delz); - // - //Add up stresslet for particle i - //v_tally_tensor(i,nlocal,nlocal,newton_pair,fx*delx,fy*dely,fz*delz, - //0.5*(fx*dely+fy*delx),0.5*(fx*delz+fz*delx),0.5*(fy*delz+fz*dely)); - - } - } + domain->x2lamda(x[i],lamda); + double *h_rate = domain->h_rate; + double *h_ratelo = domain->h_ratelo; + vstream[0] = h_rate[0]*lamda[0] + h_rate[5]*lamda[1] + + h_rate[4]*lamda[2] + h_ratelo[0]; + vstream[1] = h_rate[1]*lamda[1] + h_rate[3]*lamda[2] + h_ratelo[1]; + vstream[2] = h_rate[2]*lamda[2] + h_ratelo[2]; + + + R0 = 6.0*MY_PI*mu; + RT0 = 8.0*MY_PI*mu; + RS0 = 20.0/3.0*MY_PI*mu; + + f[i][0] += vxmu2f*R0*radi*(vstream[0]-v[i][0]); + f[i][1] += vxmu2f*R0*radi*(vstream[1]-v[i][1]); + f[i][2] += vxmu2f*R0*radi*(vstream[2]-v[i][2]); + + const double radi3 = radi*radi*radi; + + torque[i][0] -= vxmu2f*RT0*radi3*(omega[i][0]+0.5*h_rate[3]/domain->zprd); + torque[i][1] -= vxmu2f*RT0*radi3*(omega[i][1]-0.5*h_rate[4]/domain->zprd); + torque[i][2] -= vxmu2f*RT0*radi3*(omega[i][2]+0.5*h_rate[5]/domain->yprd); + + // Ef = (grad(vstream) + (grad(vstream))^T) / 2 + // set Ef from h_rate in strain units + if(shearing){ + Ef[0][0] = h_rate[0]/domain->xprd; + Ef[1][1] = h_rate[1]/domain->yprd; + Ef[2][2] = h_rate[2]/domain->zprd; + Ef[0][1] = Ef[1][0] = 0.5 * h_rate[5]/domain->yprd; + Ef[0][2] = Ef[2][0] = 0.5 * h_rate[4]/domain->zprd; + Ef[1][2] = Ef[2][1] = 0.5 * h_rate[3]/domain->zprd; + + if (vflag_either) { + double vRS0 = -vxmu2f* RS0*radi3; + v_tally_tensor(i,i,nlocal,newton_pair, + vRS0*Ef[0][0],vRS0*Ef[1][1],vRS0*Ef[2][2], + vRS0*Ef[0][1],vRS0*Ef[0][2],vRS0*Ef[1][2]); } + } + } + + if (!flagHI)continue; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + jtype = type[j]; + radj = atom->radius[j]; + double radsum = radi+radj; //Sum of two particle's radii + + if (rsq < cutsq[itype][jtype] and rsq < (1.45*1.45*radsum*radsum) ) { + r = sqrt(rsq); + + // scalar resistances XA and YA + + h_sep = r - radsum; + + // if less than the minimum gap use the minimum gap instead + + if (r < cut_inner[itype][jtype]*radsum) //Scaled inner cutoff by particle radii + h_sep = cut_inner[itype][jtype]*radsum - radsum; + + double hinv,lhinv,XA11=0.0,YA11=0.0,YB11=0.0,YC12=0.0,ws[3],wd[3],nx,ny,nz; + ws[0] = (omega[i][0]+omega[j][0])/2.0; + ws[1] = (omega[i][1]+omega[j][1])/2.0; + ws[2] = (omega[i][2]+omega[j][2])/2.0; + + wd[0] = (omega[i][0]-omega[j][0])/2.0; + wd[1] = (omega[i][1]-omega[j][1])/2.0; + wd[2] = (omega[i][2]-omega[j][2])/2.0; + + nx=-delx/r;ny=-dely/r;nz=-delz/r; + + + hinv=(radi+radj)/(2.0*h_sep); + lhinv=log(hinv); + + if(lhinv < 0) error->all(FLERR,"Using pair lubricate with cutoff problem: log(1/h) is negative"); + + beta0=radj/radi; + beta1=1.0+beta0; + + double b0p2,b1p2,b1p3,mupradi; + b0p2=beta0*beta0; + b1p2=beta1*beta1; + b1p3=beta1*b1p2; + mupradi=mu*MY_PI*radi; + + // scalar resistances + if (flaglog) { + XA11=6.0*mupradi*( hinv*2.0*b0p2 + lhinv*beta0*(1.0+ 7.0*beta0+ b0p2 )/5.0 )/b1p3; + YA11=1.6*mupradi*lhinv*beta0*(2.0+beta0+2.0*b0p2)/b1p3; + YB11=-0.8*mupradi*radi*lhinv*beta0*(4.0+beta0)/b1p2; + YC12=0.8*mupradi*radi*radi*lhinv*b0p2/beta1*(1.0-4.0/beta0); //YC12*(1-4/beta0) + } + else XA11=12.0*mupradi*hinv*b0p2/b1p3; + + + + /* + if (flaglog) { + XA11=6.0*MY_PI*mu*radi*( hinv*2.0*pow(beta0,2.0) + lhinv*beta0*(1.0+ 7.0*beta0+ beta0*beta0)/5.0 )/pow(beta1,3.0); + YA11=1.6*MY_PI*mu*radi*lhinv*beta0*(2.0+beta0+2.0*beta0*beta0)/pow(beta1,3.0); + YB11=-0.8*MY_PI*mu*radi*radi*lhinv*beta0*(4.0+beta0)/(beta1*beta1); + YC12=0.8*MY_PI*mu*pow(radi,3.0)*lhinv*beta0*beta0/beta1*(1.0-4.0/beta0); //YC12*(1-4/beta0) + } + else XA11=12*MY_PI*mu*radi*hinv*pow(beta0,2.0)/pow(beta1,3.0); + */ + // Relative velocity components U^2-U^1 + vr1 = v[j][0] - v[i][0]; + vr2 = v[j][1] - v[i][1]; + vr3 = v[j][2] - v[i][2]; + + // normal component (vr.n)n + + vnnr = vr1*nx + vr2*ny + vr3*nz; + vn1 = vnnr*nx; + vn2 = vnnr*ny; + vn3 = vnnr*nz; + + // tangential component vr - (vr.n)n + + vt1 = vr1 - vn1; + vt2 = vr2 - vn2; + vt3 = vr3 - vn3; + + // force due to squeeze type motion + //f=XA11 nn dot vr + fx = XA11*vn1; + fy = XA11*vn2; + fz = XA11*vn3; + + + // force due to all shear kind of motions + + if (flaglog) { + double ybfac=(1.0-beta0*(1.0+4.0*beta0)/(4.0+beta0))*YB11; + //f+=YA11*vt1-(r1+r2)*YA11*ws cross n + ybfac* wd cross n + fx = fx + YA11*(vt1-(radi+radj)*(ws[1]*nz-ws[2]*ny))+ybfac*(wd[1]*nz-wd[2]*ny); + fy = fy + YA11*(vt2-(radi+radj)*(ws[2]*nx-ws[0]*nz))+ybfac*(wd[2]*nx-wd[0]*nz); + fz = fz + YA11*(vt3-(radi+radj)*(ws[0]*ny-ws[1]*nx))+ybfac*(wd[0]*ny-wd[1]*nx); + } + + // scale forces for appropriate units + + fx *= vxmu2f; + fy *= vxmu2f; + fz *= vxmu2f; + + // add to total force + + f[i][0] += fx; + f[i][1] += fy; + f[i][2] += fz; + + if(newton_pair || j < nlocal) { + f[j][0] -= fx; + f[j][1] -= fy; + f[j][2] -= fz; + } + + // torque due to this force + + if (flaglog) { + double wsdotn,wddotn; + wsdotn=ws[0]*nx+ws[1]*ny+ws[2]*nz; + wddotn=wd[0]*nx+wd[1]*ny+wd[2]*nz; + + //squeeze+shear+pump contributions to torque + //YB11*(vr cross n + (r1+r2)* tang(ws)) +YC12*(1-4/beta)*tang(wd) + double tx = YB11*(vr2*nz -vr3*ny + (radi+radj)*(ws[0]-wsdotn*nx)); + double ty = YB11*(vr3*nx -vr1*nz + (radi+radj)*(ws[1]-wsdotn*ny)); + double tz = YB11*(vr1*ny -vr2*nx + (radi+radj)*(ws[2]-wsdotn*nz)); + + double ttx = YC12*(wd[0]-wddotn*nx); + double tty = YC12*(wd[1]-wddotn*ny); + double ttz = YC12*(wd[2]-wddotn*nz); + + torque[i][0] += vxmu2f * (tx + ttx); + torque[i][1] += vxmu2f * (ty + tty); + torque[i][2] += vxmu2f * (tz + ttz); + + if(newton_pair || j < nlocal) { + torque[j][0] += vxmu2f * (tx - ttx); + torque[j][1] += vxmu2f * (ty - tty); + torque[j][2] += vxmu2f * (tz - ttz); + } + } + + // set j = nlocal so that only I gets tallied + + if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair,0.0,0.0,fx,fy,fz,delx,dely,delz); + // + //Add up stresslet for particle i + //v_tally_tensor(i,nlocal,nlocal,newton_pair,fx*delx,fy*dely,fz*delz, + //0.5*(fx*dely+fy*delx),0.5*(fx*delz+fz*delx),0.5*(fy*delz+fz*dely)); + + } + } + + } + } /* ---------------------------------------------------------------------- @@ -317,82 +332,84 @@ void PairLubricateSimple::compute(int eflag, int vflag) void PairLubricateSimple::init_style() { - if (force->newton_pair == 1) - error->all(FLERR,"Pair lubricate/poly requires newton pair off"); - if (comm->ghost_velocity == 0) - error->all(FLERR, - "Pair lubricate/poly requires ghost atoms store velocity"); - if (!atom->sphere_flag) - error->all(FLERR,"Pair lubricate/poly requires atom style sphere"); - - // ensure all particles are finite-size - // for pair hybrid, should limit test to types using the pair style - - double *radius = atom->radius; - int nlocal = atom->nlocal; - - for (int i = 0; i < nlocal; i++) - if (radius[i] == 0.0) - error->one(FLERR,"Pair lubricate/poly requires extended particles"); - - neighbor->add_request(this, NeighConst::REQ_FULL); - - // set the isotropic constants that depend on the volume fraction - // vol_T = total volume - - // check for fix deform, if exists it must use "remap v" - // If box will change volume, set appropriate flag so that volume - // and v.f. corrections are re-calculated at every step. - - // Ranga: Volume fraction correction unnecessary for our purposes - // if available volume is different from box volume - // due to walls, set volume appropriately; if walls will - // move, set appropriate flag so that volume and v.f. corrections - // are re-calculated at every step. - - shearing = flagdeform = flagwall = 0; - for (int i = 0; i < modify->nfix; i++){ - if (strcmp(modify->fix[i]->style,"deform") == 0) { - shearing = flagdeform = 1; - if (((FixDeform *) modify->fix[i])->remapflag != V_REMAP) - error->all(FLERR,"Using pair lubricate with inconsistent " - "fix deform remap option"); - } - if (strstr(modify->fix[i]->style,"wall") != NULL) { - if (flagwall) - error->all(FLERR, - "Cannot use multiple fix wall commands with " - "pair lubricate/poly"); - flagwall = 1; // Walls exist - wallfix = (FixWall *) modify->fix[i]; - if (wallfix->xflag) flagwall = 2; // Moving walls exist - } - - if (strstr(modify->fix[i]->style,"wall") != NULL){ - flagwall = 1; // Walls exist - if (((FixWall *) modify->fix[i])->xflag ) { - flagwall = 2; // Moving walls exist - wallfix = (FixWall *) modify->fix[i]; - } - } - } - - // check for fix deform, if exists it must use "remap v" - - shearing = 0; - for (int i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"deform") == 0) { - shearing = 1; - if (((FixDeform *) modify->fix[i])->remapflag != V_REMAP) - error->all(FLERR,"Using pair lubricate/poly with inconsistent " - "fix deform remap option"); - } - - // set Ef = 0 since used whether shearing or not - - Ef[0][0] = Ef[0][1] = Ef[0][2] = 0.0; - Ef[1][0] = Ef[1][1] = Ef[1][2] = 0.0; - Ef[2][0] = Ef[2][1] = Ef[2][2] = 0.0; + if (force->newton_pair == 1) + error->all(FLERR,"Pair lubricate/poly requires newton pair off"); + if (comm->ghost_velocity == 0) + error->all(FLERR, + "Pair lubricate/poly requires ghost atoms store velocity"); + if (!atom->sphere_flag) + error->all(FLERR,"Pair lubricate/poly requires atom style sphere"); + + // ensure all particles are finite-size + // for pair hybrid, should limit test to types using the pair style + + double *radius = atom->radius; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) + if (radius[i] == 0.0) + error->one(FLERR,"Pair lubricate/poly requires extended particles"); + + // CHRIS:: IMPORTANT :: support for half list was added + //neighbor->add_request(this, NeighConst::REQ_FULL); + neighbor->add_request(this); + + // set the isotropic constants that depend on the volume fraction + // vol_T = total volume + + // check for fix deform, if exists it must use "remap v" + // If box will change volume, set appropriate flag so that volume + // and v.f. corrections are re-calculated at every step. + + // Ranga: Volume fraction correction unnecessary for our purposes + // if available volume is different from box volume + // due to walls, set volume appropriately; if walls will + // move, set appropriate flag so that volume and v.f. corrections + // are re-calculated at every step. + + shearing = flagdeform = flagwall = 0; + for (int i = 0; i < modify->nfix; i++){ + if (strcmp(modify->fix[i]->style,"deform") == 0 || strcmp(modify->fix[i]->style,"deform/kk") == 0) { + shearing = flagdeform = 1; + if (((FixDeform *) modify->fix[i])->remapflag != V_REMAP) + error->all(FLERR,"Using pair lubricate with inconsistent " + "fix deform remap option"); + } + if (strstr(modify->fix[i]->style,"wall") != NULL) { + if (flagwall) + error->all(FLERR, + "Cannot use multiple fix wall commands with " + "pair lubricate/poly"); + flagwall = 1; // Walls exist + wallfix = (FixWall *) modify->fix[i]; + if (wallfix->xflag) flagwall = 2; // Moving walls exist + } + + if (strstr(modify->fix[i]->style,"wall") != NULL){ + flagwall = 1; // Walls exist + if (((FixWall *) modify->fix[i])->xflag ) { + flagwall = 2; // Moving walls exist + wallfix = (FixWall *) modify->fix[i]; + } + } + } + + // check for fix deform, if exists it must use "remap v" + + shearing = 0; // then why set it above?? + for (int i = 0; i < modify->nfix; i++) + if (strcmp(modify->fix[i]->style,"deform") == 0 || strcmp(modify->fix[i]->style,"deform/kk") == 0) { + shearing = 1; + if (((FixDeform *) modify->fix[i])->remapflag != V_REMAP) + error->all(FLERR,"Using pair lubricate/poly with inconsistent " + "fix deform remap option"); + } + + // set Ef = 0 since used whether shearing or not + + Ef[0][0] = Ef[0][1] = Ef[0][2] = 0.0; + Ef[1][0] = Ef[1][1] = Ef[1][2] = 0.0; + Ef[2][0] = Ef[2][1] = Ef[2][2] = 0.0; } /* ---------------------------------------------------------------------- diff --git a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp b/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp new file mode 100644 index 0000000000..d135a90808 --- /dev/null +++ b/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp @@ -0,0 +1,770 @@ +// 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 "pair_lubricate_Simple_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "domain_kokkos.h" +#include "error.h" +#include "fix.h" +#include "fix_wall.h" +#include "force.h" +#include "input.h" +#include "kokkos.h" +#include "math_const.h" +#include "math_special_kokkos.h" +#include "memory_kokkos.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" +#include "variable.h" + +#include + +using namespace LAMMPS_NS; +using namespace MathConst; +using namespace MathSpecialKokkos; + +// same as fix_wall.cpp + +enum { EDGE, CONSTANT, VARIABLE }; + +//#define _NO_RANDOM + +/* ---------------------------------------------------------------------- */ + +template +PairLubricateSimpleKokkos::PairLubricateSimpleKokkos(LAMMPS *lmp) : PairLubricateSimple(lmp) +{ + respa_enable = 0; + + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + domainKK = (DomainKokkos *) domain; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | V_MASK | F_MASK | OMEGA_MASK | TORQUE_MASK | TYPE_MASK | VIRIAL_MASK | RADIUS_MASK; + datamask_modify = F_MASK | TORQUE_MASK | VIRIAL_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +PairLubricateSimpleKokkos::~PairLubricateSimpleKokkos() +{ + if (copymode) return; + + if (allocated) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->destroy_kokkos(k_cut_inner,cut_inner); + memoryKK->destroy_kokkos(k_cutsq,cutsq); + } +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLubricateSimpleKokkos::init_style() +{ + printf("Inside PairLubricateSimpleKokkos::init_style()\n"); + PairLubricateSimple::init_style(); + + // error if rRESPA with inner levels + + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { + int respa = 0; + if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; + if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; + if (respa) + error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); + } + + // adjust neighbor list request for KOKKOS + + neighflag = lmp->kokkos->neighflag; + auto request = neighbor->find_request(this); + // auto request = neighbor->add_request(this, NeighConst::REQ_FULL); + request->set_kokkos_host(std::is_same_v && + !std::is_same_v); + request->set_kokkos_device(std::is_same_v); + //if (neighflag == FULL) request->enable_full(); + // if (neighflag != FULL) + // error->all(FLERR,"Must use full neighbor list style with lubricate/simple/kk"); + printf("Leaving PairLubricateSimpleKokkos::init_style() shearing= %i\n",shearing); +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLubricateSimpleKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + if (neighflag == FULL) no_virial_fdotr_compute = 1; + + ev_init(eflag,vflag,0); + + // reallocate per-atom arrays if necessary + + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_inner.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK | TORQUE_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + v = atomKK->k_v.view(); + f = atomKK->k_f.view(); + omega = atomKK->k_omega.view(); + torque = atomKK->k_torque.view(); + type = atomKK->k_type.view(); + radius = atomKK->k_radius.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + newton_pair = force->newton_pair; + vxmu2f = force->vxmu2f; + + // loop over neighbors of my atoms + + int inum = list->inum; + NeighListKokkos* k_list = static_cast*>(list); + d_numneigh = k_list->d_numneigh; + d_neighbors = k_list->d_neighbors; + d_ilist = k_list->d_ilist; + + copymode = 1; + + // FLD contribution to force & torque + + R0 = 6.0*MY_PI*mu; + RT0 = 8.0*MY_PI*mu; + RS0 = 20.0/3.0*MY_PI*mu; + + h_rate = domainKK->h_rate; + h_ratelo = domainKK->h_ratelo; + + xprd = domainKK->xprd; + yprd = domainKK->yprd; + zprd = domainKK->zprd; + + if(flagfld) { + + if(shearing) { + double *h_rate = domainKK->h_rate; + Ef[0][0] = h_rate[0]/xprd; + Ef[1][1] = h_rate[1]/yprd; + Ef[2][2] = h_rate[2]/zprd; + Ef[0][1] = Ef[1][0] = 0.5 * h_rate[5]/yprd; + Ef[0][2] = Ef[2][0] = 0.5 * h_rate[4]/zprd; + Ef[1][2] = Ef[2][1] = 0.5 * h_rate[3]/zprd; + // needs to be a k_Ef + } + + EV_FLOAT ev; + + // printf("pair::compute() flagfld= %i shearing= %i nlocal= %i inum= %i vxmu2f= %f prd= %f %f %f\n",flagfld,shearing,atom->nlocal,inum,vxmu2f,xprd,yprd,zprd); + // printf(" h_rate= %f %f %f %f %f %f\n",h_rate[0],h_rate[1],h_rate[2],h_rate[3],h_rate[4],h_rate[5]); + // printf(" h_ratelo= %f %f %f\n",h_ratelo[0],h_ratelo[1],h_ratelo[2]); + // printf(" Ef= %f %f %f %f %f %f\n",Ef[0][0],Ef[1][1],Ef[2][2],Ef[0][1],Ef[0][2],Ef[1][2]); + +#if 1 + domainKK->x2lamda(atom->nlocal); + if(shearing && vflag_either) { + if (neighflag == HALF) { + if(newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); + } else if (neighflag == HALFTHREAD) { + if(newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); + } else if (neighflag == FULL) { + if(newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); + } + } else { // value of NEWTON_PAIR not used, so just 0 + if (neighflag == HALF) Kokkos::parallel_for(Kokkos::RangePolicy >(0,nlocal),*this); + else if (neighflag == HALFTHREAD) Kokkos::parallel_for(Kokkos::RangePolicy >(0,nlocal),*this); + else if (neighflag == FULL) Kokkos::parallel_for(Kokkos::RangePolicy >(0,nlocal),*this); + } + domainKK->lamda2x(atom->nlocal); + + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } +#endif + } + + EV_FLOAT ev; + + if(flagHI) { + + if (flagfld) { // FLAGFLD == 1 + if (vflag_either) { // VFLAG == 1 + if (neighflag == HALF) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + } else if (neighflag == HALFTHREAD) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + } else if (neighflag == FULL) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + } + } else { // VFLAG==0 + if (neighflag == HALF) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + } else if (neighflag == HALFTHREAD) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + } else if (neighflag == FULL) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + } + } + } else { // FLAGFLD == 0 + if (evflag) { // VFLAG== 1 + if (neighflag == HALF) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + } else if (neighflag == HALFTHREAD) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + } else if (neighflag == FULL) { + if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); + } + } else { // VFLAG == 0 + if (neighflag == HALF) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + } else if (neighflag == HALFTHREAD) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + } else if (neighflag == FULL) { + if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); + } + } + } + + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + } // if(flagHI) + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.template sync(); + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + + +template +template +KOKKOS_INLINE_FUNCTION +void PairLubricateSimpleKokkos::operator()(TagPairLubricateSimpleComputeFLD, const int ii, EV_FLOAT &ev) const { + + // The f and torque arrays are atomic for Half/Thread neighbor style + Kokkos::View::value,Kokkos::MemoryTraits::value> > a_f = f; + Kokkos::View::value,Kokkos::MemoryTraits::value> > a_torque = torque; + + const int i = d_ilist[ii]; + const LMP_FLOAT radi = radius[i]; + + LMP_FLOAT vstream[3]; + vstream[0] = h_rate[0]*x(i,0) + h_rate[5]*x(i,1) + h_rate[4]*x(i,2) + h_ratelo[0]; + vstream[1] = h_rate[1]*x(i,1) + h_rate[3]*x(i,2) + h_ratelo[1]; + vstream[2] = h_rate[2]*x(i,2) + h_ratelo[2]; + + a_f(i,0) += vxmu2f*R0*radi*(vstream[0]-v(i,0)); + a_f(i,1) += vxmu2f*R0*radi*(vstream[1]-v(i,1)); + a_f(i,2) += vxmu2f*R0*radi*(vstream[2]-v(i,2)); + + const LMP_FLOAT radi3 = radi*radi*radi; + + a_torque(i,0) -= vxmu2f*RT0*radi3*(omega(i,0)+0.5*h_rate[3]/zprd); + a_torque(i,1) -= vxmu2f*RT0*radi3*(omega(i,1)-0.5*h_rate[4]/zprd); + a_torque(i,2) -= vxmu2f*RT0*radi3*(omega(i,2)+0.5*h_rate[5]/yprd); + + // Ef = (grad(vstream) + (grad(vstream))^T) / 2 + // set Ef from h_rate in strain units + + if(SHEARING){ + double vRS0 = 1.0; //-vxmu2f * RS0*radi3; + v_tally_tensor(ev,i,i, + vRS0*Ef[0][0],vRS0*Ef[1][1],vRS0*Ef[2][2], + vRS0*Ef[0][1],vRS0*Ef[0][2],vRS0*Ef[1][2]); + } + +} + +template +template +KOKKOS_INLINE_FUNCTION +void PairLubricateSimpleKokkos::operator()(TagPairLubricateSimpleComputeFLD, const int ii) const { + EV_FLOAT ev; + this->template operator()(TagPairLubricateSimpleComputeFLD(), ii, ev); +} + +template +template +KOKKOS_INLINE_FUNCTION +void PairLubricateSimpleKokkos::operator()(TagPairLubricateSimpleCompute, const int ii, EV_FLOAT &ev) const { + + // The f and torque arrays are atomic for Half/Thread neighbor style + Kokkos::View::value,Kokkos::MemoryTraits::value> > a_f = f; + Kokkos::View::value,Kokkos::MemoryTraits::value> > a_torque = torque; + + const int i = d_ilist[ii]; + const X_FLOAT xtmp = x(i,0); + const X_FLOAT ytmp = x(i,1); + const X_FLOAT ztmp = x(i,2); + const int itype = type[i]; + const LMP_FLOAT radi = radius[i]; + const int jnum = d_numneigh[i]; + + LMP_FLOAT wsx,wsy,wsz; + LMP_FLOAT wdx,wdy,wdz; + + F_FLOAT fx_i = 0.0; + F_FLOAT fy_i = 0.0; + F_FLOAT fz_i = 0.0; + + F_FLOAT torquex_i = 0.0; + F_FLOAT torquey_i = 0.0; + F_FLOAT torquez_i = 0.0; + + for (int jj = 0; jj < jnum; jj++) { + int j = d_neighbors(i,jj); + j &= NEIGHMASK; + + const X_FLOAT delx = xtmp - x(j,0); + const X_FLOAT dely = ytmp - x(j,1); + const X_FLOAT delz = ztmp - x(j,2); + const X_FLOAT rsq = delx*delx + dely*dely + delz*delz; + const int jtype = type[j]; + const LMP_FLOAT radj = radius[j]; + + double radsum = radi + radj; // Sum of two particle's radii + + if(rsq < d_cutsq(itype,jtype) && rsq < 1.45*1.45*radsum*radsum) { + const LMP_FLOAT r = sqrt(rsq); + + // scalar resistances XA and YA + + LMP_FLOAT h_sep = r - radsum; + + // if less than minimum gap (scaled inner cutoff by particle radii), use minimum gap instead + + if (r < d_cut_inner(itype,jtype)*radsum) h_sep = d_cut_inner(itype,jtype)*radsum - radsum; + + const LMP_FLOAT wsx = (omega(i,0) + omega(j,0)) * 0.5; + const LMP_FLOAT wsy = (omega(i,1) + omega(j,1)) * 0.5; + const LMP_FLOAT wsz = (omega(i,2) + omega(j,2)) * 0.5; + + const LMP_FLOAT wdx = (omega(i,0) - omega(j,0)) * 0.5; + const LMP_FLOAT wdy = (omega(i,1) - omega(j,1)) * 0.5; + const LMP_FLOAT wdz = (omega(i,2) - omega(j,2)) * 0.5; + + const LMP_FLOAT nx = -delx / r; + const LMP_FLOAT ny = -dely / r; + const LMP_FLOAT nz = -delz / r; + + const LMP_FLOAT hinv = (radi + radj) / (2.0 * h_sep); + + const LMP_FLOAT lhinv = log(hinv); + //if(lhinv < 0.0) error->all(FLERR,"Using pair lubricate with cutoff problem: log(1/h) is negative"); + + const LMP_FLOAT beta0 = radj / radi; + const LMP_FLOAT beta1 = 1.0 + beta0; + + const LMP_FLOAT b0p2 = beta0 * beta0; + const LMP_FLOAT b1p2 = beta1 * beta1; + const LMP_FLOAT b1p3 = beta1 * b1p2; + const LMP_FLOAT mupradi = mu * MY_PI * radi; + + // scalar resistances + + LMP_FLOAT XA11, YA11, YB11, YC12; + if(flaglog) { + XA11 = 6.0*mupradi*( hinv*2.0*b0p2 + lhinv*beta0*(1.0+ 7.0*beta0+ b0p2 )/5.0 )/b1p3; + YA11 = 1.6*mupradi*lhinv*beta0*(2.0+beta0+2.0*b0p2)/b1p3; + YB11 = -0.8*mupradi*radi*lhinv*beta0*(4.0+beta0)/b1p2; + YC12 = 0.8*mupradi*radi*radi*lhinv*b0p2/beta1*(1.0-4.0/beta0); //YC12*(1-4/beta0) + } else { + XA11 = 12.0*mupradi*hinv*b0p2/b1p3; + } + + // relative velocity components U^2-U^1 + + LMP_FLOAT vr1 = v(j,0) - v(i,0); + LMP_FLOAT vr2 = v(j,1) - v(i,1); + LMP_FLOAT vr3 = v(j,2) - v(i,2); + + // normal component (vr.n)n + + LMP_FLOAT vnnr = vr1*nx + vr2*ny + vr3*nz; + LMP_FLOAT vn1 = vnnr * nx; + LMP_FLOAT vn2 = vnnr * ny; + LMP_FLOAT vn3 = vnnr * nz; + + // tangential component vr - (vr.n)n + + LMP_FLOAT vt1 = vr1 - vn1; + LMP_FLOAT vt2 = vr2 - vn2; + LMP_FLOAT vt3 = vr3 - vn3; + + // force due to squeeze type motion : f = XA11 nn dot vr + + F_FLOAT fx = XA11 * vn1; + F_FLOAT fy = XA11 * vn2; + F_FLOAT fz = XA11 * vn3; + + // force due to all shear kind of motions + + if(flaglog) { + LMP_FLOAT ybfac = (1.0-beta0*(1.0+4.0*beta0)/(4.0+beta0))*YB11; + //f+=YA11*vt1-(r1+r2)*YA11*ws cross n + ybfac* wd cross n + fx += YA11 * (vt1-(radi+radj)*(wsy*nz-wsz*ny)) + ybfac * (wdy*nz-wdz*ny); + fy += YA11 * (vt2-(radi+radj)*(wsz*nx-wsx*nz)) + ybfac * (wdz*nx-wdx*nz); + fz += YA11 * (vt3-(radi+radj)*(wsx*ny-wsy*nx)) + ybfac * (wdx*ny-wdy*nx); + } + + // scale forces for appropriate units + + fx *= vxmu2f; + fy *= vxmu2f; + fz *= vxmu2f; + + fx_i += fx; + fy_i += fy; + fz_i += fz; + + if ((NEIGHFLAG==HALF || NEIGHFLAG==HALFTHREAD) && (NEWTON_PAIR || j < nlocal)) { + a_f(j,0) -= fx; + a_f(j,1) -= fy; + a_f(j,2) -= fz; + } + + // torque due to this force + + if (flaglog) { + + LMP_FLOAT wsdotn = wsx*nx + wsy*ny + wsz*nz; + LMP_FLOAT wddotn = wdx*nx + wdy*ny + wdz*nz; + + // squeeze+shear+pump contributions to torque + + //YB11*(vr cross n + (r1+r2)* tang(ws)) +YC12*(1-4/beta)*tang(wd) + + // YB11 & YC12 are not correct if radi != radj, but pair lubricate requires mono-disperse, so ok... + + F_FLOAT tx = YB11*(vr2*nz -vr3*ny + (radi+radj)*(wsx-wsdotn*nx)); + F_FLOAT ty = YB11*(vr3*nx -vr1*nz + (radi+radj)*(wsy-wsdotn*ny)); + F_FLOAT tz = YB11*(vr1*ny -vr2*nx + (radi+radj)*(wsz-wsdotn*nz)); + + F_FLOAT ttx = YC12*(wdx-wddotn*nx); + F_FLOAT tty = YC12*(wdy-wddotn*ny); + F_FLOAT ttz = YC12*(wdz-wddotn*nz); + + // if(i == 1) printf("i= %i x= %f %f %f x= %f %f %f rsq= %f tq= %f %f %f\n",i, + // x(i,0),x(i,1),x(i,2), + // x(j,0),x(j,1),x(j,2), rsq, tx,ty,tz); + // if(j == 1) printf(" j= %i x= %f %f %f x= %f %f %f rsq= %f tq= %f %f %f\n",i, + // x(i,0),x(i,1),x(i,2), + // x(j,0),x(j,1),x(j,2), rsq, tx,ty,tz); + + // torque is same on both particles ? + + torquex_i += vxmu2f * (tx + ttx); + torquey_i += vxmu2f * (ty + tty); + torquez_i += vxmu2f * (tz + ttz); + + if ((NEIGHFLAG==HALF || NEIGHFLAG==HALFTHREAD) && (NEWTON_PAIR || j < nlocal)) { + a_torque(j,0) += vxmu2f * (tx - ttx); + a_torque(j,1) += vxmu2f * (ty - tty); + a_torque(j,2) += vxmu2f * (tz - ttz); + } + } // if(flaglog) + + if (VFLAG) ev_tally_xyz(ev, i, j, fx, fy, fz, delx, dely, delz); + + } // if(rsq) + } // for(jj) + + a_f(i,0) += fx_i; + a_f(i,1) += fy_i; + a_f(i,2) += fz_i; + a_torque(i,0) += torquex_i; + a_torque(i,1) += torquey_i; + a_torque(i,2) += torquez_i; +} + +template +template +KOKKOS_INLINE_FUNCTION +void PairLubricateSimpleKokkos::operator()(TagPairLubricateSimpleCompute, const int ii) const { + EV_FLOAT ev; + this->template operator()(TagPairLubricateSimpleCompute(), ii, ev); +} + + +/* ---------------------------------------------------------------------- */ + +template +template +KOKKOS_INLINE_FUNCTION +void PairLubricateSimpleKokkos::ev_tally_xyz(EV_FLOAT & ev, int i, int j, + F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, + X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const +{ + Kokkos::View::value,Kokkos::MemoryTraits::value> > v_vatom = k_vatom.view(); + + const F_FLOAT v0 = delx*fx; + const F_FLOAT v1 = dely*fy; + const F_FLOAT v2 = delz*fz; + const F_FLOAT v3 = delx*fy; + const F_FLOAT v4 = delx*fz; + const F_FLOAT v5 = dely*fz; + + if (vflag_global) { + if (NEIGHFLAG != FULL) { + if (NEWTON_PAIR) { // neigh half, newton on + ev.v[0] += v0; + ev.v[1] += v1; + ev.v[2] += v2; + ev.v[3] += v3; + ev.v[4] += v4; + ev.v[5] += v5; + } else { // neigh half, newton off + if (i < nlocal) { + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } + if (j < nlocal) { + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } + } + } else { //neigh full + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } + } + + if (vflag_atom) { + + if (NEIGHFLAG == FULL || NEWTON_PAIR || i < nlocal) { + v_vatom(i,0) += 0.5*v0; + v_vatom(i,1) += 0.5*v1; + v_vatom(i,2) += 0.5*v2; + v_vatom(i,3) += 0.5*v3; + v_vatom(i,4) += 0.5*v4; + v_vatom(i,5) += 0.5*v5; + } + if (NEIGHFLAG != FULL && (NEWTON_PAIR || j < nlocal)) { + v_vatom(j,0) += 0.5*v0; + v_vatom(j,1) += 0.5*v1; + v_vatom(j,2) += 0.5*v2; + v_vatom(j,3) += 0.5*v3; + v_vatom(j,4) += 0.5*v4; + v_vatom(j,5) += 0.5*v5; + } + } +} + +/* ---------------------------------------------------------------------- */ + +template +template +KOKKOS_INLINE_FUNCTION +void PairLubricateSimpleKokkos::v_tally_tensor(EV_FLOAT & ev, int i, int j, + F_FLOAT vxx, F_FLOAT vyy, F_FLOAT vzz, + F_FLOAT vxy, F_FLOAT vxz, F_FLOAT vyz) const +{ + Kokkos::View::value,Kokkos::MemoryTraits::value> > v_vatom = k_vatom.view(); + + const F_FLOAT v0 = vxx; + const F_FLOAT v1 = vyy; + const F_FLOAT v2 = vzz; + const F_FLOAT v3 = vxy; + const F_FLOAT v4 = vxz; + const F_FLOAT v5 = vyz; + + if (vflag_global) { + if (NEIGHFLAG != FULL) { + if (NEWTON_PAIR) { // neigh half, newton on + ev.v[0] += v0; + ev.v[1] += v1; + ev.v[2] += v2; + ev.v[3] += v3; + ev.v[4] += v4; + ev.v[5] += v5; + } else { // neigh half, newton off + if (i < nlocal) { + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } + if (j < nlocal) { + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } + } + } else { //neigh full + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } + } + + if (vflag_atom) { + + if (NEIGHFLAG == FULL || NEWTON_PAIR || i < nlocal) { + v_vatom(i,0) += 0.5*v0; + v_vatom(i,1) += 0.5*v1; + v_vatom(i,2) += 0.5*v2; + v_vatom(i,3) += 0.5*v3; + v_vatom(i,4) += 0.5*v4; + v_vatom(i,5) += 0.5*v5; + } + if (NEIGHFLAG != FULL && (NEWTON_PAIR || j < nlocal)) { + v_vatom(j,0) += 0.5*v0; + v_vatom(j,1) += 0.5*v1; + v_vatom(j,2) += 0.5*v2; + v_vatom(j,3) += 0.5*v3; + v_vatom(j,4) += 0.5*v4; + v_vatom(j,5) += 0.5*v5; + } + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLubricateSimpleKokkos::allocate() +{ + printf("Inside PairLubricateSimpleKokkos::allocate()\n"); + + PairLubricateSimple::allocate(); + + int n = atom->ntypes; + + memory->destroy(cutsq); + memoryKK->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); + d_cutsq = k_cutsq.template view(); + + memory->destroy(cut_inner); + memoryKK->create_kokkos(k_cut_inner,cut_inner,n+1,n+1,"pair:cut_inner"); + d_cut_inner = k_cut_inner.template view(); +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +template +void PairLubricateSimpleKokkos::settings(int narg, char **arg) +{ + if (narg != 5 && narg != 7) error->all(FLERR, "Illegal pair_style command"); + + PairLubricateSimple::settings(narg,arg); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLubricateSimpleKokkos::init_one(int i, int j) +{ + double cutone = PairLubricateSimple::init_one(i,j); + double cutinnerm = cut_inner[i][j]; + + k_cutsq.h_view(i,j) = k_cutsq.h_view(j,i) = cutone*cutone; + k_cutsq.template modify(); + + k_cut_inner.h_view(i,j) = k_cut_inner.h_view(j,i) = cutinnerm; + k_cut_inner.template modify(); + + return cutone; +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +template +void PairLubricateSimpleKokkos::coeff(int narg, char **arg) +{ + PairLubricateSimple::coeff(narg,arg); +} + +namespace LAMMPS_NS { +template class PairLubricateSimpleKokkos; +#ifdef LMP_KOKKOS_GPU +template class PairLubricateSimpleKokkos; +#endif +} diff --git a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.h b/src/USER-SUMAN/pair_lubricate_Simple_kokkos.h new file mode 100644 index 0000000000..2207bc8fce --- /dev/null +++ b/src/USER-SUMAN/pair_lubricate_Simple_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 PAIR_CLASS +// clang-format off +PairStyle(lubricate/Simple/kk,PairLubricateSimpleKokkos); +PairStyle(lubricate/Simple/kk/device,PairLubricateSimpleKokkos); +PairStyle(lubricate/Simple/kk/host,PairLubricateSimpleKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_PAIR_LUBRICATE_SIMPLE_KOKKOS_H +#define LMP_PAIR_LUBRICATE_SIMPLE_KOKKOS_H + +#include "pair_lubricate_Simple.h" +#include "pair_kokkos.h" +//#include "kokkos_type.h" +//#include "kokkos_base.h" +//#include "Kokkos_Random.hpp" +#include "comm_kokkos.h" + +namespace LAMMPS_NS { + +template +struct TagPairLubricateSimpleCompute {}; + +template +struct TagPairLubricateSimpleComputeFLD {}; + +template +class PairLubricateSimpleKokkos : public PairLubricateSimple { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + typedef DeviceType device_type; + typedef ArrayTypes AT; + typedef EV_FLOAT value_type; + + PairLubricateSimpleKokkos(class LAMMPS *); + ~PairLubricateSimpleKokkos() override; + void compute(int, int) override; + void coeff(int, char **) override; + void settings(int, char **) override; + void init_style() override; + double init_one(int, int) override; + + template + KOKKOS_INLINE_FUNCTION + void operator()(TagPairLubricateSimpleCompute, const int, EV_FLOAT &ev) const; + template + KOKKOS_INLINE_FUNCTION + void operator()(TagPairLubricateSimpleCompute, const int) const; + + template + KOKKOS_INLINE_FUNCTION + void operator()(TagPairLubricateSimpleComputeFLD, const int, EV_FLOAT &ev) const; + + template + KOKKOS_INLINE_FUNCTION + void operator()(TagPairLubricateSimpleComputeFLD, const int) const; + + template + KOKKOS_INLINE_FUNCTION + void ev_tally_xyz(EV_FLOAT &ev, int i, int j, + F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, + X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const; + + template + KOKKOS_INLINE_FUNCTION + void v_tally_tensor(EV_FLOAT &ev, int i, int j, + F_FLOAT vxx, F_FLOAT vyy, F_FLOAT vzz, + F_FLOAT vxy, F_FLOAT vxz, F_FLOAT vyz) const; + + protected: + typename AT::t_x_array_randomread x; + typename AT::t_x_array c_x; + typename AT::t_v_array_randomread v; + typename AT::t_v_array_randomread omega; + typename AT::t_f_array f; + typename AT::t_f_array torque; + typename AT::t_int_1d_randomread type; + typename AT::t_float_1d_randomread radius; + + DAT::tdual_virial_array k_vatom; + typename AT::t_virial_array d_vatom; + + typename AT::t_neighbors_2d d_neighbors; + typename AT::t_int_1d_randomread d_ilist; + typename AT::t_int_1d_randomread d_numneigh; + + int newton_pair; + double special_lj[4]; + + typename AT::tdual_ffloat_2d k_cutsq; + typename AT::t_ffloat_2d d_cutsq; + typename AT::tdual_ffloat_2d k_cut_inner; + typename AT::t_ffloat_2d d_cut_inner; + + int neighflag; + int nlocal,nall,eflag,vflag; + LMP_FLOAT vxmu2f; + + LMP_FLOAT R0, RT0, RS0; + LMP_FLOAT xprd, yprd, zprd; + Few h_rate; + Few h_ratelo; + + class DomainKokkos *domainKK; + + void allocate(); + + friend void pair_virial_fdotr_compute(PairLubricateSimpleKokkos*); +}; + +} + +#endif +#endif + From 7261c833dff33f0e39030b6055f0a3061d966fcf Mon Sep 17 00:00:00 2001 From: cjknight Date: Wed, 24 Jan 2024 09:44:51 -0600 Subject: [PATCH 11/43] clean up & fix virial --- src/USER-SUMAN/pair_lubricate_Simple.cpp | 2 +- src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp | 17 ++--------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/USER-SUMAN/pair_lubricate_Simple.cpp b/src/USER-SUMAN/pair_lubricate_Simple.cpp index 68b5126048..219bbde867 100644 --- a/src/USER-SUMAN/pair_lubricate_Simple.cpp +++ b/src/USER-SUMAN/pair_lubricate_Simple.cpp @@ -73,7 +73,7 @@ PairLubricateSimple::~PairLubricateSimple() void PairLubricateSimple::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz,tx,ty,tz; + double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz; double rsq,r,h_sep,beta0,beta1,radi,radj; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3; double vt1,vt2,vt3; diff --git a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp b/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp index d135a90808..8af935acaa 100644 --- a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp +++ b/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp @@ -185,12 +185,6 @@ void PairLubricateSimpleKokkos::compute(int eflag_in, int vflag_in) EV_FLOAT ev; - // printf("pair::compute() flagfld= %i shearing= %i nlocal= %i inum= %i vxmu2f= %f prd= %f %f %f\n",flagfld,shearing,atom->nlocal,inum,vxmu2f,xprd,yprd,zprd); - // printf(" h_rate= %f %f %f %f %f %f\n",h_rate[0],h_rate[1],h_rate[2],h_rate[3],h_rate[4],h_rate[5]); - // printf(" h_ratelo= %f %f %f\n",h_ratelo[0],h_ratelo[1],h_ratelo[2]); - // printf(" Ef= %f %f %f %f %f %f\n",Ef[0][0],Ef[1][1],Ef[2][2],Ef[0][1],Ef[0][2],Ef[1][2]); - -#if 1 domainKK->x2lamda(atom->nlocal); if(shearing && vflag_either) { if (neighflag == HALF) { @@ -218,7 +212,7 @@ void PairLubricateSimpleKokkos::compute(int eflag_in, int vflag_in) virial[4] += ev.v[4]; virial[5] += ev.v[5]; } -#endif + } EV_FLOAT ev; @@ -328,7 +322,7 @@ void PairLubricateSimpleKokkos::operator()(TagPairLubricateSimpleCom // set Ef from h_rate in strain units if(SHEARING){ - double vRS0 = 1.0; //-vxmu2f * RS0*radi3; + double vRS0 = -vxmu2f * RS0*radi3; v_tally_tensor(ev,i,i, vRS0*Ef[0][0],vRS0*Ef[1][1],vRS0*Ef[2][2], vRS0*Ef[0][1],vRS0*Ef[0][2],vRS0*Ef[1][2]); @@ -504,13 +498,6 @@ void PairLubricateSimpleKokkos::operator()(TagPairLubricateSimpleCom F_FLOAT ttx = YC12*(wdx-wddotn*nx); F_FLOAT tty = YC12*(wdy-wddotn*ny); F_FLOAT ttz = YC12*(wdz-wddotn*nz); - - // if(i == 1) printf("i= %i x= %f %f %f x= %f %f %f rsq= %f tq= %f %f %f\n",i, - // x(i,0),x(i,1),x(i,2), - // x(j,0),x(j,1),x(j,2), rsq, tx,ty,tz); - // if(j == 1) printf(" j= %i x= %f %f %f x= %f %f %f rsq= %f tq= %f %f %f\n",i, - // x(i,0),x(i,1),x(i,2), - // x(j,0),x(j,1),x(j,2), rsq, tx,ty,tz); // torque is same on both particles ? From 8cee2604eb50df44856bd96e74290fcc2ea75032 Mon Sep 17 00:00:00 2001 From: cjknight Date: Wed, 24 Jan 2024 10:43:06 -0600 Subject: [PATCH 12/43] remove debug output --- src/USER-SUMAN/pair_lubricate_Simple.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/USER-SUMAN/pair_lubricate_Simple.cpp b/src/USER-SUMAN/pair_lubricate_Simple.cpp index 219bbde867..cfe14bb426 100644 --- a/src/USER-SUMAN/pair_lubricate_Simple.cpp +++ b/src/USER-SUMAN/pair_lubricate_Simple.cpp @@ -418,6 +418,5 @@ void PairLubricateSimple::init_style() void PairLubricateSimple::allocate() { - printf("Inside PairLubricateSimple::allocate()\n"); PairLubricate::allocate(); } From 4889f1b9fd9ed6352c9089c8b22d66a3b3ca6bd9 Mon Sep 17 00:00:00 2001 From: cjknight Date: Wed, 24 Jan 2024 21:55:34 -0600 Subject: [PATCH 13/43] remove print statements --- src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp b/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp index 8af935acaa..a8f71d639c 100644 --- a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp +++ b/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp @@ -81,7 +81,6 @@ PairLubricateSimpleKokkos::~PairLubricateSimpleKokkos() template void PairLubricateSimpleKokkos::init_style() { - printf("Inside PairLubricateSimpleKokkos::init_style()\n"); PairLubricateSimple::init_style(); // error if rRESPA with inner levels @@ -98,14 +97,9 @@ void PairLubricateSimpleKokkos::init_style() neighflag = lmp->kokkos->neighflag; auto request = neighbor->find_request(this); - // auto request = neighbor->add_request(this, NeighConst::REQ_FULL); request->set_kokkos_host(std::is_same_v && !std::is_same_v); request->set_kokkos_device(std::is_same_v); - //if (neighflag == FULL) request->enable_full(); - // if (neighflag != FULL) - // error->all(FLERR,"Must use full neighbor list style with lubricate/simple/kk"); - printf("Leaving PairLubricateSimpleKokkos::init_style() shearing= %i\n",shearing); } /* ---------------------------------------------------------------------- */ @@ -692,9 +686,7 @@ void PairLubricateSimpleKokkos::v_tally_tensor(EV_FLOAT & ev, int i, template void PairLubricateSimpleKokkos::allocate() -{ - printf("Inside PairLubricateSimpleKokkos::allocate()\n"); - +{ PairLubricateSimple::allocate(); int n = atom->ntypes; From 13d42b7955311a9d6623324112446928e99cadce Mon Sep 17 00:00:00 2001 From: cjknight Date: Tue, 28 May 2024 22:11:52 -0500 Subject: [PATCH 14/43] update sphere_flag to radius_flag --- src/USER-SUMAN/pair_brownian.cpp | 2 +- src/USER-SUMAN/pair_brownian_kokkos.cpp | 1 + src/USER-SUMAN/pair_lubricate_Simple.cpp | 4 ++-- src/USER-SUMAN/pair_lubricate_Simple_kokkos.h | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/USER-SUMAN/pair_brownian.cpp b/src/USER-SUMAN/pair_brownian.cpp index 783bea6690..3b1ddfa99e 100644 --- a/src/USER-SUMAN/pair_brownian.cpp +++ b/src/USER-SUMAN/pair_brownian.cpp @@ -476,7 +476,7 @@ void PairBrownian::coeff(int narg, char **arg) void PairBrownian::init_style() { - if (!atom->sphere_flag) error->all(FLERR, "Pair brownian requires atom style sphere"); + if (!atom->radius_flag) error->all(FLERR, "Pair brownian requires atom attribute radius"); // if newton off, forces between atoms ij will be double computed // using different random numbers diff --git a/src/USER-SUMAN/pair_brownian_kokkos.cpp b/src/USER-SUMAN/pair_brownian_kokkos.cpp index 2450d53b37..421fd9666d 100644 --- a/src/USER-SUMAN/pair_brownian_kokkos.cpp +++ b/src/USER-SUMAN/pair_brownian_kokkos.cpp @@ -16,6 +16,7 @@ #include "atom_kokkos.h" #include "atom_masks.h" +#include "domain_kokkos.h" #include "error.h" #include "fix.h" #include "fix_wall.h" diff --git a/src/USER-SUMAN/pair_lubricate_Simple.cpp b/src/USER-SUMAN/pair_lubricate_Simple.cpp index cfe14bb426..49cc2d6024 100644 --- a/src/USER-SUMAN/pair_lubricate_Simple.cpp +++ b/src/USER-SUMAN/pair_lubricate_Simple.cpp @@ -337,8 +337,8 @@ void PairLubricateSimple::init_style() if (comm->ghost_velocity == 0) error->all(FLERR, "Pair lubricate/poly requires ghost atoms store velocity"); - if (!atom->sphere_flag) - error->all(FLERR,"Pair lubricate/poly requires atom style sphere"); + if (!atom->radius_flag) + error->all(FLERR,"Pair lubricate/poly requires atom attribute radius"); // ensure all particles are finite-size // for pair hybrid, should limit test to types using the pair style diff --git a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.h b/src/USER-SUMAN/pair_lubricate_Simple_kokkos.h index 2207bc8fce..144d22412d 100644 --- a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.h +++ b/src/USER-SUMAN/pair_lubricate_Simple_kokkos.h @@ -25,6 +25,7 @@ PairStyle(lubricate/Simple/kk/host,PairLubricateSimpleKokkos); #include "pair_lubricate_Simple.h" #include "pair_kokkos.h" +#include "kokkos_few.h" //#include "kokkos_type.h" //#include "kokkos_base.h" //#include "Kokkos_Random.hpp" From bdbfa7f6e22aaddfd54a78d7fa7d1822ca66042a Mon Sep 17 00:00:00 2001 From: cjknight Date: Wed, 29 May 2024 03:29:37 +0000 Subject: [PATCH 15/43] track pair_brownian changes in COLLOID --- src/COLLOID/pair_brownian.cpp | 59 ++- src/COLLOID/pair_brownian.h | 4 +- src/USER-SUMAN/pair_brownian.cpp | 752 ------------------------------- src/USER-SUMAN/pair_brownian.h | 64 --- 4 files changed, 50 insertions(+), 829 deletions(-) delete mode 100644 src/USER-SUMAN/pair_brownian.cpp delete mode 100644 src/USER-SUMAN/pair_brownian.h diff --git a/src/COLLOID/pair_brownian.cpp b/src/COLLOID/pair_brownian.cpp index 39432ca61b..133136a53e 100644 --- a/src/COLLOID/pair_brownian.cpp +++ b/src/COLLOID/pair_brownian.cpp @@ -42,6 +42,8 @@ using namespace LAMMPS_NS; using namespace MathConst; using namespace MathSpecial; +//#define _NO_RANDOM + /* ---------------------------------------------------------------------- */ PairBrownian::PairBrownian(LAMMPS *lmp) : Pair(lmp) @@ -54,6 +56,8 @@ PairBrownian::PairBrownian(LAMMPS *lmp) : Pair(lmp) PairBrownian::~PairBrownian() { + if(copymode) return; + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); @@ -68,6 +72,10 @@ PairBrownian::~PairBrownian() void PairBrownian::compute(int eflag, int vflag) { +#ifdef _NO_RANDOM + printf("Warning:: PairBrownian::compute() Random numbers all set to 0.5\n"); +#endif + int i, j, ii, jj, inum, jnum, itype, jtype; double xtmp, ytmp, ztmp, delx, dely, delz, fx, fy, fz, tx, ty, tz; double rsq, r, h_sep, radi; @@ -91,7 +99,7 @@ void PairBrownian::compute(int eflag, int vflag) // This section of code adjusts R0/RT0/RS0 if necessary due to changes // in the volume fraction as a result of fix deform or moving walls - + double dims[3], wallcoord; if (flagVF) // Flag for volume fraction corrections if (flagdeform || flagwall == 2) { // Possible changes in volume fraction @@ -134,12 +142,12 @@ void PairBrownian::compute(int eflag, int vflag) prethermostat = sqrt(24.0 * force->boltz * t_target / update->dt); prethermostat *= sqrt(force->vxmu2f / force->ftm2v / force->mvv2e); - + inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; - + for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; @@ -152,6 +160,18 @@ void PairBrownian::compute(int eflag, int vflag) // FLD contribution to force and torque due to isotropic terms +#ifdef _NO_RANDOM + if (flagfld) { + f[i][0] += prethermostat * sqrt(R0) * 0.5; + f[i][1] += prethermostat * sqrt(R0) * 0.5; + f[i][2] += prethermostat * sqrt(R0) * 0.5; + if (flaglog) { + torque[i][0] += prethermostat * sqrt(RT0) * 0.5; + torque[i][1] += prethermostat * sqrt(RT0) * 0.5; + torque[i][2] += prethermostat * sqrt(RT0) * 0.5; + } + } +#else if (flagfld) { f[i][0] += prethermostat * sqrt(R0) * (random->uniform() - 0.5); f[i][1] += prethermostat * sqrt(R0) * (random->uniform() - 0.5); @@ -162,7 +182,8 @@ void PairBrownian::compute(int eflag, int vflag) torque[i][2] += prethermostat * sqrt(RT0) * (random->uniform() - 0.5); } } - +#endif + if (!flagHI) continue; for (jj = 0; jj < jnum; jj++) { @@ -205,7 +226,11 @@ void PairBrownian::compute(int eflag, int vflag) // generate a random number +#ifdef _NO_RANDOM + randr = 0.5; +#else randr = random->uniform() - 0.5; +#endif // contribution due to Brownian motion @@ -230,12 +255,18 @@ void PairBrownian::compute(int eflag, int vflag) // force in each of the two directions +#ifdef _NO_RANDOM + randr = 0.5; +#else randr = random->uniform() - 0.5; +#endif fx += Fbmag * randr * p2[0]; fy += Fbmag * randr * p2[1]; fz += Fbmag * randr * p2[2]; +#ifndef _NO_RANDOM randr = random->uniform() - 0.5; +#endif fx += Fbmag * randr * p3[0]; fy += Fbmag * randr * p3[1]; fz += Fbmag * randr * p3[2]; @@ -246,7 +277,7 @@ void PairBrownian::compute(int eflag, int vflag) fx = vxmu2f * fx; fy = vxmu2f * fy; fz = vxmu2f * fz; - + // sum to total force f[i][0] -= fx; @@ -298,12 +329,18 @@ void PairBrownian::compute(int eflag, int vflag) // force in each direction +#ifdef _NO_RANDOM + randr = 0.5; +#else randr = random->uniform() - 0.5; +#endif tx = Fbmag * randr * p2[0]; ty = Fbmag * randr * p2[1]; tz = Fbmag * randr * p2[2]; +#ifndef _NO_RANDOM randr = random->uniform() - 0.5; +#endif tx += Fbmag * randr * p3[0]; ty += Fbmag * randr * p3[1]; tz += Fbmag * randr * p3[2]; @@ -321,12 +358,12 @@ void PairBrownian::compute(int eflag, int vflag) } } - if (evflag) - ev_tally_xyz(i, j, nlocal, newton_pair, 0.0, 0.0, -fx, -fy, -fz, delx, dely, delz); + if (evflag) + ev_tally_xyz(i, j, nlocal, newton_pair, 0.0, 0.0, -fx, -fy, -fz, delx, dely, delz); } } } - + if (vflag_fdotr) virial_fdotr_compute(); } @@ -434,7 +471,7 @@ void PairBrownian::coeff(int narg, char **arg) ------------------------------------------------------------------------- */ void PairBrownian::init_style() -{ +{ if (!atom->radius_flag) error->all(FLERR, "Pair brownian requires atom attribute radius"); // if newton off, forces between atoms ij will be double computed @@ -477,8 +514,8 @@ void PairBrownian::init_style() flagdeform = flagwall = 0; for (int i = 0; i < modify->nfix; i++) { - if (strcmp(modify->fix[i]->style, "deform") == 0) - flagdeform = 1; + if (strcmp(modify->fix[i]->style, "deform") == 0) flagdeform = 1; + else if (strcmp(modify->fix[i]->style, "deform/kk") == 0) flagdeform = 1; // cleaner way to do this?? what about flagwall? else if (strstr(modify->fix[i]->style, "wall") != nullptr) { if (flagwall) error->all(FLERR, "Cannot use multiple fix wall commands with pair brownian"); flagwall = 1; // Walls exist diff --git a/src/COLLOID/pair_brownian.h b/src/COLLOID/pair_brownian.h index a6a08db699..0bb4e2188b 100644 --- a/src/COLLOID/pair_brownian.h +++ b/src/COLLOID/pair_brownian.h @@ -31,7 +31,7 @@ class PairBrownian : public Pair { void compute(int, int) override; void settings(int, char **) override; void coeff(int, char **) override; - double init_one(int, int) override; + virtual double init_one(int, int) override; void init_style() override; void write_restart(FILE *) override; void read_restart(FILE *) override; @@ -55,7 +55,7 @@ class PairBrownian : public Pair { class RanMars *random; void set_3_orthogonal_vectors(double *, double *, double *); - void allocate(); + virtual void allocate(); }; } // namespace LAMMPS_NS diff --git a/src/USER-SUMAN/pair_brownian.cpp b/src/USER-SUMAN/pair_brownian.cpp deleted file mode 100644 index 3b1ddfa99e..0000000000 --- a/src/USER-SUMAN/pair_brownian.cpp +++ /dev/null @@ -1,752 +0,0 @@ -/* ---------------------------------------------------------------------- - 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: Amit Kumar and Michael Bybee (UIUC) -------------------------------------------------------------------------- */ - -#include "pair_brownian.h" - -#include "atom.h" -#include "comm.h" -#include "domain.h" -#include "error.h" -#include "fix.h" -#include "fix_wall.h" -#include "force.h" -#include "input.h" -#include "math_const.h" -#include "math_special.h" -#include "memory.h" -#include "modify.h" -#include "neigh_list.h" -#include "neighbor.h" -#include "random_mars.h" -#include "update.h" -#include "variable.h" - -#include -#include - -using namespace LAMMPS_NS; -using namespace MathConst; -using namespace MathSpecial; - -// same as fix_wall.cpp - -enum { EDGE, CONSTANT, VARIABLE }; - -//#define _NO_RANDOM - -/* ---------------------------------------------------------------------- */ - -PairBrownian::PairBrownian(LAMMPS *lmp) : Pair(lmp) -{ - single_enable = 0; - random = nullptr; -} - -/* ---------------------------------------------------------------------- */ - -PairBrownian::~PairBrownian() -{ - if(copymode) return; - - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); - - memory->destroy(cut); - memory->destroy(cut_inner); - } - delete random; -} - -/* ---------------------------------------------------------------------- */ - -void PairBrownian::compute(int eflag, int vflag) -{ -#ifdef _NO_RANDOM - printf("Warning:: PairBrownian::compute() Random numbers all set to 0.5\n"); -#endif - - int i, j, ii, jj, inum, jnum, itype, jtype; - double xtmp, ytmp, ztmp, delx, dely, delz, fx, fy, fz, tx, ty, tz; - double rsq, r, h_sep, radi; - int *ilist, *jlist, *numneigh, **firstneigh; - - ev_init(eflag, vflag); - - double **x = atom->x; - double **f = atom->f; - double **torque = atom->torque; - double *radius = atom->radius; - int *type = atom->type; - int nlocal = atom->nlocal; - int newton_pair = force->newton_pair; - - double vxmu2f = force->vxmu2f; - double randr; - double prethermostat; - double xl[3], a_sq, a_sh, a_pu, Fbmag; - double p1[3], p2[3], p3[3]; - - // This section of code adjusts R0/RT0/RS0 if necessary due to changes - // in the volume fraction as a result of fix deform or moving walls - - double dims[3], wallcoord; - if (flagVF) // Flag for volume fraction corrections - if (flagdeform || flagwall == 2) { // Possible changes in volume fraction - if (flagdeform && !flagwall) - for (j = 0; j < 3; j++) dims[j] = domain->prd[j]; - else if (flagwall == 2 || (flagdeform && flagwall == 1)) { - double wallhi[3], walllo[3]; - for (int j = 0; j < 3; j++) { - wallhi[j] = domain->prd[j]; - walllo[j] = 0; - } - for (int m = 0; m < wallfix->nwall; m++) { - int dim = wallfix->wallwhich[m] / 2; - int side = wallfix->wallwhich[m] % 2; - if (wallfix->xstyle[m] == VARIABLE) { - wallcoord = input->variable->compute_equal(wallfix->xindex[m]); - } else - wallcoord = wallfix->coord0[m]; - if (side == 0) - walllo[dim] = wallcoord; - else - wallhi[dim] = wallcoord; - } - for (int j = 0; j < 3; j++) dims[j] = wallhi[j] - walllo[j]; - } - double vol_T = dims[0] * dims[1] * dims[2]; - double vol_f = vol_P / vol_T; - if (flaglog == 0) { - R0 = 6 * MY_PI * mu * rad * (1.0 + 2.16 * vol_f); - RT0 = 8 * MY_PI * mu * cube(rad); - //RS0 = 20.0/3.0*MY_PI*mu*pow(rad,3)*(1.0 + 3.33*vol_f + 2.80*vol_f*vol_f); - } else { - R0 = 6 * MY_PI * mu * rad * (1.0 + 2.725 * vol_f - 6.583 * vol_f * vol_f); - RT0 = 8 * MY_PI * mu * cube(rad) * (1.0 + 0.749 * vol_f - 2.469 * vol_f * vol_f); - //RS0 = 20.0/3.0*MY_PI*mu*pow(rad,3)*(1.0 + 3.64*vol_f - 6.95*vol_f*vol_f); - } - } - - // scale factor for Brownian moments - - prethermostat = sqrt(24.0 * force->boltz * t_target / update->dt); - prethermostat *= sqrt(force->vxmu2f / force->ftm2v / force->mvv2e); - - inum = list->inum; - ilist = list->ilist; - numneigh = list->numneigh; - firstneigh = list->firstneigh; - - for (ii = 0; ii < inum; ii++) { - i = ilist[ii]; - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - itype = type[i]; - radi = radius[i]; - jlist = firstneigh[i]; - jnum = numneigh[i]; - - // FLD contribution to force and torque due to isotropic terms - -#ifdef _NO_RANDOM - if (flagfld) { - f[i][0] += prethermostat * sqrt(R0) * 0.5; - f[i][1] += prethermostat * sqrt(R0) * 0.5; - f[i][2] += prethermostat * sqrt(R0) * 0.5; - if (flaglog) { - torque[i][0] += prethermostat * sqrt(RT0) * 0.5; - torque[i][1] += prethermostat * sqrt(RT0) * 0.5; - torque[i][2] += prethermostat * sqrt(RT0) * 0.5; - } - } -#else - if (flagfld) { - f[i][0] += prethermostat * sqrt(R0) * (random->uniform() - 0.5); - f[i][1] += prethermostat * sqrt(R0) * (random->uniform() - 0.5); - f[i][2] += prethermostat * sqrt(R0) * (random->uniform() - 0.5); - if (flaglog) { - torque[i][0] += prethermostat * sqrt(RT0) * (random->uniform() - 0.5); - torque[i][1] += prethermostat * sqrt(RT0) * (random->uniform() - 0.5); - torque[i][2] += prethermostat * sqrt(RT0) * (random->uniform() - 0.5); - } - } -#endif - - if (!flagHI) continue; - - for (jj = 0; jj < jnum; jj++) { - j = jlist[jj]; - j &= NEIGHMASK; - - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - rsq = delx * delx + dely * dely + delz * delz; - jtype = type[j]; - - if (rsq < cutsq[itype][jtype]) { - r = sqrt(rsq); - - // scalar resistances a_sq and a_sh - - h_sep = r - 2.0 * radi; - - // if less than minimum gap, use minimum gap instead - - if (r < cut_inner[itype][jtype]) h_sep = cut_inner[itype][jtype] - 2.0 * radi; - - // scale h_sep by radi - - h_sep = h_sep / radi; - - // scalar resistances - - if (flaglog) { - a_sq = 6.0 * MY_PI * mu * radi * (1.0 / 4.0 / h_sep + 9.0 / 40.0 * log(1.0 / h_sep)); - a_sh = 6.0 * MY_PI * mu * radi * (1.0 / 6.0 * log(1.0 / h_sep)); - a_pu = 8.0 * MY_PI * mu * cube(radi) * (3.0 / 160.0 * log(1.0 / h_sep)); - } else - a_sq = 6.0 * MY_PI * mu * radi * (1.0 / 4.0 / h_sep); - - // generate the Pairwise Brownian Force: a_sq - - Fbmag = prethermostat * sqrt(a_sq); - - // generate a random number - -#ifdef _NO_RANDOM - randr = 0.5; -#else - randr = random->uniform() - 0.5; -#endif - - // contribution due to Brownian motion - - fx = Fbmag * randr * delx / r; - fy = Fbmag * randr * dely / r; - fz = Fbmag * randr * delz / r; - - // add terms due to a_sh - - if (flaglog) { - - // generate two orthogonal vectors to the line of centers - - p1[0] = delx / r; - p1[1] = dely / r; - p1[2] = delz / r; - set_3_orthogonal_vectors(p1, p2, p3); - - // magnitude - - Fbmag = prethermostat * sqrt(a_sh); - - // force in each of the two directions - -#ifdef _NO_RANDOM - randr = 0.5; -#else - randr = random->uniform() - 0.5; -#endif - fx += Fbmag * randr * p2[0]; - fy += Fbmag * randr * p2[1]; - fz += Fbmag * randr * p2[2]; - -#ifndef _NO_RANDOM - randr = random->uniform() - 0.5; -#endif - fx += Fbmag * randr * p3[0]; - fy += Fbmag * randr * p3[1]; - fz += Fbmag * randr * p3[2]; - } - - // scale forces to appropriate units - - fx = vxmu2f * fx; - fy = vxmu2f * fy; - fz = vxmu2f * fz; - - // sum to total force - - f[i][0] -= fx; - f[i][1] -= fy; - f[i][2] -= fz; - - if (newton_pair || j < nlocal) { - //randr = random->uniform()-0.5; - //fx = Fbmag*randr*delx/r; - //fy = Fbmag*randr*dely/r; - //fz = Fbmag*randr*delz/r; - - f[j][0] += fx; - f[j][1] += fy; - f[j][2] += fz; - } - - // torque due to the Brownian Force - - if (flaglog) { - - // location of the point of closest approach on I from its center - - xl[0] = -delx / r * radi; - xl[1] = -dely / r * radi; - xl[2] = -delz / r * radi; - - // torque = xl_cross_F - - tx = xl[1] * fz - xl[2] * fy; - ty = xl[2] * fx - xl[0] * fz; - tz = xl[0] * fy - xl[1] * fx; - - // torque is same on both particles - - torque[i][0] -= tx; - torque[i][1] -= ty; - torque[i][2] -= tz; - - if (newton_pair || j < nlocal) { - torque[j][0] -= tx; - torque[j][1] -= ty; - torque[j][2] -= tz; - } - - // torque due to a_pu - - Fbmag = prethermostat * sqrt(a_pu); - - // force in each direction - -#ifdef _NO_RANDOM - randr = 0.5; -#else - randr = random->uniform() - 0.5; -#endif - tx = Fbmag * randr * p2[0]; - ty = Fbmag * randr * p2[1]; - tz = Fbmag * randr * p2[2]; - -#ifndef _NO_RANDOM - randr = random->uniform() - 0.5; -#endif - tx += Fbmag * randr * p3[0]; - ty += Fbmag * randr * p3[1]; - tz += Fbmag * randr * p3[2]; - - // torque has opposite sign on two particles - - torque[i][0] -= tx; - torque[i][1] -= ty; - torque[i][2] -= tz; - - if (newton_pair || j < nlocal) { - torque[j][0] += tx; - torque[j][1] += ty; - torque[j][2] += tz; - } - } - - if (evflag) - ev_tally_xyz(i, j, nlocal, newton_pair, 0.0, 0.0, -fx, -fy, -fz, delx, dely, delz); - } - } - } - - if (vflag_fdotr) virial_fdotr_compute(); -} - -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -void PairBrownian::allocate() -{ - allocated = 1; - int np1 = atom->ntypes + 1; - - memory->create(setflag, np1, np1, "pair:setflag"); - for (int i = 1; i < np1; i++) - for (int j = i; j < np1; j++) setflag[i][j] = 0; - - memory->create(cutsq, np1, np1, "pair:cutsq"); - - memory->create(cut, np1, np1, "pair:cut"); - memory->create(cut_inner, np1, np1, "pair:cut_inner"); -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairBrownian::settings(int narg, char **arg) -{ - if (narg != 7 && narg != 9) error->all(FLERR, "Illegal pair_style command"); - - mu = utils::numeric(FLERR, arg[0], false, lmp); - flaglog = utils::inumeric(FLERR, arg[1], false, lmp); - flagfld = utils::inumeric(FLERR, arg[2], false, lmp); - cut_inner_global = utils::numeric(FLERR, arg[3], false, lmp); - cut_global = utils::numeric(FLERR, arg[4], false, lmp); - t_target = utils::numeric(FLERR, arg[5], false, lmp); - seed = utils::inumeric(FLERR, arg[6], false, lmp); - - flagHI = flagVF = 1; - if (narg == 9) { - flagHI = utils::inumeric(FLERR, arg[7], false, lmp); - flagVF = utils::inumeric(FLERR, arg[8], false, lmp); - } - - if (flaglog == 1 && flagHI == 0) { - error->warning(FLERR, - "Cannot include log terms without 1/r terms; " - "setting flagHI to 1"); - flagHI = 1; - } - - // initialize Marsaglia RNG with processor-unique seed - - delete random; - random = new RanMars(lmp, seed + comm->me); - - // reset cutoffs that have been explicitly set - - if (allocated) { - for (int i = 1; i <= atom->ntypes; i++) - for (int j = i; j <= atom->ntypes; j++) - if (setflag[i][j]) { - cut_inner[i][j] = cut_inner_global; - cut[i][j] = cut_global; - } - } -} - -/* ---------------------------------------------------------------------- - set coeffs for one or more type pairs -------------------------------------------------------------------------- */ - -void PairBrownian::coeff(int narg, char **arg) -{ - if (narg != 2 && narg != 4) error->all(FLERR, "Incorrect args for pair coefficients"); - - if (!allocated) allocate(); - - int ilo, ihi, jlo, jhi; - utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error); - utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error); - - double cut_inner_one = cut_inner_global; - double cut_one = cut_global; - - if (narg == 4) { - cut_inner_one = utils::numeric(FLERR, arg[2], false, lmp); - cut_one = utils::numeric(FLERR, arg[3], false, lmp); - } - - int count = 0; - for (int i = ilo; i <= ihi; i++) - for (int j = MAX(jlo, i); j <= jhi; j++) { - cut_inner[i][j] = cut_inner_one; - cut[i][j] = cut_one; - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR, "Incorrect args for pair coefficients"); -} - -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairBrownian::init_style() -{ - if (!atom->radius_flag) error->all(FLERR, "Pair brownian requires atom attribute radius"); - - // if newton off, forces between atoms ij will be double computed - // using different random numbers - - if (force->newton_pair == 0 && comm->me == 0) - error->warning(FLERR, "Pair brownian needs newton pair on for momentum conservation"); - - neighbor->add_request(this); - - // ensure all particles are finite-size - // for pair hybrid, should limit test to types using the pair style - - double *radius = atom->radius; - int nlocal = atom->nlocal; - - for (int i = 0; i < nlocal; i++) - if (radius[i] == 0.0) error->one(FLERR, "Pair brownian requires extended particles"); - - // require monodisperse system with same radii for all types - - double radtype; - for (int i = 1; i <= atom->ntypes; i++) { - if (!atom->radius_consistency(i, radtype)) - error->all(FLERR, "Pair brownian requires monodisperse particles"); - if (i > 1 && radtype != rad) error->all(FLERR, "Pair brownian requires monodisperse particles"); - rad = radtype; - } - - // set the isotropic constants that depend on the volume fraction - // vol_T = total volume - // check for fix deform, if exists it must use "remap v" - // If box will change volume, set appropriate flag so that volume - // and v.f. corrections are re-calculated at every step. - // - // If available volume is different from box volume - // due to walls, set volume appropriately; if walls will - // move, set appropriate flag so that volume and v.f. corrections - // are re-calculated at every step. - - flagdeform = flagwall = 0; - for (int i = 0; i < modify->nfix; i++) { - if (strcmp(modify->fix[i]->style, "deform") == 0) flagdeform = 1; - else if (strcmp(modify->fix[i]->style, "deform/kk") == 0) flagdeform = 1; // cleaner way to do this?? what about flagwall? - else if (strstr(modify->fix[i]->style, "wall") != nullptr) { - if (flagwall) error->all(FLERR, "Cannot use multiple fix wall commands with pair brownian"); - flagwall = 1; // Walls exist - wallfix = dynamic_cast(modify->fix[i]); - if (wallfix->xflag) flagwall = 2; // Moving walls exist - } - } - - // set the isotropic constants depending on the volume fraction - // vol_T = total volumeshearing = flagdeform = flagwall = 0; - - double vol_T, wallcoord; - if (!flagwall) - vol_T = domain->xprd * domain->yprd * domain->zprd; - else { - double wallhi[3], walllo[3]; - for (int j = 0; j < 3; j++) { - wallhi[j] = domain->prd[j]; - walllo[j] = 0; - } - for (int m = 0; m < wallfix->nwall; m++) { - int dim = wallfix->wallwhich[m] / 2; - int side = wallfix->wallwhich[m] % 2; - if (wallfix->xstyle[m] == VARIABLE) { - wallfix->xindex[m] = input->variable->find(wallfix->xstr[m]); - // Since fix->wall->init happens after pair->init_style - wallcoord = input->variable->compute_equal(wallfix->xindex[m]); - } - - else - wallcoord = wallfix->coord0[m]; - - if (side == 0) - walllo[dim] = wallcoord; - else - wallhi[dim] = wallcoord; - } - vol_T = (wallhi[0] - walllo[0]) * (wallhi[1] - walllo[1]) * (wallhi[2] - walllo[2]); - } - - // vol_P = volume of particles, assuming mono-dispersity - // vol_f = volume fraction - - vol_P = atom->natoms * (4.0 / 3.0) * MY_PI * cube(rad); - - double vol_f = vol_P / vol_T; - - // set isotropic constants - if (!flagVF) vol_f = 0; - - if (flaglog == 0) { - R0 = 6 * MY_PI * mu * rad * (1.0 + 2.16 * vol_f); - RT0 = 8 * MY_PI * mu * cube(rad); // not actually needed - } else { - R0 = 6 * MY_PI * mu * rad * (1.0 + 2.725 * vol_f - 6.583 * vol_f * vol_f); - RT0 = 8 * MY_PI * mu * cube(rad) * (1.0 + 0.749 * vol_f - 2.469 * vol_f * vol_f); - } -} - -/* ---------------------------------------------------------------------- - init for one type pair i,j and corresponding j,i -------------------------------------------------------------------------- */ - -double PairBrownian::init_one(int i, int j) -{ - if (setflag[i][j] == 0) { - cut_inner[i][j] = mix_distance(cut_inner[i][i], cut_inner[j][j]); - cut[i][j] = mix_distance(cut[i][i], cut[j][j]); - } - - cut_inner[j][i] = cut_inner[i][j]; - - return cut[i][j]; -} - -/* ---------------------------------------------------------------------- - proc 0 writes to restart file -------------------------------------------------------------------------- */ - -void PairBrownian::write_restart(FILE *fp) -{ - write_restart_settings(fp); - - int i, j; - for (i = 1; i <= atom->ntypes; i++) - for (j = i; j <= atom->ntypes; j++) { - fwrite(&setflag[i][j], sizeof(int), 1, fp); - if (setflag[i][j]) { - fwrite(&cut_inner[i][j], sizeof(double), 1, fp); - fwrite(&cut[i][j], sizeof(double), 1, fp); - } - } -} - -/* ---------------------------------------------------------------------- - proc 0 reads from restart file, bcasts -------------------------------------------------------------------------- */ - -void PairBrownian::read_restart(FILE *fp) -{ - read_restart_settings(fp); - allocate(); - - int i, j; - int me = comm->me; - for (i = 1; i <= atom->ntypes; i++) - for (j = i; j <= atom->ntypes; j++) { - if (me == 0) utils::sfread(FLERR, &setflag[i][j], sizeof(int), 1, fp, nullptr, error); - MPI_Bcast(&setflag[i][j], 1, MPI_INT, 0, world); - if (setflag[i][j]) { - if (me == 0) { - utils::sfread(FLERR, &cut_inner[i][j], sizeof(double), 1, fp, nullptr, error); - utils::sfread(FLERR, &cut[i][j], sizeof(double), 1, fp, nullptr, error); - } - MPI_Bcast(&cut_inner[i][j], 1, MPI_DOUBLE, 0, world); - MPI_Bcast(&cut[i][j], 1, MPI_DOUBLE, 0, world); - } - } -} - -/* ---------------------------------------------------------------------- - proc 0 writes to restart file -------------------------------------------------------------------------- */ - -void PairBrownian::write_restart_settings(FILE *fp) -{ - fwrite(&mu, sizeof(double), 1, fp); - fwrite(&flaglog, sizeof(int), 1, fp); - fwrite(&flagfld, sizeof(int), 1, fp); - fwrite(&cut_inner_global, sizeof(double), 1, fp); - fwrite(&cut_global, sizeof(double), 1, fp); - fwrite(&t_target, sizeof(double), 1, fp); - fwrite(&seed, sizeof(int), 1, fp); - fwrite(&offset_flag, sizeof(int), 1, fp); - fwrite(&mix_flag, sizeof(int), 1, fp); - fwrite(&flagHI, sizeof(int), 1, fp); - fwrite(&flagVF, sizeof(int), 1, fp); -} - -/* ---------------------------------------------------------------------- - proc 0 reads from restart file, bcasts -------------------------------------------------------------------------- */ - -void PairBrownian::read_restart_settings(FILE *fp) -{ - int me = comm->me; - if (me == 0) { - utils::sfread(FLERR, &mu, sizeof(double), 1, fp, nullptr, error); - utils::sfread(FLERR, &flaglog, sizeof(int), 1, fp, nullptr, error); - utils::sfread(FLERR, &flagfld, sizeof(int), 1, fp, nullptr, error); - utils::sfread(FLERR, &cut_inner_global, sizeof(double), 1, fp, nullptr, error); - utils::sfread(FLERR, &cut_global, sizeof(double), 1, fp, nullptr, error); - utils::sfread(FLERR, &t_target, sizeof(double), 1, fp, nullptr, error); - utils::sfread(FLERR, &seed, sizeof(int), 1, fp, nullptr, error); - utils::sfread(FLERR, &offset_flag, sizeof(int), 1, fp, nullptr, error); - utils::sfread(FLERR, &mix_flag, sizeof(int), 1, fp, nullptr, error); - utils::sfread(FLERR, &flagHI, sizeof(int), 1, fp, nullptr, error); - utils::sfread(FLERR, &flagVF, sizeof(int), 1, fp, nullptr, error); - } - MPI_Bcast(&mu, 1, MPI_DOUBLE, 0, world); - MPI_Bcast(&flaglog, 1, MPI_INT, 0, world); - MPI_Bcast(&flagfld, 1, MPI_INT, 0, world); - MPI_Bcast(&cut_inner_global, 1, MPI_DOUBLE, 0, world); - MPI_Bcast(&cut_global, 1, MPI_DOUBLE, 0, world); - MPI_Bcast(&t_target, 1, MPI_DOUBLE, 0, world); - MPI_Bcast(&seed, 1, MPI_INT, 0, world); - MPI_Bcast(&offset_flag, 1, MPI_INT, 0, world); - MPI_Bcast(&mix_flag, 1, MPI_INT, 0, world); - MPI_Bcast(&flagHI, 1, MPI_INT, 0, world); - MPI_Bcast(&flagVF, 1, MPI_INT, 0, world); - - // additional setup based on restart parameters - - delete random; - random = new RanMars(lmp, seed + comm->me); -} - -/* ----------------------------------------------------------------------*/ - -void PairBrownian::set_3_orthogonal_vectors(double p1[3], double p2[3], double p3[3]) -{ - double norm; - int ix, iy, iz; - - // find the index of maximum magnitude and store it in iz - - if (fabs(p1[0]) > fabs(p1[1])) { - iz = 0; - ix = 1; - iy = 2; - } else { - iz = 1; - ix = 2; - iy = 0; - } - - if (iz == 0) { - if (fabs(p1[0]) < fabs(p1[2])) { - iz = 2; - ix = 0; - iy = 1; - } - } else { - if (fabs(p1[1]) < fabs(p1[2])) { - iz = 2; - ix = 0; - iy = 1; - } - } - - // set p2 arbitrarily such that it's orthogonal to p1 - - p2[ix] = 1.0; - p2[iy] = 1.0; - p2[iz] = -(p1[ix] * p2[ix] + p1[iy] * p2[iy]) / p1[iz]; - - // normalize p2 - - norm = sqrt(p2[0] * p2[0] + p2[1] * p2[1] + p2[2] * p2[2]); - - p2[0] = p2[0] / norm; - p2[1] = p2[1] / norm; - p2[2] = p2[2] / norm; - - // Set p3 by taking the cross product p3=p2xp1 - - p3[0] = p1[1] * p2[2] - p1[2] * p2[1]; - p3[1] = p1[2] * p2[0] - p1[0] * p2[2]; - p3[2] = p1[0] * p2[1] - p1[1] * p2[0]; -} diff --git a/src/USER-SUMAN/pair_brownian.h b/src/USER-SUMAN/pair_brownian.h deleted file mode 100644 index 0bb4e2188b..0000000000 --- a/src/USER-SUMAN/pair_brownian.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- 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(brownian,PairBrownian); -// clang-format on -#else - -#ifndef LMP_PAIR_BROWNIAN_H -#define LMP_PAIR_BROWNIAN_H - -#include "pair.h" - -namespace LAMMPS_NS { - -class PairBrownian : public Pair { - public: - PairBrownian(class LAMMPS *); - ~PairBrownian() override; - void compute(int, int) override; - void settings(int, char **) override; - void coeff(int, char **) override; - virtual double init_one(int, int) override; - void init_style() override; - void write_restart(FILE *) override; - void read_restart(FILE *) override; - void write_restart_settings(FILE *) override; - void read_restart_settings(FILE *) override; - - protected: - double cut_inner_global, cut_global; - double t_target, mu; - int flaglog, flagfld; - int flagHI, flagVF; - int flagdeform, flagwall; - double vol_P; - double rad; - class FixWall *wallfix; - - int seed; - double **cut_inner, **cut; - double R0, RT0; - - class RanMars *random; - - void set_3_orthogonal_vectors(double *, double *, double *); - virtual void allocate(); -}; - -} // namespace LAMMPS_NS - -#endif -#endif From b5f8d4b46c59d87a58f7e26228e2c8d27c3069cc Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 30 May 2024 14:34:15 -0500 Subject: [PATCH 16/43] fix memory leak for fix_dynamic(a.k.a. neigh/history) --- src/comm.cpp | 1 + src/comm.h | 1 + src/comm_brick.cpp | 12 ++++++++---- src/comm_tiled.cpp | 6 ++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/comm.cpp b/src/comm.cpp index 02999fd541..1b1546f893 100644 --- a/src/comm.cpp +++ b/src/comm.cpp @@ -75,6 +75,7 @@ Comm::Comm(LAMMPS *lmp) : Pointers(lmp) maxexchange = maxexchange_atom = maxexchange_fix = 0; maxexchange_fix_dynamic = 0; bufextra = BUFEXTRA; + bufextra_max = bufextra; grid2proc = nullptr; xsplit = ysplit = zsplit = nullptr; diff --git a/src/comm.h b/src/comm.h index fde4c3b81f..8515866dff 100644 --- a/src/comm.h +++ b/src/comm.h @@ -140,6 +140,7 @@ class Comm : protected Pointers { int maxexchange_fix; // static contribution to maxexchange from Fixes int maxexchange_fix_dynamic; // 1 if a fix has a dynamic contribution int bufextra; // augment send buf size for an exchange atom + int bufextra_max; int gridflag; // option for creating 3d grid int mapflag; // option for mapping procs to 3d grid diff --git a/src/comm_brick.cpp b/src/comm_brick.cpp index cf38271029..c75b183584 100644 --- a/src/comm_brick.cpp +++ b/src/comm_brick.cpp @@ -133,9 +133,11 @@ void CommBrick::init() { Comm::init(); - int bufextra_old = bufextra; init_exchange(); - if (bufextra > bufextra_old) grow_send(maxsend+bufextra,2); + if (bufextra > bufextra_max) { + grow_send(maxsend+bufextra,2); + bufextra_max = bufextra; + } // memory for multi style communication // allocate in setup @@ -672,9 +674,11 @@ void CommBrick::exchange() // only need to reset if a fix can dynamically add to size of single atom if (maxexchange_fix_dynamic) { - int bufextra_old = bufextra; init_exchange(); - if (bufextra > bufextra_old) grow_send(maxsend+bufextra,2); + if (bufextra > bufextra_max) { + grow_send(maxsend+bufextra,2); + bufextra_max = bufextra; + } } // subbox bounds for orthogonal or triclinic diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index b864e0523d..f4657c4790 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -943,9 +943,11 @@ void CommTiled::exchange() // only need to reset if a fix can dynamically add to size of single atom if (maxexchange_fix_dynamic) { - int bufextra_old = bufextra; init_exchange(); - if (bufextra > bufextra_old) grow_send(maxsend+bufextra,2); + if (bufextra > bufextra_max) { + grow_send(maxsend+bufextra,2); + bufextra = bufextra_max; + } } // domain properties used in exchange method and methods it calls From f9a95f72569d6273944d6891eb26a6ce31ce14a8 Mon Sep 17 00:00:00 2001 From: cjknight Date: Wed, 19 Jun 2024 16:55:18 -0500 Subject: [PATCH 17/43] fix virial accumulate for gran/hooke/history/kokkos --- src/KOKKOS/pair_gran_hooke_history_kokkos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp index dc8679c10d..6ed338f1f0 100644 --- a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp +++ b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp @@ -443,7 +443,7 @@ void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryC } if (VFLAG) - ev_tally_xyz(ev, i, j, fx_i, fy_i, fz_i, delx, dely, delz); + ev_tally_xyz(ev, i, j, fx, fy, fz, delx, dely, delz); } a_f(i,0) += fx_i; From 663aa8aa803478893c689b96f4489231da2c7ae6 Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 20 Jun 2024 22:33:11 -0500 Subject: [PATCH 18/43] fix missing pairs within same bin --- src/KOKKOS/npair_kokkos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KOKKOS/npair_kokkos.cpp b/src/KOKKOS/npair_kokkos.cpp index 44e9e355b9..927cd4b8a5 100644 --- a/src/KOKKOS/npair_kokkos.cpp +++ b/src/KOKKOS/npair_kokkos.cpp @@ -1438,7 +1438,7 @@ void NeighborKokkosExecute::build_ItemSizeGPU(typename Kokkos::TeamP for (int k = 0; k < nstencil; k++) { const int jbin = ibin + stencil[k]; - if (ibin == jbin) continue; + //if (ibin == jbin) continue; if (HalfNeigh && Newton && !Tri && (ibin == jbin)) continue; bincount_current = c_bincount[jbin]; From 75d3566a699ce7efe5f2d4fe3f4b11b6d090803e Mon Sep 17 00:00:00 2001 From: Chris Knight Date: Wed, 2 Oct 2024 15:35:33 +0000 Subject: [PATCH 19/43] move brownian to KOKKOS directory --- src/{USER-SUMAN => KOKKOS}/pair_brownian_kokkos.cpp | 0 src/{USER-SUMAN => KOKKOS}/pair_brownian_kokkos.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/{USER-SUMAN => KOKKOS}/pair_brownian_kokkos.cpp (100%) rename src/{USER-SUMAN => KOKKOS}/pair_brownian_kokkos.h (100%) diff --git a/src/USER-SUMAN/pair_brownian_kokkos.cpp b/src/KOKKOS/pair_brownian_kokkos.cpp similarity index 100% rename from src/USER-SUMAN/pair_brownian_kokkos.cpp rename to src/KOKKOS/pair_brownian_kokkos.cpp diff --git a/src/USER-SUMAN/pair_brownian_kokkos.h b/src/KOKKOS/pair_brownian_kokkos.h similarity index 100% rename from src/USER-SUMAN/pair_brownian_kokkos.h rename to src/KOKKOS/pair_brownian_kokkos.h From 299e0bafff6bc0640cec6e98ed3072d45286283c Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 3 Oct 2024 05:38:20 +0000 Subject: [PATCH 20/43] revert deform refactor to only sync when needed --- src/KOKKOS/fix_deform_kokkos.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/KOKKOS/fix_deform_kokkos.cpp b/src/KOKKOS/fix_deform_kokkos.cpp index af9c154876..0a0ce895e5 100644 --- a/src/KOKKOS/fix_deform_kokkos.cpp +++ b/src/KOKKOS/fix_deform_kokkos.cpp @@ -55,7 +55,7 @@ void FixDeformKokkos::pre_exchange() void FixDeformKokkos::end_of_step() { - atomKK->sync(Host,ALL_MASK); + if (remapflag == Domain::X_REMAP) atomKK->sync(Host,ALL_MASK); FixDeform::end_of_step(); - atomKK->modified(Host,ALL_MASK); + if (remapflag == Domain::X_REMAP) atomKK->modified(Host,ALL_MASK); } From 28d02cf2ab63813a34349d083ba71a01684b1b7c Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 3 Oct 2024 15:32:03 +0000 Subject: [PATCH 21/43] remove _NO_RANDOM debug from brownian styles --- src/COLLOID/pair_brownian.cpp | 44 ++++------------------------- src/KOKKOS/pair_brownian_kokkos.cpp | 39 +++---------------------- 2 files changed, 10 insertions(+), 73 deletions(-) diff --git a/src/COLLOID/pair_brownian.cpp b/src/COLLOID/pair_brownian.cpp index 87733911d6..e1ef7ceb87 100644 --- a/src/COLLOID/pair_brownian.cpp +++ b/src/COLLOID/pair_brownian.cpp @@ -42,8 +42,6 @@ using namespace LAMMPS_NS; using namespace MathConst; using namespace MathSpecial; -//#define _NO_RANDOM - /* ---------------------------------------------------------------------- */ PairBrownian::PairBrownian(LAMMPS *lmp) : Pair(lmp) @@ -72,10 +70,6 @@ PairBrownian::~PairBrownian() void PairBrownian::compute(int eflag, int vflag) { -#ifdef _NO_RANDOM - printf("Warning:: PairBrownian::compute() Random numbers all set to 0.5\n"); -#endif - int i, j, ii, jj, inum, jnum, itype, jtype; double xtmp, ytmp, ztmp, delx, dely, delz, fx, fy, fz, tx, ty, tz; double rsq, r, h_sep, radi; @@ -160,18 +154,6 @@ void PairBrownian::compute(int eflag, int vflag) // FLD contribution to force and torque due to isotropic terms -#ifdef _NO_RANDOM - if (flagfld) { - f[i][0] += prethermostat * sqrt(R0) * 0.5; - f[i][1] += prethermostat * sqrt(R0) * 0.5; - f[i][2] += prethermostat * sqrt(R0) * 0.5; - if (flaglog) { - torque[i][0] += prethermostat * sqrt(RT0) * 0.5; - torque[i][1] += prethermostat * sqrt(RT0) * 0.5; - torque[i][2] += prethermostat * sqrt(RT0) * 0.5; - } - } -#else if (flagfld) { f[i][0] += prethermostat * sqrt(R0) * (random->uniform() - 0.5); f[i][1] += prethermostat * sqrt(R0) * (random->uniform() - 0.5); @@ -182,7 +164,6 @@ void PairBrownian::compute(int eflag, int vflag) torque[i][2] += prethermostat * sqrt(RT0) * (random->uniform() - 0.5); } } -#endif if (!flagHI) continue; @@ -226,11 +207,7 @@ void PairBrownian::compute(int eflag, int vflag) // generate a random number -#ifdef _NO_RANDOM - randr = 0.5; -#else randr = random->uniform() - 0.5; -#endif // contribution due to Brownian motion @@ -255,19 +232,14 @@ void PairBrownian::compute(int eflag, int vflag) // force in each of the two directions -#ifdef _NO_RANDOM - randr = 0.5; -#else randr = random->uniform() - 0.5; -#endif fx += Fbmag * randr * p2[0]; fy += Fbmag * randr * p2[1]; fz += Fbmag * randr * p2[2]; -#ifndef _NO_RANDOM randr = random->uniform() - 0.5; -#endif - fx += Fbmag * randr * p3[0]; + + fx += Fbmag * randr * p3[0]; fy += Fbmag * randr * p3[1]; fz += Fbmag * randr * p3[2]; } @@ -329,19 +301,15 @@ void PairBrownian::compute(int eflag, int vflag) // force in each direction -#ifdef _NO_RANDOM - randr = 0.5; -#else randr = random->uniform() - 0.5; -#endif - tx = Fbmag * randr * p2[0]; + + tx = Fbmag * randr * p2[0]; ty = Fbmag * randr * p2[1]; tz = Fbmag * randr * p2[2]; -#ifndef _NO_RANDOM randr = random->uniform() - 0.5; -#endif - tx += Fbmag * randr * p3[0]; + + tx += Fbmag * randr * p3[0]; ty += Fbmag * randr * p3[1]; tz += Fbmag * randr * p3[2]; diff --git a/src/KOKKOS/pair_brownian_kokkos.cpp b/src/KOKKOS/pair_brownian_kokkos.cpp index 421fd9666d..a35c7e1fec 100644 --- a/src/KOKKOS/pair_brownian_kokkos.cpp +++ b/src/KOKKOS/pair_brownian_kokkos.cpp @@ -43,8 +43,6 @@ using namespace MathSpecialKokkos; enum { EDGE, CONSTANT, VARIABLE }; -//#define _NO_RANDOM - /* ---------------------------------------------------------------------- */ template @@ -108,10 +106,6 @@ void PairBrownianKokkos::init_style() template void PairBrownianKokkos::compute(int eflag_in, int vflag_in) { -#ifdef _NO_RANDOM - printf("Warning:: PairBrownian::compute() Random numbers all set to 0.5\n"); -#endif - eflag = eflag_in; vflag = vflag_in; @@ -301,18 +295,6 @@ void PairBrownianKokkos::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute Date: Thu, 3 Oct 2024 15:35:30 +0000 Subject: [PATCH 22/43] remove white space changes --- src/COLLOID/pair_brownian.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/COLLOID/pair_brownian.cpp b/src/COLLOID/pair_brownian.cpp index e1ef7ceb87..9eecffac21 100644 --- a/src/COLLOID/pair_brownian.cpp +++ b/src/COLLOID/pair_brownian.cpp @@ -93,7 +93,6 @@ void PairBrownian::compute(int eflag, int vflag) // This section of code adjusts R0/RT0/RS0 if necessary due to changes // in the volume fraction as a result of fix deform or moving walls - double dims[3], wallcoord; if (flagVF) // Flag for volume fraction corrections if (flagdeform || flagwall == 2) { // Possible changes in volume fraction @@ -136,12 +135,10 @@ void PairBrownian::compute(int eflag, int vflag) prethermostat = sqrt(24.0 * force->boltz * t_target / update->dt); prethermostat *= sqrt(force->vxmu2f / force->ftm2v / force->mvv2e); - inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; - for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; @@ -164,7 +161,6 @@ void PairBrownian::compute(int eflag, int vflag) torque[i][2] += prethermostat * sqrt(RT0) * (random->uniform() - 0.5); } } - if (!flagHI) continue; for (jj = 0; jj < jnum; jj++) { @@ -238,7 +234,6 @@ void PairBrownian::compute(int eflag, int vflag) fz += Fbmag * randr * p2[2]; randr = random->uniform() - 0.5; - fx += Fbmag * randr * p3[0]; fy += Fbmag * randr * p3[1]; fz += Fbmag * randr * p3[2]; @@ -249,7 +244,6 @@ void PairBrownian::compute(int eflag, int vflag) fx = vxmu2f * fx; fy = vxmu2f * fy; fz = vxmu2f * fz; - // sum to total force f[i][0] -= fx; @@ -302,13 +296,11 @@ void PairBrownian::compute(int eflag, int vflag) // force in each direction randr = random->uniform() - 0.5; - tx = Fbmag * randr * p2[0]; ty = Fbmag * randr * p2[1]; tz = Fbmag * randr * p2[2]; randr = random->uniform() - 0.5; - tx += Fbmag * randr * p3[0]; ty += Fbmag * randr * p3[1]; tz += Fbmag * randr * p3[2]; @@ -331,7 +323,7 @@ void PairBrownian::compute(int eflag, int vflag) } } } - + if (vflag_fdotr) virial_fdotr_compute(); } From 8ef30fe05b3d2e10ccc8f8c3782cc63a2d4634fb Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 3 Oct 2024 15:39:09 +0000 Subject: [PATCH 23/43] remove white space changes --- src/COLLOID/pair_brownian.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/COLLOID/pair_brownian.cpp b/src/COLLOID/pair_brownian.cpp index 9eecffac21..8c5db10a8b 100644 --- a/src/COLLOID/pair_brownian.cpp +++ b/src/COLLOID/pair_brownian.cpp @@ -93,6 +93,7 @@ void PairBrownian::compute(int eflag, int vflag) // This section of code adjusts R0/RT0/RS0 if necessary due to changes // in the volume fraction as a result of fix deform or moving walls + double dims[3], wallcoord; if (flagVF) // Flag for volume fraction corrections if (flagdeform || flagwall == 2) { // Possible changes in volume fraction @@ -135,10 +136,12 @@ void PairBrownian::compute(int eflag, int vflag) prethermostat = sqrt(24.0 * force->boltz * t_target / update->dt); prethermostat *= sqrt(force->vxmu2f / force->ftm2v / force->mvv2e); + inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; firstneigh = list->firstneigh; + for (ii = 0; ii < inum; ii++) { i = ilist[ii]; xtmp = x[i][0]; @@ -161,6 +164,7 @@ void PairBrownian::compute(int eflag, int vflag) torque[i][2] += prethermostat * sqrt(RT0) * (random->uniform() - 0.5); } } + if (!flagHI) continue; for (jj = 0; jj < jnum; jj++) { @@ -296,12 +300,12 @@ void PairBrownian::compute(int eflag, int vflag) // force in each direction randr = random->uniform() - 0.5; - tx = Fbmag * randr * p2[0]; + tx = Fbmag * randr * p2[0]; ty = Fbmag * randr * p2[1]; tz = Fbmag * randr * p2[2]; randr = random->uniform() - 0.5; - tx += Fbmag * randr * p3[0]; + tx += Fbmag * randr * p3[0]; ty += Fbmag * randr * p3[1]; tz += Fbmag * randr * p3[2]; @@ -318,12 +322,12 @@ void PairBrownian::compute(int eflag, int vflag) } } - if (evflag) - ev_tally_xyz(i, j, nlocal, newton_pair, 0.0, 0.0, -fx, -fy, -fz, delx, dely, delz); + if (evflag) + ev_tally_xyz(i, j, nlocal, newton_pair, 0.0, 0.0, -fx, -fy, -fz, delx, dely, delz); } } } - + if (vflag_fdotr) virial_fdotr_compute(); } @@ -431,7 +435,7 @@ void PairBrownian::coeff(int narg, char **arg) ------------------------------------------------------------------------- */ void PairBrownian::init_style() -{ +{ if (!atom->radius_flag) error->all(FLERR, "Pair brownian requires atom attribute radius"); // if newton off, forces between atoms ij will be double computed From 47e8093e07f73a698febea474a421a86900fd3bd Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 3 Oct 2024 15:41:10 +0000 Subject: [PATCH 24/43] remove white space changes --- src/COLLOID/pair_brownian.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/COLLOID/pair_brownian.cpp b/src/COLLOID/pair_brownian.cpp index 8c5db10a8b..b0a12fdbae 100644 --- a/src/COLLOID/pair_brownian.cpp +++ b/src/COLLOID/pair_brownian.cpp @@ -238,7 +238,7 @@ void PairBrownian::compute(int eflag, int vflag) fz += Fbmag * randr * p2[2]; randr = random->uniform() - 0.5; - fx += Fbmag * randr * p3[0]; + fx += Fbmag * randr * p3[0]; fy += Fbmag * randr * p3[1]; fz += Fbmag * randr * p3[2]; } @@ -248,7 +248,8 @@ void PairBrownian::compute(int eflag, int vflag) fx = vxmu2f * fx; fy = vxmu2f * fy; fz = vxmu2f * fz; - // sum to total force + + // sum to total force f[i][0] -= fx; f[i][1] -= fy; From b7d529d945cbae75bab7e8d1df49c3535720ebfd Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 3 Oct 2024 15:41:43 +0000 Subject: [PATCH 25/43] remove white space changes --- src/COLLOID/pair_brownian.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/COLLOID/pair_brownian.cpp b/src/COLLOID/pair_brownian.cpp index b0a12fdbae..885a7f6b97 100644 --- a/src/COLLOID/pair_brownian.cpp +++ b/src/COLLOID/pair_brownian.cpp @@ -249,7 +249,7 @@ void PairBrownian::compute(int eflag, int vflag) fy = vxmu2f * fy; fz = vxmu2f * fz; - // sum to total force + // sum to total force f[i][0] -= fx; f[i][1] -= fy; From 5fe5fc0b10e8bbf3c4b22fc4e51cd465679514b2 Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 3 Oct 2024 15:43:26 +0000 Subject: [PATCH 26/43] remove old logic --- src/KOKKOS/npair_kokkos.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/KOKKOS/npair_kokkos.cpp b/src/KOKKOS/npair_kokkos.cpp index 927cd4b8a5..4fec623c5d 100644 --- a/src/KOKKOS/npair_kokkos.cpp +++ b/src/KOKKOS/npair_kokkos.cpp @@ -1438,7 +1438,6 @@ void NeighborKokkosExecute::build_ItemSizeGPU(typename Kokkos::TeamP for (int k = 0; k < nstencil; k++) { const int jbin = ibin + stencil[k]; - //if (ibin == jbin) continue; if (HalfNeigh && Newton && !Tri && (ibin == jbin)) continue; bincount_current = c_bincount[jbin]; From 0edf9d42b00ab59ad7b44cc42e87b6b3513f333a Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 3 Oct 2024 15:46:44 +0000 Subject: [PATCH 27/43] remove white space changes --- src/KOKKOS/pair_gran_hooke_history_kokkos.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp index 6ed338f1f0..5c84032bb9 100644 --- a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp +++ b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp @@ -163,12 +163,12 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) d_firstshear = fix_historyKK->k_firstvalue.template view(); Kokkos::deep_copy(d_firsttouch,0); - + EV_FLOAT ev; if (neighflag == HALF) { if (force->newton_pair) { - if (vflag_either) { // VFLAG == 1 + if (vflag_either) { if (shearupdate) { Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); } else { @@ -198,7 +198,7 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) } } else { // HALFTHREAD if (force->newton_pair) { - if (vflag_either) { // VFLAG == 0 + if (vflag_either) { if (shearupdate) { Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); } else { @@ -227,7 +227,7 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) } } } - + if (eflag_atom) { k_eatom.template modify(); k_eatom.template sync(); @@ -241,7 +241,7 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) virial[4] += ev.v[4]; virial[5] += ev.v[5]; } - + if (vflag_atom) { k_vatom.template modify(); k_vatom.template sync(); @@ -300,7 +300,7 @@ void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryC const LMP_FLOAT jmass = rmass[j]; const LMP_FLOAT jrad = radius[j]; const LMP_FLOAT radsum = irad + jrad; - + // check for touching neighbors if (rsq >= radsum * radsum) { @@ -422,7 +422,7 @@ void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryC fx_i += fx; fy_i += fy; fz_i += fz; - + F_FLOAT tor1 = rinv * (dely*fs3 - delz*fs2); F_FLOAT tor2 = rinv * (delz*fs1 - delx*fs3); F_FLOAT tor3 = rinv * (delx*fs2 - dely*fs1); From a0f09a42bfd08e862bb5c528334113a2b3608b27 Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 3 Oct 2024 15:48:12 +0000 Subject: [PATCH 28/43] remove lubricate/Simple ; not ready for primetime --- src/KOKKOS/pair_gran_hooke_history_kokkos.cpp | 4 +- src/USER-SUMAN/pair_lubricate_Simple.cpp | 422 ---------- src/USER-SUMAN/pair_lubricate_Simple.h | 71 -- .../pair_lubricate_Simple_kokkos.cpp | 749 ------------------ src/USER-SUMAN/pair_lubricate_Simple_kokkos.h | 130 --- 5 files changed, 2 insertions(+), 1374 deletions(-) delete mode 100644 src/USER-SUMAN/pair_lubricate_Simple.cpp delete mode 100644 src/USER-SUMAN/pair_lubricate_Simple.h delete mode 100644 src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp delete mode 100644 src/USER-SUMAN/pair_lubricate_Simple_kokkos.h diff --git a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp index 5c84032bb9..50fcd7c054 100644 --- a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp +++ b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp @@ -163,7 +163,7 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) d_firstshear = fix_historyKK->k_firstvalue.template view(); Kokkos::deep_copy(d_firsttouch,0); - + EV_FLOAT ev; if (neighflag == HALF) { @@ -422,7 +422,7 @@ void PairGranHookeHistoryKokkos::operator()(TagPairGranHookeHistoryC fx_i += fx; fy_i += fy; fz_i += fz; - + F_FLOAT tor1 = rinv * (dely*fs3 - delz*fs2); F_FLOAT tor2 = rinv * (delz*fs1 - delx*fs3); F_FLOAT tor3 = rinv * (delx*fs2 - dely*fs1); diff --git a/src/USER-SUMAN/pair_lubricate_Simple.cpp b/src/USER-SUMAN/pair_lubricate_Simple.cpp deleted file mode 100644 index 49cc2d6024..0000000000 --- a/src/USER-SUMAN/pair_lubricate_Simple.cpp +++ /dev/null @@ -1,422 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator -http://lammps.sandia.gov, 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 authors: Randy Schunk (SNL) - Amit Kumar and Michael Bybee (UIUC) - Dave Heine (Corning), polydispersity - ------------------------------------------------------------------------- */ -/* Modified by Ranga on 27/05/2017 from the GRM formulation - given by Kim and Karilla, Microhydrodynamics */ - -#include -#include -#include -#include -#include "pair_lubricate_Simple.h" -#include "atom.h" -#include "atom_vec.h" -#include "comm.h" -#include "force.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "domain.h" -#include "modify.h" -#include "fix.h" -#include "fix_deform.h" -#include "memory.h" -#include "random_mars.h" -#include "fix_wall.h" -#include "input.h" -#include "variable.h" -#include "math_const.h" -#include "error.h" - -using namespace LAMMPS_NS; -using namespace MathConst; - -// same as fix_deform.cpp - -enum{NO_REMAP,X_REMAP,V_REMAP}; - - -// same as fix_wall.cpp - -enum{EDGE,CONSTANT,VARIABLE}; - -/* ---------------------------------------------------------------------- */ - -PairLubricateSimple::PairLubricateSimple(LAMMPS *lmp) : PairLubricate(lmp) -{ - no_virial_fdotr_compute = 1; -} - -/* ---------------------------------------------------------------------- */ - -PairLubricateSimple::~PairLubricateSimple() -{ - if (copymode) return; -} - -/* ---------------------------------------------------------------------- */ - -void PairLubricateSimple::compute(int eflag, int vflag) -{ - int i,j,ii,jj,inum,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz; - double rsq,r,h_sep,beta0,beta1,radi,radj; - double vr1,vr2,vr3,vnnr,vn1,vn2,vn3; - double vt1,vt2,vt3; - int *ilist,*jlist,*numneigh,**firstneigh; - double lamda[3],vstream[3]; - - double vxmu2f = force->vxmu2f; - - if (eflag || vflag) ev_setup(eflag,vflag); - else evflag = vflag_fdotr = 0; - - double **x = atom->x; - double **v = atom->v; - double **f = atom->f; - double **omega = atom->omega; - double **torque = atom->torque; - double *radius = atom->radius; - 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; - - for (ii = 0; ii < inum; ii++) { - i = ilist[ii]; - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - itype = type[i]; - jlist = firstneigh[i]; - jnum = numneigh[i]; - radi = radius[i]; - - // Drag contribution to force and torque due to isotropic terms - // Drag contribution to stress from isotropic RS0 - - if (flagfld) { - - domain->x2lamda(x[i],lamda); - double *h_rate = domain->h_rate; - double *h_ratelo = domain->h_ratelo; - vstream[0] = h_rate[0]*lamda[0] + h_rate[5]*lamda[1] + - h_rate[4]*lamda[2] + h_ratelo[0]; - vstream[1] = h_rate[1]*lamda[1] + h_rate[3]*lamda[2] + h_ratelo[1]; - vstream[2] = h_rate[2]*lamda[2] + h_ratelo[2]; - - - R0 = 6.0*MY_PI*mu; - RT0 = 8.0*MY_PI*mu; - RS0 = 20.0/3.0*MY_PI*mu; - - f[i][0] += vxmu2f*R0*radi*(vstream[0]-v[i][0]); - f[i][1] += vxmu2f*R0*radi*(vstream[1]-v[i][1]); - f[i][2] += vxmu2f*R0*radi*(vstream[2]-v[i][2]); - - const double radi3 = radi*radi*radi; - - torque[i][0] -= vxmu2f*RT0*radi3*(omega[i][0]+0.5*h_rate[3]/domain->zprd); - torque[i][1] -= vxmu2f*RT0*radi3*(omega[i][1]-0.5*h_rate[4]/domain->zprd); - torque[i][2] -= vxmu2f*RT0*radi3*(omega[i][2]+0.5*h_rate[5]/domain->yprd); - - // Ef = (grad(vstream) + (grad(vstream))^T) / 2 - // set Ef from h_rate in strain units - if(shearing){ - Ef[0][0] = h_rate[0]/domain->xprd; - Ef[1][1] = h_rate[1]/domain->yprd; - Ef[2][2] = h_rate[2]/domain->zprd; - Ef[0][1] = Ef[1][0] = 0.5 * h_rate[5]/domain->yprd; - Ef[0][2] = Ef[2][0] = 0.5 * h_rate[4]/domain->zprd; - Ef[1][2] = Ef[2][1] = 0.5 * h_rate[3]/domain->zprd; - - if (vflag_either) { - double vRS0 = -vxmu2f* RS0*radi3; - v_tally_tensor(i,i,nlocal,newton_pair, - vRS0*Ef[0][0],vRS0*Ef[1][1],vRS0*Ef[2][2], - vRS0*Ef[0][1],vRS0*Ef[0][2],vRS0*Ef[1][2]); - } - } - - } - - if (!flagHI)continue; - - for (jj = 0; jj < jnum; jj++) { - j = jlist[jj]; - j &= NEIGHMASK; - - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - rsq = delx*delx + dely*dely + delz*delz; - jtype = type[j]; - radj = atom->radius[j]; - double radsum = radi+radj; //Sum of two particle's radii - - if (rsq < cutsq[itype][jtype] and rsq < (1.45*1.45*radsum*radsum) ) { - r = sqrt(rsq); - - // scalar resistances XA and YA - - h_sep = r - radsum; - - // if less than the minimum gap use the minimum gap instead - - if (r < cut_inner[itype][jtype]*radsum) //Scaled inner cutoff by particle radii - h_sep = cut_inner[itype][jtype]*radsum - radsum; - - double hinv,lhinv,XA11=0.0,YA11=0.0,YB11=0.0,YC12=0.0,ws[3],wd[3],nx,ny,nz; - ws[0] = (omega[i][0]+omega[j][0])/2.0; - ws[1] = (omega[i][1]+omega[j][1])/2.0; - ws[2] = (omega[i][2]+omega[j][2])/2.0; - - wd[0] = (omega[i][0]-omega[j][0])/2.0; - wd[1] = (omega[i][1]-omega[j][1])/2.0; - wd[2] = (omega[i][2]-omega[j][2])/2.0; - - nx=-delx/r;ny=-dely/r;nz=-delz/r; - - - hinv=(radi+radj)/(2.0*h_sep); - lhinv=log(hinv); - - if(lhinv < 0) error->all(FLERR,"Using pair lubricate with cutoff problem: log(1/h) is negative"); - - beta0=radj/radi; - beta1=1.0+beta0; - - double b0p2,b1p2,b1p3,mupradi; - b0p2=beta0*beta0; - b1p2=beta1*beta1; - b1p3=beta1*b1p2; - mupradi=mu*MY_PI*radi; - - // scalar resistances - if (flaglog) { - XA11=6.0*mupradi*( hinv*2.0*b0p2 + lhinv*beta0*(1.0+ 7.0*beta0+ b0p2 )/5.0 )/b1p3; - YA11=1.6*mupradi*lhinv*beta0*(2.0+beta0+2.0*b0p2)/b1p3; - YB11=-0.8*mupradi*radi*lhinv*beta0*(4.0+beta0)/b1p2; - YC12=0.8*mupradi*radi*radi*lhinv*b0p2/beta1*(1.0-4.0/beta0); //YC12*(1-4/beta0) - } - else XA11=12.0*mupradi*hinv*b0p2/b1p3; - - - - /* - if (flaglog) { - XA11=6.0*MY_PI*mu*radi*( hinv*2.0*pow(beta0,2.0) + lhinv*beta0*(1.0+ 7.0*beta0+ beta0*beta0)/5.0 )/pow(beta1,3.0); - YA11=1.6*MY_PI*mu*radi*lhinv*beta0*(2.0+beta0+2.0*beta0*beta0)/pow(beta1,3.0); - YB11=-0.8*MY_PI*mu*radi*radi*lhinv*beta0*(4.0+beta0)/(beta1*beta1); - YC12=0.8*MY_PI*mu*pow(radi,3.0)*lhinv*beta0*beta0/beta1*(1.0-4.0/beta0); //YC12*(1-4/beta0) - } - else XA11=12*MY_PI*mu*radi*hinv*pow(beta0,2.0)/pow(beta1,3.0); - */ - // Relative velocity components U^2-U^1 - vr1 = v[j][0] - v[i][0]; - vr2 = v[j][1] - v[i][1]; - vr3 = v[j][2] - v[i][2]; - - // normal component (vr.n)n - - vnnr = vr1*nx + vr2*ny + vr3*nz; - vn1 = vnnr*nx; - vn2 = vnnr*ny; - vn3 = vnnr*nz; - - // tangential component vr - (vr.n)n - - vt1 = vr1 - vn1; - vt2 = vr2 - vn2; - vt3 = vr3 - vn3; - - // force due to squeeze type motion - //f=XA11 nn dot vr - fx = XA11*vn1; - fy = XA11*vn2; - fz = XA11*vn3; - - - // force due to all shear kind of motions - - if (flaglog) { - double ybfac=(1.0-beta0*(1.0+4.0*beta0)/(4.0+beta0))*YB11; - //f+=YA11*vt1-(r1+r2)*YA11*ws cross n + ybfac* wd cross n - fx = fx + YA11*(vt1-(radi+radj)*(ws[1]*nz-ws[2]*ny))+ybfac*(wd[1]*nz-wd[2]*ny); - fy = fy + YA11*(vt2-(radi+radj)*(ws[2]*nx-ws[0]*nz))+ybfac*(wd[2]*nx-wd[0]*nz); - fz = fz + YA11*(vt3-(radi+radj)*(ws[0]*ny-ws[1]*nx))+ybfac*(wd[0]*ny-wd[1]*nx); - } - - // scale forces for appropriate units - - fx *= vxmu2f; - fy *= vxmu2f; - fz *= vxmu2f; - - // add to total force - - f[i][0] += fx; - f[i][1] += fy; - f[i][2] += fz; - - if(newton_pair || j < nlocal) { - f[j][0] -= fx; - f[j][1] -= fy; - f[j][2] -= fz; - } - - // torque due to this force - - if (flaglog) { - double wsdotn,wddotn; - wsdotn=ws[0]*nx+ws[1]*ny+ws[2]*nz; - wddotn=wd[0]*nx+wd[1]*ny+wd[2]*nz; - - //squeeze+shear+pump contributions to torque - //YB11*(vr cross n + (r1+r2)* tang(ws)) +YC12*(1-4/beta)*tang(wd) - double tx = YB11*(vr2*nz -vr3*ny + (radi+radj)*(ws[0]-wsdotn*nx)); - double ty = YB11*(vr3*nx -vr1*nz + (radi+radj)*(ws[1]-wsdotn*ny)); - double tz = YB11*(vr1*ny -vr2*nx + (radi+radj)*(ws[2]-wsdotn*nz)); - - double ttx = YC12*(wd[0]-wddotn*nx); - double tty = YC12*(wd[1]-wddotn*ny); - double ttz = YC12*(wd[2]-wddotn*nz); - - torque[i][0] += vxmu2f * (tx + ttx); - torque[i][1] += vxmu2f * (ty + tty); - torque[i][2] += vxmu2f * (tz + ttz); - - if(newton_pair || j < nlocal) { - torque[j][0] += vxmu2f * (tx - ttx); - torque[j][1] += vxmu2f * (ty - tty); - torque[j][2] += vxmu2f * (tz - ttz); - } - } - - // set j = nlocal so that only I gets tallied - - if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair,0.0,0.0,fx,fy,fz,delx,dely,delz); - // - //Add up stresslet for particle i - //v_tally_tensor(i,nlocal,nlocal,newton_pair,fx*delx,fy*dely,fz*delz, - //0.5*(fx*dely+fy*delx),0.5*(fx*delz+fz*delx),0.5*(fy*delz+fz*dely)); - - } - } - - } - -} - -/* ---------------------------------------------------------------------- - init specific to this pair style - ------------------------------------------------------------------------- */ - -void PairLubricateSimple::init_style() -{ - if (force->newton_pair == 1) - error->all(FLERR,"Pair lubricate/poly requires newton pair off"); - if (comm->ghost_velocity == 0) - error->all(FLERR, - "Pair lubricate/poly requires ghost atoms store velocity"); - if (!atom->radius_flag) - error->all(FLERR,"Pair lubricate/poly requires atom attribute radius"); - - // ensure all particles are finite-size - // for pair hybrid, should limit test to types using the pair style - - double *radius = atom->radius; - int nlocal = atom->nlocal; - - for (int i = 0; i < nlocal; i++) - if (radius[i] == 0.0) - error->one(FLERR,"Pair lubricate/poly requires extended particles"); - - // CHRIS:: IMPORTANT :: support for half list was added - //neighbor->add_request(this, NeighConst::REQ_FULL); - neighbor->add_request(this); - - // set the isotropic constants that depend on the volume fraction - // vol_T = total volume - - // check for fix deform, if exists it must use "remap v" - // If box will change volume, set appropriate flag so that volume - // and v.f. corrections are re-calculated at every step. - - // Ranga: Volume fraction correction unnecessary for our purposes - // if available volume is different from box volume - // due to walls, set volume appropriately; if walls will - // move, set appropriate flag so that volume and v.f. corrections - // are re-calculated at every step. - - shearing = flagdeform = flagwall = 0; - for (int i = 0; i < modify->nfix; i++){ - if (strcmp(modify->fix[i]->style,"deform") == 0 || strcmp(modify->fix[i]->style,"deform/kk") == 0) { - shearing = flagdeform = 1; - if (((FixDeform *) modify->fix[i])->remapflag != V_REMAP) - error->all(FLERR,"Using pair lubricate with inconsistent " - "fix deform remap option"); - } - if (strstr(modify->fix[i]->style,"wall") != NULL) { - if (flagwall) - error->all(FLERR, - "Cannot use multiple fix wall commands with " - "pair lubricate/poly"); - flagwall = 1; // Walls exist - wallfix = (FixWall *) modify->fix[i]; - if (wallfix->xflag) flagwall = 2; // Moving walls exist - } - - if (strstr(modify->fix[i]->style,"wall") != NULL){ - flagwall = 1; // Walls exist - if (((FixWall *) modify->fix[i])->xflag ) { - flagwall = 2; // Moving walls exist - wallfix = (FixWall *) modify->fix[i]; - } - } - } - - // check for fix deform, if exists it must use "remap v" - - shearing = 0; // then why set it above?? - for (int i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"deform") == 0 || strcmp(modify->fix[i]->style,"deform/kk") == 0) { - shearing = 1; - if (((FixDeform *) modify->fix[i])->remapflag != V_REMAP) - error->all(FLERR,"Using pair lubricate/poly with inconsistent " - "fix deform remap option"); - } - - // set Ef = 0 since used whether shearing or not - - Ef[0][0] = Ef[0][1] = Ef[0][2] = 0.0; - Ef[1][0] = Ef[1][1] = Ef[1][2] = 0.0; - Ef[2][0] = Ef[2][1] = Ef[2][2] = 0.0; -} - -/* ---------------------------------------------------------------------- - allocate all arrays; overiding here so Kokkos can overide - ------------------------------------------------------------------------- */ - -void PairLubricateSimple::allocate() -{ - PairLubricate::allocate(); -} diff --git a/src/USER-SUMAN/pair_lubricate_Simple.h b/src/USER-SUMAN/pair_lubricate_Simple.h deleted file mode 100644 index 46f7019b92..0000000000 --- a/src/USER-SUMAN/pair_lubricate_Simple.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- c++ -*- ---------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, 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 - -PairStyle(lubricate/Simple,PairLubricateSimple) - -#else - -#ifndef LMP_PAIR_LUBRICATE_SIMPLE_H -#define LMP_PAIR_LUBRICATE_SIMPLE_H - -#include "pair_lubricate.h" - -namespace LAMMPS_NS { - -class PairLubricateSimple : public PairLubricate { - public: - PairLubricateSimple(class LAMMPS *); - ~PairLubricateSimple() override; - void compute(int, int); - void init_style(); - void allocate() override; -}; - -} - -#endif -#endif - -/* ERROR/WARNING messages: - -E: Pair lubricate/poly requires newton pair off - -Self-explanatory. - -E: Pair lubricate/poly requires ghost atoms store velocity - -Use the comm_modify vel yes command to enable this. - -E: Pair lubricate/poly requires atom style sphere - -Self-explanatory. - -E: Pair lubricate/poly requires extended particles - -One of the particles has radius 0.0. - -E: Using pair lubricate with inconsistent fix deform remap option - -Must use remap v option with fix deform with this pair style. - -E: Cannot use multiple fix wall commands with pair lubricate/poly - -Self-explanatory. - -E: Using pair lubricate/poly with inconsistent fix deform remap option - -If fix deform is used, the remap v option is required. - -*/ diff --git a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp b/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp deleted file mode 100644 index a8f71d639c..0000000000 --- a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.cpp +++ /dev/null @@ -1,749 +0,0 @@ -// 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 "pair_lubricate_Simple_kokkos.h" - -#include "atom_kokkos.h" -#include "atom_masks.h" -#include "domain_kokkos.h" -#include "error.h" -#include "fix.h" -#include "fix_wall.h" -#include "force.h" -#include "input.h" -#include "kokkos.h" -#include "math_const.h" -#include "math_special_kokkos.h" -#include "memory_kokkos.h" -#include "neigh_list.h" -#include "neigh_request.h" -#include "neighbor.h" -#include "respa.h" -#include "update.h" -#include "variable.h" - -#include - -using namespace LAMMPS_NS; -using namespace MathConst; -using namespace MathSpecialKokkos; - -// same as fix_wall.cpp - -enum { EDGE, CONSTANT, VARIABLE }; - -//#define _NO_RANDOM - -/* ---------------------------------------------------------------------- */ - -template -PairLubricateSimpleKokkos::PairLubricateSimpleKokkos(LAMMPS *lmp) : PairLubricateSimple(lmp) -{ - respa_enable = 0; - - kokkosable = 1; - atomKK = (AtomKokkos *) atom; - domainKK = (DomainKokkos *) domain; - execution_space = ExecutionSpaceFromDevice::space; - datamask_read = X_MASK | V_MASK | F_MASK | OMEGA_MASK | TORQUE_MASK | TYPE_MASK | VIRIAL_MASK | RADIUS_MASK; - datamask_modify = F_MASK | TORQUE_MASK | VIRIAL_MASK; -} - -/* ---------------------------------------------------------------------- */ - -template -PairLubricateSimpleKokkos::~PairLubricateSimpleKokkos() -{ - if (copymode) return; - - if (allocated) { - memoryKK->destroy_kokkos(k_vatom,vatom); - memoryKK->destroy_kokkos(k_cut_inner,cut_inner); - memoryKK->destroy_kokkos(k_cutsq,cutsq); - } -} - -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -template -void PairLubricateSimpleKokkos::init_style() -{ - PairLubricateSimple::init_style(); - - // error if rRESPA with inner levels - - if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { - int respa = 0; - if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; - if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; - if (respa) - error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); - } - - // adjust neighbor list request for KOKKOS - - neighflag = lmp->kokkos->neighflag; - auto request = neighbor->find_request(this); - request->set_kokkos_host(std::is_same_v && - !std::is_same_v); - request->set_kokkos_device(std::is_same_v); -} - -/* ---------------------------------------------------------------------- */ - -template -void PairLubricateSimpleKokkos::compute(int eflag_in, int vflag_in) -{ - eflag = eflag_in; - vflag = vflag_in; - - if (neighflag == FULL) no_virial_fdotr_compute = 1; - - ev_init(eflag,vflag,0); - - // reallocate per-atom arrays if necessary - - if (vflag_atom) { - memoryKK->destroy_kokkos(k_vatom,vatom); - memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); - d_vatom = k_vatom.view(); - } - - atomKK->sync(execution_space,datamask_read); - k_cutsq.template sync(); - k_cut_inner.template sync(); - if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); - else atomKK->modified(execution_space,F_MASK | TORQUE_MASK); - - x = atomKK->k_x.view(); - c_x = atomKK->k_x.view(); - v = atomKK->k_v.view(); - f = atomKK->k_f.view(); - omega = atomKK->k_omega.view(); - torque = atomKK->k_torque.view(); - type = atomKK->k_type.view(); - radius = atomKK->k_radius.view(); - nlocal = atom->nlocal; - nall = atom->nlocal + atom->nghost; - newton_pair = force->newton_pair; - vxmu2f = force->vxmu2f; - - // loop over neighbors of my atoms - - int inum = list->inum; - NeighListKokkos* k_list = static_cast*>(list); - d_numneigh = k_list->d_numneigh; - d_neighbors = k_list->d_neighbors; - d_ilist = k_list->d_ilist; - - copymode = 1; - - // FLD contribution to force & torque - - R0 = 6.0*MY_PI*mu; - RT0 = 8.0*MY_PI*mu; - RS0 = 20.0/3.0*MY_PI*mu; - - h_rate = domainKK->h_rate; - h_ratelo = domainKK->h_ratelo; - - xprd = domainKK->xprd; - yprd = domainKK->yprd; - zprd = domainKK->zprd; - - if(flagfld) { - - if(shearing) { - double *h_rate = domainKK->h_rate; - Ef[0][0] = h_rate[0]/xprd; - Ef[1][1] = h_rate[1]/yprd; - Ef[2][2] = h_rate[2]/zprd; - Ef[0][1] = Ef[1][0] = 0.5 * h_rate[5]/yprd; - Ef[0][2] = Ef[2][0] = 0.5 * h_rate[4]/zprd; - Ef[1][2] = Ef[2][1] = 0.5 * h_rate[3]/zprd; - // needs to be a k_Ef - } - - EV_FLOAT ev; - - domainKK->x2lamda(atom->nlocal); - if(shearing && vflag_either) { - if (neighflag == HALF) { - if(newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); - else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); - } else if (neighflag == HALFTHREAD) { - if(newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); - else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); - } else if (neighflag == FULL) { - if(newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); - else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlocal),*this,ev); - } - } else { // value of NEWTON_PAIR not used, so just 0 - if (neighflag == HALF) Kokkos::parallel_for(Kokkos::RangePolicy >(0,nlocal),*this); - else if (neighflag == HALFTHREAD) Kokkos::parallel_for(Kokkos::RangePolicy >(0,nlocal),*this); - else if (neighflag == FULL) Kokkos::parallel_for(Kokkos::RangePolicy >(0,nlocal),*this); - } - domainKK->lamda2x(atom->nlocal); - - if (vflag_global) { - virial[0] += ev.v[0]; - virial[1] += ev.v[1]; - virial[2] += ev.v[2]; - virial[3] += ev.v[3]; - virial[4] += ev.v[4]; - virial[5] += ev.v[5]; - } - - } - - EV_FLOAT ev; - - if(flagHI) { - - if (flagfld) { // FLAGFLD == 1 - if (vflag_either) { // VFLAG == 1 - if (neighflag == HALF) { - if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - } else if (neighflag == HALFTHREAD) { - if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - } else if (neighflag == FULL) { - if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - } - } else { // VFLAG==0 - if (neighflag == HALF) { - if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - } else if (neighflag == HALFTHREAD) { - if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - } else if (neighflag == FULL) { - if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - } - } - } else { // FLAGFLD == 0 - if (evflag) { // VFLAG== 1 - if (neighflag == HALF) { - if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - } else if (neighflag == HALFTHREAD) { - if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - } else if (neighflag == FULL) { - if (newton_pair) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - else Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,inum),*this,ev); - } - } else { // VFLAG == 0 - if (neighflag == HALF) { - if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - } else if (neighflag == HALFTHREAD) { - if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - } else if (neighflag == FULL) { - if (newton_pair) Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - else Kokkos::parallel_for(Kokkos::RangePolicy >(0,inum),*this); - } - } - } - - if (vflag_global) { - virial[0] += ev.v[0]; - virial[1] += ev.v[1]; - virial[2] += ev.v[2]; - virial[3] += ev.v[3]; - virial[4] += ev.v[4]; - virial[5] += ev.v[5]; - } - - } // if(flagHI) - - if (vflag_atom) { - k_vatom.template modify(); - k_vatom.template sync(); - } - - if (vflag_fdotr) pair_virial_fdotr_compute(this); - - copymode = 0; -} - - -template -template -KOKKOS_INLINE_FUNCTION -void PairLubricateSimpleKokkos::operator()(TagPairLubricateSimpleComputeFLD, const int ii, EV_FLOAT &ev) const { - - // The f and torque arrays are atomic for Half/Thread neighbor style - Kokkos::View::value,Kokkos::MemoryTraits::value> > a_f = f; - Kokkos::View::value,Kokkos::MemoryTraits::value> > a_torque = torque; - - const int i = d_ilist[ii]; - const LMP_FLOAT radi = radius[i]; - - LMP_FLOAT vstream[3]; - vstream[0] = h_rate[0]*x(i,0) + h_rate[5]*x(i,1) + h_rate[4]*x(i,2) + h_ratelo[0]; - vstream[1] = h_rate[1]*x(i,1) + h_rate[3]*x(i,2) + h_ratelo[1]; - vstream[2] = h_rate[2]*x(i,2) + h_ratelo[2]; - - a_f(i,0) += vxmu2f*R0*radi*(vstream[0]-v(i,0)); - a_f(i,1) += vxmu2f*R0*radi*(vstream[1]-v(i,1)); - a_f(i,2) += vxmu2f*R0*radi*(vstream[2]-v(i,2)); - - const LMP_FLOAT radi3 = radi*radi*radi; - - a_torque(i,0) -= vxmu2f*RT0*radi3*(omega(i,0)+0.5*h_rate[3]/zprd); - a_torque(i,1) -= vxmu2f*RT0*radi3*(omega(i,1)-0.5*h_rate[4]/zprd); - a_torque(i,2) -= vxmu2f*RT0*radi3*(omega(i,2)+0.5*h_rate[5]/yprd); - - // Ef = (grad(vstream) + (grad(vstream))^T) / 2 - // set Ef from h_rate in strain units - - if(SHEARING){ - double vRS0 = -vxmu2f * RS0*radi3; - v_tally_tensor(ev,i,i, - vRS0*Ef[0][0],vRS0*Ef[1][1],vRS0*Ef[2][2], - vRS0*Ef[0][1],vRS0*Ef[0][2],vRS0*Ef[1][2]); - } - -} - -template -template -KOKKOS_INLINE_FUNCTION -void PairLubricateSimpleKokkos::operator()(TagPairLubricateSimpleComputeFLD, const int ii) const { - EV_FLOAT ev; - this->template operator()(TagPairLubricateSimpleComputeFLD(), ii, ev); -} - -template -template -KOKKOS_INLINE_FUNCTION -void PairLubricateSimpleKokkos::operator()(TagPairLubricateSimpleCompute, const int ii, EV_FLOAT &ev) const { - - // The f and torque arrays are atomic for Half/Thread neighbor style - Kokkos::View::value,Kokkos::MemoryTraits::value> > a_f = f; - Kokkos::View::value,Kokkos::MemoryTraits::value> > a_torque = torque; - - const int i = d_ilist[ii]; - const X_FLOAT xtmp = x(i,0); - const X_FLOAT ytmp = x(i,1); - const X_FLOAT ztmp = x(i,2); - const int itype = type[i]; - const LMP_FLOAT radi = radius[i]; - const int jnum = d_numneigh[i]; - - LMP_FLOAT wsx,wsy,wsz; - LMP_FLOAT wdx,wdy,wdz; - - F_FLOAT fx_i = 0.0; - F_FLOAT fy_i = 0.0; - F_FLOAT fz_i = 0.0; - - F_FLOAT torquex_i = 0.0; - F_FLOAT torquey_i = 0.0; - F_FLOAT torquez_i = 0.0; - - for (int jj = 0; jj < jnum; jj++) { - int j = d_neighbors(i,jj); - j &= NEIGHMASK; - - const X_FLOAT delx = xtmp - x(j,0); - const X_FLOAT dely = ytmp - x(j,1); - const X_FLOAT delz = ztmp - x(j,2); - const X_FLOAT rsq = delx*delx + dely*dely + delz*delz; - const int jtype = type[j]; - const LMP_FLOAT radj = radius[j]; - - double radsum = radi + radj; // Sum of two particle's radii - - if(rsq < d_cutsq(itype,jtype) && rsq < 1.45*1.45*radsum*radsum) { - const LMP_FLOAT r = sqrt(rsq); - - // scalar resistances XA and YA - - LMP_FLOAT h_sep = r - radsum; - - // if less than minimum gap (scaled inner cutoff by particle radii), use minimum gap instead - - if (r < d_cut_inner(itype,jtype)*radsum) h_sep = d_cut_inner(itype,jtype)*radsum - radsum; - - const LMP_FLOAT wsx = (omega(i,0) + omega(j,0)) * 0.5; - const LMP_FLOAT wsy = (omega(i,1) + omega(j,1)) * 0.5; - const LMP_FLOAT wsz = (omega(i,2) + omega(j,2)) * 0.5; - - const LMP_FLOAT wdx = (omega(i,0) - omega(j,0)) * 0.5; - const LMP_FLOAT wdy = (omega(i,1) - omega(j,1)) * 0.5; - const LMP_FLOAT wdz = (omega(i,2) - omega(j,2)) * 0.5; - - const LMP_FLOAT nx = -delx / r; - const LMP_FLOAT ny = -dely / r; - const LMP_FLOAT nz = -delz / r; - - const LMP_FLOAT hinv = (radi + radj) / (2.0 * h_sep); - - const LMP_FLOAT lhinv = log(hinv); - //if(lhinv < 0.0) error->all(FLERR,"Using pair lubricate with cutoff problem: log(1/h) is negative"); - - const LMP_FLOAT beta0 = radj / radi; - const LMP_FLOAT beta1 = 1.0 + beta0; - - const LMP_FLOAT b0p2 = beta0 * beta0; - const LMP_FLOAT b1p2 = beta1 * beta1; - const LMP_FLOAT b1p3 = beta1 * b1p2; - const LMP_FLOAT mupradi = mu * MY_PI * radi; - - // scalar resistances - - LMP_FLOAT XA11, YA11, YB11, YC12; - if(flaglog) { - XA11 = 6.0*mupradi*( hinv*2.0*b0p2 + lhinv*beta0*(1.0+ 7.0*beta0+ b0p2 )/5.0 )/b1p3; - YA11 = 1.6*mupradi*lhinv*beta0*(2.0+beta0+2.0*b0p2)/b1p3; - YB11 = -0.8*mupradi*radi*lhinv*beta0*(4.0+beta0)/b1p2; - YC12 = 0.8*mupradi*radi*radi*lhinv*b0p2/beta1*(1.0-4.0/beta0); //YC12*(1-4/beta0) - } else { - XA11 = 12.0*mupradi*hinv*b0p2/b1p3; - } - - // relative velocity components U^2-U^1 - - LMP_FLOAT vr1 = v(j,0) - v(i,0); - LMP_FLOAT vr2 = v(j,1) - v(i,1); - LMP_FLOAT vr3 = v(j,2) - v(i,2); - - // normal component (vr.n)n - - LMP_FLOAT vnnr = vr1*nx + vr2*ny + vr3*nz; - LMP_FLOAT vn1 = vnnr * nx; - LMP_FLOAT vn2 = vnnr * ny; - LMP_FLOAT vn3 = vnnr * nz; - - // tangential component vr - (vr.n)n - - LMP_FLOAT vt1 = vr1 - vn1; - LMP_FLOAT vt2 = vr2 - vn2; - LMP_FLOAT vt3 = vr3 - vn3; - - // force due to squeeze type motion : f = XA11 nn dot vr - - F_FLOAT fx = XA11 * vn1; - F_FLOAT fy = XA11 * vn2; - F_FLOAT fz = XA11 * vn3; - - // force due to all shear kind of motions - - if(flaglog) { - LMP_FLOAT ybfac = (1.0-beta0*(1.0+4.0*beta0)/(4.0+beta0))*YB11; - //f+=YA11*vt1-(r1+r2)*YA11*ws cross n + ybfac* wd cross n - fx += YA11 * (vt1-(radi+radj)*(wsy*nz-wsz*ny)) + ybfac * (wdy*nz-wdz*ny); - fy += YA11 * (vt2-(radi+radj)*(wsz*nx-wsx*nz)) + ybfac * (wdz*nx-wdx*nz); - fz += YA11 * (vt3-(radi+radj)*(wsx*ny-wsy*nx)) + ybfac * (wdx*ny-wdy*nx); - } - - // scale forces for appropriate units - - fx *= vxmu2f; - fy *= vxmu2f; - fz *= vxmu2f; - - fx_i += fx; - fy_i += fy; - fz_i += fz; - - if ((NEIGHFLAG==HALF || NEIGHFLAG==HALFTHREAD) && (NEWTON_PAIR || j < nlocal)) { - a_f(j,0) -= fx; - a_f(j,1) -= fy; - a_f(j,2) -= fz; - } - - // torque due to this force - - if (flaglog) { - - LMP_FLOAT wsdotn = wsx*nx + wsy*ny + wsz*nz; - LMP_FLOAT wddotn = wdx*nx + wdy*ny + wdz*nz; - - // squeeze+shear+pump contributions to torque - - //YB11*(vr cross n + (r1+r2)* tang(ws)) +YC12*(1-4/beta)*tang(wd) - - // YB11 & YC12 are not correct if radi != radj, but pair lubricate requires mono-disperse, so ok... - - F_FLOAT tx = YB11*(vr2*nz -vr3*ny + (radi+radj)*(wsx-wsdotn*nx)); - F_FLOAT ty = YB11*(vr3*nx -vr1*nz + (radi+radj)*(wsy-wsdotn*ny)); - F_FLOAT tz = YB11*(vr1*ny -vr2*nx + (radi+radj)*(wsz-wsdotn*nz)); - - F_FLOAT ttx = YC12*(wdx-wddotn*nx); - F_FLOAT tty = YC12*(wdy-wddotn*ny); - F_FLOAT ttz = YC12*(wdz-wddotn*nz); - - // torque is same on both particles ? - - torquex_i += vxmu2f * (tx + ttx); - torquey_i += vxmu2f * (ty + tty); - torquez_i += vxmu2f * (tz + ttz); - - if ((NEIGHFLAG==HALF || NEIGHFLAG==HALFTHREAD) && (NEWTON_PAIR || j < nlocal)) { - a_torque(j,0) += vxmu2f * (tx - ttx); - a_torque(j,1) += vxmu2f * (ty - tty); - a_torque(j,2) += vxmu2f * (tz - ttz); - } - } // if(flaglog) - - if (VFLAG) ev_tally_xyz(ev, i, j, fx, fy, fz, delx, dely, delz); - - } // if(rsq) - } // for(jj) - - a_f(i,0) += fx_i; - a_f(i,1) += fy_i; - a_f(i,2) += fz_i; - a_torque(i,0) += torquex_i; - a_torque(i,1) += torquey_i; - a_torque(i,2) += torquez_i; -} - -template -template -KOKKOS_INLINE_FUNCTION -void PairLubricateSimpleKokkos::operator()(TagPairLubricateSimpleCompute, const int ii) const { - EV_FLOAT ev; - this->template operator()(TagPairLubricateSimpleCompute(), ii, ev); -} - - -/* ---------------------------------------------------------------------- */ - -template -template -KOKKOS_INLINE_FUNCTION -void PairLubricateSimpleKokkos::ev_tally_xyz(EV_FLOAT & ev, int i, int j, - F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, - X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const -{ - Kokkos::View::value,Kokkos::MemoryTraits::value> > v_vatom = k_vatom.view(); - - const F_FLOAT v0 = delx*fx; - const F_FLOAT v1 = dely*fy; - const F_FLOAT v2 = delz*fz; - const F_FLOAT v3 = delx*fy; - const F_FLOAT v4 = delx*fz; - const F_FLOAT v5 = dely*fz; - - if (vflag_global) { - if (NEIGHFLAG != FULL) { - if (NEWTON_PAIR) { // neigh half, newton on - ev.v[0] += v0; - ev.v[1] += v1; - ev.v[2] += v2; - ev.v[3] += v3; - ev.v[4] += v4; - ev.v[5] += v5; - } else { // neigh half, newton off - if (i < nlocal) { - ev.v[0] += 0.5*v0; - ev.v[1] += 0.5*v1; - ev.v[2] += 0.5*v2; - ev.v[3] += 0.5*v3; - ev.v[4] += 0.5*v4; - ev.v[5] += 0.5*v5; - } - if (j < nlocal) { - ev.v[0] += 0.5*v0; - ev.v[1] += 0.5*v1; - ev.v[2] += 0.5*v2; - ev.v[3] += 0.5*v3; - ev.v[4] += 0.5*v4; - ev.v[5] += 0.5*v5; - } - } - } else { //neigh full - ev.v[0] += 0.5*v0; - ev.v[1] += 0.5*v1; - ev.v[2] += 0.5*v2; - ev.v[3] += 0.5*v3; - ev.v[4] += 0.5*v4; - ev.v[5] += 0.5*v5; - } - } - - if (vflag_atom) { - - if (NEIGHFLAG == FULL || NEWTON_PAIR || i < nlocal) { - v_vatom(i,0) += 0.5*v0; - v_vatom(i,1) += 0.5*v1; - v_vatom(i,2) += 0.5*v2; - v_vatom(i,3) += 0.5*v3; - v_vatom(i,4) += 0.5*v4; - v_vatom(i,5) += 0.5*v5; - } - if (NEIGHFLAG != FULL && (NEWTON_PAIR || j < nlocal)) { - v_vatom(j,0) += 0.5*v0; - v_vatom(j,1) += 0.5*v1; - v_vatom(j,2) += 0.5*v2; - v_vatom(j,3) += 0.5*v3; - v_vatom(j,4) += 0.5*v4; - v_vatom(j,5) += 0.5*v5; - } - } -} - -/* ---------------------------------------------------------------------- */ - -template -template -KOKKOS_INLINE_FUNCTION -void PairLubricateSimpleKokkos::v_tally_tensor(EV_FLOAT & ev, int i, int j, - F_FLOAT vxx, F_FLOAT vyy, F_FLOAT vzz, - F_FLOAT vxy, F_FLOAT vxz, F_FLOAT vyz) const -{ - Kokkos::View::value,Kokkos::MemoryTraits::value> > v_vatom = k_vatom.view(); - - const F_FLOAT v0 = vxx; - const F_FLOAT v1 = vyy; - const F_FLOAT v2 = vzz; - const F_FLOAT v3 = vxy; - const F_FLOAT v4 = vxz; - const F_FLOAT v5 = vyz; - - if (vflag_global) { - if (NEIGHFLAG != FULL) { - if (NEWTON_PAIR) { // neigh half, newton on - ev.v[0] += v0; - ev.v[1] += v1; - ev.v[2] += v2; - ev.v[3] += v3; - ev.v[4] += v4; - ev.v[5] += v5; - } else { // neigh half, newton off - if (i < nlocal) { - ev.v[0] += 0.5*v0; - ev.v[1] += 0.5*v1; - ev.v[2] += 0.5*v2; - ev.v[3] += 0.5*v3; - ev.v[4] += 0.5*v4; - ev.v[5] += 0.5*v5; - } - if (j < nlocal) { - ev.v[0] += 0.5*v0; - ev.v[1] += 0.5*v1; - ev.v[2] += 0.5*v2; - ev.v[3] += 0.5*v3; - ev.v[4] += 0.5*v4; - ev.v[5] += 0.5*v5; - } - } - } else { //neigh full - ev.v[0] += 0.5*v0; - ev.v[1] += 0.5*v1; - ev.v[2] += 0.5*v2; - ev.v[3] += 0.5*v3; - ev.v[4] += 0.5*v4; - ev.v[5] += 0.5*v5; - } - } - - if (vflag_atom) { - - if (NEIGHFLAG == FULL || NEWTON_PAIR || i < nlocal) { - v_vatom(i,0) += 0.5*v0; - v_vatom(i,1) += 0.5*v1; - v_vatom(i,2) += 0.5*v2; - v_vatom(i,3) += 0.5*v3; - v_vatom(i,4) += 0.5*v4; - v_vatom(i,5) += 0.5*v5; - } - if (NEIGHFLAG != FULL && (NEWTON_PAIR || j < nlocal)) { - v_vatom(j,0) += 0.5*v0; - v_vatom(j,1) += 0.5*v1; - v_vatom(j,2) += 0.5*v2; - v_vatom(j,3) += 0.5*v3; - v_vatom(j,4) += 0.5*v4; - v_vatom(j,5) += 0.5*v5; - } - } -} - -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -template -void PairLubricateSimpleKokkos::allocate() -{ - PairLubricateSimple::allocate(); - - int n = atom->ntypes; - - memory->destroy(cutsq); - memoryKK->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); - d_cutsq = k_cutsq.template view(); - - memory->destroy(cut_inner); - memoryKK->create_kokkos(k_cut_inner,cut_inner,n+1,n+1,"pair:cut_inner"); - d_cut_inner = k_cut_inner.template view(); -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -template -void PairLubricateSimpleKokkos::settings(int narg, char **arg) -{ - if (narg != 5 && narg != 7) error->all(FLERR, "Illegal pair_style command"); - - PairLubricateSimple::settings(narg,arg); -} - -/* ---------------------------------------------------------------------- - init for one type pair i,j and corresponding j,i -------------------------------------------------------------------------- */ - -template -double PairLubricateSimpleKokkos::init_one(int i, int j) -{ - double cutone = PairLubricateSimple::init_one(i,j); - double cutinnerm = cut_inner[i][j]; - - k_cutsq.h_view(i,j) = k_cutsq.h_view(j,i) = cutone*cutone; - k_cutsq.template modify(); - - k_cut_inner.h_view(i,j) = k_cut_inner.h_view(j,i) = cutinnerm; - k_cut_inner.template modify(); - - return cutone; -} - -/* ---------------------------------------------------------------------- - set coeffs for one or more type pairs -------------------------------------------------------------------------- */ - -template -void PairLubricateSimpleKokkos::coeff(int narg, char **arg) -{ - PairLubricateSimple::coeff(narg,arg); -} - -namespace LAMMPS_NS { -template class PairLubricateSimpleKokkos; -#ifdef LMP_KOKKOS_GPU -template class PairLubricateSimpleKokkos; -#endif -} diff --git a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.h b/src/USER-SUMAN/pair_lubricate_Simple_kokkos.h deleted file mode 100644 index 144d22412d..0000000000 --- a/src/USER-SUMAN/pair_lubricate_Simple_kokkos.h +++ /dev/null @@ -1,130 +0,0 @@ -/* -*- 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(lubricate/Simple/kk,PairLubricateSimpleKokkos); -PairStyle(lubricate/Simple/kk/device,PairLubricateSimpleKokkos); -PairStyle(lubricate/Simple/kk/host,PairLubricateSimpleKokkos); -// clang-format on -#else - -// clang-format off -#ifndef LMP_PAIR_LUBRICATE_SIMPLE_KOKKOS_H -#define LMP_PAIR_LUBRICATE_SIMPLE_KOKKOS_H - -#include "pair_lubricate_Simple.h" -#include "pair_kokkos.h" -#include "kokkos_few.h" -//#include "kokkos_type.h" -//#include "kokkos_base.h" -//#include "Kokkos_Random.hpp" -#include "comm_kokkos.h" - -namespace LAMMPS_NS { - -template -struct TagPairLubricateSimpleCompute {}; - -template -struct TagPairLubricateSimpleComputeFLD {}; - -template -class PairLubricateSimpleKokkos : public PairLubricateSimple { - public: - enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; - typedef DeviceType device_type; - typedef ArrayTypes AT; - typedef EV_FLOAT value_type; - - PairLubricateSimpleKokkos(class LAMMPS *); - ~PairLubricateSimpleKokkos() override; - void compute(int, int) override; - void coeff(int, char **) override; - void settings(int, char **) override; - void init_style() override; - double init_one(int, int) override; - - template - KOKKOS_INLINE_FUNCTION - void operator()(TagPairLubricateSimpleCompute, const int, EV_FLOAT &ev) const; - template - KOKKOS_INLINE_FUNCTION - void operator()(TagPairLubricateSimpleCompute, const int) const; - - template - KOKKOS_INLINE_FUNCTION - void operator()(TagPairLubricateSimpleComputeFLD, const int, EV_FLOAT &ev) const; - - template - KOKKOS_INLINE_FUNCTION - void operator()(TagPairLubricateSimpleComputeFLD, const int) const; - - template - KOKKOS_INLINE_FUNCTION - void ev_tally_xyz(EV_FLOAT &ev, int i, int j, - F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, - X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const; - - template - KOKKOS_INLINE_FUNCTION - void v_tally_tensor(EV_FLOAT &ev, int i, int j, - F_FLOAT vxx, F_FLOAT vyy, F_FLOAT vzz, - F_FLOAT vxy, F_FLOAT vxz, F_FLOAT vyz) const; - - protected: - typename AT::t_x_array_randomread x; - typename AT::t_x_array c_x; - typename AT::t_v_array_randomread v; - typename AT::t_v_array_randomread omega; - typename AT::t_f_array f; - typename AT::t_f_array torque; - typename AT::t_int_1d_randomread type; - typename AT::t_float_1d_randomread radius; - - DAT::tdual_virial_array k_vatom; - typename AT::t_virial_array d_vatom; - - typename AT::t_neighbors_2d d_neighbors; - typename AT::t_int_1d_randomread d_ilist; - typename AT::t_int_1d_randomread d_numneigh; - - int newton_pair; - double special_lj[4]; - - typename AT::tdual_ffloat_2d k_cutsq; - typename AT::t_ffloat_2d d_cutsq; - typename AT::tdual_ffloat_2d k_cut_inner; - typename AT::t_ffloat_2d d_cut_inner; - - int neighflag; - int nlocal,nall,eflag,vflag; - LMP_FLOAT vxmu2f; - - LMP_FLOAT R0, RT0, RS0; - LMP_FLOAT xprd, yprd, zprd; - Few h_rate; - Few h_ratelo; - - class DomainKokkos *domainKK; - - void allocate(); - - friend void pair_virial_fdotr_compute(PairLubricateSimpleKokkos*); -}; - -} - -#endif -#endif - From 4bf92cc846a10a332904abd576ea7c1cff00d3d6 Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 3 Oct 2024 18:35:02 +0000 Subject: [PATCH 29/43] update kokkos install to include brownian --- src/KOKKOS/Install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index 31359d4e4a..ee2e8e61fe 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -277,6 +277,8 @@ action npair_trim_kokkos.h action pack_kokkos.h pack.h action pair_adp_kokkos.cpp pair_adp.cpp action pair_adp_kokkos.h pair_adp.h +action pair_brownian_kokkos.cpp pair_brownian.cpp +action pair_brownian_kokkos.h pair_brownian.h action pair_buck_coul_cut_kokkos.cpp action pair_buck_coul_cut_kokkos.h action pair_buck_coul_long_kokkos.cpp pair_buck_coul_long.cpp From d6562b7514410a9e99241bbeb82e8272ab589333 Mon Sep 17 00:00:00 2001 From: cjknight Date: Thu, 3 Oct 2024 19:30:09 +0000 Subject: [PATCH 30/43] fix-whitespace --- src/COLLOID/pair_brownian.cpp | 2 +- src/COLLOID/pair_lubricate.cpp | 2 +- src/KOKKOS/pair_brownian_kokkos.cpp | 356 +++++++++--------- src/KOKKOS/pair_brownian_kokkos.h | 42 +-- src/KOKKOS/pair_gran_hooke_history_kokkos.cpp | 38 +- 5 files changed, 220 insertions(+), 220 deletions(-) diff --git a/src/COLLOID/pair_brownian.cpp b/src/COLLOID/pair_brownian.cpp index 885a7f6b97..db58bc7bfe 100644 --- a/src/COLLOID/pair_brownian.cpp +++ b/src/COLLOID/pair_brownian.cpp @@ -55,7 +55,7 @@ PairBrownian::PairBrownian(LAMMPS *lmp) : Pair(lmp) PairBrownian::~PairBrownian() { if(copymode) return; - + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/COLLOID/pair_lubricate.cpp b/src/COLLOID/pair_lubricate.cpp index b697552377..d758ac8840 100644 --- a/src/COLLOID/pair_lubricate.cpp +++ b/src/COLLOID/pair_lubricate.cpp @@ -57,7 +57,7 @@ PairLubricate::PairLubricate(LAMMPS *lmp) : Pair(lmp) PairLubricate::~PairLubricate() { if (copymode) return; - + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/KOKKOS/pair_brownian_kokkos.cpp b/src/KOKKOS/pair_brownian_kokkos.cpp index a35c7e1fec..406ec033a5 100644 --- a/src/KOKKOS/pair_brownian_kokkos.cpp +++ b/src/KOKKOS/pair_brownian_kokkos.cpp @@ -47,7 +47,7 @@ enum { EDGE, CONSTANT, VARIABLE }; template PairBrownianKokkos::PairBrownianKokkos(LAMMPS *lmp) : PairBrownian(lmp), - rand_pool(seed + comm->me) + rand_pool(seed + comm->me) { respa_enable = 0; @@ -115,7 +115,7 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) // This section of code adjusts R0/RT0/RS0 if necessary due to changes // in the volume fraction as a result of fix deform or moving walls - + double dims[3], wallcoord; if (flagVF) // Flag for volume fraction corrections if (flagdeform || flagwall == 2) { // Possible changes in volume fraction @@ -158,7 +158,7 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) prethermostat = sqrt(24.0 * force->boltz * t_target / update->dt); prethermostat *= sqrt(force->vxmu2f / force->ftm2v / force->mvv2e); - + // reallocate per-atom arrays if necessary if (vflag_atom) { @@ -193,7 +193,7 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) d_ilist = k_list->d_ilist; copymode = 1; - + EV_FLOAT ev; if (flagfld) { // FLAGFLD == 1 @@ -245,7 +245,7 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) } } } - + if (vflag_global) { virial[0] += ev.v[0]; virial[1] += ev.v[1]; @@ -259,7 +259,7 @@ void PairBrownianKokkos::compute(int eflag_in, int vflag_in) k_vatom.template modify(); k_vatom.template sync(); } - + if (vflag_fdotr) pair_virial_fdotr_compute(this); copymode = 0; @@ -269,13 +269,13 @@ template template KOKKOS_INLINE_FUNCTION void PairBrownianKokkos::operator()(TagPairBrownianCompute, const int ii, EV_FLOAT &ev) const { - + // The f and torque arrays are atomic for Half/Thread neighbor style Kokkos::View::value,Kokkos::MemoryTraits::value> > a_f = f; Kokkos::View::value,Kokkos::MemoryTraits::value> > a_torque = torque; rand_type rand_gen = rand_pool.get_state(); - + const int i = d_ilist[ii]; const X_FLOAT xtmp = x(i,0); const X_FLOAT ytmp = x(i,1); @@ -286,7 +286,7 @@ void PairBrownianKokkos::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute::operator()(TagPairBrownianCompute(ev, i, j, -fx, -fy, -fz, delx, dely, delz); } } - + } // if(flagHI) - + rand_pool.free_state(rand_gen); - + a_f(i,0) += fx_i; a_f(i,1) += fy_i; a_f(i,2) += fz_i; @@ -505,33 +505,33 @@ void PairBrownianKokkos::ev_tally_xyz(EV_FLOAT & ev, int i, int j, const F_FLOAT v3 = delx*fy; const F_FLOAT v4 = delx*fz; const F_FLOAT v5 = dely*fz; - + if (vflag_global) { if (NEIGHFLAG != FULL) { if (NEWTON_PAIR) { // neigh half, newton on - ev.v[0] += v0; - ev.v[1] += v1; - ev.v[2] += v2; - ev.v[3] += v3; - ev.v[4] += v4; - ev.v[5] += v5; + ev.v[0] += v0; + ev.v[1] += v1; + ev.v[2] += v2; + ev.v[3] += v3; + ev.v[4] += v4; + ev.v[5] += v5; } else { // neigh half, newton off - if (i < nlocal) { - ev.v[0] += 0.5*v0; - ev.v[1] += 0.5*v1; - ev.v[2] += 0.5*v2; - ev.v[3] += 0.5*v3; - ev.v[4] += 0.5*v4; - ev.v[5] += 0.5*v5; - } - if (j < nlocal) { - ev.v[0] += 0.5*v0; - ev.v[1] += 0.5*v1; - ev.v[2] += 0.5*v2; - ev.v[3] += 0.5*v3; - ev.v[4] += 0.5*v4; - ev.v[5] += 0.5*v5; - } + if (i < nlocal) { + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } + if (j < nlocal) { + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; + } } } else { //neigh full ev.v[0] += 0.5*v0; @@ -542,9 +542,9 @@ void PairBrownianKokkos::ev_tally_xyz(EV_FLOAT & ev, int i, int j, ev.v[5] += 0.5*v5; } } - + if (vflag_atom) { - + if (NEIGHFLAG == FULL || NEWTON_PAIR || i < nlocal) { v_vatom(i,0) += 0.5*v0; v_vatom(i,1) += 0.5*v1; @@ -574,11 +574,11 @@ void PairBrownianKokkos::allocate() PairBrownian::allocate(); int n = atom->ntypes; - + memory->destroy(cutsq); memoryKK->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); d_cutsq = k_cutsq.template view(); - + memory->destroy(cut_inner); memoryKK->create_kokkos(k_cut_inner,cut_inner,n+1,n+1,"pair:cut_inner"); d_cut_inner = k_cut_inner.template view(); @@ -608,7 +608,7 @@ double PairBrownianKokkos::init_one(int i, int j) k_cutsq.h_view(i,j) = k_cutsq.h_view(j,i) = cutone*cutone; k_cutsq.template modify(); - + k_cut_inner.h_view(i,j) = k_cut_inner.h_view(j,i) = cutinnerm; k_cut_inner.template modify(); diff --git a/src/KOKKOS/pair_brownian_kokkos.h b/src/KOKKOS/pair_brownian_kokkos.h index 06b443fcc4..2247fd7ba0 100644 --- a/src/KOKKOS/pair_brownian_kokkos.h +++ b/src/KOKKOS/pair_brownian_kokkos.h @@ -34,7 +34,7 @@ namespace LAMMPS_NS { template struct TagPairBrownianCompute {}; - + template class PairBrownianKokkos : public PairBrownian, public KokkosBase { public: @@ -42,7 +42,7 @@ class PairBrownianKokkos : public PairBrownian, public KokkosBase { typedef DeviceType device_type; typedef ArrayTypes AT; typedef EV_FLOAT value_type; - + PairBrownianKokkos(class LAMMPS *); ~PairBrownianKokkos() override; void compute(int, int) override; @@ -78,7 +78,7 @@ class PairBrownianKokkos : public PairBrownian, public KokkosBase { typename AT::t_neighbors_2d d_neighbors; typename AT::t_int_1d_randomread d_ilist; typename AT::t_int_1d_randomread d_numneigh; - + int newton_pair; double special_lj[4]; @@ -86,7 +86,7 @@ class PairBrownianKokkos : public PairBrownian, public KokkosBase { typename AT::t_ffloat_2d d_cutsq; typename AT::tdual_ffloat_2d k_cut_inner; typename AT::t_ffloat_2d d_cut_inner; - + int neighflag; int nlocal,nall,eflag,vflag; LMP_FLOAT vxmu2f; @@ -99,9 +99,9 @@ class PairBrownianKokkos : public PairBrownian, public KokkosBase { void set_3_orthogonal_vectors(const double p1[3], double * const p2, double * const p3) const { double norm; int ix, iy, iz; - + // find the index of maximum magnitude and store it in iz - + if (fabs(p1[0]) > fabs(p1[1])) { iz = 0; ix = 1; @@ -111,42 +111,42 @@ class PairBrownianKokkos : public PairBrownian, public KokkosBase { ix = 2; iy = 0; } - + if (iz == 0) { if (fabs(p1[0]) < fabs(p1[2])) { - iz = 2; - ix = 0; - iy = 1; + iz = 2; + ix = 0; + iy = 1; } } else { if (fabs(p1[1]) < fabs(p1[2])) { - iz = 2; - ix = 0; - iy = 1; + iz = 2; + ix = 0; + iy = 1; } } - + // set p2 arbitrarily such that it's orthogonal to p1 - + p2[ix] = 1.0; p2[iy] = 1.0; p2[iz] = -(p1[ix] * p2[ix] + p1[iy] * p2[iy]) / p1[iz]; - + // normalize p2 - + norm = sqrt(p2[0] * p2[0] + p2[1] * p2[1] + p2[2] * p2[2]); - + p2[0] = p2[0] / norm; p2[1] = p2[1] / norm; p2[2] = p2[2] / norm; - + // Set p3 by taking the cross product p3=p2xp1 - + p3[0] = p1[1] * p2[2] - p1[2] * p2[1]; p3[1] = p1[2] * p2[0] - p1[0] * p2[2]; p3[2] = p1[0] * p2[1] - p1[1] * p2[0]; }; - + friend void pair_virial_fdotr_compute(PairBrownianKokkos*); Kokkos::Random_XorShift64_Pool rand_pool; diff --git a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp index 50fcd7c054..b3aaced0e5 100644 --- a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp +++ b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp @@ -466,8 +466,8 @@ template template KOKKOS_INLINE_FUNCTION void PairGranHookeHistoryKokkos::ev_tally_xyz(EV_FLOAT &ev, int i, int j, - F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, - X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const + F_FLOAT fx, F_FLOAT fy, F_FLOAT fz, + X_FLOAT delx, X_FLOAT dely, X_FLOAT delz) const { Kokkos::View::value,Kokkos::MemoryTraits::value> > v_vatom = k_vatom.view(); @@ -477,7 +477,7 @@ void PairGranHookeHistoryKokkos::ev_tally_xyz(EV_FLOAT &ev, int i, i const F_FLOAT v3 = delx*fy; const F_FLOAT v4 = delx*fz; const F_FLOAT v5 = dely*fz; - + if (vflag_global) { if (NEWTON_PAIR) { // neigh half, newton on ev.v[0] += v0; @@ -488,26 +488,26 @@ void PairGranHookeHistoryKokkos::ev_tally_xyz(EV_FLOAT &ev, int i, i ev.v[5] += v5; } else { // neigh half, newton off if (i < nlocal) { - ev.v[0] += 0.5*v0; - ev.v[1] += 0.5*v1; - ev.v[2] += 0.5*v2; - ev.v[3] += 0.5*v3; - ev.v[4] += 0.5*v4; - ev.v[5] += 0.5*v5; + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; } if (j < nlocal) { - ev.v[0] += 0.5*v0; - ev.v[1] += 0.5*v1; - ev.v[2] += 0.5*v2; - ev.v[3] += 0.5*v3; - ev.v[4] += 0.5*v4; - ev.v[5] += 0.5*v5; + ev.v[0] += 0.5*v0; + ev.v[1] += 0.5*v1; + ev.v[2] += 0.5*v2; + ev.v[3] += 0.5*v3; + ev.v[4] += 0.5*v4; + ev.v[5] += 0.5*v5; } - } + } } - + if (vflag_atom) { - + if (NEWTON_PAIR || i < nlocal) { v_vatom(i,0) += 0.5*v0; v_vatom(i,1) += 0.5*v1; @@ -524,7 +524,7 @@ void PairGranHookeHistoryKokkos::ev_tally_xyz(EV_FLOAT &ev, int i, i v_vatom(j,4) += 0.5*v4; v_vatom(j,5) += 0.5*v5; } - + } } From a26c81d73bb21d9e5fea12d623b4cf7b5ad04344 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Thu, 3 Oct 2024 15:59:27 -0600 Subject: [PATCH 31/43] Revert changes to pair lubricate base class --- src/COLLOID/pair_brownian.cpp | 2 +- src/COLLOID/pair_lubricate.cpp | 2 -- src/COLLOID/pair_lubricate.h | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/COLLOID/pair_brownian.cpp b/src/COLLOID/pair_brownian.cpp index db58bc7bfe..6773900e44 100644 --- a/src/COLLOID/pair_brownian.cpp +++ b/src/COLLOID/pair_brownian.cpp @@ -54,7 +54,7 @@ PairBrownian::PairBrownian(LAMMPS *lmp) : Pair(lmp) PairBrownian::~PairBrownian() { - if(copymode) return; + if (copymode) return; if (allocated) { memory->destroy(setflag); diff --git a/src/COLLOID/pair_lubricate.cpp b/src/COLLOID/pair_lubricate.cpp index d758ac8840..14e587e5f8 100644 --- a/src/COLLOID/pair_lubricate.cpp +++ b/src/COLLOID/pair_lubricate.cpp @@ -56,8 +56,6 @@ PairLubricate::PairLubricate(LAMMPS *lmp) : Pair(lmp) PairLubricate::~PairLubricate() { - if (copymode) return; - if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/COLLOID/pair_lubricate.h b/src/COLLOID/pair_lubricate.h index 6956293dbc..8097eb76dd 100644 --- a/src/COLLOID/pair_lubricate.h +++ b/src/COLLOID/pair_lubricate.h @@ -56,7 +56,7 @@ class PairLubricate : public Pair { double R0, RT0, RS0; double **cut_inner, **cut; - virtual void allocate(); + void allocate(); }; } // namespace LAMMPS_NS From d0f6f21c39fe3e086dbbd1752dcaf26997d52f6f Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Thu, 3 Oct 2024 16:17:06 -0600 Subject: [PATCH 32/43] Use wrapper and remove sync to host --- src/KOKKOS/compute_temp_deform_kokkos.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/KOKKOS/compute_temp_deform_kokkos.cpp b/src/KOKKOS/compute_temp_deform_kokkos.cpp index 328cf783e0..17e6b143a4 100644 --- a/src/KOKKOS/compute_temp_deform_kokkos.cpp +++ b/src/KOKKOS/compute_temp_deform_kokkos.cpp @@ -215,8 +215,7 @@ void ComputeTempDeformKokkos::remove_bias_all() domainKK->lamda2x(nlocal); - atomKK->k_v.template modify(); - atomKK->k_v.template sync(); + atomKK->modified(execution_space,V_MASK); } template @@ -246,8 +245,7 @@ void ComputeTempDeformKokkos::restore_bias_all() Kokkos::parallel_for(Kokkos::RangePolicy(0,nlocal),*this); copymode = 0; - atomKK->k_v.template modify(); - atomKK->k_v.template sync(); + atomKK->modified(execution_space,V_MASK); } template From 98ad09b0c952a6cb4638c1d07777645bc147fad4 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Thu, 3 Oct 2024 16:17:39 -0600 Subject: [PATCH 33/43] Tighten up check even more --- src/KOKKOS/fix_deform_kokkos.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/KOKKOS/fix_deform_kokkos.cpp b/src/KOKKOS/fix_deform_kokkos.cpp index 0a0ce895e5..9b279fa91d 100644 --- a/src/KOKKOS/fix_deform_kokkos.cpp +++ b/src/KOKKOS/fix_deform_kokkos.cpp @@ -55,7 +55,11 @@ void FixDeformKokkos::pre_exchange() void FixDeformKokkos::end_of_step() { - if (remapflag == Domain::X_REMAP) atomKK->sync(Host,ALL_MASK); + if (remapflag == Domain::X_REMAP && rfix.size() > 0) + atomKK->sync(Host,ALL_MASK); + FixDeform::end_of_step(); - if (remapflag == Domain::X_REMAP) atomKK->modified(Host,ALL_MASK); + + if (remapflag == Domain::X_REMAP && rfix.size() > 0) + atomKK->modified(Host,ALL_MASK); } From 3776ff938daaf1a1255d65ed526cdf3b2b5b8a21 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Thu, 3 Oct 2024 16:36:05 -0600 Subject: [PATCH 34/43] Need to use vflag_either instead of vflag_global --- src/KOKKOS/pair_gran_hooke_history_kokkos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp index b3aaced0e5..495d56721a 100644 --- a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp +++ b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp @@ -212,7 +212,7 @@ void PairGranHookeHistoryKokkos::compute(int eflag_in, int vflag_in) } } } else { - if (vflag_global) { + if (vflag_either) { if (shearupdate) { Kokkos::parallel_reduce(Kokkos::RangePolicy>(0,inum),*this, ev); } else { From f7cf8596706f81455e8db258674d75a97a3c2cf2 Mon Sep 17 00:00:00 2001 From: cjknight Date: Fri, 4 Oct 2024 15:32:47 +0000 Subject: [PATCH 35/43] doc --- doc/src/pair_brownian.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/pair_brownian.rst b/doc/src/pair_brownian.rst index 9fec789ba0..9e740e663b 100644 --- a/doc/src/pair_brownian.rst +++ b/doc/src/pair_brownian.rst @@ -6,7 +6,7 @@ pair_style brownian command =========================== -Accelerator Variants: *brownian/omp* +Accelerator Variants: *brownian/omp*, *brownian/kk* pair_style brownian/poly command ================================ From 08266b65e4bb2d779cc8fef345e439e0e267df8e Mon Sep 17 00:00:00 2001 From: cjknight Date: Fri, 4 Oct 2024 15:45:16 +0000 Subject: [PATCH 36/43] doc --- doc/src/Commands_pair.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/Commands_pair.rst b/doc/src/Commands_pair.rst index a55c9568e3..5f42f53bd5 100644 --- a/doc/src/Commands_pair.rst +++ b/doc/src/Commands_pair.rst @@ -44,7 +44,7 @@ OPT. * :doc:`born/coul/wolf/cs (g) ` * :doc:`born/gauss ` * :doc:`bpm/spring ` - * :doc:`brownian (o) ` + * :doc:`brownian (ko) ` * :doc:`brownian/poly (o) ` * :doc:`buck (giko) ` * :doc:`buck/coul/cut (giko) ` From 9108168ea3f87eb6463c357375357118dc231a0a Mon Sep 17 00:00:00 2001 From: cjknight Date: Fri, 4 Oct 2024 11:35:46 -0500 Subject: [PATCH 37/43] doc --- doc/src/pair_brownian.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/src/pair_brownian.rst b/doc/src/pair_brownian.rst index 9e740e663b..a740952a5c 100644 --- a/doc/src/pair_brownian.rst +++ b/doc/src/pair_brownian.rst @@ -1,5 +1,6 @@ .. index:: pair_style brownian .. index:: pair_style brownian/omp +.. index:: pair_style brownian/kk .. index:: pair_style brownian/poly .. index:: pair_style brownian/poly/omp From 8827dec5a91472eab3063fdb3108ab03db0dd327 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Fri, 4 Oct 2024 13:04:20 -0600 Subject: [PATCH 38/43] Small refactor --- src/KOKKOS/compute_temp_deform_kokkos.cpp | 16 ++++- src/KOKKOS/compute_temp_deform_kokkos.h | 1 + src/KOKKOS/fix_langevin_kokkos.cpp | 28 +++++---- src/KOKKOS/fix_nh_kokkos.cpp | 74 +++++++++++++++++------ src/KOKKOS/fix_nvt_sllod_kokkos.cpp | 35 ++++++++--- src/KOKKOS/fix_temp_berendsen_kokkos.cpp | 22 ++++--- src/KOKKOS/fix_temp_rescale_kokkos.cpp | 23 ++++--- src/compute.h | 1 + 8 files changed, 140 insertions(+), 60 deletions(-) diff --git a/src/KOKKOS/compute_temp_deform_kokkos.cpp b/src/KOKKOS/compute_temp_deform_kokkos.cpp index 17e6b143a4..54acf58a21 100644 --- a/src/KOKKOS/compute_temp_deform_kokkos.cpp +++ b/src/KOKKOS/compute_temp_deform_kokkos.cpp @@ -190,10 +190,20 @@ void ComputeTempDeformKokkos::operator()(TagComputeTempDeformVector< } /* ---------------------------------------------------------------------- */ + template void ComputeTempDeformKokkos::remove_bias_all() { - atomKK->sync(execution_space,datamask_read); + remove_bias_all_kk(); + atomKK->sync(Host,V_MASK); +} + +/* ---------------------------------------------------------------------- */ + +template +void ComputeTempDeformKokkos::remove_bias_all_kk() +{ + atomKK->sync(execution_space,X_MASK|V_MASK); v = atomKK->k_v.view(); x = atomKK->k_x.view(); mask = atomKK->k_mask.view(); @@ -232,12 +242,12 @@ void ComputeTempDeformKokkos::operator()(TagComputeTempDeformRemoveB } /* ---------------------------------------------------------------------- */ + template void ComputeTempDeformKokkos::restore_bias_all() { - atomKK->sync(execution_space,datamask_read); + atomKK->sync(execution_space,V_MASK); v = atomKK->k_v.view(); - x = atomKK->k_x.view(); mask = atomKK->k_mask.view(); int nlocal = atom->nlocal; diff --git a/src/KOKKOS/compute_temp_deform_kokkos.h b/src/KOKKOS/compute_temp_deform_kokkos.h index 2880314b55..b7584e6e14 100644 --- a/src/KOKKOS/compute_temp_deform_kokkos.h +++ b/src/KOKKOS/compute_temp_deform_kokkos.h @@ -69,6 +69,7 @@ class ComputeTempDeformKokkos: public ComputeTempDeform { double compute_scalar() override; void compute_vector() override; void remove_bias_all() override; + void remove_bias_all_kk() override; void restore_bias_all() override; template diff --git a/src/KOKKOS/fix_langevin_kokkos.cpp b/src/KOKKOS/fix_langevin_kokkos.cpp index e60b1f0ec6..546f204de6 100644 --- a/src/KOKKOS/fix_langevin_kokkos.cpp +++ b/src/KOKKOS/fix_langevin_kokkos.cpp @@ -86,7 +86,6 @@ FixLangevinKokkos::FixLangevinKokkos(LAMMPS *lmp, int narg, char **a execution_space = ExecutionSpaceFromDevice::space; datamask_read = V_MASK | F_MASK | MASK_MASK | RMASS_MASK | TYPE_MASK; datamask_modify = F_MASK; - } /* ---------------------------------------------------------------------- */ @@ -227,12 +226,16 @@ void FixLangevinKokkos::post_force(int /*vflag*/) // account for bias velocity if (tbiasflag == BIAS) { - atomKK->sync(temperature->execution_space,temperature->datamask_read); - temperature->compute_scalar(); - temperature->remove_bias_all(); // modifies velocities - // if temeprature compute is kokkosized host-device comm won't be needed - atomKK->modified(temperature->execution_space,temperature->datamask_modify); - atomKK->sync(execution_space,temperature->datamask_modify); + if (temperature->kokkosable) { + temperature->compute_scalar(); + temperature->remove_bias_all_kk(); + } else { + atomKK->sync(temperature->execution_space,temperature->datamask_read); + temperature->compute_scalar(); + temperature->remove_bias_all(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + } } // compute langevin force in parallel on the device @@ -526,10 +529,13 @@ void FixLangevinKokkos::post_force(int /*vflag*/) if (tbiasflag == BIAS) { - atomKK->sync(temperature->execution_space,temperature->datamask_read); - temperature->restore_bias_all(); // modifies velocities - atomKK->modified(temperature->execution_space,temperature->datamask_modify); - atomKK->sync(execution_space,temperature->datamask_modify); + if (temperature->kokkosable) temperature->restore_bias_all(); + else { + atomKK->sync(temperature->execution_space,temperature->datamask_read); + temperature->restore_bias_all(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + } } // set modify flags for the views modified in post_force functor diff --git a/src/KOKKOS/fix_nh_kokkos.cpp b/src/KOKKOS/fix_nh_kokkos.cpp index b3614488b5..ff67f63b0d 100644 --- a/src/KOKKOS/fix_nh_kokkos.cpp +++ b/src/KOKKOS/fix_nh_kokkos.cpp @@ -80,7 +80,11 @@ void FixNHKokkos::setup(int /*vflag*/) { // tdof needed by compute_temp_target() + atomKK->sync(temperature->execution_space,temperature->datamask_read); t_current = temperature->compute_scalar(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + tdof = temperature->dof; // t_target is needed by NPH and NPT in compute_scalar() @@ -105,6 +109,7 @@ void FixNHKokkos::setup(int /*vflag*/) atomKK->sync(temperature->execution_space,temperature->datamask_read); t0 = temperature->compute_scalar(); atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); if (t0 < EPSILON) error->all(FLERR,"Current temperature too close to zero, consider using ptemp keyword"); } @@ -117,6 +122,8 @@ void FixNHKokkos::setup(int /*vflag*/) atomKK->sync(temperature->execution_space,temperature->datamask_read); t_current = temperature->compute_scalar(); atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + tdof = temperature->dof; if (pstat_flag) { @@ -194,9 +201,7 @@ void FixNHKokkos::initial_integrate(int /*vflag*/) if (pstat_flag) { atomKK->sync(temperature->execution_space,temperature->datamask_read); - atomKK->modified(temperature->execution_space,temperature->datamask_modify); - //atomKK->sync(pressure->execution_space,pressure->datamask_read); - //atomKK->modified(pressure->execution_space,pressure->datamask_modify); + atomKK->sync(pressure->execution_space,pressure->datamask_read); if (pstyle == ISO) { temperature->compute_scalar(); pressure->compute_scalar(); @@ -204,6 +209,10 @@ void FixNHKokkos::initial_integrate(int /*vflag*/) temperature->compute_vector(); pressure->compute_vector(); } + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->modified(pressure->execution_space,pressure->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,pressure->datamask_modify); couple(); pressure->addstep(update->ntimestep+1); } @@ -250,6 +259,7 @@ void FixNHKokkos::final_integrate() atomKK->sync(temperature->execution_space,temperature->datamask_read); t_current = temperature->compute_scalar(); atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); } if (pstat_flag) nh_v_press(); @@ -260,15 +270,24 @@ void FixNHKokkos::final_integrate() atomKK->sync(temperature->execution_space,temperature->datamask_read); t_current = temperature->compute_scalar(); atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); tdof = temperature->dof; if (pstat_flag) { - //atomKK->sync(pressure->execution_space,pressure->datamask_read); - //atomKK->modified(pressure->execution_space,pressure->datamask_modify); - if (pstyle == ISO) pressure->compute_scalar(); - else { + if (pstyle == ISO) { + atomKK->sync(pressure->execution_space,pressure->datamask_read); + pressure->compute_scalar(); + atomKK->modified(pressure->execution_space,pressure->datamask_modify); + atomKK->sync(execution_space,pressure->datamask_modify); + } else { + atomKK->sync(temperature->execution_space,temperature->datamask_read); + atomKK->sync(pressure->execution_space,pressure->datamask_read); temperature->compute_vector(); pressure->compute_vector(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->modified(pressure->execution_space,pressure->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,pressure->datamask_modify); } couple(); pressure->addstep(update->ntimestep+1); @@ -480,9 +499,13 @@ void FixNHKokkos::nh_v_press() factor[2] = exp(-dt4*(omega_dot[2]+mtk_term2)); if (which == BIAS) { - atomKK->sync(temperature->execution_space,temperature->datamask_read); - temperature->remove_bias_all(); - atomKK->modified(temperature->execution_space,temperature->datamask_modify); + if (temperature->kokkosable) temperature->remove_bias_all_kk(); + else { + atomKK->sync(temperature->execution_space,temperature->datamask_read); + temperature->remove_bias_all(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + } } atomKK->sync(execution_space,V_MASK | MASK_MASK); @@ -497,11 +520,14 @@ void FixNHKokkos::nh_v_press() atomKK->modified(execution_space,V_MASK); if (which == BIAS) { - atomKK->sync(temperature->execution_space,temperature->datamask_read); - temperature->restore_bias_all(); - atomKK->modified(temperature->execution_space,temperature->datamask_modify); + if (temperature->kokkosable) temperature->restore_bias_all(); + else { + atomKK->sync(temperature->execution_space,temperature->datamask_read); + temperature->restore_bias_all(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + } } - } template @@ -617,9 +643,13 @@ void FixNHKokkos::nh_v_temp() if (igroup == atomKK->firstgroup) nlocal = atomKK->nfirst; if (which == BIAS) { - atomKK->sync(temperature->execution_space,temperature->datamask_read); - temperature->remove_bias_all(); - atomKK->modified(temperature->execution_space,temperature->datamask_modify); + if (temperature->kokkosable) temperature->remove_bias_all_kk(); + else { + atomKK->sync(temperature->execution_space,temperature->datamask_read); + temperature->remove_bias_all(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + } } atomKK->sync(execution_space,V_MASK | MASK_MASK); @@ -631,9 +661,13 @@ void FixNHKokkos::nh_v_temp() atomKK->modified(execution_space,V_MASK); if (which == BIAS) { - atomKK->sync(temperature->execution_space,temperature->datamask_read); - temperature->restore_bias_all(); - atomKK->modified(temperature->execution_space,temperature->datamask_modify); + if (temperature->kokkosable) temperature->restore_bias_all(); + else { + atomKK->sync(temperature->execution_space,temperature->datamask_read); + temperature->restore_bias_all(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + } } } diff --git a/src/KOKKOS/fix_nvt_sllod_kokkos.cpp b/src/KOKKOS/fix_nvt_sllod_kokkos.cpp index ddcc0c728c..42f78270ad 100644 --- a/src/KOKKOS/fix_nvt_sllod_kokkos.cpp +++ b/src/KOKKOS/fix_nvt_sllod_kokkos.cpp @@ -68,6 +68,10 @@ FixNVTSllodKokkos::FixNVTSllodKokkos(LAMMPS *lmp, int narg, char **a this->modify->add_compute(fmt::format("{} {} temp/deform/kk",this->id_temp,this->group->names[this->igroup])); this->tcomputeflag = 1; this->nondeformbias = 0; + + this->execution_space = ExecutionSpaceFromDevice::space; + this->datamask_read = EMPTY_MASK; + this->datamask_modify = EMPTY_MASK; } /* ---------------------------------------------------------------------- */ @@ -114,6 +118,7 @@ void FixNVTSllodKokkos::nh_v_temp() atomKK->sync(this->temperature->execution_space,this->temperature->datamask_read); this->temperature->compute_scalar(); atomKK->modified(this->temperature->execution_space,this->temperature->datamask_modify); + atomKK->sync(this->execution_space,this->temperature->datamask_modify); } v = atomKK->k_v.view(); @@ -130,9 +135,13 @@ void FixNVTSllodKokkos::nh_v_temp() vdelu = typename AT::t_v_array(Kokkos::NoInit("nvt/sllod/kk:vdelu"), atomKK->nmax); if (!this->psllod_flag) { - atomKK->sync(this->temperature->execution_space,this->temperature->datamask_read); - this->temperature->remove_bias_all(); - atomKK->modified(this->temperature->execution_space,this->temperature->datamask_modify); + if (this->temperature->kokkosable) this->temperature->remove_bias_all_kk(); + else { + atomKK->sync(this->temperature->execution_space,this->temperature->datamask_read); + this->temperature->remove_bias_all(); + atomKK->modified(this->temperature->execution_space,this->temperature->datamask_modify); + atomKK->sync(this->execution_space,this->temperature->datamask_modify); + } } atomKK->sync(this->execution_space,V_MASK | MASK_MASK); @@ -142,9 +151,13 @@ void FixNVTSllodKokkos::nh_v_temp() this->copymode = 0; if (this->psllod_flag) { - atomKK->sync(this->temperature->execution_space,this->temperature->datamask_read); - this->temperature->remove_bias_all(); - atomKK->modified(this->temperature->execution_space,this->temperature->datamask_modify); + if (this->temperature->kokkosable) this->temperature->remove_bias_all_kk(); + else { + atomKK->sync(this->temperature->execution_space,this->temperature->datamask_read); + this->temperature->remove_bias_all(); + atomKK->modified(this->temperature->execution_space,this->temperature->datamask_modify); + atomKK->sync(this->execution_space,this->temperature->datamask_modify); + } } atomKK->sync(this->execution_space,V_MASK | MASK_MASK); @@ -155,9 +168,13 @@ void FixNVTSllodKokkos::nh_v_temp() atomKK->modified(this->execution_space,V_MASK); - atomKK->sync(this->temperature->execution_space,this->temperature->datamask_read); - this->temperature->restore_bias_all(); - atomKK->modified(this->temperature->execution_space,this->temperature->datamask_modify); + if (this->temperature->kokkosable) this->temperature->restore_bias_all(); + else { + atomKK->sync(this->temperature->execution_space,this->temperature->datamask_read); + this->temperature->restore_bias_all(); + atomKK->modified(this->temperature->execution_space,this->temperature->datamask_modify); + atomKK->sync(this->execution_space,this->temperature->datamask_modify); + } } template diff --git a/src/KOKKOS/fix_temp_berendsen_kokkos.cpp b/src/KOKKOS/fix_temp_berendsen_kokkos.cpp index 8aaf586194..32d04a58b3 100644 --- a/src/KOKKOS/fix_temp_berendsen_kokkos.cpp +++ b/src/KOKKOS/fix_temp_berendsen_kokkos.cpp @@ -97,10 +97,13 @@ void FixTempBerendsenKokkos::end_of_step() auto groupbit = this->groupbit; if (which == NOBIAS) { - atomKK->sync(temperature->execution_space,temperature->datamask_read); - temperature->remove_bias_all(); - atomKK->modified(temperature->execution_space,temperature->datamask_modify); - atomKK->sync(execution_space,temperature->datamask_modify); + if (temperature->kokkosable) temperature->remove_bias_all_kk(); + else { + atomKK->sync(temperature->execution_space,temperature->datamask_read); + temperature->remove_bias_all(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + } } atomKK->sync(execution_space,V_MASK|MASK_MASK); @@ -116,10 +119,13 @@ void FixTempBerendsenKokkos::end_of_step() atomKK->modified(execution_space,V_MASK); if (which == NOBIAS) { - atomKK->sync(temperature->execution_space,temperature->datamask_read); - temperature->restore_bias_all(); - atomKK->modified(temperature->execution_space,temperature->datamask_modify); - atomKK->sync(execution_space,temperature->datamask_modify); + if (temperature->kokkosable) temperature->restore_bias_all(); + else { + atomKK->sync(temperature->execution_space,temperature->datamask_read); + temperature->restore_bias_all(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + } } } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/fix_temp_rescale_kokkos.cpp b/src/KOKKOS/fix_temp_rescale_kokkos.cpp index 5c295634e7..02ba4ff1e2 100644 --- a/src/KOKKOS/fix_temp_rescale_kokkos.cpp +++ b/src/KOKKOS/fix_temp_rescale_kokkos.cpp @@ -99,10 +99,13 @@ void FixTempRescaleKokkos::end_of_step() auto groupbit = this->groupbit; if (which == NOBIAS) { - atomKK->sync(temperature->execution_space,temperature->datamask_read); - temperature->remove_bias_all(); - atomKK->modified(temperature->execution_space,temperature->datamask_modify); - atomKK->sync(execution_space,temperature->datamask_modify); + if (temperature->kokkosable) temperature->remove_bias_all_kk(); + else { + atomKK->sync(temperature->execution_space,temperature->datamask_read); + temperature->remove_bias_all(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + } } atomKK->sync(execution_space,V_MASK|MASK_MASK); @@ -118,11 +121,13 @@ void FixTempRescaleKokkos::end_of_step() atomKK->modified(execution_space,V_MASK); if (which == NOBIAS) { - atomKK->sync(temperature->execution_space,temperature->datamask_read); - temperature->restore_bias_all(); - atomKK->modified(temperature->execution_space,temperature->datamask_modify); - atomKK->sync(execution_space,temperature->datamask_modify); - + if (temperature->kokkosable) temperature->restore_bias_all(); + else { + atomKK->sync(temperature->execution_space,temperature->datamask_read); + temperature->restore_bias_all(); + atomKK->modified(temperature->execution_space,temperature->datamask_modify); + atomKK->sync(execution_space,temperature->datamask_modify); + } } } } diff --git a/src/compute.h b/src/compute.h index 6956c3ae99..50c69d8d01 100644 --- a/src/compute.h +++ b/src/compute.h @@ -144,6 +144,7 @@ class Compute : protected Pointers { virtual void remove_bias(int, double *) {} virtual void remove_bias_thr(int, double *, double *) {} virtual void remove_bias_all() {} + virtual void remove_bias_all_kk() {} virtual void reapply_bias_all() {} virtual void restore_bias(int, double *) {} virtual void restore_bias_thr(int, double *, double *) {} From 27954609b8f1c2f3333064f61dd27ad971ea6132 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Fri, 4 Oct 2024 15:25:38 -0600 Subject: [PATCH 39/43] Disallow newton on with full neigh list --- src/KOKKOS/kokkos.cpp | 15 ++++++++++++--- src/KOKKOS/kokkos.h | 1 + src/accelerator_kokkos.h | 1 + src/input.cpp | 2 ++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index b3edb0e6a0..00676c7bf8 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -633,15 +633,24 @@ void KokkosLMP::accelerator(int narg, char **arg) // set neighbor binsize, same as neigh_modify command force->newton = force->newton_pair = force->newton_bond = newtonflag; - - if (neigh_thread && newtonflag) - error->all(FLERR,"Must use KOKKOS package option 'newton off' with 'neigh/thread on'"); + newton_check(); neighbor->binsize_user = binsize; if (binsize <= 0.0) neighbor->binsizeflag = 0; else neighbor->binsizeflag = 1; } +/* ---------------------------------------------------------------------- */ + +void KokkosLMP::newton_check() +{ + if (neighflag == FULL && force->newton) + error->all(FLERR,"Must use 'newton off' with KOKKOS package option 'neigh full'"); + + if (neigh_thread && force->newton) + error->all(FLERR,"Must use 'newton off' with KOKKOS package option 'neigh/thread on'"); +} + /* ---------------------------------------------------------------------- called by Finish ------------------------------------------------------------------------- */ diff --git a/src/KOKKOS/kokkos.h b/src/KOKKOS/kokkos.h index 419de62dec..f88fb6e685 100644 --- a/src/KOKKOS/kokkos.h +++ b/src/KOKKOS/kokkos.h @@ -64,6 +64,7 @@ class KokkosLMP : protected Pointers { static void initialize(const Kokkos::InitializationSettings&, Error *); static void finalize(); void accelerator(int, char **); + void newton_check(); bigint neigh_count(int); template diff --git a/src/accelerator_kokkos.h b/src/accelerator_kokkos.h index 36a376bff8..dec52b2363 100644 --- a/src/accelerator_kokkos.h +++ b/src/accelerator_kokkos.h @@ -59,6 +59,7 @@ class KokkosLMP { void accelerator(int, char **) {} int neigh_list_kokkos(int) { return 0; } int neigh_count(int) { return 0; } + void newton_check() {}; }; class AtomKokkos : public Atom { diff --git a/src/input.cpp b/src/input.cpp index 38c38ca2ee..25211ba848 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1687,6 +1687,8 @@ void Input::newton() if (newton_pair || newton_bond) force->newton = 1; else force->newton = 0; + + if (lmp->kokkos) lmp->kokkos->newton_check(); } /* ---------------------------------------------------------------------- */ From b494a486a177e75fe4c4b5bc4cf36a9bdd40dcf5 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 Oct 2024 17:59:44 -0400 Subject: [PATCH 40/43] cosmetic --- src/KOKKOS/pair_gran_hooke_history_kokkos.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp index 495d56721a..ef797a797f 100644 --- a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp +++ b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp @@ -524,9 +524,7 @@ void PairGranHookeHistoryKokkos::ev_tally_xyz(EV_FLOAT &ev, int i, i v_vatom(j,4) += 0.5*v4; v_vatom(j,5) += 0.5*v5; } - } - } namespace LAMMPS_NS { From 2c738669ff74a009ba860d21155a2fe34ba37212 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Fri, 4 Oct 2024 16:15:34 -0600 Subject: [PATCH 41/43] compute_temp_sphere does not modify positions --- src/compute_temp_sphere.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compute_temp_sphere.cpp b/src/compute_temp_sphere.cpp index 2ee067abcb..65c2cdf3cc 100644 --- a/src/compute_temp_sphere.cpp +++ b/src/compute_temp_sphere.cpp @@ -14,6 +14,7 @@ #include "compute_temp_sphere.h" #include "atom.h" +#include "atom_masks.h" #include "domain.h" #include "error.h" #include "force.h" @@ -76,6 +77,8 @@ ComputeTempSphere::ComputeTempSphere(LAMMPS *lmp, int narg, char **arg) : if (!atom->omega_flag) error->all(FLERR, "Compute temp/sphere requires atom attribute omega"); if (!atom->radius_flag) error->all(FLERR, "Compute temp/sphere requires atom attribute radius"); + + datamask_modify = ALL_MASK & ~X_MASK; } /* ---------------------------------------------------------------------- */ From 47b918499f76dcdf6387191f5a52edf3e234c8c0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 Oct 2024 18:09:06 -0400 Subject: [PATCH 42/43] silence compiler warnings, remove dead code --- src/QEQ/fix_qeq_ctip.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/QEQ/fix_qeq_ctip.cpp b/src/QEQ/fix_qeq_ctip.cpp index 0649c47412..889e0f5ebd 100644 --- a/src/QEQ/fix_qeq_ctip.cpp +++ b/src/QEQ/fix_qeq_ctip.cpp @@ -241,11 +241,9 @@ void FixQEqCTIP::init_matvec() double r = cutoff; double rsq = r*r; - double r6 = rsq*rsq*rsq; double erfcd_cut = exp(-cdamp * cdamp * rsq); double t_cut = 1.0 / (1.0 + EWALD_P * cdamp * r); - double erfcc_cut = (t_cut * (A1 + t_cut * (A2 + t_cut * (A3 + t_cut * (A4 + t_cut * A5)))) * erfcd_cut) / r; inum = list->inum; ilist = list->ilist; @@ -285,9 +283,8 @@ void FixQEqCTIP::compute_H() int inum, jnum, *ilist, *jlist, *numneigh, **firstneigh; int i, j, ii, jj; double dx, dy, dz, r_sqr, r, reff; - double cutoffsq, cutoffcu, cutoff4, cdampcu, erfcc_cut, erfcd_cut, t_cut; + double cutoffsq, erfcd_cut, t_cut; double erfcc, erfcd, t; - int elt1, elt2; double **x = atom->x; int *mask = atom->mask; @@ -299,14 +296,8 @@ void FixQEqCTIP::compute_H() firstneigh = list->firstneigh; cutoffsq = cutoff * cutoff; - cutoffcu = cutoffsq * cutoff; - cutoff4 = cutoffsq * cutoffsq; - cdampcu = cdamp * cdamp * cdamp; - erfcd_cut = exp(-cdamp * cdamp * cutoffsq); t_cut = 1.0 / (1.0 + EWALD_P * cdamp * cutoff); - erfcc_cut = t_cut * (A1 + t_cut * (A2 + t_cut * (A3 + t_cut * (A4 + t_cut * A5)))) * erfcd_cut; - // fill in the H matrix m_fill = 0; From 70cbf051fe3b546d6c28c9188816f5420a758d80 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 Oct 2024 19:41:59 -0400 Subject: [PATCH 43/43] apply clang-format --- src/fix.h | 18 +++++++++--------- src/fix_balance.h | 8 ++++---- src/fix_bond_history.h | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/fix.h b/src/fix.h index 594fbb51bf..7609caf5fe 100644 --- a/src/fix.h +++ b/src/fix.h @@ -216,17 +216,17 @@ class Fix : protected Pointers { virtual int pack_reverse_comm(int, int, double *) { return 0; } virtual void unpack_reverse_comm(int, int *, double *) {} - virtual void reset_grid(){}; + virtual void reset_grid() {}; - virtual void pack_forward_grid(int, void *, int, int *){}; - virtual void unpack_forward_grid(int, void *, int, int *){}; - virtual void pack_reverse_grid(int, void *, int, int *){}; - virtual void unpack_reverse_grid(int, void *, int, int *){}; - virtual void pack_remap_grid(int, void *, int, int *){}; - virtual void unpack_remap_grid(int, void *, int, int *){}; + virtual void pack_forward_grid(int, void *, int, int *) {}; + virtual void unpack_forward_grid(int, void *, int, int *) {}; + virtual void pack_reverse_grid(int, void *, int, int *) {}; + virtual void unpack_reverse_grid(int, void *, int, int *) {}; + virtual void pack_remap_grid(int, void *, int, int *) {}; + virtual void unpack_remap_grid(int, void *, int, int *) {}; virtual int unpack_read_grid(int, char *) { return 0; }; - virtual void pack_write_grid(int, void *){}; - virtual void unpack_write_grid(int, void *, int *){}; + virtual void pack_write_grid(int, void *) {}; + virtual void unpack_write_grid(int, void *, int *) {}; virtual int get_grid_by_name(const std::string &, int &) { return -1; }; virtual void *get_grid_by_index(int) { return nullptr; }; diff --git a/src/fix_balance.h b/src/fix_balance.h index a319710ac6..1d53451946 100644 --- a/src/fix_balance.h +++ b/src/fix_balance.h @@ -43,9 +43,9 @@ class FixBalance : public Fix { int nevery, lbstyle, nitermax; double thresh, stopthresh; 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 + 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 @@ -53,7 +53,7 @@ class FixBalance : public Fix { double maxloadperproc; // max load on any processor int itercount; // iteration count of last call to Balance int pending; - bigint lastbalance; // last timestep balancing was attempted + bigint lastbalance; // last timestep balancing was attempted class Balance *balance; class Irregular *irregular; diff --git a/src/fix_bond_history.h b/src/fix_bond_history.h index 377685ea84..7e8c998b72 100644 --- a/src/fix_bond_history.h +++ b/src/fix_bond_history.h @@ -62,7 +62,7 @@ class FixBondHistory : public Fix { // to enable quick look up std::map, std::vector> cached_histories; - int *setflag; // Set by BondBPM, which bond types are used + int *setflag; // Set by BondBPM, which bond types are used double **bondstore; int stored_flag; int ndata;