From ea9c1002fed3261274eeac0769b165a2f27fcea2 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 11 Oct 2019 17:51:19 -0600 Subject: [PATCH 01/91] Created placeholders for ComputeGrid and ComputeSNAGrid classes --- src/compute_grid.cpp | 186 ++++++++++++++++++++++++++ src/compute_grid.h | 69 ++++++++++ src/compute_sna_grid.cpp | 277 +++++++++++++++++++++++++++++++++++++++ src/compute_sna_grid.h | 75 +++++++++++ 4 files changed, 607 insertions(+) create mode 100644 src/compute_grid.cpp create mode 100644 src/compute_grid.h create mode 100644 src/compute_sna_grid.cpp create mode 100644 src/compute_sna_grid.h diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp new file mode 100644 index 0000000000..c67d72160b --- /dev/null +++ b/src/compute_grid.cpp @@ -0,0 +1,186 @@ +/* ---------------------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#include "compute_grid.h" +#include +#include +#include "atom.h" +#include "update.h" +#include "modify.h" +#include "domain.h" +#include "memory.h" +#include "error.h" + +using namespace LAMMPS_NS; + +enum{ONCE,NFREQ,EVERY}; + +/* ---------------------------------------------------------------------- */ + +ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : + Compute(lmp, narg, arg), + idchunk(NULL), masstotal(NULL), massproc(NULL), com(NULL), comall(NULL) +{ + if (narg != 4) error->all(FLERR,"Illegal compute com/chunk command"); + + array_flag = 1; + size_array_cols = 3; + size_array_rows = 0; + size_array_rows_variable = 1; + extarray = 0; + + // ID of compute chunk/atom + + int n = strlen(arg[3]) + 1; + idchunk = new char[n]; + strcpy(idchunk,arg[3]); + + init(); + + // chunk-based data + + nchunk = 1; + maxchunk = 0; + allocate(); + + firstflag = massneed = 1; +} + +/* ---------------------------------------------------------------------- */ + +ComputeGrid::~ComputeGrid() +{ + delete [] idchunk; + memory->destroy(massproc); + memory->destroy(masstotal); + memory->destroy(com); + memory->destroy(comall); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeGrid::init() +{ + int icompute = modify->find_compute(idchunk); + if (icompute < 0) + error->all(FLERR,"Chunk/atom compute does not exist for compute com/chunk"); + cchunk = (ComputeChunkAtom *) modify->compute[icompute]; + if (strcmp(cchunk->style,"chunk/atom") != 0) + error->all(FLERR,"Compute com/chunk does not use chunk/atom compute"); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeGrid::setup() +{ + // one-time calculation of per-chunk mass + // done in setup, so that ComputeChunkAtom::setup() is already called + + if (firstflag && cchunk->idsflag == ONCE) { + compute_array(); + firstflag = massneed = 0; + } +} + +/* ---------------------------------------------------------------------- */ + +void ComputeGrid::compute_array() +{ + int index; + double massone; + double unwrap[3]; + + invoked_array = update->ntimestep; + + // compute chunk/atom assigns atoms to chunk IDs + // extract ichunk index vector from compute + // ichunk = 1 to Nchunk for included atoms, 0 for excluded atoms + + nchunk = cchunk->setup_chunks(); + cchunk->compute_ichunk(); + int *ichunk = cchunk->ichunk; + + if (nchunk > maxchunk) allocate(); + size_array_rows = nchunk; + + // zero local per-chunk values + + for (int i = 0; i < nchunk; i++) + com[i][0] = com[i][1] = com[i][2] = 0.0; + if (massneed) + for (int i = 0; i < nchunk; i++) massproc[i] = 0.0; + + // compute COM for each chunk + + double **x = atom->x; + int *mask = atom->mask; + int *type = atom->type; + imageint *image = atom->image; + double *mass = atom->mass; + double *rmass = atom->rmass; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + index = ichunk[i]-1; + if (index < 0) continue; + if (rmass) massone = rmass[i]; + else massone = mass[type[i]]; + domain->unmap(x[i],image[i],unwrap); + com[index][0] += unwrap[0] * massone; + com[index][1] += unwrap[1] * massone; + com[index][2] += unwrap[2] * massone; + if (massneed) massproc[index] += massone; + } + + MPI_Allreduce(&com[0][0],&comall[0][0],3*nchunk,MPI_DOUBLE,MPI_SUM,world); + if (massneed) + MPI_Allreduce(massproc,masstotal,nchunk,MPI_DOUBLE,MPI_SUM,world); + + for (int i = 0; i < nchunk; i++) { + if (masstotal[i] > 0.0) { + comall[i][0] /= masstotal[i]; + comall[i][1] /= masstotal[i]; + comall[i][2] /= masstotal[i]; + } else comall[i][0] = comall[i][1] = comall[i][2] = 0.0; + } +} + +/* ---------------------------------------------------------------------- + free and reallocate per-chunk arrays +------------------------------------------------------------------------- */ + +void ComputeGrid::allocate() +{ + memory->destroy(massproc); + memory->destroy(masstotal); + memory->destroy(com); + memory->destroy(comall); + maxchunk = nchunk; + memory->create(massproc,maxchunk,"com/chunk:massproc"); + memory->create(masstotal,maxchunk,"com/chunk:masstotal"); + memory->create(com,maxchunk,3,"com/chunk:com"); + memory->create(comall,maxchunk,3,"com/chunk:comall"); + array = comall; +} + +/* ---------------------------------------------------------------------- + memory usage of local data +------------------------------------------------------------------------- */ + +double ComputeGrid::memory_usage() +{ + double bytes = (bigint) maxchunk * 2 * sizeof(double); + bytes += (bigint) maxchunk * 2*3 * sizeof(double); + return bytes; +} diff --git a/src/compute_grid.h b/src/compute_grid.h new file mode 100644 index 0000000000..cece7050de --- /dev/null +++ b/src/compute_grid.h @@ -0,0 +1,69 @@ +/* -*- 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 COMPUTE_CLASS + +ComputeStyle(grid,ComputeGrid) + +#else + +#ifndef LMP_COMPUTE_GRID_H +#define LMP_COMPUTE_GRID_H + +#include "compute.h" + +namespace LAMMPS_NS { + +class ComputeGrid : public Compute { + public: + char *idchunk; // fields accessed by other classes + double *masstotal; + + ComputeGrid(class LAMMPS *, int, char **); + ~ComputeGrid(); + void init(); + void setup(); + void compute_array(); + + void lock_enable(); + void lock_disable(); + int lock_length(); + void lock(class Fix *, bigint, bigint); + void unlock(class Fix *); + + double memory_usage(); + + private: + int nchunk,maxchunk; + int firstflag,massneed; + + double *massproc; + double **com,**comall; + + void allocate(); +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +*/ diff --git a/src/compute_sna_grid.cpp b/src/compute_sna_grid.cpp new file mode 100644 index 0000000000..58f7e9fc38 --- /dev/null +++ b/src/compute_sna_grid.cpp @@ -0,0 +1,277 @@ +/* ---------------------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#include "compute_sna_grid.h" +#include +#include +#include "sna.h" +#include "atom.h" +#include "update.h" +#include "modify.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "force.h" +#include "pair.h" +#include "comm.h" +#include "memory.h" +#include "error.h" + +using namespace LAMMPS_NS; + +ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : + Compute(lmp, narg, arg), cutsq(NULL), list(NULL), sna(NULL), + radelem(NULL), wjelem(NULL) +{ + double rmin0, rfac0; + int twojmax, switchflag, bzeroflag; + radelem = NULL; + wjelem = NULL; + + int ntypes = atom->ntypes; + int nargmin = 6+2*ntypes; + + if (narg < nargmin) error->all(FLERR,"Illegal compute sna/grid command"); + + // default values + + rmin0 = 0.0; + switchflag = 1; + bzeroflag = 1; + quadraticflag = 0; + + // offset by 1 to match up with types + + memory->create(radelem,ntypes+1,"sna/grid:radelem"); + memory->create(wjelem,ntypes+1,"sna/grid:wjelem"); + + rcutfac = atof(arg[3]); + rfac0 = atof(arg[4]); + twojmax = atoi(arg[5]); + + for(int i = 0; i < ntypes; i++) + radelem[i+1] = atof(arg[6+i]); + for(int i = 0; i < ntypes; i++) + wjelem[i+1] = atof(arg[6+ntypes+i]); + + // construct cutsq + + double cut; + cutmax = 0.0; + memory->create(cutsq,ntypes+1,ntypes+1,"sna/grid:cutsq"); + for(int i = 1; i <= ntypes; i++) { + cut = 2.0*radelem[i]*rcutfac; + if (cut > cutmax) cutmax = cut; + cutsq[i][i] = cut*cut; + for(int j = i+1; j <= ntypes; j++) { + cut = (radelem[i]+radelem[j])*rcutfac; + cutsq[i][j] = cutsq[j][i] = cut*cut; + } + } + + // process optional args + + int iarg = nargmin; + + while (iarg < narg) { + if (strcmp(arg[iarg],"rmin0") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid command"); + rmin0 = atof(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"switchflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid command"); + switchflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"bzeroflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid command"); + bzeroflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"quadraticflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid command"); + quadraticflag = atoi(arg[iarg+1]); + iarg += 2; + } else error->all(FLERR,"Illegal compute sna/grid command"); + } + + snaptr = new SNA(lmp,rfac0,twojmax, + rmin0,switchflag,bzeroflag); + + ncoeff = snaptr->ncoeff; + size_peratom_cols = ncoeff; + if (quadraticflag) size_peratom_cols += (ncoeff*(ncoeff+1))/2; + peratom_flag = 1; + + nmax = 0; + sna = NULL; +} + +/* ---------------------------------------------------------------------- */ + +ComputeSNAGrid::~ComputeSNAGrid() +{ + memory->destroy(sna); + memory->destroy(radelem); + memory->destroy(wjelem); + memory->destroy(cutsq); + delete snaptr; +} + +/* ---------------------------------------------------------------------- */ + +void ComputeSNAGrid::init() +{ + if (force->pair == NULL) + error->all(FLERR,"Compute sna/grid requires a pair style be defined"); + + if (cutmax > force->pair->cutforce) + error->all(FLERR,"Compute sna/grid cutoff is longer than pairwise cutoff"); + + // need an occasional full neighbor list + + int irequest = neighbor->request(this,instance_me); + neighbor->requests[irequest]->pair = 0; + neighbor->requests[irequest]->compute = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->occasional = 1; + + int count = 0; + for (int i = 0; i < modify->ncompute; i++) + if (strcmp(modify->compute[i]->style,"sna/grid") == 0) count++; + if (count > 1 && comm->me == 0) + error->warning(FLERR,"More than one compute sna/grid"); + snaptr->init(); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeSNAGrid::init_list(int /*id*/, NeighList *ptr) +{ + list = ptr; +} + +/* ---------------------------------------------------------------------- */ + +void ComputeSNAGrid::compute_pergrid() +{ + invoked_peratom = update->ntimestep; + + // grow sna array if necessary + + if (atom->nmax > nmax) { + memory->destroy(sna); + nmax = atom->nmax; + memory->create(sna,nmax,size_peratom_cols,"sna/grid:sna"); + array_atom = sna; + } + + // invoke full neighbor list (will copy or build if necessary) + + neighbor->build_one(list); + + const int inum = list->inum; + const int* const ilist = list->ilist; + const int* const numneigh = list->numneigh; + int** const firstneigh = list->firstneigh; + int * const type = atom->type; + + // compute sna for each atom in group + // use full neighbor list to count atoms less than cutoff + + double** const x = atom->x; + const int* const mask = atom->mask; + + for (int ii = 0; ii < inum; ii++) { + const int i = ilist[ii]; + if (mask[i] & groupbit) { + + const double xtmp = x[i][0]; + const double ytmp = x[i][1]; + const double ztmp = x[i][2]; + const int itype = type[i]; + const double radi = radelem[itype]; + const int* const jlist = firstneigh[i]; + const int jnum = numneigh[i]; + + // insure rij, inside, and typej are of size jnum + + snaptr->grow_rij(jnum); + + // rij[][3] = displacements between atom I and those neighbors + // inside = indices of neighbors of I within cutoff + // typej = types of neighbors of I within cutoff + + int ninside = 0; + for (int jj = 0; jj < jnum; jj++) { + int j = jlist[jj]; + j &= NEIGHMASK; + + const double delx = xtmp - x[j][0]; + const double dely = ytmp - x[j][1]; + const double delz = ztmp - x[j][2]; + const double rsq = delx*delx + dely*dely + delz*delz; + int jtype = type[j]; + if (rsq < cutsq[itype][jtype] && rsq>1e-20) { + snaptr->rij[ninside][0] = delx; + snaptr->rij[ninside][1] = dely; + snaptr->rij[ninside][2] = delz; + snaptr->inside[ninside] = j; + snaptr->wj[ninside] = wjelem[jtype]; + snaptr->rcutij[ninside] = (radi+radelem[jtype])*rcutfac; + ninside++; + } + } + + snaptr->compute_ui(ninside); + snaptr->compute_zi(); + snaptr->compute_bi(); + for (int icoeff = 0; icoeff < ncoeff; icoeff++) + sna[i][icoeff] = snaptr->blist[icoeff]; + if (quadraticflag) { + int ncount = ncoeff; + for (int icoeff = 0; icoeff < ncoeff; icoeff++) { + double bi = snaptr->blist[icoeff]; + + // diagonal element of quadratic matrix + + sna[i][ncount++] = 0.5*bi*bi; + + // upper-triangular elements of quadratic matrix + + for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) + sna[i][ncount++] = bi*snaptr->blist[jcoeff]; + } + } + } else { + for (int icoeff = 0; icoeff < size_peratom_cols; icoeff++) + sna[i][icoeff] = 0.0; + } + } +} + +/* ---------------------------------------------------------------------- + memory usage +------------------------------------------------------------------------- */ + +double ComputeSNAGrid::memory_usage() +{ + double bytes = nmax*size_peratom_cols * sizeof(double); // sna + bytes += snaptr->memory_usage(); // SNA object + + return bytes; +} + diff --git a/src/compute_sna_grid.h b/src/compute_sna_grid.h new file mode 100644 index 0000000000..f85d9679cc --- /dev/null +++ b/src/compute_sna_grid.h @@ -0,0 +1,75 @@ +/* -*- 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 COMPUTE_CLASS + +ComputeStyle(sna/grid,ComputeSNAGrid) + +#else + +#ifndef LMP_COMPUTE_SNA_GRID_H +#define LMP_COMPUTE_SNA_GRID_H + +#include "compute.h" + +namespace LAMMPS_NS { + +class ComputeSNAGrid : public Compute { + public: + ComputeSNAGrid(class LAMMPS *, int, char **); + ~ComputeSNAGrid(); + void init(); + void init_list(int, class NeighList *); + void compute_grid(); + double memory_usage(); + + private: + int nmax; + int ncoeff; + double **cutsq; + class NeighList *list; + double **sna; + double rcutfac; + double *radelem; + double *wjelem; + class SNA* snaptr; + double cutmax; + int quadraticflag; +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +E: Compute sna/grid requires a pair style be defined + +Self-explanatory. + +E: Compute sna/grid cutoff is longer than pairwise cutoff + +Self-explanatory. + +W: More than one compute sna/grid + +Self-explanatory. + +*/ From 762ecf8f0e5bb8fb146bb7ef42bd80e9a4e7f9e1 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Sat, 19 Oct 2019 17:03:19 -0600 Subject: [PATCH 02/91] Completed serial version with PBC, but incorrect --- src/compute_grid.cpp | 255 +++++++++++++++++++++++---------------- src/compute_grid.h | 45 ++++--- src/compute_sna_grid.cpp | 166 +++++++++++++------------ src/compute_sna_grid.h | 8 +- 4 files changed, 266 insertions(+), 208 deletions(-) diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index c67d72160b..d8c7eb3697 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -18,169 +18,218 @@ #include "update.h" #include "modify.h" #include "domain.h" +#include "force.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; -enum{ONCE,NFREQ,EVERY}; - /* ---------------------------------------------------------------------- */ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - idchunk(NULL), masstotal(NULL), massproc(NULL), com(NULL), comall(NULL) + Compute(lmp, narg, arg) { - if (narg != 4) error->all(FLERR,"Illegal compute com/chunk command"); + if (narg < 6) error->all(FLERR,"Illegal compute grid command"); array_flag = 1; - size_array_cols = 3; + size_array_cols = 0; size_array_rows = 0; - size_array_rows_variable = 1; - extarray = 0; + extarray = 1; - // ID of compute chunk/atom + int iarg0 = 3; + int iarg = iarg0; + if (strcmp(arg[iarg],"grid") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal compute grid command"); + nx = force->inumeric(FLERR,arg[iarg+1]); + ny = force->inumeric(FLERR,arg[iarg+2]); + nz = force->inumeric(FLERR,arg[iarg+3]); + if (nx <= 0 || ny <= 0 || nz <= 0) + error->all(FLERR,"All grid dimensions must be positive"); + iarg += 4; + } else error->all(FLERR,"Illegal compute grid command"); - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + nargbase = iarg - iarg0; - init(); - - // chunk-based data - - nchunk = 1; - maxchunk = 0; - allocate(); - - firstflag = massneed = 1; + size_array_rows = nx*ny*nz; } /* ---------------------------------------------------------------------- */ ComputeGrid::~ComputeGrid() { - delete [] idchunk; - memory->destroy(massproc); - memory->destroy(masstotal); - memory->destroy(com); - memory->destroy(comall); } /* ---------------------------------------------------------------------- */ void ComputeGrid::init() { - int icompute = modify->find_compute(idchunk); - if (icompute < 0) - error->all(FLERR,"Chunk/atom compute does not exist for compute com/chunk"); - cchunk = (ComputeChunkAtom *) modify->compute[icompute]; - if (strcmp(cchunk->style,"chunk/atom") != 0) - error->all(FLERR,"Compute com/chunk does not use chunk/atom compute"); } /* ---------------------------------------------------------------------- */ void ComputeGrid::setup() { - // one-time calculation of per-chunk mass - // done in setup, so that ComputeChunkAtom::setup() is already called + + // calculate grid layout - if (firstflag && cchunk->idsflag == ONCE) { - compute_array(); - firstflag = massneed = 0; + triclinic = domain->triclinic; + + if (triclinic == 0) { + prd = domain->prd; + boxlo = domain->boxlo; + } else { + prd = domain->prd_lamda; + boxlo = domain->boxlo_lamda; } + + double xprd = prd[0]; + double yprd = prd[1]; + double zprd = prd[2]; + + delxinv = nx/xprd; + delyinv = ny/yprd; + delzinv = nz/zprd; + + delx = 1.0/delxinv; + dely = 1.0/delyinv; + delz = 1.0/delzinv; + + // sufficient conditions for stencil bounding rcut + + // require |delz*mz|^2 <= rcut^2 + // require |dely*my|^2 <= rcut^2 + |delyz*mz_max|^2 + // require |delx*mx|^2 <= rcut^2 + |delxz*mz_max|^2 + |delxy*my_max|^2 + + double delxy = domain->xy/ny; + double delxz = domain->xz/nz; + double delyz = domain->yz/nz; + + if (!triclinic) { + mz = cutmax*delzinv + 1; + my = sqrt(cutmax*cutmax + pow(delyz*mz,2))*delyinv + 1; + mx = sqrt(cutmax*cutmax + pow(delxz*mz,2) + + pow(delxy*my,2))*delxinv + 1; + } else { + double delxinvtmp = nx/domain->xprd; + double delyinvtmp = ny/domain->yprd; + double delzinvtmp = nz/domain->zprd; + mz = cutmax*delzinvtmp + 1; + my = sqrt(cutmax*cutmax + pow(delyz*mz,2))*delyinvtmp + 1; + mx = sqrt(cutmax*cutmax + pow(delxz*mz,2) + + pow(delxy*my,2))*delxinvtmp + 1; + } + + printf("mx = %d\n",mx); + printf("my = %d\n",my); + printf("mz = %d\n",mz); + + // size global grid to accomodate periodic interactions + + nxfull = nx + 2*mx; + nyfull = ny + 2*my; + nzfull = nz + 2*mz; + nxyfull = nxfull * nyfull; + + printf("nxfull = %d\n",nxfull); + printf("nyfull = %d\n",nyfull); + printf("nzfull = %d\n",nzfull); + + x0full = boxlo[0] - mx*delx; + y0full = boxlo[1] - my*dely; + z0full = boxlo[2] - mz*delz; + + allocate(); } -/* ---------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + convert grid index to box coords +------------------------------------------------------------------------- */ -void ComputeGrid::compute_array() +void ComputeGrid::igridfull2x(int igrid, double *x) { - int index; - double massone; - double unwrap[3]; + int iz = igrid / nxyfull; + igrid -= iz*nxyfull; + int iy = igrid / nxfull; + igrid -= igrid*nxfull; + int ix = igrid; - invoked_array = update->ntimestep; + x[0] = x0full+ix*delx; + x[1] = y0full+iy*dely; + x[2] = z0full+iz*delz; - // compute chunk/atom assigns atoms to chunk IDs - // extract ichunk index vector from compute - // ichunk = 1 to Nchunk for included atoms, 0 for excluded atoms + if (triclinic) domain->lamda2x(x, x); - nchunk = cchunk->setup_chunks(); - cchunk->compute_ichunk(); - int *ichunk = cchunk->ichunk; +} - if (nchunk > maxchunk) allocate(); - size_array_rows = nchunk; +/* ---------------------------------------------------------------------- + gather global array from full grid +------------------------------------------------------------------------- */ - // zero local per-chunk values +void ComputeGrid::gather_global_array() +{ + int iarray; + memset(&array[0][0],0,size_array_rows*size_array_cols*sizeof(double)); - for (int i = 0; i < nchunk; i++) - com[i][0] = com[i][1] = com[i][2] = 0.0; - if (massneed) - for (int i = 0; i < nchunk; i++) massproc[i] = 0.0; + for (int igrid = 0; igrid < ngridfull; igrid++) { - // compute COM for each chunk + // inefficient, should exploit shared ix structure - double **x = atom->x; - int *mask = atom->mask; - int *type = atom->type; - imageint *image = atom->image; - double *mass = atom->mass; - double *rmass = atom->rmass; - int nlocal = atom->nlocal; - - for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit) { - index = ichunk[i]-1; - if (index < 0) continue; - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - domain->unmap(x[i],image[i],unwrap); - com[index][0] += unwrap[0] * massone; - com[index][1] += unwrap[1] * massone; - com[index][2] += unwrap[2] * massone; - if (massneed) massproc[index] += massone; - } - - MPI_Allreduce(&com[0][0],&comall[0][0],3*nchunk,MPI_DOUBLE,MPI_SUM,world); - if (massneed) - MPI_Allreduce(massproc,masstotal,nchunk,MPI_DOUBLE,MPI_SUM,world); - - for (int i = 0; i < nchunk; i++) { - if (masstotal[i] > 0.0) { - comall[i][0] /= masstotal[i]; - comall[i][1] /= masstotal[i]; - comall[i][2] /= masstotal[i]; - } else comall[i][0] = comall[i][1] = comall[i][2] = 0.0; + iarray = igridfull2iarray(igrid); + for (int icol = 0; icol < size_array_cols; icol++) + array[iarray][icol] += gridfull[igrid][icol]; } } /* ---------------------------------------------------------------------- - free and reallocate per-chunk arrays + convert full grid index to compute array index + inefficient, should exploit shared ix structure +------------------------------------------------------------------------- */ + +int ComputeGrid::igridfull2iarray(int igrid) +{ + int iz = igrid / nxyfull; + igrid -= iz*nxyfull; + int iy = igrid / nxfull; + igrid -= igrid*nxfull; + int ix = igrid; + + ix -= mx; + iy -= my; + iz -= mz; + + while (ix < 0) ix += nx; + while (iy < 0) iy += ny; + while (iz < 0) iz += nz; + + while (ix >= nx) ix -= nx; + while (iy >= ny) iy -= ny; + while (iz >= nz) iz -= nz; + + int iarray = (iz * ny + iy) * nx + ix; + + return iarray; +} + +/* ---------------------------------------------------------------------- + free and reallocate arrays ------------------------------------------------------------------------- */ void ComputeGrid::allocate() { - memory->destroy(massproc); - memory->destroy(masstotal); - memory->destroy(com); - memory->destroy(comall); - maxchunk = nchunk; - memory->create(massproc,maxchunk,"com/chunk:massproc"); - memory->create(masstotal,maxchunk,"com/chunk:masstotal"); - memory->create(com,maxchunk,3,"com/chunk:com"); - memory->create(comall,maxchunk,3,"com/chunk:comall"); - array = comall; -} + ngridfull = nxfull*nyfull*nzfull; + // grow global array if necessary + + memory->destroy(array); + memory->create(array,size_array_rows,size_array_cols,"sna/grid:array"); + memory->create(gridfull,ngridfull,size_array_cols,"sna/grid:gridfull"); +} /* ---------------------------------------------------------------------- memory usage of local data ------------------------------------------------------------------------- */ double ComputeGrid::memory_usage() { - double bytes = (bigint) maxchunk * 2 * sizeof(double); - bytes += (bigint) maxchunk * 2*3 * sizeof(double); - return bytes; + int nbytes = 0; + return nbytes; } diff --git a/src/compute_grid.h b/src/compute_grid.h index cece7050de..61775186ff 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -11,12 +11,6 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#ifdef COMPUTE_CLASS - -ComputeStyle(grid,ComputeGrid) - -#else - #ifndef LMP_COMPUTE_GRID_H #define LMP_COMPUTE_GRID_H @@ -26,36 +20,39 @@ namespace LAMMPS_NS { class ComputeGrid : public Compute { public: - char *idchunk; // fields accessed by other classes - double *masstotal; ComputeGrid(class LAMMPS *, int, char **); - ~ComputeGrid(); + virtual ~ComputeGrid(); void init(); void setup(); - void compute_array(); - - void lock_enable(); - void lock_disable(); - int lock_length(); - void lock(class Fix *, bigint, bigint); - void unlock(class Fix *); + virtual void compute_array() = 0; double memory_usage(); + protected: + int nx, ny, nz; // grid dimensions + int nxfull, nyfull, nzfull; // grid dimensions with ghost points + int nxyfull; // nx_full*ny_full + int ngridfull; // number of full grid points + double **gridfull; // full grid points + int mx, my, mz; // cutmax stencil dimensions + int triclinic; // triclinic flag + double *boxlo, *prd; // box info (units real/ortho or reduced/tri) + double delxinv,delyinv,delzinv; // inverse grid spacing + double delx,dely,delz; // grid spacing + double x0full, y0full, z0full; // origin of full grid + int nargbase; // number of base class args + double cutmax; // largest cutoff distance + virtual void allocate(); + void igridfull2x(int, double*); // convert full grid point to coord + void gather_global_array(); // gather global array from full grid + int igridfull2iarray(int); // convert full grid index to compute array index + private: - int nchunk,maxchunk; - int firstflag,massneed; - - double *massproc; - double **com,**comall; - - void allocate(); }; } -#endif #endif /* ERROR/WARNING messages: diff --git a/src/compute_sna_grid.cpp b/src/compute_sna_grid.cpp index 58f7e9fc38..1f998ced9b 100644 --- a/src/compute_sna_grid.cpp +++ b/src/compute_sna_grid.cpp @@ -11,6 +11,7 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +#include "compute_grid.h" #include "compute_sna_grid.h" #include #include @@ -30,7 +31,7 @@ using namespace LAMMPS_NS; ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), cutsq(NULL), list(NULL), sna(NULL), + ComputeGrid(lmp, narg, arg), cutsq(NULL), list(NULL), sna(NULL), radelem(NULL), wjelem(NULL) { double rmin0, rfac0; @@ -38,6 +39,13 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : radelem = NULL; wjelem = NULL; + // skip over arguments used by base class + // so that argument positions are identical to + // regular per-atom compute + + arg += nargbase; + narg -= nargbase; + int ntypes = atom->ntypes; int nargmin = 6+2*ntypes; @@ -58,6 +66,7 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : rcutfac = atof(arg[3]); rfac0 = atof(arg[4]); twojmax = atoi(arg[5]); + printf("rcutfac = %g rfac0 = %g twojmax = %d\n",rcutfac, rfac0, twojmax); for(int i = 0; i < ntypes; i++) radelem[i+1] = atof(arg[6+i]); @@ -73,6 +82,7 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : cut = 2.0*radelem[i]*rcutfac; if (cut > cutmax) cutmax = cut; cutsq[i][i] = cut*cut; + printf("i = %d cutsq[i][i] = %g\n",i,cutsq[i][i]); for(int j = i+1; j <= ntypes; j++) { cut = (radelem[i]+radelem[j])*rcutfac; cutsq[i][j] = cutsq[j][i] = cut*cut; @@ -84,6 +94,7 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : int iarg = nargmin; while (iarg < narg) { + printf("iarg = %d arg = %s\n",iarg, arg[iarg]); if (strcmp(arg[iarg],"rmin0") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal compute sna/grid command"); @@ -105,18 +116,19 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : quadraticflag = atoi(arg[iarg+1]); iarg += 2; } else error->all(FLERR,"Illegal compute sna/grid command"); + } + printf("rmin0 = %g, bzeroflag = %d, quadraticflag = %d\n", + rmin0, bzeroflag, quadraticflag); + snaptr = new SNA(lmp,rfac0,twojmax, rmin0,switchflag,bzeroflag); ncoeff = snaptr->ncoeff; - size_peratom_cols = ncoeff; - if (quadraticflag) size_peratom_cols += (ncoeff*(ncoeff+1))/2; - peratom_flag = 1; - - nmax = 0; - sna = NULL; + size_array_cols = ncoeff; + if (quadraticflag) size_array_cols += (ncoeff*(ncoeff+1))/2; + array_flag = 1; } /* ---------------------------------------------------------------------- */ @@ -166,101 +178,101 @@ void ComputeSNAGrid::init_list(int /*id*/, NeighList *ptr) /* ---------------------------------------------------------------------- */ -void ComputeSNAGrid::compute_pergrid() +void ComputeSNAGrid::compute_array() { - invoked_peratom = update->ntimestep; + invoked_array = update->ntimestep; - // grow sna array if necessary +// // invoke full neighbor list (will copy or build if necessary) - if (atom->nmax > nmax) { - memory->destroy(sna); - nmax = atom->nmax; - memory->create(sna,nmax,size_peratom_cols,"sna/grid:sna"); - array_atom = sna; - } +// neighbor->build_one(list); - // invoke full neighbor list (will copy or build if necessary) +// const int inum = list->inum; +// const int* const ilist = list->ilist; +// const int* const numneigh = list->numneigh; +// int** const firstneigh = list->firstneigh; - neighbor->build_one(list); - - const int inum = list->inum; - const int* const ilist = list->ilist; - const int* const numneigh = list->numneigh; - int** const firstneigh = list->firstneigh; int * const type = atom->type; - // compute sna for each atom in group - // use full neighbor list to count atoms less than cutoff + // compute sna for each gridpoint double** const x = atom->x; const int* const mask = atom->mask; + const int ntotal = atom->nlocal + atom->nghost; - for (int ii = 0; ii < inum; ii++) { - const int i = ilist[ii]; - if (mask[i] & groupbit) { + printf("ngridfull = %d\n",ngridfull); + for (int igrid = 0; igrid < ngridfull; igrid++) { + printf("igrid = %d\n",igrid); + double rtmp[3]; + igridfull2x(igrid, rtmp); + const double xtmp = rtmp[0]; + const double ytmp = rtmp[1]; + const double ztmp = rtmp[2]; - const double xtmp = x[i][0]; - const double ytmp = x[i][1]; - const double ztmp = x[i][2]; - const int itype = type[i]; - const double radi = radelem[itype]; - const int* const jlist = firstneigh[i]; - const int jnum = numneigh[i]; + // rij[][3] = displacements between atom I and those neighbors + // inside = indices of neighbors of I within cutoff + // typej = types of neighbors of I within cutoff - // insure rij, inside, and typej are of size jnum + int ninside = 0; + for (int j = 0; j < ntotal; j++) { - snaptr->grow_rij(jnum); + // check that j is in comute group - // rij[][3] = displacements between atom I and those neighbors - // inside = indices of neighbors of I within cutoff - // typej = types of neighbors of I within cutoff + if (!(mask[j] & groupbit)) continue; - int ninside = 0; - for (int jj = 0; jj < jnum; jj++) { - int j = jlist[jj]; - j &= NEIGHMASK; + // insure rij, inside, and typej are of size jnum - const double delx = xtmp - x[j][0]; - const double dely = ytmp - x[j][1]; - const double delz = ztmp - x[j][2]; - const double rsq = delx*delx + dely*dely + delz*delz; - int jtype = type[j]; - if (rsq < cutsq[itype][jtype] && rsq>1e-20) { - snaptr->rij[ninside][0] = delx; - snaptr->rij[ninside][1] = dely; - snaptr->rij[ninside][2] = delz; - snaptr->inside[ninside] = j; - snaptr->wj[ninside] = wjelem[jtype]; - snaptr->rcutij[ninside] = (radi+radelem[jtype])*rcutfac; - ninside++; - } + snaptr->grow_rij(ninside+1); + + const double delx = xtmp - x[j][0]; + const double dely = ytmp - x[j][1]; + const double delz = ztmp - x[j][2]; + const double rsq = delx*delx + dely*dely + delz*delz; + int jtype = type[j]; + if (rsq < cutsq[jtype][jtype] && rsq>1e-20) { + printf("ninside = %d\n",ninside); + snaptr->rij[ninside][0] = delx; + snaptr->rij[ninside][1] = dely; + snaptr->rij[ninside][2] = delz; + snaptr->inside[ninside] = j; + snaptr->wj[ninside] = wjelem[jtype]; + snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; + ninside++; } + } - snaptr->compute_ui(ninside); - snaptr->compute_zi(); - snaptr->compute_bi(); - for (int icoeff = 0; icoeff < ncoeff; icoeff++) - sna[i][icoeff] = snaptr->blist[icoeff]; - if (quadraticflag) { - int ncount = ncoeff; - for (int icoeff = 0; icoeff < ncoeff; icoeff++) { - double bi = snaptr->blist[icoeff]; + snaptr->compute_ui(ninside); + snaptr->compute_zi(); + snaptr->compute_bi(); + for (int icoeff = 0; icoeff < ncoeff; icoeff++) + sna[igrid][icoeff] = snaptr->blist[icoeff]; + printf("igrid = %d B0 = %g\n",igrid,sna[igrid][0]); + if (quadraticflag) { + int ncount = ncoeff; + for (int icoeff = 0; icoeff < ncoeff; icoeff++) { + double bi = snaptr->blist[icoeff]; - // diagonal element of quadratic matrix + // diagonal element of quadratic matrix - sna[i][ncount++] = 0.5*bi*bi; + sna[igrid][ncount++] = 0.5*bi*bi; - // upper-triangular elements of quadratic matrix + // upper-triangular elements of quadratic matrix - for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - sna[i][ncount++] = bi*snaptr->blist[jcoeff]; - } + for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) + sna[igrid][ncount++] = bi*snaptr->blist[jcoeff]; } - } else { - for (int icoeff = 0; icoeff < size_peratom_cols; icoeff++) - sna[i][icoeff] = 0.0; } } + gather_global_array(); +} + +/* ---------------------------------------------------------------------- + allocate array in base class and then set up pointers +------------------------------------------------------------------------- */ + +void ComputeSNAGrid::allocate() +{ + ComputeGrid::allocate(); + sna = gridfull; } /* ---------------------------------------------------------------------- @@ -269,7 +281,7 @@ void ComputeSNAGrid::compute_pergrid() double ComputeSNAGrid::memory_usage() { - double bytes = nmax*size_peratom_cols * sizeof(double); // sna + double bytes = size_array_rows*size_array_cols * sizeof(double); // grid bytes += snaptr->memory_usage(); // SNA object return bytes; diff --git a/src/compute_sna_grid.h b/src/compute_sna_grid.h index f85d9679cc..2bd18a915e 100644 --- a/src/compute_sna_grid.h +++ b/src/compute_sna_grid.h @@ -20,18 +20,19 @@ ComputeStyle(sna/grid,ComputeSNAGrid) #ifndef LMP_COMPUTE_SNA_GRID_H #define LMP_COMPUTE_SNA_GRID_H -#include "compute.h" +#include "compute_grid.h" namespace LAMMPS_NS { -class ComputeSNAGrid : public Compute { +class ComputeSNAGrid : public ComputeGrid { public: ComputeSNAGrid(class LAMMPS *, int, char **); ~ComputeSNAGrid(); void init(); void init_list(int, class NeighList *); - void compute_grid(); + void compute_array(); double memory_usage(); + void allocate(); private: int nmax; @@ -43,7 +44,6 @@ class ComputeSNAGrid : public Compute { double *radelem; double *wjelem; class SNA* snaptr; - double cutmax; int quadraticflag; }; From 8374280383487f86c1f69f437501e1a77c253e60 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 23 Oct 2019 18:46:28 -0600 Subject: [PATCH 03/91] Got a first pass working for ortho and tri grids --- examples/snap/in.grid | 71 +++++++++++++++++ examples/snap/in.grid.tri | 116 ++++++++++++++++++++++++++++ src/{ => SNAP}/compute_sna_grid.cpp | 0 src/{ => SNAP}/compute_sna_grid.h | 0 src/compute_grid.cpp | 56 ++++++++++---- src/compute_grid.h | 2 + 6 files changed, 231 insertions(+), 14 deletions(-) create mode 100644 examples/snap/in.grid create mode 100644 examples/snap/in.grid.tri rename src/{ => SNAP}/compute_sna_grid.cpp (100%) rename src/{ => SNAP}/compute_sna_grid.h (100%) diff --git a/examples/snap/in.grid b/examples/snap/in.grid new file mode 100644 index 0000000000..bec57dc9ff --- /dev/null +++ b/examples/snap/in.grid @@ -0,0 +1,71 @@ +# Demonstrate bispectrum computes + +# Initialize simulation + +variable nsteps index 0 +variable nrep index 1 +variable a index 3.316 +variable ngrid index 2 + +units metal + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice custom $a & + a1 1 0 0 & + a2 0 1 0 & + a3 0 0 1 & + basis 0 0 0 & + basis 0.5 0.5 0.5 & +# origin 0.25 0.25 0.25 + +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 180.88 + +# choose potential + +include Ta06A.snap + +# define grid compute and atom compute + +group snapgroup type 1 +variable twojmax equal 2 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quad equal 0 +variable switch equal 0 + +compute b all sna/atom & + ${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & + quadraticflag ${quad} switchflag ${switch} + +compute mygrid all sna/grid grid ${ngrid} ${ngrid} ${ngrid} & + ${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & + quadraticflag ${quad} switchflag ${switch} + +# define output + +thermo_style custom step temp ke pe vol c_mygrid[1][1] c_mygrid[2][1] c_mygrid[3][1] c_mygrid[4][1] c_mygrid[5][1] c_mygrid[6][1] c_mygrid[7][1] c_mygrid[8][1] +thermo_modify norm yes + +dump mydump_b all custom 1000 dump_b id c_b[*] + +# run + +run 0 + diff --git a/examples/snap/in.grid.tri b/examples/snap/in.grid.tri new file mode 100644 index 0000000000..c02138f66a --- /dev/null +++ b/examples/snap/in.grid.tri @@ -0,0 +1,116 @@ +# Demonstrate bispectrum computes + +# Initialize simulation + +variable nsteps index 0 +variable nrep index 1 +variable a index 3.316 +variable ngrid index 4 + +variable ngridx equal 3*${ngrid} +variable ngridy equal 2*${ngrid} +variable ngridz equal 1*${ngrid} + +units metal + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice custom $a & + a1 1 0 0 & + a2 1 1 0 & + a3 1 1 1 & + basis 0 0 0 & + basis 0.0 0.0 0.5 & +# origin 0.25 0.25 0.25 + +box tilt large +region box prism 0 ${nx} 0 ${ny} 0 ${nz} ${ny} ${nz} ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 180.88 + +# choose potential + +include Ta06A.snap + +# define grid compute and atom compute + +group snapgroup type 1 +variable twojmax equal 2 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quad equal 0 +variable switch equal 0 + +compute b all sna/atom & + ${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & + quadraticflag ${quad} switchflag ${switch} + +compute mygrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} & + ${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & + quadraticflag ${quad} switchflag ${switch} + +# define output + +thermo_style custom step temp ke pe vol & + c_mygrid[1][1] c_mygrid[2][1] c_mygrid[3][1] c_mygrid[4][1] c_mygrid[5][1] c_mygrid[6][1] c_mygrid[7][1] c_mygrid[8][1] c_mygrid[9][1] & + c_mygrid[10][1] c_mygrid[11][1] c_mygrid[12][1] c_mygrid[13][1] c_mygrid[14][1] c_mygrid[15][1] c_mygrid[16][1] c_mygrid[17][1] c_mygrid[18][1] c_mygrid[19][1] & + c_mygrid[20][1] c_mygrid[21][1] c_mygrid[22][1] c_mygrid[23][1] c_mygrid[24][1] c_mygrid[25][1] c_mygrid[26][1] c_mygrid[27][1] c_mygrid[28][1] c_mygrid[29][1] & + c_mygrid[30][1] c_mygrid[31][1] c_mygrid[32][1] c_mygrid[33][1] c_mygrid[34][1] c_mygrid[35][1] c_mygrid[36][1] c_mygrid[37][1] c_mygrid[38][1] c_mygrid[39][1] & + c_mygrid[40][1] c_mygrid[41][1] c_mygrid[42][1] c_mygrid[43][1] c_mygrid[44][1] c_mygrid[45][1] c_mygrid[46][1] c_mygrid[47][1] c_mygrid[48][1] c_mygrid[49][1] & + c_mygrid[50][1] c_mygrid[51][1] c_mygrid[52][1] c_mygrid[53][1] c_mygrid[54][1] c_mygrid[55][1] c_mygrid[56][1] c_mygrid[57][1] c_mygrid[58][1] c_mygrid[59][1] & + c_mygrid[60][1] c_mygrid[61][1] c_mygrid[62][1] c_mygrid[63][1] c_mygrid[64][1] c_mygrid[65][1] c_mygrid[66][1] c_mygrid[67][1] c_mygrid[68][1] c_mygrid[69][1] & + c_mygrid[70][1] c_mygrid[71][1] c_mygrid[72][1] c_mygrid[73][1] c_mygrid[74][1] c_mygrid[75][1] c_mygrid[76][1] c_mygrid[77][1] c_mygrid[78][1] c_mygrid[79][1] & + c_mygrid[80][1] c_mygrid[81][1] c_mygrid[82][1] c_mygrid[83][1] c_mygrid[84][1] c_mygrid[85][1] c_mygrid[86][1] c_mygrid[87][1] c_mygrid[88][1] c_mygrid[89][1] & + c_mygrid[90][1] c_mygrid[91][1] c_mygrid[92][1] c_mygrid[93][1] c_mygrid[94][1] c_mygrid[95][1] c_mygrid[96][1] c_mygrid[97][1] c_mygrid[98][1] c_mygrid[99][1] & + c_mygrid[101][1] c_mygrid[102][1] c_mygrid[103][1] c_mygrid[104][1] c_mygrid[105][1] c_mygrid[106][1] c_mygrid[107][1] c_mygrid[108][1] c_mygrid[109][1] & + c_mygrid[110][1] c_mygrid[111][1] c_mygrid[112][1] c_mygrid[113][1] c_mygrid[114][1] c_mygrid[115][1] c_mygrid[116][1] c_mygrid[117][1] c_mygrid[118][1] c_mygrid[119][1] & + c_mygrid[120][1] c_mygrid[121][1] c_mygrid[122][1] c_mygrid[123][1] c_mygrid[124][1] c_mygrid[125][1] c_mygrid[126][1] c_mygrid[127][1] c_mygrid[128][1] c_mygrid[129][1] & + c_mygrid[130][1] c_mygrid[131][1] c_mygrid[132][1] c_mygrid[133][1] c_mygrid[134][1] c_mygrid[135][1] c_mygrid[136][1] c_mygrid[137][1] c_mygrid[138][1] c_mygrid[139][1] & + c_mygrid[140][1] c_mygrid[141][1] c_mygrid[142][1] c_mygrid[143][1] c_mygrid[144][1] c_mygrid[145][1] c_mygrid[146][1] c_mygrid[147][1] c_mygrid[148][1] c_mygrid[149][1] & + c_mygrid[150][1] c_mygrid[151][1] c_mygrid[152][1] c_mygrid[153][1] c_mygrid[154][1] c_mygrid[155][1] c_mygrid[156][1] c_mygrid[157][1] c_mygrid[158][1] c_mygrid[159][1] & + c_mygrid[160][1] c_mygrid[161][1] c_mygrid[162][1] c_mygrid[163][1] c_mygrid[164][1] c_mygrid[165][1] c_mygrid[166][1] c_mygrid[167][1] c_mygrid[168][1] c_mygrid[169][1] & + c_mygrid[170][1] c_mygrid[171][1] c_mygrid[172][1] c_mygrid[173][1] c_mygrid[174][1] c_mygrid[175][1] c_mygrid[176][1] c_mygrid[177][1] c_mygrid[178][1] c_mygrid[179][1] & + c_mygrid[180][1] c_mygrid[181][1] c_mygrid[182][1] c_mygrid[183][1] c_mygrid[184][1] c_mygrid[185][1] c_mygrid[186][1] c_mygrid[187][1] c_mygrid[188][1] c_mygrid[189][1] & + c_mygrid[190][1] c_mygrid[191][1] c_mygrid[192][1] c_mygrid[193][1] c_mygrid[194][1] c_mygrid[195][1] c_mygrid[196][1] c_mygrid[197][1] c_mygrid[198][1] c_mygrid[199][1] & + c_mygrid[201][1] c_mygrid[202][1] c_mygrid[203][1] c_mygrid[204][1] c_mygrid[205][1] c_mygrid[206][1] c_mygrid[207][1] c_mygrid[208][1] c_mygrid[209][1] & + c_mygrid[210][1] c_mygrid[211][1] c_mygrid[212][1] c_mygrid[213][1] c_mygrid[214][1] c_mygrid[215][1] c_mygrid[216][1] c_mygrid[217][1] c_mygrid[218][1] c_mygrid[219][1] & + c_mygrid[220][1] c_mygrid[221][1] c_mygrid[222][1] c_mygrid[223][1] c_mygrid[224][1] c_mygrid[225][1] c_mygrid[226][1] c_mygrid[227][1] c_mygrid[228][1] c_mygrid[229][1] & + c_mygrid[230][1] c_mygrid[231][1] c_mygrid[232][1] c_mygrid[233][1] c_mygrid[234][1] c_mygrid[235][1] c_mygrid[236][1] c_mygrid[237][1] c_mygrid[238][1] c_mygrid[239][1] & + c_mygrid[240][1] c_mygrid[241][1] c_mygrid[242][1] c_mygrid[243][1] c_mygrid[244][1] c_mygrid[245][1] c_mygrid[246][1] c_mygrid[247][1] c_mygrid[248][1] c_mygrid[249][1] & + c_mygrid[250][1] c_mygrid[251][1] c_mygrid[252][1] c_mygrid[253][1] c_mygrid[254][1] c_mygrid[255][1] c_mygrid[256][1] c_mygrid[257][1] c_mygrid[258][1] c_mygrid[259][1] & + c_mygrid[260][1] c_mygrid[261][1] c_mygrid[262][1] c_mygrid[263][1] c_mygrid[264][1] c_mygrid[265][1] c_mygrid[266][1] c_mygrid[267][1] c_mygrid[268][1] c_mygrid[269][1] & + c_mygrid[270][1] c_mygrid[271][1] c_mygrid[272][1] c_mygrid[273][1] c_mygrid[274][1] c_mygrid[275][1] c_mygrid[276][1] c_mygrid[277][1] c_mygrid[278][1] c_mygrid[279][1] & + c_mygrid[280][1] c_mygrid[281][1] c_mygrid[282][1] c_mygrid[283][1] c_mygrid[284][1] c_mygrid[285][1] c_mygrid[286][1] c_mygrid[287][1] c_mygrid[288][1] c_mygrid[289][1] & + c_mygrid[290][1] c_mygrid[291][1] c_mygrid[292][1] c_mygrid[293][1] c_mygrid[294][1] c_mygrid[295][1] c_mygrid[296][1] c_mygrid[297][1] c_mygrid[298][1] c_mygrid[299][1] & + c_mygrid[301][1] c_mygrid[302][1] c_mygrid[303][1] c_mygrid[304][1] c_mygrid[305][1] c_mygrid[306][1] c_mygrid[307][1] c_mygrid[308][1] c_mygrid[309][1] & + c_mygrid[310][1] c_mygrid[311][1] c_mygrid[312][1] c_mygrid[313][1] c_mygrid[314][1] c_mygrid[315][1] c_mygrid[316][1] c_mygrid[317][1] c_mygrid[318][1] c_mygrid[319][1] & + c_mygrid[320][1] c_mygrid[321][1] c_mygrid[322][1] c_mygrid[323][1] c_mygrid[324][1] c_mygrid[325][1] c_mygrid[326][1] c_mygrid[327][1] c_mygrid[328][1] c_mygrid[329][1] & + c_mygrid[330][1] c_mygrid[331][1] c_mygrid[332][1] c_mygrid[333][1] c_mygrid[334][1] c_mygrid[335][1] c_mygrid[336][1] c_mygrid[337][1] c_mygrid[338][1] c_mygrid[339][1] & + c_mygrid[340][1] c_mygrid[341][1] c_mygrid[342][1] c_mygrid[343][1] c_mygrid[344][1] c_mygrid[345][1] c_mygrid[346][1] c_mygrid[347][1] c_mygrid[348][1] c_mygrid[349][1] & + c_mygrid[350][1] c_mygrid[351][1] c_mygrid[352][1] c_mygrid[353][1] c_mygrid[354][1] c_mygrid[355][1] c_mygrid[356][1] c_mygrid[357][1] c_mygrid[358][1] c_mygrid[359][1] & + c_mygrid[360][1] c_mygrid[361][1] c_mygrid[362][1] c_mygrid[363][1] c_mygrid[364][1] c_mygrid[365][1] c_mygrid[366][1] c_mygrid[367][1] c_mygrid[368][1] c_mygrid[369][1] & + c_mygrid[370][1] c_mygrid[371][1] c_mygrid[372][1] c_mygrid[373][1] c_mygrid[374][1] c_mygrid[375][1] c_mygrid[376][1] c_mygrid[377][1] c_mygrid[378][1] c_mygrid[379][1] & + c_mygrid[380][1] c_mygrid[381][1] c_mygrid[382][1] c_mygrid[383][1] c_mygrid[384][1] + +thermo_modify norm yes + +dump mydump_b all custom 1000 dump_b id c_b[*] + +# run + +run 0 + diff --git a/src/compute_sna_grid.cpp b/src/SNAP/compute_sna_grid.cpp similarity index 100% rename from src/compute_sna_grid.cpp rename to src/SNAP/compute_sna_grid.cpp diff --git a/src/compute_sna_grid.h b/src/SNAP/compute_sna_grid.h similarity index 100% rename from src/compute_sna_grid.h rename to src/SNAP/compute_sna_grid.h diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index d8c7eb3697..ec969fd01f 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -34,7 +34,7 @@ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : array_flag = 1; size_array_cols = 0; size_array_rows = 0; - extarray = 1; + extarray = 0; int iarg0 = 3; int iarg = iarg0; @@ -119,10 +119,6 @@ void ComputeGrid::setup() + pow(delxy*my,2))*delxinvtmp + 1; } - printf("mx = %d\n",mx); - printf("my = %d\n",my); - printf("mz = %d\n",mz); - // size global grid to accomodate periodic interactions nxfull = nx + 2*mx; @@ -130,10 +126,6 @@ void ComputeGrid::setup() nzfull = nz + 2*mz; nxyfull = nxfull * nyfull; - printf("nxfull = %d\n",nxfull); - printf("nyfull = %d\n",nyfull); - printf("nzfull = %d\n",nzfull); - x0full = boxlo[0] - mx*delx; y0full = boxlo[1] - my*dely; z0full = boxlo[2] - mz*delz; @@ -148,9 +140,9 @@ void ComputeGrid::setup() void ComputeGrid::igridfull2x(int igrid, double *x) { int iz = igrid / nxyfull; - igrid -= iz*nxyfull; + igrid -= iz * nxyfull; int iy = igrid / nxfull; - igrid -= igrid*nxfull; + igrid -= iy * nxfull; int ix = igrid; x[0] = x0full+ix*delx; @@ -161,14 +153,28 @@ void ComputeGrid::igridfull2x(int igrid, double *x) } +/* ---------------------------------------------------------------------- + copy local grid to global array +------------------------------------------------------------------------- */ + +void ComputeGrid::copy_local_grid() +{ + int igridfull; + for (int iarray = 0; iarray < size_array_rows; iarray++) { + igridfull = iarray2igridfull(iarray); + for (int icol = 0; icol < size_array_cols; icol++) + array[iarray][icol] = gridfull[igridfull][icol]; + } +} + /* ---------------------------------------------------------------------- gather global array from full grid ------------------------------------------------------------------------- */ void ComputeGrid::gather_global_array() { - int iarray; - memset(&array[0][0],0,size_array_rows*size_array_cols*sizeof(double)); + int iarray; + memset(&array[0][0],0,size_array_rows*size_array_cols*sizeof(double)); for (int igrid = 0; igrid < ngridfull; igrid++) { @@ -190,7 +196,7 @@ int ComputeGrid::igridfull2iarray(int igrid) int iz = igrid / nxyfull; igrid -= iz*nxyfull; int iy = igrid / nxfull; - igrid -= igrid*nxfull; + igrid -= iy*nxfull; int ix = igrid; ix -= mx; @@ -210,6 +216,28 @@ int ComputeGrid::igridfull2iarray(int igrid) return iarray; } +/* ---------------------------------------------------------------------- + convert compute array index to full grid index + inefficient, should exploit shared ix structure +------------------------------------------------------------------------- */ + +int ComputeGrid::iarray2igridfull(int iarray) +{ + int iz = iarray / (nx*ny); + iarray -= iz*(nx*ny); + int iy = iarray / nx; + iarray -= iy*nx; + int ix = iarray; + + ix += mx; + iy += my; + iz += mz; + + int igrid = (iz * nyfull + iy) * nxfull + ix; + + return igrid; +} + /* ---------------------------------------------------------------------- free and reallocate arrays ------------------------------------------------------------------------- */ diff --git a/src/compute_grid.h b/src/compute_grid.h index 61775186ff..bc757c37bc 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -46,7 +46,9 @@ class ComputeGrid : public Compute { virtual void allocate(); void igridfull2x(int, double*); // convert full grid point to coord void gather_global_array(); // gather global array from full grid + void copy_local_grid(); // copy local grid to global array int igridfull2iarray(int); // convert full grid index to compute array index + int iarray2igridfull(int); // convert compute array index to full grid index private: }; From 0fc325c98b2b4ffd8fb24cd53ce732221add6ac0 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 23 Oct 2019 18:56:21 -0600 Subject: [PATCH 04/91] Got a first pass working for ortho and tri grids --- src/SNAP/compute_sna_grid.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/SNAP/compute_sna_grid.cpp b/src/SNAP/compute_sna_grid.cpp index 1f998ced9b..26bd272d9f 100644 --- a/src/SNAP/compute_sna_grid.cpp +++ b/src/SNAP/compute_sna_grid.cpp @@ -66,7 +66,6 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : rcutfac = atof(arg[3]); rfac0 = atof(arg[4]); twojmax = atoi(arg[5]); - printf("rcutfac = %g rfac0 = %g twojmax = %d\n",rcutfac, rfac0, twojmax); for(int i = 0; i < ntypes; i++) radelem[i+1] = atof(arg[6+i]); @@ -82,7 +81,6 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : cut = 2.0*radelem[i]*rcutfac; if (cut > cutmax) cutmax = cut; cutsq[i][i] = cut*cut; - printf("i = %d cutsq[i][i] = %g\n",i,cutsq[i][i]); for(int j = i+1; j <= ntypes; j++) { cut = (radelem[i]+radelem[j])*rcutfac; cutsq[i][j] = cutsq[j][i] = cut*cut; @@ -94,7 +92,6 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : int iarg = nargmin; while (iarg < narg) { - printf("iarg = %d arg = %s\n",iarg, arg[iarg]); if (strcmp(arg[iarg],"rmin0") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal compute sna/grid command"); @@ -119,9 +116,6 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : } - printf("rmin0 = %g, bzeroflag = %d, quadraticflag = %d\n", - rmin0, bzeroflag, quadraticflag); - snaptr = new SNA(lmp,rfac0,twojmax, rmin0,switchflag,bzeroflag); @@ -199,9 +193,12 @@ void ComputeSNAGrid::compute_array() const int* const mask = atom->mask; const int ntotal = atom->nlocal + atom->nghost; + // insure rij, inside, and typej are of size jnum + + snaptr->grow_rij(ntotal); + printf("ngridfull = %d\n",ngridfull); for (int igrid = 0; igrid < ngridfull; igrid++) { - printf("igrid = %d\n",igrid); double rtmp[3]; igridfull2x(igrid, rtmp); const double xtmp = rtmp[0]; @@ -215,21 +212,17 @@ void ComputeSNAGrid::compute_array() int ninside = 0; for (int j = 0; j < ntotal; j++) { - // check that j is in comute group + // check that j is in compute group if (!(mask[j] & groupbit)) continue; - // insure rij, inside, and typej are of size jnum - - snaptr->grow_rij(ninside+1); - const double delx = xtmp - x[j][0]; const double dely = ytmp - x[j][1]; const double delz = ztmp - x[j][2]; const double rsq = delx*delx + dely*dely + delz*delz; int jtype = type[j]; if (rsq < cutsq[jtype][jtype] && rsq>1e-20) { - printf("ninside = %d\n",ninside); + // printf("ninside = %d\n",ninside); snaptr->rij[ninside][0] = delx; snaptr->rij[ninside][1] = dely; snaptr->rij[ninside][2] = delz; @@ -245,7 +238,7 @@ void ComputeSNAGrid::compute_array() snaptr->compute_bi(); for (int icoeff = 0; icoeff < ncoeff; icoeff++) sna[igrid][icoeff] = snaptr->blist[icoeff]; - printf("igrid = %d B0 = %g\n",igrid,sna[igrid][0]); + // printf("igrid = %d %g %g %g %d B0 = %g\n",igrid,xtmp,ytmp,ztmp,ninside,sna[igrid][0]); if (quadraticflag) { int ncount = ncoeff; for (int icoeff = 0; icoeff < ncoeff; icoeff++) { @@ -262,7 +255,8 @@ void ComputeSNAGrid::compute_array() } } } - gather_global_array(); + // gather_global_array(); + copy_local_grid(); } /* ---------------------------------------------------------------------- From 5956908cfd2bbd097be8126cc4f062d5cc9cc519 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 23 Oct 2019 21:51:36 -0600 Subject: [PATCH 05/91] Added cols for coords --- examples/snap/in.grid | 6 ++- examples/snap/in.grid.tri | 78 +++++++++++++++++------------------ src/SNAP/compute_sna_grid.cpp | 6 +-- src/compute_grid.cpp | 41 +++++++++++++++++- src/compute_grid.h | 5 ++- 5 files changed, 90 insertions(+), 46 deletions(-) diff --git a/examples/snap/in.grid b/examples/snap/in.grid index bec57dc9ff..5293558fab 100644 --- a/examples/snap/in.grid +++ b/examples/snap/in.grid @@ -60,7 +60,11 @@ compute mygrid all sna/grid grid ${ngrid} ${ngrid} ${ngrid} & # define output -thermo_style custom step temp ke pe vol c_mygrid[1][1] c_mygrid[2][1] c_mygrid[3][1] c_mygrid[4][1] c_mygrid[5][1] c_mygrid[6][1] c_mygrid[7][1] c_mygrid[8][1] +thermo_style custom step temp ke pe vol & + c_mygrid[1][1] c_mygrid[2][1] c_mygrid[3][1] c_mygrid[4][1] c_mygrid[5][1] c_mygrid[6][1] c_mygrid[7][1] c_mygrid[8][1] & + c_mygrid[1][2] c_mygrid[2][2] c_mygrid[3][2] c_mygrid[4][2] c_mygrid[5][2] c_mygrid[6][2] c_mygrid[7][2] c_mygrid[8][2] & + c_mygrid[1][3] c_mygrid[2][3] c_mygrid[3][3] c_mygrid[4][3] c_mygrid[5][3] c_mygrid[6][3] c_mygrid[7][3] c_mygrid[8][3] & + c_mygrid[1][4] c_mygrid[2][4] c_mygrid[3][4] c_mygrid[4][4] c_mygrid[5][4] c_mygrid[6][4] c_mygrid[7][4] c_mygrid[8][4] thermo_modify norm yes dump mydump_b all custom 1000 dump_b id c_b[*] diff --git a/examples/snap/in.grid.tri b/examples/snap/in.grid.tri index c02138f66a..3c471d9b66 100644 --- a/examples/snap/in.grid.tri +++ b/examples/snap/in.grid.tri @@ -66,45 +66,45 @@ compute mygrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} & # define output thermo_style custom step temp ke pe vol & - c_mygrid[1][1] c_mygrid[2][1] c_mygrid[3][1] c_mygrid[4][1] c_mygrid[5][1] c_mygrid[6][1] c_mygrid[7][1] c_mygrid[8][1] c_mygrid[9][1] & - c_mygrid[10][1] c_mygrid[11][1] c_mygrid[12][1] c_mygrid[13][1] c_mygrid[14][1] c_mygrid[15][1] c_mygrid[16][1] c_mygrid[17][1] c_mygrid[18][1] c_mygrid[19][1] & - c_mygrid[20][1] c_mygrid[21][1] c_mygrid[22][1] c_mygrid[23][1] c_mygrid[24][1] c_mygrid[25][1] c_mygrid[26][1] c_mygrid[27][1] c_mygrid[28][1] c_mygrid[29][1] & - c_mygrid[30][1] c_mygrid[31][1] c_mygrid[32][1] c_mygrid[33][1] c_mygrid[34][1] c_mygrid[35][1] c_mygrid[36][1] c_mygrid[37][1] c_mygrid[38][1] c_mygrid[39][1] & - c_mygrid[40][1] c_mygrid[41][1] c_mygrid[42][1] c_mygrid[43][1] c_mygrid[44][1] c_mygrid[45][1] c_mygrid[46][1] c_mygrid[47][1] c_mygrid[48][1] c_mygrid[49][1] & - c_mygrid[50][1] c_mygrid[51][1] c_mygrid[52][1] c_mygrid[53][1] c_mygrid[54][1] c_mygrid[55][1] c_mygrid[56][1] c_mygrid[57][1] c_mygrid[58][1] c_mygrid[59][1] & - c_mygrid[60][1] c_mygrid[61][1] c_mygrid[62][1] c_mygrid[63][1] c_mygrid[64][1] c_mygrid[65][1] c_mygrid[66][1] c_mygrid[67][1] c_mygrid[68][1] c_mygrid[69][1] & - c_mygrid[70][1] c_mygrid[71][1] c_mygrid[72][1] c_mygrid[73][1] c_mygrid[74][1] c_mygrid[75][1] c_mygrid[76][1] c_mygrid[77][1] c_mygrid[78][1] c_mygrid[79][1] & - c_mygrid[80][1] c_mygrid[81][1] c_mygrid[82][1] c_mygrid[83][1] c_mygrid[84][1] c_mygrid[85][1] c_mygrid[86][1] c_mygrid[87][1] c_mygrid[88][1] c_mygrid[89][1] & - c_mygrid[90][1] c_mygrid[91][1] c_mygrid[92][1] c_mygrid[93][1] c_mygrid[94][1] c_mygrid[95][1] c_mygrid[96][1] c_mygrid[97][1] c_mygrid[98][1] c_mygrid[99][1] & - c_mygrid[101][1] c_mygrid[102][1] c_mygrid[103][1] c_mygrid[104][1] c_mygrid[105][1] c_mygrid[106][1] c_mygrid[107][1] c_mygrid[108][1] c_mygrid[109][1] & - c_mygrid[110][1] c_mygrid[111][1] c_mygrid[112][1] c_mygrid[113][1] c_mygrid[114][1] c_mygrid[115][1] c_mygrid[116][1] c_mygrid[117][1] c_mygrid[118][1] c_mygrid[119][1] & - c_mygrid[120][1] c_mygrid[121][1] c_mygrid[122][1] c_mygrid[123][1] c_mygrid[124][1] c_mygrid[125][1] c_mygrid[126][1] c_mygrid[127][1] c_mygrid[128][1] c_mygrid[129][1] & - c_mygrid[130][1] c_mygrid[131][1] c_mygrid[132][1] c_mygrid[133][1] c_mygrid[134][1] c_mygrid[135][1] c_mygrid[136][1] c_mygrid[137][1] c_mygrid[138][1] c_mygrid[139][1] & - c_mygrid[140][1] c_mygrid[141][1] c_mygrid[142][1] c_mygrid[143][1] c_mygrid[144][1] c_mygrid[145][1] c_mygrid[146][1] c_mygrid[147][1] c_mygrid[148][1] c_mygrid[149][1] & - c_mygrid[150][1] c_mygrid[151][1] c_mygrid[152][1] c_mygrid[153][1] c_mygrid[154][1] c_mygrid[155][1] c_mygrid[156][1] c_mygrid[157][1] c_mygrid[158][1] c_mygrid[159][1] & - c_mygrid[160][1] c_mygrid[161][1] c_mygrid[162][1] c_mygrid[163][1] c_mygrid[164][1] c_mygrid[165][1] c_mygrid[166][1] c_mygrid[167][1] c_mygrid[168][1] c_mygrid[169][1] & - c_mygrid[170][1] c_mygrid[171][1] c_mygrid[172][1] c_mygrid[173][1] c_mygrid[174][1] c_mygrid[175][1] c_mygrid[176][1] c_mygrid[177][1] c_mygrid[178][1] c_mygrid[179][1] & - c_mygrid[180][1] c_mygrid[181][1] c_mygrid[182][1] c_mygrid[183][1] c_mygrid[184][1] c_mygrid[185][1] c_mygrid[186][1] c_mygrid[187][1] c_mygrid[188][1] c_mygrid[189][1] & - c_mygrid[190][1] c_mygrid[191][1] c_mygrid[192][1] c_mygrid[193][1] c_mygrid[194][1] c_mygrid[195][1] c_mygrid[196][1] c_mygrid[197][1] c_mygrid[198][1] c_mygrid[199][1] & - c_mygrid[201][1] c_mygrid[202][1] c_mygrid[203][1] c_mygrid[204][1] c_mygrid[205][1] c_mygrid[206][1] c_mygrid[207][1] c_mygrid[208][1] c_mygrid[209][1] & - c_mygrid[210][1] c_mygrid[211][1] c_mygrid[212][1] c_mygrid[213][1] c_mygrid[214][1] c_mygrid[215][1] c_mygrid[216][1] c_mygrid[217][1] c_mygrid[218][1] c_mygrid[219][1] & - c_mygrid[220][1] c_mygrid[221][1] c_mygrid[222][1] c_mygrid[223][1] c_mygrid[224][1] c_mygrid[225][1] c_mygrid[226][1] c_mygrid[227][1] c_mygrid[228][1] c_mygrid[229][1] & - c_mygrid[230][1] c_mygrid[231][1] c_mygrid[232][1] c_mygrid[233][1] c_mygrid[234][1] c_mygrid[235][1] c_mygrid[236][1] c_mygrid[237][1] c_mygrid[238][1] c_mygrid[239][1] & - c_mygrid[240][1] c_mygrid[241][1] c_mygrid[242][1] c_mygrid[243][1] c_mygrid[244][1] c_mygrid[245][1] c_mygrid[246][1] c_mygrid[247][1] c_mygrid[248][1] c_mygrid[249][1] & - c_mygrid[250][1] c_mygrid[251][1] c_mygrid[252][1] c_mygrid[253][1] c_mygrid[254][1] c_mygrid[255][1] c_mygrid[256][1] c_mygrid[257][1] c_mygrid[258][1] c_mygrid[259][1] & - c_mygrid[260][1] c_mygrid[261][1] c_mygrid[262][1] c_mygrid[263][1] c_mygrid[264][1] c_mygrid[265][1] c_mygrid[266][1] c_mygrid[267][1] c_mygrid[268][1] c_mygrid[269][1] & - c_mygrid[270][1] c_mygrid[271][1] c_mygrid[272][1] c_mygrid[273][1] c_mygrid[274][1] c_mygrid[275][1] c_mygrid[276][1] c_mygrid[277][1] c_mygrid[278][1] c_mygrid[279][1] & - c_mygrid[280][1] c_mygrid[281][1] c_mygrid[282][1] c_mygrid[283][1] c_mygrid[284][1] c_mygrid[285][1] c_mygrid[286][1] c_mygrid[287][1] c_mygrid[288][1] c_mygrid[289][1] & - c_mygrid[290][1] c_mygrid[291][1] c_mygrid[292][1] c_mygrid[293][1] c_mygrid[294][1] c_mygrid[295][1] c_mygrid[296][1] c_mygrid[297][1] c_mygrid[298][1] c_mygrid[299][1] & - c_mygrid[301][1] c_mygrid[302][1] c_mygrid[303][1] c_mygrid[304][1] c_mygrid[305][1] c_mygrid[306][1] c_mygrid[307][1] c_mygrid[308][1] c_mygrid[309][1] & - c_mygrid[310][1] c_mygrid[311][1] c_mygrid[312][1] c_mygrid[313][1] c_mygrid[314][1] c_mygrid[315][1] c_mygrid[316][1] c_mygrid[317][1] c_mygrid[318][1] c_mygrid[319][1] & - c_mygrid[320][1] c_mygrid[321][1] c_mygrid[322][1] c_mygrid[323][1] c_mygrid[324][1] c_mygrid[325][1] c_mygrid[326][1] c_mygrid[327][1] c_mygrid[328][1] c_mygrid[329][1] & - c_mygrid[330][1] c_mygrid[331][1] c_mygrid[332][1] c_mygrid[333][1] c_mygrid[334][1] c_mygrid[335][1] c_mygrid[336][1] c_mygrid[337][1] c_mygrid[338][1] c_mygrid[339][1] & - c_mygrid[340][1] c_mygrid[341][1] c_mygrid[342][1] c_mygrid[343][1] c_mygrid[344][1] c_mygrid[345][1] c_mygrid[346][1] c_mygrid[347][1] c_mygrid[348][1] c_mygrid[349][1] & - c_mygrid[350][1] c_mygrid[351][1] c_mygrid[352][1] c_mygrid[353][1] c_mygrid[354][1] c_mygrid[355][1] c_mygrid[356][1] c_mygrid[357][1] c_mygrid[358][1] c_mygrid[359][1] & - c_mygrid[360][1] c_mygrid[361][1] c_mygrid[362][1] c_mygrid[363][1] c_mygrid[364][1] c_mygrid[365][1] c_mygrid[366][1] c_mygrid[367][1] c_mygrid[368][1] c_mygrid[369][1] & - c_mygrid[370][1] c_mygrid[371][1] c_mygrid[372][1] c_mygrid[373][1] c_mygrid[374][1] c_mygrid[375][1] c_mygrid[376][1] c_mygrid[377][1] c_mygrid[378][1] c_mygrid[379][1] & - c_mygrid[380][1] c_mygrid[381][1] c_mygrid[382][1] c_mygrid[383][1] c_mygrid[384][1] + c_mygrid[1][4] c_mygrid[2][4] c_mygrid[3][4] c_mygrid[4][4] c_mygrid[5][4] c_mygrid[6][4] c_mygrid[7][4] c_mygrid[8][4] c_mygrid[9][4] & + c_mygrid[10][4] c_mygrid[11][4] c_mygrid[12][4] c_mygrid[13][4] c_mygrid[14][4] c_mygrid[15][4] c_mygrid[16][4] c_mygrid[17][4] c_mygrid[18][4] c_mygrid[19][4] & + c_mygrid[20][4] c_mygrid[21][4] c_mygrid[22][4] c_mygrid[23][4] c_mygrid[24][4] c_mygrid[25][4] c_mygrid[26][4] c_mygrid[27][4] c_mygrid[28][4] c_mygrid[29][4] & + c_mygrid[30][4] c_mygrid[31][4] c_mygrid[32][4] c_mygrid[33][4] c_mygrid[34][4] c_mygrid[35][4] c_mygrid[36][4] c_mygrid[37][4] c_mygrid[38][4] c_mygrid[39][4] & + c_mygrid[40][4] c_mygrid[41][4] c_mygrid[42][4] c_mygrid[43][4] c_mygrid[44][4] c_mygrid[45][4] c_mygrid[46][4] c_mygrid[47][4] c_mygrid[48][4] c_mygrid[49][4] & + c_mygrid[50][4] c_mygrid[51][4] c_mygrid[52][4] c_mygrid[53][4] c_mygrid[54][4] c_mygrid[55][4] c_mygrid[56][4] c_mygrid[57][4] c_mygrid[58][4] c_mygrid[59][4] & + c_mygrid[60][4] c_mygrid[61][4] c_mygrid[62][4] c_mygrid[63][4] c_mygrid[64][4] c_mygrid[65][4] c_mygrid[66][4] c_mygrid[67][4] c_mygrid[68][4] c_mygrid[69][4] & + c_mygrid[70][4] c_mygrid[71][4] c_mygrid[72][4] c_mygrid[73][4] c_mygrid[74][4] c_mygrid[75][4] c_mygrid[76][4] c_mygrid[77][4] c_mygrid[78][4] c_mygrid[79][4] & + c_mygrid[80][4] c_mygrid[81][4] c_mygrid[82][4] c_mygrid[83][4] c_mygrid[84][4] c_mygrid[85][4] c_mygrid[86][4] c_mygrid[87][4] c_mygrid[88][4] c_mygrid[89][4] & + c_mygrid[90][4] c_mygrid[91][4] c_mygrid[92][4] c_mygrid[93][4] c_mygrid[94][4] c_mygrid[95][4] c_mygrid[96][4] c_mygrid[97][4] c_mygrid[98][4] c_mygrid[99][4] & + c_mygrid[101][4] c_mygrid[102][4] c_mygrid[103][4] c_mygrid[104][4] c_mygrid[105][4] c_mygrid[106][4] c_mygrid[107][4] c_mygrid[108][4] c_mygrid[109][4] & + c_mygrid[110][4] c_mygrid[111][4] c_mygrid[112][4] c_mygrid[113][4] c_mygrid[114][4] c_mygrid[115][4] c_mygrid[116][4] c_mygrid[117][4] c_mygrid[118][4] c_mygrid[119][4] & + c_mygrid[120][4] c_mygrid[121][4] c_mygrid[122][4] c_mygrid[123][4] c_mygrid[124][4] c_mygrid[125][4] c_mygrid[126][4] c_mygrid[127][4] c_mygrid[128][4] c_mygrid[129][4] & + c_mygrid[130][4] c_mygrid[131][4] c_mygrid[132][4] c_mygrid[133][4] c_mygrid[134][4] c_mygrid[135][4] c_mygrid[136][4] c_mygrid[137][4] c_mygrid[138][4] c_mygrid[139][4] & + c_mygrid[140][4] c_mygrid[141][4] c_mygrid[142][4] c_mygrid[143][4] c_mygrid[144][4] c_mygrid[145][4] c_mygrid[146][4] c_mygrid[147][4] c_mygrid[148][4] c_mygrid[149][4] & + c_mygrid[150][4] c_mygrid[151][4] c_mygrid[152][4] c_mygrid[153][4] c_mygrid[154][4] c_mygrid[155][4] c_mygrid[156][4] c_mygrid[157][4] c_mygrid[158][4] c_mygrid[159][4] & + c_mygrid[160][4] c_mygrid[161][4] c_mygrid[162][4] c_mygrid[163][4] c_mygrid[164][4] c_mygrid[165][4] c_mygrid[166][4] c_mygrid[167][4] c_mygrid[168][4] c_mygrid[169][4] & + c_mygrid[170][4] c_mygrid[171][4] c_mygrid[172][4] c_mygrid[173][4] c_mygrid[174][4] c_mygrid[175][4] c_mygrid[176][4] c_mygrid[177][4] c_mygrid[178][4] c_mygrid[179][4] & + c_mygrid[180][4] c_mygrid[181][4] c_mygrid[182][4] c_mygrid[183][4] c_mygrid[184][4] c_mygrid[185][4] c_mygrid[186][4] c_mygrid[187][4] c_mygrid[188][4] c_mygrid[189][4] & + c_mygrid[190][4] c_mygrid[191][4] c_mygrid[192][4] c_mygrid[193][4] c_mygrid[194][4] c_mygrid[195][4] c_mygrid[196][4] c_mygrid[197][4] c_mygrid[198][4] c_mygrid[199][4] & + c_mygrid[201][4] c_mygrid[202][4] c_mygrid[203][4] c_mygrid[204][4] c_mygrid[205][4] c_mygrid[206][4] c_mygrid[207][4] c_mygrid[208][4] c_mygrid[209][4] & + c_mygrid[210][4] c_mygrid[211][4] c_mygrid[212][4] c_mygrid[213][4] c_mygrid[214][4] c_mygrid[215][4] c_mygrid[216][4] c_mygrid[217][4] c_mygrid[218][4] c_mygrid[219][4] & + c_mygrid[220][4] c_mygrid[221][4] c_mygrid[222][4] c_mygrid[223][4] c_mygrid[224][4] c_mygrid[225][4] c_mygrid[226][4] c_mygrid[227][4] c_mygrid[228][4] c_mygrid[229][4] & + c_mygrid[230][4] c_mygrid[231][4] c_mygrid[232][4] c_mygrid[233][4] c_mygrid[234][4] c_mygrid[235][4] c_mygrid[236][4] c_mygrid[237][4] c_mygrid[238][4] c_mygrid[239][4] & + c_mygrid[240][4] c_mygrid[241][4] c_mygrid[242][4] c_mygrid[243][4] c_mygrid[244][4] c_mygrid[245][4] c_mygrid[246][4] c_mygrid[247][4] c_mygrid[248][4] c_mygrid[249][4] & + c_mygrid[250][4] c_mygrid[251][4] c_mygrid[252][4] c_mygrid[253][4] c_mygrid[254][4] c_mygrid[255][4] c_mygrid[256][4] c_mygrid[257][4] c_mygrid[258][4] c_mygrid[259][4] & + c_mygrid[260][4] c_mygrid[261][4] c_mygrid[262][4] c_mygrid[263][4] c_mygrid[264][4] c_mygrid[265][4] c_mygrid[266][4] c_mygrid[267][4] c_mygrid[268][4] c_mygrid[269][4] & + c_mygrid[270][4] c_mygrid[271][4] c_mygrid[272][4] c_mygrid[273][4] c_mygrid[274][4] c_mygrid[275][4] c_mygrid[276][4] c_mygrid[277][4] c_mygrid[278][4] c_mygrid[279][4] & + c_mygrid[280][4] c_mygrid[281][4] c_mygrid[282][4] c_mygrid[283][4] c_mygrid[284][4] c_mygrid[285][4] c_mygrid[286][4] c_mygrid[287][4] c_mygrid[288][4] c_mygrid[289][4] & + c_mygrid[290][4] c_mygrid[291][4] c_mygrid[292][4] c_mygrid[293][4] c_mygrid[294][4] c_mygrid[295][4] c_mygrid[296][4] c_mygrid[297][4] c_mygrid[298][4] c_mygrid[299][4] & + c_mygrid[301][4] c_mygrid[302][4] c_mygrid[303][4] c_mygrid[304][4] c_mygrid[305][4] c_mygrid[306][4] c_mygrid[307][4] c_mygrid[308][4] c_mygrid[309][4] & + c_mygrid[310][4] c_mygrid[311][4] c_mygrid[312][4] c_mygrid[313][4] c_mygrid[314][4] c_mygrid[315][4] c_mygrid[316][4] c_mygrid[317][4] c_mygrid[318][4] c_mygrid[319][4] & + c_mygrid[320][4] c_mygrid[321][4] c_mygrid[322][4] c_mygrid[323][4] c_mygrid[324][4] c_mygrid[325][4] c_mygrid[326][4] c_mygrid[327][4] c_mygrid[328][4] c_mygrid[329][4] & + c_mygrid[330][4] c_mygrid[331][4] c_mygrid[332][4] c_mygrid[333][4] c_mygrid[334][4] c_mygrid[335][4] c_mygrid[336][4] c_mygrid[337][4] c_mygrid[338][4] c_mygrid[339][4] & + c_mygrid[340][4] c_mygrid[341][4] c_mygrid[342][4] c_mygrid[343][4] c_mygrid[344][4] c_mygrid[345][4] c_mygrid[346][4] c_mygrid[347][4] c_mygrid[348][4] c_mygrid[349][4] & + c_mygrid[350][4] c_mygrid[351][4] c_mygrid[352][4] c_mygrid[353][4] c_mygrid[354][4] c_mygrid[355][4] c_mygrid[356][4] c_mygrid[357][4] c_mygrid[358][4] c_mygrid[359][4] & + c_mygrid[360][4] c_mygrid[361][4] c_mygrid[362][4] c_mygrid[363][4] c_mygrid[364][4] c_mygrid[365][4] c_mygrid[366][4] c_mygrid[367][4] c_mygrid[368][4] c_mygrid[369][4] & + c_mygrid[370][4] c_mygrid[371][4] c_mygrid[372][4] c_mygrid[373][4] c_mygrid[374][4] c_mygrid[375][4] c_mygrid[376][4] c_mygrid[377][4] c_mygrid[378][4] c_mygrid[379][4] & + c_mygrid[380][4] c_mygrid[381][4] c_mygrid[382][4] c_mygrid[383][4] c_mygrid[384][4] thermo_modify norm yes diff --git a/src/SNAP/compute_sna_grid.cpp b/src/SNAP/compute_sna_grid.cpp index 26bd272d9f..d9912cdc47 100644 --- a/src/SNAP/compute_sna_grid.cpp +++ b/src/SNAP/compute_sna_grid.cpp @@ -120,7 +120,7 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : rmin0,switchflag,bzeroflag); ncoeff = snaptr->ncoeff; - size_array_cols = ncoeff; + size_array_cols = size_array_cols_base + ncoeff; if (quadraticflag) size_array_cols += (ncoeff*(ncoeff+1))/2; array_flag = 1; } @@ -237,8 +237,8 @@ void ComputeSNAGrid::compute_array() snaptr->compute_zi(); snaptr->compute_bi(); for (int icoeff = 0; icoeff < ncoeff; icoeff++) - sna[igrid][icoeff] = snaptr->blist[icoeff]; - // printf("igrid = %d %g %g %g %d B0 = %g\n",igrid,xtmp,ytmp,ztmp,ninside,sna[igrid][0]); + sna[igrid][size_array_cols_base+icoeff] = snaptr->blist[icoeff]; + // printf("igrid = %d %g %g %g %d B0 = %g\n",igrid,xtmp,ytmp,ztmp,ninside,sna[igrid][size_array_cols_base+0]); if (quadraticflag) { int ncount = ncoeff; for (int icoeff = 0; icoeff < ncoeff; icoeff++) { diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index ec969fd01f..63e4a8c885 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -51,6 +51,7 @@ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : nargbase = iarg - iarg0; size_array_rows = nx*ny*nz; + size_array_cols_base = 3; } /* ---------------------------------------------------------------------- */ @@ -131,6 +132,7 @@ void ComputeGrid::setup() z0full = boxlo[2] - mz*delz; allocate(); + assign_coords_array(); } /* ---------------------------------------------------------------------- @@ -153,6 +155,26 @@ void ComputeGrid::igridfull2x(int igrid, double *x) } +/* ---------------------------------------------------------------------- + convert array index to box coords +------------------------------------------------------------------------- */ + +void ComputeGrid::iarray2x(int iarray, double *x) +{ + int iz = iarray / (nx*ny); + iarray -= iz * (nx*ny); + int iy = iarray / nx; + iarray -= iy * nx; + int ix = iarray; + + x[0] = ix*delx; + x[1] = iy*dely; + x[2] = iz*delz; + + if (triclinic) domain->lamda2x(x, x); + +} + /* ---------------------------------------------------------------------- copy local grid to global array ------------------------------------------------------------------------- */ @@ -162,11 +184,26 @@ void ComputeGrid::copy_local_grid() int igridfull; for (int iarray = 0; iarray < size_array_rows; iarray++) { igridfull = iarray2igridfull(iarray); - for (int icol = 0; icol < size_array_cols; icol++) + for (int icol = size_array_cols_base; icol < size_array_cols; icol++) array[iarray][icol] = gridfull[igridfull][icol]; } } +/* ---------------------------------------------------------------------- + copy coords to global array +------------------------------------------------------------------------- */ + +void ComputeGrid::assign_coords_array() +{ + double x[3]; + for (int iarray = 0; iarray < size_array_rows; iarray++) { + iarray2x(iarray,x); + array[iarray][0] = x[0]; + array[iarray][1] = x[1]; + array[iarray][2] = x[2]; + } +} + /* ---------------------------------------------------------------------- gather global array from full grid ------------------------------------------------------------------------- */ @@ -181,7 +218,7 @@ void ComputeGrid::gather_global_array() // inefficient, should exploit shared ix structure iarray = igridfull2iarray(igrid); - for (int icol = 0; icol < size_array_cols; icol++) + for (int icol = size_array_cols_base; icol < size_array_cols; icol++) array[iarray][icol] += gridfull[igrid][icol]; } } diff --git a/src/compute_grid.h b/src/compute_grid.h index bc757c37bc..1468f9ad91 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -33,7 +33,7 @@ class ComputeGrid : public Compute { int nx, ny, nz; // grid dimensions int nxfull, nyfull, nzfull; // grid dimensions with ghost points int nxyfull; // nx_full*ny_full - int ngridfull; // number of full grid points + int ngridfull; // number of full grid points double **gridfull; // full grid points int mx, my, mz; // cutmax stencil dimensions int triclinic; // triclinic flag @@ -43,10 +43,13 @@ class ComputeGrid : public Compute { double x0full, y0full, z0full; // origin of full grid int nargbase; // number of base class args double cutmax; // largest cutoff distance + int size_array_cols_base; // number of columns used for coords, etc. virtual void allocate(); void igridfull2x(int, double*); // convert full grid point to coord + void iarray2x(int, double*); // convert array point to coord void gather_global_array(); // gather global array from full grid void copy_local_grid(); // copy local grid to global array + void assign_coords_array(); // assign coords to global array int igridfull2iarray(int); // convert full grid index to compute array index int iarray2igridfull(int); // convert compute array index to full grid index From 59e3b4c5ba8b3de1d7f183a1cecb793b14886b99 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 24 Oct 2019 16:12:23 -0600 Subject: [PATCH 06/91] Fixed bug in lammps.py --- python/lammps.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/python/lammps.py b/python/lammps.py index 36cf2d2fdd..f23268cd60 100644 --- a/python/lammps.py +++ b/python/lammps.py @@ -399,14 +399,9 @@ class lammps(object): ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) return ptr if type == 2: - if style == 0: - self.lib.lammps_extract_compute.restype = POINTER(c_int) - ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) - return ptr[0] - else: - self.lib.lammps_extract_compute.restype = POINTER(POINTER(c_double)) - ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) - return ptr + self.lib.lammps_extract_compute.restype = POINTER(POINTER(c_double)) + ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) + return ptr return None # extract fix info From 2fa9e5fefb26f3e4540ed7dc6e4e1563e49432bc Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 24 Oct 2019 19:48:41 -0600 Subject: [PATCH 07/91] Completed brute force parallel implementation using MPI_Allreduce() --- src/SNAP/compute_sna_grid.cpp | 60 +++------- src/SNAP/compute_sna_grid.h | 4 - src/compute_grid.cpp | 220 ++++++++++------------------------ src/compute_grid.h | 26 ++-- 4 files changed, 93 insertions(+), 217 deletions(-) diff --git a/src/SNAP/compute_sna_grid.cpp b/src/SNAP/compute_sna_grid.cpp index d9912cdc47..a9f3b6c3fb 100644 --- a/src/SNAP/compute_sna_grid.cpp +++ b/src/SNAP/compute_sna_grid.cpp @@ -31,7 +31,7 @@ using namespace LAMMPS_NS; ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : - ComputeGrid(lmp, narg, arg), cutsq(NULL), list(NULL), sna(NULL), + ComputeGrid(lmp, narg, arg), cutsq(NULL), sna(NULL), radelem(NULL), wjelem(NULL) { double rmin0, rfac0; @@ -120,8 +120,9 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : rmin0,switchflag,bzeroflag); ncoeff = snaptr->ncoeff; - size_array_cols = size_array_cols_base + ncoeff; - if (quadraticflag) size_array_cols += (ncoeff*(ncoeff+1))/2; + nvalues = ncoeff; + if (quadraticflag) nvalues += (ncoeff*(ncoeff+1))/2; + size_array_cols = size_array_cols_base + nvalues; array_flag = 1; } @@ -165,26 +166,10 @@ void ComputeSNAGrid::init() /* ---------------------------------------------------------------------- */ -void ComputeSNAGrid::init_list(int /*id*/, NeighList *ptr) -{ - list = ptr; -} - -/* ---------------------------------------------------------------------- */ - void ComputeSNAGrid::compute_array() { invoked_array = update->ntimestep; -// // invoke full neighbor list (will copy or build if necessary) - -// neighbor->build_one(list); - -// const int inum = list->inum; -// const int* const ilist = list->ilist; -// const int* const numneigh = list->numneigh; -// int** const firstneigh = list->firstneigh; - int * const type = atom->type; // compute sna for each gridpoint @@ -197,13 +182,12 @@ void ComputeSNAGrid::compute_array() snaptr->grow_rij(ntotal); - printf("ngridfull = %d\n",ngridfull); - for (int igrid = 0; igrid < ngridfull; igrid++) { - double rtmp[3]; - igridfull2x(igrid, rtmp); - const double xtmp = rtmp[0]; - const double ytmp = rtmp[1]; - const double ztmp = rtmp[2]; + printf("ngrid = %d\n",ngrid); + for (int igrid = 0; igrid < ngrid; igrid++) { + if (!grid_local[igrid]) continue; + const double xtmp = grid[igrid][0]; + const double ytmp = grid[igrid][1]; + const double ztmp = grid[igrid][2]; // rij[][3] = displacements between atom I and those neighbors // inside = indices of neighbors of I within cutoff @@ -237,7 +221,7 @@ void ComputeSNAGrid::compute_array() snaptr->compute_zi(); snaptr->compute_bi(); for (int icoeff = 0; icoeff < ncoeff; icoeff++) - sna[igrid][size_array_cols_base+icoeff] = snaptr->blist[icoeff]; + grid[igrid][size_array_cols_base+icoeff] = snaptr->blist[icoeff]; // printf("igrid = %d %g %g %g %d B0 = %g\n",igrid,xtmp,ytmp,ztmp,ninside,sna[igrid][size_array_cols_base+0]); if (quadraticflag) { int ncount = ncoeff; @@ -246,27 +230,16 @@ void ComputeSNAGrid::compute_array() // diagonal element of quadratic matrix - sna[igrid][ncount++] = 0.5*bi*bi; + grid[igrid][size_array_cols_base+ncount++] = 0.5*bi*bi; // upper-triangular elements of quadratic matrix for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - sna[igrid][ncount++] = bi*snaptr->blist[jcoeff]; + grid[igrid][size_array_cols_base+ncount++] = bi*snaptr->blist[jcoeff]; } } } - // gather_global_array(); - copy_local_grid(); -} - -/* ---------------------------------------------------------------------- - allocate array in base class and then set up pointers -------------------------------------------------------------------------- */ - -void ComputeSNAGrid::allocate() -{ - ComputeGrid::allocate(); - sna = gridfull; + MPI_Allreduce(&grid[0][0],&gridall[0][0],ngrid*size_array_cols,MPI_DOUBLE,MPI_SUM,world); } /* ---------------------------------------------------------------------- @@ -275,9 +248,8 @@ void ComputeSNAGrid::allocate() double ComputeSNAGrid::memory_usage() { - double bytes = size_array_rows*size_array_cols * sizeof(double); // grid - bytes += snaptr->memory_usage(); // SNA object + double nbytes = snaptr->memory_usage(); // SNA object - return bytes; + return nbytes; } diff --git a/src/SNAP/compute_sna_grid.h b/src/SNAP/compute_sna_grid.h index 2bd18a915e..0242a2962b 100644 --- a/src/SNAP/compute_sna_grid.h +++ b/src/SNAP/compute_sna_grid.h @@ -29,16 +29,12 @@ class ComputeSNAGrid : public ComputeGrid { ComputeSNAGrid(class LAMMPS *, int, char **); ~ComputeSNAGrid(); void init(); - void init_list(int, class NeighList *); void compute_array(); double memory_usage(); - void allocate(); private: - int nmax; int ncoeff; double **cutsq; - class NeighList *list; double **sna; double rcutfac; double *radelem; diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 63e4a8c885..2f67d22182 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -50,7 +50,7 @@ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : nargbase = iarg - iarg0; - size_array_rows = nx*ny*nz; + size_array_rows = ngrid = nx*ny*nz; size_array_cols_base = 3; } @@ -58,6 +58,8 @@ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : ComputeGrid::~ComputeGrid() { + memory->destroy(grid); + memory->destroy(grid_local); } /* ---------------------------------------------------------------------- */ @@ -78,9 +80,13 @@ void ComputeGrid::setup() if (triclinic == 0) { prd = domain->prd; boxlo = domain->boxlo; + sublo = domain->sublo; + subhi = domain->subhi; } else { prd = domain->prd_lamda; boxlo = domain->boxlo_lamda; + sublo = domain->sublo_lamda; + subhi = domain->subhi_lamda; } double xprd = prd[0]; @@ -95,78 +101,23 @@ void ComputeGrid::setup() dely = 1.0/delyinv; delz = 1.0/delzinv; - // sufficient conditions for stencil bounding rcut - - // require |delz*mz|^2 <= rcut^2 - // require |dely*my|^2 <= rcut^2 + |delyz*mz_max|^2 - // require |delx*mx|^2 <= rcut^2 + |delxz*mz_max|^2 + |delxy*my_max|^2 - - double delxy = domain->xy/ny; - double delxz = domain->xz/nz; - double delyz = domain->yz/nz; - - if (!triclinic) { - mz = cutmax*delzinv + 1; - my = sqrt(cutmax*cutmax + pow(delyz*mz,2))*delyinv + 1; - mx = sqrt(cutmax*cutmax + pow(delxz*mz,2) - + pow(delxy*my,2))*delxinv + 1; - } else { - double delxinvtmp = nx/domain->xprd; - double delyinvtmp = ny/domain->yprd; - double delzinvtmp = nz/domain->zprd; - mz = cutmax*delzinvtmp + 1; - my = sqrt(cutmax*cutmax + pow(delyz*mz,2))*delyinvtmp + 1; - mx = sqrt(cutmax*cutmax + pow(delxz*mz,2) - + pow(delxy*my,2))*delxinvtmp + 1; - } - - // size global grid to accomodate periodic interactions - - nxfull = nx + 2*mx; - nyfull = ny + 2*my; - nzfull = nz + 2*mz; - nxyfull = nxfull * nyfull; - - x0full = boxlo[0] - mx*delx; - y0full = boxlo[1] - my*dely; - z0full = boxlo[2] - mz*delz; - allocate(); - assign_coords_array(); + assign_grid_coords(); + assign_grid_local(); } /* ---------------------------------------------------------------------- - convert grid index to box coords + convert global array index to box coords ------------------------------------------------------------------------- */ -void ComputeGrid::igridfull2x(int igrid, double *x) +void ComputeGrid::grid2x(int igrid, double *x) { - int iz = igrid / nxyfull; - igrid -= iz * nxyfull; - int iy = igrid / nxfull; - igrid -= iy * nxfull; + int iz = igrid / (nx*ny); + igrid -= iz * (nx*ny); + int iy = igrid / nx; + igrid -= iy * nx; int ix = igrid; - x[0] = x0full+ix*delx; - x[1] = y0full+iy*dely; - x[2] = z0full+iz*delz; - - if (triclinic) domain->lamda2x(x, x); - -} - -/* ---------------------------------------------------------------------- - convert array index to box coords -------------------------------------------------------------------------- */ - -void ComputeGrid::iarray2x(int iarray, double *x) -{ - int iz = iarray / (nx*ny); - iarray -= iz * (nx*ny); - int iy = iarray / nx; - iarray -= iy * nx; - int ix = iarray; - x[0] = ix*delx; x[1] = iy*dely; x[2] = iz*delz; @@ -176,16 +127,43 @@ void ComputeGrid::iarray2x(int iarray, double *x) } /* ---------------------------------------------------------------------- - copy local grid to global array + check if grid point is local ------------------------------------------------------------------------- */ -void ComputeGrid::copy_local_grid() +int ComputeGrid::check_grid_local(int igrid) { - int igridfull; - for (int iarray = 0; iarray < size_array_rows; iarray++) { - igridfull = iarray2igridfull(iarray); - for (int icol = size_array_cols_base; icol < size_array_cols; icol++) - array[iarray][icol] = gridfull[igridfull][icol]; + double x[3]; + + int iz = igrid / (nx*ny); + igrid -= iz * (nx*ny); + int iy = igrid / nx; + igrid -= iy * nx; + int ix = igrid; + + x[0] = ix*delx; + x[1] = iy*dely; + x[2] = iz*delz; + + int islocal = + x[0] >= sublo[0] && x[0] < subhi[0] && + x[1] >= sublo[1] && x[1] < subhi[1] && + x[2] >= sublo[2] && x[2] < subhi[2]; + + return islocal; +} + +/* ---------------------------------------------------------------------- + copy coords to global array +------------------------------------------------------------------------- */ + +void ComputeGrid::assign_grid_coords() +{ + double x[3]; + for (int igrid = 0; igrid < ngrid; igrid++) { + grid2x(igrid,x); + grid[igrid][0] = x[0]; + grid[igrid][1] = x[1]; + grid[igrid][2] = x[2]; } } @@ -193,101 +171,33 @@ void ComputeGrid::copy_local_grid() copy coords to global array ------------------------------------------------------------------------- */ -void ComputeGrid::assign_coords_array() +void ComputeGrid::assign_grid_local() { double x[3]; - for (int iarray = 0; iarray < size_array_rows; iarray++) { - iarray2x(iarray,x); - array[iarray][0] = x[0]; - array[iarray][1] = x[1]; - array[iarray][2] = x[2]; + for (int igrid = 0; igrid < ngrid; igrid++) { + if (check_grid_local(igrid)) + grid_local[igrid] = 1; + else { + grid_local[igrid] = 0; + memset(grid[igrid],0,size_array_cols); + } } } -/* ---------------------------------------------------------------------- - gather global array from full grid -------------------------------------------------------------------------- */ - -void ComputeGrid::gather_global_array() -{ - int iarray; - memset(&array[0][0],0,size_array_rows*size_array_cols*sizeof(double)); - - for (int igrid = 0; igrid < ngridfull; igrid++) { - - // inefficient, should exploit shared ix structure - - iarray = igridfull2iarray(igrid); - for (int icol = size_array_cols_base; icol < size_array_cols; icol++) - array[iarray][icol] += gridfull[igrid][icol]; - } -} - -/* ---------------------------------------------------------------------- - convert full grid index to compute array index - inefficient, should exploit shared ix structure -------------------------------------------------------------------------- */ - -int ComputeGrid::igridfull2iarray(int igrid) -{ - int iz = igrid / nxyfull; - igrid -= iz*nxyfull; - int iy = igrid / nxfull; - igrid -= iy*nxfull; - int ix = igrid; - - ix -= mx; - iy -= my; - iz -= mz; - - while (ix < 0) ix += nx; - while (iy < 0) iy += ny; - while (iz < 0) iz += nz; - - while (ix >= nx) ix -= nx; - while (iy >= ny) iy -= ny; - while (iz >= nz) iz -= nz; - - int iarray = (iz * ny + iy) * nx + ix; - - return iarray; -} - -/* ---------------------------------------------------------------------- - convert compute array index to full grid index - inefficient, should exploit shared ix structure -------------------------------------------------------------------------- */ - -int ComputeGrid::iarray2igridfull(int iarray) -{ - int iz = iarray / (nx*ny); - iarray -= iz*(nx*ny); - int iy = iarray / nx; - iarray -= iy*nx; - int ix = iarray; - - ix += mx; - iy += my; - iz += mz; - - int igrid = (iz * nyfull + iy) * nxfull + ix; - - return igrid; -} - /* ---------------------------------------------------------------------- free and reallocate arrays ------------------------------------------------------------------------- */ void ComputeGrid::allocate() { - ngridfull = nxfull*nyfull*nzfull; - // grow global array if necessary - memory->destroy(array); - memory->create(array,size_array_rows,size_array_cols,"sna/grid:array"); - memory->create(gridfull,ngridfull,size_array_cols,"sna/grid:gridfull"); + memory->destroy(grid); + memory->destroy(grid_local); + memory->create(grid,size_array_rows,size_array_cols,"grid:grid"); + memory->create(gridall,size_array_rows,size_array_cols,"grid:gridall"); + memory->create(grid_local,size_array_rows,"grid:grid_local"); + array = gridall; } /* ---------------------------------------------------------------------- memory usage of local data @@ -295,6 +205,8 @@ void ComputeGrid::allocate() double ComputeGrid::memory_usage() { - int nbytes = 0; + double nbytes = size_array_rows*size_array_cols * + sizeof(double); // grid + nbytes += size_array_rows*sizeof(int); // grid_local return nbytes; } diff --git a/src/compute_grid.h b/src/compute_grid.h index 1468f9ad91..a1c938db2e 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -31,28 +31,24 @@ class ComputeGrid : public Compute { protected: int nx, ny, nz; // grid dimensions - int nxfull, nyfull, nzfull; // grid dimensions with ghost points - int nxyfull; // nx_full*ny_full - int ngridfull; // number of full grid points - double **gridfull; // full grid points - int mx, my, mz; // cutmax stencil dimensions + int ngrid; // number of grid points + int nvalues; // number of values per grid point + double **grid; // global grid + double **gridall; // global grid summed over procs int triclinic; // triclinic flag double *boxlo, *prd; // box info (units real/ortho or reduced/tri) + double *sublo, *subhi; // subdomain info (units real/ortho or reduced/tri) double delxinv,delyinv,delzinv; // inverse grid spacing double delx,dely,delz; // grid spacing - double x0full, y0full, z0full; // origin of full grid int nargbase; // number of base class args double cutmax; // largest cutoff distance int size_array_cols_base; // number of columns used for coords, etc. - virtual void allocate(); - void igridfull2x(int, double*); // convert full grid point to coord - void iarray2x(int, double*); // convert array point to coord - void gather_global_array(); // gather global array from full grid - void copy_local_grid(); // copy local grid to global array - void assign_coords_array(); // assign coords to global array - int igridfull2iarray(int); // convert full grid index to compute array index - int iarray2igridfull(int); // convert compute array index to full grid index - + int *grid_local; // local flag for each grid point + void allocate(); + void grid2x(int, double*); // convert grid point to coord + void assign_grid_coords(); // assign coords for grid + void assign_grid_local(); // set local flag for each grid point + int check_grid_local(int); // check if grid point is local private: }; From 651e9c63973809d1026faac942f84998dfe7ac74 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Tue, 19 May 2020 11:01:31 -0600 Subject: [PATCH 08/91] Initialized arrays to NULL --- src/compute_grid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 2f67d22182..011dafa030 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -27,7 +27,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg) + Compute(lmp, narg, arg), grid(NULL), grid_local(NULL) { if (narg < 6) error->all(FLERR,"Illegal compute grid command"); From 4a261f396128a0d19beba082bd7f4ab6c54a1803 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Sat, 23 May 2020 10:18:16 -0600 Subject: [PATCH 09/91] Added python example (!) and turned on switching function --- examples/snap/grid.py | 104 +++++++++++++++++++++++++++++++++++ examples/snap/in.grid | 9 ++- examples/snap/in.grid.python | 61 ++++++++++++++++++++ examples/snap/in.grid.tri | 82 +++++++++++++-------------- 4 files changed, 214 insertions(+), 42 deletions(-) create mode 100755 examples/snap/grid.py create mode 100644 examples/snap/in.grid.python diff --git a/examples/snap/grid.py b/examples/snap/grid.py new file mode 100755 index 0000000000..9fe88fd1b4 --- /dev/null +++ b/examples/snap/grid.py @@ -0,0 +1,104 @@ +#!/Users/athomps/miniconda3/bin/python3.7 +# +# An example of SNAP grid from LAMMPS Python interface +# +# https://lammps.sandia.gov/doc/Python_library.html + + +from lammps import lammps +import lammps_utils + +# define command line input variables + +ngridx = 2 +ngridy = 3 +ngridz = 4 +twojmax = 2 + +lmp_cmdargs = ["-echo","screen"] +lmp_cmdargs = lammps_utils.set_cmdlinevars(lmp_cmdargs, + { + "ngridx":ngridx, + "ngridy":ngridy, + "ngridz":ngridz, + "twojmax":twojmax + } + ) + +# launch LAMMPS instance + +lmp = lammps(cmdargs=lmp_cmdargs) + +# run LAMMPS input script + +lmp.file("in.grid.python") + +# get quantities from LAMMPS + +num_atoms = lmp.get_natoms() + +# set things not accessible from LAMMPS + +# first 3 cols are x, y, z, coords + +ncols0 = 3 + +# analytical relation + +ncoeff = (twojmax+2)*(twojmax+3)*(twojmax+4) +ncoeff = ncoeff // 24 # integer division +ncols = ncols0+ncoeff + +# get B_0 at position (0,0,0) in 4 different ways + +# 1. from comute sna/atom + +bptr = lmp.extract_compute("b", 1, 2) # 1 = per-atom data, 2 = array +print("b = ",bptr[0][0]) + +# 2. from compute sna/grid + +bgridptr = lmp.extract_compute("bgrid", 0, 2) # 0 = style global, 2 = type array +print("bgrid = ",bgridptr[0][3]) + +# 3. from Numpy array pointing to sna/atom array + +bptr_np = lammps_utils.extract_compute_np(lmp,"b",1,2,(num_atoms,ncoeff)) +print("b_np = ",bptr_np[0][0]) + +# 4. from Numpy array pointing to sna/grid array + +bgridptr_np = lammps_utils.extract_compute_np(lmp,"bgrid",0,2,(ngridz,ngridy,ngridx,ncols)) +print("bgrid_np = ",bgridptr_np[0][0][0][ncols0+0]) + +# print out the LAMMPS array to a file + +outfile = open("bgrid.dat",'w') +igrid = 0 +for iz in range(ngridz): + for iy in range(ngridy): + for ix in range(ngridx): + outfile.write("x, y, z = %g %g %g\n" % + (bgridptr[igrid][0], + bgridptr[igrid][1], + bgridptr[igrid][2])) + for icoeff in range(ncoeff): + outfile.write("%g " % bgridptr[igrid][ncols0+icoeff]) + outfile.write("\n") + igrid += 1 +outfile.close() + +# print out the Numpy array to a file + +outfile = open("bgrid_np.dat",'w') +for iz in range(ngridz): + for iy in range(ngridy): + for ix in range(ngridx): + outfile.write("x, y, z = %g %g %g\n" % + (bgridptr_np[iz][iy][ix][0], + bgridptr_np[iz][iy][ix][1], + bgridptr_np[iz][iy][ix][2])) + for icoeff in range(ncoeff): + outfile.write("%g " % bgridptr_np[iz][iy][ix][ncols0+icoeff]) + outfile.write("\n") +outfile.close() diff --git a/examples/snap/in.grid b/examples/snap/in.grid index 5293558fab..2702fccad1 100644 --- a/examples/snap/in.grid +++ b/examples/snap/in.grid @@ -46,7 +46,7 @@ variable wj equal 1 variable radelem equal 0.5 variable bzero equal 0 variable quad equal 0 -variable switch equal 0 +variable switch equal 1 compute b all sna/atom & ${rcutfac} ${rfac0} ${twojmax} ${radelem} & @@ -60,11 +60,16 @@ compute mygrid all sna/grid grid ${ngrid} ${ngrid} ${ngrid} & # define output +# mygrid is ngrid by (3+nbis) = 8x8 thermo_style custom step temp ke pe vol & c_mygrid[1][1] c_mygrid[2][1] c_mygrid[3][1] c_mygrid[4][1] c_mygrid[5][1] c_mygrid[6][1] c_mygrid[7][1] c_mygrid[8][1] & c_mygrid[1][2] c_mygrid[2][2] c_mygrid[3][2] c_mygrid[4][2] c_mygrid[5][2] c_mygrid[6][2] c_mygrid[7][2] c_mygrid[8][2] & c_mygrid[1][3] c_mygrid[2][3] c_mygrid[3][3] c_mygrid[4][3] c_mygrid[5][3] c_mygrid[6][3] c_mygrid[7][3] c_mygrid[8][3] & - c_mygrid[1][4] c_mygrid[2][4] c_mygrid[3][4] c_mygrid[4][4] c_mygrid[5][4] c_mygrid[6][4] c_mygrid[7][4] c_mygrid[8][4] + c_mygrid[1][4] c_mygrid[2][4] c_mygrid[3][4] c_mygrid[4][4] c_mygrid[5][4] c_mygrid[6][4] c_mygrid[7][4] c_mygrid[8][4] & + c_mygrid[1][5] c_mygrid[2][5] c_mygrid[3][5] c_mygrid[4][5] c_mygrid[5][5] c_mygrid[6][5] c_mygrid[7][5] c_mygrid[8][5] & + c_mygrid[1][6] c_mygrid[2][6] c_mygrid[3][6] c_mygrid[4][6] c_mygrid[5][6] c_mygrid[6][6] c_mygrid[7][6] c_mygrid[8][6] & + c_mygrid[1][7] c_mygrid[2][7] c_mygrid[3][7] c_mygrid[4][7] c_mygrid[5][7] c_mygrid[6][7] c_mygrid[7][7] c_mygrid[8][7] & + c_mygrid[1][8] c_mygrid[2][8] c_mygrid[3][8] c_mygrid[4][8] c_mygrid[5][8] c_mygrid[6][8] c_mygrid[7][8] c_mygrid[8][8] thermo_modify norm yes dump mydump_b all custom 1000 dump_b id c_b[*] diff --git a/examples/snap/in.grid.python b/examples/snap/in.grid.python new file mode 100644 index 0000000000..13fe6d0638 --- /dev/null +++ b/examples/snap/in.grid.python @@ -0,0 +1,61 @@ +# Demonstrate bispectrum per-atom and grid computes + +# Invoked from grid.py +# pass in values for ngridx, ngridy, ngridz, twojmax + +# Initialize simulation + +variable nsteps equal 0 +variable nrep equal 1 +variable a equal 3.316 + +units metal + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice custom ${a} a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 + +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 180.88 + +# define grid compute and atom compute + +group snapgroup type 1 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quad equal 0 +variable switch equal 1 + +compute b all sna/atom ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} + +compute bgrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} + +# create dummy potential for neighbor list + +variable rcutneigh equal 2.0*${rcutfac}*${radelem} +pair_style zero ${rcutneigh} +pair_coeff * * + +# define output + +thermo_style custom step temp ke pe vol c_bgrid[1][1] +thermo_modify norm yes + +dump mydump_b all custom 1000 dump_b id c_b[*] + +# run + +run 0 diff --git a/examples/snap/in.grid.tri b/examples/snap/in.grid.tri index 3c471d9b66..c984799e09 100644 --- a/examples/snap/in.grid.tri +++ b/examples/snap/in.grid.tri @@ -51,7 +51,7 @@ variable wj equal 1 variable radelem equal 0.5 variable bzero equal 0 variable quad equal 0 -variable switch equal 0 +variable switch equal 1 compute b all sna/atom & ${rcutfac} ${rfac0} ${twojmax} ${radelem} & @@ -65,46 +65,48 @@ compute mygrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} & # define output +# mygrid is ngrid by (3+nbis) = 384x8 + thermo_style custom step temp ke pe vol & - c_mygrid[1][4] c_mygrid[2][4] c_mygrid[3][4] c_mygrid[4][4] c_mygrid[5][4] c_mygrid[6][4] c_mygrid[7][4] c_mygrid[8][4] c_mygrid[9][4] & - c_mygrid[10][4] c_mygrid[11][4] c_mygrid[12][4] c_mygrid[13][4] c_mygrid[14][4] c_mygrid[15][4] c_mygrid[16][4] c_mygrid[17][4] c_mygrid[18][4] c_mygrid[19][4] & - c_mygrid[20][4] c_mygrid[21][4] c_mygrid[22][4] c_mygrid[23][4] c_mygrid[24][4] c_mygrid[25][4] c_mygrid[26][4] c_mygrid[27][4] c_mygrid[28][4] c_mygrid[29][4] & - c_mygrid[30][4] c_mygrid[31][4] c_mygrid[32][4] c_mygrid[33][4] c_mygrid[34][4] c_mygrid[35][4] c_mygrid[36][4] c_mygrid[37][4] c_mygrid[38][4] c_mygrid[39][4] & - c_mygrid[40][4] c_mygrid[41][4] c_mygrid[42][4] c_mygrid[43][4] c_mygrid[44][4] c_mygrid[45][4] c_mygrid[46][4] c_mygrid[47][4] c_mygrid[48][4] c_mygrid[49][4] & - c_mygrid[50][4] c_mygrid[51][4] c_mygrid[52][4] c_mygrid[53][4] c_mygrid[54][4] c_mygrid[55][4] c_mygrid[56][4] c_mygrid[57][4] c_mygrid[58][4] c_mygrid[59][4] & - c_mygrid[60][4] c_mygrid[61][4] c_mygrid[62][4] c_mygrid[63][4] c_mygrid[64][4] c_mygrid[65][4] c_mygrid[66][4] c_mygrid[67][4] c_mygrid[68][4] c_mygrid[69][4] & - c_mygrid[70][4] c_mygrid[71][4] c_mygrid[72][4] c_mygrid[73][4] c_mygrid[74][4] c_mygrid[75][4] c_mygrid[76][4] c_mygrid[77][4] c_mygrid[78][4] c_mygrid[79][4] & - c_mygrid[80][4] c_mygrid[81][4] c_mygrid[82][4] c_mygrid[83][4] c_mygrid[84][4] c_mygrid[85][4] c_mygrid[86][4] c_mygrid[87][4] c_mygrid[88][4] c_mygrid[89][4] & - c_mygrid[90][4] c_mygrid[91][4] c_mygrid[92][4] c_mygrid[93][4] c_mygrid[94][4] c_mygrid[95][4] c_mygrid[96][4] c_mygrid[97][4] c_mygrid[98][4] c_mygrid[99][4] & - c_mygrid[101][4] c_mygrid[102][4] c_mygrid[103][4] c_mygrid[104][4] c_mygrid[105][4] c_mygrid[106][4] c_mygrid[107][4] c_mygrid[108][4] c_mygrid[109][4] & - c_mygrid[110][4] c_mygrid[111][4] c_mygrid[112][4] c_mygrid[113][4] c_mygrid[114][4] c_mygrid[115][4] c_mygrid[116][4] c_mygrid[117][4] c_mygrid[118][4] c_mygrid[119][4] & - c_mygrid[120][4] c_mygrid[121][4] c_mygrid[122][4] c_mygrid[123][4] c_mygrid[124][4] c_mygrid[125][4] c_mygrid[126][4] c_mygrid[127][4] c_mygrid[128][4] c_mygrid[129][4] & - c_mygrid[130][4] c_mygrid[131][4] c_mygrid[132][4] c_mygrid[133][4] c_mygrid[134][4] c_mygrid[135][4] c_mygrid[136][4] c_mygrid[137][4] c_mygrid[138][4] c_mygrid[139][4] & - c_mygrid[140][4] c_mygrid[141][4] c_mygrid[142][4] c_mygrid[143][4] c_mygrid[144][4] c_mygrid[145][4] c_mygrid[146][4] c_mygrid[147][4] c_mygrid[148][4] c_mygrid[149][4] & - c_mygrid[150][4] c_mygrid[151][4] c_mygrid[152][4] c_mygrid[153][4] c_mygrid[154][4] c_mygrid[155][4] c_mygrid[156][4] c_mygrid[157][4] c_mygrid[158][4] c_mygrid[159][4] & - c_mygrid[160][4] c_mygrid[161][4] c_mygrid[162][4] c_mygrid[163][4] c_mygrid[164][4] c_mygrid[165][4] c_mygrid[166][4] c_mygrid[167][4] c_mygrid[168][4] c_mygrid[169][4] & - c_mygrid[170][4] c_mygrid[171][4] c_mygrid[172][4] c_mygrid[173][4] c_mygrid[174][4] c_mygrid[175][4] c_mygrid[176][4] c_mygrid[177][4] c_mygrid[178][4] c_mygrid[179][4] & - c_mygrid[180][4] c_mygrid[181][4] c_mygrid[182][4] c_mygrid[183][4] c_mygrid[184][4] c_mygrid[185][4] c_mygrid[186][4] c_mygrid[187][4] c_mygrid[188][4] c_mygrid[189][4] & - c_mygrid[190][4] c_mygrid[191][4] c_mygrid[192][4] c_mygrid[193][4] c_mygrid[194][4] c_mygrid[195][4] c_mygrid[196][4] c_mygrid[197][4] c_mygrid[198][4] c_mygrid[199][4] & - c_mygrid[201][4] c_mygrid[202][4] c_mygrid[203][4] c_mygrid[204][4] c_mygrid[205][4] c_mygrid[206][4] c_mygrid[207][4] c_mygrid[208][4] c_mygrid[209][4] & - c_mygrid[210][4] c_mygrid[211][4] c_mygrid[212][4] c_mygrid[213][4] c_mygrid[214][4] c_mygrid[215][4] c_mygrid[216][4] c_mygrid[217][4] c_mygrid[218][4] c_mygrid[219][4] & - c_mygrid[220][4] c_mygrid[221][4] c_mygrid[222][4] c_mygrid[223][4] c_mygrid[224][4] c_mygrid[225][4] c_mygrid[226][4] c_mygrid[227][4] c_mygrid[228][4] c_mygrid[229][4] & - c_mygrid[230][4] c_mygrid[231][4] c_mygrid[232][4] c_mygrid[233][4] c_mygrid[234][4] c_mygrid[235][4] c_mygrid[236][4] c_mygrid[237][4] c_mygrid[238][4] c_mygrid[239][4] & - c_mygrid[240][4] c_mygrid[241][4] c_mygrid[242][4] c_mygrid[243][4] c_mygrid[244][4] c_mygrid[245][4] c_mygrid[246][4] c_mygrid[247][4] c_mygrid[248][4] c_mygrid[249][4] & - c_mygrid[250][4] c_mygrid[251][4] c_mygrid[252][4] c_mygrid[253][4] c_mygrid[254][4] c_mygrid[255][4] c_mygrid[256][4] c_mygrid[257][4] c_mygrid[258][4] c_mygrid[259][4] & - c_mygrid[260][4] c_mygrid[261][4] c_mygrid[262][4] c_mygrid[263][4] c_mygrid[264][4] c_mygrid[265][4] c_mygrid[266][4] c_mygrid[267][4] c_mygrid[268][4] c_mygrid[269][4] & - c_mygrid[270][4] c_mygrid[271][4] c_mygrid[272][4] c_mygrid[273][4] c_mygrid[274][4] c_mygrid[275][4] c_mygrid[276][4] c_mygrid[277][4] c_mygrid[278][4] c_mygrid[279][4] & - c_mygrid[280][4] c_mygrid[281][4] c_mygrid[282][4] c_mygrid[283][4] c_mygrid[284][4] c_mygrid[285][4] c_mygrid[286][4] c_mygrid[287][4] c_mygrid[288][4] c_mygrid[289][4] & - c_mygrid[290][4] c_mygrid[291][4] c_mygrid[292][4] c_mygrid[293][4] c_mygrid[294][4] c_mygrid[295][4] c_mygrid[296][4] c_mygrid[297][4] c_mygrid[298][4] c_mygrid[299][4] & - c_mygrid[301][4] c_mygrid[302][4] c_mygrid[303][4] c_mygrid[304][4] c_mygrid[305][4] c_mygrid[306][4] c_mygrid[307][4] c_mygrid[308][4] c_mygrid[309][4] & - c_mygrid[310][4] c_mygrid[311][4] c_mygrid[312][4] c_mygrid[313][4] c_mygrid[314][4] c_mygrid[315][4] c_mygrid[316][4] c_mygrid[317][4] c_mygrid[318][4] c_mygrid[319][4] & - c_mygrid[320][4] c_mygrid[321][4] c_mygrid[322][4] c_mygrid[323][4] c_mygrid[324][4] c_mygrid[325][4] c_mygrid[326][4] c_mygrid[327][4] c_mygrid[328][4] c_mygrid[329][4] & - c_mygrid[330][4] c_mygrid[331][4] c_mygrid[332][4] c_mygrid[333][4] c_mygrid[334][4] c_mygrid[335][4] c_mygrid[336][4] c_mygrid[337][4] c_mygrid[338][4] c_mygrid[339][4] & - c_mygrid[340][4] c_mygrid[341][4] c_mygrid[342][4] c_mygrid[343][4] c_mygrid[344][4] c_mygrid[345][4] c_mygrid[346][4] c_mygrid[347][4] c_mygrid[348][4] c_mygrid[349][4] & - c_mygrid[350][4] c_mygrid[351][4] c_mygrid[352][4] c_mygrid[353][4] c_mygrid[354][4] c_mygrid[355][4] c_mygrid[356][4] c_mygrid[357][4] c_mygrid[358][4] c_mygrid[359][4] & - c_mygrid[360][4] c_mygrid[361][4] c_mygrid[362][4] c_mygrid[363][4] c_mygrid[364][4] c_mygrid[365][4] c_mygrid[366][4] c_mygrid[367][4] c_mygrid[368][4] c_mygrid[369][4] & - c_mygrid[370][4] c_mygrid[371][4] c_mygrid[372][4] c_mygrid[373][4] c_mygrid[374][4] c_mygrid[375][4] c_mygrid[376][4] c_mygrid[377][4] c_mygrid[378][4] c_mygrid[379][4] & - c_mygrid[380][4] c_mygrid[381][4] c_mygrid[382][4] c_mygrid[383][4] c_mygrid[384][4] + c_mygrid[1][7] c_mygrid[2][7] c_mygrid[3][7] c_mygrid[4][7] c_mygrid[5][7] c_mygrid[6][7] c_mygrid[7][7] c_mygrid[8][7] c_mygrid[9][7] & + c_mygrid[10][7] c_mygrid[11][7] c_mygrid[12][7] c_mygrid[13][7] c_mygrid[14][7] c_mygrid[15][7] c_mygrid[16][7] c_mygrid[17][7] c_mygrid[18][7] c_mygrid[19][7] & + c_mygrid[20][7] c_mygrid[21][7] c_mygrid[22][7] c_mygrid[23][7] c_mygrid[24][7] c_mygrid[25][7] c_mygrid[26][7] c_mygrid[27][7] c_mygrid[28][7] c_mygrid[29][7] & + c_mygrid[30][7] c_mygrid[31][7] c_mygrid[32][7] c_mygrid[33][7] c_mygrid[34][7] c_mygrid[35][7] c_mygrid[36][7] c_mygrid[37][7] c_mygrid[38][7] c_mygrid[39][7] & + c_mygrid[40][7] c_mygrid[41][7] c_mygrid[42][7] c_mygrid[43][7] c_mygrid[44][7] c_mygrid[45][7] c_mygrid[46][7] c_mygrid[47][7] c_mygrid[48][7] c_mygrid[49][7] & + c_mygrid[50][7] c_mygrid[51][7] c_mygrid[52][7] c_mygrid[53][7] c_mygrid[54][7] c_mygrid[55][7] c_mygrid[56][7] c_mygrid[57][7] c_mygrid[58][7] c_mygrid[59][7] & + c_mygrid[60][7] c_mygrid[61][7] c_mygrid[62][7] c_mygrid[63][7] c_mygrid[64][7] c_mygrid[65][7] c_mygrid[66][7] c_mygrid[67][7] c_mygrid[68][7] c_mygrid[69][7] & + c_mygrid[70][7] c_mygrid[71][7] c_mygrid[72][7] c_mygrid[73][7] c_mygrid[74][7] c_mygrid[75][7] c_mygrid[76][7] c_mygrid[77][7] c_mygrid[78][7] c_mygrid[79][7] & + c_mygrid[80][7] c_mygrid[81][7] c_mygrid[82][7] c_mygrid[83][7] c_mygrid[84][7] c_mygrid[85][7] c_mygrid[86][7] c_mygrid[87][7] c_mygrid[88][7] c_mygrid[89][7] & + c_mygrid[90][7] c_mygrid[91][7] c_mygrid[92][7] c_mygrid[93][7] c_mygrid[94][7] c_mygrid[95][7] c_mygrid[96][7] c_mygrid[97][7] c_mygrid[98][7] c_mygrid[99][7] & + c_mygrid[101][7] c_mygrid[102][7] c_mygrid[103][7] c_mygrid[104][7] c_mygrid[105][7] c_mygrid[106][7] c_mygrid[107][7] c_mygrid[108][7] c_mygrid[109][7] & + c_mygrid[110][7] c_mygrid[111][7] c_mygrid[112][7] c_mygrid[113][7] c_mygrid[114][7] c_mygrid[115][7] c_mygrid[116][7] c_mygrid[117][7] c_mygrid[118][7] c_mygrid[119][7] & + c_mygrid[120][7] c_mygrid[121][7] c_mygrid[122][7] c_mygrid[123][7] c_mygrid[124][7] c_mygrid[125][7] c_mygrid[126][7] c_mygrid[127][7] c_mygrid[128][7] c_mygrid[129][7] & + c_mygrid[130][7] c_mygrid[131][7] c_mygrid[132][7] c_mygrid[133][7] c_mygrid[134][7] c_mygrid[135][7] c_mygrid[136][7] c_mygrid[137][7] c_mygrid[138][7] c_mygrid[139][7] & + c_mygrid[140][7] c_mygrid[141][7] c_mygrid[142][7] c_mygrid[143][7] c_mygrid[144][7] c_mygrid[145][7] c_mygrid[146][7] c_mygrid[147][7] c_mygrid[148][7] c_mygrid[149][7] & + c_mygrid[150][7] c_mygrid[151][7] c_mygrid[152][7] c_mygrid[153][7] c_mygrid[154][7] c_mygrid[155][7] c_mygrid[156][7] c_mygrid[157][7] c_mygrid[158][7] c_mygrid[159][7] & + c_mygrid[160][7] c_mygrid[161][7] c_mygrid[162][7] c_mygrid[163][7] c_mygrid[164][7] c_mygrid[165][7] c_mygrid[166][7] c_mygrid[167][7] c_mygrid[168][7] c_mygrid[169][7] & + c_mygrid[170][7] c_mygrid[171][7] c_mygrid[172][7] c_mygrid[173][7] c_mygrid[174][7] c_mygrid[175][7] c_mygrid[176][7] c_mygrid[177][7] c_mygrid[178][7] c_mygrid[179][7] & + c_mygrid[180][7] c_mygrid[181][7] c_mygrid[182][7] c_mygrid[183][7] c_mygrid[184][7] c_mygrid[185][7] c_mygrid[186][7] c_mygrid[187][7] c_mygrid[188][7] c_mygrid[189][7] & + c_mygrid[190][7] c_mygrid[191][7] c_mygrid[192][7] c_mygrid[193][7] c_mygrid[194][7] c_mygrid[195][7] c_mygrid[196][7] c_mygrid[197][7] c_mygrid[198][7] c_mygrid[199][7] & + c_mygrid[201][7] c_mygrid[202][7] c_mygrid[203][7] c_mygrid[204][7] c_mygrid[205][7] c_mygrid[206][7] c_mygrid[207][7] c_mygrid[208][7] c_mygrid[209][7] & + c_mygrid[210][7] c_mygrid[211][7] c_mygrid[212][7] c_mygrid[213][7] c_mygrid[214][7] c_mygrid[215][7] c_mygrid[216][7] c_mygrid[217][7] c_mygrid[218][7] c_mygrid[219][7] & + c_mygrid[220][7] c_mygrid[221][7] c_mygrid[222][7] c_mygrid[223][7] c_mygrid[224][7] c_mygrid[225][7] c_mygrid[226][7] c_mygrid[227][7] c_mygrid[228][7] c_mygrid[229][7] & + c_mygrid[230][7] c_mygrid[231][7] c_mygrid[232][7] c_mygrid[233][7] c_mygrid[234][7] c_mygrid[235][7] c_mygrid[236][7] c_mygrid[237][7] c_mygrid[238][7] c_mygrid[239][7] & + c_mygrid[240][7] c_mygrid[241][7] c_mygrid[242][7] c_mygrid[243][7] c_mygrid[244][7] c_mygrid[245][7] c_mygrid[246][7] c_mygrid[247][7] c_mygrid[248][7] c_mygrid[249][7] & + c_mygrid[250][7] c_mygrid[251][7] c_mygrid[252][7] c_mygrid[253][7] c_mygrid[254][7] c_mygrid[255][7] c_mygrid[256][7] c_mygrid[257][7] c_mygrid[258][7] c_mygrid[259][7] & + c_mygrid[260][7] c_mygrid[261][7] c_mygrid[262][7] c_mygrid[263][7] c_mygrid[264][7] c_mygrid[265][7] c_mygrid[266][7] c_mygrid[267][7] c_mygrid[268][7] c_mygrid[269][7] & + c_mygrid[270][7] c_mygrid[271][7] c_mygrid[272][7] c_mygrid[273][7] c_mygrid[274][7] c_mygrid[275][7] c_mygrid[276][7] c_mygrid[277][7] c_mygrid[278][7] c_mygrid[279][7] & + c_mygrid[280][7] c_mygrid[281][7] c_mygrid[282][7] c_mygrid[283][7] c_mygrid[284][7] c_mygrid[285][7] c_mygrid[286][7] c_mygrid[287][7] c_mygrid[288][7] c_mygrid[289][7] & + c_mygrid[290][7] c_mygrid[291][7] c_mygrid[292][7] c_mygrid[293][7] c_mygrid[294][7] c_mygrid[295][7] c_mygrid[296][7] c_mygrid[297][7] c_mygrid[298][7] c_mygrid[299][7] & + c_mygrid[301][7] c_mygrid[302][7] c_mygrid[303][7] c_mygrid[304][7] c_mygrid[305][7] c_mygrid[306][7] c_mygrid[307][7] c_mygrid[308][7] c_mygrid[309][7] & + c_mygrid[310][7] c_mygrid[311][7] c_mygrid[312][7] c_mygrid[313][7] c_mygrid[314][7] c_mygrid[315][7] c_mygrid[316][7] c_mygrid[317][7] c_mygrid[318][7] c_mygrid[319][7] & + c_mygrid[320][7] c_mygrid[321][7] c_mygrid[322][7] c_mygrid[323][7] c_mygrid[324][7] c_mygrid[325][7] c_mygrid[326][7] c_mygrid[327][7] c_mygrid[328][7] c_mygrid[329][7] & + c_mygrid[330][7] c_mygrid[331][7] c_mygrid[332][7] c_mygrid[333][7] c_mygrid[334][7] c_mygrid[335][7] c_mygrid[336][7] c_mygrid[337][7] c_mygrid[338][7] c_mygrid[339][7] & + c_mygrid[340][7] c_mygrid[341][7] c_mygrid[342][7] c_mygrid[343][7] c_mygrid[344][7] c_mygrid[345][7] c_mygrid[346][7] c_mygrid[347][7] c_mygrid[348][7] c_mygrid[349][7] & + c_mygrid[350][7] c_mygrid[351][7] c_mygrid[352][7] c_mygrid[353][7] c_mygrid[354][7] c_mygrid[355][7] c_mygrid[356][7] c_mygrid[357][7] c_mygrid[358][7] c_mygrid[359][7] & + c_mygrid[360][7] c_mygrid[361][7] c_mygrid[362][7] c_mygrid[363][7] c_mygrid[364][7] c_mygrid[365][7] c_mygrid[366][7] c_mygrid[367][7] c_mygrid[368][7] c_mygrid[369][7] & + c_mygrid[370][7] c_mygrid[371][7] c_mygrid[372][7] c_mygrid[373][7] c_mygrid[374][7] c_mygrid[375][7] c_mygrid[376][7] c_mygrid[377][7] c_mygrid[378][7] c_mygrid[379][7] & + c_mygrid[380][7] c_mygrid[381][7] c_mygrid[382][7] c_mygrid[383][7] c_mygrid[384][7] thermo_modify norm yes From 4bfb5051237421cdef4501f9a3edb23f52589629 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Mon, 25 May 2020 16:35:50 -0600 Subject: [PATCH 10/91] Added reviewer response doc --- src/ReviewerResponse.tex | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/ReviewerResponse.tex diff --git a/src/ReviewerResponse.tex b/src/ReviewerResponse.tex new file mode 100644 index 0000000000..e29d756d78 --- /dev/null +++ b/src/ReviewerResponse.tex @@ -0,0 +1,59 @@ +\pdfoutput=1 +\documentclass[onecolumn,prb,showpacs,aps,superscriptaddress]{revtex4-1} +%\documentclass[prb,showpacs,aps,superscriptaddress]{revtex4-1} + + +\usepackage[english]{babel} +\usepackage[ansinew]{inputenc} +\usepackage{times} +\usepackage{graphicx} +\usepackage{graphics} +\usepackage{amsmath} +\usepackage{amsfonts} +\usepackage{amssymb} +\usepackage{amsbsy} +\usepackage{dsfont} +\usepackage{epstopdf} +\usepackage{makeidx} +%\usepackage{subfigure} +\usepackage{color} +\usepackage{pgf} +\usepackage{bm} +\usepackage{tikz} +%\usepackage[normalem]{ulem} +\usepackage{graphicx} % needed for figures +\usepackage{dcolumn} % needed for some tables +\usepackage{bm} % for math +\usepackage{amssymb} % for math + + +\begin{document} + +{\bf Title Here} + + +\vspace{1cm} + +We thank the reviewers for their careful reading of the manuscript and their suggestions for improvement. We have updated the manuscript accordingly. Please see below for our detailed responses to the review comments. + +\vspace{2cm} + + +\textbf{\underline{Reviewer 1:}} +\begin{itemize} + \item \textbf{Review Comment 1:} Blah blah + \item \textbf{Author Reply 1:} Thank you for your review. We agree making the blha blah is a good idea. We added the following sentence to the Conclusions to address this point \\ + ``Blah blah'' + +\end{itemize} + +\textbf{\underline{Reviewer 2:}} +\begin{itemize} + \item \textbf{Review Comment 1:} Blah blah + \item \textbf{Author Reply 1:} Blah blah \\ + +\end{itemize} + +\end{document} + + From 4295dd2dbcc9aae860607e823c440169c1cc23ae Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Mon, 25 May 2020 17:09:32 -0600 Subject: [PATCH 11/91] Wrong number --- src/ReviewerResponse.tex | 59 ---------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 src/ReviewerResponse.tex diff --git a/src/ReviewerResponse.tex b/src/ReviewerResponse.tex deleted file mode 100644 index e29d756d78..0000000000 --- a/src/ReviewerResponse.tex +++ /dev/null @@ -1,59 +0,0 @@ -\pdfoutput=1 -\documentclass[onecolumn,prb,showpacs,aps,superscriptaddress]{revtex4-1} -%\documentclass[prb,showpacs,aps,superscriptaddress]{revtex4-1} - - -\usepackage[english]{babel} -\usepackage[ansinew]{inputenc} -\usepackage{times} -\usepackage{graphicx} -\usepackage{graphics} -\usepackage{amsmath} -\usepackage{amsfonts} -\usepackage{amssymb} -\usepackage{amsbsy} -\usepackage{dsfont} -\usepackage{epstopdf} -\usepackage{makeidx} -%\usepackage{subfigure} -\usepackage{color} -\usepackage{pgf} -\usepackage{bm} -\usepackage{tikz} -%\usepackage[normalem]{ulem} -\usepackage{graphicx} % needed for figures -\usepackage{dcolumn} % needed for some tables -\usepackage{bm} % for math -\usepackage{amssymb} % for math - - -\begin{document} - -{\bf Title Here} - - -\vspace{1cm} - -We thank the reviewers for their careful reading of the manuscript and their suggestions for improvement. We have updated the manuscript accordingly. Please see below for our detailed responses to the review comments. - -\vspace{2cm} - - -\textbf{\underline{Reviewer 1:}} -\begin{itemize} - \item \textbf{Review Comment 1:} Blah blah - \item \textbf{Author Reply 1:} Thank you for your review. We agree making the blha blah is a good idea. We added the following sentence to the Conclusions to address this point \\ - ``Blah blah'' - -\end{itemize} - -\textbf{\underline{Reviewer 2:}} -\begin{itemize} - \item \textbf{Review Comment 1:} Blah blah - \item \textbf{Author Reply 1:} Blah blah \\ - -\end{itemize} - -\end{document} - - From cf6570d81283a356915bd4379ca807837988ccc9 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 2 Jul 2021 15:06:19 -0600 Subject: [PATCH 12/91] Tweaked comments in grid examples --- examples/snap/in.grid | 3 +++ examples/snap/in.grid.tri | 26 ++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/examples/snap/in.grid b/examples/snap/in.grid index 2702fccad1..44c42673e0 100644 --- a/examples/snap/in.grid +++ b/examples/snap/in.grid @@ -1,5 +1,8 @@ # Demonstrate bispectrum computes +# CORRECTNESS: thermo output for c_mygrid[*][1] and c_mygrid[*][8] should +# match the values in dump_b: 108.173 3.21778 0.712238 7.06634 1.04273 + # Initialize simulation variable nsteps index 0 diff --git a/examples/snap/in.grid.tri b/examples/snap/in.grid.tri index c984799e09..fc71c3a43f 100644 --- a/examples/snap/in.grid.tri +++ b/examples/snap/in.grid.tri @@ -1,5 +1,15 @@ # Demonstrate bispectrum computes +# This triclinic cell has 6 times the volume of a single bcc cube +# and contains 12 atoms. It is a 3x2x1 supercell +# with each unit cell containing 2 atoms and the +# reduced lattice vectors are [1 0 0], [1 1 0], and [1 1 1]. +# The grid is listed in x-fastest order +# CORRECTNESS: thermo output for c_mygrid[*][7] should contain +# the same 2 values that appear in c_mygrid[*][7] for in.grid, +# 7.0663376 and 13.808803, corresponding to atom and insterstitial sites, +# respectively, and with occurrences 12 and 36, respectively. + # Initialize simulation variable nsteps index 0 @@ -11,13 +21,17 @@ variable ngridx equal 3*${ngrid} variable ngridy equal 2*${ngrid} variable ngridz equal 1*${ngrid} +variable nrepx equal 1*${nrep} +variable nrepy equal 1*${nrep} +variable nrepz equal 1*${nrep} + units metal # generate the box and atom positions using a BCC lattice -variable nx equal ${nrep} -variable ny equal ${nrep} -variable nz equal ${nrep} +variable nx equal ${nrepx} +variable ny equal ${nrepy} +variable nz equal ${nrepz} boundary p p p @@ -78,7 +92,7 @@ thermo_style custom step temp ke pe vol & c_mygrid[70][7] c_mygrid[71][7] c_mygrid[72][7] c_mygrid[73][7] c_mygrid[74][7] c_mygrid[75][7] c_mygrid[76][7] c_mygrid[77][7] c_mygrid[78][7] c_mygrid[79][7] & c_mygrid[80][7] c_mygrid[81][7] c_mygrid[82][7] c_mygrid[83][7] c_mygrid[84][7] c_mygrid[85][7] c_mygrid[86][7] c_mygrid[87][7] c_mygrid[88][7] c_mygrid[89][7] & c_mygrid[90][7] c_mygrid[91][7] c_mygrid[92][7] c_mygrid[93][7] c_mygrid[94][7] c_mygrid[95][7] c_mygrid[96][7] c_mygrid[97][7] c_mygrid[98][7] c_mygrid[99][7] & - c_mygrid[101][7] c_mygrid[102][7] c_mygrid[103][7] c_mygrid[104][7] c_mygrid[105][7] c_mygrid[106][7] c_mygrid[107][7] c_mygrid[108][7] c_mygrid[109][7] & + c_mygrid[100][7] c_mygrid[101][7] c_mygrid[102][7] c_mygrid[103][7] c_mygrid[104][7] c_mygrid[105][7] c_mygrid[106][7] c_mygrid[107][7] c_mygrid[108][7] c_mygrid[109][7] & c_mygrid[110][7] c_mygrid[111][7] c_mygrid[112][7] c_mygrid[113][7] c_mygrid[114][7] c_mygrid[115][7] c_mygrid[116][7] c_mygrid[117][7] c_mygrid[118][7] c_mygrid[119][7] & c_mygrid[120][7] c_mygrid[121][7] c_mygrid[122][7] c_mygrid[123][7] c_mygrid[124][7] c_mygrid[125][7] c_mygrid[126][7] c_mygrid[127][7] c_mygrid[128][7] c_mygrid[129][7] & c_mygrid[130][7] c_mygrid[131][7] c_mygrid[132][7] c_mygrid[133][7] c_mygrid[134][7] c_mygrid[135][7] c_mygrid[136][7] c_mygrid[137][7] c_mygrid[138][7] c_mygrid[139][7] & @@ -88,7 +102,7 @@ thermo_style custom step temp ke pe vol & c_mygrid[170][7] c_mygrid[171][7] c_mygrid[172][7] c_mygrid[173][7] c_mygrid[174][7] c_mygrid[175][7] c_mygrid[176][7] c_mygrid[177][7] c_mygrid[178][7] c_mygrid[179][7] & c_mygrid[180][7] c_mygrid[181][7] c_mygrid[182][7] c_mygrid[183][7] c_mygrid[184][7] c_mygrid[185][7] c_mygrid[186][7] c_mygrid[187][7] c_mygrid[188][7] c_mygrid[189][7] & c_mygrid[190][7] c_mygrid[191][7] c_mygrid[192][7] c_mygrid[193][7] c_mygrid[194][7] c_mygrid[195][7] c_mygrid[196][7] c_mygrid[197][7] c_mygrid[198][7] c_mygrid[199][7] & - c_mygrid[201][7] c_mygrid[202][7] c_mygrid[203][7] c_mygrid[204][7] c_mygrid[205][7] c_mygrid[206][7] c_mygrid[207][7] c_mygrid[208][7] c_mygrid[209][7] & + c_mygrid[200][7] c_mygrid[201][7] c_mygrid[202][7] c_mygrid[203][7] c_mygrid[204][7] c_mygrid[205][7] c_mygrid[206][7] c_mygrid[207][7] c_mygrid[208][7] c_mygrid[209][7] & c_mygrid[210][7] c_mygrid[211][7] c_mygrid[212][7] c_mygrid[213][7] c_mygrid[214][7] c_mygrid[215][7] c_mygrid[216][7] c_mygrid[217][7] c_mygrid[218][7] c_mygrid[219][7] & c_mygrid[220][7] c_mygrid[221][7] c_mygrid[222][7] c_mygrid[223][7] c_mygrid[224][7] c_mygrid[225][7] c_mygrid[226][7] c_mygrid[227][7] c_mygrid[228][7] c_mygrid[229][7] & c_mygrid[230][7] c_mygrid[231][7] c_mygrid[232][7] c_mygrid[233][7] c_mygrid[234][7] c_mygrid[235][7] c_mygrid[236][7] c_mygrid[237][7] c_mygrid[238][7] c_mygrid[239][7] & @@ -98,7 +112,7 @@ thermo_style custom step temp ke pe vol & c_mygrid[270][7] c_mygrid[271][7] c_mygrid[272][7] c_mygrid[273][7] c_mygrid[274][7] c_mygrid[275][7] c_mygrid[276][7] c_mygrid[277][7] c_mygrid[278][7] c_mygrid[279][7] & c_mygrid[280][7] c_mygrid[281][7] c_mygrid[282][7] c_mygrid[283][7] c_mygrid[284][7] c_mygrid[285][7] c_mygrid[286][7] c_mygrid[287][7] c_mygrid[288][7] c_mygrid[289][7] & c_mygrid[290][7] c_mygrid[291][7] c_mygrid[292][7] c_mygrid[293][7] c_mygrid[294][7] c_mygrid[295][7] c_mygrid[296][7] c_mygrid[297][7] c_mygrid[298][7] c_mygrid[299][7] & - c_mygrid[301][7] c_mygrid[302][7] c_mygrid[303][7] c_mygrid[304][7] c_mygrid[305][7] c_mygrid[306][7] c_mygrid[307][7] c_mygrid[308][7] c_mygrid[309][7] & + c_mygrid[300][7] c_mygrid[301][7] c_mygrid[302][7] c_mygrid[303][7] c_mygrid[304][7] c_mygrid[305][7] c_mygrid[306][7] c_mygrid[307][7] c_mygrid[308][7] c_mygrid[309][7] & c_mygrid[310][7] c_mygrid[311][7] c_mygrid[312][7] c_mygrid[313][7] c_mygrid[314][7] c_mygrid[315][7] c_mygrid[316][7] c_mygrid[317][7] c_mygrid[318][7] c_mygrid[319][7] & c_mygrid[320][7] c_mygrid[321][7] c_mygrid[322][7] c_mygrid[323][7] c_mygrid[324][7] c_mygrid[325][7] c_mygrid[326][7] c_mygrid[327][7] c_mygrid[328][7] c_mygrid[329][7] & c_mygrid[330][7] c_mygrid[331][7] c_mygrid[332][7] c_mygrid[333][7] c_mygrid[334][7] c_mygrid[335][7] c_mygrid[336][7] c_mygrid[337][7] c_mygrid[338][7] c_mygrid[339][7] & From 442585313c4e8c9ba03419987a44266412acaa33 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 2 Jul 2021 15:11:14 -0600 Subject: [PATCH 13/91] Test --- examples/snap/in.grid.tri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/snap/in.grid.tri b/examples/snap/in.grid.tri index fc71c3a43f..da87774107 100644 --- a/examples/snap/in.grid.tri +++ b/examples/snap/in.grid.tri @@ -1,4 +1,4 @@ -# Demonstrate bispectrum computes +# Demonstrate bispectrum computes for triclinic cell # This triclinic cell has 6 times the volume of a single bcc cube # and contains 12 atoms. It is a 3x2x1 supercell From e102864c2dd9bf56b9a87808e98ac9b7042cff41 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 2 Jul 2021 15:13:40 -0600 Subject: [PATCH 14/91] Test2 --- examples/snap/in.grid.tri | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/snap/in.grid.tri b/examples/snap/in.grid.tri index da87774107..a5b2453c3b 100644 --- a/examples/snap/in.grid.tri +++ b/examples/snap/in.grid.tri @@ -1,6 +1,7 @@ # Demonstrate bispectrum computes for triclinic cell -# This triclinic cell has 6 times the volume of a single bcc cube +# This triclinic cell has 6 times the volume of the single +# unit cell used by in.grid # and contains 12 atoms. It is a 3x2x1 supercell # with each unit cell containing 2 atoms and the # reduced lattice vectors are [1 0 0], [1 1 0], and [1 1 1]. From 01475cb3a84005ddde51411c97c4f5f1eb353d71 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 2 Jul 2021 15:35:59 -0600 Subject: [PATCH 15/91] Test3 --- examples/snap/in.grid.tri | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/snap/in.grid.tri b/examples/snap/in.grid.tri index a5b2453c3b..201f763eeb 100644 --- a/examples/snap/in.grid.tri +++ b/examples/snap/in.grid.tri @@ -131,3 +131,4 @@ dump mydump_b all custom 1000 dump_b id c_b[*] run 0 + From 39039d261f39966bad202ded3c5244065f323aa3 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 2 Jul 2021 15:37:49 -0600 Subject: [PATCH 16/91] Test6 --- examples/snap/in.grid.tri | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/snap/in.grid.tri b/examples/snap/in.grid.tri index 201f763eeb..f375c18c42 100644 --- a/examples/snap/in.grid.tri +++ b/examples/snap/in.grid.tri @@ -132,3 +132,4 @@ dump mydump_b all custom 1000 dump_b id c_b[*] run 0 + From e17ace385ddc6d00a485c1c8fd04989526462d6f Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 2 Jul 2021 17:47:45 -0600 Subject: [PATCH 17/91] First pass at distributed memory for grid --- src/SNAP/compute_sna_grid.cpp | 93 +++++++------- src/compute_grid.cpp | 224 ++++++++++++++++++++-------------- src/compute_grid.h | 17 ++- 3 files changed, 194 insertions(+), 140 deletions(-) diff --git a/src/SNAP/compute_sna_grid.cpp b/src/SNAP/compute_sna_grid.cpp index a9f3b6c3fb..196819008c 100644 --- a/src/SNAP/compute_sna_grid.cpp +++ b/src/SNAP/compute_sna_grid.cpp @@ -182,66 +182,75 @@ void ComputeSNAGrid::compute_array() snaptr->grow_rij(ntotal); - printf("ngrid = %d\n",ngrid); - for (int igrid = 0; igrid < ngrid; igrid++) { - if (!grid_local[igrid]) continue; - const double xtmp = grid[igrid][0]; - const double ytmp = grid[igrid][1]; - const double ztmp = grid[igrid][2]; + for (int iz = nzlo; iz <= nzhi; iz++) + for (int iy = nylo; iy <= nyhi; iy++) + for (int ix = nxlo; ix <= nxhi; ix++) { + const int igrid = iz*(nx*ny) + iy*nx + ix; + const double xtmp = grid[igrid][0]; + const double ytmp = grid[igrid][1]; + const double ztmp = grid[igrid][2]; - // rij[][3] = displacements between atom I and those neighbors - // inside = indices of neighbors of I within cutoff - // typej = types of neighbors of I within cutoff + // rij[][3] = displacements between atom I and those neighbors + // inside = indices of neighbors of I within cutoff + // typej = types of neighbors of I within cutoff - int ninside = 0; - for (int j = 0; j < ntotal; j++) { + int ninside = 0; + for (int j = 0; j < ntotal; j++) { - // check that j is in compute group + // check that j is in compute group - if (!(mask[j] & groupbit)) continue; + if (!(mask[j] & groupbit)) continue; - const double delx = xtmp - x[j][0]; - const double dely = ytmp - x[j][1]; - const double delz = ztmp - x[j][2]; - const double rsq = delx*delx + dely*dely + delz*delz; - int jtype = type[j]; - if (rsq < cutsq[jtype][jtype] && rsq>1e-20) { - // printf("ninside = %d\n",ninside); - snaptr->rij[ninside][0] = delx; - snaptr->rij[ninside][1] = dely; - snaptr->rij[ninside][2] = delz; - snaptr->inside[ninside] = j; - snaptr->wj[ninside] = wjelem[jtype]; - snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; - ninside++; - } - } + const double delx = xtmp - x[j][0]; + const double dely = ytmp - x[j][1]; + const double delz = ztmp - x[j][2]; + const double rsq = delx*delx + dely*dely + delz*delz; + int jtype = type[j]; + if (rsq < cutsq[jtype][jtype] && rsq>1e-20) { + snaptr->rij[ninside][0] = delx; + snaptr->rij[ninside][1] = dely; + snaptr->rij[ninside][2] = delz; + snaptr->inside[ninside] = j; + snaptr->wj[ninside] = wjelem[jtype]; + snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; + ninside++; + } + } - snaptr->compute_ui(ninside); - snaptr->compute_zi(); - snaptr->compute_bi(); - for (int icoeff = 0; icoeff < ncoeff; icoeff++) - grid[igrid][size_array_cols_base+icoeff] = snaptr->blist[icoeff]; - // printf("igrid = %d %g %g %g %d B0 = %g\n",igrid,xtmp,ytmp,ztmp,ninside,sna[igrid][size_array_cols_base+0]); - if (quadraticflag) { - int ncount = ncoeff; - for (int icoeff = 0; icoeff < ncoeff; icoeff++) { - double bi = snaptr->blist[icoeff]; + snaptr->compute_ui(ninside); + snaptr->compute_zi(); + snaptr->compute_bi(); + for (int icoeff = 0; icoeff < ncoeff; icoeff++) + gridlocal[size_array_cols_base+icoeff][iz][iy][ix] = snaptr->blist[icoeff]; + if (quadraticflag) { + int ncount = ncoeff; + for (int icoeff = 0; icoeff < ncoeff; icoeff++) { + double bi = snaptr->blist[icoeff]; - // diagonal element of quadratic matrix + // diagonal element of quadratic matrix - grid[igrid][size_array_cols_base+ncount++] = 0.5*bi*bi; + gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = 0.5*bi*bi; // upper-triangular elements of quadratic matrix for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - grid[igrid][size_array_cols_base+ncount++] = bi*snaptr->blist[jcoeff]; + gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = bi*snaptr->blist[jcoeff]; } } } + + for (int iz = nzlo; iz <= nzhi; iz++) + for (int iy = nylo; iy <= nyhi; iy++) + for (int ix = nxlo; ix <= nxhi; ix++) { + const int igrid = iz*(nx*ny) + iy*nx + ix; + for (int j = 0; j < nvalues; j++) + grid[igrid][size_array_cols_base + j] = gridlocal[size_array_cols_base + j][iz][iy][ix]; + } MPI_Allreduce(&grid[0][0],&gridall[0][0],ngrid*size_array_cols,MPI_DOUBLE,MPI_SUM,world); + } + /* ---------------------------------------------------------------------- memory usage ------------------------------------------------------------------------- */ diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 011dafa030..b16a51b739 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -21,13 +21,14 @@ #include "force.h" #include "memory.h" #include "error.h" +#include "comm.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), grid(NULL), grid_local(NULL) + Compute(lmp, narg, arg), grid(NULL), local_flags(NULL), gridlocal(NULL) { if (narg < 6) error->all(FLERR,"Illegal compute grid command"); @@ -59,7 +60,8 @@ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : ComputeGrid::~ComputeGrid() { memory->destroy(grid); - memory->destroy(grid_local); + memory->destroy(local_flags); + memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); } /* ---------------------------------------------------------------------- */ @@ -72,7 +74,118 @@ void ComputeGrid::init() void ComputeGrid::setup() { - + + set_grid_global(); + set_grid_local(); + allocate(); + assign_coords(); + assign_local_flags(); +} + +/* ---------------------------------------------------------------------- + convert global array index to box coords +------------------------------------------------------------------------- */ + +void ComputeGrid::grid2x(int igrid, double *x) +{ + int iz = igrid / (nx*ny); + igrid -= iz * (nx*ny); + int iy = igrid / nx; + igrid -= iy * nx; + int ix = igrid; + + x[0] = ix*delx; + x[1] = iy*dely; + x[2] = iz*delz; + + if (triclinic) domain->lamda2x(x, x); + +} + +/* ---------------------------------------------------------------------- + check if grid point is local +------------------------------------------------------------------------- */ + +int ComputeGrid::check_local(int igrid) +{ + double x[3]; + + int iz = igrid / (nx*ny); + igrid -= iz * (nx*ny); + int iy = igrid / nx; + igrid -= iy * nx; + int ix = igrid; + + x[0] = ix*delx; + x[1] = iy*dely; + x[2] = iz*delz; + + int islocal = + x[0] >= sublo[0] && x[0] < subhi[0] && + x[1] >= sublo[1] && x[1] < subhi[1] && + x[2] >= sublo[2] && x[2] < subhi[2]; + + return islocal; +} + +/* ---------------------------------------------------------------------- + copy coords to global array +------------------------------------------------------------------------- */ + +void ComputeGrid::assign_coords() +{ + double x[3]; + for (int igrid = 0; igrid < ngrid; igrid++) { + grid2x(igrid,x); + grid[igrid][0] = x[0]; + grid[igrid][1] = x[1]; + grid[igrid][2] = x[2]; + } +} + +/* ---------------------------------------------------------------------- + copy coords to global array +------------------------------------------------------------------------- */ + +void ComputeGrid::assign_local_flags() +{ + double x[3]; + for (int igrid = 0; igrid < ngrid; igrid++) { + if (check_local(igrid)) + local_flags[igrid] = 1; + else { + local_flags[igrid] = 0; + memset(grid[igrid],0,size_array_cols); + } + } +} + +/* ---------------------------------------------------------------------- + free and reallocate arrays +------------------------------------------------------------------------- */ + +void ComputeGrid::allocate() +{ + // allocate arrays + + memory->destroy(grid); + memory->destroy(local_flags); + memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + memory->create(grid,size_array_rows,size_array_cols,"grid:grid"); + memory->create(gridall,size_array_rows,size_array_cols,"grid:gridall"); + memory->create(local_flags,size_array_rows,"grid:local_flags"); + memory->create4d_offset(gridlocal,size_array_cols,nzlo,nzhi,nylo,nyhi, + nxlo,nxhi,"grid:gridlocal"); + array = gridall; +} + + +/* ---------------------------------------------------------------------- + set global grid +------------------------------------------------------------------------- */ + +void ComputeGrid::set_grid_global() +{ // calculate grid layout triclinic = domain->triclinic; @@ -100,105 +213,31 @@ void ComputeGrid::setup() delx = 1.0/delxinv; dely = 1.0/delyinv; delz = 1.0/delzinv; - - allocate(); - assign_grid_coords(); - assign_grid_local(); } /* ---------------------------------------------------------------------- - convert global array index to box coords + set local subset of grid that I own + n xyz lo/hi = 3d brick that I own (inclusive) ------------------------------------------------------------------------- */ -void ComputeGrid::grid2x(int igrid, double *x) +void ComputeGrid::set_grid_local() { - int iz = igrid / (nx*ny); - igrid -= iz * (nx*ny); - int iy = igrid / nx; - igrid -= iy * nx; - int ix = igrid; + // global indices of grid range from 0 to N-1 + // nlo,nhi = lower/upper limits of the 3d sub-brick of + // global grid that I own without ghost cells - x[0] = ix*delx; - x[1] = iy*dely; - x[2] = iz*delz; + nxlo = static_cast (comm->xsplit[comm->myloc[0]] * nx); + nxhi = static_cast (comm->xsplit[comm->myloc[0]+1] * nx) - 1; - if (triclinic) domain->lamda2x(x, x); + nylo = static_cast (comm->ysplit[comm->myloc[1]] * ny); + nyhi = static_cast (comm->ysplit[comm->myloc[1]+1] * ny) - 1; + nzlo = static_cast (comm->zsplit[comm->myloc[2]] * nz); + nzhi = static_cast (comm->zsplit[comm->myloc[2]+1] * nz) - 1; + + ngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); } -/* ---------------------------------------------------------------------- - check if grid point is local -------------------------------------------------------------------------- */ - -int ComputeGrid::check_grid_local(int igrid) -{ - double x[3]; - - int iz = igrid / (nx*ny); - igrid -= iz * (nx*ny); - int iy = igrid / nx; - igrid -= iy * nx; - int ix = igrid; - - x[0] = ix*delx; - x[1] = iy*dely; - x[2] = iz*delz; - - int islocal = - x[0] >= sublo[0] && x[0] < subhi[0] && - x[1] >= sublo[1] && x[1] < subhi[1] && - x[2] >= sublo[2] && x[2] < subhi[2]; - - return islocal; -} - -/* ---------------------------------------------------------------------- - copy coords to global array -------------------------------------------------------------------------- */ - -void ComputeGrid::assign_grid_coords() -{ - double x[3]; - for (int igrid = 0; igrid < ngrid; igrid++) { - grid2x(igrid,x); - grid[igrid][0] = x[0]; - grid[igrid][1] = x[1]; - grid[igrid][2] = x[2]; - } -} - -/* ---------------------------------------------------------------------- - copy coords to global array -------------------------------------------------------------------------- */ - -void ComputeGrid::assign_grid_local() -{ - double x[3]; - for (int igrid = 0; igrid < ngrid; igrid++) { - if (check_grid_local(igrid)) - grid_local[igrid] = 1; - else { - grid_local[igrid] = 0; - memset(grid[igrid],0,size_array_cols); - } - } -} - -/* ---------------------------------------------------------------------- - free and reallocate arrays -------------------------------------------------------------------------- */ - -void ComputeGrid::allocate() -{ - // grow global array if necessary - - memory->destroy(grid); - memory->destroy(grid_local); - memory->create(grid,size_array_rows,size_array_cols,"grid:grid"); - memory->create(gridall,size_array_rows,size_array_cols,"grid:gridall"); - memory->create(grid_local,size_array_rows,"grid:grid_local"); - array = gridall; -} /* ---------------------------------------------------------------------- memory usage of local data ------------------------------------------------------------------------- */ @@ -207,6 +246,7 @@ double ComputeGrid::memory_usage() { double nbytes = size_array_rows*size_array_cols * sizeof(double); // grid - nbytes += size_array_rows*sizeof(int); // grid_local + nbytes += size_array_rows*sizeof(int); // local_flags + nbytes += size_array_cols*ngridlocal*sizeof(double); // gridlocal return nbytes; } diff --git a/src/compute_grid.h b/src/compute_grid.h index a1c938db2e..7e1a4d706b 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -30,11 +30,14 @@ class ComputeGrid : public Compute { double memory_usage(); protected: - int nx, ny, nz; // grid dimensions - int ngrid; // number of grid points + int nx, ny, nz; // global grid dimensions + int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive + int ngrid; // number of global grid points + int ngridlocal; // number of local grid points int nvalues; // number of values per grid point double **grid; // global grid double **gridall; // global grid summed over procs + double ****gridlocal; // local grid int triclinic; // triclinic flag double *boxlo, *prd; // box info (units real/ortho or reduced/tri) double *sublo, *subhi; // subdomain info (units real/ortho or reduced/tri) @@ -43,12 +46,14 @@ class ComputeGrid : public Compute { int nargbase; // number of base class args double cutmax; // largest cutoff distance int size_array_cols_base; // number of columns used for coords, etc. - int *grid_local; // local flag for each grid point + int *local_flags; // local flag for each grid point void allocate(); void grid2x(int, double*); // convert grid point to coord - void assign_grid_coords(); // assign coords for grid - void assign_grid_local(); // set local flag for each grid point - int check_grid_local(int); // check if grid point is local + void assign_coords(); // assign coords for grid + void assign_local_flags(); // set local flag for each grid point + int check_local(int); // check if grid point is local + void set_grid_global(); // set global grid + void set_grid_local(); // set bounds for local grid private: }; From 4c22f094de1c0a5632c3514974f75bc6e2c85c78 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 2 Jul 2021 18:15:55 -0600 Subject: [PATCH 18/91] Minor tweak --- src/compute_grid.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index b16a51b739..1939dd544e 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -74,7 +74,6 @@ void ComputeGrid::init() void ComputeGrid::setup() { - set_grid_global(); set_grid_local(); allocate(); @@ -149,7 +148,6 @@ void ComputeGrid::assign_coords() void ComputeGrid::assign_local_flags() { - double x[3]; for (int igrid = 0; igrid < ngrid; igrid++) { if (check_local(igrid)) local_flags[igrid] = 1; From 07db7a40955ebb356ea16166985b1b296d1d8bb3 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 14 Jul 2021 13:35:05 -0600 Subject: [PATCH 19/91] Changed to different check_local() --- src/SNAP/compute_sna_grid.cpp | 6 +-- src/compute_grid.cpp | 75 ++++++++++++++++++++++++++--------- src/compute_grid.h | 3 ++ 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/src/SNAP/compute_sna_grid.cpp b/src/SNAP/compute_sna_grid.cpp index 196819008c..d2c2ae74ca 100644 --- a/src/SNAP/compute_sna_grid.cpp +++ b/src/SNAP/compute_sna_grid.cpp @@ -231,10 +231,10 @@ void ComputeSNAGrid::compute_array() gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = 0.5*bi*bi; - // upper-triangular elements of quadratic matrix + // upper-triangular elements of quadratic matrix - for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = bi*snaptr->blist[jcoeff]; + for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) + gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = bi*snaptr->blist[jcoeff]; } } } diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 1939dd544e..3cbcb2c2db 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -53,6 +53,7 @@ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : size_array_rows = ngrid = nx*ny*nz; size_array_cols_base = 3; + gridlocal_allocated = 0; } /* ---------------------------------------------------------------------- */ @@ -61,7 +62,8 @@ ComputeGrid::~ComputeGrid() { memory->destroy(grid); memory->destroy(local_flags); - memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + if (gridlocal_allocated) + memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); } /* ---------------------------------------------------------------------- */ @@ -101,28 +103,59 @@ void ComputeGrid::grid2x(int igrid, double *x) } +/* ---------------------------------------------------------------------- + convert global array index to box coords +------------------------------------------------------------------------- */ + +void ComputeGrid::grid2ix(int igrid, int& ix, int& iy, int& iz) +{ + iz = igrid / (nx*ny); + igrid -= iz * (nx*ny); + iy = igrid / nx; + igrid -= iy * nx; + ix = igrid; +} + +// /* ---------------------------------------------------------------------- +// check if grid point is local +// ------------------------------------------------------------------------- */ + +// int ComputeGrid::check_local(int igrid) +// { +// double x[3]; + +// int iz = igrid / (nx*ny); +// igrid -= iz * (nx*ny); +// int iy = igrid / nx; +// igrid -= iy * nx; +// int ix = igrid; + +// x[0] = ix*delx; +// x[1] = iy*dely; +// x[2] = iz*delz; + +// int islocal = +// x[0] >= sublo[0] && x[0] < subhi[0] && +// x[1] >= sublo[1] && x[1] < subhi[1] && +// x[2] >= sublo[2] && x[2] < subhi[2]; + +// return islocal; +// } + /* ---------------------------------------------------------------------- check if grid point is local ------------------------------------------------------------------------- */ int ComputeGrid::check_local(int igrid) { - double x[3]; + int ix, iy, iz; - int iz = igrid / (nx*ny); - igrid -= iz * (nx*ny); - int iy = igrid / nx; - igrid -= iy * nx; - int ix = igrid; - - x[0] = ix*delx; - x[1] = iy*dely; - x[2] = iz*delz; + grid2ix(igrid, ix, iy, iz); int islocal = - x[0] >= sublo[0] && x[0] < subhi[0] && - x[1] >= sublo[1] && x[1] < subhi[1] && - x[2] >= sublo[2] && x[2] < subhi[2]; + ix >= nxlo && ix <= nxhi && + iy >= nylo && iy <= nyhi && + iz >= nzlo && iz <= nzhi; return islocal; } @@ -153,7 +186,7 @@ void ComputeGrid::assign_local_flags() local_flags[igrid] = 1; else { local_flags[igrid] = 0; - memset(grid[igrid],0,size_array_cols); + memset(grid[igrid],0,size_array_cols * sizeof(double)); } } } @@ -168,12 +201,16 @@ void ComputeGrid::allocate() memory->destroy(grid); memory->destroy(local_flags); - memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + if (gridlocal_allocated) + memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); memory->create(grid,size_array_rows,size_array_cols,"grid:grid"); memory->create(gridall,size_array_rows,size_array_cols,"grid:gridall"); memory->create(local_flags,size_array_rows,"grid:local_flags"); - memory->create4d_offset(gridlocal,size_array_cols,nzlo,nzhi,nylo,nyhi, - nxlo,nxhi,"grid:gridlocal"); + if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { + gridlocal_allocated = 1; + memory->create4d_offset(gridlocal,size_array_cols,nzlo,nzhi,nylo,nyhi, + nxlo,nxhi,"grid:gridlocal"); + } array = gridall; } @@ -234,6 +271,8 @@ void ComputeGrid::set_grid_local() nzhi = static_cast (comm->zsplit[comm->myloc[2]+1] * nz) - 1; ngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); + + printf("me = %d n = %d x %d %d y %d %d z %d %d \n", comm->me, ngridlocal, nxlo, nxhi, nylo, nyhi, nzlo, nzhi); } /* ---------------------------------------------------------------------- diff --git a/src/compute_grid.h b/src/compute_grid.h index 7e1a4d706b..1b2797732d 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -47,8 +47,11 @@ class ComputeGrid : public Compute { double cutmax; // largest cutoff distance int size_array_cols_base; // number of columns used for coords, etc. int *local_flags; // local flag for each grid point + int gridlocal_allocated; // shows if gridlocal allocated + void allocate(); void grid2x(int, double*); // convert grid point to coord + void grid2ix(int, int&, int&, int&); // convert grid point to ix, iy, iz void assign_coords(); // assign coords for grid void assign_local_flags(); // set local flag for each grid point int check_local(int); // check if grid point is local From 6378d1d128612d3ee6f214bebcb88df54604a7fc Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 14 Jul 2021 13:50:49 -0600 Subject: [PATCH 20/91] Moved SNAP files to ML-SNAP --- src/{SNAP => ML-SNAP}/compute_sna_grid.cpp | 0 src/{SNAP => ML-SNAP}/compute_sna_grid.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/{SNAP => ML-SNAP}/compute_sna_grid.cpp (100%) rename src/{SNAP => ML-SNAP}/compute_sna_grid.h (100%) diff --git a/src/SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp similarity index 100% rename from src/SNAP/compute_sna_grid.cpp rename to src/ML-SNAP/compute_sna_grid.cpp diff --git a/src/SNAP/compute_sna_grid.h b/src/ML-SNAP/compute_sna_grid.h similarity index 100% rename from src/SNAP/compute_sna_grid.h rename to src/ML-SNAP/compute_sna_grid.h From 614c3bc5b9905ba6c306a74208636e9eb9cd76c1 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Mon, 19 Jul 2021 14:44:08 -0600 Subject: [PATCH 21/91] Merged in old compute-grid --- src/ML-SNAP/compute_sna_grid.cpp | 122 +++++++++++++++++++++++-------- src/ML-SNAP/compute_sna_grid.h | 6 +- src/ML-SNAP/compute_snap.cpp | 2 - src/compute_grid.cpp | 6 +- 4 files changed, 98 insertions(+), 38 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index d2c2ae74ca..89e4b450bb 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -13,8 +13,6 @@ #include "compute_grid.h" #include "compute_sna_grid.h" -#include -#include #include "sna.h" #include "atom.h" #include "update.h" @@ -27,17 +25,20 @@ #include "comm.h" #include "memory.h" #include "error.h" +#include "tokenizer.h" + +#include +#include using namespace LAMMPS_NS; ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : - ComputeGrid(lmp, narg, arg), cutsq(NULL), sna(NULL), - radelem(NULL), wjelem(NULL) + ComputeGrid(lmp, narg, arg), cutsq(nullptr), + radelem(nullptr), wjelem(nullptr) { - double rmin0, rfac0; - int twojmax, switchflag, bzeroflag; - radelem = NULL; - wjelem = NULL; + + double rfac0, rmin0; + int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; // skip over arguments used by base class // so that argument positions are identical to @@ -57,10 +58,14 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : switchflag = 1; bzeroflag = 1; quadraticflag = 0; + chemflag = 0; + bnormflag = 0; + wselfallflag = 0; + nelements = 1; + + // process required arguments - // offset by 1 to match up with types - - memory->create(radelem,ntypes+1,"sna/grid:radelem"); + memory->create(radelem,ntypes+1,"sna/grid:radelem"); // offset by 1 to match up with types memory->create(wjelem,ntypes+1,"sna/grid:wjelem"); rcutfac = atof(arg[3]); @@ -112,12 +117,36 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Illegal compute sna/grid command"); quadraticflag = atoi(arg[iarg+1]); iarg += 2; + } else if (strcmp(arg[iarg],"chem") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid command"); + chemflag = 1; + memory->create(map,ntypes+1,"compute_sna_grid:map"); + nelements = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + for (int i = 0; i < ntypes; i++) { + int jelem = utils::inumeric(FLERR,arg[iarg+2+i],false,lmp); + if (jelem < 0 || jelem >= nelements) + error->all(FLERR,"Illegal compute sna/grid command"); + map[i+1] = jelem; + } + iarg += 2+ntypes; + } else if (strcmp(arg[iarg],"bnormflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid command"); + bnormflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"wselfallflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid command"); + wselfallflag = atoi(arg[iarg+1]); + iarg += 2; } else error->all(FLERR,"Illegal compute sna/grid command"); } - snaptr = new SNA(lmp,rfac0,twojmax, - rmin0,switchflag,bzeroflag); + snaptr = new SNA(lmp, rfac0, twojmax, + rmin0, switchflag, bzeroflag, + chemflag, bnormflag, wselfallflag, nelements); ncoeff = snaptr->ncoeff; nvalues = ncoeff; @@ -130,18 +159,19 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : ComputeSNAGrid::~ComputeSNAGrid() { - memory->destroy(sna); memory->destroy(radelem); memory->destroy(wjelem); memory->destroy(cutsq); delete snaptr; + + if (chemflag) memory->destroy(map); } /* ---------------------------------------------------------------------- */ void ComputeSNAGrid::init() { - if (force->pair == NULL) + if (force->pair == nullptr) error->all(FLERR,"Compute sna/grid requires a pair style be defined"); if (cutmax > force->pair->cutforce) @@ -170,12 +200,28 @@ void ComputeSNAGrid::compute_array() { invoked_array = update->ntimestep; - int * const type = atom->type; + // invoke full neighbor list (will copy or build if necessary) + + // neighbor->build_one(list); + + int mynxlo = static_cast (comm->xsplit[comm->myloc[0]] * nx); + int mynxhi = static_cast (comm->xsplit[comm->myloc[0]+1] * nx) - 1; + + int mynylo = static_cast (comm->ysplit[comm->myloc[1]] * ny); + int mynyhi = static_cast (comm->ysplit[comm->myloc[1]+1] * ny) - 1; + + int mynzlo = static_cast (comm->zsplit[comm->myloc[2]] * nz); + int mynzhi = static_cast (comm->zsplit[comm->myloc[2]+1] * nz) - 1; + + int myngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); + + printf("me = %d n = %d x %d %d y %d %d z %d %d \n", comm->me, myngridlocal, mynxlo, mynxhi, mynylo, mynyhi, mynzlo, mynzhi); // compute sna for each gridpoint double** const x = atom->x; const int* const mask = atom->mask; + int * const type = atom->type; const int ntotal = atom->nlocal + atom->nghost; // insure rij, inside, and typej are of size jnum @@ -190,6 +236,14 @@ void ComputeSNAGrid::compute_array() const double ytmp = grid[igrid][1]; const double ztmp = grid[igrid][2]; + // currently, all grid points are type 1 + + const int itype = 1; + int ielem = 0; + if (chemflag) + ielem = map[itype]; + const double radi = radelem[itype]; + // rij[][3] = displacements between atom I and those neighbors // inside = indices of neighbors of I within cutoff // typej = types of neighbors of I within cutoff @@ -206,6 +260,9 @@ void ComputeSNAGrid::compute_array() const double delz = ztmp - x[j][2]; const double rsq = delx*delx + dely*dely + delz*delz; int jtype = type[j]; + int jelem = 0; + if (chemflag) + jelem = map[jtype]; if (rsq < cutsq[jtype][jtype] && rsq>1e-20) { snaptr->rij[ninside][0] = delx; snaptr->rij[ninside][1] = dely; @@ -213,32 +270,33 @@ void ComputeSNAGrid::compute_array() snaptr->inside[ninside] = j; snaptr->wj[ninside] = wjelem[jtype]; snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; + snaptr->element[ninside] = jelem; // element index for multi-element snap ninside++; } } - snaptr->compute_ui(ninside); + snaptr->compute_ui(ninside, ielem); snaptr->compute_zi(); - snaptr->compute_bi(); + snaptr->compute_bi(ielem); + + // linear contributions + for (int icoeff = 0; icoeff < ncoeff; icoeff++) gridlocal[size_array_cols_base+icoeff][iz][iy][ix] = snaptr->blist[icoeff]; + + // quadratic contributions + if (quadraticflag) { int ncount = ncoeff; for (int icoeff = 0; icoeff < ncoeff; icoeff++) { - double bi = snaptr->blist[icoeff]; - - // diagonal element of quadratic matrix - - gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = 0.5*bi*bi; - - // upper-triangular elements of quadratic matrix - + double bveci = snaptr->blist[icoeff]; + gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = 0.5*bveci*bveci; for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = bi*snaptr->blist[jcoeff]; + gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = bveci*snaptr->blist[jcoeff]; + } + } } - } - } - + for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { @@ -257,7 +315,9 @@ void ComputeSNAGrid::compute_array() double ComputeSNAGrid::memory_usage() { - double nbytes = snaptr->memory_usage(); // SNA object + double nbytes = snaptr->memory_usage(); // SNA object + int n = atom->ntypes+1; + nbytes += (double)n*sizeof(int); // map return nbytes; } diff --git a/src/ML-SNAP/compute_sna_grid.h b/src/ML-SNAP/compute_sna_grid.h index 0242a2962b..e2640081af 100644 --- a/src/ML-SNAP/compute_sna_grid.h +++ b/src/ML-SNAP/compute_sna_grid.h @@ -35,11 +35,13 @@ class ComputeSNAGrid : public ComputeGrid { private: int ncoeff; double **cutsq; - double **sna; double rcutfac; double *radelem; double *wjelem; - class SNA* snaptr; + int *map; // map types to [0,nelements) + int nelements, chemflag; + class SNA *snaptr; + double cutmax; int quadraticflag; }; diff --git a/src/ML-SNAP/compute_snap.cpp b/src/ML-SNAP/compute_snap.cpp index 63deff9f8f..6da7b78444 100644 --- a/src/ML-SNAP/compute_snap.cpp +++ b/src/ML-SNAP/compute_snap.cpp @@ -43,8 +43,6 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; - radelem = nullptr; - wjelem = nullptr; int ntypes = atom->ntypes; int nargmin = 6+2*ntypes; diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 3cbcb2c2db..3bdbddbc0c 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -41,9 +41,9 @@ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : int iarg = iarg0; if (strcmp(arg[iarg],"grid") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal compute grid command"); - nx = force->inumeric(FLERR,arg[iarg+1]); - ny = force->inumeric(FLERR,arg[iarg+2]); - nz = force->inumeric(FLERR,arg[iarg+3]); + nx = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + ny = utils::inumeric(FLERR,arg[iarg+2],false,lmp); + nz = utils::inumeric(FLERR,arg[iarg+3],false,lmp); if (nx <= 0 || ny <= 0 || nz <= 0) error->all(FLERR,"All grid dimensions must be positive"); iarg += 4; From 6d75912f7a567925c5f36ef19fd3f5e6d46d12ff Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 28 Jul 2021 18:34:08 -0600 Subject: [PATCH 22/91] Switched to local array --- src/ML-SNAP/compute_sna_grid.cpp | 30 +++++++++------ src/ML-SNAP/compute_sna_grid.h | 2 + src/compute_grid.cpp | 64 +++++++++++++++++++++++++------- 3 files changed, 71 insertions(+), 25 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 89e4b450bb..0b0c0674e4 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -22,6 +22,7 @@ #include "neigh_request.h" #include "force.h" #include "pair.h" +#include "domain.h" #include "comm.h" #include "memory.h" #include "error.h" @@ -196,26 +197,31 @@ void ComputeSNAGrid::init() /* ---------------------------------------------------------------------- */ +void ComputeSNAGrid::init_list(int /*id*/, NeighList *ptr) +{ + list = ptr; +} + +/* ---------------------------------------------------------------------- */ + void ComputeSNAGrid::compute_array() { invoked_array = update->ntimestep; - // invoke full neighbor list (will copy or build if necessary) + // // invoke full neighbor list (will copy or build if necessary) - // neighbor->build_one(list); + // neighbor->build_one(list); - int mynxlo = static_cast (comm->xsplit[comm->myloc[0]] * nx); - int mynxhi = static_cast (comm->xsplit[comm->myloc[0]+1] * nx) - 1; + // int mynxlo = static_cast (comm->xsplit[comm->myloc[0]] * nx); + // int mynxhi = static_cast (comm->xsplit[comm->myloc[0]+1] * nx) - 1; - int mynylo = static_cast (comm->ysplit[comm->myloc[1]] * ny); - int mynyhi = static_cast (comm->ysplit[comm->myloc[1]+1] * ny) - 1; + // int mynylo = static_cast (comm->ysplit[comm->myloc[1]] * ny); + // int mynyhi = static_cast (comm->ysplit[comm->myloc[1]+1] * ny) - 1; - int mynzlo = static_cast (comm->zsplit[comm->myloc[2]] * nz); - int mynzhi = static_cast (comm->zsplit[comm->myloc[2]+1] * nz) - 1; + // int mynzlo = static_cast (comm->zsplit[comm->myloc[2]] * nz); + // int mynzhi = static_cast (comm->zsplit[comm->myloc[2]+1] * nz) - 1; - int myngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); - - printf("me = %d n = %d x %d %d y %d %d z %d %d \n", comm->me, myngridlocal, mynxlo, mynxhi, mynylo, mynyhi, mynzlo, mynzhi); + // int myngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); // compute sna for each gridpoint @@ -263,7 +269,7 @@ void ComputeSNAGrid::compute_array() int jelem = 0; if (chemflag) jelem = map[jtype]; - if (rsq < cutsq[jtype][jtype] && rsq>1e-20) { + if (rsq < cutsq[jtype][jtype]) { snaptr->rij[ninside][0] = delx; snaptr->rij[ninside][1] = dely; snaptr->rij[ninside][2] = delz; diff --git a/src/ML-SNAP/compute_sna_grid.h b/src/ML-SNAP/compute_sna_grid.h index e2640081af..d40c87df9b 100644 --- a/src/ML-SNAP/compute_sna_grid.h +++ b/src/ML-SNAP/compute_sna_grid.h @@ -29,12 +29,14 @@ class ComputeSNAGrid : public ComputeGrid { ComputeSNAGrid(class LAMMPS *, int, char **); ~ComputeSNAGrid(); void init(); + void init_list(int, class NeighList *); void compute_array(); double memory_usage(); private: int ncoeff; double **cutsq; + class NeighList *list; double rcutfac; double *radelem; double *wjelem; diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 3bdbddbc0c..740131deda 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -28,7 +28,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), grid(NULL), local_flags(NULL), gridlocal(NULL) + Compute(lmp, narg, arg), grid(nullptr), gridall(nullptr), local_flags(nullptr), gridlocal(nullptr) { if (narg < 6) error->all(FLERR,"Illegal compute grid command"); @@ -61,9 +61,12 @@ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : ComputeGrid::~ComputeGrid() { memory->destroy(grid); + memory->destroy(gridall); memory->destroy(local_flags); - if (gridlocal_allocated) + if (gridlocal_allocated) { + gridlocal_allocated = 0; memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + } } /* ---------------------------------------------------------------------- */ @@ -200,9 +203,14 @@ void ComputeGrid::allocate() // allocate arrays memory->destroy(grid); + memory->destroy(gridall); memory->destroy(local_flags); - if (gridlocal_allocated) - memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + if (gridlocal_allocated) { + gridlocal_allocated = 0; + // can't seem to do this without seg-fault + // memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + } + memory->create(grid,size_array_rows,size_array_cols,"grid:grid"); memory->create(gridall,size_array_rows,size_array_cols,"grid:gridall"); memory->create(local_flags,size_array_rows,"grid:local_flags"); @@ -257,18 +265,48 @@ void ComputeGrid::set_grid_global() void ComputeGrid::set_grid_local() { - // global indices of grid range from 0 to N-1 - // nlo,nhi = lower/upper limits of the 3d sub-brick of - // global grid that I own without ghost cells + // nx,ny,nz = extent of global grid + // indices into the global grid range from 0 to N-1 in each dim + // if grid point is inside my sub-domain I own it, + // this includes sub-domain lo boundary but excludes hi boundary + // ixyz lo/hi = inclusive lo/hi bounds of global grid sub-brick I own + // if proc owns no grid cells in a dim, then ilo > ihi + // if 2 procs share a boundary a grid point is exactly on, + // the 2 equality if tests insure a consistent decision + // as to which proc owns it - nxlo = static_cast (comm->xsplit[comm->myloc[0]] * nx); - nxhi = static_cast (comm->xsplit[comm->myloc[0]+1] * nx) - 1; + double xfraclo,xfrachi,yfraclo,yfrachi,zfraclo,zfrachi; - nylo = static_cast (comm->ysplit[comm->myloc[1]] * ny); - nyhi = static_cast (comm->ysplit[comm->myloc[1]+1] * ny) - 1; + if (comm->layout != Comm::LAYOUT_TILED) { + xfraclo = comm->xsplit[comm->myloc[0]]; + xfrachi = comm->xsplit[comm->myloc[0]+1]; + yfraclo = comm->ysplit[comm->myloc[1]]; + yfrachi = comm->ysplit[comm->myloc[1]+1]; + zfraclo = comm->zsplit[comm->myloc[2]]; + zfrachi = comm->zsplit[comm->myloc[2]+1]; + } else { + xfraclo = comm->mysplit[0][0]; + xfrachi = comm->mysplit[0][1]; + yfraclo = comm->mysplit[1][0]; + yfrachi = comm->mysplit[1][1]; + zfraclo = comm->mysplit[2][0]; + zfrachi = comm->mysplit[2][1]; + } - nzlo = static_cast (comm->zsplit[comm->myloc[2]] * nz); - nzhi = static_cast (comm->zsplit[comm->myloc[2]+1] * nz) - 1; + nxlo = static_cast (xfraclo * nx); + if (1.0*nxlo != xfraclo*nx) nxlo++; + nxhi = static_cast (xfrachi * nx); + if (1.0*nxhi == xfrachi*nx) nxhi--; + + nylo = static_cast (yfraclo * ny); + if (1.0*nylo != yfraclo*ny) nylo++; + nyhi = static_cast (yfrachi * ny); + if (1.0*nyhi == yfrachi*ny) nyhi--; + + nzlo = static_cast (zfraclo * nz); + if (1.0*nzlo != zfraclo*nz) nzlo++; + nzhi = static_cast (zfrachi * nz); + if (1.0*nzhi == zfrachi*nz) nzhi--; ngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); From 162868f13c5aa8b314634b0a89bbc8851a6f508c Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 30 Jul 2021 10:01:20 -0600 Subject: [PATCH 23/91] Readded r=0 check --- src/ML-SNAP/compute_sna_grid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 0b0c0674e4..62778a9e83 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -269,7 +269,7 @@ void ComputeSNAGrid::compute_array() int jelem = 0; if (chemflag) jelem = map[jtype]; - if (rsq < cutsq[jtype][jtype]) { + if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { snaptr->rij[ninside][0] = delx; snaptr->rij[ninside][1] = dely; snaptr->rij[ninside][2] = delz; From 347e5a59783a4924aee2cf48a3b09c46c15d3374 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Sun, 22 Aug 2021 16:03:50 -0600 Subject: [PATCH 24/91] Created local grid that is used to populate global grid --- src/ML-SNAP/compute_sna_grid.cpp | 27 ++++++--------------------- src/compute_grid.cpp | 6 ++++-- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 62778a9e83..2def0cf6a4 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -37,7 +37,6 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : ComputeGrid(lmp, narg, arg), cutsq(nullptr), radelem(nullptr), wjelem(nullptr) { - double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; @@ -208,21 +207,6 @@ void ComputeSNAGrid::compute_array() { invoked_array = update->ntimestep; - // // invoke full neighbor list (will copy or build if necessary) - - // neighbor->build_one(list); - - // int mynxlo = static_cast (comm->xsplit[comm->myloc[0]] * nx); - // int mynxhi = static_cast (comm->xsplit[comm->myloc[0]+1] * nx) - 1; - - // int mynylo = static_cast (comm->ysplit[comm->myloc[1]] * ny); - // int mynyhi = static_cast (comm->ysplit[comm->myloc[1]+1] * ny) - 1; - - // int mynzlo = static_cast (comm->zsplit[comm->myloc[2]] * nz); - // int mynzhi = static_cast (comm->zsplit[comm->myloc[2]+1] * nz) - 1; - - // int myngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); - // compute sna for each gridpoint double** const x = atom->x; @@ -285,7 +269,7 @@ void ComputeSNAGrid::compute_array() snaptr->compute_zi(); snaptr->compute_bi(ielem); - // linear contributions + // linear contributions for (int icoeff = 0; icoeff < ncoeff; icoeff++) gridlocal[size_array_cols_base+icoeff][iz][iy][ix] = snaptr->blist[icoeff]; @@ -302,16 +286,17 @@ void ComputeSNAGrid::compute_array() } } } - + for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { - const int igrid = iz*(nx*ny) + iy*nx + ix; - for (int j = 0; j < nvalues; j++) - grid[igrid][size_array_cols_base + j] = gridlocal[size_array_cols_base + j][iz][iy][ix]; + const int igrid = iz*(nx*ny) + iy*nx + ix; + for (int j = 0; j < nvalues; j++) + grid[igrid][size_array_cols_base + j] = gridlocal[size_array_cols_base + j][iz][iy][ix]; } MPI_Allreduce(&grid[0][0],&gridall[0][0],ngrid*size_array_cols,MPI_DOUBLE,MPI_SUM,world); + } diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 740131deda..0d880b94d5 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -207,8 +207,11 @@ void ComputeGrid::allocate() memory->destroy(local_flags); if (gridlocal_allocated) { gridlocal_allocated = 0; - // can't seem to do this without seg-fault + // MEMORY LEAK!! + // can't seem to free this memory without seg-fault + // printf("Before allocate destroy4d, proc %d %p\n",comm->me,gridlocal); // memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + // printf("After allocate destroy4d, proc %d %p\n",comm->me,gridlocal); } memory->create(grid,size_array_rows,size_array_cols,"grid:grid"); @@ -310,7 +313,6 @@ void ComputeGrid::set_grid_local() ngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); - printf("me = %d n = %d x %d %d y %d %d z %d %d \n", comm->me, ngridlocal, nxlo, nxhi, nylo, nyhi, nzlo, nzhi); } /* ---------------------------------------------------------------------- From 94c97e83a2b108f681a90ea72a0d4e340ba269bc Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Sun, 22 Aug 2021 18:30:02 -0600 Subject: [PATCH 25/91] Added this helper file --- examples/snap/lammps_utils.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/snap/lammps_utils.py diff --git a/examples/snap/lammps_utils.py b/examples/snap/lammps_utils.py new file mode 100644 index 0000000000..ea74459a74 --- /dev/null +++ b/examples/snap/lammps_utils.py @@ -0,0 +1,26 @@ +import numpy as np +import ctypes + +def set_cmdlinevars(cmdargs, argdict): + for key in argdict.keys(): + cmdargs += ["-var",key,f"{argdict[key]}"] + return cmdargs + +def extract_commands(string): + return [x for x in string.splitlines() if x.strip() != ''] + +def extract_compute_np(lmp,name,compute_type,result_type,array_shape): + """ + Convert a lammps compute to a numpy array. + Assumes the compute returns a floating point numbers. + Note that the result is a view into the original memory. + If the result type is 0 (scalar) then conversion to numpy is skipped and a python float is returned. + """ + ptr = lmp.extract_compute(name, compute_type, result_type) # 1,2: Style (1) is per-atom compute, returns array type (2). + if result_type == 0: return ptr # No casting needed, lammps.py already works + if result_type == 2: ptr = ptr.contents + total_size = np.prod(array_shape) + buffer_ptr = ctypes.cast(ptr, ctypes.POINTER(ctypes.c_double * total_size)) + array_np = np.frombuffer(buffer_ptr.contents, dtype=float) + array_np.shape = array_shape + return array_np From 1b1f6f29c251b8c03d254737927149ebdba08211 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Sun, 22 Aug 2021 18:44:35 -0600 Subject: [PATCH 26/91] Updated grid.py to use sna/grid/local compute, but it seg-faults --- examples/snap/in.grid.python | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/snap/in.grid.python b/examples/snap/in.grid.python index 13fe6d0638..e04415d558 100644 --- a/examples/snap/in.grid.python +++ b/examples/snap/in.grid.python @@ -43,6 +43,8 @@ compute b all sna/atom ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${r compute bgrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} +compute bgridlocal all sna/grid/local grid ${ngridx} ${ngridy} ${ngridz} ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} + # create dummy potential for neighbor list variable rcutneigh equal 2.0*${rcutfac}*${radelem} @@ -56,6 +58,8 @@ thermo_modify norm yes dump mydump_b all custom 1000 dump_b id c_b[*] +dump mydump_bgridlocal all local 1000 dump_bgridlocal index c_bgridlocal[1] + # run run 0 From f473ca498bbe32b6439bfe78cfc937ef5e54fe71 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Sun, 22 Aug 2021 19:24:23 -0600 Subject: [PATCH 27/91] Created in.grid.local, fixed some problems in src --- examples/snap/in.grid.local | 73 ++++++ src/ML-SNAP/compute_sna_grid_local.cpp | 308 +++++++++++++++++++++++++ src/ML-SNAP/compute_sna_grid_local.h | 75 ++++++ src/compute_grid_local.cpp | 253 ++++++++++++++++++++ src/compute_grid_local.h | 69 ++++++ 5 files changed, 778 insertions(+) create mode 100644 examples/snap/in.grid.local create mode 100644 src/ML-SNAP/compute_sna_grid_local.cpp create mode 100644 src/ML-SNAP/compute_sna_grid_local.h create mode 100644 src/compute_grid_local.cpp create mode 100644 src/compute_grid_local.h diff --git a/examples/snap/in.grid.local b/examples/snap/in.grid.local new file mode 100644 index 0000000000..dc04fd5371 --- /dev/null +++ b/examples/snap/in.grid.local @@ -0,0 +1,73 @@ +# Demonstrate bispectrum computes with local grid + +# Initialize simulation + +variable nsteps index 0 +variable nrep index 1 +variable a index 3.316 +variable ngrid index 2 + +units metal + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice custom $a & + a1 1 0 0 & + a2 0 1 0 & + a3 0 0 1 & + basis 0 0 0 & + basis 0.5 0.5 0.5 & +# origin 0.25 0.25 0.25 + +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 180.88 + +# choose potential + +include Ta06A.snap + +# define grid compute and atom compute + +group snapgroup type 1 +variable twojmax equal 2 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quad equal 0 +variable switch equal 1 + +compute b all sna/atom & + ${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & + quadraticflag ${quad} switchflag ${switch} + +compute mygridlocal all sna/grid/local grid ${ngrid} ${ngrid} ${ngrid} & + ${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & + quadraticflag ${quad} switchflag ${switch} + +# define output + +# mygrid is ngrid by (3+nbis) = 8x8 +thermo_style custom step temp ke pe vol +thermo_modify norm yes + +dump mydump_b all custom 1000 dump_b id c_b[*] +dump mydump_bgridlocal all local 1000 dump_bgridlocal index c_mygridlocal[*] + +# run + +run 0 + diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp new file mode 100644 index 0000000000..18d9f5496d --- /dev/null +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -0,0 +1,308 @@ +/* ---------------------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#include "compute_grid_local.h" +#include "compute_sna_grid_local.h" +#include "sna.h" +#include "atom.h" +#include "update.h" +#include "modify.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "force.h" +#include "pair.h" +#include "domain.h" +#include "comm.h" +#include "memory.h" +#include "error.h" +#include "tokenizer.h" + +#include +#include + +using namespace LAMMPS_NS; + +ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : + ComputeGridLocal(lmp, narg, arg), cutsq(nullptr), + radelem(nullptr), wjelem(nullptr) +{ + double rfac0, rmin0; + int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; + + // skip over arguments used by base class + // so that argument positions are identical to + // regular per-atom compute + + arg += nargbase; + narg -= nargbase; + + int ntypes = atom->ntypes; + int nargmin = 6+2*ntypes; + + if (narg < nargmin) error->all(FLERR,"Illegal compute sna/grid/local command"); + + // default values + + rmin0 = 0.0; + switchflag = 1; + bzeroflag = 1; + quadraticflag = 0; + chemflag = 0; + bnormflag = 0; + wselfallflag = 0; + nelements = 1; + + // process required arguments + + memory->create(radelem,ntypes+1,"sna/grid/local:radelem"); // offset by 1 to match up with types + memory->create(wjelem,ntypes+1,"sna/grid/local:wjelem"); + + rcutfac = atof(arg[3]); + rfac0 = atof(arg[4]); + twojmax = atoi(arg[5]); + + for(int i = 0; i < ntypes; i++) + radelem[i+1] = atof(arg[6+i]); + for(int i = 0; i < ntypes; i++) + wjelem[i+1] = atof(arg[6+ntypes+i]); + + // construct cutsq + + double cut; + cutmax = 0.0; + memory->create(cutsq,ntypes+1,ntypes+1,"sna/grid/local:cutsq"); + for(int i = 1; i <= ntypes; i++) { + cut = 2.0*radelem[i]*rcutfac; + if (cut > cutmax) cutmax = cut; + cutsq[i][i] = cut*cut; + for(int j = i+1; j <= ntypes; j++) { + cut = (radelem[i]+radelem[j])*rcutfac; + cutsq[i][j] = cutsq[j][i] = cut*cut; + } + } + + // process optional args + + int iarg = nargmin; + + while (iarg < narg) { + if (strcmp(arg[iarg],"rmin0") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid/local command"); + rmin0 = atof(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"switchflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid/local command"); + switchflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"bzeroflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid/local command"); + bzeroflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"quadraticflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid/local command"); + quadraticflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"chem") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid/local command"); + chemflag = 1; + memory->create(map,ntypes+1,"compute_sna_grid_local:map"); + nelements = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + for (int i = 0; i < ntypes; i++) { + int jelem = utils::inumeric(FLERR,arg[iarg+2+i],false,lmp); + if (jelem < 0 || jelem >= nelements) + error->all(FLERR,"Illegal compute sna/grid/local command"); + map[i+1] = jelem; + } + iarg += 2+ntypes; + } else if (strcmp(arg[iarg],"bnormflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid/local command"); + bnormflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"wselfallflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute sna/grid/local command"); + wselfallflag = atoi(arg[iarg+1]); + iarg += 2; + } else error->all(FLERR,"Illegal compute sna/grid/local command"); + + } + + snaptr = new SNA(lmp, rfac0, twojmax, + rmin0, switchflag, bzeroflag, + chemflag, bnormflag, wselfallflag, nelements); + + ncoeff = snaptr->ncoeff; + nvalues = ncoeff; + if (quadraticflag) nvalues += (ncoeff*(ncoeff+1))/2; + size_local_cols = size_local_cols_base + nvalues; +} + +/* ---------------------------------------------------------------------- */ + +ComputeSNAGridLocal::~ComputeSNAGridLocal() +{ + memory->destroy(radelem); + memory->destroy(wjelem); + memory->destroy(cutsq); + delete snaptr; + + if (chemflag) memory->destroy(map); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeSNAGridLocal::init() +{ + if (force->pair == nullptr) + error->all(FLERR,"Compute sna/grid/local requires a pair style be defined"); + + if (cutmax > force->pair->cutforce) + error->all(FLERR,"Compute sna/grid/local cutoff is longer than pairwise cutoff"); + + // need an occasional full neighbor list + + int irequest = neighbor->request(this,instance_me); + neighbor->requests[irequest]->pair = 0; + neighbor->requests[irequest]->compute = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->occasional = 1; + + int count = 0; + for (int i = 0; i < modify->ncompute; i++) + if (strcmp(modify->compute[i]->style,"sna/grid/local") == 0) count++; + if (count > 1 && comm->me == 0) + error->warning(FLERR,"More than one compute sna/grid/local"); + snaptr->init(); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeSNAGridLocal::init_list(int /*id*/, NeighList *ptr) +{ + list = ptr; +} + +/* ---------------------------------------------------------------------- */ + +void ComputeSNAGridLocal::compute_local() +{ + invoked_array = update->ntimestep; + + // compute sna for each gridpoint + + double** const x = atom->x; + const int* const mask = atom->mask; + int * const type = atom->type; + const int ntotal = atom->nlocal + atom->nghost; + + // insure rij, inside, and typej are of size jnum + + snaptr->grow_rij(ntotal); + + for (int iz = nzlo; iz <= nzhi; iz++) + for (int iy = nylo; iy <= nyhi; iy++) + for (int ix = nxlo; ix <= nxhi; ix++) { + double xgrid[3]; + grid2x(ix, iy, iz, xgrid); + const double xtmp = xgrid[0]; + const double ytmp = xgrid[1]; + const double ztmp = xgrid[2]; + + // currently, all grid points are type 1 + + const int itype = 1; + int ielem = 0; + if (chemflag) + ielem = map[itype]; + const double radi = radelem[itype]; + + // rij[][3] = displacements between atom I and those neighbors + // inside = indices of neighbors of I within cutoff + // typej = types of neighbors of I within cutoff + + int ninside = 0; + for (int j = 0; j < ntotal; j++) { + + // check that j is in compute group + + if (!(mask[j] & groupbit)) continue; + + const double delx = xtmp - x[j][0]; + const double dely = ytmp - x[j][1]; + const double delz = ztmp - x[j][2]; + const double rsq = delx*delx + dely*dely + delz*delz; + int jtype = type[j]; + int jelem = 0; + if (chemflag) + jelem = map[jtype]; + if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { + snaptr->rij[ninside][0] = delx; + snaptr->rij[ninside][1] = dely; + snaptr->rij[ninside][2] = delz; + snaptr->inside[ninside] = j; + snaptr->wj[ninside] = wjelem[jtype]; + snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; + snaptr->element[ninside] = jelem; // element index for multi-element snap + ninside++; + } + } + + snaptr->compute_ui(ninside, ielem); + snaptr->compute_zi(); + snaptr->compute_bi(ielem); + + // linear contributions + + for (int icoeff = 0; icoeff < ncoeff; icoeff++) + gridlocal[size_local_cols_base+icoeff][iz][iy][ix] = snaptr->blist[icoeff]; + + // quadratic contributions + + if (quadraticflag) { + int ncount = ncoeff; + for (int icoeff = 0; icoeff < ncoeff; icoeff++) { + double bveci = snaptr->blist[icoeff]; + gridlocal[size_local_cols_base+ncount++][iz][iy][ix] = 0.5*bveci*bveci; + for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) + gridlocal[size_local_cols_base+ncount++][iz][iy][ix] = bveci*snaptr->blist[jcoeff]; + } + } + } + + // copy 4d array to 2d array + + copy_gridlocal_to_local_array(); +} + + +/* ---------------------------------------------------------------------- + memory usage +------------------------------------------------------------------------- */ + +double ComputeSNAGridLocal::memory_usage() +{ + double nbytes = snaptr->memory_usage(); // SNA object + int n = atom->ntypes+1; + nbytes += (double)n*sizeof(int); // map + + return nbytes; +} + diff --git a/src/ML-SNAP/compute_sna_grid_local.h b/src/ML-SNAP/compute_sna_grid_local.h new file mode 100644 index 0000000000..21e321d123 --- /dev/null +++ b/src/ML-SNAP/compute_sna_grid_local.h @@ -0,0 +1,75 @@ +/* -*- 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 COMPUTE_CLASS + +ComputeStyle(sna/grid/local,ComputeSNAGridLocal) + +#else + +#ifndef LMP_COMPUTE_SNA_GRID_LOCAL_H +#define LMP_COMPUTE_SNA_GRID_LOCAL_H + +#include "compute_grid_local.h" + +namespace LAMMPS_NS { + +class ComputeSNAGridLocal : public ComputeGridLocal { + public: + ComputeSNAGridLocal(class LAMMPS *, int, char **); + ~ComputeSNAGridLocal(); + void init(); + void init_list(int, class NeighList *); + void compute_local(); + double memory_usage(); + + private: + int ncoeff; + double **cutsq; + class NeighList *list; + double rcutfac; + double *radelem; + double *wjelem; + int *map; // map types to [0,nelements) + int nelements, chemflag; + class SNA *snaptr; + double cutmax; + int quadraticflag; +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +E: Compute sna/grid/local requires a pair style be defined + +Self-explanatory. + +E: Compute sna/grid/local cutoff is longer than pairwise cutoff + +Self-explanatory. + +W: More than one compute sna/grid/local + +Self-explanatory. + +*/ diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp new file mode 100644 index 0000000000..8c0f8ff066 --- /dev/null +++ b/src/compute_grid_local.cpp @@ -0,0 +1,253 @@ +/* ---------------------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#include "compute_grid_local.h" +#include +#include +#include "atom.h" +#include "update.h" +#include "modify.h" +#include "domain.h" +#include "force.h" +#include "memory.h" +#include "error.h" +#include "comm.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +ComputeGridLocal::ComputeGridLocal(LAMMPS *lmp, int narg, char **arg) : + Compute(lmp, narg, arg), gridlocal(nullptr), alocal(nullptr) +{ + if (narg < 6) error->all(FLERR,"Illegal compute grid/local command"); + + local_flag = 1; + size_local_cols = 0; + size_local_rows = 0; + extarray = 0; + + int iarg0 = 3; + int iarg = iarg0; + if (strcmp(arg[iarg],"grid") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal compute grid/local command"); + nx = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + ny = utils::inumeric(FLERR,arg[iarg+2],false,lmp); + nz = utils::inumeric(FLERR,arg[iarg+3],false,lmp); + if (nx <= 0 || ny <= 0 || nz <= 0) + error->all(FLERR,"All grid/local dimensions must be positive"); + iarg += 4; + } else error->all(FLERR,"Illegal compute grid/local command"); + + nargbase = iarg - iarg0; + + size_local_cols_base = 6; + gridlocal_allocated = 0; +} + +/* ---------------------------------------------------------------------- */ + +ComputeGridLocal::~ComputeGridLocal() +{ + if (gridlocal_allocated) { + gridlocal_allocated = 0; + memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + } + memory->destroy(alocal); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeGridLocal::init() +{ +} + +/* ---------------------------------------------------------------------- */ + +void ComputeGridLocal::setup() +{ + set_grid_global(); + set_grid_local(); + allocate(); +} + +/* ---------------------------------------------------------------------- + convert global array indexes to box coords +------------------------------------------------------------------------- */ + +void ComputeGridLocal::grid2x(int ix, int iy, int iz, double *x) +{ + x[0] = ix*delx; + x[1] = iy*dely; + x[2] = iz*delz; + + if (triclinic) domain->lamda2x(x, x); +} + +/* ---------------------------------------------------------------------- + free and reallocate arrays +------------------------------------------------------------------------- */ + +void ComputeGridLocal::allocate() +{ + // allocate local array + + if (gridlocal_allocated) { + gridlocal_allocated = 0; + // MEMORY LEAK!! + // can't seem to free this memory without seg-fault + // printf("Before allocate destroy4d, proc %d %p\n",comm->me,gridlocal); + // memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + // printf("After allocate destroy4d, proc %d %p\n",comm->me,gridlocal); + } + + if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { + gridlocal_allocated = 1; + memory->create4d_offset(gridlocal,size_array_cols,nzlo,nzhi,nylo,nyhi, + nxlo,nxhi,"grid:gridlocal"); + } +} + +/* ---------------------------------------------------------------------- + set global grid +------------------------------------------------------------------------- */ + +void ComputeGridLocal::set_grid_global() +{ + // calculate grid layout + + triclinic = domain->triclinic; + + if (triclinic == 0) { + prd = domain->prd; + boxlo = domain->boxlo; + sublo = domain->sublo; + subhi = domain->subhi; + } else { + prd = domain->prd_lamda; + boxlo = domain->boxlo_lamda; + sublo = domain->sublo_lamda; + subhi = domain->subhi_lamda; + } + + double xprd = prd[0]; + double yprd = prd[1]; + double zprd = prd[2]; + + delxinv = nx/xprd; + delyinv = ny/yprd; + delzinv = nz/zprd; + + delx = 1.0/delxinv; + dely = 1.0/delyinv; + delz = 1.0/delzinv; +} + +/* ---------------------------------------------------------------------- + set local subset of grid that I own + n xyz lo/hi = 3d brick that I own (inclusive) +------------------------------------------------------------------------- */ + +void ComputeGridLocal::set_grid_local() +{ + // nx,ny,nz = extent of global grid + // indices into the global grid range from 0 to N-1 in each dim + // if grid point is inside my sub-domain I own it, + // this includes sub-domain lo boundary but excludes hi boundary + // ixyz lo/hi = inclusive lo/hi bounds of global grid sub-brick I own + // if proc owns no grid cells in a dim, then ilo > ihi + // if 2 procs share a boundary a grid point is exactly on, + // the 2 equality if tests insure a consistent decision + // as to which proc owns it + + double xfraclo,xfrachi,yfraclo,yfrachi,zfraclo,zfrachi; + + if (comm->layout != Comm::LAYOUT_TILED) { + xfraclo = comm->xsplit[comm->myloc[0]]; + xfrachi = comm->xsplit[comm->myloc[0]+1]; + yfraclo = comm->ysplit[comm->myloc[1]]; + yfrachi = comm->ysplit[comm->myloc[1]+1]; + zfraclo = comm->zsplit[comm->myloc[2]]; + zfrachi = comm->zsplit[comm->myloc[2]+1]; + } else { + xfraclo = comm->mysplit[0][0]; + xfrachi = comm->mysplit[0][1]; + yfraclo = comm->mysplit[1][0]; + yfrachi = comm->mysplit[1][1]; + zfraclo = comm->mysplit[2][0]; + zfrachi = comm->mysplit[2][1]; + } + + nxlo = static_cast (xfraclo * nx); + if (1.0*nxlo != xfraclo*nx) nxlo++; + nxhi = static_cast (xfrachi * nx); + if (1.0*nxhi == xfrachi*nx) nxhi--; + + nylo = static_cast (yfraclo * ny); + if (1.0*nylo != yfraclo*ny) nylo++; + nyhi = static_cast (yfrachi * ny); + if (1.0*nyhi == yfrachi*ny) nyhi--; + + nzlo = static_cast (zfraclo * nz); + if (1.0*nzlo != zfraclo*nz) nzlo++; + nzhi = static_cast (zfrachi * nz); + if (1.0*nzhi == zfrachi*nz) nzhi--; + + ngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); + size_local_rows = ngridlocal; + + memory->destroy(alocal); + memory->create(alocal, size_local_rows, size_local_cols, "compute/grid/local:alocal"); + array_local = alocal; + + int igrid = 0; + for (int iz = nzlo; iz <= nzhi; iz++) + for (int iy = nylo; iy <= nyhi; iy++) + for (int ix = nxlo; ix <= nxhi; ix++) { + alocal[igrid][0] = ix; + alocal[igrid][1] = iy; + alocal[igrid][2] = iz; + double xgrid[3]; + grid2x(ix, iy, iz, xgrid); + alocal[igrid][3] = xgrid[0]; + alocal[igrid][4] = xgrid[1]; + alocal[igrid][5] = xgrid[2]; + igrid++; + } +} + +/* ---------------------------------------------------------------------- + copy the 4d gridlocal array values to the 2d local array +------------------------------------------------------------------------- */ + +void ComputeGridLocal::copy_gridlocal_to_local_array() +{ + int igrid = 0; + for (int iz = nzlo; iz <= nzhi; iz++) + for (int iy = nylo; iy <= nyhi; iy++) + for (int ix = nxlo; ix <= nxhi; ix++) { + for (int icol = size_local_cols_base; icol < size_local_cols; icol++) + alocal[igrid][icol] = gridlocal[icol][iz][iy][ix]; + igrid++; + } +} + +/* ---------------------------------------------------------------------- + memory usage of local data +------------------------------------------------------------------------- */ + +double ComputeGridLocal::memory_usage() +{ + int nbytes = size_array_cols*ngridlocal*sizeof(double); // gridlocal + return nbytes; +} diff --git a/src/compute_grid_local.h b/src/compute_grid_local.h new file mode 100644 index 0000000000..b6cd882b2e --- /dev/null +++ b/src/compute_grid_local.h @@ -0,0 +1,69 @@ +/* -*- 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. +------------------------------------------------------------------------- */ + +#ifndef LMP_COMPUTE_GRID_LOCAL_H +#define LMP_COMPUTE_GRID_LOCAL_H + +#include "compute.h" + +namespace LAMMPS_NS { + +class ComputeGridLocal : public Compute { + public: + + ComputeGridLocal(class LAMMPS *, int, char **); + virtual ~ComputeGridLocal(); + void init(); + void setup(); + virtual void compute_local() = 0; + + double memory_usage(); + + protected: + int nx, ny, nz; // global grid dimensions + int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive + int ngridlocal; // number of local grid points + int nvalues; // number of values per grid point + double ****gridlocal; // local grid + double **alocal; // pointer to Compute::array_local + int triclinic; // triclinic flag + double *boxlo, *prd; // box info (units real/ortho or reduced/tri) + double *sublo, *subhi; // subdomain info (units real/ortho or reduced/tri) + double delxinv,delyinv,delzinv; // inverse grid spacing + double delx,dely,delz; // grid spacing + int nargbase; // number of base class args + double cutmax; // largest cutoff distance + int size_local_cols_base; // number of columns used for coords, etc. + int gridlocal_allocated; // shows if gridlocal allocated + + void allocate(); + void grid2x(int, int, int, double*); // convert global indices to coordinates + void set_grid_global(); // set global grid + void set_grid_local(); // set bounds for local grid + void copy_gridlocal_to_local_array();// copy 4d gridlocal array to 2d local array + private: +}; + +} + +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +*/ From 5bf13b2f3cc2c8e603f4ee20ae5cbb4c8cb4c1fb Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 25 Aug 2021 17:50:40 -0600 Subject: [PATCH 28/91] Declared victory on compute grid and grid/local --- src/ML-SNAP/compute_sna_grid_local.cpp | 11 +++++++---- src/compute_grid.cpp | 6 +----- src/compute_grid_local.cpp | 10 +++------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index 18d9f5496d..c1574bfa26 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -272,17 +272,20 @@ void ComputeSNAGridLocal::compute_local() // linear contributions for (int icoeff = 0; icoeff < ncoeff; icoeff++) - gridlocal[size_local_cols_base+icoeff][iz][iy][ix] = snaptr->blist[icoeff]; - + gridlocal[size_local_cols_base+icoeff][iz][iy][ix] = + snaptr->blist[icoeff]; + // quadratic contributions if (quadraticflag) { int ncount = ncoeff; for (int icoeff = 0; icoeff < ncoeff; icoeff++) { double bveci = snaptr->blist[icoeff]; - gridlocal[size_local_cols_base+ncount++][iz][iy][ix] = 0.5*bveci*bveci; + gridlocal[size_local_cols_base+ncount++][iz][iy][ix] = + 0.5*bveci*bveci; for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - gridlocal[size_local_cols_base+ncount++][iz][iy][ix] = bveci*snaptr->blist[jcoeff]; + gridlocal[size_local_cols_base+ncount++][iz][iy][ix] = + bveci*snaptr->blist[jcoeff]; } } } diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 0d880b94d5..7eee793023 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -207,11 +207,7 @@ void ComputeGrid::allocate() memory->destroy(local_flags); if (gridlocal_allocated) { gridlocal_allocated = 0; - // MEMORY LEAK!! - // can't seem to free this memory without seg-fault - // printf("Before allocate destroy4d, proc %d %p\n",comm->me,gridlocal); - // memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); - // printf("After allocate destroy4d, proc %d %p\n",comm->me,gridlocal); + memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); } memory->create(grid,size_array_rows,size_array_cols,"grid:grid"); diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index 8c0f8ff066..dab9aa44d4 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -104,16 +104,12 @@ void ComputeGridLocal::allocate() if (gridlocal_allocated) { gridlocal_allocated = 0; - // MEMORY LEAK!! - // can't seem to free this memory without seg-fault - // printf("Before allocate destroy4d, proc %d %p\n",comm->me,gridlocal); - // memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); - // printf("After allocate destroy4d, proc %d %p\n",comm->me,gridlocal); + memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); } if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { gridlocal_allocated = 1; - memory->create4d_offset(gridlocal,size_array_cols,nzlo,nzhi,nylo,nyhi, + memory->create4d_offset(gridlocal,size_local_cols,nzlo,nzhi,nylo,nyhi, nxlo,nxhi,"grid:gridlocal"); } } @@ -248,6 +244,6 @@ void ComputeGridLocal::copy_gridlocal_to_local_array() double ComputeGridLocal::memory_usage() { - int nbytes = size_array_cols*ngridlocal*sizeof(double); // gridlocal + int nbytes = size_local_cols*ngridlocal*sizeof(double); // gridlocal return nbytes; } From 78f9c7b47818dcffc6c89ecdeb9e8d1cb8df85a0 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 25 Aug 2021 17:52:53 -0600 Subject: [PATCH 29/91] Declared victory on compute grid and grid/local --- examples/snap/in.grid.local | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/snap/in.grid.local b/examples/snap/in.grid.local index dc04fd5371..121f0ba981 100644 --- a/examples/snap/in.grid.local +++ b/examples/snap/in.grid.local @@ -71,3 +71,7 @@ dump mydump_bgridlocal all local 1000 dump_bgridlocal index c_mygridlocal[*] run 0 +run 0 + +run 0 + From ea3c89165a14565351d49b25fb14043b9f9a1649 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 26 Aug 2021 11:52:06 -0600 Subject: [PATCH 30/91] Resolved memory management issue exposed by RCB in in.grid.test --- examples/snap/in.grid.test | 105 +++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 examples/snap/in.grid.test diff --git a/examples/snap/in.grid.test b/examples/snap/in.grid.test new file mode 100644 index 0000000000..c684200d44 --- /dev/null +++ b/examples/snap/in.grid.test @@ -0,0 +1,105 @@ +# Demonstrate bispectrum computes + +# CORRECTNESS: thermo output for c_mygrid[*][1] and c_mygrid[*][8] should +# match the values in dump_b: 108.173 3.21778 0.712238 7.06634 1.04273 + +# Initialize simulation + +variable nsteps index 0 +variable nrep index 3 +variable a index 3.316 +variable ngrid index 2 + +units metal + +atom_modify map yes + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice custom $a & + a1 1 0 0 & + a2 0 1 0 & + a3 0 0 1 & + basis 0 0 0 & + basis 0.5 0.5 0.5 & +# origin 0.25 0.25 0.25 +# origin 0.25e-3 0.25e-3 0.25e-3 + +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 180.88 + +write_dump all custom test.dump id type x y z + +# choose potential + +include Ta06A.snap + +# define grid compute and atom compute + +group snapgroup type 1 +variable twojmax equal 2 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quad equal 0 +variable switch equal 1 + +compute b all sna/atom & + ${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & + quadraticflag ${quad} switchflag ${switch} + +compute mygrid all sna/grid grid ${ngrid} ${ngrid} ${ngrid} & + ${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & + quadraticflag ${quad} switchflag ${switch} + +compute mygridlocal all sna/grid/local grid ${ngrid} ${ngrid} ${ngrid} & + ${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & + quadraticflag ${quad} switchflag ${switch} + +# define output + +# mygrid is ngrid by (3+nbis) = 8x8 +thermo_style custom step temp ke pe vol & + c_mygrid[1][1] c_mygrid[2][1] c_mygrid[3][1] c_mygrid[4][1] c_mygrid[5][1] c_mygrid[6][1] c_mygrid[7][1] c_mygrid[8][1] & + c_mygrid[1][2] c_mygrid[2][2] c_mygrid[3][2] c_mygrid[4][2] c_mygrid[5][2] c_mygrid[6][2] c_mygrid[7][2] c_mygrid[8][2] & + c_mygrid[1][3] c_mygrid[2][3] c_mygrid[3][3] c_mygrid[4][3] c_mygrid[5][3] c_mygrid[6][3] c_mygrid[7][3] c_mygrid[8][3] & + c_mygrid[1][4] c_mygrid[2][4] c_mygrid[3][4] c_mygrid[4][4] c_mygrid[5][4] c_mygrid[6][4] c_mygrid[7][4] c_mygrid[8][4] & + c_mygrid[1][5] c_mygrid[2][5] c_mygrid[3][5] c_mygrid[4][5] c_mygrid[5][5] c_mygrid[6][5] c_mygrid[7][5] c_mygrid[8][5] & + c_mygrid[1][6] c_mygrid[2][6] c_mygrid[3][6] c_mygrid[4][6] c_mygrid[5][6] c_mygrid[6][6] c_mygrid[7][6] c_mygrid[8][6] & + c_mygrid[1][7] c_mygrid[2][7] c_mygrid[3][7] c_mygrid[4][7] c_mygrid[5][7] c_mygrid[6][7] c_mygrid[7][7] c_mygrid[8][7] & + c_mygrid[1][8] c_mygrid[2][8] c_mygrid[3][8] c_mygrid[4][8] c_mygrid[5][8] c_mygrid[6][8] c_mygrid[7][8] c_mygrid[8][8] +thermo_modify norm yes + +#dump mydump_b all custom 1 dump_b id c_b[*] +dump mydump_bgridlocal all local 1 dump_bgridlocal index c_mygridlocal[*] + +# run + +run 1 + +# rcb + +comm_style tiled +balance 0.99 rcb +run 1 + +# rcb again + +balance 0.99 rcb +run 1 + From db58cec057e7b790bd706ad63c28c3ff79473d7f Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 26 Aug 2021 11:52:46 -0600 Subject: [PATCH 31/91] Resolved memory management issue exposed by RCB in in.grid.test --- src/compute_grid.cpp | 36 +++++++++++++++++--------------- src/compute_grid.h | 3 ++- src/compute_grid_local.cpp | 42 +++++++++++++++++++++++--------------- src/compute_grid_local.h | 4 +++- 4 files changed, 51 insertions(+), 34 deletions(-) diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 7eee793023..52bd7d6307 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -60,13 +60,7 @@ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : ComputeGrid::~ComputeGrid() { - memory->destroy(grid); - memory->destroy(gridall); - memory->destroy(local_flags); - if (gridlocal_allocated) { - gridlocal_allocated = 0; - memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); - } + deallocate(); } /* ---------------------------------------------------------------------- */ @@ -79,6 +73,7 @@ void ComputeGrid::init() void ComputeGrid::setup() { + deallocate(); set_grid_global(); set_grid_local(); allocate(); @@ -195,21 +190,13 @@ void ComputeGrid::assign_local_flags() } /* ---------------------------------------------------------------------- - free and reallocate arrays + create arrays ------------------------------------------------------------------------- */ void ComputeGrid::allocate() { // allocate arrays - memory->destroy(grid); - memory->destroy(gridall); - memory->destroy(local_flags); - if (gridlocal_allocated) { - gridlocal_allocated = 0; - memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); - } - memory->create(grid,size_array_rows,size_array_cols,"grid:grid"); memory->create(gridall,size_array_rows,size_array_cols,"grid:gridall"); memory->create(local_flags,size_array_rows,"grid:local_flags"); @@ -222,6 +209,23 @@ void ComputeGrid::allocate() } +/* ---------------------------------------------------------------------- + free arrays +------------------------------------------------------------------------- */ + +void ComputeGrid::deallocate() +{ + memory->destroy(grid); + memory->destroy(gridall); + memory->destroy(local_flags); + if (gridlocal_allocated) { + gridlocal_allocated = 0; + memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + } + array = nullptr; +} + + /* ---------------------------------------------------------------------- set global grid ------------------------------------------------------------------------- */ diff --git a/src/compute_grid.h b/src/compute_grid.h index 1b2797732d..421656febf 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -49,7 +49,8 @@ class ComputeGrid : public Compute { int *local_flags; // local flag for each grid point int gridlocal_allocated; // shows if gridlocal allocated - void allocate(); + void allocate(); // create arrays + void deallocate(); // free arrays void grid2x(int, double*); // convert grid point to coord void grid2ix(int, int&, int&, int&); // convert grid point to ix, iy, iz void assign_coords(); // assign coords for grid diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index dab9aa44d4..1b8de3c48a 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -59,11 +59,7 @@ ComputeGridLocal::ComputeGridLocal(LAMMPS *lmp, int narg, char **arg) : ComputeGridLocal::~ComputeGridLocal() { - if (gridlocal_allocated) { - gridlocal_allocated = 0; - memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); - } - memory->destroy(alocal); + deallocate(); } /* ---------------------------------------------------------------------- */ @@ -76,9 +72,11 @@ void ComputeGridLocal::init() void ComputeGridLocal::setup() { + deallocate(); set_grid_global(); set_grid_local(); allocate(); + assign_coords(); } /* ---------------------------------------------------------------------- @@ -95,25 +93,34 @@ void ComputeGridLocal::grid2x(int ix, int iy, int iz, double *x) } /* ---------------------------------------------------------------------- - free and reallocate arrays + create arrays ------------------------------------------------------------------------- */ void ComputeGridLocal::allocate() { - // allocate local array - - if (gridlocal_allocated) { - gridlocal_allocated = 0; - memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); - } - if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { gridlocal_allocated = 1; memory->create4d_offset(gridlocal,size_local_cols,nzlo,nzhi,nylo,nyhi, nxlo,nxhi,"grid:gridlocal"); + memory->create(alocal, size_local_rows, size_local_cols, "compute/grid/local:alocal"); + array_local = alocal; } } +/* ---------------------------------------------------------------------- + free arrays +------------------------------------------------------------------------- */ + +void ComputeGridLocal::deallocate() +{ + if (gridlocal_allocated) { + gridlocal_allocated = 0; + memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + memory->destroy(alocal); + } + array_local = nullptr; +} + /* ---------------------------------------------------------------------- set global grid ------------------------------------------------------------------------- */ @@ -201,11 +208,14 @@ void ComputeGridLocal::set_grid_local() ngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); size_local_rows = ngridlocal; +} - memory->destroy(alocal); - memory->create(alocal, size_local_rows, size_local_cols, "compute/grid/local:alocal"); - array_local = alocal; +/* ---------------------------------------------------------------------- + copy coords to local array +------------------------------------------------------------------------- */ +void ComputeGridLocal::assign_coords() +{ int igrid = 0; for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) diff --git a/src/compute_grid_local.h b/src/compute_grid_local.h index b6cd882b2e..6189e5b27d 100644 --- a/src/compute_grid_local.h +++ b/src/compute_grid_local.h @@ -46,10 +46,12 @@ class ComputeGridLocal : public Compute { int size_local_cols_base; // number of columns used for coords, etc. int gridlocal_allocated; // shows if gridlocal allocated - void allocate(); + void allocate(); // create arrays + void deallocate(); // free arrays void grid2x(int, int, int, double*); // convert global indices to coordinates void set_grid_global(); // set global grid void set_grid_local(); // set bounds for local grid + void assign_coords(); // assign coords for grid void copy_gridlocal_to_local_array();// copy 4d gridlocal array to 2d local array private: }; From 0a4e85a1f35c029b920246980ad0d1cfa4c42988 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 26 Aug 2021 11:58:39 -0600 Subject: [PATCH 32/91] Added README.grid --- examples/snap/README.grid | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 examples/snap/README.grid diff --git a/examples/snap/README.grid b/examples/snap/README.grid new file mode 100644 index 0000000000..9033c9d445 --- /dev/null +++ b/examples/snap/README.grid @@ -0,0 +1,9 @@ +This branch contains the following examples: + +in.grid # simple example of grid +in.grid.local # simple example of grid/local +in.grid.python # used by grid.py +in.grid.test # stress test of grid and grid/local +in.grid.tri # grid with triclinic cell + +grid.py # access data from Python library interface From 8bddc801df643bf69f8c1a4c3798646dc46a130f Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Sun, 3 Oct 2021 17:55:55 -0600 Subject: [PATCH 33/91] First successful compile of pair style --- src/ML-SNAP/pair_sna_grid.cpp | 182 ++++++++++++++++++ src/ML-SNAP/pair_sna_grid.h | 76 ++++++++ src/pair_grid.cpp | 344 ++++++++++++++++++++++++++++++++++ src/pair_grid.h | 88 +++++++++ 4 files changed, 690 insertions(+) create mode 100644 src/ML-SNAP/pair_sna_grid.cpp create mode 100644 src/ML-SNAP/pair_sna_grid.h create mode 100644 src/pair_grid.cpp create mode 100644 src/pair_grid.h diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp new file mode 100644 index 0000000000..605e05ebf9 --- /dev/null +++ b/src/ML-SNAP/pair_sna_grid.cpp @@ -0,0 +1,182 @@ +/* ---------------------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#include "pair_grid.h" +#include "pair_sna_grid.h" +#include "sna.h" +#include "atom.h" +#include "update.h" +#include "modify.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "force.h" +#include "pair.h" +#include "domain.h" +#include "comm.h" +#include "memory.h" +#include "error.h" +#include "tokenizer.h" + +#include +#include + +using namespace LAMMPS_NS; + +PairSNAGrid::PairSNAGrid(LAMMPS *lmp) : + PairGrid(lmp), cutsq(nullptr), + radelem(nullptr), wjelem(nullptr) +{ +} + +/* ---------------------------------------------------------------------- */ + +PairSNAGrid::~PairSNAGrid() +{ + memory->destroy(radelem); + memory->destroy(wjelem); + memory->destroy(cutsq); + delete snaptr; + + if (chemflag) memory->destroy(map); +} + +/* ---------------------------------------------------------------------- */ + +void PairSNAGrid::init() +{ + if (force->pair == nullptr) + error->all(FLERR,"Pair sna/grid requires a pair style be defined"); + + if (cutmax > force->pair->cutforce) + error->all(FLERR,"Pair sna/grid cutoff is longer than pairwise cutoff"); + + // need an occasional full neighbor list + + int irequest = neighbor->request(this,instance_me); + neighbor->requests[irequest]->pair = 0; + neighbor->requests[irequest]->compute = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->occasional = 1; + + snaptr->init(); +} + +/* ---------------------------------------------------------------------- */ + +void PairSNAGrid::init_list(int /*id*/, NeighList *ptr) +{ + list = ptr; +} + +/* ---------------------------------------------------------------------- */ + +void PairSNAGrid::compute(int eflag, int vflag) +{ + + // compute sna for each gridpoint + + double** const x = atom->x; + const int* const mask = atom->mask; + int * const type = atom->type; + const int ntotal = atom->nlocal + atom->nghost; + + // insure rij, inside, and typej are of size jnum + + snaptr->grow_rij(ntotal); + + for (int iz = nzlo; iz <= nzhi; iz++) + for (int iy = nylo; iy <= nyhi; iy++) + for (int ix = nxlo; ix <= nxhi; ix++) { + double xgrid[3]; + grid2x(ix, iy, iz, xgrid); + const double xtmp = xgrid[0]; + const double ytmp = xgrid[1]; + const double ztmp = xgrid[2]; + + // currently, all grid points are type 1 + + const int itype = 1; + int ielem = 0; + if (chemflag) + ielem = map[itype]; + const double radi = radelem[itype]; + + // rij[][3] = displacements between atom I and those neighbors + // inside = indices of neighbors of I within cutoff + // typej = types of neighbors of I within cutoff + + int ninside = 0; + for (int j = 0; j < ntotal; j++) { + + const double delx = xtmp - x[j][0]; + const double dely = ytmp - x[j][1]; + const double delz = ztmp - x[j][2]; + const double rsq = delx*delx + dely*dely + delz*delz; + int jtype = type[j]; + int jelem = 0; + if (chemflag) + jelem = map[jtype]; + if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { + snaptr->rij[ninside][0] = delx; + snaptr->rij[ninside][1] = dely; + snaptr->rij[ninside][2] = delz; + snaptr->inside[ninside] = j; + snaptr->wj[ninside] = wjelem[jtype]; + snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; + snaptr->element[ninside] = jelem; // element index for multi-element snap + ninside++; + } + } + + snaptr->compute_ui(ninside, ielem); + snaptr->compute_zi(); + snaptr->compute_bi(ielem); + + // linear contributions + + for (int icoeff = 0; icoeff < ncoeff; icoeff++) + gridlocal[ndesc_base+icoeff][iz][iy][ix] = + snaptr->blist[icoeff]; + + // quadratic contributions + + if (quadraticflag) { + int ncount = ncoeff; + for (int icoeff = 0; icoeff < ncoeff; icoeff++) { + double bveci = snaptr->blist[icoeff]; + gridlocal[ndesc_base+ncount++][iz][iy][ix] = + 0.5*bveci*bveci; + for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) + gridlocal[ndesc_base+ncount++][iz][iy][ix] = + bveci*snaptr->blist[jcoeff]; + } + } + } +} + + +/* ---------------------------------------------------------------------- + memory usage +------------------------------------------------------------------------- */ + +double PairSNAGrid::memory_usage() +{ + double nbytes = snaptr->memory_usage(); // SNA object + int n = atom->ntypes+1; + nbytes += (double)n*sizeof(int); // map + + return nbytes; +} + diff --git a/src/ML-SNAP/pair_sna_grid.h b/src/ML-SNAP/pair_sna_grid.h new file mode 100644 index 0000000000..d94032e58c --- /dev/null +++ b/src/ML-SNAP/pair_sna_grid.h @@ -0,0 +1,76 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS +// clang-format off +PairStyle(sna/grid, PairSNAGrid); +// clang-format on +#else + +#ifndef LMP_PAIR_SNA_GRID_H +#define LMP_PAIR_SNA_GRID_H + +#include "pair_grid.h" + +namespace LAMMPS_NS { + +class PairSNAGrid : public PairGrid { + public: + PairSNAGrid(class LAMMPS *); + ~PairSNAGrid(); + + void init(); + void init_list(int, class NeighList *); + void compute(int, int); + double memory_usage(); + + private: + int ncoeff; + double **cutsq; + class NeighList *list; + double rcutfac; + double *radelem; + double *wjelem; + int *map; // map types to [0,nelements) + int nelements, chemflag; + class SNA *snaptr; + double cutmax; + int quadraticflag; +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +E: Compute sna/grid/local requires a pair style be defined + +Self-explanatory. + +E: Compute sna/grid/local cutoff is longer than pairwise cutoff + +Self-explanatory. + +W: More than one compute sna/grid/local + +Self-explanatory. + +*/ diff --git a/src/pair_grid.cpp b/src/pair_grid.cpp new file mode 100644 index 0000000000..2d4abb7388 --- /dev/null +++ b/src/pair_grid.cpp @@ -0,0 +1,344 @@ +/* ---------------------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#include "pair_grid.h" +#include +#include +#include "atom.h" +#include "update.h" +#include "modify.h" +#include "domain.h" +#include "force.h" +#include "memory.h" +#include "error.h" +#include "comm.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +PairGrid::PairGrid(LAMMPS *lmp) : + Pair(lmp), gridlocal(nullptr), alocal(nullptr) +{ + single_enable = 0; + restartinfo = 0; + one_coeff = 1; + manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; + + + ndesc = 0; + ngridlocal = 0; + + ndesc_base = 6; + gridlocal_allocated = 0; + beta_max = 0; + beta = nullptr; +} + +/* ---------------------------------------------------------------------- */ + +PairGrid::~PairGrid() +{ + if (copymode) return; + + memory->destroy(beta); + + deallocate_grid(); +} + +/* ---------------------------------------------------------------------- */ + +void PairGrid::init() +{ +} + +/* ---------------------------------------------------------------------- */ + +void PairGrid::setup() +{ + deallocate_grid(); + set_grid_global(); + set_grid_local(); + allocate_grid(); + assign_coords(); +} + +/* ---------------------------------------------------------------------- + convert global array indexes to box coords +------------------------------------------------------------------------- */ + +void PairGrid::grid2x(int ix, int iy, int iz, double *x) +{ + x[0] = ix*delx; + x[1] = iy*dely; + x[2] = iz*delz; + + if (triclinic) domain->lamda2x(x, x); +} + +/* ---------------------------------------------------------------------- + create arrays +------------------------------------------------------------------------- */ + +void PairGrid::allocate_grid() +{ + if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { + gridlocal_allocated = 1; + memory->create4d_offset(gridlocal,ndesc,nzlo,nzhi,nylo,nyhi, + nxlo,nxhi,"pair/grid:gridlocal"); + memory->create(alocal, ngridlocal, ndesc, "pair/grid:alocal"); + } +} + +/* ---------------------------------------------------------------------- + free arrays +------------------------------------------------------------------------- */ + +void PairGrid::deallocate_grid() +{ + if (gridlocal_allocated) { + gridlocal_allocated = 0; + memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + memory->destroy(alocal); + } +} + +/* ---------------------------------------------------------------------- + set global grid +------------------------------------------------------------------------- */ + +void PairGrid::set_grid_global() +{ + // calculate grid layout + + triclinic = domain->triclinic; + + if (triclinic == 0) { + prd = domain->prd; + boxlo = domain->boxlo; + sublo = domain->sublo; + subhi = domain->subhi; + } else { + prd = domain->prd_lamda; + boxlo = domain->boxlo_lamda; + sublo = domain->sublo_lamda; + subhi = domain->subhi_lamda; + } + + double xprd = prd[0]; + double yprd = prd[1]; + double zprd = prd[2]; + + delxinv = nx/xprd; + delyinv = ny/yprd; + delzinv = nz/zprd; + + delx = 1.0/delxinv; + dely = 1.0/delyinv; + delz = 1.0/delzinv; +} + +/* ---------------------------------------------------------------------- + set local subset of grid that I own + n xyz lo/hi = 3d brick that I own (inclusive) +------------------------------------------------------------------------- */ + +void PairGrid::set_grid_local() +{ + // nx,ny,nz = extent of global grid + // indices into the global grid range from 0 to N-1 in each dim + // if grid point is inside my sub-domain I own it, + // this includes sub-domain lo boundary but excludes hi boundary + // ixyz lo/hi = inclusive lo/hi bounds of global grid sub-brick I own + // if proc owns no grid cells in a dim, then ilo > ihi + // if 2 procs share a boundary a grid point is exactly on, + // the 2 equality if tests insure a consistent decision + // as to which proc owns it + + double xfraclo,xfrachi,yfraclo,yfrachi,zfraclo,zfrachi; + + if (comm->layout != Comm::LAYOUT_TILED) { + xfraclo = comm->xsplit[comm->myloc[0]]; + xfrachi = comm->xsplit[comm->myloc[0]+1]; + yfraclo = comm->ysplit[comm->myloc[1]]; + yfrachi = comm->ysplit[comm->myloc[1]+1]; + zfraclo = comm->zsplit[comm->myloc[2]]; + zfrachi = comm->zsplit[comm->myloc[2]+1]; + } else { + xfraclo = comm->mysplit[0][0]; + xfrachi = comm->mysplit[0][1]; + yfraclo = comm->mysplit[1][0]; + yfrachi = comm->mysplit[1][1]; + zfraclo = comm->mysplit[2][0]; + zfrachi = comm->mysplit[2][1]; + } + + nxlo = static_cast (xfraclo * nx); + if (1.0*nxlo != xfraclo*nx) nxlo++; + nxhi = static_cast (xfrachi * nx); + if (1.0*nxhi == xfrachi*nx) nxhi--; + + nylo = static_cast (yfraclo * ny); + if (1.0*nylo != yfraclo*ny) nylo++; + nyhi = static_cast (yfrachi * ny); + if (1.0*nyhi == yfrachi*ny) nyhi--; + + nzlo = static_cast (zfraclo * nz); + if (1.0*nzlo != zfraclo*nz) nzlo++; + nzhi = static_cast (zfrachi * nz); + if (1.0*nzhi == zfrachi*nz) nzhi--; + + ngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); +} + +/* ---------------------------------------------------------------------- + copy coords to local array +------------------------------------------------------------------------- */ + +void PairGrid::assign_coords() +{ + int igrid = 0; + for (int iz = nzlo; iz <= nzhi; iz++) + for (int iy = nylo; iy <= nyhi; iy++) + for (int ix = nxlo; ix <= nxhi; ix++) { + alocal[igrid][0] = ix; + alocal[igrid][1] = iy; + alocal[igrid][2] = iz; + double xgrid[3]; + grid2x(ix, iy, iz, xgrid); + alocal[igrid][3] = xgrid[0]; + alocal[igrid][4] = xgrid[1]; + alocal[igrid][5] = xgrid[2]; + igrid++; + } +} + +/* ---------------------------------------------------------------------- + copy the 4d gridlocal array values to the 2d local array +------------------------------------------------------------------------- */ + +void PairGrid::copy_gridlocal_to_local_array() +{ + int igrid = 0; + for (int iz = nzlo; iz <= nzhi; iz++) + for (int iy = nylo; iy <= nyhi; iy++) + for (int ix = nxlo; ix <= nxhi; ix++) { + for (int icol = ndesc_base; icol < ndesc; icol++) + alocal[igrid][icol] = gridlocal[icol][iz][iy][ix]; + igrid++; + } +} + +/* ---------------------------------------------------------------------- + get beta from someplace +------------------------------------------------------------------------- */ + +void PairGrid::compute_beta() +{ + int igrid = 0; + for (int iz = nzlo; iz <= nzhi; iz++) + for (int iy = nylo; iy <= nyhi; iy++) + for (int ix = nxlo; ix <= nxhi; ix++) { + for (int icol = ndesc_base; icol < ndesc; icol++) + beta[igrid][icol] = 1.0; + igrid++; + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +void PairGrid::allocate() +{ + allocated = 1; + int n = atom->ntypes; + memory->create(setflag,n+1,n+1,"pair:setflag"); + memory->create(cutsq,n+1,n+1,"pair:cutsq"); + map = new int[n+1]; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +void PairGrid::settings(int narg, char ** arg) +{ + if (narg < 6) error->all(FLERR,"Illegal pair style command"); + + int iarg0 = 3; + int iarg = iarg0; + if (strcmp(arg[iarg],"grid") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal pair grid command"); + nx = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + ny = utils::inumeric(FLERR,arg[iarg+2],false,lmp); + nz = utils::inumeric(FLERR,arg[iarg+3],false,lmp); + if (nx <= 0 || ny <= 0 || nz <= 0) + error->all(FLERR,"All grid/local dimensions must be positive"); + iarg += 4; + } else error->all(FLERR,"Illegal pair grid command"); + + nargbase = iarg - iarg0; + +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +void PairGrid::coeff(int narg, char **arg) +{ + if (!allocated) allocate(); + if (narg != 2 + atom->ntypes) error->all(FLERR,"Incorrect args for pair coefficients"); + + map_element2type(narg-4,arg+4); + +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +void PairGrid::init_style() +{ + if (force->newton_pair == 0) + error->all(FLERR,"Pair style grid requires newton pair on"); + + // no neighbor list + + // int irequest = neighbor->request(this,instance_me); + // neighbor->requests[irequest]->half = 0; + // neighbor->requests[irequest]->full = 1; + +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +double PairGrid::init_one(int i, int j) +{ + if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); + return 0.0; +} + +/* ---------------------------------------------------------------------- + memory usage of local data +------------------------------------------------------------------------- */ + +double PairGrid::memory_usage() +{ + int nbytes = ndesc*ngridlocal*sizeof(double); // gridlocal + return nbytes; +} diff --git a/src/pair_grid.h b/src/pair_grid.h new file mode 100644 index 0000000000..9c40165154 --- /dev/null +++ b/src/pair_grid.h @@ -0,0 +1,88 @@ +/* -*- 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 +// clang-format off +PairStyle(grid,PairGrid); +// clang-format on +#else + +#ifndef LMP_PAIR_GRID_H +#define LMP_PAIR_GRID_H + +#include "pair.h" + +namespace LAMMPS_NS { + +class PairGrid : public Pair { + public: + PairGrid(class LAMMPS *); + virtual ~PairGrid(); + void init(); + void setup(); + virtual void compute(int, int) { + printf("DANGER! This function should always be overridden by child\n"); + }; + + void settings(int, char **); + virtual void coeff(int, char **); + virtual void init_style(); + virtual double init_one(int, int); + double memory_usage(); + + protected: + int nx, ny, nz; // global grid dimensions + int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive + int ngridlocal; // number of local grid points + int nvalues; // number of values per grid point + double ****gridlocal; // local grid + double **alocal; // pointer to Compute::array_local + int triclinic; // triclinic flag + double *boxlo, *prd; // box info (units real/ortho or reduced/tri) + double *sublo, *subhi; // subdomain info (units real/ortho or reduced/tri) + double delxinv,delyinv,delzinv; // inverse grid spacing + double delx,dely,delz; // grid spacing + int nargbase; // number of base class args + double cutmax; // largest cutoff distance + int ndesc; // number of descriptors + int ndesc_base; // number of columns used for coords, etc. + int gridlocal_allocated; // shows if gridlocal allocated + double **beta; // betas for all local grid points in list + int beta_max; // length of beta + + void allocate(); // allocate pairstyle arrays + void allocate_grid(); // create grid arrays + void deallocate_grid(); // free grid arrays + void grid2x(int, int, int, double*); // convert global indices to coordinates + void set_grid_global(); // set global grid + void set_grid_local(); // set bounds for local grid + void assign_coords(); // assign coords for grid + void copy_gridlocal_to_local_array();// copy 4d gridlocal array to 2d local array + void compute_beta(); // get betas from someplace + private: +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +*/ From f41d65029418633e688bcb24e1f1b83414f1ba75 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Sun, 3 Oct 2021 17:59:33 -0600 Subject: [PATCH 34/91] Added non-working pair script --- examples/snap/in.grid.pair | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 examples/snap/in.grid.pair diff --git a/examples/snap/in.grid.pair b/examples/snap/in.grid.pair new file mode 100644 index 0000000000..ee40984ce6 --- /dev/null +++ b/examples/snap/in.grid.pair @@ -0,0 +1,61 @@ +# Demonstrate bispectrum computes + +# CORRECTNESS: thermo output for c_mygrid[*][1] and c_mygrid[*][8] should +# match the values in dump_b: 108.173 3.21778 0.712238 7.06634 1.04273 + +# Initialize simulation + +variable nsteps index 0 +variable nrep index 3 +variable a index 3.316 +variable ngrid index 2 + +units metal + +atom_modify map yes + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice custom $a & + a1 1 0 0 & + a2 0 1 0 & + a3 0 0 1 & + basis 0 0 0 & + basis 0.5 0.5 0.5 & +# origin 0.25 0.25 0.25 +# origin 0.25e-3 0.25e-3 0.25e-3 + +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 180.88 + +write_dump all custom test.dump id type x y z + +# define grid compute and atom compute + +group snapgroup type 1 +variable twojmax equal 2 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quad equal 0 +variable switch equal 1 + +pair_style sna/grid grid ${ngrid} ${ngrid} ${ngrid} & + ${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & + quadraticflag ${quad} switchflag ${switch} +pair_coeff * * + +run 0 From e698d295fc6fd6afdeca34ee2709342b1427f6d7 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Sun, 3 Oct 2021 18:35:54 -0600 Subject: [PATCH 35/91] Fixed some parsing errors, more waiting --- src/ML-SNAP/pair_sna_grid.cpp | 120 ++++++++++++++++++++++++++++++++++ src/ML-SNAP/pair_sna_grid.h | 1 + src/pair_grid.cpp | 7 +- 3 files changed, 123 insertions(+), 5 deletions(-) diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp index 605e05ebf9..f2176b7520 100644 --- a/src/ML-SNAP/pair_sna_grid.cpp +++ b/src/ML-SNAP/pair_sna_grid.cpp @@ -167,6 +167,126 @@ void PairSNAGrid::compute(int eflag, int vflag) } +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +void PairSNAGrid::settings(int narg, char ** arg) +{ + double rfac0, rmin0; + int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; + + // call base class first + + PairGrid::settings(narg, arg); + + // skip over arguments used by base class + // so that argument positions are identical to + // regular per-atom compute + + arg += nargbase; + narg -= nargbase; + + int ntypes = atom->ntypes; + int nargmin = 3+2*ntypes; + + if (narg < nargmin) error->all(FLERR,"Illegal pair sna/grid command"); + + // default values + + rmin0 = 0.0; + switchflag = 1; + bzeroflag = 1; + quadraticflag = 0; + chemflag = 0; + bnormflag = 0; + wselfallflag = 0; + nelements = 1; + + // process required arguments + + memory->create(radelem,ntypes+1,"sna/grid/local:radelem"); // offset by 1 to match up with types + memory->create(wjelem,ntypes+1,"sna/grid/local:wjelem"); + + rcutfac = atof(arg[0]); + rfac0 = atof(arg[1]); + twojmax = atoi(arg[2]); + + for(int i = 0; i < ntypes; i++) + radelem[i+1] = atof(arg[3+i]); + for(int i = 0; i < ntypes; i++) + wjelem[i+1] = atof(arg[3+ntypes+i]); + + // construct cutsq + + double cut; + cutmax = 0.0; + memory->create(cutsq,ntypes+1,ntypes+1,"sna/grid/local:cutsq"); + for(int i = 1; i <= ntypes; i++) { + cut = 2.0*radelem[i]*rcutfac; + if (cut > cutmax) cutmax = cut; + cutsq[i][i] = cut*cut; + for(int j = i+1; j <= ntypes; j++) { + cut = (radelem[i]+radelem[j])*rcutfac; + cutsq[i][j] = cutsq[j][i] = cut*cut; + } + } + + // process optional args + + int iarg = nargmin; + + while (iarg < narg) { + printf("%d %d %d %s\n",iarg,narg,nargbase,arg[iarg]); + if (strcmp(arg[iarg],"rmin0") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal pair sna/grid command"); + rmin0 = atof(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"switchflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal pair sna/grid command"); + switchflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"bzeroflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal pair sna/grid command"); + bzeroflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"quadraticflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal pair sna/grid command"); + quadraticflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"chem") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal pair sna/grid command"); + chemflag = 1; + memory->create(map,ntypes+1,"compute_sna_grid_local:map"); + nelements = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + for (int i = 0; i < ntypes; i++) { + int jelem = utils::inumeric(FLERR,arg[iarg+2+i],false,lmp); + if (jelem < 0 || jelem >= nelements) + error->all(FLERR,"Illegal pair sna/grid command"); + map[i+1] = jelem; + } + iarg += 2+ntypes; + } else if (strcmp(arg[iarg],"bnormflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal pair sna/grid command"); + bnormflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"wselfallflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal pair sna/grid command"); + wselfallflag = atoi(arg[iarg+1]); + iarg += 2; + } else error->all(FLERR,"Illegal pair sna/grid command"); + + } + +} + /* ---------------------------------------------------------------------- memory usage ------------------------------------------------------------------------- */ diff --git a/src/ML-SNAP/pair_sna_grid.h b/src/ML-SNAP/pair_sna_grid.h index d94032e58c..30b6aa8f92 100644 --- a/src/ML-SNAP/pair_sna_grid.h +++ b/src/ML-SNAP/pair_sna_grid.h @@ -31,6 +31,7 @@ class PairSNAGrid : public PairGrid { void init(); void init_list(int, class NeighList *); + void settings(int, char **); void compute(int, int); double memory_usage(); diff --git a/src/pair_grid.cpp b/src/pair_grid.cpp index 2d4abb7388..56478ad21f 100644 --- a/src/pair_grid.cpp +++ b/src/pair_grid.cpp @@ -275,9 +275,8 @@ void PairGrid::allocate() void PairGrid::settings(int narg, char ** arg) { - if (narg < 6) error->all(FLERR,"Illegal pair style command"); - - int iarg0 = 3; + if (narg < 4) error->all(FLERR,"Illegal pair style command"); + int iarg0 = 0; int iarg = iarg0; if (strcmp(arg[iarg],"grid") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal pair grid command"); @@ -288,9 +287,7 @@ void PairGrid::settings(int narg, char ** arg) error->all(FLERR,"All grid/local dimensions must be positive"); iarg += 4; } else error->all(FLERR,"Illegal pair grid command"); - nargbase = iarg - iarg0; - } /* ---------------------------------------------------------------------- From 1450af8ba19991984c682ffb52fa253f5c30d06c Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 22 Oct 2021 17:01:20 -0600 Subject: [PATCH 36/91] Latest version of PairGrid --- src/ML-SNAP/pair_sna_grid.cpp | 8 ++++---- src/ML-SNAP/pair_sna_grid.h | 1 - src/pair_grid.cpp | 11 +++++++---- src/pair_grid.h | 2 +- src/verlet.cpp | 6 ++++++ 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp index f2176b7520..3bfdcb7e12 100644 --- a/src/ML-SNAP/pair_sna_grid.cpp +++ b/src/ML-SNAP/pair_sna_grid.cpp @@ -205,8 +205,8 @@ void PairSNAGrid::settings(int narg, char ** arg) // process required arguments - memory->create(radelem,ntypes+1,"sna/grid/local:radelem"); // offset by 1 to match up with types - memory->create(wjelem,ntypes+1,"sna/grid/local:wjelem"); + memory->create(radelem,ntypes+1,"pair:sna/grid:radelem"); // offset by 1 to match up with types + memory->create(wjelem,ntypes+1,"pair:sna/grid:wjelem"); rcutfac = atof(arg[0]); rfac0 = atof(arg[1]); @@ -221,7 +221,7 @@ void PairSNAGrid::settings(int narg, char ** arg) double cut; cutmax = 0.0; - memory->create(cutsq,ntypes+1,ntypes+1,"sna/grid/local:cutsq"); + memory->create(cutsq,ntypes+1,ntypes+1,"pair:sna/grid:cutsq"); for(int i = 1; i <= ntypes; i++) { cut = 2.0*radelem[i]*rcutfac; if (cut > cutmax) cutmax = cut; @@ -262,7 +262,7 @@ void PairSNAGrid::settings(int narg, char ** arg) if (iarg+2 > narg) error->all(FLERR,"Illegal pair sna/grid command"); chemflag = 1; - memory->create(map,ntypes+1,"compute_sna_grid_local:map"); + memory->create(map,ntypes+1,"pair:sna/grid:map"); nelements = utils::inumeric(FLERR,arg[iarg+1],false,lmp); for (int i = 0; i < ntypes; i++) { int jelem = utils::inumeric(FLERR,arg[iarg+2+i],false,lmp); diff --git a/src/ML-SNAP/pair_sna_grid.h b/src/ML-SNAP/pair_sna_grid.h index 30b6aa8f92..2216739ce3 100644 --- a/src/ML-SNAP/pair_sna_grid.h +++ b/src/ML-SNAP/pair_sna_grid.h @@ -45,7 +45,6 @@ class PairSNAGrid : public PairGrid { int *map; // map types to [0,nelements) int nelements, chemflag; class SNA *snaptr; - double cutmax; int quadraticflag; }; diff --git a/src/pair_grid.cpp b/src/pair_grid.cpp index 56478ad21f..166d4c258d 100644 --- a/src/pair_grid.cpp +++ b/src/pair_grid.cpp @@ -67,6 +67,7 @@ void PairGrid::init() void PairGrid::setup() { + printf("Hello, world! C\n"); deallocate_grid(); set_grid_global(); set_grid_local(); @@ -297,9 +298,11 @@ void PairGrid::settings(int narg, char ** arg) void PairGrid::coeff(int narg, char **arg) { if (!allocated) allocate(); - if (narg != 2 + atom->ntypes) error->all(FLERR,"Incorrect args for pair coefficients"); + if (narg != 2) error->all(FLERR,"Incorrect args for pair coefficients"); + // if (narg != 2 + atom->ntypes) error->all(FLERR,"Incorrect args for pair coefficients"); - map_element2type(narg-4,arg+4); + // map_element2type(narg-4,arg+4); + // map_element2type(0,nullptr); } @@ -321,13 +324,13 @@ void PairGrid::init_style() } /* ---------------------------------------------------------------------- - init for one type pair i,j and corresponding j,i + return maximum force cut off distance ------------------------------------------------------------------------- */ double PairGrid::init_one(int i, int j) { if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); - return 0.0; + return cutmax; } /* ---------------------------------------------------------------------- diff --git a/src/pair_grid.h b/src/pair_grid.h index 9c40165154..d7aa151633 100644 --- a/src/pair_grid.h +++ b/src/pair_grid.h @@ -57,7 +57,7 @@ class PairGrid : public Pair { int ndesc; // number of descriptors int ndesc_base; // number of columns used for coords, etc. int gridlocal_allocated; // shows if gridlocal allocated - double **beta; // betas for all local grid points in list + double **beta; // betas for all local grid points in list int beta_max; // length of beta void allocate(); // allocate pairstyle arrays diff --git a/src/verlet.cpp b/src/verlet.cpp index b9b0b392e1..385b234a29 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -99,6 +99,8 @@ void Verlet::setup(int flag) } } + printf("Hello, world! A\n"); + if (lmp->kokkos) error->all(FLERR,"KOKKOS package requires run_style verlet/kk"); @@ -126,6 +128,8 @@ void Verlet::setup(int flag) modify->setup_post_neighbor(); neighbor->ncalls = 0; + printf("Hello, world! B\n"); + // compute all forces force->setup(); @@ -133,6 +137,8 @@ void Verlet::setup(int flag) force_clear(); modify->setup_pre_force(vflag); + printf("Hello, world!\n"); + if (pair_compute_flag) force->pair->compute(eflag,vflag); else if (force->pair) force->pair->compute_dummy(eflag,vflag); From 6d5506353b83fc369259cc29add6dc6f67d34fca Mon Sep 17 00:00:00 2001 From: LOFT Date: Sun, 24 Oct 2021 15:45:24 -0600 Subject: [PATCH 37/91] Eliminated a few mistakes,s till not working --- examples/snap/in.grid.pair | 2 +- src/ML-SNAP/pair_sna_grid.cpp | 15 +++++++------ src/ML-SNAP/pair_sna_grid.h | 7 ++++-- src/pair_grid.cpp | 40 +++++++++++++---------------------- src/pair_grid.h | 3 +-- 5 files changed, 31 insertions(+), 36 deletions(-) diff --git a/examples/snap/in.grid.pair b/examples/snap/in.grid.pair index ee40984ce6..9d21c1f62c 100644 --- a/examples/snap/in.grid.pair +++ b/examples/snap/in.grid.pair @@ -56,6 +56,6 @@ pair_style sna/grid grid ${ngrid} ${ngrid} ${ngrid} & ${rcutfac} ${rfac0} ${twojmax} ${radelem} & ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & quadraticflag ${quad} switchflag ${switch} -pair_coeff * * +pair_coeff * * Al run 0 diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp index 3bfdcb7e12..7e626edd1a 100644 --- a/src/ML-SNAP/pair_sna_grid.cpp +++ b/src/ML-SNAP/pair_sna_grid.cpp @@ -53,14 +53,11 @@ PairSNAGrid::~PairSNAGrid() /* ---------------------------------------------------------------------- */ -void PairSNAGrid::init() +void PairSNAGrid::init_style() { if (force->pair == nullptr) error->all(FLERR,"Pair sna/grid requires a pair style be defined"); - if (cutmax > force->pair->cutforce) - error->all(FLERR,"Pair sna/grid cutoff is longer than pairwise cutoff"); - // need an occasional full neighbor list int irequest = neighbor->request(this,instance_me); @@ -70,7 +67,13 @@ void PairSNAGrid::init() neighbor->requests[irequest]->full = 1; neighbor->requests[irequest]->occasional = 1; + snaptr = new SNA(lmp, rfac0, twojmax, + rmin0, switchflag, bzeroflag, + chemflag, bnormflag, wselfallflag, nelements); + ndesc = ndesc_base + snaptr->ncoeff; + printf("ndesc = %d\n", ndesc); snaptr->init(); + } /* ---------------------------------------------------------------------- */ @@ -173,8 +176,6 @@ void PairSNAGrid::compute(int eflag, int vflag) void PairSNAGrid::settings(int narg, char ** arg) { - double rfac0, rmin0; - int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; // call base class first @@ -232,6 +233,8 @@ void PairSNAGrid::settings(int narg, char ** arg) } } + printf("settings cutmax = %g \n",cutmax); + // process optional args int iarg = nargmin; diff --git a/src/ML-SNAP/pair_sna_grid.h b/src/ML-SNAP/pair_sna_grid.h index 2216739ce3..929d6db975 100644 --- a/src/ML-SNAP/pair_sna_grid.h +++ b/src/ML-SNAP/pair_sna_grid.h @@ -29,7 +29,7 @@ class PairSNAGrid : public PairGrid { PairSNAGrid(class LAMMPS *); ~PairSNAGrid(); - void init(); + void init_style(); void init_list(int, class NeighList *); void settings(int, char **); void compute(int, int); @@ -43,9 +43,12 @@ class PairSNAGrid : public PairGrid { double *radelem; double *wjelem; int *map; // map types to [0,nelements) - int nelements, chemflag; + int nelements; class SNA *snaptr; int quadraticflag; + int twojmax, switchflag, bzeroflag, bnormflag; + int chemflag, wselfallflag; + double rfac0, rmin0; }; } diff --git a/src/pair_grid.cpp b/src/pair_grid.cpp index 166d4c258d..b552b509e5 100644 --- a/src/pair_grid.cpp +++ b/src/pair_grid.cpp @@ -59,20 +59,19 @@ PairGrid::~PairGrid() /* ---------------------------------------------------------------------- */ -void PairGrid::init() -{ -} - -/* ---------------------------------------------------------------------- */ - void PairGrid::setup() { printf("Hello, world! C\n"); deallocate_grid(); + printf("Hello, world! D\n"); set_grid_global(); + printf("Hello, world! E\n"); set_grid_local(); + printf("Hello, world! F\n"); allocate_grid(); + printf("Hello, world! G\n"); assign_coords(); + printf("Hello, world! H\n"); } /* ---------------------------------------------------------------------- @@ -96,6 +95,7 @@ void PairGrid::allocate_grid() { if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { gridlocal_allocated = 1; + printf("ngridlocal = %d ndesc = %d\n",ngridlocal, ndesc); memory->create4d_offset(gridlocal,ndesc,nzlo,nzhi,nylo,nyhi, nxlo,nxhi,"pair/grid:gridlocal"); memory->create(alocal, ngridlocal, ndesc, "pair/grid:alocal"); @@ -209,6 +209,7 @@ void PairGrid::set_grid_local() void PairGrid::assign_coords() { + printf("nxhi/lo = %d %d nyhi/lo = %d %d nzhi/lo = %d %d\n",nxlo,nxhi,nylo,nyhi,nzlo,nzhi); int igrid = 0; for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) @@ -266,6 +267,10 @@ void PairGrid::allocate() allocated = 1; int n = atom->ntypes; memory->create(setflag,n+1,n+1,"pair:setflag"); + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + setflag[i][j] = 0; + memory->create(cutsq,n+1,n+1,"pair:cutsq"); map = new int[n+1]; } @@ -298,38 +303,23 @@ void PairGrid::settings(int narg, char ** arg) void PairGrid::coeff(int narg, char **arg) { if (!allocated) allocate(); - if (narg != 2) error->all(FLERR,"Incorrect args for pair coefficients"); + if (narg < 2) error->all(FLERR,"Incorrect args for pair coefficients"); // if (narg != 2 + atom->ntypes) error->all(FLERR,"Incorrect args for pair coefficients"); - // map_element2type(narg-4,arg+4); + map_element2type(narg-2,arg+2); // map_element2type(0,nullptr); } -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairGrid::init_style() -{ - if (force->newton_pair == 0) - error->all(FLERR,"Pair style grid requires newton pair on"); - - // no neighbor list - - // int irequest = neighbor->request(this,instance_me); - // neighbor->requests[irequest]->half = 0; - // neighbor->requests[irequest]->full = 1; - -} - /* ---------------------------------------------------------------------- return maximum force cut off distance ------------------------------------------------------------------------- */ double PairGrid::init_one(int i, int j) { + printf("i = %d j = %d setflag = %d\n", i, j, setflag[i][j]); if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); + printf("PairGrid cutmax = %g\n",cutmax); return cutmax; } diff --git a/src/pair_grid.h b/src/pair_grid.h index d7aa151633..97799a5c30 100644 --- a/src/pair_grid.h +++ b/src/pair_grid.h @@ -28,7 +28,7 @@ class PairGrid : public Pair { public: PairGrid(class LAMMPS *); virtual ~PairGrid(); - void init(); + virtual void init_style(){}; void setup(); virtual void compute(int, int) { printf("DANGER! This function should always be overridden by child\n"); @@ -36,7 +36,6 @@ class PairGrid : public Pair { void settings(int, char **); virtual void coeff(int, char **); - virtual void init_style(); virtual double init_one(int, int); double memory_usage(); From dcf521be53a00542c4e06b17c4114574b245a76e Mon Sep 17 00:00:00 2001 From: LOFT Date: Fri, 29 Oct 2021 06:34:32 -0600 Subject: [PATCH 38/91] Fixed a few more problems, but still no joy --- src/ML-SNAP/pair_sna_grid.cpp | 3 ++- src/ML-SNAP/pair_sna_grid.h | 3 --- src/pair_grid.cpp | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp index 7e626edd1a..dc3de8e941 100644 --- a/src/ML-SNAP/pair_sna_grid.cpp +++ b/src/ML-SNAP/pair_sna_grid.cpp @@ -34,9 +34,10 @@ using namespace LAMMPS_NS; PairSNAGrid::PairSNAGrid(LAMMPS *lmp) : - PairGrid(lmp), cutsq(nullptr), + PairGrid(lmp), radelem(nullptr), wjelem(nullptr) { + snaptr = nullptr; } /* ---------------------------------------------------------------------- */ diff --git a/src/ML-SNAP/pair_sna_grid.h b/src/ML-SNAP/pair_sna_grid.h index 929d6db975..9ae0eece79 100644 --- a/src/ML-SNAP/pair_sna_grid.h +++ b/src/ML-SNAP/pair_sna_grid.h @@ -37,13 +37,10 @@ class PairSNAGrid : public PairGrid { private: int ncoeff; - double **cutsq; class NeighList *list; double rcutfac; double *radelem; double *wjelem; - int *map; // map types to [0,nelements) - int nelements; class SNA *snaptr; int quadraticflag; int twojmax, switchflag, bzeroflag, bnormflag; diff --git a/src/pair_grid.cpp b/src/pair_grid.cpp index b552b509e5..dd35f75f8c 100644 --- a/src/pair_grid.cpp +++ b/src/pair_grid.cpp @@ -36,7 +36,6 @@ PairGrid::PairGrid(LAMMPS *lmp) : manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - ndesc = 0; ngridlocal = 0; @@ -62,7 +61,7 @@ PairGrid::~PairGrid() void PairGrid::setup() { printf("Hello, world! C\n"); - deallocate_grid(); + // deallocate_grid(); printf("Hello, world! D\n"); set_grid_global(); printf("Hello, world! E\n"); @@ -70,7 +69,7 @@ void PairGrid::setup() printf("Hello, world! F\n"); allocate_grid(); printf("Hello, world! G\n"); - assign_coords(); + // assign_coords(); printf("Hello, world! H\n"); } @@ -273,6 +272,7 @@ void PairGrid::allocate() memory->create(cutsq,n+1,n+1,"pair:cutsq"); map = new int[n+1]; + printf("Allocated!\n"); } /* ---------------------------------------------------------------------- From 591af3f5602c8e63707f446d8727cf9931755ef8 Mon Sep 17 00:00:00 2001 From: LOFT Date: Fri, 29 Oct 2021 07:49:15 -0600 Subject: [PATCH 39/91] Eliminated obvious but hard to find error in neighbor list request --- examples/snap/in.grid.pair | 2 ++ src/ML-SNAP/pair_sna_grid.cpp | 9 +++------ src/pair_grid.cpp | 2 ++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/snap/in.grid.pair b/examples/snap/in.grid.pair index 9d21c1f62c..5f70f79d09 100644 --- a/examples/snap/in.grid.pair +++ b/examples/snap/in.grid.pair @@ -58,4 +58,6 @@ pair_style sna/grid grid ${ngrid} ${ngrid} ${ngrid} & quadraticflag ${quad} switchflag ${switch} pair_coeff * * Al +neighbor 0.0 nsq + run 0 diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp index dc3de8e941..6dc7bc9173 100644 --- a/src/ML-SNAP/pair_sna_grid.cpp +++ b/src/ML-SNAP/pair_sna_grid.cpp @@ -56,17 +56,14 @@ PairSNAGrid::~PairSNAGrid() void PairSNAGrid::init_style() { - if (force->pair == nullptr) - error->all(FLERR,"Pair sna/grid requires a pair style be defined"); + if (force->newton_pair == 0) + error->all(FLERR,"Pair style sna/grid requires newton pair on"); - // need an occasional full neighbor list + // need a full neighbor list int irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->pair = 0; - neighbor->requests[irequest]->compute = 1; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->full = 1; - neighbor->requests[irequest]->occasional = 1; snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, diff --git a/src/pair_grid.cpp b/src/pair_grid.cpp index dd35f75f8c..f76629717b 100644 --- a/src/pair_grid.cpp +++ b/src/pair_grid.cpp @@ -60,6 +60,7 @@ PairGrid::~PairGrid() void PairGrid::setup() { + printf("Inside PairGrid::setup()\n"); printf("Hello, world! C\n"); // deallocate_grid(); printf("Hello, world! D\n"); @@ -317,6 +318,7 @@ void PairGrid::coeff(int narg, char **arg) double PairGrid::init_one(int i, int j) { + printf("Inside PairGrid::init_one()\n"); printf("i = %d j = %d setflag = %d\n", i, j, setflag[i][j]); if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); printf("PairGrid cutmax = %g\n",cutmax); From c69edde55cf3245c9ab30bf455927be94f63b232 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 10 Dec 2021 18:30:44 -0700 Subject: [PATCH 40/91] Eliminated several undefined variables --- examples/snap/in.grid.pair | 8 +++----- src/ML-SNAP/pair_sna_grid.cpp | 10 +++++----- src/pair_grid.cpp | 17 ++--------------- src/verlet.cpp | 6 ------ 4 files changed, 10 insertions(+), 31 deletions(-) diff --git a/examples/snap/in.grid.pair b/examples/snap/in.grid.pair index 5f70f79d09..e2143427e6 100644 --- a/examples/snap/in.grid.pair +++ b/examples/snap/in.grid.pair @@ -1,8 +1,5 @@ -# Demonstrate bispectrum computes +# Demonstrate pair style base on sna/grid -# CORRECTNESS: thermo output for c_mygrid[*][1] and c_mygrid[*][8] should -# match the values in dump_b: 108.173 3.21778 0.712238 7.06634 1.04273 - # Initialize simulation variable nsteps index 0 @@ -58,6 +55,7 @@ pair_style sna/grid grid ${ngrid} ${ngrid} ${ngrid} & quadraticflag ${quad} switchflag ${switch} pair_coeff * * Al +thermo_style custom step temp epair emol etotal press neighbor 0.0 nsq -run 0 +run 10 diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp index 6dc7bc9173..5be3bf98d6 100644 --- a/src/ML-SNAP/pair_sna_grid.cpp +++ b/src/ML-SNAP/pair_sna_grid.cpp @@ -68,8 +68,8 @@ void PairSNAGrid::init_style() snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements); - ndesc = ndesc_base + snaptr->ncoeff; - printf("ndesc = %d\n", ndesc); + ncoeff = snaptr->ncoeff; + ndesc = ndesc_base + ncoeff; snaptr->init(); } @@ -85,6 +85,7 @@ void PairSNAGrid::init_list(int /*id*/, NeighList *ptr) void PairSNAGrid::compute(int eflag, int vflag) { + ev_init(eflag,vflag); // compute sna for each gridpoint @@ -165,6 +166,8 @@ void PairSNAGrid::compute(int eflag, int vflag) } } } + + if (vflag_fdotr) virial_fdotr_compute(); } @@ -231,14 +234,11 @@ void PairSNAGrid::settings(int narg, char ** arg) } } - printf("settings cutmax = %g \n",cutmax); - // process optional args int iarg = nargmin; while (iarg < narg) { - printf("%d %d %d %s\n",iarg,narg,nargbase,arg[iarg]); if (strcmp(arg[iarg],"rmin0") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal pair sna/grid command"); diff --git a/src/pair_grid.cpp b/src/pair_grid.cpp index f76629717b..3f88635ecf 100644 --- a/src/pair_grid.cpp +++ b/src/pair_grid.cpp @@ -60,18 +60,11 @@ PairGrid::~PairGrid() void PairGrid::setup() { - printf("Inside PairGrid::setup()\n"); - printf("Hello, world! C\n"); - // deallocate_grid(); - printf("Hello, world! D\n"); + deallocate_grid(); set_grid_global(); - printf("Hello, world! E\n"); set_grid_local(); - printf("Hello, world! F\n"); allocate_grid(); - printf("Hello, world! G\n"); - // assign_coords(); - printf("Hello, world! H\n"); + assign_coords(); } /* ---------------------------------------------------------------------- @@ -95,7 +88,6 @@ void PairGrid::allocate_grid() { if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { gridlocal_allocated = 1; - printf("ngridlocal = %d ndesc = %d\n",ngridlocal, ndesc); memory->create4d_offset(gridlocal,ndesc,nzlo,nzhi,nylo,nyhi, nxlo,nxhi,"pair/grid:gridlocal"); memory->create(alocal, ngridlocal, ndesc, "pair/grid:alocal"); @@ -209,7 +201,6 @@ void PairGrid::set_grid_local() void PairGrid::assign_coords() { - printf("nxhi/lo = %d %d nyhi/lo = %d %d nzhi/lo = %d %d\n",nxlo,nxhi,nylo,nyhi,nzlo,nzhi); int igrid = 0; for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) @@ -273,7 +264,6 @@ void PairGrid::allocate() memory->create(cutsq,n+1,n+1,"pair:cutsq"); map = new int[n+1]; - printf("Allocated!\n"); } /* ---------------------------------------------------------------------- @@ -318,10 +308,7 @@ void PairGrid::coeff(int narg, char **arg) double PairGrid::init_one(int i, int j) { - printf("Inside PairGrid::init_one()\n"); - printf("i = %d j = %d setflag = %d\n", i, j, setflag[i][j]); if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); - printf("PairGrid cutmax = %g\n",cutmax); return cutmax; } diff --git a/src/verlet.cpp b/src/verlet.cpp index 385b234a29..b9b0b392e1 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -99,8 +99,6 @@ void Verlet::setup(int flag) } } - printf("Hello, world! A\n"); - if (lmp->kokkos) error->all(FLERR,"KOKKOS package requires run_style verlet/kk"); @@ -128,8 +126,6 @@ void Verlet::setup(int flag) modify->setup_post_neighbor(); neighbor->ncalls = 0; - printf("Hello, world! B\n"); - // compute all forces force->setup(); @@ -137,8 +133,6 @@ void Verlet::setup(int flag) force_clear(); modify->setup_pre_force(vflag); - printf("Hello, world!\n"); - if (pair_compute_flag) force->pair->compute(eflag,vflag); else if (force->pair) force->pair->compute_dummy(eflag,vflag); From addb8948f9a922e095d8184c59d6f7ffeab30b27 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 23 Dec 2021 15:01:41 -0700 Subject: [PATCH 41/91] Able to run dynamics smoothly, does not conserve energy, but maybe that is a feature --- examples/snap/in.grid.pair | 25 +++++-- src/ML-SNAP/pair_sna_grid.cpp | 125 +++++++++++++++++++++++++++++++++- src/compute_grid_local.h | 2 +- src/pair_grid.cpp | 19 ++++-- src/pair_grid.h | 2 +- 5 files changed, 158 insertions(+), 15 deletions(-) diff --git a/examples/snap/in.grid.pair b/examples/snap/in.grid.pair index e2143427e6..99c9623f7d 100644 --- a/examples/snap/in.grid.pair +++ b/examples/snap/in.grid.pair @@ -2,10 +2,14 @@ # Initialize simulation -variable nsteps index 0 +variable dt index 0.5e-5 +variable nthermo index 100 +variable nsteps index 10000 variable nrep index 3 -variable a index 3.316 +variable a index 3.0 variable ngrid index 2 +variable t index 300 +variable del index 0.1 units metal @@ -31,7 +35,7 @@ lattice custom $a & region box block 0 ${nx} 0 ${ny} 0 ${nz} create_box 1 box create_atoms 1 box - +displace_atoms all random ${del} ${del} ${del} 12345 mass 1 180.88 write_dump all custom test.dump id type x y z @@ -56,6 +60,17 @@ pair_style sna/grid grid ${ngrid} ${ngrid} ${ngrid} & pair_coeff * * Al thermo_style custom step temp epair emol etotal press -neighbor 0.0 nsq +thermo ${nthermo} +thermo_modify norm yes -run 10 +# Set up NVE run + +timestep ${dt} +neighbor 1.0 bin +neigh_modify once no every 1 delay 0 check yes + +# Run MD + +velocity all create $t 4928459 loop geom +fix 1 all nve +run ${nsteps} diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp index 5be3bf98d6..c84dcaf467 100644 --- a/src/ML-SNAP/pair_sna_grid.cpp +++ b/src/ML-SNAP/pair_sna_grid.cpp @@ -85,19 +85,25 @@ void PairSNAGrid::init_list(int /*id*/, NeighList *ptr) void PairSNAGrid::compute(int eflag, int vflag) { + double fij[3]; + ev_init(eflag,vflag); // compute sna for each gridpoint double** const x = atom->x; + double **f = atom->f; const int* const mask = atom->mask; int * const type = atom->type; const int ntotal = atom->nlocal + atom->nghost; - // insure rij, inside, and typej are of size jnum + // insure rij, inside, and typej are of size ntotal snaptr->grow_rij(ntotal); + // first generate fingerprint, + // which allows calculation of beta + for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { @@ -153,6 +159,7 @@ void PairSNAGrid::compute(int eflag, int vflag) snaptr->blist[icoeff]; // quadratic contributions + // untested if (quadraticflag) { int ncount = ncoeff; @@ -167,7 +174,123 @@ void PairSNAGrid::compute(int eflag, int vflag) } } + // this is a proxy for a call to the energy model + // beta is dE/dB^i, the derivative of the total + // energy w.r.t. to descriptors of grid point i + + compute_beta(); + + // second compute forces using beta + + int igrid = 0; + for (int iz = nzlo; iz <= nzhi; iz++) + for (int iy = nylo; iy <= nyhi; iy++) + for (int ix = nxlo; ix <= nxhi; ix++) { + double xgrid[3]; + grid2x(ix, iy, iz, xgrid); + const double xtmp = xgrid[0]; + const double ytmp = xgrid[1]; + const double ztmp = xgrid[2]; + + // currently, all grid points are type 1 + + const int itype = 1; + int ielem = 0; + if (chemflag) + ielem = map[itype]; + const double radi = radelem[itype]; + + // rij[][3] = displacements between atom I and those neighbors + // inside = indices of neighbors of I within cutoff + // typej = types of neighbors of I within cutoff + + int ninside = 0; + for (int j = 0; j < ntotal; j++) { + + const double delx = xtmp - x[j][0]; + const double dely = ytmp - x[j][1]; + const double delz = ztmp - x[j][2]; + const double rsq = delx*delx + dely*dely + delz*delz; + int jtype = type[j]; + int jelem = 0; + if (chemflag) + jelem = map[jtype]; + if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { + snaptr->rij[ninside][0] = delx; + snaptr->rij[ninside][1] = dely; + snaptr->rij[ninside][2] = delz; + snaptr->inside[ninside] = j; + snaptr->wj[ninside] = wjelem[jtype]; + snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; + snaptr->element[ninside] = jelem; // element index for multi-element snap + ninside++; + } + } + + // compute Ui, Yi for atom I + + if (chemflag) + snaptr->compute_ui(ninside, ielem); + else + snaptr->compute_ui(ninside, 0); + + // for neighbors of I within cutoff: + // compute Fij = dEi/dRj = -dEi/dRi + // add to Fi, subtract from Fj + // scaling is that for type I + + snaptr->compute_yi(beta[igrid]); + + for (int jj = 0; jj < ninside; jj++) { + int j = snaptr->inside[jj]; + if (chemflag) + snaptr->compute_duidrj(snaptr->rij[jj], snaptr->wj[jj], + snaptr->rcutij[jj],jj, snaptr->element[jj]); + else + snaptr->compute_duidrj(snaptr->rij[jj], snaptr->wj[jj], + snaptr->rcutij[jj],jj, 0); + + snaptr->compute_deidrj(fij); + + f[j][0] -= fij[0]; + f[j][1] -= fij[1]; + f[j][2] -= fij[2]; + + // tally per-atom virial contribution + + if (vflag) + ev_tally_xyz(-1,j,atom->nlocal,force->newton_pair,0.0,0.0, + fij[0],fij[1],fij[2], + -snaptr->rij[jj][0],-snaptr->rij[jj][1], + -snaptr->rij[jj][2]); + } + + // tally energy contribution + + if (eflag) { + + // get descriptors again + + snaptr->compute_zi(); + snaptr->compute_bi(ielem); + + // evdwl = energy of atom I, sum over coeffs_k * Bi_k + + double evdwl = 0.0; + + // E = beta.B + + for (int icoeff = 0; icoeff < ncoeff; icoeff++) + evdwl += beta[igrid][icoeff]*snaptr->blist[icoeff]; + + ev_tally_full(-1,2.0*evdwl,0.0,0.0,0.0,0.0,0.0); + + } + igrid++; + } + if (vflag_fdotr) virial_fdotr_compute(); + } diff --git a/src/compute_grid_local.h b/src/compute_grid_local.h index 6189e5b27d..b3d2f4cd94 100644 --- a/src/compute_grid_local.h +++ b/src/compute_grid_local.h @@ -34,7 +34,7 @@ class ComputeGridLocal : public Compute { int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive int ngridlocal; // number of local grid points int nvalues; // number of values per grid point - double ****gridlocal; // local grid + double ****gridlocal; // local grid, redundant w.r.t. alocal double **alocal; // pointer to Compute::array_local int triclinic; // triclinic flag double *boxlo, *prd; // box info (units real/ortho or reduced/tri) diff --git a/src/pair_grid.cpp b/src/pair_grid.cpp index 3f88635ecf..1f17553055 100644 --- a/src/pair_grid.cpp +++ b/src/pair_grid.cpp @@ -23,12 +23,14 @@ #include "error.h" #include "comm.h" +#define BETA_CONST 1.0e-2 + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ PairGrid::PairGrid(LAMMPS *lmp) : - Pair(lmp), gridlocal(nullptr), alocal(nullptr) + Pair(lmp), gridlocal(nullptr), alocal(nullptr), beta(nullptr) { single_enable = 0; restartinfo = 0; @@ -50,9 +52,6 @@ PairGrid::PairGrid(LAMMPS *lmp) : PairGrid::~PairGrid() { if (copymode) return; - - memory->destroy(beta); - deallocate_grid(); } @@ -91,6 +90,7 @@ void PairGrid::allocate_grid() memory->create4d_offset(gridlocal,ndesc,nzlo,nzhi,nylo,nyhi, nxlo,nxhi,"pair/grid:gridlocal"); memory->create(alocal, ngridlocal, ndesc, "pair/grid:alocal"); + memory->create(beta, ngridlocal, ndesc-ndesc_base, "pair/grid:beta"); } } @@ -104,6 +104,7 @@ void PairGrid::deallocate_grid() gridlocal_allocated = 0; memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); memory->destroy(alocal); + memory->destroy(beta); } } @@ -234,17 +235,21 @@ void PairGrid::copy_gridlocal_to_local_array() } /* ---------------------------------------------------------------------- - get beta from someplace + calculate beta ------------------------------------------------------------------------- */ + // this is a proxy for a call to the energy model + // beta is dE/dB^i, the derivative of the total + // energy w.r.t. to descriptors of grid point i + void PairGrid::compute_beta() { int igrid = 0; for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { - for (int icol = ndesc_base; icol < ndesc; icol++) - beta[igrid][icol] = 1.0; + for (int icol = 0; icol < ndesc-ndesc_base; icol++) + beta[igrid][icol] = BETA_CONST; igrid++; } } diff --git a/src/pair_grid.h b/src/pair_grid.h index 97799a5c30..b5bf7ad9ef 100644 --- a/src/pair_grid.h +++ b/src/pair_grid.h @@ -44,7 +44,7 @@ class PairGrid : public Pair { int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive int ngridlocal; // number of local grid points int nvalues; // number of values per grid point - double ****gridlocal; // local grid + double ****gridlocal; // local grid, redundant w.r.t. alocal double **alocal; // pointer to Compute::array_local int triclinic; // triclinic flag double *boxlo, *prd; // box info (units real/ortho or reduced/tri) From 19d469222a6450d0bf8f90358f50a248ff6a6ee7 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 23 Dec 2021 16:28:25 -0700 Subject: [PATCH 42/91] Added test for energy conservation --- examples/snap/econs.py | 16 ++++++++++++++++ examples/snap/in.grid.pair | 27 +++++++++++++++++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 examples/snap/econs.py diff --git a/examples/snap/econs.py b/examples/snap/econs.py new file mode 100644 index 0000000000..2e7167daca --- /dev/null +++ b/examples/snap/econs.py @@ -0,0 +1,16 @@ +import lammps + +infile = "in.grid.pair" +faclist = [0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5] + +print("# Timestep DeltaE DeltaE/Timestep^2") +for fac in faclist: + cmdlist = ["-screen","none","-var","dtfac", "%g" % fac] + lmp = lammps.lammps(cmdargs = cmdlist) + lmp.file(infile) + dt = lmp.extract_global("dt", lammps.LAMMPS_DOUBLE) + de = lmp.extract_fix("avede", lammps.LMP_STYLE_GLOBAL, lammps.LMP_TYPE_SCALAR) + dedt2 = de/dt**2 + print(f"{dt} {de} {dedt2}") + + diff --git a/examples/snap/in.grid.pair b/examples/snap/in.grid.pair index 99c9623f7d..e4cf3e3298 100644 --- a/examples/snap/in.grid.pair +++ b/examples/snap/in.grid.pair @@ -1,10 +1,16 @@ # Demonstrate pair style base on sna/grid +# Test energy conservation +# Choose dtfac in the range [0.01,Infinity] +# Large dtfac means small timestep, while +# keeping trajectory output interval fixed +# Variable etotdelta measures change in (PE+KE)/natoms # Initialize simulation -variable dt index 0.5e-5 -variable nthermo index 100 -variable nsteps index 10000 +variable dtfac index 1 +variable dt equal 0.5e-3/${dtfac} +variable nthermo equal 1000*${dtfac} +variable nsteps equal 1000*${dtfac} variable nrep index 3 variable a index 3.0 variable ngrid index 2 @@ -35,8 +41,9 @@ lattice custom $a & region box block 0 ${nx} 0 ${ny} 0 ${nz} create_box 1 box create_atoms 1 box -displace_atoms all random ${del} ${del} ${del} 12345 mass 1 180.88 +displace_atoms all random ${del} ${del} ${del} 12345 +velocity all create $t 4928459 loop geom write_dump all custom test.dump id type x y z @@ -59,7 +66,16 @@ pair_style sna/grid grid ${ngrid} ${ngrid} ${ngrid} & quadraticflag ${quad} switchflag ${switch} pair_coeff * * Al -thermo_style custom step temp epair emol etotal press +thermo ${nthermo} +thermo_modify norm yes + +run 0 + +variable etot0 equal etotal +variable etotdelta equal abs(etotal-${etot0})/atoms +fix avede all ave/time 1 ${nthermo} ${nthermo} v_etotdelta + +thermo_style custom step temp epair ke etotal press v_etotdelta f_avede thermo ${nthermo} thermo_modify norm yes @@ -71,6 +87,5 @@ neigh_modify once no every 1 delay 0 check yes # Run MD -velocity all create $t 4928459 loop geom fix 1 all nve run ${nsteps} From 6de9c09730d9b0e9569d44be0f863fd2cdeb397b Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 23 Dec 2021 16:35:30 -0700 Subject: [PATCH 43/91] Tweaked econs.py --- examples/snap/econs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/snap/econs.py b/examples/snap/econs.py index 2e7167daca..aece097622 100644 --- a/examples/snap/econs.py +++ b/examples/snap/econs.py @@ -1,7 +1,7 @@ import lammps infile = "in.grid.pair" -faclist = [0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5] +faclist = [0.001,0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5] print("# Timestep DeltaE DeltaE/Timestep^2") for fac in faclist: From 567c5c733465f891e39e333b877e368f12596b3d Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 23 Dec 2021 16:37:23 -0700 Subject: [PATCH 44/91] Fixed sign error that now gives wonderful energy conservation --- src/ML-SNAP/pair_sna_grid.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp index c84dcaf467..43a07b48e4 100644 --- a/src/ML-SNAP/pair_sna_grid.cpp +++ b/src/ML-SNAP/pair_sna_grid.cpp @@ -252,9 +252,9 @@ void PairSNAGrid::compute(int eflag, int vflag) snaptr->compute_deidrj(fij); - f[j][0] -= fij[0]; - f[j][1] -= fij[1]; - f[j][2] -= fij[2]; + f[j][0] += fij[0]; + f[j][1] += fij[1]; + f[j][2] += fij[2]; // tally per-atom virial contribution From 57aedc500ee7a99fe290f53b3103286427288886 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 23 Dec 2021 17:40:29 -0700 Subject: [PATCH 45/91] Added a numerical force test, not automated --- examples/snap/in.fnum | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 examples/snap/in.fnum diff --git a/examples/snap/in.fnum b/examples/snap/in.fnum new file mode 100644 index 0000000000..addb9827d0 --- /dev/null +++ b/examples/snap/in.fnum @@ -0,0 +1,63 @@ +# Demonstrate pair style base on sna/grid +# Check numerical forces + +variable nrep index 3 +variable a index 3.0 +variable ngrid index 2 +variable del index 0.1 +variable fdelta index 0.0001 + +units metal + +atom_modify map yes + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice custom $a & + a1 1 0 0 & + a2 0 1 0 & + a3 0 0 1 & + basis 0 0 0 & + basis 0.5 0.5 0.5 & +# origin 0.25 0.25 0.25 +# origin 0.25e-3 0.25e-3 0.25e-3 + +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box +mass 1 180.88 +displace_atoms all random ${del} ${del} ${del} 12345 + +# define grid compute and atom compute + +group snapgroup type 1 +variable twojmax equal 2 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quad equal 0 +variable switch equal 1 + +pair_style sna/grid grid ${ngrid} ${ngrid} ${ngrid} & + ${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & + quadraticflag ${quad} switchflag ${switch} +pair_coeff * * Al + +fix fnum all numdiff 1 ${fdelta} +variable fz1 equal fz[1] +variable fnumz1 equal f_fnum[1][3] +variable ferrz1 equal f_fnum[1][3]-fz[1] +thermo_style custom v_fz1 v_fnumz1 v_ferrz1 +thermo_modify norm yes + +run 0 From 4a7f726395ff720145219a6a0a09d4e5fc6e6ec8 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 23 Dec 2021 17:40:59 -0700 Subject: [PATCH 46/91] Minor tweak --- examples/snap/in.grid.pair | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/snap/in.grid.pair b/examples/snap/in.grid.pair index e4cf3e3298..128da2ad7a 100644 --- a/examples/snap/in.grid.pair +++ b/examples/snap/in.grid.pair @@ -70,7 +70,6 @@ thermo ${nthermo} thermo_modify norm yes run 0 - variable etot0 equal etotal variable etotdelta equal abs(etotal-${etot0})/atoms fix avede all ave/time 1 ${nthermo} ${nthermo} v_etotdelta @@ -87,5 +86,5 @@ neigh_modify once no every 1 delay 0 check yes # Run MD -fix 1 all nve +fix mynve all nve run ${nsteps} From ad307fb7849e408edad0b5aa8bef7614386e683f Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 30 Dec 2021 11:43:32 -0700 Subject: [PATCH 47/91] Added script for RMSE on numerical forces --- examples/snap/fnum.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/snap/fnum.py diff --git a/examples/snap/fnum.py b/examples/snap/fnum.py new file mode 100644 index 0000000000..bde45b042c --- /dev/null +++ b/examples/snap/fnum.py @@ -0,0 +1,24 @@ +import lammps + +def sqerr(a,b): + return (a[0]-b[0])**2+(a[1]-b[1])**2+(a[2]-b[2])**2 + +infile = "in.fnum" + +fdeltalist = [1.0e-2,1.0e-3,1.0e-4,1.0e-5,1.0e-6,1.0e-7,1.0e-8,1.0e-9,1.0e-10] + +print("Fdelta RMSE") +for fdelta in fdeltalist: + cmdlist = ["-screen","none","-var","fdelta",f'{fdelta}'] + lmp = lammps.lammps(cmdargs = cmdlist) + lmp.file(infile) + natoms = lmp.get_natoms() + + f = lmp.extract_atom("f") + fnum = lmp.extract_fix("fnum", lammps.LMP_STYLE_ATOM, lammps.LMP_TYPE_ARRAY) + + sumsq = 0 + for i in range(natoms): + sumsq += sqerr(fnum[i],f[i]) + rmse = (sumsq/natoms)**0.5 + print(f"{fdelta} {rmse}") From 0e8287730271cd3256832ab9249d6fa40ac1da43 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 30 Dec 2021 11:51:16 -0700 Subject: [PATCH 48/91] Tweak --- examples/snap/fnum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/snap/fnum.py b/examples/snap/fnum.py index bde45b042c..9f496861cc 100644 --- a/examples/snap/fnum.py +++ b/examples/snap/fnum.py @@ -18,7 +18,7 @@ for fdelta in fdeltalist: fnum = lmp.extract_fix("fnum", lammps.LMP_STYLE_ATOM, lammps.LMP_TYPE_ARRAY) sumsq = 0 - for i in range(natoms): + for i in range(nlocal): sumsq += sqerr(fnum[i],f[i]) rmse = (sumsq/natoms)**0.5 print(f"{fdelta} {rmse}") From 499bae77bdc3f0ad2521f76a6832c72e55f6b526 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 30 Dec 2021 12:02:53 -0700 Subject: [PATCH 49/91] Tweak --- examples/snap/fnum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/snap/fnum.py b/examples/snap/fnum.py index 9f496861cc..83bdbba503 100644 --- a/examples/snap/fnum.py +++ b/examples/snap/fnum.py @@ -12,7 +12,7 @@ for fdelta in fdeltalist: cmdlist = ["-screen","none","-var","fdelta",f'{fdelta}'] lmp = lammps.lammps(cmdargs = cmdlist) lmp.file(infile) - natoms = lmp.get_natoms() + nlocal = lmp.extract_global("nlocal") f = lmp.extract_atom("f") fnum = lmp.extract_fix("fnum", lammps.LMP_STYLE_ATOM, lammps.LMP_TYPE_ARRAY) @@ -20,5 +20,5 @@ for fdelta in fdeltalist: sumsq = 0 for i in range(nlocal): sumsq += sqerr(fnum[i],f[i]) - rmse = (sumsq/natoms)**0.5 + rmse = (sumsq/nlocal)**0.5 print(f"{fdelta} {rmse}") From 82b7b2f3ea641daaff87dd2659dc881bbcc585ef Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Tue, 4 Jan 2022 14:02:29 -0700 Subject: [PATCH 50/91] Simplified access of force errors --- examples/snap/fnum.py | 14 ++------------ examples/snap/in.fnum | 8 +++----- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/examples/snap/fnum.py b/examples/snap/fnum.py index 83bdbba503..1e50e49b09 100644 --- a/examples/snap/fnum.py +++ b/examples/snap/fnum.py @@ -1,8 +1,5 @@ import lammps -def sqerr(a,b): - return (a[0]-b[0])**2+(a[1]-b[1])**2+(a[2]-b[2])**2 - infile = "in.fnum" fdeltalist = [1.0e-2,1.0e-3,1.0e-4,1.0e-5,1.0e-6,1.0e-7,1.0e-8,1.0e-9,1.0e-10] @@ -12,13 +9,6 @@ for fdelta in fdeltalist: cmdlist = ["-screen","none","-var","fdelta",f'{fdelta}'] lmp = lammps.lammps(cmdargs = cmdlist) lmp.file(infile) - nlocal = lmp.extract_global("nlocal") - - f = lmp.extract_atom("f") - fnum = lmp.extract_fix("fnum", lammps.LMP_STYLE_ATOM, lammps.LMP_TYPE_ARRAY) - - sumsq = 0 - for i in range(nlocal): - sumsq += sqerr(fnum[i],f[i]) - rmse = (sumsq/nlocal)**0.5 + faverrsq = lmp.extract_compute("faverrsq", lammps.LMP_STYLE_GLOBAL, lammps.LMP_TYPE_SCALAR) + rmse = faverrsq**0.5 print(f"{fdelta} {rmse}") diff --git a/examples/snap/in.fnum b/examples/snap/in.fnum index addb9827d0..1298e9aed9 100644 --- a/examples/snap/in.fnum +++ b/examples/snap/in.fnum @@ -54,10 +54,8 @@ pair_style sna/grid grid ${ngrid} ${ngrid} ${ngrid} & pair_coeff * * Al fix fnum all numdiff 1 ${fdelta} -variable fz1 equal fz[1] -variable fnumz1 equal f_fnum[1][3] -variable ferrz1 equal f_fnum[1][3]-fz[1] -thermo_style custom v_fz1 v_fnumz1 v_ferrz1 -thermo_modify norm yes +variable ferrsq atom (fx-f_fnum[1])^2+(fy-f_fnum[2])^2+(fz-f_fnum[3])^2 +compute faverrsq all reduce ave v_ferrsq +thermo_style custom c_faverrsq run 0 From 6ef7d19fc0a8a6180dd0c9ea3d4399c7d8143a0c Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 8 Apr 2022 15:05:17 -0600 Subject: [PATCH 51/91] Added a test for bgrid/local --- examples/snap/grid.local.py | 119 +++++++++++++++++++++++++++++ examples/snap/in.grid.python.local | 69 +++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100755 examples/snap/grid.local.py create mode 100644 examples/snap/in.grid.python.local diff --git a/examples/snap/grid.local.py b/examples/snap/grid.local.py new file mode 100755 index 0000000000..8b8cb99d66 --- /dev/null +++ b/examples/snap/grid.local.py @@ -0,0 +1,119 @@ +#!/Users/athomps/miniconda3/bin/python3.7 +# +# An example of SNAP grid from LAMMPS Python interface +# +# https://lammps.sandia.gov/doc/Python_library.html + + +from lammps import lammps, LMP_STYLE_LOCAL, LMP_SIZE_ROWS, LMP_SIZE_COLS, LMP_TYPE_ARRAY +import lammps_utils + +from mpi4py import MPI +comm = MPI.COMM_WORLD +me = comm.Get_rank() +nprocs = comm.Get_size() + +# define command line input variables + +ngridx = 2 +ngridy = 3 +ngridz = nprocs +twojmax = 2 + +lmp_cmdargs = ["-echo","screen"] +lmp_cmdargs = lammps_utils.set_cmdlinevars(lmp_cmdargs, + { + "ngridx":ngridx, + "ngridy":ngridy, + "ngridz":ngridz, + "twojmax":twojmax + } + ) + +# launch LAMMPS instance + +lmp = lammps(cmdargs=lmp_cmdargs) + +# run LAMMPS input script + +lmp.file("in.grid.python.local") + +# get quantities from LAMMPS + +num_atoms = lmp.get_natoms() + +# set things not accessible from LAMMPS + +# first 3 cols are x, y, z, coords + +ncols0 = 3 + +# analytical relation + +ncoeff = (twojmax+2)*(twojmax+3)*(twojmax+4) +ncoeff = ncoeff // 24 # integer division +ncols = ncols0+ncoeff + +# get B_0 at position (0,0,0) in 4 different ways + +# 1. from comute sna/atom + +bptr = lmp.extract_compute("b", 1, 2) # 1 = per-atom data, 2 = array +print("b = ",bptr[0][0]) + +# 2. from compute sna/grid + +bgridptr = lmp.extract_compute("bgrid", 0, 2) # 0 = style global, 2 = type array +print("bgrid = ",bgridptr[0][3]) + +# 3. from Numpy array pointing to sna/atom array + +bptr_np = lammps_utils.extract_compute_np(lmp,"b",1,2,(num_atoms,ncoeff)) +print("b_np = ",bptr_np[0][0]) + +# 4. from Numpy array pointing to sna/grid array + +bgridptr_np = lammps_utils.extract_compute_np(lmp,"bgrid",0,2,(ngridz,ngridy,ngridx,ncols)) +print("bgrid_np = ",bgridptr_np[0][0][0][ncols0+0]) + +# 5. from sna/grid/local array + +bgridlocalnrows = lmp.extract_compute("bgridlocal", LMP_STYLE_LOCAL, LMP_SIZE_ROWS) +print("bgridlocal nrows = ",bgridlocalnrows) +bgridlocalncols = lmp.extract_compute("bgridlocal", LMP_STYLE_LOCAL, LMP_SIZE_COLS) +print("bgridlocal ncols = ",bgridlocalncols) +bgridlocalptr = lmp.extract_compute("bgridlocal", LMP_STYLE_LOCAL, LMP_TYPE_ARRAY) +print("bgridlocal = ",bgridlocalptr) +print("bgridlocal[0][0] = ",bgridlocalptr[5][10]) + +# print out the LAMMPS array to a file + +outfile = open("bgrid.dat",'w') +igrid = 0 +for iz in range(ngridz): + for iy in range(ngridy): + for ix in range(ngridx): + outfile.write("x, y, z = %g %g %g\n" % + (bgridptr[igrid][0], + bgridptr[igrid][1], + bgridptr[igrid][2])) + for icoeff in range(ncoeff): + outfile.write("%g " % bgridptr[igrid][ncols0+icoeff]) + outfile.write("\n") + igrid += 1 +outfile.close() + +# print out the Numpy array to a file + +outfile = open("bgrid_np.dat",'w') +for iz in range(ngridz): + for iy in range(ngridy): + for ix in range(ngridx): + outfile.write("x, y, z = %g %g %g\n" % + (bgridptr_np[iz][iy][ix][0], + bgridptr_np[iz][iy][ix][1], + bgridptr_np[iz][iy][ix][2])) + for icoeff in range(ncoeff): + outfile.write("%g " % bgridptr_np[iz][iy][ix][ncols0+icoeff]) + outfile.write("\n") +outfile.close() diff --git a/examples/snap/in.grid.python.local b/examples/snap/in.grid.python.local new file mode 100644 index 0000000000..af95696a2b --- /dev/null +++ b/examples/snap/in.grid.python.local @@ -0,0 +1,69 @@ +# Demonstrate bispectrum per-atom and grid computes + +# Invoked from grid.py +# pass in values for ngridx, ngridy, ngridz, twojmax + +# Initialize simulation + +variable nsteps equal 0 +variable nrep equal 1 +variable a equal 3.316 + +units metal + +# make processor grid equal to nz + +processors 1 1 ${ngridz} + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice custom ${a} a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 + +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 180.88 + +# define grid compute and atom compute + +group snapgroup type 1 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quad equal 0 +variable switch equal 1 + +compute b all sna/atom ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} + +compute bgrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} + +compute bgridlocal all sna/grid/local grid ${ngridx} ${ngridy} ${ngridz} ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} + +# create dummy potential for neighbor list + +variable rcutneigh equal 2.0*${rcutfac}*${radelem} +pair_style zero ${rcutneigh} +pair_coeff * * + +# define output + +thermo_style custom step temp ke pe vol c_bgrid[1][1] +thermo_modify norm yes + +dump mydump_b all custom 1000 dump_b id c_b[*] + +dump mydump_bgridlocal all local 1000 dump_bgridlocal index c_bgridlocal[*] + +# run + +run 0 From da6fb4c5443d72e790484e63a23e3e9b4e272860 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 8 Apr 2022 15:47:12 -0600 Subject: [PATCH 52/91] Added epsilon shift to eliminate uneven tiebreaks --- src/compute_grid_local.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index 1b8de3c48a..e99a742c3b 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -191,6 +191,19 @@ void ComputeGridLocal::set_grid_local() zfrachi = comm->mysplit[2][1]; } + // not fully clear why this works + // without, sometimes get uneven assignments + // in case where ngridz is multiple of nprocz + + double MYEPS = 1.0e-10; + + xfraclo += MYEPS; + xfrachi += MYEPS; + yfraclo += MYEPS; + yfrachi += MYEPS; + zfraclo += MYEPS; + zfrachi += MYEPS; + nxlo = static_cast (xfraclo * nx); if (1.0*nxlo != xfraclo*nx) nxlo++; nxhi = static_cast (xfrachi * nx); From 429163d2b29608892c67d69852802e062de3dc0f Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Mon, 11 Apr 2022 14:47:14 -0600 Subject: [PATCH 53/91] Added check for grid points outside subdomain --- src/compute_grid_local.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index e99a742c3b..d751a517cb 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -238,6 +238,14 @@ void ComputeGridLocal::assign_coords() alocal[igrid][2] = iz; double xgrid[3]; grid2x(ix, iy, iz, xgrid); + + // ensure gridpoint is not strictly outside subdomain + + if (xgrid[0] < sublo[0] && xgrid[0] > subhi[0] && + xgrid[1] < sublo[1] && xgrid[1] > subhi[1] && + xgrid[2] < sublo[2] && xgrid[2] > subhi[2]) + error->all(FLERR,"Invalid gridpoint position in compute grid/local"); + alocal[igrid][3] = xgrid[0]; alocal[igrid][4] = xgrid[1]; alocal[igrid][5] = xgrid[2]; From bae9ef7e565e2616cef8901fc0dc923f210f4754 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Mon, 11 Apr 2022 14:51:15 -0600 Subject: [PATCH 54/91] Added check for grid points outside subdomain --- src/compute_grid_local.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index d751a517cb..33e2bc9c49 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -244,7 +244,7 @@ void ComputeGridLocal::assign_coords() if (xgrid[0] < sublo[0] && xgrid[0] > subhi[0] && xgrid[1] < sublo[1] && xgrid[1] > subhi[1] && xgrid[2] < sublo[2] && xgrid[2] > subhi[2]) - error->all(FLERR,"Invalid gridpoint position in compute grid/local"); + error->one(FLERR,"Invalid gridpoint position in compute grid/local"); alocal[igrid][3] = xgrid[0]; alocal[igrid][4] = xgrid[1]; From c939316b99b9e06ac10d14455665ee85b4712ff4 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Mon, 11 Apr 2022 14:52:35 -0600 Subject: [PATCH 55/91] Added check for grid points outside subdomain --- src/compute_grid_local.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index 33e2bc9c49..299e42d81d 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -241,9 +241,9 @@ void ComputeGridLocal::assign_coords() // ensure gridpoint is not strictly outside subdomain - if (xgrid[0] < sublo[0] && xgrid[0] > subhi[0] && - xgrid[1] < sublo[1] && xgrid[1] > subhi[1] && - xgrid[2] < sublo[2] && xgrid[2] > subhi[2]) + if (xgrid[0] < sublo[0] || xgrid[0] > subhi[0] || + xgrid[1] < sublo[1] || xgrid[1] > subhi[1] || + xgrid[2] < sublo[2] || xgrid[2] > subhi[2]) error->one(FLERR,"Invalid gridpoint position in compute grid/local"); alocal[igrid][3] = xgrid[0]; From ab73faee095419dbf80733bd64745880c0bab53a Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Tue, 19 Apr 2022 11:33:59 -0600 Subject: [PATCH 56/91] Removed EPS trick that was causing some unexpected reordering --- src/compute_grid_local.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index 299e42d81d..ec385f6a13 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -191,18 +191,18 @@ void ComputeGridLocal::set_grid_local() zfrachi = comm->mysplit[2][1]; } - // not fully clear why this works - // without, sometimes get uneven assignments - // in case where ngridz is multiple of nprocz + // // not fully clear why this works + // // without, sometimes get uneven assignments + // // in case where ngridz is multiple of nprocz - double MYEPS = 1.0e-10; + // double MYEPS = 1.0e-10; - xfraclo += MYEPS; - xfrachi += MYEPS; - yfraclo += MYEPS; - yfrachi += MYEPS; - zfraclo += MYEPS; - zfrachi += MYEPS; + // xfraclo += MYEPS; + // xfrachi += MYEPS; + // yfraclo += MYEPS; + // yfrachi += MYEPS; + // zfraclo += MYEPS; + // zfrachi += MYEPS; nxlo = static_cast (xfraclo * nx); if (1.0*nxlo != xfraclo*nx) nxlo++; From 4c5782018897874fe3c11ac50757d505d7239885 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Tue, 19 Apr 2022 11:48:16 -0600 Subject: [PATCH 57/91] Applied the Modine transpose to x,y,z --- src/compute_grid_local.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index ec385f6a13..0d8738e230 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -230,9 +230,9 @@ void ComputeGridLocal::set_grid_local() void ComputeGridLocal::assign_coords() { int igrid = 0; - for (int iz = nzlo; iz <= nzhi; iz++) + for (int ix = nxlo; ix <= nxhi; ix++) for (int iy = nylo; iy <= nyhi; iy++) - for (int ix = nxlo; ix <= nxhi; ix++) { + for (int iz = nzlo; iz <= nzhi; iz++) { alocal[igrid][0] = ix; alocal[igrid][1] = iy; alocal[igrid][2] = iz; @@ -260,9 +260,9 @@ void ComputeGridLocal::assign_coords() void ComputeGridLocal::copy_gridlocal_to_local_array() { int igrid = 0; - for (int iz = nzlo; iz <= nzhi; iz++) + for (int ix = nxlo; ix <= nxhi; ix++) for (int iy = nylo; iy <= nyhi; iy++) - for (int ix = nxlo; ix <= nxhi; ix++) { + for (int iz = nzlo; iz <= nzhi; iz++) { for (int icol = size_local_cols_base; icol < size_local_cols; icol++) alocal[igrid][icol] = gridlocal[icol][iz][iy][ix]; igrid++; From 78aec491ff871ca2135b3861cd34f40b80ab89ca Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 22 Apr 2022 17:32:26 -0600 Subject: [PATCH 58/91] Minor tweaks --- examples/snap/grid.local.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/snap/grid.local.py b/examples/snap/grid.local.py index 8b8cb99d66..414558b79b 100755 --- a/examples/snap/grid.local.py +++ b/examples/snap/grid.local.py @@ -82,9 +82,11 @@ bgridlocalnrows = lmp.extract_compute("bgridlocal", LMP_STYLE_LOCAL, LMP_SIZE_RO print("bgridlocal nrows = ",bgridlocalnrows) bgridlocalncols = lmp.extract_compute("bgridlocal", LMP_STYLE_LOCAL, LMP_SIZE_COLS) print("bgridlocal ncols = ",bgridlocalncols) -bgridlocalptr = lmp.extract_compute("bgridlocal", LMP_STYLE_LOCAL, LMP_TYPE_ARRAY) -print("bgridlocal = ",bgridlocalptr) -print("bgridlocal[0][0] = ",bgridlocalptr[5][10]) + +if bgridlocalnrows > 0: + bgridlocalptr = lmp.extract_compute("bgridlocal", LMP_STYLE_LOCAL, LMP_TYPE_ARRAY) + print("bgridlocal = ",bgridlocalptr) + print("bgridlocal[0][0] = ",bgridlocalptr[5][10]) # print out the LAMMPS array to a file From 872e4de6ab9c91cd8e1001457cc39f558e38e53e Mon Sep 17 00:00:00 2001 From: Lenz Fiedler Date: Thu, 19 May 2022 23:21:15 +0200 Subject: [PATCH 59/91] Rolled back the Modine transpose --- src/compute_grid_local.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index 0d8738e230..ec385f6a13 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -230,9 +230,9 @@ void ComputeGridLocal::set_grid_local() void ComputeGridLocal::assign_coords() { int igrid = 0; - for (int ix = nxlo; ix <= nxhi; ix++) + for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) - for (int iz = nzlo; iz <= nzhi; iz++) { + for (int ix = nxlo; ix <= nxhi; ix++) { alocal[igrid][0] = ix; alocal[igrid][1] = iy; alocal[igrid][2] = iz; @@ -260,9 +260,9 @@ void ComputeGridLocal::assign_coords() void ComputeGridLocal::copy_gridlocal_to_local_array() { int igrid = 0; - for (int ix = nxlo; ix <= nxhi; ix++) + for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) - for (int iz = nzlo; iz <= nzhi; iz++) { + for (int ix = nxlo; ix <= nxhi; ix++) { for (int icol = size_local_cols_base; icol < size_local_cols; icol++) alocal[igrid][icol] = gridlocal[icol][iz][iy][ix]; igrid++; From 2b001f9505aff2fe538d78c42720960025b412df Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 20 May 2022 13:21:55 -0600 Subject: [PATCH 60/91] Fix subdomain check for triclinic --- src/compute_grid_local.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index ec385f6a13..66eb0c5db3 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -81,6 +81,7 @@ void ComputeGridLocal::setup() /* ---------------------------------------------------------------------- convert global array indexes to box coords + for triclinic, these will be lamda coords ------------------------------------------------------------------------- */ void ComputeGridLocal::grid2x(int ix, int iy, int iz, double *x) @@ -88,8 +89,6 @@ void ComputeGridLocal::grid2x(int ix, int iy, int iz, double *x) x[0] = ix*delx; x[1] = iy*dely; x[2] = iz*delz; - - if (triclinic) domain->lamda2x(x, x); } /* ---------------------------------------------------------------------- @@ -245,6 +244,10 @@ void ComputeGridLocal::assign_coords() xgrid[1] < sublo[1] || xgrid[1] > subhi[1] || xgrid[2] < sublo[2] || xgrid[2] > subhi[2]) error->one(FLERR,"Invalid gridpoint position in compute grid/local"); + + // convert lamda to x, y, z, after sudomain check + + if (triclinic) domain->lamda2x(xgrid, xgrid); alocal[igrid][3] = xgrid[0]; alocal[igrid][4] = xgrid[1]; From 59e010343016b9eafcaf75d3f279fd2b34b9fbc5 Mon Sep 17 00:00:00 2001 From: Lenz Fiedler Date: Tue, 24 May 2022 17:00:41 +0200 Subject: [PATCH 61/91] Added EPSILON to subdomain check --- src/compute_grid_local.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index 66eb0c5db3..a6f3cf29ad 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -23,6 +23,10 @@ #include "error.h" #include "comm.h" +// For the subdomain test below; grid-points and subdomain boundaries +// sometimes differ by minimal amounts (in the order of 2e-17). +#define EPSILON 1.0e-10 + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -239,11 +243,15 @@ void ComputeGridLocal::assign_coords() grid2x(ix, iy, iz, xgrid); // ensure gridpoint is not strictly outside subdomain - - if (xgrid[0] < sublo[0] || xgrid[0] > subhi[0] || - xgrid[1] < sublo[1] || xgrid[1] > subhi[1] || - xgrid[2] < sublo[2] || xgrid[2] > subhi[2]) - error->one(FLERR,"Invalid gridpoint position in compute grid/local"); + // There have been some problem with a gridpoint being something like 2e-17 outside of the subdomain, + // thus the EPISLON check. + if ((sublo[0]-xgrid[0]) > EPSILON || (xgrid[0]-subhi[0]) > EPSILON || + (sublo[1]-xgrid[1]) > EPSILON || (xgrid[1]-subhi[1]) > EPSILON || + (sublo[2]-xgrid[2]) > EPSILON || (xgrid[2]-subhi[2]) > EPSILON) + { + error->one(FLERR,"Invalid gridpoint position in compute grid/local"); + } + // convert lamda to x, y, z, after sudomain check From 0a8b4c514265c478d219876b75cc90ade4ea3677 Mon Sep 17 00:00:00 2001 From: Lenz Fiedler Date: Wed, 25 May 2022 15:27:27 +0200 Subject: [PATCH 62/91] Hotfix for triclinic calculations --- src/compute_grid_local.cpp | 36 ++++++++++++++++++++++++++++++------ src/compute_grid_local.h | 1 + 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index a6f3cf29ad..504555a718 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -85,7 +85,6 @@ void ComputeGridLocal::setup() /* ---------------------------------------------------------------------- convert global array indexes to box coords - for triclinic, these will be lamda coords ------------------------------------------------------------------------- */ void ComputeGridLocal::grid2x(int ix, int iy, int iz, double *x) @@ -93,8 +92,23 @@ void ComputeGridLocal::grid2x(int ix, int iy, int iz, double *x) x[0] = ix*delx; x[1] = iy*dely; x[2] = iz*delz; + + if (triclinic) domain->lamda2x(x, x); } +/* ---------------------------------------------------------------------- + convert global array indexes to lamda coords; for orthorombic + cells defaults to grid2x. +------------------------------------------------------------------------- */ + +void ComputeGridLocal::grid2lamda(int ix, int iy, int iz, double *x) +{ + x[0] = ix*delx; + x[1] = iy*dely; + x[2] = iz*delz; +} + + /* ---------------------------------------------------------------------- create arrays ------------------------------------------------------------------------- */ @@ -240,9 +254,20 @@ void ComputeGridLocal::assign_coords() alocal[igrid][1] = iy; alocal[igrid][2] = iz; double xgrid[3]; - grid2x(ix, iy, iz, xgrid); - // ensure gridpoint is not strictly outside subdomain + // For triclinic: create gridpoint in lamda coordinates and transform after check. + // For orthorombic: create gridpoint in box coordinates. + + if (triclinic) + { + grid2lamda(ix, iy, iz, xgrid); + } + else + { + grid2x(ix, iy, iz, xgrid); + } + + // Ensure gridpoint is not strictly outside subdomain. // There have been some problem with a gridpoint being something like 2e-17 outside of the subdomain, // thus the EPISLON check. if ((sublo[0]-xgrid[0]) > EPSILON || (xgrid[0]-subhi[0]) > EPSILON || @@ -252,11 +277,10 @@ void ComputeGridLocal::assign_coords() error->one(FLERR,"Invalid gridpoint position in compute grid/local"); } - // convert lamda to x, y, z, after sudomain check - + if (triclinic) domain->lamda2x(xgrid, xgrid); - + alocal[igrid][3] = xgrid[0]; alocal[igrid][4] = xgrid[1]; alocal[igrid][5] = xgrid[2]; diff --git a/src/compute_grid_local.h b/src/compute_grid_local.h index b3d2f4cd94..79a5ea765d 100644 --- a/src/compute_grid_local.h +++ b/src/compute_grid_local.h @@ -49,6 +49,7 @@ class ComputeGridLocal : public Compute { void allocate(); // create arrays void deallocate(); // free arrays void grid2x(int, int, int, double*); // convert global indices to coordinates + void grid2lamda(int, int, int, double*); // convert global indices to lamda coordinates void set_grid_global(); // set global grid void set_grid_local(); // set bounds for local grid void assign_coords(); // assign coords for grid From 9ca91bfe8010ce28167d7cc5e3f350bcb9e4fe8f Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 15 Jun 2022 18:14:27 -0600 Subject: [PATCH 63/91] Created two simple examples of compute sna/grid and sna/grid/local --- examples/snap/README.grid | 10 ++ examples/snap/in.grid.snap | 94 ++++++++++ examples/snap/in.grid.tri | 143 +++++++--------- examples/snap/log.15Jun22.grid.snap.g++.1 | 167 ++++++++++++++++++ examples/snap/log.15Jun22.grid.snap.g++.4 | 168 ++++++++++++++++++ examples/snap/log.15Jun22.grid.tri.g++.1 | 200 ++++++++++++++++++++++ examples/snap/log.15Jun22.grid.tri.g++.4 | 200 ++++++++++++++++++++++ 7 files changed, 900 insertions(+), 82 deletions(-) create mode 100644 examples/snap/in.grid.snap create mode 100644 examples/snap/log.15Jun22.grid.snap.g++.1 create mode 100644 examples/snap/log.15Jun22.grid.snap.g++.4 create mode 100644 examples/snap/log.15Jun22.grid.tri.g++.1 create mode 100644 examples/snap/log.15Jun22.grid.tri.g++.4 diff --git a/examples/snap/README.grid b/examples/snap/README.grid index 9033c9d445..a552ce38ab 100644 --- a/examples/snap/README.grid +++ b/examples/snap/README.grid @@ -7,3 +7,13 @@ in.grid.test # stress test of grid and grid/local in.grid.tri # grid with triclinic cell grid.py # access data from Python library interface + +For the LAMMPS public repo, the only examples that will be provided are: + + in.grid.snap # simple test of grid and grid/local + in.grid.tri # same for a triclinic box + log.15Jun22.grid.snap.g++.1 + log.15Jun22.grid.snap.g++.4 + log.15Jun22.grid.tri.g++.1 + log.15Jun22.grid.tri.g++.4 + diff --git a/examples/snap/in.grid.snap b/examples/snap/in.grid.snap new file mode 100644 index 0000000000..08c95a004f --- /dev/null +++ b/examples/snap/in.grid.snap @@ -0,0 +1,94 @@ +# Demonstrate calculation of SNAP bispectrum descriptors on a grid + +# CORRECTNESS: The two atom positions coincide with two of +# the gridpoints, so c_b[2][1-5] should match c_mygrid[8][4-8]. +# The same is true for compute grid/local c_mygridlocal[8][4-11]. +# Local arrays can not be access directly in the script, +# but they are printed out to file dump.blocal + +variable nrep index 1 +variable a index 3.316 +variable ngrid index 2 + +units metal +atom_modify map hash + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice custom $a & + a1 1 0 0 & + a2 0 1 0 & + a3 0 0 1 & + basis 0 0 0 & + basis 0.5 0.5 0.5 & + +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 180.88 + +# define atom compute and grid compute + +group snapgroup type 1 +variable twojmax equal 2 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quadratic equal 0 +variable switch equal 1 + +variable snap_options string & + "${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} & + bzeroflag ${bzero} switchflag ${switch}" + +# build zero potential to satisfy compute sna/atom + +pair_style zero ${rcutfac} +pair_coeff * * + +# define atom and grid computes + +compute b all sna/atom ${snap_options} +compute mygrid all sna/grid grid ${ngrid} ${ngrid} ${ngrid} & + ${snap_options} +compute mygridlocal all sna/grid/local grid ${ngrid} ${ngrid} ${ngrid} & + ${snap_options} + +# define output + +variable B5atom equal c_b[2][5] +variable B5grid equal c_mygrid[8][8] + +variable rmse_global equal "sqrt( & + (c_mygrid[8][1] - x[2])^2 + & + (c_mygrid[8][2] - y[2])^2 + & + (c_mygrid[8][3] - z[2])^2 + & + (c_mygrid[8][4] - c_b[2][1])^2 + & + (c_mygrid[8][5] - c_b[2][2])^2 + & + (c_mygrid[8][6] - c_b[2][3])^2 + & + (c_mygrid[8][7] - c_b[2][4])^2 + & + (c_mygrid[8][8] - c_b[2][5])^2 & + )" + +thermo_style custom step v_B5atom v_B5grid v_rmse_global + +# this is the only way to view the local grid + +dump 1 all local 1000 dump.blocal c_mygridlocal[*] +dump 2 all custom 1000 dump.batom id x y z c_b[*] + +# run + +run 0 + diff --git a/examples/snap/in.grid.tri b/examples/snap/in.grid.tri index f375c18c42..5283957eb8 100644 --- a/examples/snap/in.grid.tri +++ b/examples/snap/in.grid.tri @@ -1,4 +1,5 @@ -# Demonstrate bispectrum computes for triclinic cell +# Demonstrate calculation of SNAP bispectrum +# descriptors on a grid for triclinic cell # This triclinic cell has 6 times the volume of the single # unit cell used by in.grid @@ -6,35 +7,37 @@ # with each unit cell containing 2 atoms and the # reduced lattice vectors are [1 0 0], [1 1 0], and [1 1 1]. # The grid is listed in x-fastest order -# CORRECTNESS: thermo output for c_mygrid[*][7] should contain -# the same 2 values that appear in c_mygrid[*][7] for in.grid, -# 7.0663376 and 13.808803, corresponding to atom and insterstitial sites, -# respectively, and with occurrences 12 and 36, respectively. + +# CORRECTNESS: The atom positions coincide with certain +# gridpoints, so c_b[1][1-5] should match c_mygrid[1][4-8] +# and c_b[7][1-5] should match c_mygrid[13][4-8]. +# Local arrays can not be access directly in the script, +# but they are printed out to file dump.blocal.tri # Initialize simulation -variable nsteps index 0 -variable nrep index 1 -variable a index 3.316 -variable ngrid index 4 +variable nrep index 1 +variable a index 3.316 +variable ngrid index 2 -variable ngridx equal 3*${ngrid} -variable ngridy equal 2*${ngrid} -variable ngridz equal 1*${ngrid} +variable nrepx equal 3*${nrep} +variable nrepy equal 2*${nrep} +variable nrepz equal 1*${nrep} -variable nrepx equal 1*${nrep} -variable nrepy equal 1*${nrep} -variable nrepz equal 1*${nrep} +variable ngridx equal 3*${ngrid} +variable ngridy equal 2*${ngrid} +variable ngridz equal 1*${ngrid} -units metal +units metal +atom_modify map hash sort 0 0 # generate the box and atom positions using a BCC lattice -variable nx equal ${nrepx} -variable ny equal ${nrepy} -variable nz equal ${nrepz} +variable nx equal ${nrepx} +variable ny equal ${nrepy} +variable nz equal ${nrepz} -boundary p p p +boundary p p p lattice custom $a & a1 1 0 0 & @@ -42,20 +45,16 @@ lattice custom $a & a3 1 1 1 & basis 0 0 0 & basis 0.0 0.0 0.5 & -# origin 0.25 0.25 0.25 + spacing 1 1 1 box tilt large region box prism 0 ${nx} 0 ${ny} 0 ${nz} ${ny} ${nz} ${nz} create_box 1 box create_atoms 1 box -mass 1 180.88 +mass 1 180.88 -# choose potential - -include Ta06A.snap - -# define grid compute and atom compute +# define atom compute and grid compute group snapgroup type 1 variable twojmax equal 2 @@ -65,71 +64,51 @@ variable rmin0 equal 0 variable wj equal 1 variable radelem equal 0.5 variable bzero equal 0 -variable quad equal 0 +variable quadratic equal 0 variable switch equal 1 -compute b all sna/atom & - ${rcutfac} ${rfac0} ${twojmax} ${radelem} & - ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & - quadraticflag ${quad} switchflag ${switch} +variable snap_options string & + "${rcutfac} ${rfac0} ${twojmax} ${radelem} & + ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} & + bzeroflag ${bzero} switchflag ${switch}" -compute mygrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} & - ${rcutfac} ${rfac0} ${twojmax} ${radelem} & - ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & - quadraticflag ${quad} switchflag ${switch} +# build zero potential to satisfy compute sna/atom + +pair_style zero ${rcutfac} +pair_coeff * * + +# define atom and grid computes + +compute b all sna/atom ${snap_options} +compute mygrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} & + ${snap_options} +compute mygridlocal all sna/grid/local grid ${ngridx} ${ngridy} ${ngridz} & + ${snap_options} # define output -# mygrid is ngrid by (3+nbis) = 384x8 +variable B5atom equal c_b[7][5] +variable B5grid equal c_mygrid[13][8] -thermo_style custom step temp ke pe vol & - c_mygrid[1][7] c_mygrid[2][7] c_mygrid[3][7] c_mygrid[4][7] c_mygrid[5][7] c_mygrid[6][7] c_mygrid[7][7] c_mygrid[8][7] c_mygrid[9][7] & - c_mygrid[10][7] c_mygrid[11][7] c_mygrid[12][7] c_mygrid[13][7] c_mygrid[14][7] c_mygrid[15][7] c_mygrid[16][7] c_mygrid[17][7] c_mygrid[18][7] c_mygrid[19][7] & - c_mygrid[20][7] c_mygrid[21][7] c_mygrid[22][7] c_mygrid[23][7] c_mygrid[24][7] c_mygrid[25][7] c_mygrid[26][7] c_mygrid[27][7] c_mygrid[28][7] c_mygrid[29][7] & - c_mygrid[30][7] c_mygrid[31][7] c_mygrid[32][7] c_mygrid[33][7] c_mygrid[34][7] c_mygrid[35][7] c_mygrid[36][7] c_mygrid[37][7] c_mygrid[38][7] c_mygrid[39][7] & - c_mygrid[40][7] c_mygrid[41][7] c_mygrid[42][7] c_mygrid[43][7] c_mygrid[44][7] c_mygrid[45][7] c_mygrid[46][7] c_mygrid[47][7] c_mygrid[48][7] c_mygrid[49][7] & - c_mygrid[50][7] c_mygrid[51][7] c_mygrid[52][7] c_mygrid[53][7] c_mygrid[54][7] c_mygrid[55][7] c_mygrid[56][7] c_mygrid[57][7] c_mygrid[58][7] c_mygrid[59][7] & - c_mygrid[60][7] c_mygrid[61][7] c_mygrid[62][7] c_mygrid[63][7] c_mygrid[64][7] c_mygrid[65][7] c_mygrid[66][7] c_mygrid[67][7] c_mygrid[68][7] c_mygrid[69][7] & - c_mygrid[70][7] c_mygrid[71][7] c_mygrid[72][7] c_mygrid[73][7] c_mygrid[74][7] c_mygrid[75][7] c_mygrid[76][7] c_mygrid[77][7] c_mygrid[78][7] c_mygrid[79][7] & - c_mygrid[80][7] c_mygrid[81][7] c_mygrid[82][7] c_mygrid[83][7] c_mygrid[84][7] c_mygrid[85][7] c_mygrid[86][7] c_mygrid[87][7] c_mygrid[88][7] c_mygrid[89][7] & - c_mygrid[90][7] c_mygrid[91][7] c_mygrid[92][7] c_mygrid[93][7] c_mygrid[94][7] c_mygrid[95][7] c_mygrid[96][7] c_mygrid[97][7] c_mygrid[98][7] c_mygrid[99][7] & - c_mygrid[100][7] c_mygrid[101][7] c_mygrid[102][7] c_mygrid[103][7] c_mygrid[104][7] c_mygrid[105][7] c_mygrid[106][7] c_mygrid[107][7] c_mygrid[108][7] c_mygrid[109][7] & - c_mygrid[110][7] c_mygrid[111][7] c_mygrid[112][7] c_mygrid[113][7] c_mygrid[114][7] c_mygrid[115][7] c_mygrid[116][7] c_mygrid[117][7] c_mygrid[118][7] c_mygrid[119][7] & - c_mygrid[120][7] c_mygrid[121][7] c_mygrid[122][7] c_mygrid[123][7] c_mygrid[124][7] c_mygrid[125][7] c_mygrid[126][7] c_mygrid[127][7] c_mygrid[128][7] c_mygrid[129][7] & - c_mygrid[130][7] c_mygrid[131][7] c_mygrid[132][7] c_mygrid[133][7] c_mygrid[134][7] c_mygrid[135][7] c_mygrid[136][7] c_mygrid[137][7] c_mygrid[138][7] c_mygrid[139][7] & - c_mygrid[140][7] c_mygrid[141][7] c_mygrid[142][7] c_mygrid[143][7] c_mygrid[144][7] c_mygrid[145][7] c_mygrid[146][7] c_mygrid[147][7] c_mygrid[148][7] c_mygrid[149][7] & - c_mygrid[150][7] c_mygrid[151][7] c_mygrid[152][7] c_mygrid[153][7] c_mygrid[154][7] c_mygrid[155][7] c_mygrid[156][7] c_mygrid[157][7] c_mygrid[158][7] c_mygrid[159][7] & - c_mygrid[160][7] c_mygrid[161][7] c_mygrid[162][7] c_mygrid[163][7] c_mygrid[164][7] c_mygrid[165][7] c_mygrid[166][7] c_mygrid[167][7] c_mygrid[168][7] c_mygrid[169][7] & - c_mygrid[170][7] c_mygrid[171][7] c_mygrid[172][7] c_mygrid[173][7] c_mygrid[174][7] c_mygrid[175][7] c_mygrid[176][7] c_mygrid[177][7] c_mygrid[178][7] c_mygrid[179][7] & - c_mygrid[180][7] c_mygrid[181][7] c_mygrid[182][7] c_mygrid[183][7] c_mygrid[184][7] c_mygrid[185][7] c_mygrid[186][7] c_mygrid[187][7] c_mygrid[188][7] c_mygrid[189][7] & - c_mygrid[190][7] c_mygrid[191][7] c_mygrid[192][7] c_mygrid[193][7] c_mygrid[194][7] c_mygrid[195][7] c_mygrid[196][7] c_mygrid[197][7] c_mygrid[198][7] c_mygrid[199][7] & - c_mygrid[200][7] c_mygrid[201][7] c_mygrid[202][7] c_mygrid[203][7] c_mygrid[204][7] c_mygrid[205][7] c_mygrid[206][7] c_mygrid[207][7] c_mygrid[208][7] c_mygrid[209][7] & - c_mygrid[210][7] c_mygrid[211][7] c_mygrid[212][7] c_mygrid[213][7] c_mygrid[214][7] c_mygrid[215][7] c_mygrid[216][7] c_mygrid[217][7] c_mygrid[218][7] c_mygrid[219][7] & - c_mygrid[220][7] c_mygrid[221][7] c_mygrid[222][7] c_mygrid[223][7] c_mygrid[224][7] c_mygrid[225][7] c_mygrid[226][7] c_mygrid[227][7] c_mygrid[228][7] c_mygrid[229][7] & - c_mygrid[230][7] c_mygrid[231][7] c_mygrid[232][7] c_mygrid[233][7] c_mygrid[234][7] c_mygrid[235][7] c_mygrid[236][7] c_mygrid[237][7] c_mygrid[238][7] c_mygrid[239][7] & - c_mygrid[240][7] c_mygrid[241][7] c_mygrid[242][7] c_mygrid[243][7] c_mygrid[244][7] c_mygrid[245][7] c_mygrid[246][7] c_mygrid[247][7] c_mygrid[248][7] c_mygrid[249][7] & - c_mygrid[250][7] c_mygrid[251][7] c_mygrid[252][7] c_mygrid[253][7] c_mygrid[254][7] c_mygrid[255][7] c_mygrid[256][7] c_mygrid[257][7] c_mygrid[258][7] c_mygrid[259][7] & - c_mygrid[260][7] c_mygrid[261][7] c_mygrid[262][7] c_mygrid[263][7] c_mygrid[264][7] c_mygrid[265][7] c_mygrid[266][7] c_mygrid[267][7] c_mygrid[268][7] c_mygrid[269][7] & - c_mygrid[270][7] c_mygrid[271][7] c_mygrid[272][7] c_mygrid[273][7] c_mygrid[274][7] c_mygrid[275][7] c_mygrid[276][7] c_mygrid[277][7] c_mygrid[278][7] c_mygrid[279][7] & - c_mygrid[280][7] c_mygrid[281][7] c_mygrid[282][7] c_mygrid[283][7] c_mygrid[284][7] c_mygrid[285][7] c_mygrid[286][7] c_mygrid[287][7] c_mygrid[288][7] c_mygrid[289][7] & - c_mygrid[290][7] c_mygrid[291][7] c_mygrid[292][7] c_mygrid[293][7] c_mygrid[294][7] c_mygrid[295][7] c_mygrid[296][7] c_mygrid[297][7] c_mygrid[298][7] c_mygrid[299][7] & - c_mygrid[300][7] c_mygrid[301][7] c_mygrid[302][7] c_mygrid[303][7] c_mygrid[304][7] c_mygrid[305][7] c_mygrid[306][7] c_mygrid[307][7] c_mygrid[308][7] c_mygrid[309][7] & - c_mygrid[310][7] c_mygrid[311][7] c_mygrid[312][7] c_mygrid[313][7] c_mygrid[314][7] c_mygrid[315][7] c_mygrid[316][7] c_mygrid[317][7] c_mygrid[318][7] c_mygrid[319][7] & - c_mygrid[320][7] c_mygrid[321][7] c_mygrid[322][7] c_mygrid[323][7] c_mygrid[324][7] c_mygrid[325][7] c_mygrid[326][7] c_mygrid[327][7] c_mygrid[328][7] c_mygrid[329][7] & - c_mygrid[330][7] c_mygrid[331][7] c_mygrid[332][7] c_mygrid[333][7] c_mygrid[334][7] c_mygrid[335][7] c_mygrid[336][7] c_mygrid[337][7] c_mygrid[338][7] c_mygrid[339][7] & - c_mygrid[340][7] c_mygrid[341][7] c_mygrid[342][7] c_mygrid[343][7] c_mygrid[344][7] c_mygrid[345][7] c_mygrid[346][7] c_mygrid[347][7] c_mygrid[348][7] c_mygrid[349][7] & - c_mygrid[350][7] c_mygrid[351][7] c_mygrid[352][7] c_mygrid[353][7] c_mygrid[354][7] c_mygrid[355][7] c_mygrid[356][7] c_mygrid[357][7] c_mygrid[358][7] c_mygrid[359][7] & - c_mygrid[360][7] c_mygrid[361][7] c_mygrid[362][7] c_mygrid[363][7] c_mygrid[364][7] c_mygrid[365][7] c_mygrid[366][7] c_mygrid[367][7] c_mygrid[368][7] c_mygrid[369][7] & - c_mygrid[370][7] c_mygrid[371][7] c_mygrid[372][7] c_mygrid[373][7] c_mygrid[374][7] c_mygrid[375][7] c_mygrid[376][7] c_mygrid[377][7] c_mygrid[378][7] c_mygrid[379][7] & - c_mygrid[380][7] c_mygrid[381][7] c_mygrid[382][7] c_mygrid[383][7] c_mygrid[384][7] +# do not compare x,y,z because assignment of ids +# to atoms is not unnique for different processor grids -thermo_modify norm yes +variable rmse_global equal "sqrt( & + (c_mygrid[13][4] - c_b[7][1])^2 + & + (c_mygrid[13][5] - c_b[7][2])^2 + & + (c_mygrid[13][6] - c_b[7][3])^2 + & + (c_mygrid[13][7] - c_b[7][4])^2 + & + (c_mygrid[13][8] - c_b[7][5])^2 & + )" -dump mydump_b all custom 1000 dump_b id c_b[*] +thermo_style custom step v_B5atom v_B5grid v_rmse_global + +# this is the only way to view the local grid + +dump 1 all local 1000 dump.blocal.tri c_mygridlocal[*] +dump 2 all custom 1000 dump.batom.tri id x y z c_b[*] # run -run 0 - - +run 0 diff --git a/examples/snap/log.15Jun22.grid.snap.g++.1 b/examples/snap/log.15Jun22.grid.snap.g++.1 new file mode 100644 index 0000000000..71b884d1b6 --- /dev/null +++ b/examples/snap/log.15Jun22.grid.snap.g++.1 @@ -0,0 +1,167 @@ +LAMMPS (28 Jul 2021) +# Demonstrate calculation of SNAP bispectrum descriptors on a grid + +# CORRECTNESS: The two atom positions coincide with two of +# the gridpoints, so c_b[2][1-5] should match c_mygrid[8][4-8]. +# The same is true for compute grid/local c_mygridlocal[8][4-11]. +# Local arrays can not be access directly in the script, +# but they are printed out to file dump.blocal + +variable nrep index 1 +variable a index 3.316 +variable ngrid index 2 + +units metal +atom_modify map hash + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable nx equal 1 +variable ny equal ${nrep} +variable ny equal 1 +variable nz equal ${nrep} +variable nz equal 1 + +boundary p p p + +lattice custom $a a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 +lattice custom 3.316 a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 +Lattice spacing in x,y,z = 3.3160000 3.3160000 3.3160000 +region box block 0 ${nx} 0 ${ny} 0 ${nz} +region box block 0 1 0 ${ny} 0 ${nz} +region box block 0 1 0 1 0 ${nz} +region box block 0 1 0 1 0 1 +create_box 1 box +Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (3.3160000 3.3160000 3.3160000) + 1 by 1 by 1 MPI processor grid +create_atoms 1 box +Created 2 atoms + using lattice units in orthogonal box = (0.0000000 0.0000000 0.0000000) to (3.3160000 3.3160000 3.3160000) + create_atoms CPU = 0.000 seconds + +mass 1 180.88 + +# define atom compute and grid compute + +group snapgroup type 1 +2 atoms in group snapgroup +variable twojmax equal 2 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quadratic equal 0 +variable switch equal 1 + +variable snap_options string "${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch}" +4.67637 ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 + +# build zero potential to satisfy compute sna/atom + +pair_style zero ${rcutfac} +pair_style zero 4.67637 +pair_coeff * * + +# define atom and grid computes + +compute b all sna/atom ${snap_options} +compute b all sna/atom 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 +compute mygrid all sna/grid grid ${ngrid} ${ngrid} ${ngrid} ${snap_options} +compute mygrid all sna/grid grid 2 ${ngrid} ${ngrid} ${snap_options} +compute mygrid all sna/grid grid 2 2 ${ngrid} ${snap_options} +compute mygrid all sna/grid grid 2 2 2 ${snap_options} +compute mygrid all sna/grid grid 2 2 2 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 +compute mygridlocal all sna/grid/local grid ${ngrid} ${ngrid} ${ngrid} ${snap_options} +compute mygridlocal all sna/grid/local grid 2 ${ngrid} ${ngrid} ${snap_options} +compute mygridlocal all sna/grid/local grid 2 2 ${ngrid} ${snap_options} +compute mygridlocal all sna/grid/local grid 2 2 2 ${snap_options} +compute mygridlocal all sna/grid/local grid 2 2 2 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 + +# define output + +variable B5atom equal c_b[2][5] +variable B5grid equal c_mygrid[8][8] + +variable rmse_global equal "sqrt( (c_mygrid[8][1] - x[2])^2 + (c_mygrid[8][2] - y[2])^2 + (c_mygrid[8][3] - z[2])^2 + (c_mygrid[8][4] - c_b[2][1])^2 + (c_mygrid[8][5] - c_b[2][2])^2 + (c_mygrid[8][6] - c_b[2][3])^2 + (c_mygrid[8][7] - c_b[2][4])^2 + (c_mygrid[8][8] - c_b[2][5])^2 )" + +thermo_style custom step v_B5atom v_B5grid v_rmse_global + +# this is the only way to view the local grid + +dump 1 all local 1000 dump.blocal c_mygridlocal[*] +dump 2 all custom 1000 dump.batom id x y z c_b[*] + +# run + +run 0 +WARNING: No fixes defined, atoms won't move (src/verlet.cpp:55) +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 6.67637 + ghost atom cutoff = 6.67637 + binsize = 3.338185, bins = 1 1 1 + 4 neighbor lists, perpetual/occasional/extra = 1 3 0 + (1) pair zero, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d + bin: standard + (2) compute sna/atom, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (3) compute sna/grid, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (4) compute sna/grid/local, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 8.384 | 8.384 | 8.384 Mbytes +Step v_B5atom v_B5grid v_rmse_global + 0 1.0427295 1.0427295 0 +Loop time of 1e-06 on 1 procs for 0 steps with 2 atoms + +100.0% CPU use with 1 MPI tasks x no OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 1e-06 | | |100.00 + +Nlocal: 2.00000 ave 2 max 2 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 339.000 ave 339 max 339 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 64.0000 ave 64 max 64 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 128.000 ave 128 max 128 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 128 +Ave neighs/atom = 64.000000 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 diff --git a/examples/snap/log.15Jun22.grid.snap.g++.4 b/examples/snap/log.15Jun22.grid.snap.g++.4 new file mode 100644 index 0000000000..80761fc395 --- /dev/null +++ b/examples/snap/log.15Jun22.grid.snap.g++.4 @@ -0,0 +1,168 @@ +LAMMPS (28 Jul 2021) +# Demonstrate calculation of SNAP bispectrum descriptors on a grid + +# CORRECTNESS: The two atom positions coincide with two of +# the gridpoints, so c_b[2][1-5] should match c_mygrid[8][4-8]. +# The same is true for compute grid/local c_mygridlocal[8][4-11]. +# Local arrays can not be access directly in the script, +# but they are printed out to file dump.blocal + +variable nrep index 1 +variable a index 3.316 +variable ngrid index 2 + +units metal +atom_modify map hash + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable nx equal 1 +variable ny equal ${nrep} +variable ny equal 1 +variable nz equal ${nrep} +variable nz equal 1 + +boundary p p p + +lattice custom $a a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 +lattice custom 3.316 a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 +Lattice spacing in x,y,z = 3.3160000 3.3160000 3.3160000 +region box block 0 ${nx} 0 ${ny} 0 ${nz} +region box block 0 1 0 ${ny} 0 ${nz} +region box block 0 1 0 1 0 ${nz} +region box block 0 1 0 1 0 1 +create_box 1 box +Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (3.3160000 3.3160000 3.3160000) + 1 by 2 by 2 MPI processor grid +create_atoms 1 box +Created 2 atoms + using lattice units in orthogonal box = (0.0000000 0.0000000 0.0000000) to (3.3160000 3.3160000 3.3160000) + create_atoms CPU = 0.001 seconds + +mass 1 180.88 + +# define atom compute and grid compute + +group snapgroup type 1 +2 atoms in group snapgroup +variable twojmax equal 2 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quadratic equal 0 +variable switch equal 1 + +variable snap_options string "${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch}" +4.67637 ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 + +# build zero potential to satisfy compute sna/atom + +pair_style zero ${rcutfac} +pair_style zero 4.67637 +pair_coeff * * + +# define atom and grid computes + +compute b all sna/atom ${snap_options} +compute b all sna/atom 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 +compute mygrid all sna/grid grid ${ngrid} ${ngrid} ${ngrid} ${snap_options} +compute mygrid all sna/grid grid 2 ${ngrid} ${ngrid} ${snap_options} +compute mygrid all sna/grid grid 2 2 ${ngrid} ${snap_options} +compute mygrid all sna/grid grid 2 2 2 ${snap_options} +compute mygrid all sna/grid grid 2 2 2 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 +compute mygridlocal all sna/grid/local grid ${ngrid} ${ngrid} ${ngrid} ${snap_options} +compute mygridlocal all sna/grid/local grid 2 ${ngrid} ${ngrid} ${snap_options} +compute mygridlocal all sna/grid/local grid 2 2 ${ngrid} ${snap_options} +compute mygridlocal all sna/grid/local grid 2 2 2 ${snap_options} +compute mygridlocal all sna/grid/local grid 2 2 2 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 + +# define output + +variable B5atom equal c_b[2][5] +variable B5grid equal c_mygrid[8][8] + +variable rmse_global equal "sqrt( (c_mygrid[8][1] - x[2])^2 + (c_mygrid[8][2] - y[2])^2 + (c_mygrid[8][3] - z[2])^2 + (c_mygrid[8][4] - c_b[2][1])^2 + (c_mygrid[8][5] - c_b[2][2])^2 + (c_mygrid[8][6] - c_b[2][3])^2 + (c_mygrid[8][7] - c_b[2][4])^2 + (c_mygrid[8][8] - c_b[2][5])^2 )" + +thermo_style custom step v_B5atom v_B5grid v_rmse_global + +# this is the only way to view the local grid + +dump 1 all local 1000 dump.blocal c_mygridlocal[*] +dump 2 all custom 1000 dump.batom id x y z c_b[*] + +# run + +run 0 +WARNING: No fixes defined, atoms won't move (src/verlet.cpp:55) +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 6.67637 + ghost atom cutoff = 6.67637 + binsize = 3.338185, bins = 1 1 1 + 4 neighbor lists, perpetual/occasional/extra = 1 3 0 + (1) pair zero, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d + bin: standard + (2) compute sna/atom, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (3) compute sna/grid, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (4) compute sna/grid/local, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard +WARNING: Proc sub-domain size < neighbor skin, could lead to lost atoms (src/domain.cpp:964) +Per MPI rank memory allocation (min/avg/max) = 7.381 | 7.889 | 8.397 Mbytes +Step v_B5atom v_B5grid v_rmse_global + 0 1.0427295 1.0427295 0 +Loop time of 1.5e-06 on 4 procs for 0 steps with 2 atoms + +83.3% CPU use with 4 MPI tasks x no OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 1.5e-06 | | |100.00 + +Nlocal: 0.500000 ave 1 max 0 min +Histogram: 2 0 0 0 0 0 0 0 0 2 +Nghost: 274.500 ave 275 max 274 min +Histogram: 2 0 0 0 0 0 0 0 0 2 +Neighs: 16.0000 ave 40 max 0 min +Histogram: 2 0 0 0 0 0 1 0 0 1 +FullNghs: 32.0000 ave 64 max 0 min +Histogram: 2 0 0 0 0 0 0 0 0 2 + +Total # of neighbors = 128 +Ave neighs/atom = 64.000000 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 diff --git a/examples/snap/log.15Jun22.grid.tri.g++.1 b/examples/snap/log.15Jun22.grid.tri.g++.1 new file mode 100644 index 0000000000..c261154367 --- /dev/null +++ b/examples/snap/log.15Jun22.grid.tri.g++.1 @@ -0,0 +1,200 @@ +LAMMPS (28 Jul 2021) +# Demonstrate calculation of SNAP bispectrum +# descriptors on a grid for triclinic cell + +# This triclinic cell has 6 times the volume of the single +# unit cell used by in.grid +# and contains 12 atoms. It is a 3x2x1 supercell +# with each unit cell containing 2 atoms and the +# reduced lattice vectors are [1 0 0], [1 1 0], and [1 1 1]. +# The grid is listed in x-fastest order + +# CORRECTNESS: The atom positions coincide with certain +# gridpoints, so c_b[1][1-5] should match c_mygrid[1][4-8] +# and c_b[7][1-5] should match c_mygrid[13][4-8]. +# Local arrays can not be access directly in the script, +# but they are printed out to file dump.blocal.tri + +# Initialize simulation + +variable nrep index 1 +variable a index 3.316 +variable ngrid index 2 + +variable nrepx equal 3*${nrep} +variable nrepx equal 3*1 +variable nrepy equal 2*${nrep} +variable nrepy equal 2*1 +variable nrepz equal 1*${nrep} +variable nrepz equal 1*1 + +variable ngridx equal 3*${ngrid} +variable ngridx equal 3*2 +variable ngridy equal 2*${ngrid} +variable ngridy equal 2*2 +variable ngridz equal 1*${ngrid} +variable ngridz equal 1*2 + +units metal +atom_modify map hash sort 0 0 + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrepx} +variable nx equal 3 +variable ny equal ${nrepy} +variable ny equal 2 +variable nz equal ${nrepz} +variable nz equal 1 + +boundary p p p + +lattice custom $a a1 1 0 0 a2 1 1 0 a3 1 1 1 basis 0 0 0 basis 0.0 0.0 0.5 spacing 1 1 1 +lattice custom 3.316 a1 1 0 0 a2 1 1 0 a3 1 1 1 basis 0 0 0 basis 0.0 0.0 0.5 spacing 1 1 1 +Lattice spacing in x,y,z = 3.3160000 3.3160000 3.3160000 + +box tilt large +region box prism 0 ${nx} 0 ${ny} 0 ${nz} ${ny} ${nz} ${nz} +region box prism 0 3 0 ${ny} 0 ${nz} ${ny} ${nz} ${nz} +region box prism 0 3 0 2 0 ${nz} ${ny} ${nz} ${nz} +region box prism 0 3 0 2 0 1 ${ny} ${nz} ${nz} +region box prism 0 3 0 2 0 1 2 ${nz} ${nz} +region box prism 0 3 0 2 0 1 2 1 ${nz} +region box prism 0 3 0 2 0 1 2 1 1 +create_box 1 box +Created triclinic box = (0.0000000 0.0000000 0.0000000) to (9.9480000 6.6320000 3.3160000) with tilt (6.6320000 3.3160000 3.3160000) +WARNING: Triclinic box skew is large (src/domain.cpp:219) + 1 by 1 by 1 MPI processor grid +create_atoms 1 box +Created 12 atoms + using lattice units in triclinic box = (0.0000000 0.0000000 0.0000000) to (9.9480000 6.6320000 3.3160000) with tilt (6.6320000 3.3160000 3.3160000) + create_atoms CPU = 0.001 seconds + +mass 1 180.88 + +# define atom compute and grid compute + +group snapgroup type 1 +12 atoms in group snapgroup +variable twojmax equal 2 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quadratic equal 0 +variable switch equal 1 + +variable snap_options string "${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch}" +4.67637 ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 + +# build zero potential to satisfy compute sna/atom + +pair_style zero ${rcutfac} +pair_style zero 4.67637 +pair_coeff * * + +# define atom and grid computes + +compute b all sna/atom ${snap_options} +compute b all sna/atom 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 +compute mygrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} ${snap_options} +compute mygrid all sna/grid grid 6 ${ngridy} ${ngridz} ${snap_options} +compute mygrid all sna/grid grid 6 4 ${ngridz} ${snap_options} +compute mygrid all sna/grid grid 6 4 2 ${snap_options} +compute mygrid all sna/grid grid 6 4 2 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 +compute mygridlocal all sna/grid/local grid ${ngridx} ${ngridy} ${ngridz} ${snap_options} +compute mygridlocal all sna/grid/local grid 6 ${ngridy} ${ngridz} ${snap_options} +compute mygridlocal all sna/grid/local grid 6 4 ${ngridz} ${snap_options} +compute mygridlocal all sna/grid/local grid 6 4 2 ${snap_options} +compute mygridlocal all sna/grid/local grid 6 4 2 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 + +# define output + +variable B5atom equal c_b[7][5] +variable B5grid equal c_mygrid[13][8] + +# do not compare x,y,z because assignment of ids +# to atoms is not unnique for different processor grids + +variable rmse_global equal "sqrt( (c_mygrid[13][4] - c_b[7][1])^2 + (c_mygrid[13][5] - c_b[7][2])^2 + (c_mygrid[13][6] - c_b[7][3])^2 + (c_mygrid[13][7] - c_b[7][4])^2 + (c_mygrid[13][8] - c_b[7][5])^2 )" + +thermo_style custom step v_B5atom v_B5grid v_rmse_global + +# this is the only way to view the local grid + +dump 1 all local 1000 dump.blocal.tri c_mygridlocal[*] +dump 2 all custom 1000 dump.batom.tri id x y z c_b[*] + +# run + +run 0 +WARNING: No fixes defined, atoms won't move (src/verlet.cpp:55) +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 6.67637 + ghost atom cutoff = 6.67637 + binsize = 3.338185, bins = 6 3 1 + 4 neighbor lists, perpetual/occasional/extra = 1 3 0 + (1) pair zero, perpetual + attributes: half, newton on + pair build: half/bin/newton/tri + stencil: half/bin/3d/tri + bin: standard + (2) compute sna/atom, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (3) compute sna/grid, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (4) compute sna/grid/local, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 8.435 | 8.435 | 8.435 Mbytes +Step v_B5atom v_B5grid v_rmse_global + 0 1.0427295 1.0427295 7.2262471e-14 +Loop time of 1e-06 on 1 procs for 0 steps with 12 atoms + +100.0% CPU use with 1 MPI tasks x no OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 1e-06 | | |100.00 + +Nlocal: 12.0000 ave 12 max 12 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 604.000 ave 604 max 604 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 384.000 ave 384 max 384 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 768.000 ave 768 max 768 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 768 +Ave neighs/atom = 64.000000 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 diff --git a/examples/snap/log.15Jun22.grid.tri.g++.4 b/examples/snap/log.15Jun22.grid.tri.g++.4 new file mode 100644 index 0000000000..bac7ecaa5a --- /dev/null +++ b/examples/snap/log.15Jun22.grid.tri.g++.4 @@ -0,0 +1,200 @@ +LAMMPS (28 Jul 2021) +# Demonstrate calculation of SNAP bispectrum +# descriptors on a grid for triclinic cell + +# This triclinic cell has 6 times the volume of the single +# unit cell used by in.grid +# and contains 12 atoms. It is a 3x2x1 supercell +# with each unit cell containing 2 atoms and the +# reduced lattice vectors are [1 0 0], [1 1 0], and [1 1 1]. +# The grid is listed in x-fastest order + +# CORRECTNESS: The atom positions coincide with certain +# gridpoints, so c_b[1][1-5] should match c_mygrid[1][4-8] +# and c_b[7][1-5] should match c_mygrid[13][4-8]. +# Local arrays can not be access directly in the script, +# but they are printed out to file dump.blocal.tri + +# Initialize simulation + +variable nrep index 1 +variable a index 3.316 +variable ngrid index 2 + +variable nrepx equal 3*${nrep} +variable nrepx equal 3*1 +variable nrepy equal 2*${nrep} +variable nrepy equal 2*1 +variable nrepz equal 1*${nrep} +variable nrepz equal 1*1 + +variable ngridx equal 3*${ngrid} +variable ngridx equal 3*2 +variable ngridy equal 2*${ngrid} +variable ngridy equal 2*2 +variable ngridz equal 1*${ngrid} +variable ngridz equal 1*2 + +units metal +atom_modify map hash sort 0 0 + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrepx} +variable nx equal 3 +variable ny equal ${nrepy} +variable ny equal 2 +variable nz equal ${nrepz} +variable nz equal 1 + +boundary p p p + +lattice custom $a a1 1 0 0 a2 1 1 0 a3 1 1 1 basis 0 0 0 basis 0.0 0.0 0.5 spacing 1 1 1 +lattice custom 3.316 a1 1 0 0 a2 1 1 0 a3 1 1 1 basis 0 0 0 basis 0.0 0.0 0.5 spacing 1 1 1 +Lattice spacing in x,y,z = 3.3160000 3.3160000 3.3160000 + +box tilt large +region box prism 0 ${nx} 0 ${ny} 0 ${nz} ${ny} ${nz} ${nz} +region box prism 0 3 0 ${ny} 0 ${nz} ${ny} ${nz} ${nz} +region box prism 0 3 0 2 0 ${nz} ${ny} ${nz} ${nz} +region box prism 0 3 0 2 0 1 ${ny} ${nz} ${nz} +region box prism 0 3 0 2 0 1 2 ${nz} ${nz} +region box prism 0 3 0 2 0 1 2 1 ${nz} +region box prism 0 3 0 2 0 1 2 1 1 +create_box 1 box +Created triclinic box = (0.0000000 0.0000000 0.0000000) to (9.9480000 6.6320000 3.3160000) with tilt (6.6320000 3.3160000 3.3160000) +WARNING: Triclinic box skew is large (src/domain.cpp:219) + 2 by 2 by 1 MPI processor grid +create_atoms 1 box +Created 12 atoms + using lattice units in triclinic box = (0.0000000 0.0000000 0.0000000) to (9.9480000 6.6320000 3.3160000) with tilt (6.6320000 3.3160000 3.3160000) + create_atoms CPU = 0.001 seconds + +mass 1 180.88 + +# define atom compute and grid compute + +group snapgroup type 1 +12 atoms in group snapgroup +variable twojmax equal 2 +variable rcutfac equal 4.67637 +variable rfac0 equal 0.99363 +variable rmin0 equal 0 +variable wj equal 1 +variable radelem equal 0.5 +variable bzero equal 0 +variable quadratic equal 0 +variable switch equal 1 + +variable snap_options string "${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch}" +4.67637 ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 ${radelem} ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 ${wj} rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 ${rmin0} quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag ${quadratic} bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag ${bzero} switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag ${switch} +4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 + +# build zero potential to satisfy compute sna/atom + +pair_style zero ${rcutfac} +pair_style zero 4.67637 +pair_coeff * * + +# define atom and grid computes + +compute b all sna/atom ${snap_options} +compute b all sna/atom 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 +compute mygrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} ${snap_options} +compute mygrid all sna/grid grid 6 ${ngridy} ${ngridz} ${snap_options} +compute mygrid all sna/grid grid 6 4 ${ngridz} ${snap_options} +compute mygrid all sna/grid grid 6 4 2 ${snap_options} +compute mygrid all sna/grid grid 6 4 2 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 +compute mygridlocal all sna/grid/local grid ${ngridx} ${ngridy} ${ngridz} ${snap_options} +compute mygridlocal all sna/grid/local grid 6 ${ngridy} ${ngridz} ${snap_options} +compute mygridlocal all sna/grid/local grid 6 4 ${ngridz} ${snap_options} +compute mygridlocal all sna/grid/local grid 6 4 2 ${snap_options} +compute mygridlocal all sna/grid/local grid 6 4 2 4.67637 0.99363 2 0.5 1 rmin0 0 quadraticflag 0 bzeroflag 0 switchflag 1 + +# define output + +variable B5atom equal c_b[7][5] +variable B5grid equal c_mygrid[13][8] + +# do not compare x,y,z because assignment of ids +# to atoms is not unnique for different processor grids + +variable rmse_global equal "sqrt( (c_mygrid[13][4] - c_b[7][1])^2 + (c_mygrid[13][5] - c_b[7][2])^2 + (c_mygrid[13][6] - c_b[7][3])^2 + (c_mygrid[13][7] - c_b[7][4])^2 + (c_mygrid[13][8] - c_b[7][5])^2 )" + +thermo_style custom step v_B5atom v_B5grid v_rmse_global + +# this is the only way to view the local grid + +dump 1 all local 1000 dump.blocal.tri c_mygridlocal[*] +dump 2 all custom 1000 dump.batom.tri id x y z c_b[*] + +# run + +run 0 +WARNING: No fixes defined, atoms won't move (src/verlet.cpp:55) +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 6.67637 + ghost atom cutoff = 6.67637 + binsize = 3.338185, bins = 6 3 1 + 4 neighbor lists, perpetual/occasional/extra = 1 3 0 + (1) pair zero, perpetual + attributes: half, newton on + pair build: half/bin/newton/tri + stencil: half/bin/3d/tri + bin: standard + (2) compute sna/atom, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (3) compute sna/grid, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard + (4) compute sna/grid/local, occasional + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 8.405 | 8.405 | 8.405 Mbytes +Step v_B5atom v_B5grid v_rmse_global + 0 1.0427295 1.0427295 2.1052124e-14 +Loop time of 1.25e-06 on 4 procs for 0 steps with 12 atoms + +140.0% CPU use with 4 MPI tasks x no OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 1.25e-06 | | |100.00 + +Nlocal: 3.00000 ave 4 max 2 min +Histogram: 2 0 0 0 0 0 0 0 0 2 +Nghost: 459.000 ave 460 max 458 min +Histogram: 2 0 0 0 0 0 0 0 0 2 +Neighs: 96.0000 ave 128 max 64 min +Histogram: 2 0 0 0 0 0 0 0 0 2 +FullNghs: 192.000 ave 256 max 128 min +Histogram: 2 0 0 0 0 0 0 0 0 2 + +Total # of neighbors = 768 +Ave neighs/atom = 64.000000 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 From 8004f8bf0ff3a9a4920017e9f6eabe55be48c09f Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 15 Jun 2022 18:59:48 -0600 Subject: [PATCH 64/91] Removed unneeded member functions and data --- src/compute_grid.cpp | 92 ++++---------------------------------------- src/compute_grid.h | 6 +-- 2 files changed, 9 insertions(+), 89 deletions(-) diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 52bd7d6307..91d320bf63 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -28,7 +28,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), grid(nullptr), gridall(nullptr), local_flags(nullptr), gridlocal(nullptr) + Compute(lmp, narg, arg), grid(nullptr), gridall(nullptr), gridlocal(nullptr) { if (narg < 6) error->all(FLERR,"Illegal compute grid command"); @@ -77,8 +77,6 @@ void ComputeGrid::setup() set_grid_global(); set_grid_local(); allocate(); - assign_coords(); - assign_local_flags(); } /* ---------------------------------------------------------------------- @@ -101,91 +99,18 @@ void ComputeGrid::grid2x(int igrid, double *x) } -/* ---------------------------------------------------------------------- - convert global array index to box coords -------------------------------------------------------------------------- */ - -void ComputeGrid::grid2ix(int igrid, int& ix, int& iy, int& iz) -{ - iz = igrid / (nx*ny); - igrid -= iz * (nx*ny); - iy = igrid / nx; - igrid -= iy * nx; - ix = igrid; -} - -// /* ---------------------------------------------------------------------- -// check if grid point is local -// ------------------------------------------------------------------------- */ - -// int ComputeGrid::check_local(int igrid) -// { -// double x[3]; - -// int iz = igrid / (nx*ny); -// igrid -= iz * (nx*ny); -// int iy = igrid / nx; -// igrid -= iy * nx; -// int ix = igrid; - -// x[0] = ix*delx; -// x[1] = iy*dely; -// x[2] = iz*delz; - -// int islocal = -// x[0] >= sublo[0] && x[0] < subhi[0] && -// x[1] >= sublo[1] && x[1] < subhi[1] && -// x[2] >= sublo[2] && x[2] < subhi[2]; - -// return islocal; -// } - -/* ---------------------------------------------------------------------- - check if grid point is local -------------------------------------------------------------------------- */ - -int ComputeGrid::check_local(int igrid) -{ - int ix, iy, iz; - - grid2ix(igrid, ix, iy, iz); - - int islocal = - ix >= nxlo && ix <= nxhi && - iy >= nylo && iy <= nyhi && - iz >= nzlo && iz <= nzhi; - - return islocal; -} - /* ---------------------------------------------------------------------- copy coords to global array ------------------------------------------------------------------------- */ -void ComputeGrid::assign_coords() +void ComputeGrid::assign_coords_all() { double x[3]; for (int igrid = 0; igrid < ngrid; igrid++) { grid2x(igrid,x); - grid[igrid][0] = x[0]; - grid[igrid][1] = x[1]; - grid[igrid][2] = x[2]; - } -} - -/* ---------------------------------------------------------------------- - copy coords to global array -------------------------------------------------------------------------- */ - -void ComputeGrid::assign_local_flags() -{ - for (int igrid = 0; igrid < ngrid; igrid++) { - if (check_local(igrid)) - local_flags[igrid] = 1; - else { - local_flags[igrid] = 0; - memset(grid[igrid],0,size_array_cols * sizeof(double)); - } + gridall[igrid][0] = x[0]; + gridall[igrid][1] = x[1]; + gridall[igrid][2] = x[2]; } } @@ -199,7 +124,6 @@ void ComputeGrid::allocate() memory->create(grid,size_array_rows,size_array_cols,"grid:grid"); memory->create(gridall,size_array_rows,size_array_cols,"grid:gridall"); - memory->create(local_flags,size_array_rows,"grid:local_flags"); if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { gridlocal_allocated = 1; memory->create4d_offset(gridlocal,size_array_cols,nzlo,nzhi,nylo,nyhi, @@ -217,7 +141,6 @@ void ComputeGrid::deallocate() { memory->destroy(grid); memory->destroy(gridall); - memory->destroy(local_flags); if (gridlocal_allocated) { gridlocal_allocated = 0; memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); @@ -322,8 +245,9 @@ void ComputeGrid::set_grid_local() double ComputeGrid::memory_usage() { double nbytes = size_array_rows*size_array_cols * - sizeof(double); // grid - nbytes += size_array_rows*sizeof(int); // local_flags + sizeof(double); // grid + nbytes += size_array_rows*size_array_cols * + sizeof(double); // gridall nbytes += size_array_cols*ngridlocal*sizeof(double); // gridlocal return nbytes; } diff --git a/src/compute_grid.h b/src/compute_grid.h index 421656febf..ab8e5bbf9e 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -46,16 +46,12 @@ class ComputeGrid : public Compute { int nargbase; // number of base class args double cutmax; // largest cutoff distance int size_array_cols_base; // number of columns used for coords, etc. - int *local_flags; // local flag for each grid point int gridlocal_allocated; // shows if gridlocal allocated void allocate(); // create arrays void deallocate(); // free arrays void grid2x(int, double*); // convert grid point to coord - void grid2ix(int, int&, int&, int&); // convert grid point to ix, iy, iz - void assign_coords(); // assign coords for grid - void assign_local_flags(); // set local flag for each grid point - int check_local(int); // check if grid point is local + void assign_coords_all(); // assign coords for global grid void set_grid_global(); // set global grid void set_grid_local(); // set bounds for local grid private: From 9d5f4bf1e9ad7b301c152db0069383d6147f0790 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 15 Jun 2022 19:02:14 -0600 Subject: [PATCH 65/91] Updated to include switchinnerflag support, anticipating merging in the latest LAMMPS --- src/ML-SNAP/compute_sna_grid.cpp | 36 ++++++++++++++++++++++++-- src/ML-SNAP/compute_sna_grid.h | 3 +++ src/ML-SNAP/compute_sna_grid_local.cpp | 32 ++++++++++++++++++++++- src/ML-SNAP/compute_sna_grid_local.h | 3 +++ 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 2def0cf6a4..d6ebcda3ef 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -61,6 +61,7 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : chemflag = 0; bnormflag = 0; wselfallflag = 0; + switchinnerflag = 0; nelements = 1; // process required arguments @@ -92,6 +93,11 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : } } + // set local input checks + + int sinnerflag = 0; + int dinnerflag = 0; + // process optional args int iarg = nargmin; @@ -140,13 +146,37 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Illegal compute sna/grid command"); wselfallflag = atoi(arg[iarg+1]); iarg += 2; + } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute snap command"); + switchinnerflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"sinner") == 0) { + iarg++; + if (iarg+ntypes > narg) + error->all(FLERR,"Illegal compute snap command"); + memory->create(sinnerelem,ntypes+1,"snap:sinnerelem"); + for (int i = 0; i < ntypes; i++) + sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + sinnerflag = 1; + iarg += ntypes; + } else if (strcmp(arg[iarg],"dinner") == 0) { + iarg++; + if (iarg+ntypes > narg) + error->all(FLERR,"Illegal compute snap command"); + memory->create(dinnerelem,ntypes+1,"snap:dinnerelem"); + for (int i = 0; i < ntypes; i++) + dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + dinnerflag = 1; + iarg += ntypes; } else error->all(FLERR,"Illegal compute sna/grid command"); } snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, - chemflag, bnormflag, wselfallflag, nelements); + chemflag, bnormflag, wselfallflag, + nelements, switchinnerflag); ncoeff = snaptr->ncoeff; nvalues = ncoeff; @@ -287,6 +317,8 @@ void ComputeSNAGrid::compute_array() } } + memset(grid[0],0,ngrid*size_array_cols*sizeof(double)); + for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { @@ -295,7 +327,7 @@ void ComputeSNAGrid::compute_array() grid[igrid][size_array_cols_base + j] = gridlocal[size_array_cols_base + j][iz][iy][ix]; } MPI_Allreduce(&grid[0][0],&gridall[0][0],ngrid*size_array_cols,MPI_DOUBLE,MPI_SUM,world); - + assign_coords_all(); } diff --git a/src/ML-SNAP/compute_sna_grid.h b/src/ML-SNAP/compute_sna_grid.h index d40c87df9b..777b874505 100644 --- a/src/ML-SNAP/compute_sna_grid.h +++ b/src/ML-SNAP/compute_sna_grid.h @@ -42,6 +42,9 @@ class ComputeSNAGrid : public ComputeGrid { double *wjelem; int *map; // map types to [0,nelements) int nelements, chemflag; + int switchinnerflag; + double *sinnerelem; + double *dinnerelem; class SNA *snaptr; double cutmax; int quadraticflag; diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index c1574bfa26..7b26a88975 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -61,8 +61,14 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : chemflag = 0; bnormflag = 0; wselfallflag = 0; + switchinnerflag = 0; nelements = 1; + // set local input checks + + int sinnerflag = 0; + int dinnerflag = 0; + // process required arguments memory->create(radelem,ntypes+1,"sna/grid/local:radelem"); // offset by 1 to match up with types @@ -140,13 +146,37 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Illegal compute sna/grid/local command"); wselfallflag = atoi(arg[iarg+1]); iarg += 2; + } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal compute snap command"); + switchinnerflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"sinner") == 0) { + iarg++; + if (iarg+ntypes > narg) + error->all(FLERR,"Illegal compute snap command"); + memory->create(sinnerelem,ntypes+1,"snap:sinnerelem"); + for (int i = 0; i < ntypes; i++) + sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + sinnerflag = 1; + iarg += ntypes; + } else if (strcmp(arg[iarg],"dinner") == 0) { + iarg++; + if (iarg+ntypes > narg) + error->all(FLERR,"Illegal compute snap command"); + memory->create(dinnerelem,ntypes+1,"snap:dinnerelem"); + for (int i = 0; i < ntypes; i++) + dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + dinnerflag = 1; + iarg += ntypes; } else error->all(FLERR,"Illegal compute sna/grid/local command"); } snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, - chemflag, bnormflag, wselfallflag, nelements); + chemflag, bnormflag, wselfallflag, + nelements, switchinnerflag); ncoeff = snaptr->ncoeff; nvalues = ncoeff; diff --git a/src/ML-SNAP/compute_sna_grid_local.h b/src/ML-SNAP/compute_sna_grid_local.h index 21e321d123..853d629d87 100644 --- a/src/ML-SNAP/compute_sna_grid_local.h +++ b/src/ML-SNAP/compute_sna_grid_local.h @@ -42,6 +42,9 @@ class ComputeSNAGridLocal : public ComputeGridLocal { double *wjelem; int *map; // map types to [0,nelements) int nelements, chemflag; + int switchinnerflag; + double *sinnerelem; + double *dinnerelem; class SNA *snaptr; double cutmax; int quadraticflag; From 70f836e2753df19a5bcb106717d93bf66dd4cf4e Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 15 Jun 2022 19:53:37 -0600 Subject: [PATCH 66/91] Updated to latest LAMMPS --- src/ML-SNAP/compute_sna_grid.cpp | 37 +++++++++-------- src/ML-SNAP/compute_sna_grid_local.cpp | 36 +++++++++------- src/ML-SNAP/pair_sna_grid.cpp | 57 +++++++++++++++++++------- src/ML-SNAP/pair_sna_grid.h | 3 ++ 4 files changed, 88 insertions(+), 45 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index d6ebcda3ef..302e81ede2 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -148,13 +148,13 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : iarg += 2; } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snap command"); + error->all(FLERR,"Illegal compute sna/grid command"); switchinnerflag = atoi(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"sinner") == 0) { iarg++; if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute snap command"); + error->all(FLERR,"Illegal compute sna/grid command"); memory->create(sinnerelem,ntypes+1,"snap:sinnerelem"); for (int i = 0; i < ntypes; i++) sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); @@ -163,7 +163,7 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : } else if (strcmp(arg[iarg],"dinner") == 0) { iarg++; if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute snap command"); + error->all(FLERR,"Illegal compute sna/grid command"); memory->create(dinnerelem,ntypes+1,"snap:dinnerelem"); for (int i = 0; i < ntypes; i++) dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); @@ -201,20 +201,20 @@ ComputeSNAGrid::~ComputeSNAGrid() void ComputeSNAGrid::init() { - if (force->pair == nullptr) - error->all(FLERR,"Compute sna/grid requires a pair style be defined"); + // if (force->pair == nullptr) + // error->all(FLERR,"Compute sna/grid requires a pair style be defined"); - if (cutmax > force->pair->cutforce) - error->all(FLERR,"Compute sna/grid cutoff is longer than pairwise cutoff"); + // if (cutmax > force->pair->cutforce) + // error->all(FLERR,"Compute sna/grid cutoff is longer than pairwise cutoff"); - // need an occasional full neighbor list + // // need an occasional full neighbor list - int irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->pair = 0; - neighbor->requests[irequest]->compute = 1; - neighbor->requests[irequest]->half = 0; - neighbor->requests[irequest]->full = 1; - neighbor->requests[irequest]->occasional = 1; + // int irequest = neighbor->request(this,instance_me); + // neighbor->requests[irequest]->pair = 0; + // neighbor->requests[irequest]->compute = 1; + // neighbor->requests[irequest]->half = 0; + // neighbor->requests[irequest]->full = 1; + // neighbor->requests[irequest]->occasional = 1; int count = 0; for (int i = 0; i < modify->ncompute; i++) @@ -282,7 +282,8 @@ void ComputeSNAGrid::compute_array() int jtype = type[j]; int jelem = 0; if (chemflag) - jelem = map[jtype]; + jelem = map[jtype]; + if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { snaptr->rij[ninside][0] = delx; snaptr->rij[ninside][1] = dely; @@ -290,7 +291,11 @@ void ComputeSNAGrid::compute_array() snaptr->inside[ninside] = j; snaptr->wj[ninside] = wjelem[jtype]; snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; - snaptr->element[ninside] = jelem; // element index for multi-element snap + if (switchinnerflag) { + snaptr->sinnerij[ninside] = sinnerelem[jelem]; + snaptr->dinnerij[ninside] = dinnerelem[jelem]; + } + if (chemflag) snaptr->element[ninside] = jelem; ninside++; } } diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index 7b26a88975..67ac316834 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -148,13 +148,13 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : iarg += 2; } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snap command"); + error->all(FLERR,"Illegal compute sna/grid/local command"); switchinnerflag = atoi(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"sinner") == 0) { iarg++; if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute snap command"); + error->all(FLERR,"Illegal compute sna/grid/local command"); memory->create(sinnerelem,ntypes+1,"snap:sinnerelem"); for (int i = 0; i < ntypes; i++) sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); @@ -163,7 +163,7 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : } else if (strcmp(arg[iarg],"dinner") == 0) { iarg++; if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute snap command"); + error->all(FLERR,"Illegal compute sna/grid/local command"); memory->create(dinnerelem,ntypes+1,"snap:dinnerelem"); for (int i = 0; i < ntypes; i++) dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); @@ -200,20 +200,20 @@ ComputeSNAGridLocal::~ComputeSNAGridLocal() void ComputeSNAGridLocal::init() { - if (force->pair == nullptr) - error->all(FLERR,"Compute sna/grid/local requires a pair style be defined"); + // if (force->pair == nullptr) + // error->all(FLERR,"Compute sna/grid/local requires a pair style be defined"); - if (cutmax > force->pair->cutforce) - error->all(FLERR,"Compute sna/grid/local cutoff is longer than pairwise cutoff"); + // if (cutmax > force->pair->cutforce) + // error->all(FLERR,"Compute sna/grid/local cutoff is longer than pairwise cutoff"); - // need an occasional full neighbor list + // // need an occasional full neighbor list - int irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->pair = 0; - neighbor->requests[irequest]->compute = 1; - neighbor->requests[irequest]->half = 0; - neighbor->requests[irequest]->full = 1; - neighbor->requests[irequest]->occasional = 1; + // int irequest = neighbor->request(this,instance_me); + // neighbor->requests[irequest]->pair = 0; + // neighbor->requests[irequest]->compute = 1; + // neighbor->requests[irequest]->half = 0; + // neighbor->requests[irequest]->full = 1; + // neighbor->requests[irequest]->occasional = 1; int count = 0; for (int i = 0; i < modify->ncompute; i++) @@ -234,6 +234,7 @@ void ComputeSNAGridLocal::init_list(int /*id*/, NeighList *ptr) void ComputeSNAGridLocal::compute_local() { + printf("Entering compute_local()\n"); invoked_array = update->ntimestep; // compute sna for each gridpoint @@ -290,7 +291,11 @@ void ComputeSNAGridLocal::compute_local() snaptr->inside[ninside] = j; snaptr->wj[ninside] = wjelem[jtype]; snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; - snaptr->element[ninside] = jelem; // element index for multi-element snap + if (switchinnerflag) { + snaptr->sinnerij[ninside] = sinnerelem[jelem]; + snaptr->dinnerij[ninside] = dinnerelem[jelem]; + } + if (chemflag) snaptr->element[ninside] = jelem; // element index for multi-element snap ninside++; } } @@ -323,6 +328,7 @@ void ComputeSNAGridLocal::compute_local() // copy 4d array to 2d array copy_gridlocal_to_local_array(); + printf("Exiting compute_local()\n"); } diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp index 43a07b48e4..effed79ebf 100644 --- a/src/ML-SNAP/pair_sna_grid.cpp +++ b/src/ML-SNAP/pair_sna_grid.cpp @@ -59,15 +59,16 @@ void PairSNAGrid::init_style() if (force->newton_pair == 0) error->all(FLERR,"Pair style sna/grid requires newton pair on"); - // need a full neighbor list + // // need a full neighbor list - int irequest = neighbor->request(this,instance_me); - neighbor->requests[irequest]->half = 0; - neighbor->requests[irequest]->full = 1; + // int irequest = neighbor->request(this,instance_me); + // neighbor->requests[irequest]->half = 0; + // neighbor->requests[irequest]->full = 1; snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, - chemflag, bnormflag, wselfallflag, nelements); + chemflag, bnormflag, wselfallflag, + nelements, switchinnerflag); ncoeff = snaptr->ncoeff; ndesc = ndesc_base + ncoeff; snaptr->init(); @@ -213,8 +214,8 @@ void PairSNAGrid::compute(int eflag, int vflag) const double rsq = delx*delx + dely*dely + delz*delz; int jtype = type[j]; int jelem = 0; - if (chemflag) - jelem = map[jtype]; + jelem = map[jtype]; + if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { snaptr->rij[ninside][0] = delx; snaptr->rij[ninside][1] = dely; @@ -222,7 +223,11 @@ void PairSNAGrid::compute(int eflag, int vflag) snaptr->inside[ninside] = j; snaptr->wj[ninside] = wjelem[jtype]; snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; - snaptr->element[ninside] = jelem; // element index for multi-element snap + if (switchinnerflag) { + snaptr->sinnerij[ninside] = 0.5*(sinnerelem[ielem]+sinnerelem[jelem]); + snaptr->dinnerij[ninside] = 0.5*(dinnerelem[ielem]+dinnerelem[jelem]); + } + if (chemflag) snaptr->element[ninside] = jelem; ninside++; } } @@ -243,12 +248,7 @@ void PairSNAGrid::compute(int eflag, int vflag) for (int jj = 0; jj < ninside; jj++) { int j = snaptr->inside[jj]; - if (chemflag) - snaptr->compute_duidrj(snaptr->rij[jj], snaptr->wj[jj], - snaptr->rcutij[jj],jj, snaptr->element[jj]); - else - snaptr->compute_duidrj(snaptr->rij[jj], snaptr->wj[jj], - snaptr->rcutij[jj],jj, 0); + snaptr->compute_duidrj(jj); snaptr->compute_deidrj(fij); @@ -326,6 +326,7 @@ void PairSNAGrid::settings(int narg, char ** arg) chemflag = 0; bnormflag = 0; wselfallflag = 0; + switchinnerflag = 0; nelements = 1; // process required arguments @@ -357,6 +358,11 @@ void PairSNAGrid::settings(int narg, char ** arg) } } + // set local input checks + + int sinnerflag = 0; + int dinnerflag = 0; + // process optional args int iarg = nargmin; @@ -405,6 +411,29 @@ void PairSNAGrid::settings(int narg, char ** arg) error->all(FLERR,"Illegal pair sna/grid command"); wselfallflag = atoi(arg[iarg+1]); iarg += 2; + } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { + if (iarg+2 > narg) + error->all(FLERR,"Illegal pair sna/grid command"); + switchinnerflag = atoi(arg[iarg+1]); + iarg += 2; + } else if (strcmp(arg[iarg],"sinner") == 0) { + iarg++; + if (iarg+ntypes > narg) + error->all(FLERR,"Illegal pair sna/grid command"); + memory->create(sinnerelem,ntypes+1,"snap:sinnerelem"); + for (int i = 0; i < ntypes; i++) + sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + sinnerflag = 1; + iarg += ntypes; + } else if (strcmp(arg[iarg],"dinner") == 0) { + iarg++; + if (iarg+ntypes > narg) + error->all(FLERR,"Illegal pair sna/grid command"); + memory->create(dinnerelem,ntypes+1,"snap:dinnerelem"); + for (int i = 0; i < ntypes; i++) + dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + dinnerflag = 1; + iarg += ntypes; } else error->all(FLERR,"Illegal pair sna/grid command"); } diff --git a/src/ML-SNAP/pair_sna_grid.h b/src/ML-SNAP/pair_sna_grid.h index 9ae0eece79..653bb9d1c1 100644 --- a/src/ML-SNAP/pair_sna_grid.h +++ b/src/ML-SNAP/pair_sna_grid.h @@ -45,6 +45,9 @@ class PairSNAGrid : public PairGrid { int quadraticflag; int twojmax, switchflag, bzeroflag, bnormflag; int chemflag, wselfallflag; + int switchinnerflag; + double *sinnerelem; + double *dinnerelem; double rfac0, rmin0; }; From 483e3cf04996125511bcd2b5d7aa0d295fdb072e Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Wed, 15 Jun 2022 20:28:22 -0600 Subject: [PATCH 67/91] Eliminated global storage for grid/local --- src/ML-SNAP/compute_sna_grid_local.cpp | 33 +++----------- src/ML-SNAP/pair_sna_grid.cpp | 6 --- src/compute_grid_local.cpp | 63 +++++--------------------- src/compute_grid_local.h | 1 - 4 files changed, 18 insertions(+), 85 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index 67ac316834..e45a334d67 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -200,21 +200,6 @@ ComputeSNAGridLocal::~ComputeSNAGridLocal() void ComputeSNAGridLocal::init() { - // if (force->pair == nullptr) - // error->all(FLERR,"Compute sna/grid/local requires a pair style be defined"); - - // if (cutmax > force->pair->cutforce) - // error->all(FLERR,"Compute sna/grid/local cutoff is longer than pairwise cutoff"); - - // // need an occasional full neighbor list - - // int irequest = neighbor->request(this,instance_me); - // neighbor->requests[irequest]->pair = 0; - // neighbor->requests[irequest]->compute = 1; - // neighbor->requests[irequest]->half = 0; - // neighbor->requests[irequest]->full = 1; - // neighbor->requests[irequest]->occasional = 1; - int count = 0; for (int i = 0; i < modify->ncompute; i++) if (strcmp(modify->compute[i]->style,"sna/grid/local") == 0) count++; @@ -234,7 +219,6 @@ void ComputeSNAGridLocal::init_list(int /*id*/, NeighList *ptr) void ComputeSNAGridLocal::compute_local() { - printf("Entering compute_local()\n"); invoked_array = update->ntimestep; // compute sna for each gridpoint @@ -248,6 +232,7 @@ void ComputeSNAGridLocal::compute_local() snaptr->grow_rij(ntotal); + int igrid = 0; for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { @@ -307,8 +292,7 @@ void ComputeSNAGridLocal::compute_local() // linear contributions for (int icoeff = 0; icoeff < ncoeff; icoeff++) - gridlocal[size_local_cols_base+icoeff][iz][iy][ix] = - snaptr->blist[icoeff]; + alocal[igrid][size_local_cols_base+icoeff] = snaptr->blist[icoeff]; // quadratic contributions @@ -316,19 +300,14 @@ void ComputeSNAGridLocal::compute_local() int ncount = ncoeff; for (int icoeff = 0; icoeff < ncoeff; icoeff++) { double bveci = snaptr->blist[icoeff]; - gridlocal[size_local_cols_base+ncount++][iz][iy][ix] = - 0.5*bveci*bveci; + alocal[igrid][size_local_cols_base+ncount++] = 0.5*bveci*bveci; for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - gridlocal[size_local_cols_base+ncount++][iz][iy][ix] = + alocal[igrid][size_local_cols_base+ncount++] = bveci*snaptr->blist[jcoeff]; } } + igrid++; } - - // copy 4d array to 2d array - - copy_gridlocal_to_local_array(); - printf("Exiting compute_local()\n"); } @@ -340,7 +319,7 @@ double ComputeSNAGridLocal::memory_usage() { double nbytes = snaptr->memory_usage(); // SNA object int n = atom->ntypes+1; - nbytes += (double)n*sizeof(int); // map + nbytes += (double)n*sizeof(int); // map return nbytes; } diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp index effed79ebf..ffb4dfa033 100644 --- a/src/ML-SNAP/pair_sna_grid.cpp +++ b/src/ML-SNAP/pair_sna_grid.cpp @@ -59,12 +59,6 @@ void PairSNAGrid::init_style() if (force->newton_pair == 0) error->all(FLERR,"Pair style sna/grid requires newton pair on"); - // // need a full neighbor list - - // int irequest = neighbor->request(this,instance_me); - // neighbor->requests[irequest]->half = 0; - // neighbor->requests[irequest]->full = 1; - snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index 504555a718..4169d23e54 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -117,8 +117,6 @@ void ComputeGridLocal::allocate() { if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { gridlocal_allocated = 1; - memory->create4d_offset(gridlocal,size_local_cols,nzlo,nzhi,nylo,nyhi, - nxlo,nxhi,"grid:gridlocal"); memory->create(alocal, size_local_rows, size_local_cols, "compute/grid/local:alocal"); array_local = alocal; } @@ -132,7 +130,6 @@ void ComputeGridLocal::deallocate() { if (gridlocal_allocated) { gridlocal_allocated = 0; - memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); memory->destroy(alocal); } array_local = nullptr; @@ -208,19 +205,6 @@ void ComputeGridLocal::set_grid_local() zfrachi = comm->mysplit[2][1]; } - // // not fully clear why this works - // // without, sometimes get uneven assignments - // // in case where ngridz is multiple of nprocz - - // double MYEPS = 1.0e-10; - - // xfraclo += MYEPS; - // xfrachi += MYEPS; - // yfraclo += MYEPS; - // yfrachi += MYEPS; - // zfraclo += MYEPS; - // zfrachi += MYEPS; - nxlo = static_cast (xfraclo * nx); if (1.0*nxlo != xfraclo*nx) nxlo++; nxhi = static_cast (xfrachi * nx); @@ -255,27 +239,20 @@ void ComputeGridLocal::assign_coords() alocal[igrid][2] = iz; double xgrid[3]; - // For triclinic: create gridpoint in lamda coordinates and transform after check. - // For orthorombic: create gridpoint in box coordinates. + // for triclinic: create gridpoint in lamda coordinates and transform after check. + // for orthorombic: create gridpoint in box coordinates. - if (triclinic) - { - grid2lamda(ix, iy, iz, xgrid); - } - else - { - grid2x(ix, iy, iz, xgrid); - } + if (triclinic) + grid2lamda(ix, iy, iz, xgrid); + else + grid2x(ix, iy, iz, xgrid); - // Ensure gridpoint is not strictly outside subdomain. - // There have been some problem with a gridpoint being something like 2e-17 outside of the subdomain, - // thus the EPISLON check. - if ((sublo[0]-xgrid[0]) > EPSILON || (xgrid[0]-subhi[0]) > EPSILON || - (sublo[1]-xgrid[1]) > EPSILON || (xgrid[1]-subhi[1]) > EPSILON || - (sublo[2]-xgrid[2]) > EPSILON || (xgrid[2]-subhi[2]) > EPSILON) - { - error->one(FLERR,"Invalid gridpoint position in compute grid/local"); - } + // ensure gridpoint is not strictly outside subdomain + + if ((sublo[0]-xgrid[0]) > EPSILON || (xgrid[0]-subhi[0]) > EPSILON || + (sublo[1]-xgrid[1]) > EPSILON || (xgrid[1]-subhi[1]) > EPSILON || + (sublo[2]-xgrid[2]) > EPSILON || (xgrid[2]-subhi[2]) > EPSILON) + error->one(FLERR,"Invalid gridpoint position in compute grid/local"); // convert lamda to x, y, z, after sudomain check @@ -288,22 +265,6 @@ void ComputeGridLocal::assign_coords() } } -/* ---------------------------------------------------------------------- - copy the 4d gridlocal array values to the 2d local array -------------------------------------------------------------------------- */ - -void ComputeGridLocal::copy_gridlocal_to_local_array() -{ - int igrid = 0; - for (int iz = nzlo; iz <= nzhi; iz++) - for (int iy = nylo; iy <= nyhi; iy++) - for (int ix = nxlo; ix <= nxhi; ix++) { - for (int icol = size_local_cols_base; icol < size_local_cols; icol++) - alocal[igrid][icol] = gridlocal[icol][iz][iy][ix]; - igrid++; - } -} - /* ---------------------------------------------------------------------- memory usage of local data ------------------------------------------------------------------------- */ diff --git a/src/compute_grid_local.h b/src/compute_grid_local.h index 79a5ea765d..0e6e37cd35 100644 --- a/src/compute_grid_local.h +++ b/src/compute_grid_local.h @@ -53,7 +53,6 @@ class ComputeGridLocal : public Compute { void set_grid_global(); // set global grid void set_grid_local(); // set bounds for local grid void assign_coords(); // assign coords for grid - void copy_gridlocal_to_local_array();// copy 4d gridlocal array to 2d local array private: }; From e30f86c2ff31775d8dd282e157f7c056c5693505 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 16 Jun 2022 08:22:51 -0600 Subject: [PATCH 68/91] Removed a few more unnecessary member data --- src/compute_grid_local.cpp | 7 +++---- src/compute_grid_local.h | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index 4169d23e54..bcc56c3abd 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -32,7 +32,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeGridLocal::ComputeGridLocal(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), gridlocal(nullptr), alocal(nullptr) + Compute(lmp, narg, arg), alocal(nullptr) { if (narg < 6) error->all(FLERR,"Illegal compute grid/local command"); @@ -220,8 +220,7 @@ void ComputeGridLocal::set_grid_local() nzhi = static_cast (zfrachi * nz); if (1.0*nzhi == zfrachi*nz) nzhi--; - ngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); - size_local_rows = ngridlocal; + size_local_rows = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); } /* ---------------------------------------------------------------------- @@ -271,6 +270,6 @@ void ComputeGridLocal::assign_coords() double ComputeGridLocal::memory_usage() { - int nbytes = size_local_cols*ngridlocal*sizeof(double); // gridlocal + int nbytes = size_local_rows * size_local_cols * sizeof(double); // gridlocal return nbytes; } diff --git a/src/compute_grid_local.h b/src/compute_grid_local.h index 0e6e37cd35..15ea8ca47f 100644 --- a/src/compute_grid_local.h +++ b/src/compute_grid_local.h @@ -32,9 +32,7 @@ class ComputeGridLocal : public Compute { protected: int nx, ny, nz; // global grid dimensions int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive - int ngridlocal; // number of local grid points int nvalues; // number of values per grid point - double ****gridlocal; // local grid, redundant w.r.t. alocal double **alocal; // pointer to Compute::array_local int triclinic; // triclinic flag double *boxlo, *prd; // box info (units real/ortho or reduced/tri) From 535a5211fc60dcd9571596ac1403c8f1f91fa6d9 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 16 Jun 2022 10:33:54 -0600 Subject: [PATCH 69/91] More cleanup --- src/ML-SNAP/compute_sna_grid.cpp | 23 ++++++++--------------- src/ML-SNAP/compute_sna_grid_local.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 302e81ede2..e96b54e7ed 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -173,6 +173,12 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : } + if (switchinnerflag && !(sinnerflag && dinnerflag)) + error->all(FLERR,"Illegal compute sna/grid command: switchinnerflag = 1, missing sinner/dinner keyword"); + + if (!switchinnerflag && (sinnerflag || dinnerflag)) + error->all(FLERR,"Illegal compute sna/grid command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, @@ -201,21 +207,6 @@ ComputeSNAGrid::~ComputeSNAGrid() void ComputeSNAGrid::init() { - // if (force->pair == nullptr) - // error->all(FLERR,"Compute sna/grid requires a pair style be defined"); - - // if (cutmax > force->pair->cutforce) - // error->all(FLERR,"Compute sna/grid cutoff is longer than pairwise cutoff"); - - // // need an occasional full neighbor list - - // int irequest = neighbor->request(this,instance_me); - // neighbor->requests[irequest]->pair = 0; - // neighbor->requests[irequest]->compute = 1; - // neighbor->requests[irequest]->half = 0; - // neighbor->requests[irequest]->full = 1; - // neighbor->requests[irequest]->occasional = 1; - int count = 0; for (int i = 0; i < modify->ncompute; i++) if (strcmp(modify->compute[i]->style,"sna/grid") == 0) count++; @@ -284,6 +275,8 @@ void ComputeSNAGrid::compute_array() if (chemflag) jelem = map[jtype]; + // printf("jtype = %d cutsq[jtype][jtype] = %g\n", + // jtype, cutsq[jtype][jtype]); if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { snaptr->rij[ninside][0] = delx; snaptr->rij[ninside][1] = dely; diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index e45a334d67..1dacc28617 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -173,6 +173,12 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : } + if (switchinnerflag && !(sinnerflag && dinnerflag)) + error->all(FLERR,"Illegal compute sna/grid/local command: switchinnerflag = 1, missing sinner/dinner keyword"); + + if (!switchinnerflag && (sinnerflag || dinnerflag)) + error->all(FLERR,"Illegal compute sna/grid/local command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, From f12e8f932afb32cc462e71f21dbe336578110c98 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 16 Jun 2022 18:20:46 -0600 Subject: [PATCH 70/91] Eliminated problem with unassigned coordinates in grid array --- src/ML-SNAP/compute_sna_grid.cpp | 14 +++++++------- src/compute_grid.cpp | 7 ++++--- src/compute_grid.h | 1 - 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index e96b54e7ed..1d868ba769 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -242,10 +242,12 @@ void ComputeSNAGrid::compute_array() for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { + double xgrid[3]; const int igrid = iz*(nx*ny) + iy*nx + ix; - const double xtmp = grid[igrid][0]; - const double ytmp = grid[igrid][1]; - const double ztmp = grid[igrid][2]; + grid2x(igrid, xgrid); + const double xtmp = xgrid[0]; + const double ytmp = xgrid[1]; + const double ztmp = xgrid[2]; // currently, all grid points are type 1 @@ -275,8 +277,6 @@ void ComputeSNAGrid::compute_array() if (chemflag) jelem = map[jtype]; - // printf("jtype = %d cutsq[jtype][jtype] = %g\n", - // jtype, cutsq[jtype][jtype]); if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { snaptr->rij[ninside][0] = delx; snaptr->rij[ninside][1] = dely; @@ -315,7 +315,7 @@ void ComputeSNAGrid::compute_array() } } - memset(grid[0],0,ngrid*size_array_cols*sizeof(double)); + memset(&grid[0][0],0,size_array_rows*size_array_cols*sizeof(double)); for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) @@ -324,7 +324,7 @@ void ComputeSNAGrid::compute_array() for (int j = 0; j < nvalues; j++) grid[igrid][size_array_cols_base + j] = gridlocal[size_array_cols_base + j][iz][iy][ix]; } - MPI_Allreduce(&grid[0][0],&gridall[0][0],ngrid*size_array_cols,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&grid[0][0],&gridall[0][0],size_array_rows*size_array_cols,MPI_DOUBLE,MPI_SUM,world); assign_coords_all(); } diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 91d320bf63..dd21b731e8 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -51,7 +51,7 @@ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : nargbase = iarg - iarg0; - size_array_rows = ngrid = nx*ny*nz; + size_array_rows = nx*ny*nz; size_array_cols_base = 3; gridlocal_allocated = 0; } @@ -106,7 +106,7 @@ void ComputeGrid::grid2x(int igrid, double *x) void ComputeGrid::assign_coords_all() { double x[3]; - for (int igrid = 0; igrid < ngrid; igrid++) { + for (int igrid = 0; igrid < size_array_rows; igrid++) { grid2x(igrid,x); gridall[igrid][0] = x[0]; gridall[igrid][1] = x[1]; @@ -122,12 +122,13 @@ void ComputeGrid::allocate() { // allocate arrays + printf("In allocate() %d %d \n", size_array_rows,size_array_cols); memory->create(grid,size_array_rows,size_array_cols,"grid:grid"); memory->create(gridall,size_array_rows,size_array_cols,"grid:gridall"); if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { gridlocal_allocated = 1; memory->create4d_offset(gridlocal,size_array_cols,nzlo,nzhi,nylo,nyhi, - nxlo,nxhi,"grid:gridlocal"); + nxlo,nxhi,"grid:gridlocal"); } array = gridall; } diff --git a/src/compute_grid.h b/src/compute_grid.h index ab8e5bbf9e..7bda1a89fa 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -32,7 +32,6 @@ class ComputeGrid : public Compute { protected: int nx, ny, nz; // global grid dimensions int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive - int ngrid; // number of global grid points int ngridlocal; // number of local grid points int nvalues; // number of values per grid point double **grid; // global grid From a7c5b5e8fd152f5abe064451b4371a9695834095 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 16 Jun 2022 20:22:40 -0600 Subject: [PATCH 71/91] Finsished documentation --- doc/src/Commands_compute.rst | 2 + doc/src/Errors_warnings.rst | 6 + doc/src/Packages_details.rst | 2 + doc/src/compute.rst | 2 + doc/src/compute_sna_atom.rst | 300 +++++++++++++++++++- doc/utils/sphinx-config/false_positives.txt | 3 + src/ML-SNAP/compute_sna_grid.h | 6 - src/ML-SNAP/compute_sna_grid_local.h | 8 - 8 files changed, 311 insertions(+), 18 deletions(-) diff --git a/doc/src/Commands_compute.rst b/doc/src/Commands_compute.rst index 61c5e83eda..bb0c3e9c2a 100644 --- a/doc/src/Commands_compute.rst +++ b/doc/src/Commands_compute.rst @@ -138,6 +138,8 @@ KOKKOS, o = OPENMP, t = OPT. * :doc:`smd/vol ` * :doc:`snap ` * :doc:`sna/atom ` + * :doc:`sna/grid ` + * :doc:`sna/grid/local ` * :doc:`snad/atom ` * :doc:`snav/atom ` * :doc:`sph/e/atom ` diff --git a/doc/src/Errors_warnings.rst b/doc/src/Errors_warnings.rst index 2d588a1b77..ab06ac523c 100644 --- a/doc/src/Errors_warnings.rst +++ b/doc/src/Errors_warnings.rst @@ -470,6 +470,12 @@ This will most likely cause errors in kinetic fluctuations. *More than one compute sna/atom* Self-explanatory. +*More than one compute sna/grid* + Self-explanatory. + +*More than one compute sna/grid/local* + Self-explanatory. + *More than one compute snad/atom* Self-explanatory. diff --git a/doc/src/Packages_details.rst b/doc/src/Packages_details.rst index aaac06a4a8..92a4cab46b 100644 --- a/doc/src/Packages_details.rst +++ b/doc/src/Packages_details.rst @@ -1801,6 +1801,8 @@ computes which analyze attributes of the potential. * src/ML-SNAP: filenames -> commands * :doc:`pair_style snap ` * :doc:`compute sna/atom ` +* :doc:`compute sna/grid ` +* :doc:`compute sna/grid/local ` * :doc:`compute snad/atom ` * :doc:`compute snav/atom ` * examples/snap diff --git a/doc/src/compute.rst b/doc/src/compute.rst index 6fdedbbb95..cf17433035 100644 --- a/doc/src/compute.rst +++ b/doc/src/compute.rst @@ -284,6 +284,8 @@ The individual style names on the :doc:`Commands compute ` pag * :doc:`smd/vol ` - per-particle volumes and their sum in Smooth Mach Dynamics * :doc:`snap ` - gradients of SNAP energy and forces w.r.t. linear coefficients and related quantities for fitting SNAP potentials * :doc:`sna/atom ` - bispectrum components for each atom +* :doc:`sna/grid ` - global array of bispectrum components on a regular grid +* :doc:`sna/grid/local ` - local array of bispectrum components on a regular grid * :doc:`snad/atom ` - derivative of bispectrum components for each atom * :doc:`snav/atom ` - virial contribution from bispectrum components for each atom * :doc:`sph/e/atom ` - per-atom internal energy of Smooth-Particle Hydrodynamics atoms diff --git a/doc/src/compute_sna_atom.rst b/doc/src/compute_sna_atom.rst index 54a6df02a2..2bbee1e6b6 100644 --- a/doc/src/compute_sna_atom.rst +++ b/doc/src/compute_sna_atom.rst @@ -24,6 +24,9 @@ Syntax compute ID group-ID snad/atom rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ... compute ID group-ID snav/atom rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ... compute ID group-ID snap rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ... + compute ID group-ID snap rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ... + compute ID group-ID sna/grid nx ny nz rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ... + compute ID group-ID sna/grid/local nx ny nz rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ... * ID, group-ID are documented in :doc:`compute ` command * sna/atom = style name of this compute command @@ -32,6 +35,7 @@ Syntax * twojmax = band limit for bispectrum components (non-negative integer) * R_1, R_2,... = list of cutoff radii, one for each type (distance units) * w_1, w_2,... = list of neighbor weights, one for each type +* nx, ny, nz = number of grid points in x, y, and z directions (positive integer) * zero or more keyword/value pairs may be appended * keyword = *rmin0* or *switchflag* or *bzeroflag* or *quadraticflag* or *chem* or *bnormflag* or *wselfallflag* or *bikflag* or *switchinnerflag* or *sinner* or *dinner* @@ -78,6 +82,7 @@ Examples compute snap all snap 1.4 0.95 6 2.0 1.0 compute snap all snap 1.0 0.99363 6 3.81 3.83 1.0 0.93 chem 2 0 1 compute snap all snap 1.0 0.99363 6 3.81 3.83 1.0 0.93 switchinnerflag 1 sinner 1.35 1.6 dinner 0.25 0.3 + compute bgrid all sna/grid/local 200 200 200 1.4 0.95 6 2.0 1.0 Description """"""""""" @@ -212,6 +217,46 @@ command: See section below on output for a detailed explanation of the data layout in the global array. +The compute *sna/grid* and *sna/grid/local* commands calculate +bispectrum components for a regular grid of points. +These are calculated from the local density of nearby atoms *i'* +around each grid point, as if there was a central atom *i* +at the grid point. This is useful for characterizing fine-scale +structure in a configuration of atoms, and it has been used +to build a machine-learning surrogate for finite-temperature Kohn-Sham +density functional theory (:ref:`Ellis et al. `). +Neighbor atoms not in the group do not contribute to the +bispectrum components of the grid points. The distance cutoff :math:`R_{ii'}` +and other parameters are defined as for a central atom with the same type as the +neighbor atoms *i'*. + +Compute *sna/grid* calculates a global array containing bispectrum +components for a regular grid of points. +The grid is aligned with the current box dimensions, with the +first point at the box origin, and forming a regular 3d array with +*nx*, *ny*, and *nz* points in the x, y, and z directions. For triclinic +boxes, the array is congruent with the periodic lattice vectors +a, b, and c. The array contains one row for each of the +:math:`nx \times ny \times nz` grid points, looping over the index for *ix* fastest, +then *iy*, and *iz* slowest. Each row of the array contains the *x*, *y*, +and *z* coordinates of the grid point, followed by the bispectrum +components. See section below on output for a detailed explanation of the data +layout in the global array. + +Compute *sna/grid/local* calculates bispectrum components of a regular +grid of points similarly to compute *sna/grid* described above. +However, because the array is local, it contains only rows for grid points +that are local to the processor subdomain. The global grid +of :math:`nx \times ny \times nz` points is still laid out in space the same as for *sna/grid*, +but grid points are strictly partitioned, so that every grid point appears in +one and only one local array. The array contains one row for each of the +local grid points, looping over the global index *ix* fastest, +then *iy*, and *iz* slowest. Each row of the array contains +the global indexes *ix*, *iy*, and *iz* first, followed by the *x*, *y*, +and *z* coordinates of the grid point, followed by the bispectrum +components. See section below on output for a detailed explanation of the data +layout in the global array. + The value of all bispectrum components will be zero for atoms not in the group. Neighbor atoms not in the group do not contribute to the bispectrum of atoms in the group. @@ -441,6 +486,250 @@ page for an overview of LAMMPS output options. To see how this command can be used within a Python workflow to train SNAP potentials, see the examples in `FitSNAP `_. +The value of all bispectrum components will be zero for atoms not in +the group. Neighbor atoms not in the group do not contribute to the +bispectrum of atoms in the group. + +The neighbor list needed to compute this quantity is constructed each +time the calculation is performed (i.e. each time a snapshot of atoms +is dumped). Thus it can be inefficient to compute/dump this quantity +too frequently. + +The argument *rcutfac* is a scale factor that controls the ratio of +atomic radius to radial cutoff distance. + +The argument *rfac0* and the optional keyword *rmin0* define the +linear mapping from radial distance to polar angle :math:`theta_0` on the +3-sphere, given above. + +The argument *twojmax* defines which +bispectrum components are generated. See section below on output for a +detailed explanation of the number of bispectrum components and the +ordered in which they are listed. + +The keyword *switchflag* can be used to turn off the switching +function :math:`f_c(r)`. + +The keyword *bzeroflag* determines whether or not *B0*, the bispectrum +components of an atom with no neighbors, are subtracted from the +calculated bispectrum components. This optional keyword normally only +affects compute *sna/atom*\ . However, when *quadraticflag* is on, it +also affects *snad/atom* and *snav/atom*\ . + +The keyword *quadraticflag* determines whether or not the quadratic +combinations of bispectrum quantities are generated. These are formed +by taking the outer product of the vector of bispectrum components with +itself. See section below on output for a detailed explanation of the +number of quadratic terms and the ordered in which they are listed. + +The keyword *chem* activates the explicit multi-element variant of the +SNAP bispectrum components. The argument *nelements* specifies the +number of SNAP elements that will be handled. This is followed by +*elementlist*, a list of integers of length *ntypes*, with values in the +range [0, *nelements* ), which maps each LAMMPS type to one of the SNAP +elements. Note that multiple LAMMPS types can be mapped to the same +element, and some elements may be mapped by no LAMMPS type. However, in +typical use cases (training SNAP potentials) the mapping from LAMMPS +types to elements is one-to-one. + +The explicit multi-element variant invoked by the *chem* keyword +partitions the density of neighbors into partial densities for each +chemical element. This is described in detail in the paper by +:ref:`Cusentino et al. ` The bispectrum components are +indexed on ordered triplets of elements: + +.. math:: + + B_{j_1,j_2,j}^{\kappa\lambda\mu} = + \sum_{m_1,m'_1=-j_1}^{j_1}\sum_{m_2,m'_2=-j_2}^{j_2}\sum_{m,m'=-j}^{j} (u^{\mu}_{j,m,m'})^* + H {\scriptscriptstyle \begin{array}{l} {j} {m} {m'} \\ + {j_1} {m_1} {m'_1} \\ + {j_2} {m_2} {m'_2} \end{array}} + u^{\kappa}_{j_1,m_1,m'_1} u^{\lambda}_{j_2,m_2,m'_2} + +where :math:`u^{\mu}_{j,m,m'}` is an expansion coefficient for the partial density of neighbors +of element :math:`\mu` + +.. math:: + + u^{\mu}_{j,m,m'} = w^{self}_{\mu_{i}\mu} U^{j,m,m'}(0,0,0) + \sum_{r_{ii'} < R_{ii'}}{\delta_{\mu\mu_{i'}}f_c(r_{ii'}) w_{\mu_{i'}} U^{j,m,m'}(\theta_0,\theta,\phi)} + +where :math:`w^{self}_{\mu_{i}\mu}` is the self-contribution, which is +either 1 or 0 (see keyword *wselfallflag* below), +:math:`\delta_{\mu\mu_{i'}}` indicates that the sum is only over +neighbor atoms of element :math:`\mu`, and all other quantities are the +same as those appearing in the original equation for :math:`u^j_{m,m'}` +given above. + +The keyword *wselfallflag* defines the rule used for the +self-contribution. If *wselfallflag* is on, then +:math:`w^{self}_{\mu_{i}\mu}` = 1. If it is off then +:math:`w^{self}_{\mu_{i}\mu}` = 0, except in the case of +:math:`{\mu_{i}=\mu}`, when :math:`w^{self}_{\mu_{i}\mu}` = 1. When the +*chem* keyword is not used, this keyword has no effect. + +The keyword *bnormflag* determines whether or not the bispectrum +component :math:`B_{j_1,j_2,j}` is divided by a factor of :math:`2j+1`. +This normalization simplifies force calculations because of the +following symmetry relation + +.. math:: + + \frac{B_{j_1,j_2,j}}{2j+1} = \frac{B_{j,j_2,j_1}}{2j_1+1} = \frac{B_{j_1,j,j_2}}{2j_2+1} + +This option is typically used in conjunction with the *chem* keyword, +and LAMMPS will generate a warning if both *chem* and *bnormflag* +are not both set or not both unset. + +The keyword *bikflag* determines whether or not to expand the bispectrum +rows of the global array returned by compute snap. If *bikflag* is set +to *1* then the bispectrum row, which is typically the per-atom bispectrum +descriptors :math:`B_{i,k}` summed over all atoms *i* to produce +:math:`B_k`, becomes bispectrum rows equal to the number of atoms. Thus, +the resulting bispectrum rows are :math:`B_{i,k}` instead of just +:math:`B_k`. In this case, the entries in the final column for these rows +are set to zero. + +The keyword *switchinnerflag* with value 1 +activates an additional radial switching +function similar to :math:`f_c(r)` above, but acting to switch off +smoothly contributions from neighbor atoms at short separation distances. +This is useful when SNAP is used in combination with a simple +repulsive potential. For a neighbor atom at +distance :math:`r`, its contribution is scaled by a multiplicative +factor :math:`f_{inner}(r)` defined as follows: + +.. math:: + + = & 0, r \leq S_{inner} - D_{inner} \\ + f_{inner}(r) = & \frac{1}{2}(1 - \cos(\frac{\pi}{2} (1 + \frac{r-S_{inner}}{D_{inner}})), S_{inner} - D_{inner} < r \leq S_{inner} + D_{inner} \\ + = & 1, r > S_{inner} + D_{inner} + +where the switching region is centered at :math:`S_{inner}` and it extends a distance :math:`D_{inner}` +to the left and to the right of this. +With this option, additional keywords *sinner* and *dinner* must be used, +each followed by *ntypes* +values for :math:`S_{inner}` and :math:`D_{inner}`, respectively. +When the central atom and the neighbor atom have different types, +the values of :math:`S_{inner}` and :math:`D_{inner}` are +the arithmetic means of the values for both types. + +.. note:: + + If you have a bonded system, then the settings of :doc:`special_bonds + ` command can remove pairwise interactions between + atoms in the same bond, angle, or dihedral. This is the default + setting for the :doc:`special_bonds ` command, and + means those pairwise interactions do not appear in the neighbor list. + Because this fix uses the neighbor list, it also means those pairs + will not be included in the calculation. One way to get around this, + is to write a dump file, and use the :doc:`rerun ` command to + compute the bispectrum components for snapshots in the dump file. + The rerun script can use a :doc:`special_bonds ` + command that includes all pairs in the neighbor list. + +---------- + +Output info +""""""""""" + +Compute *sna/atom* calculates a per-atom array, each column +corresponding to a particular bispectrum component. The total number of +columns and the identity of the bispectrum component contained in each +column depend of the value of *twojmax*, as described by the following +piece of python code: + +.. parsed-literal:: + + for j1 in range(0,twojmax+1): + for j2 in range(0,j1+1): + for j in range(j1-j2,min(twojmax,j1+j2)+1,2): + if (j>=j1): print j1/2.,j2/2.,j/2. + +For even twojmax = 2(*m*\ -1), :math:`K = m(m+1)(2m+1)/6`, the *m*\ -th pyramidal number. For odd twojmax = 2 *m*\ -1, :math:`K = m(m+1)(m+2)/3`, twice the *m*\ -th tetrahedral number. + +.. note:: + + the *diagonal* keyword allowing other possible choices + for the number of bispectrum components was removed in 2019, + since all potentials use the value of 3, corresponding to the + above set of bispectrum components. + +Compute *snad/atom* evaluates a per-atom array. The columns are arranged +into *ntypes* blocks, listed in order of atom type *I*\ . Each block +contains three sub-blocks corresponding to the *x*, *y*, and *z* +components of the atom position. Each of these sub-blocks contains *K* +columns for the *K* bispectrum components, the same as for compute +*sna/atom* + +Compute *snav/atom* evaluates a per-atom array. The columns are arranged +into *ntypes* blocks, listed in order of atom type *I*\ . Each block +contains six sub-blocks corresponding to the *xx*, *yy*, *zz*, +*yz*, *xz*, and *xy* components of the virial tensor in Voigt +notation. Each of these sub-blocks contains *K* columns for the *K* +bispectrum components, the same as for compute *sna/atom* + +Compute *snap* evaluates a global array. The columns are arranged into +*ntypes* blocks, listed in order of atom type *I*\ . Each block contains +one column for each bispectrum component, the same as for compute +*sna/atom*\ . A final column contains the corresponding energy, force +component on an atom, or virial stress component. The rows of the array +appear in the following order: + +* 1 row: *sna/atom* quantities summed for all atoms of type *I* +* 3\*\ *N* rows: *snad/atom* quantities, with derivatives w.r.t. x, y, and z coordinate of atom *i* appearing in consecutive rows. The atoms are sorted based on atom ID. +* 6 rows: *snav/atom* quantities summed for all atoms of type *I* + +For example, if *K* =30 and ntypes=1, the number of columns in the +per-atom arrays generated by *sna/atom*, *snad/atom*, and +*snav/atom* are 30, 90, and 180, respectively. With *quadratic* value=1, +the numbers of columns are 930, 2790, and 5580, respectively. The +number of columns in the global array generated by *snap* are 31, and +931, respectively, while the number of rows is 1+3\*\ *N*\ +6, where *N* +is the total number of atoms. + +If the *quadratic* keyword value is set to 1, then additional columns +are generated, corresponding to the products of all distinct pairs of +bispectrum components. If the number of bispectrum components is *K*, +then the number of distinct pairs is *K*\ (\ *K*\ +1)/2. For compute +*sna/atom* these columns are appended to existing *K* columns. The +ordering of quadratic terms is upper-triangular, (1,1),(1,2)...(1,\ *K*\ +),(2,1)...(\ *K*\ -1,\ *K*\ -1),(\ *K*\ -1,\ *K*\ ),(\ *K*,\ *K*\ ). +For computes *snad/atom* and *snav/atom* each set of *K*\ (\ *K*\ +1)/2 +additional columns is inserted directly after each of sub-block of +linear terms i.e. linear and quadratic terms are contiguous. So the +nesting order from inside to outside is bispectrum component, linear +then quadratic, vector/tensor component, type. + +If the *chem* keyword is used, then the data is arranged into +:math:`N_{elem}^3` sub-blocks, each sub-block corresponding to a +particular chemical labeling :math:`\kappa\lambda\mu` with the last +label changing fastest. Each sub-block contains *K* bispectrum +components. For the purposes of handling contributions to force, virial, +and quadratic combinations, these :math:`N_{elem}^3` sub-blocks are +treated as a single block of :math:`K N_{elem}^3` columns. + +These values can be accessed by any command that uses per-atom values +from a compute as input. See the :doc:`Howto output ` doc +page for an overview of LAMMPS output options. To see how this command +can be used within a Python workflow to train SNAP potentials, see the +examples in `FitSNAP `_. + +Compute *sna/grid* evaluates a global array. +The array contains one row for each of the +:math:`nx \times ny \times nz` grid points, looping over the index for *ix* fastest, +then *iy*, and *iz* slowest. Each row of the array contains the *x*, *y*, +and *z* coordinates of the grid point, followed by the bispectrum +components. + +Compute *sna/grid/local* evaluates a local array. +The array contains one row for each of the +local grid points, looping over the global index *ix* fastest, +then *iy*, and *iz* slowest. Each row of the array contains +the global indexes *ix*, *iy*, and *iz* first, followed by the *x*, *y*, +and *z* coordinates of the grid point, followed by the bispectrum +components. + Restrictions """""""""""" @@ -464,9 +753,8 @@ The optional keyword defaults are *rmin0* = 0, .. _Thompson20141: -**(Thompson)** Thompson, Swiler, Trott, Foiles, Tucker, under review, preprint -available at `arXiv:1409.3880 `_ - +**(Thompson)** Thompson, Swiler, Trott, Foiles, Tucker, J Comp Phys, 285, 316, (2015). + .. _Bartok20101: **(Bartok)** Bartok, Payne, Risi, Csanyi, Phys Rev Lett, 104, 136403 (2010). @@ -486,4 +774,8 @@ of Angular Momentum, World Scientific, Singapore (1987). .. _Cusentino2020: -**(Cusentino)** Cusentino, Wood, and Thompson, J Phys Chem A, xxx, xxxxx, (2020) +**(Cusentino)** Cusentino, Wood, Thompson, J Phys Chem A, 124, 5456, (2020) + +.. _Ellis2021: + +**(Ellis)** Ellis, Fiedler, Popoola, Modine, Stephens, Thompson, Cangi, Rajamanickam, Phys Rev B, 104, 035120, (2021) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 836dc4efa8..21f4549441 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -372,6 +372,7 @@ Caltech Camilloni Camiloni Campana +Cangi Cao Capolungo Caro @@ -2676,6 +2677,7 @@ polyhedra Polym polymorphism popen +Popoola Popov popstore Poresag @@ -2819,6 +2821,7 @@ radians Rafferty rahman Rahman +Rajamanickam Ralf Raman ramped diff --git a/src/ML-SNAP/compute_sna_grid.h b/src/ML-SNAP/compute_sna_grid.h index 777b874505..c203ce8bb4 100644 --- a/src/ML-SNAP/compute_sna_grid.h +++ b/src/ML-SNAP/compute_sna_grid.h @@ -63,12 +63,6 @@ Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. -E: Compute sna/grid requires a pair style be defined - -Self-explanatory. - -E: Compute sna/grid cutoff is longer than pairwise cutoff - Self-explanatory. W: More than one compute sna/grid diff --git a/src/ML-SNAP/compute_sna_grid_local.h b/src/ML-SNAP/compute_sna_grid_local.h index 853d629d87..5ce40069ee 100644 --- a/src/ML-SNAP/compute_sna_grid_local.h +++ b/src/ML-SNAP/compute_sna_grid_local.h @@ -63,14 +63,6 @@ Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. -E: Compute sna/grid/local requires a pair style be defined - -Self-explanatory. - -E: Compute sna/grid/local cutoff is longer than pairwise cutoff - -Self-explanatory. - W: More than one compute sna/grid/local Self-explanatory. From e201d6e77e9ce45250a1caf5e4a44301cb3ab2a0 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 16 Jun 2022 20:31:06 -0600 Subject: [PATCH 72/91] Delete files --- examples/snap/README.grid | 19 -- examples/snap/econs.py | 16 - examples/snap/fnum.py | 14 - examples/snap/grid.local.py | 121 -------- examples/snap/grid.py | 104 ------- examples/snap/in.fnum | 61 ---- examples/snap/in.grid | 83 ------ examples/snap/in.grid.local | 77 ----- examples/snap/in.grid.pair | 90 ------ examples/snap/in.grid.python | 65 ----- examples/snap/in.grid.python.local | 69 ----- examples/snap/in.grid.test | 105 ------- examples/snap/lammps_utils.py | 26 -- src/ML-SNAP/pair_sna_grid.cpp | 449 ----------------------------- src/ML-SNAP/pair_sna_grid.h | 79 ----- src/pair_grid.cpp | 328 --------------------- src/pair_grid.h | 87 ------ 17 files changed, 1793 deletions(-) delete mode 100644 examples/snap/README.grid delete mode 100644 examples/snap/econs.py delete mode 100644 examples/snap/fnum.py delete mode 100755 examples/snap/grid.local.py delete mode 100755 examples/snap/grid.py delete mode 100644 examples/snap/in.fnum delete mode 100644 examples/snap/in.grid delete mode 100644 examples/snap/in.grid.local delete mode 100644 examples/snap/in.grid.pair delete mode 100644 examples/snap/in.grid.python delete mode 100644 examples/snap/in.grid.python.local delete mode 100644 examples/snap/in.grid.test delete mode 100644 examples/snap/lammps_utils.py delete mode 100644 src/ML-SNAP/pair_sna_grid.cpp delete mode 100644 src/ML-SNAP/pair_sna_grid.h delete mode 100644 src/pair_grid.cpp delete mode 100644 src/pair_grid.h diff --git a/examples/snap/README.grid b/examples/snap/README.grid deleted file mode 100644 index a552ce38ab..0000000000 --- a/examples/snap/README.grid +++ /dev/null @@ -1,19 +0,0 @@ -This branch contains the following examples: - -in.grid # simple example of grid -in.grid.local # simple example of grid/local -in.grid.python # used by grid.py -in.grid.test # stress test of grid and grid/local -in.grid.tri # grid with triclinic cell - -grid.py # access data from Python library interface - -For the LAMMPS public repo, the only examples that will be provided are: - - in.grid.snap # simple test of grid and grid/local - in.grid.tri # same for a triclinic box - log.15Jun22.grid.snap.g++.1 - log.15Jun22.grid.snap.g++.4 - log.15Jun22.grid.tri.g++.1 - log.15Jun22.grid.tri.g++.4 - diff --git a/examples/snap/econs.py b/examples/snap/econs.py deleted file mode 100644 index aece097622..0000000000 --- a/examples/snap/econs.py +++ /dev/null @@ -1,16 +0,0 @@ -import lammps - -infile = "in.grid.pair" -faclist = [0.001,0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5] - -print("# Timestep DeltaE DeltaE/Timestep^2") -for fac in faclist: - cmdlist = ["-screen","none","-var","dtfac", "%g" % fac] - lmp = lammps.lammps(cmdargs = cmdlist) - lmp.file(infile) - dt = lmp.extract_global("dt", lammps.LAMMPS_DOUBLE) - de = lmp.extract_fix("avede", lammps.LMP_STYLE_GLOBAL, lammps.LMP_TYPE_SCALAR) - dedt2 = de/dt**2 - print(f"{dt} {de} {dedt2}") - - diff --git a/examples/snap/fnum.py b/examples/snap/fnum.py deleted file mode 100644 index 1e50e49b09..0000000000 --- a/examples/snap/fnum.py +++ /dev/null @@ -1,14 +0,0 @@ -import lammps - -infile = "in.fnum" - -fdeltalist = [1.0e-2,1.0e-3,1.0e-4,1.0e-5,1.0e-6,1.0e-7,1.0e-8,1.0e-9,1.0e-10] - -print("Fdelta RMSE") -for fdelta in fdeltalist: - cmdlist = ["-screen","none","-var","fdelta",f'{fdelta}'] - lmp = lammps.lammps(cmdargs = cmdlist) - lmp.file(infile) - faverrsq = lmp.extract_compute("faverrsq", lammps.LMP_STYLE_GLOBAL, lammps.LMP_TYPE_SCALAR) - rmse = faverrsq**0.5 - print(f"{fdelta} {rmse}") diff --git a/examples/snap/grid.local.py b/examples/snap/grid.local.py deleted file mode 100755 index 414558b79b..0000000000 --- a/examples/snap/grid.local.py +++ /dev/null @@ -1,121 +0,0 @@ -#!/Users/athomps/miniconda3/bin/python3.7 -# -# An example of SNAP grid from LAMMPS Python interface -# -# https://lammps.sandia.gov/doc/Python_library.html - - -from lammps import lammps, LMP_STYLE_LOCAL, LMP_SIZE_ROWS, LMP_SIZE_COLS, LMP_TYPE_ARRAY -import lammps_utils - -from mpi4py import MPI -comm = MPI.COMM_WORLD -me = comm.Get_rank() -nprocs = comm.Get_size() - -# define command line input variables - -ngridx = 2 -ngridy = 3 -ngridz = nprocs -twojmax = 2 - -lmp_cmdargs = ["-echo","screen"] -lmp_cmdargs = lammps_utils.set_cmdlinevars(lmp_cmdargs, - { - "ngridx":ngridx, - "ngridy":ngridy, - "ngridz":ngridz, - "twojmax":twojmax - } - ) - -# launch LAMMPS instance - -lmp = lammps(cmdargs=lmp_cmdargs) - -# run LAMMPS input script - -lmp.file("in.grid.python.local") - -# get quantities from LAMMPS - -num_atoms = lmp.get_natoms() - -# set things not accessible from LAMMPS - -# first 3 cols are x, y, z, coords - -ncols0 = 3 - -# analytical relation - -ncoeff = (twojmax+2)*(twojmax+3)*(twojmax+4) -ncoeff = ncoeff // 24 # integer division -ncols = ncols0+ncoeff - -# get B_0 at position (0,0,0) in 4 different ways - -# 1. from comute sna/atom - -bptr = lmp.extract_compute("b", 1, 2) # 1 = per-atom data, 2 = array -print("b = ",bptr[0][0]) - -# 2. from compute sna/grid - -bgridptr = lmp.extract_compute("bgrid", 0, 2) # 0 = style global, 2 = type array -print("bgrid = ",bgridptr[0][3]) - -# 3. from Numpy array pointing to sna/atom array - -bptr_np = lammps_utils.extract_compute_np(lmp,"b",1,2,(num_atoms,ncoeff)) -print("b_np = ",bptr_np[0][0]) - -# 4. from Numpy array pointing to sna/grid array - -bgridptr_np = lammps_utils.extract_compute_np(lmp,"bgrid",0,2,(ngridz,ngridy,ngridx,ncols)) -print("bgrid_np = ",bgridptr_np[0][0][0][ncols0+0]) - -# 5. from sna/grid/local array - -bgridlocalnrows = lmp.extract_compute("bgridlocal", LMP_STYLE_LOCAL, LMP_SIZE_ROWS) -print("bgridlocal nrows = ",bgridlocalnrows) -bgridlocalncols = lmp.extract_compute("bgridlocal", LMP_STYLE_LOCAL, LMP_SIZE_COLS) -print("bgridlocal ncols = ",bgridlocalncols) - -if bgridlocalnrows > 0: - bgridlocalptr = lmp.extract_compute("bgridlocal", LMP_STYLE_LOCAL, LMP_TYPE_ARRAY) - print("bgridlocal = ",bgridlocalptr) - print("bgridlocal[0][0] = ",bgridlocalptr[5][10]) - -# print out the LAMMPS array to a file - -outfile = open("bgrid.dat",'w') -igrid = 0 -for iz in range(ngridz): - for iy in range(ngridy): - for ix in range(ngridx): - outfile.write("x, y, z = %g %g %g\n" % - (bgridptr[igrid][0], - bgridptr[igrid][1], - bgridptr[igrid][2])) - for icoeff in range(ncoeff): - outfile.write("%g " % bgridptr[igrid][ncols0+icoeff]) - outfile.write("\n") - igrid += 1 -outfile.close() - -# print out the Numpy array to a file - -outfile = open("bgrid_np.dat",'w') -for iz in range(ngridz): - for iy in range(ngridy): - for ix in range(ngridx): - outfile.write("x, y, z = %g %g %g\n" % - (bgridptr_np[iz][iy][ix][0], - bgridptr_np[iz][iy][ix][1], - bgridptr_np[iz][iy][ix][2])) - for icoeff in range(ncoeff): - outfile.write("%g " % bgridptr_np[iz][iy][ix][ncols0+icoeff]) - outfile.write("\n") -outfile.close() diff --git a/examples/snap/grid.py b/examples/snap/grid.py deleted file mode 100755 index 9fe88fd1b4..0000000000 --- a/examples/snap/grid.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/Users/athomps/miniconda3/bin/python3.7 -# -# An example of SNAP grid from LAMMPS Python interface -# -# https://lammps.sandia.gov/doc/Python_library.html - - -from lammps import lammps -import lammps_utils - -# define command line input variables - -ngridx = 2 -ngridy = 3 -ngridz = 4 -twojmax = 2 - -lmp_cmdargs = ["-echo","screen"] -lmp_cmdargs = lammps_utils.set_cmdlinevars(lmp_cmdargs, - { - "ngridx":ngridx, - "ngridy":ngridy, - "ngridz":ngridz, - "twojmax":twojmax - } - ) - -# launch LAMMPS instance - -lmp = lammps(cmdargs=lmp_cmdargs) - -# run LAMMPS input script - -lmp.file("in.grid.python") - -# get quantities from LAMMPS - -num_atoms = lmp.get_natoms() - -# set things not accessible from LAMMPS - -# first 3 cols are x, y, z, coords - -ncols0 = 3 - -# analytical relation - -ncoeff = (twojmax+2)*(twojmax+3)*(twojmax+4) -ncoeff = ncoeff // 24 # integer division -ncols = ncols0+ncoeff - -# get B_0 at position (0,0,0) in 4 different ways - -# 1. from comute sna/atom - -bptr = lmp.extract_compute("b", 1, 2) # 1 = per-atom data, 2 = array -print("b = ",bptr[0][0]) - -# 2. from compute sna/grid - -bgridptr = lmp.extract_compute("bgrid", 0, 2) # 0 = style global, 2 = type array -print("bgrid = ",bgridptr[0][3]) - -# 3. from Numpy array pointing to sna/atom array - -bptr_np = lammps_utils.extract_compute_np(lmp,"b",1,2,(num_atoms,ncoeff)) -print("b_np = ",bptr_np[0][0]) - -# 4. from Numpy array pointing to sna/grid array - -bgridptr_np = lammps_utils.extract_compute_np(lmp,"bgrid",0,2,(ngridz,ngridy,ngridx,ncols)) -print("bgrid_np = ",bgridptr_np[0][0][0][ncols0+0]) - -# print out the LAMMPS array to a file - -outfile = open("bgrid.dat",'w') -igrid = 0 -for iz in range(ngridz): - for iy in range(ngridy): - for ix in range(ngridx): - outfile.write("x, y, z = %g %g %g\n" % - (bgridptr[igrid][0], - bgridptr[igrid][1], - bgridptr[igrid][2])) - for icoeff in range(ncoeff): - outfile.write("%g " % bgridptr[igrid][ncols0+icoeff]) - outfile.write("\n") - igrid += 1 -outfile.close() - -# print out the Numpy array to a file - -outfile = open("bgrid_np.dat",'w') -for iz in range(ngridz): - for iy in range(ngridy): - for ix in range(ngridx): - outfile.write("x, y, z = %g %g %g\n" % - (bgridptr_np[iz][iy][ix][0], - bgridptr_np[iz][iy][ix][1], - bgridptr_np[iz][iy][ix][2])) - for icoeff in range(ncoeff): - outfile.write("%g " % bgridptr_np[iz][iy][ix][ncols0+icoeff]) - outfile.write("\n") -outfile.close() diff --git a/examples/snap/in.fnum b/examples/snap/in.fnum deleted file mode 100644 index 1298e9aed9..0000000000 --- a/examples/snap/in.fnum +++ /dev/null @@ -1,61 +0,0 @@ -# Demonstrate pair style base on sna/grid -# Check numerical forces - -variable nrep index 3 -variable a index 3.0 -variable ngrid index 2 -variable del index 0.1 -variable fdelta index 0.0001 - -units metal - -atom_modify map yes - -# generate the box and atom positions using a BCC lattice - -variable nx equal ${nrep} -variable ny equal ${nrep} -variable nz equal ${nrep} - -boundary p p p - -lattice custom $a & - a1 1 0 0 & - a2 0 1 0 & - a3 0 0 1 & - basis 0 0 0 & - basis 0.5 0.5 0.5 & -# origin 0.25 0.25 0.25 -# origin 0.25e-3 0.25e-3 0.25e-3 - -region box block 0 ${nx} 0 ${ny} 0 ${nz} -create_box 1 box -create_atoms 1 box -mass 1 180.88 -displace_atoms all random ${del} ${del} ${del} 12345 - -# define grid compute and atom compute - -group snapgroup type 1 -variable twojmax equal 2 -variable rcutfac equal 4.67637 -variable rfac0 equal 0.99363 -variable rmin0 equal 0 -variable wj equal 1 -variable radelem equal 0.5 -variable bzero equal 0 -variable quad equal 0 -variable switch equal 1 - -pair_style sna/grid grid ${ngrid} ${ngrid} ${ngrid} & - ${rcutfac} ${rfac0} ${twojmax} ${radelem} & - ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & - quadraticflag ${quad} switchflag ${switch} -pair_coeff * * Al - -fix fnum all numdiff 1 ${fdelta} -variable ferrsq atom (fx-f_fnum[1])^2+(fy-f_fnum[2])^2+(fz-f_fnum[3])^2 -compute faverrsq all reduce ave v_ferrsq -thermo_style custom c_faverrsq - -run 0 diff --git a/examples/snap/in.grid b/examples/snap/in.grid deleted file mode 100644 index 44c42673e0..0000000000 --- a/examples/snap/in.grid +++ /dev/null @@ -1,83 +0,0 @@ -# Demonstrate bispectrum computes - -# CORRECTNESS: thermo output for c_mygrid[*][1] and c_mygrid[*][8] should -# match the values in dump_b: 108.173 3.21778 0.712238 7.06634 1.04273 - -# Initialize simulation - -variable nsteps index 0 -variable nrep index 1 -variable a index 3.316 -variable ngrid index 2 - -units metal - -# generate the box and atom positions using a BCC lattice - -variable nx equal ${nrep} -variable ny equal ${nrep} -variable nz equal ${nrep} - -boundary p p p - -lattice custom $a & - a1 1 0 0 & - a2 0 1 0 & - a3 0 0 1 & - basis 0 0 0 & - basis 0.5 0.5 0.5 & -# origin 0.25 0.25 0.25 - -region box block 0 ${nx} 0 ${ny} 0 ${nz} -create_box 1 box -create_atoms 1 box - -mass 1 180.88 - -# choose potential - -include Ta06A.snap - -# define grid compute and atom compute - -group snapgroup type 1 -variable twojmax equal 2 -variable rcutfac equal 4.67637 -variable rfac0 equal 0.99363 -variable rmin0 equal 0 -variable wj equal 1 -variable radelem equal 0.5 -variable bzero equal 0 -variable quad equal 0 -variable switch equal 1 - -compute b all sna/atom & - ${rcutfac} ${rfac0} ${twojmax} ${radelem} & - ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & - quadraticflag ${quad} switchflag ${switch} - -compute mygrid all sna/grid grid ${ngrid} ${ngrid} ${ngrid} & - ${rcutfac} ${rfac0} ${twojmax} ${radelem} & - ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & - quadraticflag ${quad} switchflag ${switch} - -# define output - -# mygrid is ngrid by (3+nbis) = 8x8 -thermo_style custom step temp ke pe vol & - c_mygrid[1][1] c_mygrid[2][1] c_mygrid[3][1] c_mygrid[4][1] c_mygrid[5][1] c_mygrid[6][1] c_mygrid[7][1] c_mygrid[8][1] & - c_mygrid[1][2] c_mygrid[2][2] c_mygrid[3][2] c_mygrid[4][2] c_mygrid[5][2] c_mygrid[6][2] c_mygrid[7][2] c_mygrid[8][2] & - c_mygrid[1][3] c_mygrid[2][3] c_mygrid[3][3] c_mygrid[4][3] c_mygrid[5][3] c_mygrid[6][3] c_mygrid[7][3] c_mygrid[8][3] & - c_mygrid[1][4] c_mygrid[2][4] c_mygrid[3][4] c_mygrid[4][4] c_mygrid[5][4] c_mygrid[6][4] c_mygrid[7][4] c_mygrid[8][4] & - c_mygrid[1][5] c_mygrid[2][5] c_mygrid[3][5] c_mygrid[4][5] c_mygrid[5][5] c_mygrid[6][5] c_mygrid[7][5] c_mygrid[8][5] & - c_mygrid[1][6] c_mygrid[2][6] c_mygrid[3][6] c_mygrid[4][6] c_mygrid[5][6] c_mygrid[6][6] c_mygrid[7][6] c_mygrid[8][6] & - c_mygrid[1][7] c_mygrid[2][7] c_mygrid[3][7] c_mygrid[4][7] c_mygrid[5][7] c_mygrid[6][7] c_mygrid[7][7] c_mygrid[8][7] & - c_mygrid[1][8] c_mygrid[2][8] c_mygrid[3][8] c_mygrid[4][8] c_mygrid[5][8] c_mygrid[6][8] c_mygrid[7][8] c_mygrid[8][8] -thermo_modify norm yes - -dump mydump_b all custom 1000 dump_b id c_b[*] - -# run - -run 0 - diff --git a/examples/snap/in.grid.local b/examples/snap/in.grid.local deleted file mode 100644 index 121f0ba981..0000000000 --- a/examples/snap/in.grid.local +++ /dev/null @@ -1,77 +0,0 @@ -# Demonstrate bispectrum computes with local grid - -# Initialize simulation - -variable nsteps index 0 -variable nrep index 1 -variable a index 3.316 -variable ngrid index 2 - -units metal - -# generate the box and atom positions using a BCC lattice - -variable nx equal ${nrep} -variable ny equal ${nrep} -variable nz equal ${nrep} - -boundary p p p - -lattice custom $a & - a1 1 0 0 & - a2 0 1 0 & - a3 0 0 1 & - basis 0 0 0 & - basis 0.5 0.5 0.5 & -# origin 0.25 0.25 0.25 - -region box block 0 ${nx} 0 ${ny} 0 ${nz} -create_box 1 box -create_atoms 1 box - -mass 1 180.88 - -# choose potential - -include Ta06A.snap - -# define grid compute and atom compute - -group snapgroup type 1 -variable twojmax equal 2 -variable rcutfac equal 4.67637 -variable rfac0 equal 0.99363 -variable rmin0 equal 0 -variable wj equal 1 -variable radelem equal 0.5 -variable bzero equal 0 -variable quad equal 0 -variable switch equal 1 - -compute b all sna/atom & - ${rcutfac} ${rfac0} ${twojmax} ${radelem} & - ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & - quadraticflag ${quad} switchflag ${switch} - -compute mygridlocal all sna/grid/local grid ${ngrid} ${ngrid} ${ngrid} & - ${rcutfac} ${rfac0} ${twojmax} ${radelem} & - ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & - quadraticflag ${quad} switchflag ${switch} - -# define output - -# mygrid is ngrid by (3+nbis) = 8x8 -thermo_style custom step temp ke pe vol -thermo_modify norm yes - -dump mydump_b all custom 1000 dump_b id c_b[*] -dump mydump_bgridlocal all local 1000 dump_bgridlocal index c_mygridlocal[*] - -# run - -run 0 - -run 0 - -run 0 - diff --git a/examples/snap/in.grid.pair b/examples/snap/in.grid.pair deleted file mode 100644 index 128da2ad7a..0000000000 --- a/examples/snap/in.grid.pair +++ /dev/null @@ -1,90 +0,0 @@ -# Demonstrate pair style base on sna/grid -# Test energy conservation -# Choose dtfac in the range [0.01,Infinity] -# Large dtfac means small timestep, while -# keeping trajectory output interval fixed -# Variable etotdelta measures change in (PE+KE)/natoms - -# Initialize simulation - -variable dtfac index 1 -variable dt equal 0.5e-3/${dtfac} -variable nthermo equal 1000*${dtfac} -variable nsteps equal 1000*${dtfac} -variable nrep index 3 -variable a index 3.0 -variable ngrid index 2 -variable t index 300 -variable del index 0.1 - -units metal - -atom_modify map yes - -# generate the box and atom positions using a BCC lattice - -variable nx equal ${nrep} -variable ny equal ${nrep} -variable nz equal ${nrep} - -boundary p p p - -lattice custom $a & - a1 1 0 0 & - a2 0 1 0 & - a3 0 0 1 & - basis 0 0 0 & - basis 0.5 0.5 0.5 & -# origin 0.25 0.25 0.25 -# origin 0.25e-3 0.25e-3 0.25e-3 - -region box block 0 ${nx} 0 ${ny} 0 ${nz} -create_box 1 box -create_atoms 1 box -mass 1 180.88 -displace_atoms all random ${del} ${del} ${del} 12345 -velocity all create $t 4928459 loop geom - -write_dump all custom test.dump id type x y z - -# define grid compute and atom compute - -group snapgroup type 1 -variable twojmax equal 2 -variable rcutfac equal 4.67637 -variable rfac0 equal 0.99363 -variable rmin0 equal 0 -variable wj equal 1 -variable radelem equal 0.5 -variable bzero equal 0 -variable quad equal 0 -variable switch equal 1 - -pair_style sna/grid grid ${ngrid} ${ngrid} ${ngrid} & - ${rcutfac} ${rfac0} ${twojmax} ${radelem} & - ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & - quadraticflag ${quad} switchflag ${switch} -pair_coeff * * Al - -thermo ${nthermo} -thermo_modify norm yes - -run 0 -variable etot0 equal etotal -variable etotdelta equal abs(etotal-${etot0})/atoms -fix avede all ave/time 1 ${nthermo} ${nthermo} v_etotdelta - -thermo_style custom step temp epair ke etotal press v_etotdelta f_avede -thermo ${nthermo} -thermo_modify norm yes - -# Set up NVE run - -timestep ${dt} -neighbor 1.0 bin -neigh_modify once no every 1 delay 0 check yes - -# Run MD - -fix mynve all nve -run ${nsteps} diff --git a/examples/snap/in.grid.python b/examples/snap/in.grid.python deleted file mode 100644 index e04415d558..0000000000 --- a/examples/snap/in.grid.python +++ /dev/null @@ -1,65 +0,0 @@ -# Demonstrate bispectrum per-atom and grid computes - -# Invoked from grid.py -# pass in values for ngridx, ngridy, ngridz, twojmax - -# Initialize simulation - -variable nsteps equal 0 -variable nrep equal 1 -variable a equal 3.316 - -units metal - -# generate the box and atom positions using a BCC lattice - -variable nx equal ${nrep} -variable ny equal ${nrep} -variable nz equal ${nrep} - -boundary p p p - -lattice custom ${a} a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 - -region box block 0 ${nx} 0 ${ny} 0 ${nz} -create_box 1 box -create_atoms 1 box - -mass 1 180.88 - -# define grid compute and atom compute - -group snapgroup type 1 -variable rcutfac equal 4.67637 -variable rfac0 equal 0.99363 -variable rmin0 equal 0 -variable wj equal 1 -variable radelem equal 0.5 -variable bzero equal 0 -variable quad equal 0 -variable switch equal 1 - -compute b all sna/atom ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} - -compute bgrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} - -compute bgridlocal all sna/grid/local grid ${ngridx} ${ngridy} ${ngridz} ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} - -# create dummy potential for neighbor list - -variable rcutneigh equal 2.0*${rcutfac}*${radelem} -pair_style zero ${rcutneigh} -pair_coeff * * - -# define output - -thermo_style custom step temp ke pe vol c_bgrid[1][1] -thermo_modify norm yes - -dump mydump_b all custom 1000 dump_b id c_b[*] - -dump mydump_bgridlocal all local 1000 dump_bgridlocal index c_bgridlocal[1] - -# run - -run 0 diff --git a/examples/snap/in.grid.python.local b/examples/snap/in.grid.python.local deleted file mode 100644 index af95696a2b..0000000000 --- a/examples/snap/in.grid.python.local +++ /dev/null @@ -1,69 +0,0 @@ -# Demonstrate bispectrum per-atom and grid computes - -# Invoked from grid.py -# pass in values for ngridx, ngridy, ngridz, twojmax - -# Initialize simulation - -variable nsteps equal 0 -variable nrep equal 1 -variable a equal 3.316 - -units metal - -# make processor grid equal to nz - -processors 1 1 ${ngridz} - -# generate the box and atom positions using a BCC lattice - -variable nx equal ${nrep} -variable ny equal ${nrep} -variable nz equal ${nrep} - -boundary p p p - -lattice custom ${a} a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 - -region box block 0 ${nx} 0 ${ny} 0 ${nz} -create_box 1 box -create_atoms 1 box - -mass 1 180.88 - -# define grid compute and atom compute - -group snapgroup type 1 -variable rcutfac equal 4.67637 -variable rfac0 equal 0.99363 -variable rmin0 equal 0 -variable wj equal 1 -variable radelem equal 0.5 -variable bzero equal 0 -variable quad equal 0 -variable switch equal 1 - -compute b all sna/atom ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} - -compute bgrid all sna/grid grid ${ngridx} ${ngridy} ${ngridz} ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} - -compute bgridlocal all sna/grid/local grid ${ngridx} ${ngridy} ${ngridz} ${rcutfac} ${rfac0} ${twojmax} ${radelem} ${wj} rmin0 ${rmin0} bzeroflag ${bzero} quadraticflag ${quad} switchflag ${switch} - -# create dummy potential for neighbor list - -variable rcutneigh equal 2.0*${rcutfac}*${radelem} -pair_style zero ${rcutneigh} -pair_coeff * * - -# define output - -thermo_style custom step temp ke pe vol c_bgrid[1][1] -thermo_modify norm yes - -dump mydump_b all custom 1000 dump_b id c_b[*] - -dump mydump_bgridlocal all local 1000 dump_bgridlocal index c_bgridlocal[*] - -# run - -run 0 diff --git a/examples/snap/in.grid.test b/examples/snap/in.grid.test deleted file mode 100644 index c684200d44..0000000000 --- a/examples/snap/in.grid.test +++ /dev/null @@ -1,105 +0,0 @@ -# Demonstrate bispectrum computes - -# CORRECTNESS: thermo output for c_mygrid[*][1] and c_mygrid[*][8] should -# match the values in dump_b: 108.173 3.21778 0.712238 7.06634 1.04273 - -# Initialize simulation - -variable nsteps index 0 -variable nrep index 3 -variable a index 3.316 -variable ngrid index 2 - -units metal - -atom_modify map yes - -# generate the box and atom positions using a BCC lattice - -variable nx equal ${nrep} -variable ny equal ${nrep} -variable nz equal ${nrep} - -boundary p p p - -lattice custom $a & - a1 1 0 0 & - a2 0 1 0 & - a3 0 0 1 & - basis 0 0 0 & - basis 0.5 0.5 0.5 & -# origin 0.25 0.25 0.25 -# origin 0.25e-3 0.25e-3 0.25e-3 - -region box block 0 ${nx} 0 ${ny} 0 ${nz} -create_box 1 box -create_atoms 1 box - -mass 1 180.88 - -write_dump all custom test.dump id type x y z - -# choose potential - -include Ta06A.snap - -# define grid compute and atom compute - -group snapgroup type 1 -variable twojmax equal 2 -variable rcutfac equal 4.67637 -variable rfac0 equal 0.99363 -variable rmin0 equal 0 -variable wj equal 1 -variable radelem equal 0.5 -variable bzero equal 0 -variable quad equal 0 -variable switch equal 1 - -compute b all sna/atom & - ${rcutfac} ${rfac0} ${twojmax} ${radelem} & - ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & - quadraticflag ${quad} switchflag ${switch} - -compute mygrid all sna/grid grid ${ngrid} ${ngrid} ${ngrid} & - ${rcutfac} ${rfac0} ${twojmax} ${radelem} & - ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & - quadraticflag ${quad} switchflag ${switch} - -compute mygridlocal all sna/grid/local grid ${ngrid} ${ngrid} ${ngrid} & - ${rcutfac} ${rfac0} ${twojmax} ${radelem} & - ${wj} rmin0 ${rmin0} bzeroflag ${bzero} & - quadraticflag ${quad} switchflag ${switch} - -# define output - -# mygrid is ngrid by (3+nbis) = 8x8 -thermo_style custom step temp ke pe vol & - c_mygrid[1][1] c_mygrid[2][1] c_mygrid[3][1] c_mygrid[4][1] c_mygrid[5][1] c_mygrid[6][1] c_mygrid[7][1] c_mygrid[8][1] & - c_mygrid[1][2] c_mygrid[2][2] c_mygrid[3][2] c_mygrid[4][2] c_mygrid[5][2] c_mygrid[6][2] c_mygrid[7][2] c_mygrid[8][2] & - c_mygrid[1][3] c_mygrid[2][3] c_mygrid[3][3] c_mygrid[4][3] c_mygrid[5][3] c_mygrid[6][3] c_mygrid[7][3] c_mygrid[8][3] & - c_mygrid[1][4] c_mygrid[2][4] c_mygrid[3][4] c_mygrid[4][4] c_mygrid[5][4] c_mygrid[6][4] c_mygrid[7][4] c_mygrid[8][4] & - c_mygrid[1][5] c_mygrid[2][5] c_mygrid[3][5] c_mygrid[4][5] c_mygrid[5][5] c_mygrid[6][5] c_mygrid[7][5] c_mygrid[8][5] & - c_mygrid[1][6] c_mygrid[2][6] c_mygrid[3][6] c_mygrid[4][6] c_mygrid[5][6] c_mygrid[6][6] c_mygrid[7][6] c_mygrid[8][6] & - c_mygrid[1][7] c_mygrid[2][7] c_mygrid[3][7] c_mygrid[4][7] c_mygrid[5][7] c_mygrid[6][7] c_mygrid[7][7] c_mygrid[8][7] & - c_mygrid[1][8] c_mygrid[2][8] c_mygrid[3][8] c_mygrid[4][8] c_mygrid[5][8] c_mygrid[6][8] c_mygrid[7][8] c_mygrid[8][8] -thermo_modify norm yes - -#dump mydump_b all custom 1 dump_b id c_b[*] -dump mydump_bgridlocal all local 1 dump_bgridlocal index c_mygridlocal[*] - -# run - -run 1 - -# rcb - -comm_style tiled -balance 0.99 rcb -run 1 - -# rcb again - -balance 0.99 rcb -run 1 - diff --git a/examples/snap/lammps_utils.py b/examples/snap/lammps_utils.py deleted file mode 100644 index ea74459a74..0000000000 --- a/examples/snap/lammps_utils.py +++ /dev/null @@ -1,26 +0,0 @@ -import numpy as np -import ctypes - -def set_cmdlinevars(cmdargs, argdict): - for key in argdict.keys(): - cmdargs += ["-var",key,f"{argdict[key]}"] - return cmdargs - -def extract_commands(string): - return [x for x in string.splitlines() if x.strip() != ''] - -def extract_compute_np(lmp,name,compute_type,result_type,array_shape): - """ - Convert a lammps compute to a numpy array. - Assumes the compute returns a floating point numbers. - Note that the result is a view into the original memory. - If the result type is 0 (scalar) then conversion to numpy is skipped and a python float is returned. - """ - ptr = lmp.extract_compute(name, compute_type, result_type) # 1,2: Style (1) is per-atom compute, returns array type (2). - if result_type == 0: return ptr # No casting needed, lammps.py already works - if result_type == 2: ptr = ptr.contents - total_size = np.prod(array_shape) - buffer_ptr = ctypes.cast(ptr, ctypes.POINTER(ctypes.c_double * total_size)) - array_np = np.frombuffer(buffer_ptr.contents, dtype=float) - array_np.shape = array_shape - return array_np diff --git a/src/ML-SNAP/pair_sna_grid.cpp b/src/ML-SNAP/pair_sna_grid.cpp deleted file mode 100644 index ffb4dfa033..0000000000 --- a/src/ML-SNAP/pair_sna_grid.cpp +++ /dev/null @@ -1,449 +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. -------------------------------------------------------------------------- */ - -#include "pair_grid.h" -#include "pair_sna_grid.h" -#include "sna.h" -#include "atom.h" -#include "update.h" -#include "modify.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "neigh_request.h" -#include "force.h" -#include "pair.h" -#include "domain.h" -#include "comm.h" -#include "memory.h" -#include "error.h" -#include "tokenizer.h" - -#include -#include - -using namespace LAMMPS_NS; - -PairSNAGrid::PairSNAGrid(LAMMPS *lmp) : - PairGrid(lmp), - radelem(nullptr), wjelem(nullptr) -{ - snaptr = nullptr; -} - -/* ---------------------------------------------------------------------- */ - -PairSNAGrid::~PairSNAGrid() -{ - memory->destroy(radelem); - memory->destroy(wjelem); - memory->destroy(cutsq); - delete snaptr; - - if (chemflag) memory->destroy(map); -} - -/* ---------------------------------------------------------------------- */ - -void PairSNAGrid::init_style() -{ - if (force->newton_pair == 0) - error->all(FLERR,"Pair style sna/grid requires newton pair on"); - - snaptr = new SNA(lmp, rfac0, twojmax, - rmin0, switchflag, bzeroflag, - chemflag, bnormflag, wselfallflag, - nelements, switchinnerflag); - ncoeff = snaptr->ncoeff; - ndesc = ndesc_base + ncoeff; - snaptr->init(); - -} - -/* ---------------------------------------------------------------------- */ - -void PairSNAGrid::init_list(int /*id*/, NeighList *ptr) -{ - list = ptr; -} - -/* ---------------------------------------------------------------------- */ - -void PairSNAGrid::compute(int eflag, int vflag) -{ - double fij[3]; - - ev_init(eflag,vflag); - - // compute sna for each gridpoint - - double** const x = atom->x; - double **f = atom->f; - const int* const mask = atom->mask; - int * const type = atom->type; - const int ntotal = atom->nlocal + atom->nghost; - - // insure rij, inside, and typej are of size ntotal - - snaptr->grow_rij(ntotal); - - // first generate fingerprint, - // which allows calculation of beta - - for (int iz = nzlo; iz <= nzhi; iz++) - for (int iy = nylo; iy <= nyhi; iy++) - for (int ix = nxlo; ix <= nxhi; ix++) { - double xgrid[3]; - grid2x(ix, iy, iz, xgrid); - const double xtmp = xgrid[0]; - const double ytmp = xgrid[1]; - const double ztmp = xgrid[2]; - - // currently, all grid points are type 1 - - const int itype = 1; - int ielem = 0; - if (chemflag) - ielem = map[itype]; - const double radi = radelem[itype]; - - // rij[][3] = displacements between atom I and those neighbors - // inside = indices of neighbors of I within cutoff - // typej = types of neighbors of I within cutoff - - int ninside = 0; - for (int j = 0; j < ntotal; j++) { - - const double delx = xtmp - x[j][0]; - const double dely = ytmp - x[j][1]; - const double delz = ztmp - x[j][2]; - const double rsq = delx*delx + dely*dely + delz*delz; - int jtype = type[j]; - int jelem = 0; - if (chemflag) - jelem = map[jtype]; - if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { - snaptr->rij[ninside][0] = delx; - snaptr->rij[ninside][1] = dely; - snaptr->rij[ninside][2] = delz; - snaptr->inside[ninside] = j; - snaptr->wj[ninside] = wjelem[jtype]; - snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; - snaptr->element[ninside] = jelem; // element index for multi-element snap - ninside++; - } - } - - snaptr->compute_ui(ninside, ielem); - snaptr->compute_zi(); - snaptr->compute_bi(ielem); - - // linear contributions - - for (int icoeff = 0; icoeff < ncoeff; icoeff++) - gridlocal[ndesc_base+icoeff][iz][iy][ix] = - snaptr->blist[icoeff]; - - // quadratic contributions - // untested - - if (quadraticflag) { - int ncount = ncoeff; - for (int icoeff = 0; icoeff < ncoeff; icoeff++) { - double bveci = snaptr->blist[icoeff]; - gridlocal[ndesc_base+ncount++][iz][iy][ix] = - 0.5*bveci*bveci; - for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - gridlocal[ndesc_base+ncount++][iz][iy][ix] = - bveci*snaptr->blist[jcoeff]; - } - } - } - - // this is a proxy for a call to the energy model - // beta is dE/dB^i, the derivative of the total - // energy w.r.t. to descriptors of grid point i - - compute_beta(); - - // second compute forces using beta - - int igrid = 0; - for (int iz = nzlo; iz <= nzhi; iz++) - for (int iy = nylo; iy <= nyhi; iy++) - for (int ix = nxlo; ix <= nxhi; ix++) { - double xgrid[3]; - grid2x(ix, iy, iz, xgrid); - const double xtmp = xgrid[0]; - const double ytmp = xgrid[1]; - const double ztmp = xgrid[2]; - - // currently, all grid points are type 1 - - const int itype = 1; - int ielem = 0; - if (chemflag) - ielem = map[itype]; - const double radi = radelem[itype]; - - // rij[][3] = displacements between atom I and those neighbors - // inside = indices of neighbors of I within cutoff - // typej = types of neighbors of I within cutoff - - int ninside = 0; - for (int j = 0; j < ntotal; j++) { - - const double delx = xtmp - x[j][0]; - const double dely = ytmp - x[j][1]; - const double delz = ztmp - x[j][2]; - const double rsq = delx*delx + dely*dely + delz*delz; - int jtype = type[j]; - int jelem = 0; - jelem = map[jtype]; - - if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { - snaptr->rij[ninside][0] = delx; - snaptr->rij[ninside][1] = dely; - snaptr->rij[ninside][2] = delz; - snaptr->inside[ninside] = j; - snaptr->wj[ninside] = wjelem[jtype]; - snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; - if (switchinnerflag) { - snaptr->sinnerij[ninside] = 0.5*(sinnerelem[ielem]+sinnerelem[jelem]); - snaptr->dinnerij[ninside] = 0.5*(dinnerelem[ielem]+dinnerelem[jelem]); - } - if (chemflag) snaptr->element[ninside] = jelem; - ninside++; - } - } - - // compute Ui, Yi for atom I - - if (chemflag) - snaptr->compute_ui(ninside, ielem); - else - snaptr->compute_ui(ninside, 0); - - // for neighbors of I within cutoff: - // compute Fij = dEi/dRj = -dEi/dRi - // add to Fi, subtract from Fj - // scaling is that for type I - - snaptr->compute_yi(beta[igrid]); - - for (int jj = 0; jj < ninside; jj++) { - int j = snaptr->inside[jj]; - snaptr->compute_duidrj(jj); - - snaptr->compute_deidrj(fij); - - f[j][0] += fij[0]; - f[j][1] += fij[1]; - f[j][2] += fij[2]; - - // tally per-atom virial contribution - - if (vflag) - ev_tally_xyz(-1,j,atom->nlocal,force->newton_pair,0.0,0.0, - fij[0],fij[1],fij[2], - -snaptr->rij[jj][0],-snaptr->rij[jj][1], - -snaptr->rij[jj][2]); - } - - // tally energy contribution - - if (eflag) { - - // get descriptors again - - snaptr->compute_zi(); - snaptr->compute_bi(ielem); - - // evdwl = energy of atom I, sum over coeffs_k * Bi_k - - double evdwl = 0.0; - - // E = beta.B - - for (int icoeff = 0; icoeff < ncoeff; icoeff++) - evdwl += beta[igrid][icoeff]*snaptr->blist[icoeff]; - - ev_tally_full(-1,2.0*evdwl,0.0,0.0,0.0,0.0,0.0); - - } - igrid++; - } - - if (vflag_fdotr) virial_fdotr_compute(); - -} - - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairSNAGrid::settings(int narg, char ** arg) -{ - - // call base class first - - PairGrid::settings(narg, arg); - - // skip over arguments used by base class - // so that argument positions are identical to - // regular per-atom compute - - arg += nargbase; - narg -= nargbase; - - int ntypes = atom->ntypes; - int nargmin = 3+2*ntypes; - - if (narg < nargmin) error->all(FLERR,"Illegal pair sna/grid command"); - - // default values - - rmin0 = 0.0; - switchflag = 1; - bzeroflag = 1; - quadraticflag = 0; - chemflag = 0; - bnormflag = 0; - wselfallflag = 0; - switchinnerflag = 0; - nelements = 1; - - // process required arguments - - memory->create(radelem,ntypes+1,"pair:sna/grid:radelem"); // offset by 1 to match up with types - memory->create(wjelem,ntypes+1,"pair:sna/grid:wjelem"); - - rcutfac = atof(arg[0]); - rfac0 = atof(arg[1]); - twojmax = atoi(arg[2]); - - for(int i = 0; i < ntypes; i++) - radelem[i+1] = atof(arg[3+i]); - for(int i = 0; i < ntypes; i++) - wjelem[i+1] = atof(arg[3+ntypes+i]); - - // construct cutsq - - double cut; - cutmax = 0.0; - memory->create(cutsq,ntypes+1,ntypes+1,"pair:sna/grid:cutsq"); - for(int i = 1; i <= ntypes; i++) { - cut = 2.0*radelem[i]*rcutfac; - if (cut > cutmax) cutmax = cut; - cutsq[i][i] = cut*cut; - for(int j = i+1; j <= ntypes; j++) { - cut = (radelem[i]+radelem[j])*rcutfac; - cutsq[i][j] = cutsq[j][i] = cut*cut; - } - } - - // set local input checks - - int sinnerflag = 0; - int dinnerflag = 0; - - // process optional args - - int iarg = nargmin; - - while (iarg < narg) { - if (strcmp(arg[iarg],"rmin0") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal pair sna/grid command"); - rmin0 = atof(arg[iarg+1]); - iarg += 2; - } else if (strcmp(arg[iarg],"switchflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal pair sna/grid command"); - switchflag = atoi(arg[iarg+1]); - iarg += 2; - } else if (strcmp(arg[iarg],"bzeroflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal pair sna/grid command"); - bzeroflag = atoi(arg[iarg+1]); - iarg += 2; - } else if (strcmp(arg[iarg],"quadraticflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal pair sna/grid command"); - quadraticflag = atoi(arg[iarg+1]); - iarg += 2; - } else if (strcmp(arg[iarg],"chem") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal pair sna/grid command"); - chemflag = 1; - memory->create(map,ntypes+1,"pair:sna/grid:map"); - nelements = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - for (int i = 0; i < ntypes; i++) { - int jelem = utils::inumeric(FLERR,arg[iarg+2+i],false,lmp); - if (jelem < 0 || jelem >= nelements) - error->all(FLERR,"Illegal pair sna/grid command"); - map[i+1] = jelem; - } - iarg += 2+ntypes; - } else if (strcmp(arg[iarg],"bnormflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal pair sna/grid command"); - bnormflag = atoi(arg[iarg+1]); - iarg += 2; - } else if (strcmp(arg[iarg],"wselfallflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal pair sna/grid command"); - wselfallflag = atoi(arg[iarg+1]); - iarg += 2; - } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal pair sna/grid command"); - switchinnerflag = atoi(arg[iarg+1]); - iarg += 2; - } else if (strcmp(arg[iarg],"sinner") == 0) { - iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal pair sna/grid command"); - memory->create(sinnerelem,ntypes+1,"snap:sinnerelem"); - for (int i = 0; i < ntypes; i++) - sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); - sinnerflag = 1; - iarg += ntypes; - } else if (strcmp(arg[iarg],"dinner") == 0) { - iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal pair sna/grid command"); - memory->create(dinnerelem,ntypes+1,"snap:dinnerelem"); - for (int i = 0; i < ntypes; i++) - dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); - dinnerflag = 1; - iarg += ntypes; - } else error->all(FLERR,"Illegal pair sna/grid command"); - - } - -} - -/* ---------------------------------------------------------------------- - memory usage -------------------------------------------------------------------------- */ - -double PairSNAGrid::memory_usage() -{ - double nbytes = snaptr->memory_usage(); // SNA object - int n = atom->ntypes+1; - nbytes += (double)n*sizeof(int); // map - - return nbytes; -} - diff --git a/src/ML-SNAP/pair_sna_grid.h b/src/ML-SNAP/pair_sna_grid.h deleted file mode 100644 index 653bb9d1c1..0000000000 --- a/src/ML-SNAP/pair_sna_grid.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- c++ -*- ---------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://www.lammps.org/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#ifdef PAIR_CLASS -// clang-format off -PairStyle(sna/grid, PairSNAGrid); -// clang-format on -#else - -#ifndef LMP_PAIR_SNA_GRID_H -#define LMP_PAIR_SNA_GRID_H - -#include "pair_grid.h" - -namespace LAMMPS_NS { - -class PairSNAGrid : public PairGrid { - public: - PairSNAGrid(class LAMMPS *); - ~PairSNAGrid(); - - void init_style(); - void init_list(int, class NeighList *); - void settings(int, char **); - void compute(int, int); - double memory_usage(); - - private: - int ncoeff; - class NeighList *list; - double rcutfac; - double *radelem; - double *wjelem; - class SNA *snaptr; - int quadraticflag; - int twojmax, switchflag, bzeroflag, bnormflag; - int chemflag, wselfallflag; - int switchinnerflag; - double *sinnerelem; - double *dinnerelem; - double rfac0, rmin0; -}; - -} - -#endif -#endif - -/* ERROR/WARNING messages: - -E: Illegal ... command - -Self-explanatory. Check the input script syntax and compare to the -documentation for the command. You can use -echo screen as a -command-line option when running LAMMPS to see the offending line. - -E: Compute sna/grid/local requires a pair style be defined - -Self-explanatory. - -E: Compute sna/grid/local cutoff is longer than pairwise cutoff - -Self-explanatory. - -W: More than one compute sna/grid/local - -Self-explanatory. - -*/ diff --git a/src/pair_grid.cpp b/src/pair_grid.cpp deleted file mode 100644 index 1f17553055..0000000000 --- a/src/pair_grid.cpp +++ /dev/null @@ -1,328 +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. -------------------------------------------------------------------------- */ - -#include "pair_grid.h" -#include -#include -#include "atom.h" -#include "update.h" -#include "modify.h" -#include "domain.h" -#include "force.h" -#include "memory.h" -#include "error.h" -#include "comm.h" - -#define BETA_CONST 1.0e-2 - -using namespace LAMMPS_NS; - -/* ---------------------------------------------------------------------- */ - -PairGrid::PairGrid(LAMMPS *lmp) : - Pair(lmp), gridlocal(nullptr), alocal(nullptr), beta(nullptr) -{ - single_enable = 0; - restartinfo = 0; - one_coeff = 1; - manybody_flag = 1; - centroidstressflag = CENTROID_NOTAVAIL; - - ndesc = 0; - ngridlocal = 0; - - ndesc_base = 6; - gridlocal_allocated = 0; - beta_max = 0; - beta = nullptr; -} - -/* ---------------------------------------------------------------------- */ - -PairGrid::~PairGrid() -{ - if (copymode) return; - deallocate_grid(); -} - -/* ---------------------------------------------------------------------- */ - -void PairGrid::setup() -{ - deallocate_grid(); - set_grid_global(); - set_grid_local(); - allocate_grid(); - assign_coords(); -} - -/* ---------------------------------------------------------------------- - convert global array indexes to box coords -------------------------------------------------------------------------- */ - -void PairGrid::grid2x(int ix, int iy, int iz, double *x) -{ - x[0] = ix*delx; - x[1] = iy*dely; - x[2] = iz*delz; - - if (triclinic) domain->lamda2x(x, x); -} - -/* ---------------------------------------------------------------------- - create arrays -------------------------------------------------------------------------- */ - -void PairGrid::allocate_grid() -{ - if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { - gridlocal_allocated = 1; - memory->create4d_offset(gridlocal,ndesc,nzlo,nzhi,nylo,nyhi, - nxlo,nxhi,"pair/grid:gridlocal"); - memory->create(alocal, ngridlocal, ndesc, "pair/grid:alocal"); - memory->create(beta, ngridlocal, ndesc-ndesc_base, "pair/grid:beta"); - } -} - -/* ---------------------------------------------------------------------- - free arrays -------------------------------------------------------------------------- */ - -void PairGrid::deallocate_grid() -{ - if (gridlocal_allocated) { - gridlocal_allocated = 0; - memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); - memory->destroy(alocal); - memory->destroy(beta); - } -} - -/* ---------------------------------------------------------------------- - set global grid -------------------------------------------------------------------------- */ - -void PairGrid::set_grid_global() -{ - // calculate grid layout - - triclinic = domain->triclinic; - - if (triclinic == 0) { - prd = domain->prd; - boxlo = domain->boxlo; - sublo = domain->sublo; - subhi = domain->subhi; - } else { - prd = domain->prd_lamda; - boxlo = domain->boxlo_lamda; - sublo = domain->sublo_lamda; - subhi = domain->subhi_lamda; - } - - double xprd = prd[0]; - double yprd = prd[1]; - double zprd = prd[2]; - - delxinv = nx/xprd; - delyinv = ny/yprd; - delzinv = nz/zprd; - - delx = 1.0/delxinv; - dely = 1.0/delyinv; - delz = 1.0/delzinv; -} - -/* ---------------------------------------------------------------------- - set local subset of grid that I own - n xyz lo/hi = 3d brick that I own (inclusive) -------------------------------------------------------------------------- */ - -void PairGrid::set_grid_local() -{ - // nx,ny,nz = extent of global grid - // indices into the global grid range from 0 to N-1 in each dim - // if grid point is inside my sub-domain I own it, - // this includes sub-domain lo boundary but excludes hi boundary - // ixyz lo/hi = inclusive lo/hi bounds of global grid sub-brick I own - // if proc owns no grid cells in a dim, then ilo > ihi - // if 2 procs share a boundary a grid point is exactly on, - // the 2 equality if tests insure a consistent decision - // as to which proc owns it - - double xfraclo,xfrachi,yfraclo,yfrachi,zfraclo,zfrachi; - - if (comm->layout != Comm::LAYOUT_TILED) { - xfraclo = comm->xsplit[comm->myloc[0]]; - xfrachi = comm->xsplit[comm->myloc[0]+1]; - yfraclo = comm->ysplit[comm->myloc[1]]; - yfrachi = comm->ysplit[comm->myloc[1]+1]; - zfraclo = comm->zsplit[comm->myloc[2]]; - zfrachi = comm->zsplit[comm->myloc[2]+1]; - } else { - xfraclo = comm->mysplit[0][0]; - xfrachi = comm->mysplit[0][1]; - yfraclo = comm->mysplit[1][0]; - yfrachi = comm->mysplit[1][1]; - zfraclo = comm->mysplit[2][0]; - zfrachi = comm->mysplit[2][1]; - } - - nxlo = static_cast (xfraclo * nx); - if (1.0*nxlo != xfraclo*nx) nxlo++; - nxhi = static_cast (xfrachi * nx); - if (1.0*nxhi == xfrachi*nx) nxhi--; - - nylo = static_cast (yfraclo * ny); - if (1.0*nylo != yfraclo*ny) nylo++; - nyhi = static_cast (yfrachi * ny); - if (1.0*nyhi == yfrachi*ny) nyhi--; - - nzlo = static_cast (zfraclo * nz); - if (1.0*nzlo != zfraclo*nz) nzlo++; - nzhi = static_cast (zfrachi * nz); - if (1.0*nzhi == zfrachi*nz) nzhi--; - - ngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); -} - -/* ---------------------------------------------------------------------- - copy coords to local array -------------------------------------------------------------------------- */ - -void PairGrid::assign_coords() -{ - int igrid = 0; - for (int iz = nzlo; iz <= nzhi; iz++) - for (int iy = nylo; iy <= nyhi; iy++) - for (int ix = nxlo; ix <= nxhi; ix++) { - alocal[igrid][0] = ix; - alocal[igrid][1] = iy; - alocal[igrid][2] = iz; - double xgrid[3]; - grid2x(ix, iy, iz, xgrid); - alocal[igrid][3] = xgrid[0]; - alocal[igrid][4] = xgrid[1]; - alocal[igrid][5] = xgrid[2]; - igrid++; - } -} - -/* ---------------------------------------------------------------------- - copy the 4d gridlocal array values to the 2d local array -------------------------------------------------------------------------- */ - -void PairGrid::copy_gridlocal_to_local_array() -{ - int igrid = 0; - for (int iz = nzlo; iz <= nzhi; iz++) - for (int iy = nylo; iy <= nyhi; iy++) - for (int ix = nxlo; ix <= nxhi; ix++) { - for (int icol = ndesc_base; icol < ndesc; icol++) - alocal[igrid][icol] = gridlocal[icol][iz][iy][ix]; - igrid++; - } -} - -/* ---------------------------------------------------------------------- - calculate beta -------------------------------------------------------------------------- */ - - // this is a proxy for a call to the energy model - // beta is dE/dB^i, the derivative of the total - // energy w.r.t. to descriptors of grid point i - -void PairGrid::compute_beta() -{ - int igrid = 0; - for (int iz = nzlo; iz <= nzhi; iz++) - for (int iy = nylo; iy <= nyhi; iy++) - for (int ix = nxlo; ix <= nxhi; ix++) { - for (int icol = 0; icol < ndesc-ndesc_base; icol++) - beta[igrid][icol] = BETA_CONST; - igrid++; - } -} - -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -void PairGrid::allocate() -{ - allocated = 1; - int n = atom->ntypes; - memory->create(setflag,n+1,n+1,"pair:setflag"); - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - memory->create(cutsq,n+1,n+1,"pair:cutsq"); - map = new int[n+1]; -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairGrid::settings(int narg, char ** arg) -{ - if (narg < 4) error->all(FLERR,"Illegal pair style command"); - int iarg0 = 0; - int iarg = iarg0; - if (strcmp(arg[iarg],"grid") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal pair grid command"); - nx = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - ny = utils::inumeric(FLERR,arg[iarg+2],false,lmp); - nz = utils::inumeric(FLERR,arg[iarg+3],false,lmp); - if (nx <= 0 || ny <= 0 || nz <= 0) - error->all(FLERR,"All grid/local dimensions must be positive"); - iarg += 4; - } else error->all(FLERR,"Illegal pair grid command"); - nargbase = iarg - iarg0; -} - -/* ---------------------------------------------------------------------- - set coeffs for one or more type pairs -------------------------------------------------------------------------- */ - -void PairGrid::coeff(int narg, char **arg) -{ - if (!allocated) allocate(); - if (narg < 2) error->all(FLERR,"Incorrect args for pair coefficients"); - // if (narg != 2 + atom->ntypes) error->all(FLERR,"Incorrect args for pair coefficients"); - - map_element2type(narg-2,arg+2); - // map_element2type(0,nullptr); - -} - -/* ---------------------------------------------------------------------- - return maximum force cut off distance -------------------------------------------------------------------------- */ - -double PairGrid::init_one(int i, int j) -{ - if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); - return cutmax; -} - -/* ---------------------------------------------------------------------- - memory usage of local data -------------------------------------------------------------------------- */ - -double PairGrid::memory_usage() -{ - int nbytes = ndesc*ngridlocal*sizeof(double); // gridlocal - return nbytes; -} diff --git a/src/pair_grid.h b/src/pair_grid.h deleted file mode 100644 index b5bf7ad9ef..0000000000 --- a/src/pair_grid.h +++ /dev/null @@ -1,87 +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 -// clang-format off -PairStyle(grid,PairGrid); -// clang-format on -#else - -#ifndef LMP_PAIR_GRID_H -#define LMP_PAIR_GRID_H - -#include "pair.h" - -namespace LAMMPS_NS { - -class PairGrid : public Pair { - public: - PairGrid(class LAMMPS *); - virtual ~PairGrid(); - virtual void init_style(){}; - void setup(); - virtual void compute(int, int) { - printf("DANGER! This function should always be overridden by child\n"); - }; - - void settings(int, char **); - virtual void coeff(int, char **); - virtual double init_one(int, int); - double memory_usage(); - - protected: - int nx, ny, nz; // global grid dimensions - int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive - int ngridlocal; // number of local grid points - int nvalues; // number of values per grid point - double ****gridlocal; // local grid, redundant w.r.t. alocal - double **alocal; // pointer to Compute::array_local - int triclinic; // triclinic flag - double *boxlo, *prd; // box info (units real/ortho or reduced/tri) - double *sublo, *subhi; // subdomain info (units real/ortho or reduced/tri) - double delxinv,delyinv,delzinv; // inverse grid spacing - double delx,dely,delz; // grid spacing - int nargbase; // number of base class args - double cutmax; // largest cutoff distance - int ndesc; // number of descriptors - int ndesc_base; // number of columns used for coords, etc. - int gridlocal_allocated; // shows if gridlocal allocated - double **beta; // betas for all local grid points in list - int beta_max; // length of beta - - void allocate(); // allocate pairstyle arrays - void allocate_grid(); // create grid arrays - void deallocate_grid(); // free grid arrays - void grid2x(int, int, int, double*); // convert global indices to coordinates - void set_grid_global(); // set global grid - void set_grid_local(); // set bounds for local grid - void assign_coords(); // assign coords for grid - void copy_gridlocal_to_local_array();// copy 4d gridlocal array to 2d local array - void compute_beta(); // get betas from someplace - private: -}; - -} - -#endif -#endif - -/* ERROR/WARNING messages: - -E: Illegal ... command - -Self-explanatory. Check the input script syntax and compare to the -documentation for the command. You can use -echo screen as a -command-line option when running LAMMPS to see the offending line. - -*/ From f27e9941ae839c28f123f58df497ae2ec38acb81 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 17 Jun 2022 12:48:24 -0400 Subject: [PATCH 73/91] fix homepage urls, tabs & trailing whitespace, remove errors from headers --- doc/src/compute.rst | 4 +- doc/src/compute_sna_atom.rst | 10 +- src/ML-SNAP/compute_sna_grid.cpp | 136 ++++++++++++------------- src/ML-SNAP/compute_sna_grid.h | 18 +--- src/ML-SNAP/compute_sna_grid_local.cpp | 132 ++++++++++++------------ src/ML-SNAP/compute_sna_grid_local.h | 16 +-- src/compute_grid.cpp | 10 +- src/compute_grid.h | 14 +-- src/compute_grid_local.cpp | 46 ++++----- src/compute_grid_local.h | 14 +-- 10 files changed, 175 insertions(+), 225 deletions(-) diff --git a/doc/src/compute.rst b/doc/src/compute.rst index cf17433035..508c440e78 100644 --- a/doc/src/compute.rst +++ b/doc/src/compute.rst @@ -284,8 +284,8 @@ The individual style names on the :doc:`Commands compute ` pag * :doc:`smd/vol ` - per-particle volumes and their sum in Smooth Mach Dynamics * :doc:`snap ` - gradients of SNAP energy and forces w.r.t. linear coefficients and related quantities for fitting SNAP potentials * :doc:`sna/atom ` - bispectrum components for each atom -* :doc:`sna/grid ` - global array of bispectrum components on a regular grid -* :doc:`sna/grid/local ` - local array of bispectrum components on a regular grid +* :doc:`sna/grid ` - global array of bispectrum components on a regular grid +* :doc:`sna/grid/local ` - local array of bispectrum components on a regular grid * :doc:`snad/atom ` - derivative of bispectrum components for each atom * :doc:`snav/atom ` - virial contribution from bispectrum components for each atom * :doc:`sph/e/atom ` - per-atom internal energy of Smooth-Particle Hydrodynamics atoms diff --git a/doc/src/compute_sna_atom.rst b/doc/src/compute_sna_atom.rst index 2bbee1e6b6..5f777685fd 100644 --- a/doc/src/compute_sna_atom.rst +++ b/doc/src/compute_sna_atom.rst @@ -35,7 +35,7 @@ Syntax * twojmax = band limit for bispectrum components (non-negative integer) * R_1, R_2,... = list of cutoff radii, one for each type (distance units) * w_1, w_2,... = list of neighbor weights, one for each type -* nx, ny, nz = number of grid points in x, y, and z directions (positive integer) +* nx, ny, nz = number of grid points in x, y, and z directions (positive integer) * zero or more keyword/value pairs may be appended * keyword = *rmin0* or *switchflag* or *bzeroflag* or *quadraticflag* or *chem* or *bnormflag* or *wselfallflag* or *bikflag* or *switchinnerflag* or *sinner* or *dinner* @@ -223,7 +223,7 @@ These are calculated from the local density of nearby atoms *i'* around each grid point, as if there was a central atom *i* at the grid point. This is useful for characterizing fine-scale structure in a configuration of atoms, and it has been used -to build a machine-learning surrogate for finite-temperature Kohn-Sham +to build a machine-learning surrogate for finite-temperature Kohn-Sham density functional theory (:ref:`Ellis et al. `). Neighbor atoms not in the group do not contribute to the bispectrum components of the grid points. The distance cutoff :math:`R_{ii'}` @@ -231,7 +231,7 @@ and other parameters are defined as for a central atom with the same type as the neighbor atoms *i'*. Compute *sna/grid* calculates a global array containing bispectrum -components for a regular grid of points. +components for a regular grid of points. The grid is aligned with the current box dimensions, with the first point at the box origin, and forming a regular 3d array with *nx*, *ny*, and *nz* points in the x, y, and z directions. For triclinic @@ -720,7 +720,7 @@ The array contains one row for each of the :math:`nx \times ny \times nz` grid points, looping over the index for *ix* fastest, then *iy*, and *iz* slowest. Each row of the array contains the *x*, *y*, and *z* coordinates of the grid point, followed by the bispectrum -components. +components. Compute *sna/grid/local* evaluates a local array. The array contains one row for each of the @@ -754,7 +754,7 @@ The optional keyword defaults are *rmin0* = 0, .. _Thompson20141: **(Thompson)** Thompson, Swiler, Trott, Foiles, Tucker, J Comp Phys, 285, 316, (2015). - + .. _Bartok20101: **(Bartok)** Bartok, Payne, Risi, Csanyi, Phys Rev Lett, 104, 136403 (2010). diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 1d868ba769..8247771493 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, Sandia National Laboratories + https://www.lammps.org/ Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract @@ -41,7 +41,7 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; // skip over arguments used by base class - // so that argument positions are identical to + // so that argument positions are identical to // regular per-atom compute arg += nargbase; @@ -63,7 +63,7 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : wselfallflag = 0; switchinnerflag = 0; nelements = 1; - + // process required arguments memory->create(radelem,ntypes+1,"sna/grid:radelem"); // offset by 1 to match up with types @@ -175,14 +175,14 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all(FLERR,"Illegal compute sna/grid command: switchinnerflag = 1, missing sinner/dinner keyword"); - + if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all(FLERR,"Illegal compute sna/grid command: switchinnerflag = 0, unexpected sinner/dinner keyword"); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, - nelements, switchinnerflag); + nelements, switchinnerflag); ncoeff = snaptr->ncoeff; nvalues = ncoeff; @@ -236,83 +236,83 @@ void ComputeSNAGrid::compute_array() const int ntotal = atom->nlocal + atom->nghost; // insure rij, inside, and typej are of size jnum - + snaptr->grow_rij(ntotal); for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { - double xgrid[3]; - const int igrid = iz*(nx*ny) + iy*nx + ix; - grid2x(igrid, xgrid); - const double xtmp = xgrid[0]; - const double ytmp = xgrid[1]; - const double ztmp = xgrid[2]; + double xgrid[3]; + const int igrid = iz*(nx*ny) + iy*nx + ix; + grid2x(igrid, xgrid); + const double xtmp = xgrid[0]; + const double ytmp = xgrid[1]; + const double ztmp = xgrid[2]; - // currently, all grid points are type 1 - - const int itype = 1; - int ielem = 0; - if (chemflag) - ielem = map[itype]; - const double radi = radelem[itype]; + // currently, all grid points are type 1 - // rij[][3] = displacements between atom I and those neighbors - // inside = indices of neighbors of I within cutoff - // typej = types of neighbors of I within cutoff + const int itype = 1; + int ielem = 0; + if (chemflag) + ielem = map[itype]; + const double radi = radelem[itype]; - int ninside = 0; - for (int j = 0; j < ntotal; j++) { + // rij[][3] = displacements between atom I and those neighbors + // inside = indices of neighbors of I within cutoff + // typej = types of neighbors of I within cutoff - // check that j is in compute group + int ninside = 0; + for (int j = 0; j < ntotal; j++) { - if (!(mask[j] & groupbit)) continue; + // check that j is in compute group - const double delx = xtmp - x[j][0]; - const double dely = ytmp - x[j][1]; - const double delz = ztmp - x[j][2]; - const double rsq = delx*delx + dely*dely + delz*delz; - int jtype = type[j]; - int jelem = 0; - if (chemflag) + if (!(mask[j] & groupbit)) continue; + + const double delx = xtmp - x[j][0]; + const double dely = ytmp - x[j][1]; + const double delz = ztmp - x[j][2]; + const double rsq = delx*delx + dely*dely + delz*delz; + int jtype = type[j]; + int jelem = 0; + if (chemflag) jelem = map[jtype]; - if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { - snaptr->rij[ninside][0] = delx; - snaptr->rij[ninside][1] = dely; - snaptr->rij[ninside][2] = delz; - snaptr->inside[ninside] = j; - snaptr->wj[ninside] = wjelem[jtype]; - snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; - if (switchinnerflag) { - snaptr->sinnerij[ninside] = sinnerelem[jelem]; - snaptr->dinnerij[ninside] = dinnerelem[jelem]; - } - if (chemflag) snaptr->element[ninside] = jelem; - ninside++; - } - } + if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { + snaptr->rij[ninside][0] = delx; + snaptr->rij[ninside][1] = dely; + snaptr->rij[ninside][2] = delz; + snaptr->inside[ninside] = j; + snaptr->wj[ninside] = wjelem[jtype]; + snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; + if (switchinnerflag) { + snaptr->sinnerij[ninside] = sinnerelem[jelem]; + snaptr->dinnerij[ninside] = dinnerelem[jelem]; + } + if (chemflag) snaptr->element[ninside] = jelem; + ninside++; + } + } - snaptr->compute_ui(ninside, ielem); - snaptr->compute_zi(); - snaptr->compute_bi(ielem); + snaptr->compute_ui(ninside, ielem); + snaptr->compute_zi(); + snaptr->compute_bi(ielem); - // linear contributions + // linear contributions - for (int icoeff = 0; icoeff < ncoeff; icoeff++) - gridlocal[size_array_cols_base+icoeff][iz][iy][ix] = snaptr->blist[icoeff]; - - // quadratic contributions + for (int icoeff = 0; icoeff < ncoeff; icoeff++) + gridlocal[size_array_cols_base+icoeff][iz][iy][ix] = snaptr->blist[icoeff]; - if (quadraticflag) { - int ncount = ncoeff; - for (int icoeff = 0; icoeff < ncoeff; icoeff++) { - double bveci = snaptr->blist[icoeff]; - gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = 0.5*bveci*bveci; - for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = bveci*snaptr->blist[jcoeff]; - } - } + // quadratic contributions + + if (quadraticflag) { + int ncount = ncoeff; + for (int icoeff = 0; icoeff < ncoeff; icoeff++) { + double bveci = snaptr->blist[icoeff]; + gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = 0.5*bveci*bveci; + for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) + gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = bveci*snaptr->blist[jcoeff]; + } + } } memset(&grid[0][0],0,size_array_rows*size_array_cols*sizeof(double)); @@ -320,9 +320,9 @@ void ComputeSNAGrid::compute_array() for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { - const int igrid = iz*(nx*ny) + iy*nx + ix; - for (int j = 0; j < nvalues; j++) - grid[igrid][size_array_cols_base + j] = gridlocal[size_array_cols_base + j][iz][iy][ix]; + const int igrid = iz*(nx*ny) + iy*nx + ix; + for (int j = 0; j < nvalues; j++) + grid[igrid][size_array_cols_base + j] = gridlocal[size_array_cols_base + j][iz][iy][ix]; } MPI_Allreduce(&grid[0][0],&gridall[0][0],size_array_rows*size_array_cols,MPI_DOUBLE,MPI_SUM,world); assign_coords_all(); diff --git a/src/ML-SNAP/compute_sna_grid.h b/src/ML-SNAP/compute_sna_grid.h index c203ce8bb4..9bc3da8112 100644 --- a/src/ML-SNAP/compute_sna_grid.h +++ b/src/ML-SNAP/compute_sna_grid.h @@ -1,6 +1,6 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, Sandia National Laboratories + https://www.lammps.org/ Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract @@ -54,19 +54,3 @@ class ComputeSNAGrid : public ComputeGrid { #endif #endif - -/* ERROR/WARNING messages: - -E: Illegal ... command - -Self-explanatory. Check the input script syntax and compare to the -documentation for the command. You can use -echo screen as a -command-line option when running LAMMPS to see the offending line. - -Self-explanatory. - -W: More than one compute sna/grid - -Self-explanatory. - -*/ diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index 1dacc28617..70b5b362d8 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, Sandia National Laboratories + https://www.lammps.org/ Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract @@ -41,7 +41,7 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; // skip over arguments used by base class - // so that argument positions are identical to + // so that argument positions are identical to // regular per-atom compute arg += nargbase; @@ -63,7 +63,7 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : wselfallflag = 0; switchinnerflag = 0; nelements = 1; - + // set local input checks int sinnerflag = 0; @@ -175,14 +175,14 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all(FLERR,"Illegal compute sna/grid/local command: switchinnerflag = 1, missing sinner/dinner keyword"); - + if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all(FLERR,"Illegal compute sna/grid/local command: switchinnerflag = 0, unexpected sinner/dinner keyword"); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, - nelements, switchinnerflag); + nelements, switchinnerflag); ncoeff = snaptr->ncoeff; nvalues = ncoeff; @@ -235,84 +235,84 @@ void ComputeSNAGridLocal::compute_local() const int ntotal = atom->nlocal + atom->nghost; // insure rij, inside, and typej are of size jnum - + snaptr->grow_rij(ntotal); int igrid = 0; for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { - double xgrid[3]; - grid2x(ix, iy, iz, xgrid); - const double xtmp = xgrid[0]; - const double ytmp = xgrid[1]; - const double ztmp = xgrid[2]; + double xgrid[3]; + grid2x(ix, iy, iz, xgrid); + const double xtmp = xgrid[0]; + const double ytmp = xgrid[1]; + const double ztmp = xgrid[2]; - // currently, all grid points are type 1 - - const int itype = 1; - int ielem = 0; - if (chemflag) - ielem = map[itype]; - const double radi = radelem[itype]; + // currently, all grid points are type 1 - // rij[][3] = displacements between atom I and those neighbors - // inside = indices of neighbors of I within cutoff - // typej = types of neighbors of I within cutoff + const int itype = 1; + int ielem = 0; + if (chemflag) + ielem = map[itype]; + const double radi = radelem[itype]; - int ninside = 0; - for (int j = 0; j < ntotal; j++) { + // rij[][3] = displacements between atom I and those neighbors + // inside = indices of neighbors of I within cutoff + // typej = types of neighbors of I within cutoff - // check that j is in compute group + int ninside = 0; + for (int j = 0; j < ntotal; j++) { - if (!(mask[j] & groupbit)) continue; + // check that j is in compute group - const double delx = xtmp - x[j][0]; - const double dely = ytmp - x[j][1]; - const double delz = ztmp - x[j][2]; - const double rsq = delx*delx + dely*dely + delz*delz; - int jtype = type[j]; - int jelem = 0; - if (chemflag) - jelem = map[jtype]; - if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { - snaptr->rij[ninside][0] = delx; - snaptr->rij[ninside][1] = dely; - snaptr->rij[ninside][2] = delz; - snaptr->inside[ninside] = j; - snaptr->wj[ninside] = wjelem[jtype]; - snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; - if (switchinnerflag) { - snaptr->sinnerij[ninside] = sinnerelem[jelem]; - snaptr->dinnerij[ninside] = dinnerelem[jelem]; - } - if (chemflag) snaptr->element[ninside] = jelem; // element index for multi-element snap - ninside++; - } - } + if (!(mask[j] & groupbit)) continue; - snaptr->compute_ui(ninside, ielem); - snaptr->compute_zi(); - snaptr->compute_bi(ielem); + const double delx = xtmp - x[j][0]; + const double dely = ytmp - x[j][1]; + const double delz = ztmp - x[j][2]; + const double rsq = delx*delx + dely*dely + delz*delz; + int jtype = type[j]; + int jelem = 0; + if (chemflag) + jelem = map[jtype]; + if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { + snaptr->rij[ninside][0] = delx; + snaptr->rij[ninside][1] = dely; + snaptr->rij[ninside][2] = delz; + snaptr->inside[ninside] = j; + snaptr->wj[ninside] = wjelem[jtype]; + snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; + if (switchinnerflag) { + snaptr->sinnerij[ninside] = sinnerelem[jelem]; + snaptr->dinnerij[ninside] = dinnerelem[jelem]; + } + if (chemflag) snaptr->element[ninside] = jelem; // element index for multi-element snap + ninside++; + } + } - // linear contributions + snaptr->compute_ui(ninside, ielem); + snaptr->compute_zi(); + snaptr->compute_bi(ielem); - for (int icoeff = 0; icoeff < ncoeff; icoeff++) - alocal[igrid][size_local_cols_base+icoeff] = snaptr->blist[icoeff]; + // linear contributions - // quadratic contributions + for (int icoeff = 0; icoeff < ncoeff; icoeff++) + alocal[igrid][size_local_cols_base+icoeff] = snaptr->blist[icoeff]; - if (quadraticflag) { - int ncount = ncoeff; - for (int icoeff = 0; icoeff < ncoeff; icoeff++) { - double bveci = snaptr->blist[icoeff]; - alocal[igrid][size_local_cols_base+ncount++] = 0.5*bveci*bveci; - for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - alocal[igrid][size_local_cols_base+ncount++] = - bveci*snaptr->blist[jcoeff]; - } - } - igrid++; + // quadratic contributions + + if (quadraticflag) { + int ncount = ncoeff; + for (int icoeff = 0; icoeff < ncoeff; icoeff++) { + double bveci = snaptr->blist[icoeff]; + alocal[igrid][size_local_cols_base+ncount++] = 0.5*bveci*bveci; + for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) + alocal[igrid][size_local_cols_base+ncount++] = + bveci*snaptr->blist[jcoeff]; + } + } + igrid++; } } diff --git a/src/ML-SNAP/compute_sna_grid_local.h b/src/ML-SNAP/compute_sna_grid_local.h index 5ce40069ee..69a2c528fc 100644 --- a/src/ML-SNAP/compute_sna_grid_local.h +++ b/src/ML-SNAP/compute_sna_grid_local.h @@ -1,6 +1,6 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, Sandia National Laboratories + https://www.lammps.org/ Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract @@ -54,17 +54,3 @@ class ComputeSNAGridLocal : public ComputeGridLocal { #endif #endif - -/* ERROR/WARNING messages: - -E: Illegal ... command - -Self-explanatory. Check the input script syntax and compare to the -documentation for the command. You can use -echo screen as a -command-line option when running LAMMPS to see the offending line. - -W: More than one compute sna/grid/local - -Self-explanatory. - -*/ diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index dd21b731e8..60c9987cbc 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, Sandia National Laboratories + https://www.lammps.org/ Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract @@ -128,7 +128,7 @@ void ComputeGrid::allocate() if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { gridlocal_allocated = 1; memory->create4d_offset(gridlocal,size_array_cols,nzlo,nzhi,nylo,nyhi, - nxlo,nxhi,"grid:gridlocal"); + nxlo,nxhi,"grid:gridlocal"); } array = gridall; } @@ -179,7 +179,7 @@ void ComputeGrid::set_grid_global() delxinv = nx/xprd; delyinv = ny/yprd; delzinv = nz/zprd; - + delx = 1.0/delxinv; dely = 1.0/delyinv; delz = 1.0/delzinv; @@ -245,9 +245,9 @@ void ComputeGrid::set_grid_local() double ComputeGrid::memory_usage() { - double nbytes = size_array_rows*size_array_cols * + double nbytes = size_array_rows*size_array_cols * sizeof(double); // grid - nbytes += size_array_rows*size_array_cols * + nbytes += size_array_rows*size_array_cols * sizeof(double); // gridall nbytes += size_array_cols*ngridlocal*sizeof(double); // gridlocal return nbytes; diff --git a/src/compute_grid.h b/src/compute_grid.h index 7bda1a89fa..b0214b2b15 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -1,6 +1,6 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, Sandia National Laboratories + https://www.lammps.org/ Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract @@ -42,7 +42,7 @@ class ComputeGrid : public Compute { double *sublo, *subhi; // subdomain info (units real/ortho or reduced/tri) double delxinv,delyinv,delzinv; // inverse grid spacing double delx,dely,delz; // grid spacing - int nargbase; // number of base class args + int nargbase; // number of base class args double cutmax; // largest cutoff distance int size_array_cols_base; // number of columns used for coords, etc. int gridlocal_allocated; // shows if gridlocal allocated @@ -59,13 +59,3 @@ class ComputeGrid : public Compute { } #endif - -/* ERROR/WARNING messages: - -E: Illegal ... command - -Self-explanatory. Check the input script syntax and compare to the -documentation for the command. You can use -echo screen as a -command-line option when running LAMMPS to see the offending line. - -*/ diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index bcc56c3abd..e30d06fe45 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, Sandia National Laboratories + https://www.lammps.org/ Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract @@ -164,7 +164,7 @@ void ComputeGridLocal::set_grid_global() delxinv = nx/xprd; delyinv = ny/yprd; delzinv = nz/zprd; - + delx = 1.0/delxinv; dely = 1.0/delyinv; delz = 1.0/delzinv; @@ -233,34 +233,34 @@ void ComputeGridLocal::assign_coords() for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { - alocal[igrid][0] = ix; - alocal[igrid][1] = iy; - alocal[igrid][2] = iz; - double xgrid[3]; + alocal[igrid][0] = ix; + alocal[igrid][1] = iy; + alocal[igrid][2] = iz; + double xgrid[3]; - // for triclinic: create gridpoint in lamda coordinates and transform after check. - // for orthorombic: create gridpoint in box coordinates. + // for triclinic: create gridpoint in lamda coordinates and transform after check. + // for orthorombic: create gridpoint in box coordinates. - if (triclinic) - grid2lamda(ix, iy, iz, xgrid); - else - grid2x(ix, iy, iz, xgrid); + if (triclinic) + grid2lamda(ix, iy, iz, xgrid); + else + grid2x(ix, iy, iz, xgrid); - // ensure gridpoint is not strictly outside subdomain + // ensure gridpoint is not strictly outside subdomain - if ((sublo[0]-xgrid[0]) > EPSILON || (xgrid[0]-subhi[0]) > EPSILON || - (sublo[1]-xgrid[1]) > EPSILON || (xgrid[1]-subhi[1]) > EPSILON || - (sublo[2]-xgrid[2]) > EPSILON || (xgrid[2]-subhi[2]) > EPSILON) - error->one(FLERR,"Invalid gridpoint position in compute grid/local"); + if ((sublo[0]-xgrid[0]) > EPSILON || (xgrid[0]-subhi[0]) > EPSILON || + (sublo[1]-xgrid[1]) > EPSILON || (xgrid[1]-subhi[1]) > EPSILON || + (sublo[2]-xgrid[2]) > EPSILON || (xgrid[2]-subhi[2]) > EPSILON) + error->one(FLERR,"Invalid gridpoint position in compute grid/local"); - // convert lamda to x, y, z, after sudomain check + // convert lamda to x, y, z, after sudomain check - if (triclinic) domain->lamda2x(xgrid, xgrid); + if (triclinic) domain->lamda2x(xgrid, xgrid); - alocal[igrid][3] = xgrid[0]; - alocal[igrid][4] = xgrid[1]; - alocal[igrid][5] = xgrid[2]; - igrid++; + alocal[igrid][3] = xgrid[0]; + alocal[igrid][4] = xgrid[1]; + alocal[igrid][5] = xgrid[2]; + igrid++; } } diff --git a/src/compute_grid_local.h b/src/compute_grid_local.h index 15ea8ca47f..5c5611250b 100644 --- a/src/compute_grid_local.h +++ b/src/compute_grid_local.h @@ -1,6 +1,6 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, Sandia National Laboratories + https://www.lammps.org/ Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract @@ -39,7 +39,7 @@ class ComputeGridLocal : public Compute { double *sublo, *subhi; // subdomain info (units real/ortho or reduced/tri) double delxinv,delyinv,delzinv; // inverse grid spacing double delx,dely,delz; // grid spacing - int nargbase; // number of base class args + int nargbase; // number of base class args double cutmax; // largest cutoff distance int size_local_cols_base; // number of columns used for coords, etc. int gridlocal_allocated; // shows if gridlocal allocated @@ -57,13 +57,3 @@ class ComputeGridLocal : public Compute { } #endif - -/* ERROR/WARNING messages: - -E: Illegal ... command - -Self-explanatory. Check the input script syntax and compare to the -documentation for the command. You can use -echo screen as a -command-line option when running LAMMPS to see the offending line. - -*/ From 185d5cdc0fda9d6511b3084ff718998aff7eba09 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 17 Jun 2022 12:50:54 -0400 Subject: [PATCH 74/91] update .gitignore --- src/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/.gitignore b/src/.gitignore index de157734fc..198dcdc290 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -179,6 +179,10 @@ /compute_snad_atom.h /compute_snav_atom.cpp /compute_snav_atom.h +/compute_sna_grid.cpp +/compute_sna_grid.h +/compute_sna_grid_local.cpp +/compute_sna_grid_local.h /compute_snap.cpp /compute_snap.h /openmp_snap.h From dac99e462ffb7891c15a59074d39c89b53a1a5d4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 17 Jun 2022 13:04:25 -0400 Subject: [PATCH 75/91] update log files --- examples/snap/log.15Jun22.grid.snap.g++.1 | 46 +++++++++------------ examples/snap/log.15Jun22.grid.snap.g++.4 | 48 +++++++++------------- examples/snap/log.15Jun22.grid.tri.g++.1 | 50 ++++++++++------------- examples/snap/log.15Jun22.grid.tri.g++.4 | 50 ++++++++++------------- 4 files changed, 81 insertions(+), 113 deletions(-) diff --git a/examples/snap/log.15Jun22.grid.snap.g++.1 b/examples/snap/log.15Jun22.grid.snap.g++.1 index 71b884d1b6..ec2026b16e 100644 --- a/examples/snap/log.15Jun22.grid.snap.g++.1 +++ b/examples/snap/log.15Jun22.grid.snap.g++.1 @@ -1,4 +1,5 @@ -LAMMPS (28 Jul 2021) +LAMMPS (2 Jun 2022) + using 1 OpenMP thread(s) per MPI task # Demonstrate calculation of SNAP bispectrum descriptors on a grid # CORRECTNESS: The two atom positions coincide with two of @@ -27,17 +28,17 @@ boundary p p p lattice custom $a a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 lattice custom 3.316 a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 -Lattice spacing in x,y,z = 3.3160000 3.3160000 3.3160000 +Lattice spacing in x,y,z = 3.316 3.316 3.316 region box block 0 ${nx} 0 ${ny} 0 ${nz} region box block 0 1 0 ${ny} 0 ${nz} region box block 0 1 0 1 0 ${nz} region box block 0 1 0 1 0 1 create_box 1 box -Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (3.3160000 3.3160000 3.3160000) +Created orthogonal box = (0 0 0) to (3.316 3.316 3.316) 1 by 1 by 1 MPI processor grid create_atoms 1 box Created 2 atoms - using lattice units in orthogonal box = (0.0000000 0.0000000 0.0000000) to (3.3160000 3.3160000 3.3160000) + using lattice units in orthogonal box = (0 0 0) to (3.316 3.316 3.316) create_atoms CPU = 0.000 seconds mass 1 180.88 @@ -105,14 +106,15 @@ dump 2 all custom 1000 dump.batom id x y z c_b[*] # run run 0 -WARNING: No fixes defined, atoms won't move (src/verlet.cpp:55) +WARNING: No fixes with time integration, atoms won't move (src/verlet.cpp:60) +Generated 0 of 0 mixed pair_coeff terms from geometric mixing rule Neighbor list info ... update every 1 steps, delay 10 steps, check yes max neighbors/atom: 2000, page size: 100000 master list distance cutoff = 6.67637 ghost atom cutoff = 6.67637 binsize = 3.338185, bins = 1 1 1 - 4 neighbor lists, perpetual/occasional/extra = 1 3 0 + 2 neighbor lists, perpetual/occasional/extra = 1 1 0 (1) pair zero, perpetual attributes: half, newton on pair build: half/bin/atomonly/newton @@ -123,22 +125,12 @@ Neighbor list info ... pair build: full/bin/atomonly stencil: full/bin/3d bin: standard - (3) compute sna/grid, occasional - attributes: full, newton on - pair build: full/bin/atomonly - stencil: full/bin/3d - bin: standard - (4) compute sna/grid/local, occasional - attributes: full, newton on - pair build: full/bin/atomonly - stencil: full/bin/3d - bin: standard -Per MPI rank memory allocation (min/avg/max) = 8.384 | 8.384 | 8.384 Mbytes -Step v_B5atom v_B5grid v_rmse_global - 0 1.0427295 1.0427295 0 -Loop time of 1e-06 on 1 procs for 0 steps with 2 atoms +Per MPI rank memory allocation (min/avg/max) = 7.127 | 7.127 | 7.127 Mbytes + Step v_B5atom v_B5grid v_rmse_global + 0 1.0427295 1.0427295 9.1551336e-16 +Loop time of 1.43e-06 on 1 procs for 0 steps with 2 atoms -100.0% CPU use with 1 MPI tasks x no OpenMP threads +139.9% CPU use with 1 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total @@ -148,19 +140,19 @@ Neigh | 0 | 0 | 0 | 0.0 | 0.00 Comm | 0 | 0 | 0 | 0.0 | 0.00 Output | 0 | 0 | 0 | 0.0 | 0.00 Modify | 0 | 0 | 0 | 0.0 | 0.00 -Other | | 1e-06 | | |100.00 +Other | | 1.43e-06 | | |100.00 -Nlocal: 2.00000 ave 2 max 2 min +Nlocal: 2 ave 2 max 2 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Nghost: 339.000 ave 339 max 339 min +Nghost: 339 ave 339 max 339 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Neighs: 64.0000 ave 64 max 64 min +Neighs: 64 ave 64 max 64 min Histogram: 1 0 0 0 0 0 0 0 0 0 -FullNghs: 128.000 ave 128 max 128 min +FullNghs: 128 ave 128 max 128 min Histogram: 1 0 0 0 0 0 0 0 0 0 Total # of neighbors = 128 -Ave neighs/atom = 64.000000 +Ave neighs/atom = 64 Neighbor list builds = 0 Dangerous builds = 0 diff --git a/examples/snap/log.15Jun22.grid.snap.g++.4 b/examples/snap/log.15Jun22.grid.snap.g++.4 index 80761fc395..5be17ada7d 100644 --- a/examples/snap/log.15Jun22.grid.snap.g++.4 +++ b/examples/snap/log.15Jun22.grid.snap.g++.4 @@ -1,4 +1,5 @@ -LAMMPS (28 Jul 2021) +LAMMPS (2 Jun 2022) + using 1 OpenMP thread(s) per MPI task # Demonstrate calculation of SNAP bispectrum descriptors on a grid # CORRECTNESS: The two atom positions coincide with two of @@ -27,17 +28,17 @@ boundary p p p lattice custom $a a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 lattice custom 3.316 a1 1 0 0 a2 0 1 0 a3 0 0 1 basis 0 0 0 basis 0.5 0.5 0.5 -Lattice spacing in x,y,z = 3.3160000 3.3160000 3.3160000 +Lattice spacing in x,y,z = 3.316 3.316 3.316 region box block 0 ${nx} 0 ${ny} 0 ${nz} region box block 0 1 0 ${ny} 0 ${nz} region box block 0 1 0 1 0 ${nz} region box block 0 1 0 1 0 1 create_box 1 box -Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (3.3160000 3.3160000 3.3160000) +Created orthogonal box = (0 0 0) to (3.316 3.316 3.316) 1 by 2 by 2 MPI processor grid create_atoms 1 box Created 2 atoms - using lattice units in orthogonal box = (0.0000000 0.0000000 0.0000000) to (3.3160000 3.3160000 3.3160000) + using lattice units in orthogonal box = (0 0 0) to (3.316 3.316 3.316) create_atoms CPU = 0.001 seconds mass 1 180.88 @@ -105,14 +106,15 @@ dump 2 all custom 1000 dump.batom id x y z c_b[*] # run run 0 -WARNING: No fixes defined, atoms won't move (src/verlet.cpp:55) +WARNING: No fixes with time integration, atoms won't move (src/verlet.cpp:60) +Generated 0 of 0 mixed pair_coeff terms from geometric mixing rule Neighbor list info ... update every 1 steps, delay 10 steps, check yes max neighbors/atom: 2000, page size: 100000 master list distance cutoff = 6.67637 ghost atom cutoff = 6.67637 binsize = 3.338185, bins = 1 1 1 - 4 neighbor lists, perpetual/occasional/extra = 1 3 0 + 2 neighbor lists, perpetual/occasional/extra = 1 1 0 (1) pair zero, perpetual attributes: half, newton on pair build: half/bin/atomonly/newton @@ -123,23 +125,13 @@ Neighbor list info ... pair build: full/bin/atomonly stencil: full/bin/3d bin: standard - (3) compute sna/grid, occasional - attributes: full, newton on - pair build: full/bin/atomonly - stencil: full/bin/3d - bin: standard - (4) compute sna/grid/local, occasional - attributes: full, newton on - pair build: full/bin/atomonly - stencil: full/bin/3d - bin: standard -WARNING: Proc sub-domain size < neighbor skin, could lead to lost atoms (src/domain.cpp:964) -Per MPI rank memory allocation (min/avg/max) = 7.381 | 7.889 | 8.397 Mbytes -Step v_B5atom v_B5grid v_rmse_global - 0 1.0427295 1.0427295 0 -Loop time of 1.5e-06 on 4 procs for 0 steps with 2 atoms +WARNING: Proc sub-domain size < neighbor skin, could lead to lost atoms (src/domain.cpp:970) +Per MPI rank memory allocation (min/avg/max) = 6.123 | 6.631 | 7.139 Mbytes + Step v_B5atom v_B5grid v_rmse_global + 0 1.0427295 1.0427295 1.6316879e-15 +Loop time of 2.57125e-06 on 4 procs for 0 steps with 2 atoms -83.3% CPU use with 4 MPI tasks x no OpenMP threads +107.0% CPU use with 4 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total @@ -149,19 +141,19 @@ Neigh | 0 | 0 | 0 | 0.0 | 0.00 Comm | 0 | 0 | 0 | 0.0 | 0.00 Output | 0 | 0 | 0 | 0.0 | 0.00 Modify | 0 | 0 | 0 | 0.0 | 0.00 -Other | | 1.5e-06 | | |100.00 +Other | | 2.571e-06 | | |100.00 -Nlocal: 0.500000 ave 1 max 0 min +Nlocal: 0.5 ave 1 max 0 min Histogram: 2 0 0 0 0 0 0 0 0 2 -Nghost: 274.500 ave 275 max 274 min +Nghost: 274.5 ave 275 max 274 min Histogram: 2 0 0 0 0 0 0 0 0 2 -Neighs: 16.0000 ave 40 max 0 min +Neighs: 16 ave 40 max 0 min Histogram: 2 0 0 0 0 0 1 0 0 1 -FullNghs: 32.0000 ave 64 max 0 min +FullNghs: 32 ave 64 max 0 min Histogram: 2 0 0 0 0 0 0 0 0 2 Total # of neighbors = 128 -Ave neighs/atom = 64.000000 +Ave neighs/atom = 64 Neighbor list builds = 0 Dangerous builds = 0 diff --git a/examples/snap/log.15Jun22.grid.tri.g++.1 b/examples/snap/log.15Jun22.grid.tri.g++.1 index c261154367..e26315235b 100644 --- a/examples/snap/log.15Jun22.grid.tri.g++.1 +++ b/examples/snap/log.15Jun22.grid.tri.g++.1 @@ -1,4 +1,5 @@ -LAMMPS (28 Jul 2021) +LAMMPS (2 Jun 2022) + using 1 OpenMP thread(s) per MPI task # Demonstrate calculation of SNAP bispectrum # descriptors on a grid for triclinic cell @@ -51,7 +52,7 @@ boundary p p p lattice custom $a a1 1 0 0 a2 1 1 0 a3 1 1 1 basis 0 0 0 basis 0.0 0.0 0.5 spacing 1 1 1 lattice custom 3.316 a1 1 0 0 a2 1 1 0 a3 1 1 1 basis 0 0 0 basis 0.0 0.0 0.5 spacing 1 1 1 -Lattice spacing in x,y,z = 3.3160000 3.3160000 3.3160000 +Lattice spacing in x,y,z = 3.316 3.316 3.316 box tilt large region box prism 0 ${nx} 0 ${ny} 0 ${nz} ${ny} ${nz} ${nz} @@ -62,13 +63,13 @@ region box prism 0 3 0 2 0 1 2 ${nz} ${nz} region box prism 0 3 0 2 0 1 2 1 ${nz} region box prism 0 3 0 2 0 1 2 1 1 create_box 1 box -Created triclinic box = (0.0000000 0.0000000 0.0000000) to (9.9480000 6.6320000 3.3160000) with tilt (6.6320000 3.3160000 3.3160000) -WARNING: Triclinic box skew is large (src/domain.cpp:219) +Created triclinic box = (0 0 0) to (9.948 6.632 3.316) with tilt (6.632 3.316 3.316) +WARNING: Triclinic box skew is large (src/domain.cpp:224) 1 by 1 by 1 MPI processor grid create_atoms 1 box Created 12 atoms - using lattice units in triclinic box = (0.0000000 0.0000000 0.0000000) to (9.9480000 6.6320000 3.3160000) with tilt (6.6320000 3.3160000 3.3160000) - create_atoms CPU = 0.001 seconds + using lattice units in triclinic box = (0 0 0) to (9.948 6.632 3.316) with tilt (6.632 3.316 3.316) + create_atoms CPU = 0.000 seconds mass 1 180.88 @@ -138,14 +139,15 @@ dump 2 all custom 1000 dump.batom.tri id x y z c_b[*] # run run 0 -WARNING: No fixes defined, atoms won't move (src/verlet.cpp:55) +WARNING: No fixes with time integration, atoms won't move (src/verlet.cpp:60) +Generated 0 of 0 mixed pair_coeff terms from geometric mixing rule Neighbor list info ... update every 1 steps, delay 10 steps, check yes max neighbors/atom: 2000, page size: 100000 master list distance cutoff = 6.67637 ghost atom cutoff = 6.67637 binsize = 3.338185, bins = 6 3 1 - 4 neighbor lists, perpetual/occasional/extra = 1 3 0 + 2 neighbor lists, perpetual/occasional/extra = 1 1 0 (1) pair zero, perpetual attributes: half, newton on pair build: half/bin/newton/tri @@ -156,22 +158,12 @@ Neighbor list info ... pair build: full/bin/atomonly stencil: full/bin/3d bin: standard - (3) compute sna/grid, occasional - attributes: full, newton on - pair build: full/bin/atomonly - stencil: full/bin/3d - bin: standard - (4) compute sna/grid/local, occasional - attributes: full, newton on - pair build: full/bin/atomonly - stencil: full/bin/3d - bin: standard -Per MPI rank memory allocation (min/avg/max) = 8.435 | 8.435 | 8.435 Mbytes -Step v_B5atom v_B5grid v_rmse_global - 0 1.0427295 1.0427295 7.2262471e-14 -Loop time of 1e-06 on 1 procs for 0 steps with 12 atoms +Per MPI rank memory allocation (min/avg/max) = 7.183 | 7.183 | 7.183 Mbytes + Step v_B5atom v_B5grid v_rmse_global + 0 1.0427295 1.0427295 7.2262471e-14 +Loop time of 1.414e-06 on 1 procs for 0 steps with 12 atoms -100.0% CPU use with 1 MPI tasks x no OpenMP threads +70.7% CPU use with 1 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total @@ -181,19 +173,19 @@ Neigh | 0 | 0 | 0 | 0.0 | 0.00 Comm | 0 | 0 | 0 | 0.0 | 0.00 Output | 0 | 0 | 0 | 0.0 | 0.00 Modify | 0 | 0 | 0 | 0.0 | 0.00 -Other | | 1e-06 | | |100.00 +Other | | 1.414e-06 | | |100.00 -Nlocal: 12.0000 ave 12 max 12 min +Nlocal: 12 ave 12 max 12 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Nghost: 604.000 ave 604 max 604 min +Nghost: 604 ave 604 max 604 min Histogram: 1 0 0 0 0 0 0 0 0 0 -Neighs: 384.000 ave 384 max 384 min +Neighs: 384 ave 384 max 384 min Histogram: 1 0 0 0 0 0 0 0 0 0 -FullNghs: 768.000 ave 768 max 768 min +FullNghs: 768 ave 768 max 768 min Histogram: 1 0 0 0 0 0 0 0 0 0 Total # of neighbors = 768 -Ave neighs/atom = 64.000000 +Ave neighs/atom = 64 Neighbor list builds = 0 Dangerous builds = 0 diff --git a/examples/snap/log.15Jun22.grid.tri.g++.4 b/examples/snap/log.15Jun22.grid.tri.g++.4 index bac7ecaa5a..cee3ce7f12 100644 --- a/examples/snap/log.15Jun22.grid.tri.g++.4 +++ b/examples/snap/log.15Jun22.grid.tri.g++.4 @@ -1,4 +1,5 @@ -LAMMPS (28 Jul 2021) +LAMMPS (2 Jun 2022) + using 1 OpenMP thread(s) per MPI task # Demonstrate calculation of SNAP bispectrum # descriptors on a grid for triclinic cell @@ -51,7 +52,7 @@ boundary p p p lattice custom $a a1 1 0 0 a2 1 1 0 a3 1 1 1 basis 0 0 0 basis 0.0 0.0 0.5 spacing 1 1 1 lattice custom 3.316 a1 1 0 0 a2 1 1 0 a3 1 1 1 basis 0 0 0 basis 0.0 0.0 0.5 spacing 1 1 1 -Lattice spacing in x,y,z = 3.3160000 3.3160000 3.3160000 +Lattice spacing in x,y,z = 3.316 3.316 3.316 box tilt large region box prism 0 ${nx} 0 ${ny} 0 ${nz} ${ny} ${nz} ${nz} @@ -62,13 +63,13 @@ region box prism 0 3 0 2 0 1 2 ${nz} ${nz} region box prism 0 3 0 2 0 1 2 1 ${nz} region box prism 0 3 0 2 0 1 2 1 1 create_box 1 box -Created triclinic box = (0.0000000 0.0000000 0.0000000) to (9.9480000 6.6320000 3.3160000) with tilt (6.6320000 3.3160000 3.3160000) -WARNING: Triclinic box skew is large (src/domain.cpp:219) +Created triclinic box = (0 0 0) to (9.948 6.632 3.316) with tilt (6.632 3.316 3.316) +WARNING: Triclinic box skew is large (src/domain.cpp:224) 2 by 2 by 1 MPI processor grid create_atoms 1 box Created 12 atoms - using lattice units in triclinic box = (0.0000000 0.0000000 0.0000000) to (9.9480000 6.6320000 3.3160000) with tilt (6.6320000 3.3160000 3.3160000) - create_atoms CPU = 0.001 seconds + using lattice units in triclinic box = (0 0 0) to (9.948 6.632 3.316) with tilt (6.632 3.316 3.316) + create_atoms CPU = 0.000 seconds mass 1 180.88 @@ -138,14 +139,15 @@ dump 2 all custom 1000 dump.batom.tri id x y z c_b[*] # run run 0 -WARNING: No fixes defined, atoms won't move (src/verlet.cpp:55) +WARNING: No fixes with time integration, atoms won't move (src/verlet.cpp:60) +Generated 0 of 0 mixed pair_coeff terms from geometric mixing rule Neighbor list info ... update every 1 steps, delay 10 steps, check yes max neighbors/atom: 2000, page size: 100000 master list distance cutoff = 6.67637 ghost atom cutoff = 6.67637 binsize = 3.338185, bins = 6 3 1 - 4 neighbor lists, perpetual/occasional/extra = 1 3 0 + 2 neighbor lists, perpetual/occasional/extra = 1 1 0 (1) pair zero, perpetual attributes: half, newton on pair build: half/bin/newton/tri @@ -156,22 +158,12 @@ Neighbor list info ... pair build: full/bin/atomonly stencil: full/bin/3d bin: standard - (3) compute sna/grid, occasional - attributes: full, newton on - pair build: full/bin/atomonly - stencil: full/bin/3d - bin: standard - (4) compute sna/grid/local, occasional - attributes: full, newton on - pair build: full/bin/atomonly - stencil: full/bin/3d - bin: standard -Per MPI rank memory allocation (min/avg/max) = 8.405 | 8.405 | 8.405 Mbytes -Step v_B5atom v_B5grid v_rmse_global - 0 1.0427295 1.0427295 2.1052124e-14 -Loop time of 1.25e-06 on 4 procs for 0 steps with 12 atoms +Per MPI rank memory allocation (min/avg/max) = 7.15 | 7.15 | 7.15 Mbytes + Step v_B5atom v_B5grid v_rmse_global + 0 1.0427295 1.0427295 1.9367585e-14 +Loop time of 2.65825e-06 on 4 procs for 0 steps with 12 atoms -140.0% CPU use with 4 MPI tasks x no OpenMP threads +84.6% CPU use with 4 MPI tasks x 1 OpenMP threads MPI task timing breakdown: Section | min time | avg time | max time |%varavg| %total @@ -181,19 +173,19 @@ Neigh | 0 | 0 | 0 | 0.0 | 0.00 Comm | 0 | 0 | 0 | 0.0 | 0.00 Output | 0 | 0 | 0 | 0.0 | 0.00 Modify | 0 | 0 | 0 | 0.0 | 0.00 -Other | | 1.25e-06 | | |100.00 +Other | | 2.658e-06 | | |100.00 -Nlocal: 3.00000 ave 4 max 2 min +Nlocal: 3 ave 4 max 2 min Histogram: 2 0 0 0 0 0 0 0 0 2 -Nghost: 459.000 ave 460 max 458 min +Nghost: 459 ave 460 max 458 min Histogram: 2 0 0 0 0 0 0 0 0 2 -Neighs: 96.0000 ave 128 max 64 min +Neighs: 96 ave 128 max 64 min Histogram: 2 0 0 0 0 0 0 0 0 2 -FullNghs: 192.000 ave 256 max 128 min +FullNghs: 192 ave 256 max 128 min Histogram: 2 0 0 0 0 0 0 0 0 2 Total # of neighbors = 768 -Ave neighs/atom = 64.000000 +Ave neighs/atom = 64 Neighbor list builds = 0 Dangerous builds = 0 From 5b9c4069e976edbcc0a7d45e20eec42c4a0f52d1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 17 Jun 2022 13:25:29 -0400 Subject: [PATCH 76/91] make headers clang-format compatible and use override keywords --- src/ML-SNAP/compute_sna_grid.h | 16 ++++++++-------- src/ML-SNAP/compute_sna_grid_local.h | 16 ++++++++-------- src/compute_grid.h | 11 +++++------ src/compute_grid_local.h | 11 +++++------ 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.h b/src/ML-SNAP/compute_sna_grid.h index 9bc3da8112..750f779a00 100644 --- a/src/ML-SNAP/compute_sna_grid.h +++ b/src/ML-SNAP/compute_sna_grid.h @@ -12,9 +12,9 @@ ------------------------------------------------------------------------- */ #ifdef COMPUTE_CLASS - -ComputeStyle(sna/grid,ComputeSNAGrid) - +// clang-format off +ComputeStyle(sna/grid,ComputeSNAGrid); +// clang-format on #else #ifndef LMP_COMPUTE_SNA_GRID_H @@ -27,11 +27,11 @@ namespace LAMMPS_NS { class ComputeSNAGrid : public ComputeGrid { public: ComputeSNAGrid(class LAMMPS *, int, char **); - ~ComputeSNAGrid(); - void init(); - void init_list(int, class NeighList *); - void compute_array(); - double memory_usage(); + ~ComputeSNAGrid() override; + void init() override; + void init_list(int, class NeighList *) override; + void compute_array() override; + double memory_usage() override; private: int ncoeff; diff --git a/src/ML-SNAP/compute_sna_grid_local.h b/src/ML-SNAP/compute_sna_grid_local.h index 69a2c528fc..c7678d049e 100644 --- a/src/ML-SNAP/compute_sna_grid_local.h +++ b/src/ML-SNAP/compute_sna_grid_local.h @@ -12,9 +12,9 @@ ------------------------------------------------------------------------- */ #ifdef COMPUTE_CLASS - -ComputeStyle(sna/grid/local,ComputeSNAGridLocal) - +// clang-format off +ComputeStyle(sna/grid/local,ComputeSNAGridLocal); +// clang-format on #else #ifndef LMP_COMPUTE_SNA_GRID_LOCAL_H @@ -27,11 +27,11 @@ namespace LAMMPS_NS { class ComputeSNAGridLocal : public ComputeGridLocal { public: ComputeSNAGridLocal(class LAMMPS *, int, char **); - ~ComputeSNAGridLocal(); - void init(); - void init_list(int, class NeighList *); - void compute_local(); - double memory_usage(); + ~ComputeSNAGridLocal() override; + void init() override; + void init_list(int, class NeighList *) override; + void compute_local() override; + double memory_usage() override; private: int ncoeff; diff --git a/src/compute_grid.h b/src/compute_grid.h index b0214b2b15..4264039cc8 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -22,12 +22,12 @@ class ComputeGrid : public Compute { public: ComputeGrid(class LAMMPS *, int, char **); - virtual ~ComputeGrid(); - void init(); - void setup(); - virtual void compute_array() = 0; + ~ComputeGrid() override; + void init() override; + void setup() override; + void compute_array() override = 0; - double memory_usage(); + double memory_usage() override; protected: int nx, ny, nz; // global grid dimensions @@ -53,7 +53,6 @@ class ComputeGrid : public Compute { void assign_coords_all(); // assign coords for global grid void set_grid_global(); // set global grid void set_grid_local(); // set bounds for local grid - private: }; } diff --git a/src/compute_grid_local.h b/src/compute_grid_local.h index 5c5611250b..2989628d79 100644 --- a/src/compute_grid_local.h +++ b/src/compute_grid_local.h @@ -22,12 +22,12 @@ class ComputeGridLocal : public Compute { public: ComputeGridLocal(class LAMMPS *, int, char **); - virtual ~ComputeGridLocal(); - void init(); - void setup(); - virtual void compute_local() = 0; + ~ComputeGridLocal() override; + void init() override; + void setup() override; + void compute_local() override = 0; - double memory_usage(); + double memory_usage() override; protected: int nx, ny, nz; // global grid dimensions @@ -51,7 +51,6 @@ class ComputeGridLocal : public Compute { void set_grid_global(); // set global grid void set_grid_local(); // set bounds for local grid void assign_coords(); // assign coords for grid - private: }; } From d9646ee537d642f72e3de20b4c3cf26d94c44a3d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 17 Jun 2022 13:25:40 -0400 Subject: [PATCH 77/91] remove dead code --- src/ML-SNAP/compute_sna_grid.cpp | 1 - src/ML-SNAP/compute_sna_grid_local.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 8247771493..5ea49469e2 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -255,7 +255,6 @@ void ComputeSNAGrid::compute_array() int ielem = 0; if (chemflag) ielem = map[itype]; - const double radi = radelem[itype]; // rij[][3] = displacements between atom I and those neighbors // inside = indices of neighbors of I within cutoff diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index 70b5b362d8..614880043c 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -254,7 +254,6 @@ void ComputeSNAGridLocal::compute_local() int ielem = 0; if (chemflag) ielem = map[itype]; - const double radi = radelem[itype]; // rij[][3] = displacements between atom I and those neighbors // inside = indices of neighbors of I within cutoff From 9fd6bde0ed8f5f1c040d67b2c0f8c3092e13db7a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 17 Jun 2022 13:47:23 -0400 Subject: [PATCH 78/91] enable and apply clang-format --- src/ML-SNAP/compute_sna_grid.cpp | 200 ++++++++++++------------- src/ML-SNAP/compute_sna_grid.h | 2 +- src/ML-SNAP/compute_sna_grid_local.cpp | 193 +++++++++++------------- src/ML-SNAP/compute_sna_grid_local.h | 2 +- src/compute_grid.cpp | 121 +++++++-------- src/compute_grid.h | 47 +++--- src/compute_grid_local.cpp | 107 +++++++------ src/compute_grid_local.h | 43 +++--- 8 files changed, 337 insertions(+), 378 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 5ea49469e2..e182b16d64 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -11,22 +11,22 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "compute_grid.h" #include "compute_sna_grid.h" -#include "sna.h" + #include "atom.h" -#include "update.h" +#include "comm.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "modify.h" -#include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" -#include "force.h" +#include "neighbor.h" #include "pair.h" -#include "domain.h" -#include "comm.h" -#include "memory.h" -#include "error.h" +#include "sna.h" #include "tokenizer.h" +#include "update.h" #include #include @@ -34,8 +34,7 @@ using namespace LAMMPS_NS; ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : - ComputeGrid(lmp, narg, arg), cutsq(nullptr), - radelem(nullptr), wjelem(nullptr) + ComputeGrid(lmp, narg, arg), cutsq(nullptr), radelem(nullptr), wjelem(nullptr) { double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; @@ -48,9 +47,9 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : narg -= nargbase; int ntypes = atom->ntypes; - int nargmin = 6+2*ntypes; + int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR,"Illegal compute sna/grid command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute sna/grid command"); // default values @@ -66,30 +65,28 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem,ntypes+1,"sna/grid:radelem"); // offset by 1 to match up with types - memory->create(wjelem,ntypes+1,"sna/grid:wjelem"); + memory->create(radelem, ntypes + 1, "sna/grid:radelem"); // offset by 1 to match up with types + memory->create(wjelem, ntypes + 1, "sna/grid:wjelem"); rcutfac = atof(arg[3]); rfac0 = atof(arg[4]); twojmax = atoi(arg[5]); - for(int i = 0; i < ntypes; i++) - radelem[i+1] = atof(arg[6+i]); - for(int i = 0; i < ntypes; i++) - wjelem[i+1] = atof(arg[6+ntypes+i]); + for (int i = 0; i < ntypes; i++) radelem[i + 1] = atof(arg[6 + i]); + for (int i = 0; i < ntypes; i++) wjelem[i + 1] = atof(arg[6 + ntypes + i]); // construct cutsq double cut; cutmax = 0.0; - memory->create(cutsq,ntypes+1,ntypes+1,"sna/grid:cutsq"); - for(int i = 1; i <= ntypes; i++) { - cut = 2.0*radelem[i]*rcutfac; + memory->create(cutsq, ntypes + 1, ntypes + 1, "sna/grid:cutsq"); + for (int i = 1; i <= ntypes; i++) { + cut = 2.0 * radelem[i] * rcutfac; if (cut > cutmax) cutmax = cut; - cutsq[i][i] = cut*cut; - for(int j = i+1; j <= ntypes; j++) { - cut = (radelem[i]+radelem[j])*rcutfac; - cutsq[i][j] = cutsq[j][i] = cut*cut; + cutsq[i][i] = cut * cut; + for (int j = i + 1; j <= ntypes; j++) { + cut = (radelem[i] + radelem[j]) * rcutfac; + cutsq[i][j] = cutsq[j][i] = cut * cut; } } @@ -103,90 +100,81 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : int iarg = nargmin; while (iarg < narg) { - if (strcmp(arg[iarg],"rmin0") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid command"); - rmin0 = atof(arg[iarg+1]); + if (strcmp(arg[iarg], "rmin0") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); + rmin0 = atof(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"switchflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid command"); - switchflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); + switchflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"bzeroflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid command"); - bzeroflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "bzeroflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); + bzeroflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"quadraticflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid command"); - quadraticflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "quadraticflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); + quadraticflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"chem") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid command"); + } else if (strcmp(arg[iarg], "chem") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); chemflag = 1; - memory->create(map,ntypes+1,"compute_sna_grid:map"); - nelements = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + memory->create(map, ntypes + 1, "compute_sna_grid:map"); + nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { - int jelem = utils::inumeric(FLERR,arg[iarg+2+i],false,lmp); - if (jelem < 0 || jelem >= nelements) - error->all(FLERR,"Illegal compute sna/grid command"); - map[i+1] = jelem; + int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute sna/grid command"); + map[i + 1] = jelem; } - iarg += 2+ntypes; - } else if (strcmp(arg[iarg],"bnormflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid command"); - bnormflag = atoi(arg[iarg+1]); + iarg += 2 + ntypes; + } else if (strcmp(arg[iarg], "bnormflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); + bnormflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"wselfallflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid command"); - wselfallflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "wselfallflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); + wselfallflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid command"); - switchinnerflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); + switchinnerflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"sinner") == 0) { + } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute sna/grid command"); - memory->create(sinnerelem,ntypes+1,"snap:sinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute sna/grid command"); + memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) - sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); sinnerflag = 1; iarg += ntypes; - } else if (strcmp(arg[iarg],"dinner") == 0) { + } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute sna/grid command"); - memory->create(dinnerelem,ntypes+1,"snap:dinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute sna/grid command"); + memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) - dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; - } else error->all(FLERR,"Illegal compute sna/grid command"); - + } else + error->all(FLERR, "Illegal compute sna/grid command"); } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all(FLERR,"Illegal compute sna/grid command: switchinnerflag = 1, missing sinner/dinner keyword"); + error->all( + FLERR, + "Illegal compute sna/grid command: switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all(FLERR,"Illegal compute sna/grid command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + error->all( + FLERR, + "Illegal compute sna/grid command: switchinnerflag = 0, unexpected sinner/dinner keyword"); - snaptr = new SNA(lmp, rfac0, twojmax, - rmin0, switchflag, bzeroflag, - chemflag, bnormflag, wselfallflag, - nelements, switchinnerflag); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, + wselfallflag, nelements, switchinnerflag); ncoeff = snaptr->ncoeff; nvalues = ncoeff; - if (quadraticflag) nvalues += (ncoeff*(ncoeff+1))/2; + if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; size_array_cols = size_array_cols_base + nvalues; array_flag = 1; } @@ -209,9 +197,8 @@ void ComputeSNAGrid::init() { int count = 0; for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style,"sna/grid") == 0) count++; - if (count > 1 && comm->me == 0) - error->warning(FLERR,"More than one compute sna/grid"); + if (strcmp(modify->compute[i]->style, "sna/grid") == 0) count++; + if (count > 1 && comm->me == 0) error->warning(FLERR, "More than one compute sna/grid"); snaptr->init(); } @@ -230,9 +217,9 @@ void ComputeSNAGrid::compute_array() // compute sna for each gridpoint - double** const x = atom->x; - const int* const mask = atom->mask; - int * const type = atom->type; + double **const x = atom->x; + const int *const mask = atom->mask; + int *const type = atom->type; const int ntotal = atom->nlocal + atom->nghost; // insure rij, inside, and typej are of size jnum @@ -243,7 +230,7 @@ void ComputeSNAGrid::compute_array() for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { double xgrid[3]; - const int igrid = iz*(nx*ny) + iy*nx + ix; + const int igrid = iz * (nx * ny) + iy * nx + ix; grid2x(igrid, xgrid); const double xtmp = xgrid[0]; const double ytmp = xgrid[1]; @@ -253,8 +240,7 @@ void ComputeSNAGrid::compute_array() const int itype = 1; int ielem = 0; - if (chemflag) - ielem = map[itype]; + if (chemflag) ielem = map[itype]; // rij[][3] = displacements between atom I and those neighbors // inside = indices of neighbors of I within cutoff @@ -270,11 +256,10 @@ void ComputeSNAGrid::compute_array() const double delx = xtmp - x[j][0]; const double dely = ytmp - x[j][1]; const double delz = ztmp - x[j][2]; - const double rsq = delx*delx + dely*dely + delz*delz; + const double rsq = delx * delx + dely * dely + delz * delz; int jtype = type[j]; int jelem = 0; - if (chemflag) - jelem = map[jtype]; + if (chemflag) jelem = map[jtype]; if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { snaptr->rij[ninside][0] = delx; @@ -282,7 +267,7 @@ void ComputeSNAGrid::compute_array() snaptr->rij[ninside][2] = delz; snaptr->inside[ninside] = j; snaptr->wj[ninside] = wjelem[jtype]; - snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; + snaptr->rcutij[ninside] = 2.0 * radelem[jtype] * rcutfac; if (switchinnerflag) { snaptr->sinnerij[ninside] = sinnerelem[jelem]; snaptr->dinnerij[ninside] = dinnerelem[jelem]; @@ -299,7 +284,7 @@ void ComputeSNAGrid::compute_array() // linear contributions for (int icoeff = 0; icoeff < ncoeff; icoeff++) - gridlocal[size_array_cols_base+icoeff][iz][iy][ix] = snaptr->blist[icoeff]; + gridlocal[size_array_cols_base + icoeff][iz][iy][ix] = snaptr->blist[icoeff]; // quadratic contributions @@ -307,28 +292,28 @@ void ComputeSNAGrid::compute_array() int ncount = ncoeff; for (int icoeff = 0; icoeff < ncoeff; icoeff++) { double bveci = snaptr->blist[icoeff]; - gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = 0.5*bveci*bveci; - for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - gridlocal[size_array_cols_base+ncount++][iz][iy][ix] = bveci*snaptr->blist[jcoeff]; + gridlocal[size_array_cols_base + ncount++][iz][iy][ix] = 0.5 * bveci * bveci; + for (int jcoeff = icoeff + 1; jcoeff < ncoeff; jcoeff++) + gridlocal[size_array_cols_base + ncount++][iz][iy][ix] = + bveci * snaptr->blist[jcoeff]; } } } - memset(&grid[0][0],0,size_array_rows*size_array_cols*sizeof(double)); + memset(&grid[0][0], 0, size_array_rows * size_array_cols * sizeof(double)); for (int iz = nzlo; iz <= nzhi; iz++) for (int iy = nylo; iy <= nyhi; iy++) for (int ix = nxlo; ix <= nxhi; ix++) { - const int igrid = iz*(nx*ny) + iy*nx + ix; + const int igrid = iz * (nx * ny) + iy * nx + ix; for (int j = 0; j < nvalues; j++) grid[igrid][size_array_cols_base + j] = gridlocal[size_array_cols_base + j][iz][iy][ix]; } - MPI_Allreduce(&grid[0][0],&gridall[0][0],size_array_rows*size_array_cols,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&grid[0][0], &gridall[0][0], size_array_rows * size_array_cols, MPI_DOUBLE, MPI_SUM, + world); assign_coords_all(); - } - /* ---------------------------------------------------------------------- memory usage ------------------------------------------------------------------------- */ @@ -336,9 +321,8 @@ void ComputeSNAGrid::compute_array() double ComputeSNAGrid::memory_usage() { double nbytes = snaptr->memory_usage(); // SNA object - int n = atom->ntypes+1; - nbytes += (double)n*sizeof(int); // map + int n = atom->ntypes + 1; + nbytes += (double) n * sizeof(int); // map return nbytes; } - diff --git a/src/ML-SNAP/compute_sna_grid.h b/src/ML-SNAP/compute_sna_grid.h index 750f779a00..7eef027ef7 100644 --- a/src/ML-SNAP/compute_sna_grid.h +++ b/src/ML-SNAP/compute_sna_grid.h @@ -50,7 +50,7 @@ class ComputeSNAGrid : public ComputeGrid { int quadraticflag; }; -} +} // namespace LAMMPS_NS #endif #endif diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index 614880043c..7359acacbf 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -11,22 +11,22 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "compute_grid_local.h" #include "compute_sna_grid_local.h" -#include "sna.h" + #include "atom.h" -#include "update.h" +#include "comm.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "modify.h" -#include "neighbor.h" #include "neigh_list.h" #include "neigh_request.h" -#include "force.h" +#include "neighbor.h" #include "pair.h" -#include "domain.h" -#include "comm.h" -#include "memory.h" -#include "error.h" +#include "sna.h" #include "tokenizer.h" +#include "update.h" #include #include @@ -34,8 +34,7 @@ using namespace LAMMPS_NS; ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : - ComputeGridLocal(lmp, narg, arg), cutsq(nullptr), - radelem(nullptr), wjelem(nullptr) + ComputeGridLocal(lmp, narg, arg), cutsq(nullptr), radelem(nullptr), wjelem(nullptr) { double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; @@ -48,9 +47,9 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : narg -= nargbase; int ntypes = atom->ntypes; - int nargmin = 6+2*ntypes; + int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR,"Illegal compute sna/grid/local command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute sna/grid/local command"); // default values @@ -71,30 +70,29 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem,ntypes+1,"sna/grid/local:radelem"); // offset by 1 to match up with types - memory->create(wjelem,ntypes+1,"sna/grid/local:wjelem"); + memory->create(radelem, ntypes + 1, + "sna/grid/local:radelem"); // offset by 1 to match up with types + memory->create(wjelem, ntypes + 1, "sna/grid/local:wjelem"); rcutfac = atof(arg[3]); rfac0 = atof(arg[4]); twojmax = atoi(arg[5]); - for(int i = 0; i < ntypes; i++) - radelem[i+1] = atof(arg[6+i]); - for(int i = 0; i < ntypes; i++) - wjelem[i+1] = atof(arg[6+ntypes+i]); + for (int i = 0; i < ntypes; i++) radelem[i + 1] = atof(arg[6 + i]); + for (int i = 0; i < ntypes; i++) wjelem[i + 1] = atof(arg[6 + ntypes + i]); // construct cutsq double cut; cutmax = 0.0; - memory->create(cutsq,ntypes+1,ntypes+1,"sna/grid/local:cutsq"); - for(int i = 1; i <= ntypes; i++) { - cut = 2.0*radelem[i]*rcutfac; + memory->create(cutsq, ntypes + 1, ntypes + 1, "sna/grid/local:cutsq"); + for (int i = 1; i <= ntypes; i++) { + cut = 2.0 * radelem[i] * rcutfac; if (cut > cutmax) cutmax = cut; - cutsq[i][i] = cut*cut; - for(int j = i+1; j <= ntypes; j++) { - cut = (radelem[i]+radelem[j])*rcutfac; - cutsq[i][j] = cutsq[j][i] = cut*cut; + cutsq[i][i] = cut * cut; + for (int j = i + 1; j <= ntypes; j++) { + cut = (radelem[i] + radelem[j]) * rcutfac; + cutsq[i][j] = cutsq[j][i] = cut * cut; } } @@ -103,90 +101,82 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : int iarg = nargmin; while (iarg < narg) { - if (strcmp(arg[iarg],"rmin0") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid/local command"); - rmin0 = atof(arg[iarg+1]); + if (strcmp(arg[iarg], "rmin0") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + rmin0 = atof(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"switchflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid/local command"); - switchflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + switchflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"bzeroflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid/local command"); - bzeroflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "bzeroflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + bzeroflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"quadraticflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid/local command"); - quadraticflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "quadraticflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + quadraticflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"chem") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid/local command"); + } else if (strcmp(arg[iarg], "chem") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); chemflag = 1; - memory->create(map,ntypes+1,"compute_sna_grid_local:map"); - nelements = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + memory->create(map, ntypes + 1, "compute_sna_grid_local:map"); + nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { - int jelem = utils::inumeric(FLERR,arg[iarg+2+i],false,lmp); + int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); if (jelem < 0 || jelem >= nelements) - error->all(FLERR,"Illegal compute sna/grid/local command"); - map[i+1] = jelem; + error->all(FLERR, "Illegal compute sna/grid/local command"); + map[i + 1] = jelem; } - iarg += 2+ntypes; - } else if (strcmp(arg[iarg],"bnormflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid/local command"); - bnormflag = atoi(arg[iarg+1]); + iarg += 2 + ntypes; + } else if (strcmp(arg[iarg], "bnormflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + bnormflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"wselfallflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid/local command"); - wselfallflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "wselfallflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + wselfallflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/grid/local command"); - switchinnerflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + switchinnerflag = atoi(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"sinner") == 0) { + } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute sna/grid/local command"); - memory->create(sinnerelem,ntypes+1,"snap:sinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) - sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); sinnerflag = 1; iarg += ntypes; - } else if (strcmp(arg[iarg],"dinner") == 0) { + } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute sna/grid/local command"); - memory->create(dinnerelem,ntypes+1,"snap:dinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) - dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; - } else error->all(FLERR,"Illegal compute sna/grid/local command"); - + } else + error->all(FLERR, "Illegal compute sna/grid/local command"); } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all(FLERR,"Illegal compute sna/grid/local command: switchinnerflag = 1, missing sinner/dinner keyword"); + error->all(FLERR, + "Illegal compute sna/grid/local command: switchinnerflag = 1, missing sinner/dinner " + "keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all(FLERR,"Illegal compute sna/grid/local command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + error->all(FLERR, + "Illegal compute sna/grid/local command: switchinnerflag = 0, unexpected " + "sinner/dinner keyword"); - snaptr = new SNA(lmp, rfac0, twojmax, - rmin0, switchflag, bzeroflag, - chemflag, bnormflag, wselfallflag, - nelements, switchinnerflag); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, + wselfallflag, nelements, switchinnerflag); ncoeff = snaptr->ncoeff; nvalues = ncoeff; - if (quadraticflag) nvalues += (ncoeff*(ncoeff+1))/2; + if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; size_local_cols = size_local_cols_base + nvalues; } @@ -208,9 +198,8 @@ void ComputeSNAGridLocal::init() { int count = 0; for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style,"sna/grid/local") == 0) count++; - if (count > 1 && comm->me == 0) - error->warning(FLERR,"More than one compute sna/grid/local"); + if (strcmp(modify->compute[i]->style, "sna/grid/local") == 0) count++; + if (count > 1 && comm->me == 0) error->warning(FLERR, "More than one compute sna/grid/local"); snaptr->init(); } @@ -229,9 +218,9 @@ void ComputeSNAGridLocal::compute_local() // compute sna for each gridpoint - double** const x = atom->x; - const int* const mask = atom->mask; - int * const type = atom->type; + double **const x = atom->x; + const int *const mask = atom->mask; + int *const type = atom->type; const int ntotal = atom->nlocal + atom->nghost; // insure rij, inside, and typej are of size jnum @@ -252,8 +241,7 @@ void ComputeSNAGridLocal::compute_local() const int itype = 1; int ielem = 0; - if (chemflag) - ielem = map[itype]; + if (chemflag) ielem = map[itype]; // rij[][3] = displacements between atom I and those neighbors // inside = indices of neighbors of I within cutoff @@ -269,23 +257,23 @@ void ComputeSNAGridLocal::compute_local() const double delx = xtmp - x[j][0]; const double dely = ytmp - x[j][1]; const double delz = ztmp - x[j][2]; - const double rsq = delx*delx + dely*dely + delz*delz; + const double rsq = delx * delx + dely * dely + delz * delz; int jtype = type[j]; int jelem = 0; - if (chemflag) - jelem = map[jtype]; + if (chemflag) jelem = map[jtype]; if (rsq < cutsq[jtype][jtype] && rsq > 1e-20) { snaptr->rij[ninside][0] = delx; snaptr->rij[ninside][1] = dely; snaptr->rij[ninside][2] = delz; snaptr->inside[ninside] = j; snaptr->wj[ninside] = wjelem[jtype]; - snaptr->rcutij[ninside] = 2.0*radelem[jtype]*rcutfac; + snaptr->rcutij[ninside] = 2.0 * radelem[jtype] * rcutfac; if (switchinnerflag) { snaptr->sinnerij[ninside] = sinnerelem[jelem]; snaptr->dinnerij[ninside] = dinnerelem[jelem]; } - if (chemflag) snaptr->element[ninside] = jelem; // element index for multi-element snap + if (chemflag) + snaptr->element[ninside] = jelem; // element index for multi-element snap ninside++; } } @@ -297,7 +285,7 @@ void ComputeSNAGridLocal::compute_local() // linear contributions for (int icoeff = 0; icoeff < ncoeff; icoeff++) - alocal[igrid][size_local_cols_base+icoeff] = snaptr->blist[icoeff]; + alocal[igrid][size_local_cols_base + icoeff] = snaptr->blist[icoeff]; // quadratic contributions @@ -305,17 +293,15 @@ void ComputeSNAGridLocal::compute_local() int ncount = ncoeff; for (int icoeff = 0; icoeff < ncoeff; icoeff++) { double bveci = snaptr->blist[icoeff]; - alocal[igrid][size_local_cols_base+ncount++] = 0.5*bveci*bveci; - for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) - alocal[igrid][size_local_cols_base+ncount++] = - bveci*snaptr->blist[jcoeff]; + alocal[igrid][size_local_cols_base + ncount++] = 0.5 * bveci * bveci; + for (int jcoeff = icoeff + 1; jcoeff < ncoeff; jcoeff++) + alocal[igrid][size_local_cols_base + ncount++] = bveci * snaptr->blist[jcoeff]; } } igrid++; } } - /* ---------------------------------------------------------------------- memory usage ------------------------------------------------------------------------- */ @@ -323,9 +309,8 @@ void ComputeSNAGridLocal::compute_local() double ComputeSNAGridLocal::memory_usage() { double nbytes = snaptr->memory_usage(); // SNA object - int n = atom->ntypes+1; - nbytes += (double)n*sizeof(int); // map + int n = atom->ntypes + 1; + nbytes += (double) n * sizeof(int); // map return nbytes; } - diff --git a/src/ML-SNAP/compute_sna_grid_local.h b/src/ML-SNAP/compute_sna_grid_local.h index c7678d049e..760d0de8cc 100644 --- a/src/ML-SNAP/compute_sna_grid_local.h +++ b/src/ML-SNAP/compute_sna_grid_local.h @@ -50,7 +50,7 @@ class ComputeSNAGridLocal : public ComputeGridLocal { int quadraticflag; }; -} +} // namespace LAMMPS_NS #endif #endif diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 60c9987cbc..0a8ba5a697 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -12,25 +12,26 @@ ------------------------------------------------------------------------- */ #include "compute_grid.h" -#include -#include + #include "atom.h" -#include "update.h" -#include "modify.h" +#include "comm.h" #include "domain.h" +#include "error.h" #include "force.h" #include "memory.h" -#include "error.h" -#include "comm.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), grid(nullptr), gridall(nullptr), gridlocal(nullptr) + Compute(lmp, narg, arg), grid(nullptr), gridall(nullptr), gridlocal(nullptr) { - if (narg < 6) error->all(FLERR,"Illegal compute grid command"); + if (narg < 6) error->all(FLERR, "Illegal compute grid command"); array_flag = 1; size_array_cols = 0; @@ -39,19 +40,19 @@ ComputeGrid::ComputeGrid(LAMMPS *lmp, int narg, char **arg) : int iarg0 = 3; int iarg = iarg0; - if (strcmp(arg[iarg],"grid") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal compute grid command"); - nx = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - ny = utils::inumeric(FLERR,arg[iarg+2],false,lmp); - nz = utils::inumeric(FLERR,arg[iarg+3],false,lmp); - if (nx <= 0 || ny <= 0 || nz <= 0) - error->all(FLERR,"All grid dimensions must be positive"); + if (strcmp(arg[iarg], "grid") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal compute grid command"); + nx = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); + ny = utils::inumeric(FLERR, arg[iarg + 2], false, lmp); + nz = utils::inumeric(FLERR, arg[iarg + 3], false, lmp); + if (nx <= 0 || ny <= 0 || nz <= 0) error->all(FLERR, "All grid dimensions must be positive"); iarg += 4; - } else error->all(FLERR,"Illegal compute grid command"); + } else + error->all(FLERR, "Illegal compute grid command"); nargbase = iarg - iarg0; - size_array_rows = nx*ny*nz; + size_array_rows = nx * ny * nz; size_array_cols_base = 3; gridlocal_allocated = 0; } @@ -65,9 +66,7 @@ ComputeGrid::~ComputeGrid() /* ---------------------------------------------------------------------- */ -void ComputeGrid::init() -{ -} +void ComputeGrid::init() {} /* ---------------------------------------------------------------------- */ @@ -85,18 +84,17 @@ void ComputeGrid::setup() void ComputeGrid::grid2x(int igrid, double *x) { - int iz = igrid / (nx*ny); - igrid -= iz * (nx*ny); + int iz = igrid / (nx * ny); + igrid -= iz * (nx * ny); int iy = igrid / nx; igrid -= iy * nx; int ix = igrid; - x[0] = ix*delx; - x[1] = iy*dely; - x[2] = iz*delz; + x[0] = ix * delx; + x[1] = iy * dely; + x[2] = iz * delz; if (triclinic) domain->lamda2x(x, x); - } /* ---------------------------------------------------------------------- @@ -107,7 +105,7 @@ void ComputeGrid::assign_coords_all() { double x[3]; for (int igrid = 0; igrid < size_array_rows; igrid++) { - grid2x(igrid,x); + grid2x(igrid, x); gridall[igrid][0] = x[0]; gridall[igrid][1] = x[1]; gridall[igrid][2] = x[2]; @@ -122,18 +120,17 @@ void ComputeGrid::allocate() { // allocate arrays - printf("In allocate() %d %d \n", size_array_rows,size_array_cols); - memory->create(grid,size_array_rows,size_array_cols,"grid:grid"); - memory->create(gridall,size_array_rows,size_array_cols,"grid:gridall"); + printf("In allocate() %d %d \n", size_array_rows, size_array_cols); + memory->create(grid, size_array_rows, size_array_cols, "grid:grid"); + memory->create(gridall, size_array_rows, size_array_cols, "grid:gridall"); if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { gridlocal_allocated = 1; - memory->create4d_offset(gridlocal,size_array_cols,nzlo,nzhi,nylo,nyhi, - nxlo,nxhi,"grid:gridlocal"); + memory->create4d_offset(gridlocal, size_array_cols, nzlo, nzhi, nylo, nyhi, nxlo, nxhi, + "grid:gridlocal"); } array = gridall; } - /* ---------------------------------------------------------------------- free arrays ------------------------------------------------------------------------- */ @@ -144,19 +141,18 @@ void ComputeGrid::deallocate() memory->destroy(gridall); if (gridlocal_allocated) { gridlocal_allocated = 0; - memory->destroy4d_offset(gridlocal,nzlo,nylo,nxlo); + memory->destroy4d_offset(gridlocal, nzlo, nylo, nxlo); } array = nullptr; } - /* ---------------------------------------------------------------------- set global grid ------------------------------------------------------------------------- */ void ComputeGrid::set_grid_global() { - // calculate grid layout + // calculate grid layout triclinic = domain->triclinic; @@ -176,13 +172,13 @@ void ComputeGrid::set_grid_global() double yprd = prd[1]; double zprd = prd[2]; - delxinv = nx/xprd; - delyinv = ny/yprd; - delzinv = nz/zprd; + delxinv = nx / xprd; + delyinv = ny / yprd; + delzinv = nz / zprd; - delx = 1.0/delxinv; - dely = 1.0/delyinv; - delz = 1.0/delzinv; + delx = 1.0 / delxinv; + dely = 1.0 / delyinv; + delz = 1.0 / delzinv; } /* ---------------------------------------------------------------------- @@ -202,15 +198,15 @@ void ComputeGrid::set_grid_local() // the 2 equality if tests insure a consistent decision // as to which proc owns it - double xfraclo,xfrachi,yfraclo,yfrachi,zfraclo,zfrachi; + double xfraclo, xfrachi, yfraclo, yfrachi, zfraclo, zfrachi; if (comm->layout != Comm::LAYOUT_TILED) { xfraclo = comm->xsplit[comm->myloc[0]]; - xfrachi = comm->xsplit[comm->myloc[0]+1]; + xfrachi = comm->xsplit[comm->myloc[0] + 1]; yfraclo = comm->ysplit[comm->myloc[1]]; - yfrachi = comm->ysplit[comm->myloc[1]+1]; + yfrachi = comm->ysplit[comm->myloc[1] + 1]; zfraclo = comm->zsplit[comm->myloc[2]]; - zfrachi = comm->zsplit[comm->myloc[2]+1]; + zfrachi = comm->zsplit[comm->myloc[2] + 1]; } else { xfraclo = comm->mysplit[0][0]; xfrachi = comm->mysplit[0][1]; @@ -220,23 +216,22 @@ void ComputeGrid::set_grid_local() zfrachi = comm->mysplit[2][1]; } - nxlo = static_cast (xfraclo * nx); - if (1.0*nxlo != xfraclo*nx) nxlo++; - nxhi = static_cast (xfrachi * nx); - if (1.0*nxhi == xfrachi*nx) nxhi--; + nxlo = static_cast(xfraclo * nx); + if (1.0 * nxlo != xfraclo * nx) nxlo++; + nxhi = static_cast(xfrachi * nx); + if (1.0 * nxhi == xfrachi * nx) nxhi--; - nylo = static_cast (yfraclo * ny); - if (1.0*nylo != yfraclo*ny) nylo++; - nyhi = static_cast (yfrachi * ny); - if (1.0*nyhi == yfrachi*ny) nyhi--; + nylo = static_cast(yfraclo * ny); + if (1.0 * nylo != yfraclo * ny) nylo++; + nyhi = static_cast(yfrachi * ny); + if (1.0 * nyhi == yfrachi * ny) nyhi--; - nzlo = static_cast (zfraclo * nz); - if (1.0*nzlo != zfraclo*nz) nzlo++; - nzhi = static_cast (zfrachi * nz); - if (1.0*nzhi == zfrachi*nz) nzhi--; + nzlo = static_cast(zfraclo * nz); + if (1.0 * nzlo != zfraclo * nz) nzlo++; + nzhi = static_cast(zfrachi * nz); + if (1.0 * nzhi == zfrachi * nz) nzhi--; ngridlocal = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); - } /* ---------------------------------------------------------------------- @@ -245,10 +240,8 @@ void ComputeGrid::set_grid_local() double ComputeGrid::memory_usage() { - double nbytes = size_array_rows*size_array_cols * - sizeof(double); // grid - nbytes += size_array_rows*size_array_cols * - sizeof(double); // gridall - nbytes += size_array_cols*ngridlocal*sizeof(double); // gridlocal + double nbytes = size_array_rows * size_array_cols * sizeof(double); // grid + nbytes += size_array_rows * size_array_cols * sizeof(double); // gridall + nbytes += size_array_cols * ngridlocal * sizeof(double); // gridlocal return nbytes; } diff --git a/src/compute_grid.h b/src/compute_grid.h index 4264039cc8..96338a035d 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -20,7 +20,6 @@ namespace LAMMPS_NS { class ComputeGrid : public Compute { public: - ComputeGrid(class LAMMPS *, int, char **); ~ComputeGrid() override; void init() override; @@ -30,31 +29,31 @@ class ComputeGrid : public Compute { double memory_usage() override; protected: - int nx, ny, nz; // global grid dimensions - int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive - int ngridlocal; // number of local grid points - int nvalues; // number of values per grid point - double **grid; // global grid - double **gridall; // global grid summed over procs - double ****gridlocal; // local grid - int triclinic; // triclinic flag - double *boxlo, *prd; // box info (units real/ortho or reduced/tri) - double *sublo, *subhi; // subdomain info (units real/ortho or reduced/tri) - double delxinv,delyinv,delzinv; // inverse grid spacing - double delx,dely,delz; // grid spacing - int nargbase; // number of base class args - double cutmax; // largest cutoff distance - int size_array_cols_base; // number of columns used for coords, etc. - int gridlocal_allocated; // shows if gridlocal allocated + int nx, ny, nz; // global grid dimensions + int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive + int ngridlocal; // number of local grid points + int nvalues; // number of values per grid point + double **grid; // global grid + double **gridall; // global grid summed over procs + double ****gridlocal; // local grid + int triclinic; // triclinic flag + double *boxlo, *prd; // box info (units real/ortho or reduced/tri) + double *sublo, *subhi; // subdomain info (units real/ortho or reduced/tri) + double delxinv, delyinv, delzinv; // inverse grid spacing + double delx, dely, delz; // grid spacing + int nargbase; // number of base class args + double cutmax; // largest cutoff distance + int size_array_cols_base; // number of columns used for coords, etc. + int gridlocal_allocated; // shows if gridlocal allocated - void allocate(); // create arrays - void deallocate(); // free arrays - void grid2x(int, double*); // convert grid point to coord - void assign_coords_all(); // assign coords for global grid - void set_grid_global(); // set global grid - void set_grid_local(); // set bounds for local grid + void allocate(); // create arrays + void deallocate(); // free arrays + void grid2x(int, double *); // convert grid point to coord + void assign_coords_all(); // assign coords for global grid + void set_grid_global(); // set global grid + void set_grid_local(); // set bounds for local grid }; -} +} // namespace LAMMPS_NS #endif diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index e30d06fe45..5f341680bd 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -12,29 +12,30 @@ ------------------------------------------------------------------------- */ #include "compute_grid_local.h" -#include -#include + #include "atom.h" -#include "update.h" -#include "modify.h" +#include "comm.h" #include "domain.h" +#include "error.h" #include "force.h" #include "memory.h" -#include "error.h" -#include "comm.h" +#include "modify.h" +#include "update.h" + +#include // For the subdomain test below; grid-points and subdomain boundaries // sometimes differ by minimal amounts (in the order of 2e-17). -#define EPSILON 1.0e-10 +static constexpr double EPSILON = 1.0e-10; using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeGridLocal::ComputeGridLocal(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), alocal(nullptr) + Compute(lmp, narg, arg), alocal(nullptr) { - if (narg < 6) error->all(FLERR,"Illegal compute grid/local command"); + if (narg < 6) error->all(FLERR, "Illegal compute grid/local command"); local_flag = 1; size_local_cols = 0; @@ -43,15 +44,16 @@ ComputeGridLocal::ComputeGridLocal(LAMMPS *lmp, int narg, char **arg) : int iarg0 = 3; int iarg = iarg0; - if (strcmp(arg[iarg],"grid") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal compute grid/local command"); - nx = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - ny = utils::inumeric(FLERR,arg[iarg+2],false,lmp); - nz = utils::inumeric(FLERR,arg[iarg+3],false,lmp); + if (strcmp(arg[iarg], "grid") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal compute grid/local command"); + nx = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); + ny = utils::inumeric(FLERR, arg[iarg + 2], false, lmp); + nz = utils::inumeric(FLERR, arg[iarg + 3], false, lmp); if (nx <= 0 || ny <= 0 || nz <= 0) - error->all(FLERR,"All grid/local dimensions must be positive"); + error->all(FLERR, "All grid/local dimensions must be positive"); iarg += 4; - } else error->all(FLERR,"Illegal compute grid/local command"); + } else + error->all(FLERR, "Illegal compute grid/local command"); nargbase = iarg - iarg0; @@ -68,9 +70,7 @@ ComputeGridLocal::~ComputeGridLocal() /* ---------------------------------------------------------------------- */ -void ComputeGridLocal::init() -{ -} +void ComputeGridLocal::init() {} /* ---------------------------------------------------------------------- */ @@ -89,9 +89,9 @@ void ComputeGridLocal::setup() void ComputeGridLocal::grid2x(int ix, int iy, int iz, double *x) { - x[0] = ix*delx; - x[1] = iy*dely; - x[2] = iz*delz; + x[0] = ix * delx; + x[1] = iy * dely; + x[2] = iz * delz; if (triclinic) domain->lamda2x(x, x); } @@ -103,12 +103,11 @@ void ComputeGridLocal::grid2x(int ix, int iy, int iz, double *x) void ComputeGridLocal::grid2lamda(int ix, int iy, int iz, double *x) { - x[0] = ix*delx; - x[1] = iy*dely; - x[2] = iz*delz; + x[0] = ix * delx; + x[1] = iy * dely; + x[2] = iz * delz; } - /* ---------------------------------------------------------------------- create arrays ------------------------------------------------------------------------- */ @@ -141,7 +140,7 @@ void ComputeGridLocal::deallocate() void ComputeGridLocal::set_grid_global() { - // calculate grid layout + // calculate grid layout triclinic = domain->triclinic; @@ -161,13 +160,13 @@ void ComputeGridLocal::set_grid_global() double yprd = prd[1]; double zprd = prd[2]; - delxinv = nx/xprd; - delyinv = ny/yprd; - delzinv = nz/zprd; + delxinv = nx / xprd; + delyinv = ny / yprd; + delzinv = nz / zprd; - delx = 1.0/delxinv; - dely = 1.0/delyinv; - delz = 1.0/delzinv; + delx = 1.0 / delxinv; + dely = 1.0 / delyinv; + delz = 1.0 / delzinv; } /* ---------------------------------------------------------------------- @@ -187,15 +186,15 @@ void ComputeGridLocal::set_grid_local() // the 2 equality if tests insure a consistent decision // as to which proc owns it - double xfraclo,xfrachi,yfraclo,yfrachi,zfraclo,zfrachi; + double xfraclo, xfrachi, yfraclo, yfrachi, zfraclo, zfrachi; if (comm->layout != Comm::LAYOUT_TILED) { xfraclo = comm->xsplit[comm->myloc[0]]; - xfrachi = comm->xsplit[comm->myloc[0]+1]; + xfrachi = comm->xsplit[comm->myloc[0] + 1]; yfraclo = comm->ysplit[comm->myloc[1]]; - yfrachi = comm->ysplit[comm->myloc[1]+1]; + yfrachi = comm->ysplit[comm->myloc[1] + 1]; zfraclo = comm->zsplit[comm->myloc[2]]; - zfrachi = comm->zsplit[comm->myloc[2]+1]; + zfrachi = comm->zsplit[comm->myloc[2] + 1]; } else { xfraclo = comm->mysplit[0][0]; xfrachi = comm->mysplit[0][1]; @@ -205,20 +204,20 @@ void ComputeGridLocal::set_grid_local() zfrachi = comm->mysplit[2][1]; } - nxlo = static_cast (xfraclo * nx); - if (1.0*nxlo != xfraclo*nx) nxlo++; - nxhi = static_cast (xfrachi * nx); - if (1.0*nxhi == xfrachi*nx) nxhi--; + nxlo = static_cast(xfraclo * nx); + if (1.0 * nxlo != xfraclo * nx) nxlo++; + nxhi = static_cast(xfrachi * nx); + if (1.0 * nxhi == xfrachi * nx) nxhi--; - nylo = static_cast (yfraclo * ny); - if (1.0*nylo != yfraclo*ny) nylo++; - nyhi = static_cast (yfrachi * ny); - if (1.0*nyhi == yfrachi*ny) nyhi--; + nylo = static_cast(yfraclo * ny); + if (1.0 * nylo != yfraclo * ny) nylo++; + nyhi = static_cast(yfrachi * ny); + if (1.0 * nyhi == yfrachi * ny) nyhi--; - nzlo = static_cast (zfraclo * nz); - if (1.0*nzlo != zfraclo*nz) nzlo++; - nzhi = static_cast (zfrachi * nz); - if (1.0*nzhi == zfrachi*nz) nzhi--; + nzlo = static_cast(zfraclo * nz); + if (1.0 * nzlo != zfraclo * nz) nzlo++; + nzhi = static_cast(zfrachi * nz); + if (1.0 * nzhi == zfrachi * nz) nzhi--; size_local_rows = (nxhi - nxlo + 1) * (nyhi - nylo + 1) * (nzhi - nzlo + 1); } @@ -248,10 +247,10 @@ void ComputeGridLocal::assign_coords() // ensure gridpoint is not strictly outside subdomain - if ((sublo[0]-xgrid[0]) > EPSILON || (xgrid[0]-subhi[0]) > EPSILON || - (sublo[1]-xgrid[1]) > EPSILON || (xgrid[1]-subhi[1]) > EPSILON || - (sublo[2]-xgrid[2]) > EPSILON || (xgrid[2]-subhi[2]) > EPSILON) - error->one(FLERR,"Invalid gridpoint position in compute grid/local"); + if ((sublo[0] - xgrid[0]) > EPSILON || (xgrid[0] - subhi[0]) > EPSILON || + (sublo[1] - xgrid[1]) > EPSILON || (xgrid[1] - subhi[1]) > EPSILON || + (sublo[2] - xgrid[2]) > EPSILON || (xgrid[2] - subhi[2]) > EPSILON) + error->one(FLERR, "Invalid gridpoint position in compute grid/local"); // convert lamda to x, y, z, after sudomain check @@ -270,6 +269,6 @@ void ComputeGridLocal::assign_coords() double ComputeGridLocal::memory_usage() { - int nbytes = size_local_rows * size_local_cols * sizeof(double); // gridlocal + int nbytes = size_local_rows * size_local_cols * sizeof(double); // gridlocal return nbytes; } diff --git a/src/compute_grid_local.h b/src/compute_grid_local.h index 2989628d79..b34dd2d096 100644 --- a/src/compute_grid_local.h +++ b/src/compute_grid_local.h @@ -20,7 +20,6 @@ namespace LAMMPS_NS { class ComputeGridLocal : public Compute { public: - ComputeGridLocal(class LAMMPS *, int, char **); ~ComputeGridLocal() override; void init() override; @@ -30,29 +29,29 @@ class ComputeGridLocal : public Compute { double memory_usage() override; protected: - int nx, ny, nz; // global grid dimensions - int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive - int nvalues; // number of values per grid point - double **alocal; // pointer to Compute::array_local - int triclinic; // triclinic flag - double *boxlo, *prd; // box info (units real/ortho or reduced/tri) - double *sublo, *subhi; // subdomain info (units real/ortho or reduced/tri) - double delxinv,delyinv,delzinv; // inverse grid spacing - double delx,dely,delz; // grid spacing - int nargbase; // number of base class args - double cutmax; // largest cutoff distance - int size_local_cols_base; // number of columns used for coords, etc. - int gridlocal_allocated; // shows if gridlocal allocated + int nx, ny, nz; // global grid dimensions + int nxlo, nxhi, nylo, nyhi, nzlo, nzhi; // local grid bounds, inclusive + int nvalues; // number of values per grid point + double **alocal; // pointer to Compute::array_local + int triclinic; // triclinic flag + double *boxlo, *prd; // box info (units real/ortho or reduced/tri) + double *sublo, *subhi; // subdomain info (units real/ortho or reduced/tri) + double delxinv, delyinv, delzinv; // inverse grid spacing + double delx, dely, delz; // grid spacing + int nargbase; // number of base class args + double cutmax; // largest cutoff distance + int size_local_cols_base; // number of columns used for coords, etc. + int gridlocal_allocated; // shows if gridlocal allocated - void allocate(); // create arrays - void deallocate(); // free arrays - void grid2x(int, int, int, double*); // convert global indices to coordinates - void grid2lamda(int, int, int, double*); // convert global indices to lamda coordinates - void set_grid_global(); // set global grid - void set_grid_local(); // set bounds for local grid - void assign_coords(); // assign coords for grid + void allocate(); // create arrays + void deallocate(); // free arrays + void grid2x(int, int, int, double *); // convert global indices to coordinates + void grid2lamda(int, int, int, double *); // convert global indices to lamda coordinates + void set_grid_global(); // set global grid + void set_grid_local(); // set bounds for local grid + void assign_coords(); // assign coords for grid }; -} +} // namespace LAMMPS_NS #endif From 86f0a62ee0454694f8fe8ed9cc2e68ce27138327 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 17 Jun 2022 17:16:02 -0600 Subject: [PATCH 79/91] Cleaned up programming style --- doc/src/compute_sna_atom.rst | 46 ++++++++++++++++++++---------------- src/compute_grid.cpp | 5 ---- src/compute_grid.h | 1 - src/compute_grid_local.cpp | 4 ---- src/compute_grid_local.h | 1 - 5 files changed, 26 insertions(+), 31 deletions(-) diff --git a/doc/src/compute_sna_atom.rst b/doc/src/compute_sna_atom.rst index 5f777685fd..242defe614 100644 --- a/doc/src/compute_sna_atom.rst +++ b/doc/src/compute_sna_atom.rst @@ -15,6 +15,12 @@ compute snav/atom command compute snap command ==================== +compute sna/grid command +======================== + +compute sna/grid/local command +============================== + Syntax """""" @@ -222,13 +228,13 @@ bispectrum components for a regular grid of points. These are calculated from the local density of nearby atoms *i'* around each grid point, as if there was a central atom *i* at the grid point. This is useful for characterizing fine-scale -structure in a configuration of atoms, and it has been used -to build a machine-learning surrogate for finite-temperature Kohn-Sham -density functional theory (:ref:`Ellis et al. `). +structure in a configuration of atoms, and it is used +in the `MALA package `_ +to build machine-learning surrogates for finite-temperature Kohn-Sham +density functional theory (:ref:`Ellis et al. `) Neighbor atoms not in the group do not contribute to the bispectrum components of the grid points. The distance cutoff :math:`R_{ii'}` -and other parameters are defined as for a central atom with the same type as the -neighbor atoms *i'*. +assumes that *i* has the same type as the neighbor atom *i'*. Compute *sna/grid* calculates a global array containing bispectrum components for a regular grid of points. @@ -688,6 +694,21 @@ number of columns in the global array generated by *snap* are 31, and 931, respectively, while the number of rows is 1+3\*\ *N*\ +6, where *N* is the total number of atoms. +Compute *sna/grid* evaluates a global array. +The array contains one row for each of the +:math:`nx \times ny \times nz` grid points, looping over the index for *ix* fastest, +then *iy*, and *iz* slowest. Each row of the array contains the *x*, *y*, +and *z* coordinates of the grid point, followed by the bispectrum +components. + +Compute *sna/grid/local* evaluates a local array. +The array contains one row for each of the +local grid points, looping over the global index *ix* fastest, +then *iy*, and *iz* slowest. Each row of the array contains +the global indexes *ix*, *iy*, and *iz* first, followed by the *x*, *y*, +and *z* coordinates of the grid point, followed by the bispectrum +components. + If the *quadratic* keyword value is set to 1, then additional columns are generated, corresponding to the products of all distinct pairs of bispectrum components. If the number of bispectrum components is *K*, @@ -715,21 +736,6 @@ page for an overview of LAMMPS output options. To see how this command can be used within a Python workflow to train SNAP potentials, see the examples in `FitSNAP `_. -Compute *sna/grid* evaluates a global array. -The array contains one row for each of the -:math:`nx \times ny \times nz` grid points, looping over the index for *ix* fastest, -then *iy*, and *iz* slowest. Each row of the array contains the *x*, *y*, -and *z* coordinates of the grid point, followed by the bispectrum -components. - -Compute *sna/grid/local* evaluates a local array. -The array contains one row for each of the -local grid points, looping over the global index *ix* fastest, -then *iy*, and *iz* slowest. Each row of the array contains -the global indexes *ix*, *iy*, and *iz* first, followed by the *x*, *y*, -and *z* coordinates of the grid point, followed by the bispectrum -components. - Restrictions """""""""""" diff --git a/src/compute_grid.cpp b/src/compute_grid.cpp index 0a8ba5a697..7a5ffe1e24 100644 --- a/src/compute_grid.cpp +++ b/src/compute_grid.cpp @@ -66,10 +66,6 @@ ComputeGrid::~ComputeGrid() /* ---------------------------------------------------------------------- */ -void ComputeGrid::init() {} - -/* ---------------------------------------------------------------------- */ - void ComputeGrid::setup() { deallocate(); @@ -120,7 +116,6 @@ void ComputeGrid::allocate() { // allocate arrays - printf("In allocate() %d %d \n", size_array_rows, size_array_cols); memory->create(grid, size_array_rows, size_array_cols, "grid:grid"); memory->create(gridall, size_array_rows, size_array_cols, "grid:gridall"); if (nxlo <= nxhi && nylo <= nyhi && nzlo <= nzhi) { diff --git a/src/compute_grid.h b/src/compute_grid.h index 96338a035d..84b3bc4e98 100644 --- a/src/compute_grid.h +++ b/src/compute_grid.h @@ -22,7 +22,6 @@ class ComputeGrid : public Compute { public: ComputeGrid(class LAMMPS *, int, char **); ~ComputeGrid() override; - void init() override; void setup() override; void compute_array() override = 0; diff --git a/src/compute_grid_local.cpp b/src/compute_grid_local.cpp index 5f341680bd..48714962ac 100644 --- a/src/compute_grid_local.cpp +++ b/src/compute_grid_local.cpp @@ -70,10 +70,6 @@ ComputeGridLocal::~ComputeGridLocal() /* ---------------------------------------------------------------------- */ -void ComputeGridLocal::init() {} - -/* ---------------------------------------------------------------------- */ - void ComputeGridLocal::setup() { deallocate(); diff --git a/src/compute_grid_local.h b/src/compute_grid_local.h index b34dd2d096..5bc6f2082a 100644 --- a/src/compute_grid_local.h +++ b/src/compute_grid_local.h @@ -22,7 +22,6 @@ class ComputeGridLocal : public Compute { public: ComputeGridLocal(class LAMMPS *, int, char **); ~ComputeGridLocal() override; - void init() override; void setup() override; void compute_local() override = 0; From 44436c0eb662fb4e396c8496354bbe59b04e3f31 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 17 Jun 2022 17:24:34 -0600 Subject: [PATCH 80/91] Cleaned up programming style --- src/ML-SNAP/compute_sna_atom.cpp | 151 ++++++++--------- src/ML-SNAP/compute_sna_atom.h | 1 + src/ML-SNAP/compute_sna_grid.cpp | 92 +++++----- src/ML-SNAP/compute_sna_grid.h | 2 - src/ML-SNAP/compute_sna_grid_local.cpp | 114 ++++++------- src/ML-SNAP/compute_sna_grid_local.h | 2 - src/ML-SNAP/compute_snad_atom.cpp | 157 ++++++++--------- src/ML-SNAP/compute_snad_atom.h | 2 +- src/ML-SNAP/compute_snap.cpp | 177 ++++++++++--------- src/ML-SNAP/compute_snap.h | 2 +- src/ML-SNAP/compute_snav_atom.cpp | 224 +++++++++++++------------ src/ML-SNAP/compute_snav_atom.h | 3 +- 12 files changed, 460 insertions(+), 467 deletions(-) diff --git a/src/ML-SNAP/compute_sna_atom.cpp b/src/ML-SNAP/compute_sna_atom.cpp index 5f24ebeaa6..69f233b1c3 100644 --- a/src/ML-SNAP/compute_sna_atom.cpp +++ b/src/ML-SNAP/compute_sna_atom.cpp @@ -30,25 +30,28 @@ using namespace LAMMPS_NS; +#define SNAPCOMPUTENAME "sna/atom" + ComputeSNAAtom::ComputeSNAAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), sna(nullptr), radelem(nullptr), wjelem(nullptr), sinnerelem(nullptr), dinnerelem(nullptr) { - double rmin0, rfac0; + // code common to all SNAP computes + + double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; int ntypes = atom->ntypes; - int nargmin = 6+2*ntypes; + int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR,"Illegal compute sna/atom command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); // default values rmin0 = 0.0; switchflag = 1; bzeroflag = 1; - bnormflag = 0; quadraticflag = 0; chemflag = 0; bnormflag = 0; @@ -56,32 +59,34 @@ ComputeSNAAtom::ComputeSNAAtom(LAMMPS *lmp, int narg, char **arg) : switchinnerflag = 0; nelements = 1; - // offset by 1 to match up with types + // process required arguments - memory->create(radelem,ntypes+1,"sna/atom:radelem"); - memory->create(wjelem,ntypes+1,"sna/atom:wjelem"); + memory->create(radelem, ntypes + 1, "sna/atom:radelem"); // offset by 1 to match up with types + memory->create(wjelem, ntypes + 1, "sna/atom:wjelem"); - rcutfac = atof(arg[3]); - rfac0 = atof(arg[4]); - twojmax = atoi(arg[5]); + rcutfac = utils::numeric(FLERR, arg[3], false, lmp); + rfac0 = utils::numeric(FLERR, arg[4], false, lmp); + twojmax = utils::inumeric(FLERR, arg[5], false, lmp); for (int i = 0; i < ntypes; i++) - radelem[i+1] = atof(arg[6+i]); + radelem[i + 1] = + utils::numeric(FLERR, arg[6 + i], false, lmp); for (int i = 0; i < ntypes; i++) - wjelem[i+1] = atof(arg[6+ntypes+i]); + wjelem[i + 1] = + utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); // construct cutsq double cut; cutmax = 0.0; - memory->create(cutsq,ntypes+1,ntypes+1,"sna/atom:cutsq"); + memory->create(cutsq, ntypes + 1, ntypes + 1, "sna/atom:cutsq"); for (int i = 1; i <= ntypes; i++) { - cut = 2.0*radelem[i]*rcutfac; + cut = 2.0 * radelem[i] * rcutfac; if (cut > cutmax) cutmax = cut; - cutsq[i][i] = cut*cut; - for (int j = i+1; j <= ntypes; j++) { - cut = (radelem[i]+radelem[j])*rcutfac; - cutsq[i][j] = cutsq[j][i] = cut*cut; + cutsq[i][i] = cut * cut; + for (int j = i + 1; j <= ntypes; j++) { + cut = (radelem[i] + radelem[j]) * rcutfac; + cutsq[i][j] = cutsq[j][i] = cut * cut; } } @@ -95,89 +100,85 @@ ComputeSNAAtom::ComputeSNAAtom(LAMMPS *lmp, int narg, char **arg) : int iarg = nargmin; while (iarg < narg) { - if (strcmp(arg[iarg],"rmin0") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/atom command"); - rmin0 = atof(arg[iarg+1]); + if (strcmp(arg[iarg], "rmin0") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"switchflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/atom command"); - switchflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"bzeroflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/atom command"); - bzeroflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "bzeroflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"quadraticflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/atom command"); - quadraticflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "quadraticflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"chem") == 0) { - if (iarg+2+ntypes > narg) - error->all(FLERR,"Illegal compute sna/atom command"); + } else if (strcmp(arg[iarg], "chem") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); chemflag = 1; - memory->create(map,ntypes+1,"compute_sna_atom:map"); - nelements = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + memory->create(map, ntypes + 1, "compute_sna_grid:map"); + nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { - int jelem = utils::inumeric(FLERR,arg[iarg+2+i],false,lmp); - if (jelem < 0 || jelem >= nelements) - error->all(FLERR,"Illegal compute sna/atom command"); - map[i+1] = jelem; + int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + map[i + 1] = jelem; } - iarg += 2+ntypes; - } else if (strcmp(arg[iarg],"bnormflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/atom command"); - bnormflag = atoi(arg[iarg+1]); + iarg += 2 + ntypes; + } else if (strcmp(arg[iarg], "bnormflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"wselfallflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/atom command"); - wselfallflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "wselfallflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute sna/atom command"); - switchinnerflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"sinner") == 0) { + } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute sna/atom command"); - memory->create(sinnerelem,ntypes+1,"sna/atom:sinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) - sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); sinnerflag = 1; iarg += ntypes; - } else if (strcmp(arg[iarg],"dinner") == 0) { + } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute sna/atom command"); - memory->create(dinnerelem,ntypes+1,"sna/atom:dinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) - dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; - } else error->all(FLERR,"Illegal compute sna/atom command"); + } else + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all(FLERR,"Illegal compute sna/atom command: switchinnerflag = 1, missing sinner/dinner keyword"); + error->all( + FLERR, + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all(FLERR,"Illegal compute sna/atom command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + error->all( + FLERR, + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); - snaptr = new SNA(lmp, rfac0, twojmax, - rmin0, switchflag, bzeroflag, - chemflag, bnormflag, wselfallflag, - nelements, switchinnerflag); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, + wselfallflag, nelements, switchinnerflag); ncoeff = snaptr->ncoeff; - size_peratom_cols = ncoeff; - if (quadraticflag) size_peratom_cols += (ncoeff*(ncoeff+1))/2; + nvalues = ncoeff; + if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; + + // end code common to all SNAP computes + + size_peratom_cols = nvalues; peratom_flag = 1; nmax = 0; diff --git a/src/ML-SNAP/compute_sna_atom.h b/src/ML-SNAP/compute_sna_atom.h index 7d1ebfa2f8..059062670f 100644 --- a/src/ML-SNAP/compute_sna_atom.h +++ b/src/ML-SNAP/compute_sna_atom.h @@ -50,6 +50,7 @@ class ComputeSNAAtom : public Compute { class SNA *snaptr; double cutmax; int quadraticflag; + int nvalues; }; } // namespace LAMMPS_NS diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index e182b16d64..4c8e4f82ef 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -15,17 +15,11 @@ #include "atom.h" #include "comm.h" -#include "domain.h" #include "error.h" #include "force.h" #include "memory.h" #include "modify.h" -#include "neigh_list.h" -#include "neigh_request.h" -#include "neighbor.h" -#include "pair.h" #include "sna.h" -#include "tokenizer.h" #include "update.h" #include @@ -33,12 +27,11 @@ using namespace LAMMPS_NS; +#define SNAPCOMPUTENAME "sna/grid" + ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : ComputeGrid(lmp, narg, arg), cutsq(nullptr), radelem(nullptr), wjelem(nullptr) { - double rfac0, rmin0; - int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; - // skip over arguments used by base class // so that argument positions are identical to // regular per-atom compute @@ -46,10 +39,15 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : arg += nargbase; narg -= nargbase; + // code common to all SNAP computes + + double rfac0, rmin0; + int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; + int ntypes = atom->ntypes; int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR, "Illegal compute sna/grid command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); // default values @@ -65,15 +63,19 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem, ntypes + 1, "sna/grid:radelem"); // offset by 1 to match up with types + memory->create(radelem, ntypes + 1, "sna/grid:radelem"); // offset by 1 to match up with types memory->create(wjelem, ntypes + 1, "sna/grid:wjelem"); - rcutfac = atof(arg[3]); - rfac0 = atof(arg[4]); - twojmax = atoi(arg[5]); + rcutfac = utils::numeric(FLERR, arg[3], false, lmp); + rfac0 = utils::numeric(FLERR, arg[4], false, lmp); + twojmax = utils::inumeric(FLERR, arg[5], false, lmp); - for (int i = 0; i < ntypes; i++) radelem[i + 1] = atof(arg[6 + i]); - for (int i = 0; i < ntypes; i++) wjelem[i + 1] = atof(arg[6 + ntypes + i]); + for (int i = 0; i < ntypes; i++) + radelem[i + 1] = + utils::numeric(FLERR, arg[6 + i], false, lmp); + for (int i = 0; i < ntypes; i++) + wjelem[i + 1] = + utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); // construct cutsq @@ -101,47 +103,47 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg], "rmin0") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); - rmin0 = atof(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); - switchflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "bzeroflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); - bzeroflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "quadraticflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); - quadraticflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "chem") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); chemflag = 1; memory->create(map, ntypes + 1, "compute_sna_grid:map"); nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); - if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute sna/grid command"); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); map[i + 1] = jelem; } iarg += 2 + ntypes; } else if (strcmp(arg[iarg], "bnormflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); - bnormflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "wselfallflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); - wselfallflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid command"); - switchinnerflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute sna/grid command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); @@ -149,25 +151,25 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : iarg += ntypes; } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute sna/grid command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; } else - error->all(FLERR, "Illegal compute sna/grid command"); + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); } if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute sna/grid command: switchinnerflag = 1, missing sinner/dinner keyword"); + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute sna/grid command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); @@ -175,6 +177,9 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : ncoeff = snaptr->ncoeff; nvalues = ncoeff; if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; + + // end code common to all SNAP computes + size_array_cols = size_array_cols_base + nvalues; array_flag = 1; } @@ -195,22 +200,13 @@ ComputeSNAGrid::~ComputeSNAGrid() void ComputeSNAGrid::init() { - int count = 0; - for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style, "sna/grid") == 0) count++; - if (count > 1 && comm->me == 0) error->warning(FLERR, "More than one compute sna/grid"); + if ((modify->get_compute_by_style("sna/grid").size() > 1) && (comm->me == 0)) + error->warning(FLERR, "More than one instance of compute sna/grid"); snaptr->init(); } /* ---------------------------------------------------------------------- */ -void ComputeSNAGrid::init_list(int /*id*/, NeighList *ptr) -{ - list = ptr; -} - -/* ---------------------------------------------------------------------- */ - void ComputeSNAGrid::compute_array() { invoked_array = update->ntimestep; diff --git a/src/ML-SNAP/compute_sna_grid.h b/src/ML-SNAP/compute_sna_grid.h index 7eef027ef7..839003dc2e 100644 --- a/src/ML-SNAP/compute_sna_grid.h +++ b/src/ML-SNAP/compute_sna_grid.h @@ -29,14 +29,12 @@ class ComputeSNAGrid : public ComputeGrid { ComputeSNAGrid(class LAMMPS *, int, char **); ~ComputeSNAGrid() override; void init() override; - void init_list(int, class NeighList *) override; void compute_array() override; double memory_usage() override; private: int ncoeff; double **cutsq; - class NeighList *list; double rcutfac; double *radelem; double *wjelem; diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index 7359acacbf..d9d66787f4 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -15,17 +15,11 @@ #include "atom.h" #include "comm.h" -#include "domain.h" #include "error.h" #include "force.h" #include "memory.h" #include "modify.h" -#include "neigh_list.h" -#include "neigh_request.h" -#include "neighbor.h" -#include "pair.h" #include "sna.h" -#include "tokenizer.h" #include "update.h" #include @@ -33,12 +27,11 @@ using namespace LAMMPS_NS; +#define SNAPCOMPUTENAME "sna/grid/local" + ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : ComputeGridLocal(lmp, narg, arg), cutsq(nullptr), radelem(nullptr), wjelem(nullptr) { - double rfac0, rmin0; - int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; - // skip over arguments used by base class // so that argument positions are identical to // regular per-atom compute @@ -46,10 +39,15 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : arg += nargbase; narg -= nargbase; + // code common to all SNAP computes + + double rfac0, rmin0; + int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; + int ntypes = atom->ntypes; int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR, "Illegal compute sna/grid/local command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); // default values @@ -63,23 +61,21 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : switchinnerflag = 0; nelements = 1; - // set local input checks - - int sinnerflag = 0; - int dinnerflag = 0; - // process required arguments - memory->create(radelem, ntypes + 1, - "sna/grid/local:radelem"); // offset by 1 to match up with types + memory->create(radelem, ntypes + 1, "sna/grid/local:radelem"); // offset by 1 to match up with types memory->create(wjelem, ntypes + 1, "sna/grid/local:wjelem"); - rcutfac = atof(arg[3]); - rfac0 = atof(arg[4]); - twojmax = atoi(arg[5]); + rcutfac = utils::numeric(FLERR, arg[3], false, lmp); + rfac0 = utils::numeric(FLERR, arg[4], false, lmp); + twojmax = utils::inumeric(FLERR, arg[5], false, lmp); - for (int i = 0; i < ntypes; i++) radelem[i + 1] = atof(arg[6 + i]); - for (int i = 0; i < ntypes; i++) wjelem[i + 1] = atof(arg[6 + ntypes + i]); + for (int i = 0; i < ntypes; i++) + radelem[i + 1] = + utils::numeric(FLERR, arg[6 + i], false, lmp); + for (int i = 0; i < ntypes; i++) + wjelem[i + 1] = + utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); // construct cutsq @@ -96,54 +92,58 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : } } + // set local input checks + + int sinnerflag = 0; + int dinnerflag = 0; + // process optional args int iarg = nargmin; while (iarg < narg) { if (strcmp(arg[iarg], "rmin0") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); - rmin0 = atof(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); - switchflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "bzeroflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); - bzeroflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "quadraticflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); - quadraticflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "chem") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); chemflag = 1; - memory->create(map, ntypes + 1, "compute_sna_grid_local:map"); + memory->create(map, ntypes + 1, "compute_sna_grid:map"); nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); - if (jelem < 0 || jelem >= nelements) - error->all(FLERR, "Illegal compute sna/grid/local command"); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); map[i + 1] = jelem; } iarg += 2 + ntypes; } else if (strcmp(arg[iarg], "bnormflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); - bnormflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "wselfallflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); - wselfallflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); - switchinnerflag = atoi(arg[iarg + 1]); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); @@ -151,25 +151,25 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : iarg += ntypes; } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute sna/grid/local command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; } else - error->all(FLERR, "Illegal compute sna/grid/local command"); + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all(FLERR, - "Illegal compute sna/grid/local command: switchinnerflag = 1, missing sinner/dinner " - "keyword"); + error->all( + FLERR, + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all(FLERR, - "Illegal compute sna/grid/local command: switchinnerflag = 0, unexpected " - "sinner/dinner keyword"); + error->all( + FLERR, + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); @@ -177,6 +177,9 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : ncoeff = snaptr->ncoeff; nvalues = ncoeff; if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; + + // end code common to all SNAP computes + size_local_cols = size_local_cols_base + nvalues; } @@ -196,22 +199,13 @@ ComputeSNAGridLocal::~ComputeSNAGridLocal() void ComputeSNAGridLocal::init() { - int count = 0; - for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style, "sna/grid/local") == 0) count++; - if (count > 1 && comm->me == 0) error->warning(FLERR, "More than one compute sna/grid/local"); + if ((modify->get_compute_by_style("sna/grid/local").size() > 1) && (comm->me == 0)) + error->warning(FLERR, "More than one instance of compute sna/grid/local"); snaptr->init(); } /* ---------------------------------------------------------------------- */ -void ComputeSNAGridLocal::init_list(int /*id*/, NeighList *ptr) -{ - list = ptr; -} - -/* ---------------------------------------------------------------------- */ - void ComputeSNAGridLocal::compute_local() { invoked_array = update->ntimestep; diff --git a/src/ML-SNAP/compute_sna_grid_local.h b/src/ML-SNAP/compute_sna_grid_local.h index 760d0de8cc..60f93b92b0 100644 --- a/src/ML-SNAP/compute_sna_grid_local.h +++ b/src/ML-SNAP/compute_sna_grid_local.h @@ -29,14 +29,12 @@ class ComputeSNAGridLocal : public ComputeGridLocal { ComputeSNAGridLocal(class LAMMPS *, int, char **); ~ComputeSNAGridLocal() override; void init() override; - void init_list(int, class NeighList *) override; void compute_local() override; double memory_usage() override; private: int ncoeff; double **cutsq; - class NeighList *list; double rcutfac; double *radelem; double *wjelem; diff --git a/src/ML-SNAP/compute_snad_atom.cpp b/src/ML-SNAP/compute_snad_atom.cpp index 838d8a85c9..c9a88da535 100644 --- a/src/ML-SNAP/compute_snad_atom.cpp +++ b/src/ML-SNAP/compute_snad_atom.cpp @@ -30,24 +30,27 @@ using namespace LAMMPS_NS; +#define SNAPCOMPUTENAME "snad/atom" + ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), snad(nullptr), radelem(nullptr), wjelem(nullptr), sinnerelem(nullptr), dinnerelem(nullptr) { + // code common to all SNAP computes + double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; int ntypes = atom->ntypes; - int nargmin = 6+2*ntypes; + int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR,"Illegal compute snad/atom command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); // default values rmin0 = 0.0; switchflag = 1; bzeroflag = 1; - bnormflag = 0; quadraticflag = 0; chemflag = 0; bnormflag = 0; @@ -57,28 +60,32 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem,ntypes+1,"snad/atom:radelem"); // offset by 1 to match up with types - memory->create(wjelem,ntypes+1,"snad/atom:wjelem"); - rcutfac = atof(arg[3]); - rfac0 = atof(arg[4]); - twojmax = atoi(arg[5]); + memory->create(radelem, ntypes + 1, "snad/atom:radelem"); // offset by 1 to match up with types + memory->create(wjelem, ntypes + 1, "snad/atom:wjelem"); + + rcutfac = utils::numeric(FLERR, arg[3], false, lmp); + rfac0 = utils::numeric(FLERR, arg[4], false, lmp); + twojmax = utils::inumeric(FLERR, arg[5], false, lmp); + for (int i = 0; i < ntypes; i++) - radelem[i+1] = atof(arg[6+i]); + radelem[i + 1] = + utils::numeric(FLERR, arg[6 + i], false, lmp); for (int i = 0; i < ntypes; i++) - wjelem[i+1] = atof(arg[6+ntypes+i]); + wjelem[i + 1] = + utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); // construct cutsq double cut; cutmax = 0.0; - memory->create(cutsq,ntypes+1,ntypes+1,"snad/atom:cutsq"); + memory->create(cutsq, ntypes + 1, ntypes + 1, "snad/atom:cutsq"); for (int i = 1; i <= ntypes; i++) { - cut = 2.0*radelem[i]*rcutfac; + cut = 2.0 * radelem[i] * rcutfac; if (cut > cutmax) cutmax = cut; - cutsq[i][i] = cut*cut; - for (int j = i+1; j <= ntypes; j++) { - cut = (radelem[i]+radelem[j])*rcutfac; - cutsq[i][j] = cutsq[j][i] = cut*cut; + cutsq[i][i] = cut * cut; + for (int j = i + 1; j <= ntypes; j++) { + cut = (radelem[i] + radelem[j]) * rcutfac; + cutsq[i][j] = cutsq[j][i] = cut * cut; } } @@ -92,93 +99,87 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : int iarg = nargmin; while (iarg < narg) { - if (strcmp(arg[iarg],"rmin0") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snad/atom command"); - rmin0 = atof(arg[iarg+1]); + if (strcmp(arg[iarg], "rmin0") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"bzeroflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snad/atom command"); - bzeroflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"switchflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snad/atom command"); - switchflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "bzeroflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"quadraticflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snad/atom command"); - quadraticflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "quadraticflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"chem") == 0) { - if (iarg+2+ntypes > narg) - error->all(FLERR,"Illegal compute snad/atom command"); + } else if (strcmp(arg[iarg], "chem") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); chemflag = 1; - memory->create(map,ntypes+1,"compute_snad_atom:map"); - nelements = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + memory->create(map, ntypes + 1, "compute_sna_grid:map"); + nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { - int jelem = utils::inumeric(FLERR,arg[iarg+2+i],false,lmp); - if (jelem < 0 || jelem >= nelements) - error->all(FLERR,"Illegal compute snad/atom command"); - map[i+1] = jelem; + int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + map[i + 1] = jelem; } - iarg += 2+ntypes; - } else if (strcmp(arg[iarg],"bnormflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snad/atom command"); - bnormflag = atoi(arg[iarg+1]); + iarg += 2 + ntypes; + } else if (strcmp(arg[iarg], "bnormflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"wselfallflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snad/atom command"); - wselfallflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "wselfallflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snad/atom command"); - switchinnerflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"sinner") == 0) { + } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute snad/atom command"); - memory->create(sinnerelem,ntypes+1,"snad/atom:sinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) - sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); sinnerflag = 1; iarg += ntypes; - } else if (strcmp(arg[iarg],"dinner") == 0) { + } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute snad/atom command"); - memory->create(dinnerelem,ntypes+1,"snad/atom:dinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) - dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; - } else error->all(FLERR,"Illegal compute snad/atom command"); + } else + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all(FLERR,"Illegal compute snad/atom command: switchinnerflag = 1, missing sinner/dinner keyword"); + error->all( + FLERR, + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all(FLERR,"Illegal compute snad/atom command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + error->all( + FLERR, + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); - - snaptr = new SNA(lmp, rfac0, twojmax, - rmin0, switchflag, bzeroflag, - chemflag, bnormflag, wselfallflag, - nelements, switchinnerflag); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, + wselfallflag, nelements, switchinnerflag); ncoeff = snaptr->ncoeff; - nperdim = ncoeff; - if (quadraticflag) nperdim += (ncoeff*(ncoeff+1))/2; - yoffset = nperdim; - zoffset = 2*nperdim; - size_peratom_cols = 3*nperdim*atom->ntypes; + nvalues = ncoeff; + if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; + + // end code common to all SNAP computes + + yoffset = nvalues; + zoffset = 2*nvalues; + size_peratom_cols = 3*nvalues*atom->ntypes; comm_reverse = size_peratom_cols; peratom_flag = 1; @@ -289,7 +290,7 @@ void ComputeSNADAtom::compute_peratom() // const int typeoffset = threencoeff*(atom->type[i]-1); // const int quadraticoffset = threencoeff*atom->ntypes + // threencoeffq*(atom->type[i]-1); - const int typeoffset = 3*nperdim*(atom->type[i]-1); + const int typeoffset = 3*nvalues*(atom->type[i]-1); // insure rij, inside, and typej are of size jnum diff --git a/src/ML-SNAP/compute_snad_atom.h b/src/ML-SNAP/compute_snad_atom.h index 0cdb075daf..ac27e10769 100644 --- a/src/ML-SNAP/compute_snad_atom.h +++ b/src/ML-SNAP/compute_snad_atom.h @@ -37,7 +37,7 @@ class ComputeSNADAtom : public Compute { private: int nmax; - int ncoeff, nperdim, yoffset, zoffset; + int ncoeff, nvalues, yoffset, zoffset; double **cutsq; class NeighList *list; double **snad; diff --git a/src/ML-SNAP/compute_snap.cpp b/src/ML-SNAP/compute_snap.cpp index 83f56e338c..64daaa4c1e 100644 --- a/src/ML-SNAP/compute_snap.cpp +++ b/src/ML-SNAP/compute_snap.cpp @@ -32,6 +32,8 @@ using namespace LAMMPS_NS; enum{SCALAR,VECTOR,ARRAY}; +#define SNAPCOMPUTENAME "snap" + ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), snap(nullptr), snapall(nullptr), snap_peratom(nullptr), radelem(nullptr), wjelem(nullptr), @@ -41,13 +43,15 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : array_flag = 1; extarray = 0; + // code common to all SNAP computes + double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; int ntypes = atom->ntypes; - int nargmin = 6+2*ntypes; + int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR,"Illegal compute snap command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); // default values @@ -55,7 +59,6 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : switchflag = 1; bzeroflag = 1; quadraticflag = 0; - bikflag = 0; chemflag = 0; bnormflag = 0; wselfallflag = 0; @@ -64,28 +67,32 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem,ntypes+1,"snap:radelem"); // offset by 1 to match up with types - memory->create(wjelem,ntypes+1,"snap:wjelem"); - rcutfac = atof(arg[3]); - rfac0 = atof(arg[4]); - twojmax = atoi(arg[5]); + memory->create(radelem, ntypes + 1, "snap:radelem"); // offset by 1 to match up with types + memory->create(wjelem, ntypes + 1, "snap:wjelem"); + + rcutfac = utils::numeric(FLERR, arg[3], false, lmp); + rfac0 = utils::numeric(FLERR, arg[4], false, lmp); + twojmax = utils::inumeric(FLERR, arg[5], false, lmp); + for (int i = 0; i < ntypes; i++) - radelem[i+1] = atof(arg[6+i]); + radelem[i + 1] = + utils::numeric(FLERR, arg[6 + i], false, lmp); for (int i = 0; i < ntypes; i++) - wjelem[i+1] = atof(arg[6+ntypes+i]); + wjelem[i + 1] = + utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); // construct cutsq double cut; cutmax = 0.0; - memory->create(cutsq,ntypes+1,ntypes+1,"snap:cutsq"); + memory->create(cutsq, ntypes + 1, ntypes + 1, "snap:cutsq"); for (int i = 1; i <= ntypes; i++) { - cut = 2.0*radelem[i]*rcutfac; + cut = 2.0 * radelem[i] * rcutfac; if (cut > cutmax) cutmax = cut; - cutsq[i][i] = cut*cut; - for (int j = i+1; j <= ntypes; j++) { - cut = (radelem[i]+radelem[j])*rcutfac; - cutsq[i][j] = cutsq[j][i] = cut*cut; + cutsq[i][i] = cut * cut; + for (int j = i + 1; j <= ntypes; j++) { + cut = (radelem[i] + radelem[j]) * rcutfac; + cutsq[i][j] = cutsq[j][i] = cut * cut; } } @@ -99,107 +106,97 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : int iarg = nargmin; while (iarg < narg) { - if (strcmp(arg[iarg],"rmin0") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snap command"); - rmin0 = atof(arg[iarg+1]); + if (strcmp(arg[iarg], "rmin0") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"bzeroflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snap command"); - bzeroflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"switchflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snap command"); - switchflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "bzeroflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"quadraticflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snap command"); - quadraticflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "quadraticflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"chem") == 0) { - if (iarg+2+ntypes > narg) - error->all(FLERR,"Illegal compute snap command"); + } else if (strcmp(arg[iarg], "chem") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); chemflag = 1; - memory->create(map,ntypes+1,"compute_snap:map"); - nelements = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + memory->create(map, ntypes + 1, "compute_sna_grid:map"); + nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { - int jelem = utils::inumeric(FLERR,arg[iarg+2+i],false,lmp); - if (jelem < 0 || jelem >= nelements) - error->all(FLERR,"Illegal compute snap command"); - map[i+1] = jelem; + int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + map[i + 1] = jelem; } - iarg += 2+ntypes; - } else if (strcmp(arg[iarg],"bnormflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snap command"); - bnormflag = atoi(arg[iarg+1]); + iarg += 2 + ntypes; + } else if (strcmp(arg[iarg], "bnormflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"wselfallflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snap command"); - wselfallflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "wselfallflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"bikflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snap command"); - bikflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snap command"); - switchinnerflag = atoi(arg[iarg+1]); - iarg += 2; - } else if (strcmp(arg[iarg],"sinner") == 0) { + } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute snap command"); - memory->create(sinnerelem,ntypes+1,"snap:sinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) - sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); sinnerflag = 1; iarg += ntypes; - } else if (strcmp(arg[iarg],"dinner") == 0) { + } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute snap command"); - memory->create(dinnerelem,ntypes+1,"snap:dinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) - dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; - } else error->all(FLERR,"Illegal compute snap command"); + } else + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all(FLERR,"Illegal compute snap command: switchinnerflag = 1, missing sinner/dinner keyword"); + error->all( + FLERR, + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all(FLERR,"Illegal compute snap command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + error->all( + FLERR, + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); - snaptr = new SNA(lmp, rfac0, twojmax, - rmin0, switchflag, bzeroflag, - chemflag, bnormflag, wselfallflag, - nelements, switchinnerflag); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, + wselfallflag, nelements, switchinnerflag); ncoeff = snaptr->ncoeff; - nperdim = ncoeff; - if (quadraticflag) nperdim += (ncoeff*(ncoeff+1))/2; + nvalues = ncoeff; + if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; + + // end code common to all SNAP computes + ndims_force = 3; ndims_virial = 6; - yoffset = nperdim; - zoffset = 2*nperdim; + yoffset = nvalues; + zoffset = 2*nvalues; natoms = atom->natoms; bik_rows = 1; if (bikflag) bik_rows = natoms; size_array_rows = bik_rows+ndims_force*natoms+ndims_virial; - size_array_cols = nperdim*atom->ntypes+1; + size_array_cols = nvalues*atom->ntypes+1; lastcol = size_array_cols-1; ndims_peratom = ndims_force; - size_peratom = ndims_peratom*nperdim*atom->ntypes; + size_peratom = ndims_peratom*nvalues*atom->ntypes; nmax = 0; } @@ -341,8 +338,8 @@ void ComputeSnap::compute_array() const double radi = radelem[itype]; const int* const jlist = firstneigh[i]; const int jnum = numneigh[i]; - const int typeoffset_local = ndims_peratom*nperdim*(itype-1); - const int typeoffset_global = nperdim*(itype-1); + const int typeoffset_local = ndims_peratom*nvalues*(itype-1); + const int typeoffset_global = nvalues*(itype-1); // insure rij, inside, and typej are of size jnum @@ -481,9 +478,9 @@ void ComputeSnap::compute_array() // accumulate bispectrum force contributions to global array for (int itype = 0; itype < atom->ntypes; itype++) { - const int typeoffset_local = ndims_peratom*nperdim*itype; - const int typeoffset_global = nperdim*itype; - for (int icoeff = 0; icoeff < nperdim; icoeff++) { + const int typeoffset_local = ndims_peratom*nvalues*itype; + const int typeoffset_global = nvalues*itype; + for (int icoeff = 0; icoeff < nvalues; icoeff++) { for (int i = 0; i < ntotal; i++) { double *snadi = snap_peratom[i]+typeoffset_local; int iglobal = atom->tag[i]; @@ -549,10 +546,10 @@ void ComputeSnap::dbdotr_compute() int nall = atom->nlocal + atom->nghost; for (int i = 0; i < nall; i++) for (int itype = 0; itype < atom->ntypes; itype++) { - const int typeoffset_local = ndims_peratom*nperdim*itype; - const int typeoffset_global = nperdim*itype; + const int typeoffset_local = ndims_peratom*nvalues*itype; + const int typeoffset_global = nvalues*itype; double *snadi = snap_peratom[i]+typeoffset_local; - for (int icoeff = 0; icoeff < nperdim; icoeff++) { + for (int icoeff = 0; icoeff < nvalues; icoeff++) { double dbdx = snadi[icoeff]; double dbdy = snadi[icoeff+yoffset]; double dbdz = snadi[icoeff+zoffset]; diff --git a/src/ML-SNAP/compute_snap.h b/src/ML-SNAP/compute_snap.h index bc0670e2c7..9f4162d6c4 100644 --- a/src/ML-SNAP/compute_snap.h +++ b/src/ML-SNAP/compute_snap.h @@ -35,7 +35,7 @@ class ComputeSnap : public Compute { private: int natoms, nmax, size_peratom, lastcol; - int ncoeff, nperdim, yoffset, zoffset; + int ncoeff, nvalues, yoffset, zoffset; int ndims_peratom, ndims_force, ndims_virial; double **cutsq; class NeighList *list; diff --git a/src/ML-SNAP/compute_snav_atom.cpp b/src/ML-SNAP/compute_snav_atom.cpp index 0baa4bc110..b2fa24b231 100644 --- a/src/ML-SNAP/compute_snav_atom.cpp +++ b/src/ML-SNAP/compute_snav_atom.cpp @@ -21,6 +21,7 @@ #include "neighbor.h" #include "neigh_list.h" #include "force.h" +#include "pair.h" #include "comm.h" #include "memory.h" #include "error.h" @@ -29,24 +30,27 @@ using namespace LAMMPS_NS; +#define SNAPCOMPUTENAME "snav/atom" + ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), snav(nullptr), radelem(nullptr), wjelem(nullptr), sinnerelem(nullptr), dinnerelem(nullptr) { + // code common to all SNAP computes + double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; int ntypes = atom->ntypes; - int nargmin = 6+2*ntypes; + int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR,"Illegal compute snav/atom command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); // default values rmin0 = 0.0; switchflag = 1; bzeroflag = 1; - bnormflag = 0; quadraticflag = 0; chemflag = 0; bnormflag = 0; @@ -56,24 +60,32 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem,ntypes+1,"snav/atom:radelem"); // offset by 1 to match up with types - memory->create(wjelem,ntypes+1,"snav/atom:wjelem"); - rcutfac = atof(arg[3]); - rfac0 = atof(arg[4]); - twojmax = atoi(arg[5]); + memory->create(radelem, ntypes + 1, "snav/atom:radelem"); // offset by 1 to match up with types + memory->create(wjelem, ntypes + 1, "snav/atom:wjelem"); + + rcutfac = utils::numeric(FLERR, arg[3], false, lmp); + rfac0 = utils::numeric(FLERR, arg[4], false, lmp); + twojmax = utils::inumeric(FLERR, arg[5], false, lmp); + for (int i = 0; i < ntypes; i++) - radelem[i+1] = atof(arg[6+i]); + radelem[i + 1] = + utils::numeric(FLERR, arg[6 + i], false, lmp); for (int i = 0; i < ntypes; i++) - wjelem[i+1] = atof(arg[6+ntypes+i]); + wjelem[i + 1] = + utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); + // construct cutsq + double cut; - memory->create(cutsq,ntypes+1,ntypes+1,"snav/atom:cutsq"); + cutmax = 0.0; + memory->create(cutsq, ntypes + 1, ntypes + 1, "snav/atom:cutsq"); for (int i = 1; i <= ntypes; i++) { - cut = 2.0*radelem[i]*rcutfac; - cutsq[i][i] = cut*cut; - for (int j = i+1; j <= ntypes; j++) { - cut = (radelem[i]+radelem[j])*rcutfac; - cutsq[i][j] = cutsq[j][i] = cut*cut; + cut = 2.0 * radelem[i] * rcutfac; + if (cut > cutmax) cutmax = cut; + cutsq[i][i] = cut * cut; + for (int j = i + 1; j <= ntypes; j++) { + cut = (radelem[i] + radelem[j]) * rcutfac; + cutsq[i][j] = cutsq[j][i] = cut * cut; } } @@ -87,90 +99,85 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : int iarg = nargmin; while (iarg < narg) { - if (strcmp(arg[iarg],"rmin0") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snav/atom command"); - rmin0 = atof(arg[iarg+1]); + if (strcmp(arg[iarg], "rmin0") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"switchflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snav/atom command"); - switchflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"bzeroflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snav/atom command"); - bzeroflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "bzeroflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"quadraticflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snav/atom command"); - quadraticflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "quadraticflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"chem") == 0) { - if (iarg+2+ntypes > narg) - error->all(FLERR,"Illegal compute snav/atom command"); + } else if (strcmp(arg[iarg], "chem") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); chemflag = 1; - memory->create(map,ntypes+1,"compute_sna_atom:map"); - nelements = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + memory->create(map, ntypes + 1, "compute_sna_grid:map"); + nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { - int jelem = utils::inumeric(FLERR,arg[iarg+2+i],false,lmp); - if (jelem < 0 || jelem >= nelements) - error->all(FLERR,"Illegal compute snav/atom command"); - map[i+1] = jelem; + int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + map[i + 1] = jelem; } - iarg += 2+ntypes; - } else if (strcmp(arg[iarg],"bnormflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snav/atom command"); - bnormflag = atoi(arg[iarg+1]); + iarg += 2 + ntypes; + } else if (strcmp(arg[iarg], "bnormflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"wselfallflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snav/atom command"); - wselfallflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "wselfallflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"switchinnerflag") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal compute snav/atom command"); - switchinnerflag = atoi(arg[iarg+1]); + } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"sinner") == 0) { + } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute snav/atom command"); - memory->create(sinnerelem,ntypes+1,"snav/atom:sinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) - sinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); sinnerflag = 1; iarg += ntypes; - } else if (strcmp(arg[iarg],"dinner") == 0) { + } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg+ntypes > narg) - error->all(FLERR,"Illegal compute snav/atom command"); - memory->create(dinnerelem,ntypes+1,"snav/atom:dinnerelem"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) - dinnerelem[i+1] = utils::numeric(FLERR,arg[iarg+i],false,lmp); + dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; - } else error->all(FLERR,"Illegal compute snav/atom command"); + } else + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all(FLERR,"Illegal compute snav/atom command: switchinnerflag = 1, missing sinner/dinner keyword"); + error->all( + FLERR, + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all(FLERR,"Illegal compute snav/atom command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + error->all( + FLERR, + "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); - snaptr = new SNA(lmp, rfac0, twojmax, - rmin0, switchflag, bzeroflag, - chemflag, bnormflag, wselfallflag, - nelements, switchinnerflag); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, + wselfallflag, nelements, switchinnerflag); ncoeff = snaptr->ncoeff; - nperdim = ncoeff; - if (quadraticflag) nperdim += (ncoeff*(ncoeff+1))/2; - size_peratom_cols = 6*nperdim*atom->ntypes; + nvalues = ncoeff; + if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; + + // end code common to all SNAP computes + + size_peratom_cols = 6*nvalues*atom->ntypes; comm_reverse = size_peratom_cols; peratom_flag = 1; @@ -203,10 +210,9 @@ void ComputeSNAVAtom::init() { if (force->pair == nullptr) error->all(FLERR,"Compute snav/atom requires a pair style be defined"); - // TODO: Not sure what to do with this error check since cutoff radius is not - // a single number - //if (sqrt(cutsq) > force->pair->cutforce) - // error->all(FLERR,"Compute snav/atom cutoff is longer than pairwise cutoff"); + + if (cutmax > force->pair->cutforce) + error->all(FLERR,"Compute snav/atom cutoff is longer than pairwise cutoff"); // need an occasional full neighbor list @@ -280,7 +286,7 @@ void ComputeSNAVAtom::compute_peratom() const int* const jlist = firstneigh[i]; const int jnum = numneigh[i]; - const int typeoffset = 6*nperdim*(atom->type[i]-1); + const int typeoffset = 6*nvalues*(atom->type[i]-1); // insure rij, inside, and typej are of size jnum @@ -339,17 +345,17 @@ void ComputeSNAVAtom::compute_peratom() for (int icoeff = 0; icoeff < ncoeff; icoeff++) { snavi[icoeff] += snaptr->dblist[icoeff][0]*xtmp; - snavi[icoeff+nperdim] += snaptr->dblist[icoeff][1]*ytmp; - snavi[icoeff+2*nperdim] += snaptr->dblist[icoeff][2]*ztmp; - snavi[icoeff+3*nperdim] += snaptr->dblist[icoeff][1]*ztmp; - snavi[icoeff+4*nperdim] += snaptr->dblist[icoeff][0]*ztmp; - snavi[icoeff+5*nperdim] += snaptr->dblist[icoeff][0]*ytmp; + snavi[icoeff+nvalues] += snaptr->dblist[icoeff][1]*ytmp; + snavi[icoeff+2*nvalues] += snaptr->dblist[icoeff][2]*ztmp; + snavi[icoeff+3*nvalues] += snaptr->dblist[icoeff][1]*ztmp; + snavi[icoeff+4*nvalues] += snaptr->dblist[icoeff][0]*ztmp; + snavi[icoeff+5*nvalues] += snaptr->dblist[icoeff][0]*ytmp; snavj[icoeff] -= snaptr->dblist[icoeff][0]*x[j][0]; - snavj[icoeff+nperdim] -= snaptr->dblist[icoeff][1]*x[j][1]; - snavj[icoeff+2*nperdim] -= snaptr->dblist[icoeff][2]*x[j][2]; - snavj[icoeff+3*nperdim] -= snaptr->dblist[icoeff][1]*x[j][2]; - snavj[icoeff+4*nperdim] -= snaptr->dblist[icoeff][0]*x[j][2]; - snavj[icoeff+5*nperdim] -= snaptr->dblist[icoeff][0]*x[j][1]; + snavj[icoeff+nvalues] -= snaptr->dblist[icoeff][1]*x[j][1]; + snavj[icoeff+2*nvalues] -= snaptr->dblist[icoeff][2]*x[j][2]; + snavj[icoeff+3*nvalues] -= snaptr->dblist[icoeff][1]*x[j][2]; + snavj[icoeff+4*nvalues] -= snaptr->dblist[icoeff][0]*x[j][2]; + snavj[icoeff+5*nvalues] -= snaptr->dblist[icoeff][0]*x[j][1]; } if (quadraticflag) { @@ -369,17 +375,17 @@ void ComputeSNAVAtom::compute_peratom() double dbytmp = bi*biy; double dbztmp = bi*biz; snavi[ncount] += dbxtmp*xtmp; - snavi[ncount+nperdim] += dbytmp*ytmp; - snavi[ncount+2*nperdim] += dbztmp*ztmp; - snavi[ncount+3*nperdim] += dbytmp*ztmp; - snavi[ncount+4*nperdim] += dbxtmp*ztmp; - snavi[ncount+5*nperdim] += dbxtmp*ytmp; + snavi[ncount+nvalues] += dbytmp*ytmp; + snavi[ncount+2*nvalues] += dbztmp*ztmp; + snavi[ncount+3*nvalues] += dbytmp*ztmp; + snavi[ncount+4*nvalues] += dbxtmp*ztmp; + snavi[ncount+5*nvalues] += dbxtmp*ytmp; snavj[ncount] -= dbxtmp*x[j][0]; - snavj[ncount+nperdim] -= dbytmp*x[j][1]; - snavj[ncount+2*nperdim] -= dbztmp*x[j][2]; - snavj[ncount+3*nperdim] -= dbytmp*x[j][2]; - snavj[ncount+4*nperdim] -= dbxtmp*x[j][2]; - snavj[ncount+5*nperdim] -= dbxtmp*x[j][1]; + snavj[ncount+nvalues] -= dbytmp*x[j][1]; + snavj[ncount+2*nvalues] -= dbztmp*x[j][2]; + snavj[ncount+3*nvalues] -= dbytmp*x[j][2]; + snavj[ncount+4*nvalues] -= dbxtmp*x[j][2]; + snavj[ncount+5*nvalues] -= dbxtmp*x[j][1]; ncount++; // upper-triangular elements of quadratic matrix @@ -392,17 +398,17 @@ void ComputeSNAVAtom::compute_peratom() double dbztmp = bi*snaptr->dblist[jcoeff][2] + biz*snaptr->blist[jcoeff]; snavi[ncount] += dbxtmp*xtmp; - snavi[ncount+nperdim] += dbytmp*ytmp; - snavi[ncount+2*nperdim] += dbztmp*ztmp; - snavi[ncount+3*nperdim] += dbytmp*ztmp; - snavi[ncount+4*nperdim] += dbxtmp*ztmp; - snavi[ncount+5*nperdim] += dbxtmp*ytmp; + snavi[ncount+nvalues] += dbytmp*ytmp; + snavi[ncount+2*nvalues] += dbztmp*ztmp; + snavi[ncount+3*nvalues] += dbytmp*ztmp; + snavi[ncount+4*nvalues] += dbxtmp*ztmp; + snavi[ncount+5*nvalues] += dbxtmp*ytmp; snavj[ncount] -= dbxtmp*x[j][0]; - snavj[ncount+nperdim] -= dbytmp*x[j][1]; - snavj[ncount+2*nperdim] -= dbztmp*x[j][2]; - snavj[ncount+3*nperdim] -= dbytmp*x[j][2]; - snavj[ncount+4*nperdim] -= dbxtmp*x[j][2]; - snavj[ncount+5*nperdim] -= dbxtmp*x[j][1]; + snavj[ncount+nvalues] -= dbytmp*x[j][1]; + snavj[ncount+2*nvalues] -= dbztmp*x[j][2]; + snavj[ncount+3*nvalues] -= dbytmp*x[j][2]; + snavj[ncount+4*nvalues] -= dbxtmp*x[j][2]; + snavj[ncount+5*nvalues] -= dbxtmp*x[j][1]; ncount++; } } diff --git a/src/ML-SNAP/compute_snav_atom.h b/src/ML-SNAP/compute_snav_atom.h index 1eb84d8df7..2eac0b7b28 100644 --- a/src/ML-SNAP/compute_snav_atom.h +++ b/src/ML-SNAP/compute_snav_atom.h @@ -37,7 +37,7 @@ class ComputeSNAVAtom : public Compute { private: int nmax; - int ncoeff, nperdim; + int ncoeff, nvalues; double **cutsq; class NeighList *list; double **snav; @@ -50,6 +50,7 @@ class ComputeSNAVAtom : public Compute { double *sinnerelem; double *dinnerelem; class SNA *snaptr; + double cutmax; int quadraticflag; }; From 3ff998fdb0bff166355eeb2b61694b1a4ecc359d Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Fri, 17 Jun 2022 17:31:58 -0600 Subject: [PATCH 81/91] Restricted style string matching --- src/ML-SNAP/compute_sna_grid.cpp | 2 +- src/ML-SNAP/compute_sna_grid_local.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 4c8e4f82ef..2a9b9bf672 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -200,7 +200,7 @@ ComputeSNAGrid::~ComputeSNAGrid() void ComputeSNAGrid::init() { - if ((modify->get_compute_by_style("sna/grid").size() > 1) && (comm->me == 0)) + if ((modify->get_compute_by_style("^sna/grid$").size() > 1) && (comm->me == 0)) error->warning(FLERR, "More than one instance of compute sna/grid"); snaptr->init(); } diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index d9d66787f4..aa18d4c84d 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -199,7 +199,7 @@ ComputeSNAGridLocal::~ComputeSNAGridLocal() void ComputeSNAGridLocal::init() { - if ((modify->get_compute_by_style("sna/grid/local").size() > 1) && (comm->me == 0)) + if ((modify->get_compute_by_style("^sna/grid/local$").size() > 1) && (comm->me == 0)) error->warning(FLERR, "More than one instance of compute sna/grid/local"); snaptr->init(); } From cbc7669a4f43a4e7180444afbd00311c554de857 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 17 Jun 2022 19:37:26 -0400 Subject: [PATCH 82/91] apply clang-format --- src/ML-SNAP/compute_sna_grid.cpp | 22 +++++++++------------- src/ML-SNAP/compute_sna_grid_local.cpp | 23 ++++++++++------------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 2a9b9bf672..90df726687 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -63,19 +63,16 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem, ntypes + 1, "sna/grid:radelem"); // offset by 1 to match up with types + memory->create(radelem, ntypes + 1, "sna/grid:radelem"); // offset by 1 to match up with types memory->create(wjelem, ntypes + 1, "sna/grid:wjelem"); rcutfac = utils::numeric(FLERR, arg[3], false, lmp); rfac0 = utils::numeric(FLERR, arg[4], false, lmp); twojmax = utils::inumeric(FLERR, arg[5], false, lmp); + for (int i = 0; i < ntypes; i++) radelem[i + 1] = utils::numeric(FLERR, arg[6 + i], false, lmp); for (int i = 0; i < ntypes; i++) - radelem[i + 1] = - utils::numeric(FLERR, arg[6 + i], false, lmp); - for (int i = 0; i < ntypes; i++) - wjelem[i + 1] = - utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); + wjelem[i + 1] = utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); // construct cutsq @@ -125,7 +122,8 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); - if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (jelem < 0 || jelem >= nelements) + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); map[i + 1] = jelem; } iarg += 2 + ntypes; @@ -162,14 +160,12 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all( - FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, + " command: switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all( - FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, + " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index aa18d4c84d..3da5ef4e8a 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -63,19 +63,17 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem, ntypes + 1, "sna/grid/local:radelem"); // offset by 1 to match up with types + memory->create(radelem, ntypes + 1, + "sna/grid/local:radelem"); // offset by 1 to match up with types memory->create(wjelem, ntypes + 1, "sna/grid/local:wjelem"); rcutfac = utils::numeric(FLERR, arg[3], false, lmp); rfac0 = utils::numeric(FLERR, arg[4], false, lmp); twojmax = utils::inumeric(FLERR, arg[5], false, lmp); + for (int i = 0; i < ntypes; i++) radelem[i + 1] = utils::numeric(FLERR, arg[6 + i], false, lmp); for (int i = 0; i < ntypes; i++) - radelem[i + 1] = - utils::numeric(FLERR, arg[6 + i], false, lmp); - for (int i = 0; i < ntypes; i++) - wjelem[i + 1] = - utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); + wjelem[i + 1] = utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); // construct cutsq @@ -125,7 +123,8 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); - if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (jelem < 0 || jelem >= nelements) + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); map[i + 1] = jelem; } iarg += 2 + ntypes; @@ -162,14 +161,12 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all( - FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, + " command: switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all( - FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, + " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); From 34e7fa92ab1f0d0b85845d34e22e24515ec7e9af Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 17 Jun 2022 19:44:13 -0400 Subject: [PATCH 83/91] simplify using fmt --- src/ML-SNAP/compute_sna_atom.cpp | 32 ++++++++++----------- src/ML-SNAP/compute_sna_grid.cpp | 39 +++++++++++++------------- src/ML-SNAP/compute_sna_grid_local.cpp | 39 +++++++++++++------------- src/ML-SNAP/compute_snad_atom.cpp | 32 ++++++++++----------- src/ML-SNAP/compute_snap.cpp | 32 ++++++++++----------- src/ML-SNAP/compute_snav_atom.cpp | 32 ++++++++++----------- 6 files changed, 98 insertions(+), 108 deletions(-) diff --git a/src/ML-SNAP/compute_sna_atom.cpp b/src/ML-SNAP/compute_sna_atom.cpp index 69f233b1c3..daec59e3f0 100644 --- a/src/ML-SNAP/compute_sna_atom.cpp +++ b/src/ML-SNAP/compute_sna_atom.cpp @@ -30,8 +30,6 @@ using namespace LAMMPS_NS; -#define SNAPCOMPUTENAME "sna/atom" - ComputeSNAAtom::ComputeSNAAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), sna(nullptr), radelem(nullptr), wjelem(nullptr), sinnerelem(nullptr), dinnerelem(nullptr) @@ -45,7 +43,7 @@ ComputeSNAAtom::ComputeSNAAtom(LAMMPS *lmp, int narg, char **arg) : int ntypes = atom->ntypes; int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute {} command", style); // default values @@ -101,47 +99,47 @@ ComputeSNAAtom::ComputeSNAAtom(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg], "rmin0") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "bzeroflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "quadraticflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "chem") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); chemflag = 1; memory->create(map, ntypes + 1, "compute_sna_grid:map"); nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); - if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute {} command", style); map[i + 1] = jelem; } iarg += 2 + ntypes; } else if (strcmp(arg[iarg], "bnormflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "wselfallflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); @@ -149,25 +147,25 @@ ComputeSNAAtom::ComputeSNAAtom(LAMMPS *lmp, int narg, char **arg) : iarg += ntypes; } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; } else - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + error->all(FLERR, "Illegal compute {} command", style); } if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword"); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 90df726687..f8da915051 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -27,8 +27,6 @@ using namespace LAMMPS_NS; -#define SNAPCOMPUTENAME "sna/grid" - ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : ComputeGrid(lmp, narg, arg), cutsq(nullptr), radelem(nullptr), wjelem(nullptr) { @@ -47,7 +45,7 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : int ntypes = atom->ntypes; int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute {} command", style); // default values @@ -100,48 +98,47 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg], "rmin0") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "bzeroflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "quadraticflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "chem") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); chemflag = 1; memory->create(map, ntypes + 1, "compute_sna_grid:map"); nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); - if (jelem < 0 || jelem >= nelements) - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute {} command", style); map[i + 1] = jelem; } iarg += 2 + ntypes; } else if (strcmp(arg[iarg], "bnormflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "wselfallflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); @@ -149,23 +146,25 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : iarg += ntypes; } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; } else - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + error->all(FLERR, "Illegal compute {} command", style); } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, - " command: switchinnerflag = 1, missing sinner/dinner keyword"); + error->all(FLERR, + "Illegal compute {} command: switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, - " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + error->all(FLERR, + "Illegal compute {} command: switchinnerflag = 0, unexpected sinner/dinner keyword", + style); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index 3da5ef4e8a..079ecac319 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -27,8 +27,6 @@ using namespace LAMMPS_NS; -#define SNAPCOMPUTENAME "sna/grid/local" - ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : ComputeGridLocal(lmp, narg, arg), cutsq(nullptr), radelem(nullptr), wjelem(nullptr) { @@ -47,7 +45,7 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : int ntypes = atom->ntypes; int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute {} command", style); // default values @@ -101,48 +99,47 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg], "rmin0") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "bzeroflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "quadraticflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "chem") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); chemflag = 1; memory->create(map, ntypes + 1, "compute_sna_grid:map"); nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); - if (jelem < 0 || jelem >= nelements) - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute {} command", style); map[i + 1] = jelem; } iarg += 2 + ntypes; } else if (strcmp(arg[iarg], "bnormflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "wselfallflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); @@ -150,23 +147,25 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : iarg += ntypes; } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; } else - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + error->all(FLERR, "Illegal compute {} command", style); } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, - " command: switchinnerflag = 1, missing sinner/dinner keyword"); + error->all(FLERR, + "Illegal compute {} command: switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, - " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + error->all(FLERR, + "Illegal compute {} command: switchinnerflag = 0, unexpected sinner/dinner keyword", + style); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_snad_atom.cpp b/src/ML-SNAP/compute_snad_atom.cpp index c9a88da535..623eb16268 100644 --- a/src/ML-SNAP/compute_snad_atom.cpp +++ b/src/ML-SNAP/compute_snad_atom.cpp @@ -30,8 +30,6 @@ using namespace LAMMPS_NS; -#define SNAPCOMPUTENAME "snad/atom" - ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), snad(nullptr), radelem(nullptr), wjelem(nullptr), sinnerelem(nullptr), dinnerelem(nullptr) @@ -44,7 +42,7 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : int ntypes = atom->ntypes; int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute {} command", style); // default values @@ -100,47 +98,47 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg], "rmin0") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "bzeroflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "quadraticflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "chem") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); chemflag = 1; memory->create(map, ntypes + 1, "compute_sna_grid:map"); nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); - if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute {} command", style); map[i + 1] = jelem; } iarg += 2 + ntypes; } else if (strcmp(arg[iarg], "bnormflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "wselfallflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); @@ -148,25 +146,25 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : iarg += ntypes; } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; } else - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + error->all(FLERR, "Illegal compute {} command", style); } if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword"); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_snap.cpp b/src/ML-SNAP/compute_snap.cpp index 64daaa4c1e..2aa503021c 100644 --- a/src/ML-SNAP/compute_snap.cpp +++ b/src/ML-SNAP/compute_snap.cpp @@ -32,8 +32,6 @@ using namespace LAMMPS_NS; enum{SCALAR,VECTOR,ARRAY}; -#define SNAPCOMPUTENAME "snap" - ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), snap(nullptr), snapall(nullptr), snap_peratom(nullptr), radelem(nullptr), wjelem(nullptr), @@ -51,7 +49,7 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : int ntypes = atom->ntypes; int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute {} command", style); // default values @@ -107,47 +105,47 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg], "rmin0") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "bzeroflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "quadraticflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "chem") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); chemflag = 1; memory->create(map, ntypes + 1, "compute_sna_grid:map"); nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); - if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute {} command", style); map[i + 1] = jelem; } iarg += 2 + ntypes; } else if (strcmp(arg[iarg], "bnormflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "wselfallflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); @@ -155,25 +153,25 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : iarg += ntypes; } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; } else - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + error->all(FLERR, "Illegal compute {} command", style); } if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword"); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_snav_atom.cpp b/src/ML-SNAP/compute_snav_atom.cpp index b2fa24b231..74d52e231a 100644 --- a/src/ML-SNAP/compute_snav_atom.cpp +++ b/src/ML-SNAP/compute_snav_atom.cpp @@ -30,8 +30,6 @@ using namespace LAMMPS_NS; -#define SNAPCOMPUTENAME "snav/atom" - ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), snav(nullptr), radelem(nullptr), wjelem(nullptr), sinnerelem(nullptr), dinnerelem(nullptr) @@ -44,7 +42,7 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : int ntypes = atom->ntypes; int nargmin = 6 + 2 * ntypes; - if (narg < nargmin) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (narg < nargmin) error->all(FLERR, "Illegal compute {} command", style); // default values @@ -100,47 +98,47 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg], "rmin0") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); rmin0 = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "bzeroflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bzeroflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "quadraticflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); quadraticflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "chem") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); chemflag = 1; memory->create(map, ntypes + 1, "compute_sna_grid:map"); nelements = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 0; i < ntypes; i++) { int jelem = utils::inumeric(FLERR, arg[iarg + 2 + i], false, lmp); - if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute {} command", style); map[i + 1] = jelem; } iarg += 2 + ntypes; } else if (strcmp(arg[iarg], "bnormflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); bnormflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "wselfallflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); wselfallflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "switchinnerflag") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute {} command", style); switchinnerflag = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "sinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(sinnerelem, ntypes + 1, "snap:sinnerelem"); for (int i = 0; i < ntypes; i++) sinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); @@ -148,25 +146,25 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : iarg += ntypes; } else if (strcmp(arg[iarg], "dinner") == 0) { iarg++; - if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + if (iarg + ntypes > narg) error->all(FLERR, "Illegal compute {} command", style); memory->create(dinnerelem, ntypes + 1, "snap:dinnerelem"); for (int i = 0; i < ntypes; i++) dinnerelem[i + 1] = utils::numeric(FLERR, arg[iarg + i], false, lmp); dinnerflag = 1; iarg += ntypes; } else - error->all(FLERR, "Illegal compute ", SNAPCOMPUTENAME, " command"); + error->all(FLERR, "Illegal compute {} command", style); } if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 1, missing sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword"); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute ", SNAPCOMPUTENAME, " command: switchinnerflag = 0, unexpected sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword"); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); From b3fea1cb71d1f3e47dceacf07e0d252bd9670fdd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 17 Jun 2022 19:48:09 -0400 Subject: [PATCH 84/91] make spellchecker happy --- doc/src/compute_sna_atom.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/compute_sna_atom.rst b/doc/src/compute_sna_atom.rst index 242defe614..f6946b421d 100644 --- a/doc/src/compute_sna_atom.rst +++ b/doc/src/compute_sna_atom.rst @@ -252,7 +252,7 @@ layout in the global array. Compute *sna/grid/local* calculates bispectrum components of a regular grid of points similarly to compute *sna/grid* described above. However, because the array is local, it contains only rows for grid points -that are local to the processor subdomain. The global grid +that are local to the processor sub-domain. The global grid of :math:`nx \times ny \times nz` points is still laid out in space the same as for *sna/grid*, but grid points are strictly partitioned, so that every grid point appears in one and only one local array. The array contains one row for each of the From eb69bb28b8c266d4c41848b8dfb0945130f81e1d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 17 Jun 2022 21:52:57 -0400 Subject: [PATCH 85/91] add missing style index entries --- doc/src/compute_sna_atom.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/src/compute_sna_atom.rst b/doc/src/compute_sna_atom.rst index f6946b421d..354a9a8fa6 100644 --- a/doc/src/compute_sna_atom.rst +++ b/doc/src/compute_sna_atom.rst @@ -2,6 +2,8 @@ .. index:: compute snad/atom .. index:: compute snav/atom .. index:: compute snap +.. index:: compute sna/grid +.. index:: compute sna/grid/local compute sna/atom command ======================== From de4558aa07fef7301dd6352761b03fc89fb501f4 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Sun, 19 Jun 2022 09:58:01 -0600 Subject: [PATCH 86/91] Tweaked error messages --- src/ML-SNAP/compute_sna_atom.cpp | 9 +++++--- src/ML-SNAP/compute_sna_grid.cpp | 30 +++++++++++++++---------- src/ML-SNAP/compute_sna_grid_local.cpp | 31 +++++++++++++++----------- src/ML-SNAP/compute_snad_atom.cpp | 18 +++++++++------ src/ML-SNAP/compute_snap.cpp | 15 ++++++++----- src/ML-SNAP/compute_snav_atom.cpp | 20 ++++++++++------- 6 files changed, 74 insertions(+), 49 deletions(-) diff --git a/src/ML-SNAP/compute_sna_atom.cpp b/src/ML-SNAP/compute_sna_atom.cpp index daec59e3f0..9dce3d6e6d 100644 --- a/src/ML-SNAP/compute_sna_atom.cpp +++ b/src/ML-SNAP/compute_sna_atom.cpp @@ -35,7 +35,7 @@ ComputeSNAAtom::ComputeSNAAtom(LAMMPS *lmp, int narg, char **arg) : radelem(nullptr), wjelem(nullptr), sinnerelem(nullptr), dinnerelem(nullptr) { - // code common to all SNAP computes + // begin code common to all SNAP computes double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; @@ -160,12 +160,15 @@ ComputeSNAAtom::ComputeSNAAtom(LAMMPS *lmp, int narg, char **arg) : if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", + style); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index f8da915051..dc92ee2b15 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -37,7 +37,7 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : arg += nargbase; narg -= nargbase; - // code common to all SNAP computes + // begin code common to all SNAP computes double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; @@ -61,22 +61,25 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem, ntypes + 1, "sna/grid:radelem"); // offset by 1 to match up with types - memory->create(wjelem, ntypes + 1, "sna/grid:wjelem"); + memory->create(radelem, ntypes + 1, "sna/atom:radelem"); // offset by 1 to match up with types + memory->create(wjelem, ntypes + 1, "sna/atom:wjelem"); rcutfac = utils::numeric(FLERR, arg[3], false, lmp); rfac0 = utils::numeric(FLERR, arg[4], false, lmp); twojmax = utils::inumeric(FLERR, arg[5], false, lmp); - for (int i = 0; i < ntypes; i++) radelem[i + 1] = utils::numeric(FLERR, arg[6 + i], false, lmp); for (int i = 0; i < ntypes; i++) - wjelem[i + 1] = utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); + radelem[i + 1] = + utils::numeric(FLERR, arg[6 + i], false, lmp); + for (int i = 0; i < ntypes; i++) + wjelem[i + 1] = + utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); // construct cutsq double cut; cutmax = 0.0; - memory->create(cutsq, ntypes + 1, ntypes + 1, "sna/grid:cutsq"); + memory->create(cutsq, ntypes + 1, ntypes + 1, "sna/atom:cutsq"); for (int i = 1; i <= ntypes; i++) { cut = 2.0 * radelem[i] * rcutfac; if (cut > cutmax) cutmax = cut; @@ -157,14 +160,17 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all(FLERR, - "Illegal compute {} command: switchinnerflag = 1, missing sinner/dinner keyword", - style); + error->all( + FLERR, + "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all(FLERR, - "Illegal compute {} command: switchinnerflag = 0, unexpected sinner/dinner keyword", - style); + error->all( + FLERR, + "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", + style); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index 079ecac319..8b0121b9ce 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -37,7 +37,7 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : arg += nargbase; narg -= nargbase; - // code common to all SNAP computes + // begin code common to all SNAP computes double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; @@ -61,23 +61,25 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem, ntypes + 1, - "sna/grid/local:radelem"); // offset by 1 to match up with types - memory->create(wjelem, ntypes + 1, "sna/grid/local:wjelem"); + memory->create(radelem, ntypes + 1, "sna/atom:radelem"); // offset by 1 to match up with types + memory->create(wjelem, ntypes + 1, "sna/atom:wjelem"); rcutfac = utils::numeric(FLERR, arg[3], false, lmp); rfac0 = utils::numeric(FLERR, arg[4], false, lmp); twojmax = utils::inumeric(FLERR, arg[5], false, lmp); - for (int i = 0; i < ntypes; i++) radelem[i + 1] = utils::numeric(FLERR, arg[6 + i], false, lmp); for (int i = 0; i < ntypes; i++) - wjelem[i + 1] = utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); + radelem[i + 1] = + utils::numeric(FLERR, arg[6 + i], false, lmp); + for (int i = 0; i < ntypes; i++) + wjelem[i + 1] = + utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); // construct cutsq double cut; cutmax = 0.0; - memory->create(cutsq, ntypes + 1, ntypes + 1, "sna/grid/local:cutsq"); + memory->create(cutsq, ntypes + 1, ntypes + 1, "sna/atom:cutsq"); for (int i = 1; i <= ntypes; i++) { cut = 2.0 * radelem[i] * rcutfac; if (cut > cutmax) cutmax = cut; @@ -158,14 +160,17 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all(FLERR, - "Illegal compute {} command: switchinnerflag = 1, missing sinner/dinner keyword", - style); + error->all( + FLERR, + "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all(FLERR, - "Illegal compute {} command: switchinnerflag = 0, unexpected sinner/dinner keyword", - style); + error->all( + FLERR, + "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", + style); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_snad_atom.cpp b/src/ML-SNAP/compute_snad_atom.cpp index 623eb16268..1cd2278b00 100644 --- a/src/ML-SNAP/compute_snad_atom.cpp +++ b/src/ML-SNAP/compute_snad_atom.cpp @@ -34,7 +34,8 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), snad(nullptr), radelem(nullptr), wjelem(nullptr), sinnerelem(nullptr), dinnerelem(nullptr) { - // code common to all SNAP computes + + // begin code common to all SNAP computes double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; @@ -58,8 +59,8 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem, ntypes + 1, "snad/atom:radelem"); // offset by 1 to match up with types - memory->create(wjelem, ntypes + 1, "snad/atom:wjelem"); + memory->create(radelem, ntypes + 1, "sna/atom:radelem"); // offset by 1 to match up with types + memory->create(wjelem, ntypes + 1, "sna/atom:wjelem"); rcutfac = utils::numeric(FLERR, arg[3], false, lmp); rfac0 = utils::numeric(FLERR, arg[4], false, lmp); @@ -76,7 +77,7 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : double cut; cutmax = 0.0; - memory->create(cutsq, ntypes + 1, ntypes + 1, "snad/atom:cutsq"); + memory->create(cutsq, ntypes + 1, ntypes + 1, "sna/atom:cutsq"); for (int i = 1; i <= ntypes; i++) { cut = 2.0 * radelem[i] * rcutfac; if (cut > cutmax) cutmax = cut; @@ -159,12 +160,15 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", + style); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); @@ -174,7 +178,7 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; // end code common to all SNAP computes - + yoffset = nvalues; zoffset = 2*nvalues; size_peratom_cols = 3*nvalues*atom->ntypes; diff --git a/src/ML-SNAP/compute_snap.cpp b/src/ML-SNAP/compute_snap.cpp index 2aa503021c..fb10fa0fbe 100644 --- a/src/ML-SNAP/compute_snap.cpp +++ b/src/ML-SNAP/compute_snap.cpp @@ -41,7 +41,7 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : array_flag = 1; extarray = 0; - // code common to all SNAP computes + // begin code common to all SNAP computes double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; @@ -65,8 +65,8 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem, ntypes + 1, "snap:radelem"); // offset by 1 to match up with types - memory->create(wjelem, ntypes + 1, "snap:wjelem"); + memory->create(radelem, ntypes + 1, "sna/atom:radelem"); // offset by 1 to match up with types + memory->create(wjelem, ntypes + 1, "sna/atom:wjelem"); rcutfac = utils::numeric(FLERR, arg[3], false, lmp); rfac0 = utils::numeric(FLERR, arg[4], false, lmp); @@ -83,7 +83,7 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : double cut; cutmax = 0.0; - memory->create(cutsq, ntypes + 1, ntypes + 1, "snap:cutsq"); + memory->create(cutsq, ntypes + 1, ntypes + 1, "sna/atom:cutsq"); for (int i = 1; i <= ntypes; i++) { cut = 2.0 * radelem[i] * rcutfac; if (cut > cutmax) cutmax = cut; @@ -166,12 +166,15 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", + style); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_snav_atom.cpp b/src/ML-SNAP/compute_snav_atom.cpp index 74d52e231a..4b7b0caa64 100644 --- a/src/ML-SNAP/compute_snav_atom.cpp +++ b/src/ML-SNAP/compute_snav_atom.cpp @@ -34,7 +34,8 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), snav(nullptr), radelem(nullptr), wjelem(nullptr), sinnerelem(nullptr), dinnerelem(nullptr) { - // code common to all SNAP computes + + // begin code common to all SNAP computes double rfac0, rmin0; int twojmax, switchflag, bzeroflag, bnormflag, wselfallflag; @@ -58,8 +59,8 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem, ntypes + 1, "snav/atom:radelem"); // offset by 1 to match up with types - memory->create(wjelem, ntypes + 1, "snav/atom:wjelem"); + memory->create(radelem, ntypes + 1, "sna/atom:radelem"); // offset by 1 to match up with types + memory->create(wjelem, ntypes + 1, "sna/atom:wjelem"); rcutfac = utils::numeric(FLERR, arg[3], false, lmp); rfac0 = utils::numeric(FLERR, arg[4], false, lmp); @@ -76,7 +77,7 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : double cut; cutmax = 0.0; - memory->create(cutsq, ntypes + 1, ntypes + 1, "snav/atom:cutsq"); + memory->create(cutsq, ntypes + 1, ntypes + 1, "sna/atom:cutsq"); for (int i = 1; i <= ntypes; i++) { cut = 2.0 * radelem[i] * rcutfac; if (cut > cutmax) cutmax = cut; @@ -159,12 +160,15 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword"); + "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", + style); + snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); @@ -174,8 +178,8 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; // end code common to all SNAP computes - - size_peratom_cols = 6*nvalues*atom->ntypes; + + size_peratom_cols = 6*nvalues*atom->ntypes; comm_reverse = size_peratom_cols; peratom_flag = 1; From f632cff8f245d18d0696b17f02342a0e1c609681 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 19 Jun 2022 16:11:37 -0400 Subject: [PATCH 87/91] remove excess text and re-apply clang-format --- src/ML-SNAP/compute_sna_atom.cpp | 9 ++++----- src/ML-SNAP/compute_sna_grid.cpp | 24 +++++++++--------------- src/ML-SNAP/compute_sna_grid_local.cpp | 24 +++++++++--------------- src/ML-SNAP/compute_snad_atom.cpp | 9 ++++----- src/ML-SNAP/compute_snap.cpp | 9 ++++----- src/ML-SNAP/compute_snav_atom.cpp | 9 ++++----- 6 files changed, 34 insertions(+), 50 deletions(-) diff --git a/src/ML-SNAP/compute_sna_atom.cpp b/src/ML-SNAP/compute_sna_atom.cpp index 9dce3d6e6d..1d2190d50d 100644 --- a/src/ML-SNAP/compute_sna_atom.cpp +++ b/src/ML-SNAP/compute_sna_atom.cpp @@ -160,15 +160,14 @@ ComputeSNAAtom::ComputeSNAAtom(LAMMPS *lmp, int narg, char **arg) : if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", - style); + "Illegal compute {} command: switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", - style); - + "Illegal compute {} command: switchinnerflag = 0, unexpected sinner/dinner keyword", + style); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index dc92ee2b15..ac267112b1 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -61,19 +61,16 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem, ntypes + 1, "sna/atom:radelem"); // offset by 1 to match up with types + memory->create(radelem, ntypes + 1, "sna/atom:radelem"); // offset by 1 to match up with types memory->create(wjelem, ntypes + 1, "sna/atom:wjelem"); rcutfac = utils::numeric(FLERR, arg[3], false, lmp); rfac0 = utils::numeric(FLERR, arg[4], false, lmp); twojmax = utils::inumeric(FLERR, arg[5], false, lmp); + for (int i = 0; i < ntypes; i++) radelem[i + 1] = utils::numeric(FLERR, arg[6 + i], false, lmp); for (int i = 0; i < ntypes; i++) - radelem[i + 1] = - utils::numeric(FLERR, arg[6 + i], false, lmp); - for (int i = 0; i < ntypes; i++) - wjelem[i + 1] = - utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); + wjelem[i + 1] = utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); // construct cutsq @@ -160,17 +157,14 @@ ComputeSNAGrid::ComputeSNAGrid(LAMMPS *lmp, int narg, char **arg) : } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all( - FLERR, - "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", - style); + error->all(FLERR, + "Illegal compute {} command: switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all( - FLERR, - "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", - style); - + error->all(FLERR, + "Illegal compute {} command: switchinnerflag = 0, unexpected sinner/dinner keyword", + style); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index 8b0121b9ce..059f177696 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -61,19 +61,16 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : // process required arguments - memory->create(radelem, ntypes + 1, "sna/atom:radelem"); // offset by 1 to match up with types + memory->create(radelem, ntypes + 1, "sna/atom:radelem"); // offset by 1 to match up with types memory->create(wjelem, ntypes + 1, "sna/atom:wjelem"); rcutfac = utils::numeric(FLERR, arg[3], false, lmp); rfac0 = utils::numeric(FLERR, arg[4], false, lmp); twojmax = utils::inumeric(FLERR, arg[5], false, lmp); + for (int i = 0; i < ntypes; i++) radelem[i + 1] = utils::numeric(FLERR, arg[6 + i], false, lmp); for (int i = 0; i < ntypes; i++) - radelem[i + 1] = - utils::numeric(FLERR, arg[6 + i], false, lmp); - for (int i = 0; i < ntypes; i++) - wjelem[i + 1] = - utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); + wjelem[i + 1] = utils::numeric(FLERR, arg[6 + ntypes + i], false, lmp); // construct cutsq @@ -160,17 +157,14 @@ ComputeSNAGridLocal::ComputeSNAGridLocal(LAMMPS *lmp, int narg, char **arg) : } if (switchinnerflag && !(sinnerflag && dinnerflag)) - error->all( - FLERR, - "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", - style); + error->all(FLERR, + "Illegal compute {} command: switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) - error->all( - FLERR, - "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", - style); - + error->all(FLERR, + "Illegal compute {} command: switchinnerflag = 0, unexpected sinner/dinner keyword", + style); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_snad_atom.cpp b/src/ML-SNAP/compute_snad_atom.cpp index 1cd2278b00..9d080508f5 100644 --- a/src/ML-SNAP/compute_snad_atom.cpp +++ b/src/ML-SNAP/compute_snad_atom.cpp @@ -160,15 +160,14 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", - style); + "Illegal compute {} command: switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", - style); - + "Illegal compute {} command: switchinnerflag = 0, unexpected sinner/dinner keyword", + style); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_snap.cpp b/src/ML-SNAP/compute_snap.cpp index fb10fa0fbe..d1f75f8382 100644 --- a/src/ML-SNAP/compute_snap.cpp +++ b/src/ML-SNAP/compute_snap.cpp @@ -166,15 +166,14 @@ ComputeSnap::ComputeSnap(LAMMPS *lmp, int narg, char **arg) : if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", - style); + "Illegal compute {} command: switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", - style); - + "Illegal compute {} command: switchinnerflag = 0, unexpected sinner/dinner keyword", + style); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); diff --git a/src/ML-SNAP/compute_snav_atom.cpp b/src/ML-SNAP/compute_snav_atom.cpp index 4b7b0caa64..27c304b424 100644 --- a/src/ML-SNAP/compute_snav_atom.cpp +++ b/src/ML-SNAP/compute_snav_atom.cpp @@ -160,15 +160,14 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : if (switchinnerflag && !(sinnerflag && dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 1, missing sinner/dinner keyword", - style); + "Illegal compute {} command: switchinnerflag = 1, missing sinner/dinner keyword", + style); if (!switchinnerflag && (sinnerflag || dinnerflag)) error->all( FLERR, - "Illegal compute {} command:, style switchinnerflag = 0, unexpected sinner/dinner keyword", - style); - + "Illegal compute {} command: switchinnerflag = 0, unexpected sinner/dinner keyword", + style); snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements, switchinnerflag); From 4881b232d30a0a53d8a63ca43d75ec6f336225ba Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 19 Jun 2022 16:28:55 -0400 Subject: [PATCH 88/91] whitespace --- src/ML-SNAP/compute_snad_atom.cpp | 2 +- src/ML-SNAP/compute_snav_atom.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ML-SNAP/compute_snad_atom.cpp b/src/ML-SNAP/compute_snad_atom.cpp index 9d080508f5..12839629a9 100644 --- a/src/ML-SNAP/compute_snad_atom.cpp +++ b/src/ML-SNAP/compute_snad_atom.cpp @@ -177,7 +177,7 @@ ComputeSNADAtom::ComputeSNADAtom(LAMMPS *lmp, int narg, char **arg) : if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; // end code common to all SNAP computes - + yoffset = nvalues; zoffset = 2*nvalues; size_peratom_cols = 3*nvalues*atom->ntypes; diff --git a/src/ML-SNAP/compute_snav_atom.cpp b/src/ML-SNAP/compute_snav_atom.cpp index 27c304b424..949dda8e5c 100644 --- a/src/ML-SNAP/compute_snav_atom.cpp +++ b/src/ML-SNAP/compute_snav_atom.cpp @@ -177,7 +177,7 @@ ComputeSNAVAtom::ComputeSNAVAtom(LAMMPS *lmp, int narg, char **arg) : if (quadraticflag) nvalues += (ncoeff * (ncoeff + 1)) / 2; // end code common to all SNAP computes - + size_peratom_cols = 6*nvalues*atom->ntypes; comm_reverse = size_peratom_cols; peratom_flag = 1; From b1b580cc041f3092a138e59ca68713268dc41237 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Mon, 27 Jun 2022 17:03:02 -0600 Subject: [PATCH 89/91] Final tidying up --- doc/src/compute_sna_atom.rst | 229 ----------------------- src/{ => ML-SNAP}/compute_grid.cpp | 0 src/{ => ML-SNAP}/compute_grid.h | 0 src/{ => ML-SNAP}/compute_grid_local.cpp | 0 src/{ => ML-SNAP}/compute_grid_local.h | 0 src/ML-SNAP/compute_sna_grid.cpp | 3 +- src/ML-SNAP/compute_sna_grid_local.cpp | 1 + 7 files changed, 3 insertions(+), 230 deletions(-) rename src/{ => ML-SNAP}/compute_grid.cpp (100%) rename src/{ => ML-SNAP}/compute_grid.h (100%) rename src/{ => ML-SNAP}/compute_grid_local.cpp (100%) rename src/{ => ML-SNAP}/compute_grid_local.h (100%) diff --git a/doc/src/compute_sna_atom.rst b/doc/src/compute_sna_atom.rst index 354a9a8fa6..deb717d84d 100644 --- a/doc/src/compute_sna_atom.rst +++ b/doc/src/compute_sna_atom.rst @@ -467,235 +467,6 @@ number of columns in the global array generated by *snap* are 31, and 931, respectively, while the number of rows is 1+3\*\ *N*\ +6, where *N* is the total number of atoms. -If the *quadratic* keyword value is set to 1, then additional columns -are generated, corresponding to the products of all distinct pairs of -bispectrum components. If the number of bispectrum components is *K*, -then the number of distinct pairs is *K*\ (\ *K*\ +1)/2. For compute -*sna/atom* these columns are appended to existing *K* columns. The -ordering of quadratic terms is upper-triangular, (1,1),(1,2)...(1,\ *K*\ -),(2,1)...(\ *K*\ -1,\ *K*\ -1),(\ *K*\ -1,\ *K*\ ),(\ *K*,\ *K*\ ). -For computes *snad/atom* and *snav/atom* each set of *K*\ (\ *K*\ +1)/2 -additional columns is inserted directly after each of sub-block of -linear terms i.e. linear and quadratic terms are contiguous. So the -nesting order from inside to outside is bispectrum component, linear -then quadratic, vector/tensor component, type. - -If the *chem* keyword is used, then the data is arranged into -:math:`N_{elem}^3` sub-blocks, each sub-block corresponding to a -particular chemical labeling :math:`\kappa\lambda\mu` with the last -label changing fastest. Each sub-block contains *K* bispectrum -components. For the purposes of handling contributions to force, virial, -and quadratic combinations, these :math:`N_{elem}^3` sub-blocks are -treated as a single block of :math:`K N_{elem}^3` columns. - -These values can be accessed by any command that uses per-atom values -from a compute as input. See the :doc:`Howto output ` doc -page for an overview of LAMMPS output options. To see how this command -can be used within a Python workflow to train SNAP potentials, see the -examples in `FitSNAP `_. - -The value of all bispectrum components will be zero for atoms not in -the group. Neighbor atoms not in the group do not contribute to the -bispectrum of atoms in the group. - -The neighbor list needed to compute this quantity is constructed each -time the calculation is performed (i.e. each time a snapshot of atoms -is dumped). Thus it can be inefficient to compute/dump this quantity -too frequently. - -The argument *rcutfac* is a scale factor that controls the ratio of -atomic radius to radial cutoff distance. - -The argument *rfac0* and the optional keyword *rmin0* define the -linear mapping from radial distance to polar angle :math:`theta_0` on the -3-sphere, given above. - -The argument *twojmax* defines which -bispectrum components are generated. See section below on output for a -detailed explanation of the number of bispectrum components and the -ordered in which they are listed. - -The keyword *switchflag* can be used to turn off the switching -function :math:`f_c(r)`. - -The keyword *bzeroflag* determines whether or not *B0*, the bispectrum -components of an atom with no neighbors, are subtracted from the -calculated bispectrum components. This optional keyword normally only -affects compute *sna/atom*\ . However, when *quadraticflag* is on, it -also affects *snad/atom* and *snav/atom*\ . - -The keyword *quadraticflag* determines whether or not the quadratic -combinations of bispectrum quantities are generated. These are formed -by taking the outer product of the vector of bispectrum components with -itself. See section below on output for a detailed explanation of the -number of quadratic terms and the ordered in which they are listed. - -The keyword *chem* activates the explicit multi-element variant of the -SNAP bispectrum components. The argument *nelements* specifies the -number of SNAP elements that will be handled. This is followed by -*elementlist*, a list of integers of length *ntypes*, with values in the -range [0, *nelements* ), which maps each LAMMPS type to one of the SNAP -elements. Note that multiple LAMMPS types can be mapped to the same -element, and some elements may be mapped by no LAMMPS type. However, in -typical use cases (training SNAP potentials) the mapping from LAMMPS -types to elements is one-to-one. - -The explicit multi-element variant invoked by the *chem* keyword -partitions the density of neighbors into partial densities for each -chemical element. This is described in detail in the paper by -:ref:`Cusentino et al. ` The bispectrum components are -indexed on ordered triplets of elements: - -.. math:: - - B_{j_1,j_2,j}^{\kappa\lambda\mu} = - \sum_{m_1,m'_1=-j_1}^{j_1}\sum_{m_2,m'_2=-j_2}^{j_2}\sum_{m,m'=-j}^{j} (u^{\mu}_{j,m,m'})^* - H {\scriptscriptstyle \begin{array}{l} {j} {m} {m'} \\ - {j_1} {m_1} {m'_1} \\ - {j_2} {m_2} {m'_2} \end{array}} - u^{\kappa}_{j_1,m_1,m'_1} u^{\lambda}_{j_2,m_2,m'_2} - -where :math:`u^{\mu}_{j,m,m'}` is an expansion coefficient for the partial density of neighbors -of element :math:`\mu` - -.. math:: - - u^{\mu}_{j,m,m'} = w^{self}_{\mu_{i}\mu} U^{j,m,m'}(0,0,0) + \sum_{r_{ii'} < R_{ii'}}{\delta_{\mu\mu_{i'}}f_c(r_{ii'}) w_{\mu_{i'}} U^{j,m,m'}(\theta_0,\theta,\phi)} - -where :math:`w^{self}_{\mu_{i}\mu}` is the self-contribution, which is -either 1 or 0 (see keyword *wselfallflag* below), -:math:`\delta_{\mu\mu_{i'}}` indicates that the sum is only over -neighbor atoms of element :math:`\mu`, and all other quantities are the -same as those appearing in the original equation for :math:`u^j_{m,m'}` -given above. - -The keyword *wselfallflag* defines the rule used for the -self-contribution. If *wselfallflag* is on, then -:math:`w^{self}_{\mu_{i}\mu}` = 1. If it is off then -:math:`w^{self}_{\mu_{i}\mu}` = 0, except in the case of -:math:`{\mu_{i}=\mu}`, when :math:`w^{self}_{\mu_{i}\mu}` = 1. When the -*chem* keyword is not used, this keyword has no effect. - -The keyword *bnormflag* determines whether or not the bispectrum -component :math:`B_{j_1,j_2,j}` is divided by a factor of :math:`2j+1`. -This normalization simplifies force calculations because of the -following symmetry relation - -.. math:: - - \frac{B_{j_1,j_2,j}}{2j+1} = \frac{B_{j,j_2,j_1}}{2j_1+1} = \frac{B_{j_1,j,j_2}}{2j_2+1} - -This option is typically used in conjunction with the *chem* keyword, -and LAMMPS will generate a warning if both *chem* and *bnormflag* -are not both set or not both unset. - -The keyword *bikflag* determines whether or not to expand the bispectrum -rows of the global array returned by compute snap. If *bikflag* is set -to *1* then the bispectrum row, which is typically the per-atom bispectrum -descriptors :math:`B_{i,k}` summed over all atoms *i* to produce -:math:`B_k`, becomes bispectrum rows equal to the number of atoms. Thus, -the resulting bispectrum rows are :math:`B_{i,k}` instead of just -:math:`B_k`. In this case, the entries in the final column for these rows -are set to zero. - -The keyword *switchinnerflag* with value 1 -activates an additional radial switching -function similar to :math:`f_c(r)` above, but acting to switch off -smoothly contributions from neighbor atoms at short separation distances. -This is useful when SNAP is used in combination with a simple -repulsive potential. For a neighbor atom at -distance :math:`r`, its contribution is scaled by a multiplicative -factor :math:`f_{inner}(r)` defined as follows: - -.. math:: - - = & 0, r \leq S_{inner} - D_{inner} \\ - f_{inner}(r) = & \frac{1}{2}(1 - \cos(\frac{\pi}{2} (1 + \frac{r-S_{inner}}{D_{inner}})), S_{inner} - D_{inner} < r \leq S_{inner} + D_{inner} \\ - = & 1, r > S_{inner} + D_{inner} - -where the switching region is centered at :math:`S_{inner}` and it extends a distance :math:`D_{inner}` -to the left and to the right of this. -With this option, additional keywords *sinner* and *dinner* must be used, -each followed by *ntypes* -values for :math:`S_{inner}` and :math:`D_{inner}`, respectively. -When the central atom and the neighbor atom have different types, -the values of :math:`S_{inner}` and :math:`D_{inner}` are -the arithmetic means of the values for both types. - -.. note:: - - If you have a bonded system, then the settings of :doc:`special_bonds - ` command can remove pairwise interactions between - atoms in the same bond, angle, or dihedral. This is the default - setting for the :doc:`special_bonds ` command, and - means those pairwise interactions do not appear in the neighbor list. - Because this fix uses the neighbor list, it also means those pairs - will not be included in the calculation. One way to get around this, - is to write a dump file, and use the :doc:`rerun ` command to - compute the bispectrum components for snapshots in the dump file. - The rerun script can use a :doc:`special_bonds ` - command that includes all pairs in the neighbor list. - ----------- - -Output info -""""""""""" - -Compute *sna/atom* calculates a per-atom array, each column -corresponding to a particular bispectrum component. The total number of -columns and the identity of the bispectrum component contained in each -column depend of the value of *twojmax*, as described by the following -piece of python code: - -.. parsed-literal:: - - for j1 in range(0,twojmax+1): - for j2 in range(0,j1+1): - for j in range(j1-j2,min(twojmax,j1+j2)+1,2): - if (j>=j1): print j1/2.,j2/2.,j/2. - -For even twojmax = 2(*m*\ -1), :math:`K = m(m+1)(2m+1)/6`, the *m*\ -th pyramidal number. For odd twojmax = 2 *m*\ -1, :math:`K = m(m+1)(m+2)/3`, twice the *m*\ -th tetrahedral number. - -.. note:: - - the *diagonal* keyword allowing other possible choices - for the number of bispectrum components was removed in 2019, - since all potentials use the value of 3, corresponding to the - above set of bispectrum components. - -Compute *snad/atom* evaluates a per-atom array. The columns are arranged -into *ntypes* blocks, listed in order of atom type *I*\ . Each block -contains three sub-blocks corresponding to the *x*, *y*, and *z* -components of the atom position. Each of these sub-blocks contains *K* -columns for the *K* bispectrum components, the same as for compute -*sna/atom* - -Compute *snav/atom* evaluates a per-atom array. The columns are arranged -into *ntypes* blocks, listed in order of atom type *I*\ . Each block -contains six sub-blocks corresponding to the *xx*, *yy*, *zz*, -*yz*, *xz*, and *xy* components of the virial tensor in Voigt -notation. Each of these sub-blocks contains *K* columns for the *K* -bispectrum components, the same as for compute *sna/atom* - -Compute *snap* evaluates a global array. The columns are arranged into -*ntypes* blocks, listed in order of atom type *I*\ . Each block contains -one column for each bispectrum component, the same as for compute -*sna/atom*\ . A final column contains the corresponding energy, force -component on an atom, or virial stress component. The rows of the array -appear in the following order: - -* 1 row: *sna/atom* quantities summed for all atoms of type *I* -* 3\*\ *N* rows: *snad/atom* quantities, with derivatives w.r.t. x, y, and z coordinate of atom *i* appearing in consecutive rows. The atoms are sorted based on atom ID. -* 6 rows: *snav/atom* quantities summed for all atoms of type *I* - -For example, if *K* =30 and ntypes=1, the number of columns in the -per-atom arrays generated by *sna/atom*, *snad/atom*, and -*snav/atom* are 30, 90, and 180, respectively. With *quadratic* value=1, -the numbers of columns are 930, 2790, and 5580, respectively. The -number of columns in the global array generated by *snap* are 31, and -931, respectively, while the number of rows is 1+3\*\ *N*\ +6, where *N* -is the total number of atoms. - Compute *sna/grid* evaluates a global array. The array contains one row for each of the :math:`nx \times ny \times nz` grid points, looping over the index for *ix* fastest, diff --git a/src/compute_grid.cpp b/src/ML-SNAP/compute_grid.cpp similarity index 100% rename from src/compute_grid.cpp rename to src/ML-SNAP/compute_grid.cpp diff --git a/src/compute_grid.h b/src/ML-SNAP/compute_grid.h similarity index 100% rename from src/compute_grid.h rename to src/ML-SNAP/compute_grid.h diff --git a/src/compute_grid_local.cpp b/src/ML-SNAP/compute_grid_local.cpp similarity index 100% rename from src/compute_grid_local.cpp rename to src/ML-SNAP/compute_grid_local.cpp diff --git a/src/compute_grid_local.h b/src/ML-SNAP/compute_grid_local.h similarity index 100% rename from src/compute_grid_local.h rename to src/ML-SNAP/compute_grid_local.h diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index ac267112b1..771a30eb9f 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -228,7 +228,8 @@ void ComputeSNAGrid::compute_array() const double ztmp = xgrid[2]; // currently, all grid points are type 1 - + // not clear what a better choice would be + const int itype = 1; int ielem = 0; if (chemflag) ielem = map[itype]; diff --git a/src/ML-SNAP/compute_sna_grid_local.cpp b/src/ML-SNAP/compute_sna_grid_local.cpp index 059f177696..80a1baddab 100644 --- a/src/ML-SNAP/compute_sna_grid_local.cpp +++ b/src/ML-SNAP/compute_sna_grid_local.cpp @@ -227,6 +227,7 @@ void ComputeSNAGridLocal::compute_local() const double ztmp = xgrid[2]; // currently, all grid points are type 1 + // not clear what a better choice would be const int itype = 1; int ielem = 0; From b165c2ca080113877c35c316cbaea7c38d653f36 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 28 Jun 2022 08:39:12 -0400 Subject: [PATCH 90/91] add files to .gitignore after move to package --- src/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/.gitignore b/src/.gitignore index 8294a204c7..4c1cf49b3b 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -173,6 +173,10 @@ /pair_tdpd.cpp /pair_tdpd.h +/compute_grid.cpp +/compute_grid.h +/compute_grid_local.cpp +/compute_grid_local.h /compute_sna_atom.cpp /compute_sna_atom.h /compute_snad_atom.cpp From a9f3108f294586552277b2f21924a31d629f7bfd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 28 Jun 2022 08:39:20 -0400 Subject: [PATCH 91/91] whitespace --- src/ML-SNAP/compute_sna_grid.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ML-SNAP/compute_sna_grid.cpp b/src/ML-SNAP/compute_sna_grid.cpp index 771a30eb9f..497390f99a 100644 --- a/src/ML-SNAP/compute_sna_grid.cpp +++ b/src/ML-SNAP/compute_sna_grid.cpp @@ -228,8 +228,8 @@ void ComputeSNAGrid::compute_array() const double ztmp = xgrid[2]; // currently, all grid points are type 1 - // not clear what a better choice would be - + // not clear what a better choice would be + const int itype = 1; int ielem = 0; if (chemflag) ielem = map[itype];